UNPKG

dynamodb-toolbox

Version:

Lightweight and type-safe query builder for DynamoDB and TypeScript.

57 lines (56 loc) 1.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TableAction = exports.Table = void 0; const index_js_1 = require("../errors/index.js"); const isString_js_1 = require("../utils/validation/isString.js"); const constants_js_1 = require("./constants.js"); class Table { constructor({ documentClient, /** * @debt v3 "To rename tableName" */ name, partitionKey, sortKey, indexes = {}, entityAttributeSavedAs = '_et', meta = {} }) { this.getDocumentClient = () => { if (this.documentClient === undefined) { throw new index_js_1.DynamoDBToolboxError('actions.missingDocumentClient', { message: 'You need to set a document client on your table to send a command' }); } return this.documentClient; }; this.documentClient = documentClient; this.tableName = name; this.partitionKey = partitionKey; if (sortKey) { this.sortKey = sortKey; } this.indexes = indexes; this.entityAttributeSavedAs = entityAttributeSavedAs; this[constants_js_1.$entities] = []; this.meta = meta; } getName() { if (this.tableName === undefined) { throw new index_js_1.DynamoDBToolboxError('table.missingTableName', { message: 'Please specify a table name in your Table constructor or in your command options.' }); } if ((0, isString_js_1.isString)(this.tableName)) { return this.tableName; } else { return this.tableName(); } } build(Action) { return new Action(this, this[constants_js_1.$entities]); } } exports.Table = Table; class TableAction { constructor(table, entities = []) { this.table = table; this[constants_js_1.$entities] = entities; } } exports.TableAction = TableAction;