@tinyactors/wasm 0.0.0-stage → 0.3.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 +21 -0
- package/README.md +75 -2
- package/index.d.ts +1221 -0
- package/index.mjs +11 -0
- package/init.d.ts +16 -0
- package/init.mjs +7 -0
- package/lib/address.mjs +112 -0
- package/lib/cbor.mjs +262 -0
- package/lib/checks.mjs +54 -0
- package/lib/compile.mjs +379 -0
- package/lib/convenience.mjs +162 -0
- package/lib/datamodel.mjs +1341 -0
- package/lib/direct.mjs +12 -0
- package/lib/errors.mjs +66 -0
- package/lib/host.mjs +2049 -0
- package/lib/http.mjs +85 -0
- package/lib/module.mjs +324 -0
- package/lib/quickjs.mjs +78 -0
- package/lib/realm-script.mjs +2 -0
- package/lib/realms.mjs +122 -0
- package/lib/state.mjs +32 -0
- package/lib/values.mjs +31 -0
- package/package.json +51 -4
- package/tinyactors.wasm +0 -0
package/lib/state.mjs
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// The module instance the package's classes use: loaded once by init(),
|
|
2
|
+
// which both entries share (index.mjs awaits it at the top level;
|
|
3
|
+
// init.mjs leaves it to the application, for a Service Worker or a
|
|
4
|
+
// bundler without top-level await). A call before it settles throws
|
|
5
|
+
// TA_ERROR_STATE.
|
|
6
|
+
import { TinyactorsError } from './errors.mjs';
|
|
7
|
+
import { load } from './module.mjs';
|
|
8
|
+
|
|
9
|
+
let current = null;
|
|
10
|
+
let loading = null;
|
|
11
|
+
|
|
12
|
+
// Loads the module once: the bundled tinyactors.wasm, or `source` (a URL,
|
|
13
|
+
// a Response, bytes or a WebAssembly.Module). Later calls answer the same
|
|
14
|
+
// instance, whatever they pass.
|
|
15
|
+
export function init(source) {
|
|
16
|
+
if (loading === null) {
|
|
17
|
+
loading = load(source).then((module) => {
|
|
18
|
+
current = module;
|
|
19
|
+
return module;
|
|
20
|
+
}, (error) => {
|
|
21
|
+
loading = null;
|
|
22
|
+
throw error;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return loading.then(() => undefined);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// The instance, once init() settled.
|
|
29
|
+
export function instance() {
|
|
30
|
+
if (current === null) throw new TinyactorsError('@tinyactors/wasm is not loaded: await init() first', { status: 'TA_ERROR_STATE' });
|
|
31
|
+
return current;
|
|
32
|
+
}
|
package/lib/values.mjs
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// encode and decode, as the addon defines them (src/values.c): the one
|
|
2
|
+
// conversion the API uses, streaming through core's writer and reader
|
|
3
|
+
// (cbor.mjs), the call's text and bytes in the environment's arena, a mark
|
|
4
|
+
// per call. encode writes an Address as tag 32 on its text, decode reads
|
|
5
|
+
// tag 32 as an Address.
|
|
6
|
+
import * as cbor from './cbor.mjs';
|
|
7
|
+
import { bytesOf } from './checks.mjs';
|
|
8
|
+
import { instance } from './state.mjs';
|
|
9
|
+
|
|
10
|
+
// encode(value) -> Uint8Array: the value's CBOR, copied once out of the
|
|
11
|
+
// call's arena.
|
|
12
|
+
export function encode(value) {
|
|
13
|
+
const module = instance();
|
|
14
|
+
const scratch = module.scratch;
|
|
15
|
+
return module.scoped(scratch, () => {
|
|
16
|
+
const [at, length] = cbor.write(module, scratch, value, { addresses: true });
|
|
17
|
+
return module.copyOut(at, length);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// decode(bytes) -> value: a Uint8Array or an ArrayBuffer, read during the
|
|
22
|
+
// call.
|
|
23
|
+
export function decode(bytes) {
|
|
24
|
+
const view = bytesOf(bytes, 'decode takes a Uint8Array or an ArrayBuffer');
|
|
25
|
+
const module = instance();
|
|
26
|
+
const scratch = module.scratch;
|
|
27
|
+
return module.scoped(scratch, () => {
|
|
28
|
+
const [at, length] = module.copyIn(scratch, view);
|
|
29
|
+
return cbor.read(module, scratch, at, length, { addresses: true });
|
|
30
|
+
});
|
|
31
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinyactors/wasm",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "SCXML statecharts as actors on the tinyactors host, in the browser, Node.js and Bun (WebAssembly; the API of @tinyactors/node)",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"actor",
|
|
7
|
+
"actors",
|
|
8
|
+
"statechart",
|
|
9
|
+
"scxml",
|
|
10
|
+
"state-machine",
|
|
11
|
+
"wasm",
|
|
12
|
+
"webassembly",
|
|
13
|
+
"browser"
|
|
14
|
+
],
|
|
15
|
+
"homepage": "https://github.com/tinyactors-dev/tinyactors-napi#readme",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/tinyactors-dev/tinyactors.git",
|
|
19
|
+
"directory": "tinyactors-napi"
|
|
20
|
+
},
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/tinyactors-dev/tinyactors/issues"
|
|
23
|
+
},
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=22.3.0"
|
|
27
|
+
},
|
|
28
|
+
"type": "module",
|
|
29
|
+
"types": "./index.d.ts",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./index.d.ts",
|
|
33
|
+
"default": "./index.mjs"
|
|
34
|
+
},
|
|
35
|
+
"./init": {
|
|
36
|
+
"types": "./init.d.ts",
|
|
37
|
+
"default": "./init.mjs"
|
|
38
|
+
},
|
|
39
|
+
"./tinyactors.wasm": "./tinyactors.wasm",
|
|
40
|
+
"./package.json": "./package.json"
|
|
41
|
+
},
|
|
42
|
+
"sideEffects": false,
|
|
43
|
+
"files": [
|
|
44
|
+
"index.mjs",
|
|
45
|
+
"init.mjs",
|
|
46
|
+
"init.d.ts",
|
|
47
|
+
"lib",
|
|
48
|
+
"tinyactors.wasm",
|
|
49
|
+
"index.d.ts",
|
|
50
|
+
"README.md",
|
|
51
|
+
"LICENSE"
|
|
52
|
+
]
|
|
53
|
+
}
|
package/tinyactors.wasm
ADDED
|
Binary file
|