@trayio/cdk-runtime 3.4.0 → 3.5.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/HttpOperationExecution.d.ts +4 -1
- package/dist/connector/operation/HttpOperationExecution.d.ts.map +1 -1
- package/dist/connector/operation/HttpOperationExecution.js +4 -2
- package/dist/connector/operation/HttpOperationExecutionFactory.d.ts +3 -1
- package/dist/connector/operation/HttpOperationExecutionFactory.d.ts.map +1 -1
- package/dist/connector/operation/HttpOperationExecutionFactory.js +2 -2
- package/dist/connector/operation/OperationExecutionFactory.d.ts.map +1 -1
- package/dist/connector/operation/OperationExecutionFactory.js +5 -5
- package/dist/connector/operation/OperationExecutionGateway.unit.test.js +33 -0
- package/package.json +5 -5
|
@@ -1,14 +1,17 @@
|
|
|
1
|
+
import * as O from 'fp-ts/Option';
|
|
1
2
|
import { OperationHandlerAuth, OperationHandlerContext, OperationHandlerResult } from '@trayio/cdk-dsl/connector/operation/OperationHandler';
|
|
2
3
|
import { HttpOperationHandler } from '@trayio/cdk-dsl/connector/operation/HttpOperationHandler';
|
|
3
4
|
import { HttpClient } from '@trayio/commons/http/HttpClient';
|
|
4
5
|
import { FileStorage } from '@trayio/commons/file/File';
|
|
6
|
+
import { OperationGlobalConfigHttp } from '@trayio/cdk-dsl/connector/operation/OperationGlobalConfig';
|
|
5
7
|
import { OperationExecution } from './OperationExecution';
|
|
6
8
|
export declare class HttpOperationExecution<AUTH extends OperationHandlerAuth<unknown, unknown>, IN, OUT> implements OperationExecution<AUTH, IN, OUT> {
|
|
7
9
|
private jsonSerialization;
|
|
8
10
|
private httpClient;
|
|
9
11
|
private handler;
|
|
10
12
|
private fileStorage;
|
|
11
|
-
|
|
13
|
+
private globalConfiguration;
|
|
14
|
+
constructor(httpClient: HttpClient, fileStorage: FileStorage, handler: HttpOperationHandler<AUTH, IN, OUT>, globalConfiguration: O.Option<OperationGlobalConfigHttp>);
|
|
12
15
|
execute(ctx: OperationHandlerContext<AUTH>, input: IN): Promise<OperationHandlerResult<OUT>>;
|
|
13
16
|
private operationRequestToHttpRequest;
|
|
14
17
|
private serializeAsJson;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpOperationExecution.d.ts","sourceRoot":"","sources":["../../../src/connector/operation/HttpOperationExecution.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"HttpOperationExecution.d.ts","sourceRoot":"","sources":["../../../src/connector/operation/HttpOperationExecution.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAKlC,OAAO,EACN,oBAAoB,EACpB,uBAAuB,EACvB,sBAAsB,EAGtB,MAAM,sDAAsD,CAAC;AAC9D,OAAO,EAGN,oBAAoB,EAKpB,MAAM,0DAA0D,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAW7D,OAAO,EAAQ,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAE9D,OAAO,EAAE,yBAAyB,EAAE,MAAM,2DAA2D,CAAC;AACtG,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAO1D,qBAAa,sBAAsB,CAClC,IAAI,SAAS,oBAAoB,CAAC,OAAO,EAAE,OAAO,CAAC,EACnD,EAAE,EACF,GAAG,CACF,YAAW,kBAAkB,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC;IAE7C,OAAO,CAAC,iBAAiB,CAAoB;IAC7C,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,OAAO,CAAsC;IACrD,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,mBAAmB,CAAsC;gBAGhE,UAAU,EAAE,UAAU,EACtB,WAAW,EAAE,WAAW,EACxB,OAAO,EAAE,oBAAoB,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC,EAC5C,mBAAmB,EAAE,CAAC,CAAC,MAAM,CAAC,yBAAyB,CAAC;IASnD,OAAO,CACZ,GAAG,EAAE,uBAAuB,CAAC,IAAI,CAAC,EAClC,KAAK,EAAE,EAAE,GACP,OAAO,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAC;IA+DvC,OAAO,CAAC,6BAA6B;IAiCrC,OAAO,CAAC,eAAe;IAOvB,OAAO,CAAC,yBAAyB;IAajC,OAAO,CAAC,eAAe;IAOvB,OAAO,CAAC,oBAAoB;IAuD5B,OAAO,CAAC,eAAe;IA0BvB,OAAO,CAAC,kBAAkB;IAI1B,OAAO,CAAC,oBAAoB;IAc5B,OAAO,CAAC,aAAa;IAiCrB,OAAO,CAAC,eAAe;IAmBvB,OAAO,CAAC,cAAc;IAMtB,OAAO,CAAC,eAAe;IA2CvB,OAAO,CAAC,eAAe;IAiBvB,OAAO,CAAC,qBAAqB;CAwC7B"}
|
|
@@ -48,15 +48,17 @@ const BufferExtensions_1 = require("@trayio/commons/buffer/BufferExtensions");
|
|
|
48
48
|
const mime = require('mime');
|
|
49
49
|
const { AWS_LAMBDA_FUNCTION_MEMORY_SIZE, CONNECTOR_MAX_ALLOCATED_RAM_MB } = process.env;
|
|
50
50
|
class HttpOperationExecution {
|
|
51
|
-
constructor(httpClient, fileStorage, handler) {
|
|
51
|
+
constructor(httpClient, fileStorage, handler, globalConfiguration) {
|
|
52
52
|
this.jsonSerialization = new JsonSerialization_1.JsonSerialization();
|
|
53
53
|
this.httpClient = httpClient;
|
|
54
54
|
this.fileStorage = fileStorage;
|
|
55
55
|
this.handler = handler;
|
|
56
|
+
this.globalConfiguration = globalConfiguration;
|
|
56
57
|
}
|
|
57
58
|
execute(ctx, input) {
|
|
58
59
|
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
-
const
|
|
60
|
+
const request = (0, function_1.pipe)(this.globalConfiguration, O.match(() => this.handler.request, (globalConfig) => (0, function_1.pipe)(globalConfig.baseUrl, O.match(() => this.handler.request, (baseUrl) => this.handler.request.withPath(`${baseUrl(ctx)}${this.handler.request.path}`)))));
|
|
61
|
+
const operationRequest = this.handler.requestHandler(ctx, input, request);
|
|
60
62
|
const httpRequestE = yield this.operationRequestToHttpRequest(operationRequest)();
|
|
61
63
|
if (E.isLeft(httpRequestE)) {
|
|
62
64
|
return OperationHandler_1.OperationHandlerResult.failure(OperationHandler_1.OperationHandlerError.connectorError(httpRequestE.left.message));
|
|
@@ -2,11 +2,13 @@ import { OperationHandlerAuth } from '@trayio/cdk-dsl/connector/operation/Operat
|
|
|
2
2
|
import { HttpOperationHandler } from '@trayio/cdk-dsl/connector/operation/HttpOperationHandler';
|
|
3
3
|
import { HttpClient } from '@trayio/commons/http/HttpClient';
|
|
4
4
|
import { FileStorage } from '@trayio/commons/dist/file/File';
|
|
5
|
+
import { OperationGlobalConfigHttp } from '@trayio/cdk-dsl/connector/operation/OperationGlobalConfig';
|
|
6
|
+
import * as O from 'fp-ts/Option';
|
|
5
7
|
import { OperationExecution } from './OperationExecution';
|
|
6
8
|
export declare class HttpOperationExecutionFactory {
|
|
7
9
|
private httpClient;
|
|
8
10
|
private fileStorage;
|
|
9
11
|
constructor(httpClient: HttpClient, fileStorage: FileStorage);
|
|
10
|
-
executionFrom<AUTH extends OperationHandlerAuth<unknown, unknown>, IN, OUT>(handler: HttpOperationHandler<AUTH, IN, OUT>): OperationExecution<AUTH, IN, OUT>;
|
|
12
|
+
executionFrom<AUTH extends OperationHandlerAuth<unknown, unknown>, IN, OUT>(handler: HttpOperationHandler<AUTH, IN, OUT>, globalConfiguration: O.Option<OperationGlobalConfigHttp>): OperationExecution<AUTH, IN, OUT>;
|
|
11
13
|
}
|
|
12
14
|
//# sourceMappingURL=HttpOperationExecutionFactory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpOperationExecutionFactory.d.ts","sourceRoot":"","sources":["../../../src/connector/operation/HttpOperationExecutionFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,sDAAsD,CAAC;AAC5F,OAAO,EAAE,oBAAoB,EAAE,MAAM,0DAA0D,CAAC;AAChG,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG1D,qBAAa,6BAA6B;IAExC,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,WAAW;gBADX,UAAU,EAAE,UAAU,EACtB,WAAW,EAAE,WAAW;IAGjC,aAAa,CAAC,IAAI,SAAS,oBAAoB,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,EAAE,EAAE,GAAG,EACzE,OAAO,EAAE,oBAAoB,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"HttpOperationExecutionFactory.d.ts","sourceRoot":"","sources":["../../../src/connector/operation/HttpOperationExecutionFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,sDAAsD,CAAC;AAC5F,OAAO,EAAE,oBAAoB,EAAE,MAAM,0DAA0D,CAAC;AAChG,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,yBAAyB,EAAE,MAAM,2DAA2D,CAAC;AACtG,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG1D,qBAAa,6BAA6B;IAExC,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,WAAW;gBADX,UAAU,EAAE,UAAU,EACtB,WAAW,EAAE,WAAW;IAGjC,aAAa,CAAC,IAAI,SAAS,oBAAoB,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,EAAE,EAAE,GAAG,EACzE,OAAO,EAAE,oBAAoB,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC,EAC5C,mBAAmB,EAAE,CAAC,CAAC,MAAM,CAAC,yBAAyB,CAAC,GACtD,kBAAkB,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC;CAQpC"}
|
|
@@ -7,8 +7,8 @@ class HttpOperationExecutionFactory {
|
|
|
7
7
|
this.httpClient = httpClient;
|
|
8
8
|
this.fileStorage = fileStorage;
|
|
9
9
|
}
|
|
10
|
-
executionFrom(handler) {
|
|
11
|
-
return new HttpOperationExecution_1.HttpOperationExecution(this.httpClient, this.fileStorage, handler);
|
|
10
|
+
executionFrom(handler, globalConfiguration) {
|
|
11
|
+
return new HttpOperationExecution_1.HttpOperationExecution(this.httpClient, this.fileStorage, handler, globalConfiguration);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
exports.HttpOperationExecutionFactory = HttpOperationExecutionFactory;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OperationExecutionFactory.d.ts","sourceRoot":"","sources":["../../../src/connector/operation/OperationExecutionFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,gBAAgB,EAEhB,MAAM,2DAA2D,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,sDAAsD,CAAC;AAC5F,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG1D,OAAO,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC;AAGxF,qBAAa,yBAAyB;IACrC,OAAO,CAAC,mCAAmC,CAAsC;IACjF,OAAO,CAAC,6BAA6B,CAAgC;IACrE,OAAO,CAAC,kCAAkC,CAAqC;gBAG9E,UAAU,EAAE,UAAU,EACtB,WAAW,EAAE,WAAW,EACxB,iCAAiC,EAAE,iCAAiC;IAYrE,aAAa,CAAC,IAAI,SAAS,oBAAoB,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,EAAE,EAAE,GAAG,EACzE,OAAO,EAAE,gBAAgB,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC,GACtC,kBAAkB,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC;
|
|
1
|
+
{"version":3,"file":"OperationExecutionFactory.d.ts","sourceRoot":"","sources":["../../../src/connector/operation/OperationExecutionFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,gBAAgB,EAEhB,MAAM,2DAA2D,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,sDAAsD,CAAC;AAC5F,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG1D,OAAO,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC;AAGxF,qBAAa,yBAAyB;IACrC,OAAO,CAAC,mCAAmC,CAAsC;IACjF,OAAO,CAAC,6BAA6B,CAAgC;IACrE,OAAO,CAAC,kCAAkC,CAAqC;gBAG9E,UAAU,EAAE,UAAU,EACtB,WAAW,EAAE,WAAW,EACxB,iCAAiC,EAAE,iCAAiC;IAYrE,aAAa,CAAC,IAAI,SAAS,oBAAoB,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,EAAE,EAAE,GAAG,EACzE,OAAO,EAAE,gBAAgB,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC,GACtC,kBAAkB,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC;IAWpC,OAAO,CAAC,2BAA2B;CAqBnC"}
|
|
@@ -13,16 +13,16 @@ class OperationExecutionFactory {
|
|
|
13
13
|
new CompositeOperationExecutionFactory_1.CompositeOperationExecutionFactory(operationHandlerInvocationFactory);
|
|
14
14
|
}
|
|
15
15
|
executionFrom(handler) {
|
|
16
|
-
const executionFromImplementation = this.executionFromImplementation(handler
|
|
16
|
+
const executionFromImplementation = this.executionFromImplementation(handler);
|
|
17
17
|
const execution = this.operationExecutionValidationFactory.decorateExecution(executionFromImplementation, handler.validation);
|
|
18
18
|
return execution;
|
|
19
19
|
}
|
|
20
|
-
executionFromImplementation(
|
|
21
|
-
switch (implementation._tag) {
|
|
20
|
+
executionFromImplementation(handler) {
|
|
21
|
+
switch (handler.implementation._tag) {
|
|
22
22
|
case 'HttpOperationHandler':
|
|
23
|
-
return this.httpOperationExecutionFactory.executionFrom(implementation);
|
|
23
|
+
return this.httpOperationExecutionFactory.executionFrom(handler.implementation, handler.globalConfiguration);
|
|
24
24
|
case 'CompositeOperationHandler':
|
|
25
|
-
return this.compositeOperationExecutionFactory.executionFrom(implementation);
|
|
25
|
+
return this.compositeOperationExecutionFactory.executionFrom(handler.implementation);
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
}
|
|
@@ -36,6 +36,7 @@ const ExpressHttpServer_1 = require("@trayio/express/http/ExpressHttpServer");
|
|
|
36
36
|
const ExpressHttpController_1 = require("@trayio/express/http/ExpressHttpController");
|
|
37
37
|
const NodeFsFileStorage_1 = require("@trayio/commons/file/NodeFsFileStorage");
|
|
38
38
|
require("./OperationHandlerTestRunner");
|
|
39
|
+
const OperationGlobalConfig_1 = require("@trayio/cdk-dsl/connector/operation/OperationGlobalConfig");
|
|
39
40
|
const fileStorage = new NodeFsFileStorage_1.NodeFsFileStorage('/tmp');
|
|
40
41
|
class TestControllerHttp {
|
|
41
42
|
constructor() {
|
|
@@ -155,6 +156,38 @@ describe('OperationExecutionGateway', () => {
|
|
|
155
156
|
.finallyDoNothing())
|
|
156
157
|
.nothingAfterAll());
|
|
157
158
|
});
|
|
159
|
+
describe('set a baseUrl via globalConfig', () => {
|
|
160
|
+
const globalConfig = OperationGlobalConfig_1.OperationGlobalConfigHttp.create().withBaseUrl(() => 'http://localhost:3000');
|
|
161
|
+
const getProductOperation = OperationHandlerSetup_1.OperationHandlerSetup.configureHandler((handler) => handler
|
|
162
|
+
.addInputValidation((inputValidation) => inputValidation
|
|
163
|
+
.condition((ctx, input) => input.id > 0)
|
|
164
|
+
.errorMessage(() => 'id must be bigger than zero'))
|
|
165
|
+
.withGlobalConfiguration(globalConfig)
|
|
166
|
+
.usingHttp((http) => http
|
|
167
|
+
.get('/posts/:id')
|
|
168
|
+
.handleRequest((ctx, input, request) => request.addPathParameter('id', input.id.toString()).withoutBody())
|
|
169
|
+
.handleResponse((ctx, input, response) => response.parseWithBodyAsJson())));
|
|
170
|
+
OperationHandlerTest_1.OperationHandlerTestSetup.configureHandlerTest(getProductOperation, (handlerTest) => handlerTest
|
|
171
|
+
.usingHandlerContext('test')
|
|
172
|
+
.nothingBeforeAll()
|
|
173
|
+
.testCase('should get a product', (testCase) => testCase
|
|
174
|
+
.usingHandlerContext('test')
|
|
175
|
+
.givenNothing()
|
|
176
|
+
.when(() => ({ id: 2 }))
|
|
177
|
+
.then(({ output }) => {
|
|
178
|
+
const outputValue = OperationHandler_1.OperationHandlerResult.getSuccessfulValueOrFail(output);
|
|
179
|
+
expect(outputValue.id).toEqual(2);
|
|
180
|
+
})
|
|
181
|
+
.finallyDoNothing())
|
|
182
|
+
.testCase('should validate id', (testCase) => testCase
|
|
183
|
+
.givenNothing()
|
|
184
|
+
.when(() => ({ id: -1 }))
|
|
185
|
+
.then(({ output }) => {
|
|
186
|
+
expect(output.isFailure).toBe(true);
|
|
187
|
+
})
|
|
188
|
+
.finallyDoNothing())
|
|
189
|
+
.nothingAfterAll());
|
|
190
|
+
});
|
|
158
191
|
describe('get a product as text', () => {
|
|
159
192
|
const getProductOperationAsText = OperationHandlerSetup_1.OperationHandlerSetup.configureHandler((handler) => handler
|
|
160
193
|
.addInputValidation((inputValidation) => inputValidation
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trayio/cdk-runtime",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.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.5.0",
|
|
18
|
+
"@trayio/cdk-dsl": "3.5.0",
|
|
19
|
+
"@trayio/express": "3.5.0",
|
|
20
|
+
"@trayio/winston": "3.5.0",
|
|
21
21
|
"mime": "3.0.0",
|
|
22
22
|
"uuid": "9.0.0"
|
|
23
23
|
},
|