@superbee/core 0.2.0-pre.2 → 0.2.0-pre.21

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 (517) hide show
  1. package/README.md +1000 -0
  2. package/dist/artifact-contract.d.ts +90 -0
  3. package/dist/artifact-contract.d.ts.map +1 -0
  4. package/dist/artifact-contract.js +205 -0
  5. package/dist/artifact-contract.js.map +1 -0
  6. package/dist/backend.d.ts +19 -1
  7. package/dist/backend.d.ts.map +1 -1
  8. package/dist/backend.js +83 -36
  9. package/dist/backend.js.map +1 -1
  10. package/dist/blob-contract.d.ts +80 -0
  11. package/dist/blob-contract.d.ts.map +1 -0
  12. package/dist/blob-contract.js +131 -0
  13. package/dist/blob-contract.js.map +1 -0
  14. package/dist/blob-journal.d.ts +302 -0
  15. package/dist/blob-journal.d.ts.map +1 -0
  16. package/dist/blob-journal.js +540 -0
  17. package/dist/blob-journal.js.map +1 -0
  18. package/dist/body-replace-guards.d.ts +50 -0
  19. package/dist/body-replace-guards.d.ts.map +1 -0
  20. package/dist/body-replace-guards.js +158 -0
  21. package/dist/body-replace-guards.js.map +1 -0
  22. package/dist/builtin-recipes/content.d.ts +93 -0
  23. package/dist/builtin-recipes/content.d.ts.map +1 -0
  24. package/dist/builtin-recipes/content.js +288 -0
  25. package/dist/builtin-recipes/content.js.map +1 -0
  26. package/dist/builtin-recipes.d.ts +10 -0
  27. package/dist/builtin-recipes.d.ts.map +1 -0
  28. package/dist/builtin-recipes.js +97 -0
  29. package/dist/builtin-recipes.js.map +1 -0
  30. package/dist/bundle-health/index.d.ts +14 -0
  31. package/dist/bundle-health/index.d.ts.map +1 -0
  32. package/dist/bundle-health/index.js +12 -0
  33. package/dist/bundle-health/index.js.map +1 -0
  34. package/dist/bundle-health/kind-findings.d.ts +44 -0
  35. package/dist/bundle-health/kind-findings.d.ts.map +1 -0
  36. package/dist/bundle-health/kind-findings.js +68 -0
  37. package/dist/bundle-health/kind-findings.js.map +1 -0
  38. package/dist/bundle-health/legacy-page.d.ts +39 -0
  39. package/dist/bundle-health/legacy-page.d.ts.map +1 -0
  40. package/dist/bundle-health/legacy-page.js +50 -0
  41. package/dist/bundle-health/legacy-page.js.map +1 -0
  42. package/dist/bundle-health/report.d.ts +202 -0
  43. package/dist/bundle-health/report.d.ts.map +1 -0
  44. package/dist/bundle-health/report.js +438 -0
  45. package/dist/bundle-health/report.js.map +1 -0
  46. package/dist/bundle-ops.d.ts +1 -1
  47. package/dist/bundle-ops.d.ts.map +1 -1
  48. package/dist/bundle-ops.js +2 -2
  49. package/dist/bundle-ops.js.map +1 -1
  50. package/dist/bundle.d.ts +2 -1
  51. package/dist/bundle.d.ts.map +1 -1
  52. package/dist/bundle.js +3 -3
  53. package/dist/bundle.js.map +1 -1
  54. package/dist/code-point-order.d.ts +8 -0
  55. package/dist/code-point-order.d.ts.map +1 -0
  56. package/dist/code-point-order.js +20 -0
  57. package/dist/code-point-order.js.map +1 -0
  58. package/dist/connectors.d.ts +230 -0
  59. package/dist/connectors.d.ts.map +1 -0
  60. package/dist/connectors.js +1150 -0
  61. package/dist/connectors.js.map +1 -0
  62. package/dist/cross-bundle.d.ts +135 -0
  63. package/dist/cross-bundle.d.ts.map +1 -0
  64. package/dist/cross-bundle.js +186 -0
  65. package/dist/cross-bundle.js.map +1 -0
  66. package/dist/dependencies.d.ts +94 -0
  67. package/dist/dependencies.d.ts.map +1 -0
  68. package/dist/dependencies.js +180 -0
  69. package/dist/dependencies.js.map +1 -0
  70. package/dist/document-codec.d.ts +6 -1
  71. package/dist/document-codec.d.ts.map +1 -1
  72. package/dist/document-codec.js +8 -4
  73. package/dist/document-codec.js.map +1 -1
  74. package/dist/document-field-actions.d.ts +31 -1
  75. package/dist/document-field-actions.d.ts.map +1 -1
  76. package/dist/document-field-actions.js +137 -34
  77. package/dist/document-field-actions.js.map +1 -1
  78. package/dist/document-mutation.d.ts +22 -10
  79. package/dist/document-mutation.d.ts.map +1 -1
  80. package/dist/document-mutation.js +58 -27
  81. package/dist/document-mutation.js.map +1 -1
  82. package/dist/document-write-policy.d.ts.map +1 -1
  83. package/dist/document-write-policy.js +4 -2
  84. package/dist/document-write-policy.js.map +1 -1
  85. package/dist/engine.d.ts +9 -2
  86. package/dist/engine.d.ts.map +1 -1
  87. package/dist/engine.js +11 -4
  88. package/dist/engine.js.map +1 -1
  89. package/dist/file-journaled-backend-internal.d.ts +21 -0
  90. package/dist/file-journaled-backend-internal.d.ts.map +1 -0
  91. package/dist/file-journaled-backend-internal.js +12 -0
  92. package/dist/file-journaled-backend-internal.js.map +1 -0
  93. package/dist/file-journaled-backend.d.ts +200 -0
  94. package/dist/file-journaled-backend.d.ts.map +1 -0
  95. package/dist/file-journaled-backend.js +1334 -0
  96. package/dist/file-journaled-backend.js.map +1 -0
  97. package/dist/filesystem-host.d.ts +15 -0
  98. package/dist/filesystem-host.d.ts.map +1 -0
  99. package/dist/filesystem-host.js +20 -0
  100. package/dist/filesystem-host.js.map +1 -0
  101. package/dist/filesystem-identity.d.ts +86 -4
  102. package/dist/filesystem-identity.d.ts.map +1 -1
  103. package/dist/filesystem-identity.js +338 -102
  104. package/dist/filesystem-identity.js.map +1 -1
  105. package/dist/filesystem-lock.d.ts +16 -3
  106. package/dist/filesystem-lock.d.ts.map +1 -1
  107. package/dist/filesystem-lock.js +323 -77
  108. package/dist/filesystem-lock.js.map +1 -1
  109. package/dist/filesystem-push-role.d.ts +77 -0
  110. package/dist/filesystem-push-role.d.ts.map +1 -0
  111. package/dist/filesystem-push-role.js +165 -0
  112. package/dist/filesystem-push-role.js.map +1 -0
  113. package/dist/filesystem.d.ts +17 -0
  114. package/dist/filesystem.d.ts.map +1 -0
  115. package/dist/filesystem.js +18 -0
  116. package/dist/filesystem.js.map +1 -0
  117. package/dist/frontmatter.d.ts +8 -0
  118. package/dist/frontmatter.d.ts.map +1 -1
  119. package/dist/frontmatter.js +14 -4
  120. package/dist/frontmatter.js.map +1 -1
  121. package/dist/governed-body-write.d.ts +106 -0
  122. package/dist/governed-body-write.d.ts.map +1 -0
  123. package/dist/governed-body-write.js +251 -0
  124. package/dist/governed-body-write.js.map +1 -0
  125. package/dist/host-policy-snapshot.d.ts +9 -0
  126. package/dist/host-policy-snapshot.d.ts.map +1 -0
  127. package/dist/host-policy-snapshot.js +33 -0
  128. package/dist/host-policy-snapshot.js.map +1 -0
  129. package/dist/host-text.d.ts +31 -0
  130. package/dist/host-text.d.ts.map +1 -0
  131. package/dist/host-text.js +77 -0
  132. package/dist/host-text.js.map +1 -0
  133. package/dist/hosted-client/binding.d.ts +7 -0
  134. package/dist/hosted-client/binding.d.ts.map +1 -0
  135. package/dist/hosted-client/binding.js +10 -0
  136. package/dist/hosted-client/binding.js.map +1 -0
  137. package/dist/hosted-client/blob-delivery.d.ts +67 -0
  138. package/dist/hosted-client/blob-delivery.d.ts.map +1 -0
  139. package/dist/hosted-client/blob-delivery.js +169 -0
  140. package/dist/hosted-client/blob-delivery.js.map +1 -0
  141. package/dist/hosted-client/blob-write.d.ts +386 -0
  142. package/dist/hosted-client/blob-write.d.ts.map +1 -0
  143. package/dist/hosted-client/blob-write.js +770 -0
  144. package/dist/hosted-client/blob-write.js.map +1 -0
  145. package/dist/hosted-client/bundle-listing.d.ts +46 -0
  146. package/dist/hosted-client/bundle-listing.d.ts.map +1 -0
  147. package/dist/hosted-client/bundle-listing.js +36 -0
  148. package/dist/hosted-client/bundle-listing.js.map +1 -0
  149. package/dist/hosted-client/client.d.ts +219 -0
  150. package/dist/hosted-client/client.d.ts.map +1 -0
  151. package/dist/hosted-client/client.js +309 -0
  152. package/dist/hosted-client/client.js.map +1 -0
  153. package/dist/hosted-client/directory.d.ts +46 -0
  154. package/dist/hosted-client/directory.d.ts.map +1 -0
  155. package/dist/hosted-client/directory.js +74 -0
  156. package/dist/hosted-client/directory.js.map +1 -0
  157. package/dist/hosted-client/errors.d.ts +26 -0
  158. package/dist/hosted-client/errors.d.ts.map +1 -0
  159. package/dist/hosted-client/errors.js +35 -0
  160. package/dist/hosted-client/errors.js.map +1 -0
  161. package/dist/hosted-client/inbox.d.ts +320 -0
  162. package/dist/hosted-client/inbox.d.ts.map +1 -0
  163. package/dist/hosted-client/inbox.js +379 -0
  164. package/dist/hosted-client/inbox.js.map +1 -0
  165. package/dist/hosted-client/index.d.ts +30 -0
  166. package/dist/hosted-client/index.d.ts.map +1 -0
  167. package/dist/hosted-client/index.js +32 -0
  168. package/dist/hosted-client/index.js.map +1 -0
  169. package/dist/hosted-client/journal.d.ts +103 -0
  170. package/dist/hosted-client/journal.d.ts.map +1 -0
  171. package/dist/hosted-client/journal.js +464 -0
  172. package/dist/hosted-client/journal.js.map +1 -0
  173. package/dist/hosted-client/node.d.ts +74 -0
  174. package/dist/hosted-client/node.d.ts.map +1 -0
  175. package/dist/hosted-client/node.js +219 -0
  176. package/dist/hosted-client/node.js.map +1 -0
  177. package/dist/hosted-client/reference.d.ts +12 -0
  178. package/dist/hosted-client/reference.d.ts.map +1 -0
  179. package/dist/hosted-client/reference.js +29 -0
  180. package/dist/hosted-client/reference.js.map +1 -0
  181. package/dist/hosted-client/write.d.ts +217 -0
  182. package/dist/hosted-client/write.d.ts.map +1 -0
  183. package/dist/hosted-client/write.js +418 -0
  184. package/dist/hosted-client/write.js.map +1 -0
  185. package/dist/hosted-transport/answer-rows.d.ts +243 -0
  186. package/dist/hosted-transport/answer-rows.d.ts.map +1 -0
  187. package/dist/hosted-transport/answer-rows.js +454 -0
  188. package/dist/hosted-transport/answer-rows.js.map +1 -0
  189. package/dist/hosted-transport/blob-reads.d.ts +35 -0
  190. package/dist/hosted-transport/blob-reads.d.ts.map +1 -0
  191. package/dist/hosted-transport/blob-reads.js +179 -0
  192. package/dist/hosted-transport/blob-reads.js.map +1 -0
  193. package/dist/hosted-transport/blob-write.d.ts +34 -0
  194. package/dist/hosted-transport/blob-write.d.ts.map +1 -0
  195. package/dist/hosted-transport/blob-write.js +115 -0
  196. package/dist/hosted-transport/blob-write.js.map +1 -0
  197. package/dist/hosted-transport/carrier.d.ts +151 -0
  198. package/dist/hosted-transport/carrier.d.ts.map +1 -0
  199. package/dist/hosted-transport/carrier.js +260 -0
  200. package/dist/hosted-transport/carrier.js.map +1 -0
  201. package/dist/hosted-transport/history-pages.d.ts +55 -0
  202. package/dist/hosted-transport/history-pages.d.ts.map +1 -0
  203. package/dist/hosted-transport/history-pages.js +69 -0
  204. package/dist/hosted-transport/history-pages.js.map +1 -0
  205. package/dist/hosted-transport/index.d.ts +18 -0
  206. package/dist/hosted-transport/index.d.ts.map +1 -0
  207. package/dist/hosted-transport/index.js +18 -0
  208. package/dist/hosted-transport/index.js.map +1 -0
  209. package/dist/hosted-transport/operations.d.ts +85 -0
  210. package/dist/hosted-transport/operations.d.ts.map +1 -0
  211. package/dist/hosted-transport/operations.js +128 -0
  212. package/dist/hosted-transport/operations.js.map +1 -0
  213. package/dist/hosted-transport/paged-reads.d.ts +87 -0
  214. package/dist/hosted-transport/paged-reads.d.ts.map +1 -0
  215. package/dist/hosted-transport/paged-reads.js +238 -0
  216. package/dist/hosted-transport/paged-reads.js.map +1 -0
  217. package/dist/hosted-transport/read-adapter.d.ts +256 -0
  218. package/dist/hosted-transport/read-adapter.d.ts.map +1 -0
  219. package/dist/hosted-transport/read-adapter.js +568 -0
  220. package/dist/hosted-transport/read-adapter.js.map +1 -0
  221. package/dist/hosted-transport/root-write.d.ts +114 -0
  222. package/dist/hosted-transport/root-write.d.ts.map +1 -0
  223. package/dist/hosted-transport/root-write.js +171 -0
  224. package/dist/hosted-transport/root-write.js.map +1 -0
  225. package/dist/hosted-transport/whole-document-transport.d.ts +204 -0
  226. package/dist/hosted-transport/whole-document-transport.d.ts.map +1 -0
  227. package/dist/hosted-transport/whole-document-transport.js +447 -0
  228. package/dist/hosted-transport/whole-document-transport.js.map +1 -0
  229. package/dist/index.d.ts +34 -10
  230. package/dist/index.d.ts.map +1 -1
  231. package/dist/index.js +26 -8
  232. package/dist/index.js.map +1 -1
  233. package/dist/indexeddb-backend.d.ts +28 -6
  234. package/dist/indexeddb-backend.d.ts.map +1 -1
  235. package/dist/indexeddb-backend.js +471 -92
  236. package/dist/indexeddb-backend.js.map +1 -1
  237. package/dist/journaled-backend.d.ts +247 -10
  238. package/dist/journaled-backend.d.ts.map +1 -1
  239. package/dist/journaled-backend.js +302 -1
  240. package/dist/journaled-backend.js.map +1 -1
  241. package/dist/kind-authoring.d.ts +170 -0
  242. package/dist/kind-authoring.d.ts.map +1 -0
  243. package/dist/kind-authoring.js +451 -0
  244. package/dist/kind-authoring.js.map +1 -0
  245. package/dist/kind-conformance-error.d.ts +15 -0
  246. package/dist/kind-conformance-error.d.ts.map +1 -0
  247. package/dist/kind-conformance-error.js +20 -0
  248. package/dist/kind-conformance-error.js.map +1 -0
  249. package/dist/kind-coverage.d.ts +99 -0
  250. package/dist/kind-coverage.d.ts.map +1 -0
  251. package/dist/kind-coverage.js +186 -0
  252. package/dist/kind-coverage.js.map +1 -0
  253. package/dist/kind-field-mutation.d.ts +4 -0
  254. package/dist/kind-field-mutation.d.ts.map +1 -1
  255. package/dist/kind-field-mutation.js +28 -3
  256. package/dist/kind-field-mutation.js.map +1 -1
  257. package/dist/kinds-load.js +4 -4
  258. package/dist/kinds-load.js.map +1 -1
  259. package/dist/kinds.d.ts +65 -2
  260. package/dist/kinds.d.ts.map +1 -1
  261. package/dist/kinds.js +341 -21
  262. package/dist/kinds.js.map +1 -1
  263. package/dist/link-types.d.ts +26 -0
  264. package/dist/link-types.d.ts.map +1 -0
  265. package/dist/link-types.js +57 -0
  266. package/dist/link-types.js.map +1 -0
  267. package/dist/links.d.ts +21 -3
  268. package/dist/links.d.ts.map +1 -1
  269. package/dist/links.js +213 -14
  270. package/dist/links.js.map +1 -1
  271. package/dist/managed-document-metadata.d.ts +2 -0
  272. package/dist/managed-document-metadata.d.ts.map +1 -0
  273. package/dist/managed-document-metadata.js +9 -0
  274. package/dist/managed-document-metadata.js.map +1 -0
  275. package/dist/memory-backend.d.ts +2 -2
  276. package/dist/memory-backend.d.ts.map +1 -1
  277. package/dist/memory-backend.js +26 -11
  278. package/dist/memory-backend.js.map +1 -1
  279. package/dist/paths.d.ts +16 -0
  280. package/dist/paths.d.ts.map +1 -1
  281. package/dist/paths.js +25 -0
  282. package/dist/paths.js.map +1 -1
  283. package/dist/platform.d.ts +13 -2
  284. package/dist/platform.d.ts.map +1 -1
  285. package/dist/platform.js +16 -0
  286. package/dist/platform.js.map +1 -1
  287. package/dist/portable-export.d.ts +119 -0
  288. package/dist/portable-export.d.ts.map +1 -0
  289. package/dist/portable-export.js +501 -0
  290. package/dist/portable-export.js.map +1 -0
  291. package/dist/publication-filesystem.d.ts +1 -1
  292. package/dist/publication-filesystem.d.ts.map +1 -1
  293. package/dist/publication-filesystem.js +1 -1
  294. package/dist/publication-filesystem.js.map +1 -1
  295. package/dist/qualified-links.d.ts +67 -0
  296. package/dist/qualified-links.d.ts.map +1 -0
  297. package/dist/qualified-links.js +117 -0
  298. package/dist/qualified-links.js.map +1 -0
  299. package/dist/query-filter.d.ts +16 -2
  300. package/dist/query-filter.d.ts.map +1 -1
  301. package/dist/query-filter.js +40 -1
  302. package/dist/query-filter.js.map +1 -1
  303. package/dist/query-order.d.ts +22 -0
  304. package/dist/query-order.d.ts.map +1 -0
  305. package/dist/query-order.js +42 -0
  306. package/dist/query-order.js.map +1 -0
  307. package/dist/recipe-lifecycle/errors.d.ts +96 -0
  308. package/dist/recipe-lifecycle/errors.d.ts.map +1 -0
  309. package/dist/recipe-lifecycle/errors.js +122 -0
  310. package/dist/recipe-lifecycle/errors.js.map +1 -0
  311. package/dist/recipe-lifecycle/evolution.d.ts +108 -0
  312. package/dist/recipe-lifecycle/evolution.d.ts.map +1 -0
  313. package/dist/recipe-lifecycle/evolution.js +884 -0
  314. package/dist/recipe-lifecycle/evolution.js.map +1 -0
  315. package/dist/recipe-lifecycle/index.d.ts +26 -0
  316. package/dist/recipe-lifecycle/index.d.ts.map +1 -0
  317. package/dist/recipe-lifecycle/index.js +22 -0
  318. package/dist/recipe-lifecycle/index.js.map +1 -0
  319. package/dist/recipe-lifecycle/install.d.ts +127 -0
  320. package/dist/recipe-lifecycle/install.d.ts.map +1 -0
  321. package/dist/recipe-lifecycle/install.js +526 -0
  322. package/dist/recipe-lifecycle/install.js.map +1 -0
  323. package/dist/recipe-lifecycle/legacy-aliases.d.ts +16 -0
  324. package/dist/recipe-lifecycle/legacy-aliases.d.ts.map +1 -0
  325. package/dist/recipe-lifecycle/legacy-aliases.js +51 -0
  326. package/dist/recipe-lifecycle/legacy-aliases.js.map +1 -0
  327. package/dist/recipe-lifecycle/stamp.d.ts +136 -0
  328. package/dist/recipe-lifecycle/stamp.d.ts.map +1 -0
  329. package/dist/recipe-lifecycle/stamp.js +326 -0
  330. package/dist/recipe-lifecycle/stamp.js.map +1 -0
  331. package/dist/recipes.d.ts +29 -1
  332. package/dist/recipes.d.ts.map +1 -1
  333. package/dist/recipes.js +137 -1
  334. package/dist/recipes.js.map +1 -1
  335. package/dist/record-overlay/apply.d.ts +43 -0
  336. package/dist/record-overlay/apply.d.ts.map +1 -0
  337. package/dist/record-overlay/apply.js +527 -0
  338. package/dist/record-overlay/apply.js.map +1 -0
  339. package/dist/record-overlay/canonical.d.ts +22 -0
  340. package/dist/record-overlay/canonical.d.ts.map +1 -0
  341. package/dist/record-overlay/canonical.js +47 -0
  342. package/dist/record-overlay/canonical.js.map +1 -0
  343. package/dist/record-overlay/digest.d.ts +4 -0
  344. package/dist/record-overlay/digest.d.ts.map +1 -0
  345. package/dist/record-overlay/digest.js +11 -0
  346. package/dist/record-overlay/digest.js.map +1 -0
  347. package/dist/record-overlay/errors.d.ts +44 -0
  348. package/dist/record-overlay/errors.d.ts.map +1 -0
  349. package/dist/record-overlay/errors.js +55 -0
  350. package/dist/record-overlay/errors.js.map +1 -0
  351. package/dist/record-overlay/findings.d.ts +5 -0
  352. package/dist/record-overlay/findings.d.ts.map +1 -0
  353. package/dist/record-overlay/findings.js +83 -0
  354. package/dist/record-overlay/findings.js.map +1 -0
  355. package/dist/record-overlay/index.d.ts +23 -0
  356. package/dist/record-overlay/index.d.ts.map +1 -0
  357. package/dist/record-overlay/index.js +21 -0
  358. package/dist/record-overlay/index.js.map +1 -0
  359. package/dist/record-overlay/plan.d.ts +12 -0
  360. package/dist/record-overlay/plan.d.ts.map +1 -0
  361. package/dist/record-overlay/plan.js +285 -0
  362. package/dist/record-overlay/plan.js.map +1 -0
  363. package/dist/record-overlay/policy.d.ts +69 -0
  364. package/dist/record-overlay/policy.d.ts.map +1 -0
  365. package/dist/record-overlay/policy.js +228 -0
  366. package/dist/record-overlay/policy.js.map +1 -0
  367. package/dist/record-overlay/redact.d.ts +3 -0
  368. package/dist/record-overlay/redact.d.ts.map +1 -0
  369. package/dist/record-overlay/redact.js +27 -0
  370. package/dist/record-overlay/redact.js.map +1 -0
  371. package/dist/record-overlay/signal-kind.d.ts +30 -0
  372. package/dist/record-overlay/signal-kind.d.ts.map +1 -0
  373. package/dist/record-overlay/signal-kind.js +38 -0
  374. package/dist/record-overlay/signal-kind.js.map +1 -0
  375. package/dist/record-overlay/signal-text.d.ts +45 -0
  376. package/dist/record-overlay/signal-text.d.ts.map +1 -0
  377. package/dist/record-overlay/signal-text.js +116 -0
  378. package/dist/record-overlay/signal-text.js.map +1 -0
  379. package/dist/record-overlay/source-index.d.ts +19 -0
  380. package/dist/record-overlay/source-index.d.ts.map +1 -0
  381. package/dist/record-overlay/source-index.js +102 -0
  382. package/dist/record-overlay/source-index.js.map +1 -0
  383. package/dist/record-overlay/types.d.ts +291 -0
  384. package/dist/record-overlay/types.d.ts.map +1 -0
  385. package/dist/record-overlay/types.js +2 -0
  386. package/dist/record-overlay/types.js.map +1 -0
  387. package/dist/remote-backend.d.ts +67 -67
  388. package/dist/remote-backend.d.ts.map +1 -1
  389. package/dist/remote-backend.js +169 -201
  390. package/dist/remote-backend.js.map +1 -1
  391. package/dist/remote-document-codec.d.ts +15 -0
  392. package/dist/remote-document-codec.d.ts.map +1 -0
  393. package/dist/remote-document-codec.js +103 -0
  394. package/dist/remote-document-codec.js.map +1 -0
  395. package/dist/remote-error.d.ts +38 -0
  396. package/dist/remote-error.d.ts.map +1 -0
  397. package/dist/remote-error.js +59 -0
  398. package/dist/remote-error.js.map +1 -0
  399. package/dist/remote-operations.d.ts +6 -3
  400. package/dist/remote-operations.d.ts.map +1 -1
  401. package/dist/remote-operations.js +23 -5
  402. package/dist/remote-operations.js.map +1 -1
  403. package/dist/remote-parsers.d.ts +86 -0
  404. package/dist/remote-parsers.d.ts.map +1 -0
  405. package/dist/remote-parsers.js +181 -0
  406. package/dist/remote-parsers.js.map +1 -0
  407. package/dist/remote.d.ts +5 -2
  408. package/dist/remote.d.ts.map +1 -1
  409. package/dist/remote.js +5 -1
  410. package/dist/remote.js.map +1 -1
  411. package/dist/search/backend-source.d.ts +6 -0
  412. package/dist/search/backend-source.d.ts.map +1 -0
  413. package/dist/search/backend-source.js +33 -0
  414. package/dist/search/backend-source.js.map +1 -0
  415. package/dist/search/contract.d.ts +151 -0
  416. package/dist/search/contract.d.ts.map +1 -0
  417. package/dist/search/contract.js +78 -0
  418. package/dist/search/contract.js.map +1 -0
  419. package/dist/search/errors.d.ts +30 -0
  420. package/dist/search/errors.d.ts.map +1 -0
  421. package/dist/search/errors.js +50 -0
  422. package/dist/search/errors.js.map +1 -0
  423. package/dist/search/identity.d.ts +12 -0
  424. package/dist/search/identity.d.ts.map +1 -0
  425. package/dist/search/identity.js +90 -0
  426. package/dist/search/identity.js.map +1 -0
  427. package/dist/search/index.d.ts +16 -0
  428. package/dist/search/index.d.ts.map +1 -0
  429. package/dist/search/index.js +15 -0
  430. package/dist/search/index.js.map +1 -0
  431. package/dist/search/memory-source.d.ts +36 -0
  432. package/dist/search/memory-source.d.ts.map +1 -0
  433. package/dist/search/memory-source.js +235 -0
  434. package/dist/search/memory-source.js.map +1 -0
  435. package/dist/search/rank.d.ts +34 -0
  436. package/dist/search/rank.d.ts.map +1 -0
  437. package/dist/search/rank.js +129 -0
  438. package/dist/search/rank.js.map +1 -0
  439. package/dist/search/row-text.d.ts +38 -0
  440. package/dist/search/row-text.d.ts.map +1 -0
  441. package/dist/search/row-text.js +88 -0
  442. package/dist/search/row-text.js.map +1 -0
  443. package/dist/search/search.d.ts +28 -0
  444. package/dist/search/search.d.ts.map +1 -0
  445. package/dist/search/search.js +257 -0
  446. package/dist/search/search.js.map +1 -0
  447. package/dist/search/source.d.ts +67 -0
  448. package/dist/search/source.d.ts.map +1 -0
  449. package/dist/search/source.js +2 -0
  450. package/dist/search/source.js.map +1 -0
  451. package/dist/search/text.d.ts +47 -0
  452. package/dist/search/text.d.ts.map +1 -0
  453. package/dist/search/text.js +148 -0
  454. package/dist/search/text.js.map +1 -0
  455. package/dist/site-capabilities.d.ts +339 -0
  456. package/dist/site-capabilities.d.ts.map +1 -0
  457. package/dist/site-capabilities.js +717 -0
  458. package/dist/site-capabilities.js.map +1 -0
  459. package/dist/source-engine/guard.d.ts +82 -0
  460. package/dist/source-engine/guard.d.ts.map +1 -0
  461. package/dist/source-engine/guard.js +396 -0
  462. package/dist/source-engine/guard.js.map +1 -0
  463. package/dist/source-engine/index.d.ts +24 -0
  464. package/dist/source-engine/index.d.ts.map +1 -0
  465. package/dist/source-engine/index.js +20 -0
  466. package/dist/source-engine/index.js.map +1 -0
  467. package/dist/source-engine/machine-state.d.ts +74 -0
  468. package/dist/source-engine/machine-state.d.ts.map +1 -0
  469. package/dist/source-engine/machine-state.js +48 -0
  470. package/dist/source-engine/machine-state.js.map +1 -0
  471. package/dist/source-engine/observe.d.ts +18 -0
  472. package/dist/source-engine/observe.d.ts.map +1 -0
  473. package/dist/source-engine/observe.js +598 -0
  474. package/dist/source-engine/observe.js.map +1 -0
  475. package/dist/source-engine/robots.d.ts +53 -0
  476. package/dist/source-engine/robots.d.ts.map +1 -0
  477. package/dist/source-engine/robots.js +158 -0
  478. package/dist/source-engine/robots.js.map +1 -0
  479. package/dist/source-engine/types.d.ts +285 -0
  480. package/dist/source-engine/types.d.ts.map +1 -0
  481. package/dist/source-engine/types.js +2 -0
  482. package/dist/source-engine/types.js.map +1 -0
  483. package/dist/source-harness/conformance.d.ts +16 -0
  484. package/dist/source-harness/conformance.d.ts.map +1 -0
  485. package/dist/source-harness/conformance.js +265 -0
  486. package/dist/source-harness/conformance.js.map +1 -0
  487. package/dist/source-harness/fixture.d.ts +95 -0
  488. package/dist/source-harness/fixture.d.ts.map +1 -0
  489. package/dist/source-harness/fixture.js +261 -0
  490. package/dist/source-harness/fixture.js.map +1 -0
  491. package/dist/source-harness/index.d.ts +22 -0
  492. package/dist/source-harness/index.d.ts.map +1 -0
  493. package/dist/source-harness/index.js +19 -0
  494. package/dist/source-harness/index.js.map +1 -0
  495. package/dist/source-harness/peer.d.ts +74 -0
  496. package/dist/source-harness/peer.d.ts.map +1 -0
  497. package/dist/source-harness/peer.js +106 -0
  498. package/dist/source-harness/peer.js.map +1 -0
  499. package/dist/storage.d.ts +6 -2
  500. package/dist/storage.d.ts.map +1 -1
  501. package/dist/storage.js +4 -1
  502. package/dist/storage.js.map +1 -1
  503. package/dist/types.d.ts +33 -5
  504. package/dist/types.d.ts.map +1 -1
  505. package/dist/uncertain-write.d.ts +156 -19
  506. package/dist/uncertain-write.d.ts.map +1 -1
  507. package/dist/uncertain-write.js +90 -31
  508. package/dist/uncertain-write.js.map +1 -1
  509. package/dist/versioning.d.ts +9 -4
  510. package/dist/versioning.d.ts.map +1 -1
  511. package/dist/versioning.js +9 -4
  512. package/dist/versioning.js.map +1 -1
  513. package/dist/write-identity.d.ts +5 -0
  514. package/dist/write-identity.d.ts.map +1 -0
  515. package/dist/write-identity.js +9 -0
  516. package/dist/write-identity.js.map +1 -0
  517. package/package.json +94 -2
@@ -2,12 +2,14 @@
2
2
  * `RemoteBackend` — a {@link StorageBackend} implemented over the wire-protocol v0
3
3
  * reference contract (`docs/WIRE-PROTOCOL.md`, `@superbee/server`).
4
4
  *
5
- * This is the client half of the seam over HTTP: every method maps directly to a wire endpoint,
6
- * and response versions remain the same content-addressed {@link Version} tokens local backends
7
- * produce. Tri-backend contract tests pin that invariant.
5
+ * This is the client half of the seam over HTTP: every method maps directly to a wire endpoint
6
+ * (a guarded document write may first ask `GET /v0/capabilities` whether the host records
7
+ * outcomes; see {@link RemoteBackendOptions.maxRetries}), and response versions remain the same
8
+ * content-addressed {@link Version} tokens local backends produce. Tri-backend contract tests pin
9
+ * that invariant.
8
10
  *
9
11
  * Zero new dependencies: it calls an injectable {@link FetchLike} transport
10
- * (defaulting to the global `fetch`, available on Node >= 20) with a constructed
12
+ * (defaulting to the global `fetch`, available in every supported Node runtime) with a constructed
11
13
  * `Request`. That means the SAME adapter runs against a real HTTP server, or — in
12
14
  * tests — directly against an in-process `createRouter(bundle)` function with no
13
15
  * sockets: `createRouter` returns exactly the `(req: Request) => Promise<Response>`
@@ -42,29 +44,16 @@
42
44
  */
43
45
  import { DEFAULT_BLOB_CONTENT_TYPE } from "./content-type.js";
44
46
  import { InvalidInputError } from "./errors.js";
45
- import { headsDigest, isHeadsDigest } from "./heads-digest.js";
47
+ import { MalformedDocumentError } from "./frontmatter-contract.js";
48
+ import { encodeRemoteDocument } from "./remote-document-codec.js";
49
+ import { RemoteError, malformed } from "./remote-error.js";
50
+ import { SNAPSHOT_TRUNCATED, parseHeadsAnswer, readSnapshotStream } from "./remote-parsers.js";
46
51
  import { assertSafeBlobKey, assertSafeConceptId, assertSafeReservedDir, assertSafeReservedFilename, compareStorageKeys } from "./paths.js";
47
- import { isRequestIdentity } from "./uncertain-write.js";
48
- import { VersionConflict, stripETagWrapper } from "./version-transport.js";
49
- /**
50
- * A non-2xx wire response that is neither a `404` (ENOENT-shaped) nor a `412`
51
- * ({@link VersionConflict}) — the generic case, carrying the error envelope's `code` alongside
52
- * the raw HTTP `status`, so a caller can distinguish e.g.
53
- * `AUTH_REQUIRED` (401, an unauthenticated/misconfigured `--remote`) from `RUNTIME` (5xx, a
54
- * genuine server-side bug) instead of both collapsing into a generically-classified `Error`.
55
- */
56
- export class RemoteError extends Error {
57
- /** The envelope's `code` field, or a status-derived guess when the envelope is missing/unparseable. */
58
- code;
59
- /** The raw HTTP status that produced this error. */
60
- status;
61
- constructor(message, code, status, cause) {
62
- super(message, cause === undefined ? undefined : { cause });
63
- this.name = "RemoteError";
64
- this.code = code;
65
- this.status = status;
66
- }
67
- }
52
+ import { isRequestIdentity, mintRequestId } from "./uncertain-write.js";
53
+ import { VersionConflict, isContentVersion, stripETagWrapper } from "./version-transport.js";
54
+ // The typed rejection lives in `remote-error.ts`, shared with the heads and snapshot parsers this
55
+ // backend calls; it stays importable from here for every existing consumer.
56
+ export { RemoteError } from "./remote-error.js";
68
57
  /** An ENOENT-shaped rejection so missing-document handling matches the local adapters. */
69
58
  function notFound(id) {
70
59
  const err = new Error(`no concept document '${id}'`);
@@ -111,6 +100,18 @@ function assertValidExpectedVersion(expectedVersion) {
111
100
  }
112
101
  /** The header that carries a write's durable request identity (`docs/WIRE-PROTOCOL.md`). */
113
102
  const IDENTITY_HEADER = "Idempotency-Key";
103
+ /** The wire's `400 USAGE` message from a host that records no outcomes, answering any request that carries a key. */
104
+ const IDENTITY_UNSUPPORTED = "request identity is not supported by this host";
105
+ /** Whether `res` is a host's refusal of request identity itself, as opposed to a recorded or document refusal. */
106
+ async function refusesIdentity(res) {
107
+ try {
108
+ const envelope = (await res.json());
109
+ return envelope?.error?.code === "USAGE" && envelope.error.message === IDENTITY_UNSUPPORTED;
110
+ }
111
+ catch {
112
+ return false;
113
+ }
114
+ }
114
115
  /**
115
116
  * Reject a request identity the wire would refuse before any request is sent, so a malformed
116
117
  * key is a caller-side `InvalidInputError` rather than a `400` the caller might mistake for a
@@ -123,129 +124,10 @@ function assertRequestIdentity(requestId) {
123
124
  }
124
125
  /** The lookup route's `200` body: a recorded outcome, never `unknown`. */
125
126
  const RECORDED_OUTCOME_KINDS = new Set(["committed", "conflict", "refused"]);
126
- /** A snapshot body that ended, or failed, before its terminator arrived with the announced count. */
127
- const SNAPSHOT_TRUNCATED = "SNAPSHOT_TRUNCATED";
128
- /**
129
- * A snapshot whose body arrived whole, with its terminator and the announced count, but whose
130
- * rows digest to something other than the header announced. Not truncation: re-requesting will
131
- * not necessarily repair it, since the authority contradicted itself. A consumer discards the
132
- * documents' claim to the header digest either way.
133
- */
134
- const SNAPSHOT_DIGEST_MISMATCH = "SNAPSHOT_DIGEST_MISMATCH";
135
- function isDocumentHead(value) {
136
- if (typeof value !== "object" || value === null)
137
- return false;
138
- const head = value;
139
- return typeof head.id === "string" && typeof head.version === "string";
140
- }
141
- /** A wire payload the authority produced but the contract does not admit: not retried, not truncation. */
142
- function malformed(message) {
143
- return new RemoteError(message, "RUNTIME", 502);
144
- }
145
127
  /** Quote a bare digest for `If-None-Match`; an already quoted or weak form passes through. */
146
128
  function etagForm(token) {
147
129
  return token.startsWith('"') || token.startsWith("W/") ? token : `"${token}"`;
148
130
  }
149
- /**
150
- * Split a response body into its NDJSON lines as they arrive, decoding UTF-8 across chunk
151
- * boundaries. Only `TextDecoder` and the Web Streams reader are used, so the same code runs in a
152
- * browser. A partial trailing line at the end of the body is a cut line and is not yielded; a
153
- * transport failure while reading is reported as truncation, since either way the terminator
154
- * never arrived. Leaving the loop early cancels the reader so the connection is released.
155
- */
156
- async function* ndjsonLines(body, status) {
157
- const reader = body.getReader();
158
- const decoder = new TextDecoder();
159
- let buffered = "";
160
- try {
161
- for (;;) {
162
- let chunk;
163
- try {
164
- chunk = await reader.read();
165
- }
166
- catch (cause) {
167
- throw new RemoteError("snapshot body failed before its end line arrived", SNAPSHOT_TRUNCATED, status, cause);
168
- }
169
- buffered += decoder.decode(chunk.value, { stream: !chunk.done });
170
- let start = 0;
171
- for (let newline = buffered.indexOf("\n"); newline !== -1; newline = buffered.indexOf("\n", start)) {
172
- yield buffered.slice(start, newline);
173
- start = newline + 1;
174
- }
175
- buffered = buffered.slice(start);
176
- if (chunk.done)
177
- return;
178
- }
179
- }
180
- finally {
181
- await reader.cancel().catch(() => undefined);
182
- }
183
- }
184
- function parseSnapshotLine(line) {
185
- let record;
186
- try {
187
- record = JSON.parse(line);
188
- }
189
- catch {
190
- throw malformed("snapshot line is not JSON");
191
- }
192
- if (typeof record !== "object" || record === null)
193
- throw malformed("snapshot line is not a JSON object");
194
- return record;
195
- }
196
- function parseSnapshotHeader(line) {
197
- const record = parseSnapshotLine(line);
198
- if (record.kind !== "snapshot")
199
- throw malformed("snapshot did not begin with its header line");
200
- if (typeof record.count !== "number" || !Number.isInteger(record.count) || record.count < 0) {
201
- throw malformed("snapshot header carries no document count");
202
- }
203
- if (!isHeadsDigest(record.digest))
204
- throw malformed("snapshot header carries no well-formed digest");
205
- return { count: record.count, digest: record.digest };
206
- }
207
- /**
208
- * The document lines of a snapshot, ending normally only at an `end` line whose count equals
209
- * both the header's announcement and the documents actually seen, and only when the digest
210
- * recomputed over the received heads equals the header's. Anything else is a rejection: a body
211
- * that ends first is `SNAPSHOT_TRUNCATED`; a whole body whose heads digest differently is
212
- * `SNAPSHOT_DIGEST_MISMATCH`; a line the contract does not admit is malformed. The digest is the
213
- * client's own check of the listing it is about to trust: a count and a terminator say the body
214
- * is whole, only the recipe says it is the state the header named.
215
- */
216
- async function* snapshotDocuments(lines, header, status) {
217
- let seen = 0;
218
- const received = [];
219
- for await (const line of lines) {
220
- const record = parseSnapshotLine(line);
221
- if (record.kind === "doc") {
222
- if (typeof record.id !== "string" || typeof record.version !== "string" || typeof record.body !== "string") {
223
- throw malformed("snapshot doc line lacks id, version, or body");
224
- }
225
- if (typeof record.frontmatter !== "object" || record.frontmatter === null || Array.isArray(record.frontmatter)) {
226
- throw malformed("snapshot doc line lacks a frontmatter object");
227
- }
228
- seen += 1;
229
- if (seen > header.count)
230
- throw malformed(`snapshot delivered more than the ${header.count} announced document(s)`);
231
- received.push({ id: record.id, version: record.version });
232
- yield { id: record.id, version: record.version, frontmatter: record.frontmatter, body: record.body };
233
- continue;
234
- }
235
- if (record.kind === "end") {
236
- if (record.count !== seen || seen !== header.count) {
237
- throw new RemoteError(`snapshot end line counts ${String(record.count)} document(s), but ${seen} of ${header.count} announced arrived`, SNAPSHOT_TRUNCATED, status);
238
- }
239
- const recomputed = headsDigest(received);
240
- if (recomputed !== header.digest) {
241
- throw new RemoteError(`snapshot header announced digest ${header.digest}, but its ${seen} document(s) digest to ${recomputed}`, SNAPSHOT_DIGEST_MISMATCH, status);
242
- }
243
- return;
244
- }
245
- throw malformed(`snapshot line has unexpected kind ${JSON.stringify(record.kind)}`);
246
- }
247
- throw new RemoteError(`snapshot ended after ${seen} of ${header.count} document(s) without its end line`, SNAPSHOT_TRUNCATED, status);
248
- }
249
131
  /**
250
132
  * Transient HTTP statuses worth retrying: 500 (a Cloudflare D1 cold-start surfaces as a 500
251
133
  * "storage caused object to be reset" the first time a hibernated database is hit), plus the edge
@@ -253,6 +135,18 @@ async function* snapshotDocuments(lines, header, status) {
253
135
  * REAL result, never retried; 501/505 are terminal server bugs, not transient, so also excluded.
254
136
  */
255
137
  const RETRIABLE_STATUS = new Set([500, 502, 503, 504]);
138
+ /** A `500` naming a stored document that does not parse: a retry reads the same bytes again. */
139
+ async function namesMalformedDocument(res) {
140
+ if (res.status !== 500)
141
+ return false;
142
+ try {
143
+ const envelope = (await res.clone().json());
144
+ return typeof envelope?.error?.details?.malformed?.reason === "string";
145
+ }
146
+ catch {
147
+ return false;
148
+ }
149
+ }
256
150
  /** Retry-backoff timing: exponential base doubling, capped, with jitter to avoid a thundering herd. */
257
151
  const RETRY_BASE_MS = 150;
258
152
  const RETRY_CAP_MS = 2000;
@@ -298,6 +192,8 @@ export class RemoteBackend {
298
192
  fetchImpl;
299
193
  authToken;
300
194
  maxRetries;
195
+ /** The pending or settled answer to whether this host records outcomes; see {@link recordsOutcomes}. */
196
+ operationsSupport;
301
197
  constructor(options) {
302
198
  this.baseUrl = trimTrailingSlashes(options.baseUrl);
303
199
  this.bundle = options.bundle;
@@ -328,19 +224,23 @@ export class RemoteBackend {
328
224
  // object reset" when a hibernated database is first hit; also 502/503/504 from the edge) or a
329
225
  // network/transport error — with exponential backoff + jitter, so a hibernated-backend hiccup is
330
226
  // transparent instead of a hard failure. A REAL result (2xx, or 4xx incl. 412 VersionConflict,
331
- // or 401) returns/throws immediately, never retried. Safe because every op is content-addressed
332
- // + CAS: a retried write lands the same version or a conflict (possibly SPURIOUS — a prior
333
- // attempt may have committed before its response was lost — but never silent data loss); a
334
- // retried read is idempotent. `send` rebuilds the Request per attempt from `init` (bodies are
335
- // strings/bytes, so reusable — no consumed-stream hazard).
227
+ // or 401) returns/throws immediately, never retried. A retried read is idempotent. `send`
228
+ // rebuilds the Request per attempt from the same `init` (bodies are strings/bytes, so reusable —
229
+ // no consumed-stream hazard), so every attempt carries the same headers, `Idempotency-Key`
230
+ // included.
336
231
  //
337
- // A write that carries `Idempotency-Key` is different again: its transient retries are true
338
- // replays, answered from the authority's recorded outcome, so a retry after a lost response
232
+ // A write that carries `Idempotency-Key` is therefore retried as a true replay, answered from
233
+ // the authority's recorded outcome while it keeps that record: a retry after a lost response
339
234
  // can neither apply twice nor surface a spurious conflict against its own earlier application.
235
+ // `write` and `delete` attach one to guarded document writes on a host with `operations` (see
236
+ // `maxRetries` for which). A guarded write without one lands the same version or a conflict
237
+ // (possibly SPURIOUS — a prior attempt may have committed before its response was lost), except
238
+ // that a document returned in between to exactly the state its premise names (the same bytes
239
+ // hash to the same version) lets the retry apply again over that change.
340
240
  for (let attempt = 0;; attempt++) {
341
241
  try {
342
242
  const res = await this.fetchImpl(new Request(url, init));
343
- if (RETRIABLE_STATUS.has(res.status) && attempt < this.maxRetries) {
243
+ if (RETRIABLE_STATUS.has(res.status) && attempt < this.maxRetries && !(await namesMalformedDocument(res))) {
344
244
  await delay(retryDelayMs(attempt));
345
245
  continue;
346
246
  }
@@ -369,6 +269,12 @@ export class RemoteBackend {
369
269
  const actual = envelope?.error?.details?.actual ?? null;
370
270
  return new VersionConflict(fallbackId, expected, actual);
371
271
  }
272
+ const malformedDoc = envelope?.error?.details?.malformed;
273
+ if (malformedDoc && typeof malformedDoc.reason === "string") {
274
+ // The server could read the request but not the stored document: the same failure a local
275
+ // scan raises, so `onSkip` callers can set this one document aside.
276
+ return new MalformedDocumentError(typeof malformedDoc.id === "string" ? malformedDoc.id : fallbackId, new Error(malformedDoc.reason));
277
+ }
372
278
  const message = envelope?.error?.message ?? `wire request failed with status ${res.status}`;
373
279
  // The envelope's own `code` wins when present (every route in this repo's servers emits
374
280
  // one); a status-derived guess covers a malformed/absent envelope or a conformant-but-
@@ -433,15 +339,19 @@ export class RemoteBackend {
433
339
  headers["If-Match"] = options.expectedVersion;
434
340
  if (options.actor)
435
341
  headers["X-Actor"] = options.actor;
342
+ // Captured before the capability question can yield, so the payload is the document as it
343
+ // stood when `write` was called and an unencodable one is refused before any request.
344
+ const body = encodeRemoteDocument(doc.frontmatter, doc.body ?? "");
345
+ let minted = false;
436
346
  if (options.requestId !== undefined) {
437
347
  assertRequestIdentity(options.requestId);
438
348
  headers[IDENTITY_HEADER] = options.requestId;
439
349
  }
440
- const res = await this.send(`/docs/${encodeId(id)}`, {
441
- method: "PUT",
442
- headers,
443
- body: JSON.stringify({ frontmatter: doc.frontmatter, body: doc.body ?? "" }),
444
- });
350
+ else if (options.expectedVersion !== undefined && (await this.recordsOutcomes())) {
351
+ headers[IDENTITY_HEADER] = mintRequestId();
352
+ minted = true;
353
+ }
354
+ const res = await this.sendDocWrite(`/docs/${encodeId(id)}`, { method: "PUT", headers, body }, minted);
445
355
  if (!res.ok)
446
356
  throw await this.toError(res, id);
447
357
  const payload = (await res.json());
@@ -449,10 +359,11 @@ export class RemoteBackend {
449
359
  }
450
360
  /**
451
361
  * `GET /v0/capabilities`, deployment-scoped: what this authority implements. `operations` says
452
- * whether it records outcomes by request identity. A host without it ignores `Idempotency-Key`
453
- * and answers the lookup route with a route-miss `404`, which {@link lookupOperation} cannot
454
- * tell from "never recorded"; a consumer that relies on identity checks this once before it
455
- * sends any intent. Missing booleans read as `false`.
362
+ * whether it records outcomes by request identity. The reference router without it refuses any
363
+ * request carrying `Idempotency-Key`, and the lookup route, with `400 USAGE`; a host that lacks
364
+ * the lookup route altogether answers it with a route-miss `404`, which {@link lookupOperation}
365
+ * cannot tell from "never recorded". A consumer that relies on identity checks this once before
366
+ * it sends any intent. Missing booleans read as `false`.
456
367
  */
457
368
  async wireCapabilities() {
458
369
  const res = await this.send("/v0/capabilities", { method: "GET" }, "deployment");
@@ -471,16 +382,65 @@ export class RemoteBackend {
471
382
  snapshot: flag("snapshot"),
472
383
  };
473
384
  }
385
+ /**
386
+ * Whether this host records outcomes by request identity, asked through `GET /v0/capabilities`
387
+ * and shared by concurrent callers. A host that answers anything but a `2xx` with
388
+ * `operations: true` is treated as not recording them, since a host that does not record them
389
+ * refuses a key with `400`. That answer is kept for the backend's lifetime, except that a
390
+ * transient status still returned after `send`'s retries, or a transport failure, is not kept:
391
+ * the former sends this write unidentified, and the latter rejects the write before it is sent.
392
+ * A kept yes is also dropped when a minted key meets the host's identity refusal; see
393
+ * {@link sendDocWrite}.
394
+ */
395
+ recordsOutcomes() {
396
+ this.operationsSupport ??= this.probeOperations();
397
+ return this.operationsSupport;
398
+ }
399
+ async probeOperations() {
400
+ let res;
401
+ try {
402
+ res = await this.send("/v0/capabilities", { method: "GET" }, "deployment");
403
+ }
404
+ catch (err) {
405
+ this.operationsSupport = undefined;
406
+ throw err;
407
+ }
408
+ if (RETRIABLE_STATUS.has(res.status))
409
+ this.operationsSupport = undefined;
410
+ if (!res.ok)
411
+ return false;
412
+ try {
413
+ const payload = (await res.json());
414
+ return payload?.operations === true;
415
+ }
416
+ catch {
417
+ return false;
418
+ }
419
+ }
420
+ /**
421
+ * Send a document `PUT` or `DELETE`. When its `Idempotency-Key` was minted here, a kept
422
+ * `operations` answer may be stale: a host that has since lost its outcome store refuses every
423
+ * key with the wire's `400` {@link IDENTITY_UNSUPPORTED} before applying anything. That answer
424
+ * is dropped and the write is sent once more without a key, as to any host without
425
+ * `operations`. A caller's own `requestId` is never dropped, so its refusal is the answer.
426
+ */
427
+ async sendDocWrite(path, init, minted) {
428
+ const res = await this.send(path, init);
429
+ if (!minted || res.status !== 400 || !(await refusesIdentity(res.clone())))
430
+ return res;
431
+ this.operationsSupport = undefined;
432
+ const { [IDENTITY_HEADER]: _refused, ...headers } = init.headers;
433
+ return this.send(path, { ...init, headers });
434
+ }
474
435
  /**
475
436
  * `GET /heads`: every document id and version the authority holds, under one digest, or
476
437
  * `null` when `ifNoneMatch` named the digest it still holds (a `304`: nothing changed). A
477
438
  * `200` is diffed against the caller's own copy: an id missing from `heads` was deleted, a
478
439
  * differing version changed. A `200` without a well-formed digest, whose `count` and rows
479
440
  * disagree, or whose rows digest by the documented recipe to something other than the served
480
- * digest, is rejected rather than trusted, as is a `304` to a request that sent no
481
- * `ifNoneMatch`. The recomputation is what stops a listing that is whole by its own count
482
- * but not the state its digest names (a shortened listing under the real digest) from being
483
- * diffed as a mass deletion. Not part of the {@link StorageBackend} seam.
441
+ * digest, is rejected rather than trusted ({@link parseHeadsAnswer} owns that admission), as
442
+ * is a `304` to a request that sent no `ifNoneMatch`. Not part of the {@link StorageBackend}
443
+ * seam.
484
444
  */
485
445
  async heads(options = {}) {
486
446
  const headers = {};
@@ -496,21 +456,7 @@ export class RemoteBackend {
496
456
  }
497
457
  if (!res.ok)
498
458
  throw await this.toError(res, "heads");
499
- const payload = (await res.json());
500
- if (!isHeadsDigest(payload?.digest))
501
- throw malformed("wire heads answered without a well-formed digest");
502
- if (!Array.isArray(payload.heads) || !payload.heads.every(isDocumentHead)) {
503
- throw malformed("wire heads answered without a heads array of { id, version } rows");
504
- }
505
- if (payload.count !== payload.heads.length) {
506
- throw malformed(`wire heads count ${String(payload.count)} disagrees with its ${payload.heads.length} row(s)`);
507
- }
508
- const heads = payload.heads.map(({ id, version }) => ({ id, version }));
509
- const recomputed = headsDigest(heads);
510
- if (recomputed !== payload.digest) {
511
- throw malformed(`wire heads served digest ${payload.digest}, but its ${heads.length} row(s) digest to ${recomputed}`);
512
- }
513
- return { digest: payload.digest, heads };
459
+ return parseHeadsAnswer(await res.json());
514
460
  }
515
461
  /**
516
462
  * `GET /snapshot`: the whole bundle in one response. The header line is parsed before this
@@ -518,8 +464,9 @@ export class RemoteBackend {
518
464
  * the documents then stream through {@link RemoteSnapshot.docs}. Transient retry applies only
519
465
  * to obtaining the response: a body cut mid-stream is reported to the consumer as
520
466
  * `SNAPSHOT_TRUNCATED`, a whole body whose heads do not digest to the header's announcement as
521
- * `SNAPSHOT_DIGEST_MISMATCH`, and re-requesting is the consumer's decision. Reserved files are
522
- * not part of a snapshot. Not part of the {@link StorageBackend} seam.
467
+ * `SNAPSHOT_DIGEST_MISMATCH` ({@link readSnapshotStream} owns the grammar), and re-requesting
468
+ * is the consumer's decision. Reserved files are not part of a snapshot. Not part of the
469
+ * {@link StorageBackend} seam.
523
470
  */
524
471
  async snapshot() {
525
472
  const res = await this.send("/snapshot", { method: "GET" });
@@ -527,19 +474,7 @@ export class RemoteBackend {
527
474
  throw await this.toError(res, "snapshot");
528
475
  if (!res.body)
529
476
  throw new RemoteError("snapshot response carried no body", SNAPSHOT_TRUNCATED, res.status);
530
- const lines = ndjsonLines(res.body, res.status);
531
- const first = await lines.next();
532
- if (first.done)
533
- throw new RemoteError("snapshot ended before its header line", SNAPSHOT_TRUNCATED, res.status);
534
- let header;
535
- try {
536
- header = parseSnapshotHeader(first.value);
537
- }
538
- catch (err) {
539
- await lines.return(undefined);
540
- throw err;
541
- }
542
- return { header, docs: snapshotDocuments(lines, header, res.status) };
477
+ return readSnapshotStream(res.body, { status: res.status });
543
478
  }
544
479
  /**
545
480
  * `GET /operations/{requestId}`: the authority's recorded outcome for an identified write, or
@@ -575,11 +510,14 @@ export class RemoteBackend {
575
510
  * {@link RemoteBackend.queryHeads} are both thin row-mappings over it, so a wire
576
511
  * pagination change cannot make the two scans silently paginate differently.
577
512
  */
578
- async pageDocs(baseParams, mapRow, errorContext) {
513
+ async pageDocs(baseParams, mapRow, errorContext, skipped) {
579
514
  const rows = [];
580
515
  let cursor;
581
516
  for (;;) {
582
517
  const params = new URLSearchParams(baseParams);
518
+ // Ask the server to leave an unparsable document out and name it, rather than fail the page.
519
+ if (skipped)
520
+ params.set("malformed", "skip");
583
521
  if (cursor)
584
522
  params.set("cursor", cursor);
585
523
  const qs = params.toString();
@@ -589,6 +527,13 @@ export class RemoteBackend {
589
527
  const payload = (await res.json());
590
528
  for (const row of payload.docs)
591
529
  rows.push(mapRow(row));
530
+ if (skipped && Array.isArray(payload.skipped)) {
531
+ for (const entry of payload.skipped) {
532
+ if (typeof entry?.id !== "string")
533
+ continue;
534
+ skipped.set(entry.id, typeof entry.reason === "string" ? entry.reason : "malformed frontmatter");
535
+ }
536
+ }
592
537
  if (!payload.next_cursor)
593
538
  break;
594
539
  cursor = payload.next_cursor;
@@ -599,7 +544,11 @@ export class RemoteBackend {
599
544
  const params = new URLSearchParams();
600
545
  if (prefix)
601
546
  params.set("prefix", prefix);
602
- return (await this.pageDocs(params, (row) => row.id, prefix ?? "")).sort(compareStorageKeys);
547
+ // A document the server could not parse still exists: it is listed, and reading it raises
548
+ // the same MalformedDocumentError a local read does.
549
+ const skipped = new Map();
550
+ const ids = await this.pageDocs(params, (row) => row.id, prefix ?? "", skipped);
551
+ return [...new Set([...ids, ...skipped.keys()])].sort(compareStorageKeys);
603
552
  }
604
553
  /**
605
554
  * The seam's OPTIONAL head-projection push-down, over the SAME `GET /docs` route
@@ -612,7 +561,7 @@ export class RemoteBackend {
612
561
  * `docs/WIRE-PROTOCOL.md`); the engine's `queryHeads` re-filter covers it, per the
613
562
  * seam contract (over-returning is fine; semantics live in core).
614
563
  */
615
- async queryHeads(filter = {}) {
564
+ async queryHeads(filter = {}, options = {}) {
616
565
  const params = new URLSearchParams();
617
566
  params.set("fields", "frontmatter");
618
567
  if (filter.prefix)
@@ -621,7 +570,17 @@ export class RemoteBackend {
621
570
  params.set("type", filter.type);
622
571
  for (const tag of filter.tags ?? [])
623
572
  params.append("tag", tag);
624
- return this.pageDocs(params, (row) => ({ id: row.id, frontmatter: row.frontmatter, version: row.version }), filter.prefix ?? "");
573
+ const skipped = new Map();
574
+ const rows = await this.pageDocs(params, (row) => ({ id: row.id, frontmatter: row.frontmatter, version: row.version }), filter.prefix ?? "", skipped);
575
+ // The server leaves a malformed document out of the listing and names it. A caller that
576
+ // asked for no skip report keeps the scan's fail-loud contract.
577
+ const named = [...skipped].sort(([a], [b]) => compareStorageKeys(a, b));
578
+ if (named.length > 0 && !options.onSkip) {
579
+ throw new MalformedDocumentError(named[0][0], new Error(named[0][1]));
580
+ }
581
+ for (const [id, reason] of named)
582
+ options.onSkip?.({ id, reason });
583
+ return rows;
625
584
  }
626
585
  async versions(id) {
627
586
  assertSafeConceptId(id);
@@ -687,11 +646,20 @@ export class RemoteBackend {
687
646
  const headers = {};
688
647
  if (options.expectedVersion !== undefined)
689
648
  headers["If-Match"] = options.expectedVersion;
649
+ let minted = false;
690
650
  if (options.requestId !== undefined) {
691
651
  assertRequestIdentity(options.requestId);
692
652
  headers[IDENTITY_HEADER] = options.requestId;
693
653
  }
694
- const res = await this.send(`/docs/${encodeId(id)}`, { method: "DELETE", headers });
654
+ else if (options.expectedVersion !== undefined &&
655
+ isContentVersion(stripETagWrapper(options.expectedVersion)) &&
656
+ (await this.recordsOutcomes())) {
657
+ // The wire identifies a delete only under a content-version premise; any other premise
658
+ // stays an unidentified request rather than becoming a `400`.
659
+ headers[IDENTITY_HEADER] = mintRequestId();
660
+ minted = true;
661
+ }
662
+ const res = await this.sendDocWrite(`/docs/${encodeId(id)}`, { method: "DELETE", headers }, minted);
695
663
  if (!res.ok)
696
664
  throw await this.toError(res, id);
697
665
  const payload = (await res.json());