@atscript/ui 0.1.162 → 0.1.164

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/dist/client-factory.cjs +27 -0
  2. package/dist/client-factory.d.cts +53 -0
  3. package/dist/client-factory.d.mts +53 -0
  4. package/dist/client-factory.mjs +25 -0
  5. package/dist/form/apply.cjs +38 -0
  6. package/dist/form/apply.d.cts +36 -0
  7. package/dist/form/apply.d.mts +36 -0
  8. package/dist/form/apply.mjs +38 -0
  9. package/dist/form/clone.cjs +30 -0
  10. package/dist/form/clone.d.cts +23 -0
  11. package/dist/form/clone.d.mts +23 -0
  12. package/dist/form/clone.mjs +30 -0
  13. package/dist/form/create-form-def.cjs +440 -0
  14. package/dist/form/create-form-def.d.cts +67 -0
  15. package/dist/form/create-form-def.d.mts +67 -0
  16. package/dist/form/create-form-def.mjs +438 -0
  17. package/dist/form/decimal-format.cjs +324 -0
  18. package/dist/form/decimal-format.d.cts +86 -0
  19. package/dist/form/decimal-format.d.mts +86 -0
  20. package/dist/form/decimal-format.mjs +315 -0
  21. package/dist/form/diff.cjs +458 -0
  22. package/dist/form/diff.d.cts +80 -0
  23. package/dist/form/diff.d.mts +80 -0
  24. package/dist/form/diff.mjs +457 -0
  25. package/dist/form/dirty.cjs +65 -0
  26. package/dist/form/dirty.d.cts +47 -0
  27. package/dist/form/dirty.d.mts +47 -0
  28. package/dist/form/dirty.mjs +64 -0
  29. package/dist/form/error-utils.cjs +97 -0
  30. package/dist/form/error-utils.d.cts +58 -0
  31. package/dist/form/error-utils.d.mts +58 -0
  32. package/dist/form/error-utils.mjs +92 -0
  33. package/dist/form/form-actions.cjs +30 -0
  34. package/dist/form/form-actions.d.cts +17 -0
  35. package/dist/form/form-actions.d.mts +17 -0
  36. package/dist/form/form-actions.mjs +30 -0
  37. package/dist/form/grid.cjs +69 -0
  38. package/dist/form/grid.d.cts +49 -0
  39. package/dist/form/grid.d.mts +49 -0
  40. package/dist/form/grid.mjs +64 -0
  41. package/dist/form/labels.cjs +10 -0
  42. package/dist/form/labels.d.cts +7 -0
  43. package/dist/form/labels.d.mts +7 -0
  44. package/dist/form/labels.mjs +10 -0
  45. package/dist/form/measurement.cjs +20 -0
  46. package/dist/form/measurement.d.cts +29 -0
  47. package/dist/form/measurement.d.mts +29 -0
  48. package/dist/form/measurement.mjs +20 -0
  49. package/dist/form/path-utils.cjs +182 -0
  50. package/dist/form/path-utils.d.cts +47 -0
  51. package/dist/form/path-utils.d.mts +47 -0
  52. package/dist/form/path-utils.mjs +175 -0
  53. package/dist/form/rebase.cjs +89 -0
  54. package/dist/form/rebase.d.cts +61 -0
  55. package/dist/form/rebase.d.mts +61 -0
  56. package/dist/form/rebase.mjs +89 -0
  57. package/dist/form/skipped-nav.cjs +100 -0
  58. package/dist/form/skipped-nav.d.cts +13 -0
  59. package/dist/form/skipped-nav.d.mts +13 -0
  60. package/dist/form/skipped-nav.mjs +98 -0
  61. package/dist/form/types.cjs +40 -0
  62. package/dist/form/types.d.cts +133 -0
  63. package/dist/form/types.d.mts +133 -0
  64. package/dist/form/types.mjs +36 -0
  65. package/dist/form/union-detect.cjs +46 -0
  66. package/dist/form/union-detect.d.cts +22 -0
  67. package/dist/form/union-detect.d.mts +22 -0
  68. package/dist/form/union-detect.mjs +46 -0
  69. package/dist/form/validate.cjs +150 -0
  70. package/dist/form/validate.d.cts +50 -0
  71. package/dist/form/validate.d.mts +50 -0
  72. package/dist/form/validate.mjs +147 -0
  73. package/dist/index.cjs +217 -3360
  74. package/dist/index.d.cts +38 -1693
  75. package/dist/index.d.mts +38 -1693
  76. package/dist/index.mjs +35 -3179
  77. package/dist/nav/model-routes.cjs +59 -0
  78. package/dist/nav/model-routes.d.cts +33 -0
  79. package/dist/nav/model-routes.d.mts +33 -0
  80. package/dist/nav/model-routes.mjs +59 -0
  81. package/dist/plugin/annotations.cjs +577 -0
  82. package/dist/plugin/annotations.mjs +577 -0
  83. package/dist/plugin/primitives.cjs +30 -0
  84. package/dist/plugin/primitives.mjs +30 -0
  85. package/dist/plugin/value-help-validation.cjs +419 -0
  86. package/dist/plugin/value-help-validation.mjs +413 -0
  87. package/dist/plugin.cjs +4 -1001
  88. package/dist/plugin.mjs +2 -999
  89. package/dist/shared/annotation-keys.cjs +189 -0
  90. package/dist/shared/annotation-keys.d.cts +82 -0
  91. package/dist/shared/annotation-keys.d.mts +82 -0
  92. package/dist/shared/annotation-keys.mjs +97 -0
  93. package/dist/shared/field-resolver.cjs +123 -0
  94. package/dist/shared/field-resolver.d.cts +77 -0
  95. package/dist/shared/field-resolver.d.mts +77 -0
  96. package/dist/shared/field-resolver.mjs +110 -0
  97. package/dist/shared/meta-cache.cjs +244 -0
  98. package/dist/shared/meta-cache.d.cts +110 -0
  99. package/dist/shared/meta-cache.d.mts +110 -0
  100. package/dist/shared/meta-cache.mjs +237 -0
  101. package/dist/shared/str.cjs +19 -0
  102. package/dist/shared/str.d.cts +7 -0
  103. package/dist/shared/str.d.mts +7 -0
  104. package/dist/shared/str.mjs +17 -0
  105. package/dist/table/column-resolver.cjs +17 -0
  106. package/dist/table/column-resolver.d.cts +11 -0
  107. package/dist/table/column-resolver.d.mts +11 -0
  108. package/dist/table/column-resolver.mjs +15 -0
  109. package/dist/table/create-table-def.cjs +233 -0
  110. package/dist/table/create-table-def.d.cts +15 -0
  111. package/dist/table/create-table-def.d.mts +15 -0
  112. package/dist/table/create-table-def.mjs +233 -0
  113. package/dist/table/navigate-href.cjs +45 -0
  114. package/dist/table/navigate-href.d.cts +31 -0
  115. package/dist/table/navigate-href.d.mts +31 -0
  116. package/dist/table/navigate-href.mjs +45 -0
  117. package/dist/table/types.d.cts +287 -0
  118. package/dist/table/types.d.mts +287 -0
  119. package/dist/table/value-kind.cjs +20 -0
  120. package/dist/table/value-kind.d.cts +15 -0
  121. package/dist/table/value-kind.d.mts +15 -0
  122. package/dist/table/value-kind.mjs +19 -0
  123. package/dist/value-help/dict-paths.cjs +17 -0
  124. package/dist/value-help/dict-paths.d.cts +11 -0
  125. package/dist/value-help/dict-paths.d.mts +11 -0
  126. package/dist/value-help/dict-paths.mjs +17 -0
  127. package/dist/value-help/distinct-client.cjs +51 -0
  128. package/dist/value-help/distinct-client.d.cts +40 -0
  129. package/dist/value-help/distinct-client.d.mts +40 -0
  130. package/dist/value-help/distinct-client.mjs +50 -0
  131. package/dist/value-help/extract-literals.cjs +76 -0
  132. package/dist/value-help/extract-literals.d.cts +32 -0
  133. package/dist/value-help/extract-literals.d.mts +32 -0
  134. package/dist/value-help/extract-literals.mjs +74 -0
  135. package/dist/value-help/extract-ref.cjs +100 -0
  136. package/dist/value-help/extract-ref.d.cts +37 -0
  137. package/dist/value-help/extract-ref.d.mts +37 -0
  138. package/dist/value-help/extract-ref.mjs +100 -0
  139. package/dist/value-help/filter-tree.cjs +45 -0
  140. package/dist/value-help/filter-tree.mjs +45 -0
  141. package/dist/value-help/index.d.mts +8 -0
  142. package/dist/value-help/resolve-options.cjs +64 -0
  143. package/dist/value-help/resolve-options.d.cts +35 -0
  144. package/dist/value-help/resolve-options.d.mts +35 -0
  145. package/dist/value-help/resolve-options.mjs +60 -0
  146. package/dist/value-help/resolve.cjs +62 -0
  147. package/dist/value-help/resolve.d.cts +31 -0
  148. package/dist/value-help/resolve.d.mts +31 -0
  149. package/dist/value-help/resolve.mjs +61 -0
  150. package/dist/value-help/types.d.cts +36 -0
  151. package/dist/value-help/types.d.mts +36 -0
  152. package/dist/value-help/value-help-client.cjs +136 -0
  153. package/dist/value-help/value-help-client.d.cts +67 -0
  154. package/dist/value-help/value-help-client.d.mts +67 -0
  155. package/dist/value-help/value-help-client.mjs +134 -0
  156. package/package.json +10 -10
@@ -0,0 +1,76 @@
1
+ require("../shared/annotation-keys.cjs");
2
+ //#region src/value-help/extract-literals.ts
3
+ /**
4
+ * Extracts options from a union of literal types (e.g. 'a' | 'b' | 'c').
5
+ * Returns undefined if the type is not a pure union of literals.
6
+ *
7
+ * Handles nested unions created by flattenAnnotatedType, which recurses
8
+ * into union items and produces synthetic unions containing both individual
9
+ * literals and the original union type as nested items.
10
+ */
11
+ function extractLiteralOptions(prop, outer) {
12
+ if (prop.type.kind !== "union") return void 0;
13
+ const result = collectLiterals(prop.type.items, /* @__PURE__ */ new Set());
14
+ if (!result || result.length === 0) return void 0;
15
+ const labels = [prop, outer].flatMap((node) => node?.metadata.get("ui.literalLabel") ?? []);
16
+ if (labels.length) {
17
+ const byValue = new Map(labels.map((l) => [l.value, l.label]));
18
+ for (const option of result) option.label = byValue.get(option.key) ?? option.label;
19
+ }
20
+ return result;
21
+ }
22
+ /**
23
+ * The literal options of a field: a literal union's, or those of an array of one
24
+ * (`tags: Tag[]`), where the array prop's own `@ui.literalLabel` labels win over the
25
+ * element type's. `undefined` when the field is neither. Since 0.1.148.
26
+ */
27
+ function extractFieldLiteralOptions(prop) {
28
+ if (prop.type.kind === "array") return extractLiteralOptions(prop.type.of, prop);
29
+ return extractLiteralOptions(prop);
30
+ }
31
+ /** Returns true when the annotated type is a union composed entirely of literal values. */
32
+ function isPureLiteralUnion(prop) {
33
+ if (prop.type.kind !== "union") return false;
34
+ return checkAllLiterals(prop.type.items);
35
+ }
36
+ /** Walks union items returning true only if every leaf is a literal value. */
37
+ function checkAllLiterals(items) {
38
+ for (const item of items) {
39
+ if (item.type.kind === "" && item.type.value !== void 0) continue;
40
+ if (item.type.kind === "union") {
41
+ if (!checkAllLiterals(item.type.items)) return false;
42
+ continue;
43
+ }
44
+ return false;
45
+ }
46
+ return items.length > 0;
47
+ }
48
+ /**
49
+ * Recursively collects literal values from union items.
50
+ * Returns null if any non-literal, non-union item is found (invalid union).
51
+ * Returns empty array when all items are valid but already seen (deduped).
52
+ */
53
+ function collectLiterals(items, seen) {
54
+ const result = [];
55
+ for (const item of items) if (item.type.kind === "" && item.type.value !== void 0) {
56
+ const raw = item.type.value;
57
+ const val = String(raw);
58
+ if (!seen.has(val)) {
59
+ seen.add(val);
60
+ result.push({
61
+ key: val,
62
+ label: val,
63
+ value: raw
64
+ });
65
+ }
66
+ } else if (item.type.kind === "union") {
67
+ const nested = collectLiterals(item.type.items, seen);
68
+ if (nested === null) return null;
69
+ result.push(...nested);
70
+ } else return null;
71
+ return result;
72
+ }
73
+ //#endregion
74
+ exports.extractFieldLiteralOptions = extractFieldLiteralOptions;
75
+ exports.extractLiteralOptions = extractLiteralOptions;
76
+ exports.isPureLiteralUnion = isPureLiteralUnion;
@@ -0,0 +1,32 @@
1
+ import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
2
+
3
+ //#region src/value-help/extract-literals.d.ts
4
+ /**
5
+ * One literal of a union: `key` / `label` are the string forms the UI keys
6
+ * on; `value` is the typed literal (`true`, `3`, `'a'`) — what a filter or a
7
+ * form must send to the server. `value` since 0.1.148.
8
+ */
9
+ interface LiteralOption {
10
+ key: string;
11
+ label: string;
12
+ value: string | number | boolean;
13
+ }
14
+ /**
15
+ * Extracts options from a union of literal types (e.g. 'a' | 'b' | 'c').
16
+ * Returns undefined if the type is not a pure union of literals.
17
+ *
18
+ * Handles nested unions created by flattenAnnotatedType, which recurses
19
+ * into union items and produces synthetic unions containing both individual
20
+ * literals and the original union type as nested items.
21
+ */
22
+ declare function extractLiteralOptions(prop: TAtscriptAnnotatedType, outer?: TAtscriptAnnotatedType): LiteralOption[] | undefined;
23
+ /**
24
+ * The literal options of a field: a literal union's, or those of an array of one
25
+ * (`tags: Tag[]`), where the array prop's own `@ui.literalLabel` labels win over the
26
+ * element type's. `undefined` when the field is neither. Since 0.1.148.
27
+ */
28
+ declare function extractFieldLiteralOptions(prop: TAtscriptAnnotatedType): LiteralOption[] | undefined;
29
+ /** Returns true when the annotated type is a union composed entirely of literal values. */
30
+ declare function isPureLiteralUnion(prop: TAtscriptAnnotatedType): boolean;
31
+ //#endregion
32
+ export { extractFieldLiteralOptions, extractLiteralOptions, isPureLiteralUnion };
@@ -0,0 +1,32 @@
1
+ import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
2
+
3
+ //#region src/value-help/extract-literals.d.ts
4
+ /**
5
+ * One literal of a union: `key` / `label` are the string forms the UI keys
6
+ * on; `value` is the typed literal (`true`, `3`, `'a'`) — what a filter or a
7
+ * form must send to the server. `value` since 0.1.148.
8
+ */
9
+ interface LiteralOption {
10
+ key: string;
11
+ label: string;
12
+ value: string | number | boolean;
13
+ }
14
+ /**
15
+ * Extracts options from a union of literal types (e.g. 'a' | 'b' | 'c').
16
+ * Returns undefined if the type is not a pure union of literals.
17
+ *
18
+ * Handles nested unions created by flattenAnnotatedType, which recurses
19
+ * into union items and produces synthetic unions containing both individual
20
+ * literals and the original union type as nested items.
21
+ */
22
+ declare function extractLiteralOptions(prop: TAtscriptAnnotatedType, outer?: TAtscriptAnnotatedType): LiteralOption[] | undefined;
23
+ /**
24
+ * The literal options of a field: a literal union's, or those of an array of one
25
+ * (`tags: Tag[]`), where the array prop's own `@ui.literalLabel` labels win over the
26
+ * element type's. `undefined` when the field is neither. Since 0.1.148.
27
+ */
28
+ declare function extractFieldLiteralOptions(prop: TAtscriptAnnotatedType): LiteralOption[] | undefined;
29
+ /** Returns true when the annotated type is a union composed entirely of literal values. */
30
+ declare function isPureLiteralUnion(prop: TAtscriptAnnotatedType): boolean;
31
+ //#endregion
32
+ export { extractFieldLiteralOptions, extractLiteralOptions, isPureLiteralUnion };
@@ -0,0 +1,74 @@
1
+ import "../shared/annotation-keys.mjs";
2
+ //#region src/value-help/extract-literals.ts
3
+ /**
4
+ * Extracts options from a union of literal types (e.g. 'a' | 'b' | 'c').
5
+ * Returns undefined if the type is not a pure union of literals.
6
+ *
7
+ * Handles nested unions created by flattenAnnotatedType, which recurses
8
+ * into union items and produces synthetic unions containing both individual
9
+ * literals and the original union type as nested items.
10
+ */
11
+ function extractLiteralOptions(prop, outer) {
12
+ if (prop.type.kind !== "union") return void 0;
13
+ const result = collectLiterals(prop.type.items, /* @__PURE__ */ new Set());
14
+ if (!result || result.length === 0) return void 0;
15
+ const labels = [prop, outer].flatMap((node) => node?.metadata.get("ui.literalLabel") ?? []);
16
+ if (labels.length) {
17
+ const byValue = new Map(labels.map((l) => [l.value, l.label]));
18
+ for (const option of result) option.label = byValue.get(option.key) ?? option.label;
19
+ }
20
+ return result;
21
+ }
22
+ /**
23
+ * The literal options of a field: a literal union's, or those of an array of one
24
+ * (`tags: Tag[]`), where the array prop's own `@ui.literalLabel` labels win over the
25
+ * element type's. `undefined` when the field is neither. Since 0.1.148.
26
+ */
27
+ function extractFieldLiteralOptions(prop) {
28
+ if (prop.type.kind === "array") return extractLiteralOptions(prop.type.of, prop);
29
+ return extractLiteralOptions(prop);
30
+ }
31
+ /** Returns true when the annotated type is a union composed entirely of literal values. */
32
+ function isPureLiteralUnion(prop) {
33
+ if (prop.type.kind !== "union") return false;
34
+ return checkAllLiterals(prop.type.items);
35
+ }
36
+ /** Walks union items returning true only if every leaf is a literal value. */
37
+ function checkAllLiterals(items) {
38
+ for (const item of items) {
39
+ if (item.type.kind === "" && item.type.value !== void 0) continue;
40
+ if (item.type.kind === "union") {
41
+ if (!checkAllLiterals(item.type.items)) return false;
42
+ continue;
43
+ }
44
+ return false;
45
+ }
46
+ return items.length > 0;
47
+ }
48
+ /**
49
+ * Recursively collects literal values from union items.
50
+ * Returns null if any non-literal, non-union item is found (invalid union).
51
+ * Returns empty array when all items are valid but already seen (deduped).
52
+ */
53
+ function collectLiterals(items, seen) {
54
+ const result = [];
55
+ for (const item of items) if (item.type.kind === "" && item.type.value !== void 0) {
56
+ const raw = item.type.value;
57
+ const val = String(raw);
58
+ if (!seen.has(val)) {
59
+ seen.add(val);
60
+ result.push({
61
+ key: val,
62
+ label: val,
63
+ value: raw
64
+ });
65
+ }
66
+ } else if (item.type.kind === "union") {
67
+ const nested = collectLiterals(item.type.items, seen);
68
+ if (nested === null) return null;
69
+ result.push(...nested);
70
+ } else return null;
71
+ return result;
72
+ }
73
+ //#endregion
74
+ export { extractFieldLiteralOptions, extractLiteralOptions, isPureLiteralUnion };
@@ -0,0 +1,100 @@
1
+ const require_annotation_keys = require("../shared/annotation-keys.cjs");
2
+ const require_filter_tree = require("./filter-tree.cjs");
3
+ //#region src/value-help/extract-ref.ts
4
+ /**
5
+ * Hard cap on how many `.ref` hops the chain walk follows. Real chains are one
6
+ * or two hops (view field → table field → dictionary); the cap is a backstop,
7
+ * not a modelling limit — and it is also what terminates a cyclic chain.
8
+ */
9
+ const MAX_REF_CHAIN_DEPTH = 8;
10
+ /**
11
+ * `@db.http.path` of a binding target. Two producers, two shapes — `/meta`
12
+ * deserialization does not normalize annotation values, so both are read here:
13
+ *
14
+ * - compiled `.as` (the atscript runtime): the annotated type itself (a class
15
+ * with a `metadata` Map) or a getter `() => Type` for a cross-file ref;
16
+ * - `/meta` (the serialized type): a shallow target `{ id, metadata }` whose
17
+ * `metadata` is a plain record.
18
+ *
19
+ * Also accepts `{ type: () => Type }`.
20
+ */
21
+ function bindingTargetPath(target) {
22
+ if (target === null || typeof target !== "object" && typeof target !== "function") return;
23
+ const t = target;
24
+ if (typeof target === "function" && t.metadata === void 0) return bindingTargetPath(target());
25
+ if (t.metadata instanceof Map) return t.metadata.get(require_annotation_keys.DB_HTTP_PATH);
26
+ if (t.metadata && typeof t.metadata === "object") return t.metadata[require_annotation_keys.DB_HTTP_PATH];
27
+ return t.type === void 0 ? void 0 : bindingTargetPath(t.type);
28
+ }
29
+ /**
30
+ * The `@ui.valueHelp` binding of a node, when its target is served by a
31
+ * controller (`@db.http.path`). Without a path the binding is ignored and the
32
+ * caller falls back to the FK walk.
33
+ */
34
+ function bindingInfo(node) {
35
+ const binding = node.metadata.get(require_annotation_keys.UI_VALUE_HELP);
36
+ if (!binding?.field) return void 0;
37
+ const url = bindingTargetPath(binding.target);
38
+ if (!url) return void 0;
39
+ const info = {
40
+ url,
41
+ targetField: binding.field
42
+ };
43
+ if (binding.filter) {
44
+ const { filter, pinned } = require_filter_tree.valueHelpFilter(binding.filter);
45
+ info.filter = filter;
46
+ if (pinned.length > 0) info.pinned = pinned;
47
+ }
48
+ return info;
49
+ }
50
+ /**
51
+ * Synchronous probe. Returns `{ url, targetField }` for the first link of the
52
+ * reference chain starting at `prop` that carries a `@ui.valueHelp` binding
53
+ * (since 0.1.148 — an explicit binding beats `@db.rel.FK`, and also supplies
54
+ * the static `filter` / `pinned` fields), or that satisfies all three conditions:
55
+ *
56
+ * 1. the link carries `@db.rel.FK`,
57
+ * 2. the link has a `.ref`,
58
+ * 3. the ref's target metadata carries `@db.http.path`.
59
+ *
60
+ * Since 0.1.134 the probe follows **reference chains**: when a link does not
61
+ * qualify, it hops onto the referenced field (`ref.type()` → that object's
62
+ * `props[ref.field]`) and re-tests. A view field declared as
63
+ * `errorCode: Issue.errorCode`, where `Issue.errorCode: ErrorCode.code` is the
64
+ * link carrying `@db.rel.FK`, therefore keeps its value help instead of losing
65
+ * the dictionary.
66
+ *
67
+ * This mirrors what the server already does on the `/meta` path: since
68
+ * `@atscript/db` 0.1.128 the serialized meta collapses such chains onto the
69
+ * terminal field (`ref` → terminal, `db.rel.FK: true`), so a form def built
70
+ * from `/meta` and one built from the compiled `.as` type land on the same
71
+ * dictionary.
72
+ *
73
+ * The walk is bounded ({@link MAX_REF_CHAIN_DEPTH}), which is also what makes a
74
+ * cyclic chain terminate (it runs out of hops and gives up instead of looping).
75
+ * It stops as soon as a link has no `.ref`, or the referenced
76
+ * field cannot be found — e.g. behind a shallow `{ id, metadata }` ref target
77
+ * from `/meta`, which carries no props (and needs none: the server already
78
+ * resolved the chain).
79
+ */
80
+ function extractValueHelp(prop) {
81
+ let node = prop;
82
+ for (let depth = 0; node && depth < MAX_REF_CHAIN_DEPTH; depth++) {
83
+ const bound = bindingInfo(node);
84
+ if (bound) return bound;
85
+ const ref = node.ref;
86
+ if (!ref) return void 0;
87
+ const target = ref.type();
88
+ if (!target) return void 0;
89
+ if (node.metadata.has("db.rel.FK")) {
90
+ const url = target.metadata.get(require_annotation_keys.DB_HTTP_PATH);
91
+ if (url) return {
92
+ url,
93
+ targetField: ref.field
94
+ };
95
+ }
96
+ node = (target.type.kind === "object" ? target.type : void 0)?.props.get(ref.field);
97
+ }
98
+ }
99
+ //#endregion
100
+ exports.extractValueHelp = extractValueHelp;
@@ -0,0 +1,37 @@
1
+ import { ValueHelpInfo } from "./types.cjs";
2
+ import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
3
+
4
+ //#region src/value-help/extract-ref.d.ts
5
+ /**
6
+ * Synchronous probe. Returns `{ url, targetField }` for the first link of the
7
+ * reference chain starting at `prop` that carries a `@ui.valueHelp` binding
8
+ * (since 0.1.148 — an explicit binding beats `@db.rel.FK`, and also supplies
9
+ * the static `filter` / `pinned` fields), or that satisfies all three conditions:
10
+ *
11
+ * 1. the link carries `@db.rel.FK`,
12
+ * 2. the link has a `.ref`,
13
+ * 3. the ref's target metadata carries `@db.http.path`.
14
+ *
15
+ * Since 0.1.134 the probe follows **reference chains**: when a link does not
16
+ * qualify, it hops onto the referenced field (`ref.type()` → that object's
17
+ * `props[ref.field]`) and re-tests. A view field declared as
18
+ * `errorCode: Issue.errorCode`, where `Issue.errorCode: ErrorCode.code` is the
19
+ * link carrying `@db.rel.FK`, therefore keeps its value help instead of losing
20
+ * the dictionary.
21
+ *
22
+ * This mirrors what the server already does on the `/meta` path: since
23
+ * `@atscript/db` 0.1.128 the serialized meta collapses such chains onto the
24
+ * terminal field (`ref` → terminal, `db.rel.FK: true`), so a form def built
25
+ * from `/meta` and one built from the compiled `.as` type land on the same
26
+ * dictionary.
27
+ *
28
+ * The walk is bounded ({@link MAX_REF_CHAIN_DEPTH}), which is also what makes a
29
+ * cyclic chain terminate (it runs out of hops and gives up instead of looping).
30
+ * It stops as soon as a link has no `.ref`, or the referenced
31
+ * field cannot be found — e.g. behind a shallow `{ id, metadata }` ref target
32
+ * from `/meta`, which carries no props (and needs none: the server already
33
+ * resolved the chain).
34
+ */
35
+ declare function extractValueHelp(prop: TAtscriptAnnotatedType): ValueHelpInfo | undefined;
36
+ //#endregion
37
+ export { extractValueHelp };
@@ -0,0 +1,37 @@
1
+ import { ValueHelpInfo } from "./types.mjs";
2
+ import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
3
+
4
+ //#region src/value-help/extract-ref.d.ts
5
+ /**
6
+ * Synchronous probe. Returns `{ url, targetField }` for the first link of the
7
+ * reference chain starting at `prop` that carries a `@ui.valueHelp` binding
8
+ * (since 0.1.148 — an explicit binding beats `@db.rel.FK`, and also supplies
9
+ * the static `filter` / `pinned` fields), or that satisfies all three conditions:
10
+ *
11
+ * 1. the link carries `@db.rel.FK`,
12
+ * 2. the link has a `.ref`,
13
+ * 3. the ref's target metadata carries `@db.http.path`.
14
+ *
15
+ * Since 0.1.134 the probe follows **reference chains**: when a link does not
16
+ * qualify, it hops onto the referenced field (`ref.type()` → that object's
17
+ * `props[ref.field]`) and re-tests. A view field declared as
18
+ * `errorCode: Issue.errorCode`, where `Issue.errorCode: ErrorCode.code` is the
19
+ * link carrying `@db.rel.FK`, therefore keeps its value help instead of losing
20
+ * the dictionary.
21
+ *
22
+ * This mirrors what the server already does on the `/meta` path: since
23
+ * `@atscript/db` 0.1.128 the serialized meta collapses such chains onto the
24
+ * terminal field (`ref` → terminal, `db.rel.FK: true`), so a form def built
25
+ * from `/meta` and one built from the compiled `.as` type land on the same
26
+ * dictionary.
27
+ *
28
+ * The walk is bounded ({@link MAX_REF_CHAIN_DEPTH}), which is also what makes a
29
+ * cyclic chain terminate (it runs out of hops and gives up instead of looping).
30
+ * It stops as soon as a link has no `.ref`, or the referenced
31
+ * field cannot be found — e.g. behind a shallow `{ id, metadata }` ref target
32
+ * from `/meta`, which carries no props (and needs none: the server already
33
+ * resolved the chain).
34
+ */
35
+ declare function extractValueHelp(prop: TAtscriptAnnotatedType): ValueHelpInfo | undefined;
36
+ //#endregion
37
+ export { extractValueHelp };
@@ -0,0 +1,100 @@
1
+ import { DB_HTTP_PATH, UI_VALUE_HELP } from "../shared/annotation-keys.mjs";
2
+ import { valueHelpFilter } from "./filter-tree.mjs";
3
+ //#region src/value-help/extract-ref.ts
4
+ /**
5
+ * Hard cap on how many `.ref` hops the chain walk follows. Real chains are one
6
+ * or two hops (view field → table field → dictionary); the cap is a backstop,
7
+ * not a modelling limit — and it is also what terminates a cyclic chain.
8
+ */
9
+ const MAX_REF_CHAIN_DEPTH = 8;
10
+ /**
11
+ * `@db.http.path` of a binding target. Two producers, two shapes — `/meta`
12
+ * deserialization does not normalize annotation values, so both are read here:
13
+ *
14
+ * - compiled `.as` (the atscript runtime): the annotated type itself (a class
15
+ * with a `metadata` Map) or a getter `() => Type` for a cross-file ref;
16
+ * - `/meta` (the serialized type): a shallow target `{ id, metadata }` whose
17
+ * `metadata` is a plain record.
18
+ *
19
+ * Also accepts `{ type: () => Type }`.
20
+ */
21
+ function bindingTargetPath(target) {
22
+ if (target === null || typeof target !== "object" && typeof target !== "function") return;
23
+ const t = target;
24
+ if (typeof target === "function" && t.metadata === void 0) return bindingTargetPath(target());
25
+ if (t.metadata instanceof Map) return t.metadata.get(DB_HTTP_PATH);
26
+ if (t.metadata && typeof t.metadata === "object") return t.metadata[DB_HTTP_PATH];
27
+ return t.type === void 0 ? void 0 : bindingTargetPath(t.type);
28
+ }
29
+ /**
30
+ * The `@ui.valueHelp` binding of a node, when its target is served by a
31
+ * controller (`@db.http.path`). Without a path the binding is ignored and the
32
+ * caller falls back to the FK walk.
33
+ */
34
+ function bindingInfo(node) {
35
+ const binding = node.metadata.get(UI_VALUE_HELP);
36
+ if (!binding?.field) return void 0;
37
+ const url = bindingTargetPath(binding.target);
38
+ if (!url) return void 0;
39
+ const info = {
40
+ url,
41
+ targetField: binding.field
42
+ };
43
+ if (binding.filter) {
44
+ const { filter, pinned } = valueHelpFilter(binding.filter);
45
+ info.filter = filter;
46
+ if (pinned.length > 0) info.pinned = pinned;
47
+ }
48
+ return info;
49
+ }
50
+ /**
51
+ * Synchronous probe. Returns `{ url, targetField }` for the first link of the
52
+ * reference chain starting at `prop` that carries a `@ui.valueHelp` binding
53
+ * (since 0.1.148 — an explicit binding beats `@db.rel.FK`, and also supplies
54
+ * the static `filter` / `pinned` fields), or that satisfies all three conditions:
55
+ *
56
+ * 1. the link carries `@db.rel.FK`,
57
+ * 2. the link has a `.ref`,
58
+ * 3. the ref's target metadata carries `@db.http.path`.
59
+ *
60
+ * Since 0.1.134 the probe follows **reference chains**: when a link does not
61
+ * qualify, it hops onto the referenced field (`ref.type()` → that object's
62
+ * `props[ref.field]`) and re-tests. A view field declared as
63
+ * `errorCode: Issue.errorCode`, where `Issue.errorCode: ErrorCode.code` is the
64
+ * link carrying `@db.rel.FK`, therefore keeps its value help instead of losing
65
+ * the dictionary.
66
+ *
67
+ * This mirrors what the server already does on the `/meta` path: since
68
+ * `@atscript/db` 0.1.128 the serialized meta collapses such chains onto the
69
+ * terminal field (`ref` → terminal, `db.rel.FK: true`), so a form def built
70
+ * from `/meta` and one built from the compiled `.as` type land on the same
71
+ * dictionary.
72
+ *
73
+ * The walk is bounded ({@link MAX_REF_CHAIN_DEPTH}), which is also what makes a
74
+ * cyclic chain terminate (it runs out of hops and gives up instead of looping).
75
+ * It stops as soon as a link has no `.ref`, or the referenced
76
+ * field cannot be found — e.g. behind a shallow `{ id, metadata }` ref target
77
+ * from `/meta`, which carries no props (and needs none: the server already
78
+ * resolved the chain).
79
+ */
80
+ function extractValueHelp(prop) {
81
+ let node = prop;
82
+ for (let depth = 0; node && depth < MAX_REF_CHAIN_DEPTH; depth++) {
83
+ const bound = bindingInfo(node);
84
+ if (bound) return bound;
85
+ const ref = node.ref;
86
+ if (!ref) return void 0;
87
+ const target = ref.type();
88
+ if (!target) return void 0;
89
+ if (node.metadata.has("db.rel.FK")) {
90
+ const url = target.metadata.get(DB_HTTP_PATH);
91
+ if (url) return {
92
+ url,
93
+ targetField: ref.field
94
+ };
95
+ }
96
+ node = (target.type.kind === "object" ? target.type : void 0)?.props.get(ref.field);
97
+ }
98
+ }
99
+ //#endregion
100
+ export { extractValueHelp };
@@ -0,0 +1,45 @@
1
+ //#region src/value-help/filter-tree.ts
2
+ function isFieldRef(value) {
3
+ return value !== null && typeof value === "object" && "field" in value;
4
+ }
5
+ /**
6
+ * A deliberate copy of `translateQueryTree` from `@atscript/db`: that module is a
7
+ * server-side runtime, and importing it would pull `@atscript/db` into the browser
8
+ * bundle. `filter-tree.spec.ts` guards the two against drift.
9
+ */
10
+ function translate(node) {
11
+ if (Array.isArray(node.$and)) return { $and: node.$and.map(translate) };
12
+ if (Array.isArray(node.$or)) return { $or: node.$or.map(translate) };
13
+ if (node.$not && typeof node.$not === "object") return { $not: translate(node.$not) };
14
+ const left = node.left.field;
15
+ const op = node.op;
16
+ const right = node.right;
17
+ if (isFieldRef(right)) return { [left]: { [op]: { $field: right.field } } };
18
+ if (op === "$exists") return { [left]: { $exists: right !== false } };
19
+ return { [left]: { [op]: right } };
20
+ }
21
+ /**
22
+ * Fields the tree pins to one value (`=` comparison against a literal) at its top-level
23
+ * `and` chain. The runtime twin of `pinnedFields` in `plugin/value-help-validation.ts`
24
+ * (which reads the source predicate) — keep the two rules in step.
25
+ */
26
+ function pinnedOf(node, out) {
27
+ if (Array.isArray(node.$and)) for (const n of node.$and) pinnedOf(n, out);
28
+ else if (node.left && node.op === "$eq" && !isFieldRef(node.right)) out.push(node.left.field);
29
+ }
30
+ /**
31
+ * Translates the static `filter` of a `@ui.valueHelp` binding into a Uniquery
32
+ * `FilterExpr` (mirrors `translateQueryTree` of `@atscript/db`, with refs
33
+ * resolved to the plain field path), plus the target fields it pins with `=` —
34
+ * constant inside the picker, so their columns are hidden. Since 0.1.148.
35
+ */
36
+ function valueHelpFilter(tree) {
37
+ const pinned = [];
38
+ pinnedOf(tree, pinned);
39
+ return {
40
+ filter: translate(tree),
41
+ pinned: [...new Set(pinned)]
42
+ };
43
+ }
44
+ //#endregion
45
+ exports.valueHelpFilter = valueHelpFilter;
@@ -0,0 +1,45 @@
1
+ //#region src/value-help/filter-tree.ts
2
+ function isFieldRef(value) {
3
+ return value !== null && typeof value === "object" && "field" in value;
4
+ }
5
+ /**
6
+ * A deliberate copy of `translateQueryTree` from `@atscript/db`: that module is a
7
+ * server-side runtime, and importing it would pull `@atscript/db` into the browser
8
+ * bundle. `filter-tree.spec.ts` guards the two against drift.
9
+ */
10
+ function translate(node) {
11
+ if (Array.isArray(node.$and)) return { $and: node.$and.map(translate) };
12
+ if (Array.isArray(node.$or)) return { $or: node.$or.map(translate) };
13
+ if (node.$not && typeof node.$not === "object") return { $not: translate(node.$not) };
14
+ const left = node.left.field;
15
+ const op = node.op;
16
+ const right = node.right;
17
+ if (isFieldRef(right)) return { [left]: { [op]: { $field: right.field } } };
18
+ if (op === "$exists") return { [left]: { $exists: right !== false } };
19
+ return { [left]: { [op]: right } };
20
+ }
21
+ /**
22
+ * Fields the tree pins to one value (`=` comparison against a literal) at its top-level
23
+ * `and` chain. The runtime twin of `pinnedFields` in `plugin/value-help-validation.ts`
24
+ * (which reads the source predicate) — keep the two rules in step.
25
+ */
26
+ function pinnedOf(node, out) {
27
+ if (Array.isArray(node.$and)) for (const n of node.$and) pinnedOf(n, out);
28
+ else if (node.left && node.op === "$eq" && !isFieldRef(node.right)) out.push(node.left.field);
29
+ }
30
+ /**
31
+ * Translates the static `filter` of a `@ui.valueHelp` binding into a Uniquery
32
+ * `FilterExpr` (mirrors `translateQueryTree` of `@atscript/db`, with refs
33
+ * resolved to the plain field path), plus the target fields it pins with `=` —
34
+ * constant inside the picker, so their columns are hidden. Since 0.1.148.
35
+ */
36
+ function valueHelpFilter(tree) {
37
+ const pinned = [];
38
+ pinnedOf(tree, pinned);
39
+ return {
40
+ filter: translate(tree),
41
+ pinned: [...new Set(pinned)]
42
+ };
43
+ }
44
+ //#endregion
45
+ export { valueHelpFilter };
@@ -0,0 +1,8 @@
1
+ import { TFormEntryOptions, ValueHelpInfo } from "./types.mjs";
2
+ import { ResolvedValueHelp, resetValueHelpCache, resolveValueHelp } from "./resolve.mjs";
3
+ import { ValueHelpClient, ValueHelpResult, ValueHelpSearchOptions, invalidateValueHelpCache, setValueHelpCacheTtl } from "./value-help-client.mjs";
4
+ import { valueHelpDictPaths } from "./dict-paths.mjs";
5
+ import { extractFieldLiteralOptions, extractLiteralOptions, isPureLiteralUnion } from "./extract-literals.mjs";
6
+ import { extractValueHelp } from "./extract-ref.mjs";
7
+ import { optKey, optLabel, optionLabel, parseStaticOptions, resolveOptions } from "./resolve-options.mjs";
8
+ import { fetchDistinctValues, isPickerDeclined } from "./distinct-client.mjs";
@@ -0,0 +1,64 @@
1
+ const require_annotation_keys = require("../shared/annotation-keys.cjs");
2
+ const require_field_resolver = require("../shared/field-resolver.cjs");
3
+ const require_extract_literals = require("./extract-literals.cjs");
4
+ //#region src/value-help/resolve-options.ts
5
+ /** Extracts the key from an option entry. */
6
+ function optKey(opt) {
7
+ return typeof opt === "string" ? opt : opt.key;
8
+ }
9
+ /** Extracts the display label from an option entry. */
10
+ function optLabel(opt) {
11
+ return typeof opt === "string" ? opt : opt.label;
12
+ }
13
+ const labelMaps = /* @__PURE__ */ new WeakMap();
14
+ /**
15
+ * The display label of a literal-union column's option (`@ui.literalLabel`) for
16
+ * `value` — `undefined` when the column has no options or none matches. Map-backed
17
+ * per options array, so rendering a table does not scan the options per cell.
18
+ * The one lookup behind the table cell, the filter chips, export and a custom cell.
19
+ * Since 0.1.148.
20
+ */
21
+ function optionLabel(column, value) {
22
+ const options = column.options;
23
+ if (!options?.length) return void 0;
24
+ if (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean") return;
25
+ let labels = labelMaps.get(options);
26
+ if (!labels) {
27
+ labels = new Map(options.map((o) => [o.key, o.label]));
28
+ labelMaps.set(options, labels);
29
+ }
30
+ return labels.get(String(value));
31
+ }
32
+ /**
33
+ * Converts raw option annotation value to a normalized array.
34
+ */
35
+ function parseStaticOptions(raw) {
36
+ return require_field_resolver.asArray(raw).map((item) => {
37
+ if (typeof item === "object" && item !== null && "label" in item) {
38
+ const { label, value } = item;
39
+ return value !== void 0 ? {
40
+ key: value,
41
+ label
42
+ } : label;
43
+ }
44
+ return String(item);
45
+ });
46
+ }
47
+ /**
48
+ * Resolves options from metadata with a fallback chain:
49
+ * 1. `@ui.form.fn.options` (dynamic, compiled by ui-fns)
50
+ * 2. `@ui.form.options` (static annotation)
51
+ * 3. Literal union type extraction (auto-derived from type)
52
+ * 4. Future: dictionary / value-help lookup
53
+ */
54
+ function resolveOptions(prop, scope) {
55
+ const resolved = require_field_resolver.resolveFieldProp(prop, require_annotation_keys.UI_FORM_FN_OPTIONS, require_annotation_keys.UI_FORM_OPTIONS, scope, { transform: parseStaticOptions });
56
+ if (resolved !== void 0) return resolved;
57
+ return require_extract_literals.extractFieldLiteralOptions(prop);
58
+ }
59
+ //#endregion
60
+ exports.optKey = optKey;
61
+ exports.optLabel = optLabel;
62
+ exports.optionLabel = optionLabel;
63
+ exports.parseStaticOptions = parseStaticOptions;
64
+ exports.resolveOptions = resolveOptions;