@trayio/tray-openapi 5.34.0 → 5.35.0-unstable.fd7158a
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/OpenApiCodecs.d.ts +207 -4
- package/dist/OpenApiCodecs.d.ts.map +1 -1
- package/dist/OpenApiCodecs.js +3 -3
- package/dist/OpenApiSchemaImporter.d.ts +2 -2
- package/dist/OpenApiSchemaImporter.d.ts.map +1 -1
- package/dist/OpenApiSchemaImporter.js +33 -55
- package/dist/OpenApiSchemaImporter.unit.test.js +24 -13
- package/dist/OpenApiSchemaTransformer.d.ts +2 -2
- package/dist/OpenApiSchemaTransformer.d.ts.map +1 -1
- package/dist/OpenApiSchemaTransformer.js +2 -25
- package/dist/OpenApiSchemaTransformer.unit.test.js +30 -44
- package/dist/OpenApiTypeDescriptors.d.ts +389 -32
- package/dist/OpenApiTypeDescriptors.d.ts.map +1 -1
- package/dist/OpenApiTypeDescriptors.js +80 -109
- package/dist/file-generators/GenerateHandler.d.ts +2 -2
- package/dist/file-generators/GenerateHandler.d.ts.map +1 -1
- package/dist/file-generators/GenerateHandler.js +75 -78
- package/dist/file-generators/GenerateHandler.unit.test.js +73 -97
- package/dist/file-generators/GenerateHandlerTest.d.ts +2 -2
- package/dist/file-generators/GenerateHandlerTest.d.ts.map +1 -1
- package/dist/file-generators/GenerateHandlerTest.js +69 -76
- package/dist/file-generators/GenerateHandlerTest.unit.test.js +206 -230
- package/dist/file-generators/GenerateOperationJson.d.ts +2 -2
- package/dist/file-generators/GenerateOperationJson.d.ts.map +1 -1
- package/dist/file-generators/GenerateOperationJson.js +4 -29
- package/dist/file-generators/GenerateOperationJson.unit.test.js +25 -49
- package/dist/file-generators/SchemaGenerator.d.ts.map +1 -1
- package/dist/file-generators/SchemaGenerator.js +14 -37
- package/dist/file-generators/types/GenerateInputSchema.d.ts +2 -2
- package/dist/file-generators/types/GenerateInputSchema.d.ts.map +1 -1
- package/dist/file-generators/types/GenerateInputSchema.js +88 -95
- package/dist/file-generators/types/GenerateInputSchema.test.js +60 -91
- package/dist/file-generators/types/GenerateInputType.test.js +143 -169
- package/dist/file-generators/types/GenerateInputTypes.d.ts +2 -2
- package/dist/file-generators/types/GenerateInputTypes.d.ts.map +1 -1
- package/dist/file-generators/types/GenerateInputTypes.js +7 -28
- package/dist/file-generators/types/GenerateOutput.d.ts +4 -6
- package/dist/file-generators/types/GenerateOutput.d.ts.map +1 -1
- package/dist/file-generators/types/GenerateOutput.js +46 -57
- package/dist/file-generators/types/GenerateOutput.test.js +35 -62
- package/package.json +6 -8
|
@@ -1,30 +1,6 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
const
|
|
27
|
-
const O = __importStar(require("fp-ts/Option"));
|
|
3
|
+
const effect_1 = require("effect");
|
|
28
4
|
const GenerateHandler_1 = require("./GenerateHandler");
|
|
29
5
|
const SchemaGenerator_1 = require("./SchemaGenerator");
|
|
30
6
|
const getGenerateHandlerInput = (input) => ({
|
|
@@ -41,7 +17,7 @@ describe('GenerateHandler', () => {
|
|
|
41
17
|
it('it should generate a handler with no inputs', () => {
|
|
42
18
|
const payload = getGenerateHandlerInput({});
|
|
43
19
|
const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
|
|
44
|
-
expect(
|
|
20
|
+
expect(effect_1.Either.right(`import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";
|
|
45
21
|
import { OpenApiTestAuth } from "../OpenApiTestAuth";
|
|
46
22
|
import { GetPhotoInput } from "./input";
|
|
47
23
|
import { GetPhotoOutput } from "./output";
|
|
@@ -62,22 +38,22 @@ import { globalConfigHttp } from "../GlobalConfig";
|
|
|
62
38
|
});
|
|
63
39
|
it('it should generate a handler with a path parameter', () => {
|
|
64
40
|
const input = (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
65
|
-
type:
|
|
66
|
-
properties:
|
|
41
|
+
type: effect_1.Option.some('object'),
|
|
42
|
+
properties: effect_1.Option.some({
|
|
67
43
|
photoId: (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
68
|
-
type:
|
|
69
|
-
in:
|
|
44
|
+
type: effect_1.Option.some('string'),
|
|
45
|
+
in: effect_1.Option.some('path'),
|
|
70
46
|
}),
|
|
71
47
|
}),
|
|
72
|
-
required:
|
|
73
|
-
additionalProperties:
|
|
48
|
+
required: effect_1.Option.some(['photoId']),
|
|
49
|
+
additionalProperties: effect_1.Option.some(false),
|
|
74
50
|
});
|
|
75
51
|
const payload = getGenerateHandlerInput({
|
|
76
52
|
input,
|
|
77
53
|
httpPath: '/photos/{photoId}',
|
|
78
54
|
});
|
|
79
55
|
const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
|
|
80
|
-
expect(
|
|
56
|
+
expect(effect_1.Either.right(`import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";
|
|
81
57
|
import { OpenApiTestAuth } from "../OpenApiTestAuth";
|
|
82
58
|
import { GetPhotoInput } from "./input";
|
|
83
59
|
import { GetPhotoOutput } from "./output";
|
|
@@ -98,19 +74,19 @@ import { globalConfigHttp } from "../GlobalConfig";
|
|
|
98
74
|
});
|
|
99
75
|
it('it should generate a handler with a body input as json', () => {
|
|
100
76
|
const input = (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
101
|
-
type:
|
|
102
|
-
properties:
|
|
77
|
+
type: effect_1.Option.some('object'),
|
|
78
|
+
properties: effect_1.Option.some({
|
|
103
79
|
photoId: (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
104
|
-
type:
|
|
105
|
-
in:
|
|
80
|
+
type: effect_1.Option.some('string'),
|
|
81
|
+
in: effect_1.Option.some('body'),
|
|
106
82
|
}),
|
|
107
83
|
}),
|
|
108
|
-
required:
|
|
109
|
-
additionalProperties:
|
|
84
|
+
required: effect_1.Option.some(['photoId']),
|
|
85
|
+
additionalProperties: effect_1.Option.some(false),
|
|
110
86
|
});
|
|
111
87
|
const payload = getGenerateHandlerInput({ input });
|
|
112
88
|
const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
|
|
113
|
-
expect(
|
|
89
|
+
expect(effect_1.Either.right(`import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";
|
|
114
90
|
import { OpenApiTestAuth } from "../OpenApiTestAuth";
|
|
115
91
|
import { GetPhotoInput } from "./input";
|
|
116
92
|
import { GetPhotoOutput } from "./output";
|
|
@@ -131,19 +107,19 @@ import { globalConfigHttp } from "../GlobalConfig";
|
|
|
131
107
|
});
|
|
132
108
|
it('it should generate a handler with a query string input', () => {
|
|
133
109
|
const input = (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
134
|
-
type:
|
|
135
|
-
properties:
|
|
110
|
+
type: effect_1.Option.some('object'),
|
|
111
|
+
properties: effect_1.Option.some({
|
|
136
112
|
id: (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
137
|
-
type:
|
|
138
|
-
in:
|
|
113
|
+
type: effect_1.Option.some('string'),
|
|
114
|
+
in: effect_1.Option.some('query'),
|
|
139
115
|
}),
|
|
140
116
|
}),
|
|
141
|
-
required:
|
|
142
|
-
additionalProperties:
|
|
117
|
+
required: effect_1.Option.some(['id']),
|
|
118
|
+
additionalProperties: effect_1.Option.some(false),
|
|
143
119
|
});
|
|
144
120
|
const payload = getGenerateHandlerInput({ input });
|
|
145
121
|
const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
|
|
146
|
-
expect(
|
|
122
|
+
expect(effect_1.Either.right(`import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";
|
|
147
123
|
import { OpenApiTestAuth } from "../OpenApiTestAuth";
|
|
148
124
|
import { GetPhotoInput } from "./input";
|
|
149
125
|
import { GetPhotoOutput } from "./output";
|
|
@@ -164,19 +140,19 @@ import { globalConfigHttp } from "../GlobalConfig";
|
|
|
164
140
|
});
|
|
165
141
|
it('it should generate a handler with a header input', () => {
|
|
166
142
|
const input = (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
167
|
-
type:
|
|
168
|
-
properties:
|
|
143
|
+
type: effect_1.Option.some('object'),
|
|
144
|
+
properties: effect_1.Option.some({
|
|
169
145
|
'Content-Type': (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
170
|
-
type:
|
|
171
|
-
in:
|
|
146
|
+
type: effect_1.Option.some('string'),
|
|
147
|
+
in: effect_1.Option.some('header'),
|
|
172
148
|
}),
|
|
173
149
|
}),
|
|
174
|
-
required:
|
|
175
|
-
additionalProperties:
|
|
150
|
+
required: effect_1.Option.some(['Content-Type']),
|
|
151
|
+
additionalProperties: effect_1.Option.some(false),
|
|
176
152
|
});
|
|
177
153
|
const payload = getGenerateHandlerInput({ input });
|
|
178
154
|
const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
|
|
179
|
-
expect(
|
|
155
|
+
expect(effect_1.Either.right(`import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";
|
|
180
156
|
import { OpenApiTestAuth } from "../OpenApiTestAuth";
|
|
181
157
|
import { GetPhotoInput } from "./input";
|
|
182
158
|
import { GetPhotoOutput } from "./output";
|
|
@@ -197,18 +173,18 @@ import { globalConfigHttp } from "../GlobalConfig";
|
|
|
197
173
|
});
|
|
198
174
|
it('it should generate a handler and transform number type to string for input', () => {
|
|
199
175
|
const input = (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
200
|
-
type:
|
|
201
|
-
properties:
|
|
176
|
+
type: effect_1.Option.some('object'),
|
|
177
|
+
properties: effect_1.Option.some({
|
|
202
178
|
'Content-Type': (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
203
|
-
type:
|
|
204
|
-
in:
|
|
179
|
+
type: effect_1.Option.some('integer'),
|
|
180
|
+
in: effect_1.Option.some('header'),
|
|
205
181
|
}),
|
|
206
182
|
}),
|
|
207
|
-
additionalProperties:
|
|
183
|
+
additionalProperties: effect_1.Option.some(false),
|
|
208
184
|
});
|
|
209
185
|
const payload = getGenerateHandlerInput({ input });
|
|
210
186
|
const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
|
|
211
|
-
expect(
|
|
187
|
+
expect(effect_1.Either.right(`import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";
|
|
212
188
|
import { OpenApiTestAuth } from "../OpenApiTestAuth";
|
|
213
189
|
import { GetPhotoInput } from "./input";
|
|
214
190
|
import { GetPhotoOutput } from "./output";
|
|
@@ -229,30 +205,30 @@ import { globalConfigHttp } from "../GlobalConfig";
|
|
|
229
205
|
});
|
|
230
206
|
it('it should generate a handler with a query string and path param input', () => {
|
|
231
207
|
const input = (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
232
|
-
type:
|
|
233
|
-
properties:
|
|
208
|
+
type: effect_1.Option.some('object'),
|
|
209
|
+
properties: effect_1.Option.some({
|
|
234
210
|
id: (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
235
|
-
type:
|
|
236
|
-
in:
|
|
211
|
+
type: effect_1.Option.some('string'),
|
|
212
|
+
in: effect_1.Option.some('query'),
|
|
237
213
|
}),
|
|
238
214
|
photoId: (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
239
|
-
type:
|
|
240
|
-
in:
|
|
215
|
+
type: effect_1.Option.some('string'),
|
|
216
|
+
in: effect_1.Option.some('path'),
|
|
241
217
|
}),
|
|
242
218
|
commentId: (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
243
|
-
type:
|
|
244
|
-
in:
|
|
219
|
+
type: effect_1.Option.some('string'),
|
|
220
|
+
in: effect_1.Option.some('path'),
|
|
245
221
|
}),
|
|
246
222
|
}),
|
|
247
|
-
required:
|
|
248
|
-
additionalProperties:
|
|
223
|
+
required: effect_1.Option.some(['photoId']),
|
|
224
|
+
additionalProperties: effect_1.Option.some(false),
|
|
249
225
|
});
|
|
250
226
|
const payload = getGenerateHandlerInput({
|
|
251
227
|
input,
|
|
252
228
|
httpPath: '/photos/{photoId}/{commentId}',
|
|
253
229
|
});
|
|
254
230
|
const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
|
|
255
|
-
expect(
|
|
231
|
+
expect(effect_1.Either.right(`import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";
|
|
256
232
|
import { OpenApiTestAuth } from "../OpenApiTestAuth";
|
|
257
233
|
import { GetPhotoInput } from "./input";
|
|
258
234
|
import { GetPhotoOutput } from "./output";
|
|
@@ -273,23 +249,23 @@ import { globalConfigHttp } from "../GlobalConfig";
|
|
|
273
249
|
});
|
|
274
250
|
it('it should generate a handler with a query string and body param input', () => {
|
|
275
251
|
const input = (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
276
|
-
type:
|
|
277
|
-
properties:
|
|
252
|
+
type: effect_1.Option.some('object'),
|
|
253
|
+
properties: effect_1.Option.some({
|
|
278
254
|
id: (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
279
|
-
type:
|
|
280
|
-
in:
|
|
255
|
+
type: effect_1.Option.some('string'),
|
|
256
|
+
in: effect_1.Option.some('query'),
|
|
281
257
|
}),
|
|
282
258
|
photoId: (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
283
|
-
type:
|
|
284
|
-
in:
|
|
259
|
+
type: effect_1.Option.some('string'),
|
|
260
|
+
in: effect_1.Option.some('body'),
|
|
285
261
|
}),
|
|
286
262
|
}),
|
|
287
|
-
required:
|
|
288
|
-
additionalProperties:
|
|
263
|
+
required: effect_1.Option.some(['id', 'photoId']),
|
|
264
|
+
additionalProperties: effect_1.Option.some(false),
|
|
289
265
|
});
|
|
290
266
|
const payload = getGenerateHandlerInput({ input });
|
|
291
267
|
const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
|
|
292
|
-
expect(
|
|
268
|
+
expect(effect_1.Either.right(`import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";
|
|
293
269
|
import { OpenApiTestAuth } from "../OpenApiTestAuth";
|
|
294
270
|
import { GetPhotoInput } from "./input";
|
|
295
271
|
import { GetPhotoOutput } from "./output";
|
|
@@ -310,23 +286,23 @@ import { globalConfigHttp } from "../GlobalConfig";
|
|
|
310
286
|
});
|
|
311
287
|
it('it should generate a handler with an optional query string and body param input', () => {
|
|
312
288
|
const input = (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
313
|
-
type:
|
|
314
|
-
properties:
|
|
289
|
+
type: effect_1.Option.some('object'),
|
|
290
|
+
properties: effect_1.Option.some({
|
|
315
291
|
id: (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
316
|
-
type:
|
|
317
|
-
in:
|
|
292
|
+
type: effect_1.Option.some('string'),
|
|
293
|
+
in: effect_1.Option.some('query'),
|
|
318
294
|
}),
|
|
319
295
|
photoId: (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
320
|
-
type:
|
|
321
|
-
in:
|
|
296
|
+
type: effect_1.Option.some('string'),
|
|
297
|
+
in: effect_1.Option.some('body'),
|
|
322
298
|
}),
|
|
323
299
|
}),
|
|
324
|
-
required:
|
|
325
|
-
additionalProperties:
|
|
300
|
+
required: effect_1.Option.some(['photoId']),
|
|
301
|
+
additionalProperties: effect_1.Option.some(false),
|
|
326
302
|
});
|
|
327
303
|
const payload = getGenerateHandlerInput({ input });
|
|
328
304
|
const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
|
|
329
|
-
expect(
|
|
305
|
+
expect(effect_1.Either.right(`import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";
|
|
330
306
|
import { OpenApiTestAuth } from "../OpenApiTestAuth";
|
|
331
307
|
import { GetPhotoInput } from "./input";
|
|
332
308
|
import { GetPhotoOutput } from "./output";
|
|
@@ -347,20 +323,20 @@ import { globalConfigHttp } from "../GlobalConfig";
|
|
|
347
323
|
});
|
|
348
324
|
it('it should generate a handler with a nullable body input', () => {
|
|
349
325
|
const input = (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
350
|
-
type:
|
|
351
|
-
properties:
|
|
326
|
+
type: effect_1.Option.some('object'),
|
|
327
|
+
properties: effect_1.Option.some({
|
|
352
328
|
photoId: (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
353
|
-
type:
|
|
354
|
-
in:
|
|
355
|
-
nullable:
|
|
329
|
+
type: effect_1.Option.some('string'),
|
|
330
|
+
in: effect_1.Option.some('body'),
|
|
331
|
+
nullable: effect_1.Option.some(true),
|
|
356
332
|
}),
|
|
357
333
|
}),
|
|
358
|
-
required:
|
|
359
|
-
additionalProperties:
|
|
334
|
+
required: effect_1.Option.none(),
|
|
335
|
+
additionalProperties: effect_1.Option.some(false),
|
|
360
336
|
});
|
|
361
337
|
const payload = getGenerateHandlerInput({ input });
|
|
362
338
|
const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
|
|
363
|
-
expect(
|
|
339
|
+
expect(effect_1.Either.right(`import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";
|
|
364
340
|
import { castUndefinedPropertyToNull } from "@trayio/commons/dynamictype/DynamicType";
|
|
365
341
|
import { OpenApiTestAuth } from "../OpenApiTestAuth";
|
|
366
342
|
import { GetPhotoInput } from "./input";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Either } from 'effect';
|
|
2
2
|
import { SchemaObject } from '../OpenApiTypeDescriptors';
|
|
3
3
|
export type GenerateHandlerTestInput = {
|
|
4
4
|
operationNameCamelCase: string;
|
|
5
5
|
input: SchemaObject;
|
|
6
6
|
output: SchemaObject;
|
|
7
7
|
};
|
|
8
|
-
export declare const generateHandlerTest: ({ operationNameCamelCase, input, output, }: GenerateHandlerTestInput) =>
|
|
8
|
+
export declare const generateHandlerTest: ({ operationNameCamelCase, input, output, }: GenerateHandlerTestInput) => Either.Either<string, Error>;
|
|
9
9
|
//# sourceMappingURL=GenerateHandlerTest.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GenerateHandlerTest.d.ts","sourceRoot":"","sources":["../../src/file-generators/GenerateHandlerTest.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"GenerateHandlerTest.d.ts","sourceRoot":"","sources":["../../src/file-generators/GenerateHandlerTest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAgB,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAqB,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAE5E,MAAM,MAAM,wBAAwB,GAAG;IACtC,sBAAsB,EAAE,MAAM,CAAC;IAC/B,KAAK,EAAE,YAAY,CAAC;IACpB,MAAM,EAAE,YAAY,CAAC;CACrB,CAAC;AAgGF,eAAO,MAAM,mBAAmB,GAAI,4CAIjC,wBAAwB,KAAG,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAqCtD,CAAC"}
|
|
@@ -1,82 +1,66 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.generateHandlerTest = void 0;
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return `'test_value'`;
|
|
38
|
-
}, (type) => {
|
|
39
|
-
switch (type) {
|
|
40
|
-
case 'string':
|
|
41
|
-
const isEnum = O.isSome(prop.enum);
|
|
42
|
-
if (isEnum) {
|
|
43
|
-
const enumValues = O.getOrElse(() => ['test'])(prop.enum);
|
|
44
|
-
if (enumValues.length > 0) {
|
|
45
|
-
return `'${enumValues[0]}'`;
|
|
4
|
+
const effect_1 = require("effect");
|
|
5
|
+
const getDefaultValue = (prop) => (0, effect_1.pipe)(prop.default, effect_1.Option.match({
|
|
6
|
+
onNone: () => effect_1.Option.match(prop.type, {
|
|
7
|
+
onNone: () => {
|
|
8
|
+
if (effect_1.Option.isSome(prop.oneOf)) {
|
|
9
|
+
const oneOfProp = effect_1.Option.getOrElse(prop.oneOf, () => []);
|
|
10
|
+
if (oneOfProp.length > 0) {
|
|
11
|
+
return getDefaultValue(oneOfProp[0]);
|
|
46
12
|
}
|
|
47
13
|
}
|
|
48
|
-
return `'test'`;
|
|
49
|
-
case 'number':
|
|
50
|
-
case 'integer':
|
|
51
|
-
return 2;
|
|
52
|
-
case 'boolean':
|
|
53
|
-
return true;
|
|
54
|
-
case 'array':
|
|
55
|
-
const arrayProp = prop;
|
|
56
|
-
return arrayProp.items
|
|
57
|
-
? `[${getDefaultValue(arrayProp.items)}]`
|
|
58
|
-
: '[]';
|
|
59
|
-
case 'object':
|
|
60
|
-
return O.fold(() => `{}`, (properties) => handleInput(properties))(prop.properties);
|
|
61
|
-
default:
|
|
62
14
|
return `'test_value'`;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
15
|
+
},
|
|
16
|
+
onSome: (type) => {
|
|
17
|
+
switch (type) {
|
|
18
|
+
case 'string':
|
|
19
|
+
const isEnum = effect_1.Option.isSome(prop.enum);
|
|
20
|
+
if (isEnum) {
|
|
21
|
+
const enumValues = effect_1.Option.getOrElse(prop.enum, () => ['test']);
|
|
22
|
+
if (enumValues.length > 0) {
|
|
23
|
+
return `'${enumValues[0]}'`;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return `'test'`;
|
|
27
|
+
case 'number':
|
|
28
|
+
case 'integer':
|
|
29
|
+
return 2;
|
|
30
|
+
case 'boolean':
|
|
31
|
+
return true;
|
|
32
|
+
case 'array':
|
|
33
|
+
const arrayProp = prop;
|
|
34
|
+
return arrayProp.items
|
|
35
|
+
? `[${getDefaultValue(arrayProp.items)}]`
|
|
36
|
+
: '[]';
|
|
37
|
+
case 'object':
|
|
38
|
+
return effect_1.Option.match(prop.properties, {
|
|
39
|
+
onNone: () => `{}`,
|
|
40
|
+
onSome: (properties) => handleInput(properties),
|
|
41
|
+
});
|
|
42
|
+
default:
|
|
43
|
+
return `'test_value'`;
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
}),
|
|
47
|
+
onSome: (defaultEntry) => {
|
|
48
|
+
if (Array.isArray(defaultEntry)) {
|
|
49
|
+
if (defaultEntry.length === 0) {
|
|
50
|
+
return getDefaultValue({ ...prop, default: effect_1.Option.none() });
|
|
51
|
+
}
|
|
52
|
+
return `'${defaultEntry[0]}'`;
|
|
68
53
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
54
|
+
switch (typeof defaultEntry) {
|
|
55
|
+
case 'string':
|
|
56
|
+
return `'${defaultEntry}'`;
|
|
57
|
+
case 'number':
|
|
58
|
+
case 'boolean':
|
|
59
|
+
return defaultEntry;
|
|
60
|
+
default:
|
|
61
|
+
return `'test_value'`;
|
|
62
|
+
}
|
|
63
|
+
},
|
|
80
64
|
}));
|
|
81
65
|
// TODO: make handleInput and handleOutput accept an option and do the fold inside, will make the code cleaner in the template and switch case
|
|
82
66
|
const handleInput = (inputs) => {
|
|
@@ -87,7 +71,8 @@ const handleOutput = (outputs) => {
|
|
|
87
71
|
const expectations = Object.entries(outputs).map(([key, prop]) => `expect(outputValue['${key}']).toEqual(${getDefaultValue(prop)});`);
|
|
88
72
|
return expectations.join('\n');
|
|
89
73
|
};
|
|
90
|
-
const generateHandlerTest = ({ operationNameCamelCase, input, output, }) =>
|
|
74
|
+
const generateHandlerTest = ({ operationNameCamelCase, input, output, }) => effect_1.Either.try({
|
|
75
|
+
try: () => `import { OperationHandlerTestSetup } from '@trayio/cdk-dsl/connector/operation/OperationHandlerTest';
|
|
91
76
|
import { OperationHandlerResult } from '@trayio/cdk-dsl/connector/operation/OperationHandler';
|
|
92
77
|
import { ${operationNameCamelCase}Handler } from './handler';
|
|
93
78
|
import '@trayio/cdk-runtime/connector/operation/OperationHandlerTestRunner';
|
|
@@ -99,19 +84,27 @@ const generateHandlerTest = ({ operationNameCamelCase, input, output, }) => E.tr
|
|
|
99
84
|
.testCase('should ${operationNameCamelCase}', (testCase) =>
|
|
100
85
|
testCase
|
|
101
86
|
.givenNothing()
|
|
102
|
-
.when(() => (${
|
|
87
|
+
.when(() => (${effect_1.Option.match(input.properties, {
|
|
88
|
+
onNone: () => `{}`,
|
|
89
|
+
onSome: (properties) => handleInput(properties),
|
|
90
|
+
})}
|
|
103
91
|
))
|
|
104
92
|
.then(({ output }) => {
|
|
105
93
|
// console.log(output);
|
|
106
94
|
const outputValue =
|
|
107
95
|
OperationHandlerResult.getSuccessfulValueOrFail(output);
|
|
108
|
-
${
|
|
96
|
+
${effect_1.Option.match(output.properties, {
|
|
97
|
+
onNone: () => `{}`,
|
|
98
|
+
onSome: (properties) => handleOutput(properties),
|
|
99
|
+
})}
|
|
109
100
|
|
|
110
101
|
})
|
|
111
102
|
.finallyDoNothing()
|
|
112
103
|
)
|
|
113
104
|
.nothingAfterAll()
|
|
114
|
-
);`,
|
|
105
|
+
);`,
|
|
106
|
+
catch: (e) => new Error(`Failed to generate handler test: ${e}`),
|
|
107
|
+
});
|
|
115
108
|
exports.generateHandlerTest = generateHandlerTest;
|
|
116
109
|
// ${handleOutput(output.properties || {})}
|
|
117
110
|
// .when(() => (${O.fold(input.properties ? handleInput(input.properties) : `{}`
|