@thi.ng/wasm-api 1.0.1 → 1.1.0
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/CHANGELOG.md +10 -1
- package/README.md +27 -13
- package/api.d.ts +1 -0
- package/api.js +1 -0
- package/bridge.d.ts +1 -1
- package/bridge.js +5 -2
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2022-11-
|
|
3
|
+
- **Last updated**: 2022-11-28T13:36:49Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -9,6 +9,15 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
## [1.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/wasm-api@1.1.0) (2022-11-28)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- update panic handler, add event support ([ab940d9](https://github.com/thi-ng/umbrella/commit/ab940d9))
|
|
17
|
+
- update panic handler to broadcast event w/ panic message
|
|
18
|
+
- only throw Panic error if no listeners could be notified
|
|
19
|
+
- add `EVENT_PANIC` constant
|
|
20
|
+
|
|
12
21
|
# [1.0.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/wasm-api@1.0.0) (2022-11-23)
|
|
13
22
|
|
|
14
23
|
#### 🛑 Breaking changes
|
package/README.md
CHANGED
|
@@ -10,11 +10,12 @@ This project is part of the
|
|
|
10
10
|
[@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo.
|
|
11
11
|
|
|
12
12
|
- [About](#about)
|
|
13
|
-
|
|
13
|
+
- [Custom API modules](#custom-api-modules)
|
|
14
14
|
- [Building Zig projects with these hybrid API modules](#building-zig-projects-with-these-hybrid-api-modules)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
- [
|
|
15
|
+
- [String handling](#string-handling)
|
|
16
|
+
- [Memory allocations](#memory-allocations)
|
|
17
|
+
- [API module auto-initialization](#api-module-auto-initialization)
|
|
18
|
+
- [Object indices & handles](#object-indices--handles)
|
|
18
19
|
- [Status](#status)
|
|
19
20
|
- [Support packages](#support-packages)
|
|
20
21
|
- [Installation](#installation)
|
|
@@ -64,7 +65,7 @@ only bindings for these mentioned langs are included.
|
|
|
64
65
|
frontend/utility](https://github.com/thi-ng/umbrella/blob/develop/packages/wasm-api-bindgen/README.md#cli-generator)
|
|
65
66
|
for the code generator(s)
|
|
66
67
|
|
|
67
|
-
|
|
68
|
+
## Custom API modules
|
|
68
69
|
|
|
69
70
|
The
|
|
70
71
|
[`WasmBridge`](https://docs.thi.ng/umbrella/wasm-api/classes/WasmBridge.html)
|
|
@@ -126,7 +127,8 @@ export const bridge = new WasmBridge([new CustomAPI()]);
|
|
|
126
127
|
```
|
|
127
128
|
|
|
128
129
|
In Zig (or any other language of your choice) we can then utilize this custom
|
|
129
|
-
API like so (Please also see [example
|
|
130
|
+
API like so (Please also see [example
|
|
131
|
+
projects](https://github.com/thi-ng/umbrella/tree/develop/examples/zig-canvas/)
|
|
130
132
|
& other example snippets in this readme):
|
|
131
133
|
|
|
132
134
|
Bindings file / lib:
|
|
@@ -176,7 +178,7 @@ To avoid guesswork about the internals of these API modules, all of them are
|
|
|
176
178
|
using an overall uniform structure, with the main Zig entry point in
|
|
177
179
|
`/zig/lib.zig`...
|
|
178
180
|
|
|
179
|
-
|
|
181
|
+
## String handling
|
|
180
182
|
|
|
181
183
|
Most low-level languages deal with strings very differently and alas there's no
|
|
182
184
|
general standard. Some have UTF-8/16 support, others don't. In some languages
|
|
@@ -198,7 +200,7 @@ Finally, see more information in the
|
|
|
198
200
|
[@thi.ng/wasm-api-bindgen](https://github.com/thi-ng/umbrella/blob/develop/packages/wasm-api-bindgen/README.md#string-handling)
|
|
199
201
|
package readme.
|
|
200
202
|
|
|
201
|
-
|
|
203
|
+
## Memory allocations
|
|
202
204
|
|
|
203
205
|
If explicitly enabled on the WASM side, the `WasmBridge` includes support for
|
|
204
206
|
malloc/free-style allocations (within the linear WASM memory) from the JS side.
|
|
@@ -244,7 +246,18 @@ try {
|
|
|
244
246
|
}
|
|
245
247
|
```
|
|
246
248
|
|
|
247
|
-
###
|
|
249
|
+
### API module auto-initialization
|
|
250
|
+
|
|
251
|
+
The supplied child APIs
|
|
252
|
+
([wasm-api-dom](https://github.com/thi-ng/umbrella/tree/develop/packages/wasm-api-dom),
|
|
253
|
+
[wasm-api-schedule](https://github.com/thi-ng/umbrella/tree/develop/packages/wasm-api-schedule)
|
|
254
|
+
etc.) use an auto-intialization hook related to the above `WASM_ALLOCATOR`
|
|
255
|
+
mechanism: If that allocator is available, the WASM side of these modules will
|
|
256
|
+
auto initialize and thus reduce boilerplate. However, if no such central
|
|
257
|
+
allocator is defined and/or a custom allocator should be used, then these API
|
|
258
|
+
modules will be have to be initialized manually.
|
|
259
|
+
|
|
260
|
+
## Object indices & handles
|
|
248
261
|
|
|
249
262
|
Since only numeric values can be exchanged between the WASM module and the JS
|
|
250
263
|
host, any JS native objects the WASM side might want to be working with must be
|
|
@@ -291,13 +304,14 @@ canvases.delete(0);
|
|
|
291
304
|
// true
|
|
292
305
|
```
|
|
293
306
|
|
|
294
|
-
|
|
307
|
+
The supplied Zig core library also includes a
|
|
295
308
|
[`ManagedIndex`](https://github.com/thi-ng/umbrella/blob/develop/packages/wasm-api/zig/managed-index.zig)
|
|
296
|
-
for similar
|
|
309
|
+
for similar resource management on the Zig side of the application. For example,
|
|
310
|
+
in the
|
|
297
311
|
[@thi.ng/wasm-api-dom](https://github.com/thi-ng/umbrella/blob/develop/packages/wasm-api-dom/)
|
|
298
312
|
&
|
|
299
313
|
[@thi.ng/wasm-api-schedule](https://github.com/thi-ng/umbrella/blob/develop/packages/wasm-api-schedule/)
|
|
300
|
-
packages this is used to manage Zig event listeners.
|
|
314
|
+
packages this is used to manage Zig-side event listeners.
|
|
301
315
|
|
|
302
316
|
## Status
|
|
303
317
|
|
|
@@ -334,7 +348,7 @@ node --experimental-repl-await
|
|
|
334
348
|
> const wasmApi = await import("@thi.ng/wasm-api");
|
|
335
349
|
```
|
|
336
350
|
|
|
337
|
-
Package sizes (gzipped, pre-treeshake): ESM: 2.
|
|
351
|
+
Package sizes (gzipped, pre-treeshake): ESM: 2.73 KB
|
|
338
352
|
|
|
339
353
|
## Dependencies
|
|
340
354
|
|
package/api.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Fn, IDeref, ILength } from "@thi.ng/api";
|
|
2
2
|
import type { WasmBridge } from "./bridge.js";
|
|
3
3
|
export declare const EVENT_MEMORY_CHANGED = "memory-changed";
|
|
4
|
+
export declare const EVENT_PANIC = "panic";
|
|
4
5
|
export declare type BigIntArray = bigint[] | BigInt64Array | BigUint64Array;
|
|
5
6
|
export declare type ReadonlyWasmString = IDeref<string> & ILength & {
|
|
6
7
|
readonly addr: number;
|
package/api.js
CHANGED
package/bridge.d.ts
CHANGED
|
@@ -181,6 +181,6 @@ export declare class WasmBridge<T extends WasmExports = WasmExports> implements
|
|
|
181
181
|
/** {@inheritDoc @thi.ng/api#INotify.removeListener} */
|
|
182
182
|
removeListener(id: string, fn: Listener, scope?: any): boolean;
|
|
183
183
|
/** {@inheritDoc @thi.ng/api#INotify.notify} */
|
|
184
|
-
notify(event: Event):
|
|
184
|
+
notify(event: Event): boolean;
|
|
185
185
|
}
|
|
186
186
|
//# sourceMappingURL=bridge.d.ts.map
|
package/bridge.js
CHANGED
|
@@ -5,7 +5,7 @@ import { assert } from "@thi.ng/errors/assert";
|
|
|
5
5
|
import { defError } from "@thi.ng/errors/deferror";
|
|
6
6
|
import { hexdumpLines, U16, U32, U64BIG, U8 } from "@thi.ng/hex";
|
|
7
7
|
import { ConsoleLogger } from "@thi.ng/logger/console";
|
|
8
|
-
import { EVENT_MEMORY_CHANGED, } from "./api.js";
|
|
8
|
+
import { EVENT_MEMORY_CHANGED, EVENT_PANIC, } from "./api.js";
|
|
9
9
|
export const Panic = defError(() => "Panic");
|
|
10
10
|
export const OutOfMemoryError = defError(() => "Out of memory");
|
|
11
11
|
/**
|
|
@@ -69,7 +69,10 @@ let WasmBridge = class WasmBridge {
|
|
|
69
69
|
debugger;
|
|
70
70
|
},
|
|
71
71
|
_panic: (addr, len) => {
|
|
72
|
-
|
|
72
|
+
const msg = this.getString(addr, len);
|
|
73
|
+
if (!this.notify({ id: EVENT_PANIC, value: msg })) {
|
|
74
|
+
throw new Panic(msg);
|
|
75
|
+
}
|
|
73
76
|
},
|
|
74
77
|
timer: () => performance.now(),
|
|
75
78
|
epoch: () => BigInt(Date.now()),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/wasm-api",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Generic, modular, extensible API bridge and infrastructure for hybrid JS & WebAssembly projects",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -35,12 +35,12 @@
|
|
|
35
35
|
"test:build-zig": "zig build-lib -O ReleaseSmall -target wasm32-freestanding -dynamic --strip --pkg-begin wasmapi zig/lib.zig --pkg-end test/custom.zig && wasm-dis -o custom.wast custom.wasm && cp custom.wasm test"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@thi.ng/api": "^8.
|
|
39
|
-
"@thi.ng/arrays": "^2.4.
|
|
38
|
+
"@thi.ng/api": "^8.5.0",
|
|
39
|
+
"@thi.ng/arrays": "^2.4.3",
|
|
40
40
|
"@thi.ng/checks": "^3.3.3",
|
|
41
41
|
"@thi.ng/errors": "^2.2.4",
|
|
42
42
|
"@thi.ng/hex": "^2.3.0",
|
|
43
|
-
"@thi.ng/idgen": "^2.1.
|
|
43
|
+
"@thi.ng/idgen": "^2.1.19",
|
|
44
44
|
"@thi.ng/logger": "^1.4.3"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
@@ -110,5 +110,5 @@
|
|
|
110
110
|
"status": "alpha",
|
|
111
111
|
"year": 2022
|
|
112
112
|
},
|
|
113
|
-
"gitHead": "
|
|
113
|
+
"gitHead": "75ec32ff7f1b7b5e72e7a04ace24732cd5d6c774\n"
|
|
114
114
|
}
|