UNPKG

@softchef/cdk-iot-device-management

Version:

IoT device management is composed of things, thing types, thing groups, jobs, files API services. The constructs can be used independently, that are based on full-managed service to create an API Gateway & Lambda function.

47 lines (46 loc) 1.93 kB
import { __assign, __read } from "tslib"; import { marshall, unmarshall } from "@aws-sdk/util-dynamodb"; var processObj = function (obj, processFunc, children) { if (obj) { if (!children || (Array.isArray(children) && children.length === 0)) { return processFunc(obj); } else { if (Array.isArray(children)) { return processKeysInObj(obj, processFunc, children); } else { return processAllKeysInObj(obj, processFunc, children.children); } } } return undefined; }; var processKeyInObj = function (obj, processFunc, children) { if (Array.isArray(obj)) { return obj.map(function (item) { return processObj(item, processFunc, children); }); } return processObj(obj, processFunc, children); }; var processKeysInObj = function (obj, processFunc, keyNodes) { return keyNodes.reduce(function (acc, _a) { var _b; var key = _a.key, children = _a.children; return (__assign(__assign({}, acc), (_b = {}, _b[key] = processKeyInObj(acc[key], processFunc, children), _b))); }, obj); }; var processAllKeysInObj = function (obj, processFunc, children) { return Object.entries(obj).reduce(function (acc, _a) { var _b; var _c = __read(_a, 2), key = _c[0], value = _c[1]; return (__assign(__assign({}, acc), (_b = {}, _b[key] = processKeyInObj(value, processFunc, children), _b))); }, {}); }; export var marshallInput = function (obj, keyNodes, options) { var marshallFunc = function (toMarshall) { return marshall(toMarshall, options); }; return processKeysInObj(obj, marshallFunc, keyNodes); }; export var unmarshallOutput = function (obj, keyNodes, options) { var unmarshallFunc = function (toMarshall) { return unmarshall(toMarshall, options); }; return processKeysInObj(obj, unmarshallFunc, keyNodes); };