@atscript/ui 0.1.146 → 0.1.148

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.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Validator, createDataFromAnnotatedType, deserializeAnnotatedType, detectDiscriminator, flattenAnnotatedType } from "@atscript/typescript/utils";
2
- import { Client, encodeNavigateId } from "@atscript/db-client";
2
+ import { Client, actionIdentifier, encodeNavigateId } from "@atscript/db-client";
3
3
  import { createDbValidatorPlugin } from "@atscript/db/validator";
4
4
  //#region src/shared/annotation-keys.ts
5
5
  const UI_TYPE = "ui.type";
@@ -42,6 +42,7 @@ const UI_DICT_ATTR = "ui.dict.attr";
42
42
  const UI_DICT_FILTERABLE = "ui.dict.filterable";
43
43
  const UI_DICT_SORTABLE = "ui.dict.sortable";
44
44
  const UI_DICT_SEARCHABLE = "ui.dict.searchable";
45
+ const UI_VALUE_HELP = "ui.valueHelp";
45
46
  const UI_NAV_GROUP = "ui.nav.group";
46
47
  const UI_NAV_ORDER = "ui.nav.order";
47
48
  const UI_NAV_HIDDEN = "ui.nav.hidden";
@@ -220,10 +221,25 @@ function resolveAttrs(prop, scope, keys = {}) {
220
221
  * into union items and produces synthetic unions containing both individual
221
222
  * literals and the original union type as nested items.
222
223
  */
223
- function extractLiteralOptions(prop) {
224
+ function extractLiteralOptions(prop, outer) {
224
225
  if (prop.type.kind !== "union") return void 0;
225
226
  const result = collectLiterals(prop.type.items, /* @__PURE__ */ new Set());
226
- return result && result.length > 0 ? result : void 0;
227
+ if (!result || result.length === 0) return void 0;
228
+ const labels = [prop, outer].flatMap((node) => node?.metadata.get("ui.literalLabel") ?? []);
229
+ if (labels.length) {
230
+ const byValue = new Map(labels.map((l) => [l.value, l.label]));
231
+ for (const option of result) option.label = byValue.get(option.key) ?? option.label;
232
+ }
233
+ return result;
234
+ }
235
+ /**
236
+ * The literal options of a field: a literal union's, or those of an array of one
237
+ * (`tags: Tag[]`), where the array prop's own `@ui.literalLabel` labels win over the
238
+ * element type's. `undefined` when the field is neither. Since 0.1.148.
239
+ */
240
+ function extractFieldLiteralOptions(prop) {
241
+ if (prop.type.kind === "array") return extractLiteralOptions(prop.type.of, prop);
242
+ return extractLiteralOptions(prop);
227
243
  }
228
244
  /** Returns true when the annotated type is a union composed entirely of literal values. */
229
245
  function isPureLiteralUnion(prop) {
@@ -250,12 +266,14 @@ function checkAllLiterals(items) {
250
266
  function collectLiterals(items, seen) {
251
267
  const result = [];
252
268
  for (const item of items) if (item.type.kind === "" && item.type.value !== void 0) {
253
- const val = String(item.type.value);
269
+ const raw = item.type.value;
270
+ const val = String(raw);
254
271
  if (!seen.has(val)) {
255
272
  seen.add(val);
256
273
  result.push({
257
274
  key: val,
258
- label: val
275
+ label: val,
276
+ value: raw
259
277
  });
260
278
  }
261
279
  } else if (item.type.kind === "union") {
@@ -266,6 +284,50 @@ function collectLiterals(items, seen) {
266
284
  return result;
267
285
  }
268
286
  //#endregion
287
+ //#region src/value-help/filter-tree.ts
288
+ function isFieldRef(value) {
289
+ return value !== null && typeof value === "object" && "field" in value;
290
+ }
291
+ /**
292
+ * A deliberate copy of `translateQueryTree` from `@atscript/db`: that module is a
293
+ * server-side runtime, and importing it would pull `@atscript/db` into the browser
294
+ * bundle. `filter-tree.spec.ts` guards the two against drift.
295
+ */
296
+ function translate(node) {
297
+ if (Array.isArray(node.$and)) return { $and: node.$and.map(translate) };
298
+ if (Array.isArray(node.$or)) return { $or: node.$or.map(translate) };
299
+ if (node.$not && typeof node.$not === "object") return { $not: translate(node.$not) };
300
+ const left = node.left.field;
301
+ const op = node.op;
302
+ const right = node.right;
303
+ if (isFieldRef(right)) return { [left]: { [op]: { $field: right.field } } };
304
+ if (op === "$exists") return { [left]: { $exists: right !== false } };
305
+ return { [left]: { [op]: right } };
306
+ }
307
+ /**
308
+ * Fields the tree pins to one value (`=` comparison against a literal) at its top-level
309
+ * `and` chain. The runtime twin of `pinnedFields` in `plugin/value-help-validation.ts`
310
+ * (which reads the source predicate) — keep the two rules in step.
311
+ */
312
+ function pinnedOf(node, out) {
313
+ if (Array.isArray(node.$and)) for (const n of node.$and) pinnedOf(n, out);
314
+ else if (node.left && node.op === "$eq" && !isFieldRef(node.right)) out.push(node.left.field);
315
+ }
316
+ /**
317
+ * Translates the static `filter` of a `@ui.valueHelp` binding into a Uniquery
318
+ * `FilterExpr` (mirrors `translateQueryTree` of `@atscript/db`, with refs
319
+ * resolved to the plain field path), plus the target fields it pins with `=` —
320
+ * constant inside the picker, so their columns are hidden. Since 0.1.148.
321
+ */
322
+ function valueHelpFilter(tree) {
323
+ const pinned = [];
324
+ pinnedOf(tree, pinned);
325
+ return {
326
+ filter: translate(tree),
327
+ pinned: [...new Set(pinned)]
328
+ };
329
+ }
330
+ //#endregion
269
331
  //#region src/value-help/extract-ref.ts
270
332
  /**
271
333
  * Hard cap on how many `.ref` hops the chain walk follows. Real chains are one
@@ -274,8 +336,50 @@ function collectLiterals(items, seen) {
274
336
  */
275
337
  const MAX_REF_CHAIN_DEPTH = 8;
276
338
  /**
339
+ * `@db.http.path` of a binding target. Two producers, two shapes — `/meta`
340
+ * deserialization does not normalize annotation values, so both are read here:
341
+ *
342
+ * - compiled `.as` (the atscript runtime): the annotated type itself (a class
343
+ * with a `metadata` Map) or a getter `() => Type` for a cross-file ref;
344
+ * - `/meta` (the serialized type): a shallow target `{ id, metadata }` whose
345
+ * `metadata` is a plain record.
346
+ *
347
+ * Also accepts `{ type: () => Type }`.
348
+ */
349
+ function bindingTargetPath(target) {
350
+ if (target === null || typeof target !== "object" && typeof target !== "function") return;
351
+ const t = target;
352
+ if (typeof target === "function" && t.metadata === void 0) return bindingTargetPath(target());
353
+ if (t.metadata instanceof Map) return t.metadata.get(DB_HTTP_PATH);
354
+ if (t.metadata && typeof t.metadata === "object") return t.metadata[DB_HTTP_PATH];
355
+ return t.type === void 0 ? void 0 : bindingTargetPath(t.type);
356
+ }
357
+ /**
358
+ * The `@ui.valueHelp` binding of a node, when its target is served by a
359
+ * controller (`@db.http.path`). Without a path the binding is ignored and the
360
+ * caller falls back to the FK walk.
361
+ */
362
+ function bindingInfo(node) {
363
+ const binding = node.metadata.get(UI_VALUE_HELP);
364
+ if (!binding?.field) return void 0;
365
+ const url = bindingTargetPath(binding.target);
366
+ if (!url) return void 0;
367
+ const info = {
368
+ url,
369
+ targetField: binding.field
370
+ };
371
+ if (binding.filter) {
372
+ const { filter, pinned } = valueHelpFilter(binding.filter);
373
+ info.filter = filter;
374
+ if (pinned.length > 0) info.pinned = pinned;
375
+ }
376
+ return info;
377
+ }
378
+ /**
277
379
  * Synchronous probe. Returns `{ url, targetField }` for the first link of the
278
- * reference chain starting at `prop` that satisfies all three conditions:
380
+ * reference chain starting at `prop` that carries a `@ui.valueHelp` binding
381
+ * (since 0.1.148 — an explicit binding beats `@db.rel.FK`, and also supplies
382
+ * the static `filter` / `pinned` fields), or that satisfies all three conditions:
279
383
  *
280
384
  * 1. the link carries `@db.rel.FK`,
281
385
  * 2. the link has a `.ref`,
@@ -304,6 +408,8 @@ const MAX_REF_CHAIN_DEPTH = 8;
304
408
  function extractValueHelp(prop) {
305
409
  let node = prop;
306
410
  for (let depth = 0; node && depth < MAX_REF_CHAIN_DEPTH; depth++) {
411
+ const bound = bindingInfo(node);
412
+ if (bound) return bound;
307
413
  const ref = node.ref;
308
414
  if (!ref) return void 0;
309
415
  const target = ref.type();
@@ -335,7 +441,8 @@ const UI_TAGS = new Set([
335
441
  * - **Non-object types** (primitive, array, union, etc.): produces a single leaf root field
336
442
  * with `path: ''`.
337
443
  *
338
- * A `@db.column.derived` field is marked `derived` straight from its metadata.
444
+ * A `@db.column.derived` field is marked `derived` straight from its metadata;
445
+ * a computed view column, from `opts.metaFields`.
339
446
  */
340
447
  function createFormDef(type, opts) {
341
448
  if (type.type.kind !== "object") {
@@ -365,7 +472,9 @@ function createFormDef(type, opts) {
365
472
  if (originalProp.type.of.type.kind === "array" && !getFieldMeta(originalProp, "ui.form.component")) continue;
366
473
  }
367
474
  if (kind === "array" || kind === "object" || kind === "union" || kind === "tuple") structuredPrefixes.add(path + ".");
368
- fields.push(createFieldDef(path, originalProp));
475
+ const field = createFieldDef(path, originalProp);
476
+ if (opts?.metaFields?.[path]?.computed) field.derived = true;
477
+ fields.push(field);
369
478
  }
370
479
  const orderMap = new Map(fields.map((f) => [f, getFieldMeta(f.prop, "ui.form.order") ?? Infinity]));
371
480
  fields.sort((a, b) => orderMap.get(a) - orderMap.get(b));
@@ -660,6 +769,25 @@ function optKey(opt) {
660
769
  function optLabel(opt) {
661
770
  return typeof opt === "string" ? opt : opt.label;
662
771
  }
772
+ const labelMaps = /* @__PURE__ */ new WeakMap();
773
+ /**
774
+ * The display label of a literal-union column's option (`@ui.literalLabel`) for
775
+ * `value` — `undefined` when the column has no options or none matches. Map-backed
776
+ * per options array, so rendering a table does not scan the options per cell.
777
+ * The one lookup behind the table cell, the filter chips, export and a custom cell.
778
+ * Since 0.1.148.
779
+ */
780
+ function optionLabel(column, value) {
781
+ const options = column.options;
782
+ if (!options?.length) return void 0;
783
+ if (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean") return;
784
+ let labels = labelMaps.get(options);
785
+ if (!labels) {
786
+ labels = new Map(options.map((o) => [o.key, o.label]));
787
+ labelMaps.set(options, labels);
788
+ }
789
+ return labels.get(String(value));
790
+ }
663
791
  /**
664
792
  * Converts raw option annotation value to a normalized array.
665
793
  */
@@ -685,9 +813,23 @@ function parseStaticOptions(raw) {
685
813
  function resolveOptions(prop, scope) {
686
814
  const resolved = resolveFieldProp(prop, UI_FORM_FN_OPTIONS, UI_FORM_OPTIONS, scope, { transform: parseStaticOptions });
687
815
  if (resolved !== void 0) return resolved;
688
- const literals = extractLiteralOptions(prop);
689
- if (literals !== void 0) return literals;
690
- if (prop.type.kind === "array") return extractLiteralOptions(prop.type.of);
816
+ return extractFieldLiteralOptions(prop);
817
+ }
818
+ //#endregion
819
+ //#region src/shared/str.ts
820
+ /** Converts a dot-path to a human-readable label (e.g. 'firstName' → 'First Name'). */
821
+ function humanizePath(path) {
822
+ return path.slice(path.lastIndexOf(".") + 1).replace(/([a-z])([A-Z])/g, "$1 $2").replace(/^./, (s) => s.toUpperCase());
823
+ }
824
+ /** Escape special regex characters in user input for safe embedding in a `$regex` filter. */
825
+ function escapeRegex(input) {
826
+ return input.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
827
+ }
828
+ /** Safely convert an unknown value to a string without triggering no-base-to-string lint errors. */
829
+ function str(value) {
830
+ if (typeof value === "string") return value;
831
+ if (typeof value === "number" || typeof value === "bigint" || typeof value === "boolean") return `${value}`;
832
+ return JSON.stringify(value) ?? "";
691
833
  }
692
834
  //#endregion
693
835
  //#region src/value-help/value-help-client.ts
@@ -714,32 +856,33 @@ var ValueHelpClient = class {
714
856
  async search(resolved, opts) {
715
857
  const mode = opts?.mode ?? "form";
716
858
  const limit = opts?.limit ?? 20;
717
- const selectFields = opts?.select ?? computeSelectFields(resolved, mode);
859
+ const valueField = opts?.valueField;
860
+ const selectFields = opts?.select ?? computeSelectFields(resolved, mode, valueField);
718
861
  const text = opts?.text;
719
- if (!text) return { items: await this._client.query({ controls: {
862
+ const scope = opts?.filter;
863
+ const controls = {
720
864
  $select: selectFields,
721
865
  $limit: limit
722
- } }) };
723
- if (resolved.searchable) return { items: await this._client.query({ controls: {
724
- $select: selectFields,
725
- $limit: limit,
726
- $search: text
727
- } }) };
728
- const filter = buildOrFilter(text, selectFields, resolved.primaryKeys[0] ?? resolved.labelField);
866
+ };
867
+ let filter = scope;
868
+ if (text) if (resolved.searchable) controls.$search = text;
869
+ else {
870
+ const search = buildOrFilter(text, selectFields, valueField ?? resolved.primaryKeys[0] ?? resolved.labelField);
871
+ filter = scope ? { $and: [scope, search] } : search;
872
+ }
729
873
  return { items: await this._client.query({
730
- filter,
731
- controls: {
732
- $select: selectFields,
733
- $limit: limit
734
- }
874
+ ...filter && { filter },
875
+ controls
735
876
  }) };
736
877
  }
737
878
  };
738
879
  /**
739
- * Compute the $select fields for a value-help query.
880
+ * Compute the $select fields for a value-help query — always including the
881
+ * `valueField` the picker commits (a unique non-PK field is otherwise never fetched).
740
882
  */
741
- function computeSelectFields(resolved, mode) {
883
+ function computeSelectFields(resolved, mode, valueField) {
742
884
  const fields = [...resolved.primaryKeys, resolved.labelField];
885
+ if (valueField) fields.push(valueField);
743
886
  if (resolved.descrField) fields.push(resolved.descrField);
744
887
  if (mode === "filter") fields.push(...resolved.attrFields);
745
888
  return [...new Set(fields)];
@@ -749,7 +892,7 @@ function computeSelectFields(resolved, mode) {
749
892
  * Uses regex startsWith (case-insensitive) on text fields + exact match on PK.
750
893
  */
751
894
  function buildOrFilter(text, fields, pkField) {
752
- const escaped = text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
895
+ const escaped = escapeRegex(text);
753
896
  const conditions = [];
754
897
  for (const field of fields) if (field !== pkField) conditions.push({ [field]: { $regex: `/^${escaped}/i` } });
755
898
  const asNum = Number(text);
@@ -758,6 +901,54 @@ function buildOrFilter(text, fields, pkField) {
758
901
  return { $or: conditions };
759
902
  }
760
903
  //#endregion
904
+ //#region src/value-help/distinct-client.ts
905
+ /**
906
+ * `true` for a 4xx answer — the server declined this picker (gate, ARBAC, unknown field).
907
+ * @internal Shared with `@atscript/vue-table`.
908
+ */
909
+ function isPickerDeclined(err) {
910
+ const status = err?.status;
911
+ return typeof status === "number" && status >= 400 && status < 500;
912
+ }
913
+ /**
914
+ * Distinct values of one column of the table behind `client`, via
915
+ * `/query?$groupBy=<field>`. All server gates (hidden field, ARBAC `$groupBy`
916
+ * control, row scope, write-only, encrypted) apply as for any grouped read; a
917
+ * 4xx rejects with a `ClientError` — see {@link isPickerDeclined}.
918
+ * `hasMore` tells whether another page follows.
919
+ *
920
+ * @internal Backs the distinct-values picker of `@atscript/vue-table`.
921
+ */
922
+ async function fetchDistinctValues(client, field, opts = {}) {
923
+ const limit = opts.limit ?? 50;
924
+ const text = opts.text?.trim();
925
+ const conditions = [];
926
+ if (opts.filter) conditions.push(opts.filter);
927
+ if (text) if (opts.numeric) {
928
+ const n = Number(text);
929
+ if (!Number.isFinite(n)) return {
930
+ items: [],
931
+ hasMore: false
932
+ };
933
+ conditions.push({ [field]: n });
934
+ } else conditions.push({ [field]: { $regex: `/^${escapeRegex(text)}/i` } });
935
+ const filter = conditions.length > 1 ? { $and: conditions } : conditions[0];
936
+ const rows = await client.aggregate({
937
+ ...filter && { filter },
938
+ controls: {
939
+ $groupBy: [field],
940
+ $select: [field],
941
+ ...opts.sortable && { $sort: { [field]: 1 } },
942
+ $limit: limit + 1,
943
+ $skip: opts.skip ?? 0
944
+ }
945
+ });
946
+ return {
947
+ items: rows.slice(0, limit).map((r) => r[field]).filter((v) => v !== null && v !== void 0),
948
+ hasMore: rows.length > limit
949
+ };
950
+ }
951
+ //#endregion
761
952
  //#region src/client-factory.ts
762
953
  const builtin = (url) => new Client(url);
763
954
  let _default = builtin;
@@ -2267,18 +2458,6 @@ function groupInteger(integer, locale) {
2267
2458
  return out.join(sep);
2268
2459
  }
2269
2460
  //#endregion
2270
- //#region src/shared/str.ts
2271
- /** Converts a dot-path to a human-readable label (e.g. 'firstName' → 'First Name'). */
2272
- function humanizePath(path) {
2273
- return path.slice(path.lastIndexOf(".") + 1).replace(/([a-z])([A-Z])/g, "$1 $2").replace(/^./, (s) => s.toUpperCase());
2274
- }
2275
- /** Safely convert an unknown value to a string without triggering no-base-to-string lint errors. */
2276
- function str(value) {
2277
- if (typeof value === "string") return value;
2278
- if (typeof value === "number" || typeof value === "bigint" || typeof value === "boolean") return `${value}`;
2279
- return JSON.stringify(value) ?? "";
2280
- }
2281
- //#endregion
2282
2461
  //#region src/table/create-table-def.ts
2283
2462
  /**
2284
2463
  * Builds a TableDef from a moost-db MetaResponse.
@@ -2298,40 +2477,44 @@ function createTableDef(meta, preDeserializedType) {
2298
2477
  const fieldMeta = meta.fields[path];
2299
2478
  if (!isReadable(fieldMeta)) continue;
2300
2479
  if (getFieldMeta(prop, "ui.table.exclude") !== void 0) continue;
2301
- const options = extractLiteralOptions(prop);
2480
+ const options = extractFieldLiteralOptions(prop);
2302
2481
  const valueHelpInfo = extractValueHelp(prop);
2303
- const maxLengthMeta = getFieldMeta(prop, EXPECT_MAX_LENGTH);
2304
- const tableType = getFieldMeta(prop, UI_TABLE_TYPE);
2305
- const sharedType = getFieldMeta(prop, UI_TYPE);
2306
- const tableComponent = getFieldMeta(prop, UI_TABLE_COMPONENT);
2307
- columns.push({
2308
- path,
2309
- label: getFieldMeta(prop, "meta.label") ?? humanizePath(path),
2310
- type: tableType ?? sharedType ?? (valueHelpInfo ? "ref" : inferDisplayType(prop, options)),
2311
- component: tableComponent,
2312
- selectWith: getFieldMeta(prop, UI_TABLE_SELECT_WITH),
2313
- sortable: fieldMeta.sortable ?? false,
2314
- filterable: fieldMeta.filterable ?? false,
2315
- ...fieldMeta.filterOps && { filterOps: [...fieldMeta.filterOps] },
2316
- nullable: prop.optional === true,
2317
- width: getFieldMeta(prop, UI_TABLE_WIDTH),
2318
- maxLen: maxLengthMeta?.length,
2319
- order: getFieldMeta(prop, "ui.table.order") ?? Infinity,
2482
+ let distinct;
2483
+ if (!valueHelpInfo && !options && fieldMeta.groupable && fieldMeta.filterable) {
2484
+ const url = type.metadata.get(DB_HTTP_PATH);
2485
+ if (url && getFieldMeta(prop, "ui.valueHelp.distinct") !== void 0) distinct = {
2486
+ url,
2487
+ field: path
2488
+ };
2489
+ }
2490
+ columns.push(buildColumn(path, prop, fieldMeta, {
2320
2491
  options,
2321
2492
  valueHelpInfo,
2322
- ...extractMeasurement(prop)
2323
- });
2493
+ distinct
2494
+ }));
2495
+ }
2496
+ if (meta.decorations) {
2497
+ const decoType = deserializeAnnotatedType(meta.decorations);
2498
+ if (decoType.type.kind === "object") for (const [path, prop] of decoType.type.props) {
2499
+ const fieldMeta = meta.fields[path];
2500
+ if (!fieldMeta?.decoration || flatMap.has(path)) continue;
2501
+ if (getFieldMeta(prop, "ui.table.exclude") !== void 0) continue;
2502
+ flatMap.set(path, prop);
2503
+ columns.push(buildColumn(path, prop, fieldMeta, { options: extractFieldLiteralOptions(prop) }));
2504
+ }
2324
2505
  }
2325
2506
  columns.sort((a, b) => a.order - b.order);
2326
2507
  const actions = groupActions(meta.actions ?? []);
2327
2508
  const crud = meta.crud ?? {};
2509
+ const preferredId = meta.preferredId ?? meta.primaryKeys;
2328
2510
  return {
2329
2511
  type,
2330
2512
  columns,
2331
2513
  flatMap,
2332
2514
  fetchableFields: new Set(Object.keys(meta.fields).filter((p) => isReadable(meta.fields[p]))),
2333
2515
  primaryKeys: meta.primaryKeys,
2334
- preferredId: meta.preferredId ?? meta.primaryKeys,
2516
+ preferredId,
2517
+ identifierFields: identifierFieldsOf(preferredId, meta.actions ?? []),
2335
2518
  versionColumn: meta.versionColumn,
2336
2519
  crud,
2337
2520
  canRemove: "remove" in crud,
@@ -2342,6 +2525,54 @@ function createTableDef(meta, preDeserializedType) {
2342
2525
  relations: meta.relations
2343
2526
  };
2344
2527
  }
2528
+ /**
2529
+ * One column. A server-declared display-only column (`fieldMeta.decoration`)
2530
+ * is never sortable, filterable or groupable and always nullable (a decoration
2531
+ * can be absent); an ordinary one takes its capabilities from `/meta`.
2532
+ */
2533
+ function buildColumn(path, prop, fieldMeta, resolved) {
2534
+ const { options, valueHelpInfo, distinct } = resolved;
2535
+ const maxLengthMeta = getFieldMeta(prop, EXPECT_MAX_LENGTH);
2536
+ const tableType = getFieldMeta(prop, UI_TABLE_TYPE);
2537
+ const sharedType = getFieldMeta(prop, UI_TYPE);
2538
+ const tableComponent = getFieldMeta(prop, UI_TABLE_COMPONENT);
2539
+ const decoration = fieldMeta.decoration === true;
2540
+ const filterOps = decoration ? void 0 : fieldMeta.filterOps;
2541
+ return {
2542
+ path,
2543
+ label: getFieldMeta(prop, "meta.label") ?? humanizePath(path),
2544
+ type: tableType ?? sharedType ?? (valueHelpInfo ? "ref" : inferDisplayType(prop, options)),
2545
+ valueKind: inferValueKind(prop),
2546
+ component: tableComponent,
2547
+ selectWith: getFieldMeta(prop, UI_TABLE_SELECT_WITH),
2548
+ sortable: !decoration && (fieldMeta.sortable ?? false),
2549
+ filterable: !decoration && (fieldMeta.filterable ?? false),
2550
+ ...filterOps && { filterOps: [...filterOps] },
2551
+ nullable: decoration || prop.optional === true,
2552
+ width: getFieldMeta(prop, UI_TABLE_WIDTH),
2553
+ maxLen: maxLengthMeta?.length,
2554
+ order: getFieldMeta(prop, "ui.table.order") ?? Infinity,
2555
+ options,
2556
+ valueHelpInfo,
2557
+ ...distinct && { distinct },
2558
+ ...extractMeasurement(prop)
2559
+ };
2560
+ }
2561
+ /**
2562
+ * `preferredId` ∪ every delegated action's `idMap` paths, in that order —
2563
+ * the same array when no action carries an `idMap`.
2564
+ */
2565
+ function identifierFieldsOf(preferredId, actions) {
2566
+ let out;
2567
+ for (const a of actions) {
2568
+ if (!a.idMap) continue;
2569
+ for (const path of Object.values(a.idMap)) {
2570
+ if (preferredId.includes(path) || out?.includes(path)) continue;
2571
+ (out ??= [...preferredId]).push(path);
2572
+ }
2573
+ }
2574
+ return out ?? preferredId;
2575
+ }
2345
2576
  /** A field the caller may read: listed in `meta.fields` and not write-only. */
2346
2577
  function isReadable(field) {
2347
2578
  return field !== void 0 && field.writeOnly !== true;
@@ -2393,6 +2624,82 @@ function inferDisplayType(prop, literalOpts) {
2393
2624
  }
2394
2625
  return "text";
2395
2626
  }
2627
+ /**
2628
+ * Number metadata that makes the server treat a plain `number` column as an
2629
+ * integer (mirrors the db layer's `valueTypeOf`), beside the `int` / `expect.int` tags.
2630
+ */
2631
+ const INTEGER_NUMBER_META = [
2632
+ "expect.int",
2633
+ "db.default.increment",
2634
+ "db.default.now",
2635
+ "db.agg.count",
2636
+ "db.agg.countDistinct"
2637
+ ];
2638
+ /** The kind of one scalar leaf, or `undefined` for a non-scalar / unknown design type. */
2639
+ function scalarValueKind(prop) {
2640
+ const final = prop.type;
2641
+ const tags = final.tags;
2642
+ switch (final.designType) {
2643
+ case "string": return tags?.has("isoDate") ? "isoDate" : tags?.has("date") ? "date" : "string";
2644
+ case "number":
2645
+ if (tags?.has("timestamp")) return "timestamp";
2646
+ if (tags?.has("int") || INTEGER_NUMBER_META.some((k) => prop.metadata.has(k))) return "integer";
2647
+ return "number";
2648
+ case "decimal": return "decimal";
2649
+ case "boolean": return "boolean";
2650
+ default: return;
2651
+ }
2652
+ }
2653
+ /** Kinds of every non-null leaf of a (possibly nested) union; `null` when one is not a scalar. */
2654
+ function collectUnionKinds(items, out) {
2655
+ for (const item of items) {
2656
+ if (item.type.kind === "union") {
2657
+ collectUnionKinds(item.type.items, out);
2658
+ continue;
2659
+ }
2660
+ if (item.type.kind === "") {
2661
+ const dt = item.type.designType;
2662
+ if (dt === "null" || dt === "undefined") continue;
2663
+ out.add(scalarValueKind(item));
2664
+ continue;
2665
+ }
2666
+ out.add(void 0);
2667
+ }
2668
+ }
2669
+ /**
2670
+ * Scalar storage kind of the column's value — what the server's filter guard
2671
+ * checks. A scalar maps to its kind; a union that agrees on one kind across
2672
+ * its non-null members (`'a' | 'b'`, `1 | 2`, `number.timestamp | null`)
2673
+ * takes it; arrays, objects, JSON and mixed unions have none (`undefined`),
2674
+ * which means no value coercion.
2675
+ */
2676
+ function inferValueKind(prop) {
2677
+ const kind = prop.type.kind;
2678
+ if (kind === "") return scalarValueKind(prop);
2679
+ if (kind !== "union") return void 0;
2680
+ const kinds = /* @__PURE__ */ new Set();
2681
+ collectUnionKinds(prop.type.items, kinds);
2682
+ if (kinds.size !== 1) return void 0;
2683
+ return [...kinds][0];
2684
+ }
2685
+ //#endregion
2686
+ //#region src/table/value-kind.ts
2687
+ /** Storage kinds that hold plain numbers (a `timestamp` is epoch ms, but filters treat it as a date). */
2688
+ const NUMERIC_VALUE_KINDS = new Set([
2689
+ "number",
2690
+ "integer",
2691
+ "decimal"
2692
+ ]);
2693
+ /**
2694
+ * The typed value of one of a column's `options` — the literal itself
2695
+ * (`true`, `3`, `'a'`), falling back to the string `key` for a hand-built
2696
+ * column that has no `value`.
2697
+ *
2698
+ * @internal Shared with `@atscript/vue-table`.
2699
+ */
2700
+ function optionValue(option) {
2701
+ return option.value ?? option.key;
2702
+ }
2396
2703
  //#endregion
2397
2704
  //#region src/table/column-resolver.ts
2398
2705
  /** Get sortable columns. */
@@ -2428,11 +2735,26 @@ function getColumn(def, path) {
2428
2735
  *
2429
2736
  * Table/rows-level navigate actions carry no `$1` placeholder and return
2430
2737
  * `action.value` verbatim.
2738
+ *
2739
+ * A delegated action (`action.idMap`, since 0.1.147) reads `id` as one of THIS
2740
+ * table's rows (or identifiers) and encodes the owner's identification it maps
2741
+ * to, in `Object.keys(idMap)` order — the same as `Client`. A row the map
2742
+ * cannot address (a missing path) has no link.
2431
2743
  */
2432
2744
  function navigateHrefFor(action, id, preferredId) {
2433
2745
  if (action.processor !== "navigate") return void 0;
2434
2746
  if (action.level !== "row") return action.value;
2435
- if (id === void 0 || preferredId.length === 0) return void 0;
2747
+ if (id === void 0) return void 0;
2748
+ if (action.idMap) {
2749
+ let mapped;
2750
+ try {
2751
+ mapped = actionIdentifier(action, id, []);
2752
+ } catch {
2753
+ return;
2754
+ }
2755
+ return action.value.replace(/\$1/g, encodeNavigateId(mapped, Object.keys(action.idMap)));
2756
+ }
2757
+ if (preferredId.length === 0) return void 0;
2436
2758
  return action.value.replace(/\$1/g, encodeNavigateId(id, preferredId));
2437
2759
  }
2438
2760
  //#endregion
@@ -2491,4 +2813,4 @@ function resolvePath(model, table, view) {
2491
2813
  return path.length > 0 ? path : void 0;
2492
2814
  }
2493
2815
  //#endregion
2494
- export { DB_AMOUNT_CURRENCY, DB_AMOUNT_CURRENCY_REF, DB_COLUMN_PRECISION, DB_HTTP_PATH, DB_REL_FK, DB_UNIT, DB_UNIT_REF, DEFAULT_COL_SPAN, DEFAULT_ROW_SPAN, EXPECT_MAX_LENGTH, META_DEFAULT, META_DESCRIPTION, META_ID, META_LABEL, META_READONLY, META_REQUIRED, META_SENSITIVE, StaticFieldResolver, UI_DICT_ATTR, UI_DICT_DESCR, UI_DICT_FILTERABLE, UI_DICT_LABEL, UI_DICT_SEARCHABLE, UI_DICT_SORTABLE, UI_FORM_ACTION, UI_FORM_ATTR, UI_FORM_AUTOCOMPLETE, UI_FORM_CLASSES, UI_FORM_COMPONENT, UI_FORM_DISABLED, UI_FORM_FN_ATTR, UI_FORM_FN_CLASSES, UI_FORM_FN_DESCRIPTION, UI_FORM_FN_DISABLED, UI_FORM_FN_HIDDEN, UI_FORM_FN_HINT, UI_FORM_FN_LABEL, UI_FORM_FN_OPTIONS, UI_FORM_FN_PLACEHOLDER, UI_FORM_FN_PREFIX, UI_FORM_FN_READONLY, UI_FORM_FN_STYLES, UI_FORM_FN_SUBMIT_DISABLED, UI_FORM_FN_SUBMIT_TEXT, UI_FORM_FN_TITLE, UI_FORM_FN_VALUE, UI_FORM_GRID_COL_SPAN, UI_FORM_GRID_ROW_SPAN, UI_FORM_HIDDEN, UI_FORM_HINT, UI_FORM_LABEL_SINGULAR, UI_FORM_OPTIONS, UI_FORM_ORDER, UI_FORM_PLACEHOLDER, UI_FORM_PREFIX, UI_FORM_PREFIX_ICON, UI_FORM_PREFIX_REF, UI_FORM_STYLES, UI_FORM_SUBMIT_TEXT, UI_FORM_SUFFIX, UI_FORM_SUFFIX_ICON, UI_FORM_SUFFIX_REF, UI_FORM_TYPE, UI_FORM_VALIDATE, UI_NAV_GROUP, UI_NAV_HIDDEN, UI_NAV_ORDER, UI_TABLE_ATTR, UI_TABLE_CLASSES, UI_TABLE_COMPONENT, UI_TABLE_EXCLUDE, UI_TABLE_FN_ATTR, UI_TABLE_FN_CLASSES, UI_TABLE_FN_PREFIX, UI_TABLE_FN_STYLES, UI_TABLE_ORDER, UI_TABLE_SELECT_WITH, UI_TABLE_STYLES, UI_TABLE_TYPE, UI_TABLE_WIDTH, UI_TYPE, ValueHelpClient, WF_ACTION_WITH_DATA, applyFormChanges, asArray, buildDescendantErrorCounts, buildFormDiff, buildFormRebase, buildGridClasses, buildModelRoutes, buildUnionVariants, collectDirtyPaths, createFieldValidator, createFormData, createFormDef, createFormValueResolver, createTableDef, deepClone, deepEqual, defaultResolver, deleteByPath, detectUnionVariant, enforceScale, extractLiteralOptions, extractMeasurement, extractValueHelp, formatDecimalForDisplay, getByPath, getColumn, getCurrencyDecimals, getCurrencyDisplayParts, getDecimalSeparator, getDeclaredFormActions, getDefaultClientFactory, getDefaultValidatorPlugins, getFieldMeta, getFilterableColumns, getFormValidator, getMetaEntry, getResolver, getSortableColumns, getThousandsSeparator, groupInteger, hasComputedAnnotations, hasFieldMeta, isArrayField, isFieldHidden, isObjectField, isPathDirty, isPureLiteralUnion, isTupleField, isUnionField, iteratePathAncestors, joinDecimalString, joinPath, mergeErrorMaps, navigateHrefFor, omitPaths, optKey, optLabel, parseColSpan, parseDecimalInput, parseRowSpan, parseStaticAttrs, parseStaticOptions, resetDefaultClientFactory, resetMetaCache, resetValueHelpCache, resolveAttrs, resolveFieldProp, resolveFormProp, resolveGridSpec, resolveOptions, resolveSingularLabel, resolveStatic, resolveValueHelp, setByPath, setDefaultClientFactory, setDefaultValidatorPlugins, setResolver, splitDecimalString, str, unionVariantChanged, valueHelpDictPaths };
2816
+ export { DB_AMOUNT_CURRENCY, DB_AMOUNT_CURRENCY_REF, DB_COLUMN_PRECISION, DB_HTTP_PATH, DB_REL_FK, DB_UNIT, DB_UNIT_REF, DEFAULT_COL_SPAN, DEFAULT_ROW_SPAN, EXPECT_MAX_LENGTH, META_DEFAULT, META_DESCRIPTION, META_ID, META_LABEL, META_READONLY, META_REQUIRED, META_SENSITIVE, NUMERIC_VALUE_KINDS, StaticFieldResolver, UI_DICT_ATTR, UI_DICT_DESCR, UI_DICT_FILTERABLE, UI_DICT_LABEL, UI_DICT_SEARCHABLE, UI_DICT_SORTABLE, UI_FORM_ACTION, UI_FORM_ATTR, UI_FORM_AUTOCOMPLETE, UI_FORM_CLASSES, UI_FORM_COMPONENT, UI_FORM_DISABLED, UI_FORM_FN_ATTR, UI_FORM_FN_CLASSES, UI_FORM_FN_DESCRIPTION, UI_FORM_FN_DISABLED, UI_FORM_FN_HIDDEN, UI_FORM_FN_HINT, UI_FORM_FN_LABEL, UI_FORM_FN_OPTIONS, UI_FORM_FN_PLACEHOLDER, UI_FORM_FN_PREFIX, UI_FORM_FN_READONLY, UI_FORM_FN_STYLES, UI_FORM_FN_SUBMIT_DISABLED, UI_FORM_FN_SUBMIT_TEXT, UI_FORM_FN_TITLE, UI_FORM_FN_VALUE, UI_FORM_GRID_COL_SPAN, UI_FORM_GRID_ROW_SPAN, UI_FORM_HIDDEN, UI_FORM_HINT, UI_FORM_LABEL_SINGULAR, UI_FORM_OPTIONS, UI_FORM_ORDER, UI_FORM_PLACEHOLDER, UI_FORM_PREFIX, UI_FORM_PREFIX_ICON, UI_FORM_PREFIX_REF, UI_FORM_STYLES, UI_FORM_SUBMIT_TEXT, UI_FORM_SUFFIX, UI_FORM_SUFFIX_ICON, UI_FORM_SUFFIX_REF, UI_FORM_TYPE, UI_FORM_VALIDATE, UI_NAV_GROUP, UI_NAV_HIDDEN, UI_NAV_ORDER, UI_TABLE_ATTR, UI_TABLE_CLASSES, UI_TABLE_COMPONENT, UI_TABLE_EXCLUDE, UI_TABLE_FN_ATTR, UI_TABLE_FN_CLASSES, UI_TABLE_FN_PREFIX, UI_TABLE_FN_STYLES, UI_TABLE_ORDER, UI_TABLE_SELECT_WITH, UI_TABLE_STYLES, UI_TABLE_TYPE, UI_TABLE_WIDTH, UI_TYPE, ValueHelpClient, WF_ACTION_WITH_DATA, applyFormChanges, asArray, buildDescendantErrorCounts, buildFormDiff, buildFormRebase, buildGridClasses, buildModelRoutes, buildUnionVariants, collectDirtyPaths, createFieldValidator, createFormData, createFormDef, createFormValueResolver, createTableDef, deepClone, deepEqual, defaultResolver, deleteByPath, detectUnionVariant, enforceScale, escapeRegex, extractFieldLiteralOptions, extractLiteralOptions, extractMeasurement, extractValueHelp, fetchDistinctValues, formatDecimalForDisplay, getByPath, getColumn, getCurrencyDecimals, getCurrencyDisplayParts, getDecimalSeparator, getDeclaredFormActions, getDefaultClientFactory, getDefaultValidatorPlugins, getFieldMeta, getFilterableColumns, getFormValidator, getMetaEntry, getResolver, getSortableColumns, getThousandsSeparator, groupInteger, hasComputedAnnotations, hasFieldMeta, isArrayField, isFieldHidden, isObjectField, isPathDirty, isPickerDeclined, isPureLiteralUnion, isTupleField, isUnionField, iteratePathAncestors, joinDecimalString, joinPath, mergeErrorMaps, navigateHrefFor, omitPaths, optKey, optLabel, optionLabel, optionValue, parseColSpan, parseDecimalInput, parseRowSpan, parseStaticAttrs, parseStaticOptions, resetDefaultClientFactory, resetMetaCache, resetValueHelpCache, resolveAttrs, resolveFieldProp, resolveFormProp, resolveGridSpec, resolveOptions, resolveSingularLabel, resolveStatic, resolveValueHelp, setByPath, setDefaultClientFactory, setDefaultValidatorPlugins, setResolver, splitDecimalString, str, unionVariantChanged, valueHelpDictPaths };