@polyengine/runtime 0.1.0-pre.g633468a → 0.2.0-pre.g2125a06

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/README.md CHANGED
@@ -12,10 +12,10 @@ npm install @polyengine/runtime
12
12
  ```
13
13
 
14
14
  ```js
15
- import * as api from "@polyengine/runtime/cabi";
15
+ import * as api from "@polyengine/runtime/cache";
16
16
  ```
17
17
 
18
- Entry points: `./cabi`, `./cache`, `./digest`, `./embedder`, `./exec`, `./intrinsics`, `./jspi`, `./plan`, `./shim`, `./task`.
18
+ Entry points: `./cache`, `./digest`, `./embedder`, `./plan`, `./shim`.
19
19
 
20
20
  ESM only, Node >= 22.14. Documentation, examples and the embedder API contract
21
21
  live in the [repository](https://github.com/polymorph-components/polyengine).
package/esm/cache/core.js CHANGED
@@ -57,7 +57,10 @@ import { loadEnvelope, PlanError, TranslateError } from "../plan/loader.js";
57
57
  * unwritable (issue #196): the eviction attempt that a layout mismatch
58
58
  * triggers is swallowed internally by the backend, so a read-only
59
59
  * pre-warmed cache from an older layout degrades to "always miss, always
60
- * re-translate" rather than throwing. */
60
+ * re-translate" rather than throwing.
61
+ *
62
+ * @internal — on-disk/on-Cache-API schema version, owned by the bundled
63
+ * cache backends. */
61
64
  export const CACHE_LAYOUT_VERSION = 1;
62
65
  async function sha256Hex(bytes) {
63
66
  const digest = await crypto.subtle.digest("SHA-256", bytes.slice().buffer);
@@ -36,14 +36,19 @@
36
36
  // (each has 0 or 1 resource types), but a world with 2+ resources throws a
37
37
  // clearly-labeled `DigestError` rather than silently guessing.
38
38
  // cewd = component-engine world digest, the project's pre-rebrand name; kept as an opaque wire constant.
39
+ /** @internal */
39
40
  export const CEWD_VERSION = 1;
41
+ /** @internal */
40
42
  export class DigestError extends Error {
41
43
  constructor(message) {
42
44
  super(message);
43
45
  this.name = "DigestError";
44
46
  }
45
47
  }
46
- /** Compute the canonical world digest from a loaded wire plan. */
48
+ /**
49
+ * Compute the canonical world digest from a loaded wire plan.
50
+ * @internal
51
+ */
47
52
  export async function computeWorldDigest(plan) {
48
53
  const resourceNames = buildResourceNameMap(plan);
49
54
  const imports = plan.imports.map((imp) => canonImport(plan, imp, resourceNames));
@@ -314,6 +319,7 @@ function sortByName(items) {
314
319
  * Recursively sort object keys (alphabetically) and serialize with no extra
315
320
  * whitespace. Array order is preserved verbatim — this must match
316
321
  * `crates/bindgen/src/digest.rs::canonical_string` byte-for-byte.
322
+ * @internal
317
323
  */
318
324
  export function canonicalStringify(v) {
319
325
  return JSON.stringify(sortKeysDeep(v));
package/esm/digest/mod.js CHANGED
@@ -1,3 +1,27 @@
1
- // Runtime digest handshake — public surface (docs/architecture.md §9).
1
+ /**
2
+ * The world-digest handshake (CEWD, docs/architecture.md §9): computing a
3
+ * canonical digest over a component's world types, and verifying generated
4
+ * bindings against the component they are used with.
5
+ *
6
+ * **This is not embedder API.** The entry point exists as a support surface
7
+ * for bindgen-generated bindings — whose typed `instantiate` wrapper
8
+ * verifies the digest before instantiating (contracts/embedder-api.md
9
+ * amendment A17) — and for the runtime's own internals. No host program
10
+ * should hand-write an import of this module.
11
+ *
12
+ * **Its contents are completely unstable: there is no compatibility promise
13
+ * of any kind, including within a minor line.** This is an explicit
14
+ * carve-out from the caret-honest versioning policy in README.md
15
+ * §"Consuming", which otherwise promises backward compatibility within a
16
+ * minor line — every symbol here may be renamed, reshaped, or removed in
17
+ * any release, including a patch. Regenerate your bindings when you bump
18
+ * the runtime.
19
+ *
20
+ * The supported host-facing surface is `@polyengine/runtime/embedder`
21
+ * (contracts/embedder-api.md).
22
+ *
23
+ * @module
24
+ */
25
+ // Runtime digest handshake — package entry point (docs/architecture.md §9).
2
26
  export * from "./digest.js";
3
27
  export * from "./verify.js";
@@ -12,6 +12,7 @@ import { computeWorldDigest } from "./digest.js";
12
12
  *
13
13
  * Named and catchable: `err instanceof WorldDigestMismatchError`, or
14
14
  * `err.name === "WorldDigestMismatchError"` across realms.
15
+ * @internal
15
16
  */
16
17
  export class WorldDigestMismatchError extends Error {
17
18
  name = "WorldDigestMismatchError";
@@ -43,6 +44,7 @@ export class WorldDigestMismatchError extends Error {
43
44
  * constant bindgen embedded at generation time). Returns `null` on match,
44
45
  * or a `DigestMismatch` report naming the first divergent path on
45
46
  * mismatch.
47
+ * @internal
46
48
  */
47
49
  export async function verifyWorldDigest(plan, expectedDigest) {
48
50
  const actual = await computeWorldDigest(plan);
@@ -60,6 +62,7 @@ export async function verifyWorldDigest(plan, expectedDigest) {
60
62
  * trees in parallel to name the first divergent import/export/type path.
61
63
  * `expectedCanonicalJson` is normally produced by `crates/bindgen`'s
62
64
  * `digest --json` output, or by `computeWorldDigest` on a reference plan.
65
+ * @internal
63
66
  */
64
67
  export async function diffWorldDigest(plan, expectedCanonicalJson) {
65
68
  const actual = await computeWorldDigest(plan);
@@ -16,12 +16,19 @@
16
16
  *
17
17
  * WIT labels are already lower-kebab in practice, so the first fragment needs
18
18
  * no adjustment; nothing here lower-cases anything.
19
+ * @internal — the runtime applies the naming rules; embedders write the
20
+ * resulting JS names literally (contracts/embedder-api.md §"Naming and
21
+ * casing").
19
22
  */
20
23
  export function camelCase(label) {
21
24
  const parts = label.split("-");
22
25
  return parts[0] + parts.slice(1).map(upperFirst).join("");
23
26
  }
24
- /** `tcp-socket` -> `TcpSocket` (resource class names). */
27
+ /**
28
+ * `tcp-socket` -> `TcpSocket` (resource class names).
29
+ * @internal — the runtime applies the naming rules; embedders write the
30
+ * resulting class names literally.
31
+ */
25
32
  export function pascalCase(label) {
26
33
  return label.split("-").map(upperFirst).join("");
27
34
  }
@@ -29,7 +36,11 @@ function upperFirst(s) {
29
36
  return s.length === 0 ? s : s[0].toUpperCase() + s.slice(1);
30
37
  }
31
38
  const MANGLED = /^\[([a-z-]+)\](.*)$/;
32
- /** Decode a mangled leaf name; unmangled names come back as `plain`. */
39
+ /**
40
+ * Decode a mangled leaf name; unmangled names come back as `plain`.
41
+ * @internal — leaf-name demangling, performed by the runtime and by
42
+ * bindgen-generated code.
43
+ */
33
44
  export function parseLeafName(raw) {
34
45
  const m = MANGLED.exec(raw);
35
46
  if (m === null)
@@ -10,7 +10,11 @@
10
10
  // other. It is stable per module instance and needs no permissions (unlike
11
11
  // reading deno.json, which embedder paths must never do — no fs perms).
12
12
  import { copyCensus } from "@polyengine/protocol";
13
- /** The URL of this copy of the runtime. Identity of the copy. */
13
+ /**
14
+ * The URL of this copy of the runtime. Identity of the copy.
15
+ * @internal — copy-identity constant for the A9 multi-copy diagnostics; not
16
+ * host-facing.
17
+ */
14
18
  export const COPY_URL = import.meta.url;
15
19
  /**
16
20
  * The `@polyengine/runtime` version this copy was built from, recorded in the copy
@@ -22,8 +26,10 @@ export const COPY_URL = import.meta.url;
22
26
  *
23
27
  * INVARIANT: keep in sync with `version` in runtime/deno.json — pinned by
24
28
  * runtime/tests/embedder/cross_copy_test.ts.
29
+ * @internal — copy-identity constant for the A9 multi-copy diagnostics; not
30
+ * host-facing.
25
31
  */
26
- export const RUNTIME_VERSION = "0.1.0";
32
+ export const RUNTIME_VERSION = "0.2.0";
27
33
  /**
28
34
  * Compose a cross-copy diagnostic: what was foreign, which copy is speaking,
29
35
  * the census of every copy in the graph, and the by-value remediation.
@@ -54,6 +54,8 @@ export function artifactsFromEnvelope(envelopeJson, componentBytes) {
54
54
  * world-digest handshake (contracts/digest.md) must complete before any
55
55
  * guest code runs: generated `instantiate` wrappers call this, verify the
56
56
  * plan, and only then delegate to `instantiate` below.
57
+ * @internal — bindgen-generated code only — the digest handshake needs the
58
+ * plan before instantiating (amendment A17).
57
59
  */
58
60
  export async function resolveArtifacts(src) {
59
61
  if ("plan" in src)
@@ -102,7 +104,11 @@ export async function instantiate(source, imports = {}, opts = {}) {
102
104
  });
103
105
  return instance;
104
106
  }
105
- /** Alias matching the C2 dispatch's spelling. */
107
+ /**
108
+ * Alias matching the C2 dispatch's spelling.
109
+ * @internal — alias kept for bindgen-generated code only; hosts call
110
+ * `instantiate`.
111
+ */
106
112
  export const instantiateEmbedder = instantiate;
107
113
  /**
108
114
  * Symbol-keyed, deliberately NOT re-exported from `mod.ts`: the
@@ -334,6 +334,8 @@ cls, rep, rt, owns) {
334
334
  * guest holds handles: the guest's handle is the only reference keeping a
335
335
  * host object alive across calls, and a weak map here would let it be
336
336
  * collected under the guest's feet.
337
+ * @internal — runtime-owned instance<->rep mapping; hosts supply a class, not
338
+ * a registry.
337
339
  */
338
340
  export class HostResourceRegistry {
339
341
  className;
@@ -28,6 +28,9 @@ import { ErrorContext, Future, lowerFutureSource, lowerStreamSource, Stream, } f
28
28
  * Wrappers materialized for `borrow<R>` arguments of one call. The contract:
29
29
  * "instance valid **only during the call** (retention throws)", so the scope
30
30
  * invalidates them when the call returns.
31
+ *
32
+ * @internal — the runtime materializes and invalidates these per call; a
33
+ * host never constructs or names one.
31
34
  */
32
35
  export class BorrowScope {
33
36
  #invalidate = [];
@@ -82,6 +85,8 @@ export function checkNoCollisions(key, labels, what) {
82
85
  * option** boxes as `{ kind: "some", value } | { kind: "none" }`. Only option maps
83
86
  * to `undefined`, so this is the only ambiguity, and the flag is set only when
84
87
  * descending through an option's payload — every other constructor resets it.
88
+ * @internal — value-adapter internals; the facade adapts values at the
89
+ * boundary.
85
90
  */
86
91
  export function toHost(v, t, o, scope = NO_BORROWS, inOption = false) {
87
92
  switch (t.kind) {
@@ -203,6 +208,10 @@ function single(v, o) {
203
208
  // ---------------------------------------------------------------------------
204
209
  // conventions -> internal
205
210
  // ---------------------------------------------------------------------------
211
+ /**
212
+ * @internal — value-adapter internals; the facade adapts values at the
213
+ * boundary.
214
+ */
206
215
  export function fromHost(v, t, o, inOption = false) {
207
216
  switch (t.kind) {
208
217
  case "bool":
@@ -36,6 +36,7 @@ const SEMVER = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+([0-9A-Za-z.-]+))
36
36
  *
37
37
  * Last, not first: a package name may not contain `@`, but being explicit
38
38
  * costs nothing and matches how wasmtime splits (`name.rfind('@')`).
39
+ * @internal — version-resolution internals.
39
40
  */
40
41
  export function parseInterfaceId(id) {
41
42
  const at = id.lastIndexOf("@");
@@ -45,6 +46,7 @@ export function parseInterfaceId(id) {
45
46
  const version = id.slice(at + 1);
46
47
  return { base, version, semver: parseSemver(version) };
47
48
  }
49
+ /** @internal — version-resolution internals. */
48
50
  export function parseSemver(v) {
49
51
  const m = SEMVER.exec(v);
50
52
  if (m === null)
@@ -74,6 +76,7 @@ export function parseSemver(v) {
74
76
  *
75
77
  * Build metadata is ignored for track purposes (`2.1.2+abc` -> `@2`), as
76
78
  * semver requires.
79
+ * @internal — version-resolution internals.
77
80
  */
78
81
  export function trackKey(id) {
79
82
  const p = parseInterfaceId(id);
@@ -96,6 +99,7 @@ function trackKeyOf(base, v) {
96
99
  * Note `semver::Version::parse("0.2")` fails — which is exactly why the two
97
100
  * mechanisms compose: a track key can never be mistaken for a full version,
98
101
  * and a full version never generates a track key equal to itself.
102
+ * @internal — version-resolution internals.
99
103
  */
100
104
  export function asTrackKeySpelling(id) {
101
105
  const p = parseInterfaceId(id);
@@ -115,6 +119,8 @@ export function asTrackKeySpelling(id) {
115
119
  * Only the *interface-id* keys participate: world-level bare imports live at
116
120
  * the record's top level under camelCase names and are matched by exact
117
121
  * string equality, never by version machinery.
122
+ * @internal — built by `instantiate` from the embedder's plain imports
123
+ * record; hosts never construct one.
118
124
  */
119
125
  export class ImportResolver {
120
126
  #exact = new Map();
@@ -236,7 +242,10 @@ export class ImportResolver {
236
242
  return undefined;
237
243
  }
238
244
  }
239
- /** Semver precedence, prerelease-aware (semver.org §11). */
245
+ /**
246
+ * Semver precedence, prerelease-aware (semver.org §11).
247
+ * @internal — version-resolution internals.
248
+ */
240
249
  export function compareSemver(a, b) {
241
250
  if (a.major !== b.major)
242
251
  return a.major - b.major;
@@ -11,7 +11,10 @@
11
11
  // - own/borrow `resource: <table index>` (wire) -> `ResourceTypeInfo`
12
12
  // identity tokens created per resource table at load time
13
13
  import { ResourceTypeInfo, } from "../cabi/types.js";
14
- /** Fault in the plan document itself (version/shape/reference errors). */
14
+ /**
15
+ * Fault in the plan document itself (version/shape/reference errors).
16
+ * @internal
17
+ */
15
18
  export class PlanError extends Error {
16
19
  constructor(message) {
17
20
  super(message);
@@ -26,6 +29,7 @@ export class PlanError extends Error {
26
29
  * component* and is the only failure that satisfies `assert_invalid` /
27
30
  * `assert_malformed`. `PlanError` and the other phases are failures of our
28
31
  * own pipeline and must never be scored as conformance passes.
32
+ * @internal
29
33
  */
30
34
  export class TranslateError extends Error {
31
35
  phase;
@@ -60,11 +64,13 @@ export class TranslateError extends Error {
60
64
  * producer and consumer bumped in the same commit), so v0 plans are refused
61
65
  * rather than best-effort accepted — a stale cached artifact must be a loud
62
66
  * failure, not a subtly different execution.
67
+ * @internal
63
68
  */
64
69
  export const SUPPORTED_FORMAT_VERSION = 4;
65
70
  /**
66
71
  * Validate a plan document and convert its type tables. Fails fast on
67
72
  * formatVersion mismatch per contracts/plan-format.md "Executor obligations".
73
+ * @internal
68
74
  */
69
75
  export function loadPlan(wire) {
70
76
  if (wire.formatVersion !== SUPPORTED_FORMAT_VERSION) {
@@ -206,6 +212,7 @@ export function loadPlan(wire) {
206
212
  * field of a `resource` initializer). Mirrors wasmtime
207
213
  * `Component::resource_index` (wasmtime-environ 47.0.3
208
214
  * `component/info.rs:222`).
215
+ * @internal
209
216
  */
210
217
  export function resourceIndexOfDefined(plan, definedIndex) {
211
218
  return plan.numImportedResources + definedIndex;
@@ -215,6 +222,7 @@ export function resourceIndexOfDefined(plan, definedIndex) {
215
222
  * bytes. The plan is validated (formatVersion, type tables) but returned in
216
223
  * wire form: the executor re-runs `loadPlan` per instantiation so resource
217
224
  * identity tokens are fresh per component instance.
225
+ * @internal
218
226
  */
219
227
  export function loadEnvelope(json) {
220
228
  let envelope;
@@ -559,6 +567,7 @@ function loadTypeDecl(t, resourceTokens, where) {
559
567
  type: loadValType(t, resourceTokens, where),
560
568
  };
561
569
  }
570
+ /** @internal */
562
571
  export function loadValType(t, resourceTokens, where) {
563
572
  switch (t.kind) {
564
573
  case "bool":
package/esm/plan/mod.js CHANGED
@@ -1,3 +1,26 @@
1
+ /**
2
+ * The translation plan: the wire descriptor IR emitted by the translator
3
+ * (`Wire*` types, contracts/plan-format.md) plus the loader that validates
4
+ * it and converts it into the runtime's in-memory type model.
5
+ *
6
+ * **This is not embedder API.** The entry point exists as a support surface
7
+ * for bindgen-generated bindings and for the runtime's own internals, which
8
+ * import from it directly. No host program should hand-write an import of
9
+ * this module.
10
+ *
11
+ * **Its contents are completely unstable: there is no compatibility promise
12
+ * of any kind, including within a minor line.** This is an explicit
13
+ * carve-out from the caret-honest versioning policy in README.md
14
+ * §"Consuming", which otherwise promises backward compatibility within a
15
+ * minor line — every symbol here may be renamed, reshaped, or removed in
16
+ * any release, including a patch. Regenerate your bindings when you bump
17
+ * the runtime.
18
+ *
19
+ * The supported host-facing surface is `@polyengine/runtime/embedder`
20
+ * (contracts/embedder-api.md).
21
+ *
22
+ * @module
23
+ */
1
24
  // Plan format + loader (contracts/plan-format.md v0).
2
25
  export * from "./format.js";
3
26
  export * from "./loader.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polyengine/runtime",
3
- "version": "0.1.0-pre.g633468a",
3
+ "version": "0.2.0-pre.g2125a06",
4
4
  "description": "A WebAssembly Component Model host for JavaScript engines: plan executor, canonical ABI, 0.3 task scheduler, JSPI bridge, and embedder API.",
5
5
  "homepage": "https://github.com/polymorph-components/polyengine#readme",
6
6
  "repository": {
@@ -11,15 +11,9 @@
11
11
  "bugs": {
12
12
  "url": "https://github.com/polymorph-components/polyengine/issues"
13
13
  },
14
- "module": "./esm/cabi/mod.js",
15
- "types": "./types/cabi/mod.d.ts",
14
+ "module": "./esm/cache/mod.js",
15
+ "types": "./types/cache/mod.d.ts",
16
16
  "exports": {
17
- "./cabi": {
18
- "import": {
19
- "types": "./types/cabi/mod.d.ts",
20
- "default": "./esm/cabi/mod.js"
21
- }
22
- },
23
17
  "./cache": {
24
18
  "import": {
25
19
  "types": "./types/cache/mod.d.ts",
@@ -32,18 +26,6 @@
32
26
  "default": "./esm/plan/mod.js"
33
27
  }
34
28
  },
35
- "./task": {
36
- "import": {
37
- "types": "./types/task/mod.d.ts",
38
- "default": "./esm/task/mod.js"
39
- }
40
- },
41
- "./exec": {
42
- "import": {
43
- "types": "./types/exec/mod.d.ts",
44
- "default": "./esm/exec/mod.js"
45
- }
46
- },
47
29
  "./embedder": {
48
30
  "import": {
49
31
  "types": "./types/embedder/mod.d.ts",
@@ -56,24 +38,12 @@
56
38
  "default": "./esm/digest/mod.js"
57
39
  }
58
40
  },
59
- "./intrinsics": {
60
- "import": {
61
- "types": "./types/intrinsics/mod.d.ts",
62
- "default": "./esm/intrinsics/mod.js"
63
- }
64
- },
65
41
  "./shim": {
66
42
  "import": {
67
43
  "types": "./types/shim/mod.d.ts",
68
44
  "default": "./esm/shim/mod.js"
69
45
  }
70
46
  },
71
- "./jspi": {
72
- "import": {
73
- "types": "./types/jspi/mod.d.ts",
74
- "default": "./esm/jspi/mod.js"
75
- }
76
- },
77
47
  "./package.json": "./package.json"
78
48
  },
79
49
  "scripts": {},
@@ -85,7 +55,7 @@
85
55
  "access": "public"
86
56
  },
87
57
  "dependencies": {
88
- "@polyengine/protocol": "0.1.0-pre.g633468a"
58
+ "@polyengine/protocol": "0.2.0-pre.g2125a06"
89
59
  },
90
60
  "_generatedBy": "dnt@0.43.2"
91
61
  }
@@ -16,7 +16,10 @@ export interface TranslatorLike {
16
16
  * unwritable (issue #196): the eviction attempt that a layout mismatch
17
17
  * triggers is swallowed internally by the backend, so a read-only
18
18
  * pre-warmed cache from an older layout degrades to "always miss, always
19
- * re-translate" rather than throwing. */
19
+ * re-translate" rather than throwing.
20
+ *
21
+ * @internal — on-disk/on-Cache-API schema version, owned by the bundled
22
+ * cache backends. */
20
23
  export declare const CACHE_LAYOUT_VERSION = 1;
21
24
  /** The three-part identity a translation is content-addressed by. */
22
25
  export interface CacheKey {
@@ -47,7 +50,10 @@ export interface ArtifactCache {
47
50
  * internally on a failed integrity check during `get`. */
48
51
  evict(key: CacheKey): Promise<void>;
49
52
  }
50
- /** On-disk / on-Cache-API metadata envelope stored alongside the plan. */
53
+ /**
54
+ * On-disk / on-Cache-API metadata envelope stored alongside the plan.
55
+ * @internal — the cache backends' own stored metadata envelope.
56
+ */
51
57
  export interface CacheMeta {
52
58
  layoutVersion: number;
53
59
  componentSha256: string;
@@ -1,17 +1,24 @@
1
1
  import type { WirePlan } from "../plan/format.js";
2
+ /** @internal */
2
3
  export declare const CEWD_VERSION = 1;
4
+ /** @internal */
3
5
  export declare class DigestError extends Error {
4
6
  constructor(message: string);
5
7
  }
8
+ /** @internal */
6
9
  export interface WorldDigestResult {
7
10
  canonicalJson: string;
8
11
  digest: string;
9
12
  }
10
- /** Compute the canonical world digest from a loaded wire plan. */
13
+ /**
14
+ * Compute the canonical world digest from a loaded wire plan.
15
+ * @internal
16
+ */
11
17
  export declare function computeWorldDigest(plan: WirePlan): Promise<WorldDigestResult>;
12
18
  /**
13
19
  * Recursively sort object keys (alphabetically) and serialize with no extra
14
20
  * whitespace. Array order is preserved verbatim — this must match
15
21
  * `crates/bindgen/src/digest.rs::canonical_string` byte-for-byte.
22
+ * @internal
16
23
  */
17
24
  export declare function canonicalStringify(v: unknown): string;
@@ -1,2 +1,26 @@
1
+ /**
2
+ * The world-digest handshake (CEWD, docs/architecture.md §9): computing a
3
+ * canonical digest over a component's world types, and verifying generated
4
+ * bindings against the component they are used with.
5
+ *
6
+ * **This is not embedder API.** The entry point exists as a support surface
7
+ * for bindgen-generated bindings — whose typed `instantiate` wrapper
8
+ * verifies the digest before instantiating (contracts/embedder-api.md
9
+ * amendment A17) — and for the runtime's own internals. No host program
10
+ * should hand-write an import of this module.
11
+ *
12
+ * **Its contents are completely unstable: there is no compatibility promise
13
+ * of any kind, including within a minor line.** This is an explicit
14
+ * carve-out from the caret-honest versioning policy in README.md
15
+ * §"Consuming", which otherwise promises backward compatibility within a
16
+ * minor line — every symbol here may be renamed, reshaped, or removed in
17
+ * any release, including a patch. Regenerate your bindings when you bump
18
+ * the runtime.
19
+ *
20
+ * The supported host-facing surface is `@polyengine/runtime/embedder`
21
+ * (contracts/embedder-api.md).
22
+ *
23
+ * @module
24
+ */
1
25
  export * from "./digest.js";
2
26
  export * from "./verify.js";
@@ -1,4 +1,5 @@
1
1
  import type { WirePlan } from "../plan/format.js";
2
+ /** @internal */
2
3
  export interface DigestMismatch {
3
4
  expected: string;
4
5
  actual: string;
@@ -18,6 +19,7 @@ export interface DigestMismatch {
18
19
  *
19
20
  * Named and catchable: `err instanceof WorldDigestMismatchError`, or
20
21
  * `err.name === "WorldDigestMismatchError"` across realms.
22
+ * @internal
21
23
  */
22
24
  export declare class WorldDigestMismatchError extends Error {
23
25
  readonly name = "WorldDigestMismatchError";
@@ -36,6 +38,7 @@ export declare class WorldDigestMismatchError extends Error {
36
38
  * constant bindgen embedded at generation time). Returns `null` on match,
37
39
  * or a `DigestMismatch` report naming the first divergent path on
38
40
  * mismatch.
41
+ * @internal
39
42
  */
40
43
  export declare function verifyWorldDigest(plan: WirePlan, expectedDigest: string): Promise<DigestMismatch | null>;
41
44
  /**
@@ -44,5 +47,6 @@ export declare function verifyWorldDigest(plan: WirePlan, expectedDigest: string
44
47
  * trees in parallel to name the first divergent import/export/type path.
45
48
  * `expectedCanonicalJson` is normally produced by `crates/bindgen`'s
46
49
  * `digest --json` output, or by `computeWorldDigest` on a reference plan.
50
+ * @internal
47
51
  */
48
52
  export declare function diffWorldDigest(plan: WirePlan, expectedCanonicalJson: string): Promise<DigestMismatch | null>;
@@ -9,9 +9,16 @@
9
9
  *
10
10
  * WIT labels are already lower-kebab in practice, so the first fragment needs
11
11
  * no adjustment; nothing here lower-cases anything.
12
+ * @internal — the runtime applies the naming rules; embedders write the
13
+ * resulting JS names literally (contracts/embedder-api.md §"Naming and
14
+ * casing").
12
15
  */
13
16
  export declare function camelCase(label: string): string;
14
- /** `tcp-socket` -> `TcpSocket` (resource class names). */
17
+ /**
18
+ * `tcp-socket` -> `TcpSocket` (resource class names).
19
+ * @internal — the runtime applies the naming rules; embedders write the
20
+ * resulting class names literally.
21
+ */
15
22
  export declare function pascalCase(label: string): string;
16
23
  /**
17
24
  * A leaf name in `plan.exports` / `plan.imports`, decoded.
@@ -36,5 +43,9 @@ export type LeafName = {
36
43
  resource: string;
37
44
  member: string;
38
45
  };
39
- /** Decode a mangled leaf name; unmangled names come back as `plain`. */
46
+ /**
47
+ * Decode a mangled leaf name; unmangled names come back as `plain`.
48
+ * @internal — leaf-name demangling, performed by the runtime and by
49
+ * bindgen-generated code.
50
+ */
40
51
  export declare function parseLeafName(raw: string): LeafName;
@@ -1,4 +1,8 @@
1
- /** The URL of this copy of the runtime. Identity of the copy. */
1
+ /**
2
+ * The URL of this copy of the runtime. Identity of the copy.
3
+ * @internal — copy-identity constant for the A9 multi-copy diagnostics; not
4
+ * host-facing.
5
+ */
2
6
  export declare const COPY_URL: string;
3
7
  /**
4
8
  * The `@polyengine/runtime` version this copy was built from, recorded in the copy
@@ -10,8 +14,10 @@ export declare const COPY_URL: string;
10
14
  *
11
15
  * INVARIANT: keep in sync with `version` in runtime/deno.json — pinned by
12
16
  * runtime/tests/embedder/cross_copy_test.ts.
17
+ * @internal — copy-identity constant for the A9 multi-copy diagnostics; not
18
+ * host-facing.
13
19
  */
14
- export declare const RUNTIME_VERSION = "0.1.0";
20
+ export declare const RUNTIME_VERSION = "0.2.0";
15
21
  /**
16
22
  * Compose a cross-copy diagnostic: what was foreign, which copy is speaking,
17
23
  * the census of every copy in the graph, and the by-value remediation.
@@ -47,6 +47,8 @@ export declare function artifactsFromEnvelope(envelopeJson: string, componentByt
47
47
  * world-digest handshake (contracts/digest.md) must complete before any
48
48
  * guest code runs: generated `instantiate` wrappers call this, verify the
49
49
  * plan, and only then delegate to `instantiate` below.
50
+ * @internal — bindgen-generated code only — the digest handshake needs the
51
+ * plan before instantiating (amendment A17).
50
52
  */
51
53
  export declare function resolveArtifacts(src: InstantiateSource): Promise<ComponentArtifacts>;
52
54
  export interface EmbedderOptions {
@@ -77,7 +79,11 @@ export interface EmbedderInstance {
77
79
  * resolution (see `version.ts`).
78
80
  */
79
81
  export declare function instantiate(source: InstantiateSource, imports?: Record<string, unknown>, opts?: EmbedderOptions): Promise<EmbedderInstance>;
80
- /** Alias matching the C2 dispatch's spelling. */
82
+ /**
83
+ * Alias matching the C2 dispatch's spelling.
84
+ * @internal — alias kept for bindgen-generated code only; hosts call
85
+ * `instantiate`.
86
+ */
81
87
  export declare const instantiateEmbedder: typeof instantiate;
82
88
  /**
83
89
  * Symbol-keyed, deliberately NOT re-exported from `mod.ts`: the
@@ -127,6 +127,8 @@ export declare function makeWrapper(cls: any, rep: number, rt: ResourceTypeInfo,
127
127
  * guest holds handles: the guest's handle is the only reference keeping a
128
128
  * host object alive across calls, and a weak map here would let it be
129
129
  * collected under the guest's feet.
130
+ * @internal — runtime-owned instance<->rep mapping; hosts supply a class, not
131
+ * a registry.
130
132
  */
131
133
  export declare class HostResourceRegistry {
132
134
  #private;
@@ -4,7 +4,10 @@ import { type HostFuture, type HostStream } from "../exec/host_streams.js";
4
4
  import { ErrorContext as InternalErrorContext } from "../task/mod.js";
5
5
  /** `Chunk<u8>` is a `Uint8Array`; every other element type chunks as `T[]`. */
6
6
  export type Chunk<T> = T extends number ? Uint8Array | T[] : T[];
7
- /** Per-element adaptation, supplied by the value adapter. */
7
+ /**
8
+ * Per-element adaptation, supplied by the value adapter.
9
+ * @internal — supplied by the value adapter, never by a host.
10
+ */
8
11
  export interface ElemCodec<T> {
9
12
  readonly element: ValType | null;
10
13
  /** internal component value -> conventions value */
@@ -2,6 +2,8 @@ import type { ComponentValue, ValType } from "../cabi/types.js";
2
2
  /**
3
3
  * The parts of adaptation that need instance state: resources (identity
4
4
  * mapping, ownership) and the borrow scope of the call in flight.
5
+ * @internal — value-adapter wiring, supplied by the runtime's instance
6
+ * state.
5
7
  */
6
8
  export interface ValueBridge {
7
9
  /** A guest handed the host an `own<R>`; the host now owns it. */
@@ -35,6 +37,9 @@ export interface ValueBridge {
35
37
  * Wrappers materialized for `borrow<R>` arguments of one call. The contract:
36
38
  * "instance valid **only during the call** (retention throws)", so the scope
37
39
  * invalidates them when the call returns.
40
+ *
41
+ * @internal — the runtime materializes and invalidates these per call; a
42
+ * host never constructs or names one.
38
43
  */
39
44
  export declare class BorrowScope {
40
45
  #private;
@@ -51,6 +56,7 @@ export declare const NO_BORROWS: BorrowScope;
51
56
  * no diagnostic anywhere. Contract principle 2: footguns are design defects.
52
57
  */
53
58
  export declare function checkNoCollisions(key: object, labels: string[], what: string): void;
59
+ /** @internal — value-adapter wiring. */
54
60
  export interface AdapterOptions {
55
61
  bridge: ValueBridge;
56
62
  /** Names the site in error messages (`import 'wasi:x/y'.f`, param 2). */
@@ -64,7 +70,13 @@ export interface AdapterOptions {
64
70
  * option** boxes as `{ kind: "some", value } | { kind: "none" }`. Only option maps
65
71
  * to `undefined`, so this is the only ambiguity, and the flag is set only when
66
72
  * descending through an option's payload — every other constructor resets it.
73
+ * @internal — value-adapter internals; the facade adapts values at the
74
+ * boundary.
67
75
  */
68
76
  export declare function toHost(v: ComponentValue, t: ValType, o: AdapterOptions, scope?: BorrowScope, inOption?: boolean): unknown;
77
+ /**
78
+ * @internal — value-adapter internals; the facade adapts values at the
79
+ * boundary.
80
+ */
69
81
  export declare function fromHost(v: unknown, t: ValType, o: AdapterOptions, inOption?: boolean): ComponentValue;
70
82
  export declare function describe(v: unknown): string;
@@ -6,7 +6,11 @@ export declare class ImportRegistrationError extends Error {
6
6
  export declare class ImportResolutionError extends Error {
7
7
  constructor(message: string);
8
8
  }
9
- /** A parsed `name@version` interface id. `version` is null when unversioned. */
9
+ /**
10
+ * A parsed `name@version` interface id. `version` is null when unversioned.
11
+ * @internal — interface-id parsing internals; embedders write ids, the
12
+ * runtime parses them.
13
+ */
10
14
  export interface ParsedId {
11
15
  /** The id with the version suffix removed (`wasi:clocks/monotonic-clock`). */
12
16
  base: string;
@@ -15,6 +19,10 @@ export interface ParsedId {
15
19
  /** Parsed semver, or null when unversioned / unparseable. */
16
20
  semver: Semver | null;
17
21
  }
22
+ /**
23
+ * @internal — version-resolution internals; §"Version canonicalization" of
24
+ * contracts/embedder-api.md is implemented here, not called by hosts.
25
+ */
18
26
  export interface Semver {
19
27
  major: number;
20
28
  minor: number;
@@ -28,8 +36,10 @@ export interface Semver {
28
36
  *
29
37
  * Last, not first: a package name may not contain `@`, but being explicit
30
38
  * costs nothing and matches how wasmtime splits (`name.rfind('@')`).
39
+ * @internal — version-resolution internals.
31
40
  */
32
41
  export declare function parseInterfaceId(id: string): ParsedId;
42
+ /** @internal — version-resolution internals. */
33
43
  export declare function parseSemver(v: string): Semver | null;
34
44
  /**
35
45
  * The compatibility-track key of an interface id, or null when the id belongs
@@ -48,6 +58,7 @@ export declare function parseSemver(v: string): Semver | null;
48
58
  *
49
59
  * Build metadata is ignored for track purposes (`2.1.2+abc` -> `@2`), as
50
60
  * semver requires.
61
+ * @internal — version-resolution internals.
51
62
  */
52
63
  export declare function trackKey(id: string): string | null;
53
64
  /**
@@ -56,6 +67,7 @@ export declare function trackKey(id: string): string | null;
56
67
  * Note `semver::Version::parse("0.2")` fails — which is exactly why the two
57
68
  * mechanisms compose: a track key can never be mistaken for a full version,
58
69
  * and a full version never generates a track key equal to itself.
70
+ * @internal — version-resolution internals.
59
71
  */
60
72
  export declare function asTrackKeySpelling(id: string): string | null;
61
73
  /**
@@ -64,6 +76,8 @@ export declare function asTrackKeySpelling(id: string): string | null;
64
76
  * Only the *interface-id* keys participate: world-level bare imports live at
65
77
  * the record's top level under camelCase names and are matched by exact
66
78
  * string equality, never by version machinery.
79
+ * @internal — built by `instantiate` from the embedder's plain imports
80
+ * record; hosts never construct one.
67
81
  */
68
82
  export declare class ImportResolver {
69
83
  #private;
@@ -81,5 +95,8 @@ export declare class ImportResolver {
81
95
  value: unknown;
82
96
  } | undefined;
83
97
  }
84
- /** Semver precedence, prerelease-aware (semver.org §11). */
98
+ /**
99
+ * Semver precedence, prerelease-aware (semver.org §11).
100
+ * @internal — version-resolution internals.
101
+ */
85
102
  export declare function compareSemver(a: Semver, b: Semver): number;
@@ -1,5 +1,9 @@
1
- /** Core wasm lane types as emitted in `coreType` and `rep` fields. */
1
+ /**
2
+ * Core wasm lane types as emitted in `coreType` and `rep` fields.
3
+ * @internal
4
+ */
2
5
  export type WireCoreType = "i32" | "i64" | "f32" | "f64";
6
+ /** @internal */
3
7
  export interface WirePlan {
4
8
  formatVersion: number;
5
9
  producer: {
@@ -59,6 +63,7 @@ export interface WirePlan {
59
63
  exports: WireExport[];
60
64
  worldDigest: string;
61
65
  }
66
+ /** @internal */
62
67
  export type WireModule = {
63
68
  kind: "embedded";
64
69
  offset: number;
@@ -69,12 +74,14 @@ export type WireModule = {
69
74
  len: number;
70
75
  intrinsics: WireIntrinsicEntry[];
71
76
  };
77
+ /** @internal */
72
78
  export interface WireIntrinsicEntry {
73
79
  module: string;
74
80
  name: string;
75
81
  category: string;
76
82
  def: WireCoreDef;
77
83
  }
84
+ /** @internal */
78
85
  export type WireInitializer = {
79
86
  op: "instantiate-module";
80
87
  module: number;
@@ -111,6 +118,7 @@ export type WireInitializer = {
111
118
  dtor: WireCoreDef | null;
112
119
  instance: number;
113
120
  };
121
+ /** @internal */
114
122
  export type WireCoreDef = {
115
123
  kind: "export";
116
124
  instance: number;
@@ -137,10 +145,12 @@ export type WireCoreDef = {
137
145
  } | {
138
146
  kind: "task-may-block";
139
147
  };
148
+ /** @internal */
140
149
  export interface WireCoreExport {
141
150
  instance: number;
142
151
  item: WireExportItem;
143
152
  }
153
+ /** @internal */
144
154
  export interface WireExportItem {
145
155
  name: string;
146
156
  space: "func" | "table" | "memory" | "global" | "tag" | "unknown";
@@ -150,6 +160,7 @@ export interface WireExportItem {
150
160
  * Only the M0-relevant variants are given precise field types; the rest are
151
161
  * matched by `kind` and rejected at instantiate time with milestone-aware
152
162
  * errors (contracts/intrinsics.md §B).
163
+ * @internal
153
164
  */
154
165
  export type WireTrampoline = {
155
166
  kind: "lower-import";
@@ -197,6 +208,7 @@ export type WireTrampoline = {
197
208
  index: number;
198
209
  [field: string]: unknown;
199
210
  };
211
+ /** @internal */
200
212
  export interface WireCanonicalOptions {
201
213
  instance: number;
202
214
  stringEncoding: "utf8" | "utf16" | "latin1+utf16";
@@ -211,7 +223,10 @@ export interface WireCanonicalOptions {
211
223
  results: WireCoreType[];
212
224
  };
213
225
  }
214
- /** descriptor-ir.md ValType JSON (nested structurally). */
226
+ /**
227
+ * descriptor-ir.md ValType JSON (nested structurally).
228
+ * @internal
229
+ */
215
230
  export type WireValType = {
216
231
  kind: "bool" | "s8" | "u8" | "s16" | "u16" | "s32" | "u32" | "s64" | "u64" | "f32" | "f64" | "char" | "string" | "error-context";
217
232
  } | {
@@ -263,6 +278,7 @@ export type WireValType = {
263
278
  kind: "future";
264
279
  element: WireValType | null;
265
280
  };
281
+ /** @internal */
266
282
  export type WireTypeDecl = {
267
283
  kind: "func";
268
284
  params: {
@@ -272,6 +288,7 @@ export type WireTypeDecl = {
272
288
  results: WireValType[];
273
289
  async: boolean;
274
290
  } | WireValType;
291
+ /** @internal */
275
292
  export type WireResourceTable = {
276
293
  kind: "concrete";
277
294
  resource: number;
@@ -281,25 +298,34 @@ export type WireResourceTable = {
281
298
  id: number;
282
299
  };
283
300
  /** One stream or future table (plan v2). */
284
- /** One error-context table: the owning component instance, nothing else. */
301
+ /**
302
+ * One error-context table: the owning component instance, nothing else.
303
+ * @internal
304
+ */
285
305
  export interface WireErrorContextTable {
286
306
  instance: number;
287
307
  }
308
+ /** @internal */
288
309
  export interface WireAsyncTable {
289
310
  element: WireValType | null;
290
311
  instance: number;
291
312
  }
292
- /** One imported resource type: back-reference into `plan.imports`. */
313
+ /**
314
+ * One imported resource type: back-reference into `plan.imports`.
315
+ * @internal
316
+ */
293
317
  export interface WireImportedResource {
294
318
  /** `RuntimeImportIndex` — index into `plan.imports`. */
295
319
  import: number;
296
320
  }
321
+ /** @internal */
297
322
  export interface WireImport {
298
323
  name: string;
299
324
  path: string[];
300
325
  kind: string;
301
326
  type?: number;
302
327
  }
328
+ /** @internal */
303
329
  export type WireExport = {
304
330
  kind: "lifted-func";
305
331
  name: string;
@@ -324,6 +350,7 @@ export type WireExport = {
324
350
  name: string;
325
351
  module: number;
326
352
  };
353
+ /** @internal */
327
354
  export type WireTypeExport = {
328
355
  kind: "resource";
329
356
  resource: number;
@@ -335,6 +362,7 @@ export type WireTypeExport = {
335
362
  * The shim's C-ABI envelope: plan + adapter artifacts in one JSON document
336
363
  * (crates/translator-shim/README.md documents the 1:1 mapping to the
337
364
  * contract's artifact set).
365
+ * @internal
338
366
  */
339
367
  export interface WireEnvelope {
340
368
  plan?: WirePlan;
@@ -360,6 +388,7 @@ export interface WireEnvelope {
360
388
  * valid but uses a shape this plan-format version cannot express, and
361
389
  * `"internal"` is a shim bug. Neither of the latter two may be scored as a
362
390
  * correct rejection.
391
+ * @internal
363
392
  */
364
393
  export interface WireErrorDetail {
365
394
  phase: "validation" | "unsupported" | "internal";
@@ -1,6 +1,9 @@
1
1
  import { type FuncType, ResourceTypeInfo, type ValType } from "../cabi/types.js";
2
2
  import type { WireErrorDetail, WirePlan, WireValType } from "./format.js";
3
- /** Fault in the plan document itself (version/shape/reference errors). */
3
+ /**
4
+ * Fault in the plan document itself (version/shape/reference errors).
5
+ * @internal
6
+ */
4
7
  export declare class PlanError extends Error {
5
8
  constructor(message: string);
6
9
  }
@@ -12,6 +15,7 @@ export declare class PlanError extends Error {
12
15
  * component* and is the only failure that satisfies `assert_invalid` /
13
16
  * `assert_malformed`. `PlanError` and the other phases are failures of our
14
17
  * own pipeline and must never be scored as conformance passes.
18
+ * @internal
15
19
  */
16
20
  export declare class TranslateError extends Error {
17
21
  readonly phase: WireErrorDetail["phase"];
@@ -39,9 +43,13 @@ export declare class TranslateError extends Error {
39
43
  * producer and consumer bumped in the same commit), so v0 plans are refused
40
44
  * rather than best-effort accepted — a stale cached artifact must be a loud
41
45
  * failure, not a subtly different execution.
46
+ * @internal
42
47
  */
43
48
  export declare const SUPPORTED_FORMAT_VERSION = 4;
44
- /** A types-table entry after conversion. */
49
+ /**
50
+ * A types-table entry after conversion.
51
+ * @internal
52
+ */
45
53
  export type LoadedType = {
46
54
  kind: "func";
47
55
  funcType: FuncType;
@@ -50,6 +58,7 @@ export type LoadedType = {
50
58
  kind: "value";
51
59
  type: ValType;
52
60
  };
61
+ /** @internal */
53
62
  export interface LoadedPlan {
54
63
  wire: WirePlan;
55
64
  /** Converted types table, index-aligned with `wire.types`. */
@@ -91,6 +100,7 @@ export interface LoadedPlan {
91
100
  /**
92
101
  * Validate a plan document and convert its type tables. Fails fast on
93
102
  * formatVersion mismatch per contracts/plan-format.md "Executor obligations".
103
+ * @internal
94
104
  */
95
105
  export declare function loadPlan(wire: WirePlan): LoadedPlan;
96
106
  /**
@@ -98,6 +108,7 @@ export declare function loadPlan(wire: WirePlan): LoadedPlan;
98
108
  * field of a `resource` initializer). Mirrors wasmtime
99
109
  * `Component::resource_index` (wasmtime-environ 47.0.3
100
110
  * `component/info.rs:222`).
111
+ * @internal
101
112
  */
102
113
  export declare function resourceIndexOfDefined(plan: LoadedPlan, definedIndex: number): number;
103
114
  /**
@@ -105,9 +116,11 @@ export declare function resourceIndexOfDefined(plan: LoadedPlan, definedIndex: n
105
116
  * bytes. The plan is validated (formatVersion, type tables) but returned in
106
117
  * wire form: the executor re-runs `loadPlan` per instantiation so resource
107
118
  * identity tokens are fresh per component instance.
119
+ * @internal
108
120
  */
109
121
  export declare function loadEnvelope(json: string): {
110
122
  wire: WirePlan;
111
123
  adapters: Map<string, Uint8Array>;
112
124
  };
125
+ /** @internal */
113
126
  export declare function loadValType(t: WireValType, resourceTokens: ResourceTypeInfo[], where: string): ValType;
@@ -1,2 +1,25 @@
1
+ /**
2
+ * The translation plan: the wire descriptor IR emitted by the translator
3
+ * (`Wire*` types, contracts/plan-format.md) plus the loader that validates
4
+ * it and converts it into the runtime's in-memory type model.
5
+ *
6
+ * **This is not embedder API.** The entry point exists as a support surface
7
+ * for bindgen-generated bindings and for the runtime's own internals, which
8
+ * import from it directly. No host program should hand-write an import of
9
+ * this module.
10
+ *
11
+ * **Its contents are completely unstable: there is no compatibility promise
12
+ * of any kind, including within a minor line.** This is an explicit
13
+ * carve-out from the caret-honest versioning policy in README.md
14
+ * §"Consuming", which otherwise promises backward compatibility within a
15
+ * minor line — every symbol here may be renamed, reshaped, or removed in
16
+ * any release, including a patch. Regenerate your bindings when you bump
17
+ * the runtime.
18
+ *
19
+ * The supported host-facing surface is `@polyengine/runtime/embedder`
20
+ * (contracts/embedder-api.md).
21
+ *
22
+ * @module
23
+ */
1
24
  export * from "./format.js";
2
25
  export * from "./loader.js";