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