@trayio/tray-openapi 5.33.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,119 +1,90 @@
|
|
|
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
|
-
exports.
|
|
27
|
-
const
|
|
28
|
-
const io_ts_types_1 = require("io-ts-types");
|
|
3
|
+
exports.openApiSpecSchema = exports.openApiSpecPathSchema = exports.parameterSchemaSchema = exports.schemaObjectTypeCodec = exports.schemaObjectSchema = exports.baseSchemaObjectSchema = void 0;
|
|
4
|
+
const effect_1 = require("effect");
|
|
29
5
|
const TypeCodec_1 = require("@trayio/commons/codec/TypeCodec");
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const
|
|
65
|
-
exports.
|
|
66
|
-
t.type({
|
|
67
|
-
type: (0, io_ts_types_1.optionFromNullable)(nonArraySchemaObjectType),
|
|
68
|
-
}),
|
|
69
|
-
]));
|
|
70
|
-
// TODO: do we need the schemaObjectTypeDescriptor AND the schemaObjectTypeCodec?
|
|
71
|
-
// Added the schemaObjectTypeCodec in order to use the RemoveNullValuesCodec to remove O.none values instead of sestting them to null
|
|
72
|
-
exports.schemaObjectTypeDescriptor = t.recursion('schemaObject', () => t.union([
|
|
73
|
-
arraySchemaObjectSchemaTypeDescriptor,
|
|
74
|
-
nonArraySchemaObjectSchemaTypeDescriptor,
|
|
75
|
-
]));
|
|
76
|
-
exports.schemaObjectTypeCodec = TypeCodec_1.TypeCodec.fromDescriptor(exports.schemaObjectTypeDescriptor);
|
|
77
|
-
const componentSchemaTypeDescriptor = t.type({
|
|
78
|
-
schemas: (0, io_ts_types_1.optionFromNullable)(t.record(t.string, exports.schemaObjectTypeDescriptor)),
|
|
6
|
+
// Schemas
|
|
7
|
+
//
|
|
8
|
+
// SchemaObject is recursive, so the base fields are declared once as plain schema fields and spread into the array and
|
|
9
|
+
// non-array variants; the recursion goes through Schema.suspend. Recursive schemas need an explicit type annotation.
|
|
10
|
+
const nonArraySchemaObjectType = effect_1.Schema.Literal('boolean', 'object', 'number', 'string', 'integer');
|
|
11
|
+
const schemaObjectRef = effect_1.Schema.suspend(() => exports.schemaObjectSchema);
|
|
12
|
+
const baseSchemaObjectFields = {
|
|
13
|
+
title: effect_1.Schema.OptionFromNullishOr(effect_1.Schema.String, null),
|
|
14
|
+
additionalProperties: effect_1.Schema.OptionFromNullishOr(effect_1.Schema.Union(effect_1.Schema.Boolean, schemaObjectRef), null),
|
|
15
|
+
properties: effect_1.Schema.OptionFromNullishOr(effect_1.Schema.mutable(effect_1.Schema.Record({ key: effect_1.Schema.String, value: schemaObjectRef })), null),
|
|
16
|
+
required: effect_1.Schema.OptionFromNullishOr(effect_1.Schema.mutable(effect_1.Schema.Array(effect_1.Schema.String)), null),
|
|
17
|
+
allOf: effect_1.Schema.OptionFromNullishOr(effect_1.Schema.mutable(effect_1.Schema.Array(schemaObjectRef)), null),
|
|
18
|
+
oneOf: effect_1.Schema.OptionFromNullishOr(effect_1.Schema.mutable(effect_1.Schema.Array(schemaObjectRef)), null),
|
|
19
|
+
anyOf: effect_1.Schema.OptionFromNullishOr(effect_1.Schema.mutable(effect_1.Schema.Array(schemaObjectRef)), null),
|
|
20
|
+
not: effect_1.Schema.OptionFromNullishOr(schemaObjectRef, null),
|
|
21
|
+
in: effect_1.Schema.OptionFromNullishOr(effect_1.Schema.String, null),
|
|
22
|
+
nullable: effect_1.Schema.OptionFromNullishOr(effect_1.Schema.Boolean, null),
|
|
23
|
+
default: effect_1.Schema.OptionFromNullishOr(effect_1.Schema.Union(effect_1.Schema.String, effect_1.Schema.Number, effect_1.Schema.Boolean, effect_1.Schema.mutable(effect_1.Schema.Array(effect_1.Schema.Union(effect_1.Schema.String, effect_1.Schema.Number, effect_1.Schema.Boolean)))), null),
|
|
24
|
+
enum: effect_1.Schema.OptionFromNullishOr(effect_1.Schema.mutable(effect_1.Schema.Array(effect_1.Schema.Union(effect_1.Schema.String, effect_1.Schema.Number, effect_1.Schema.Boolean))), null),
|
|
25
|
+
};
|
|
26
|
+
exports.baseSchemaObjectSchema = effect_1.Schema.Struct(baseSchemaObjectFields).annotations({ identifier: 'baseSchema' });
|
|
27
|
+
const arraySchemaObjectSchema = effect_1.Schema.Struct({
|
|
28
|
+
...baseSchemaObjectFields,
|
|
29
|
+
type: effect_1.Schema.OptionFromNullishOr(effect_1.Schema.Literal('array'), null),
|
|
30
|
+
items: schemaObjectRef,
|
|
31
|
+
}).annotations({ identifier: 'ArraySchema' });
|
|
32
|
+
const nonArraySchemaObjectSchema = effect_1.Schema.Struct({
|
|
33
|
+
...baseSchemaObjectFields,
|
|
34
|
+
type: effect_1.Schema.OptionFromNullishOr(nonArraySchemaObjectType, null),
|
|
35
|
+
}).annotations({ identifier: 'nonArraySchema' });
|
|
36
|
+
// TODO: do we need the schemaObjectSchema AND the schemaObjectTypeCodec?
|
|
37
|
+
// Added the schemaObjectTypeCodec in order to use the RemoveNullValuesCodec to remove Option.none() values instead of setting them to null
|
|
38
|
+
exports.schemaObjectSchema = effect_1.Schema.Union(arraySchemaObjectSchema, nonArraySchemaObjectSchema).annotations({ identifier: 'schemaObject' });
|
|
39
|
+
exports.schemaObjectTypeCodec = TypeCodec_1.TypeCodec.fromSchema(exports.schemaObjectSchema);
|
|
40
|
+
const componentSchemaSchema = effect_1.Schema.Struct({
|
|
41
|
+
schemas: effect_1.Schema.OptionFromNullishOr(effect_1.Schema.mutable(effect_1.Schema.Record({ key: effect_1.Schema.String, value: exports.schemaObjectSchema })), null),
|
|
79
42
|
});
|
|
80
|
-
const
|
|
81
|
-
schema:
|
|
43
|
+
const mediaTypeSchema = effect_1.Schema.Struct({
|
|
44
|
+
schema: effect_1.Schema.OptionFromNullishOr(exports.schemaObjectSchema, null),
|
|
82
45
|
});
|
|
83
|
-
const
|
|
84
|
-
content:
|
|
46
|
+
const openApiSpecRequestBodySchema = effect_1.Schema.Struct({
|
|
47
|
+
content: effect_1.Schema.mutable(effect_1.Schema.Record({ key: effect_1.Schema.String, value: mediaTypeSchema })),
|
|
85
48
|
});
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
49
|
+
const openApiSpecResponsesSchema = effect_1.Schema.mutable(effect_1.Schema.Record({
|
|
50
|
+
key: effect_1.Schema.String,
|
|
51
|
+
value: effect_1.Schema.Struct({
|
|
52
|
+
description: effect_1.Schema.String,
|
|
53
|
+
content: effect_1.Schema.OptionFromNullishOr(effect_1.Schema.mutable(effect_1.Schema.Record({ key: effect_1.Schema.String, value: mediaTypeSchema })), null),
|
|
54
|
+
}),
|
|
89
55
|
}));
|
|
90
|
-
exports.
|
|
91
|
-
name:
|
|
92
|
-
in:
|
|
93
|
-
description: (
|
|
94
|
-
required: (
|
|
95
|
-
schema: exports.
|
|
56
|
+
exports.parameterSchemaSchema = effect_1.Schema.Struct({
|
|
57
|
+
name: effect_1.Schema.String,
|
|
58
|
+
in: effect_1.Schema.String,
|
|
59
|
+
description: effect_1.Schema.OptionFromNullishOr(effect_1.Schema.String, null),
|
|
60
|
+
required: effect_1.Schema.OptionFromNullishOr(effect_1.Schema.Boolean, null),
|
|
61
|
+
schema: exports.schemaObjectSchema,
|
|
96
62
|
});
|
|
97
|
-
exports.
|
|
98
|
-
description: (
|
|
99
|
-
summary: (
|
|
100
|
-
tags: (
|
|
101
|
-
operationId:
|
|
102
|
-
parameters: (
|
|
103
|
-
requestBody: (
|
|
104
|
-
responses: (
|
|
63
|
+
exports.openApiSpecPathSchema = effect_1.Schema.Struct({
|
|
64
|
+
description: effect_1.Schema.OptionFromNullishOr(effect_1.Schema.String, null),
|
|
65
|
+
summary: effect_1.Schema.OptionFromNullishOr(effect_1.Schema.String, null),
|
|
66
|
+
tags: effect_1.Schema.OptionFromNullishOr(effect_1.Schema.mutable(effect_1.Schema.Array(effect_1.Schema.String)), null),
|
|
67
|
+
operationId: effect_1.Schema.String,
|
|
68
|
+
parameters: effect_1.Schema.OptionFromNullishOr(effect_1.Schema.mutable(effect_1.Schema.Array(exports.parameterSchemaSchema)), null),
|
|
69
|
+
requestBody: effect_1.Schema.OptionFromNullishOr(openApiSpecRequestBodySchema, null),
|
|
70
|
+
responses: effect_1.Schema.OptionFromNullishOr(openApiSpecResponsesSchema, null),
|
|
105
71
|
});
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
72
|
+
/** One optional Path per HTTP method, the io-ts `partialRecord(keyof, path)` shape. */
|
|
73
|
+
const pathsByMethodSchema = effect_1.Schema.partial(effect_1.Schema.Struct({
|
|
74
|
+
get: exports.openApiSpecPathSchema,
|
|
75
|
+
post: exports.openApiSpecPathSchema,
|
|
76
|
+
put: exports.openApiSpecPathSchema,
|
|
77
|
+
patch: exports.openApiSpecPathSchema,
|
|
78
|
+
delete: exports.openApiSpecPathSchema,
|
|
79
|
+
}));
|
|
80
|
+
exports.openApiSpecSchema = effect_1.Schema.Struct({
|
|
81
|
+
openapi: effect_1.Schema.String,
|
|
82
|
+
info: effect_1.Schema.Struct({
|
|
83
|
+
title: effect_1.Schema.String,
|
|
84
|
+
description: effect_1.Schema.String,
|
|
85
|
+
version: effect_1.Schema.String,
|
|
86
|
+
}),
|
|
87
|
+
servers: effect_1.Schema.mutable(effect_1.Schema.Array(effect_1.Schema.Struct({ url: effect_1.Schema.String }))),
|
|
88
|
+
paths: effect_1.Schema.mutable(effect_1.Schema.Record({ key: effect_1.Schema.String, value: pathsByMethodSchema })),
|
|
89
|
+
components: componentSchemaSchema,
|
|
119
90
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Either } from 'effect';
|
|
2
2
|
import { SchemaObject } from '../OpenApiTypeDescriptors';
|
|
3
3
|
type HandlerHttpMethod = 'get' | 'post' | 'put' | 'patch' | 'delete';
|
|
4
4
|
export type GenerateHandlerInput = {
|
|
@@ -10,6 +10,6 @@ export type GenerateHandlerInput = {
|
|
|
10
10
|
httpPath: string;
|
|
11
11
|
input: SchemaObject;
|
|
12
12
|
};
|
|
13
|
-
export declare const generateHandler: ({ connectorNamePascalCase, operationNamePascalCase, operationNameCamelCase, httpMethod, baseUrl, httpPath, input, }: GenerateHandlerInput) =>
|
|
13
|
+
export declare const generateHandler: ({ connectorNamePascalCase, operationNamePascalCase, operationNameCamelCase, httpMethod, baseUrl, httpPath, input, }: GenerateHandlerInput) => Either.Either<string, Error>;
|
|
14
14
|
export {};
|
|
15
15
|
//# sourceMappingURL=GenerateHandler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GenerateHandler.d.ts","sourceRoot":"","sources":["../../src/file-generators/GenerateHandler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"GenerateHandler.d.ts","sourceRoot":"","sources":["../../src/file-generators/GenerateHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,YAAY,EAAoB,MAAM,2BAA2B,CAAC;AAE3E,KAAK,iBAAiB,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;AAErE,MAAM,MAAM,oBAAoB,GAAG;IAClC,uBAAuB,EAAE,MAAM,CAAC;IAChC,uBAAuB,EAAE,MAAM,CAAC;IAChC,sBAAsB,EAAE,MAAM,CAAC;IAC/B,UAAU,EAAE,iBAAiB,CAAC;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,YAAY,CAAC;CACpB,CAAC;AAuNF,eAAO,MAAM,eAAe,GAAI,qHAQ7B,oBAAoB,KAAG,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAqBlD,CAAC"}
|
|
@@ -1,41 +1,20 @@
|
|
|
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.generateHandler = void 0;
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
4
|
+
const effect_1 = require("effect");
|
|
5
|
+
const getInputVariable = (name, type) => effect_1.Option.match(type, {
|
|
6
|
+
onNone: () => `input.${name}`,
|
|
7
|
+
onSome: (inputType) => {
|
|
8
|
+
switch (inputType) {
|
|
9
|
+
case 'integer':
|
|
10
|
+
case 'boolean':
|
|
11
|
+
case 'number':
|
|
12
|
+
return `input.${name}.toString()`;
|
|
13
|
+
default:
|
|
14
|
+
return `input.${name}`;
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
});
|
|
39
18
|
const generateRequestHandlerInputs = (inputs, bodyInputs) => {
|
|
40
19
|
if (bodyInputs.length > 0) {
|
|
41
20
|
let containsNullable = false;
|
|
@@ -74,54 +53,69 @@ const handleOptionalInput = (inputString, name, requiredInputs) => {
|
|
|
74
53
|
};
|
|
75
54
|
const constructInputs = (properties, requiredInputs) => {
|
|
76
55
|
const inputsArray = Object.entries(properties);
|
|
77
|
-
const requiredInputsArray =
|
|
56
|
+
const requiredInputsArray = effect_1.Option.getOrElse(requiredInputs, () => []);
|
|
78
57
|
const bodyInputs = [];
|
|
79
58
|
const handlerInput = inputsArray.map(([name, input], index) => {
|
|
80
59
|
let inputMapping = '';
|
|
81
|
-
return
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
60
|
+
return effect_1.Option.match(input.in, {
|
|
61
|
+
onNone: () => '',
|
|
62
|
+
onSome: (inputIn) => {
|
|
63
|
+
switch (inputIn) {
|
|
64
|
+
case 'body':
|
|
65
|
+
bodyInputs.push({
|
|
66
|
+
input: `${name}: input.${name}`,
|
|
67
|
+
nullable: effect_1.Option.getOrElse(input.nullable, () => {
|
|
68
|
+
if (requiredInputsArray.includes(name)) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
return true;
|
|
72
|
+
}),
|
|
73
|
+
});
|
|
74
|
+
break;
|
|
75
|
+
case 'path':
|
|
76
|
+
inputMapping = handleOptionalInput(`requestBuilder = requestBuilder.addPathParameter("${name}", ${getInputVariable(name, input.type)});`, name, requiredInputsArray);
|
|
77
|
+
break;
|
|
78
|
+
case 'query':
|
|
79
|
+
inputMapping = handleOptionalInput(`requestBuilder = requestBuilder.addQueryString("${name}", ${getInputVariable(name, input.type)});`, name, requiredInputsArray);
|
|
80
|
+
break;
|
|
81
|
+
case 'header':
|
|
82
|
+
inputMapping = handleOptionalInput(`requestBuilder = requestBuilder.addHeader("${name}", ${getInputVariable(name, input.type)});`, name, requiredInputsArray);
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
return inputMapping;
|
|
86
|
+
},
|
|
87
|
+
});
|
|
106
88
|
});
|
|
107
89
|
return generateRequestHandlerInputs(handlerInput, bodyInputs);
|
|
108
90
|
};
|
|
109
|
-
const handleInput = (inputs) =>
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
91
|
+
const handleInput = (inputs) => effect_1.Option.match(inputs.properties, {
|
|
92
|
+
onNone: () => 'request.withoutBody()',
|
|
93
|
+
onSome: (properties) => `{${constructInputs(properties, inputs.required)}}`,
|
|
94
|
+
});
|
|
95
|
+
const generatePath = (path, inputs) => effect_1.Option.match(inputs.properties, {
|
|
96
|
+
onNone: () => path,
|
|
97
|
+
onSome: (properties) => Object.entries(properties).reduce((acc, [name, input]) => effect_1.Option.match(input.in, {
|
|
98
|
+
onNone: () => acc,
|
|
99
|
+
onSome: (inValue) => {
|
|
100
|
+
if (inValue === 'path') {
|
|
101
|
+
return acc.replace(`{${name}}`, `:${name}`);
|
|
102
|
+
}
|
|
103
|
+
return acc;
|
|
104
|
+
},
|
|
105
|
+
}), path),
|
|
106
|
+
});
|
|
116
107
|
const generateImports = (connectorNamePascalCase, operationNamePascalCase, inputs) => {
|
|
117
|
-
const requiredInputs =
|
|
118
|
-
const containsNullable =
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
108
|
+
const requiredInputs = effect_1.Option.getOrElse(inputs.required, () => []);
|
|
109
|
+
const containsNullable = effect_1.Option.match(inputs.properties, {
|
|
110
|
+
onNone: () => false,
|
|
111
|
+
onSome: (properties) => !!Object.entries(properties).find(([name, input]) => effect_1.Option.getOrElse(input.nullable, () => {
|
|
112
|
+
const inputIn = effect_1.Option.getOrElse(input.in, () => '');
|
|
113
|
+
if (!requiredInputs.includes(name) && inputIn === 'body') {
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
return false;
|
|
117
|
+
})),
|
|
118
|
+
});
|
|
125
119
|
const imports = [
|
|
126
120
|
'import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";',
|
|
127
121
|
];
|
|
@@ -136,7 +130,8 @@ const generateImports = (connectorNamePascalCase, operationNamePascalCase, input
|
|
|
136
130
|
`import { globalConfigHttp } from "../GlobalConfig";`,
|
|
137
131
|
].join('\n');
|
|
138
132
|
};
|
|
139
|
-
const generateHandler = ({ connectorNamePascalCase, operationNamePascalCase, operationNameCamelCase, httpMethod, baseUrl, httpPath, input, }) =>
|
|
133
|
+
const generateHandler = ({ connectorNamePascalCase, operationNamePascalCase, operationNameCamelCase, httpMethod, baseUrl, httpPath, input, }) => effect_1.Either.try({
|
|
134
|
+
try: () => `${generateImports(connectorNamePascalCase, operationNamePascalCase, input)}
|
|
140
135
|
|
|
141
136
|
export const ${operationNameCamelCase}Handler = OperationHandlerSetup.configureHandler<
|
|
142
137
|
${connectorNamePascalCase}Auth,
|
|
@@ -149,5 +144,7 @@ const generateHandler = ({ connectorNamePascalCase, operationNamePascalCase, ope
|
|
|
149
144
|
.handleRequest((ctx, input, request) => ${handleInput(input)})
|
|
150
145
|
.handleResponse((ctx, input, response) => response.parseWithBodyAsJson())
|
|
151
146
|
)
|
|
152
|
-
);`,
|
|
147
|
+
);`,
|
|
148
|
+
catch: (error) => new Error(`Failed to generate handler: ${error}`),
|
|
149
|
+
});
|
|
153
150
|
exports.generateHandler = generateHandler;
|