@atscript/ui 0.1.163 → 0.1.164
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client-factory.cjs +27 -0
- package/dist/client-factory.d.cts +53 -0
- package/dist/client-factory.d.mts +53 -0
- package/dist/client-factory.mjs +25 -0
- package/dist/form/apply.cjs +38 -0
- package/dist/form/apply.d.cts +36 -0
- package/dist/form/apply.d.mts +36 -0
- package/dist/form/apply.mjs +38 -0
- package/dist/form/clone.cjs +30 -0
- package/dist/form/clone.d.cts +23 -0
- package/dist/form/clone.d.mts +23 -0
- package/dist/form/clone.mjs +30 -0
- package/dist/form/create-form-def.cjs +440 -0
- package/dist/form/create-form-def.d.cts +67 -0
- package/dist/form/create-form-def.d.mts +67 -0
- package/dist/form/create-form-def.mjs +438 -0
- package/dist/form/decimal-format.cjs +324 -0
- package/dist/form/decimal-format.d.cts +86 -0
- package/dist/form/decimal-format.d.mts +86 -0
- package/dist/form/decimal-format.mjs +315 -0
- package/dist/form/diff.cjs +458 -0
- package/dist/form/diff.d.cts +80 -0
- package/dist/form/diff.d.mts +80 -0
- package/dist/form/diff.mjs +457 -0
- package/dist/form/dirty.cjs +65 -0
- package/dist/form/dirty.d.cts +47 -0
- package/dist/form/dirty.d.mts +47 -0
- package/dist/form/dirty.mjs +64 -0
- package/dist/form/error-utils.cjs +97 -0
- package/dist/form/error-utils.d.cts +58 -0
- package/dist/form/error-utils.d.mts +58 -0
- package/dist/form/error-utils.mjs +92 -0
- package/dist/form/form-actions.cjs +30 -0
- package/dist/form/form-actions.d.cts +17 -0
- package/dist/form/form-actions.d.mts +17 -0
- package/dist/form/form-actions.mjs +30 -0
- package/dist/form/grid.cjs +69 -0
- package/dist/form/grid.d.cts +49 -0
- package/dist/form/grid.d.mts +49 -0
- package/dist/form/grid.mjs +64 -0
- package/dist/form/labels.cjs +10 -0
- package/dist/form/labels.d.cts +7 -0
- package/dist/form/labels.d.mts +7 -0
- package/dist/form/labels.mjs +10 -0
- package/dist/form/measurement.cjs +20 -0
- package/dist/form/measurement.d.cts +29 -0
- package/dist/form/measurement.d.mts +29 -0
- package/dist/form/measurement.mjs +20 -0
- package/dist/form/path-utils.cjs +182 -0
- package/dist/form/path-utils.d.cts +47 -0
- package/dist/form/path-utils.d.mts +47 -0
- package/dist/form/path-utils.mjs +175 -0
- package/dist/form/rebase.cjs +89 -0
- package/dist/form/rebase.d.cts +61 -0
- package/dist/form/rebase.d.mts +61 -0
- package/dist/form/rebase.mjs +89 -0
- package/dist/form/skipped-nav.cjs +100 -0
- package/dist/form/skipped-nav.d.cts +13 -0
- package/dist/form/skipped-nav.d.mts +13 -0
- package/dist/form/skipped-nav.mjs +98 -0
- package/dist/form/types.cjs +40 -0
- package/dist/form/types.d.cts +133 -0
- package/dist/form/types.d.mts +133 -0
- package/dist/form/types.mjs +36 -0
- package/dist/form/union-detect.cjs +46 -0
- package/dist/form/union-detect.d.cts +22 -0
- package/dist/form/union-detect.d.mts +22 -0
- package/dist/form/union-detect.mjs +46 -0
- package/dist/form/validate.cjs +150 -0
- package/dist/form/validate.d.cts +50 -0
- package/dist/form/validate.d.mts +50 -0
- package/dist/form/validate.mjs +147 -0
- package/dist/index.cjs +217 -3360
- package/dist/index.d.cts +38 -1693
- package/dist/index.d.mts +38 -1693
- package/dist/index.mjs +35 -3179
- package/dist/nav/model-routes.cjs +59 -0
- package/dist/nav/model-routes.d.cts +33 -0
- package/dist/nav/model-routes.d.mts +33 -0
- package/dist/nav/model-routes.mjs +59 -0
- package/dist/plugin/annotations.cjs +577 -0
- package/dist/plugin/annotations.mjs +577 -0
- package/dist/plugin/primitives.cjs +30 -0
- package/dist/plugin/primitives.mjs +30 -0
- package/dist/plugin/value-help-validation.cjs +419 -0
- package/dist/plugin/value-help-validation.mjs +413 -0
- package/dist/plugin.cjs +4 -1001
- package/dist/plugin.mjs +2 -999
- package/dist/shared/annotation-keys.cjs +189 -0
- package/dist/shared/annotation-keys.d.cts +82 -0
- package/dist/shared/annotation-keys.d.mts +82 -0
- package/dist/shared/annotation-keys.mjs +97 -0
- package/dist/shared/field-resolver.cjs +123 -0
- package/dist/shared/field-resolver.d.cts +77 -0
- package/dist/shared/field-resolver.d.mts +77 -0
- package/dist/shared/field-resolver.mjs +110 -0
- package/dist/shared/meta-cache.cjs +244 -0
- package/dist/shared/meta-cache.d.cts +110 -0
- package/dist/shared/meta-cache.d.mts +110 -0
- package/dist/shared/meta-cache.mjs +237 -0
- package/dist/shared/str.cjs +19 -0
- package/dist/shared/str.d.cts +7 -0
- package/dist/shared/str.d.mts +7 -0
- package/dist/shared/str.mjs +17 -0
- package/dist/table/column-resolver.cjs +17 -0
- package/dist/table/column-resolver.d.cts +11 -0
- package/dist/table/column-resolver.d.mts +11 -0
- package/dist/table/column-resolver.mjs +15 -0
- package/dist/table/create-table-def.cjs +233 -0
- package/dist/table/create-table-def.d.cts +15 -0
- package/dist/table/create-table-def.d.mts +15 -0
- package/dist/table/create-table-def.mjs +233 -0
- package/dist/table/navigate-href.cjs +45 -0
- package/dist/table/navigate-href.d.cts +31 -0
- package/dist/table/navigate-href.d.mts +31 -0
- package/dist/table/navigate-href.mjs +45 -0
- package/dist/table/types.d.cts +287 -0
- package/dist/table/types.d.mts +287 -0
- package/dist/table/value-kind.cjs +20 -0
- package/dist/table/value-kind.d.cts +15 -0
- package/dist/table/value-kind.d.mts +15 -0
- package/dist/table/value-kind.mjs +19 -0
- package/dist/value-help/dict-paths.cjs +17 -0
- package/dist/value-help/dict-paths.d.cts +11 -0
- package/dist/value-help/dict-paths.d.mts +11 -0
- package/dist/value-help/dict-paths.mjs +17 -0
- package/dist/value-help/distinct-client.cjs +51 -0
- package/dist/value-help/distinct-client.d.cts +40 -0
- package/dist/value-help/distinct-client.d.mts +40 -0
- package/dist/value-help/distinct-client.mjs +50 -0
- package/dist/value-help/extract-literals.cjs +76 -0
- package/dist/value-help/extract-literals.d.cts +32 -0
- package/dist/value-help/extract-literals.d.mts +32 -0
- package/dist/value-help/extract-literals.mjs +74 -0
- package/dist/value-help/extract-ref.cjs +100 -0
- package/dist/value-help/extract-ref.d.cts +37 -0
- package/dist/value-help/extract-ref.d.mts +37 -0
- package/dist/value-help/extract-ref.mjs +100 -0
- package/dist/value-help/filter-tree.cjs +45 -0
- package/dist/value-help/filter-tree.mjs +45 -0
- package/dist/value-help/index.d.mts +8 -0
- package/dist/value-help/resolve-options.cjs +64 -0
- package/dist/value-help/resolve-options.d.cts +35 -0
- package/dist/value-help/resolve-options.d.mts +35 -0
- package/dist/value-help/resolve-options.mjs +60 -0
- package/dist/value-help/resolve.cjs +62 -0
- package/dist/value-help/resolve.d.cts +31 -0
- package/dist/value-help/resolve.d.mts +31 -0
- package/dist/value-help/resolve.mjs +61 -0
- package/dist/value-help/types.d.cts +36 -0
- package/dist/value-help/types.d.mts +36 -0
- package/dist/value-help/value-help-client.cjs +136 -0
- package/dist/value-help/value-help-client.d.cts +67 -0
- package/dist/value-help/value-help-client.d.mts +67 -0
- package/dist/value-help/value-help-client.mjs +134 -0
- package/package.json +10 -10
|
@@ -0,0 +1,419 @@
|
|
|
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" }], doc));
|
|
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
|
+
/**
|
|
399
|
+
* `@ui.form.type` / `@ui.type`: the free-entry `tags` renderer edits an array —
|
|
400
|
+
* on any other field it would mount with a scalar value.
|
|
401
|
+
*/
|
|
402
|
+
function validateFormType(token, args, doc) {
|
|
403
|
+
if (args[0]?.text !== "tags") return [];
|
|
404
|
+
const design = hostDesign(token, doc);
|
|
405
|
+
if (design === void 0 || design === "array") return [];
|
|
406
|
+
return [{
|
|
407
|
+
message: `'tags' requires an array field (e.g. string[]), got ${design}`,
|
|
408
|
+
severity: ERROR,
|
|
409
|
+
range: args[0].range
|
|
410
|
+
}];
|
|
411
|
+
}
|
|
412
|
+
//#endregion
|
|
413
|
+
exports.isValueHelpTarget = isValueHelpTarget;
|
|
414
|
+
exports.literalLabelValues = literalLabelValues;
|
|
415
|
+
exports.validateDistinct = validateDistinct;
|
|
416
|
+
exports.validateFormType = validateFormType;
|
|
417
|
+
exports.validateLiteralLabel = validateLiteralLabel;
|
|
418
|
+
exports.validateValueHelp = validateValueHelp;
|
|
419
|
+
exports.valueHelpScopes = valueHelpScopes;
|