@telorun/analyzer 0.64.0 → 0.65.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 +19 -3
- package/dist/definition-registry.d.ts +23 -6
- package/dist/definition-registry.d.ts.map +1 -1
- package/dist/definition-registry.js +41 -13
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/schema-compat.d.ts +59 -22
- package/dist/schema-compat.d.ts.map +1 -1
- package/dist/schema-compat.js +60 -75
- package/dist/schema-error-report.d.ts +68 -0
- package/dist/schema-error-report.d.ts.map +1 -0
- package/dist/schema-error-report.js +356 -0
- package/dist/telo-version.d.ts +1 -1
- package/dist/telo-version.js +1 -1
- package/dist/validate-nested-inline.d.ts +22 -1
- package/dist/validate-nested-inline.d.ts.map +1 -1
- package/dist/validate-nested-inline.js +17 -9
- package/dist/validate-step-inputs.js +11 -3
- package/package.json +2 -2
- package/src/analyzer.ts +22 -2
- package/src/definition-registry.ts +48 -11
- package/src/index.ts +10 -2
- package/src/schema-compat.ts +92 -79
- package/src/schema-error-report.ts +417 -0
- package/src/telo-version.ts +1 -1
- package/src/validate-nested-inline.ts +35 -14
- package/src/validate-step-inputs.ts +10 -4
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,EAAsB,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAiBzE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAIL,KAAK,WAAW,EACjB,MAAM,sBAAsB,CAAC;AA8B9B,OAAO,EAAmB,KAAK,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAWvF,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,aAAa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;QAAE,WAAW,EAAE,kBAAkB,EAAE,CAAC;QAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;QAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE;CAsB5F"}
|
package/dist/analyzer.js
CHANGED
|
@@ -1257,6 +1257,17 @@ export class StaticAnalyzer {
|
|
|
1257
1257
|
diagnostics.push(...validateIncludePlacement(allManifests));
|
|
1258
1258
|
}
|
|
1259
1259
|
resolveSchemaTypeRefs(allManifests, aliases, aliasesByModule);
|
|
1260
|
+
// ...and over the manifests the DEFINITION REGISTRY holds, which are not
|
|
1261
|
+
// these. `normalizeInlineResources` deep-clones — that clone is the
|
|
1262
|
+
// analyzer's immutability boundary — while `defs.register` ran before it, on
|
|
1263
|
+
// the originals. So a kind whose `schema:` references a named shape kept the
|
|
1264
|
+
// authored `telo://Self/<Type>` spelling everywhere the registry is read,
|
|
1265
|
+
// which is where a resource's configuration is validated: the schema failed
|
|
1266
|
+
// to compile, the failure was swallowed, and `telo check` reported nothing
|
|
1267
|
+
// about a resource the kernel then rejected at boot. The pass is idempotent
|
|
1268
|
+
// — a canonical id parses as no authority and is left alone — so running it
|
|
1269
|
+
// over both is the whole repair.
|
|
1270
|
+
resolveSchemaTypeRefs(manifests, aliases, aliasesByModule);
|
|
1260
1271
|
// Trusted-input fast path: when the caller has already attested that
|
|
1261
1272
|
// this exact manifest set passes analysis (e.g. via the kernel's
|
|
1262
1273
|
// hash-stamped `.validated.json` cache), skip the validation walk.
|
|
@@ -1523,8 +1534,10 @@ export class StaticAnalyzer {
|
|
|
1523
1534
|
for (const slot of collectCelValueSlots(m, schema, "")) {
|
|
1524
1535
|
celReturnSlots.push({ manifest: m, resource, filePath, ...slot });
|
|
1525
1536
|
}
|
|
1526
|
-
// Phase 2+3: AJV on substituted data — CEL fields replaced with typed
|
|
1527
|
-
|
|
1537
|
+
// Phase 2+3: AJV on substituted data — CEL fields replaced with typed
|
|
1538
|
+
// placeholders. Through the REGISTRY, so a kind whose schema references
|
|
1539
|
+
// a shape declared elsewhere is checked on the instance that holds it.
|
|
1540
|
+
const ajvIssues = defs.validateResourceConfig(substituteCelFields(m, schema, undefined, { external: (ref) => defs.schemaForId(ref) }), schema);
|
|
1528
1541
|
// Phase 4: value slots that must satisfy a type declared elsewhere on
|
|
1529
1542
|
// the resource (`x-telo-value-schema-from`) — e.g. every row of a
|
|
1530
1543
|
// decision table against its declared `outputType`, so a mistyped branch
|
|
@@ -1615,7 +1628,10 @@ export class StaticAnalyzer {
|
|
|
1615
1628
|
}
|
|
1616
1629
|
const viaRoot = aliases.resolveKind(kind);
|
|
1617
1630
|
return viaRoot ? defs.resolve(viaRoot) : undefined;
|
|
1618
|
-
}, allManifests
|
|
1631
|
+
}, allManifests, {
|
|
1632
|
+
validate: (data, target) => defs.validateResourceConfig(data, target),
|
|
1633
|
+
external: (ref) => defs.schemaForId(ref),
|
|
1634
|
+
}));
|
|
1619
1635
|
}
|
|
1620
1636
|
// (Invocation context compatibility check is handled via x-telo-context in the CEL pass below)
|
|
1621
1637
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ResourceDefinition, ResourceManifest } from "@telorun/sdk";
|
|
2
2
|
import type { AliasResolver } from "./alias-resolver.js";
|
|
3
3
|
import { type ReferenceFieldMap } from "./reference-field-map.js";
|
|
4
|
-
|
|
4
|
+
import { type SchemaIssue } from "./schema-error-report.js";
|
|
5
5
|
export declare class DefinitionRegistry {
|
|
6
6
|
constructor();
|
|
7
7
|
/** Per-instance AJV for cross-module $ref resolution. Isolated so each registry
|
|
@@ -9,6 +9,7 @@ export declare class DefinitionRegistry {
|
|
|
9
9
|
* across analyze() calls and no unbounded growth across the process lifetime. */
|
|
10
10
|
private readonly ajv;
|
|
11
11
|
private readonly registeredSchemaIds;
|
|
12
|
+
private readonly compiledValidators;
|
|
12
13
|
/** The subset of `registeredSchemaIds` claimed by a kind's schema. Kinds and
|
|
13
14
|
* named `Telo.Type`s share one `telo://<module>/<Name>` id space, so this is
|
|
14
15
|
* what lets a colliding type name be reported instead of silently dropped. */
|
|
@@ -77,12 +78,28 @@ export declare class DefinitionRegistry {
|
|
|
77
78
|
* sanctioned way to reuse one, so a comparator that cannot follow the
|
|
78
79
|
* reference judges two opaque nodes and learns nothing. */
|
|
79
80
|
schemaForId(id: string): Record<string, any> | undefined;
|
|
80
|
-
/**
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
81
|
+
/**
|
|
82
|
+
* Validates a resource's configuration against its kind's schema, with the
|
|
83
|
+
* offending field's path — what a `SCHEMA_VIOLATION` diagnostic is built from.
|
|
84
|
+
*
|
|
85
|
+
* On THIS registry's AJV, which is the point: it holds every registered
|
|
86
|
+
* definition schema and every named `Telo.Type`, so a kind whose schema
|
|
87
|
+
* references a shape declared elsewhere is checked rather than skipped. The
|
|
88
|
+
* module-level instance this used to run on had none of them registered, so
|
|
89
|
+
* such a schema failed to compile and the failure was swallowed — a resource
|
|
90
|
+
* could be arbitrarily wrong and `telo check` reported nothing, while the
|
|
91
|
+
* kernel (whose validator does resolve the reference) rejected it at boot.
|
|
92
|
+
* Two AJVs answering one question is what made that possible; there is now
|
|
93
|
+
* one, and it is the same one `schemaCompileError` reports through.
|
|
94
|
+
*/
|
|
85
95
|
validateWithRefs(data: unknown, schema: Record<string, any>): string[];
|
|
96
|
+
/** {@link validateWithRefs}, with the path each issue is anchored at. */
|
|
97
|
+
validateResourceConfig(data: unknown, schema: Record<string, any>): SchemaIssue[];
|
|
98
|
+
/** Memoized per schema OBJECT — the analyzer validates every resource of a
|
|
99
|
+
* kind against the same one, and this runs at keystroke time in an editor.
|
|
100
|
+
* A schema AJV refuses compiles to `undefined`; that is reported once,
|
|
101
|
+
* anchored on the owning definition, by `schemaCompileError`. */
|
|
102
|
+
private compiledFor;
|
|
86
103
|
/** Returns the AJV compile error for `schema`, or `undefined` when it compiles.
|
|
87
104
|
* Compiles on this registry's instance, which has every loaded module schema
|
|
88
105
|
* plus the manifest root registered, so local `#/$defs`, `telo://manifest`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definition-registry.d.ts","sourceRoot":"","sources":["../src/definition-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,EAIL,KAAK,iBAAiB,EACvB,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"definition-registry.d.ts","sourceRoot":"","sources":["../src/definition-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,EAIL,KAAK,iBAAiB,EACvB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAIL,KAAK,WAAW,EACjB,MAAM,0BAA0B,CAAC;AAOlC,qBAAa,kBAAkB;;IAK7B;;sFAEkF;IAClF,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAe;IACnC,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAqB;IACzD,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAyD;IAC5F;;mFAE+E;IAC/E,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAqB;IAEzD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAyC;IAC9D,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAwC;IAClE,mEAAmE;IACnE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA+B;IAC1D;;;;wEAIoE;IACpE,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA6B;IAEzD,QAAQ,CAAC,UAAU,EAAE,kBAAkB,GAAG,IAAI;IAoC9C,OAAO,CAAC,aAAa;IASrB;;;;;;;;;;;;;2FAauF;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AW,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;KAAE,GACvD,iBAAiB,GAAG,SAAS;IAOhC;;;;;;;;qFAQiF;IACjF,2BAA2B,CACzB,QAAQ,EAAE,gBAAgB,EAC1B,OAAO,EAAE,aAAa,EACtB,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,GAC1C,iBAAiB,GAAG,SAAS;IAkChC;;;;;;;;;;;;;OAaG;IACH,qBAAqB,CACnB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,aAAa,GACxB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS;IAsBlC,OAAO,CAAC,uBAAuB;IAU/B;;qEAEiE;IACjE,YAAY,CAAC,YAAY,EAAE,MAAM,GAAG,kBAAkB,EAAE;IAgBxD,KAAK,IAAI,MAAM,EAAE;CAGlB"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { canonicalTypeSchemaId } from "@telorun/sdk";
|
|
2
2
|
import { KERNEL_BUILTINS } from "./builtins.js";
|
|
3
3
|
import { buildFieldMapAtPath, buildReferenceFieldMap, isSchemaFromEntry, } from "./reference-field-map.js";
|
|
4
|
-
import { createAjv,
|
|
4
|
+
import { createAjv, navigateJsonPointer } from "./schema-compat.js";
|
|
5
|
+
import { formatSingleError, reduceSchemaErrors, schemaIssues, } from "./schema-error-report.js";
|
|
5
6
|
import { effectiveAuthorSchema } from "./extends-resolution.js";
|
|
6
|
-
/** Pure kind → ResourceDefinition map. No controller loading, no lifecycle. */
|
|
7
7
|
export class DefinitionRegistry {
|
|
8
8
|
constructor() {
|
|
9
9
|
for (const def of KERNEL_BUILTINS)
|
|
@@ -14,6 +14,7 @@ export class DefinitionRegistry {
|
|
|
14
14
|
* across analyze() calls and no unbounded growth across the process lifetime. */
|
|
15
15
|
ajv = createAjv();
|
|
16
16
|
registeredSchemaIds = new Set();
|
|
17
|
+
compiledValidators = new WeakMap();
|
|
17
18
|
/** The subset of `registeredSchemaIds` claimed by a kind's schema. Kinds and
|
|
18
19
|
* named `Telo.Type`s share one `telo://<module>/<Name>` id space, so this is
|
|
19
20
|
* what lets a colliding type name be reported instead of silently dropped. */
|
|
@@ -152,22 +153,49 @@ export class DefinitionRegistry {
|
|
|
152
153
|
const schema = compiled?.schema;
|
|
153
154
|
return schema && typeof schema === "object" ? schema : undefined;
|
|
154
155
|
}
|
|
155
|
-
/**
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
156
|
+
/**
|
|
157
|
+
* Validates a resource's configuration against its kind's schema, with the
|
|
158
|
+
* offending field's path — what a `SCHEMA_VIOLATION` diagnostic is built from.
|
|
159
|
+
*
|
|
160
|
+
* On THIS registry's AJV, which is the point: it holds every registered
|
|
161
|
+
* definition schema and every named `Telo.Type`, so a kind whose schema
|
|
162
|
+
* references a shape declared elsewhere is checked rather than skipped. The
|
|
163
|
+
* module-level instance this used to run on had none of them registered, so
|
|
164
|
+
* such a schema failed to compile and the failure was swallowed — a resource
|
|
165
|
+
* could be arbitrarily wrong and `telo check` reported nothing, while the
|
|
166
|
+
* kernel (whose validator does resolve the reference) rejected it at boot.
|
|
167
|
+
* Two AJVs answering one question is what made that possible; there is now
|
|
168
|
+
* one, and it is the same one `schemaCompileError` reports through.
|
|
169
|
+
*/
|
|
160
170
|
validateWithRefs(data, schema) {
|
|
161
|
-
|
|
171
|
+
const validate = this.compiledFor(schema);
|
|
172
|
+
if (!validate || validate(data))
|
|
173
|
+
return [];
|
|
174
|
+
return reduceSchemaErrors(validate.errors).map(formatSingleError);
|
|
175
|
+
}
|
|
176
|
+
/** {@link validateWithRefs}, with the path each issue is anchored at. */
|
|
177
|
+
validateResourceConfig(data, schema) {
|
|
178
|
+
const validate = this.compiledFor(schema);
|
|
179
|
+
if (!validate || validate(data))
|
|
180
|
+
return [];
|
|
181
|
+
return schemaIssues(validate.errors);
|
|
182
|
+
}
|
|
183
|
+
/** Memoized per schema OBJECT — the analyzer validates every resource of a
|
|
184
|
+
* kind against the same one, and this runs at keystroke time in an editor.
|
|
185
|
+
* A schema AJV refuses compiles to `undefined`; that is reported once,
|
|
186
|
+
* anchored on the owning definition, by `schemaCompileError`. */
|
|
187
|
+
compiledFor(schema) {
|
|
188
|
+
const cached = this.compiledValidators.get(schema);
|
|
189
|
+
if (cached)
|
|
190
|
+
return cached;
|
|
162
191
|
try {
|
|
163
|
-
validate = this.ajv.compile(schema);
|
|
192
|
+
const validate = this.ajv.compile(schema);
|
|
193
|
+
this.compiledValidators.set(schema, validate);
|
|
194
|
+
return validate;
|
|
164
195
|
}
|
|
165
196
|
catch {
|
|
166
|
-
return
|
|
197
|
+
return undefined;
|
|
167
198
|
}
|
|
168
|
-
if (validate(data))
|
|
169
|
-
return [];
|
|
170
|
-
return (validate.errors ?? []).map(formatSingleError);
|
|
171
199
|
}
|
|
172
200
|
/** Returns the AJV compile error for `schema`, or `undefined` when it compiles.
|
|
173
201
|
* Compiles on this registry's instance, which has every loaded module schema
|
package/dist/index.d.ts
CHANGED
|
@@ -60,8 +60,10 @@ export { validateDynamicSelectors, validateRefSlotDeclarations } from "./validat
|
|
|
60
60
|
export type { RefSlotIssue } from "./validate-ref-slots.js";
|
|
61
61
|
export { validateValueTypeSlots } from "./validate-value-type-slots.js";
|
|
62
62
|
export type { ValueTypeSlotIssue } from "./validate-value-type-slots.js";
|
|
63
|
-
export { checkSchemaCompatibility, selectUnionBranch } from "./schema-compat.js";
|
|
64
|
-
export type { CompatibilityResult } from "./schema-compat.js";
|
|
63
|
+
export { checkSchemaCompatibility, resolveRefIn, selectUnionBranch } from "./schema-compat.js";
|
|
64
|
+
export type { CompatibilityResult, ExternalSchemaResolver } from "./schema-compat.js";
|
|
65
|
+
export { ajvErrorToPath, formatAjvErrors, formatSingleError, reduceSchemaErrors, schemaIssues, } from "./schema-error-report.js";
|
|
66
|
+
export type { AjvErrorLike, SchemaIssue } from "./schema-error-report.js";
|
|
65
67
|
export { visitManifest } from "./manifest-visitor.js";
|
|
66
68
|
export type { CelSiteEvent, ManifestVisitor, RefSiteEvent, ResourceEnterEvent, ResourceExitEvent, ScopeBoundaryEvent, SchemaFromSiteEvent, VisitOptions, } from "./manifest-visitor.js";
|
|
67
69
|
export { Loader } from "./manifest-loader.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,0BAA0B,EAC1B,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,mBAAmB,EACnB,wBAAwB,EACxB,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,SAAS,GACV,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EACL,sBAAsB,EACtB,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a,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC3E,YAAY,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAKxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,YAAY,EAAE,QAAQ,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,YAAY,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAGzF,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,YAAY,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC1F,YAAY,EACR,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,WAAW,EACX,cAAc,EACd,QAAQ,EACR,aAAa,EACb,KAAK,EACR,MAAM,YAAY,CAAC;AACpB,cAAc,uBAAuB,CAAC;AAGtC,cAAc,sBAAsB,CAAC;AAIrC,OAAO,EACL,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,4BAA4B,CAAC;AACpC,cAAc,oBAAoB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -36,7 +36,8 @@ export { validateZoneViolations } from "./validate-zone-violations.js";
|
|
|
36
36
|
export { containmentIndex, findZoneRegions, regionManifests, } from "./resolve-zone-containment.js";
|
|
37
37
|
export { validateDynamicSelectors, validateRefSlotDeclarations } from "./validate-ref-slots.js";
|
|
38
38
|
export { validateValueTypeSlots } from "./validate-value-type-slots.js";
|
|
39
|
-
export { checkSchemaCompatibility, selectUnionBranch } from "./schema-compat.js";
|
|
39
|
+
export { checkSchemaCompatibility, resolveRefIn, selectUnionBranch } from "./schema-compat.js";
|
|
40
|
+
export { ajvErrorToPath, formatAjvErrors, formatSingleError, reduceSchemaErrors, schemaIssues, } from "./schema-error-report.js";
|
|
40
41
|
export { visitManifest } from "./manifest-visitor.js";
|
|
41
42
|
export { Loader } from "./manifest-loader.js";
|
|
42
43
|
export { isModuleKind, MODULE_KINDS } from "./module-kinds.js";
|
package/dist/schema-compat.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type SchemaIssue } from "./schema-error-report.js";
|
|
1
2
|
declare const Ajv: any;
|
|
2
3
|
/** Creates a configured AJV instance (allErrors, strict: false, with formats).
|
|
3
4
|
* Also registers the kernel manifest root schema under `telo://manifest` so
|
|
@@ -35,14 +36,8 @@ export interface CompatibilityResult {
|
|
|
35
36
|
* {@link withLiveValuesSkipped} takes one.
|
|
36
37
|
*/
|
|
37
38
|
export declare function checkSchemaCompatibility(source: Record<string, any>, target: Record<string, any>, resolveRef?: (ref: string) => Record<string, any> | undefined): CompatibilityResult;
|
|
38
|
-
export
|
|
39
|
-
export
|
|
40
|
-
/** A schema validation issue with a dotted-path pointer to the offending field. */
|
|
41
|
-
export interface SchemaIssue {
|
|
42
|
-
message: string;
|
|
43
|
-
/** Dotted path to the field (e.g. "config.handler"). Empty string means root. */
|
|
44
|
-
path: string;
|
|
45
|
-
}
|
|
39
|
+
export { formatAjvErrors, formatSingleError } from "./schema-error-report.js";
|
|
40
|
+
export type { SchemaIssue } from "./schema-error-report.js";
|
|
46
41
|
/** Validate actual data against a JSON Schema. Returns issues with path info, or empty array if valid. */
|
|
47
42
|
export declare function validateAgainstSchema(data: unknown, schema: Record<string, any>): SchemaIssue[];
|
|
48
43
|
/** Resolves a JSON Pointer (RFC 6901, must start with "/") into a schema object.
|
|
@@ -76,8 +71,36 @@ export declare function jsonSchemaToCelType(schema: Record<string, any> | undefi
|
|
|
76
71
|
/** Check whether a CEL return type is compatible with a JSON Schema type constraint. */
|
|
77
72
|
export declare function celTypeSatisfiesJsonSchema(celType: string, schema: Record<string, any>): boolean;
|
|
78
73
|
export declare function celPlaceholderForSchema(rawSchema: Record<string, any>): unknown;
|
|
79
|
-
/**
|
|
80
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Resolve a `$ref` — the document-local `#/$defs/...` form against `root`, and
|
|
76
|
+
* anything else through `external` when a caller supplies one.
|
|
77
|
+
*
|
|
78
|
+
* A named shape is addressed by a registered id (`telo:<module>/<Type>`), which
|
|
79
|
+
* lives in a schema store rather than in this document, so without the hook a
|
|
80
|
+
* walk stops at the reference and treats a described value as undescribed:
|
|
81
|
+
* every CEL leaf under it is handed the schema-unaware `""` placeholder and
|
|
82
|
+
* then rejected against a branch it was never measured against. The caller
|
|
83
|
+
* supplies the store because only the caller has one.
|
|
84
|
+
*/
|
|
85
|
+
export declare function resolveRef(schema: Record<string, any>, root: Record<string, any>, external?: ExternalSchemaResolver): Record<string, any>;
|
|
86
|
+
/**
|
|
87
|
+
* {@link resolveRef}, reporting the ROOT the result's own `#/...` references
|
|
88
|
+
* resolve against.
|
|
89
|
+
*
|
|
90
|
+
* Following an external reference enters another document, and a `$ref` inside
|
|
91
|
+
* it is relative to THAT document — which is the whole of how a shape declares
|
|
92
|
+
* its own vocabulary (`anyOf: [{$ref: "#/$defs/Text"}, …]`). Resolving those
|
|
93
|
+
* against the referring document finds nothing, and a walker that then treats
|
|
94
|
+
* the branches as unconstrained accepts every one of them, resolves the union
|
|
95
|
+
* to nothing, and hands the values underneath an untyped stand-in. So the base
|
|
96
|
+
* travels with the schema.
|
|
97
|
+
*/
|
|
98
|
+
export declare function resolveRefIn(schema: Record<string, any>, root: Record<string, any>, external?: ExternalSchemaResolver): {
|
|
99
|
+
schema: Record<string, any>;
|
|
100
|
+
root: Record<string, any>;
|
|
101
|
+
};
|
|
102
|
+
/** Looks a registered schema up by its `$id`. */
|
|
103
|
+
export type ExternalSchemaResolver = (ref: string) => Record<string, any> | undefined;
|
|
81
104
|
/** Collect property schemas from top-level `properties` and all `oneOf`/`anyOf` sub-schemas. */
|
|
82
105
|
/**
|
|
83
106
|
* The `oneOf` / `anyOf` branch a value is written against, when exactly one fits.
|
|
@@ -95,20 +118,34 @@ export declare function resolveRef(schema: Record<string, any>, root: Record<str
|
|
|
95
118
|
* — an ambiguous union is one the analyzer should not resolve on the author's
|
|
96
119
|
* behalf.
|
|
97
120
|
*/
|
|
98
|
-
export declare function selectUnionBranch(schema: Record<string, any>, data: unknown, root: Record<string, any
|
|
121
|
+
export declare function selectUnionBranch(schema: Record<string, any>, data: unknown, root: Record<string, any>, external?: ExternalSchemaResolver): Record<string, any>;
|
|
99
122
|
export declare function collectProperties(schema: Record<string, any>): Record<string, any>;
|
|
100
123
|
/** Deep-clone `data`, replacing every pure CEL template string (`${{ expr }}`) with a
|
|
101
124
|
* schema-appropriate placeholder so AJV can validate non-CEL fields without false positives. */
|
|
102
|
-
|
|
103
|
-
/** Called with the dotted path of every value replaced by a placeholder.
|
|
125
|
+
/** Everything {@link substituteCelFields} does beyond walking the value.
|
|
104
126
|
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
127
|
+
* One object rather than trailing positionals: the resolver is the parameter a
|
|
128
|
+
* caller most needs and was the LAST of six, so reaching it meant counting
|
|
129
|
+
* `undefined`s — and a caller that stopped counting one short simply got the
|
|
130
|
+
* old blind behaviour, silently. Two of them did. */
|
|
131
|
+
export interface SubstituteOptions {
|
|
132
|
+
/** Called with the dotted path of every value replaced by a placeholder.
|
|
133
|
+
*
|
|
134
|
+
* A placeholder is a stand-in for something only known at runtime, so its
|
|
135
|
+
* VALUE says nothing: a caller that judges constraints at these paths reports
|
|
136
|
+
* against a value no author wrote. Some constraints cannot be satisfied by
|
|
137
|
+
* construction at all (`pattern`, `format`, a `oneOf` of unrelated shapes),
|
|
138
|
+
* so making every placeholder acceptable is not achievable in general —
|
|
139
|
+
* knowing where not to look is. Structural findings survive because they are
|
|
140
|
+
* located at the CONTAINER, not at the substituted leaf. */
|
|
141
|
+
onSubstitute?: (path: string) => void;
|
|
142
|
+
/** Dotted path of `data` within the resource, for `onSubstitute`. */
|
|
143
|
+
path?: string;
|
|
144
|
+
/** Resolves a named shape (`telo:<module>/<Type>`) to its schema. Without it
|
|
145
|
+
* a slot described by one reads as undescribed and every CEL leaf beneath it
|
|
146
|
+
* is handed the typeless `""` stand-in — which the shape then rejects, so a
|
|
147
|
+
* perfectly valid expression is reported as a violation. */
|
|
148
|
+
external?: ExternalSchemaResolver;
|
|
149
|
+
}
|
|
150
|
+
export declare function substituteCelFields(data: unknown, schema: Record<string, any>, rootSchema?: Record<string, any>, options?: SubstituteOptions): unknown;
|
|
114
151
|
//# sourceMappingURL=schema-compat.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-compat.d.ts","sourceRoot":"","sources":["../src/schema-compat.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"schema-compat.d.ts","sourceRoot":"","sources":["../src/schema-compat.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAgB,KAAK,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAG1E,QAAA,MAAM,GAAG,KAA0C,CAAC;AAEpD;;;;;;;mCAOmC;AACnC,wBAAgB,SAAS,IAAI,YAAY,CAAC,OAAO,GAAG,CAAC,CAYpD;AAKD,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,OAAO,CAAC;IACpB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAYD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC3B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC3B,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAA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rE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;iEAG6D;IAC7D,QAAQ,CAAC,EAAE,sBAAsB,CAAC;CACnC;AAED,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,OAAO,EACb,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC3B,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAChC,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAuET"}
|
package/dist/schema-compat.js
CHANGED
|
@@ -3,6 +3,7 @@ import addFormats from "ajv-formats";
|
|
|
3
3
|
import { isRefSentinel, isTaggedSentinel, producedTypeOf, } from "@telorun/templating";
|
|
4
4
|
import { celBaseOfValueType, celTypeOfValueType, readValueTypeSlot, valueBrandBases, valueTypeOf, valueTypePlaceholder, } from "@telorun/sdk";
|
|
5
5
|
import { ManifestRootSchema } from "./manifest-schemas.js";
|
|
6
|
+
import { schemaIssues } from "./schema-error-report.js";
|
|
6
7
|
import { registerTeloKeywords } from "./value-type-keyword.js";
|
|
7
8
|
const Ajv = AjvModule.default ?? AjvModule;
|
|
8
9
|
/** Creates a configured AJV instance (allErrors, strict: false, with formats).
|
|
@@ -193,48 +194,7 @@ function compare(rawSource, rawTarget, path, issues, resolveRef, seen) {
|
|
|
193
194
|
}
|
|
194
195
|
}
|
|
195
196
|
}
|
|
196
|
-
export
|
|
197
|
-
const p = err.instancePath || "/";
|
|
198
|
-
const params = err.params ?? {};
|
|
199
|
-
switch (err.keyword) {
|
|
200
|
-
case "additionalProperties":
|
|
201
|
-
return `${p} must NOT have additional properties ('${params.additionalProperty}' is not allowed)`;
|
|
202
|
-
case "required":
|
|
203
|
-
return `${p} is missing required property '${params.missingProperty}'`;
|
|
204
|
-
case "enum":
|
|
205
|
-
return `${p} ${err.message ?? "is invalid"} (${params.allowedValues?.join(" | ")})`;
|
|
206
|
-
case "type":
|
|
207
|
-
return `${p} must be ${params.type} (got ${typeof err.data})`;
|
|
208
|
-
default:
|
|
209
|
-
return `${p} ${err.message ?? "is invalid"}`;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
export function formatAjvErrors(errors) {
|
|
213
|
-
if (!errors || errors.length === 0)
|
|
214
|
-
return "Unknown schema error";
|
|
215
|
-
return errors.map(formatSingleError).join("; ");
|
|
216
|
-
}
|
|
217
|
-
/** Converts an AJV error object to a dotted path string compatible with PositionIndex keys.
|
|
218
|
-
* e.g. instancePath "/config/routes/0/handler" → "config.routes[0].handler"
|
|
219
|
-
* For "required" keyword errors, appends the missing property to the parent path. */
|
|
220
|
-
function ajvErrorToPath(err) {
|
|
221
|
-
const instancePath = (err.instancePath ?? "");
|
|
222
|
-
const parts = instancePath.split("/").filter((p) => p !== "");
|
|
223
|
-
let result = "";
|
|
224
|
-
for (const part of parts) {
|
|
225
|
-
if (/^\d+$/.test(part)) {
|
|
226
|
-
result += `[${part}]`;
|
|
227
|
-
}
|
|
228
|
-
else {
|
|
229
|
-
result += result ? `.${part}` : part;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
if (err.keyword === "required" && err.params?.missingProperty) {
|
|
233
|
-
const missing = err.params.missingProperty;
|
|
234
|
-
result += result ? `.${missing}` : missing;
|
|
235
|
-
}
|
|
236
|
-
return result;
|
|
237
|
-
}
|
|
197
|
+
export { formatAjvErrors, formatSingleError } from "./schema-error-report.js";
|
|
238
198
|
/** Does `schema` compile as-authored? Used to tell a malformed module schema
|
|
239
199
|
* (the author's problem) apart from a fault we introduced while normalizing it. */
|
|
240
200
|
function schemaCompiles(schema) {
|
|
@@ -268,10 +228,7 @@ export function validateAgainstSchema(data, schema) {
|
|
|
268
228
|
}
|
|
269
229
|
if (validate(data))
|
|
270
230
|
return [];
|
|
271
|
-
return (validate.errors
|
|
272
|
-
message: formatSingleError(err),
|
|
273
|
-
path: ajvErrorToPath(err),
|
|
274
|
-
}));
|
|
231
|
+
return schemaIssues(validate.errors);
|
|
275
232
|
}
|
|
276
233
|
/** Resolves a JSON Pointer (RFC 6901, must start with "/") into a schema object.
|
|
277
234
|
* Returns undefined when any segment along the path is missing or not an object. */
|
|
@@ -590,15 +547,43 @@ function objectPlaceholder(schema) {
|
|
|
590
547
|
return out;
|
|
591
548
|
}
|
|
592
549
|
const CEL_PURE_RE = /^\s*\$\{\{[^}]*\}\}\s*$/;
|
|
593
|
-
/**
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
550
|
+
/**
|
|
551
|
+
* Resolve a `$ref` — the document-local `#/$defs/...` form against `root`, and
|
|
552
|
+
* anything else through `external` when a caller supplies one.
|
|
553
|
+
*
|
|
554
|
+
* A named shape is addressed by a registered id (`telo:<module>/<Type>`), which
|
|
555
|
+
* lives in a schema store rather than in this document, so without the hook a
|
|
556
|
+
* walk stops at the reference and treats a described value as undescribed:
|
|
557
|
+
* every CEL leaf under it is handed the schema-unaware `""` placeholder and
|
|
558
|
+
* then rejected against a branch it was never measured against. The caller
|
|
559
|
+
* supplies the store because only the caller has one.
|
|
560
|
+
*/
|
|
561
|
+
export function resolveRef(schema, root, external) {
|
|
562
|
+
return resolveRefIn(schema, root, external).schema;
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* {@link resolveRef}, reporting the ROOT the result's own `#/...` references
|
|
566
|
+
* resolve against.
|
|
567
|
+
*
|
|
568
|
+
* Following an external reference enters another document, and a `$ref` inside
|
|
569
|
+
* it is relative to THAT document — which is the whole of how a shape declares
|
|
570
|
+
* its own vocabulary (`anyOf: [{$ref: "#/$defs/Text"}, …]`). Resolving those
|
|
571
|
+
* against the referring document finds nothing, and a walker that then treats
|
|
572
|
+
* the branches as unconstrained accepts every one of them, resolves the union
|
|
573
|
+
* to nothing, and hands the values underneath an untyped stand-in. So the base
|
|
574
|
+
* travels with the schema.
|
|
575
|
+
*/
|
|
576
|
+
export function resolveRefIn(schema, root, external) {
|
|
577
|
+
if (!schema.$ref || typeof schema.$ref !== "string")
|
|
578
|
+
return { schema, root };
|
|
579
|
+
if (schema.$ref === "#")
|
|
580
|
+
return { schema: root, root };
|
|
581
|
+
if (schema.$ref.startsWith("#/$defs/")) {
|
|
582
|
+
const resolved = root.$defs?.[schema.$ref.slice("#/$defs/".length)];
|
|
583
|
+
return resolved ? { schema: resolved, root } : { schema, root };
|
|
584
|
+
}
|
|
585
|
+
const target = external?.(schema.$ref);
|
|
586
|
+
return target ? { schema: target, root: target } : { schema, root };
|
|
602
587
|
}
|
|
603
588
|
/** Collect property schemas from top-level `properties` and all `oneOf`/`anyOf` sub-schemas. */
|
|
604
589
|
/**
|
|
@@ -617,7 +602,7 @@ export function resolveRef(schema, root) {
|
|
|
617
602
|
* — an ambiguous union is one the analyzer should not resolve on the author's
|
|
618
603
|
* behalf.
|
|
619
604
|
*/
|
|
620
|
-
export function selectUnionBranch(schema, data, root) {
|
|
605
|
+
export function selectUnionBranch(schema, data, root, external) {
|
|
621
606
|
const branches = (schema.oneOf ?? schema.anyOf);
|
|
622
607
|
if (!Array.isArray(branches) || branches.length === 0)
|
|
623
608
|
return schema;
|
|
@@ -639,7 +624,7 @@ export function selectUnionBranch(schema, data, root) {
|
|
|
639
624
|
if (!kind)
|
|
640
625
|
return schema;
|
|
641
626
|
const fits = branches
|
|
642
|
-
.map((b) => resolveRef(b, root))
|
|
627
|
+
.map((b) => resolveRef(b, root, external))
|
|
643
628
|
.filter((b) => {
|
|
644
629
|
const types = Array.isArray(b.type) ? b.type : b.type ? [b.type] : [];
|
|
645
630
|
if (types.length > 0 && !types.includes(kind))
|
|
@@ -680,21 +665,13 @@ export function collectProperties(schema) {
|
|
|
680
665
|
}
|
|
681
666
|
return props;
|
|
682
667
|
}
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
* against a value no author wrote. Some constraints cannot be satisfied by
|
|
691
|
-
* construction at all (`pattern`, `format`, a `oneOf` of unrelated shapes),
|
|
692
|
-
* so making every placeholder acceptable is not achievable in general —
|
|
693
|
-
* knowing where not to look is. Structural findings survive because they are
|
|
694
|
-
* located at the CONTAINER, not at the substituted leaf. */
|
|
695
|
-
onSubstitute, path = "") {
|
|
696
|
-
const root = rootSchema ?? schema;
|
|
697
|
-
const resolved = selectUnionBranch(resolveRef(schema, root), data, root);
|
|
668
|
+
export function substituteCelFields(data, schema, rootSchema, options = {}) {
|
|
669
|
+
const { onSubstitute, external } = options;
|
|
670
|
+
const path = options.path ?? "";
|
|
671
|
+
const base = rootSchema ?? schema;
|
|
672
|
+
const entered = resolveRefIn(schema, base, external);
|
|
673
|
+
const root = entered.root;
|
|
674
|
+
const resolved = selectUnionBranch(entered.schema, data, root, external);
|
|
698
675
|
const mark = () => onSubstitute?.(path);
|
|
699
676
|
if (typeof data === "string" && CEL_PURE_RE.test(data)) {
|
|
700
677
|
mark();
|
|
@@ -733,8 +710,12 @@ onSubstitute, path = "") {
|
|
|
733
710
|
return celPlaceholderForSchema(resolved);
|
|
734
711
|
}
|
|
735
712
|
if (Array.isArray(data)) {
|
|
736
|
-
const
|
|
737
|
-
return data.map((
|
|
713
|
+
const item = resolveRefIn((resolved.items ?? {}), root, external);
|
|
714
|
+
return data.map((element, i) => substituteCelFields(element, item.schema, item.root, {
|
|
715
|
+
onSubstitute,
|
|
716
|
+
path: `${path}[${i}]`,
|
|
717
|
+
external,
|
|
718
|
+
}));
|
|
738
719
|
}
|
|
739
720
|
if (data !== null && typeof data === "object") {
|
|
740
721
|
const props = collectProperties(resolved);
|
|
@@ -743,7 +724,11 @@ onSubstitute, path = "") {
|
|
|
743
724
|
: undefined;
|
|
744
725
|
const result = {};
|
|
745
726
|
for (const [k, v] of Object.entries(data)) {
|
|
746
|
-
result[k] = substituteCelFields(v, (props[k] ?? addlProps ?? {}), root,
|
|
727
|
+
result[k] = substituteCelFields(v, (props[k] ?? addlProps ?? {}), root, {
|
|
728
|
+
onSubstitute,
|
|
729
|
+
path: path ? `${path}.${k}` : k,
|
|
730
|
+
external,
|
|
731
|
+
});
|
|
747
732
|
}
|
|
748
733
|
return result;
|
|
749
734
|
}
|