@atscript/ui-fns 0.1.151 → 0.1.152

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/index.cjs CHANGED
@@ -1,124 +1,12 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  let _atscript_ui = require("@atscript/ui");
3
3
  //#region src/runtime/fn-compiler.ts
4
- /**
5
- * The hidden globals as one frozen object every call's sandbox inherits
6
- * from. A call then copies only its own few scope keys instead of all ~80
7
- * hidden names, while name resolution inside `with` is unchanged: scope keys,
8
- * then the hidden globals (`null`), then `Object.prototype`, then the real
9
- * globals. Both levels are frozen, so assigning any sandbox name still fails
10
- * silently.
11
- */
12
- const HIDDEN = Object.freeze(Object.fromEntries([
13
- "global",
14
- "process",
15
- "Buffer",
16
- "require",
17
- "__filename",
18
- "__dirname",
19
- "exports",
20
- "module",
21
- "setImmediate",
22
- "clearImmediate",
23
- "setTimeout",
24
- "clearTimeout",
25
- "setInterval",
26
- "clearInterval",
27
- "queueMicrotask",
28
- "queueGlobalMicrotask",
29
- "globalThis",
30
- "window",
31
- "self",
32
- "document",
33
- "localStorage",
34
- "sessionStorage",
35
- "indexedDB",
36
- "caches",
37
- "console",
38
- "performance",
39
- "fetch",
40
- "XMLHttpRequest",
41
- "Image",
42
- "Audio",
43
- "navigator",
44
- "navigation",
45
- "location",
46
- "history",
47
- "screen",
48
- "requestAnimationFrame",
49
- "cancelAnimationFrame",
50
- "cancelIdleCallback",
51
- "captureEvents",
52
- "chrome",
53
- "clientInformation",
54
- "addEventListener",
55
- "removeEventListener",
56
- "blur",
57
- "close",
58
- "closed",
59
- "confirm",
60
- "alert",
61
- "customElements",
62
- "dispatchEvent",
63
- "debug",
64
- "focus",
65
- "find",
66
- "frames",
67
- "getSelection",
68
- "getScreenDetails",
69
- "getEventListeners",
70
- "keys",
71
- "launchQueue",
72
- "parent",
73
- "postMessage",
74
- "print",
75
- "profile",
76
- "profileEnd",
77
- "prompt",
78
- "queryLocalFonts",
79
- "queryObjects",
80
- "releaseEvents",
81
- "reportError",
82
- "resizeBy",
83
- "resizeTo",
84
- "scheduler",
85
- "stop",
86
- "scroll",
87
- "scrollBy",
88
- "scrollTo",
89
- "scrollY",
90
- "scrollX",
91
- "top",
92
- "eval",
93
- "__ctx__"
94
- ].map((name) => [name, null])));
95
- /**
96
- * The per-call sandbox: the scope's own keys on an object inheriting
97
- * {@link HIDDEN}, frozen. A scope key that shadows a hidden (or inherited)
98
- * name is defined rather than assigned — assignment would hit the frozen
99
- * inherited property and throw.
100
- */
101
- function sandbox(scope) {
102
- const box = Object.create(HIDDEN);
103
- const src = scope;
104
- for (const key of Object.keys(src)) if (key in box) Object.defineProperty(box, key, {
105
- value: src[key],
106
- enumerable: true,
107
- writable: true,
108
- configurable: true
109
- });
110
- else box[key] = src[key];
111
- return Object.freeze(box);
112
- }
113
- function compileSandboxed(code) {
114
- const body = new Function("__ctx__", `with(__ctx__){\n${code}\n}`);
115
- return (scope) => body(sandbox(scope));
116
- }
4
+ const pool = new (require("@prostojs/deserialize-fn")).FNPool();
117
5
  const fieldFns = /* @__PURE__ */ new Map();
118
6
  const topFns = /* @__PURE__ */ new Map();
119
7
  /**
120
8
  * Compiles a field-level function string from a `@ui.form.fn.*` / `@ui.table.fn.*` annotation
121
- * into a callable function. Compiled once per string and cached.
9
+ * into a callable function. Compiled once per string and cached (via FNPool).
122
10
  *
123
11
  * The function string should be an arrow or regular function expression:
124
12
  * `"(v, data, ctx, entry) => !data.firstName"`
@@ -129,7 +17,7 @@ const topFns = /* @__PURE__ */ new Map();
129
17
  function compileFieldFn(fnStr) {
130
18
  let fn = fieldFns.get(fnStr);
131
19
  if (!fn) {
132
- fn = compileSandboxed(`return (${fnStr})(v, data, context, entry)`);
20
+ fn = pool.getFn(`return (${fnStr})(v, data, context, entry)`);
133
21
  fieldFns.set(fnStr, fn);
134
22
  }
135
23
  return fn;
@@ -146,7 +34,7 @@ function compileFieldFn(fnStr) {
146
34
  function compileTopFn(fnStr) {
147
35
  let fn = topFns.get(fnStr);
148
36
  if (!fn) {
149
- fn = compileSandboxed(`return (${fnStr})(data, context)`);
37
+ fn = pool.getFn(`return (${fnStr})(data, context)`);
150
38
  topFns.set(fnStr, fn);
151
39
  }
152
40
  return fn;
package/dist/index.d.cts CHANGED
@@ -37,7 +37,7 @@ interface TFieldEvaluated {
37
37
  //#region src/runtime/fn-compiler.d.ts
38
38
  /**
39
39
  * Compiles a field-level function string from a `@ui.form.fn.*` / `@ui.table.fn.*` annotation
40
- * into a callable function. Compiled once per string and cached.
40
+ * into a callable function. Compiled once per string and cached (via FNPool).
41
41
  *
42
42
  * The function string should be an arrow or regular function expression:
43
43
  * `"(v, data, ctx, entry) => !data.firstName"`
package/dist/index.d.mts CHANGED
@@ -37,7 +37,7 @@ interface TFieldEvaluated {
37
37
  //#region src/runtime/fn-compiler.d.ts
38
38
  /**
39
39
  * Compiles a field-level function string from a `@ui.form.fn.*` / `@ui.table.fn.*` annotation
40
- * into a callable function. Compiled once per string and cached.
40
+ * into a callable function. Compiled once per string and cached (via FNPool).
41
41
  *
42
42
  * The function string should be an arrow or regular function expression:
43
43
  * `"(v, data, ctx, entry) => !data.firstName"`
package/dist/index.mjs CHANGED
@@ -1,123 +1,12 @@
1
1
  import { META_READONLY, UI_FORM_COMPONENT, UI_FORM_DISABLED, UI_FORM_FN_ATTR, UI_FORM_FN_DISABLED, UI_FORM_FN_HIDDEN, UI_FORM_FN_PREFIX, UI_FORM_FN_READONLY, UI_FORM_HIDDEN, UI_FORM_TYPE, UI_FORM_VALIDATE, UI_TABLE_FN_ATTR, UI_TABLE_FN_PREFIX, UI_TYPE, asArray, getFieldMeta, resolveFieldProp, resolveOptions, resolveStatic, setDefaultValidatorPlugins, setResolver } from "@atscript/ui";
2
+ import { FNPool } from "@prostojs/deserialize-fn";
2
3
  //#region src/runtime/fn-compiler.ts
3
- /**
4
- * The hidden globals as one frozen object every call's sandbox inherits
5
- * from. A call then copies only its own few scope keys instead of all ~80
6
- * hidden names, while name resolution inside `with` is unchanged: scope keys,
7
- * then the hidden globals (`null`), then `Object.prototype`, then the real
8
- * globals. Both levels are frozen, so assigning any sandbox name still fails
9
- * silently.
10
- */
11
- const HIDDEN = Object.freeze(Object.fromEntries([
12
- "global",
13
- "process",
14
- "Buffer",
15
- "require",
16
- "__filename",
17
- "__dirname",
18
- "exports",
19
- "module",
20
- "setImmediate",
21
- "clearImmediate",
22
- "setTimeout",
23
- "clearTimeout",
24
- "setInterval",
25
- "clearInterval",
26
- "queueMicrotask",
27
- "queueGlobalMicrotask",
28
- "globalThis",
29
- "window",
30
- "self",
31
- "document",
32
- "localStorage",
33
- "sessionStorage",
34
- "indexedDB",
35
- "caches",
36
- "console",
37
- "performance",
38
- "fetch",
39
- "XMLHttpRequest",
40
- "Image",
41
- "Audio",
42
- "navigator",
43
- "navigation",
44
- "location",
45
- "history",
46
- "screen",
47
- "requestAnimationFrame",
48
- "cancelAnimationFrame",
49
- "cancelIdleCallback",
50
- "captureEvents",
51
- "chrome",
52
- "clientInformation",
53
- "addEventListener",
54
- "removeEventListener",
55
- "blur",
56
- "close",
57
- "closed",
58
- "confirm",
59
- "alert",
60
- "customElements",
61
- "dispatchEvent",
62
- "debug",
63
- "focus",
64
- "find",
65
- "frames",
66
- "getSelection",
67
- "getScreenDetails",
68
- "getEventListeners",
69
- "keys",
70
- "launchQueue",
71
- "parent",
72
- "postMessage",
73
- "print",
74
- "profile",
75
- "profileEnd",
76
- "prompt",
77
- "queryLocalFonts",
78
- "queryObjects",
79
- "releaseEvents",
80
- "reportError",
81
- "resizeBy",
82
- "resizeTo",
83
- "scheduler",
84
- "stop",
85
- "scroll",
86
- "scrollBy",
87
- "scrollTo",
88
- "scrollY",
89
- "scrollX",
90
- "top",
91
- "eval",
92
- "__ctx__"
93
- ].map((name) => [name, null])));
94
- /**
95
- * The per-call sandbox: the scope's own keys on an object inheriting
96
- * {@link HIDDEN}, frozen. A scope key that shadows a hidden (or inherited)
97
- * name is defined rather than assigned — assignment would hit the frozen
98
- * inherited property and throw.
99
- */
100
- function sandbox(scope) {
101
- const box = Object.create(HIDDEN);
102
- const src = scope;
103
- for (const key of Object.keys(src)) if (key in box) Object.defineProperty(box, key, {
104
- value: src[key],
105
- enumerable: true,
106
- writable: true,
107
- configurable: true
108
- });
109
- else box[key] = src[key];
110
- return Object.freeze(box);
111
- }
112
- function compileSandboxed(code) {
113
- const body = new Function("__ctx__", `with(__ctx__){\n${code}\n}`);
114
- return (scope) => body(sandbox(scope));
115
- }
4
+ const pool = new FNPool();
116
5
  const fieldFns = /* @__PURE__ */ new Map();
117
6
  const topFns = /* @__PURE__ */ new Map();
118
7
  /**
119
8
  * Compiles a field-level function string from a `@ui.form.fn.*` / `@ui.table.fn.*` annotation
120
- * into a callable function. Compiled once per string and cached.
9
+ * into a callable function. Compiled once per string and cached (via FNPool).
121
10
  *
122
11
  * The function string should be an arrow or regular function expression:
123
12
  * `"(v, data, ctx, entry) => !data.firstName"`
@@ -128,7 +17,7 @@ const topFns = /* @__PURE__ */ new Map();
128
17
  function compileFieldFn(fnStr) {
129
18
  let fn = fieldFns.get(fnStr);
130
19
  if (!fn) {
131
- fn = compileSandboxed(`return (${fnStr})(v, data, context, entry)`);
20
+ fn = pool.getFn(`return (${fnStr})(v, data, context, entry)`);
132
21
  fieldFns.set(fnStr, fn);
133
22
  }
134
23
  return fn;
@@ -145,7 +34,7 @@ function compileFieldFn(fnStr) {
145
34
  function compileTopFn(fnStr) {
146
35
  let fn = topFns.get(fnStr);
147
36
  if (!fn) {
148
- fn = compileSandboxed(`return (${fnStr})(data, context)`);
37
+ fn = pool.getFn(`return (${fnStr})(data, context)`);
149
38
  topFns.set(fnStr, fn);
150
39
  }
151
40
  return fn;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/ui-fns",
3
- "version": "0.1.151",
3
+ "version": "0.1.152",
4
4
  "description": "Dynamic fn-compiled field properties for @atscript/ui (opt-in, uses new Function)",
5
5
  "keywords": [
6
6
  "annotations",
@@ -47,12 +47,12 @@
47
47
  "access": "public"
48
48
  },
49
49
  "dependencies": {
50
- "@atscript/ui": "^0.1.151"
50
+ "@prostojs/deserialize-fn": "^0.0.6",
51
+ "@atscript/ui": "^0.1.152"
51
52
  },
52
53
  "devDependencies": {
53
54
  "@atscript/core": "^0.1.102",
54
55
  "@atscript/typescript": "^0.1.102",
55
- "@prostojs/deserialize-fn": "^0.0.5",
56
56
  "vitest": "npm:@voidzero-dev/vite-plus-test@0.1.14"
57
57
  },
58
58
  "peerDependencies": {