@tinyactors/wasm 0.0.0-stage → 0.4.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Dario Hamidi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,85 @@
1
- # Temporary Holding Version
1
+ # @tinyactors/wasm
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ SCXML statecharts as actors, in the browser, a Worker, Node.js and Bun:
4
+ the tinyactors host compiled to WebAssembly, with the API of
5
+ [`@tinyactors/node`](https://www.npmjs.com/package/@tinyactors/node), the
6
+ same classes, methods, handlers, values, errors and types. Both packages
7
+ are one release: the same version and the same changelog.
8
+
9
+ ```sh
10
+ npm install @tinyactors/wasm
11
+ ```
12
+
13
+ ```js
14
+ import { compileCharts, Host } from '@tinyactors/wasm';
15
+
16
+ const compiled = compileCharts([{ name: 'hello.scxml', text: `
17
+ <scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0"
18
+ datamodel="ecmascript" name="hello" initial="s">
19
+ <state id="s"><onentry><log expr="'hello from ' + _ioprocessors.scxml.location"/></onentry></state>
20
+ </scxml>` }]);
21
+ const host = new Host(compiled, { system: 'web', log: (entry) => console.log(entry.text) });
22
+ compiled.close();
23
+ host.spawn('hello');
24
+ await host.idle();
25
+ host.close();
26
+ ```
27
+
28
+ The default entry loads the module with top-level `await`, so every name
29
+ works once the import settles. Where a module graph cannot hold
30
+ top-level `await` (a Service Worker), or a bundler does not place
31
+ `tinyactors.wasm`, import `@tinyactors/wasm/init` and `await init()`
32
+ first. No bundler is needed: a page imports the package's `index.mjs`
33
+ (through an import map, or by its path), and a module Worker by its
34
+ path.
35
+
36
+ ## What it needs
37
+
38
+ - **Engines:** WebAssembly with `extended-const`, `multivalue`,
39
+ `bulk-memory` and `nontrapping-fptoint`, top-level `await` and
40
+ `String.prototype.isWellFormed`: by the engines' release notes Chrome
41
+ and Edge 114, Firefox 119 and Safari 16.4 (only Chromium is tested);
42
+ Node.js 22.3 and Bun 1.4.
43
+ - **A Content Security Policy** that allows the module and the charts'
44
+ expressions: `script-src 'self' 'wasm-unsafe-eval' 'unsafe-eval'`
45
+ (on quickjs `'wasm-unsafe-eval'` is enough).
46
+ - **TypeScript:** the `es2022` and `dom` libs; the types declare
47
+ `Symbol.dispose` and `Disposable` themselves, so no `esnext` lib is
48
+ needed.
49
+ - **Size** (measured by `mise run pack:wasm`, 2026-10-18): the package
50
+ is 534 KiB packed and 1434 KiB unpacked; the module, `tinyactors.wasm`
51
+ (built for size, `-Oz`, quickjs in it), is 1150 KiB, 456 KiB with gzip
52
+ and 378 KiB with brotli, as a server sends it; without quickjs it was
53
+ 137 KiB with brotli.
54
+ - **quickjs:** `datamodel: 'quickjs'`, the sandbox for charts you do
55
+ not trust, is in the same module: a page whose policy forbids
56
+ `'unsafe-eval'` uses it.
57
+
58
+ ## Documentation
59
+
60
+ The guides are shared with `@tinyactors/node`:
61
+
62
+ - [In the browser](https://github.com/tinyactors-dev/tinyactors-napi/blob/main/docs/guide/browser.md):
63
+ what differs here (loading, the CSP, bytes as `Uint8Array`, Workers,
64
+ IndexedDB, memory) and what a browser asks of you.
65
+ - [@tinyactors/node's README](https://github.com/tinyactors-dev/tinyactors-napi#readme):
66
+ the concepts, from a first chart to hosts, actors, I/O processors and
67
+ errors.
68
+ - [The guides](https://github.com/tinyactors-dev/tinyactors-napi/tree/main/docs/guide),
69
+ in three groups, as the README orders them:
70
+ - **writing an application:** charts, I/O processors, when the actor
71
+ is not there, services, hibernation with a store, testing, the
72
+ quickjs sandbox;
73
+ - **operating a host** (the README's
74
+ [Operating a host](https://github.com/tinyactors-dev/tinyactors-napi#operating-a-host)):
75
+ inspection, capacity, telemetry, hibernation by a policy of your own,
76
+ migration, snapshots;
77
+ - **the wire format** (the README's
78
+ [Wire format](https://github.com/tinyactors-dev/tinyactors-napi#wire-format)):
79
+ `encode` and `decode`, `decodeTraces`, addresses, other systems and
80
+ SCXML's BasicHTTP.
81
+
82
+ Charts are trusted code: their expressions run as JavaScript in a realm
83
+ of their own, which is not a security boundary.
84
+
85
+ MIT licensed.