@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/direct.mjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// The direct layer of @tinyactors/wasm: the same names, shapes, errors and
|
|
2
|
+
// lifetimes as @tinyactors/node's (lib/direct.mjs, the addon's exports),
|
|
3
|
+
// in JavaScript over the module (docs/browser.md). The convenience layer
|
|
4
|
+
// (lib/convenience.mjs) imports it as `#direct` under the export condition
|
|
5
|
+
// `tinyactors-wasm`, and the package's entries (index.mjs, init.mjs) export
|
|
6
|
+
// both. Nothing here touches the module before a call: an entry loads it.
|
|
7
|
+
export { Address } from './address.mjs';
|
|
8
|
+
export { compileCharts, compileSystem } from './compile.mjs';
|
|
9
|
+
export { CompileError, ResolveError, TinyactorsError } from './errors.mjs';
|
|
10
|
+
export { Host, SimulatedClock } from './host.mjs';
|
|
11
|
+
export { encodeHTTPPost, parseHTTPRequest } from './http.mjs';
|
|
12
|
+
export { decode, encode } from './values.mjs';
|
package/lib/errors.mjs
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// The errors, as the addon defines them (src/module.c, src/compile.c):
|
|
2
|
+
// TinyactorsError, an Error with read-only `code`, `reason`, `path` and
|
|
3
|
+
// `status` (core's name of a status, ta_status_name), each undefined when
|
|
4
|
+
// not given; CompileError and ResolveError, its subclasses. A poisoned
|
|
5
|
+
// module's error carries what poisoned it as its `cause`.
|
|
6
|
+
export class TinyactorsError extends Error {
|
|
7
|
+
constructor(message, options) {
|
|
8
|
+
const given = options ?? {};
|
|
9
|
+
super(message, given.cause !== undefined ? { cause: given.cause } : undefined);
|
|
10
|
+
Object.defineProperties(this, {
|
|
11
|
+
code: { value: given.code, enumerable: true },
|
|
12
|
+
reason: { value: given.reason, enumerable: true },
|
|
13
|
+
path: { value: given.path, enumerable: true },
|
|
14
|
+
status: { value: given.status, enumerable: true },
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
get name() { return 'TinyactorsError'; }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// A compilation with an error: every diagnostic, the message the first
|
|
22
|
+
// error's as a compiler prints it.
|
|
23
|
+
export class CompileError extends TinyactorsError {
|
|
24
|
+
constructor(message, options) {
|
|
25
|
+
const given = options ?? {};
|
|
26
|
+
super(message, { status: given.status ?? 'TA_ERROR_INVALID' });
|
|
27
|
+
Object.defineProperty(this, 'diagnostics', { value: Object.freeze([...(given.diagnostics ?? [])]), enumerable: true });
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
get name() { return 'CompileError'; }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// A resolver's refusal: a diagnostic of the resolved file at its line and
|
|
34
|
+
// column.
|
|
35
|
+
export class ResolveError extends TinyactorsError {
|
|
36
|
+
constructor(message, options) {
|
|
37
|
+
super(message, { status: 'TA_ERROR_INVALID' });
|
|
38
|
+
const given = options ?? {};
|
|
39
|
+
Object.defineProperties(this, {
|
|
40
|
+
line: { value: given.line, enumerable: true },
|
|
41
|
+
column: { value: given.column, enumerable: true },
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
get name() { return 'ResolveError'; }
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// A refusal of a call: core's status by its name.
|
|
49
|
+
export function refusal(status, message) {
|
|
50
|
+
return new TinyactorsError(message, { status });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// A reply's error (core wrote it: {code, message, data: {reason, path}}),
|
|
54
|
+
// or a refused config's: a TinyactorsError with `status` only when it is
|
|
55
|
+
// a call's (`status` given).
|
|
56
|
+
export function coreError(error, status) {
|
|
57
|
+
const options = {};
|
|
58
|
+
if (status !== undefined) options.status = status;
|
|
59
|
+
if (error === null || typeof error !== 'object') return new TinyactorsError(status ?? 'TA_ERROR_INVALID', options);
|
|
60
|
+
options.code = error.code;
|
|
61
|
+
if (error.data !== null && typeof error.data === 'object') {
|
|
62
|
+
options.reason = error.data.reason;
|
|
63
|
+
options.path = error.data.path;
|
|
64
|
+
}
|
|
65
|
+
return new TinyactorsError(error.message, options);
|
|
66
|
+
}
|