0.0.6 • Published 5 years ago

teason v0.0.6

Weekly downloads
1
License
ISC
Repository
github
Last release
5 years ago

teason - it's teason then

teason is a cli that takes TypeScript definitions and generates both JSON schema and JSON mock data.

Some might call it a TSON generator

Examples

Take a look at the examples to understand what teason does

Examples can be found in the /examples directory

How to use

npm i teason

After installing you will be able to run the command npx teason --help

cli options

Teason requires two things to run

  1. Folder path where the TypeScript definitions can be found
  2. The interface name to use

Not defining output-paths will result in no output (a dry-run)

Changing validation-keywords will remove the default value (faker)

Options:
  -t, --types-folder <folder>                       folder path with typescript types
  -i, --interface-name <name>                       main interface to begin with
  -j, --json-output-path <file_path>                output file to store the generated JSON
  -s, --schema-output-path <file_path>              output file to store the generated Schema
  -v, --validation-keywords <comma separated list>  keywords of extra annotation to accept ex: "title,test,data"  (default: ["faker"])
  -h, --help                                        output usage information

config options

You can also store your config in a .teasonrc file

{
  "typesFolder": "types",
  "interfaceName": "Database",
  "jsonOutputPath": "out.json",
  "schemaOutputPath": "out.schema.json",
  "validationKeywords": ["faker"]
}

Schema

The schema output can be used to validate or create new JSON data.

validation with ajv and/or creating with json-editor github

Mock data

Mock data that conforms to your schema. Can be extended with @faker annotations to create more realistic data

Uses typescript-json-schema, json-schema-faker and faker.js under the hood.

json-server

The output from teason is not optimized for json-server, but it can be done quite easily.

The quickest way is to use normalizr and define a normalizr.schema (not to be confused with a json schema).

/examples/post-process.ts contains what you need. In most cases you will only have to change the result of getDbSchema() to get the script working for you