@polyengine/runtime 0.1.0-pre.g633468a

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 (126) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +23 -0
  3. package/esm/cabi/async_values.js +162 -0
  4. package/esm/cabi/bulk_lists.js +198 -0
  5. package/esm/cabi/context.js +42 -0
  6. package/esm/cabi/flatten.js +145 -0
  7. package/esm/cabi/float.js +67 -0
  8. package/esm/cabi/handles.js +253 -0
  9. package/esm/cabi/layout.js +149 -0
  10. package/esm/cabi/lift.js +196 -0
  11. package/esm/cabi/load.js +146 -0
  12. package/esm/cabi/lower.js +141 -0
  13. package/esm/cabi/memory.js +182 -0
  14. package/esm/cabi/mod.js +22 -0
  15. package/esm/cabi/store.js +186 -0
  16. package/esm/cabi/strings.js +336 -0
  17. package/esm/cabi/trap.js +38 -0
  18. package/esm/cabi/types.js +264 -0
  19. package/esm/cabi/values.js +64 -0
  20. package/esm/cache/core.js +156 -0
  21. package/esm/cache/dir.js +170 -0
  22. package/esm/cache/mod.js +4 -0
  23. package/esm/cache/web.js +136 -0
  24. package/esm/digest/digest.js +332 -0
  25. package/esm/digest/mod.js +3 -0
  26. package/esm/digest/verify.js +129 -0
  27. package/esm/embedder/casing.js +56 -0
  28. package/esm/embedder/copy.js +42 -0
  29. package/esm/embedder/errors.js +26 -0
  30. package/esm/embedder/imports.js +63 -0
  31. package/esm/embedder/instantiate.js +978 -0
  32. package/esm/embedder/mod.js +40 -0
  33. package/esm/embedder/resources.js +406 -0
  34. package/esm/embedder/streams.js +770 -0
  35. package/esm/embedder/values.js +450 -0
  36. package/esm/embedder/version.js +273 -0
  37. package/esm/exec/boundary.js +1902 -0
  38. package/esm/exec/executor.js +1004 -0
  39. package/esm/exec/host_streams.js +818 -0
  40. package/esm/exec/mod.js +4 -0
  41. package/esm/intrinsics/async_builtins.js +510 -0
  42. package/esm/intrinsics/context.js +90 -0
  43. package/esm/intrinsics/errors.js +13 -0
  44. package/esm/intrinsics/fact_calls.js +865 -0
  45. package/esm/intrinsics/mod.js +564 -0
  46. package/esm/intrinsics/stream_builtins.js +578 -0
  47. package/esm/intrinsics/transcode.js +443 -0
  48. package/esm/jspi/bridge.js +579 -0
  49. package/esm/jspi/mechanics.js +89 -0
  50. package/esm/jspi/mod.js +5 -0
  51. package/esm/jspi/suspending.js +15 -0
  52. package/esm/jspi/types.js +29 -0
  53. package/esm/package.json +3 -0
  54. package/esm/plan/format.js +5 -0
  55. package/esm/plan/loader.js +657 -0
  56. package/esm/plan/mod.js +3 -0
  57. package/esm/shim/mod.js +2 -0
  58. package/esm/shim/translator.js +94 -0
  59. package/esm/task/mod.js +483 -0
  60. package/esm/task/scheduler.js +1028 -0
  61. package/esm/task/streams.js +786 -0
  62. package/esm/task/subtask.js +135 -0
  63. package/esm/task/thread.js +255 -0
  64. package/esm/task/waitable.js +144 -0
  65. package/package.json +91 -0
  66. package/types/cabi/async_values.d.ts +35 -0
  67. package/types/cabi/bulk_lists.d.ts +18 -0
  68. package/types/cabi/context.d.ts +59 -0
  69. package/types/cabi/flatten.d.ts +14 -0
  70. package/types/cabi/float.d.ts +14 -0
  71. package/types/cabi/handles.d.ts +70 -0
  72. package/types/cabi/layout.d.ts +13 -0
  73. package/types/cabi/lift.d.ts +25 -0
  74. package/types/cabi/load.d.ts +14 -0
  75. package/types/cabi/lower.d.ts +10 -0
  76. package/types/cabi/memory.d.ts +58 -0
  77. package/types/cabi/mod.d.ts +15 -0
  78. package/types/cabi/store.d.ts +12 -0
  79. package/types/cabi/strings.d.ts +23 -0
  80. package/types/cabi/trap.d.ts +11 -0
  81. package/types/cabi/types.d.ts +206 -0
  82. package/types/cabi/values.d.ts +5 -0
  83. package/types/cache/core.d.ts +97 -0
  84. package/types/cache/dir.d.ts +6 -0
  85. package/types/cache/mod.d.ts +3 -0
  86. package/types/cache/web.d.ts +10 -0
  87. package/types/digest/digest.d.ts +17 -0
  88. package/types/digest/mod.d.ts +2 -0
  89. package/types/digest/verify.d.ts +48 -0
  90. package/types/embedder/casing.d.ts +40 -0
  91. package/types/embedder/copy.d.ts +24 -0
  92. package/types/embedder/errors.d.ts +11 -0
  93. package/types/embedder/imports.d.ts +47 -0
  94. package/types/embedder/instantiate.d.ts +88 -0
  95. package/types/embedder/mod.d.ts +11 -0
  96. package/types/embedder/resources.d.ts +158 -0
  97. package/types/embedder/streams.d.ts +202 -0
  98. package/types/embedder/values.d.ts +70 -0
  99. package/types/embedder/version.d.ts +85 -0
  100. package/types/exec/boundary.d.ts +360 -0
  101. package/types/exec/executor.d.ts +125 -0
  102. package/types/exec/host_streams.d.ts +165 -0
  103. package/types/exec/mod.d.ts +3 -0
  104. package/types/intrinsics/async_builtins.d.ts +69 -0
  105. package/types/intrinsics/context.d.ts +28 -0
  106. package/types/intrinsics/errors.d.ts +5 -0
  107. package/types/intrinsics/fact_calls.d.ts +120 -0
  108. package/types/intrinsics/mod.d.ts +187 -0
  109. package/types/intrinsics/stream_builtins.d.ts +113 -0
  110. package/types/intrinsics/transcode.d.ts +21 -0
  111. package/types/jspi/bridge.d.ts +227 -0
  112. package/types/jspi/mechanics.d.ts +50 -0
  113. package/types/jspi/mod.d.ts +3 -0
  114. package/types/jspi/suspending.d.ts +1 -0
  115. package/types/jspi/types.d.ts +26 -0
  116. package/types/plan/format.d.ts +369 -0
  117. package/types/plan/loader.d.ts +113 -0
  118. package/types/plan/mod.d.ts +2 -0
  119. package/types/shim/mod.d.ts +1 -0
  120. package/types/shim/translator.d.ts +55 -0
  121. package/types/task/mod.d.ts +257 -0
  122. package/types/task/scheduler.d.ts +421 -0
  123. package/types/task/streams.d.ts +370 -0
  124. package/types/task/subtask.d.ts +96 -0
  125. package/types/task/thread.d.ts +73 -0
  126. package/types/task/waitable.d.ts +67 -0
@@ -0,0 +1,42 @@
1
+ // This runtime copy's identity (contracts/embedder-api.md §"Module identity
2
+ // and @polyengine/protocol", amendment A9; issue #83).
3
+ //
4
+ // One module owns the copy's URL so every diagnostic composes the same
5
+ // message, and so lowering sites deep in the value adapters can name the copy
6
+ // without threading it through their signatures.
7
+ //
8
+ // `import.meta.url` is the identity: it is what distinguishes the source
9
+ // checkout from a bundled `polyengine-embedder.mjs`, and two bundles from each
10
+ // other. It is stable per module instance and needs no permissions (unlike
11
+ // reading deno.json, which embedder paths must never do — no fs perms).
12
+ import { copyCensus } from "@polyengine/protocol";
13
+ /** The URL of this copy of the runtime. Identity of the copy. */
14
+ export const COPY_URL = import.meta.url;
15
+ /**
16
+ * The `@polyengine/runtime` version this copy was built from, recorded in the copy
17
+ * registry alongside the URL.
18
+ *
19
+ * Hardcoded on purpose: embedder code paths run without filesystem
20
+ * permissions (and a browser bundle has no filesystem at all), so reading
21
+ * `runtime/deno.json` at runtime is not an option.
22
+ *
23
+ * INVARIANT: keep in sync with `version` in runtime/deno.json — pinned by
24
+ * runtime/tests/embedder/cross_copy_test.ts.
25
+ */
26
+ export const RUNTIME_VERSION = "0.1.0";
27
+ /**
28
+ * Compose a cross-copy diagnostic: what was foreign, which copy is speaking,
29
+ * the census of every copy in the graph, and the by-value remediation.
30
+ *
31
+ * Kept to one line but complete — the whole point of A9's stateful half is
32
+ * that "recognized but foreign" is a NAMED failure, never a silent
33
+ * adaptation (a foreign `Stream` pumped as an async iterable) and never a
34
+ * misleading generic ("handle is not an error-context").
35
+ */
36
+ export function describeCrossCopy(what, remedy) {
37
+ const census = copyCensus();
38
+ return `${what} was minted by a DIFFERENT polyengine runtime copy and cannot ` +
39
+ `be used through this one (this copy: ${COPY_URL}${census === "" ? "" : `; ${census}`}). Handles are stateful — their machinery lives in the copy that minted ` +
40
+ `them (contracts/embedder-api.md amendment A9, issue #83)` +
41
+ `${remedy === undefined ? "" : `. ${remedy}`}`;
42
+ }
@@ -0,0 +1,26 @@
1
+ // The embedder-facing error model (contracts/embedder-api.md §"Error model").
2
+ //
3
+ // The canonical definitions live in `@polyengine/protocol` since amendment A9 —
4
+ // this module is the unchanged import path for them (every existing
5
+ // `from "./errors.ts"` / `@polyengine/runtime/embedder` import keeps working) plus
6
+ // the runtime-local `NameCollisionError`, which never crosses a copy boundary
7
+ // (it is raised while BUILDING a facade, before any value exists) and
8
+ // therefore carries no brand: the A9 table's omissions are deliberate.
9
+ //
10
+ // Recognition at the runtime's own boundaries is by BRAND, not class: use the
11
+ // `is*` predicates re-exported below, never `instanceof`, for any value that
12
+ // arrives from embedder code (issue #83).
13
+ export { DroppedError, InvalidHandleError, isDroppedError, isInvalidHandleError, isPeerTrappedError, isStreamProducerError, isTrap, isComponentException, PeerTrappedError, Trap, ComponentException, } from "@polyengine/protocol";
14
+ /**
15
+ * Two WIT labels in one scope camelCase to the same JS name.
16
+ *
17
+ * A footgun is a design defect (contract principle 2): silently letting one
18
+ * field/flag/function shadow another would corrupt values at the boundary with
19
+ * no diagnostic anywhere. Refused at facade build instead.
20
+ */
21
+ export class NameCollisionError extends Error {
22
+ constructor(message) {
23
+ super(message);
24
+ this.name = "NameCollisionError";
25
+ }
26
+ }
@@ -0,0 +1,63 @@
1
+ // `requiredImports()` — the supported enumeration of a component's linkable
2
+ // import leaves (contracts/embedder-api.md §"Module wiring and
3
+ // instantiation"; C2 checklist item 2).
4
+ //
5
+ // C0 finding #8: `plan.imports` proved the right authority, and every embedder
6
+ // that needed it hand-rolled the same walk (tools/smoke-c0/wasi_stub.ts).
7
+ // Blessing it removes that. It is also this layer's own input: the facade
8
+ // builds its import wrappers from exactly this list.
9
+ import { loadPlan } from "../plan/loader.js";
10
+ import { camelCase, parseLeafName, pascalCase } from "./casing.js";
11
+ function toLoaded(input) {
12
+ if ("wire" in input && "types" in input)
13
+ return input;
14
+ const wire = "plan" in input ? input.plan : input;
15
+ return loadPlan(wire);
16
+ }
17
+ /** Enumerate the component's linkable import leaves. */
18
+ export function requiredImports(input) {
19
+ const loaded = toLoaded(input);
20
+ return loaded.wire.imports.map((imp) => {
21
+ const leaf = imp.path.length === 0
22
+ ? imp.name
23
+ : imp.path[imp.path.length - 1];
24
+ const member = parseLeafName(leaf);
25
+ const out = {
26
+ interfaceId: imp.name,
27
+ path: [...imp.path],
28
+ leaf,
29
+ kind: imp.kind,
30
+ member,
31
+ jsName: jsNameOf(member, imp.kind),
32
+ };
33
+ if (member.form !== "plain")
34
+ out.jsClass = pascalCase(member.resource);
35
+ if (imp.type !== undefined) {
36
+ const t = loaded.types[imp.type];
37
+ if (t !== undefined && t.kind === "func") {
38
+ out.type = {
39
+ params: t.funcType.params.map((p, i) => ({
40
+ name: t.paramNames[i] ?? String(i),
41
+ type: p,
42
+ })),
43
+ results: t.funcType.results,
44
+ async: t.funcType.async === true,
45
+ };
46
+ }
47
+ }
48
+ return out;
49
+ });
50
+ }
51
+ function jsNameOf(member, kind) {
52
+ switch (member.form) {
53
+ case "plain":
54
+ return kind === "resource"
55
+ ? pascalCase(member.name)
56
+ : camelCase(member.name);
57
+ case "constructor":
58
+ return "constructor";
59
+ case "method":
60
+ case "static":
61
+ return camelCase(member.member);
62
+ }
63
+ }