@telorun/kernel 0.46.0 → 0.48.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 (75) hide show
  1. package/dist/application-env.d.ts +26 -11
  2. package/dist/application-env.d.ts.map +1 -1
  3. package/dist/application-env.js +36 -12
  4. package/dist/application-env.js.map +1 -1
  5. package/dist/bundle/module-manifest.d.ts +6 -0
  6. package/dist/bundle/module-manifest.d.ts.map +1 -1
  7. package/dist/bundle/module-manifest.js +4 -0
  8. package/dist/bundle/module-manifest.js.map +1 -1
  9. package/dist/controller-loaders/npm-loader.d.ts +2 -16
  10. package/dist/controller-loaders/npm-loader.d.ts.map +1 -1
  11. package/dist/controller-loaders/npm-loader.js +42 -1
  12. package/dist/controller-loaders/npm-loader.js.map +1 -1
  13. package/dist/controller-registry.d.ts +6 -6
  14. package/dist/controller-registry.d.ts.map +1 -1
  15. package/dist/controller-registry.js +14 -10
  16. package/dist/controller-registry.js.map +1 -1
  17. package/dist/controllers/module/import-controller.d.ts +0 -46
  18. package/dist/controllers/module/import-controller.d.ts.map +1 -1
  19. package/dist/controllers/module/import-controller.js +10 -30
  20. package/dist/controllers/module/import-controller.js.map +1 -1
  21. package/dist/controllers/resource-definition/abstract-controller.d.ts +0 -4
  22. package/dist/controllers/resource-definition/abstract-controller.d.ts.map +1 -1
  23. package/dist/controllers/resource-definition/abstract-controller.js +0 -4
  24. package/dist/controllers/resource-definition/abstract-controller.js.map +1 -1
  25. package/dist/controllers/resource-definition/resource-definition-controller.d.ts +0 -4
  26. package/dist/controllers/resource-definition/resource-definition-controller.d.ts.map +1 -1
  27. package/dist/controllers/resource-definition/resource-definition-controller.js +0 -4
  28. package/dist/controllers/resource-definition/resource-definition-controller.js.map +1 -1
  29. package/dist/controllers/resource-definition/resource-inherited-controller.d.ts.map +1 -1
  30. package/dist/controllers/resource-definition/resource-inherited-controller.js +0 -1
  31. package/dist/controllers/resource-definition/resource-inherited-controller.js.map +1 -1
  32. package/dist/controllers/resource-definition/resource-template-controller.d.ts.map +1 -1
  33. package/dist/controllers/resource-definition/resource-template-controller.js +0 -1
  34. package/dist/controllers/resource-definition/resource-template-controller.js.map +1 -1
  35. package/dist/kernel.d.ts.map +1 -1
  36. package/dist/kernel.js +19 -12
  37. package/dist/kernel.js.map +1 -1
  38. package/dist/module-context.d.ts +25 -4
  39. package/dist/module-context.d.ts.map +1 -1
  40. package/dist/module-context.js +28 -5
  41. package/dist/module-context.js.map +1 -1
  42. package/dist/resource-context.d.ts +3 -1
  43. package/dist/resource-context.d.ts.map +1 -1
  44. package/dist/resource-context.js +2 -0
  45. package/dist/resource-context.js.map +1 -1
  46. package/dist/transports/oci/oci-client.d.ts +5 -0
  47. package/dist/transports/oci/oci-client.d.ts.map +1 -1
  48. package/dist/transports/oci/oci-client.js.map +1 -1
  49. package/dist/transports/oci/oci-transport.d.ts +18 -0
  50. package/dist/transports/oci/oci-transport.d.ts.map +1 -1
  51. package/dist/transports/oci/oci-transport.js +41 -8
  52. package/dist/transports/oci/oci-transport.js.map +1 -1
  53. package/dist/transports/registry-transport.d.ts +7 -0
  54. package/dist/transports/registry-transport.d.ts.map +1 -1
  55. package/dist/transports/registry-transport.js +29 -10
  56. package/dist/transports/registry-transport.js.map +1 -1
  57. package/dist/transports/transport.d.ts +19 -0
  58. package/dist/transports/transport.d.ts.map +1 -1
  59. package/package.json +3 -3
  60. package/src/application-env.ts +36 -11
  61. package/src/bundle/module-manifest.ts +10 -0
  62. package/src/controller-loaders/npm-loader.ts +47 -1
  63. package/src/controller-registry.ts +14 -10
  64. package/src/controllers/module/import-controller.ts +11 -30
  65. package/src/controllers/resource-definition/abstract-controller.ts +0 -4
  66. package/src/controllers/resource-definition/resource-definition-controller.ts +0 -4
  67. package/src/controllers/resource-definition/resource-inherited-controller.ts +0 -2
  68. package/src/controllers/resource-definition/resource-template-controller.ts +0 -2
  69. package/src/kernel.ts +21 -12
  70. package/src/module-context.ts +30 -6
  71. package/src/resource-context.ts +3 -1
  72. package/src/transports/oci/oci-client.ts +5 -0
  73. package/src/transports/oci/oci-transport.ts +46 -10
  74. package/src/transports/registry-transport.ts +32 -10
  75. package/src/transports/transport.ts +20 -0
@@ -168,20 +168,26 @@ export class RegistryTransport implements Transport {
168
168
  return Array.isArray(body.versions) ? body.versions : [];
169
169
  }
170
170
 
171
- async digest(ref: string): Promise<string | null> {
172
- // Mirrors the sources' fetch-URL derivation: a direct URL points at (or
173
- // contains) the YAML file; a bare registry ref folds into the registry
174
- // layout. The digest is Telo's canonical hash over the `telo.yaml` bytes.
171
+ /** Mirrors the sources' fetch-URL derivation: a direct URL points at (or
172
+ * contains) the YAML file; a bare registry ref folds into the registry
173
+ * layout. `null` when this transport does not own the ref's shape. */
174
+ private manifestUrl(ref: string): string | null {
175
175
  const { base } = splitIntegrity(ref);
176
- let fetchUrl: string;
177
176
  if (base.startsWith("http://") || base.startsWith("https://")) {
178
- fetchUrl = base.includes(".yaml") ? base : `${base}/${DEFAULT_MANIFEST_FILENAME}`;
179
- } else if (isRegistryRef(ref)) {
177
+ return base.includes(".yaml") ? base : `${base}/${DEFAULT_MANIFEST_FILENAME}`;
178
+ }
179
+ if (isRegistryRef(ref)) {
180
180
  const { modulePath, version } = parseModuleRef(ref);
181
- fetchUrl = `${this.registryUrl.replace(/\/+$/, "")}/${modulePath}/${version}/${DEFAULT_MANIFEST_FILENAME}`;
182
- } else {
183
- return null;
181
+ return `${this.registryUrl.replace(/\/+$/, "")}/${modulePath}/${version}/${DEFAULT_MANIFEST_FILENAME}`;
184
182
  }
183
+ return null;
184
+ }
185
+
186
+ async digest(ref: string): Promise<string | null> {
187
+ // The digest is Telo's canonical hash over the `telo.yaml` bytes — the same
188
+ // value `manifestHash` returns, but absent-is-null rather than a throw.
189
+ const fetchUrl = this.manifestUrl(ref);
190
+ if (!fetchUrl) return null;
185
191
  await assertPublicEgress(fetchUrl);
186
192
  const res = await fetch(fetchUrl);
187
193
  if (res.status === 404) return null;
@@ -192,6 +198,22 @@ export class RegistryTransport implements Transport {
192
198
  return `sha256-${await sha256Base64Url(bytes)}`;
193
199
  }
194
200
 
201
+ /** Hashes the **raw response bytes**, which is exactly what `verifiedFetch`
202
+ * checks an inline `#sha256-…` pin against on the read path. */
203
+ async manifestHash(ref: string): Promise<string> {
204
+ const fetchUrl = this.manifestUrl(ref);
205
+ if (!fetchUrl) {
206
+ throw new Error(`cannot hash non-remote import '${ref}'`);
207
+ }
208
+ await assertPublicEgress(fetchUrl);
209
+ const res = await fetch(fetchUrl);
210
+ if (!res.ok) {
211
+ throw new Error(`fetch ${fetchUrl}: ${res.status} ${res.statusText}`);
212
+ }
213
+ const bytes = new Uint8Array(await res.arrayBuffer());
214
+ return `sha256-${await sha256Base64Url(bytes)}`;
215
+ }
216
+
195
217
  async fetchArtifact(ref: string): Promise<FetchedArtifact> {
196
218
  // `read` verifies the manifest bytes against the inline `#sha256-...` hash.
197
219
  const { text: manifest, source } = await this.source.read(ref);
@@ -99,6 +99,26 @@ export interface Transport {
99
99
  * digest per version and re-checks it on every track. */
100
100
  digest(ref: string): Promise<string | null>;
101
101
 
102
+ /** Telo's inline integrity hash (`sha256-<base64url>`) for the `telo.yaml`
103
+ * `ref` resolves to — the value written as a `#sha256-…` pin by `telo
104
+ * publish` and re-pinned by `telo upgrade`. Throws when the ref does not
105
+ * resolve; callers decide whether that is fatal (`--frozen`) or best-effort.
106
+ *
107
+ * This is on the interface, not computed by the caller, because *what gets
108
+ * hashed* is transport-specific and must match exactly what that transport's
109
+ * own `source.read()` verifies — otherwise a pin written at publish fails
110
+ * verification at import. HTTP/registry hash the raw response bytes;
111
+ * OCI hashes the UTF-8 encoding of the `telo.yaml` extracted from the tar
112
+ * layer. A caller cannot know which, so a caller-side scheme branch silently
113
+ * degrades the moment a transport is added — which is exactly how `oci://`
114
+ * refs came to be published unpinned.
115
+ *
116
+ * Distinct from `digest()`: that is an opaque transport-native content id for
117
+ * change detection, never written into a manifest or compared across
118
+ * transports. This is the portable, cross-transport hash Telo itself
119
+ * verifies. */
120
+ manifestHash(ref: string): Promise<string>;
121
+
102
122
  /** Push `bundle` to `destination` (a base ref / repo whose scheme this
103
123
  * transport owns), pinning the payload and writing the transport-native
104
124
  * artifact shape. Throws on failure. Used by `telo publish`. */