in packages/dynamodb-data-mapper/src/DataMapper.ts [277:323]
async createTable(
valueConstructor: ZeroArgumentsConstructor<any>,
options: CreateTableOptions
) {
const schema = getSchema(valueConstructor.prototype);
const { attributes, indexKeys, tableKeys } = keysFromSchema(schema);
const TableName = this.getTableName(valueConstructor.prototype);
let throughput: { ProvisionedThroughput?: ProvisionedThroughput } = {};
if (options.billingMode !== 'PAY_PER_REQUEST') {
throughput = {
...provisionedThroughput(options.readCapacityUnits, options.writeCapacityUnits),
};
}
const {
streamViewType = 'NONE',
indexOptions = {},
billingMode,
sseSpecification,
} = options;
const {
TableDescription: {TableStatus} = {TableStatus: 'CREATING'}
} = await this.client.createTable({
...indexDefinitions(indexKeys, indexOptions, schema),
TableName,
...throughput,
BillingMode: billingMode,
AttributeDefinitions: attributeDefinitionList(attributes),
KeySchema: keyTypesToElementList(tableKeys),
StreamSpecification: streamViewType === 'NONE'
? { StreamEnabled: false }
: { StreamEnabled: true, StreamViewType: streamViewType },
SSESpecification: sseSpecification
? {
Enabled: true,
SSEType: sseSpecification.sseType,
KMSMasterKeyId: sseSpecification.kmsMasterKeyId,
}
: { Enabled: false },
}).promise();
if (TableStatus !== 'ACTIVE') {
await this.client.waitFor('tableExists', {TableName}).promise();
}
}