UNPKG

dynamodb-toolbox

Version:

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

42 lines (41 loc) 1.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GetTransaction = void 0; const index_js_1 = require("../../../../entity/actions/parse/index.js"); const index_js_2 = require("../../../../entity/index.js"); const index_js_3 = require("../../../../errors/index.js"); const constants_js_1 = require("./constants.js"); const options_js_1 = require("./options.js"); class GetTransaction extends index_js_2.EntityAction { constructor(entity, key, options = {}) { super(entity); this[constants_js_1.$key] = key; this[constants_js_1.$options] = options; } key(nextKey) { return new GetTransaction(this.entity, nextKey, this[constants_js_1.$options]); } options(nextOptions) { return new GetTransaction(this.entity, this[constants_js_1.$key], typeof nextOptions === 'function' ? nextOptions(this[constants_js_1.$options]) : nextOptions); } params() { var _a; if (!this[constants_js_1.$key]) { throw new index_js_3.DynamoDBToolboxError('actions.incompleteAction', { message: 'GetTransaction incomplete: Missing "key" property' }); } const options = this[constants_js_1.$options]; const { key } = this.entity.build(index_js_1.EntityParser).parse(this[constants_js_1.$key], { mode: 'key' }); const awsOptions = (0, options_js_1.parseOptions)(this.entity, options); return { Get: { TableName: (_a = options.tableName) !== null && _a !== void 0 ? _a : this.entity.table.getName(), Key: key, ...awsOptions } }; } } exports.GetTransaction = GetTransaction; GetTransaction.actionName = 'transactGet';