11import type { Context } from '@emnapi/runtime'
22
3- export declare interface BaseCreateOptions {
4- filename ?: string
5- nodeBinding ?: {
6- node : {
7- emitAsyncInit : Function
8- emitAsyncDestroy : Function
9- makeCallback : Function
10- }
11- napi : {
12- asyncInit : Function
13- asyncDestroy : Function
14- makeCallback : Function
15- }
3+ export declare interface NodeBinding {
4+ node : {
5+ emitAsyncInit : Function
6+ emitAsyncDestroy : Function
7+ makeCallback : Function
8+ }
9+ napi : {
10+ asyncInit : Function
11+ asyncDestroy : Function
12+ makeCallback : Function
1613 }
14+ }
15+
16+ export declare type BaseCreateOptions = {
17+ filename ?: string
18+ nodeBinding ?: NodeBinding
1719 onCreateWorker ?: ( ) => any
1820 print ?: ( str : string ) => void
1921 printErr ?: ( str : string ) => void
22+ postMessage ?: ( msg : any ) => any
2023}
2124
2225export declare type CreateOptions = BaseCreateOptions & ( {
2326 context : Context
24- childThread ?: false
27+ childThread ?: boolean
2528} | {
2629 context ?: Context
27- postMessage ?: ( msg : any ) => any
2830 childThread : true
2931} )
3032
@@ -41,7 +43,7 @@ export declare interface InitOptions {
4143 table ?: WebAssembly . Table
4244}
4345
44- export declare interface NapiModule < ChildThread extends boolean > {
46+ export declare interface NapiModule {
4547 imports : {
4648 env : any
4749 napi : any
@@ -50,7 +52,7 @@ export declare interface NapiModule<ChildThread extends boolean> {
5052 exports : any
5153 loaded : boolean
5254 filename : string
53- childThread : ChildThread
55+ childThread : boolean
5456 emnapi : {
5557 syncMemory < T extends ArrayBuffer | ArrayBufferView > (
5658 js_to_wasm : boolean ,
@@ -66,78 +68,55 @@ export declare interface NapiModule<ChildThread extends boolean> {
6668 postMessage ?: ( msg : any ) => any
6769}
6870
69- export declare type ToBoolean < T > = [ T ] extends [ never ]
70- ? false
71- : [ T ] extends [ boolean ]
72- ? T
73- : T extends 0
74- ? false
75- : T extends ''
76- ? false
77- : T extends null
78- ? false
79- : T extends undefined
80- ? false
81- // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
82- : T extends void
83- ? false
84- : true
85-
86- export declare function createNapiModule < T extends CreateOptions > (
87- options : T
88- ) : NapiModule < ToBoolean < T [ 'childThread' ] > >
89-
90- export declare interface BaseLoadOptions {
91- wasi ?: {
92- readonly wasiImport ?: Record < string , any >
93- initialize ( instance : object ) : void
94- getImportObject ? ( ) : any
95- }
71+ export declare function createNapiModule (
72+ options : CreateOptions
73+ ) : NapiModule
74+
75+ export declare interface ReactorWASI {
76+ readonly wasiImport ?: Record < string , any >
77+ initialize ( instance : object ) : void
78+ getImportObject ? ( ) : any
79+ }
80+
81+ export declare interface LoadOptions {
82+ wasi ?: ReactorWASI
9683 overwriteImports ?: ( importObject : WebAssembly . Imports ) => WebAssembly . Imports
84+ /** Required if in child thread */
85+ tid ?: number
86+ /** Required if in child thread */
87+ arg ?: number
9788}
9889
99- export declare type LoadOptions = BaseLoadOptions & (
100- ( BaseCreateOptions & ( {
101- context : Context
102- childThread ?: false
103- } | {
104- context ?: Context
105- postMessage ?: ( msg : any ) => any
106- childThread : true
107- tid : number
108- arg : number
109- } ) ) |
110- ( {
111- napiModule : NapiModule < false >
112- } | {
113- napiModule : NapiModule < true >
114- tid : number
115- arg : number
116- } )
117- )
118-
119- export declare type LoadInChildThread < T > = T extends LoadOptions
120- ? 'napiModule' extends keyof T
121- ? T [ 'napiModule' ] extends NapiModule < infer R >
122- ? R
123- : never
124- : 'childThread' extends keyof T
125- ? T [ 'childThread' ]
126- : never
127- : never
128-
129- export declare interface LoadResult < ChildThread extends boolean > extends WebAssembly . WebAssemblyInstantiatedSource {
130- napiModule : NapiModule < ChildThread >
90+ export declare type InstantiateOptions = CreateOptions & LoadOptions
91+
92+ export declare interface InstantiatedSource extends WebAssembly . WebAssemblyInstantiatedSource {
93+ napiModule : NapiModule
13194}
13295
133- export declare function loadNapiModule < T extends LoadOptions > (
96+ export declare function loadNapiModule (
97+ napiModule : NapiModule ,
98+ /** Only support `BufferSource` or `WebAssembly.Module` on Node.js */
99+ wasmInput : string | URL | BufferSource | WebAssembly . Module ,
100+ options ?: LoadOptions
101+ ) : Promise < WebAssembly . WebAssemblyInstantiatedSource >
102+
103+ export declare function loadNapiModuleSync (
104+ napiModule : NapiModule ,
105+ /** Only support `BufferSource` or `WebAssembly.Module` on Node.js */
106+ wasmInput : string | URL | BufferSource | WebAssembly . Module ,
107+ options ?: LoadOptions
108+ ) : WebAssembly . WebAssemblyInstantiatedSource
109+
110+ export declare function instantiateNapiModule (
111+ /** Only support `BufferSource` or `WebAssembly.Module` on Node.js */
134112 wasmInput : string | URL | BufferSource | WebAssembly . Module ,
135- options : T
136- ) : Promise < LoadResult < ToBoolean < LoadInChildThread < T > > > >
113+ options : InstantiateOptions
114+ ) : Promise < InstantiatedSource >
137115
138- export declare function loadNapiModuleSync < T extends LoadOptions > (
116+ export declare function instantiateNapiModuleSync (
117+ /** Only support `BufferSource` or `WebAssembly.Module` on Node.js */
139118 wasmInput : string | URL | BufferSource | WebAssembly . Module ,
140- options : T
141- ) : LoadResult < ToBoolean < LoadInChildThread < T > > >
119+ options : InstantiateOptions
120+ ) : InstantiatedSource
142121
143122export declare function handleMessage ( msg : { data : any } , callback : ( type : string , payload : any ) => any ) : void
0 commit comments