@tinyactors/wasm 0.3.0 → 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/README.md +15 -6
- package/index.d.ts +899 -590
- package/index.mjs +3 -4
- package/init.mjs +0 -1
- package/lib/checks.mjs +3 -1
- package/lib/compile.mjs +27 -16
- package/lib/convenience.mjs +815 -101
- package/lib/datamodel.mjs +59 -398
- package/lib/direct.mjs +6 -4
- package/lib/errors.mjs +28 -0
- package/lib/host.mjs +191 -34
- package/lib/http.mjs +19 -0
- package/lib/realm-script.mjs +1 -1
- package/lib/version.mjs +5 -0
- package/package.json +1 -1
- package/tinyactors.wasm +0 -0
package/index.mjs
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
// @tinyactors/wasm: the package's names, its module loaded with top-level
|
|
2
2
|
// await (the bundled tinyactors.wasm, beside this file), so
|
|
3
|
-
// `import { Host } from '@tinyactors/wasm'` is the line it is in Node:
|
|
4
|
-
//
|
|
5
|
-
// (
|
|
3
|
+
// `import { Host } from '@tinyactors/wasm'` is the line it is in Node: what
|
|
4
|
+
// the application layer (../lib/convenience.mjs) exports, over the direct
|
|
5
|
+
// layer (lib/direct.mjs), which it imports as `#direct`.
|
|
6
6
|
import { init } from './lib/state.mjs';
|
|
7
7
|
|
|
8
8
|
await init();
|
|
9
9
|
|
|
10
|
-
export * from './lib/direct.mjs';
|
|
11
10
|
export * from './lib/convenience.mjs';
|
package/init.mjs
CHANGED
package/lib/checks.mjs
CHANGED
|
@@ -5,10 +5,12 @@
|
|
|
5
5
|
// A session an input takes: a bigint from 1 to 2^64-1, or a number that is
|
|
6
6
|
// a safe integer from 1; as a bigint.
|
|
7
7
|
export function sessionOf(value) {
|
|
8
|
+
// an Actor (the application layer's): its id, a bigint
|
|
9
|
+
if (value !== null && typeof value === 'object' && typeof value.id === 'bigint') value = value.id;
|
|
8
10
|
if (typeof value === 'bigint') {
|
|
9
11
|
if (value >= 1n && value < 1n << 64n) return value;
|
|
10
12
|
} else if (typeof value === 'number' && Number.isSafeInteger(value) && value >= 1) return BigInt(value);
|
|
11
|
-
throw new TypeError('a session is a bigint from 1 to 2^64-1 or a safe integer from 1');
|
|
13
|
+
throw new TypeError('a session is an Actor, a bigint from 1 to 2^64-1 or a safe integer from 1');
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
// A non-negative integer at most `limit` (2^32-1 unless said).
|
package/lib/compile.mjs
CHANGED
|
@@ -18,7 +18,10 @@
|
|
|
18
18
|
// After a compilation that succeeded, every expression and script of an
|
|
19
19
|
// "ecmascript" chart is parsed by the engine in the native datamodel's
|
|
20
20
|
// shapes, nothing run (the addon's check): each syntax error a warning at
|
|
21
|
-
// its line, an error with warningsAsErrors
|
|
21
|
+
// its line, an error with warningsAsErrors, and so is a script's top-level
|
|
22
|
+
// declaration the native datamodel refuses (let, const, class) or makes a
|
|
23
|
+
// variable of the session (var), asked of the application's kit (realm.js,
|
|
24
|
+
// `advice`). The parser is node:vm's Script
|
|
22
25
|
// in node and bun (the addon's), the realm's Function in a browser, where
|
|
23
26
|
// a page finds the error's line and column by a <script> element that
|
|
24
27
|
// does not parse (it runs nothing: the source is inside a function
|
|
@@ -26,7 +29,7 @@
|
|
|
26
29
|
// policy that refuses string evaluation (realms.mjs, policyRefusal) the
|
|
27
30
|
// check is skipped: the native datamodel cannot run there either.
|
|
28
31
|
import { CompileError, ResolveError, TinyactorsError, refusal } from './errors.mjs';
|
|
29
|
-
import { policyRefusal } from './realms.mjs';
|
|
32
|
+
import { application, policyRefusal } from './realms.mjs';
|
|
30
33
|
import { instance } from './state.mjs';
|
|
31
34
|
|
|
32
35
|
const SEVERITIES = ['note', 'warning', 'error'];
|
|
@@ -183,15 +186,15 @@ const VALUE_SHAPE = ["(function(){'use strict';return (\n", '\n);})', 'expr'];
|
|
|
183
186
|
|
|
184
187
|
// The shape an expression is checked in (the datamodel's own), or null
|
|
185
188
|
// for <content> (JSON, XML or text, not ECMAScript).
|
|
186
|
-
function shapeOf(kind
|
|
189
|
+
function shapeOf(kind) {
|
|
187
190
|
switch (kind) {
|
|
188
191
|
case KIND.CONDITION: return [VALUE_SHAPE[0], VALUE_SHAPE[1], 'cond'];
|
|
189
192
|
case KIND.VALUE:
|
|
190
193
|
case KIND.STRING: return VALUE_SHAPE;
|
|
191
194
|
case KIND.LOCATION: return ["(function(__v){'use strict';(\n", '\n) = __v;})', 'location'];
|
|
192
195
|
case KIND.ITEM: return ["(function(__v){'use strict';(\n", '\n) = __v;})', 'item'];
|
|
193
|
-
case KIND.GLOBAL_SCRIPT:
|
|
194
|
-
case KIND.SCRIPT: return
|
|
196
|
+
case KIND.GLOBAL_SCRIPT:
|
|
197
|
+
case KIND.SCRIPT: return ["(function(){'use strict';\n", '\n})', '<script>'];
|
|
195
198
|
default: return null;
|
|
196
199
|
}
|
|
197
200
|
}
|
|
@@ -263,11 +266,15 @@ function checkImage(module, result, errors) {
|
|
|
263
266
|
if (module.call('ta_web_image_expression', module.env, image, e) !== 0) continue;
|
|
264
267
|
const x = module.words().slice(module.record, module.record + 6);
|
|
265
268
|
const info = { kind: x[1], line: x[2], column: x[3], source: module.string(x[4], x[5]) };
|
|
266
|
-
const shape = shapeOf(info.kind
|
|
269
|
+
const shape = shapeOf(info.kind);
|
|
267
270
|
if (shape === null) continue;
|
|
268
271
|
const script = info.kind === KIND.SCRIPT || info.kind === KIND.GLOBAL_SCRIPT;
|
|
269
272
|
const source = script ? info.source : info.source.replace(/[; \t\n\r]+$/, '');
|
|
270
|
-
|
|
273
|
+
let failure = checker(shape[0] + source + shape[1]), label = 'SyntaxError: ';
|
|
274
|
+
if (failure === null && script) { // it parses: a top-level declaration the native datamodel refuses or keeps
|
|
275
|
+
const advice = application().advice(info.source);
|
|
276
|
+
if (advice !== null) [failure, label] = [[advice, 2, 1], ''];
|
|
277
|
+
}
|
|
271
278
|
if (failure === null) continue;
|
|
272
279
|
const [message, inShape] = failure;
|
|
273
280
|
let column = failure[2];
|
|
@@ -283,17 +290,21 @@ function checkImage(module, result, errors) {
|
|
|
283
290
|
file,
|
|
284
291
|
line: info.line + sourceLine - 1,
|
|
285
292
|
column: sourceLine === 1 ? info.column : column,
|
|
286
|
-
message: `${shape[2]}:
|
|
293
|
+
message: `${shape[2]}: ${label}${message}`,
|
|
287
294
|
}));
|
|
288
295
|
}
|
|
289
296
|
}
|
|
290
297
|
return found;
|
|
291
298
|
}
|
|
292
299
|
|
|
293
|
-
function compileWith(manifest, [given,
|
|
294
|
-
let flags = 0;
|
|
300
|
+
function compileWith(manifest, [given, options], usage) {
|
|
301
|
+
let flags = 0, resolver;
|
|
295
302
|
if (options !== undefined) {
|
|
296
|
-
if (options === null || typeof options !== 'object') throw new TypeError('a compile call\'s options are an object: {warningsAsErrors}');
|
|
303
|
+
if (options === null || typeof options !== 'object') throw new TypeError('a compile call\'s options are an object: {resolver, warningsAsErrors}');
|
|
304
|
+
for (const key of Object.keys(options)) {
|
|
305
|
+
if (key !== 'resolver' && key !== 'warningsAsErrors') throw new TypeError('a compile call\'s options are {resolver, warningsAsErrors}');
|
|
306
|
+
}
|
|
307
|
+
resolver = options.resolver;
|
|
297
308
|
const werror = options.warningsAsErrors;
|
|
298
309
|
if (werror !== undefined && typeof werror !== 'boolean') throw new TypeError('warningsAsErrors is a boolean');
|
|
299
310
|
if (werror) flags |= WERROR;
|
|
@@ -367,13 +378,13 @@ function compileWith(manifest, [given, resolver, options], usage) {
|
|
|
367
378
|
}
|
|
368
379
|
}
|
|
369
380
|
|
|
370
|
-
// each takes (sources or manifest,
|
|
371
|
-
export function compileCharts(sources,
|
|
372
|
-
return compileWith(false, [...arguments], 'compileCharts(sources,
|
|
381
|
+
// each takes (sources or manifest, options?): their lengths are 2
|
|
382
|
+
export function compileCharts(sources, options) { // eslint-disable-line no-unused-vars
|
|
383
|
+
return compileWith(false, [...arguments], 'compileCharts(sources, options?): sources an array of {name, text} of strings');
|
|
373
384
|
}
|
|
374
385
|
|
|
375
|
-
export function compileSystem(manifest,
|
|
376
|
-
return compileWith(true, [...arguments], 'compileSystem(manifest,
|
|
386
|
+
export function compileSystem(manifest, options) { // eslint-disable-line no-unused-vars
|
|
387
|
+
return compileWith(true, [...arguments], 'compileSystem(manifest, options?): the manifest a {name, text} of strings');
|
|
377
388
|
}
|
|
378
389
|
|
|
379
390
|
export { TinyactorsError };
|