@agentshouse/mdruntime 0.1.0-c2c52158b7381 → 0.1.0-c2d73b235d7d7

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 (442) hide show
  1. package/README.md +24 -20
  2. package/dist/acceptance.d.ts +3 -0
  3. package/dist/acceptance.d.ts.map +1 -0
  4. package/dist/acceptance.js +328 -0
  5. package/dist/act-lanes.d.ts +30 -0
  6. package/dist/act-lanes.d.ts.map +1 -0
  7. package/dist/act-lanes.js +225 -0
  8. package/dist/actions.d.ts +26 -0
  9. package/dist/actions.d.ts.map +1 -0
  10. package/dist/actions.js +345 -0
  11. package/dist/adapter.d.ts +315 -122
  12. package/dist/adapter.d.ts.map +1 -1
  13. package/dist/attached-model.d.ts +4 -11
  14. package/dist/attached-model.d.ts.map +1 -1
  15. package/dist/attached-model.js +33 -49
  16. package/dist/{binary.d.ts → attachment.d.ts} +8 -9
  17. package/dist/attachment.d.ts.map +1 -0
  18. package/dist/attachment.js +15 -0
  19. package/dist/authored.d.ts +88 -0
  20. package/dist/authored.d.ts.map +1 -0
  21. package/dist/authored.js +345 -0
  22. package/dist/bootstrap.d.ts +30 -11
  23. package/dist/bootstrap.d.ts.map +1 -1
  24. package/dist/bootstrap.js +305 -140
  25. package/dist/cell.d.ts +6 -0
  26. package/dist/cell.d.ts.map +1 -0
  27. package/dist/cell.js +9 -0
  28. package/dist/chain.d.ts +12 -0
  29. package/dist/chain.d.ts.map +1 -0
  30. package/dist/chain.js +67 -0
  31. package/dist/change-set.d.ts +10 -16
  32. package/dist/change-set.d.ts.map +1 -1
  33. package/dist/change-set.js +17 -90
  34. package/dist/change.d.ts +7 -2
  35. package/dist/change.d.ts.map +1 -1
  36. package/dist/change.js +7 -2
  37. package/dist/chat-types.d.ts +3 -0
  38. package/dist/chat-types.d.ts.map +1 -0
  39. package/dist/chat-types.js +11 -0
  40. package/dist/client.d.ts +53 -31
  41. package/dist/client.d.ts.map +1 -1
  42. package/dist/client.js +66 -29
  43. package/dist/collection.d.ts +33 -21
  44. package/dist/collection.d.ts.map +1 -1
  45. package/dist/collection.js +57 -366
  46. package/dist/column.d.ts +5 -0
  47. package/dist/column.d.ts.map +1 -0
  48. package/dist/column.js +9 -0
  49. package/dist/compile.d.ts +19 -0
  50. package/dist/compile.d.ts.map +1 -0
  51. package/dist/compile.js +755 -0
  52. package/dist/connection.d.ts +6 -142
  53. package/dist/connection.d.ts.map +1 -1
  54. package/dist/connection.js +117 -4210
  55. package/dist/context.d.ts +2 -0
  56. package/dist/context.d.ts.map +1 -0
  57. package/dist/{chat/context.js → context.js} +2 -5
  58. package/dist/conversation-live.d.ts +150 -0
  59. package/dist/conversation-live.d.ts.map +1 -0
  60. package/dist/conversation-live.js +260 -0
  61. package/dist/conversation-row.d.ts +55 -0
  62. package/dist/conversation-row.d.ts.map +1 -0
  63. package/dist/conversation-row.js +82 -0
  64. package/dist/conversation.d.ts +84 -54
  65. package/dist/conversation.d.ts.map +1 -1
  66. package/dist/conversation.js +1043 -823
  67. package/dist/declaration.d.ts +10 -0
  68. package/dist/declaration.d.ts.map +1 -0
  69. package/dist/declaration.js +24 -0
  70. package/dist/discovery.d.ts +12 -0
  71. package/dist/discovery.d.ts.map +1 -0
  72. package/dist/discovery.js +175 -0
  73. package/dist/download.d.ts +6 -0
  74. package/dist/download.d.ts.map +1 -0
  75. package/dist/download.js +42 -0
  76. package/dist/durability.d.ts +20 -4
  77. package/dist/durability.d.ts.map +1 -1
  78. package/dist/durability.js +12 -0
  79. package/dist/entry.d.ts +30 -3
  80. package/dist/entry.d.ts.map +1 -1
  81. package/dist/entry.js +135 -41
  82. package/dist/expectation.d.ts +26 -13
  83. package/dist/expectation.d.ts.map +1 -1
  84. package/dist/expectation.js +72 -19
  85. package/dist/failure.d.ts +3 -0
  86. package/dist/failure.d.ts.map +1 -1
  87. package/dist/failure.js +8 -0
  88. package/dist/figures.d.ts +49 -0
  89. package/dist/figures.d.ts.map +1 -0
  90. package/dist/figures.js +199 -0
  91. package/dist/file.d.ts +2 -11
  92. package/dist/file.d.ts.map +1 -1
  93. package/dist/file.js +7 -4
  94. package/dist/holdings.d.ts +29 -0
  95. package/dist/holdings.d.ts.map +1 -0
  96. package/dist/holdings.js +95 -0
  97. package/dist/host.d.ts +25 -8
  98. package/dist/host.d.ts.map +1 -1
  99. package/dist/host.js +157 -61
  100. package/dist/house-query.d.ts +24 -0
  101. package/dist/house-query.d.ts.map +1 -0
  102. package/dist/house-query.js +102 -0
  103. package/dist/identity.d.ts +1 -3
  104. package/dist/identity.d.ts.map +1 -1
  105. package/dist/identity.js +1 -7
  106. package/dist/index.d.ts +49 -19
  107. package/dist/index.d.ts.map +1 -1
  108. package/dist/index.js +25 -8
  109. package/dist/install.d.ts +60 -0
  110. package/dist/install.d.ts.map +1 -0
  111. package/dist/install.js +537 -0
  112. package/dist/lifecycle.d.ts +7 -0
  113. package/dist/lifecycle.d.ts.map +1 -0
  114. package/dist/lifecycle.js +292 -0
  115. package/dist/linked-file.d.ts +7 -0
  116. package/dist/linked-file.d.ts.map +1 -0
  117. package/dist/linked-file.js +16 -0
  118. package/dist/listing.d.ts +60 -0
  119. package/dist/listing.d.ts.map +1 -0
  120. package/dist/listing.js +168 -0
  121. package/dist/live.d.ts +39 -0
  122. package/dist/live.d.ts.map +1 -0
  123. package/dist/live.js +223 -0
  124. package/dist/loaded.d.ts +7 -0
  125. package/dist/loaded.d.ts.map +1 -0
  126. package/dist/loaded.js +46 -0
  127. package/dist/locks.d.ts +7 -0
  128. package/dist/locks.d.ts.map +1 -0
  129. package/dist/locks.js +34 -0
  130. package/dist/lost.d.ts +5 -0
  131. package/dist/lost.d.ts.map +1 -0
  132. package/dist/lost.js +49 -0
  133. package/dist/media.d.ts +24 -0
  134. package/dist/media.d.ts.map +1 -0
  135. package/dist/media.js +365 -0
  136. package/dist/memory.d.ts +22 -8
  137. package/dist/memory.d.ts.map +1 -1
  138. package/dist/memory.js +311 -120
  139. package/dist/messages.d.ts +67 -0
  140. package/dist/messages.d.ts.map +1 -0
  141. package/dist/messages.js +180 -0
  142. package/dist/modal.d.ts +2 -0
  143. package/dist/modal.d.ts.map +1 -0
  144. package/dist/modal.js +11 -0
  145. package/dist/model.d.ts +15 -15
  146. package/dist/model.d.ts.map +1 -1
  147. package/dist/model.js +11 -22
  148. package/dist/models.d.ts +10 -0
  149. package/dist/models.d.ts.map +1 -0
  150. package/dist/models.js +153 -0
  151. package/dist/name.d.ts +0 -1
  152. package/dist/name.d.ts.map +1 -1
  153. package/dist/name.js +3 -7
  154. package/dist/observation.d.ts +40 -10
  155. package/dist/observation.d.ts.map +1 -1
  156. package/dist/observation.js +265 -44
  157. package/dist/online.d.ts +7 -0
  158. package/dist/online.d.ts.map +1 -0
  159. package/dist/online.js +29 -0
  160. package/dist/opened.d.ts +6 -6
  161. package/dist/opened.d.ts.map +1 -1
  162. package/dist/opened.js +7 -7
  163. package/dist/opening.d.ts +4 -0
  164. package/dist/opening.d.ts.map +1 -0
  165. package/dist/opening.js +71 -0
  166. package/dist/outcome.d.ts +46 -16
  167. package/dist/outcome.d.ts.map +1 -1
  168. package/dist/outcome.js +51 -7
  169. package/dist/overlay.d.ts +24 -11
  170. package/dist/overlay.d.ts.map +1 -1
  171. package/dist/overlay.js +138 -193
  172. package/dist/page-metadata.d.ts +8 -0
  173. package/dist/page-metadata.d.ts.map +1 -0
  174. package/dist/page-metadata.js +19 -0
  175. package/dist/parts.d.ts +7 -0
  176. package/dist/parts.d.ts.map +1 -0
  177. package/dist/parts.js +36 -0
  178. package/dist/paths.d.ts +2 -0
  179. package/dist/paths.d.ts.map +1 -1
  180. package/dist/paths.js +26 -0
  181. package/dist/preparation.d.ts +46 -0
  182. package/dist/preparation.d.ts.map +1 -0
  183. package/dist/preparation.js +344 -0
  184. package/dist/presence.d.ts +58 -0
  185. package/dist/presence.d.ts.map +1 -0
  186. package/dist/presence.js +231 -0
  187. package/dist/queries.d.ts +16 -0
  188. package/dist/queries.d.ts.map +1 -0
  189. package/dist/queries.js +330 -0
  190. package/dist/query.d.ts +22 -209
  191. package/dist/query.d.ts.map +1 -1
  192. package/dist/query.js +3 -494
  193. package/dist/{chat/questions.d.ts → questions.d.ts} +6 -7
  194. package/dist/questions.d.ts.map +1 -0
  195. package/dist/{chat/questions.js → questions.js} +14 -8
  196. package/dist/queue.d.ts +40 -0
  197. package/dist/queue.d.ts.map +1 -0
  198. package/dist/queue.js +482 -0
  199. package/dist/reach.d.ts +31 -15
  200. package/dist/reach.d.ts.map +1 -1
  201. package/dist/reach.js +385 -176
  202. package/dist/react.d.ts +27 -3
  203. package/dist/react.d.ts.map +1 -1
  204. package/dist/react.js +33 -1
  205. package/dist/{chat/read.d.ts → read.d.ts} +2 -0
  206. package/dist/read.d.ts.map +1 -0
  207. package/dist/{chat/read.js → read.js} +4 -0
  208. package/dist/readiness.d.ts +36 -21
  209. package/dist/readiness.d.ts.map +1 -1
  210. package/dist/readiness.js +20 -18
  211. package/dist/reads.d.ts +38 -10
  212. package/dist/reads.d.ts.map +1 -1
  213. package/dist/reads.js +174 -83
  214. package/dist/recovery.d.ts +4 -0
  215. package/dist/recovery.d.ts.map +1 -1
  216. package/dist/recovery.js +59 -2
  217. package/dist/refresh.d.ts +18 -15
  218. package/dist/refresh.d.ts.map +1 -1
  219. package/dist/refresh.js +145 -79
  220. package/dist/refusal.d.ts +5 -0
  221. package/dist/refusal.d.ts.map +1 -0
  222. package/dist/refusal.js +55 -0
  223. package/dist/replica.d.ts +45 -38
  224. package/dist/replica.d.ts.map +1 -1
  225. package/dist/replica.js +319 -229
  226. package/dist/retried.d.ts +30 -0
  227. package/dist/retried.d.ts.map +1 -0
  228. package/dist/retried.js +72 -0
  229. package/dist/room-draft.d.ts +53 -13
  230. package/dist/room-draft.d.ts.map +1 -1
  231. package/dist/room-draft.js +405 -115
  232. package/dist/room-drafts.d.ts +24 -0
  233. package/dist/room-drafts.d.ts.map +1 -0
  234. package/dist/room-drafts.js +222 -0
  235. package/dist/room-list.d.ts +10 -0
  236. package/dist/room-list.d.ts.map +1 -0
  237. package/dist/room-list.js +47 -0
  238. package/dist/rows.d.ts +40 -32
  239. package/dist/rows.d.ts.map +1 -1
  240. package/dist/rows.js +72 -123
  241. package/dist/run-tables.d.ts +25 -0
  242. package/dist/run-tables.d.ts.map +1 -0
  243. package/dist/run-tables.js +98 -0
  244. package/dist/running.d.ts +5 -0
  245. package/dist/running.d.ts.map +1 -0
  246. package/dist/running.js +10 -0
  247. package/dist/runs.d.ts +27 -0
  248. package/dist/runs.d.ts.map +1 -0
  249. package/dist/runs.js +92 -0
  250. package/dist/runtime.d.ts +38 -0
  251. package/dist/runtime.d.ts.map +1 -0
  252. package/dist/runtime.js +1 -0
  253. package/dist/save.d.ts +45 -87
  254. package/dist/save.d.ts.map +1 -1
  255. package/dist/save.js +402 -286
  256. package/dist/saves.d.ts +34 -0
  257. package/dist/saves.d.ts.map +1 -0
  258. package/dist/saves.js +464 -0
  259. package/dist/search.d.ts +12 -95
  260. package/dist/search.d.ts.map +1 -1
  261. package/dist/search.js +10 -317
  262. package/dist/seed.d.ts +11 -2
  263. package/dist/seed.d.ts.map +1 -1
  264. package/dist/seed.js +71 -1
  265. package/dist/selector.d.ts +3 -0
  266. package/dist/selector.d.ts.map +1 -0
  267. package/dist/selector.js +22 -0
  268. package/dist/shared.d.ts +1 -10
  269. package/dist/shared.d.ts.map +1 -1
  270. package/dist/shared.js +13 -135
  271. package/dist/shown.d.ts +35 -0
  272. package/dist/shown.d.ts.map +1 -0
  273. package/dist/shown.js +327 -0
  274. package/dist/socket/admission.d.ts +7 -0
  275. package/dist/socket/admission.d.ts.map +1 -0
  276. package/dist/socket/admission.js +39 -0
  277. package/dist/socket/answers.d.ts +6 -0
  278. package/dist/socket/answers.d.ts.map +1 -0
  279. package/dist/socket/answers.js +20 -0
  280. package/dist/socket/lanes.d.ts +28 -0
  281. package/dist/socket/lanes.d.ts.map +1 -0
  282. package/dist/socket/lanes.js +103 -0
  283. package/dist/socket/reads.d.ts +10 -0
  284. package/dist/socket/reads.d.ts.map +1 -0
  285. package/dist/socket/reads.js +31 -0
  286. package/dist/socket/session.d.ts +41 -0
  287. package/dist/socket/session.d.ts.map +1 -0
  288. package/dist/socket/session.js +26 -0
  289. package/dist/socket.d.ts +70 -0
  290. package/dist/socket.d.ts.map +1 -0
  291. package/dist/socket.js +172 -0
  292. package/dist/source.d.ts +96 -0
  293. package/dist/source.d.ts.map +1 -0
  294. package/dist/source.js +149 -0
  295. package/dist/status.d.ts +4 -5
  296. package/dist/status.d.ts.map +1 -1
  297. package/dist/status.js +3 -7
  298. package/dist/store/installs.d.ts +30 -0
  299. package/dist/store/installs.d.ts.map +1 -0
  300. package/dist/store/installs.js +40 -0
  301. package/dist/store/readiness.d.ts +11 -0
  302. package/dist/store/readiness.d.ts.map +1 -0
  303. package/dist/store/readiness.js +68 -0
  304. package/dist/store/records.d.ts +234 -0
  305. package/dist/store/records.d.ts.map +1 -0
  306. package/dist/store/records.js +474 -0
  307. package/dist/store/room-held.d.ts +8 -0
  308. package/dist/store/room-held.d.ts.map +1 -0
  309. package/dist/store/room-held.js +17 -0
  310. package/dist/store/rooms-shown.d.ts +8 -0
  311. package/dist/store/rooms-shown.d.ts.map +1 -0
  312. package/dist/store/rooms-shown.js +13 -0
  313. package/dist/store/space.d.ts +11 -0
  314. package/dist/store/space.d.ts.map +1 -0
  315. package/dist/store/space.js +41 -0
  316. package/dist/store/watchers.d.ts +17 -0
  317. package/dist/store/watchers.d.ts.map +1 -0
  318. package/dist/store/watchers.js +56 -0
  319. package/dist/store/writes.d.ts +24 -0
  320. package/dist/store/writes.d.ts.map +1 -0
  321. package/dist/store/writes.js +125 -0
  322. package/dist/store.d.ts +115 -160
  323. package/dist/store.d.ts.map +1 -1
  324. package/dist/store.js +171 -762
  325. package/dist/stored.d.ts +181 -0
  326. package/dist/stored.d.ts.map +1 -0
  327. package/dist/stored.js +807 -0
  328. package/dist/surface.d.ts +100 -0
  329. package/dist/surface.d.ts.map +1 -0
  330. package/dist/surface.js +258 -0
  331. package/dist/sync.d.ts +21 -0
  332. package/dist/sync.d.ts.map +1 -0
  333. package/dist/sync.js +557 -0
  334. package/dist/tables.d.ts +362 -204
  335. package/dist/tables.d.ts.map +1 -1
  336. package/dist/tables.js +378 -264
  337. package/dist/tallies.d.ts +18 -0
  338. package/dist/tallies.d.ts.map +1 -0
  339. package/dist/tallies.js +128 -0
  340. package/dist/transfer.d.ts +0 -5
  341. package/dist/transfer.d.ts.map +1 -1
  342. package/dist/turn.d.ts +1 -1
  343. package/dist/turn.d.ts.map +1 -1
  344. package/dist/turn.js +28 -20
  345. package/dist/validation.d.ts +31 -0
  346. package/dist/validation.d.ts.map +1 -0
  347. package/dist/validation.js +144 -0
  348. package/dist/windows.d.ts +1 -11
  349. package/dist/windows.d.ts.map +1 -1
  350. package/dist/windows.js +2 -70
  351. package/dist/wire.d.ts +89 -17
  352. package/dist/wire.d.ts.map +1 -1
  353. package/dist/wire.js +38 -15
  354. package/package.json +16 -20
  355. package/AGENTS.md +0 -308
  356. package/dist/attempt.d.ts +0 -16
  357. package/dist/attempt.d.ts.map +0 -1
  358. package/dist/attempt.js +0 -70
  359. package/dist/binary.d.ts.map +0 -1
  360. package/dist/binary.js +0 -8
  361. package/dist/chat/acts.d.ts +0 -33
  362. package/dist/chat/acts.d.ts.map +0 -1
  363. package/dist/chat/acts.js +0 -36
  364. package/dist/chat/context.d.ts +0 -3
  365. package/dist/chat/context.d.ts.map +0 -1
  366. package/dist/chat/earlier.d.ts +0 -10
  367. package/dist/chat/earlier.d.ts.map +0 -1
  368. package/dist/chat/earlier.js +0 -54
  369. package/dist/chat/house.d.ts +0 -25
  370. package/dist/chat/house.d.ts.map +0 -1
  371. package/dist/chat/house.js +0 -38
  372. package/dist/chat/input.d.ts +0 -11
  373. package/dist/chat/input.d.ts.map +0 -1
  374. package/dist/chat/input.js +0 -92
  375. package/dist/chat/kit.d.ts +0 -61
  376. package/dist/chat/kit.d.ts.map +0 -1
  377. package/dist/chat/kit.js +0 -123
  378. package/dist/chat/lasting.d.ts +0 -6
  379. package/dist/chat/lasting.d.ts.map +0 -1
  380. package/dist/chat/lasting.js +0 -19
  381. package/dist/chat/list.d.ts +0 -28
  382. package/dist/chat/list.d.ts.map +0 -1
  383. package/dist/chat/list.js +0 -103
  384. package/dist/chat/markdown.d.ts +0 -21
  385. package/dist/chat/markdown.d.ts.map +0 -1
  386. package/dist/chat/markdown.js +0 -246
  387. package/dist/chat/message.d.ts +0 -7
  388. package/dist/chat/message.d.ts.map +0 -1
  389. package/dist/chat/message.js +0 -237
  390. package/dist/chat/messages.d.ts +0 -29
  391. package/dist/chat/messages.d.ts.map +0 -1
  392. package/dist/chat/messages.js +0 -190
  393. package/dist/chat/name.d.ts +0 -7
  394. package/dist/chat/name.d.ts.map +0 -1
  395. package/dist/chat/name.js +0 -37
  396. package/dist/chat/opened.d.ts +0 -12
  397. package/dist/chat/opened.d.ts.map +0 -1
  398. package/dist/chat/opened.js +0 -19
  399. package/dist/chat/overlay.d.ts +0 -32
  400. package/dist/chat/overlay.d.ts.map +0 -1
  401. package/dist/chat/overlay.js +0 -103
  402. package/dist/chat/parts.d.ts +0 -58
  403. package/dist/chat/parts.d.ts.map +0 -1
  404. package/dist/chat/parts.js +0 -120
  405. package/dist/chat/pieces.d.ts +0 -62
  406. package/dist/chat/pieces.d.ts.map +0 -1
  407. package/dist/chat/pieces.js +0 -1110
  408. package/dist/chat/process.d.ts +0 -20
  409. package/dist/chat/process.d.ts.map +0 -1
  410. package/dist/chat/process.js +0 -32
  411. package/dist/chat/provider.d.ts +0 -68
  412. package/dist/chat/provider.d.ts.map +0 -1
  413. package/dist/chat/provider.js +0 -619
  414. package/dist/chat/question.d.ts +0 -9
  415. package/dist/chat/question.d.ts.map +0 -1
  416. package/dist/chat/question.js +0 -69
  417. package/dist/chat/questions.d.ts.map +0 -1
  418. package/dist/chat/read.d.ts.map +0 -1
  419. package/dist/chat/ready.d.ts +0 -37
  420. package/dist/chat/ready.d.ts.map +0 -1
  421. package/dist/chat/ready.js +0 -93
  422. package/dist/chat/room-file.d.ts +0 -8
  423. package/dist/chat/room-file.d.ts.map +0 -1
  424. package/dist/chat/room-file.js +0 -72
  425. package/dist/chat/steady.d.ts +0 -3
  426. package/dist/chat/steady.d.ts.map +0 -1
  427. package/dist/chat/steady.js +0 -26
  428. package/dist/chat/style.d.ts +0 -4
  429. package/dist/chat/style.d.ts.map +0 -1
  430. package/dist/chat/style.js +0 -306
  431. package/dist/chat.d.ts +0 -15
  432. package/dist/chat.d.ts.map +0 -1
  433. package/dist/chat.js +0 -8
  434. package/dist/fence.d.ts +0 -6
  435. package/dist/fence.d.ts.map +0 -1
  436. package/dist/fence.js +0 -10
  437. package/dist/log.d.ts +0 -5
  438. package/dist/log.d.ts.map +0 -1
  439. package/dist/log.js +0 -14
  440. package/dist/read-side.d.ts +0 -27
  441. package/dist/read-side.d.ts.map +0 -1
  442. package/dist/read-side.js +0 -1179
package/dist/save.js CHANGED
@@ -1,13 +1,14 @@
1
- import { definitionOf } from './model.js';
2
- import { apply, ARRAY_INDEX, ATTACHMENT, links, parse, pointerSegments, references, relative, relativize, retarget, roomReferences, serialize, target, } from '@agentshouse/mdmodel';
3
- import { immutable, leaving, queuedFile, departure, } from './change.js';
4
- import { available, changedCleanly, collectionOf, documentsOf, governing, referring, validateCollection, } from './collection.js';
5
- import { changeBatchIdentity } from './identity.js';
6
- import { overlaying } from './overlay.js';
7
- import { covered, normalize } from './paths.js';
8
- import { differences, sorting } from './shared.js';
9
- import { ROW_WEIGHT, stepped } from './turn.js';
10
- function refuse(code, file, location) {
1
+ import { apply, ARRAY_INDEX, ATTACHMENT, create, links, parse, pointerSegments, references, relative, relativePath, relativizable, relativize, retarget, roomReferences, serialize, target, writeRoomPath, } from '@agentshouse/mdmodel';
2
+ import { immutable, isPart, leaving, queuedFile, departure, } from './change.js';
3
+ import { collectionOf, definitionsAt, documentsOf, governing, typeAt, UNTYPED, } from './collection.js';
4
+ import { changeBatchIdentity, roomDraftRevision } from './identity.js';
5
+ import { composed, overlaying } from './overlay.js';
6
+ import { ancestors } from './paths.js';
7
+ import { entriesIn, sorting } from './shared.js';
8
+ import { applyParts, changedParts, changesOf, moveTarget, partsBetween, withdrawnDrafts, } from './room-draft.js';
9
+ import { paced, ROW_WEIGHT, stepped } from './turn.js';
10
+ import { validatedCollection } from './validation.js';
11
+ function refuse(code, file, location, line) {
11
12
  return {
12
13
  kind: 'refused',
13
14
  refusal: {
@@ -15,13 +16,14 @@ function refuse(code, file, location) {
15
16
  retryable: false,
16
17
  ...(file === undefined ? {} : { file }),
17
18
  ...(location === undefined ? {} : { location }),
19
+ ...(line === undefined ? {} : { line }),
18
20
  },
19
21
  };
20
22
  }
23
+ function refusedBy(refusal, file) {
24
+ return refuse(refusal.rule, file, refusal.location, refusal.line);
25
+ }
21
26
  function repointed(document, definition, from, to, moves, settled) {
22
- const parsed = parse(document.content, from);
23
- if (!parsed.ok)
24
- return [];
25
27
  const changes = [];
26
28
  const names = new Set();
27
29
  for (const { pointer, value } of definition === undefined
@@ -44,43 +46,13 @@ function repointed(document, definition, from, to, moves, settled) {
44
46
  }
45
47
  if (changes.length === 0)
46
48
  return [];
47
- const applied = apply(parsed.document, changes);
49
+ const applied = apply(document, changes, definition);
48
50
  if (applied.outcome !== 'applied')
49
51
  return [];
50
52
  const next = applied.document;
51
53
  return [...names].map((name) => ({ kind: 'field', path: from, name, value: next.fields[name] }));
52
54
  }
53
- function edited(document, changes) {
54
- const parts = new Map();
55
- for (const change of changes) {
56
- if (change.kind === 'preamble')
57
- parts.set('preamble', { kind: 'preamble', value: change.value, prior: document.preamble });
58
- if (change.kind === 'section')
59
- parts.set(`section ${change.name}`, {
60
- kind: 'section',
61
- name: change.name,
62
- value: change.value,
63
- prior: document.sections[change.name] ?? '',
64
- });
65
- }
66
- if (parts.size === 0)
67
- return document;
68
- const applied = apply(document, [...parts.values()]);
69
- return applied.outcome === 'applied' ? applied.document : document;
70
- }
71
- function bodies(path, before, after) {
72
- const changes = [];
73
- if (after.preamble !== before.preamble) {
74
- changes.push({ kind: 'preamble', path, value: after.preamble });
75
- }
76
- for (const [name, value] of Object.entries(after.sections)) {
77
- if (before.sections[name] === value)
78
- continue;
79
- changes.push({ kind: 'section', path, name, value });
80
- }
81
- return changes;
82
- }
83
- function relinks(path, moved, before, moves) {
55
+ function relinks(path, moved, before, moves, definition) {
84
56
  const changes = [];
85
57
  for (const link of links(before, path)) {
86
58
  const destination = moves.get(link.target) ?? link.target;
@@ -93,28 +65,30 @@ function relinks(path, moved, before, moves) {
93
65
  }
94
66
  if (changes.length === 0)
95
67
  return { kind: 'changes', changes: [] };
96
- const applied = apply(before, changes);
97
- if (applied.outcome === 'refuse') {
98
- return {
99
- kind: 'refused',
100
- refusal: {
101
- code: applied.refusal.rule,
102
- retryable: false,
103
- file: path,
104
- ...(applied.refusal.location === undefined ? {} : { location: applied.refusal.location }),
105
- },
106
- };
107
- }
68
+ const applied = apply(before, changes, definition);
69
+ if (applied.outcome === 'refuse')
70
+ return refusedBy(applied.refusal, path);
108
71
  const after = applied.document;
109
72
  if (after === before)
110
73
  return { kind: 'changes', changes: [] };
111
74
  if (before.type === undefined) {
112
75
  return { kind: 'changes', changes: [{ kind: 'replace', path, content: serialize(after) }] };
113
76
  }
114
- return { kind: 'changes', changes: bodies(path, before, after) };
77
+ return { kind: 'changes', changes: partsBetween(path, before, after) };
115
78
  }
116
79
  function partKey(change) {
117
- return change.kind === 'section' ? `section ${change.name}` : change.kind;
80
+ return change.kind === 'section' || change.kind === 'field'
81
+ ? `${change.kind} ${change.name}`
82
+ : change.kind;
83
+ }
84
+ const NAMES_A_SKIP_TESTS = 64;
85
+ const ENCODED = /[%&\\]/u;
86
+ function movedNames(moves) {
87
+ const names = new Set([...moves.keys()].map((path) => path.slice(path.lastIndexOf('/') + 1)));
88
+ return names.size > NAMES_A_SKIP_TESTS ? null : [...names];
89
+ }
90
+ function cannotLink(text, names) {
91
+ return names !== null && !ENCODED.test(text) && !names.some((name) => text.includes(name));
118
92
  }
119
93
  function* rewrites(changes, visible) {
120
94
  const moves = new Map();
@@ -141,17 +115,21 @@ function* rewrites(changes, visible) {
141
115
  }
142
116
  if (moves.size === 0)
143
117
  return { kind: 'changes', changes };
118
+ const names = movedNames(moves);
144
119
  const merged = [...changes];
145
120
  const added = [];
146
121
  for (const [path, document] of yield* documentsOf(visible.collection)) {
147
122
  if (settled.has(path))
148
123
  continue;
149
124
  const moved = moves.get(path) ?? path;
150
- const definition = definitionOf(governing(visible.collection.composition, path), document.type);
125
+ const definition = definitionsAt(visible.collection.composition, path)(document.type);
151
126
  const repointing = repointed(document, definition, path, moved, moves, settled);
152
127
  added.push(...repointing);
153
128
  const own = parts.get(path) ?? [];
154
- const relinked = relinks(path, moved, edited(document, own.map((index) => merged[index])), moves);
129
+ const edited = applyParts(document, own.map((index) => merged[index]), definition);
130
+ const relinked = moved === path && own.length === 0 && cannotLink(document.content, names)
131
+ ? { kind: 'changes', changes: [] }
132
+ : relinks(path, moved, edited.outcome === 'applied' ? edited.document : document, moves, definition);
155
133
  if (relinked.kind === 'refused')
156
134
  return relinked;
157
135
  const keyed = new Map();
@@ -164,7 +142,7 @@ function* rewrites(changes, visible) {
164
142
  if (change.kind === 'replace') {
165
143
  for (const index of own) {
166
144
  const kind = merged[index]?.kind;
167
- if (kind === 'section' || kind === 'preamble')
145
+ if (kind === 'field' || kind === 'section' || kind === 'preamble')
168
146
  merged[index] = null;
169
147
  }
170
148
  added.push(change);
@@ -220,35 +198,33 @@ function crossed(document, definition, path, to) {
220
198
  }
221
199
  return changes;
222
200
  }
223
- function rewritten(path, document, changes) {
201
+ function rewritten(path, document, changes, definition) {
224
202
  if (changes.length === 0)
225
203
  return [];
226
- const applied = apply(document, changes);
204
+ const applied = apply(document, changes, definition);
227
205
  if (applied.outcome !== 'applied')
228
206
  return [];
229
207
  const after = applied.document;
230
208
  if (document.type === undefined)
231
209
  return [{ kind: 'replace', path, content: serialize(after) }];
232
- const names = new Set(changes.flatMap((change) => change.kind === 'reference' ? [pointerSegments(change.pointer)[0] ?? ''] : []));
233
- return [
234
- ...[...names].map((name) => ({ kind: 'field', path, name, value: after.fields[name] })),
235
- ...bodies(path, document, after),
236
- ];
210
+ return partsBetween(path, document, after);
237
211
  }
238
- function roomPathOf(handle, path) {
239
- return `/rooms/${handle}/${path}`;
240
- }
241
- export function* leavingRewritten(batch, visible) {
212
+ function* leavingRewritten(batch, visible) {
242
213
  const between = batch.between;
243
214
  if (between === undefined)
244
215
  return batch;
245
- const moved = new Map(between.moves.map(({ path, to }) => [path, roomPathOf(between.destination.handle, to)]));
216
+ const { handle } = between.destination;
217
+ const moved = new Map(between.moves.map(({ path, to }) => [path, to]));
246
218
  const derived = [];
247
219
  for (const [path, document] of yield* documentsOf(visible.collection)) {
248
220
  if (moved.has(path))
249
221
  continue;
250
- const definition = definitionOf(governing(visible.collection.composition, path), document.type);
251
- derived.push(...rewritten(path, document, crossed(document, definition, path, (named) => moved.get(named))));
222
+ const definition = definitionsAt(visible.collection.composition, path)(document.type);
223
+ const into = (named) => {
224
+ const to = moved.get(named);
225
+ return to === undefined ? undefined : relativePath({ path }, { handle, path: to });
226
+ };
227
+ derived.push(...rewritten(path, document, crossed(document, definition, path, into), definition));
252
228
  yield ROW_WEIGHT + visible.collection.text[path].length;
253
229
  }
254
230
  if (derived.length === 0)
@@ -267,10 +243,6 @@ export function* effectiveIn(batch, locator, visible) {
267
243
  ? yield* leavingRewritten(batch, visible)
268
244
  : yield* providerRewritten(batch, visible);
269
245
  }
270
- function* chained(...sets) {
271
- for (const set of sets)
272
- yield* set;
273
- }
274
246
  function* incoming(collection, removed, candidates) {
275
247
  const found = new Map();
276
248
  const note = (target, file) => {
@@ -294,7 +266,7 @@ function* incoming(collection, removed, candidates) {
294
266
  for (const [path, document] of candidates === null
295
267
  ? yield* documentsOf(collection)
296
268
  : read(candidates)) {
297
- const definition = definitionOf(governing(collection.composition, path), document.type);
269
+ const definition = definitionsAt(collection.composition, path)(document.type);
298
270
  for (const { value, to } of definition === undefined ? [] : references(document, definition)) {
299
271
  if (to.includes(ATTACHMENT))
300
272
  continue;
@@ -324,6 +296,8 @@ function* incoming(collection, removed, candidates) {
324
296
  function affected(change) {
325
297
  return change.kind === 'move' ? [change.path, change.to] : [change.path];
326
298
  }
299
+ const WRITE = ['write'];
300
+ const MOVE_OUT = ['write', 'erase'];
327
301
  function guard(changes, input, removing) {
328
302
  const overridden = new Map();
329
303
  const existing = {
@@ -332,21 +306,17 @@ function guard(changes, input, removing) {
332
306
  add: (path) => void overridden.set(path, true),
333
307
  delete: (path) => void overridden.set(path, false),
334
308
  };
309
+ const occupied = (path) => input.folders.has(path) ? path : (ancestors(path).find((one) => existing.has(one)) ?? null);
335
310
  for (const [index, change] of changes.entries()) {
336
311
  for (const path of affected(change)) {
337
- const normalized = normalize(path);
338
- if (normalized === null || normalized === '')
339
- return refuse('room-root', path);
340
- if (covered(input.providerOwnedPaths, normalized)) {
341
- return refuse('provider-owned-path', normalized);
342
- }
343
- const operation = change.kind === 'remove' ? removing : 'write';
344
- if (!input.local && !covered(input.operations[operation], normalized))
345
- return refuse(`${operation}-grant`, normalized);
312
+ const refused = input.rule(path, change.kind === 'remove' ? removing : WRITE);
313
+ if (refused !== null)
314
+ return refuse(refused.code, refused.path);
346
315
  }
347
316
  if (change.kind === 'create' || change.kind === 'arrival') {
348
- if (existing.has(change.path))
349
- return refuse('path-collision', change.path);
317
+ const taken = existing.has(change.path) ? change.path : occupied(change.path);
318
+ if (taken !== null)
319
+ return refuse('path-collision', taken);
350
320
  existing.add(change.path);
351
321
  continue;
352
322
  }
@@ -356,6 +326,9 @@ function guard(changes, input, removing) {
356
326
  input.bases.some((base) => base.kind === 'absent' && base.path === change.path))) {
357
327
  return refuse('path-collision', change.path);
358
328
  }
329
+ const taken = occupied(change.path);
330
+ if (taken !== null)
331
+ return refuse('path-collision', taken);
359
332
  if (!input.local &&
360
333
  existing.has(change.path) &&
361
334
  input.visible.revisions[departure(changes, index)] === undefined) {
@@ -367,8 +340,9 @@ function guard(changes, input, removing) {
367
340
  if (change.kind === 'move') {
368
341
  if (!existing.has(change.path))
369
342
  return refuse('path-absent', change.path);
370
- if (existing.has(change.to))
371
- return refuse('path-collision', change.to);
343
+ const taken = existing.has(change.to) ? change.to : occupied(change.to);
344
+ if (taken !== null)
345
+ return refuse('path-collision', taken);
372
346
  if (unrevised(input, change.path)) {
373
347
  return refuse('unknown-revision', change.path);
374
348
  }
@@ -398,9 +372,9 @@ function guard(changes, input, removing) {
398
372
  return null;
399
373
  }
400
374
  function unrevised(input, path) {
401
- return (!input.local && input.queued?.has(path) !== true && input.visible.revisions[path] === undefined);
375
+ return !input.local && !input.queued.has(path) && input.visible.revisions[path] === undefined;
402
376
  }
403
- export function queuedDocuments(queue) {
377
+ function queuedDocuments(queue) {
404
378
  const paths = new Set();
405
379
  for (const batch of queue) {
406
380
  for (const change of batch.changes) {
@@ -445,7 +419,7 @@ function* preconditionsOf(changes, visible, bases) {
445
419
  };
446
420
  for (const change of changes) {
447
421
  yield ROW_WEIGHT;
448
- if (change.kind === 'field' || change.kind === 'section' || change.kind === 'preamble') {
422
+ if (isPart(change)) {
449
423
  const based = bases.find((base) => sameTarget(base, change));
450
424
  if (based !== undefined) {
451
425
  add(based);
@@ -534,107 +508,103 @@ function* exceeding(limits, changes, effective, resulting) {
534
508
  return null;
535
509
  }
536
510
  function shellRelative(text, path, handle, definition) {
537
- if (!text.includes(`/rooms/${handle}/`))
511
+ if (!relativizable(text, handle))
538
512
  return null;
539
- const parsed = parse(text, path);
513
+ const parsed = parse(text, path, definition);
540
514
  if (!parsed.ok)
541
515
  return null;
542
516
  const result = relativize(parsed.document, path, handle, definition(parsed.document.type));
543
517
  return result.outcome === 'applied' && result.document.content !== text ? result.document : null;
544
518
  }
545
519
  function relativeField(path, name, value, handle, definition) {
546
- const opened = parse('---\n---\n');
547
- if (definition === undefined ||
548
- !opened.ok ||
549
- !JSON.stringify(value ?? null).includes(`/rooms/${handle}/`))
520
+ if (definition === undefined || !relativizable(JSON.stringify(value ?? null), handle))
550
521
  return value;
551
- const held = apply(opened.document, [{ kind: 'field', name, value, prior: undefined }]);
522
+ const held = apply(create(definition.name, definition), [{ kind: 'field', name, value, prior: undefined }], definition);
552
523
  if (held.outcome !== 'applied')
553
524
  return value;
554
525
  const result = relativize(held.document, path, handle, definition);
555
526
  return result.outcome === 'applied' ? result.document.fields[name] : value;
556
527
  }
557
528
  function relativeChanges(input) {
529
+ const changes = [];
530
+ for (const change of input.changes) {
531
+ const next = relativeChange(change, input);
532
+ if ('refusal' in next)
533
+ return next;
534
+ changes.push(next.change);
535
+ }
536
+ return { kind: 'changes', changes };
537
+ }
538
+ function relativeChange(change, input) {
558
539
  const { handle, composition, visible } = input;
559
- const typed = (path) => (type) => definitionOf(governing(composition, path), type);
560
540
  const body = (path, text) => shellRelative(text, path, handle, () => undefined)?.content ?? text;
561
- return input.changes.map((change) => {
562
- const definition = typed(change.path);
563
- if (change.kind === 'field') {
564
- const type = visible.collection.document(change.path)?.type;
565
- const value = relativeField(change.path, change.name, change.value, handle, definition(type));
566
- return value === change.value ? change : { ...change, value };
567
- }
568
- if (change.kind === 'section' || change.kind === 'preamble') {
569
- const value = body(change.path, change.value);
570
- return value === change.value ? change : { ...change, value };
571
- }
572
- if (change.kind === 'replace' || (change.kind === 'create' && 'content' in change)) {
573
- const content = shellRelative(change.content, change.path, handle, definition)?.content ?? change.content;
574
- return content === change.content ? change : { ...change, content };
575
- }
576
- if (change.kind !== 'create')
577
- return change;
578
- const type = typeof change.fields.type === 'string' ? change.fields.type : undefined;
579
- const fields = Object.fromEntries(Object.entries(change.fields).map(([name, value]) => [
580
- name,
581
- relativeField(change.path, name, value, handle, definition(type)),
582
- ]));
583
- const sections = Object.fromEntries(Object.entries(change.sections).map(([name, value]) => [name, body(change.path, value)]));
584
- return { ...change, fields, sections };
585
- });
586
- }
587
- function* unmodeledType(collection, composition) {
588
- if (available(composition))
589
- return false;
590
- for (const [path, document] of yield* documentsOf(collection)) {
591
- if (document.type !== undefined &&
592
- document.type !== 'any' &&
593
- governing(composition, path).status === 'unavailable')
594
- return true;
595
- yield ROW_WEIGHT + collection.text[path].length;
541
+ const definition = definitionsAt(composition, change.path);
542
+ if (change.kind === 'field') {
543
+ const type = visible.collection.document(change.path)?.type;
544
+ const value = relativeField(change.path, change.name, change.value, handle, definition(type));
545
+ return { change: value === change.value ? change : { ...change, value } };
546
+ }
547
+ if (change.kind === 'section' || change.kind === 'preamble') {
548
+ const value = body(change.path, change.value);
549
+ return { change: value === change.value ? change : { ...change, value } };
596
550
  }
597
- return false;
551
+ if (change.kind === 'replace' || (change.kind === 'create' && 'content' in change)) {
552
+ const content = shellRelative(change.content, change.path, handle, definition)?.content ?? change.content;
553
+ return { change: content === change.content ? change : { ...change, content } };
554
+ }
555
+ if (change.kind !== 'create')
556
+ return { change };
557
+ const type = typeof change.fields.type === 'string' ? change.fields.type : undefined;
558
+ const fields = Object.fromEntries(Object.entries(change.fields).map(([name, value]) => [
559
+ name,
560
+ relativeField(change.path, name, value, handle, definition(type)),
561
+ ]));
562
+ const sections = Object.fromEntries(Object.entries(change.sections).map(([name, value]) => [name, body(change.path, value)]));
563
+ const written = composed(change.path, fields, sections, composition);
564
+ if (written.outcome === 'refuse')
565
+ return refusedBy(written.refusal, change.path);
566
+ if (written.outcome === 'stale')
567
+ throw new Error(`the creation of ${change.path} is stale`);
568
+ if (Object.keys(sections).length === 0)
569
+ return { change: { ...change, fields, sections } };
570
+ return {
571
+ change: { kind: 'create', path: change.path, content: serialize(written.document) },
572
+ };
598
573
  }
599
574
  function unqueueable(file) {
600
- return { kind: 'refused', refusal: { code: 'unknown-revision', retryable: false, file } };
601
- }
602
- function isPart(change) {
603
- return change.kind === 'field' || change.kind === 'section' || change.kind === 'preamble';
575
+ return refuse('unknown-revision', file);
604
576
  }
605
577
  function touched(change) {
606
578
  return change.kind === 'move' ? [change.path, change.to] : [change.path];
607
579
  }
608
- function partsApplied(content, path, changes) {
609
- const parsed = parse(content, path);
610
- if (!parsed.ok)
611
- return null;
612
- const document = parsed.document;
613
- const parts = new Map();
580
+ function partsApplied(content, path, changes, composition) {
581
+ const applied = partsResult(content, path, changes, composition);
582
+ return applied?.outcome === 'applied' ? serialize(applied.document) : null;
583
+ }
584
+ function unapplied(changes, visible, composition) {
585
+ const parted = new Map();
614
586
  for (const change of changes) {
615
- if (change.kind === 'field')
616
- parts.set(`field ${change.name}`, {
617
- kind: 'field',
618
- name: change.name,
619
- value: change.value,
620
- prior: document.fields[change.name],
621
- });
622
- else if (change.kind === 'section')
623
- parts.set(`section ${change.name}`, {
624
- kind: 'section',
625
- name: change.name,
626
- value: change.value,
627
- prior: document.sections[change.name] ?? '',
628
- });
629
- else
630
- parts.set('preamble', { kind: 'preamble', value: change.value, prior: document.preamble });
587
+ if (isPart(change))
588
+ parted.set(change.path, [...(parted.get(change.path) ?? []), change]);
589
+ }
590
+ for (const [path, parts] of parted) {
591
+ const content = visible.documents[path];
592
+ if (content === undefined)
593
+ continue;
594
+ const applied = partsResult(content, path, parts, composition);
595
+ if (applied?.outcome === 'refuse')
596
+ return refusedBy(applied.refusal, path);
631
597
  }
632
- const applied = apply(document, [...parts.values()]);
633
- return applied.outcome === 'applied' ? serialize(applied.document) : null;
598
+ return null;
599
+ }
600
+ function partsResult(content, path, changes, composition) {
601
+ const definitions = definitionsAt(composition, path);
602
+ const parsed = parse(content, path, definitions);
603
+ return parsed.ok ? applyParts(parsed.document, changes, definitions(parsed.document.type)) : null;
634
604
  }
635
- function settledParts(changes, deferred) {
605
+ function settledParts(changes, deferred, composition) {
636
606
  for (const [held, parts] of deferred) {
637
- const content = partsApplied(held.content, held.path, parts);
607
+ const content = partsApplied(held.content, held.path, parts, composition);
638
608
  if (content === null)
639
609
  return held.path;
640
610
  changes[changes.indexOf(held)] = { ...held, content };
@@ -709,7 +679,9 @@ function* relinked(batch, move, before, after, appending) {
709
679
  for (const change of derived.changes) {
710
680
  if (change === move)
711
681
  continue;
712
- const unsettled = isPart(change) ? null : settledParts(changes, deferred);
682
+ const unsettled = isPart(change)
683
+ ? null
684
+ : settledParts(changes, deferred, after.collection.composition);
713
685
  if (unsettled !== null)
714
686
  return unqueueable(unsettled);
715
687
  const outcome = folded(changes, change, appending, deferred);
@@ -720,7 +692,7 @@ function* relinked(batch, move, before, after, appending) {
720
692
  if (outcome !== 'skipped')
721
693
  changed = true;
722
694
  }
723
- const unsettled = settledParts(changes, deferred);
695
+ const unsettled = settledParts(changes, deferred, after.collection.composition);
724
696
  if (unsettled !== null)
725
697
  return unqueueable(unsettled);
726
698
  if (!changed)
@@ -781,11 +753,10 @@ function withdrawnFile(batch, change, at) {
781
753
  ];
782
754
  return immutable({ ...batch, id: changeBatchIdentity(), changes, preconditions });
783
755
  }
784
- export function* requeuing(queue, changes, visible, changeable, state) {
756
+ function* requeuing(queue, changes, visible, changeable, state) {
785
757
  const next = [...queue];
786
758
  const origins = new Map();
787
759
  const withdrawn = new Map();
788
- const owners = new Set();
789
760
  const queued = new Set();
790
761
  const kept = [];
791
762
  const originOf = (batch) => origins.get(batch) ?? batch.id;
@@ -831,7 +802,6 @@ export function* requeuing(queue, changes, visible, changeable, state) {
831
802
  if (replaced !== null)
832
803
  origins.set(replaced, origin);
833
804
  }
834
- owners.add(originOf(owner));
835
805
  next.splice(index, following.length, ...rebuilt.filter((batch) => batch !== null));
836
806
  queued.add(change.path);
837
807
  }
@@ -841,91 +811,65 @@ export function* requeuing(queue, changes, visible, changeable, state) {
841
811
  changes: kept,
842
812
  queued,
843
813
  withdrawn,
844
- owners,
845
814
  };
846
815
  }
847
- function covering(precondition) {
848
- return precondition.kind === 'field' ||
849
- precondition.kind === 'section' ||
850
- precondition.kind === 'preamble'
851
- ? identity(precondition)
852
- : `path ${precondition.path}`;
853
- }
854
- export function joined(queue, owner, extra) {
855
- const later = new Set(queue.slice(queue.indexOf(owner) + 1).flatMap((batch) => batch.changes.flatMap(touched)));
856
- const clash = extra.changes.flatMap(touched).find((path) => later.has(path));
857
- if (clash !== undefined)
858
- return unqueueable(clash);
859
- const changes = [...owner.changes];
860
- const deferred = new Map();
861
- for (const change of extra.changes) {
862
- const unsettled = isPart(change) ? null : settledParts(changes, deferred);
863
- if (unsettled !== null)
864
- return unqueueable(unsettled);
865
- if (folded(changes, change, true, deferred) === 'refused')
866
- return unqueueable(change.path);
867
- }
868
- const unsettled = settledParts(changes, deferred);
869
- if (unsettled !== null)
870
- return unqueueable(unsettled);
871
- const held = new Set(owner.preconditions.map(covering));
872
- const written = new Set(owner.changes.flatMap((change) => change.kind === 'create' || change.kind === 'replace' ? [change.path] : []));
873
- const preconditions = [
874
- ...owner.preconditions,
875
- ...extra.preconditions.filter((precondition) => {
876
- const key = covering(precondition);
877
- return (!held.has(key) && (key === `path ${precondition.path}` || !written.has(precondition.path)));
878
- }),
879
- ];
880
- const batch = immutable({
881
- ...owner,
882
- ...(extra.validation === undefined ? {} : { validation: extra.validation }),
883
- id: changeBatchIdentity(),
884
- changes,
885
- preconditions,
886
- });
887
- return { kind: 'joined', batch, queue: queue.map((item) => (item === owner ? batch : item)) };
888
- }
889
- export function* limiting(queue, batch, limits, state) {
816
+ function* limiting(queue, batch, limits, state) {
890
817
  const at = queue.indexOf(batch);
891
818
  const rewritten = yield* providerRewritten(batch, yield* state(queue.slice(0, at)));
892
819
  const limited = yield* exceeding(limits, batch.changes, rewritten.changes, yield* state(queue.slice(0, at + 1)));
893
- return limited?.kind === 'refused' ? limited.refusal : null;
820
+ return limited?.refusal ?? null;
894
821
  }
895
- function typedText(content) {
896
- if (content === undefined)
897
- return false;
898
- const parsed = parse(content);
899
- return parsed.ok && parsed.document.type !== undefined && parsed.document.type !== 'any';
822
+ function typedContent(composition, path, content) {
823
+ return (content !== undefined && (typeAt(composition, path, parse(content)) ?? UNTYPED) !== UNTYPED);
900
824
  }
901
- function* judging(visible, resulting, composition, clean, removed, touched) {
825
+ function touchedLibrary(resulting, touched, composition) {
826
+ const entries = touched
827
+ .flatMap((path) => {
828
+ const content = resulting.documents[path];
829
+ const binary = resulting.binaries[path] !== undefined;
830
+ return content === undefined && !binary ? [] : [{ path, content: content ?? null }];
831
+ })
832
+ .sort((left, right) => (left.path < right.path ? -1 : left.path > right.path ? 1 : 0));
833
+ const contents = new Map(entries.map(({ path, content }) => [path, content]));
834
+ const binaries = new Set(Array.from(entriesIn(resulting.binaries), ([path]) => path));
835
+ return validatedCollection(() => Promise.resolve({ entries, next: null }), async (paths) => {
836
+ const known = new Map();
837
+ const pace = paced();
838
+ for (const path of paths) {
839
+ const content = contents.get(path);
840
+ if (binaries.has(path))
841
+ known.set(path, { type: undefined, binary: true });
842
+ else if (content !== undefined && content !== null) {
843
+ const type = typeAt(composition, path, parse(content, path, definitionsAt(composition, path)));
844
+ if (type !== undefined)
845
+ known.set(path, { type, binary: false });
846
+ await pace(content.length + ROW_WEIGHT);
847
+ }
848
+ }
849
+ return known;
850
+ }, composition);
851
+ }
852
+ async function judging(visible, resulting, composition, validate, removed, touched) {
902
853
  if (removed.size > 0) {
903
- const referrers = clean === null ? null : yield* referring(clean, composition, removed);
904
- const referenced = yield* incoming(collectionOf(resulting.documents, composition), removed, clean === null || referrers === null
905
- ? null
906
- : chained(referrers, yield* differences(clean.text, resulting.documents)));
854
+ const referenced = await stepped(incoming(collectionOf(resulting.documents, composition), removed, null));
907
855
  if (referenced !== null)
908
856
  return referenced;
909
857
  }
910
858
  const typedPaths = [];
859
+ const pace = paced();
911
860
  for (const path of touched) {
912
861
  const before = visible.documents[path];
913
862
  const after = resulting.documents[path];
914
- if (typedText(before) || typedText(after))
863
+ if (typedContent(composition, path, before) || typedContent(composition, path, after))
915
864
  typedPaths.push(path);
916
- yield ROW_WEIGHT + (before?.length ?? 0) + (after?.length ?? 0);
865
+ await pace((before?.length ?? 0) + (after?.length ?? 0) + ROW_WEIGHT);
917
866
  }
918
867
  const withoutModel = typedPaths.find((path) => governing(composition, path).status === 'unavailable');
919
868
  if (withoutModel !== undefined)
920
869
  return refuse('model-unavailable', withoutModel);
921
- const verdict = clean !== null &&
922
- (yield* changedCleanly({ text: resulting.documents, binaries: resulting.binaries }, clean, composition))
923
- ? { verdict: 'accept' }
924
- : yield* validateCollection(typedPaths.length > 0
925
- ? resulting.documents
926
- : Object.fromEntries(touched.flatMap((path) => resulting.documents[path] === undefined
927
- ? []
928
- : [[path, resulting.documents[path]]])), Object.keys(resulting.binaries), composition);
870
+ const verdict = typedPaths.length > 0
871
+ ? await validate(resulting, touched)
872
+ : await touchedLibrary(resulting, touched, composition);
929
873
  if (verdict.verdict === 'refuse') {
930
874
  return {
931
875
  kind: 'refused',
@@ -934,6 +878,7 @@ function* judging(visible, resulting, composition, clean, removed, touched) {
934
878
  retryable: false,
935
879
  file: verdict.file,
936
880
  ...(verdict.location === undefined ? {} : { location: verdict.location }),
881
+ ...(verdict.line === undefined ? {} : { line: verdict.line }),
937
882
  ...(verdict.referrers === undefined ? {} : { referrers: verdict.referrers }),
938
883
  },
939
884
  };
@@ -946,11 +891,9 @@ function* judging(visible, resulting, composition, clean, removed, touched) {
946
891
  };
947
892
  }
948
893
  function placed(reference) {
949
- const key = roomPathOf(reference.handle, reference.path);
894
+ const key = writeRoomPath(reference);
950
895
  if (reference.kind === 'link')
951
896
  return `link ${key}`;
952
- if (reference.kind === 'item')
953
- return `section ${reference.section} ${key}`;
954
897
  const pointer = reference.pointer
955
898
  .split('/')
956
899
  .map((segment) => (ARRAY_INDEX.test(segment) ? '-' : segment))
@@ -960,10 +903,11 @@ function placed(reference) {
960
903
  function roomReferencesIn(path, content, composition) {
961
904
  if (content === undefined)
962
905
  return [];
963
- const parsed = parse(content, path);
906
+ const definitions = definitionsAt(composition, path);
907
+ const parsed = parse(content, path, definitions);
964
908
  if (!parsed.ok)
965
909
  return [];
966
- return roomReferences(path, content, definitionOf(governing(composition, path), parsed.document.type));
910
+ return roomReferences(parsed.document, { path }, definitions(parsed.document.type));
967
911
  }
968
912
  function* admittedRooms(changes, visible, resulting, composition) {
969
913
  const from = new Map();
@@ -981,7 +925,7 @@ function* admittedRooms(changes, visible, resulting, composition) {
981
925
  continue;
982
926
  if (held.has(placed(reference)))
983
927
  continue;
984
- return refuse('unresolved-reference', path, reference.kind === 'field' ? reference.pointer : reference.section);
928
+ return refuse('unresolved-reference', path, reference.pointer);
985
929
  }
986
930
  yield ROW_WEIGHT + now.length;
987
931
  }
@@ -998,32 +942,33 @@ function validationOf(validated) {
998
942
  },
999
943
  };
1000
944
  }
1001
- function* batching(input) {
1002
- const changes = relativeChanges(input);
945
+ async function batching(input) {
946
+ const relative = relativeChanges(input);
947
+ if (relative.kind === 'refused')
948
+ return relative;
949
+ const { changes } = relative;
1003
950
  const structural = changes.find((change) => change.kind === 'move' || change.kind === 'remove');
1004
- if (structural !== undefined &&
1005
- (yield* unmodeledType(input.visible.collection, input.composition)))
951
+ if (structural !== undefined && input.unmodeled) {
1006
952
  return refuse('model-unavailable', structural.path);
953
+ }
1007
954
  if (changes.length === 0)
1008
955
  return refuse('no-change');
1009
- const rewritten = yield* rewrites(changes, input.visible);
956
+ const rewritten = await stepped(rewrites(changes, input.visible));
1010
957
  if (rewritten.kind === 'refused')
1011
958
  return rewritten;
1012
- const refusal = guard(changes, input, 'delete');
959
+ const refusal = guard(changes, input, WRITE) ?? unapplied(changes, input.visible, input.composition);
1013
960
  if (refusal !== null)
1014
961
  return refusal;
1015
- const preconditions = yield* preconditionsOf(changes, input.visible, input.bases);
1016
- const predicted = yield* anticipated(changes, preconditions, rewritten.changes, input.visible);
1017
- const resulting = yield* overlaying(input.visible, [
1018
- { id: '', baseRoomVersion: input.baseRoomVersion, ...predicted },
1019
- ]);
1020
- const judged = yield* judging(input.visible, resulting, input.composition, input.clean !== undefined && available(input.composition) ? input.clean : null, new Set(changes.filter((change) => change.kind === 'remove').map((change) => change.path)), [...new Set(predicted.changes.flatMap(affected))]);
962
+ const preconditions = await stepped(preconditionsOf(changes, input.visible, input.bases));
963
+ const predicted = await stepped(anticipated(changes, preconditions, rewritten.changes, input.visible));
964
+ const resulting = await stepped(overlaying(input.visible, [{ id: '', baseRoomVersion: input.baseRoomVersion, ...predicted }], input.composition));
965
+ const judged = await judging(input.visible, resulting, input.composition, input.validate, new Set(changes.filter((change) => change.kind === 'remove').map((change) => change.path)), [...new Set(predicted.changes.flatMap(affected))]);
1021
966
  if (judged.kind === 'refused')
1022
967
  return judged;
1023
- const crossing = yield* admittedRooms(changes, input.visible, resulting, input.composition);
968
+ const crossing = await stepped(admittedRooms(changes, input.visible, resulting, input.composition));
1024
969
  if (crossing !== null)
1025
970
  return crossing;
1026
- const limited = yield* exceeding(input.providerLimits, changes, predicted.changes, resulting);
971
+ const limited = await stepped(exceeding(input.providerLimits, changes, predicted.changes, resulting));
1027
972
  if (limited !== null)
1028
973
  return limited;
1029
974
  return {
@@ -1038,7 +983,7 @@ function* batching(input) {
1038
983
  }),
1039
984
  };
1040
985
  }
1041
- export const MOVE_DOCUMENTS = 'move-documents';
986
+ const MOVE_DOCUMENTS = 'move-documents';
1042
987
  function heldAt(visible, path) {
1043
988
  return visible.documents[path] !== undefined || visible.binaries[path] !== undefined;
1044
989
  }
@@ -1047,22 +992,25 @@ function arrivingText(path, to, source, moved) {
1047
992
  const document = source.visible.collection.document(path);
1048
993
  if (document === undefined)
1049
994
  return content;
1050
- const definition = definitionOf(governing(source.composition, path), document.type);
995
+ const definition = definitionsAt(source.composition, path)(document.type);
1051
996
  const changes = crossed(document, definition, path, (named, href) => {
1052
997
  const at = moved.get(named);
1053
998
  if (at !== undefined)
1054
999
  return target(to, href) === at ? undefined : relative(to, at);
1055
- return heldAt(source.visible, named) ? roomPathOf(source.handle, named) : undefined;
1000
+ return heldAt(source.visible, named)
1001
+ ? relativePath({ path: to }, { handle: source.handle, path: named })
1002
+ : undefined;
1056
1003
  });
1057
1004
  if (changes.length === 0)
1058
1005
  return content;
1059
- const applied = apply(document, changes);
1006
+ const applied = apply(document, changes, definition);
1060
1007
  return applied.outcome === 'applied' ? serialize(applied.document) : content;
1061
1008
  }
1062
1009
  function arrivalOf({ path, to }, source, moved) {
1063
- const { documents, revisions, fileIds, changes, binaries } = source.visible;
1010
+ const { documents, revisions, fileIds, created, changes, binaries } = source.visible;
1064
1011
  const kept = {
1065
1012
  ...(fileIds[path] === undefined ? {} : { fileId: fileIds[path] }),
1013
+ ...(created[path] === undefined ? {} : { created: created[path] }),
1066
1014
  ...(changes[path] === undefined ? {} : { change: changes[path] }),
1067
1015
  };
1068
1016
  const heads = {
@@ -1071,11 +1019,11 @@ function arrivalOf({ path, to }, source, moved) {
1071
1019
  };
1072
1020
  const binary = binaries[path];
1073
1021
  if (binary?.state === 'accepted') {
1074
- const { fileRef, byteLength, mediaType, sha256 } = binary;
1022
+ const { byteLength, mediaType, sha256 } = binary;
1075
1023
  return {
1076
1024
  kind: 'arrival',
1077
1025
  path: to,
1078
- binary: { fileRef, byteLength, mediaType, sha256 },
1026
+ binary: { byteLength, mediaType, sha256 },
1079
1027
  ...heads,
1080
1028
  };
1081
1029
  }
@@ -1087,12 +1035,10 @@ function arrivalOf({ path, to }, source, moved) {
1087
1035
  ...(content === documents[path] ? heads : kept),
1088
1036
  };
1089
1037
  }
1090
- function* moving(input) {
1038
+ async function moving(input) {
1091
1039
  const { source, destination, moves } = input;
1092
- if (moves.length === 0)
1093
- return refuse('no-change');
1094
1040
  const removals = moves.map(({ path }) => ({ kind: 'remove', path }));
1095
- const leaves = guard(removals, { ...source, local: input.local, bases: [] }, 'write');
1041
+ const leaves = guard(removals, { ...source, local: input.local, bases: [] }, MOVE_OUT);
1096
1042
  if (leaves !== null)
1097
1043
  return leaves;
1098
1044
  const uploading = moves.find(({ path }) => source.visible.binaries[path]?.state === 'pending');
@@ -1100,16 +1046,15 @@ function* moving(input) {
1100
1046
  return refuse('unknown-revision', uploading.path);
1101
1047
  const moved = new Map(moves.map(({ path, to }) => [path, to]));
1102
1048
  const arrivals = moves.map((move) => arrivalOf(move, source, moved));
1103
- const arrives = guard(arrivals, { ...destination, local: input.local, bases: [] }, 'write');
1049
+ const arrives = guard(arrivals, { ...destination, local: input.local, bases: [] }, WRITE);
1104
1050
  if (arrives !== null)
1105
1051
  return arrives;
1106
1052
  const bound = input.providerLimits.find((limit) => limit.name === MOVE_DOCUMENTS)?.value;
1107
1053
  if (typeof bound === 'number' && moves.length > bound) {
1108
1054
  return refuse('provider-limit', undefined, MOVE_DOCUMENTS);
1109
1055
  }
1110
- if (yield* unmodeledType(source.visible.collection, source.composition)) {
1056
+ if (source.unmodeled)
1111
1057
  return refuse('model-unavailable', moves[0].path);
1112
- }
1113
1058
  const id = changeBatchIdentity();
1114
1059
  const between = {
1115
1060
  source: { room: source.room, baseRoomVersion: source.baseRoomVersion },
@@ -1129,9 +1074,9 @@ function* moving(input) {
1129
1074
  ...written,
1130
1075
  between,
1131
1076
  };
1132
- const effective = yield* leavingRewritten(leavingBatch, source.visible);
1133
- const left = yield* overlaying(source.visible, [effective]);
1134
- const sourceJudged = yield* judging(source.visible, left, source.composition, available(source.composition) ? source.clean : null, new Set(moves.map(({ path }) => path)), [...new Set(effective.changes.map((change) => change.path))]);
1077
+ const effective = await stepped(leavingRewritten(leavingBatch, source.visible));
1078
+ const left = await stepped(overlaying(source.visible, [effective], source.composition));
1079
+ const sourceJudged = await judging(source.visible, left, source.composition, source.validate, new Set(moves.map(({ path }) => path)), [...new Set(effective.changes.map((change) => change.path))]);
1135
1080
  if (sourceJudged.kind === 'refused')
1136
1081
  return sourceJudged;
1137
1082
  const arrivingBatch = {
@@ -1142,19 +1087,190 @@ function* moving(input) {
1142
1087
  ...written,
1143
1088
  between,
1144
1089
  };
1145
- const arrived = yield* overlaying(destination.visible, [arrivingBatch]);
1146
- const destinationJudged = yield* judging(destination.visible, arrived, destination.composition, available(destination.composition) ? destination.clean : null, new Set(), moves.map(({ to }) => to));
1090
+ const arrived = await stepped(overlaying(destination.visible, [arrivingBatch], destination.composition));
1091
+ const destinationJudged = await judging(destination.visible, arrived, destination.composition, destination.validate, new Set(), moves.map(({ to }) => to));
1147
1092
  if (destinationJudged.kind === 'refused')
1148
1093
  return destinationJudged;
1149
- const limited = (yield* exceeding(input.providerLimits, removals, effective.changes, left)) ??
1150
- (yield* exceeding(input.providerLimits, arrivals, arrivals, arrived));
1094
+ const limited = (await stepped(exceeding(input.providerLimits, removals, effective.changes, left))) ??
1095
+ (await stepped(exceeding(input.providerLimits, arrivals, arrivals, arrived)));
1151
1096
  if (limited !== null)
1152
1097
  return limited;
1153
1098
  return { kind: 'moved', leaving: immutable(leavingBatch), arriving: immutable(arrivingBatch) };
1154
1099
  }
1155
- export function buildMove(input) {
1156
- return stepped(moving(input));
1100
+ function unreadable(saved, visible, composition) {
1101
+ const path = saved.find(({ path: at, parts }) => (parts.fields !== undefined ||
1102
+ parts.sections !== undefined ||
1103
+ parts.preamble !== undefined) &&
1104
+ typedContent(composition, at, visible.documents[at]) &&
1105
+ governing(composition, at).status === 'unavailable')?.path;
1106
+ return path === undefined ? null : refuse('model-unavailable', path);
1107
+ }
1108
+ function changedUnderneath(saved, visible) {
1109
+ const parts = saved.flatMap(({ path, parts: held }) => changedParts(path, held, visible));
1110
+ return parts.length === 0
1111
+ ? null
1112
+ : { kind: 'refused', refusal: { code: 'changed-underneath', retryable: false, parts } };
1113
+ }
1114
+ function sideOf(room, visible) {
1115
+ const { record } = room;
1116
+ return {
1117
+ room: record.locator,
1118
+ handle: record.declaration.handle,
1119
+ baseRoomVersion: record.roomVersion,
1120
+ composition: room.composition,
1121
+ rule: room.rule,
1122
+ visible,
1123
+ folders: room.folders,
1124
+ queued: queuedDocuments(room.queue),
1125
+ unmodeled: !room.modelled,
1126
+ validate: room.validate,
1127
+ };
1128
+ }
1129
+ function carriedDrafts(ask, from, into) {
1130
+ return new Map(ask.saved.flatMap(({ path, parts }) => {
1131
+ const record = from.drafts.get(path);
1132
+ if (parts.move === undefined || record === undefined || ask.consumed.has(path))
1133
+ return [];
1134
+ const to = moveTarget(parts.move);
1135
+ if (into.drafts.has(to))
1136
+ return [];
1137
+ const locator = into.record.locator;
1138
+ return [[path, { ...record, locator, path: to, revision: roomDraftRevision() }]];
1139
+ }));
1140
+ }
1141
+ async function plannedMove(ask, source, into) {
1142
+ const destination = into.record.locator;
1143
+ const mixed = ask.saved.find(({ parts }) => Object.keys(parts).length !== 1 || parts.move?.room !== destination);
1144
+ if (mixed !== undefined)
1145
+ return refuse('mixed-room-move', mixed.path);
1146
+ const leavingVisible = await stepped(source.replay(source.queue));
1147
+ const changed = changedUnderneath(ask.saved, leavingVisible);
1148
+ if (changed !== null)
1149
+ return changed;
1150
+ const moves = ask.saved.map(({ path, parts }) => ({ path, to: moveTarget(parts.move) }));
1151
+ const built = await moving({
1152
+ source: sideOf(source, leavingVisible),
1153
+ destination: sideOf(into, await stepped(into.replay(into.queue))),
1154
+ moves,
1155
+ providerLimits: ask.providerLimits,
1156
+ local: ask.local,
1157
+ ...(ask.writtenBy === undefined ? {} : { writtenBy: ask.writtenBy }),
1158
+ });
1159
+ if (built.kind === 'refused')
1160
+ return built;
1161
+ const { id } = built.leaving;
1162
+ const carried = carriedDrafts(ask, source, into);
1163
+ return {
1164
+ kind: 'planned',
1165
+ identifier: id,
1166
+ rooms: [
1167
+ {
1168
+ locator: source.record.locator,
1169
+ queue: [...source.queue, built.leaving],
1170
+ saved: new Map([[id, ask.saved]]),
1171
+ consumed: [...ask.consumed, ...carried.keys()],
1172
+ carried: [],
1173
+ },
1174
+ {
1175
+ locator: destination,
1176
+ queue: [...into.queue, built.arriving],
1177
+ saved: new Map([
1178
+ [id, [...carried.values()].map(({ path }) => ({ path, parts: {} }))],
1179
+ ]),
1180
+ consumed: [],
1181
+ carried: [...carried.values()],
1182
+ },
1183
+ ],
1184
+ };
1185
+ }
1186
+ async function plannedWithin(ask, room) {
1187
+ const { record } = room;
1188
+ const visible = await stepped(room.replay(room.queue));
1189
+ const changed = unreadable(ask.saved, visible, room.composition) ?? changedUnderneath(ask.saved, visible);
1190
+ if (changed !== null)
1191
+ return changed;
1192
+ const parts = ask.saved.map(({ path, parts: held }) => changesOf(path, held));
1193
+ const changes = parts.flatMap(({ changes: made }) => made);
1194
+ const requeue = await stepped(requeuing(room.queue, changes, visible, (batch) => room.changeable.has(batch.id), room.replay));
1195
+ if (requeue.kind === 'refused')
1196
+ return requeue;
1197
+ const foreign = [...requeue.withdrawn.keys()].some((origin) => {
1198
+ const writer = room.queue.find((batch) => batch.id === origin)?.writtenBy;
1199
+ return writer?.app !== ask.writtenBy?.app || writer?.release !== ask.writtenBy?.release;
1200
+ });
1201
+ if (foreign)
1202
+ return unqueueable([...requeue.queued].at(-1));
1203
+ const input = {
1204
+ local: ask.local,
1205
+ baseRoomVersion: record.roomVersion,
1206
+ composition: room.composition,
1207
+ rule: room.rule,
1208
+ providerLimits: ask.providerLimits,
1209
+ handle: record.declaration.handle,
1210
+ visible,
1211
+ folders: room.folders,
1212
+ changes,
1213
+ bases: parts.flatMap(({ bases }) => bases),
1214
+ queued: queuedDocuments(room.queue),
1215
+ writtenBy: ask.writtenBy,
1216
+ unmodeled: !room.modelled,
1217
+ validate: room.validate,
1218
+ };
1219
+ const rewritten = requeue.withdrawn.size > 0;
1220
+ if (rewritten) {
1221
+ const whole = await batching({
1222
+ ...input,
1223
+ providerLimits: [],
1224
+ queued: new Set([...input.queued, ...requeue.queued]),
1225
+ });
1226
+ if (whole.kind === 'refused')
1227
+ return whole;
1228
+ }
1229
+ const own = !rewritten
1230
+ ? await batching(input)
1231
+ : requeue.changes.length === 0
1232
+ ? null
1233
+ : await batching({
1234
+ ...input,
1235
+ visible: await stepped(room.replay(requeue.queue)),
1236
+ changes: requeue.changes,
1237
+ queued: queuedDocuments(requeue.queue),
1238
+ });
1239
+ if (own?.kind === 'refused')
1240
+ return own;
1241
+ const queue = own === null ? requeue.queue : [...requeue.queue, own.batch];
1242
+ const saved = new Map();
1243
+ for (const [origin, rebuilt] of requeue.withdrawn) {
1244
+ if (rebuilt === null)
1245
+ continue;
1246
+ const limited = await stepped(limiting(queue, rebuilt, ask.providerLimits, room.replay));
1247
+ if (limited !== null)
1248
+ return { kind: 'refused', refusal: limited };
1249
+ saved.set(rebuilt.id, withdrawnDrafts(room.saved.get(origin) ?? [], changes));
1250
+ }
1251
+ if (own !== null) {
1252
+ saved.set(own.batch.id, ask.saved.filter(({ path }) => !requeue.queued.has(path)));
1253
+ }
1254
+ const carried = carriedDrafts(ask, room, room);
1255
+ return {
1256
+ kind: 'planned',
1257
+ identifier: own?.batch.id ??
1258
+ [...requeue.withdrawn].map(([origin, rebuilt]) => rebuilt?.id ?? origin).at(-1),
1259
+ rooms: [
1260
+ {
1261
+ locator: record.locator,
1262
+ queue,
1263
+ saved,
1264
+ consumed: [...ask.consumed, ...carried.keys()],
1265
+ carried: [...carried.values()],
1266
+ },
1267
+ ],
1268
+ };
1269
+ }
1270
+ export function destination(locator, saved) {
1271
+ const into = saved.find(({ parts }) => parts.move?.room !== undefined && parts.move.room !== locator);
1272
+ return into?.parts.move?.room ?? null;
1157
1273
  }
1158
- export function buildBatch(input) {
1159
- return stepped(batching(input));
1274
+ export function planSave(ask, room, into) {
1275
+ return into === undefined ? plannedWithin(ask, room) : plannedMove(ask, room, into);
1160
1276
  }