@agentshouse/mdruntime 0.1.0-c698c0ebd65bd → 0.1.0-c6dd3e87e3f5e

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 (229) hide show
  1. package/README.md +18 -15
  2. package/dist/adapter.d.ts +125 -50
  3. package/dist/adapter.d.ts.map +1 -1
  4. package/dist/attached-model.d.ts +5 -1
  5. package/dist/attached-model.d.ts.map +1 -1
  6. package/dist/attached-model.js +38 -4
  7. package/dist/binary.d.ts +0 -5
  8. package/dist/binary.d.ts.map +1 -1
  9. package/dist/binary.js +1 -1
  10. package/dist/bootstrap.d.ts +27 -11
  11. package/dist/bootstrap.d.ts.map +1 -1
  12. package/dist/bootstrap.js +184 -85
  13. package/dist/chain.d.ts +11 -0
  14. package/dist/chain.d.ts.map +1 -0
  15. package/dist/chain.js +64 -0
  16. package/dist/change-set.d.ts +9 -14
  17. package/dist/change-set.d.ts.map +1 -1
  18. package/dist/change-set.js +11 -63
  19. package/dist/change.d.ts +31 -1
  20. package/dist/change.d.ts.map +1 -1
  21. package/dist/change.js +10 -1
  22. package/dist/client.d.ts +25 -14
  23. package/dist/client.d.ts.map +1 -1
  24. package/dist/client.js +97 -11
  25. package/dist/collection.d.ts +10 -7
  26. package/dist/collection.d.ts.map +1 -1
  27. package/dist/collection.js +38 -79
  28. package/dist/compile.d.ts +16 -0
  29. package/dist/compile.d.ts.map +1 -0
  30. package/dist/compile.js +786 -0
  31. package/dist/connection.d.ts +44 -17
  32. package/dist/connection.d.ts.map +1 -1
  33. package/dist/connection.js +3496 -976
  34. package/dist/conversation.d.ts +33 -14
  35. package/dist/conversation.d.ts.map +1 -1
  36. package/dist/conversation.js +571 -242
  37. package/dist/digest.d.ts +7 -0
  38. package/dist/digest.d.ts.map +1 -0
  39. package/dist/digest.js +113 -0
  40. package/dist/durability.d.ts +4 -1
  41. package/dist/durability.d.ts.map +1 -1
  42. package/dist/durability.js +5 -0
  43. package/dist/entry.d.ts +6 -3
  44. package/dist/entry.d.ts.map +1 -1
  45. package/dist/entry.js +18 -23
  46. package/dist/file.d.ts +2 -19
  47. package/dist/file.d.ts.map +1 -1
  48. package/dist/file.js +7 -122
  49. package/dist/fulltext.d.ts +27 -0
  50. package/dist/fulltext.d.ts.map +1 -0
  51. package/dist/fulltext.js +370 -0
  52. package/dist/host.d.ts +12 -3
  53. package/dist/host.d.ts.map +1 -1
  54. package/dist/host.js +125 -19
  55. package/dist/identity.d.ts +1 -0
  56. package/dist/identity.d.ts.map +1 -1
  57. package/dist/identity.js +3 -0
  58. package/dist/index.d.ts +16 -10
  59. package/dist/index.d.ts.map +1 -1
  60. package/dist/index.js +6 -0
  61. package/dist/live.d.ts +22 -0
  62. package/dist/live.d.ts.map +1 -0
  63. package/dist/live.js +123 -0
  64. package/dist/media.d.ts +8 -0
  65. package/dist/media.d.ts.map +1 -0
  66. package/dist/media.js +218 -0
  67. package/dist/memory.d.ts +14 -6
  68. package/dist/memory.d.ts.map +1 -1
  69. package/dist/memory.js +198 -94
  70. package/dist/messages.d.ts +28 -0
  71. package/dist/messages.d.ts.map +1 -0
  72. package/dist/messages.js +90 -0
  73. package/dist/model.d.ts +9 -2
  74. package/dist/model.d.ts.map +1 -1
  75. package/dist/model.js +8 -2
  76. package/dist/name.d.ts +4 -0
  77. package/dist/name.d.ts.map +1 -0
  78. package/dist/name.js +122 -0
  79. package/dist/observation.d.ts +20 -2
  80. package/dist/observation.d.ts.map +1 -1
  81. package/dist/observation.js +113 -12
  82. package/dist/opened.d.ts +22 -0
  83. package/dist/opened.d.ts.map +1 -0
  84. package/dist/opened.js +107 -0
  85. package/dist/outcome.d.ts +45 -7
  86. package/dist/outcome.d.ts.map +1 -1
  87. package/dist/outcome.js +39 -0
  88. package/dist/overlay.d.ts +3 -4
  89. package/dist/overlay.d.ts.map +1 -1
  90. package/dist/overlay.js +100 -182
  91. package/dist/paths.d.ts +1 -0
  92. package/dist/paths.d.ts.map +1 -1
  93. package/dist/paths.js +4 -0
  94. package/dist/query.d.ts +66 -4
  95. package/dist/query.d.ts.map +1 -1
  96. package/dist/query.js +48 -7
  97. package/dist/reach.d.ts +18 -6
  98. package/dist/reach.d.ts.map +1 -1
  99. package/dist/reach.js +220 -73
  100. package/dist/react.d.ts +8 -6
  101. package/dist/react.d.ts.map +1 -1
  102. package/dist/react.js +7 -17
  103. package/dist/readiness.d.ts +52 -0
  104. package/dist/readiness.d.ts.map +1 -0
  105. package/dist/readiness.js +27 -0
  106. package/dist/recovery.d.ts +26 -0
  107. package/dist/recovery.d.ts.map +1 -0
  108. package/dist/recovery.js +224 -0
  109. package/dist/refresh.d.ts +16 -14
  110. package/dist/refresh.d.ts.map +1 -1
  111. package/dist/refresh.js +115 -51
  112. package/dist/replica.d.ts +55 -33
  113. package/dist/replica.d.ts.map +1 -1
  114. package/dist/replica.js +297 -154
  115. package/dist/room-draft.d.ts +34 -4
  116. package/dist/room-draft.d.ts.map +1 -1
  117. package/dist/room-draft.js +105 -31
  118. package/dist/rows.d.ts +37 -37
  119. package/dist/rows.d.ts.map +1 -1
  120. package/dist/rows.js +173 -104
  121. package/dist/save.d.ts +53 -9
  122. package/dist/save.d.ts.map +1 -1
  123. package/dist/save.js +537 -170
  124. package/dist/search.d.ts +39 -28
  125. package/dist/search.d.ts.map +1 -1
  126. package/dist/search.js +37 -105
  127. package/dist/seed.d.ts +16 -0
  128. package/dist/seed.d.ts.map +1 -0
  129. package/dist/seed.js +75 -0
  130. package/dist/shared.d.ts +15 -0
  131. package/dist/shared.d.ts.map +1 -0
  132. package/dist/shared.js +421 -0
  133. package/dist/status.d.ts +5 -0
  134. package/dist/status.d.ts.map +1 -1
  135. package/dist/status.js +3 -1
  136. package/dist/store.d.ts +96 -80
  137. package/dist/store.d.ts.map +1 -1
  138. package/dist/store.js +306 -523
  139. package/dist/stored.d.ts +130 -0
  140. package/dist/stored.d.ts.map +1 -0
  141. package/dist/stored.js +560 -0
  142. package/dist/tables.d.ts +325 -0
  143. package/dist/tables.d.ts.map +1 -0
  144. package/dist/tables.js +578 -0
  145. package/dist/transfer.d.ts +0 -5
  146. package/dist/transfer.d.ts.map +1 -1
  147. package/dist/turn.d.ts +9 -0
  148. package/dist/turn.d.ts.map +1 -0
  149. package/dist/turn.js +75 -0
  150. package/dist/validation.d.ts +29 -0
  151. package/dist/validation.d.ts.map +1 -0
  152. package/dist/validation.js +101 -0
  153. package/dist/windows.d.ts +22 -0
  154. package/dist/windows.d.ts.map +1 -0
  155. package/dist/windows.js +89 -0
  156. package/dist/wire.d.ts +164 -32
  157. package/dist/wire.d.ts.map +1 -1
  158. package/dist/wire.js +55 -31
  159. package/dist/words.d.ts +19 -0
  160. package/dist/words.d.ts.map +1 -0
  161. package/dist/words.js +156 -0
  162. package/package.json +18 -19
  163. package/AGENTS.md +0 -299
  164. package/dist/chat/acts.d.ts +0 -33
  165. package/dist/chat/acts.d.ts.map +0 -1
  166. package/dist/chat/acts.js +0 -36
  167. package/dist/chat/context.d.ts +0 -3
  168. package/dist/chat/context.d.ts.map +0 -1
  169. package/dist/chat/context.js +0 -10
  170. package/dist/chat/input.d.ts +0 -9
  171. package/dist/chat/input.d.ts.map +0 -1
  172. package/dist/chat/input.js +0 -99
  173. package/dist/chat/kit.d.ts +0 -60
  174. package/dist/chat/kit.d.ts.map +0 -1
  175. package/dist/chat/kit.js +0 -123
  176. package/dist/chat/lasting.d.ts +0 -6
  177. package/dist/chat/lasting.d.ts.map +0 -1
  178. package/dist/chat/lasting.js +0 -19
  179. package/dist/chat/list.d.ts +0 -26
  180. package/dist/chat/list.d.ts.map +0 -1
  181. package/dist/chat/list.js +0 -62
  182. package/dist/chat/markdown.d.ts +0 -20
  183. package/dist/chat/markdown.d.ts.map +0 -1
  184. package/dist/chat/markdown.js +0 -188
  185. package/dist/chat/message.d.ts +0 -6
  186. package/dist/chat/message.d.ts.map +0 -1
  187. package/dist/chat/message.js +0 -192
  188. package/dist/chat/messages.d.ts +0 -21
  189. package/dist/chat/messages.d.ts.map +0 -1
  190. package/dist/chat/messages.js +0 -151
  191. package/dist/chat/name.d.ts +0 -6
  192. package/dist/chat/name.d.ts.map +0 -1
  193. package/dist/chat/name.js +0 -37
  194. package/dist/chat/opened.d.ts +0 -11
  195. package/dist/chat/opened.d.ts.map +0 -1
  196. package/dist/chat/opened.js +0 -17
  197. package/dist/chat/overlay.d.ts +0 -31
  198. package/dist/chat/overlay.d.ts.map +0 -1
  199. package/dist/chat/overlay.js +0 -97
  200. package/dist/chat/parts.d.ts +0 -57
  201. package/dist/chat/parts.d.ts.map +0 -1
  202. package/dist/chat/parts.js +0 -119
  203. package/dist/chat/process.d.ts +0 -20
  204. package/dist/chat/process.d.ts.map +0 -1
  205. package/dist/chat/process.js +0 -32
  206. package/dist/chat/provider.d.ts +0 -63
  207. package/dist/chat/provider.d.ts.map +0 -1
  208. package/dist/chat/provider.js +0 -620
  209. package/dist/chat/question.d.ts +0 -9
  210. package/dist/chat/question.d.ts.map +0 -1
  211. package/dist/chat/question.js +0 -80
  212. package/dist/chat/questions.d.ts +0 -31
  213. package/dist/chat/questions.d.ts.map +0 -1
  214. package/dist/chat/questions.js +0 -111
  215. package/dist/chat/read.d.ts +0 -5
  216. package/dist/chat/read.d.ts.map +0 -1
  217. package/dist/chat/read.js +0 -13
  218. package/dist/chat/ready.d.ts +0 -33
  219. package/dist/chat/ready.d.ts.map +0 -1
  220. package/dist/chat/ready.js +0 -91
  221. package/dist/chat/style.d.ts +0 -4
  222. package/dist/chat/style.d.ts.map +0 -1
  223. package/dist/chat/style.js +0 -302
  224. package/dist/chat.d.ts +0 -14
  225. package/dist/chat.d.ts.map +0 -1
  226. package/dist/chat.js +0 -8
  227. package/dist/read-side.d.ts +0 -18
  228. package/dist/read-side.d.ts.map +0 -1
  229. 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
+ }
package/dist/status.d.ts CHANGED
@@ -5,11 +5,16 @@ export type AttentionEntry = {
5
5
  path: string;
6
6
  returned: ReturnReason;
7
7
  };
8
+ export type UnsentChange = {
9
+ room: string;
10
+ path: string;
11
+ };
8
12
  export type SyncStatus = {
9
13
  state: Open<'pending' | 'syncing' | 'synced'>;
10
14
  lastCompleted: string | null;
11
15
  providerUnreachable: boolean;
12
16
  attentionRequired: readonly AttentionEntry[];
17
+ unsent: readonly UnsentChange[];
13
18
  reset: string | null;
14
19
  };
15
20
  export type CycleProgress = {
@@ -1 +1 @@
1
- {"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../src/status.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,YAAY,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,KAAK,EAAE,IAAI,CAAC,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAC,CAAC;IAC9C,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,mBAAmB,EAAE,OAAO,CAAC;IAC7B,iBAAiB,EAAE,SAAS,cAAc,EAAE,CAAC;IAC7C,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,eAAO,MAAM,QAAQ,EAAE,UAMtB,CAAC;AAEF,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAE3D;AAED,wBAAgB,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAErD;AAED,wBAAgB,IAAI,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAQhE"}
1
+ {"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../src/status.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,MAAM,MAAM,cAAc,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,YAAY,CAAA;CAAE,CAAC;AAEpF,MAAM,MAAM,YAAY,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1D,MAAM,MAAM,UAAU,GAAG;IACvB,KAAK,EAAE,IAAI,CAAC,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAC,CAAC;IAC9C,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,mBAAmB,EAAE,OAAO,CAAC;IAC7B,iBAAiB,EAAE,SAAS,cAAc,EAAE,CAAC;IAC7C,MAAM,EAAE,SAAS,YAAY,EAAE,CAAC;IAChC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,eAAO,MAAM,QAAQ,EAAE,UAOtB,CAAC;AAEF,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAE3D;AAED,wBAAgB,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAErD;AAED,wBAAgB,IAAI,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAShE"}
package/dist/status.js CHANGED
@@ -3,6 +3,7 @@ export const STARTING = {
3
3
  lastCompleted: null,
4
4
  providerUnreachable: false,
5
5
  attentionRequired: [],
6
+ unsent: [],
6
7
  reset: null,
7
8
  };
8
9
  export function transferring(status) {
@@ -16,5 +17,6 @@ export function same(one, other) {
16
17
  one.lastCompleted === other.lastCompleted &&
17
18
  one.providerUnreachable === other.providerUnreachable &&
18
19
  one.reset === other.reset &&
19
- JSON.stringify(one.attentionRequired) === JSON.stringify(other.attentionRequired));
20
+ JSON.stringify(one.attentionRequired) === JSON.stringify(other.attentionRequired) &&
21
+ JSON.stringify(one.unsent) === JSON.stringify(other.unsent));
20
22
  }
package/dist/store.d.ts CHANGED
@@ -1,50 +1,37 @@
1
- import type { ModelState } from './model.js';
2
- import type { Capability, HeadChange, Member, OperationScopes, ProviderLimit, ReplicaAdmission, TypedSelection } from './adapter.js';
3
- import type { AcceptedMessage } from './adapter.js';
1
+ import type { BootstrapInventory, Capability, ListedConversation, Member, ProviderLimit } from './adapter.js';
4
2
  import type { ChangeBatch } from './change.js';
5
- import { type HeldBinary } from './overlay.js';
6
- import type { ChatDraftFile } from './file.js';
3
+ import { type Composition } from './collection.js';
4
+ import type { Plan } from './query.js';
5
+ import type { ReplicaRecord } from './replica.js';
7
6
  import type { Submission } from './outcome.js';
8
7
  import type { RoomDraftRecord, SavedDraft } from './room-draft.js';
9
- export declare const STORE_SCHEMA = 23;
10
- export declare const AUTHORED_SCHEMA = 2;
11
- export type ReplicaRecord = {
12
- locator: string;
13
- name: string;
14
- handle: string;
15
- operations: OperationScopes;
16
- replica: ReplicaAdmission;
17
- model: ModelState;
18
- typedSelection: TypedSelection | null;
19
- selectionModel: ModelState;
20
- providerOwnedPaths: readonly string[];
21
- roomVersion: string;
22
- transfer: string;
23
- documents: Readonly<Record<string, string>>;
24
- binaries: Readonly<Record<string, HeldBinary>>;
25
- revisions: Readonly<Record<string, string>>;
26
- changes: Readonly<Record<string, HeadChange>>;
27
- written: Readonly<Record<string, string>>;
28
- };
29
- export type StagedLayer = Pick<ReplicaRecord, 'documents' | 'binaries' | 'revisions' | 'changes' | 'written'>;
8
+ import type { ModelState, StoredModel } from './model.js';
9
+ import type { SearchWindow } from './search.js';
10
+ import type { CommittedWrite, ConversationWrite, CountedRoom, HeldConversation, HeldEntry, MessageWindow, QueryAnswer, QueryRoom, Referrer, RoomCommit, RuntimeDatabase, SearchAsk, StoredEntry, StoredFile, TypedEntry, View } from './tables.js';
11
+ export type { ConversationWrite, HeldConversation, MessageWindow } from './tables.js';
30
12
  export type TransferRecord = {
31
- locator: string;
32
- transfer: string;
33
- selection: string;
34
- from: string;
35
- last: string;
36
- pageToken: string | null;
37
- models: {
38
- collection: ModelState;
39
- selection: ModelState;
13
+ readonly locator: string;
14
+ readonly transfer: string;
15
+ readonly selection: string;
16
+ readonly from: string;
17
+ readonly last: string;
18
+ readonly done: BootstrapInventory;
19
+ readonly models: {
20
+ readonly collection: ModelState;
40
21
  };
22
+ readonly key: number | null;
23
+ };
24
+ export type StoredReplica = Omit<ReplicaRecord, 'model'> & {
25
+ readonly model: StoredModel;
41
26
  };
42
27
  export type PendingState = {
43
28
  readonly drafts: readonly SavedDraft[];
44
29
  readonly submission: Submission;
45
30
  readonly lost: boolean;
46
31
  readonly upload?: unknown;
47
- readonly accepted?: string;
32
+ };
33
+ export type TargetRecord = {
34
+ established: boolean;
48
35
  };
49
36
  export type QueueRecord = {
50
37
  locator: string;
@@ -57,82 +44,111 @@ export type PresentationRecord = {
57
44
  app: string;
58
45
  value: unknown;
59
46
  };
60
- export type HeldConversation = {
61
- conversation: string;
62
- read: string | null | undefined;
63
- messages: readonly AcceptedMessage[];
64
- };
65
- export type ConversationWrite = {
66
- conversation: string;
67
- messages: readonly AcceptedMessage[];
68
- read?: string | null;
69
- };
70
47
  export type ChatSubmission = {
71
48
  readonly operation: string;
72
49
  readonly text: string;
73
- readonly files: readonly ChatDraftFile[];
74
50
  readonly turn: string | null;
75
51
  };
76
52
  export type ChatDraftRecord = {
77
53
  conversation: string;
78
54
  text: string;
79
- files: readonly ChatDraftFile[];
80
55
  revision: string;
81
56
  submitted?: readonly ChatSubmission[];
57
+ moves?: readonly string[];
82
58
  };
83
- export type RecordWrite = {
84
- next: ReplicaRecord;
85
- previous: ReplicaRecord | null;
86
- stored?: StagedLayer;
59
+ export type CallRecord = {
60
+ readonly operation: string;
61
+ readonly name: string;
62
+ readonly input: unknown;
87
63
  };
88
64
  export type AuthoredWrite = {
89
65
  locator: string;
90
- queue: readonly ChangeBatch[];
66
+ queue?: readonly ChangeBatch[];
67
+ founded?: readonly ChangeBatch[];
91
68
  saved?: ReadonlyMap<string, readonly SavedDraft[]>;
92
69
  roomDrafts?: readonly RoomDraftRecord[];
93
70
  consumedRoomDrafts?: readonly string[];
94
71
  };
72
+ export type StagedPage = {
73
+ readonly entries: readonly StoredEntry[];
74
+ readonly folders: readonly string[];
75
+ };
76
+ export type RefreshedPage = StagedPage & {
77
+ readonly removals: readonly string[];
78
+ readonly folderRemovals: readonly string[];
79
+ };
80
+ export type Opened = {
81
+ readonly rooms: ReadonlyMap<string, StoredReplica>;
82
+ readonly unindexed: ReadonlySet<number>;
83
+ readonly overlaid: ReadonlyMap<number, ReadonlySet<string>>;
84
+ readonly erasing: boolean;
85
+ readonly orphans: readonly number[];
86
+ readonly lastCompleted: string | null;
87
+ readonly providerLimits: readonly ProviderLimit[];
88
+ readonly capabilities: readonly Capability[];
89
+ readonly member: Member | null;
90
+ readonly targets: Readonly<Record<string, TargetRecord>>;
91
+ readonly presentation: readonly PresentationRecord[];
92
+ readonly conversationList: readonly ListedConversation[] | null;
93
+ };
94
+ export type Commit = {
95
+ readonly rooms: readonly RoomCommit[];
96
+ readonly writes?: readonly AuthoredWrite[];
97
+ readonly files?: readonly StoredFile[];
98
+ readonly whole?: boolean;
99
+ readonly discards?: readonly string[];
100
+ };
95
101
  export type RuntimeStore = {
96
- all(): Promise<readonly ReplicaRecord[]>;
97
- keepAuthored(input: AuthoredWrite): Promise<void>;
98
- write(input: RecordWrite): Promise<void>;
99
- revokeModels(records: readonly ReplicaRecord[]): Promise<void>;
100
- lastCompleted(): Promise<string | null>;
101
- complete(at: string): Promise<void>;
102
- providerLimits(): Promise<readonly ProviderLimit[]>;
103
- capabilities(): Promise<readonly Capability[]>;
104
- declare(limits: readonly ProviderLimit[], capabilities: readonly Capability[]): Promise<void>;
105
- member(): Promise<Member | null>;
106
- keepMember(member: Member | null): Promise<void>;
102
+ opened(): Promise<Opened>;
103
+ counts(rooms: readonly CountedRoom[]): Promise<readonly number[]>;
104
+ query(plan: Plan, rooms: readonly QueryRoom[], budget: number | null): Promise<QueryAnswer>;
105
+ changes(keys: readonly number[]): number;
106
+ entries(key: number, view: View, paths: readonly string[]): Promise<readonly HeldEntry[]>;
107
+ typed(key: number, view: View, paths: readonly string[]): Promise<readonly TypedEntry[]>;
108
+ referrers(key: number, view: View, targets: readonly string[], kinds: readonly string[]): Promise<readonly Referrer[]>;
109
+ files(key: number, view: View, after: string | null, limit: number): Promise<readonly {
110
+ readonly path: string;
111
+ readonly revision: string;
112
+ }[]>;
113
+ folders(key: number, view: View, paths: readonly string[]): Promise<readonly string[]>;
114
+ typedWithin(key: number, view: View, roots: readonly string[], within: boolean): Promise<boolean>;
115
+ search(ask: SearchAsk): Promise<SearchWindow>;
116
+ stage(record: TransferRecord, composition: Composition, page: StagedPage): Promise<number | null>;
117
+ refresh(key: number, composition: Composition, page: RefreshedPage): Promise<void>;
118
+ unrefresh(key: number): Promise<void>;
119
+ commit(commit: Commit): Promise<CommittedWrite>;
120
+ fence(locators: readonly string[]): Promise<void>;
121
+ erase(locator: string | null, limit: number): Promise<boolean>;
122
+ abandon(locator: string): Promise<void>;
123
+ release(key: number): Promise<void>;
124
+ rederive(key: number, composition: Composition, bytes: number, ms: number, floor: number): Promise<{
125
+ readonly done: boolean;
126
+ readonly text: number;
127
+ }>;
128
+ fact(name: string, value: unknown): Promise<void>;
107
129
  queues(): Promise<readonly QueueRecord[]>;
108
130
  submit(locator: string, id: string, submission: Submission, lost: boolean): Promise<void>;
109
- accept(locator: string, id: string, roomVersion: string): Promise<void>;
110
131
  keepUpload(locator: string, id: string, upload: unknown): Promise<void>;
111
132
  roomDrafts(): Promise<readonly RoomDraftRecord[]>;
112
- presentation(): Promise<readonly PresentationRecord[]>;
113
133
  present(record: PresentationRecord): Promise<void>;
114
134
  conversations(): Promise<readonly HeldConversation[]>;
115
135
  keepMessages(write: ConversationWrite): Promise<void>;
136
+ messageWindow(conversation: string, limit: number, before: readonly [string, string] | null): Promise<MessageWindow>;
137
+ messageCount(conversation: string): Promise<number>;
138
+ turnArrived(conversation: string, turn: string): Promise<boolean>;
116
139
  dropConversations(conversations: readonly string[]): Promise<void>;
117
140
  chatDrafts(): Promise<readonly ChatDraftRecord[]>;
118
- keepChatDraft(record: ChatDraftRecord): Promise<void>;
141
+ keepChatDrafts(records: readonly ChatDraftRecord[]): Promise<void>;
119
142
  dropChatDraft(conversation: string): Promise<void>;
120
- keepRoomDraft(record: RoomDraftRecord): Promise<void>;
143
+ calls(): Promise<readonly CallRecord[]>;
144
+ keepCall(record: CallRecord): Promise<void>;
145
+ dropCall(operation: string): Promise<void>;
146
+ keepRoomDraft(record: RoomDraftRecord, files: readonly StoredFile[]): Promise<void>;
121
147
  discardRoomDraft(locator: string, path: string): Promise<void>;
122
148
  fences(): Promise<readonly string[]>;
123
- erase(locators: readonly string[]): Promise<void>;
124
- transfers(): Promise<readonly TransferRecord[]>;
125
- staged(record: TransferRecord): Promise<StagedLayer>;
126
- stage(record: TransferRecord, page: StagedLayer): Promise<void>;
127
- abandon(locator: string): Promise<void>;
128
149
  generation(): Promise<string | null>;
129
150
  rememberGeneration(value: string): Promise<void>;
130
- close(): void;
151
+ file(key: string, type: string): Promise<Blob>;
131
152
  };
132
- export declare function authoredHolder(): Promise<string | null>;
133
- export declare function authoredBy(holder: string): Promise<boolean>;
134
- export declare function authoredBinding(): Promise<string | null>;
135
- export declare function bindAuthored(binding: string): Promise<void>;
136
- export declare function removeRuntimeStore(holder?: string): Promise<boolean>;
137
- export declare function openRuntimeStore(fenced: (locator: string) => boolean): Promise<RuntimeStore>;
153
+ export declare function openRuntimeStore(fenced: (locator: string) => boolean, authored: RuntimeDatabase): RuntimeStore;
138
154
  //# sourceMappingURL=store.d.ts.map