1.2.8 • Published 7 years ago

type-l v1.2.8

Weekly downloads
1
License
MIT
Repository
-
Last release
7 years ago

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
1.2.8

7 years ago

1.3.0

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.6

7 years ago

1.1.5

7 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.0

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago