@telorun/analyzer 0.51.0 → 0.52.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/analyzer.d.ts.map +1 -1
- package/dist/analyzer.js +121 -4
- package/dist/cel-bindings.d.ts +57 -0
- package/dist/cel-bindings.d.ts.map +1 -0
- package/dist/cel-bindings.js +207 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/sources/integrity.d.ts +10 -0
- package/dist/sources/integrity.d.ts.map +1 -1
- package/dist/sources/integrity.js +18 -0
- package/dist/validate-cel-context.d.ts.map +1 -1
- package/dist/validate-cel-context.js +8 -3
- package/package.json +2 -2
- package/src/analyzer.ts +146 -3
- package/src/cel-bindings.ts +222 -0
- package/src/index.ts +9 -0
- package/src/sources/integrity.ts +20 -0
- package/src/validate-cel-context.ts +8 -3
package/dist/analyzer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analyzer.d.ts","sourceRoot":"","sources":["../src/analyzer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAIzE,OAAO,EACL,aAAa,EAEb,KAAK,YAAY,EAElB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAIL,KAAK,WAAW,EACjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D,OAAO,EACL,KAAK,aAAa,EAGnB,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"analyzer.d.ts","sourceRoot":"","sources":["../src/analyzer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAIzE,OAAO,EACL,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initionRegistry } from "./definition-registry.js";
|
|
|
6
6
|
import { effectiveAuthorSchema } from "./extends-resolution.js";
|
|
7
7
|
import { PERMISSIVE_CONTRACT, resolveContract, } from "./invocation-contract.js";
|
|
8
8
|
import { buildDependencyGraph, formatCycle } from "./dependency-graph.js";
|
|
9
|
-
import { buildKernelGlobalsSchema, mergeKernelGlobalsIntoContext } from "./kernel-globals.js";
|
|
9
|
+
import { buildKernelGlobalsSchema, KERNEL_GLOBAL_NAMES, mergeKernelGlobalsIntoContext, } from "./kernel-globals.js";
|
|
10
10
|
import { buildObservedStateIndex, buildObservedStateResourcesSchema, collectRunReachableNames, observedStateRead, validateObservedStateDeclarations, } from "./validate-observed-state.js";
|
|
11
11
|
import { computeSuggestKind } from "./kind-suggest.js";
|
|
12
12
|
import { visitManifest } from "./manifest-visitor.js";
|
|
@@ -21,8 +21,9 @@ import { rewriteSyntheticOrigins } from "./rewrite-synthetic-origins.js";
|
|
|
21
21
|
import { celTypeSatisfiesJsonSchema, substituteCelFields, validateAgainstSchema, } from "./schema-compat.js";
|
|
22
22
|
import { collectValueSchemaIssues } from "./validate-value-schema.js";
|
|
23
23
|
import { DiagnosticSeverity } from "./types.js";
|
|
24
|
-
import { extractAccessChains, extractCelRegionScopes, extractContextsFromSchema, getManifestItem, pathMatchesScope, resolveContextAnnotations, } from "./validate-cel-context.js";
|
|
24
|
+
import { extractAccessChains, extractCelRegionScopes, extractContextsFromSchema, getManifestItem, pathMatchesScope, resolveContextAnnotations, resolveTypeFieldToSchema, } from "./validate-cel-context.js";
|
|
25
25
|
import { buildEvalPaths, evalPathsCover } from "./eval-paths.js";
|
|
26
|
+
import { BINDINGS_ANNOTATION, bindingContextProperties, bindingPathChain, CEL_RESERVED_WORDS, findBindingSites, resolveBindingOrder, schemaAtChain, } from "./cel-bindings.js";
|
|
26
27
|
import { validateExtends } from "./validate-extends.js";
|
|
27
28
|
import { validateLogging } from "./validate-logging.js";
|
|
28
29
|
import { validateModuleArtifact } from "./validate-module-artifact.js";
|
|
@@ -307,12 +308,18 @@ function buildStepContextSchema(manifest, defSchema, allManifests, defs, aliases
|
|
|
307
308
|
continue;
|
|
308
309
|
const invokeField = stepCtx.invoke;
|
|
309
310
|
const outputTypeField = stepCtx.outputType;
|
|
311
|
+
// Optional: the field a step uses to produce a result without dispatching.
|
|
312
|
+
// Only a kind that declares one has pure steps at all.
|
|
313
|
+
const valueField = stepCtx.value;
|
|
310
314
|
if (!invokeField || !outputTypeField)
|
|
311
315
|
continue;
|
|
312
316
|
const steps = manifest[fieldName];
|
|
313
317
|
if (!Array.isArray(steps))
|
|
314
318
|
continue;
|
|
315
319
|
const stepItemSchema = resolveLocalRef(fieldSchema.items, defSchema);
|
|
320
|
+
// The instance's own input contract, for typing a pure step that just
|
|
321
|
+
// forwards one of its values.
|
|
322
|
+
const ownInputs = resolveTypeFieldToSchema(manifest.inputType, allManifests);
|
|
316
323
|
const stepProperties = {};
|
|
317
324
|
walkStepArray(steps, stepItemSchema, defSchema, fieldName, (s) => {
|
|
318
325
|
const name = s.name;
|
|
@@ -321,8 +328,29 @@ function buildStepContextSchema(manifest, defSchema, allManifests, defs, aliases
|
|
|
321
328
|
// wrappers (try/if/while/switch/throw) don't produce a result and must
|
|
322
329
|
// not shadow real entries with a permissive `additionalProperties: true`,
|
|
323
330
|
// or unknown step references slip through chain validation.
|
|
324
|
-
if (typeof name !== "string"
|
|
331
|
+
if (typeof name !== "string")
|
|
325
332
|
return;
|
|
333
|
+
if (!invoke || typeof invoke !== "object") {
|
|
334
|
+
// A pure step dispatches nothing, so there is no contract to resolve.
|
|
335
|
+
// Where its expression is a plain chain into something already typed —
|
|
336
|
+
// an earlier step's result, or the kind's own inputs — that type carries
|
|
337
|
+
// through; anything else (arithmetic, a call, a comprehension) stays
|
|
338
|
+
// permissive rather than guessed. Same rule as a named binding's.
|
|
339
|
+
if (valueField && valueField in s) {
|
|
340
|
+
const scopeRoot = {
|
|
341
|
+
properties: {
|
|
342
|
+
steps: { type: "object", properties: { ...stepProperties } },
|
|
343
|
+
...(ownInputs ? { inputs: ownInputs } : {}),
|
|
344
|
+
},
|
|
345
|
+
};
|
|
346
|
+
const chained = schemaAtChain(bindingPathChain(s[valueField]), scopeRoot);
|
|
347
|
+
stepProperties[name] = {
|
|
348
|
+
type: "object",
|
|
349
|
+
properties: { result: chained ?? PERMISSIVE_CONTRACT },
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
326
354
|
const invokedKind = invoke.kind;
|
|
327
355
|
const invokedName = invoke.name;
|
|
328
356
|
// A named `!ref` carries the target's own manifest (which may narrow the
|
|
@@ -618,6 +646,26 @@ function errorContextForPath(path, scopes) {
|
|
|
618
646
|
}
|
|
619
647
|
return best?.schema;
|
|
620
648
|
}
|
|
649
|
+
/** Add a kind's named bindings to a resolved context, when the context declares
|
|
650
|
+
* a bindings region. They go UNDER the context's own properties: a scope
|
|
651
|
+
* variable wins over a same-named binding at runtime, so static typing has to
|
|
652
|
+
* agree (the collision itself is `BINDING_NAME_RESERVED`). */
|
|
653
|
+
function withBindingNames(contextSchema, resource) {
|
|
654
|
+
const field = contextSchema[BINDINGS_ANNOTATION];
|
|
655
|
+
if (typeof field !== "string")
|
|
656
|
+
return contextSchema;
|
|
657
|
+
const bindings = resource[field];
|
|
658
|
+
if (bindings === null || typeof bindings !== "object" || Array.isArray(bindings)) {
|
|
659
|
+
return contextSchema;
|
|
660
|
+
}
|
|
661
|
+
return {
|
|
662
|
+
...contextSchema,
|
|
663
|
+
properties: {
|
|
664
|
+
...bindingContextProperties(bindings, contextSchema),
|
|
665
|
+
...(contextSchema.properties ?? {}),
|
|
666
|
+
},
|
|
667
|
+
};
|
|
668
|
+
}
|
|
621
669
|
/** Member-access chains in a CEL expression, or none when it doesn't parse.
|
|
622
670
|
* Best-effort: a syntax error is reported by the engine pass, not here. */
|
|
623
671
|
function celAccessChains(env, expr) {
|
|
@@ -1414,6 +1462,9 @@ export class StaticAnalyzer {
|
|
|
1414
1462
|
// `x-telo-step-context` / `x-telo-error-context` scopes. A `!cel` outside
|
|
1415
1463
|
// every region is read as a literal — the runtime never evaluates it.
|
|
1416
1464
|
let celEvalPaths = [];
|
|
1465
|
+
// The bindings field this kind declares (if any), read by the CEL sites that
|
|
1466
|
+
// see the names it introduces.
|
|
1467
|
+
let celBindingSites;
|
|
1417
1468
|
// The compile half alone: a field that resolves at startup, where observed
|
|
1418
1469
|
// state cannot exist yet.
|
|
1419
1470
|
let celCompilePaths = [];
|
|
@@ -1444,6 +1495,72 @@ export class StaticAnalyzer {
|
|
|
1444
1495
|
}
|
|
1445
1496
|
}
|
|
1446
1497
|
celErrorScopes = collectErrorContextScopes(e.definition?.schema);
|
|
1498
|
+
celBindingSites = findBindingSites(e.definition?.schema);
|
|
1499
|
+
if (celBindingSites) {
|
|
1500
|
+
const declared = m[celBindingSites.field];
|
|
1501
|
+
const bindingsName = m.metadata?.name;
|
|
1502
|
+
const bindingsFile = m.metadata?.source;
|
|
1503
|
+
const resourceRef = { kind: m.kind, name: bindingsName ?? "" };
|
|
1504
|
+
// Which field holds the bindings would otherwise be decided by
|
|
1505
|
+
// schema walk order, silently.
|
|
1506
|
+
if (celBindingSites.fields.length > 1) {
|
|
1507
|
+
diagnostics.push({
|
|
1508
|
+
severity: DiagnosticSeverity.Error,
|
|
1509
|
+
code: "BINDING_FIELD_AMBIGUOUS",
|
|
1510
|
+
source: SOURCE,
|
|
1511
|
+
message: `${m.kind}/${bindingsName}: the kind's schema points '${BINDINGS_ANNOTATION}' at more than one field (${celBindingSites.fields.join(", ")}). Every annotated context must name the same bindings field.`,
|
|
1512
|
+
data: { resource: resourceRef, filePath: bindingsFile, path: celBindingSites.field },
|
|
1513
|
+
});
|
|
1514
|
+
}
|
|
1515
|
+
if (declared !== null && typeof declared === "object" && !Array.isArray(declared)) {
|
|
1516
|
+
for (const cycle of resolveBindingOrder(declared).cycles) {
|
|
1517
|
+
diagnostics.push({
|
|
1518
|
+
severity: DiagnosticSeverity.Error,
|
|
1519
|
+
code: "BINDING_CYCLE",
|
|
1520
|
+
source: SOURCE,
|
|
1521
|
+
message: `${m.kind}/${bindingsName}: '${celBindingSites.field}' has a cycle — ${cycle.join(" → ")}. A binding is resolved from the ones it references, so it cannot reference itself, directly or through others.`,
|
|
1522
|
+
data: {
|
|
1523
|
+
resource: resourceRef,
|
|
1524
|
+
filePath: bindingsFile,
|
|
1525
|
+
path: `${celBindingSites.field}.${cycle[0]}`,
|
|
1526
|
+
},
|
|
1527
|
+
});
|
|
1528
|
+
}
|
|
1529
|
+
// Every name the CEL environment already binds at this site: the
|
|
1530
|
+
// kernel globals (registered straight onto the environment, not
|
|
1531
|
+
// contributed by any annotation), the scope the annotated contexts
|
|
1532
|
+
// declare, and the two the analyzer merges per site. Shadowing one
|
|
1533
|
+
// would leave the binding silently unreachable there — as would
|
|
1534
|
+
// naming it after a CEL keyword, which never lexes as a reference.
|
|
1535
|
+
const inScope = new Set([
|
|
1536
|
+
...KERNEL_GLOBAL_NAMES,
|
|
1537
|
+
...celBindingSites.scopeNames,
|
|
1538
|
+
]);
|
|
1539
|
+
if (celStepContextSchema)
|
|
1540
|
+
inScope.add("steps");
|
|
1541
|
+
if (celErrorScopes.size > 0)
|
|
1542
|
+
inScope.add("error");
|
|
1543
|
+
const keywords = new Set(CEL_RESERVED_WORDS);
|
|
1544
|
+
for (const name of Object.keys(declared)) {
|
|
1545
|
+
const shadows = inScope.has(name);
|
|
1546
|
+
if (!shadows && !keywords.has(name))
|
|
1547
|
+
continue;
|
|
1548
|
+
diagnostics.push({
|
|
1549
|
+
severity: DiagnosticSeverity.Error,
|
|
1550
|
+
code: "BINDING_NAME_RESERVED",
|
|
1551
|
+
source: SOURCE,
|
|
1552
|
+
message: shadows
|
|
1553
|
+
? `${m.kind}/${bindingsName}: binding '${name}' shadows a variable already in scope here (${[...inScope].sort().join(", ")}). Rename the binding — a scope variable always wins, so this one would never be read.`
|
|
1554
|
+
: `${m.kind}/${bindingsName}: binding '${name}' is a CEL keyword, so no expression can read it as a reference. Rename the binding.`,
|
|
1555
|
+
data: {
|
|
1556
|
+
resource: resourceRef,
|
|
1557
|
+
filePath: bindingsFile,
|
|
1558
|
+
path: `${celBindingSites.field}.${name}`,
|
|
1559
|
+
},
|
|
1560
|
+
});
|
|
1561
|
+
}
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1447
1564
|
// The non-eval-field check only applies to runtime resource instances:
|
|
1448
1565
|
// structural / templating kinds (capability `Telo.Template`, or no
|
|
1449
1566
|
// definition) carry CEL the kernel evaluates by other rules.
|
|
@@ -1565,7 +1682,7 @@ export class StaticAnalyzer {
|
|
|
1565
1682
|
aliases,
|
|
1566
1683
|
allManifests: allManifests,
|
|
1567
1684
|
});
|
|
1568
|
-
effectiveContext = mergeKernelGlobalsIntoContext(resolvedContext, kernelGlobals);
|
|
1685
|
+
effectiveContext = mergeKernelGlobalsIntoContext(withBindingNames(resolvedContext, m), kernelGlobals);
|
|
1569
1686
|
}
|
|
1570
1687
|
else if (observedStateContext) {
|
|
1571
1688
|
// No `x-telo-context` matched, so nothing was chain-validated here
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/** Annotation on an `x-telo-context` node naming the resource field that holds
|
|
2
|
+
* the kind's named CEL bindings. The field is read from the RESOURCE ROOT, not
|
|
3
|
+
* the per-scope manifest item: a bindings map belongs to the resource, while the
|
|
4
|
+
* contexts that see it may be anchored anywhere (a decision table annotates both
|
|
5
|
+
* `choices` and `default`). */
|
|
6
|
+
export declare const BINDINGS_ANNOTATION = "x-telo-bindings-from";
|
|
7
|
+
export interface BindingSites {
|
|
8
|
+
/** Resource field holding the bindings map. */
|
|
9
|
+
field: string;
|
|
10
|
+
/** Every field named by an annotation on this kind. More than one is a
|
|
11
|
+
* kind-authoring mistake: which of them holds the bindings would be decided
|
|
12
|
+
* by schema walk order. */
|
|
13
|
+
fields: string[];
|
|
14
|
+
/** Variable names the annotated contexts declare — a binding may not shadow one. */
|
|
15
|
+
scopeNames: Set<string>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* CEL keywords. A binding named after one is unreachable — `true` lexes as a
|
|
19
|
+
* literal, `in` as an operator — so it is reserved alongside the scope names,
|
|
20
|
+
* which turns silence into a diagnostic.
|
|
21
|
+
*/
|
|
22
|
+
export declare const CEL_RESERVED_WORDS: readonly string[];
|
|
23
|
+
/** Locate a kind's bindings field and the scope names its annotated contexts
|
|
24
|
+
* declare. Returns undefined for a kind that declares no bindings region. */
|
|
25
|
+
export declare function findBindingSites(definitionSchema: Record<string, any> | undefined): BindingSites | undefined;
|
|
26
|
+
/** Each binding's dependencies, restricted to its siblings — an identifier that
|
|
27
|
+
* names something else in scope (`inputs`, `item`) is not an edge. */
|
|
28
|
+
export declare function bindingDependencies(bindings: Record<string, unknown>): Map<string, Set<string>>;
|
|
29
|
+
/** Member-access chain for a binding whose value is one bare dotted identifier
|
|
30
|
+
* expression (`inputs.user.name`). Null for anything else — a literal, a call,
|
|
31
|
+
* a comprehension, a structured value — none of which reduces to a typed path. */
|
|
32
|
+
export declare function bindingPathChain(value: unknown): string[] | null;
|
|
33
|
+
/**
|
|
34
|
+
* The context properties a bindings map contributes: each name typed from its
|
|
35
|
+
* expression where that expression is a chain into an already-typed scope
|
|
36
|
+
* variable, and left open otherwise.
|
|
37
|
+
*
|
|
38
|
+
* Gradual by design — the same stance `x-telo-context-element-from` takes. An
|
|
39
|
+
* open schema costs a missed `CEL_UNKNOWN_FIELD` under that name; inventing a
|
|
40
|
+
* type would cost a false one.
|
|
41
|
+
*/
|
|
42
|
+
export declare function bindingContextProperties(bindings: Record<string, unknown>, contextSchema: Record<string, any>): Record<string, any>;
|
|
43
|
+
/** Walk a member-access chain through a schema's `properties`, returning the
|
|
44
|
+
* terminal node or undefined once the path leaves typed schema. */
|
|
45
|
+
export declare function schemaAtChain(chain: string[] | null, root: Record<string, any>): Record<string, any> | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Evaluation order derived from the reference graph, plus any cycles found.
|
|
48
|
+
*
|
|
49
|
+
* Order is what the editor and diagnostics show; the runtime does not need it,
|
|
50
|
+
* since lazy evaluation reaches a binding's dependencies by construction. A
|
|
51
|
+
* cycle is reported as the path that closes it (`a → b → a`).
|
|
52
|
+
*/
|
|
53
|
+
export declare function resolveBindingOrder(bindings: Record<string, unknown>): {
|
|
54
|
+
order: string[];
|
|
55
|
+
cycles: string[][];
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=cel-bindings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cel-bindings.d.ts","sourceRoot":"","sources":["../src/cel-bindings.ts"],"names":[],"mappings":"AAIA;;;;gCAIgC;AAChC,eAAO,MAAM,mBAAmB,yBAAyB,CAAC;AAE1D,MAAM,WAAW,YAAY;IAC3B,+CAA+C;IAC/C,KAAK,EAAE,MAAM,CAAC;IACd;;gCAE4B;IAC5B,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,oFAAoF;IACpF,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CACzB;AAED;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,EAAE,SAAS,MAAM,EAsB/C,CAAC;AAEF;8EAC8E;AAC9E,wBAAgB,gBAAgB,CAC9B,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,GAChD,YAAY,GAAG,SAAS,CAW1B;AAuDD;uEACuE;AACvE,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAW1B;AAED;;mFAEmF;AACnF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,EAAE,GAAG,IAAI,CAQhE;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACjC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAMrB;AAED;oEACoE;AACpE,wBAAgB,aAAa,CAC3B,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EACtB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACxB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CASjC;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IACtE,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC;CACpB,CAwBA"}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { isCompiledValue } from "@telorun/sdk";
|
|
2
|
+
import { buildCelEnvironment, extractAccessChains } from "@telorun/templating";
|
|
3
|
+
import { extractContextsFromSchema } from "./validate-cel-context.js";
|
|
4
|
+
/** Annotation on an `x-telo-context` node naming the resource field that holds
|
|
5
|
+
* the kind's named CEL bindings. The field is read from the RESOURCE ROOT, not
|
|
6
|
+
* the per-scope manifest item: a bindings map belongs to the resource, while the
|
|
7
|
+
* contexts that see it may be anchored anywhere (a decision table annotates both
|
|
8
|
+
* `choices` and `default`). */
|
|
9
|
+
export const BINDINGS_ANNOTATION = "x-telo-bindings-from";
|
|
10
|
+
/**
|
|
11
|
+
* CEL keywords. A binding named after one is unreachable — `true` lexes as a
|
|
12
|
+
* literal, `in` as an operator — so it is reserved alongside the scope names,
|
|
13
|
+
* which turns silence into a diagnostic.
|
|
14
|
+
*/
|
|
15
|
+
export const CEL_RESERVED_WORDS = [
|
|
16
|
+
"as",
|
|
17
|
+
"break",
|
|
18
|
+
"const",
|
|
19
|
+
"continue",
|
|
20
|
+
"else",
|
|
21
|
+
"false",
|
|
22
|
+
"for",
|
|
23
|
+
"function",
|
|
24
|
+
"if",
|
|
25
|
+
"import",
|
|
26
|
+
"in",
|
|
27
|
+
"let",
|
|
28
|
+
"loop",
|
|
29
|
+
"namespace",
|
|
30
|
+
"null",
|
|
31
|
+
"package",
|
|
32
|
+
"return",
|
|
33
|
+
"true",
|
|
34
|
+
"var",
|
|
35
|
+
"void",
|
|
36
|
+
"while",
|
|
37
|
+
];
|
|
38
|
+
/** Locate a kind's bindings field and the scope names its annotated contexts
|
|
39
|
+
* declare. Returns undefined for a kind that declares no bindings region. */
|
|
40
|
+
export function findBindingSites(definitionSchema) {
|
|
41
|
+
if (!definitionSchema)
|
|
42
|
+
return undefined;
|
|
43
|
+
const fields = [];
|
|
44
|
+
const scopeNames = new Set();
|
|
45
|
+
for (const { schema } of extractContextsFromSchema(definitionSchema)) {
|
|
46
|
+
const declared = schema?.[BINDINGS_ANNOTATION];
|
|
47
|
+
if (typeof declared !== "string" || declared.length === 0)
|
|
48
|
+
continue;
|
|
49
|
+
if (!fields.includes(declared))
|
|
50
|
+
fields.push(declared);
|
|
51
|
+
for (const name of Object.keys(schema.properties ?? {}))
|
|
52
|
+
scopeNames.add(name);
|
|
53
|
+
}
|
|
54
|
+
return fields.length > 0 ? { field: fields[0], fields, scopeNames } : undefined;
|
|
55
|
+
}
|
|
56
|
+
const TEMPLATE_RE = /\$\{\{\s*([^}]+?)\s*\}\}/g;
|
|
57
|
+
const EXACT_TEMPLATE_RE = /^\s*\$\{\{\s*([^}]+?)\s*\}\}\s*$/;
|
|
58
|
+
/** Parser for expressions that reach here uncompiled. Built once; the base
|
|
59
|
+
* environment is stateless and shared with the runtime's own. */
|
|
60
|
+
let parseEnv;
|
|
61
|
+
/**
|
|
62
|
+
* Root identifiers an expression source reads — the first element of every
|
|
63
|
+
* member-access chain, which is what a dependency edge is made of.
|
|
64
|
+
*
|
|
65
|
+
* Parsed, never lexed: `inputs.total` reads `inputs`, not `total`, and a name
|
|
66
|
+
* inside a string literal reads nothing. A token scan would make two bindings
|
|
67
|
+
* named after each other's *fields* look mutually recursive and reject a correct
|
|
68
|
+
* manifest — the worst outcome a static check has. An expression that does not
|
|
69
|
+
* parse contributes no edges; its syntax error is the engine pass's to report.
|
|
70
|
+
*/
|
|
71
|
+
function addRootIdentifiers(source, out) {
|
|
72
|
+
try {
|
|
73
|
+
parseEnv ??= buildCelEnvironment();
|
|
74
|
+
for (const chain of extractAccessChains(parseEnv.parse(source).ast)) {
|
|
75
|
+
if (chain.length > 0)
|
|
76
|
+
out.add(chain[0]);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
// Unparseable — see above.
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/** Root identifiers a binding's value reads. Walks the whole value so a
|
|
84
|
+
* structured binding (a map with `!cel` leaves) is covered, and reads both a
|
|
85
|
+
* compiled expression and a still-raw `${{ }}` string — the editor's
|
|
86
|
+
* round-trip view never compiles. An untagged plain string is a literal, not
|
|
87
|
+
* an expression, and contributes nothing. */
|
|
88
|
+
function collectRefs(value, out) {
|
|
89
|
+
if (isCompiledValue(value)) {
|
|
90
|
+
const refs = value.refs;
|
|
91
|
+
if (refs)
|
|
92
|
+
for (const ref of refs)
|
|
93
|
+
out.add(ref);
|
|
94
|
+
else
|
|
95
|
+
addRootIdentifiers(value.source ?? "", out);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (typeof value === "string") {
|
|
99
|
+
for (const match of value.matchAll(TEMPLATE_RE))
|
|
100
|
+
addRootIdentifiers(match[1], out);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (Array.isArray(value)) {
|
|
104
|
+
for (const entry of value)
|
|
105
|
+
collectRefs(entry, out);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (value !== null && typeof value === "object") {
|
|
109
|
+
for (const entry of Object.values(value))
|
|
110
|
+
collectRefs(entry, out);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/** Each binding's dependencies, restricted to its siblings — an identifier that
|
|
114
|
+
* names something else in scope (`inputs`, `item`) is not an edge. */
|
|
115
|
+
export function bindingDependencies(bindings) {
|
|
116
|
+
const names = new Set(Object.keys(bindings));
|
|
117
|
+
const deps = new Map();
|
|
118
|
+
for (const [name, value] of Object.entries(bindings)) {
|
|
119
|
+
const refs = new Set();
|
|
120
|
+
collectRefs(value, refs);
|
|
121
|
+
const own = new Set();
|
|
122
|
+
for (const ref of refs)
|
|
123
|
+
if (names.has(ref))
|
|
124
|
+
own.add(ref);
|
|
125
|
+
deps.set(name, own);
|
|
126
|
+
}
|
|
127
|
+
return deps;
|
|
128
|
+
}
|
|
129
|
+
/** Member-access chain for a binding whose value is one bare dotted identifier
|
|
130
|
+
* expression (`inputs.user.name`). Null for anything else — a literal, a call,
|
|
131
|
+
* a comprehension, a structured value — none of which reduces to a typed path. */
|
|
132
|
+
export function bindingPathChain(value) {
|
|
133
|
+
let source;
|
|
134
|
+
if (isCompiledValue(value))
|
|
135
|
+
source = value.source;
|
|
136
|
+
else if (typeof value === "string")
|
|
137
|
+
source = value.match(EXACT_TEMPLATE_RE)?.[1];
|
|
138
|
+
if (source === undefined)
|
|
139
|
+
return null;
|
|
140
|
+
const expr = source.trim();
|
|
141
|
+
if (!/^[A-Za-z_]\w*(\.[A-Za-z_]\w*)*$/.test(expr))
|
|
142
|
+
return null;
|
|
143
|
+
return expr.split(".");
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* The context properties a bindings map contributes: each name typed from its
|
|
147
|
+
* expression where that expression is a chain into an already-typed scope
|
|
148
|
+
* variable, and left open otherwise.
|
|
149
|
+
*
|
|
150
|
+
* Gradual by design — the same stance `x-telo-context-element-from` takes. An
|
|
151
|
+
* open schema costs a missed `CEL_UNKNOWN_FIELD` under that name; inventing a
|
|
152
|
+
* type would cost a false one.
|
|
153
|
+
*/
|
|
154
|
+
export function bindingContextProperties(bindings, contextSchema) {
|
|
155
|
+
const props = {};
|
|
156
|
+
for (const [name, value] of Object.entries(bindings)) {
|
|
157
|
+
props[name] = schemaAtChain(bindingPathChain(value), contextSchema) ?? {};
|
|
158
|
+
}
|
|
159
|
+
return props;
|
|
160
|
+
}
|
|
161
|
+
/** Walk a member-access chain through a schema's `properties`, returning the
|
|
162
|
+
* terminal node or undefined once the path leaves typed schema. */
|
|
163
|
+
export function schemaAtChain(chain, root) {
|
|
164
|
+
if (!chain)
|
|
165
|
+
return undefined;
|
|
166
|
+
let current = root;
|
|
167
|
+
for (const key of chain) {
|
|
168
|
+
const props = current?.properties;
|
|
169
|
+
if (!props || !(key in props))
|
|
170
|
+
return undefined;
|
|
171
|
+
current = props[key];
|
|
172
|
+
}
|
|
173
|
+
return current && typeof current === "object" ? current : undefined;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Evaluation order derived from the reference graph, plus any cycles found.
|
|
177
|
+
*
|
|
178
|
+
* Order is what the editor and diagnostics show; the runtime does not need it,
|
|
179
|
+
* since lazy evaluation reaches a binding's dependencies by construction. A
|
|
180
|
+
* cycle is reported as the path that closes it (`a → b → a`).
|
|
181
|
+
*/
|
|
182
|
+
export function resolveBindingOrder(bindings) {
|
|
183
|
+
const deps = bindingDependencies(bindings);
|
|
184
|
+
const order = [];
|
|
185
|
+
const cycles = [];
|
|
186
|
+
const state = new Map();
|
|
187
|
+
const path = [];
|
|
188
|
+
const visit = (name) => {
|
|
189
|
+
const seen = state.get(name);
|
|
190
|
+
if (seen === "done")
|
|
191
|
+
return;
|
|
192
|
+
if (seen === "visiting") {
|
|
193
|
+
cycles.push([...path.slice(path.indexOf(name)), name]);
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
state.set(name, "visiting");
|
|
197
|
+
path.push(name);
|
|
198
|
+
for (const dep of deps.get(name) ?? [])
|
|
199
|
+
visit(dep);
|
|
200
|
+
path.pop();
|
|
201
|
+
state.set(name, "done");
|
|
202
|
+
order.push(name);
|
|
203
|
+
};
|
|
204
|
+
for (const name of Object.keys(bindings))
|
|
205
|
+
visit(name);
|
|
206
|
+
return { order, cycles };
|
|
207
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ export { importResolutionDiagnostics } from "./import-resolution-diagnostics.js"
|
|
|
5
5
|
export type { GraphLoadError, ImportEdge, LoadedFile, LoadedGraph, LoadedModule, ParseError, } from "./loaded-types.js";
|
|
6
6
|
export { flattenForAnalyzer, flattenLoadedModule, forwardReExportManifests, parseExportEntry, reExportSpecsFromExports, resolveExportedKinds, selectModuleManifestsForAnalysis, stampExportedKinds, stampReExportedKinds, type ParsedExportEntry, type ReExportSpec, } from "./flatten-for-analyzer.js";
|
|
7
7
|
export { buildEvalPaths, evalPathCovers } from "./eval-paths.js";
|
|
8
|
+
export { BINDINGS_ANNOTATION, bindingContextProperties, bindingDependencies, findBindingSites, resolveBindingOrder, } from "./cel-bindings.js";
|
|
9
|
+
export type { BindingSites } from "./cel-bindings.js";
|
|
8
10
|
export { applyObservedStateNode, buildObservedStateIndex, buildObservedStateResourcesSchema, collectRunReachableNames, observedStateRead, validateObservedStateDeclarations, OBSERVED_STATE_SCHEMA, } from "./validate-observed-state.js";
|
|
9
11
|
export type { AnalyzedResource, ObservedStateRead } from "./validate-observed-state.js";
|
|
10
12
|
export { moduleScopedDefResolver, scopeResolverForModule } from "./alias-resolver.js";
|
|
@@ -36,7 +38,7 @@ export type { DocumentPosition } from "./position-metadata.js";
|
|
|
36
38
|
export { HttpSource } from "./sources/http-source.js";
|
|
37
39
|
export { RegistrySource } from "./sources/registry-source.js";
|
|
38
40
|
export { defaultSources } from "./sources/default-sources.js";
|
|
39
|
-
export { splitIntegrity, foldIntegrity, verifyIntegrity, verifiedFetch, sha256Base64Url, IntegrityError, } from "./sources/integrity.js";
|
|
41
|
+
export { splitIntegrity, foldIntegrity, isCanonicalIntegrity, verifyIntegrity, verifiedFetch, sha256Base64Url, IntegrityError, } from "./sources/integrity.js";
|
|
40
42
|
export { parseModuleRef, isRegistryRef } from "./sources/module-ref.js";
|
|
41
43
|
export type { ParsedModuleRef } from "./sources/module-ref.js";
|
|
42
44
|
export { OCI_SCHEME, isOciRef, parseOciRef } from "./sources/oci-ref.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,YAAY,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,2BAA2B,EAAE,MAAM,oCAAoC,CAAC;AACjF,YAAY,EACR,cAAc,EACd,UAAU,EACV,UAAU,EACV,WAAW,EACX,YAAY,EACZ,UAAU,GACb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACH,kBAAkB,EAClB,mBAAmB,EACnB,wBAAwB,EACxB,gBAAgB,EAChB,wBAAwB,EACxB,oBAAoB,EACpB,gCAAgC,EAChC,kBAAkB,EAClB,oBAAoB,EACpB,KAAK,iBAAiB,EACtB,KAAK,YAAY,GACpB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjE,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACvB,iCAAiC,EACjC,wBAAwB,EACxB,iBAAiB,EACjB,iCAAiC,EACjC,qBAAqB,GACtB,MAAM,8BAA8B,CAAC;AACtC,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACxF,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AACtF,YAAY,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,yBAAyB,EACzB,qBAAqB,EACrB,sBAAsB,EACtB,qBAAq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,EAAE,MAAM,6BAA6B,CAAC;AACvE,OAAO,EACL,WAAW,EACX,aAAa,EACb,qBAAqB,EACrB,gBAAgB,EAChB,WAAW,EACX,iBAAiB,EACjB,sBAAsB,EACtB,WAAW,EACX,eAAe,GAChB,MAAM,wBAAwB,CAAC;AAChC,YAAY,EACV,gBAAgB,EAChB,SAAS,EACT,YAAY,EACZ,cAAc,GACf,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,eAAe,EACf,cAAc,GACf,MAAM,2BAA2B,CAAC;AACnC,YAAY,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC1D,YAAY,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAC9F,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC3E,YAAY,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAC3E,YAAY,EACR,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,WAAW,EACX,cAAc,EACd,QAAQ,EACR,aAAa,EACb,KAAK,EACR,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export { StaticAnalyzer } from "./analyzer.js";
|
|
|
3
3
|
export { importResolutionDiagnostics } from "./import-resolution-diagnostics.js";
|
|
4
4
|
export { flattenForAnalyzer, flattenLoadedModule, forwardReExportManifests, parseExportEntry, reExportSpecsFromExports, resolveExportedKinds, selectModuleManifestsForAnalysis, stampExportedKinds, stampReExportedKinds, } from "./flatten-for-analyzer.js";
|
|
5
5
|
export { buildEvalPaths, evalPathCovers } from "./eval-paths.js";
|
|
6
|
+
export { BINDINGS_ANNOTATION, bindingContextProperties, bindingDependencies, findBindingSites, resolveBindingOrder, } from "./cel-bindings.js";
|
|
6
7
|
export { applyObservedStateNode, buildObservedStateIndex, buildObservedStateResourcesSchema, collectRunReachableNames, observedStateRead, validateObservedStateDeclarations, OBSERVED_STATE_SCHEMA, } from "./validate-observed-state.js";
|
|
7
8
|
export { moduleScopedDefResolver, scopeResolverForModule } from "./alias-resolver.js";
|
|
8
9
|
export { ancestorChain, contractDeclarer, controllerBearingAncestor, effectiveAuthorSchema, effectiveContractField, effectiveStatusSchema, hasOwnControllerOrTemplate, inheritedCapability, isInheritedDelegation, mappingFieldFor, needsContractMapping, resolveParent, } from "./extends-resolution.js";
|
|
@@ -21,7 +22,7 @@ export { buildDocumentPositions, buildLineOffsets, buildPositionIndex, documentL
|
|
|
21
22
|
export { HttpSource } from "./sources/http-source.js";
|
|
22
23
|
export { RegistrySource } from "./sources/registry-source.js";
|
|
23
24
|
export { defaultSources } from "./sources/default-sources.js";
|
|
24
|
-
export { splitIntegrity, foldIntegrity, verifyIntegrity, verifiedFetch, sha256Base64Url, IntegrityError, } from "./sources/integrity.js";
|
|
25
|
+
export { splitIntegrity, foldIntegrity, isCanonicalIntegrity, verifyIntegrity, verifiedFetch, sha256Base64Url, IntegrityError, } from "./sources/integrity.js";
|
|
25
26
|
export { parseModuleRef, isRegistryRef } from "./sources/module-ref.js";
|
|
26
27
|
export { OCI_SCHEME, isOciRef, parseOciRef } from "./sources/oci-ref.js";
|
|
27
28
|
export { parseVersionedRef, withRefVersion } from "./sources/versioned-ref.js";
|
|
@@ -24,6 +24,16 @@ export declare function splitIntegrity(ref: string): {
|
|
|
24
24
|
* author-authored pin is never overwritten). Inverse of `splitIntegrity`;
|
|
25
25
|
* used to fold the object form's `integrity:` sibling into the source string. */
|
|
26
26
|
export declare function foldIntegrity(source: string, integrity: unknown): string;
|
|
27
|
+
/** True for a value safe to WRITE into a manifest as an integrity pin.
|
|
28
|
+
*
|
|
29
|
+
* A pin arriving from outside the file — the hub's version index, a registry
|
|
30
|
+
* response — is untrusted text before it is untrusted *content*: a value
|
|
31
|
+
* carrying a quote, a `#`, or a newline corrupts the YAML it is spliced into,
|
|
32
|
+
* which no later install-time verification can catch because the manifest no
|
|
33
|
+
* longer parses. A wrong-but-well-formed hash is the case install *does*
|
|
34
|
+
* catch; this is the case it cannot. Callers writing a pin they did not
|
|
35
|
+
* compute check here first and fall back to writing none. */
|
|
36
|
+
export declare function isCanonicalIntegrity(value: unknown): value is string;
|
|
27
37
|
/** SHA-256 of `bytes` as unpadded base64url — the canonical inline-hash form. */
|
|
28
38
|
export declare function sha256Base64Url(bytes: Uint8Array): Promise<string>;
|
|
29
39
|
/** Hash `bytes` and compare against `integrity` (`<alg>-<digest>`). Throws a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"integrity.d.ts","sourceRoot":"","sources":["../../src/sources/integrity.ts"],"names":[],"mappings":"AAAA;;;;;;6EAM6E;
|
|
1
|
+
{"version":3,"file":"integrity.d.ts","sourceRoot":"","sources":["../../src/sources/integrity.ts"],"names":[],"mappings":"AAAA;;;;;;6EAM6E;AAc7E;;;qDAGqD;AACrD,qBAAa,cAAe,SAAQ,KAAK;gBAC3B,OAAO,EAAE,MAAM;CAI5B;AAED;;2EAE2E;AAC3E,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,CAIhF;AAED;;;kFAGkF;AAClF,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,GAAG,MAAM,CAIxE;AAED;;;;;;;;8DAQ8D;AAC9D,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAEpE;AAcD,iFAAiF;AACjF,wBAAsB,eAAe,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAOxE;AAED;;gFAEgF;AAChF,wBAAsB,eAAe,CACnC,KAAK,EAAE,UAAU,EACjB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC,CAkBf;AAED;;;;sCAIsC;AACtC,wBAAsB,aAAa,CACjC,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC;IAAE,KAAK,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAU9C"}
|
|
@@ -9,6 +9,12 @@
|
|
|
9
9
|
* fragments (rare in module refs) pass through untouched. `sha256` is the
|
|
10
10
|
* only algorithm accepted today; the prefix leaves room to migrate. */
|
|
11
11
|
const INTEGRITY_FRAGMENT = /#(sha256-[A-Za-z0-9_+/=-]+)$/;
|
|
12
|
+
/** The canonical written form: SHA-256 as unpadded base64url, exactly what
|
|
13
|
+
* {@link sha256Base64Url} emits and what the `layers[].integrity` schema
|
|
14
|
+
* accepts. Stricter than {@link INTEGRITY_FRAGMENT}, which also tolerates the
|
|
15
|
+
* padded / standard-base64 spellings {@link verifyIntegrity} normalizes on the
|
|
16
|
+
* way in — reading is forgiving, writing is not. */
|
|
17
|
+
const CANONICAL_INTEGRITY = /^sha256-[A-Za-z0-9_-]{43}$/;
|
|
12
18
|
/** A failed integrity/tamper check — always terminal, never best-effort. A
|
|
13
19
|
* distinct type so a caller doing best-effort network handling (e.g. the
|
|
14
20
|
* bundle extractor warning-and-skipping on a fetch blip) can still let a
|
|
@@ -37,6 +43,18 @@ export function foldIntegrity(source, integrity) {
|
|
|
37
43
|
? `${source}#${integrity}`
|
|
38
44
|
: source;
|
|
39
45
|
}
|
|
46
|
+
/** True for a value safe to WRITE into a manifest as an integrity pin.
|
|
47
|
+
*
|
|
48
|
+
* A pin arriving from outside the file — the hub's version index, a registry
|
|
49
|
+
* response — is untrusted text before it is untrusted *content*: a value
|
|
50
|
+
* carrying a quote, a `#`, or a newline corrupts the YAML it is spliced into,
|
|
51
|
+
* which no later install-time verification can catch because the manifest no
|
|
52
|
+
* longer parses. A wrong-but-well-formed hash is the case install *does*
|
|
53
|
+
* catch; this is the case it cannot. Callers writing a pin they did not
|
|
54
|
+
* compute check here first and fall back to writing none. */
|
|
55
|
+
export function isCanonicalIntegrity(value) {
|
|
56
|
+
return typeof value === "string" && CANONICAL_INTEGRITY.test(value);
|
|
57
|
+
}
|
|
40
58
|
function toBase64Url(bytes) {
|
|
41
59
|
let binary = "";
|
|
42
60
|
for (let i = 0; i < bytes.length; i++)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-cel-context.d.ts","sourceRoot":"","sources":["../src/validate-cel-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AAItF,MAAM,WAAW,kBAAkB;IACjC;mEAC+D;IAC/D,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACnC;;kDAE8C;IAC9C,IAAI,CAAC,EAAE;QACL,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CAAC;KACxD,CAAC;IACF,OAAO,CAAC,EAAE;QACR,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;KAC/C,CAAC;IACF,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC;CACtC;AA4CD,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,OAAO,EACd,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,EACnC,Q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> 0) {
|
|
285
285
|
if (fromRoot) {
|
|
286
|
-
const
|
|
287
|
-
if (
|
|
288
|
-
|
|
286
|
+
const navigated = navigatePath(manifestRoot, fromRoot.split("/"));
|
|
287
|
+
if (navigated && typeof navigated === "object" && !Array.isArray(navigated)) {
|
|
288
|
+
// A `telo#Type` slot resolves to the schema it names — the inline
|
|
289
|
+
// `{ kind, schema }` wrapper, a `!ref` to a named type, or a bare name —
|
|
290
|
+
// so the variable is typed by the CONTRACT rather than by the wrapper
|
|
291
|
+
// around it. A raw JSON Schema resolves to itself, and a plain property
|
|
292
|
+
// map (a transport scope) resolves to nothing and is used verbatim.
|
|
293
|
+
return resolveTypeFieldToSchema(navigated, allManifests ?? []) ?? navigated;
|
|
289
294
|
}
|
|
290
295
|
}
|
|
291
296
|
if (defs) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telorun/analyzer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.52.0",
|
|
4
4
|
"description": "Telo Analyzer - Static manifest validator for Telo manifests.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"telo",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"@types/node": "^20.0.0",
|
|
49
49
|
"typescript": "^5.0.0",
|
|
50
50
|
"vitest": "^2.1.8",
|
|
51
|
-
"@telorun/sdk": "0.
|
|
51
|
+
"@telorun/sdk": "0.65.0"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"@telorun/sdk": "*"
|
package/src/analyzer.ts
CHANGED
|
@@ -23,7 +23,11 @@ import {
|
|
|
23
23
|
resolveContract,
|
|
24
24
|
} from "./invocation-contract.js";
|
|
25
25
|
import { buildDependencyGraph, formatCycle } from "./dependency-graph.js";
|
|
26
|
-
import {
|
|
26
|
+
import {
|
|
27
|
+
buildKernelGlobalsSchema,
|
|
28
|
+
KERNEL_GLOBAL_NAMES,
|
|
29
|
+
mergeKernelGlobalsIntoContext,
|
|
30
|
+
} from "./kernel-globals.js";
|
|
27
31
|
import {
|
|
28
32
|
buildObservedStateIndex,
|
|
29
33
|
buildObservedStateResourcesSchema,
|
|
@@ -59,6 +63,16 @@ import {
|
|
|
59
63
|
resolveTypeFieldToSchema,
|
|
60
64
|
} from "./validate-cel-context.js";
|
|
61
65
|
import { buildEvalPaths, evalPathsCover } from "./eval-paths.js";
|
|
66
|
+
import {
|
|
67
|
+
BINDINGS_ANNOTATION,
|
|
68
|
+
bindingContextProperties,
|
|
69
|
+
bindingPathChain,
|
|
70
|
+
CEL_RESERVED_WORDS,
|
|
71
|
+
findBindingSites,
|
|
72
|
+
resolveBindingOrder,
|
|
73
|
+
schemaAtChain,
|
|
74
|
+
type BindingSites,
|
|
75
|
+
} from "./cel-bindings.js";
|
|
62
76
|
import { validateExtends } from "./validate-extends.js";
|
|
63
77
|
import { validateLogging } from "./validate-logging.js";
|
|
64
78
|
import { validateModuleArtifact } from "./validate-module-artifact.js";
|
|
@@ -416,6 +430,9 @@ function buildStepContextSchema(
|
|
|
416
430
|
|
|
417
431
|
const invokeField = stepCtx.invoke;
|
|
418
432
|
const outputTypeField = stepCtx.outputType;
|
|
433
|
+
// Optional: the field a step uses to produce a result without dispatching.
|
|
434
|
+
// Only a kind that declares one has pure steps at all.
|
|
435
|
+
const valueField = stepCtx.value;
|
|
419
436
|
if (!invokeField || !outputTypeField) continue;
|
|
420
437
|
|
|
421
438
|
const steps = manifest[fieldName];
|
|
@@ -426,6 +443,13 @@ function buildStepContextSchema(
|
|
|
426
443
|
defSchema,
|
|
427
444
|
);
|
|
428
445
|
|
|
446
|
+
// The instance's own input contract, for typing a pure step that just
|
|
447
|
+
// forwards one of its values.
|
|
448
|
+
const ownInputs = resolveTypeFieldToSchema(
|
|
449
|
+
(manifest as Record<string, any>).inputType,
|
|
450
|
+
allManifests,
|
|
451
|
+
);
|
|
452
|
+
|
|
429
453
|
const stepProperties: Record<string, any> = {};
|
|
430
454
|
|
|
431
455
|
walkStepArray(steps, stepItemSchema, defSchema, fieldName, (s) => {
|
|
@@ -435,7 +459,28 @@ function buildStepContextSchema(
|
|
|
435
459
|
// wrappers (try/if/while/switch/throw) don't produce a result and must
|
|
436
460
|
// not shadow real entries with a permissive `additionalProperties: true`,
|
|
437
461
|
// or unknown step references slip through chain validation.
|
|
438
|
-
if (typeof name !== "string"
|
|
462
|
+
if (typeof name !== "string") return;
|
|
463
|
+
if (!invoke || typeof invoke !== "object") {
|
|
464
|
+
// A pure step dispatches nothing, so there is no contract to resolve.
|
|
465
|
+
// Where its expression is a plain chain into something already typed —
|
|
466
|
+
// an earlier step's result, or the kind's own inputs — that type carries
|
|
467
|
+
// through; anything else (arithmetic, a call, a comprehension) stays
|
|
468
|
+
// permissive rather than guessed. Same rule as a named binding's.
|
|
469
|
+
if (valueField && valueField in s) {
|
|
470
|
+
const scopeRoot = {
|
|
471
|
+
properties: {
|
|
472
|
+
steps: { type: "object", properties: { ...stepProperties } },
|
|
473
|
+
...(ownInputs ? { inputs: ownInputs } : {}),
|
|
474
|
+
},
|
|
475
|
+
};
|
|
476
|
+
const chained = schemaAtChain(bindingPathChain(s[valueField]), scopeRoot);
|
|
477
|
+
stepProperties[name] = {
|
|
478
|
+
type: "object",
|
|
479
|
+
properties: { result: chained ?? PERMISSIVE_CONTRACT },
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
439
484
|
const invokedKind = invoke.kind as string | undefined;
|
|
440
485
|
const invokedName = invoke.name as string | undefined;
|
|
441
486
|
// A named `!ref` carries the target's own manifest (which may narrow the
|
|
@@ -765,6 +810,29 @@ function errorContextForPath(
|
|
|
765
810
|
return best?.schema;
|
|
766
811
|
}
|
|
767
812
|
|
|
813
|
+
/** Add a kind's named bindings to a resolved context, when the context declares
|
|
814
|
+
* a bindings region. They go UNDER the context's own properties: a scope
|
|
815
|
+
* variable wins over a same-named binding at runtime, so static typing has to
|
|
816
|
+
* agree (the collision itself is `BINDING_NAME_RESERVED`). */
|
|
817
|
+
function withBindingNames(
|
|
818
|
+
contextSchema: Record<string, any>,
|
|
819
|
+
resource: Record<string, any>,
|
|
820
|
+
): Record<string, any> {
|
|
821
|
+
const field = contextSchema[BINDINGS_ANNOTATION];
|
|
822
|
+
if (typeof field !== "string") return contextSchema;
|
|
823
|
+
const bindings = resource[field];
|
|
824
|
+
if (bindings === null || typeof bindings !== "object" || Array.isArray(bindings)) {
|
|
825
|
+
return contextSchema;
|
|
826
|
+
}
|
|
827
|
+
return {
|
|
828
|
+
...contextSchema,
|
|
829
|
+
properties: {
|
|
830
|
+
...bindingContextProperties(bindings as Record<string, unknown>, contextSchema),
|
|
831
|
+
...(contextSchema.properties ?? {}),
|
|
832
|
+
},
|
|
833
|
+
};
|
|
834
|
+
}
|
|
835
|
+
|
|
768
836
|
/** Member-access chains in a CEL expression, or none when it doesn't parse.
|
|
769
837
|
* Best-effort: a syntax error is reported by the engine pass, not here. */
|
|
770
838
|
function celAccessChains(env: Environment, expr: string): string[][] {
|
|
@@ -1695,6 +1763,9 @@ export class StaticAnalyzer {
|
|
|
1695
1763
|
// `x-telo-step-context` / `x-telo-error-context` scopes. A `!cel` outside
|
|
1696
1764
|
// every region is read as a literal — the runtime never evaluates it.
|
|
1697
1765
|
let celEvalPaths: string[] = [];
|
|
1766
|
+
// The bindings field this kind declares (if any), read by the CEL sites that
|
|
1767
|
+
// see the names it introduces.
|
|
1768
|
+
let celBindingSites: BindingSites | undefined;
|
|
1698
1769
|
// The compile half alone: a field that resolves at startup, where observed
|
|
1699
1770
|
// state cannot exist yet.
|
|
1700
1771
|
let celCompilePaths: string[] = [];
|
|
@@ -1748,6 +1819,75 @@ export class StaticAnalyzer {
|
|
|
1748
1819
|
e.definition?.schema as Record<string, any> | undefined,
|
|
1749
1820
|
);
|
|
1750
1821
|
|
|
1822
|
+
celBindingSites = findBindingSites(e.definition?.schema as Record<string, any>);
|
|
1823
|
+
if (celBindingSites) {
|
|
1824
|
+
const declared = (m as Record<string, any>)[celBindingSites.field];
|
|
1825
|
+
const bindingsName = (m.metadata as any)?.name as string | undefined;
|
|
1826
|
+
const bindingsFile = (m.metadata as { source?: string } | undefined)?.source;
|
|
1827
|
+
const resourceRef = { kind: m.kind, name: bindingsName ?? "" };
|
|
1828
|
+
|
|
1829
|
+
// Which field holds the bindings would otherwise be decided by
|
|
1830
|
+
// schema walk order, silently.
|
|
1831
|
+
if (celBindingSites.fields.length > 1) {
|
|
1832
|
+
diagnostics.push({
|
|
1833
|
+
severity: DiagnosticSeverity.Error,
|
|
1834
|
+
code: "BINDING_FIELD_AMBIGUOUS",
|
|
1835
|
+
source: SOURCE,
|
|
1836
|
+
message: `${m.kind}/${bindingsName}: the kind's schema points '${BINDINGS_ANNOTATION}' at more than one field (${celBindingSites.fields.join(", ")}). Every annotated context must name the same bindings field.`,
|
|
1837
|
+
data: { resource: resourceRef, filePath: bindingsFile, path: celBindingSites.field },
|
|
1838
|
+
});
|
|
1839
|
+
}
|
|
1840
|
+
|
|
1841
|
+
if (declared !== null && typeof declared === "object" && !Array.isArray(declared)) {
|
|
1842
|
+
|
|
1843
|
+
for (const cycle of resolveBindingOrder(declared).cycles) {
|
|
1844
|
+
diagnostics.push({
|
|
1845
|
+
severity: DiagnosticSeverity.Error,
|
|
1846
|
+
code: "BINDING_CYCLE",
|
|
1847
|
+
source: SOURCE,
|
|
1848
|
+
message: `${m.kind}/${bindingsName}: '${celBindingSites.field}' has a cycle — ${cycle.join(" → ")}. A binding is resolved from the ones it references, so it cannot reference itself, directly or through others.`,
|
|
1849
|
+
data: {
|
|
1850
|
+
resource: resourceRef,
|
|
1851
|
+
filePath: bindingsFile,
|
|
1852
|
+
path: `${celBindingSites.field}.${cycle[0]}`,
|
|
1853
|
+
},
|
|
1854
|
+
});
|
|
1855
|
+
}
|
|
1856
|
+
|
|
1857
|
+
// Every name the CEL environment already binds at this site: the
|
|
1858
|
+
// kernel globals (registered straight onto the environment, not
|
|
1859
|
+
// contributed by any annotation), the scope the annotated contexts
|
|
1860
|
+
// declare, and the two the analyzer merges per site. Shadowing one
|
|
1861
|
+
// would leave the binding silently unreachable there — as would
|
|
1862
|
+
// naming it after a CEL keyword, which never lexes as a reference.
|
|
1863
|
+
const inScope = new Set<string>([
|
|
1864
|
+
...KERNEL_GLOBAL_NAMES,
|
|
1865
|
+
...celBindingSites.scopeNames,
|
|
1866
|
+
]);
|
|
1867
|
+
if (celStepContextSchema) inScope.add("steps");
|
|
1868
|
+
if (celErrorScopes.size > 0) inScope.add("error");
|
|
1869
|
+
const keywords = new Set<string>(CEL_RESERVED_WORDS);
|
|
1870
|
+
|
|
1871
|
+
for (const name of Object.keys(declared)) {
|
|
1872
|
+
const shadows = inScope.has(name);
|
|
1873
|
+
if (!shadows && !keywords.has(name)) continue;
|
|
1874
|
+
diagnostics.push({
|
|
1875
|
+
severity: DiagnosticSeverity.Error,
|
|
1876
|
+
code: "BINDING_NAME_RESERVED",
|
|
1877
|
+
source: SOURCE,
|
|
1878
|
+
message: shadows
|
|
1879
|
+
? `${m.kind}/${bindingsName}: binding '${name}' shadows a variable already in scope here (${[...inScope].sort().join(", ")}). Rename the binding — a scope variable always wins, so this one would never be read.`
|
|
1880
|
+
: `${m.kind}/${bindingsName}: binding '${name}' is a CEL keyword, so no expression can read it as a reference. Rename the binding.`,
|
|
1881
|
+
data: {
|
|
1882
|
+
resource: resourceRef,
|
|
1883
|
+
filePath: bindingsFile,
|
|
1884
|
+
path: `${celBindingSites.field}.${name}`,
|
|
1885
|
+
},
|
|
1886
|
+
});
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
|
|
1751
1891
|
// The non-eval-field check only applies to runtime resource instances:
|
|
1752
1892
|
// structural / templating kinds (capability `Telo.Template`, or no
|
|
1753
1893
|
// definition) carry CEL the kernel evaluates by other rules.
|
|
@@ -1889,7 +2029,10 @@ export class StaticAnalyzer {
|
|
|
1889
2029
|
aliases,
|
|
1890
2030
|
allManifests: allManifests as Record<string, any>[],
|
|
1891
2031
|
});
|
|
1892
|
-
effectiveContext = mergeKernelGlobalsIntoContext(
|
|
2032
|
+
effectiveContext = mergeKernelGlobalsIntoContext(
|
|
2033
|
+
withBindingNames(resolvedContext, m as Record<string, any>),
|
|
2034
|
+
kernelGlobals,
|
|
2035
|
+
);
|
|
1893
2036
|
} else if (observedStateContext) {
|
|
1894
2037
|
// No `x-telo-context` matched, so nothing was chain-validated here
|
|
1895
2038
|
// before. Validate the observed-state segment alone rather than
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { isCompiledValue } from "@telorun/sdk";
|
|
2
|
+
import { buildCelEnvironment, extractAccessChains } from "@telorun/templating";
|
|
3
|
+
import { extractContextsFromSchema } from "./validate-cel-context.js";
|
|
4
|
+
|
|
5
|
+
/** Annotation on an `x-telo-context` node naming the resource field that holds
|
|
6
|
+
* the kind's named CEL bindings. The field is read from the RESOURCE ROOT, not
|
|
7
|
+
* the per-scope manifest item: a bindings map belongs to the resource, while the
|
|
8
|
+
* contexts that see it may be anchored anywhere (a decision table annotates both
|
|
9
|
+
* `choices` and `default`). */
|
|
10
|
+
export const BINDINGS_ANNOTATION = "x-telo-bindings-from";
|
|
11
|
+
|
|
12
|
+
export interface BindingSites {
|
|
13
|
+
/** Resource field holding the bindings map. */
|
|
14
|
+
field: string;
|
|
15
|
+
/** Every field named by an annotation on this kind. More than one is a
|
|
16
|
+
* kind-authoring mistake: which of them holds the bindings would be decided
|
|
17
|
+
* by schema walk order. */
|
|
18
|
+
fields: string[];
|
|
19
|
+
/** Variable names the annotated contexts declare — a binding may not shadow one. */
|
|
20
|
+
scopeNames: Set<string>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* CEL keywords. A binding named after one is unreachable — `true` lexes as a
|
|
25
|
+
* literal, `in` as an operator — so it is reserved alongside the scope names,
|
|
26
|
+
* which turns silence into a diagnostic.
|
|
27
|
+
*/
|
|
28
|
+
export const CEL_RESERVED_WORDS: readonly string[] = [
|
|
29
|
+
"as",
|
|
30
|
+
"break",
|
|
31
|
+
"const",
|
|
32
|
+
"continue",
|
|
33
|
+
"else",
|
|
34
|
+
"false",
|
|
35
|
+
"for",
|
|
36
|
+
"function",
|
|
37
|
+
"if",
|
|
38
|
+
"import",
|
|
39
|
+
"in",
|
|
40
|
+
"let",
|
|
41
|
+
"loop",
|
|
42
|
+
"namespace",
|
|
43
|
+
"null",
|
|
44
|
+
"package",
|
|
45
|
+
"return",
|
|
46
|
+
"true",
|
|
47
|
+
"var",
|
|
48
|
+
"void",
|
|
49
|
+
"while",
|
|
50
|
+
];
|
|
51
|
+
|
|
52
|
+
/** Locate a kind's bindings field and the scope names its annotated contexts
|
|
53
|
+
* declare. Returns undefined for a kind that declares no bindings region. */
|
|
54
|
+
export function findBindingSites(
|
|
55
|
+
definitionSchema: Record<string, any> | undefined,
|
|
56
|
+
): BindingSites | undefined {
|
|
57
|
+
if (!definitionSchema) return undefined;
|
|
58
|
+
const fields: string[] = [];
|
|
59
|
+
const scopeNames = new Set<string>();
|
|
60
|
+
for (const { schema } of extractContextsFromSchema(definitionSchema)) {
|
|
61
|
+
const declared = schema?.[BINDINGS_ANNOTATION];
|
|
62
|
+
if (typeof declared !== "string" || declared.length === 0) continue;
|
|
63
|
+
if (!fields.includes(declared)) fields.push(declared);
|
|
64
|
+
for (const name of Object.keys(schema.properties ?? {})) scopeNames.add(name);
|
|
65
|
+
}
|
|
66
|
+
return fields.length > 0 ? { field: fields[0]!, fields, scopeNames } : undefined;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const TEMPLATE_RE = /\$\{\{\s*([^}]+?)\s*\}\}/g;
|
|
70
|
+
const EXACT_TEMPLATE_RE = /^\s*\$\{\{\s*([^}]+?)\s*\}\}\s*$/;
|
|
71
|
+
|
|
72
|
+
/** Parser for expressions that reach here uncompiled. Built once; the base
|
|
73
|
+
* environment is stateless and shared with the runtime's own. */
|
|
74
|
+
let parseEnv: ReturnType<typeof buildCelEnvironment> | undefined;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Root identifiers an expression source reads — the first element of every
|
|
78
|
+
* member-access chain, which is what a dependency edge is made of.
|
|
79
|
+
*
|
|
80
|
+
* Parsed, never lexed: `inputs.total` reads `inputs`, not `total`, and a name
|
|
81
|
+
* inside a string literal reads nothing. A token scan would make two bindings
|
|
82
|
+
* named after each other's *fields* look mutually recursive and reject a correct
|
|
83
|
+
* manifest — the worst outcome a static check has. An expression that does not
|
|
84
|
+
* parse contributes no edges; its syntax error is the engine pass's to report.
|
|
85
|
+
*/
|
|
86
|
+
function addRootIdentifiers(source: string, out: Set<string>): void {
|
|
87
|
+
try {
|
|
88
|
+
parseEnv ??= buildCelEnvironment();
|
|
89
|
+
for (const chain of extractAccessChains(parseEnv.parse(source).ast)) {
|
|
90
|
+
if (chain.length > 0) out.add(chain[0]!);
|
|
91
|
+
}
|
|
92
|
+
} catch {
|
|
93
|
+
// Unparseable — see above.
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Root identifiers a binding's value reads. Walks the whole value so a
|
|
98
|
+
* structured binding (a map with `!cel` leaves) is covered, and reads both a
|
|
99
|
+
* compiled expression and a still-raw `${{ }}` string — the editor's
|
|
100
|
+
* round-trip view never compiles. An untagged plain string is a literal, not
|
|
101
|
+
* an expression, and contributes nothing. */
|
|
102
|
+
function collectRefs(value: unknown, out: Set<string>): void {
|
|
103
|
+
if (isCompiledValue(value)) {
|
|
104
|
+
const refs = (value as { refs?: readonly string[] }).refs;
|
|
105
|
+
if (refs) for (const ref of refs) out.add(ref);
|
|
106
|
+
else addRootIdentifiers((value as { source?: string }).source ?? "", out);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (typeof value === "string") {
|
|
110
|
+
for (const match of value.matchAll(TEMPLATE_RE)) addRootIdentifiers(match[1]!, out);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (Array.isArray(value)) {
|
|
114
|
+
for (const entry of value) collectRefs(entry, out);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (value !== null && typeof value === "object") {
|
|
118
|
+
for (const entry of Object.values(value)) collectRefs(entry, out);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** Each binding's dependencies, restricted to its siblings — an identifier that
|
|
123
|
+
* names something else in scope (`inputs`, `item`) is not an edge. */
|
|
124
|
+
export function bindingDependencies(
|
|
125
|
+
bindings: Record<string, unknown>,
|
|
126
|
+
): Map<string, Set<string>> {
|
|
127
|
+
const names = new Set(Object.keys(bindings));
|
|
128
|
+
const deps = new Map<string, Set<string>>();
|
|
129
|
+
for (const [name, value] of Object.entries(bindings)) {
|
|
130
|
+
const refs = new Set<string>();
|
|
131
|
+
collectRefs(value, refs);
|
|
132
|
+
const own = new Set<string>();
|
|
133
|
+
for (const ref of refs) if (names.has(ref)) own.add(ref);
|
|
134
|
+
deps.set(name, own);
|
|
135
|
+
}
|
|
136
|
+
return deps;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Member-access chain for a binding whose value is one bare dotted identifier
|
|
140
|
+
* expression (`inputs.user.name`). Null for anything else — a literal, a call,
|
|
141
|
+
* a comprehension, a structured value — none of which reduces to a typed path. */
|
|
142
|
+
export function bindingPathChain(value: unknown): string[] | null {
|
|
143
|
+
let source: string | undefined;
|
|
144
|
+
if (isCompiledValue(value)) source = (value as { source?: string }).source;
|
|
145
|
+
else if (typeof value === "string") source = value.match(EXACT_TEMPLATE_RE)?.[1];
|
|
146
|
+
if (source === undefined) return null;
|
|
147
|
+
const expr = source.trim();
|
|
148
|
+
if (!/^[A-Za-z_]\w*(\.[A-Za-z_]\w*)*$/.test(expr)) return null;
|
|
149
|
+
return expr.split(".");
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* The context properties a bindings map contributes: each name typed from its
|
|
154
|
+
* expression where that expression is a chain into an already-typed scope
|
|
155
|
+
* variable, and left open otherwise.
|
|
156
|
+
*
|
|
157
|
+
* Gradual by design — the same stance `x-telo-context-element-from` takes. An
|
|
158
|
+
* open schema costs a missed `CEL_UNKNOWN_FIELD` under that name; inventing a
|
|
159
|
+
* type would cost a false one.
|
|
160
|
+
*/
|
|
161
|
+
export function bindingContextProperties(
|
|
162
|
+
bindings: Record<string, unknown>,
|
|
163
|
+
contextSchema: Record<string, any>,
|
|
164
|
+
): Record<string, any> {
|
|
165
|
+
const props: Record<string, any> = {};
|
|
166
|
+
for (const [name, value] of Object.entries(bindings)) {
|
|
167
|
+
props[name] = schemaAtChain(bindingPathChain(value), contextSchema) ?? {};
|
|
168
|
+
}
|
|
169
|
+
return props;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** Walk a member-access chain through a schema's `properties`, returning the
|
|
173
|
+
* terminal node or undefined once the path leaves typed schema. */
|
|
174
|
+
export function schemaAtChain(
|
|
175
|
+
chain: string[] | null,
|
|
176
|
+
root: Record<string, any>,
|
|
177
|
+
): Record<string, any> | undefined {
|
|
178
|
+
if (!chain) return undefined;
|
|
179
|
+
let current: Record<string, any> | undefined = root;
|
|
180
|
+
for (const key of chain) {
|
|
181
|
+
const props = current?.properties as Record<string, any> | undefined;
|
|
182
|
+
if (!props || !(key in props)) return undefined;
|
|
183
|
+
current = props[key] as Record<string, any>;
|
|
184
|
+
}
|
|
185
|
+
return current && typeof current === "object" ? current : undefined;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Evaluation order derived from the reference graph, plus any cycles found.
|
|
190
|
+
*
|
|
191
|
+
* Order is what the editor and diagnostics show; the runtime does not need it,
|
|
192
|
+
* since lazy evaluation reaches a binding's dependencies by construction. A
|
|
193
|
+
* cycle is reported as the path that closes it (`a → b → a`).
|
|
194
|
+
*/
|
|
195
|
+
export function resolveBindingOrder(bindings: Record<string, unknown>): {
|
|
196
|
+
order: string[];
|
|
197
|
+
cycles: string[][];
|
|
198
|
+
} {
|
|
199
|
+
const deps = bindingDependencies(bindings);
|
|
200
|
+
const order: string[] = [];
|
|
201
|
+
const cycles: string[][] = [];
|
|
202
|
+
const state = new Map<string, "visiting" | "done">();
|
|
203
|
+
const path: string[] = [];
|
|
204
|
+
|
|
205
|
+
const visit = (name: string): void => {
|
|
206
|
+
const seen = state.get(name);
|
|
207
|
+
if (seen === "done") return;
|
|
208
|
+
if (seen === "visiting") {
|
|
209
|
+
cycles.push([...path.slice(path.indexOf(name)), name]);
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
state.set(name, "visiting");
|
|
213
|
+
path.push(name);
|
|
214
|
+
for (const dep of deps.get(name) ?? []) visit(dep);
|
|
215
|
+
path.pop();
|
|
216
|
+
state.set(name, "done");
|
|
217
|
+
order.push(name);
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
for (const name of Object.keys(bindings)) visit(name);
|
|
221
|
+
return { order, cycles };
|
|
222
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -24,6 +24,14 @@ export {
|
|
|
24
24
|
type ReExportSpec,
|
|
25
25
|
} from "./flatten-for-analyzer.js";
|
|
26
26
|
export { buildEvalPaths, evalPathCovers } from "./eval-paths.js";
|
|
27
|
+
export {
|
|
28
|
+
BINDINGS_ANNOTATION,
|
|
29
|
+
bindingContextProperties,
|
|
30
|
+
bindingDependencies,
|
|
31
|
+
findBindingSites,
|
|
32
|
+
resolveBindingOrder,
|
|
33
|
+
} from "./cel-bindings.js";
|
|
34
|
+
export type { BindingSites } from "./cel-bindings.js";
|
|
27
35
|
export {
|
|
28
36
|
applyObservedStateNode,
|
|
29
37
|
buildObservedStateIndex,
|
|
@@ -111,6 +119,7 @@ export { defaultSources } from "./sources/default-sources.js";
|
|
|
111
119
|
export {
|
|
112
120
|
splitIntegrity,
|
|
113
121
|
foldIntegrity,
|
|
122
|
+
isCanonicalIntegrity,
|
|
114
123
|
verifyIntegrity,
|
|
115
124
|
verifiedFetch,
|
|
116
125
|
sha256Base64Url,
|
package/src/sources/integrity.ts
CHANGED
|
@@ -11,6 +11,13 @@
|
|
|
11
11
|
* only algorithm accepted today; the prefix leaves room to migrate. */
|
|
12
12
|
const INTEGRITY_FRAGMENT = /#(sha256-[A-Za-z0-9_+/=-]+)$/;
|
|
13
13
|
|
|
14
|
+
/** The canonical written form: SHA-256 as unpadded base64url, exactly what
|
|
15
|
+
* {@link sha256Base64Url} emits and what the `layers[].integrity` schema
|
|
16
|
+
* accepts. Stricter than {@link INTEGRITY_FRAGMENT}, which also tolerates the
|
|
17
|
+
* padded / standard-base64 spellings {@link verifyIntegrity} normalizes on the
|
|
18
|
+
* way in — reading is forgiving, writing is not. */
|
|
19
|
+
const CANONICAL_INTEGRITY = /^sha256-[A-Za-z0-9_-]{43}$/;
|
|
20
|
+
|
|
14
21
|
/** A failed integrity/tamper check — always terminal, never best-effort. A
|
|
15
22
|
* distinct type so a caller doing best-effort network handling (e.g. the
|
|
16
23
|
* bundle extractor warning-and-skipping on a fetch blip) can still let a
|
|
@@ -41,6 +48,19 @@ export function foldIntegrity(source: string, integrity: unknown): string {
|
|
|
41
48
|
: source;
|
|
42
49
|
}
|
|
43
50
|
|
|
51
|
+
/** True for a value safe to WRITE into a manifest as an integrity pin.
|
|
52
|
+
*
|
|
53
|
+
* A pin arriving from outside the file — the hub's version index, a registry
|
|
54
|
+
* response — is untrusted text before it is untrusted *content*: a value
|
|
55
|
+
* carrying a quote, a `#`, or a newline corrupts the YAML it is spliced into,
|
|
56
|
+
* which no later install-time verification can catch because the manifest no
|
|
57
|
+
* longer parses. A wrong-but-well-formed hash is the case install *does*
|
|
58
|
+
* catch; this is the case it cannot. Callers writing a pin they did not
|
|
59
|
+
* compute check here first and fall back to writing none. */
|
|
60
|
+
export function isCanonicalIntegrity(value: unknown): value is string {
|
|
61
|
+
return typeof value === "string" && CANONICAL_INTEGRITY.test(value);
|
|
62
|
+
}
|
|
63
|
+
|
|
44
64
|
function toBase64Url(bytes: Uint8Array): string {
|
|
45
65
|
let binary = "";
|
|
46
66
|
for (let i = 0; i < bytes.length; i++) binary += String.fromCharCode(bytes[i]);
|
|
@@ -325,11 +325,16 @@ export function resolveContextAnnotations(
|
|
|
325
325
|
: [fromRefKindRaw];
|
|
326
326
|
if (fromRoot || fromRefKinds.length > 0) {
|
|
327
327
|
if (fromRoot) {
|
|
328
|
-
const
|
|
328
|
+
const navigated = navigatePath(manifestRoot, fromRoot.split("/")) as
|
|
329
329
|
| Record<string, any>
|
|
330
330
|
| undefined;
|
|
331
|
-
if (
|
|
332
|
-
|
|
331
|
+
if (navigated && typeof navigated === "object" && !Array.isArray(navigated)) {
|
|
332
|
+
// A `telo#Type` slot resolves to the schema it names — the inline
|
|
333
|
+
// `{ kind, schema }` wrapper, a `!ref` to a named type, or a bare name —
|
|
334
|
+
// so the variable is typed by the CONTRACT rather than by the wrapper
|
|
335
|
+
// around it. A raw JSON Schema resolves to itself, and a plain property
|
|
336
|
+
// map (a transport scope) resolves to nothing and is used verbatim.
|
|
337
|
+
return resolveTypeFieldToSchema(navigated, allManifests ?? []) ?? navigated;
|
|
333
338
|
}
|
|
334
339
|
}
|
|
335
340
|
if (defs) {
|