UNPKG

@prismatic-io/spectral

Version:

Utility library for building Prismatic connectors and code-native integrations

107 lines (106 loc) 4.66 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createConnections = void 0; const path_1 = __importDefault(require("path")); const createImport_1 = require("../utils/createImport"); const createTemplate_1 = require("../utils/createTemplate"); const createTypeInterface_1 = require("../utils/createTypeInterface"); const getImports_1 = require("./getImports"); const getInputs_1 = require("./getInputs"); const helpers_1 = require("./helpers"); const createConnections = (_a) => __awaiter(void 0, [_a], void 0, function* ({ component, dryRun, verbose, sourceDir, destinationDir, reusableConnectionStableKeys = [], }) { var _b, _c; if (verbose) { console.info("Creating connections..."); } const connectionIndex = yield renderConnectionsIndex({ imports: ((_b = component.connections) !== null && _b !== void 0 ? _b : []).map((connection) => { return { import: (0, createImport_1.createImport)(connection.key), }; }), dryRun, verbose, sourceDir, destinationDir, reusableConnectionStableKeys, componentKey: component.key, }); const connections = yield Promise.all(((_c = component.connections) !== null && _c !== void 0 ? _c : []).map((connection) => __awaiter(void 0, void 0, void 0, function* () { const inputs = (0, getInputs_1.getInputs)({ inputs: connection.inputs, }); const imports = (0, getImports_1.getImports)({ inputs, additionalImports: { "@prismatic-io/spectral/dist/types": ["ConfigVarExpression", "ConfigVarVisibility"], }, }); const onPremAvailable = connection.inputs.some((input) => input.onPremControlled || input.onPremiseControlled); return yield renderConnection({ connection: { typeInterface: (0, createTypeInterface_1.createTypeInterface)(connection.key), import: (0, createImport_1.createImport)(connection.key), key: connection.key, label: connection.label, comments: connection.comments, inputs, onPremAvailable, componentKey: component.key, componentIsPublic: Boolean(component.public), }, imports, dryRun, verbose, sourceDir, destinationDir, }); }))); if (verbose) { console.info(""); } return Promise.resolve({ connectionIndex, connections, }); }); exports.createConnections = createConnections; const renderConnectionsIndex = (_a) => __awaiter(void 0, [_a], void 0, function* ({ imports, dryRun, verbose, sourceDir, destinationDir, reusableConnectionStableKeys = [], componentKey, }) { return yield (0, createTemplate_1.createTemplate)({ source: path_1.default.join(sourceDir, "connections", "index.ts.ejs"), destination: path_1.default.join(destinationDir, "connections", "index.ts"), data: { imports, reusableConnectionStableKeys, componentKey, helpers: helpers_1.helpers, }, dryRun, verbose, }); }); const renderConnection = (_a) => __awaiter(void 0, [_a], void 0, function* ({ connection, dryRun, imports, verbose, sourceDir, destinationDir, }) { return yield (0, createTemplate_1.createTemplate)({ source: path_1.default.join(sourceDir, "connections", "connection.ts.ejs"), destination: path_1.default.join(destinationDir, "connections", `${connection.import}.ts`), data: { connection, helpers: helpers_1.helpers, imports, }, dryRun, verbose, }); });