UNPKG

dynamodb-toolbox

Version:

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

62 lines (61 loc) 3 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.DeleteItemCommand = void 0; const lib_dynamodb_1 = require("@aws-sdk/lib-dynamodb"); const index_js_1 = require("../../../entity/actions/format/index.js"); const constants_js_1 = require("../../../entity/constants.js"); const decorator_js_1 = require("../../../entity/decorator.js"); const index_js_2 = require("../../../entity/index.js"); const index_js_3 = require("../../../errors/index.js"); const constants_js_2 = require("./constants.js"); const index_js_4 = require("./deleteItemParams/index.js"); class DeleteItemCommand extends index_js_2.EntityAction { constructor(entity, key, options = {}) { super(entity); this[constants_js_2.$key] = key; this[constants_js_2.$options] = options; } key(nextKey) { return new DeleteItemCommand(this.entity, nextKey, this[constants_js_2.$options]); } options(nextOptions) { return new DeleteItemCommand(this.entity, this[constants_js_2.$key], typeof nextOptions === 'function' ? nextOptions(this[constants_js_2.$options]) : nextOptions); } [constants_js_1.$sentArgs]() { if (!this[constants_js_2.$key]) { throw new index_js_3.DynamoDBToolboxError('actions.incompleteAction', { message: 'DeleteItemCommand incomplete: Missing "key" property' }); } return [this[constants_js_2.$key], this[constants_js_2.$options]]; } params() { return (0, index_js_4.deleteItemParams)(this.entity, ...this[constants_js_1.$sentArgs]()); } async send(documentClientOptions) { const deleteItemParams = this.params(); const commandOutput = await this.entity.table .getDocumentClient() .send(new lib_dynamodb_1.DeleteCommand(deleteItemParams), documentClientOptions); const { Attributes: attributes, ...restCommandOutput } = commandOutput; if (attributes === undefined) { return restCommandOutput; } const formattedItem = new index_js_1.EntityFormatter(this.entity).format(attributes); return { Attributes: formattedItem, ...restCommandOutput }; } } exports.DeleteItemCommand = DeleteItemCommand; DeleteItemCommand.actionName = 'delete'; __decorate([ (0, decorator_js_1.interceptable)() ], DeleteItemCommand.prototype, "send", null);