@trayio/tray-openapi 5.35.0-unstable.fd7158a → 6.0.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.
Files changed (41) hide show
  1. package/dist/OpenApiCodecs.d.ts +4 -207
  2. package/dist/OpenApiCodecs.d.ts.map +1 -1
  3. package/dist/OpenApiCodecs.js +3 -3
  4. package/dist/OpenApiSchemaImporter.d.ts +2 -2
  5. package/dist/OpenApiSchemaImporter.d.ts.map +1 -1
  6. package/dist/OpenApiSchemaImporter.js +55 -33
  7. package/dist/OpenApiSchemaImporter.unit.test.js +13 -24
  8. package/dist/OpenApiSchemaTransformer.d.ts +2 -2
  9. package/dist/OpenApiSchemaTransformer.d.ts.map +1 -1
  10. package/dist/OpenApiSchemaTransformer.js +25 -2
  11. package/dist/OpenApiSchemaTransformer.unit.test.js +44 -30
  12. package/dist/OpenApiTypeDescriptors.d.ts +32 -389
  13. package/dist/OpenApiTypeDescriptors.d.ts.map +1 -1
  14. package/dist/OpenApiTypeDescriptors.js +109 -80
  15. package/dist/file-generators/GenerateHandler.d.ts +2 -2
  16. package/dist/file-generators/GenerateHandler.d.ts.map +1 -1
  17. package/dist/file-generators/GenerateHandler.js +78 -75
  18. package/dist/file-generators/GenerateHandler.unit.test.js +97 -73
  19. package/dist/file-generators/GenerateHandlerTest.d.ts +2 -2
  20. package/dist/file-generators/GenerateHandlerTest.d.ts.map +1 -1
  21. package/dist/file-generators/GenerateHandlerTest.js +76 -69
  22. package/dist/file-generators/GenerateHandlerTest.unit.test.js +230 -206
  23. package/dist/file-generators/GenerateOperationJson.d.ts +2 -2
  24. package/dist/file-generators/GenerateOperationJson.d.ts.map +1 -1
  25. package/dist/file-generators/GenerateOperationJson.js +29 -4
  26. package/dist/file-generators/GenerateOperationJson.unit.test.js +49 -25
  27. package/dist/file-generators/SchemaGenerator.d.ts.map +1 -1
  28. package/dist/file-generators/SchemaGenerator.js +37 -14
  29. package/dist/file-generators/types/GenerateInputSchema.d.ts +2 -2
  30. package/dist/file-generators/types/GenerateInputSchema.d.ts.map +1 -1
  31. package/dist/file-generators/types/GenerateInputSchema.js +95 -88
  32. package/dist/file-generators/types/GenerateInputSchema.test.js +91 -60
  33. package/dist/file-generators/types/GenerateInputType.test.js +169 -143
  34. package/dist/file-generators/types/GenerateInputTypes.d.ts +2 -2
  35. package/dist/file-generators/types/GenerateInputTypes.d.ts.map +1 -1
  36. package/dist/file-generators/types/GenerateInputTypes.js +28 -7
  37. package/dist/file-generators/types/GenerateOutput.d.ts +6 -4
  38. package/dist/file-generators/types/GenerateOutput.d.ts.map +1 -1
  39. package/dist/file-generators/types/GenerateOutput.js +57 -46
  40. package/dist/file-generators/types/GenerateOutput.test.js +62 -35
  41. package/package.json +8 -6
@@ -1,90 +1,119 @@
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
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.openApiSpecSchema = exports.openApiSpecPathSchema = exports.parameterSchemaSchema = exports.schemaObjectTypeCodec = exports.schemaObjectSchema = exports.baseSchemaObjectSchema = void 0;
4
- const effect_1 = require("effect");
26
+ exports.openApiSpecTypeDescriptor = exports.openApiSpecPathTypeDescriptor = exports.parameterSchemaTypeDescriptor = exports.schemaObjectTypeCodec = exports.schemaObjectTypeDescriptor = exports.baseSchemaObjectSchemaTypeDescriptor = void 0;
27
+ const t = __importStar(require("io-ts"));
28
+ const io_ts_types_1 = require("io-ts-types");
5
29
  const TypeCodec_1 = require("@trayio/commons/codec/TypeCodec");
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),
30
+ // Type Descriptors
31
+ const nonArraySchemaObjectType = t.keyof({
32
+ boolean: null,
33
+ object: null,
34
+ number: null,
35
+ string: null,
36
+ integer: null,
37
+ });
38
+ exports.baseSchemaObjectSchemaTypeDescriptor = t.recursion('baseSchema', () => t.type({
39
+ title: (0, io_ts_types_1.optionFromNullable)(t.string),
40
+ additionalProperties: (0, io_ts_types_1.optionFromNullable)(t.union([t.boolean, exports.schemaObjectTypeDescriptor])),
41
+ properties: (0, io_ts_types_1.optionFromNullable)(t.record(t.string, exports.schemaObjectTypeDescriptor)),
42
+ required: (0, io_ts_types_1.optionFromNullable)(t.array(t.string)),
43
+ allOf: (0, io_ts_types_1.optionFromNullable)(t.array(exports.schemaObjectTypeDescriptor)),
44
+ oneOf: (0, io_ts_types_1.optionFromNullable)(t.array(exports.schemaObjectTypeDescriptor)),
45
+ anyOf: (0, io_ts_types_1.optionFromNullable)(t.array(exports.schemaObjectTypeDescriptor)),
46
+ not: (0, io_ts_types_1.optionFromNullable)(exports.schemaObjectTypeDescriptor),
47
+ in: (0, io_ts_types_1.optionFromNullable)(t.string),
48
+ nullable: (0, io_ts_types_1.optionFromNullable)(t.boolean),
49
+ default: (0, io_ts_types_1.optionFromNullable)(t.union([
50
+ t.string,
51
+ t.number,
52
+ t.boolean,
53
+ t.array(t.union([t.string, t.number, t.boolean])),
54
+ ])),
55
+ enum: (0, io_ts_types_1.optionFromNullable)(t.array(t.union([t.string, t.number, t.boolean]))),
56
+ }));
57
+ const arraySchemaObjectSchemaTypeDescriptor = t.recursion('ArraySchema', () => t.intersection([
58
+ exports.baseSchemaObjectSchemaTypeDescriptor,
59
+ t.type({
60
+ type: (0, io_ts_types_1.optionFromNullable)(t.literal('array')),
61
+ items: exports.schemaObjectTypeDescriptor,
62
+ }),
63
+ ]));
64
+ const nonArraySchemaObjectSchemaTypeDescriptor = t.recursion('nonArraySchema', () => t.intersection([
65
+ exports.baseSchemaObjectSchemaTypeDescriptor,
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)),
42
79
  });
43
- const mediaTypeSchema = effect_1.Schema.Struct({
44
- schema: effect_1.Schema.OptionFromNullishOr(exports.schemaObjectSchema, null),
80
+ const mediaTypeTypeDescriptor = t.type({
81
+ schema: (0, io_ts_types_1.optionFromNullable)(exports.schemaObjectTypeDescriptor),
45
82
  });
46
- const openApiSpecRequestBodySchema = effect_1.Schema.Struct({
47
- content: effect_1.Schema.mutable(effect_1.Schema.Record({ key: effect_1.Schema.String, value: mediaTypeSchema })),
83
+ const openApiSpecRequestBodyTypeDescriptor = t.type({
84
+ content: t.record(t.string, mediaTypeTypeDescriptor),
48
85
  });
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
- }),
86
+ const openApiSpecResponsesTypeDescriptor = t.record(t.string, t.type({
87
+ description: t.string,
88
+ content: (0, io_ts_types_1.optionFromNullable)(t.record(t.string, mediaTypeTypeDescriptor)),
55
89
  }));
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,
90
+ exports.parameterSchemaTypeDescriptor = t.type({
91
+ name: t.string,
92
+ in: t.string,
93
+ description: (0, io_ts_types_1.optionFromNullable)(t.string),
94
+ required: (0, io_ts_types_1.optionFromNullable)(t.boolean),
95
+ schema: exports.schemaObjectTypeDescriptor,
62
96
  });
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),
97
+ exports.openApiSpecPathTypeDescriptor = t.type({
98
+ description: (0, io_ts_types_1.optionFromNullable)(t.string),
99
+ summary: (0, io_ts_types_1.optionFromNullable)(t.string),
100
+ tags: (0, io_ts_types_1.optionFromNullable)(t.array(t.string)),
101
+ operationId: t.string,
102
+ parameters: (0, io_ts_types_1.optionFromNullable)(t.array(exports.parameterSchemaTypeDescriptor)),
103
+ requestBody: (0, io_ts_types_1.optionFromNullable)(openApiSpecRequestBodyTypeDescriptor),
104
+ responses: (0, io_ts_types_1.optionFromNullable)(openApiSpecResponsesTypeDescriptor),
71
105
  });
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,
106
+ const httpKeys = t.keyof({
107
+ get: null,
108
+ post: null,
109
+ put: null,
110
+ patch: null,
111
+ delete: null,
112
+ });
113
+ exports.openApiSpecTypeDescriptor = t.type({
114
+ openapi: t.string,
115
+ info: t.type({ title: t.string, description: t.string, version: t.string }),
116
+ servers: t.array(t.type({ url: t.string })),
117
+ paths: t.record(t.string, TypeCodec_1.TypeCodec.partialRecord(httpKeys, exports.openApiSpecPathTypeDescriptor)),
118
+ components: componentSchemaTypeDescriptor,
90
119
  });
@@ -1,4 +1,4 @@
1
- import { Either } from 'effect';
1
+ import * as E from 'fp-ts/Either';
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) => Either.Either<string, Error>;
13
+ export declare const generateHandler: ({ connectorNamePascalCase, operationNamePascalCase, operationNameCamelCase, httpMethod, baseUrl, httpPath, input, }: GenerateHandlerInput) => E.Either<Error, string>;
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":"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
+ {"version":3,"file":"GenerateHandler.d.ts","sourceRoot":"","sources":["../../src/file-generators/GenerateHandler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,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;AAiNF,eAAO,MAAM,eAAe,wHAQzB,oBAAoB,KAAG,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAqB9C,CAAC"}
@@ -1,20 +1,41 @@
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
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.generateHandler = void 0;
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
- });
27
+ const O = __importStar(require("fp-ts/Option"));
28
+ const E = __importStar(require("fp-ts/Either"));
29
+ const getInputVariable = (name, type) => O.fold(() => `input.${name}`, (inputType) => {
30
+ switch (inputType) {
31
+ case 'integer':
32
+ case 'boolean':
33
+ case 'number':
34
+ return `input.${name}.toString()`;
35
+ default:
36
+ return `input.${name}`;
37
+ }
38
+ })(type);
18
39
  const generateRequestHandlerInputs = (inputs, bodyInputs) => {
19
40
  if (bodyInputs.length > 0) {
20
41
  let containsNullable = false;
@@ -53,69 +74,54 @@ const handleOptionalInput = (inputString, name, requiredInputs) => {
53
74
  };
54
75
  const constructInputs = (properties, requiredInputs) => {
55
76
  const inputsArray = Object.entries(properties);
56
- const requiredInputsArray = effect_1.Option.getOrElse(requiredInputs, () => []);
77
+ const requiredInputsArray = O.getOrElse(() => [])(requiredInputs);
57
78
  const bodyInputs = [];
58
79
  const handlerInput = inputsArray.map(([name, input], index) => {
59
80
  let inputMapping = '';
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
- });
81
+ return O.fold(() => '', (inputIn) => {
82
+ switch (inputIn) {
83
+ case 'body':
84
+ bodyInputs.push({
85
+ input: `${name}: input.${name}`,
86
+ nullable: O.getOrElse(() => {
87
+ if (requiredInputsArray.includes(name)) {
88
+ return false;
89
+ }
90
+ return true;
91
+ })(input.nullable),
92
+ });
93
+ break;
94
+ case 'path':
95
+ inputMapping = handleOptionalInput(`requestBuilder = requestBuilder.addPathParameter("${name}", ${getInputVariable(name, input.type)});`, name, requiredInputsArray);
96
+ break;
97
+ case 'query':
98
+ inputMapping = handleOptionalInput(`requestBuilder = requestBuilder.addQueryString("${name}", ${getInputVariable(name, input.type)});`, name, requiredInputsArray);
99
+ break;
100
+ case 'header':
101
+ inputMapping = handleOptionalInput(`requestBuilder = requestBuilder.addHeader("${name}", ${getInputVariable(name, input.type)});`, name, requiredInputsArray);
102
+ break;
103
+ }
104
+ return inputMapping;
105
+ })(input.in);
88
106
  });
89
107
  return generateRequestHandlerInputs(handlerInput, bodyInputs);
90
108
  };
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
- });
109
+ const handleInput = (inputs) => O.fold(() => 'request.withoutBody()', (properties) => `{${constructInputs(properties, inputs.required)}}`)(inputs.properties);
110
+ const generatePath = (path, inputs) => O.fold(() => path, (properties) => Object.entries(properties).reduce((acc, [name, input]) => O.fold(() => acc, (inValue) => {
111
+ if (inValue === 'path') {
112
+ return acc.replace(`{${name}}`, `:${name}`);
113
+ }
114
+ return acc;
115
+ })(input.in), path))(inputs.properties);
107
116
  const generateImports = (connectorNamePascalCase, operationNamePascalCase, inputs) => {
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
- });
117
+ const requiredInputs = O.getOrElse(() => [])(inputs.required);
118
+ const containsNullable = O.fold(() => false, (properties) => !!Object.entries(properties).find(([name, input]) => O.getOrElse(() => {
119
+ const inputIn = O.getOrElse(() => '')(input.in);
120
+ if (!requiredInputs.includes(name) && inputIn === 'body') {
121
+ return true;
122
+ }
123
+ return false;
124
+ })(input.nullable)))(inputs.properties);
119
125
  const imports = [
120
126
  'import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";',
121
127
  ];
@@ -130,8 +136,7 @@ const generateImports = (connectorNamePascalCase, operationNamePascalCase, input
130
136
  `import { globalConfigHttp } from "../GlobalConfig";`,
131
137
  ].join('\n');
132
138
  };
133
- const generateHandler = ({ connectorNamePascalCase, operationNamePascalCase, operationNameCamelCase, httpMethod, baseUrl, httpPath, input, }) => effect_1.Either.try({
134
- try: () => `${generateImports(connectorNamePascalCase, operationNamePascalCase, input)}
139
+ const generateHandler = ({ connectorNamePascalCase, operationNamePascalCase, operationNameCamelCase, httpMethod, baseUrl, httpPath, input, }) => E.tryCatch(() => `${generateImports(connectorNamePascalCase, operationNamePascalCase, input)}
135
140
 
136
141
  export const ${operationNameCamelCase}Handler = OperationHandlerSetup.configureHandler<
137
142
  ${connectorNamePascalCase}Auth,
@@ -144,7 +149,5 @@ const generateHandler = ({ connectorNamePascalCase, operationNamePascalCase, ope
144
149
  .handleRequest((ctx, input, request) => ${handleInput(input)})
145
150
  .handleResponse((ctx, input, response) => response.parseWithBodyAsJson())
146
151
  )
147
- );`,
148
- catch: (error) => new Error(`Failed to generate handler: ${error}`),
149
- });
152
+ );`, (error) => new Error(`Failed to generate handler: ${error}`));
150
153
  exports.generateHandler = generateHandler;