@trayio/cdk-build 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/dist/connector/ConnectorBuilder.d.ts +9 -0
- package/dist/connector/ConnectorBuilder.d.ts.map +1 -0
- package/dist/connector/ConnectorBuilder.js +81 -0
- package/dist/connector/operation/ConnectorOperationSchemaGenerator.d.ts +6 -0
- package/dist/connector/operation/ConnectorOperationSchemaGenerator.d.ts.map +1 -0
- package/dist/connector/operation/ConnectorOperationSchemaGenerator.js +60 -0
- package/package.json +33 -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.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as TE from 'fp-ts/TaskEither';
|
|
2
|
+
export declare class ConnectorBuilder {
|
|
3
|
+
private operationSchemaGenerator;
|
|
4
|
+
buildConnector(cdkProjectPath: string): TE.TaskEither<Error, undefined>;
|
|
5
|
+
generateSchemas(cdkProjectPath: string): TE.TaskEither<Error, undefined>;
|
|
6
|
+
getOperations(cdkProjectPath: string): Array<string>;
|
|
7
|
+
private generatePackage;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=ConnectorBuilder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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;CA+CvB"}
|
|
@@ -0,0 +1,81 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.ConnectorBuilder = void 0;
|
|
30
|
+
const TE = __importStar(require("fp-ts/TaskEither"));
|
|
31
|
+
const function_1 = require("fp-ts/function");
|
|
32
|
+
const Array_1 = require("fp-ts/Array");
|
|
33
|
+
const pathLib = __importStar(require("path"));
|
|
34
|
+
const fse = __importStar(require("fs-extra"));
|
|
35
|
+
const adm_zip_1 = __importDefault(require("adm-zip"));
|
|
36
|
+
const ConnectorOperationSchemaGenerator_1 = require("./operation/ConnectorOperationSchemaGenerator");
|
|
37
|
+
class ConnectorBuilder {
|
|
38
|
+
constructor() {
|
|
39
|
+
this.operationSchemaGenerator = new ConnectorOperationSchemaGenerator_1.ConnectorOperationSchemaGenerator();
|
|
40
|
+
}
|
|
41
|
+
buildConnector(cdkProjectPath) {
|
|
42
|
+
return (0, function_1.pipe)(this.generateSchemas(cdkProjectPath), TE.chain(() => this.generatePackage(cdkProjectPath)));
|
|
43
|
+
}
|
|
44
|
+
generateSchemas(cdkProjectPath) {
|
|
45
|
+
const operations = this.getOperations(cdkProjectPath);
|
|
46
|
+
return (0, function_1.pipe)((0, Array_1.traverse)(TE.ApplicativeSeq)((operation) => {
|
|
47
|
+
const operationPath = pathLib.join(cdkProjectPath, 'src', operation);
|
|
48
|
+
return this.operationSchemaGenerator.generateSchemasForOperation(operationPath, operation);
|
|
49
|
+
})(operations), TE.map(() => undefined));
|
|
50
|
+
}
|
|
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);
|
|
58
|
+
}
|
|
59
|
+
// TODO: better error handling
|
|
60
|
+
generatePackage(cdkProjectPath) {
|
|
61
|
+
const connectorPackagePath = pathLib.join(cdkProjectPath, 'dist', 'connector.zip');
|
|
62
|
+
const connectorJsonPath = pathLib.join(cdkProjectPath, 'connector.json');
|
|
63
|
+
const connectorJson = fse.readJsonSync(connectorJsonPath);
|
|
64
|
+
const connectorPackage = new adm_zip_1.default();
|
|
65
|
+
connectorPackage.addLocalFolder(pathLib.join(cdkProjectPath, 'src'), pathLib.join(connectorJson.name, 'src'));
|
|
66
|
+
const entries = connectorPackage.getEntries();
|
|
67
|
+
// exclude all the ctx.json files from the zip as it can contain sensitive information
|
|
68
|
+
for (const entry of entries) {
|
|
69
|
+
if (entry.entryName.endsWith('.ctx.json')) {
|
|
70
|
+
connectorPackage.deleteFile(entry.entryName);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
connectorPackage.addLocalFile(pathLib.join(cdkProjectPath, 'package.json'), connectorJson.name);
|
|
74
|
+
connectorPackage.addLocalFile(pathLib.join(cdkProjectPath, 'tsconfig.json'), connectorJson.name);
|
|
75
|
+
connectorPackage.addLocalFile(pathLib.join(cdkProjectPath, 'jest.config.js'), connectorJson.name);
|
|
76
|
+
connectorPackage.addLocalFile(pathLib.join(cdkProjectPath, 'connector.json'), connectorJson.name);
|
|
77
|
+
connectorPackage.writeZip(connectorPackagePath);
|
|
78
|
+
return TE.right(undefined);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.ConnectorBuilder = ConnectorBuilder;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as TE from 'fp-ts/TaskEither';
|
|
2
|
+
export declare class ConnectorOperationSchemaGenerator {
|
|
3
|
+
generateSchemasForOperation(operationPath: string, operationName: string): TE.TaskEither<Error, undefined>;
|
|
4
|
+
private generateSchema;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=ConnectorOperationSchemaGenerator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConnectorOperationSchemaGenerator.d.ts","sourceRoot":"","sources":["../../../src/connector/operation/ConnectorOperationSchemaGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AASvC,qBAAa,iCAAiC;IAC7C,2BAA2B,CAC1B,aAAa,EAAE,MAAM,EACrB,aAAa,EAAE,MAAM,GACnB,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC;IAiElC,OAAO,CAAC,cAAc;CAYtB"}
|
|
@@ -0,0 +1,60 @@
|
|
|
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.ConnectorOperationSchemaGenerator = void 0;
|
|
27
|
+
const TE = __importStar(require("fp-ts/TaskEither"));
|
|
28
|
+
const function_1 = require("fp-ts/function");
|
|
29
|
+
const pathLib = __importStar(require("path"));
|
|
30
|
+
const StringExtensions_1 = require("@trayio/commons/string/StringExtensions");
|
|
31
|
+
const TJSTraySchemaGenerator_1 = require("@trayio/tray-schema/schema/TJSTraySchemaGenerator");
|
|
32
|
+
const fse = __importStar(require("fs-extra"));
|
|
33
|
+
const DynamicType_1 = require("@trayio/commons/dynamictype/DynamicType");
|
|
34
|
+
class ConnectorOperationSchemaGenerator {
|
|
35
|
+
generateSchemasForOperation(operationPath, operationName) {
|
|
36
|
+
const inputFilePath = pathLib.join(operationPath, 'input.ts');
|
|
37
|
+
const outputFilePath = pathLib.join(operationPath, 'output.ts');
|
|
38
|
+
const responseFilePath = pathLib.join(operationPath, 'response.ts');
|
|
39
|
+
const inputTypeName = `${StringExtensions_1.StringExtensions.pascalCase(operationName)}Input`;
|
|
40
|
+
const outputTypeName = `${StringExtensions_1.StringExtensions.pascalCase(operationName)}Output`;
|
|
41
|
+
const responseTypeName = `${StringExtensions_1.StringExtensions.pascalCase(operationName)}Response`;
|
|
42
|
+
const inputSchemaFilePath = pathLib.join(operationPath, 'input.json');
|
|
43
|
+
const outputSchemaFilePath = pathLib.join(operationPath, 'output.json');
|
|
44
|
+
const responseSchemaFilePath = pathLib.join(operationPath, 'response.json');
|
|
45
|
+
return (0, function_1.pipe)(TE.tryCatch(() => fse.exists(inputFilePath), (reason) => new Error(String(reason))), TE.chain(() => TE.tryCatch(() => fse.exists(outputFilePath), (reason) => new Error(String(reason)))), TE.chain(() => {
|
|
46
|
+
console.log(`Generating types for operation: ${operationName}`); // TODO: Remove this and use a logger
|
|
47
|
+
return this.generateSchema(inputFilePath, inputTypeName, inputSchemaFilePath);
|
|
48
|
+
}), TE.chain(() => this.generateSchema(outputFilePath, outputTypeName, outputSchemaFilePath)), TE.chain(() => (0, function_1.pipe)(TE.tryCatch(() => fse.exists(responseFilePath), (reason) => new Error(String(reason))), TE.map((exists) => {
|
|
49
|
+
if (exists) {
|
|
50
|
+
return this.generateSchema(responseFilePath, responseTypeName, responseSchemaFilePath);
|
|
51
|
+
}
|
|
52
|
+
return undefined;
|
|
53
|
+
}))), TE.chain(() => TE.right(undefined)));
|
|
54
|
+
}
|
|
55
|
+
generateSchema(filePath, typeName, schemaFilePath) {
|
|
56
|
+
const schemaTransformer = new TJSTraySchemaGenerator_1.TJSTraySchemaGenerator();
|
|
57
|
+
return (0, function_1.pipe)(TE.fromEither(schemaTransformer.generateFromType(typeName, filePath)), TE.chain((schema) => DynamicType_1.DynamicType.writeToFileAsync(schemaFilePath, schema)));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.ConnectorOperationSchemaGenerator = ConnectorOperationSchemaGenerator;
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@trayio/cdk-build",
|
|
3
|
+
"version": "0.0.1-beta",
|
|
4
|
+
"description": "Build utilities for CDK projects",
|
|
5
|
+
"exports": {
|
|
6
|
+
"./*": "./dist/*.js"
|
|
7
|
+
},
|
|
8
|
+
"author": "Tray.io",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=18.x"
|
|
12
|
+
},
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@trayio/commons": "0.0.1-beta",
|
|
18
|
+
"@trayio/tray-schema": "0.0.1-beta",
|
|
19
|
+
"adm-zip": "0.5.10"
|
|
20
|
+
},
|
|
21
|
+
"typesVersions": {
|
|
22
|
+
"*": {
|
|
23
|
+
"*": [
|
|
24
|
+
"*",
|
|
25
|
+
"dist/*"
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"/dist"
|
|
31
|
+
],
|
|
32
|
+
"stableVersion": "2.15.0"
|
|
33
|
+
}
|