0.6.14 • Published 3 years ago

tyranid-tdgen v0.6.14

Weekly downloads
4
License
Apache-2.0
Repository
github
Last release
3 years ago

tyranid-tdgen

npm version codecov

Generate typescript .d.ts files from your tyranid schema definitions. The generated type definition files extend tyranids own type definitions through declaration merging

Example Usage - Command Line

Pass your model directory to tyranid-tdgen

npm install -g tyranid-tdgen
tyranid-tdgen "./dist/example/models/*.js" > isomorphic.d.ts

For help...

tyranid-tdgen --help

Example Usage - Module

(see /example for the code and output shown below)

Say we have a user tyranid collection, User.ts...

import { Tyr } from 'tyranid';

export default new Tyr.Collection({
  id: 'u00',
  name: 'user',
  dbName: 'users',
  fields: {
    _id: { is: 'mongoid' },
    name: { is: 'string' },
    email: { is: 'email' },
    teamId: { is: 'mongoid' },
    skills: {
      is: 'array',
      of: {
        is: 'object',
        fields: {
          years: { is: 'integer' },
          name: { is: 'string' }
        }
      }
    }
  }
});

In a separate typescript/javascript file, after initializing tyranid, we can generate a type definition file like so...

import { Tyr } from 'tyranid';
import * as fs from 'fs';
import * as mongodb from 'mongodb';
import * as path from 'path';
import { generateFile } from '../';

generate().catch(console.error);

async function generate() {
  const db = await mongodb.MongoClient.connect(
    'mongodb://127.0.0.1:27017/tyranid_tdgen'
  );

  await Tyr.config({
    db: db,
    validate: [
      {
        dir: path.resolve(__dirname, `./models/`),
        fileMatch: '.*.ts'
      }
    ]
  });

  await Promise.all([
    generateFile(
      Tyr.collections,
      path.resolve(__dirname, './output/isomorphic.d.ts')
    ),
    generateFile(
      Tyr.collections,
      path.resolve(__dirname, './output/server.d.ts'),
      { type: 'server' }
    ),
    generateFile(
      Tyr.collections,
      path.resolve(__dirname, './output/client.d.ts'),
      { type: 'client' }
    )
  ]);

  process.exit(0);
}

See ./example/output for the resulting generated type definition files.

0.6.14

3 years ago

0.6.13

4 years ago

0.6.12

4 years ago

0.6.11

4 years ago

0.6.10

4 years ago

0.6.9

4 years ago

0.6.7

4 years ago

0.6.6

4 years ago

0.6.5

4 years ago

0.6.2

4 years ago

0.6.0-alpha.0

4 years ago

0.5.39

4 years ago

0.5.38

4 years ago

0.5.37

4 years ago

0.5.36

4 years ago

0.5.35

4 years ago

0.5.26

4 years ago

0.5.25

4 years ago

0.5.24

5 years ago

0.5.23

5 years ago

0.5.22

5 years ago

0.5.21

5 years ago

0.5.20

5 years ago

0.5.19

5 years ago

0.5.18

5 years ago

0.5.17

5 years ago

0.5.16

5 years ago

0.5.15

5 years ago

0.5.14

5 years ago

0.5.13

5 years ago

0.5.12

5 years ago

0.5.11

5 years ago

0.5.10

6 years ago

0.5.9

6 years ago

0.5.8

6 years ago

0.5.7

6 years ago

0.5.6

6 years ago

0.5.5

6 years ago

0.5.4

6 years ago

0.5.3

6 years ago

0.5.2

6 years ago

0.5.1

6 years ago

0.5.0

6 years ago

0.4.3

6 years ago

0.4.2

6 years ago

0.4.1

7 years ago

0.3.0

7 years ago

0.2.12

7 years ago

0.2.11

7 years ago

0.2.10

7 years ago

0.2.8

7 years ago

0.2.7

7 years ago

0.2.6

7 years ago

0.2.5

7 years ago

0.2.4

7 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.0.28

7 years ago

0.0.27

7 years ago

0.0.26

7 years ago

0.0.25

7 years ago

0.0.24

7 years ago

0.0.23

7 years ago

0.0.22

7 years ago

0.0.21

7 years ago

0.0.20

7 years ago

0.0.19

7 years ago

0.0.18

7 years ago

0.0.16

7 years ago

0.0.15

7 years ago

0.0.14

7 years ago

0.0.13

7 years ago

0.0.12

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago