@atscript/ui 0.1.163 → 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,35 @@
1
+ import { TFormEntryOptions } from "./types.cjs";
2
+ import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
3
+
4
+ //#region src/value-help/resolve-options.d.ts
5
+ /** Extracts the key from an option entry. */
6
+ declare function optKey(opt: TFormEntryOptions): string;
7
+ /** Extracts the display label from an option entry. */
8
+ declare function optLabel(opt: TFormEntryOptions): string;
9
+ /**
10
+ * The display label of a literal-union column's option (`@ui.literalLabel`) for
11
+ * `value` — `undefined` when the column has no options or none matches. Map-backed
12
+ * per options array, so rendering a table does not scan the options per cell.
13
+ * The one lookup behind the table cell, the filter chips, export and a custom cell.
14
+ * Since 0.1.148.
15
+ */
16
+ declare function optionLabel(column: {
17
+ options?: {
18
+ key: string;
19
+ label: string;
20
+ }[];
21
+ }, value: unknown): string | undefined;
22
+ /**
23
+ * Converts raw option annotation value to a normalized array.
24
+ */
25
+ declare function parseStaticOptions(raw: unknown): TFormEntryOptions[];
26
+ /**
27
+ * Resolves options from metadata with a fallback chain:
28
+ * 1. `@ui.form.fn.options` (dynamic, compiled by ui-fns)
29
+ * 2. `@ui.form.options` (static annotation)
30
+ * 3. Literal union type extraction (auto-derived from type)
31
+ * 4. Future: dictionary / value-help lookup
32
+ */
33
+ declare function resolveOptions(prop: TAtscriptAnnotatedType, scope: Record<string, unknown>): TFormEntryOptions[] | undefined;
34
+ //#endregion
35
+ export { optKey, optLabel, optionLabel, parseStaticOptions, resolveOptions };
@@ -0,0 +1,35 @@
1
+ import { TFormEntryOptions } from "./types.mjs";
2
+ import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
3
+
4
+ //#region src/value-help/resolve-options.d.ts
5
+ /** Extracts the key from an option entry. */
6
+ declare function optKey(opt: TFormEntryOptions): string;
7
+ /** Extracts the display label from an option entry. */
8
+ declare function optLabel(opt: TFormEntryOptions): string;
9
+ /**
10
+ * The display label of a literal-union column's option (`@ui.literalLabel`) for
11
+ * `value` — `undefined` when the column has no options or none matches. Map-backed
12
+ * per options array, so rendering a table does not scan the options per cell.
13
+ * The one lookup behind the table cell, the filter chips, export and a custom cell.
14
+ * Since 0.1.148.
15
+ */
16
+ declare function optionLabel(column: {
17
+ options?: {
18
+ key: string;
19
+ label: string;
20
+ }[];
21
+ }, value: unknown): string | undefined;
22
+ /**
23
+ * Converts raw option annotation value to a normalized array.
24
+ */
25
+ declare function parseStaticOptions(raw: unknown): TFormEntryOptions[];
26
+ /**
27
+ * Resolves options from metadata with a fallback chain:
28
+ * 1. `@ui.form.fn.options` (dynamic, compiled by ui-fns)
29
+ * 2. `@ui.form.options` (static annotation)
30
+ * 3. Literal union type extraction (auto-derived from type)
31
+ * 4. Future: dictionary / value-help lookup
32
+ */
33
+ declare function resolveOptions(prop: TAtscriptAnnotatedType, scope: Record<string, unknown>): TFormEntryOptions[] | undefined;
34
+ //#endregion
35
+ export { optKey, optLabel, optionLabel, parseStaticOptions, resolveOptions };
@@ -0,0 +1,60 @@
1
+ import { UI_FORM_FN_OPTIONS, UI_FORM_OPTIONS } from "../shared/annotation-keys.mjs";
2
+ import { asArray, resolveFieldProp } from "../shared/field-resolver.mjs";
3
+ import { extractFieldLiteralOptions } from "./extract-literals.mjs";
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 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 = resolveFieldProp(prop, UI_FORM_FN_OPTIONS, UI_FORM_OPTIONS, scope, { transform: parseStaticOptions });
56
+ if (resolved !== void 0) return resolved;
57
+ return extractFieldLiteralOptions(prop);
58
+ }
59
+ //#endregion
60
+ export { optKey, optLabel, optionLabel, parseStaticOptions, resolveOptions };
@@ -0,0 +1,62 @@
1
+ const require_annotation_keys = require("../shared/annotation-keys.cjs");
2
+ const require_meta_cache = require("../shared/meta-cache.cjs");
3
+ //#region src/value-help/resolve.ts
4
+ /**
5
+ * Lazily fetch and extract value-help metadata for the given URL.
6
+ *
7
+ * - Issues exactly one `GET {url}/meta` per URL across the session (shared via meta-cache).
8
+ * - Concurrent callers with the same URL share the in-flight promise.
9
+ * - If the underlying fetch rejects, the cache entry is evicted so a later
10
+ * retry performs a fresh fetch.
11
+ */
12
+ function resolveValueHelp(url) {
13
+ const entry = require_meta_cache.getMetaEntry(url);
14
+ if (entry.resolved) return entry.resolved;
15
+ entry.resolved = Promise.all([entry.meta, entry.type]).then(([meta, type]) => buildResolved(url, meta, type));
16
+ return entry.resolved;
17
+ }
18
+ /** Thin alias over `resetMetaCache` — retained so existing test code keeps working. */
19
+ function resetValueHelpCache() {
20
+ require_meta_cache.resetMetaCache();
21
+ }
22
+ function buildResolved(url, meta, targetType) {
23
+ const objectType = targetType.type.kind === "object" ? targetType.type : void 0;
24
+ const versionColumn = meta.versionColumn;
25
+ const primaryKeys = [];
26
+ let labelField;
27
+ let descrField;
28
+ const attrFields = [];
29
+ let firstStringField;
30
+ if (objectType) for (const [name, fieldProp] of objectType.props) {
31
+ if (name === versionColumn) continue;
32
+ const isPK = fieldProp.metadata.has(require_annotation_keys.META_ID);
33
+ if (isPK) primaryKeys.push(name);
34
+ if (fieldProp.metadata.has("ui.dict.label")) labelField = name;
35
+ if (fieldProp.metadata.has("ui.dict.descr")) descrField = name;
36
+ if (fieldProp.metadata.has("ui.dict.attr")) attrFields.push(name);
37
+ if (!firstStringField && !isPK && fieldProp.type.kind === "" && fieldProp.type.designType === "string") firstStringField = name;
38
+ }
39
+ if (!labelField) labelField = firstStringField;
40
+ if (!labelField) labelField = primaryKeys[0] ?? "id";
41
+ const filterableFields = [];
42
+ const sortableFields = [];
43
+ if (meta.fields) for (const [name, fm] of Object.entries(meta.fields)) {
44
+ if (name === versionColumn) continue;
45
+ if (fm?.filterable) filterableFields.push(name);
46
+ if (fm?.sortable) sortableFields.push(name);
47
+ }
48
+ return {
49
+ url,
50
+ primaryKeys,
51
+ labelField,
52
+ descrField,
53
+ attrFields,
54
+ filterableFields,
55
+ sortableFields,
56
+ searchable: !!meta.searchable,
57
+ targetType
58
+ };
59
+ }
60
+ //#endregion
61
+ exports.resetValueHelpCache = resetValueHelpCache;
62
+ exports.resolveValueHelp = resolveValueHelp;
@@ -0,0 +1,31 @@
1
+ import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
2
+
3
+ //#region src/value-help/resolve.d.ts
4
+ /**
5
+ * Field-role + capability metadata for a value-help target, lazily resolved
6
+ * from the target's own `/meta` endpoint.
7
+ */
8
+ interface ResolvedValueHelp {
9
+ url: string;
10
+ primaryKeys: string[];
11
+ labelField: string;
12
+ descrField: string | undefined;
13
+ attrFields: string[];
14
+ filterableFields: string[];
15
+ sortableFields: string[];
16
+ searchable: boolean;
17
+ targetType: TAtscriptAnnotatedType;
18
+ }
19
+ /**
20
+ * Lazily fetch and extract value-help metadata for the given URL.
21
+ *
22
+ * - Issues exactly one `GET {url}/meta` per URL across the session (shared via meta-cache).
23
+ * - Concurrent callers with the same URL share the in-flight promise.
24
+ * - If the underlying fetch rejects, the cache entry is evicted so a later
25
+ * retry performs a fresh fetch.
26
+ */
27
+ declare function resolveValueHelp(url: string): Promise<ResolvedValueHelp>;
28
+ /** Thin alias over `resetMetaCache` — retained so existing test code keeps working. */
29
+ declare function resetValueHelpCache(): void;
30
+ //#endregion
31
+ export { ResolvedValueHelp, resetValueHelpCache, resolveValueHelp };
@@ -0,0 +1,31 @@
1
+ import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
2
+
3
+ //#region src/value-help/resolve.d.ts
4
+ /**
5
+ * Field-role + capability metadata for a value-help target, lazily resolved
6
+ * from the target's own `/meta` endpoint.
7
+ */
8
+ interface ResolvedValueHelp {
9
+ url: string;
10
+ primaryKeys: string[];
11
+ labelField: string;
12
+ descrField: string | undefined;
13
+ attrFields: string[];
14
+ filterableFields: string[];
15
+ sortableFields: string[];
16
+ searchable: boolean;
17
+ targetType: TAtscriptAnnotatedType;
18
+ }
19
+ /**
20
+ * Lazily fetch and extract value-help metadata for the given URL.
21
+ *
22
+ * - Issues exactly one `GET {url}/meta` per URL across the session (shared via meta-cache).
23
+ * - Concurrent callers with the same URL share the in-flight promise.
24
+ * - If the underlying fetch rejects, the cache entry is evicted so a later
25
+ * retry performs a fresh fetch.
26
+ */
27
+ declare function resolveValueHelp(url: string): Promise<ResolvedValueHelp>;
28
+ /** Thin alias over `resetMetaCache` — retained so existing test code keeps working. */
29
+ declare function resetValueHelpCache(): void;
30
+ //#endregion
31
+ export { ResolvedValueHelp, resetValueHelpCache, resolveValueHelp };
@@ -0,0 +1,61 @@
1
+ import { META_ID } from "../shared/annotation-keys.mjs";
2
+ import { getMetaEntry, resetMetaCache } from "../shared/meta-cache.mjs";
3
+ //#region src/value-help/resolve.ts
4
+ /**
5
+ * Lazily fetch and extract value-help metadata for the given URL.
6
+ *
7
+ * - Issues exactly one `GET {url}/meta` per URL across the session (shared via meta-cache).
8
+ * - Concurrent callers with the same URL share the in-flight promise.
9
+ * - If the underlying fetch rejects, the cache entry is evicted so a later
10
+ * retry performs a fresh fetch.
11
+ */
12
+ function resolveValueHelp(url) {
13
+ const entry = getMetaEntry(url);
14
+ if (entry.resolved) return entry.resolved;
15
+ entry.resolved = Promise.all([entry.meta, entry.type]).then(([meta, type]) => buildResolved(url, meta, type));
16
+ return entry.resolved;
17
+ }
18
+ /** Thin alias over `resetMetaCache` — retained so existing test code keeps working. */
19
+ function resetValueHelpCache() {
20
+ resetMetaCache();
21
+ }
22
+ function buildResolved(url, meta, targetType) {
23
+ const objectType = targetType.type.kind === "object" ? targetType.type : void 0;
24
+ const versionColumn = meta.versionColumn;
25
+ const primaryKeys = [];
26
+ let labelField;
27
+ let descrField;
28
+ const attrFields = [];
29
+ let firstStringField;
30
+ if (objectType) for (const [name, fieldProp] of objectType.props) {
31
+ if (name === versionColumn) continue;
32
+ const isPK = fieldProp.metadata.has(META_ID);
33
+ if (isPK) primaryKeys.push(name);
34
+ if (fieldProp.metadata.has("ui.dict.label")) labelField = name;
35
+ if (fieldProp.metadata.has("ui.dict.descr")) descrField = name;
36
+ if (fieldProp.metadata.has("ui.dict.attr")) attrFields.push(name);
37
+ if (!firstStringField && !isPK && fieldProp.type.kind === "" && fieldProp.type.designType === "string") firstStringField = name;
38
+ }
39
+ if (!labelField) labelField = firstStringField;
40
+ if (!labelField) labelField = primaryKeys[0] ?? "id";
41
+ const filterableFields = [];
42
+ const sortableFields = [];
43
+ if (meta.fields) for (const [name, fm] of Object.entries(meta.fields)) {
44
+ if (name === versionColumn) continue;
45
+ if (fm?.filterable) filterableFields.push(name);
46
+ if (fm?.sortable) sortableFields.push(name);
47
+ }
48
+ return {
49
+ url,
50
+ primaryKeys,
51
+ labelField,
52
+ descrField,
53
+ attrFields,
54
+ filterableFields,
55
+ sortableFields,
56
+ searchable: !!meta.searchable,
57
+ targetType
58
+ };
59
+ }
60
+ //#endregion
61
+ export { resetValueHelpCache, resolveValueHelp };
@@ -0,0 +1,36 @@
1
+ import { FilterExpr } from "@atscript/db-client";
2
+
3
+ //#region src/value-help/types.d.ts
4
+ /** An option for select/radio fields — either a plain string or a `{ key, label }` pair. */
5
+ type TFormEntryOptions = {
6
+ key: string;
7
+ label: string;
8
+ } | string;
9
+ /**
10
+ * Minimal sync probe output for a value-help–eligible prop.
11
+ *
12
+ * Emitted by `extractValueHelp(prop)` at def-construction time. Consumers use
13
+ * `url` to key the lazy resolver (`resolveValueHelp(url)`) that fetches the
14
+ * target's own `/meta` endpoint and returns the field-role details.
15
+ */
16
+ interface ValueHelpInfo {
17
+ /** HTTP path to the value-help target (from the target's `@db.http.path`). */
18
+ url: string;
19
+ /**
20
+ * Field on the target that this FK references (from `prop.ref.field`, e.g. "id").
21
+ * This is the value committed to the FK field when the user picks a row.
22
+ */
23
+ targetField: string;
24
+ /**
25
+ * Static dictionary scope from `@ui.valueHelp`'s filter — AND'd into every
26
+ * picker query. Since 0.1.148.
27
+ */
28
+ filter?: FilterExpr;
29
+ /**
30
+ * Target fields the filter pins with `=` — constant in the picker, hidden
31
+ * from its columns. Since 0.1.148.
32
+ */
33
+ pinned?: string[];
34
+ }
35
+ //#endregion
36
+ export { TFormEntryOptions, ValueHelpInfo };
@@ -0,0 +1,36 @@
1
+ import { FilterExpr } from "@atscript/db-client";
2
+
3
+ //#region src/value-help/types.d.ts
4
+ /** An option for select/radio fields — either a plain string or a `{ key, label }` pair. */
5
+ type TFormEntryOptions = {
6
+ key: string;
7
+ label: string;
8
+ } | string;
9
+ /**
10
+ * Minimal sync probe output for a value-help–eligible prop.
11
+ *
12
+ * Emitted by `extractValueHelp(prop)` at def-construction time. Consumers use
13
+ * `url` to key the lazy resolver (`resolveValueHelp(url)`) that fetches the
14
+ * target's own `/meta` endpoint and returns the field-role details.
15
+ */
16
+ interface ValueHelpInfo {
17
+ /** HTTP path to the value-help target (from the target's `@db.http.path`). */
18
+ url: string;
19
+ /**
20
+ * Field on the target that this FK references (from `prop.ref.field`, e.g. "id").
21
+ * This is the value committed to the FK field when the user picks a row.
22
+ */
23
+ targetField: string;
24
+ /**
25
+ * Static dictionary scope from `@ui.valueHelp`'s filter — AND'd into every
26
+ * picker query. Since 0.1.148.
27
+ */
28
+ filter?: FilterExpr;
29
+ /**
30
+ * Target fields the filter pins with `=` — constant in the picker, hidden
31
+ * from its columns. Since 0.1.148.
32
+ */
33
+ pinned?: string[];
34
+ }
35
+ //#endregion
36
+ export { TFormEntryOptions, ValueHelpInfo };
@@ -0,0 +1,136 @@
1
+ const require_str = require("../shared/str.cjs");
2
+ //#region src/value-help/value-help-client.ts
3
+ let cacheTtl = 5e3;
4
+ let searches = /* @__PURE__ */ new WeakMap();
5
+ /**
6
+ * How long (ms) a settled value-help search is reused for an identical
7
+ * search on the same client. Default 5000. `0` shares only searches still in
8
+ * flight; a negative value turns sharing off. Server-side rendering never
9
+ * shares (one process serves many viewers).
10
+ */
11
+ function setValueHelpCacheTtl(ms) {
12
+ cacheTtl = ms;
13
+ }
14
+ /**
15
+ * Drop shared value-help search results — for one `client`, or for every
16
+ * client when omitted. Call after writing to a dictionary outside the
17
+ * built-in table actions to make pickers refetch at once.
18
+ */
19
+ function invalidateValueHelpCache(client) {
20
+ if (client) searches.get(client)?.clear();
21
+ else searches = /* @__PURE__ */ new WeakMap();
22
+ }
23
+ function now() {
24
+ return typeof performance === "undefined" ? Date.now() : performance.now();
25
+ }
26
+ /** Cache key of a plain-JSON request; `undefined` when it holds anything else (never shared). */
27
+ function requestKey(request) {
28
+ let plain = true;
29
+ try {
30
+ const key = JSON.stringify(request, (_k, v) => {
31
+ if (typeof v === "function" || typeof v === "symbol") plain = false;
32
+ else if (v !== null && typeof v === "object" && !Array.isArray(v)) {
33
+ const proto = Object.getPrototypeOf(v);
34
+ if (proto !== Object.prototype && proto !== null) plain = false;
35
+ }
36
+ return v;
37
+ });
38
+ return plain ? key : void 0;
39
+ } catch {
40
+ return;
41
+ }
42
+ }
43
+ function sharedQuery(client, request) {
44
+ const run = () => client.query(request);
45
+ if (cacheTtl < 0 || typeof window === "undefined") return run();
46
+ const key = requestKey(request);
47
+ if (key === void 0) return run();
48
+ let byKey = searches.get(client);
49
+ if (!byKey) searches.set(client, byKey = /* @__PURE__ */ new Map());
50
+ const hit = byKey.get(key);
51
+ if (hit && (hit.settledAt === void 0 || now() - hit.settledAt < cacheTtl)) return hit.promise;
52
+ const entry = { promise: run().then((items) => {
53
+ entry.settledAt = now();
54
+ return items;
55
+ }, (err) => {
56
+ if (byKey.get(key) === entry) byKey.delete(key);
57
+ throw err;
58
+ }) };
59
+ byKey.set(key, entry);
60
+ return entry.promise;
61
+ }
62
+ /**
63
+ * Value-help query client. Wraps a `Client` from `@atscript/db-client`
64
+ * with FK-specific search logic (regex fallback for non-searchable tables,
65
+ * $select scoping).
66
+ *
67
+ * Consumers resolve the target's metadata once via `resolveValueHelp(url)`
68
+ * and pass the resulting `ResolvedValueHelp` to `search()`. Label resolution
69
+ * for cells is deliberately unsupported — cells always display raw ids.
70
+ *
71
+ * Identical searches on the same `Client` are shared (see
72
+ * {@link setValueHelpCacheTtl}).
73
+ */
74
+ var ValueHelpClient = class {
75
+ _client;
76
+ constructor(client) {
77
+ this._client = client;
78
+ }
79
+ /**
80
+ * Search the target with value-help semantics.
81
+ *
82
+ * - If target is searchable → sends `$search` (server full-text)
83
+ * - If not searchable → sends `$or` regex across select fields + exact PK match
84
+ */
85
+ async search(resolved, opts) {
86
+ const mode = opts?.mode ?? "form";
87
+ const limit = opts?.limit ?? 20;
88
+ const valueField = opts?.valueField;
89
+ const selectFields = opts?.select ?? computeSelectFields(resolved, mode, valueField);
90
+ const text = opts?.text;
91
+ const scope = opts?.filter;
92
+ const controls = {
93
+ $select: selectFields,
94
+ $limit: limit
95
+ };
96
+ let filter = scope;
97
+ if (text) if (resolved.searchable) controls.$search = text;
98
+ else {
99
+ const search = buildOrFilter(text, selectFields, valueField ?? resolved.primaryKeys[0] ?? resolved.labelField);
100
+ filter = scope ? { $and: [scope, search] } : search;
101
+ }
102
+ const items = await sharedQuery(this._client, {
103
+ ...filter && { filter },
104
+ controls
105
+ });
106
+ return { items: Array.isArray(items) ? items.slice() : items };
107
+ }
108
+ };
109
+ /**
110
+ * Compute the $select fields for a value-help query — always including the
111
+ * `valueField` the picker commits (a unique non-PK field is otherwise never fetched).
112
+ */
113
+ function computeSelectFields(resolved, mode, valueField) {
114
+ const fields = [...resolved.primaryKeys, resolved.labelField];
115
+ if (valueField) fields.push(valueField);
116
+ if (resolved.descrField) fields.push(resolved.descrField);
117
+ if (mode === "filter") fields.push(...resolved.attrFields);
118
+ return [...new Set(fields)];
119
+ }
120
+ /**
121
+ * Build a Uniquery `$or` filter for value-help search across multiple fields.
122
+ * Uses regex startsWith (case-insensitive) on text fields + exact match on PK.
123
+ */
124
+ function buildOrFilter(text, fields, pkField) {
125
+ const escaped = require_str.escapeRegex(text);
126
+ const conditions = [];
127
+ for (const field of fields) if (field !== pkField) conditions.push({ [field]: { $regex: `/^${escaped}/i` } });
128
+ const asNum = Number(text);
129
+ if (!Number.isNaN(asNum)) conditions.push({ [pkField]: asNum });
130
+ else conditions.push({ [pkField]: text });
131
+ return { $or: conditions };
132
+ }
133
+ //#endregion
134
+ exports.ValueHelpClient = ValueHelpClient;
135
+ exports.invalidateValueHelpCache = invalidateValueHelpCache;
136
+ exports.setValueHelpCacheTtl = setValueHelpCacheTtl;
@@ -0,0 +1,67 @@
1
+ import { ResolvedValueHelp } from "./resolve.cjs";
2
+ import { Client, FilterExpr } from "@atscript/db-client";
3
+
4
+ //#region src/value-help/value-help-client.d.ts
5
+ interface ValueHelpSearchOptions {
6
+ /** Search term. Empty or undefined returns all records. */
7
+ text?: string;
8
+ /** "form" = PK + label + descr; "filter" = all dict fields including attrs. Default: "form". */
9
+ mode?: "form" | "filter";
10
+ /** Max results. Default: 20. */
11
+ limit?: number;
12
+ /** Override the computed select fields. */
13
+ select?: string[];
14
+ /**
15
+ * Static dictionary scope (`ValueHelpInfo.filter`) — AND'd with the search
16
+ * filter and with `$search`. Since 0.1.148.
17
+ */
18
+ filter?: FilterExpr;
19
+ /**
20
+ * The target field the picker commits (`ValueHelpInfo.targetField`). It is
21
+ * selected, and it is the exact-match key of a non-searchable search — a
22
+ * composite-key dictionary's `primaryKeys[0]` is not the value. Default:
23
+ * `primaryKeys[0]`. Since 0.1.148.
24
+ */
25
+ valueField?: string;
26
+ }
27
+ interface ValueHelpResult {
28
+ items: Record<string, unknown>[];
29
+ }
30
+ /**
31
+ * How long (ms) a settled value-help search is reused for an identical
32
+ * search on the same client. Default 5000. `0` shares only searches still in
33
+ * flight; a negative value turns sharing off. Server-side rendering never
34
+ * shares (one process serves many viewers).
35
+ */
36
+ declare function setValueHelpCacheTtl(ms: number): void;
37
+ /**
38
+ * Drop shared value-help search results — for one `client`, or for every
39
+ * client when omitted. Call after writing to a dictionary outside the
40
+ * built-in table actions to make pickers refetch at once.
41
+ */
42
+ declare function invalidateValueHelpCache(client?: Client): void;
43
+ /**
44
+ * Value-help query client. Wraps a `Client` from `@atscript/db-client`
45
+ * with FK-specific search logic (regex fallback for non-searchable tables,
46
+ * $select scoping).
47
+ *
48
+ * Consumers resolve the target's metadata once via `resolveValueHelp(url)`
49
+ * and pass the resulting `ResolvedValueHelp` to `search()`. Label resolution
50
+ * for cells is deliberately unsupported — cells always display raw ids.
51
+ *
52
+ * Identical searches on the same `Client` are shared (see
53
+ * {@link setValueHelpCacheTtl}).
54
+ */
55
+ declare class ValueHelpClient {
56
+ private readonly _client;
57
+ constructor(client: Client);
58
+ /**
59
+ * Search the target with value-help semantics.
60
+ *
61
+ * - If target is searchable → sends `$search` (server full-text)
62
+ * - If not searchable → sends `$or` regex across select fields + exact PK match
63
+ */
64
+ search(resolved: ResolvedValueHelp, opts?: ValueHelpSearchOptions): Promise<ValueHelpResult>;
65
+ }
66
+ //#endregion
67
+ export { ValueHelpClient, ValueHelpResult, ValueHelpSearchOptions, invalidateValueHelpCache, setValueHelpCacheTtl };
@@ -0,0 +1,67 @@
1
+ import { ResolvedValueHelp } from "./resolve.mjs";
2
+ import { Client, FilterExpr } from "@atscript/db-client";
3
+
4
+ //#region src/value-help/value-help-client.d.ts
5
+ interface ValueHelpSearchOptions {
6
+ /** Search term. Empty or undefined returns all records. */
7
+ text?: string;
8
+ /** "form" = PK + label + descr; "filter" = all dict fields including attrs. Default: "form". */
9
+ mode?: "form" | "filter";
10
+ /** Max results. Default: 20. */
11
+ limit?: number;
12
+ /** Override the computed select fields. */
13
+ select?: string[];
14
+ /**
15
+ * Static dictionary scope (`ValueHelpInfo.filter`) — AND'd with the search
16
+ * filter and with `$search`. Since 0.1.148.
17
+ */
18
+ filter?: FilterExpr;
19
+ /**
20
+ * The target field the picker commits (`ValueHelpInfo.targetField`). It is
21
+ * selected, and it is the exact-match key of a non-searchable search — a
22
+ * composite-key dictionary's `primaryKeys[0]` is not the value. Default:
23
+ * `primaryKeys[0]`. Since 0.1.148.
24
+ */
25
+ valueField?: string;
26
+ }
27
+ interface ValueHelpResult {
28
+ items: Record<string, unknown>[];
29
+ }
30
+ /**
31
+ * How long (ms) a settled value-help search is reused for an identical
32
+ * search on the same client. Default 5000. `0` shares only searches still in
33
+ * flight; a negative value turns sharing off. Server-side rendering never
34
+ * shares (one process serves many viewers).
35
+ */
36
+ declare function setValueHelpCacheTtl(ms: number): void;
37
+ /**
38
+ * Drop shared value-help search results — for one `client`, or for every
39
+ * client when omitted. Call after writing to a dictionary outside the
40
+ * built-in table actions to make pickers refetch at once.
41
+ */
42
+ declare function invalidateValueHelpCache(client?: Client): void;
43
+ /**
44
+ * Value-help query client. Wraps a `Client` from `@atscript/db-client`
45
+ * with FK-specific search logic (regex fallback for non-searchable tables,
46
+ * $select scoping).
47
+ *
48
+ * Consumers resolve the target's metadata once via `resolveValueHelp(url)`
49
+ * and pass the resulting `ResolvedValueHelp` to `search()`. Label resolution
50
+ * for cells is deliberately unsupported — cells always display raw ids.
51
+ *
52
+ * Identical searches on the same `Client` are shared (see
53
+ * {@link setValueHelpCacheTtl}).
54
+ */
55
+ declare class ValueHelpClient {
56
+ private readonly _client;
57
+ constructor(client: Client);
58
+ /**
59
+ * Search the target with value-help semantics.
60
+ *
61
+ * - If target is searchable → sends `$search` (server full-text)
62
+ * - If not searchable → sends `$or` regex across select fields + exact PK match
63
+ */
64
+ search(resolved: ResolvedValueHelp, opts?: ValueHelpSearchOptions): Promise<ValueHelpResult>;
65
+ }
66
+ //#endregion
67
+ export { ValueHelpClient, ValueHelpResult, ValueHelpSearchOptions, invalidateValueHelpCache, setValueHelpCacheTtl };