@telorun/templating 0.106.0 → 0.108.0
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/builtins.d.ts +9 -0
- package/dist/builtins.d.ts.map +1 -1
- package/dist/builtins.js +10 -0
- package/dist/cel/analyze.d.ts +6 -6
- package/dist/cel/analyze.d.ts.map +1 -1
- package/dist/cel/analyze.js +138 -183
- package/dist/cel/compile.d.ts +50 -12
- package/dist/cel/compile.d.ts.map +1 -1
- package/dist/cel/compile.js +140 -48
- package/dist/cel/diagnose.d.ts +52 -56
- package/dist/cel/diagnose.d.ts.map +1 -1
- package/dist/cel/diagnose.js +69 -291
- package/dist/cel/environment.d.ts +33 -33
- package/dist/cel/environment.d.ts.map +1 -1
- package/dist/cel/environment.js +54 -80
- package/dist/cel/module-call.d.ts +68 -79
- package/dist/cel/module-call.d.ts.map +1 -1
- package/dist/cel/module-call.js +118 -194
- package/dist/cel/value-brands.d.ts +18 -0
- package/dist/cel/value-brands.d.ts.map +1 -0
- package/dist/cel/value-brands.js +33 -0
- package/dist/cel/verdict-codes.d.ts +40 -0
- package/dist/cel/verdict-codes.d.ts.map +1 -0
- package/dist/cel/verdict-codes.js +43 -0
- package/dist/engine.d.ts +18 -3
- package/dist/engine.d.ts.map +1 -1
- package/dist/engines/cel.d.ts +6 -5
- package/dist/engines/cel.d.ts.map +1 -1
- package/dist/engines/cel.js +57 -82
- package/dist/engines/hole-analysis.d.ts +7 -3
- package/dist/engines/hole-analysis.d.ts.map +1 -1
- package/dist/engines/hole-analysis.js +7 -1
- package/dist/engines/include.js +1 -1
- package/dist/engines/interpolate.d.ts.map +1 -1
- package/dist/engines/interpolate.js +17 -11
- package/dist/engines/module-path.js +1 -1
- package/dist/engines/sql.d.ts.map +1 -1
- package/dist/engines/sql.js +4 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -6
- package/package.json +6 -6
- package/src/builtins.ts +12 -0
- package/src/cel/analyze.ts +152 -193
- package/src/cel/compile.ts +166 -47
- package/src/cel/diagnose.ts +116 -370
- package/src/cel/environment.ts +66 -82
- package/src/cel/module-call.ts +129 -292
- package/src/cel/value-brands.ts +34 -0
- package/src/cel/verdict-codes.ts +66 -0
- package/src/engine.ts +19 -3
- package/src/engines/cel.ts +62 -95
- package/src/engines/hole-analysis.ts +16 -16
- package/src/engines/include.ts +1 -1
- package/src/engines/interpolate.ts +33 -19
- package/src/engines/module-path.ts +1 -1
- package/src/engines/sql.ts +11 -1
- package/src/index.ts +11 -11
- package/dist/cel/catalog.d.ts +0 -67
- package/dist/cel/catalog.d.ts.map +0 -1
- package/dist/cel/catalog.js +0 -1253
- package/dist/cel/value-identity.d.ts +0 -18
- package/dist/cel/value-identity.d.ts.map +0 -1
- package/dist/cel/value-identity.js +0 -25
- package/src/cel/catalog.ts +0 -1379
- package/src/cel/value-identity.ts +0 -34
package/src/cel/diagnose.ts
CHANGED
|
@@ -1,385 +1,131 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { moduleCallOf } from "./module-call.js";
|
|
4
|
-
import type { CallSite, DiagnosticFix, EngineDiagnostic } from "../engine.js";
|
|
5
|
-
|
|
6
|
-
/** Classifies every function call in a CEL expression against the environment's
|
|
7
|
-
* own function registry.
|
|
1
|
+
/**
|
|
2
|
+
* Every function call in a CEL expression, reported for the caller that judges it.
|
|
8
3
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
4
|
+
* **The classifier is gone, and so is its reason for existing.** This file used to decide
|
|
5
|
+
* `CEL_UNKNOWN_FUNCTION`, `CEL_WRONG_CALL_FORM` and `CEL_INVALID_ARGUMENT` itself, by
|
|
6
|
+
* looking every call up in the environment's registry — because the engine it drove reported
|
|
7
|
+
* one sentence for three unrelated mistakes (`found no matching overload for 'f(...)'`), two
|
|
8
|
+
* of whose readings actively misled: the message named argument types, so the repair for
|
|
9
|
+
* `startsWith(key, 'x')` looked like a cast when the fix was `key.startsWith('x')`.
|
|
15
10
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* decidable by lookup, which is what keeps a cel-js version bump from silently
|
|
21
|
-
* degrading this back into the passthrough it replaced. */
|
|
22
|
-
|
|
23
|
-
/** One registered signature, reduced to what classification needs. */
|
|
24
|
-
interface FnEntry {
|
|
25
|
-
readonly signature: string;
|
|
26
|
-
readonly form: "global" | "receiver";
|
|
27
|
-
/** Parameter count, excluding the receiver for a receiver form. */
|
|
28
|
-
readonly arity: number;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface FunctionIndex {
|
|
32
|
-
readonly byName: ReadonlyMap<string, readonly FnEntry[]>;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** Determinism is Telo catalog metadata; cel-js builtins carry none. Absent
|
|
36
|
-
* means "no signal", never "deterministic" — consumers of
|
|
37
|
-
* `CallSite.deterministic` must not read undefined as a guarantee. */
|
|
38
|
-
const DETERMINISM: ReadonlyMap<string, boolean> = new Map(
|
|
39
|
-
CEL_FUNCTIONS.map((f) => [f.name, f.deterministic]),
|
|
40
|
-
);
|
|
41
|
-
const HOST_BACKED: ReadonlyMap<string, boolean> = new Map(
|
|
42
|
-
CEL_FUNCTIONS.map((f) => [f.name, f.hostBacked === true]),
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
/** The flags a module function carries, as the host that resolves it derives
|
|
46
|
-
* them — or undefined where the name reaches no function. */
|
|
47
|
-
export type ModuleCallFlags = (
|
|
48
|
-
qualified: string,
|
|
49
|
-
) => { readonly deterministic: boolean; readonly hostBacked: boolean } | undefined;
|
|
50
|
-
|
|
51
|
-
const INDEX_CACHE = new WeakMap<Environment, FunctionIndex>();
|
|
52
|
-
|
|
53
|
-
/** Registry view of an environment, memoized: environments are rebuilt per
|
|
54
|
-
* analysis path, but each is immutable once built. */
|
|
55
|
-
export function functionIndex(env: Environment): FunctionIndex {
|
|
56
|
-
const cached = INDEX_CACHE.get(env);
|
|
57
|
-
if (cached) return cached;
|
|
58
|
-
|
|
59
|
-
const byName = new Map<string, FnEntry[]>();
|
|
60
|
-
|
|
61
|
-
for (const fn of env.getDefinitions().functions) {
|
|
62
|
-
const form = fn.receiverType === null ? "global" : "receiver";
|
|
63
|
-
const entry: FnEntry = { signature: fn.signature, form, arity: fn.params?.length ?? 0 };
|
|
64
|
-
const entries = byName.get(fn.name);
|
|
65
|
-
if (entries) entries.push(entry);
|
|
66
|
-
else byName.set(fn.name, [entry]);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const index: FunctionIndex = { byName };
|
|
70
|
-
INDEX_CACHE.set(env, index);
|
|
71
|
-
return index;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/** A call plus the nodes needed to rewrite it. Internal — `CallSite` is the
|
|
75
|
-
* shape that crosses the engine seam. */
|
|
76
|
-
interface RawCall extends CallSite {
|
|
77
|
-
readonly receiver?: ASTNode;
|
|
78
|
-
readonly args: readonly ASTNode[];
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/** Macros the parser expands rather than dispatching through the registry, so
|
|
82
|
-
* they never appear in `getDefinitions()` and would otherwise classify as
|
|
83
|
-
* unknown names.
|
|
11
|
+
* `@telorun/cel` decides each of them where the cause is known, with a range and a whole-
|
|
12
|
+
* source fix — an unknown name, a name called in the other form, a type no overload takes,
|
|
13
|
+
* and a refusal over a literal argument (`checkLiteralArguments`, which runs the very code
|
|
14
|
+
* the evaluation runs). So nothing here classifies, and nothing reads a message.
|
|
84
15
|
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
moduleCallFlags: ModuleCallFlags | undefined,
|
|
101
|
-
): RawCall[] {
|
|
102
|
-
const out: RawCall[] = [];
|
|
103
|
-
visit(root);
|
|
104
|
-
return out.sort((a, b) => a.start - b.start);
|
|
105
|
-
|
|
106
|
-
function visit(node: ASTNode): void {
|
|
107
|
-
const args = node.args as unknown;
|
|
108
|
-
// A RESOLVED module call is reported under its QUALIFIED name and is never
|
|
109
|
-
// looked up in the catalog: the two namespaces are disjoint by construction
|
|
110
|
-
// (a bare name is always the catalog), so classifying it here would report
|
|
111
|
-
// `there is no function 'format'` for a call that names a module's own, and
|
|
112
|
-
// attaching the catalog's determinism to it would be a flag about a
|
|
113
|
-
// different function entirely. What a module call's flags are is the
|
|
114
|
-
// resolving host's answer, carried when it gives one.
|
|
115
|
-
const moduleCall = moduleCallOf(node);
|
|
116
|
-
if (moduleCall) {
|
|
117
|
-
const flags = moduleCallFlags?.(moduleCall.qualified);
|
|
118
|
-
out.push({
|
|
119
|
-
name: moduleCall.qualified,
|
|
120
|
-
form: "receiver",
|
|
121
|
-
moduleCall: true,
|
|
122
|
-
arity: moduleCall.args.length,
|
|
123
|
-
start: node.start,
|
|
124
|
-
end: node.end,
|
|
125
|
-
...(flags ? { deterministic: flags.deterministic, hostBacked: flags.hostBacked } : {}),
|
|
126
|
-
args: moduleCall.args,
|
|
127
|
-
});
|
|
128
|
-
for (const arg of moduleCall.args) visit(arg);
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
if (node.op === "call" || node.op === "rcall") {
|
|
132
|
-
const tuple = args as unknown[];
|
|
133
|
-
const name = tuple[0];
|
|
134
|
-
if (typeof name === "string" && !MACROS.has(name)) {
|
|
135
|
-
const receiver = node.op === "rcall" ? tuple[1] : undefined;
|
|
136
|
-
const rawArgs = node.op === "rcall" ? tuple[2] : tuple[1];
|
|
137
|
-
const callArgs = (Array.isArray(rawArgs) ? rawArgs : []).filter(isNode);
|
|
138
|
-
out.push({
|
|
139
|
-
name,
|
|
140
|
-
form: node.op === "rcall" ? "receiver" : "global",
|
|
141
|
-
arity: callArgs.length,
|
|
142
|
-
start: node.start,
|
|
143
|
-
end: node.end,
|
|
144
|
-
...(index.byName.has(name)
|
|
145
|
-
? { deterministic: DETERMINISM.get(name), hostBacked: HOST_BACKED.get(name) }
|
|
146
|
-
: {}),
|
|
147
|
-
...(isNode(receiver) ? { receiver } : {}),
|
|
148
|
-
args: callArgs,
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
for (const arg of Array.isArray(args) ? args : [args]) {
|
|
153
|
-
if (isNode(arg)) visit(arg);
|
|
154
|
-
else if (Array.isArray(arg)) for (const item of arg) if (isNode(item)) visit(item);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/** Node shapes that can carry a `.` on their right without reparsing
|
|
160
|
-
* differently. Everything else — an operator expression, a literal that would
|
|
161
|
-
* sit against the dot — is parenthesized when moved into receiver position. */
|
|
162
|
-
const SELF_DELIMITING = new Set<string>(["id", ".", ".?", "call", "rcall", "[]", "[?]"]);
|
|
163
|
-
|
|
164
|
-
/** Source text of a node. When it is about to become a receiver it may need
|
|
165
|
-
* parentheses: an identifier, member chain, index or call is self-delimiting,
|
|
166
|
-
* but an operator expression or a bare literal against a `.` is not. */
|
|
167
|
-
function nodeText(source: string, node: ASTNode, asReceiver = false): string {
|
|
168
|
-
const text = source.slice(node.start, node.end);
|
|
169
|
-
if (!asReceiver) return text;
|
|
170
|
-
return SELF_DELIMITING.has(node.op) ? text : `(${text})`;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/** The same call written in the other form, or undefined when the shape does
|
|
174
|
-
* not allow it (a global call with no arguments has no receiver to move). */
|
|
175
|
-
function transpose(source: string, call: RawCall): string | undefined {
|
|
176
|
-
if (call.form === "global") {
|
|
177
|
-
const [first, ...rest] = call.args;
|
|
178
|
-
if (!first) return undefined;
|
|
179
|
-
const argText = rest.map((a) => nodeText(source, a));
|
|
180
|
-
return `${nodeText(source, first, true)}.${call.name}(${argText.join(", ")})`;
|
|
181
|
-
}
|
|
182
|
-
if (!call.receiver) return undefined;
|
|
183
|
-
const argText = [nodeText(source, call.receiver), ...call.args.map((a) => nodeText(source, a))];
|
|
184
|
-
return `${call.name}(${argText.join(", ")})`;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/** Splice a rewritten call back into the full source. The fix always carries
|
|
188
|
-
* the whole corrected source, so a consumer applies it by replacing the
|
|
189
|
-
* scalar. */
|
|
190
|
-
function spliceFix(source: string, call: RawCall, rewritten: string): DiagnosticFix {
|
|
191
|
-
return { replacement: source.slice(0, call.start) + rewritten + source.slice(call.end) };
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/** Replace only the called name, leaving arguments untouched. The offset is
|
|
195
|
-
* derived rather than searched: a receiver whose own text contains the name
|
|
196
|
-
* (`slice.slice(1)`) would defeat a first-occurrence replace. */
|
|
197
|
-
function renameFix(source: string, call: RawCall, to: string): DiagnosticFix | undefined {
|
|
198
|
-
const searchFrom = call.receiver ? call.receiver.end : call.start;
|
|
199
|
-
const at = source.indexOf(call.name, searchFrom);
|
|
200
|
-
if (at === -1 || at >= call.end) return undefined;
|
|
201
|
-
return { replacement: source.slice(0, at) + to + source.slice(at + call.name.length) };
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/** Arity the call would need in the other form: moving a receiver in adds an
|
|
205
|
-
* argument, moving it out removes one. */
|
|
206
|
-
function transposedArity(call: RawCall): number {
|
|
207
|
-
return call.form === "global" ? call.arity - 1 : call.arity + 1;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
function accepts(entries: readonly FnEntry[], form: CallSite["form"], arity: number): boolean {
|
|
211
|
-
return entries.some((e) => e.form === form && e.arity === arity);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
const listOf = (names: readonly string[]): string => [...new Set(names)].sort().join(", ");
|
|
215
|
-
|
|
216
|
-
/** Names registered in exactly the form and arity the author wrote — the only
|
|
217
|
-
* ones that could replace this call with no further edits. Ranked by shared
|
|
218
|
-
* prefix, which is what reaches `nowIso` from `no`; edit distance never
|
|
219
|
-
* would (4 characters against a 2-character name). Returns [] when nothing
|
|
220
|
-
* shares a prefix, so the caller lists what is legal here instead of
|
|
221
|
-
* guessing. */
|
|
222
|
-
function candidates(call: RawCall, index: FunctionIndex): string[] {
|
|
223
|
-
const written = call.name.toLowerCase();
|
|
224
|
-
return callableHere(call, index)
|
|
225
|
-
.filter((name) => {
|
|
226
|
-
const lower = name.toLowerCase();
|
|
227
|
-
return lower.startsWith(written) || written.startsWith(lower);
|
|
228
|
-
})
|
|
229
|
-
.sort((a, b) => a.length - b.length || a.localeCompare(b));
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/** Every name callable in exactly the position written — same form, same
|
|
233
|
-
* argument count. Arity is what makes the list usable: a receiver's type is
|
|
234
|
-
* `dyn` at analysis time so every method is nominally reachable, and printing
|
|
235
|
-
* all forty says nothing. */
|
|
236
|
-
function callableHere(call: RawCall, index: FunctionIndex): string[] {
|
|
237
|
-
const names: string[] = [];
|
|
238
|
-
for (const [name, entries] of index.byName) {
|
|
239
|
-
if (name !== call.name && accepts(entries, call.form, call.arity)) names.push(name);
|
|
240
|
-
}
|
|
241
|
-
return names;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
function signaturesOf(name: string, index: FunctionIndex): string[] {
|
|
245
|
-
return (index.byName.get(name) ?? []).map((e) => e.signature);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
/** Spread-friendly optional `fix`, so an undecidable rewrite simply omits the
|
|
249
|
-
* field rather than carrying `undefined` into the diagnostic. */
|
|
250
|
-
const withFix = (fix: DiagnosticFix | undefined): { fix?: DiagnosticFix } => (fix ? { fix } : {});
|
|
251
|
-
|
|
252
|
-
/** The literal value of an argument, or `undefined` when it is an expression
|
|
253
|
-
* whose value is not statically known. A negated numeric literal is one node
|
|
254
|
-
* out (`-1` parses as unary minus over a value), and reading it is what lets a
|
|
255
|
-
* bound like "0–10" catch the below-range case as well as the above. */
|
|
256
|
-
function literalOf(node: ASTNode): unknown {
|
|
257
|
-
if (node.op === "value") return node.args;
|
|
258
|
-
if (node.op === "-_") {
|
|
259
|
-
const inner = node.args;
|
|
260
|
-
if (isNode(inner) && inner.op === "value") {
|
|
261
|
-
const v = inner.args as unknown;
|
|
262
|
-
if (typeof v === "number") return -v;
|
|
263
|
-
if (typeof v === "bigint") return -v;
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
return undefined;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
const ARG_CHECKS: ReadonlyMap<string, NonNullable<CelFunctionDoc["checkArgs"]>> = new Map(
|
|
270
|
-
CEL_FUNCTIONS.flatMap((f) => (f.checkArgs ? [[f.name, f.checkArgs] as const] : [])),
|
|
271
|
-
);
|
|
272
|
-
|
|
16
|
+
* What is left is Telo's half: the call LIST, which the analyzer needs to judge whether a
|
|
17
|
+
* module call reaches a function at all (`FUNCTION_UNRESOLVED` / `_NOT_EXPORTED` /
|
|
18
|
+
* `_NOT_CALLABLE` / `_ARITY_MISMATCH` / `_ARGUMENT_MISMATCH`) — a verdict that is manifest
|
|
19
|
+
* context and never this engine's.
|
|
20
|
+
*/
|
|
21
|
+
import type { CelEnvironment, CelNode, CheckResult } from "@telorun/cel";
|
|
22
|
+
import { moduleCallArgumentChains } from "./analyze.js";
|
|
23
|
+
import type { CallSite, EngineDiagnostic } from "../engine.js";
|
|
24
|
+
import type { CelCallAudit } from "./verdict-codes.js";
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* What one audit establishes. The diagnostic lists stay on the shape because the ANALYZER
|
|
28
|
+
* reads them: they are now always empty from here — the engine's checker decides every
|
|
29
|
+
* verdict about a call — and a caller that merged two lists keeps doing so unchanged.
|
|
30
|
+
*/
|
|
273
31
|
export interface CallAudit {
|
|
274
32
|
readonly diagnostics: readonly EngineDiagnostic[];
|
|
33
|
+
/** Every function call in the source, in source order. */
|
|
275
34
|
readonly calls: readonly CallSite[];
|
|
276
|
-
/**
|
|
277
|
-
* type-checker said, unlike {@link CallAudit.diagnostics}: a call whose types
|
|
278
|
-
* are all correct and whose specifier is `.2q` type-checks perfectly, and is
|
|
279
|
-
* exactly the defect this catches. */
|
|
280
|
-
readonly argumentIssues: readonly EngineDiagnostic[];
|
|
281
|
-
/** Names that resolve, but that no registered signature accepts as written.
|
|
282
|
-
* The caller appends their signatures to a type-check failure it could not
|
|
283
|
-
* otherwise explain. */
|
|
35
|
+
/** Names a type-check failure mentions that resolved to nothing. */
|
|
284
36
|
readonly unresolved: readonly string[];
|
|
37
|
+
/** Refusals over a literal argument. The engine decides these at check now. */
|
|
38
|
+
readonly argumentIssues: readonly EngineDiagnostic[];
|
|
285
39
|
}
|
|
286
40
|
|
|
287
|
-
/**
|
|
288
|
-
*
|
|
289
|
-
*
|
|
290
|
-
*
|
|
41
|
+
/**
|
|
42
|
+
* The flags a module function carries, as the host that resolves it derives them — or
|
|
43
|
+
* undefined where the name reaches no function. Absent means "no signal", never
|
|
44
|
+
* "deterministic".
|
|
45
|
+
*/
|
|
46
|
+
export type ModuleCallFlags = (
|
|
47
|
+
qualified: string,
|
|
48
|
+
) => { readonly deterministic: boolean; readonly hostBacked: boolean } | undefined;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Every call the expression makes, with what the checker resolved about it.
|
|
52
|
+
*
|
|
53
|
+
* A module call carries no catalog flag: what a module function's determinism and
|
|
54
|
+
* host-backedness are follows from the callable it resolves to, so they are carried only as
|
|
55
|
+
* the host's `moduleCallFlags` reports them, and stay absent where it gives nothing.
|
|
56
|
+
*/
|
|
291
57
|
export function auditCalls(
|
|
292
58
|
source: string,
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
/** The flags of the module functions the expression calls, from whoever
|
|
296
|
-
* resolves them. */
|
|
59
|
+
root: CelNode,
|
|
60
|
+
environment: CelEnvironment,
|
|
297
61
|
moduleCallFlags?: ModuleCallFlags,
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
const diagnostics:
|
|
301
|
-
const
|
|
302
|
-
const
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
...withFix(rewritten ? spliceFix(source, call, rewritten) : undefined),
|
|
348
|
-
});
|
|
349
|
-
continue;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
unresolved.push(call.name);
|
|
62
|
+
checked?: CheckResult,
|
|
63
|
+
): CelCallAudit {
|
|
64
|
+
const result = checked ?? environment.check({ source, root, namespaces: environment.namespaces(), diagnostics: [] });
|
|
65
|
+
const argumentChains = moduleCallArgumentChains(root);
|
|
66
|
+
const byNode = new Map(
|
|
67
|
+
[...argumentChains].map(([node, chains]) => [`${node.range[0]}:${node.range[1]}`, chains]),
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
// **One entry per call.** The checker already lists a qualified call — with `namespace`
|
|
71
|
+
// set and `form: "receiver"`, which is how it was written — so appending a second entry
|
|
72
|
+
// per `qualifiedCalls` showed every module call twice, with two contradictory forms, to
|
|
73
|
+
// every consumer that iterates this list.
|
|
74
|
+
const calls: CallSite[] = [];
|
|
75
|
+
for (const call of result.calls) {
|
|
76
|
+
const qualified = call.namespace !== undefined;
|
|
77
|
+
const flags = qualified ? moduleCallFlags?.(call.name) : undefined;
|
|
78
|
+
const chains = qualified ? byNode.get(`${call.range[0]}:${call.range[1]}`) : undefined;
|
|
79
|
+
calls.push({
|
|
80
|
+
name: call.name,
|
|
81
|
+
form: call.form,
|
|
82
|
+
arity: call.arity,
|
|
83
|
+
start: call.range[0],
|
|
84
|
+
end: call.range[1],
|
|
85
|
+
...(qualified ? { moduleCall: true as const } : {}),
|
|
86
|
+
// A module call's arguments as the analysis saw them: the type the checker gives each
|
|
87
|
+
// one, and the chain where the argument IS one — so a caller holding the callee's
|
|
88
|
+
// signature can compare a declared shape rather than a CEL type alone.
|
|
89
|
+
...(qualified && call.argumentTypes
|
|
90
|
+
? {
|
|
91
|
+
arguments: call.argumentTypes.map((type, at) => {
|
|
92
|
+
const chain = chains?.[at] ?? null;
|
|
93
|
+
return {
|
|
94
|
+
...(type === "dyn" ? {} : { type }),
|
|
95
|
+
...(chain ? { chain } : {}),
|
|
96
|
+
};
|
|
97
|
+
}),
|
|
98
|
+
}
|
|
99
|
+
: {}),
|
|
100
|
+
// A module call carries no catalog flag: its determinism and host-backedness follow
|
|
101
|
+
// from the callable the name resolves to, which only the host that resolves it knows.
|
|
102
|
+
...(qualified
|
|
103
|
+
? flags
|
|
104
|
+
? { deterministic: flags.deterministic, hostBacked: flags.hostBacked }
|
|
105
|
+
: {}
|
|
106
|
+
: {
|
|
107
|
+
...(call.deterministic === undefined ? {} : { deterministic: call.deterministic }),
|
|
108
|
+
...(call.hostBacked === undefined ? {} : { hostBacked: call.hostBacked }),
|
|
109
|
+
}),
|
|
110
|
+
});
|
|
353
111
|
}
|
|
354
112
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
unresolved,
|
|
374
|
-
argumentIssues,
|
|
375
|
-
};
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
/** Registered signatures for names a type-check failure mentions, so the
|
|
379
|
-
* residual says what the function actually accepts rather than only echoing
|
|
380
|
-
* what the author wrote. */
|
|
381
|
-
export function explainUnresolved(names: readonly string[], env: Environment): string {
|
|
382
|
-
const index = functionIndex(env);
|
|
383
|
-
const signatures = [...new Set(names)].flatMap((n) => signaturesOf(n, index));
|
|
384
|
-
return signatures.length > 0 ? ` Registered: ${listOf(signatures)}.` : "";
|
|
113
|
+
calls.sort((left, right) => left.start - right.start || left.end - right.end);
|
|
114
|
+
return { diagnostics: [], calls, unresolved: [], argumentIssues: [] };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Registered signatures for names a type-check failure mentions, so a residual message says
|
|
119
|
+
* what the function actually accepts rather than only echoing what the author wrote.
|
|
120
|
+
*/
|
|
121
|
+
export function explainUnresolved(names: readonly string[], environment: CelEnvironment): string {
|
|
122
|
+
const wanted = new Set(names);
|
|
123
|
+
const signatures = environment
|
|
124
|
+
.definitions()
|
|
125
|
+
.functions.filter((entry) => wanted.has(entry.name))
|
|
126
|
+
.map((entry) => entry.signature);
|
|
127
|
+
if (signatures.length === 0) return "";
|
|
128
|
+
const listed = [...new Set(signatures)].map((signature) => `\`${signature}\``);
|
|
129
|
+
const last = listed.pop()!;
|
|
130
|
+
return ` Registered: ${listed.length > 0 ? `${listed.join(", ")} and ${last}` : last}.`;
|
|
385
131
|
}
|