@agentshouse/mdruntime 0.1.0-cdb8840578a20 → 0.1.0-cdded6c080913

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 (365) 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 +151 -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 +97 -3359
  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 +53 -0
  52. package/dist/conversation.d.ts +43 -18
  53. package/dist/conversation.d.ts.map +1 -1
  54. package/dist/conversation.js +718 -312
  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 +16 -4
  62. package/dist/durability.d.ts.map +1 -1
  63. package/dist/durability.js +5 -0
  64. package/dist/entry.d.ts +5 -2
  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 +7 -8
  77. package/dist/host.d.ts.map +1 -1
  78. package/dist/host.js +101 -24
  79. package/dist/identity.d.ts +0 -2
  80. package/dist/identity.d.ts.map +1 -1
  81. package/dist/identity.js +0 -6
  82. package/dist/index.d.ts +32 -13
  83. package/dist/index.d.ts.map +1 -1
  84. package/dist/index.js +10 -1
  85. package/dist/install.d.ts +56 -0
  86. package/dist/install.d.ts.map +1 -0
  87. package/dist/install.js +560 -0
  88. package/dist/job.d.ts +33 -0
  89. package/dist/job.d.ts.map +1 -0
  90. package/dist/job.js +54 -0
  91. package/dist/lifecycle.d.ts +7 -0
  92. package/dist/lifecycle.d.ts.map +1 -0
  93. package/dist/lifecycle.js +267 -0
  94. package/dist/listing.d.ts +53 -0
  95. package/dist/listing.d.ts.map +1 -0
  96. package/dist/listing.js +175 -0
  97. package/dist/live.d.ts +23 -0
  98. package/dist/live.d.ts.map +1 -0
  99. package/dist/live.js +165 -0
  100. package/dist/locks.d.ts +9 -0
  101. package/dist/locks.d.ts.map +1 -0
  102. package/dist/locks.js +61 -0
  103. package/dist/log.d.ts +1 -0
  104. package/dist/log.d.ts.map +1 -1
  105. package/dist/lost.d.ts +5 -0
  106. package/dist/lost.d.ts.map +1 -0
  107. package/dist/lost.js +61 -0
  108. package/dist/media.d.ts +8 -0
  109. package/dist/media.d.ts.map +1 -0
  110. package/dist/media.js +218 -0
  111. package/dist/memory.d.ts +19 -7
  112. package/dist/memory.d.ts.map +1 -1
  113. package/dist/memory.js +248 -103
  114. package/dist/messages.d.ts +52 -0
  115. package/dist/messages.d.ts.map +1 -0
  116. package/dist/messages.js +168 -0
  117. package/dist/model.d.ts +8 -10
  118. package/dist/model.d.ts.map +1 -1
  119. package/dist/model.js +6 -18
  120. package/dist/models.d.ts +14 -0
  121. package/dist/models.d.ts.map +1 -0
  122. package/dist/models.js +193 -0
  123. package/dist/name.d.ts +4 -0
  124. package/dist/name.d.ts.map +1 -0
  125. package/dist/name.js +122 -0
  126. package/dist/observation.d.ts +17 -2
  127. package/dist/observation.d.ts.map +1 -1
  128. package/dist/observation.js +100 -5
  129. package/dist/opened.d.ts +22 -0
  130. package/dist/opened.d.ts.map +1 -0
  131. package/dist/opened.js +107 -0
  132. package/dist/opening.d.ts +4 -0
  133. package/dist/opening.d.ts.map +1 -0
  134. package/dist/opening.js +56 -0
  135. package/dist/outcome.d.ts +49 -8
  136. package/dist/outcome.d.ts.map +1 -1
  137. package/dist/outcome.js +42 -0
  138. package/dist/overlay.d.ts +4 -5
  139. package/dist/overlay.d.ts.map +1 -1
  140. package/dist/overlay.js +106 -156
  141. package/dist/{chat/parts.d.ts → parts.d.ts} +11 -9
  142. package/dist/parts.d.ts.map +1 -0
  143. package/dist/{chat/parts.js → parts.js} +45 -46
  144. package/dist/paths.d.ts +1 -0
  145. package/dist/paths.d.ts.map +1 -1
  146. package/dist/paths.js +4 -0
  147. package/dist/preparation.d.ts +20 -0
  148. package/dist/preparation.d.ts.map +1 -0
  149. package/dist/preparation.js +226 -0
  150. package/dist/queries.d.ts +16 -0
  151. package/dist/queries.d.ts.map +1 -0
  152. package/dist/queries.js +272 -0
  153. package/dist/query.d.ts +26 -185
  154. package/dist/query.d.ts.map +1 -1
  155. package/dist/query.js +3 -464
  156. package/dist/{chat/questions.d.ts → questions.d.ts} +5 -2
  157. package/dist/questions.d.ts.map +1 -0
  158. package/dist/{chat/questions.js → questions.js} +12 -1
  159. package/dist/reach.d.ts +19 -9
  160. package/dist/reach.d.ts.map +1 -1
  161. package/dist/reach.js +287 -99
  162. package/dist/react.d.ts +12 -4
  163. package/dist/react.d.ts.map +1 -1
  164. package/dist/react.js +7 -17
  165. package/dist/{chat/read.d.ts → read.d.ts} +2 -0
  166. package/dist/read.d.ts.map +1 -0
  167. package/dist/{chat/read.js → read.js} +4 -0
  168. package/dist/readiness.d.ts +14 -17
  169. package/dist/readiness.d.ts.map +1 -1
  170. package/dist/readiness.js +2 -8
  171. package/dist/reads.d.ts +36 -0
  172. package/dist/reads.d.ts.map +1 -0
  173. package/dist/reads.js +150 -0
  174. package/dist/recovery.d.ts +3 -2
  175. package/dist/recovery.d.ts.map +1 -1
  176. package/dist/recovery.js +43 -8
  177. package/dist/refresh.d.ts +17 -14
  178. package/dist/refresh.d.ts.map +1 -1
  179. package/dist/refresh.js +143 -52
  180. package/dist/refusal.d.ts +5 -0
  181. package/dist/refusal.d.ts.map +1 -0
  182. package/dist/refusal.js +56 -0
  183. package/dist/replica.d.ts +55 -33
  184. package/dist/replica.d.ts.map +1 -1
  185. package/dist/replica.js +331 -181
  186. package/dist/room-draft.d.ts +37 -6
  187. package/dist/room-draft.d.ts.map +1 -1
  188. package/dist/room-draft.js +161 -74
  189. package/dist/room-drafts.d.ts +24 -0
  190. package/dist/room-drafts.d.ts.map +1 -0
  191. package/dist/room-drafts.js +216 -0
  192. package/dist/rows.d.ts +31 -29
  193. package/dist/rows.d.ts.map +1 -1
  194. package/dist/rows.js +59 -116
  195. package/dist/runtime.d.ts +42 -0
  196. package/dist/runtime.d.ts.map +1 -0
  197. package/dist/runtime.js +1 -0
  198. package/dist/save.d.ts +53 -14
  199. package/dist/save.d.ts.map +1 -1
  200. package/dist/save.js +534 -187
  201. package/dist/saves.d.ts +70 -0
  202. package/dist/saves.d.ts.map +1 -0
  203. package/dist/saves.js +1004 -0
  204. package/dist/search.d.ts +15 -78
  205. package/dist/search.d.ts.map +1 -1
  206. package/dist/search.js +10 -184
  207. package/dist/seed.d.ts +25 -0
  208. package/dist/seed.d.ts.map +1 -0
  209. package/dist/seed.js +146 -0
  210. package/dist/shared.d.ts +7 -3
  211. package/dist/shared.d.ts.map +1 -1
  212. package/dist/shared.js +119 -66
  213. package/dist/shown.d.ts +31 -0
  214. package/dist/shown.d.ts.map +1 -0
  215. package/dist/shown.js +294 -0
  216. package/dist/socket/admission.d.ts +7 -0
  217. package/dist/socket/admission.d.ts.map +1 -0
  218. package/dist/socket/admission.js +39 -0
  219. package/dist/socket/answers.d.ts +6 -0
  220. package/dist/socket/answers.d.ts.map +1 -0
  221. package/dist/socket/answers.js +20 -0
  222. package/dist/socket/lanes.d.ts +20 -0
  223. package/dist/socket/lanes.d.ts.map +1 -0
  224. package/dist/socket/lanes.js +77 -0
  225. package/dist/socket/reads.d.ts +10 -0
  226. package/dist/socket/reads.d.ts.map +1 -0
  227. package/dist/socket/reads.js +31 -0
  228. package/dist/socket/rooms.d.ts +43 -0
  229. package/dist/socket/rooms.d.ts.map +1 -0
  230. package/dist/socket/rooms.js +90 -0
  231. package/dist/socket/session.d.ts +39 -0
  232. package/dist/socket/session.d.ts.map +1 -0
  233. package/dist/socket/session.js +23 -0
  234. package/dist/socket.d.ts +70 -0
  235. package/dist/socket.d.ts.map +1 -0
  236. package/dist/socket.js +175 -0
  237. package/dist/source.d.ts +61 -0
  238. package/dist/source.d.ts.map +1 -0
  239. package/dist/source.js +81 -0
  240. package/dist/status.d.ts +4 -5
  241. package/dist/status.d.ts.map +1 -1
  242. package/dist/status.js +3 -7
  243. package/dist/store/fences.d.ts +16 -0
  244. package/dist/store/fences.d.ts.map +1 -0
  245. package/dist/store/fences.js +26 -0
  246. package/dist/store/installs.d.ts +30 -0
  247. package/dist/store/installs.d.ts.map +1 -0
  248. package/dist/store/installs.js +34 -0
  249. package/dist/store/readiness.d.ts +10 -0
  250. package/dist/store/readiness.d.ts.map +1 -0
  251. package/dist/store/readiness.js +52 -0
  252. package/dist/store/records.d.ts +212 -0
  253. package/dist/store/records.d.ts.map +1 -0
  254. package/dist/store/records.js +408 -0
  255. package/dist/store/room-held.d.ts +8 -0
  256. package/dist/store/room-held.d.ts.map +1 -0
  257. package/dist/store/room-held.js +17 -0
  258. package/dist/store/space.d.ts +11 -0
  259. package/dist/store/space.d.ts.map +1 -0
  260. package/dist/store/space.js +43 -0
  261. package/dist/store/watchers.d.ts +17 -0
  262. package/dist/store/watchers.d.ts.map +1 -0
  263. package/dist/store/watchers.js +57 -0
  264. package/dist/store/writes.d.ts +24 -0
  265. package/dist/store/writes.d.ts.map +1 -0
  266. package/dist/store/writes.js +125 -0
  267. package/dist/store.d.ts +106 -150
  268. package/dist/store.d.ts.map +1 -1
  269. package/dist/store.js +136 -713
  270. package/dist/stored.d.ts +156 -0
  271. package/dist/stored.d.ts.map +1 -0
  272. package/dist/stored.js +637 -0
  273. package/dist/surface.d.ts +88 -0
  274. package/dist/surface.d.ts.map +1 -0
  275. package/dist/surface.js +222 -0
  276. package/dist/sync.d.ts +20 -0
  277. package/dist/sync.d.ts.map +1 -0
  278. package/dist/sync.js +531 -0
  279. package/dist/tables.d.ts +415 -0
  280. package/dist/tables.d.ts.map +1 -0
  281. package/dist/tables.js +740 -0
  282. package/dist/tallies.d.ts +18 -0
  283. package/dist/tallies.d.ts.map +1 -0
  284. package/dist/tallies.js +129 -0
  285. package/dist/transfer.d.ts +0 -5
  286. package/dist/transfer.d.ts.map +1 -1
  287. package/dist/turn.d.ts +5 -3
  288. package/dist/turn.d.ts.map +1 -1
  289. package/dist/turn.js +51 -21
  290. package/dist/validation.d.ts +29 -0
  291. package/dist/validation.d.ts.map +1 -0
  292. package/dist/validation.js +104 -0
  293. package/dist/windows.d.ts +11 -0
  294. package/dist/windows.d.ts.map +1 -0
  295. package/dist/windows.js +16 -0
  296. package/dist/wire.d.ts +50 -6
  297. package/dist/wire.d.ts.map +1 -1
  298. package/dist/wire.js +16 -2
  299. package/package.json +18 -19
  300. package/AGENTS.md +0 -300
  301. package/dist/acquisition.d.ts +0 -14
  302. package/dist/acquisition.d.ts.map +0 -1
  303. package/dist/acquisition.js +0 -24
  304. package/dist/chat/acts.d.ts +0 -33
  305. package/dist/chat/acts.d.ts.map +0 -1
  306. package/dist/chat/acts.js +0 -36
  307. package/dist/chat/context.d.ts +0 -3
  308. package/dist/chat/context.d.ts.map +0 -1
  309. package/dist/chat/input.d.ts +0 -9
  310. package/dist/chat/input.d.ts.map +0 -1
  311. package/dist/chat/input.js +0 -99
  312. package/dist/chat/kit.d.ts +0 -61
  313. package/dist/chat/kit.d.ts.map +0 -1
  314. package/dist/chat/kit.js +0 -123
  315. package/dist/chat/lasting.d.ts +0 -6
  316. package/dist/chat/lasting.d.ts.map +0 -1
  317. package/dist/chat/lasting.js +0 -19
  318. package/dist/chat/list.d.ts +0 -27
  319. package/dist/chat/list.d.ts.map +0 -1
  320. package/dist/chat/list.js +0 -63
  321. package/dist/chat/markdown.d.ts +0 -20
  322. package/dist/chat/markdown.d.ts.map +0 -1
  323. package/dist/chat/markdown.js +0 -188
  324. package/dist/chat/message.d.ts +0 -6
  325. package/dist/chat/message.d.ts.map +0 -1
  326. package/dist/chat/message.js +0 -192
  327. package/dist/chat/messages.d.ts +0 -22
  328. package/dist/chat/messages.d.ts.map +0 -1
  329. package/dist/chat/messages.js +0 -155
  330. package/dist/chat/name.d.ts +0 -6
  331. package/dist/chat/name.d.ts.map +0 -1
  332. package/dist/chat/name.js +0 -37
  333. package/dist/chat/opened.d.ts +0 -11
  334. package/dist/chat/opened.d.ts.map +0 -1
  335. package/dist/chat/opened.js +0 -17
  336. package/dist/chat/overlay.d.ts +0 -31
  337. package/dist/chat/overlay.d.ts.map +0 -1
  338. package/dist/chat/overlay.js +0 -97
  339. package/dist/chat/parts.d.ts.map +0 -1
  340. package/dist/chat/process.d.ts +0 -20
  341. package/dist/chat/process.d.ts.map +0 -1
  342. package/dist/chat/process.js +0 -32
  343. package/dist/chat/provider.d.ts +0 -63
  344. package/dist/chat/provider.d.ts.map +0 -1
  345. package/dist/chat/provider.js +0 -629
  346. package/dist/chat/question.d.ts +0 -9
  347. package/dist/chat/question.d.ts.map +0 -1
  348. package/dist/chat/question.js +0 -80
  349. package/dist/chat/questions.d.ts.map +0 -1
  350. package/dist/chat/read.d.ts.map +0 -1
  351. package/dist/chat/ready.d.ts +0 -34
  352. package/dist/chat/ready.d.ts.map +0 -1
  353. package/dist/chat/ready.js +0 -91
  354. package/dist/chat/style.d.ts +0 -4
  355. package/dist/chat/style.d.ts.map +0 -1
  356. package/dist/chat/style.js +0 -302
  357. package/dist/chat.d.ts +0 -14
  358. package/dist/chat.d.ts.map +0 -1
  359. package/dist/chat.js +0 -8
  360. package/dist/fence.d.ts +0 -6
  361. package/dist/fence.d.ts.map +0 -1
  362. package/dist/fence.js +0 -10
  363. package/dist/read-side.d.ts +0 -25
  364. package/dist/read-side.d.ts.map +0 -1
  365. package/dist/read-side.js +0 -639
package/dist/replica.js CHANGED
@@ -1,199 +1,215 @@
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 { ROW_WEIGHT } from './turn.js';
9
+ export function compositionOf(record, builtIn, typedPaths) {
8
10
  return {
9
11
  model: record.model,
10
12
  selection: record.typedSelection === null
11
13
  ? null
12
- : { roots: record.typedSelection.roots, model: record.selectionModel },
14
+ : { roots: record.typedSelection.roots, model: builtIn },
15
+ typedPaths,
13
16
  };
14
17
  }
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 };
18
+ export function storedRecord(record) {
19
+ const { key: _key, ...stored } = record;
20
+ return JSON.stringify({ ...stored, model: storedModel(stored.model) });
28
21
  }
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),
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}`);
32
+ }
33
+ }
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
+ }
34
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
+ });
35
54
  }
36
- export function sameMembership(record, other) {
37
- return (JSON.stringify(record.typedSelection?.roots ?? null) ===
38
- JSON.stringify(other.typedSelection?.roots ?? null));
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;
85
+ }
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
+ };
39
97
  }
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));
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,
112
+ };
45
113
  }
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;
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 });
63
120
  }
121
+ yield ROW_WEIGHT;
64
122
  }
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) };
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]);
71
128
  }
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 };
129
+ function changePaths(change) {
130
+ return change.kind === 'move' ? [change.path, change.to] : [change.path];
79
131
  }
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];
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);
116
142
  }
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);
143
+ return paths;
126
144
  }
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
- });
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
+ }
163
157
  }
164
- return { layer, replay };
158
+ return paths;
165
159
  }
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
- };
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;
181
175
  }
182
- const { layer, replay } = predicted(confirmed, batches, previous);
183
176
  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
- },
177
+ visible: { ...layer, collection: collectionOf(layer.documents, composition) },
178
+ touched,
191
179
  };
192
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
+ }
193
209
  function present(layer, path) {
194
210
  return layer.documents[path] !== undefined || layer.binaries[path] !== undefined;
195
211
  }
196
- function holds(layer, preconditions) {
212
+ export function holds(layer, preconditions) {
197
213
  const parsed = new Map();
198
214
  const documentAt = (path) => {
199
215
  if (!parsed.has(path)) {
@@ -258,15 +274,19 @@ function effects(change) {
258
274
  { kind: 'present', path: change.to },
259
275
  ];
260
276
  }
261
- if (change.kind === 'binary')
277
+ if (change.kind === 'binary' || change.kind === 'arrival')
262
278
  return [{ kind: 'present', path }];
263
279
  return [{ kind: 'absent', path }];
264
280
  }
265
281
  export function landed(batch, confirmed, current = {}) {
266
- const layer = {
267
- ...confirmed.record,
268
- documents: patched(confirmed.record.documents, Object.entries(current)),
269
- };
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 };
270
290
  return batch.changes.every((change, index) => {
271
291
  if (change.kind === 'replace' || (change.kind === 'create' && 'content' in change)) {
272
292
  const at = landing(batch.changes, index, change.path);
@@ -284,32 +304,162 @@ export function landed(batch, confirmed, current = {}) {
284
304
  });
285
305
  });
286
306
  }
287
- 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) {
288
322
  if (!queue.some(withdrawable))
289
- return [];
290
- const composition = compositionOf(confirmed.record);
291
- let layer = confirmed.record;
323
+ return { withdrawn: [], kept: queue };
324
+ let layer = confirmed;
292
325
  const withdrawn = [];
326
+ const kept = [];
293
327
  for (const batch of queue) {
294
328
  if (withdrawable(batch) && !holds(layer, batch.preconditions)) {
295
329
  withdrawn.push(batch);
296
330
  continue;
297
331
  }
298
- const effective = batch.changes.some((change) => change.kind === 'move')
299
- ? providerRewritten(batch, {
332
+ const effective = rewriting(batch, locator)
333
+ ? yield* effectiveIn(batch, locator, {
300
334
  ...layer,
301
335
  collection: collectionOf(layer.documents, composition),
302
336
  })
303
337
  : batch;
304
338
  let unapplied = false;
305
- const next = overlay(layer, [effective], () => {
339
+ const next = yield* overlaying(layer, [effective], () => {
306
340
  unapplied = true;
307
341
  });
308
342
  if (local && unapplied) {
309
343
  withdrawn.push(batch);
310
344
  continue;
311
345
  }
346
+ kept.push(local || !withdrawable(batch) ? batch : founded(batch, layer));
312
347
  layer = next;
313
348
  }
314
- 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 };
315
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: 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[];