@trayio/tray-schema 0.33.0 → 0.35.0

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/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Tray.io, Inc
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,9 @@
1
+ import * as TJS from 'typescript-json-schema';
2
+ import { Either } from 'fp-ts/Either';
3
+ import { DynamicObject } from '@trayio/tray-commons/dynamictype/DynamicType';
4
+ import { TraySchemaGenerator } from './TraySchemaGenerator';
5
+ export declare class TJSTraySchemaGenerator implements TraySchemaGenerator {
6
+ generateFromType(type: string, path: string): Either<Error, DynamicObject>;
7
+ jsonSchemaToTraySchema(schema: TJS.Definition): TJS.Definition;
8
+ }
9
+ //# sourceMappingURL=TJSTraySchemaGenerator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TJSTraySchemaGenerator.d.ts","sourceRoot":"","sources":["../../src/schema/TJSTraySchemaGenerator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,GAAG,MAAM,wBAAwB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAe,MAAM,cAAc,CAAC;AAEnD,OAAO,EAAE,aAAa,EAAE,MAAM,8CAA8C,CAAC;AAC7E,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,qBAAa,sBAAuB,YAAW,mBAAmB;IACjE,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,aAAa,CAAC;IA2B1E,sBAAsB,CAAC,MAAM,EAAE,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC,UAAU;CAsF9D"}
@@ -23,13 +23,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.TJSTraySchemaTypeTransformer = void 0;
26
+ exports.TJSTraySchemaGenerator = void 0;
27
27
  const path_1 = require("path");
28
28
  const TJS = __importStar(require("typescript-json-schema"));
29
29
  const Either_1 = require("fp-ts/Either");
30
30
  const lodash_1 = require("lodash");
31
- class TJSTraySchemaTypeTransformer {
32
- generateFromTypes(type, path) {
31
+ class TJSTraySchemaGenerator {
32
+ generateFromType(type, path) {
33
33
  const settings = {
34
34
  // this will prevent creating references in the schema when references are used in the types
35
35
  ref: false,
@@ -37,6 +37,8 @@ class TJSTraySchemaTypeTransformer {
37
37
  validationKeywords: ['lookupInput', 'lookupOperation', 'enumLabels'],
38
38
  // adds a required array to every entitiy in the schema which describes which children are required
39
39
  required: true,
40
+ // adds "additionalProperties: false" to the schemas
41
+ noExtraProps: true,
40
42
  };
41
43
  const compilerOptions = {
42
44
  strictNullChecks: true,
@@ -133,4 +135,4 @@ class TJSTraySchemaTypeTransformer {
133
135
  return schema;
134
136
  }
135
137
  }
136
- exports.TJSTraySchemaTypeTransformer = TJSTraySchemaTypeTransformer;
138
+ exports.TJSTraySchemaGenerator = TJSTraySchemaGenerator;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=TJSTraySchemaGenerator.unit.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TJSTraySchemaGenerator.unit.test.d.ts","sourceRoot":"","sources":["../../src/schema/TJSTraySchemaGenerator.unit.test.ts"],"names":[],"mappings":""}
@@ -25,13 +25,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  const E = __importStar(require("fp-ts/Either"));
27
27
  const path_1 = require("path");
28
- const TJSTraySchemaTypeTransformer_1 = require("./TJSTraySchemaTypeTransformer");
29
- describe('TJSTraySchemaTypeTransformer', () => {
28
+ const TJSTraySchemaGenerator_1 = require("./TJSTraySchemaGenerator");
29
+ describe('TJSTraySchemaGenerator', () => {
30
30
  it('Generates data types', () => {
31
31
  const type = 'Input';
32
32
  const dirPath = __dirname;
33
- const path = (0, path_1.join)(dirPath, 'datatypes.test.data.ts');
34
- const result = new TJSTraySchemaTypeTransformer_1.TJSTraySchemaTypeTransformer().generateFromTypes(type, path);
33
+ const path = (0, path_1.join)(dirPath, 'dataTypes.test.data.ts');
34
+ const result = new TJSTraySchemaGenerator_1.TJSTraySchemaGenerator().generateFromType(type, path);
35
35
  const actual = E.getOrElse((error) => {
36
36
  console.warn(error);
37
37
  throw new Error(`Failed to generate JSON schema from type`);
@@ -50,6 +50,7 @@ describe('TJSTraySchemaTypeTransformer', () => {
50
50
  },
51
51
  },
52
52
  required: ['arr', 'bool', 'int', 'num', 'obj', 'str'],
53
+ additionalProperties: false,
53
54
  $schema: 'http://json-schema.org/draft-07/schema#',
54
55
  };
55
56
  expect(actual).toEqual(expected);
@@ -58,7 +59,7 @@ describe('TJSTraySchemaTypeTransformer', () => {
58
59
  const type = 'Input';
59
60
  const dirPath = __dirname;
60
61
  const path = (0, path_1.join)(dirPath, 'importsReusable.test.data.ts');
61
- const result = new TJSTraySchemaTypeTransformer_1.TJSTraySchemaTypeTransformer().generateFromTypes(type, path);
62
+ const result = new TJSTraySchemaGenerator_1.TJSTraySchemaGenerator().generateFromType(type, path);
62
63
  const actual = E.getOrElse((error) => {
63
64
  console.warn(error);
64
65
  throw new Error(`Failed to generate JSON schema from type`);
@@ -74,16 +75,18 @@ describe('TJSTraySchemaTypeTransformer', () => {
74
75
  reusableFieldB: { type: 'string' },
75
76
  },
76
77
  required: ['reusableFieldA', 'reusableFieldB'],
78
+ additionalProperties: false,
77
79
  },
78
80
  reusableSchemaA: { type: 'number' },
79
81
  reusableSchemaB: { type: 'string' },
80
82
  },
81
83
  required: [
82
84
  'reusableFields',
83
- 'specificField',
84
85
  'reusableSchemaA',
85
86
  'reusableSchemaB',
87
+ 'specificField',
86
88
  ],
89
+ additionalProperties: false,
87
90
  $schema: 'http://json-schema.org/draft-07/schema#',
88
91
  };
89
92
  expect(actual).toEqual(expected);
@@ -92,7 +95,7 @@ describe('TJSTraySchemaTypeTransformer', () => {
92
95
  const type = 'Input';
93
96
  const dirPath = __dirname;
94
97
  const path = (0, path_1.join)(dirPath, 'oneOf.test.data.ts');
95
- const result = new TJSTraySchemaTypeTransformer_1.TJSTraySchemaTypeTransformer().generateFromTypes(type, path);
98
+ const result = new TJSTraySchemaGenerator_1.TJSTraySchemaGenerator().generateFromType(type, path);
96
99
  const actual = E.getOrElse((error) => {
97
100
  console.warn(error);
98
101
  throw new Error(`Failed to generate JSON schema from type`);
@@ -118,16 +121,19 @@ describe('TJSTraySchemaTypeTransformer', () => {
118
121
  metadata: { type: 'string' },
119
122
  },
120
123
  required: ['metadata', 'path'],
124
+ additionalProperties: false,
121
125
  },
122
126
  {
123
127
  type: 'object',
124
128
  properties: { imgId: { type: 'number' } },
125
129
  required: ['imgId'],
130
+ additionalProperties: false,
126
131
  },
127
132
  ],
128
133
  },
129
134
  },
130
135
  required: ['src'],
136
+ additionalProperties: false,
131
137
  },
132
138
  {
133
139
  type: 'object',
@@ -139,12 +145,14 @@ describe('TJSTraySchemaTypeTransformer', () => {
139
145
  },
140
146
  },
141
147
  required: ['msg'],
148
+ additionalProperties: false,
142
149
  },
143
150
  ],
144
151
  },
145
152
  },
146
153
  },
147
154
  required: ['elements'],
155
+ additionalProperties: false,
148
156
  $schema: 'http://json-schema.org/draft-07/schema#',
149
157
  };
150
158
  expect(actual).toEqual(expected);
@@ -153,7 +161,7 @@ describe('TJSTraySchemaTypeTransformer', () => {
153
161
  const type = 'Input';
154
162
  const dirPath = __dirname;
155
163
  const path = (0, path_1.join)(dirPath, 'enum.test.data.ts');
156
- const result = new TJSTraySchemaTypeTransformer_1.TJSTraySchemaTypeTransformer().generateFromTypes(type, path);
164
+ const result = new TJSTraySchemaGenerator_1.TJSTraySchemaGenerator().generateFromType(type, path);
157
165
  const actual = E.getOrElse((error) => {
158
166
  console.warn(error);
159
167
  throw new Error(`Failed to generate JSON schema from type`);
@@ -175,10 +183,12 @@ describe('TJSTraySchemaTypeTransformer', () => {
175
183
  },
176
184
  },
177
185
  required: ['text', 'type'],
186
+ additionalProperties: false,
178
187
  },
179
188
  },
180
189
  },
181
190
  required: ['actions'],
191
+ additionalProperties: false,
182
192
  $schema: 'http://json-schema.org/draft-07/schema#',
183
193
  };
184
194
  expect(actual).toEqual(expected);
@@ -187,7 +197,7 @@ describe('TJSTraySchemaTypeTransformer', () => {
187
197
  const type = 'Input';
188
198
  const dirPath = __dirname;
189
199
  const path = (0, path_1.join)(dirPath, 'ddl.test.data.ts');
190
- const result = new TJSTraySchemaTypeTransformer_1.TJSTraySchemaTypeTransformer().generateFromTypes(type, path);
200
+ const result = new TJSTraySchemaGenerator_1.TJSTraySchemaGenerator().generateFromType(type, path);
191
201
  const actual = E.getOrElse((error) => {
192
202
  console.warn(error);
193
203
  throw new Error(`Failed to generate JSON schema from type`);
@@ -207,6 +217,7 @@ describe('TJSTraySchemaTypeTransformer', () => {
207
217
  },
208
218
  },
209
219
  required: ['emails'],
220
+ additionalProperties: false,
210
221
  $schema: 'http://json-schema.org/draft-07/schema#',
211
222
  };
212
223
  expect(actual).toEqual(expected);
@@ -215,7 +226,7 @@ describe('TJSTraySchemaTypeTransformer', () => {
215
226
  const type = 'Input';
216
227
  const dirPath = __dirname;
217
228
  const path = (0, path_1.join)(dirPath, 'required.test.data.ts');
218
- const result = new TJSTraySchemaTypeTransformer_1.TJSTraySchemaTypeTransformer().generateFromTypes(type, path);
229
+ const result = new TJSTraySchemaGenerator_1.TJSTraySchemaGenerator().generateFromType(type, path);
219
230
  const actual = E.getOrElse((error) => {
220
231
  console.warn(error);
221
232
  throw new Error(`Failed to generate JSON schema from type`);
@@ -227,6 +238,7 @@ describe('TJSTraySchemaTypeTransformer', () => {
227
238
  optionalField: { type: 'string' },
228
239
  },
229
240
  required: ['mandatoryField'],
241
+ additionalProperties: false,
230
242
  $schema: 'http://json-schema.org/draft-07/schema#',
231
243
  };
232
244
  expect(actual).toEqual(expected);
@@ -235,7 +247,7 @@ describe('TJSTraySchemaTypeTransformer', () => {
235
247
  const type = 'Input';
236
248
  const dirPath = __dirname;
237
249
  const path = (0, path_1.join)(dirPath, 'format.test.data.ts');
238
- const result = new TJSTraySchemaTypeTransformer_1.TJSTraySchemaTypeTransformer().generateFromTypes(type, path);
250
+ const result = new TJSTraySchemaGenerator_1.TJSTraySchemaGenerator().generateFromType(type, path);
239
251
  const actual = E.getOrElse((error) => {
240
252
  console.warn(error);
241
253
  throw new Error(`Failed to generate JSON schema from type`);
@@ -250,6 +262,7 @@ describe('TJSTraySchemaTypeTransformer', () => {
250
262
  file: { format: 'file', type: 'string' },
251
263
  },
252
264
  required: ['file', 'html', 'longNotes', 'password', 'timestamp'],
265
+ additionalProperties: false,
253
266
  $schema: 'http://json-schema.org/draft-07/schema#',
254
267
  };
255
268
  expect(actual).toEqual(expected);
@@ -258,7 +271,7 @@ describe('TJSTraySchemaTypeTransformer', () => {
258
271
  const type = 'Input';
259
272
  const dirPath = __dirname;
260
273
  const path = (0, path_1.join)(dirPath, 'default.test.data.ts');
261
- const result = new TJSTraySchemaTypeTransformer_1.TJSTraySchemaTypeTransformer().generateFromTypes(type, path);
274
+ const result = new TJSTraySchemaGenerator_1.TJSTraySchemaGenerator().generateFromType(type, path);
262
275
  const actual = E.getOrElse((error) => {
263
276
  console.warn(error);
264
277
  throw new Error(`Failed to generate JSON schema from type`);
@@ -283,6 +296,7 @@ describe('TJSTraySchemaTypeTransformer', () => {
283
296
  },
284
297
  },
285
298
  required: ['arr', 'bool', 'int', 'num', 'obj', 'str'],
299
+ additionalProperties: false,
286
300
  $schema: 'http://json-schema.org/draft-07/schema#',
287
301
  };
288
302
  expect(actual).toEqual(expected);
@@ -0,0 +1,6 @@
1
+ import { Either } from 'fp-ts/lib/Either';
2
+ import { DynamicObject } from '@trayio/tray-commons/dynamictype/DynamicType';
3
+ export interface TraySchemaGenerator {
4
+ generateFromType(type: string, path: string): Either<Error, DynamicObject>;
5
+ }
6
+ //# sourceMappingURL=TraySchemaGenerator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TraySchemaGenerator.d.ts","sourceRoot":"","sources":["../../src/schema/TraySchemaGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,8CAA8C,CAAC;AAE7E,MAAM,WAAW,mBAAmB;IACnC,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;CAC3E"}
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@trayio/tray-schema",
3
- "version": "0.33.0",
3
+ "version": "0.35.0",
4
4
  "description": "Vanilla typescript code with extensions to the language or basic features",
5
5
  "exports": {
6
6
  "./*": "./dist/*.js"
7
7
  },
8
8
  "author": "Tray.io",
9
- "license": "Proprietary",
9
+ "license": "MIT",
10
10
  "publishConfig": {
11
11
  "access": "public"
12
12
  },
13
13
  "dependencies": {
14
- "@trayio/tray-commons": "0.33.0",
15
- "@types/node": "18.7.18",
14
+ "@trayio/tray-commons": "0.35.0",
15
+ "@types/node": "18.11.9",
16
16
  "lodash": "4.17.5",
17
17
  "typescript-json-schema": "0.61.0"
18
18
  },
@@ -1,9 +0,0 @@
1
- import * as TJS from 'typescript-json-schema';
2
- import { Either } from 'fp-ts/Either';
3
- import { DynamicObject } from '@trayio/tray-commons/dynamictype/DynamicType';
4
- import { TraySchemaTypeTransformer } from './TraySchemaTypeTransformer';
5
- export declare class TJSTraySchemaTypeTransformer implements TraySchemaTypeTransformer {
6
- generateFromTypes(type: string, path: string): Either<Error, DynamicObject>;
7
- jsonSchemaToTraySchema(schema: TJS.Definition): TJS.Definition;
8
- }
9
- //# sourceMappingURL=TJSTraySchemaTypeTransformer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TJSTraySchemaTypeTransformer.d.ts","sourceRoot":"","sources":["../../src/schema/TJSTraySchemaTypeTransformer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,GAAG,MAAM,wBAAwB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAe,MAAM,cAAc,CAAC;AAEnD,OAAO,EAAE,aAAa,EAAE,MAAM,8CAA8C,CAAC;AAC7E,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAExE,qBAAa,4BAA6B,YAAW,yBAAyB;IAC7E,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,aAAa,CAAC;IAyB3E,sBAAsB,CAAC,MAAM,EAAE,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC,UAAU;CAsF9D"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=TJSTraySchemaTypeTransformer.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TJSTraySchemaTypeTransformer.test.d.ts","sourceRoot":"","sources":["../../src/schema/TJSTraySchemaTypeTransformer.test.ts"],"names":[],"mappings":""}
@@ -1,6 +0,0 @@
1
- import { Either } from 'fp-ts/lib/Either';
2
- import { DynamicObject } from '@trayio/tray-commons/dynamictype/DynamicType';
3
- export interface TraySchemaTypeTransformer {
4
- generateFromTypes(type: string, path: string): Either<Error, DynamicObject>;
5
- }
6
- //# sourceMappingURL=TraySchemaTypeTransformer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TraySchemaTypeTransformer.d.ts","sourceRoot":"","sources":["../../src/schema/TraySchemaTypeTransformer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,8CAA8C,CAAC;AAE7E,MAAM,WAAW,yBAAyB;IACzC,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;CAC5E"}