UNPKG

dynamodb-ts-model

Version:

A DynamoDB model/client with full TypeScript typings

66 lines 2.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DynamoClient = void 0; const client_dynamodb_1 = require("@aws-sdk/client-dynamodb"); const lib_dynamodb_1 = require("@aws-sdk/lib-dynamodb"); const DynamoBatch_1 = require("./DynamoBatch"); const DynamoModel_1 = require("./DynamoModel"); const DynamoTransaction_1 = require("./DynamoTransaction"); function defaultDc() { return lib_dynamodb_1.DynamoDBDocument.from(new client_dynamodb_1.DynamoDBClient({})); } /** * A DynamoDB client */ class DynamoClient { /** * Create a model for a DynamoDB table without supplying the runtime parameters. * @returns a builder used to build a model. */ static model() { return new DynamoModel_1.DynamoModelBuilder(); } constructor(dc = defaultDc(), options = {}) { this.dc = dc; this.options = options; this.tableMetrics = new Map(); } /** * Create a model for a DynamoDB table * @param name Name of the model * @param tableName Name of the table * @returns a builder used to build a model. */ model(name, tableName = name) { return new DynamoModel_1.DynamoModelBuilder(this, name, tableName); } /** * Create a transaction * @param [name] Optional name identifying the transaction for logging etc. */ transaction(name) { return new DynamoTransaction_1.DynamoTransactionProxy(this, name); } /** * Create a batch statement * @param [name] Optional name identifying the statement for logging etc. */ batch(name) { return new DynamoBatch_1.DynamoBatchStatementProxy(this, name); } /** * Get metrics for each table operated on by this client instance. * For metrics to be collected, the option enableTableMetrics must be true when constructing the client. */ getTableMetrics() { return this.tableMetrics; } /** * Clear the table metrics */ clearTableMetrics() { this.tableMetrics = new Map(); } } exports.DynamoClient = DynamoClient; //# sourceMappingURL=DynamoClient.js.map