@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,78 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.JPLZeroDivisionError = exports.JPLTypeError = exports.JPLTypeConversionError = exports.JPLReferenceError = void 0;
7
+ var _types = require("../types");
8
+ var _execution = _interopRequireDefault(require("./execution"));
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ function format(value, replacements) {
11
+ return replacements.length > 0 ? (0, _types.template)(value, ...replacements) : (0, _types.displayValue)(value);
12
+ }
13
+
14
+ /**
15
+ * JPL error type for generic runtime errors.
16
+ *
17
+ * `value` can by of any type.
18
+ * If at least one replacement is specified, the value is formatted as a template.
19
+ */
20
+ class JPLRuntimeError extends _execution.default {
21
+ constructor(value, ...replacements) {
22
+ const message = format(value, replacements);
23
+ super(message, 'JPLRuntimeError');
24
+ this.value = replacements.length > 0 ? message : (0, _types.normalize)(value);
25
+ }
26
+ }
27
+ var _default = exports.default = JPLRuntimeError;
28
+ /**
29
+ * JPL runtime error type for type errors.
30
+ *
31
+ * `value` can by of any type.
32
+ * If at least one replacement is specified, the value is formatted as a template.
33
+ */
34
+ class JPLTypeError extends JPLRuntimeError {
35
+ constructor(value, ...replacements) {
36
+ super(`TypeError - ${format(value, replacements)}`);
37
+ }
38
+ }
39
+
40
+ /**
41
+ * JPL runtime error type for reference errors.
42
+ *
43
+ * `value` can by of any type.
44
+ * If at least one replacement is specified, the value is formatted as a template.
45
+ */
46
+ exports.JPLTypeError = JPLTypeError;
47
+ class JPLReferenceError extends JPLRuntimeError {
48
+ constructor(value, ...replacements) {
49
+ super(`ReferenceError - ${format(value, replacements)}`);
50
+ }
51
+ }
52
+
53
+ /**
54
+ * JPL runtime error type for zero division errors.
55
+ *
56
+ * `value` can by of any type.
57
+ * If at least one replacement is specified, the value is formatted as a template.
58
+ */
59
+ exports.JPLReferenceError = JPLReferenceError;
60
+ class JPLZeroDivisionError extends JPLRuntimeError {
61
+ constructor(value, ...replacements) {
62
+ super(`ZeroDivisionError - ${format(value, replacements)}`);
63
+ }
64
+ }
65
+
66
+ /**
67
+ * JPL runtime error type for type conversion errors.
68
+ *
69
+ * `value` can by of any type.
70
+ * If at least one replacement is specified, the value is formatted as a template.
71
+ */
72
+ exports.JPLZeroDivisionError = JPLZeroDivisionError;
73
+ class JPLTypeConversionError extends JPLRuntimeError {
74
+ constructor(value, ...replacements) {
75
+ super(`TypeConversionError - ${format(value, replacements)}`);
76
+ }
77
+ }
78
+ exports.JPLTypeConversionError = JPLTypeConversionError;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _error = _interopRequireDefault(require("./error"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
+ /** JPL error type for syntax errors */
10
+ class JPLSyntaxError extends _error.default {
11
+ constructor(message) {
12
+ super(message, 'JPLSyntaxError');
13
+ }
14
+ }
15
+ var _default = exports.default = JPLSyntaxError;
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.nativeFunction = nativeFunction;
7
+ exports.orphanFunction = orphanFunction;
8
+ exports.scopedFunction = scopedFunction;
9
+ var _runtimeScope = _interopRequireDefault(require("./runtimeScope"));
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+ function jplEnclosure(runtime, signal, next, input, ...args) {
12
+ const {
13
+ argNames,
14
+ pipe,
15
+ scope
16
+ } = this;
17
+ return runtime.executeInstructions(pipe, [input], scope.next({
18
+ signal,
19
+ vars: Object.fromEntries(argNames.map((name, i) => [name, args[i] ?? null]))
20
+ }), next);
21
+ }
22
+
23
+ /**
24
+ * Create a scoped JPL function from the specified instructions.
25
+ *
26
+ * The function is bound to the specified scope.
27
+ *
28
+ * @param {string[]} argNames Names to bind the function arguments to
29
+ * @param {object[]} instructions Instructions to execute
30
+ * @param {JPLRuntimeScope} scope Runtime scope to bind the function to
31
+ */
32
+ function scopedFunction(argNames, instructions, scope) {
33
+ return jplEnclosure.bind({
34
+ argNames,
35
+ pipe: instructions,
36
+ scope
37
+ });
38
+ }
39
+
40
+ /**
41
+ * Create an orphan JPL function from the specified instructions.
42
+ *
43
+ * Some optional scope presets may be specified, e.g. for allowing the function access to some specified variables.
44
+ * Other than that, the function does not have access to any external variables.
45
+ *
46
+ * @param {string[]} argNames Names to bind the function arguments to
47
+ * @param {object[]} instructions Instructions to execute
48
+ * @param {{ vars: object? }} [presets] Optional scope presets
49
+ */
50
+ function orphanFunction(argNames, instructions, presets) {
51
+ return scopedFunction(argNames, instructions, new _runtimeScope.default(presets));
52
+ }
53
+
54
+ /**
55
+ * Wrap the specified synchronous function to allow it to be used as a JPL function.
56
+ *
57
+ * If your function runs asynchronous routines, you should create the function yourself.
58
+ * `next` must be called for each single result, which produces an array of results itself.
59
+ * All resulting results must be returned as a single array.
60
+ *
61
+ * It is recommended to check the provided JPLRuntimeSignal in asynchronous routines to stop the routine when execution has been canceled:
62
+ * ```
63
+ * signal.checkHealth();
64
+ * ```
65
+ *
66
+ * The following pattern can be used to merge the results of multiple asynchronous routines:
67
+ * ```
68
+ * const promises = ...;
69
+ * return runtime.muxAll([promises], async (promise) => {
70
+ * const result = await promise;
71
+ * return next(result);
72
+ * });
73
+ * ```
74
+ *
75
+ * @param {(runtime: JPLRuntime, input: any, ...args: any[]) => (Promise<any[]> | any[])} fn The function to be wrapped
76
+ */
77
+ function nativeFunction(fn) {
78
+ return async (runtime, signal, next, input, ...args) => {
79
+ const results = await fn(runtime, input, ...args);
80
+ return runtime.muxAll([results], next);
81
+ };
82
+ }
@@ -0,0 +1,336 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _exportNames = {
7
+ applyArray: true,
8
+ applyCombinations: true,
9
+ applyObject: true,
10
+ DEFINITION_VERSION: true,
11
+ DEFINITION_VERSION_MAJOR: true,
12
+ DEFINITION_VERSION_MINOR: true,
13
+ adaptError: true,
14
+ adaptErrors: true,
15
+ adaptErrorsAsync: true,
16
+ JPLErrorEnclosure: true,
17
+ JPLError: true,
18
+ JPLExecutionError: true,
19
+ JPLFatalError: true,
20
+ JPLReferenceError: true,
21
+ JPLRuntimeError: true,
22
+ JPLTypeConversionError: true,
23
+ JPLTypeError: true,
24
+ JPLZeroDivisionError: true,
25
+ JPLSyntaxError: true,
26
+ nativeFunction: true,
27
+ orphanFunction: true,
28
+ scopedFunction: true,
29
+ mux: true,
30
+ muxAll: true,
31
+ muxAsync: true,
32
+ muxOne: true,
33
+ JPLRuntimeScope: true,
34
+ JPLType: true,
35
+ assertType: true,
36
+ displayValue: true,
37
+ jplJSONStripper: true,
38
+ jplStripper: true,
39
+ jplTypedStripper: true,
40
+ jsonStripper: true,
41
+ normalize: true,
42
+ rawStripper: true,
43
+ strictDisplayValue: true,
44
+ stringify: true,
45
+ strip: true,
46
+ template: true,
47
+ typeOf: true,
48
+ typeOrder: true,
49
+ unwrap: true
50
+ };
51
+ Object.defineProperty(exports, "DEFINITION_VERSION", {
52
+ enumerable: true,
53
+ get: function () {
54
+ return _definition.DEFINITION_VERSION;
55
+ }
56
+ });
57
+ Object.defineProperty(exports, "DEFINITION_VERSION_MAJOR", {
58
+ enumerable: true,
59
+ get: function () {
60
+ return _definition.DEFINITION_VERSION_MAJOR;
61
+ }
62
+ });
63
+ Object.defineProperty(exports, "DEFINITION_VERSION_MINOR", {
64
+ enumerable: true,
65
+ get: function () {
66
+ return _definition.DEFINITION_VERSION_MINOR;
67
+ }
68
+ });
69
+ Object.defineProperty(exports, "JPLError", {
70
+ enumerable: true,
71
+ get: function () {
72
+ return _error.default;
73
+ }
74
+ });
75
+ Object.defineProperty(exports, "JPLErrorEnclosure", {
76
+ enumerable: true,
77
+ get: function () {
78
+ return _enclosure.default;
79
+ }
80
+ });
81
+ Object.defineProperty(exports, "JPLExecutionError", {
82
+ enumerable: true,
83
+ get: function () {
84
+ return _execution.default;
85
+ }
86
+ });
87
+ Object.defineProperty(exports, "JPLFatalError", {
88
+ enumerable: true,
89
+ get: function () {
90
+ return _fatal.default;
91
+ }
92
+ });
93
+ Object.defineProperty(exports, "JPLReferenceError", {
94
+ enumerable: true,
95
+ get: function () {
96
+ return _runtime.JPLReferenceError;
97
+ }
98
+ });
99
+ Object.defineProperty(exports, "JPLRuntimeError", {
100
+ enumerable: true,
101
+ get: function () {
102
+ return _runtime.default;
103
+ }
104
+ });
105
+ Object.defineProperty(exports, "JPLRuntimeScope", {
106
+ enumerable: true,
107
+ get: function () {
108
+ return _runtimeScope.default;
109
+ }
110
+ });
111
+ Object.defineProperty(exports, "JPLSyntaxError", {
112
+ enumerable: true,
113
+ get: function () {
114
+ return _syntax.default;
115
+ }
116
+ });
117
+ Object.defineProperty(exports, "JPLType", {
118
+ enumerable: true,
119
+ get: function () {
120
+ return _types.JPLType;
121
+ }
122
+ });
123
+ Object.defineProperty(exports, "JPLTypeConversionError", {
124
+ enumerable: true,
125
+ get: function () {
126
+ return _runtime.JPLTypeConversionError;
127
+ }
128
+ });
129
+ Object.defineProperty(exports, "JPLTypeError", {
130
+ enumerable: true,
131
+ get: function () {
132
+ return _runtime.JPLTypeError;
133
+ }
134
+ });
135
+ Object.defineProperty(exports, "JPLZeroDivisionError", {
136
+ enumerable: true,
137
+ get: function () {
138
+ return _runtime.JPLZeroDivisionError;
139
+ }
140
+ });
141
+ Object.defineProperty(exports, "adaptError", {
142
+ enumerable: true,
143
+ get: function () {
144
+ return _adaptErrors.adaptError;
145
+ }
146
+ });
147
+ Object.defineProperty(exports, "adaptErrors", {
148
+ enumerable: true,
149
+ get: function () {
150
+ return _adaptErrors.default;
151
+ }
152
+ });
153
+ Object.defineProperty(exports, "adaptErrorsAsync", {
154
+ enumerable: true,
155
+ get: function () {
156
+ return _adaptErrors.adaptErrorsAsync;
157
+ }
158
+ });
159
+ Object.defineProperty(exports, "applyArray", {
160
+ enumerable: true,
161
+ get: function () {
162
+ return _apply.applyArray;
163
+ }
164
+ });
165
+ Object.defineProperty(exports, "applyCombinations", {
166
+ enumerable: true,
167
+ get: function () {
168
+ return _apply.applyCombinations;
169
+ }
170
+ });
171
+ Object.defineProperty(exports, "applyObject", {
172
+ enumerable: true,
173
+ get: function () {
174
+ return _apply.applyObject;
175
+ }
176
+ });
177
+ Object.defineProperty(exports, "assertType", {
178
+ enumerable: true,
179
+ get: function () {
180
+ return _types.assertType;
181
+ }
182
+ });
183
+ Object.defineProperty(exports, "displayValue", {
184
+ enumerable: true,
185
+ get: function () {
186
+ return _types.displayValue;
187
+ }
188
+ });
189
+ Object.defineProperty(exports, "jplJSONStripper", {
190
+ enumerable: true,
191
+ get: function () {
192
+ return _types.jplJSONStripper;
193
+ }
194
+ });
195
+ Object.defineProperty(exports, "jplStripper", {
196
+ enumerable: true,
197
+ get: function () {
198
+ return _types.jplStripper;
199
+ }
200
+ });
201
+ Object.defineProperty(exports, "jplTypedStripper", {
202
+ enumerable: true,
203
+ get: function () {
204
+ return _types.jplTypedStripper;
205
+ }
206
+ });
207
+ Object.defineProperty(exports, "jsonStripper", {
208
+ enumerable: true,
209
+ get: function () {
210
+ return _types.jsonStripper;
211
+ }
212
+ });
213
+ Object.defineProperty(exports, "mux", {
214
+ enumerable: true,
215
+ get: function () {
216
+ return _mux.default;
217
+ }
218
+ });
219
+ Object.defineProperty(exports, "muxAll", {
220
+ enumerable: true,
221
+ get: function () {
222
+ return _mux.muxAll;
223
+ }
224
+ });
225
+ Object.defineProperty(exports, "muxAsync", {
226
+ enumerable: true,
227
+ get: function () {
228
+ return _mux.muxAsync;
229
+ }
230
+ });
231
+ Object.defineProperty(exports, "muxOne", {
232
+ enumerable: true,
233
+ get: function () {
234
+ return _mux.muxOne;
235
+ }
236
+ });
237
+ Object.defineProperty(exports, "nativeFunction", {
238
+ enumerable: true,
239
+ get: function () {
240
+ return _functions.nativeFunction;
241
+ }
242
+ });
243
+ Object.defineProperty(exports, "normalize", {
244
+ enumerable: true,
245
+ get: function () {
246
+ return _types.normalize;
247
+ }
248
+ });
249
+ Object.defineProperty(exports, "orphanFunction", {
250
+ enumerable: true,
251
+ get: function () {
252
+ return _functions.orphanFunction;
253
+ }
254
+ });
255
+ Object.defineProperty(exports, "rawStripper", {
256
+ enumerable: true,
257
+ get: function () {
258
+ return _types.rawStripper;
259
+ }
260
+ });
261
+ Object.defineProperty(exports, "scopedFunction", {
262
+ enumerable: true,
263
+ get: function () {
264
+ return _functions.scopedFunction;
265
+ }
266
+ });
267
+ Object.defineProperty(exports, "strictDisplayValue", {
268
+ enumerable: true,
269
+ get: function () {
270
+ return _types.strictDisplayValue;
271
+ }
272
+ });
273
+ Object.defineProperty(exports, "stringify", {
274
+ enumerable: true,
275
+ get: function () {
276
+ return _types.stringify;
277
+ }
278
+ });
279
+ Object.defineProperty(exports, "strip", {
280
+ enumerable: true,
281
+ get: function () {
282
+ return _types.strip;
283
+ }
284
+ });
285
+ Object.defineProperty(exports, "template", {
286
+ enumerable: true,
287
+ get: function () {
288
+ return _types.template;
289
+ }
290
+ });
291
+ Object.defineProperty(exports, "typeOf", {
292
+ enumerable: true,
293
+ get: function () {
294
+ return _types.typeOf;
295
+ }
296
+ });
297
+ Object.defineProperty(exports, "typeOrder", {
298
+ enumerable: true,
299
+ get: function () {
300
+ return _types.typeOrder;
301
+ }
302
+ });
303
+ Object.defineProperty(exports, "unwrap", {
304
+ enumerable: true,
305
+ get: function () {
306
+ return _types.unwrap;
307
+ }
308
+ });
309
+ var _apply = require("./apply");
310
+ var _definition = require("./definition");
311
+ var _adaptErrors = _interopRequireWildcard(require("./errors/adaptErrors"));
312
+ var _enclosure = _interopRequireDefault(require("./errors/enclosure"));
313
+ var _error = _interopRequireDefault(require("./errors/error"));
314
+ var _execution = _interopRequireDefault(require("./errors/execution"));
315
+ var _fatal = _interopRequireDefault(require("./errors/fatal"));
316
+ var _runtime = _interopRequireWildcard(require("./errors/runtime"));
317
+ var _syntax = _interopRequireDefault(require("./errors/syntax"));
318
+ var _functions = require("./functions");
319
+ var _mux = _interopRequireWildcard(require("./mux"));
320
+ var _ops = require("./ops");
321
+ Object.keys(_ops).forEach(function (key) {
322
+ if (key === "default" || key === "__esModule") return;
323
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
324
+ if (key in exports && exports[key] === _ops[key]) return;
325
+ Object.defineProperty(exports, key, {
326
+ enumerable: true,
327
+ get: function () {
328
+ return _ops[key];
329
+ }
330
+ });
331
+ });
332
+ var _runtimeScope = _interopRequireDefault(require("./runtimeScope"));
333
+ var _types = require("./types");
334
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
335
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
336
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ exports.mergeSegments = mergeSegments;
8
+ exports.muxAll = muxAll;
9
+ exports.muxAsync = muxAsync;
10
+ exports.muxOne = muxOne;
11
+ /**
12
+ * Multiplex the specified array of arguments by calling cb for all possible combinations of arguments.
13
+ * If the specified `args` array is empty, `cb` is called once without any arguments.
14
+ *
15
+ * `mux([[1, 2], [3, 4]], cb)` for example calls:
16
+ * - `cb(1, 3)`
17
+ * - `cb(1, 4)`
18
+ * - `cb(2, 3)`
19
+ * - `cb(2, 4)`
20
+ */
21
+ function mux(args, cb) {
22
+ const argCount = args.length;
23
+ if (argCount === 1) {
24
+ args[0].forEach(arg => cb(arg));
25
+ return;
26
+ }
27
+ let execCount = 1;
28
+ const indices = args.map(arg => {
29
+ const argLength = arg?.length ?? 0;
30
+ execCount *= argLength;
31
+ return [argLength, 0, arg];
32
+ });
33
+ if (execCount === 0) return;
34
+ const buffer = args.map(([v]) => v);
35
+ let execIndex = 0;
36
+ for (;;) {
37
+ cb(...buffer);
38
+ execIndex += 1;
39
+ if (execIndex >= execCount) break;
40
+ // determine next combination
41
+ for (let argIndex = argCount - 1; argIndex >= 0; argIndex -= 1) {
42
+ const arg = indices[argIndex];
43
+ const [max, current, values] = arg;
44
+ const next = current + 1;
45
+ if (next < max) {
46
+ arg[1] = next;
47
+ buffer[argIndex] = values[next];
48
+ break;
49
+ }
50
+ arg[1] = 0;
51
+ [buffer[argIndex]] = values;
52
+ }
53
+ }
54
+ }
55
+ var _default = exports.default = mux;
56
+ /** Multiplex the specified array of arguments and return the results produced by the callbacks */
57
+ function muxOne(args, cb) {
58
+ const argCount = args.length;
59
+ if (argCount === 1) return args[0].map(arg => cb(arg));
60
+ let execCount = 1;
61
+ const indices = args.map(arg => {
62
+ const argLength = arg?.length ?? 0;
63
+ execCount *= argLength;
64
+ return [argLength, 0, arg];
65
+ });
66
+ if (execCount === 0) return [];
67
+ const outputs = new Array(execCount);
68
+ const buffer = args.map(([v]) => v);
69
+ let execIndex = 0;
70
+ for (;;) {
71
+ outputs[execIndex] = cb(...buffer);
72
+ execIndex += 1;
73
+ if (execIndex >= execCount) break;
74
+ // determine next combination
75
+ for (let argIndex = argCount - 1; argIndex >= 0; argIndex -= 1) {
76
+ const arg = indices[argIndex];
77
+ const [max, current, values] = arg;
78
+ const next = current + 1;
79
+ if (next < max) {
80
+ arg[1] = next;
81
+ buffer[argIndex] = values[next];
82
+ break;
83
+ }
84
+ arg[1] = 0;
85
+ [buffer[argIndex]] = values;
86
+ }
87
+ }
88
+ return outputs;
89
+ }
90
+
91
+ /** Multiplex the specified array of arguments asynchronously and return the results produced by the callbacks */
92
+ function muxAsync(args, cb) {
93
+ return Promise.all(muxOne(args, cb));
94
+ }
95
+
96
+ /** Multiplex the specified array of arguments asynchronously and return a single array of all merged result arrays produced by the callbacks */
97
+ async function muxAll(args, cb) {
98
+ return mergeSegments(await muxAsync(args, cb));
99
+ }
100
+
101
+ /** Create a single array from the specified array segments */
102
+ function mergeSegments(segments) {
103
+ if (segments.length === 0) return segments;
104
+ if (segments.length === 1) return segments[0];
105
+ return segments.flat(1);
106
+ }
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _op = require("./op");
7
+ Object.keys(_op).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _op[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _op[key];
14
+ }
15
+ });
16
+ });
17
+ var _opa = require("./opa");
18
+ Object.keys(_opa).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _opa[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _opa[key];
25
+ }
26
+ });
27
+ });
28
+ var _opc = require("./opc");
29
+ Object.keys(_opc).forEach(function (key) {
30
+ if (key === "default" || key === "__esModule") return;
31
+ if (key in exports && exports[key] === _opc[key]) return;
32
+ Object.defineProperty(exports, key, {
33
+ enumerable: true,
34
+ get: function () {
35
+ return _opc[key];
36
+ }
37
+ });
38
+ });
39
+ var _opm = require("./opm");
40
+ Object.keys(_opm).forEach(function (key) {
41
+ if (key === "default" || key === "__esModule") return;
42
+ if (key in exports && exports[key] === _opm[key]) return;
43
+ Object.defineProperty(exports, key, {
44
+ enumerable: true,
45
+ get: function () {
46
+ return _opm[key];
47
+ }
48
+ });
49
+ });
50
+ var _opu = require("./opu");
51
+ Object.keys(_opu).forEach(function (key) {
52
+ if (key === "default" || key === "__esModule") return;
53
+ if (key in exports && exports[key] === _opu[key]) return;
54
+ Object.defineProperty(exports, key, {
55
+ enumerable: true,
56
+ get: function () {
57
+ return _opu[key];
58
+ }
59
+ });
60
+ });