@trayio/cdk-runtime 3.8.0-beta → 3.9.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.
@@ -1,38 +1,29 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.CompositeOperationExecution = void 0;
13
4
  const OperationHandler_1 = require("@trayio/cdk-dsl/connector/operation/OperationHandler");
14
5
  class CompositeOperationExecution {
6
+ handlerInvocationFactory;
7
+ handler;
15
8
  constructor(handlerInvocationFactory, handler) {
16
9
  this.handlerInvocationFactory = handlerInvocationFactory;
17
10
  this.handler = handler;
18
11
  }
19
- execute(ctx, input) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- const handlerInvocation = this.handlerInvocationFactory(ctx);
22
- try {
23
- const result = yield this.handler.handlerFunction(ctx, input, handlerInvocation);
24
- return result;
12
+ async execute(ctx, input) {
13
+ const handlerInvocation = this.handlerInvocationFactory(ctx);
14
+ try {
15
+ const result = await this.handler.handlerFunction(ctx, input, handlerInvocation);
16
+ return result;
17
+ }
18
+ catch (error) {
19
+ if (this.isError(error)) {
20
+ return OperationHandler_1.OperationHandlerResult.failure(OperationHandler_1.OperationHandlerError.connectorError(error.message));
25
21
  }
26
- catch (error) {
27
- if (this.isError(error)) {
28
- return OperationHandler_1.OperationHandlerResult.failure(OperationHandler_1.OperationHandlerError.connectorError(error.message));
29
- }
30
- if (typeof error === 'string') {
31
- return OperationHandler_1.OperationHandlerResult.failure(OperationHandler_1.OperationHandlerError.connectorError(error));
32
- }
33
- return OperationHandler_1.OperationHandlerResult.failure(OperationHandler_1.OperationHandlerError.connectorError('Operation failed with unknown error'));
22
+ if (typeof error === 'string') {
23
+ return OperationHandler_1.OperationHandlerResult.failure(OperationHandler_1.OperationHandlerError.connectorError(error));
34
24
  }
35
- });
25
+ return OperationHandler_1.OperationHandlerResult.failure(OperationHandler_1.OperationHandlerError.connectorError('Operation failed with unknown error'));
26
+ }
36
27
  }
37
28
  // TODO: Move to commons
38
29
  isError(error) {
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CompositeOperationExecutionFactory = void 0;
4
4
  const CompositeOperationExecution_1 = require("./CompositeOperationExecution");
5
5
  class CompositeOperationExecutionFactory {
6
+ handlerInvocationFactory;
6
7
  constructor(handlerInvocationFactory) {
7
8
  this.handlerInvocationFactory = handlerInvocationFactory;
8
9
  }
@@ -22,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
25
  Object.defineProperty(exports, "__esModule", { value: true });
35
26
  exports.HttpOperationExecution = void 0;
36
27
  const TE = __importStar(require("fp-ts/TaskEither"));
@@ -48,6 +39,11 @@ const BufferExtensions_1 = require("@trayio/commons/buffer/BufferExtensions");
48
39
  const mime = require('mime');
49
40
  const { AWS_LAMBDA_FUNCTION_MEMORY_SIZE, CONNECTOR_MAX_ALLOCATED_RAM_MB } = process.env;
50
41
  class HttpOperationExecution {
42
+ jsonSerialization;
43
+ httpClient;
44
+ handler;
45
+ fileStorage;
46
+ globalConfiguration;
51
47
  constructor(httpClient, fileStorage, handler, globalConfiguration) {
52
48
  this.jsonSerialization = new JsonSerialization_1.JsonSerialization();
53
49
  this.httpClient = httpClient;
@@ -55,24 +51,22 @@ class HttpOperationExecution {
55
51
  this.handler = handler;
56
52
  this.globalConfiguration = globalConfiguration;
57
53
  }
58
- execute(ctx, input) {
59
- return __awaiter(this, void 0, void 0, function* () {
60
- const request = (0, function_1.pipe)(this.globalConfiguration, O.match(() => this.handler.request, (globalConfig) => this.decorateRequest(globalConfig, this.handler.request, ctx)));
61
- const operationRequest = this.handler.requestHandler(ctx, input, request);
62
- const httpRequestE = yield this.operationRequestToHttpRequest(operationRequest)();
63
- if (E.isLeft(httpRequestE)) {
64
- return OperationHandler_1.OperationHandlerResult.failure(OperationHandler_1.OperationHandlerError.connectorError(httpRequestE.left.message));
65
- }
66
- const resultTE = this.httpClient.execute(operationRequest.method, operationRequest.path, httpRequestE.right);
67
- const operationResponseTE = (0, function_1.pipe)(resultTE,
68
- // get the dsl http response object
69
- TE.map((response) => this.handler.responseHandler(ctx, input, new HttpOperationHandler_1.HttpOperationResponseBuilder(response, this.defaultErrorHandling(response.statusCode)))),
70
- // interpret the dsl response object by mapping the low level http response to a connector response
71
- TE.chain((operationResponse) => this.parseResponse(operationResponse)),
72
- // handle errors during the execution of the http request or parsing or the http response
73
- TE.mapLeft((error) => OperationHandler_1.OperationHandlerResult.failure(OperationHandler_1.OperationHandlerError.connectorError(error.message))));
74
- return TE.toUnion(operationResponseTE)();
75
- });
54
+ async execute(ctx, input) {
55
+ const request = (0, function_1.pipe)(this.globalConfiguration, O.match(() => this.handler.request, (globalConfig) => this.decorateRequest(globalConfig, this.handler.request, ctx)));
56
+ const operationRequest = this.handler.requestHandler(ctx, input, request);
57
+ const httpRequestE = await this.operationRequestToHttpRequest(operationRequest)();
58
+ if (E.isLeft(httpRequestE)) {
59
+ return OperationHandler_1.OperationHandlerResult.failure(OperationHandler_1.OperationHandlerError.connectorError(httpRequestE.left.message));
60
+ }
61
+ const resultTE = this.httpClient.execute(operationRequest.method, operationRequest.path, httpRequestE.right);
62
+ const operationResponseTE = (0, function_1.pipe)(resultTE,
63
+ // get the dsl http response object
64
+ TE.map((response) => this.handler.responseHandler(ctx, input, new HttpOperationHandler_1.HttpOperationResponseBuilder(response, this.defaultErrorHandling(response.statusCode)))),
65
+ // interpret the dsl response object by mapping the low level http response to a connector response
66
+ TE.chain((operationResponse) => this.parseResponse(operationResponse)),
67
+ // handle errors during the execution of the http request or parsing or the http response
68
+ TE.mapLeft((error) => OperationHandler_1.OperationHandlerResult.failure(OperationHandler_1.OperationHandlerError.connectorError(error.message))));
69
+ return TE.toUnion(operationResponseTE)();
76
70
  }
77
71
  decorateRequest(globalConfig, operationRequest, ctx) {
78
72
  return (0, function_1.pipe)(globalConfig.baseUrl, O.fold(() => operationRequest, (baseUrl) => operationRequest.withUrl(`${baseUrl(ctx)}${operationRequest.path}`)), (request) => (0, function_1.pipe)(globalConfig.bearerToken, O.fold(() => request, (bearerToken) => request.withBearerToken(bearerToken(ctx)))), (request) => (0, function_1.pipe)(globalConfig.headers, (headers) => {
@@ -101,7 +95,10 @@ class HttpOperationExecution {
101
95
  default:
102
96
  return this.serializeAsJson(operationRequest.body);
103
97
  }
104
- }), O.getOrElse(() => this.serializeEmptyBody()), TE.map((serializedBody) => (Object.assign(Object.assign({}, operationRequest.request), { body: serializedBody }))));
98
+ }), O.getOrElse(() => this.serializeEmptyBody()), TE.map((serializedBody) => ({
99
+ ...operationRequest.request,
100
+ body: serializedBody,
101
+ })));
105
102
  }
106
103
  serializeAsJson(body) {
107
104
  const serializedBody = this.jsonSerialization.serialize(body);
@@ -210,18 +207,15 @@ class HttpOperationExecution {
210
207
  key: fileExtension ? `${(0, uuid_1.v4)()}.${fileExtension}` : (0, uuid_1.v4)(),
211
208
  metadata: {
212
209
  name: (0, uuid_1.v4)(),
213
- size: parseFloat(contentLength !== null && contentLength !== void 0 ? contentLength : undefined),
210
+ size: parseFloat(contentLength ?? undefined),
214
211
  contentType,
215
212
  },
216
- }, O.some(uploadOptions)), TE.chain((file) => (0, function_1.pipe)(this.fileStorage.getSharedUrl(file.key), TE.map((sharedUrl) => {
217
- var _a, _b;
218
- return operationResponse.responseParser({
219
- name: file.metadata.name,
220
- url: sharedUrl.url,
221
- mime_type: (_a = file.metadata.contentType) !== null && _a !== void 0 ? _a : '',
222
- expires: (_b = sharedUrl.expires) !== null && _b !== void 0 ? _b : 0,
223
- });
224
- }))));
213
+ }, O.some(uploadOptions)), TE.chain((file) => (0, function_1.pipe)(this.fileStorage.getSharedUrl(file.key), TE.map((sharedUrl) => operationResponse.responseParser({
214
+ name: file.metadata.name,
215
+ url: sharedUrl.url,
216
+ mime_type: file.metadata.contentType ?? '',
217
+ expires: sharedUrl.expires ?? 0,
218
+ })))));
225
219
  }
226
220
  parseBodyAsText(operationResponse) {
227
221
  const arrayBufferTE = BufferExtensions_1.BufferExtensions.readableToArrayBuffer(operationResponse.response.body);
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HttpOperationExecutionFactory = void 0;
4
4
  const HttpOperationExecution_1 = require("./HttpOperationExecution");
5
5
  class HttpOperationExecutionFactory {
6
+ httpClient;
7
+ fileStorage;
6
8
  constructor(httpClient, fileStorage) {
7
9
  this.httpClient = httpClient;
8
10
  this.fileStorage = fileStorage;
@@ -5,6 +5,9 @@ const HttpOperationExecutionFactory_1 = require("./HttpOperationExecutionFactory
5
5
  const CompositeOperationExecutionFactory_1 = require("./CompositeOperationExecutionFactory");
6
6
  const OperationExecutionValidationFactory_1 = require("./OperationExecutionValidationFactory");
7
7
  class OperationExecutionFactory {
8
+ operationExecutionValidationFactory;
9
+ httpOperationExecutionFactory;
10
+ compositeOperationExecutionFactory;
8
11
  constructor(httpClient, fileStorage, operationHandlerInvocationFactory) {
9
12
  this.operationExecutionValidationFactory =
10
13
  new OperationExecutionValidationFactory_1.OperationExecutionValidationFactory();
@@ -30,6 +30,8 @@ const OperationHandler_1 = require("@trayio/cdk-dsl/connector/operation/Operatio
30
30
  const OperationHandlerSetup_1 = require("@trayio/cdk-dsl/connector/operation/OperationHandlerSetup");
31
31
  const OperationExecutionFactory_1 = require("./OperationExecutionFactory");
32
32
  class OperationExecutionGateway {
33
+ executionFactory;
34
+ operationHandlerInvocationFactory;
33
35
  constructor(httpClient, fileStorage) {
34
36
  const operationHandlerInvocationFactory = (ctx) => (handlerReference) => (input) => {
35
37
  const result = (0, function_1.pipe)(this.lookup(handlerReference, true), O.map((handlerExecution) => handlerExecution.execute(ctx, input)));
@@ -39,100 +39,98 @@ require("./OperationHandlerTestRunner");
39
39
  const OperationGlobalConfig_1 = require("@trayio/cdk-dsl/connector/operation/OperationGlobalConfig");
40
40
  const fileStorage = new NodeFsFileStorage_1.NodeFsFileStorage('/tmp');
41
41
  class TestControllerHttp {
42
- constructor() {
43
- this.getEndpoints = () => [
44
- {
45
- path: `/posts/:id`,
46
- method: Http_1.HttpMethod.Get,
47
- execute: (request) => {
48
- const { id } = request.pathParams;
42
+ getEndpoints = () => [
43
+ {
44
+ path: `/posts/:id`,
45
+ method: Http_1.HttpMethod.Get,
46
+ execute: (request) => {
47
+ const { id } = request.pathParams;
48
+ return T.of({
49
+ body: stream_1.Readable.from(JSON.stringify({
50
+ id: parseInt(id, 10),
51
+ title: 'test',
52
+ })),
53
+ headers: {},
54
+ statusCode: 200,
55
+ });
56
+ },
57
+ },
58
+ {
59
+ path: `/tokens`,
60
+ method: Http_1.HttpMethod.Get,
61
+ execute: (request) => {
62
+ const token = request.headers.authorization;
63
+ if (token === 'Bearer valid') {
49
64
  return T.of({
50
65
  body: stream_1.Readable.from(JSON.stringify({
51
- id: parseInt(id, 10),
52
- title: 'test',
66
+ success: true,
53
67
  })),
54
68
  headers: {},
55
69
  statusCode: 200,
56
70
  });
57
- },
71
+ }
72
+ throw new Error('Unauthorized');
58
73
  },
59
- {
60
- path: `/tokens`,
61
- method: Http_1.HttpMethod.Get,
62
- execute: (request) => {
63
- const token = request.headers.authorization;
64
- if (token === 'Bearer valid') {
65
- return T.of({
66
- body: stream_1.Readable.from(JSON.stringify({
67
- success: true,
68
- })),
69
- headers: {},
70
- statusCode: 200,
71
- });
72
- }
73
- throw new Error('Unauthorized');
74
- },
75
- },
76
- {
77
- path: `/posts/create`,
78
- method: Http_1.HttpMethod.Post,
79
- execute: (request) => {
80
- const { body } = request;
81
- return T.of({
82
- body: body,
83
- headers: {},
84
- statusCode: 200,
85
- });
86
- },
74
+ },
75
+ {
76
+ path: `/posts/create`,
77
+ method: Http_1.HttpMethod.Post,
78
+ execute: (request) => {
79
+ const { body } = request;
80
+ return T.of({
81
+ body: body,
82
+ headers: {},
83
+ statusCode: 200,
84
+ });
87
85
  },
88
- {
89
- path: `/image-upload`,
90
- method: Http_1.HttpMethod.Post,
91
- execute: (request) => {
92
- const { body } = request;
93
- return (0, function_1.pipe)(fileStorage.write({
94
- content: body,
95
- key: 'test.ico',
96
- metadata: {
97
- name: 'test.ico',
98
- },
99
- }), TE.fold(() => T.of({
100
- body: stream_1.Readable.from(JSON.stringify({
101
- success: false,
102
- })),
103
- headers: {},
104
- statusCode: 500,
105
- }), () => T.of({
106
- body: stream_1.Readable.from(JSON.stringify({
107
- success: true,
108
- })),
109
- headers: {},
110
- statusCode: 200,
111
- })));
112
- },
86
+ },
87
+ {
88
+ path: `/image-upload`,
89
+ method: Http_1.HttpMethod.Post,
90
+ execute: (request) => {
91
+ const { body } = request;
92
+ return (0, function_1.pipe)(fileStorage.write({
93
+ content: body,
94
+ key: 'test.ico',
95
+ metadata: {
96
+ name: 'test.ico',
97
+ },
98
+ }), TE.fold(() => T.of({
99
+ body: stream_1.Readable.from(JSON.stringify({
100
+ success: false,
101
+ })),
102
+ headers: {},
103
+ statusCode: 500,
104
+ }), () => T.of({
105
+ body: stream_1.Readable.from(JSON.stringify({
106
+ success: true,
107
+ })),
108
+ headers: {},
109
+ statusCode: 200,
110
+ })));
113
111
  },
114
- {
115
- path: `/multipart-upload`,
116
- method: Http_1.HttpMethod.Post,
117
- execute: (request) => {
118
- const { body } = request;
119
- expect(body).toEqual(expect.objectContaining({
120
- fields: expect.objectContaining({ test: 'Hello world!' }),
121
- files: expect.objectContaining({
122
- 'test-image': expect.any(Object),
123
- }),
124
- }));
125
- return T.of({
126
- body: stream_1.Readable.from(JSON.stringify({
127
- success: true,
128
- })),
129
- headers: {},
130
- statusCode: 200,
131
- });
132
- },
112
+ },
113
+ {
114
+ path: `/multipart-upload`,
115
+ method: Http_1.HttpMethod.Post,
116
+ execute: (request) => {
117
+ const { body } = request;
118
+ expect(body).toEqual(expect.objectContaining({
119
+ fields: expect.objectContaining({ test: 'Hello world!' }),
120
+ files: expect.objectContaining({
121
+ 'test-image': expect.any(Object),
122
+ }),
123
+ }));
124
+ return T.of({
125
+ body: stream_1.Readable.from(JSON.stringify({
126
+ success: true,
127
+ })),
128
+ headers: {},
129
+ statusCode: 200,
130
+ });
133
131
  },
134
- ];
135
- }
132
+ },
133
+ ];
136
134
  }
137
135
  const testHttpController = new ExpressHttpController_1.ExpressHttpController(new TestControllerHttp(), '/tmp');
138
136
  describe('OperationExecutionGateway', () => {
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.OperationExecutionTest = void 0;
13
4
  const WinstonCliLogging_1 = require("@trayio/winston/cli/WinstonCliLogging");
@@ -18,6 +9,8 @@ function fail(reason) {
18
9
  }
19
10
  global.fail = fail;
20
11
  class OperationExecutionTest {
12
+ handlerTest;
13
+ handlerInvocationFactory;
21
14
  constructor(handlerTest, handlerInvocationFactory) {
22
15
  this.handlerTest = handlerTest;
23
16
  this.handlerInvocationFactory = handlerInvocationFactory;
@@ -27,21 +20,21 @@ class OperationExecutionTest {
27
20
  const defaultCtx = this.handlerTest.ctx;
28
21
  const defaultInvoke = this.handlerInvocationFactory(defaultCtx);
29
22
  let testContext;
30
- beforeAll(() => __awaiter(this, void 0, void 0, function* () {
31
- const beforeAllResult = yield this.handlerTest.beforeAllFunction(defaultCtx, defaultInvoke);
23
+ beforeAll(async () => {
24
+ const beforeAllResult = await this.handlerTest.beforeAllFunction(defaultCtx, defaultInvoke);
32
25
  switch (beforeAllResult.isSuccess) {
33
26
  case false:
34
27
  fail(`BeforeAll has failed with the following error ${beforeAllResult.error}`);
35
28
  case true:
36
29
  testContext = beforeAllResult.value;
37
30
  }
38
- }));
31
+ });
39
32
  this.handlerTest.testCaseFactories.forEach((testCaseFactory) => {
40
- it(testCaseFactory.description, () => __awaiter(this, void 0, void 0, function* () {
33
+ it(testCaseFactory.description, async () => {
41
34
  const testCase = testCaseFactory.testCase(testContext);
42
35
  const { ctx } = testCase;
43
36
  const invoke = this.handlerInvocationFactory(ctx);
44
- const givenResult = yield testCase.givenFunction(ctx, testContext, invoke);
37
+ const givenResult = await testCase.givenFunction(ctx, testContext, invoke);
45
38
  let testCaseContext;
46
39
  switch (givenResult.isSuccess) {
47
40
  case false:
@@ -50,7 +43,7 @@ class OperationExecutionTest {
50
43
  testCaseContext = givenResult.value;
51
44
  }
52
45
  const input = testCase.whenFunction(ctx, testContext, testCaseContext);
53
- const output = yield execution.execute(ctx, input);
46
+ const output = await execution.execute(ctx, input);
54
47
  const infoArg = process.argv.filter((arg) => arg.startsWith('--verbose'))[0];
55
48
  if (infoArg === '--verbose=true') {
56
49
  const logger = new WinstonCliLogging_1.WinstonCliLogging();
@@ -70,18 +63,18 @@ class OperationExecutionTest {
70
63
  output,
71
64
  };
72
65
  testCase.thenFunction(testCaseResult);
73
- const finallyResult = yield testCase.finallyFunction(testCaseResult, invoke);
66
+ const finallyResult = await testCase.finallyFunction(testCaseResult, invoke);
74
67
  if (finallyResult.isFailure) {
75
68
  fail(`Finally has failed with the following error ${finallyResult.error}`);
76
69
  }
77
- }));
70
+ });
78
71
  });
79
- afterAll(() => __awaiter(this, void 0, void 0, function* () {
80
- const afterAllResult = yield this.handlerTest.afterAllFunction(defaultCtx, testContext, defaultInvoke);
72
+ afterAll(async () => {
73
+ const afterAllResult = await this.handlerTest.afterAllFunction(defaultCtx, testContext, defaultInvoke);
81
74
  if (afterAllResult.isFailure) {
82
75
  fail(`AfterAll has failed with the following error ${afterAllResult.error}`);
83
76
  }
84
- }));
77
+ });
85
78
  });
86
79
  }
87
80
  }
@@ -30,6 +30,7 @@ const E = __importStar(require("fp-ts/Either"));
30
30
  const function_1 = require("fp-ts/function");
31
31
  const OperationExecutionTest_1 = require("./OperationExecutionTest");
32
32
  class OperationExecutionTestRunner {
33
+ operationExecutionGateway;
33
34
  constructor(operationExecutionGateway) {
34
35
  this.operationExecutionGateway = operationExecutionGateway;
35
36
  }
@@ -1,47 +1,38 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.OperationExecutionValidation = void 0;
13
4
  const OperationHandler_1 = require("@trayio/cdk-dsl/connector/operation/OperationHandler");
14
5
  class OperationExecutionValidation {
6
+ handlerValidation;
7
+ execution;
15
8
  constructor(handlerValidation, execution) {
16
9
  this.handlerValidation = handlerValidation;
17
10
  this.execution = execution;
18
11
  }
19
- execute(ctx, input) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- // TODO Add input schema validation
22
- const { inputValidation } = this.handlerValidation;
23
- const inputValidationResult = inputValidation
24
- .filter((validation) => !validation.condition(ctx, input))
25
- .map((validation) => validation.errorMessage(ctx, input));
26
- if (inputValidationResult.length > 0) {
27
- return OperationHandler_1.OperationHandlerResult.failure(OperationHandler_1.OperationHandlerError.userInputError(inputValidationResult.join(', ')));
28
- }
29
- const result = yield this.execution.execute(ctx, input);
30
- switch (result.isFailure) {
31
- case true:
32
- return result;
33
- case false:
34
- // TODO Add output schema validation
35
- const { outputValidation } = this.handlerValidation;
36
- const outputValidationResult = outputValidation
37
- .filter((validation) => !validation.condition(ctx, input, result.value))
38
- .map((validation) => validation.errorMessage(ctx, input, result.value));
39
- if (outputValidationResult.length > 0) {
40
- return OperationHandler_1.OperationHandlerResult.failure(OperationHandler_1.OperationHandlerError.connectorError(outputValidationResult.join(', ')));
41
- }
42
- return result;
43
- }
44
- });
12
+ async execute(ctx, input) {
13
+ // TODO Add input schema validation
14
+ const { inputValidation } = this.handlerValidation;
15
+ const inputValidationResult = inputValidation
16
+ .filter((validation) => !validation.condition(ctx, input))
17
+ .map((validation) => validation.errorMessage(ctx, input));
18
+ if (inputValidationResult.length > 0) {
19
+ return OperationHandler_1.OperationHandlerResult.failure(OperationHandler_1.OperationHandlerError.userInputError(inputValidationResult.join(', ')));
20
+ }
21
+ const result = await this.execution.execute(ctx, input);
22
+ switch (result.isFailure) {
23
+ case true:
24
+ return result;
25
+ case false:
26
+ // TODO Add output schema validation
27
+ const { outputValidation } = this.handlerValidation;
28
+ const outputValidationResult = outputValidation
29
+ .filter((validation) => !validation.condition(ctx, input, result.value))
30
+ .map((validation) => validation.errorMessage(ctx, input, result.value));
31
+ if (outputValidationResult.length > 0) {
32
+ return OperationHandler_1.OperationHandlerResult.failure(OperationHandler_1.OperationHandlerError.connectorError(outputValidationResult.join(', ')));
33
+ }
34
+ return result;
35
+ }
45
36
  }
46
37
  }
47
38
  exports.OperationExecutionValidation = OperationExecutionValidation;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trayio/cdk-runtime",
3
- "version": "3.8.0-beta",
3
+ "version": "3.9.0",
4
4
  "description": "A Runtime that executes connector operations defined using the CDK DSL",
5
5
  "exports": {
6
6
  "./*": "./dist/*.js"
@@ -14,10 +14,10 @@
14
14
  "node": ">=18.x"
15
15
  },
16
16
  "dependencies": {
17
- "@trayio/axios": "3.8.0-beta",
18
- "@trayio/cdk-dsl": "3.8.0-beta",
19
- "@trayio/express": "3.8.0-beta",
20
- "@trayio/winston": "3.8.0-beta",
17
+ "@trayio/axios": "3.9.0",
18
+ "@trayio/cdk-dsl": "3.9.0",
19
+ "@trayio/express": "3.9.0",
20
+ "@trayio/winston": "3.9.0",
21
21
  "mime": "3.0.0",
22
22
  "uuid": "9.0.0"
23
23
  },