@atscript/ui 0.1.189 → 0.1.190

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 (60) hide show
  1. package/dist/client-factory.d.cts +9 -7
  2. package/dist/client-factory.d.mts +9 -7
  3. package/dist/form/create-form-def.cjs +38 -1
  4. package/dist/form/create-form-def.d.cts +1 -1
  5. package/dist/form/create-form-def.d.mts +1 -1
  6. package/dist/form/create-form-def.mjs +38 -1
  7. package/dist/form/diff.cjs +8 -1
  8. package/dist/form/diff.d.cts +5 -2
  9. package/dist/form/diff.d.mts +5 -2
  10. package/dist/form/diff.mjs +9 -2
  11. package/dist/form/skipped-nav.cjs +1 -1
  12. package/dist/form/skipped-nav.mjs +1 -1
  13. package/dist/index.cjs +11 -0
  14. package/dist/index.d.cts +7 -4
  15. package/dist/index.d.mts +7 -4
  16. package/dist/index.mjs +6 -3
  17. package/dist/messages.cjs +3 -0
  18. package/dist/messages.d.cts +3 -0
  19. package/dist/messages.d.mts +3 -0
  20. package/dist/messages.mjs +3 -0
  21. package/dist/plugin/annotations.cjs +57 -2
  22. package/dist/plugin/annotations.mjs +58 -3
  23. package/dist/plugin/value-help-validation.cjs +358 -24
  24. package/dist/plugin/value-help-validation.mjs +356 -26
  25. package/dist/shared/annotation-keys.cjs +11 -0
  26. package/dist/shared/annotation-keys.d.cts +3 -1
  27. package/dist/shared/annotation-keys.d.mts +3 -1
  28. package/dist/shared/annotation-keys.mjs +8 -1
  29. package/dist/shared/meta-cache.d.cts +3 -3
  30. package/dist/shared/meta-cache.d.mts +3 -3
  31. package/dist/shared/value-label.cjs +28 -0
  32. package/dist/shared/value-label.d.cts +25 -0
  33. package/dist/shared/value-label.d.mts +25 -0
  34. package/dist/shared/value-label.mjs +27 -0
  35. package/dist/table/create-table-def.cjs +15 -1
  36. package/dist/table/create-table-def.mjs +15 -1
  37. package/dist/table/types.d.cts +31 -9
  38. package/dist/table/types.d.mts +31 -9
  39. package/dist/value-help/distinct-client.d.cts +2 -2
  40. package/dist/value-help/distinct-client.d.mts +2 -2
  41. package/dist/value-help/extract-ref.cjs +22 -5
  42. package/dist/value-help/extract-ref.mjs +23 -6
  43. package/dist/value-help/filter-tree.cjs +39 -14
  44. package/dist/value-help/filter-tree.mjs +39 -14
  45. package/dist/value-help/index.d.mts +3 -1
  46. package/dist/value-help/options.cjs +30 -0
  47. package/dist/value-help/options.d.cts +19 -0
  48. package/dist/value-help/options.d.mts +19 -0
  49. package/dist/value-help/options.mjs +29 -0
  50. package/dist/value-help/scope.cjs +50 -0
  51. package/dist/value-help/scope.d.cts +32 -0
  52. package/dist/value-help/scope.d.mts +32 -0
  53. package/dist/value-help/scope.mjs +49 -0
  54. package/dist/value-help/types.d.cts +29 -1
  55. package/dist/value-help/types.d.mts +29 -1
  56. package/dist/value-help/value-help-client.cjs +23 -4
  57. package/dist/value-help/value-help-client.d.cts +27 -8
  58. package/dist/value-help/value-help-client.d.mts +27 -8
  59. package/dist/value-help/value-help-client.mjs +23 -5
  60. package/package.json +9 -9
@@ -52,6 +52,7 @@ const ROW_SPAN_VALUES = [
52
52
  * - `ui.table.<key>` — table-only static
53
53
  * - `ui.dict.<key>` — value-help annotations
54
54
  * - `ui.valueHelp`, `ui.literalLabel` — dictionary binding, union literal labels
55
+ * - `ui.valueLabel` — a code shown with the text of a sibling field
55
56
  * - `ui.nav.<key>` — model-level navigation annotations
56
57
  * - `ui.array.<key>` — array control annotations
57
58
  *
@@ -453,7 +454,7 @@ const uiAnnotations = { ui: {
453
454
  },
454
455
  valueHelp: {
455
456
  $self: new _atscript_core.AnnotationSpec({
456
- description: "Binds this field to a value-help dictionary **without a foreign key** — no constraint, no query semantics, presentation only. Filter pickers (table filter dialog / inline field) and form reference pickers search the target's controller and commit the target's `field`. The binding wins over a `@db.rel.FK` on the field or its chain, and travels through chain refs and `extends`. The optional `filter` is a static scope AND'd into every picker query; fields it pins with `=` are hidden from the picker columns.\n\n**Example:**\n```atscript\n@ui.valueHelp AttributeValue, 'value', `attribute = 'color'`\ncolor: Ticket.color\n```\n",
457
+ description: "Binds this field to a value-help dictionary **without a foreign key** — no constraint, no query semantics, presentation only. Filter pickers (table filter dialog / inline field) and form reference pickers search the target's controller and commit the target's `field`. The binding wins over a `@db.rel.FK` on the field or its chain, and travels through chain refs and `extends`. The optional `filter` is a scope AND'd into every picker query; fields it pins with `=` are hidden from the picker columns. In a form, `targetField = Host.field` (`Host`: the interface declaring this field) narrows the picker by the value of another field of the form; while that field is empty the condition is left out. Table filters ignore such conditions.\n\n**Example:**\n```atscript\n@ui.valueHelp AttributeValue, 'value', `attribute = 'color'`\ncolor: Ticket.color\n\n@ui.valueHelp City, 'id', `country = Customer.country and active = true`\ncity?: string\n```\n",
457
458
  nodeType: ["prop", "type"],
458
459
  multiple: false,
459
460
  argument: [
@@ -473,12 +474,44 @@ const uiAnnotations = { ui: {
473
474
  optional: true,
474
475
  name: "filter",
475
476
  type: "query",
476
- description: "Static scope on the target (`attribute = 'color' and active = true`) — field-to-value comparisons of the target's fields only.",
477
+ description: "Scope on the target (`attribute = 'color' and active = true`): comparisons of the target's fields with literal values, and — top-level `and` conditions only — `targetField = Host.field`, which narrows the picker of a form by the value of another field of the host interface (left out while that field is empty).",
477
478
  fieldScope: require_value_help_validation.valueHelpScopes.filter
478
479
  }
479
480
  ],
480
481
  validate: require_value_help_validation.validateValueHelp
481
482
  }),
483
+ fill: new _atscript_core.AnnotationSpec({
484
+ description: "A pick also fills another field of the form: writes the picked row's `targetField` into the sibling `local`, as an edit would. Repeat per field. Applies to the field's own binding (`@ui.valueHelp`, else `@db.rel.FK`) in forms only; a derived, read-only or navigation sibling is skipped. The clear button clears a filled field again while it still holds what the last pick wrote. Not passed through references.\n\n**Example:**\n```atscript\n@ui.valueHelp City, 'id'\n@ui.valueHelp.fill 'cityName', 'name'\ncity?: string\ncityName?: string\n```\n",
485
+ nodeType: ["prop"],
486
+ multiple: true,
487
+ mergeStrategy: "replace",
488
+ passedWhenReferred: false,
489
+ argument: [{
490
+ name: "local",
491
+ type: "string",
492
+ description: "A top-level scalar field of this interface that the pick writes — not this field.",
493
+ fieldScope: require_value_help_validation.valueHelpScopes.hostField
494
+ }, {
495
+ name: "targetField",
496
+ type: "string",
497
+ description: "A top-level scalar field of the dictionary whose value is written; same type as `local`.",
498
+ fieldScope: require_value_help_validation.valueHelpScopes.bindingField
499
+ }],
500
+ validate: require_value_help_validation.validateFill
501
+ }),
502
+ column: new _atscript_core.AnnotationSpec({
503
+ description: "A column of this binding's picker dialogs: they show exactly these dictionary fields, in order, instead of the dictionary's key / label / description view. Repeat per column. The combobox and the dropdown keep key, label and description.\n\n**Example:**\n```atscript\n@ui.valueHelp City, 'id'\n@ui.valueHelp.column 'id'\n@ui.valueHelp.column 'name'\n@ui.valueHelp.column 'region'\ncity?: string\n```\n",
504
+ nodeType: ["prop"],
505
+ multiple: true,
506
+ mergeStrategy: "replace",
507
+ argument: {
508
+ name: "field",
509
+ type: "string",
510
+ description: "A top-level scalar field of the dictionary shown as a column.",
511
+ fieldScope: require_value_help_validation.valueHelpScopes.bindingField
512
+ },
513
+ validate: require_value_help_validation.validateColumn
514
+ }),
482
515
  distinct: new _atscript_core.AnnotationSpec({
483
516
  description: "Offers a **distinct-values picker** for this column in table filters: the values already stored, read from the table's own controller via `$groupBy`. Shown only when the server reports the field filterable and groupable, and the field has no dictionary binding, FK help or literal options. Not offered in forms.\n\n**Example:**\n```atscript\n@ui.valueHelp.distinct\ncity?: string\n```\n",
484
517
  nodeType: ["prop", "type"],
@@ -503,6 +536,28 @@ const uiAnnotations = { ui: {
503
536
  }],
504
537
  validate: require_value_help_validation.validateLiteralLabel
505
538
  }),
539
+ valueLabel: new _atscript_core.AnnotationSpec({
540
+ description: "Shows this field's value — a code — together with its text, read from a string field of the same interface: in table cells, export, read-only form fields and the reference field while it is not focused. Sorting and filtering stay on the code, and filter chips show the code. On a field with a value-help binding, let the pick fill the text (`@ui.valueHelp.fill`), or it goes stale after a pick. Not passed through references.\n\n**Example:**\n```atscript\n@ui.valueHelp City, 'code'\n@ui.valueHelp.fill 'cityName', 'name'\n@ui.valueLabel 'cityName'\ncity?: string\ncityName?: string\n```\n",
541
+ nodeType: ["prop"],
542
+ passedWhenReferred: false,
543
+ argument: [{
544
+ name: "field",
545
+ type: "string",
546
+ description: "A string field of this interface holding the text of this field's value — not this field.",
547
+ valueScope: require_value_help_validation.valueLabelFields
548
+ }, {
549
+ optional: true,
550
+ name: "arrangement",
551
+ type: "string",
552
+ description: "How the code and its text are shown: `textKey` (default) — `Berlin (BER)`; `keyText` — `BER (Berlin)`; `text` — `Berlin`. An empty text shows the code alone.",
553
+ values: [
554
+ "textKey",
555
+ "keyText",
556
+ "text"
557
+ ]
558
+ }],
559
+ validate: require_value_help_validation.validateValueLabel
560
+ }),
506
561
  dict: {
507
562
  label: new _atscript_core.AnnotationSpec({
508
563
  description: "Marks this field as the primary display label when the table is used as a value-help dictionary",
@@ -1,4 +1,4 @@
1
- import { isValueHelpTarget, literalLabelValues, validateDistinct, validateFormType, validateLiteralLabel, validateValueHelp, valueHelpScopes } from "./value-help-validation.mjs";
1
+ import { isValueHelpTarget, literalLabelValues, validateColumn, validateDistinct, validateFill, validateFormType, validateLiteralLabel, validateValueHelp, validateValueLabel, valueHelpScopes, valueLabelFields } from "./value-help-validation.mjs";
2
2
  import { AnnotationSpec } from "@atscript/core";
3
3
  //#region src/plugin/annotations.ts
4
4
  const BUILTIN_TYPES = [
@@ -52,6 +52,7 @@ const ROW_SPAN_VALUES = [
52
52
  * - `ui.table.<key>` — table-only static
53
53
  * - `ui.dict.<key>` — value-help annotations
54
54
  * - `ui.valueHelp`, `ui.literalLabel` — dictionary binding, union literal labels
55
+ * - `ui.valueLabel` — a code shown with the text of a sibling field
55
56
  * - `ui.nav.<key>` — model-level navigation annotations
56
57
  * - `ui.array.<key>` — array control annotations
57
58
  *
@@ -453,7 +454,7 @@ const uiAnnotations = { ui: {
453
454
  },
454
455
  valueHelp: {
455
456
  $self: new AnnotationSpec({
456
- description: "Binds this field to a value-help dictionary **without a foreign key** — no constraint, no query semantics, presentation only. Filter pickers (table filter dialog / inline field) and form reference pickers search the target's controller and commit the target's `field`. The binding wins over a `@db.rel.FK` on the field or its chain, and travels through chain refs and `extends`. The optional `filter` is a static scope AND'd into every picker query; fields it pins with `=` are hidden from the picker columns.\n\n**Example:**\n```atscript\n@ui.valueHelp AttributeValue, 'value', `attribute = 'color'`\ncolor: Ticket.color\n```\n",
457
+ description: "Binds this field to a value-help dictionary **without a foreign key** — no constraint, no query semantics, presentation only. Filter pickers (table filter dialog / inline field) and form reference pickers search the target's controller and commit the target's `field`. The binding wins over a `@db.rel.FK` on the field or its chain, and travels through chain refs and `extends`. The optional `filter` is a scope AND'd into every picker query; fields it pins with `=` are hidden from the picker columns. In a form, `targetField = Host.field` (`Host`: the interface declaring this field) narrows the picker by the value of another field of the form; while that field is empty the condition is left out. Table filters ignore such conditions.\n\n**Example:**\n```atscript\n@ui.valueHelp AttributeValue, 'value', `attribute = 'color'`\ncolor: Ticket.color\n\n@ui.valueHelp City, 'id', `country = Customer.country and active = true`\ncity?: string\n```\n",
457
458
  nodeType: ["prop", "type"],
458
459
  multiple: false,
459
460
  argument: [
@@ -473,12 +474,44 @@ const uiAnnotations = { ui: {
473
474
  optional: true,
474
475
  name: "filter",
475
476
  type: "query",
476
- description: "Static scope on the target (`attribute = 'color' and active = true`) — field-to-value comparisons of the target's fields only.",
477
+ description: "Scope on the target (`attribute = 'color' and active = true`): comparisons of the target's fields with literal values, and — top-level `and` conditions only — `targetField = Host.field`, which narrows the picker of a form by the value of another field of the host interface (left out while that field is empty).",
477
478
  fieldScope: valueHelpScopes.filter
478
479
  }
479
480
  ],
480
481
  validate: validateValueHelp
481
482
  }),
483
+ fill: new AnnotationSpec({
484
+ description: "A pick also fills another field of the form: writes the picked row's `targetField` into the sibling `local`, as an edit would. Repeat per field. Applies to the field's own binding (`@ui.valueHelp`, else `@db.rel.FK`) in forms only; a derived, read-only or navigation sibling is skipped. The clear button clears a filled field again while it still holds what the last pick wrote. Not passed through references.\n\n**Example:**\n```atscript\n@ui.valueHelp City, 'id'\n@ui.valueHelp.fill 'cityName', 'name'\ncity?: string\ncityName?: string\n```\n",
485
+ nodeType: ["prop"],
486
+ multiple: true,
487
+ mergeStrategy: "replace",
488
+ passedWhenReferred: false,
489
+ argument: [{
490
+ name: "local",
491
+ type: "string",
492
+ description: "A top-level scalar field of this interface that the pick writes — not this field.",
493
+ fieldScope: valueHelpScopes.hostField
494
+ }, {
495
+ name: "targetField",
496
+ type: "string",
497
+ description: "A top-level scalar field of the dictionary whose value is written; same type as `local`.",
498
+ fieldScope: valueHelpScopes.bindingField
499
+ }],
500
+ validate: validateFill
501
+ }),
502
+ column: new AnnotationSpec({
503
+ description: "A column of this binding's picker dialogs: they show exactly these dictionary fields, in order, instead of the dictionary's key / label / description view. Repeat per column. The combobox and the dropdown keep key, label and description.\n\n**Example:**\n```atscript\n@ui.valueHelp City, 'id'\n@ui.valueHelp.column 'id'\n@ui.valueHelp.column 'name'\n@ui.valueHelp.column 'region'\ncity?: string\n```\n",
504
+ nodeType: ["prop"],
505
+ multiple: true,
506
+ mergeStrategy: "replace",
507
+ argument: {
508
+ name: "field",
509
+ type: "string",
510
+ description: "A top-level scalar field of the dictionary shown as a column.",
511
+ fieldScope: valueHelpScopes.bindingField
512
+ },
513
+ validate: validateColumn
514
+ }),
482
515
  distinct: new AnnotationSpec({
483
516
  description: "Offers a **distinct-values picker** for this column in table filters: the values already stored, read from the table's own controller via `$groupBy`. Shown only when the server reports the field filterable and groupable, and the field has no dictionary binding, FK help or literal options. Not offered in forms.\n\n**Example:**\n```atscript\n@ui.valueHelp.distinct\ncity?: string\n```\n",
484
517
  nodeType: ["prop", "type"],
@@ -503,6 +536,28 @@ const uiAnnotations = { ui: {
503
536
  }],
504
537
  validate: validateLiteralLabel
505
538
  }),
539
+ valueLabel: new AnnotationSpec({
540
+ description: "Shows this field's value — a code — together with its text, read from a string field of the same interface: in table cells, export, read-only form fields and the reference field while it is not focused. Sorting and filtering stay on the code, and filter chips show the code. On a field with a value-help binding, let the pick fill the text (`@ui.valueHelp.fill`), or it goes stale after a pick. Not passed through references.\n\n**Example:**\n```atscript\n@ui.valueHelp City, 'code'\n@ui.valueHelp.fill 'cityName', 'name'\n@ui.valueLabel 'cityName'\ncity?: string\ncityName?: string\n```\n",
541
+ nodeType: ["prop"],
542
+ passedWhenReferred: false,
543
+ argument: [{
544
+ name: "field",
545
+ type: "string",
546
+ description: "A string field of this interface holding the text of this field's value — not this field.",
547
+ valueScope: valueLabelFields
548
+ }, {
549
+ optional: true,
550
+ name: "arrangement",
551
+ type: "string",
552
+ description: "How the code and its text are shown: `textKey` (default) — `Berlin (BER)`; `keyText` — `BER (Berlin)`; `text` — `Berlin`. An empty text shows the code alone.",
553
+ values: [
554
+ "textKey",
555
+ "keyText",
556
+ "text"
557
+ ]
558
+ }],
559
+ validate: validateValueLabel
560
+ }),
506
561
  dict: {
507
562
  label: new AnnotationSpec({
508
563
  description: "Marks this field as the primary display label when the table is used as a value-help dictionary",
@@ -3,7 +3,9 @@ let _atscript_db_shared = require("@atscript/db/shared");
3
3
  //#region src/plugin/value-help-validation.ts
4
4
  /**
5
5
  * Editor scopes + validators of `@ui.valueHelp`, `@ui.valueHelp.distinct` and
6
- * `@ui.literalLabel` (since 0.1.148). Scopes and validators share one source,
6
+ * `@ui.literalLabel` (since 0.1.148), and of `@ui.valueHelp.fill`,
7
+ * `@ui.valueHelp.column`, host references in a binding filter and
8
+ * `@ui.valueLabel` (since 0.1.190). Scopes and validators share one source,
7
9
  * so a diagnostic and what the editor completes never diverge.
8
10
  */
9
11
  const WARNING = 2;
@@ -21,11 +23,27 @@ const valueHelpScopes = {
21
23
  unqualifiedTarget: target
22
24
  } : void 0;
23
25
  },
24
- filter: (arg) => {
26
+ filter: (arg, doc) => {
25
27
  const target = targetOf(arg);
26
- return target ? {
27
- allowedTypes: [target],
28
+ if (!target) return void 0;
29
+ const host = hostOf(arg, doc);
30
+ return {
31
+ allowedTypes: typeof host === "object" && host.name !== target ? [target, host.name] : [target],
28
32
  unqualifiedTarget: target
33
+ };
34
+ },
35
+ hostField: (arg, doc) => {
36
+ const host = hostOf(arg, doc);
37
+ return typeof host === "object" ? {
38
+ allowedTypes: [],
39
+ unqualifiedTarget: host.name
40
+ } : void 0;
41
+ },
42
+ bindingField: (arg, doc) => {
43
+ const binding = bindingOf((0, _atscript_db_shared.annotationTarget)(arg, doc), doc);
44
+ return binding ? {
45
+ allowedTypes: [],
46
+ unqualifiedTarget: binding.name
29
47
  } : void 0;
30
48
  }
31
49
  };
@@ -196,32 +214,139 @@ function annotatedField(node, doc) {
196
214
  owner
197
215
  };
198
216
  }
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
217
  /** Top-level conjuncts of a predicate (an `and` chain flattened). */
203
218
  function conjuncts(expr) {
204
219
  if ((0, _atscript_core.isQueryLogical)(expr) && expr.operator === "and") return expr.operands.flatMap(conjuncts);
205
220
  return [expr];
206
221
  }
222
+ /** The right-hand field reference of a comparison, if it compares two fields. */
223
+ function rightRef(cmp) {
224
+ return cmp.right && "fieldRef" in cmp.right ? cmp.right : void 0;
225
+ }
207
226
  /**
208
227
  * 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.
228
+ * compile-time twin of `pinnedOf` in `value-help/filter-tree.ts` (which reads
229
+ * the emitted tree at runtime) — keep the two rules in step.
211
230
  */
212
231
  function pinnedFields(filter) {
213
232
  const pinned = /* @__PURE__ */ new Set();
214
233
  const expr = filter?.queryNode?.expression;
215
234
  if (!expr) return pinned;
216
- for (const c of conjuncts(expr)) if ((0, _atscript_core.isQueryComparison)(c) && c.operator === "=" && c.right && !("fieldRef" in c.right)) pinned.add(c.left.fieldRef.text);
235
+ for (const c of conjuncts(expr)) {
236
+ if (!(0, _atscript_core.isQueryComparison)(c) || c.operator !== "=" || !c.right) continue;
237
+ if (!rightRef(c)) pinned.add(c.left.fieldRef.text);
238
+ }
217
239
  return pinned;
218
240
  }
241
+ /**
242
+ * The target fields the filter's host references pin (`targetField =
243
+ * Host.field`), each with its host field — pinned only while that host field
244
+ * has a value.
245
+ */
246
+ function hostPins(filter, hostName) {
247
+ const pins = /* @__PURE__ */ new Map();
248
+ const expr = filter?.queryNode?.expression;
249
+ if (!expr) return pins;
250
+ for (const c of conjuncts(expr)) {
251
+ if (!(0, _atscript_core.isQueryComparison)(c) || c.operator !== "=") continue;
252
+ const ref = rightRef(c);
253
+ if (ref?.typeRef?.text === hostName) pins.set(c.left.fieldRef.text, ref.fieldRef.text);
254
+ }
255
+ return pins;
256
+ }
257
+ /**
258
+ * The {@link THost} of the field the annotation (or argument) `token` sits
259
+ * on; `undefined` when it sits on no field (a type-level binding, an entry
260
+ * that lands nowhere).
261
+ */
262
+ function hostOf(token, doc) {
263
+ const node = token.parentNode;
264
+ if (!node) return void 0;
265
+ if ((0, _atscript_core.isRef)(node)) {
266
+ const at = node.token("identifier")?.range.start;
267
+ const block = at ? doc.annotateBlockAt(at.line, at.character) : void 0;
268
+ if (!block) return void 0;
269
+ if (!block.isMutating) return "copy";
270
+ if (node.hasChain) return "inline";
271
+ const field = (0, _atscript_db_shared.annotationTarget)(token, doc);
272
+ const fields = (0, _atscript_db_shared.getTypeFields)(field?.ownerNode, doc);
273
+ return field && fields ? {
274
+ name: block.targetName,
275
+ fields,
276
+ field
277
+ } : void 0;
278
+ }
279
+ if (!(0, _atscript_core.isProp)(node)) return void 0;
280
+ const iface = node.ownerNode?.ownerNode;
281
+ if (!(0, _atscript_core.isStructure)(node.ownerNode) || !iface || !(0, _atscript_core.isInterface)(iface)) return "inline";
282
+ const fields = (0, _atscript_db_shared.getTypeFields)(iface, doc);
283
+ return fields && iface.id ? {
284
+ name: iface.id,
285
+ fields,
286
+ field: node
287
+ } : void 0;
288
+ }
289
+ const REFUSED = {
290
+ inline: "a top-level field of an interface, not a field of an inline structure, a type or a nested annotate entry",
291
+ copy: "a field of an interface or of a mutating annotate block, not of an `annotate … as` copy"
292
+ };
293
+ /**
294
+ * The binding a field's fills and columns belong to: its own `@ui.valueHelp`
295
+ * (for an `annotate` entry's field, the landed one — the entry's wins), else its
296
+ * own `@db.rel.FK` help. A binding the field only gets through its type or a
297
+ * chain reference takes no fills or columns.
298
+ */
299
+ function bindingOf(field, doc) {
300
+ if (!field) return void 0;
301
+ const own = field.annotations?.find((a) => a.name === "ui.valueHelp");
302
+ if (own) {
303
+ const name = own.args[0]?.text;
304
+ return name ? {
305
+ name,
306
+ target: resolveTarget(name, doc)
307
+ } : void 0;
308
+ }
309
+ if (field.countAnnotations("db.rel.FK") > 0) {
310
+ const ref = (0, _atscript_db_shared.fkChainRef)(field.getDefinition());
311
+ if (ref?.id) return {
312
+ name: ref.id,
313
+ target: resolveTarget(ref.id, doc.refOrigin(ref))
314
+ };
315
+ }
316
+ }
317
+ const SCALAR = "a scalar (not an object, an array, a navigation or @db.json)";
318
+ /** Whether a field holds no scalar: an object, an array, `@db.json` or a navigation. */
319
+ function isNotScalar(prop, doc) {
320
+ if (prop.countAnnotations("db.json") > 0 || (0, _atscript_db_shared.isNavProp)(prop)) return true;
321
+ const design = designOf(prop.getDefinition(), doc.declaringDoc(prop, doc));
322
+ return design === "object" || design === "array";
323
+ }
324
+ /** FL3 / CL2: why `name` is no top-level scalar field of the binding's target. */
325
+ function targetFieldProblem(binding, name) {
326
+ if (name.includes(".")) return `'${name}' must be a top-level field of '${binding.name}', not a dotted path`;
327
+ const target = binding.target;
328
+ if (!target) return void 0;
329
+ const prop = target.props.get(name);
330
+ if (!prop) return `Field '${name}' does not exist on '${binding.name}'`;
331
+ if (isNotScalar(prop, target.doc)) return `'${binding.name}.${name}' must be ${SCALAR}`;
332
+ }
333
+ /** FL4 / VH9: why the host field `local` cannot take the target field `name`'s values. */
334
+ function designMismatch(host, local, binding, name, doc) {
335
+ const localProp = host.fields.get(local);
336
+ const targetProp = binding.target?.props.get(name);
337
+ if (!localProp || !targetProp || !binding.target) return void 0;
338
+ const a = designOf(targetProp.getDefinition(), binding.target.doc);
339
+ const b = designOf(localProp.getDefinition(), doc.declaringDoc(localProp, doc));
340
+ if (!a || !b || a === "other" || b === "other" || a === b) return void 0;
341
+ return `'${binding.name}.${name}' is ${a}, '${host.name}.${local}' is ${b}`;
342
+ }
219
343
  function validateValueHelp(token, args, doc) {
220
344
  const errors = [];
221
345
  const [targetArg, fieldArg, filterArg] = args;
222
346
  const host = token.parentNode;
223
347
  const field = annotatedField(host, doc);
224
- if (isNavigation(field?.prop ?? host)) errors.push({
348
+ const navNode = field?.prop ?? host;
349
+ if (navNode && (0, _atscript_db_shared.isNavProp)(navNode)) errors.push({
225
350
  message: "@ui.valueHelp is not valid on a navigation field — bind the foreign-key field",
226
351
  severity: ERROR,
227
352
  range: token.range
@@ -273,36 +398,51 @@ function validateValueHelp(token, args, doc) {
273
398
  });
274
399
  }
275
400
  const filterQuery = filterArg?.queryNode;
401
+ const formHost = hostOf(token, doc);
402
+ const validHost = typeof formHost === "object" ? formHost : void 0;
276
403
  if (filterArg && filterQuery) {
277
404
  errors.push(...(0, _atscript_db_shared.validateQueryScope)(filterArg, {
278
- allowedTypes: [targetName],
405
+ allowedTypes: validHost && validHost.name !== targetName ? [targetName, validHost.name] : [targetName],
279
406
  unqualifiedTarget: targetName
280
407
  }, 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
- });
408
+ errors.push(...validateHostRefs(filterQuery.expression, {
409
+ host: formHost,
410
+ binding: {
411
+ name: targetName,
412
+ target
413
+ },
414
+ doc
415
+ }));
286
416
  }
287
417
  if (fieldProp && fieldName !== void 0) {
288
418
  const idFields = [...target.props.entries()].filter(([, p]) => p.countAnnotations("meta.id") > 0);
289
419
  let ok = fieldProp.countAnnotations("db.index.unique") > 0 || fieldProp.countAnnotations("meta.id") > 0 && idFields.length === 1;
290
420
  if (!ok && fieldProp.countAnnotations("meta.id") > 0) {
291
- const pinned = pinnedFields(filterArg);
292
- ok = idFields.every(([name]) => name === fieldName || pinned.has(name));
421
+ const literal = pinnedFields(filterArg);
422
+ const byHost = validHost ? hostPins(filterArg, validHost.name) : void 0;
423
+ const fieldAnnotations = validHost?.field.annotations ?? [];
424
+ const argOf = (name) => fieldAnnotations.find((a) => a.name === name)?.args[0]?.text;
425
+ const formType = argOf("ui.form.type") ?? argOf("ui.type");
426
+ const dropdown = formType === "select" || formType === "radio";
427
+ const fills = fieldAnnotations.filter((a) => a.name === "ui.valueHelp.fill");
428
+ const writtenBack = (member) => {
429
+ const local = byHost?.get(member);
430
+ return !dropdown && local !== void 0 && fills.some((a) => a.args[0]?.text === local && a.args[1]?.text === member);
431
+ };
432
+ ok = idFields.every(([name]) => name === fieldName || literal.has(name) || writtenBack(name));
293
433
  }
294
434
  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)`,
435
+ 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 '=' to a literal in the filter, or to a host field a fill writes back from the picked row)`,
296
436
  severity: WARNING,
297
437
  range: token.range
298
438
  });
299
439
  }
300
440
  if (filterQuery && (0, _atscript_db_shared.getAnnotationAlias)(target.decl, "db.table.filterable") === "manual") {
301
441
  const seen = /* @__PURE__ */ new Set();
302
- (0, _atscript_db_shared.forEachFieldRef)(filterQuery.expression, (ref) => {
303
- if (ref.typeRef && ref.typeRef.text !== targetName) return;
442
+ for (const { left: ref } of comparisons(filterQuery.expression)) {
443
+ if (ref.typeRef && ref.typeRef.text !== targetName) continue;
304
444
  const name = ref.fieldRef.text;
305
- if (seen.has(name)) return;
445
+ if (seen.has(name)) continue;
306
446
  seen.add(name);
307
447
  const prop = target.props.get(name.split(".")[0]);
308
448
  if (prop && prop.countAnnotations("db.column.filterable") === 0) errors.push({
@@ -310,7 +450,27 @@ function validateValueHelp(token, args, doc) {
310
450
  severity: WARNING,
311
451
  range: ref.fieldRef.range
312
452
  });
313
- });
453
+ }
454
+ }
455
+ if (validHost && (0, _atscript_core.isRef)(host)) {
456
+ const binding = {
457
+ name: targetName,
458
+ target
459
+ };
460
+ for (const a of validHost.field.annotations ?? []) {
461
+ if (a.token.parentNode === host) continue;
462
+ const isFill = a.name === "ui.valueHelp.fill";
463
+ if (!isFill && a.name !== "ui.valueHelp.column") continue;
464
+ const local = isFill ? a.args[0]?.text : void 0;
465
+ const name = a.args[isFill ? 1 : 0]?.text;
466
+ if (name === void 0) continue;
467
+ const problem = targetFieldProblem(binding, name) ?? (local === void 0 ? void 0 : designMismatch(validHost, local, binding, name, doc));
468
+ if (problem) errors.push({
469
+ message: `@${a.name} '${a.args.map((t) => t.text).join("', '")}' of this field: ${problem}`,
470
+ severity: ERROR,
471
+ range: token.range
472
+ });
473
+ }
314
474
  }
315
475
  return errors;
316
476
  }
@@ -319,6 +479,138 @@ function comparisons(expr) {
319
479
  if ((0, _atscript_core.isQueryLogical)(expr)) return expr.operands.flatMap(comparisons);
320
480
  return (0, _atscript_core.isQueryComparison)(expr) ? [expr] : [];
321
481
  }
482
+ /**
483
+ * VH5 / VH9 (since 0.1.190): a field-to-field comparison is a host reference —
484
+ * a top-level `and` conjunct `targetField = Host.field` naming an existing
485
+ * scalar field of the host of the same design type that is not the bound
486
+ * field. Anything else that compares two fields or names the host is an error.
487
+ */
488
+ function validateHostRefs(expr, ctx) {
489
+ const errors = [];
490
+ const { host, binding, doc } = ctx;
491
+ const targetName = binding.name;
492
+ const error = (message, range) => errors.push({
493
+ message,
494
+ severity: ERROR,
495
+ range
496
+ });
497
+ const visit = (node, topLevel) => {
498
+ if ((0, _atscript_core.isQueryLogical)(node)) {
499
+ const chain = topLevel && node.operator === "and";
500
+ for (const operand of node.operands) visit(operand, chain);
501
+ return;
502
+ }
503
+ if (!(0, _atscript_core.isQueryComparison)(node)) return;
504
+ const hostName = typeof host === "object" ? host.name : void 0;
505
+ if (hostName && hostName !== targetName && node.left.typeRef?.text === hostName) error(`the left side names a field of '${targetName}'; a host field belongs on the right ('field = ${hostName}.${node.left.fieldRef.text}')`, node.left.typeRef.range);
506
+ const ref = rightRef(node);
507
+ if (!ref) return;
508
+ if (typeof host !== "object") {
509
+ error(host === void 0 ? "a value-help filter compares target fields with literal values" : `a host reference (a right-hand field reference) needs ${REFUSED[host]}`, ref.fieldRef.range);
510
+ return;
511
+ }
512
+ const typeName = ref.typeRef?.text;
513
+ if (typeName !== host.name) {
514
+ if (typeName === void 0 || typeName === targetName) error(`a value-help filter compares target fields with literal values, or with a field of the host: '${host.name}.${ref.fieldRef.text}'`, ref.fieldRef.range);
515
+ return;
516
+ }
517
+ if (!topLevel) error("a host reference must be a top-level 'and' conjunct of the filter (not under 'or' / 'not')", ref.fieldRef.range);
518
+ if (node.operator !== "=") error(`a host reference compares with '=' (got '${node.operator}')`, ref.fieldRef.range);
519
+ const name = ref.fieldRef.text;
520
+ const prop = name.includes(".") ? void 0 : host.fields.get(name);
521
+ if (!prop) {
522
+ error(name.includes(".") ? `a host reference names a top-level field of '${host.name}', not a dotted path` : `Field '${name}' does not exist on '${host.name}'`, ref.fieldRef.range);
523
+ return;
524
+ }
525
+ if (name === host.field.id) error("a host reference cannot name the bound field itself", ref.fieldRef.range);
526
+ else if (isNotScalar(prop, doc)) error(`host field '${host.name}.${name}' must be ${SCALAR}`, ref.fieldRef.range);
527
+ else {
528
+ const mismatch = designMismatch(host, name, binding, node.left.fieldRef.text, doc);
529
+ if (mismatch) error(mismatch, ref.fieldRef.range);
530
+ }
531
+ };
532
+ visit(expr, true);
533
+ return errors;
534
+ }
535
+ function validateFill(token, args, doc) {
536
+ const errors = [];
537
+ const [localArg, targetArg] = args;
538
+ const host = hostOf(token, doc);
539
+ if (typeof host !== "object") {
540
+ if (host) errors.push({
541
+ message: `@ui.valueHelp.fill needs ${REFUSED[host]}`,
542
+ severity: ERROR,
543
+ range: token.range
544
+ });
545
+ return errors;
546
+ }
547
+ const binding = bindingOf(host.field, doc);
548
+ if (!binding) {
549
+ errors.push({
550
+ message: "@ui.valueHelp.fill needs a binding of this field's own (@ui.valueHelp or @db.rel.FK)",
551
+ severity: ERROR,
552
+ range: token.range
553
+ });
554
+ return errors;
555
+ }
556
+ const local = localArg?.text;
557
+ let localOk = false;
558
+ if (localArg && local !== void 0) {
559
+ const prop = local.includes(".") ? void 0 : host.fields.get(local);
560
+ if (!prop || local === host.field.id) errors.push({
561
+ message: local.includes(".") ? `'${local}' must be a top-level field of '${host.name}', not a dotted path` : prop ? "@ui.valueHelp.fill cannot fill the bound field itself" : `Field '${local}' does not exist on '${host.name}'`,
562
+ severity: ERROR,
563
+ range: localArg.range
564
+ });
565
+ else if ((0, _atscript_db_shared.isNavProp)(prop)) errors.push({
566
+ message: `'${local}' is a navigation field — a pick never writes it`,
567
+ severity: WARNING,
568
+ range: localArg.range
569
+ });
570
+ else if (isNotScalar(prop, doc)) errors.push({
571
+ message: `'${host.name}.${local}' must be ${SCALAR}`,
572
+ severity: ERROR,
573
+ range: localArg.range
574
+ });
575
+ else {
576
+ localOk = true;
577
+ const effective = (0, _atscript_db_shared.effectiveAnnotationNames)(prop, doc);
578
+ const why = effective.has("db.column.derived") ? "@db.column.derived" : effective.has("meta.readonly") ? "@meta.readonly" : void 0;
579
+ if (why) errors.push({
580
+ message: `'${local}' is ${why} — a pick never writes it`,
581
+ severity: WARNING,
582
+ range: localArg.range
583
+ });
584
+ }
585
+ }
586
+ const name = targetArg?.text;
587
+ if (targetArg && name !== void 0) {
588
+ const problem = targetFieldProblem(binding, name) ?? (localOk && local !== void 0 ? designMismatch(host, local, binding, name, doc) : void 0);
589
+ if (problem) errors.push({
590
+ message: problem,
591
+ severity: ERROR,
592
+ range: targetArg.range
593
+ });
594
+ }
595
+ return errors;
596
+ }
597
+ function validateColumn(token, args, doc) {
598
+ const field = (0, _atscript_db_shared.annotationTarget)(token, doc);
599
+ if (!field) return [];
600
+ const binding = bindingOf(field, doc);
601
+ if (!binding) return [{
602
+ message: "@ui.valueHelp.column needs a binding of this field's own (@ui.valueHelp or @db.rel.FK)",
603
+ severity: ERROR,
604
+ range: token.range
605
+ }];
606
+ const name = args[0]?.text;
607
+ const problem = name === void 0 ? void 0 : targetFieldProblem(binding, name);
608
+ return problem ? [{
609
+ message: problem,
610
+ severity: ERROR,
611
+ range: args[0].range
612
+ }] : [];
613
+ }
322
614
  function validateDistinct(token, _args, doc) {
323
615
  const errors = [];
324
616
  const host = token.parentNode;
@@ -406,6 +698,44 @@ function validateLiteralLabel(token, args, doc) {
406
698
  return errors;
407
699
  }
408
700
  /**
701
+ * `valueScope` of `@ui.valueLabel`'s `field`: the string-valued fields of the
702
+ * type the annotated field belongs to, declared or inherited
703
+ * (`siblingStringFields`: never the field itself, an object, a number or a
704
+ * dotted path) — for an `annotate` entry, of the annotated interface.
705
+ * Go-to-definition jumps to the field in the file that declares it.
706
+ */
707
+ function valueLabelFields(annotationToken, doc) {
708
+ return (0, _atscript_db_shared.siblingStringFields)(annotationToken, doc).map((prop) => {
709
+ const token = prop.token("identifier");
710
+ return Object.assign({ value: prop.id ?? `` }, token && { definition: {
711
+ doc: doc.declaringDoc(prop, doc),
712
+ token
713
+ } });
714
+ });
715
+ }
716
+ function validateValueLabel(token, args, doc) {
717
+ const errors = [];
718
+ const field = (0, _atscript_db_shared.annotationTarget)(token, doc);
719
+ const name = args[0]?.text;
720
+ if (name !== void 0) if (field?.id !== void 0 && name === field.id) errors.push({
721
+ message: "@ui.valueLabel names the field holding this value's text, not this field",
722
+ severity: ERROR,
723
+ range: args[0].range
724
+ });
725
+ else errors.push(...(0, _atscript_db_shared.validateSiblingStringField)(token, args, doc, "@ui.valueLabel"));
726
+ errors.push(...(0, _atscript_db_shared.validateExclusiveWith)(token, "@ui.valueLabel", [{ key: "ui.literalLabel" }], doc));
727
+ if (field && name !== void 0 && name !== field.id) {
728
+ const binding = bindingOf(field, doc);
729
+ const filled = (field.annotations ?? []).some((a) => a.name === "ui.valueHelp.fill" && a.args[0]?.text === name);
730
+ if (binding && !filled) errors.push({
731
+ message: `a pick of this field's value help does not fill '${name}' — the text goes stale after a pick (add @ui.valueHelp.fill '${name}', '<a field of ${binding.name}>')`,
732
+ severity: WARNING,
733
+ range: token.range
734
+ });
735
+ }
736
+ return errors;
737
+ }
738
+ /**
409
739
  * `@ui.form.type` / `@ui.type`: the free-entry `tags` renderer edits an array —
410
740
  * on any other field it would mount with a scalar value.
411
741
  */
@@ -422,8 +752,12 @@ function validateFormType(token, args, doc) {
422
752
  //#endregion
423
753
  exports.isValueHelpTarget = isValueHelpTarget;
424
754
  exports.literalLabelValues = literalLabelValues;
755
+ exports.validateColumn = validateColumn;
425
756
  exports.validateDistinct = validateDistinct;
757
+ exports.validateFill = validateFill;
426
758
  exports.validateFormType = validateFormType;
427
759
  exports.validateLiteralLabel = validateLiteralLabel;
428
760
  exports.validateValueHelp = validateValueHelp;
761
+ exports.validateValueLabel = validateValueLabel;
429
762
  exports.valueHelpScopes = valueHelpScopes;
763
+ exports.valueLabelFields = valueLabelFields;