@flowscripter/template-bun-wasm-rust-library 1.3.3 → 1.3.5
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 +1 -1
- package/dist/index.js +1 -101
- package/dist/pkg/flowscripter_template_bun_wasm_rust_library.d.ts +34 -7
- package/dist/pkg/flowscripter_template_bun_wasm_rust_library.js +132 -0
- package/dist/src/lib.d.ts.map +1 -1
- package/dist/src/lib.js +17 -0
- package/package.json +2 -2
- package/src/lib.ts +2 -0
- package/src/wasm-module.d.ts +4 -0
- package/dist/pkg/flowscripter_template_bun_wasm_rust_library.d.ts.map +0 -1
- package/dist/tests/world_test.d.ts +0 -2
- package/dist/tests/world_test.d.ts.map +0 -1
- package/pkg/flowscripter_template_bun_wasm_rust_library_bg.wasm.d.ts +0 -6
- /package/dist/{flowscripter_template_bun_wasm_rust_library_bg-rbwp754y.wasm → pkg/flowscripter_template_bun_wasm_rust_library_bg.wasm} +0 -0
package/README.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,101 +1 @@
|
|
|
1
|
-
|
|
2
|
-
// pkg/flowscripter_template_bun_wasm_rust_library.js
|
|
3
|
-
function add(a, b) {
|
|
4
|
-
const ret = wasm.add(a, b);
|
|
5
|
-
return ret;
|
|
6
|
-
}
|
|
7
|
-
function __wbg_get_imports() {
|
|
8
|
-
const import0 = {
|
|
9
|
-
__proto__: null,
|
|
10
|
-
__wbindgen_init_externref_table: function() {
|
|
11
|
-
const table = wasm.__wbindgen_externrefs;
|
|
12
|
-
const offset = table.grow(4);
|
|
13
|
-
table.set(0, undefined);
|
|
14
|
-
table.set(offset + 0, undefined);
|
|
15
|
-
table.set(offset + 1, null);
|
|
16
|
-
table.set(offset + 2, true);
|
|
17
|
-
table.set(offset + 3, false);
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
return {
|
|
21
|
-
__proto__: null,
|
|
22
|
-
"./flowscripter_template_bun_wasm_rust_library_bg.js": import0
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
var wasmModule;
|
|
26
|
-
var wasmInstance;
|
|
27
|
-
var wasm;
|
|
28
|
-
function __wbg_finalize_init(instance, module) {
|
|
29
|
-
wasmInstance = instance;
|
|
30
|
-
wasm = instance.exports;
|
|
31
|
-
wasmModule = module;
|
|
32
|
-
wasm.__wbindgen_start();
|
|
33
|
-
return wasm;
|
|
34
|
-
}
|
|
35
|
-
async function __wbg_load(module, imports) {
|
|
36
|
-
if (typeof Response === "function" && module instanceof Response) {
|
|
37
|
-
if (typeof WebAssembly.instantiateStreaming === "function") {
|
|
38
|
-
try {
|
|
39
|
-
return await WebAssembly.instantiateStreaming(module, imports);
|
|
40
|
-
} catch (e) {
|
|
41
|
-
const validResponse = module.ok && expectedResponseType(module.type);
|
|
42
|
-
if (validResponse && module.headers.get("Content-Type") !== "application/wasm") {
|
|
43
|
-
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);
|
|
44
|
-
} else {
|
|
45
|
-
throw e;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
const bytes = await module.arrayBuffer();
|
|
50
|
-
return await WebAssembly.instantiate(bytes, imports);
|
|
51
|
-
} else {
|
|
52
|
-
const instance = await WebAssembly.instantiate(module, imports);
|
|
53
|
-
if (instance instanceof WebAssembly.Instance) {
|
|
54
|
-
return { instance, module };
|
|
55
|
-
} else {
|
|
56
|
-
return instance;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
function expectedResponseType(type) {
|
|
60
|
-
switch (type) {
|
|
61
|
-
case "basic":
|
|
62
|
-
case "cors":
|
|
63
|
-
case "default":
|
|
64
|
-
return true;
|
|
65
|
-
}
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
async function __wbg_init(module_or_path) {
|
|
70
|
-
if (wasm !== undefined)
|
|
71
|
-
return wasm;
|
|
72
|
-
if (module_or_path !== undefined) {
|
|
73
|
-
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
74
|
-
({ module_or_path } = module_or_path);
|
|
75
|
-
} else {
|
|
76
|
-
console.warn("using deprecated parameters for the initialization function; pass a single object instead");
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
if (module_or_path === undefined) {
|
|
80
|
-
module_or_path = new URL("flowscripter_template_bun_wasm_rust_library_bg.wasm", import.meta.url);
|
|
81
|
-
}
|
|
82
|
-
const imports = __wbg_get_imports();
|
|
83
|
-
if (typeof module_or_path === "string" || typeof Request === "function" && module_or_path instanceof Request || typeof URL === "function" && module_or_path instanceof URL) {
|
|
84
|
-
module_or_path = fetch(module_or_path);
|
|
85
|
-
}
|
|
86
|
-
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
87
|
-
return __wbg_finalize_init(instance, module);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// pkg/flowscripter_template_bun_wasm_rust_library_bg.wasm
|
|
91
|
-
var flowscripter_template_bun_wasm_rust_library_bg_default = "./flowscripter_template_bun_wasm_rust_library_bg-rbwp754y.wasm";
|
|
92
|
-
|
|
93
|
-
// src/lib.ts
|
|
94
|
-
var wasmBuffer = typeof Bun !== "undefined" ? await Bun.file(flowscripter_template_bun_wasm_rust_library_bg_default).arrayBuffer() : await fetch(flowscripter_template_bun_wasm_rust_library_bg_default).then((response) => response.arrayBuffer());
|
|
95
|
-
async function world() {
|
|
96
|
-
await __wbg_init({ module_or_path: wasmBuffer });
|
|
97
|
-
console.info(`World ${add(3, 3)}`);
|
|
98
|
-
}
|
|
99
|
-
export {
|
|
100
|
-
world
|
|
101
|
-
};
|
|
1
|
+
export * from "./src/lib.js";
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* Adds two numbers together.
|
|
3
6
|
*
|
|
@@ -10,12 +13,36 @@
|
|
|
10
13
|
*
|
|
11
14
|
* assert_eq!(6, answer);
|
|
12
15
|
* ```
|
|
13
|
-
* @param {number} a
|
|
14
|
-
* @param {number} b
|
|
15
|
-
* @returns {number}
|
|
16
16
|
*/
|
|
17
17
|
export function add(a: number, b: number): number;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
|
|
19
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
20
|
+
|
|
21
|
+
export interface InitOutput {
|
|
22
|
+
readonly memory: WebAssembly.Memory;
|
|
23
|
+
readonly add: (a: number, b: number) => number;
|
|
24
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
25
|
+
readonly __wbindgen_start: () => void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
29
|
+
|
|
30
|
+
/**
|
|
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
|
+
*/
|
|
38
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
39
|
+
|
|
40
|
+
/**
|
|
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
|
+
*/
|
|
48
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/* @ts-self-types="./flowscripter_template_bun_wasm_rust_library.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Adds two numbers together.
|
|
5
|
+
*
|
|
6
|
+
*
|
|
7
|
+
* # Examples
|
|
8
|
+
* ```
|
|
9
|
+
* let arg1 = 3;
|
|
10
|
+
* let arg2 = 3;
|
|
11
|
+
* let answer = flowscripter_template_bun_wasm_rust_library::add(arg1, arg2);
|
|
12
|
+
*
|
|
13
|
+
* assert_eq!(6, answer);
|
|
14
|
+
* ```
|
|
15
|
+
* @param {number} a
|
|
16
|
+
* @param {number} b
|
|
17
|
+
* @returns {number}
|
|
18
|
+
*/
|
|
19
|
+
export function add(a, b) {
|
|
20
|
+
const ret = wasm.add(a, b);
|
|
21
|
+
return ret;
|
|
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
|
+
}
|
|
50
|
+
|
|
51
|
+
async function __wbg_load(module, imports) {
|
|
52
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
53
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
54
|
+
try {
|
|
55
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
56
|
+
} catch (e) {
|
|
57
|
+
const validResponse = module.ok && expectedResponseType(module.type);
|
|
58
|
+
|
|
59
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
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);
|
|
61
|
+
|
|
62
|
+
} else { throw e; }
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const bytes = await module.arrayBuffer();
|
|
67
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
68
|
+
} else {
|
|
69
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
70
|
+
|
|
71
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
72
|
+
return { instance, module };
|
|
73
|
+
} else {
|
|
74
|
+
return instance;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function expectedResponseType(type) {
|
|
79
|
+
switch (type) {
|
|
80
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
81
|
+
}
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function initSync(module) {
|
|
87
|
+
if (wasm !== undefined) return wasm;
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
if (module !== undefined) {
|
|
91
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
92
|
+
({module} = module)
|
|
93
|
+
} else {
|
|
94
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const imports = __wbg_get_imports();
|
|
99
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
100
|
+
module = new WebAssembly.Module(module);
|
|
101
|
+
}
|
|
102
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
103
|
+
return __wbg_finalize_init(instance, module);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async function __wbg_init(module_or_path) {
|
|
107
|
+
if (wasm !== undefined) return wasm;
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
if (module_or_path !== undefined) {
|
|
111
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
112
|
+
({module_or_path} = module_or_path)
|
|
113
|
+
} else {
|
|
114
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (module_or_path === undefined) {
|
|
119
|
+
module_or_path = new URL('flowscripter_template_bun_wasm_rust_library_bg.wasm', import.meta.url);
|
|
120
|
+
}
|
|
121
|
+
const imports = __wbg_get_imports();
|
|
122
|
+
|
|
123
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
124
|
+
module_or_path = fetch(module_or_path);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
128
|
+
|
|
129
|
+
return __wbg_finalize_init(instance, module);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export { initSync, __wbg_init as default };
|
package/dist/src/lib.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../../src/lib.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../../src/lib.ts"],"names":[],"mappings":"AAWA;;GAEG;AACH,wBAAsB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAM3C"}
|
package/dist/src/lib.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// oxlint-disable-next-line typescript/triple-slash-reference -- ambient .wasm module type must ship alongside this file for consumers
|
|
2
|
+
/// <reference path="./wasm-module.d.ts" />
|
|
3
|
+
import init, { add } from "../pkg/flowscripter_template_bun_wasm_rust_library.js";
|
|
4
|
+
// TODO: when https://github.com/oven-sh/bun/pull/20503 is released I believe the following can be removed
|
|
5
|
+
import wasm from "../pkg/flowscripter_template_bun_wasm_rust_library_bg.wasm";
|
|
6
|
+
const wasmBuffer = typeof Bun !== "undefined"
|
|
7
|
+
? await Bun.file(wasm).arrayBuffer()
|
|
8
|
+
: await fetch(wasm).then((response) => response.arrayBuffer());
|
|
9
|
+
/**
|
|
10
|
+
* Adds 3 and 3 and logs the result as "World 6"
|
|
11
|
+
*/
|
|
12
|
+
export async function world() {
|
|
13
|
+
// init WASM module
|
|
14
|
+
// TODO: when https://github.com/oven-sh/bun/pull/20503 is released I believe the following can be simply `await init();`
|
|
15
|
+
await init({ module_or_path: wasmBuffer });
|
|
16
|
+
console.info(`World ${add(3, 3)}`);
|
|
17
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flowscripter/template-bun-wasm-rust-library",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.5",
|
|
4
4
|
"description": "Project template for a Rust library compiled to WASM exposed as a Bun module",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bun",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"access": "public"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
|
-
"build": "wasm-pack build --target web --release --no-pack && rm pkg/.gitignore &&
|
|
42
|
+
"build": "wasm-pack build --target web --release --no-pack && rm pkg/.gitignore && rm pkg/flowscripter_template_bun_wasm_rust_library_bg.wasm.d.ts && tsc -p tsconfig.build.json && mkdir -p dist/pkg && cp pkg/*.js pkg/*.wasm pkg/*.d.ts dist/pkg/"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@types/bun": "^1.3.14",
|
package/src/lib.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// oxlint-disable-next-line typescript/triple-slash-reference -- ambient .wasm module type must ship alongside this file for consumers
|
|
2
|
+
/// <reference path="./wasm-module.d.ts" />
|
|
1
3
|
import init, { add } from "../pkg/flowscripter_template_bun_wasm_rust_library.js";
|
|
2
4
|
|
|
3
5
|
// TODO: when https://github.com/oven-sh/bun/pull/20503 is released I believe the following can be removed
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"flowscripter_template_bun_wasm_rust_library.d.ts","sourceRoot":"","sources":["../../pkg/flowscripter_template_bun_wasm_rust_library.js"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;GAeG;AACH,uBAJW,MAAM,KACN,MAAM,GACJ,MAAM,CAKlB;AAgED,2CAkBC;AAED,+DAwBC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"world_test.d.ts","sourceRoot":"","sources":["../../tests/world_test.ts"],"names":[],"mappings":""}
|