@petrea/wasm 0.0.0 → 0.5.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.
@@ -0,0 +1,83 @@
1
+ export type WasiBinding = typeof import('./binding.wasip1.cjs')
2
+
3
+ export type WasiModuleInput =
4
+ | WebAssembly.Module
5
+ | PromiseLike<WebAssembly.Module>
6
+
7
+ /** Run the instance on a linear memory the caller allocated. */
8
+ export interface WasiCallerMemoryOptions {
9
+ /**
10
+ * A caller-allocated linear memory for this instance. It must be unshared
11
+ * and created in this loader's own realm — the WASI and emnapi layers
12
+ * underneath identify a Memory with a realm-local `instanceof`, so one from
13
+ * a `node:vm` context or another frame is rejected. It is single-use: once
14
+ * a validated initialization attempt has begun, the same Memory cannot be
15
+ * passed again — including after that attempt failed, and after the instance
16
+ * was disposed.
17
+ */
18
+ memory: WebAssembly.Memory
19
+ /** Not available beside `memory`: the loader allocates neither. */
20
+ initialMemoryPages?: never
21
+ /** Not available beside `memory`: the loader allocates neither. */
22
+ maximumMemoryPages?: never
23
+ }
24
+
25
+ /** Let the loader allocate the linear memory, optionally sized. */
26
+ export interface WasiAllocatedMemoryOptions {
27
+ /** Not available beside the page counts: they size the loader's own Memory. */
28
+ memory?: never
29
+ /** @default WASM_MEMORY.initialPages */
30
+ initialMemoryPages?: number
31
+ /** @default WASM_MEMORY.maximumPages */
32
+ maximumMemoryPages?: number
33
+ }
34
+
35
+ /**
36
+ * Either memory form, never a mix of the two: the loader throws a TypeError
37
+ * on `memory` beside a page count. `{}` and an omitted argument select the
38
+ * loader defaults.
39
+ */
40
+ export type WasiInstanceOptions =
41
+ | WasiCallerMemoryOptions
42
+ | WasiAllocatedMemoryOptions
43
+
44
+ export interface WasiRuntimeStats {
45
+ /** Instances created by this evaluated loader module, not process-wide. */
46
+ createdInstances: number
47
+ /** Created instances whose dispose() has not completed. */
48
+ liveInstances: number
49
+ /** Declared initial address space, not committed memory. */
50
+ declaredInitialMemoryBytes: number
51
+ }
52
+
53
+ export interface WasiInstance {
54
+ readonly exports: WasiBinding
55
+ /** This instance's linear memory. Claimed, so it cannot start another one. */
56
+ readonly memory: WebAssembly.Memory
57
+ /** Current linear-memory size; 0 once dispose() has completed. */
58
+ readonly memoryBytes: number
59
+ readonly disposed: boolean
60
+ dispose(): Promise<void>
61
+ }
62
+
63
+ /** The memory descriptor compiled into this loader. */
64
+ export const WASM_MEMORY: Readonly<{
65
+ initialPages: number
66
+ maximumPages: number
67
+ pageBytes: number
68
+ initialBytes: number
69
+ maximumBytes: number
70
+ }>
71
+
72
+ export function getDeferredRuntimeStats(): Readonly<WasiRuntimeStats>
73
+
74
+ export function instantiate(wasmInput: WasiModuleInput): Promise<WasiBinding>
75
+ export function createInstance(
76
+ wasmInput: WasiModuleInput,
77
+ options?: WasiInstanceOptions,
78
+ ): Promise<WasiInstance>
79
+ /** Dispose the singleton and retry retained failed-initialization cleanup. */
80
+ export function dispose(): Promise<void>
81
+
82
+ /** The WASI flavor this deferred loader instantiates. */
83
+ export declare const __napiBindingTarget: 'wasm32-wasip1'