@jplorg/jpl 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) hide show
  1. package/README.md +34 -0
  2. package/lib/applyDefaults.js +34 -0
  3. package/lib/builtins/funcContains.js +25 -0
  4. package/lib/builtins/funcEndsWith.js +21 -0
  5. package/lib/builtins/funcError.js +11 -0
  6. package/lib/builtins/funcFromJSON.js +26 -0
  7. package/lib/builtins/funcHas.js +24 -0
  8. package/lib/builtins/funcIn.js +24 -0
  9. package/lib/builtins/funcKeys.js +20 -0
  10. package/lib/builtins/funcLength.js +24 -0
  11. package/lib/builtins/funcNow.js +10 -0
  12. package/lib/builtins/funcStartsWith.js +21 -0
  13. package/lib/builtins/funcToJSON.js +10 -0
  14. package/lib/builtins/funcToNumber.js +26 -0
  15. package/lib/builtins/funcToString.js +10 -0
  16. package/lib/builtins/funcTrim.js +17 -0
  17. package/lib/builtins/funcTrimEnd.js +17 -0
  18. package/lib/builtins/funcTrimStart.js +17 -0
  19. package/lib/builtins/funcType.js +10 -0
  20. package/lib/builtins/funcVoid.js +10 -0
  21. package/lib/builtins/index.js +158 -0
  22. package/lib/builtins/internals.js +8 -0
  23. package/lib/builtins/math.js +40 -0
  24. package/lib/builtins/native.js +164 -0
  25. package/lib/createSingleton.js +14 -0
  26. package/lib/index.js +80 -0
  27. package/lib/interpreter/index.js +57 -0
  28. package/lib/interpreter/parse.js +2377 -0
  29. package/lib/interpreter/parseFunction.js +24 -0
  30. package/lib/interpreter/system.js +10 -0
  31. package/lib/interpreter/util.js +349 -0
  32. package/lib/library/apply.js +142 -0
  33. package/lib/library/definition.js +9 -0
  34. package/lib/library/errors/adaptErrors.js +34 -0
  35. package/lib/library/errors/enclosure.js +16 -0
  36. package/lib/library/errors/error.js +18 -0
  37. package/lib/library/errors/execution.js +20 -0
  38. package/lib/library/errors/fatal.js +15 -0
  39. package/lib/library/errors/runtime.js +78 -0
  40. package/lib/library/errors/syntax.js +15 -0
  41. package/lib/library/functions.js +82 -0
  42. package/lib/library/index.js +336 -0
  43. package/lib/library/mux.js +106 -0
  44. package/lib/library/ops/index.js +60 -0
  45. package/lib/library/ops/op.js +180 -0
  46. package/lib/library/ops/opa.js +41 -0
  47. package/lib/library/ops/opc.js +59 -0
  48. package/lib/library/ops/opm.js +50 -0
  49. package/lib/library/ops/opu.js +77 -0
  50. package/lib/library/runtimeScope.js +38 -0
  51. package/lib/library/runtimeSignal.js +72 -0
  52. package/lib/library/types.js +305 -0
  53. package/lib/program/index.js +72 -0
  54. package/lib/program/ops/index.js +61 -0
  55. package/lib/program/ops/opAccess/index.js +55 -0
  56. package/lib/program/ops/opAccess/opaField.js +50 -0
  57. package/lib/program/ops/opAccess/opaFunction.js +50 -0
  58. package/lib/program/ops/opAccess/opaIter.js +31 -0
  59. package/lib/program/ops/opAccess/opaSlice.js +44 -0
  60. package/lib/program/ops/opAnd.js +30 -0
  61. package/lib/program/ops/opArrayConstructor.js +20 -0
  62. package/lib/program/ops/opAssignment/index.js +90 -0
  63. package/lib/program/ops/opAssignment/opaAssignField.js +125 -0
  64. package/lib/program/ops/opAssignment/opaAssignIter.js +69 -0
  65. package/lib/program/ops/opAssignment/opaAssignSlice.js +99 -0
  66. package/lib/program/ops/opAssignment/opuAddition.js +31 -0
  67. package/lib/program/ops/opAssignment/opuDivision.js +31 -0
  68. package/lib/program/ops/opAssignment/opuMultiplication.js +31 -0
  69. package/lib/program/ops/opAssignment/opuNullCoalescence.js +25 -0
  70. package/lib/program/ops/opAssignment/opuRemainder.js +31 -0
  71. package/lib/program/ops/opAssignment/opuSet.js +19 -0
  72. package/lib/program/ops/opAssignment/opuSubtraction.js +31 -0
  73. package/lib/program/ops/opAssignment/opuUpdate.js +19 -0
  74. package/lib/program/ops/opCalculation/index.js +57 -0
  75. package/lib/program/ops/opCalculation/opmAddition.js +49 -0
  76. package/lib/program/ops/opCalculation/opmDivision.js +42 -0
  77. package/lib/program/ops/opCalculation/opmMultiplication.js +40 -0
  78. package/lib/program/ops/opCalculation/opmRemainder.js +34 -0
  79. package/lib/program/ops/opCalculation/opmSubtraction.js +53 -0
  80. package/lib/program/ops/opComparison/index.js +59 -0
  81. package/lib/program/ops/opComparison/opcEqual.js +19 -0
  82. package/lib/program/ops/opComparison/opcGreater.js +19 -0
  83. package/lib/program/ops/opComparison/opcGreaterEqual.js +19 -0
  84. package/lib/program/ops/opComparison/opcLess.js +19 -0
  85. package/lib/program/ops/opComparison/opcLessEqual.js +19 -0
  86. package/lib/program/ops/opComparison/opcUnequal.js +19 -0
  87. package/lib/program/ops/opConstant.js +18 -0
  88. package/lib/program/ops/opConstantFalse.js +16 -0
  89. package/lib/program/ops/opConstantNull.js +16 -0
  90. package/lib/program/ops/opConstantTrue.js +16 -0
  91. package/lib/program/ops/opFunctionDefinition.js +21 -0
  92. package/lib/program/ops/opIf.js +38 -0
  93. package/lib/program/ops/opInterpolatedString.js +24 -0
  94. package/lib/program/ops/opNegation.js +25 -0
  95. package/lib/program/ops/opNot.js +16 -0
  96. package/lib/program/ops/opNullCoalescence.js +34 -0
  97. package/lib/program/ops/opNumber.js +18 -0
  98. package/lib/program/ops/opObjectConstructor.js +37 -0
  99. package/lib/program/ops/opOr.js +30 -0
  100. package/lib/program/ops/opOutputConcat.js +19 -0
  101. package/lib/program/ops/opString.js +18 -0
  102. package/lib/program/ops/opTry.js +37 -0
  103. package/lib/program/ops/opVariable.js +20 -0
  104. package/lib/program/ops/opVariableDefinition.js +24 -0
  105. package/lib/program/ops/opVoid.js +16 -0
  106. package/lib/program/ops/utils.js +35 -0
  107. package/lib/runtime/index.js +258 -0
  108. package/package.json +67 -0
  109. package/repl.js +212 -0
  110. package/src/applyDefaults.js +35 -0
  111. package/src/builtins/funcContains.js +27 -0
  112. package/src/builtins/funcEndsWith.js +21 -0
  113. package/src/builtins/funcError.js +7 -0
  114. package/src/builtins/funcFromJSON.js +24 -0
  115. package/src/builtins/funcHas.js +25 -0
  116. package/src/builtins/funcIn.js +25 -0
  117. package/src/builtins/funcKeys.js +20 -0
  118. package/src/builtins/funcLength.js +26 -0
  119. package/src/builtins/funcNow.js +5 -0
  120. package/src/builtins/funcStartsWith.js +21 -0
  121. package/src/builtins/funcToJSON.js +5 -0
  122. package/src/builtins/funcToNumber.js +25 -0
  123. package/src/builtins/funcToString.js +5 -0
  124. package/src/builtins/funcTrim.js +16 -0
  125. package/src/builtins/funcTrimEnd.js +16 -0
  126. package/src/builtins/funcTrimStart.js +16 -0
  127. package/src/builtins/funcType.js +5 -0
  128. package/src/builtins/funcVoid.js +5 -0
  129. package/src/builtins/index.js +145 -0
  130. package/src/builtins/internals.js +9 -0
  131. package/src/builtins/math.js +44 -0
  132. package/src/builtins/native.js +19 -0
  133. package/src/createSingleton.js +9 -0
  134. package/src/index.js +44 -0
  135. package/src/interpreter/index.js +48 -0
  136. package/src/interpreter/parse.js +1473 -0
  137. package/src/interpreter/parseFunction.js +20 -0
  138. package/src/interpreter/system.js +5 -0
  139. package/src/interpreter/util.js +237 -0
  140. package/src/library/apply.js +135 -0
  141. package/src/library/definition.js +3 -0
  142. package/src/library/errors/adaptErrors.js +28 -0
  143. package/src/library/errors/enclosure.js +11 -0
  144. package/src/library/errors/error.js +14 -0
  145. package/src/library/errors/execution.js +15 -0
  146. package/src/library/errors/fatal.js +10 -0
  147. package/src/library/errors/runtime.js +71 -0
  148. package/src/library/errors/syntax.js +10 -0
  149. package/src/library/functions.js +73 -0
  150. package/src/library/index.js +41 -0
  151. package/src/library/mux.js +98 -0
  152. package/src/library/ops/index.js +5 -0
  153. package/src/library/ops/op.js +174 -0
  154. package/src/library/ops/opa.js +35 -0
  155. package/src/library/ops/opc.js +53 -0
  156. package/src/library/ops/opm.js +44 -0
  157. package/src/library/ops/opu.js +71 -0
  158. package/src/library/runtimeScope.js +35 -0
  159. package/src/library/runtimeSignal.js +67 -0
  160. package/src/library/types.js +299 -0
  161. package/src/program/index.js +80 -0
  162. package/src/program/ops/index.js +82 -0
  163. package/src/program/ops/opAccess/index.js +55 -0
  164. package/src/program/ops/opAccess/opaField.js +58 -0
  165. package/src/program/ops/opAccess/opaFunction.js +52 -0
  166. package/src/program/ops/opAccess/opaIter.js +31 -0
  167. package/src/program/ops/opAccess/opaSlice.js +58 -0
  168. package/src/program/ops/opAnd.js +32 -0
  169. package/src/program/ops/opArrayConstructor.js +16 -0
  170. package/src/program/ops/opAssignment/index.js +102 -0
  171. package/src/program/ops/opAssignment/opaAssignField.js +156 -0
  172. package/src/program/ops/opAssignment/opaAssignIter.js +74 -0
  173. package/src/program/ops/opAssignment/opaAssignSlice.js +157 -0
  174. package/src/program/ops/opAssignment/opuAddition.js +29 -0
  175. package/src/program/ops/opAssignment/opuDivision.js +29 -0
  176. package/src/program/ops/opAssignment/opuMultiplication.js +29 -0
  177. package/src/program/ops/opAssignment/opuNullCoalescence.js +26 -0
  178. package/src/program/ops/opAssignment/opuRemainder.js +29 -0
  179. package/src/program/ops/opAssignment/opuSet.js +15 -0
  180. package/src/program/ops/opAssignment/opuSubtraction.js +29 -0
  181. package/src/program/ops/opAssignment/opuUpdate.js +15 -0
  182. package/src/program/ops/opCalculation/index.js +64 -0
  183. package/src/program/ops/opCalculation/opmAddition.js +63 -0
  184. package/src/program/ops/opCalculation/opmDivision.js +47 -0
  185. package/src/program/ops/opCalculation/opmMultiplication.js +52 -0
  186. package/src/program/ops/opCalculation/opmRemainder.js +49 -0
  187. package/src/program/ops/opCalculation/opmSubtraction.js +72 -0
  188. package/src/program/ops/opComparison/index.js +67 -0
  189. package/src/program/ops/opComparison/opcEqual.js +17 -0
  190. package/src/program/ops/opComparison/opcGreater.js +17 -0
  191. package/src/program/ops/opComparison/opcGreaterEqual.js +17 -0
  192. package/src/program/ops/opComparison/opcLess.js +17 -0
  193. package/src/program/ops/opComparison/opcLessEqual.js +17 -0
  194. package/src/program/ops/opComparison/opcUnequal.js +17 -0
  195. package/src/program/ops/opConstant.js +13 -0
  196. package/src/program/ops/opConstantFalse.js +11 -0
  197. package/src/program/ops/opConstantNull.js +11 -0
  198. package/src/program/ops/opConstantTrue.js +11 -0
  199. package/src/program/ops/opFunctionDefinition.js +17 -0
  200. package/src/program/ops/opIf.js +44 -0
  201. package/src/program/ops/opInterpolatedString.js +27 -0
  202. package/src/program/ops/opNegation.js +26 -0
  203. package/src/program/ops/opNot.js +11 -0
  204. package/src/program/ops/opNullCoalescence.js +36 -0
  205. package/src/program/ops/opNumber.js +13 -0
  206. package/src/program/ops/opObjectConstructor.js +40 -0
  207. package/src/program/ops/opOr.js +32 -0
  208. package/src/program/ops/opOutputConcat.js +17 -0
  209. package/src/program/ops/opString.js +13 -0
  210. package/src/program/ops/opTry.js +38 -0
  211. package/src/program/ops/opVariable.js +17 -0
  212. package/src/program/ops/opVariableDefinition.js +18 -0
  213. package/src/program/ops/opVoid.js +11 -0
  214. package/src/program/ops/utils.js +19 -0
  215. package/src/runtime/index.js +309 -0
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _utils = require("./utils");
8
+ var _default = exports.default = {
9
+ /** { pipes: [[op]] } */
10
+ op(runtime, input, params, scope, next) {
11
+ const iter = async from => {
12
+ // Call stack decoupling - This is necessary as some browsers (i.e. Safari) have very limited call stack sizes which result in stack overflow exceptions in certain situations.
13
+ await undefined;
14
+ scope.signal.checkHealth();
15
+ if (from >= (params.pipes?.length ?? 0)) return next(true, scope);
16
+ const pipe = params.pipes[from];
17
+ return runtime.executeInstructions(pipe ?? [], [input], scope, output => {
18
+ if (!runtime.truthy(output)) return next(false, scope);
19
+ return iter(from + 1);
20
+ });
21
+ };
22
+ return iter(0);
23
+ },
24
+ /** { pipes: [function] } */
25
+ map(runtime, params) {
26
+ return {
27
+ pipes: runtime.muxOne([params.pipes], pipe => (0, _utils.call)(pipe))
28
+ };
29
+ }
30
+ };
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _utils = require("./utils");
8
+ var _default = exports.default = {
9
+ /** { pipe: [op] } */
10
+ async op(runtime, input, params, scope, next) {
11
+ const outputs = await runtime.executeInstructions(params.pipe ?? [], [input], scope);
12
+ return next(outputs, scope);
13
+ },
14
+ /** { pipe: function } */
15
+ map(runtime, params) {
16
+ return {
17
+ pipe: (0, _utils.call)(params.pipe)
18
+ };
19
+ }
20
+ };
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _library = require("../../../library");
8
+ var _utils = require("../utils");
9
+ var _opaAssignField = _interopRequireDefault(require("./opaAssignField"));
10
+ var _opaAssignIter = _interopRequireDefault(require("./opaAssignIter"));
11
+ var _opaAssignSlice = _interopRequireDefault(require("./opaAssignSlice"));
12
+ var _opuAddition = _interopRequireDefault(require("./opuAddition"));
13
+ var _opuDivision = _interopRequireDefault(require("./opuDivision"));
14
+ var _opuMultiplication = _interopRequireDefault(require("./opuMultiplication"));
15
+ var _opuNullCoalescence = _interopRequireDefault(require("./opuNullCoalescence"));
16
+ var _opuRemainder = _interopRequireDefault(require("./opuRemainder"));
17
+ var _opuSet = _interopRequireDefault(require("./opuSet"));
18
+ var _opuSubtraction = _interopRequireDefault(require("./opuSubtraction"));
19
+ var _opuUpdate = _interopRequireDefault(require("./opuUpdate"));
20
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
+ var _default = exports.default = {
22
+ /** { pipe: [op], selectors: [opa], assignment: [opu] } */
23
+ op(runtime, input, params, scope, next) {
24
+ const iter = async (from, value) => {
25
+ // Call stack decoupling - This is necessary as some browsers (i.e. Safari) have very limited call stack sizes which result in stack overflow exceptions in certain situations.
26
+ await undefined;
27
+ scope.signal.checkHealth();
28
+ if (from >= (params.selectors?.length ?? 0)) {
29
+ const {
30
+ op,
31
+ params: opParams
32
+ } = params.assignment ?? {};
33
+ const operator = opus[op];
34
+ if (!operator) throw new _library.JPLFatalError(`invalid OPU '${op}'`);
35
+ return operator.op(runtime, input, value, opParams ?? {}, scope, output => [output]);
36
+ }
37
+ const {
38
+ op,
39
+ params: opParams
40
+ } = params.selectors[from];
41
+ const operator = opasAssign[op];
42
+ if (!operator) throw new _library.JPLFatalError(`invalid OPA '${op}' (assignment)`);
43
+ return operator.op(runtime, input, value, opParams ?? {}, scope, output => iter(from + 1, output));
44
+ };
45
+ return runtime.executeInstructions(params.pipe ?? [], [input], scope, async output => runtime.muxAll([await iter(0, output)], result => next(result === undefined ? output : result, scope)));
46
+ },
47
+ /** { pipe: function, selectors: [opa], assignment: opu } */
48
+ map(runtime, params) {
49
+ return {
50
+ pipe: (0, _utils.call)(params.pipe),
51
+ selectors: runtime.muxOne([params.selectors], ({
52
+ op,
53
+ params: opParams
54
+ }) => {
55
+ const operator = opasAssign[op];
56
+ if (!operator) throw new _library.JPLFatalError(`invalid OPA '${op}' (assignment)`);
57
+ return {
58
+ op: runtime.assertType(op, 'string'),
59
+ params: operator.map(runtime, opParams)
60
+ };
61
+ }),
62
+ assignment: (({
63
+ op,
64
+ params: opParams
65
+ }) => {
66
+ const operator = opus[op];
67
+ if (!operator) throw new _library.JPLFatalError(`invalid OPU '${op}'`);
68
+ return {
69
+ op: runtime.assertType(op, 'string'),
70
+ params: operator.map(runtime, opParams)
71
+ };
72
+ })(params.assignment)
73
+ };
74
+ }
75
+ };
76
+ const opasAssign = {
77
+ [_library.OPA_FIELD]: _opaAssignField.default,
78
+ [_library.OPA_ITER]: _opaAssignIter.default,
79
+ [_library.OPA_SLICE]: _opaAssignSlice.default
80
+ };
81
+ const opus = {
82
+ [_library.OPU_ADDITION]: _opuAddition.default,
83
+ [_library.OPU_DIVISION]: _opuDivision.default,
84
+ [_library.OPU_MULTIPLICATION]: _opuMultiplication.default,
85
+ [_library.OPU_NULL_COALESCENCE]: _opuNullCoalescence.default,
86
+ [_library.OPU_REMAINDER]: _opuRemainder.default,
87
+ [_library.OPU_SET]: _opuSet.default,
88
+ [_library.OPU_SUBTRACTION]: _opuSubtraction.default,
89
+ [_library.OPU_UPDATE]: _opuUpdate.default
90
+ };
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _library = require("../../../library");
8
+ var _utils = require("../utils");
9
+ var _default = exports.default = {
10
+ /** { pipe: [op], optional: boolean } */
11
+ async op(runtime, input, target, params, scope, next) {
12
+ let items;
13
+ const vt = runtime.unwrapValue(target);
14
+ const tt = runtime.type(target);
15
+ switch (tt) {
16
+ case 'null':
17
+ case 'object':
18
+ case 'array':
19
+ items = vt;
20
+ break;
21
+ case 'string':
22
+ items = [...vt];
23
+ break;
24
+ default:
25
+ if (params.optional) return [undefined];
26
+ throw new _library.JPLTypeError('cannot access fields of %s (%*<100v) (assignment)', tt, vt);
27
+ }
28
+ const fields = await runtime.executeInstructions(params.pipe ?? [], [input], scope, output => [output]);
29
+ const iter = async (from, source) => {
30
+ // Call stack decoupling - This is necessary as some browsers (i.e. Safari) have very limited call stack sizes which result in stack overflow exceptions in certain situations.
31
+ await undefined;
32
+ scope.signal.checkHealth();
33
+ if (from >= fields.length) return [source];
34
+ const t = tt === 'string' ? tt : runtime.type(source);
35
+ const field = runtime.unwrapValue(fields[from]);
36
+ const tf = runtime.type(field);
37
+ switch (t) {
38
+ case 'null':
39
+ {
40
+ switch (tf) {
41
+ case 'string':
42
+ return runtime.muxAll([await next(null)], output => {
43
+ if (output === undefined) return iter(from + 1, source);
44
+ return iter(from + 1, {
45
+ [field]: output
46
+ });
47
+ });
48
+ case 'number':
49
+ {
50
+ const i = Math.trunc(field);
51
+ return runtime.muxAll([await next(null)], output => {
52
+ if (output === undefined) return iter(from + 1, source);
53
+ return iter(from + 1, (0, _library.applyArray)([], [[i, output]]));
54
+ });
55
+ }
56
+ default:
57
+ }
58
+ break;
59
+ }
60
+ case 'object':
61
+ if (tf === 'string') {
62
+ const item = source[field];
63
+ return runtime.muxAll([await next(item ?? null)], output => {
64
+ if (output === undefined) return iter(from + 1, source);
65
+ return iter(from + 1, (0, _library.applyObject)(source, [[field, output]]));
66
+ });
67
+ }
68
+ break;
69
+ case 'array':
70
+ if (tf === 'number') {
71
+ const i = Math.trunc(field);
72
+ const item = source[i >= 0 ? i : source.length + i];
73
+ return runtime.muxAll([await next(item ?? null)], output => {
74
+ if (output === undefined) return iter(from + 1, source);
75
+ return iter(from + 1, (0, _library.applyArray)(source, [[i, output]]));
76
+ });
77
+ }
78
+ break;
79
+ case 'string':
80
+ if (tf === 'number') {
81
+ const i = Math.trunc(field);
82
+ const item = source[i >= 0 ? i : source.length + i];
83
+ return runtime.muxAll([await next(item ?? null)], output => {
84
+ if (output === undefined) return iter(from + 1, source);
85
+ const r = runtime.unwrapValue(output);
86
+ const tr = runtime.type(r);
87
+ switch (tr) {
88
+ case 'null':
89
+ case 'string':
90
+ return iter(from + 1, (0, _library.applyArray)(source, [[i, output ?? ' ']], ' '));
91
+ default:
92
+ }
93
+ throw new _library.JPLTypeError('cannot assign %s (%*<100v) to string (%*<100v)', tr, r, source.join(''));
94
+ });
95
+ }
96
+ break;
97
+ default:
98
+ }
99
+ if (params.optional) return iter(from + 1, source);
100
+ throw new _library.JPLTypeError('cannot access field of %s (%*<100v) with %s (%*<100v) (assignment)', t, t === 'string' ? source.join('') : source, tf, field);
101
+ };
102
+ return runtime.muxAsync([await iter(0, items)], results => {
103
+ if (items === results) return target;
104
+ const t = tt === 'string' ? tt : runtime.type(results);
105
+ switch (t) {
106
+ case 'null':
107
+ return undefined;
108
+ case 'object':
109
+ case 'array':
110
+ return runtime.alterValue(target, () => results);
111
+ case 'string':
112
+ return runtime.alterValue(target, () => results.join(''));
113
+ default:
114
+ }
115
+ return undefined;
116
+ });
117
+ },
118
+ /** { pipe: function, optional: boolean } */
119
+ map(runtime, params) {
120
+ return {
121
+ pipe: (0, _utils.call)(params.pipe),
122
+ optional: runtime.assertType(params.optional, 'boolean')
123
+ };
124
+ }
125
+ };
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _library = require("../../../library");
8
+ var _default = exports.default = {
9
+ /** { optional: boolean } */
10
+ async op(runtime, input, target, params, scope, next) {
11
+ const vt = runtime.unwrapValue(target);
12
+ const tt = runtime.type(vt);
13
+ switch (tt) {
14
+ case 'object':
15
+ {
16
+ const items = Object.entries(vt);
17
+ const outputs = await runtime.muxAsync([items], async item => runtime.muxAsync([await next(item[1] ?? null)], output => {
18
+ if (output === undefined) return item;
19
+ return [item[0], output];
20
+ }));
21
+ return runtime.muxAsync([(0, _library.applyCombinations)(items, outputs)], results => {
22
+ if (items === results) return target;
23
+ return runtime.alterValue(target, () => Object.fromEntries(results));
24
+ });
25
+ }
26
+ case 'array':
27
+ {
28
+ const items = vt;
29
+ const outputs = await runtime.muxAsync([items], async item => runtime.muxAsync([await next(item ?? null)], output => {
30
+ if (output === undefined) return item;
31
+ return output;
32
+ }));
33
+ return runtime.muxAsync([(0, _library.applyCombinations)(items, outputs)], results => {
34
+ if (items === results) return target;
35
+ return runtime.alterValue(target, () => results);
36
+ });
37
+ }
38
+ case 'string':
39
+ {
40
+ const items = [...vt];
41
+ const outputs = await runtime.muxAsync([items], async item => runtime.muxAsync([await next(item)], output => {
42
+ if (output === undefined) return item;
43
+ const r = runtime.unwrapValue(output);
44
+ const tr = runtime.type(r);
45
+ switch (tr) {
46
+ case 'null':
47
+ case 'string':
48
+ return r ?? ' ';
49
+ default:
50
+ }
51
+ throw new _library.JPLTypeError('cannot assign %s (%*<100v) to string (%*<100v)', tr, r, vt);
52
+ }));
53
+ return runtime.muxAsync([(0, _library.applyCombinations)(items, outputs)], results => {
54
+ if (items === results) return target;
55
+ return runtime.alterValue(target, () => results.join(''));
56
+ });
57
+ }
58
+ default:
59
+ }
60
+ if (params.optional) return [undefined];
61
+ throw new _library.JPLTypeError('cannot iterate over %s (%*<100v) (assignment)', tt, vt);
62
+ },
63
+ /** { optional: boolean } */
64
+ map(runtime, params) {
65
+ return {
66
+ optional: runtime.assertType(params.optional, 'boolean')
67
+ };
68
+ }
69
+ };
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _library = require("../../../library");
8
+ var _utils = require("../utils");
9
+ function shallowCompareArrays(a, b) {
10
+ if (a.length !== b.length) return false;
11
+ return a.every((v, i) => v === b[i]);
12
+ }
13
+ var _default = exports.default = {
14
+ /** { from: [op], to: [op], optional: boolean } */
15
+ async op(runtime, input, target, params, scope, next) {
16
+ const [froms, tos] = await Promise.all([runtime.executeInstructions(params.from ?? [], [input], scope), runtime.executeInstructions(params.to ?? [], [input], scope)]);
17
+ const ranges = runtime.muxOne([runtime.unwrapValues(froms), runtime.unwrapValues(tos)], (from, to) => [from, to]);
18
+ const iter = async (from, source) => {
19
+ // Call stack decoupling - This is necessary as some browsers (i.e. Safari) have very limited call stack sizes which result in stack overflow exceptions in certain situations.
20
+ await undefined;
21
+ scope.signal.checkHealth();
22
+ if (from >= ranges.length) return [source];
23
+ const v = runtime.unwrapValue(source);
24
+ const tv = runtime.type(source);
25
+ const [start, end] = ranges[from];
26
+ const ts = runtime.type(start);
27
+ const te = runtime.type(end);
28
+ switch (tv) {
29
+ case 'array':
30
+ if (['number', 'null'].includes(ts) && ['number', 'null'].includes(te)) {
31
+ return runtime.muxAll([await next(v.slice(Math.trunc(start ?? 0), Math.trunc(end ?? v.length)))], async output => {
32
+ if (output === undefined) return iter(from + 1, source);
33
+ return iter(from + 1, await runtime.alterValue(source, value => {
34
+ const result = runtime.unwrapValue(output);
35
+ const tr = runtime.type(result);
36
+ switch (tr) {
37
+ case 'null':
38
+ case 'array':
39
+ {
40
+ let s = Math.trunc(start ?? 0);
41
+ let e = Math.trunc(end ?? value.length);
42
+ s = s >= 0 ? Math.min(value.length, s) : Math.max(0, value.length + s);
43
+ e = Math.max(s, e >= 0 ? Math.min(value.length, e) : Math.max(0, value.length + e));
44
+ if (shallowCompareArrays(value.slice(s, e), result ?? [])) return value;
45
+ const c = [...value];
46
+ c.splice(s, e - s, ...(result ?? []));
47
+ return c;
48
+ }
49
+ default:
50
+ }
51
+ throw new _library.JPLTypeError('cannot assign %s (%*<100v) to slice of %s (%*<100v)', tr, result, tv, value);
52
+ }));
53
+ });
54
+ }
55
+ break;
56
+ case 'string':
57
+ if (['number', 'null'].includes(ts) && ['number', 'null'].includes(te)) {
58
+ const chars = [...v];
59
+ return runtime.muxAll([await next(chars.slice(Math.trunc(start ?? 0), Math.trunc(end ?? chars.length)).join(''))], async output => {
60
+ if (output === undefined) return iter(from + 1, source);
61
+ return iter(from + 1, await runtime.alterValue(source, value => {
62
+ const result = runtime.unwrapValue(output);
63
+ const tr = runtime.type(result);
64
+ switch (tr) {
65
+ case 'null':
66
+ case 'string':
67
+ {
68
+ const chars = [...value];
69
+ let s = Math.trunc(start ?? 0);
70
+ let e = Math.trunc(end ?? chars.length);
71
+ s = s >= 0 ? Math.min(chars.length, s) : Math.max(0, chars.length + s);
72
+ e = Math.max(s, e >= 0 ? Math.min(chars.length, e) : Math.max(0, chars.length + e));
73
+ if (shallowCompareArrays(chars.slice(s, e), result ?? [])) return value;
74
+ chars.splice(s, e - s, ...(result ?? []));
75
+ return chars.join('');
76
+ }
77
+ default:
78
+ }
79
+ throw new _library.JPLTypeError('cannot assign %s (%*<100v) to slice of %s (%*<100v)', tr, result, tv, value);
80
+ }));
81
+ });
82
+ }
83
+ break;
84
+ default:
85
+ }
86
+ if (params.optional) return iter(from + 1, source);
87
+ throw new _library.JPLTypeError('cannot slice %s (%*<100v) with %s (%*<100v) and %s (%*<100v) (assignment)', tv, v, ts, start, te, end);
88
+ };
89
+ return runtime.muxOne([await iter(0, target)], output => runtime.type(output) === 'null' ? undefined : output);
90
+ },
91
+ /** { from: function, to: function, optional: boolean } */
92
+ map(runtime, params) {
93
+ return {
94
+ from: (0, _utils.call)(params.from),
95
+ to: (0, _utils.call)(params.to),
96
+ optional: runtime.assertType(params.optional, 'boolean')
97
+ };
98
+ }
99
+ };
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _library = require("../../../library");
8
+ var _utils = require("../utils");
9
+ var _default = exports.default = {
10
+ /** { pipe: [op] } */
11
+ op(runtime, input, target, params, scope, next) {
12
+ return runtime.executeInstructions([{
13
+ op: _library.OP_CALCULATION,
14
+ params: {
15
+ pipe: (0, _utils.constant)(target),
16
+ operations: [{
17
+ op: _library.OPM_ADDITION,
18
+ params: {
19
+ by: params.pipe ?? []
20
+ }
21
+ }]
22
+ }
23
+ }], [input], scope, next);
24
+ },
25
+ /** { pipe: function } */
26
+ map(runtime, params) {
27
+ return {
28
+ pipe: (0, _utils.call)(params.pipe)
29
+ };
30
+ }
31
+ };
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _library = require("../../../library");
8
+ var _utils = require("../utils");
9
+ var _default = exports.default = {
10
+ /** { pipe: [op] } */
11
+ op(runtime, input, target, params, scope, next) {
12
+ return runtime.executeInstructions([{
13
+ op: _library.OP_CALCULATION,
14
+ params: {
15
+ pipe: (0, _utils.constant)(target),
16
+ operations: [{
17
+ op: _library.OPM_DIVISION,
18
+ params: {
19
+ by: params.pipe ?? []
20
+ }
21
+ }]
22
+ }
23
+ }], [input], scope, next);
24
+ },
25
+ /** { pipe: function } */
26
+ map(runtime, params) {
27
+ return {
28
+ pipe: (0, _utils.call)(params.pipe)
29
+ };
30
+ }
31
+ };
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _library = require("../../../library");
8
+ var _utils = require("../utils");
9
+ var _default = exports.default = {
10
+ /** { pipe: [op] } */
11
+ op(runtime, input, target, params, scope, next) {
12
+ return runtime.executeInstructions([{
13
+ op: _library.OP_CALCULATION,
14
+ params: {
15
+ pipe: (0, _utils.constant)(target),
16
+ operations: [{
17
+ op: _library.OPM_MULTIPLICATION,
18
+ params: {
19
+ by: params.pipe ?? []
20
+ }
21
+ }]
22
+ }
23
+ }], [input], scope, next);
24
+ },
25
+ /** { pipe: function } */
26
+ map(runtime, params) {
27
+ return {
28
+ pipe: (0, _utils.call)(params.pipe)
29
+ };
30
+ }
31
+ };
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _library = require("../../../library");
8
+ var _utils = require("../utils");
9
+ var _default = exports.default = {
10
+ /** { pipe: [op] } */
11
+ op(runtime, input, target, params, scope, next) {
12
+ return runtime.executeInstructions([{
13
+ op: _library.OP_NULL_COALESCENCE,
14
+ params: {
15
+ pipes: [(0, _utils.constant)(target), params.pipe ?? []]
16
+ }
17
+ }], [input], scope, next);
18
+ },
19
+ /** { pipe: function } */
20
+ map(runtime, params) {
21
+ return {
22
+ pipe: (0, _utils.call)(params.pipe)
23
+ };
24
+ }
25
+ };
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _library = require("../../../library");
8
+ var _utils = require("../utils");
9
+ var _default = exports.default = {
10
+ /** { pipe: [op] } */
11
+ op(runtime, input, target, params, scope, next) {
12
+ return runtime.executeInstructions([{
13
+ op: _library.OP_CALCULATION,
14
+ params: {
15
+ pipe: (0, _utils.constant)(target),
16
+ operations: [{
17
+ op: _library.OPM_REMAINDER,
18
+ params: {
19
+ by: params.pipe ?? []
20
+ }
21
+ }]
22
+ }
23
+ }], [input], scope, next);
24
+ },
25
+ /** { pipe: function } */
26
+ map(runtime, params) {
27
+ return {
28
+ pipe: (0, _utils.call)(params.pipe)
29
+ };
30
+ }
31
+ };
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _utils = require("../utils");
8
+ var _default = exports.default = {
9
+ /** { pipe: [op] } */
10
+ op(runtime, input, target, params, scope, next) {
11
+ return runtime.executeInstructions(params.pipe ?? [], [input], scope, next);
12
+ },
13
+ /** { pipe: function } */
14
+ map(runtime, params) {
15
+ return {
16
+ pipe: (0, _utils.call)(params.pipe)
17
+ };
18
+ }
19
+ };
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _library = require("../../../library");
8
+ var _utils = require("../utils");
9
+ var _default = exports.default = {
10
+ /** { pipe: [op] } */
11
+ op(runtime, input, target, params, scope, next) {
12
+ return runtime.executeInstructions([{
13
+ op: _library.OP_CALCULATION,
14
+ params: {
15
+ pipe: (0, _utils.constant)(target),
16
+ operations: [{
17
+ op: _library.OPM_SUBTRACTION,
18
+ params: {
19
+ by: params.pipe ?? []
20
+ }
21
+ }]
22
+ }
23
+ }], [input], scope, next);
24
+ },
25
+ /** { pipe: function } */
26
+ map(runtime, params) {
27
+ return {
28
+ pipe: (0, _utils.call)(params.pipe)
29
+ };
30
+ }
31
+ };
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _utils = require("../utils");
8
+ var _default = exports.default = {
9
+ /** { pipe: [op] } */
10
+ op(runtime, input, target, params, scope, next) {
11
+ return runtime.executeInstructions(params.pipe ?? [], [target], scope, next);
12
+ },
13
+ /** { pipe: function } */
14
+ map(runtime, params) {
15
+ return {
16
+ pipe: (0, _utils.call)(params.pipe)
17
+ };
18
+ }
19
+ };