UNPKG

@jplorg/jpl

Version:
50 lines (49 loc) 1.78 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _library = require("../../../library"); var _utils = require("../utils"); var _default = exports.default = { /** { args: [[op]], bound: boolean, optional: boolean } */ async op(runtime, input, target, params, scope, next) { const value = runtime.unwrapValue(target); const t = runtime.type(value); switch (t) { case 'function': { const args = await runtime.muxAsync([params.args ?? []], arg => runtime.executeInstructions(arg ?? [], [input], scope)); return runtime.muxAll(args, async (...a) => { try { const fnNext = async output => { try { return await next(output); } catch (err) { throw new _library.JPLErrorEnclosure(err); } }; if (params.bound) { return await value(runtime, scope.signal, fnNext, a[0] ?? null, ...a.slice(1)); } return await value(runtime, scope.signal, fnNext, input, ...a); } catch (err) { if (_library.JPLErrorEnclosure.is(err)) throw err.inner; throw (0, _library.adaptError)(err); } }); } default: } if (params.optional) return []; throw new _library.JPLTypeError('cannot execute %s (%*<100v)', t, value); }, /** { args: [function], bound: boolean, optional: boolean } */ map(runtime, params) { return { args: runtime.muxOne([params.args], entry => (0, _utils.call)(entry)), bound: runtime.assertType(params.bound, 'boolean'), optional: runtime.assertType(params.optional, 'boolean') }; } };