@agentshouse/mdruntime 0.1.0-c698c0ebd65bd → 0.1.0-c6bf34fa9e444

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 (359) hide show
  1. package/README.md +19 -16
  2. package/dist/acceptance.d.ts +6 -0
  3. package/dist/acceptance.d.ts.map +1 -0
  4. package/dist/acceptance.js +389 -0
  5. package/dist/actions.d.ts +20 -0
  6. package/dist/actions.d.ts.map +1 -0
  7. package/dist/actions.js +250 -0
  8. package/dist/adapter.d.ts +154 -58
  9. package/dist/adapter.d.ts.map +1 -1
  10. package/dist/attached-model.d.ts +7 -10
  11. package/dist/attached-model.d.ts.map +1 -1
  12. package/dist/attached-model.js +40 -41
  13. package/dist/binary.d.ts +0 -5
  14. package/dist/binary.d.ts.map +1 -1
  15. package/dist/binary.js +1 -1
  16. package/dist/bootstrap.d.ts +31 -11
  17. package/dist/bootstrap.d.ts.map +1 -1
  18. package/dist/bootstrap.js +323 -93
  19. package/dist/cell.d.ts +6 -0
  20. package/dist/cell.d.ts.map +1 -0
  21. package/dist/cell.js +9 -0
  22. package/dist/chain.d.ts +12 -0
  23. package/dist/chain.d.ts.map +1 -0
  24. package/dist/chain.js +64 -0
  25. package/dist/change-set.d.ts +9 -14
  26. package/dist/change-set.d.ts.map +1 -1
  27. package/dist/change-set.js +11 -63
  28. package/dist/change.d.ts +32 -1
  29. package/dist/change.d.ts.map +1 -1
  30. package/dist/change.js +10 -1
  31. package/dist/chat-types.d.ts +5 -0
  32. package/dist/chat-types.d.ts.map +1 -0
  33. package/dist/chat-types.js +13 -0
  34. package/dist/client.d.ts +42 -15
  35. package/dist/client.d.ts.map +1 -1
  36. package/dist/client.js +100 -11
  37. package/dist/collection.d.ts +11 -7
  38. package/dist/collection.d.ts.map +1 -1
  39. package/dist/collection.js +38 -79
  40. package/dist/compile.d.ts +16 -0
  41. package/dist/compile.d.ts.map +1 -0
  42. package/dist/compile.js +717 -0
  43. package/dist/connection.d.ts +8 -117
  44. package/dist/connection.d.ts.map +1 -1
  45. package/dist/connection.js +101 -2486
  46. package/dist/context.d.ts +2 -0
  47. package/dist/context.d.ts.map +1 -0
  48. package/dist/{chat/context.js → context.js} +1 -4
  49. package/dist/conversation-row.d.ts +33 -0
  50. package/dist/conversation-row.d.ts.map +1 -0
  51. package/dist/conversation-row.js +47 -0
  52. package/dist/conversation.d.ts +47 -18
  53. package/dist/conversation.d.ts.map +1 -1
  54. package/dist/conversation.js +809 -300
  55. package/dist/digest.d.ts +7 -0
  56. package/dist/digest.d.ts.map +1 -0
  57. package/dist/digest.js +113 -0
  58. package/dist/discovery.d.ts +10 -0
  59. package/dist/discovery.d.ts.map +1 -0
  60. package/dist/discovery.js +175 -0
  61. package/dist/durability.d.ts +19 -1
  62. package/dist/durability.d.ts.map +1 -1
  63. package/dist/durability.js +5 -0
  64. package/dist/entry.d.ts +7 -4
  65. package/dist/entry.d.ts.map +1 -1
  66. package/dist/entry.js +33 -28
  67. package/dist/figures.d.ts +48 -0
  68. package/dist/figures.d.ts.map +1 -0
  69. package/dist/figures.js +197 -0
  70. package/dist/file.d.ts +2 -19
  71. package/dist/file.d.ts.map +1 -1
  72. package/dist/file.js +7 -122
  73. package/dist/holdings.d.ts +29 -0
  74. package/dist/holdings.d.ts.map +1 -0
  75. package/dist/holdings.js +95 -0
  76. package/dist/host.d.ts +11 -3
  77. package/dist/host.d.ts.map +1 -1
  78. package/dist/host.js +127 -20
  79. package/dist/index.d.ts +32 -11
  80. package/dist/index.d.ts.map +1 -1
  81. package/dist/index.js +10 -0
  82. package/dist/install.d.ts +56 -0
  83. package/dist/install.d.ts.map +1 -0
  84. package/dist/install.js +560 -0
  85. package/dist/job.d.ts +33 -0
  86. package/dist/job.d.ts.map +1 -0
  87. package/dist/job.js +54 -0
  88. package/dist/lifecycle.d.ts +7 -0
  89. package/dist/lifecycle.d.ts.map +1 -0
  90. package/dist/lifecycle.js +267 -0
  91. package/dist/listing.d.ts +53 -0
  92. package/dist/listing.d.ts.map +1 -0
  93. package/dist/listing.js +175 -0
  94. package/dist/live.d.ts +23 -0
  95. package/dist/live.d.ts.map +1 -0
  96. package/dist/live.js +165 -0
  97. package/dist/locks.d.ts +9 -0
  98. package/dist/locks.d.ts.map +1 -0
  99. package/dist/locks.js +61 -0
  100. package/dist/log.d.ts +1 -0
  101. package/dist/log.d.ts.map +1 -1
  102. package/dist/lost.d.ts +5 -0
  103. package/dist/lost.d.ts.map +1 -0
  104. package/dist/lost.js +61 -0
  105. package/dist/media.d.ts +8 -0
  106. package/dist/media.d.ts.map +1 -0
  107. package/dist/media.js +218 -0
  108. package/dist/memory.d.ts +19 -6
  109. package/dist/memory.d.ts.map +1 -1
  110. package/dist/memory.js +247 -96
  111. package/dist/messages.d.ts +52 -0
  112. package/dist/messages.d.ts.map +1 -0
  113. package/dist/messages.js +168 -0
  114. package/dist/model.d.ts +11 -11
  115. package/dist/model.d.ts.map +1 -1
  116. package/dist/model.js +7 -10
  117. package/dist/models.d.ts +14 -0
  118. package/dist/models.d.ts.map +1 -0
  119. package/dist/models.js +193 -0
  120. package/dist/name.d.ts +4 -0
  121. package/dist/name.d.ts.map +1 -0
  122. package/dist/name.js +122 -0
  123. package/dist/observation.d.ts +22 -4
  124. package/dist/observation.d.ts.map +1 -1
  125. package/dist/observation.js +120 -14
  126. package/dist/opened.d.ts +22 -0
  127. package/dist/opened.d.ts.map +1 -0
  128. package/dist/opened.js +107 -0
  129. package/dist/opening.d.ts +4 -0
  130. package/dist/opening.d.ts.map +1 -0
  131. package/dist/opening.js +56 -0
  132. package/dist/outcome.d.ts +49 -8
  133. package/dist/outcome.d.ts.map +1 -1
  134. package/dist/outcome.js +42 -0
  135. package/dist/overlay.d.ts +4 -4
  136. package/dist/overlay.d.ts.map +1 -1
  137. package/dist/overlay.js +111 -182
  138. package/dist/{chat/parts.d.ts → parts.d.ts} +11 -9
  139. package/dist/parts.d.ts.map +1 -0
  140. package/dist/{chat/parts.js → parts.js} +45 -46
  141. package/dist/paths.d.ts +1 -0
  142. package/dist/paths.d.ts.map +1 -1
  143. package/dist/paths.js +4 -0
  144. package/dist/preparation.d.ts +20 -0
  145. package/dist/preparation.d.ts.map +1 -0
  146. package/dist/preparation.js +226 -0
  147. package/dist/queries.d.ts +16 -0
  148. package/dist/queries.d.ts.map +1 -0
  149. package/dist/queries.js +272 -0
  150. package/dist/query.d.ts +50 -183
  151. package/dist/query.d.ts.map +1 -1
  152. package/dist/query.js +3 -464
  153. package/dist/{chat/questions.d.ts → questions.d.ts} +3 -2
  154. package/dist/questions.d.ts.map +1 -0
  155. package/dist/{chat/questions.js → questions.js} +8 -1
  156. package/dist/reach.d.ts +21 -7
  157. package/dist/reach.d.ts.map +1 -1
  158. package/dist/reach.js +288 -88
  159. package/dist/react.d.ts +12 -6
  160. package/dist/react.d.ts.map +1 -1
  161. package/dist/react.js +7 -17
  162. package/dist/{chat/read.d.ts → read.d.ts} +2 -0
  163. package/dist/read.d.ts.map +1 -0
  164. package/dist/{chat/read.js → read.js} +4 -0
  165. package/dist/readiness.d.ts +50 -0
  166. package/dist/readiness.d.ts.map +1 -0
  167. package/dist/readiness.js +27 -0
  168. package/dist/reads.d.ts +36 -0
  169. package/dist/reads.d.ts.map +1 -0
  170. package/dist/reads.js +136 -0
  171. package/dist/recovery.d.ts +26 -0
  172. package/dist/recovery.d.ts.map +1 -0
  173. package/dist/recovery.js +232 -0
  174. package/dist/refresh.d.ts +17 -14
  175. package/dist/refresh.d.ts.map +1 -1
  176. package/dist/refresh.js +143 -51
  177. package/dist/refusal.d.ts +5 -0
  178. package/dist/refusal.d.ts.map +1 -0
  179. package/dist/refusal.js +56 -0
  180. package/dist/replica.d.ts +55 -33
  181. package/dist/replica.d.ts.map +1 -1
  182. package/dist/replica.js +332 -154
  183. package/dist/room-draft.d.ts +37 -6
  184. package/dist/room-draft.d.ts.map +1 -1
  185. package/dist/room-draft.js +161 -74
  186. package/dist/room-drafts.d.ts +24 -0
  187. package/dist/room-drafts.d.ts.map +1 -0
  188. package/dist/room-drafts.js +216 -0
  189. package/dist/rows.d.ts +30 -37
  190. package/dist/rows.d.ts.map +1 -1
  191. package/dist/rows.js +59 -126
  192. package/dist/runtime.d.ts +42 -0
  193. package/dist/runtime.d.ts.map +1 -0
  194. package/dist/runtime.js +1 -0
  195. package/dist/save.d.ts +53 -9
  196. package/dist/save.d.ts.map +1 -1
  197. package/dist/save.js +542 -172
  198. package/dist/saves.d.ts +70 -0
  199. package/dist/saves.d.ts.map +1 -0
  200. package/dist/saves.js +1004 -0
  201. package/dist/search.d.ts +15 -55
  202. package/dist/search.d.ts.map +1 -1
  203. package/dist/search.js +10 -121
  204. package/dist/seed.d.ts +25 -0
  205. package/dist/seed.d.ts.map +1 -0
  206. package/dist/seed.js +146 -0
  207. package/dist/shared.d.ts +15 -0
  208. package/dist/shared.d.ts.map +1 -0
  209. package/dist/shared.js +421 -0
  210. package/dist/shown.d.ts +31 -0
  211. package/dist/shown.d.ts.map +1 -0
  212. package/dist/shown.js +294 -0
  213. package/dist/socket/admission.d.ts +7 -0
  214. package/dist/socket/admission.d.ts.map +1 -0
  215. package/dist/socket/admission.js +39 -0
  216. package/dist/socket/answers.d.ts +6 -0
  217. package/dist/socket/answers.d.ts.map +1 -0
  218. package/dist/socket/answers.js +20 -0
  219. package/dist/socket/lanes.d.ts +20 -0
  220. package/dist/socket/lanes.d.ts.map +1 -0
  221. package/dist/socket/lanes.js +77 -0
  222. package/dist/socket/reads.d.ts +10 -0
  223. package/dist/socket/reads.d.ts.map +1 -0
  224. package/dist/socket/reads.js +31 -0
  225. package/dist/socket/rooms.d.ts +43 -0
  226. package/dist/socket/rooms.d.ts.map +1 -0
  227. package/dist/socket/rooms.js +90 -0
  228. package/dist/socket/session.d.ts +39 -0
  229. package/dist/socket/session.d.ts.map +1 -0
  230. package/dist/socket/session.js +23 -0
  231. package/dist/socket.d.ts +70 -0
  232. package/dist/socket.d.ts.map +1 -0
  233. package/dist/socket.js +175 -0
  234. package/dist/source.d.ts +61 -0
  235. package/dist/source.d.ts.map +1 -0
  236. package/dist/source.js +81 -0
  237. package/dist/status.d.ts +5 -2
  238. package/dist/status.d.ts.map +1 -1
  239. package/dist/status.js +3 -7
  240. package/dist/store/fences.d.ts +16 -0
  241. package/dist/store/fences.d.ts.map +1 -0
  242. package/dist/store/fences.js +26 -0
  243. package/dist/store/installs.d.ts +30 -0
  244. package/dist/store/installs.d.ts.map +1 -0
  245. package/dist/store/installs.js +34 -0
  246. package/dist/store/readiness.d.ts +10 -0
  247. package/dist/store/readiness.d.ts.map +1 -0
  248. package/dist/store/readiness.js +52 -0
  249. package/dist/store/records.d.ts +212 -0
  250. package/dist/store/records.d.ts.map +1 -0
  251. package/dist/store/records.js +408 -0
  252. package/dist/store/room-held.d.ts +8 -0
  253. package/dist/store/room-held.d.ts.map +1 -0
  254. package/dist/store/room-held.js +17 -0
  255. package/dist/store/space.d.ts +11 -0
  256. package/dist/store/space.d.ts.map +1 -0
  257. package/dist/store/space.js +43 -0
  258. package/dist/store/watchers.d.ts +17 -0
  259. package/dist/store/watchers.d.ts.map +1 -0
  260. package/dist/store/watchers.js +57 -0
  261. package/dist/store/writes.d.ts +24 -0
  262. package/dist/store/writes.d.ts.map +1 -0
  263. package/dist/store/writes.js +125 -0
  264. package/dist/store.d.ts +106 -127
  265. package/dist/store.d.ts.map +1 -1
  266. package/dist/store.js +136 -575
  267. package/dist/stored.d.ts +156 -0
  268. package/dist/stored.d.ts.map +1 -0
  269. package/dist/stored.js +637 -0
  270. package/dist/surface.d.ts +88 -0
  271. package/dist/surface.d.ts.map +1 -0
  272. package/dist/surface.js +222 -0
  273. package/dist/sync.d.ts +20 -0
  274. package/dist/sync.d.ts.map +1 -0
  275. package/dist/sync.js +531 -0
  276. package/dist/tables.d.ts +415 -0
  277. package/dist/tables.d.ts.map +1 -0
  278. package/dist/tables.js +740 -0
  279. package/dist/tallies.d.ts +18 -0
  280. package/dist/tallies.d.ts.map +1 -0
  281. package/dist/tallies.js +129 -0
  282. package/dist/transfer.d.ts +0 -5
  283. package/dist/transfer.d.ts.map +1 -1
  284. package/dist/turn.d.ts +9 -0
  285. package/dist/turn.d.ts.map +1 -0
  286. package/dist/turn.js +75 -0
  287. package/dist/validation.d.ts +29 -0
  288. package/dist/validation.d.ts.map +1 -0
  289. package/dist/validation.js +104 -0
  290. package/dist/windows.d.ts +11 -0
  291. package/dist/windows.d.ts.map +1 -0
  292. package/dist/windows.js +16 -0
  293. package/dist/wire.d.ts +181 -33
  294. package/dist/wire.d.ts.map +1 -1
  295. package/dist/wire.js +62 -31
  296. package/package.json +18 -19
  297. package/AGENTS.md +0 -299
  298. package/dist/chat/acts.d.ts +0 -33
  299. package/dist/chat/acts.d.ts.map +0 -1
  300. package/dist/chat/acts.js +0 -36
  301. package/dist/chat/context.d.ts +0 -3
  302. package/dist/chat/context.d.ts.map +0 -1
  303. package/dist/chat/input.d.ts +0 -9
  304. package/dist/chat/input.d.ts.map +0 -1
  305. package/dist/chat/input.js +0 -99
  306. package/dist/chat/kit.d.ts +0 -60
  307. package/dist/chat/kit.d.ts.map +0 -1
  308. package/dist/chat/kit.js +0 -123
  309. package/dist/chat/lasting.d.ts +0 -6
  310. package/dist/chat/lasting.d.ts.map +0 -1
  311. package/dist/chat/lasting.js +0 -19
  312. package/dist/chat/list.d.ts +0 -26
  313. package/dist/chat/list.d.ts.map +0 -1
  314. package/dist/chat/list.js +0 -62
  315. package/dist/chat/markdown.d.ts +0 -20
  316. package/dist/chat/markdown.d.ts.map +0 -1
  317. package/dist/chat/markdown.js +0 -188
  318. package/dist/chat/message.d.ts +0 -6
  319. package/dist/chat/message.d.ts.map +0 -1
  320. package/dist/chat/message.js +0 -192
  321. package/dist/chat/messages.d.ts +0 -21
  322. package/dist/chat/messages.d.ts.map +0 -1
  323. package/dist/chat/messages.js +0 -151
  324. package/dist/chat/name.d.ts +0 -6
  325. package/dist/chat/name.d.ts.map +0 -1
  326. package/dist/chat/name.js +0 -37
  327. package/dist/chat/opened.d.ts +0 -11
  328. package/dist/chat/opened.d.ts.map +0 -1
  329. package/dist/chat/opened.js +0 -17
  330. package/dist/chat/overlay.d.ts +0 -31
  331. package/dist/chat/overlay.d.ts.map +0 -1
  332. package/dist/chat/overlay.js +0 -97
  333. package/dist/chat/parts.d.ts.map +0 -1
  334. package/dist/chat/process.d.ts +0 -20
  335. package/dist/chat/process.d.ts.map +0 -1
  336. package/dist/chat/process.js +0 -32
  337. package/dist/chat/provider.d.ts +0 -63
  338. package/dist/chat/provider.d.ts.map +0 -1
  339. package/dist/chat/provider.js +0 -620
  340. package/dist/chat/question.d.ts +0 -9
  341. package/dist/chat/question.d.ts.map +0 -1
  342. package/dist/chat/question.js +0 -80
  343. package/dist/chat/questions.d.ts.map +0 -1
  344. package/dist/chat/read.d.ts.map +0 -1
  345. package/dist/chat/ready.d.ts +0 -33
  346. package/dist/chat/ready.d.ts.map +0 -1
  347. package/dist/chat/ready.js +0 -91
  348. package/dist/chat/style.d.ts +0 -4
  349. package/dist/chat/style.d.ts.map +0 -1
  350. package/dist/chat/style.js +0 -302
  351. package/dist/chat.d.ts +0 -14
  352. package/dist/chat.d.ts.map +0 -1
  353. package/dist/chat.js +0 -8
  354. package/dist/fence.d.ts +0 -6
  355. package/dist/fence.d.ts.map +0 -1
  356. package/dist/fence.js +0 -10
  357. package/dist/read-side.d.ts +0 -18
  358. package/dist/read-side.d.ts.map +0 -1
  359. package/dist/read-side.js +0 -440
package/dist/shared.js ADDED
@@ -0,0 +1,421 @@
1
+ import { finished, ROW_WEIGHT } from './turn.js';
2
+ const BITS = 5;
3
+ const MASK = (1 << BITS) - 1;
4
+ const roots = new WeakMap();
5
+ function hashOf(key) {
6
+ let hash = 0x811c9dc5;
7
+ for (let index = 0; index < key.length; index += 1) {
8
+ hash ^= key.charCodeAt(index);
9
+ hash = Math.imul(hash, 0x01000193);
10
+ }
11
+ return hash >>> 0;
12
+ }
13
+ function isLeaf(node) {
14
+ return 'key' in node;
15
+ }
16
+ function isCollision(node) {
17
+ return 'leaves' in node;
18
+ }
19
+ function fragment(hash, shift) {
20
+ return (hash >>> shift) & MASK;
21
+ }
22
+ function count(bits) {
23
+ let left = bits - ((bits >>> 1) & 0x55555555);
24
+ left = (left & 0x33333333) + ((left >>> 2) & 0x33333333);
25
+ return (((left + (left >>> 4)) & 0x0f0f0f0f) * 0x01010101) >>> 24;
26
+ }
27
+ function slot(bitmap, bit) {
28
+ return count(bitmap & (bit - 1));
29
+ }
30
+ function lookup(root, key) {
31
+ const hash = hashOf(key);
32
+ let node = root.node;
33
+ let shift = 0;
34
+ while (node !== undefined) {
35
+ if (isLeaf(node))
36
+ return node.key === key ? node : undefined;
37
+ if (isCollision(node))
38
+ return node.leaves.find((leaf) => leaf.key === key);
39
+ const bit = 1 << fragment(hash, shift);
40
+ if ((node.bitmap & bit) === 0)
41
+ return undefined;
42
+ node = node.children[slot(node.bitmap, bit)];
43
+ shift += BITS;
44
+ }
45
+ return undefined;
46
+ }
47
+ function branchOf(node, shift) {
48
+ return { bitmap: 1 << fragment(node.hash, shift), children: [node] };
49
+ }
50
+ function joined(left, right, shift) {
51
+ if (left.hash === right.hash) {
52
+ const leaves = isCollision(left) ? left.leaves : [left];
53
+ return { hash: right.hash, leaves: [...leaves, right] };
54
+ }
55
+ return put(branchOf(left, shift), right, shift);
56
+ }
57
+ function put(node, leaf, shift) {
58
+ if (node === undefined)
59
+ return leaf;
60
+ if (isLeaf(node)) {
61
+ if (node.key !== leaf.key)
62
+ return joined(node, leaf, shift);
63
+ return node.value === leaf.value ? node : leaf;
64
+ }
65
+ if (isCollision(node)) {
66
+ if (node.hash !== leaf.hash)
67
+ return joined(node, leaf, shift);
68
+ const at = node.leaves.findIndex((held) => held.key === leaf.key);
69
+ if (at === -1)
70
+ return { hash: node.hash, leaves: [...node.leaves, leaf] };
71
+ if (node.leaves[at].value === leaf.value)
72
+ return node;
73
+ return {
74
+ hash: node.hash,
75
+ leaves: node.leaves.map((held, index) => (index === at ? leaf : held)),
76
+ };
77
+ }
78
+ const bit = 1 << fragment(leaf.hash, shift);
79
+ const at = slot(node.bitmap, bit);
80
+ if ((node.bitmap & bit) === 0) {
81
+ return {
82
+ bitmap: node.bitmap | bit,
83
+ children: [...node.children.slice(0, at), leaf, ...node.children.slice(at)],
84
+ };
85
+ }
86
+ const child = node.children[at];
87
+ const next = put(child, leaf, shift + BITS);
88
+ if (next === child)
89
+ return node;
90
+ return {
91
+ bitmap: node.bitmap,
92
+ children: node.children.map((held, index) => (index === at ? next : held)),
93
+ };
94
+ }
95
+ function lone(node) {
96
+ if (node.children.length !== 1)
97
+ return null;
98
+ const [only] = node.children;
99
+ return isLeaf(only) || isCollision(only) ? only : null;
100
+ }
101
+ function taken(node, hash, key, shift) {
102
+ if (isLeaf(node))
103
+ return node.key === key ? undefined : node;
104
+ if (isCollision(node)) {
105
+ const leaves = node.leaves.filter((leaf) => leaf.key !== key);
106
+ if (leaves.length === node.leaves.length)
107
+ return node;
108
+ return leaves.length === 1 ? leaves[0] : { hash: node.hash, leaves };
109
+ }
110
+ const bit = 1 << fragment(hash, shift);
111
+ if ((node.bitmap & bit) === 0)
112
+ return node;
113
+ const at = slot(node.bitmap, bit);
114
+ const child = node.children[at];
115
+ const next = taken(child, hash, key, shift + BITS);
116
+ if (next === child)
117
+ return node;
118
+ if (next === undefined) {
119
+ if (node.children.length === 1)
120
+ return undefined;
121
+ const rest = {
122
+ bitmap: node.bitmap & ~bit,
123
+ children: node.children.filter((_, index) => index !== at),
124
+ };
125
+ return lone(rest) ?? rest;
126
+ }
127
+ const replaced = {
128
+ bitmap: node.bitmap,
129
+ children: node.children.map((held, index) => (index === at ? next : held)),
130
+ };
131
+ return lone(replaced) ?? replaced;
132
+ }
133
+ function* leavesOf(node) {
134
+ if (node === undefined)
135
+ return;
136
+ if (isLeaf(node)) {
137
+ yield node;
138
+ return;
139
+ }
140
+ if (isCollision(node)) {
141
+ yield* node.leaves;
142
+ return;
143
+ }
144
+ for (const child of node.children)
145
+ yield* leavesOf(child);
146
+ }
147
+ function facade(root) {
148
+ let keys;
149
+ const target = {};
150
+ const map = new Proxy(target, {
151
+ get(held, property, receiver) {
152
+ if (typeof property === 'string') {
153
+ const leaf = lookup(root, property);
154
+ if (leaf !== undefined)
155
+ return leaf.value;
156
+ }
157
+ return Reflect.get(held, property, receiver);
158
+ },
159
+ has(held, property) {
160
+ return ((typeof property === 'string' && lookup(root, property) !== undefined) ||
161
+ Reflect.has(held, property));
162
+ },
163
+ ownKeys() {
164
+ keys ??= [...leavesOf(root.node)].map((leaf) => leaf.key);
165
+ return keys;
166
+ },
167
+ getOwnPropertyDescriptor(_held, property) {
168
+ if (typeof property !== 'string')
169
+ return undefined;
170
+ const leaf = lookup(root, property);
171
+ if (leaf === undefined)
172
+ return undefined;
173
+ return { value: leaf.value, writable: false, enumerable: true, configurable: true };
174
+ },
175
+ set: () => false,
176
+ defineProperty: () => false,
177
+ deleteProperty: () => false,
178
+ });
179
+ roots.set(map, root);
180
+ return map;
181
+ }
182
+ export function* entriesIn(map) {
183
+ const root = roots.get(map);
184
+ if (root === undefined) {
185
+ for (const key of Object.keys(map))
186
+ yield [key, map[key]];
187
+ return;
188
+ }
189
+ for (const leaf of leavesOf(root.node))
190
+ yield [leaf.key, leaf.value];
191
+ }
192
+ function* rooted(map) {
193
+ const held = roots.get(map);
194
+ if (held !== undefined)
195
+ return held;
196
+ let node;
197
+ let size = 0;
198
+ for (const [key, value] of entriesIn(map)) {
199
+ node = put(node, { key, hash: hashOf(key), value }, 0);
200
+ size += 1;
201
+ yield ROW_WEIGHT;
202
+ }
203
+ return { node, size };
204
+ }
205
+ const RUN = 1 << 10;
206
+ function* merged(left, right) {
207
+ const into = [];
208
+ let at = 0;
209
+ let from = 0;
210
+ while (at < left.length || from < right.length) {
211
+ into.push(from === right.length || (at < left.length && left[at] < right[from])
212
+ ? left[at++]
213
+ : right[from++]);
214
+ yield ROW_WEIGHT;
215
+ }
216
+ return into;
217
+ }
218
+ function* pathsOf(map) {
219
+ for (const [key] of entriesIn(map))
220
+ yield key;
221
+ }
222
+ export function* sortedKeys(map) {
223
+ return yield* sorting(pathsOf(map));
224
+ }
225
+ export function* sorting(keys) {
226
+ let runs = [];
227
+ let run = [];
228
+ for (const key of keys) {
229
+ run.push(key);
230
+ yield ROW_WEIGHT;
231
+ if (run.length === RUN) {
232
+ runs.push(run.sort());
233
+ run = [];
234
+ }
235
+ }
236
+ if (run.length > 0)
237
+ runs.push(run.sort());
238
+ while (runs.length > 1) {
239
+ const next = [];
240
+ for (let at = 0; at < runs.length; at += 2) {
241
+ next.push(at + 1 === runs.length ? runs[at] : yield* merged(runs[at], runs[at + 1]));
242
+ }
243
+ runs = next;
244
+ }
245
+ return runs[0] ?? [];
246
+ }
247
+ export function* sharing(map) {
248
+ return roots.has(map) ? map : facade(yield* rooted(map));
249
+ }
250
+ export function shared(map) {
251
+ return finished(sharing(map));
252
+ }
253
+ export function patched(base, set, removed = []) {
254
+ return finished(patching(base, set, removed));
255
+ }
256
+ export function* patching(base, set, removed = []) {
257
+ const root = yield* rooted(base);
258
+ let node = root.node;
259
+ let size = root.size;
260
+ for (const key of removed) {
261
+ if (node === undefined)
262
+ break;
263
+ const before = lookup({ node, size }, key);
264
+ if (before === undefined)
265
+ continue;
266
+ node = taken(node, before.hash, key, 0);
267
+ size -= 1;
268
+ yield ROW_WEIGHT;
269
+ }
270
+ for (const [key, value] of set) {
271
+ const before = lookup({ node, size }, key);
272
+ node = put(node, { key, hash: hashOf(key), value }, 0);
273
+ if (before === undefined)
274
+ size += 1;
275
+ yield ROW_WEIGHT;
276
+ }
277
+ if (node === root.node && roots.has(base))
278
+ return base;
279
+ return facade({ node, size });
280
+ }
281
+ export function sizeOf(map) {
282
+ return roots.get(map)?.size ?? Object.keys(map).length;
283
+ }
284
+ function* compared(left, right, same, into) {
285
+ const pending = [[left, right]];
286
+ for (let pair = pending.pop(); pair !== undefined; pair = pending.pop()) {
287
+ const [one, other] = pair;
288
+ if (one === other)
289
+ continue;
290
+ if (one !== undefined &&
291
+ other !== undefined &&
292
+ !isLeaf(one) &&
293
+ !isCollision(one) &&
294
+ !isLeaf(other) &&
295
+ !isCollision(other)) {
296
+ const children = [];
297
+ for (let remaining = one.bitmap | other.bitmap; remaining !== 0; remaining &= remaining - 1) {
298
+ const bit = remaining & -remaining;
299
+ children.push([
300
+ (one.bitmap & bit) === 0 ? undefined : one.children[slot(one.bitmap, bit)],
301
+ (other.bitmap & bit) === 0 ? undefined : other.children[slot(other.bitmap, bit)],
302
+ ]);
303
+ }
304
+ pending.push(...children.reverse());
305
+ continue;
306
+ }
307
+ const before = new Map();
308
+ for (const leaf of leavesOf(one)) {
309
+ before.set(leaf.key, leaf.value);
310
+ yield ROW_WEIGHT;
311
+ }
312
+ for (const leaf of leavesOf(other)) {
313
+ const held = before.get(leaf.key);
314
+ before.delete(leaf.key);
315
+ if (held === undefined || !same(held, leaf.value))
316
+ into.add(leaf.key);
317
+ yield ROW_WEIGHT;
318
+ }
319
+ for (const key of before.keys())
320
+ into.add(key);
321
+ }
322
+ }
323
+ export function* differences(left, right, same = Object.is) {
324
+ const into = new Set();
325
+ if (left === right)
326
+ return into;
327
+ const leftRoot = roots.get(left);
328
+ const rightRoot = roots.get(right);
329
+ if (leftRoot !== undefined && rightRoot !== undefined) {
330
+ yield* compared(leftRoot.node, rightRoot.node, same, into);
331
+ return into;
332
+ }
333
+ for (const [key, value] of entriesIn(left)) {
334
+ if (!Object.hasOwn(right, key) || !same(value, right[key]))
335
+ into.add(key);
336
+ yield ROW_WEIGHT;
337
+ }
338
+ for (const [key] of entriesIn(right)) {
339
+ if (!Object.hasOwn(left, key))
340
+ into.add(key);
341
+ yield ROW_WEIGHT;
342
+ }
343
+ return into;
344
+ }
345
+ export function differing(left, right, same = Object.is) {
346
+ return finished(differences(left, right, same));
347
+ }
348
+ const drafts = new WeakMap();
349
+ const GONE = Symbol('gone');
350
+ export function drafted(base) {
351
+ const written = new Map();
352
+ const read = (key) => {
353
+ const held = written.get(key);
354
+ if (held === GONE)
355
+ return undefined;
356
+ return held ?? (Object.hasOwn(base, key) ? base[key] : undefined);
357
+ };
358
+ const draft = new Proxy({}, {
359
+ get(held, property, receiver) {
360
+ if (typeof property === 'string') {
361
+ const value = read(property);
362
+ if (value !== undefined)
363
+ return value;
364
+ }
365
+ return Reflect.get(held, property, receiver);
366
+ },
367
+ has(held, property) {
368
+ return ((typeof property === 'string' && read(property) !== undefined) ||
369
+ Reflect.has(held, property));
370
+ },
371
+ ownKeys() {
372
+ const keys = new Set(Object.keys(base));
373
+ for (const [key, value] of written) {
374
+ if (value === GONE)
375
+ keys.delete(key);
376
+ else
377
+ keys.add(key);
378
+ }
379
+ return [...keys];
380
+ },
381
+ getOwnPropertyDescriptor(_held, property) {
382
+ if (typeof property !== 'string')
383
+ return undefined;
384
+ const value = read(property);
385
+ if (value === undefined)
386
+ return undefined;
387
+ return { value, writable: true, enumerable: true, configurable: true };
388
+ },
389
+ set(_held, property, value) {
390
+ if (typeof property !== 'string')
391
+ return false;
392
+ written.set(property, value);
393
+ return true;
394
+ },
395
+ deleteProperty(_held, property) {
396
+ if (typeof property !== 'string')
397
+ return false;
398
+ written.set(property, GONE);
399
+ return true;
400
+ },
401
+ defineProperty: () => false,
402
+ });
403
+ drafts.set(draft, { base, written });
404
+ return draft;
405
+ }
406
+ export function settled(draft) {
407
+ return finished(settling(draft));
408
+ }
409
+ export function* settling(draft) {
410
+ const held = drafts.get(draft);
411
+ const set = [];
412
+ const removed = [];
413
+ for (const [key, value] of held.written) {
414
+ if (value === GONE)
415
+ removed.push(key);
416
+ else
417
+ set.push([key, value]);
418
+ yield ROW_WEIGHT;
419
+ }
420
+ return yield* patching(held.base, set, removed);
421
+ }
@@ -0,0 +1,31 @@
1
+ import type { DiscoveredRoom, Member } from './adapter.js';
2
+ import type { ChangeSet } from './change-set.js';
3
+ import type { QueueEntry } from './outcome.js';
4
+ import type { Runtime } from './runtime.js';
5
+ import type { Live, Moving } from './socket.js';
6
+ import { type CycleProgress } from './status.js';
7
+ export declare const ROOMS_TOPIC = "rooms";
8
+ export declare const STATUS_TOPIC = "sync-status";
9
+ export declare const REFUSAL_TOPIC = "connection-refusal";
10
+ export declare const STORAGE_LOSS_TOPIC = "storage-loss";
11
+ export declare const SERVICE_MODE_TOPIC = "service-mode";
12
+ export declare const MEMBER_TOPIC = "member";
13
+ export declare const AUTHORITY_TOPIC = "authority-changes";
14
+ export declare const LOCKS_TOPIC = "locks";
15
+ export declare const queueTopic: (locator: string) => string;
16
+ export declare function recoverReads({ liveQueries, figures }: Runtime): void;
17
+ export declare function emitRooms(runtime: Runtime, changed?: readonly string[]): Promise<void>;
18
+ export declare function emitKnownRooms(runtime: Runtime): void;
19
+ export declare function emitRefusal(runtime: Runtime): void;
20
+ export declare function emitStorageLoss({ store }: Runtime): void;
21
+ export declare function emitMember({ store }: Runtime, member: Member | null): void;
22
+ export declare function show(runtime: Runtime): Promise<void>;
23
+ export declare function moveTo(runtime: Runtime, next: Moving): Promise<void>;
24
+ export declare function statusShown(runtime: Runtime): Promise<void>;
25
+ export declare function transferring({ socket }: Runtime): Moving;
26
+ export declare function pendingShown(runtime: Runtime): Promise<void>;
27
+ export declare function entriesOf(runtime: Runtime, locator: string): Promise<readonly QueueEntry[]>;
28
+ export declare function publishChangeSet(runtime: Runtime, set: ChangeSet): Promise<void>;
29
+ export declare function roomUnreadable(runtime: Runtime, room: DiscoveredRoom): void;
30
+ export declare function rest(runtime: Runtime, progress: CycleProgress | null, live?: Live): Promise<void>;
31
+ //# sourceMappingURL=shown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shown.d.ts","sourceRoot":"","sources":["../src/shown.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAA6B,KAAK,aAAa,EAAmB,MAAM,aAAa,CAAC;AAiB7F,eAAO,MAAM,WAAW,UAAU,CAAC;AAEnC,eAAO,MAAM,YAAY,gBAAgB,CAAC;AAE1C,eAAO,MAAM,aAAa,uBAAuB,CAAC;AAElD,eAAO,MAAM,kBAAkB,iBAAiB,CAAC;AAEjD,eAAO,MAAM,kBAAkB,iBAAiB,CAAC;AAEjD,eAAO,MAAM,YAAY,WAAW,CAAC;AAErC,eAAO,MAAM,eAAe,sBAAsB,CAAC;AAEnD,eAAO,MAAM,WAAW,UAAU,CAAC;AAEnC,eAAO,MAAM,UAAU,YAAa,MAAM,WAA4B,CAAC;AA0CvE,wBAAgB,YAAY,CAAC,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE,OAAO,QAG7D;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAMtF;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,QAI9C;AA8ED,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,QAK3C;AAED,wBAAgB,eAAe,CAAC,EAAE,KAAK,EAAE,EAAE,OAAO,QAGjD;AAED,wBAAgB,UAAU,CAAC,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,QAEnE;AAsBD,wBAAgB,IAAI,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAepD;AAED,wBAAgB,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAIpE;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAE3D;AAED,wBAAgB,YAAY,CAAC,EAAE,MAAM,EAAE,EAAE,OAAO,GAAG,MAAM,CAExD;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAK5D;AAYD,wBAAsB,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,UAAU,EAAE,CAAC,CAKjG;AAcD,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAuBhF;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,cAAc,QAIpE;AAED,wBAAsB,IAAI,CACxB,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,aAAa,GAAG,IAAI,EAC9B,IAAI,GAAE,IAAqC,iBAgC5C"}