@telorun/analyzer 0.56.1 → 0.58.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.
Files changed (133) hide show
  1. package/dist/analyzer.d.ts +5 -0
  2. package/dist/analyzer.d.ts.map +1 -1
  3. package/dist/analyzer.js +232 -94
  4. package/dist/cel-environment.d.ts.map +1 -1
  5. package/dist/cel-environment.js +6 -3
  6. package/dist/definition-registry.d.ts +5 -0
  7. package/dist/definition-registry.d.ts.map +1 -1
  8. package/dist/definition-registry.js +9 -0
  9. package/dist/index.d.ts +14 -4
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +8 -3
  12. package/dist/invocation-contract.d.ts +21 -13
  13. package/dist/invocation-contract.d.ts.map +1 -1
  14. package/dist/invocation-contract.js +43 -46
  15. package/dist/loaded-types.d.ts +13 -0
  16. package/dist/loaded-types.d.ts.map +1 -1
  17. package/dist/manifest-loader.d.ts +8 -1
  18. package/dist/manifest-loader.d.ts.map +1 -1
  19. package/dist/manifest-loader.js +33 -6
  20. package/dist/manifest-visitor.d.ts +4 -0
  21. package/dist/manifest-visitor.d.ts.map +1 -1
  22. package/dist/manifest-visitor.js +3 -3
  23. package/dist/migrations/driver.d.ts +69 -0
  24. package/dist/migrations/driver.d.ts.map +1 -0
  25. package/dist/migrations/driver.js +200 -0
  26. package/dist/migrations/entries/index.d.ts +3 -0
  27. package/dist/migrations/entries/index.d.ts.map +1 -0
  28. package/dist/migrations/entries/index.js +9 -0
  29. package/dist/migrations/entries/normalize-value-types.json +48 -0
  30. package/dist/migrations/entries/ref-slot-scalar-type.json +20 -0
  31. package/dist/migrations/entry-data.d.ts +25 -0
  32. package/dist/migrations/entry-data.d.ts.map +1 -0
  33. package/dist/migrations/entry-data.js +171 -0
  34. package/dist/migrations/index.d.ts +22 -0
  35. package/dist/migrations/index.d.ts.map +1 -0
  36. package/dist/migrations/index.js +19 -0
  37. package/dist/migrations/match.d.ts +162 -0
  38. package/dist/migrations/match.d.ts.map +1 -0
  39. package/dist/migrations/match.js +295 -0
  40. package/dist/migrations/patch.d.ts +68 -0
  41. package/dist/migrations/patch.d.ts.map +1 -0
  42. package/dist/migrations/patch.js +236 -0
  43. package/dist/migrations/provenance.d.ts +25 -0
  44. package/dist/migrations/provenance.d.ts.map +1 -0
  45. package/dist/migrations/provenance.js +118 -0
  46. package/dist/migrations/registry.d.ts +35 -0
  47. package/dist/migrations/registry.d.ts.map +1 -0
  48. package/dist/migrations/registry.js +35 -0
  49. package/dist/migrations/report.d.ts +28 -0
  50. package/dist/migrations/report.d.ts.map +1 -0
  51. package/dist/migrations/report.js +144 -0
  52. package/dist/migrations/types.d.ts +115 -0
  53. package/dist/migrations/types.d.ts.map +1 -0
  54. package/dist/migrations/types.js +24 -0
  55. package/dist/migrations/yaml-edit.d.ts +21 -0
  56. package/dist/migrations/yaml-edit.d.ts.map +1 -0
  57. package/dist/migrations/yaml-edit.js +245 -0
  58. package/dist/module-file-claims.d.ts +65 -0
  59. package/dist/module-file-claims.d.ts.map +1 -0
  60. package/dist/module-file-claims.js +106 -0
  61. package/dist/parse-loaded-file.d.ts +8 -0
  62. package/dist/parse-loaded-file.d.ts.map +1 -1
  63. package/dist/parse-loaded-file.js +22 -13
  64. package/dist/resolve-schema-type-refs.d.ts +29 -12
  65. package/dist/resolve-schema-type-refs.d.ts.map +1 -1
  66. package/dist/resolve-schema-type-refs.js +89 -16
  67. package/dist/schema-compat.d.ts +35 -9
  68. package/dist/schema-compat.d.ts.map +1 -1
  69. package/dist/schema-compat.js +181 -54
  70. package/dist/schema-region.d.ts +33 -0
  71. package/dist/schema-region.d.ts.map +1 -0
  72. package/dist/schema-region.js +45 -0
  73. package/dist/types.d.ts +51 -0
  74. package/dist/types.d.ts.map +1 -1
  75. package/dist/types.js +6 -0
  76. package/dist/validate-cel-context.d.ts.map +1 -1
  77. package/dist/validate-cel-context.js +29 -3
  78. package/dist/validate-include-placement.d.ts +26 -0
  79. package/dist/validate-include-placement.d.ts.map +1 -0
  80. package/dist/validate-include-placement.js +67 -0
  81. package/dist/validate-step-inputs.d.ts +8 -1
  82. package/dist/validate-step-inputs.d.ts.map +1 -1
  83. package/dist/validate-step-inputs.js +47 -2
  84. package/dist/validate-throws-coverage.d.ts.map +1 -1
  85. package/dist/validate-throws-coverage.js +15 -12
  86. package/dist/validate-value-type-slots.d.ts +43 -0
  87. package/dist/validate-value-type-slots.d.ts.map +1 -0
  88. package/dist/validate-value-type-slots.js +142 -0
  89. package/dist/value-type-keyword.d.ts +60 -0
  90. package/dist/value-type-keyword.d.ts.map +1 -0
  91. package/dist/value-type-keyword.js +119 -0
  92. package/dist/yaml-source-edit.d.ts +56 -0
  93. package/dist/yaml-source-edit.d.ts.map +1 -0
  94. package/dist/yaml-source-edit.js +93 -0
  95. package/package.json +4 -3
  96. package/src/analyzer.ts +276 -129
  97. package/src/cel-environment.ts +6 -3
  98. package/src/definition-registry.ts +10 -0
  99. package/src/index.ts +31 -3
  100. package/src/invocation-contract.ts +43 -48
  101. package/src/loaded-types.ts +13 -0
  102. package/src/manifest-loader.ts +37 -6
  103. package/src/manifest-visitor.ts +11 -3
  104. package/src/migrations/driver.ts +262 -0
  105. package/src/migrations/entries/index.ts +10 -0
  106. package/src/migrations/entries/normalize-value-types.json +48 -0
  107. package/src/migrations/entries/ref-slot-scalar-type.json +20 -0
  108. package/src/migrations/entry-data.ts +207 -0
  109. package/src/migrations/index.ts +22 -0
  110. package/src/migrations/match.ts +382 -0
  111. package/src/migrations/patch.ts +265 -0
  112. package/src/migrations/provenance.ts +167 -0
  113. package/src/migrations/registry.ts +40 -0
  114. package/src/migrations/report.ts +169 -0
  115. package/src/migrations/types.ts +144 -0
  116. package/src/migrations/yaml-edit.ts +260 -0
  117. package/src/module-file-claims.ts +168 -0
  118. package/src/parse-loaded-file.ts +31 -12
  119. package/src/resolve-schema-type-refs.ts +93 -16
  120. package/src/schema-compat.ts +218 -62
  121. package/src/schema-region.ts +46 -0
  122. package/src/types.ts +54 -0
  123. package/src/validate-cel-context.ts +36 -3
  124. package/src/validate-include-placement.ts +70 -0
  125. package/src/validate-step-inputs.ts +56 -1
  126. package/src/validate-throws-coverage.ts +16 -11
  127. package/src/validate-value-type-slots.ts +182 -0
  128. package/src/value-type-keyword.ts +135 -0
  129. package/src/yaml-source-edit.ts +106 -0
  130. package/dist/binary-slot.d.ts +0 -39
  131. package/dist/binary-slot.d.ts.map +0 -1
  132. package/dist/binary-slot.js +0 -58
  133. package/src/binary-slot.ts +0 -71
@@ -1,6 +1,7 @@
1
1
  import { defaultCustomTags } from "@telorun/templating";
2
2
  import { parseAllDocuments } from "yaml";
3
3
  import { buildCelEnvironment } from "./cel-environment.js";
4
+ import { migrateManifests, NO_MIGRATIONS } from "./migrations/driver.js";
4
5
  import { buildDocumentPositions } from "./position-metadata.js";
5
6
  import { precompileDoc } from "./precompile.js";
6
7
  import { documentToAst } from "./yaml-ast.js";
@@ -42,27 +43,34 @@ export function parseLoadedFile(source, requestedUrl, text, options) {
42
43
  });
43
44
  }
44
45
  });
45
- const manifests = [];
46
- let env;
47
- for (const doc of documents) {
46
+ const manifests = documents.map((doc) => {
48
47
  const raw = doc.toJSON();
49
- if (raw === null || raw === undefined) {
50
- manifests.push(null);
51
- continue;
52
- }
53
- if (options?.compile) {
48
+ return raw === null || raw === undefined ? null : raw;
49
+ });
50
+ // The migration phase, immediately after parse. It runs BEFORE precompile so
51
+ // matchers see the values the author wrote rather than `CompiledValue`
52
+ // wrappers, and — through the loader — before `desugarLoadedFile`, so a rule
53
+ // only ever matches author-written nodes: a synthetic Telo.Import manifest
54
+ // has no YAML document to edit, records a path the file never had, and
55
+ // carries its `variables` / `secrets` by reference from the module doc, so a
56
+ // match inside one would apply twice.
57
+ const migrations = options?.migrate
58
+ ? migrateManifests({ source, manifests, entries: options.migrations })
59
+ : NO_MIGRATIONS;
60
+ let env;
61
+ if (options?.compile) {
62
+ for (let i = 0; i < manifests.length; i++) {
63
+ const raw = manifests[i];
64
+ if (raw === null)
65
+ continue;
54
66
  env ??= options.celEnv ?? buildCelEnvironment();
55
67
  try {
56
- const compiled = precompileDoc(raw, env);
57
- manifests.push(compiled);
68
+ manifests[i] = precompileDoc(raw, env);
58
69
  }
59
70
  catch (error) {
60
71
  throw new Error(`Failed to compile manifest in ${source}: ${error instanceof Error ? error.message : String(error)}`);
61
72
  }
62
73
  }
63
- else {
64
- manifests.push(raw);
65
- }
66
74
  }
67
75
  return {
68
76
  source,
@@ -73,5 +81,6 @@ export function parseLoadedFile(source, requestedUrl, text, options) {
73
81
  manifests,
74
82
  positions,
75
83
  parseErrors,
84
+ migrations,
76
85
  };
77
86
  }
@@ -1,20 +1,37 @@
1
1
  import type { ResourceManifest } from "@telorun/sdk";
2
2
  import type { AliasResolver } from "./alias-resolver.js";
3
3
  /**
4
- * Rewrites import-scoped schema references in place. A `$ref` of the form
5
- * `telo://<authority>/<typeName>` names a `Type.JsonSchema` (or any `Telo.Type`)
6
- * reached through an import: `telo://Self/<type>` for the declaring module's own
7
- * type, `telo://<Alias>/<type>` for an imported module's. Each authority is
8
- * resolved to the owning module's name and the ref is rewritten to the canonical
9
- * `telo://<module>/<type>` the type registered its schema under.
4
+ * Rewrites schema references to their canonical, module-scoped form, in place.
10
5
  *
11
- * The version lives on the `imports:` entry, never the URI only the pinned
12
- * version is loaded, so the canonical id is version-free.
6
+ * A named shape is written with the reference tag `!ref File` for the declaring
7
+ * module's own, `!ref <Alias>.<File>` for one an imported library exports — which
8
+ * is Telo's ONE reference grammar, and `use: schema` has been in the `x-telo-ref`
9
+ * vocabulary for exactly this relation all along (*names a shape; no runtime
10
+ * instance, no edge*). Phase 2.5 has already turned the tag into `{kind, name,
11
+ * alias?}`; this pass turns that into `{ $ref: "telo:<module>/<type>" }`, the id
12
+ * the type registered its schema under.
13
13
  *
14
- * Already-canonical refs (authority is a real module name, not an alias) and
15
- * fragment-bearing built-ins (`telo://manifest#/$defs/ResourceRef`) are left
16
- * untouched: the former because the authority resolves to nothing, the latter
17
- * because they don't match the `authority/type` grammar.
14
+ * WHY NORMALIZE RATHER THAN RESOLVE. Substituting the shape itself would inline
15
+ * it, which changes schema identity — the compiled-validator cache is keyed on it
16
+ * and would make a self-recursive shape inexpressible. Keeping a REFERENCE is
17
+ * what every validator wants, and it is not an AJV concern: a Rust validator
18
+ * wants a registered id just as much. So the tag is the authoring surface and the
19
+ * canonical `$ref` is the internal form, exactly as `resolveRefSentinels` and
20
+ * `resolveSchemaRefKinds` already split authoring sugar from canonical form.
21
+ *
22
+ * ALIAS SCOPE IS WHAT THE CANONICAL FORM CARRIES. The authority is resolved in
23
+ * the DECLARING module's scope, so the id names the owning module and two
24
+ * libraries declaring a shape of the same name stay distinct. A downstream
25
+ * resolver reads the module off the id instead of matching a bare name, which is
26
+ * how an alias used to get silently dropped.
27
+ *
28
+ * The legacy authoring spelling `$ref: "telo://<authority>/<type>"` is resolved
29
+ * the same way, since a published artifact carries it. The version lives on the
30
+ * `imports:` entry, never the URI — only the pinned version is loaded, so the
31
+ * canonical id is version-free. Already-canonical refs and fragment-bearing
32
+ * built-ins (`telo://manifest#/$defs/ResourceRef`) are left untouched: the former
33
+ * because the authority resolves to nothing, the latter because they do not match
34
+ * the `authority/type` grammar.
18
35
  */
19
36
  export declare function resolveSchemaTypeRefs(resources: ResourceManifest[], aliases?: AliasResolver, aliasesByModule?: Map<string, AliasResolver>): void;
20
37
  //# sourceMappingURL=resolve-schema-type-refs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolve-schema-type-refs.d.ts","sourceRoot":"","sources":["../src/resolve-schema-type-refs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAKzD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,gBAAgB,EAAE,EAC7B,OAAO,CAAC,EAAE,aAAa,EACvB,eAAe,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,GAC3C,IAAI,CAyBN"}
1
+ {"version":3,"file":"resolve-schema-type-refs.d.ts","sourceRoot":"","sources":["../src/resolve-schema-type-refs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAKzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,gBAAgB,EAAE,EAC7B,OAAO,CAAC,EAAE,aAAa,EACvB,eAAe,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,GAC3C,IAAI,CA6DN"}
@@ -2,28 +2,51 @@ import { canonicalTypeSchemaId, parseTeloTypeRef } from "@telorun/sdk";
2
2
  /** Schema-bearing fields on a Telo.Definition / Telo.Type resource. */
3
3
  const SCHEMA_FIELDS = ["schema", "inputType", "outputType"];
4
4
  /**
5
- * Rewrites import-scoped schema references in place. A `$ref` of the form
6
- * `telo://<authority>/<typeName>` names a `Type.JsonSchema` (or any `Telo.Type`)
7
- * reached through an import: `telo://Self/<type>` for the declaring module's own
8
- * type, `telo://<Alias>/<type>` for an imported module's. Each authority is
9
- * resolved to the owning module's name and the ref is rewritten to the canonical
10
- * `telo://<module>/<type>` the type registered its schema under.
5
+ * Rewrites schema references to their canonical, module-scoped form, in place.
11
6
  *
12
- * The version lives on the `imports:` entry, never the URI only the pinned
13
- * version is loaded, so the canonical id is version-free.
7
+ * A named shape is written with the reference tag `!ref File` for the declaring
8
+ * module's own, `!ref <Alias>.<File>` for one an imported library exports — which
9
+ * is Telo's ONE reference grammar, and `use: schema` has been in the `x-telo-ref`
10
+ * vocabulary for exactly this relation all along (*names a shape; no runtime
11
+ * instance, no edge*). Phase 2.5 has already turned the tag into `{kind, name,
12
+ * alias?}`; this pass turns that into `{ $ref: "telo:<module>/<type>" }`, the id
13
+ * the type registered its schema under.
14
14
  *
15
- * Already-canonical refs (authority is a real module name, not an alias) and
16
- * fragment-bearing built-ins (`telo://manifest#/$defs/ResourceRef`) are left
17
- * untouched: the former because the authority resolves to nothing, the latter
18
- * because they don't match the `authority/type` grammar.
15
+ * WHY NORMALIZE RATHER THAN RESOLVE. Substituting the shape itself would inline
16
+ * it, which changes schema identity — the compiled-validator cache is keyed on it
17
+ * and would make a self-recursive shape inexpressible. Keeping a REFERENCE is
18
+ * what every validator wants, and it is not an AJV concern: a Rust validator
19
+ * wants a registered id just as much. So the tag is the authoring surface and the
20
+ * canonical `$ref` is the internal form, exactly as `resolveRefSentinels` and
21
+ * `resolveSchemaRefKinds` already split authoring sugar from canonical form.
22
+ *
23
+ * ALIAS SCOPE IS WHAT THE CANONICAL FORM CARRIES. The authority is resolved in
24
+ * the DECLARING module's scope, so the id names the owning module and two
25
+ * libraries declaring a shape of the same name stay distinct. A downstream
26
+ * resolver reads the module off the id instead of matching a bare name, which is
27
+ * how an alias used to get silently dropped.
28
+ *
29
+ * The legacy authoring spelling `$ref: "telo://<authority>/<type>"` is resolved
30
+ * the same way, since a published artifact carries it. The version lives on the
31
+ * `imports:` entry, never the URI — only the pinned version is loaded, so the
32
+ * canonical id is version-free. Already-canonical refs and fragment-bearing
33
+ * built-ins (`telo://manifest#/$defs/ResourceRef`) are left untouched: the former
34
+ * because the authority resolves to nothing, the latter because they do not match
35
+ * the `authority/type` grammar.
19
36
  */
20
37
  export function resolveSchemaTypeRefs(resources, aliases, aliasesByModule) {
21
- const walk = (value, resolveAuthority) => {
38
+ const walk = (value, resolveAuthority, ownModule,
39
+ // The type field's OWN value is a declared reference slot (`x-telo-ref:
40
+ // Telo.Type`), with its own reference validation and its own editor picker.
41
+ // Only what sits INSIDE it is schema, and only schema is this pass's to
42
+ // canonicalize — rewriting the slot itself would hand the reference checker
43
+ // a shape it is right to reject.
44
+ isSlotRoot) => {
22
45
  if (value === null || typeof value !== "object")
23
46
  return;
24
47
  if (Array.isArray(value)) {
25
48
  for (const item of value)
26
- walk(item, resolveAuthority);
49
+ walk(item, resolveAuthority, ownModule, false);
27
50
  return;
28
51
  }
29
52
  const obj = value;
@@ -33,15 +56,65 @@ export function resolveSchemaTypeRefs(resources, aliases, aliasesByModule) {
33
56
  if (module)
34
57
  obj.$ref = canonicalTypeSchemaId(module, parsed.typeName);
35
58
  }
59
+ // A reference the tag left behind. Rewritten in place rather than replaced,
60
+ // so a node that carried siblings (a `title`, a `description`) keeps them —
61
+ // a `$ref` beside other keywords is ordinary JSON Schema.
62
+ const named = resolvedRefInSchema(obj);
63
+ if (named) {
64
+ const module = named.alias === undefined ? ownModule : resolveAuthority(named.alias);
65
+ // An unresolvable alias is left exactly as written: `validateReferences`
66
+ // is what reports a reference that names nothing, and guessing a module
67
+ // here would turn a typo into a `$ref` that resolves to the wrong shape.
68
+ if (module) {
69
+ const canonical = canonicalTypeSchemaId(module, named.name);
70
+ if (isSlotRoot) {
71
+ // At the slot root the reference STAYS a reference — the canonical id
72
+ // is stamped beside it. That is what makes the resolver alias-aware
73
+ // here: it reads the module off the id instead of matching a bare
74
+ // `metadata.name` across a flattened list, where two libraries
75
+ // declaring a shape of the same name collide silently.
76
+ obj.$ref = canonical;
77
+ }
78
+ else {
79
+ delete obj.kind;
80
+ delete obj.name;
81
+ delete obj.alias;
82
+ obj.$ref = canonical;
83
+ }
84
+ }
85
+ }
36
86
  for (const key of Object.keys(obj))
37
- walk(obj[key], resolveAuthority);
87
+ walk(obj[key], resolveAuthority, ownModule, false);
38
88
  };
39
89
  for (const r of resources) {
40
90
  const ownModule = r.metadata?.module;
41
91
  const resolver = (ownModule ? aliasesByModule?.get(ownModule) : undefined) ?? aliases;
42
92
  const resolveAuthority = (authority) => authority === "Self" ? ownModule : resolver?.moduleForAlias(authority);
43
93
  for (const field of SCHEMA_FIELDS) {
44
- walk(r[field], resolveAuthority);
94
+ walk(r[field], resolveAuthority, ownModule, true);
45
95
  }
46
96
  }
47
97
  }
98
+ /**
99
+ * A resolved `!ref` sitting where a schema belongs, or null.
100
+ *
101
+ * Recognised structurally: Phase 2.5 writes `{kind, name, alias?}` and nothing
102
+ * else, and a node carrying JSON Schema keywords is a schema that happens to be
103
+ * beside one rather than a reference. Being conservative here is the safe
104
+ * direction — a node this declines to rewrite stays a reference for
105
+ * `validateReferences` to judge, while one it rewrote wrongly would silently
106
+ * become a different shape.
107
+ */
108
+ function resolvedRefInSchema(obj) {
109
+ if (typeof obj.kind !== "string" || typeof obj.name !== "string")
110
+ return null;
111
+ for (const key of Object.keys(obj)) {
112
+ // `$ref` is allowed so the pass is idempotent at a slot root, where the id
113
+ // is stamped BESIDE the reference rather than replacing it.
114
+ if (key !== "kind" && key !== "name" && key !== "alias" && key !== "$ref")
115
+ return null;
116
+ }
117
+ return typeof obj.alias === "string"
118
+ ? { name: obj.name, alias: obj.alias }
119
+ : { name: obj.name };
120
+ }
@@ -12,10 +12,29 @@ export interface CompatibilityResult {
12
12
  compatible: boolean;
13
13
  issues: string[];
14
14
  }
15
- /** Conservative structural JSON Schema compatibility check.
16
- * Only flags definite mismatches: missing required fields and primitive type conflicts.
17
- * Ambiguous cases (anyOf/oneOf/etc.) are treated as compatible. */
18
- export declare function checkSchemaCompatibility(source: Record<string, any>, target: Record<string, any>): CompatibilityResult;
15
+ /**
16
+ * Conservative structural JSON Schema compatibility check is a value shaped
17
+ * like `source` acceptable where `target` is declared?
18
+ *
19
+ * COVARIANT, because the values this compares are consumed by reading: a
20
+ * narrower element satisfies a slot declaring a wider one. Only DEFINITE
21
+ * mismatches are flagged — a missing required field, a primitive type conflict,
22
+ * a disagreeing type argument. Anything ambiguous (`anyOf` / `oneOf` / `allOf`,
23
+ * an absent `type`, an undeclared argument) is treated as compatible, so an
24
+ * unmigrated producer and consumer keep checking exactly as they did.
25
+ *
26
+ * The traversal is written here rather than reused: the function this replaced
27
+ * compared only `type` for the names in `target.required` and descended only
28
+ * into objects, so a stream of arrays of strings and a stream of arrays of
29
+ * integers both read as `array` and passed — leaving argument checking inert on
30
+ * exactly the nested shapes it exists for. What survives from it is its posture.
31
+ *
32
+ * `resolveRef` sees through a named shape. Declaring a shape once and
33
+ * referencing it is the sanctioned way to reuse one, so without it two such
34
+ * arguments present as opaque nodes carrying no information — the same reason
35
+ * {@link withLiveValuesSkipped} takes one.
36
+ */
37
+ export declare function checkSchemaCompatibility(source: Record<string, any>, target: Record<string, any>, resolveRef?: (ref: string) => Record<string, any> | undefined): CompatibilityResult;
19
38
  export declare function formatSingleError(err: any): string;
20
39
  export declare function formatAjvErrors(errors: any[] | null | undefined): string;
21
40
  /** A schema validation issue with a dotted-path pointer to the offending field. */
@@ -36,14 +55,21 @@ export declare function navigateJsonPointer(schema: unknown, pointer: string): u
36
55
  * Returns `undefined` if any segment cannot be resolved. */
37
56
  export declare function navigateSchemaToExprPath(schema: Record<string, any>, path: string): Record<string, any> | undefined;
38
57
  /**
39
- * Recognized `x-telo-type` value brands and the CEL primitive each refines.
58
+ * Every `json`-represented value type's CEL brand → the primitive it refines.
59
+ *
40
60
  * A brand is a nominal type the analyzer registers (see cel-environment.ts) so
41
- * structurally-identical values (a `TcpPort` and a `UdpPort` are both integers)
42
- * stay distinct for static wiring checks. Brands carry no runtime effect — the
43
- * value flows as its base type. Add new brands here (e.g. `Url: "string"`).
61
+ * structurally-identical values (a `Telo.TcpPort` and a `Telo.UdpPort` are both
62
+ * integers) stay distinct for static wiring checks. Brands carry no runtime
63
+ * effect — the value flows as its base type.
64
+ *
65
+ * DERIVED from the value-type vocabulary, never hand-written: a new brand is a
66
+ * new entry file, and a table here would be a second place to edit that could
67
+ * silently disagree with the one the runtime reads.
44
68
  */
45
69
  export declare const VALUE_BRAND_BASE: Record<string, string>;
46
- /** Read a recognized `x-telo-type` brand off a schema, or undefined. */
70
+ /** Read a `json`-represented value type's brand off a schema, or undefined.
71
+ * An `instance` type is not a brand — it replaces the JSON layer rather than
72
+ * refining it, so it carries its binding's CEL type instead. */
47
73
  export declare function brandOfSchema(schema: Record<string, any> | undefined): string | undefined;
48
74
  /** Map a JSON Schema type annotation to a CEL type string. */
49
75
  export declare function jsonSchemaToCelType(schema: Record<string, any> | undefined): string;
@@ -1 +1 @@
1
- {"version":3,"file":"schema-compat.d.ts","sourceRoot":"","sources":["../src/schema-compat.ts"],"names":[],"mappings":"AAKA,QAAA,MAAM,GAAG,KAA0C,CAAC;AAEpD;;;;;;;mCAOmC;AACnC,wBAAgB,SAAS,IAAI,YAAY,CAAC,OAAO,GAAG,CAAC,CAWpD;AAKD,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,OAAO,CAAC;IACpB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED;;oEAEoE;AACpE,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC3B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC1B,mBAAmB,CAIrB;AAiDD,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,CAelD;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAGxE;AAuBD,mFAAmF;AACnF,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,iFAAiF;IACjF,IAAI,EAAE,MAAM,CAAC;CACd;AAaD,0GAA0G;AAC1G,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,WAAW,EAAE,CA2B/F;AAED;qFACqF;AACrF,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAQ7E;AAED;;;;6DAI6D;AAC7D,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,MAAM,CAAC,MAAM,EAA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;;6DAQ6D;AAC7D,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,EACrC,IAAI,SAAK,GACR,OAAO,CAiET"}
@@ -1,7 +1,8 @@
1
1
  import AjvModule from "ajv";
2
2
  import addFormats from "ajv-formats";
3
- import { isRefSentinel, isTaggedSentinel, ManifestRootSchema, normalizeRefSlots } from "@telorun/templating";
4
- import { binaryKeyword, isBinarySlot } from "./binary-slot.js";
3
+ import { isRefSentinel, isTaggedSentinel, ManifestRootSchema, producedTypeOf, } from "@telorun/templating";
4
+ import { celBaseOfValueType, celTypeOfValueType, readValueTypeSlot, valueBrandBases, valueTypeOf, valueTypePlaceholder, } from "@telorun/sdk";
5
+ import { registerTeloKeywords } from "./value-type-keyword.js";
5
6
  const Ajv = AjvModule.default ?? AjvModule;
6
7
  /** Creates a configured AJV instance (allErrors, strict: false, with formats).
7
8
  * Also registers the kernel manifest root schema under `telo://manifest` so
@@ -16,53 +17,144 @@ export function createAjv() {
16
17
  addFormats.default
17
18
  ? addFormats.default(instance)
18
19
  : addFormats(instance);
19
- // Bytes have no JSON Schema type, so the annotation carries the check. Registered
20
- // here and in the kernel's validators from one definition, so a literal at a byte
21
- // slot is rejected statically and at dispatch by the identical rule.
22
- instance.addKeyword(binaryKeyword());
20
+ // One registration site for every Telo keyword the annotations as no-ops and
21
+ // `x-telo-type` as the one that checks. Registered here and in the kernel's
22
+ // validators from one definition, so a literal at an instance-typed slot is
23
+ // rejected statically and at dispatch by the identical rule.
24
+ registerTeloKeywords(instance);
23
25
  instance.addSchema(ManifestRootSchema);
24
26
  return instance;
25
27
  }
26
28
  const ajv = createAjv();
27
29
  const compiledSchemaValidators = new WeakMap();
28
- /** Conservative structural JSON Schema compatibility check.
29
- * Only flags definite mismatches: missing required fields and primitive type conflicts.
30
- * Ambiguous cases (anyOf/oneOf/etc.) are treated as compatible. */
31
- export function checkSchemaCompatibility(source, target) {
30
+ /**
31
+ * Conservative structural JSON Schema compatibility check is a value shaped
32
+ * like `source` acceptable where `target` is declared?
33
+ *
34
+ * COVARIANT, because the values this compares are consumed by reading: a
35
+ * narrower element satisfies a slot declaring a wider one. Only DEFINITE
36
+ * mismatches are flagged — a missing required field, a primitive type conflict,
37
+ * a disagreeing type argument. Anything ambiguous (`anyOf` / `oneOf` / `allOf`,
38
+ * an absent `type`, an undeclared argument) is treated as compatible, so an
39
+ * unmigrated producer and consumer keep checking exactly as they did.
40
+ *
41
+ * The traversal is written here rather than reused: the function this replaced
42
+ * compared only `type` for the names in `target.required` and descended only
43
+ * into objects, so a stream of arrays of strings and a stream of arrays of
44
+ * integers both read as `array` and passed — leaving argument checking inert on
45
+ * exactly the nested shapes it exists for. What survives from it is its posture.
46
+ *
47
+ * `resolveRef` sees through a named shape. Declaring a shape once and
48
+ * referencing it is the sanctioned way to reuse one, so without it two such
49
+ * arguments present as opaque nodes carrying no information — the same reason
50
+ * {@link withLiveValuesSkipped} takes one.
51
+ */
52
+ export function checkSchemaCompatibility(source, target, resolveRef) {
32
53
  const issues = [];
33
- checkObject(source, target, "", issues);
54
+ compare(source, target, "", issues, resolveRef, new Set());
34
55
  return { compatible: issues.length === 0, issues };
35
56
  }
36
- function checkObject(source, target, path, issues) {
37
- const targetRequired = target.required ?? [];
57
+ function deref(schema, resolveRef) {
58
+ if (!resolveRef || typeof schema.$ref !== "string")
59
+ return schema;
60
+ return resolveRef(schema.$ref) ?? schema;
61
+ }
62
+ function compare(rawSource, rawTarget, path, issues, resolveRef, seen) {
63
+ if (!rawSource || !rawTarget || typeof rawSource !== "object" || typeof rawTarget !== "object") {
64
+ return;
65
+ }
66
+ // A recursive shape reached through the same pair of references twice is the
67
+ // same question again; answering it once terminates and loses nothing.
68
+ //
69
+ // The key is the REFERENCE PAIR and deliberately not the path. A path grows on
70
+ // every descent, so a key containing it is new every time and the guard never
71
+ // fires — which is a stack overflow on the first self-referential shape, taking
72
+ // every other diagnostic in the file with it. It also has to be this way to be
73
+ // correct rather than merely terminating: comparing two schemas gives the same
74
+ // answer wherever they are reached from, so the second visit has nothing to add.
75
+ if (typeof rawSource.$ref === "string" && typeof rawTarget.$ref === "string") {
76
+ const key = `${rawSource.$ref}|${rawTarget.$ref}`;
77
+ if (seen.has(key))
78
+ return;
79
+ seen.add(key);
80
+ }
81
+ const source = deref(rawSource, resolveRef);
82
+ const target = deref(rawTarget, resolveRef);
83
+ // Value types first: an `instance` representation has no JSON `type` to
84
+ // compare, so its identity IS the comparison — and its arguments are where the
85
+ // real information lives.
86
+ const sourceType = readValueTypeSlot(source);
87
+ const targetType = readValueTypeSlot(target);
88
+ if (sourceType && targetType) {
89
+ if (sourceType.name !== targetType.name) {
90
+ issues.push(`${path || "/"}: value type mismatch — source is '${sourceType.name}', target expects '${targetType.name}'`);
91
+ return;
92
+ }
93
+ for (const [argument, targetArg] of Object.entries(targetType.args)) {
94
+ const sourceArg = sourceType.args[argument];
95
+ // An omitted argument is *any*, in BOTH directions. That is what keeps a
96
+ // bare `Telo.Stream` flowing into a typed slot and vice versa, so nothing
97
+ // that does not declare its element is forced to.
98
+ if (sourceArg === undefined)
99
+ continue;
100
+ compare(sourceArg, targetArg, `${path}<${argument}>`, issues, resolveRef, seen);
101
+ }
102
+ return;
103
+ }
104
+ // One side declares a value type and the other does not. A `json`
105
+ // representation refines a base type, so it is compared through that base — a
106
+ // `Telo.TcpPort` into a plain `integer` slot is gradual typing working. An
107
+ // `instance` is not JSON at all, so ANY declared JSON type on the other side is
108
+ // a definite conflict; a side declaring no type at all is still saying nothing
109
+ // and stays compatible.
110
+ if (Boolean(sourceType) !== Boolean(targetType)) {
111
+ const declared = (sourceType ?? targetType);
112
+ const other = sourceType ? target : source;
113
+ if (declared.entry && typeof other.type === "string") {
114
+ const base = celBaseOfValueType(declared.entry);
115
+ const asJson = base === undefined ? undefined : declared.entry.base;
116
+ if (asJson !== other.type) {
117
+ issues.push(`${path || "/"}: value type mismatch — ${sourceType ? "source is" : "target expects"} '${declared.name}', ${sourceType ? "target expects" : "source is"} '${other.type}'`);
118
+ return;
119
+ }
120
+ }
121
+ }
122
+ // Only flag definite primitive type clashes; an absent or union `type` says
123
+ // too little to judge.
124
+ if (typeof source.type === "string" &&
125
+ typeof target.type === "string" &&
126
+ source.type !== target.type) {
127
+ issues.push(`${path || "/"}: type mismatch — source is '${source.type}', target expects '${target.type}'`);
128
+ return;
129
+ }
130
+ if (source.anyOf || source.oneOf || source.allOf)
131
+ return;
132
+ if (target.anyOf || target.oneOf || target.allOf)
133
+ return;
134
+ // An array's element, which the old comparison never looked at — so every
135
+ // nested shape passed regardless of what it contained.
136
+ if (target.items && source.items) {
137
+ compare(source.items, target.items, `${path}[]`, issues, resolveRef, seen);
138
+ }
139
+ const targetRequired = Array.isArray(target.required) ? target.required : [];
38
140
  const sourceProps = source.properties ?? {};
39
141
  const targetProps = target.properties ?? {};
40
142
  for (const field of targetRequired) {
41
143
  if (!(field in sourceProps)) {
144
+ // Only when the source describes an object at all: a schema with no
145
+ // `properties` is saying nothing about its shape, not saying it is empty.
146
+ if (source.properties === undefined)
147
+ continue;
42
148
  issues.push(`${path}/${field}: required by target but missing from source`);
43
149
  continue;
44
150
  }
45
151
  const srcProp = sourceProps[field];
46
152
  const tgtProp = targetProps[field];
47
153
  if (tgtProp && srcProp) {
48
- checkProperty(srcProp, tgtProp, `${path}/${field}`, issues);
154
+ compare(srcProp, tgtProp, `${path}/${field}`, issues, resolveRef, seen);
49
155
  }
50
156
  }
51
157
  }
52
- function checkProperty(source, target, path, issues) {
53
- // Only flag definite primitive type clashes; skip anyOf/oneOf/allOf
54
- if (source.type &&
55
- target.type &&
56
- typeof source.type === "string" &&
57
- typeof target.type === "string" &&
58
- source.type !== target.type) {
59
- issues.push(`${path}: type mismatch — source is '${source.type}', target expects '${target.type}'`);
60
- return;
61
- }
62
- if (target.type === "object" && source.type === "object") {
63
- checkObject(source, target, path, issues);
64
- }
65
- }
66
158
  export function formatSingleError(err) {
67
159
  const p = err.instancePath || "/";
68
160
  const params = err.params ?? {};
@@ -120,13 +212,8 @@ function schemaCompiles(schema) {
120
212
  export function validateAgainstSchema(data, schema) {
121
213
  let validate = compiledSchemaValidators.get(schema);
122
214
  if (!validate) {
123
- // Normalize outside the try: a fault in our own ref-slot normalization must
124
- // surface, never be mistaken for the module author's schema being malformed.
125
- // Drop the legacy scalar `type` an older published module may still pin on
126
- // its `x-telo-ref` slots so a resolved reference object validates.
127
- const normalized = normalizeRefSlots(schema);
128
215
  try {
129
- validate = ajv.compile(normalized);
216
+ validate = ajv.compile(schema);
130
217
  }
131
218
  catch (err) {
132
219
  // The normalized schema didn't compile. If the original schema is itself
@@ -198,28 +285,36 @@ export function navigateSchemaToExprPath(schema, path) {
198
285
  return current;
199
286
  }
200
287
  /**
201
- * Recognized `x-telo-type` value brands and the CEL primitive each refines.
288
+ * Every `json`-represented value type's CEL brand → the primitive it refines.
289
+ *
202
290
  * A brand is a nominal type the analyzer registers (see cel-environment.ts) so
203
- * structurally-identical values (a `TcpPort` and a `UdpPort` are both integers)
204
- * stay distinct for static wiring checks. Brands carry no runtime effect — the
205
- * value flows as its base type. Add new brands here (e.g. `Url: "string"`).
291
+ * structurally-identical values (a `Telo.TcpPort` and a `Telo.UdpPort` are both
292
+ * integers) stay distinct for static wiring checks. Brands carry no runtime
293
+ * effect — the value flows as its base type.
294
+ *
295
+ * DERIVED from the value-type vocabulary, never hand-written: a new brand is a
296
+ * new entry file, and a table here would be a second place to edit that could
297
+ * silently disagree with the one the runtime reads.
206
298
  */
207
- export const VALUE_BRAND_BASE = {
208
- TcpPort: "int",
209
- UdpPort: "int",
210
- };
211
- /** Read a recognized `x-telo-type` brand off a schema, or undefined. */
299
+ export const VALUE_BRAND_BASE = valueBrandBases();
300
+ /** Read a `json`-represented value type's brand off a schema, or undefined.
301
+ * An `instance` type is not a brand — it replaces the JSON layer rather than
302
+ * refining it, so it carries its binding's CEL type instead. */
212
303
  export function brandOfSchema(schema) {
213
- const brand = schema?.["x-telo-type"];
214
- return typeof brand === "string" && brand in VALUE_BRAND_BASE ? brand : undefined;
304
+ const entry = valueTypeOf(schema);
305
+ return entry && entry.representation === "json" ? entry.name : undefined;
215
306
  }
216
307
  /** Map a JSON Schema type annotation to a CEL type string. */
217
308
  export function jsonSchemaToCelType(schema) {
218
309
  if (!schema || typeof schema !== "object")
219
310
  return "dyn";
220
- const brand = brandOfSchema(schema);
221
- if (brand)
222
- return brand;
311
+ // A declared value type IS the type — for an `instance` representation it is
312
+ // the only thing that says so, since bytes and streams have no JSON Schema
313
+ // type at all. Before the three annotations were unified, a byte slot's
314
+ // expression typed as `dyn` because nothing here consulted `x-telo-binary`.
315
+ const entry = valueTypeOf(schema);
316
+ if (entry)
317
+ return celTypeOfValueType(entry);
223
318
  if (schema.anyOf || schema.oneOf || schema.allOf)
224
319
  return "dyn";
225
320
  if (Array.isArray(schema.type))
@@ -263,6 +358,16 @@ export function celTypeSatisfiesJsonSchema(celType, schema) {
263
358
  return fieldBrand === celType;
264
359
  celType = sourceBase;
265
360
  }
361
+ // An `instance` representation has no JSON Schema type to compare against, so
362
+ // an expression carrying its binding's CEL type is accepted on that ground
363
+ // alone. This ADDS a case and never removes one: a mismatch falls through to
364
+ // the rules below rather than being rejected here, so nothing that checks
365
+ // today stops checking, and the `bytes` row still accepts a byte expression at
366
+ // a plain `type: string` slot.
367
+ const slotEntry = valueTypeOf(schema);
368
+ if (slotEntry?.representation === "instance" && celTypeOfValueType(slotEntry) === celType) {
369
+ return true;
370
+ }
266
371
  if (!schema.type && !schema.anyOf && !schema.oneOf && !schema.allOf)
267
372
  return true;
268
373
  if (schema.anyOf || schema.oneOf || schema.allOf)
@@ -357,12 +462,16 @@ function foldedConstraints(schema) {
357
462
  }
358
463
  export function celPlaceholderForSchema(rawSchema) {
359
464
  const schema = foldedConstraints(rawSchema);
360
- // A byte slot's placeholder must BE bytes: the same keyword validates statically
361
- // and at dispatch, so a CEL leaf standing in for a runtime buffer has to satisfy
362
- // it. This is what keeps the rule single — a literal is rejected because no YAML
363
- // literal is a Uint8Array, while a value arriving by reference passes.
364
- if (isBinarySlot(schema))
365
- return new Uint8Array();
465
+ // An instance-typed slot's placeholder must BE an instance: the same keyword
466
+ // validates statically and at dispatch, so a CEL leaf standing in for a runtime
467
+ // value has to satisfy it. This is what keeps the rule single — a literal is
468
+ // rejected because no YAML literal is a byte buffer, while a value arriving by
469
+ // reference passes. The stand-in comes from the binding table, so a new
470
+ // instance type brings its own rather than adding a branch here; a `live` type
471
+ // declares none, because nothing validates it.
472
+ const placeholder = valueTypePlaceholder(schema);
473
+ if (placeholder !== undefined)
474
+ return placeholder;
366
475
  if (schema.default !== undefined)
367
476
  return schema.default;
368
477
  // An enum-constrained field needs a placeholder drawn from the enum: the
@@ -537,6 +646,24 @@ onSubstitute, path = "") {
537
646
  if (isRefSentinel(data)) {
538
647
  return data;
539
648
  }
649
+ // A tag whose produced type is a CONSTANT of the tag rather than a function of
650
+ // the slot substitutes a placeholder of THAT type: `!include-text` always
651
+ // produces a string and `!include-bytes` always produces bytes. Collapsing
652
+ // them to a slot-shaped placeholder like a CEL expression would make every
653
+ // slot accept both, so a byte embed at a `type: string` field passed
654
+ // `telo check` and failed at resource creation — and the reverse did too.
655
+ // Substituting the real type lets AJV and the `x-telo-type` keyword reject
656
+ // both directions statically, with no new diagnostic code.
657
+ //
658
+ // The engine is what says so. This used to branch on two tag names, which was
659
+ // the only place a tag's produced type was written down and it was written in
660
+ // the consumer — so a future tag producing bytes had to be added to a set here
661
+ // rather than declaring it.
662
+ if (isTaggedSentinel(data)) {
663
+ const produced = producedTypeOf(data.engine);
664
+ if (produced)
665
+ return celPlaceholderForSchema(produced);
666
+ }
540
667
  if (isTaggedSentinel(data)) {
541
668
  mark();
542
669
  return celPlaceholderForSchema(resolved);