@flowscripter/template-bun-wasm-rust-library 1.0.6 → 1.0.7

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/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  ],
18
18
  "module": "index.ts",
19
19
  "type": "module",
20
- "version": "1.0.6",
20
+ "version": "1.0.7",
21
21
  "files": [
22
22
  "src/**/*",
23
23
  "pkg/**/*",
@@ -29,9 +29,9 @@
29
29
  "access": "public"
30
30
  },
31
31
  "devDependencies": {
32
- "@types/bun": "^1.2.10"
32
+ "@types/bun": "^1.3.14"
33
33
  },
34
34
  "peerDependencies": {
35
- "typescript": "^5.8.3"
35
+ "typescript": "^6.0.3"
36
36
  }
37
37
  }
@@ -1,5 +1,6 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
+
3
4
  /**
4
5
  * Adds two numbers together.
5
6
  *
@@ -18,29 +19,30 @@ export function add(a: number, b: number): number;
18
19
  export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
19
20
 
20
21
  export interface InitOutput {
21
- readonly memory: WebAssembly.Memory;
22
- readonly add: (a: number, b: number) => number;
23
- readonly __wbindgen_export_0: WebAssembly.Table;
24
- readonly __wbindgen_start: () => void;
22
+ readonly memory: WebAssembly.Memory;
23
+ readonly add: (a: number, b: number) => number;
24
+ readonly __wbindgen_externrefs: WebAssembly.Table;
25
+ readonly __wbindgen_start: () => void;
25
26
  }
26
27
 
27
28
  export type SyncInitInput = BufferSource | WebAssembly.Module;
29
+
28
30
  /**
29
- * Instantiates the given `module`, which can either be bytes or
30
- * a precompiled `WebAssembly.Module`.
31
- *
32
- * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
33
- *
34
- * @returns {InitOutput}
35
- */
31
+ * Instantiates the given `module`, which can either be bytes or
32
+ * a precompiled `WebAssembly.Module`.
33
+ *
34
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
35
+ *
36
+ * @returns {InitOutput}
37
+ */
36
38
  export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
37
39
 
38
40
  /**
39
- * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
40
- * for everything else, calls `WebAssembly.instantiate` directly.
41
- *
42
- * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
43
- *
44
- * @returns {Promise<InitOutput>}
45
- */
41
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
42
+ * for everything else, calls `WebAssembly.instantiate` directly.
43
+ *
44
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
45
+ *
46
+ * @returns {Promise<InitOutput>}
47
+ */
46
48
  export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
@@ -1,4 +1,4 @@
1
- let wasm;
1
+ /* @ts-self-types="./flowscripter_template_bun_wasm_rust_library.d.ts" */
2
2
 
3
3
  /**
4
4
  * Adds two numbers together.
@@ -20,73 +20,74 @@ export function add(a, b) {
20
20
  const ret = wasm.add(a, b);
21
21
  return ret;
22
22
  }
23
+ function __wbg_get_imports() {
24
+ const import0 = {
25
+ __proto__: null,
26
+ __wbindgen_init_externref_table: function() {
27
+ const table = wasm.__wbindgen_externrefs;
28
+ const offset = table.grow(4);
29
+ table.set(0, undefined);
30
+ table.set(offset + 0, undefined);
31
+ table.set(offset + 1, null);
32
+ table.set(offset + 2, true);
33
+ table.set(offset + 3, false);
34
+ },
35
+ };
36
+ return {
37
+ __proto__: null,
38
+ "./flowscripter_template_bun_wasm_rust_library_bg.js": import0,
39
+ };
40
+ }
41
+
42
+ let wasmModule, wasmInstance, wasm;
43
+ function __wbg_finalize_init(instance, module) {
44
+ wasmInstance = instance;
45
+ wasm = instance.exports;
46
+ wasmModule = module;
47
+ wasm.__wbindgen_start();
48
+ return wasm;
49
+ }
23
50
 
24
51
  async function __wbg_load(module, imports) {
25
52
  if (typeof Response === 'function' && module instanceof Response) {
26
53
  if (typeof WebAssembly.instantiateStreaming === 'function') {
27
54
  try {
28
55
  return await WebAssembly.instantiateStreaming(module, imports);
29
-
30
56
  } catch (e) {
31
- if (module.headers.get('Content-Type') != 'application/wasm') {
57
+ const validResponse = module.ok && expectedResponseType(module.type);
58
+
59
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
32
60
  console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
33
61
 
34
- } else {
35
- throw e;
36
- }
62
+ } else { throw e; }
37
63
  }
38
64
  }
39
65
 
40
66
  const bytes = await module.arrayBuffer();
41
67
  return await WebAssembly.instantiate(bytes, imports);
42
-
43
68
  } else {
44
69
  const instance = await WebAssembly.instantiate(module, imports);
45
70
 
46
71
  if (instance instanceof WebAssembly.Instance) {
47
72
  return { instance, module };
48
-
49
73
  } else {
50
74
  return instance;
51
75
  }
52
76
  }
53
- }
54
-
55
- function __wbg_get_imports() {
56
- const imports = {};
57
- imports.wbg = {};
58
- imports.wbg.__wbindgen_init_externref_table = function() {
59
- const table = wasm.__wbindgen_export_0;
60
- const offset = table.grow(4);
61
- table.set(0, undefined);
62
- table.set(offset + 0, undefined);
63
- table.set(offset + 1, null);
64
- table.set(offset + 2, true);
65
- table.set(offset + 3, false);
66
- ;
67
- };
68
77
 
69
- return imports;
70
- }
71
-
72
- function __wbg_init_memory(imports, memory) {
73
-
74
- }
75
-
76
- function __wbg_finalize_init(instance, module) {
77
- wasm = instance.exports;
78
- __wbg_init.__wbindgen_wasm_module = module;
79
-
80
-
81
- wasm.__wbindgen_start();
82
- return wasm;
78
+ function expectedResponseType(type) {
79
+ switch (type) {
80
+ case 'basic': case 'cors': case 'default': return true;
81
+ }
82
+ return false;
83
+ }
83
84
  }
84
85
 
85
86
  function initSync(module) {
86
87
  if (wasm !== undefined) return wasm;
87
88
 
88
89
 
89
- if (typeof module !== 'undefined') {
90
+ if (module !== undefined) {
90
91
  if (Object.getPrototypeOf(module) === Object.prototype) {
91
92
  ({module} = module)
92
93
  } else {
@@ -95,15 +96,10 @@ function initSync(module) {
95
96
  }
96
97
 
97
98
  const imports = __wbg_get_imports();
98
-
99
- __wbg_init_memory(imports);
100
-
101
99
  if (!(module instanceof WebAssembly.Module)) {
102
100
  module = new WebAssembly.Module(module);
103
101
  }
104
-
105
102
  const instance = new WebAssembly.Instance(module, imports);
106
-
107
103
  return __wbg_finalize_init(instance, module);
108
104
  }
109
105
 
@@ -111,7 +107,7 @@ async function __wbg_init(module_or_path) {
111
107
  if (wasm !== undefined) return wasm;
112
108
 
113
109
 
114
- if (typeof module_or_path !== 'undefined') {
110
+ if (module_or_path !== undefined) {
115
111
  if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
116
112
  ({module_or_path} = module_or_path)
117
113
  } else {
@@ -119,7 +115,7 @@ async function __wbg_init(module_or_path) {
119
115
  }
120
116
  }
121
117
 
122
- if (typeof module_or_path === 'undefined') {
118
+ if (module_or_path === undefined) {
123
119
  module_or_path = new URL('flowscripter_template_bun_wasm_rust_library_bg.wasm', import.meta.url);
124
120
  }
125
121
  const imports = __wbg_get_imports();
@@ -128,12 +124,9 @@ async function __wbg_init(module_or_path) {
128
124
  module_or_path = fetch(module_or_path);
129
125
  }
130
126
 
131
- __wbg_init_memory(imports);
132
-
133
127
  const { instance, module } = await __wbg_load(await module_or_path, imports);
134
128
 
135
129
  return __wbg_finalize_init(instance, module);
136
130
  }
137
131
 
138
- export { initSync };
139
- export default __wbg_init;
132
+ export { initSync, __wbg_init as default };
@@ -2,5 +2,5 @@
2
2
  /* eslint-disable */
3
3
  export const memory: WebAssembly.Memory;
4
4
  export const add: (a: number, b: number) => number;
5
- export const __wbindgen_export_0: WebAssembly.Table;
5
+ export const __wbindgen_externrefs: WebAssembly.Table;
6
6
  export const __wbindgen_start: () => void;
package/src/lib.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import init, {
2
2
  add,
3
3
  } from "../pkg/flowscripter_template_bun_wasm_rust_library.js";
4
+
5
+ // TODO: when https://github.com/oven-sh/bun/pull/20503 is released I believe the following can be removed
4
6
  import wasm from "../pkg/flowscripter_template_bun_wasm_rust_library_bg.wasm";
5
7
  const wasmBuffer = typeof Bun !== "undefined"
6
8
  ? await Bun.file(wasm).arrayBuffer()
@@ -11,6 +13,7 @@ const wasmBuffer = typeof Bun !== "undefined"
11
13
  */
12
14
  export async function world(): Promise<void> {
13
15
  // init WASM module
16
+ // TODO: when https://github.com/oven-sh/bun/pull/20503 is released I believe the following can be simply `await init();`
14
17
  await init({ module_or_path: wasmBuffer });
15
18
 
16
19
  console.info(`World ${add(3, 3)}`);