UNPKG

@sprucelabs/spruce-cli

Version:

Command line interface for building Spruce skills.

42 lines 1.69 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const spruce_event_utils_1 = require("@sprucelabs/spruce-event-utils"); const isEqual_1 = __importDefault(require("lodash/isEqual")); const uniqWith_1 = __importDefault(require("lodash/uniqWith")); const actionUtil = { mergeActionResults(...objects) { const isObject = (obj) => obj && typeof obj === 'object'; return objects.reduce((prev, obj) => { Object.keys(obj || {}).forEach((key) => { const pVal = prev[key]; const oVal = obj[key]; if (Array.isArray(pVal) && Array.isArray(oVal)) { prev[key] = pVal.concat(...oVal); prev[key] = this.makeUnique(prev[key]); } else if (isObject(pVal) && isObject(oVal)) { prev[key] = this.mergeActionResults(pVal, oVal); } else if (typeof oVal !== 'undefined') { prev[key] = oVal; } }); return prev; }, {}); }, makeUnique(val) { return (0, uniqWith_1.default)(val, (a, b) => { return (0, isEqual_1.default)(a, b) || (a.path && b.path && a.path === b.path); }); }, assertNoErrorsInResponse(response) { if (response.totalContracts > 0) { spruce_event_utils_1.eventResponseUtil.getFirstResponseOrThrow(response); } }, }; exports.default = actionUtil; //# sourceMappingURL=action.utility.js.map