@trayio/tray-schema 1.6.0 → 1.8.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/LegacyTraySchemaConverter.js +1 -5
- package/dist/schema/LegacyTraySchemaConverter.unit.test.js +70 -0
- package/dist/schema/TJSTraySchemaGenerator.d.ts.map +1 -1
- package/dist/schema/TJSTraySchemaGenerator.js +3 -0
- package/dist/schema/TJSTraySchemaGenerator.unit.test.js +31 -0
- package/dist/schema/ddlAuth.test.data.d.ts +9 -0
- package/dist/schema/ddlAuth.test.data.d.ts.map +1 -0
- package/dist/schema/ddlAuth.test.data.js +2 -0
- package/package.json +2 -2
|
@@ -12,11 +12,7 @@ class LegacyTraySchemaConverter {
|
|
|
12
12
|
const lookup = object.lookup;
|
|
13
13
|
object.lookup = {
|
|
14
14
|
url: '{{{step.ephemeral_url}}}',
|
|
15
|
-
body: {
|
|
16
|
-
step_settings: this.transformLookupInput(lookup.input),
|
|
17
|
-
// auth_id: '{{{step.auth_id}}}', //TODO add this conditionally, only needs to be added for connectors that use authentications
|
|
18
|
-
message: lookup.operation,
|
|
19
|
-
},
|
|
15
|
+
body: Object.assign({ step_settings: this.transformLookupInput(lookup.input), message: lookup.operation }, (lookup.authRequired && { auth_id: '{{{step.auth_id}}}' })),
|
|
20
16
|
};
|
|
21
17
|
}
|
|
22
18
|
return object;
|
|
@@ -72,6 +72,76 @@ describe('LegacyTraySchemaConverter', () => {
|
|
|
72
72
|
const result = converter.convertToLegacySchema(schema);
|
|
73
73
|
expect(result).toEqual(expected);
|
|
74
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
|
+
});
|
|
75
145
|
it('should convert a connector schema with a lookup to legacy schema and also has a lookup field', () => {
|
|
76
146
|
const schema = {
|
|
77
147
|
type: 'object',
|
|
@@ -1 +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;
|
|
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;IAiC1E,sBAAsB,CAAC,MAAM,EAAE,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC,UAAU;CAwG9D"}
|
|
@@ -37,6 +37,7 @@ class TJSTraySchemaGenerator {
|
|
|
37
37
|
validationKeywords: [
|
|
38
38
|
'lookupInput',
|
|
39
39
|
'lookupOperation',
|
|
40
|
+
'lookupAuthRequired',
|
|
40
41
|
'enumLabels',
|
|
41
42
|
'advanced',
|
|
42
43
|
],
|
|
@@ -63,9 +64,11 @@ class TJSTraySchemaGenerator {
|
|
|
63
64
|
object.lookup = {
|
|
64
65
|
operation: object.lookupOperation,
|
|
65
66
|
input: object.lookupInput,
|
|
67
|
+
authRequired: object.lookupAuthRequired,
|
|
66
68
|
};
|
|
67
69
|
delete object.lookupOperation;
|
|
68
70
|
delete object.lookupInput;
|
|
71
|
+
delete object.lookupAuthRequired;
|
|
69
72
|
}
|
|
70
73
|
};
|
|
71
74
|
const transformEnumLabels = (object) => {
|
|
@@ -281,6 +281,37 @@ describe('TJSTraySchemaGenerator', () => {
|
|
|
281
281
|
};
|
|
282
282
|
expect(actual).toEqual(expected);
|
|
283
283
|
});
|
|
284
|
+
it('Generates DDL lookup format including authRequired during post processing', () => {
|
|
285
|
+
const type = 'Input';
|
|
286
|
+
const dirPath = __dirname;
|
|
287
|
+
const path = (0, path_1.join)(dirPath, 'ddlAuth.test.data.ts');
|
|
288
|
+
const result = new TJSTraySchemaGenerator_1.TJSTraySchemaGenerator().generateFromType(type, path);
|
|
289
|
+
const actual = E.getOrElse((error) => {
|
|
290
|
+
console.warn(error);
|
|
291
|
+
throw new Error(`Failed to generate JSON schema from type`);
|
|
292
|
+
})(result);
|
|
293
|
+
const expected = {
|
|
294
|
+
type: 'object',
|
|
295
|
+
properties: {
|
|
296
|
+
emails: {
|
|
297
|
+
type: 'string',
|
|
298
|
+
lookup: {
|
|
299
|
+
operation: 'list_users_actual_ddl',
|
|
300
|
+
input: {
|
|
301
|
+
include_private_channels: false,
|
|
302
|
+
workspace_id: '{{{workspace_id}}}',
|
|
303
|
+
},
|
|
304
|
+
authRequired: true,
|
|
305
|
+
},
|
|
306
|
+
},
|
|
307
|
+
},
|
|
308
|
+
advanced: [],
|
|
309
|
+
required: ['emails'],
|
|
310
|
+
additionalProperties: false,
|
|
311
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
312
|
+
};
|
|
313
|
+
expect(actual).toEqual(expected);
|
|
314
|
+
});
|
|
284
315
|
it('Generates required fields array based on typescripts optional (?) symbol', () => {
|
|
285
316
|
const type = 'Input';
|
|
286
317
|
const dirPath = __dirname;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type Input = {
|
|
2
|
+
/**
|
|
3
|
+
* @lookupOperation list_users_actual_ddl
|
|
4
|
+
* @lookupInput {"include_private_channels": false,"workspace_id": "{{{workspace_id}}}"}
|
|
5
|
+
* @lookupAuthRequired true
|
|
6
|
+
*/
|
|
7
|
+
emails: string;
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=ddlAuth.test.data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ddlAuth.test.data.d.ts","sourceRoot":"","sources":["../../src/schema/ddlAuth.test.data.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,KAAK,GAAG;IACnB;;;;OAIG;IACH,MAAM,EAAE,MAAM,CAAC;CACf,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trayio/tray-schema",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "Schema for Tray connectors and authentications",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./*": "./dist/*.js"
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"access": "public"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@trayio/commons": "1.
|
|
14
|
+
"@trayio/commons": "1.8.0",
|
|
15
15
|
"@types/node": "18.11.9",
|
|
16
16
|
"lodash": "4.17.21",
|
|
17
17
|
"typescript-json-schema": "0.62.0"
|