UNPKG

dyngoose

Version:

Elegant DynamoDB object modeling for Typescript

39 lines 1.51 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const client_dynamodb_1 = require("@aws-sdk/client-dynamodb"); const connections_1 = require("./connections"); /** * This acts as a Singleton class to provide the default DynamoDB Client to * tables when it does not have an explicit connection provided in the table's * metadata. */ class Config { static get defaultConnection() { if (this.__defaultConnection == null) { let credentials; if (typeof process.env.DYNAMO_ACCESS_KEY_ID === 'string' && typeof process.env.DYNAMO_SECRET_ACCESS_KEY === 'string') { credentials = { accessKeyId: process.env.DYNAMO_ACCESS_KEY_ID, secretAccessKey: process.env.DYNAMO_SECRET_ACCESS_KEY, }; } this.__defaultConnection = new connections_1.DynamoDBConnection({ endpoint: process.env.DYNAMO_ENDPOINT, region: process.env.DYNAMO_REGION, enableAWSXray: process.env.ENABLE_XRAY === 'true', credentials, }); } return this.__defaultConnection; } static set defaultConnection(connection) { if (connection instanceof client_dynamodb_1.DynamoDB) { this.__defaultConnection = { client: connection }; } else { this.__defaultConnection = connection; } } } exports.default = Config; //# sourceMappingURL=config.js.map