@lapxo/bound 0.1.8 → 0.2.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 (248) hide show
  1. package/README.md +56 -20
  2. package/TARGET.bound +70 -27
  3. package/assets/wasm/guest.js +4 -0
  4. package/assets/wasm/manifest.json +27 -0
  5. package/assets/wasm/runtime.js +6 -0
  6. package/assets/wasm/runtime.wasm +0 -0
  7. package/dist/cli/accept.js +83 -59
  8. package/dist/cli/act-result.d.ts +9 -0
  9. package/dist/cli/act-result.js +68 -13
  10. package/dist/cli/args.d.ts +1 -0
  11. package/dist/cli/args.js +5 -2
  12. package/dist/cli/custodian.d.ts +1 -0
  13. package/dist/cli/custodian.js +29 -0
  14. package/dist/cli/native-descendant.d.ts +1 -0
  15. package/dist/cli/native-descendant.js +19 -0
  16. package/dist/cli/native.d.ts +1 -0
  17. package/dist/cli/native.js +60 -0
  18. package/dist/cli/observe.js +9 -2
  19. package/dist/cli/pass.js +9 -4
  20. package/dist/cli/place.d.ts +2 -0
  21. package/dist/cli/place.js +7 -4
  22. package/dist/cli/standing-result.js +7 -26
  23. package/dist/cli/verb.js +65 -9
  24. package/dist/engine/index.d.ts +11 -0
  25. package/dist/engine/index.js +9 -0
  26. package/dist/engine/object.d.ts +17 -0
  27. package/dist/engine/object.js +38 -0
  28. package/dist/fold/admission-history.js +2 -2
  29. package/dist/fold/claims.d.ts +4 -0
  30. package/dist/fold/claims.js +23 -3
  31. package/dist/fold/closed.d.ts +1 -1
  32. package/dist/fold/closed.js +36 -7
  33. package/dist/fold/digests.d.ts +1 -1
  34. package/dist/fold/digests.js +6 -4
  35. package/dist/fold/evidence.d.ts +1 -1
  36. package/dist/fold/kept.js +2 -1
  37. package/dist/fold/object.d.ts +3 -17
  38. package/dist/fold/object.js +2 -38
  39. package/dist/fold/observed.d.ts +1 -0
  40. package/dist/fold/observed.js +54 -9
  41. package/dist/fold/readers.d.ts +4 -3
  42. package/dist/fold/readers.js +18 -13
  43. package/dist/fold/resolved.js +12 -2
  44. package/dist/fold/signers.js +2 -2
  45. package/dist/host/adapters/modules/javascript.d.ts +2 -0
  46. package/dist/host/adapters/modules/javascript.js +8 -6
  47. package/dist/host/admitted-place.d.ts +5 -0
  48. package/dist/host/admitted-place.js +57 -0
  49. package/dist/host/capsule-process.d.ts +1 -1
  50. package/dist/host/capsule-process.js +4 -1
  51. package/dist/host/capsule.d.ts +4 -0
  52. package/dist/host/capsule.js +16 -2
  53. package/dist/host/cell-receipts.js +1 -1
  54. package/dist/host/contextual-place.d.ts +59 -0
  55. package/dist/host/contextual-place.js +77 -0
  56. package/dist/host/hash.d.ts +7 -0
  57. package/dist/host/hash.js +6 -0
  58. package/dist/host/io.d.ts +2 -0
  59. package/dist/host/io.js +2 -0
  60. package/dist/host/lifetime.js +61 -22
  61. package/dist/host/native/bounded-file.d.ts +8 -0
  62. package/dist/host/native/bounded-file.js +32 -0
  63. package/dist/host/native/command.d.ts +36 -0
  64. package/dist/host/native/command.js +91 -0
  65. package/dist/host/native/control-bridge-worker.d.ts +1 -0
  66. package/dist/host/native/control-bridge-worker.js +88 -0
  67. package/dist/host/native/control-bridge.d.ts +30 -0
  68. package/dist/host/native/control-bridge.js +110 -0
  69. package/dist/host/native/control-selection.d.ts +29 -0
  70. package/dist/host/native/control-selection.js +32 -0
  71. package/dist/host/native/custody.d.ts +5 -0
  72. package/dist/host/native/custody.js +91 -0
  73. package/dist/host/native/deadline.d.ts +12 -0
  74. package/dist/host/native/deadline.js +28 -0
  75. package/dist/host/native/descendants.d.ts +1 -0
  76. package/dist/host/native/descendants.js +528 -0
  77. package/dist/host/native/generated-custodian.d.ts +122 -0
  78. package/dist/host/native/generated-custodian.js +267 -0
  79. package/dist/host/native/generated.d.ts +217 -0
  80. package/dist/host/native/generated.js +379 -0
  81. package/dist/host/native/image.d.ts +36 -0
  82. package/dist/host/native/image.js +45 -0
  83. package/dist/host/native/jobs.d.ts +75 -0
  84. package/dist/host/native/jobs.js +148 -0
  85. package/dist/host/native/loader.d.ts +80 -0
  86. package/dist/host/native/loader.js +269 -0
  87. package/dist/host/native/materialize.d.ts +22 -0
  88. package/dist/host/native/materialize.js +175 -0
  89. package/dist/host/native/module-closure.d.ts +27 -0
  90. package/dist/host/native/module-closure.js +99 -0
  91. package/dist/host/native/module-syntax.d.ts +8 -0
  92. package/dist/host/native/module-syntax.js +63 -0
  93. package/dist/host/native/native-binary.d.ts +54 -0
  94. package/dist/host/native/native-binary.js +115 -0
  95. package/dist/host/native/native-program.d.ts +56 -0
  96. package/dist/host/native/native-program.js +72 -0
  97. package/dist/host/native/node-jobs.d.ts +84 -0
  98. package/dist/host/native/node-jobs.js +187 -0
  99. package/dist/host/native/node-launch.d.ts +72 -0
  100. package/dist/host/native/node-launch.js +159 -0
  101. package/dist/host/native/preload.d.ts +1 -0
  102. package/dist/host/native/preload.js +45 -0
  103. package/dist/host/native/reading.d.ts +91 -0
  104. package/dist/host/native/reading.js +249 -0
  105. package/dist/host/native/receipt-environment.d.ts +3 -0
  106. package/dist/host/native/receipt-environment.js +41 -0
  107. package/dist/host/native/references.d.ts +5 -0
  108. package/dist/host/native/references.js +30 -0
  109. package/dist/host/native/root.d.ts +17 -0
  110. package/dist/host/native/root.js +37 -0
  111. package/dist/host/native/route.d.ts +66 -0
  112. package/dist/host/native/route.js +216 -0
  113. package/dist/host/native/runtime.d.ts +4 -0
  114. package/dist/host/native/runtime.js +9 -0
  115. package/dist/host/native-reader-context.d.ts +3 -0
  116. package/dist/host/native-reader-context.js +8 -0
  117. package/dist/host/objects.d.ts +2 -1
  118. package/dist/host/objects.js +24 -4
  119. package/dist/host/place-clock-selection.d.ts +55 -0
  120. package/dist/host/place-clock-selection.js +124 -0
  121. package/dist/host/ports/local-act.d.ts +10 -0
  122. package/dist/host/ports/local-act.js +78 -6
  123. package/dist/host/ports/place-act.d.ts +46 -0
  124. package/dist/host/ports/place-act.js +169 -0
  125. package/dist/host/process-lifetime.js +8 -3
  126. package/dist/host/provide.d.ts +25 -0
  127. package/dist/host/provide.js +115 -13
  128. package/dist/host/reading-closures.d.ts +17 -1
  129. package/dist/host/reading-closures.js +98 -18
  130. package/dist/host/reading-context.d.ts +29 -0
  131. package/dist/host/reading-context.js +53 -0
  132. package/dist/host/reference-authenticated.d.ts +28 -0
  133. package/dist/host/reference-authenticated.js +84 -0
  134. package/dist/host/reference-native.d.ts +10 -0
  135. package/dist/host/reference-native.js +50 -0
  136. package/dist/host/reference-profile.d.ts +23 -0
  137. package/dist/host/reference-profile.js +62 -0
  138. package/dist/host/reference.d.ts +6 -0
  139. package/dist/host/reference.js +24 -0
  140. package/dist/host/root-clock-source.d.ts +85 -0
  141. package/dist/host/root-clock-source.js +305 -0
  142. package/dist/host/selected-capsules.js +3 -2
  143. package/dist/host/selected-topos.d.ts +1 -1
  144. package/dist/host/selected-topos.js +9 -1
  145. package/dist/land/act.d.ts +26 -0
  146. package/dist/land/act.js +96 -3
  147. package/dist/land/ledger.d.ts +4 -0
  148. package/dist/land/ledger.js +20 -2
  149. package/dist/observe/regions.d.ts +4 -0
  150. package/dist/observe/regions.js +109 -1
  151. package/dist/observe/runner.d.ts +4 -0
  152. package/dist/observe/runner.js +9 -2
  153. package/dist/wasm/adapter.d.ts +51 -0
  154. package/dist/wasm/adapter.js +180 -0
  155. package/dist/wasm/node-worker.d.ts +1 -0
  156. package/dist/wasm/node-worker.js +13 -0
  157. package/dist/wasm/object.d.ts +8 -0
  158. package/dist/wasm/object.js +76 -0
  159. package/dist/wasm/worker.d.ts +1 -0
  160. package/dist/wasm/worker.js +7 -0
  161. package/docs/contracts/authenticated-reference.publication.json +25 -0
  162. package/docs/contracts/cli.md +13 -0
  163. package/docs/contracts/engine-object-projection.publication.json +25 -0
  164. package/docs/contracts/engine.md +39 -0
  165. package/docs/contracts/native-publication.inventory.json +8 -0
  166. package/docs/contracts/optional-wasm-adapter.publication.json +25 -0
  167. package/docs/contracts/publication-additions.inventory.json +8 -0
  168. package/docs/contracts/reference-port.md +33 -0
  169. package/docs/contracts/reference-port.publication.json +25 -0
  170. package/licenses/wasm/bound.txt +21 -0
  171. package/licenses/wasm/fast-text-encoding.txt +201 -0
  172. package/licenses/wasm/jitl-quickjs-ffi-types.txt +21 -0
  173. package/licenses/wasm/jitl-quickjs-wasmfile-release-sync.txt +47 -0
  174. package/licenses/wasm/obligations.txt +21 -0
  175. package/licenses/wasm/quickjs-emscripten-core.txt +21 -0
  176. package/licenses/wasm/topos.txt +21 -0
  177. package/package.json +94 -4
  178. package/receipts.bound +7672 -573
  179. package/samples/authenticated-reference/no.json +31 -0
  180. package/samples/authenticated-reference/yes/editorial-state/TARGET.bound +57 -0
  181. package/samples/authenticated-reference/yes/editorial-state/inputs/arrival.json +1 -0
  182. package/samples/authenticated-reference/yes/editorial-state/inputs/coverage.json +1 -0
  183. package/samples/authenticated-reference/yes/editorial-state/inputs/era.json +1 -0
  184. package/samples/authenticated-reference/yes/editorial-state/inputs/order.json +1 -0
  185. package/samples/authenticated-reference/yes/editorial-state/inputs/signature.json +1 -0
  186. package/samples/authenticated-reference/yes/editorial-state/inputs/transport.arrival.json +1 -0
  187. package/samples/authenticated-reference/yes/editorial-state/inputs/transport.coverage.json +1 -0
  188. package/samples/authenticated-reference/yes/editorial-state/inputs/transport.era.json +1 -0
  189. package/samples/authenticated-reference/yes/editorial-state/inputs/transport.order.json +1 -0
  190. package/samples/authenticated-reference/yes/editorial-state/inputs/transport.signature.json +1 -0
  191. package/samples/authenticated-reference/yes/editorial-state/inputs/transport.yes.json +1 -0
  192. package/samples/authenticated-reference/yes/editorial-state/inputs/yes.json +1 -0
  193. package/samples/authenticated-reference/yes/weather-reading/TARGET.bound +57 -0
  194. package/samples/authenticated-reference/yes/weather-reading/inputs/arrival.json +1 -0
  195. package/samples/authenticated-reference/yes/weather-reading/inputs/coverage.json +1 -0
  196. package/samples/authenticated-reference/yes/weather-reading/inputs/era.json +1 -0
  197. package/samples/authenticated-reference/yes/weather-reading/inputs/order.json +1 -0
  198. package/samples/authenticated-reference/yes/weather-reading/inputs/signature.json +1 -0
  199. package/samples/authenticated-reference/yes/weather-reading/inputs/transport.arrival.json +1 -0
  200. package/samples/authenticated-reference/yes/weather-reading/inputs/transport.coverage.json +1 -0
  201. package/samples/authenticated-reference/yes/weather-reading/inputs/transport.era.json +1 -0
  202. package/samples/authenticated-reference/yes/weather-reading/inputs/transport.order.json +1 -0
  203. package/samples/authenticated-reference/yes/weather-reading/inputs/transport.signature.json +1 -0
  204. package/samples/authenticated-reference/yes/weather-reading/inputs/transport.yes.json +1 -0
  205. package/samples/authenticated-reference/yes/weather-reading/inputs/yes.json +1 -0
  206. package/samples/authenticated-reference/yes.json +19 -0
  207. package/samples/engine-alphabet/TARGET.bound +29 -0
  208. package/samples/engine-alphabet/inputs/sample.json +323 -0
  209. package/samples/engine-alphabet/package.json +1 -0
  210. package/samples/engine-alphabet/reader.js +1457 -0
  211. package/samples/engine-alphabet/receipts.bound +12 -0
  212. package/samples/engine-interval/TARGET.bound +29 -0
  213. package/samples/engine-interval/inputs/sample.json +277 -0
  214. package/samples/engine-interval/package.json +1 -0
  215. package/samples/engine-interval/reader.js +1457 -0
  216. package/samples/engine-interval/receipts.bound +12 -0
  217. package/samples/no/engine-order/TARGET.bound +29 -0
  218. package/samples/no/engine-order/inputs/sample.json +277 -0
  219. package/samples/no/engine-order/package.json +1 -0
  220. package/samples/no/engine-order/reader.js +1457 -0
  221. package/samples/reference-port/no/catalog/standing.json +1 -0
  222. package/samples/reference-port/no/catalog/transport.json +1 -0
  223. package/samples/reference-port/no/route-notes/standing.json +1 -0
  224. package/samples/reference-port/no/route-notes/transport.json +1 -0
  225. package/samples/reference-port/yes/catalog/TARGET.bound +33 -0
  226. package/samples/reference-port/yes/catalog/standing.json +1 -0
  227. package/samples/reference-port/yes/catalog/transport.json +1 -0
  228. package/samples/reference-port/yes/route-notes/TARGET.bound +33 -0
  229. package/samples/reference-port/yes/route-notes/standing.json +1 -0
  230. package/samples/reference-port/yes/route-notes/transport.json +1 -0
  231. package/samples/wasm/editorial-notes/TARGET.bound +65 -0
  232. package/samples/wasm/editorial-notes/esm.bound +59 -0
  233. package/samples/wasm/editorial-notes/no-deadline.bound +65 -0
  234. package/samples/wasm/editorial-notes/no-memory.bound +65 -0
  235. package/samples/wasm/editorial-notes/no-missing-limit.bound +64 -0
  236. package/samples/wasm/editorial-notes/receipts.bound +1 -0
  237. package/samples/wasm/water-level/TARGET.bound +65 -0
  238. package/samples/wasm/water-level/esm.bound +59 -0
  239. package/samples/wasm/water-level/no-deadline.bound +65 -0
  240. package/samples/wasm/water-level/no-memory.bound +65 -0
  241. package/samples/wasm/water-level/no-missing-limit.bound +64 -0
  242. package/samples/wasm/water-level/receipts.bound +1 -0
  243. package/vectors/engine-object.cli.json +548 -0
  244. package/vectors/native/authenticated-reference-formation.vector.json +53 -0
  245. package/vectors/native/authenticated-reference.cli.json +157 -0
  246. package/vectors/native/authenticated-reference.vector.json +440 -0
  247. package/vectors/reference-port.cli.json +688 -0
  248. package/vectors/wasm-object.cli.json +452 -0
@@ -0,0 +1,1457 @@
1
+ // work/bound-0.1.9/repository/node_modules/@lapxo/topos/dist/wire/outcome.js
2
+ var fact = (value) => ({ kind: "fact", value });
3
+ var abstain = (why) => ({ kind: "abstain", why });
4
+ var refuse = (why, named) => ({ kind: "refuse", why, ...named === void 0 ? {} : { named } });
5
+
6
+ // work/bound-0.1.9/repository/node_modules/@lapxo/topos/dist/wire/values.js
7
+ function unpipe(value) {
8
+ const out = [];
9
+ let at = "";
10
+ for (let i = 0; i < value.length; i++) {
11
+ const c = value[i];
12
+ if (c === "\\") {
13
+ const next = value[i + 1];
14
+ if (next !== "|" && next !== "\\")
15
+ return null;
16
+ at += next;
17
+ i += 1;
18
+ } else if (c === "|") {
19
+ out.push(at);
20
+ at = "";
21
+ } else {
22
+ at += c;
23
+ }
24
+ }
25
+ out.push(at);
26
+ return out;
27
+ }
28
+ var OPEN = "*";
29
+ var num = (s) => {
30
+ if (!/^-?\d+(\.\d+)?$/.test(s))
31
+ return null;
32
+ const n = Number(s);
33
+ return isFinite(n) ? n : null;
34
+ };
35
+ function decimal(n) {
36
+ if (!isFinite(n))
37
+ throw new Error(`REFUSE\xB7wire decimal: \`${n}\` is not a finite number`);
38
+ const got = /^(-?)(\d)(?:\.(\d+))?e([+-])(\d+)$/.exec(String(n));
39
+ if (got === null)
40
+ return String(n);
41
+ const [, sign2 = "", lead = "", rest = "", ahead = "", exp = "0"] = got;
42
+ return ahead === "+" ? `${sign2}${lead}${rest}${"0".repeat(Number(exp) - rest.length)}` : `${sign2}0.${"0".repeat(Number(exp) - 1)}${lead}${rest}`;
43
+ }
44
+ var GRAMMARS = {
45
+ interval: (value) => {
46
+ const at = value.indexOf("..");
47
+ if (at < 0)
48
+ return null;
49
+ const lo = value.slice(0, at);
50
+ const hi = value.slice(at + 2);
51
+ const l = lo === OPEN ? null : num(lo);
52
+ const h = hi === OPEN ? null : num(hi);
53
+ if (lo !== OPEN && l === null || hi !== OPEN && h === null)
54
+ return null;
55
+ return { kind: "interval", lo: l, hi: h };
56
+ },
57
+ alphabet: (value) => {
58
+ const values = unpipe(value);
59
+ return values === null ? null : { kind: "enumerated", values };
60
+ },
61
+ ladder: (value) => {
62
+ const parts2 = unpipe(value);
63
+ if (parts2 === null || parts2.length !== 2)
64
+ return null;
65
+ return { kind: "band", floor: parts2[0] ?? "", ceiling: parts2[1] ?? "" };
66
+ }
67
+ };
68
+ function boundOf(form2, value, grammars) {
69
+ const extra = Array.isArray(grammars) ? grammars.find((g) => g.form === form2) : void 0;
70
+ if (extra)
71
+ return extra.parse(value);
72
+ return GRAMMARS[form2]?.(value) ?? null;
73
+ }
74
+ var BOUND_FORMS = Object.keys(GRAMMARS);
75
+ var REF_RELATIONS = ["within", "copies", "derives"];
76
+
77
+ // work/bound-0.1.9/repository/node_modules/@lapxo/topos/dist/wire/line.js
78
+ var PROTOCOL = "bound-lock/1";
79
+ var NEEDS_QUOTE = /[ ="\n\\]/;
80
+ function escape(value) {
81
+ if (!NEEDS_QUOTE.test(value))
82
+ return value;
83
+ return `"${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n")}"`;
84
+ }
85
+ function unescape(token) {
86
+ if (!token.startsWith('"'))
87
+ return NEEDS_QUOTE.test(token) ? null : token;
88
+ if (token.length < 2 || !token.endsWith('"'))
89
+ return null;
90
+ const body = token.slice(1, -1);
91
+ let out = "";
92
+ for (let i = 0; i < body.length; i++) {
93
+ const c = body[i];
94
+ if (c !== "\\") {
95
+ if (c === '"')
96
+ return null;
97
+ out += c;
98
+ continue;
99
+ }
100
+ const next = body[i + 1];
101
+ if (next === '"')
102
+ out += '"';
103
+ else if (next === "\\")
104
+ out += "\\";
105
+ else if (next === "n")
106
+ out += "\n";
107
+ else
108
+ return null;
109
+ i += 1;
110
+ }
111
+ return out;
112
+ }
113
+ var UTF8 = new TextEncoder();
114
+ function byBytes(a, b) {
115
+ const x = UTF8.encode(a);
116
+ const y = UTF8.encode(b);
117
+ for (let i = 0; i < x.length && i < y.length; i++) {
118
+ if (x[i] !== y[i])
119
+ return x[i] - y[i];
120
+ }
121
+ return x.length - y.length;
122
+ }
123
+ var unwritten = (fields) => fields["form"] === "interval" && fields["value"] !== void 0 && fields["value"] !== "withdraw" && boundOf("interval", fields["value"]) === null;
124
+ function canonical(fields, version = "1") {
125
+ if (unwritten(fields))
126
+ throw new Error(`REFUSE\xB7wire canonical: \`${fields["value"]}\` is no interval the wire writes: two ends, each decimal or *`);
127
+ const keys = Object.keys(fields).sort(byBytes);
128
+ const tokens = keys.map((k) => `${k}=${escape(fields[k])}`);
129
+ return [`${PROTOCOL.split("/")[0]}/${version}`, ...tokens].join(" ");
130
+ }
131
+ var ABSENT = "-";
132
+ function parse(text, options = {}) {
133
+ if (text.includes("\n")) {
134
+ return refuse("a line is one line \u2014 a newline in a value must be escaped as `\\n`");
135
+ }
136
+ const space = text.indexOf(" ");
137
+ const envelope = space === -1 ? text : text.slice(0, space);
138
+ const [name, version] = envelope.split("/");
139
+ if (name !== PROTOCOL.split("/")[0] || !version) {
140
+ return refuse(`no \`bound-lock/<v>\` envelope \u2014 found \`${envelope.slice(0, 24)}\``);
141
+ }
142
+ if (version !== PROTOCOL.split("/")[1]) {
143
+ return abstain(`\`bound-lock/${version}\` is a version this reader does not know`);
144
+ }
145
+ const fields = {};
146
+ const writtenKeys = /* @__PURE__ */ new Set();
147
+ for (const token of tokensOf(space === -1 ? "" : text.slice(space + 1))) {
148
+ if (token === null)
149
+ return refuse("a quoted value is not closed");
150
+ const at = token.indexOf("=");
151
+ if (at <= 0)
152
+ return refuse(`\`${token.slice(0, 24)}\` is not \`key=value\``);
153
+ const key = token.slice(0, at);
154
+ if (writtenKeys.has(key))
155
+ return refuse(`\`${key}\` appears twice \u2014 one line, one value per key`);
156
+ writtenKeys.add(key);
157
+ const value = unescape(token.slice(at + 1));
158
+ if (value === null)
159
+ return refuse(`\`${key}\` has an escaping this format does not define`);
160
+ if (value !== ABSENT)
161
+ fields[key] = value;
162
+ }
163
+ if (unwritten(fields))
164
+ return refuse(`\`${fields["value"]}\` is no interval the wire reads: two ends, each decimal or *`);
165
+ return fact({ version, fields, ...options.preserveKeys ? { keys: [...writtenKeys] } : {} });
166
+ }
167
+ function* tokensOf(rest) {
168
+ let at = 0;
169
+ while (at < rest.length) {
170
+ while (rest[at] === " ")
171
+ at += 1;
172
+ if (at >= rest.length)
173
+ return;
174
+ let end = at;
175
+ let quoted = false;
176
+ while (end < rest.length && (quoted || rest[end] !== " ")) {
177
+ if (rest[end] === "\\" && quoted)
178
+ end += 1;
179
+ else if (rest[end] === '"')
180
+ quoted = !quoted;
181
+ end += 1;
182
+ }
183
+ if (quoted) {
184
+ yield null;
185
+ return;
186
+ }
187
+ yield rest.slice(at, end);
188
+ at = end;
189
+ }
190
+ }
191
+
192
+ // work/bound-0.1.9/repository/node_modules/@lapxo/topos/dist/wire/grammar.js
193
+ var [FORBID, EMPTY, MEMBER, PAIR, STEP, AT, EVERY, ESCAPE] = ["not:", "none", "|", "=", "/", "@", "*", "\\"];
194
+ var refuse2 = (grammar, why) => {
195
+ throw new Error(`REFUSE\xB7wire ${grammar}: ${why}`);
196
+ };
197
+ function alphabet(given) {
198
+ if (typeof given !== "string") {
199
+ const written2 = given.members.map((one) => one.split(ESCAPE).join(ESCAPE + ESCAPE).split(MEMBER).join(ESCAPE + MEMBER)).join(MEMBER);
200
+ if (given.polarity === "forbid")
201
+ return FORBID + written2;
202
+ return written2.startsWith(FORBID) || written2 === EMPTY ? refuse2("alphabet", "a permitted alphabet neither begins with not: nor is the one word none") : written2 || EMPTY;
203
+ }
204
+ const forbid = given.startsWith(FORBID);
205
+ const body = forbid ? given.slice(FORBID.length) : given;
206
+ const members = !forbid && body === EMPTY ? [] : unpipe(body) ?? refuse2("alphabet", "a backslash escapes only a pipe or itself");
207
+ return { polarity: forbid ? "forbid" : "permit", members: members.filter((one) => one !== "") };
208
+ }
209
+
210
+ // work/bound-0.1.9/repository/node_modules/@lapxo/obligations/dist/lattice/errors.js
211
+ var UnitError = class _UnitError extends Error {
212
+ code;
213
+ detail;
214
+ constructor(code, message, detail = {}) {
215
+ super(message);
216
+ this.name = "UnitError";
217
+ this.code = code;
218
+ this.detail = Object.freeze({ ...detail });
219
+ Object.setPrototypeOf(this, _UnitError.prototype);
220
+ }
221
+ };
222
+
223
+ // work/bound-0.1.9/repository/node_modules/@lapxo/obligations/dist/lattice/order.js
224
+ function build(levels, join2, meet) {
225
+ const n = levels.length;
226
+ for (let i = 0; i < n; i++) {
227
+ if (levels.indexOf(levels[i]) !== i) {
228
+ throw new UnitError("DUPLICATE_LEVEL", `the level \`${levels[i]}\` is declared twice`, {
229
+ level: levels[i]
230
+ });
231
+ }
232
+ }
233
+ const index = new Map(levels.map((l, i) => [l, i]));
234
+ const leq = (a, b) => join2[a][b] === b;
235
+ const total = levels.every((_, i) => levels.every((__, j) => join2[i][j] === i || join2[i][j] === j));
236
+ let simple = true;
237
+ for (let x = 0; x < n && simple; x++) {
238
+ for (let y = 0; y < n && simple; y++) {
239
+ for (let z = 0; z < n; z++) {
240
+ if (meet[x][join2[y][z]] !== join2[meet[x][y]][meet[x][z]]) {
241
+ simple = false;
242
+ break;
243
+ }
244
+ }
245
+ }
246
+ }
247
+ const all = [...levels.keys()];
248
+ const bottomIx = all.find((i) => all.every((j) => leq(i, j))) ?? 0;
249
+ const topIx = all.find((i) => all.every((j) => leq(j, i))) ?? n - 1;
250
+ const joinIrr = all.filter((j) => j !== bottomIx && all.filter((x) => x !== j && leq(x, j)).reduce((acc, x) => join2[acc][x], bottomIx) !== j);
251
+ const meetIrr = all.filter((m) => m !== topIx && all.filter((x) => x !== m && leq(m, x)).reduce((acc, x) => meet[acc][x], topIx) !== m);
252
+ const seen = /* @__PURE__ */ new Set();
253
+ const allDebits = [];
254
+ for (const x of [...joinIrr, ...meetIrr]) {
255
+ if (!seen.has(x)) {
256
+ seen.add(x);
257
+ allDebits.push(x);
258
+ }
259
+ }
260
+ return {
261
+ levels,
262
+ isLadder: total,
263
+ isSimple: simple,
264
+ bottomIx,
265
+ topIx,
266
+ bottom: levels[bottomIx],
267
+ top: levels[topIx],
268
+ leq,
269
+ higher: (a, b) => join2[a][b],
270
+ lower: (a, b) => meet[a][b],
271
+ rank(level) {
272
+ const r = index.get(level);
273
+ if (r === void 0) {
274
+ throw new UnitError("UNKNOWN_LEVEL", `no level \`${level}\` in this scale`, {
275
+ level,
276
+ levels
277
+ });
278
+ }
279
+ return r;
280
+ },
281
+ stateOf(floor, ceiling) {
282
+ if (!leq(floor, ceiling))
283
+ return "CONFLICT";
284
+ if (floor !== bottomIx)
285
+ return "REQUIRED";
286
+ if (ceiling !== topIx)
287
+ return "FORBIDDEN";
288
+ return "FREE";
289
+ },
290
+ joins: () => joinIrr.slice(),
291
+ limits: () => meetIrr.slice(),
292
+ debits: () => allDebits.slice(),
293
+ intervalHeight(lo, hi) {
294
+ if (!leq(lo, hi))
295
+ return null;
296
+ const inside = all.filter((x) => leq(lo, x) && leq(x, hi));
297
+ const covers = (x) => inside.filter((y) => y !== x && leq(x, y) && !inside.some((z) => z !== x && z !== y && leq(x, z) && leq(z, y)));
298
+ const long = /* @__PURE__ */ new Map([[lo, 0]]);
299
+ const short = /* @__PURE__ */ new Map([[lo, 0]]);
300
+ const walk = [...inside].sort((a, b) => inside.filter((z) => leq(z, a)).length - inside.filter((z) => leq(z, b)).length);
301
+ for (const x of walk) {
302
+ const lx = long.get(x);
303
+ const sx = short.get(x);
304
+ if (lx === void 0 || sx === void 0)
305
+ continue;
306
+ for (const y of covers(x)) {
307
+ long.set(y, Math.max(long.get(y) ?? lx + 1, lx + 1));
308
+ short.set(y, Math.min(short.get(y) ?? sx + 1, sx + 1));
309
+ }
310
+ }
311
+ const l = long.get(hi);
312
+ return l !== void 0 && l === short.get(hi) ? l : null;
313
+ }
314
+ };
315
+ }
316
+ function chain(levels) {
317
+ if (!Array.isArray(levels) || levels.length === 0) {
318
+ throw new UnitError("EMPTY_CHAIN", "a chain needs at least one level");
319
+ }
320
+ const n = levels.length;
321
+ const grid = (f) => [...Array(n)].map((_, i) => [...Array(n)].map((__, j) => f(i, j)));
322
+ return build(levels, grid(Math.max), grid(Math.min));
323
+ }
324
+ function order(levels, leq) {
325
+ if (!Array.isArray(levels) || levels.length === 0) {
326
+ throw new UnitError("EMPTY_CHAIN", "an order needs at least one level");
327
+ }
328
+ const n = levels.length;
329
+ const bound = (a, b, up) => {
330
+ const bs = [...Array(n).keys()].filter((x) => up ? leq[a][x] && leq[b][x] : leq[x][a] && leq[x][b]);
331
+ const least = bs.filter((x) => bs.every((y) => up ? leq[x][y] : leq[y][x]));
332
+ if (least.length !== 1) {
333
+ throw new UnitError("MALFORMED", `\`${levels[a]}\` and \`${levels[b]}\` have ${least.length} ${up ? "lowest common" : "highest common"} bounds, so this is not a usable scale`, { levels: [levels[a], levels[b]] });
334
+ }
335
+ return least[0];
336
+ };
337
+ const grid = (up) => [...Array(n)].map((_, i) => [...Array(n)].map((__, j) => bound(i, j, up)));
338
+ return build(levels, grid(true), grid(false));
339
+ }
340
+
341
+ // work/bound-0.1.9/repository/node_modules/@lapxo/obligations/dist/debit/unit.js
342
+ function unit(subject, bounds) {
343
+ return { subject, floor: bounds.floor, ceiling: bounds.ceiling };
344
+ }
345
+ var permitAll = (c, subject) => unit(subject, { floor: c.bottom, ceiling: c.top });
346
+ function state(c, u) {
347
+ return c.stateOf(c.rank(u.floor), c.rank(u.ceiling));
348
+ }
349
+ function band(c, units, from, onFloor, onCeiling) {
350
+ let floor = from.floor;
351
+ let ceiling = from.ceiling;
352
+ for (const u of units) {
353
+ floor = onFloor(floor, c.rank(u.floor));
354
+ ceiling = onCeiling(ceiling, c.rank(u.ceiling));
355
+ }
356
+ return { subject: units[0].subject, floor: c.levels[floor], ceiling: c.levels[ceiling] };
357
+ }
358
+ function fuse(c, units) {
359
+ if (units.length === 0)
360
+ return permitAll(c, "");
361
+ return band(c, units, { floor: c.bottomIx, ceiling: c.topIx }, (a, b) => c.higher(a, b), (a, b) => c.lower(a, b));
362
+ }
363
+ function entails(c, a, b) {
364
+ const [af, ac] = [c.rank(a.floor), c.rank(a.ceiling)];
365
+ const [bf, bc] = [c.rank(b.floor), c.rank(b.ceiling)];
366
+ return c.leq(bf, af) && c.leq(ac, bc);
367
+ }
368
+
369
+ // work/bound-0.1.9/repository/node_modules/@lapxo/obligations/dist/debit/packed.js
370
+ var WIDTH = 32;
371
+
372
+ // work/bound-0.1.9/repository/node_modules/@lapxo/obligations/dist/debit/masks.js
373
+ function chunkCount(n) {
374
+ if (n <= 0)
375
+ return 0;
376
+ return Math.ceil(n / WIDTH);
377
+ }
378
+ var WideMask = class _WideMask {
379
+ words;
380
+ width;
381
+ constructor(width, words) {
382
+ this.width = width;
383
+ this.words = words ?? new Uint32Array(chunkCount(width));
384
+ }
385
+ static fromTokens(tokens, allowed) {
386
+ const m = new _WideMask(tokens.length);
387
+ tokens.forEach((t, i) => {
388
+ if (allowed.has(t))
389
+ m.set(i);
390
+ });
391
+ return m;
392
+ }
393
+ set(bit) {
394
+ if (bit < 0 || bit >= this.width) {
395
+ throw new UnitError("MALFORMED", `bit ${bit} is outside a mask of width ${this.width}`, {
396
+ bit,
397
+ width: this.width
398
+ });
399
+ }
400
+ this.words[bit >> 5] |= 1 << (bit & 31);
401
+ }
402
+ has(bit) {
403
+ if (bit < 0 || bit >= this.width)
404
+ return false;
405
+ return (this.words[bit >> 5] & 1 << (bit & 31)) !== 0;
406
+ }
407
+ and(other) {
408
+ const w = Math.max(this.width, other.width);
409
+ const out = new _WideMask(w);
410
+ const n = Math.min(this.words.length, other.words.length);
411
+ for (let i = 0; i < n; i++)
412
+ out.words[i] = this.words[i] & other.words[i];
413
+ return out;
414
+ }
415
+ or(other) {
416
+ const w = Math.max(this.width, other.width);
417
+ const out = new _WideMask(w);
418
+ for (let i = 0; i < out.words.length; i++) {
419
+ out.words[i] = (this.words[i] ?? 0) | (other.words[i] ?? 0);
420
+ }
421
+ return out;
422
+ }
423
+ difference(other) {
424
+ const w = Math.max(this.width, other.width);
425
+ const out = new _WideMask(w);
426
+ for (let i = 0; i < out.words.length; i++) {
427
+ out.words[i] = (this.words[i] ?? 0) & ~(other.words[i] ?? 0);
428
+ }
429
+ const spare = w % 32;
430
+ if (spare !== 0 && out.words.length > 0) {
431
+ out.words[out.words.length - 1] &= (1 << spare) - 1;
432
+ }
433
+ return out;
434
+ }
435
+ subsetOf(other) {
436
+ const n = Math.max(this.words.length, other.words.length);
437
+ for (let i = 0; i < n; i++) {
438
+ const a = this.words[i] ?? 0;
439
+ const b = other.words[i] ?? 0;
440
+ if ((a & ~b) !== 0)
441
+ return false;
442
+ }
443
+ return true;
444
+ }
445
+ size() {
446
+ let n = 0;
447
+ for (let i = 0; i < this.width; i++)
448
+ if (this.has(i))
449
+ n++;
450
+ return n;
451
+ }
452
+ members(tokens) {
453
+ return tokens.filter((_, i) => this.has(i));
454
+ }
455
+ static filled(width) {
456
+ const m = new _WideMask(width);
457
+ if (width <= 0)
458
+ return m;
459
+ m.words.fill(4294967295);
460
+ const spare = width % 32;
461
+ if (spare !== 0)
462
+ m.words[m.words.length - 1] = (1 << spare) - 1;
463
+ return m;
464
+ }
465
+ };
466
+
467
+ // work/bound-0.1.9/repository/node_modules/@lapxo/obligations/dist/lattice/scale-lattice.js
468
+ function fromScale(c) {
469
+ const inhabited = (x) => state(c, x) !== "CONFLICT";
470
+ return {
471
+ top: permitAll(c, ""),
472
+ bottom: { subject: "", floor: c.levels[c.topIx] ?? "", ceiling: c.levels[c.bottomIx] ?? "" },
473
+ leq: (a, b) => entails(c, a, b),
474
+ meet: (a, b) => fuse(c, [a, b]),
475
+ join: (a, b) => {
476
+ if (!inhabited(a))
477
+ return b;
478
+ if (!inhabited(b))
479
+ return a;
480
+ return {
481
+ subject: a.subject || b.subject,
482
+ floor: c.levels[c.lower(c.rank(a.floor), c.rank(b.floor))] ?? a.floor,
483
+ ceiling: c.levels[c.higher(c.rank(a.ceiling), c.rank(b.ceiling))] ?? a.ceiling
484
+ };
485
+ },
486
+ show: (x) => `[${x.floor}, ${x.ceiling}]`,
487
+ inhabited
488
+ };
489
+ }
490
+ function subsets(tokens) {
491
+ return {
492
+ bottom: new WideMask(tokens.length),
493
+ top: WideMask.filled(tokens.length),
494
+ leq: (a, b) => a.subsetOf(b),
495
+ meet: (a, b) => a.and(b),
496
+ join: (a, b) => a.or(b),
497
+ show: (x) => x.members(tokens).join(","),
498
+ inhabited: (x) => x.size() > 0
499
+ };
500
+ }
501
+
502
+ // work/bound-0.1.9/repository/node_modules/@lapxo/obligations/dist/lattice/forms.js
503
+ function intervals(lo, hi) {
504
+ const low = Math.min(lo, hi);
505
+ const high = Math.max(lo, hi);
506
+ return {
507
+ bottom: { lo: high, hi: low },
508
+ top: { lo: low, hi: high },
509
+ leq(a, b) {
510
+ if (a.lo > a.hi)
511
+ return true;
512
+ if (b.lo > b.hi)
513
+ return false;
514
+ return b.lo <= a.lo && a.hi <= b.hi;
515
+ },
516
+ meet(a, b) {
517
+ return { lo: Math.max(a.lo, b.lo), hi: Math.min(a.hi, b.hi) };
518
+ },
519
+ join(a, b) {
520
+ if (a.lo > a.hi)
521
+ return b;
522
+ if (b.lo > b.hi)
523
+ return a;
524
+ return { lo: Math.min(a.lo, b.lo), hi: Math.max(a.hi, b.hi) };
525
+ },
526
+ show(x) {
527
+ return x.lo > x.hi ? "empty" : `${x.lo}..${x.hi}`;
528
+ },
529
+ inhabited(x) {
530
+ return x.lo <= x.hi;
531
+ }
532
+ };
533
+ }
534
+ function form(f) {
535
+ const held = { lattice: f.lattice, parse: f.parse, emit: f.emit, count: f.count, show: f.show, points: f.points };
536
+ const lacking = Object.entries(held).find(([, fn]) => typeof fn !== "function");
537
+ if (lacking)
538
+ throw new Error(`form \`${f.id}\` declared no ${lacking[0]}`);
539
+ return f;
540
+ }
541
+ var rec = (x) => x !== null && typeof x === "object" ? x : {};
542
+ function strings(x) {
543
+ return Array.isArray(x) ? x.map(String) : [];
544
+ }
545
+ var drawn = (seed) => {
546
+ let s = seed >>> 0;
547
+ return () => {
548
+ s = s + 1831565813 >>> 0;
549
+ let t = Math.imul(s ^ s >>> 15, s | 1);
550
+ t ^= t + Math.imul(t ^ t >>> 7, t | 61);
551
+ return ((t ^ t >>> 14) >>> 0) / 4294967296;
552
+ };
553
+ };
554
+ var picked = (draw, xs) => xs[Math.floor(draw() * xs.length)];
555
+ function bandCount(levels, folded) {
556
+ if (levels.length === 0)
557
+ return { kind: "refused", why: "a ladder with no levels cannot be counted" };
558
+ const c = chain(levels);
559
+ const f = c.rank(folded.floor);
560
+ const cl = c.rank(folded.ceiling);
561
+ if (!c.leq(f, cl))
562
+ return { kind: "finite", n: 0 };
563
+ const n = levels.filter((_, i) => c.leq(f, i) && c.leq(i, cl)).length;
564
+ return { kind: "finite", n };
565
+ }
566
+ var BAND = {
567
+ parse(params, demand) {
568
+ const L = this.lattice(params);
569
+ const d = rec(demand);
570
+ return {
571
+ subject: String(d.subject ?? ""),
572
+ floor: String(d.floor ?? L.top.floor),
573
+ ceiling: String(d.ceiling ?? L.top.ceiling)
574
+ };
575
+ },
576
+ emit(_params, value) {
577
+ return { subject: value.subject, floor: value.floor, ceiling: value.ceiling };
578
+ },
579
+ count(folded, params) {
580
+ return bandCount(strings(rec(params).levels), folded);
581
+ },
582
+ points(params, seed, n) {
583
+ const L = this.lattice(params);
584
+ const levels = strings(rec(params).levels);
585
+ const draw = drawn(seed);
586
+ const band2 = (floor, ceiling) => ({ subject: "", floor, ceiling });
587
+ return Array.from({ length: n }, () => {
588
+ const [a, b] = [picked(draw, levels), picked(draw, levels)];
589
+ return [band2(a, b), band2(b, a)].find((x) => L.inhabited(x)) ?? band2(a, a);
590
+ });
591
+ }
592
+ };
593
+ var ladderForm = form({
594
+ id: "ladder",
595
+ lattice(params) {
596
+ const levels = strings(rec(params).levels);
597
+ if (levels.length === 0)
598
+ throw new Error("ladder needs levels");
599
+ return fromScale(chain(levels));
600
+ },
601
+ ...BAND,
602
+ show(value) {
603
+ return value.floor === value.ceiling ? value.floor : `${value.floor}..${value.ceiling}`;
604
+ }
605
+ });
606
+ var alphabetForm = form({
607
+ id: "alphabet",
608
+ lattice(params) {
609
+ return subsets(strings(rec(params).tokens));
610
+ },
611
+ parse(params, demand) {
612
+ const tokens = strings(rec(params).tokens);
613
+ const d = rec(demand);
614
+ const want = d.want !== void 0 ? strings(d.want) : tokens;
615
+ return WideMask.fromTokens(tokens, new Set(want));
616
+ },
617
+ emit(params, value) {
618
+ return { want: value.members(strings(rec(params).tokens)) };
619
+ },
620
+ count(folded) {
621
+ return { kind: "finite", n: folded.size() };
622
+ },
623
+ show(value) {
624
+ return `${value.size()}`;
625
+ },
626
+ points(params, seed, n) {
627
+ const tokens = strings(rec(params).tokens);
628
+ const draw = drawn(seed);
629
+ return Array.from({ length: n }, () => WideMask.fromTokens(tokens, new Set(tokens.filter(() => draw() < 0.5))));
630
+ }
631
+ });
632
+ var continuousForm = form({
633
+ id: "continuous",
634
+ lattice(params) {
635
+ const p = rec(params);
636
+ return intervals(Number(p.lo ?? 0), Number(p.hi ?? 1));
637
+ },
638
+ parse(params, demand) {
639
+ const L = this.lattice(params);
640
+ const d = rec(demand);
641
+ return {
642
+ lo: d.lo === void 0 ? L.top.lo : Number(d.lo),
643
+ hi: d.hi === void 0 ? L.top.hi : Number(d.hi)
644
+ };
645
+ },
646
+ emit(_params, value) {
647
+ return { lo: value.lo, hi: value.hi };
648
+ },
649
+ count() {
650
+ return { kind: "refused", why: "a continuous band has no count; prefer not to exist over inventing one" };
651
+ },
652
+ show(value) {
653
+ return value.lo > value.hi ? "empty" : `${value.lo}..${value.hi}`;
654
+ },
655
+ points(params, seed, n) {
656
+ const p = rec(params);
657
+ const lo = Number(p.lo ?? 0);
658
+ const hi = Number(p.hi ?? 1);
659
+ const draw = drawn(seed);
660
+ const at = () => lo + Math.round(draw() * (hi - lo));
661
+ return Array.from({ length: n }, () => ({ lo: at(), hi: at() }));
662
+ }
663
+ });
664
+ var latticeForm = form({
665
+ id: "lattice",
666
+ lattice(params) {
667
+ const p = rec(params);
668
+ const levels = strings(p.levels);
669
+ const leq = p.leq;
670
+ if (levels.length && leq)
671
+ return fromScale(order(levels, leq));
672
+ throw new Error("lattice needs levels+leq");
673
+ },
674
+ ...BAND,
675
+ show(value) {
676
+ return `${value.floor}..${value.ceiling}`;
677
+ }
678
+ });
679
+ var FORM_IMPLEMENTATIONS = [ladderForm, alphabetForm, continuousForm, latticeForm];
680
+ var FORMS = [...FORM_IMPLEMENTATIONS];
681
+
682
+ // work/bound-0.1.9/repository/node_modules/@lapxo/obligations/dist/field/field.js
683
+ function coordinate(name, steps = "/") {
684
+ const at = name.split(new RegExp(`[${steps.replace(/[.*+?^${}()|[\]\\-]/g, "\\$&")}]`)).filter((s) => s !== "");
685
+ while (at[at.length - 1] === "*" || at[at.length - 1] === "**")
686
+ at.pop();
687
+ return at;
688
+ }
689
+
690
+ // work/bound-0.1.9/repository/node_modules/@lapxo/obligations/dist/lattice/obligatory.js
691
+ function cell(at, epoch = 0, seen = [], restsOn = []) {
692
+ return { at: coordinate(at), epoch, seen, restsOn };
693
+ }
694
+ function mark(one) {
695
+ if (one.widens !== void 0 && one.reach === "travels") {
696
+ throw new UnitError("widening-travels", "obligations: REFUSE\xB7widening-travels a widening stands where it was witnessed and never travels to what rests there", { pole: one.pole });
697
+ }
698
+ return one.takes === void 0 ? one : { ...one, sign: -1 };
699
+ }
700
+ function live(lines) {
701
+ const taken = new Set(lines.flatMap((line) => line.takes === void 0 ? [] : [line.takes]));
702
+ return lines.filter((line) => line.takes === void 0 && (line.id === void 0 || !taken.has(line.id)));
703
+ }
704
+ function restOf(c, world = /* @__PURE__ */ new Map()) {
705
+ const own = c.at.join("/");
706
+ const out = [];
707
+ const held = /* @__PURE__ */ new Set();
708
+ const edge = [...c.restsOn];
709
+ for (let i = 0; i < edge.length; i += 1) {
710
+ const name = edge[i];
711
+ if (name === own)
712
+ throw new UnitError("rest-cycle", `obligations: REFUSE\xB7rest ${own} rests on itself: an order of rest with a cycle has no fold to reach`, { at: own });
713
+ if (held.has(name))
714
+ continue;
715
+ held.add(name);
716
+ out.push(name);
717
+ edge.push(...world.get(name)?.restsOn ?? []);
718
+ }
719
+ return out;
720
+ }
721
+ function parts(L, c, world = /* @__PURE__ */ new Map()) {
722
+ const rest = restOf(c, world);
723
+ const above = rest.flatMap((name) => live(world.get(name)?.marks ?? []).filter((one) => one.reach === "travels" && one.widens === void 0));
724
+ const marks = [...live(c.marks ?? []), ...above].sort((a, b) => (a.at ?? 0) - (b.at ?? 0));
725
+ let required = L.top;
726
+ let signed = L.top;
727
+ for (const one of marks) {
728
+ if (one.pole === "floor")
729
+ required = L.meet(required, one.span);
730
+ else
731
+ signed = one.widens === void 0 ? L.meet(signed, one.span) : L.join(signed, one.span);
732
+ }
733
+ const origins = live(c.seen);
734
+ const held = origins.reduce((acc, claim) => L.meet(acc, claim.span), L.top);
735
+ return { floor: L.meet(required, held), ceiling: L.meet(signed, held), origins, rest, required, signed };
736
+ }
737
+ function state2(L, c, world = /* @__PURE__ */ new Map()) {
738
+ const { floor, ceiling, origins, required, signed } = parts(L, c, world);
739
+ if (!L.inhabited(L.meet(required, signed)))
740
+ return "CONFLICT";
741
+ if (new Set(origins.map((claim) => claim.origin)).size < 2)
742
+ return "REQUIRED";
743
+ if (!L.inhabited(origins.reduce((acc, claim) => L.meet(acc, claim.span), L.top)))
744
+ return "CONFLICT";
745
+ return L.inhabited(L.meet(floor, ceiling)) ? "FREE" : "FORBIDDEN";
746
+ }
747
+
748
+ // work/bound-0.1.9/repository/node_modules/@lapxo/topos/dist/wire/object-record.js
749
+ function coordinateText(value) {
750
+ return value !== "" && !/[\s\\|]/.test(value) && value.split("/").every((s) => s !== "" && s !== "." && s !== ".." && s !== "*" && s !== "**");
751
+ }
752
+ function restCoordinates(text) {
753
+ try {
754
+ const read = alphabet(text);
755
+ if (read.polarity !== "permit" || read.members.some((one) => !coordinateText(one)))
756
+ return void 0;
757
+ const sorted = [...new Set(read.members)].sort(byBytes);
758
+ if (alphabet({ polarity: "permit", members: sorted }) !== text)
759
+ return void 0;
760
+ return sorted;
761
+ } catch {
762
+ return void 0;
763
+ }
764
+ }
765
+ var COMMON = ["type", "scope", "id", "epoch", "by", "sig"];
766
+ function objectFromFields(fields, keys, schema, globalFields, forms) {
767
+ const bad = (why, key) => refuse(why, key);
768
+ if (keys.includes("at"))
769
+ return bad("object records carry no at: order is epoch and a local join witness is widens", "at");
770
+ const type = fields.type;
771
+ if (!schema.types.has(type ?? "") || !["cell", "claim", "mark"].includes(type ?? ""))
772
+ return bad("an object record names a declared type: cell, claim or mark", "type");
773
+ if (!/^(0|[1-9][0-9]*)$/.test(fields.epoch ?? "") || !Number.isSafeInteger(Number(fields.epoch)))
774
+ return bad("an object record carries an exactly supported logical epoch", "epoch");
775
+ if (Number(fields.epoch) < schema.activation)
776
+ return bad(`an object epoch precedes typed-wire activation ${schema.activation}`, "epoch");
777
+ let row;
778
+ if (type === "cell")
779
+ row = "cell";
780
+ else if (fields.sign === "-1")
781
+ row = `${type}/negative`;
782
+ else if (fields.sign !== "+1")
783
+ return bad("a claim or mark names sign=+1 or sign=-1", "sign");
784
+ else if (type === "claim")
785
+ row = "claim/positive";
786
+ else if (fields.pole === "floor" && fields.reach === "travels" && fields.widens === void 0)
787
+ row = "mark/floor-travelling";
788
+ else if (fields.pole === "ceiling" && fields.reach === "travels" && fields.widens === void 0)
789
+ row = "mark/travelling";
790
+ else if (fields.pole === "ceiling" && fields.reach === "local")
791
+ row = "mark/local";
792
+ else
793
+ return bad("a positive mark is ceiling/travels, ceiling/local with widens, or floor/travels without widens", "pole");
794
+ const required = schema.required.get(row);
795
+ const allowed = schema.allowed.get(row);
796
+ if (!required || !allowed || schema.common.size === 0 || schema.configuration.size === 0 || [...schema.common].some((k) => !required.has(k) || !allowed.has(k)) || [...required].some((k) => !allowed.has(k)))
797
+ return bad(`typed wire has no complete required/allowed contract for ${row}`, "type");
798
+ for (const key of COMMON)
799
+ if (fields[key] === void 0 || fields[key] === "")
800
+ return bad(`an object record has no ${key}`, key);
801
+ for (const key of keys)
802
+ if (!globalFields.has(key) || !allowed.has(key))
803
+ return bad(`\`${key}=\` is not allowed on ${row}`, key);
804
+ for (const key of required)
805
+ if (!allowed.has(key) || fields[key] === void 0 || fields[key] === "")
806
+ return bad(`a ${row} record has no declared required \`${key}\``, key);
807
+ if (!coordinateText(fields.scope))
808
+ return bad("scope is a canonical cell coordinate", "scope");
809
+ if (type === "cell") {
810
+ if (!forms.has(fields.form))
811
+ return bad("the cell names no admitted form", "form");
812
+ if (restCoordinates(fields.restsOn) === void 0)
813
+ return bad("cell restsOn is none or a canonical alphabet of coordinates", "restsOn");
814
+ }
815
+ return fact({ record: type, fields: { ...fields } });
816
+ }
817
+
818
+ // work/bound-0.1.9/repository/node_modules/@lapxo/topos/dist/wire/sig.js
819
+ function parseSignature(value) {
820
+ const colon = value.lastIndexOf(":");
821
+ if (colon <= 0 || colon === value.length - 1)
822
+ return null;
823
+ return { algorithm: value.slice(0, colon), raw: value.slice(colon + 1) };
824
+ }
825
+
826
+ // work/bound-0.1.9/repository/node_modules/@lapxo/topos/dist/wire/claimline.js
827
+ var ENVELOPE = /* @__PURE__ */ new Set(["sig", "expires", "repo", "by", "epoch"]);
828
+ var WITHDRAW = "withdraw";
829
+ var WIRE = "wire/";
830
+ var WAS = "audit/wire/";
831
+ function listOf(scope) {
832
+ if (scope.startsWith(WAS))
833
+ return scope.slice(WAS.length);
834
+ if (scope.startsWith(WIRE))
835
+ return scope.slice(WIRE.length);
836
+ return void 0;
837
+ }
838
+ function epochOf(fields) {
839
+ const value = fields["epoch"] ?? "";
840
+ return /^\d+$/.test(value) ? Number(value) : 0;
841
+ }
842
+ function names(withdraw, line) {
843
+ return Object.keys(withdraw).filter((k) => k !== "value" && !ENVELOPE.has(k)).every((k) => line[k] === withdraw[k]);
844
+ }
845
+ function wireAt(lines, epoch) {
846
+ const mine = lines.filter((f) => listOf(f["scope"] ?? "") !== void 0 && epochOf(f) <= epoch);
847
+ const withdrawals = mine.filter((f) => f["value"] === WITHDRAW);
848
+ const candidates = /* @__PURE__ */ new Map();
849
+ for (const f of mine) {
850
+ if (f["value"] === WITHDRAW || withdrawals.some((w) => names(w, f)))
851
+ continue;
852
+ const key = (listOf(f["scope"] ?? "") ?? "") + "\0" + (f["by"] ?? "");
853
+ const held = candidates.get(key) ?? [];
854
+ const newest = held.length ? epochOf(held[0]) : -1;
855
+ if (epochOf(f) > newest)
856
+ candidates.set(key, [f]);
857
+ else if (epochOf(f) === newest)
858
+ candidates.set(key, [...held, f]);
859
+ }
860
+ const live2 = [...candidates.values()].flatMap((rows) => rows.some((f) => (f["scope"] ?? "").startsWith(WIRE)) ? rows.filter((f) => (f["scope"] ?? "").startsWith(WIRE)) : rows);
861
+ const values = /* @__PURE__ */ new Map();
862
+ for (const f of live2) {
863
+ const key = listOf(f["scope"] ?? "") ?? "", prior = values.get(key);
864
+ if (prior !== void 0 && prior !== f["value"])
865
+ throw Error(`REFUSE\xB7wire wire/${key} has conflicting live declarations`);
866
+ values.set(key, f["value"] ?? "");
867
+ }
868
+ const standing = /* @__PURE__ */ new Map();
869
+ for (const f of mine) {
870
+ const key = listOf(f["scope"] ?? "") ?? "";
871
+ if (f["value"] === WITHDRAW || withdrawals.some((w) => names(w, f)))
872
+ continue;
873
+ const held = standing.get(key);
874
+ const newer = held === void 0 || epochOf(f) > epochOf(held) || epochOf(f) === epochOf(held) && (f["scope"] ?? "").startsWith(WIRE) && (held["scope"] ?? "").startsWith(WAS);
875
+ if (newer)
876
+ standing.set(key, f);
877
+ }
878
+ if (!standing.size)
879
+ return null;
880
+ const ids = (name) => new Set((standing.get(name)?.["value"] ?? "").split("|").filter(Boolean));
881
+ const formOf = new Map([...standing].filter(([name]) => name.startsWith("form/")).map(([name, f]) => [name.slice("form/".length), f["value"] ?? ""]));
882
+ const lists = new Map([...standing.keys()].filter((name) => !name.includes("/")).map((name) => [name, ids(name)]));
883
+ return {
884
+ epoch,
885
+ ...standing.has("object/types") ? { object: {
886
+ activation: epochOf(standing.get("object/types")),
887
+ types: ids("object/types"),
888
+ common: ids("object/common"),
889
+ reserved: ids("object/reserved"),
890
+ configuration: ids("object/allowed/config"),
891
+ required: new Map([...standing.keys()].filter((k) => k.startsWith("object/required/")).map((k) => [k.slice("object/required/".length), ids(k)])),
892
+ allowed: new Map([...standing.keys()].filter((k) => k.startsWith("object/allowed/")).map((k) => [k.slice("object/allowed/".length), ids(k)]))
893
+ } } : {},
894
+ fields: ids("fields"),
895
+ required: ids("required"),
896
+ roles: ids("roles"),
897
+ forms: ids("forms"),
898
+ classes: ids("at-classes"),
899
+ digests: new Set([...ids("digest-algorithms")].map((one) => one.split(":")[0])),
900
+ signatures: ids("signature-algorithms"),
901
+ formOf,
902
+ lists
903
+ };
904
+ }
905
+ function admittedDigest(value, wire) {
906
+ const colon = value.indexOf(":");
907
+ return colon > 0 && wire.digests.has(value.slice(0, colon)) && /^[0-9a-f]+$/i.test(value.slice(colon + 1));
908
+ }
909
+ function isRegion(need) {
910
+ if (need.startsWith("/") || /[\s\\]/.test(need))
911
+ return false;
912
+ const steps = need.split("/").filter((step) => step !== "");
913
+ return steps.length > 0 && steps.every((step, i) => step !== "." && step !== ".." && (!step.includes("*") || i === steps.length - 1));
914
+ }
915
+ var FIELD_FORMS = {
916
+ region: (value) => value.split("|").filter(Boolean).every(isRegion),
917
+ class: (value, wire) => {
918
+ const colon = value.indexOf(":");
919
+ if (colon <= 0 || !wire.classes.has(value.slice(0, colon)))
920
+ return false;
921
+ const rest = value.slice(colon + 1);
922
+ return !/^[a-z0-9-]+:[0-9a-f]{16,}$/i.test(rest) || admittedDigest(rest, wire);
923
+ },
924
+ signature: (value, wire) => {
925
+ const got = parseSignature(value);
926
+ if (got === null || !wire.signatures.has(got.algorithm))
927
+ return false;
928
+ const era = got.algorithm.slice(got.algorithm.lastIndexOf(":") + 1);
929
+ return admittedDigest(got.algorithm, wire) || got.algorithm.includes(":") && (wire.lists.get("era")?.has(era) ?? false);
930
+ },
931
+ count: (value) => /^\d+$/.test(value)
932
+ };
933
+ function debit(field, why) {
934
+ return refuse(why, field);
935
+ }
936
+ function fromLine(text, wire, grammars) {
937
+ const line = parse(text, { preserveKeys: true });
938
+ if (line.kind !== "fact") {
939
+ return line.kind === "abstain" ? abstain(line.why) : refuse(line.why, line.named);
940
+ }
941
+ const f = line.value.fields;
942
+ const keys = line.value.keys;
943
+ if (keys.includes("type")) {
944
+ if (!wire?.object)
945
+ return refuse("typed object grammar is not admitted at this epoch", "type");
946
+ if (!wire.object.configuration.size || !wire.object.reserved.size || [...wire.object.reserved].some((k) => wire.object.configuration.has(k)))
947
+ return refuse("typed wire has no closed configuration/object field contract", "type");
948
+ const got = objectFromFields(f, keys, wire.object, wire.fields, wire.forms);
949
+ if (got.kind !== "fact")
950
+ return got;
951
+ if (!FIELD_FORMS.signature(f.sig, wire))
952
+ return refuse("object signature grammar is not admitted", "sig");
953
+ if (got.value.record === "cell" && !admittedDigest(f.topos, wire))
954
+ return refuse("cell topos is not an admitted digest", "topos");
955
+ if (got.value.record === "cell" && (f.restsOn ?? "").split("|").some((name) => admittedDigest(name, wire)))
956
+ return refuse("cell restsOn names coordinates, not byte digests", "restsOn");
957
+ return got;
958
+ }
959
+ if (wire) {
960
+ if (wire.object) {
961
+ if (!wire.object.configuration.size || !wire.object.reserved.size || [...wire.object.reserved].some((k) => wire.object.configuration.has(k)))
962
+ return refuse("typed wire has no closed configuration/object field contract", "type");
963
+ const reserved = keys.find((k) => wire.object.reserved.has(k) || !wire.object.configuration.has(k));
964
+ if (reserved)
965
+ return refuse(`\`${reserved}=\` is an object-only field: untyped configuration cannot carry it`, reserved);
966
+ }
967
+ for (const k of Object.keys(f))
968
+ if (!wire.fields.has(k))
969
+ return debit(k, `\`${k}=\` is not a field of the wire at epoch ${wire.epoch}`);
970
+ for (const k of wire.required)
971
+ if (f[k] === void 0)
972
+ return debit(k, `a claim with no \`${k}\``);
973
+ for (const [k, form2] of wire.formOf) {
974
+ const v = f[k];
975
+ if (v === void 0)
976
+ continue;
977
+ const ids = wire.lists.get(form2);
978
+ const reads = FIELD_FORMS[form2] ?? (ids ? (value) => ids.has(value) : void 0);
979
+ if (!reads)
980
+ return abstain(`\`${k}\` takes the form ${form2}, which this reader does not know`);
981
+ if (!reads(v, wire))
982
+ return debit(k, `\`${k}=${v}\` is not a ${form2} of the wire at epoch ${wire.epoch}`);
983
+ }
984
+ if (f.role !== void 0 && !wire.roles.has(f.role))
985
+ return abstain(`\`role=${f.role}\` is a role this wire does not name`);
986
+ if (!wire.forms.has(f.form ?? ""))
987
+ return abstain(`\`form=${f.form}\` is a form this wire does not name`);
988
+ }
989
+ const listed = Array.isArray(grammars) ? grammars : void 0;
990
+ const bound = f.value === WITHDRAW ? { kind: "enumerated", values: [WITHDRAW] } : boundOf(f.form ?? "", f.value ?? "", listed);
991
+ if (bound === null) {
992
+ const mine = BOUND_FORMS.includes(f.form ?? "") || (listed?.some((g) => g.form === f.form) ?? false);
993
+ return mine ? debit("value", `\`${f.value}\` is not a ${f.form}`) : abstain(`\`form=${f.form}\` is a form this reader does not know`);
994
+ }
995
+ const role = f.role === "writes" ? "writes" : f.role === "demands" ? "demands" : "reads";
996
+ const extra = {};
997
+ for (const [k, v] of Object.entries(f)) {
998
+ if (["scope", "measure", "form", "value", "by", "at", "role", "unit", "multiplicity", "epoch", "ref", "to", "ref_by"].includes(k))
999
+ continue;
1000
+ extra[k] = v;
1001
+ }
1002
+ const rel = f.ref;
1003
+ const to = f.to === void 0 ? null : unpipe(f.to);
1004
+ const reference = rel && to && REF_RELATIONS.includes(rel) ? { rel, to, by: f.ref_by === "declared" ? "declared" : "inferred" } : null;
1005
+ return fact({
1006
+ scope: f.scope ?? "",
1007
+ measure: f.measure ?? "",
1008
+ bound,
1009
+ role,
1010
+ by: f.by ?? "",
1011
+ at: f.at ?? "",
1012
+ ...f.unit !== void 0 ? { unit: f.unit } : {},
1013
+ ...f.multiplicity === "one" || f.multiplicity === "many" || f.multiplicity === "unknown" ? { multiplicity: f.multiplicity } : {},
1014
+ ...f.epoch !== void 0 ? { epoch: f.epoch } : {},
1015
+ ...reference ? { reference } : {},
1016
+ extra
1017
+ });
1018
+ }
1019
+ var EPOCHS = intervals(-Infinity, Infinity);
1020
+ var QUORUMS = intervals(1, Infinity);
1021
+
1022
+ // work/bound-0.1.9/repository/node_modules/@lapxo/topos/dist/wire/record-kind.js
1023
+ function recordKind(text) {
1024
+ const got = parse(text, { preserveKeys: true });
1025
+ if (got.kind !== "fact")
1026
+ return got;
1027
+ if (!got.value.keys.includes("type"))
1028
+ return fact("config");
1029
+ const type = got.value.fields.type;
1030
+ return type === "cell" || type === "claim" || type === "mark" ? fact(type) : refuse("an explicit type names cell, claim or mark", "type");
1031
+ }
1032
+
1033
+ // work/bound-0.1.9/repository/node_modules/@lapxo/topos/dist/wire/object-history.js
1034
+ function objectHistory(lines) {
1035
+ const parsed = [];
1036
+ for (const text of lines) {
1037
+ const p = parse(text);
1038
+ if (p.kind !== "fact")
1039
+ return p;
1040
+ parsed.push(p.value.fields);
1041
+ }
1042
+ const objects = [], configuration = [];
1043
+ for (let i = 0; i < lines.length; i++) {
1044
+ const k = recordKind(lines[i]);
1045
+ if (k.kind !== "fact")
1046
+ return k;
1047
+ if (k.value === "config") {
1048
+ configuration.push(parsed[i]);
1049
+ continue;
1050
+ }
1051
+ const got = fromLine(lines[i], wireAt(parsed, Number(parsed[i].epoch)));
1052
+ if (got.kind !== "fact")
1053
+ return got;
1054
+ if (!("record" in got.value))
1055
+ throw Error("typed history returned configuration");
1056
+ objects.push(got.value);
1057
+ }
1058
+ return fact({ objects, configuration });
1059
+ }
1060
+
1061
+ // work/topos-0.1.17/repository/dist/wire/outcome.js
1062
+ var fact2 = (value) => ({ kind: "fact", value });
1063
+ var refuse3 = (why, named) => ({ kind: "refuse", why, ...named === void 0 ? {} : { named } });
1064
+
1065
+ // work/topos-0.1.17/repository/dist/wire/values.js
1066
+ function unpipe2(value) {
1067
+ const out = [];
1068
+ let at = "";
1069
+ for (let i = 0; i < value.length; i++) {
1070
+ const c = value[i];
1071
+ if (c === "\\") {
1072
+ const next = value[i + 1];
1073
+ if (next !== "|" && next !== "\\")
1074
+ return null;
1075
+ at += next;
1076
+ i += 1;
1077
+ } else if (c === "|") {
1078
+ out.push(at);
1079
+ at = "";
1080
+ } else {
1081
+ at += c;
1082
+ }
1083
+ }
1084
+ out.push(at);
1085
+ return out;
1086
+ }
1087
+ var OPEN2 = "*";
1088
+ var num2 = (s) => {
1089
+ if (!/^-?\d+(\.\d+)?$/.test(s))
1090
+ return null;
1091
+ const n = Number(s);
1092
+ return isFinite(n) ? n : null;
1093
+ };
1094
+ var GRAMMARS2 = {
1095
+ interval: (value) => {
1096
+ const at = value.indexOf("..");
1097
+ if (at < 0)
1098
+ return null;
1099
+ const lo = value.slice(0, at);
1100
+ const hi = value.slice(at + 2);
1101
+ const l = lo === OPEN2 ? null : num2(lo);
1102
+ const h = hi === OPEN2 ? null : num2(hi);
1103
+ if (lo !== OPEN2 && l === null || hi !== OPEN2 && h === null)
1104
+ return null;
1105
+ return { kind: "interval", lo: l, hi: h };
1106
+ },
1107
+ alphabet: (value) => {
1108
+ const values = unpipe2(value);
1109
+ return values === null ? null : { kind: "enumerated", values };
1110
+ },
1111
+ ladder: (value) => {
1112
+ const parts2 = unpipe2(value);
1113
+ if (parts2 === null || parts2.length !== 2)
1114
+ return null;
1115
+ return { kind: "band", floor: parts2[0] ?? "", ceiling: parts2[1] ?? "" };
1116
+ }
1117
+ };
1118
+ function boundOf2(form2, value, grammars) {
1119
+ const extra = Array.isArray(grammars) ? grammars.find((g) => g.form === form2) : void 0;
1120
+ if (extra)
1121
+ return extra.parse(value);
1122
+ return GRAMMARS2[form2]?.(value) ?? null;
1123
+ }
1124
+ var BOUND_FORMS2 = Object.keys(GRAMMARS2);
1125
+
1126
+ // work/topos-0.1.17/repository/dist/wire/line.js
1127
+ var PROTOCOL2 = "bound-lock/1";
1128
+ var NEEDS_QUOTE2 = /[ ="\n\\]/;
1129
+ function escape2(value) {
1130
+ if (!NEEDS_QUOTE2.test(value))
1131
+ return value;
1132
+ return `"${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n")}"`;
1133
+ }
1134
+ var UTF82 = new TextEncoder();
1135
+ function byBytes2(a, b) {
1136
+ const x = UTF82.encode(a);
1137
+ const y = UTF82.encode(b);
1138
+ for (let i = 0; i < x.length && i < y.length; i++) {
1139
+ if (x[i] !== y[i])
1140
+ return x[i] - y[i];
1141
+ }
1142
+ return x.length - y.length;
1143
+ }
1144
+ var unwritten2 = (fields) => fields["form"] === "interval" && fields["value"] !== void 0 && fields["value"] !== "withdraw" && boundOf2("interval", fields["value"]) === null;
1145
+ function canonical2(fields, version = "1") {
1146
+ if (unwritten2(fields))
1147
+ throw new Error(`REFUSE\xB7wire canonical: \`${fields["value"]}\` is no interval the wire writes: two ends, each decimal or *`);
1148
+ const keys = Object.keys(fields).sort(byBytes2);
1149
+ const tokens = keys.map((k) => `${k}=${escape2(fields[k])}`);
1150
+ return [`${PROTOCOL2.split("/")[0]}/${version}`, ...tokens].join(" ");
1151
+ }
1152
+ function signedBytes(fields, version = "1") {
1153
+ const { sig: _sig, ...rest } = fields;
1154
+ return canonical2(rest, version);
1155
+ }
1156
+
1157
+ // work/topos-0.1.17/repository/dist/wire/grammar.js
1158
+ var [FORBID2, EMPTY2, MEMBER2, PAIR2, STEP2, AT2, EVERY2, ESCAPE2] = ["not:", "none", "|", "=", "/", "@", "*", "\\"];
1159
+ var refuse4 = (grammar, why) => {
1160
+ throw new Error(`REFUSE\xB7wire ${grammar}: ${why}`);
1161
+ };
1162
+ function alphabet2(given) {
1163
+ if (typeof given !== "string") {
1164
+ const written2 = given.members.map((one) => one.split(ESCAPE2).join(ESCAPE2 + ESCAPE2).split(MEMBER2).join(ESCAPE2 + MEMBER2)).join(MEMBER2);
1165
+ if (given.polarity === "forbid")
1166
+ return FORBID2 + written2;
1167
+ return written2.startsWith(FORBID2) || written2 === EMPTY2 ? refuse4("alphabet", "a permitted alphabet neither begins with not: nor is the one word none") : written2 || EMPTY2;
1168
+ }
1169
+ const forbid = given.startsWith(FORBID2);
1170
+ const body = forbid ? given.slice(FORBID2.length) : given;
1171
+ const members = !forbid && body === EMPTY2 ? [] : unpipe2(body) ?? refuse4("alphabet", "a backslash escapes only a pipe or itself");
1172
+ return { polarity: forbid ? "forbid" : "permit", members: members.filter((one) => one !== "") };
1173
+ }
1174
+
1175
+ // work/topos-0.1.17/repository/dist/wire/object-record.js
1176
+ function coordinateText2(value) {
1177
+ return value !== "" && !/[\s\\|]/.test(value) && value.split("/").every((s) => s !== "" && s !== "." && s !== ".." && s !== "*" && s !== "**");
1178
+ }
1179
+ function restCoordinates2(text) {
1180
+ try {
1181
+ const read = alphabet2(text);
1182
+ if (read.polarity !== "permit" || read.members.some((one) => !coordinateText2(one)))
1183
+ return void 0;
1184
+ const sorted = [...new Set(read.members)].sort(byBytes2);
1185
+ if (alphabet2({ polarity: "permit", members: sorted }) !== text)
1186
+ return void 0;
1187
+ return sorted;
1188
+ } catch {
1189
+ return void 0;
1190
+ }
1191
+ }
1192
+
1193
+ // work/bound-0.2.0/order-candidate/dist/wire/object-context.js
1194
+ function validateObjectContext(records, context2) {
1195
+ const fail = (why) => refuse3(`object context: ${why}`);
1196
+ const ids = /* @__PURE__ */ new Map();
1197
+ for (const record of records) {
1198
+ if (!context2.admit(record))
1199
+ return fail(`signature or authority does not admit ${record.fields.id}`);
1200
+ const prior = ids.get(record.fields.id);
1201
+ if (prior && signedBytes(prior.fields) !== signedBytes(record.fields))
1202
+ return fail(`record ID collision ${record.fields.id}`);
1203
+ if (!prior)
1204
+ ids.set(record.fields.id, record);
1205
+ }
1206
+ const unique = [...ids.values()];
1207
+ const position = new Map(unique.map((record, index) => [record.fields.id, index]));
1208
+ const cells = /* @__PURE__ */ new Map();
1209
+ for (const record of unique.filter((r) => r.record === "cell")) {
1210
+ if (cells.has(record.fields.scope))
1211
+ return fail(`cell definition is not unique at ${record.fields.scope}`);
1212
+ cells.set(record.fields.scope, record);
1213
+ }
1214
+ const selected = /* @__PURE__ */ new Map();
1215
+ for (const [scope, record] of cells) {
1216
+ try {
1217
+ const got = context2.resolve(record);
1218
+ if (got.digest !== record.fields.topos || got.form.id !== record.fields.form)
1219
+ return fail(`selected digest/form does not match ${scope}`);
1220
+ got.form.lattice(got.params);
1221
+ selected.set(scope, got);
1222
+ } catch (error) {
1223
+ return fail(`codec/pin/decoder stop at ${scope}: ${String(error)}`);
1224
+ }
1225
+ }
1226
+ const edges = /* @__PURE__ */ new Map();
1227
+ for (const [scope, record] of cells) {
1228
+ const rest = restCoordinates2(record.fields.restsOn);
1229
+ if (rest === void 0)
1230
+ return fail(`invalid declared rest at ${scope}`);
1231
+ for (const parent of rest) {
1232
+ const ancestor = cells.get(parent);
1233
+ if (!ancestor)
1234
+ return fail(`missing rest target ${parent}`);
1235
+ if (Number(ancestor.fields.epoch) > Number(record.fields.epoch))
1236
+ return fail(`rest target ${parent} did not exist at cell declaration`);
1237
+ if (["topos", "form", "params", "measure"].some((k) => ancestor.fields[k] !== record.fields[k]))
1238
+ return fail(`incompatible rest component ${scope}/${parent}`);
1239
+ }
1240
+ edges.set(scope, rest);
1241
+ }
1242
+ const colour = /* @__PURE__ */ new Map();
1243
+ for (const scope of cells.keys()) {
1244
+ if (colour.get(scope) === 2)
1245
+ continue;
1246
+ const stack = [{ name: scope, exit: false }];
1247
+ while (stack.length) {
1248
+ const next = stack.pop();
1249
+ if (next.exit) {
1250
+ colour.set(next.name, 2);
1251
+ continue;
1252
+ }
1253
+ if (colour.get(next.name) === 1)
1254
+ return fail(`declared rest cycle reachable from ${scope}`);
1255
+ if (colour.get(next.name) === 2)
1256
+ continue;
1257
+ colour.set(next.name, 1);
1258
+ stack.push({ name: next.name, exit: true });
1259
+ for (const parent of [...edges.get(next.name)].reverse())
1260
+ stack.push({ name: parent, exit: false });
1261
+ }
1262
+ }
1263
+ for (const record of unique.filter((r) => r.record !== "cell")) {
1264
+ const f = record.fields;
1265
+ const own = cells.get(f.scope);
1266
+ if (!own || Number(own.fields.epoch) > Number(f.epoch) || Number(own.fields.epoch) === Number(f.epoch) && position.get(own.fields.id) > position.get(f.id))
1267
+ return fail(`cell not declared before ${f.id}`);
1268
+ if (f.sign === "-1") {
1269
+ const target = ids.get(f.takes);
1270
+ if (!target || target.record !== record.record || target.fields.scope !== f.scope || target.fields.sign !== "+1" || target.fields.by !== f.by || Number(target.fields.epoch) >= Number(f.epoch))
1271
+ return fail(`unauthorized or incompatible withdrawal target ${f.takes}`);
1272
+ } else {
1273
+ const codec = selected.get(f.scope);
1274
+ try {
1275
+ codec.form.parse(codec.params, f.value);
1276
+ } catch (error) {
1277
+ return fail(`span codec stop at ${f.id}: ${String(error)}`);
1278
+ }
1279
+ if (record.record === "claim" && !context2.origin(f.origin, f.by, f.scope))
1280
+ return fail(`origin is not attested for ${f.id}`);
1281
+ if (f.widens !== void 0 && !context2.witness(f.widens, f.by, f.scope))
1282
+ return fail(`join witness is not admitted for ${f.id}`);
1283
+ }
1284
+ }
1285
+ for (const scope of cells.keys()) {
1286
+ const rest = /* @__PURE__ */ new Set();
1287
+ const pending = [...edges.get(scope)];
1288
+ while (pending.length) {
1289
+ const name = pending.pop();
1290
+ if (rest.has(name))
1291
+ continue;
1292
+ rest.add(name);
1293
+ pending.push(...edges.get(name));
1294
+ }
1295
+ const marks = unique.filter((r) => r.record === "mark" && r.fields.sign === "+1" && r.fields.pole === "ceiling" && (r.fields.scope === scope || rest.has(r.fields.scope) && r.fields.reach === "travels"));
1296
+ const epochs = /* @__PURE__ */ new Map();
1297
+ for (const m of marks)
1298
+ epochs.set(m.fields.epoch, [...epochs.get(m.fields.epoch) ?? [], m]);
1299
+ for (const same of epochs.values())
1300
+ if (same.length > 1 && same.some((m) => m.fields.widens !== void 0))
1301
+ return fail(`ambiguous same-epoch ceiling acts at ${scope}`);
1302
+ }
1303
+ return fact2(unique);
1304
+ }
1305
+
1306
+ // work/bound-0.1.9/repository/node_modules/@lapxo/obligations/dist/field/join.js
1307
+ function join(L, c, span2, witness, at) {
1308
+ if (witness === "")
1309
+ throw new UnitError("join-unwitnessed", "obligations: REFUSE\xB7join a widening lands only with a witness or the signatures of whoever rests on the old bound");
1310
+ return { ...c, marks: [...c.marks ?? [], mark({ pole: "ceiling", reach: "local", span: L.meet(L.top, span2), widens: witness, ...at === void 0 ? {} : { at } })] };
1311
+ }
1312
+
1313
+ // work/bound-0.1.9/repository/node_modules/@lapxo/obligations/dist/field/observe.js
1314
+ function observe(c, claim, s = claim.takes === void 0 ? 1 : -1) {
1315
+ const takes = s === 1 ? void 0 : claim.takes ?? claim.id;
1316
+ if (s === 1 && claim.takes !== void 0)
1317
+ throw new UnitError("sign-mismatch", "obligations: REFUSE\xB7observe a claim that takes another back is observed at \u22121, never at +1");
1318
+ if (s === -1 && takes === void 0)
1319
+ throw new UnitError("withdrawal-unnamed", "obligations: REFUSE\xB7observe a withdrawal names the claim it takes back, never a value that looks like it");
1320
+ const line = takes === void 0 ? claim : { origin: claim.origin, span: claim.span, sign: -1, takes, ...claim.at === void 0 ? {} : { at: claim.at } };
1321
+ return { ...c, epoch: Math.max(c.epoch, claim.at ?? c.epoch), seen: [...c.seen, line] };
1322
+ }
1323
+
1324
+ // work/bound-0.1.9/repository/node_modules/@lapxo/obligations/dist/field/require.js
1325
+ function require2(L, world, name, span2, line = {}) {
1326
+ const held = world.get(name) ?? cell(name);
1327
+ return new Map([...world, [name, { ...held, marks: [...held.marks ?? [], mark({ pole: "floor", reach: "travels", span: L.meet(L.top, span2), ...line })] }]]);
1328
+ }
1329
+
1330
+ // work/bound-0.1.9/repository/node_modules/@lapxo/obligations/dist/field/sign.js
1331
+ function sign(L, world, name, span2, line = {}) {
1332
+ const held = world.get(name) ?? cell(name);
1333
+ return new Map([...world, [name, { ...held, marks: [...held.marks ?? [], mark({ pole: "ceiling", reach: "travels", span: L.meet(L.top, span2), ...line })] }]]);
1334
+ }
1335
+
1336
+ // work/bound-0.2.0/engine-candidate/src/engine/object.ts
1337
+ function objectFold(records, context2) {
1338
+ let world = /* @__PURE__ */ new Map();
1339
+ const definitions = new Map(records.filter((r) => r.record === "cell").map((r) => [r.fields.scope, r]));
1340
+ const codecs = new Map([...definitions].map(([name, c]) => [name, context2.resolve(c)]));
1341
+ const ids = new Map(records.map((r) => [r.fields.id, r]));
1342
+ for (const record of [...records].sort((a, b) => Number(a.fields.epoch) - Number(b.fields.epoch))) {
1343
+ const f = record.fields, name = f.scope, at = Number(f.epoch);
1344
+ if (record.record === "cell") {
1345
+ world = new Map([...world, [name, cell(name, at, [], restCoordinates(f.restsOn))]]);
1346
+ continue;
1347
+ }
1348
+ const codec = codecs.get(name), L = codec.form.lattice(codec.params), held = world.get(name);
1349
+ if (record.record === "claim") {
1350
+ const target = f.sign === "-1" ? ids.get(f.takes).fields : f;
1351
+ const changed = observe(held, { id: f.id, at, origin: target.origin, span: codec.form.parse(codec.params, target.value), ...f.takes ? { takes: f.takes } : {} }, f.sign === "-1" ? -1 : 1);
1352
+ const seen = [...changed.seen];
1353
+ seen[seen.length - 1] = { ...seen.at(-1), id: f.id };
1354
+ world = new Map([...world, [name, { ...changed, seen }]]);
1355
+ } else if (f.sign === "-1") {
1356
+ const target = ids.get(f.takes).fields;
1357
+ world = new Map([...world, [name, { ...held, marks: [...held.marks ?? [], mark({ id: f.id, at, takes: f.takes, pole: target.pole, reach: "local", span: codec.form.parse(codec.params, target.value) })] }]]);
1358
+ } else if (f.widens !== void 0) {
1359
+ const changed = join(L, held, codec.form.parse(codec.params, f.value), f.widens, at);
1360
+ const marks = [...changed.marks ?? []];
1361
+ marks[marks.length - 1] = { ...marks.at(-1), id: f.id };
1362
+ world = new Map([...world, [name, { ...changed, marks }]]);
1363
+ } else {
1364
+ const span2 = codec.form.parse(codec.params, f.value);
1365
+ world = f.pole === "floor" ? require2(L, world, name, span2, { id: f.id, at }) : sign(L, world, name, span2, { id: f.id, at });
1366
+ }
1367
+ }
1368
+ return [...world].map(([name, c]) => {
1369
+ const codec = codecs.get(name), L = codec.form.lattice(codec.params);
1370
+ return { cell: name, state: state2(L, c, world), parts: parts(L, c, world), rest: restOf(c, world), ownMarks: live(c.marks ?? []).map((m) => m.id), ownClaims: live(c.seen).map((s) => ({ id: s.id, origin: s.origin })), marks: live(c.marks ?? []), claims: live(c.seen) };
1371
+ });
1372
+ }
1373
+
1374
+ // work/bound-0.1.9/repository/node_modules/@lapxo/topos/dist/forms/form.js
1375
+ var paramsOf = (params) => params !== null && typeof params === "object" ? params : {};
1376
+ function refuseForm(id, why) {
1377
+ throw new Error(`REFUSE\xB7form ${id}: ${why}`);
1378
+ }
1379
+ function numberAt(id, params, name) {
1380
+ const held = paramsOf(params)[name];
1381
+ if (typeof held !== "number" || !isFinite(held))
1382
+ refuseForm(id, `takes ${name} as a number, and a value it is not given is not invented`);
1383
+ return held;
1384
+ }
1385
+ function wordsAt(id, params, name) {
1386
+ const held = paramsOf(params)[name];
1387
+ if (!Array.isArray(held) || !held.length || held.some((one) => typeof one !== "string"))
1388
+ refuseForm(id, `takes ${name} as a list of words`);
1389
+ return held;
1390
+ }
1391
+ var written = (words) => alphabet({ polarity: "permit", members: [...new Set(words)].sort(byBytes) });
1392
+ function bandOf(id, whole, text) {
1393
+ if (text === "empty")
1394
+ return { lo: whole.hi, hi: whole.lo };
1395
+ const read = (value) => ((got) => got.kind === "fact" && got.value.bound.kind === "interval" ? { lo: got.value.bound.lo ?? whole.lo, hi: got.value.bound.hi ?? whole.hi } : void 0)(fromLine(canonical({ form: "interval", value }), null));
1396
+ return read(text) ?? read(`${text}..${text}`) ?? refuseForm(id, `\`${text}\` is not a band: lo..hi or one end, each a number or *`);
1397
+ }
1398
+ var bandText = (value) => ((end) => value.lo > value.hi ? "empty" : `${end(value.lo)}..${end(value.hi)}`)((n) => isFinite(n) ? decimal(n) : "*");
1399
+
1400
+ // work/bound-0.1.9/repository/node_modules/@lapxo/topos/dist/forms/alphabet.js
1401
+ var tokensOf2 = (params) => ({ tokens: wordsAt("alphabet", params, "tokens") });
1402
+ var alphabetOfForm = {
1403
+ id: "alphabet",
1404
+ lattice: (params) => alphabetForm.lattice(tokensOf2(params)),
1405
+ parse(params, text) {
1406
+ const { tokens } = tokensOf2(params);
1407
+ const read = alphabet(text);
1408
+ const stray = read.members.find((one) => !tokens.includes(one));
1409
+ if (stray !== void 0)
1410
+ refuseForm("alphabet", `\`${stray}\` is not one of its tokens`);
1411
+ return WideMask.fromTokens(tokens, new Set(read.polarity === "forbid" ? tokens.filter((one) => !read.members.includes(one)) : read.members));
1412
+ },
1413
+ emit: (params, value) => written(value.members(tokensOf2(params).tokens)),
1414
+ show: (params, value) => alphabetForm.lattice(tokensOf2(params)).show(value),
1415
+ points: (params, seed, n) => alphabetForm.points(tokensOf2(params), seed, n)
1416
+ };
1417
+
1418
+ // work/bound-0.1.9/repository/node_modules/@lapxo/topos/dist/forms/interval.js
1419
+ var span = (params) => ({ lo: numberAt("interval", params, "lo"), hi: numberAt("interval", params, "hi") });
1420
+ var intervalForm = {
1421
+ id: "interval",
1422
+ lattice: (params) => continuousForm.lattice(span(params)),
1423
+ parse: (params, text) => bandOf("interval", span(params), text),
1424
+ emit: (_params, value) => bandText(value),
1425
+ show: (params, value) => continuousForm.lattice(span(params)).show(value),
1426
+ points: (params, seed, n) => continuousForm.points(span(params), seed, n)
1427
+ };
1428
+
1429
+ // work/bound-0.2.0/engine-candidate/tools/samples/typed-provider.mjs
1430
+ function context({ digest, records, admit }) {
1431
+ const granted = (family, id, by, scope) => records.filter((row) => row.scope === `${family}/${id}` && row.value === id && row.by === by && admit(row) && (row.condition ?? "").split("|").includes(scope)).length === 1;
1432
+ return {
1433
+ resolve(cell2) {
1434
+ const form2 = [intervalForm, alphabetOfForm].find((one) => one.id === cell2.fields.form);
1435
+ if (!form2) throw Error("REFUSE\xB7codec sample has no selected form");
1436
+ return { digest, form: form2, params: JSON.parse(cell2.fields.params) };
1437
+ },
1438
+ origin: (id, by, scope) => granted("evidence/origin", id, by, scope),
1439
+ witness: (id, by, scope) => granted("evidence/witness", id, by, scope)
1440
+ };
1441
+ }
1442
+
1443
+ // work/bound-0.2.0/api-public-places/reader-entry.ts
1444
+ function observe2(bytes) {
1445
+ const sample = JSON.parse(new TextDecoder().decode(bytes));
1446
+ const history = objectHistory(sample.history);
1447
+ if (history.kind !== "fact") throw Error("REFUSE\xB7" + history.why);
1448
+ const context2 = context({ digest: sample.pin, records: history.value.configuration, admit: () => true });
1449
+ const checked = validateObjectContext(history.value.objects, { ...context2, admit: () => true });
1450
+ if (checked.kind !== "fact") throw Error("REFUSE\xB7" + checked.why);
1451
+ const actual = objectFold(checked.value, context2);
1452
+ if (JSON.stringify(actual) !== JSON.stringify(sample.expected)) throw Error("REFUSE\xB7engine projection differs from captured native output");
1453
+ return [{ scope: "conformance/engine-object/" + sample.name, role: "writes", measure: "count", bound: { kind: "interval", lo: 0, hi: 0 } }];
1454
+ }
1455
+ export {
1456
+ observe2 as observe
1457
+ };