@jplorg/jpl 2.0.0 → 2.1.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 (320) hide show
  1. package/dist/esm/main.js +3474 -0
  2. package/dist/types/applyDefaults.d.ts +2 -0
  3. package/dist/types/builtins/funcContains.d.ts +3 -0
  4. package/dist/types/builtins/funcEndsWith.d.ts +3 -0
  5. package/dist/types/builtins/funcError.d.ts +3 -0
  6. package/dist/types/builtins/funcFromJSON.d.ts +3 -0
  7. package/dist/types/builtins/funcHas.d.ts +3 -0
  8. package/dist/types/builtins/funcIn.d.ts +3 -0
  9. package/dist/types/builtins/funcKeys.d.ts +3 -0
  10. package/dist/types/builtins/funcLength.d.ts +3 -0
  11. package/dist/types/builtins/funcNow.d.ts +3 -0
  12. package/dist/types/builtins/funcStartsWith.d.ts +3 -0
  13. package/dist/types/builtins/funcToJSON.d.ts +3 -0
  14. package/dist/types/builtins/funcToLowerCase.d.ts +3 -0
  15. package/dist/types/builtins/funcToNumber.d.ts +3 -0
  16. package/dist/types/builtins/funcToString.d.ts +3 -0
  17. package/dist/types/builtins/funcToUpperCase.d.ts +3 -0
  18. package/dist/types/builtins/funcTrim.d.ts +3 -0
  19. package/dist/types/builtins/funcTrimEnd.d.ts +3 -0
  20. package/dist/types/builtins/funcTrimStart.d.ts +3 -0
  21. package/dist/types/builtins/funcType.d.ts +3 -0
  22. package/dist/types/builtins/funcVoid.d.ts +3 -0
  23. package/dist/types/builtins/index.d.ts +2 -0
  24. package/dist/types/builtins/internals.d.ts +1 -0
  25. package/dist/types/builtins/math.d.ts +17 -0
  26. package/dist/types/createSingleton.d.ts +1 -0
  27. package/dist/types/interpreter/index.d.ts +21 -0
  28. package/dist/types/interpreter/parse.d.ts +194 -0
  29. package/{src/interpreter/parseFunction.js → dist/types/interpreter/parseFunction.d.ts} +2 -10
  30. package/dist/types/interpreter/system.d.ts +3 -0
  31. package/dist/types/interpreter/util.d.ts +89 -0
  32. package/dist/types/library/apply.d.ts +32 -0
  33. package/dist/types/library/definition.d.ts +79 -0
  34. package/dist/types/library/errors/adaptErrors.d.ts +6 -0
  35. package/dist/types/library/errors/enclosure.d.ts +6 -0
  36. package/dist/types/library/errors/error.d.ts +6 -0
  37. package/dist/types/library/errors/execution.d.ts +12 -0
  38. package/dist/types/library/errors/fatal.d.ts +4 -0
  39. package/dist/types/library/errors/runtime.d.ts +46 -0
  40. package/dist/types/library/errors/syntax.d.ts +7 -0
  41. package/{src/library/functions.js → dist/types/library/functions.d.ts} +9 -30
  42. package/dist/types/library/index.d.ts +18 -0
  43. package/dist/types/library/mux.d.ts +19 -0
  44. package/{src/library/ops/op.js → dist/types/library/ops/op.d.ts} +25 -49
  45. package/{src/library/ops/opa.js → dist/types/library/ops/opa.d.ts} +4 -7
  46. package/{src/library/ops/opc.js → dist/types/library/ops/opc.d.ts} +6 -11
  47. package/{src/library/ops/opm.js → dist/types/library/ops/opm.d.ts} +5 -9
  48. package/{src/library/ops/opu.js → dist/types/library/ops/opu.d.ts} +8 -15
  49. package/dist/types/library/runtimeScope.d.ts +23 -0
  50. package/dist/types/library/runtimeSignal.d.ts +25 -0
  51. package/dist/types/library/types.d.ts +97 -0
  52. package/dist/types/main.d.ts +19 -0
  53. package/dist/types/program/handler.d.ts +12 -0
  54. package/dist/types/program/index.d.ts +40 -0
  55. package/dist/types/program/ops/index.d.ts +5 -0
  56. package/dist/types/program/ops/opAccess/index.d.ts +11 -0
  57. package/dist/types/program/ops/opAccess/opaField.d.ts +11 -0
  58. package/dist/types/program/ops/opAccess/opaFunction.d.ts +11 -0
  59. package/dist/types/program/ops/opAccess/opaIter.d.ts +11 -0
  60. package/dist/types/program/ops/opAccess/opaSlice.d.ts +11 -0
  61. package/dist/types/program/ops/opAnd.d.ts +11 -0
  62. package/dist/types/program/ops/opArrayConstructor.d.ts +11 -0
  63. package/dist/types/program/ops/opAssignment/index.d.ts +11 -0
  64. package/dist/types/program/ops/opAssignment/opaAssignField.d.ts +11 -0
  65. package/dist/types/program/ops/opAssignment/opaAssignIter.d.ts +11 -0
  66. package/dist/types/program/ops/opAssignment/opaAssignSlice.d.ts +11 -0
  67. package/dist/types/program/ops/opAssignment/opuAddition.d.ts +11 -0
  68. package/dist/types/program/ops/opAssignment/opuDivision.d.ts +11 -0
  69. package/dist/types/program/ops/opAssignment/opuMultiplication.d.ts +11 -0
  70. package/dist/types/program/ops/opAssignment/opuNullCoalescence.d.ts +11 -0
  71. package/dist/types/program/ops/opAssignment/opuRemainder.d.ts +11 -0
  72. package/dist/types/program/ops/opAssignment/opuSet.d.ts +11 -0
  73. package/dist/types/program/ops/opAssignment/opuSubtraction.d.ts +11 -0
  74. package/dist/types/program/ops/opAssignment/opuUpdate.d.ts +11 -0
  75. package/dist/types/program/ops/opCalculation/index.d.ts +11 -0
  76. package/dist/types/program/ops/opCalculation/opmAddition.d.ts +11 -0
  77. package/dist/types/program/ops/opCalculation/opmDivision.d.ts +11 -0
  78. package/dist/types/program/ops/opCalculation/opmMultiplication.d.ts +11 -0
  79. package/dist/types/program/ops/opCalculation/opmRemainder.d.ts +11 -0
  80. package/dist/types/program/ops/opCalculation/opmSubtraction.d.ts +11 -0
  81. package/dist/types/program/ops/opComparison/index.d.ts +11 -0
  82. package/dist/types/program/ops/opComparison/opcEqual.d.ts +11 -0
  83. package/dist/types/program/ops/opComparison/opcGreater.d.ts +11 -0
  84. package/dist/types/program/ops/opComparison/opcGreaterEqual.d.ts +11 -0
  85. package/dist/types/program/ops/opComparison/opcLess.d.ts +11 -0
  86. package/dist/types/program/ops/opComparison/opcLessEqual.d.ts +11 -0
  87. package/dist/types/program/ops/opComparison/opcUnequal.d.ts +11 -0
  88. package/dist/types/program/ops/opConstant.d.ts +11 -0
  89. package/dist/types/program/ops/opConstantFalse.d.ts +11 -0
  90. package/dist/types/program/ops/opConstantNull.d.ts +11 -0
  91. package/dist/types/program/ops/opConstantTrue.d.ts +11 -0
  92. package/dist/types/program/ops/opFunctionDefinition.d.ts +11 -0
  93. package/dist/types/program/ops/opIf.d.ts +11 -0
  94. package/dist/types/program/ops/opInterpolatedString.d.ts +11 -0
  95. package/dist/types/program/ops/opNegation.d.ts +11 -0
  96. package/dist/types/program/ops/opNot.d.ts +11 -0
  97. package/dist/types/program/ops/opNullCoalescence.d.ts +11 -0
  98. package/dist/types/program/ops/opNumber.d.ts +11 -0
  99. package/dist/types/program/ops/opObjectConstructor.d.ts +11 -0
  100. package/dist/types/program/ops/opOr.d.ts +11 -0
  101. package/dist/types/program/ops/opOutputConcat.d.ts +11 -0
  102. package/dist/types/program/ops/opString.d.ts +11 -0
  103. package/dist/types/program/ops/opTry.d.ts +11 -0
  104. package/dist/types/program/ops/opVariable.d.ts +11 -0
  105. package/dist/types/program/ops/opVariableDefinition.d.ts +11 -0
  106. package/dist/types/program/ops/opVoid.d.ts +11 -0
  107. package/dist/types/program/ops/utils.d.ts +5 -0
  108. package/dist/types/program/params.d.ts +68 -0
  109. package/dist/types/runtime/index.d.ts +83 -0
  110. package/package.json +66 -49
  111. package/{repl.js → repl.ts} +85 -39
  112. package/lib/applyDefaults.js +0 -34
  113. package/lib/builtins/funcContains.js +0 -25
  114. package/lib/builtins/funcEndsWith.js +0 -21
  115. package/lib/builtins/funcError.js +0 -11
  116. package/lib/builtins/funcFromJSON.js +0 -26
  117. package/lib/builtins/funcHas.js +0 -24
  118. package/lib/builtins/funcIn.js +0 -24
  119. package/lib/builtins/funcKeys.js +0 -20
  120. package/lib/builtins/funcLength.js +0 -24
  121. package/lib/builtins/funcNow.js +0 -10
  122. package/lib/builtins/funcStartsWith.js +0 -21
  123. package/lib/builtins/funcToJSON.js +0 -10
  124. package/lib/builtins/funcToLowerCase.js +0 -17
  125. package/lib/builtins/funcToNumber.js +0 -26
  126. package/lib/builtins/funcToString.js +0 -10
  127. package/lib/builtins/funcToUpperCase.js +0 -17
  128. package/lib/builtins/funcTrim.js +0 -17
  129. package/lib/builtins/funcTrimEnd.js +0 -17
  130. package/lib/builtins/funcTrimStart.js +0 -17
  131. package/lib/builtins/funcType.js +0 -10
  132. package/lib/builtins/funcVoid.js +0 -10
  133. package/lib/builtins/index.js +0 -205
  134. package/lib/builtins/internals.js +0 -8
  135. package/lib/builtins/math.js +0 -40
  136. package/lib/builtins/native.js +0 -180
  137. package/lib/createSingleton.js +0 -14
  138. package/lib/index.js +0 -79
  139. package/lib/interpreter/index.js +0 -56
  140. package/lib/interpreter/parse.js +0 -2377
  141. package/lib/interpreter/parseFunction.js +0 -24
  142. package/lib/interpreter/system.js +0 -10
  143. package/lib/interpreter/util.js +0 -349
  144. package/lib/library/apply.js +0 -142
  145. package/lib/library/definition.js +0 -9
  146. package/lib/library/errors/adaptErrors.js +0 -34
  147. package/lib/library/errors/enclosure.js +0 -16
  148. package/lib/library/errors/error.js +0 -18
  149. package/lib/library/errors/execution.js +0 -20
  150. package/lib/library/errors/fatal.js +0 -15
  151. package/lib/library/errors/runtime.js +0 -78
  152. package/lib/library/errors/syntax.js +0 -17
  153. package/lib/library/functions.js +0 -82
  154. package/lib/library/index.js +0 -335
  155. package/lib/library/mux.js +0 -106
  156. package/lib/library/ops/index.js +0 -60
  157. package/lib/library/ops/op.js +0 -180
  158. package/lib/library/ops/opa.js +0 -41
  159. package/lib/library/ops/opc.js +0 -59
  160. package/lib/library/ops/opm.js +0 -50
  161. package/lib/library/ops/opu.js +0 -77
  162. package/lib/library/runtimeScope.js +0 -38
  163. package/lib/library/runtimeSignal.js +0 -72
  164. package/lib/library/types.js +0 -304
  165. package/lib/program/index.js +0 -101
  166. package/lib/program/ops/index.js +0 -61
  167. package/lib/program/ops/opAccess/index.js +0 -55
  168. package/lib/program/ops/opAccess/opaField.js +0 -50
  169. package/lib/program/ops/opAccess/opaFunction.js +0 -50
  170. package/lib/program/ops/opAccess/opaIter.js +0 -33
  171. package/lib/program/ops/opAccess/opaSlice.js +0 -46
  172. package/lib/program/ops/opAnd.js +0 -30
  173. package/lib/program/ops/opArrayConstructor.js +0 -20
  174. package/lib/program/ops/opAssignment/index.js +0 -90
  175. package/lib/program/ops/opAssignment/opaAssignField.js +0 -125
  176. package/lib/program/ops/opAssignment/opaAssignIter.js +0 -71
  177. package/lib/program/ops/opAssignment/opaAssignSlice.js +0 -101
  178. package/lib/program/ops/opAssignment/opuAddition.js +0 -31
  179. package/lib/program/ops/opAssignment/opuDivision.js +0 -31
  180. package/lib/program/ops/opAssignment/opuMultiplication.js +0 -31
  181. package/lib/program/ops/opAssignment/opuNullCoalescence.js +0 -25
  182. package/lib/program/ops/opAssignment/opuRemainder.js +0 -31
  183. package/lib/program/ops/opAssignment/opuSet.js +0 -19
  184. package/lib/program/ops/opAssignment/opuSubtraction.js +0 -31
  185. package/lib/program/ops/opAssignment/opuUpdate.js +0 -19
  186. package/lib/program/ops/opCalculation/index.js +0 -57
  187. package/lib/program/ops/opCalculation/opmAddition.js +0 -49
  188. package/lib/program/ops/opCalculation/opmDivision.js +0 -42
  189. package/lib/program/ops/opCalculation/opmMultiplication.js +0 -40
  190. package/lib/program/ops/opCalculation/opmRemainder.js +0 -34
  191. package/lib/program/ops/opCalculation/opmSubtraction.js +0 -53
  192. package/lib/program/ops/opComparison/index.js +0 -59
  193. package/lib/program/ops/opComparison/opcEqual.js +0 -19
  194. package/lib/program/ops/opComparison/opcGreater.js +0 -19
  195. package/lib/program/ops/opComparison/opcGreaterEqual.js +0 -19
  196. package/lib/program/ops/opComparison/opcLess.js +0 -19
  197. package/lib/program/ops/opComparison/opcLessEqual.js +0 -19
  198. package/lib/program/ops/opComparison/opcUnequal.js +0 -19
  199. package/lib/program/ops/opConstant.js +0 -18
  200. package/lib/program/ops/opConstantFalse.js +0 -16
  201. package/lib/program/ops/opConstantNull.js +0 -16
  202. package/lib/program/ops/opConstantTrue.js +0 -16
  203. package/lib/program/ops/opFunctionDefinition.js +0 -21
  204. package/lib/program/ops/opIf.js +0 -38
  205. package/lib/program/ops/opInterpolatedString.js +0 -24
  206. package/lib/program/ops/opNegation.js +0 -25
  207. package/lib/program/ops/opNot.js +0 -16
  208. package/lib/program/ops/opNullCoalescence.js +0 -34
  209. package/lib/program/ops/opNumber.js +0 -18
  210. package/lib/program/ops/opObjectConstructor.js +0 -37
  211. package/lib/program/ops/opOr.js +0 -30
  212. package/lib/program/ops/opOutputConcat.js +0 -19
  213. package/lib/program/ops/opString.js +0 -18
  214. package/lib/program/ops/opTry.js +0 -37
  215. package/lib/program/ops/opVariable.js +0 -20
  216. package/lib/program/ops/opVariableDefinition.js +0 -24
  217. package/lib/program/ops/opVoid.js +0 -16
  218. package/lib/program/ops/utils.js +0 -35
  219. package/lib/runtime/index.js +0 -258
  220. package/src/applyDefaults.js +0 -35
  221. package/src/builtins/funcContains.js +0 -27
  222. package/src/builtins/funcEndsWith.js +0 -21
  223. package/src/builtins/funcError.js +0 -7
  224. package/src/builtins/funcFromJSON.js +0 -24
  225. package/src/builtins/funcHas.js +0 -25
  226. package/src/builtins/funcIn.js +0 -25
  227. package/src/builtins/funcKeys.js +0 -20
  228. package/src/builtins/funcLength.js +0 -26
  229. package/src/builtins/funcNow.js +0 -5
  230. package/src/builtins/funcStartsWith.js +0 -21
  231. package/src/builtins/funcToJSON.js +0 -5
  232. package/src/builtins/funcToLowerCase.js +0 -20
  233. package/src/builtins/funcToNumber.js +0 -25
  234. package/src/builtins/funcToString.js +0 -5
  235. package/src/builtins/funcToUpperCase.js +0 -20
  236. package/src/builtins/funcTrim.js +0 -16
  237. package/src/builtins/funcTrimEnd.js +0 -16
  238. package/src/builtins/funcTrimStart.js +0 -16
  239. package/src/builtins/funcType.js +0 -5
  240. package/src/builtins/funcVoid.js +0 -5
  241. package/src/builtins/index.js +0 -193
  242. package/src/builtins/internals.js +0 -9
  243. package/src/builtins/math.js +0 -44
  244. package/src/createSingleton.js +0 -9
  245. package/src/index.js +0 -44
  246. package/src/interpreter/index.js +0 -48
  247. package/src/interpreter/parse.js +0 -1473
  248. package/src/interpreter/system.js +0 -5
  249. package/src/interpreter/util.js +0 -237
  250. package/src/library/apply.js +0 -135
  251. package/src/library/definition.js +0 -3
  252. package/src/library/errors/adaptErrors.js +0 -28
  253. package/src/library/errors/enclosure.js +0 -11
  254. package/src/library/errors/error.js +0 -14
  255. package/src/library/errors/execution.js +0 -15
  256. package/src/library/errors/fatal.js +0 -10
  257. package/src/library/errors/runtime.js +0 -71
  258. package/src/library/errors/syntax.js +0 -12
  259. package/src/library/index.js +0 -41
  260. package/src/library/mux.js +0 -98
  261. package/src/library/runtimeScope.js +0 -35
  262. package/src/library/runtimeSignal.js +0 -67
  263. package/src/library/types.js +0 -299
  264. package/src/program/index.js +0 -114
  265. package/src/program/ops/index.js +0 -82
  266. package/src/program/ops/opAccess/index.js +0 -55
  267. package/src/program/ops/opAccess/opaField.js +0 -58
  268. package/src/program/ops/opAccess/opaFunction.js +0 -52
  269. package/src/program/ops/opAccess/opaIter.js +0 -34
  270. package/src/program/ops/opAccess/opaSlice.js +0 -61
  271. package/src/program/ops/opAnd.js +0 -32
  272. package/src/program/ops/opArrayConstructor.js +0 -16
  273. package/src/program/ops/opAssignment/index.js +0 -102
  274. package/src/program/ops/opAssignment/opaAssignField.js +0 -156
  275. package/src/program/ops/opAssignment/opaAssignIter.js +0 -77
  276. package/src/program/ops/opAssignment/opaAssignSlice.js +0 -160
  277. package/src/program/ops/opAssignment/opuAddition.js +0 -29
  278. package/src/program/ops/opAssignment/opuDivision.js +0 -29
  279. package/src/program/ops/opAssignment/opuMultiplication.js +0 -29
  280. package/src/program/ops/opAssignment/opuNullCoalescence.js +0 -26
  281. package/src/program/ops/opAssignment/opuRemainder.js +0 -29
  282. package/src/program/ops/opAssignment/opuSet.js +0 -15
  283. package/src/program/ops/opAssignment/opuSubtraction.js +0 -29
  284. package/src/program/ops/opAssignment/opuUpdate.js +0 -15
  285. package/src/program/ops/opCalculation/index.js +0 -64
  286. package/src/program/ops/opCalculation/opmAddition.js +0 -63
  287. package/src/program/ops/opCalculation/opmDivision.js +0 -47
  288. package/src/program/ops/opCalculation/opmMultiplication.js +0 -52
  289. package/src/program/ops/opCalculation/opmRemainder.js +0 -49
  290. package/src/program/ops/opCalculation/opmSubtraction.js +0 -72
  291. package/src/program/ops/opComparison/index.js +0 -67
  292. package/src/program/ops/opComparison/opcEqual.js +0 -17
  293. package/src/program/ops/opComparison/opcGreater.js +0 -17
  294. package/src/program/ops/opComparison/opcGreaterEqual.js +0 -17
  295. package/src/program/ops/opComparison/opcLess.js +0 -17
  296. package/src/program/ops/opComparison/opcLessEqual.js +0 -17
  297. package/src/program/ops/opComparison/opcUnequal.js +0 -17
  298. package/src/program/ops/opConstant.js +0 -13
  299. package/src/program/ops/opConstantFalse.js +0 -11
  300. package/src/program/ops/opConstantNull.js +0 -11
  301. package/src/program/ops/opConstantTrue.js +0 -11
  302. package/src/program/ops/opFunctionDefinition.js +0 -17
  303. package/src/program/ops/opIf.js +0 -44
  304. package/src/program/ops/opInterpolatedString.js +0 -27
  305. package/src/program/ops/opNegation.js +0 -26
  306. package/src/program/ops/opNot.js +0 -11
  307. package/src/program/ops/opNullCoalescence.js +0 -36
  308. package/src/program/ops/opNumber.js +0 -13
  309. package/src/program/ops/opObjectConstructor.js +0 -40
  310. package/src/program/ops/opOr.js +0 -32
  311. package/src/program/ops/opOutputConcat.js +0 -17
  312. package/src/program/ops/opString.js +0 -13
  313. package/src/program/ops/opTry.js +0 -38
  314. package/src/program/ops/opVariable.js +0 -17
  315. package/src/program/ops/opVariableDefinition.js +0 -18
  316. package/src/program/ops/opVoid.js +0 -11
  317. package/src/program/ops/utils.js +0 -19
  318. package/src/runtime/index.js +0 -309
  319. /package/{src/builtins/native.js → dist/types/builtins/native.d.ts} +0 -0
  320. /package/{src/library/ops/index.js → dist/types/library/ops/index.d.ts} +0 -0
@@ -1,58 +0,0 @@
1
- import { JPLTypeError } from '../../../library';
2
- import { call } from '../utils';
3
-
4
- export default {
5
- /** { pipe: [op], optional: boolean } */
6
- op(runtime, input, target, params, scope, next) {
7
- const value = runtime.unwrapValue(target);
8
- const tv = runtime.type(value);
9
-
10
- return runtime.executeInstructions(params.pipe ?? [], [input], scope, (output) => {
11
- const field = runtime.unwrapValue(output);
12
- const tf = runtime.type(field);
13
- switch (tv) {
14
- case 'null':
15
- if (['string', 'number'].includes(tf)) return next(null);
16
- break;
17
-
18
- case 'object':
19
- if (tf === 'string') return next(value[field] ?? null);
20
- break;
21
-
22
- case 'array':
23
- if (tf === 'number') {
24
- const i = Math.trunc(field);
25
- return next(value[i >= 0 ? i : value.length + i] ?? null);
26
- }
27
- break;
28
-
29
- case 'string':
30
- if (tf === 'number') {
31
- const i = Math.trunc(field);
32
- const chars = [...value];
33
- return next(chars[i >= 0 ? i : chars.length + i] ?? null);
34
- }
35
- break;
36
-
37
- default:
38
- }
39
-
40
- if (params.optional) return [];
41
- throw new JPLTypeError(
42
- 'cannot access field of %s (%*<100v) with %s (%*<100v)',
43
- tv,
44
- value,
45
- tf,
46
- field,
47
- );
48
- });
49
- },
50
-
51
- /** { pipe: function, optional: boolean } */
52
- map(runtime, params) {
53
- return {
54
- pipe: call(params.pipe),
55
- optional: runtime.assertType(params.optional, 'boolean'),
56
- };
57
- },
58
- };
@@ -1,52 +0,0 @@
1
- import { JPLErrorEnclosure, JPLTypeError, adaptError } from '../../../library';
2
- import { call } from '../utils';
3
-
4
- export default {
5
- /** { args: [[op]], bound: boolean, optional: boolean } */
6
- async op(runtime, input, target, params, scope, next) {
7
- const value = runtime.unwrapValue(target);
8
- const t = runtime.type(value);
9
- switch (t) {
10
- case 'function': {
11
- const args = await runtime.muxAsync([params.args ?? []], (arg) =>
12
- runtime.executeInstructions(arg ?? [], [input], scope),
13
- );
14
-
15
- return runtime.muxAll(args, async (...a) => {
16
- try {
17
- const fnNext = async (output) => {
18
- try {
19
- return await next(output);
20
- } catch (err) {
21
- throw new JPLErrorEnclosure(err);
22
- }
23
- };
24
-
25
- if (params.bound) {
26
- return await value(runtime, scope.signal, fnNext, a[0] ?? null, ...a.slice(1));
27
- }
28
-
29
- return await value(runtime, scope.signal, fnNext, input, ...a);
30
- } catch (err) {
31
- if (JPLErrorEnclosure.is(err)) throw err.inner;
32
- throw adaptError(err);
33
- }
34
- });
35
- }
36
-
37
- default:
38
- }
39
-
40
- if (params.optional) return [];
41
- throw new JPLTypeError('cannot execute %s (%*<100v)', t, value);
42
- },
43
-
44
- /** { args: [function], bound: boolean, optional: boolean } */
45
- map(runtime, params) {
46
- return {
47
- args: runtime.muxOne([params.args], (entry) => call(entry)),
48
- bound: runtime.assertType(params.bound, 'boolean'),
49
- optional: runtime.assertType(params.optional, 'boolean'),
50
- };
51
- },
52
- };
@@ -1,34 +0,0 @@
1
- import { JPLTypeError } from '../../../library';
2
-
3
- export default {
4
- /** { optional: boolean } */
5
- op(runtime, input, target, params, scope, next) {
6
- const value = runtime.unwrapValue(target);
7
- const t = runtime.type(value);
8
- switch (t) {
9
- case 'null':
10
- return [];
11
-
12
- case 'object':
13
- return runtime.muxAll([Object.values(value)], next);
14
-
15
- case 'array':
16
- return runtime.muxAll([value], next);
17
-
18
- case 'string':
19
- return runtime.muxAll([[...value]], next);
20
-
21
- default:
22
- }
23
-
24
- if (params.optional) return [];
25
- throw new JPLTypeError('cannot iterate over %s (%*<100v)', t, value);
26
- },
27
-
28
- /** { optional: boolean } */
29
- map(runtime, params) {
30
- return {
31
- optional: runtime.assertType(params.optional, 'boolean'),
32
- };
33
- },
34
- };
@@ -1,61 +0,0 @@
1
- import { JPLTypeError } from '../../../library';
2
- import { call } from '../utils';
3
-
4
- export default {
5
- /** { from: [op], to: [op], optional: boolean } */
6
- async op(runtime, input, target, params, scope, next) {
7
- const value = runtime.unwrapValue(target);
8
- const tv = runtime.type(value);
9
-
10
- const [froms, tos] = await Promise.all([
11
- runtime.executeInstructions(params.from ?? [], [input], scope),
12
- runtime.executeInstructions(params.to ?? [], [input], scope),
13
- ]);
14
-
15
- return runtime.muxAll([runtime.unwrapValues(froms), runtime.unwrapValues(tos)], (from, to) => {
16
- const tf = runtime.type(from);
17
- const tt = runtime.type(to);
18
- switch (tv) {
19
- case 'null':
20
- return next(null);
21
-
22
- case 'array':
23
- if (['number', 'null'].includes(tf) && ['number', 'null'].includes(tt)) {
24
- return next(value.slice(Math.trunc(from ?? 0), Math.trunc(to ?? value.length)));
25
- }
26
- break;
27
-
28
- case 'string':
29
- if (['number', 'null'].includes(tf) && ['number', 'null'].includes(tt)) {
30
- const chars = [...value];
31
- return next(
32
- chars.slice(Math.trunc(from ?? 0), Math.trunc(to ?? chars.length)).join(''),
33
- );
34
- }
35
- break;
36
-
37
- default:
38
- }
39
-
40
- if (params.optional) return [];
41
- throw new JPLTypeError(
42
- 'cannot slice %s (%*<100v) with %s (%*<100v) and %s (%*<100v)',
43
- tv,
44
- value,
45
- tf,
46
- from,
47
- tt,
48
- to,
49
- );
50
- });
51
- },
52
-
53
- /** { from: function, to: function, optional: boolean } */
54
- map(runtime, params) {
55
- return {
56
- from: call(params.from),
57
- to: call(params.to),
58
- optional: runtime.assertType(params.optional, 'boolean'),
59
- };
60
- },
61
- };
@@ -1,32 +0,0 @@
1
- import { call } from './utils';
2
-
3
- export default {
4
- /** { pipes: [[op]] } */
5
- op(runtime, input, params, scope, next) {
6
- const iter = async (from) => {
7
- // 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.
8
- await undefined;
9
-
10
- scope.signal.checkHealth();
11
-
12
- if (from >= (params.pipes?.length ?? 0)) return next(true, scope);
13
-
14
- const pipe = params.pipes[from];
15
-
16
- return runtime.executeInstructions(pipe ?? [], [input], scope, (output) => {
17
- if (!runtime.truthy(output)) return next(false, scope);
18
-
19
- return iter(from + 1);
20
- });
21
- };
22
-
23
- return iter(0);
24
- },
25
-
26
- /** { pipes: [function] } */
27
- map(runtime, params) {
28
- return {
29
- pipes: runtime.muxOne([params.pipes], (pipe) => call(pipe)),
30
- };
31
- },
32
- };
@@ -1,16 +0,0 @@
1
- import { call } from './utils';
2
-
3
- export default {
4
- /** { pipe: [op] } */
5
- async op(runtime, input, params, scope, next) {
6
- const outputs = await runtime.executeInstructions(params.pipe ?? [], [input], scope);
7
- return next(outputs, scope);
8
- },
9
-
10
- /** { pipe: function } */
11
- map(runtime, params) {
12
- return {
13
- pipe: call(params.pipe),
14
- };
15
- },
16
- };
@@ -1,102 +0,0 @@
1
- import {
2
- JPLFatalError,
3
- OPA_FIELD,
4
- OPA_ITER,
5
- OPA_SLICE,
6
- OPU_ADDITION,
7
- OPU_DIVISION,
8
- OPU_MULTIPLICATION,
9
- OPU_NULL_COALESCENCE,
10
- OPU_REMAINDER,
11
- OPU_SET,
12
- OPU_SUBTRACTION,
13
- OPU_UPDATE,
14
- } from '../../../library';
15
- import { call } from '../utils';
16
- import opaAssignField from './opaAssignField';
17
- import opaAssignIter from './opaAssignIter';
18
- import opaAssignSlice from './opaAssignSlice';
19
- import opuAddition from './opuAddition';
20
- import opuDivision from './opuDivision';
21
- import opuMultiplication from './opuMultiplication';
22
- import opuNullCoalescence from './opuNullCoalescence';
23
- import opuRemainder from './opuRemainder';
24
- import opuSet from './opuSet';
25
- import opuSubtraction from './opuSubtraction';
26
- import opuUpdate from './opuUpdate';
27
-
28
- export default {
29
- /** { pipe: [op], selectors: [opa], assignment: [opu] } */
30
- op(runtime, input, params, scope, next) {
31
- const iter = async (from, value) => {
32
- // 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.
33
- await undefined;
34
-
35
- scope.signal.checkHealth();
36
-
37
- if (from >= (params.selectors?.length ?? 0)) {
38
- const { op, params: opParams } = params.assignment ?? {};
39
- const operator = opus[op];
40
- if (!operator) throw new JPLFatalError(`invalid OPU '${op}'`);
41
-
42
- return operator.op(runtime, input, value, opParams ?? {}, scope, (output) => [output]);
43
- }
44
-
45
- const { op, params: opParams } = params.selectors[from];
46
- const operator = opasAssign[op];
47
- if (!operator) throw new JPLFatalError(`invalid OPA '${op}' (assignment)`);
48
-
49
- return operator.op(runtime, input, value, opParams ?? {}, scope, (output) =>
50
- iter(from + 1, output),
51
- );
52
- };
53
-
54
- return runtime.executeInstructions(params.pipe ?? [], [input], scope, async (output) =>
55
- runtime.muxAll([await iter(0, output)], (result) =>
56
- next(result === undefined ? output : result, scope),
57
- ),
58
- );
59
- },
60
-
61
- /** { pipe: function, selectors: [opa], assignment: opu } */
62
- map(runtime, params) {
63
- return {
64
- pipe: call(params.pipe),
65
- selectors: runtime.muxOne([params.selectors], ({ op, params: opParams }) => {
66
- const operator = opasAssign[op];
67
- if (!operator) throw new JPLFatalError(`invalid OPA '${op}' (assignment)`);
68
-
69
- return {
70
- op: runtime.assertType(op, 'string'),
71
- params: operator.map(runtime, opParams),
72
- };
73
- }),
74
- assignment: (({ op, params: opParams }) => {
75
- const operator = opus[op];
76
- if (!operator) throw new JPLFatalError(`invalid OPU '${op}'`);
77
-
78
- return {
79
- op: runtime.assertType(op, 'string'),
80
- params: operator.map(runtime, opParams),
81
- };
82
- })(params.assignment),
83
- };
84
- },
85
- };
86
-
87
- const opasAssign = {
88
- [OPA_FIELD]: opaAssignField,
89
- [OPA_ITER]: opaAssignIter,
90
- [OPA_SLICE]: opaAssignSlice,
91
- };
92
-
93
- const opus = {
94
- [OPU_ADDITION]: opuAddition,
95
- [OPU_DIVISION]: opuDivision,
96
- [OPU_MULTIPLICATION]: opuMultiplication,
97
- [OPU_NULL_COALESCENCE]: opuNullCoalescence,
98
- [OPU_REMAINDER]: opuRemainder,
99
- [OPU_SET]: opuSet,
100
- [OPU_SUBTRACTION]: opuSubtraction,
101
- [OPU_UPDATE]: opuUpdate,
102
- };
@@ -1,156 +0,0 @@
1
- import { JPLTypeError, applyArray, applyObject } from '../../../library';
2
- import { call } from '../utils';
3
-
4
- export default {
5
- /** { pipe: [op], optional: boolean } */
6
- async op(runtime, input, target, params, scope, next) {
7
- let items;
8
- const vt = runtime.unwrapValue(target);
9
- const tt = runtime.type(target);
10
- switch (tt) {
11
- case 'null':
12
- case 'object':
13
- case 'array':
14
- items = vt;
15
- break;
16
-
17
- case 'string':
18
- items = [...vt];
19
- break;
20
-
21
- default:
22
- if (params.optional) return [undefined];
23
- throw new JPLTypeError('cannot access fields of %s (%*<100v) (assignment)', tt, vt);
24
- }
25
-
26
- const fields = await runtime.executeInstructions(
27
- params.pipe ?? [],
28
- [input],
29
- scope,
30
- (output) => [output],
31
- );
32
-
33
- const iter = async (from, source) => {
34
- // 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.
35
- await undefined;
36
-
37
- scope.signal.checkHealth();
38
-
39
- if (from >= fields.length) return [source];
40
-
41
- const t = tt === 'string' ? tt : runtime.type(source);
42
- const field = runtime.unwrapValue(fields[from]);
43
- const tf = runtime.type(field);
44
- switch (t) {
45
- case 'null': {
46
- switch (tf) {
47
- case 'string':
48
- return runtime.muxAll([await next(null)], (output) => {
49
- if (output === undefined) return iter(from + 1, source);
50
- return iter(from + 1, { [field]: output });
51
- });
52
-
53
- case 'number': {
54
- const i = Math.trunc(field);
55
- return runtime.muxAll([await next(null)], (output) => {
56
- if (output === undefined) return iter(from + 1, source);
57
- return iter(from + 1, applyArray([], [[i, output]]));
58
- });
59
- }
60
-
61
- default:
62
- }
63
-
64
- break;
65
- }
66
-
67
- case 'object':
68
- if (tf === 'string') {
69
- const item = source[field];
70
- return runtime.muxAll([await next(item ?? null)], (output) => {
71
- if (output === undefined) return iter(from + 1, source);
72
- return iter(from + 1, applyObject(source, [[field, output]]));
73
- });
74
- }
75
- break;
76
-
77
- case 'array':
78
- if (tf === 'number') {
79
- const i = Math.trunc(field);
80
- const item = source[i >= 0 ? i : source.length + i];
81
- return runtime.muxAll([await next(item ?? null)], (output) => {
82
- if (output === undefined) return iter(from + 1, source);
83
- return iter(from + 1, applyArray(source, [[i, output]]));
84
- });
85
- }
86
- break;
87
-
88
- case 'string':
89
- if (tf === 'number') {
90
- const i = Math.trunc(field);
91
- const item = source[i >= 0 ? i : source.length + i];
92
- return runtime.muxAll([await next(item ?? null)], (output) => {
93
- if (output === undefined) return iter(from + 1, source);
94
- const r = runtime.unwrapValue(output);
95
- const tr = runtime.type(r);
96
- switch (tr) {
97
- case 'null':
98
- case 'string':
99
- return iter(from + 1, applyArray(source, [[i, output ?? ' ']], ' '));
100
-
101
- default:
102
- }
103
-
104
- throw new JPLTypeError(
105
- 'cannot assign %s (%*<100v) to string (%*<100v)',
106
- tr,
107
- r,
108
- source.join(''),
109
- );
110
- });
111
- }
112
- break;
113
-
114
- default:
115
- }
116
-
117
- if (params.optional) return iter(from + 1, source);
118
- throw new JPLTypeError(
119
- 'cannot access field of %s (%*<100v) with %s (%*<100v) (assignment)',
120
- t,
121
- t === 'string' ? source.join('') : source,
122
- tf,
123
- field,
124
- );
125
- };
126
-
127
- return runtime.muxAsync([await iter(0, items)], (results) => {
128
- if (items === results) return target;
129
-
130
- const t = tt === 'string' ? tt : runtime.type(results);
131
- switch (t) {
132
- case 'null':
133
- return undefined;
134
-
135
- case 'object':
136
- case 'array':
137
- return runtime.alterValue(target, () => results);
138
-
139
- case 'string':
140
- return runtime.alterValue(target, () => results.join(''));
141
-
142
- default:
143
- }
144
-
145
- return undefined;
146
- });
147
- },
148
-
149
- /** { pipe: function, optional: boolean } */
150
- map(runtime, params) {
151
- return {
152
- pipe: call(params.pipe),
153
- optional: runtime.assertType(params.optional, 'boolean'),
154
- };
155
- },
156
- };
@@ -1,77 +0,0 @@
1
- import { JPLTypeError, applyCombinations } from '../../../library';
2
-
3
- export default {
4
- /** { optional: boolean } */
5
- async op(runtime, input, target, params, scope, next) {
6
- const vt = runtime.unwrapValue(target);
7
- const tt = runtime.type(vt);
8
- switch (tt) {
9
- case 'null':
10
- return [undefined];
11
-
12
- case 'object': {
13
- const items = Object.entries(vt);
14
- const outputs = await runtime.muxAsync([items], async (item) =>
15
- runtime.muxAsync([await next(item[1] ?? null)], (output) => {
16
- if (output === undefined) return item;
17
- return [item[0], output];
18
- }),
19
- );
20
- return runtime.muxAsync([applyCombinations(items, outputs)], (results) => {
21
- if (items === results) return target;
22
- return runtime.alterValue(target, () => Object.fromEntries(results));
23
- });
24
- }
25
-
26
- case 'array': {
27
- const items = vt;
28
- const outputs = await runtime.muxAsync([items], async (item) =>
29
- runtime.muxAsync([await next(item ?? null)], (output) => {
30
- if (output === undefined) return item;
31
- return output;
32
- }),
33
- );
34
- return runtime.muxAsync([applyCombinations(items, outputs)], (results) => {
35
- if (items === results) return target;
36
- return runtime.alterValue(target, () => results);
37
- });
38
- }
39
-
40
- case 'string': {
41
- const items = [...vt];
42
- const outputs = await runtime.muxAsync([items], async (item) =>
43
- runtime.muxAsync([await next(item)], (output) => {
44
- if (output === undefined) return item;
45
- const r = runtime.unwrapValue(output);
46
- const tr = runtime.type(r);
47
- switch (tr) {
48
- case 'null':
49
- case 'string':
50
- return r ?? ' ';
51
-
52
- default:
53
- }
54
-
55
- throw new JPLTypeError('cannot assign %s (%*<100v) to string (%*<100v)', tr, r, vt);
56
- }),
57
- );
58
- return runtime.muxAsync([applyCombinations(items, outputs)], (results) => {
59
- if (items === results) return target;
60
- return runtime.alterValue(target, () => results.join(''));
61
- });
62
- }
63
-
64
- default:
65
- }
66
-
67
- if (params.optional) return [undefined];
68
- throw new JPLTypeError('cannot iterate over %s (%*<100v) (assignment)', tt, vt);
69
- },
70
-
71
- /** { optional: boolean } */
72
- map(runtime, params) {
73
- return {
74
- optional: runtime.assertType(params.optional, 'boolean'),
75
- };
76
- },
77
- };