@telorun/templating 0.107.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 +2 -2
- package/dist/builtins.d.ts.map +1 -1
- 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 +47 -17
- package/dist/cel/compile.d.ts.map +1 -1
- package/dist/cel/compile.js +135 -83
- package/dist/cel/diagnose.d.ts +52 -57
- package/dist/cel/diagnose.d.ts.map +1 -1
- package/dist/cel/diagnose.js +69 -291
- package/dist/cel/environment.d.ts +33 -37
- package/dist/cel/environment.d.ts.map +1 -1
- package/dist/cel/environment.js +54 -86
- 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 +14 -12
- package/dist/cel/value-brands.d.ts.map +1 -1
- package/dist/cel/value-brands.js +26 -24
- package/dist/cel/verdict-codes.d.ts +13 -2
- package/dist/cel/verdict-codes.d.ts.map +1 -1
- package/dist/cel/verdict-codes.js +20 -1
- package/dist/engine.d.ts +4 -4
- package/dist/engine.d.ts.map +1 -1
- package/dist/engines/cel.d.ts +2 -2
- package/dist/engines/cel.d.ts.map +1 -1
- package/dist/engines/cel.js +53 -81
- package/dist/engines/hole-analysis.d.ts +3 -3
- package/dist/engines/hole-analysis.d.ts.map +1 -1
- package/dist/engines/interpolate.js +11 -8
- package/dist/index.d.ts +4 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -5
- package/package.json +4 -4
- package/src/builtins.ts +2 -2
- package/src/cel/analyze.ts +152 -193
- package/src/cel/compile.ts +160 -77
- package/src/cel/diagnose.ts +115 -370
- package/src/cel/environment.ts +64 -87
- package/src/cel/module-call.ts +129 -292
- package/src/cel/value-brands.ts +26 -25
- package/src/cel/verdict-codes.ts +20 -1
- package/src/engine.ts +4 -4
- package/src/engines/cel.ts +52 -84
- package/src/engines/hole-analysis.ts +3 -3
- package/src/engines/interpolate.ts +16 -13
- package/src/index.ts +8 -11
- package/dist/cel/catalog.d.ts +0 -70
- package/dist/cel/catalog.d.ts.map +0 -1
- package/dist/cel/catalog.js +0 -1320
- package/dist/cel/json-prefix-scan.d.ts +0 -17
- package/dist/cel/json-prefix-scan.d.ts.map +0 -1
- package/dist/cel/json-prefix-scan.js +0 -160
- 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 -1455
- package/src/cel/json-prefix-scan.ts +0 -152
- package/src/cel/value-identity.ts +0 -34
package/dist/builtins.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CelEnvironment } from "@telorun/cel";
|
|
2
2
|
import { TemplatingEngineRegistry } from "./registry.js";
|
|
3
3
|
import type { TemplatingEngine } from "./engine.js";
|
|
4
4
|
/** Single source of truth for the built-in templating engines. Every host
|
|
@@ -35,7 +35,7 @@ export declare function celExpressionsOf(engineName: string, source: string): st
|
|
|
35
35
|
* The single reader of `TemplatingEngine.repeatable`, so a consumer comparing
|
|
36
36
|
* two tagged scalars never recognises a tag by name.
|
|
37
37
|
*/
|
|
38
|
-
export declare function repeatableSource(engineName: string, source: string, celEnv:
|
|
38
|
+
export declare function repeatableSource(engineName: string, source: string, celEnv: CelEnvironment): boolean;
|
|
39
39
|
/** Memoized singleton: returns the default registry. Hosts that don't need
|
|
40
40
|
* per-instance isolation (precompile, the analyzer's tagged-value walker)
|
|
41
41
|
* should use this so they share the same registry instance the YAML tag
|
package/dist/builtins.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builtins.d.ts","sourceRoot":"","sources":["../src/builtins.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"builtins.d.ts","sourceRoot":"","sources":["../src/builtins.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAQnD,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD;;;;;gEAKgE;AAChE,eAAO,MAAM,cAAc,EAAE,SAAS,gBAAgB,EASrD,CAAC;AAEF,wBAAgB,qBAAqB,IAAI,wBAAwB,CAMhE;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAEtF;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAG7E;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,GAAG,OAAO,CAEpG;AAID;;;oBAGoB;AACpB,wBAAgB,eAAe,IAAI,wBAAwB,CAK1D"}
|
package/dist/cel/analyze.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type CelNode } from "@telorun/cel";
|
|
2
2
|
/**
|
|
3
3
|
* Extract all member-access chains from a CEL AST.
|
|
4
4
|
* Returns arrays like ["request", "query", "name"] for `request.query.name`.
|
|
@@ -12,14 +12,14 @@ import type { ASTNode } from "@marcbachmann/cel-js";
|
|
|
12
12
|
* tree, before this walk — an unresolved tree still reports the receiver, which
|
|
13
13
|
* is the right answer for a caller that supplied no module names.
|
|
14
14
|
*/
|
|
15
|
-
export declare function extractAccessChains(node:
|
|
15
|
+
export declare function extractAccessChains(node: CelNode): string[][];
|
|
16
16
|
/**
|
|
17
17
|
* Each resolved module call's arguments as plain member chains, keyed by the
|
|
18
18
|
* call's node — `null` for an argument that is not one, or that is rooted at a
|
|
19
19
|
* name the expression itself binds (`xs.map(item, Billing.total(item))`), which
|
|
20
20
|
* no context schema describes.
|
|
21
21
|
*/
|
|
22
|
-
export declare function moduleCallArgumentChains(node:
|
|
22
|
+
export declare function moduleCallArgumentChains(node: CelNode): Map<CelNode, Array<string[] | null>>;
|
|
23
23
|
/** Sentinel chain segment emitted for index access (`obj[expr]`) — a dynamic
|
|
24
24
|
* member that can't be resolved to a static name. Consumers that attribute
|
|
25
25
|
* chains to declared names treat this as "unknown member". */
|
|
@@ -35,7 +35,7 @@ export interface CallResultAccess {
|
|
|
35
35
|
* {@link extractAccessChains} deliberately skips, since their root is a value
|
|
36
36
|
* no context schema describes. The caller supplies the call's result schema.
|
|
37
37
|
*/
|
|
38
|
-
export declare function extractCallResultAccesses(node:
|
|
38
|
+
export declare function extractCallResultAccesses(node: CelNode): CallResultAccess[];
|
|
39
39
|
interface NullableIssue {
|
|
40
40
|
/** Dotted path of the nullable value being dereferenced (e.g. "error"). */
|
|
41
41
|
path: string;
|
|
@@ -45,7 +45,7 @@ interface NullableIssue {
|
|
|
45
45
|
/** The dotted chain an expression IS, when it is a plain chain whose schema
|
|
46
46
|
* admits null — a value that may itself be null, rather than one dereferenced
|
|
47
47
|
* through a null. */
|
|
48
|
-
export declare function nullableValueChain(node:
|
|
48
|
+
export declare function nullableValueChain(node: CelNode, contextSchema: Record<string, any>): string | null;
|
|
49
49
|
/**
|
|
50
50
|
* Find member accesses on a nullable value that are not null-guarded in the
|
|
51
51
|
* surrounding expression. A context field whose schema admits `null` (e.g. the
|
|
@@ -54,7 +54,7 @@ export declare function nullableValueChain(node: ASTNode, contextSchema: Record<
|
|
|
54
54
|
* `x != null` flowing through `?:` ternaries and `&&` / `||` short-circuits.
|
|
55
55
|
* Returns one issue per unguarded dereference.
|
|
56
56
|
*/
|
|
57
|
-
export declare function findNullableAccessIssues(node:
|
|
57
|
+
export declare function findNullableAccessIssues(node: CelNode, contextSchema: Record<string, any>): NullableIssue[];
|
|
58
58
|
/**
|
|
59
59
|
* Check whether a member-access chain accesses only fields declared in a JSON Schema.
|
|
60
60
|
* Returns an error string if a field is unknown in a schema that declares explicit
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analyze.d.ts","sourceRoot":"","sources":["../../src/cel/analyze.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"analyze.d.ts","sourceRoot":"","sources":["../../src/cel/analyze.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,OAAO,EACb,MAAM,cAAc,CAAC;AAItB;;;;;;;;;;;;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;AA8FD;;+DAE+D;AAC/D,eAAO,MAAM,aAAa,QAAQ,CAAC;AA6BnC;+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;AA4BD,UAAU,aAAa;IACrB,2EAA2E;IAC3E,IAAI,EAAE,MAAM,CAAC;IACb,6DAA6D;IAC7D,MAAM,EAAE,MAAM,CAAC;CAChB;AA0BD;;sBAEsB;AACtB,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,OAAO,EACb,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACjC,MAAM,GAAG,IAAI,CAIf;AA0DD;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,OAAO,EACb,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACjC,aAAa,EAAE,CAIjB;AA2ED;;;;;;;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,3 +1,4 @@
|
|
|
1
|
+
import { childNodes, namespaceMacroBinding, receiverMacroBinding, } from "@telorun/cel";
|
|
1
2
|
import { isLiveSlot } from "@telorun/sdk";
|
|
2
3
|
import { moduleCallOf } from "./module-call.js";
|
|
3
4
|
/**
|
|
@@ -31,30 +32,54 @@ export function moduleCallArgumentChains(node) {
|
|
|
31
32
|
});
|
|
32
33
|
return out;
|
|
33
34
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
35
|
+
/**
|
|
36
|
+
* `cel.bind(name, init, body)`.
|
|
37
|
+
*
|
|
38
|
+
* `cel` is a RESERVED namespace — one a host can never claim, because the standard macros
|
|
39
|
+
* are written on it — so this is **not** a qualified call: it reads as a receiver call on
|
|
40
|
+
* the ident `cel`, which is in no scope and never will be. The engine's own binding table
|
|
41
|
+
* says which argument is the name and which are scoped.
|
|
39
42
|
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
43
|
+
* The receiver is deliberately not returned: it contributes no chain, and descending into it
|
|
44
|
+
* is what produced a `CEL_UNKNOWN_FIELD` for `cel` itself.
|
|
45
|
+
*/
|
|
42
46
|
function bindCall(node) {
|
|
43
|
-
if (node.
|
|
47
|
+
if (node.kind !== "receiverCall")
|
|
48
|
+
return null;
|
|
49
|
+
if (node.receiver.kind !== "ident" || node.receiver.name !== "cel")
|
|
50
|
+
return null;
|
|
51
|
+
const binding = namespaceMacroBinding("cel", node.name, node.args.length);
|
|
52
|
+
if (!binding)
|
|
44
53
|
return null;
|
|
45
|
-
const
|
|
46
|
-
if (
|
|
54
|
+
const nameNode = node.args[binding.variableArgument];
|
|
55
|
+
if (nameNode?.kind !== "ident")
|
|
47
56
|
return null;
|
|
48
|
-
|
|
57
|
+
const scoped = binding.scopedArguments;
|
|
58
|
+
// `cel.bind(name, init, body)`: the body is scoped, everything else before it is not.
|
|
59
|
+
const body = node.args[scoped[scoped.length - 1]];
|
|
60
|
+
const init = node.args.find((unused, at) => at !== binding.variableArgument && !scoped.includes(at));
|
|
61
|
+
if (!init || !body)
|
|
49
62
|
return null;
|
|
50
|
-
|
|
63
|
+
return { name: nameNode.name, init, body };
|
|
64
|
+
}
|
|
65
|
+
/** A comprehension macro's iteration variable and the arguments it scopes, from the
|
|
66
|
+
* engine's own binding table rather than a list of method names kept in step with it. */
|
|
67
|
+
function comprehension(node) {
|
|
68
|
+
if (node.kind !== "receiverCall")
|
|
69
|
+
return null;
|
|
70
|
+
if (node.receiver.kind === "ident" && node.receiver.name === "cel")
|
|
51
71
|
return null;
|
|
52
|
-
const
|
|
53
|
-
if (!
|
|
72
|
+
const binding = receiverMacroBinding(node.name, node.args.length);
|
|
73
|
+
if (!binding)
|
|
54
74
|
return null;
|
|
55
|
-
|
|
75
|
+
const nameNode = node.args[binding.variableArgument];
|
|
76
|
+
if (nameNode?.kind !== "ident")
|
|
56
77
|
return null;
|
|
57
|
-
return {
|
|
78
|
+
return {
|
|
79
|
+
receiver: node.receiver,
|
|
80
|
+
bound: nameNode.name,
|
|
81
|
+
scoped: binding.scopedArguments.flatMap((at) => (node.args[at] ? [node.args[at]] : [])),
|
|
82
|
+
};
|
|
58
83
|
}
|
|
59
84
|
function visitNode(node, chains, boundVars, onModuleCall) {
|
|
60
85
|
const chain = extractChain(node, boundVars);
|
|
@@ -77,71 +102,48 @@ function visitNode(node, chains, boundVars, onModuleCall) {
|
|
|
77
102
|
visitNode(bind.body, chains, new Set(boundVars).add(bind.name), onModuleCall);
|
|
78
103
|
return;
|
|
79
104
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
visitNode(receiver, chains, boundVars, onModuleCall);
|
|
88
|
-
if (Array.isArray(comprehensionArgs) &&
|
|
89
|
-
comprehensionArgs.length >= 2 &&
|
|
90
|
-
isASTNode(comprehensionArgs[0]) &&
|
|
91
|
-
comprehensionArgs[0].op === "id") {
|
|
92
|
-
const newBoundVars = new Set(boundVars);
|
|
93
|
-
newBoundVars.add(comprehensionArgs[0].args);
|
|
94
|
-
for (let i = 1; i < comprehensionArgs.length; i++) {
|
|
95
|
-
const arg = comprehensionArgs[i];
|
|
96
|
-
if (isASTNode(arg))
|
|
97
|
-
visitNode(arg, chains, newBoundVars, onModuleCall);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
105
|
+
const macro = comprehension(node);
|
|
106
|
+
if (macro) {
|
|
107
|
+
// The receiver is evaluated outside the binding; only the scoped arguments see it.
|
|
108
|
+
visitNode(macro.receiver, chains, boundVars, onModuleCall);
|
|
109
|
+
const inner = new Set(boundVars).add(macro.bound);
|
|
110
|
+
for (const arg of macro.scoped)
|
|
111
|
+
visitNode(arg, chains, inner, onModuleCall);
|
|
100
112
|
return;
|
|
101
113
|
}
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
for (const arg of args) {
|
|
105
|
-
if (isASTNode(arg)) {
|
|
106
|
-
visitNode(arg, chains, boundVars, onModuleCall);
|
|
107
|
-
}
|
|
108
|
-
else if (Array.isArray(arg)) {
|
|
109
|
-
for (const item of arg) {
|
|
110
|
-
if (isASTNode(item))
|
|
111
|
-
visitNode(item, chains, boundVars, onModuleCall);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
else if (isASTNode(args)) {
|
|
117
|
-
// Unary operators (`!_`, `-_`) carry their operand as a single node
|
|
118
|
-
// rather than a one-element array, so descend into it directly.
|
|
119
|
-
visitNode(args, chains, boundVars, onModuleCall);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
function isASTNode(v) {
|
|
123
|
-
return v !== null && typeof v === "object" && "op" in v;
|
|
114
|
+
for (const child of childNodes(node))
|
|
115
|
+
visitNode(child, chains, boundVars, onModuleCall);
|
|
124
116
|
}
|
|
125
117
|
/** Sentinel chain segment emitted for index access (`obj[expr]`) — a dynamic
|
|
126
118
|
* member that can't be resolved to a static name. Consumers that attribute
|
|
127
119
|
* chains to declared names treat this as "unknown member". */
|
|
128
120
|
export const INDEX_SEGMENT = "[*]";
|
|
129
121
|
function extractChain(node, boundVars) {
|
|
130
|
-
if (node.
|
|
131
|
-
|
|
132
|
-
|
|
122
|
+
if (node.kind === "ident") {
|
|
123
|
+
// An ABSOLUTE name (`.y`) resolves against the environment's declarations and never
|
|
124
|
+
// against a name the expression bound, so a binding of the same spelling cannot hide it.
|
|
125
|
+
if (!node.absolute && boundVars.has(node.name))
|
|
133
126
|
return null;
|
|
134
|
-
return [name];
|
|
127
|
+
return [node.name];
|
|
135
128
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
129
|
+
// **An OPTIONAL read ends the chain.** `a.?b` and `a[?0]` answer an `optional<T>`, so what
|
|
130
|
+
// follows is a method on that optional (`.orValue('')`) rather than a member of the
|
|
131
|
+
// context — and the author has said outright that the member may be absent, which is not a
|
|
132
|
+
// claim a context schema has to declare. The engine makes both a real `select`/`index`
|
|
133
|
+
// with `optional: true`, where the replaced engine had no node this walk could chain, so
|
|
134
|
+
// continuing would both invent a read and hand `validateChainAgainstSchema` a path past
|
|
135
|
+
// the point the expression stopped asserting anything.
|
|
136
|
+
if (node.kind === "select") {
|
|
137
|
+
if (node.optional)
|
|
138
|
+
return null;
|
|
139
|
+
const parent = extractChain(node.operand, boundVars);
|
|
139
140
|
if (parent !== null)
|
|
140
|
-
return [...parent, field];
|
|
141
|
+
return [...parent, node.field];
|
|
141
142
|
}
|
|
142
|
-
if (node.
|
|
143
|
-
|
|
144
|
-
|
|
143
|
+
if (node.kind === "index") {
|
|
144
|
+
if (node.optional)
|
|
145
|
+
return null;
|
|
146
|
+
const parent = extractChain(node.operand, boundVars);
|
|
145
147
|
if (parent !== null)
|
|
146
148
|
return [...parent, INDEX_SEGMENT];
|
|
147
149
|
}
|
|
@@ -158,15 +160,19 @@ export function extractCallResultAccesses(node) {
|
|
|
158
160
|
return out;
|
|
159
161
|
}
|
|
160
162
|
function visitAccess(node, out) {
|
|
161
|
-
if (node.
|
|
163
|
+
if (node.kind === "select" || node.kind === "index") {
|
|
162
164
|
const members = [];
|
|
163
165
|
let base = node;
|
|
164
|
-
while (base.
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
166
|
+
while (base.kind === "select" || base.kind === "index") {
|
|
167
|
+
if (base.kind === "select") {
|
|
168
|
+
members.unshift(base.field);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
members.unshift(INDEX_SEGMENT);
|
|
172
|
+
// The index is its own expression and may itself read off a call's result.
|
|
173
|
+
visitAccess(base.index, out);
|
|
174
|
+
}
|
|
175
|
+
base = base.operand;
|
|
170
176
|
}
|
|
171
177
|
const call = moduleCallOf(base);
|
|
172
178
|
if (call) {
|
|
@@ -178,26 +184,8 @@ function visitAccess(node, out) {
|
|
|
178
184
|
visitAccess(base, out);
|
|
179
185
|
return;
|
|
180
186
|
}
|
|
181
|
-
const
|
|
182
|
-
|
|
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
|
-
}
|
|
187
|
+
for (const child of childNodes(node))
|
|
188
|
+
visitAccess(child, out);
|
|
201
189
|
}
|
|
202
190
|
/** True when a JSON Schema admits `null` — `type: "null"` or a union that
|
|
203
191
|
* includes it (e.g. `["object", "null"]`). */
|
|
@@ -231,7 +219,7 @@ export function nullableValueChain(node, contextSchema) {
|
|
|
231
219
|
return schemaIsNullable(schemaAtChain(chain.split("."), contextSchema)) ? chain : null;
|
|
232
220
|
}
|
|
233
221
|
function isNullLiteral(node) {
|
|
234
|
-
return node.
|
|
222
|
+
return node.kind === "literal" && node.literal.type === "null";
|
|
235
223
|
}
|
|
236
224
|
/** Dotted form of a static member chain rooted at a free identifier, or null
|
|
237
225
|
* when the node isn't such a chain (call result, bound var, index, …). */
|
|
@@ -245,35 +233,34 @@ const EMPTY_NARROWING = { whenTrue: new Set(), whenFalse: new Set() };
|
|
|
245
233
|
/** Derive which chains a boolean condition proves non-null in its true / false
|
|
246
234
|
* branches. Handles `x == null` / `x != null`, negation, and `&&` / `||`. */
|
|
247
235
|
function deriveNarrowing(node, boundVars) {
|
|
248
|
-
if (node.
|
|
249
|
-
const
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
236
|
+
if (node.kind === "unary" && node.operator === "!") {
|
|
237
|
+
const inner = deriveNarrowing(node.operand, boundVars);
|
|
238
|
+
return { whenTrue: inner.whenFalse, whenFalse: inner.whenTrue };
|
|
239
|
+
}
|
|
240
|
+
if (node.kind !== "binary")
|
|
241
|
+
return EMPTY_NARROWING;
|
|
242
|
+
if (node.operator === "==" || node.operator === "!=") {
|
|
243
|
+
const chain = isNullLiteral(node.right)
|
|
244
|
+
? dottedChain(node.left, boundVars)
|
|
245
|
+
: isNullLiteral(node.left)
|
|
246
|
+
? dottedChain(node.right, boundVars)
|
|
254
247
|
: null;
|
|
255
248
|
if (chain === null)
|
|
256
249
|
return EMPTY_NARROWING;
|
|
257
250
|
const proven = new Set([chain]);
|
|
258
|
-
return node.
|
|
251
|
+
return node.operator === "!="
|
|
259
252
|
? { whenTrue: proven, whenFalse: new Set() }
|
|
260
253
|
: { whenTrue: new Set(), whenFalse: proven };
|
|
261
254
|
}
|
|
262
|
-
if (node.
|
|
263
|
-
const
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
if (node.op === "&&") {
|
|
267
|
-
const [a, b] = node.args;
|
|
268
|
-
const na = deriveNarrowing(a, boundVars);
|
|
269
|
-
const nb = deriveNarrowing(b, boundVars);
|
|
270
|
-
return { whenTrue: union(na.whenTrue, nb.whenTrue), whenFalse: new Set() };
|
|
255
|
+
if (node.operator === "&&") {
|
|
256
|
+
const left = deriveNarrowing(node.left, boundVars);
|
|
257
|
+
const right = deriveNarrowing(node.right, boundVars);
|
|
258
|
+
return { whenTrue: union(left.whenTrue, right.whenTrue), whenFalse: new Set() };
|
|
271
259
|
}
|
|
272
|
-
if (node.
|
|
273
|
-
const
|
|
274
|
-
const
|
|
275
|
-
|
|
276
|
-
return { whenTrue: new Set(), whenFalse: union(na.whenFalse, nb.whenFalse) };
|
|
260
|
+
if (node.operator === "||") {
|
|
261
|
+
const left = deriveNarrowing(node.left, boundVars);
|
|
262
|
+
const right = deriveNarrowing(node.right, boundVars);
|
|
263
|
+
return { whenTrue: new Set(), whenFalse: union(left.whenFalse, right.whenFalse) };
|
|
277
264
|
}
|
|
278
265
|
return EMPTY_NARROWING;
|
|
279
266
|
}
|
|
@@ -295,97 +282,65 @@ export function findNullableAccessIssues(node, contextSchema) {
|
|
|
295
282
|
}
|
|
296
283
|
function walkNullable(node, nonNull, boundVars, issues, schema) {
|
|
297
284
|
// Dereference of an object/array member — check the receiver's nullability.
|
|
298
|
-
if (node.
|
|
299
|
-
const
|
|
300
|
-
const objChain = dottedChain(obj, boundVars);
|
|
285
|
+
if (node.kind === "select" || node.kind === "index") {
|
|
286
|
+
const objChain = dottedChain(node.operand, boundVars);
|
|
301
287
|
if (objChain !== null && !nonNull.has(objChain)) {
|
|
302
|
-
|
|
303
|
-
if (schemaIsNullable(objSchema)) {
|
|
288
|
+
if (schemaIsNullable(schemaAtChain(objChain.split("."), schema))) {
|
|
304
289
|
issues.push({
|
|
305
290
|
path: objChain,
|
|
306
|
-
member: node.
|
|
291
|
+
member: node.kind === "select" ? node.field : "[index]",
|
|
307
292
|
});
|
|
308
293
|
}
|
|
309
294
|
}
|
|
310
|
-
walkNullable(
|
|
311
|
-
// The index expression (`obj[expr]`) is itself evaluated — descend so a
|
|
312
|
-
//
|
|
313
|
-
if (node.
|
|
314
|
-
walkNullable(
|
|
315
|
-
}
|
|
295
|
+
walkNullable(node.operand, nonNull, boundVars, issues, schema);
|
|
296
|
+
// The index expression (`obj[expr]`) is itself evaluated — descend so a nullable
|
|
297
|
+
// deref used as an index (`items[error.code]`) is caught.
|
|
298
|
+
if (node.kind === "index")
|
|
299
|
+
walkNullable(node.index, nonNull, boundVars, issues, schema);
|
|
316
300
|
return;
|
|
317
301
|
}
|
|
318
|
-
if (node.
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
walkNullable(
|
|
323
|
-
walkNullable(elseB, union(nonNull, n.whenFalse), boundVars, issues, schema);
|
|
302
|
+
if (node.kind === "conditional") {
|
|
303
|
+
walkNullable(node.condition, nonNull, boundVars, issues, schema);
|
|
304
|
+
const narrowed = deriveNarrowing(node.condition, boundVars);
|
|
305
|
+
walkNullable(node.whenTrue, union(nonNull, narrowed.whenTrue), boundVars, issues, schema);
|
|
306
|
+
walkNullable(node.whenFalse, union(nonNull, narrowed.whenFalse), boundVars, issues, schema);
|
|
324
307
|
return;
|
|
325
308
|
}
|
|
326
|
-
if (node.
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
const
|
|
330
|
-
|
|
331
|
-
walkNullable(b, union(nonNull, carried), boundVars, issues, schema);
|
|
309
|
+
if (node.kind === "binary" && (node.operator === "&&" || node.operator === "||")) {
|
|
310
|
+
walkNullable(node.left, nonNull, boundVars, issues, schema);
|
|
311
|
+
const narrowed = deriveNarrowing(node.left, boundVars);
|
|
312
|
+
const carried = node.operator === "&&" ? narrowed.whenTrue : narrowed.whenFalse;
|
|
313
|
+
walkNullable(node.right, union(nonNull, carried), boundVars, issues, schema);
|
|
332
314
|
return;
|
|
333
315
|
}
|
|
334
|
-
// A module call's receiver is a module name, not a value; mirror
|
|
335
|
-
//
|
|
316
|
+
// A module call's receiver is a module name, not a value; mirror extractAccessChains so
|
|
317
|
+
// it is never read as a nullable context field.
|
|
336
318
|
const moduleCall = moduleCallOf(node);
|
|
337
319
|
if (moduleCall) {
|
|
338
320
|
for (const arg of moduleCall.args)
|
|
339
321
|
walkNullable(arg, nonNull, boundVars, issues, schema);
|
|
340
322
|
return;
|
|
341
323
|
}
|
|
342
|
-
// `cel.bind` binds a name for its body; mirror extractAccessChains so a bound
|
|
343
|
-
//
|
|
324
|
+
// `cel.bind` binds a name for its body; mirror extractAccessChains so a bound name is
|
|
325
|
+
// never read as a nullable context field.
|
|
344
326
|
const bind = bindCall(node);
|
|
345
327
|
if (bind) {
|
|
346
328
|
walkNullable(bind.init, nonNull, boundVars, issues, schema);
|
|
347
329
|
walkNullable(bind.body, nonNull, new Set(boundVars).add(bind.name), issues, schema);
|
|
348
330
|
return;
|
|
349
331
|
}
|
|
350
|
-
//
|
|
351
|
-
//
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
const
|
|
357
|
-
|
|
358
|
-
if (isASTNode(receiver))
|
|
359
|
-
walkNullable(receiver, nonNull, boundVars, issues, schema);
|
|
360
|
-
if (Array.isArray(comprehensionArgs) &&
|
|
361
|
-
comprehensionArgs.length >= 2 &&
|
|
362
|
-
isASTNode(comprehensionArgs[0]) &&
|
|
363
|
-
comprehensionArgs[0].op === "id") {
|
|
364
|
-
const inner = new Set(boundVars);
|
|
365
|
-
inner.add(comprehensionArgs[0].args);
|
|
366
|
-
for (let i = 1; i < comprehensionArgs.length; i++) {
|
|
367
|
-
const arg = comprehensionArgs[i];
|
|
368
|
-
if (isASTNode(arg))
|
|
369
|
-
walkNullable(arg, nonNull, inner, issues, schema);
|
|
370
|
-
}
|
|
371
|
-
}
|
|
332
|
+
// A comprehension binds a loop variable; mirror extractAccessChains so a bound var is
|
|
333
|
+
// never mistaken for a nullable context field.
|
|
334
|
+
const macro = comprehension(node);
|
|
335
|
+
if (macro) {
|
|
336
|
+
walkNullable(macro.receiver, nonNull, boundVars, issues, schema);
|
|
337
|
+
const inner = new Set(boundVars).add(macro.bound);
|
|
338
|
+
for (const arg of macro.scoped)
|
|
339
|
+
walkNullable(arg, nonNull, inner, issues, schema);
|
|
372
340
|
return;
|
|
373
341
|
}
|
|
374
|
-
const
|
|
375
|
-
|
|
376
|
-
for (const arg of args) {
|
|
377
|
-
if (isASTNode(arg))
|
|
378
|
-
walkNullable(arg, nonNull, boundVars, issues, schema);
|
|
379
|
-
else if (Array.isArray(arg)) {
|
|
380
|
-
for (const item of arg) {
|
|
381
|
-
if (isASTNode(item))
|
|
382
|
-
walkNullable(item, nonNull, boundVars, issues, schema);
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
else if (isASTNode(args)) {
|
|
388
|
-
walkNullable(args, nonNull, boundVars, issues, schema);
|
|
342
|
+
for (const child of childNodes(node)) {
|
|
343
|
+
walkNullable(child, nonNull, boundVars, issues, schema);
|
|
389
344
|
}
|
|
390
345
|
}
|
|
391
346
|
/**
|
package/dist/cel/compile.d.ts
CHANGED
|
@@ -1,21 +1,51 @@
|
|
|
1
|
-
import type { CompiledValue } from "@telorun/sdk";
|
|
2
|
-
import { type Environment } from "@marcbachmann/cel-js";
|
|
3
1
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
2
|
+
* Compiling one CEL expression into a `CompiledValue`, and the repeatability verdict on its
|
|
3
|
+
* text.
|
|
4
|
+
*
|
|
5
|
+
* **The module-call rewrite is gone from this package.** It used to happen here, on the
|
|
6
|
+
* parsed tree, through internals the previous engine did not expose — a `setMeta('macro')`
|
|
7
|
+
* redirect that made a qualified call check and evaluate as something else. `@telorun/cel`
|
|
8
|
+
* has `qcall` as a node of its own, produced by a total tree-to-tree pass over the name set
|
|
9
|
+
* (`parseExpression({ namespaces })`), and a `CelExpression` records the set it was resolved
|
|
10
|
+
* under, so an environment refuses a tree resolved for a different site rather than
|
|
11
|
+
* silently answering a different question. What is left here is reading the result.
|
|
9
12
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
import { type CompiledValue } from "@telorun/sdk";
|
|
14
|
+
import { type CelEnvironment, type CelExpression, type NamespaceImplementation } from "@telorun/cel";
|
|
15
|
+
import { type ModuleCallDispatch } from "./module-call.js";
|
|
16
|
+
/**
|
|
17
|
+
* Whether an expression's text, written twice in one value, means one value both times: it
|
|
18
|
+
* calls no catalog function whose result differs per call, and makes no call that may be a
|
|
19
|
+
* module's — a module function's determinism is its callee's, which the text does not say.
|
|
20
|
+
*
|
|
21
|
+
* Text that does not read whole means no value, so it is not repeatable; `analyze` is what
|
|
22
|
+
* reports why. Reading never throws here, which is the engine's own contract: the first
|
|
23
|
+
* unreadable thing is one ranged diagnostic and the tree keeps the longest prefix.
|
|
24
|
+
*/
|
|
25
|
+
export declare function repeatableExpression(expr: string, environment: CelEnvironment): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Compile one CEL expression into a `CompiledValue`. The `!cel` engine compiles its whole
|
|
28
|
+
* scalar with it, and the tags with holes compile each hole.
|
|
14
29
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
|
|
20
|
-
export declare function compileExpression(expr: string,
|
|
30
|
+
* `moduleNames` are the declaring module's own names; a call whose receiver is one of them
|
|
31
|
+
* is resolved to a `qcall` as the expression is READ, so every later reader — the root
|
|
32
|
+
* references below, the analyzer's passes, the kernel's dependency walk — sees the resolved
|
|
33
|
+
* shape rather than re-deriving it from the source text.
|
|
34
|
+
*/
|
|
35
|
+
export declare function compileExpression(expr: string, environment: CelEnvironment, moduleNames?: ReadonlySet<string>): CompiledValue;
|
|
36
|
+
/** A `CompiledValue` over an expression already read against its site's names. */
|
|
37
|
+
export declare function compiledValueOf(expr: string, parsed: CelExpression, environment: CelEnvironment): CompiledValue;
|
|
38
|
+
/**
|
|
39
|
+
* A scope's module functions as the engine's own per-evaluation dispatch — **the one
|
|
40
|
+
* adapter**, so every host that binds a table converts its arguments the same way.
|
|
41
|
+
*
|
|
42
|
+
* The table is keyed by qualified name (`Billing.total`), the form the kernel and the
|
|
43
|
+
* analyzer both hold it in; the engine asks by namespace and name, never learning that a
|
|
44
|
+
* qualified name is one string with a dot in it. A second adapter is what made `telo check`
|
|
45
|
+
* and the kernel disagree: the analyzer kept its own, called the bound function with the raw
|
|
46
|
+
* values, and handed a map literal written at a call site a `CelMap` where the kernel handed
|
|
47
|
+
* a plain object — a check/run divergence by construction, in the one direction nothing
|
|
48
|
+
* reports.
|
|
49
|
+
*/
|
|
50
|
+
export declare function namespaceDispatchOf(table: ModuleCallDispatch | undefined): ((namespace: string, name: string) => NamespaceImplementation | undefined) | undefined;
|
|
21
51
|
//# sourceMappingURL=compile.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/cel/compile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/cel/compile.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAe,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAKL,KAAK,cAAc,EACnB,KAAK,aAAa,EAElB,KAAK,uBAAuB,EAC7B,MAAM,cAAc,CAAC;AACtB,OAAO,EAGL,KAAK,kBAAkB,EACxB,MAAM,kBAAkB,CAAC;AAwC1B;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,cAAc,GAAG,OAAO,CAIvF;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,cAAc,EAC3B,WAAW,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,GAChC,aAAa,CAYf;AAED,kFAAkF;AAClF,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,aAAa,EACrB,WAAW,EAAE,cAAc,GAC1B,aAAa,CAiBf;AAiCD;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,kBAAkB,GAAG,SAAS,GACpC,CAAC,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,uBAAuB,GAAG,SAAS,CAAC,GAAG,SAAS,CAMxF"}
|