@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,423 @@
1
+ import { getFieldsForType, getSiblingAnnotation, isInterface, isProp, isQueryComparison, isQueryLogical, isRef, isStructure } from "@atscript/core";
2
+ import { NOT_DIMENSION_REASON, forEachFieldRef, getAnnotationAlias, isAliasDecl, isDbSourceDecl, isStrictAggregateStruct, primitiveBaseType, validateExclusiveWith, validateQueryScope, validateRefArgument } from "@atscript/db/shared";
3
+ //#region src/plugin/value-help-validation.ts
4
+ /**
5
+ * Editor scopes + validators of `@ui.valueHelp`, `@ui.valueHelp.distinct` and
6
+ * `@ui.literalLabel` (since 0.1.148). Scopes and validators share one source,
7
+ * so a diagnostic and what the editor completes never diverge.
8
+ */
9
+ const WARNING = 2;
10
+ const ERROR = 1;
11
+ const MAX_DEPTH = 8;
12
+ /** The target type text (first argument) of the annotation the argument belongs to. */
13
+ function targetOf(arg) {
14
+ return getSiblingAnnotation(arg)?.args[0]?.text || void 0;
15
+ }
16
+ const valueHelpScopes = {
17
+ field: (arg) => {
18
+ const target = targetOf(arg);
19
+ return target ? {
20
+ allowedTypes: [],
21
+ unqualifiedTarget: target
22
+ } : void 0;
23
+ },
24
+ filter: (arg) => {
25
+ const target = targetOf(arg);
26
+ return target ? {
27
+ allowedTypes: [target],
28
+ unqualifiedTarget: target
29
+ } : void 0;
30
+ }
31
+ };
32
+ /** `refFilter` of the binding target: an interface that is not a `@db.alias`. */
33
+ function isValueHelpTarget(decl) {
34
+ return isInterface(decl) && !isAliasDecl(decl);
35
+ }
36
+ /**
37
+ * The one resolver behind {@link designOf} and {@link collectLiterals}: the leaf
38
+ * definitions of a type expression with refs, type aliases and unions unwound
39
+ * (an intersection is one leaf). `null` marks a branch that cannot be resolved,
40
+ * so the callers skip their check instead of guessing.
41
+ */
42
+ function leavesOf(def, doc, depth = 0) {
43
+ if (!def || depth > MAX_DEPTH) return [null];
44
+ switch (def.entity) {
45
+ case "ref": {
46
+ const ref = def;
47
+ const unwound = doc.unwindType(ref.id, ref.chain);
48
+ return unwound ? leavesOf(unwound.def, unwound.doc, depth + 1) : [null];
49
+ }
50
+ case "type": return leavesOf(def.getDefinition(), doc, depth + 1);
51
+ case "group": {
52
+ const group = def;
53
+ if (group.op === "&") return [{
54
+ def,
55
+ doc
56
+ }];
57
+ return group.unwrap().flatMap((item) => leavesOf(item, doc, depth + 1));
58
+ }
59
+ default: return [{
60
+ def,
61
+ doc
62
+ }];
63
+ }
64
+ }
65
+ function constDesign(def) {
66
+ const token = def.token("identifier");
67
+ if (token?.type === "text") return "string";
68
+ if (token?.type === "number") return "number";
69
+ if (token?.text === "true" || token?.text === "false") return "boolean";
70
+ return "other";
71
+ }
72
+ function leafDesign(def) {
73
+ switch (def.entity) {
74
+ case "primitive": {
75
+ const base = primitiveBaseType(def);
76
+ if (base === "string" || base === "number" || base === "decimal" || base === "boolean") return base;
77
+ if (base === "object") return "object";
78
+ if (base === "array" || base === "tuple") return "array";
79
+ return base ? "other" : void 0;
80
+ }
81
+ case "const": return constDesign(def);
82
+ case "structure":
83
+ case "interface":
84
+ case "group": return "object";
85
+ case "array":
86
+ case "tuple": return "array";
87
+ default: return;
88
+ }
89
+ }
90
+ /** A `null` / `undefined` / `void` leaf: it does not take part in a field's value kind. */
91
+ function isEmptyLeaf(def) {
92
+ if (def.entity !== "primitive") return false;
93
+ const base = primitiveBaseType(def);
94
+ return base === "null" || base === "void" || base === "undefined";
95
+ }
96
+ /** Design type of a resolved definition; `undefined` when it cannot be resolved (skip checks). */
97
+ function designOf(def, doc) {
98
+ const leaves = leavesOf(def, doc);
99
+ const present = leaves.filter((leaf) => !leaf || !isEmptyLeaf(leaf.def));
100
+ const kinds = new Set((present.length > 0 ? present : leaves).map((leaf) => leaf ? leafDesign(leaf.def) : void 0));
101
+ if (kinds.has(void 0)) return void 0;
102
+ return kinds.size === 1 ? [...kinds][0] : "other";
103
+ }
104
+ /**
105
+ * The definition an annotated node stands for, with the document that declares it: a prop /
106
+ * type declaration's definition, or — in an `annotate` block — the entry's target type.
107
+ */
108
+ function hostLeaves(node, doc) {
109
+ const host = doc.annotatedDefinition(node);
110
+ return host ? leavesOf(host.def, host.doc) : [null];
111
+ }
112
+ /** Whether a resolved leaf is a `number.timestamp` (any extension of it): the primitive's tags say so. */
113
+ function isTimestampLeaf(def) {
114
+ if (primitiveBaseType(def) !== "number") return false;
115
+ const tags = def.tags;
116
+ return !!tags && (tags.has("timestamp") || tags.has("created") || tags.has("updated"));
117
+ }
118
+ function hostDesign(token, doc) {
119
+ const host = doc.annotatedDefinition(token.parentNode);
120
+ return host ? designOf(host.def, host.doc) : void 0;
121
+ }
122
+ /** The values of a `boolean` host, as `@ui.literalLabel` names them. */
123
+ const BOOLEAN_VALUES = ["true", "false"];
124
+ /**
125
+ * Collects the values of a pure literal union or a `boolean` (`'true'` / `'false'`), or
126
+ * of an array of one; `null` / `undefined` members (`boolean | null`) have none. `false`
127
+ * when the host is anything else, `undefined` when it cannot be resolved.
128
+ */
129
+ function collectLiterals(def, doc, out, depth = 0) {
130
+ let unresolved = false;
131
+ const start = out.length;
132
+ for (const leaf of leavesOf(def, doc, depth)) if (!leaf) unresolved = true;
133
+ else if (leaf.def.entity === "const") {
134
+ const text = leaf.def.token("identifier")?.text;
135
+ if (text === void 0) return false;
136
+ out.push({
137
+ text,
138
+ def: leaf.def,
139
+ doc: leaf.doc
140
+ });
141
+ } else if (leaf.def.entity === "array") {
142
+ const ok = collectLiterals(leaf.def.getDefinition(), leaf.doc, out, depth + 1);
143
+ if (ok === false) return false;
144
+ if (ok === void 0) unresolved = true;
145
+ } else if (leaf.def.entity === "primitive" && primitiveBaseType(leaf.def) === "boolean") for (const text of BOOLEAN_VALUES) out.push({ text });
146
+ else if (!isEmptyLeaf(leaf.def)) return false;
147
+ if (unresolved) return void 0;
148
+ return out.length > start;
149
+ }
150
+ /** {@link collectLiterals} of the type an annotated node stands for. */
151
+ function collectHostLiterals(node, doc, out) {
152
+ const host = doc.annotatedDefinition(node);
153
+ return collectLiterals(host?.def, host?.doc ?? doc, out);
154
+ }
155
+ function resolveTarget(name, doc) {
156
+ const owner = doc.getDeclarationOwnerNode(name);
157
+ if (!owner?.node || !isInterface(owner.node)) return void 0;
158
+ const props = /* @__PURE__ */ new Map();
159
+ for (const prop of getFieldsForType(doc, name)) if (prop.id) props.set(prop.id, prop);
160
+ return {
161
+ doc: owner.doc,
162
+ decl: owner.node,
163
+ props
164
+ };
165
+ }
166
+ /**
167
+ * The annotated TARGET prop: the prop itself for an inline annotation, or — for an `annotate`
168
+ * entry — the prop of the target type the entry names. Its owning struct and declaration are
169
+ * resolved the same way as for an inline prop. `undefined` when the entry does not resolve.
170
+ */
171
+ function annotatedField(node, doc) {
172
+ if (!node) return void 0;
173
+ let prop = node;
174
+ let path = node.id ?? "";
175
+ if (isRef(node)) {
176
+ const idToken = node.token("identifier");
177
+ const block = idToken ? doc.annotateBlockAt(idToken.range.start.line, idToken.range.start.character) : void 0;
178
+ if (block) {
179
+ const chain = [node.id, ...node.chain.map((c) => c.text)];
180
+ path = chain.join(".");
181
+ prop = (doc.unwindType(block.targetName, chain.slice(0, -1))?.def)?.props?.get(chain.at(-1));
182
+ }
183
+ }
184
+ if (!prop || !isProp(prop)) return void 0;
185
+ let struct;
186
+ let up = prop.ownerNode;
187
+ while (up && !isInterface(up)) {
188
+ if (isStructure(up)) struct = up;
189
+ up = up.ownerNode;
190
+ }
191
+ const owner = up && isInterface(up) ? up : struct;
192
+ return {
193
+ prop,
194
+ path,
195
+ struct,
196
+ owner
197
+ };
198
+ }
199
+ function isNavigation(node) {
200
+ return !!node && (node.countAnnotations("db.rel.to") > 0 || node.countAnnotations("db.rel.from") > 0 || node.countAnnotations("db.rel.via") > 0);
201
+ }
202
+ /** Top-level conjuncts of a predicate (an `and` chain flattened). */
203
+ function conjuncts(expr) {
204
+ if (isQueryLogical(expr) && expr.operator === "and") return expr.operands.flatMap(conjuncts);
205
+ return [expr];
206
+ }
207
+ /**
208
+ * Fields the filter pins with a top-level `=` against a literal value. The
209
+ * compile-time twin of `pinnedOf` in `value-help/filter-tree.ts` (which reads the
210
+ * emitted tree at runtime) — keep the two rules in step.
211
+ */
212
+ function pinnedFields(filter) {
213
+ const pinned = /* @__PURE__ */ new Set();
214
+ const expr = filter?.queryNode?.expression;
215
+ if (!expr) return pinned;
216
+ for (const c of conjuncts(expr)) if (isQueryComparison(c) && c.operator === "=" && c.right && !("fieldRef" in c.right)) pinned.add(c.left.fieldRef.text);
217
+ return pinned;
218
+ }
219
+ function validateValueHelp(token, args, doc) {
220
+ const errors = [];
221
+ const [targetArg, fieldArg, filterArg] = args;
222
+ const host = token.parentNode;
223
+ const field = annotatedField(host, doc);
224
+ if (isNavigation(field?.prop ?? host)) errors.push({
225
+ message: "@ui.valueHelp is not valid on a navigation field — bind the foreign-key field",
226
+ severity: ERROR,
227
+ range: token.range
228
+ });
229
+ errors.push(...validateExclusiveWith(token, "@ui.valueHelp", [{ key: "ui.valueHelp.distinct" }], doc));
230
+ if (!targetArg) return errors;
231
+ const targetErrors = validateRefArgument(targetArg, doc, {
232
+ accept: isValueHelpTarget,
233
+ expected: "must be an interface — a value-help dictionary."
234
+ });
235
+ errors.push(...targetErrors);
236
+ if (targetErrors.length > 0) return errors;
237
+ const targetName = targetArg.text;
238
+ const target = resolveTarget(targetName, doc);
239
+ if (!target) return errors;
240
+ if (!isDbSourceDecl(target.decl) && target.decl.countAnnotations("db.http.path") === 0) errors.push({
241
+ message: `'${targetName}' is not a @db.table / @db.view and has no @db.http.path — the binding is ignored and the field falls back to its foreign key`,
242
+ severity: WARNING,
243
+ range: targetArg.range
244
+ });
245
+ const fieldName = fieldArg?.text;
246
+ let fieldDesign;
247
+ let fieldProp;
248
+ if (fieldArg && fieldName !== void 0) {
249
+ fieldProp = fieldName.includes(".") ? void 0 : target.props.get(fieldName);
250
+ if (!fieldProp) errors.push({
251
+ message: fieldName.includes(".") ? `Value-help field '${fieldName}' must be a top-level field of '${targetName}', not a dotted path` : `Field '${fieldName}' does not exist on '${targetName}'`,
252
+ severity: ERROR,
253
+ range: fieldArg.range
254
+ });
255
+ else {
256
+ fieldDesign = designOf(fieldProp.getDefinition(), target.doc);
257
+ if (fieldProp.countAnnotations("db.json") > 0 || fieldDesign === "object" || fieldDesign === "array") {
258
+ errors.push({
259
+ message: `Value-help field '${targetName}.${fieldName}' must be a scalar (not an object, array or @db.json)`,
260
+ severity: ERROR,
261
+ range: fieldArg.range
262
+ });
263
+ fieldDesign = void 0;
264
+ }
265
+ }
266
+ }
267
+ if (fieldDesign && fieldDesign !== "other") {
268
+ const hostType = hostDesign(token, doc);
269
+ if (hostType && hostType !== fieldDesign) errors.push({
270
+ message: `Value-help field '${targetName}.${fieldName}' is ${fieldDesign}, '${field?.path || host?.id || "this field"}' is ${hostType}`,
271
+ severity: ERROR,
272
+ range: token.range
273
+ });
274
+ }
275
+ const filterQuery = filterArg?.queryNode;
276
+ if (filterArg && filterQuery) {
277
+ errors.push(...validateQueryScope(filterArg, {
278
+ allowedTypes: [targetName],
279
+ unqualifiedTarget: targetName
280
+ }, doc));
281
+ for (const cmp of comparisons(filterQuery.expression)) if (cmp.right && "fieldRef" in cmp.right) errors.push({
282
+ message: "a value-help filter compares target fields with literal values",
283
+ severity: ERROR,
284
+ range: cmp.right.fieldRef.range
285
+ });
286
+ }
287
+ if (fieldProp && fieldName !== void 0) {
288
+ const idFields = [...target.props.entries()].filter(([, p]) => p.countAnnotations("meta.id") > 0);
289
+ let ok = fieldProp.countAnnotations("db.index.unique") > 0 || fieldProp.countAnnotations("meta.id") > 0 && idFields.length === 1;
290
+ if (!ok && fieldProp.countAnnotations("meta.id") > 0) {
291
+ const pinned = pinnedFields(filterArg);
292
+ ok = idFields.every(([name]) => name === fieldName || pinned.has(name));
293
+ }
294
+ if (!ok) errors.push({
295
+ message: `values may repeat in the picker — '${targetName}.${fieldName}' is not unique (a sole @meta.id, @db.index.unique, or a composite key member with the other members pinned by '=' in the filter)`,
296
+ severity: WARNING,
297
+ range: token.range
298
+ });
299
+ }
300
+ if (filterQuery && getAnnotationAlias(target.decl, "db.table.filterable") === "manual") {
301
+ const seen = /* @__PURE__ */ new Set();
302
+ forEachFieldRef(filterQuery.expression, (ref) => {
303
+ if (ref.typeRef && ref.typeRef.text !== targetName) return;
304
+ const name = ref.fieldRef.text;
305
+ if (seen.has(name)) return;
306
+ seen.add(name);
307
+ const prop = target.props.get(name.split(".")[0]);
308
+ if (prop && prop.countAnnotations("db.column.filterable") === 0) errors.push({
309
+ message: `the dictionary controller will reject this filter ('${name}' needs @db.column.filterable)`,
310
+ severity: WARNING,
311
+ range: ref.fieldRef.range
312
+ });
313
+ });
314
+ }
315
+ return errors;
316
+ }
317
+ /** Every comparison of a predicate, depth-first. */
318
+ function comparisons(expr) {
319
+ if (isQueryLogical(expr)) return expr.operands.flatMap(comparisons);
320
+ return isQueryComparison(expr) ? [expr] : [];
321
+ }
322
+ function validateDistinct(token, _args, doc) {
323
+ const errors = [];
324
+ const host = token.parentNode;
325
+ const design = hostDesign(token, doc);
326
+ if (hostLeaves(host, doc).some((leaf) => leaf && isTimestampLeaf(leaf.def))) errors.push({
327
+ message: "@ui.valueHelp.distinct requires a string or number field, got timestamp — a timestamp is not a value to pick from a list",
328
+ severity: ERROR,
329
+ range: token.range
330
+ });
331
+ else if (design && design !== "string" && design !== "number") errors.push({
332
+ message: `@ui.valueHelp.distinct requires a string or number field, got ${design}`,
333
+ severity: ERROR,
334
+ range: token.range
335
+ });
336
+ const field = annotatedField(host, doc);
337
+ const owner = field?.owner;
338
+ if (!owner || !field) return errors;
339
+ if (!isDbSourceDecl(owner)) {
340
+ errors.push({
341
+ message: "distinct values are served by a DB controller — declare this on a @db.table/@db.view",
342
+ severity: WARNING,
343
+ range: token.range
344
+ });
345
+ return errors;
346
+ }
347
+ const struct = field.struct;
348
+ if (struct && isStructure(struct) && field.prop.countAnnotations("db.column.dimension") === 0 && isStrictAggregateStruct(struct)) errors.push({
349
+ message: `$groupBy rejects this field of a strict aggregate table: ${NOT_DIMENSION_REASON} (add @db.column.dimension)`,
350
+ severity: WARNING,
351
+ range: token.range
352
+ });
353
+ return errors;
354
+ }
355
+ /**
356
+ * `valueScope` of `@ui.literalLabel`'s `value`: the literals of the annotated
357
+ * union (or array of one), each linked to the literal it declares — completion
358
+ * offers them and go-to-definition on the value jumps to the literal. A `boolean`
359
+ * host offers `'true'` / `'false'` (since 0.1.165).
360
+ */
361
+ function literalLabelValues(annotationToken, doc) {
362
+ const found = [];
363
+ if (collectHostLiterals(annotationToken.parentNode, doc, found) === false) return;
364
+ const seen = /* @__PURE__ */ new Set();
365
+ const candidates = [];
366
+ for (const { text, def, doc: declaring } of found) {
367
+ if (seen.has(text)) continue;
368
+ seen.add(text);
369
+ const token = def?.token("identifier");
370
+ candidates.push({
371
+ value: text,
372
+ ...token && declaring && { definition: {
373
+ doc: declaring,
374
+ token
375
+ } }
376
+ });
377
+ }
378
+ return candidates.length > 0 ? candidates : void 0;
379
+ }
380
+ function validateLiteralLabel(token, args, doc) {
381
+ const errors = [];
382
+ const host = token.parentNode;
383
+ const found = [];
384
+ const pure = collectHostLiterals(host, doc, found);
385
+ const literals = found.map((l) => l.text);
386
+ if (pure === false) {
387
+ errors.push({
388
+ message: "@ui.literalLabel requires a union of literal values or a boolean (or an array of one)",
389
+ severity: ERROR,
390
+ range: token.range
391
+ });
392
+ return errors;
393
+ }
394
+ const value = args[0];
395
+ if (!value) return errors;
396
+ if (pure === true && !literals.includes(value.text)) errors.push({
397
+ message: `'${value.text}' is not one of the literals: ${literals.map((l) => `'${l}'`).join(", ")}`,
398
+ severity: ERROR,
399
+ range: value.range
400
+ });
401
+ if ((host?.annotations ?? []).filter((a) => a.name === "ui.literalLabel" && a.args[0]?.text === value.text).findIndex((a) => a.token === token) > 0) errors.push({
402
+ message: `duplicate @ui.literalLabel for '${value.text}'`,
403
+ severity: ERROR,
404
+ range: value.range
405
+ });
406
+ return errors;
407
+ }
408
+ /**
409
+ * `@ui.form.type` / `@ui.type`: the free-entry `tags` renderer edits an array —
410
+ * on any other field it would mount with a scalar value.
411
+ */
412
+ function validateFormType(token, args, doc) {
413
+ if (args[0]?.text !== "tags") return [];
414
+ const design = hostDesign(token, doc);
415
+ if (design === void 0 || design === "array") return [];
416
+ return [{
417
+ message: `'tags' requires an array field (e.g. string[]), got ${design}`,
418
+ severity: ERROR,
419
+ range: args[0].range
420
+ }];
421
+ }
422
+ //#endregion
423
+ export { isValueHelpTarget, literalLabelValues, validateDistinct, validateFormType, validateLiteralLabel, validateValueHelp, valueHelpScopes };