@trayio/tray-schema 0.34.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/dist/schema/TJSTraySchemaGenerator.d.ts +9 -0
- package/dist/schema/TJSTraySchemaGenerator.d.ts.map +1 -0
- package/dist/schema/{TJSTraySchemaTypeTransformer.js → TJSTraySchemaGenerator.js} +6 -4
- package/dist/schema/TJSTraySchemaGenerator.unit.test.d.ts +2 -0
- package/dist/schema/TJSTraySchemaGenerator.unit.test.d.ts.map +1 -0
- package/dist/schema/{TJSTraySchemaTypeTransformer.test.js → TJSTraySchemaGenerator.unit.test.js} +26 -12
- package/dist/schema/TraySchemaGenerator.d.ts +6 -0
- package/dist/schema/TraySchemaGenerator.d.ts.map +1 -0
- package/package.json +3 -3
- package/dist/schema/TJSTraySchemaTypeTransformer.d.ts +0 -9
- package/dist/schema/TJSTraySchemaTypeTransformer.d.ts.map +0 -1
- package/dist/schema/TJSTraySchemaTypeTransformer.test.d.ts +0 -2
- package/dist/schema/TJSTraySchemaTypeTransformer.test.d.ts.map +0 -1
- package/dist/schema/TraySchemaTypeTransformer.d.ts +0 -6
- package/dist/schema/TraySchemaTypeTransformer.d.ts.map +0 -1
- /package/dist/schema/{TraySchemaTypeTransformer.js → TraySchemaGenerator.js} +0 -0
|
@@ -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.
|
|
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
|
|
32
|
-
|
|
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.
|
|
138
|
+
exports.TJSTraySchemaGenerator = TJSTraySchemaGenerator;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TJSTraySchemaGenerator.unit.test.d.ts","sourceRoot":"","sources":["../../src/schema/TJSTraySchemaGenerator.unit.test.ts"],"names":[],"mappings":""}
|
package/dist/schema/{TJSTraySchemaTypeTransformer.test.js → TJSTraySchemaGenerator.unit.test.js}
RENAMED
|
@@ -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
|
|
29
|
-
describe('
|
|
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, '
|
|
34
|
-
const result = new
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trayio/tray-schema",
|
|
3
|
-
"version": "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"
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"access": "public"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@trayio/tray-commons": "0.
|
|
15
|
-
"@types/node": "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 +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"}
|
|
File without changes
|