@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/replica.js CHANGED
@@ -1,174 +1,215 @@
1
1
  import { equalValue, parse } from '@agentshouse/mdmodel';
2
2
  import { immutable, landing } from './change.js';
3
- import { collectionOf, unreadable, validateCollection, } from './collection.js';
4
- import { acceptedBinaries, overlay, overlayChanged, sameLayerText, } from './overlay.js';
5
- import { providerRewritten } from './save.js';
6
- export function compositionOf(record) {
3
+ import { collectionOf } from './collection.js';
4
+ import { storedModel } from './model.js';
5
+ import { acceptedBinaries, overlaying } from './overlay.js';
6
+ import { writtenFacts } from './rows.js';
7
+ import { effectiveIn, rewriting } from './save.js';
8
+ import { ROW_WEIGHT } from './turn.js';
9
+ export function compositionOf(record, builtIn, typedPaths) {
7
10
  return {
8
11
  model: record.model,
9
12
  selection: record.typedSelection === null
10
13
  ? null
11
- : { roots: record.typedSelection.roots, model: record.selectionModel },
14
+ : { roots: record.typedSelection.roots, model: builtIn },
15
+ typedPaths,
12
16
  };
13
17
  }
14
- export function confirmedOf(record, previous) {
15
- return {
16
- record,
17
- collection: collectionOf(record.documents, compositionOf(record), previous?.collection),
18
- };
18
+ export function storedRecord(record) {
19
+ const { key: _key, ...stored } = record;
20
+ return JSON.stringify({ ...stored, model: storedModel(stored.model) });
19
21
  }
20
- export function sameMembership(record, other) {
21
- return (JSON.stringify(record.typedSelection?.roots ?? null) ===
22
- JSON.stringify(other.typedSelection?.roots ?? null));
23
- }
24
- export function readStaged(record, previous) {
25
- const textChanged = previous === undefined || !sameLayerText(record, previous.record);
26
- const modeled = record.model.status !== 'unavailable' || record.selectionModel.status !== 'unavailable';
27
- if (modeled &&
28
- (textChanged ||
29
- record.model !== previous?.record.model ||
30
- record.selectionModel !== previous?.record.selectionModel)) {
31
- const verdict = validateCollection(record.documents, Object.keys(record.binaries), compositionOf(record));
32
- if (verdict.verdict === 'refuse' && verdict.rule !== 'model-unavailable') {
33
- return { kind: 'refused', refusal: verdict };
34
- }
35
- if (verdict.verdict === 'refuse') {
36
- const refused = unreadable(record.documents, previous?.record.documents);
37
- if (refused !== null)
38
- return refused;
39
- }
40
- }
41
- else if (textChanged) {
42
- const refused = unreadable(record.documents, previous?.record.documents);
43
- if (refused !== null)
44
- return refused;
22
+ const PROBES = new Set([
23
+ 'then',
24
+ 'toJSON',
25
+ 'constructor',
26
+ 'valueOf',
27
+ 'toString',
28
+ ]);
29
+ class UnreadPath extends Error {
30
+ constructor(path) {
31
+ super(`the replica slice holds no row for ${path}`);
45
32
  }
46
- return { kind: 'staged', confirmed: confirmedOf(record, previous) };
47
33
  }
48
- export function readReclassified(record, previous) {
49
- const verdict = validateCollection(record.documents, Object.keys(record.binaries), compositionOf(record));
50
- if (verdict.verdict !== 'refuse')
51
- return { kind: 'staged', confirmed: confirmedOf(record, previous) };
52
- return verdict.rule === 'model-unavailable'
53
- ? { kind: 'deferred' }
54
- : { kind: 'refused', refusal: verdict };
34
+ function strict(values, held) {
35
+ const guard = (property) => {
36
+ if (typeof property === 'string' && !held.has(property) && !PROBES.has(property)) {
37
+ throw new UnreadPath(property);
38
+ }
39
+ };
40
+ return new Proxy(values, {
41
+ get(target, property, receiver) {
42
+ guard(property);
43
+ return Reflect.get(target, property, receiver);
44
+ },
45
+ has(target, property) {
46
+ guard(property);
47
+ return Reflect.has(target, property);
48
+ },
49
+ getOwnPropertyDescriptor(target, property) {
50
+ guard(property);
51
+ return Reflect.getOwnPropertyDescriptor(target, property);
52
+ },
53
+ });
55
54
  }
56
- function returnedBinaries(held, submitted, accepted) {
57
- const binaries = { ...held };
58
- for (const change of submitted.changes) {
59
- if (change.kind !== 'move')
60
- continue;
61
- const moved = binaries[change.path];
62
- if (moved === undefined || accepted.revisions[change.to] === undefined)
63
- continue;
64
- binaries[change.to] = moved;
65
- delete binaries[change.path];
55
+ export function* slicing(entries, paths) {
56
+ const held = new Set(paths);
57
+ for (const entry of entries)
58
+ held.add(entry.path);
59
+ const documents = {};
60
+ const binaries = {};
61
+ const revisions = {};
62
+ const fileIds = {};
63
+ const created = {};
64
+ const changes = {};
65
+ const written = {};
66
+ const facts = {};
67
+ for (const entry of entries) {
68
+ if (entry.facts !== null)
69
+ facts[entry.path] = entry.facts;
70
+ if (entry.binary !== null)
71
+ binaries[entry.path] = entry.binary;
72
+ else if (entry.content !== null)
73
+ documents[entry.path] = entry.content;
74
+ if (entry.revision !== null)
75
+ revisions[entry.path] = entry.revision;
76
+ if (entry.fileId !== null)
77
+ fileIds[entry.path] = entry.fileId;
78
+ if (entry.created !== null)
79
+ created[entry.path] = entry.created;
80
+ if (entry.change !== null)
81
+ changes[entry.path] = entry.change;
82
+ if (entry.written !== null)
83
+ written[entry.path] = entry.written;
84
+ yield ROW_WEIGHT;
66
85
  }
67
- Object.assign(binaries, acceptedBinaries(accepted.binaryFiles ?? {}));
68
- for (const path of accepted.removals)
69
- delete binaries[path];
70
- return binaries;
86
+ return {
87
+ documents: strict(documents, held),
88
+ binaries: strict(binaries, held),
89
+ revisions: strict(revisions, held),
90
+ fileIds: strict(fileIds, held),
91
+ created: strict(created, held),
92
+ changes: strict(changes, held),
93
+ written: strict(written, held),
94
+ facts: strict(facts, held),
95
+ held,
96
+ };
71
97
  }
72
- export function applyReturned(confirmed, submitted, accepted, roomVersion, writtenAt) {
73
- const { documents, revisions, changes, removals } = accepted;
74
- const nextDocuments = { ...confirmed.record.documents, ...documents };
75
- const nextRevisions = { ...confirmed.record.revisions, ...revisions };
76
- const nextChanges = { ...confirmed.record.changes };
77
- const nextWritten = {
78
- ...confirmed.record.written,
79
- ...Object.fromEntries(Object.keys(documents).map((path) => [path, writtenAt])),
98
+ export function entryAt(layer, path) {
99
+ const content = layer.documents[path];
100
+ const binary = layer.binaries[path];
101
+ if (content === undefined && binary === undefined)
102
+ return null;
103
+ return {
104
+ path,
105
+ content: content ?? null,
106
+ binary: binary ?? null,
107
+ revision: layer.revisions[path] ?? null,
108
+ fileId: layer.fileIds[path] ?? null,
109
+ created: layer.created[path] ?? null,
110
+ change: layer.changes[path] ?? null,
111
+ written: layer.written?.[path] ?? null,
80
112
  };
81
- for (const [path, revision] of Object.entries(revisions)) {
82
- if (confirmed.record.revisions[path] !== revision)
83
- delete nextChanges[path];
113
+ }
114
+ export function* slicingWith(slice, set, removed) {
115
+ const entries = new Map();
116
+ for (const path of slice.held) {
117
+ const entry = entryAt(slice, path);
118
+ if (entry !== null) {
119
+ entries.set(path, { ...entry, type: null, facts: slice.facts[path] ?? null });
120
+ }
121
+ yield ROW_WEIGHT;
84
122
  }
85
- Object.assign(nextChanges, changes);
86
- for (const path of removals) {
87
- delete nextDocuments[path];
88
- delete nextRevisions[path];
89
- delete nextChanges[path];
90
- delete nextWritten[path];
123
+ for (const path of removed)
124
+ entries.delete(path);
125
+ for (const entry of set)
126
+ entries.set(entry.path, { ...entry, type: null });
127
+ return yield* slicing([...entries.values()], [...slice.held, ...set.map(({ path }) => path), ...removed]);
128
+ }
129
+ function changePaths(change) {
130
+ return change.kind === 'move' ? [change.path, change.to] : [change.path];
131
+ }
132
+ export function touchedBy(queue) {
133
+ const paths = new Set();
134
+ for (const batch of queue) {
135
+ for (const change of batch.changes)
136
+ for (const path of changePaths(change))
137
+ paths.add(path);
138
+ for (const precondition of batch.preconditions)
139
+ paths.add(precondition.path);
140
+ for (const move of batch.between?.moves ?? [])
141
+ paths.add(move.path);
91
142
  }
92
- return readStaged({
93
- ...confirmed.record,
94
- roomVersion,
95
- documents: nextDocuments,
96
- revisions: nextRevisions,
97
- changes: nextChanges,
98
- written: nextWritten,
99
- binaries: returnedBinaries(confirmed.record.binaries, submitted, accepted),
100
- }, confirmed);
143
+ return paths;
101
144
  }
102
- function predicted(confirmed, batches, previous) {
103
- const composition = compositionOf(confirmed.record);
104
- let layer = confirmed.record;
105
- const replay = [];
106
- const prior = new Map(previous?.replay.map((step) => [step.id, step]) ?? []);
107
- for (const batch of batches) {
108
- const before = layer;
109
- const old = prior.get(batch.id);
110
- const hasMove = batch.changes.some((change) => change.kind === 'move');
111
- const reuseRewrite = old?.collection !== undefined &&
112
- sameLayerText(before, old.before) &&
113
- old.collection.composition.model === composition.model &&
114
- old.collection.composition.selection?.model === composition.selection?.model &&
115
- JSON.stringify(old.collection.composition.selection?.roots) ===
116
- JSON.stringify(composition.selection?.roots);
117
- const collection = hasMove
118
- ? reuseRewrite
119
- ? old.collection
120
- : collectionOf(before.documents, composition, old?.collection ?? confirmed.collection)
121
- : undefined;
122
- const effective = collection === undefined
123
- ? batch
124
- : reuseRewrite
125
- ? old.effective
126
- : providerRewritten(batch, { ...before, collection });
127
- layer =
128
- old === undefined
129
- ? overlay(before, [effective])
130
- : overlayChanged(before, [effective], old.before, [old.effective], old.after);
131
- replay.push({
132
- id: batch.id,
133
- before,
134
- after: layer,
135
- effective,
136
- ...(collection === undefined ? {} : { collection }),
137
- });
145
+ export function movedBy(queue, locator) {
146
+ const paths = new Set();
147
+ for (const batch of queue) {
148
+ if (!rewriting(batch, locator))
149
+ continue;
150
+ for (const change of batch.changes)
151
+ if (change.kind === 'move')
152
+ paths.add(change.path);
153
+ if (batch.between?.source.room === locator) {
154
+ for (const move of batch.between.moves)
155
+ paths.add(move.path);
156
+ }
138
157
  }
139
- return { layer, replay };
158
+ return paths;
140
159
  }
141
- export function replicaOf(confirmed, queue, previous) {
142
- const batches = Object.freeze(queue.map(immutable));
143
- if (batches.length === 0) {
144
- return {
145
- confirmed,
146
- queue: batches,
147
- visible: {
148
- documents: confirmed.record.documents,
149
- binaries: confirmed.record.binaries,
150
- revisions: confirmed.record.revisions,
151
- changes: confirmed.record.changes,
152
- collection: confirmed.collection,
153
- },
154
- replay: [],
155
- };
160
+ export function* replaying(confirmed, queue, locator, composition) {
161
+ let layer = confirmed;
162
+ const touched = new Set();
163
+ for (const batch of queue) {
164
+ const effective = rewriting(batch, locator)
165
+ ? yield* effectiveIn(batch, locator, {
166
+ ...layer,
167
+ collection: collectionOf(layer.documents, composition),
168
+ })
169
+ : batch;
170
+ for (const change of effective.changes)
171
+ for (const path of changePaths(change))
172
+ touched.add(path);
173
+ layer = yield* overlaying(layer, [effective]);
174
+ yield ROW_WEIGHT;
156
175
  }
157
- const { layer, replay } = predicted(confirmed, batches, previous);
158
176
  return {
159
- confirmed,
160
- queue: batches,
161
- replay,
162
- visible: {
163
- ...layer,
164
- collection: collectionOf(layer.documents, compositionOf(confirmed.record), previous?.visible.collection ?? confirmed.collection),
165
- },
177
+ visible: { ...layer, collection: collectionOf(layer.documents, composition) },
178
+ touched,
166
179
  };
167
180
  }
181
+ export function* overlayOf(visible, touched) {
182
+ const rows = [];
183
+ for (const path of touched) {
184
+ const entry = entryAt(visible, path);
185
+ yield ROW_WEIGHT + (entry?.content?.length ?? 0);
186
+ const text = entry?.binary === null ? entry.content : null;
187
+ rows.push(entry === null
188
+ ? {
189
+ path,
190
+ present: false,
191
+ content: null,
192
+ binary: null,
193
+ revision: null,
194
+ fileId: null,
195
+ created: null,
196
+ change: null,
197
+ written: null,
198
+ facts: null,
199
+ }
200
+ : {
201
+ ...entry,
202
+ written: null,
203
+ present: true,
204
+ facts: text === null ? null : writtenFacts(path, text, visible.collection.composition),
205
+ });
206
+ }
207
+ return rows;
208
+ }
168
209
  function present(layer, path) {
169
210
  return layer.documents[path] !== undefined || layer.binaries[path] !== undefined;
170
211
  }
171
- function holds(layer, preconditions) {
212
+ export function holds(layer, preconditions) {
172
213
  const parsed = new Map();
173
214
  const documentAt = (path) => {
174
215
  if (!parsed.has(path)) {
@@ -233,12 +274,19 @@ function effects(change) {
233
274
  { kind: 'present', path: change.to },
234
275
  ];
235
276
  }
236
- if (change.kind === 'binary')
277
+ if (change.kind === 'binary' || change.kind === 'arrival')
237
278
  return [{ kind: 'present', path }];
238
279
  return [{ kind: 'absent', path }];
239
280
  }
240
281
  export function landed(batch, confirmed, current = {}) {
241
- const layer = { ...confirmed.record, documents: { ...confirmed.record.documents, ...current } };
282
+ const documents = new Proxy(confirmed.documents, {
283
+ get(target, property, receiver) {
284
+ if (typeof property === 'string' && Object.hasOwn(current, property))
285
+ return current[property];
286
+ return Reflect.get(target, property, receiver);
287
+ },
288
+ });
289
+ const layer = { ...confirmed, documents };
242
290
  return batch.changes.every((change, index) => {
243
291
  if (change.kind === 'replace' || (change.kind === 'create' && 'content' in change)) {
244
292
  const at = landing(batch.changes, index, change.path);
@@ -256,32 +304,162 @@ export function landed(batch, confirmed, current = {}) {
256
304
  });
257
305
  });
258
306
  }
259
- export function withdrawals(confirmed, queue, withdrawable, local) {
307
+ function founded(batch, layer) {
308
+ let changed = false;
309
+ const preconditions = batch.preconditions.map((precondition) => {
310
+ if (precondition.kind !== 'content')
311
+ return precondition;
312
+ const revision = layer.revisions[precondition.path];
313
+ if (revision === undefined || layer.documents[precondition.path] !== precondition.content) {
314
+ return precondition;
315
+ }
316
+ changed = true;
317
+ return { kind: 'revision', path: precondition.path, revision };
318
+ });
319
+ return changed ? immutable({ ...batch, preconditions }) : batch;
320
+ }
321
+ export function* standing(confirmed, queue, withdrawable, local, locator, composition) {
260
322
  if (!queue.some(withdrawable))
261
- return [];
262
- const composition = compositionOf(confirmed.record);
263
- let layer = confirmed.record;
323
+ return { withdrawn: [], kept: queue };
324
+ let layer = confirmed;
264
325
  const withdrawn = [];
326
+ const kept = [];
265
327
  for (const batch of queue) {
266
328
  if (withdrawable(batch) && !holds(layer, batch.preconditions)) {
267
329
  withdrawn.push(batch);
268
330
  continue;
269
331
  }
270
- const effective = batch.changes.some((change) => change.kind === 'move')
271
- ? providerRewritten(batch, {
332
+ const effective = rewriting(batch, locator)
333
+ ? yield* effectiveIn(batch, locator, {
272
334
  ...layer,
273
335
  collection: collectionOf(layer.documents, composition),
274
336
  })
275
337
  : batch;
276
338
  let unapplied = false;
277
- const next = overlay(layer, [effective], () => {
339
+ const next = yield* overlaying(layer, [effective], () => {
278
340
  unapplied = true;
279
341
  });
280
342
  if (local && unapplied) {
281
343
  withdrawn.push(batch);
282
344
  continue;
283
345
  }
346
+ kept.push(local || !withdrawable(batch) ? batch : founded(batch, layer));
284
347
  layer = next;
285
348
  }
286
- return withdrawn;
349
+ return { withdrawn, kept };
350
+ }
351
+ export function returnedPaths(submitted, accepted) {
352
+ const paths = new Set([
353
+ ...Object.keys(accepted.documents),
354
+ ...Object.keys(accepted.revisions),
355
+ ...Object.keys(accepted.fileIds ?? {}),
356
+ ...Object.keys(accepted.changes),
357
+ ...Object.keys(accepted.binaryFiles ?? {}),
358
+ ...accepted.removals,
359
+ ]);
360
+ for (const change of submitted.changes) {
361
+ if (change.kind === 'move') {
362
+ paths.add(change.path);
363
+ paths.add(change.to);
364
+ }
365
+ if (change.kind === 'arrival')
366
+ paths.add(change.path);
367
+ }
368
+ return paths;
369
+ }
370
+ export function* returning(confirmed, submitted, accepted, writtenAt, composition) {
371
+ const documents = new Map();
372
+ const binaries = new Map();
373
+ const revisions = new Map();
374
+ const fileIds = new Map();
375
+ const created = new Map();
376
+ const changes = new Map();
377
+ const written = new Map();
378
+ const facts = new Map();
379
+ const read = (changed, held, path) => (changed.has(path) ? changed.get(path) : held[path]);
380
+ for (const [path, content] of Object.entries(accepted.documents)) {
381
+ yield ROW_WEIGHT + content.length;
382
+ documents.set(path, content);
383
+ facts.set(path, writtenFacts(path, content, composition));
384
+ fileIds.set(path, undefined);
385
+ written.set(path, writtenAt);
386
+ }
387
+ for (const [path, revision] of Object.entries(accepted.revisions)) {
388
+ yield ROW_WEIGHT;
389
+ revisions.set(path, revision);
390
+ fileIds.set(path, undefined);
391
+ if (confirmed.revisions[path] !== revision)
392
+ changes.set(path, undefined);
393
+ }
394
+ for (const [path, fileId] of Object.entries(accepted.fileIds ?? {}))
395
+ fileIds.set(path, fileId);
396
+ for (const [path, change] of Object.entries(accepted.changes))
397
+ changes.set(path, change);
398
+ for (const path of accepted.removals) {
399
+ documents.set(path, undefined);
400
+ revisions.set(path, undefined);
401
+ fileIds.set(path, undefined);
402
+ changes.set(path, undefined);
403
+ written.set(path, undefined);
404
+ }
405
+ for (const change of submitted.changes) {
406
+ if (change.kind === 'arrival') {
407
+ if (accepted.revisions[change.path] === undefined)
408
+ continue;
409
+ created.set(change.path, change.created);
410
+ if ('binary' in change)
411
+ binaries.set(change.path, { state: 'accepted', ...change.binary });
412
+ continue;
413
+ }
414
+ if (change.kind !== 'move' || accepted.revisions[change.to] === undefined)
415
+ continue;
416
+ created.set(change.to, read(created, confirmed.created, change.path));
417
+ created.set(change.path, undefined);
418
+ const moved = read(binaries, confirmed.binaries, change.path);
419
+ if (moved === undefined)
420
+ continue;
421
+ binaries.set(change.to, moved);
422
+ binaries.set(change.path, undefined);
423
+ }
424
+ for (const [path, binary] of acceptedBinaries(accepted.binaryFiles ?? {}))
425
+ binaries.set(path, binary);
426
+ for (const path of accepted.removals) {
427
+ binaries.set(path, undefined);
428
+ created.set(path, undefined);
429
+ }
430
+ const paths = new Set([
431
+ ...documents.keys(),
432
+ ...binaries.keys(),
433
+ ...revisions.keys(),
434
+ ...fileIds.keys(),
435
+ ...created.keys(),
436
+ ...changes.keys(),
437
+ ...written.keys(),
438
+ ]);
439
+ const set = [];
440
+ const removed = [];
441
+ for (const path of paths) {
442
+ const content = read(documents, confirmed.documents, path);
443
+ const binary = read(binaries, confirmed.binaries, path);
444
+ yield ROW_WEIGHT;
445
+ if (content === undefined && binary === undefined) {
446
+ removed.push(path);
447
+ continue;
448
+ }
449
+ const text = binary === undefined ? (content ?? null) : null;
450
+ const fresh = confirmed.documents[path] === undefined && confirmed.binaries[path] === undefined;
451
+ set.push({
452
+ path,
453
+ content: text,
454
+ facts: text === null ? null : (read(facts, confirmed.facts, path) ?? null),
455
+ binary: binary ?? null,
456
+ revision: read(revisions, confirmed.revisions, path) ?? null,
457
+ fileId: read(fileIds, confirmed.fileIds, path) ?? null,
458
+ created: read(created, confirmed.created, path) ??
459
+ (fresh ? (read(changes, confirmed.changes, path)?.time ?? null) : null),
460
+ change: read(changes, confirmed.changes, path) ?? null,
461
+ written: read(written, confirmed.written, path) ?? null,
462
+ });
463
+ }
464
+ return { set, removed };
287
465
  }
@@ -32,6 +32,7 @@ export type RoomDraftParts = {
32
32
  readonly creation?: RoomDraftCreation;
33
33
  readonly move?: {
34
34
  readonly to: string;
35
+ readonly room?: string;
35
36
  readonly base?: string | null;
36
37
  };
37
38
  readonly removal?: {
@@ -39,11 +40,12 @@ export type RoomDraftParts = {
39
40
  };
40
41
  readonly file?: {
41
42
  readonly blob: Blob;
43
+ readonly base?: string | null;
42
44
  };
43
45
  };
44
46
  export type HeldFile = {
45
- readonly blob: Blob;
46
47
  readonly localId: string;
48
+ readonly name?: string;
47
49
  readonly byteLength: number;
48
50
  readonly mediaType: string;
49
51
  readonly sha256: string;
@@ -69,6 +71,7 @@ type HeldParts = {
69
71
  readonly creation?: RoomDraftCreation;
70
72
  readonly move?: {
71
73
  readonly to: string;
74
+ readonly room?: string;
72
75
  readonly base: string | null;
73
76
  };
74
77
  readonly removal?: {
@@ -87,9 +90,9 @@ type ChangedUnderneath = {
87
90
  readonly file?: string | null;
88
91
  };
89
92
  export type ReturnReason = ProviderRefusal & {
90
- readonly kind: 'conflicted' | 'rejected' | 'expired' | 'withdrawn';
93
+ readonly kind: Open<'conflicted' | 'rejected' | 'withdrawn'>;
91
94
  };
92
- export declare function returnedBy(kind: 'expired' | 'withdrawn'): ReturnReason;
95
+ export declare function returnedBy(kind: 'withdrawn'): ReturnReason;
93
96
  export type RoomDraft = {
94
97
  readonly room: string;
95
98
  readonly path: string;
@@ -110,7 +113,7 @@ export type RoomDraftWrite = {
110
113
  export declare function staleWrite(current: RoomDraft | null): RoomDraftWrite;
111
114
  export type ChangedPart = {
112
115
  readonly path: string;
113
- readonly part: Open<'field' | 'section' | 'preamble' | 'markdown' | 'creation' | 'move' | 'removal' | 'file'>;
116
+ readonly part: Open<'field' | 'section' | 'preamble' | 'markdown' | 'move' | 'removal' | 'file'>;
114
117
  readonly name?: string;
115
118
  };
116
119
  export type RoomDraftRecord = {
@@ -124,16 +127,44 @@ export type SavedDraft = {
124
127
  readonly path: string;
125
128
  readonly parts: HeldParts;
126
129
  };
127
- export declare function readParts(value: unknown): RoomDraftParts;
130
+ export declare function readParts(value: unknown, path: string): RoomDraftParts;
131
+ export declare function gatheredParts(earlier: unknown, later: unknown): unknown;
128
132
  export declare function held(current: HeldParts | undefined, parts: RoomDraftParts, file?: HeldFile): HeldParts;
129
133
  export declare function underneath(parts: HeldParts, path: string, visible: VisibleLayer | undefined): ChangedUnderneath;
130
134
  export declare function heldFile(blob: Blob, base: string | null): Promise<HeldFile>;
131
135
  export declare function binaryBase(visible: VisibleLayer | undefined, path: string): string | null;
132
- export declare function changedParts(path: string, report: ChangedUnderneath): readonly ChangedPart[];
136
+ export declare function changedParts(path: string, parts: HeldParts, visible: VisibleLayer | undefined): readonly ChangedPart[];
137
+ export declare function lineEnded(text: string): string;
138
+ export type TextParts = {
139
+ readonly fields?: Readonly<Record<string, {
140
+ readonly value: unknown;
141
+ }>>;
142
+ readonly sections?: Readonly<Record<string, {
143
+ readonly value: string;
144
+ }>>;
145
+ readonly preamble?: {
146
+ readonly value: string;
147
+ };
148
+ };
149
+ export declare function partsAfter(markdown: string, parts: TextParts): string;
133
150
  export declare function returnedInto(existing: HeldParts | undefined, returned: HeldParts): HeldParts;
134
151
  export declare function moveTarget(move: {
135
152
  readonly to: string;
136
153
  }): string;
154
+ export declare function readSavedParts(named: readonly {
155
+ readonly path: string;
156
+ readonly parts: unknown;
157
+ }[]): readonly {
158
+ readonly path: string;
159
+ readonly parts: RoomDraftParts;
160
+ }[];
161
+ export declare function partsChanges(named: readonly {
162
+ readonly path: string;
163
+ readonly parts: unknown;
164
+ }[]): {
165
+ readonly changes: readonly Change[];
166
+ readonly preconditions: readonly Precondition[];
167
+ };
137
168
  export declare function changesOf(path: string, parts: HeldParts): {
138
169
  changes: readonly Change[];
139
170
  bases: readonly Precondition[];