@agentshouse/mdruntime 0.1.0-cd3ee807e46ae → 0.1.0-cd507e16e5fc0

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 (361) 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 +157 -57
  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/attempt.d.ts.map +1 -1
  14. package/dist/attempt.js +14 -1
  15. package/dist/binary.d.ts +0 -5
  16. package/dist/binary.d.ts.map +1 -1
  17. package/dist/binary.js +1 -1
  18. package/dist/bootstrap.d.ts +31 -11
  19. package/dist/bootstrap.d.ts.map +1 -1
  20. package/dist/bootstrap.js +324 -89
  21. package/dist/cell.d.ts +6 -0
  22. package/dist/cell.d.ts.map +1 -0
  23. package/dist/cell.js +9 -0
  24. package/dist/chain.d.ts +12 -0
  25. package/dist/chain.d.ts.map +1 -0
  26. package/dist/chain.js +64 -0
  27. package/dist/change-set.d.ts +9 -14
  28. package/dist/change-set.d.ts.map +1 -1
  29. package/dist/change-set.js +11 -63
  30. package/dist/change.d.ts +32 -1
  31. package/dist/change.d.ts.map +1 -1
  32. package/dist/change.js +10 -1
  33. package/dist/chat-types.d.ts +5 -0
  34. package/dist/chat-types.d.ts.map +1 -0
  35. package/dist/chat-types.js +13 -0
  36. package/dist/client.d.ts +43 -16
  37. package/dist/client.d.ts.map +1 -1
  38. package/dist/client.js +101 -12
  39. package/dist/collection.d.ts +11 -7
  40. package/dist/collection.d.ts.map +1 -1
  41. package/dist/collection.js +38 -79
  42. package/dist/compile.d.ts +16 -0
  43. package/dist/compile.d.ts.map +1 -0
  44. package/dist/compile.js +717 -0
  45. package/dist/connection.d.ts +8 -116
  46. package/dist/connection.d.ts.map +1 -1
  47. package/dist/connection.js +104 -2410
  48. package/dist/context.d.ts +2 -0
  49. package/dist/context.d.ts.map +1 -0
  50. package/dist/{chat/context.js → context.js} +1 -4
  51. package/dist/conversation-live.d.ts +136 -0
  52. package/dist/conversation-live.d.ts.map +1 -0
  53. package/dist/conversation-live.js +248 -0
  54. package/dist/conversation-row.d.ts +33 -0
  55. package/dist/conversation-row.d.ts.map +1 -0
  56. package/dist/conversation-row.js +53 -0
  57. package/dist/conversation.d.ts +57 -40
  58. package/dist/conversation.d.ts.map +1 -1
  59. package/dist/conversation.js +992 -543
  60. package/dist/digest.d.ts +7 -0
  61. package/dist/digest.d.ts.map +1 -0
  62. package/dist/digest.js +113 -0
  63. package/dist/discovery.d.ts +10 -0
  64. package/dist/discovery.d.ts.map +1 -0
  65. package/dist/discovery.js +175 -0
  66. package/dist/durability.d.ts +19 -1
  67. package/dist/durability.d.ts.map +1 -1
  68. package/dist/durability.js +5 -0
  69. package/dist/entry.d.ts +20 -0
  70. package/dist/entry.d.ts.map +1 -0
  71. package/dist/entry.js +161 -0
  72. package/dist/figures.d.ts +49 -0
  73. package/dist/figures.d.ts.map +1 -0
  74. package/dist/figures.js +197 -0
  75. package/dist/file.d.ts +2 -19
  76. package/dist/file.d.ts.map +1 -1
  77. package/dist/file.js +7 -122
  78. package/dist/holdings.d.ts +29 -0
  79. package/dist/holdings.d.ts.map +1 -0
  80. package/dist/holdings.js +95 -0
  81. package/dist/host.d.ts +12 -3
  82. package/dist/host.d.ts.map +1 -1
  83. package/dist/host.js +130 -20
  84. package/dist/index.d.ts +34 -11
  85. package/dist/index.d.ts.map +1 -1
  86. package/dist/index.js +12 -0
  87. package/dist/install.d.ts +56 -0
  88. package/dist/install.d.ts.map +1 -0
  89. package/dist/install.js +556 -0
  90. package/dist/job.d.ts +33 -0
  91. package/dist/job.d.ts.map +1 -0
  92. package/dist/job.js +54 -0
  93. package/dist/lifecycle.d.ts +7 -0
  94. package/dist/lifecycle.d.ts.map +1 -0
  95. package/dist/lifecycle.js +268 -0
  96. package/dist/listing.d.ts +53 -0
  97. package/dist/listing.d.ts.map +1 -0
  98. package/dist/listing.js +176 -0
  99. package/dist/live.d.ts +23 -0
  100. package/dist/live.d.ts.map +1 -0
  101. package/dist/live.js +165 -0
  102. package/dist/locks.d.ts +9 -0
  103. package/dist/locks.d.ts.map +1 -0
  104. package/dist/locks.js +61 -0
  105. package/dist/log.d.ts +1 -0
  106. package/dist/log.d.ts.map +1 -1
  107. package/dist/lost.d.ts +5 -0
  108. package/dist/lost.d.ts.map +1 -0
  109. package/dist/lost.js +61 -0
  110. package/dist/media.d.ts +8 -0
  111. package/dist/media.d.ts.map +1 -0
  112. package/dist/media.js +218 -0
  113. package/dist/memory.d.ts +19 -5
  114. package/dist/memory.d.ts.map +1 -1
  115. package/dist/memory.js +254 -94
  116. package/dist/messages.d.ts +52 -0
  117. package/dist/messages.d.ts.map +1 -0
  118. package/dist/messages.js +168 -0
  119. package/dist/model.d.ts +11 -11
  120. package/dist/model.d.ts.map +1 -1
  121. package/dist/model.js +7 -10
  122. package/dist/models.d.ts +14 -0
  123. package/dist/models.d.ts.map +1 -0
  124. package/dist/models.js +195 -0
  125. package/dist/name.d.ts +4 -0
  126. package/dist/name.d.ts.map +1 -0
  127. package/dist/name.js +122 -0
  128. package/dist/observation.d.ts +22 -4
  129. package/dist/observation.d.ts.map +1 -1
  130. package/dist/observation.js +120 -14
  131. package/dist/opened.d.ts +22 -0
  132. package/dist/opened.d.ts.map +1 -0
  133. package/dist/opened.js +107 -0
  134. package/dist/opening.d.ts +4 -0
  135. package/dist/opening.d.ts.map +1 -0
  136. package/dist/opening.js +57 -0
  137. package/dist/outcome.d.ts +53 -8
  138. package/dist/outcome.d.ts.map +1 -1
  139. package/dist/outcome.js +43 -0
  140. package/dist/overlay.d.ts +4 -4
  141. package/dist/overlay.d.ts.map +1 -1
  142. package/dist/overlay.js +111 -182
  143. package/dist/{chat/parts.d.ts → parts.d.ts} +11 -9
  144. package/dist/parts.d.ts.map +1 -0
  145. package/dist/{chat/parts.js → parts.js} +45 -46
  146. package/dist/paths.d.ts +2 -0
  147. package/dist/paths.d.ts.map +1 -1
  148. package/dist/paths.js +26 -0
  149. package/dist/preparation.d.ts +20 -0
  150. package/dist/preparation.d.ts.map +1 -0
  151. package/dist/preparation.js +226 -0
  152. package/dist/queries.d.ts +16 -0
  153. package/dist/queries.d.ts.map +1 -0
  154. package/dist/queries.js +272 -0
  155. package/dist/query.d.ts +50 -183
  156. package/dist/query.d.ts.map +1 -1
  157. package/dist/query.js +3 -464
  158. package/dist/{chat/questions.d.ts → questions.d.ts} +5 -2
  159. package/dist/questions.d.ts.map +1 -0
  160. package/dist/{chat/questions.js → questions.js} +12 -1
  161. package/dist/reach.d.ts +21 -7
  162. package/dist/reach.d.ts.map +1 -1
  163. package/dist/reach.js +289 -89
  164. package/dist/react.d.ts +16 -6
  165. package/dist/react.d.ts.map +1 -1
  166. package/dist/react.js +7 -17
  167. package/dist/{chat/read.d.ts → read.d.ts} +2 -0
  168. package/dist/read.d.ts.map +1 -0
  169. package/dist/{chat/read.js → read.js} +4 -0
  170. package/dist/readiness.d.ts +49 -0
  171. package/dist/readiness.d.ts.map +1 -0
  172. package/dist/readiness.js +27 -0
  173. package/dist/reads.d.ts +37 -0
  174. package/dist/reads.d.ts.map +1 -0
  175. package/dist/reads.js +171 -0
  176. package/dist/recovery.d.ts +26 -0
  177. package/dist/recovery.d.ts.map +1 -0
  178. package/dist/recovery.js +232 -0
  179. package/dist/refresh.d.ts +17 -14
  180. package/dist/refresh.d.ts.map +1 -1
  181. package/dist/refresh.js +143 -51
  182. package/dist/refusal.d.ts +5 -0
  183. package/dist/refusal.d.ts.map +1 -0
  184. package/dist/refusal.js +56 -0
  185. package/dist/replica.d.ts +56 -33
  186. package/dist/replica.d.ts.map +1 -1
  187. package/dist/replica.js +333 -154
  188. package/dist/room-draft.d.ts +37 -6
  189. package/dist/room-draft.d.ts.map +1 -1
  190. package/dist/room-draft.js +161 -74
  191. package/dist/room-drafts.d.ts +24 -0
  192. package/dist/room-drafts.d.ts.map +1 -0
  193. package/dist/room-drafts.js +216 -0
  194. package/dist/rows.d.ts +30 -37
  195. package/dist/rows.d.ts.map +1 -1
  196. package/dist/rows.js +59 -126
  197. package/dist/runtime.d.ts +43 -0
  198. package/dist/runtime.d.ts.map +1 -0
  199. package/dist/runtime.js +1 -0
  200. package/dist/save.d.ts +56 -9
  201. package/dist/save.d.ts.map +1 -1
  202. package/dist/save.js +548 -174
  203. package/dist/saves.d.ts +70 -0
  204. package/dist/saves.d.ts.map +1 -0
  205. package/dist/saves.js +1008 -0
  206. package/dist/search.d.ts +15 -55
  207. package/dist/search.d.ts.map +1 -1
  208. package/dist/search.js +10 -121
  209. package/dist/seed.d.ts +25 -0
  210. package/dist/seed.d.ts.map +1 -0
  211. package/dist/seed.js +146 -0
  212. package/dist/shared.d.ts +15 -0
  213. package/dist/shared.d.ts.map +1 -0
  214. package/dist/shared.js +425 -0
  215. package/dist/shown.d.ts +31 -0
  216. package/dist/shown.d.ts.map +1 -0
  217. package/dist/shown.js +295 -0
  218. package/dist/socket/admission.d.ts +7 -0
  219. package/dist/socket/admission.d.ts.map +1 -0
  220. package/dist/socket/admission.js +39 -0
  221. package/dist/socket/answers.d.ts +6 -0
  222. package/dist/socket/answers.d.ts.map +1 -0
  223. package/dist/socket/answers.js +20 -0
  224. package/dist/socket/lanes.d.ts +20 -0
  225. package/dist/socket/lanes.d.ts.map +1 -0
  226. package/dist/socket/lanes.js +77 -0
  227. package/dist/socket/reads.d.ts +10 -0
  228. package/dist/socket/reads.d.ts.map +1 -0
  229. package/dist/socket/reads.js +31 -0
  230. package/dist/socket/rooms.d.ts +44 -0
  231. package/dist/socket/rooms.d.ts.map +1 -0
  232. package/dist/socket/rooms.js +90 -0
  233. package/dist/socket/session.d.ts +39 -0
  234. package/dist/socket/session.d.ts.map +1 -0
  235. package/dist/socket/session.js +23 -0
  236. package/dist/socket.d.ts +70 -0
  237. package/dist/socket.d.ts.map +1 -0
  238. package/dist/socket.js +175 -0
  239. package/dist/source.d.ts +61 -0
  240. package/dist/source.d.ts.map +1 -0
  241. package/dist/source.js +81 -0
  242. package/dist/status.d.ts +5 -2
  243. package/dist/status.d.ts.map +1 -1
  244. package/dist/status.js +3 -7
  245. package/dist/store/fences.d.ts +16 -0
  246. package/dist/store/fences.d.ts.map +1 -0
  247. package/dist/store/fences.js +26 -0
  248. package/dist/store/installs.d.ts +30 -0
  249. package/dist/store/installs.d.ts.map +1 -0
  250. package/dist/store/installs.js +34 -0
  251. package/dist/store/readiness.d.ts +10 -0
  252. package/dist/store/readiness.d.ts.map +1 -0
  253. package/dist/store/readiness.js +52 -0
  254. package/dist/store/records.d.ts +212 -0
  255. package/dist/store/records.d.ts.map +1 -0
  256. package/dist/store/records.js +431 -0
  257. package/dist/store/room-held.d.ts +8 -0
  258. package/dist/store/room-held.d.ts.map +1 -0
  259. package/dist/store/room-held.js +17 -0
  260. package/dist/store/space.d.ts +11 -0
  261. package/dist/store/space.d.ts.map +1 -0
  262. package/dist/store/space.js +43 -0
  263. package/dist/store/watchers.d.ts +17 -0
  264. package/dist/store/watchers.d.ts.map +1 -0
  265. package/dist/store/watchers.js +57 -0
  266. package/dist/store/writes.d.ts +24 -0
  267. package/dist/store/writes.d.ts.map +1 -0
  268. package/dist/store/writes.js +125 -0
  269. package/dist/store.d.ts +106 -117
  270. package/dist/store.d.ts.map +1 -1
  271. package/dist/store.js +138 -490
  272. package/dist/stored.d.ts +156 -0
  273. package/dist/stored.d.ts.map +1 -0
  274. package/dist/stored.js +649 -0
  275. package/dist/surface.d.ts +88 -0
  276. package/dist/surface.d.ts.map +1 -0
  277. package/dist/surface.js +223 -0
  278. package/dist/sync.d.ts +19 -0
  279. package/dist/sync.d.ts.map +1 -0
  280. package/dist/sync.js +532 -0
  281. package/dist/tables.d.ts +417 -0
  282. package/dist/tables.d.ts.map +1 -0
  283. package/dist/tables.js +740 -0
  284. package/dist/tallies.d.ts +18 -0
  285. package/dist/tallies.d.ts.map +1 -0
  286. package/dist/tallies.js +129 -0
  287. package/dist/transfer.d.ts +0 -5
  288. package/dist/transfer.d.ts.map +1 -1
  289. package/dist/turn.d.ts +9 -0
  290. package/dist/turn.d.ts.map +1 -0
  291. package/dist/turn.js +75 -0
  292. package/dist/validation.d.ts +29 -0
  293. package/dist/validation.d.ts.map +1 -0
  294. package/dist/validation.js +104 -0
  295. package/dist/windows.d.ts +11 -0
  296. package/dist/windows.d.ts.map +1 -0
  297. package/dist/windows.js +16 -0
  298. package/dist/wire.d.ts +181 -33
  299. package/dist/wire.d.ts.map +1 -1
  300. package/dist/wire.js +62 -31
  301. package/package.json +22 -19
  302. package/AGENTS.md +0 -318
  303. package/dist/chat/acts.d.ts +0 -34
  304. package/dist/chat/acts.d.ts.map +0 -1
  305. package/dist/chat/acts.js +0 -36
  306. package/dist/chat/context.d.ts +0 -3
  307. package/dist/chat/context.d.ts.map +0 -1
  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 -60
  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 -20
  318. package/dist/chat/list.d.ts.map +0 -1
  319. package/dist/chat/list.js +0 -59
  320. package/dist/chat/markdown.d.ts +0 -19
  321. package/dist/chat/markdown.d.ts.map +0 -1
  322. package/dist/chat/markdown.js +0 -187
  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 -21
  327. package/dist/chat/messages.d.ts.map +0 -1
  328. package/dist/chat/messages.js +0 -151
  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 -645
  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 -80
  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 -33
  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/read-side.d.ts +0 -18
  360. package/dist/read-side.d.ts.map +0 -1
  361. package/dist/read-side.js +0 -440
@@ -0,0 +1,216 @@
1
+ import { plain } from '@agentshouse/mdmodel';
2
+ import { changeSet } from './change-set.js';
3
+ import { collectionOf } from './collection.js';
4
+ import { runtimeError } from './failure.js';
5
+ import { roomDraftRevision } from './identity.js';
6
+ import { normalize } from './paths.js';
7
+ import { slicing } from './replica.js';
8
+ import { binaryBase, gatheredParts, held, heldFile, readParts, staleWrite, underneath, } from './room-draft.js';
9
+ import { stepped } from './turn.js';
10
+ const ROOM_DRAFTS = 'room-drafts';
11
+ const presentationTopic = (app) => `presentation\u0000${app}`;
12
+ export async function visibleOf(store, locator, paths) {
13
+ const kept = await store.record(locator);
14
+ if (kept === undefined)
15
+ return undefined;
16
+ const local = await store.open();
17
+ const slice = await stepped(slicing(await local.entries(kept.key, 'visible', paths), paths));
18
+ return { ...slice, collection: collectionOf(slice.documents, store.composed(kept)) };
19
+ }
20
+ function roomDraftOf(record, visible) {
21
+ return structuredClone({
22
+ room: record.locator,
23
+ path: record.path,
24
+ revision: record.revision,
25
+ parts: record.parts,
26
+ changedUnderneath: underneath(record.parts, record.path, visible),
27
+ returned: record.returned,
28
+ });
29
+ }
30
+ async function roomDraftsOf(store, records) {
31
+ const rooms = new Map();
32
+ for (const record of records) {
33
+ const paths = rooms.get(record.locator) ?? [];
34
+ paths.push(record.path);
35
+ rooms.set(record.locator, paths);
36
+ }
37
+ const layers = new Map();
38
+ for (const [locator, paths] of rooms) {
39
+ layers.set(locator, await visibleOf(store, locator, paths));
40
+ }
41
+ return records.map((record) => roomDraftOf(record, layers.get(record.locator)));
42
+ }
43
+ function inOrder(records) {
44
+ return [...records].sort((left, right) => {
45
+ if (left.locator !== right.locator)
46
+ return left.locator < right.locator ? -1 : 1;
47
+ if (left.path !== right.path)
48
+ return left.path < right.path ? -1 : 1;
49
+ return 0;
50
+ });
51
+ }
52
+ async function snapshotRoomDrafts(store) {
53
+ return roomDraftsOf(store, inOrder(await store.drafts()));
54
+ }
55
+ export function publishRoomDrafts({ store, socket }, waitingOnly, touched = null) {
56
+ const unwatched = () => socket.closed() || store.watching(ROOM_DRAFTS).length === 0;
57
+ if (unwatched())
58
+ return Promise.resolve();
59
+ return store.publication(async () => {
60
+ if (unwatched())
61
+ return;
62
+ const records = await store.drafts();
63
+ if (socket.closed())
64
+ return;
65
+ if (touched !== null &&
66
+ !records.some((record) => touched.some(({ locator, path }) => locator === record.locator && (path === null || path === record.path)))) {
67
+ return;
68
+ }
69
+ const value = await roomDraftsOf(store, inOrder(records));
70
+ if (socket.closed())
71
+ return;
72
+ const answered = store.watching(ROOM_DRAFTS, waitingOnly ? 'waiting' : 'all');
73
+ for (const watcher of answered)
74
+ watcher.answer(value);
75
+ });
76
+ }
77
+ async function presentationOf(store, app) {
78
+ const value = await (await store.open()).presentation(app);
79
+ return value === undefined ? null : structuredClone(value);
80
+ }
81
+ export function emitPresentation({ store, socket }, app) {
82
+ const topic = presentationTopic(app);
83
+ const listening = () => store.watching(topic, 'ready');
84
+ if (socket.closed() || listening().length === 0)
85
+ return Promise.resolve();
86
+ return store.publication(async () => {
87
+ if (socket.closed() || listening().length === 0)
88
+ return;
89
+ const value = await presentationOf(store, app);
90
+ if (socket.closed())
91
+ return;
92
+ for (const watcher of listening())
93
+ watcher.answer(value);
94
+ });
95
+ }
96
+ async function writtenRoomDraft({ store }, room, path, revision, input, next) {
97
+ const parts = readParts(input, path);
98
+ if (path === '' || normalize(path) !== path)
99
+ throw runtimeError('room-draft-malformed', `room-draft-malformed at ${path}: a path inside the Room, such as notes/a.md`);
100
+ const local = await store.open();
101
+ const current = await store.draft(room, path);
102
+ if ((current?.revision ?? null) !== revision) {
103
+ return staleWrite(current === undefined ? null : ((await roomDraftsOf(store, [current]))[0] ?? null));
104
+ }
105
+ const file = parts.file === undefined
106
+ ? undefined
107
+ : await heldFile(parts.file.blob, parts.file.base === undefined
108
+ ? binaryBase(await visibleOf(store, room, [path]), path)
109
+ : parts.file.base);
110
+ const record = {
111
+ locator: room,
112
+ path,
113
+ revision: next,
114
+ parts: held(current?.parts, parts, file),
115
+ returned: current?.returned ?? null,
116
+ };
117
+ await local.keepRoomDraft(record, parts.file === undefined || file === undefined
118
+ ? []
119
+ : [{ key: file.localId, blob: parts.file.blob }]);
120
+ await store.changed(changeSet(room, { drafts: [path] }));
121
+ return { outcome: 'written', roomDraft: (await roomDraftsOf(store, [record]))[0] ?? null };
122
+ }
123
+ async function keptPresentation({ store }, app, next) {
124
+ const local = await store.open();
125
+ const stored = next(await local.presentation(app));
126
+ await local.present({ app, value: stored });
127
+ await store.changed(changeSet('', { presentation: app }));
128
+ }
129
+ export function roomDraftSurface(runtime) {
130
+ const { store } = runtime;
131
+ return {
132
+ list() {
133
+ return store
134
+ .exclusive(async () => {
135
+ await store.open();
136
+ return snapshotRoomDrafts(store);
137
+ })
138
+ .then((listed) => {
139
+ publishRoomDrafts(runtime, true);
140
+ return listed;
141
+ });
142
+ },
143
+ async read(room, path) {
144
+ const record = await store.draft(room, path);
145
+ return record === undefined ? null : ((await roomDraftsOf(store, [record]))[0] ?? null);
146
+ },
147
+ write(room, path, revision, input, next = roomDraftRevision()) {
148
+ if (typeof next !== 'string' || next === '')
149
+ return Promise.reject(runtimeError('room-draft-malformed'));
150
+ return store.gathered(`room-draft\u0000${room}\u0000${path}`, { revision, input, next }, (earlier, later) => {
151
+ if (later.revision !== earlier.next)
152
+ return null;
153
+ const parts = gatheredParts(earlier.input, later.input);
154
+ return parts === null
155
+ ? null
156
+ : { revision: earlier.revision, input: parts, next: later.next };
157
+ }, (written) => writtenRoomDraft(runtime, room, path, written.revision, written.input, written.next));
158
+ },
159
+ discard(room, path, revision) {
160
+ return store.exclusive(async () => {
161
+ const local = await store.open();
162
+ const current = await store.draft(room, path);
163
+ if (current === undefined || current.revision !== revision) {
164
+ return staleWrite(current === undefined ? null : ((await roomDraftsOf(store, [current]))[0] ?? null));
165
+ }
166
+ await local.discardRoomDraft(room, path);
167
+ await store.changed(changeSet(room, { drafts: [path] }));
168
+ return { outcome: 'written', roomDraft: null };
169
+ });
170
+ },
171
+ };
172
+ }
173
+ export function presentationSurface(runtime) {
174
+ const { store } = runtime;
175
+ return {
176
+ read(app) {
177
+ return store.exclusive(() => presentationOf(store, app));
178
+ },
179
+ write(app, value) {
180
+ return store.exclusive(() => keptPresentation(runtime, app, () => structuredClone(value)));
181
+ },
182
+ edit(app, members) {
183
+ return store.gathered(`presentation\u0000${app}`, structuredClone(members), (earlier, later) => ({ ...earlier, ...later }), (edited) => keptPresentation(runtime, app, (kept) => Object.fromEntries([
184
+ ...Object.entries(plain(kept) ? kept : {}).filter(([member]) => !Object.hasOwn(edited, member)),
185
+ ...Object.entries(edited).filter(([, value]) => value !== null),
186
+ ])));
187
+ },
188
+ };
189
+ }
190
+ export function watchRoomDrafts({ store, socket }, deliver) {
191
+ const watcher = store.watch(ROOM_DRAFTS, deliver);
192
+ const unwatched = () => socket.closed() || !watcher.held();
193
+ void store
194
+ .exclusive(async () => {
195
+ await store.open();
196
+ })
197
+ .then(() => store.publication(async () => {
198
+ if (unwatched())
199
+ return;
200
+ const value = await snapshotRoomDrafts(store);
201
+ if (!unwatched())
202
+ watcher.answer(value);
203
+ }), () => { });
204
+ return watcher.stop;
205
+ }
206
+ export function watchPresentation({ store, socket }, app, deliver) {
207
+ const watcher = store.watch(presentationTopic(app), deliver);
208
+ void store
209
+ .exclusive(async () => {
210
+ const value = await presentationOf(store, app);
211
+ if (!socket.closed() && watcher.held())
212
+ watcher.answer(value);
213
+ })
214
+ .catch(() => { });
215
+ return watcher.stop;
216
+ }
package/dist/rows.d.ts CHANGED
@@ -1,46 +1,39 @@
1
- import { type Document } from '@agentshouse/mdmodel';
2
- import type { HeadChange } from './adapter.js';
3
- import type { BinaryFileRecord } from './binary.js';
1
+ import { type HeldValue } from '@agentshouse/mdmodel';
2
+ import type { SavedFacts } from './adapter.js';
4
3
  import { type Composition } from './collection.js';
5
- type Fields = Readonly<Record<string, unknown>>;
6
- export type DocumentRow = {
7
- key: string;
8
- kind: 'document';
9
- room: string;
10
- path: string;
11
- type: string | null;
12
- fields: Fields;
13
- values: Fields;
14
- reached: Readonly<Record<string, readonly unknown[]>>;
15
- directories: readonly string[];
16
- body: string;
17
- change: HeadChange | null;
18
- binary: BinaryFileRecord | null;
4
+ type LinkKind = 'field' | 'link';
5
+ type HeldLink = {
6
+ readonly kind: LinkKind;
7
+ readonly keys: string;
8
+ readonly places: string;
9
+ readonly target: string;
10
+ readonly field: string;
19
11
  };
20
- export type BodyRow = {
21
- key: string;
22
- kind: 'body';
23
- room: string;
24
- path: string;
25
- preamble: string;
26
- sections: Readonly<Record<string, string>>;
27
- markdown: string;
12
+ export type Described = {
13
+ readonly type: string | null;
14
+ readonly declared: string | null;
15
+ readonly queried: boolean;
16
+ readonly folder: string;
17
+ readonly fields: string | null;
18
+ readonly links: string | null;
28
19
  };
29
- export type ReferenceRow = {
30
- key: string;
31
- kind: 'reference';
32
- room: string;
33
- source: string;
34
- target: string;
35
- field: string;
36
- forms: readonly string[];
37
- path: string;
38
- type: string;
20
+ export type Held = {
21
+ readonly type: string | null;
22
+ readonly fields: Readonly<Record<string, unknown>> | null;
23
+ readonly links: readonly string[];
24
+ };
25
+ export type Derived = {
26
+ readonly values: readonly HeldValue[];
27
+ readonly links: readonly HeldLink[];
39
28
  };
40
- export type Row = DocumentRow | BodyRow | ReferenceRow;
41
29
  export declare function documentKey(room: string, path: string): string;
42
30
  export declare function roomOfKey(key: string): string;
31
+ export declare function pathOfKey(key: string): string;
43
32
  export declare function markdownPath(path: string): boolean;
44
- export declare function rowsOf(room: string, path: string, document: Document | null, composition: Composition, change: HeadChange | null, binary: BinaryFileRecord | null): readonly Row[];
33
+ export declare function folderOf(path: string): string;
34
+ export declare function writtenFacts(path: string, content: string, composition: Composition): SavedFacts | null;
35
+ export declare function described(path: string, content: string | null, facts: SavedFacts | null): Described;
36
+ export declare function heldOf(path: string, content: string | null, facts: SavedFacts | null): Held;
37
+ export declare function derived(path: string, held: Held, composition: Composition): Derived;
45
38
  export {};
46
39
  //# sourceMappingURL=rows.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"rows.d.ts","sourceRoot":"","sources":["../src/rows.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,QAAQ,EACd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,a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AI,GACvB,SAAS,CAeX;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI,GAAG,IAAI,CAK3F;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,GAAG,OAAO,CAYnF"}
package/dist/rows.js CHANGED
@@ -1,4 +1,4 @@
1
- import { ARRAY_INDEX, escapePointer, references, target, } from '@agentshouse/mdmodel';
1
+ import { byCodePoint, documentFacts, indexed, parse } from '@agentshouse/mdmodel';
2
2
  import { governing } from './collection.js';
3
3
  import { definitionOf } from './model.js';
4
4
  function keyOf(...parts) {
@@ -10,136 +10,69 @@ export function documentKey(room, path) {
10
10
  export function roomOfKey(key) {
11
11
  return key.split('\u0000')[1];
12
12
  }
13
- function plainObject(value) {
14
- return typeof value === 'object' && value !== null && !Array.isArray(value);
13
+ export function pathOfKey(key) {
14
+ return key.split('\u0000')[2];
15
15
  }
16
- function compared(reading, exact, value) {
17
- if (!reading.references.has(exact))
18
- return value;
19
- return (typeof value === 'string' ? target(reading.path, value) : null) ?? undefined;
16
+ export function markdownPath(path) {
17
+ return path.endsWith('.md');
20
18
  }
21
- function record(reading, node, forms, exact) {
22
- const value = Array.isArray(node)
23
- ? node.map((item, index) => compared(reading, `${exact}/${index}`, item))
24
- : compared(reading, exact, node);
25
- for (const form of forms) {
26
- if (form.pending)
27
- continue;
28
- (reading.reached[form.text] ??= []).push(value);
29
- if (!form.through && value !== undefined && !plainObject(value)) {
30
- reading.values[form.text] = value;
31
- }
32
- }
33
- if (Array.isArray(node) || plainObject(node) || !reading.references.has(exact))
34
- return;
35
- const found = compared(reading, exact, node);
36
- if (typeof found !== 'string')
37
- return;
38
- const field = forms
39
- .map((form) => form.text)
40
- .reduce((left, right) => (right.length < left.length ? right : left));
41
- const known = reading.targets.get(`${field}\u0000${found}`);
42
- const kept = known ?? { field, target: found, forms: new Set() };
43
- for (const form of forms)
44
- kept.forms.add(form.text);
45
- reading.targets.set(`${field}\u0000${found}`, kept);
19
+ export function folderOf(path) {
20
+ return path.slice(0, Math.max(path.lastIndexOf('/'), 0));
46
21
  }
47
- function walk(reading, node, forms, exact) {
48
- record(reading, node, forms, exact);
49
- if (Array.isArray(node)) {
50
- node.forEach((item, index) => walk(reading, item, forms.flatMap((form) => [
51
- ...(form.pending
52
- ? []
53
- : [{ text: `${form.text}/${index}`, through: form.through, pending: false }]),
54
- { text: form.text, through: true, pending: true },
55
- ]), `${exact}/${index}`));
56
- return;
57
- }
58
- if (!plainObject(node))
59
- return;
60
- for (const [key, value] of Object.entries(node)) {
61
- const segment = escapePointer(key);
62
- walk(reading, value, forms.flatMap((form) => form.pending && ARRAY_INDEX.test(key)
63
- ? []
64
- : [{ text: `${form.text}/${segment}`, through: form.through, pending: false }]), `${exact}/${segment}`);
65
- }
22
+ function byKey(_key, value) {
23
+ if (typeof value !== 'object' || value === null || Array.isArray(value))
24
+ return value;
25
+ return Object.fromEntries(Object.entries(value).sort(([one], [other]) => byCodePoint(one, other)));
66
26
  }
67
- function directoriesOf(path) {
68
- const parts = path.split('/').slice(0, -1);
69
- return ['', ...parts.map((_, index) => parts.slice(0, index + 1).join('/'))];
27
+ function fieldsText(fields) {
28
+ return JSON.stringify(fields, byKey);
70
29
  }
71
- export function markdownPath(path) {
72
- return path.endsWith('.md');
30
+ export function writtenFacts(path, content, composition) {
31
+ const model = governing(composition, path);
32
+ const facts = documentFacts(path, parse(content, path), {
33
+ types: model.status === 'unavailable' ? {} : model.types,
34
+ });
35
+ return facts === null
36
+ ? null
37
+ : { ...facts, fields: JSON.parse(fieldsText(facts.fields)) };
73
38
  }
74
- export function rowsOf(room, path, document, composition, change, binary) {
75
- const key = documentKey(room, path);
76
- const body = keyOf('b', room, path);
77
- if (document === null || !markdownPath(path)) {
78
- return [
79
- {
80
- key,
81
- kind: 'document',
82
- room,
83
- path,
84
- type: null,
85
- fields: {},
86
- values: {},
87
- reached: {},
88
- directories: directoriesOf(path),
89
- body,
90
- change,
91
- binary,
92
- },
93
- ];
94
- }
95
- const type = document.type ?? 'any';
96
- const definition = definitionOf(governing(composition, path), document.type);
97
- const reading = {
98
- path,
99
- references: new Set(definition === undefined ? [] : references(document, definition).map((one) => one.pointer)),
100
- values: {},
101
- reached: {},
102
- targets: new Map(),
39
+ export function described(path, content, facts) {
40
+ const folder = folderOf(path);
41
+ const unread = { type: null, fields: null, links: null, folder };
42
+ if (content === null)
43
+ return { ...unread, declared: null, queried: true };
44
+ if (facts === null)
45
+ return { ...unread, declared: null, queried: !markdownPath(path) };
46
+ const links = JSON.stringify(facts.links);
47
+ if (!markdownPath(path))
48
+ return { ...unread, declared: facts.type, queried: true, links };
49
+ return {
50
+ type: facts.type,
51
+ declared: facts.type,
52
+ queried: true,
53
+ folder,
54
+ fields: fieldsText(facts.fields),
55
+ links,
103
56
  };
104
- for (const [name, value] of Object.entries(document.fields)) {
105
- const segment = escapePointer(name);
106
- walk(reading, value, [{ text: `/${segment}`, through: false, pending: false }], `/${segment}`);
107
- }
108
- const { values, reached } = reading;
109
- return [
110
- {
111
- key,
112
- kind: 'document',
113
- room,
114
- path,
115
- type,
116
- fields: document.fields,
117
- values,
118
- reached,
119
- directories: directoriesOf(path),
120
- body,
121
- change,
122
- binary,
123
- },
124
- {
125
- key: body,
126
- kind: 'body',
127
- room,
128
- path,
129
- preamble: document.preamble,
130
- sections: document.sections,
131
- markdown: document.content,
132
- },
133
- ...[...reading.targets.values()].map(({ field, target: found, forms }) => ({
134
- key: keyOf('r', room, path, field, found),
135
- kind: 'reference',
136
- room,
137
- source: key,
138
- target: documentKey(room, found),
139
- field,
140
- forms: [...forms].sort(),
141
- path,
142
- type,
143
- })),
144
- ];
57
+ }
58
+ export function heldOf(path, content, facts) {
59
+ if (content === null || facts === null)
60
+ return { type: null, fields: null, links: [] };
61
+ return markdownPath(path)
62
+ ? { type: facts.type, fields: facts.fields, links: facts.links }
63
+ : { type: null, fields: null, links: facts.links };
64
+ }
65
+ export function derived(path, held, composition) {
66
+ const stored = held.links.map((target) => ({
67
+ kind: 'link',
68
+ keys: '',
69
+ places: '',
70
+ target,
71
+ field: '',
72
+ }));
73
+ if (held.type === null || held.fields === null)
74
+ return { values: [], links: stored };
75
+ const definition = definitionOf(governing(composition, path), held.type);
76
+ const { values, links: fields } = indexed(path, held.fields, definition);
77
+ return { values, links: [...fields, ...stored] };
145
78
  }
@@ -0,0 +1,43 @@
1
+ import type { Authorization, DiscoveredRoom, PathRule, ScopedRefusal, TypedPath } from './adapter.js';
2
+ import type { ChangeSet } from './change-set.js';
3
+ import type { ChangeBatch } from './change.js';
4
+ import type { RuntimeShell } from './durability.js';
5
+ import type { LiveConversations } from './conversation-live.js';
6
+ import type { FiguresRead } from './figures.js';
7
+ import type { Withheld } from './install.js';
8
+ import type { LiveQueries } from './live.js';
9
+ import type { Log } from './log.js';
10
+ import type { ModelState } from './model.js';
11
+ import type { ReadAnswers } from './reads.js';
12
+ import type { Recovery } from './recovery.js';
13
+ import type { ReplicaRecord } from './replica.js';
14
+ import type { RuntimeSocket, RoomDeclaration } from './socket.js';
15
+ import type { CycleProgress } from './status.js';
16
+ import type { Settling } from './saves.js';
17
+ import type { HeldCover, RuntimeStore, Store, Work } from './store.js';
18
+ import type { schemaTypes } from './attached-model.js';
19
+ export type Runtime = {
20
+ readonly store: Store;
21
+ readonly socket: RuntimeSocket;
22
+ readonly journal: Log;
23
+ readonly recovery: Recovery;
24
+ readonly shell: RuntimeShell;
25
+ readonly localSaves: boolean;
26
+ readonly roomTypes: Parameters<typeof schemaTypes>[1];
27
+ readonly builtIn: ModelState;
28
+ readonly typedPaths: readonly TypedPath[];
29
+ readonly pathRule: PathRule;
30
+ readonly usableWhenHeld: readonly string[];
31
+ readonly build: string;
32
+ readonly conversations: LiveConversations;
33
+ readonly liveQueries: LiveQueries<HeldCover>;
34
+ readonly figures: FiguresRead;
35
+ readonly lastAnswers: ReadAnswers;
36
+ settle(local: RuntimeStore, locator: string, work: Work, record: ReplicaRecord, queue: readonly ChangeBatch[], settling?: Settling): Promise<ChangeSet>;
37
+ scoped(result: ScopedRefusal, room: RoomDeclaration, local: RuntimeStore): Promise<void>;
38
+ submitLater(locator: string): void;
39
+ unpair(local: RuntimeStore): Promise<void>;
40
+ advanced(room: DiscoveredRoom, local: RuntimeStore, authorized: Authorization): Promise<Withheld | null>;
41
+ withhold(withheld: Withheld, room: DiscoveredRoom, local: RuntimeStore, progress: CycleProgress): Promise<void>;
42
+ };
43
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EACd,QAAQ,EACR,aAAa,EACb,SAAS,EACV,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,aAAa,EAAE,MAA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IAAI,EAAE,IAAI,EACV,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE,SAAS,WAAW,EAAE,EAC7B,QAAQ,CAAC,EAAE,QAAQ,GAClB,OAAO,CAAC,SAAS,CAAC,CAAC;IACtB,MAAM,CAAC,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACzF,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,MAAM,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,QAAQ,CACN,IAAI,EAAE,cAAc,EACpB,KAAK,EAAE,YAAY,EACnB,UAAU,EAAE,aAAa,GACxB,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;IAC5B,QAAQ,CACN,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,cAAc,EACpB,KAAK,EAAE,YAAY,EACnB,QAAQ,EAAE,aAAa,GACtB,OAAO,CAAC,IAAI,CAAC,CAAC;CAClB,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
package/dist/save.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import type { ProviderLimit } from './adapter.js';
1
+ import { type Validation } from '@agentshouse/mdmodel';
2
+ import type { OperationScopes, PathRule, ProviderLimit } from './adapter.js';
2
3
  import { type Change, type ChangeBatch, type Precondition, type WrittenBy } from './change.js';
3
4
  import { type Composition } from './collection.js';
4
5
  import { type Layer } from './overlay.js';
@@ -18,22 +19,33 @@ export type SaveInput = {
18
19
  baseRoomVersion: string;
19
20
  operations: import('./adapter.js').OperationScopes;
20
21
  providerOwnedPaths: readonly string[];
22
+ authoredPaths?: readonly string[];
21
23
  providerLimits: readonly ProviderLimit[];
24
+ pathRule: PathRule;
22
25
  visible: VisibleLayer;
26
+ folders: ReadonlySet<string>;
23
27
  handle: string;
24
28
  changes: readonly Change[];
25
29
  bases: readonly Precondition[];
26
30
  queued?: ReadonlySet<string>;
27
31
  writtenBy?: WrittenBy;
32
+ unmodeled: boolean;
33
+ validate: Validator;
28
34
  };
29
- export type BatchResult = {
30
- kind: 'batch';
31
- batch: ChangeBatch;
32
- } | {
35
+ export type Validator = (resulting: Layer, touched: readonly string[]) => Promise<Validation>;
36
+ type Refusing = {
33
37
  kind: 'refused';
34
38
  refusal: SaveRefusal;
35
39
  };
36
- export declare function providerRewritten(batch: ChangeBatch, visible: VisibleLayer): ChangeBatch;
40
+ export type BatchResult = {
41
+ kind: 'batch';
42
+ batch: ChangeBatch;
43
+ } | Refusing;
44
+ export declare function providerRewritten(batch: ChangeBatch, visible: VisibleLayer): Generator<number, ChangeBatch, void>;
45
+ export declare function leavingRewritten(batch: ChangeBatch, visible: VisibleLayer): Generator<number, ChangeBatch, void>;
46
+ export declare function rewriting(batch: ChangeBatch, locator: string): boolean;
47
+ export declare function effectiveIn(batch: ChangeBatch, locator: string, visible: VisibleLayer): Generator<number, ChangeBatch, void>;
48
+ export declare function queuedDocuments(queue: readonly ChangeBatch[]): ReadonlySet<string>;
37
49
  export type Requeued = {
38
50
  kind: 'requeued';
39
51
  queue: readonly ChangeBatch[];
@@ -53,8 +65,43 @@ export type Joining = {
53
65
  kind: 'refused';
54
66
  refusal: SaveRefusal;
55
67
  };
56
- export declare function requeued(queue: readonly ChangeBatch[], changes: readonly Change[], visible: VisibleLayer, changeable: (batch: ChangeBatch) => boolean, state: (queue: readonly ChangeBatch[]) => VisibleLayer): Requeued;
68
+ type VisibleOver = (queue: readonly ChangeBatch[]) => Generator<number, VisibleLayer, void>;
69
+ export declare function requeuing(queue: readonly ChangeBatch[], changes: readonly Change[], visible: VisibleLayer, changeable: (batch: ChangeBatch) => boolean, state: VisibleOver): Generator<number, Requeued, void>;
57
70
  export declare function joined(queue: readonly ChangeBatch[], owner: ChangeBatch, extra: ChangeBatch): Joining;
58
- export declare function limitedIn(queue: readonly ChangeBatch[], batch: ChangeBatch, limits: readonly ProviderLimit[], state: (queue: readonly ChangeBatch[]) => Layer): SaveRefusal | null;
59
- export declare function buildBatch(input: SaveInput): BatchResult;
71
+ export declare function limiting(queue: readonly ChangeBatch[], batch: ChangeBatch, limits: readonly ProviderLimit[], state: VisibleOver): Generator<number, SaveRefusal | null, void>;
72
+ export declare const MOVE_DOCUMENTS = "move-documents";
73
+ export type MoveSide = {
74
+ room: string;
75
+ handle: string;
76
+ baseRoomVersion: string;
77
+ composition: Composition;
78
+ operations: OperationScopes;
79
+ providerOwnedPaths: readonly string[];
80
+ authoredPaths?: readonly string[];
81
+ visible: VisibleLayer;
82
+ folders: ReadonlySet<string>;
83
+ queued: ReadonlySet<string>;
84
+ unmodeled: boolean;
85
+ validate: Validator;
86
+ };
87
+ export type MoveInput = {
88
+ source: MoveSide;
89
+ destination: MoveSide;
90
+ moves: readonly {
91
+ readonly path: string;
92
+ readonly to: string;
93
+ }[];
94
+ providerLimits: readonly ProviderLimit[];
95
+ pathRule: PathRule;
96
+ local: boolean;
97
+ writtenBy?: WrittenBy;
98
+ };
99
+ export type MoveResult = {
100
+ kind: 'moved';
101
+ leaving: ChangeBatch;
102
+ arriving: ChangeBatch;
103
+ } | Refusing;
104
+ export declare function buildMove(input: MoveInput): Promise<MoveResult>;
105
+ export declare function buildBatch(input: SaveInput): Promise<BatchResult>;
106
+ export {};
60
107
  //# sourceMappingURL=save.d.ts.map