@trayio/cdk-runtime 3.8.0 → 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.
- package/dist/connector/operation/CompositeOperationExecution.js +15 -24
- package/dist/connector/operation/CompositeOperationExecutionFactory.js +1 -0
- package/dist/connector/operation/HttpOperationExecution.js +32 -38
- package/dist/connector/operation/HttpOperationExecutionFactory.js +2 -0
- package/dist/connector/operation/OperationExecutionFactory.js +3 -0
- package/dist/connector/operation/OperationExecutionGateway.js +2 -0
- package/dist/connector/operation/OperationExecutionGateway.unit.test.js +82 -84
- package/dist/connector/operation/OperationExecutionTest.js +13 -20
- package/dist/connector/operation/OperationExecutionTestRunner.js +1 -0
- package/dist/connector/operation/OperationExecutionValidation.js +26 -35
- package/package.json +5 -5
|
@@ -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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
27
|
-
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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) => (
|
|
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
|
|
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
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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(() =>
|
|
31
|
-
const beforeAllResult =
|
|
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, () =>
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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(() =>
|
|
80
|
-
const afterAllResult =
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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.
|
|
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.
|
|
18
|
-
"@trayio/cdk-dsl": "3.
|
|
19
|
-
"@trayio/express": "3.
|
|
20
|
-
"@trayio/winston": "3.
|
|
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
|
},
|