@jplorg/jpl 2.2.0 → 2.3.1
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.
package/dist/esm/main.js
CHANGED
|
@@ -460,14 +460,19 @@ function lt(e) {
|
|
|
460
460
|
// lib/runtime/index.ts
|
|
461
461
|
var ut = { vars: {} };
|
|
462
462
|
function I(e = {}, t = {}) {
|
|
463
|
-
return
|
|
463
|
+
return {
|
|
464
|
+
...r(e, t, "vars"),
|
|
465
|
+
signal: AbortSignal.any([e.signal, t.signal].filter((e) => e != null))
|
|
466
|
+
};
|
|
464
467
|
}
|
|
465
468
|
var dt = class {
|
|
466
469
|
#e;
|
|
467
470
|
#t;
|
|
468
471
|
#n;
|
|
469
472
|
constructor(e, t) {
|
|
470
|
-
this.#e = I(t?.runtime, ut), this.#t = e, this.#n = this.createScope({ vars: Object.fromEntries(this.muxOne([Object.entries(this.options.vars)], ([e, t]) => [e, this.normalizeValue(t)])) })
|
|
473
|
+
this.#e = I(t?.runtime, ut), this.#t = e, this.#n = this.createScope({ vars: Object.fromEntries(this.muxOne([Object.entries(this.options.vars)], ([e, t]) => [e, this.normalizeValue(t)])) }), this.options.signal?.aborted && this.#n.signal.exit(), this.options.signal?.addEventListener("abort", () => {
|
|
474
|
+
this.#n.signal.exit();
|
|
475
|
+
});
|
|
471
476
|
}
|
|
472
477
|
get options() {
|
|
473
478
|
return this.#e;
|
|
@@ -3294,7 +3299,7 @@ var _r = $((e, t, n) => t ** gr(e, n ?? null)), vr = $((e, t) => Math.sqrt(t)),
|
|
|
3294
3299
|
trunc: () => jr,
|
|
3295
3300
|
type: () => mr,
|
|
3296
3301
|
void: () => hr
|
|
3297
|
-
}), Pr = "\n# There are additional builtins that are implemented directly in the corresponding languages.\n# Also the functions in the \"internals\" namespace are not exposed to the public and are only to be used by the builtins below.\n\nfunc map(f): ([.[] | f()])\n| func mapValues(f): (.[] |= f())\n| func select(f): (if f() then . else void() end)\n| func reduce(f, s): (\n l = length()\n | func i(i, n, c): (if n < l then i(i, n + 1, f->(.[n], c, n)) else c end)\n | i(i, 0, s)\n)\n| func while(cond, f): (\n func i(i): (if cond() then ., i->(f(), i) else void() end)\n | i(i)\n)\n| func until(cond, f): (\n func i(i): (if cond() then . else i->(f(), i) end)\n | i(i)\n)\n| func range(from, to, step): (\n t = type->(from) | if t != \"number\" then error->(\"cannot use \\(t) as a number\") end\n | t = type->(to) | if t != \"number\" then error->(\"cannot use \\(t) as a number\") end\n | s = (step | if . != 0 and . != null then abs() else 1 end)\n | while->(\n from,\n if from <= to then func (): (. < to) else func (): (. > to) end,\n if from <= to then func (): (. + s) else func (): (. - s) end\n )\n)\n\n\n# type selectors:\n| func isArray(): (type() == \"array\")\n| func arrays(): (select(isArray))\n| func isObject(): (type() == \"object\")\n| func objects(): (select(isObject))\n| func isIterable(): (contains->([\"array\", \"object\"], type()))\n| func iterables(): (select(isIterable))\n| func isScalar(): (not contains->([\"array\", \"object\"], type()))\n| func scalars(): (select(isScalar))\n| func isBoolean(): (type() == \"boolean\")\n| func booleans(): (select(isBoolean))\n| func isNumber(): (type() == \"number\")\n| func numbers(): (select(isNumber))\n| func isString(): (type() == \"string\")\n| func strings(): (select(isString))\n| func isNull(): (type() == \"null\")\n| func nulls(): (select(isNull))\n| func isFunction(): (type() == \"function\")\n| func functions(): (select(isFunction))\n| func isNullLike(): (contains->([\"null\", \"function\"], type()))\n| func nullLikes(): (select(isNullLike))\n| func isValue(): (not contains->([\"null\", \"function\"], type()))\n| func values(): (select(isValue))\n| func isContent(): (isValue() and not contains->([[], {}, \"\"], .))\n| func contents(): (select(isContent))\n\n\n| func toEntries(): (o = . | keys() | map(func (): ({ key: ., value: o[.] })))\n| func fromEntries(): (\n reduce(\n func (s): (s + { (.key ?? .Key ?? .name ?? .Name): if has(\"value\") then .value else .Value end }),\n {}\n )\n)\n| func withEntries(f): (toEntries() | map(f) | fromEntries())\n\n| func add(): (reduce(func (sum): (sum + .)))\n| func join(sep): (\n reduce(\n func (sum): (\n if sum == null then \"\" else sum + sep end\n + (. | toString())\n )\n ) ?? \"\"\n)\n| func sortBy(f): ([.[] | [[f()], .]] | internals.sortEntries() | [.[][1]])\n| func sort(): (sortBy(func (): (.)))\n| func groupBy(f): (\n key = 0 | value = 1\n | [.[] | [[f()], [.]]] | internals.sortEntries()\n | if . == []\n then .\n else\n reduce->(\n .[1:],\n func (sum): (if sum[-1][key] == .[key] then (sum)[-1][value] += .[value] else sum + [.] end),\n .[:1]\n )\n | [.[][value]]\n end\n)\n| func group(): (groupBy(func (): (.)))\n| func uniqueBy(f): (groupBy(f) | map(func (): (.[0])))\n| func unique(): (group() | map(func (): (.[0])))\n| func recurseBy(f, cond): (\n c = cond ?? func (): (. != null)\n | func r(r): (., (f() | select(c) | r(r)))\n | r(r)\n)\n| func recurse(cond): (recurseBy(func (): ((arrays(), objects()) | .[]), cond))\n| func reverse(): ([.[length() - 1 - range(0, length())]])\n| func minBy(f): (\n key = 0 | value = 1\n | [.[] | [[f()], .]]\n | reduce->(.[1:], func (sum): (if .[key] < sum[key] then . else sum end), .[0])\n | .[value]\n)\n| func min(): (reduce->(.[1:], func (sum): (if . < sum then . else sum end), .[0]))\n| func maxBy(f): (\n key = 0 | value = 1\n | [.[] | [[f()], .]]\n | reduce->(.[1:], func (sum): (if .[key] > sum[key] then . else sum end), .[0])\n | .[value]\n)\n| func max(): (reduce->(.[1:], func (sum): (if . > sum then . else sum end), .[0]))\n| func first(f): ([f()][0])\n| func nth(which, f): (\n [f()]\n | .[if which | type() == \"number\" then which else length() | which() end]\n)\n| func last(f): ([f()][-1])\n| func isEmpty(f): (first(func (): ((f() | false), true)))\n| func allBy(f, cond): (isEmpty(func (): (f() | cond() and void())))\n| func all(cond): (allBy(func (): (.[]), cond))\n| func anyBy(f, cond): (not isEmpty(func (): (f() | cond() or void())))\n| func any(cond): (anyBy(func (): (.[]), cond))\n\n| func getPath(path): (\n fields = (path | if type() == 'string' then . / '.' end)\n | reduce->(fields, func (sum): sum[if type->(sum) == 'array' then toNumber() else toString() end], .)\n)\n| func updatePath(path, update): (\n fields = (path | if type() == 'string' then (. / '.')[] |= (v = . | try toNumber() catch v) end)\n | reduce->(\n reverse->(fields),\n func (sum): (\n field = .\n | func (): (\n if type() == 'array'\n then (\n input = .\n | try toNumber->(field) catch toString->(field)\n | if type() == 'number'\n then input[.] |= sum()\n else {}[.] |= sum()\n end\n ) elif type() == 'object'\n then (\n .[toString->(field)] |= sum()\n ) elif type->(field) == 'number'\n then (\n [][field] |= sum()\n ) else (\n {}[toString->(field)] |= sum()\n )\n end\n )\n ),\n update\n )->(.)\n)\n| func setPath(path, value): (\n updatePath(path, func (): value)\n)\n", Fr = n(async () => {
|
|
3302
|
+
}), Pr = "\n# There are additional builtins that are implemented directly in the corresponding languages.\n# Also the functions in the \"internals\" namespace are not exposed to the public and are only to be used by the builtins below.\n\nfunc map(f): ([.[] | f()])\n| func mapValues(f): (.[] |= f())\n| func select(f): (if f() then . else void() end)\n| func reduce(f, s): (\n l = length()\n | func i(i, n, c): (if n < l then i(i, n + 1, f->(.[n], c, n)) else c end)\n | i(i, 0, s)\n)\n| func while(cond, f): (\n func i(i): (if cond() then ., i->(f(), i) else void() end)\n | i(i)\n)\n| func until(cond, f): (\n func i(i): (if cond() then . else i->(f(), i) end)\n | i(i)\n)\n| func range(from, to, step): (\n t = type->(from) | if t != \"number\" then error->(\"cannot use \\(t) as a number\") end\n | t = type->(to) | if t != \"number\" then error->(\"cannot use \\(t) as a number\") end\n | s = (step | if . != 0 and . != null then abs() else 1 end)\n | while->(\n from,\n if from <= to then func (): (. < to) else func (): (. > to) end,\n if from <= to then func (): (. + s) else func (): (. - s) end\n )\n)\n\n\n# type selectors:\n| func isArray(): (type() == \"array\")\n| func arrays(): (select(isArray))\n| func isObject(): (type() == \"object\")\n| func objects(): (select(isObject))\n| func isIterable(): (contains->([\"array\", \"object\"], type()))\n| func iterables(): (select(isIterable))\n| func isScalar(): (not contains->([\"array\", \"object\"], type()))\n| func scalars(): (select(isScalar))\n| func isBoolean(): (type() == \"boolean\")\n| func booleans(): (select(isBoolean))\n| func isNumber(): (type() == \"number\")\n| func numbers(): (select(isNumber))\n| func isString(): (type() == \"string\")\n| func strings(): (select(isString))\n| func isNull(): (type() == \"null\")\n| func nulls(): (select(isNull))\n| func isFunction(): (type() == \"function\")\n| func functions(): (select(isFunction))\n| func isNullLike(): (contains->([\"null\", \"function\"], type()))\n| func nullLikes(): (select(isNullLike))\n| func isValue(): (not contains->([\"null\", \"function\"], type()))\n| func values(): (select(isValue))\n| func isContent(): (isValue() and not contains->([[], {}, \"\"], .))\n| func contents(): (select(isContent))\n\n\n| func toEntries(): (o = . | keys() | map(func (): ({ key: ., value: o[.] })))\n| func fromEntries(): (\n reduce(\n func (s): (s + { (.key ?? .Key ?? .name ?? .Name): if has(\"value\") then .value else .Value end }),\n {}\n )\n)\n| func withEntries(f): (toEntries() | map(f) | fromEntries())\n\n| func add(): (reduce(func (sum): (sum + .)))\n| func join(sep): (\n reduce(\n func (sum): (\n if sum == null then \"\" else sum + sep end\n + (. | toString())\n )\n ) ?? \"\"\n)\n| func sortBy(f): ([.[] | [[f()], .]] | internals.sortEntries() | [.[][1]])\n| func sort(): (sortBy(func (): (.)))\n| func groupBy(f): (\n key = 0 | value = 1\n | [.[] | [[f()], [.]]] | internals.sortEntries()\n | if . == []\n then .\n else\n reduce->(\n .[1:],\n func (sum): (if sum[-1][key] == .[key] then (sum)[-1][value] += .[value] else sum + [.] end),\n .[:1]\n )\n | [.[][value]]\n end\n)\n| func group(): (groupBy(func (): (.)))\n| func uniqueBy(f): (groupBy(f) | map(func (): (.[0])))\n| func unique(): (group() | map(func (): (.[0])))\n| func recurseBy(f, cond): (\n c = cond ?? func (): (. != null)\n | func r(r): (., (f() | select(c) | r(r)))\n | r(r)\n)\n| func recurse(cond): (recurseBy(func (): ((arrays(), objects()) | .[]), cond))\n| func reverse(): ([.[length() - 1 - range(0, length())]])\n| func minBy(f): (\n key = 0 | value = 1\n | [.[] | [[f()], .]]\n | reduce->(.[1:], func (sum): (if .[key] < sum[key] then . else sum end), .[0])\n | .[value]\n)\n| func min(): (reduce->(.[1:], func (sum): (if . < sum then . else sum end), .[0]))\n| func maxBy(f): (\n key = 0 | value = 1\n | [.[] | [[f()], .]]\n | reduce->(.[1:], func (sum): (if .[key] > sum[key] then . else sum end), .[0])\n | .[value]\n)\n| func max(): (reduce->(.[1:], func (sum): (if . > sum then . else sum end), .[0]))\n| func first(f): ([f()][0])\n| func nth(which, f): (\n [f()]\n | .[if which | type() == \"number\" then which else length() | which() end]\n)\n| func last(f): ([f()][-1])\n| func isEmpty(f): (first(func (): ((f() | false), true)))\n| func allBy(f, cond): (isEmpty(func (): (f() | cond() and void())))\n| func all(cond): (allBy(func (): (.[]), cond))\n| func anyBy(f, cond): (not isEmpty(func (): (f() | cond() or void())))\n| func any(cond): (anyBy(func (): (.[]), cond))\n\n| func getPath(path): (\n fields = (path | if type() == 'string' then . / '.' end)\n | reduce->(fields, func (sum): sum[if type->(sum) == 'array' then toNumber() else toString() end], .)\n)\n| func updatePath(path, update): (\n fields = (path | if type() == 'string' then (. / '.')[] |= (v = . | try toNumber() catch v) end)\n | reduce->(\n reverse->(fields),\n func (sum): (\n field = .\n | func (): (\n if type() == 'array'\n then (\n input = .\n | try toNumber->(field) catch toString->(field)\n | if type() == 'number'\n then (input)[.] |= sum()\n else {}[.] |= sum()\n end\n ) elif type() == 'object'\n then (\n .[toString->(field)] |= sum()\n ) elif type->(field) == 'number'\n then (\n [][field] |= sum()\n ) else (\n {}[toString->(field)] |= sum()\n )\n end\n )\n ),\n update\n )->(.)\n)\n| func setPath(path, value): (\n updatePath(path, func (): value)\n)\n", Fr = n(async () => {
|
|
3298
3303
|
await void 0;
|
|
3299
3304
|
let e = { ...Nr };
|
|
3300
3305
|
return await (await qn.parse(Pr, { runtime: {
|
|
@@ -9,6 +9,7 @@ export type JPLRuntimeOptions = {
|
|
|
9
9
|
[name: string]: unknown;
|
|
10
10
|
};
|
|
11
11
|
adjustResult?: (result: unknown, scope: JPLRuntimeScope) => Promise<unknown[]> | unknown[];
|
|
12
|
+
signal?: AbortSignal;
|
|
12
13
|
};
|
|
13
14
|
export declare function applyRuntimeDefaults(options?: JPLRuntimeOptions, defaults?: JPLRuntimeOptions): JPLRuntimeOptions;
|
|
14
15
|
/** JPL runtime */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jplorg/jpl",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.1",
|
|
4
4
|
"description": "JPL interpreter",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -52,23 +52,23 @@
|
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@eslint/js": "^10.0.1",
|
|
55
|
-
"@types/node": "^
|
|
55
|
+
"@types/node": "^26.6.6",
|
|
56
56
|
"@types/react": "^19.3.0",
|
|
57
57
|
"@types/react-dom": "^19.3.0",
|
|
58
58
|
"@vitejs/plugin-react": "^6.3.0",
|
|
59
|
-
"eslint": "^10.
|
|
59
|
+
"eslint": "^10.15.0",
|
|
60
60
|
"eslint-config-prettier": "^10.1.8",
|
|
61
61
|
"eslint-import-resolver-typescript": "^4.4.5",
|
|
62
62
|
"eslint-plugin-import-x": "^4.18.1",
|
|
63
63
|
"eslint-plugin-prettier": "^5.5.7",
|
|
64
64
|
"eslint-plugin-react-hooks": "^7.1.1",
|
|
65
|
-
"eslint-plugin-react-refresh": "^0.5.
|
|
65
|
+
"eslint-plugin-react-refresh": "^0.5.8",
|
|
66
66
|
"globals": "^17.14.0",
|
|
67
67
|
"prettier": "^3.10.1",
|
|
68
68
|
"react": "^19.3.1",
|
|
69
69
|
"react-dom": "^19.3.1",
|
|
70
70
|
"typescript": "^6.0.3",
|
|
71
|
-
"typescript-eslint": "^8.
|
|
71
|
+
"typescript-eslint": "^8.73.0",
|
|
72
72
|
"unplugin-dts": "^1.1.2",
|
|
73
73
|
"vite": "^8.3.8"
|
|
74
74
|
}
|