@northtalk/ts 0.6.0 → 0.7.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/{binary-value-C4ZiXVjv.d.ts → binary-value-M8v567iA.d.ts} +1 -1
- package/{checker-CUhn2XaM.js → checker-Coml0Tf9.js} +581 -71
- package/{core-egHbNmve.d.ts → core-D4qYURer.d.ts} +1 -1
- package/{debug--Of4MSLw.d.ts → debug-C_Ob5rkl.d.ts} +126 -9
- package/debug.d.ts +1 -1
- package/debug.js +1 -1
- package/{driver-BIm1mL77.d.ts → driver-CLi_OmyQ.d.ts} +1 -1
- package/driver.d.ts +1 -1
- package/driver.js +1 -1
- package/encoding-BL2ECJmg.js +338 -0
- package/{engine-DbDcopGM.d.ts → engine-BBNHy4-F.d.ts} +2 -2
- package/{engine-CXf5FCwi.js → engine-DhBk0lTt.js} +6 -6
- package/{errors-D11zizZg.js → errors-P3ga1I-9.js} +124 -21
- package/{group-BpzTo0k4.js → group-BqccKTWz.js} +367 -68
- package/{http-fetch-DFwVIOQg.js → http-fetch-DA-NbFIM.js} +2 -2
- package/http.d.ts +1 -1
- package/http.js +4 -4
- package/index-CBuczWK0.d.ts +9 -0
- package/index.d.ts +6 -12
- package/index.js +15 -14
- package/{inline-grants-XbX9HL_w.js → inline-grants-BT2nnfLA.js} +4 -5
- package/{lean-aCvN6y52.js → lean-BJmLobmd.js} +13 -8
- package/{lean-DiS9rUcn.d.ts → lean-CFLJ9VrX.d.ts} +155 -6
- package/lean.d.ts +5 -6
- package/lean.js +15 -14
- package/{manifest-CCfpn0kC.js → manifest-37x-HSxH.js} +4 -3
- package/message-layer.d.ts +2 -2
- package/message-layer.js +2 -2
- package/notify.d.ts +1 -1
- package/notify.js +1 -1
- package/{objects-DmUc0lha.js → objects-DE6kRk0r.js} +1 -1
- package/{objects-DYq_YvaQ.d.ts → objects-DVlpWsi0.d.ts} +7 -3
- package/{operations-DnCcztkZ.js → operations-CGjDlkGU.js} +73 -15
- package/package.json +5 -1
- package/peer-capability-elnbQy-J.js +149 -0
- package/peer.d.ts +173 -0
- package/peer.js +542 -0
- package/{readers-8WCimMop.d.ts → readers-ChQ0e92c.d.ts} +1 -1
- package/{readers-CsvlahLi.js → readers-yMS1eAOp.js} +1 -1
- package/{request-pump-binary-oqjWFqZA.js → request-pump-binary-BS1J8DF2.js} +4 -4
- package/{router-BZ-aYeXA.js → router-Bm7A2kjt.js} +4 -4
- package/{router-BQsO8aPV.d.ts → router-D0rf5SkW.d.ts} +2 -2
- package/session.d.ts +2 -2
- package/session.js +64 -16
- package/setup.d.ts +3 -2
- package/setup.js +13 -16
- package/sqlite.d.ts +2 -2
- package/sqlite.js +5 -5
- package/{store-DHlo6fP5.js → store-D80OlpyG.js} +2 -2
- package/store-capability-DBLlWaNO.js +187 -0
- package/store.d.ts +2 -2
- package/store.js +2 -2
- package/{user-capability-BcRQyyEw.js → user-capability-D6hGa3eF.js} +3 -4
- package/wasm.d.ts +13 -6
- package/wasm.js +45 -19
- package/encoding-RUuES_e4.js +0 -99
- package/manifest-mpivREn-.d.ts +0 -122
- package/store-capability-BrUUAwVS.js +0 -389
package/encoding-RUuES_e4.js
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { o as invalidValue, q as requireValue } from "./errors-D11zizZg.js";
|
|
3
|
-
import { n as toBase64 } from "./base64-CDO-a06R.js";
|
|
4
|
-
//#region src/standard-capability-checks.ts
|
|
5
|
-
const checks = /* @__PURE__ */ new WeakMap();
|
|
6
|
-
const registerStandardChecks = (op, rules) => {
|
|
7
|
-
checks.set(op, rules);
|
|
8
|
-
};
|
|
9
|
-
const standardChecks = (op) => checks.get(op);
|
|
10
|
-
//#endregion
|
|
11
|
-
//#region src/encoding.ts
|
|
12
|
-
/** The spec's JSON string form: every U+0000..U+001F uses lowercase \u00xx. */
|
|
13
|
-
const quoteJSON = (s) => "\"" + s.replaceAll(/[\u0000-\u001f"\\]/g, (ch) => ch === "\"" ? String.raw`\"` : ch === "\\" ? "\\\\" : String.raw`\u${ch.charCodeAt(0).toString(16).padStart(4, "0")}`) + "\"";
|
|
14
|
-
const encodeValue = (value, adapter) => {
|
|
15
|
-
requireValue(value);
|
|
16
|
-
const pending = [value];
|
|
17
|
-
const output = [];
|
|
18
|
-
while (pending.length) {
|
|
19
|
-
const next = pending.pop();
|
|
20
|
-
if (typeof next === "string") {
|
|
21
|
-
output.push(next);
|
|
22
|
-
continue;
|
|
23
|
-
}
|
|
24
|
-
switch (next.kind) {
|
|
25
|
-
case "nothing":
|
|
26
|
-
output.push("null");
|
|
27
|
-
break;
|
|
28
|
-
case "boolean":
|
|
29
|
-
output.push(next.asBool() ? "true" : "false");
|
|
30
|
-
break;
|
|
31
|
-
case "text":
|
|
32
|
-
output.push(quoteJSON(next.asText()));
|
|
33
|
-
break;
|
|
34
|
-
case "number": {
|
|
35
|
-
const canonical = next.asDecimal().toString();
|
|
36
|
-
output.push(!canonical.includes(".") && BigInt(canonical) > -(2n ** 53n) && BigInt(canonical) < 2n ** 53n ? canonical : `{"$dec":${quoteJSON(canonical)}}`);
|
|
37
|
-
break;
|
|
38
|
-
}
|
|
39
|
-
case "instant":
|
|
40
|
-
output.push(`{"$instant":${quoteJSON(next.toString())}}`);
|
|
41
|
-
break;
|
|
42
|
-
case "civil date":
|
|
43
|
-
output.push(`{"$date":${quoteJSON(next.toString())}}`);
|
|
44
|
-
break;
|
|
45
|
-
case "object": {
|
|
46
|
-
const o = next.asObjectRef();
|
|
47
|
-
output.push(`{"$object":[${quoteJSON(o.kind)},${quoteJSON(o.id)}]}`);
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
case "bytes":
|
|
51
|
-
output.push(`{"$bytes":${quoteJSON(toBase64(next.bytesView()))}}`);
|
|
52
|
-
break;
|
|
53
|
-
case "quantity": {
|
|
54
|
-
const q = next.asQuantity();
|
|
55
|
-
output.push(`{"$quantity":[${quoteJSON(q.number.toString())},${quoteJSON(q.unit)}]}`);
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
case "range": {
|
|
59
|
-
const { from, to } = next.asRange();
|
|
60
|
-
output.push("{\"$range\":[");
|
|
61
|
-
pending.push("]}", to, ",", from);
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
64
|
-
case "list":
|
|
65
|
-
output.push("[");
|
|
66
|
-
pending.push("]");
|
|
67
|
-
for (let i = next.length; i >= 1; i--) {
|
|
68
|
-
if (i < next.length) pending.push(",");
|
|
69
|
-
pending.push(next.index(i));
|
|
70
|
-
}
|
|
71
|
-
break;
|
|
72
|
-
case "map": {
|
|
73
|
-
const entries = next.entries();
|
|
74
|
-
const tagged = entries.some(([k]) => k.startsWith("$"));
|
|
75
|
-
output.push(tagged ? "{\"$map\":[" : "{");
|
|
76
|
-
pending.push(tagged ? "]}" : "}");
|
|
77
|
-
for (let i = entries.length - 1; i >= 0; i--) {
|
|
78
|
-
const [k, v] = entries[i];
|
|
79
|
-
if (i < entries.length - 1) pending.push(",");
|
|
80
|
-
if (tagged) pending.push("]", v, `[${quoteJSON(k)},`);
|
|
81
|
-
else pending.push(v, `${quoteJSON(k)}:`);
|
|
82
|
-
}
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
case "function":
|
|
86
|
-
case "pattern":
|
|
87
|
-
if (adapter) {
|
|
88
|
-
output.push(adapter(next));
|
|
89
|
-
break;
|
|
90
|
-
}
|
|
91
|
-
invalidValue(`The Value Encoding of a ${next.kind} isn't implemented yet`);
|
|
92
|
-
break;
|
|
93
|
-
default: invalidValue(`The Value Encoding of a ${next.kind} isn't implemented yet`);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return output.join("");
|
|
97
|
-
};
|
|
98
|
-
//#endregion
|
|
99
|
-
export { standardChecks as i, quoteJSON as n, registerStandardChecks as r, encodeValue as t };
|
package/manifest-mpivREn-.d.ts
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
/// <reference lib="esnext.disposable" />
|
|
2
|
-
import { $t as Script, Dn as Library, J as Value, K as Decimal, Qt as Group, Zt as Core, _ as LoadOptions, ht as ObjectKind, jt as Grant, qt as Shape } from "./debug--Of4MSLw.js";
|
|
3
|
-
import { n as Drive, r as DrivenGroupOptions } from "./driver-BIm1mL77.js";
|
|
4
|
-
//#region src/talk.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* Dedents NorthTalk source; rejects JS interpolation.
|
|
7
|
-
*
|
|
8
|
-
* Write NorthTalk's own interpolation as `\${…}` and its backticks as `` \` ``.
|
|
9
|
-
* Pass values as Request arguments instead of splicing them into source. The
|
|
10
|
-
* longest whitespace prefix shared by every non-blank line is removed, compared
|
|
11
|
-
* exactly, so tabs and spaces never match each other.
|
|
12
|
-
*/
|
|
13
|
-
declare const talk: (strings: TemplateStringsArray, ...values: unknown[]) => string;
|
|
14
|
-
//#endregion
|
|
15
|
-
//#region src/plain.d.ts
|
|
16
|
-
/** Plain JS data, as `fromValue` writes it (ADR 0119). */
|
|
17
|
-
type PlainValue = null | boolean | string | Decimal | Uint8Array | Value | PlainValue[] | {
|
|
18
|
-
[key: string]: PlainValue;
|
|
19
|
-
} | Map<string, PlainValue>;
|
|
20
|
-
type ToValueOptions = {
|
|
21
|
-
/**
|
|
22
|
-
* `integer` reads safe integers through `num`; `decimal` uses `num` for
|
|
23
|
-
* any JS number. The default refuses JS numbers.
|
|
24
|
-
*/
|
|
25
|
-
numbers?: 'refuse' | 'integer' | 'decimal';
|
|
26
|
-
};
|
|
27
|
-
type FromValueOptions = {
|
|
28
|
-
maps?: 'object' | 'map';
|
|
29
|
-
numbers?: 'decimal' | 'string';
|
|
30
|
-
};
|
|
31
|
-
/**
|
|
32
|
-
* Plain JS data to a Value by the named constructors (ADR 0119). Anything
|
|
33
|
-
* the table doesn't name, and cyclic data, throws `invalid value`.
|
|
34
|
-
*/
|
|
35
|
-
declare const toValue: (plain: unknown, options?: ToValueOptions) => Value;
|
|
36
|
-
/** A Value as plain JS data (ADR 0119); kinds with no JS form stay Values. */
|
|
37
|
-
declare const fromValue: (v: Value, options?: FromValueOptions) => PlainValue;
|
|
38
|
-
//#endregion
|
|
39
|
-
//#region src/encoding.d.ts
|
|
40
|
-
/**
|
|
41
|
-
* A Message Layer adapter's own spelling of a Function Value or a Text
|
|
42
|
-
* Pattern, which the Value Encoding doesn't hold.
|
|
43
|
-
*/
|
|
44
|
-
type AdapterEncoder = (v: Value) => string;
|
|
45
|
-
declare const encodeValue: (value: Value, adapter?: AdapterEncoder) => string;
|
|
46
|
-
//#endregion
|
|
47
|
-
//#region src/json.d.ts
|
|
48
|
-
/** Read exact decimal digits, NFC strings and insertion-ordered maps. */
|
|
49
|
-
declare const decodeJson: (source: string) => Value;
|
|
50
|
-
/** Compact JSON, with canonical numbers and chapter 7's string escapes. */
|
|
51
|
-
declare const encodeJson: (value: Value) => string;
|
|
52
|
-
//#endregion
|
|
53
|
-
//#region src/handlers.d.ts
|
|
54
|
-
/** Untyped Handler calls accept safe-integer JS numbers and plain data. */
|
|
55
|
-
type Handlers = {
|
|
56
|
-
[name: string]: (...args: (PlainValue | number | bigint)[]) => Promise<PlainValue>;
|
|
57
|
-
};
|
|
58
|
-
/** The Host supplies T without runtime checking of its arguments or results. */
|
|
59
|
-
type ScriptWithHandlers<T = Handlers> = Script & {
|
|
60
|
-
readonly handlers: T;
|
|
61
|
-
};
|
|
62
|
-
/**
|
|
63
|
-
* Calls invoke with integer-mode toValue arguments and default fromValue answers.
|
|
64
|
-
* The Script's existing driver or Host Pump loop still runs the Requests.
|
|
65
|
-
* Promise hooks, symbols and non-message properties read as undefined.
|
|
66
|
-
*/
|
|
67
|
-
declare const handlersOf: <T = Handlers>(script: Script) => T;
|
|
68
|
-
//#endregion
|
|
69
|
-
//#region src/group-helper.d.ts
|
|
70
|
-
/** A Group whose driver closes explicitly or at the end of an `await using` scope. */
|
|
71
|
-
type DrivenGroup = Omit<Group, 'load'> & Pick<Drive, 'close' | typeof Symbol.asyncDispose> & {
|
|
72
|
-
load<T = Handlers>(o: LoadOptions): ScriptWithHandlers<T>;
|
|
73
|
-
};
|
|
74
|
-
/** The Zig Host Adapter requires its asynchronously created Core. */
|
|
75
|
-
type CreateGroupOptions = DrivenGroupOptions & {
|
|
76
|
-
core: Core;
|
|
77
|
-
};
|
|
78
|
-
/** Creates a driven Group on the supplied Core; close has the driver's shutdown semantics. */
|
|
79
|
-
declare const createGroup: (o: CreateGroupOptions) => DrivenGroup;
|
|
80
|
-
//#endregion
|
|
81
|
-
//#region src/inline-grants.d.ts
|
|
82
|
-
/** Argument and result types are supplied by the Host, without runtime checking. */
|
|
83
|
-
type InlineFunction = (...args: never[]) => unknown;
|
|
84
|
-
type InlineOperation = InlineFunction | {
|
|
85
|
-
arity?: number;
|
|
86
|
-
fn: InlineFunction;
|
|
87
|
-
} | {
|
|
88
|
-
arity?: number;
|
|
89
|
-
async: InlineFunction;
|
|
90
|
-
maxPendingMs?: number;
|
|
91
|
-
};
|
|
92
|
-
/**
|
|
93
|
-
* Defines one Capability per key and grants all its Operations. Arguments use
|
|
94
|
-
* default fromValue; results use integer-mode toValue. Arity is fn.length unless
|
|
95
|
-
* overridden, including for async functions, which also receive a final signal.
|
|
96
|
-
*/
|
|
97
|
-
declare const inlineGrants: (capabilities: Readonly<Record<string, Readonly<Record<string, InlineOperation>>>>) => Record<string, Grant<void>>;
|
|
98
|
-
//#endregion
|
|
99
|
-
//#region src/manifest.d.ts
|
|
100
|
-
type MessageDecl = {
|
|
101
|
-
args?: readonly Shape[];
|
|
102
|
-
description?: string;
|
|
103
|
-
/** NorthTalk source, each sending this message. */
|
|
104
|
-
examples?: readonly string[];
|
|
105
|
-
name: string;
|
|
106
|
-
receivers?: readonly ObjectKind[];
|
|
107
|
-
};
|
|
108
|
-
type ManifestSpec = {
|
|
109
|
-
grants: Readonly<Record<string, Grant<any>>>;
|
|
110
|
-
kind: string;
|
|
111
|
-
libraries?: readonly Library[];
|
|
112
|
-
messages?: readonly MessageDecl[];
|
|
113
|
-
objectKinds?: readonly ObjectKind[];
|
|
114
|
-
objects?: Readonly<Record<string, ObjectKind>>;
|
|
115
|
-
/** The Owner Kind: one of objectKinds, the kind of `me` for tooling. */
|
|
116
|
-
ownerKind?: ObjectKind;
|
|
117
|
-
version: string;
|
|
118
|
-
};
|
|
119
|
-
/** Chapter 9's deterministic JSON file, ending in LF; never calls the Host. */
|
|
120
|
-
declare const exportManifest: (m: ManifestSpec) => string;
|
|
121
|
-
//#endregion
|
|
122
|
-
export { PlainValue as _, InlineOperation as a, toValue as b, DrivenGroup as c, ScriptWithHandlers as d, handlersOf as f, FromValueOptions as g, encodeValue as h, InlineFunction as i, createGroup as l, encodeJson as m, MessageDecl as n, inlineGrants as o, decodeJson as p, exportManifest as r, CreateGroupOptions as s, ManifestSpec as t, Handlers as u, ToValueOptions as v, talk as x, fromValue as y };
|
|
@@ -1,389 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { L as nothing, N as map, Q as text, T as instant, i as ScriptError, t as HostError, u as bool } from "./errors-D11zizZg.js";
|
|
3
|
-
import { St as validComputedMessageName, dt as errorMessages, i as arithmetic, n as ScriptError$1, vt as defineValueCapability, xt as shape } from "./operations-DnCcztkZ.js";
|
|
4
|
-
import { r as registerStandardChecks } from "./encoding-RUuES_e4.js";
|
|
5
|
-
//#region src/standard-capabilities.ts
|
|
6
|
-
const costOf = (costs, name) => {
|
|
7
|
-
const cost = costs && Object.hasOwn(costs, name) ? costs[name] : void 0;
|
|
8
|
-
if (!cost || !Number.isSafeInteger(cost.fuel) || cost.fuel < 0 || cost.alloc !== void 0 && (!Number.isSafeInteger(cost.alloc) || cost.alloc < 0)) throw new HostError("invalid value", `Invalid or missing cost for ${name}`);
|
|
9
|
-
return Object.freeze({
|
|
10
|
-
fuel: cost.fuel,
|
|
11
|
-
...cost.alloc === void 0 ? {} : { alloc: cost.alloc }
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
const fixed = (capability) => {
|
|
15
|
-
for (const op of capability.operations.values()) {
|
|
16
|
-
Object.freeze(op.args);
|
|
17
|
-
Object.freeze(op.errors);
|
|
18
|
-
Object.freeze(op);
|
|
19
|
-
}
|
|
20
|
-
return capability;
|
|
21
|
-
};
|
|
22
|
-
const instantShape = Object.freeze({
|
|
23
|
-
k: "kind",
|
|
24
|
-
kind: "instant"
|
|
25
|
-
});
|
|
26
|
-
const textShape$1 = Object.freeze({
|
|
27
|
-
k: "kind",
|
|
28
|
-
kind: "text"
|
|
29
|
-
});
|
|
30
|
-
const valueShape = Object.freeze({ k: "value" });
|
|
31
|
-
const dataListShape = Object.freeze({
|
|
32
|
-
k: "list",
|
|
33
|
-
of: Object.freeze({ k: "any" })
|
|
34
|
-
});
|
|
35
|
-
/** The Pump's Clock reading; there is no Host clock implementation. */
|
|
36
|
-
const clockCapability = (costs) => fixed(defineValueCapability("clock", { now: {
|
|
37
|
-
mode: "immediate",
|
|
38
|
-
args: [],
|
|
39
|
-
result: instantShape,
|
|
40
|
-
errors: [],
|
|
41
|
-
cost: costOf(costs, "now"),
|
|
42
|
-
do: (call) => instant(call.now)
|
|
43
|
-
} }));
|
|
44
|
-
/** The Host owns durable timers, scoped by Script and name. */
|
|
45
|
-
const timerCapability = (impl, costs) => {
|
|
46
|
-
if (!impl || typeof impl.schedule !== "function" || typeof impl.cancel !== "function") throw new HostError("invalid value", "Timer needs Schedule and Cancel");
|
|
47
|
-
return fixed(defineValueCapability("timer", {
|
|
48
|
-
schedule: {
|
|
49
|
-
mode: "fire-and-forget",
|
|
50
|
-
args: [
|
|
51
|
-
textShape$1,
|
|
52
|
-
instantShape,
|
|
53
|
-
textShape$1,
|
|
54
|
-
dataListShape
|
|
55
|
-
],
|
|
56
|
-
errors: [],
|
|
57
|
-
cost: costOf(costs, "schedule"),
|
|
58
|
-
fire: (call, name, at, message, args) => impl.schedule(call, name.asText(), at, message.asText(), args)
|
|
59
|
-
},
|
|
60
|
-
cancel: {
|
|
61
|
-
mode: "fire-and-forget",
|
|
62
|
-
args: [textShape$1],
|
|
63
|
-
errors: [],
|
|
64
|
-
cost: costOf(costs, "cancel"),
|
|
65
|
-
fire: (call, name) => impl.cancel(call, name.asText())
|
|
66
|
-
}
|
|
67
|
-
}));
|
|
68
|
-
};
|
|
69
|
-
/** The Host shows Values in text form and answers read with a line of text. */
|
|
70
|
-
const consoleCapability = (impl, costs) => {
|
|
71
|
-
if (!impl || typeof impl.write !== "function" || typeof impl.read !== "function") throw new HostError("invalid value", "Console needs Write and Read");
|
|
72
|
-
return fixed(defineValueCapability("console", {
|
|
73
|
-
write: {
|
|
74
|
-
mode: "fire-and-forget",
|
|
75
|
-
args: [valueShape],
|
|
76
|
-
errors: [],
|
|
77
|
-
cost: costOf(costs, "write"),
|
|
78
|
-
fire: (call, value) => impl.write(call, value)
|
|
79
|
-
},
|
|
80
|
-
read: {
|
|
81
|
-
mode: "suspending",
|
|
82
|
-
args: [],
|
|
83
|
-
result: textShape$1,
|
|
84
|
-
errors: [],
|
|
85
|
-
maxPendingMs: 2147483647,
|
|
86
|
-
cost: costOf(costs, "read"),
|
|
87
|
-
start: (call) => impl.read(call)
|
|
88
|
-
}
|
|
89
|
-
}));
|
|
90
|
-
};
|
|
91
|
-
const civilShape = Object.freeze({
|
|
92
|
-
k: "kind",
|
|
93
|
-
kind: "civil date"
|
|
94
|
-
});
|
|
95
|
-
const optionalTextShape = Object.freeze({
|
|
96
|
-
k: "optional",
|
|
97
|
-
of: textShape$1
|
|
98
|
-
});
|
|
99
|
-
const secondsShape = Object.freeze({
|
|
100
|
-
k: "quantity",
|
|
101
|
-
unit: "s"
|
|
102
|
-
});
|
|
103
|
-
const disambiguations = /* @__PURE__ */ new Set([
|
|
104
|
-
"compatible",
|
|
105
|
-
"earlier",
|
|
106
|
-
"later",
|
|
107
|
-
"reject"
|
|
108
|
-
]);
|
|
109
|
-
const zoneText = (value) => value?.asText();
|
|
110
|
-
const calendarError = (code, data) => data.get("zone").kind === "text" && (code === "unknown zone" || code === "ambiguous time" && data.get("civil").kind === "civil date");
|
|
111
|
-
const checkToInstant = (args) => {
|
|
112
|
-
const civil = args[0];
|
|
113
|
-
const disambiguation = zoneText(args[1]);
|
|
114
|
-
const bad = !("hour" in civil.asCivilDate()) ? civil : args.length === 3 && disambiguation !== void 0 && !disambiguations.has(disambiguation) ? args[1] : void 0;
|
|
115
|
-
if (bad) throw new ScriptError$1("out of domain", [["function", text("toInstant")], ["value", bad]], true);
|
|
116
|
-
};
|
|
117
|
-
/** The Host owns zone data; the Grant binding supplies its default zone. */
|
|
118
|
-
const calendarCapability = (impl, costs) => {
|
|
119
|
-
for (const name of [
|
|
120
|
-
"today",
|
|
121
|
-
"now",
|
|
122
|
-
"toCivil",
|
|
123
|
-
"toInstant",
|
|
124
|
-
"offset",
|
|
125
|
-
"zone"
|
|
126
|
-
]) if (!impl || typeof impl[name] !== "function") throw new HostError("invalid value", `Calendar needs ${name}`);
|
|
127
|
-
const unknownZone = [{
|
|
128
|
-
code: "unknown zone",
|
|
129
|
-
fields: { zone: textShape$1 }
|
|
130
|
-
}];
|
|
131
|
-
const operations = {
|
|
132
|
-
today: {
|
|
133
|
-
mode: "immediate",
|
|
134
|
-
args: [optionalTextShape],
|
|
135
|
-
result: civilShape,
|
|
136
|
-
errors: unknownZone,
|
|
137
|
-
cost: costOf(costs, "today"),
|
|
138
|
-
do: (call, zone) => impl.today(call, zoneText(zone))
|
|
139
|
-
},
|
|
140
|
-
now: {
|
|
141
|
-
mode: "immediate",
|
|
142
|
-
args: [optionalTextShape],
|
|
143
|
-
result: civilShape,
|
|
144
|
-
errors: unknownZone,
|
|
145
|
-
cost: costOf(costs, "now"),
|
|
146
|
-
do: (call, zone) => impl.now(call, zoneText(zone))
|
|
147
|
-
},
|
|
148
|
-
toCivil: {
|
|
149
|
-
mode: "immediate",
|
|
150
|
-
args: [instantShape, optionalTextShape],
|
|
151
|
-
result: civilShape,
|
|
152
|
-
errors: unknownZone,
|
|
153
|
-
cost: costOf(costs, "toCivil"),
|
|
154
|
-
do: (call, value, zone) => impl.toCivil(call, value, zoneText(zone))
|
|
155
|
-
},
|
|
156
|
-
toInstant: {
|
|
157
|
-
mode: "immediate",
|
|
158
|
-
args: [
|
|
159
|
-
civilShape,
|
|
160
|
-
optionalTextShape,
|
|
161
|
-
optionalTextShape
|
|
162
|
-
],
|
|
163
|
-
result: instantShape,
|
|
164
|
-
errors: [...unknownZone, {
|
|
165
|
-
code: "ambiguous time",
|
|
166
|
-
fields: {
|
|
167
|
-
civil: civilShape,
|
|
168
|
-
zone: textShape$1
|
|
169
|
-
}
|
|
170
|
-
}],
|
|
171
|
-
cost: costOf(costs, "toInstant"),
|
|
172
|
-
do: (call, ...args) => {
|
|
173
|
-
const second = zoneText(args[1]);
|
|
174
|
-
const isZone = args.length === 2 && second !== void 0 && !disambiguations.has(second);
|
|
175
|
-
return impl.toInstant(call, args[0], isZone ? "compatible" : second ?? "compatible", isZone ? second : zoneText(args[2]));
|
|
176
|
-
}
|
|
177
|
-
},
|
|
178
|
-
offset: {
|
|
179
|
-
mode: "immediate",
|
|
180
|
-
args: [instantShape, optionalTextShape],
|
|
181
|
-
result: secondsShape,
|
|
182
|
-
errors: unknownZone,
|
|
183
|
-
cost: costOf(costs, "offset"),
|
|
184
|
-
do: (call, value, zone) => impl.offset(call, value, zoneText(zone))
|
|
185
|
-
},
|
|
186
|
-
zone: {
|
|
187
|
-
mode: "immediate",
|
|
188
|
-
args: [optionalTextShape],
|
|
189
|
-
result: textShape$1,
|
|
190
|
-
errors: unknownZone,
|
|
191
|
-
cost: costOf(costs, "zone"),
|
|
192
|
-
do: (call, zone) => impl.zone(call, zoneText(zone))
|
|
193
|
-
}
|
|
194
|
-
};
|
|
195
|
-
for (const [name, op] of Object.entries(operations)) registerStandardChecks(op, {
|
|
196
|
-
error: calendarError,
|
|
197
|
-
...name === "toInstant" ? { arguments: checkToInstant } : {},
|
|
198
|
-
...[
|
|
199
|
-
"today",
|
|
200
|
-
"now",
|
|
201
|
-
"toCivil"
|
|
202
|
-
].includes(name) ? { result: (value) => !("hour" in value.asCivilDate()) === (name === "today") } : {}
|
|
203
|
-
});
|
|
204
|
-
return fixed(defineValueCapability("calendar", operations));
|
|
205
|
-
};
|
|
206
|
-
//#endregion
|
|
207
|
-
//#region src/store-capability.ts
|
|
208
|
-
/** A Core-raised error as the Host sees it, with its catalogue message. */
|
|
209
|
-
const hostScriptError = (code, fields) => {
|
|
210
|
-
const message = (errorMessages[code] ?? code).replaceAll(/{(\w+)}/g, (_, name) => {
|
|
211
|
-
const field = fields.find(([k]) => k === name);
|
|
212
|
-
return field ? field[1].toString() : `{${name}}`;
|
|
213
|
-
});
|
|
214
|
-
return new ScriptError(code, message, map(fields.map(([k, v]) => [k, v])));
|
|
215
|
-
};
|
|
216
|
-
/** The `+` rules outside any Run, uncharged (chapter 9, Adding). */
|
|
217
|
-
const add = (a, b) => {
|
|
218
|
-
try {
|
|
219
|
-
return arithmetic("add", a, b);
|
|
220
|
-
} catch (error) {
|
|
221
|
-
throw error instanceof ScriptError$1 ? hostScriptError(error.code, error.fields) : error;
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
const textShape = shape.text;
|
|
225
|
-
const keyShape = textShape;
|
|
226
|
-
const amountShape = shape.oneOf(shape.number, {
|
|
227
|
-
k: "kind",
|
|
228
|
-
kind: "quantity"
|
|
229
|
-
});
|
|
230
|
-
const OPERATIONS = [
|
|
231
|
-
"get",
|
|
232
|
-
"set",
|
|
233
|
-
"delete",
|
|
234
|
-
"keys",
|
|
235
|
-
"increment",
|
|
236
|
-
"swap",
|
|
237
|
-
"watch",
|
|
238
|
-
"unwatch"
|
|
239
|
-
];
|
|
240
|
-
const isText = (data, field) => data.get(field).kind === "text";
|
|
241
|
-
const errorFields = {
|
|
242
|
-
"can't store": (data) => isText(data, "kind"),
|
|
243
|
-
"store full": (data) => [
|
|
244
|
-
"size",
|
|
245
|
-
"keys",
|
|
246
|
-
"value"
|
|
247
|
-
].includes(data.get("limit").asText() ?? ""),
|
|
248
|
-
"store busy": (data) => isText(data, "key"),
|
|
249
|
-
"watch limit": (data) => [
|
|
250
|
-
"watches",
|
|
251
|
-
"size",
|
|
252
|
-
"pending"
|
|
253
|
-
].includes(data.get("limit").asText() ?? ""),
|
|
254
|
-
"wrong kind": (data) => isText(data, "expected") && isText(data, "got") && data.entries().some(([k]) => k === "value"),
|
|
255
|
-
"incompatible units": (data) => isText(data, "left") && isText(data, "right"),
|
|
256
|
-
overflow: (data) => isText(data, "operator")
|
|
257
|
-
};
|
|
258
|
-
const checkKey = (args) => {
|
|
259
|
-
if (args[0].asText() === "") throw new ScriptError$1("invalid key", [], true);
|
|
260
|
-
};
|
|
261
|
-
const effectiveMessage = (args) => args[2]?.asText() ?? "storeChanged";
|
|
262
|
-
const checkUnwatch = (args) => {
|
|
263
|
-
if (args[0].asText() === "") throw new ScriptError$1("invalid watch", [["field", text("name")]], true);
|
|
264
|
-
};
|
|
265
|
-
const checkWatch = (args) => {
|
|
266
|
-
checkUnwatch(args);
|
|
267
|
-
const message = effectiveMessage(args);
|
|
268
|
-
if (message.includes(":") || !validComputedMessageName(message, 1)) throw new ScriptError$1("invalid watch", [["field", text("message")]], true);
|
|
269
|
-
};
|
|
270
|
-
const argumentChecks = {
|
|
271
|
-
watch: checkWatch,
|
|
272
|
-
unwatch: checkUnwatch
|
|
273
|
-
};
|
|
274
|
-
const errors = (...codes) => codes.map((code) => ({ code }));
|
|
275
|
-
const writes = [
|
|
276
|
-
"can't store",
|
|
277
|
-
"store full",
|
|
278
|
-
"store busy"
|
|
279
|
-
];
|
|
280
|
-
const key = (args) => args[0].asText();
|
|
281
|
-
/** The Store is the Host's; the Grant binding names it, and `impl` coordinates every binding. */
|
|
282
|
-
const storeCapability = (impl, costs) => {
|
|
283
|
-
for (const name of [
|
|
284
|
-
...OPERATIONS,
|
|
285
|
-
"begin",
|
|
286
|
-
"commit",
|
|
287
|
-
"rollback",
|
|
288
|
-
"release"
|
|
289
|
-
]) if (!impl || typeof impl[name] !== "function") throw new HostError("invalid value", `Store needs ${name}`);
|
|
290
|
-
const operations = {
|
|
291
|
-
watch: {
|
|
292
|
-
mode: "immediate",
|
|
293
|
-
args: [
|
|
294
|
-
textShape,
|
|
295
|
-
textShape,
|
|
296
|
-
shape.optional(textShape)
|
|
297
|
-
],
|
|
298
|
-
result: shape.nothing,
|
|
299
|
-
errors: errors("watch limit"),
|
|
300
|
-
cost: costOf(costs, "watch"),
|
|
301
|
-
do: (call, ...args) => {
|
|
302
|
-
impl.watch(call, key(args), args[1].asText(), effectiveMessage(args));
|
|
303
|
-
return nothing;
|
|
304
|
-
}
|
|
305
|
-
},
|
|
306
|
-
unwatch: {
|
|
307
|
-
mode: "immediate",
|
|
308
|
-
args: [textShape],
|
|
309
|
-
result: shape.nothing,
|
|
310
|
-
errors: [],
|
|
311
|
-
cost: costOf(costs, "unwatch"),
|
|
312
|
-
do: (call, ...args) => {
|
|
313
|
-
impl.unwatch(call, key(args));
|
|
314
|
-
return nothing;
|
|
315
|
-
}
|
|
316
|
-
},
|
|
317
|
-
get: {
|
|
318
|
-
mode: "immediate",
|
|
319
|
-
args: [keyShape, shape.optional(shape.any)],
|
|
320
|
-
result: shape.any,
|
|
321
|
-
errors: [],
|
|
322
|
-
cost: costOf(costs, "get"),
|
|
323
|
-
do: (call, ...args) => impl.get(call, key(args), args[1])
|
|
324
|
-
},
|
|
325
|
-
set: {
|
|
326
|
-
mode: "immediate",
|
|
327
|
-
args: [keyShape, shape.any],
|
|
328
|
-
result: shape.nothing,
|
|
329
|
-
errors: errors(...writes),
|
|
330
|
-
cost: costOf(costs, "set"),
|
|
331
|
-
segmentBound: true,
|
|
332
|
-
do: (call, ...args) => {
|
|
333
|
-
impl.set(call, key(args), args[1]);
|
|
334
|
-
return nothing;
|
|
335
|
-
}
|
|
336
|
-
},
|
|
337
|
-
delete: {
|
|
338
|
-
mode: "immediate",
|
|
339
|
-
args: [keyShape],
|
|
340
|
-
result: shape.nothing,
|
|
341
|
-
errors: errors("store busy"),
|
|
342
|
-
cost: costOf(costs, "delete"),
|
|
343
|
-
segmentBound: true,
|
|
344
|
-
do: (call, ...args) => {
|
|
345
|
-
impl.delete(call, key(args));
|
|
346
|
-
return nothing;
|
|
347
|
-
}
|
|
348
|
-
},
|
|
349
|
-
keys: {
|
|
350
|
-
mode: "immediate",
|
|
351
|
-
args: [shape.optional(textShape)],
|
|
352
|
-
result: shape.listOf(textShape),
|
|
353
|
-
errors: [],
|
|
354
|
-
cost: costOf(costs, "keys"),
|
|
355
|
-
do: (call, prefix) => impl.keys(call, prefix?.asText())
|
|
356
|
-
},
|
|
357
|
-
increment: {
|
|
358
|
-
mode: "immediate",
|
|
359
|
-
args: [keyShape, shape.optional(amountShape)],
|
|
360
|
-
result: amountShape,
|
|
361
|
-
errors: errors("wrong kind", "incompatible units", "overflow", "store full", "store busy"),
|
|
362
|
-
cost: costOf(costs, "increment"),
|
|
363
|
-
segmentBound: true,
|
|
364
|
-
do: (call, ...args) => impl.increment(call, key(args), args[1])
|
|
365
|
-
},
|
|
366
|
-
swap: {
|
|
367
|
-
mode: "immediate",
|
|
368
|
-
args: [
|
|
369
|
-
keyShape,
|
|
370
|
-
shape.any,
|
|
371
|
-
shape.any
|
|
372
|
-
],
|
|
373
|
-
result: shape.bool,
|
|
374
|
-
errors: errors(...writes),
|
|
375
|
-
cost: costOf(costs, "swap"),
|
|
376
|
-
segmentBound: true,
|
|
377
|
-
do: (call, ...args) => bool(impl.swap(call, key(args), args[1], args[2]))
|
|
378
|
-
}
|
|
379
|
-
};
|
|
380
|
-
const coordinator = impl;
|
|
381
|
-
const capability = defineValueCapability("store", operations, { coordinator: () => coordinator }, (context) => impl.release(context));
|
|
382
|
-
for (const [name, op] of capability.operations) registerStandardChecks(op, {
|
|
383
|
-
error: (code, data) => Boolean(op.errors?.some((e) => e.code === code) && errorFields[code]?.(data)),
|
|
384
|
-
...name === "keys" ? {} : { arguments: argumentChecks[name] ?? checkKey }
|
|
385
|
-
});
|
|
386
|
-
return fixed(capability);
|
|
387
|
-
};
|
|
388
|
-
//#endregion
|
|
389
|
-
export { clockCapability as a, fixed as c, calendarCapability as i, timerCapability as l, hostScriptError as n, consoleCapability as o, storeCapability as r, costOf as s, add as t };
|