type-l

1.2.8 • Public • Published

type-l

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

Building schema

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

// 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.

Looking for usage example? Check it out 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

Readme

Keywords

none

Package Sidebar

Install

npm i type-l

Weekly Downloads

1

Version

1.2.8

License

MIT

Last publish

Collaborators

  • vqueiroz