@agentshouse/mdruntime 0.1.0-cd50a4607cb7d → 0.1.0-cd71aba4d0215

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 (385) hide show
  1. package/README.md +19 -16
  2. package/dist/acceptance.d.ts +3 -0
  3. package/dist/acceptance.d.ts.map +1 -0
  4. package/dist/acceptance.js +318 -0
  5. package/dist/act-lanes.d.ts +33 -0
  6. package/dist/act-lanes.d.ts.map +1 -0
  7. package/dist/act-lanes.js +177 -0
  8. package/dist/actions.d.ts +25 -0
  9. package/dist/actions.d.ts.map +1 -0
  10. package/dist/actions.js +261 -0
  11. package/dist/adapter.d.ts +175 -116
  12. package/dist/adapter.d.ts.map +1 -1
  13. package/dist/attached-model.d.ts +7 -10
  14. package/dist/attached-model.d.ts.map +1 -1
  15. package/dist/attached-model.js +40 -41
  16. package/dist/binary.d.ts +0 -5
  17. package/dist/binary.d.ts.map +1 -1
  18. package/dist/binary.js +1 -1
  19. package/dist/bootstrap.d.ts +31 -11
  20. package/dist/bootstrap.d.ts.map +1 -1
  21. package/dist/bootstrap.js +309 -109
  22. package/dist/cell.d.ts +6 -0
  23. package/dist/cell.d.ts.map +1 -0
  24. package/dist/cell.js +9 -0
  25. package/dist/chain.d.ts +12 -0
  26. package/dist/chain.d.ts.map +1 -0
  27. package/dist/chain.js +64 -0
  28. package/dist/change-set.d.ts +13 -16
  29. package/dist/change-set.d.ts.map +1 -1
  30. package/dist/change-set.js +17 -88
  31. package/dist/change.d.ts +32 -1
  32. package/dist/change.d.ts.map +1 -1
  33. package/dist/change.js +14 -3
  34. package/dist/chat-types.d.ts +5 -0
  35. package/dist/chat-types.d.ts.map +1 -0
  36. package/dist/chat-types.js +13 -0
  37. package/dist/client.d.ts +41 -19
  38. package/dist/client.d.ts.map +1 -1
  39. package/dist/client.js +129 -25
  40. package/dist/collection.d.ts +29 -21
  41. package/dist/collection.d.ts.map +1 -1
  42. package/dist/collection.js +48 -290
  43. package/dist/compile.d.ts +16 -0
  44. package/dist/compile.d.ts.map +1 -0
  45. package/dist/compile.js +711 -0
  46. package/dist/connection.d.ts +7 -118
  47. package/dist/connection.d.ts.map +1 -1
  48. package/dist/connection.js +111 -2972
  49. package/dist/context.d.ts +2 -0
  50. package/dist/context.d.ts.map +1 -0
  51. package/dist/{chat/context.js → context.js} +1 -4
  52. package/dist/conversation-live.d.ts +138 -0
  53. package/dist/conversation-live.d.ts.map +1 -0
  54. package/dist/conversation-live.js +249 -0
  55. package/dist/conversation-row.d.ts +33 -0
  56. package/dist/conversation-row.d.ts.map +1 -0
  57. package/dist/conversation-row.js +53 -0
  58. package/dist/conversation.d.ts +72 -47
  59. package/dist/conversation.d.ts.map +1 -1
  60. package/dist/conversation.js +1036 -690
  61. package/dist/declaration.d.ts +10 -0
  62. package/dist/declaration.d.ts.map +1 -0
  63. package/dist/declaration.js +24 -0
  64. package/dist/digest.d.ts +7 -0
  65. package/dist/digest.d.ts.map +1 -0
  66. package/dist/digest.js +113 -0
  67. package/dist/discovery.d.ts +10 -0
  68. package/dist/discovery.d.ts.map +1 -0
  69. package/dist/discovery.js +153 -0
  70. package/dist/durability.d.ts +22 -1
  71. package/dist/durability.d.ts.map +1 -1
  72. package/dist/durability.js +5 -0
  73. package/dist/entry.d.ts +5 -2
  74. package/dist/entry.d.ts.map +1 -1
  75. package/dist/entry.js +33 -28
  76. package/dist/expectation.d.ts +4 -2
  77. package/dist/expectation.d.ts.map +1 -1
  78. package/dist/expectation.js +33 -11
  79. package/dist/failure.d.ts +3 -0
  80. package/dist/failure.d.ts.map +1 -1
  81. package/dist/failure.js +6 -0
  82. package/dist/figures.d.ts +49 -0
  83. package/dist/figures.d.ts.map +1 -0
  84. package/dist/figures.js +197 -0
  85. package/dist/file.d.ts +2 -19
  86. package/dist/file.d.ts.map +1 -1
  87. package/dist/file.js +7 -122
  88. package/dist/holdings.d.ts +29 -0
  89. package/dist/holdings.d.ts.map +1 -0
  90. package/dist/holdings.js +95 -0
  91. package/dist/host.d.ts +26 -4
  92. package/dist/host.d.ts.map +1 -1
  93. package/dist/host.js +161 -25
  94. package/dist/identity.d.ts +0 -2
  95. package/dist/identity.d.ts.map +1 -1
  96. package/dist/identity.js +0 -6
  97. package/dist/index.d.ts +39 -13
  98. package/dist/index.d.ts.map +1 -1
  99. package/dist/index.js +17 -2
  100. package/dist/install.d.ts +54 -0
  101. package/dist/install.d.ts.map +1 -0
  102. package/dist/install.js +539 -0
  103. package/dist/lifecycle.d.ts +7 -0
  104. package/dist/lifecycle.d.ts.map +1 -0
  105. package/dist/lifecycle.js +279 -0
  106. package/dist/listing.d.ts +48 -0
  107. package/dist/listing.d.ts.map +1 -0
  108. package/dist/listing.js +139 -0
  109. package/dist/live.d.ts +23 -0
  110. package/dist/live.d.ts.map +1 -0
  111. package/dist/live.js +165 -0
  112. package/dist/locks.d.ts +7 -0
  113. package/dist/locks.d.ts.map +1 -0
  114. package/dist/locks.js +33 -0
  115. package/dist/log.d.ts +1 -0
  116. package/dist/log.d.ts.map +1 -1
  117. package/dist/lost.d.ts +5 -0
  118. package/dist/lost.d.ts.map +1 -0
  119. package/dist/lost.js +50 -0
  120. package/dist/media.d.ts +8 -0
  121. package/dist/media.d.ts.map +1 -0
  122. package/dist/media.js +218 -0
  123. package/dist/memory.d.ts +22 -7
  124. package/dist/memory.d.ts.map +1 -1
  125. package/dist/memory.js +278 -110
  126. package/dist/messages.d.ts +49 -0
  127. package/dist/messages.d.ts.map +1 -0
  128. package/dist/messages.js +150 -0
  129. package/dist/model.d.ts +11 -13
  130. package/dist/model.d.ts.map +1 -1
  131. package/dist/model.js +7 -24
  132. package/dist/models.d.ts +10 -0
  133. package/dist/models.d.ts.map +1 -0
  134. package/dist/models.js +156 -0
  135. package/dist/name.d.ts +4 -0
  136. package/dist/name.d.ts.map +1 -0
  137. package/dist/name.js +122 -0
  138. package/dist/observation.d.ts +17 -2
  139. package/dist/observation.d.ts.map +1 -1
  140. package/dist/observation.js +107 -17
  141. package/dist/opened.d.ts +22 -0
  142. package/dist/opened.d.ts.map +1 -0
  143. package/dist/opened.js +107 -0
  144. package/dist/opening.d.ts +4 -0
  145. package/dist/opening.d.ts.map +1 -0
  146. package/dist/opening.js +59 -0
  147. package/dist/outcome.d.ts +52 -8
  148. package/dist/outcome.d.ts.map +1 -1
  149. package/dist/outcome.js +57 -0
  150. package/dist/overlay.d.ts +5 -5
  151. package/dist/overlay.d.ts.map +1 -1
  152. package/dist/overlay.js +127 -166
  153. package/dist/page-metadata.d.ts +8 -0
  154. package/dist/page-metadata.d.ts.map +1 -0
  155. package/dist/page-metadata.js +19 -0
  156. package/dist/parts.d.ts +11 -0
  157. package/dist/parts.d.ts.map +1 -0
  158. package/dist/parts.js +21 -0
  159. package/dist/paths.d.ts +2 -0
  160. package/dist/paths.d.ts.map +1 -1
  161. package/dist/paths.js +26 -0
  162. package/dist/preparation.d.ts +20 -0
  163. package/dist/preparation.d.ts.map +1 -0
  164. package/dist/preparation.js +233 -0
  165. package/dist/presence.d.ts +52 -0
  166. package/dist/presence.d.ts.map +1 -0
  167. package/dist/presence.js +220 -0
  168. package/dist/queries.d.ts +16 -0
  169. package/dist/queries.d.ts.map +1 -0
  170. package/dist/queries.js +270 -0
  171. package/dist/query.d.ts +27 -186
  172. package/dist/query.d.ts.map +1 -1
  173. package/dist/query.js +3 -464
  174. package/dist/{chat/questions.d.ts → questions.d.ts} +5 -2
  175. package/dist/questions.d.ts.map +1 -0
  176. package/dist/{chat/questions.js → questions.js} +13 -2
  177. package/dist/queue.d.ts +40 -0
  178. package/dist/queue.d.ts.map +1 -0
  179. package/dist/queue.js +455 -0
  180. package/dist/reach.d.ts +21 -7
  181. package/dist/reach.d.ts.map +1 -1
  182. package/dist/reach.js +315 -96
  183. package/dist/react.d.ts +25 -4
  184. package/dist/react.d.ts.map +1 -1
  185. package/dist/react.js +22 -18
  186. package/dist/{chat/read.d.ts → read.d.ts} +2 -0
  187. package/dist/read.d.ts.map +1 -0
  188. package/dist/{chat/read.js → read.js} +4 -0
  189. package/dist/readiness.d.ts +49 -0
  190. package/dist/readiness.d.ts.map +1 -0
  191. package/dist/readiness.js +27 -0
  192. package/dist/reads.d.ts +39 -0
  193. package/dist/reads.d.ts.map +1 -0
  194. package/dist/reads.js +178 -0
  195. package/dist/recovery.d.ts +5 -2
  196. package/dist/recovery.d.ts.map +1 -1
  197. package/dist/recovery.js +65 -8
  198. package/dist/refresh.d.ts +17 -14
  199. package/dist/refresh.d.ts.map +1 -1
  200. package/dist/refresh.js +145 -54
  201. package/dist/refusal.d.ts +5 -0
  202. package/dist/refusal.d.ts.map +1 -0
  203. package/dist/refusal.js +57 -0
  204. package/dist/replica.d.ts +50 -33
  205. package/dist/replica.d.ts.map +1 -1
  206. package/dist/replica.js +338 -189
  207. package/dist/retried.d.ts +30 -0
  208. package/dist/retried.d.ts.map +1 -0
  209. package/dist/retried.js +72 -0
  210. package/dist/room-draft.d.ts +39 -10
  211. package/dist/room-draft.d.ts.map +1 -1
  212. package/dist/room-draft.js +186 -115
  213. package/dist/room-drafts.d.ts +24 -0
  214. package/dist/room-drafts.d.ts.map +1 -0
  215. package/dist/room-drafts.js +217 -0
  216. package/dist/rows.d.ts +31 -29
  217. package/dist/rows.d.ts.map +1 -1
  218. package/dist/rows.js +60 -118
  219. package/dist/runtime.d.ts +36 -0
  220. package/dist/runtime.d.ts.map +1 -0
  221. package/dist/runtime.js +1 -0
  222. package/dist/save.d.ts +42 -48
  223. package/dist/save.d.ts.map +1 -1
  224. package/dist/save.js +715 -248
  225. package/dist/saves.d.ts +32 -0
  226. package/dist/saves.d.ts.map +1 -0
  227. package/dist/saves.js +413 -0
  228. package/dist/search.d.ts +15 -77
  229. package/dist/search.d.ts.map +1 -1
  230. package/dist/search.js +10 -186
  231. package/dist/seed.d.ts +25 -0
  232. package/dist/seed.d.ts.map +1 -0
  233. package/dist/seed.js +145 -0
  234. package/dist/shared.d.ts +6 -7
  235. package/dist/shared.d.ts.map +1 -1
  236. package/dist/shared.js +75 -104
  237. package/dist/shown.d.ts +32 -0
  238. package/dist/shown.d.ts.map +1 -0
  239. package/dist/shown.js +290 -0
  240. package/dist/socket/admission.d.ts +7 -0
  241. package/dist/socket/admission.d.ts.map +1 -0
  242. package/dist/socket/admission.js +39 -0
  243. package/dist/socket/answers.d.ts +6 -0
  244. package/dist/socket/answers.d.ts.map +1 -0
  245. package/dist/socket/answers.js +20 -0
  246. package/dist/socket/lanes.d.ts +21 -0
  247. package/dist/socket/lanes.d.ts.map +1 -0
  248. package/dist/socket/lanes.js +80 -0
  249. package/dist/socket/reads.d.ts +10 -0
  250. package/dist/socket/reads.d.ts.map +1 -0
  251. package/dist/socket/reads.js +31 -0
  252. package/dist/socket/session.d.ts +38 -0
  253. package/dist/socket/session.d.ts.map +1 -0
  254. package/dist/socket/session.js +23 -0
  255. package/dist/socket.d.ts +68 -0
  256. package/dist/socket.d.ts.map +1 -0
  257. package/dist/socket.js +171 -0
  258. package/dist/source.d.ts +61 -0
  259. package/dist/source.d.ts.map +1 -0
  260. package/dist/source.js +82 -0
  261. package/dist/status.d.ts +4 -5
  262. package/dist/status.d.ts.map +1 -1
  263. package/dist/status.js +3 -7
  264. package/dist/store/installs.d.ts +30 -0
  265. package/dist/store/installs.d.ts.map +1 -0
  266. package/dist/store/installs.js +34 -0
  267. package/dist/store/readiness.d.ts +10 -0
  268. package/dist/store/readiness.d.ts.map +1 -0
  269. package/dist/store/readiness.js +52 -0
  270. package/dist/store/records.d.ts +212 -0
  271. package/dist/store/records.d.ts.map +1 -0
  272. package/dist/store/records.js +430 -0
  273. package/dist/store/room-held.d.ts +8 -0
  274. package/dist/store/room-held.d.ts.map +1 -0
  275. package/dist/store/room-held.js +17 -0
  276. package/dist/store/space.d.ts +11 -0
  277. package/dist/store/space.d.ts.map +1 -0
  278. package/dist/store/space.js +41 -0
  279. package/dist/store/watchers.d.ts +17 -0
  280. package/dist/store/watchers.d.ts.map +1 -0
  281. package/dist/store/watchers.js +56 -0
  282. package/dist/store/writes.d.ts +24 -0
  283. package/dist/store/writes.d.ts.map +1 -0
  284. package/dist/store/writes.js +125 -0
  285. package/dist/store.d.ts +111 -142
  286. package/dist/store.d.ts.map +1 -1
  287. package/dist/store.js +159 -687
  288. package/dist/stored.d.ts +156 -0
  289. package/dist/stored.d.ts.map +1 -0
  290. package/dist/stored.js +649 -0
  291. package/dist/surface.d.ts +88 -0
  292. package/dist/surface.d.ts.map +1 -0
  293. package/dist/surface.js +223 -0
  294. package/dist/sync.d.ts +19 -0
  295. package/dist/sync.d.ts.map +1 -0
  296. package/dist/sync.js +540 -0
  297. package/dist/tables.d.ts +412 -0
  298. package/dist/tables.d.ts.map +1 -0
  299. package/dist/tables.js +737 -0
  300. package/dist/tallies.d.ts +18 -0
  301. package/dist/tallies.d.ts.map +1 -0
  302. package/dist/tallies.js +129 -0
  303. package/dist/transfer.d.ts +0 -5
  304. package/dist/transfer.d.ts.map +1 -1
  305. package/dist/turn.d.ts +5 -3
  306. package/dist/turn.d.ts.map +1 -1
  307. package/dist/turn.js +51 -21
  308. package/dist/validation.d.ts +29 -0
  309. package/dist/validation.d.ts.map +1 -0
  310. package/dist/validation.js +104 -0
  311. package/dist/windows.d.ts +11 -0
  312. package/dist/windows.d.ts.map +1 -0
  313. package/dist/windows.js +16 -0
  314. package/dist/wire.d.ts +220 -36
  315. package/dist/wire.d.ts.map +1 -1
  316. package/dist/wire.js +73 -33
  317. package/package.json +19 -19
  318. package/AGENTS.md +0 -296
  319. package/dist/attempt.d.ts +0 -16
  320. package/dist/attempt.d.ts.map +0 -1
  321. package/dist/attempt.js +0 -70
  322. package/dist/chat/acts.d.ts +0 -33
  323. package/dist/chat/acts.d.ts.map +0 -1
  324. package/dist/chat/acts.js +0 -36
  325. package/dist/chat/context.d.ts +0 -3
  326. package/dist/chat/context.d.ts.map +0 -1
  327. package/dist/chat/input.d.ts +0 -9
  328. package/dist/chat/input.d.ts.map +0 -1
  329. package/dist/chat/input.js +0 -99
  330. package/dist/chat/kit.d.ts +0 -60
  331. package/dist/chat/kit.d.ts.map +0 -1
  332. package/dist/chat/kit.js +0 -123
  333. package/dist/chat/lasting.d.ts +0 -6
  334. package/dist/chat/lasting.d.ts.map +0 -1
  335. package/dist/chat/lasting.js +0 -19
  336. package/dist/chat/list.d.ts +0 -26
  337. package/dist/chat/list.d.ts.map +0 -1
  338. package/dist/chat/list.js +0 -62
  339. package/dist/chat/markdown.d.ts +0 -20
  340. package/dist/chat/markdown.d.ts.map +0 -1
  341. package/dist/chat/markdown.js +0 -188
  342. package/dist/chat/message.d.ts +0 -6
  343. package/dist/chat/message.d.ts.map +0 -1
  344. package/dist/chat/message.js +0 -192
  345. package/dist/chat/messages.d.ts +0 -21
  346. package/dist/chat/messages.d.ts.map +0 -1
  347. package/dist/chat/messages.js +0 -151
  348. package/dist/chat/name.d.ts +0 -6
  349. package/dist/chat/name.d.ts.map +0 -1
  350. package/dist/chat/name.js +0 -37
  351. package/dist/chat/opened.d.ts +0 -11
  352. package/dist/chat/opened.d.ts.map +0 -1
  353. package/dist/chat/opened.js +0 -17
  354. package/dist/chat/overlay.d.ts +0 -31
  355. package/dist/chat/overlay.d.ts.map +0 -1
  356. package/dist/chat/overlay.js +0 -97
  357. package/dist/chat/parts.d.ts +0 -57
  358. package/dist/chat/parts.d.ts.map +0 -1
  359. package/dist/chat/parts.js +0 -119
  360. package/dist/chat/process.d.ts +0 -20
  361. package/dist/chat/process.d.ts.map +0 -1
  362. package/dist/chat/process.js +0 -32
  363. package/dist/chat/provider.d.ts +0 -63
  364. package/dist/chat/provider.d.ts.map +0 -1
  365. package/dist/chat/provider.js +0 -620
  366. package/dist/chat/question.d.ts +0 -9
  367. package/dist/chat/question.d.ts.map +0 -1
  368. package/dist/chat/question.js +0 -80
  369. package/dist/chat/questions.d.ts.map +0 -1
  370. package/dist/chat/read.d.ts.map +0 -1
  371. package/dist/chat/ready.d.ts +0 -33
  372. package/dist/chat/ready.d.ts.map +0 -1
  373. package/dist/chat/ready.js +0 -91
  374. package/dist/chat/style.d.ts +0 -4
  375. package/dist/chat/style.d.ts.map +0 -1
  376. package/dist/chat/style.js +0 -302
  377. package/dist/chat.d.ts +0 -14
  378. package/dist/chat.d.ts.map +0 -1
  379. package/dist/chat.js +0 -8
  380. package/dist/fence.d.ts +0 -6
  381. package/dist/fence.d.ts.map +0 -1
  382. package/dist/fence.js +0 -10
  383. package/dist/read-side.d.ts +0 -25
  384. package/dist/read-side.d.ts.map +0 -1
  385. package/dist/read-side.js +0 -639
@@ -1,60 +1,68 @@
1
- import { apply, equalValue, frontmatterValue, parse, serialize } from '@agentshouse/mdmodel';
1
+ import { apply, create, equalValue, frontmatterValue, parse, serialize, } from '@agentshouse/mdmodel';
2
2
  import { runtimeError } from './failure.js';
3
- import { hexDigest } from './file.js';
3
+ import { sha256 } from './digest.js';
4
4
  import { binaryLocalId } from './identity.js';
5
5
  import { normalize } from './paths.js';
6
- export function returnedBy(kind) {
7
- return { kind, code: kind, fields: {}, retryable: false };
6
+ export function returnedBy() {
7
+ return { kind: 'withdrawn', code: 'withdrawn', fields: {}, retryable: false };
8
8
  }
9
9
  export function staleWrite(current) {
10
- return { outcome: 'stale', code: 'stale', retryable: false, current };
10
+ return { outcome: 'stale', current };
11
11
  }
12
- function malformed() {
13
- throw runtimeError('room-draft-malformed');
12
+ function malformed(at, needs) {
13
+ throw runtimeError('room-draft-malformed', at === undefined ? 'room-draft-malformed' : `room-draft-malformed at ${at}: ${needs}`);
14
14
  }
15
15
  function plain(value) {
16
16
  return typeof value === 'object' && value !== null && !Array.isArray(value);
17
17
  }
18
- function text(value) {
19
- return typeof value === 'string' ? value : malformed();
18
+ function text(value, at) {
19
+ return typeof value === 'string' ? value : malformed(at, 'text');
20
20
  }
21
- function optionalText(value) {
22
- return value === undefined ? undefined : text(value);
21
+ function optionalText(value, at) {
22
+ return value === undefined ? undefined : text(value, at);
23
23
  }
24
- function markdownBase(value) {
25
- return value === null ? null : optionalText(value);
24
+ function markdownBase(value, at) {
25
+ return value === null ? null : optionalText(value, at);
26
26
  }
27
- function entries(value, each) {
27
+ function entries(value, at, each) {
28
28
  if (!plain(value))
29
- malformed();
29
+ malformed(at, 'an object of named values');
30
30
  const read = {};
31
31
  for (const [name, item] of Object.entries(value))
32
- read[name] = each(item);
32
+ read[name] = each(item, `${at}.${name}`);
33
33
  return read;
34
34
  }
35
- function fieldValue(value) {
35
+ function frontmatter(item, at) {
36
+ return frontmatterValue(item) ? item : malformed(at, 'a frontmatter value');
37
+ }
38
+ function fieldValue(value, at) {
36
39
  if (value === null)
37
40
  return null;
38
41
  if (!plain(value) || !Object.hasOwn(value, 'value') || !frontmatterValue(value.value)) {
39
- malformed();
42
+ malformed(at, '{ value } with a frontmatter value, or null where the document lacks it');
40
43
  }
41
44
  return { value: value.value };
42
45
  }
43
- function textPart(value) {
46
+ function textPart(value, at) {
44
47
  if (!plain(value))
45
- malformed();
46
- const base = optionalText(value.base);
47
- return { value: text(value.value), ...(base === undefined ? {} : { base }) };
48
+ malformed(at, '{ value, base }');
49
+ const base = optionalText(value.base, `${at}.base`);
50
+ return { value: text(value.value, `${at}.value`), ...(base === undefined ? {} : { base }) };
48
51
  }
49
- function creationOf(value) {
52
+ function creationOf(value, at) {
50
53
  if (!plain(value))
51
- malformed();
54
+ malformed(at, '{ type, fields, sections }, or { markdown }');
52
55
  if (Object.hasOwn(value, 'markdown'))
53
- return { markdown: text(value.markdown) };
54
- const fields = entries(value.fields, (item) => (frontmatterValue(item) ? item : malformed()));
55
- return { type: text(value.type), fields, sections: entries(value.sections, text) };
56
+ return { markdown: text(value.markdown, `${at}.markdown`) };
57
+ if (typeof value.type !== 'string')
58
+ malformed(`${at}.type`, 'a type name, or markdown in place of type, fields and sections');
59
+ return {
60
+ type: value.type,
61
+ fields: entries(value.fields, `${at}.fields`, frontmatter),
62
+ sections: entries(value.sections, `${at}.sections`, text),
63
+ };
56
64
  }
57
- const PART_NAMES = new Set([
65
+ const PART_NAMES = [
58
66
  'fields',
59
67
  'sections',
60
68
  'preamble',
@@ -63,47 +71,57 @@ const PART_NAMES = new Set([
63
71
  'move',
64
72
  'removal',
65
73
  'file',
66
- ]);
67
- export function readParts(value) {
68
- if (!plain(value) || Object.keys(value).some((name) => !PART_NAMES.has(name)))
69
- malformed();
74
+ ];
75
+ const NAMED_PARTS = `a part named ${PART_NAMES.slice(0, -1).join(', ')} or ${PART_NAMES.at(-1)}`;
76
+ export function readParts(value, path) {
77
+ if (!plain(value))
78
+ malformed(path, 'an object of parts');
79
+ const unknown = Object.keys(value).find((name) => !PART_NAMES.includes(name));
80
+ if (unknown !== undefined)
81
+ malformed(`${path} ${unknown}`, NAMED_PARTS);
70
82
  const parts = {};
71
83
  if (value.fields !== undefined) {
72
- parts.fields = entries(value.fields, (item) => {
84
+ parts.fields = entries(value.fields, `${path} fields`, (item, at) => {
73
85
  if (!plain(item) || !Object.hasOwn(item, 'value') || !frontmatterValue(item.value)) {
74
- malformed();
86
+ malformed(at, '{ value, base } with a frontmatter value');
75
87
  }
76
88
  return item.base === undefined
77
89
  ? { value: item.value }
78
- : { value: item.value, base: fieldValue(item.base) };
90
+ : { value: item.value, base: fieldValue(item.base, `${at}.base`) };
79
91
  });
80
92
  }
81
93
  if (value.sections !== undefined)
82
- parts.sections = entries(value.sections, textPart);
94
+ parts.sections = entries(value.sections, `${path} sections`, textPart);
83
95
  if (value.preamble !== undefined)
84
- parts.preamble = textPart(value.preamble);
96
+ parts.preamble = textPart(value.preamble, `${path} preamble`);
85
97
  if (value.markdown !== undefined)
86
- parts.markdown = textPart(value.markdown);
98
+ parts.markdown = textPart(value.markdown, `${path} markdown`);
87
99
  if (value.creation !== undefined)
88
- parts.creation = creationOf(value.creation);
100
+ parts.creation = creationOf(value.creation, `${path} creation`);
89
101
  if (value.move !== undefined) {
90
102
  if (!plain(value.move))
91
- malformed();
92
- const base = markdownBase(value.move.base);
93
- parts.move = { to: text(value.move.to), ...(base === undefined ? {} : { base }) };
103
+ malformed(`${path} move`, '{ to, room, base }');
104
+ const base = markdownBase(value.move.base, `${path} move.base`);
105
+ const room = optionalText(value.move.room, `${path} move.room`);
106
+ parts.move = {
107
+ to: text(value.move.to, `${path} move.to`),
108
+ ...(room === undefined ? {} : { room }),
109
+ ...(base === undefined ? {} : { base }),
110
+ };
94
111
  }
95
112
  if (value.removal !== undefined) {
96
113
  if (!plain(value.removal))
97
- malformed();
98
- const base = markdownBase(value.removal.base);
114
+ malformed(`${path} removal`, '{ base }');
115
+ const base = markdownBase(value.removal.base, `${path} removal.base`);
99
116
  parts.removal = base === undefined ? {} : { base };
100
117
  }
101
118
  if (value.file !== undefined) {
102
119
  if (!plain(value.file) || !(value.file.blob instanceof Blob))
103
- malformed();
120
+ malformed(`${path} file`, '{ blob, base } with a Blob');
104
121
  if (Object.keys(value).length > 1)
105
122
  throw runtimeError('room-draft-file-exclusive');
106
- parts.file = { blob: value.file.blob };
123
+ const base = markdownBase(value.file.base, `${path} file.base`);
124
+ parts.file = base === undefined ? { blob: value.file.blob } : { blob: value.file.blob, base };
107
125
  }
108
126
  return parts;
109
127
  }
@@ -120,11 +138,51 @@ function kept(prior, base) {
120
138
  throw runtimeError('room-draft-base-missing');
121
139
  return base;
122
140
  }
141
+ function movePart(current, move) {
142
+ return {
143
+ to: move.to,
144
+ ...(move.room === undefined ? {} : { room: move.room }),
145
+ base: kept(current, move.base),
146
+ };
147
+ }
123
148
  function editsText(parts) {
124
149
  return (parts.preamble !== undefined ||
125
150
  named(parts.fields).length > 0 ||
126
151
  named(parts.sections).length > 0);
127
152
  }
153
+ function partNames(parts) {
154
+ const names = [];
155
+ for (const [name, part] of Object.entries(parts)) {
156
+ if (name === 'preamble' || name === 'markdown')
157
+ names.push(name);
158
+ else if ((name === 'fields' || name === 'sections') && plain(part))
159
+ names.push(...Object.keys(part).map((one) => `${name}/${one}`));
160
+ else
161
+ return null;
162
+ }
163
+ return names.sort().join('\u0000');
164
+ }
165
+ function withBaseOf(prior, part) {
166
+ return plain(part) && plain(prior) && Object.hasOwn(prior, 'base')
167
+ ? { ...part, base: prior.base }
168
+ : part;
169
+ }
170
+ export function gatheredParts(earlier, later) {
171
+ if (!plain(earlier) || !plain(later))
172
+ return null;
173
+ const named = partNames(earlier);
174
+ if (named === null || named !== partNames(later))
175
+ return null;
176
+ return Object.fromEntries(Object.entries(later).map(([name, part]) => [
177
+ name,
178
+ name === 'fields' || name === 'sections'
179
+ ? Object.fromEntries(Object.entries(part).map(([one, value]) => [
180
+ one,
181
+ withBaseOf(earlier[name][one], value),
182
+ ]))
183
+ : withBaseOf(earlier[name], part),
184
+ ]));
185
+ }
128
186
  export function held(current, parts, file) {
129
187
  if (parts.markdown !== undefined && editsText(parts)) {
130
188
  throw runtimeError('room-draft-markdown-exclusive');
@@ -144,9 +202,7 @@ export function held(current, parts, file) {
144
202
  }
145
203
  return {
146
204
  file: current.file,
147
- ...(parts.move === undefined
148
- ? {}
149
- : { move: { to: parts.move.to, base: kept(current.move, parts.move.base) } }),
205
+ ...(parts.move === undefined ? {} : { move: movePart(current.move, parts.move) }),
150
206
  ...(parts.removal === undefined
151
207
  ? {}
152
208
  : { removal: { base: kept(current.removal, parts.removal.base) } }),
@@ -181,9 +237,8 @@ export function held(current, parts, file) {
181
237
  }
182
238
  if (parts.creation !== undefined)
183
239
  next.creation = parts.creation;
184
- if (parts.move !== undefined) {
185
- next.move = { to: parts.move.to, base: kept(current?.move, parts.move.base) };
186
- }
240
+ if (parts.move !== undefined)
241
+ next.move = movePart(current?.move, parts.move);
187
242
  if (parts.removal !== undefined) {
188
243
  next.removal = { base: kept(current?.removal, parts.removal.base) };
189
244
  }
@@ -240,29 +295,32 @@ export function underneath(parts, path, visible) {
240
295
  }
241
296
  const UNTYPED_MEDIA_TYPE = 'application/octet-stream';
242
297
  export async function heldFile(blob, base) {
243
- const bytes = await blob.arrayBuffer();
244
298
  return {
245
- blob,
246
299
  localId: binaryLocalId(),
247
- byteLength: bytes.byteLength,
300
+ ...(blob instanceof File ? { name: blob.name } : {}),
301
+ byteLength: blob.size,
248
302
  mediaType: blob.type === '' ? UNTYPED_MEDIA_TYPE : blob.type,
249
- sha256: hexDigest(await crypto.subtle.digest('SHA-256', bytes)),
303
+ sha256: await sha256(blob),
250
304
  base,
251
305
  };
252
306
  }
253
307
  export function binaryBase(visible, path) {
254
- return visible?.binaries[path] === undefined ? null : (visible.revisions[path] ?? null);
308
+ const binary = visible?.binaries[path];
309
+ if (binary === undefined)
310
+ return null;
311
+ return visible?.revisions[path] ?? (binary.state === 'pending' ? binary.localId : null);
255
312
  }
256
- export function changedParts(path, report) {
313
+ export function changedParts(path, parts, visible) {
314
+ const report = underneath(parts, path, visible);
315
+ const made = parts.file?.base === null;
257
316
  return [
258
- ...(report.creation === undefined ? [] : [{ path, part: 'creation' }]),
259
317
  ...named(report.fields).map(([name]) => ({ path, part: 'field', name })),
260
318
  ...named(report.sections).map(([name]) => ({ path, part: 'section', name })),
261
319
  ...(report.preamble === undefined ? [] : [{ path, part: 'preamble' }]),
262
320
  ...(report.markdown === undefined ? [] : [{ path, part: 'markdown' }]),
263
321
  ...(report.move === undefined ? [] : [{ path, part: 'move' }]),
264
322
  ...(report.removal === undefined ? [] : [{ path, part: 'removal' }]),
265
- ...(report.file === undefined ? [] : [{ path, part: 'file' }]),
323
+ ...(report.file === undefined || made ? [] : [{ path, part: 'file' }]),
266
324
  ];
267
325
  }
268
326
  function joined(existing, returned) {
@@ -272,34 +330,46 @@ function joined(existing, returned) {
272
330
  merged[name] = part;
273
331
  return Object.keys(merged).length === 0 ? undefined : merged;
274
332
  }
275
- function ended(text) {
333
+ export function lineEnded(text) {
276
334
  return text === '' || text.endsWith('\n') ? text : `${text}\n`;
277
335
  }
278
- function frontmatterOf(fields) {
279
- const opened = parse('---\n---\n');
280
- if (!opened.ok)
281
- return malformed();
282
- let document = opened.document;
283
- for (const [name, part] of fields) {
284
- const next = apply(document, { kind: 'field', name, value: part.value, prior: undefined });
285
- if (next.outcome !== 'applied')
286
- return malformed();
287
- document = next.document;
288
- }
289
- return serialize(document);
336
+ function written(start, changes, definition) {
337
+ const next = apply(start, changes, definition);
338
+ return next.outcome === 'applied' ? serialize(next.document) : malformed();
290
339
  }
291
- function concatenated(markdown, parts) {
340
+ function empty(definition) {
341
+ const parsed = parse('', '', definition);
342
+ return parsed.ok ? parsed.document : malformed();
343
+ }
344
+ export function partsAfter(markdown, parts, definitions) {
292
345
  const fields = named(parts.fields);
346
+ const sections = named(parts.sections);
347
+ if (fields.length === 0 && sections.length === 0 && parts.preamble === undefined)
348
+ return markdown;
349
+ const whole = parse(markdown, '', definitions);
350
+ const definition = whole.ok ? definitions?.(whole.document.type) : undefined;
351
+ const head = [
352
+ ...fields.map(([name, part]) => ({
353
+ kind: 'field',
354
+ name,
355
+ value: part.value,
356
+ prior: undefined,
357
+ })),
358
+ ...(parts.preamble === undefined
359
+ ? []
360
+ : [{ kind: 'preamble', value: lineEnded(parts.preamble.value), prior: '' }]),
361
+ ];
293
362
  const pieces = [
294
- ...(fields.length === 0 ? [] : [frontmatterOf(fields)]),
295
- ...(parts.preamble === undefined ? [] : [parts.preamble.value]),
296
- ...named(parts.sections).map(([name, part]) => `## ${name}\n${part.value}`),
363
+ ...(head.length === 0
364
+ ? []
365
+ : [
366
+ written(fields.length === 0 ? empty(definition) : create(undefined, definition), head, definition),
367
+ ]),
368
+ ...sections.map(([name, part]) => written(empty(definition), [{ kind: 'section', name, value: lineEnded(part.value), prior: undefined }], definition)),
297
369
  ];
298
- if (pieces.length === 0)
299
- return markdown;
300
- return `${ended(markdown)}\n${pieces.map(ended).join('')}`;
370
+ return `${lineEnded(markdown)}\n${pieces.join('')}`;
301
371
  }
302
- export function returnedInto(existing, returned) {
372
+ export function returnedInto(existing, returned, definitions) {
303
373
  if (existing === undefined)
304
374
  return returned;
305
375
  const next = { ...existing };
@@ -319,7 +389,7 @@ export function returnedInto(existing, returned) {
319
389
  delete next.fields;
320
390
  delete next.sections;
321
391
  delete next.preamble;
322
- const value = concatenated(whole.value, existing.markdown === undefined ? existing : returned);
392
+ const value = partsAfter(whole.value, existing.markdown === undefined ? existing : returned, definitions);
323
393
  next.markdown = { value, base: whole.base };
324
394
  }
325
395
  const creation = existing.creation ?? returned.creation;
@@ -340,6 +410,36 @@ export function moveTarget(move) {
340
410
  const to = normalize(move.to);
341
411
  return to === null || to === '' ? move.to : to;
342
412
  }
413
+ export function readSavedParts(named) {
414
+ const read = named.map(({ path, parts }) => ({ path, parts: readParts(parts, path) }));
415
+ read.forEach(({ path }, at) => {
416
+ if (path === '' || normalize(path) !== path)
417
+ malformed(path, 'a path inside the Room, such as notes/a.md');
418
+ if (read.findIndex((one) => one.path === path) !== at)
419
+ malformed(path, 'each path once in one save');
420
+ });
421
+ return read;
422
+ }
423
+ export function partsChanges(named) {
424
+ const changes = [];
425
+ const preconditions = [];
426
+ for (const { path, parts } of readSavedParts(named)) {
427
+ const parted = held(undefined, parts);
428
+ const made = changesOf(path, parted);
429
+ changes.push(...made.changes);
430
+ preconditions.push(...made.bases);
431
+ for (const change of made.changes) {
432
+ if (change.kind === 'create')
433
+ preconditions.push({ kind: 'absent', path });
434
+ if (change.kind === 'move')
435
+ preconditions.push({ kind: 'absent', path: change.to });
436
+ }
437
+ const revision = parted.markdown?.base ?? parted.move?.base ?? parted.removal?.base;
438
+ if (typeof revision === 'string')
439
+ preconditions.push({ kind: 'revision', path, revision });
440
+ }
441
+ return { changes, preconditions };
442
+ }
343
443
  export function changesOf(path, parts) {
344
444
  const changes = [];
345
445
  const bases = [];
@@ -359,23 +459,23 @@ export function changesOf(path, parts) {
359
459
  bases.push({ kind: 'field', path, name, value: part.base?.value });
360
460
  }
361
461
  for (const [name, part] of named(parts.sections)) {
362
- changes.push({ kind: 'section', path, name, value: part.value });
462
+ changes.push({ kind: 'section', path, name, value: lineEnded(part.value) });
363
463
  bases.push({ kind: 'section', path, name, value: part.base });
364
464
  }
365
465
  if (parts.preamble !== undefined) {
366
- changes.push({ kind: 'preamble', path, value: parts.preamble.value });
466
+ changes.push({ kind: 'preamble', path, value: lineEnded(parts.preamble.value) });
367
467
  bases.push({ kind: 'preamble', path, value: parts.preamble.base });
368
468
  }
369
469
  if (parts.markdown !== undefined) {
370
470
  changes.push({ kind: 'replace', path, content: parts.markdown.value });
371
471
  }
372
472
  if (parts.file !== undefined && parts.removal === undefined) {
373
- const { base, ...file } = parts.file;
473
+ const { base, name: _name, ...file } = parts.file;
374
474
  const at = parts.move === undefined ? path : moveTarget(parts.move);
375
475
  if (base !== null && at !== path)
376
476
  changes.push({ kind: 'move', path, to: at });
377
477
  changes.push({ kind: 'binary', path: at, ...file });
378
- if (base === null && at !== path)
478
+ if (base === null)
379
479
  bases.push({ kind: 'absent', path: at });
380
480
  return { changes, bases };
381
481
  }
@@ -387,35 +487,6 @@ export function changesOf(path, parts) {
387
487
  changes.push({ kind: 'remove', path });
388
488
  return { changes, bases };
389
489
  }
390
- function rebased(before, after) {
391
- return before === undefined ? after : { ...after, base: before.base };
392
- }
393
- function rebasedAll(before, after) {
394
- return {
395
- ...before,
396
- ...Object.fromEntries(Object.entries(after).map(([name, part]) => [name, rebased(before?.[name], part)])),
397
- };
398
- }
399
- export function joinedDraft(carried, saved) {
400
- const draft = saved.find((item) => item.path === carried.path);
401
- if (draft === undefined)
402
- return carried;
403
- const held = carried.parts;
404
- const next = draft.parts;
405
- return {
406
- path: carried.path,
407
- parts: {
408
- ...held,
409
- ...next,
410
- ...(next.fields === undefined ? {} : { fields: rebasedAll(held.fields, next.fields) }),
411
- ...(next.sections === undefined
412
- ? {}
413
- : { sections: rebasedAll(held.sections, next.sections) }),
414
- ...(next.preamble === undefined ? {} : { preamble: rebased(held.preamble, next.preamble) }),
415
- ...(next.markdown === undefined ? {} : { markdown: rebased(held.markdown, next.markdown) }),
416
- },
417
- };
418
- }
419
490
  export function withdrawnDrafts(drafts, changes) {
420
491
  return drafts.flatMap((draft) => {
421
492
  const file = draft.parts.file;
@@ -0,0 +1,24 @@
1
+ import { type ChangeSet } from './change-set.js';
2
+ import { type VisibleLayer } from './replica.js';
3
+ import { type RoomDraft, type RoomDraftWrite } from './room-draft.js';
4
+ import type { Runtime } from './runtime.js';
5
+ import type { Store } from './store.js';
6
+ export type RoomDraftSurface = {
7
+ list(): Promise<readonly RoomDraft[]>;
8
+ read(room: string, path: string): Promise<RoomDraft | null>;
9
+ write(room: string, path: string, revision: string | null, parts: unknown, next?: string): Promise<RoomDraftWrite>;
10
+ discard(room: string, path: string, revision: string): Promise<RoomDraftWrite>;
11
+ };
12
+ export type PresentationSurface = {
13
+ read(app: string): Promise<unknown>;
14
+ write(app: string, value: unknown): Promise<void>;
15
+ edit(app: string, members: Readonly<Record<string, unknown>>): Promise<void>;
16
+ };
17
+ export declare function visibleOf(store: Store, locator: string, paths: readonly string[]): Promise<VisibleLayer | undefined>;
18
+ export declare function publishRoomDrafts({ store, socket }: Runtime, waitingOnly: boolean, touched?: ChangeSet['documents'] | null): Promise<void>;
19
+ export declare function emitPresentation({ store, socket }: Runtime, app: string): Promise<void>;
20
+ export declare function roomDraftSurface(runtime: Runtime): RoomDraftSurface;
21
+ export declare function presentationSurface(runtime: Runtime): PresentationSurface;
22
+ export declare function watchRoomDrafts({ store, socket }: Runtime, deliver: (value: unknown) => void): () => void;
23
+ export declare function watchPresentation({ store, socket }: Runtime, app: string, deliver: (value: unknown) => void): () => void;
24
+ //# sourceMappingURL=room-drafts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"room-drafts.d.ts","sourceRoot":"","sources":["../src/room-drafts.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAK5D,OAAO,EAAW,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAQL,KAAK,SAAS,EAEd,KAAK,cAAc,EACpB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAGxC,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,IAAI,OAAO,CAAC,SAAS,SAAS,EAAE,CAAC,CAAC;IACtC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC;IAC5D,KAAK,CACH,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,GAAG,IAAI,EACvB,KAAK,EAAE,OAAO,EACd,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,cAAc,CAAC,CAAC;IAC3B,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;CAChF,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACpC,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClD,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9E,CAAC;AAMF,wBAAsB,SAAS,CAC7B,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,SAAS,MAAM,EAAE,GACvB,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,CAMnC;AA0CD,wBAAgB,iBAAiB,CAC/B,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,OAAO,EAC1B,WAAW,EAAE,OAAO,EACpB,OAAO,GAAE,SAAS,CAAC,WAAW,CAAC,GAAG,IAAW,GAC5C,OAAO,CAAC,IAAI,CAAC,CAuBf;AAOD,wBAAgB,gBAAgB,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAUvF;AAoDD,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,gBAAgB,CAkDnE;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,mBAAmB,CA8BzE;AAED,wBAAgB,eAAe,CAC7B,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,OAAO,EAC1B,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GAChC,MAAM,IAAI,CAiBZ;AAED,wBAAgB,iBAAiB,CAC/B,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,OAAO,EAC1B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GAChC,MAAM,IAAI,CASZ"}