@trayio/cdk-build 1.6.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import * as TE from 'fp-ts/TaskEither';
|
|
2
2
|
export declare class ConnectorBuilder {
|
|
3
3
|
private operationSchemaGenerator;
|
|
4
|
-
private legacySchemaConverter;
|
|
5
4
|
buildConnector(cdkProjectPath: string): TE.TaskEither<Error, undefined>;
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
generateSchemas(cdkProjectPath: string): TE.TaskEither<Error, undefined>;
|
|
6
|
+
getOperations(cdkProjectPath: string): Array<string>;
|
|
8
7
|
private generatePackage;
|
|
9
|
-
private deleteSchemas;
|
|
10
|
-
private getOperations;
|
|
11
8
|
}
|
|
12
9
|
//# sourceMappingURL=ConnectorBuilder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConnectorBuilder.d.ts","sourceRoot":"","sources":["../../src/connector/ConnectorBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"ConnectorBuilder.d.ts","sourceRoot":"","sources":["../../src/connector/ConnectorBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAQvC,qBAAa,gBAAgB;IAC5B,OAAO,CAAC,wBAAwB,CAA2C;IAE3E,cAAc,CAAC,cAAc,EAAE,MAAM,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC;IAOvE,eAAe,CAAC,cAAc,EAAE,MAAM,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC;IAcxE,aAAa,CAAC,cAAc,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;IAYpD,OAAO,CAAC,eAAe;CAmDvB"}
|
|
@@ -28,21 +28,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.ConnectorBuilder = void 0;
|
|
30
30
|
const TE = __importStar(require("fp-ts/TaskEither"));
|
|
31
|
-
const O = __importStar(require("fp-ts/Option"));
|
|
32
31
|
const function_1 = require("fp-ts/function");
|
|
33
32
|
const Array_1 = require("fp-ts/Array");
|
|
34
33
|
const pathLib = __importStar(require("path"));
|
|
35
34
|
const fse = __importStar(require("fs-extra"));
|
|
36
35
|
const adm_zip_1 = __importDefault(require("adm-zip"));
|
|
37
|
-
const LegacyTraySchemaConverter_1 = require("@trayio/tray-schema/schema/LegacyTraySchemaConverter");
|
|
38
36
|
const ConnectorOperationSchemaGenerator_1 = require("./operation/ConnectorOperationSchemaGenerator");
|
|
39
37
|
class ConnectorBuilder {
|
|
40
38
|
constructor() {
|
|
41
39
|
this.operationSchemaGenerator = new ConnectorOperationSchemaGenerator_1.ConnectorOperationSchemaGenerator();
|
|
42
|
-
this.legacySchemaConverter = new LegacyTraySchemaConverter_1.LegacyTraySchemaConverter();
|
|
43
40
|
}
|
|
44
41
|
buildConnector(cdkProjectPath) {
|
|
45
|
-
return (0, function_1.pipe)(this.generateSchemas(cdkProjectPath), TE.chain(() => this.
|
|
42
|
+
return (0, function_1.pipe)(this.generateSchemas(cdkProjectPath), TE.chain(() => this.generatePackage(cdkProjectPath)));
|
|
46
43
|
}
|
|
47
44
|
generateSchemas(cdkProjectPath) {
|
|
48
45
|
const operations = this.getOperations(cdkProjectPath);
|
|
@@ -51,31 +48,13 @@ class ConnectorBuilder {
|
|
|
51
48
|
return this.operationSchemaGenerator.generateSchemasForOperation(operationPath, operation);
|
|
52
49
|
})(operations), TE.map(() => undefined));
|
|
53
50
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const outputJsonPath = pathLib.join(operationPath, 'output.json');
|
|
62
|
-
const responseJsonPath = pathLib.join(operationPath, 'response.json');
|
|
63
|
-
// TODO: use DynamicType and safecasts
|
|
64
|
-
const operationJson = fse.readJsonSync(operationJsonPath);
|
|
65
|
-
const inputJson = this.legacySchemaConverter.convertToLegacySchema(fse.readJsonSync(inputJsonPath));
|
|
66
|
-
const outputJson = this.legacySchemaConverter.convertToLegacySchema(fse.readJsonSync(outputJsonPath));
|
|
67
|
-
const responseJsonOpt = (0, function_1.pipe)(O.fromPredicate((path) => fse.existsSync(path))(responseJsonPath), O.map((path) => fse.readJSONSync(path)));
|
|
68
|
-
const completeOperationJson = Object.assign(Object.assign({}, operationJson), { name: operation, input_schema: inputJson, output_schema: outputJson });
|
|
69
|
-
return (0, function_1.pipe)(responseJsonOpt, O.map((responseJson) => (Object.assign(Object.assign({}, completeOperationJson), { reply_schema: this.legacySchemaConverter.convertToLegacySchema(responseJson) }))), O.getOrElse(() => completeOperationJson));
|
|
70
|
-
});
|
|
71
|
-
const connectorJsonPath = pathLib.join(cdkProjectPath, 'connector.json');
|
|
72
|
-
const connectorJson = fse.readJsonSync(connectorJsonPath);
|
|
73
|
-
const legacyConnectorsJson = [
|
|
74
|
-
Object.assign(Object.assign({}, connectorJson), { messages: operationEntries }),
|
|
75
|
-
];
|
|
76
|
-
const legacyConnectorsJsonPath = pathLib.join(cdkProjectPath, 'connectors.json');
|
|
77
|
-
fse.writeJSONSync(legacyConnectorsJsonPath, legacyConnectorsJson);
|
|
78
|
-
return TE.right(undefined);
|
|
51
|
+
getOperations(cdkProjectPath) {
|
|
52
|
+
const srcPath = pathLib.join(cdkProjectPath, 'src');
|
|
53
|
+
const srcEntries = fse.readdirSync(srcPath, { withFileTypes: true });
|
|
54
|
+
return srcEntries
|
|
55
|
+
.filter((srcEntry) => srcEntry.isDirectory())
|
|
56
|
+
.filter((srcEntry) => fse.existsSync(pathLib.join(srcPath, srcEntry.name, 'operation.json')))
|
|
57
|
+
.map((srcEntry) => srcEntry.name);
|
|
79
58
|
}
|
|
80
59
|
// TODO: better error handling
|
|
81
60
|
generatePackage(cdkProjectPath) {
|
|
@@ -99,30 +78,5 @@ class ConnectorBuilder {
|
|
|
99
78
|
connectorPackage.writeZip(connectorPackagePath);
|
|
100
79
|
return TE.right(undefined);
|
|
101
80
|
}
|
|
102
|
-
deleteSchemas(cdkProjectPath) {
|
|
103
|
-
const operations = this.getOperations(cdkProjectPath);
|
|
104
|
-
return (0, function_1.pipe)((0, Array_1.traverse)(TE.ApplicativeSeq)((operation) => {
|
|
105
|
-
const operationPath = pathLib.join(cdkProjectPath, 'src', operation);
|
|
106
|
-
const inputJsonPath = pathLib.join(operationPath, 'input.json');
|
|
107
|
-
const outputJsonPath = pathLib.join(operationPath, 'output.json');
|
|
108
|
-
const responseJsonPath = pathLib.join(operationPath, 'response.json');
|
|
109
|
-
const deleteInputJson = TE.tryCatch(() => fse.remove(inputJsonPath), (reason) => new Error(String(reason)));
|
|
110
|
-
const deleteOutputJson = TE.tryCatch(() => fse.remove(outputJsonPath), (reason) => new Error(String(reason)));
|
|
111
|
-
const deleteResponseJson = TE.tryCatch(() => fse.remove(responseJsonPath), (reason) => new Error(String(reason)));
|
|
112
|
-
return (0, function_1.pipe)(TE.sequenceArray([
|
|
113
|
-
deleteInputJson,
|
|
114
|
-
deleteOutputJson,
|
|
115
|
-
deleteResponseJson,
|
|
116
|
-
]), TE.map(() => undefined));
|
|
117
|
-
})(operations), TE.map(() => undefined));
|
|
118
|
-
}
|
|
119
|
-
getOperations(cdkProjectPath) {
|
|
120
|
-
const srcPath = pathLib.join(cdkProjectPath, 'src');
|
|
121
|
-
const srcEntries = fse.readdirSync(srcPath, { withFileTypes: true });
|
|
122
|
-
return srcEntries
|
|
123
|
-
.filter((srcEntry) => srcEntry.isDirectory())
|
|
124
|
-
.filter((srcEntry) => fse.existsSync(pathLib.join(srcPath, srcEntry.name, 'operation.json')))
|
|
125
|
-
.map((srcEntry) => srcEntry.name);
|
|
126
|
-
}
|
|
127
81
|
}
|
|
128
82
|
exports.ConnectorBuilder = ConnectorBuilder;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trayio/cdk-build",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "Build utilities for CDK projects",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./*": "./dist/*.js"
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"access": "public"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@trayio/commons": "1.
|
|
18
|
-
"@trayio/tray-schema": "1.
|
|
17
|
+
"@trayio/commons": "1.8.0",
|
|
18
|
+
"@trayio/tray-schema": "1.8.0",
|
|
19
19
|
"adm-zip": "0.5.10"
|
|
20
20
|
},
|
|
21
21
|
"typesVersions": {
|