@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
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
|
|
2
|
+
import { T as instant, et as text, o as invalidValue, q as requireValue, t as HostError } from "./errors-P3ga1I-9.js";
|
|
3
|
+
import { bt as defineValueCapability, n as ScriptError } from "./operations-CGjDlkGU.js";
|
|
4
|
+
import { n as toBase64 } from "./base64-CDO-a06R.js";
|
|
5
|
+
//#region src/standard-capability-checks.ts
|
|
6
|
+
const checks = /* @__PURE__ */ new WeakMap();
|
|
7
|
+
const registerStandardChecks = (op, rules) => {
|
|
8
|
+
checks.set(op, rules);
|
|
9
|
+
};
|
|
10
|
+
const standardChecks = (op) => checks.get(op);
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/standard-capabilities.ts
|
|
13
|
+
/** The reserved Grant name every Script holds a Group's musical clock under. */
|
|
14
|
+
const MUSICAL_CLOCK = "musical-clock";
|
|
15
|
+
const costOf = (costs, name) => {
|
|
16
|
+
const cost = costs && Object.hasOwn(costs, name) ? costs[name] : void 0;
|
|
17
|
+
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}`);
|
|
18
|
+
return Object.freeze({
|
|
19
|
+
fuel: cost.fuel,
|
|
20
|
+
...cost.alloc === void 0 ? {} : { alloc: cost.alloc }
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
const fixed = (capability) => {
|
|
24
|
+
for (const op of capability.operations.values()) {
|
|
25
|
+
Object.freeze(op.args);
|
|
26
|
+
Object.freeze(op.errors);
|
|
27
|
+
Object.freeze(op);
|
|
28
|
+
}
|
|
29
|
+
return capability;
|
|
30
|
+
};
|
|
31
|
+
const instantShape = Object.freeze({
|
|
32
|
+
k: "kind",
|
|
33
|
+
kind: "instant"
|
|
34
|
+
});
|
|
35
|
+
const textShape = Object.freeze({
|
|
36
|
+
k: "kind",
|
|
37
|
+
kind: "text"
|
|
38
|
+
});
|
|
39
|
+
const valueShape = Object.freeze({ k: "value" });
|
|
40
|
+
const dataListShape = Object.freeze({
|
|
41
|
+
k: "list",
|
|
42
|
+
of: Object.freeze({ k: "any" })
|
|
43
|
+
});
|
|
44
|
+
/** The Pump's Clock reading; there is no Host clock implementation. */
|
|
45
|
+
const clockCapability = (costs) => fixed(defineValueCapability("clock", { now: {
|
|
46
|
+
mode: "immediate",
|
|
47
|
+
args: [],
|
|
48
|
+
result: instantShape,
|
|
49
|
+
errors: [],
|
|
50
|
+
cost: costOf(costs, "now"),
|
|
51
|
+
do: (call) => instant(call.now)
|
|
52
|
+
} }));
|
|
53
|
+
/** The Host owns durable timers, scoped by Script and name. */
|
|
54
|
+
const timerCapability = (impl, costs) => {
|
|
55
|
+
if (!impl || typeof impl.schedule !== "function" || typeof impl.cancel !== "function") throw new HostError("invalid value", "Timer needs Schedule and Cancel");
|
|
56
|
+
return fixed(defineValueCapability("timer", {
|
|
57
|
+
schedule: {
|
|
58
|
+
mode: "fire-and-forget",
|
|
59
|
+
args: [
|
|
60
|
+
textShape,
|
|
61
|
+
instantShape,
|
|
62
|
+
textShape,
|
|
63
|
+
dataListShape
|
|
64
|
+
],
|
|
65
|
+
errors: [],
|
|
66
|
+
cost: costOf(costs, "schedule"),
|
|
67
|
+
fire: (call, name, at, message, args) => impl.schedule(call, name.asText(), at, message.asText(), args)
|
|
68
|
+
},
|
|
69
|
+
cancel: {
|
|
70
|
+
mode: "fire-and-forget",
|
|
71
|
+
args: [textShape],
|
|
72
|
+
errors: [],
|
|
73
|
+
cost: costOf(costs, "cancel"),
|
|
74
|
+
fire: (call, name) => impl.cancel(call, name.asText())
|
|
75
|
+
}
|
|
76
|
+
}));
|
|
77
|
+
};
|
|
78
|
+
const musicalShape = Object.freeze({
|
|
79
|
+
k: "oneOf",
|
|
80
|
+
of: Object.freeze([Object.freeze({
|
|
81
|
+
k: "unitKind",
|
|
82
|
+
kind: "bar"
|
|
83
|
+
}), Object.freeze({
|
|
84
|
+
k: "unitKind",
|
|
85
|
+
kind: "beat"
|
|
86
|
+
})])
|
|
87
|
+
});
|
|
88
|
+
/**
|
|
89
|
+
* The musical clock a Group's `musicalClock` option takes (chapter 9): one
|
|
90
|
+
* suspending `wait`, with no `maxPending`, that Scripts call through a plain
|
|
91
|
+
* `wait` in a Musical Unit. Only the Core makes it, since `wait` can't name
|
|
92
|
+
* a Host's Operation.
|
|
93
|
+
*/
|
|
94
|
+
const musicalClockCapability = (impl, costs, release) => {
|
|
95
|
+
if (!impl || typeof impl.wait !== "function") throw new HostError("invalid value", "A musical clock needs Wait");
|
|
96
|
+
return fixed(defineValueCapability(MUSICAL_CLOCK, { wait: {
|
|
97
|
+
mode: "suspending",
|
|
98
|
+
args: [musicalShape],
|
|
99
|
+
result: Object.freeze({
|
|
100
|
+
k: "kind",
|
|
101
|
+
kind: "nothing"
|
|
102
|
+
}),
|
|
103
|
+
cost: costOf(costs, "wait"),
|
|
104
|
+
start: (call, count) => impl.wait(call, count)
|
|
105
|
+
} }, void 0, release, MUSICAL_CLOCK));
|
|
106
|
+
};
|
|
107
|
+
/** Whether a Capability is one `musicalClockCapability` made. */
|
|
108
|
+
const isMusicalClock = (c) => {
|
|
109
|
+
const op = c.operations.get("wait");
|
|
110
|
+
return c.name === "musical-clock" && c.operations.size === 1 && op?.mode === "suspending" && op.maxPendingMs === void 0;
|
|
111
|
+
};
|
|
112
|
+
/** The Host shows Values in text form and answers read with a line of text. */
|
|
113
|
+
const consoleCapability = (impl, costs) => {
|
|
114
|
+
if (!impl || typeof impl.write !== "function" || typeof impl.read !== "function") throw new HostError("invalid value", "Console needs Write and Read");
|
|
115
|
+
return fixed(defineValueCapability("console", {
|
|
116
|
+
write: {
|
|
117
|
+
mode: "fire-and-forget",
|
|
118
|
+
args: [valueShape],
|
|
119
|
+
errors: [],
|
|
120
|
+
cost: costOf(costs, "write"),
|
|
121
|
+
fire: (call, value) => impl.write(call, value)
|
|
122
|
+
},
|
|
123
|
+
read: {
|
|
124
|
+
mode: "suspending",
|
|
125
|
+
args: [],
|
|
126
|
+
result: textShape,
|
|
127
|
+
errors: [],
|
|
128
|
+
maxPendingMs: 2147483647,
|
|
129
|
+
cost: costOf(costs, "read"),
|
|
130
|
+
start: (call) => impl.read(call)
|
|
131
|
+
}
|
|
132
|
+
}));
|
|
133
|
+
};
|
|
134
|
+
const civilShape = Object.freeze({
|
|
135
|
+
k: "kind",
|
|
136
|
+
kind: "civil date"
|
|
137
|
+
});
|
|
138
|
+
const optionalTextShape = Object.freeze({
|
|
139
|
+
k: "optional",
|
|
140
|
+
of: textShape
|
|
141
|
+
});
|
|
142
|
+
const secondsShape = Object.freeze({
|
|
143
|
+
k: "quantity",
|
|
144
|
+
unit: "s"
|
|
145
|
+
});
|
|
146
|
+
const disambiguations = /* @__PURE__ */ new Set([
|
|
147
|
+
"compatible",
|
|
148
|
+
"earlier",
|
|
149
|
+
"later",
|
|
150
|
+
"reject"
|
|
151
|
+
]);
|
|
152
|
+
const zoneText = (value) => value?.asText();
|
|
153
|
+
const calendarError = (code, data) => data.get("zone").kind === "text" && (code === "unknown zone" || code === "ambiguous time" && data.get("civil").kind === "civil date");
|
|
154
|
+
const checkToInstant = (args) => {
|
|
155
|
+
const civil = args[0];
|
|
156
|
+
const disambiguation = zoneText(args[1]);
|
|
157
|
+
const bad = !("hour" in civil.asCivilDate()) ? civil : args.length === 3 && disambiguation !== void 0 && !disambiguations.has(disambiguation) ? args[1] : void 0;
|
|
158
|
+
if (bad) throw new ScriptError("out of domain", [["function", text("toInstant")], ["value", bad]], true);
|
|
159
|
+
};
|
|
160
|
+
/** The Host owns zone data; the Grant binding supplies its default zone. */
|
|
161
|
+
const calendarCapability = (impl, costs) => {
|
|
162
|
+
for (const name of [
|
|
163
|
+
"today",
|
|
164
|
+
"now",
|
|
165
|
+
"toCivil",
|
|
166
|
+
"toInstant",
|
|
167
|
+
"offset",
|
|
168
|
+
"zone"
|
|
169
|
+
]) if (!impl || typeof impl[name] !== "function") throw new HostError("invalid value", `Calendar needs ${name}`);
|
|
170
|
+
const unknownZone = [{
|
|
171
|
+
code: "unknown zone",
|
|
172
|
+
fields: { zone: textShape }
|
|
173
|
+
}];
|
|
174
|
+
const operations = {
|
|
175
|
+
today: {
|
|
176
|
+
mode: "immediate",
|
|
177
|
+
args: [optionalTextShape],
|
|
178
|
+
result: civilShape,
|
|
179
|
+
errors: unknownZone,
|
|
180
|
+
cost: costOf(costs, "today"),
|
|
181
|
+
do: (call, zone) => impl.today(call, zoneText(zone))
|
|
182
|
+
},
|
|
183
|
+
now: {
|
|
184
|
+
mode: "immediate",
|
|
185
|
+
args: [optionalTextShape],
|
|
186
|
+
result: civilShape,
|
|
187
|
+
errors: unknownZone,
|
|
188
|
+
cost: costOf(costs, "now"),
|
|
189
|
+
do: (call, zone) => impl.now(call, zoneText(zone))
|
|
190
|
+
},
|
|
191
|
+
toCivil: {
|
|
192
|
+
mode: "immediate",
|
|
193
|
+
args: [instantShape, optionalTextShape],
|
|
194
|
+
result: civilShape,
|
|
195
|
+
errors: unknownZone,
|
|
196
|
+
cost: costOf(costs, "toCivil"),
|
|
197
|
+
do: (call, value, zone) => impl.toCivil(call, value, zoneText(zone))
|
|
198
|
+
},
|
|
199
|
+
toInstant: {
|
|
200
|
+
mode: "immediate",
|
|
201
|
+
args: [
|
|
202
|
+
civilShape,
|
|
203
|
+
optionalTextShape,
|
|
204
|
+
optionalTextShape
|
|
205
|
+
],
|
|
206
|
+
result: instantShape,
|
|
207
|
+
errors: [...unknownZone, {
|
|
208
|
+
code: "ambiguous time",
|
|
209
|
+
fields: {
|
|
210
|
+
civil: civilShape,
|
|
211
|
+
zone: textShape
|
|
212
|
+
}
|
|
213
|
+
}],
|
|
214
|
+
cost: costOf(costs, "toInstant"),
|
|
215
|
+
do: (call, ...args) => {
|
|
216
|
+
const second = zoneText(args[1]);
|
|
217
|
+
const isZone = args.length === 2 && second !== void 0 && !disambiguations.has(second);
|
|
218
|
+
return impl.toInstant(call, args[0], isZone ? "compatible" : second ?? "compatible", isZone ? second : zoneText(args[2]));
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
offset: {
|
|
222
|
+
mode: "immediate",
|
|
223
|
+
args: [instantShape, optionalTextShape],
|
|
224
|
+
result: secondsShape,
|
|
225
|
+
errors: unknownZone,
|
|
226
|
+
cost: costOf(costs, "offset"),
|
|
227
|
+
do: (call, value, zone) => impl.offset(call, value, zoneText(zone))
|
|
228
|
+
},
|
|
229
|
+
zone: {
|
|
230
|
+
mode: "immediate",
|
|
231
|
+
args: [optionalTextShape],
|
|
232
|
+
result: textShape,
|
|
233
|
+
errors: unknownZone,
|
|
234
|
+
cost: costOf(costs, "zone"),
|
|
235
|
+
do: (call, zone) => impl.zone(call, zoneText(zone))
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
for (const [name, op] of Object.entries(operations)) registerStandardChecks(op, {
|
|
239
|
+
error: calendarError,
|
|
240
|
+
...name === "toInstant" ? { arguments: checkToInstant } : {},
|
|
241
|
+
...[
|
|
242
|
+
"today",
|
|
243
|
+
"now",
|
|
244
|
+
"toCivil"
|
|
245
|
+
].includes(name) ? { result: (value) => !("hour" in value.asCivilDate()) === (name === "today") } : {}
|
|
246
|
+
});
|
|
247
|
+
return fixed(defineValueCapability("calendar", operations));
|
|
248
|
+
};
|
|
249
|
+
//#endregion
|
|
250
|
+
//#region src/encoding.ts
|
|
251
|
+
/** The spec's JSON string form: every U+0000..U+001F uses lowercase \u00xx. */
|
|
252
|
+
const quoteJSON = (s) => "\"" + s.replaceAll(/[\u0000-\u001f"\\]/g, (ch) => ch === "\"" ? String.raw`\"` : ch === "\\" ? "\\\\" : String.raw`\u${ch.charCodeAt(0).toString(16).padStart(4, "0")}`) + "\"";
|
|
253
|
+
const encodeValue = (value, adapter) => {
|
|
254
|
+
requireValue(value);
|
|
255
|
+
const pending = [value];
|
|
256
|
+
const output = [];
|
|
257
|
+
while (pending.length) {
|
|
258
|
+
const next = pending.pop();
|
|
259
|
+
if (typeof next === "string") {
|
|
260
|
+
output.push(next);
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
switch (next.kind) {
|
|
264
|
+
case "nothing":
|
|
265
|
+
output.push("null");
|
|
266
|
+
break;
|
|
267
|
+
case "boolean":
|
|
268
|
+
output.push(next.asBool() ? "true" : "false");
|
|
269
|
+
break;
|
|
270
|
+
case "text":
|
|
271
|
+
output.push(quoteJSON(next.asText()));
|
|
272
|
+
break;
|
|
273
|
+
case "number": {
|
|
274
|
+
const canonical = next.asDecimal().toString();
|
|
275
|
+
output.push(!canonical.includes(".") && BigInt(canonical) > -(2n ** 53n) && BigInt(canonical) < 2n ** 53n ? canonical : `{"$dec":${quoteJSON(canonical)}}`);
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
case "instant":
|
|
279
|
+
output.push(`{"$instant":${quoteJSON(next.toString())}}`);
|
|
280
|
+
break;
|
|
281
|
+
case "civil date":
|
|
282
|
+
output.push(`{"$date":${quoteJSON(next.toString())}}`);
|
|
283
|
+
break;
|
|
284
|
+
case "object": {
|
|
285
|
+
const o = next.asObjectRef();
|
|
286
|
+
output.push(`{"$object":[${quoteJSON(o.kind)},${quoteJSON(o.id)}]}`);
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
289
|
+
case "bytes":
|
|
290
|
+
output.push(`{"$bytes":${quoteJSON(toBase64(next.bytesView()))}}`);
|
|
291
|
+
break;
|
|
292
|
+
case "quantity": {
|
|
293
|
+
const q = next.asQuantity();
|
|
294
|
+
output.push(`{"$quantity":[${quoteJSON(q.number.toString())},${quoteJSON(q.unit)}]}`);
|
|
295
|
+
break;
|
|
296
|
+
}
|
|
297
|
+
case "range": {
|
|
298
|
+
const { from, to } = next.asRange();
|
|
299
|
+
output.push("{\"$range\":[");
|
|
300
|
+
pending.push("]}", to, ",", from);
|
|
301
|
+
break;
|
|
302
|
+
}
|
|
303
|
+
case "list":
|
|
304
|
+
output.push("[");
|
|
305
|
+
pending.push("]");
|
|
306
|
+
for (let i = next.length; i >= 1; i--) {
|
|
307
|
+
if (i < next.length) pending.push(",");
|
|
308
|
+
pending.push(next.index(i));
|
|
309
|
+
}
|
|
310
|
+
break;
|
|
311
|
+
case "map": {
|
|
312
|
+
const entries = next.entries();
|
|
313
|
+
const tagged = entries.some(([k]) => k.startsWith("$"));
|
|
314
|
+
output.push(tagged ? "{\"$map\":[" : "{");
|
|
315
|
+
pending.push(tagged ? "]}" : "}");
|
|
316
|
+
for (let i = entries.length - 1; i >= 0; i--) {
|
|
317
|
+
const [k, v] = entries[i];
|
|
318
|
+
if (i < entries.length - 1) pending.push(",");
|
|
319
|
+
if (tagged) pending.push("]", v, `[${quoteJSON(k)},`);
|
|
320
|
+
else pending.push(v, `${quoteJSON(k)}:`);
|
|
321
|
+
}
|
|
322
|
+
break;
|
|
323
|
+
}
|
|
324
|
+
case "function":
|
|
325
|
+
case "pattern":
|
|
326
|
+
if (adapter) {
|
|
327
|
+
output.push(adapter(next));
|
|
328
|
+
break;
|
|
329
|
+
}
|
|
330
|
+
invalidValue(`The Value Encoding of a ${next.kind} isn't implemented yet`);
|
|
331
|
+
break;
|
|
332
|
+
default: invalidValue(`The Value Encoding of a ${next.kind} isn't implemented yet`);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
return output.join("");
|
|
336
|
+
};
|
|
337
|
+
//#endregion
|
|
338
|
+
export { clockCapability as a, fixed as c, timerCapability as d, registerStandardChecks as f, calendarCapability as i, isMusicalClock as l, quoteJSON as n, consoleCapability as o, standardChecks as p, MUSICAL_CLOCK as r, costOf as s, encodeValue as t, musicalClockCapability as u };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference lib="esnext.disposable" />
|
|
2
|
-
import { Dt as EffectResult, J as Value, Mt as GrantContext, Ut as SegmentContext, bt as Call,
|
|
3
|
-
import { i as WatchLimits, n as RouterOptions, t as NotificationRouter } from "./router-
|
|
2
|
+
import { Dt as EffectResult, J as Value, Mt as GrantContext, Ut as SegmentContext, bt as Call, fn as StoreImpl } from "./debug-C_Ob5rkl.js";
|
|
3
|
+
import { i as WatchLimits, n as RouterOptions, t as NotificationRouter } from "./router-D0rf5SkW.js";
|
|
4
4
|
//#region src/store/engine.d.ts
|
|
5
5
|
/** A Store's limits, each counted by logical size (chapter 8). */
|
|
6
6
|
type StoreQuotas = {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
|
|
2
|
-
import { A as listValues, L as nothing,
|
|
3
|
-
import {
|
|
4
|
-
import { i as decodeValueMembers } from "./readers-
|
|
5
|
-
import { n as quoteJSON, t as encodeValue } from "./encoding-
|
|
6
|
-
import { n as hostScriptError, t as add } from "./store-capability-
|
|
7
|
-
import { n as createRouter, t as changed } from "./router-
|
|
2
|
+
import { A as listValues, L as nothing, et as text, o as invalidValue, v as dec } from "./errors-P3ga1I-9.js";
|
|
3
|
+
import { Q as sizeOf, ut as compareText } from "./operations-CGjDlkGU.js";
|
|
4
|
+
import { i as decodeValueMembers } from "./readers-yMS1eAOp.js";
|
|
5
|
+
import { n as quoteJSON, t as encodeValue } from "./encoding-BL2ECJmg.js";
|
|
6
|
+
import { n as hostScriptError, t as add } from "./store-capability-DBLlWaNO.js";
|
|
7
|
+
import { n as createRouter, t as changed } from "./router-Bm7A2kjt.js";
|
|
8
8
|
//#region src/store/engine.ts
|
|
9
9
|
/** The Session Store's quotas (chapter 12, The Session Store). */
|
|
10
10
|
const sessionQuotas = Object.freeze({
|
|
@@ -56,12 +56,8 @@ const grammar = {
|
|
|
56
56
|
"true"
|
|
57
57
|
],
|
|
58
58
|
"labels": {
|
|
59
|
-
"reserved": ["to"],
|
|
60
|
-
"excluded": [
|
|
61
|
-
"from",
|
|
62
|
-
"otherwise",
|
|
63
|
-
"with"
|
|
64
|
-
]
|
|
59
|
+
"reserved": ["on", "to"],
|
|
60
|
+
"excluded": ["from", "otherwise"]
|
|
65
61
|
},
|
|
66
62
|
"chunk": [
|
|
67
63
|
{
|
|
@@ -164,6 +160,8 @@ const grammar = {
|
|
|
164
160
|
"ordering-words",
|
|
165
161
|
"pattern-anchor",
|
|
166
162
|
"replace-first",
|
|
163
|
+
"repeat-with",
|
|
164
|
+
"shape-of",
|
|
167
165
|
"script-variable",
|
|
168
166
|
"target",
|
|
169
167
|
"wait-from",
|
|
@@ -381,6 +379,53 @@ const units = [
|
|
|
381
379
|
"calendar": false,
|
|
382
380
|
"factor": ["5", "9"]
|
|
383
381
|
},
|
|
382
|
+
{
|
|
383
|
+
"name": "Hz",
|
|
384
|
+
"kind": "frequency",
|
|
385
|
+
"calendar": false,
|
|
386
|
+
"factor": ["1", "1"]
|
|
387
|
+
},
|
|
388
|
+
{
|
|
389
|
+
"name": "kHz",
|
|
390
|
+
"kind": "frequency",
|
|
391
|
+
"calendar": false,
|
|
392
|
+
"factor": ["1000", "1"]
|
|
393
|
+
},
|
|
394
|
+
{
|
|
395
|
+
"name": "cent",
|
|
396
|
+
"plural": "cents",
|
|
397
|
+
"kind": "pitch interval",
|
|
398
|
+
"calendar": false,
|
|
399
|
+
"factor": ["1", "1"]
|
|
400
|
+
},
|
|
401
|
+
{
|
|
402
|
+
"name": "semitone",
|
|
403
|
+
"plural": "semitones",
|
|
404
|
+
"kind": "pitch interval",
|
|
405
|
+
"calendar": false,
|
|
406
|
+
"factor": ["100", "1"]
|
|
407
|
+
},
|
|
408
|
+
{
|
|
409
|
+
"name": "octave",
|
|
410
|
+
"plural": "octaves",
|
|
411
|
+
"kind": "pitch interval",
|
|
412
|
+
"calendar": false,
|
|
413
|
+
"factor": ["1200", "1"]
|
|
414
|
+
},
|
|
415
|
+
{
|
|
416
|
+
"name": "bar",
|
|
417
|
+
"plural": "bars",
|
|
418
|
+
"kind": "bar",
|
|
419
|
+
"calendar": false,
|
|
420
|
+
"factor": ["1", "1"]
|
|
421
|
+
},
|
|
422
|
+
{
|
|
423
|
+
"name": "beat",
|
|
424
|
+
"plural": "beats",
|
|
425
|
+
"kind": "beat",
|
|
426
|
+
"calendar": false,
|
|
427
|
+
"factor": ["1", "1"]
|
|
428
|
+
},
|
|
384
429
|
{
|
|
385
430
|
"name": "USD",
|
|
386
431
|
"kind": "USD",
|
|
@@ -449,6 +494,10 @@ const unitKinds = [
|
|
|
449
494
|
"exact duration",
|
|
450
495
|
"calendar duration",
|
|
451
496
|
"temperature difference",
|
|
497
|
+
"frequency",
|
|
498
|
+
"pitch interval",
|
|
499
|
+
"bar",
|
|
500
|
+
"beat",
|
|
452
501
|
"USD",
|
|
453
502
|
"EUR",
|
|
454
503
|
"GBP",
|
|
@@ -491,6 +540,28 @@ const unitKindTable = [
|
|
|
491
540
|
"dimension": "temperature",
|
|
492
541
|
"factor": "1"
|
|
493
542
|
},
|
|
543
|
+
{
|
|
544
|
+
"name": "frequency",
|
|
545
|
+
"dimension": "time^-1",
|
|
546
|
+
"factor": "1"
|
|
547
|
+
},
|
|
548
|
+
{
|
|
549
|
+
"name": "pitch interval",
|
|
550
|
+
"dimension": "pitch",
|
|
551
|
+
"factor": "1"
|
|
552
|
+
},
|
|
553
|
+
{
|
|
554
|
+
"name": "bar",
|
|
555
|
+
"dimension": "bar",
|
|
556
|
+
"factor": "1",
|
|
557
|
+
"musical": true
|
|
558
|
+
},
|
|
559
|
+
{
|
|
560
|
+
"name": "beat",
|
|
561
|
+
"dimension": "beat",
|
|
562
|
+
"factor": "1",
|
|
563
|
+
"musical": true
|
|
564
|
+
},
|
|
494
565
|
{
|
|
495
566
|
"name": "USD",
|
|
496
567
|
"dimension": "USD",
|
|
@@ -552,6 +623,7 @@ const diagnosticCodes = [
|
|
|
552
623
|
"leaves recovery catch",
|
|
553
624
|
"duplicate key",
|
|
554
625
|
"unknown kind",
|
|
626
|
+
"bad shape",
|
|
555
627
|
"no conversion",
|
|
556
628
|
"bad number",
|
|
557
629
|
"pattern too large",
|
|
@@ -580,6 +652,7 @@ const diagnosticCodes = [
|
|
|
580
652
|
"veto outside a decision",
|
|
581
653
|
"after a suspension",
|
|
582
654
|
"wrong message",
|
|
655
|
+
"negated shape",
|
|
583
656
|
"bad suffixes",
|
|
584
657
|
"can't write",
|
|
585
658
|
"not a property",
|
|
@@ -3123,12 +3196,14 @@ const ownUnit = (spec) => {
|
|
|
3123
3196
|
var UnitError = class extends Error {
|
|
3124
3197
|
name = "UnitError";
|
|
3125
3198
|
};
|
|
3199
|
+
const musicalKinds = new Set(unitKindTable.flatMap((k) => "musical" in k && k.musical ? [k.name] : []));
|
|
3126
3200
|
const entries = /* @__PURE__ */ new Map();
|
|
3127
3201
|
for (const u of units) {
|
|
3128
3202
|
const entry = {
|
|
3129
3203
|
name: u.name,
|
|
3130
3204
|
kind: u.kind,
|
|
3131
3205
|
calendar: u.calendar,
|
|
3206
|
+
musical: musicalKinds.has(u.kind),
|
|
3132
3207
|
factor: [parseDec(u.factor[0]), parseDec(u.factor[1])],
|
|
3133
3208
|
..."plural" in u && u.plural ? { plural: u.plural } : {}
|
|
3134
3209
|
};
|
|
@@ -3153,6 +3228,7 @@ const parseUnit = (text) => {
|
|
|
3153
3228
|
let sign = text.startsWith("1/") ? -1 : 1;
|
|
3154
3229
|
const slots = [];
|
|
3155
3230
|
let calendar = false;
|
|
3231
|
+
let musical = false;
|
|
3156
3232
|
const parts = body.split(/([*/])/);
|
|
3157
3233
|
let slashes = sign < 0 ? 1 : 0;
|
|
3158
3234
|
for (let i = 0; i < parts.length; i += 2) {
|
|
@@ -3172,10 +3248,13 @@ const parseUnit = (text) => {
|
|
|
3172
3248
|
unit: entry.name,
|
|
3173
3249
|
exponent
|
|
3174
3250
|
});
|
|
3175
|
-
|
|
3251
|
+
const compound = parts.length > 1 || power !== void 0 || sign < 0;
|
|
3252
|
+
calendar ||= entry.calendar && compound;
|
|
3253
|
+
musical ||= entry.musical && compound;
|
|
3176
3254
|
}
|
|
3177
3255
|
if (slashes > 1) throw new UnitError("a Compound Unit has at most one `/`");
|
|
3178
3256
|
if (calendar) throw new UnitError("a Calendar Unit can't be part of a Compound Unit");
|
|
3257
|
+
if (musical) throw new UnitError("a Musical Unit can't be part of a Compound Unit");
|
|
3179
3258
|
return ownUnit(ordered(slots));
|
|
3180
3259
|
};
|
|
3181
3260
|
const ordered = (slots) => slots.filter((slot) => slot.exponent !== 0).sort((a, b) => kindOrder.get(entryOf(a).kind) - kindOrder.get(entryOf(b).kind));
|
|
@@ -3275,10 +3354,18 @@ const fromBase = (value, spec) => {
|
|
|
3275
3354
|
return v;
|
|
3276
3355
|
};
|
|
3277
3356
|
const checkCalendar = (spec) => {
|
|
3278
|
-
const
|
|
3279
|
-
|
|
3357
|
+
const alone = spec.find((slot) => {
|
|
3358
|
+
const entry = entryOf(slot);
|
|
3359
|
+
return entry.calendar || entry.musical;
|
|
3360
|
+
});
|
|
3361
|
+
if (alone && (spec.length > 1 || alone.exponent !== 1)) throw new UnitError(entryOf(alone).calendar ? "a Calendar Unit stands alone" : "a Musical Unit stands alone");
|
|
3280
3362
|
return spec;
|
|
3281
3363
|
};
|
|
3364
|
+
/** The Musical Unit Kind a Unit is in, `bar` or `beat`, if it is one (ADR 0166). */
|
|
3365
|
+
const musicalKind = (spec) => {
|
|
3366
|
+
const entry = spec.length === 1 ? entryOf(spec[0]) : void 0;
|
|
3367
|
+
return entry?.musical && spec[0].exponent === 1 ? entry.kind : void 0;
|
|
3368
|
+
};
|
|
3282
3369
|
/**
|
|
3283
3370
|
* The Unit of `a * b` or `a / b` (chapter 3, Quantity arithmetic): the left
|
|
3284
3371
|
* operand's, with each of the right operand's slots converted into the
|
|
@@ -3350,6 +3437,13 @@ let decimalParts;
|
|
|
3350
3437
|
* written with exponent 0, or NaN. The fast paths compute on it directly.
|
|
3351
3438
|
*/
|
|
3352
3439
|
let smallInteger;
|
|
3440
|
+
/**
|
|
3441
|
+
* Internal: a Decimal's coefficient as a signed JS number when it is a safe
|
|
3442
|
+
* integer, or NaN; `smallExponent` is then its exponent. The fast paths
|
|
3443
|
+
* compute on the pair directly.
|
|
3444
|
+
*/
|
|
3445
|
+
let smallCoefficient;
|
|
3446
|
+
let smallExponent;
|
|
3353
3447
|
let isDecimal;
|
|
3354
3448
|
/** Internal: owned Map pairs. Never pass these arrays to a Host. */
|
|
3355
3449
|
let ownedMapPairs;
|
|
@@ -3360,26 +3454,30 @@ var Decimal = class Decimal {
|
|
|
3360
3454
|
#canonical;
|
|
3361
3455
|
#parts;
|
|
3362
3456
|
#small;
|
|
3363
|
-
|
|
3457
|
+
#exponent;
|
|
3458
|
+
constructor(token, canonical, parts, small, exponent) {
|
|
3364
3459
|
if (token !== decimalToken) invalidValue("Use a numeric constructor");
|
|
3365
3460
|
this.#canonical = canonical;
|
|
3366
3461
|
this.#parts = parts && frozenParts(parts);
|
|
3367
3462
|
this.#small = small;
|
|
3463
|
+
this.#exponent = exponent;
|
|
3368
3464
|
Object.preventExtensions(this);
|
|
3369
3465
|
}
|
|
3370
3466
|
static {
|
|
3371
3467
|
isDecimal = (input) => typeof input === "object" && input !== null && #small in input;
|
|
3372
|
-
makeDecimal = (canonical, parts) => new Decimal(decimalToken, canonical, parts, parts.
|
|
3373
|
-
makeSmallDecimal = (n) => new Decimal(decimalToken, void 0, void 0, n);
|
|
3468
|
+
makeDecimal = (canonical, parts) => new Decimal(decimalToken, canonical, parts, parts.coefficient <= SAFE ? Number(parts.coefficient) * (parts.negative ? -1 : 1) + 0 : NaN, parts.exponent);
|
|
3469
|
+
makeSmallDecimal = (n, exponent) => new Decimal(decimalToken, void 0, void 0, n, exponent);
|
|
3374
3470
|
decimalParts = (decimal) => decimal.#parts ??= frozenParts({
|
|
3375
3471
|
coefficient: BigInt(Math.abs(decimal.#small)),
|
|
3376
|
-
exponent:
|
|
3472
|
+
exponent: decimal.#exponent,
|
|
3377
3473
|
negative: decimal.#small < 0
|
|
3378
3474
|
});
|
|
3379
|
-
smallInteger = (decimal) => decimal.#small;
|
|
3475
|
+
smallInteger = (decimal) => decimal.#exponent === 0 ? decimal.#small : NaN;
|
|
3476
|
+
smallCoefficient = (decimal) => decimal.#small;
|
|
3477
|
+
smallExponent = (decimal) => decimal.#exponent;
|
|
3380
3478
|
}
|
|
3381
3479
|
toString() {
|
|
3382
|
-
return this.#canonical ??= this.#parts ? formatDec(this
|
|
3480
|
+
return this.#canonical ??= this.#parts || this.#exponent !== 0 ? formatDec(decimalParts(this)) : String(this.#small);
|
|
3383
3481
|
}
|
|
3384
3482
|
toBigInt() {
|
|
3385
3483
|
const parts = decimalParts(this);
|
|
@@ -3799,9 +3897,11 @@ const dec = (s) => {
|
|
|
3799
3897
|
negative: negative && !zero
|
|
3800
3898
|
}));
|
|
3801
3899
|
};
|
|
3802
|
-
/**
|
|
3803
|
-
|
|
3804
|
-
|
|
3900
|
+
/**
|
|
3901
|
+
* A safe-integer coefficient and an exponent within chapter 3's limits
|
|
3902
|
+
* (-6176 to 0) as a number Value, without BigInt or text work.
|
|
3903
|
+
*/
|
|
3904
|
+
const smallDecimalNumber = (n, exponent) => makeValue("number", makeSmallDecimal(n + 0, exponent));
|
|
3805
3905
|
const canonicalNumber = (parts) => makeValue("number", makeDecimal(void 0, parts));
|
|
3806
3906
|
/** ECMAScript's shortest round-trip digits, expanded without rounding. */
|
|
3807
3907
|
const num = (n) => {
|
|
@@ -4136,8 +4236,11 @@ var ScriptError = class extends Error {
|
|
|
4136
4236
|
this.reason = code === "send failed" ? data.get("reason").asText() : void 0;
|
|
4137
4237
|
}
|
|
4138
4238
|
};
|
|
4139
|
-
/**
|
|
4140
|
-
|
|
4239
|
+
/**
|
|
4240
|
+
* The rejection of a Request whose receiver's Run ended without answering.
|
|
4241
|
+
* An `errored` Run's error map rides as `error` (chapter 6).
|
|
4242
|
+
*/
|
|
4243
|
+
const sendFailed = (reason, error) => new ScriptError("send failed", `No answer came: the receiver's Run ended ${reason}`, map([["reason", text(reason)], ...error ? [["error", error]] : []]));
|
|
4141
4244
|
const hostDetail = (error) => error instanceof Error ? `${error.name}: ${error.message}` : `the Host threw ${typeof error === "symbol" ? error.toString() : String(error)}`;
|
|
4142
4245
|
//#endregion
|
|
4143
|
-
export {
|
|
4246
|
+
export { sourceForm as $, charactersAt as $t, listValues as A, subtract as At, ownedMapPairs as B, civilOfUs as Bt, functionsBelongTo as C, integerOf as Ct, isDecimal as D, negate as Dt, instantOf as E, multiply as Et, mapOfLayout as F, addMonths as Ft, record as G, isoWeek as Gt, quantity as H, dayOfYear as Ht, mapWithEntry as I, checkInstant as It, sliceText as J, parseInstant as Jt, requireArgs as K, nowMicros as Kt, nothing as L, civilDays as Lt, literalDigits as M, DateRangeError as Mt, map as N, US_PER_DAY as Nt, isReadable as O, powerInteger as Ot, mapLayout as P, US_PER_SECOND as Pt, smallInteger as Q, characterBoundaries as Qt, num as R, civilFromFields as Rt, functionValue as S, formatDec as St, instant as T, mod as Tt, quantityOf as U, formatInstant as Ut, patternValue as V, civilUs as Vt, range as W, isInstant as Wt, smallDecimalNumber as X, weekday as Xt, smallCoefficient as Y, parseInstantText as Yt, smallExponent as Z, assertScalarText as Zt, concatText as _, decOf as _t, hostDetail as a, simpleFold as an, fromBase as at, displayText as b, div as bt, Decimal as c, builtins as cn, parseUnit as ct, bytes as d, libraryExports as dn, toBase as dt, generalCategory as en, text as et, bytesOf as f, unitKinds as fn, unitEntry as ft, compareBytes as g, compareDec as gt, civilOf as h, add as ht, ScriptError as i, scalarCount as in, combine as it, listWithItem as j, withinLimits as jt, list as k, roundRatio as kt, Value as l, diagnosticCodes as ln, powerOf as lt, civilDate as m, ArithmeticError as mt, LoadError as n, lower as nn, trimWhiteSpace as nt, invalidValue as o, upper as on, musicalKind as ot, canonicalNumber as p, units as pn, unitText as pt, requireValue as q, parseCivil as qt, MailboxFull as r, normalizeNFC as rn, UnitError as rt, sendFailed as s, unicodeVersion as sn, ownUnit as st, HostError as t, isWhiteSpace as tn, textStorage as tt, bool as u, grammar as un, sameDimension as ut, dec as v, digitCount as vt, hiddenCodePoint as w, isInteger as wt, extendList as x, divide as xt, decimalParts as y, digitsOf as yt, objectValue as z, civilOfDays as zt };
|