@northtalk/ts 0.3.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 (53) 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-Bb6HPDtM.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-BzGUgjL6.d.ts +22 -0
  7. package/{debug-CY9x_Wsi.d.ts → debug-C72o2pZy.d.ts} +475 -45
  8. package/debug.d.ts +2 -2
  9. package/debug.js +1 -1
  10. package/{driver-CwmL5M32.d.ts → driver-ClV_UDEK.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-Dtby_FkE.d.ts} +2 -2
  16. package/{errors-CPPJmAAh.js → errors-BKJES3Zu.js} +1 -1
  17. package/{group-CnpvKoLw.js → group-vuUL2tq-.js} +5903 -1387
  18. package/http.d.ts +1 -1
  19. package/http.js +3 -3
  20. package/index-ByF5j53i.d.ts +779 -0
  21. package/index.d.ts +5 -659
  22. package/index.js +16 -15
  23. package/{inline-grants-Bvk-2aUL.js → inline-grants-Cx0Z9XAt.js} +25 -20
  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-Dnqor7Gn.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-DAFVvvq4.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-BspOCPA0.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 +50 -27
  51. package/core-D902b5Nu.d.ts +0 -14
  52. package/manifest-CeavwKxo.d.ts +0 -122
  53. package/sha256-B_kyYw3Z.js +0 -124
package/index.js CHANGED
@@ -1,23 +1,23 @@
1
1
 
2
- import { G as record, Gt as formatInstant, H as quantity, Jt as nowMicros, L as nothing, N as map, Q as text, R as num, T as instant, W as range, Xt as parseInstant, c as Decimal, d as bytes, dt as builtins, gt as units, i as ScriptError, k as list, l as Value, ln as unicodeVersion, m as civilDate, n as LoadError, pt as grammar, r as MailboxFull, t as HostError, u as bool, v as dec } from "./errors-CPPJmAAh.js";
3
- import { t as defineObjectKind } from "./objects-CawjPfhl.js";
4
- import { h as Lexer, i as defineCapability, p as validMessageSelector, t as LimitReached, u as shape } from "./capabilities-BCw9uREe.js";
5
- import { a as syntaxText, c as parseSource, i as syntaxSelector, l as parseSourceRecovering, m as declarationStart, o as ParseError, r as checkSyntax, s as parseEntry, t as checkSource } from "./checker-Dmnm2SeU.js";
6
- import { U as waitUs, dt as costModel, et as disassemble, pt as languageVersion, r as NotImplementedError, u as canConvert } from "./base64-DA7UgjG2.js";
7
- import { _ as loadScript, b as exportsOf, c as compileLibrary, d as Run, f as Script, g as deliver, h as defaultLimits, i as restore, m as callFunction, n as TsScript, p as UnitLoadError, r as newGroup, s as codeIdentity, t as TsGroup, u as stdlibSources, v as LoweringError, x as lowerTree, y as compileSource } from "./group-CnpvKoLw.js";
8
- import { c as readDisplay, r as decodeValue } from "./readers-C2YMRjC3.js";
9
- import { t as encodeValue } from "./encoding-BUhsrLPK.js";
10
- import { n as exportManifest } from "./manifest-BTwN3NiP.js";
11
- import { a as sqliteCapability, c as fromValue, i as httpCapability, l as toValue, n as createGroup$1, o as decodeJson, r as handlersOf, s as encodeJson, t as inlineGrants, u as talk } from "./inline-grants-Bvk-2aUL.js";
12
- import { n as localeCapability, t as userCapability } from "./user-capability-kDFbi3sm.js";
13
- import { a as clockCapability, i as calendarCapability, l as timerCapability, o as consoleCapability, r as storeCapability, t as add } from "./store-capability-BYghoYSd.js";
2
+ import { G as record, H as quantity, Kt as formatInstant, L as nothing, N as map, Q as text, R as num, T as instant, W as range, Yt as nowMicros, Zt as parseInstant, c as Decimal, d as bytes, dt as builtins, gt as units, i as ScriptError, k as list, l as Value, m as civilDate, n as LoadError, pt as grammar, r as MailboxFull, t as HostError, u as bool, un as unicodeVersion, v as dec } from "./errors-BKJES3Zu.js";
3
+ import { t as defineObjectKind } from "./objects-BC4fS0vq.js";
4
+ import { h as Lexer, i as defineCapability, p as validMessageSelector, t as LimitReached, u as shape } from "./capabilities-Bi5Qm6Fr.js";
5
+ import { a as syntaxText, c as parseSource, i as syntaxSelector, l as parseSourceRecovering, o as ParseError, p as declarationStart, r as checkSyntax, s as parseEntry, t as checkSource, v as kindNames } from "./checker-DMI4LiRm.js";
6
+ import { W as waitUs, ft as costModel, mt as languageVersion, r as NotImplementedError, tt as disassemble, u as canConvert } from "./base64-Dtqaz_0A.js";
7
+ import { S as lowerTree, _ as deliver, b as compileSource, c as codeIdentity, d as stdlibSources, f as Run, g as defaultLimits, h as callFunction, i as restore, l as compileLibrary, m as UnitLoadError, n as TsScript, p as Script, r as newGroup, s as stateFingerprint, t as TsGroup, v as loadScript, x as exportsOf, y as LoweringError } from "./group-vuUL2tq-.js";
8
+ import { n as exportManifest } from "./manifest-Dw-8Unmf.js";
9
+ import { c as readDisplay, r as decodeValue } from "./readers-B5e5bBrY.js";
10
+ import { t as encodeValue } from "./encoding-C3Q7pIC9.js";
11
+ import { a as sqliteCapability, c as fromValue, i as httpCapability, l as toValue, n as createGroup$1, o as decodeJson, r as handlersOf, s as encodeJson, t as inlineGrants, u as talk } from "./inline-grants-Cx0Z9XAt.js";
12
+ import { n as localeCapability, t as userCapability } from "./user-capability-5-IvCeZI.js";
13
+ import { a as clockCapability, i as calendarCapability, l as timerCapability, o as consoleCapability, r as storeCapability, t as add } from "./store-capability-BxXgiRM7.js";
14
14
  //#region src/versions.ts
15
15
  const coreVersions = Object.freeze({
16
16
  language: languageVersion,
17
17
  costModel: String(costModel.version),
18
18
  unicode: unicodeVersion,
19
- core: "ts/0.3.0",
20
- saveFormat: String(11)
19
+ core: "ts/0.4.0",
20
+ saveFormat: String(1)
21
21
  });
22
22
  //#endregion
23
23
  //#region src/core.ts
@@ -36,6 +36,7 @@ const core = Object.freeze({
36
36
  compileLibrary,
37
37
  newGroup,
38
38
  restore,
39
+ stateFingerprint,
39
40
  versions: coreVersions
40
41
  });
41
42
  /** Return the process-wide Core, also used by the free-function helpers. */
@@ -48,4 +49,4 @@ const createGroup = (o) => createGroup$1({
48
49
  core: o.core ?? createCore()
49
50
  });
50
51
  //#endregion
51
- export { Script as CompiledScript, Decimal, HostError, Lexer, LimitReached, LoadError, LoweringError, MailboxFull, NotImplementedError, ParseError, Run, ScriptError, TsGroup, TsScript, UnitLoadError, Value, add, bool, builtins, bytes, calendarCapability, callFunction, canConvert, checkSource, checkSyntax, civilDate, clockCapability, codeIdentity, compileLibrary, compileSource, consoleCapability, coreVersions, createCore, createGroup, dec, declarationStart, decodeJson, decodeValue, defaultLimits, defineCapability, defineObjectKind, deliver, disassemble, encodeJson, encodeValue, exportManifest, exportsOf, formatInstant, fromValue, grammar, handlersOf, httpCapability, inlineGrants, instant, list, loadScript, localeCapability, lowerTree, map, newGroup, nothing, nowMicros, num, parseEntry, parseInstant, parseSource, parseSourceRecovering, quantity, range, readDisplay, record, restore, shape, sqliteCapability, stdlibSources, storeCapability, syntaxSelector, syntaxText, talk, text, timerCapability, toValue, units, userCapability, validMessageSelector, waitUs };
52
+ export { Script as CompiledScript, Decimal, HostError, Lexer, LimitReached, LoadError, LoweringError, MailboxFull, NotImplementedError, ParseError, Run, ScriptError, TsGroup, TsScript, UnitLoadError, Value, add, bool, builtins, bytes, calendarCapability, callFunction, canConvert, checkSource, checkSyntax, civilDate, clockCapability, codeIdentity, compileLibrary, compileSource, consoleCapability, coreVersions, createCore, createGroup, dec, declarationStart, decodeJson, decodeValue, defaultLimits, defineCapability, defineObjectKind, deliver, disassemble, encodeJson, encodeValue, exportManifest, exportsOf, formatInstant, fromValue, grammar, handlersOf, httpCapability, inlineGrants, instant, kindNames, list, loadScript, localeCapability, lowerTree, map, newGroup, nothing, nowMicros, num, parseEntry, parseInstant, parseSource, parseSourceRecovering, quantity, range, readDisplay, record, restore, shape, sqliteCapability, stdlibSources, storeCapability, syntaxSelector, syntaxText, talk, text, timerCapability, toValue, units, userCapability, validMessageSelector, waitUs };
@@ -1,9 +1,9 @@
1
1
 
2
- import { A as listValues, D as isDecimal, Dt as isInteger, Et as integerOf, G as record, L as nothing, N as map, Q as text, R as num, an as normalizeNFC, d as bytes, en as characterBoundaries, i as ScriptError, l as Value, o as invalidValue, q as requireValue, t as HostError, u as bool, v as dec, y as decimalParts } from "./errors-CPPJmAAh.js";
3
- import { a as defineValueCapability, f as validComputedMessageName, i as defineCapability, m as validStaticMessageName, s as expectedOf, u as shape } from "./capabilities-BCw9uREe.js";
4
- import { ft as errorMessages, i as ScriptError$1 } 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 { A as listValues, D as isDecimal, Dt as isInteger, Et as integerOf, G as record, L as nothing, N as map, Q as text, R as num, d as bytes, i as ScriptError, l as Value, o as invalidValue, on as normalizeNFC, q as requireValue, t as HostError, tn as characterBoundaries, u as bool, v as dec, y as decimalParts } from "./errors-BKJES3Zu.js";
3
+ import { a as defineValueCapability, f as validComputedMessageName, i as defineCapability, m as validStaticMessageName, s as expectedOf, u as shape } from "./capabilities-Bi5Qm6Fr.js";
4
+ import { i as ScriptError$1, pt as errorMessages } from "./base64-Dtqaz_0A.js";
5
+ import { r as registerStandardChecks } from "./encoding-C3Q7pIC9.js";
6
+ import { c as fixed, s as costOf } from "./store-capability-BxXgiRM7.js";
7
7
  import { asyncDispose, newDrivenGroup } from "./driver.js";
8
8
  //#region src/talk.ts
9
9
  const blank = /^[\t ]*$/;
@@ -401,7 +401,6 @@ const encodeJson = (value) => {
401
401
  };
402
402
  //#endregion
403
403
  //#region src/sqlite-capability.ts
404
- const MAX_WHOLE = Number.MAX_SAFE_INTEGER;
405
404
  const isWhole = (n) => Number.isSafeInteger(n) && n >= 0;
406
405
  const INT64_MIN = -(2n ** 63n);
407
406
  const INT64_MAX = 2n ** 63n - 1n;
@@ -434,7 +433,16 @@ const errorFields = {
434
433
  "too many rows": (data) => data.get("max").kind === "number",
435
434
  unrepresentable: (data) => isText(data, "column")
436
435
  };
437
- const errors = (...codes) => codes.map((code) => ({ code }));
436
+ const declaredFields = {
437
+ sql: { reason: shape.text },
438
+ constraint: { kind: shape.text },
439
+ "too many rows": { max: shape.number },
440
+ unrepresentable: { column: shape.text }
441
+ };
442
+ const errors = (...codes) => codes.map((code) => declaredFields[code] ? {
443
+ code,
444
+ fields: declaredFields[code]
445
+ } : { code });
438
446
  const coreFailure = (code, field, value) => new ScriptError(code, "", map([[field, text(value)]]));
439
447
  const checkBinding = (binding) => {
440
448
  if (!binding || typeof binding !== "object" || typeof binding.database !== "string" || !isWhole(binding.maxRows) || binding.tables !== void 0 && (!Array.isArray(binding.tables) || !binding.tables.every((t) => typeof t === "string"))) throw new HostError("invalid value", "A sqlite binding is {database, tables, maxRows}");
@@ -507,8 +515,8 @@ const rowsOf = (result) => {
507
515
  }
508
516
  return listValues(result.rows.map((row) => map(columns.map((column, i) => [column, valueOf(row[i], column)]))));
509
517
  };
510
- /** Optional for Hosts. perRow is whole Fuel charged per row of max. */
511
- const sqliteCapability = (impl, costs, perRow) => {
518
+ /** Optional for Hosts. perStep is whole Fuel charged before each SQLite step. */
519
+ const sqliteCapability = (impl, costs, perStep) => {
512
520
  for (const name of [
513
521
  "coordinator",
514
522
  "query",
@@ -517,13 +525,8 @@ const sqliteCapability = (impl, costs, perRow) => {
517
525
  "commit",
518
526
  "rollback"
519
527
  ]) if (!impl || typeof impl[name] !== "function") throw new HostError("invalid value", `sqlite needs ${name}`);
520
- if (!isWhole(perRow)) throw new HostError("invalid value", "The per-row cost must be a whole number");
521
- const chargeRows = (call, max) => call.charge(Math.min(max * perRow, MAX_WHOLE));
522
- const statement = (run) => (call, ...args) => {
523
- const max = rowsAllowed(args[2], call.binding);
524
- chargeRows(call, max);
525
- return run(call, args[0].asText(), paramsOf(args[1]), max);
526
- };
528
+ if (!isWhole(perStep)) throw new HostError("invalid value", "The per-step cost must be a whole number");
529
+ const statement = (run) => (call, ...args) => run(call, args[0].asText(), paramsOf(args[1]), rowsAllowed(args[2], call.binding), () => call.charge(perStep));
527
530
  const statementArgs = [
528
531
  shape.text,
529
532
  paramsShape,
@@ -549,8 +552,9 @@ const sqliteCapability = (impl, costs, perRow) => {
549
552
  result: shape.listOf(shape.any),
550
553
  errors: errors("sql", "not read-only", "too many rows", "unrepresentable"),
551
554
  cost: costOf(costs, "query"),
552
- do: statement((call, sql, params, max) => {
553
- const result = impl.query(call, sql, params, max);
555
+ metering: "read-only",
556
+ do: statement((call, sql, params, max, beforeStep) => {
557
+ const result = impl.query(call, sql, params, max, beforeStep);
554
558
  checkForm(result, max, false);
555
559
  return rowsOf(result);
556
560
  })
@@ -565,8 +569,9 @@ const sqliteCapability = (impl, costs, perRow) => {
565
569
  errors: errors("sql", "constraint", "sqlite busy", "too many rows", "unrepresentable"),
566
570
  cost: costOf(costs, "change"),
567
571
  segmentBound: true,
568
- do: statement((call, sql, params, max) => {
569
- const result = impl.change(call, sql, params, max);
572
+ metering: "segment-bound",
573
+ do: statement((call, sql, params, max, beforeStep) => {
574
+ const result = impl.change(call, sql, params, max, beforeStep);
570
575
  checkForm(result, max, true);
571
576
  const rows = rowsOf(result);
572
577
  return map([["changes", dec(String(result.changes))], ["rows", rows]]);
@@ -1,7 +1,39 @@
1
1
 
2
- import { K as requireArgs, t as HostError } from "./errors-CPPJmAAh.js";
3
- import { pt as languageVersion, ut as compareText } from "./base64-DA7UgjG2.js";
4
- import { n as quoteJSON } from "./encoding-BUhsrLPK.js";
2
+ import { K as requireArgs, t as HostError } from "./errors-BKJES3Zu.js";
3
+ import { t as LimitReached } from "./capabilities-Bi5Qm6Fr.js";
4
+ import { dt as compareText, mt as languageVersion } from "./base64-Dtqaz_0A.js";
5
+ import { n as quoteJSON } from "./encoding-C3Q7pIC9.js";
6
+ //#region src/call-meter.ts
7
+ var CallMeter = class {
8
+ take;
9
+ /** The Fuel accepted increments added up to. */
10
+ charged = 0;
11
+ /** An increment didn't fit: the call faults, whatever the Host does next. */
12
+ refused = false;
13
+ #starting = false;
14
+ constructor(take) {
15
+ this.take = take;
16
+ }
17
+ /** Runs the Operation's starting callback, the only time it may charge. */
18
+ starting(start) {
19
+ this.#starting = true;
20
+ try {
21
+ return start();
22
+ } finally {
23
+ this.#starting = false;
24
+ }
25
+ }
26
+ charge = (fuel) => {
27
+ if (!this.#starting) throw new HostError("invalid value", "Charge only while starting");
28
+ if (!Number.isSafeInteger(fuel) || fuel < 0) throw new HostError("invalid value", "Fuel must be a whole number");
29
+ if (this.refused || !this.take(fuel, this.charged)) {
30
+ this.refused = true;
31
+ throw new LimitReached("the Run can’t cover this charge");
32
+ }
33
+ this.charged += fuel;
34
+ };
35
+ };
36
+ //#endregion
5
37
  //#region src/embedding.ts
6
38
  /** request({ name, args }).result, for either Core's Script. */
7
39
  const invoke = (script, name, args) => {
@@ -58,7 +90,8 @@ const operationData = (name, op) => ({
58
90
  abandon: op.scope.abandon
59
91
  } : { closes: op.scope.closes } } : {},
60
92
  ...op.mode === "immediate" && op.segmentBound ? { segmentBound: true } : {},
61
- ...op.command ? { command: true } : {}
93
+ ...op.command ? { command: true } : {},
94
+ ...op.mode !== "fire-and-forget" && op.metering ? { metering: op.metering } : {}
62
95
  });
63
96
  const grantData = (grant, operation = operationData) => ({
64
97
  capability: grant.capability.name,
@@ -133,5 +166,91 @@ const exportManifest = (m) => {
133
166
  ...m.ownerKind ? { ownerKind: m.ownerKind.name } : {}
134
167
  })}\n`;
135
168
  };
169
+ /** A Shape from its Host Manifest data, as `shapeData` writes it. */
170
+ const shapeOf = (data) => {
171
+ if (typeof data === "string") return data === "any" ? { k: "any" } : data === "value" ? { k: "value" } : {
172
+ k: "kind",
173
+ kind: data
174
+ };
175
+ const d = data;
176
+ if (typeof d.object === "string") return {
177
+ k: "object",
178
+ kind: d.object
179
+ };
180
+ if (typeof d.quantity === "string") return {
181
+ k: "quantity",
182
+ unit: d.quantity
183
+ };
184
+ if (typeof d.unitKind === "string") return {
185
+ k: "unitKind",
186
+ kind: d.unitKind
187
+ };
188
+ if ("list" in d) return {
189
+ k: "list",
190
+ of: shapeOf(d.list)
191
+ };
192
+ if (Array.isArray(d.oneOf)) return {
193
+ k: "oneOf",
194
+ of: d.oneOf.map(shapeOf)
195
+ };
196
+ if ("optional" in d) return {
197
+ k: "optional",
198
+ of: shapeOf(d.optional)
199
+ };
200
+ if (Array.isArray(d.map)) return {
201
+ k: "map",
202
+ fields: d.map.map((f) => ({
203
+ key: f.key,
204
+ optional: f.optional === true,
205
+ shape: shapeOf(f.shape)
206
+ })),
207
+ open: d.open === true
208
+ };
209
+ throw new HostError("invalid save");
210
+ };
211
+ /**
212
+ * A Grant's Operations from their Host Manifest data, as a save keeps them:
213
+ * their shapes and declared costs, with no Host functions.
214
+ */
215
+ const operationsOf = (json) => {
216
+ let data;
217
+ try {
218
+ data = JSON.parse(json);
219
+ } catch {
220
+ throw new HostError("invalid save");
221
+ }
222
+ if (!data || typeof data.capability !== "string" || !Array.isArray(data.operations)) throw new HostError("invalid save");
223
+ return {
224
+ capability: data.capability,
225
+ operations: new Map(data.operations.map((op) => {
226
+ const cost = op.cost;
227
+ const errors = op.errors;
228
+ const scope = op.scope;
229
+ const decl = {
230
+ mode: op.mode,
231
+ args: op.args.map(shapeOf),
232
+ ...Array.isArray(op.labels) ? { labels: op.labels } : {},
233
+ ...op.result === void 0 ? {} : { result: shapeOf(op.result) },
234
+ cost: {
235
+ fuel: cost.fuel,
236
+ alloc: cost.alloc
237
+ },
238
+ ...typeof op.maxPending === "number" ? { maxPendingMs: op.maxPending } : {},
239
+ ...errors ? { errors: errors.map((e) => ({
240
+ code: e.code,
241
+ fields: Object.fromEntries(e.fields.map((f) => [f.key, f.optional ? {
242
+ optional: true,
243
+ shape: shapeOf(f.shape)
244
+ } : shapeOf(f.shape)]))
245
+ })) } : {},
246
+ ...scope ? { scope } : {},
247
+ ...op.segmentBound ? { segmentBound: true } : {},
248
+ ...op.command ? { command: true } : {},
249
+ ...op.metering ? { metering: op.metering } : {}
250
+ };
251
+ return [op.name, decl];
252
+ }))
253
+ };
254
+ };
136
255
  //#endregion
137
- export { shapeData as a, operationData as i, exportManifest as n, invoke as o, grantData as r, canonicalJSON as t };
256
+ export { operationsOf as a, CallMeter as c, operationData as i, exportManifest as n, shapeData as o, grantData as r, invoke as s, canonicalJSON as t };
@@ -1,6 +1,6 @@
1
1
  /// <reference lib="esnext.disposable" />
2
- import { i as JsonObject, n as Json, r as JsonNumber, s as readOrderedJSON } from "./readers-DMCXzY3X.js";
3
- import { n as decodeBinaryValue, r as encodeBinaryValue, t as BinaryValueOptions } from "./binary-value-BcHcwVLO.js";
2
+ import { i as JsonObject, n as Json, r as JsonNumber, s as readOrderedJSON } from "./readers-DAFVvvq4.js";
3
+ import { n as decodeBinaryValue, r as encodeBinaryValue, t as BinaryValueOptions } from "./binary-value-Bb6HPDtM.js";
4
4
  //#region src/request-pump-binary.d.ts
5
5
  export declare const requestPumpFeature: "request-pump-fields-v1";
6
6
  export declare const callbacksFeature: "callbacks-fields-v1";
package/message-layer.js CHANGED
@@ -1,4 +1,4 @@
1
1
 
2
- import { l as readOrderedJSON, n as JsonObject, t as JsonNumber } from "./readers-C2YMRjC3.js";
3
- import { c as isRequestPumpBinary, f as decodeBinaryValue, i as encodeBinaryFrame, n as decodeBinaryFrame, p as encodeBinaryValue, t as callbacksFeature, u as requestPumpFeature } from "./request-pump-binary-Cp3RGZIJ.js";
2
+ import { l as readOrderedJSON, n as JsonObject, t as JsonNumber } from "./readers-B5e5bBrY.js";
3
+ import { c as isRequestPumpBinary, f as decodeBinaryValue, i as encodeBinaryFrame, n as decodeBinaryFrame, p as encodeBinaryValue, t as callbacksFeature, u as requestPumpFeature } from "./request-pump-binary-BjnyqXV5.js";
4
4
  export { JsonNumber, JsonObject, callbacksFeature, decodeBinaryFrame, decodeBinaryValue, encodeBinaryFrame, encodeBinaryValue, isRequestPumpBinary, readOrderedJSON, requestPumpFeature };
package/notify.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  /// <reference lib="esnext.disposable" />
2
- import { a as changed, i as WatchLimits, n as RouterOptions, o as createRouter, r as RoutingResult, t as NotificationRouter } from "./router-BE5Tbbd7.js";
2
+ import { a as changed, i as WatchLimits, n as RouterOptions, o as createRouter, r as RoutingResult, t as NotificationRouter } from "./router-BspOCPA0.js";
3
3
  export { type NotificationRouter, type RouterOptions, type RoutingResult, type WatchLimits, changed, createRouter };
package/notify.js CHANGED
@@ -1,2 +1,2 @@
1
1
 
2
- export { t as changed, n as createRouter } from "./router-BSREiSux.js";
2
+ export { t as changed, n as createRouter } from "./router-BCHEfs4x.js";
@@ -1,5 +1,5 @@
1
1
 
2
- import { t as HostError, z as objectValue } from "./errors-CPPJmAAh.js";
2
+ import { t as HostError, z as objectValue } from "./errors-BKJES3Zu.js";
3
3
  //#region src/objects.ts
4
4
  const elementCost = (cost, name) => {
5
5
  const c = cost;
@@ -1,5 +1,5 @@
1
1
  /// <reference lib="esnext.disposable" />
2
- import { A as SessionControls, Dn as replacementLibraries, E as RunEvent, En as compileLibrary, F as TsRestoreOptions, Gn as LoadError, I as TsScript, N as TsGroup, Ot as Grant, P as TsGroupOptions, Rt as ScopeDecl, S as Report, T as RestoreResult, Ut as Shape, bt as CapabilityDef, cn as SqliteBinding, dn as LocaleImpl, ft as HostObject, h as Inspection, ht as ObjectKindDef, j as SessionPort, kn as Limits, mt as ObjectKind, pn as CalendarImpl, q as Value, t as DebugController, vt as GrantDecls, xn as Library } from "./debug-CY9x_Wsi.js";
2
+ import { An as compileLibrary, C as Report, D as RunEvent, E as RestoreResult, F as TsGroupOptions, Ht as ScopeDecl, I as TsRestoreOptions, J as Value, L as TsScript, M as SessionPort, Nn as Limits, P as TsGroup, Tn as Library, Yn as LoadError, _n as CalendarImpl, fn as SqliteBinding, g as Inspection, gt as ObjectKindDef, hn as LocaleImpl, ht as ObjectKind, j as SessionControls, jn as replacementLibraries, jt as Grant, pt as HostObject, qt as Shape, t as DebugController, xt as CapabilityDef, yt as GrantDecls } from "./debug-C72o2pZy.js";
3
3
  //#region src/setup.d.ts
4
4
  type ShapeSpec = string | {
5
5
  quantity: string;
@@ -41,6 +41,7 @@ type OperationSpec = {
41
41
  /** Argument Labels, one per argument after the first (ADR 0115). */
42
42
  labels?: string[];
43
43
  maxPending?: number;
44
+ metering?: 'read-only' | 'segment-bound';
44
45
  mode: 'immediate' | 'suspending' | 'fire-and-forget';
45
46
  name: string;
46
47
  result?: ShapeSpec;
@@ -128,7 +129,7 @@ type Setup = {
128
129
  alloc?: number;
129
130
  fuel?: number;
130
131
  }>;
131
- perRow?: number;
132
+ perStep?: number;
132
133
  }[];
133
134
  };
134
135
  declare const operationDeclarations: (capabilities: ReadonlyMap<string, CapabilityDef<unknown>>) => GrantDecls;
@@ -402,6 +403,12 @@ declare class SessionHost {
402
403
  * means the value is not a Function Value.
403
404
  */
404
405
  functionDocumentation(value: Value): string | null;
406
+ /**
407
+ * Each defining-source version's Declaration Documentation, by unit
408
+ * identity, kept before code changes can discard it (chapter 9).
409
+ */
410
+ private unitDocs;
411
+ private retainDocs;
405
412
  /**
406
413
  * An Entry or a Session Command. Returns the lines it printed. At a
407
414
  * debugger pause, only `:fix` of the paused Run.
@@ -442,6 +449,7 @@ declare class SessionHost {
442
449
  private mock;
443
450
  private stub;
444
451
  private settle;
452
+ private charge;
445
453
  private isHandler;
446
454
  private has;
447
455
  private sessionSource;
@@ -531,7 +539,7 @@ type ReplayOptions = {
531
539
  capabilities?: SessionEnvironment['capabilities'];
532
540
  /**
533
541
  * Where the Session Host turns once the Transcript runs out, so a
534
- * Playground can go on live from a replayed session: its Clock, its
542
+ * Host can go on live from a replayed session: its Clock, its
535
543
  * built-in Capabilities, and where later items and echoed values go.
536
544
  */
537
545
  live?: Pick<SessionEnvironment, 'builtIns' | 'capabilities' | 'now' | 'record' | 'result' | 'transcriptEnds'>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@northtalk/ts",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "NorthTalk, a readable scripting language for embedding: the TS Core, its Session Host and Standard Capabilities.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
 
2
- import { $t as assertScalarText, A as listValues, H as quantity, L as nothing, N as map, Q as text, T as instant, W as range, Xt as parseInstant, f as bytesOf, l as Value, m as civilDate, o as invalidValue, u as bool, v as dec, w as hiddenCodePoint } from "./errors-CPPJmAAh.js";
3
- import { t as fromBase64 } from "./base64-DA7UgjG2.js";
2
+ import { A as listValues, H as quantity, L as nothing, N as map, Q as text, T as instant, W as range, Zt as parseInstant, en as assertScalarText, f as bytesOf, l as Value, m as civilDate, o as invalidValue, u as bool, v as dec, w as hiddenCodePoint } from "./errors-BKJES3Zu.js";
3
+ import { t as fromBase64 } from "./base64-Dtqaz_0A.js";
4
4
  //#region src/readers.ts
5
5
  var Reader = class {
6
6
  source;
@@ -1,5 +1,5 @@
1
1
  /// <reference lib="esnext.disposable" />
2
- import { q as Value } from "./debug-CY9x_Wsi.js";
2
+ import { J as Value } from "./debug-C72o2pZy.js";
3
3
  //#region src/readers.d.ts
4
4
  /** Finds the Host Object a reader names by its kind and id, or none. */
5
5
  type ObjectResolver = (kind: string, id: string) => {
@@ -1,8 +1,8 @@
1
1
 
2
- import { A as listValues, Gt as formatInstant, H as quantity, L as nothing, N as map, Q as text, R as num, S as functionValue, T as instant, V as patternValue, W as range, Xt as parseInstant, an as normalizeNFC, d as bytes, l as Value, m as civilDate, o as invalidValue, u as bool, v as dec, z as objectValue } from "./errors-CPPJmAAh.js";
3
- import { t as checkSource, v as viewSource } from "./checker-Dmnm2SeU.js";
4
- import { n as toBase64, ot as patternSource, v as decodeUtf8 } from "./base64-DA7UgjG2.js";
5
- import { a as fromJson, n as JsonObject, o as isJsonNumber, s as isJsonObject, t as JsonNumber } from "./readers-C2YMRjC3.js";
2
+ import { A as listValues, H as quantity, Kt as formatInstant, L as nothing, N as map, Q as text, R as num, S as functionValue, T as instant, V as patternValue, W as range, Zt as parseInstant, d as bytes, l as Value, m as civilDate, o as invalidValue, on as normalizeNFC, u as bool, v as dec, z as objectValue } from "./errors-BKJES3Zu.js";
3
+ import { _ as viewSource, t as checkSource } from "./checker-DMI4LiRm.js";
4
+ import { n as toBase64, st as patternSource, v as decodeUtf8 } from "./base64-Dtqaz_0A.js";
5
+ import { a as fromJson, n as JsonObject, o as isJsonNumber, s as isJsonObject, t as JsonNumber } from "./readers-B5e5bBrY.js";
6
6
  //#region src/binary-value.ts
7
7
  const coreErrors = /* @__PURE__ */ new WeakSet();
8
8
  const max = 2n ** 64n;
@@ -1,9 +1,9 @@
1
1
 
2
- import { A as listValues, N as map, Q as text, i as ScriptError, t as HostError, u as bool } from "./errors-CPPJmAAh.js";
3
- import { Q as sizeOf, ut as compareText } from "./base64-DA7UgjG2.js";
4
- import { t as encodeValue } from "./encoding-BUhsrLPK.js";
5
- import { t as sha256 } from "./sha256-B_kyYw3Z.js";
6
- import { n as hostScriptError } from "./store-capability-BYghoYSd.js";
2
+ import { A as listValues, N as map, Q as text, i as ScriptError, t as HostError, u as bool } from "./errors-BKJES3Zu.js";
3
+ import { $ as sizeOf, dt as compareText } from "./base64-Dtqaz_0A.js";
4
+ import { t as encodeValue } from "./encoding-C3Q7pIC9.js";
5
+ import { n as sha256 } from "./sha256-9CGf5BS_.js";
6
+ import { n as hostScriptError } from "./store-capability-BxXgiRM7.js";
7
7
  //#region src/notify/router.ts
8
8
  /**
9
9
  * Whether a commit changed a key's value: compared by the bytes of the Value
@@ -1,6 +1,6 @@
1
1
  /// <reference lib="esnext.disposable" />
2
- import { D as SaveOptions, F as TsRestoreOptions, Jt as Group, N as TsGroup, T as RestoreResult, kt as GrantContext, q as Value, yt as Call } from "./debug-CY9x_Wsi.js";
3
- import { t as TsCore } from "./core-D902b5Nu.js";
2
+ import { E as RestoreResult, I as TsRestoreOptions, J as Value, Mt as GrantContext, O as SaveOptions, P as TsGroup, Qt as Group, bt as Call } from "./debug-C72o2pZy.js";
3
+ import { t as TsCore } from "./core-BzGUgjL6.js";
4
4
  //#region src/notify/router.d.ts
5
5
  /** A Store's four limits on its watches (Store Notifications, Limits). */
6
6
  type WatchLimits = {
package/session.d.ts CHANGED
@@ -1,9 +1,47 @@
1
1
  /// <reference lib="esnext.disposable" />
2
- import { C as Setup, _ as UserPrompt, a as ReplayOptions, c as parseTranscript, d as DebugAction, f as MOCK_ARGUMENTS, g as SourcePlacement, h as SessionHost, i as parseEnvelope, l as replayTranscript, m as SessionEnvironment, n as ObjectReference, o as Replayed, p as Mock, r as SessionObjects, s as TranscriptItem, t as Envelope, u as writeTranscript, v as Waiting } from "./objects-BdWn56Ia.js";
2
+ import { J as Value } from "./debug-C72o2pZy.js";
3
+ import { C as Setup, _ as UserPrompt, a as ReplayOptions, c as parseTranscript, d as DebugAction, f as MOCK_ARGUMENTS, g as SourcePlacement, h as SessionHost, i as parseEnvelope, l as replayTranscript, m as SessionEnvironment, n as ObjectReference, o as Replayed, p as Mock, r as SessionObjects, s as TranscriptItem, t as Envelope, u as writeTranscript, v as Waiting } from "./objects-Dnqor7Gn.js";
4
+ //#region src/session/describe.d.ts
5
+ /** One declaration of the session source, as `:describe` reads it. */
6
+ type DeclaredName = {
7
+ kind: 'use' | 'handler' | 'function' | 'constant' | 'variable';
8
+ library?: string;
9
+ names: string[];
10
+ source: string;
11
+ uses?: {
12
+ local: string;
13
+ name: string;
14
+ }[];
15
+ };
16
+ /** What the Session Host holds for name lookup. */
17
+ type Names = {
18
+ readonly declarations: readonly DeclaredName[];
19
+ /** Whether a current binding has the name, which shadows a Built-in. */
20
+ has(name: string): boolean;
21
+ /** User Libraries, in the order added, with their current sources. */
22
+ readonly libraries: ReadonlyMap<string, string>;
23
+ /** Refuses the command with `! <reason>`. */
24
+ refuse(reason: string): never;
25
+ /** Retained Declaration Documentation, by unit identity and function name. */
26
+ readonly unitDocs?: ReadonlyMap<string, ReadonlyMap<string, string>>;
27
+ /** A current Script Variable's value, from one explicit snapshot. */
28
+ variable(name: string): Value | undefined;
29
+ };
30
+ /** `:describe <target>`'s rows. */
31
+ export declare const describe: (names: Names, rest: string) => string[];
32
+ /** `:apropos [query]`'s rows. */
33
+ export declare const apropos: (names: Names, rest: string) => string[];
34
+ /**
35
+ * The Names of one whole Script, for a host without a Session Host: each
36
+ * declaration of `source` in order, with the comments before it, and the
37
+ * given User Libraries. No Script Variable has a value to show.
38
+ */
39
+ export declare const scriptNames: (source: string, libraries: ReadonlyMap<string, string>, refuse: (reason: string) => never) => Names;
40
+ //#endregion
3
41
  //#region src/generated/builtin-docs.d.ts
4
42
  export declare const builtinDocs: Readonly<Record<string, {
5
43
  call: string;
6
44
  gives: string;
7
45
  }>>;
8
46
  //#endregion
9
- export { type DebugAction, type Envelope, MOCK_ARGUMENTS, type Mock, type ObjectReference, type ReplayOptions, type Replayed, type SessionEnvironment, SessionHost, SessionObjects, type Setup, type SourcePlacement, type TranscriptItem, type UserPrompt, type Waiting, parseEnvelope, parseTranscript, replayTranscript, writeTranscript };
47
+ export { type DebugAction, type Envelope, MOCK_ARGUMENTS, type Mock, type Names, type ObjectReference, type ReplayOptions, type Replayed, type SessionEnvironment, SessionHost, SessionObjects, type Setup, type SourcePlacement, type TranscriptItem, type UserPrompt, type Waiting, parseEnvelope, parseTranscript, replayTranscript, writeTranscript };