@trayio/tray-schema 0.0.1-beta

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.
Files changed (57) hide show
  1. package/LICENSE.txt +22 -0
  2. package/README.md +70 -0
  3. package/dist/schema/LegacyTraySchemaConverter.d.ts +11 -0
  4. package/dist/schema/LegacyTraySchemaConverter.d.ts.map +1 -0
  5. package/dist/schema/LegacyTraySchemaConverter.js +61 -0
  6. package/dist/schema/LegacyTraySchemaConverter.unit.test.d.ts +2 -0
  7. package/dist/schema/LegacyTraySchemaConverter.unit.test.d.ts.map +1 -0
  8. package/dist/schema/LegacyTraySchemaConverter.unit.test.js +469 -0
  9. package/dist/schema/TJSTraySchemaGenerator.d.ts +9 -0
  10. package/dist/schema/TJSTraySchemaGenerator.d.ts.map +1 -0
  11. package/dist/schema/TJSTraySchemaGenerator.js +163 -0
  12. package/dist/schema/TJSTraySchemaGenerator.unit.test.d.ts +2 -0
  13. package/dist/schema/TJSTraySchemaGenerator.unit.test.d.ts.map +1 -0
  14. package/dist/schema/TJSTraySchemaGenerator.unit.test.js +432 -0
  15. package/dist/schema/TraySchemaGenerator.d.ts +6 -0
  16. package/dist/schema/TraySchemaGenerator.d.ts.map +1 -0
  17. package/dist/schema/TraySchemaGenerator.js +2 -0
  18. package/dist/schema/advanced.test.data.d.ts +14 -0
  19. package/dist/schema/advanced.test.data.d.ts.map +1 -0
  20. package/dist/schema/advanced.test.data.js +2 -0
  21. package/dist/schema/dataTypes.test.data.d.ts +12 -0
  22. package/dist/schema/dataTypes.test.data.d.ts.map +1 -0
  23. package/dist/schema/dataTypes.test.data.js +2 -0
  24. package/dist/schema/ddl.test.data.d.ts +8 -0
  25. package/dist/schema/ddl.test.data.d.ts.map +1 -0
  26. package/dist/schema/ddl.test.data.js +2 -0
  27. package/dist/schema/ddlAuth.test.data.d.ts +9 -0
  28. package/dist/schema/ddlAuth.test.data.d.ts.map +1 -0
  29. package/dist/schema/ddlAuth.test.data.js +2 -0
  30. package/dist/schema/default.test.data.d.ts +28 -0
  31. package/dist/schema/default.test.data.d.ts.map +1 -0
  32. package/dist/schema/default.test.data.js +2 -0
  33. package/dist/schema/enum.test.data.d.ts +17 -0
  34. package/dist/schema/enum.test.data.d.ts.map +1 -0
  35. package/dist/schema/enum.test.data.js +8 -0
  36. package/dist/schema/enumLabels.test.data.d.ts +20 -0
  37. package/dist/schema/enumLabels.test.data.d.ts.map +1 -0
  38. package/dist/schema/enumLabels.test.data.js +11 -0
  39. package/dist/schema/format.test.data.d.ts +23 -0
  40. package/dist/schema/format.test.data.d.ts.map +1 -0
  41. package/dist/schema/format.test.data.js +2 -0
  42. package/dist/schema/importsReusable.test.data.d.ts +9 -0
  43. package/dist/schema/importsReusable.test.data.d.ts.map +1 -0
  44. package/dist/schema/importsReusable.test.data.js +2 -0
  45. package/dist/schema/oneOf.test.data.d.ts +28 -0
  46. package/dist/schema/oneOf.test.data.d.ts.map +1 -0
  47. package/dist/schema/oneOf.test.data.js +2 -0
  48. package/dist/schema/required.test.data.d.ts +5 -0
  49. package/dist/schema/required.test.data.d.ts.map +1 -0
  50. package/dist/schema/required.test.data.js +2 -0
  51. package/dist/schema/reusableField.test.data.d.ts +5 -0
  52. package/dist/schema/reusableField.test.data.d.ts.map +1 -0
  53. package/dist/schema/reusableField.test.data.js +2 -0
  54. package/dist/schema/reusableSchema.test.data.d.ts +5 -0
  55. package/dist/schema/reusableSchema.test.data.d.ts.map +1 -0
  56. package/dist/schema/reusableSchema.test.data.js +2 -0
  57. package/package.json +30 -0
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.
package/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # Tray-schema
2
+ This module contains a collection of utilities for transforming and manipulating various representations of Tray's connector schema.
3
+
4
+ # TJSTraySchemaTypeTransformer
5
+
6
+ ## Overview
7
+ This part of the module takes a CDK connectors input or output typescript type definitions, along with any JSdoc annotations, and generates JSON schema representing these types. Specifically this format is Tray schema, otherwise known as CAPI schema, but importantly it is not the old way of writing connector JSON schema, which is reffered to as the legacy connector schema.
8
+
9
+ To generate the full schema for a connector this utility will be invoked for each operation's input and output. Operation metadata is pulled from the handler (using a different util) and then all of this schema is stiched together (using yet another different util) to produce the final connectors.json in Tray schema format. Which will then be transformed into legcay connector schema (by yet another different util) to ensure the connector works with the legacy deployment process.
10
+
11
+ Have a look at the example types used for unit tests within `src/TJSTraySchemaTypeTransformer/tests/` for examples of how to do different things with typescript and JSdoc.
12
+
13
+ ## Why use NPM lib typescript-json-schema
14
+
15
+ We found only 2 suitable libraries for converting typescript types to JSON schema:
16
+ - typescript-json-schema:
17
+ - It's functionality cannot be extended
18
+ - It won't throw an exception if you ask it to generate "invalid" schema
19
+ - ts-json-schema-generator
20
+ - Is an extension of typescript-json-schema
21
+ - It's functionality can be extended
22
+ - It will throw an exception if you ask it to generate "invalid" schema. And this is the main reason we did not chose this library, because this library sees some of the extra properties Tray schema has as invalid.
23
+
24
+ ## Post processing
25
+ To get around the non extendable nature of the typescript-json-schema lib we perform a number of different post processing steps on the generated JSON schema.
26
+ ## Enums
27
+ Tray schema supports enum labels so users can have a enum value which is sent and an enum label which is just displayed in the UI. Adding support for enum lables is trivial, until you realise that typescript-json-schema sorts the enums alphabetically. There are a few different ways to handle this, all of them are not ideal.
28
+
29
+ You can force the user to specify their enum, enum labels and enum order, which is incredibley cumbersome, they would have to write the enum list 4 times (its 4 not 3 because a TS enum needs a key and value).
30
+
31
+ For now we will not allow custom enum labels, instead we try to generate they best enum label possible automatically, in addition the order of enums can't be specified. We are planning on opening a PR to the typescript-json-schema lib to add a config option to disable this sorting. This way when we have this PR merged we can enable enum labels through the @enumLabel JSdoc annotation and it will be backwards compatible for end users.
32
+
33
+ ## Lookup / DDLs
34
+ Ideally DDLs would be defined in JSdoc like this, using the dot to target the property in the resulting JSON schema (e.g. @lookup.operation). Unfortunately this doesn't work with the typescript-json-schema library. So instead we use camelCased annotation names (e.g. @lookupOperation) and then use post processing to rearrange the schema. Potentially we could also raise a PR to the lib to add this dot notation support.
35
+ ```
36
+ // ideal input
37
+ export type Input = {
38
+ /**
39
+ * @lookup.operation list_users_actual_ddl
40
+ * @lookup.input {"include_private_channels": false,"workspace_id": "{{{workspace_id}}}"}
41
+ */
42
+ emails: string;
43
+ };
44
+
45
+ // actual input
46
+ export type Input = {
47
+ /**
48
+ * @lookupOperation list_users_actual_ddl
49
+ * @lookupInput {"include_private_channels": false,"workspace_id": "{{{workspace_id}}}"}
50
+ */
51
+ emails: string;
52
+ };
53
+
54
+ // Output
55
+ emails: {
56
+ type: 'string',
57
+ lookup: {
58
+ operation: 'list_users_actual_ddl',
59
+ input: {
60
+ include_private_channels: false,
61
+ workspace_id: '{{{workspace_id}}}',
62
+ },
63
+ },
64
+ },
65
+ ```
66
+
67
+ ## Advance fields not supported yet
68
+ Some more work is required to support advanced fields, which is when a field is hidden within the Tray UI in an expandable advanced section.
69
+
70
+ Would need to add a new JSdoc annotation @advanced, this will be added to each item of the schema though when it needs to be in an array, similar to how the required fields works. So post processing would be required to strip out the individual required: true on each item and combine them into an array at the parent item level.
@@ -0,0 +1,11 @@
1
+ import { DynamicObject } from '@trayio/commons/dynamictype/DynamicType';
2
+ export interface LegacyTraySchemaConverterInterface {
3
+ convertToLegacySchema(schema: DynamicObject): DynamicObject;
4
+ }
5
+ export declare class LegacyTraySchemaConverter implements LegacyTraySchemaConverterInterface {
6
+ convertToLegacySchema(schema: DynamicObject): DynamicObject;
7
+ private transformLookup;
8
+ private transformLookupInput;
9
+ private transformEnums;
10
+ }
11
+ //# sourceMappingURL=LegacyTraySchemaConverter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LegacyTraySchemaConverter.d.ts","sourceRoot":"","sources":["../../src/schema/LegacyTraySchemaConverter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAExE,MAAM,WAAW,kCAAkC;IAClD,qBAAqB,CAAC,MAAM,EAAE,aAAa,GAAG,aAAa,CAAC;CAC5D;AAED,qBAAa,yBACZ,YAAW,kCAAkC;IAE7C,qBAAqB,CAAC,MAAM,EAAE,aAAa,GAAG,aAAa;IAY3D,OAAO,CAAC,eAAe,CAsBrB;IAEF,OAAO,CAAC,oBAAoB,CAc1B;IAEF,OAAO,CAAC,cAAc,CAoBpB;CACF"}
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LegacyTraySchemaConverter = void 0;
4
+ class LegacyTraySchemaConverter {
5
+ constructor() {
6
+ this.transformLookup = (object) => {
7
+ if (typeof object !== 'object' || object === null)
8
+ return object;
9
+ if (object.lookup &&
10
+ object.lookup.operation &&
11
+ object.lookup.input) {
12
+ const lookup = object.lookup;
13
+ object.lookup = {
14
+ url: '{{{step.ephemeral_url}}}',
15
+ body: Object.assign({ step_settings: this.transformLookupInput(lookup.input), message: lookup.operation }, (lookup.authRequired && { auth_id: '{{{step.auth_id}}}' })),
16
+ };
17
+ }
18
+ return object;
19
+ };
20
+ this.transformLookupInput = (input) => {
21
+ if (typeof input !== 'object' || input === null)
22
+ return input;
23
+ const result = {};
24
+ Object.keys(input).forEach((key) => {
25
+ result[key] = {
26
+ value: typeof input[key] === 'object'
27
+ ? this.transformLookupInput(input[key])
28
+ : input[key],
29
+ type: typeof input[key],
30
+ };
31
+ });
32
+ return result;
33
+ };
34
+ this.transformEnums = (object) => {
35
+ if (typeof object !== 'object' || object === null)
36
+ return object;
37
+ if (object.enum &&
38
+ object.enumLabels &&
39
+ Array.isArray(object.enum) &&
40
+ Array.isArray(object.enumLabels)) {
41
+ object.enum = object.enum.map((enumItem, index) => ({
42
+ value: enumItem,
43
+ text: object.enumLabels[index],
44
+ }));
45
+ delete object.enumLabels;
46
+ }
47
+ return object;
48
+ };
49
+ }
50
+ convertToLegacySchema(schema) {
51
+ for (const [key, value] of Object.entries(schema)) {
52
+ if (typeof value === 'object' && value !== null) {
53
+ this.transformLookup(value);
54
+ this.transformEnums(value);
55
+ this.convertToLegacySchema(value);
56
+ }
57
+ }
58
+ return schema;
59
+ }
60
+ }
61
+ exports.LegacyTraySchemaConverter = LegacyTraySchemaConverter;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=LegacyTraySchemaConverter.unit.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LegacyTraySchemaConverter.unit.test.d.ts","sourceRoot":"","sources":["../../src/schema/LegacyTraySchemaConverter.unit.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,469 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const LegacyTraySchemaConverter_1 = require("./LegacyTraySchemaConverter");
4
+ describe('LegacyTraySchemaConverter', () => {
5
+ const converter = new LegacyTraySchemaConverter_1.LegacyTraySchemaConverter();
6
+ describe('convertToLegacySchema', () => {
7
+ it('should convert a connector schema with a lookup to legacy schema', () => {
8
+ const schema = {
9
+ type: 'object',
10
+ properties: {
11
+ id: {
12
+ type: 'number',
13
+ lookup: {
14
+ operation: 'list_tables_ddl',
15
+ input: {
16
+ workspace_id: '{{{workspace_id}}}',
17
+ project_id: '{{{project_id}}}',
18
+ service: {
19
+ name: '{{{service_name}}}',
20
+ version: 1,
21
+ },
22
+ },
23
+ },
24
+ },
25
+ },
26
+ additionalProperties: false,
27
+ required: ['id'],
28
+ $schema: 'http://json-schema.org/draft-07/schema#',
29
+ advanced: [],
30
+ };
31
+ const expected = {
32
+ type: 'object',
33
+ properties: {
34
+ id: {
35
+ type: 'number',
36
+ lookup: {
37
+ url: '{{{step.ephemeral_url}}}',
38
+ body: {
39
+ step_settings: {
40
+ workspace_id: {
41
+ value: '{{{workspace_id}}}',
42
+ type: 'string',
43
+ },
44
+ project_id: {
45
+ value: '{{{project_id}}}',
46
+ type: 'string',
47
+ },
48
+ service: {
49
+ type: 'object',
50
+ value: {
51
+ name: {
52
+ value: '{{{service_name}}}',
53
+ type: 'string',
54
+ },
55
+ version: {
56
+ value: 1,
57
+ type: 'number',
58
+ },
59
+ },
60
+ },
61
+ },
62
+ message: 'list_tables_ddl',
63
+ },
64
+ },
65
+ },
66
+ },
67
+ additionalProperties: false,
68
+ required: ['id'],
69
+ $schema: 'http://json-schema.org/draft-07/schema#',
70
+ advanced: [],
71
+ };
72
+ const result = converter.convertToLegacySchema(schema);
73
+ expect(result).toEqual(expected);
74
+ });
75
+ it('should convert a connector schema with a lookup and include authId on DDL when authRequired is true', () => {
76
+ const schema = {
77
+ type: 'object',
78
+ properties: {
79
+ id: {
80
+ type: 'number',
81
+ lookup: {
82
+ operation: 'list_tables_ddl',
83
+ input: {
84
+ workspace_id: '{{{workspace_id}}}',
85
+ project_id: '{{{project_id}}}',
86
+ service: {
87
+ name: '{{{service_name}}}',
88
+ version: 1,
89
+ },
90
+ },
91
+ authRequired: true,
92
+ },
93
+ },
94
+ },
95
+ additionalProperties: false,
96
+ required: ['id'],
97
+ $schema: 'http://json-schema.org/draft-07/schema#',
98
+ advanced: [],
99
+ };
100
+ const expected = {
101
+ type: 'object',
102
+ properties: {
103
+ id: {
104
+ type: 'number',
105
+ lookup: {
106
+ url: '{{{step.ephemeral_url}}}',
107
+ body: {
108
+ step_settings: {
109
+ workspace_id: {
110
+ value: '{{{workspace_id}}}',
111
+ type: 'string',
112
+ },
113
+ project_id: {
114
+ value: '{{{project_id}}}',
115
+ type: 'string',
116
+ },
117
+ service: {
118
+ type: 'object',
119
+ value: {
120
+ name: {
121
+ value: '{{{service_name}}}',
122
+ type: 'string',
123
+ },
124
+ version: {
125
+ value: 1,
126
+ type: 'number',
127
+ },
128
+ },
129
+ },
130
+ },
131
+ message: 'list_tables_ddl',
132
+ auth_id: '{{{step.auth_id}}}',
133
+ },
134
+ },
135
+ },
136
+ },
137
+ additionalProperties: false,
138
+ required: ['id'],
139
+ $schema: 'http://json-schema.org/draft-07/schema#',
140
+ advanced: [],
141
+ };
142
+ const result = converter.convertToLegacySchema(schema);
143
+ expect(result).toEqual(expected);
144
+ });
145
+ it('should convert a connector schema with a lookup to legacy schema and also has a lookup field', () => {
146
+ const schema = {
147
+ type: 'object',
148
+ properties: {
149
+ id: {
150
+ type: 'number',
151
+ lookup: {
152
+ operation: 'list_tables_ddl',
153
+ input: {
154
+ workspace_id: '{{{workspace_id}}}',
155
+ project_id: '{{{project_id}}}',
156
+ },
157
+ },
158
+ },
159
+ lookup: {
160
+ type: 'string',
161
+ lookup: {
162
+ operation: 'list_tables_ddl',
163
+ input: {
164
+ workspace_id: '{{{workspace_id}}}',
165
+ project_id: '{{{project_id}}}',
166
+ },
167
+ },
168
+ },
169
+ },
170
+ additionalProperties: false,
171
+ required: ['id'],
172
+ $schema: 'http://json-schema.org/draft-07/schema#',
173
+ advanced: [],
174
+ };
175
+ const expected = {
176
+ type: 'object',
177
+ properties: {
178
+ id: {
179
+ type: 'number',
180
+ lookup: {
181
+ url: '{{{step.ephemeral_url}}}',
182
+ body: {
183
+ step_settings: {
184
+ workspace_id: {
185
+ value: '{{{workspace_id}}}',
186
+ type: 'string',
187
+ },
188
+ project_id: {
189
+ value: '{{{project_id}}}',
190
+ type: 'string',
191
+ },
192
+ },
193
+ message: 'list_tables_ddl',
194
+ },
195
+ },
196
+ },
197
+ lookup: {
198
+ type: 'string',
199
+ lookup: {
200
+ url: '{{{step.ephemeral_url}}}',
201
+ body: {
202
+ step_settings: {
203
+ workspace_id: {
204
+ value: '{{{workspace_id}}}',
205
+ type: 'string',
206
+ },
207
+ project_id: {
208
+ value: '{{{project_id}}}',
209
+ type: 'string',
210
+ },
211
+ },
212
+ message: 'list_tables_ddl',
213
+ },
214
+ },
215
+ },
216
+ },
217
+ additionalProperties: false,
218
+ required: ['id'],
219
+ $schema: 'http://json-schema.org/draft-07/schema#',
220
+ advanced: [],
221
+ };
222
+ const result = converter.convertToLegacySchema(schema);
223
+ expect(result).toEqual(expected);
224
+ });
225
+ it('should convert a schema with an enum', () => {
226
+ const schema = {
227
+ type: 'object',
228
+ properties: {
229
+ actions: {
230
+ description: 'example dropdown',
231
+ type: 'array',
232
+ items: {
233
+ type: 'object',
234
+ properties: {
235
+ text: { type: 'string' },
236
+ type: {
237
+ type: 'string',
238
+ enum: ['default always', 'primary-one', 'the_danger'],
239
+ enumLabels: ['Default Always', 'Primary One', 'The Danger'],
240
+ },
241
+ },
242
+ additionalProperties: false,
243
+ required: ['text', 'type'],
244
+ advanced: [],
245
+ },
246
+ },
247
+ name: { type: 'string' },
248
+ },
249
+ additionalProperties: false,
250
+ required: ['actions', 'name'],
251
+ $schema: 'http://json-schema.org/draft-07/schema#',
252
+ advanced: [],
253
+ };
254
+ const expected = {
255
+ type: 'object',
256
+ properties: {
257
+ actions: {
258
+ description: 'example dropdown',
259
+ type: 'array',
260
+ items: {
261
+ type: 'object',
262
+ properties: {
263
+ text: { type: 'string' },
264
+ type: {
265
+ type: 'string',
266
+ enum: [
267
+ {
268
+ value: 'default always',
269
+ text: 'Default Always',
270
+ },
271
+ {
272
+ value: 'primary-one',
273
+ text: 'Primary One',
274
+ },
275
+ {
276
+ value: 'the_danger',
277
+ text: 'The Danger',
278
+ },
279
+ ],
280
+ },
281
+ },
282
+ additionalProperties: false,
283
+ required: ['text', 'type'],
284
+ advanced: [],
285
+ },
286
+ },
287
+ name: { type: 'string' },
288
+ },
289
+ required: ['actions', 'name'],
290
+ additionalProperties: false,
291
+ $schema: 'http://json-schema.org/draft-07/schema#',
292
+ advanced: [],
293
+ };
294
+ const result = converter.convertToLegacySchema(schema);
295
+ expect(result).toEqual(expected);
296
+ });
297
+ it('should convert a schema with an enum and a field name as enum', () => {
298
+ const schema = {
299
+ type: 'object',
300
+ properties: {
301
+ actions: {
302
+ description: 'example dropdown',
303
+ type: 'array',
304
+ items: {
305
+ type: 'object',
306
+ properties: {
307
+ text: { type: 'string' },
308
+ type: {
309
+ type: 'string',
310
+ enum: ['default always', 'primary-one', 'the_danger'],
311
+ enumLabels: ['Default Always', 'Primary One', 'The Danger'],
312
+ },
313
+ },
314
+ additionalProperties: false,
315
+ required: ['text', 'type'],
316
+ advanced: [],
317
+ },
318
+ },
319
+ enum: { type: 'string' },
320
+ },
321
+ additionalProperties: false,
322
+ required: ['actions', 'enum'],
323
+ $schema: 'http://json-schema.org/draft-07/schema#',
324
+ advanced: [],
325
+ };
326
+ const expected = {
327
+ type: 'object',
328
+ properties: {
329
+ actions: {
330
+ description: 'example dropdown',
331
+ type: 'array',
332
+ items: {
333
+ type: 'object',
334
+ properties: {
335
+ text: { type: 'string' },
336
+ type: {
337
+ type: 'string',
338
+ enum: [
339
+ {
340
+ value: 'default always',
341
+ text: 'Default Always',
342
+ },
343
+ {
344
+ value: 'primary-one',
345
+ text: 'Primary One',
346
+ },
347
+ {
348
+ value: 'the_danger',
349
+ text: 'The Danger',
350
+ },
351
+ ],
352
+ },
353
+ },
354
+ additionalProperties: false,
355
+ required: ['text', 'type'],
356
+ advanced: [],
357
+ },
358
+ },
359
+ enum: { type: 'string' },
360
+ },
361
+ additionalProperties: false,
362
+ required: ['actions', 'enum'],
363
+ $schema: 'http://json-schema.org/draft-07/schema#',
364
+ advanced: [],
365
+ };
366
+ const result = converter.convertToLegacySchema(schema);
367
+ expect(result).toEqual(expected);
368
+ });
369
+ it('should convert lookups and enums in nested objects', () => {
370
+ const schema = {
371
+ properties: {
372
+ id: {
373
+ type: 'object',
374
+ properties: {
375
+ lookup: {
376
+ input: {
377
+ input1: 'value1',
378
+ input2: 'value2',
379
+ },
380
+ operation: 'operation',
381
+ },
382
+ },
383
+ },
384
+ nested: {
385
+ properties: {
386
+ sort_by: {
387
+ type: {
388
+ type: 'string',
389
+ enum: ['value1', 'value2'],
390
+ enumLabels: ['Value 1', 'Value 2'],
391
+ },
392
+ },
393
+ },
394
+ },
395
+ },
396
+ };
397
+ const expected = {
398
+ properties: {
399
+ id: {
400
+ type: 'object',
401
+ properties: {
402
+ lookup: {
403
+ url: '{{{step.ephemeral_url}}}',
404
+ body: {
405
+ step_settings: {
406
+ input1: {
407
+ value: 'value1',
408
+ type: 'string',
409
+ },
410
+ input2: {
411
+ value: 'value2',
412
+ type: 'string',
413
+ },
414
+ },
415
+ message: 'operation',
416
+ },
417
+ },
418
+ },
419
+ },
420
+ nested: {
421
+ properties: {
422
+ sort_by: {
423
+ type: {
424
+ type: 'string',
425
+ enum: [
426
+ {
427
+ value: 'value1',
428
+ text: 'Value 1',
429
+ },
430
+ {
431
+ value: 'value2',
432
+ text: 'Value 2',
433
+ },
434
+ ],
435
+ },
436
+ },
437
+ },
438
+ },
439
+ },
440
+ };
441
+ const result = converter.convertToLegacySchema(schema);
442
+ expect(result).toEqual(expected);
443
+ });
444
+ it('should preserve the schema without a lookup and an enum', () => {
445
+ const schema = {
446
+ type: 'object',
447
+ properties: {
448
+ name: { type: 'string' },
449
+ },
450
+ additionalProperties: false,
451
+ required: ['actions'],
452
+ $schema: 'http://json-schema.org/draft-07/schema#',
453
+ advanced: [],
454
+ };
455
+ const expected = {
456
+ type: 'object',
457
+ properties: {
458
+ name: { type: 'string' },
459
+ },
460
+ additionalProperties: false,
461
+ required: ['actions'],
462
+ $schema: 'http://json-schema.org/draft-07/schema#',
463
+ advanced: [],
464
+ };
465
+ const result = converter.convertToLegacySchema(schema);
466
+ expect(result).toEqual(expected);
467
+ });
468
+ });
469
+ });
@@ -0,0 +1,9 @@
1
+ import * as TJS from 'typescript-json-schema';
2
+ import { Either } from 'fp-ts/Either';
3
+ import { DynamicObject } from '@trayio/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,yCAAyC,CAAC;AACxE,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;IAqC1E,sBAAsB,CAAC,MAAM,EAAE,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC,UAAU;CAwG9D"}