@gadgetinc/substrate 0.1.0-rc.1

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 (181) hide show
  1. package/dist/assets/kernel.wasm +0 -0
  2. package/dist/assets/manifest.json +32 -0
  3. package/dist/assets/network-driver.js +2 -0
  4. package/dist/assets/network-driver.js.map +1 -0
  5. package/dist/assets/runtime.js +264 -0
  6. package/dist/assets/runtime.js.map +1 -0
  7. package/dist/binaries.d.ts +58 -0
  8. package/dist/binaries.d.ts.map +1 -0
  9. package/dist/boot/index.d.ts +318 -0
  10. package/dist/boot/index.d.ts.map +1 -0
  11. package/dist/index.d.ts +8 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +4589 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/kernel/bridge.d.ts +64 -0
  16. package/dist/kernel/bridge.d.ts.map +1 -0
  17. package/dist/kernel/types.d.ts +518 -0
  18. package/dist/kernel/types.d.ts.map +1 -0
  19. package/dist/kernel/wasm.d.ts +20 -0
  20. package/dist/kernel/wasm.d.ts.map +1 -0
  21. package/dist/node/assert.d.ts +99 -0
  22. package/dist/node/assert.d.ts.map +1 -0
  23. package/dist/node/async_hooks.d.ts +88 -0
  24. package/dist/node/async_hooks.d.ts.map +1 -0
  25. package/dist/node/buffer.d.ts +62 -0
  26. package/dist/node/buffer.d.ts.map +1 -0
  27. package/dist/node/child_process.d.ts +300 -0
  28. package/dist/node/child_process.d.ts.map +1 -0
  29. package/dist/node/cluster.d.ts +37 -0
  30. package/dist/node/cluster.d.ts.map +1 -0
  31. package/dist/node/constants.d.ts +306 -0
  32. package/dist/node/constants.d.ts.map +1 -0
  33. package/dist/node/crypto.d.ts +176 -0
  34. package/dist/node/crypto.d.ts.map +1 -0
  35. package/dist/node/dgram.d.ts +44 -0
  36. package/dist/node/dgram.d.ts.map +1 -0
  37. package/dist/node/diagnostics_channel.d.ts +57 -0
  38. package/dist/node/diagnostics_channel.d.ts.map +1 -0
  39. package/dist/node/dns.d.ts +278 -0
  40. package/dist/node/dns.d.ts.map +1 -0
  41. package/dist/node/domain.d.ts +21 -0
  42. package/dist/node/domain.d.ts.map +1 -0
  43. package/dist/node/events.d.ts +54 -0
  44. package/dist/node/events.d.ts.map +1 -0
  45. package/dist/node/fs/promises.d.ts +116 -0
  46. package/dist/node/fs/promises.d.ts.map +1 -0
  47. package/dist/node/fs.d.ts +536 -0
  48. package/dist/node/fs.d.ts.map +1 -0
  49. package/dist/node/http.d.ts +471 -0
  50. package/dist/node/http.d.ts.map +1 -0
  51. package/dist/node/http2.d.ts +508 -0
  52. package/dist/node/http2.d.ts.map +1 -0
  53. package/dist/node/https.d.ts +42 -0
  54. package/dist/node/https.d.ts.map +1 -0
  55. package/dist/node/inspector.d.ts +25 -0
  56. package/dist/node/inspector.d.ts.map +1 -0
  57. package/dist/node/net.d.ts +231 -0
  58. package/dist/node/net.d.ts.map +1 -0
  59. package/dist/node/os.d.ts +318 -0
  60. package/dist/node/os.d.ts.map +1 -0
  61. package/dist/node/path.d.ts +144 -0
  62. package/dist/node/path.d.ts.map +1 -0
  63. package/dist/node/process.d.ts +105 -0
  64. package/dist/node/process.d.ts.map +1 -0
  65. package/dist/node/punycode.d.ts +34 -0
  66. package/dist/node/punycode.d.ts.map +1 -0
  67. package/dist/node/querystring.d.ts +49 -0
  68. package/dist/node/querystring.d.ts.map +1 -0
  69. package/dist/node/readline.d.ts +99 -0
  70. package/dist/node/readline.d.ts.map +1 -0
  71. package/dist/node/stream.d.ts +409 -0
  72. package/dist/node/stream.d.ts.map +1 -0
  73. package/dist/node/string_decoder.d.ts +46 -0
  74. package/dist/node/string_decoder.d.ts.map +1 -0
  75. package/dist/node/timers.d.ts +79 -0
  76. package/dist/node/timers.d.ts.map +1 -0
  77. package/dist/node/tls.d.ts +159 -0
  78. package/dist/node/tls.d.ts.map +1 -0
  79. package/dist/node/trace_events.d.ts +18 -0
  80. package/dist/node/trace_events.d.ts.map +1 -0
  81. package/dist/node/tty.d.ts +67 -0
  82. package/dist/node/tty.d.ts.map +1 -0
  83. package/dist/node/url.d.ts +85 -0
  84. package/dist/node/url.d.ts.map +1 -0
  85. package/dist/node/util.d.ts +252 -0
  86. package/dist/node/util.d.ts.map +1 -0
  87. package/dist/node/v8.d.ts +134 -0
  88. package/dist/node/v8.d.ts.map +1 -0
  89. package/dist/node/vm.d.ts +89 -0
  90. package/dist/node/vm.d.ts.map +1 -0
  91. package/dist/node/wasi.d.ts +25 -0
  92. package/dist/node/wasi.d.ts.map +1 -0
  93. package/dist/node/worker_threads.d.ts +206 -0
  94. package/dist/node/worker_threads.d.ts.map +1 -0
  95. package/dist/node/ws.d.ts +110 -0
  96. package/dist/node/ws.d.ts.map +1 -0
  97. package/dist/node/zlib.d.ts +328 -0
  98. package/dist/node/zlib.d.ts.map +1 -0
  99. package/dist/persistence/opfs-store.d.ts +93 -0
  100. package/dist/persistence/opfs-store.d.ts.map +1 -0
  101. package/dist/runtime/async-function-shim.d.ts +27 -0
  102. package/dist/runtime/async-function-shim.d.ts.map +1 -0
  103. package/dist/runtime/fs-interface.d.ts +60 -0
  104. package/dist/runtime/fs-interface.d.ts.map +1 -0
  105. package/dist/runtime/index.d.ts +113 -0
  106. package/dist/runtime/index.d.ts.map +1 -0
  107. package/dist/runtime/loader.d.ts +50 -0
  108. package/dist/runtime/loader.d.ts.map +1 -0
  109. package/dist/runtime/loaders/async-transform.d.ts +40 -0
  110. package/dist/runtime/loaders/async-transform.d.ts.map +1 -0
  111. package/dist/runtime/loaders/cjs.d.ts +37 -0
  112. package/dist/runtime/loaders/cjs.d.ts.map +1 -0
  113. package/dist/runtime/loaders/detect-module-type.d.ts +21 -0
  114. package/dist/runtime/loaders/detect-module-type.d.ts.map +1 -0
  115. package/dist/runtime/loaders/esm.d.ts +140 -0
  116. package/dist/runtime/loaders/esm.d.ts.map +1 -0
  117. package/dist/runtime/loaders/source-map-registry.d.ts +43 -0
  118. package/dist/runtime/loaders/source-map-registry.d.ts.map +1 -0
  119. package/dist/runtime/loaders/source-map.d.ts +50 -0
  120. package/dist/runtime/loaders/source-map.d.ts.map +1 -0
  121. package/dist/runtime/loaders/utils.d.ts +6 -0
  122. package/dist/runtime/loaders/utils.d.ts.map +1 -0
  123. package/dist/runtime/native-globals.d.ts +24 -0
  124. package/dist/runtime/native-globals.d.ts.map +1 -0
  125. package/dist/runtime/network-driver.d.ts +78 -0
  126. package/dist/runtime/network-driver.d.ts.map +1 -0
  127. package/dist/runtime/process-context.d.ts +96 -0
  128. package/dist/runtime/process-context.d.ts.map +1 -0
  129. package/dist/runtime/process-event-loop.d.ts +356 -0
  130. package/dist/runtime/process-event-loop.d.ts.map +1 -0
  131. package/dist/runtime/process-handler.d.ts +71 -0
  132. package/dist/runtime/process-handler.d.ts.map +1 -0
  133. package/dist/runtime/process-handlers/node.d.ts +22 -0
  134. package/dist/runtime/process-handlers/node.d.ts.map +1 -0
  135. package/dist/runtime/process-handlers/npm.d.ts +20 -0
  136. package/dist/runtime/process-handlers/npm.d.ts.map +1 -0
  137. package/dist/runtime/process-handlers/npx.d.ts +11 -0
  138. package/dist/runtime/process-handlers/npx.d.ts.map +1 -0
  139. package/dist/runtime/process-handlers/pnpm.d.ts +12 -0
  140. package/dist/runtime/process-handlers/pnpm.d.ts.map +1 -0
  141. package/dist/runtime/process-handlers/shell.d.ts +24 -0
  142. package/dist/runtime/process-handlers/shell.d.ts.map +1 -0
  143. package/dist/runtime/process-handlers/yarn.d.ts +12 -0
  144. package/dist/runtime/process-handlers/yarn.d.ts.map +1 -0
  145. package/dist/runtime/process-helpers.d.ts +17 -0
  146. package/dist/runtime/process-helpers.d.ts.map +1 -0
  147. package/dist/runtime/process-manager.d.ts +87 -0
  148. package/dist/runtime/process-manager.d.ts.map +1 -0
  149. package/dist/runtime/process-scheduler.d.ts +123 -0
  150. package/dist/runtime/process-scheduler.d.ts.map +1 -0
  151. package/dist/runtime/process-waker.d.ts +24 -0
  152. package/dist/runtime/process-waker.d.ts.map +1 -0
  153. package/dist/runtime/promise.d.ts +44 -0
  154. package/dist/runtime/promise.d.ts.map +1 -0
  155. package/dist/runtime/stack-trace.d.ts +52 -0
  156. package/dist/runtime/stack-trace.d.ts.map +1 -0
  157. package/dist/runtime/wasm-package-interceptor.d.ts +141 -0
  158. package/dist/runtime/wasm-package-interceptor.d.ts.map +1 -0
  159. package/dist/runtime/web-streams.d.ts +57 -0
  160. package/dist/runtime/web-streams.d.ts.map +1 -0
  161. package/dist/runtime/websocket.d.ts +102 -0
  162. package/dist/runtime/websocket.d.ts.map +1 -0
  163. package/dist/shim/websocket-shim-inline.d.ts +9 -0
  164. package/dist/shim/websocket-shim-inline.d.ts.map +1 -0
  165. package/dist/shim/websocket-shim.d.ts +15 -0
  166. package/dist/shim/websocket-shim.d.ts.map +1 -0
  167. package/dist/sw/index.d.ts +53 -0
  168. package/dist/sw/index.d.ts.map +1 -0
  169. package/dist/utils/debug.d.ts +75 -0
  170. package/dist/utils/debug.d.ts.map +1 -0
  171. package/dist/utils/path.d.ts +20 -0
  172. package/dist/utils/path.d.ts.map +1 -0
  173. package/dist/utils/tarball.d.ts +37 -0
  174. package/dist/utils/tarball.d.ts.map +1 -0
  175. package/dist/utils/websocket-protocol.d.ts +102 -0
  176. package/dist/utils/websocket-protocol.d.ts.map +1 -0
  177. package/dist/worker/host.d.ts +14 -0
  178. package/dist/worker/host.d.ts.map +1 -0
  179. package/dist/worker/types.d.ts +209 -0
  180. package/dist/worker/types.d.ts.map +1 -0
  181. package/package.json +53 -0
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Binary Configuration
3
+ *
4
+ * Central configuration for all binaries that Substrate can install and run.
5
+ * This module is the source of truth for:
6
+ * - Binary versions
7
+ * - Binary handlers
8
+ * - Tarball URL generation
9
+ * - Binary specs for initialization
10
+ */
11
+ /**
12
+ * Specification for installing a binary
13
+ */
14
+ export interface BinarySpec {
15
+ /** URL to the tarball containing the binary */
16
+ tarUrl: string;
17
+ }
18
+ /**
19
+ * Available binary names
20
+ *
21
+ */
22
+ export type BinaryName = "npm" | "pnpm" | "yarn";
23
+ /**
24
+ * Default versions for each binary.
25
+ * Update these when upgrading binary versions.
26
+ */
27
+ export declare const BINARY_VERSIONS: Record<BinaryName, string>;
28
+ /**
29
+ * Get the default tarball URL for a binary.
30
+ *
31
+ * When no baseUrl is provided, returns the CDN URL for the binary tarball.
32
+ * When a baseUrl is provided, returns a relative path under that base.
33
+ *
34
+ * @param binary - The binary name
35
+ * @param baseUrl - Base URL prefix. If omitted, uses the Gadget CDN.
36
+ * @returns The full tarball URL
37
+ */
38
+ export declare function getDefaultTarballUrl(binary: BinaryName, baseUrl?: string): string;
39
+ /**
40
+ * Get default BinarySpec objects for all binaries
41
+ *
42
+ * @param baseUrl - Base URL prefix for tarball URLs
43
+ * @returns Record of binary names to their specs
44
+ */
45
+ export declare function getDefaultBinarySpecs(baseUrl?: string): Record<BinaryName, BinarySpec>;
46
+ /**
47
+ * Get all binary names
48
+ */
49
+ export declare function getBinaryNames(): BinaryName[];
50
+ /**
51
+ * Get all binary versions as a record
52
+ */
53
+ export declare function getBinaryVersions(): Record<BinaryName, string>;
54
+ /**
55
+ * Check if a string is a valid binary name
56
+ */
57
+ export declare function isBinaryName(name: string): name is BinaryName;
58
+ //# sourceMappingURL=binaries.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"binaries.d.ts","sourceRoot":"","sources":["../src/binaries.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AASH;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,+CAA+C;IAC/C,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC;AAMjD;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAOtD,CAAC;AAMF;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAMjF;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,UAAU,EAAE,UAAU,CAAC,CAMtF;AAMD;;GAEG;AACH,wBAAgB,cAAc,IAAI,UAAU,EAAE,CAE7C;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,CAE9D;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,UAAU,CAE7D"}
@@ -0,0 +1,318 @@
1
+ /**
2
+ * Substrate Bootloader
3
+ *
4
+ * Consolidates all Substrate initialization:
5
+ * - Service Worker registration and activation
6
+ * - Multi-tab coordination (via thumbdrive's MultiTabWorkerBroker)
7
+ * - Kernel WASM loading
8
+ * - OPFS filesystem initialization (future)
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import { bootSubstrate } from '@gadgetinc/substrate/boot';
13
+ *
14
+ * const substrate = await bootSubstrate({
15
+ * name: 'my-project',
16
+ * });
17
+ *
18
+ * // fetch() and WebSocket just work - SW intercepts transparently
19
+ * const response = await fetch('/api/hello');
20
+ * ```
21
+ */
22
+ import type { RoutingConfig } from "../sw/index.js";
23
+ import type { BinarySpec } from "../binaries.js";
24
+ import type { ConsoleLogLevel } from "../worker/types.js";
25
+ import type { ProcessInfo } from "../kernel/types.js";
26
+ import type { WasmPackageMapping } from "../runtime/wasm-package-interceptor.js";
27
+ export type { WasmPackageMapping };
28
+ export interface SubstrateBootConfig {
29
+ /**
30
+ * Unique name for this Substrate instance.
31
+ * Used for multi-tab coordination - all tabs with the same name share a kernel.
32
+ */
33
+ name?: string;
34
+ /**
35
+ * URL to the Substrate kernel WASM
36
+ * @default CDN URL based on package version
37
+ */
38
+ kernelUrl?: string;
39
+ /**
40
+ * URL to the Substrate runtime entrypoint.
41
+ * @default CDN URL based on package version
42
+ */
43
+ runtimeUrl?: string | URL;
44
+ /**
45
+ * URL to the Substrate network driver entrypoint.
46
+ * @default CDN URL based on package version
47
+ */
48
+ networkDriverUrl?: string;
49
+ /**
50
+ * Base URL for binary tarball URLs.
51
+ * If not specified, uses the Gadget CDN.
52
+ */
53
+ binaryTarballBaseUrl?: string;
54
+ /**
55
+ * Base path for routing. All requests below this path will be routed to the kernel.
56
+ * If not specified, derived from the current URL pathname.
57
+ *
58
+ * @example
59
+ * // If page is at /playground/project-123/index.html
60
+ * // basePath will be /playground/project-123/
61
+ * // Pass null to explicitly disable basePath routing (use port-based only)
62
+ */
63
+ basePath?: string | null;
64
+ /**
65
+ * Port to route basePath requests to. When set along with basePath, the SW
66
+ * strips the basePath prefix and rewrites the URL to localhost:{basePathPort}
67
+ * so the kernel's substrateFetch routes by port to the correct virtual server.
68
+ * The target server does NOT need to know about the basePath — it serves
69
+ * from "/".
70
+ *
71
+ * The SW also tracks which clients (iframes) were served via basePath, so
72
+ * subsequent same-origin requests from those clients (root-relative URLs
73
+ * without the prefix) are automatically routed to the same port.
74
+ *
75
+ * @example
76
+ * // basePath: "/__preview__", basePathPort: 5173
77
+ * // Navigation to /__preview__/ → http://localhost:5173/
78
+ * // Sub-resource /src/main.js from that iframe → http://localhost:5173/src/main.js
79
+ */
80
+ basePathPort?: number | null;
81
+ /**
82
+ * CORS proxy URL for external requests.
83
+ * If not specified, external requests will be attempted directly (may fail with CORS errors).
84
+ */
85
+ proxyUrl?: string;
86
+ /**
87
+ * Domains that don't need proxying (known to be CORS-friendly).
88
+ */
89
+ neverProxy?: string[];
90
+ /**
91
+ * Initial working directory.
92
+ * @default '/'
93
+ */
94
+ cwd?: string;
95
+ /**
96
+ * Environment variables.
97
+ */
98
+ env?: Record<string, string>;
99
+ /**
100
+ * Binaries to install into the runtime.
101
+ *
102
+ */
103
+ binaries?: {
104
+ npm?: boolean | BinarySpec;
105
+ pnpm?: boolean | BinarySpec;
106
+ yarn?: boolean | BinarySpec;
107
+ };
108
+ /**
109
+ * Logging configuration for the runtime.
110
+ */
111
+ logging?: {
112
+ level?: "off" | "error" | "warn" | "info" | "debug" | "trace";
113
+ components?: string[];
114
+ };
115
+ /**
116
+ * Debug options.
117
+ */
118
+ debug?: {
119
+ trackVfs?: boolean;
120
+ };
121
+ /**
122
+ * Custom WASM package mappings. When a native binding matching one of the
123
+ * patterns is detected during mount(), the corresponding WASM package is
124
+ * fetched from npm and used instead.
125
+ *
126
+ * Default mappings for rollup, esbuild, and rolldown are always registered.
127
+ * Custom mappings with the same `packageName` as a default will override it.
128
+ *
129
+ * @example
130
+ * ```ts
131
+ * await bootSubstrate({
132
+ * wasmPackages: [{
133
+ * packageName: "my-tool",
134
+ * wasmPackage: "my-tool-wasm",
135
+ * nativeBindingPatterns: ["^@my-tool/native-"],
136
+ * wasmExportPath: "dist/index.js",
137
+ * }],
138
+ * });
139
+ * ```
140
+ */
141
+ wasmPackages?: WasmPackageMapping[];
142
+ /**
143
+ * Persistence configuration. When set, the runtime opens an OPFS store
144
+ * and wires host imports for the kernel's persistence bridge.
145
+ */
146
+ persistence?: {
147
+ /** Name of the OPFS store. Each name gets its own isolated storage. */
148
+ storeName: string;
149
+ };
150
+ /**
151
+ * Callback for console output from worker/runtime logs.
152
+ * Args are forwarded to preserve console formatting (e.g. %c).
153
+ */
154
+ onConsole?: (logLevel: ConsoleLogLevel, args: unknown[]) => void;
155
+ /**
156
+ * Callback when a port starts listening.
157
+ */
158
+ onPortListen?: (port: number) => void;
159
+ /**
160
+ * Callback when a port stops listening.
161
+ */
162
+ onPortClose?: (port: number) => void;
163
+ }
164
+ export interface SubstrateClient {
165
+ /**
166
+ * Whether this tab is the leader (owns the kernel).
167
+ */
168
+ readonly isLeader: boolean;
169
+ /**
170
+ * Mount files to the virtual filesystem.
171
+ */
172
+ mount(tree: FileSystemTree, mountPoint?: string): Promise<void>;
173
+ /**
174
+ * Read a file from the virtual filesystem.
175
+ */
176
+ readFile(path: string): Promise<string>;
177
+ /**
178
+ * Write a file to the virtual filesystem.
179
+ */
180
+ writeFile(path: string, content: string): Promise<void>;
181
+ /**
182
+ * Spawn a process.
183
+ */
184
+ spawn(command: string, args?: string[], options?: SpawnOptions): SubstrateProcess;
185
+ /**
186
+ * Wait for a port to start listening.
187
+ */
188
+ waitForPort(port: number, timeout?: number): Promise<void>;
189
+ /**
190
+ * Check if a port is listening.
191
+ */
192
+ isListening(port: number): boolean;
193
+ /**
194
+ * Get all listening ports.
195
+ */
196
+ getListeningPorts(): number[];
197
+ /**
198
+ * Persist the current VFS state to the OPFS store.
199
+ * Requires a store to be open (either via boot config or mountStore).
200
+ * Flushes all dirty inodes and saves VFS metadata.
201
+ */
202
+ persist(): Promise<void>;
203
+ /**
204
+ * Open an OPFS store and mount its VFS (lazy, metadata-only).
205
+ * Can be called after boot to load a previously persisted filesystem.
206
+ * File data is loaded on demand when accessed.
207
+ */
208
+ mountStore(storeName: string): Promise<void>;
209
+ /**
210
+ * List available OPFS store names.
211
+ */
212
+ listStores(): Promise<string[]>;
213
+ /**
214
+ * Delete an OPFS store and all its data.
215
+ */
216
+ deleteStore(storeName: string): Promise<void>;
217
+ /**
218
+ * Terminate the runtime. Awaits worker shutdown to release OPFS handles.
219
+ */
220
+ terminate(): Promise<void>;
221
+ /**
222
+ * List all processes in the kernel process table.
223
+ * @param options.includeExited - Include recently reaped processes (default: false)
224
+ * Useful for debugging and verifying process cleanup.
225
+ */
226
+ listProcesses(options?: {
227
+ includeExited?: boolean;
228
+ }): Promise<ProcessInfo[]>;
229
+ /**
230
+ * Add a listener for leadership changes.
231
+ */
232
+ on(event: "leadership", callback: (isLeader: boolean) => void): void;
233
+ /**
234
+ * WebSocket constructor that routes connections through the virtual network.
235
+ *
236
+ * Use this instead of the native WebSocket to connect to servers running in Substrate.
237
+ *
238
+ * @example
239
+ * ```ts
240
+ * const ws = new substrate.WebSocket('ws://localhost:8080');
241
+ * ws.onopen = () => ws.send('Hello!');
242
+ * ws.onmessage = (e) => console.log(e.data);
243
+ * ```
244
+ */
245
+ WebSocket: {
246
+ new (url: string | URL, protocols?: string | string[]): SubstrateWebSocketProxy;
247
+ readonly CONNECTING: 0;
248
+ readonly OPEN: 1;
249
+ readonly CLOSING: 2;
250
+ readonly CLOSED: 3;
251
+ };
252
+ }
253
+ /**
254
+ * WebSocket proxy that communicates with virtual servers through the worker.
255
+ * Implements the standard WebSocket API.
256
+ */
257
+ export interface SubstrateWebSocketProxy extends EventTarget {
258
+ readonly url: string;
259
+ readonly readyState: number;
260
+ readonly protocol: string;
261
+ readonly extensions: string;
262
+ readonly bufferedAmount: number;
263
+ binaryType: "blob" | "arraybuffer";
264
+ onopen: ((this: SubstrateWebSocketProxy, ev: Event) => void) | null;
265
+ onmessage: ((this: SubstrateWebSocketProxy, ev: MessageEvent) => void) | null;
266
+ onerror: ((this: SubstrateWebSocketProxy, ev: Event) => void) | null;
267
+ onclose: ((this: SubstrateWebSocketProxy, ev: CloseEvent) => void) | null;
268
+ send(data: string | ArrayBufferLike | Blob | ArrayBufferView): void;
269
+ close(code?: number, reason?: string): void;
270
+ }
271
+ export interface FileNode {
272
+ file: {
273
+ contents: string | Uint8Array;
274
+ };
275
+ }
276
+ export interface DirectoryNode {
277
+ directory: FileSystemTree;
278
+ }
279
+ export type FileSystemTree = {
280
+ [name: string]: FileNode | DirectoryNode;
281
+ };
282
+ export interface SpawnOptions {
283
+ cwd?: string;
284
+ env?: Record<string, string>;
285
+ }
286
+ export interface SubstrateProcess {
287
+ readonly pid: Promise<number>;
288
+ stdout: ReadableStream<string>;
289
+ stderr: ReadableStream<string>;
290
+ exit: Promise<number>;
291
+ kill(): void;
292
+ }
293
+ /**
294
+ * Boot Substrate with Service Worker network interception and multi-tab coordination.
295
+ *
296
+ * This must be called early in your application, before any requests that should
297
+ * be intercepted by the Service Worker.
298
+ *
299
+ * @example
300
+ * ```ts
301
+ * const substrate = await bootSubstrate({
302
+ * name: 'my-project',
303
+ * });
304
+ *
305
+ * await substrate.mount({
306
+ * 'server.js': { file: { contents: '...' } }
307
+ * });
308
+ *
309
+ * substrate.spawn('node', ['server.js']);
310
+ *
311
+ * // fetch() just works - SW intercepts automatically
312
+ * await substrate.waitForPort(3000);
313
+ * const res = await fetch('http://localhost:3000/');
314
+ * ```
315
+ */
316
+ export declare function bootSubstrate(config?: SubstrateBootConfig): Promise<SubstrateClient>;
317
+ export type { RoutingConfig };
318
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/boot/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAapD,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,gBAAgB,CAAC;AAG7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AACjF,YAAY,EAAE,kBAAkB,EAAE,CAAC;AAMnC,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;IAE1B;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;;OAGG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAE9B;;;;;;;;OAQG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAEzB;;;;;;;;;;;;;;;OAeG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAE7B;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;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,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7C;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE;QACJ,QAAQ,EAAE,MAAM,GAAG,UAAU,CAAC;KAC/B,CAAC;CACH;AAED,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,cAAc,CAAC;CAC3B;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,aAAa,CAAC;CAC1C,CAAC;AAEF,MAAM,WAAW,YAAY;IAC3B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9B,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC;IAC/B,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC;IAC/B,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IACtB,IAAI,IAAI,IAAI,CAAC;CACd;AA6UD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,aAAa,CAAC,MAAM,GAAE,mBAAwB,GAAG,OAAO,CAAC,eAAe,CAAC,CAsC9F;AA20BD,YAAY,EAAE,aAAa,EAAE,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @gadgetinc/substrate
3
+ *
4
+ * A browser-native JavaScript runtime with Node.js compatibility.
5
+ */
6
+ export { bootSubstrate, type SubstrateBootConfig, type SubstrateClient, type SpawnOptions, type RoutingConfig, type FileNode, type DirectoryNode, type FileSystemTree, type SubstrateProcess, } from "./boot/index.js";
7
+ export { setLogLevel, setLogComponents, type LogLevel } from "./utils/debug.js";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EACL,aAAa,EACb,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,gBAAgB,GACtB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,KAAK,QAAQ,EAAE,MAAM,kBAAkB,CAAC"}