@atscript/ui 0.1.162 → 0.1.164
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/client-factory.cjs +27 -0
- package/dist/client-factory.d.cts +53 -0
- package/dist/client-factory.d.mts +53 -0
- package/dist/client-factory.mjs +25 -0
- package/dist/form/apply.cjs +38 -0
- package/dist/form/apply.d.cts +36 -0
- package/dist/form/apply.d.mts +36 -0
- package/dist/form/apply.mjs +38 -0
- package/dist/form/clone.cjs +30 -0
- package/dist/form/clone.d.cts +23 -0
- package/dist/form/clone.d.mts +23 -0
- package/dist/form/clone.mjs +30 -0
- package/dist/form/create-form-def.cjs +440 -0
- package/dist/form/create-form-def.d.cts +67 -0
- package/dist/form/create-form-def.d.mts +67 -0
- package/dist/form/create-form-def.mjs +438 -0
- package/dist/form/decimal-format.cjs +324 -0
- package/dist/form/decimal-format.d.cts +86 -0
- package/dist/form/decimal-format.d.mts +86 -0
- package/dist/form/decimal-format.mjs +315 -0
- package/dist/form/diff.cjs +458 -0
- package/dist/form/diff.d.cts +80 -0
- package/dist/form/diff.d.mts +80 -0
- package/dist/form/diff.mjs +457 -0
- package/dist/form/dirty.cjs +65 -0
- package/dist/form/dirty.d.cts +47 -0
- package/dist/form/dirty.d.mts +47 -0
- package/dist/form/dirty.mjs +64 -0
- package/dist/form/error-utils.cjs +97 -0
- package/dist/form/error-utils.d.cts +58 -0
- package/dist/form/error-utils.d.mts +58 -0
- package/dist/form/error-utils.mjs +92 -0
- package/dist/form/form-actions.cjs +30 -0
- package/dist/form/form-actions.d.cts +17 -0
- package/dist/form/form-actions.d.mts +17 -0
- package/dist/form/form-actions.mjs +30 -0
- package/dist/form/grid.cjs +69 -0
- package/dist/form/grid.d.cts +49 -0
- package/dist/form/grid.d.mts +49 -0
- package/dist/form/grid.mjs +64 -0
- package/dist/form/labels.cjs +10 -0
- package/dist/form/labels.d.cts +7 -0
- package/dist/form/labels.d.mts +7 -0
- package/dist/form/labels.mjs +10 -0
- package/dist/form/measurement.cjs +20 -0
- package/dist/form/measurement.d.cts +29 -0
- package/dist/form/measurement.d.mts +29 -0
- package/dist/form/measurement.mjs +20 -0
- package/dist/form/path-utils.cjs +182 -0
- package/dist/form/path-utils.d.cts +47 -0
- package/dist/form/path-utils.d.mts +47 -0
- package/dist/form/path-utils.mjs +175 -0
- package/dist/form/rebase.cjs +89 -0
- package/dist/form/rebase.d.cts +61 -0
- package/dist/form/rebase.d.mts +61 -0
- package/dist/form/rebase.mjs +89 -0
- package/dist/form/skipped-nav.cjs +100 -0
- package/dist/form/skipped-nav.d.cts +13 -0
- package/dist/form/skipped-nav.d.mts +13 -0
- package/dist/form/skipped-nav.mjs +98 -0
- package/dist/form/types.cjs +40 -0
- package/dist/form/types.d.cts +133 -0
- package/dist/form/types.d.mts +133 -0
- package/dist/form/types.mjs +36 -0
- package/dist/form/union-detect.cjs +46 -0
- package/dist/form/union-detect.d.cts +22 -0
- package/dist/form/union-detect.d.mts +22 -0
- package/dist/form/union-detect.mjs +46 -0
- package/dist/form/validate.cjs +150 -0
- package/dist/form/validate.d.cts +50 -0
- package/dist/form/validate.d.mts +50 -0
- package/dist/form/validate.mjs +147 -0
- package/dist/index.cjs +217 -3360
- package/dist/index.d.cts +38 -1693
- package/dist/index.d.mts +38 -1693
- package/dist/index.mjs +35 -3179
- package/dist/nav/model-routes.cjs +59 -0
- package/dist/nav/model-routes.d.cts +33 -0
- package/dist/nav/model-routes.d.mts +33 -0
- package/dist/nav/model-routes.mjs +59 -0
- package/dist/plugin/annotations.cjs +577 -0
- package/dist/plugin/annotations.mjs +577 -0
- package/dist/plugin/primitives.cjs +30 -0
- package/dist/plugin/primitives.mjs +30 -0
- package/dist/plugin/value-help-validation.cjs +419 -0
- package/dist/plugin/value-help-validation.mjs +413 -0
- package/dist/plugin.cjs +4 -1001
- package/dist/plugin.mjs +2 -999
- package/dist/shared/annotation-keys.cjs +189 -0
- package/dist/shared/annotation-keys.d.cts +82 -0
- package/dist/shared/annotation-keys.d.mts +82 -0
- package/dist/shared/annotation-keys.mjs +97 -0
- package/dist/shared/field-resolver.cjs +123 -0
- package/dist/shared/field-resolver.d.cts +77 -0
- package/dist/shared/field-resolver.d.mts +77 -0
- package/dist/shared/field-resolver.mjs +110 -0
- package/dist/shared/meta-cache.cjs +244 -0
- package/dist/shared/meta-cache.d.cts +110 -0
- package/dist/shared/meta-cache.d.mts +110 -0
- package/dist/shared/meta-cache.mjs +237 -0
- package/dist/shared/str.cjs +19 -0
- package/dist/shared/str.d.cts +7 -0
- package/dist/shared/str.d.mts +7 -0
- package/dist/shared/str.mjs +17 -0
- package/dist/table/column-resolver.cjs +17 -0
- package/dist/table/column-resolver.d.cts +11 -0
- package/dist/table/column-resolver.d.mts +11 -0
- package/dist/table/column-resolver.mjs +15 -0
- package/dist/table/create-table-def.cjs +233 -0
- package/dist/table/create-table-def.d.cts +15 -0
- package/dist/table/create-table-def.d.mts +15 -0
- package/dist/table/create-table-def.mjs +233 -0
- package/dist/table/navigate-href.cjs +45 -0
- package/dist/table/navigate-href.d.cts +31 -0
- package/dist/table/navigate-href.d.mts +31 -0
- package/dist/table/navigate-href.mjs +45 -0
- package/dist/table/types.d.cts +287 -0
- package/dist/table/types.d.mts +287 -0
- package/dist/table/value-kind.cjs +20 -0
- package/dist/table/value-kind.d.cts +15 -0
- package/dist/table/value-kind.d.mts +15 -0
- package/dist/table/value-kind.mjs +19 -0
- package/dist/value-help/dict-paths.cjs +17 -0
- package/dist/value-help/dict-paths.d.cts +11 -0
- package/dist/value-help/dict-paths.d.mts +11 -0
- package/dist/value-help/dict-paths.mjs +17 -0
- package/dist/value-help/distinct-client.cjs +51 -0
- package/dist/value-help/distinct-client.d.cts +40 -0
- package/dist/value-help/distinct-client.d.mts +40 -0
- package/dist/value-help/distinct-client.mjs +50 -0
- package/dist/value-help/extract-literals.cjs +76 -0
- package/dist/value-help/extract-literals.d.cts +32 -0
- package/dist/value-help/extract-literals.d.mts +32 -0
- package/dist/value-help/extract-literals.mjs +74 -0
- package/dist/value-help/extract-ref.cjs +100 -0
- package/dist/value-help/extract-ref.d.cts +37 -0
- package/dist/value-help/extract-ref.d.mts +37 -0
- package/dist/value-help/extract-ref.mjs +100 -0
- package/dist/value-help/filter-tree.cjs +45 -0
- package/dist/value-help/filter-tree.mjs +45 -0
- package/dist/value-help/index.d.mts +8 -0
- package/dist/value-help/resolve-options.cjs +64 -0
- package/dist/value-help/resolve-options.d.cts +35 -0
- package/dist/value-help/resolve-options.d.mts +35 -0
- package/dist/value-help/resolve-options.mjs +60 -0
- package/dist/value-help/resolve.cjs +62 -0
- package/dist/value-help/resolve.d.cts +31 -0
- package/dist/value-help/resolve.d.mts +31 -0
- package/dist/value-help/resolve.mjs +61 -0
- package/dist/value-help/types.d.cts +36 -0
- package/dist/value-help/types.d.mts +36 -0
- package/dist/value-help/value-help-client.cjs +136 -0
- package/dist/value-help/value-help-client.d.cts +67 -0
- package/dist/value-help/value-help-client.d.mts +67 -0
- package/dist/value-help/value-help-client.mjs +134 -0
- package/package.json +10 -10
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { escapeRegex } from "../shared/str.mjs";
|
|
2
|
+
//#region src/value-help/value-help-client.ts
|
|
3
|
+
let cacheTtl = 5e3;
|
|
4
|
+
let searches = /* @__PURE__ */ new WeakMap();
|
|
5
|
+
/**
|
|
6
|
+
* How long (ms) a settled value-help search is reused for an identical
|
|
7
|
+
* search on the same client. Default 5000. `0` shares only searches still in
|
|
8
|
+
* flight; a negative value turns sharing off. Server-side rendering never
|
|
9
|
+
* shares (one process serves many viewers).
|
|
10
|
+
*/
|
|
11
|
+
function setValueHelpCacheTtl(ms) {
|
|
12
|
+
cacheTtl = ms;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Drop shared value-help search results — for one `client`, or for every
|
|
16
|
+
* client when omitted. Call after writing to a dictionary outside the
|
|
17
|
+
* built-in table actions to make pickers refetch at once.
|
|
18
|
+
*/
|
|
19
|
+
function invalidateValueHelpCache(client) {
|
|
20
|
+
if (client) searches.get(client)?.clear();
|
|
21
|
+
else searches = /* @__PURE__ */ new WeakMap();
|
|
22
|
+
}
|
|
23
|
+
function now() {
|
|
24
|
+
return typeof performance === "undefined" ? Date.now() : performance.now();
|
|
25
|
+
}
|
|
26
|
+
/** Cache key of a plain-JSON request; `undefined` when it holds anything else (never shared). */
|
|
27
|
+
function requestKey(request) {
|
|
28
|
+
let plain = true;
|
|
29
|
+
try {
|
|
30
|
+
const key = JSON.stringify(request, (_k, v) => {
|
|
31
|
+
if (typeof v === "function" || typeof v === "symbol") plain = false;
|
|
32
|
+
else if (v !== null && typeof v === "object" && !Array.isArray(v)) {
|
|
33
|
+
const proto = Object.getPrototypeOf(v);
|
|
34
|
+
if (proto !== Object.prototype && proto !== null) plain = false;
|
|
35
|
+
}
|
|
36
|
+
return v;
|
|
37
|
+
});
|
|
38
|
+
return plain ? key : void 0;
|
|
39
|
+
} catch {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function sharedQuery(client, request) {
|
|
44
|
+
const run = () => client.query(request);
|
|
45
|
+
if (cacheTtl < 0 || typeof window === "undefined") return run();
|
|
46
|
+
const key = requestKey(request);
|
|
47
|
+
if (key === void 0) return run();
|
|
48
|
+
let byKey = searches.get(client);
|
|
49
|
+
if (!byKey) searches.set(client, byKey = /* @__PURE__ */ new Map());
|
|
50
|
+
const hit = byKey.get(key);
|
|
51
|
+
if (hit && (hit.settledAt === void 0 || now() - hit.settledAt < cacheTtl)) return hit.promise;
|
|
52
|
+
const entry = { promise: run().then((items) => {
|
|
53
|
+
entry.settledAt = now();
|
|
54
|
+
return items;
|
|
55
|
+
}, (err) => {
|
|
56
|
+
if (byKey.get(key) === entry) byKey.delete(key);
|
|
57
|
+
throw err;
|
|
58
|
+
}) };
|
|
59
|
+
byKey.set(key, entry);
|
|
60
|
+
return entry.promise;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Value-help query client. Wraps a `Client` from `@atscript/db-client`
|
|
64
|
+
* with FK-specific search logic (regex fallback for non-searchable tables,
|
|
65
|
+
* $select scoping).
|
|
66
|
+
*
|
|
67
|
+
* Consumers resolve the target's metadata once via `resolveValueHelp(url)`
|
|
68
|
+
* and pass the resulting `ResolvedValueHelp` to `search()`. Label resolution
|
|
69
|
+
* for cells is deliberately unsupported — cells always display raw ids.
|
|
70
|
+
*
|
|
71
|
+
* Identical searches on the same `Client` are shared (see
|
|
72
|
+
* {@link setValueHelpCacheTtl}).
|
|
73
|
+
*/
|
|
74
|
+
var ValueHelpClient = class {
|
|
75
|
+
_client;
|
|
76
|
+
constructor(client) {
|
|
77
|
+
this._client = client;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Search the target with value-help semantics.
|
|
81
|
+
*
|
|
82
|
+
* - If target is searchable → sends `$search` (server full-text)
|
|
83
|
+
* - If not searchable → sends `$or` regex across select fields + exact PK match
|
|
84
|
+
*/
|
|
85
|
+
async search(resolved, opts) {
|
|
86
|
+
const mode = opts?.mode ?? "form";
|
|
87
|
+
const limit = opts?.limit ?? 20;
|
|
88
|
+
const valueField = opts?.valueField;
|
|
89
|
+
const selectFields = opts?.select ?? computeSelectFields(resolved, mode, valueField);
|
|
90
|
+
const text = opts?.text;
|
|
91
|
+
const scope = opts?.filter;
|
|
92
|
+
const controls = {
|
|
93
|
+
$select: selectFields,
|
|
94
|
+
$limit: limit
|
|
95
|
+
};
|
|
96
|
+
let filter = scope;
|
|
97
|
+
if (text) if (resolved.searchable) controls.$search = text;
|
|
98
|
+
else {
|
|
99
|
+
const search = buildOrFilter(text, selectFields, valueField ?? resolved.primaryKeys[0] ?? resolved.labelField);
|
|
100
|
+
filter = scope ? { $and: [scope, search] } : search;
|
|
101
|
+
}
|
|
102
|
+
const items = await sharedQuery(this._client, {
|
|
103
|
+
...filter && { filter },
|
|
104
|
+
controls
|
|
105
|
+
});
|
|
106
|
+
return { items: Array.isArray(items) ? items.slice() : items };
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Compute the $select fields for a value-help query — always including the
|
|
111
|
+
* `valueField` the picker commits (a unique non-PK field is otherwise never fetched).
|
|
112
|
+
*/
|
|
113
|
+
function computeSelectFields(resolved, mode, valueField) {
|
|
114
|
+
const fields = [...resolved.primaryKeys, resolved.labelField];
|
|
115
|
+
if (valueField) fields.push(valueField);
|
|
116
|
+
if (resolved.descrField) fields.push(resolved.descrField);
|
|
117
|
+
if (mode === "filter") fields.push(...resolved.attrFields);
|
|
118
|
+
return [...new Set(fields)];
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Build a Uniquery `$or` filter for value-help search across multiple fields.
|
|
122
|
+
* Uses regex startsWith (case-insensitive) on text fields + exact match on PK.
|
|
123
|
+
*/
|
|
124
|
+
function buildOrFilter(text, fields, pkField) {
|
|
125
|
+
const escaped = escapeRegex(text);
|
|
126
|
+
const conditions = [];
|
|
127
|
+
for (const field of fields) if (field !== pkField) conditions.push({ [field]: { $regex: `/^${escaped}/i` } });
|
|
128
|
+
const asNum = Number(text);
|
|
129
|
+
if (!Number.isNaN(asNum)) conditions.push({ [pkField]: asNum });
|
|
130
|
+
else conditions.push({ [pkField]: text });
|
|
131
|
+
return { $or: conditions };
|
|
132
|
+
}
|
|
133
|
+
//#endregion
|
|
134
|
+
export { ValueHelpClient, invalidateValueHelpCache, setValueHelpCacheTtl };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/ui",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.164",
|
|
4
4
|
"description": "Framework-agnostic runtime for form and table definitions from atscript annotated types",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"annotations",
|
|
@@ -47,20 +47,20 @@
|
|
|
47
47
|
"access": "public"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@atscript/db-client": "^0.1.
|
|
50
|
+
"@atscript/db-client": "^0.1.168"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@atscript/core": "^0.2.
|
|
54
|
-
"@atscript/db": "^0.1.
|
|
55
|
-
"@atscript/typescript": "^0.2.
|
|
56
|
-
"@uniqu/core": "^0.
|
|
57
|
-
"unplugin-atscript": "^0.2.
|
|
53
|
+
"@atscript/core": "^0.2.4",
|
|
54
|
+
"@atscript/db": "^0.1.168",
|
|
55
|
+
"@atscript/typescript": "^0.2.4",
|
|
56
|
+
"@uniqu/core": "^0.2.0",
|
|
57
|
+
"unplugin-atscript": "^0.2.4",
|
|
58
58
|
"vitest": "npm:@voidzero-dev/vite-plus-test@0.1.14"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
|
-
"@atscript/core": "^0.2.
|
|
62
|
-
"@atscript/db": "^0.1.
|
|
63
|
-
"@atscript/typescript": "^0.2.
|
|
61
|
+
"@atscript/core": "^0.2.4",
|
|
62
|
+
"@atscript/db": "^0.1.168",
|
|
63
|
+
"@atscript/typescript": "^0.2.4"
|
|
64
64
|
},
|
|
65
65
|
"scripts": {
|
|
66
66
|
"build": "vp pack",
|