UNPKG

@nerdware/ddb-single-table

Version:

A schema-based DynamoDB modeling tool, high-level API, and type-generator built to supercharge single-table designs!⚡

21 lines (20 loc) 1.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.transformItem = void 0; const ts_type_safety_utils_1 = require("@nerdware/ts-type-safety-utils"); /** * This `IOAction` uses the `transformItem` method (if defined in the Model's * schema options), to transform an entire item before it is sent to the database. * This is useful for potentially adding/removing/renaming item properties, however * **it may necessitate providing explicit Model type params for `ItemOutput` and/or * `ItemInput`, depending on the changes made.** */ const transformItem = function (item, { schemaOptions, ioDirection }) { // If schemaOptions has transformItem toDB/fromDB, pass the existing item into the fn const transformItem = schemaOptions.transformItem?.[ioDirection]; // If the new item has type mismatches, they're caught by the `typeChecking` method if ((0, ts_type_safety_utils_1.isFunction)(transformItem)) item = transformItem(item); return item; }; exports.transformItem = transformItem;