@jplorg/jpl
Version:
JPL interpreter
37 lines (36 loc) • 1.42 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _library = require("../../library");
var _utils = require("./utils");
var _default = exports.default = {
/** { fields: [{ key: [op], value: [op], optional: boolean }] } */
async op(runtime, input, params, scope, next) {
const fields = await runtime.muxAsync([params.fields ?? []], async field => {
const [keys, values] = await Promise.all([runtime.executeInstructions(field.key ?? [], [input], scope), runtime.executeInstructions(field.value ?? [], [input], scope)]);
return runtime.muxAll([runtime.unwrapValues(keys), values], (key, value) => {
const t = runtime.type(key);
switch (t) {
case 'string':
return [[key, value]];
default:
}
if (field.optional) return [];
throw new _library.JPLTypeError('cannot use %s (%*<100v) as object key', t, key);
});
});
return runtime.muxAll(fields, (...entries) => next(Object.fromEntries(entries), scope));
},
/** { fields: [{ key: function, value: function, optional: boolean }] } */
map(runtime, params) {
return {
fields: runtime.muxOne([params.fields], entry => ({
key: (0, _utils.call)(entry.key),
value: (0, _utils.call)(entry.value),
optional: runtime.assertType(entry.optional, 'boolean')
}))
};
}
};