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","file":"/npm/@stackspot/cdk-component-dynamodb-typescript@0.3.3/lib/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@stackspot/cdk-component-dynamodb-typescript@0.3.3/lib/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","import { Construct } from 'constructs';\nimport { GlobalSecondaryIndexProps, Table, TableProps } from 'aws-cdk-lib/aws-dynamodb';\nimport * as lambda from 'aws-cdk-lib/aws-lambda';\nimport * as iam from 'aws-cdk-lib/aws-iam';\nimport { RepositoryCodegen } from './repository-codegen';\n\nenum GrantTypeLambda {\n  READ_ONLY,\n  READ_WRITE,\n}\n\nexport interface StackSpotDynamoDBTableProps {\n  readonly tableConfiguration: TableProps;\n  readonly gsis?: GlobalSecondaryIndexProps[];\n  readonly lambdasConfiguration?: StackSpotDynamoDBTableLambdasConfigurationProps;\n  readonly generateRepository?: boolean;\n  readonly repositoryGenerationConfiguration?: StackSpotDynamoDBTableRepositoryGenerationConfigurationProps;\n}\n\nexport interface StackSpotDynamoDBTableBackendLambda {\n  readonly operationId: string;\n  readonly lambdaFunc: lambda.Function;\n}\n\nexport interface StackSpotDynamoDBTableLambdasConfigurationProps {\n  readonly lambdasById: StackSpotDynamoDBTableBackendLambda[];\n  readonly tableNameEnvironmentVariable: string;\n  readonly readOnly?: string[];\n}\n\nexport interface StackSpotDynamoDBTableRepositoryGenerationConfigurationProps {\n  readonly sourceDir?: string;\n  readonly tracing?: boolean;\n}\n\nexport class StackSpotDynamoDBTable extends Table {\n  private readonly repositoryCodegen?: RepositoryCodegen;\n\n  protected readonly props: StackSpotDynamoDBTableProps;\n\n  constructor(scope: Construct, id: string, props: StackSpotDynamoDBTableProps) {\n    super(scope, id, props.tableConfiguration);\n    this.props = props;\n\n    this.configureGlobalSecondaryIndexes();\n\n    this.configureLambdasPermission();\n\n    if (props.generateRepository || props.repositoryGenerationConfiguration) {\n      this.repositoryCodegen = new RepositoryCodegen(props.repositoryGenerationConfiguration);\n      this.repositoryCodegen.generateCode();\n    }\n  }\n\n  private configureGlobalSecondaryIndexes() {\n    this.props.gsis?.forEach((gsi) => {\n      this.addGlobalSecondaryIndex(gsi);\n    });\n  }\n\n  private configureLambdasPermission() {\n    if (this.props.lambdasConfiguration) {\n      const lambdasConfiguration = this.props.lambdasConfiguration;\n      this.configReadWriteLambdas(lambdasConfiguration);\n      this.configReadOnlyLambdas(lambdasConfiguration);\n    }\n  }\n\n  private configReadWriteLambdas(lambdasConfiguration: StackSpotDynamoDBTableLambdasConfigurationProps) {\n    const readWriteLambdas: StackSpotDynamoDBTableBackendLambda[] = this.getLambdasByGrantType(\n      lambdasConfiguration,\n      GrantTypeLambda.READ_WRITE\n    );\n    this.configLambdas(lambdasConfiguration, readWriteLambdas, Table.prototype.grantReadWriteData);\n  }\n\n  private configReadOnlyLambdas(lambdasConfiguration: StackSpotDynamoDBTableLambdasConfigurationProps) {\n    const readLambdas: StackSpotDynamoDBTableBackendLambda[] = this.getLambdasByGrantType(\n      lambdasConfiguration,\n      GrantTypeLambda.READ_ONLY\n    );\n    this.configLambdas(lambdasConfiguration, readLambdas, Table.prototype.grantReadData);\n  }\n\n  private getLambdasByGrantType(\n    lambdasConfiguration: StackSpotDynamoDBTableLambdasConfigurationProps,\n    grantType: GrantTypeLambda\n  ): StackSpotDynamoDBTableBackendLambda[] {\n    const lambdasDesiredToBeReadOnly: string[] = lambdasConfiguration.readOnly ?? [];\n    const lambdasById: StackSpotDynamoDBTableBackendLambda[] = lambdasConfiguration.lambdasById;\n    return lambdasById.filter(\n      ({ operationId }) => (grantType == GrantTypeLambda.READ_ONLY) == lambdasDesiredToBeReadOnly.includes(operationId)\n    );\n  }\n\n  private configLambdas(\n    lambdasConfiguration: StackSpotDynamoDBTableLambdasConfigurationProps,\n    lambdas: StackSpotDynamoDBTableBackendLambda[],\n    func: (grantee: iam.IGrantable) => iam.Grant\n  ) {\n    lambdas.forEach(({ lambdaFunc }) => {\n      func.call(this, lambdaFunc);\n      lambdaFunc.addEnvironment(lambdasConfiguration.tableNameEnvironmentVariable, this.tableName);\n    });\n  }\n}\n"]}