UNPKG

cspace-ui

Version:
64 lines (52 loc) 2.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = exports.createInvocationData = void 0; var _get = _interopRequireDefault(require("lodash/get")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } const prepareParams = params => { if (params) { const paramPairs = Object.keys(params).map(key => ({ key, value: params[key] })); if (paramPairs.length > 0) { return { param: paramPairs }; } } return undefined; }; const createInvocationData = (config, invocationDescriptor, params) => { const { mode, recordType: invocationRecordType, csid: invocationCsid } = invocationDescriptor.toJS(); const invocationContext = { mode, params: prepareParams(params), docType: (0, _get.default)(config, ['recordTypes', invocationRecordType, 'serviceConfig', 'objectName']) }; if (mode === 'single') { invocationContext.singleCSID = invocationCsid; } else if (mode === 'list') { invocationContext.listCSIDs = { csid: invocationCsid }; } else if (mode === 'group') { invocationContext.groupCSID = invocationCsid; } return { 'ns2:invocationContext': _objectSpread({ '@xmlns:ns2': 'http://collectionspace.org/services/common/invocable' }, invocationContext) }; }; exports.createInvocationData = createInvocationData; var _default = {}; exports.default = _default;