@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
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { RuntimeError } from "@telorun/sdk";
|
|
2
|
+
import type { AnalyzeResult, EngineDiagnostic } from "../engine.js";
|
|
3
|
+
import type { CallAudit } from "./diagnose.js";
|
|
4
|
+
/** Every code the `!cel`, `!interpolate` and `!sql` engines emit: `diagnostics`
|
|
5
|
+
* from `analyze`, `errors` thrown by compiling or evaluating. Stated once here;
|
|
6
|
+
* the types below hold every emit site to it, and the conformance runner
|
|
7
|
+
* requires a `verdicts.json` row for each.
|
|
8
|
+
*
|
|
9
|
+
* **Four codes the ENGINE decides are deliberately absent**, because these engines cannot
|
|
10
|
+
* reach them and a code no row can pin is a claim the gate can never satisfy:
|
|
11
|
+
* `FUNCTION_UNRESOLVED`, `FUNCTION_ARITY_MISMATCH` and `FUNCTION_ARGUMENT_MISMATCH` need a
|
|
12
|
+
* namespace declared CLOSED and with a parameter list, and a module's names are registered
|
|
13
|
+
* open and withhold their parameters on purpose — whether a call reaches a function, and
|
|
14
|
+
* whether its arity and arguments fit, rest on the export gate, the dependency edge and a
|
|
15
|
+
* JSON Schema per parameter, which are the analyzer's verdicts. `CEL_TYPE_ARGUMENT_MISMATCH`
|
|
16
|
+
* needs a parameterized value type on both sides, and the brands registered here are
|
|
17
|
+
* nominal with a base and no parameters. Each is still reported where it IS decided — by
|
|
18
|
+
* the analyzer, against its own environment. */
|
|
19
|
+
export declare const CEL_VERDICT_CODES: {
|
|
20
|
+
readonly diagnostics: readonly ["BINDING_NAME_RESERVED", "CEL_INVALID_ARGUMENT", "CEL_NULLABLE_ACCESS", "CEL_SYNTAX_ERROR", "CEL_TYPE_ARGUMENT_MISMATCH", "CEL_TYPE_ERROR", "CEL_UNKNOWN_FIELD", "CEL_UNKNOWN_FUNCTION", "CEL_UNKNOWN_IDENTIFIER", "CEL_WRONG_CALL_FORM", "FUNCTION_ARGUMENT_MISMATCH", "FUNCTION_ARITY_MISMATCH", "FUNCTION_UNRESOLVED", "INTERPOLATION_HOLE_NOT_CONVERTIBLE"];
|
|
21
|
+
readonly errors: readonly ["ERR_INTERPOLATION_HOLE_NOT_CONVERTIBLE"];
|
|
22
|
+
};
|
|
23
|
+
export type CelDiagnosticCode = (typeof CEL_VERDICT_CODES.diagnostics)[number];
|
|
24
|
+
export type CelErrorCode = (typeof CEL_VERDICT_CODES.errors)[number];
|
|
25
|
+
/** A diagnostic one of the three engines builds. */
|
|
26
|
+
export interface CelDiagnostic extends EngineDiagnostic {
|
|
27
|
+
readonly code: CelDiagnosticCode;
|
|
28
|
+
}
|
|
29
|
+
/** What those engines' `analyze` answers. */
|
|
30
|
+
export interface CelAnalyzeResult extends AnalyzeResult {
|
|
31
|
+
readonly diagnostics: readonly CelDiagnostic[];
|
|
32
|
+
}
|
|
33
|
+
/** The call audit, as those engines read it. */
|
|
34
|
+
export interface CelCallAudit extends CallAudit {
|
|
35
|
+
readonly diagnostics: readonly CelDiagnostic[];
|
|
36
|
+
readonly argumentIssues: readonly CelDiagnostic[];
|
|
37
|
+
}
|
|
38
|
+
/** The one constructor of a coded error those engines throw. */
|
|
39
|
+
export declare function celVerdictError(code: CelErrorCode, message: string): RuntimeError;
|
|
40
|
+
//# sourceMappingURL=verdict-codes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verdict-codes.d.ts","sourceRoot":"","sources":["../../src/cel/verdict-codes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C;;;;;;;;;;;;;;iDAciD;AACjD,eAAO,MAAM,iBAAiB;;;CAsBpB,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,iBAAiB,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAC/E,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,iBAAiB,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC;AAErE,oDAAoD;AACpD,MAAM,WAAW,aAAc,SAAQ,gBAAgB;IACrD,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;CAClC;AAED,6CAA6C;AAC7C,MAAM,WAAW,gBAAiB,SAAQ,aAAa;IACrD,QAAQ,CAAC,WAAW,EAAE,SAAS,aAAa,EAAE,CAAC;CAChD;AAED,gDAAgD;AAChD,MAAM,WAAW,YAAa,SAAQ,SAAS;IAC7C,QAAQ,CAAC,WAAW,EAAE,SAAS,aAAa,EAAE,CAAC;IAC/C,QAAQ,CAAC,cAAc,EAAE,SAAS,aAAa,EAAE,CAAC;CACnD;AAED,gEAAgE;AAChE,wBAAgB,eAAe,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,GAAG,YAAY,CAEjF"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { RuntimeError } from "@telorun/sdk";
|
|
2
|
+
/** Every code the `!cel`, `!interpolate` and `!sql` engines emit: `diagnostics`
|
|
3
|
+
* from `analyze`, `errors` thrown by compiling or evaluating. Stated once here;
|
|
4
|
+
* the types below hold every emit site to it, and the conformance runner
|
|
5
|
+
* requires a `verdicts.json` row for each.
|
|
6
|
+
*
|
|
7
|
+
* **Four codes the ENGINE decides are deliberately absent**, because these engines cannot
|
|
8
|
+
* reach them and a code no row can pin is a claim the gate can never satisfy:
|
|
9
|
+
* `FUNCTION_UNRESOLVED`, `FUNCTION_ARITY_MISMATCH` and `FUNCTION_ARGUMENT_MISMATCH` need a
|
|
10
|
+
* namespace declared CLOSED and with a parameter list, and a module's names are registered
|
|
11
|
+
* open and withhold their parameters on purpose — whether a call reaches a function, and
|
|
12
|
+
* whether its arity and arguments fit, rest on the export gate, the dependency edge and a
|
|
13
|
+
* JSON Schema per parameter, which are the analyzer's verdicts. `CEL_TYPE_ARGUMENT_MISMATCH`
|
|
14
|
+
* needs a parameterized value type on both sides, and the brands registered here are
|
|
15
|
+
* nominal with a base and no parameters. Each is still reported where it IS decided — by
|
|
16
|
+
* the analyzer, against its own environment. */
|
|
17
|
+
export const CEL_VERDICT_CODES = {
|
|
18
|
+
diagnostics: [
|
|
19
|
+
"BINDING_NAME_RESERVED",
|
|
20
|
+
"CEL_INVALID_ARGUMENT",
|
|
21
|
+
"CEL_NULLABLE_ACCESS",
|
|
22
|
+
"CEL_SYNTAX_ERROR",
|
|
23
|
+
"CEL_TYPE_ARGUMENT_MISMATCH",
|
|
24
|
+
"CEL_TYPE_ERROR",
|
|
25
|
+
"CEL_UNKNOWN_FIELD",
|
|
26
|
+
"CEL_UNKNOWN_FUNCTION",
|
|
27
|
+
"CEL_UNKNOWN_IDENTIFIER",
|
|
28
|
+
"CEL_WRONG_CALL_FORM",
|
|
29
|
+
// Forwarded from the engine's checker, which decides them. Whether a module call
|
|
30
|
+
// REACHES a function, and whether its arity and arguments fit, is still the analyzer's
|
|
31
|
+
// verdict against its own environment — these engines register a module's names open and
|
|
32
|
+
// withhold their parameters, so they pass the engine's codes through rather than deciding.
|
|
33
|
+
"FUNCTION_ARGUMENT_MISMATCH",
|
|
34
|
+
"FUNCTION_ARITY_MISMATCH",
|
|
35
|
+
"FUNCTION_UNRESOLVED",
|
|
36
|
+
"INTERPOLATION_HOLE_NOT_CONVERTIBLE",
|
|
37
|
+
],
|
|
38
|
+
errors: ["ERR_INTERPOLATION_HOLE_NOT_CONVERTIBLE"],
|
|
39
|
+
};
|
|
40
|
+
/** The one constructor of a coded error those engines throw. */
|
|
41
|
+
export function celVerdictError(code, message) {
|
|
42
|
+
return new RuntimeError(code, message);
|
|
43
|
+
}
|
package/dist/engine.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CelEnvironment } from "@telorun/cel";
|
|
2
2
|
import type { CompiledValue } from "@telorun/sdk";
|
|
3
3
|
import type { ModuleCallFlags } from "./cel/diagnose.js";
|
|
4
4
|
import type { ModuleCallTypeResolver } from "./cel/module-call.js";
|
|
@@ -6,7 +6,7 @@ import type { ModuleCallTypeResolver } from "./cel/module-call.js";
|
|
|
6
6
|
* parse against a CEL environment (the `cel` engine) read it from `celEnv`;
|
|
7
7
|
* engines that resolve fully at compile time (`literal`) ignore it. */
|
|
8
8
|
export interface CompileEnv {
|
|
9
|
-
readonly celEnv:
|
|
9
|
+
readonly celEnv: CelEnvironment;
|
|
10
10
|
/**
|
|
11
11
|
* The names a call's receiver may be for the call to resolve as a MODULE
|
|
12
12
|
* call — the declaring module's `imports:` keys, `Self`, its `metadata.name`
|
|
@@ -31,7 +31,7 @@ export interface CompileEnv {
|
|
|
31
31
|
* expression again against a different environment. One expression, one
|
|
32
32
|
* verdict. */
|
|
33
33
|
export interface AnalyzeEnv {
|
|
34
|
-
readonly celEnv:
|
|
34
|
+
readonly celEnv: CelEnvironment;
|
|
35
35
|
readonly contextSchema: Record<string, unknown> | null;
|
|
36
36
|
/**
|
|
37
37
|
* The caller vouches that `celEnv` declares EVERY name legal at this site, so
|
|
@@ -191,6 +191,10 @@ export interface EngineFileClaim {
|
|
|
191
191
|
/** The path may name a directory, which then claims every file beneath it.
|
|
192
192
|
* Whether it does is a question for whoever holds the directory. */
|
|
193
193
|
readonly directory?: boolean;
|
|
194
|
+
/** The diagnostic code reporting a claim that names nothing — the static twin
|
|
195
|
+
* of the runtime's refusal, declared by the engine so the existence check
|
|
196
|
+
* recognises no tag by name. */
|
|
197
|
+
readonly notFoundCode: string;
|
|
194
198
|
}
|
|
195
199
|
/** One CEL expression inside a tagged scalar, by offset into the scalar's
|
|
196
200
|
* source. */
|
|
@@ -261,5 +265,16 @@ export interface TemplatingEngine {
|
|
|
261
265
|
* engine whose scalar holds no CEL. A source the engine cannot read yields
|
|
262
266
|
* no regions; `analyze` is what reports why. */
|
|
263
267
|
expressionRegions?(source: string): readonly ExpressionRegion[];
|
|
268
|
+
/** Whether the tagged text, written twice in one value, means one value both
|
|
269
|
+
* times — the engine's verdict on the TEXT ALONE, with no module name set and
|
|
270
|
+
* nothing evaluated: no expression in it calls a catalog function whose
|
|
271
|
+
* result differs per call, and none makes a call that may be a module's (a
|
|
272
|
+
* method on a bare identifier), whose determinism is its callee's.
|
|
273
|
+
*
|
|
274
|
+
* What lets a consumer holding two character-identical tagged scalars say
|
|
275
|
+
* they are equal without evaluating either. Absent on an engine that gives no
|
|
276
|
+
* such verdict, which reads as "not repeatable". A source the engine cannot
|
|
277
|
+
* read is not repeatable; `analyze` is what reports why. */
|
|
278
|
+
repeatable?(source: string, celEnv: CelEnvironment): boolean;
|
|
264
279
|
}
|
|
265
280
|
//# sourceMappingURL=engine.d.ts.map
|
package/dist/engine.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"m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AAG,SAAS,gBAAgB,EAAE,CAAC;IAEhE;;;;;;;;;iEAS6D;IAC7D,UAAU,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC;CAC9D"}
|
package/dist/engines/cel.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type {
|
|
1
|
+
import { type CelNode } from "@telorun/cel";
|
|
2
|
+
import type { CelAnalyzeResult } from "../cel/verdict-codes.js";
|
|
3
|
+
import type { AnalyzeEnv, TemplatingEngine } from "../engine.js";
|
|
3
4
|
/** Statically analyze one CEL expression against the effective context schema:
|
|
4
5
|
* parse → classify every call → type-check → validate member-access chains →
|
|
5
6
|
* flag nullable access. Single source of truth shared by the `!cel` engine
|
|
@@ -11,12 +12,12 @@ import type { AnalyzeEnv, AnalyzeResult, TemplatingEngine } from "../engine.js";
|
|
|
11
12
|
* "no matching overload" survive next to the diagnostic that actually
|
|
12
13
|
* explained it, and left `${{ }}` interpolations chain-validated but never
|
|
13
14
|
* type-checked at all. */
|
|
14
|
-
export declare function analyzeCelExpression(source: string, env: AnalyzeEnv):
|
|
15
|
+
export declare function analyzeCelExpression(source: string, env: AnalyzeEnv): CelAnalyzeResult;
|
|
15
16
|
/** {@link analyzeCelExpression}, with the resolved tree it built — for a tag
|
|
16
17
|
* that asks its own questions of one expression without parsing it again. */
|
|
17
18
|
export declare function analyzeCelWithTree(source: string, env: AnalyzeEnv): {
|
|
18
|
-
result:
|
|
19
|
-
ast?:
|
|
19
|
+
result: CelAnalyzeResult;
|
|
20
|
+
ast?: CelNode;
|
|
20
21
|
};
|
|
21
22
|
/** The `!cel` engine. Treats the entire tagged scalar as a single CEL
|
|
22
23
|
* expression — no `${{ }}` wrapping. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cel.d.ts","sourceRoot":"","sources":["../../src/engines/cel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"cel.d.ts","sourceRoot":"","sources":["../../src/engines/cel.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,KAAK,OAAO,EAAE,MAAM,cAAc,CAAC;AAYxE,OAAO,KAAK,EAAE,gBAAgB,EAAiB,MAAM,yBAAyB,CAAC;AAC/E,OAAO,KAAK,EAAE,UAAU,EAAY,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAE3E;;;;;;;;;;2BAU2B;AAC3B,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,GAAG,gBAAgB,CAEtF;AAED;8EAC8E;AAC9E,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,UAAU,GACd;IAAE,MAAM,EAAE,gBAAgB,CAAC;IAAC,GAAG,CAAC,EAAE,OAAO,CAAA;CAAE,CAoL7C;AAkDD;yCACyC;AACzC,eAAO,MAAM,SAAS,EAAE,gBAmBvB,CAAC"}
|
package/dist/engines/cel.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { qualifiedCalls } from "@telorun/cel";
|
|
2
|
+
import { extractAccessChains, extractCallResultAccesses, findNullableAccessIssues, INDEX_SEGMENT, validateChainAgainstSchema, } from "../cel/analyze.js";
|
|
3
|
+
import { compileExpression, repeatableExpression } from "../cel/compile.js";
|
|
4
|
+
import { auditCalls } from "../cel/diagnose.js";
|
|
5
|
+
import { moduleNameBindings, unresolvedCallReceivers } from "../cel/module-call.js";
|
|
5
6
|
/** Statically analyze one CEL expression against the effective context schema:
|
|
6
7
|
* parse → classify every call → type-check → validate member-access chains →
|
|
7
8
|
* flag nullable access. Single source of truth shared by the `!cel` engine
|
|
@@ -20,29 +21,29 @@ export function analyzeCelExpression(source, env) {
|
|
|
20
21
|
* that asks its own questions of one expression without parsing it again. */
|
|
21
22
|
export function analyzeCelWithTree(source, env) {
|
|
22
23
|
const out = [];
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
// **Reading never throws and never discards what it read**: the first unreadable thing is
|
|
25
|
+
// one ranged diagnostic and the tree keeps the longest prefix, so a scalar an author is
|
|
26
|
+
// mid-way through typing still reports its chains and its calls.
|
|
27
|
+
const parsed = env.celEnv.parse(source);
|
|
28
|
+
if (parsed.diagnostics.length > 0) {
|
|
29
|
+
const first = parsed.diagnostics[0];
|
|
28
30
|
return {
|
|
29
31
|
result: {
|
|
30
|
-
diagnostics: [{ code: "CEL_SYNTAX_ERROR", message:
|
|
32
|
+
diagnostics: [{ code: "CEL_SYNTAX_ERROR", message: first.message }],
|
|
31
33
|
calls: [],
|
|
32
34
|
},
|
|
33
35
|
};
|
|
34
36
|
}
|
|
35
|
-
const ast = parsed.
|
|
36
|
-
// Resolution
|
|
37
|
-
//
|
|
38
|
-
// know a module name from a variable.
|
|
39
|
-
|
|
40
|
-
const resolvedCalls = resolveModuleCalls(parsed.ast, env.moduleNames, env.moduleCallType).length > 0;
|
|
37
|
+
const ast = parsed.root;
|
|
38
|
+
// Resolution happened as the expression was READ, over the environment's own namespaces —
|
|
39
|
+
// `qcall` is a node of its own rather than a rewrite — so every walk below already sees
|
|
40
|
+
// the resolved shape and none of them has to know a module name from a variable.
|
|
41
|
+
const resolvedCalls = qualifiedCalls(ast).length > 0;
|
|
41
42
|
// A name bound inside the expression can never be read once a module owns it:
|
|
42
43
|
// `Billing.f(x)` under a comprehension variable named `Billing` resolves to
|
|
43
44
|
// the module. Reported rather than silently shadowed, the rule every other
|
|
44
45
|
// name in CEL scope follows.
|
|
45
|
-
for (const name of moduleNameBindings(
|
|
46
|
+
for (const name of moduleNameBindings(ast, env.moduleNames)) {
|
|
46
47
|
out.push({
|
|
47
48
|
code: "BINDING_NAME_RESERVED",
|
|
48
49
|
message: `'${name}' names a module here (an imports: alias, Self, or this module's own name), ` +
|
|
@@ -50,7 +51,8 @@ export function analyzeCelWithTree(source, env) {
|
|
|
50
51
|
`be read. Rename the bound variable.`,
|
|
51
52
|
});
|
|
52
53
|
}
|
|
53
|
-
const
|
|
54
|
+
const checked = env.celEnv.check(parsed);
|
|
55
|
+
const audit = auditCalls(source, ast, env.celEnv, env.moduleCallFlags, checked);
|
|
54
56
|
// Reported whatever the type-checker concludes. A literal argument a guard
|
|
55
57
|
// will refuse is a defect the manifest states outright, and leaving it to the
|
|
56
58
|
// run is the thing static analysis exists to prevent — so it is not gated on
|
|
@@ -59,16 +61,25 @@ export function analyzeCelWithTree(source, env) {
|
|
|
59
61
|
let type;
|
|
60
62
|
let checkError;
|
|
61
63
|
try {
|
|
62
|
-
//
|
|
63
|
-
//
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
64
|
+
// The TREE is checked, never the source again: `check(source)` would re-read it, and a
|
|
65
|
+
// tree resolved under another site's names is refused rather than answered about.
|
|
66
|
+
if (checked.valid)
|
|
67
|
+
type = checked.typeName;
|
|
68
|
+
else {
|
|
69
|
+
// **Every verdict is the engine's, coded and ranged.** This used to be one opaque
|
|
70
|
+
// sentence — `found no matching overload for 'f(...)'` for three unrelated mistakes —
|
|
71
|
+
// which is why a classifier sat beside it rewriting the message. The engine decides an
|
|
72
|
+
// unknown name, a name called in the other form, an unknown field, a type no overload
|
|
73
|
+
// takes and a refusal over a literal argument each where its cause is known, so they
|
|
74
|
+
// come through as they are.
|
|
75
|
+
for (const diagnostic of checked.diagnostics) {
|
|
76
|
+
out.push({
|
|
77
|
+
code: diagnostic.code,
|
|
78
|
+
message: diagnostic.message,
|
|
79
|
+
...(diagnostic.fix ? { fix: diagnostic.fix } : {}),
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
checkError = checked.diagnostics[0]?.message;
|
|
72
83
|
}
|
|
73
84
|
}
|
|
74
85
|
catch (e) {
|
|
@@ -97,22 +108,9 @@ export function analyzeCelWithTree(source, env) {
|
|
|
97
108
|
// this analyzer refuses and the kernel would run fine.
|
|
98
109
|
// What explaining a rejection already reported, so the context's own chain
|
|
99
110
|
// check below does not report it twice.
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
// which is the whole reason it exists as more than a message rewriter.
|
|
104
|
-
out.push(...audit.diagnostics);
|
|
105
|
-
const unknownFields = audit.diagnostics.length === 0 ? explainUnknownFields(parsed.ast, env) : [];
|
|
106
|
-
out.push(...unknownFields);
|
|
107
|
-
for (const d of unknownFields)
|
|
108
|
-
explained.add(d.message);
|
|
109
|
-
if (audit.diagnostics.length === 0 && unknownFields.length === 0) {
|
|
110
|
-
out.push({
|
|
111
|
-
code: "CEL_TYPE_ERROR",
|
|
112
|
-
message: checkError + explainUnresolved(audit.unresolved, env.celEnv) + DYN_HINT(checkError),
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
}
|
|
111
|
+
// What the engine already said, so the host's own schema reading below does not say it
|
|
112
|
+
// twice in different words.
|
|
113
|
+
const explained = new Set(out.map((diagnostic) => diagnostic.message));
|
|
116
114
|
// An undeclared ROOT identifier. cel-js types an unknown name as `dyn` and
|
|
117
115
|
// accepts it, so `!cel "fff"` type-checked, reached the runtime and resolved
|
|
118
116
|
// to nothing — the one CEL mistake with no static report at all. Member
|
|
@@ -130,12 +128,12 @@ export function analyzeCelWithTree(source, env) {
|
|
|
130
128
|
// Walked only once a root is unknown, which a correct expression never has.
|
|
131
129
|
let callReceivers;
|
|
132
130
|
const reported = new Set();
|
|
133
|
-
for (const chain of extractAccessChains(
|
|
131
|
+
for (const chain of extractAccessChains(ast)) {
|
|
134
132
|
const root = chain[0];
|
|
135
133
|
if (!root || reported.has(root) || env.celEnv.hasVariable(root))
|
|
136
134
|
continue;
|
|
137
135
|
reported.add(root);
|
|
138
|
-
callReceivers ??= unresolvedCallReceivers(
|
|
136
|
+
callReceivers ??= unresolvedCallReceivers(ast, env.moduleNames);
|
|
139
137
|
out.push({
|
|
140
138
|
code: "CEL_UNKNOWN_IDENTIFIER",
|
|
141
139
|
message: `unknown identifier '${root}' — nothing by that name is in scope here.` +
|
|
@@ -149,7 +147,7 @@ export function analyzeCelWithTree(source, env) {
|
|
|
149
147
|
// caller resolves: member access on it is checked exactly as a read off the
|
|
150
148
|
// context would be, under the call as written.
|
|
151
149
|
if (resolvedCalls && env.moduleCallResult) {
|
|
152
|
-
for (const access of extractCallResultAccesses(
|
|
150
|
+
for (const access of extractCallResultAccesses(ast)) {
|
|
153
151
|
const schema = env.moduleCallResult(access.qualified);
|
|
154
152
|
if (!schema)
|
|
155
153
|
continue;
|
|
@@ -164,12 +162,12 @@ export function analyzeCelWithTree(source, env) {
|
|
|
164
162
|
}
|
|
165
163
|
if (env.contextSchema) {
|
|
166
164
|
const contextSchema = env.contextSchema;
|
|
167
|
-
for (const chain of extractAccessChains(
|
|
165
|
+
for (const chain of extractAccessChains(ast)) {
|
|
168
166
|
const err = validateChainAgainstSchema(chain, contextSchema);
|
|
169
167
|
if (err && !explained.has(err))
|
|
170
168
|
out.push({ code: "CEL_UNKNOWN_FIELD", message: err });
|
|
171
169
|
}
|
|
172
|
-
for (const issue of findNullableAccessIssues(
|
|
170
|
+
for (const issue of findNullableAccessIssues(ast, contextSchema)) {
|
|
173
171
|
// Index access (member "[index]") attaches without a dot; a named field
|
|
174
172
|
// attaches with one — so the suggested CEL stays valid either way.
|
|
175
173
|
const access = issue.member === "[index]" ? issue.member : `.${issue.member}`;
|
|
@@ -182,10 +180,12 @@ export function analyzeCelWithTree(source, env) {
|
|
|
182
180
|
return {
|
|
183
181
|
result: {
|
|
184
182
|
diagnostics: out,
|
|
185
|
-
calls:
|
|
183
|
+
calls: audit.calls,
|
|
186
184
|
...(type === undefined ? {} : { type }),
|
|
187
|
-
...(ast.
|
|
188
|
-
|
|
185
|
+
...(ast.kind === "literal" && ast.literal.type === "string"
|
|
186
|
+
? { stringLiteral: ast.literal.value }
|
|
187
|
+
: {}),
|
|
188
|
+
...(checkError === undefined ? {} : { readTypes: chainTypes(ast, env) }),
|
|
189
189
|
},
|
|
190
190
|
ast,
|
|
191
191
|
};
|
|
@@ -217,8 +217,8 @@ function chainTypes(ast, env) {
|
|
|
217
217
|
if (chain.includes(INDEX_SEGMENT))
|
|
218
218
|
continue;
|
|
219
219
|
const result = env.celEnv.check(chain.join("."));
|
|
220
|
-
if (result.valid
|
|
221
|
-
types.add(result.
|
|
220
|
+
if (result.valid)
|
|
221
|
+
types.add(result.typeName);
|
|
222
222
|
}
|
|
223
223
|
return [...types];
|
|
224
224
|
}
|
|
@@ -228,34 +228,6 @@ function checkerRejects(chain, env) {
|
|
|
228
228
|
const named = end === -1 ? chain : chain.slice(0, end);
|
|
229
229
|
return !env.celEnv.check(named.join(".")).valid;
|
|
230
230
|
}
|
|
231
|
-
/** The audited call sites, each module call carrying its arguments as the type
|
|
232
|
-
* check saw them. Matched by position, which is what identifies one call among
|
|
233
|
-
* several of the same name. */
|
|
234
|
-
function withCallArguments(calls, ast) {
|
|
235
|
-
const byStart = new Map();
|
|
236
|
-
for (const { node, call } of moduleCallNodes(ast))
|
|
237
|
-
byStart.set(node.start, call);
|
|
238
|
-
const chainsByStart = new Map();
|
|
239
|
-
for (const [node, chains] of moduleCallArgumentChains(ast))
|
|
240
|
-
chainsByStart.set(node.start, chains);
|
|
241
|
-
return calls.map((site) => {
|
|
242
|
-
const call = site.moduleCall ? byStart.get(site.start) : undefined;
|
|
243
|
-
if (!call)
|
|
244
|
-
return site;
|
|
245
|
-
const chains = chainsByStart.get(site.start);
|
|
246
|
-
return {
|
|
247
|
-
...site,
|
|
248
|
-
arguments: call.args.map((arg, index) => {
|
|
249
|
-
const type = call.argumentTypes?.[index];
|
|
250
|
-
const chain = chains?.[index] ?? null;
|
|
251
|
-
return {
|
|
252
|
-
...(type !== undefined ? { type } : {}),
|
|
253
|
-
...(chain && !chain.includes(INDEX_SEGMENT) ? { chain } : {}),
|
|
254
|
-
};
|
|
255
|
-
}),
|
|
256
|
-
};
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
231
|
/** `dyn` in a checker message means an operand whose type is unknown here —
|
|
260
232
|
* almost always a step result whose invoked resource declares no
|
|
261
233
|
* `outputType:`. Without this, the reader takes `dyn` for a cast problem. */
|
|
@@ -279,4 +251,7 @@ export const celEngine = {
|
|
|
279
251
|
expressionRegions(source) {
|
|
280
252
|
return [{ start: 0, end: source.length }];
|
|
281
253
|
},
|
|
254
|
+
repeatable(source, celEnv) {
|
|
255
|
+
return repeatableExpression(source, celEnv);
|
|
256
|
+
},
|
|
282
257
|
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CelEnvironment, CelNode } from "@telorun/cel";
|
|
2
2
|
import type { CompiledValue } from "@telorun/sdk";
|
|
3
3
|
import { type InterpolationHole } from "../cel/interpolation-holes.js";
|
|
4
|
-
import type {
|
|
4
|
+
import type { CelAnalyzeResult, CelDiagnostic } from "../cel/verdict-codes.js";
|
|
5
|
+
import type { AnalyzeEnv, CompileEnv, ExpressionRegion } from "../engine.js";
|
|
5
6
|
/** The holes of a scalar a hole-bearing tag compiles, or a thrown error naming
|
|
6
7
|
* where the reading failed — a tag's scalar that cannot be read is not a value. */
|
|
7
8
|
export declare function requireHoles(tag: string, source: string): readonly InterpolationHole[];
|
|
@@ -17,7 +18,10 @@ export declare function compileHoles(holes: readonly InterpolationHole[], env: C
|
|
|
17
18
|
* as they do under `!cel`; a fix computed against one hole's expression is
|
|
18
19
|
* re-anchored onto the whole scalar, and call offsets onto the scalar too.
|
|
19
20
|
* `perHole` adds a tag's own verdict on a hole that analyzed clean. */
|
|
20
|
-
export declare function analyzeHoles(source: string, env: AnalyzeEnv, perHole?: (hole: InterpolationHole, result:
|
|
21
|
+
export declare function analyzeHoles(source: string, env: AnalyzeEnv, perHole?: (hole: InterpolationHole, result: CelAnalyzeResult, ast: CelNode | undefined) => readonly CelDiagnostic[]): CelAnalyzeResult;
|
|
21
22
|
/** The CEL expressions of a hole-bearing scalar, by offset. */
|
|
22
23
|
export declare function holeRegions(source: string): readonly ExpressionRegion[];
|
|
24
|
+
/** Whether every hole of a hole-bearing scalar is repeatable; the literal text
|
|
25
|
+
* between them always is. */
|
|
26
|
+
export declare function holesRepeatable(source: string, celEnv: CelEnvironment): boolean;
|
|
23
27
|
//# sourceMappingURL=hole-analysis.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hole-analysis.d.ts","sourceRoot":"","sources":["../../src/engines/hole-analysis.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"hole-analysis.d.ts","sourceRoot":"","sources":["../../src/engines/hole-analysis.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC/E,OAAO,KAAK,EAAE,UAAU,EAAY,UAAU,EAAiB,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAGtG;oFACoF;AACpF,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,iBAAiB,EAAE,CAItF;AAED;sDACsD;AACtD,wBAAgB,YAAY,CAC1B,KAAK,EAAE,SAAS,iBAAiB,EAAE,EACnC,GAAG,EAAE,UAAU,GACd;IACD,QAAQ,CAAC,QAAQ,EAAE,SAAS,aAAa,EAAE,CAAC;IAC5C,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC5B,CAWA;AAED;;;wEAGwE;AACxE,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,UAAU,EACf,OAAO,CAAC,EAAE,CACR,IAAI,EAAE,iBAAiB,EACvB,MAAM,EAAE,gBAAgB,EACxB,GAAG,EAAE,OAAO,GAAG,SAAS,KACrB,SAAS,aAAa,EAAE,GAC5B,gBAAgB,CAkBlB;AAED,+DAA+D;AAC/D,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,gBAAgB,EAAE,CAIvE;AAED;8BAC8B;AAC9B,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,GAAG,OAAO,CAG/E"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { compileExpression } from "../cel/compile.js";
|
|
1
|
+
import { compileExpression, repeatableExpression } from "../cel/compile.js";
|
|
2
2
|
import { readInterpolationHoles, } from "../cel/interpolation-holes.js";
|
|
3
3
|
import { analyzeCelWithTree } from "./cel.js";
|
|
4
4
|
/** The holes of a scalar a hole-bearing tag compiles, or a thrown error naming
|
|
@@ -57,6 +57,12 @@ export function holeRegions(source) {
|
|
|
57
57
|
return [];
|
|
58
58
|
return reading.holes.map((h) => ({ start: h.exprStart, end: h.exprStart + h.expr.length }));
|
|
59
59
|
}
|
|
60
|
+
/** Whether every hole of a hole-bearing scalar is repeatable; the literal text
|
|
61
|
+
* between them always is. */
|
|
62
|
+
export function holesRepeatable(source, celEnv) {
|
|
63
|
+
const reading = readInterpolationHoles(source);
|
|
64
|
+
return reading.ok && reading.holes.every((h) => repeatableExpression(h.expr, celEnv));
|
|
65
|
+
}
|
|
60
66
|
function reanchor(source, hole, fix) {
|
|
61
67
|
return {
|
|
62
68
|
replacement: source.slice(0, hole.exprStart) +
|
package/dist/engines/include.js
CHANGED
|
@@ -146,7 +146,7 @@ function includeEngine(name, produced) {
|
|
|
146
146
|
// A malformed path claims nothing. `analyze` is what says why, so
|
|
147
147
|
// claiming a half-understood path here would produce a second, worse
|
|
148
148
|
// report from publish about the same mistake.
|
|
149
|
-
return path ? [{ path }] : [];
|
|
149
|
+
return path ? [{ path, notFoundCode: "INCLUDE_FILE_NOT_FOUND" }] : [];
|
|
150
150
|
},
|
|
151
151
|
};
|
|
152
152
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interpolate.d.ts","sourceRoot":"","sources":["../../src/engines/interpolate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"interpolate.d.ts","sourceRoot":"","sources":["../../src/engines/interpolate.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAc,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAWjE;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,EAAE,gBAwC/B,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { RuntimeError } from "@telorun/sdk";
|
|
1
|
+
import { CelEvaluationError, isCelMap, isCelRecord } from "@telorun/cel";
|
|
3
2
|
import { nullableValueChain } from "../cel/analyze.js";
|
|
4
3
|
import { literalFragments } from "../cel/interpolation-holes.js";
|
|
5
|
-
import {
|
|
4
|
+
import { celVerdictError } from "../cel/verdict-codes.js";
|
|
5
|
+
import { analyzeHoles, compileHoles, holeRegions, holesRepeatable, requireHoles, } from "./hole-analysis.js";
|
|
6
6
|
const INTERPOLATE_ENGINE = "interpolate";
|
|
7
7
|
/**
|
|
8
8
|
* The `!interpolate` engine: literal text with `${{ expr }}` holes, always a
|
|
@@ -46,6 +46,9 @@ export const interpolateEngine = {
|
|
|
46
46
|
expressionRegions(source) {
|
|
47
47
|
return holeRegions(source);
|
|
48
48
|
},
|
|
49
|
+
repeatable(source, celEnv) {
|
|
50
|
+
return holesRepeatable(source, celEnv);
|
|
51
|
+
},
|
|
49
52
|
};
|
|
50
53
|
/** A clean hole's own checks, over the tree its analysis already built:
|
|
51
54
|
* whether it may be null, and whether CEL can turn its type into text at all. */
|
|
@@ -80,9 +83,9 @@ function convertibleTypes(env) {
|
|
|
80
83
|
if (cached)
|
|
81
84
|
return cached;
|
|
82
85
|
const types = new Set(["dyn"]);
|
|
83
|
-
for (const fn of env.
|
|
84
|
-
if (fn.name === "string" && fn.receiverType === null && fn.
|
|
85
|
-
types.add(fn.
|
|
86
|
+
for (const fn of env.definitions().functions) {
|
|
87
|
+
if (fn.name === "string" && fn.receiverType === null && fn.parameters.length === 1) {
|
|
88
|
+
types.add(fn.parameters[0]);
|
|
86
89
|
}
|
|
87
90
|
}
|
|
88
91
|
CONVERTIBLE.set(env, types);
|
|
@@ -94,17 +97,17 @@ function stringConversion(env) {
|
|
|
94
97
|
const cached = CONVERSIONS.get(env);
|
|
95
98
|
if (cached)
|
|
96
99
|
return cached;
|
|
97
|
-
const program = env.
|
|
100
|
+
const program = env.compile("string(value)");
|
|
98
101
|
const conversion = (value, hole, source) => {
|
|
99
102
|
if (typeof value === "string")
|
|
100
103
|
return value;
|
|
101
104
|
try {
|
|
102
|
-
return program({ value });
|
|
105
|
+
return program.evaluate({ value });
|
|
103
106
|
}
|
|
104
107
|
catch (error) {
|
|
105
|
-
if (!(error instanceof
|
|
108
|
+
if (!(error instanceof CelEvaluationError))
|
|
106
109
|
throw error;
|
|
107
|
-
throw
|
|
110
|
+
throw celVerdictError("ERR_INTERPOLATION_HOLE_NOT_CONVERTIBLE", `the hole '\${{ ${hole.expr} }}' at offset ${hole.start} of !interpolate ${JSON.stringify(source)} ` +
|
|
108
111
|
`evaluated to ${runtimeTypeOf(value)}, which CEL's string() cannot convert to text. ` +
|
|
109
112
|
`Declare outputType on the resource producing it so the check sees its type, or guard it inside the hole.`);
|
|
110
113
|
}
|
|
@@ -117,7 +120,10 @@ function runtimeTypeOf(value) {
|
|
|
117
120
|
return "null";
|
|
118
121
|
if (Array.isArray(value))
|
|
119
122
|
return "a list";
|
|
120
|
-
|
|
123
|
+
// Both of the value domain's map representations, asked of the domain rather than of the
|
|
124
|
+
// prototype: a branded value is a plain object, so a prototype test named an optional, a
|
|
125
|
+
// type and every host named type "a map".
|
|
126
|
+
if (isCelMap(value) || isCelRecord(value))
|
|
121
127
|
return "a map";
|
|
122
128
|
return `a value of type ${value.constructor?.name ?? typeof value}`;
|
|
123
129
|
}
|
|
@@ -28,6 +28,6 @@ export const modulePathEngine = {
|
|
|
28
28
|
},
|
|
29
29
|
fileClaims(source) {
|
|
30
30
|
const { path } = normalizeModulePath(source);
|
|
31
|
-
return path ? [{ path, directory: true }] : [];
|
|
31
|
+
return path ? [{ path, directory: true, notFoundCode: "MODULE_PATH_NOT_FOUND" }] : [];
|
|
32
32
|
},
|
|
33
33
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sql.d.ts","sourceRoot":"","sources":["../../src/engines/sql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAsB,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAE7F,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"sql.d.ts","sourceRoot":"","sources":["../../src/engines/sql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAsB,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAE7F,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AASrD,OAAO,EAAE,kBAAkB,EAAE,KAAK,gBAAgB,EAAE,CAAC;AAErD;;;;;kFAKkF;AAClF,eAAO,MAAM,SAAS,EAAE,gBAsCvB,CAAC"}
|
package/dist/engines/sql.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isParameterizedSql } from "@telorun/sdk";
|
|
2
2
|
import { literalFragments } from "../cel/interpolation-holes.js";
|
|
3
|
-
import { analyzeHoles, compileHoles, holeRegions, requireHoles } from "./hole-analysis.js";
|
|
3
|
+
import { analyzeHoles, compileHoles, holeRegions, holesRepeatable, requireHoles, } from "./hole-analysis.js";
|
|
4
4
|
export { isParameterizedSql };
|
|
5
5
|
/** The `!sql` engine. Treats the tagged scalar as a SQL string with `${{ }}`
|
|
6
6
|
* holes whose values are *bound*, not spliced. Unlike `!cel` (one bare
|
|
@@ -39,4 +39,7 @@ export const sqlEngine = {
|
|
|
39
39
|
expressionRegions(source) {
|
|
40
40
|
return holeRegions(source);
|
|
41
41
|
},
|
|
42
|
+
repeatable(source, celEnv) {
|
|
43
|
+
return holesRepeatable(source, celEnv);
|
|
44
|
+
},
|
|
42
45
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export { buildCelEnvironment, celBuiltinFunctions,
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
1
|
+
export { buildCelEnvironment, buildCelLanguageEnvironment, celBuiltinFunctions, celFunctionCatalog, type CelHandlers, } from "./cel/environment.js";
|
|
2
|
+
export { compileExpression, namespaceDispatchOf } from "./cel/compile.js";
|
|
3
|
+
export { registerValueBrands } from "./cel/value-brands.js";
|
|
4
4
|
export { interpolationShape, literalFragments, readInterpolationHoles, type HoleReading, type InterpolationHole, type InterpolationShape, } from "./cel/interpolation-holes.js";
|
|
5
5
|
export { extractAccessChains, findNullableAccessIssues, INDEX_SEGMENT, validateChainAgainstSchema, } from "./cel/analyze.js";
|
|
6
|
-
export { auditCalls, explainUnresolved,
|
|
7
|
-
export { MODULE_CALL_DISPATCH_KEY,
|
|
6
|
+
export { auditCalls, explainUnresolved, type CallAudit, type ModuleCallFlags, } from "./cel/diagnose.js";
|
|
7
|
+
export { celNamespaceNames, MODULE_CALL_DISPATCH_KEY, moduleCallNames, moduleCallOf, type ModuleCallDispatch, type ModuleCallTypeResolver, } from "./cel/module-call.js";
|
|
8
8
|
export { walkCelExpressions } from "./cel/walk.js";
|
|
9
9
|
export { celEngine } from "./engines/cel.js";
|
|
10
10
|
export { includeBytesEngine, includeTextEngine, normalizeIncludePath, normalizeModulePath, type NormalizedIncludePath, } from "./engines/include.js";
|
|
@@ -14,7 +14,7 @@ export { modulePathEngine } from "./engines/module-path.js";
|
|
|
14
14
|
export { refEngine } from "./engines/ref.js";
|
|
15
15
|
export { sqlEngine, isParameterizedSql, type ParameterizedSql } from "./engines/sql.js";
|
|
16
16
|
export { TemplatingEngineRegistry } from "./registry.js";
|
|
17
|
-
export { builtinEngines, celExpressionsOf, createDefaultRegistry, defaultRegistry, producedTypeOf, } from "./builtins.js";
|
|
17
|
+
export { builtinEngines, celExpressionsOf, createDefaultRegistry, defaultRegistry, producedTypeOf, repeatableSource, } from "./builtins.js";
|
|
18
18
|
export type { AnalyzeEnv, AnalyzeResult, CallArgument, CallSite, CompileEnv, DiagnosticFix, EngineDiagnostic, EngineFileClaim, ExpressionRegion, TemplatingEngine, } from "./engine.js";
|
|
19
19
|
export { CEL_ENGINE, INCLUDE_BYTES_ENGINE, INCLUDE_ENGINE_NAMES, INCLUDE_TEXT_ENGINE, isIncludeSentinel, isModulePathSentinel, isRefSentinel, isTaggedSentinel, makeTaggedSentinel, MODULE_FILE_ENGINE_NAMES, MODULE_PATH_ENGINE, plainChainOf, type TaggedSentinel, } from "./sentinel.js";
|
|
20
20
|
export { buildCustomTags, defaultCustomTags } from "./yaml-tags.js";
|