@northtalk/ts 0.2.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 +16 -14
- package/{base64-DORMd3Hv.js → base64-Dtqaz_0A.js} +880 -409
- package/{binary-value-CEmh60GC.d.ts → binary-value-Bb6HPDtM.d.ts} +2 -2
- package/{capabilities-CH0FkRMq.js → capabilities-Bi5Qm6Fr.js} +39 -20
- package/{checker-Dc1jl2WH.js → checker-DMI4LiRm.js} +321 -112
- package/core-BzGUgjL6.d.ts +22 -0
- package/{debug-CQBxKnJB.d.ts → debug-C72o2pZy.d.ts} +506 -50
- package/debug.d.ts +3 -3
- package/debug.js +1 -1
- package/driver-ClV_UDEK.d.ts +63 -0
- package/driver.d.ts +2 -40
- package/driver.js +24 -4
- package/{encoding-nlrpj-Pb.js → encoding-C3Q7pIC9.js} +2 -2
- package/{engine-BGaJ9dAk.js → engine-BpdGfAND.js} +6 -6
- package/{engine-vbYInVYF.d.ts → engine-Dtby_FkE.d.ts} +3 -3
- package/{errors-LYJZ_c8h.js → errors-BKJES3Zu.js} +1060 -751
- package/{group-B742gg4T.js → group-vuUL2tq-.js} +6526 -1725
- package/http.d.ts +2 -2
- package/http.js +3 -3
- package/index-ByF5j53i.d.ts +779 -0
- package/index.d.ts +6 -651
- package/index.js +23 -15
- package/{http-capability-CSTkw1Yt.js → inline-grants-Cx0Z9XAt.js} +109 -24
- package/manifest-Dw-8Unmf.js +256 -0
- package/message-layer.d.ts +3 -3
- package/message-layer.js +2 -2
- package/notify.d.ts +2 -2
- package/notify.js +1 -1
- package/{objects-Db7IB5vQ.js → objects-BC4fS0vq.js} +1 -1
- package/{objects-DJ3QtCCs.d.ts → objects-Dnqor7Gn.d.ts} +12 -4
- package/{operation-promises-EgZXG5N_.js → operation-promises-ClA1BTaS.js} +10 -5
- package/package.json +2 -2
- package/{readers-CjJHKHvH.js → readers-B5e5bBrY.js} +2 -2
- package/{readers-BFPuosPk.d.ts → readers-DAFVvvq4.d.ts} +2 -2
- package/{request-pump-binary-DdY3X-yl.js → request-pump-binary-BjnyqXV5.js} +4 -4
- package/{router--71qvxtY.js → router-BCHEfs4x.js} +5 -5
- package/{router-Zhrw5l__.d.ts → router-BspOCPA0.d.ts} +3 -3
- package/session.d.ts +41 -3
- package/session.js +260 -179
- package/setup.d.ts +2 -2
- package/setup.js +4 -4
- package/sha256-9CGf5BS_.js +168 -0
- package/sqlite.d.ts +5 -5
- package/sqlite.js +27 -21
- package/{store-hJrRULMx.js → store-DTQa0lyE.js} +2 -2
- package/{store-capability-OZp4hXmj.js → store-capability-BxXgiRM7.js} +4 -4
- package/store.d.ts +3 -3
- package/store.js +2 -2
- package/{user-capability-BK4Asg7D.js → user-capability-5-IvCeZI.js} +5 -5
- package/wasm.d.ts +12 -8
- package/wasm.js +67 -39
- package/core-DptnvQT9.d.ts +0 -14
- package/manifest-BscyH_rW.d.ts +0 -70
- package/manifest-DjsxDSuB.js +0 -129
- package/sha256-B_kyYw3Z.js +0 -124
package/index.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
import {
|
|
3
|
-
import { t as defineObjectKind } from "./objects-
|
|
4
|
-
import {
|
|
5
|
-
import { a as
|
|
6
|
-
import {
|
|
7
|
-
import { _ as
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { a as fromValue, i as
|
|
12
|
-
import { n as localeCapability, t as userCapability } from "./user-capability-
|
|
13
|
-
import { a as clockCapability, i as calendarCapability, l as timerCapability, o as consoleCapability, r as storeCapability, t as add } from "./store-capability-
|
|
2
|
+
import { G as record, H as quantity, Kt as formatInstant, L as nothing, N as map, Q as text, R as num, T as instant, W as range, Yt as nowMicros, Zt as parseInstant, c as Decimal, d as bytes, dt as builtins, gt as units, i as ScriptError, k as list, l as Value, m as civilDate, n as LoadError, pt as grammar, r as MailboxFull, t as HostError, u as bool, un as unicodeVersion, v as dec } from "./errors-BKJES3Zu.js";
|
|
3
|
+
import { t as defineObjectKind } from "./objects-BC4fS0vq.js";
|
|
4
|
+
import { h as Lexer, i as defineCapability, p as validMessageSelector, t as LimitReached, u as shape } from "./capabilities-Bi5Qm6Fr.js";
|
|
5
|
+
import { a as syntaxText, c as parseSource, i as syntaxSelector, l as parseSourceRecovering, o as ParseError, p as declarationStart, r as checkSyntax, s as parseEntry, t as checkSource, v as kindNames } from "./checker-DMI4LiRm.js";
|
|
6
|
+
import { W as waitUs, ft as costModel, mt as languageVersion, r as NotImplementedError, tt as disassemble, u as canConvert } from "./base64-Dtqaz_0A.js";
|
|
7
|
+
import { S as lowerTree, _ as deliver, b as compileSource, c as codeIdentity, d as stdlibSources, f as Run, g as defaultLimits, h as callFunction, i as restore, l as compileLibrary, m as UnitLoadError, n as TsScript, p as Script, r as newGroup, s as stateFingerprint, t as TsGroup, v as loadScript, x as exportsOf, y as LoweringError } from "./group-vuUL2tq-.js";
|
|
8
|
+
import { n as exportManifest } from "./manifest-Dw-8Unmf.js";
|
|
9
|
+
import { c as readDisplay, r as decodeValue } from "./readers-B5e5bBrY.js";
|
|
10
|
+
import { t as encodeValue } from "./encoding-C3Q7pIC9.js";
|
|
11
|
+
import { a as sqliteCapability, c as fromValue, i as httpCapability, l as toValue, n as createGroup$1, o as decodeJson, r as handlersOf, s as encodeJson, t as inlineGrants, u as talk } from "./inline-grants-Cx0Z9XAt.js";
|
|
12
|
+
import { n as localeCapability, t as userCapability } from "./user-capability-5-IvCeZI.js";
|
|
13
|
+
import { a as clockCapability, i as calendarCapability, l as timerCapability, o as consoleCapability, r as storeCapability, t as add } from "./store-capability-BxXgiRM7.js";
|
|
14
14
|
//#region src/versions.ts
|
|
15
15
|
const coreVersions = Object.freeze({
|
|
16
16
|
language: languageVersion,
|
|
17
17
|
costModel: String(costModel.version),
|
|
18
18
|
unicode: unicodeVersion,
|
|
19
|
-
core: "ts/0.
|
|
20
|
-
saveFormat: String(
|
|
19
|
+
core: "ts/0.4.0",
|
|
20
|
+
saveFormat: String(1)
|
|
21
21
|
});
|
|
22
22
|
//#endregion
|
|
23
23
|
//#region src/core.ts
|
|
@@ -36,9 +36,17 @@ const core = Object.freeze({
|
|
|
36
36
|
compileLibrary,
|
|
37
37
|
newGroup,
|
|
38
38
|
restore,
|
|
39
|
+
stateFingerprint,
|
|
39
40
|
versions: coreVersions
|
|
40
41
|
});
|
|
41
42
|
/** Return the process-wide Core, also used by the free-function helpers. */
|
|
42
43
|
const createCore = () => core;
|
|
43
44
|
//#endregion
|
|
44
|
-
|
|
45
|
+
//#region src/create-group.ts
|
|
46
|
+
/** Creates a driven Group that supports `await using` and explicit close(reason). */
|
|
47
|
+
const createGroup = (o) => createGroup$1({
|
|
48
|
+
...o,
|
|
49
|
+
core: o.core ?? createCore()
|
|
50
|
+
});
|
|
51
|
+
//#endregion
|
|
52
|
+
export { Script as CompiledScript, Decimal, HostError, Lexer, LimitReached, LoadError, LoweringError, MailboxFull, NotImplementedError, ParseError, Run, ScriptError, TsGroup, TsScript, UnitLoadError, Value, add, bool, builtins, bytes, calendarCapability, callFunction, canConvert, checkSource, checkSyntax, civilDate, clockCapability, codeIdentity, compileLibrary, compileSource, consoleCapability, coreVersions, createCore, createGroup, dec, declarationStart, decodeJson, decodeValue, defaultLimits, defineCapability, defineObjectKind, deliver, disassemble, encodeJson, encodeValue, exportManifest, exportsOf, formatInstant, fromValue, grammar, handlersOf, httpCapability, inlineGrants, instant, kindNames, list, loadScript, localeCapability, lowerTree, map, newGroup, nothing, nowMicros, num, parseEntry, parseInstant, parseSource, parseSourceRecovering, quantity, range, readDisplay, record, restore, shape, sqliteCapability, stdlibSources, storeCapability, syntaxSelector, syntaxText, talk, text, timerCapability, toValue, units, userCapability, validMessageSelector, waitUs };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
|
|
2
|
-
import {
|
|
3
|
-
import { a as defineValueCapability, f as validComputedMessageName, s as expectedOf, u as shape } from "./capabilities-
|
|
4
|
-
import { i as ScriptError$1,
|
|
5
|
-
import { r as registerStandardChecks } from "./encoding-
|
|
6
|
-
import { c as fixed, s as costOf } from "./store-capability-
|
|
2
|
+
import { A as listValues, D as isDecimal, Dt as isInteger, Et as integerOf, G as record, L as nothing, N as map, Q as text, R as num, d as bytes, i as ScriptError, l as Value, o as invalidValue, on as normalizeNFC, q as requireValue, t as HostError, tn as characterBoundaries, u as bool, v as dec, y as decimalParts } from "./errors-BKJES3Zu.js";
|
|
3
|
+
import { a as defineValueCapability, f as validComputedMessageName, i as defineCapability, m as validStaticMessageName, s as expectedOf, u as shape } from "./capabilities-Bi5Qm6Fr.js";
|
|
4
|
+
import { i as ScriptError$1, pt as errorMessages } from "./base64-Dtqaz_0A.js";
|
|
5
|
+
import { r as registerStandardChecks } from "./encoding-C3Q7pIC9.js";
|
|
6
|
+
import { c as fixed, s as costOf } from "./store-capability-BxXgiRM7.js";
|
|
7
|
+
import { asyncDispose, newDrivenGroup } from "./driver.js";
|
|
7
8
|
//#region src/talk.ts
|
|
8
9
|
const blank = /^[\t ]*$/;
|
|
9
10
|
const commonPrefix = (a, b) => {
|
|
@@ -41,7 +42,7 @@ const isPlainObject = (input) => [null, Object.prototype].includes(Object.getPro
|
|
|
41
42
|
* the table doesn't name, and cyclic data, throws `invalid value`.
|
|
42
43
|
*/
|
|
43
44
|
const toValue = (plain, options = {}) => {
|
|
44
|
-
const
|
|
45
|
+
const numberMode = options.numbers;
|
|
45
46
|
const open = /* @__PURE__ */ new Set();
|
|
46
47
|
const convert = (input) => {
|
|
47
48
|
switch (typeof input) {
|
|
@@ -49,7 +50,9 @@ const toValue = (plain, options = {}) => {
|
|
|
49
50
|
case "boolean": return bool(input);
|
|
50
51
|
case "string": return text(input);
|
|
51
52
|
case "bigint": return num(input);
|
|
52
|
-
case "number":
|
|
53
|
+
case "number":
|
|
54
|
+
if (numberMode === "integer") return Number.isSafeInteger(input) ? num(input) : invalidValue("A JS number must be a safe integer; use dec() or { numbers: 'decimal' }");
|
|
55
|
+
return numberMode === "decimal" ? num(input) : invalidValue("A JS number needs { numbers: 'integer' } or { numbers: 'decimal' }, or num() or dec()");
|
|
53
56
|
case "object": break;
|
|
54
57
|
default: return invalidValue(`Not plain data: ${typeof input}`);
|
|
55
58
|
}
|
|
@@ -83,7 +86,7 @@ const toValue = (plain, options = {}) => {
|
|
|
83
86
|
};
|
|
84
87
|
/** A Value as plain JS data (ADR 0119); kinds with no JS form stay Values. */
|
|
85
88
|
const fromValue = (v, options = {}) => {
|
|
86
|
-
|
|
89
|
+
requireValue(v);
|
|
87
90
|
const convert = (value) => {
|
|
88
91
|
switch (value.kind) {
|
|
89
92
|
case "nothing": return null;
|
|
@@ -398,7 +401,6 @@ const encodeJson = (value) => {
|
|
|
398
401
|
};
|
|
399
402
|
//#endregion
|
|
400
403
|
//#region src/sqlite-capability.ts
|
|
401
|
-
const MAX_WHOLE = Number.MAX_SAFE_INTEGER;
|
|
402
404
|
const isWhole = (n) => Number.isSafeInteger(n) && n >= 0;
|
|
403
405
|
const INT64_MIN = -(2n ** 63n);
|
|
404
406
|
const INT64_MAX = 2n ** 63n - 1n;
|
|
@@ -431,7 +433,16 @@ const errorFields = {
|
|
|
431
433
|
"too many rows": (data) => data.get("max").kind === "number",
|
|
432
434
|
unrepresentable: (data) => isText(data, "column")
|
|
433
435
|
};
|
|
434
|
-
const
|
|
436
|
+
const declaredFields = {
|
|
437
|
+
sql: { reason: shape.text },
|
|
438
|
+
constraint: { kind: shape.text },
|
|
439
|
+
"too many rows": { max: shape.number },
|
|
440
|
+
unrepresentable: { column: shape.text }
|
|
441
|
+
};
|
|
442
|
+
const errors = (...codes) => codes.map((code) => declaredFields[code] ? {
|
|
443
|
+
code,
|
|
444
|
+
fields: declaredFields[code]
|
|
445
|
+
} : { code });
|
|
435
446
|
const coreFailure = (code, field, value) => new ScriptError(code, "", map([[field, text(value)]]));
|
|
436
447
|
const checkBinding = (binding) => {
|
|
437
448
|
if (!binding || typeof binding !== "object" || typeof binding.database !== "string" || !isWhole(binding.maxRows) || binding.tables !== void 0 && (!Array.isArray(binding.tables) || !binding.tables.every((t) => typeof t === "string"))) throw new HostError("invalid value", "A sqlite binding is {database, tables, maxRows}");
|
|
@@ -504,8 +515,8 @@ const rowsOf = (result) => {
|
|
|
504
515
|
}
|
|
505
516
|
return listValues(result.rows.map((row) => map(columns.map((column, i) => [column, valueOf(row[i], column)]))));
|
|
506
517
|
};
|
|
507
|
-
/** Optional for Hosts.
|
|
508
|
-
const sqliteCapability = (impl, costs,
|
|
518
|
+
/** Optional for Hosts. perStep is whole Fuel charged before each SQLite step. */
|
|
519
|
+
const sqliteCapability = (impl, costs, perStep) => {
|
|
509
520
|
for (const name of [
|
|
510
521
|
"coordinator",
|
|
511
522
|
"query",
|
|
@@ -514,13 +525,8 @@ const sqliteCapability = (impl, costs, perRow) => {
|
|
|
514
525
|
"commit",
|
|
515
526
|
"rollback"
|
|
516
527
|
]) if (!impl || typeof impl[name] !== "function") throw new HostError("invalid value", `sqlite needs ${name}`);
|
|
517
|
-
if (!isWhole(
|
|
518
|
-
const
|
|
519
|
-
const statement = (run) => (call, ...args) => {
|
|
520
|
-
const max = rowsAllowed(args[2], call.binding);
|
|
521
|
-
chargeRows(call, max);
|
|
522
|
-
return run(call, args[0].asText(), paramsOf(args[1]), max);
|
|
523
|
-
};
|
|
528
|
+
if (!isWhole(perStep)) throw new HostError("invalid value", "The per-step cost must be a whole number");
|
|
529
|
+
const statement = (run) => (call, ...args) => run(call, args[0].asText(), paramsOf(args[1]), rowsAllowed(args[2], call.binding), () => call.charge(perStep));
|
|
524
530
|
const statementArgs = [
|
|
525
531
|
shape.text,
|
|
526
532
|
paramsShape,
|
|
@@ -546,8 +552,9 @@ const sqliteCapability = (impl, costs, perRow) => {
|
|
|
546
552
|
result: shape.listOf(shape.any),
|
|
547
553
|
errors: errors("sql", "not read-only", "too many rows", "unrepresentable"),
|
|
548
554
|
cost: costOf(costs, "query"),
|
|
549
|
-
|
|
550
|
-
|
|
555
|
+
metering: "read-only",
|
|
556
|
+
do: statement((call, sql, params, max, beforeStep) => {
|
|
557
|
+
const result = impl.query(call, sql, params, max, beforeStep);
|
|
551
558
|
checkForm(result, max, false);
|
|
552
559
|
return rowsOf(result);
|
|
553
560
|
})
|
|
@@ -562,8 +569,9 @@ const sqliteCapability = (impl, costs, perRow) => {
|
|
|
562
569
|
errors: errors("sql", "constraint", "sqlite busy", "too many rows", "unrepresentable"),
|
|
563
570
|
cost: costOf(costs, "change"),
|
|
564
571
|
segmentBound: true,
|
|
565
|
-
|
|
566
|
-
|
|
572
|
+
metering: "segment-bound",
|
|
573
|
+
do: statement((call, sql, params, max, beforeStep) => {
|
|
574
|
+
const result = impl.change(call, sql, params, max, beforeStep);
|
|
567
575
|
checkForm(result, max, true);
|
|
568
576
|
const rows = rowsOf(result);
|
|
569
577
|
return map([["changes", dec(String(result.changes))], ["rows", rows]]);
|
|
@@ -725,4 +733,81 @@ const httpCapability = (impl, costs) => {
|
|
|
725
733
|
return fixed(defineValueCapability("http", operations));
|
|
726
734
|
};
|
|
727
735
|
//#endregion
|
|
728
|
-
|
|
736
|
+
//#region src/handlers.ts
|
|
737
|
+
/**
|
|
738
|
+
* Calls invoke with integer-mode toValue arguments and default fromValue answers.
|
|
739
|
+
* The Script's existing driver or Host Pump loop still runs the Requests.
|
|
740
|
+
* Promise hooks, symbols and non-message properties read as undefined.
|
|
741
|
+
*/
|
|
742
|
+
const handlersOf = (script) => new Proxy(Object.create(null), { get: (_target, name) => {
|
|
743
|
+
if (typeof name !== "string" || name === "then" || Object.hasOwn(Object.prototype, name) || !validStaticMessageName(name)) return;
|
|
744
|
+
return async (...args) => {
|
|
745
|
+
const values = args.map((arg, index) => {
|
|
746
|
+
try {
|
|
747
|
+
return toValue(arg, { numbers: "integer" });
|
|
748
|
+
} catch (error) {
|
|
749
|
+
if (error instanceof HostError && error.code === "invalid value") invalidValue(`Argument ${index + 1} to ${name}: ${error.message}`);
|
|
750
|
+
throw error;
|
|
751
|
+
}
|
|
752
|
+
});
|
|
753
|
+
return fromValue(await script.invoke(name, ...values));
|
|
754
|
+
};
|
|
755
|
+
} });
|
|
756
|
+
//#endregion
|
|
757
|
+
//#region src/group-helper.ts
|
|
758
|
+
/** Creates a driven Group on the supplied Core; close has the driver's shutdown semantics. */
|
|
759
|
+
const createGroup = (o) => {
|
|
760
|
+
const { core, ...options } = o;
|
|
761
|
+
const { group, drive } = newDrivenGroup(core, options);
|
|
762
|
+
const load = group.load.bind(group);
|
|
763
|
+
return Object.assign(group, {
|
|
764
|
+
load: (o) => {
|
|
765
|
+
const script = load(o);
|
|
766
|
+
return Object.assign(script, { handlers: handlersOf(script) });
|
|
767
|
+
},
|
|
768
|
+
close: drive.close,
|
|
769
|
+
[asyncDispose]: drive[asyncDispose]
|
|
770
|
+
});
|
|
771
|
+
};
|
|
772
|
+
//#endregion
|
|
773
|
+
//#region src/inline-grants.ts
|
|
774
|
+
const resultValue = (result) => {
|
|
775
|
+
try {
|
|
776
|
+
return toValue(result, { numbers: "integer" });
|
|
777
|
+
} catch (error) {
|
|
778
|
+
if (error instanceof HostError && error.code === "invalid value") throw new ScriptError(error.code, error.message);
|
|
779
|
+
throw error;
|
|
780
|
+
}
|
|
781
|
+
};
|
|
782
|
+
/**
|
|
783
|
+
* Defines one Capability per key and grants all its Operations. Arguments use
|
|
784
|
+
* default fromValue; results use integer-mode toValue. Arity is fn.length unless
|
|
785
|
+
* overridden, including for async functions, which also receive a final signal.
|
|
786
|
+
*/
|
|
787
|
+
const inlineGrants = (capabilities) => Object.fromEntries(Object.entries(capabilities).map(([name, operations]) => {
|
|
788
|
+
const ops = Object.fromEntries(Object.entries(operations).map(([opName, op]) => {
|
|
789
|
+
const spec = typeof op === "function" ? { fn: op } : op;
|
|
790
|
+
const fn = "async" in spec ? spec.async : spec.fn;
|
|
791
|
+
const arity = spec.arity ?? fn.length;
|
|
792
|
+
if (!Number.isSafeInteger(arity) || arity < 0) invalidValue("An inline Operation arity must be a non-negative safe integer");
|
|
793
|
+
const base = {
|
|
794
|
+
args: Array.from({ length: arity }, () => shape.value),
|
|
795
|
+
result: shape.value,
|
|
796
|
+
cost: { fuel: 0 },
|
|
797
|
+
command: true
|
|
798
|
+
};
|
|
799
|
+
return [opName, "async" in spec ? {
|
|
800
|
+
...base,
|
|
801
|
+
mode: "suspending",
|
|
802
|
+
maxPendingMs: spec.maxPendingMs,
|
|
803
|
+
run: async (call, ...args) => resultValue(await Reflect.apply(fn, void 0, [...args.map((value) => fromValue(value)), call.signal]))
|
|
804
|
+
} : {
|
|
805
|
+
...base,
|
|
806
|
+
mode: "immediate",
|
|
807
|
+
do: (_call, ...args) => resultValue(Reflect.apply(fn, void 0, args.map((value) => fromValue(value))))
|
|
808
|
+
}];
|
|
809
|
+
}));
|
|
810
|
+
return [name, defineCapability(name, ops).grant("all", void 0)];
|
|
811
|
+
}));
|
|
812
|
+
//#endregion
|
|
813
|
+
export { sqliteCapability as a, fromValue as c, httpCapability as i, toValue as l, createGroup as n, decodeJson as o, handlersOf as r, encodeJson as s, inlineGrants as t, talk as u };
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
|
|
2
|
+
import { K as requireArgs, t as HostError } from "./errors-BKJES3Zu.js";
|
|
3
|
+
import { t as LimitReached } from "./capabilities-Bi5Qm6Fr.js";
|
|
4
|
+
import { dt as compareText, mt as languageVersion } from "./base64-Dtqaz_0A.js";
|
|
5
|
+
import { n as quoteJSON } from "./encoding-C3Q7pIC9.js";
|
|
6
|
+
//#region src/call-meter.ts
|
|
7
|
+
var CallMeter = class {
|
|
8
|
+
take;
|
|
9
|
+
/** The Fuel accepted increments added up to. */
|
|
10
|
+
charged = 0;
|
|
11
|
+
/** An increment didn't fit: the call faults, whatever the Host does next. */
|
|
12
|
+
refused = false;
|
|
13
|
+
#starting = false;
|
|
14
|
+
constructor(take) {
|
|
15
|
+
this.take = take;
|
|
16
|
+
}
|
|
17
|
+
/** Runs the Operation's starting callback, the only time it may charge. */
|
|
18
|
+
starting(start) {
|
|
19
|
+
this.#starting = true;
|
|
20
|
+
try {
|
|
21
|
+
return start();
|
|
22
|
+
} finally {
|
|
23
|
+
this.#starting = false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
charge = (fuel) => {
|
|
27
|
+
if (!this.#starting) throw new HostError("invalid value", "Charge only while starting");
|
|
28
|
+
if (!Number.isSafeInteger(fuel) || fuel < 0) throw new HostError("invalid value", "Fuel must be a whole number");
|
|
29
|
+
if (this.refused || !this.take(fuel, this.charged)) {
|
|
30
|
+
this.refused = true;
|
|
31
|
+
throw new LimitReached("the Run can’t cover this charge");
|
|
32
|
+
}
|
|
33
|
+
this.charged += fuel;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/embedding.ts
|
|
38
|
+
/** request({ name, args }).result, for either Core's Script. */
|
|
39
|
+
const invoke = (script, name, args) => {
|
|
40
|
+
requireArgs(args, `invoke('${name}')`, name);
|
|
41
|
+
return script.request({
|
|
42
|
+
name,
|
|
43
|
+
args
|
|
44
|
+
}).result;
|
|
45
|
+
};
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/manifest.ts
|
|
48
|
+
const shapeData = (shape) => {
|
|
49
|
+
switch (shape.k) {
|
|
50
|
+
case "any": return "any";
|
|
51
|
+
case "value": return "value";
|
|
52
|
+
case "kind": return shape.kind;
|
|
53
|
+
case "object": return { object: shape.kind };
|
|
54
|
+
case "quantity": return { quantity: shape.unit };
|
|
55
|
+
case "unitKind": return { unitKind: shape.kind };
|
|
56
|
+
case "list": return { list: shapeData(shape.of) };
|
|
57
|
+
case "oneOf": return { oneOf: shape.of.map(shapeData) };
|
|
58
|
+
case "optional": return { optional: shapeData(shape.of) };
|
|
59
|
+
case "map": return {
|
|
60
|
+
map: shape.fields.map((f) => ({
|
|
61
|
+
key: f.key,
|
|
62
|
+
shape: shapeData(f.shape),
|
|
63
|
+
...f.optional ? { optional: true } : {}
|
|
64
|
+
})),
|
|
65
|
+
...shape.open ? { open: true } : {}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const operationData = (name, op) => ({
|
|
70
|
+
name,
|
|
71
|
+
mode: op.mode,
|
|
72
|
+
args: (op.args ?? []).map(shapeData),
|
|
73
|
+
...op.labels?.length ? { labels: [...op.labels] } : {},
|
|
74
|
+
...op.result ? { result: shapeData(op.result) } : {},
|
|
75
|
+
cost: {
|
|
76
|
+
fuel: op.cost.fuel,
|
|
77
|
+
alloc: op.cost.alloc ?? 0
|
|
78
|
+
},
|
|
79
|
+
...op.mode === "suspending" && op.maxPendingMs !== void 0 ? { maxPending: op.maxPendingMs } : {},
|
|
80
|
+
...op.errors === void 0 ? {} : { errors: [...op.errors].sort((a, b) => compareText(a.code, b.code)).map((e) => ({
|
|
81
|
+
code: e.code,
|
|
82
|
+
fields: Object.entries(e.fields ?? {}).map(([key, f]) => ({
|
|
83
|
+
key,
|
|
84
|
+
shape: shapeData("shape" in f ? f.shape : f),
|
|
85
|
+
..."shape" in f ? { optional: true } : {}
|
|
86
|
+
}))
|
|
87
|
+
})) },
|
|
88
|
+
...op.mode === "immediate" && op.scope ? { scope: "opens" in op.scope ? {
|
|
89
|
+
opens: op.scope.opens,
|
|
90
|
+
abandon: op.scope.abandon
|
|
91
|
+
} : { closes: op.scope.closes } } : {},
|
|
92
|
+
...op.mode === "immediate" && op.segmentBound ? { segmentBound: true } : {},
|
|
93
|
+
...op.command ? { command: true } : {},
|
|
94
|
+
...op.mode !== "fire-and-forget" && op.metering ? { metering: op.metering } : {}
|
|
95
|
+
});
|
|
96
|
+
const grantData = (grant, operation = operationData) => ({
|
|
97
|
+
capability: grant.capability.name,
|
|
98
|
+
operations: [...grant.ops].sort(compareText).map((name) => operation(name, grant.capability.operations.get(name)))
|
|
99
|
+
});
|
|
100
|
+
/** Operation Data plus the manifest-only documentation fields. */
|
|
101
|
+
const documentedOperation = (name, op) => ({
|
|
102
|
+
...operationData(name, op),
|
|
103
|
+
...op.description ? { description: op.description } : {},
|
|
104
|
+
...op.examples?.length ? { examples: op.examples } : {}
|
|
105
|
+
});
|
|
106
|
+
const canonicalJSON = (value) => {
|
|
107
|
+
if (typeof value === "string") return quoteJSON(value);
|
|
108
|
+
if (Array.isArray(value)) return `[${value.map(canonicalJSON).join(",")}]`;
|
|
109
|
+
if (value && typeof value === "object") return `{${Object.entries(value).map(([k, v]) => `${quoteJSON(k)}:${canonicalJSON(v)}`).join(",")}}`;
|
|
110
|
+
return JSON.stringify(value);
|
|
111
|
+
};
|
|
112
|
+
const byName = (values) => [...values].sort((a, b) => compareText(a.name, b.name));
|
|
113
|
+
const costData = (cost) => ({
|
|
114
|
+
fuel: cost?.fuel ?? 0,
|
|
115
|
+
alloc: cost?.alloc ?? 0
|
|
116
|
+
});
|
|
117
|
+
const needsData = (needs) => [...needs].sort((a, b) => compareText(a.capability, b.capability) || compareText(a.operation, b.operation)).map(({ capability, operation }) => ({
|
|
118
|
+
capability,
|
|
119
|
+
operation
|
|
120
|
+
}));
|
|
121
|
+
/** Chapter 9's deterministic JSON file, ending in LF; never calls the Host. */
|
|
122
|
+
const exportManifest = (m) => {
|
|
123
|
+
if (m.ownerKind && !(m.objectKinds ?? []).includes(m.ownerKind)) throw new HostError("invalid value", "ownerKind is not in objectKinds");
|
|
124
|
+
return `${canonicalJSON({
|
|
125
|
+
kind: m.kind,
|
|
126
|
+
version: m.version,
|
|
127
|
+
language: languageVersion,
|
|
128
|
+
grants: Object.entries(m.grants).sort(([a], [b]) => compareText(a, b)).map(([name, grant]) => ({
|
|
129
|
+
name,
|
|
130
|
+
...grantData(grant, documentedOperation)
|
|
131
|
+
})),
|
|
132
|
+
libraries: byName(m.libraries ?? []).map((l) => ({
|
|
133
|
+
name: l.name,
|
|
134
|
+
version: l.version,
|
|
135
|
+
source: l.source,
|
|
136
|
+
needs: needsData(l.needs)
|
|
137
|
+
})),
|
|
138
|
+
messages: byName(m.messages ?? []).map((message) => ({
|
|
139
|
+
name: message.name,
|
|
140
|
+
args: (message.args ?? []).map(shapeData),
|
|
141
|
+
receivers: byName(message.receivers ?? []).map((kind) => kind.name),
|
|
142
|
+
...message.description ? { description: message.description } : {},
|
|
143
|
+
...message.examples?.length ? { examples: message.examples } : {}
|
|
144
|
+
})),
|
|
145
|
+
objectKinds: byName(m.objectKinds ?? []).map((kind) => ({
|
|
146
|
+
name: kind.name,
|
|
147
|
+
props: [...kind.props].sort(([a], [b]) => compareText(a, b)).map(([name, prop]) => ({
|
|
148
|
+
name,
|
|
149
|
+
shape: prop.shape ? shapeData(prop.shape) : "value",
|
|
150
|
+
readOnly: !prop.set,
|
|
151
|
+
getCost: costData(prop.getCost),
|
|
152
|
+
setCost: costData(prop.setCost)
|
|
153
|
+
})),
|
|
154
|
+
parentKinds: [...kind.parentKinds].sort(compareText),
|
|
155
|
+
...kind.elements ? { elements: {
|
|
156
|
+
shape: shapeData(kind.elements.shape),
|
|
157
|
+
countCost: costData(kind.elements.countCost),
|
|
158
|
+
atCost: costData(kind.elements.atCost),
|
|
159
|
+
findCost: costData(kind.elements.findCost)
|
|
160
|
+
} } : {}
|
|
161
|
+
})),
|
|
162
|
+
objects: Object.entries(m.objects ?? {}).sort(([a], [b]) => compareText(a, b)).map(([name, kind]) => ({
|
|
163
|
+
name,
|
|
164
|
+
kind: kind.name
|
|
165
|
+
})),
|
|
166
|
+
...m.ownerKind ? { ownerKind: m.ownerKind.name } : {}
|
|
167
|
+
})}\n`;
|
|
168
|
+
};
|
|
169
|
+
/** A Shape from its Host Manifest data, as `shapeData` writes it. */
|
|
170
|
+
const shapeOf = (data) => {
|
|
171
|
+
if (typeof data === "string") return data === "any" ? { k: "any" } : data === "value" ? { k: "value" } : {
|
|
172
|
+
k: "kind",
|
|
173
|
+
kind: data
|
|
174
|
+
};
|
|
175
|
+
const d = data;
|
|
176
|
+
if (typeof d.object === "string") return {
|
|
177
|
+
k: "object",
|
|
178
|
+
kind: d.object
|
|
179
|
+
};
|
|
180
|
+
if (typeof d.quantity === "string") return {
|
|
181
|
+
k: "quantity",
|
|
182
|
+
unit: d.quantity
|
|
183
|
+
};
|
|
184
|
+
if (typeof d.unitKind === "string") return {
|
|
185
|
+
k: "unitKind",
|
|
186
|
+
kind: d.unitKind
|
|
187
|
+
};
|
|
188
|
+
if ("list" in d) return {
|
|
189
|
+
k: "list",
|
|
190
|
+
of: shapeOf(d.list)
|
|
191
|
+
};
|
|
192
|
+
if (Array.isArray(d.oneOf)) return {
|
|
193
|
+
k: "oneOf",
|
|
194
|
+
of: d.oneOf.map(shapeOf)
|
|
195
|
+
};
|
|
196
|
+
if ("optional" in d) return {
|
|
197
|
+
k: "optional",
|
|
198
|
+
of: shapeOf(d.optional)
|
|
199
|
+
};
|
|
200
|
+
if (Array.isArray(d.map)) return {
|
|
201
|
+
k: "map",
|
|
202
|
+
fields: d.map.map((f) => ({
|
|
203
|
+
key: f.key,
|
|
204
|
+
optional: f.optional === true,
|
|
205
|
+
shape: shapeOf(f.shape)
|
|
206
|
+
})),
|
|
207
|
+
open: d.open === true
|
|
208
|
+
};
|
|
209
|
+
throw new HostError("invalid save");
|
|
210
|
+
};
|
|
211
|
+
/**
|
|
212
|
+
* A Grant's Operations from their Host Manifest data, as a save keeps them:
|
|
213
|
+
* their shapes and declared costs, with no Host functions.
|
|
214
|
+
*/
|
|
215
|
+
const operationsOf = (json) => {
|
|
216
|
+
let data;
|
|
217
|
+
try {
|
|
218
|
+
data = JSON.parse(json);
|
|
219
|
+
} catch {
|
|
220
|
+
throw new HostError("invalid save");
|
|
221
|
+
}
|
|
222
|
+
if (!data || typeof data.capability !== "string" || !Array.isArray(data.operations)) throw new HostError("invalid save");
|
|
223
|
+
return {
|
|
224
|
+
capability: data.capability,
|
|
225
|
+
operations: new Map(data.operations.map((op) => {
|
|
226
|
+
const cost = op.cost;
|
|
227
|
+
const errors = op.errors;
|
|
228
|
+
const scope = op.scope;
|
|
229
|
+
const decl = {
|
|
230
|
+
mode: op.mode,
|
|
231
|
+
args: op.args.map(shapeOf),
|
|
232
|
+
...Array.isArray(op.labels) ? { labels: op.labels } : {},
|
|
233
|
+
...op.result === void 0 ? {} : { result: shapeOf(op.result) },
|
|
234
|
+
cost: {
|
|
235
|
+
fuel: cost.fuel,
|
|
236
|
+
alloc: cost.alloc
|
|
237
|
+
},
|
|
238
|
+
...typeof op.maxPending === "number" ? { maxPendingMs: op.maxPending } : {},
|
|
239
|
+
...errors ? { errors: errors.map((e) => ({
|
|
240
|
+
code: e.code,
|
|
241
|
+
fields: Object.fromEntries(e.fields.map((f) => [f.key, f.optional ? {
|
|
242
|
+
optional: true,
|
|
243
|
+
shape: shapeOf(f.shape)
|
|
244
|
+
} : shapeOf(f.shape)]))
|
|
245
|
+
})) } : {},
|
|
246
|
+
...scope ? { scope } : {},
|
|
247
|
+
...op.segmentBound ? { segmentBound: true } : {},
|
|
248
|
+
...op.command ? { command: true } : {},
|
|
249
|
+
...op.metering ? { metering: op.metering } : {}
|
|
250
|
+
};
|
|
251
|
+
return [op.name, decl];
|
|
252
|
+
}))
|
|
253
|
+
};
|
|
254
|
+
};
|
|
255
|
+
//#endregion
|
|
256
|
+
export { operationsOf as a, CallMeter as c, operationData as i, exportManifest as n, shapeData as o, grantData as r, invoke as s, canonicalJSON as t };
|
package/message-layer.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import { i as JsonObject, n as Json, r as JsonNumber, s as readOrderedJSON } from "./readers-
|
|
3
|
-
import { n as decodeBinaryValue, r as encodeBinaryValue, t as BinaryValueOptions } from "./binary-value-
|
|
1
|
+
/// <reference lib="esnext.disposable" />
|
|
2
|
+
import { i as JsonObject, n as Json, r as JsonNumber, s as readOrderedJSON } from "./readers-DAFVvvq4.js";
|
|
3
|
+
import { n as decodeBinaryValue, r as encodeBinaryValue, t as BinaryValueOptions } from "./binary-value-Bb6HPDtM.js";
|
|
4
4
|
//#region src/request-pump-binary.d.ts
|
|
5
5
|
export declare const requestPumpFeature: "request-pump-fields-v1";
|
|
6
6
|
export declare const callbacksFeature: "callbacks-fields-v1";
|
package/message-layer.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
|
|
2
|
-
import { l as readOrderedJSON, n as JsonObject, t as JsonNumber } from "./readers-
|
|
3
|
-
import { c as isRequestPumpBinary, f as decodeBinaryValue, i as encodeBinaryFrame, n as decodeBinaryFrame, p as encodeBinaryValue, t as callbacksFeature, u as requestPumpFeature } from "./request-pump-binary-
|
|
2
|
+
import { l as readOrderedJSON, n as JsonObject, t as JsonNumber } from "./readers-B5e5bBrY.js";
|
|
3
|
+
import { c as isRequestPumpBinary, f as decodeBinaryValue, i as encodeBinaryFrame, n as decodeBinaryFrame, p as encodeBinaryValue, t as callbacksFeature, u as requestPumpFeature } from "./request-pump-binary-BjnyqXV5.js";
|
|
4
4
|
export { JsonNumber, JsonObject, callbacksFeature, decodeBinaryFrame, decodeBinaryValue, encodeBinaryFrame, encodeBinaryValue, isRequestPumpBinary, readOrderedJSON, requestPumpFeature };
|
package/notify.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
import { a as changed, i as WatchLimits, n as RouterOptions, o as createRouter, r as RoutingResult, t as NotificationRouter } from "./router-
|
|
1
|
+
/// <reference lib="esnext.disposable" />
|
|
2
|
+
import { a as changed, i as WatchLimits, n as RouterOptions, o as createRouter, r as RoutingResult, t as NotificationRouter } from "./router-BspOCPA0.js";
|
|
3
3
|
export { type NotificationRouter, type RouterOptions, type RoutingResult, type WatchLimits, changed, createRouter };
|
package/notify.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
|
|
2
|
-
export { t as changed, n as createRouter } from "./router
|
|
2
|
+
export { t as changed, n as createRouter } from "./router-BCHEfs4x.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
/// <reference lib="esnext.disposable" />
|
|
2
|
+
import { An as compileLibrary, C as Report, D as RunEvent, E as RestoreResult, F as TsGroupOptions, Ht as ScopeDecl, I as TsRestoreOptions, J as Value, L as TsScript, M as SessionPort, Nn as Limits, P as TsGroup, Tn as Library, Yn as LoadError, _n as CalendarImpl, fn as SqliteBinding, g as Inspection, gt as ObjectKindDef, hn as LocaleImpl, ht as ObjectKind, j as SessionControls, jn as replacementLibraries, jt as Grant, pt as HostObject, qt as Shape, t as DebugController, xt as CapabilityDef, yt as GrantDecls } from "./debug-C72o2pZy.js";
|
|
3
3
|
//#region src/setup.d.ts
|
|
4
4
|
type ShapeSpec = string | {
|
|
5
5
|
quantity: string;
|
|
@@ -41,6 +41,7 @@ type OperationSpec = {
|
|
|
41
41
|
/** Argument Labels, one per argument after the first (ADR 0115). */
|
|
42
42
|
labels?: string[];
|
|
43
43
|
maxPending?: number;
|
|
44
|
+
metering?: 'read-only' | 'segment-bound';
|
|
44
45
|
mode: 'immediate' | 'suspending' | 'fire-and-forget';
|
|
45
46
|
name: string;
|
|
46
47
|
result?: ShapeSpec;
|
|
@@ -128,7 +129,7 @@ type Setup = {
|
|
|
128
129
|
alloc?: number;
|
|
129
130
|
fuel?: number;
|
|
130
131
|
}>;
|
|
131
|
-
|
|
132
|
+
perStep?: number;
|
|
132
133
|
}[];
|
|
133
134
|
};
|
|
134
135
|
declare const operationDeclarations: (capabilities: ReadonlyMap<string, CapabilityDef<unknown>>) => GrantDecls;
|
|
@@ -402,6 +403,12 @@ declare class SessionHost {
|
|
|
402
403
|
* means the value is not a Function Value.
|
|
403
404
|
*/
|
|
404
405
|
functionDocumentation(value: Value): string | null;
|
|
406
|
+
/**
|
|
407
|
+
* Each defining-source version's Declaration Documentation, by unit
|
|
408
|
+
* identity, kept before code changes can discard it (chapter 9).
|
|
409
|
+
*/
|
|
410
|
+
private unitDocs;
|
|
411
|
+
private retainDocs;
|
|
405
412
|
/**
|
|
406
413
|
* An Entry or a Session Command. Returns the lines it printed. At a
|
|
407
414
|
* debugger pause, only `:fix` of the paused Run.
|
|
@@ -442,6 +449,7 @@ declare class SessionHost {
|
|
|
442
449
|
private mock;
|
|
443
450
|
private stub;
|
|
444
451
|
private settle;
|
|
452
|
+
private charge;
|
|
445
453
|
private isHandler;
|
|
446
454
|
private has;
|
|
447
455
|
private sessionSource;
|
|
@@ -531,7 +539,7 @@ type ReplayOptions = {
|
|
|
531
539
|
capabilities?: SessionEnvironment['capabilities'];
|
|
532
540
|
/**
|
|
533
541
|
* Where the Session Host turns once the Transcript runs out, so a
|
|
534
|
-
*
|
|
542
|
+
* Host can go on live from a replayed session: its Clock, its
|
|
535
543
|
* built-in Capabilities, and where later items and echoed values go.
|
|
536
544
|
*/
|
|
537
545
|
live?: Pick<SessionEnvironment, 'builtIns' | 'capabilities' | 'now' | 'record' | 'result' | 'transcriptEnds'>;
|
|
@@ -2,22 +2,27 @@
|
|
|
2
2
|
//#region src/operation-promises.ts
|
|
3
3
|
const pending = /* @__PURE__ */ new WeakMap();
|
|
4
4
|
/** Tracks forwarding too, so the final answer/failure is queued before completion. */
|
|
5
|
-
const trackOperation = (group, result) => {
|
|
5
|
+
const trackOperation = (group, call, result) => {
|
|
6
6
|
let operations = pending.get(group);
|
|
7
7
|
if (!operations) {
|
|
8
|
-
operations = /* @__PURE__ */ new
|
|
8
|
+
operations = /* @__PURE__ */ new Map();
|
|
9
9
|
pending.set(group, operations);
|
|
10
10
|
}
|
|
11
11
|
const done = () => {
|
|
12
12
|
operations.delete(completed);
|
|
13
13
|
};
|
|
14
14
|
const completed = result.then(done, done);
|
|
15
|
-
operations.
|
|
15
|
+
operations.set(completed, {
|
|
16
|
+
callId: call.id,
|
|
17
|
+
grantName: call.grantName,
|
|
18
|
+
scriptName: call.scriptName
|
|
19
|
+
});
|
|
16
20
|
};
|
|
21
|
+
const pendingOperations = (group) => [...pending.get(group)?.values() ?? []];
|
|
17
22
|
/** Includes abandoned calls whose Host work is still finishing. */
|
|
18
23
|
const waitForOperations = async (group) => {
|
|
19
24
|
const operations = pending.get(group);
|
|
20
|
-
while (operations?.size) await Promise.all(operations);
|
|
25
|
+
while (operations?.size) await Promise.all(operations.keys());
|
|
21
26
|
};
|
|
22
27
|
//#endregion
|
|
23
|
-
export {
|
|
28
|
+
export { trackOperation as n, waitForOperations as r, pendingOperations as t };
|