@trayio/tray-openapi 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.
- package/LICENSE.txt +22 -0
- package/README.md +39 -0
- package/dist/OpenApiCodecs.d.ts +5 -0
- package/dist/OpenApiCodecs.d.ts.map +1 -0
- package/dist/OpenApiCodecs.js +8 -0
- package/dist/OpenApiSchemaImporter.d.ts +17 -0
- package/dist/OpenApiSchemaImporter.d.ts.map +1 -0
- package/dist/OpenApiSchemaImporter.js +138 -0
- package/dist/OpenApiSchemaImporter.test.d.ts +2 -0
- package/dist/OpenApiSchemaImporter.test.d.ts.map +1 -0
- package/dist/OpenApiSchemaImporter.test.js +85 -0
- package/dist/OpenApiSchemaTransformer.d.ts +9 -0
- package/dist/OpenApiSchemaTransformer.d.ts.map +1 -0
- package/dist/OpenApiSchemaTransformer.js +68 -0
- package/dist/OpenApiSchemaTransformer.test.d.ts +2 -0
- package/dist/OpenApiSchemaTransformer.test.d.ts.map +1 -0
- package/dist/OpenApiSchemaTransformer.test.js +118 -0
- package/dist/OpenApiTypeDescriptors.d.ts +109 -0
- package/dist/OpenApiTypeDescriptors.d.ts.map +1 -0
- package/dist/OpenApiTypeDescriptors.js +107 -0
- package/dist/file-generators/GenerateHandler.d.ts +15 -0
- package/dist/file-generators/GenerateHandler.d.ts.map +1 -0
- package/dist/file-generators/GenerateHandler.js +110 -0
- package/dist/file-generators/GenerateHandler.test.d.ts +2 -0
- package/dist/file-generators/GenerateHandler.test.d.ts.map +1 -0
- package/dist/file-generators/GenerateHandler.test.js +427 -0
- package/dist/file-generators/GenerateHandlerTest.d.ts +9 -0
- package/dist/file-generators/GenerateHandlerTest.d.ts.map +1 -0
- package/dist/file-generators/GenerateHandlerTest.js +88 -0
- package/dist/file-generators/GenerateHandlerTest.test.d.ts +2 -0
- package/dist/file-generators/GenerateHandlerTest.test.d.ts.map +1 -0
- package/dist/file-generators/GenerateHandlerTest.test.js +640 -0
- package/dist/file-generators/GenerateOperationJson.d.ts +4 -0
- package/dist/file-generators/GenerateOperationJson.d.ts.map +1 -0
- package/dist/file-generators/GenerateOperationJson.js +44 -0
- package/dist/file-generators/GenerateOperationJson.test.d.ts +2 -0
- package/dist/file-generators/GenerateOperationJson.test.d.ts.map +1 -0
- package/dist/file-generators/GenerateOperationJson.test.js +78 -0
- package/dist/file-generators/types/GenerateInputSchema.d.ts +4 -0
- package/dist/file-generators/types/GenerateInputSchema.d.ts.map +1 -0
- package/dist/file-generators/types/GenerateInputSchema.js +131 -0
- package/dist/file-generators/types/GenerateInputSchema.test.d.ts +2 -0
- package/dist/file-generators/types/GenerateInputSchema.test.d.ts.map +1 -0
- package/dist/file-generators/types/GenerateInputSchema.test.js +260 -0
- package/dist/file-generators/types/GenerateInputType.test.d.ts +2 -0
- package/dist/file-generators/types/GenerateInputType.test.d.ts.map +1 -0
- package/dist/file-generators/types/GenerateInputType.test.js +447 -0
- package/dist/file-generators/types/GenerateInputTypes.d.ts +4 -0
- package/dist/file-generators/types/GenerateInputTypes.d.ts.map +1 -0
- package/dist/file-generators/types/GenerateInputTypes.js +45 -0
- package/dist/file-generators/types/GenerateOutput.d.ts +8 -0
- package/dist/file-generators/types/GenerateOutput.d.ts.map +1 -0
- package/dist/file-generators/types/GenerateOutput.js +81 -0
- package/dist/file-generators/types/GenerateOutput.test.d.ts +2 -0
- package/dist/file-generators/types/GenerateOutput.test.d.ts.map +1 -0
- package/dist/file-generators/types/GenerateOutput.test.js +213 -0
- package/dist/file-generators/types/JsonSchemaToTypescriptOptions.d.ts +9 -0
- package/dist/file-generators/types/JsonSchemaToTypescriptOptions.d.ts.map +1 -0
- package/dist/file-generators/types/JsonSchemaToTypescriptOptions.js +11 -0
- package/dist/templates/connector-template.zip +0 -0
- package/dist/test-openapi-spec.json +160 -0
- package/package.json +30 -0
|
@@ -0,0 +1,640 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const E = __importStar(require("fp-ts/Either"));
|
|
27
|
+
const O = __importStar(require("fp-ts/Option"));
|
|
28
|
+
const GenerateHandlerTest_1 = require("./GenerateHandlerTest");
|
|
29
|
+
describe('GenerateHandlerTest', () => {
|
|
30
|
+
it('should generate a handler test with inputs and outputs', () => {
|
|
31
|
+
const input = {
|
|
32
|
+
operationNameCamelCase: 'getItem',
|
|
33
|
+
input: {
|
|
34
|
+
type: O.some('object'),
|
|
35
|
+
title: O.none,
|
|
36
|
+
properties: O.some({
|
|
37
|
+
id: {
|
|
38
|
+
title: O.none,
|
|
39
|
+
type: O.some('integer'),
|
|
40
|
+
format: 'int64',
|
|
41
|
+
properties: O.none,
|
|
42
|
+
required: O.none,
|
|
43
|
+
additionalProperties: O.some(false),
|
|
44
|
+
allOf: O.none,
|
|
45
|
+
anyOf: O.none,
|
|
46
|
+
oneOf: O.none,
|
|
47
|
+
not: O.none,
|
|
48
|
+
in: O.none,
|
|
49
|
+
},
|
|
50
|
+
name: {
|
|
51
|
+
title: O.none,
|
|
52
|
+
type: O.some('string'),
|
|
53
|
+
properties: O.none,
|
|
54
|
+
required: O.none,
|
|
55
|
+
additionalProperties: O.some(false),
|
|
56
|
+
allOf: O.none,
|
|
57
|
+
anyOf: O.none,
|
|
58
|
+
oneOf: O.none,
|
|
59
|
+
not: O.none,
|
|
60
|
+
in: O.none,
|
|
61
|
+
},
|
|
62
|
+
}),
|
|
63
|
+
required: O.some(['id', 'name']),
|
|
64
|
+
additionalProperties: O.some(false),
|
|
65
|
+
allOf: O.none,
|
|
66
|
+
anyOf: O.none,
|
|
67
|
+
oneOf: O.none,
|
|
68
|
+
not: O.none,
|
|
69
|
+
in: O.none,
|
|
70
|
+
},
|
|
71
|
+
output: {
|
|
72
|
+
type: O.some('object'),
|
|
73
|
+
title: O.none,
|
|
74
|
+
properties: O.some({
|
|
75
|
+
id: {
|
|
76
|
+
title: O.none,
|
|
77
|
+
type: O.some('integer'),
|
|
78
|
+
format: 'int64',
|
|
79
|
+
properties: O.none,
|
|
80
|
+
required: O.none,
|
|
81
|
+
additionalProperties: O.some(false),
|
|
82
|
+
allOf: O.none,
|
|
83
|
+
anyOf: O.none,
|
|
84
|
+
oneOf: O.none,
|
|
85
|
+
not: O.none,
|
|
86
|
+
in: O.none,
|
|
87
|
+
},
|
|
88
|
+
name: {
|
|
89
|
+
title: O.none,
|
|
90
|
+
type: O.some('string'),
|
|
91
|
+
properties: O.none,
|
|
92
|
+
required: O.none,
|
|
93
|
+
additionalProperties: O.some(false),
|
|
94
|
+
allOf: O.none,
|
|
95
|
+
anyOf: O.none,
|
|
96
|
+
oneOf: O.none,
|
|
97
|
+
not: O.none,
|
|
98
|
+
in: O.none,
|
|
99
|
+
},
|
|
100
|
+
}),
|
|
101
|
+
required: O.some(['id']),
|
|
102
|
+
additionalProperties: O.some(false),
|
|
103
|
+
allOf: O.none,
|
|
104
|
+
anyOf: O.none,
|
|
105
|
+
oneOf: O.none,
|
|
106
|
+
not: O.none,
|
|
107
|
+
in: O.none,
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
const result = (0, GenerateHandlerTest_1.generateHandlerTest)(input);
|
|
111
|
+
if (E.isLeft(result)) {
|
|
112
|
+
console.log(result.left);
|
|
113
|
+
throw new Error('Expected right');
|
|
114
|
+
}
|
|
115
|
+
expect(`import { OperationHandlerTestSetup } from '@trayio/cdk-dsl/connector/operation/OperationHandlerTest';
|
|
116
|
+
import { OperationHandlerResult } from '@trayio/cdk-dsl/connector/operation/OperationHandler';
|
|
117
|
+
import { getItemHandler } from './handler';
|
|
118
|
+
import '@trayio/cdk-runtime/connector/operation/OperationHandlerTestRunner';
|
|
119
|
+
|
|
120
|
+
OperationHandlerTestSetup.configureHandlerTest(getItemHandler, (handlerTest) =>
|
|
121
|
+
handlerTest
|
|
122
|
+
.usingHandlerContext('test')
|
|
123
|
+
.nothingBeforeAll()
|
|
124
|
+
.testCase('should ${input.operationNameCamelCase}', (testCase) =>
|
|
125
|
+
testCase
|
|
126
|
+
.givenNothing()
|
|
127
|
+
.when(() => ({ id: 2, name: 'test' }))
|
|
128
|
+
.then(({ output }) => {
|
|
129
|
+
// console.log(output);
|
|
130
|
+
const outputValue =
|
|
131
|
+
OperationHandlerResult.getSuccessfulValueOrFail(output);
|
|
132
|
+
expect(outputValue.id).toEqual(2);
|
|
133
|
+
expect(outputValue.name).toEqual('test');
|
|
134
|
+
})
|
|
135
|
+
.finallyDoNothing()
|
|
136
|
+
)
|
|
137
|
+
.nothingAfterAll()
|
|
138
|
+
);`.replace(/\s/g, '')).toEqual(result.right.replace(/\s/g, ''));
|
|
139
|
+
});
|
|
140
|
+
it('should generate a handler test with empty inputs', () => {
|
|
141
|
+
const input = {
|
|
142
|
+
operationNameCamelCase: 'getItem',
|
|
143
|
+
input: {
|
|
144
|
+
title: O.none,
|
|
145
|
+
type: O.none,
|
|
146
|
+
properties: O.none,
|
|
147
|
+
required: O.none,
|
|
148
|
+
additionalProperties: O.none,
|
|
149
|
+
allOf: O.none,
|
|
150
|
+
anyOf: O.none,
|
|
151
|
+
oneOf: O.none,
|
|
152
|
+
not: O.none,
|
|
153
|
+
in: O.none,
|
|
154
|
+
},
|
|
155
|
+
output: {
|
|
156
|
+
type: O.some('object'),
|
|
157
|
+
title: O.none,
|
|
158
|
+
properties: O.some({
|
|
159
|
+
success: {
|
|
160
|
+
title: O.none,
|
|
161
|
+
type: O.some('boolean'),
|
|
162
|
+
properties: O.none,
|
|
163
|
+
required: O.none,
|
|
164
|
+
additionalProperties: O.none,
|
|
165
|
+
allOf: O.none,
|
|
166
|
+
anyOf: O.none,
|
|
167
|
+
oneOf: O.none,
|
|
168
|
+
not: O.none,
|
|
169
|
+
in: O.none,
|
|
170
|
+
},
|
|
171
|
+
}),
|
|
172
|
+
required: O.some(['success']),
|
|
173
|
+
additionalProperties: O.some(false),
|
|
174
|
+
allOf: O.none,
|
|
175
|
+
anyOf: O.none,
|
|
176
|
+
oneOf: O.none,
|
|
177
|
+
not: O.none,
|
|
178
|
+
in: O.none,
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
const result = (0, GenerateHandlerTest_1.generateHandlerTest)(input);
|
|
182
|
+
if (E.isLeft(result)) {
|
|
183
|
+
console.log(result.left);
|
|
184
|
+
throw new Error('Expected right');
|
|
185
|
+
}
|
|
186
|
+
expect(`import { OperationHandlerTestSetup } from '@trayio/cdk-dsl/connector/operation/OperationHandlerTest';
|
|
187
|
+
import { OperationHandlerResult } from '@trayio/cdk-dsl/connector/operation/OperationHandler';
|
|
188
|
+
import { getItemHandler } from './handler';
|
|
189
|
+
import '@trayio/cdk-runtime/connector/operation/OperationHandlerTestRunner';
|
|
190
|
+
|
|
191
|
+
OperationHandlerTestSetup.configureHandlerTest(getItemHandler, (handlerTest) =>
|
|
192
|
+
handlerTest
|
|
193
|
+
.usingHandlerContext('test')
|
|
194
|
+
.nothingBeforeAll()
|
|
195
|
+
.testCase('should ${input.operationNameCamelCase}', (testCase) =>
|
|
196
|
+
testCase
|
|
197
|
+
.givenNothing()
|
|
198
|
+
.when(() => ({}))
|
|
199
|
+
.then(({ output }) => {
|
|
200
|
+
// console.log(output);
|
|
201
|
+
const outputValue =
|
|
202
|
+
OperationHandlerResult.getSuccessfulValueOrFail(output);
|
|
203
|
+
expect(outputValue.success).toEqual(true);
|
|
204
|
+
})
|
|
205
|
+
.finallyDoNothing()
|
|
206
|
+
)
|
|
207
|
+
.nothingAfterAll()
|
|
208
|
+
);`.replace(/\s/g, '')).toEqual(result.right.replace(/\s/g, ''));
|
|
209
|
+
});
|
|
210
|
+
it('should generate a handler test with a basic object input and output type', () => {
|
|
211
|
+
const input = {
|
|
212
|
+
operationNameCamelCase: 'createPerson',
|
|
213
|
+
input: {
|
|
214
|
+
title: O.none,
|
|
215
|
+
type: O.some('object'),
|
|
216
|
+
properties: O.some({
|
|
217
|
+
metadata: {
|
|
218
|
+
title: O.none,
|
|
219
|
+
type: O.some('object'),
|
|
220
|
+
properties: O.some({
|
|
221
|
+
name: {
|
|
222
|
+
title: O.none,
|
|
223
|
+
type: O.some('string'),
|
|
224
|
+
properties: O.none,
|
|
225
|
+
required: O.none,
|
|
226
|
+
additionalProperties: O.some(false),
|
|
227
|
+
allOf: O.none,
|
|
228
|
+
anyOf: O.none,
|
|
229
|
+
oneOf: O.none,
|
|
230
|
+
not: O.none,
|
|
231
|
+
in: O.none,
|
|
232
|
+
},
|
|
233
|
+
age: {
|
|
234
|
+
title: O.none,
|
|
235
|
+
type: O.some('integer'),
|
|
236
|
+
properties: O.none,
|
|
237
|
+
required: O.none,
|
|
238
|
+
additionalProperties: O.some(false),
|
|
239
|
+
allOf: O.none,
|
|
240
|
+
anyOf: O.none,
|
|
241
|
+
oneOf: O.none,
|
|
242
|
+
not: O.none,
|
|
243
|
+
in: O.none,
|
|
244
|
+
},
|
|
245
|
+
}),
|
|
246
|
+
required: O.none,
|
|
247
|
+
additionalProperties: O.some(false),
|
|
248
|
+
allOf: O.none,
|
|
249
|
+
anyOf: O.none,
|
|
250
|
+
oneOf: O.none,
|
|
251
|
+
not: O.none,
|
|
252
|
+
in: O.none,
|
|
253
|
+
},
|
|
254
|
+
}),
|
|
255
|
+
required: O.none,
|
|
256
|
+
additionalProperties: O.some(false),
|
|
257
|
+
allOf: O.none,
|
|
258
|
+
anyOf: O.none,
|
|
259
|
+
oneOf: O.none,
|
|
260
|
+
not: O.none,
|
|
261
|
+
in: O.none,
|
|
262
|
+
},
|
|
263
|
+
output: {
|
|
264
|
+
title: O.none,
|
|
265
|
+
type: O.some('object'),
|
|
266
|
+
properties: O.some({
|
|
267
|
+
parents: {
|
|
268
|
+
title: O.none,
|
|
269
|
+
type: O.some('object'),
|
|
270
|
+
properties: O.some({
|
|
271
|
+
child: {
|
|
272
|
+
title: O.none,
|
|
273
|
+
type: O.some('string'),
|
|
274
|
+
properties: O.none,
|
|
275
|
+
required: O.none,
|
|
276
|
+
additionalProperties: O.some(false),
|
|
277
|
+
allOf: O.none,
|
|
278
|
+
anyOf: O.none,
|
|
279
|
+
oneOf: O.none,
|
|
280
|
+
not: O.none,
|
|
281
|
+
in: O.none,
|
|
282
|
+
},
|
|
283
|
+
}),
|
|
284
|
+
required: O.none,
|
|
285
|
+
additionalProperties: O.some(false),
|
|
286
|
+
allOf: O.none,
|
|
287
|
+
anyOf: O.none,
|
|
288
|
+
oneOf: O.none,
|
|
289
|
+
not: O.none,
|
|
290
|
+
in: O.none,
|
|
291
|
+
},
|
|
292
|
+
}),
|
|
293
|
+
required: O.none,
|
|
294
|
+
additionalProperties: O.some(false),
|
|
295
|
+
allOf: O.none,
|
|
296
|
+
anyOf: O.none,
|
|
297
|
+
oneOf: O.none,
|
|
298
|
+
not: O.none,
|
|
299
|
+
in: O.none,
|
|
300
|
+
},
|
|
301
|
+
};
|
|
302
|
+
const result = (0, GenerateHandlerTest_1.generateHandlerTest)(input);
|
|
303
|
+
if (E.isLeft(result)) {
|
|
304
|
+
console.log(result.left);
|
|
305
|
+
throw new Error('Expected right');
|
|
306
|
+
}
|
|
307
|
+
expect(`import { OperationHandlerTestSetup } from '@trayio/cdk-dsl/connector/operation/OperationHandlerTest';
|
|
308
|
+
import { OperationHandlerResult } from '@trayio/cdk-dsl/connector/operation/OperationHandler';
|
|
309
|
+
import { createPersonHandler } from './handler';
|
|
310
|
+
import '@trayio/cdk-runtime/connector/operation/OperationHandlerTestRunner';
|
|
311
|
+
|
|
312
|
+
OperationHandlerTestSetup.configureHandlerTest(createPersonHandler, (handlerTest) =>
|
|
313
|
+
handlerTest
|
|
314
|
+
.usingHandlerContext('test')
|
|
315
|
+
.nothingBeforeAll()
|
|
316
|
+
.testCase('should ${input.operationNameCamelCase}', (testCase) =>
|
|
317
|
+
testCase
|
|
318
|
+
.givenNothing()
|
|
319
|
+
.when(() => ({ metadata: { name: 'test', age: 2 }}))
|
|
320
|
+
.then(({ output }) => {
|
|
321
|
+
// console.log(output);
|
|
322
|
+
const outputValue =
|
|
323
|
+
OperationHandlerResult.getSuccessfulValueOrFail(output);
|
|
324
|
+
expect(outputValue.parents).toEqual({child: 'test'});
|
|
325
|
+
})
|
|
326
|
+
.finallyDoNothing()
|
|
327
|
+
)
|
|
328
|
+
.nothingAfterAll()
|
|
329
|
+
);`.replace(/\s/g, '')).toEqual(result.right.replace(/\s/g, ''));
|
|
330
|
+
});
|
|
331
|
+
it('should generate a handler test with a basic array input and output type', () => {
|
|
332
|
+
const input = {
|
|
333
|
+
operationNameCamelCase: 'listItems',
|
|
334
|
+
input: {
|
|
335
|
+
type: O.some('object'),
|
|
336
|
+
title: O.none,
|
|
337
|
+
properties: O.some({
|
|
338
|
+
ids: {
|
|
339
|
+
title: O.none,
|
|
340
|
+
type: 'array',
|
|
341
|
+
items: {
|
|
342
|
+
title: O.none,
|
|
343
|
+
type: O.some('integer'),
|
|
344
|
+
properties: O.none,
|
|
345
|
+
required: O.none,
|
|
346
|
+
additionalProperties: O.some(false),
|
|
347
|
+
allOf: O.none,
|
|
348
|
+
anyOf: O.none,
|
|
349
|
+
oneOf: O.none,
|
|
350
|
+
not: O.none,
|
|
351
|
+
in: O.none,
|
|
352
|
+
},
|
|
353
|
+
properties: O.none,
|
|
354
|
+
required: O.none,
|
|
355
|
+
additionalProperties: O.some(false),
|
|
356
|
+
allOf: O.none,
|
|
357
|
+
anyOf: O.none,
|
|
358
|
+
oneOf: O.none,
|
|
359
|
+
not: O.none,
|
|
360
|
+
in: O.none,
|
|
361
|
+
},
|
|
362
|
+
}),
|
|
363
|
+
required: O.none,
|
|
364
|
+
additionalProperties: O.some(false),
|
|
365
|
+
allOf: O.none,
|
|
366
|
+
anyOf: O.none,
|
|
367
|
+
oneOf: O.none,
|
|
368
|
+
not: O.none,
|
|
369
|
+
in: O.none,
|
|
370
|
+
},
|
|
371
|
+
output: {
|
|
372
|
+
type: O.some('object'),
|
|
373
|
+
title: O.none,
|
|
374
|
+
properties: O.some({
|
|
375
|
+
parents: {
|
|
376
|
+
title: O.none,
|
|
377
|
+
type: 'array',
|
|
378
|
+
items: {
|
|
379
|
+
title: O.none,
|
|
380
|
+
type: O.some('string'),
|
|
381
|
+
properties: O.none,
|
|
382
|
+
required: O.none,
|
|
383
|
+
additionalProperties: O.some(false),
|
|
384
|
+
allOf: O.none,
|
|
385
|
+
anyOf: O.none,
|
|
386
|
+
oneOf: O.none,
|
|
387
|
+
not: O.none,
|
|
388
|
+
in: O.none,
|
|
389
|
+
},
|
|
390
|
+
properties: O.none,
|
|
391
|
+
required: O.none,
|
|
392
|
+
additionalProperties: O.some(false),
|
|
393
|
+
allOf: O.none,
|
|
394
|
+
anyOf: O.none,
|
|
395
|
+
oneOf: O.none,
|
|
396
|
+
not: O.none,
|
|
397
|
+
in: O.none,
|
|
398
|
+
},
|
|
399
|
+
}),
|
|
400
|
+
required: O.none,
|
|
401
|
+
additionalProperties: O.some(false),
|
|
402
|
+
allOf: O.none,
|
|
403
|
+
anyOf: O.none,
|
|
404
|
+
oneOf: O.none,
|
|
405
|
+
not: O.none,
|
|
406
|
+
in: O.none,
|
|
407
|
+
},
|
|
408
|
+
};
|
|
409
|
+
const result = (0, GenerateHandlerTest_1.generateHandlerTest)(input);
|
|
410
|
+
if (E.isLeft(result)) {
|
|
411
|
+
console.log(result.left);
|
|
412
|
+
throw new Error('Expected right');
|
|
413
|
+
}
|
|
414
|
+
expect(`import { OperationHandlerTestSetup } from '@trayio/cdk-dsl/connector/operation/OperationHandlerTest';
|
|
415
|
+
import { OperationHandlerResult } from '@trayio/cdk-dsl/connector/operation/OperationHandler';
|
|
416
|
+
import { listItemsHandler } from './handler';
|
|
417
|
+
import '@trayio/cdk-runtime/connector/operation/OperationHandlerTestRunner';
|
|
418
|
+
|
|
419
|
+
OperationHandlerTestSetup.configureHandlerTest(listItemsHandler, (handlerTest) =>
|
|
420
|
+
handlerTest
|
|
421
|
+
.usingHandlerContext('test')
|
|
422
|
+
.nothingBeforeAll()
|
|
423
|
+
.testCase('should ${input.operationNameCamelCase}', (testCase) =>
|
|
424
|
+
testCase
|
|
425
|
+
.givenNothing()
|
|
426
|
+
.when(() => ({ ids: [2] }))
|
|
427
|
+
.then(({ output }) => {
|
|
428
|
+
// console.log(output);
|
|
429
|
+
const outputValue =
|
|
430
|
+
OperationHandlerResult.getSuccessfulValueOrFail(output);
|
|
431
|
+
expect(outputValue.parents).toEqual(['test']);
|
|
432
|
+
})
|
|
433
|
+
.finallyDoNothing()
|
|
434
|
+
)
|
|
435
|
+
.nothingAfterAll()
|
|
436
|
+
);`.replace(/\s/g, '')).toEqual(result.right.replace(/\s/g, ''));
|
|
437
|
+
});
|
|
438
|
+
it('should generate a handler test with a complex object output type', () => {
|
|
439
|
+
const input = {
|
|
440
|
+
operationNameCamelCase: 'listItems',
|
|
441
|
+
input: {
|
|
442
|
+
title: O.none,
|
|
443
|
+
type: O.none,
|
|
444
|
+
properties: O.none,
|
|
445
|
+
required: O.none,
|
|
446
|
+
additionalProperties: O.none,
|
|
447
|
+
allOf: O.none,
|
|
448
|
+
anyOf: O.none,
|
|
449
|
+
oneOf: O.none,
|
|
450
|
+
not: O.none,
|
|
451
|
+
in: O.none,
|
|
452
|
+
},
|
|
453
|
+
output: {
|
|
454
|
+
type: O.some('object'),
|
|
455
|
+
title: O.none,
|
|
456
|
+
properties: O.some({
|
|
457
|
+
parents: {
|
|
458
|
+
title: O.none,
|
|
459
|
+
type: O.some('object'),
|
|
460
|
+
properties: O.some({
|
|
461
|
+
child: {
|
|
462
|
+
title: O.none,
|
|
463
|
+
type: O.some('string'),
|
|
464
|
+
properties: O.none,
|
|
465
|
+
required: O.none,
|
|
466
|
+
additionalProperties: O.none,
|
|
467
|
+
allOf: O.none,
|
|
468
|
+
anyOf: O.none,
|
|
469
|
+
oneOf: O.none,
|
|
470
|
+
not: O.none,
|
|
471
|
+
in: O.none,
|
|
472
|
+
},
|
|
473
|
+
valueList: {
|
|
474
|
+
title: O.none,
|
|
475
|
+
type: 'array',
|
|
476
|
+
items: {
|
|
477
|
+
title: O.none,
|
|
478
|
+
type: O.some('string'),
|
|
479
|
+
properties: O.none,
|
|
480
|
+
required: O.none,
|
|
481
|
+
additionalProperties: O.none,
|
|
482
|
+
allOf: O.none,
|
|
483
|
+
anyOf: O.none,
|
|
484
|
+
oneOf: O.none,
|
|
485
|
+
not: O.none,
|
|
486
|
+
in: O.none,
|
|
487
|
+
},
|
|
488
|
+
properties: O.none,
|
|
489
|
+
required: O.none,
|
|
490
|
+
additionalProperties: O.some(false),
|
|
491
|
+
allOf: O.none,
|
|
492
|
+
anyOf: O.none,
|
|
493
|
+
oneOf: O.none,
|
|
494
|
+
not: O.none,
|
|
495
|
+
in: O.none,
|
|
496
|
+
},
|
|
497
|
+
}),
|
|
498
|
+
required: O.none,
|
|
499
|
+
additionalProperties: O.some(false),
|
|
500
|
+
allOf: O.none,
|
|
501
|
+
anyOf: O.none,
|
|
502
|
+
oneOf: O.none,
|
|
503
|
+
not: O.none,
|
|
504
|
+
in: O.none,
|
|
505
|
+
},
|
|
506
|
+
}),
|
|
507
|
+
required: O.none,
|
|
508
|
+
additionalProperties: O.some(false),
|
|
509
|
+
allOf: O.none,
|
|
510
|
+
anyOf: O.none,
|
|
511
|
+
oneOf: O.none,
|
|
512
|
+
not: O.none,
|
|
513
|
+
in: O.none,
|
|
514
|
+
},
|
|
515
|
+
};
|
|
516
|
+
const result = (0, GenerateHandlerTest_1.generateHandlerTest)(input);
|
|
517
|
+
if (E.isLeft(result)) {
|
|
518
|
+
console.log(result.left);
|
|
519
|
+
throw new Error('Expected right');
|
|
520
|
+
}
|
|
521
|
+
expect(`import { OperationHandlerTestSetup } from '@trayio/cdk-dsl/connector/operation/OperationHandlerTest';
|
|
522
|
+
import { OperationHandlerResult } from '@trayio/cdk-dsl/connector/operation/OperationHandler';
|
|
523
|
+
import { listItemsHandler } from './handler';
|
|
524
|
+
import '@trayio/cdk-runtime/connector/operation/OperationHandlerTestRunner';
|
|
525
|
+
|
|
526
|
+
OperationHandlerTestSetup.configureHandlerTest(listItemsHandler, (handlerTest) =>
|
|
527
|
+
handlerTest
|
|
528
|
+
.usingHandlerContext('test')
|
|
529
|
+
.nothingBeforeAll()
|
|
530
|
+
.testCase('should ${input.operationNameCamelCase}', (testCase) =>
|
|
531
|
+
testCase
|
|
532
|
+
.givenNothing()
|
|
533
|
+
.when(() => ({}))
|
|
534
|
+
.then(({ output }) => {
|
|
535
|
+
// console.log(output);
|
|
536
|
+
const outputValue =
|
|
537
|
+
OperationHandlerResult.getSuccessfulValueOrFail(output);
|
|
538
|
+
expect(outputValue.parents).toEqual({child: 'test', valueList: ['test']});
|
|
539
|
+
})
|
|
540
|
+
.finallyDoNothing()
|
|
541
|
+
)
|
|
542
|
+
.nothingAfterAll()
|
|
543
|
+
);`.replace(/\s/g, '')).toEqual(result.right.replace(/\s/g, ''));
|
|
544
|
+
});
|
|
545
|
+
it('should generate a handler test with a complex array output type', () => {
|
|
546
|
+
const input = {
|
|
547
|
+
operationNameCamelCase: 'listItems',
|
|
548
|
+
input: {
|
|
549
|
+
title: O.none,
|
|
550
|
+
type: O.none,
|
|
551
|
+
properties: O.none,
|
|
552
|
+
required: O.none,
|
|
553
|
+
additionalProperties: O.none,
|
|
554
|
+
allOf: O.none,
|
|
555
|
+
anyOf: O.none,
|
|
556
|
+
oneOf: O.none,
|
|
557
|
+
not: O.none,
|
|
558
|
+
in: O.none,
|
|
559
|
+
},
|
|
560
|
+
output: {
|
|
561
|
+
title: O.none,
|
|
562
|
+
type: O.some('object'),
|
|
563
|
+
properties: O.some({
|
|
564
|
+
parents: {
|
|
565
|
+
title: O.none,
|
|
566
|
+
type: 'array',
|
|
567
|
+
items: {
|
|
568
|
+
title: O.none,
|
|
569
|
+
type: O.some('object'),
|
|
570
|
+
properties: O.some({
|
|
571
|
+
child: {
|
|
572
|
+
title: O.none,
|
|
573
|
+
type: O.some('string'),
|
|
574
|
+
properties: O.none,
|
|
575
|
+
required: O.none,
|
|
576
|
+
additionalProperties: O.none,
|
|
577
|
+
allOf: O.none,
|
|
578
|
+
anyOf: O.none,
|
|
579
|
+
oneOf: O.none,
|
|
580
|
+
not: O.none,
|
|
581
|
+
in: O.none,
|
|
582
|
+
},
|
|
583
|
+
}),
|
|
584
|
+
required: O.none,
|
|
585
|
+
additionalProperties: O.none,
|
|
586
|
+
allOf: O.none,
|
|
587
|
+
anyOf: O.none,
|
|
588
|
+
oneOf: O.none,
|
|
589
|
+
not: O.none,
|
|
590
|
+
in: O.none,
|
|
591
|
+
},
|
|
592
|
+
properties: O.none,
|
|
593
|
+
required: O.none,
|
|
594
|
+
additionalProperties: O.some(false),
|
|
595
|
+
allOf: O.none,
|
|
596
|
+
anyOf: O.none,
|
|
597
|
+
oneOf: O.none,
|
|
598
|
+
not: O.none,
|
|
599
|
+
in: O.none,
|
|
600
|
+
},
|
|
601
|
+
}),
|
|
602
|
+
required: O.none,
|
|
603
|
+
additionalProperties: O.some(false),
|
|
604
|
+
allOf: O.none,
|
|
605
|
+
anyOf: O.none,
|
|
606
|
+
oneOf: O.none,
|
|
607
|
+
not: O.none,
|
|
608
|
+
in: O.none,
|
|
609
|
+
},
|
|
610
|
+
};
|
|
611
|
+
const result = (0, GenerateHandlerTest_1.generateHandlerTest)(input);
|
|
612
|
+
if (E.isLeft(result)) {
|
|
613
|
+
console.log(result.left);
|
|
614
|
+
throw new Error('Expected right');
|
|
615
|
+
}
|
|
616
|
+
expect(`import { OperationHandlerTestSetup } from '@trayio/cdk-dsl/connector/operation/OperationHandlerTest';
|
|
617
|
+
import { OperationHandlerResult } from '@trayio/cdk-dsl/connector/operation/OperationHandler';
|
|
618
|
+
import { listItemsHandler } from './handler';
|
|
619
|
+
import '@trayio/cdk-runtime/connector/operation/OperationHandlerTestRunner';
|
|
620
|
+
|
|
621
|
+
OperationHandlerTestSetup.configureHandlerTest(listItemsHandler, (handlerTest) =>
|
|
622
|
+
handlerTest
|
|
623
|
+
.usingHandlerContext('test')
|
|
624
|
+
.nothingBeforeAll()
|
|
625
|
+
.testCase('should ${input.operationNameCamelCase}', (testCase) =>
|
|
626
|
+
testCase
|
|
627
|
+
.givenNothing()
|
|
628
|
+
.when(() => ({}))
|
|
629
|
+
.then(({ output }) => {
|
|
630
|
+
// console.log(output);
|
|
631
|
+
const outputValue =
|
|
632
|
+
OperationHandlerResult.getSuccessfulValueOrFail(output);
|
|
633
|
+
expect(outputValue.parents).toEqual([{child: 'test'}]);
|
|
634
|
+
})
|
|
635
|
+
.finallyDoNothing()
|
|
636
|
+
)
|
|
637
|
+
.nothingAfterAll()
|
|
638
|
+
);`.replace(/\s/g, '')).toEqual(result.right.replace(/\s/g, ''));
|
|
639
|
+
});
|
|
640
|
+
});
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import * as TE from 'fp-ts/TaskEither';
|
|
2
|
+
import { FileStorage } from '@trayio/commons/file/File';
|
|
3
|
+
export declare const generateOperationJson: (fileStorage: FileStorage, operationDirPath: string, operationNameSnakeCase: string, operationNameKebabCase: string, operationDescription: string) => TE.TaskEither<Error, undefined>;
|
|
4
|
+
//# sourceMappingURL=GenerateOperationJson.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GenerateOperationJson.d.ts","sourceRoot":"","sources":["../../src/file-generators/GenerateOperationJson.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAGvC,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAGxD,eAAO,MAAM,qBAAqB,gBACpB,WAAW,oBACN,MAAM,0BACA,MAAM,0BACN,MAAM,wBACR,MAAM,KAC1B,GAAG,UAAU,CAAC,KAAK,EAAE,SAAS,CAuBhC,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.generateOperationJson = void 0;
|
|
27
|
+
const TE = __importStar(require("fp-ts/TaskEither"));
|
|
28
|
+
const O = __importStar(require("fp-ts/Option"));
|
|
29
|
+
const function_1 = require("fp-ts/function");
|
|
30
|
+
const stream_1 = require("stream");
|
|
31
|
+
const generateOperationJson = (fileStorage, operationDirPath, operationNameSnakeCase, operationNameKebabCase, operationDescription) => {
|
|
32
|
+
const operationJson = {
|
|
33
|
+
name: operationNameSnakeCase,
|
|
34
|
+
title: operationNameKebabCase,
|
|
35
|
+
description: operationDescription,
|
|
36
|
+
};
|
|
37
|
+
const writeOperationJson = fileStorage.write({
|
|
38
|
+
content: stream_1.Readable.from(JSON.stringify(operationJson)),
|
|
39
|
+
key: `${operationDirPath}/operation.json`,
|
|
40
|
+
metadata: { name: 'operation.json' },
|
|
41
|
+
}, O.none);
|
|
42
|
+
return (0, function_1.pipe)(writeOperationJson, TE.mapLeft((error) => new Error(`Failed to generate operation.json for operation: ${error}`)), TE.map(() => undefined));
|
|
43
|
+
};
|
|
44
|
+
exports.generateOperationJson = generateOperationJson;
|