@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.
Files changed (62) hide show
  1. package/LICENSE.txt +22 -0
  2. package/README.md +39 -0
  3. package/dist/OpenApiCodecs.d.ts +5 -0
  4. package/dist/OpenApiCodecs.d.ts.map +1 -0
  5. package/dist/OpenApiCodecs.js +8 -0
  6. package/dist/OpenApiSchemaImporter.d.ts +17 -0
  7. package/dist/OpenApiSchemaImporter.d.ts.map +1 -0
  8. package/dist/OpenApiSchemaImporter.js +138 -0
  9. package/dist/OpenApiSchemaImporter.test.d.ts +2 -0
  10. package/dist/OpenApiSchemaImporter.test.d.ts.map +1 -0
  11. package/dist/OpenApiSchemaImporter.test.js +85 -0
  12. package/dist/OpenApiSchemaTransformer.d.ts +9 -0
  13. package/dist/OpenApiSchemaTransformer.d.ts.map +1 -0
  14. package/dist/OpenApiSchemaTransformer.js +68 -0
  15. package/dist/OpenApiSchemaTransformer.test.d.ts +2 -0
  16. package/dist/OpenApiSchemaTransformer.test.d.ts.map +1 -0
  17. package/dist/OpenApiSchemaTransformer.test.js +118 -0
  18. package/dist/OpenApiTypeDescriptors.d.ts +109 -0
  19. package/dist/OpenApiTypeDescriptors.d.ts.map +1 -0
  20. package/dist/OpenApiTypeDescriptors.js +107 -0
  21. package/dist/file-generators/GenerateHandler.d.ts +15 -0
  22. package/dist/file-generators/GenerateHandler.d.ts.map +1 -0
  23. package/dist/file-generators/GenerateHandler.js +110 -0
  24. package/dist/file-generators/GenerateHandler.test.d.ts +2 -0
  25. package/dist/file-generators/GenerateHandler.test.d.ts.map +1 -0
  26. package/dist/file-generators/GenerateHandler.test.js +427 -0
  27. package/dist/file-generators/GenerateHandlerTest.d.ts +9 -0
  28. package/dist/file-generators/GenerateHandlerTest.d.ts.map +1 -0
  29. package/dist/file-generators/GenerateHandlerTest.js +88 -0
  30. package/dist/file-generators/GenerateHandlerTest.test.d.ts +2 -0
  31. package/dist/file-generators/GenerateHandlerTest.test.d.ts.map +1 -0
  32. package/dist/file-generators/GenerateHandlerTest.test.js +640 -0
  33. package/dist/file-generators/GenerateOperationJson.d.ts +4 -0
  34. package/dist/file-generators/GenerateOperationJson.d.ts.map +1 -0
  35. package/dist/file-generators/GenerateOperationJson.js +44 -0
  36. package/dist/file-generators/GenerateOperationJson.test.d.ts +2 -0
  37. package/dist/file-generators/GenerateOperationJson.test.d.ts.map +1 -0
  38. package/dist/file-generators/GenerateOperationJson.test.js +78 -0
  39. package/dist/file-generators/types/GenerateInputSchema.d.ts +4 -0
  40. package/dist/file-generators/types/GenerateInputSchema.d.ts.map +1 -0
  41. package/dist/file-generators/types/GenerateInputSchema.js +131 -0
  42. package/dist/file-generators/types/GenerateInputSchema.test.d.ts +2 -0
  43. package/dist/file-generators/types/GenerateInputSchema.test.d.ts.map +1 -0
  44. package/dist/file-generators/types/GenerateInputSchema.test.js +260 -0
  45. package/dist/file-generators/types/GenerateInputType.test.d.ts +2 -0
  46. package/dist/file-generators/types/GenerateInputType.test.d.ts.map +1 -0
  47. package/dist/file-generators/types/GenerateInputType.test.js +447 -0
  48. package/dist/file-generators/types/GenerateInputTypes.d.ts +4 -0
  49. package/dist/file-generators/types/GenerateInputTypes.d.ts.map +1 -0
  50. package/dist/file-generators/types/GenerateInputTypes.js +45 -0
  51. package/dist/file-generators/types/GenerateOutput.d.ts +8 -0
  52. package/dist/file-generators/types/GenerateOutput.d.ts.map +1 -0
  53. package/dist/file-generators/types/GenerateOutput.js +81 -0
  54. package/dist/file-generators/types/GenerateOutput.test.d.ts +2 -0
  55. package/dist/file-generators/types/GenerateOutput.test.d.ts.map +1 -0
  56. package/dist/file-generators/types/GenerateOutput.test.js +213 -0
  57. package/dist/file-generators/types/JsonSchemaToTypescriptOptions.d.ts +9 -0
  58. package/dist/file-generators/types/JsonSchemaToTypescriptOptions.d.ts.map +1 -0
  59. package/dist/file-generators/types/JsonSchemaToTypescriptOptions.js +11 -0
  60. package/dist/templates/connector-template.zip +0 -0
  61. package/dist/test-openapi-spec.json +160 -0
  62. package/package.json +30 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OpenApiTypeDescriptors.d.ts","sourceRoot":"","sources":["../src/OpenApiTypeDescriptors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,OAAO,CAAC;AAE3B,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAKlC,MAAM,MAAM,QAAQ,GAAG;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE;QAAE,MAAM,EAAE,iBAAiB,CAAC;QAAC,IAAI,EAAE,OAAO,CAAA;KAAE,EAAE,CAAC;CACvD,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG;IACpB,GAAG,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE;QACL,OAAO,EAAE,MAAM,CAAC;QAChB,KAAK,EAAE,MAAM,CAAC;QACd,WAAW,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAC/C,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC3B,UAAU,EAAE,iBAAiB,CAAC;IAC9B,IAAI,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,aAAa,GAAG;IAC5C,GAAG,EAAE,OAAO,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,aAAa,GAAG;IAC9C,GAAG,EAAE,SAAS,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,cAAc,GAAG,gBAAgB,CAAC;AAE1D,MAAM,MAAM,sBAAsB,GAAG;IACp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CAAC,CAAC;IAChC,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC,CAAC;IAChC,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC,CAAC;IAChC,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;IAC5B,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;CACrB,CAAC;AAYF,eAAO,MAAM,oCAAoC,EAAE,CAAC,CAAC,IAAI,CACxD,gBAAgB,EAChB,OAAO,CAiBP,CAAC;AAyBF,eAAO,MAAM,0BAA0B,EAAE,CAAC,CAAC,IAAI,CAAC,YAAY,EAAE,OAAO,CAMnE,CAAC;AAEH,eAAO,MAAM,qBAAqB,wDAEjC,CAAC;AAuBF,eAAO,MAAM,6BAA6B,EAAE,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAQpE,CAAC;AAEF,eAAO,MAAM,6BAA6B,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAO9D,CAAC;AAUH,eAAO,MAAM,yBAAyB,EAAE,CAAC,CAAC,IAAI,CAAC,aAAa,EAAE,OAAO,CAWpE,CAAC"}
@@ -0,0 +1,107 @@
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.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");
29
+ const TypeCodec_1 = require("@trayio/commons/codec/TypeCodec");
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
+ }));
49
+ const arraySchemaObjectSchemaTypeDescriptor = t.recursion('ArraySchema', () => t.intersection([
50
+ exports.baseSchemaObjectSchemaTypeDescriptor,
51
+ t.type({ type: t.literal('array'), items: exports.schemaObjectTypeDescriptor }),
52
+ ]));
53
+ const nonArraySchemaObjectSchemaTypeDescriptor = t.recursion('nonArraySchema', () => t.intersection([
54
+ exports.baseSchemaObjectSchemaTypeDescriptor,
55
+ t.type({
56
+ type: (0, io_ts_types_1.optionFromNullable)(nonArraySchemaObjectType),
57
+ }),
58
+ ]));
59
+ // TODO: do we need the schemaObjectTypeDescriptor AND the schemaObjectTypeCodec?
60
+ // Added the schemaObjectTypeCodec in order to use the RemoveNullValuesCodec to remove O.none values instead of sestting them to null
61
+ exports.schemaObjectTypeDescriptor = t.recursion('schemaObject', () => t.union([
62
+ arraySchemaObjectSchemaTypeDescriptor,
63
+ nonArraySchemaObjectSchemaTypeDescriptor,
64
+ ]));
65
+ exports.schemaObjectTypeCodec = TypeCodec_1.TypeCodec.fromDescriptor(exports.schemaObjectTypeDescriptor);
66
+ const componentSchemaTypeDescriptor = t.type({
67
+ schemas: (0, io_ts_types_1.optionFromNullable)(t.record(t.string, exports.schemaObjectTypeDescriptor)),
68
+ });
69
+ const mediaTypeTypeDescriptor = t.type({
70
+ schema: (0, io_ts_types_1.optionFromNullable)(exports.schemaObjectTypeDescriptor),
71
+ });
72
+ const openApiSpecRequestBodyTypeDescriptor = t.type({
73
+ content: t.record(t.string, mediaTypeTypeDescriptor),
74
+ });
75
+ const openApiSpecResponsesTypeDescriptor = t.record(t.string, t.type({
76
+ description: t.string,
77
+ content: (0, io_ts_types_1.optionFromNullable)(t.record(t.string, mediaTypeTypeDescriptor)),
78
+ }));
79
+ exports.parameterSchemaTypeDescriptor = t.type({
80
+ name: t.string,
81
+ in: t.string,
82
+ description: t.string,
83
+ required: (0, io_ts_types_1.optionFromNullable)(t.boolean),
84
+ schema: exports.schemaObjectTypeDescriptor,
85
+ });
86
+ exports.openApiSpecPathTypeDescriptor = t.type({
87
+ description: t.string,
88
+ tags: (0, io_ts_types_1.optionFromNullable)(t.array(t.string)),
89
+ operationId: t.string,
90
+ parameters: (0, io_ts_types_1.optionFromNullable)(t.array(exports.parameterSchemaTypeDescriptor)),
91
+ requestBody: (0, io_ts_types_1.optionFromNullable)(openApiSpecRequestBodyTypeDescriptor),
92
+ responses: (0, io_ts_types_1.optionFromNullable)(openApiSpecResponsesTypeDescriptor),
93
+ });
94
+ const httpKeys = t.keyof({
95
+ get: null,
96
+ post: null,
97
+ put: null,
98
+ patch: null,
99
+ delete: null,
100
+ });
101
+ exports.openApiSpecTypeDescriptor = t.type({
102
+ openapi: t.string,
103
+ info: t.type({ title: t.string, description: t.string, version: t.string }),
104
+ servers: t.array(t.type({ url: t.string })),
105
+ paths: t.record(t.string, TypeCodec_1.TypeCodec.partialRecord(httpKeys, exports.openApiSpecPathTypeDescriptor)),
106
+ components: componentSchemaTypeDescriptor,
107
+ });
@@ -0,0 +1,15 @@
1
+ import * as E from 'fp-ts/Either';
2
+ import { SchemaObject } from '../OpenApiTypeDescriptors';
3
+ type HandlerHttpMethod = 'get' | 'post' | 'put' | 'patch' | 'delete';
4
+ export type GenerateHandlerInput = {
5
+ connectorNamePascalCase: string;
6
+ operationNamePascalCase: string;
7
+ operationNameCamelCase: string;
8
+ httpMethod: HandlerHttpMethod;
9
+ baseUrl: string;
10
+ httpPath: string;
11
+ input: SchemaObject;
12
+ };
13
+ export declare const generateHandler: ({ connectorNamePascalCase, operationNamePascalCase, operationNameCamelCase, httpMethod, baseUrl, httpPath, input, }: GenerateHandlerInput) => E.Either<Error, string>;
14
+ export {};
15
+ //# sourceMappingURL=GenerateHandler.d.ts.map
@@ -0,0 +1 @@
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,EAEN,YAAY,EACZ,MAAM,2BAA2B,CAAC;AAEnC,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;AAsHF,eAAO,MAAM,eAAe,wHAQzB,oBAAoB,KAAG,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAoB9C,CAAC"}
@@ -0,0 +1,110 @@
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.generateHandler = void 0;
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);
39
+ const generateRequestHandlerInputs = (inputs, bodyInputs) => {
40
+ if (bodyInputs.length > 0) {
41
+ const constructedBodyProperty = `withBodyAsJson({ ${bodyInputs.join(',')} })`;
42
+ if (inputs[0] === 'request.') {
43
+ const cleanInput = inputs.filter((item) => item !== '');
44
+ return cleanInput
45
+ .join('.')
46
+ .replace('request.', `request.${constructedBodyProperty}`);
47
+ }
48
+ inputs.push(constructedBodyProperty);
49
+ }
50
+ else {
51
+ inputs.push('withoutBody()');
52
+ }
53
+ const cleanInput = inputs.filter((item) => item !== '');
54
+ return cleanInput.join('.');
55
+ };
56
+ const constructInputs = (properties) => {
57
+ const inputsArray = Object.entries(properties);
58
+ const bodyInputs = [];
59
+ const handlerInput = inputsArray.map(([name, input], index) => {
60
+ const prefix = index === 0 ? 'request.' : '';
61
+ let inputMapping = '';
62
+ if (input.type === 'array') {
63
+ // TODO: improve error message and ideally handle this more gracefully, do we expect array types at the root level?
64
+ throw new Error('Array type not yet supported');
65
+ }
66
+ return O.fold(() => '', (inputIn) => {
67
+ switch (inputIn) {
68
+ case 'body':
69
+ bodyInputs.push(`${name}: input.${name}`);
70
+ break;
71
+ case 'path':
72
+ inputMapping = `addPathParameter("${name}", ${getInputVariable(name, input.type)})`;
73
+ break;
74
+ case 'query':
75
+ inputMapping = `addQueryString("${name}", ${getInputVariable(name, input.type)})`;
76
+ break;
77
+ case 'header':
78
+ inputMapping = `addHeader("${name}", ${getInputVariable(name, input.type)})`;
79
+ break;
80
+ }
81
+ return prefix + inputMapping;
82
+ })(input.in);
83
+ });
84
+ return generateRequestHandlerInputs(handlerInput, bodyInputs);
85
+ };
86
+ const handleInput = (inputs) => O.fold(() => 'request.withoutBody()', (properties) => constructInputs(properties))(inputs.properties);
87
+ const generatePath = (path, inputs) => O.fold(() => path, (properties) => Object.entries(properties).reduce((acc, [name, input]) => O.fold(() => acc, (inValue) => {
88
+ if (inValue === 'path') {
89
+ return acc.replace(`{${name}}`, `:${name}`);
90
+ }
91
+ return acc;
92
+ })(input.in), path))(inputs.properties);
93
+ const generateHandler = ({ connectorNamePascalCase, operationNamePascalCase, operationNameCamelCase, httpMethod, baseUrl, httpPath, input, }) => E.tryCatch(() => `import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";
94
+ import { ${connectorNamePascalCase}Auth } from "../${connectorNamePascalCase}Auth";
95
+ import { ${operationNamePascalCase}Input } from "./input";
96
+ import { ${operationNamePascalCase}Output } from "./output";
97
+
98
+ export const ${operationNameCamelCase}Handler = OperationHandlerSetup.configureHandler<
99
+ ${connectorNamePascalCase}Auth,
100
+ ${operationNamePascalCase}Input,
101
+ ${operationNamePascalCase}Output
102
+ >((handler) =>
103
+ handler.usingHttp((http) =>
104
+ http
105
+ .${httpMethod}("${baseUrl}${generatePath(httpPath, input)}")
106
+ .handleRequest((ctx, input, request) => ${handleInput(input)})
107
+ .handleResponse((ctx, input, response) => response.parseWithBodyAsJson())
108
+ )
109
+ );`, (error) => new Error(`Failed to generate handler: ${error}`));
110
+ exports.generateHandler = generateHandler;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=GenerateHandler.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GenerateHandler.test.d.ts","sourceRoot":"","sources":["../../src/file-generators/GenerateHandler.test.ts"],"names":[],"mappings":""}