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.

45 lines (44 loc) 1.78 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.unmarshallOutput = exports.marshallInput = void 0; const util_dynamodb_1 = require("@aws-sdk/util-dynamodb"); const processObj = (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; }; const processKeyInObj = (obj, processFunc, children) => { if (Array.isArray(obj)) { return obj.map((item) => processObj(item, processFunc, children)); } return processObj(obj, processFunc, children); }; const processKeysInObj = (obj, processFunc, keyNodes) => keyNodes.reduce((acc, { key, children }) => ({ ...acc, [key]: processKeyInObj(acc[key], processFunc, children), }), obj); const processAllKeysInObj = (obj, processFunc, children) => Object.entries(obj).reduce((acc, [key, value]) => ({ ...acc, [key]: processKeyInObj(value, processFunc, children), }), {}); const marshallInput = (obj, keyNodes, options) => { const marshallFunc = (toMarshall) => util_dynamodb_1.marshall(toMarshall, options); return processKeysInObj(obj, marshallFunc, keyNodes); }; exports.marshallInput = marshallInput; const unmarshallOutput = (obj, keyNodes, options) => { const unmarshallFunc = (toMarshall) => util_dynamodb_1.unmarshall(toMarshall, options); return processKeysInObj(obj, unmarshallFunc, keyNodes); }; exports.unmarshallOutput = unmarshallOutput;