@atscript/ui 0.1.163 → 0.1.165

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 (164) hide show
  1. package/dist/client-factory.cjs +27 -0
  2. package/dist/client-factory.d.cts +58 -0
  3. package/dist/client-factory.d.mts +58 -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 +462 -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 +460 -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 +13 -0
  42. package/dist/form/labels.d.cts +11 -0
  43. package/dist/form/labels.d.mts +11 -0
  44. package/dist/form/labels.mjs +13 -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 +147 -0
  63. package/dist/form/types.d.mts +147 -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 +186 -0
  70. package/dist/form/validate.d.cts +81 -0
  71. package/dist/form/validate.d.mts +81 -0
  72. package/dist/form/validate.mjs +182 -0
  73. package/dist/i18n/ui-texts.cjs +135 -0
  74. package/dist/i18n/ui-texts.d.cts +81 -0
  75. package/dist/i18n/ui-texts.d.mts +81 -0
  76. package/dist/i18n/ui-texts.mjs +132 -0
  77. package/dist/index.cjs +223 -3360
  78. package/dist/index.d.cts +39 -1693
  79. package/dist/index.d.mts +39 -1693
  80. package/dist/index.mjs +36 -3179
  81. package/dist/messages.cjs +301 -0
  82. package/dist/messages.d.cts +302 -0
  83. package/dist/messages.d.mts +302 -0
  84. package/dist/messages.mjs +300 -0
  85. package/dist/nav/model-routes.cjs +59 -0
  86. package/dist/nav/model-routes.d.cts +33 -0
  87. package/dist/nav/model-routes.d.mts +33 -0
  88. package/dist/nav/model-routes.mjs +59 -0
  89. package/dist/plugin/annotations.cjs +592 -0
  90. package/dist/plugin/annotations.mjs +592 -0
  91. package/dist/plugin/primitives.cjs +30 -0
  92. package/dist/plugin/primitives.mjs +30 -0
  93. package/dist/plugin/value-help-validation.cjs +429 -0
  94. package/dist/plugin/value-help-validation.mjs +423 -0
  95. package/dist/plugin.cjs +4 -1001
  96. package/dist/plugin.mjs +2 -999
  97. package/dist/shared/annotation-keys.cjs +189 -0
  98. package/dist/shared/annotation-keys.d.cts +82 -0
  99. package/dist/shared/annotation-keys.d.mts +82 -0
  100. package/dist/shared/annotation-keys.mjs +97 -0
  101. package/dist/shared/field-resolver.cjs +123 -0
  102. package/dist/shared/field-resolver.d.cts +77 -0
  103. package/dist/shared/field-resolver.d.mts +77 -0
  104. package/dist/shared/field-resolver.mjs +110 -0
  105. package/dist/shared/meta-cache.cjs +282 -0
  106. package/dist/shared/meta-cache.d.cts +130 -0
  107. package/dist/shared/meta-cache.d.mts +130 -0
  108. package/dist/shared/meta-cache.mjs +275 -0
  109. package/dist/shared/str.cjs +19 -0
  110. package/dist/shared/str.d.cts +7 -0
  111. package/dist/shared/str.d.mts +7 -0
  112. package/dist/shared/str.mjs +17 -0
  113. package/dist/table/column-resolver.cjs +17 -0
  114. package/dist/table/column-resolver.d.cts +11 -0
  115. package/dist/table/column-resolver.d.mts +11 -0
  116. package/dist/table/column-resolver.mjs +15 -0
  117. package/dist/table/create-table-def.cjs +242 -0
  118. package/dist/table/create-table-def.d.cts +19 -0
  119. package/dist/table/create-table-def.d.mts +19 -0
  120. package/dist/table/create-table-def.mjs +242 -0
  121. package/dist/table/navigate-href.cjs +45 -0
  122. package/dist/table/navigate-href.d.cts +31 -0
  123. package/dist/table/navigate-href.d.mts +31 -0
  124. package/dist/table/navigate-href.mjs +45 -0
  125. package/dist/table/types.d.cts +290 -0
  126. package/dist/table/types.d.mts +290 -0
  127. package/dist/table/value-kind.cjs +20 -0
  128. package/dist/table/value-kind.d.cts +16 -0
  129. package/dist/table/value-kind.d.mts +16 -0
  130. package/dist/table/value-kind.mjs +19 -0
  131. package/dist/value-help/dict-paths.cjs +17 -0
  132. package/dist/value-help/dict-paths.d.cts +11 -0
  133. package/dist/value-help/dict-paths.d.mts +11 -0
  134. package/dist/value-help/dict-paths.mjs +17 -0
  135. package/dist/value-help/distinct-client.cjs +51 -0
  136. package/dist/value-help/distinct-client.d.cts +40 -0
  137. package/dist/value-help/distinct-client.d.mts +40 -0
  138. package/dist/value-help/distinct-client.mjs +50 -0
  139. package/dist/value-help/extract-literals.cjs +115 -0
  140. package/dist/value-help/extract-literals.d.cts +44 -0
  141. package/dist/value-help/extract-literals.d.mts +44 -0
  142. package/dist/value-help/extract-literals.mjs +111 -0
  143. package/dist/value-help/extract-ref.cjs +100 -0
  144. package/dist/value-help/extract-ref.d.cts +37 -0
  145. package/dist/value-help/extract-ref.d.mts +37 -0
  146. package/dist/value-help/extract-ref.mjs +100 -0
  147. package/dist/value-help/filter-tree.cjs +45 -0
  148. package/dist/value-help/filter-tree.mjs +45 -0
  149. package/dist/value-help/index.d.mts +8 -0
  150. package/dist/value-help/resolve-options.cjs +68 -0
  151. package/dist/value-help/resolve-options.d.cts +40 -0
  152. package/dist/value-help/resolve-options.d.mts +40 -0
  153. package/dist/value-help/resolve-options.mjs +64 -0
  154. package/dist/value-help/resolve.cjs +66 -0
  155. package/dist/value-help/resolve.d.cts +36 -0
  156. package/dist/value-help/resolve.d.mts +36 -0
  157. package/dist/value-help/resolve.mjs +65 -0
  158. package/dist/value-help/types.d.cts +41 -0
  159. package/dist/value-help/types.d.mts +41 -0
  160. package/dist/value-help/value-help-client.cjs +136 -0
  161. package/dist/value-help/value-help-client.d.cts +67 -0
  162. package/dist/value-help/value-help-client.d.mts +67 -0
  163. package/dist/value-help/value-help-client.mjs +134 -0
  164. package/package.json +15 -10
@@ -0,0 +1,11 @@
1
+ import { ResolvedValueHelp } from "./resolve.mjs";
2
+
3
+ //#region src/value-help/dict-paths.d.ts
4
+ /**
5
+ * Paths that make up the "dict view" of a value-help target:
6
+ * PKs + label + descr + attr fields. Used by filter dialogs to clamp
7
+ * visible columns to the dictionary subset.
8
+ */
9
+ declare function valueHelpDictPaths(resolved: ResolvedValueHelp): Set<string>;
10
+ //#endregion
11
+ export { valueHelpDictPaths };
@@ -0,0 +1,17 @@
1
+ //#region src/value-help/dict-paths.ts
2
+ /**
3
+ * Paths that make up the "dict view" of a value-help target:
4
+ * PKs + label + descr + attr fields. Used by filter dialogs to clamp
5
+ * visible columns to the dictionary subset.
6
+ */
7
+ function valueHelpDictPaths(resolved) {
8
+ const paths = [
9
+ ...resolved.primaryKeys,
10
+ resolved.labelField,
11
+ ...resolved.attrFields
12
+ ];
13
+ if (resolved.descrField) paths.push(resolved.descrField);
14
+ return new Set(paths);
15
+ }
16
+ //#endregion
17
+ export { valueHelpDictPaths };
@@ -0,0 +1,51 @@
1
+ const require_str = require("../shared/str.cjs");
2
+ //#region src/value-help/distinct-client.ts
3
+ /**
4
+ * `true` for a 4xx answer — the server declined this picker (gate, ARBAC, unknown field).
5
+ * @internal Shared with `@atscript/vue-table`.
6
+ */
7
+ function isPickerDeclined(err) {
8
+ const status = err?.status;
9
+ return typeof status === "number" && status >= 400 && status < 500;
10
+ }
11
+ /**
12
+ * Distinct values of one column of the table behind `client`, via
13
+ * `/query?$groupBy=<field>`. All server gates (hidden field, ARBAC `$groupBy`
14
+ * control, row scope, write-only, encrypted) apply as for any grouped read; a
15
+ * 4xx rejects with a `ClientError` — see {@link isPickerDeclined}.
16
+ * `hasMore` tells whether another page follows.
17
+ *
18
+ * @internal Backs the distinct-values picker of `@atscript/vue-table`.
19
+ */
20
+ async function fetchDistinctValues(client, field, opts = {}) {
21
+ const limit = opts.limit ?? 50;
22
+ const text = opts.text?.trim();
23
+ const conditions = [];
24
+ if (opts.filter) conditions.push(opts.filter);
25
+ if (text) if (opts.numeric) {
26
+ const n = Number(text);
27
+ if (!Number.isFinite(n)) return {
28
+ items: [],
29
+ hasMore: false
30
+ };
31
+ conditions.push({ [field]: n });
32
+ } else conditions.push({ [field]: { $regex: `/^${require_str.escapeRegex(text)}/i` } });
33
+ const filter = conditions.length > 1 ? { $and: conditions } : conditions[0];
34
+ const rows = await client.aggregate({
35
+ ...filter && { filter },
36
+ controls: {
37
+ $groupBy: [field],
38
+ $select: [field],
39
+ ...opts.sortable && { $sort: { [field]: 1 } },
40
+ $limit: limit + 1,
41
+ $skip: opts.skip ?? 0
42
+ }
43
+ });
44
+ return {
45
+ items: rows.slice(0, limit).map((r) => r[field]).filter((v) => v !== null && v !== void 0),
46
+ hasMore: rows.length > limit
47
+ };
48
+ }
49
+ //#endregion
50
+ exports.fetchDistinctValues = fetchDistinctValues;
51
+ exports.isPickerDeclined = isPickerDeclined;
@@ -0,0 +1,40 @@
1
+ import { Client, FilterExpr } from "@atscript/db-client";
2
+
3
+ //#region src/value-help/distinct-client.d.ts
4
+ interface DistinctValuesOptions {
5
+ /** Search text: a case-insensitive prefix match for strings, an exact match for numbers. */
6
+ text?: string;
7
+ /** Page size. Default: 50. */
8
+ limit?: number;
9
+ /**
10
+ * Rows to skip (the next page of a scrolled picker). Distinct values are only
11
+ * stable across pages when ordered, so a caller pages only with `sortable`.
12
+ */
13
+ skip?: number;
14
+ /** Send `$sort` on the grouped field — only when the server lists it as sortable. */
15
+ sortable?: boolean;
16
+ /** The field stores numbers: search is an exact match and non-numeric text finds nothing. */
17
+ numeric?: boolean;
18
+ /** Extra scope AND'd into the query (e.g. the table's `forceFilters`). */
19
+ filter?: FilterExpr;
20
+ }
21
+ /**
22
+ * `true` for a 4xx answer — the server declined this picker (gate, ARBAC, unknown field).
23
+ * @internal Shared with `@atscript/vue-table`.
24
+ */
25
+ declare function isPickerDeclined(err: unknown): boolean;
26
+ /**
27
+ * Distinct values of one column of the table behind `client`, via
28
+ * `/query?$groupBy=<field>`. All server gates (hidden field, ARBAC `$groupBy`
29
+ * control, row scope, write-only, encrypted) apply as for any grouped read; a
30
+ * 4xx rejects with a `ClientError` — see {@link isPickerDeclined}.
31
+ * `hasMore` tells whether another page follows.
32
+ *
33
+ * @internal Backs the distinct-values picker of `@atscript/vue-table`.
34
+ */
35
+ declare function fetchDistinctValues(client: Pick<Client, "aggregate">, field: string, opts?: DistinctValuesOptions): Promise<{
36
+ items: unknown[];
37
+ hasMore: boolean;
38
+ }>;
39
+ //#endregion
40
+ export { fetchDistinctValues, isPickerDeclined };
@@ -0,0 +1,40 @@
1
+ import { Client, FilterExpr } from "@atscript/db-client";
2
+
3
+ //#region src/value-help/distinct-client.d.ts
4
+ interface DistinctValuesOptions {
5
+ /** Search text: a case-insensitive prefix match for strings, an exact match for numbers. */
6
+ text?: string;
7
+ /** Page size. Default: 50. */
8
+ limit?: number;
9
+ /**
10
+ * Rows to skip (the next page of a scrolled picker). Distinct values are only
11
+ * stable across pages when ordered, so a caller pages only with `sortable`.
12
+ */
13
+ skip?: number;
14
+ /** Send `$sort` on the grouped field — only when the server lists it as sortable. */
15
+ sortable?: boolean;
16
+ /** The field stores numbers: search is an exact match and non-numeric text finds nothing. */
17
+ numeric?: boolean;
18
+ /** Extra scope AND'd into the query (e.g. the table's `forceFilters`). */
19
+ filter?: FilterExpr;
20
+ }
21
+ /**
22
+ * `true` for a 4xx answer — the server declined this picker (gate, ARBAC, unknown field).
23
+ * @internal Shared with `@atscript/vue-table`.
24
+ */
25
+ declare function isPickerDeclined(err: unknown): boolean;
26
+ /**
27
+ * Distinct values of one column of the table behind `client`, via
28
+ * `/query?$groupBy=<field>`. All server gates (hidden field, ARBAC `$groupBy`
29
+ * control, row scope, write-only, encrypted) apply as for any grouped read; a
30
+ * 4xx rejects with a `ClientError` — see {@link isPickerDeclined}.
31
+ * `hasMore` tells whether another page follows.
32
+ *
33
+ * @internal Backs the distinct-values picker of `@atscript/vue-table`.
34
+ */
35
+ declare function fetchDistinctValues(client: Pick<Client, "aggregate">, field: string, opts?: DistinctValuesOptions): Promise<{
36
+ items: unknown[];
37
+ hasMore: boolean;
38
+ }>;
39
+ //#endregion
40
+ export { fetchDistinctValues, isPickerDeclined };
@@ -0,0 +1,50 @@
1
+ import { escapeRegex } from "../shared/str.mjs";
2
+ //#region src/value-help/distinct-client.ts
3
+ /**
4
+ * `true` for a 4xx answer — the server declined this picker (gate, ARBAC, unknown field).
5
+ * @internal Shared with `@atscript/vue-table`.
6
+ */
7
+ function isPickerDeclined(err) {
8
+ const status = err?.status;
9
+ return typeof status === "number" && status >= 400 && status < 500;
10
+ }
11
+ /**
12
+ * Distinct values of one column of the table behind `client`, via
13
+ * `/query?$groupBy=<field>`. All server gates (hidden field, ARBAC `$groupBy`
14
+ * control, row scope, write-only, encrypted) apply as for any grouped read; a
15
+ * 4xx rejects with a `ClientError` — see {@link isPickerDeclined}.
16
+ * `hasMore` tells whether another page follows.
17
+ *
18
+ * @internal Backs the distinct-values picker of `@atscript/vue-table`.
19
+ */
20
+ async function fetchDistinctValues(client, field, opts = {}) {
21
+ const limit = opts.limit ?? 50;
22
+ const text = opts.text?.trim();
23
+ const conditions = [];
24
+ if (opts.filter) conditions.push(opts.filter);
25
+ if (text) if (opts.numeric) {
26
+ const n = Number(text);
27
+ if (!Number.isFinite(n)) return {
28
+ items: [],
29
+ hasMore: false
30
+ };
31
+ conditions.push({ [field]: n });
32
+ } else conditions.push({ [field]: { $regex: `/^${escapeRegex(text)}/i` } });
33
+ const filter = conditions.length > 1 ? { $and: conditions } : conditions[0];
34
+ const rows = await client.aggregate({
35
+ ...filter && { filter },
36
+ controls: {
37
+ $groupBy: [field],
38
+ $select: [field],
39
+ ...opts.sortable && { $sort: { [field]: 1 } },
40
+ $limit: limit + 1,
41
+ $skip: opts.skip ?? 0
42
+ }
43
+ });
44
+ return {
45
+ items: rows.slice(0, limit).map((r) => r[field]).filter((v) => v !== null && v !== void 0),
46
+ hasMore: rows.length > limit
47
+ };
48
+ }
49
+ //#endregion
50
+ export { fetchDistinctValues, isPickerDeclined };
@@ -0,0 +1,115 @@
1
+ require("../shared/annotation-keys.cjs");
2
+ const require_messages = require("../messages.cjs");
3
+ const require_ui_texts = require("../i18n/ui-texts.cjs");
4
+ //#region src/value-help/extract-literals.ts
5
+ /**
6
+ * The English labels an unlabelled `boolean` value shows — in table cells,
7
+ * filter chips, the filter picker, export and read-only form fields. They are
8
+ * the UI texts `UI_YES` / `UI_NO` (`AS_UI_MESSAGES`), shown in the UI locale.
9
+ * Since 0.1.165.
10
+ */
11
+ const DEFAULT_BOOLEAN_LABELS = Object.freeze({
12
+ true: require_messages.AS_UI_MESSAGES.UI_YES,
13
+ false: require_messages.AS_UI_MESSAGES.UI_NO
14
+ });
15
+ /**
16
+ * Extracts options from a union of literal types (e.g. 'a' | 'b' | 'c') or a
17
+ * `boolean` (since 0.1.165: the two values `true` / `false`, labelled
18
+ * {@link DEFAULT_BOOLEAN_LABELS} unless `@ui.literalLabel` says otherwise).
19
+ * `null` / `undefined` members of a union (`'a' | 'b' | null`, `boolean | null`)
20
+ * are not values and are skipped. Returns undefined for anything else.
21
+ *
22
+ * Handles nested unions created by flattenAnnotatedType, which recurses
23
+ * into union items and produces synthetic unions containing both individual
24
+ * literals and the original union type as nested items.
25
+ */
26
+ function extractLiteralOptions(prop, outer, t = require_ui_texts.getUiTexts().t) {
27
+ const items = prop.type.kind === "union" ? prop.type.items : isBooleanPrimitive(prop) ? [prop] : void 0;
28
+ const result = items && collectLiterals(items, /* @__PURE__ */ new Set(), t);
29
+ if (!result || result.length === 0) return void 0;
30
+ const labels = [prop, outer].flatMap((node) => node?.metadata.get("ui.literalLabel") ?? []);
31
+ if (labels.length) {
32
+ const byValue = new Map(labels.map((l) => [l.value, l.label]));
33
+ for (const option of result) option.label = byValue.get(option.key) ?? option.label;
34
+ }
35
+ return result;
36
+ }
37
+ /**
38
+ * The literal options of a field: a literal union's or a boolean's (since 0.1.165),
39
+ * or those of an array of one (`tags: Tag[]`, `flags: boolean[]`), where the array
40
+ * prop's own `@ui.literalLabel` labels win over the element type's. `undefined` when
41
+ * the field is neither. Since 0.1.148.
42
+ */
43
+ function extractFieldLiteralOptions(prop, t = require_ui_texts.getUiTexts().t) {
44
+ if (prop.type.kind === "array") return extractLiteralOptions(prop.type.of, prop, t);
45
+ return extractLiteralOptions(prop, void 0, t);
46
+ }
47
+ /** A `null` / `undefined` member of a union (`T | null`): no value of its own. */
48
+ function isEmptyMember(item) {
49
+ const dt = item.type.designType;
50
+ return item.type.kind === "" && (dt === "null" || dt === "undefined");
51
+ }
52
+ /** A `boolean` (not a `true` / `false` literal). */
53
+ function isBooleanPrimitive(prop) {
54
+ const final = prop.type;
55
+ return prop.type.kind === "" && final.designType === "boolean" && final.value === void 0;
56
+ }
57
+ /** Returns true when the annotated type is a union composed entirely of literal values. */
58
+ function isPureLiteralUnion(prop) {
59
+ if (prop.type.kind !== "union") return false;
60
+ return checkAllLiterals(prop.type.items);
61
+ }
62
+ /** Walks union items returning true only if every leaf is a literal value. */
63
+ function checkAllLiterals(items) {
64
+ for (const item of items) {
65
+ if (item.type.kind === "" && item.type.value !== void 0) continue;
66
+ if (item.type.kind === "union") {
67
+ if (!checkAllLiterals(item.type.items)) return false;
68
+ continue;
69
+ }
70
+ return false;
71
+ }
72
+ return items.length > 0;
73
+ }
74
+ /**
75
+ * Recursively collects literal values from union items: a literal is one value
76
+ * (a `true` / `false` literal default-labelled like a boolean's), a `boolean` the
77
+ * two (`true` / `false`, default-labelled), a `null` / `undefined`
78
+ * member none. Returns null if any other item is found (no options).
79
+ * Returns empty array when all items are valid but already seen (deduped).
80
+ */
81
+ function collectLiterals(items, seen, t) {
82
+ const result = [];
83
+ const add = (raw) => {
84
+ const val = String(raw);
85
+ if (!seen.has(val)) {
86
+ seen.add(val);
87
+ const label = typeof raw === "boolean" ? t(raw ? "UI_YES" : "UI_NO") : val;
88
+ result.push({
89
+ key: val,
90
+ label,
91
+ value: raw
92
+ });
93
+ }
94
+ };
95
+ for (const item of items) {
96
+ const final = item.type;
97
+ if (item.type.kind === "" && final.value !== void 0) add(final.value);
98
+ else if (isBooleanPrimitive(item)) {
99
+ add(true);
100
+ add(false);
101
+ } else if (isEmptyMember(item)) continue;
102
+ else if (item.type.kind === "union") {
103
+ const nested = collectLiterals(item.type.items, seen, t);
104
+ if (nested === null) return null;
105
+ result.push(...nested);
106
+ } else return null;
107
+ }
108
+ return result;
109
+ }
110
+ //#endregion
111
+ exports.DEFAULT_BOOLEAN_LABELS = DEFAULT_BOOLEAN_LABELS;
112
+ exports.extractFieldLiteralOptions = extractFieldLiteralOptions;
113
+ exports.extractLiteralOptions = extractLiteralOptions;
114
+ exports.isEmptyMember = isEmptyMember;
115
+ exports.isPureLiteralUnion = isPureLiteralUnion;
@@ -0,0 +1,44 @@
1
+ import { UiT } from "../i18n/ui-texts.cjs";
2
+ import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
3
+
4
+ //#region src/value-help/extract-literals.d.ts
5
+ /**
6
+ * One literal of a union: `key` / `label` are the string forms the UI keys
7
+ * on; `value` is the typed literal (`true`, `3`, `'a'`) — what a filter or a
8
+ * form must send to the server. `value` since 0.1.148.
9
+ */
10
+ interface LiteralOption {
11
+ key: string;
12
+ label: string;
13
+ value: string | number | boolean;
14
+ }
15
+ /**
16
+ * The English labels an unlabelled `boolean` value shows — in table cells,
17
+ * filter chips, the filter picker, export and read-only form fields. They are
18
+ * the UI texts `UI_YES` / `UI_NO` (`AS_UI_MESSAGES`), shown in the UI locale.
19
+ * Since 0.1.165.
20
+ */
21
+ declare const DEFAULT_BOOLEAN_LABELS: Readonly<Record<"true" | "false", string>>;
22
+ /**
23
+ * Extracts options from a union of literal types (e.g. 'a' | 'b' | 'c') or a
24
+ * `boolean` (since 0.1.165: the two values `true` / `false`, labelled
25
+ * {@link DEFAULT_BOOLEAN_LABELS} unless `@ui.literalLabel` says otherwise).
26
+ * `null` / `undefined` members of a union (`'a' | 'b' | null`, `boolean | null`)
27
+ * are not values and are skipped. Returns undefined for anything else.
28
+ *
29
+ * Handles nested unions created by flattenAnnotatedType, which recurses
30
+ * into union items and produces synthetic unions containing both individual
31
+ * literals and the original union type as nested items.
32
+ */
33
+ declare function extractLiteralOptions(prop: TAtscriptAnnotatedType, outer?: TAtscriptAnnotatedType, t?: UiT): LiteralOption[] | undefined;
34
+ /**
35
+ * The literal options of a field: a literal union's or a boolean's (since 0.1.165),
36
+ * or those of an array of one (`tags: Tag[]`, `flags: boolean[]`), where the array
37
+ * prop's own `@ui.literalLabel` labels win over the element type's. `undefined` when
38
+ * the field is neither. Since 0.1.148.
39
+ */
40
+ declare function extractFieldLiteralOptions(prop: TAtscriptAnnotatedType, t?: UiT): LiteralOption[] | undefined;
41
+ /** Returns true when the annotated type is a union composed entirely of literal values. */
42
+ declare function isPureLiteralUnion(prop: TAtscriptAnnotatedType): boolean;
43
+ //#endregion
44
+ export { DEFAULT_BOOLEAN_LABELS, extractFieldLiteralOptions, extractLiteralOptions, isPureLiteralUnion };
@@ -0,0 +1,44 @@
1
+ import { UiT } from "../i18n/ui-texts.mjs";
2
+ import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
3
+
4
+ //#region src/value-help/extract-literals.d.ts
5
+ /**
6
+ * One literal of a union: `key` / `label` are the string forms the UI keys
7
+ * on; `value` is the typed literal (`true`, `3`, `'a'`) — what a filter or a
8
+ * form must send to the server. `value` since 0.1.148.
9
+ */
10
+ interface LiteralOption {
11
+ key: string;
12
+ label: string;
13
+ value: string | number | boolean;
14
+ }
15
+ /**
16
+ * The English labels an unlabelled `boolean` value shows — in table cells,
17
+ * filter chips, the filter picker, export and read-only form fields. They are
18
+ * the UI texts `UI_YES` / `UI_NO` (`AS_UI_MESSAGES`), shown in the UI locale.
19
+ * Since 0.1.165.
20
+ */
21
+ declare const DEFAULT_BOOLEAN_LABELS: Readonly<Record<"true" | "false", string>>;
22
+ /**
23
+ * Extracts options from a union of literal types (e.g. 'a' | 'b' | 'c') or a
24
+ * `boolean` (since 0.1.165: the two values `true` / `false`, labelled
25
+ * {@link DEFAULT_BOOLEAN_LABELS} unless `@ui.literalLabel` says otherwise).
26
+ * `null` / `undefined` members of a union (`'a' | 'b' | null`, `boolean | null`)
27
+ * are not values and are skipped. Returns undefined for anything else.
28
+ *
29
+ * Handles nested unions created by flattenAnnotatedType, which recurses
30
+ * into union items and produces synthetic unions containing both individual
31
+ * literals and the original union type as nested items.
32
+ */
33
+ declare function extractLiteralOptions(prop: TAtscriptAnnotatedType, outer?: TAtscriptAnnotatedType, t?: UiT): LiteralOption[] | undefined;
34
+ /**
35
+ * The literal options of a field: a literal union's or a boolean's (since 0.1.165),
36
+ * or those of an array of one (`tags: Tag[]`, `flags: boolean[]`), where the array
37
+ * prop's own `@ui.literalLabel` labels win over the element type's. `undefined` when
38
+ * the field is neither. Since 0.1.148.
39
+ */
40
+ declare function extractFieldLiteralOptions(prop: TAtscriptAnnotatedType, t?: UiT): LiteralOption[] | undefined;
41
+ /** Returns true when the annotated type is a union composed entirely of literal values. */
42
+ declare function isPureLiteralUnion(prop: TAtscriptAnnotatedType): boolean;
43
+ //#endregion
44
+ export { DEFAULT_BOOLEAN_LABELS, extractFieldLiteralOptions, extractLiteralOptions, isPureLiteralUnion };
@@ -0,0 +1,111 @@
1
+ import "../shared/annotation-keys.mjs";
2
+ import { AS_UI_MESSAGES } from "../messages.mjs";
3
+ import { getUiTexts } from "../i18n/ui-texts.mjs";
4
+ //#region src/value-help/extract-literals.ts
5
+ /**
6
+ * The English labels an unlabelled `boolean` value shows — in table cells,
7
+ * filter chips, the filter picker, export and read-only form fields. They are
8
+ * the UI texts `UI_YES` / `UI_NO` (`AS_UI_MESSAGES`), shown in the UI locale.
9
+ * Since 0.1.165.
10
+ */
11
+ const DEFAULT_BOOLEAN_LABELS = Object.freeze({
12
+ true: AS_UI_MESSAGES.UI_YES,
13
+ false: AS_UI_MESSAGES.UI_NO
14
+ });
15
+ /**
16
+ * Extracts options from a union of literal types (e.g. 'a' | 'b' | 'c') or a
17
+ * `boolean` (since 0.1.165: the two values `true` / `false`, labelled
18
+ * {@link DEFAULT_BOOLEAN_LABELS} unless `@ui.literalLabel` says otherwise).
19
+ * `null` / `undefined` members of a union (`'a' | 'b' | null`, `boolean | null`)
20
+ * are not values and are skipped. Returns undefined for anything else.
21
+ *
22
+ * Handles nested unions created by flattenAnnotatedType, which recurses
23
+ * into union items and produces synthetic unions containing both individual
24
+ * literals and the original union type as nested items.
25
+ */
26
+ function extractLiteralOptions(prop, outer, t = getUiTexts().t) {
27
+ const items = prop.type.kind === "union" ? prop.type.items : isBooleanPrimitive(prop) ? [prop] : void 0;
28
+ const result = items && collectLiterals(items, /* @__PURE__ */ new Set(), t);
29
+ if (!result || result.length === 0) return void 0;
30
+ const labels = [prop, outer].flatMap((node) => node?.metadata.get("ui.literalLabel") ?? []);
31
+ if (labels.length) {
32
+ const byValue = new Map(labels.map((l) => [l.value, l.label]));
33
+ for (const option of result) option.label = byValue.get(option.key) ?? option.label;
34
+ }
35
+ return result;
36
+ }
37
+ /**
38
+ * The literal options of a field: a literal union's or a boolean's (since 0.1.165),
39
+ * or those of an array of one (`tags: Tag[]`, `flags: boolean[]`), where the array
40
+ * prop's own `@ui.literalLabel` labels win over the element type's. `undefined` when
41
+ * the field is neither. Since 0.1.148.
42
+ */
43
+ function extractFieldLiteralOptions(prop, t = getUiTexts().t) {
44
+ if (prop.type.kind === "array") return extractLiteralOptions(prop.type.of, prop, t);
45
+ return extractLiteralOptions(prop, void 0, t);
46
+ }
47
+ /** A `null` / `undefined` member of a union (`T | null`): no value of its own. */
48
+ function isEmptyMember(item) {
49
+ const dt = item.type.designType;
50
+ return item.type.kind === "" && (dt === "null" || dt === "undefined");
51
+ }
52
+ /** A `boolean` (not a `true` / `false` literal). */
53
+ function isBooleanPrimitive(prop) {
54
+ const final = prop.type;
55
+ return prop.type.kind === "" && final.designType === "boolean" && final.value === void 0;
56
+ }
57
+ /** Returns true when the annotated type is a union composed entirely of literal values. */
58
+ function isPureLiteralUnion(prop) {
59
+ if (prop.type.kind !== "union") return false;
60
+ return checkAllLiterals(prop.type.items);
61
+ }
62
+ /** Walks union items returning true only if every leaf is a literal value. */
63
+ function checkAllLiterals(items) {
64
+ for (const item of items) {
65
+ if (item.type.kind === "" && item.type.value !== void 0) continue;
66
+ if (item.type.kind === "union") {
67
+ if (!checkAllLiterals(item.type.items)) return false;
68
+ continue;
69
+ }
70
+ return false;
71
+ }
72
+ return items.length > 0;
73
+ }
74
+ /**
75
+ * Recursively collects literal values from union items: a literal is one value
76
+ * (a `true` / `false` literal default-labelled like a boolean's), a `boolean` the
77
+ * two (`true` / `false`, default-labelled), a `null` / `undefined`
78
+ * member none. Returns null if any other item is found (no options).
79
+ * Returns empty array when all items are valid but already seen (deduped).
80
+ */
81
+ function collectLiterals(items, seen, t) {
82
+ const result = [];
83
+ const add = (raw) => {
84
+ const val = String(raw);
85
+ if (!seen.has(val)) {
86
+ seen.add(val);
87
+ const label = typeof raw === "boolean" ? t(raw ? "UI_YES" : "UI_NO") : val;
88
+ result.push({
89
+ key: val,
90
+ label,
91
+ value: raw
92
+ });
93
+ }
94
+ };
95
+ for (const item of items) {
96
+ const final = item.type;
97
+ if (item.type.kind === "" && final.value !== void 0) add(final.value);
98
+ else if (isBooleanPrimitive(item)) {
99
+ add(true);
100
+ add(false);
101
+ } else if (isEmptyMember(item)) continue;
102
+ else if (item.type.kind === "union") {
103
+ const nested = collectLiterals(item.type.items, seen, t);
104
+ if (nested === null) return null;
105
+ result.push(...nested);
106
+ } else return null;
107
+ }
108
+ return result;
109
+ }
110
+ //#endregion
111
+ export { DEFAULT_BOOLEAN_LABELS, extractFieldLiteralOptions, extractLiteralOptions, isEmptyMember, 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 };