@atscript/ui 0.1.205 → 0.1.207
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/form/create-form-def.cjs +40 -58
- package/dist/form/create-form-def.d.cts +9 -0
- package/dist/form/create-form-def.d.mts +9 -0
- package/dist/form/create-form-def.mjs +39 -57
- package/dist/form/db-column.cjs +37 -0
- package/dist/form/db-column.mjs +35 -0
- package/dist/form/path-utils.cjs +20 -5
- package/dist/form/path-utils.d.cts +8 -1
- package/dist/form/path-utils.d.mts +8 -1
- package/dist/form/path-utils.mjs +20 -6
- package/dist/form/types.d.cts +1 -0
- package/dist/form/types.d.mts +1 -0
- package/dist/index.cjs +18 -3
- package/dist/index.d.cts +8 -5
- package/dist/index.d.mts +8 -5
- package/dist/index.mjs +11 -8
- package/dist/plugin/annotations.cjs +33 -14
- package/dist/plugin/annotations.mjs +34 -15
- package/dist/plugin/value-help-validation.cjs +26 -6
- package/dist/plugin/value-help-validation.mjs +26 -7
- package/dist/shared/annotation-keys.cjs +3 -0
- package/dist/shared/annotation-keys.mjs +3 -1
- package/dist/shared/meta-cache.cjs +5 -4
- package/dist/shared/meta-cache.d.cts +3 -2
- package/dist/shared/meta-cache.d.mts +3 -2
- package/dist/shared/meta-cache.mjs +5 -4
- package/dist/shared/value-label.cjs +14 -2
- package/dist/shared/value-label.d.cts +23 -6
- package/dist/shared/value-label.d.mts +23 -6
- package/dist/shared/value-label.mjs +14 -3
- package/dist/table/create-table-def.cjs +7 -1
- package/dist/table/create-table-def.mjs +7 -2
- package/dist/table/types.d.cts +1 -1
- package/dist/table/types.d.mts +1 -1
- package/dist/value-help/client-store.cjs +43 -0
- package/dist/value-help/client-store.d.mts +1 -0
- package/dist/value-help/client-store.mjs +40 -0
- package/dist/value-help/display-value.cjs +30 -0
- package/dist/value-help/display-value.d.cts +45 -0
- package/dist/value-help/display-value.d.mts +45 -0
- package/dist/value-help/display-value.mjs +30 -0
- package/dist/value-help/extract-ref.cjs +15 -4
- package/dist/value-help/extract-ref.d.cts +6 -1
- package/dist/value-help/extract-ref.d.mts +6 -1
- package/dist/value-help/extract-ref.mjs +16 -6
- package/dist/value-help/index.d.mts +6 -3
- package/dist/value-help/options.cjs +49 -8
- package/dist/value-help/options.d.cts +41 -4
- package/dist/value-help/options.d.mts +41 -4
- package/dist/value-help/options.mjs +47 -9
- package/dist/value-help/resolve-options.cjs +9 -7
- package/dist/value-help/resolve-options.d.cts +8 -9
- package/dist/value-help/resolve-options.d.mts +8 -9
- package/dist/value-help/resolve-options.mjs +9 -7
- package/dist/value-help/resolve.cjs +39 -8
- package/dist/value-help/resolve.d.cts +22 -5
- package/dist/value-help/resolve.d.mts +22 -5
- package/dist/value-help/resolve.mjs +40 -9
- package/dist/value-help/source.cjs +72 -0
- package/dist/value-help/source.d.cts +55 -0
- package/dist/value-help/source.d.mts +55 -0
- package/dist/value-help/source.mjs +71 -0
- package/dist/value-help/texts.cjs +315 -0
- package/dist/value-help/texts.d.cts +53 -0
- package/dist/value-help/texts.d.mts +53 -0
- package/dist/value-help/texts.mjs +310 -0
- package/dist/value-help/types.d.cts +10 -0
- package/dist/value-help/types.d.mts +10 -0
- package/dist/value-help/value-help-client.cjs +21 -19
- package/dist/value-help/value-help-client.d.cts +9 -5
- package/dist/value-help/value-help-client.d.mts +9 -5
- package/dist/value-help/value-help-client.mjs +19 -17
- package/package.json +10 -10
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import { valueHelpKey } from "./extract-ref.mjs";
|
|
2
|
+
import { codeOf } from "../shared/value-label.mjs";
|
|
3
|
+
import { clientStore, dropClientStores, staleClientStores } from "./client-store.mjs";
|
|
4
|
+
import { valueHelpRowText } from "./options.mjs";
|
|
5
|
+
import { valueHelpSource } from "./source.mjs";
|
|
6
|
+
//#region src/value-help/texts.ts
|
|
7
|
+
/** Codes per request: a lookup is a GET, the codes travel in its URL. */
|
|
8
|
+
const LOOKUP_BATCH = 100;
|
|
9
|
+
/** Texts kept per dictionary, binding scope and label field; the least recently read go first. */
|
|
10
|
+
const MAX_TEXTS = 1e4;
|
|
11
|
+
/** A failed lookup (no access, no network) asks again after this long (ms). */
|
|
12
|
+
const RETRY_MS = 3e4;
|
|
13
|
+
/**
|
|
14
|
+
* Per binding (`labelId`): the label its codes show; `null` for none — also
|
|
15
|
+
* when the dictionary's `/meta` failed, so no read asks for it again until
|
|
16
|
+
* the cache is dropped; a promise while resolving.
|
|
17
|
+
*/
|
|
18
|
+
let labels = /* @__PURE__ */ new Map();
|
|
19
|
+
/** The sources texts were read through: their `/meta` failing fails their binding's label. */
|
|
20
|
+
const watched = /* @__PURE__ */ new WeakSet();
|
|
21
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
22
|
+
/** What a binding's label depends on: its dictionary and key, its own label, its host scope. */
|
|
23
|
+
function labelId(info) {
|
|
24
|
+
const { label } = info;
|
|
25
|
+
const host = info.hostFilter ? "host" : "";
|
|
26
|
+
return `${valueHelpKey(info)}\0${label?.field ?? ""}\0${label?.arrangement ?? ""}\0${host}`;
|
|
27
|
+
}
|
|
28
|
+
/** The texts of the codes `info` binds, in its scope, read through `store`'s client from `field`. */
|
|
29
|
+
function textsOf(store, info, field) {
|
|
30
|
+
const scope = info.filter ? JSON.stringify(info.filter) : "";
|
|
31
|
+
const id = `${info.targetField}\0${field}\0${scope}`;
|
|
32
|
+
let texts = store.texts.get(id);
|
|
33
|
+
if (!texts) {
|
|
34
|
+
texts = {
|
|
35
|
+
client: store.client,
|
|
36
|
+
binding: valueHelpKey(info),
|
|
37
|
+
key: info.targetField,
|
|
38
|
+
field,
|
|
39
|
+
filter: info.filter,
|
|
40
|
+
slots: /* @__PURE__ */ new Map(),
|
|
41
|
+
stale: store.stale?.get(id)?.slots
|
|
42
|
+
};
|
|
43
|
+
store.texts.set(id, texts);
|
|
44
|
+
}
|
|
45
|
+
return texts;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* {@link textsOf} the client `info`'s source reads with. A dictionary entry
|
|
49
|
+
* made again (evicted, another UI locale) whose `/meta` fails ends the label
|
|
50
|
+
* of every binding read through it: their codes show alone until the next
|
|
51
|
+
* drop, never asked again on each read.
|
|
52
|
+
*/
|
|
53
|
+
function textsFor(info, id, label, options) {
|
|
54
|
+
const source = valueHelpSource(info, options);
|
|
55
|
+
if (!watched.has(source)) {
|
|
56
|
+
watched.add(source);
|
|
57
|
+
const map = labels;
|
|
58
|
+
source.entry.meta.catch(() => map.set(id, null));
|
|
59
|
+
}
|
|
60
|
+
return textsOf(clientStore(source.entry.client), info, label.field);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The label a binding's codes show by key: none for a dictionary keyed by
|
|
64
|
+
* more than one field, nor for a binding scoped by host values
|
|
65
|
+
* (`ValueHelpInfo.hostFilter`) whose key is not the dictionary's single
|
|
66
|
+
* primary key — such a code names no one row a batched lookup can find.
|
|
67
|
+
*/
|
|
68
|
+
function codeLabel(resolved, info) {
|
|
69
|
+
const keys = resolved.primaryKeys;
|
|
70
|
+
if (keys.length > 1 || info.hostFilter && keys[0] !== info.targetField) return void 0;
|
|
71
|
+
return resolved.label;
|
|
72
|
+
}
|
|
73
|
+
function notify(binding) {
|
|
74
|
+
for (const listener of listeners) listener(binding);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The label a binding's codes show, resolved once per binding: its
|
|
78
|
+
* `ResolvedValueHelp.label`; `null` without one, after a failed `/meta` read,
|
|
79
|
+
* or when its codes cannot be read by key (`codeLabel`).
|
|
80
|
+
*/
|
|
81
|
+
function labelOf(info, id, options) {
|
|
82
|
+
let label = labels.get(id);
|
|
83
|
+
if (label === void 0) {
|
|
84
|
+
const pending = valueHelpSource(info, options).resolve().then((r) => codeLabel(r, info) ?? null, () => null);
|
|
85
|
+
labels.set(id, label = pending);
|
|
86
|
+
pending.then((resolved) => {
|
|
87
|
+
if (labels.get(id) !== pending) return;
|
|
88
|
+
labels.set(id, resolved);
|
|
89
|
+
if (resolved) notify(valueHelpKey(info));
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return label;
|
|
93
|
+
}
|
|
94
|
+
/** Sets the slot of `code` as the most recently read. */
|
|
95
|
+
function touch(slots, code, slot) {
|
|
96
|
+
slots.delete(code);
|
|
97
|
+
slots.set(code, slot);
|
|
98
|
+
}
|
|
99
|
+
/** Drops the least recently read settled texts beyond {@link MAX_TEXTS}. */
|
|
100
|
+
function trim(slots) {
|
|
101
|
+
if (slots.size <= MAX_TEXTS) return;
|
|
102
|
+
for (const [code, slot] of slots) {
|
|
103
|
+
if (!(slot instanceof Promise)) slots.delete(code);
|
|
104
|
+
if (slots.size <= MAX_TEXTS) return;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* The texts `rows` give their codes (`key`) from `field`: a code several rows
|
|
109
|
+
* give different texts is ambiguous and gets none (`null`) — never the first
|
|
110
|
+
* row's. A row without the field gives nothing.
|
|
111
|
+
*/
|
|
112
|
+
function rowTexts(rows, key, field) {
|
|
113
|
+
const texts = /* @__PURE__ */ new Map();
|
|
114
|
+
for (const row of rows) {
|
|
115
|
+
const code = codeOf(row[key]);
|
|
116
|
+
if (code === void 0 || !(field in row)) continue;
|
|
117
|
+
const text = valueHelpRowText({ labelField: field }, row).label ?? null;
|
|
118
|
+
const known = texts.get(code);
|
|
119
|
+
texts.set(code, known === void 0 || known === text ? text : null);
|
|
120
|
+
}
|
|
121
|
+
return texts;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Ask for the text of `code`: it joins this tick's batch of `texts`, read
|
|
125
|
+
* once the tick's reads have queued their codes. Nothing while a failed
|
|
126
|
+
* lookup waits to retry. Returns what the code's slot waits on.
|
|
127
|
+
*/
|
|
128
|
+
function ask(texts, code, value) {
|
|
129
|
+
if (texts.retry !== void 0) return void 0;
|
|
130
|
+
let batch = texts.batch;
|
|
131
|
+
if (!batch) {
|
|
132
|
+
let settle;
|
|
133
|
+
const done = new Promise((resolve) => settle = resolve);
|
|
134
|
+
const created = {
|
|
135
|
+
values: /* @__PURE__ */ new Map(),
|
|
136
|
+
done,
|
|
137
|
+
settle
|
|
138
|
+
};
|
|
139
|
+
texts.batch = batch = created;
|
|
140
|
+
queueMicrotask(() => {
|
|
141
|
+
texts.batch = void 0;
|
|
142
|
+
lookup(texts, created);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
batch.values.set(code, value);
|
|
146
|
+
texts.slots.set(code, batch.done);
|
|
147
|
+
return batch.done;
|
|
148
|
+
}
|
|
149
|
+
async function lookup(texts, batch) {
|
|
150
|
+
const { client, key, field, filter, slots } = texts;
|
|
151
|
+
const { done } = batch;
|
|
152
|
+
const entries = [...batch.values];
|
|
153
|
+
const select = key === field ? [key] : [key, field];
|
|
154
|
+
let failed = false;
|
|
155
|
+
let landed = false;
|
|
156
|
+
const requests = [];
|
|
157
|
+
for (let i = 0; i < entries.length; i += LOOKUP_BATCH) {
|
|
158
|
+
const chunk = entries.slice(i, i + LOOKUP_BATCH);
|
|
159
|
+
const codes = { [key]: { $in: chunk.map(([, value]) => value) } };
|
|
160
|
+
const request = {
|
|
161
|
+
filter: filter ? { $and: [filter, codes] } : codes,
|
|
162
|
+
controls: { $select: select }
|
|
163
|
+
};
|
|
164
|
+
requests.push(Promise.resolve().then(() => client.query(request)).then((rows) => {
|
|
165
|
+
const found = rowTexts(rows, key, field);
|
|
166
|
+
for (const [code] of chunk) {
|
|
167
|
+
if (slots.get(code) !== done) continue;
|
|
168
|
+
const text = found.get(code) ?? null;
|
|
169
|
+
slots.set(code, text);
|
|
170
|
+
if (text !== null) landed = true;
|
|
171
|
+
}
|
|
172
|
+
}).catch(() => {
|
|
173
|
+
failed = true;
|
|
174
|
+
for (const [code] of chunk) if (slots.get(code) === done) slots.delete(code);
|
|
175
|
+
}));
|
|
176
|
+
}
|
|
177
|
+
await Promise.all(requests);
|
|
178
|
+
if (failed) texts.retry ??= setTimeout(() => {
|
|
179
|
+
texts.retry = void 0;
|
|
180
|
+
notify(texts.binding);
|
|
181
|
+
}, RETRY_MS);
|
|
182
|
+
trim(slots);
|
|
183
|
+
batch.settle();
|
|
184
|
+
if (landed) notify(texts.binding);
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* The dictionary text of a code bound by `info` (since 0.1.207): its row's
|
|
188
|
+
* value of the binding's label — `@ui.valueHelp.label`, else the
|
|
189
|
+
* dictionary's `@ui.dict.label` — in the binding's scope (its static
|
|
190
|
+
* `@ui.valueHelp` filter), with the arrangement to show it in
|
|
191
|
+
* (`displayValue` puts the two together). `undefined` while it loads, and for
|
|
192
|
+
* good when neither label is declared, the label field is not readable, the
|
|
193
|
+
* dictionary is keyed by more than one field, the binding's filter refers to
|
|
194
|
+
* host values and its key is not the dictionary's single primary key, its
|
|
195
|
+
* `/meta` cannot be read, no row holds the code, several rows hold it with
|
|
196
|
+
* different texts, or its text is empty: the code then shows alone. A failed
|
|
197
|
+
* lookup is asked again after a while.
|
|
198
|
+
*
|
|
199
|
+
* A miss asks for it: the misses of one tick are read in one request per
|
|
200
|
+
* dictionary and scope (`$filter` the key `$in` the codes, AND the scope;
|
|
201
|
+
* `$select` the key and the label field), through the binding's
|
|
202
|
+
* `valueHelpSource` (`options`); the rows the pickers read fill the same
|
|
203
|
+
* cache. `options.peek` reads only the texts already known: no lookup. After a
|
|
204
|
+
* data drop (`invalidateValueHelpCache`) a code keeps its text until read
|
|
205
|
+
* again. {@link onValueHelpTexts} reports arrivals, so a view can read again.
|
|
206
|
+
* In the browser only: a server render shows codes.
|
|
207
|
+
*/
|
|
208
|
+
function valueHelpText(info, value, options) {
|
|
209
|
+
const code = codeOf(value);
|
|
210
|
+
if (code === void 0 || typeof window === "undefined") return void 0;
|
|
211
|
+
const id = labelId(info);
|
|
212
|
+
const label = labelOf(info, id, options);
|
|
213
|
+
if (!label || label instanceof Promise) return void 0;
|
|
214
|
+
const texts = textsFor(info, id, label, options);
|
|
215
|
+
const slot = texts.slots.get(code);
|
|
216
|
+
if (slot === void 0 && !options?.peek) ask(texts, code, value);
|
|
217
|
+
const text = slot === void 0 || slot instanceof Promise ? texts.stale?.get(code) : slot;
|
|
218
|
+
if (typeof text !== "string") return void 0;
|
|
219
|
+
if (text === slot) touch(texts.slots, code, slot);
|
|
220
|
+
return {
|
|
221
|
+
text,
|
|
222
|
+
arrangement: label.arrangement
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Loads the texts of `values` bound by `info` in one batched read (since
|
|
227
|
+
* 0.1.207): resolves once {@link valueHelpText} knows each of them — before
|
|
228
|
+
* an export writes its rows, or as a table's rows land. Without a code among
|
|
229
|
+
* them it reads nothing, not even the dictionary's `/meta`. Never rejects.
|
|
230
|
+
*/
|
|
231
|
+
async function loadValueHelpTexts(info, values, options) {
|
|
232
|
+
if (typeof window === "undefined") return;
|
|
233
|
+
const codes = /* @__PURE__ */ new Map();
|
|
234
|
+
for (const value of values) {
|
|
235
|
+
const code = codeOf(value);
|
|
236
|
+
if (code !== void 0) codes.set(code, value);
|
|
237
|
+
}
|
|
238
|
+
if (codes.size === 0) return;
|
|
239
|
+
const id = labelId(info);
|
|
240
|
+
const label = await labelOf(info, id, options);
|
|
241
|
+
if (!label) return;
|
|
242
|
+
const texts = textsFor(info, id, label, options);
|
|
243
|
+
const waits = /* @__PURE__ */ new Set();
|
|
244
|
+
for (const [code, value] of codes) {
|
|
245
|
+
const slot = texts.slots.get(code);
|
|
246
|
+
const wait = slot === void 0 ? ask(texts, code, value) : slot;
|
|
247
|
+
if (wait instanceof Promise) waits.add(wait);
|
|
248
|
+
}
|
|
249
|
+
await Promise.all(waits);
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Run `listener` whenever texts arrive or are dropped, so a view reading
|
|
253
|
+
* {@link valueHelpText} reads again: with the binding whose texts arrived
|
|
254
|
+
* (`valueHelpKey`), with none when the cache was dropped. Returns the
|
|
255
|
+
* unsubscribe function. Since 0.1.207.
|
|
256
|
+
*/
|
|
257
|
+
function onValueHelpTexts(listener) {
|
|
258
|
+
listeners.add(listener);
|
|
259
|
+
return () => {
|
|
260
|
+
listeners.delete(listener);
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Picker rows fill the cache: the rows of a binding's search or picker page,
|
|
265
|
+
* with its label field, land in the texts of that binding's scope in `store`
|
|
266
|
+
* — the client's store when the read began, so rows read before a data drop
|
|
267
|
+
* land in the stale one.
|
|
268
|
+
*
|
|
269
|
+
* @internal
|
|
270
|
+
*/
|
|
271
|
+
function feedValueHelpTexts(store, info, resolved, rows) {
|
|
272
|
+
const label = codeLabel(resolved, info);
|
|
273
|
+
if (!label || !Array.isArray(rows)) return;
|
|
274
|
+
const { slots } = textsOf(store, info, label.field);
|
|
275
|
+
let changed = false;
|
|
276
|
+
for (const [code, text] of rowTexts(rows, info.targetField, label.field)) {
|
|
277
|
+
const prev = slots.get(code);
|
|
278
|
+
if (prev === text) continue;
|
|
279
|
+
touch(slots, code, text);
|
|
280
|
+
if (prev !== void 0) changed = true;
|
|
281
|
+
}
|
|
282
|
+
trim(slots);
|
|
283
|
+
if (changed) notify(valueHelpKey(info));
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* The data of `client`'s dictionary, or of every one, changed
|
|
287
|
+
* (`invalidateValueHelpCache`): its store goes stale (`staleClientStores`:
|
|
288
|
+
* its searches go, its texts show until read again), the labels stay — a
|
|
289
|
+
* binding whose label failed is asked again; mounted views read again.
|
|
290
|
+
*
|
|
291
|
+
* @internal
|
|
292
|
+
*/
|
|
293
|
+
function staleValueHelpTexts(client) {
|
|
294
|
+
staleClientStores(client);
|
|
295
|
+
for (const [id, label] of labels) if (label === null) labels.delete(id);
|
|
296
|
+
notify();
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* A reset (`resetMetaCache`: another viewer): every client's store and every
|
|
300
|
+
* binding's label go; mounted views read again.
|
|
301
|
+
*
|
|
302
|
+
* @internal
|
|
303
|
+
*/
|
|
304
|
+
function resetValueHelpTexts() {
|
|
305
|
+
dropClientStores();
|
|
306
|
+
labels = /* @__PURE__ */ new Map();
|
|
307
|
+
notify();
|
|
308
|
+
}
|
|
309
|
+
//#endregion
|
|
310
|
+
export { feedValueHelpTexts, loadValueHelpTexts, onValueHelpTexts, resetValueHelpTexts, staleValueHelpTexts, valueHelpText };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ValueLabelArrangement } from "../shared/value-label.cjs";
|
|
1
2
|
import { FilterExpr } from "@atscript/db-client";
|
|
2
3
|
|
|
3
4
|
//#region src/value-help/types.d.ts
|
|
@@ -64,6 +65,15 @@ interface ValueHelpInfo {
|
|
|
64
65
|
* order, instead of the dictionary view. Since 0.1.190.
|
|
65
66
|
*/
|
|
66
67
|
columns?: string[];
|
|
68
|
+
/**
|
|
69
|
+
* `@ui.valueHelp.label`: the dictionary field holding the text of this
|
|
70
|
+
* binding's codes, instead of the dictionary's `@ui.dict.label`, and the
|
|
71
|
+
* arrangement they show in (the dictionary's when left out). Since 0.1.207.
|
|
72
|
+
*/
|
|
73
|
+
label?: {
|
|
74
|
+
field: string;
|
|
75
|
+
arrangement?: ValueLabelArrangement;
|
|
76
|
+
};
|
|
67
77
|
}
|
|
68
78
|
//#endregion
|
|
69
79
|
export { TFormEntryOptions, ValueHelpInfo };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ValueLabelArrangement } from "../shared/value-label.mjs";
|
|
1
2
|
import { FilterExpr } from "@atscript/db-client";
|
|
2
3
|
|
|
3
4
|
//#region src/value-help/types.d.ts
|
|
@@ -64,6 +65,15 @@ interface ValueHelpInfo {
|
|
|
64
65
|
* order, instead of the dictionary view. Since 0.1.190.
|
|
65
66
|
*/
|
|
66
67
|
columns?: string[];
|
|
68
|
+
/**
|
|
69
|
+
* `@ui.valueHelp.label`: the dictionary field holding the text of this
|
|
70
|
+
* binding's codes, instead of the dictionary's `@ui.dict.label`, and the
|
|
71
|
+
* arrangement they show in (the dictionary's when left out). Since 0.1.207.
|
|
72
|
+
*/
|
|
73
|
+
label?: {
|
|
74
|
+
field: string;
|
|
75
|
+
arrangement?: ValueLabelArrangement;
|
|
76
|
+
};
|
|
67
77
|
}
|
|
68
78
|
//#endregion
|
|
69
79
|
export { TFormEntryOptions, ValueHelpInfo };
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
const require_dict_paths = require("./dict-paths.cjs");
|
|
1
2
|
const require_str = require("../shared/str.cjs");
|
|
2
3
|
const require_create_table_def = require("../table/create-table-def.cjs");
|
|
3
4
|
const require_value_kind = require("../table/value-kind.cjs");
|
|
5
|
+
const require_client_store = require("./client-store.cjs");
|
|
6
|
+
const require_texts = require("./texts.cjs");
|
|
4
7
|
//#region src/value-help/value-help-client.ts
|
|
5
8
|
let cacheTtl = 5e3;
|
|
6
|
-
let searches = /* @__PURE__ */ new WeakMap();
|
|
7
9
|
/**
|
|
8
10
|
* How long (ms) a settled value-help search is reused for an identical
|
|
9
11
|
* search on the same client. Default 5000. `0` shares only searches still in
|
|
@@ -14,16 +16,16 @@ function setValueHelpCacheTtl(ms) {
|
|
|
14
16
|
cacheTtl = ms;
|
|
15
17
|
}
|
|
16
18
|
/**
|
|
17
|
-
*
|
|
18
|
-
* client
|
|
19
|
-
*
|
|
19
|
+
* The dictionaries' data changed: drop shared value-help search results — for
|
|
20
|
+
* one `client`, or for every client when omitted — and (since 0.1.207) mark
|
|
21
|
+
* the texts of codes read from them stale: a code keeps its text until it is
|
|
22
|
+
* read again (one batched request), then the new text replaces it. The
|
|
23
|
+
* labels the bindings resolved stay (they are metadata); a dictionary whose
|
|
24
|
+
* `/meta` failed is asked again. Mounted views read their texts again. Call
|
|
25
|
+
* after writing to a dictionary outside the built-in table actions.
|
|
20
26
|
*/
|
|
21
27
|
function invalidateValueHelpCache(client) {
|
|
22
|
-
|
|
23
|
-
else searches = /* @__PURE__ */ new WeakMap();
|
|
24
|
-
}
|
|
25
|
-
function now() {
|
|
26
|
-
return typeof performance === "undefined" ? Date.now() : performance.now();
|
|
28
|
+
require_texts.staleValueHelpTexts(client);
|
|
27
29
|
}
|
|
28
30
|
/** Cache key of a plain-JSON request; `undefined` when it holds anything else (never shared). */
|
|
29
31
|
function requestKey(request) {
|
|
@@ -47,12 +49,11 @@ function sharedQuery(client, request) {
|
|
|
47
49
|
if (cacheTtl < 0 || typeof window === "undefined") return run();
|
|
48
50
|
const key = requestKey(request);
|
|
49
51
|
if (key === void 0) return run();
|
|
50
|
-
|
|
51
|
-
if (!byKey) searches.set(client, byKey = /* @__PURE__ */ new Map());
|
|
52
|
+
const byKey = require_client_store.clientStore(client).searches;
|
|
52
53
|
const hit = byKey.get(key);
|
|
53
|
-
if (hit && (hit.settledAt === void 0 || now() - hit.settledAt < cacheTtl)) return hit.promise;
|
|
54
|
+
if (hit && (hit.settledAt === void 0 || require_client_store.now() - hit.settledAt < cacheTtl)) return hit.promise;
|
|
54
55
|
const entry = { promise: run().then((items) => {
|
|
55
|
-
entry.settledAt = now();
|
|
56
|
+
entry.settledAt = require_client_store.now();
|
|
56
57
|
return items;
|
|
57
58
|
}, (err) => {
|
|
58
59
|
if (byKey.get(key) === entry) byKey.delete(key);
|
|
@@ -67,8 +68,8 @@ function sharedQuery(client, request) {
|
|
|
67
68
|
* $select scoping).
|
|
68
69
|
*
|
|
69
70
|
* Consumers resolve the target's metadata once via `resolveValueHelp(url)`
|
|
70
|
-
* and pass the resulting `ResolvedValueHelp` to `search()`.
|
|
71
|
-
*
|
|
71
|
+
* and pass the resulting `ResolvedValueHelp` to `search()`. A binding's
|
|
72
|
+
* `valueHelpSource` searches through it and fills the texts of its codes.
|
|
72
73
|
*
|
|
73
74
|
* Identical searches on the same `Client` are shared (see
|
|
74
75
|
* {@link setValueHelpCacheTtl}).
|
|
@@ -128,14 +129,15 @@ function valueHelpSelect(resolved, info, mode = "form", valueField = info?.targe
|
|
|
128
129
|
return [...new Set(fields)];
|
|
129
130
|
}
|
|
130
131
|
/**
|
|
131
|
-
* The dictionary's own fields of a value-help query
|
|
132
|
-
*
|
|
132
|
+
* The dictionary's own fields of a value-help query: in `"filter"` mode its
|
|
133
|
+
* dictionary view (`valueHelpDictPaths`), in `"form"` mode its keys, label and
|
|
134
|
+
* description — always including the `valueField` the picker commits (a
|
|
135
|
+
* unique non-PK field is otherwise never fetched).
|
|
133
136
|
*/
|
|
134
137
|
function computeSelectFields(resolved, mode, valueField) {
|
|
135
|
-
const fields = [...resolved.primaryKeys, resolved.labelField];
|
|
138
|
+
const fields = mode === "filter" ? [...require_dict_paths.valueHelpDictPaths(resolved)] : [...resolved.primaryKeys, resolved.labelField];
|
|
136
139
|
if (valueField) fields.push(valueField);
|
|
137
140
|
if (resolved.descrField) fields.push(resolved.descrField);
|
|
138
|
-
if (mode === "filter") fields.push(...resolved.attrFields);
|
|
139
141
|
return [...new Set(fields)];
|
|
140
142
|
}
|
|
141
143
|
/** Storage kinds the server matches text against (`$regex`): strings and whole numbers. */
|
|
@@ -46,9 +46,13 @@ interface ValueHelpResult {
|
|
|
46
46
|
*/
|
|
47
47
|
declare function setValueHelpCacheTtl(ms: number): void;
|
|
48
48
|
/**
|
|
49
|
-
*
|
|
50
|
-
* client
|
|
51
|
-
*
|
|
49
|
+
* The dictionaries' data changed: drop shared value-help search results — for
|
|
50
|
+
* one `client`, or for every client when omitted — and (since 0.1.207) mark
|
|
51
|
+
* the texts of codes read from them stale: a code keeps its text until it is
|
|
52
|
+
* read again (one batched request), then the new text replaces it. The
|
|
53
|
+
* labels the bindings resolved stay (they are metadata); a dictionary whose
|
|
54
|
+
* `/meta` failed is asked again. Mounted views read their texts again. Call
|
|
55
|
+
* after writing to a dictionary outside the built-in table actions.
|
|
52
56
|
*/
|
|
53
57
|
declare function invalidateValueHelpCache(client?: ClientLike): void;
|
|
54
58
|
/**
|
|
@@ -57,8 +61,8 @@ declare function invalidateValueHelpCache(client?: ClientLike): void;
|
|
|
57
61
|
* $select scoping).
|
|
58
62
|
*
|
|
59
63
|
* Consumers resolve the target's metadata once via `resolveValueHelp(url)`
|
|
60
|
-
* and pass the resulting `ResolvedValueHelp` to `search()`.
|
|
61
|
-
*
|
|
64
|
+
* and pass the resulting `ResolvedValueHelp` to `search()`. A binding's
|
|
65
|
+
* `valueHelpSource` searches through it and fills the texts of its codes.
|
|
62
66
|
*
|
|
63
67
|
* Identical searches on the same `Client` are shared (see
|
|
64
68
|
* {@link setValueHelpCacheTtl}).
|
|
@@ -46,9 +46,13 @@ interface ValueHelpResult {
|
|
|
46
46
|
*/
|
|
47
47
|
declare function setValueHelpCacheTtl(ms: number): void;
|
|
48
48
|
/**
|
|
49
|
-
*
|
|
50
|
-
* client
|
|
51
|
-
*
|
|
49
|
+
* The dictionaries' data changed: drop shared value-help search results — for
|
|
50
|
+
* one `client`, or for every client when omitted — and (since 0.1.207) mark
|
|
51
|
+
* the texts of codes read from them stale: a code keeps its text until it is
|
|
52
|
+
* read again (one batched request), then the new text replaces it. The
|
|
53
|
+
* labels the bindings resolved stay (they are metadata); a dictionary whose
|
|
54
|
+
* `/meta` failed is asked again. Mounted views read their texts again. Call
|
|
55
|
+
* after writing to a dictionary outside the built-in table actions.
|
|
52
56
|
*/
|
|
53
57
|
declare function invalidateValueHelpCache(client?: ClientLike): void;
|
|
54
58
|
/**
|
|
@@ -57,8 +61,8 @@ declare function invalidateValueHelpCache(client?: ClientLike): void;
|
|
|
57
61
|
* $select scoping).
|
|
58
62
|
*
|
|
59
63
|
* Consumers resolve the target's metadata once via `resolveValueHelp(url)`
|
|
60
|
-
* and pass the resulting `ResolvedValueHelp` to `search()`.
|
|
61
|
-
*
|
|
64
|
+
* and pass the resulting `ResolvedValueHelp` to `search()`. A binding's
|
|
65
|
+
* `valueHelpSource` searches through it and fills the texts of its codes.
|
|
62
66
|
*
|
|
63
67
|
* Identical searches on the same `Client` are shared (see
|
|
64
68
|
* {@link setValueHelpCacheTtl}).
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { valueHelpDictPaths } from "./dict-paths.mjs";
|
|
1
2
|
import { escapeRegex } from "../shared/str.mjs";
|
|
2
3
|
import { inferValueKind } from "../table/create-table-def.mjs";
|
|
3
4
|
import { coerceNumericText } from "../table/value-kind.mjs";
|
|
5
|
+
import { clientStore, now } from "./client-store.mjs";
|
|
6
|
+
import { staleValueHelpTexts } from "./texts.mjs";
|
|
4
7
|
//#region src/value-help/value-help-client.ts
|
|
5
8
|
let cacheTtl = 5e3;
|
|
6
|
-
let searches = /* @__PURE__ */ new WeakMap();
|
|
7
9
|
/**
|
|
8
10
|
* How long (ms) a settled value-help search is reused for an identical
|
|
9
11
|
* search on the same client. Default 5000. `0` shares only searches still in
|
|
@@ -14,16 +16,16 @@ function setValueHelpCacheTtl(ms) {
|
|
|
14
16
|
cacheTtl = ms;
|
|
15
17
|
}
|
|
16
18
|
/**
|
|
17
|
-
*
|
|
18
|
-
* client
|
|
19
|
-
*
|
|
19
|
+
* The dictionaries' data changed: drop shared value-help search results — for
|
|
20
|
+
* one `client`, or for every client when omitted — and (since 0.1.207) mark
|
|
21
|
+
* the texts of codes read from them stale: a code keeps its text until it is
|
|
22
|
+
* read again (one batched request), then the new text replaces it. The
|
|
23
|
+
* labels the bindings resolved stay (they are metadata); a dictionary whose
|
|
24
|
+
* `/meta` failed is asked again. Mounted views read their texts again. Call
|
|
25
|
+
* after writing to a dictionary outside the built-in table actions.
|
|
20
26
|
*/
|
|
21
27
|
function invalidateValueHelpCache(client) {
|
|
22
|
-
|
|
23
|
-
else searches = /* @__PURE__ */ new WeakMap();
|
|
24
|
-
}
|
|
25
|
-
function now() {
|
|
26
|
-
return typeof performance === "undefined" ? Date.now() : performance.now();
|
|
28
|
+
staleValueHelpTexts(client);
|
|
27
29
|
}
|
|
28
30
|
/** Cache key of a plain-JSON request; `undefined` when it holds anything else (never shared). */
|
|
29
31
|
function requestKey(request) {
|
|
@@ -47,8 +49,7 @@ function sharedQuery(client, request) {
|
|
|
47
49
|
if (cacheTtl < 0 || typeof window === "undefined") return run();
|
|
48
50
|
const key = requestKey(request);
|
|
49
51
|
if (key === void 0) return run();
|
|
50
|
-
|
|
51
|
-
if (!byKey) searches.set(client, byKey = /* @__PURE__ */ new Map());
|
|
52
|
+
const byKey = clientStore(client).searches;
|
|
52
53
|
const hit = byKey.get(key);
|
|
53
54
|
if (hit && (hit.settledAt === void 0 || now() - hit.settledAt < cacheTtl)) return hit.promise;
|
|
54
55
|
const entry = { promise: run().then((items) => {
|
|
@@ -67,8 +68,8 @@ function sharedQuery(client, request) {
|
|
|
67
68
|
* $select scoping).
|
|
68
69
|
*
|
|
69
70
|
* Consumers resolve the target's metadata once via `resolveValueHelp(url)`
|
|
70
|
-
* and pass the resulting `ResolvedValueHelp` to `search()`.
|
|
71
|
-
*
|
|
71
|
+
* and pass the resulting `ResolvedValueHelp` to `search()`. A binding's
|
|
72
|
+
* `valueHelpSource` searches through it and fills the texts of its codes.
|
|
72
73
|
*
|
|
73
74
|
* Identical searches on the same `Client` are shared (see
|
|
74
75
|
* {@link setValueHelpCacheTtl}).
|
|
@@ -128,14 +129,15 @@ function valueHelpSelect(resolved, info, mode = "form", valueField = info?.targe
|
|
|
128
129
|
return [...new Set(fields)];
|
|
129
130
|
}
|
|
130
131
|
/**
|
|
131
|
-
* The dictionary's own fields of a value-help query
|
|
132
|
-
*
|
|
132
|
+
* The dictionary's own fields of a value-help query: in `"filter"` mode its
|
|
133
|
+
* dictionary view (`valueHelpDictPaths`), in `"form"` mode its keys, label and
|
|
134
|
+
* description — always including the `valueField` the picker commits (a
|
|
135
|
+
* unique non-PK field is otherwise never fetched).
|
|
133
136
|
*/
|
|
134
137
|
function computeSelectFields(resolved, mode, valueField) {
|
|
135
|
-
const fields = [...resolved.primaryKeys, resolved.labelField];
|
|
138
|
+
const fields = mode === "filter" ? [...valueHelpDictPaths(resolved)] : [...resolved.primaryKeys, resolved.labelField];
|
|
136
139
|
if (valueField) fields.push(valueField);
|
|
137
140
|
if (resolved.descrField) fields.push(resolved.descrField);
|
|
138
|
-
if (mode === "filter") fields.push(...resolved.attrFields);
|
|
139
141
|
return [...new Set(fields)];
|
|
140
142
|
}
|
|
141
143
|
/** Storage kinds the server matches text against (`$regex`): strings and whole numbers. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/ui",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.207",
|
|
4
4
|
"description": "Framework-agnostic runtime for form and table definitions from atscript annotated types",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"annotations",
|
|
@@ -52,19 +52,19 @@
|
|
|
52
52
|
"access": "public"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@atscript/core": "^0.2.
|
|
56
|
-
"@atscript/db": "^0.1.
|
|
57
|
-
"@atscript/db-client": "^0.1.
|
|
58
|
-
"@atscript/typescript": "^0.2.
|
|
55
|
+
"@atscript/core": "^0.2.33",
|
|
56
|
+
"@atscript/db": "^0.1.211",
|
|
57
|
+
"@atscript/db-client": "^0.1.211",
|
|
58
|
+
"@atscript/typescript": "^0.2.33",
|
|
59
59
|
"@uniqu/core": "^0.3.0",
|
|
60
|
-
"unplugin-atscript": "^0.2.
|
|
60
|
+
"unplugin-atscript": "^0.2.33",
|
|
61
61
|
"vitest": "npm:@voidzero-dev/vite-plus-test@0.1.14"
|
|
62
62
|
},
|
|
63
63
|
"peerDependencies": {
|
|
64
|
-
"@atscript/core": "^0.2.
|
|
65
|
-
"@atscript/db": "^0.1.
|
|
66
|
-
"@atscript/db-client": "^0.1.
|
|
67
|
-
"@atscript/typescript": "^0.2.
|
|
64
|
+
"@atscript/core": "^0.2.33",
|
|
65
|
+
"@atscript/db": "^0.1.211",
|
|
66
|
+
"@atscript/db-client": "^0.1.211",
|
|
67
|
+
"@atscript/typescript": "^0.2.33"
|
|
68
68
|
},
|
|
69
69
|
"scripts": {
|
|
70
70
|
"build": "vp pack",
|