@agentshouse/mdruntime 0.1.0-c97456d63baba → 0.1.0-c9873d788cfb6

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 (368) 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 +251 -0
  8. package/dist/adapter.d.ts +153 -79
  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 +319 -107
  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 -16
  26. package/dist/change-set.d.ts.map +1 -1
  27. package/dist/change-set.js +11 -88
  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 +33 -10
  35. package/dist/client.d.ts.map +1 -1
  36. package/dist/client.js +98 -11
  37. package/dist/collection.d.ts +11 -21
  38. package/dist/collection.d.ts.map +1 -1
  39. package/dist/collection.js +39 -291
  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 +7 -129
  44. package/dist/connection.d.ts.map +1 -1
  45. package/dist/connection.js +100 -3344
  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-live.d.ts +136 -0
  50. package/dist/conversation-live.d.ts.map +1 -0
  51. package/dist/conversation-live.js +248 -0
  52. package/dist/conversation-row.d.ts +33 -0
  53. package/dist/conversation-row.d.ts.map +1 -0
  54. package/dist/conversation-row.js +53 -0
  55. package/dist/conversation.d.ts +53 -43
  56. package/dist/conversation.d.ts.map +1 -1
  57. package/dist/conversation.js +938 -680
  58. package/dist/digest.d.ts +7 -0
  59. package/dist/digest.d.ts.map +1 -0
  60. package/dist/digest.js +113 -0
  61. package/dist/discovery.d.ts +10 -0
  62. package/dist/discovery.d.ts.map +1 -0
  63. package/dist/discovery.js +175 -0
  64. package/dist/durability.d.ts +16 -4
  65. package/dist/durability.d.ts.map +1 -1
  66. package/dist/durability.js +5 -0
  67. package/dist/entry.d.ts +5 -2
  68. package/dist/entry.d.ts.map +1 -1
  69. package/dist/entry.js +33 -28
  70. package/dist/figures.d.ts +49 -0
  71. package/dist/figures.d.ts.map +1 -0
  72. package/dist/figures.js +197 -0
  73. package/dist/file.d.ts +2 -19
  74. package/dist/file.d.ts.map +1 -1
  75. package/dist/file.js +7 -122
  76. package/dist/holdings.d.ts +29 -0
  77. package/dist/holdings.d.ts.map +1 -0
  78. package/dist/holdings.js +95 -0
  79. package/dist/host.d.ts +7 -8
  80. package/dist/host.d.ts.map +1 -1
  81. package/dist/host.js +101 -24
  82. package/dist/identity.d.ts +0 -2
  83. package/dist/identity.d.ts.map +1 -1
  84. package/dist/identity.js +0 -6
  85. package/dist/index.d.ts +33 -13
  86. package/dist/index.d.ts.map +1 -1
  87. package/dist/index.js +11 -1
  88. package/dist/install.d.ts +56 -0
  89. package/dist/install.d.ts.map +1 -0
  90. package/dist/install.js +560 -0
  91. package/dist/job.d.ts +33 -0
  92. package/dist/job.d.ts.map +1 -0
  93. package/dist/job.js +54 -0
  94. package/dist/lifecycle.d.ts +7 -0
  95. package/dist/lifecycle.d.ts.map +1 -0
  96. package/dist/lifecycle.js +268 -0
  97. package/dist/listing.d.ts +53 -0
  98. package/dist/listing.d.ts.map +1 -0
  99. package/dist/listing.js +175 -0
  100. package/dist/live.d.ts +23 -0
  101. package/dist/live.d.ts.map +1 -0
  102. package/dist/live.js +165 -0
  103. package/dist/locks.d.ts +9 -0
  104. package/dist/locks.d.ts.map +1 -0
  105. package/dist/locks.js +61 -0
  106. package/dist/log.d.ts +1 -0
  107. package/dist/log.d.ts.map +1 -1
  108. package/dist/lost.d.ts +5 -0
  109. package/dist/lost.d.ts.map +1 -0
  110. package/dist/lost.js +61 -0
  111. package/dist/media.d.ts +8 -0
  112. package/dist/media.d.ts.map +1 -0
  113. package/dist/media.js +218 -0
  114. package/dist/memory.d.ts +19 -7
  115. package/dist/memory.d.ts.map +1 -1
  116. package/dist/memory.js +248 -103
  117. package/dist/messages.d.ts +52 -0
  118. package/dist/messages.d.ts.map +1 -0
  119. package/dist/messages.js +168 -0
  120. package/dist/model.d.ts +8 -10
  121. package/dist/model.d.ts.map +1 -1
  122. package/dist/model.js +6 -18
  123. package/dist/models.d.ts +14 -0
  124. package/dist/models.d.ts.map +1 -0
  125. package/dist/models.js +193 -0
  126. package/dist/name.d.ts +4 -0
  127. package/dist/name.d.ts.map +1 -0
  128. package/dist/name.js +122 -0
  129. package/dist/observation.d.ts +17 -2
  130. package/dist/observation.d.ts.map +1 -1
  131. package/dist/observation.js +100 -5
  132. package/dist/opened.d.ts +22 -0
  133. package/dist/opened.d.ts.map +1 -0
  134. package/dist/opened.js +107 -0
  135. package/dist/opening.d.ts +4 -0
  136. package/dist/opening.d.ts.map +1 -0
  137. package/dist/opening.js +57 -0
  138. package/dist/outcome.d.ts +49 -8
  139. package/dist/outcome.d.ts.map +1 -1
  140. package/dist/outcome.js +42 -0
  141. package/dist/overlay.d.ts +4 -5
  142. package/dist/overlay.d.ts.map +1 -1
  143. package/dist/overlay.js +106 -156
  144. package/dist/{chat/parts.d.ts → parts.d.ts} +11 -9
  145. package/dist/parts.d.ts.map +1 -0
  146. package/dist/{chat/parts.js → parts.js} +45 -46
  147. package/dist/paths.d.ts +1 -0
  148. package/dist/paths.d.ts.map +1 -1
  149. package/dist/paths.js +4 -0
  150. package/dist/preparation.d.ts +20 -0
  151. package/dist/preparation.d.ts.map +1 -0
  152. package/dist/preparation.js +226 -0
  153. package/dist/queries.d.ts +16 -0
  154. package/dist/queries.d.ts.map +1 -0
  155. package/dist/queries.js +272 -0
  156. package/dist/query.d.ts +26 -185
  157. package/dist/query.d.ts.map +1 -1
  158. package/dist/query.js +3 -464
  159. package/dist/{chat/questions.d.ts → questions.d.ts} +5 -2
  160. package/dist/questions.d.ts.map +1 -0
  161. package/dist/{chat/questions.js → questions.js} +12 -1
  162. package/dist/reach.d.ts +19 -9
  163. package/dist/reach.d.ts.map +1 -1
  164. package/dist/reach.js +287 -99
  165. package/dist/react.d.ts +12 -4
  166. package/dist/react.d.ts.map +1 -1
  167. package/dist/react.js +7 -17
  168. package/dist/{chat/read.d.ts → read.d.ts} +2 -0
  169. package/dist/read.d.ts.map +1 -0
  170. package/dist/{chat/read.js → read.js} +4 -0
  171. package/dist/readiness.d.ts +14 -17
  172. package/dist/readiness.d.ts.map +1 -1
  173. package/dist/readiness.js +2 -8
  174. package/dist/reads.d.ts +37 -0
  175. package/dist/reads.d.ts.map +1 -0
  176. package/dist/reads.js +171 -0
  177. package/dist/recovery.d.ts +3 -2
  178. package/dist/recovery.d.ts.map +1 -1
  179. package/dist/recovery.js +43 -8
  180. package/dist/refresh.d.ts +17 -14
  181. package/dist/refresh.d.ts.map +1 -1
  182. package/dist/refresh.js +143 -52
  183. package/dist/refusal.d.ts +5 -0
  184. package/dist/refusal.d.ts.map +1 -0
  185. package/dist/refusal.js +56 -0
  186. package/dist/replica.d.ts +55 -33
  187. package/dist/replica.d.ts.map +1 -1
  188. package/dist/replica.js +332 -181
  189. package/dist/room-draft.d.ts +37 -6
  190. package/dist/room-draft.d.ts.map +1 -1
  191. package/dist/room-draft.js +161 -74
  192. package/dist/room-drafts.d.ts +24 -0
  193. package/dist/room-drafts.d.ts.map +1 -0
  194. package/dist/room-drafts.js +216 -0
  195. package/dist/rows.d.ts +31 -29
  196. package/dist/rows.d.ts.map +1 -1
  197. package/dist/rows.js +59 -116
  198. package/dist/runtime.d.ts +43 -0
  199. package/dist/runtime.d.ts.map +1 -0
  200. package/dist/runtime.js +1 -0
  201. package/dist/save.d.ts +55 -14
  202. package/dist/save.d.ts.map +1 -1
  203. package/dist/save.js +536 -187
  204. package/dist/saves.d.ts +70 -0
  205. package/dist/saves.d.ts.map +1 -0
  206. package/dist/saves.js +1006 -0
  207. package/dist/search.d.ts +15 -77
  208. package/dist/search.d.ts.map +1 -1
  209. package/dist/search.js +10 -184
  210. package/dist/seed.d.ts +25 -0
  211. package/dist/seed.d.ts.map +1 -0
  212. package/dist/seed.js +146 -0
  213. package/dist/shared.d.ts +8 -4
  214. package/dist/shared.d.ts.map +1 -1
  215. package/dist/shared.js +126 -69
  216. package/dist/shown.d.ts +31 -0
  217. package/dist/shown.d.ts.map +1 -0
  218. package/dist/shown.js +295 -0
  219. package/dist/socket/admission.d.ts +7 -0
  220. package/dist/socket/admission.d.ts.map +1 -0
  221. package/dist/socket/admission.js +39 -0
  222. package/dist/socket/answers.d.ts +6 -0
  223. package/dist/socket/answers.d.ts.map +1 -0
  224. package/dist/socket/answers.js +20 -0
  225. package/dist/socket/lanes.d.ts +20 -0
  226. package/dist/socket/lanes.d.ts.map +1 -0
  227. package/dist/socket/lanes.js +77 -0
  228. package/dist/socket/reads.d.ts +10 -0
  229. package/dist/socket/reads.d.ts.map +1 -0
  230. package/dist/socket/reads.js +31 -0
  231. package/dist/socket/rooms.d.ts +43 -0
  232. package/dist/socket/rooms.d.ts.map +1 -0
  233. package/dist/socket/rooms.js +90 -0
  234. package/dist/socket/session.d.ts +39 -0
  235. package/dist/socket/session.d.ts.map +1 -0
  236. package/dist/socket/session.js +23 -0
  237. package/dist/socket.d.ts +70 -0
  238. package/dist/socket.d.ts.map +1 -0
  239. package/dist/socket.js +175 -0
  240. package/dist/source.d.ts +61 -0
  241. package/dist/source.d.ts.map +1 -0
  242. package/dist/source.js +81 -0
  243. package/dist/status.d.ts +4 -5
  244. package/dist/status.d.ts.map +1 -1
  245. package/dist/status.js +3 -7
  246. package/dist/store/fences.d.ts +16 -0
  247. package/dist/store/fences.d.ts.map +1 -0
  248. package/dist/store/fences.js +26 -0
  249. package/dist/store/installs.d.ts +30 -0
  250. package/dist/store/installs.d.ts.map +1 -0
  251. package/dist/store/installs.js +34 -0
  252. package/dist/store/readiness.d.ts +10 -0
  253. package/dist/store/readiness.d.ts.map +1 -0
  254. package/dist/store/readiness.js +52 -0
  255. package/dist/store/records.d.ts +212 -0
  256. package/dist/store/records.d.ts.map +1 -0
  257. package/dist/store/records.js +431 -0
  258. package/dist/store/room-held.d.ts +8 -0
  259. package/dist/store/room-held.d.ts.map +1 -0
  260. package/dist/store/room-held.js +17 -0
  261. package/dist/store/space.d.ts +11 -0
  262. package/dist/store/space.d.ts.map +1 -0
  263. package/dist/store/space.js +43 -0
  264. package/dist/store/watchers.d.ts +17 -0
  265. package/dist/store/watchers.d.ts.map +1 -0
  266. package/dist/store/watchers.js +57 -0
  267. package/dist/store/writes.d.ts +24 -0
  268. package/dist/store/writes.d.ts.map +1 -0
  269. package/dist/store/writes.js +125 -0
  270. package/dist/store.d.ts +106 -150
  271. package/dist/store.d.ts.map +1 -1
  272. package/dist/store.js +136 -713
  273. package/dist/stored.d.ts +156 -0
  274. package/dist/stored.d.ts.map +1 -0
  275. package/dist/stored.js +649 -0
  276. package/dist/surface.d.ts +88 -0
  277. package/dist/surface.d.ts.map +1 -0
  278. package/dist/surface.js +223 -0
  279. package/dist/sync.d.ts +20 -0
  280. package/dist/sync.d.ts.map +1 -0
  281. package/dist/sync.js +532 -0
  282. package/dist/tables.d.ts +417 -0
  283. package/dist/tables.d.ts.map +1 -0
  284. package/dist/tables.js +740 -0
  285. package/dist/tallies.d.ts +18 -0
  286. package/dist/tallies.d.ts.map +1 -0
  287. package/dist/tallies.js +129 -0
  288. package/dist/transfer.d.ts +0 -5
  289. package/dist/transfer.d.ts.map +1 -1
  290. package/dist/turn.d.ts +5 -3
  291. package/dist/turn.d.ts.map +1 -1
  292. package/dist/turn.js +51 -21
  293. package/dist/validation.d.ts +29 -0
  294. package/dist/validation.d.ts.map +1 -0
  295. package/dist/validation.js +104 -0
  296. package/dist/windows.d.ts +11 -0
  297. package/dist/windows.d.ts.map +1 -0
  298. package/dist/windows.js +16 -0
  299. package/dist/wire.d.ts +50 -6
  300. package/dist/wire.d.ts.map +1 -1
  301. package/dist/wire.js +16 -2
  302. package/package.json +18 -19
  303. package/AGENTS.md +0 -299
  304. package/dist/acquisition.d.ts +0 -14
  305. package/dist/acquisition.d.ts.map +0 -1
  306. package/dist/acquisition.js +0 -24
  307. package/dist/chat/acts.d.ts +0 -33
  308. package/dist/chat/acts.d.ts.map +0 -1
  309. package/dist/chat/acts.js +0 -36
  310. package/dist/chat/context.d.ts +0 -3
  311. package/dist/chat/context.d.ts.map +0 -1
  312. package/dist/chat/input.d.ts +0 -9
  313. package/dist/chat/input.d.ts.map +0 -1
  314. package/dist/chat/input.js +0 -99
  315. package/dist/chat/kit.d.ts +0 -61
  316. package/dist/chat/kit.d.ts.map +0 -1
  317. package/dist/chat/kit.js +0 -123
  318. package/dist/chat/lasting.d.ts +0 -6
  319. package/dist/chat/lasting.d.ts.map +0 -1
  320. package/dist/chat/lasting.js +0 -19
  321. package/dist/chat/list.d.ts +0 -27
  322. package/dist/chat/list.d.ts.map +0 -1
  323. package/dist/chat/list.js +0 -63
  324. package/dist/chat/markdown.d.ts +0 -20
  325. package/dist/chat/markdown.d.ts.map +0 -1
  326. package/dist/chat/markdown.js +0 -188
  327. package/dist/chat/message.d.ts +0 -6
  328. package/dist/chat/message.d.ts.map +0 -1
  329. package/dist/chat/message.js +0 -192
  330. package/dist/chat/messages.d.ts +0 -22
  331. package/dist/chat/messages.d.ts.map +0 -1
  332. package/dist/chat/messages.js +0 -155
  333. package/dist/chat/name.d.ts +0 -6
  334. package/dist/chat/name.d.ts.map +0 -1
  335. package/dist/chat/name.js +0 -37
  336. package/dist/chat/opened.d.ts +0 -11
  337. package/dist/chat/opened.d.ts.map +0 -1
  338. package/dist/chat/opened.js +0 -17
  339. package/dist/chat/overlay.d.ts +0 -31
  340. package/dist/chat/overlay.d.ts.map +0 -1
  341. package/dist/chat/overlay.js +0 -97
  342. package/dist/chat/parts.d.ts.map +0 -1
  343. package/dist/chat/process.d.ts +0 -20
  344. package/dist/chat/process.d.ts.map +0 -1
  345. package/dist/chat/process.js +0 -32
  346. package/dist/chat/provider.d.ts +0 -63
  347. package/dist/chat/provider.d.ts.map +0 -1
  348. package/dist/chat/provider.js +0 -629
  349. package/dist/chat/question.d.ts +0 -9
  350. package/dist/chat/question.d.ts.map +0 -1
  351. package/dist/chat/question.js +0 -80
  352. package/dist/chat/questions.d.ts.map +0 -1
  353. package/dist/chat/read.d.ts.map +0 -1
  354. package/dist/chat/ready.d.ts +0 -34
  355. package/dist/chat/ready.d.ts.map +0 -1
  356. package/dist/chat/ready.js +0 -91
  357. package/dist/chat/style.d.ts +0 -4
  358. package/dist/chat/style.d.ts.map +0 -1
  359. package/dist/chat/style.js +0 -302
  360. package/dist/chat.d.ts +0 -14
  361. package/dist/chat.d.ts.map +0 -1
  362. package/dist/chat.js +0 -8
  363. package/dist/fence.d.ts +0 -6
  364. package/dist/fence.d.ts.map +0 -1
  365. package/dist/fence.js +0 -10
  366. package/dist/read-side.d.ts +0 -25
  367. package/dist/read-side.d.ts.map +0 -1
  368. package/dist/read-side.js +0 -639
package/dist/replica.js CHANGED
@@ -1,199 +1,216 @@
1
1
  import { equalValue, parse } from '@agentshouse/mdmodel';
2
2
  import { immutable, landing } from './change.js';
3
- import { changedCleanly, collectionOf, unreadable, validateCollection, } from './collection.js';
4
- import { acceptedBinaries, overlay, overlayChanged, sameLayerText, } from './overlay.js';
5
- import { providerRewritten } from './save.js';
6
- import { drafted, patched, settled, shared } from './shared.js';
7
- 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 { guarding } from './shared.js';
9
+ import { ROW_WEIGHT } from './turn.js';
10
+ export function compositionOf(record, builtIn, typedPaths) {
8
11
  return {
9
12
  model: record.model,
10
13
  selection: record.typedSelection === null
11
14
  ? null
12
- : { roots: record.typedSelection.roots, model: record.selectionModel },
15
+ : { roots: record.typedSelection.roots, model: builtIn },
16
+ typedPaths,
13
17
  };
14
18
  }
15
- function held(record) {
16
- const documents = shared(record.documents);
17
- const binaries = shared(record.binaries);
18
- const revisions = shared(record.revisions);
19
- const changes = shared(record.changes);
20
- const written = shared(record.written);
21
- return documents === record.documents &&
22
- binaries === record.binaries &&
23
- revisions === record.revisions &&
24
- changes === record.changes &&
25
- written === record.written
26
- ? record
27
- : { ...record, documents, binaries, revisions, changes, written };
19
+ export function storedRecord(record) {
20
+ const { key: _key, ...stored } = record;
21
+ return JSON.stringify({ ...stored, model: storedModel(stored.model) });
28
22
  }
29
- export function confirmedOf(record, previous) {
30
- const kept = held(record);
31
- return {
32
- record: kept,
33
- collection: collectionOf(kept.documents, compositionOf(kept), previous?.collection),
23
+ const PROBES = new Set([
24
+ 'then',
25
+ 'toJSON',
26
+ 'constructor',
27
+ 'valueOf',
28
+ 'toString',
29
+ ]);
30
+ class UnreadPath extends Error {
31
+ constructor(path) {
32
+ super(`the replica slice holds no row for ${path}`);
33
+ }
34
+ }
35
+ function strict(values, held) {
36
+ const guard = (property) => {
37
+ if (typeof property === 'string' && !held.has(property) && !PROBES.has(property)) {
38
+ throw new UnreadPath(property);
39
+ }
34
40
  };
41
+ return guarding(values, {
42
+ get(target, property, receiver) {
43
+ guard(property);
44
+ return Reflect.get(target, property, receiver);
45
+ },
46
+ has(target, property) {
47
+ guard(property);
48
+ return Reflect.has(target, property);
49
+ },
50
+ getOwnPropertyDescriptor(target, property) {
51
+ guard(property);
52
+ return Reflect.getOwnPropertyDescriptor(target, property);
53
+ },
54
+ });
35
55
  }
36
- export function sameMembership(record, other) {
37
- return (JSON.stringify(record.typedSelection?.roots ?? null) ===
38
- JSON.stringify(other.typedSelection?.roots ?? null));
56
+ export function* slicing(entries, paths) {
57
+ const held = new Set(paths);
58
+ for (const entry of entries)
59
+ held.add(entry.path);
60
+ const documents = {};
61
+ const binaries = {};
62
+ const revisions = {};
63
+ const fileIds = {};
64
+ const created = {};
65
+ const changes = {};
66
+ const written = {};
67
+ const facts = {};
68
+ for (const entry of entries) {
69
+ if (entry.facts !== null)
70
+ facts[entry.path] = entry.facts;
71
+ if (entry.binary !== null)
72
+ binaries[entry.path] = entry.binary;
73
+ else if (entry.content !== null)
74
+ documents[entry.path] = entry.content;
75
+ if (entry.revision !== null)
76
+ revisions[entry.path] = entry.revision;
77
+ if (entry.fileId !== null)
78
+ fileIds[entry.path] = entry.fileId;
79
+ if (entry.created !== null)
80
+ created[entry.path] = entry.created;
81
+ if (entry.change !== null)
82
+ changes[entry.path] = entry.change;
83
+ if (entry.written !== null)
84
+ written[entry.path] = entry.written;
85
+ yield ROW_WEIGHT;
86
+ }
87
+ return {
88
+ documents: strict(documents, held),
89
+ binaries: strict(binaries, held),
90
+ revisions: strict(revisions, held),
91
+ fileIds: strict(fileIds, held),
92
+ created: strict(created, held),
93
+ changes: strict(changes, held),
94
+ written: strict(written, held),
95
+ facts: strict(facts, held),
96
+ held,
97
+ };
39
98
  }
40
- function cleanly(record, previous) {
41
- if (previous === undefined)
42
- return false;
43
- const before = previous.record;
44
- return changedCleanly({ text: record.documents, binaries: record.binaries }, { text: before.documents, binaries: before.binaries, composition: compositionOf(before) }, compositionOf(record));
99
+ export function entryAt(layer, path) {
100
+ const content = layer.documents[path];
101
+ const binary = layer.binaries[path];
102
+ if (content === undefined && binary === undefined)
103
+ return null;
104
+ return {
105
+ path,
106
+ content: content ?? null,
107
+ binary: binary ?? null,
108
+ revision: layer.revisions[path] ?? null,
109
+ fileId: layer.fileIds[path] ?? null,
110
+ created: layer.created[path] ?? null,
111
+ change: layer.changes[path] ?? null,
112
+ written: layer.written?.[path] ?? null,
113
+ };
45
114
  }
46
- export function readStaged(staged, previous) {
47
- const record = held(staged);
48
- const textChanged = previous === undefined || !sameLayerText(record, previous.record);
49
- const modeled = record.model.status !== 'unavailable' || record.selectionModel.status !== 'unavailable';
50
- if (modeled &&
51
- (textChanged ||
52
- record.model !== previous?.record.model ||
53
- record.selectionModel !== previous?.record.selectionModel) &&
54
- !cleanly(record, previous)) {
55
- const verdict = validateCollection(record.documents, Object.keys(record.binaries), compositionOf(record));
56
- if (verdict.verdict === 'refuse' && verdict.rule !== 'model-unavailable') {
57
- return { kind: 'refused', refusal: verdict };
58
- }
59
- if (verdict.verdict === 'refuse') {
60
- const refused = unreadable(record.documents, previous?.record.documents);
61
- if (refused !== null)
62
- return refused;
115
+ export function* slicingWith(slice, set, removed) {
116
+ const entries = new Map();
117
+ for (const path of slice.held) {
118
+ const entry = entryAt(slice, path);
119
+ if (entry !== null) {
120
+ entries.set(path, { ...entry, type: null, facts: slice.facts[path] ?? null });
63
121
  }
122
+ yield ROW_WEIGHT;
64
123
  }
65
- else if (textChanged) {
66
- const refused = unreadable(record.documents, previous?.record.documents);
67
- if (refused !== null)
68
- return refused;
69
- }
70
- return { kind: 'staged', confirmed: confirmedOf(record, previous) };
124
+ for (const path of removed)
125
+ entries.delete(path);
126
+ for (const entry of set)
127
+ entries.set(entry.path, { ...entry, type: null });
128
+ return yield* slicing([...entries.values()], [...slice.held, ...set.map(({ path }) => path), ...removed]);
71
129
  }
72
- export function readReclassified(record, previous) {
73
- const verdict = validateCollection(record.documents, Object.keys(record.binaries), compositionOf(record));
74
- if (verdict.verdict !== 'refuse')
75
- return { kind: 'staged', confirmed: confirmedOf(record, previous) };
76
- return verdict.rule === 'model-unavailable'
77
- ? { kind: 'deferred' }
78
- : { kind: 'refused', refusal: verdict };
130
+ function changePaths(change) {
131
+ return change.kind === 'move' ? [change.path, change.to] : [change.path];
79
132
  }
80
- function returnedBinaries(held, submitted, accepted) {
81
- const binaries = drafted(held);
82
- for (const change of submitted.changes) {
83
- if (change.kind !== 'move')
84
- continue;
85
- const moved = binaries[change.path];
86
- if (moved === undefined || accepted.revisions[change.to] === undefined)
87
- continue;
88
- binaries[change.to] = moved;
89
- delete binaries[change.path];
90
- }
91
- Object.assign(binaries, acceptedBinaries(accepted.binaryFiles ?? {}));
92
- for (const path of accepted.removals)
93
- delete binaries[path];
94
- return settled(binaries);
95
- }
96
- export function applyReturned(confirmed, submitted, accepted, roomVersion, writtenAt) {
97
- const { documents, revisions, changes, removals } = accepted;
98
- const nextDocuments = drafted(confirmed.record.documents);
99
- const nextRevisions = drafted(confirmed.record.revisions);
100
- const nextChanges = drafted(confirmed.record.changes);
101
- const nextWritten = drafted(confirmed.record.written);
102
- Object.assign(nextDocuments, documents);
103
- Object.assign(nextRevisions, revisions);
104
- for (const path of Object.keys(documents))
105
- nextWritten[path] = writtenAt;
106
- for (const [path, revision] of Object.entries(revisions)) {
107
- if (confirmed.record.revisions[path] !== revision)
108
- delete nextChanges[path];
109
- }
110
- Object.assign(nextChanges, changes);
111
- for (const path of removals) {
112
- delete nextDocuments[path];
113
- delete nextRevisions[path];
114
- delete nextChanges[path];
115
- delete nextWritten[path];
133
+ export function touchedBy(queue) {
134
+ const paths = new Set();
135
+ for (const batch of queue) {
136
+ for (const change of batch.changes)
137
+ for (const path of changePaths(change))
138
+ paths.add(path);
139
+ for (const precondition of batch.preconditions)
140
+ paths.add(precondition.path);
141
+ for (const move of batch.between?.moves ?? [])
142
+ paths.add(move.path);
116
143
  }
117
- return readStaged({
118
- ...confirmed.record,
119
- roomVersion,
120
- documents: settled(nextDocuments),
121
- revisions: settled(nextRevisions),
122
- changes: settled(nextChanges),
123
- written: settled(nextWritten),
124
- binaries: returnedBinaries(confirmed.record.binaries, submitted, accepted),
125
- }, confirmed);
144
+ return paths;
126
145
  }
127
- function predicted(confirmed, batches, previous) {
128
- const composition = compositionOf(confirmed.record);
129
- let layer = confirmed.record;
130
- const replay = [];
131
- const prior = new Map(previous?.replay.map((step) => [step.id, step]) ?? []);
132
- for (const batch of batches) {
133
- const before = layer;
134
- const old = prior.get(batch.id);
135
- const hasMove = batch.changes.some((change) => change.kind === 'move');
136
- const reuseRewrite = old?.collection !== undefined &&
137
- sameLayerText(before, old.before) &&
138
- old.collection.composition.model === composition.model &&
139
- old.collection.composition.selection?.model === composition.selection?.model &&
140
- JSON.stringify(old.collection.composition.selection?.roots) ===
141
- JSON.stringify(composition.selection?.roots);
142
- const collection = hasMove
143
- ? reuseRewrite
144
- ? old.collection
145
- : collectionOf(before.documents, composition, old?.collection ?? confirmed.collection)
146
- : undefined;
147
- const effective = collection === undefined
148
- ? batch
149
- : reuseRewrite
150
- ? old.effective
151
- : providerRewritten(batch, { ...before, collection });
152
- layer =
153
- old === undefined
154
- ? overlay(before, [effective])
155
- : overlayChanged(before, [effective], old.before, [old.effective], old.after);
156
- replay.push({
157
- id: batch.id,
158
- before,
159
- after: layer,
160
- effective,
161
- ...(collection === undefined ? {} : { collection }),
162
- });
146
+ export function movedBy(queue, locator) {
147
+ const paths = new Set();
148
+ for (const batch of queue) {
149
+ if (!rewriting(batch, locator))
150
+ continue;
151
+ for (const change of batch.changes)
152
+ if (change.kind === 'move')
153
+ paths.add(change.path);
154
+ if (batch.between?.source.room === locator) {
155
+ for (const move of batch.between.moves)
156
+ paths.add(move.path);
157
+ }
163
158
  }
164
- return { layer, replay };
159
+ return paths;
165
160
  }
166
- export function replicaOf(confirmed, queue, previous) {
167
- const batches = Object.freeze(queue.map(immutable));
168
- if (batches.length === 0) {
169
- return {
170
- confirmed,
171
- queue: batches,
172
- visible: {
173
- documents: confirmed.record.documents,
174
- binaries: confirmed.record.binaries,
175
- revisions: confirmed.record.revisions,
176
- changes: confirmed.record.changes,
177
- collection: confirmed.collection,
178
- },
179
- replay: [],
180
- };
161
+ export function* replaying(confirmed, queue, locator, composition) {
162
+ let layer = confirmed;
163
+ const touched = new Set();
164
+ for (const batch of queue) {
165
+ const effective = rewriting(batch, locator)
166
+ ? yield* effectiveIn(batch, locator, {
167
+ ...layer,
168
+ collection: collectionOf(layer.documents, composition),
169
+ })
170
+ : batch;
171
+ for (const change of effective.changes)
172
+ for (const path of changePaths(change))
173
+ touched.add(path);
174
+ layer = yield* overlaying(layer, [effective]);
175
+ yield ROW_WEIGHT;
181
176
  }
182
- const { layer, replay } = predicted(confirmed, batches, previous);
183
177
  return {
184
- confirmed,
185
- queue: batches,
186
- replay,
187
- visible: {
188
- ...layer,
189
- collection: collectionOf(layer.documents, compositionOf(confirmed.record), previous?.visible.collection ?? confirmed.collection),
190
- },
178
+ visible: { ...layer, collection: collectionOf(layer.documents, composition) },
179
+ touched,
191
180
  };
192
181
  }
182
+ export function* overlayOf(visible, touched) {
183
+ const rows = [];
184
+ for (const path of touched) {
185
+ const entry = entryAt(visible, path);
186
+ yield ROW_WEIGHT + (entry?.content?.length ?? 0);
187
+ const text = entry?.binary === null ? entry.content : null;
188
+ rows.push(entry === null
189
+ ? {
190
+ path,
191
+ present: false,
192
+ content: null,
193
+ binary: null,
194
+ revision: null,
195
+ fileId: null,
196
+ created: null,
197
+ change: null,
198
+ written: null,
199
+ facts: null,
200
+ }
201
+ : {
202
+ ...entry,
203
+ written: null,
204
+ present: true,
205
+ facts: text === null ? null : writtenFacts(path, text, visible.collection.composition),
206
+ });
207
+ }
208
+ return rows;
209
+ }
193
210
  function present(layer, path) {
194
211
  return layer.documents[path] !== undefined || layer.binaries[path] !== undefined;
195
212
  }
196
- function holds(layer, preconditions) {
213
+ export function holds(layer, preconditions) {
197
214
  const parsed = new Map();
198
215
  const documentAt = (path) => {
199
216
  if (!parsed.has(path)) {
@@ -258,15 +275,19 @@ function effects(change) {
258
275
  { kind: 'present', path: change.to },
259
276
  ];
260
277
  }
261
- if (change.kind === 'binary')
278
+ if (change.kind === 'binary' || change.kind === 'arrival')
262
279
  return [{ kind: 'present', path }];
263
280
  return [{ kind: 'absent', path }];
264
281
  }
265
282
  export function landed(batch, confirmed, current = {}) {
266
- const layer = {
267
- ...confirmed.record,
268
- documents: patched(confirmed.record.documents, Object.entries(current)),
269
- };
283
+ const documents = new Proxy(confirmed.documents, {
284
+ get(target, property, receiver) {
285
+ if (typeof property === 'string' && Object.hasOwn(current, property))
286
+ return current[property];
287
+ return Reflect.get(target, property, receiver);
288
+ },
289
+ });
290
+ const layer = { ...confirmed, documents };
270
291
  return batch.changes.every((change, index) => {
271
292
  if (change.kind === 'replace' || (change.kind === 'create' && 'content' in change)) {
272
293
  const at = landing(batch.changes, index, change.path);
@@ -284,32 +305,162 @@ export function landed(batch, confirmed, current = {}) {
284
305
  });
285
306
  });
286
307
  }
287
- export function withdrawals(confirmed, queue, withdrawable, local) {
308
+ function founded(batch, layer) {
309
+ let changed = false;
310
+ const preconditions = batch.preconditions.map((precondition) => {
311
+ if (precondition.kind !== 'content')
312
+ return precondition;
313
+ const revision = layer.revisions[precondition.path];
314
+ if (revision === undefined || layer.documents[precondition.path] !== precondition.content) {
315
+ return precondition;
316
+ }
317
+ changed = true;
318
+ return { kind: 'revision', path: precondition.path, revision };
319
+ });
320
+ return changed ? immutable({ ...batch, preconditions }) : batch;
321
+ }
322
+ export function* standing(confirmed, queue, withdrawable, local, locator, composition) {
288
323
  if (!queue.some(withdrawable))
289
- return [];
290
- const composition = compositionOf(confirmed.record);
291
- let layer = confirmed.record;
324
+ return { withdrawn: [], kept: queue };
325
+ let layer = confirmed;
292
326
  const withdrawn = [];
327
+ const kept = [];
293
328
  for (const batch of queue) {
294
329
  if (withdrawable(batch) && !holds(layer, batch.preconditions)) {
295
330
  withdrawn.push(batch);
296
331
  continue;
297
332
  }
298
- const effective = batch.changes.some((change) => change.kind === 'move')
299
- ? providerRewritten(batch, {
333
+ const effective = rewriting(batch, locator)
334
+ ? yield* effectiveIn(batch, locator, {
300
335
  ...layer,
301
336
  collection: collectionOf(layer.documents, composition),
302
337
  })
303
338
  : batch;
304
339
  let unapplied = false;
305
- const next = overlay(layer, [effective], () => {
340
+ const next = yield* overlaying(layer, [effective], () => {
306
341
  unapplied = true;
307
342
  });
308
343
  if (local && unapplied) {
309
344
  withdrawn.push(batch);
310
345
  continue;
311
346
  }
347
+ kept.push(local || !withdrawable(batch) ? batch : founded(batch, layer));
312
348
  layer = next;
313
349
  }
314
- return withdrawn;
350
+ return { withdrawn, kept };
351
+ }
352
+ export function returnedPaths(submitted, accepted) {
353
+ const paths = new Set([
354
+ ...Object.keys(accepted.documents),
355
+ ...Object.keys(accepted.revisions),
356
+ ...Object.keys(accepted.fileIds ?? {}),
357
+ ...Object.keys(accepted.changes),
358
+ ...Object.keys(accepted.binaryFiles ?? {}),
359
+ ...accepted.removals,
360
+ ]);
361
+ for (const change of submitted.changes) {
362
+ if (change.kind === 'move') {
363
+ paths.add(change.path);
364
+ paths.add(change.to);
365
+ }
366
+ if (change.kind === 'arrival')
367
+ paths.add(change.path);
368
+ }
369
+ return paths;
370
+ }
371
+ export function* returning(confirmed, submitted, accepted, writtenAt, composition) {
372
+ const documents = new Map();
373
+ const binaries = new Map();
374
+ const revisions = new Map();
375
+ const fileIds = new Map();
376
+ const created = new Map();
377
+ const changes = new Map();
378
+ const written = new Map();
379
+ const facts = new Map();
380
+ const read = (changed, held, path) => (changed.has(path) ? changed.get(path) : held[path]);
381
+ for (const [path, content] of Object.entries(accepted.documents)) {
382
+ yield ROW_WEIGHT + content.length;
383
+ documents.set(path, content);
384
+ facts.set(path, writtenFacts(path, content, composition));
385
+ fileIds.set(path, undefined);
386
+ written.set(path, writtenAt);
387
+ }
388
+ for (const [path, revision] of Object.entries(accepted.revisions)) {
389
+ yield ROW_WEIGHT;
390
+ revisions.set(path, revision);
391
+ fileIds.set(path, undefined);
392
+ if (confirmed.revisions[path] !== revision)
393
+ changes.set(path, undefined);
394
+ }
395
+ for (const [path, fileId] of Object.entries(accepted.fileIds ?? {}))
396
+ fileIds.set(path, fileId);
397
+ for (const [path, change] of Object.entries(accepted.changes))
398
+ changes.set(path, change);
399
+ for (const path of accepted.removals) {
400
+ documents.set(path, undefined);
401
+ revisions.set(path, undefined);
402
+ fileIds.set(path, undefined);
403
+ changes.set(path, undefined);
404
+ written.set(path, undefined);
405
+ }
406
+ for (const change of submitted.changes) {
407
+ if (change.kind === 'arrival') {
408
+ if (accepted.revisions[change.path] === undefined)
409
+ continue;
410
+ created.set(change.path, change.created);
411
+ if ('binary' in change)
412
+ binaries.set(change.path, { state: 'accepted', ...change.binary });
413
+ continue;
414
+ }
415
+ if (change.kind !== 'move' || accepted.revisions[change.to] === undefined)
416
+ continue;
417
+ created.set(change.to, read(created, confirmed.created, change.path));
418
+ created.set(change.path, undefined);
419
+ const moved = read(binaries, confirmed.binaries, change.path);
420
+ if (moved === undefined)
421
+ continue;
422
+ binaries.set(change.to, moved);
423
+ binaries.set(change.path, undefined);
424
+ }
425
+ for (const [path, binary] of acceptedBinaries(accepted.binaryFiles ?? {}))
426
+ binaries.set(path, binary);
427
+ for (const path of accepted.removals) {
428
+ binaries.set(path, undefined);
429
+ created.set(path, undefined);
430
+ }
431
+ const paths = new Set([
432
+ ...documents.keys(),
433
+ ...binaries.keys(),
434
+ ...revisions.keys(),
435
+ ...fileIds.keys(),
436
+ ...created.keys(),
437
+ ...changes.keys(),
438
+ ...written.keys(),
439
+ ]);
440
+ const set = [];
441
+ const removed = [];
442
+ for (const path of paths) {
443
+ const content = read(documents, confirmed.documents, path);
444
+ const binary = read(binaries, confirmed.binaries, path);
445
+ yield ROW_WEIGHT;
446
+ if (content === undefined && binary === undefined) {
447
+ removed.push(path);
448
+ continue;
449
+ }
450
+ const text = binary === undefined ? (content ?? null) : null;
451
+ const fresh = confirmed.documents[path] === undefined && confirmed.binaries[path] === undefined;
452
+ set.push({
453
+ path,
454
+ content: text,
455
+ facts: text === null ? null : (read(facts, confirmed.facts, path) ?? null),
456
+ binary: binary ?? null,
457
+ revision: read(revisions, confirmed.revisions, path) ?? null,
458
+ fileId: read(fileIds, confirmed.fileIds, path) ?? null,
459
+ created: read(created, confirmed.created, path) ??
460
+ (fresh ? (read(changes, confirmed.changes, path)?.time ?? null) : null),
461
+ change: read(changes, confirmed.changes, path) ?? null,
462
+ written: read(written, confirmed.written, path) ?? null,
463
+ });
464
+ }
465
+ return { set, removed };
315
466
  }
@@ -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: Open<'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[];