@trayio/cdk-runtime 0.0.1-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +22 -0
- package/README.md +4 -0
- package/dist/connector/operation/CompositeOperationExecution.d.ts +12 -0
- package/dist/connector/operation/CompositeOperationExecution.d.ts.map +1 -0
- package/dist/connector/operation/CompositeOperationExecution.js +45 -0
- package/dist/connector/operation/CompositeOperationExecutionFactory.d.ts +10 -0
- package/dist/connector/operation/CompositeOperationExecutionFactory.d.ts.map +1 -0
- package/dist/connector/operation/CompositeOperationExecutionFactory.js +13 -0
- package/dist/connector/operation/HttpOperationExecution.d.ts +27 -0
- package/dist/connector/operation/HttpOperationExecution.d.ts.map +1 -0
- package/dist/connector/operation/HttpOperationExecution.js +247 -0
- package/dist/connector/operation/HttpOperationExecutionFactory.d.ts +12 -0
- package/dist/connector/operation/HttpOperationExecutionFactory.d.ts.map +1 -0
- package/dist/connector/operation/HttpOperationExecutionFactory.js +14 -0
- package/dist/connector/operation/OperationExecution.d.ts +5 -0
- package/dist/connector/operation/OperationExecution.d.ts.map +1 -0
- package/dist/connector/operation/OperationExecution.js +2 -0
- package/dist/connector/operation/OperationExecutionFactory.d.ts +15 -0
- package/dist/connector/operation/OperationExecutionFactory.d.ts.map +1 -0
- package/dist/connector/operation/OperationExecutionFactory.js +29 -0
- package/dist/connector/operation/OperationExecutionGateway.d.ts +13 -0
- package/dist/connector/operation/OperationExecutionGateway.d.ts.map +1 -0
- package/dist/connector/operation/OperationExecutionGateway.js +45 -0
- package/dist/connector/operation/OperationExecutionGateway.unit.test.d.ts +2 -0
- package/dist/connector/operation/OperationExecutionGateway.unit.test.d.ts.map +1 -0
- package/dist/connector/operation/OperationExecutionGateway.unit.test.js +252 -0
- package/dist/connector/operation/OperationExecutionTest.d.ts +11 -0
- package/dist/connector/operation/OperationExecutionTest.d.ts.map +1 -0
- package/dist/connector/operation/OperationExecutionTest.js +88 -0
- package/dist/connector/operation/OperationExecutionTestRunner.d.ts +8 -0
- package/dist/connector/operation/OperationExecutionTestRunner.d.ts.map +1 -0
- package/dist/connector/operation/OperationExecutionTestRunner.js +42 -0
- package/dist/connector/operation/OperationExecutionValidation.d.ts +10 -0
- package/dist/connector/operation/OperationExecutionValidation.d.ts.map +1 -0
- package/dist/connector/operation/OperationExecutionValidation.js +47 -0
- package/dist/connector/operation/OperationExecutionValidationFactory.d.ts +8 -0
- package/dist/connector/operation/OperationExecutionValidationFactory.d.ts.map +1 -0
- package/dist/connector/operation/OperationExecutionValidationFactory.js +35 -0
- package/dist/connector/operation/OperationHandlerInvocationFactory.d.ts +4 -0
- package/dist/connector/operation/OperationHandlerInvocationFactory.d.ts.map +1 -0
- package/dist/connector/operation/OperationHandlerInvocationFactory.js +2 -0
- package/dist/connector/operation/OperationHandlerTestRunner.d.ts +2 -0
- package/dist/connector/operation/OperationHandlerTestRunner.d.ts.map +1 -0
- package/dist/connector/operation/OperationHandlerTestRunner.js +12 -0
- package/dist/connector/operation/operation.json +5 -0
- package/dist/connector/test.ctx.json +1 -0
- package/package.json +35 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Tray.io, Inc
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
# Connector Development Kit (CDK) Runtime.
|
|
2
|
+
|
|
3
|
+
The CDK runtime interprets connectors written using the CDK DSL, the runtime is responsible for handling all the implementation details including dependencies, optimizations
|
|
4
|
+
and any other aspects related to how a connector is executed.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { OperationHandlerAuth, OperationHandlerContext, OperationHandlerResult } from '@trayio/cdk-dsl/connector/operation/OperationHandler';
|
|
2
|
+
import { CompositeOperationHandler } from '@trayio/cdk-dsl/connector/operation/CompositeOperationHandler';
|
|
3
|
+
import { OperationExecution } from './OperationExecution';
|
|
4
|
+
import { OperationHandlerInvocationFactory } from './OperationHandlerInvocationFactory';
|
|
5
|
+
export declare class CompositeOperationExecution<AUTH extends OperationHandlerAuth<unknown, unknown>, IN, OUT> implements OperationExecution<AUTH, IN, OUT> {
|
|
6
|
+
private handlerInvocationFactory;
|
|
7
|
+
private handler;
|
|
8
|
+
constructor(handlerInvocationFactory: OperationHandlerInvocationFactory, handler: CompositeOperationHandler<AUTH, IN, OUT>);
|
|
9
|
+
execute(ctx: OperationHandlerContext<AUTH>, input: IN): Promise<OperationHandlerResult<OUT>>;
|
|
10
|
+
private isError;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=CompositeOperationExecution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CompositeOperationExecution.d.ts","sourceRoot":"","sources":["../../../src/connector/operation/CompositeOperationExecution.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,oBAAoB,EACpB,uBAAuB,EACvB,sBAAsB,EAEtB,MAAM,sDAAsD,CAAC;AAC9D,OAAO,EAAE,yBAAyB,EAAE,MAAM,+DAA+D,CAAC;AAC1G,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC;AAExF,qBAAa,2BAA2B,CACvC,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,wBAAwB,CAAoC;IACpE,OAAO,CAAC,OAAO,CAA2C;gBAGzD,wBAAwB,EAAE,iCAAiC,EAC3D,OAAO,EAAE,yBAAyB,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC;IAM5C,OAAO,CACZ,GAAG,EAAE,uBAAuB,CAAC,IAAI,CAAC,EAClC,KAAK,EAAE,EAAE,GACP,OAAO,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAC;IA6BvC,OAAO,CAAC,OAAO;CAQf"}
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.CompositeOperationExecution = void 0;
|
|
13
|
+
const OperationHandler_1 = require("@trayio/cdk-dsl/connector/operation/OperationHandler");
|
|
14
|
+
class CompositeOperationExecution {
|
|
15
|
+
constructor(handlerInvocationFactory, handler) {
|
|
16
|
+
this.handlerInvocationFactory = handlerInvocationFactory;
|
|
17
|
+
this.handler = handler;
|
|
18
|
+
}
|
|
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;
|
|
25
|
+
}
|
|
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'));
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
// TODO: Move to commons
|
|
38
|
+
isError(error) {
|
|
39
|
+
return (typeof error === 'object' &&
|
|
40
|
+
!Array.isArray(error) &&
|
|
41
|
+
error !== null &&
|
|
42
|
+
error.message !== undefined);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.CompositeOperationExecution = CompositeOperationExecution;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { OperationHandlerAuth } from '@trayio/cdk-dsl/connector/operation/OperationHandler';
|
|
2
|
+
import { CompositeOperationHandler } from '@trayio/cdk-dsl/connector/operation/CompositeOperationHandler';
|
|
3
|
+
import { OperationExecution } from './OperationExecution';
|
|
4
|
+
import { OperationHandlerInvocationFactory } from './OperationHandlerInvocationFactory';
|
|
5
|
+
export declare class CompositeOperationExecutionFactory {
|
|
6
|
+
private handlerInvocationFactory;
|
|
7
|
+
constructor(handlerInvocationFactory: OperationHandlerInvocationFactory);
|
|
8
|
+
executionFrom<AUTH extends OperationHandlerAuth<unknown, unknown>, IN, OUT>(handler: CompositeOperationHandler<AUTH, IN, OUT>): OperationExecution<AUTH, IN, OUT>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=CompositeOperationExecutionFactory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CompositeOperationExecutionFactory.d.ts","sourceRoot":"","sources":["../../../src/connector/operation/CompositeOperationExecutionFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,sDAAsD,CAAC;AAC5F,OAAO,EAAE,yBAAyB,EAAE,MAAM,+DAA+D,CAAC;AAC1G,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC;AAExF,qBAAa,kCAAkC;IAC9C,OAAO,CAAC,wBAAwB,CAAoC;gBAExD,wBAAwB,EAAE,iCAAiC;IAIvE,aAAa,CAAC,IAAI,SAAS,oBAAoB,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,EAAE,EAAE,GAAG,EACzE,OAAO,EAAE,yBAAyB,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC,GAC/C,kBAAkB,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC;CAMpC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CompositeOperationExecutionFactory = void 0;
|
|
4
|
+
const CompositeOperationExecution_1 = require("./CompositeOperationExecution");
|
|
5
|
+
class CompositeOperationExecutionFactory {
|
|
6
|
+
constructor(handlerInvocationFactory) {
|
|
7
|
+
this.handlerInvocationFactory = handlerInvocationFactory;
|
|
8
|
+
}
|
|
9
|
+
executionFrom(handler) {
|
|
10
|
+
return new CompositeOperationExecution_1.CompositeOperationExecution(this.handlerInvocationFactory, handler);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.CompositeOperationExecutionFactory = CompositeOperationExecutionFactory;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { OperationHandlerAuth, OperationHandlerContext, OperationHandlerResult } from '@trayio/cdk-dsl/connector/operation/OperationHandler';
|
|
2
|
+
import { HttpOperationHandler } from '@trayio/cdk-dsl/connector/operation/HttpOperationHandler';
|
|
3
|
+
import { HttpClient } from '@trayio/commons/http/HttpClient';
|
|
4
|
+
import { FileStorage } from '@trayio/commons/file/File';
|
|
5
|
+
import { OperationExecution } from './OperationExecution';
|
|
6
|
+
export declare class HttpOperationExecution<AUTH extends OperationHandlerAuth<unknown, unknown>, IN, OUT> implements OperationExecution<AUTH, IN, OUT> {
|
|
7
|
+
private jsonSerialization;
|
|
8
|
+
private httpClient;
|
|
9
|
+
private handler;
|
|
10
|
+
private fileStorage;
|
|
11
|
+
constructor(httpClient: HttpClient, fileStorage: FileStorage, handler: HttpOperationHandler<AUTH, IN, OUT>);
|
|
12
|
+
execute(ctx: OperationHandlerContext<AUTH>, input: IN): Promise<OperationHandlerResult<OUT>>;
|
|
13
|
+
private operationRequestToHttpRequest;
|
|
14
|
+
private serializeAsJson;
|
|
15
|
+
private serializeAsText;
|
|
16
|
+
private serializeAsMultipart;
|
|
17
|
+
private serializeAsFile;
|
|
18
|
+
private serializeEmptyBody;
|
|
19
|
+
private defaultErrorHandling;
|
|
20
|
+
private parseResponse;
|
|
21
|
+
private parseBodyAsJson;
|
|
22
|
+
private parseEmptyBody;
|
|
23
|
+
private parseBodyAsFile;
|
|
24
|
+
private parseBodyAsText;
|
|
25
|
+
private generateUploadOptions;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=HttpOperationExecution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpOperationExecution.d.ts","sourceRoot":"","sources":["../../../src/connector/operation/HttpOperationExecution.ts"],"names":[],"mappings":"AASA,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,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;gBAGhC,UAAU,EAAE,UAAU,EACtB,WAAW,EAAE,WAAW,EACxB,OAAO,EAAE,oBAAoB,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC;IAQvC,OAAO,CACZ,GAAG,EAAE,uBAAuB,CAAC,IAAI,CAAC,EAClC,KAAK,EAAE,EAAE,GACP,OAAO,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAC;IAiDvC,OAAO,CAAC,6BAA6B;IA+BrC,OAAO,CAAC,eAAe;IAOvB,OAAO,CAAC,eAAe;IAOvB,OAAO,CAAC,oBAAoB;IAyD5B,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"}
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.HttpOperationExecution = void 0;
|
|
36
|
+
const TE = __importStar(require("fp-ts/TaskEither"));
|
|
37
|
+
const E = __importStar(require("fp-ts/Either"));
|
|
38
|
+
const O = __importStar(require("fp-ts/Option"));
|
|
39
|
+
const function_1 = require("fp-ts/function");
|
|
40
|
+
const Array_1 = require("fp-ts/Array");
|
|
41
|
+
const uuid_1 = require("uuid");
|
|
42
|
+
const OperationHandler_1 = require("@trayio/cdk-dsl/connector/operation/OperationHandler");
|
|
43
|
+
const HttpOperationHandler_1 = require("@trayio/cdk-dsl/connector/operation/HttpOperationHandler");
|
|
44
|
+
const Http_1 = require("@trayio/commons/http/Http");
|
|
45
|
+
const JsonSerialization_1 = require("@trayio/commons/serialization/JsonSerialization");
|
|
46
|
+
const BufferExtensions_1 = require("@trayio/commons/buffer/BufferExtensions");
|
|
47
|
+
const mime = require('mime');
|
|
48
|
+
const { AWS_LAMBDA_FUNCTION_MEMORY_SIZE, CONNECTOR_MAX_ALLOCATED_RAM_MB } = process.env;
|
|
49
|
+
class HttpOperationExecution {
|
|
50
|
+
constructor(httpClient, fileStorage, handler) {
|
|
51
|
+
this.jsonSerialization = new JsonSerialization_1.JsonSerialization();
|
|
52
|
+
this.httpClient = httpClient;
|
|
53
|
+
this.fileStorage = fileStorage;
|
|
54
|
+
this.handler = handler;
|
|
55
|
+
}
|
|
56
|
+
execute(ctx, input) {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
const operationRequest = this.handler.requestHandler(ctx, input, this.handler.request);
|
|
59
|
+
const httpRequestE = yield this.operationRequestToHttpRequest(operationRequest)();
|
|
60
|
+
if (E.isLeft(httpRequestE)) {
|
|
61
|
+
return OperationHandler_1.OperationHandlerResult.failure(OperationHandler_1.OperationHandlerError.connectorError(httpRequestE.left.message));
|
|
62
|
+
}
|
|
63
|
+
const resultTE = this.httpClient.execute(operationRequest.method, operationRequest.path, httpRequestE.right);
|
|
64
|
+
const operationResponseTE = (0, function_1.pipe)(resultTE,
|
|
65
|
+
// get the dsl http response object
|
|
66
|
+
TE.map((response) => this.handler.responseHandler(ctx, input, new HttpOperationHandler_1.HttpOperationResponseBuilder(response, this.defaultErrorHandling(response.statusCode)))),
|
|
67
|
+
// interpret the dsl response object by mapping the low level http response to a connector response
|
|
68
|
+
TE.chain((operationResponse) => this.parseResponse(operationResponse)),
|
|
69
|
+
// handle errors during the execution of the http request or parsing or the http response
|
|
70
|
+
TE.mapLeft((error) => OperationHandler_1.OperationHandlerResult.failure(OperationHandler_1.OperationHandlerError.connectorError(error.message))));
|
|
71
|
+
return TE.toUnion(operationResponseTE)();
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
operationRequestToHttpRequest(operationRequest) {
|
|
75
|
+
return (0, function_1.pipe)(operationRequest.contentType, O.map((contentType) => {
|
|
76
|
+
switch (contentType) {
|
|
77
|
+
case Http_1.HttpContentType.Json:
|
|
78
|
+
return this.serializeAsJson(operationRequest.body);
|
|
79
|
+
case Http_1.HttpContentType.OctetStream:
|
|
80
|
+
return this.serializeAsFile(operationRequest);
|
|
81
|
+
case Http_1.HttpContentType.MultipartRequestBody:
|
|
82
|
+
return this.serializeAsMultipart(operationRequest.body);
|
|
83
|
+
case Http_1.HttpContentType.Text:
|
|
84
|
+
return this.serializeAsText(operationRequest.body);
|
|
85
|
+
default:
|
|
86
|
+
return this.serializeAsJson(operationRequest.body);
|
|
87
|
+
}
|
|
88
|
+
}), O.getOrElse(() => this.serializeEmptyBody()), TE.map((serializedBody) => (Object.assign(Object.assign({}, operationRequest.request), { body: serializedBody }))));
|
|
89
|
+
}
|
|
90
|
+
serializeAsJson(body) {
|
|
91
|
+
const serializedBody = this.jsonSerialization.serialize(body);
|
|
92
|
+
return TE.right(BufferExtensions_1.BufferExtensions.arrayBufferToReadable(serializedBody));
|
|
93
|
+
}
|
|
94
|
+
serializeAsText(body) {
|
|
95
|
+
const serializedBody = new TextEncoder().encode(body);
|
|
96
|
+
return TE.right(BufferExtensions_1.BufferExtensions.arrayBufferToReadable(serializedBody));
|
|
97
|
+
}
|
|
98
|
+
serializeAsMultipart(body) {
|
|
99
|
+
const fileStreamsFromReferencesTasks = Object.keys(body.files).map((fileKey) => {
|
|
100
|
+
const fileRef = body.files[fileKey];
|
|
101
|
+
return (0, function_1.pipe)(this.httpClient.execute(Http_1.HttpMethod.Get, fileRef.url, {
|
|
102
|
+
headers: {
|
|
103
|
+
[Http_1.HttpHeader.ContentType]: Http_1.HttpContentType.OctetStream,
|
|
104
|
+
},
|
|
105
|
+
pathParams: {},
|
|
106
|
+
queryString: {},
|
|
107
|
+
body: BufferExtensions_1.BufferExtensions.arrayBufferToReadable(new ArrayBuffer(0)),
|
|
108
|
+
}), TE.chain((response) => {
|
|
109
|
+
if (response.statusCode >= 300) {
|
|
110
|
+
return TE.left(Error('error downloading file from source'));
|
|
111
|
+
}
|
|
112
|
+
const parsedSized = Number.parseInt(response.headers.ContentLength ||
|
|
113
|
+
response.headers['content-length'], 10);
|
|
114
|
+
return TE.right({
|
|
115
|
+
key: fileKey,
|
|
116
|
+
metadata: {
|
|
117
|
+
name: fileRef.name,
|
|
118
|
+
size: Number.isNaN(parsedSized) ? undefined : parsedSized,
|
|
119
|
+
contentType: fileRef.mime_type,
|
|
120
|
+
},
|
|
121
|
+
content: response.body,
|
|
122
|
+
});
|
|
123
|
+
}));
|
|
124
|
+
});
|
|
125
|
+
const filesTask = (0, Array_1.sequence)(TE.MonadTask)(fileStreamsFromReferencesTasks);
|
|
126
|
+
return (0, function_1.pipe)(filesTask, TE.map((files) => files.reduce((acc, file) => {
|
|
127
|
+
acc[file.key] = file;
|
|
128
|
+
return acc;
|
|
129
|
+
}, {})), TE.map((multipartFiles) => ({
|
|
130
|
+
fields: body.fields,
|
|
131
|
+
files: multipartFiles,
|
|
132
|
+
})));
|
|
133
|
+
}
|
|
134
|
+
serializeAsFile(operationRequest) {
|
|
135
|
+
const downloadFilefromReference = this.httpClient.execute(Http_1.HttpMethod.Get, operationRequest.body.url, {
|
|
136
|
+
headers: { [Http_1.HttpHeader.ContentType]: Http_1.HttpContentType.OctetStream },
|
|
137
|
+
pathParams: {},
|
|
138
|
+
queryString: {},
|
|
139
|
+
body: BufferExtensions_1.BufferExtensions.arrayBufferToReadable(new ArrayBuffer(0)),
|
|
140
|
+
});
|
|
141
|
+
return (0, function_1.pipe)(downloadFilefromReference, TE.chain((response) => {
|
|
142
|
+
if (response.statusCode >= 300) {
|
|
143
|
+
return TE.left(Error('error downloading file from source'));
|
|
144
|
+
}
|
|
145
|
+
return TE.right(response.body);
|
|
146
|
+
}));
|
|
147
|
+
}
|
|
148
|
+
serializeEmptyBody() {
|
|
149
|
+
return TE.right(BufferExtensions_1.BufferExtensions.arrayBufferToReadable(new ArrayBuffer(0)));
|
|
150
|
+
}
|
|
151
|
+
defaultErrorHandling(statusCode) {
|
|
152
|
+
return () => OperationHandler_1.OperationHandlerResult.failure(OperationHandler_1.OperationHandlerError.apiError(`API returned a status code of ${statusCode}`, {
|
|
153
|
+
statusCode,
|
|
154
|
+
}));
|
|
155
|
+
}
|
|
156
|
+
parseResponse(operationResponse) {
|
|
157
|
+
if (operationResponse.response.statusCode >= 300) {
|
|
158
|
+
return TE.right(operationResponse.errorHandling());
|
|
159
|
+
}
|
|
160
|
+
return (0, function_1.pipe)(operationResponse.contentType, O.map((contentType) => {
|
|
161
|
+
switch (contentType) {
|
|
162
|
+
case Http_1.HttpContentType.Json:
|
|
163
|
+
return this.parseBodyAsJson(operationResponse);
|
|
164
|
+
case Http_1.HttpContentType.OctetStream:
|
|
165
|
+
return this.parseBodyAsFile(operationResponse);
|
|
166
|
+
case Http_1.HttpContentType.MultipartRequestBody:
|
|
167
|
+
return TE.right(OperationHandler_1.OperationHandlerResult.failure(OperationHandler_1.OperationHandlerError.connectorError(`Invalid Response Type ${contentType}`)));
|
|
168
|
+
case Http_1.HttpContentType.Text:
|
|
169
|
+
return this.parseBodyAsText(operationResponse);
|
|
170
|
+
default:
|
|
171
|
+
return this.parseBodyAsJson(operationResponse);
|
|
172
|
+
}
|
|
173
|
+
}), O.getOrElse(() => this.parseEmptyBody(operationResponse)));
|
|
174
|
+
}
|
|
175
|
+
parseBodyAsJson(operationResponse) {
|
|
176
|
+
const bufferTE = BufferExtensions_1.BufferExtensions.readableToArrayBuffer(operationResponse.response.body);
|
|
177
|
+
return (0, function_1.pipe)(bufferTE, TE.chain((buffer) => {
|
|
178
|
+
const deserializedBodyE = this.jsonSerialization.deserialize(buffer);
|
|
179
|
+
return TE.fromEither(deserializedBodyE);
|
|
180
|
+
}), TE.map((deserializedBody) => operationResponse.responseParser(deserializedBody)));
|
|
181
|
+
}
|
|
182
|
+
parseEmptyBody(operationResponse) {
|
|
183
|
+
return TE.right(operationResponse.responseParser(undefined));
|
|
184
|
+
}
|
|
185
|
+
parseBodyAsFile(operationResponse) {
|
|
186
|
+
const contentType = (operationResponse.response.headers[Http_1.HttpHeader.ContentType.toLowerCase()]);
|
|
187
|
+
const fileExtension = mime.getExtension(contentType);
|
|
188
|
+
const contentLength = (operationResponse.response.headers[Http_1.HttpHeader.ContentLength.toLowerCase()]);
|
|
189
|
+
const uploadOptions = this.generateUploadOptions(contentLength);
|
|
190
|
+
return (0, function_1.pipe)(this.fileStorage.write({
|
|
191
|
+
content: operationResponse.response.body,
|
|
192
|
+
key: fileExtension ? `${(0, uuid_1.v4)()}.${fileExtension}` : (0, uuid_1.v4)(),
|
|
193
|
+
metadata: {
|
|
194
|
+
name: (0, uuid_1.v4)(),
|
|
195
|
+
size: parseFloat(contentLength !== null && contentLength !== void 0 ? contentLength : undefined),
|
|
196
|
+
contentType,
|
|
197
|
+
},
|
|
198
|
+
}, O.some(uploadOptions)), TE.chain((file) => (0, function_1.pipe)(this.fileStorage.getSharedUrl(file.key), TE.map((sharedUrl) => {
|
|
199
|
+
var _a, _b;
|
|
200
|
+
return operationResponse.responseParser({
|
|
201
|
+
name: file.metadata.name,
|
|
202
|
+
url: sharedUrl.url,
|
|
203
|
+
mime_type: (_a = file.metadata.contentType) !== null && _a !== void 0 ? _a : '',
|
|
204
|
+
expires: (_b = sharedUrl.expires) !== null && _b !== void 0 ? _b : 0,
|
|
205
|
+
});
|
|
206
|
+
}))));
|
|
207
|
+
}
|
|
208
|
+
parseBodyAsText(operationResponse) {
|
|
209
|
+
const arrayBufferTE = BufferExtensions_1.BufferExtensions.readableToArrayBuffer(operationResponse.response.body);
|
|
210
|
+
return (0, function_1.pipe)(arrayBufferTE, TE.chain((arrayBuffer) => {
|
|
211
|
+
const deserializeBody = new TextDecoder().decode(arrayBuffer);
|
|
212
|
+
return TE.right(operationResponse.responseParser(deserializeBody));
|
|
213
|
+
}));
|
|
214
|
+
}
|
|
215
|
+
// This method is used to respect lambda memory limits as per the old falfel implementation
|
|
216
|
+
generateUploadOptions(contentLength) {
|
|
217
|
+
const allocatedRam = AWS_LAMBDA_FUNCTION_MEMORY_SIZE || CONNECTOR_MAX_ALLOCATED_RAM_MB;
|
|
218
|
+
const availableRAM = allocatedRam ? parseInt(allocatedRam, 10) : 128; // 128MB default
|
|
219
|
+
const uploadMinSize = 1024 * 1024 * 8, // 8MB
|
|
220
|
+
maxRam = 1024 * 1024 * availableRAM;
|
|
221
|
+
/*
|
|
222
|
+
128 / 16 = 8 (which is UPLOAD_MIN_SIZE)
|
|
223
|
+
TARGET_SIZE should either be 8MB (since default assumed RAM is 128MB) or
|
|
224
|
+
1/16 of of the availableRAM, which ever is greater. The TARGET_SIZE, set
|
|
225
|
+
as `partSize`, will always be used in conjuction with `queueSize`.
|
|
226
|
+
*/
|
|
227
|
+
const sixteenthOfRAM = Math.floor(maxRam / 16);
|
|
228
|
+
const targetSize = sixteenthOfRAM < uploadMinSize ? uploadMinSize : sixteenthOfRAM;
|
|
229
|
+
const uploadOptions = {
|
|
230
|
+
// 8MB (minimum) * 4 parallel = upto 32MB/s RAM usage
|
|
231
|
+
partSize: targetSize,
|
|
232
|
+
queueSize: 4,
|
|
233
|
+
acl: 'bucket-owner-full-control',
|
|
234
|
+
};
|
|
235
|
+
if (!contentLength) {
|
|
236
|
+
if (CONNECTOR_MAX_ALLOCATED_RAM_MB) {
|
|
237
|
+
uploadOptions.queueSize = 12;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
else if (parseInt(contentLength, 10) > targetSize &&
|
|
241
|
+
parseInt(contentLength, 10) > targetSize * 8) {
|
|
242
|
+
uploadOptions.queueSize = 12;
|
|
243
|
+
}
|
|
244
|
+
return uploadOptions;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
exports.HttpOperationExecution = HttpOperationExecution;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { OperationHandlerAuth } from '@trayio/cdk-dsl/connector/operation/OperationHandler';
|
|
2
|
+
import { HttpOperationHandler } from '@trayio/cdk-dsl/connector/operation/HttpOperationHandler';
|
|
3
|
+
import { HttpClient } from '@trayio/commons/http/HttpClient';
|
|
4
|
+
import { FileStorage } from '@trayio/commons/dist/file/File';
|
|
5
|
+
import { OperationExecution } from './OperationExecution';
|
|
6
|
+
export declare class HttpOperationExecutionFactory {
|
|
7
|
+
private httpClient;
|
|
8
|
+
private fileStorage;
|
|
9
|
+
constructor(httpClient: HttpClient, fileStorage: FileStorage);
|
|
10
|
+
executionFrom<AUTH extends OperationHandlerAuth<unknown, unknown>, IN, OUT>(handler: HttpOperationHandler<AUTH, IN, OUT>): OperationExecution<AUTH, IN, OUT>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=HttpOperationExecutionFactory.d.ts.map
|
|
@@ -0,0 +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,GAC1C,kBAAkB,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC;CAOpC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpOperationExecutionFactory = void 0;
|
|
4
|
+
const HttpOperationExecution_1 = require("./HttpOperationExecution");
|
|
5
|
+
class HttpOperationExecutionFactory {
|
|
6
|
+
constructor(httpClient, fileStorage) {
|
|
7
|
+
this.httpClient = httpClient;
|
|
8
|
+
this.fileStorage = fileStorage;
|
|
9
|
+
}
|
|
10
|
+
executionFrom(handler) {
|
|
11
|
+
return new HttpOperationExecution_1.HttpOperationExecution(this.httpClient, this.fileStorage, handler);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.HttpOperationExecutionFactory = HttpOperationExecutionFactory;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { OperationHandlerAuth, OperationHandlerContext, OperationHandlerResult } from '@trayio/cdk-dsl/connector/operation/OperationHandler';
|
|
2
|
+
export interface OperationExecution<AUTH extends OperationHandlerAuth<unknown, unknown>, IN, OUT> {
|
|
3
|
+
execute(ctx: OperationHandlerContext<AUTH>, input: IN): Promise<OperationHandlerResult<OUT>>;
|
|
4
|
+
}
|
|
5
|
+
//# sourceMappingURL=OperationExecution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OperationExecution.d.ts","sourceRoot":"","sources":["../../../src/connector/operation/OperationExecution.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,oBAAoB,EACpB,uBAAuB,EACvB,sBAAsB,EACtB,MAAM,sDAAsD,CAAC;AAE9D,MAAM,WAAW,kBAAkB,CAClC,IAAI,SAAS,oBAAoB,CAAC,OAAO,EAAE,OAAO,CAAC,EACnD,EAAE,EACF,GAAG;IAEH,OAAO,CACN,GAAG,EAAE,uBAAuB,CAAC,IAAI,CAAC,EAClC,KAAK,EAAE,EAAE,GACP,OAAO,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAC,CAAC;CACxC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { OperationHandler } from '@trayio/cdk-dsl/connector/operation/OperationHandlerSetup';
|
|
2
|
+
import { OperationHandlerAuth } from '@trayio/cdk-dsl/connector/operation/OperationHandler';
|
|
3
|
+
import { HttpClient } from '@trayio/commons/http/HttpClient';
|
|
4
|
+
import { FileStorage } from '@trayio/commons/file/File';
|
|
5
|
+
import { OperationExecution } from './OperationExecution';
|
|
6
|
+
import { OperationHandlerInvocationFactory } from './OperationHandlerInvocationFactory';
|
|
7
|
+
export declare class OperationExecutionFactory {
|
|
8
|
+
private operationExecutionValidationFactory;
|
|
9
|
+
private httpOperationExecutionFactory;
|
|
10
|
+
private compositeOperationExecutionFactory;
|
|
11
|
+
constructor(httpClient: HttpClient, fileStorage: FileStorage, operationHandlerInvocationFactory: OperationHandlerInvocationFactory);
|
|
12
|
+
executionFrom<AUTH extends OperationHandlerAuth<unknown, unknown>, IN, OUT>(handler: OperationHandler<AUTH, IN, OUT>): OperationExecution<AUTH, IN, OUT>;
|
|
13
|
+
private executionFromImplementation;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=OperationExecutionFactory.d.ts.map
|
|
@@ -0,0 +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;IAYpC,OAAO,CAAC,2BAA2B;CAoBnC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OperationExecutionFactory = void 0;
|
|
4
|
+
const HttpOperationExecutionFactory_1 = require("./HttpOperationExecutionFactory");
|
|
5
|
+
const CompositeOperationExecutionFactory_1 = require("./CompositeOperationExecutionFactory");
|
|
6
|
+
const OperationExecutionValidationFactory_1 = require("./OperationExecutionValidationFactory");
|
|
7
|
+
class OperationExecutionFactory {
|
|
8
|
+
constructor(httpClient, fileStorage, operationHandlerInvocationFactory) {
|
|
9
|
+
this.operationExecutionValidationFactory =
|
|
10
|
+
new OperationExecutionValidationFactory_1.OperationExecutionValidationFactory();
|
|
11
|
+
this.httpOperationExecutionFactory = new HttpOperationExecutionFactory_1.HttpOperationExecutionFactory(httpClient, fileStorage);
|
|
12
|
+
this.compositeOperationExecutionFactory =
|
|
13
|
+
new CompositeOperationExecutionFactory_1.CompositeOperationExecutionFactory(operationHandlerInvocationFactory);
|
|
14
|
+
}
|
|
15
|
+
executionFrom(handler) {
|
|
16
|
+
const executionFromImplementation = this.executionFromImplementation(handler.implementation);
|
|
17
|
+
const execution = this.operationExecutionValidationFactory.decorateExecution(executionFromImplementation, handler.validation);
|
|
18
|
+
return execution;
|
|
19
|
+
}
|
|
20
|
+
executionFromImplementation(implementation) {
|
|
21
|
+
switch (implementation._tag) {
|
|
22
|
+
case 'HttpOperationHandler':
|
|
23
|
+
return this.httpOperationExecutionFactory.executionFrom(implementation);
|
|
24
|
+
case 'CompositeOperationHandler':
|
|
25
|
+
return this.compositeOperationExecutionFactory.executionFrom(implementation);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.OperationExecutionFactory = OperationExecutionFactory;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as O from 'fp-ts/Option';
|
|
2
|
+
import { OperationHandlerAuth, OperationHandlerReference } from '@trayio/cdk-dsl/connector/operation/OperationHandler';
|
|
3
|
+
import { HttpClient } from '@trayio/commons/http/HttpClient';
|
|
4
|
+
import { FileStorage } from '@trayio/commons/file/File';
|
|
5
|
+
import { OperationHandlerInvocationFactory } from './OperationHandlerInvocationFactory';
|
|
6
|
+
import { OperationExecution } from './OperationExecution';
|
|
7
|
+
export declare class OperationExecutionGateway {
|
|
8
|
+
private executionFactory;
|
|
9
|
+
operationHandlerInvocationFactory: OperationHandlerInvocationFactory;
|
|
10
|
+
constructor(httpClient: HttpClient, fileStorage: FileStorage);
|
|
11
|
+
lookup<AUTH extends OperationHandlerAuth<unknown, unknown>, IN, OUT>(handlerReference: OperationHandlerReference<AUTH, IN, OUT>, includePrivate: boolean): O.Option<OperationExecution<AUTH, IN, OUT>>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=OperationExecutionGateway.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OperationExecutionGateway.d.ts","sourceRoot":"","sources":["../../../src/connector/operation/OperationExecutionGateway.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAGlC,OAAO,EACN,oBAAoB,EAEpB,yBAAyB,EAGzB,MAAM,sDAAsD,CAAC;AAE9D,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAE7D,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC;AACxF,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG1D,qBAAa,yBAAyB;IACrC,OAAO,CAAC,gBAAgB,CAA4B;IACpD,iCAAiC,EAAE,iCAAiC,CAAC;gBAEzD,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW;IA8B5D,MAAM,CAAC,IAAI,SAAS,oBAAoB,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,EAAE,EAAE,GAAG,EAClE,gBAAgB,EAAE,yBAAyB,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC,EAC1D,cAAc,EAAE,OAAO,GACrB,CAAC,CAAC,MAAM,CAAC,kBAAkB,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC,CAAC;CAO9C"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.OperationExecutionGateway = void 0;
|
|
27
|
+
const O = __importStar(require("fp-ts/Option"));
|
|
28
|
+
const function_1 = require("fp-ts/function");
|
|
29
|
+
const OperationHandler_1 = require("@trayio/cdk-dsl/connector/operation/OperationHandler");
|
|
30
|
+
const OperationHandlerSetup_1 = require("@trayio/cdk-dsl/connector/operation/OperationHandlerSetup");
|
|
31
|
+
const OperationExecutionFactory_1 = require("./OperationExecutionFactory");
|
|
32
|
+
class OperationExecutionGateway {
|
|
33
|
+
constructor(httpClient, fileStorage) {
|
|
34
|
+
const operationHandlerInvocationFactory = (ctx) => (handlerReference) => (input) => {
|
|
35
|
+
const result = (0, function_1.pipe)(this.lookup(handlerReference, true), O.map((handlerExecution) => handlerExecution.execute(ctx, input)));
|
|
36
|
+
return O.getOrElse(() => Promise.resolve(OperationHandler_1.OperationHandlerResult.failure(OperationHandler_1.OperationHandlerError.connectorError(`Handler for reference ${handlerReference.name} not found`))))(result);
|
|
37
|
+
};
|
|
38
|
+
this.operationHandlerInvocationFactory = operationHandlerInvocationFactory;
|
|
39
|
+
this.executionFactory = new OperationExecutionFactory_1.OperationExecutionFactory(httpClient, fileStorage, operationHandlerInvocationFactory);
|
|
40
|
+
}
|
|
41
|
+
lookup(handlerReference, includePrivate) {
|
|
42
|
+
return (0, function_1.pipe)(OperationHandlerSetup_1.OperationHandlerRegistry.resolve(handlerReference), O.filter((handler) => includePrivate || !handler.isPrivate), O.map((handler) => this.executionFactory.executionFrom(handler)));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.OperationExecutionGateway = OperationExecutionGateway;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OperationExecutionGateway.unit.test.d.ts","sourceRoot":"","sources":["../../../src/connector/operation/OperationExecutionGateway.unit.test.ts"],"names":[],"mappings":"AAmBA,OAAO,8BAA8B,CAAC"}
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const stream_1 = require("stream");
|
|
27
|
+
const T = __importStar(require("fp-ts/Task"));
|
|
28
|
+
const TE = __importStar(require("fp-ts/TaskEither"));
|
|
29
|
+
const function_1 = require("fp-ts/function");
|
|
30
|
+
const OperationHandlerSetup_1 = require("@trayio/cdk-dsl/connector/operation/OperationHandlerSetup");
|
|
31
|
+
const OperationHandlerTest_1 = require("@trayio/cdk-dsl/connector/operation/OperationHandlerTest");
|
|
32
|
+
const OperationHandler_1 = require("@trayio/cdk-dsl/connector/operation/OperationHandler");
|
|
33
|
+
const Http_1 = require("@trayio/commons/http/Http");
|
|
34
|
+
const ExpressHttpServer_1 = require("@trayio/express/http/ExpressHttpServer");
|
|
35
|
+
const ExpressHttpController_1 = require("@trayio/express/http/ExpressHttpController");
|
|
36
|
+
const NodeFsFileStorage_1 = require("@trayio/commons/file/NodeFsFileStorage");
|
|
37
|
+
require("./OperationHandlerTestRunner");
|
|
38
|
+
const fileStorage = new NodeFsFileStorage_1.NodeFsFileStorage('/tmp');
|
|
39
|
+
class TestControllerHttp {
|
|
40
|
+
constructor() {
|
|
41
|
+
this.getEndpoints = () => [
|
|
42
|
+
{
|
|
43
|
+
path: `/posts/:id`,
|
|
44
|
+
method: Http_1.HttpMethod.Get,
|
|
45
|
+
execute: (request) => {
|
|
46
|
+
const { id } = request.pathParams;
|
|
47
|
+
return T.of({
|
|
48
|
+
body: stream_1.Readable.from(JSON.stringify({
|
|
49
|
+
id: parseInt(id, 10),
|
|
50
|
+
title: 'test',
|
|
51
|
+
})),
|
|
52
|
+
headers: {},
|
|
53
|
+
statusCode: 200,
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
path: `/image-upload`,
|
|
59
|
+
method: Http_1.HttpMethod.Post,
|
|
60
|
+
execute: (request) => {
|
|
61
|
+
const { body } = request;
|
|
62
|
+
return (0, function_1.pipe)(fileStorage.write({
|
|
63
|
+
content: body,
|
|
64
|
+
key: 'test.ico',
|
|
65
|
+
metadata: {
|
|
66
|
+
name: 'test.ico',
|
|
67
|
+
},
|
|
68
|
+
}), TE.fold(() => T.of({
|
|
69
|
+
body: stream_1.Readable.from(JSON.stringify({
|
|
70
|
+
success: false,
|
|
71
|
+
})),
|
|
72
|
+
headers: {},
|
|
73
|
+
statusCode: 500,
|
|
74
|
+
}), () => T.of({
|
|
75
|
+
body: stream_1.Readable.from(JSON.stringify({
|
|
76
|
+
success: true,
|
|
77
|
+
})),
|
|
78
|
+
headers: {},
|
|
79
|
+
statusCode: 200,
|
|
80
|
+
})));
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
path: `/multipart-upload`,
|
|
85
|
+
method: Http_1.HttpMethod.Post,
|
|
86
|
+
execute: (request) => {
|
|
87
|
+
const { body } = request;
|
|
88
|
+
expect(body).toEqual(expect.objectContaining({
|
|
89
|
+
fields: expect.objectContaining({ test: 'Hello world!' }),
|
|
90
|
+
files: expect.objectContaining({
|
|
91
|
+
'test-image': expect.any(Object),
|
|
92
|
+
}),
|
|
93
|
+
}));
|
|
94
|
+
return T.of({
|
|
95
|
+
body: stream_1.Readable.from(JSON.stringify({
|
|
96
|
+
success: true,
|
|
97
|
+
})),
|
|
98
|
+
headers: {},
|
|
99
|
+
statusCode: 200,
|
|
100
|
+
});
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
];
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const testHttpController = new ExpressHttpController_1.ExpressHttpController(new TestControllerHttp(), '/tmp');
|
|
107
|
+
describe('OperationExecutionGateway', () => {
|
|
108
|
+
let server;
|
|
109
|
+
beforeAll(() => {
|
|
110
|
+
server = (0, ExpressHttpServer_1.startServer)([testHttpController], { port: 3000 });
|
|
111
|
+
});
|
|
112
|
+
afterAll(() => {
|
|
113
|
+
server.close();
|
|
114
|
+
});
|
|
115
|
+
describe('get a product', () => {
|
|
116
|
+
const getProductOperation = OperationHandlerSetup_1.OperationHandlerSetup.configureHandler((handler) => handler
|
|
117
|
+
.addInputValidation((inputValidation) => inputValidation
|
|
118
|
+
.condition((ctx, input) => input.id > 0)
|
|
119
|
+
.errorMessage(() => 'id must be bigger than zero'))
|
|
120
|
+
.usingHttp((http) => http
|
|
121
|
+
.get('http://localhost:3000/posts/:id')
|
|
122
|
+
.handleRequest((ctx, input, request) => request.addPathParameter('id', input.id.toString()).withoutBody())
|
|
123
|
+
.handleResponse((ctx, input, response) => response.parseWithBodyAsJson())));
|
|
124
|
+
OperationHandlerTest_1.OperationHandlerTestSetup.configureHandlerTest(getProductOperation, (handlerTest) => handlerTest
|
|
125
|
+
.usingHandlerContext('test')
|
|
126
|
+
.nothingBeforeAll()
|
|
127
|
+
.testCase('should get a product', (testCase) => testCase
|
|
128
|
+
.usingHandlerContext('test')
|
|
129
|
+
.givenNothing()
|
|
130
|
+
.when(() => ({ id: 2 }))
|
|
131
|
+
.then(({ output }) => {
|
|
132
|
+
const outputValue = OperationHandler_1.OperationHandlerResult.getSuccessfulValueOrFail(output);
|
|
133
|
+
expect(outputValue.id).toEqual(2);
|
|
134
|
+
})
|
|
135
|
+
.finallyDoNothing())
|
|
136
|
+
.testCase('should validate id', (testCase) => testCase
|
|
137
|
+
.givenNothing()
|
|
138
|
+
.when(() => ({ id: -1 }))
|
|
139
|
+
.then(({ output }) => {
|
|
140
|
+
expect(output.isFailure).toBe(true);
|
|
141
|
+
})
|
|
142
|
+
.finallyDoNothing())
|
|
143
|
+
.nothingAfterAll());
|
|
144
|
+
});
|
|
145
|
+
describe('get a product as text', () => {
|
|
146
|
+
const getProductOperationAsText = OperationHandlerSetup_1.OperationHandlerSetup.configureHandler((handler) => handler
|
|
147
|
+
.addInputValidation((inputValidation) => inputValidation
|
|
148
|
+
.condition((ctx, input) => input.id > 0)
|
|
149
|
+
.errorMessage(() => 'id must be bigger than zero'))
|
|
150
|
+
.usingHttp((http) => http
|
|
151
|
+
.get('http://localhost:3000/posts/:id')
|
|
152
|
+
.handleRequest((ctx, input, request) => request.addPathParameter('id', input.id.toString()).withoutBody())
|
|
153
|
+
.handleResponse((ctx, input, response) => response.parseWithBodyAsText((text) => OperationHandler_1.OperationHandlerResult.success({ textField: text })))));
|
|
154
|
+
OperationHandlerTest_1.OperationHandlerTestSetup.configureHandlerTest(getProductOperationAsText, (handlerTest) => handlerTest
|
|
155
|
+
.usingHandlerContext('test')
|
|
156
|
+
.nothingBeforeAll()
|
|
157
|
+
.testCase('should get a product as text', (testCase) => testCase
|
|
158
|
+
.usingHandlerContext('test')
|
|
159
|
+
.givenNothing()
|
|
160
|
+
.when(() => ({ id: 2 }))
|
|
161
|
+
.then(({ output }) => {
|
|
162
|
+
const outputValue = OperationHandler_1.OperationHandlerResult.getSuccessfulValueOrFail(output);
|
|
163
|
+
expect(outputValue.textField).toContain(`"id":2`);
|
|
164
|
+
})
|
|
165
|
+
.finallyDoNothing())
|
|
166
|
+
.testCase('should validate id', (testCase) => testCase
|
|
167
|
+
.givenNothing()
|
|
168
|
+
.when(() => ({ id: -1 }))
|
|
169
|
+
.then(({ output }) => {
|
|
170
|
+
expect(output.isFailure).toBe(true);
|
|
171
|
+
})
|
|
172
|
+
.finallyDoNothing())
|
|
173
|
+
.nothingAfterAll());
|
|
174
|
+
});
|
|
175
|
+
describe('post multipart (with file)', () => {
|
|
176
|
+
const multipartOperation = OperationHandlerSetup_1.OperationHandlerSetup.configureHandler((handler) => handler.usingHttp((http) => http
|
|
177
|
+
.post('http://localhost:3000/multipart-upload')
|
|
178
|
+
.handleRequest((_ctx, _input, request) => request.withBodyAsMultipart({
|
|
179
|
+
fields: {
|
|
180
|
+
test: 'Hello world!',
|
|
181
|
+
},
|
|
182
|
+
files: {
|
|
183
|
+
'test-image': {
|
|
184
|
+
name: 'testImage.png',
|
|
185
|
+
url: 'https://upload.wikimedia.org/wikipedia/commons/thumb/6/61/Wikipedia-logo-transparent.png/526px-Wikipedia-logo-transparent.png',
|
|
186
|
+
mime_type: 'image/png',
|
|
187
|
+
expires: 0,
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
}))
|
|
191
|
+
.handleResponse((_ctx, _input, response) => response.parseWithBodyAsJson())));
|
|
192
|
+
OperationHandlerTest_1.OperationHandlerTestSetup.configureHandlerTest(multipartOperation, (handlerTest) => handlerTest
|
|
193
|
+
.usingHandlerContext('test')
|
|
194
|
+
.nothingBeforeAll()
|
|
195
|
+
.testCase('should send a multipart body (both data and file)', (testCase) => testCase
|
|
196
|
+
.usingHandlerContext('test')
|
|
197
|
+
.givenNothing()
|
|
198
|
+
.when(() => ({}))
|
|
199
|
+
.then(({ output }) => {
|
|
200
|
+
const outputValue = OperationHandler_1.OperationHandlerResult.getSuccessfulValueOrFail(output);
|
|
201
|
+
expect(outputValue.success).toEqual(true);
|
|
202
|
+
})
|
|
203
|
+
.finallyDoNothing())
|
|
204
|
+
.nothingAfterAll());
|
|
205
|
+
});
|
|
206
|
+
describe('upload an image', () => {
|
|
207
|
+
const uploadImageOperation = OperationHandlerSetup_1.OperationHandlerSetup.configureHandler((handler) => handler.usingHttp((http) => http
|
|
208
|
+
.post('http://localhost:3000/image-upload')
|
|
209
|
+
.handleRequest((ctx, input, request) => request.withBodyAsFile({
|
|
210
|
+
name: 'test-image',
|
|
211
|
+
url: 'https://tray.io/favicon.ico',
|
|
212
|
+
mime_type: 'image/png',
|
|
213
|
+
expires: 0,
|
|
214
|
+
}))
|
|
215
|
+
.handleResponse((ctx, input, response) => response.parseWithBodyAsJson())));
|
|
216
|
+
OperationHandlerTest_1.OperationHandlerTestSetup.configureHandlerTest(uploadImageOperation, (handlerTest) => handlerTest
|
|
217
|
+
.usingHandlerContext('test')
|
|
218
|
+
.nothingBeforeAll()
|
|
219
|
+
.testCase('should upload an image', (testCase) => testCase
|
|
220
|
+
.usingHandlerContext('test')
|
|
221
|
+
.givenNothing()
|
|
222
|
+
.when(() => ({}))
|
|
223
|
+
.then(({ output }) => {
|
|
224
|
+
const outputValue = OperationHandler_1.OperationHandlerResult.getSuccessfulValueOrFail(output);
|
|
225
|
+
expect(outputValue.success).toEqual(true);
|
|
226
|
+
})
|
|
227
|
+
.finallyDoNothing())
|
|
228
|
+
.nothingAfterAll());
|
|
229
|
+
});
|
|
230
|
+
describe('download a file', () => {
|
|
231
|
+
const downloadFileOperation = OperationHandlerSetup_1.OperationHandlerSetup.configureHandler((handler) => handler.usingHttp((http) => http
|
|
232
|
+
.get('https://tray.io/favicon.ico')
|
|
233
|
+
.handleRequest((ctx, input, request) => request.withoutBody())
|
|
234
|
+
.handleResponse((ctx, input, response) => response.parseWithBodyAsFile((file) => OperationHandler_1.OperationHandlerResult.success(file)))));
|
|
235
|
+
OperationHandlerTest_1.OperationHandlerTestSetup.configureHandlerTest(downloadFileOperation, (handlerTest) => handlerTest
|
|
236
|
+
.usingHandlerContext('test')
|
|
237
|
+
.nothingBeforeAll()
|
|
238
|
+
.testCase('should download a file', (testCase) => testCase
|
|
239
|
+
.usingHandlerContext('test')
|
|
240
|
+
.givenNothing()
|
|
241
|
+
.when(() => ({}))
|
|
242
|
+
.then(({ output }) => {
|
|
243
|
+
const outputValue = OperationHandler_1.OperationHandlerResult.getSuccessfulValueOrFail(output);
|
|
244
|
+
expect(outputValue.url).toBeDefined();
|
|
245
|
+
expect(outputValue.name).toBeDefined();
|
|
246
|
+
expect(outputValue.mime_type).toBeDefined();
|
|
247
|
+
expect(outputValue.expires).toBeDefined();
|
|
248
|
+
})
|
|
249
|
+
.finallyDoNothing())
|
|
250
|
+
.nothingAfterAll());
|
|
251
|
+
});
|
|
252
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { OperationHandlerAuth } from '@trayio/cdk-dsl/connector/operation/OperationHandler';
|
|
2
|
+
import { OperationHandlerTest } from '@trayio/cdk-dsl/connector/operation/OperationHandlerTest';
|
|
3
|
+
import { OperationExecution } from './OperationExecution';
|
|
4
|
+
import { OperationHandlerInvocationFactory } from './OperationHandlerInvocationFactory';
|
|
5
|
+
export declare class OperationExecutionTest<AUTH extends OperationHandlerAuth<unknown, unknown>, IN, OUT> {
|
|
6
|
+
private handlerTest;
|
|
7
|
+
private handlerInvocationFactory;
|
|
8
|
+
constructor(handlerTest: OperationHandlerTest<AUTH, IN, OUT, unknown>, handlerInvocationFactory: OperationHandlerInvocationFactory);
|
|
9
|
+
test(execution: OperationExecution<AUTH, IN, OUT>): void;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=OperationExecutionTest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OperationExecutionTest.d.ts","sourceRoot":"","sources":["../../../src/connector/operation/OperationExecutionTest.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,oBAAoB,EAEpB,MAAM,sDAAsD,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,0DAA0D,CAAC;AAIhG,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC;AAQxF,qBAAa,sBAAsB,CAClC,IAAI,SAAS,oBAAoB,CAAC,OAAO,EAAE,OAAO,CAAC,EACnD,EAAE,EACF,GAAG;IAEH,OAAO,CAAC,WAAW,CAA+C;IAClE,OAAO,CAAC,wBAAwB,CAAoC;gBAGnE,WAAW,EAAE,oBAAoB,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,EAAE,OAAO,CAAC,EACzD,wBAAwB,EAAE,iCAAiC;IAM5D,IAAI,CAAC,SAAS,EAAE,kBAAkB,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC,GAAG,IAAI;CAiGxD"}
|
|
@@ -0,0 +1,88 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.OperationExecutionTest = void 0;
|
|
13
|
+
const WinstonCliLogging_1 = require("@trayio/winston/cli/WinstonCliLogging");
|
|
14
|
+
const CliLogging_1 = require("@trayio/commons/cli/CliLogging");
|
|
15
|
+
// TODO move this to commons, newer versions of jest removed the "fail" method but left it in the types package.
|
|
16
|
+
function fail(reason) {
|
|
17
|
+
throw new Error(reason);
|
|
18
|
+
}
|
|
19
|
+
global.fail = fail;
|
|
20
|
+
class OperationExecutionTest {
|
|
21
|
+
constructor(handlerTest, handlerInvocationFactory) {
|
|
22
|
+
this.handlerTest = handlerTest;
|
|
23
|
+
this.handlerInvocationFactory = handlerInvocationFactory;
|
|
24
|
+
}
|
|
25
|
+
test(execution) {
|
|
26
|
+
describe(`Operation ${this.handlerTest.handlerReference.name} Test`, () => {
|
|
27
|
+
const defaultCtx = this.handlerTest.ctx;
|
|
28
|
+
const defaultInvoke = this.handlerInvocationFactory(defaultCtx);
|
|
29
|
+
let testContext;
|
|
30
|
+
beforeAll(() => __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
const beforeAllResult = yield this.handlerTest.beforeAllFunction(defaultCtx, defaultInvoke);
|
|
32
|
+
switch (beforeAllResult.isSuccess) {
|
|
33
|
+
case false:
|
|
34
|
+
fail(`BeforeAll has failed with the following error ${beforeAllResult.error}`);
|
|
35
|
+
case true:
|
|
36
|
+
testContext = beforeAllResult.value;
|
|
37
|
+
}
|
|
38
|
+
}));
|
|
39
|
+
this.handlerTest.testCaseFactories.forEach((testCaseFactory) => {
|
|
40
|
+
it(testCaseFactory.description, () => __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
const testCase = testCaseFactory.testCase(testContext);
|
|
42
|
+
const { ctx } = testCase;
|
|
43
|
+
const invoke = this.handlerInvocationFactory(ctx);
|
|
44
|
+
const givenResult = yield testCase.givenFunction(ctx, testContext, invoke);
|
|
45
|
+
let testCaseContext;
|
|
46
|
+
switch (givenResult.isSuccess) {
|
|
47
|
+
case false:
|
|
48
|
+
fail(`Given has failed with the following error ${givenResult.error}`);
|
|
49
|
+
case true:
|
|
50
|
+
testCaseContext = givenResult.value;
|
|
51
|
+
}
|
|
52
|
+
const input = testCase.whenFunction(ctx, testContext, testCaseContext);
|
|
53
|
+
const output = yield execution.execute(ctx, input);
|
|
54
|
+
const infoArg = process.argv.filter((arg) => arg.startsWith('--verbose'))[0];
|
|
55
|
+
if (infoArg === '--verbose=true') {
|
|
56
|
+
const logger = new WinstonCliLogging_1.WinstonCliLogging();
|
|
57
|
+
logger.logBlock('Operation input', CliLogging_1.CliColors.blue);
|
|
58
|
+
logger.log(input);
|
|
59
|
+
if (!output.isFailure) {
|
|
60
|
+
const logOutput = output;
|
|
61
|
+
logger.logBlock('Operation output', CliLogging_1.CliColors.blue);
|
|
62
|
+
logger.log(logOutput.value);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const testCaseResult = {
|
|
66
|
+
ctx,
|
|
67
|
+
testContext,
|
|
68
|
+
testCaseContext,
|
|
69
|
+
input,
|
|
70
|
+
output,
|
|
71
|
+
};
|
|
72
|
+
testCase.thenFunction(testCaseResult);
|
|
73
|
+
const finallyResult = yield testCase.finallyFunction(testCaseResult, invoke);
|
|
74
|
+
if (finallyResult.isFailure) {
|
|
75
|
+
fail(`Finally has failed with the following error ${finallyResult.error}`);
|
|
76
|
+
}
|
|
77
|
+
}));
|
|
78
|
+
});
|
|
79
|
+
afterAll(() => __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
const afterAllResult = yield this.handlerTest.afterAllFunction(defaultCtx, testContext, defaultInvoke);
|
|
81
|
+
if (afterAllResult.isFailure) {
|
|
82
|
+
fail(`AfterAll has failed with the following error ${afterAllResult.error}`);
|
|
83
|
+
}
|
|
84
|
+
}));
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.OperationExecutionTest = OperationExecutionTest;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { OperationHandlerAuth, OperationHandlerReference } from '@trayio/cdk-dsl/connector/operation/OperationHandler';
|
|
2
|
+
import { OperationExecutionGateway } from './OperationExecutionGateway';
|
|
3
|
+
export declare class OperationExecutionTestRunner {
|
|
4
|
+
private operationExecutionGateway;
|
|
5
|
+
constructor(operationExecutionGateway: OperationExecutionGateway);
|
|
6
|
+
runTestFor<AUTH extends OperationHandlerAuth<unknown, unknown>, IN, OUT>(handlerReference: OperationHandlerReference<AUTH, IN, OUT>): void;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=OperationExecutionTestRunner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OperationExecutionTestRunner.d.ts","sourceRoot":"","sources":["../../../src/connector/operation/OperationExecutionTestRunner.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,oBAAoB,EACpB,yBAAyB,EACzB,MAAM,sDAAsD,CAAC;AAM9D,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAExE,qBAAa,4BAA4B;IACxC,OAAO,CAAC,yBAAyB,CAA4B;gBAEjD,yBAAyB,EAAE,yBAAyB;IAIhE,UAAU,CAAC,IAAI,SAAS,oBAAoB,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,EAAE,EAAE,GAAG,EACtE,gBAAgB,EAAE,yBAAyB,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC,GACxD,IAAI;CA+BP"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.OperationExecutionTestRunner = void 0;
|
|
27
|
+
const OperationHandlerTest_1 = require("@trayio/cdk-dsl/connector/operation/OperationHandlerTest");
|
|
28
|
+
const O = __importStar(require("fp-ts/Option"));
|
|
29
|
+
const E = __importStar(require("fp-ts/Either"));
|
|
30
|
+
const function_1 = require("fp-ts/function");
|
|
31
|
+
const OperationExecutionTest_1 = require("./OperationExecutionTest");
|
|
32
|
+
class OperationExecutionTestRunner {
|
|
33
|
+
constructor(operationExecutionGateway) {
|
|
34
|
+
this.operationExecutionGateway = operationExecutionGateway;
|
|
35
|
+
}
|
|
36
|
+
runTestFor(handlerReference) {
|
|
37
|
+
const executionE = (0, function_1.pipe)(this.operationExecutionGateway.lookup(handlerReference, true), E.fromOption(() => new Error(`OperationHandler for ${handlerReference.name} not found`)));
|
|
38
|
+
const executionTestE = (0, function_1.pipe)(OperationHandlerTest_1.OperationHandlerTestRegistry.resolve(handlerReference), O.map((handlerTest) => new OperationExecutionTest_1.OperationExecutionTest(handlerTest, this.operationExecutionGateway.operationHandlerInvocationFactory)), E.fromOption(() => new Error(`OperationHandlerTest for ${handlerReference.name} not found`)));
|
|
39
|
+
(0, function_1.pipe)(executionTestE, E.bindTo('executionTest'), E.bind('execution', () => executionE), E.map(({ executionTest, execution }) => executionTest.test(execution)));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.OperationExecutionTestRunner = OperationExecutionTestRunner;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { OperationHandlerAuth, OperationHandlerContext, OperationHandlerResult } from '@trayio/cdk-dsl/connector/operation/OperationHandler';
|
|
2
|
+
import { OperationHandlerValidation } from '@trayio/cdk-dsl/connector/operation/OperationHandlerValidation';
|
|
3
|
+
import { OperationExecution } from './OperationExecution';
|
|
4
|
+
export declare class OperationExecutionValidation<AUTH extends OperationHandlerAuth<unknown, unknown>, IN, OUT> implements OperationExecution<AUTH, IN, OUT> {
|
|
5
|
+
private handlerValidation;
|
|
6
|
+
private execution;
|
|
7
|
+
constructor(handlerValidation: OperationHandlerValidation<AUTH, IN, OUT>, execution: OperationExecution<AUTH, IN, OUT>);
|
|
8
|
+
execute(ctx: OperationHandlerContext<AUTH>, input: IN): Promise<OperationHandlerResult<OUT>>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=OperationExecutionValidation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OperationExecutionValidation.d.ts","sourceRoot":"","sources":["../../../src/connector/operation/OperationExecutionValidation.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,oBAAoB,EACpB,uBAAuB,EACvB,sBAAsB,EAEtB,MAAM,sDAAsD,CAAC;AAC9D,OAAO,EAAE,0BAA0B,EAAE,MAAM,gEAAgE,CAAC;AAC5G,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,qBAAa,4BAA4B,CACxC,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,CAA4C;IACrE,OAAO,CAAC,SAAS,CAAoC;gBAGpD,iBAAiB,EAAE,0BAA0B,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC,EAC5D,SAAS,EAAE,kBAAkB,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC;IAMvC,OAAO,CACZ,GAAG,EAAE,uBAAuB,CAAC,IAAI,CAAC,EAClC,KAAK,EAAE,EAAE,GACP,OAAO,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAC;CA0CvC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.OperationExecutionValidation = void 0;
|
|
13
|
+
const OperationHandler_1 = require("@trayio/cdk-dsl/connector/operation/OperationHandler");
|
|
14
|
+
class OperationExecutionValidation {
|
|
15
|
+
constructor(handlerValidation, execution) {
|
|
16
|
+
this.handlerValidation = handlerValidation;
|
|
17
|
+
this.execution = execution;
|
|
18
|
+
}
|
|
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
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.OperationExecutionValidation = OperationExecutionValidation;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as O from 'fp-ts/Option';
|
|
2
|
+
import { OperationHandlerAuth } from '@trayio/cdk-dsl/connector/operation/OperationHandler';
|
|
3
|
+
import { OperationHandlerValidation } from '@trayio/cdk-dsl/connector/operation/OperationHandlerValidation';
|
|
4
|
+
import { OperationExecution } from './OperationExecution';
|
|
5
|
+
export declare class OperationExecutionValidationFactory {
|
|
6
|
+
decorateExecution<AUTH extends OperationHandlerAuth<unknown, unknown>, IN, OUT>(execution: OperationExecution<AUTH, IN, OUT>, handlerValidationOpt: O.Option<OperationHandlerValidation<AUTH, IN, OUT>>): OperationExecution<AUTH, IN, OUT>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=OperationExecutionValidationFactory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OperationExecutionValidationFactory.d.ts","sourceRoot":"","sources":["../../../src/connector/operation/OperationExecutionValidationFactory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAElC,OAAO,EAAE,oBAAoB,EAAE,MAAM,sDAAsD,CAAC;AAC5F,OAAO,EAAE,0BAA0B,EAAE,MAAM,gEAAgE,CAAC;AAC5G,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG1D,qBAAa,mCAAmC;IAC/C,iBAAiB,CAChB,IAAI,SAAS,oBAAoB,CAAC,OAAO,EAAE,OAAO,CAAC,EACnD,EAAE,EACF,GAAG,EAEH,SAAS,EAAE,kBAAkB,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC,EAC5C,oBAAoB,EAAE,CAAC,CAAC,MAAM,CAAC,0BAA0B,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC,CAAC,GACvE,kBAAkB,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC;CAUpC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.OperationExecutionValidationFactory = void 0;
|
|
27
|
+
const O = __importStar(require("fp-ts/Option"));
|
|
28
|
+
const function_1 = require("fp-ts/function");
|
|
29
|
+
const OperationExecutionValidation_1 = require("./OperationExecutionValidation");
|
|
30
|
+
class OperationExecutionValidationFactory {
|
|
31
|
+
decorateExecution(execution, handlerValidationOpt) {
|
|
32
|
+
return (0, function_1.pipe)(handlerValidationOpt, O.map((handlerValidation) => new OperationExecutionValidation_1.OperationExecutionValidation(handlerValidation, execution)), O.getOrElse(() => execution));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.OperationExecutionValidationFactory = OperationExecutionValidationFactory;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { OperationHandlerAuth, OperationHandlerContext } from '@trayio/cdk-dsl/connector/operation/OperationHandler';
|
|
2
|
+
import { OperationHandlerInvocation } from '@trayio/cdk-dsl/connector/operation/OperationHandlerInvocation';
|
|
3
|
+
export type OperationHandlerInvocationFactory = <AUTH extends OperationHandlerAuth<unknown, unknown>>(ctx: OperationHandlerContext<AUTH>) => OperationHandlerInvocation<AUTH>;
|
|
4
|
+
//# sourceMappingURL=OperationHandlerInvocationFactory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OperationHandlerInvocationFactory.d.ts","sourceRoot":"","sources":["../../../src/connector/operation/OperationHandlerInvocationFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,oBAAoB,EACpB,uBAAuB,EACvB,MAAM,sDAAsD,CAAC;AAC9D,OAAO,EAAE,0BAA0B,EAAE,MAAM,gEAAgE,CAAC;AAE5G,MAAM,MAAM,iCAAiC,GAAG,CAC/C,IAAI,SAAS,oBAAoB,CAAC,OAAO,EAAE,OAAO,CAAC,EAEnD,GAAG,EAAE,uBAAuB,CAAC,IAAI,CAAC,KAC9B,0BAA0B,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OperationHandlerTestRunner.d.ts","sourceRoot":"","sources":["../../../src/connector/operation/OperationHandlerTestRunner.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const OperationHandlerTest_1 = require("@trayio/cdk-dsl/connector/operation/OperationHandlerTest");
|
|
4
|
+
const AxiosHttpClient_1 = require("@trayio/axios/http/AxiosHttpClient");
|
|
5
|
+
const NodeFsFileStorage_1 = require("@trayio/commons/file/NodeFsFileStorage");
|
|
6
|
+
const OperationExecutionGateway_1 = require("./OperationExecutionGateway");
|
|
7
|
+
const OperationExecutionTestRunner_1 = require("./OperationExecutionTestRunner");
|
|
8
|
+
const executionGateway = new OperationExecutionGateway_1.OperationExecutionGateway(new AxiosHttpClient_1.AxiosHttpClient(), new NodeFsFileStorage_1.NodeFsFileStorage());
|
|
9
|
+
const testRunner = new OperationExecutionTestRunner_1.OperationExecutionTestRunner(executionGateway);
|
|
10
|
+
OperationHandlerTest_1.OperationHandlerTestRegistry.onRegistration((handlerReference) => {
|
|
11
|
+
testRunner.runTestFor(handlerReference);
|
|
12
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@trayio/cdk-runtime",
|
|
3
|
+
"version": "0.0.1-beta",
|
|
4
|
+
"description": "A Runtime that executes connector operations defined using the CDK DSL",
|
|
5
|
+
"exports": {
|
|
6
|
+
"./*": "./dist/*.js"
|
|
7
|
+
},
|
|
8
|
+
"author": "Tray.io",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=18.x"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@trayio/axios": "0.0.1-beta",
|
|
18
|
+
"@trayio/cdk-dsl": "0.0.1-beta",
|
|
19
|
+
"@trayio/express": "0.0.1-beta",
|
|
20
|
+
"@trayio/winston": "0.0.1-beta",
|
|
21
|
+
"mime": "3.0.0",
|
|
22
|
+
"uuid": "9.0.0"
|
|
23
|
+
},
|
|
24
|
+
"typesVersions": {
|
|
25
|
+
"*": {
|
|
26
|
+
"*": [
|
|
27
|
+
"*",
|
|
28
|
+
"dist/*"
|
|
29
|
+
]
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"/dist"
|
|
34
|
+
]
|
|
35
|
+
}
|