UNPKG

@geek-fun/serverlessinsight

Version:

Full life cycle cross providers serverless application management for your fast-growing business.

96 lines (95 loc) 3.98 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.resolveTables = void 0; const rosRos = __importStar(require("@alicloud/ros-cdk-ros")); const lodash_1 = require("lodash"); const common_1 = require("../../common"); const tableEngineMap = new Map([ [ "TABLE_STORE_C" /* TableEnum.TABLE_STORE_C */, { clusterType: 'HYBRID', }, ], [ "TABLE_STORE_H" /* TableEnum.TABLE_STORE_H */, { clusterType: 'SSD', }, ], ]); const resolveTables = (scope, tables, tags, context) => { if ((0, lodash_1.isEmpty)(tables)) { return undefined; } tables.forEach((tableDomain) => { const { collection, throughput, attributes, keySchema, network } = tableDomain; const primaryKey = keySchema.map((key) => { const name = (0, common_1.calcRefs)(key.name, context); const type = attributes.find((attribute) => (0, common_1.calcRefs)(attribute.name, context) === name)?.type || 'STRING'; return { name, type: (0, common_1.calcRefs)(type, context) }; }); const columns = attributes ?.filter(({ name }) => !primaryKey.find((pk) => pk.name === (0, common_1.calcRefs)(name, context))) .map((attribute) => ({ name: (0, common_1.calcRefs)(attribute.name, context), type: (0, common_1.calcRefs)(attribute.type, context), })) || []; const clusterType = tableEngineMap.get((0, common_1.calcRefs)(tableDomain.type, context))?.clusterType; new rosRos.RosCustomResource(scope, tableDomain.key, { serviceToken: `acs:fc:${context.region}:${context.accountId}:functions/${common_1.SI_BOOTSTRAP_FC_PREFIX}-${context.accountId}-${context.region}`, timeout: 600, parameters: { resource: (0, common_1.calcRefs)(tableDomain.type, context), instanceName: (0, common_1.calcRefs)(collection, context), tableName: (0, common_1.calcRefs)(tableDomain.name, context), primaryKey, columns, clusterType, network, reservedThroughput: (0, common_1.calcRefs)(throughput?.reserved, context), tags, credentials: { accessKeyId: context.accessKeyId, accessKeySecret: context.accessKeySecret, securityToken: context.securityToken, }, }, }, true); }); }; exports.resolveTables = resolveTables;