UNPKG

dynamodb-toolbox

Version:

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

50 lines (49 loc) 1.95 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ItemSchema_ = exports.item = void 0; const resetLinks_js_1 = require("../../schema/utils/resetLinks.js"); const light_js_1 = require("../utils/light.js"); const schema_js_1 = require("./schema.js"); /** * Define a new item schema * * @param attributes Dictionary of attributes */ const item = (attributes) => new ItemSchema_((0, light_js_1.lightObj)(attributes)); exports.item = item; class ItemSchema_ extends schema_js_1.ItemSchema { pick(...attributeNames) { const nextAttributes = {}; for (const attributeName of attributeNames) { if (!(attributeName in this.attributes)) { continue; } nextAttributes[attributeName] = (0, resetLinks_js_1.resetLinks)(this.attributes[attributeName]); } return new ItemSchema_(nextAttributes); } omit(...attributeNames) { const nextAttributes = {}; const attributeNamesSet = new Set(attributeNames); for (const _attributeName of Object.keys(this.attributes)) { if (attributeNamesSet.has(_attributeName)) { continue; } const attributeName = _attributeName; nextAttributes[attributeName] = (0, resetLinks_js_1.resetLinks)(this.attributes[attributeName]); } return new ItemSchema_(nextAttributes); } and(additionalAttr) { const additionalAttributes = (typeof additionalAttr === 'function' ? additionalAttr(this) : additionalAttr); const nextAttributes = { ...this.attributes }; for (const [attributeName, additionalAttribute] of Object.entries(additionalAttributes)) { nextAttributes[attributeName] = additionalAttribute; } return new ItemSchema_(nextAttributes); } build(Action) { return new Action(this); } } exports.ItemSchema_ = ItemSchema_;