@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,208 +1,5 @@
1
- export declare const openApiSpecCodec: import("@trayio/commons/dist/codec/Codec").Codec<{
2
- readonly openapi: string;
3
- readonly info: {
4
- readonly title: string;
5
- readonly description: string;
6
- readonly version: string;
7
- };
8
- readonly servers: {
9
- readonly url: string;
10
- }[];
11
- readonly paths: {
12
- [x: string]: {
13
- readonly get?: {
14
- readonly description: import("effect/Option").Option<string>;
15
- readonly summary: import("effect/Option").Option<string>;
16
- readonly tags: import("effect/Option").Option<string[]>;
17
- readonly operationId: string;
18
- readonly parameters: import("effect/Option").Option<{
19
- readonly required: import("effect/Option").Option<boolean>;
20
- readonly in: string;
21
- readonly schema: import("./OpenApiTypeDescriptors").SchemaObject;
22
- readonly description: import("effect/Option").Option<string>;
23
- readonly name: string;
24
- }[]>;
25
- readonly requestBody: import("effect/Option").Option<{
26
- readonly content: {
27
- [x: string]: {
28
- readonly schema: import("effect/Option").Option<import("./OpenApiTypeDescriptors").SchemaObject>;
29
- };
30
- };
31
- }>;
32
- readonly responses: import("effect/Option").Option<{
33
- [x: string]: {
34
- readonly content: import("effect/Option").Option<{
35
- [x: string]: {
36
- readonly schema: import("effect/Option").Option<import("./OpenApiTypeDescriptors").SchemaObject>;
37
- };
38
- }>;
39
- readonly description: string;
40
- };
41
- }>;
42
- } | undefined;
43
- readonly post?: {
44
- readonly description: import("effect/Option").Option<string>;
45
- readonly summary: import("effect/Option").Option<string>;
46
- readonly tags: import("effect/Option").Option<string[]>;
47
- readonly operationId: string;
48
- readonly parameters: import("effect/Option").Option<{
49
- readonly required: import("effect/Option").Option<boolean>;
50
- readonly in: string;
51
- readonly schema: import("./OpenApiTypeDescriptors").SchemaObject;
52
- readonly description: import("effect/Option").Option<string>;
53
- readonly name: string;
54
- }[]>;
55
- readonly requestBody: import("effect/Option").Option<{
56
- readonly content: {
57
- [x: string]: {
58
- readonly schema: import("effect/Option").Option<import("./OpenApiTypeDescriptors").SchemaObject>;
59
- };
60
- };
61
- }>;
62
- readonly responses: import("effect/Option").Option<{
63
- [x: string]: {
64
- readonly content: import("effect/Option").Option<{
65
- [x: string]: {
66
- readonly schema: import("effect/Option").Option<import("./OpenApiTypeDescriptors").SchemaObject>;
67
- };
68
- }>;
69
- readonly description: string;
70
- };
71
- }>;
72
- } | undefined;
73
- readonly put?: {
74
- readonly description: import("effect/Option").Option<string>;
75
- readonly summary: import("effect/Option").Option<string>;
76
- readonly tags: import("effect/Option").Option<string[]>;
77
- readonly operationId: string;
78
- readonly parameters: import("effect/Option").Option<{
79
- readonly required: import("effect/Option").Option<boolean>;
80
- readonly in: string;
81
- readonly schema: import("./OpenApiTypeDescriptors").SchemaObject;
82
- readonly description: import("effect/Option").Option<string>;
83
- readonly name: string;
84
- }[]>;
85
- readonly requestBody: import("effect/Option").Option<{
86
- readonly content: {
87
- [x: string]: {
88
- readonly schema: import("effect/Option").Option<import("./OpenApiTypeDescriptors").SchemaObject>;
89
- };
90
- };
91
- }>;
92
- readonly responses: import("effect/Option").Option<{
93
- [x: string]: {
94
- readonly content: import("effect/Option").Option<{
95
- [x: string]: {
96
- readonly schema: import("effect/Option").Option<import("./OpenApiTypeDescriptors").SchemaObject>;
97
- };
98
- }>;
99
- readonly description: string;
100
- };
101
- }>;
102
- } | undefined;
103
- readonly patch?: {
104
- readonly description: import("effect/Option").Option<string>;
105
- readonly summary: import("effect/Option").Option<string>;
106
- readonly tags: import("effect/Option").Option<string[]>;
107
- readonly operationId: string;
108
- readonly parameters: import("effect/Option").Option<{
109
- readonly required: import("effect/Option").Option<boolean>;
110
- readonly in: string;
111
- readonly schema: import("./OpenApiTypeDescriptors").SchemaObject;
112
- readonly description: import("effect/Option").Option<string>;
113
- readonly name: string;
114
- }[]>;
115
- readonly requestBody: import("effect/Option").Option<{
116
- readonly content: {
117
- [x: string]: {
118
- readonly schema: import("effect/Option").Option<import("./OpenApiTypeDescriptors").SchemaObject>;
119
- };
120
- };
121
- }>;
122
- readonly responses: import("effect/Option").Option<{
123
- [x: string]: {
124
- readonly content: import("effect/Option").Option<{
125
- [x: string]: {
126
- readonly schema: import("effect/Option").Option<import("./OpenApiTypeDescriptors").SchemaObject>;
127
- };
128
- }>;
129
- readonly description: string;
130
- };
131
- }>;
132
- } | undefined;
133
- readonly delete?: {
134
- readonly description: import("effect/Option").Option<string>;
135
- readonly summary: import("effect/Option").Option<string>;
136
- readonly tags: import("effect/Option").Option<string[]>;
137
- readonly operationId: string;
138
- readonly parameters: import("effect/Option").Option<{
139
- readonly required: import("effect/Option").Option<boolean>;
140
- readonly in: string;
141
- readonly schema: import("./OpenApiTypeDescriptors").SchemaObject;
142
- readonly description: import("effect/Option").Option<string>;
143
- readonly name: string;
144
- }[]>;
145
- readonly requestBody: import("effect/Option").Option<{
146
- readonly content: {
147
- [x: string]: {
148
- readonly schema: import("effect/Option").Option<import("./OpenApiTypeDescriptors").SchemaObject>;
149
- };
150
- };
151
- }>;
152
- readonly responses: import("effect/Option").Option<{
153
- [x: string]: {
154
- readonly content: import("effect/Option").Option<{
155
- [x: string]: {
156
- readonly schema: import("effect/Option").Option<import("./OpenApiTypeDescriptors").SchemaObject>;
157
- };
158
- }>;
159
- readonly description: string;
160
- };
161
- }>;
162
- } | undefined;
163
- };
164
- };
165
- readonly components: {
166
- readonly schemas: import("effect/Option").Option<{
167
- [x: string]: import("./OpenApiTypeDescriptors").SchemaObject;
168
- }>;
169
- };
170
- }>;
171
- export declare const pathCodec: import("@trayio/commons/dist/codec/Codec").Codec<{
172
- readonly description: import("effect/Option").Option<string>;
173
- readonly summary: import("effect/Option").Option<string>;
174
- readonly tags: import("effect/Option").Option<string[]>;
175
- readonly operationId: string;
176
- readonly parameters: import("effect/Option").Option<{
177
- readonly required: import("effect/Option").Option<boolean>;
178
- readonly in: string;
179
- readonly schema: import("./OpenApiTypeDescriptors").SchemaObject;
180
- readonly description: import("effect/Option").Option<string>;
181
- readonly name: string;
182
- }[]>;
183
- readonly requestBody: import("effect/Option").Option<{
184
- readonly content: {
185
- [x: string]: {
186
- readonly schema: import("effect/Option").Option<import("./OpenApiTypeDescriptors").SchemaObject>;
187
- };
188
- };
189
- }>;
190
- readonly responses: import("effect/Option").Option<{
191
- [x: string]: {
192
- readonly content: import("effect/Option").Option<{
193
- [x: string]: {
194
- readonly schema: import("effect/Option").Option<import("./OpenApiTypeDescriptors").SchemaObject>;
195
- };
196
- }>;
197
- readonly description: string;
198
- };
199
- }>;
200
- }>;
201
- export declare const parameterSchemaCodec: import("@trayio/commons/dist/codec/Codec").Codec<{
202
- readonly required: import("effect/Option").Option<boolean>;
203
- readonly in: string;
204
- readonly schema: import("./OpenApiTypeDescriptors").SchemaObject;
205
- readonly description: import("effect/Option").Option<string>;
206
- readonly name: string;
207
- }>;
1
+ import { OpenAPISchema, Parameter, Path } from './OpenApiTypeDescriptors';
2
+ export declare const openApiSpecCodec: import("@trayio/commons/dist/codec/Codec").Codec<OpenAPISchema>;
3
+ export declare const pathCodec: import("@trayio/commons/dist/codec/Codec").Codec<Path>;
4
+ export declare const parameterSchemaCodec: import("@trayio/commons/dist/codec/Codec").Codec<Parameter>;
208
5
  //# sourceMappingURL=OpenApiCodecs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"OpenApiCodecs.d.ts","sourceRoot":"","sources":["../src/OpenApiCodecs.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAA0C,CAAC;AAExE,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAA8C,CAAC;AAErE,eAAO,MAAM,oBAAoB;;;;;;EAA8C,CAAC"}
1
+ {"version":3,"file":"OpenApiCodecs.d.ts","sourceRoot":"","sources":["../src/OpenApiCodecs.ts"],"names":[],"mappings":"AACA,OAAO,EACN,aAAa,EACb,SAAS,EACT,IAAI,EAIJ,MAAM,0BAA0B,CAAC;AAElC,eAAO,MAAM,gBAAgB,iEAE5B,CAAC;AAEF,eAAO,MAAM,SAAS,wDAErB,CAAC;AAEF,eAAO,MAAM,oBAAoB,6DAEhC,CAAC"}
@@ -3,6 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parameterSchemaCodec = exports.pathCodec = exports.openApiSpecCodec = void 0;
4
4
  const TypeCodec_1 = require("@trayio/commons/codec/TypeCodec");
5
5
  const OpenApiTypeDescriptors_1 = require("./OpenApiTypeDescriptors");
6
- exports.openApiSpecCodec = TypeCodec_1.TypeCodec.fromSchema(OpenApiTypeDescriptors_1.openApiSpecSchema);
7
- exports.pathCodec = TypeCodec_1.TypeCodec.fromSchema(OpenApiTypeDescriptors_1.openApiSpecPathSchema);
8
- exports.parameterSchemaCodec = TypeCodec_1.TypeCodec.fromSchema(OpenApiTypeDescriptors_1.parameterSchemaSchema);
6
+ exports.openApiSpecCodec = TypeCodec_1.TypeCodec.fromDescriptor(OpenApiTypeDescriptors_1.openApiSpecTypeDescriptor);
7
+ exports.pathCodec = TypeCodec_1.TypeCodec.fromDescriptor(OpenApiTypeDescriptors_1.openApiSpecPathTypeDescriptor);
8
+ exports.parameterSchemaCodec = TypeCodec_1.TypeCodec.fromDescriptor(OpenApiTypeDescriptors_1.parameterSchemaTypeDescriptor);
@@ -1,4 +1,4 @@
1
- import { Effect } from 'effect';
1
+ import * as TE from 'fp-ts/TaskEither';
2
2
  import { FileStorage } from '@trayio/commons/file/File';
3
3
  import { Generator } from '@trayio/generator/generator/Generator';
4
4
  import { BuildConnectorResponse } from './OpenApiTypeDescriptors';
@@ -6,7 +6,7 @@ export declare class OpenApiSchemaImporter {
6
6
  private generator;
7
7
  private fileStorage;
8
8
  constructor(generator: Generator, fileStorage: FileStorage);
9
- buildConnector(openApiSpecPath: string, connectorName: string): Effect.Effect<BuildConnectorResponse, Error>;
9
+ buildConnector(openApiSpecPath: string, connectorName: string): TE.TaskEither<Error, BuildConnectorResponse>;
10
10
  private generateOperationFromPath;
11
11
  private decodeOperation;
12
12
  private getOpenApiSpec;
@@ -1 +1 @@
1
- {"version":3,"file":"OpenApiSchemaImporter.d.ts","sourceRoot":"","sources":["../src/OpenApiSchemaImporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAwB,MAAM,QAAQ,CAAC;AAItD,OAAO,EAAQ,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,uCAAuC,CAAC;AAGlE,OAAO,EAEN,sBAAsB,EAMtB,MAAM,0BAA0B,CAAC;AAalC,qBAAa,qBAAqB;IACrB,OAAO,CAAC,SAAS;IAAa,OAAO,CAAC,WAAW;gBAAzC,SAAS,EAAE,SAAS,EAAU,WAAW,EAAE,WAAW;IAE1E,cAAc,CACb,eAAe,EAAE,MAAM,EACvB,aAAa,EAAE,MAAM,GACnB,MAAM,CAAC,MAAM,CAAC,sBAAsB,EAAE,KAAK,CAAC;IAsD/C,OAAO,CAAC,yBAAyB;IAuDjC,OAAO,CAAC,eAAe;IAgBvB,OAAO,CAAC,cAAc;IAkCtB,OAAO,CAAC,oCAAoC;IA+F5C,OAAO,CAAC,0BAA0B;IAwBlC,OAAO,CAAC,0BAA0B;CAclC"}
1
+ {"version":3,"file":"OpenApiSchemaImporter.d.ts","sourceRoot":"","sources":["../src/OpenApiSchemaImporter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AASvC,OAAO,EAAQ,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,uCAAuC,CAAC;AAGlE,OAAO,EAEN,sBAAsB,EAMtB,MAAM,0BAA0B,CAAC;AAalC,qBAAa,qBAAqB;IACrB,OAAO,CAAC,SAAS;IAAa,OAAO,CAAC,WAAW;gBAAzC,SAAS,EAAE,SAAS,EAAU,WAAW,EAAE,WAAW;IAE1E,cAAc,CACb,eAAe,EAAE,MAAM,EACvB,aAAa,EAAE,MAAM,GACnB,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,sBAAsB,CAAC;IAoD/C,OAAO,CAAC,yBAAyB;IAyDjC,OAAO,CAAC,eAAe;IAgBvB,OAAO,CAAC,cAAc;IAoCtB,OAAO,CAAC,oCAAoC;IA2F5C,OAAO,CAAC,0BAA0B;IAwBlC,OAAO,CAAC,0BAA0B;CAclC"}
@@ -1,7 +1,35 @@
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.OpenApiSchemaImporter = void 0;
4
- const effect_1 = require("effect");
27
+ const TE = __importStar(require("fp-ts/TaskEither"));
28
+ const E = __importStar(require("fp-ts/Either"));
29
+ const O = __importStar(require("fp-ts/Option"));
30
+ const function_1 = require("fp-ts/function");
31
+ const Array_1 = require("fp-ts/Array");
32
+ const Apply_1 = require("fp-ts/Apply");
5
33
  const json_ref_resolver_1 = require("@stoplight/json-ref-resolver");
6
34
  const StringExtensions_1 = require("@trayio/commons/string/StringExtensions");
7
35
  const lodash_1 = require("lodash");
@@ -23,18 +51,18 @@ class OpenApiSchemaImporter {
23
51
  this.fileStorage = fileStorage;
24
52
  }
25
53
  buildConnector(openApiSpecPath, connectorName) {
26
- return (0, effect_1.pipe)(this.generateConnectorDirectory(connectorName), effect_1.Effect.bindTo('connectorPath'), effect_1.Effect.bind('openApiSpec', () => this.getOpenApiSpec(openApiSpecPath)), effect_1.Effect.bind('paths', ({ openApiSpec }) => {
54
+ return (0, function_1.pipe)(this.generateConnectorDirectory(connectorName), TE.bindTo('connectorPath'), TE.bind('openApiSpec', () => this.getOpenApiSpec(openApiSpecPath)), TE.bind('paths', ({ openApiSpec }) => {
27
55
  if (openApiSpec.paths === undefined) {
28
- return effect_1.Effect.fail(new Error('OpenAPI spec does not contain any paths'));
56
+ return TE.left(new Error('OpenAPI spec does not contain any paths'));
29
57
  }
30
- return effect_1.Effect.succeed(Object.keys(openApiSpec.paths).map((path) => ({
58
+ return TE.right(Object.keys(openApiSpec.paths).map((path) => ({
31
59
  path,
32
60
  routes: Object.keys(openApiSpec.paths[path]).map((route) => ({
33
61
  method: route,
34
62
  path: openApiSpec.paths[path][route],
35
63
  })),
36
64
  })));
37
- }), effect_1.Effect.flatMap(({ openApiSpec, connectorPath, paths }) => effect_1.Effect.forEach((path) => this.generateOperationFromPath(path, connectorPath, openApiSpec.servers[0].url, connectorName))(paths)), effect_1.Effect.map((operation) => {
65
+ }), TE.chain(({ openApiSpec, connectorPath, paths }) => (0, Array_1.traverse)(TE.ApplicativeSeq)((path) => this.generateOperationFromPath(path, connectorPath, openApiSpec.servers[0].url, connectorName))(paths)), TE.map((operation) => {
38
66
  const flatOperations = operation.flat();
39
67
  const buildConnectorResponse = flatOperations.reduce((acc, curr) => {
40
68
  if (curr.tag === 'error') {
@@ -52,11 +80,11 @@ class OpenApiSchemaImporter {
52
80
  }));
53
81
  }
54
82
  generateOperationFromPath(path, connectorPath, baseUrl, connectorName) {
55
- return (0, effect_1.pipe)(effect_1.Effect.forEach((route) => (0, effect_1.pipe)(this.decodeOperation(route.path, path.path, route.method), effect_1.Effect.bindTo('decodedPath'), effect_1.Effect.flatMap(({ decodedPath }) => (0, effect_1.pipe)(this.generateOperationDirectory(connectorPath, decodedPath.operationId), effect_1.Effect.map((operationDirectory) => ({ operationDirectory })), effect_1.Effect.bind('inputs', () => (0, GenerateInputSchema_1.generateInputSchema)(decodedPath)), effect_1.Effect.bind('outputs', () => (0, GenerateOutput_1.generateOutputSchema)(decodedPath.responses)), effect_1.Effect.bind('decodedPath', () => effect_1.Effect.succeed(decodedPath)))), effect_1.Effect.flatMap(({ inputs, outputs, decodedPath }) => this.generateHandlerFilesAndOperationJson(route.method, decodedPath, `${connectorPath}/src/${(0, lodash_1.snakeCase)(decodedPath.operationId)}`, baseUrl, path.path, connectorName, inputs, outputs)), effect_1.Effect.map(() => ({
83
+ return (0, function_1.pipe)((0, Array_1.traverse)(TE.ApplicativeSeq)((route) => (0, function_1.pipe)(this.decodeOperation(route.path, path.path, route.method), TE.bindTo('decodedPath'), TE.chain(({ decodedPath }) => (0, function_1.pipe)(this.generateOperationDirectory(connectorPath, decodedPath.operationId), TE.bind('inputs', () => TE.fromEither((0, GenerateInputSchema_1.generateInputSchema)(decodedPath))), TE.bind('outputs', () => (0, GenerateOutput_1.generateOutputSchema)(decodedPath.responses)), TE.bind('decodedPath', () => TE.right(decodedPath)))), TE.chain(({ inputs, outputs, decodedPath }) => this.generateHandlerFilesAndOperationJson(route.method, decodedPath, `${connectorPath}/src/${(0, lodash_1.snakeCase)(decodedPath.operationId)}`, baseUrl, path.path, connectorName, inputs, outputs)), TE.map(() => ({
56
84
  tag: 'success',
57
85
  httpMethod: route.method,
58
86
  path: path.path,
59
- })), effect_1.Effect.catchAll((error) => effect_1.Effect.succeed({
87
+ })), TE.orElseW((error) => TE.right({
60
88
  tag: 'error',
61
89
  httpMethod: route.method,
62
90
  path: path.path,
@@ -64,20 +92,14 @@ class OpenApiSchemaImporter {
64
92
  }))))(path.routes));
65
93
  }
66
94
  decodeOperation(path, httpPath, method) {
67
- return (0, effect_1.pipe)(OpenApiCodecs_1.pathCodec.decode(path), effect_1.Effect.mapError((error) => new Error(`Failed to decode httpPath: ${httpPath} and method: ${method} : ${error}`)));
95
+ return (0, function_1.pipe)(TE.fromEither(OpenApiCodecs_1.pathCodec.decode(path)), TE.mapLeft((error) => new Error(`Failed to decode httpPath: ${httpPath} and method: ${method} : ${error}`)));
68
96
  }
69
97
  getOpenApiSpec(openApiSpecPath) {
70
- return (0, effect_1.pipe)(this.fileStorage.read(openApiSpecPath), effect_1.Effect.flatMap((openApiSpec) => BufferExtensions_1.BufferExtensions.readableToArrayBuffer(openApiSpec.content)), effect_1.Effect.flatMap((openApiSpec) => effect_1.Either.try({
71
- try: () => JSON.parse(Buffer.from(openApiSpec).toString('utf-8')),
72
- catch: (error) => new Error(`Failed to parse OpenAPI spec as JSON from path ${openApiSpecPath}: ${error}`),
73
- })), effect_1.Effect.flatMap((openApiSpec) => effect_1.Effect.tryPromise({
74
- try: () => {
75
- const resolver = new json_ref_resolver_1.Resolver({});
76
- const resolvedOpenApiSpec = resolver.resolve(openApiSpec, {});
77
- return resolvedOpenApiSpec;
78
- },
79
- catch: (reason) => new Error(`Failed to resolve references in schema: ${reason}`),
80
- })), effect_1.Effect.flatMap((openApiSpec) => (0, OpenApiSchemaTransformer_1.mergePathLevelParamsIntoHttpMethod)(openApiSpec.result)));
98
+ return (0, function_1.pipe)(this.fileStorage.read(openApiSpecPath), TE.chain((openApiSpec) => BufferExtensions_1.BufferExtensions.readableToArrayBuffer(openApiSpec.content)), TE.chain((openApiSpec) => TE.fromEither(E.tryCatch(() => JSON.parse(Buffer.from(openApiSpec).toString('utf-8')), (error) => new Error(`Failed to parse OpenAPI spec as JSON from path ${openApiSpecPath}: ${error}`)))), TE.chain((openApiSpec) => TE.tryCatch(() => {
99
+ const resolver = new json_ref_resolver_1.Resolver({});
100
+ const resolvedOpenApiSpec = resolver.resolve(openApiSpec, {});
101
+ return resolvedOpenApiSpec;
102
+ }, (reason) => new Error(`Failed to resolve references in schema: ${reason}`))), TE.chain((openApiSpec) => TE.fromEither((0, OpenApiSchemaTransformer_1.mergePathLevelParamsIntoHttpMethod)(openApiSpec.result))));
81
103
  }
82
104
  generateHandlerFilesAndOperationJson(method, path, operationPath, baseUrl, httpPath, connectorName, input, output) {
83
105
  const writeFile = (content, fileName) => this.fileStorage.write({
@@ -87,11 +109,11 @@ class OpenApiSchemaImporter {
87
109
  key: `${operationPath}/${fileName}`,
88
110
  metadata: { name: fileName },
89
111
  },
90
- }, effect_1.Option.none());
112
+ }, O.none);
91
113
  const operationName = path.operationId;
92
- const handleFileCreationError = (error, fileName) => (0, effect_1.pipe)(writeFile('', fileName), effect_1.Effect.mapError(() => error));
114
+ const handleFileCreationError = (error, fileName) => (0, function_1.pipe)(writeFile('', fileName), TE.mapLeft(() => error));
93
115
  const operationFileGenerationTasks = {
94
- handler: (0, effect_1.pipe)((0, GenerateHandler_1.generateHandler)({
116
+ handler: (0, function_1.pipe)(TE.fromEither((0, GenerateHandler_1.generateHandler)({
95
117
  connectorNamePascalCase: StringExtensions_1.StringExtensions.pascalCase(connectorName),
96
118
  operationNameCamelCase: (0, lodash_1.camelCase)(operationName),
97
119
  operationNamePascalCase: StringExtensions_1.StringExtensions.pascalCase(operationName),
@@ -99,30 +121,30 @@ class OpenApiSchemaImporter {
99
121
  baseUrl,
100
122
  httpPath,
101
123
  input,
102
- }),
124
+ })),
103
125
  // TODO: Why does this throw unhelpful errors?
104
- effect_1.Effect.flatMap((handlerInput) => writeFile(handlerInput, 'handler.ts')), effect_1.Effect.catchAll((error) => handleFileCreationError(error, 'handler.ts'))),
105
- handlerTest: (0, effect_1.pipe)((0, GenerateHandlerTest_1.generateHandlerTest)({
126
+ TE.chain((handlerInput) => writeFile(handlerInput, 'handler.ts')), TE.mapLeft((error) => handleFileCreationError(error, 'handler.ts'))),
127
+ handlerTest: (0, function_1.pipe)(TE.fromEither((0, GenerateHandlerTest_1.generateHandlerTest)({
106
128
  operationNameCamelCase: (0, lodash_1.camelCase)(operationName),
107
129
  input,
108
130
  output,
109
- }), effect_1.Effect.flatMap((handlerInput) => writeFile(handlerInput, 'handler.test.ts')), effect_1.Effect.catchAll((error) => handleFileCreationError(error, 'handler.test.ts'))),
110
- generateOutputType: (0, effect_1.pipe)((0, GenerateOutput_1.generateOutputTypes)(operationName, output), effect_1.Effect.flatMap((outputType) => writeFile(outputType, 'output.ts')), effect_1.Effect.catchAll((error) => handleFileCreationError(error, 'output.ts'))),
111
- generateInputType: (0, effect_1.pipe)((0, GenerateInputTypes_1.generateInputTypes)(operationName, input), effect_1.Effect.flatMap((inputType) => writeFile(inputType, 'input.ts')), effect_1.Effect.catchAll((error) => handleFileCreationError(error, 'input.ts'))),
112
- operationJson: (0, effect_1.pipe)((0, GenerateOperationJson_1.generateOperationJson)(operationName, path), effect_1.Effect.flatMap((operationJson) => writeFile(operationJson, 'operation.json')), effect_1.Effect.catchAll((error) => handleFileCreationError(error, 'operation.json'))),
131
+ })), TE.chain((handlerInput) => writeFile(handlerInput, 'handler.test.ts')), TE.mapLeft((error) => handleFileCreationError(error, 'handler.test.ts'))),
132
+ generateOutputType: (0, function_1.pipe)((0, GenerateOutput_1.generateOutputTypes)(operationName, output), TE.chain((outputType) => writeFile(outputType, 'output.ts')), TE.mapLeft((error) => handleFileCreationError(error, 'output.ts'))),
133
+ generateInputType: (0, function_1.pipe)((0, GenerateInputTypes_1.generateInputTypes)(operationName, input), TE.chain((inputType) => writeFile(inputType, 'input.ts')), TE.mapLeft((error) => handleFileCreationError(error, 'input.ts'))),
134
+ operationJson: (0, function_1.pipe)((0, GenerateOperationJson_1.generateOperationJson)(operationName, path), TE.chain((operationJson) => writeFile(operationJson, 'operation.json')), TE.mapLeft((error) => handleFileCreationError(error, 'operation.json'))),
113
135
  };
114
- return (0, effect_1.pipe)(effect_1.Effect.all(operationFileGenerationTasks, { concurrency: 'unbounded' }), effect_1.Effect.mapError((error) => new Error(`Failed to generate files for operation: ${operationName}: ${error}`)), effect_1.Effect.map(() => undefined));
136
+ return (0, function_1.pipe)((0, Apply_1.sequenceS)(TE.ApplicativePar)(operationFileGenerationTasks), TE.mapLeft((error) => new Error(`Failed to generate files for operation: ${operationName}: ${error}`)), TE.map(() => undefined));
115
137
  }
116
138
  generateConnectorDirectory(connectorName) {
117
- return (0, effect_1.pipe)(effect_1.Effect.succeed({
139
+ return (0, function_1.pipe)(TE.right({
118
140
  connectorNameTitleCase: StringExtensions_1.StringExtensions.titleCase(connectorName),
119
141
  connectorNameKebabCase: (0, lodash_1.kebabCase)(connectorName),
120
142
  connectorNamePascalCase: StringExtensions_1.StringExtensions.pascalCase(connectorName),
121
143
  connectorNameCamelCase: (0, lodash_1.camelCase)(connectorName),
122
- }), effect_1.Effect.flatMap((parameters) => this.generator.generate(`${__dirname}/templates/connector-template.zip`, process.cwd(), parameters)), effect_1.Effect.map(() => `/${(0, lodash_1.kebabCase)(connectorName)}`), effect_1.Effect.mapError((error) => new Error(`Failed to generate connector directory: ${error}`)));
144
+ }), TE.chain((parameters) => this.generator.generate(`${__dirname}/templates/connector-template.zip`, process.cwd(), parameters)), TE.map(() => `/${(0, lodash_1.kebabCase)(connectorName)}`), TE.mapLeft((error) => new Error(`Failed to generate connector directory: ${error}`)));
123
145
  }
124
146
  generateOperationDirectory(connectorPath, operationName) {
125
- return (0, effect_1.pipe)(effect_1.Effect.mapError(this.fileStorage.createDirectory(`${connectorPath}/src/${(0, lodash_1.snakeCase)(operationName)}`), (error) => new Error(`Failed to create operation directory: ${error}`)), effect_1.Effect.map(() => `${connectorPath}/src/${(0, lodash_1.snakeCase)(operationName)}`));
147
+ return (0, function_1.pipe)(TE.tryCatch(this.fileStorage.createDirectory(`${connectorPath}/src/${(0, lodash_1.snakeCase)(operationName)}`), (error) => new Error(`Failed to create operation directory: ${error}`)), TE.map(() => `${connectorPath}/src/${(0, lodash_1.snakeCase)(operationName)}`));
126
148
  }
127
149
  }
128
150
  exports.OpenApiSchemaImporter = OpenApiSchemaImporter;
@@ -15,28 +15,18 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
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
+ };
35
25
  Object.defineProperty(exports, "__esModule", { value: true });
36
- const effect_1 = require("effect");
37
26
  const NodeFsGenerator_1 = require("@trayio/generator/generator/NodeFsGenerator");
38
27
  const FakeFileStorage_1 = require("@trayio/commons/file/FakeFileStorage");
39
28
  const stream_1 = require("stream");
29
+ const E = __importStar(require("fp-ts/Either"));
40
30
  const fs = __importStar(require("fs-extra"));
41
31
  const OpenApiSchemaImporter_1 = require("./OpenApiSchemaImporter");
42
32
  const openApiSpec = __importStar(require("./test-openapi-spec.json"));
@@ -47,16 +37,15 @@ describe('openApiSchemaImporter', () => {
47
37
  let result;
48
38
  const spec = 'test-openapi-spec.json';
49
39
  beforeAll(async () => {
50
- // Effects are lazy: the write only happens when it is run (the fp-ts version wrote eagerly on construction).
51
- await effect_1.Effect.runPromise(fileStorage.write({
40
+ fileStorage.write({
52
41
  reference: {
53
42
  _tag: 'FileDescriptor',
54
43
  key: `${__dirname}/${spec}`,
55
44
  metadata: { name: spec },
56
45
  },
57
46
  content: stream_1.Readable.from(Buffer.from(JSON.stringify(openApiSpec))),
58
- }));
59
- result = await effect_1.Effect.runPromise(effect_1.Effect.either(openApiSchemaImporter.buildConnector(`${__dirname}/${spec}`, 'testConnector')));
47
+ });
48
+ result = await openApiSchemaImporter.buildConnector(`${__dirname}/${spec}`, 'testConnector')();
60
49
  });
61
50
  afterAll(async () => {
62
51
  await fs.rm(`${process.cwd()}/test-connector/`, {
@@ -65,10 +54,10 @@ describe('openApiSchemaImporter', () => {
65
54
  });
66
55
  });
67
56
  it('should import successfully', () => {
68
- const buildConnectorResponse = effect_1.Either.getOrElse(result, (error) => {
57
+ const buildConnectorResponse = E.getOrElse((error) => {
69
58
  console.error(error);
70
59
  throw new Error('Should have been right');
71
- });
60
+ })(result);
72
61
  console.log(buildConnectorResponse);
73
62
  console.log(fileStorage.files);
74
63
  expect(buildConnectorResponse.successes.length).toEqual(1);
@@ -1,9 +1,9 @@
1
- import { Either } from 'effect';
1
+ import * as E from 'fp-ts/Either';
2
2
  import { BaseOpenApiSpec } from './OpenApiTypeDescriptors';
3
3
  export declare const isObject: (value: unknown) => value is Record<string, unknown>;
4
4
  export declare const isObjectWithParameters: (value: unknown) => value is Record<string, unknown> & {
5
5
  parameters: unknown[];
6
6
  };
7
7
  export declare const getMergedParameters: (pathValue: Record<string, unknown>, httpMethodValue: Record<string, unknown>) => unknown[];
8
- export declare const mergePathLevelParamsIntoHttpMethod: (openApiSpec: BaseOpenApiSpec) => Either.Either<BaseOpenApiSpec, Error>;
8
+ export declare const mergePathLevelParamsIntoHttpMethod: (openApiSpec: BaseOpenApiSpec) => E.Either<Error, BaseOpenApiSpec>;
9
9
  //# sourceMappingURL=OpenApiSchemaTransformer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"OpenApiSchemaTransformer.d.ts","sourceRoot":"","sources":["../src/OpenApiSchemaTransformer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE3D,eAAO,MAAM,QAAQ,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAC7B,CAAC;AAE7C,eAAO,MAAM,sBAAsB,GAClC,OAAO,OAAO,KACZ,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IAAE,UAAU,EAAE,OAAO,EAAE,CAAA;CACpB,CAAC;AAE1C,eAAO,MAAM,mBAAmB,GAC/B,WAAW,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,iBAAiB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KACtC,OAAO,EAcT,CAAC;AAEF,eAAO,MAAM,kCAAkC,GAC9C,aAAa,eAAe,KAC1B,MAAM,CAAC,MAAM,CAAC,eAAe,EAAE,KAAK,CAkCtC,CAAC"}
1
+ {"version":3,"file":"OpenApiSchemaTransformer.d.ts","sourceRoot":"","sources":["../src/OpenApiSchemaTransformer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE3D,eAAO,MAAM,QAAQ,UAAW,OAAO,qCACK,CAAC;AAE7C,eAAO,MAAM,sBAAsB,UAC3B,OAAO;gBACqC,OAAO,EAAE;CACpB,CAAC;AAE1C,eAAO,MAAM,mBAAmB,cACpB,OAAO,MAAM,EAAE,OAAO,CAAC,mBACjB,OAAO,MAAM,EAAE,OAAO,CAAC,KACtC,OAAO,EAcT,CAAC;AAEF,eAAO,MAAM,kCAAkC,gBACjC,eAAe,KAC1B,EAAE,MAAM,CAAC,KAAK,EAAE,eAAe,CAkCjC,CAAC"}
@@ -1,7 +1,30 @@
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.mergePathLevelParamsIntoHttpMethod = exports.getMergedParameters = exports.isObjectWithParameters = exports.isObject = void 0;
4
- const effect_1 = require("effect");
27
+ const E = __importStar(require("fp-ts/Either"));
5
28
  const isObject = (value) => typeof value === 'object' && value !== null;
6
29
  exports.isObject = isObject;
7
30
  const isObjectWithParameters = (value) => (0, exports.isObject)(value) && 'parameters' in value;
@@ -40,6 +63,6 @@ const mergePathLevelParamsIntoHttpMethod = (openApiSpec) => {
40
63
  pathAcc[pathName] = updatedPathValue;
41
64
  return pathAcc;
42
65
  }, {});
43
- return effect_1.Either.right({ ...openApiSpec, paths });
66
+ return E.right({ ...openApiSpec, paths });
44
67
  };
45
68
  exports.mergePathLevelParamsIntoHttpMethod = mergePathLevelParamsIntoHttpMethod;