# type-l

> This project only exists because and is entirely based on projects like:

Latest version **1.2.8** (published 2017-10-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install type-l
pnpm add type-l
yarn add type-l
bun add type-l
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.8 |
| Published | 2017-10-02 |
| First published | 2017-03-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 8 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Victor Queiroz |
| Maintainers | victorqueiroz |

## Links

- npm: https://www.npmjs.com/package/type-l
- npm.io page: https://npm.io/package/type-l

## Dependencies (8)

- [jsbn](https://npm.io/package/jsbn.md) ^1.1.0
- [long](https://npm.io/package/long.md) ^3.2.0
- [buffer](https://npm.io/package/buffer.md) ^5.0.1
- [lodash](https://npm.io/package/lodash.md) ^4.17.2
- [mathjs](https://npm.io/package/mathjs.md) ^3.8.0
- [mkdirp](https://npm.io/package/mkdirp.md) ^0.5.1
- [nunjucks](https://npm.io/package/nunjucks.md) ^3.0.0
- [decimal.js](https://npm.io/package/decimal.js.md) ^7.1.0

## Recent versions

- 1.2.8 (latest) — 2017-10-02
- 1.3.0 — 2017-03-14

## README

# type-l

This project only exists because and is entirely based on projects like:

- [telegram-mt-node](https://github.com/enricostara/telegram-mt-node)
- [telegram-tl-node](https://github.com/enricostara/telegram-tl-node)
- [webogram](https://github.com/zhukov/webogram/tree/master/app/js)

## Building schema

```js
const tl = require('type-l');
const gulp = require('gulp');

gulp.task('build-schemas', function() {
    const builder = new tl.SchemaBuilder({
        schemas: [{
            prefix: 'mtproto', // Prefix and ES6 import id
            methods: require('./test/schema/mt-schema.json').methods,
            predicates: require('./test/schema/mt-schema.json').predicates
        }, {
            prefix: 'TL', // Prefix and ES6 import id
            methods: require('./test/schema/api-schema.json').methods,
            predicates: require('./test/schema/api-schema.json').predicates
        }],
        nunjucks: require('nunjucks')
    });

    const destFolder = path.resolve(__dirname, 'src/schema');

    builder.build().forEach(file => {
        const fullPath = path.resolve(destFolder, file.filePath);

        console.log('Creating', fullPath);

        mkdirp.sync(path.dirname(fullPath));
        fs.writeFileSync(fullPath, transform(file));
    });

    function transform() {
        // do some Babel transformation?
    }
});
```

## Dynamically Built Types usage
```js
// Of course you can use a better approach like `mtproto/index.js` or something like that
import { TypeVector, tl, mtproto } from './mtproto/__do_not_edit__/schema';

class MakeADifference extends TypeVector {
    constructor(options) {
        super(options);
    }
}

const msgContainer = new mtproto.MsgContainer({
    props: {
        msgs: new MakeADifference({
            type: 'mtproto.msg',
            list: [
                new mtproto.Msg({
                    props: {
                        msgId: '0x' + crypto.randomBytes(8).toString('hex'),
                        body: new mtproto.NiceTypeThatBETeamCreated({
                            props: {
                                pain: crypto.randomBytes(2048)
                            }
                        }).serialize()
                    }
                })
            ]
        })
    }
});

const buffer = msgContainer.serialize();
```

If you want to build your type files dynamically. Check our example on [build-test-schema.js](https://github.com/VictorQueiroz/type-l/blob/master/build-test-schema.js).

Looking for usage example? Check it out [test/SchemaBuilder.js](https://github.com/VictorQueiroz/type-l/blob/master/test/SchemaBuilder.js)

## Running tests

First the basics

```
git clone https://github.com/VictorQueiroz/type-l
cd type-l
```

Executing the tests is pretty much like:

```
npm install
npm test
```

---
_Source: https://npm.io/package/type-l · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
