@agentshouse/mdruntime 0.1.0-c94cfdbdb6f68 → 0.1.0-c95dc33df5c05

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