UNPKG

@aws-amplify/cli-internal

Version:
482 lines • 30 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.extractTableName = exports.classifyEnvVars = exports.FunctionRenderer = void 0; const typescript_1 = __importDefault(require("typescript")); const amplify_cli_core_1 = require("@aws-amplify/amplify-cli-core"); const ts_1 = require("../../ts"); const kinesis_generator_1 = require("../analytics/kinesis.generator"); const factory = typescript_1.default.factory; class FunctionRenderer { constructor(appId, backendEnvironmentName) { this.appId = appId; this.backendEnvironmentName = backendEnvironmentName; } renderDefineFunction(opts) { const namedImports = { '@aws-amplify/backend': new Set(['defineFunction']) }; const postImportStatements = []; const properties = []; const branchNameStatement = ts_1.TS.createBranchNameDeclaration(); postImportStatements.push(branchNameStatement); properties.push(factory.createPropertyAssignment('entry', factory.createStringLiteral(opts.entry))); if (opts.name) { properties.push(factory.createPropertyAssignment('name', factory.createTemplateExpression(factory.createTemplateHead(`${opts.resourceName}-`), [ factory.createTemplateSpan(factory.createIdentifier('branchName'), factory.createTemplateTail('')), ]))); } if (opts.timeoutSeconds) { properties.push(factory.createPropertyAssignment('timeoutSeconds', factory.createNumericLiteral(opts.timeoutSeconds))); } if (opts.memoryMB) { properties.push(factory.createPropertyAssignment('memoryMB', factory.createNumericLiteral(opts.memoryMB))); } this.renderEnvironment(properties, namedImports, opts); this.renderRuntime(properties, opts.runtime); this.renderSchedule(properties, opts.schedule); return ts_1.TS.renderResourceTsFile({ exportedVariableName: factory.createIdentifier(opts.resourceName), functionCallParameter: factory.createObjectLiteralExpression(properties, true), backendFunctionConstruct: 'defineFunction', additionalImportedBackendIdentifiers: namedImports, postImportStatements, }); } render(opts) { const baseNodes = this.renderDefineFunction(opts); const escapeHatchResult = this.renderApplyEscapeHatches(opts); const additionalImportDeclarations = this.renderCdkImports(escapeHatchResult.additionalImports); const backendTypeImport = this.renderBackendTypeImport(); const analyticsTypeImportDeclarations = this.renderAnalyticsTypeImport(opts); const allNodes = []; let foundFirstNonImport = false; for (const node of baseNodes) { if (!foundFirstNonImport && typescript_1.default.isImportDeclaration(node)) { allNodes.push(node); } else { if (!foundFirstNonImport) { for (const declaration of additionalImportDeclarations) allNodes.push(declaration); allNodes.push(backendTypeImport); if (analyticsTypeImportDeclarations) allNodes.push(analyticsTypeImportDeclarations); foundFirstNonImport = true; } allNodes.push(node); } } if (!foundFirstNonImport) { for (const declaration of additionalImportDeclarations) allNodes.push(declaration); allNodes.push(backendTypeImport); if (analyticsTypeImportDeclarations) allNodes.push(analyticsTypeImportDeclarations); } for (const statement of escapeHatchResult.postExportStatements) { allNodes.push(ts_1.newLineIdentifier); allNodes.push(statement); } return factory.createNodeArray(allNodes); } renderBackendTypeImport() { return ts_1.TS.typeImport('../../backend', 'Backend'); } renderAnalyticsTypeImport(opts) { if (!opts.kinesisConfig) return undefined; const kinesisResourceName = opts.kinesisConfig.resourceName; const className = kinesis_generator_1.AnalyticsKinesisGenerator.className(kinesisResourceName); const importPath = `../../analytics/${kinesis_generator_1.AnalyticsKinesisGenerator.fileName(kinesisResourceName)}`; return ts_1.TS.typeImport(importPath, className); } renderCdkImports(additionalImports) { const declarations = []; for (const [source, identifiers] of Object.entries(additionalImports)) { declarations.push(ts_1.TS.namedImport(source, ...Array.from(identifiers))); } return declarations; } renderApplyEscapeHatches(opts) { var _a; const statements = []; const additionalImports = {}; statements.push(createFunctionNameOverride(opts.resourceName)); for (const hatch of opts.dynamicEnvVars) { statements.push(createAddEnvironmentCall(opts.resourceName, hatch)); } const tableNames = new Set(); for (const hatch of opts.dynamicEnvVars) { if (hatch.name.startsWith('API_') && hatch.name.includes('TABLE_')) { const tableName = extractTableName(hatch.name); if (tableName) tableNames.add(tableName); } } if (tableNames.size > 0 && opts.dynamoActions.length > 0) { for (const tableName of tableNames) { statements.push(createTableGrant(opts.resourceName, tableName, opts.dynamoActions)); } } const storageTableNames = new Set(); for (const hatch of opts.dynamicEnvVars) { if (!hatch.name.startsWith('STORAGE_') || hatch.name.endsWith('BUCKETNAME')) continue; const match = hatch.name.match(/STORAGE_(.+?)_(ARN|NAME|STREAMARN)$/); if (match) storageTableNames.add(match[1].toLowerCase()); } if (storageTableNames.size > 0 && opts.dynamoActions.length > 0) { for (const tableName of storageTableNames) { statements.push(createStorageTableGrant(opts.resourceName, tableName, opts.dynamoActions)); } } if (opts.appSyncPermissions.hasMutation) { statements.push(createGraphqlGrant(opts.resourceName, 'grantMutation')); } if (opts.appSyncPermissions.hasQuery) { statements.push(createGraphqlGrant(opts.resourceName, 'grantQuery')); } if (opts.kinesisConfig && opts.kinesisConfig.actions.length > 0) { additionalImports['aws-cdk-lib'] = new Set(['aws_iam']); statements.push(createKinesisGrant(opts.resourceName, opts.kinesisConfig.actions)); } if (opts.dataTriggerModels.length > 0) { additionalImports['aws-cdk-lib/aws-lambda-event-sources'] = new Set(['DynamoEventSource']); additionalImports['aws-cdk-lib/aws-lambda'] = new Set(['StartingPosition']); statements.push(createDynamoTrigger(opts.resourceName, opts.dataTriggerModels)); } if (opts.storageTriggerTables.length > 0) { if (!additionalImports['aws-cdk-lib/aws-lambda-event-sources']) { additionalImports['aws-cdk-lib/aws-lambda-event-sources'] = new Set(); } additionalImports['aws-cdk-lib/aws-lambda-event-sources'].add('DynamoEventSource'); if (!additionalImports['aws-cdk-lib/aws-lambda']) { additionalImports['aws-cdk-lib/aws-lambda'] = new Set(); } additionalImports['aws-cdk-lib/aws-lambda'].add('StartingPosition'); statements.push(...createStorageDynamoTrigger(opts.resourceName, opts.storageTriggerTables)); } if ((_a = opts.kinesisConfig) === null || _a === void 0 ? void 0 : _a.isTrigger) { if (!additionalImports['aws-cdk-lib/aws-lambda-event-sources']) { additionalImports['aws-cdk-lib/aws-lambda-event-sources'] = new Set(); } additionalImports['aws-cdk-lib/aws-lambda-event-sources'].add('KinesisEventSource'); if (!additionalImports['aws-cdk-lib/aws-lambda']) { additionalImports['aws-cdk-lib/aws-lambda'] = new Set(); } additionalImports['aws-cdk-lib/aws-lambda'].add('StartingPosition'); additionalImports['aws-cdk-lib/aws-kinesis'] = new Set(['Stream']); statements.push(...createKinesisTrigger(opts.resourceName)); } if (opts.unMappedAuthActions.length > 0) { if (!additionalImports['aws-cdk-lib']) { additionalImports['aws-cdk-lib'] = new Set(); } additionalImports['aws-cdk-lib'].add('aws_iam'); statements.push(createUnMappedAuthGrant(opts.resourceName, opts.unMappedAuthActions)); } const extraParams = []; const allStorageTableParams = new Set(storageTableNames); for (const t of opts.storageTriggerTables) allStorageTableParams.add(t); if (allStorageTableParams.size > 0) { if (!additionalImports['aws-cdk-lib/aws-dynamodb']) { additionalImports['aws-cdk-lib/aws-dynamodb'] = new Set(); } additionalImports['aws-cdk-lib/aws-dynamodb'].add('Table'); for (const tableName of allStorageTableParams) { extraParams.push(factory.createParameterDeclaration(undefined, undefined, tableName, undefined, factory.createTypeReferenceNode('Table'))); } } if (opts.kinesisConfig) { extraParams.push(factory.createParameterDeclaration(undefined, undefined, 'analytics', undefined, factory.createTypeReferenceNode(kinesis_generator_1.AnalyticsKinesisGenerator.className(opts.kinesisConfig.resourceName)))); } const funcDeclaration = ts_1.TS.exportedFunction('applyEscapeHatches', statements, extraParams.length > 0 ? extraParams : undefined); return { postExportStatements: [funcDeclaration], additionalImports }; } renderEnvironment(target, namedImports, opts) { if (!opts.literalEnvVars || Object.keys(opts.literalEnvVars).length === 0) return; const envProps = Object.entries(opts.literalEnvVars).map(([key, value]) => { if (key === 'API_KEY' && value.startsWith(`/amplify/${this.appId}/${this.backendEnvironmentName}`)) { namedImports['@aws-amplify/backend'].add('secret'); return factory.createPropertyAssignment(key, factory.createCallExpression(factory.createIdentifier('secret'), undefined, [factory.createStringLiteral('API_KEY')])); } if (key === 'ENV') { return factory.createPropertyAssignment(key, factory.createTemplateExpression(factory.createTemplateHead(''), [ factory.createTemplateSpan(factory.createIdentifier('branchName'), factory.createTemplateTail('')), ])); } return factory.createPropertyAssignment(key, factory.createStringLiteral(value)); }); target.push(factory.createPropertyAssignment('environment', factory.createObjectLiteralExpression(envProps))); } renderRuntime(target, runtime) { if (!runtime || !runtime.includes('nodejs')) return; const nodeVersion = parseNodejsRuntime(runtime); if (nodeVersion === undefined) { throw new amplify_cli_core_1.AmplifyError('UnsupportedRuntimeError', { message: `Unsupported nodejs runtime for function: ${runtime}`, resolution: 'Update the Lambda function runtime to a supported Node.js version before migrating.', }); } target.push(factory.createPropertyAssignment('runtime', factory.createNumericLiteral(nodeVersion))); } renderSchedule(target, schedule) { if (!schedule) return; const converted = convertScheduleExpression(schedule); if (converted) { target.push(factory.createPropertyAssignment('schedule', factory.createStringLiteral(converted))); } } } exports.FunctionRenderer = FunctionRenderer; function classifyEnvVars(variables) { const retained = {}; const escapeHatches = []; const suffixGroups = [ { prefix: 'API_', suffixes: [ { suffix: '_GRAPHQLAPIKEYOUTPUT', build: () => nonNull(backendPath('data', 'apiKey')) }, { suffix: '_GRAPHQLAPIENDPOINTOUTPUT', build: () => backendPath('data', 'graphqlUrl') }, { suffix: '_GRAPHQLAPIIDOUTPUT', build: () => backendPath('data', 'apiId') }, { suffix: 'TABLE_ARN', build: (envVar) => { var _a; return backendTableProp((_a = extractTableName(envVar)) !== null && _a !== void 0 ? _a : 'unknown', 'tableArn'); }, }, { suffix: 'TABLE_NAME', build: (envVar) => { var _a; return backendTableProp((_a = extractTableName(envVar)) !== null && _a !== void 0 ? _a : 'unknown', 'tableName'); }, }, ], }, { prefix: 'STORAGE_', suffixes: [ { suffix: '_STREAMARN', build: (envVar) => nonNull(directProp(extractStorageVarName(envVar), 'tableStreamArn')) }, { suffix: '_BUCKETNAME', build: () => backendPath('storage', 'resources', 'bucket', 'bucketName') }, { suffix: '_ARN', build: (envVar) => directProp(extractStorageVarName(envVar), 'tableArn') }, { suffix: '_NAME', build: (envVar) => directProp(extractStorageVarName(envVar), 'tableName') }, ], }, { prefix: 'AUTH_', suffixes: [{ suffix: '_USERPOOLID', build: () => backendPath('auth', 'resources', 'userPool', 'userPoolId') }], }, { prefix: 'FUNCTION_', suffixes: [ { suffix: '_NAME', build: (envVar) => { const match = envVar.match(/FUNCTION_(.+?)_NAME/); const funcName = match ? match[1].toLowerCase() : 'unknown'; return backendPath(funcName, 'resources', 'lambda', 'functionName'); }, }, ], }, { prefix: 'ANALYTICS_', suffixes: [ { suffix: '_KINESISSTREAMARN', build: () => directProp('analytics', 'kinesisStreamArn'), }, ], }, ]; const classified = new Set(); for (const { prefix, suffixes } of suffixGroups) { for (const { suffix, build } of suffixes) { for (const envVar of Object.keys(variables)) { if (envVar.startsWith(prefix) && envVar.endsWith(suffix) && !classified.has(envVar)) { escapeHatches.push({ name: envVar, expression: build(envVar) }); classified.add(envVar); } } } } for (const [key, value] of Object.entries(variables)) { if (!classified.has(key)) { retained[key] = value; } } return { literalEnvVars: retained, dynamicEnvVars: escapeHatches }; } exports.classifyEnvVars = classifyEnvVars; function createAddEnvironmentCall(functionName, hatch) { return factory.createExpressionStatement(factory.createCallExpression(factory.createPropertyAccessExpression(factory.createPropertyAccessExpression(factory.createIdentifier('backend'), factory.createIdentifier(functionName)), factory.createIdentifier('addEnvironment')), undefined, [factory.createStringLiteral(hatch.name), hatch.expression])); } function createFunctionNameOverride(funcName) { const lhs = factory.createPropertyAccessExpression(factory.createPropertyAccessExpression(factory.createPropertyAccessExpression(factory.createPropertyAccessExpression(factory.createPropertyAccessExpression(factory.createIdentifier('backend'), factory.createIdentifier(funcName)), factory.createIdentifier('resources')), factory.createIdentifier('cfnResources')), factory.createIdentifier('cfnFunction')), factory.createIdentifier('functionName')); const rhs = factory.createTemplateExpression(factory.createTemplateHead(`${funcName}-`), [ factory.createTemplateSpan(factory.createIdentifier('branchName'), factory.createTemplateTail('')), ]); return factory.createExpressionStatement(factory.createAssignment(lhs, rhs)); } function backendPath(...segments) { return ts_1.TS.propAccess('backend', ...segments); } function backendTableProp(tableName, property) { const tables = factory.createPropertyAccessExpression(factory.createPropertyAccessExpression(factory.createPropertyAccessExpression(factory.createIdentifier('backend'), factory.createIdentifier('data')), factory.createIdentifier('resources')), factory.createIdentifier('tables')); const indexed = factory.createElementAccessExpression(tables, factory.createStringLiteral(tableName)); return factory.createPropertyAccessExpression(indexed, factory.createIdentifier(property)); } function directProp(varName, property) { return ts_1.TS.propAccess(varName, property); } function nonNull(expr) { return factory.createNonNullExpression(expr); } function extractTableName(envVar) { const match = envVar.match(/API_.*_(.+?)TABLE_/); if (!match) return undefined; const raw = match[1]; return raw.charAt(0).toUpperCase() + raw.slice(1).toLowerCase(); } exports.extractTableName = extractTableName; function extractStorageVarName(envVar) { const tableMatch = envVar.match(/STORAGE_(.+?)TABLE_/); if (tableMatch) return tableMatch[1].toLowerCase(); const fallbackMatch = envVar.match(/STORAGE_(.+?)_/); if (fallbackMatch) return fallbackMatch[1].toLowerCase(); return 'unknown'; } function createTableGrant(funcName, tableName, actions) { return factory.createExpressionStatement(factory.createCallExpression(factory.createPropertyAccessExpression(factory.createElementAccessExpression(factory.createPropertyAccessExpression(factory.createPropertyAccessExpression(factory.createPropertyAccessExpression(factory.createIdentifier('backend'), factory.createIdentifier('data')), factory.createIdentifier('resources')), factory.createIdentifier('tables')), factory.createStringLiteral(tableName)), factory.createIdentifier('grant')), undefined, [ factory.createPropertyAccessExpression(factory.createPropertyAccessExpression(factory.createPropertyAccessExpression(factory.createIdentifier('backend'), factory.createIdentifier(funcName)), factory.createIdentifier('resources')), factory.createIdentifier('lambda')), ...actions.map((action) => factory.createStringLiteral(action)), ])); } function createStorageTableGrant(funcName, tableName, actions) { return factory.createExpressionStatement(factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier(tableName), factory.createIdentifier('grant')), undefined, [ factory.createPropertyAccessExpression(factory.createPropertyAccessExpression(factory.createPropertyAccessExpression(factory.createIdentifier('backend'), factory.createIdentifier(funcName)), factory.createIdentifier('resources')), factory.createIdentifier('lambda')), ...actions.map((action) => factory.createStringLiteral(action)), ])); } function createGraphqlGrant(funcName, grantMethod) { return factory.createExpressionStatement(factory.createCallExpression(factory.createPropertyAccessExpression(factory.createPropertyAccessExpression(factory.createPropertyAccessExpression(factory.createPropertyAccessExpression(factory.createIdentifier('backend'), factory.createIdentifier('data')), factory.createIdentifier('resources')), factory.createIdentifier('graphqlApi')), factory.createIdentifier(grantMethod)), undefined, [ factory.createPropertyAccessExpression(factory.createPropertyAccessExpression(factory.createPropertyAccessExpression(factory.createIdentifier('backend'), factory.createIdentifier(funcName)), factory.createIdentifier('resources')), factory.createIdentifier('lambda')), ])); } function createKinesisGrant(funcName, actions) { const lambdaRef = factory.createPropertyAccessExpression(factory.createPropertyAccessExpression(factory.createPropertyAccessExpression(factory.createIdentifier('backend'), factory.createIdentifier(funcName)), factory.createIdentifier('resources')), factory.createIdentifier('lambda')); const policyStatement = factory.createNewExpression(factory.createPropertyAccessExpression(factory.createIdentifier('aws_iam'), factory.createIdentifier('PolicyStatement')), undefined, [ factory.createObjectLiteralExpression([ factory.createPropertyAssignment('actions', factory.createArrayLiteralExpression(actions.map((action) => factory.createStringLiteral(action)))), factory.createPropertyAssignment('resources', factory.createArrayLiteralExpression([ factory.createPropertyAccessExpression(factory.createIdentifier('analytics'), factory.createIdentifier('kinesisStreamArn')), ])), ], true), ]); return factory.createExpressionStatement(factory.createCallExpression(factory.createPropertyAccessExpression(lambdaRef, factory.createIdentifier('addToRolePolicy')), undefined, [policyStatement])); } function createUnMappedAuthGrant(funcName, actions) { const lambdaRef = factory.createPropertyAccessExpression(factory.createPropertyAccessExpression(factory.createPropertyAccessExpression(factory.createIdentifier('backend'), factory.createIdentifier(funcName)), factory.createIdentifier('resources')), factory.createIdentifier('lambda')); const policyStatement = factory.createNewExpression(factory.createPropertyAccessExpression(factory.createIdentifier('aws_iam'), factory.createIdentifier('PolicyStatement')), undefined, [ factory.createObjectLiteralExpression([ factory.createPropertyAssignment('actions', factory.createArrayLiteralExpression(actions.map((action) => factory.createStringLiteral(action)))), factory.createPropertyAssignment('resources', factory.createArrayLiteralExpression([ ts_1.TS.propAccess('backend', 'auth', 'resources', 'userPool', 'userPoolArn'), ])), ], true), ]); return factory.createExpressionStatement(factory.createNewExpression(factory.createPropertyAccessExpression(factory.createIdentifier('aws_iam'), factory.createIdentifier('Policy')), undefined, [ lambdaRef, factory.createStringLiteral('UnmappedCognitoActionsPolicy'), factory.createObjectLiteralExpression([ factory.createPropertyAssignment('statements', factory.createArrayLiteralExpression([policyStatement])), factory.createPropertyAssignment('roles', factory.createArrayLiteralExpression([ factory.createNonNullExpression(factory.createPropertyAccessExpression(lambdaRef, factory.createIdentifier('role'))), ])), ], true), ])); } function createDynamoTrigger(functionName, models) { return factory.createForOfStatement(undefined, factory.createVariableDeclarationList([factory.createVariableDeclaration('model', undefined, undefined, undefined)], typescript_1.default.NodeFlags.Const), factory.createArrayLiteralExpression(models.map((model) => factory.createStringLiteral(model))), factory.createBlock([ factory.createVariableStatement([], factory.createVariableDeclarationList([ factory.createVariableDeclaration('table', undefined, undefined, factory.createElementAccessExpression(factory.createPropertyAccessExpression(factory.createIdentifier('backend.data.resources'), factory.createIdentifier('tables')), factory.createIdentifier('model'))), ], typescript_1.default.NodeFlags.Const)), factory.createExpressionStatement(factory.createCallExpression(factory.createPropertyAccessExpression(factory.createPropertyAccessExpression(factory.createIdentifier(`backend.${functionName}.resources`), factory.createIdentifier('lambda')), factory.createIdentifier('addEventSource')), undefined, [ factory.createNewExpression(factory.createIdentifier('DynamoEventSource'), undefined, [ factory.createIdentifier('table'), factory.createObjectLiteralExpression([ts_1.TS.enumProp('startingPosition', 'StartingPosition', 'LATEST')]), ]), ])), factory.createExpressionStatement(factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier('table'), factory.createIdentifier('grantStreamRead')), undefined, [ factory.createNonNullExpression(factory.createPropertyAccessExpression(factory.createIdentifier(`backend.${functionName}.resources.lambda`), factory.createIdentifier('role'))), ])), factory.createExpressionStatement(factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier('table'), factory.createIdentifier('grantTableListStreams')), undefined, [ factory.createNonNullExpression(factory.createPropertyAccessExpression(factory.createIdentifier(`backend.${functionName}.resources.lambda`), factory.createIdentifier('role'))), ])), ], true)); } function createStorageDynamoTrigger(functionName, tableNames) { const statements = []; for (const tableName of tableNames) { statements.push(factory.createExpressionStatement(factory.createCallExpression(factory.createPropertyAccessExpression(factory.createPropertyAccessExpression(factory.createIdentifier(`backend.${functionName}.resources`), factory.createIdentifier('lambda')), factory.createIdentifier('addEventSource')), undefined, [ factory.createNewExpression(factory.createIdentifier('DynamoEventSource'), undefined, [ factory.createIdentifier(tableName), factory.createObjectLiteralExpression([ts_1.TS.enumProp('startingPosition', 'StartingPosition', 'LATEST')]), ]), ]))); statements.push(factory.createExpressionStatement(factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier(tableName), factory.createIdentifier('grantStreamRead')), undefined, [ factory.createNonNullExpression(factory.createPropertyAccessExpression(factory.createIdentifier(`backend.${functionName}.resources.lambda`), factory.createIdentifier('role'))), ]))); statements.push(factory.createExpressionStatement(factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier(tableName), factory.createIdentifier('grantTableListStreams')), undefined, [ factory.createNonNullExpression(factory.createPropertyAccessExpression(factory.createIdentifier(`backend.${functionName}.resources.lambda`), factory.createIdentifier('role'))), ]))); } return statements; } function createKinesisTrigger(functionName) { const fromStreamArn = factory.createVariableStatement([], factory.createVariableDeclarationList([ factory.createVariableDeclaration('kinesisStream', undefined, undefined, factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier('Stream'), factory.createIdentifier('fromStreamArn')), undefined, [ factory.createPropertyAccessExpression(factory.createPropertyAccessExpression(factory.createPropertyAccessExpression(factory.createIdentifier(`backend.${functionName}`), factory.createIdentifier('resources')), factory.createIdentifier('lambda')), factory.createIdentifier('stack')), factory.createStringLiteral('KinesisStream'), factory.createPropertyAccessExpression(factory.createIdentifier('analytics'), factory.createIdentifier('kinesisStreamArn')), ])), ], typescript_1.default.NodeFlags.Const)); const addEventSource = factory.createExpressionStatement(factory.createCallExpression(factory.createPropertyAccessExpression(factory.createPropertyAccessExpression(factory.createIdentifier(`backend.${functionName}.resources`), factory.createIdentifier('lambda')), factory.createIdentifier('addEventSource')), undefined, [ factory.createNewExpression(factory.createIdentifier('KinesisEventSource'), undefined, [ factory.createIdentifier('kinesisStream'), factory.createObjectLiteralExpression([ts_1.TS.enumProp('startingPosition', 'StartingPosition', 'LATEST')]), ]), ])); return [fromStreamArn, addEventSource]; } function parseNodejsRuntime(runtime) { const match = runtime.match(/nodejs(\d+)/); return match ? parseInt(match[1], 10) : undefined; } function convertScheduleExpression(raw) { const startIndex = raw.indexOf('(') + 1; const endIndex = raw.lastIndexOf(')'); const inner = startIndex > 0 && endIndex > startIndex ? raw.slice(startIndex, endIndex) : undefined; if (raw.startsWith('rate(') && inner) { const [value, unit] = inner.split(' '); const unitMap = { minute: 'm', minutes: 'm', hour: 'h', hours: 'h', day: 'd', days: 'd', }; return unitMap[unit] ? `every ${value}${unitMap[unit]}` : undefined; } if (raw.startsWith('cron(') && inner) { return inner; } return undefined; } //# sourceMappingURL=function.renderer.js.map