@atscript/ui 0.1.147 → 0.1.148
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.
- package/dist/index.cjs +351 -57
- package/dist/index.d.cts +158 -8
- package/dist/index.d.mts +158 -8
- package/dist/index.mjs +345 -58
- package/dist/plugin.cjs +449 -0
- package/dist/plugin.mjs +450 -1
- package/package.json +10 -10
package/dist/plugin.cjs
CHANGED
|
@@ -1,4 +1,401 @@
|
|
|
1
1
|
let _atscript_core = require("@atscript/core");
|
|
2
|
+
let _atscript_db_shared = require("@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 (0, _atscript_core.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 (0, _atscript_core.isInterface)(decl) && !(0, _atscript_db_shared.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 = (0, _atscript_db_shared.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 = (0, _atscript_db_shared.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 ((0, _atscript_db_shared.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
|
+
/** Collects the literal values of a pure literal union; `undefined` when it cannot be resolved. */
|
|
123
|
+
function collectLiterals(def, doc, out, depth = 0) {
|
|
124
|
+
let unresolved = false;
|
|
125
|
+
for (const leaf of leavesOf(def, doc, depth)) if (!leaf) unresolved = true;
|
|
126
|
+
else if (leaf.def.entity === "const") {
|
|
127
|
+
const text = leaf.def.token("identifier")?.text;
|
|
128
|
+
if (text === void 0) return false;
|
|
129
|
+
out.push({
|
|
130
|
+
text,
|
|
131
|
+
def: leaf.def,
|
|
132
|
+
doc: leaf.doc
|
|
133
|
+
});
|
|
134
|
+
} else if (leaf.def.entity === "array") {
|
|
135
|
+
const ok = collectLiterals(leaf.def.getDefinition(), leaf.doc, out, depth + 1);
|
|
136
|
+
if (ok === false) return false;
|
|
137
|
+
if (ok === void 0) unresolved = true;
|
|
138
|
+
} else return false;
|
|
139
|
+
return unresolved ? void 0 : true;
|
|
140
|
+
}
|
|
141
|
+
/** {@link collectLiterals} of the type an annotated node stands for. */
|
|
142
|
+
function collectHostLiterals(node, doc, out) {
|
|
143
|
+
const host = doc.annotatedDefinition(node);
|
|
144
|
+
return collectLiterals(host?.def, host?.doc ?? doc, out);
|
|
145
|
+
}
|
|
146
|
+
function resolveTarget(name, doc) {
|
|
147
|
+
const owner = doc.getDeclarationOwnerNode(name);
|
|
148
|
+
if (!owner?.node || !(0, _atscript_core.isInterface)(owner.node)) return void 0;
|
|
149
|
+
const props = /* @__PURE__ */ new Map();
|
|
150
|
+
for (const prop of (0, _atscript_core.getFieldsForType)(doc, name)) if (prop.id) props.set(prop.id, prop);
|
|
151
|
+
return {
|
|
152
|
+
doc: owner.doc,
|
|
153
|
+
decl: owner.node,
|
|
154
|
+
props
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* The annotated TARGET prop: the prop itself for an inline annotation, or — for an `annotate`
|
|
159
|
+
* entry — the prop of the target type the entry names. Its owning struct and declaration are
|
|
160
|
+
* resolved the same way as for an inline prop. `undefined` when the entry does not resolve.
|
|
161
|
+
*/
|
|
162
|
+
function annotatedField(node, doc) {
|
|
163
|
+
if (!node) return void 0;
|
|
164
|
+
let prop = node;
|
|
165
|
+
let path = node.id ?? "";
|
|
166
|
+
if ((0, _atscript_core.isRef)(node)) {
|
|
167
|
+
const idToken = node.token("identifier");
|
|
168
|
+
const block = idToken ? doc.annotateBlockAt(idToken.range.start.line, idToken.range.start.character) : void 0;
|
|
169
|
+
if (block) {
|
|
170
|
+
const chain = [node.id, ...node.chain.map((c) => c.text)];
|
|
171
|
+
path = chain.join(".");
|
|
172
|
+
prop = (doc.unwindType(block.targetName, chain.slice(0, -1))?.def)?.props?.get(chain.at(-1));
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (!prop || !(0, _atscript_core.isProp)(prop)) return void 0;
|
|
176
|
+
let struct;
|
|
177
|
+
let up = prop.ownerNode;
|
|
178
|
+
while (up && !(0, _atscript_core.isInterface)(up)) {
|
|
179
|
+
if ((0, _atscript_core.isStructure)(up)) struct = up;
|
|
180
|
+
up = up.ownerNode;
|
|
181
|
+
}
|
|
182
|
+
const owner = up && (0, _atscript_core.isInterface)(up) ? up : struct;
|
|
183
|
+
return {
|
|
184
|
+
prop,
|
|
185
|
+
path,
|
|
186
|
+
struct,
|
|
187
|
+
owner
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
function isNavigation(node) {
|
|
191
|
+
return !!node && (node.countAnnotations("db.rel.to") > 0 || node.countAnnotations("db.rel.from") > 0 || node.countAnnotations("db.rel.via") > 0);
|
|
192
|
+
}
|
|
193
|
+
/** Top-level conjuncts of a predicate (an `and` chain flattened). */
|
|
194
|
+
function conjuncts(expr) {
|
|
195
|
+
if ((0, _atscript_core.isQueryLogical)(expr) && expr.operator === "and") return expr.operands.flatMap(conjuncts);
|
|
196
|
+
return [expr];
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Fields the filter pins with a top-level `=` against a literal value. The
|
|
200
|
+
* compile-time twin of `pinnedOf` in `value-help/filter-tree.ts` (which reads the
|
|
201
|
+
* emitted tree at runtime) — keep the two rules in step.
|
|
202
|
+
*/
|
|
203
|
+
function pinnedFields(filter) {
|
|
204
|
+
const pinned = /* @__PURE__ */ new Set();
|
|
205
|
+
const expr = filter?.queryNode?.expression;
|
|
206
|
+
if (!expr) return pinned;
|
|
207
|
+
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);
|
|
208
|
+
return pinned;
|
|
209
|
+
}
|
|
210
|
+
function validateValueHelp(token, args, doc) {
|
|
211
|
+
const errors = [];
|
|
212
|
+
const [targetArg, fieldArg, filterArg] = args;
|
|
213
|
+
const host = token.parentNode;
|
|
214
|
+
const field = annotatedField(host, doc);
|
|
215
|
+
if (isNavigation(field?.prop ?? host)) errors.push({
|
|
216
|
+
message: "@ui.valueHelp is not valid on a navigation field — bind the foreign-key field",
|
|
217
|
+
severity: ERROR,
|
|
218
|
+
range: token.range
|
|
219
|
+
});
|
|
220
|
+
errors.push(...(0, _atscript_db_shared.validateExclusiveWith)(token, "@ui.valueHelp", [{ key: "ui.valueHelp.distinct" }]));
|
|
221
|
+
if (!targetArg) return errors;
|
|
222
|
+
const targetErrors = (0, _atscript_db_shared.validateRefArgument)(targetArg, doc, {
|
|
223
|
+
accept: isValueHelpTarget,
|
|
224
|
+
expected: "must be an interface — a value-help dictionary."
|
|
225
|
+
});
|
|
226
|
+
errors.push(...targetErrors);
|
|
227
|
+
if (targetErrors.length > 0) return errors;
|
|
228
|
+
const targetName = targetArg.text;
|
|
229
|
+
const target = resolveTarget(targetName, doc);
|
|
230
|
+
if (!target) return errors;
|
|
231
|
+
if (!(0, _atscript_db_shared.isDbSourceDecl)(target.decl) && target.decl.countAnnotations("db.http.path") === 0) errors.push({
|
|
232
|
+
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`,
|
|
233
|
+
severity: WARNING,
|
|
234
|
+
range: targetArg.range
|
|
235
|
+
});
|
|
236
|
+
const fieldName = fieldArg?.text;
|
|
237
|
+
let fieldDesign;
|
|
238
|
+
let fieldProp;
|
|
239
|
+
if (fieldArg && fieldName !== void 0) {
|
|
240
|
+
fieldProp = fieldName.includes(".") ? void 0 : target.props.get(fieldName);
|
|
241
|
+
if (!fieldProp) errors.push({
|
|
242
|
+
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}'`,
|
|
243
|
+
severity: ERROR,
|
|
244
|
+
range: fieldArg.range
|
|
245
|
+
});
|
|
246
|
+
else {
|
|
247
|
+
fieldDesign = designOf(fieldProp.getDefinition(), target.doc);
|
|
248
|
+
if (fieldProp.countAnnotations("db.json") > 0 || fieldDesign === "object" || fieldDesign === "array") {
|
|
249
|
+
errors.push({
|
|
250
|
+
message: `Value-help field '${targetName}.${fieldName}' must be a scalar (not an object, array or @db.json)`,
|
|
251
|
+
severity: ERROR,
|
|
252
|
+
range: fieldArg.range
|
|
253
|
+
});
|
|
254
|
+
fieldDesign = void 0;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
if (fieldDesign && fieldDesign !== "other") {
|
|
259
|
+
const hostType = hostDesign(token, doc);
|
|
260
|
+
if (hostType && hostType !== fieldDesign) errors.push({
|
|
261
|
+
message: `Value-help field '${targetName}.${fieldName}' is ${fieldDesign}, '${field?.path || host?.id || "this field"}' is ${hostType}`,
|
|
262
|
+
severity: ERROR,
|
|
263
|
+
range: token.range
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
const filterQuery = filterArg?.queryNode;
|
|
267
|
+
if (filterArg && filterQuery) {
|
|
268
|
+
errors.push(...(0, _atscript_db_shared.validateQueryScope)(filterArg, {
|
|
269
|
+
allowedTypes: [targetName],
|
|
270
|
+
unqualifiedTarget: targetName
|
|
271
|
+
}, doc));
|
|
272
|
+
for (const cmp of comparisons(filterQuery.expression)) if (cmp.right && "fieldRef" in cmp.right) errors.push({
|
|
273
|
+
message: "a value-help filter compares target fields with literal values",
|
|
274
|
+
severity: ERROR,
|
|
275
|
+
range: cmp.right.fieldRef.range
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
if (fieldProp && fieldName !== void 0) {
|
|
279
|
+
const idFields = [...target.props.entries()].filter(([, p]) => p.countAnnotations("meta.id") > 0);
|
|
280
|
+
let ok = fieldProp.countAnnotations("db.index.unique") > 0 || fieldProp.countAnnotations("meta.id") > 0 && idFields.length === 1;
|
|
281
|
+
if (!ok && fieldProp.countAnnotations("meta.id") > 0) {
|
|
282
|
+
const pinned = pinnedFields(filterArg);
|
|
283
|
+
ok = idFields.every(([name]) => name === fieldName || pinned.has(name));
|
|
284
|
+
}
|
|
285
|
+
if (!ok) errors.push({
|
|
286
|
+
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)`,
|
|
287
|
+
severity: WARNING,
|
|
288
|
+
range: token.range
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
if (filterQuery && (0, _atscript_db_shared.getAnnotationAlias)(target.decl, "db.table.filterable") === "manual") {
|
|
292
|
+
const seen = /* @__PURE__ */ new Set();
|
|
293
|
+
(0, _atscript_db_shared.forEachFieldRef)(filterQuery.expression, (ref) => {
|
|
294
|
+
if (ref.typeRef && ref.typeRef.text !== targetName) return;
|
|
295
|
+
const name = ref.fieldRef.text;
|
|
296
|
+
if (seen.has(name)) return;
|
|
297
|
+
seen.add(name);
|
|
298
|
+
const prop = target.props.get(name.split(".")[0]);
|
|
299
|
+
if (prop && prop.countAnnotations("db.column.filterable") === 0) errors.push({
|
|
300
|
+
message: `the dictionary controller will reject this filter ('${name}' needs @db.column.filterable)`,
|
|
301
|
+
severity: WARNING,
|
|
302
|
+
range: ref.fieldRef.range
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
return errors;
|
|
307
|
+
}
|
|
308
|
+
/** Every comparison of a predicate, depth-first. */
|
|
309
|
+
function comparisons(expr) {
|
|
310
|
+
if ((0, _atscript_core.isQueryLogical)(expr)) return expr.operands.flatMap(comparisons);
|
|
311
|
+
return (0, _atscript_core.isQueryComparison)(expr) ? [expr] : [];
|
|
312
|
+
}
|
|
313
|
+
function validateDistinct(token, _args, doc) {
|
|
314
|
+
const errors = [];
|
|
315
|
+
const host = token.parentNode;
|
|
316
|
+
const design = hostDesign(token, doc);
|
|
317
|
+
if (hostLeaves(host, doc).some((leaf) => leaf && isTimestampLeaf(leaf.def))) errors.push({
|
|
318
|
+
message: "@ui.valueHelp.distinct requires a string or number field, got timestamp — a timestamp is not a value to pick from a list",
|
|
319
|
+
severity: ERROR,
|
|
320
|
+
range: token.range
|
|
321
|
+
});
|
|
322
|
+
else if (design && design !== "string" && design !== "number") errors.push({
|
|
323
|
+
message: `@ui.valueHelp.distinct requires a string or number field, got ${design}`,
|
|
324
|
+
severity: ERROR,
|
|
325
|
+
range: token.range
|
|
326
|
+
});
|
|
327
|
+
const field = annotatedField(host, doc);
|
|
328
|
+
const owner = field?.owner;
|
|
329
|
+
if (!owner || !field) return errors;
|
|
330
|
+
if (!(0, _atscript_db_shared.isDbSourceDecl)(owner)) {
|
|
331
|
+
errors.push({
|
|
332
|
+
message: "distinct values are served by a DB controller — declare this on a @db.table/@db.view",
|
|
333
|
+
severity: WARNING,
|
|
334
|
+
range: token.range
|
|
335
|
+
});
|
|
336
|
+
return errors;
|
|
337
|
+
}
|
|
338
|
+
const struct = field.struct;
|
|
339
|
+
if (struct && (0, _atscript_core.isStructure)(struct) && field.prop.countAnnotations("db.column.dimension") === 0 && (0, _atscript_db_shared.isStrictAggregateStruct)(struct)) errors.push({
|
|
340
|
+
message: `$groupBy rejects this field of a strict aggregate table: ${_atscript_db_shared.NOT_DIMENSION_REASON} (add @db.column.dimension)`,
|
|
341
|
+
severity: WARNING,
|
|
342
|
+
range: token.range
|
|
343
|
+
});
|
|
344
|
+
return errors;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* `valueScope` of `@ui.literalLabel`'s `value`: the literals of the annotated
|
|
348
|
+
* union (or array of one), each linked to the literal it declares — completion
|
|
349
|
+
* offers them and go-to-definition on the value jumps to the literal.
|
|
350
|
+
*/
|
|
351
|
+
function literalLabelValues(annotationToken, doc) {
|
|
352
|
+
const found = [];
|
|
353
|
+
if (collectHostLiterals(annotationToken.parentNode, doc, found) === false) return;
|
|
354
|
+
const seen = /* @__PURE__ */ new Set();
|
|
355
|
+
const candidates = [];
|
|
356
|
+
for (const { text, def, doc: declaring } of found) {
|
|
357
|
+
if (seen.has(text)) continue;
|
|
358
|
+
seen.add(text);
|
|
359
|
+
const token = def.token("identifier");
|
|
360
|
+
candidates.push({
|
|
361
|
+
value: text,
|
|
362
|
+
...token && { definition: {
|
|
363
|
+
doc: declaring,
|
|
364
|
+
token
|
|
365
|
+
} }
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
return candidates.length > 0 ? candidates : void 0;
|
|
369
|
+
}
|
|
370
|
+
function validateLiteralLabel(token, args, doc) {
|
|
371
|
+
const errors = [];
|
|
372
|
+
const host = token.parentNode;
|
|
373
|
+
const found = [];
|
|
374
|
+
const pure = collectHostLiterals(host, doc, found);
|
|
375
|
+
const literals = found.map((l) => l.text);
|
|
376
|
+
if (pure === false) {
|
|
377
|
+
errors.push({
|
|
378
|
+
message: "@ui.literalLabel requires a union of literal values (or an array of one)",
|
|
379
|
+
severity: ERROR,
|
|
380
|
+
range: token.range
|
|
381
|
+
});
|
|
382
|
+
return errors;
|
|
383
|
+
}
|
|
384
|
+
const value = args[0];
|
|
385
|
+
if (!value) return errors;
|
|
386
|
+
if (pure === true && !literals.includes(value.text)) errors.push({
|
|
387
|
+
message: `'${value.text}' is not one of the literals: ${literals.map((l) => `'${l}'`).join(", ")}`,
|
|
388
|
+
severity: ERROR,
|
|
389
|
+
range: value.range
|
|
390
|
+
});
|
|
391
|
+
if ((host?.annotations ?? []).filter((a) => a.name === "ui.literalLabel" && a.args[0]?.text === value.text).findIndex((a) => a.token === token) > 0) errors.push({
|
|
392
|
+
message: `duplicate @ui.literalLabel for '${value.text}'`,
|
|
393
|
+
severity: ERROR,
|
|
394
|
+
range: value.range
|
|
395
|
+
});
|
|
396
|
+
return errors;
|
|
397
|
+
}
|
|
398
|
+
//#endregion
|
|
2
399
|
//#region src/plugin/annotations.ts
|
|
3
400
|
const BUILTIN_TYPES = [
|
|
4
401
|
"text",
|
|
@@ -49,6 +446,7 @@ const ROW_SPAN_VALUES = [
|
|
|
49
446
|
* - `ui.form.<key>` — form-only static
|
|
50
447
|
* - `ui.table.<key>` — table-only static
|
|
51
448
|
* - `ui.dict.<key>` — value-help annotations
|
|
449
|
+
* - `ui.valueHelp`, `ui.literalLabel` — dictionary binding, union literal labels
|
|
52
450
|
* - `ui.nav.<key>` — model-level navigation annotations
|
|
53
451
|
* - `ui.array.<key>` — array control annotations
|
|
54
452
|
*
|
|
@@ -436,6 +834,57 @@ const uiAnnotations = { ui: {
|
|
|
436
834
|
}
|
|
437
835
|
})
|
|
438
836
|
},
|
|
837
|
+
valueHelp: {
|
|
838
|
+
$self: new _atscript_core.AnnotationSpec({
|
|
839
|
+
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",
|
|
840
|
+
nodeType: ["prop", "type"],
|
|
841
|
+
multiple: false,
|
|
842
|
+
argument: [
|
|
843
|
+
{
|
|
844
|
+
name: "target",
|
|
845
|
+
type: "ref",
|
|
846
|
+
description: "The dictionary interface (served by a controller exposing `@db.http.path`). Not a `@db.alias`.",
|
|
847
|
+
refFilter: isValueHelpTarget
|
|
848
|
+
},
|
|
849
|
+
{
|
|
850
|
+
name: "field",
|
|
851
|
+
type: "string",
|
|
852
|
+
description: "Top-level scalar field of the target whose value this field stores. Same type as this field.",
|
|
853
|
+
fieldScope: valueHelpScopes.field
|
|
854
|
+
},
|
|
855
|
+
{
|
|
856
|
+
optional: true,
|
|
857
|
+
name: "filter",
|
|
858
|
+
type: "query",
|
|
859
|
+
description: "Static scope on the target (`attribute = 'color' and active = true`) — field-to-value comparisons of the target's fields only.",
|
|
860
|
+
fieldScope: valueHelpScopes.filter
|
|
861
|
+
}
|
|
862
|
+
],
|
|
863
|
+
validate: validateValueHelp
|
|
864
|
+
}),
|
|
865
|
+
distinct: new _atscript_core.AnnotationSpec({
|
|
866
|
+
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",
|
|
867
|
+
nodeType: ["prop", "type"],
|
|
868
|
+
validate: validateDistinct
|
|
869
|
+
})
|
|
870
|
+
},
|
|
871
|
+
literalLabel: new _atscript_core.AnnotationSpec({
|
|
872
|
+
description: "Display label for one literal of a union (`'open' | 'closed'`). Repeat per literal; unlabelled literals keep their raw text. Used by form selects/radios, table cells, enum filter options, filter chips and export. A prop's labels are added to the referenced type's (`append` merge: the type's other labels stay); for the same literal the prop's label wins.\n\n**Example:**\n```atscript\n@ui.literalLabel 'in_progress', 'In progress'\nexport type Status = 'open' | 'in_progress'\n```\n",
|
|
873
|
+
nodeType: ["prop", "type"],
|
|
874
|
+
multiple: true,
|
|
875
|
+
mergeStrategy: "append",
|
|
876
|
+
argument: [{
|
|
877
|
+
name: "value",
|
|
878
|
+
type: "string",
|
|
879
|
+
description: "The literal as text (`'2'` for the number literal `2`).",
|
|
880
|
+
valueScope: literalLabelValues
|
|
881
|
+
}, {
|
|
882
|
+
name: "label",
|
|
883
|
+
type: "string",
|
|
884
|
+
description: "Display label."
|
|
885
|
+
}],
|
|
886
|
+
validate: validateLiteralLabel
|
|
887
|
+
}),
|
|
439
888
|
dict: {
|
|
440
889
|
label: new _atscript_core.AnnotationSpec({
|
|
441
890
|
description: "Marks this field as the primary display label when the table is used as a value-help dictionary",
|