@tybys/wasm-util 0.4.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.
package/README.md CHANGED
@@ -25,7 +25,7 @@ const fs = createFsFromVolume(Volume.from({
25
25
  '/home/wasi': null
26
26
  }))
27
27
 
28
- const wasi = new WASI({
28
+ const wasi = WASI.createSync({
29
29
  args: ['chrome', 'file.wasm'],
30
30
  env: {
31
31
  NODE_ENV: 'development',
@@ -34,7 +34,7 @@ const wasi = new WASI({
34
34
  preopens: {
35
35
  '/': '/'
36
36
  },
37
- filesystem: { type: 'memfs', fs },
37
+ fs,
38
38
 
39
39
  // redirect stdout / stderr
40
40
 
@@ -31,6 +31,12 @@ export declare type AsyncifyExports<T, U> = T extends Record<string, any> ? {
31
31
  [P in keyof T]: T[P] extends Callable ? U extends Array<Exclude<keyof T, AsyncifyExportName>> ? P extends U[number] ? AsyncifyExportFunction<T[P]> : T[P] : AsyncifyExportFunction<T[P]> : T[P];
32
32
  } : T;
33
33
 
34
+ /** @public */
35
+ export declare function asyncifyLoad(asyncify: AsyncifyOptions, urlOrBuffer: string | URL | BufferSource, imports?: WebAssembly.Imports): Promise<WebAssembly.WebAssemblyInstantiatedSource>;
36
+
37
+ /** @public */
38
+ export declare function asyncifyLoadSync(asyncify: AsyncifyOptions, buffer: BufferSource, imports?: WebAssembly.Imports): WebAssembly.WebAssemblyInstantiatedSource;
39
+
34
40
  /** @public */
35
41
  export declare interface AsyncifyOptions {
36
42
  wasm64?: boolean;
@@ -41,6 +47,14 @@ export declare interface AsyncifyOptions {
41
47
  wrapExports?: string[];
42
48
  }
43
49
 
50
+ /** @public */
51
+ export declare interface AsyncWASIOptions extends WASIOptions {
52
+ fs: {
53
+ promises: IFsPromises;
54
+ };
55
+ asyncify?: Asyncify;
56
+ }
57
+
44
58
  /** @public */
45
59
  export declare interface BaseEncodingOptions {
46
60
  encoding?: BufferEncoding_2;
@@ -249,10 +263,10 @@ declare const kSetMemory: unique symbol;
249
263
  declare const kStarted: unique symbol;
250
264
 
251
265
  /** @public */
252
- export declare function load(urlOrBuffer: string | URL | BufferSource, imports?: WebAssembly.Imports, asyncify?: AsyncifyOptions): Promise<WebAssembly.WebAssemblyInstantiatedSource>;
266
+ export declare function load(urlOrBuffer: string | URL | BufferSource, imports?: WebAssembly.Imports): Promise<WebAssembly.WebAssemblyInstantiatedSource>;
253
267
 
254
268
  /** @public */
255
- export declare function loadSync(buffer: BufferSource, imports?: WebAssembly.Imports, asyncify?: AsyncifyOptions): WebAssembly.WebAssemblyInstantiatedSource;
269
+ export declare function loadSync(buffer: BufferSource, imports?: WebAssembly.Imports): WebAssembly.WebAssemblyInstantiatedSource;
256
270
 
257
271
  /** @public */
258
272
  export declare interface MakeDirectoryOptions {
@@ -342,6 +356,11 @@ export declare interface StatsBase<T> {
342
356
  birthtime: Date;
343
357
  }
344
358
 
359
+ /** @public */
360
+ export declare interface SyncWASIOptions extends WASIOptions {
361
+ fs?: IFs;
362
+ }
363
+
345
364
  /** @public */
346
365
  export declare class WASI {
347
366
  private [kSetMemory];
@@ -349,7 +368,9 @@ export declare class WASI {
349
368
  private [kExitCode];
350
369
  private [kInstance];
351
370
  readonly wasiImport: Record<string, any>;
352
- constructor(options?: WASIOptions);
371
+ static createSync(options?: SyncWASIOptions): WASI;
372
+ static createAsync(options?: AsyncWASIOptions): Promise<WASI>;
373
+ private constructor();
353
374
  start(instance: WebAssembly.Instance): number | undefined | Promise<number> | Promise<undefined>;
354
375
  initialize(instance: WebAssembly.Instance): void | Promise<void>;
355
376
  }
@@ -365,10 +386,6 @@ export declare interface WASIOptions {
365
386
  returnOnExit?: boolean | undefined;
366
387
  print?: (str: string) => void;
367
388
  printErr?: (str: string) => void;
368
- filesystem?: {
369
- type: 'memfs';
370
- fs: IFs;
371
- };
372
389
  }
373
390
 
374
391
  /** @public */
@@ -381,7 +398,7 @@ export declare const WebAssemblyMemory: {
381
398
  export declare function wrapAsyncExport<T extends Function = any>(f: Function): T;
382
399
 
383
400
  /** @public */
384
- export declare function wrapAsyncImport(f: Function, parameterType: WebAssembly.ValueType[], returnType: WebAssembly.ValueType[]): Function;
401
+ export declare function wrapAsyncImport<T extends (...args: any[]) => any>(f: T, parameterType: WebAssembly.ValueType[], returnType: WebAssembly.ValueType[]): (...args: [object, ...Parameters<T>]) => ReturnType<T>;
385
402
 
386
403
  /** @public */
387
404
  export declare function wrapExports<T extends WebAssembly.Exports>(exports: T): PromisifyExports<T, void>;