@aionbuilders/nabu 0.1.0-alpha.9 → 0.1.0

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 (319) hide show
  1. package/CHANGELOG.md +523 -0
  2. package/LICENSE +21 -0
  3. package/README.md +82 -144
  4. package/dist/behaviors/text/RichText.svelte +25 -2
  5. package/dist/behaviors/text/index.d.ts +2 -0
  6. package/dist/behaviors/text/index.js +2 -0
  7. package/dist/behaviors/text/markdown-shortcuts.extension.d.ts +5 -0
  8. package/dist/behaviors/text/markdown-shortcuts.extension.js +79 -0
  9. package/dist/behaviors/text/markdown-syntax.d.ts +42 -0
  10. package/dist/behaviors/text/markdown-syntax.js +81 -0
  11. package/dist/behaviors/text/rich-text.extension.d.ts +3 -0
  12. package/dist/behaviors/text/rich-text.extension.js +135 -53
  13. package/dist/behaviors/text/text.behavior.svelte.d.ts +217 -42
  14. package/dist/behaviors/text/text.behavior.svelte.js +657 -55
  15. package/dist/behaviors/text/typography.extension.d.ts +7 -0
  16. package/dist/behaviors/text/typography.extension.js +25 -0
  17. package/dist/blocks/Block.svelte +5 -2
  18. package/dist/blocks/BlockList.svelte +48 -0
  19. package/dist/blocks/BlockList.svelte.d.ts +17 -0
  20. package/dist/blocks/Nabu.svelte +180 -14
  21. package/dist/blocks/Nabu.svelte.d.ts +13 -0
  22. package/dist/blocks/block.extension.d.ts +3 -0
  23. package/dist/blocks/block.extension.js +8 -9
  24. package/dist/blocks/block.svelte.d.ts +356 -68
  25. package/dist/blocks/block.svelte.js +388 -42
  26. package/dist/blocks/blockquote/Blockquote.svelte +39 -0
  27. package/dist/blocks/blockquote/Blockquote.svelte.d.ts +11 -0
  28. package/dist/blocks/blockquote/blockquote.extension.d.ts +4 -0
  29. package/dist/blocks/blockquote/blockquote.extension.js +80 -0
  30. package/dist/blocks/blockquote/blockquote.svelte.d.ts +63 -0
  31. package/dist/blocks/blockquote/blockquote.svelte.js +136 -0
  32. package/dist/blocks/blockquote/index.d.ts +3 -0
  33. package/dist/blocks/blockquote/index.js +3 -0
  34. package/dist/blocks/callout/Callout.svelte +67 -0
  35. package/dist/blocks/callout/Callout.svelte.d.ts +11 -0
  36. package/dist/blocks/callout/callout.extension.d.ts +4 -0
  37. package/dist/blocks/callout/callout.extension.js +84 -0
  38. package/dist/blocks/callout/callout.svelte.d.ts +80 -0
  39. package/dist/blocks/callout/callout.svelte.js +189 -0
  40. package/dist/blocks/callout/index.d.ts +3 -0
  41. package/dist/blocks/callout/index.js +3 -0
  42. package/dist/blocks/chunks.d.ts +49 -0
  43. package/dist/blocks/chunks.js +90 -0
  44. package/dist/blocks/code/Code.svelte +84 -0
  45. package/dist/blocks/code/Code.svelte.d.ts +11 -0
  46. package/dist/blocks/code/code.extension.d.ts +4 -0
  47. package/dist/blocks/code/code.extension.js +88 -0
  48. package/dist/blocks/code/code.svelte.d.ts +68 -0
  49. package/dist/blocks/code/code.svelte.js +245 -0
  50. package/dist/blocks/code/index.d.ts +3 -0
  51. package/dist/blocks/code/index.js +3 -0
  52. package/dist/blocks/container.utils.d.ts +85 -13
  53. package/dist/blocks/container.utils.js +338 -178
  54. package/dist/blocks/dialogue/Dialogue.svelte +8 -2
  55. package/dist/blocks/dialogue/dialogue.svelte.d.ts +36 -23
  56. package/dist/blocks/dialogue/dialogue.svelte.js +51 -45
  57. package/dist/blocks/dialogue/hooks/onBeforeInput.hook.d.ts +2 -2
  58. package/dist/blocks/dialogue/hooks/onBeforeInput.hook.js +6 -4
  59. package/dist/blocks/dialogue/index.d.ts +12 -1
  60. package/dist/blocks/dialogue/index.js +51 -35
  61. package/dist/blocks/divider/Divider.svelte +28 -0
  62. package/dist/blocks/divider/Divider.svelte.d.ts +11 -0
  63. package/dist/blocks/divider/divider.extension.d.ts +23 -0
  64. package/dist/blocks/divider/divider.extension.js +153 -0
  65. package/dist/blocks/divider/divider.svelte.d.ts +54 -0
  66. package/dist/blocks/divider/divider.svelte.js +89 -0
  67. package/dist/blocks/divider/index.d.ts +3 -0
  68. package/dist/blocks/divider/index.js +3 -0
  69. package/dist/blocks/file/File.svelte +56 -0
  70. package/dist/blocks/file/File.svelte.d.ts +11 -0
  71. package/dist/blocks/file/file.extension.d.ts +4 -0
  72. package/dist/blocks/file/file.extension.js +27 -0
  73. package/dist/blocks/file/file.svelte.d.ts +29 -0
  74. package/dist/blocks/file/file.svelte.js +77 -0
  75. package/dist/blocks/file/index.d.ts +3 -0
  76. package/dist/blocks/file/index.js +3 -0
  77. package/dist/blocks/heading/Heading.svelte +2 -1
  78. package/dist/blocks/heading/heading.svelte.d.ts +27 -34
  79. package/dist/blocks/heading/heading.svelte.js +72 -60
  80. package/dist/blocks/heading/hooks/onBeforeInput.hook.js +7 -5
  81. package/dist/blocks/heading/index.d.ts +2 -2
  82. package/dist/blocks/heading/index.js +33 -8
  83. package/dist/blocks/image/Image.svelte +41 -0
  84. package/dist/blocks/image/Image.svelte.d.ts +11 -0
  85. package/dist/blocks/image/image.extension.d.ts +5 -0
  86. package/dist/blocks/image/image.extension.js +34 -0
  87. package/dist/blocks/image/image.svelte.d.ts +61 -0
  88. package/dist/blocks/image/image.svelte.js +114 -0
  89. package/dist/blocks/image/index.d.ts +3 -0
  90. package/dist/blocks/image/index.js +3 -0
  91. package/dist/blocks/index.d.ts +11 -1
  92. package/dist/blocks/index.js +11 -1
  93. package/dist/blocks/list/List.svelte +9 -2
  94. package/dist/blocks/list/ListItem.svelte +44 -7
  95. package/dist/blocks/list/convert.d.ts +20 -0
  96. package/dist/blocks/list/convert.js +92 -0
  97. package/dist/blocks/list/hooks/onBeforeInput.hook.js +60 -26
  98. package/dist/blocks/list/html-flat.d.ts +78 -0
  99. package/dist/blocks/list/html-flat.js +244 -0
  100. package/dist/blocks/list/indent.d.ts +86 -0
  101. package/dist/blocks/list/indent.js +205 -0
  102. package/dist/blocks/list/index.d.ts +7 -3
  103. package/dist/blocks/list/index.js +43 -31
  104. package/dist/blocks/list/list-item.svelte.d.ts +43 -17
  105. package/dist/blocks/list/list-item.svelte.js +143 -93
  106. package/dist/blocks/list/list.behavior.svelte.d.ts +7 -4
  107. package/dist/blocks/list/list.behavior.svelte.js +10 -5
  108. package/dist/blocks/list/list.svelte.d.ts +101 -23
  109. package/dist/blocks/list/list.svelte.js +136 -114
  110. package/dist/blocks/list/markdown.d.ts +149 -0
  111. package/dist/blocks/list/markdown.js +442 -0
  112. package/dist/blocks/list/normalize.d.ts +11 -0
  113. package/dist/blocks/list/normalize.js +396 -0
  114. package/dist/blocks/list/paste.d.ts +45 -0
  115. package/dist/blocks/list/paste.js +242 -0
  116. package/dist/blocks/list/step-back.d.ts +24 -0
  117. package/dist/blocks/list/step-back.js +87 -0
  118. package/dist/blocks/list/to-list.d.ts +7 -0
  119. package/dist/blocks/list/to-list.js +44 -0
  120. package/dist/blocks/list/todos-toggle.d.ts +20 -0
  121. package/dist/blocks/list/todos-toggle.js +48 -0
  122. package/dist/blocks/list/todos.svelte.d.ts +35 -0
  123. package/dist/blocks/list/todos.svelte.js +76 -0
  124. package/dist/blocks/media/index.d.ts +2 -0
  125. package/dist/blocks/media/index.js +2 -0
  126. package/dist/blocks/media/markdown.d.ts +12 -0
  127. package/dist/blocks/media/markdown.js +26 -0
  128. package/dist/blocks/media/media-block.svelte.d.ts +107 -0
  129. package/dist/blocks/media/media-block.svelte.js +181 -0
  130. package/dist/blocks/media/media.helpers.d.ts +24 -0
  131. package/dist/blocks/media/media.helpers.js +88 -0
  132. package/dist/blocks/megablock.svelte.d.ts +50 -19
  133. package/dist/blocks/megablock.svelte.js +115 -74
  134. package/dist/blocks/move.d.ts +23 -0
  135. package/dist/blocks/move.js +92 -0
  136. package/dist/blocks/nabu.svelte.d.ts +846 -75
  137. package/dist/blocks/nabu.svelte.js +1990 -182
  138. package/dist/blocks/paragraph/Paragraph.svelte +1 -0
  139. package/dist/blocks/paragraph/index.d.ts +2 -2
  140. package/dist/blocks/paragraph/index.js +35 -16
  141. package/dist/blocks/paragraph/paragraph.svelte.d.ts +49 -35
  142. package/dist/blocks/paragraph/paragraph.svelte.js +81 -69
  143. package/dist/blocks/paragraph/table.html.d.ts +9 -0
  144. package/dist/blocks/paragraph/table.html.js +111 -0
  145. package/dist/blocks/paragraph/table.markdown.d.ts +32 -0
  146. package/dist/blocks/paragraph/table.markdown.js +90 -0
  147. package/dist/blocks/region/Region.svelte +264 -0
  148. package/dist/blocks/region/Region.svelte.d.ts +11 -0
  149. package/dist/blocks/region/actions.d.ts +135 -0
  150. package/dist/blocks/region/actions.js +402 -0
  151. package/dist/blocks/region/close.d.ts +35 -0
  152. package/dist/blocks/region/close.js +130 -0
  153. package/dist/blocks/region/commands.d.ts +6 -0
  154. package/dist/blocks/region/commands.js +277 -0
  155. package/dist/blocks/region/create.d.ts +72 -0
  156. package/dist/blocks/region/create.js +208 -0
  157. package/dist/blocks/region/end-marker.d.ts +35 -0
  158. package/dist/blocks/region/end-marker.js +51 -0
  159. package/dist/blocks/region/facts.d.ts +69 -0
  160. package/dist/blocks/region/facts.js +152 -0
  161. package/dist/blocks/region/format.d.ts +91 -0
  162. package/dist/blocks/region/format.js +260 -0
  163. package/dist/blocks/region/index.d.ts +14 -0
  164. package/dist/blocks/region/index.js +14 -0
  165. package/dist/blocks/region/insert.d.ts +59 -0
  166. package/dist/blocks/region/insert.js +102 -0
  167. package/dist/blocks/region/messages.d.ts +254 -0
  168. package/dist/blocks/region/messages.js +131 -0
  169. package/dist/blocks/region/normalize.d.ts +7 -0
  170. package/dist/blocks/region/normalize.js +170 -0
  171. package/dist/blocks/region/region.extension.d.ts +58 -0
  172. package/dist/blocks/region/region.extension.js +119 -0
  173. package/dist/blocks/region/region.svelte.d.ts +221 -0
  174. package/dist/blocks/region/region.svelte.js +582 -0
  175. package/dist/blocks/region/regions.svelte.d.ts +141 -0
  176. package/dist/blocks/region/regions.svelte.js +276 -0
  177. package/dist/blocks/region/serialize.d.ts +57 -0
  178. package/dist/blocks/region/serialize.js +112 -0
  179. package/dist/blocks/region/types.d.ts +255 -0
  180. package/dist/blocks/region/types.js +204 -0
  181. package/dist/blocks/selection.svelte.d.ts +106 -8
  182. package/dist/blocks/selection.svelte.js +632 -74
  183. package/dist/blocks/subthread.d.ts +80 -0
  184. package/dist/blocks/subthread.js +167 -0
  185. package/dist/blocks/text-block.svelte.d.ts +70 -0
  186. package/dist/blocks/text-block.svelte.js +108 -0
  187. package/dist/blocks/toggle/Toggle.svelte +73 -0
  188. package/dist/blocks/toggle/Toggle.svelte.d.ts +11 -0
  189. package/dist/blocks/toggle/index.d.ts +3 -0
  190. package/dist/blocks/toggle/index.js +3 -0
  191. package/dist/blocks/toggle/markdown.d.ts +20 -0
  192. package/dist/blocks/toggle/markdown.js +112 -0
  193. package/dist/blocks/toggle/toggle.extension.d.ts +4 -0
  194. package/dist/blocks/toggle/toggle.extension.js +18 -0
  195. package/dist/blocks/toggle/toggle.svelte.d.ts +135 -0
  196. package/dist/blocks/toggle/toggle.svelte.js +352 -0
  197. package/dist/blocks/undo-selection.d.ts +175 -0
  198. package/dist/blocks/undo-selection.js +360 -0
  199. package/dist/blocks/video/Video.svelte +42 -0
  200. package/dist/blocks/video/Video.svelte.d.ts +11 -0
  201. package/dist/blocks/video/index.d.ts +3 -0
  202. package/dist/blocks/video/index.js +3 -0
  203. package/dist/blocks/video/video.extension.d.ts +4 -0
  204. package/dist/blocks/video/video.extension.js +27 -0
  205. package/dist/blocks/video/video.svelte.d.ts +29 -0
  206. package/dist/blocks/video/video.svelte.js +80 -0
  207. package/dist/extend.d.ts +55 -0
  208. package/dist/extend.js +88 -0
  209. package/dist/files/assets.clipboard.d.ts +77 -0
  210. package/dist/files/assets.clipboard.js +152 -0
  211. package/dist/files/files.svelte.d.ts +363 -0
  212. package/dist/files/files.svelte.js +897 -0
  213. package/dist/files/index.d.ts +3 -0
  214. package/dist/files/index.js +3 -0
  215. package/dist/files/outbox.d.ts +69 -0
  216. package/dist/files/outbox.js +48 -0
  217. package/dist/files/status.d.ts +65 -0
  218. package/dist/files/status.js +87 -0
  219. package/dist/files/store.d.ts +97 -0
  220. package/dist/files/store.js +65 -0
  221. package/dist/files/uploads.svelte.d.ts +174 -0
  222. package/dist/files/uploads.svelte.js +504 -0
  223. package/dist/index.d.ts +68 -6
  224. package/dist/index.js +117 -7
  225. package/dist/nabu-theme.css +112 -0
  226. package/dist/paste/html.paste.d.ts +74 -3
  227. package/dist/paste/html.paste.js +555 -83
  228. package/dist/paste/markdown-inline.d.ts +86 -0
  229. package/dist/paste/markdown-inline.js +528 -0
  230. package/dist/paste/markdown.paste.d.ts +2 -8
  231. package/dist/paste/markdown.paste.js +78 -94
  232. package/dist/paste/nabu.paste.d.ts +3 -0
  233. package/dist/paste/nabu.paste.js +29 -3
  234. package/dist/paste/plain-text.paste.d.ts +2 -2
  235. package/dist/paste/plain-text.paste.js +3 -3
  236. package/dist/persistence/asset-store.d.ts +51 -0
  237. package/dist/persistence/asset-store.js +103 -0
  238. package/dist/persistence/autosave.d.ts +53 -0
  239. package/dist/persistence/autosave.js +62 -0
  240. package/dist/persistence/compact.d.ts +162 -0
  241. package/dist/persistence/compact.js +141 -0
  242. package/dist/persistence/history.d.ts +77 -0
  243. package/dist/persistence/history.js +176 -0
  244. package/dist/persistence/indexeddb.d.ts +190 -4
  245. package/dist/persistence/indexeddb.js +333 -29
  246. package/dist/persistence/merge.d.ts +38 -0
  247. package/dist/persistence/merge.js +36 -0
  248. package/dist/persistence/outbox.d.ts +25 -0
  249. package/dist/persistence/outbox.js +40 -0
  250. package/dist/persistence/persistence.d.ts +70 -9
  251. package/dist/persistence/persistence.js +507 -35
  252. package/dist/persistence/recovery.d.ts +79 -0
  253. package/dist/persistence/recovery.js +79 -0
  254. package/dist/persistence/release.d.ts +34 -0
  255. package/dist/persistence/release.js +64 -0
  256. package/dist/persistence/state.svelte.d.ts +53 -0
  257. package/dist/persistence/state.svelte.js +48 -0
  258. package/dist/persistence/sync.d.ts +39 -0
  259. package/dist/persistence/sync.js +138 -0
  260. package/dist/persistence/tail.d.ts +42 -0
  261. package/dist/persistence/tail.js +103 -0
  262. package/dist/presets.d.ts +29 -24
  263. package/dist/presets.js +51 -14
  264. package/dist/themes/atelier.css +318 -0
  265. package/dist/ui/CommandChooser.svelte +153 -0
  266. package/dist/ui/CommandChooser.svelte.d.ts +13 -0
  267. package/dist/ui/CommandInvite.svelte +99 -0
  268. package/dist/ui/CommandInvite.svelte.d.ts +12 -0
  269. package/dist/ui/DragHandle.svelte +217 -0
  270. package/dist/ui/DragHandle.svelte.d.ts +11 -0
  271. package/dist/ui/FloatingToolbar.svelte +165 -0
  272. package/dist/ui/FloatingToolbar.svelte.d.ts +27 -0
  273. package/dist/ui/SlashMenu.svelte +215 -0
  274. package/dist/ui/SlashMenu.svelte.d.ts +33 -0
  275. package/dist/ui/anchor.d.ts +112 -0
  276. package/dist/ui/anchor.js +136 -0
  277. package/dist/ui/index.d.ts +10 -0
  278. package/dist/ui/index.js +15 -0
  279. package/dist/ui/slash-menu.svelte.d.ts +112 -0
  280. package/dist/ui/slash-menu.svelte.js +150 -0
  281. package/dist/utils/command-confirm.svelte.d.ts +349 -0
  282. package/dist/utils/command-confirm.svelte.js +673 -0
  283. package/dist/utils/commands.d.ts +328 -0
  284. package/dist/utils/commands.js +416 -0
  285. package/dist/utils/dom-scope.d.ts +14 -0
  286. package/dist/utils/dom-scope.js +20 -0
  287. package/dist/utils/drop.d.ts +160 -0
  288. package/dist/utils/drop.js +305 -0
  289. package/dist/utils/extensions.d.ts +488 -40
  290. package/dist/utils/extensions.js +300 -19
  291. package/dist/utils/html.d.ts +44 -0
  292. package/dist/utils/html.js +183 -0
  293. package/dist/utils/index.d.ts +4 -0
  294. package/dist/utils/index.js +4 -0
  295. package/dist/utils/keys.d.ts +120 -0
  296. package/dist/utils/keys.js +248 -0
  297. package/dist/utils/links.d.ts +22 -0
  298. package/dist/utils/links.js +34 -0
  299. package/dist/utils/placeholders.d.ts +88 -0
  300. package/dist/utils/placeholders.js +91 -0
  301. package/dist/utils/selection.svelte.d.ts +47 -19
  302. package/dist/utils/selection.svelte.js +60 -10
  303. package/dist/utils/spellcheck.d.ts +9 -0
  304. package/dist/utils/spellcheck.js +17 -0
  305. package/dist/utils/tab.d.ts +31 -0
  306. package/dist/utils/tab.js +117 -0
  307. package/dist/utils/words.d.ts +7 -0
  308. package/dist/utils/words.js +62 -0
  309. package/dist/vite.d.ts +22 -0
  310. package/dist/vite.js +34 -0
  311. package/package.json +61 -22
  312. package/dist/blocks/zone/Zone.svelte +0 -258
  313. package/dist/blocks/zone/Zone.svelte.d.ts +0 -11
  314. package/dist/blocks/zone/index.d.ts +0 -2
  315. package/dist/blocks/zone/index.js +0 -2
  316. package/dist/blocks/zone/zone.extension.d.ts +0 -2
  317. package/dist/blocks/zone/zone.extension.js +0 -221
  318. package/dist/blocks/zone/zone.svelte.d.ts +0 -112
  319. package/dist/blocks/zone/zone.svelte.js +0 -321
@@ -0,0 +1,3 @@
1
+ export { MemoryOutbox } from "./outbox.js";
2
+ export { REASON_CODES } from "./status.js";
3
+ export { Files, FileRejectedError } from "./files.svelte.js";
@@ -0,0 +1,3 @@
1
+ export { Files, FileRejectedError } from './files.svelte.js';
2
+ export { MemoryOutbox } from './outbox.js';
3
+ export { REASON_CODES } from './status.js';
@@ -0,0 +1,69 @@
1
+ /**
2
+ * The upload outbox (ADR 014 §3.4): the list of files still to send to the host (`onBeforePersist`), kept NEXT TO the
3
+ * asset store — never inside the Loro document. The local copy of the bytes is the payload, the outbox only says what is
4
+ * waiting, so an upload interrupted by a closed tab resumes when the document is opened again.
5
+ *
6
+ * An outbox is scoped to ONE document. `createPersistedEditor` plugs an `IndexedDBOutbox`
7
+ * (`persistence/outbox.js`); a non-persisted editor uses the in-memory one below. An integrator can pass any object with
8
+ * this interface as `files.outbox`.
9
+ */
10
+ /**
11
+ * @typedef {Object} OutboxEntry
12
+ * @property {string} hash `sha256-<hex>` id of the file
13
+ * @property {number} attempts how many times its upload was started
14
+ * @property {'pending' | 'error'} state `pending`: to send (or interrupted); `error`: the last attempt failed (retried on demand only)
15
+ * @property {number} updatedAt epoch ms
16
+ */
17
+ /**
18
+ * @typedef {Object} Outbox
19
+ * @property {() => Promise<OutboxEntry[]>} list
20
+ * @property {(entry: OutboxEntry) => Promise<void>} put insert or replace the entry of `entry.hash`
21
+ * @property {(hash: string) => Promise<void>} delete
22
+ * @property {() => Promise<void>} [clear] optional: forget every entry of the document
23
+ */
24
+ /**
25
+ * In-memory {@link Outbox} (lost with the page, like a non-persisted document).
26
+ * @implements {Outbox}
27
+ */
28
+ export class MemoryOutbox implements Outbox {
29
+ /** @returns {Promise<OutboxEntry[]>} */
30
+ list(): Promise<OutboxEntry[]>;
31
+ /** @param {OutboxEntry} entry */
32
+ put(entry: OutboxEntry): Promise<void>;
33
+ /** @param {string} hash */
34
+ delete(hash: string): Promise<void>;
35
+ clear(): Promise<void>;
36
+ /** Number of entries (handy in tests / diagnostics). */
37
+ get size(): number;
38
+ #private;
39
+ }
40
+ export type OutboxEntry = {
41
+ /**
42
+ * `sha256-<hex>` id of the file
43
+ */
44
+ hash: string;
45
+ /**
46
+ * how many times its upload was started
47
+ */
48
+ attempts: number;
49
+ /**
50
+ * `pending`: to send (or interrupted); `error`: the last attempt failed (retried on demand only)
51
+ */
52
+ state: "pending" | "error";
53
+ /**
54
+ * epoch ms
55
+ */
56
+ updatedAt: number;
57
+ };
58
+ export type Outbox = {
59
+ list: () => Promise<OutboxEntry[]>;
60
+ /**
61
+ * insert or replace the entry of `entry.hash`
62
+ */
63
+ put: (entry: OutboxEntry) => Promise<void>;
64
+ delete: (hash: string) => Promise<void>;
65
+ /**
66
+ * optional: forget every entry of the document
67
+ */
68
+ clear?: (() => Promise<void>) | undefined;
69
+ };
@@ -0,0 +1,48 @@
1
+ /**
2
+ * The upload outbox (ADR 014 §3.4): the list of files still to send to the host (`onBeforePersist`), kept NEXT TO the
3
+ * asset store — never inside the Loro document. The local copy of the bytes is the payload, the outbox only says what is
4
+ * waiting, so an upload interrupted by a closed tab resumes when the document is opened again.
5
+ *
6
+ * An outbox is scoped to ONE document. `createPersistedEditor` plugs an `IndexedDBOutbox`
7
+ * (`persistence/outbox.js`); a non-persisted editor uses the in-memory one below. An integrator can pass any object with
8
+ * this interface as `files.outbox`.
9
+ */
10
+
11
+ /**
12
+ * @typedef {Object} OutboxEntry
13
+ * @property {string} hash `sha256-<hex>` id of the file
14
+ * @property {number} attempts how many times its upload was started
15
+ * @property {'pending' | 'error'} state `pending`: to send (or interrupted); `error`: the last attempt failed (retried on demand only)
16
+ * @property {number} updatedAt epoch ms
17
+ */
18
+
19
+ /**
20
+ * @typedef {Object} Outbox
21
+ * @property {() => Promise<OutboxEntry[]>} list
22
+ * @property {(entry: OutboxEntry) => Promise<void>} put insert or replace the entry of `entry.hash`
23
+ * @property {(hash: string) => Promise<void>} delete
24
+ * @property {() => Promise<void>} [clear] optional: forget every entry of the document
25
+ */
26
+
27
+ /**
28
+ * In-memory {@link Outbox} (lost with the page, like a non-persisted document).
29
+ * @implements {Outbox}
30
+ */
31
+ export class MemoryOutbox {
32
+ /** @type {Map<string, OutboxEntry>} */
33
+ #entries = new Map();
34
+
35
+ /** @returns {Promise<OutboxEntry[]>} */
36
+ async list() { return [...this.#entries.values()].map((e) => ({ ...e })); }
37
+
38
+ /** @param {OutboxEntry} entry */
39
+ async put(entry) { this.#entries.set(entry.hash, { ...entry }); }
40
+
41
+ /** @param {string} hash */
42
+ async delete(hash) { this.#entries.delete(hash); }
43
+
44
+ async clear() { this.#entries.clear(); }
45
+
46
+ /** Number of entries (handy in tests / diagnostics). */
47
+ get size() { return this.#entries.size; }
48
+ }
@@ -0,0 +1,65 @@
1
+ /** @param {number} bytes @returns {string} */
2
+ export function formatBytes(bytes: number): string;
3
+ /**
4
+ * @param {FileReason['code']} code @param {string} [message] defaults to the standard sentence of the code
5
+ * @returns {FileReason}
6
+ */
7
+ export function reasonOf(code: FileReason["code"], message?: string): FileReason;
8
+ /** @param {number} size @param {number} limit @returns {FileReason} */
9
+ export function tooLarge(size: number, limit: number): FileReason;
10
+ /**
11
+ * A reason read back from a document (untrusted: a document may come from anywhere): only a known code and a bounded
12
+ * string survive. `null` when `value` is not a reason.
13
+ * @param {unknown} value @returns {FileReason | null}
14
+ */
15
+ export function normalizeReason(value: unknown): FileReason | null;
16
+ /** The reason to show for a status that carries none. @param {string} status @returns {FileReason | null} */
17
+ export function defaultReason(status: string): FileReason | null;
18
+ /**
19
+ * Status / reason model of a media block (ADR 014 lot 2). Pure helpers, no document access.
20
+ *
21
+ * `status` is what the block stores (and what a document export writes):
22
+ * - `ready` the file is stored (and, with a host, uploaded);
23
+ * - `pending` the bytes are being stored / uploaded (`block.progress` tells how far while an upload runs);
24
+ * - `error` the upload failed or was cancelled — the local copy is kept, `block.retry()` runs it again;
25
+ * - `missing` no source has the bytes (a copy without them, a corrupt embedded file…);
26
+ * - `rejected` the file was refused (`files.maxFileSize`); no ref, the block only says why.
27
+ * A block saved `pending` that no upload is running for, with neither local bytes nor a host `url` (a document opened on
28
+ * another device before the upload ended), is shown as `missing` with the reason `interrupted` (see `MediaBlock#isMissing`).
29
+ *
30
+ * `reason` explains `error`, `rejected` and `missing`: `{ code, message }` where `code` is stable (one of {@link REASON_CODES})
31
+ * and `message` a readable English sentence an interface can display as is.
32
+ */
33
+ /**
34
+ * @typedef {'ready' | 'pending' | 'error' | 'missing' | 'rejected'} FileStatus
35
+ */
36
+ /**
37
+ * @typedef {Object} FileReason
38
+ * @property {'too-large' | 'upload-failed' | 'cancelled' | 'interrupted' | 'unavailable' | 'not-embedded' | 'corrupt'} code
39
+ * @property {string} message readable, English
40
+ */
41
+ /** The stable codes of {@link FileReason}. */
42
+ export const REASON_CODES: Readonly<{
43
+ 'too-large': "The file is too large.";
44
+ 'upload-failed': "The upload failed.";
45
+ cancelled: "The upload was cancelled.";
46
+ interrupted: "The upload was interrupted before it finished: the file is not available on this device.";
47
+ unavailable: "The file is not available.";
48
+ 'not-embedded': "The file was not included in the copy (too large or not loaded yet).";
49
+ corrupt: "The file does not match its fingerprint and was ignored.";
50
+ }>;
51
+ /** Thrown by `Files#ingest` / `Files#persist` for a file the options refuse (`maxFileSize`). */
52
+ export class FileRejectedError extends Error {
53
+ /** @param {FileReason} reason */
54
+ constructor(reason: FileReason);
55
+ /** @type {FileReason} */
56
+ reason: FileReason;
57
+ }
58
+ export type FileStatus = "ready" | "pending" | "error" | "missing" | "rejected";
59
+ export type FileReason = {
60
+ code: "too-large" | "upload-failed" | "cancelled" | "interrupted" | "unavailable" | "not-embedded" | "corrupt";
61
+ /**
62
+ * readable, English
63
+ */
64
+ message: string;
65
+ };
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Status / reason model of a media block (ADR 014 lot 2). Pure helpers, no document access.
3
+ *
4
+ * `status` is what the block stores (and what a document export writes):
5
+ * - `ready` the file is stored (and, with a host, uploaded);
6
+ * - `pending` the bytes are being stored / uploaded (`block.progress` tells how far while an upload runs);
7
+ * - `error` the upload failed or was cancelled — the local copy is kept, `block.retry()` runs it again;
8
+ * - `missing` no source has the bytes (a copy without them, a corrupt embedded file…);
9
+ * - `rejected` the file was refused (`files.maxFileSize`); no ref, the block only says why.
10
+ * A block saved `pending` that no upload is running for, with neither local bytes nor a host `url` (a document opened on
11
+ * another device before the upload ended), is shown as `missing` with the reason `interrupted` (see `MediaBlock#isMissing`).
12
+ *
13
+ * `reason` explains `error`, `rejected` and `missing`: `{ code, message }` where `code` is stable (one of {@link REASON_CODES})
14
+ * and `message` a readable English sentence an interface can display as is.
15
+ */
16
+
17
+ /**
18
+ * @typedef {'ready' | 'pending' | 'error' | 'missing' | 'rejected'} FileStatus
19
+ */
20
+
21
+ /**
22
+ * @typedef {Object} FileReason
23
+ * @property {'too-large' | 'upload-failed' | 'cancelled' | 'interrupted' | 'unavailable' | 'not-embedded' | 'corrupt'} code
24
+ * @property {string} message readable, English
25
+ */
26
+
27
+ /** The stable codes of {@link FileReason}. */
28
+ export const REASON_CODES = Object.freeze({
29
+ 'too-large': 'The file is too large.',
30
+ 'upload-failed': 'The upload failed.',
31
+ 'cancelled': 'The upload was cancelled.',
32
+ 'interrupted': 'The upload was interrupted before it finished: the file is not available on this device.',
33
+ 'unavailable': 'The file is not available.',
34
+ 'not-embedded': 'The file was not included in the copy (too large or not loaded yet).',
35
+ 'corrupt': 'The file does not match its fingerprint and was ignored.',
36
+ });
37
+
38
+ /** @param {number} bytes @returns {string} */
39
+ export function formatBytes(bytes) {
40
+ if (bytes >= 1048576) return (bytes / 1048576).toFixed(1).replace(/\.0$/, '') + ' MB';
41
+ if (bytes >= 1024) return (bytes / 1024).toFixed(1).replace(/\.0$/, '') + ' KB';
42
+ return bytes + ' B';
43
+ }
44
+
45
+ /**
46
+ * @param {FileReason['code']} code @param {string} [message] defaults to the standard sentence of the code
47
+ * @returns {FileReason}
48
+ */
49
+ export function reasonOf(code, message) {
50
+ return { code, message: message || REASON_CODES[code] };
51
+ }
52
+
53
+ /** @param {number} size @param {number} limit @returns {FileReason} */
54
+ export function tooLarge(size, limit) {
55
+ return reasonOf('too-large', `The file is too large (${formatBytes(size)}); the limit is ${formatBytes(limit)}.`);
56
+ }
57
+
58
+ /**
59
+ * A reason read back from a document (untrusted: a document may come from anywhere): only a known code and a bounded
60
+ * string survive. `null` when `value` is not a reason.
61
+ * @param {unknown} value @returns {FileReason | null}
62
+ */
63
+ export function normalizeReason(value) {
64
+ if (!value || typeof value !== 'object') return null;
65
+ const { code, message } = /** @type {any} */ (value);
66
+ if (typeof code !== 'string' || !Object.hasOwn(REASON_CODES, code)) return null;
67
+ return reasonOf(/** @type {FileReason['code']} */ (code), typeof message === 'string' && message ? message.slice(0, 300) : undefined);
68
+ }
69
+
70
+ /** The reason to show for a status that carries none. @param {string} status @returns {FileReason | null} */
71
+ export function defaultReason(status) {
72
+ if (status === 'error') return reasonOf('upload-failed');
73
+ if (status === 'rejected') return reasonOf('too-large');
74
+ if (status === 'missing') return reasonOf('unavailable');
75
+ return null;
76
+ }
77
+
78
+ /** Thrown by `Files#ingest` / `Files#persist` for a file the options refuse (`maxFileSize`). */
79
+ export class FileRejectedError extends Error {
80
+ /** @param {FileReason} reason */
81
+ constructor(reason) {
82
+ super(reason.message);
83
+ this.name = 'FileRejectedError';
84
+ /** @type {FileReason} */
85
+ this.reason = reason;
86
+ }
87
+ }
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Asset storage (ADR 014 §3.3): where the BYTES of the files live, outside the Loro document. The document only holds
3
+ * references (`nabu-asset:sha256-<hex>`) and a small metadata index (`assetIndex`).
4
+ *
5
+ * `MemoryAssetStore` is the default of a non-persisted editor (lost with the page, like its document). The persisted
6
+ * editor uses `IndexedDBAssetStore` (`persistence/asset-store.js`); an integrator can pass any object with this
7
+ * interface as `files.store`.
8
+ */
9
+ /**
10
+ * What a store keeps next to the bytes.
11
+ * @typedef {Object} AssetMeta
12
+ * @property {string} mime
13
+ * @property {string} name
14
+ * @property {number} size byte length
15
+ */
16
+ /**
17
+ * @typedef {Object} AssetStore
18
+ * @property {(hash: string) => Promise<boolean>} has
19
+ * @property {(hash: string) => Promise<Blob | null>} get
20
+ * @property {(hash: string, blob: Blob, meta: AssetMeta) => Promise<void>} put
21
+ * @property {(hash: string) => Promise<void>} delete
22
+ * @property {() => AsyncIterable<string>} keys
23
+ * @property {(hash: string) => Promise<AssetMeta | null>} [stat] optional: the metadata stored with `put`
24
+ * @property {(docId: string, hashes: Iterable<string>) => Promise<void>} [setDocRefs] optional, with the three below: which files
25
+ * each document references. Only a store that offers them lets a compaction / `clearPersistence()` DELETE bytes (a file is
26
+ * deleted only when no document references it any more); without them Nabu never deletes bytes from this store.
27
+ * @property {(docId: string) => Promise<Set<string>>} [getDocRefs]
28
+ * @property {(docId: string) => Promise<void>} [clearDocRefs]
29
+ * @property {() => Promise<Set<string>>} [referencedHashes] every file referenced by at least one document
30
+ * @property {(hash: string) => Promise<number | null>} [savedAt] optional: epoch ms when the file was last stored or re-added; with
31
+ * `touch`, lets a release keep a recent file (`files.releaseGraceMs`). Without it, a release skips every file (grace on).
32
+ * @property {(hash: string) => Promise<void>} [touch] optional: refresh `savedAt` (called when a file already stored is added again)
33
+ */
34
+ /**
35
+ * In-memory {@link AssetStore}. Keys are `sha256-<hex>` hashes.
36
+ * @implements {AssetStore}
37
+ */
38
+ export class MemoryAssetStore implements AssetStore {
39
+ /** @param {string} hash */
40
+ has(hash: string): Promise<boolean>;
41
+ /** @param {string} hash @returns {Promise<Blob | null>} */
42
+ get(hash: string): Promise<Blob | null>;
43
+ /** @param {string} hash @param {Blob} blob @param {AssetMeta} meta */
44
+ put(hash: string, blob: Blob, meta: AssetMeta): Promise<void>;
45
+ /** @param {string} hash */
46
+ delete(hash: string): Promise<void>;
47
+ /** @returns {AsyncGenerator<string>} */
48
+ keys(): AsyncGenerator<string>;
49
+ /** @param {string} hash @returns {Promise<AssetMeta | null>} */
50
+ stat(hash: string): Promise<AssetMeta | null>;
51
+ /** Number of files stored (handy in tests / diagnostics). */
52
+ get size(): number;
53
+ #private;
54
+ }
55
+ /**
56
+ * What a store keeps next to the bytes.
57
+ */
58
+ export type AssetMeta = {
59
+ mime: string;
60
+ name: string;
61
+ /**
62
+ * byte length
63
+ */
64
+ size: number;
65
+ };
66
+ export type AssetStore = {
67
+ has: (hash: string) => Promise<boolean>;
68
+ get: (hash: string) => Promise<Blob | null>;
69
+ put: (hash: string, blob: Blob, meta: AssetMeta) => Promise<void>;
70
+ delete: (hash: string) => Promise<void>;
71
+ keys: () => AsyncIterable<string>;
72
+ /**
73
+ * optional: the metadata stored with `put`
74
+ */
75
+ stat?: ((hash: string) => Promise<AssetMeta | null>) | undefined;
76
+ /**
77
+ * optional, with the three below: which files
78
+ * each document references. Only a store that offers them lets a compaction / `clearPersistence()` DELETE bytes (a file is
79
+ * deleted only when no document references it any more); without them Nabu never deletes bytes from this store.
80
+ */
81
+ setDocRefs?: ((docId: string, hashes: Iterable<string>) => Promise<void>) | undefined;
82
+ getDocRefs?: ((docId: string) => Promise<Set<string>>) | undefined;
83
+ clearDocRefs?: ((docId: string) => Promise<void>) | undefined;
84
+ /**
85
+ * every file referenced by at least one document
86
+ */
87
+ referencedHashes?: (() => Promise<Set<string>>) | undefined;
88
+ /**
89
+ * optional: epoch ms when the file was last stored or re-added; with
90
+ * `touch`, lets a release keep a recent file (`files.releaseGraceMs`). Without it, a release skips every file (grace on).
91
+ */
92
+ savedAt?: ((hash: string) => Promise<number | null>) | undefined;
93
+ /**
94
+ * optional: refresh `savedAt` (called when a file already stored is added again)
95
+ */
96
+ touch?: ((hash: string) => Promise<void>) | undefined;
97
+ };
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Asset storage (ADR 014 §3.3): where the BYTES of the files live, outside the Loro document. The document only holds
3
+ * references (`nabu-asset:sha256-<hex>`) and a small metadata index (`assetIndex`).
4
+ *
5
+ * `MemoryAssetStore` is the default of a non-persisted editor (lost with the page, like its document). The persisted
6
+ * editor uses `IndexedDBAssetStore` (`persistence/asset-store.js`); an integrator can pass any object with this
7
+ * interface as `files.store`.
8
+ */
9
+
10
+ /**
11
+ * What a store keeps next to the bytes.
12
+ * @typedef {Object} AssetMeta
13
+ * @property {string} mime
14
+ * @property {string} name
15
+ * @property {number} size byte length
16
+ */
17
+
18
+ /**
19
+ * @typedef {Object} AssetStore
20
+ * @property {(hash: string) => Promise<boolean>} has
21
+ * @property {(hash: string) => Promise<Blob | null>} get
22
+ * @property {(hash: string, blob: Blob, meta: AssetMeta) => Promise<void>} put
23
+ * @property {(hash: string) => Promise<void>} delete
24
+ * @property {() => AsyncIterable<string>} keys
25
+ * @property {(hash: string) => Promise<AssetMeta | null>} [stat] optional: the metadata stored with `put`
26
+ * @property {(docId: string, hashes: Iterable<string>) => Promise<void>} [setDocRefs] optional, with the three below: which files
27
+ * each document references. Only a store that offers them lets a compaction / `clearPersistence()` DELETE bytes (a file is
28
+ * deleted only when no document references it any more); without them Nabu never deletes bytes from this store.
29
+ * @property {(docId: string) => Promise<Set<string>>} [getDocRefs]
30
+ * @property {(docId: string) => Promise<void>} [clearDocRefs]
31
+ * @property {() => Promise<Set<string>>} [referencedHashes] every file referenced by at least one document
32
+ * @property {(hash: string) => Promise<number | null>} [savedAt] optional: epoch ms when the file was last stored or re-added; with
33
+ * `touch`, lets a release keep a recent file (`files.releaseGraceMs`). Without it, a release skips every file (grace on).
34
+ * @property {(hash: string) => Promise<void>} [touch] optional: refresh `savedAt` (called when a file already stored is added again)
35
+ */
36
+
37
+ /**
38
+ * In-memory {@link AssetStore}. Keys are `sha256-<hex>` hashes.
39
+ * @implements {AssetStore}
40
+ */
41
+ export class MemoryAssetStore {
42
+ /** @type {Map<string, { blob: Blob, meta: AssetMeta }>} */
43
+ #entries = new Map();
44
+
45
+ /** @param {string} hash */
46
+ async has(hash) { return this.#entries.has(hash); }
47
+
48
+ /** @param {string} hash @returns {Promise<Blob | null>} */
49
+ async get(hash) { return this.#entries.get(hash)?.blob ?? null; }
50
+
51
+ /** @param {string} hash @param {Blob} blob @param {AssetMeta} meta */
52
+ async put(hash, blob, meta) { this.#entries.set(hash, { blob, meta: { ...meta } }); }
53
+
54
+ /** @param {string} hash */
55
+ async delete(hash) { this.#entries.delete(hash); }
56
+
57
+ /** @returns {AsyncGenerator<string>} */
58
+ async *keys() { for (const key of [...this.#entries.keys()]) yield key; }
59
+
60
+ /** @param {string} hash @returns {Promise<AssetMeta | null>} */
61
+ async stat(hash) { const e = this.#entries.get(hash); return e ? { ...e.meta } : null; }
62
+
63
+ /** Number of files stored (handy in tests / diagnostics). */
64
+ get size() { return this.#entries.size; }
65
+ }
@@ -0,0 +1,174 @@
1
+ /**
2
+ * The resolved `files.autoRetry` option: `false` disables the automatic retries, an object tunes them, anything else is the default.
3
+ * @param {unknown} option @returns {Required<AutoRetryConfig> | null}
4
+ */
5
+ export function resolveAutoRetry(option: unknown): Required<AutoRetryConfig> | null;
6
+ /** @import { Outbox, OutboxEntry } from './outbox.js' */
7
+ /** @import { FileReason } from './status.js' */
8
+ /**
9
+ * @typedef {Object} AutoRetryConfig How a persisted editor retries, by itself, the uploads it finds waiting when it is opened (P-97).
10
+ * @property {number} [initialDelay] ms before the second attempt (default 2000); each next one waits twice as long
11
+ * @property {number} [maxDelay] longest wait between two attempts (default 60000)
12
+ * @property {number} [maxAttempts] attempts per file and per session, the one at open included (default 8); the `online` event grants a new series
13
+ */
14
+ export const DEFAULT_AUTO_RETRY: Readonly<{
15
+ initialDelay: 2000;
16
+ maxDelay: 60000;
17
+ maxAttempts: 8;
18
+ }>;
19
+ /**
20
+ * What the upload queue needs from {@link import('./files.svelte.js').Files} (kept as an interface so this module does not
21
+ * reach into it).
22
+ * @typedef {Object} UploadHost
23
+ * @property {import('../blocks/nabu.svelte.js').Nabu} nabu
24
+ * @property {import('./store.js').AssetStore} store
25
+ * @property {import('loro-crdt').LoroMap} index the document's `assetIndex`
26
+ * @property {() => import('./files.svelte.js').FilesConfig} config
27
+ * @property {(write: () => void) => Promise<void>} silent run Loro writes as a silent commit (not an undo step)
28
+ * @property {(hash: string) => Promise<void>} settled resolves when the bytes of `hash` arriving with a paste are stored
29
+ * @property {() => void} forgetMissing forget the "no source has it" verdicts (the index changed)
30
+ * @property {<T>(promise: Promise<T>) => Promise<T>} track register a background job (see `Files#whenIdle`)
31
+ */
32
+ /**
33
+ * @typedef {Object} Job
34
+ * @property {string} hash
35
+ * @property {AbortController} controller
36
+ * @property {'cancel' | 'released' | null} cause why the controller was aborted
37
+ * @property {boolean} referenced a live block has referenced this file since the job started (a job nobody references
38
+ * yet, e.g. started by `Files#persist`, is not aborted by the "last block deleted" rule)
39
+ * @property {Promise<boolean>} promise resolves `true` when the upload succeeded
40
+ */
41
+ /**
42
+ * The upload side of {@link import('./files.svelte.js').Files} (ADR 014 lot 2): with a host (`files.onBeforePersist`) a file is
43
+ * stored locally first, then sent in the background. The queue is DRIVEN BY THE DOCUMENT, not by calls:
44
+ *
45
+ * - a block whose status is `pending`, with a `nabu-asset:sha256-…` ref, local bytes, no host `url` and no running upload
46
+ * → the upload starts (this is also how an upload RESUMES when a document is opened again, and how an undo that brings a
47
+ * deleted block back restarts it);
48
+ * - an upload whose file no live block references any more is aborted (`AbortController` → the `signal` given to the host);
49
+ * - success: `assetIndex[hash].url = <ref returned by the host>` and the blocks become `ready`, in a silent commit; the
50
+ * block's ref NEVER changes. Failure: the blocks become `error` (local copy kept). {@link Uploads#retry} / {@link Uploads#cancel}
51
+ * are the explicit controls.
52
+ *
53
+ * The outbox ({@link Outbox}) remembers what is waiting (and how many attempts were made) next to the local store, so it
54
+ * survives a closed tab; it is a record, the document statuses plus the local bytes are what the queue acts on.
55
+ *
56
+ * Retry on open (P-97): the files the outbox lists when the document is opened (an upload interrupted, or one that had failed) are
57
+ * sent again BY THEMSELVES, in the background: a failed `error` file at once, then, whenever an attempt fails, after 2 s, 4 s, 8 s…
58
+ * (at most 60 s), `maxAttempts` times per session; the browser's `online` event starts a fresh series. A cancelled upload (the user's
59
+ * choice) is not retried, nor are the failures of the current session (the block's `retry()` is for those). See {@link AutoRetryConfig}.
60
+ */
61
+ export class Uploads {
62
+ /** @param {UploadHost} host */
63
+ constructor(host: UploadHost);
64
+ /** @type {Outbox} */
65
+ outbox: Outbox;
66
+ /** Stop the automatic retries (timers, `online` listener). The queue itself keeps working. */
67
+ dispose(): void;
68
+ /** Resolves once the outbox was read and the first pass (resume) ran. @returns {Promise<void>} */
69
+ ready(): Promise<void>;
70
+ /** Progress (0–1) of the running upload of `hash`, `null` when none runs. Reactive. @param {string} hash @returns {number | null} */
71
+ progress(hash: string): number | null;
72
+ /** Whether any upload is running (not reactive). @returns {boolean} */
73
+ busy(): boolean;
74
+ /** Whether an upload of `hash` is running. Reactive. @param {string} hash @returns {boolean} */
75
+ isUploading(hash: string): boolean;
76
+ /** @param {string} hash @returns {string | null} the host location recorded in the index */
77
+ hostedUrl(hash: string): string | null;
78
+ /** Whether a file with this hash still has to be sent to the host. @param {string} hash @returns {boolean} */
79
+ needsUpload(hash: string): boolean;
80
+ /**
81
+ * Called for every committed change of the document. Only what can concern an upload triggers a pass: a media ref /
82
+ * status written, or (while an upload runs) a node deleted. Typing never does.
83
+ * @param {any} event a Loro event batch
84
+ */
85
+ onDocEvent(event: any): void;
86
+ /** Run a pass soon (coalesced). */
87
+ schedule(): void;
88
+ /**
89
+ * Look at the document and act: abort the uploads nobody references, start those that are due. Passes never overlap.
90
+ * @returns {Promise<void>}
91
+ */
92
+ reconcile(): Promise<void>;
93
+ /**
94
+ * Send a file that is already in the local store to the host, now (`Files#persist`). No-op without a host or when it is
95
+ * already hosted. @param {string} hash @returns {Promise<boolean>}
96
+ */
97
+ upload(hash: string): Promise<boolean>;
98
+ /**
99
+ * Run the upload of a file again from its local copy (the blocks that were `error` become `pending`).
100
+ * @param {string} hash @returns {Promise<boolean>} `true` when the file ended up at the host
101
+ */
102
+ retry(hash: string): Promise<boolean>;
103
+ /**
104
+ * Abort the running upload of a file (its `signal` fires). The blocks become `error` with the reason `cancelled`; the
105
+ * local copy stays, {@link Uploads#retry} sends it again.
106
+ * @param {string} hash @returns {boolean} whether an upload was running
107
+ */
108
+ cancel(hash: string): boolean;
109
+ #private;
110
+ }
111
+ /**
112
+ * How a persisted editor retries, by itself, the uploads it finds waiting when it is opened (P-97).
113
+ */
114
+ export type AutoRetryConfig = {
115
+ /**
116
+ * ms before the second attempt (default 2000); each next one waits twice as long
117
+ */
118
+ initialDelay?: number | undefined;
119
+ /**
120
+ * longest wait between two attempts (default 60000)
121
+ */
122
+ maxDelay?: number | undefined;
123
+ /**
124
+ * attempts per file and per session, the one at open included (default 8); the `online` event grants a new series
125
+ */
126
+ maxAttempts?: number | undefined;
127
+ };
128
+ /**
129
+ * What the upload queue needs from {@link import ('./files.svelte.js').Files} (kept as an interface so this module does not
130
+ * reach into it).
131
+ */
132
+ export type UploadHost = {
133
+ nabu: import("../blocks/nabu.svelte.js").Nabu;
134
+ store: import("./store.js").AssetStore;
135
+ /**
136
+ * the document's `assetIndex`
137
+ */
138
+ index: import("loro-crdt").LoroMap;
139
+ config: () => import("./files.svelte.js").FilesConfig;
140
+ /**
141
+ * run Loro writes as a silent commit (not an undo step)
142
+ */
143
+ silent: (write: () => void) => Promise<void>;
144
+ /**
145
+ * resolves when the bytes of `hash` arriving with a paste are stored
146
+ */
147
+ settled: (hash: string) => Promise<void>;
148
+ /**
149
+ * forget the "no source has it" verdicts (the index changed)
150
+ */
151
+ forgetMissing: () => void;
152
+ /**
153
+ * register a background job (see `Files#whenIdle`)
154
+ */
155
+ track: <T>(promise: Promise<T>) => Promise<T>;
156
+ };
157
+ export type Job = {
158
+ hash: string;
159
+ controller: AbortController;
160
+ /**
161
+ * why the controller was aborted
162
+ */
163
+ cause: "cancel" | "released" | null;
164
+ /**
165
+ * a live block has referenced this file since the job started (a job nobody references
166
+ * yet, e.g. started by `Files#persist`, is not aborted by the "last block deleted" rule)
167
+ */
168
+ referenced: boolean;
169
+ /**
170
+ * resolves `true` when the upload succeeded
171
+ */
172
+ promise: Promise<boolean>;
173
+ };
174
+ import type { Outbox } from './outbox.js';