@northtalk/ts 0.3.0 → 0.5.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.
Files changed (52) hide show
  1. package/README.md +1 -1
  2. package/{base64-DA7UgjG2.js → base64-Dtqaz_0A.js} +3 -3
  3. package/{binary-value-BcHcwVLO.d.ts → binary-value-B3knLdHD.d.ts} +1 -1
  4. package/{capabilities-BCw9uREe.js → capabilities-Bi5Qm6Fr.js} +10 -1
  5. package/{checker-Dmnm2SeU.js → checker-DMI4LiRm.js} +13 -5
  6. package/core-D_9OuTRE.d.ts +22 -0
  7. package/{debug-CY9x_Wsi.d.ts → debug-nN5tQ_p4.d.ts} +479 -45
  8. package/debug.d.ts +2 -2
  9. package/debug.js +1 -1
  10. package/{driver-CwmL5M32.d.ts → driver-Bf-7Roq6.d.ts} +1 -1
  11. package/driver.d.ts +1 -1
  12. package/driver.js +1 -1
  13. package/{encoding-BUhsrLPK.js → encoding-C3Q7pIC9.js} +2 -2
  14. package/{engine-Dj9My1qX.js → engine-BpdGfAND.js} +6 -6
  15. package/{engine-CCzaBIoi.d.ts → engine-CQqt4rTB.d.ts} +2 -2
  16. package/{errors-CPPJmAAh.js → errors-BKJES3Zu.js} +1 -1
  17. package/{group-CnpvKoLw.js → group-Bz2wh72R.js} +5917 -1391
  18. package/http.d.ts +1 -1
  19. package/http.js +3 -3
  20. package/index.d.ts +10 -6
  21. package/index.js +16 -15
  22. package/{inline-grants-Bvk-2aUL.js → inline-grants-Cx0Z9XAt.js} +25 -20
  23. package/{manifest-CeavwKxo.d.ts → manifest-DYAbIyQm.d.ts} +2 -2
  24. package/{manifest-BTwN3NiP.js → manifest-Dw-8Unmf.js} +124 -5
  25. package/message-layer.d.ts +2 -2
  26. package/message-layer.js +2 -2
  27. package/notify.d.ts +1 -1
  28. package/notify.js +1 -1
  29. package/{objects-CawjPfhl.js → objects-BC4fS0vq.js} +1 -1
  30. package/{objects-BdWn56Ia.d.ts → objects-BRcpeXwZ.d.ts} +11 -3
  31. package/package.json +1 -1
  32. package/{readers-C2YMRjC3.js → readers-B5e5bBrY.js} +2 -2
  33. package/{readers-DMCXzY3X.d.ts → readers-L90Hoa97.d.ts} +1 -1
  34. package/{request-pump-binary-Cp3RGZIJ.js → request-pump-binary-BjnyqXV5.js} +4 -4
  35. package/{router-BSREiSux.js → router-BCHEfs4x.js} +5 -5
  36. package/{router-BE5Tbbd7.d.ts → router-CBuMIl6i.d.ts} +2 -2
  37. package/session.d.ts +40 -2
  38. package/session.js +109 -27
  39. package/setup.d.ts +1 -1
  40. package/setup.js +4 -4
  41. package/sha256-9CGf5BS_.js +168 -0
  42. package/sqlite.d.ts +4 -4
  43. package/sqlite.js +26 -20
  44. package/{store-DwESnByX.js → store-DTQa0lyE.js} +2 -2
  45. package/{store-capability-BYghoYSd.js → store-capability-BxXgiRM7.js} +4 -4
  46. package/store.d.ts +2 -2
  47. package/store.js +2 -2
  48. package/{user-capability-kDFbi3sm.js → user-capability-5-IvCeZI.js} +5 -5
  49. package/wasm.d.ts +10 -6
  50. package/wasm.js +51 -27
  51. package/core-D902b5Nu.d.ts +0 -14
  52. package/sha256-B_kyYw3Z.js +0 -124
package/session.js CHANGED
@@ -1,18 +1,18 @@
1
1
 
2
- import { A as listValues, Gt as formatInstant, L as nothing, N as map, Q as text, R as num, W as range, Xt as parseInstant, dt as builtins, en as characterBoundaries, i as ScriptError, in as lower, l as Value, n as LoadError, t as HostError, u as bool } from "./errors-CPPJmAAh.js";
3
- import { o as stateOf, t as defineObjectKind } from "./objects-CawjPfhl.js";
4
- import { a as defineValueCapability, m as validStaticMessageName, u as shape } from "./capabilities-BCw9uREe.js";
5
- import { c as parseSource, g as leadingDoc, h as functionDoc, p as declarationDocs, s as parseEntry, t as checkSource, v as viewSource } from "./checker-Dmnm2SeU.js";
6
- import { C as integerValue, H as textForm$1, U as waitUs, tt as functionHead, ut as compareText } from "./base64-DA7UgjG2.js";
7
- import { a as recordLine, c as compileLibrary, h as defaultLimits, i as restore, o as traceValue, u as stdlibSources } from "./group-CnpvKoLw.js";
8
- import { c as readDisplay, l as readOrderedJSON, r as decodeValue } from "./readers-C2YMRjC3.js";
9
- import { n as quoteJSON, t as encodeValue } from "./encoding-BUhsrLPK.js";
10
- import { a as shapeData, n as exportManifest, t as canonicalJSON } from "./manifest-BTwN3NiP.js";
11
- import { n as localeCapability, t as userCapability } from "./user-capability-kDFbi3sm.js";
12
- import { a as clockCapability, i as calendarCapability, o as consoleCapability, r as storeCapability } from "./store-capability-BYghoYSd.js";
2
+ import { A as listValues, Kt as formatInstant, L as nothing, N as map, Q as text, R as num, W as range, Zt as parseInstant, an as lower, dt as builtins, i as ScriptError, l as Value, n as LoadError, t as HostError, tn as characterBoundaries, u as bool } from "./errors-BKJES3Zu.js";
3
+ import { o as stateOf, t as defineObjectKind } from "./objects-BC4fS0vq.js";
4
+ import { a as defineValueCapability, m as validStaticMessageName, u as shape } from "./capabilities-Bi5Qm6Fr.js";
5
+ import { _ as viewSource, c as parseSource, f as declarationDocs, h as leadingDoc, m as functionDoc, s as parseEntry, t as checkSource } from "./checker-DMI4LiRm.js";
6
+ import { C as integerValue, U as textForm$1, W as waitUs, dt as compareText, nt as functionHead } from "./base64-Dtqaz_0A.js";
7
+ import { a as recordLine, d as stdlibSources, g as defaultLimits, i as restore, l as compileLibrary, o as traceValue } from "./group-Bz2wh72R.js";
8
+ import { n as exportManifest, o as shapeData, t as canonicalJSON } from "./manifest-Dw-8Unmf.js";
9
+ import { c as readDisplay, l as readOrderedJSON, r as decodeValue } from "./readers-B5e5bBrY.js";
10
+ import { n as quoteJSON, t as encodeValue } from "./encoding-C3Q7pIC9.js";
11
+ import { n as localeCapability, t as userCapability } from "./user-capability-5-IvCeZI.js";
12
+ import { a as clockCapability, i as calendarCapability, o as consoleCapability, r as storeCapability } from "./store-capability-BxXgiRM7.js";
13
13
  import { buildSetupGroup, capabilityOperations, immutableSetup, operationDeclarations, shapeOf } from "./setup.js";
14
- import { a as encodeContents, i as decodeContents, o as sessionQuotas, t as StoreContentsError } from "./engine-Dj9My1qX.js";
15
- import { i as memoryStores } from "./store-DwESnByX.js";
14
+ import { a as encodeContents, i as decodeContents, o as sessionQuotas, t as StoreContentsError } from "./engine-BpdGfAND.js";
15
+ import { i as memoryStores } from "./store-DTQa0lyE.js";
16
16
  //#region src/session/objects.ts
17
17
  const externalCollection = () => {
18
18
  throw new Error("external collection callback in replay");
@@ -1230,7 +1230,7 @@ const cost = (c) => declarationValue({
1230
1230
  fuel: c?.fuel ?? 0,
1231
1231
  alloc: c?.alloc ?? 0
1232
1232
  });
1233
- const valueRows = (value) => {
1233
+ const valueRows = (value, unitDocs) => {
1234
1234
  const out = [`value ${map([["kind", text(value.kind)], ["value", value]])}`];
1235
1235
  const size = value.kind === "text" ? characterBoundaries(value.asText()).length - 1 : value.kind === "bytes" ? value.asBytes().length : value.kind === "list" ? value.length : value.kind === "map" ? value.entries().length : null;
1236
1236
  if (size !== null) out.push(`size ${size}`);
@@ -1242,7 +1242,7 @@ const valueRows = (value) => {
1242
1242
  ["name", head?.name == null ? nothing : text(head.name)],
1243
1243
  ["arity", head ? range(integerValue(BigInt(head.min)), integerValue(BigInt(head.max))) : nothing],
1244
1244
  ["home", text(fn.home)]
1245
- ])}`, `doc ${text(functionDoc(value) ?? "")}`);
1245
+ ])}`, `doc ${text(functionDoc(value, unitDocs) ?? "")}`);
1246
1246
  }
1247
1247
  if (value.kind === "object") {
1248
1248
  const state = stateOf(value);
@@ -1383,7 +1383,7 @@ const describeTarget = (names, rest) => {
1383
1383
  };
1384
1384
  };
1385
1385
  /** `:describe <target>`'s rows. */
1386
- const describe$1 = (names, rest) => {
1386
+ const describe = (names, rest) => {
1387
1387
  const { plain, target } = describeTarget(names, rest);
1388
1388
  let found = [];
1389
1389
  if (target.origin === "session") {
@@ -1402,7 +1402,7 @@ const describe$1 = (names, rest) => {
1402
1402
  if (d.arity) out.push(`arity ${d.arity[0]}..${d.arity[1]}`);
1403
1403
  if (d.variable !== void 0) {
1404
1404
  const value = names.variable(d.variable);
1405
- if (value) out.push(...valueRows(value));
1405
+ if (value) out.push(...valueRows(value, names.unitDocs));
1406
1406
  }
1407
1407
  }
1408
1408
  return out;
@@ -1478,6 +1478,52 @@ const apropos = (names, rest) => {
1478
1478
  }
1479
1479
  return out;
1480
1480
  };
1481
+ /**
1482
+ * The Names of one whole Script, for a host without a Session Host: each
1483
+ * declaration of `source` in order, with the comments before it, and the
1484
+ * given User Libraries. No Script Variable has a value to show.
1485
+ */
1486
+ const scriptNames = (source, libraries, refuse) => {
1487
+ const declarations = [];
1488
+ const tree = parseSource(source).tree;
1489
+ const checked = checkSource(source).tree;
1490
+ if (tree && checked) {
1491
+ const nodes = tree.children.filter((c) => c.kind === "node" && c.rule === "Declaration");
1492
+ let from = 0;
1493
+ viewSource(checked.root).forEach((decl, at) => {
1494
+ const node = nodes[at];
1495
+ const own = source.slice(from, node.end).replace(/^\s+/u, "");
1496
+ from = node.end;
1497
+ if (decl.k === "use") {
1498
+ const uses = decl.imports.map((i) => ({
1499
+ local: i.local.text,
1500
+ name: i.name
1501
+ }));
1502
+ declarations.push({
1503
+ kind: "use",
1504
+ library: decl.library,
1505
+ names: uses.map((u) => u.local),
1506
+ uses,
1507
+ source: own
1508
+ });
1509
+ } else {
1510
+ const name = decl.k === "constant" || decl.k === "variable" ? decl.name.text : decl.name;
1511
+ declarations.push({
1512
+ kind: decl.k,
1513
+ names: [name],
1514
+ source: own
1515
+ });
1516
+ }
1517
+ });
1518
+ }
1519
+ return {
1520
+ declarations,
1521
+ has: (name) => declarations.some((d) => d.names.includes(name)),
1522
+ libraries,
1523
+ refuse,
1524
+ variable: () => void 0
1525
+ };
1526
+ };
1481
1527
  //#endregion
1482
1528
  //#region src/generated/session.ts
1483
1529
  const inspectReader = "on entry0 entry0Object to entry0Names\n repeat for each entry0Name in entry0Names\n try\n put {name: entry0Name, value: the (entry0Name) of entry0Object} into entry0Row\n catch entry0Error\n put {} into entry0Clean\n repeat for each entry0Key in the keys of entry0Error\n if entry0Key is not in [\"message\", \"at\"] then\n put the (entry0Key) of entry0Error into the (entry0Key) of entry0Clean\n end if\n end repeat\n put {name: entry0Name, error: entry0Clean} into entry0Row\n end try\n say \"read \" & entry0Row\n end repeat\nend entry0\n";
@@ -1639,8 +1685,10 @@ const hostFailure = (error) => new ScriptError(error.get("code").asText() ?? "",
1639
1685
  const stubLine = (operation, stub) => recordLine("stub", [operation], [
1640
1686
  ["value", stub.value ? traceValue(stub.value) : null],
1641
1687
  ["error", stub.error ? traceValue(stub.error) : null],
1642
- ["charge", stub.charge ? String(stub.charge) : null]
1688
+ ["charge", stub.charge ? String(stub.charge) : null],
1689
+ ["charge-refused", stub.refused ? "yes" : null]
1643
1690
  ], true);
1691
+ const refuse$1 = (call) => call.charge(Number.MAX_SAFE_INTEGER);
1644
1692
  /** The Stubs queued for each Operation, named `<capability>.<operation>`. */
1645
1693
  var Stubs = class Stubs {
1646
1694
  queues = /* @__PURE__ */ new Map();
@@ -1677,6 +1725,7 @@ var Stubs = class Stubs {
1677
1725
  return nothing;
1678
1726
  }
1679
1727
  if (stub.charge) call.charge(stub.charge);
1728
+ if (stub.refused) refuse$1(call);
1680
1729
  if (stub.malformed) return null;
1681
1730
  if (stub.error) {
1682
1731
  if (!stub.error.entries().length) throw new Error(`The Stub for ${operation} fails`);
@@ -1689,6 +1738,7 @@ var Stubs = class Stubs {
1689
1738
  const queued = this.queues.get(operation)?.shift();
1690
1739
  const stub = queued ?? recorded;
1691
1740
  if (stub?.charge) call.charge(stub.charge);
1741
+ if (stub?.refused) refuse$1(call);
1692
1742
  if (stub?.error) {
1693
1743
  if (!stub.error.entries().length) throw new Error(queued ? `The Stub for ${operation} fails` : `The recorded call of ${operation} fails`);
1694
1744
  throw hostFailure(stub.error);
@@ -1989,6 +2039,7 @@ var SessionHost = class {
1989
2039
  declarations: this.declarations,
1990
2040
  has: (name) => this.has(name),
1991
2041
  refuse,
2042
+ unitDocs: this.unitDocs,
1992
2043
  libraries: new Map([...this.libraries].map(([name, l]) => [name, l.library.source])),
1993
2044
  variable: (name) => this.inspect().scripts.find((s) => s.name === NAME).vars.find(([n]) => n === name)?.[1]
1994
2045
  };
@@ -1999,7 +2050,15 @@ var SessionHost = class {
1999
2050
  * means the value is not a Function Value.
2000
2051
  */
2001
2052
  functionDocumentation(value) {
2002
- return functionDoc(value);
2053
+ return functionDoc(value, this.unitDocs);
2054
+ }
2055
+ /**
2056
+ * Each defining-source version's Declaration Documentation, by unit
2057
+ * identity, kept before code changes can discard it (chapter 9).
2058
+ */
2059
+ unitDocs = /* @__PURE__ */ new Map();
2060
+ retainDocs() {
2061
+ for (const [unit, docs] of this.group?.scriptUnitDocs(NAME) ?? []) if (docs.size && !this.unitDocs.has(unit)) this.unitDocs.set(unit, docs);
2003
2062
  }
2004
2063
  /**
2005
2064
  * An Entry or a Session Command. Returns the lines it printed. At a
@@ -2018,6 +2077,7 @@ var SessionHost = class {
2018
2077
  this.callStart = this.recordedItems.length;
2019
2078
  this.recording = source.replace(/\n+$/, "");
2020
2079
  const out = this.entry(source);
2080
+ this.retainDocs();
2021
2081
  this.recorded();
2022
2082
  return this.finished(out);
2023
2083
  }
@@ -2271,6 +2331,7 @@ var SessionHost = class {
2271
2331
  ...base,
2272
2332
  mode,
2273
2333
  result: shapeOf(spec.result),
2334
+ ...spec.metering ? { metering: "read-only" } : {},
2274
2335
  start: (call, ...args) => {
2275
2336
  this.mockCalls.set(call.id, {
2276
2337
  operation: key,
@@ -2302,7 +2363,10 @@ var SessionHost = class {
2302
2363
  const w = rest.trim().split(/\s+/u).filter(Boolean);
2303
2364
  return this.grant(w.length === 3 ? w : words(rest, 2));
2304
2365
  }
2305
- case "mock": return this.mock(words(rest, 2));
2366
+ case "mock": {
2367
+ const w = rest.trim().split(/\s+/u).filter(Boolean);
2368
+ return this.mock(w.length === 3 ? w : words(rest, 2));
2369
+ }
2306
2370
  case "stub":
2307
2371
  this.start();
2308
2372
  return this.stub(rest);
@@ -2310,6 +2374,9 @@ var SessionHost = class {
2310
2374
  case "fail":
2311
2375
  this.start();
2312
2376
  return this.settle(name, rest);
2377
+ case "charge":
2378
+ this.start();
2379
+ return this.charge(words(rest, 2));
2313
2380
  case "clock":
2314
2381
  this.start();
2315
2382
  return this.clock(rest);
@@ -2342,7 +2409,7 @@ var SessionHost = class {
2342
2409
  case "describe":
2343
2410
  case "apropos":
2344
2411
  this.start();
2345
- return (name === "describe" ? describe$1 : apropos)(this.names, rest.trim());
2412
+ return (name === "describe" ? describe : apropos)(this.names, rest.trim());
2346
2413
  case "runs":
2347
2414
  case "mailbox":
2348
2415
  case "vars":
@@ -2385,7 +2452,8 @@ var SessionHost = class {
2385
2452
  builtIn(capability) {
2386
2453
  return this.extensions.has(capability) || capability === "clock" || capability === "store" || capability === "user" || capability === "calendar" && Boolean(this.env.builtIns?.calendar) || capability === "locale" && Boolean(this.env.builtIns?.locale);
2387
2454
  }
2388
- mock([target, mode]) {
2455
+ mock([target, mode, metering]) {
2456
+ if (metering !== void 0 && (metering !== "read-only" || mode !== "suspending")) refuse("bad arguments");
2389
2457
  this.beforeStart();
2390
2458
  const [capability, operation, more] = target.split(".");
2391
2459
  if (more !== void 0 || !NAME_TEXT.test(capability ?? "") || !NAME_TEXT.test(operation ?? "") || capability === "console" || BUILT_IN.has(capability) || this.extensions.has(capability) || !MODES.has(mode)) refuse("bad arguments");
@@ -2395,6 +2463,7 @@ var SessionHost = class {
2395
2463
  mode,
2396
2464
  args: Array.from({ length: 8 }, () => ({ optional: "any" })),
2397
2465
  ...mode === "fire-and-forget" ? {} : { result: "any" },
2466
+ ...metering ? { metering: "read-only" } : {},
2398
2467
  cost: { fuel: 0 }
2399
2468
  };
2400
2469
  const operations = this.setup0.operations;
@@ -2442,6 +2511,17 @@ var SessionHost = class {
2442
2511
  else call.answer(settled);
2443
2512
  return this.pump();
2444
2513
  }
2514
+ charge([id, amount]) {
2515
+ if (!/^(0|[1-9]\d*)$/u.test(amount) || !Number.isSafeInteger(Number(amount))) return refuse("bad arguments");
2516
+ const call = this.pending.get(id);
2517
+ if (!call || call.signal.aborted) return refuse("no such call");
2518
+ try {
2519
+ call.requestCharge(Number(amount));
2520
+ } catch (error) {
2521
+ return refuse(error.code);
2522
+ }
2523
+ return this.pump();
2524
+ }
2445
2525
  isHandler(name) {
2446
2526
  return this.implicit.has(name) || this.declarations.some((d) => d.kind === "handler" && d.names[0]?.split(":")[0] === name);
2447
2527
  }
@@ -2452,7 +2532,7 @@ var SessionHost = class {
2452
2532
  return declarations.map((d) => `${d.source}\n`).join("");
2453
2533
  }
2454
2534
  declare(source) {
2455
- const decl = describe(source);
2535
+ const decl = describe$1(source);
2456
2536
  if (!decl.names.some((n) => this.has(n))) {
2457
2537
  try {
2458
2538
  this.script.extend(source);
@@ -2668,6 +2748,7 @@ var SessionHost = class {
2668
2748
  implicit: new Set(this.implicit),
2669
2749
  lastEntry: this.lastEntry,
2670
2750
  units: this.units,
2751
+ unitDocs: new Map(this.unitDocs),
2671
2752
  placements: new Map(this.placements),
2672
2753
  expressions: new Set(this.expressions),
2673
2754
  inspections: new Set(this.inspections),
@@ -2716,6 +2797,7 @@ var SessionHost = class {
2716
2797
  this.implicit = new Set(saved.implicit);
2717
2798
  this.lastEntry = saved.lastEntry;
2718
2799
  this.units = saved.units;
2800
+ this.unitDocs = new Map(saved.unitDocs);
2719
2801
  this.placements = new Map(saved.placements);
2720
2802
  this.expressions = new Set(saved.expressions);
2721
2803
  this.inspections = new Set(saved.inspections);
@@ -3118,7 +3200,7 @@ var SessionHost = class {
3118
3200
  if (value) {
3119
3201
  if (value.kind === "object") this.reader = value;
3120
3202
  this.env.result?.(e.run, value);
3121
- return valueRows(value).join("\n");
3203
+ return valueRows(value, this.unitDocs).join("\n");
3122
3204
  }
3123
3205
  }
3124
3206
  if (e.delivery && this.expressions.has(e.delivery)) {
@@ -3194,7 +3276,7 @@ const documentable = (entry, kind) => {
3194
3276
  if (doc === "attached") return kind === "declaration" && !entry.children.some((c) => c.kind === "node" && c.rule === "Declaration" && c.children.some((u) => u.kind === "node" && u.rule === "Use"));
3195
3277
  return true;
3196
3278
  };
3197
- const describe = (source) => {
3279
+ const describe$1 = (source) => {
3198
3280
  const checked = checkSource(source);
3199
3281
  const decl = viewSource(checked.tree.root)[0];
3200
3282
  if (decl.k === "use") {
@@ -3229,7 +3311,7 @@ const fixDeclarations = (source, tree) => {
3229
3311
  let first = from;
3230
3312
  while (first < last && /^[ \t\r]*$/u.test(all[first])) first++;
3231
3313
  from = last + 1;
3232
- return describe(all.slice(first, last + 1).join("\n"));
3314
+ return describe$1(all.slice(first, last + 1).join("\n"));
3233
3315
  });
3234
3316
  };
3235
3317
  const placed = (declarations, decl) => {
@@ -3506,4 +3588,4 @@ const replayTranscript = (recorded, options = {}) => {
3506
3588
  };
3507
3589
  };
3508
3590
  //#endregion
3509
- export { MOCK_ARGUMENTS, SessionHost, SessionObjects, builtinDocs, parseEnvelope, parseTranscript, replayTranscript, writeTranscript };
3591
+ export { MOCK_ARGUMENTS, SessionHost, SessionObjects, apropos, builtinDocs, describe, parseEnvelope, parseTranscript, replayTranscript, scriptNames, writeTranscript };
package/setup.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  /// <reference lib="esnext.disposable" />
2
- import { A as shapeOf, C as Setup, D as capabilityOperations, E as buildSetupGroup, M as tsCore, O as immutableSetup, S as OperationSpec, T as ShapeSpec, b as MissingCapabilityError, j as shapeSpec, k as operationDeclarations, w as SetupGroup, x as ObjectRefSpec, y as CaseCore } from "./objects-BdWn56Ia.js";
2
+ import { A as shapeOf, C as Setup, D as capabilityOperations, E as buildSetupGroup, M as tsCore, O as immutableSetup, S as OperationSpec, T as ShapeSpec, b as MissingCapabilityError, j as shapeSpec, k as operationDeclarations, w as SetupGroup, x as ObjectRefSpec, y as CaseCore } from "./objects-BRcpeXwZ.js";
3
3
  export { CaseCore, MissingCapabilityError, ObjectRefSpec, OperationSpec, Setup, SetupGroup, ShapeSpec, buildSetupGroup, capabilityOperations, immutableSetup, operationDeclarations, shapeOf, shapeSpec, tsCore };
package/setup.js CHANGED
@@ -1,8 +1,8 @@
1
1
 
2
- import { n as LoadError } from "./errors-CPPJmAAh.js";
3
- import { t as defineObjectKind } from "./objects-CawjPfhl.js";
4
- import { u as shape } from "./capabilities-BCw9uREe.js";
5
- import { c as compileLibrary, i as restore, l as replacementLibraries, r as newGroup } from "./group-CnpvKoLw.js";
2
+ import { n as LoadError } from "./errors-BKJES3Zu.js";
3
+ import { t as defineObjectKind } from "./objects-BC4fS0vq.js";
4
+ import { u as shape } from "./capabilities-Bi5Qm6Fr.js";
5
+ import { i as restore, l as compileLibrary, r as newGroup, u as replacementLibraries } from "./group-Bz2wh72R.js";
6
6
  //#region src/setup.ts
7
7
  const operationDeclarations = (capabilities) => {
8
8
  const declarations = Object.create(null);
@@ -0,0 +1,168 @@
1
+
2
+ //#region src/sha256.ts
3
+ const K = new Uint32Array([
4
+ 1116352408,
5
+ 1899447441,
6
+ 3049323471,
7
+ 3921009573,
8
+ 961987163,
9
+ 1508970993,
10
+ 2453635748,
11
+ 2870763221,
12
+ 3624381080,
13
+ 310598401,
14
+ 607225278,
15
+ 1426881987,
16
+ 1925078388,
17
+ 2162078206,
18
+ 2614888103,
19
+ 3248222580,
20
+ 3835390401,
21
+ 4022224774,
22
+ 264347078,
23
+ 604807628,
24
+ 770255983,
25
+ 1249150122,
26
+ 1555081692,
27
+ 1996064986,
28
+ 2554220882,
29
+ 2821834349,
30
+ 2952996808,
31
+ 3210313671,
32
+ 3336571891,
33
+ 3584528711,
34
+ 113926993,
35
+ 338241895,
36
+ 666307205,
37
+ 773529912,
38
+ 1294757372,
39
+ 1396182291,
40
+ 1695183700,
41
+ 1986661051,
42
+ 2177026350,
43
+ 2456956037,
44
+ 2730485921,
45
+ 2820302411,
46
+ 3259730800,
47
+ 3345764771,
48
+ 3516065817,
49
+ 3600352804,
50
+ 4094571909,
51
+ 275423344,
52
+ 430227734,
53
+ 506948616,
54
+ 659060556,
55
+ 883997877,
56
+ 958139571,
57
+ 1322822218,
58
+ 1537002063,
59
+ 1747873779,
60
+ 1955562222,
61
+ 2024104815,
62
+ 2227730452,
63
+ 2361852424,
64
+ 2428436474,
65
+ 2756734187,
66
+ 3204031479,
67
+ 3329325298
68
+ ]);
69
+ const rotr = (x, n) => x >>> n | x << 32 - n;
70
+ const initial = [
71
+ 1779033703,
72
+ 3144134277,
73
+ 1013904242,
74
+ 2773480762,
75
+ 1359893119,
76
+ 2600822924,
77
+ 528734635,
78
+ 1541459225
79
+ ];
80
+ /** An incremental SHA-256: `update` with bytes, then `final` once. */
81
+ var Sha256 = class {
82
+ h = new Uint32Array(initial);
83
+ w = /* @__PURE__ */ new Uint32Array(64);
84
+ block = /* @__PURE__ */ new Uint8Array(64);
85
+ blockView = new DataView(this.block.buffer);
86
+ filled = 0;
87
+ length = 0;
88
+ done = false;
89
+ update(bytes) {
90
+ if (this.done) throw new Error("Sha256.update after final");
91
+ this.length += bytes.length;
92
+ let at = 0;
93
+ if (this.filled > 0) {
94
+ const take = Math.min(64 - this.filled, bytes.length);
95
+ this.block.set(bytes.subarray(0, take), this.filled);
96
+ this.filled += take;
97
+ at = take;
98
+ if (this.filled < 64) return this;
99
+ this.compress(this.blockView, 0);
100
+ this.filled = 0;
101
+ }
102
+ const whole = at + Math.floor((bytes.length - at) / 64) * 64;
103
+ if (whole > at) {
104
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.length);
105
+ for (; at < whole; at += 64) this.compress(view, at);
106
+ }
107
+ this.block.set(bytes.subarray(at));
108
+ this.filled = bytes.length - at;
109
+ return this;
110
+ }
111
+ /** The 32-byte digest; the hash takes no more input after it. */
112
+ final() {
113
+ if (this.done) throw new Error("Sha256.final twice");
114
+ const length = this.length;
115
+ const tail = new Uint8Array(this.filled < 56 ? 64 : 128);
116
+ tail.set(this.block.subarray(0, this.filled));
117
+ tail[this.filled] = 128;
118
+ const view = new DataView(tail.buffer);
119
+ view.setUint32(tail.length - 8, Math.floor(length / 536870912));
120
+ view.setUint32(tail.length - 4, length * 8 >>> 0);
121
+ for (let at = 0; at < tail.length; at += 64) this.compress(view, at);
122
+ this.done = true;
123
+ const out = /* @__PURE__ */ new Uint8Array(32);
124
+ const outView = new DataView(out.buffer);
125
+ for (let i = 0; i < 8; i++) outView.setUint32(i * 4, this.h[i]);
126
+ return out;
127
+ }
128
+ compress(view, block) {
129
+ const { h, w } = this;
130
+ for (let i = 0; i < 16; i++) w[i] = view.getUint32(block + i * 4);
131
+ for (let i = 16; i < 64; i++) {
132
+ const s0 = rotr(w[i - 15], 7) ^ rotr(w[i - 15], 18) ^ w[i - 15] >>> 3;
133
+ const s1 = rotr(w[i - 2], 17) ^ rotr(w[i - 2], 19) ^ w[i - 2] >>> 10;
134
+ w[i] = w[i - 16] + s0 + w[i - 7] + s1 >>> 0;
135
+ }
136
+ let a = h[0], b = h[1], c = h[2], d = h[3], e = h[4], f = h[5], g = h[6], hh = h[7];
137
+ for (let i = 0; i < 64; i++) {
138
+ const s1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
139
+ const ch = e & f ^ ~e & g;
140
+ const t1 = hh + s1 + ch + K[i] + w[i] >>> 0;
141
+ const t2 = (rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22)) + (a & b ^ a & c ^ b & c) >>> 0;
142
+ hh = g;
143
+ g = f;
144
+ f = e;
145
+ e = d + t1 >>> 0;
146
+ d = c;
147
+ c = b;
148
+ b = a;
149
+ a = t1 + t2 >>> 0;
150
+ }
151
+ h[0] = h[0] + a >>> 0;
152
+ h[1] = h[1] + b >>> 0;
153
+ h[2] = h[2] + c >>> 0;
154
+ h[3] = h[3] + d >>> 0;
155
+ h[4] = h[4] + e >>> 0;
156
+ h[5] = h[5] + f >>> 0;
157
+ h[6] = h[6] + g >>> 0;
158
+ h[7] = h[7] + hh >>> 0;
159
+ }
160
+ };
161
+ /** The SHA-256 of `bytes`, as 32 bytes. */
162
+ const sha256Bytes = (bytes) => new Sha256().update(bytes).final();
163
+ const sha256 = (input) => {
164
+ const bytes = typeof input === "string" ? new TextEncoder().encode(input) : input;
165
+ return Array.from(sha256Bytes(bytes), (x) => x.toString(16).padStart(2, "0")).join("");
166
+ };
167
+ //#endregion
168
+ export { sha256 as n, sha256Bytes as r, Sha256 as t };
package/sqlite.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /// <reference lib="esnext.disposable" />
2
- import { Bt as SegmentCoordinator, an as SqlParams, cn as SqliteBinding, ln as SqliteImpl, nn as StoreImpl, on as SqlRows, yt as Call } from "./debug-CY9x_Wsi.js";
3
- import { a as Stores, r as StoreQuotas } from "./engine-CCzaBIoi.js";
2
+ import { Wt as SegmentCoordinator, bt as Call, fn as SqliteBinding, ln as SqlParams, on as StoreImpl, pn as SqliteImpl, un as SqlRows } from "./debug-nN5tQ_p4.js";
3
+ import { a as Stores, r as StoreQuotas } from "./engine-CQqt4rTB.js";
4
4
  //#region src/sqlite/database.d.ts
5
5
  /** The table that keeps a database's Stores, which no `sqlite` Grant may use. */
6
6
  export declare const STORE_TABLE = "store";
@@ -39,8 +39,8 @@ export declare class SqliteDatabase {
39
39
  exec(sql: string): void;
40
40
  /** Closes the database, discarding any Segment's uncommitted changes. */
41
41
  close(): void;
42
- query(call: Call<SqliteBinding>, sql: string, params: SqlParams, max: number): SqlRows;
43
- change(call: Call<SqliteBinding>, sql: string, params: SqlParams, max: number): SqlRows & {
42
+ query(call: Call<SqliteBinding>, sql: string, params: SqlParams, max: number, beforeStep: () => void): SqlRows;
43
+ change(call: Call<SqliteBinding>, sql: string, params: SqlParams, max: number, beforeStep: () => void): SqlRows & {
44
44
  readonly changes: number;
45
45
  };
46
46
  begin(call: Call<SqliteBinding>): void;
package/sqlite.js CHANGED
@@ -1,9 +1,9 @@
1
1
 
2
- import { Q as text, t as HostError, v as dec } from "./errors-CPPJmAAh.js";
3
- import { r as decodeValue } from "./readers-C2YMRjC3.js";
4
- import { t as encodeValue } from "./encoding-BUhsrLPK.js";
5
- import { n as hostScriptError } from "./store-capability-BYghoYSd.js";
6
- import { r as Stores, t as StoreContentsError } from "./engine-Dj9My1qX.js";
2
+ import { Q as text, t as HostError, v as dec } from "./errors-BKJES3Zu.js";
3
+ import { r as decodeValue } from "./readers-B5e5bBrY.js";
4
+ import { t as encodeValue } from "./encoding-C3Q7pIC9.js";
5
+ import { n as hostScriptError } from "./store-capability-BxXgiRM7.js";
6
+ import { r as Stores, t as StoreContentsError } from "./engine-BpdGfAND.js";
7
7
  import { DatabaseSync } from "node:sqlite";
8
8
  //#region src/sqlite/scan.ts
9
9
  const isWordChar = (c) => /[\w$]/.test(c) || c.charCodeAt(0) > 127;
@@ -276,16 +276,16 @@ var SqliteDatabase = class {
276
276
  this.writer.close();
277
277
  this.lock.close();
278
278
  }
279
- query(call, sql, params, max) {
279
+ query(call, sql, params, max, beforeStep) {
280
280
  const connection = this.holder === this.key(call) ? this.writer : this.reader;
281
- return this.statement(connection, call.binding, sql, params, max, true);
281
+ return this.statement(connection, call.binding, sql, params, max, beforeStep, true);
282
282
  }
283
- change(call, sql, params, max) {
283
+ change(call, sql, params, max, beforeStep) {
284
284
  this.acquire(call, () => failure("sqlite busy"));
285
285
  const before = this.changeCounts().total;
286
286
  this.writer.exec("SAVEPOINT northtalk_call");
287
287
  try {
288
- const result = this.statement(this.writer, call.binding, sql, params, max, false);
288
+ const result = this.statement(this.writer, call.binding, sql, params, max, beforeStep, false);
289
289
  const { changes, total } = this.changeCounts();
290
290
  this.writer.exec("RELEASE northtalk_call");
291
291
  return {
@@ -385,7 +385,7 @@ var SqliteDatabase = class {
385
385
  total: Number(row.total)
386
386
  };
387
387
  }
388
- statement(connection, binding, sql, params, max, readOnly) {
388
+ statement(connection, binding, sql, params, max, beforeStep, readOnly) {
389
389
  const scanned = scan(sql);
390
390
  if (scanned.keyword === "") throw sqlFailure("The SQL holds no statement");
391
391
  if (scanned.keyword === "VACUUM") throw sqlFailure("VACUUM is not allowed");
@@ -403,15 +403,21 @@ var SqliteDatabase = class {
403
403
  const columns = prepared.columns().map((c) => c.name);
404
404
  const rows = [];
405
405
  const bound = Array.isArray(params) ? params : [Object.fromEntries(params)];
406
- const stepped = prepared.iterate(...bound);
407
- for (const row of stepped) {
408
- if (rows.length === max) throw failure("too many rows", [["max", dec(String(max))]]);
409
- rows.push(row.map((value, i) => decoded(value, columns[i])));
406
+ const stepped = prepared.iterate(...bound)[Symbol.iterator]();
407
+ try {
408
+ for (;;) {
409
+ beforeStep();
410
+ const next = stepped.next();
411
+ if (next.done) return {
412
+ columns,
413
+ rows
414
+ };
415
+ if (rows.length === max) throw failure("too many rows", [["max", dec(String(max))]]);
416
+ rows.push(next.value.map((value, i) => decoded(value, columns[i])));
417
+ }
418
+ } finally {
419
+ stepped.return?.();
410
420
  }
411
- return {
412
- columns,
413
- rows
414
- };
415
421
  } catch (error) {
416
422
  throw translated(error);
417
423
  } finally {
@@ -518,8 +524,8 @@ const sqliteDatabases = (databases) => {
518
524
  };
519
525
  return {
520
526
  coordinator: (database) => named(database).coordinator,
521
- query: (call, sql, params, max) => named(call.binding.database).query(call, sql, params, max),
522
- change: (call, sql, params, max) => named(call.binding.database).change(call, sql, params, max),
527
+ query: (call, sql, params, max, beforeStep) => named(call.binding.database).query(call, sql, params, max, beforeStep),
528
+ change: (call, sql, params, max, beforeStep) => named(call.binding.database).change(call, sql, params, max, beforeStep),
523
529
  begin: (call) => named(call.binding.database).begin(call),
524
530
  commit: (call) => named(call.binding.database).commit(call),
525
531
  rollback: (call) => named(call.binding.database).rollback(call)
@@ -1,6 +1,6 @@
1
1
 
2
- import { ut as compareText } from "./base64-DA7UgjG2.js";
3
- import { a as encodeContents, i as decodeContents, n as StoreStateUnknownError, r as Stores, s as sessionWatchLimits } from "./engine-Dj9My1qX.js";
2
+ import { dt as compareText } from "./base64-Dtqaz_0A.js";
3
+ import { a as encodeContents, i as decodeContents, n as StoreStateUnknownError, r as Stores, s as sessionWatchLimits } from "./engine-BpdGfAND.js";
4
4
  //#region src/store/memory.ts
5
5
  /** A backend that keeps nothing outside the engine's own copy. */
6
6
  const memoryBackend = () => ({
@@ -1,8 +1,8 @@
1
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-CPPJmAAh.js";
3
- import { a as defineValueCapability, f as validComputedMessageName, u as shape } from "./capabilities-BCw9uREe.js";
4
- import { ft as errorMessages, i as ScriptError$1, o as arithmetic } from "./base64-DA7UgjG2.js";
5
- import { r as registerStandardChecks } from "./encoding-BUhsrLPK.js";
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-BKJES3Zu.js";
3
+ import { a as defineValueCapability, f as validComputedMessageName, u as shape } from "./capabilities-Bi5Qm6Fr.js";
4
+ import { i as ScriptError$1, o as arithmetic, pt as errorMessages } from "./base64-Dtqaz_0A.js";
5
+ import { r as registerStandardChecks } from "./encoding-C3Q7pIC9.js";
6
6
  //#region src/standard-capabilities.ts
7
7
  const costOf = (costs, name) => {
8
8
  const cost = costs && Object.hasOwn(costs, name) ? costs[name] : void 0;
package/store.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /// <reference lib="esnext.disposable" />
2
- import { n as RouterOptions } from "./router-BE5Tbbd7.js";
3
- import { a as Stores, c as sessionQuotas, i as StoreStateUnknownError, l as sessionWatchLimits, n as StoreContentsError, o as decodeContents, r as StoreQuotas, s as encodeContents, t as StoreBackend } from "./engine-CCzaBIoi.js";
2
+ import { n as RouterOptions } from "./router-CBuMIl6i.js";
3
+ import { a as Stores, c as sessionQuotas, i as StoreStateUnknownError, l as sessionWatchLimits, n as StoreContentsError, o as decodeContents, r as StoreQuotas, s as encodeContents, t as StoreBackend } from "./engine-CQqt4rTB.js";
4
4
  //#region src/store/memory.d.ts
5
5
  /** A backend that keeps nothing outside the engine's own copy. */
6
6
  export declare const memoryBackend: () => StoreBackend;
package/store.js CHANGED
@@ -1,4 +1,4 @@
1
1
 
2
- import { a as encodeContents, i as decodeContents, n as StoreStateUnknownError, o as sessionQuotas, r as Stores, s as sessionWatchLimits, t as StoreContentsError } from "./engine-Dj9My1qX.js";
3
- import { i as memoryStores, n as webStorageStores, r as memoryBackend, t as webStorageBackend } from "./store-DwESnByX.js";
2
+ import { a as encodeContents, i as decodeContents, n as StoreStateUnknownError, o as sessionQuotas, r as Stores, s as sessionWatchLimits, t as StoreContentsError } from "./engine-BpdGfAND.js";
3
+ import { i as memoryStores, n as webStorageStores, r as memoryBackend, t as webStorageBackend } from "./store-DTQa0lyE.js";
4
4
  export { StoreContentsError, StoreStateUnknownError, Stores, decodeContents, encodeContents, memoryBackend, memoryStores, sessionQuotas, sessionWatchLimits, webStorageBackend, webStorageStores };
@@ -1,9 +1,9 @@
1
1
 
2
- import { Dt as isInteger, Et as integerOf, N as map, Q as text, t as HostError, u as bool, y as decimalParts } from "./errors-CPPJmAAh.js";
3
- import { a as defineValueCapability, u as shape } from "./capabilities-BCw9uREe.js";
4
- import { i as ScriptError } from "./base64-DA7UgjG2.js";
5
- import { r as registerStandardChecks } from "./encoding-BUhsrLPK.js";
6
- import { c as fixed, s as costOf } from "./store-capability-BYghoYSd.js";
2
+ import { Dt as isInteger, Et as integerOf, N as map, Q as text, t as HostError, u as bool, y as decimalParts } from "./errors-BKJES3Zu.js";
3
+ import { a as defineValueCapability, u as shape } from "./capabilities-Bi5Qm6Fr.js";
4
+ import { i as ScriptError } 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
7
  //#region src/locale-tag.ts
8
8
  const grandfathered = /^(?:en-gb-oed|i-(?:ami|bnn|default|enochian|hak|klingon|lux|mingo|navajo|pwn|tao|tay|tsu)|sgn-(?:be-fr|be-nl|ch-de))$/i;
9
9
  const alpha = /^[a-z]+$/i;