@telorun/templating 0.20.0 → 0.21.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/cel/analyze.d.ts +26 -0
- package/dist/cel/analyze.d.ts.map +1 -1
- package/dist/cel/analyze.js +114 -8
- package/dist/cel/catalog.d.ts.map +1 -1
- package/dist/cel/catalog.js +10 -0
- package/dist/cel/compile.d.ts +9 -3
- package/dist/cel/compile.d.ts.map +1 -1
- package/dist/cel/compile.js +25 -11
- package/dist/cel/diagnose.d.ts +10 -1
- package/dist/cel/diagnose.d.ts.map +1 -1
- package/dist/cel/diagnose.js +42 -6
- package/dist/cel/environment.d.ts.map +1 -1
- package/dist/cel/environment.js +2 -0
- package/dist/cel/module-call.d.ts +108 -0
- package/dist/cel/module-call.d.ts.map +1 -0
- package/dist/cel/module-call.js +245 -0
- package/dist/cel/value-identity.d.ts +18 -0
- package/dist/cel/value-identity.d.ts.map +1 -0
- package/dist/cel/value-identity.js +25 -0
- package/dist/engine.d.ts +66 -0
- package/dist/engine.d.ts.map +1 -1
- package/dist/engines/cel.d.ts.map +1 -1
- package/dist/engines/cel.js +87 -6
- package/dist/engines/sql.d.ts.map +1 -1
- package/dist/engines/sql.js +5 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/package.json +3 -3
- package/src/cel/analyze.ts +131 -9
- package/src/cel/catalog.ts +10 -0
- package/src/cel/compile.ts +32 -12
- package/src/cel/diagnose.ts +56 -6
- package/src/cel/environment.ts +3 -0
- package/src/cel/module-call.ts +369 -0
- package/src/cel/value-identity.ts +34 -0
- package/src/engine.ts +72 -0
- package/src/engines/cel.ts +104 -6
- package/src/engines/sql.ts +5 -1
- package/src/index.ts +20 -1
package/dist/cel/analyze.d.ts
CHANGED
|
@@ -4,12 +4,38 @@ import type { ASTNode } from "@marcbachmann/cel-js";
|
|
|
4
4
|
* Returns arrays like ["request", "query", "name"] for `request.query.name`.
|
|
5
5
|
* Chains that start with a call or non-identifier root are ignored.
|
|
6
6
|
* Bound variables in comprehension macros (filter, map, exists, all, exists_one) are excluded.
|
|
7
|
+
*
|
|
8
|
+
* A RESOLVED module call contributes no chain for its receiver: `Billing` in
|
|
9
|
+
* `Billing.format(x)` names a module, not a value, so reading it as a root
|
|
10
|
+
* would invent a dependency, an undeclared identifier and a `resources` read
|
|
11
|
+
* that the expression never states. Resolution is `resolveModuleCalls`, on the
|
|
12
|
+
* tree, before this walk — an unresolved tree still reports the receiver, which
|
|
13
|
+
* is the right answer for a caller that supplied no module names.
|
|
7
14
|
*/
|
|
8
15
|
export declare function extractAccessChains(node: ASTNode): string[][];
|
|
16
|
+
/**
|
|
17
|
+
* Each resolved module call's arguments as plain member chains, keyed by the
|
|
18
|
+
* call's node — `null` for an argument that is not one, or that is rooted at a
|
|
19
|
+
* name the expression itself binds (`xs.map(item, Billing.total(item))`), which
|
|
20
|
+
* no context schema describes.
|
|
21
|
+
*/
|
|
22
|
+
export declare function moduleCallArgumentChains(node: ASTNode): Map<ASTNode, Array<string[] | null>>;
|
|
9
23
|
/** Sentinel chain segment emitted for index access (`obj[expr]`) — a dynamic
|
|
10
24
|
* member that can't be resolved to a static name. Consumers that attribute
|
|
11
25
|
* chains to declared names treat this as "unknown member". */
|
|
12
26
|
export declare const INDEX_SEGMENT = "[*]";
|
|
27
|
+
/** A member access on a module call's result: the call, and the members read
|
|
28
|
+
* off it in order (`Billing.total(xs).amount` → `amount`). */
|
|
29
|
+
export interface CallResultAccess {
|
|
30
|
+
readonly qualified: string;
|
|
31
|
+
readonly members: readonly string[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Every member access whose base is a module call, longest first — the chains
|
|
35
|
+
* {@link extractAccessChains} deliberately skips, since their root is a value
|
|
36
|
+
* no context schema describes. The caller supplies the call's result schema.
|
|
37
|
+
*/
|
|
38
|
+
export declare function extractCallResultAccesses(node: ASTNode): CallResultAccess[];
|
|
13
39
|
interface NullableIssue {
|
|
14
40
|
/** Dotted path of the nullable value being dereferenced (e.g. "error"). */
|
|
15
41
|
path: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analyze.d.ts","sourceRoot":"","sources":["../../src/cel/analyze.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"analyze.d.ts","sourceRoot":"","sources":["../../src/cel/analyze.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAIpD;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,EAAE,EAAE,CAI7D;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,OAAO,GAAG,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC,CAS5F;AAwGD;;+DAE+D;AAC/D,eAAO,MAAM,aAAa,QAAQ,CAAC;AAqBnC;+DAC+D;AAC/D,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;CACrC;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,OAAO,GAAG,gBAAgB,EAAE,CAI3E;AAqCD,UAAU,aAAa;IACrB,2EAA2E;IAC3E,IAAI,EAAE,MAAM,CAAC;IACb,6DAA6D;IAC7D,MAAM,EAAE,MAAM,CAAC;CAChB;AAoFD;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,OAAO,EACb,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACjC,aAAa,EAAE,CAIjB;AA4GD;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,MAAM,EAAE,EACf,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC1B,MAAM,GAAG,IAAI,CAwCf"}
|
package/dist/cel/analyze.js
CHANGED
|
@@ -1,15 +1,36 @@
|
|
|
1
1
|
import { isLiveSlot } from "@telorun/sdk";
|
|
2
|
+
import { moduleCallOf } from "./module-call.js";
|
|
2
3
|
/**
|
|
3
4
|
* Extract all member-access chains from a CEL AST.
|
|
4
5
|
* Returns arrays like ["request", "query", "name"] for `request.query.name`.
|
|
5
6
|
* Chains that start with a call or non-identifier root are ignored.
|
|
6
7
|
* Bound variables in comprehension macros (filter, map, exists, all, exists_one) are excluded.
|
|
8
|
+
*
|
|
9
|
+
* A RESOLVED module call contributes no chain for its receiver: `Billing` in
|
|
10
|
+
* `Billing.format(x)` names a module, not a value, so reading it as a root
|
|
11
|
+
* would invent a dependency, an undeclared identifier and a `resources` read
|
|
12
|
+
* that the expression never states. Resolution is `resolveModuleCalls`, on the
|
|
13
|
+
* tree, before this walk — an unresolved tree still reports the receiver, which
|
|
14
|
+
* is the right answer for a caller that supplied no module names.
|
|
7
15
|
*/
|
|
8
16
|
export function extractAccessChains(node) {
|
|
9
17
|
const chains = [];
|
|
10
18
|
visitNode(node, chains, new Set());
|
|
11
19
|
return chains;
|
|
12
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Each resolved module call's arguments as plain member chains, keyed by the
|
|
23
|
+
* call's node — `null` for an argument that is not one, or that is rooted at a
|
|
24
|
+
* name the expression itself binds (`xs.map(item, Billing.total(item))`), which
|
|
25
|
+
* no context schema describes.
|
|
26
|
+
*/
|
|
27
|
+
export function moduleCallArgumentChains(node) {
|
|
28
|
+
const out = new Map();
|
|
29
|
+
visitNode(node, [], new Set(), (call, callNode, boundVars) => {
|
|
30
|
+
out.set(callNode, call.args.map((arg) => extractChain(arg, boundVars)));
|
|
31
|
+
});
|
|
32
|
+
return out;
|
|
33
|
+
}
|
|
13
34
|
const COMPREHENSION_METHODS = new Set(["filter", "map", "exists", "all", "exists_one"]);
|
|
14
35
|
/** `cel.bind(name, init, body)` — CEL's only binding form, and the one the
|
|
15
36
|
* parser expands rather than dispatching, so it appears as a receiver call on a
|
|
@@ -35,18 +56,25 @@ function bindCall(node) {
|
|
|
35
56
|
return null;
|
|
36
57
|
return { name: nameNode.args, init, body };
|
|
37
58
|
}
|
|
38
|
-
function visitNode(node, chains, boundVars) {
|
|
59
|
+
function visitNode(node, chains, boundVars, onModuleCall) {
|
|
39
60
|
const chain = extractChain(node, boundVars);
|
|
40
61
|
if (chain !== null) {
|
|
41
62
|
chains.push(chain);
|
|
42
63
|
return;
|
|
43
64
|
}
|
|
65
|
+
const moduleCall = moduleCallOf(node);
|
|
66
|
+
if (moduleCall) {
|
|
67
|
+
onModuleCall?.(moduleCall, node, boundVars);
|
|
68
|
+
for (const arg of moduleCall.args)
|
|
69
|
+
visitNode(arg, chains, boundVars, onModuleCall);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
44
72
|
// The bound name is in scope for the body ONLY; `init` is evaluated in the
|
|
45
73
|
// enclosing scope, so a name used there still has to resolve there.
|
|
46
74
|
const bind = bindCall(node);
|
|
47
75
|
if (bind) {
|
|
48
|
-
visitNode(bind.init, chains, boundVars);
|
|
49
|
-
visitNode(bind.body, chains, new Set(boundVars).add(bind.name));
|
|
76
|
+
visitNode(bind.init, chains, boundVars, onModuleCall);
|
|
77
|
+
visitNode(bind.body, chains, new Set(boundVars).add(bind.name), onModuleCall);
|
|
50
78
|
return;
|
|
51
79
|
}
|
|
52
80
|
if (node.op === "rcall" &&
|
|
@@ -56,7 +84,7 @@ function visitNode(node, chains, boundVars) {
|
|
|
56
84
|
const receiver = node.args[1];
|
|
57
85
|
const comprehensionArgs = node.args[2];
|
|
58
86
|
if (isASTNode(receiver))
|
|
59
|
-
visitNode(receiver, chains, boundVars);
|
|
87
|
+
visitNode(receiver, chains, boundVars, onModuleCall);
|
|
60
88
|
if (Array.isArray(comprehensionArgs) &&
|
|
61
89
|
comprehensionArgs.length >= 2 &&
|
|
62
90
|
isASTNode(comprehensionArgs[0]) &&
|
|
@@ -66,7 +94,7 @@ function visitNode(node, chains, boundVars) {
|
|
|
66
94
|
for (let i = 1; i < comprehensionArgs.length; i++) {
|
|
67
95
|
const arg = comprehensionArgs[i];
|
|
68
96
|
if (isASTNode(arg))
|
|
69
|
-
visitNode(arg, chains, newBoundVars);
|
|
97
|
+
visitNode(arg, chains, newBoundVars, onModuleCall);
|
|
70
98
|
}
|
|
71
99
|
}
|
|
72
100
|
return;
|
|
@@ -75,12 +103,12 @@ function visitNode(node, chains, boundVars) {
|
|
|
75
103
|
if (Array.isArray(args)) {
|
|
76
104
|
for (const arg of args) {
|
|
77
105
|
if (isASTNode(arg)) {
|
|
78
|
-
visitNode(arg, chains, boundVars);
|
|
106
|
+
visitNode(arg, chains, boundVars, onModuleCall);
|
|
79
107
|
}
|
|
80
108
|
else if (Array.isArray(arg)) {
|
|
81
109
|
for (const item of arg) {
|
|
82
110
|
if (isASTNode(item))
|
|
83
|
-
visitNode(item, chains, boundVars);
|
|
111
|
+
visitNode(item, chains, boundVars, onModuleCall);
|
|
84
112
|
}
|
|
85
113
|
}
|
|
86
114
|
}
|
|
@@ -88,7 +116,7 @@ function visitNode(node, chains, boundVars) {
|
|
|
88
116
|
else if (isASTNode(args)) {
|
|
89
117
|
// Unary operators (`!_`, `-_`) carry their operand as a single node
|
|
90
118
|
// rather than a one-element array, so descend into it directly.
|
|
91
|
-
visitNode(args, chains, boundVars);
|
|
119
|
+
visitNode(args, chains, boundVars, onModuleCall);
|
|
92
120
|
}
|
|
93
121
|
}
|
|
94
122
|
function isASTNode(v) {
|
|
@@ -119,6 +147,58 @@ function extractChain(node, boundVars) {
|
|
|
119
147
|
}
|
|
120
148
|
return null;
|
|
121
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* Every member access whose base is a module call, longest first — the chains
|
|
152
|
+
* {@link extractAccessChains} deliberately skips, since their root is a value
|
|
153
|
+
* no context schema describes. The caller supplies the call's result schema.
|
|
154
|
+
*/
|
|
155
|
+
export function extractCallResultAccesses(node) {
|
|
156
|
+
const out = [];
|
|
157
|
+
visitAccess(node, out);
|
|
158
|
+
return out;
|
|
159
|
+
}
|
|
160
|
+
function visitAccess(node, out) {
|
|
161
|
+
if (node.op === "." || node.op === "[]") {
|
|
162
|
+
const members = [];
|
|
163
|
+
let base = node;
|
|
164
|
+
while (base.op === "." || base.op === "[]") {
|
|
165
|
+
const [obj, field] = base.args;
|
|
166
|
+
members.unshift(base.op === "." ? String(field) : INDEX_SEGMENT);
|
|
167
|
+
if (base.op === "[]" && isASTNode(field))
|
|
168
|
+
visitAccess(field, out);
|
|
169
|
+
base = obj;
|
|
170
|
+
}
|
|
171
|
+
const call = moduleCallOf(base);
|
|
172
|
+
if (call) {
|
|
173
|
+
out.push({ qualified: call.qualified, members });
|
|
174
|
+
for (const arg of call.args)
|
|
175
|
+
visitAccess(arg, out);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
visitAccess(base, out);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
const moduleCall = moduleCallOf(node);
|
|
182
|
+
if (moduleCall) {
|
|
183
|
+
for (const arg of moduleCall.args)
|
|
184
|
+
visitAccess(arg, out);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
const args = node.args;
|
|
188
|
+
if (Array.isArray(args)) {
|
|
189
|
+
for (const arg of args) {
|
|
190
|
+
if (isASTNode(arg))
|
|
191
|
+
visitAccess(arg, out);
|
|
192
|
+
else if (Array.isArray(arg))
|
|
193
|
+
for (const item of arg)
|
|
194
|
+
if (isASTNode(item))
|
|
195
|
+
visitAccess(item, out);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
else if (isASTNode(args)) {
|
|
199
|
+
visitAccess(args, out);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
122
202
|
/** True when a JSON Schema admits `null` — `type: "null"` or a union that
|
|
123
203
|
* includes it (e.g. `["object", "null"]`). */
|
|
124
204
|
function schemaIsNullable(schema) {
|
|
@@ -242,6 +322,14 @@ function walkNullable(node, nonNull, boundVars, issues, schema) {
|
|
|
242
322
|
walkNullable(b, union(nonNull, carried), boundVars, issues, schema);
|
|
243
323
|
return;
|
|
244
324
|
}
|
|
325
|
+
// A module call's receiver is a module name, not a value; mirror
|
|
326
|
+
// extractAccessChains so it is never read as a nullable context field.
|
|
327
|
+
const moduleCall = moduleCallOf(node);
|
|
328
|
+
if (moduleCall) {
|
|
329
|
+
for (const arg of moduleCall.args)
|
|
330
|
+
walkNullable(arg, nonNull, boundVars, issues, schema);
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
245
333
|
// `cel.bind` binds a name for its body; mirror extractAccessChains so a bound
|
|
246
334
|
// name is never read as a nullable context field.
|
|
247
335
|
const bind = bindCall(node);
|
|
@@ -305,6 +393,24 @@ export function validateChainAgainstSchema(chain, schema) {
|
|
|
305
393
|
const key = chain[i];
|
|
306
394
|
if (!current || typeof current !== "object")
|
|
307
395
|
return null;
|
|
396
|
+
// An index reads an ELEMENT: an array's `items`, or a map's value schema. What
|
|
397
|
+
// is below it is checked like any member access, which is what reaches a
|
|
398
|
+
// typo inside a list of records (`items[0].amont`). An object that also
|
|
399
|
+
// declares `properties` may be indexed by one of those names, which the
|
|
400
|
+
// chain does not record, so nothing below it is judged.
|
|
401
|
+
if (key === INDEX_SEGMENT) {
|
|
402
|
+
const element = current.items && typeof current.items === "object" && !Array.isArray(current.items)
|
|
403
|
+
? current.items
|
|
404
|
+
: !current.properties &&
|
|
405
|
+
current.additionalProperties &&
|
|
406
|
+
typeof current.additionalProperties === "object"
|
|
407
|
+
? current.additionalProperties
|
|
408
|
+
: undefined;
|
|
409
|
+
if (!element)
|
|
410
|
+
return null;
|
|
411
|
+
current = element;
|
|
412
|
+
continue;
|
|
413
|
+
}
|
|
308
414
|
const props = current.properties;
|
|
309
415
|
if (!props)
|
|
310
416
|
return null;
|
|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GACV,SAAS,GACT,YAAY,GACZ,MAAM,CAAC;AAEX;;;qBAGqB;AACrB,MAAM,WAAW,cAAc;IAC7B,+CAA+C;IAC/C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;0EACsE;IACtE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B;;;;yDAIqD;IACrD,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,QAAQ,CAAC,QAAQ,EAAE,mBAAmB,CAAC;IACvC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB;wBACoB;IACpB,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC;IAChC;2EACuE;IACvE,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,WAAW,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC;IAChE;;;;;;;;;;;;;;;;OAgBG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,QAAQ,EAAE,SAAS,OAAO,EAAE,KAAK,MAAM,GAAG,SAAS,CAAC;CAC3E;AAYD,wEAAwE;AACxE,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;AA8Z5D,eAAO,MAAM,aAAa,EAAE,SAAS,cAAc,EAmyBlD,CAAC;AAEF,oEAAoE;AACpE,wBAAgB,kBAAkB,IAAI,eAAe,EAAE,CAEtD"}
|
package/dist/cel/catalog.js
CHANGED
|
@@ -915,6 +915,16 @@ export const CEL_FUNCTIONS = [
|
|
|
915
915
|
},
|
|
916
916
|
// Time (non-deterministic). `nowIso`/`today` take an optional IANA timezone
|
|
917
917
|
// (default "UTC"); epoch values are absolute and take none.
|
|
918
|
+
{
|
|
919
|
+
name: "now",
|
|
920
|
+
signature: "now(): timestamp",
|
|
921
|
+
register: ["now(): google.protobuf.Timestamp"],
|
|
922
|
+
category: "time",
|
|
923
|
+
summary: "Current instant as a native timestamp, for comparison and duration arithmetic.",
|
|
924
|
+
deterministic: false,
|
|
925
|
+
hostBacked: false,
|
|
926
|
+
build: () => () => new Date(),
|
|
927
|
+
},
|
|
918
928
|
{
|
|
919
929
|
name: "nowIso",
|
|
920
930
|
signature: "nowIso(string?): string",
|
package/dist/cel/compile.d.ts
CHANGED
|
@@ -4,14 +4,20 @@ export declare const TEMPLATE_REGEX: RegExp;
|
|
|
4
4
|
export declare const EXACT_TEMPLATE_REGEX: RegExp;
|
|
5
5
|
/** Compile a single CEL expression (no `${{ }}` wrapping) into a CompiledValue.
|
|
6
6
|
* Throws on syntax errors. Used by the `!cel` engine where the entire tagged
|
|
7
|
-
* scalar is treated as one expression.
|
|
8
|
-
|
|
7
|
+
* scalar is treated as one expression.
|
|
8
|
+
*
|
|
9
|
+
* `moduleNames` are the declaring module's own names; a call whose receiver is
|
|
10
|
+
* one of them resolves to a late-bound module call HERE, on the parsed tree, so
|
|
11
|
+
* every later reader — the root references below, the analyzer's passes, the
|
|
12
|
+
* kernel's dependency walk — sees the resolved shape rather than re-deriving
|
|
13
|
+
* it from the source text. */
|
|
14
|
+
export declare function compileExpression(expr: string, env: Environment, moduleNames?: ReadonlySet<string>): CompiledValue;
|
|
9
15
|
/** Compile a string that may contain `${{ }}`-delimited CEL segments. If the
|
|
10
16
|
* string is exactly one expression, returns a single CompiledValue. If it
|
|
11
17
|
* contains interpolations, returns a CompiledValue that joins literal parts
|
|
12
18
|
* with stringified expression results. If no expressions are present, returns
|
|
13
19
|
* the input string unchanged. Throws on CEL syntax errors. */
|
|
14
|
-
export declare function compileString(s: string, env: Environment): unknown;
|
|
20
|
+
export declare function compileString(s: string, env: Environment, moduleNames?: ReadonlySet<string>): unknown;
|
|
15
21
|
/** Split an interpolated value into literal fragments and the evaluated values
|
|
16
22
|
* of its embedded expressions, instead of joining them into one string. Lets a
|
|
17
23
|
* consumer emit its own placeholders between fragments and bind the values
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/cel/compile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/cel/compile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,KAAK,EAAW,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAIjE,eAAO,MAAM,cAAc,QAA8B,CAAC;AAC1D,eAAO,MAAM,oBAAoB,QAAqC,CAAC;AAcvE;;;;;;;;+BAQ+B;AAC/B,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,WAAW,EAChB,WAAW,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,GAChC,aAAa,CAWf;AAED;;;;+DAI+D;AAC/D,wBAAgB,aAAa,CAC3B,CAAC,EAAE,MAAM,EACT,GAAG,EAAE,WAAW,EAChB,WAAW,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,GAChC,OAAO,CAkCT;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC3B;IAAE,SAAS,EAAE,MAAM,EAAE,CAAC;IAAC,MAAM,EAAE,OAAO,EAAE,CAAA;CAAE,CAsB5C"}
|
package/dist/cel/compile.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import { isCompiledValue } from "@telorun/sdk";
|
|
2
2
|
import { extractAccessChains } from "./analyze.js";
|
|
3
|
+
import { resolveModuleCalls } from "./module-call.js";
|
|
3
4
|
export const TEMPLATE_REGEX = /\$\{\{\s*([^}]+?)\s*\}\}/g;
|
|
4
5
|
export const EXACT_TEMPLATE_REGEX = /^\s*\$\{\{\s*([^}]+?)\s*\}\}\s*$/;
|
|
5
6
|
/** Root variable identifiers an expression reads, from its parsed AST — the
|
|
6
7
|
* first element of every member-access chain (`self.table` → `self`). Returns
|
|
7
8
|
* undefined when the parse result carries no AST so consumers can tell "no
|
|
8
9
|
* refs" from "unknown". */
|
|
9
|
-
function rootRefs(
|
|
10
|
-
const ast = parsed.ast;
|
|
11
|
-
if (!ast)
|
|
12
|
-
return undefined;
|
|
10
|
+
function rootRefs(ast) {
|
|
13
11
|
const roots = new Set();
|
|
14
12
|
for (const chain of extractAccessChains(ast)) {
|
|
15
13
|
if (chain.length > 0)
|
|
@@ -19,13 +17,22 @@ function rootRefs(parsed) {
|
|
|
19
17
|
}
|
|
20
18
|
/** Compile a single CEL expression (no `${{ }}` wrapping) into a CompiledValue.
|
|
21
19
|
* Throws on syntax errors. Used by the `!cel` engine where the entire tagged
|
|
22
|
-
* scalar is treated as one expression.
|
|
23
|
-
|
|
20
|
+
* scalar is treated as one expression.
|
|
21
|
+
*
|
|
22
|
+
* `moduleNames` are the declaring module's own names; a call whose receiver is
|
|
23
|
+
* one of them resolves to a late-bound module call HERE, on the parsed tree, so
|
|
24
|
+
* every later reader — the root references below, the analyzer's passes, the
|
|
25
|
+
* kernel's dependency walk — sees the resolved shape rather than re-deriving
|
|
26
|
+
* it from the source text. */
|
|
27
|
+
export function compileExpression(expr, env, moduleNames) {
|
|
24
28
|
const fn = env.parse(expr);
|
|
29
|
+
const ast = fn.ast;
|
|
30
|
+
const calls = resolveModuleCalls(ast, moduleNames);
|
|
25
31
|
return {
|
|
26
32
|
__compiled: true,
|
|
27
33
|
source: expr,
|
|
28
|
-
refs: rootRefs(
|
|
34
|
+
refs: rootRefs(ast),
|
|
35
|
+
calls,
|
|
29
36
|
call: (ctx) => fn(ctx),
|
|
30
37
|
};
|
|
31
38
|
}
|
|
@@ -34,34 +41,41 @@ export function compileExpression(expr, env) {
|
|
|
34
41
|
* contains interpolations, returns a CompiledValue that joins literal parts
|
|
35
42
|
* with stringified expression results. If no expressions are present, returns
|
|
36
43
|
* the input string unchanged. Throws on CEL syntax errors. */
|
|
37
|
-
export function compileString(s, env) {
|
|
44
|
+
export function compileString(s, env, moduleNames) {
|
|
38
45
|
if (!s.includes("${{"))
|
|
39
46
|
return s;
|
|
40
47
|
const exact = s.match(EXACT_TEMPLATE_REGEX);
|
|
41
48
|
if (exact) {
|
|
42
|
-
return compileExpression(exact[1].trim(), env);
|
|
49
|
+
return compileExpression(exact[1].trim(), env, moduleNames);
|
|
43
50
|
}
|
|
44
51
|
const parts = [];
|
|
45
52
|
let last = 0;
|
|
46
53
|
for (const m of s.matchAll(TEMPLATE_REGEX)) {
|
|
47
54
|
if (m.index > last)
|
|
48
55
|
parts.push(s.slice(last, m.index));
|
|
49
|
-
parts.push(compileExpression(m[1].trim(), env));
|
|
56
|
+
parts.push(compileExpression(m[1].trim(), env, moduleNames));
|
|
50
57
|
last = m.index + m[0].length;
|
|
51
58
|
}
|
|
52
59
|
if (last < s.length)
|
|
53
60
|
parts.push(s.slice(last));
|
|
54
61
|
const refs = new Set();
|
|
62
|
+
const calls = new Set();
|
|
55
63
|
for (const p of parts) {
|
|
56
|
-
if (typeof p
|
|
64
|
+
if (typeof p === "string")
|
|
65
|
+
continue;
|
|
66
|
+
if (p.refs)
|
|
57
67
|
for (const r of p.refs)
|
|
58
68
|
refs.add(r);
|
|
69
|
+
if (p.calls)
|
|
70
|
+
for (const c of p.calls)
|
|
71
|
+
calls.add(c);
|
|
59
72
|
}
|
|
60
73
|
return {
|
|
61
74
|
__compiled: true,
|
|
62
75
|
source: s,
|
|
63
76
|
parts,
|
|
64
77
|
refs: [...refs],
|
|
78
|
+
calls: [...calls],
|
|
65
79
|
call: (ctx) => parts.map((p) => (typeof p === "string" ? p : String(p.call(ctx) ?? ""))).join(""),
|
|
66
80
|
};
|
|
67
81
|
}
|
package/dist/cel/diagnose.d.ts
CHANGED
|
@@ -26,6 +26,12 @@ interface FnEntry {
|
|
|
26
26
|
export interface FunctionIndex {
|
|
27
27
|
readonly byName: ReadonlyMap<string, readonly FnEntry[]>;
|
|
28
28
|
}
|
|
29
|
+
/** The flags a module function carries, as the host that resolves it derives
|
|
30
|
+
* them — or undefined where the name reaches no function. */
|
|
31
|
+
export type ModuleCallFlags = (qualified: string) => {
|
|
32
|
+
readonly deterministic: boolean;
|
|
33
|
+
readonly hostBacked: boolean;
|
|
34
|
+
} | undefined;
|
|
29
35
|
/** Registry view of an environment, memoized: environments are rebuilt per
|
|
30
36
|
* analysis path, but each is immutable once built. */
|
|
31
37
|
export declare function functionIndex(env: Environment): FunctionIndex;
|
|
@@ -46,7 +52,10 @@ export interface CallAudit {
|
|
|
46
52
|
* failed type-check, because a type-check reports its first error and stops:
|
|
47
53
|
* an expression with two bad calls would otherwise fix one, re-run, and
|
|
48
54
|
* discover the next. */
|
|
49
|
-
export declare function auditCalls(source: string, ast: ASTNode, env: Environment
|
|
55
|
+
export declare function auditCalls(source: string, ast: ASTNode, env: Environment,
|
|
56
|
+
/** The flags of the module functions the expression calls, from whoever
|
|
57
|
+
* resolves them. */
|
|
58
|
+
moduleCallFlags?: ModuleCallFlags): CallAudit;
|
|
50
59
|
/** Registered signatures for names a type-check failure mentions, so the
|
|
51
60
|
* residual says what the function actually accepts rather than only echoing
|
|
52
61
|
* what the author wrote. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diagnose.d.ts","sourceRoot":"","sources":["../../src/cel/diagnose.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"diagnose.d.ts","sourceRoot":"","sources":["../../src/cel/diagnose.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGjE,OAAO,KAAK,EAAE,QAAQ,EAAiB,gBAAgB,EAAE,MAAM,cAAc,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-1,8 +1,10 @@
|
|
|
1
1
|
import { CEL_FUNCTIONS } from "./catalog.js";
|
|
2
|
+
import { moduleCallOf } from "./module-call.js";
|
|
2
3
|
/** Determinism is Telo catalog metadata; cel-js builtins carry none. Absent
|
|
3
4
|
* means "no signal", never "deterministic" — consumers of
|
|
4
5
|
* `CallSite.deterministic` must not read undefined as a guarantee. */
|
|
5
6
|
const DETERMINISM = new Map(CEL_FUNCTIONS.map((f) => [f.name, f.deterministic]));
|
|
7
|
+
const HOST_BACKED = new Map(CEL_FUNCTIONS.map((f) => [f.name, f.hostBacked === true]));
|
|
6
8
|
const INDEX_CACHE = new WeakMap();
|
|
7
9
|
/** Registry view of an environment, memoized: environments are rebuilt per
|
|
8
10
|
* analysis path, but each is immutable once built. */
|
|
@@ -38,12 +40,36 @@ function isNode(v) {
|
|
|
38
40
|
return typeof v === "object" && v !== null && "op" in v;
|
|
39
41
|
}
|
|
40
42
|
/** Every non-macro call in the expression, in source order. */
|
|
41
|
-
function collectCalls(root, index) {
|
|
43
|
+
function collectCalls(root, index, moduleCallFlags) {
|
|
42
44
|
const out = [];
|
|
43
45
|
visit(root);
|
|
44
46
|
return out.sort((a, b) => a.start - b.start);
|
|
45
47
|
function visit(node) {
|
|
46
48
|
const args = node.args;
|
|
49
|
+
// A RESOLVED module call is reported under its QUALIFIED name and is never
|
|
50
|
+
// looked up in the catalog: the two namespaces are disjoint by construction
|
|
51
|
+
// (a bare name is always the catalog), so classifying it here would report
|
|
52
|
+
// `there is no function 'format'` for a call that names a module's own, and
|
|
53
|
+
// attaching the catalog's determinism to it would be a flag about a
|
|
54
|
+
// different function entirely. What a module call's flags are is the
|
|
55
|
+
// resolving host's answer, carried when it gives one.
|
|
56
|
+
const moduleCall = moduleCallOf(node);
|
|
57
|
+
if (moduleCall) {
|
|
58
|
+
const flags = moduleCallFlags?.(moduleCall.qualified);
|
|
59
|
+
out.push({
|
|
60
|
+
name: moduleCall.qualified,
|
|
61
|
+
form: "receiver",
|
|
62
|
+
moduleCall: true,
|
|
63
|
+
arity: moduleCall.args.length,
|
|
64
|
+
start: node.start,
|
|
65
|
+
end: node.end,
|
|
66
|
+
...(flags ? { deterministic: flags.deterministic, hostBacked: flags.hostBacked } : {}),
|
|
67
|
+
args: moduleCall.args,
|
|
68
|
+
});
|
|
69
|
+
for (const arg of moduleCall.args)
|
|
70
|
+
visit(arg);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
47
73
|
if (node.op === "call" || node.op === "rcall") {
|
|
48
74
|
const tuple = args;
|
|
49
75
|
const name = tuple[0];
|
|
@@ -57,7 +83,9 @@ function collectCalls(root, index) {
|
|
|
57
83
|
arity: callArgs.length,
|
|
58
84
|
start: node.start,
|
|
59
85
|
end: node.end,
|
|
60
|
-
...(index.byName.has(name)
|
|
86
|
+
...(index.byName.has(name)
|
|
87
|
+
? { deterministic: DETERMINISM.get(name), hostBacked: HOST_BACKED.get(name) }
|
|
88
|
+
: {}),
|
|
61
89
|
...(isNode(receiver) ? { receiver } : {}),
|
|
62
90
|
args: callArgs,
|
|
63
91
|
});
|
|
@@ -128,8 +156,8 @@ function accepts(entries, form, arity) {
|
|
|
128
156
|
const listOf = (names) => [...new Set(names)].sort().join(", ");
|
|
129
157
|
/** Names registered in exactly the form and arity the author wrote — the only
|
|
130
158
|
* ones that could replace this call with no further edits. Ranked by shared
|
|
131
|
-
* prefix, which is what reaches `nowIso` from `
|
|
132
|
-
* would (
|
|
159
|
+
* prefix, which is what reaches `nowIso` from `no`; edit distance never
|
|
160
|
+
* would (4 characters against a 2-character name). Returns [] when nothing
|
|
133
161
|
* shares a prefix, so the caller lists what is legal here instead of
|
|
134
162
|
* guessing. */
|
|
135
163
|
function candidates(call, index) {
|
|
@@ -183,12 +211,20 @@ const ARG_CHECKS = new Map(CEL_FUNCTIONS.flatMap((f) => (f.checkArgs ? [[f.name,
|
|
|
183
211
|
* failed type-check, because a type-check reports its first error and stops:
|
|
184
212
|
* an expression with two bad calls would otherwise fix one, re-run, and
|
|
185
213
|
* discover the next. */
|
|
186
|
-
export function auditCalls(source, ast, env
|
|
214
|
+
export function auditCalls(source, ast, env,
|
|
215
|
+
/** The flags of the module functions the expression calls, from whoever
|
|
216
|
+
* resolves them. */
|
|
217
|
+
moduleCallFlags) {
|
|
187
218
|
const index = functionIndex(env);
|
|
188
219
|
const diagnostics = [];
|
|
189
220
|
const unresolved = [];
|
|
190
|
-
const calls = collectCalls(ast, index);
|
|
221
|
+
const calls = collectCalls(ast, index, moduleCallFlags);
|
|
191
222
|
for (const call of calls) {
|
|
223
|
+
// Resolution already decided what a module call names. The catalog has
|
|
224
|
+
// nothing to say about it, and saying it anyway would be a refusal of valid
|
|
225
|
+
// CEL.
|
|
226
|
+
if (call.moduleCall)
|
|
227
|
+
continue;
|
|
192
228
|
const entries = index.byName.get(call.name);
|
|
193
229
|
const noun = call.form === "receiver" ? "method" : "function";
|
|
194
230
|
if (!entries) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../src/cel/environment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,OAAO,EAAiB,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../src/cel/environment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,OAAO,EAAiB,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAG/D,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAsBhD;;;;;;;;;;;;;;;yDAeyD;AACzD;;;;;wBAKwB;AACxB,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,CAyB5D;AAYD;;;;;yCAKyC;AACzC,wBAAgB,mBAAmB,IAAI,UAAU,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC,CAAC,WAAW,CAAC,CAE5F;AAED,wBAAgB,mBAAmB,CAAC,QAAQ,GAAE,OAAO,CAAC,WAAW,CAAM,GAAG,WAAW,CAcpF"}
|
package/dist/cel/environment.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Environment } from "@marcbachmann/cel-js";
|
|
2
2
|
import { Stream } from "@telorun/sdk";
|
|
3
3
|
import { CEL_FUNCTIONS } from "./catalog.js";
|
|
4
|
+
import { assertCelValueIdentity, SDK_CEL_VALUE_CLASSES } from "./value-identity.js";
|
|
5
|
+
assertCelValueIdentity(SDK_CEL_VALUE_CLASSES);
|
|
4
6
|
const stub = (name) => () => {
|
|
5
7
|
throw new Error(`${name}() is not available in this environment. ` +
|
|
6
8
|
`Construct StaticAnalyzer or Loader with celHandlers to enable it.`);
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* **A call whose receiver is one of the declaring module's names.**
|
|
3
|
+
*
|
|
4
|
+
* `Billing.format(x)`, `Self.y(1)`, `<ModuleName>.y(1)` — CEL's own
|
|
5
|
+
* qualified-function rule, the one `cel.bind` and cel-go's `math.greatest`
|
|
6
|
+
* already follow. Resolution happens on the PARSED TREE, right after
|
|
7
|
+
* `env.parse` and before any check: the author's text, spans and the expression
|
|
8
|
+
* a trace shows stay exactly as written, which rewriting the source would move.
|
|
9
|
+
*
|
|
10
|
+
* A module's names are known from its own file before any import resolves — its
|
|
11
|
+
* `imports:` keys, `Self`, its `metadata.name` and `Telo` — so the set is an
|
|
12
|
+
* INPUT here rather than something this module derives. A call on a bare
|
|
13
|
+
* identifier outside the set stays an ordinary method call, which is what keeps
|
|
14
|
+
* the catalog's `format` and `Billing.format` from ever colliding, with one
|
|
15
|
+
* catalog environment compiling both.
|
|
16
|
+
*
|
|
17
|
+
* Two engine internals carry it, neither exposed by cel-js's typings — hence
|
|
18
|
+
* the exact version pin and `tests/module-call.test.ts`, which fails the moment
|
|
19
|
+
* an upgrade moves either:
|
|
20
|
+
*
|
|
21
|
+
* - `ASTNode.setMeta('macro', …)` redirects a node's check and evaluation. A
|
|
22
|
+
* comprehension macro (`map`, `filter`, …) sets `alternate` instead, and
|
|
23
|
+
* `alternate` WINS over `macro`, so a call the parser expanded as a macro
|
|
24
|
+
* needs it cleared or the rewrite is silently ignored. The parser expands
|
|
25
|
+
* those names BEFORE this rewrite and refuses any call whose arguments do not
|
|
26
|
+
* fit the macro, so no function may take a macro's name
|
|
27
|
+
* (`FUNCTION_NAME_RESERVED`); clearing keeps a call that did parse reported
|
|
28
|
+
* as the module call it names.
|
|
29
|
+
* - `async` must be set explicitly: cel-js derives it for an `rcall` from
|
|
30
|
+
* `receiverWithArgs`, which only the rcall's own checker fills in — and ours
|
|
31
|
+
* replaces it.
|
|
32
|
+
*
|
|
33
|
+
* The dispatch table is read from the activation under a key no CEL source can
|
|
34
|
+
* spell, so nothing an author can write reaches the mechanism past the export
|
|
35
|
+
* gate or the dependency edge. Binding the table is the kernel's, per scope;
|
|
36
|
+
* until something binds one, evaluating a module call throws naming the
|
|
37
|
+
* function.
|
|
38
|
+
*/
|
|
39
|
+
import type { ASTNode } from "@marcbachmann/cel-js";
|
|
40
|
+
/**
|
|
41
|
+
* Activation key the per-scope dispatch table is read from.
|
|
42
|
+
*
|
|
43
|
+
* `@` and `:` are outside CEL's identifier grammar and there is no other way to
|
|
44
|
+
* reach the activation, so no expression can name this — a spellable dispatcher
|
|
45
|
+
* would let an author call past the export gate and past the dependency edge
|
|
46
|
+
* that orders the callee before its caller.
|
|
47
|
+
*/
|
|
48
|
+
export declare const MODULE_CALL_DISPATCH_KEY = "@telo:module-functions";
|
|
49
|
+
/** Per-scope binding table: qualified name → the callable's `call`. */
|
|
50
|
+
export type ModuleCallDispatch = ReadonlyMap<string, (args: readonly unknown[]) => unknown>;
|
|
51
|
+
/**
|
|
52
|
+
* The CEL type a qualified call yields, as a type name (`"string"`,
|
|
53
|
+
* `"list<int>"`), or undefined for "not known here".
|
|
54
|
+
*
|
|
55
|
+
* A hook rather than a table because the answer belongs to the analysis, not to
|
|
56
|
+
* the expression: a signature is declared on a resource in the module the call
|
|
57
|
+
* resolves through. With no resolver — every compile, and every analysis until
|
|
58
|
+
* signatures are typed — a module call is `dyn`, which types its arguments and
|
|
59
|
+
* claims nothing about its result.
|
|
60
|
+
*/
|
|
61
|
+
export type ModuleCallTypeResolver = (qualified: string) => string | undefined;
|
|
62
|
+
/** What a resolved module call says about itself: the qualified name as
|
|
63
|
+
* written, the argument nodes, and — once the tree has been type-checked — the
|
|
64
|
+
* type the checker gave each argument. The single reader — no other surface
|
|
65
|
+
* pattern-matches the macro's shape. */
|
|
66
|
+
export interface ModuleCall {
|
|
67
|
+
readonly qualified: string;
|
|
68
|
+
readonly args: readonly ASTNode[];
|
|
69
|
+
readonly argumentTypes?: readonly string[];
|
|
70
|
+
}
|
|
71
|
+
export declare function moduleCallOf(node: ASTNode): ModuleCall | undefined;
|
|
72
|
+
/** Message for a call nothing has bound. Not a fallback value: a call that
|
|
73
|
+
* cannot reach its function has no result, and inventing one would make a
|
|
74
|
+
* missing export read as a null. */
|
|
75
|
+
export declare function unboundModuleCallMessage(qualified: string): string;
|
|
76
|
+
/**
|
|
77
|
+
* Rewrite every module call in `ast` in place and report them in source order.
|
|
78
|
+
*
|
|
79
|
+
* Returns the qualified names as written (`["Billing.format", "Self.y"]`), which
|
|
80
|
+
* is what a compiled value carries so no consumer has to re-parse to learn what
|
|
81
|
+
* an expression calls. Idempotent: a node already resolved is rewritten once and
|
|
82
|
+
* reported again, so two passes over one tree agree about what it calls.
|
|
83
|
+
*/
|
|
84
|
+
export declare function resolveModuleCalls(ast: ASTNode | undefined, moduleNames?: ReadonlySet<string>, typeOf?: ModuleCallTypeResolver): string[];
|
|
85
|
+
/** Every resolved module call in `ast` with its node, outermost first. */
|
|
86
|
+
export declare function moduleCallNodes(ast: ASTNode | undefined): Array<{
|
|
87
|
+
node: ASTNode;
|
|
88
|
+
call: ModuleCall;
|
|
89
|
+
}>;
|
|
90
|
+
/**
|
|
91
|
+
* Bare identifiers used as a call receiver that resolved to NO module name.
|
|
92
|
+
*
|
|
93
|
+
* `Foo.bar()` with no `Foo` import is an unknown identifier like any other, but
|
|
94
|
+
* the repair is not the usual one — it needs an `imports:` alias, not a
|
|
95
|
+
* different spelling — so the caller that reports the root says so.
|
|
96
|
+
*/
|
|
97
|
+
export declare function unresolvedCallReceivers(ast: ASTNode | undefined, moduleNames?: ReadonlySet<string>): Set<string>;
|
|
98
|
+
/**
|
|
99
|
+
* Names bound INSIDE the expression — a comprehension variable, a `cel.bind`
|
|
100
|
+
* name — that collide with one of the module's names.
|
|
101
|
+
*
|
|
102
|
+
* Such a binding is unreachable through a call: `Billing.f(x)` inside it
|
|
103
|
+
* resolves to the module, never to the bound value. Reported as a reserved name
|
|
104
|
+
* rather than silently shadowed, which is the rule every other name in CEL
|
|
105
|
+
* scope already follows.
|
|
106
|
+
*/
|
|
107
|
+
export declare function moduleNameBindings(ast: ASTNode | undefined, moduleNames?: ReadonlySet<string>): string[];
|
|
108
|
+
//# sourceMappingURL=module-call.d.ts.map
|