@northtalk/ts 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/README.md +16 -14
  2. package/{base64-DORMd3Hv.js → base64-Dtqaz_0A.js} +880 -409
  3. package/{binary-value-CEmh60GC.d.ts → binary-value-Bb6HPDtM.d.ts} +2 -2
  4. package/{capabilities-CH0FkRMq.js → capabilities-Bi5Qm6Fr.js} +39 -20
  5. package/{checker-Dc1jl2WH.js → checker-DMI4LiRm.js} +321 -112
  6. package/core-BzGUgjL6.d.ts +22 -0
  7. package/{debug-CQBxKnJB.d.ts → debug-C72o2pZy.d.ts} +506 -50
  8. package/debug.d.ts +3 -3
  9. package/debug.js +1 -1
  10. package/driver-ClV_UDEK.d.ts +63 -0
  11. package/driver.d.ts +2 -40
  12. package/driver.js +24 -4
  13. package/{encoding-nlrpj-Pb.js → encoding-C3Q7pIC9.js} +2 -2
  14. package/{engine-BGaJ9dAk.js → engine-BpdGfAND.js} +6 -6
  15. package/{engine-vbYInVYF.d.ts → engine-Dtby_FkE.d.ts} +3 -3
  16. package/{errors-LYJZ_c8h.js → errors-BKJES3Zu.js} +1060 -751
  17. package/{group-B742gg4T.js → group-vuUL2tq-.js} +6526 -1725
  18. package/http.d.ts +2 -2
  19. package/http.js +3 -3
  20. package/index-ByF5j53i.d.ts +779 -0
  21. package/index.d.ts +6 -651
  22. package/index.js +23 -15
  23. package/{http-capability-CSTkw1Yt.js → inline-grants-Cx0Z9XAt.js} +109 -24
  24. package/manifest-Dw-8Unmf.js +256 -0
  25. package/message-layer.d.ts +3 -3
  26. package/message-layer.js +2 -2
  27. package/notify.d.ts +2 -2
  28. package/notify.js +1 -1
  29. package/{objects-Db7IB5vQ.js → objects-BC4fS0vq.js} +1 -1
  30. package/{objects-DJ3QtCCs.d.ts → objects-Dnqor7Gn.d.ts} +12 -4
  31. package/{operation-promises-EgZXG5N_.js → operation-promises-ClA1BTaS.js} +10 -5
  32. package/package.json +2 -2
  33. package/{readers-CjJHKHvH.js → readers-B5e5bBrY.js} +2 -2
  34. package/{readers-BFPuosPk.d.ts → readers-DAFVvvq4.d.ts} +2 -2
  35. package/{request-pump-binary-DdY3X-yl.js → request-pump-binary-BjnyqXV5.js} +4 -4
  36. package/{router--71qvxtY.js → router-BCHEfs4x.js} +5 -5
  37. package/{router-Zhrw5l__.d.ts → router-BspOCPA0.d.ts} +3 -3
  38. package/session.d.ts +41 -3
  39. package/session.js +260 -179
  40. package/setup.d.ts +2 -2
  41. package/setup.js +4 -4
  42. package/sha256-9CGf5BS_.js +168 -0
  43. package/sqlite.d.ts +5 -5
  44. package/sqlite.js +27 -21
  45. package/{store-hJrRULMx.js → store-DTQa0lyE.js} +2 -2
  46. package/{store-capability-OZp4hXmj.js → store-capability-BxXgiRM7.js} +4 -4
  47. package/store.d.ts +3 -3
  48. package/store.js +2 -2
  49. package/{user-capability-BK4Asg7D.js → user-capability-5-IvCeZI.js} +5 -5
  50. package/wasm.d.ts +12 -8
  51. package/wasm.js +67 -39
  52. package/core-DptnvQT9.d.ts +0 -14
  53. package/manifest-BscyH_rW.d.ts +0 -70
  54. package/manifest-DjsxDSuB.js +0 -129
  55. package/sha256-B_kyYw3Z.js +0 -124
package/session.js CHANGED
@@ -1,18 +1,18 @@
1
1
 
2
- import { B as range, F as num, K as text, M as map, P as nothing, Qt as parseInstant, dt as characterBoundaries, i as ScriptError, it as builtins, k as listValues, l as Value, mt as lower, n as LoadError, qt as formatInstant, t as HostError, u as bool } from "./errors-LYJZ_c8h.js";
3
- import { o as stateOf, t as defineObjectKind } from "./objects-Db7IB5vQ.js";
4
- import { a as defineValueCapability, f as validComputedMessageName, u as shape } from "./capabilities-CH0FkRMq.js";
5
- import { _ as viewSource, f as declarationDocs, h as leadingDoc, m as functionDoc, o as parseEntry, s as parseSource, t as checkSource } from "./checker-Dc1jl2WH.js";
6
- import { C as integerValue, H as textForm$1, Q as functionHead, U as waitUs, st as compareText } from "./base64-DORMd3Hv.js";
7
- import { a as recordLine, c as compileLibrary, h as defaultLimits, i as restore, o as traceValue, u as stdlibSources } from "./group-B742gg4T.js";
8
- import { c as readDisplay, l as readOrderedJSON, r as decodeValue } from "./readers-CjJHKHvH.js";
9
- import { n as quoteJSON, t as encodeValue } from "./encoding-nlrpj-Pb.js";
10
- import { a as shapeData, n as exportManifest, t as canonicalJSON } from "./manifest-DjsxDSuB.js";
11
- import { n as localeCapability, t as userCapability } from "./user-capability-BK4Asg7D.js";
12
- import { a as clockCapability, i as calendarCapability, o as consoleCapability, r as storeCapability } from "./store-capability-OZp4hXmj.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-vuUL2tq-.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-BGaJ9dAk.js";
15
- import { i as memoryStores } from "./store-hJrRULMx.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");
@@ -1216,157 +1216,6 @@ const builtinDocs = {
1216
1216
  }
1217
1217
  };
1218
1218
  //#endregion
1219
- //#region src/session/observe.ts
1220
- const settled = (m) => m.counted && m.live === 0 && m.queued === 0;
1221
- const row = (fields) => `{${fields.map(([k, v]) => `${k}: ${v}`).join(", ")}}`;
1222
- const textForm = (s) => text(s).toString();
1223
- const fuelRow = (m) => {
1224
- const fuel = [...m.fuel.values()].reduce((a, b) => a + b, 0);
1225
- const state = !settled(m) ? "pending" : m.interrupted ? "interrupted" : "complete";
1226
- return `fuel ${row([
1227
- ["entry", textForm(`entry${m.entry}`)],
1228
- ["fuel", String(fuel)],
1229
- ["state", textForm(state)],
1230
- ["interrupted", String(m.interrupted)],
1231
- ["runs", String(m.live)],
1232
- ["queued", String(m.queued)]
1233
- ])}`;
1234
- };
1235
- const selectorText = (s) => validComputedMessageName(s, s.includes(":") ? s.split(":").length - 1 : 0);
1236
- var Observation = class Observation {
1237
- filters = /* @__PURE__ */ new Set();
1238
- traced = /* @__PURE__ */ new Map();
1239
- measurements = [];
1240
- lines = [];
1241
- clone() {
1242
- const c = new Observation();
1243
- c.filters = new Set(this.filters);
1244
- c.traced = new Map(this.traced);
1245
- c.measurements = this.measurements.map((m) => ({
1246
- ...m,
1247
- fuel: new Map(m.fuel)
1248
- }));
1249
- return c;
1250
- }
1251
- /** `:trace` and `:untrace`. */
1252
- trace(name, rest) {
1253
- const selector = rest.trim();
1254
- if (selector && !selectorText(selector)) return null;
1255
- if (name === "untrace") {
1256
- if (selector) this.filters.delete(selector);
1257
- else this.filters.clear();
1258
- } else if (selector) this.filters.add(selector);
1259
- else return [...this.filters].sort((a, b) => {
1260
- const x = [...a].map((c) => c.codePointAt(0));
1261
- const y = [...b].map((c) => c.codePointAt(0));
1262
- for (let i = 0; i < Math.min(x.length, y.length); i++) if (x[i] !== y[i]) return x[i] - y[i];
1263
- return x.length - y.length;
1264
- }).map((s) => `trace ${textForm(s)}`);
1265
- return [];
1266
- }
1267
- /** Starts measuring the Entry whose Request made this root Delivery. */
1268
- measure(entry, root) {
1269
- this.measurements.push({
1270
- announced: false,
1271
- closed: false,
1272
- counted: false,
1273
- entry,
1274
- fuel: /* @__PURE__ */ new Map(),
1275
- interrupted: false,
1276
- live: 0,
1277
- queued: 0,
1278
- root
1279
- });
1280
- }
1281
- /** Bare `:fuel`: every measurement's current row, in Entry order. */
1282
- rows() {
1283
- return this.measurements.map(fuelRow);
1284
- }
1285
- /** The Entry names of measurements still pending, which a restore abandons. */
1286
- pending() {
1287
- return this.measurements.filter((m) => !settled(m)).map((m) => `entry${m.entry}`);
1288
- }
1289
- end(script, run, fields) {
1290
- const selector = this.traced.get(run);
1291
- if (selector === void 0) return;
1292
- this.traced.delete(run);
1293
- this.lines.push(`trace end ${row([
1294
- ["script", textForm(script)],
1295
- ["run", textForm(run)],
1296
- ["selector", textForm(selector)],
1297
- ...fields
1298
- ])}`);
1299
- }
1300
- measured(root) {
1301
- return this.measurements.find((m) => m.root === root);
1302
- }
1303
- /**
1304
- * Follows one Host call's reports, in order. `errors` holds each errored
1305
- * Run's projected error, as its `! error` row shows it.
1306
- */
1307
- observe(reports, errors) {
1308
- for (const r of reports) if (r.kind === "run started") {
1309
- if (r.selector !== void 0 && this.filters.has(r.selector)) {
1310
- this.traced.set(r.run, r.selector);
1311
- this.lines.push(`trace start ${row([
1312
- ["script", textForm(r.script)],
1313
- ["run", textForm(r.run)],
1314
- ["selector", textForm(r.selector)],
1315
- ["args", traceValue(listValues(r.args))]
1316
- ])}`);
1317
- }
1318
- } else if (r.kind === "run end") {
1319
- const fields = [["outcome", textForm(r.outcome)]];
1320
- if (r.outcome === "completed") fields.push(["result", traceValue(r.result ?? nothing)]);
1321
- else if (r.outcome === "errored") fields.push(["error", errors?.get(r.run ?? "") ?? ""]);
1322
- else if (r.outcome === "limit fault") fields.push(["limit", textForm(r.limit ?? "")]);
1323
- else if (r.outcome === "effect failed" && r.effect) {
1324
- const e = r.effect;
1325
- fields.push(["effect", row([
1326
- ["script", textForm(e.script)],
1327
- ["run", textForm(e.run)],
1328
- ["grant", textForm(e.grant)],
1329
- ["segment", textForm(e.segment)],
1330
- ["phase", textForm(e.phase)],
1331
- ["status", textForm(e.status)],
1332
- ...e.scope ? [["scope", textForm(e.scope)]] : []
1333
- ])]);
1334
- }
1335
- if (r.run) this.end(r.script, r.run, fields);
1336
- } else if (r.kind === "run discarded") this.end(r.script, r.run, [["outcome", textForm("discarded")], ["reason", textForm(r.reason)]]);
1337
- else if (r.kind === "run accounting") {
1338
- const m = this.measured(r.rootDelivery);
1339
- if (m) {
1340
- m.fuel.set(r.run, r.fuel);
1341
- m.interrupted ||= r.state === "discarded";
1342
- }
1343
- } else if (r.kind === "causal work") {
1344
- const m = this.measured(r.rootDelivery);
1345
- if (m) {
1346
- m.counted = true;
1347
- m.live = r.liveRuns;
1348
- m.queued = r.queuedMessages;
1349
- m.interrupted ||= r.discardedMessages > 0;
1350
- }
1351
- }
1352
- }
1353
- /**
1354
- * This Host call's trace rows, then its Fuel milestones: a new
1355
- * measurement's first row, and the final row of each one that has settled.
1356
- */
1357
- observed() {
1358
- const out = this.lines;
1359
- this.lines = [];
1360
- for (const m of this.measurements) {
1361
- if (m.closed || m.announced && !settled(m)) continue;
1362
- m.announced = true;
1363
- m.closed = settled(m);
1364
- out.push(fuelRow(m));
1365
- }
1366
- return out;
1367
- }
1368
- };
1369
- //#endregion
1370
1219
  //#region src/session/inspect.ts
1371
1220
  const declarationValue = (data) => {
1372
1221
  if (data === null || data === void 0) return nothing;
@@ -1381,7 +1230,7 @@ const cost = (c) => declarationValue({
1381
1230
  fuel: c?.fuel ?? 0,
1382
1231
  alloc: c?.alloc ?? 0
1383
1232
  });
1384
- const valueRows = (value) => {
1233
+ const valueRows = (value, unitDocs) => {
1385
1234
  const out = [`value ${map([["kind", text(value.kind)], ["value", value]])}`];
1386
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;
1387
1236
  if (size !== null) out.push(`size ${size}`);
@@ -1393,7 +1242,7 @@ const valueRows = (value) => {
1393
1242
  ["name", head?.name == null ? nothing : text(head.name)],
1394
1243
  ["arity", head ? range(integerValue(BigInt(head.min)), integerValue(BigInt(head.max))) : nothing],
1395
1244
  ["home", text(fn.home)]
1396
- ])}`, `doc ${text(functionDoc(value) ?? "")}`);
1245
+ ])}`, `doc ${text(functionDoc(value, unitDocs) ?? "")}`);
1397
1246
  }
1398
1247
  if (value.kind === "object") {
1399
1248
  const state = stateOf(value);
@@ -1503,7 +1352,7 @@ const builtinDeclared = (name) => {
1503
1352
  };
1504
1353
  const describeTarget = (names, rest) => {
1505
1354
  if (!rest.startsWith("{")) {
1506
- if (!selectorText(rest)) names.refuse("bad arguments");
1355
+ if (!validStaticMessageName(rest)) names.refuse("bad arguments");
1507
1356
  return {
1508
1357
  plain: true,
1509
1358
  target: {
@@ -1534,7 +1383,7 @@ const describeTarget = (names, rest) => {
1534
1383
  };
1535
1384
  };
1536
1385
  /** `:describe <target>`'s rows. */
1537
- const describe$1 = (names, rest) => {
1386
+ const describe = (names, rest) => {
1538
1387
  const { plain, target } = describeTarget(names, rest);
1539
1388
  let found = [];
1540
1389
  if (target.origin === "session") {
@@ -1553,7 +1402,7 @@ const describe$1 = (names, rest) => {
1553
1402
  if (d.arity) out.push(`arity ${d.arity[0]}..${d.arity[1]}`);
1554
1403
  if (d.variable !== void 0) {
1555
1404
  const value = names.variable(d.variable);
1556
- if (value) out.push(...valueRows(value));
1405
+ if (value) out.push(...valueRows(value, names.unitDocs));
1557
1406
  }
1558
1407
  }
1559
1408
  return out;
@@ -1629,10 +1478,206 @@ const apropos = (names, rest) => {
1629
1478
  }
1630
1479
  return out;
1631
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
+ };
1632
1527
  //#endregion
1633
1528
  //#region src/generated/session.ts
1634
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";
1635
1530
  //#endregion
1531
+ //#region src/session/observe.ts
1532
+ const settled = (m) => m.counted && m.live === 0 && m.queued === 0;
1533
+ const row = (fields) => `{${fields.map(([k, v]) => `${k}: ${v}`).join(", ")}}`;
1534
+ const textForm = (s) => text(s).toString();
1535
+ const fuelRow = (m) => {
1536
+ const fuel = [...m.fuel.values()].reduce((a, b) => a + b, 0);
1537
+ const state = !settled(m) ? "pending" : m.interrupted ? "interrupted" : "complete";
1538
+ return `fuel ${row([
1539
+ ["entry", textForm(`entry${m.entry}`)],
1540
+ ["fuel", String(fuel)],
1541
+ ["state", textForm(state)],
1542
+ ["interrupted", String(m.interrupted)],
1543
+ ["runs", String(m.live)],
1544
+ ["queued", String(m.queued)]
1545
+ ])}`;
1546
+ };
1547
+ var Observation = class Observation {
1548
+ filters = /* @__PURE__ */ new Set();
1549
+ traced = /* @__PURE__ */ new Map();
1550
+ measurements = [];
1551
+ lines = [];
1552
+ clone() {
1553
+ const c = new Observation();
1554
+ c.filters = new Set(this.filters);
1555
+ c.traced = new Map(this.traced);
1556
+ c.measurements = this.measurements.map((m) => ({
1557
+ ...m,
1558
+ fuel: new Map(m.fuel)
1559
+ }));
1560
+ return c;
1561
+ }
1562
+ /** `:trace` and `:untrace`. */
1563
+ trace(name, rest) {
1564
+ const selector = rest.trim();
1565
+ if (selector && !validStaticMessageName(selector)) return null;
1566
+ if (name === "untrace") {
1567
+ if (selector) this.filters.delete(selector);
1568
+ else this.filters.clear();
1569
+ } else if (selector) this.filters.add(selector);
1570
+ else return [...this.filters].sort((a, b) => {
1571
+ const x = [...a].map((c) => c.codePointAt(0));
1572
+ const y = [...b].map((c) => c.codePointAt(0));
1573
+ for (let i = 0; i < Math.min(x.length, y.length); i++) if (x[i] !== y[i]) return x[i] - y[i];
1574
+ return x.length - y.length;
1575
+ }).map((s) => `trace ${textForm(s)}`);
1576
+ return [];
1577
+ }
1578
+ /** Starts measuring the Entry whose Request made this root Delivery. */
1579
+ measure(entry, root) {
1580
+ this.measurements.push({
1581
+ announced: false,
1582
+ closed: false,
1583
+ counted: false,
1584
+ entry,
1585
+ fuel: /* @__PURE__ */ new Map(),
1586
+ interrupted: false,
1587
+ live: 0,
1588
+ queued: 0,
1589
+ root
1590
+ });
1591
+ }
1592
+ /** Bare `:fuel`: every measurement's current row, in Entry order. */
1593
+ rows() {
1594
+ return this.measurements.map(fuelRow);
1595
+ }
1596
+ /** The Entry names of measurements still pending, which a restore abandons. */
1597
+ pending() {
1598
+ return this.measurements.filter((m) => !settled(m)).map((m) => `entry${m.entry}`);
1599
+ }
1600
+ end(script, run, fields) {
1601
+ const selector = this.traced.get(run);
1602
+ if (selector === void 0) return;
1603
+ this.traced.delete(run);
1604
+ this.lines.push(`trace end ${row([
1605
+ ["script", textForm(script)],
1606
+ ["run", textForm(run)],
1607
+ ["selector", textForm(selector)],
1608
+ ...fields
1609
+ ])}`);
1610
+ }
1611
+ measured(root) {
1612
+ return this.measurements.find((m) => m.root === root);
1613
+ }
1614
+ /**
1615
+ * Follows one Host call's reports, in order. `errors` holds each errored
1616
+ * Run's projected error, as its `! error` row shows it.
1617
+ */
1618
+ observe(reports, errors) {
1619
+ for (const r of reports) if (r.kind === "run started") {
1620
+ if (r.selector !== void 0 && this.filters.has(r.selector)) {
1621
+ this.traced.set(r.run, r.selector);
1622
+ this.lines.push(`trace start ${row([
1623
+ ["script", textForm(r.script)],
1624
+ ["run", textForm(r.run)],
1625
+ ["selector", textForm(r.selector)],
1626
+ ["args", traceValue(listValues(r.args))]
1627
+ ])}`);
1628
+ }
1629
+ } else if (r.kind === "run end") {
1630
+ const fields = [["outcome", textForm(r.outcome)]];
1631
+ if (r.outcome === "completed") fields.push(["result", traceValue(r.result ?? nothing)]);
1632
+ else if (r.outcome === "errored") fields.push(["error", errors?.get(r.run ?? "") ?? ""]);
1633
+ else if (r.outcome === "limit fault") fields.push(["limit", textForm(r.limit ?? "")]);
1634
+ else if (r.outcome === "effect failed" && r.effect) {
1635
+ const e = r.effect;
1636
+ fields.push(["effect", row([
1637
+ ["script", textForm(e.script)],
1638
+ ["run", textForm(e.run)],
1639
+ ["grant", textForm(e.grant)],
1640
+ ["segment", textForm(e.segment)],
1641
+ ["phase", textForm(e.phase)],
1642
+ ["status", textForm(e.status)],
1643
+ ...e.scope ? [["scope", textForm(e.scope)]] : []
1644
+ ])]);
1645
+ }
1646
+ if (r.run) this.end(r.script, r.run, fields);
1647
+ } else if (r.kind === "run discarded") this.end(r.script, r.run, [["outcome", textForm("discarded")], ["reason", textForm(r.reason)]]);
1648
+ else if (r.kind === "run accounting") {
1649
+ const m = this.measured(r.rootDelivery);
1650
+ if (m) {
1651
+ m.fuel.set(r.run, r.fuel);
1652
+ m.interrupted ||= r.state === "discarded";
1653
+ }
1654
+ } else if (r.kind === "causal work") {
1655
+ const m = this.measured(r.rootDelivery);
1656
+ if (m) {
1657
+ m.counted = true;
1658
+ m.live = r.liveRuns;
1659
+ m.queued = r.queuedMessages;
1660
+ m.interrupted ||= r.discardedMessages > 0;
1661
+ }
1662
+ }
1663
+ }
1664
+ /**
1665
+ * This Host call's trace rows, then its Fuel milestones: a new
1666
+ * measurement's first row, and the final row of each one that has settled.
1667
+ */
1668
+ observed() {
1669
+ const out = this.lines;
1670
+ this.lines = [];
1671
+ for (const m of this.measurements) {
1672
+ if (m.closed || m.announced && !settled(m)) continue;
1673
+ m.announced = true;
1674
+ m.closed = settled(m);
1675
+ out.push(fuelRow(m));
1676
+ }
1677
+ return out;
1678
+ }
1679
+ };
1680
+ //#endregion
1636
1681
  //#region src/session/stubs.ts
1637
1682
  /** An error map as a Host function fails with it, its code and message apart. */
1638
1683
  const hostFailure = (error) => new ScriptError(error.get("code").asText() ?? "", error.get("message").asText() ?? "", map(error.entries().filter(([k]) => k !== "code" && k !== "message")));
@@ -1640,8 +1685,10 @@ const hostFailure = (error) => new ScriptError(error.get("code").asText() ?? "",
1640
1685
  const stubLine = (operation, stub) => recordLine("stub", [operation], [
1641
1686
  ["value", stub.value ? traceValue(stub.value) : null],
1642
1687
  ["error", stub.error ? traceValue(stub.error) : null],
1643
- ["charge", stub.charge ? String(stub.charge) : null]
1688
+ ["charge", stub.charge ? String(stub.charge) : null],
1689
+ ["charge-refused", stub.refused ? "yes" : null]
1644
1690
  ], true);
1691
+ const refuse$1 = (call) => call.charge(Number.MAX_SAFE_INTEGER);
1645
1692
  /** The Stubs queued for each Operation, named `<capability>.<operation>`. */
1646
1693
  var Stubs = class Stubs {
1647
1694
  queues = /* @__PURE__ */ new Map();
@@ -1678,6 +1725,7 @@ var Stubs = class Stubs {
1678
1725
  return nothing;
1679
1726
  }
1680
1727
  if (stub.charge) call.charge(stub.charge);
1728
+ if (stub.refused) refuse$1(call);
1681
1729
  if (stub.malformed) return null;
1682
1730
  if (stub.error) {
1683
1731
  if (!stub.error.entries().length) throw new Error(`The Stub for ${operation} fails`);
@@ -1690,6 +1738,7 @@ var Stubs = class Stubs {
1690
1738
  const queued = this.queues.get(operation)?.shift();
1691
1739
  const stub = queued ?? recorded;
1692
1740
  if (stub?.charge) call.charge(stub.charge);
1741
+ if (stub?.refused) refuse$1(call);
1693
1742
  if (stub?.error) {
1694
1743
  if (!stub.error.entries().length) throw new Error(queued ? `The Stub for ${operation} fails` : `The recorded call of ${operation} fails`);
1695
1744
  throw hostFailure(stub.error);
@@ -1990,6 +2039,7 @@ var SessionHost = class {
1990
2039
  declarations: this.declarations,
1991
2040
  has: (name) => this.has(name),
1992
2041
  refuse,
2042
+ unitDocs: this.unitDocs,
1993
2043
  libraries: new Map([...this.libraries].map(([name, l]) => [name, l.library.source])),
1994
2044
  variable: (name) => this.inspect().scripts.find((s) => s.name === NAME).vars.find(([n]) => n === name)?.[1]
1995
2045
  };
@@ -2000,7 +2050,15 @@ var SessionHost = class {
2000
2050
  * means the value is not a Function Value.
2001
2051
  */
2002
2052
  functionDocumentation(value) {
2003
- 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);
2004
2062
  }
2005
2063
  /**
2006
2064
  * An Entry or a Session Command. Returns the lines it printed. At a
@@ -2019,6 +2077,7 @@ var SessionHost = class {
2019
2077
  this.callStart = this.recordedItems.length;
2020
2078
  this.recording = source.replace(/\n+$/, "");
2021
2079
  const out = this.entry(source);
2080
+ this.retainDocs();
2022
2081
  this.recorded();
2023
2082
  return this.finished(out);
2024
2083
  }
@@ -2272,6 +2331,7 @@ var SessionHost = class {
2272
2331
  ...base,
2273
2332
  mode,
2274
2333
  result: shapeOf(spec.result),
2334
+ ...spec.metering ? { metering: "read-only" } : {},
2275
2335
  start: (call, ...args) => {
2276
2336
  this.mockCalls.set(call.id, {
2277
2337
  operation: key,
@@ -2303,7 +2363,10 @@ var SessionHost = class {
2303
2363
  const w = rest.trim().split(/\s+/u).filter(Boolean);
2304
2364
  return this.grant(w.length === 3 ? w : words(rest, 2));
2305
2365
  }
2306
- 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
+ }
2307
2370
  case "stub":
2308
2371
  this.start();
2309
2372
  return this.stub(rest);
@@ -2311,6 +2374,9 @@ var SessionHost = class {
2311
2374
  case "fail":
2312
2375
  this.start();
2313
2376
  return this.settle(name, rest);
2377
+ case "charge":
2378
+ this.start();
2379
+ return this.charge(words(rest, 2));
2314
2380
  case "clock":
2315
2381
  this.start();
2316
2382
  return this.clock(rest);
@@ -2343,7 +2409,7 @@ var SessionHost = class {
2343
2409
  case "describe":
2344
2410
  case "apropos":
2345
2411
  this.start();
2346
- return (name === "describe" ? describe$1 : apropos)(this.names, rest.trim());
2412
+ return (name === "describe" ? describe : apropos)(this.names, rest.trim());
2347
2413
  case "runs":
2348
2414
  case "mailbox":
2349
2415
  case "vars":
@@ -2386,7 +2452,8 @@ var SessionHost = class {
2386
2452
  builtIn(capability) {
2387
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);
2388
2454
  }
2389
- mock([target, mode]) {
2455
+ mock([target, mode, metering]) {
2456
+ if (metering !== void 0 && (metering !== "read-only" || mode !== "suspending")) refuse("bad arguments");
2390
2457
  this.beforeStart();
2391
2458
  const [capability, operation, more] = target.split(".");
2392
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");
@@ -2396,6 +2463,7 @@ var SessionHost = class {
2396
2463
  mode,
2397
2464
  args: Array.from({ length: 8 }, () => ({ optional: "any" })),
2398
2465
  ...mode === "fire-and-forget" ? {} : { result: "any" },
2466
+ ...metering ? { metering: "read-only" } : {},
2399
2467
  cost: { fuel: 0 }
2400
2468
  };
2401
2469
  const operations = this.setup0.operations;
@@ -2443,6 +2511,17 @@ var SessionHost = class {
2443
2511
  else call.answer(settled);
2444
2512
  return this.pump();
2445
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
+ }
2446
2525
  isHandler(name) {
2447
2526
  return this.implicit.has(name) || this.declarations.some((d) => d.kind === "handler" && d.names[0]?.split(":")[0] === name);
2448
2527
  }
@@ -2453,7 +2532,7 @@ var SessionHost = class {
2453
2532
  return declarations.map((d) => `${d.source}\n`).join("");
2454
2533
  }
2455
2534
  declare(source) {
2456
- const decl = describe(source);
2535
+ const decl = describe$1(source);
2457
2536
  if (!decl.names.some((n) => this.has(n))) {
2458
2537
  try {
2459
2538
  this.script.extend(source);
@@ -2669,6 +2748,7 @@ var SessionHost = class {
2669
2748
  implicit: new Set(this.implicit),
2670
2749
  lastEntry: this.lastEntry,
2671
2750
  units: this.units,
2751
+ unitDocs: new Map(this.unitDocs),
2672
2752
  placements: new Map(this.placements),
2673
2753
  expressions: new Set(this.expressions),
2674
2754
  inspections: new Set(this.inspections),
@@ -2717,6 +2797,7 @@ var SessionHost = class {
2717
2797
  this.implicit = new Set(saved.implicit);
2718
2798
  this.lastEntry = saved.lastEntry;
2719
2799
  this.units = saved.units;
2800
+ this.unitDocs = new Map(saved.unitDocs);
2720
2801
  this.placements = new Map(saved.placements);
2721
2802
  this.expressions = new Set(saved.expressions);
2722
2803
  this.inspections = new Set(saved.inspections);
@@ -3119,7 +3200,7 @@ var SessionHost = class {
3119
3200
  if (value) {
3120
3201
  if (value.kind === "object") this.reader = value;
3121
3202
  this.env.result?.(e.run, value);
3122
- return valueRows(value).join("\n");
3203
+ return valueRows(value, this.unitDocs).join("\n");
3123
3204
  }
3124
3205
  }
3125
3206
  if (e.delivery && this.expressions.has(e.delivery)) {
@@ -3195,7 +3276,7 @@ const documentable = (entry, kind) => {
3195
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"));
3196
3277
  return true;
3197
3278
  };
3198
- const describe = (source) => {
3279
+ const describe$1 = (source) => {
3199
3280
  const checked = checkSource(source);
3200
3281
  const decl = viewSource(checked.tree.root)[0];
3201
3282
  if (decl.k === "use") {
@@ -3230,7 +3311,7 @@ const fixDeclarations = (source, tree) => {
3230
3311
  let first = from;
3231
3312
  while (first < last && /^[ \t\r]*$/u.test(all[first])) first++;
3232
3313
  from = last + 1;
3233
- return describe(all.slice(first, last + 1).join("\n"));
3314
+ return describe$1(all.slice(first, last + 1).join("\n"));
3234
3315
  });
3235
3316
  };
3236
3317
  const placed = (declarations, decl) => {
@@ -3507,4 +3588,4 @@ const replayTranscript = (recorded, options = {}) => {
3507
3588
  };
3508
3589
  };
3509
3590
  //#endregion
3510
- 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
-
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-DJ3QtCCs.js";
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-Dnqor7Gn.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-LYJZ_c8h.js";
3
- import { t as defineObjectKind } from "./objects-Db7IB5vQ.js";
4
- import { u as shape } from "./capabilities-CH0FkRMq.js";
5
- import { c as compileLibrary, i as restore, l as replacementLibraries, r as newGroup } from "./group-B742gg4T.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-vuUL2tq-.js";
6
6
  //#region src/setup.ts
7
7
  const operationDeclarations = (capabilities) => {
8
8
  const declarations = Object.create(null);