ts-runtime-validation 1.0.1 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # ts-runtime-check
1
+ # ts-runtime-validation
2
2
 
3
3
  ## Why?
4
4
 
5
- Get bulletproof type validation based off typescript interfaces
5
+ Get bulletproof type validation based off typescript interfaces without any extra work. This package will ingest your existing types and generate the code for you.
6
6
 
7
7
  ## How?
8
8
 
@@ -10,27 +10,27 @@ This is a code generator that is designed to run as a yarn / npm script. By defa
10
10
 
11
11
  ## Footnote
12
12
 
13
- The helper file assumes you have [ajv-validator](https://github.com/ajv-validator/ajv) peer dependency installed.
13
+ The helper file assumes you have [ajv-validator](https://github.com/ajv-validator/ajv) peer dependency installed. Since this is only a code generation tool this package can be installed as a dev dependency.
14
14
 
15
15
  ## CLI usage
16
16
 
17
17
  Ensure your project files containing the schemas you want to validate end with the prefix `.jsonschema.ts`
18
18
 
19
19
  ```
20
- Usage: ts-runtime-check [options]
20
+ Usage: ts-runtime-validation [options]
21
21
 
22
22
  Options:
23
23
  --glob Glob file path of typescript files to generate ts-interface -> json-schema validations - default: *.jsonschema.{ts,tsx}
24
24
  --rootPath RootPath of source - default: ./src
25
- --output Validation schema + typescript interface output directory (relative to root path) - default: ./.ts-runtime-check
25
+ --output Validation schema + typescript interface output directory (relative to root path) - default: ./.ts-runtime-validation
26
26
  --no-helpers Only generate JSON schema without typescript helper files
27
27
  -h, --help display help for command
28
28
  ```
29
29
 
30
- ## Usage with helper function
30
+ ## Example usage of generated ts type validation
31
31
 
32
32
  ```typescript
33
- import { isValidSchema } from "./.ts-runtime-check/isSchemaValid"; // this is autogenerated by the CLI as a helper file
33
+ import { isValidSchema } from "./.ts-runtime-validation/isSchemaValid"; // this is autogenerated by the CLI as a helper file
34
34
 
35
35
  if (isValidSchema(data, "#/definitions/ITypeA")) {
36
36
  // variable: data in this block will have typings for ITypeA
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ const SchemaGenerator_1 = require("./SchemaGenerator");
5
5
  const commander_1 = require("commander");
6
6
  const defaultGlobPattern = "*.jsonschema.{ts,tsx}";
7
7
  const defaultRootPath = "./src";
8
- const defaultOutputFolder = "./.ts-runtime-check";
8
+ const defaultOutputFolder = "./.ts-runtime-validation";
9
9
  commander_1.program.option("--glob", `Glob file path of typescript files to generate ts-interface -> json-schema validations - default: ${defaultGlobPattern}`, defaultGlobPattern);
10
10
  commander_1.program.option("--rootPath", `RootPath of source - default: ${defaultRootPath}`, defaultRootPath);
11
11
  commander_1.program.option("--output", `Validation schema + typescript interface output directory (relative to root path) - default: ${defaultOutputFolder}`, defaultOutputFolder);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAEA,uDAAoD;AACpD,yCAAoC;AAEpC,MAAM,kBAAkB,GAAG,uBAAuB,CAAC;AAEnD,MAAM,eAAe,GAAG,OAAO,CAAC;AAChC,MAAM,mBAAmB,GAAG,qBAAqB,CAAC;AASlD,mBAAO,CAAC,MAAM,CACV,QAAQ,EACR,qGAAqG,kBAAkB,EAAE,EACzH,kBAAkB,CACrB,CAAC;AACF,mBAAO,CAAC,MAAM,CAAC,YAAY,EAAE,iCAAiC,eAAe,EAAE,EAAE,eAAe,CAAC,CAAC;AAClG,mBAAO,CAAC,MAAM,CACV,UAAU,EACV,gGAAgG,mBAAmB,EAAE,EACrH,mBAAmB,CACtB,CAAC;AACF,mBAAO,CAAC,MAAM,CAAC,cAAc,EAAE,2DAA2D,EAAE,IAAI,CAAC,CAAC;AAElG,mBAAO,CAAC,KAAK,EAAE,CAAC;AAEhB,MAAM,OAAO,GAAG,mBAAO,CAAC,IAAI,EAAmB,CAAC;AAEhD,IAAI,iCAAe,CAAC,OAAO,CAAC,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAEA,uDAAoD;AACpD,yCAAoC;AAEpC,MAAM,kBAAkB,GAAG,uBAAuB,CAAC;AAEnD,MAAM,eAAe,GAAG,OAAO,CAAC;AAChC,MAAM,mBAAmB,GAAG,0BAA0B,CAAC;AASvD,mBAAO,CAAC,MAAM,CACV,QAAQ,EACR,qGAAqG,kBAAkB,EAAE,EACzH,kBAAkB,CACrB,CAAC;AACF,mBAAO,CAAC,MAAM,CAAC,YAAY,EAAE,iCAAiC,eAAe,EAAE,EAAE,eAAe,CAAC,CAAC;AAClG,mBAAO,CAAC,MAAM,CACV,UAAU,EACV,gGAAgG,mBAAmB,EAAE,EACrH,mBAAmB,CACtB,CAAC;AACF,mBAAO,CAAC,MAAM,CAAC,cAAc,EAAE,2DAA2D,EAAE,IAAI,CAAC,CAAC;AAElG,mBAAO,CAAC,KAAK,EAAE,CAAC;AAEhB,MAAM,OAAO,GAAG,mBAAO,CAAC,IAAI,EAAmB,CAAC;AAEhD,IAAI,iCAAe,CAAC,OAAO,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-runtime-validation",
3
- "version": "1.0.1",
3
+ "version": "1.0.4",
4
4
  "author": "Matthew Duong <thegalah@gmail.com>",
5
5
  "license": "MIT",
6
6
  "dependencies": {
@@ -11,7 +11,7 @@
11
11
  "typescript-json-schema": "^0.53.0"
12
12
  },
13
13
  "bin": {
14
- "ts-runtime-check": "dist/index.js"
14
+ "ts-runtime-validation": "dist/index.js"
15
15
  },
16
16
  "scripts": {
17
17
  "build": "tsc",
@@ -28,12 +28,12 @@
28
28
  "main": "index.js",
29
29
  "repository": {
30
30
  "type": "git",
31
- "url": "git+https://github.com/thegalah/ts-runtime-check.git"
31
+ "url": "git+https://github.com/thegalah/ts-runtime-validation.git"
32
32
  },
33
33
  "bugs": {
34
- "url": "https://github.com/thegalah/ts-runtime-check/issues"
34
+ "url": "https://github.com/thegalah/ts-runtime-validation/issues"
35
35
  },
36
- "homepage": "https://github.com/thegalah/ts-runtime-check#readme",
36
+ "homepage": "https://github.com/thegalah/ts-runtime-validation#readme",
37
37
  "peerDependencies": {
38
38
  "ajv": "^8.11.0"
39
39
  }
package/src/index.ts CHANGED
@@ -6,7 +6,7 @@ import { program } from "commander";
6
6
  const defaultGlobPattern = "*.jsonschema.{ts,tsx}";
7
7
 
8
8
  const defaultRootPath = "./src";
9
- const defaultOutputFolder = "./.ts-runtime-check";
9
+ const defaultOutputFolder = "./.ts-runtime-validation";
10
10
 
11
11
  export interface ICommandOptions {
12
12
  readonly glob: string;
@@ -1,51 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- var desc = Object.getOwnPropertyDescriptor(m, k);
6
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k]; } };
8
- }
9
- Object.defineProperty(o, k2, desc);
10
- }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k;
12
- o[k2] = m[k];
13
- }));
14
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
- Object.defineProperty(o, "default", { enumerable: true, value: v });
16
- }) : function(o, v) {
17
- o["default"] = v;
18
- });
19
- var __importStar = (this && this.__importStar) || function (mod) {
20
- if (mod && mod.__esModule) return mod;
21
- var result = {};
22
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
- __setModuleDefault(result, mod);
24
- return result;
25
- };
26
- Object.defineProperty(exports, "__esModule", { value: true });
27
- const path_1 = require("path");
28
- const TJS = __importStar(require("typescript-json-schema"));
29
- // optionally pass argument to schema generator
30
- const settings = {
31
- required: true,
32
- };
33
- // optionally pass ts compiler options
34
- const compilerOptions = {
35
- strictNullChecks: true,
36
- };
37
- // optionally pass a base path
38
- const basePath = "./my-dir";
39
- const program = TJS.getProgramFromFiles([(0, path_1.resolve)("my-file.ts")], compilerOptions, basePath);
40
- // We can either get the schema for one file and one type...
41
- const schema = TJS.generateSchema(program, "MyType", settings);
42
- // ... or a generator that lets us incrementally get more schemas
43
- const generator = TJS.buildGenerator(program, settings);
44
- // generator can be also reused to speed up generating the schema if usecase allows:
45
- const schemaWithReusedGenerator = TJS.generateSchema(program, "MyType", settings, [], generator);
46
- // all symbols
47
- const symbols = generator.getUserSymbols();
48
- // Get symbols for different types from generator.
49
- generator.getSchemaForSymbol("MyType");
50
- generator.getSchemaForSymbol("AnotherType");
51
- //# sourceMappingURL=generateSchema.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generateSchema.js","sourceRoot":"","sources":["../src/generateSchema.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,+BAA+B;AAE/B,4DAA8C;AAE9C,+CAA+C;AAC/C,MAAM,QAAQ,GAAoB;IAC9B,QAAQ,EAAE,IAAI;CACjB,CAAC;AAEF,sCAAsC;AACtC,MAAM,eAAe,GAAwB;IACzC,gBAAgB,EAAE,IAAI;CACzB,CAAC;AAEF,8BAA8B;AAC9B,MAAM,QAAQ,GAAG,UAAU,CAAC;AAE5B,MAAM,OAAO,GAAG,GAAG,CAAC,mBAAmB,CAAC,CAAC,IAAA,cAAO,EAAC,YAAY,CAAC,CAAC,EAAE,eAAe,EAAE,QAAQ,CAAC,CAAC;AAE5F,4DAA4D;AAC5D,MAAM,MAAM,GAAG,GAAG,CAAC,cAAc,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAE/D,iEAAiE;AAEjE,MAAM,SAAS,GAAG,GAAG,CAAC,cAAc,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;AAExD,oFAAoF;AACpF,MAAM,yBAAyB,GAAG,GAAG,CAAC,cAAc,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,CAAC,CAAC;AAEjG,cAAc;AACd,MAAM,OAAO,GAAG,SAAS,CAAC,cAAc,EAAE,CAAC;AAE3C,kDAAkD;AAClD,SAAS,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC;AACvC,SAAS,CAAC,kBAAkB,CAAC,aAAa,CAAC,CAAC"}