UNPKG

@aws-amplify/cli-internal

Version:
78 lines 5.08 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AnalyticsRenderer = void 0; const typescript_1 = __importDefault(require("typescript")); const ts_1 = require("../../ts"); const resource_types_1 = require("../../../_common/resource-types"); const factory = typescript_1.default.factory; class AnalyticsRenderer { constructor(resource) { this.resource = resource; } render(opts) { return factory.createNodeArray([ ...this.renderImports(opts), ts_1.newLineIdentifier, ts_1.TS.createBranchNameDeclaration(), ts_1.newLineIdentifier, this.renderDefineAnalytics(opts), ts_1.newLineIdentifier, this.renderPostRefactor(opts), ]); } renderImports(opts) { return [ ts_1.TS.namedImport('aws-cdk-lib', 'CfnResource'), ts_1.TS.namedImport('aws-cdk-lib/aws-kinesis', 'CfnStream'), ts_1.TS.namedImport(`./${opts.constructFileName}`, opts.constructClassName), ts_1.TS.typeImport('../backend', 'Backend'), ]; } renderDefineAnalytics(opts) { const { constructClassName, shardCount } = opts; const resourceName = this.resource.resourceName; const constructId = resourceName.charAt(0).toUpperCase() + resourceName.slice(1); const stackCall = factory.createVariableStatement(undefined, factory.createVariableDeclarationList([ factory.createVariableDeclaration('stack', undefined, undefined, factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier('backend'), factory.createIdentifier('createStack')), undefined, [factory.createStringLiteral('analytics')])), ], typescript_1.default.NodeFlags.Const)); const constructInstantiation = factory.createVariableStatement(undefined, factory.createVariableDeclarationList([ factory.createVariableDeclaration('analytics', undefined, undefined, factory.createNewExpression(factory.createIdentifier(constructClassName), undefined, [ factory.createIdentifier('stack'), factory.createStringLiteral(constructId), factory.createObjectLiteralExpression([ factory.createPropertyAssignment(factory.createIdentifier('kinesisStreamName'), factory.createStringLiteral(resourceName)), factory.createPropertyAssignment(factory.createIdentifier('kinesisStreamShardCount'), factory.createNumericLiteral(shardCount)), factory.createPropertyAssignment(factory.createIdentifier('authPolicyName'), factory.createTemplateExpression(factory.createTemplateHead(`${resourceName}-auth-policy-`), [ factory.createTemplateSpan(factory.createIdentifier('branchName'), factory.createTemplateTail('')), ])), factory.createPropertyAssignment(factory.createIdentifier('unauthPolicyName'), factory.createTemplateExpression(factory.createTemplateHead(`${resourceName}-unauth-policy-`), [ factory.createTemplateSpan(factory.createIdentifier('branchName'), factory.createTemplateTail('')), ])), factory.createPropertyAssignment(factory.createIdentifier('authRoleName'), ts_1.TS.propAccess('backend', 'auth', 'resources', 'authenticatedUserIamRole', 'roleName')), factory.createPropertyAssignment(factory.createIdentifier('unauthRoleName'), ts_1.TS.propAccess('backend', 'auth', 'resources', 'unauthenticatedUserIamRole', 'roleName')), factory.createShorthandPropertyAssignment(factory.createIdentifier('branchName')), ], true), ])), ], typescript_1.default.NodeFlags.Const)); return ts_1.TS.exportedFunction('defineAnalytics', [ stackCall, constructInstantiation, ts_1.TS.retentionLoop(ts_1.TS.propAccess('stack', 'node'), resource_types_1.ANALYTICS_RESOURCES_TO_RETAIN), factory.createReturnStatement(factory.createIdentifier('analytics')), ]); } renderPostRefactor(opts) { return factory.createFunctionDeclaration([factory.createModifier(typescript_1.default.SyntaxKind.ExportKeyword)], undefined, 'postRefactor', undefined, [ factory.createParameterDeclaration(undefined, undefined, 'analytics', undefined, factory.createTypeReferenceNode(opts.constructClassName)), ], undefined, factory.createBlock([ ts_1.TS.castAssign(factory.createCallExpression(ts_1.TS.propAccess('analytics', 'node', 'findChild'), undefined, [ factory.createStringLiteral('KinesisStream'), ]), 'CfnStream', 'name', factory.createStringLiteral(`${opts.streamName}`)), ], true)); } } exports.AnalyticsRenderer = AnalyticsRenderer; //# sourceMappingURL=kinesis.renderer.js.map