@trayio/cdk-build 1.2.0 → 1.4.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,10 +1,12 @@
|
|
|
1
1
|
import * as TE from 'fp-ts/TaskEither';
|
|
2
2
|
export declare class ConnectorBuilder {
|
|
3
3
|
private operationSchemaGenerator;
|
|
4
|
+
private legacySchemaConverter;
|
|
4
5
|
buildConnector(cdkProjectPath: string): TE.TaskEither<Error, undefined>;
|
|
5
6
|
private generateSchemas;
|
|
6
7
|
private generateConnectorsJson;
|
|
7
8
|
private generatePackage;
|
|
9
|
+
private deleteSchemas;
|
|
8
10
|
private getOperations;
|
|
9
11
|
}
|
|
10
12
|
//# 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;AAUvC,qBAAa,gBAAgB;IAC5B,OAAO,CAAC,wBAAwB,CAA2C;IAC3E,OAAO,CAAC,qBAAqB,CAAmC;IAEhE,cAAc,CAAC,cAAc,EAAE,MAAM,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC;IASvE,OAAO,CAAC,eAAe;IAiBvB,OAAO,CAAC,sBAAsB;IAmE9B,OAAO,CAAC,eAAe;IAoDvB,OAAO,CAAC,aAAa;IAsCrB,OAAO,CAAC,aAAa;CAUrB"}
|
|
@@ -34,13 +34,15 @@ const Array_1 = require("fp-ts/Array");
|
|
|
34
34
|
const pathLib = __importStar(require("path"));
|
|
35
35
|
const fse = __importStar(require("fs-extra"));
|
|
36
36
|
const adm_zip_1 = __importDefault(require("adm-zip"));
|
|
37
|
+
const LegacyTraySchemaConverter_1 = require("@trayio/tray-schema/schema/LegacyTraySchemaConverter");
|
|
37
38
|
const ConnectorOperationSchemaGenerator_1 = require("./operation/ConnectorOperationSchemaGenerator");
|
|
38
39
|
class ConnectorBuilder {
|
|
39
40
|
constructor() {
|
|
40
41
|
this.operationSchemaGenerator = new ConnectorOperationSchemaGenerator_1.ConnectorOperationSchemaGenerator();
|
|
42
|
+
this.legacySchemaConverter = new LegacyTraySchemaConverter_1.LegacyTraySchemaConverter();
|
|
41
43
|
}
|
|
42
44
|
buildConnector(cdkProjectPath) {
|
|
43
|
-
return (0, function_1.pipe)(this.generateSchemas(cdkProjectPath), TE.chain(() => this.generateConnectorsJson(cdkProjectPath)), TE.chain(() => this.generatePackage(cdkProjectPath)));
|
|
45
|
+
return (0, function_1.pipe)(this.generateSchemas(cdkProjectPath), TE.chain(() => this.generateConnectorsJson(cdkProjectPath)), TE.chain(() => this.generatePackage(cdkProjectPath)), TE.chain(() => this.deleteSchemas(cdkProjectPath)));
|
|
44
46
|
}
|
|
45
47
|
generateSchemas(cdkProjectPath) {
|
|
46
48
|
const operations = this.getOperations(cdkProjectPath);
|
|
@@ -53,7 +55,6 @@ class ConnectorBuilder {
|
|
|
53
55
|
generateConnectorsJson(cdkProjectPath) {
|
|
54
56
|
const operations = this.getOperations(cdkProjectPath);
|
|
55
57
|
const operationEntries = operations.map((operation) => {
|
|
56
|
-
console.log(`Generating schemas for operation ${operation}`); // TODO: Remove this and use a logger
|
|
57
58
|
const operationPath = pathLib.join(cdkProjectPath, 'src', operation);
|
|
58
59
|
const operationJsonPath = pathLib.join(operationPath, 'operation.json');
|
|
59
60
|
const inputJsonPath = pathLib.join(operationPath, 'input.json');
|
|
@@ -61,11 +62,11 @@ class ConnectorBuilder {
|
|
|
61
62
|
const responseJsonPath = pathLib.join(operationPath, 'response.json');
|
|
62
63
|
// TODO: use DynamicType and safecasts
|
|
63
64
|
const operationJson = fse.readJsonSync(operationJsonPath);
|
|
64
|
-
const inputJson = fse.readJsonSync(inputJsonPath);
|
|
65
|
-
const outputJson = fse.readJsonSync(outputJsonPath);
|
|
65
|
+
const inputJson = this.legacySchemaConverter.convertToLegacySchema(fse.readJsonSync(inputJsonPath));
|
|
66
|
+
const outputJson = this.legacySchemaConverter.convertToLegacySchema(fse.readJsonSync(outputJsonPath));
|
|
66
67
|
const responseJsonOpt = (0, function_1.pipe)(O.fromPredicate((path) => fse.existsSync(path))(responseJsonPath), O.map((path) => fse.readJSONSync(path)));
|
|
67
68
|
const completeOperationJson = Object.assign(Object.assign({}, operationJson), { name: operation, input_schema: inputJson, output_schema: outputJson });
|
|
68
|
-
return (0, function_1.pipe)(responseJsonOpt, O.map((responseJson) => (Object.assign(Object.assign({}, completeOperationJson), { reply_schema: responseJson }))), O.getOrElse(() => completeOperationJson));
|
|
69
|
+
return (0, function_1.pipe)(responseJsonOpt, O.map((responseJson) => (Object.assign(Object.assign({}, completeOperationJson), { reply_schema: this.legacySchemaConverter.convertToLegacySchema(responseJson) }))), O.getOrElse(() => completeOperationJson));
|
|
69
70
|
});
|
|
70
71
|
const connectorJsonPath = pathLib.join(cdkProjectPath, 'connector.json');
|
|
71
72
|
const connectorJson = fse.readJsonSync(connectorJsonPath);
|
|
@@ -83,6 +84,13 @@ class ConnectorBuilder {
|
|
|
83
84
|
const connectorJson = fse.readJsonSync(connectorJsonPath);
|
|
84
85
|
const connectorPackage = new adm_zip_1.default();
|
|
85
86
|
connectorPackage.addLocalFolder(pathLib.join(cdkProjectPath, 'src'), pathLib.join(connectorJson.name, 'src'));
|
|
87
|
+
const entries = connectorPackage.getEntries();
|
|
88
|
+
// exclude all the ctx.json files from the zip as it can contain sensitive information
|
|
89
|
+
for (const entry of entries) {
|
|
90
|
+
if (entry.entryName.endsWith('.ctx.json')) {
|
|
91
|
+
connectorPackage.deleteFile(entry.entryName);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
86
94
|
connectorPackage.addLocalFile(pathLib.join(cdkProjectPath, 'package.json'), connectorJson.name);
|
|
87
95
|
connectorPackage.addLocalFile(pathLib.join(cdkProjectPath, 'tsconfig.json'), connectorJson.name);
|
|
88
96
|
connectorPackage.addLocalFile(pathLib.join(cdkProjectPath, 'jest.config.js'), connectorJson.name);
|
|
@@ -91,6 +99,23 @@ class ConnectorBuilder {
|
|
|
91
99
|
connectorPackage.writeZip(connectorPackagePath);
|
|
92
100
|
return TE.right(undefined);
|
|
93
101
|
}
|
|
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
|
+
}
|
|
94
119
|
getOperations(cdkProjectPath) {
|
|
95
120
|
const srcPath = pathLib.join(cdkProjectPath, 'src');
|
|
96
121
|
const srcEntries = fse.readdirSync(srcPath, { withFileTypes: true });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trayio/cdk-build",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.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.4.0",
|
|
18
|
+
"@trayio/tray-schema": "1.4.0",
|
|
19
19
|
"adm-zip": "0.5.10"
|
|
20
20
|
},
|
|
21
21
|
"typesVersions": {
|