@enbox/dwn-sdk-js 0.0.6 → 0.0.8

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 (527) hide show
  1. package/dist/browser.mjs +8 -8
  2. package/dist/browser.mjs.map +4 -4
  3. package/dist/esm/generated/precompiled-validators.js +762 -911
  4. package/dist/esm/generated/precompiled-validators.js.map +1 -1
  5. package/dist/esm/src/core/abstract-message.js +4 -0
  6. package/dist/esm/src/core/abstract-message.js.map +1 -1
  7. package/dist/esm/src/core/auth.js +22 -33
  8. package/dist/esm/src/core/auth.js.map +1 -1
  9. package/dist/esm/src/core/constants.js +11 -0
  10. package/dist/esm/src/core/constants.js.map +1 -0
  11. package/dist/esm/src/core/core-protocol.js +44 -0
  12. package/dist/esm/src/core/core-protocol.js.map +1 -0
  13. package/dist/esm/src/core/dwn-constant.js +7 -7
  14. package/dist/esm/src/core/dwn-constant.js.map +1 -1
  15. package/dist/esm/src/core/dwn-error.js +10 -12
  16. package/dist/esm/src/core/dwn-error.js.map +1 -1
  17. package/dist/esm/src/core/grant-authorization.js +50 -52
  18. package/dist/esm/src/core/grant-authorization.js.map +1 -1
  19. package/dist/esm/src/core/message.js +85 -116
  20. package/dist/esm/src/core/message.js.map +1 -1
  21. package/dist/esm/src/core/messages-grant-authorization.js +63 -78
  22. package/dist/esm/src/core/messages-grant-authorization.js.map +1 -1
  23. package/dist/esm/src/core/protocol-authorization-action.js +266 -0
  24. package/dist/esm/src/core/protocol-authorization-action.js.map +1 -0
  25. package/dist/esm/src/core/protocol-authorization-validation.js +321 -0
  26. package/dist/esm/src/core/protocol-authorization-validation.js.map +1 -0
  27. package/dist/esm/src/core/protocol-authorization.js +144 -741
  28. package/dist/esm/src/core/protocol-authorization.js.map +1 -1
  29. package/dist/esm/src/core/protocols-grant-authorization.js +24 -38
  30. package/dist/esm/src/core/protocols-grant-authorization.js.map +1 -1
  31. package/dist/esm/src/core/record-chain.js +64 -0
  32. package/dist/esm/src/core/record-chain.js.map +1 -0
  33. package/dist/esm/src/core/records-grant-authorization.js +53 -72
  34. package/dist/esm/src/core/records-grant-authorization.js.map +1 -1
  35. package/dist/esm/src/core/resumable-task-manager.js +50 -65
  36. package/dist/esm/src/core/resumable-task-manager.js.map +1 -1
  37. package/dist/esm/src/core/tenant-gate.js +2 -13
  38. package/dist/esm/src/core/tenant-gate.js.map +1 -1
  39. package/dist/esm/src/dwn.js +108 -101
  40. package/dist/esm/src/dwn.js.map +1 -1
  41. package/dist/esm/src/event-stream/event-emitter-event-log.js +204 -0
  42. package/dist/esm/src/event-stream/event-emitter-event-log.js.map +1 -0
  43. package/dist/esm/src/handlers/messages-read.js +67 -81
  44. package/dist/esm/src/handlers/messages-read.js.map +1 -1
  45. package/dist/esm/src/handlers/messages-subscribe.js +51 -63
  46. package/dist/esm/src/handlers/messages-subscribe.js.map +1 -1
  47. package/dist/esm/src/handlers/messages-sync.js +75 -89
  48. package/dist/esm/src/handlers/messages-sync.js.map +1 -1
  49. package/dist/esm/src/handlers/protocols-configure.js +153 -163
  50. package/dist/esm/src/handlers/protocols-configure.js.map +1 -1
  51. package/dist/esm/src/handlers/protocols-query.js +52 -55
  52. package/dist/esm/src/handlers/protocols-query.js.map +1 -1
  53. package/dist/esm/src/handlers/records-count.js +97 -85
  54. package/dist/esm/src/handlers/records-count.js.map +1 -1
  55. package/dist/esm/src/handlers/records-delete.js +75 -93
  56. package/dist/esm/src/handlers/records-delete.js.map +1 -1
  57. package/dist/esm/src/handlers/records-query.js +116 -105
  58. package/dist/esm/src/handlers/records-query.js.map +1 -1
  59. package/dist/esm/src/handlers/records-read.js +130 -132
  60. package/dist/esm/src/handlers/records-read.js.map +1 -1
  61. package/dist/esm/src/handlers/records-subscribe.js +164 -104
  62. package/dist/esm/src/handlers/records-subscribe.js.map +1 -1
  63. package/dist/esm/src/handlers/records-write.js +213 -280
  64. package/dist/esm/src/handlers/records-write.js.map +1 -1
  65. package/dist/esm/src/index.js +5 -2
  66. package/dist/esm/src/index.js.map +1 -1
  67. package/dist/esm/src/interfaces/messages-read.js +24 -32
  68. package/dist/esm/src/interfaces/messages-read.js.map +1 -1
  69. package/dist/esm/src/interfaces/messages-subscribe.js +28 -41
  70. package/dist/esm/src/interfaces/messages-subscribe.js.map +1 -1
  71. package/dist/esm/src/interfaces/messages-sync.js +26 -40
  72. package/dist/esm/src/interfaces/messages-sync.js.map +1 -1
  73. package/dist/esm/src/interfaces/protocols-configure.js +87 -65
  74. package/dist/esm/src/interfaces/protocols-configure.js.map +1 -1
  75. package/dist/esm/src/interfaces/protocols-query.js +55 -68
  76. package/dist/esm/src/interfaces/protocols-query.js.map +1 -1
  77. package/dist/esm/src/interfaces/records-count.js +50 -66
  78. package/dist/esm/src/interfaces/records-count.js.map +1 -1
  79. package/dist/esm/src/interfaces/records-delete.js +45 -55
  80. package/dist/esm/src/interfaces/records-delete.js.map +1 -1
  81. package/dist/esm/src/interfaces/records-query.js +60 -76
  82. package/dist/esm/src/interfaces/records-query.js.map +1 -1
  83. package/dist/esm/src/interfaces/records-read.js +51 -67
  84. package/dist/esm/src/interfaces/records-read.js.map +1 -1
  85. package/dist/esm/src/interfaces/records-subscribe.js +53 -68
  86. package/dist/esm/src/interfaces/records-subscribe.js.map +1 -1
  87. package/dist/esm/src/interfaces/records-write-query.js +102 -0
  88. package/dist/esm/src/interfaces/records-write-query.js.map +1 -0
  89. package/dist/esm/src/interfaces/records-write-signing.js +81 -0
  90. package/dist/esm/src/interfaces/records-write-signing.js.map +1 -0
  91. package/dist/esm/src/interfaces/records-write.js +396 -610
  92. package/dist/esm/src/interfaces/records-write.js.map +1 -1
  93. package/dist/esm/src/jose/algorithms/signing/ed25519.js +10 -19
  94. package/dist/esm/src/jose/algorithms/signing/ed25519.js.map +1 -1
  95. package/dist/esm/src/jose/jws/general/builder.js +23 -35
  96. package/dist/esm/src/jose/jws/general/builder.js.map +1 -1
  97. package/dist/esm/src/jose/jws/general/verifier.js +56 -69
  98. package/dist/esm/src/jose/jws/general/verifier.js.map +1 -1
  99. package/dist/esm/src/protocols/permission-grant.js +43 -14
  100. package/dist/esm/src/protocols/permission-grant.js.map +1 -1
  101. package/dist/esm/src/protocols/permission-request.js +28 -14
  102. package/dist/esm/src/protocols/permission-request.js.map +1 -1
  103. package/dist/esm/src/protocols/permissions.js +325 -227
  104. package/dist/esm/src/protocols/permissions.js.map +1 -1
  105. package/dist/esm/src/smt/smt-store-level.js +42 -64
  106. package/dist/esm/src/smt/smt-store-level.js.map +1 -1
  107. package/dist/esm/src/smt/smt-store-memory.js +19 -45
  108. package/dist/esm/src/smt/smt-store-memory.js.map +1 -1
  109. package/dist/esm/src/smt/smt-utils.js +28 -45
  110. package/dist/esm/src/smt/smt-utils.js.map +1 -1
  111. package/dist/esm/src/smt/sparse-merkle-tree.js +426 -471
  112. package/dist/esm/src/smt/sparse-merkle-tree.js.map +1 -1
  113. package/dist/esm/src/state-index/state-index-level.js +113 -150
  114. package/dist/esm/src/state-index/state-index-level.js.map +1 -1
  115. package/dist/esm/src/store/blockstore-level.js +54 -156
  116. package/dist/esm/src/store/blockstore-level.js.map +1 -1
  117. package/dist/esm/src/store/blockstore-mock.js +48 -153
  118. package/dist/esm/src/store/blockstore-mock.js.map +1 -1
  119. package/dist/esm/src/store/data-store-level.js +137 -100
  120. package/dist/esm/src/store/data-store-level.js.map +1 -1
  121. package/dist/esm/src/store/index-level-compound.js +246 -0
  122. package/dist/esm/src/store/index-level-compound.js.map +1 -0
  123. package/dist/esm/src/store/index-level.js +307 -715
  124. package/dist/esm/src/store/index-level.js.map +1 -1
  125. package/dist/esm/src/store/level-wrapper.js +143 -244
  126. package/dist/esm/src/store/level-wrapper.js.map +1 -1
  127. package/dist/esm/src/store/message-store-level.js +71 -94
  128. package/dist/esm/src/store/message-store-level.js.map +1 -1
  129. package/dist/esm/src/store/resumable-task-store-level.js +62 -101
  130. package/dist/esm/src/store/resumable-task-store-level.js.map +1 -1
  131. package/dist/esm/src/store/storage-controller.js +131 -146
  132. package/dist/esm/src/store/storage-controller.js.map +1 -1
  133. package/dist/esm/src/types/permission-types.js.map +1 -1
  134. package/dist/esm/src/types/protocols-types.js +10 -0
  135. package/dist/esm/src/types/protocols-types.js.map +1 -1
  136. package/dist/esm/src/types/records-types.js.map +1 -1
  137. package/dist/esm/src/utils/abort.js +8 -19
  138. package/dist/esm/src/utils/abort.js.map +1 -1
  139. package/dist/esm/src/utils/array.js +15 -49
  140. package/dist/esm/src/utils/array.js.map +1 -1
  141. package/dist/esm/src/utils/cid.js +29 -77
  142. package/dist/esm/src/utils/cid.js.map +1 -1
  143. package/dist/esm/src/utils/data-stream.js +37 -65
  144. package/dist/esm/src/utils/data-stream.js.map +1 -1
  145. package/dist/esm/src/utils/encryption.js +136 -162
  146. package/dist/esm/src/utils/encryption.js.map +1 -1
  147. package/dist/esm/src/utils/filter.js +1 -12
  148. package/dist/esm/src/utils/filter.js.map +1 -1
  149. package/dist/esm/src/utils/hd-key.js +45 -71
  150. package/dist/esm/src/utils/hd-key.js.map +1 -1
  151. package/dist/esm/src/utils/jws.js +9 -20
  152. package/dist/esm/src/utils/jws.js.map +1 -1
  153. package/dist/esm/src/utils/memory-cache.js +12 -23
  154. package/dist/esm/src/utils/memory-cache.js.map +1 -1
  155. package/dist/esm/src/utils/messages.js +21 -33
  156. package/dist/esm/src/utils/messages.js.map +1 -1
  157. package/dist/esm/src/utils/private-key-signer.js +9 -17
  158. package/dist/esm/src/utils/private-key-signer.js.map +1 -1
  159. package/dist/esm/src/utils/protocols.js +62 -70
  160. package/dist/esm/src/utils/protocols.js.map +1 -1
  161. package/dist/esm/src/utils/records.js +103 -166
  162. package/dist/esm/src/utils/records.js.map +1 -1
  163. package/dist/esm/src/utils/secp256k1.js +60 -96
  164. package/dist/esm/src/utils/secp256k1.js.map +1 -1
  165. package/dist/esm/src/utils/secp256r1.js +54 -71
  166. package/dist/esm/src/utils/secp256r1.js.map +1 -1
  167. package/dist/esm/src/utils/time.js +5 -18
  168. package/dist/esm/src/utils/time.js.map +1 -1
  169. package/dist/esm/src/utils/url.js +3 -3
  170. package/dist/esm/src/utils/url.js.map +1 -1
  171. package/dist/esm/tests/core/auth.spec.js +3 -12
  172. package/dist/esm/tests/core/auth.spec.js.map +1 -1
  173. package/dist/esm/tests/core/message.spec.js +50 -59
  174. package/dist/esm/tests/core/message.spec.js.map +1 -1
  175. package/dist/esm/tests/core/protocol-authorization.spec.js +10 -18
  176. package/dist/esm/tests/core/protocol-authorization.spec.js.map +1 -1
  177. package/dist/esm/tests/dwn.spec.js +65 -89
  178. package/dist/esm/tests/dwn.spec.js.map +1 -1
  179. package/dist/esm/tests/event-emitter-event-log.spec.js +305 -0
  180. package/dist/esm/tests/event-emitter-event-log.spec.js.map +1 -0
  181. package/dist/esm/tests/features/author-delegated-grant.spec.js +337 -347
  182. package/dist/esm/tests/features/author-delegated-grant.spec.js.map +1 -1
  183. package/dist/esm/tests/features/owner-delegated-grant.spec.js +160 -172
  184. package/dist/esm/tests/features/owner-delegated-grant.spec.js.map +1 -1
  185. package/dist/esm/tests/features/owner-signature.spec.js +78 -82
  186. package/dist/esm/tests/features/owner-signature.spec.js.map +1 -1
  187. package/dist/esm/tests/features/permissions.spec.js +449 -184
  188. package/dist/esm/tests/features/permissions.spec.js.map +1 -1
  189. package/dist/esm/tests/features/protocol-composition.spec.js +981 -360
  190. package/dist/esm/tests/features/protocol-composition.spec.js.map +1 -1
  191. package/dist/esm/tests/features/protocol-create-action.spec.js +45 -54
  192. package/dist/esm/tests/features/protocol-create-action.spec.js.map +1 -1
  193. package/dist/esm/tests/features/protocol-delete-action.spec.js +99 -108
  194. package/dist/esm/tests/features/protocol-delete-action.spec.js.map +1 -1
  195. package/dist/esm/tests/features/protocol-update-action.spec.js +108 -117
  196. package/dist/esm/tests/features/protocol-update-action.spec.js.map +1 -1
  197. package/dist/esm/tests/features/records-immutable.spec.js +315 -0
  198. package/dist/esm/tests/features/records-immutable.spec.js.map +1 -0
  199. package/dist/esm/tests/features/records-prune.spec.js +178 -194
  200. package/dist/esm/tests/features/records-prune.spec.js.map +1 -1
  201. package/dist/esm/tests/features/records-record-limit.spec.js +542 -0
  202. package/dist/esm/tests/features/records-record-limit.spec.js.map +1 -0
  203. package/dist/esm/tests/features/records-tags.spec.js +456 -463
  204. package/dist/esm/tests/features/records-tags.spec.js.map +1 -1
  205. package/dist/esm/tests/features/resumable-tasks.spec.js +88 -98
  206. package/dist/esm/tests/features/resumable-tasks.spec.js.map +1 -1
  207. package/dist/esm/tests/handlers/messages-read.spec.js +215 -210
  208. package/dist/esm/tests/handlers/messages-read.spec.js.map +1 -1
  209. package/dist/esm/tests/handlers/messages-subscribe.spec.js +309 -171
  210. package/dist/esm/tests/handlers/messages-subscribe.spec.js.map +1 -1
  211. package/dist/esm/tests/handlers/messages-sync.spec.js +272 -199
  212. package/dist/esm/tests/handlers/messages-sync.spec.js.map +1 -1
  213. package/dist/esm/tests/handlers/protocols-configure.spec.js +247 -241
  214. package/dist/esm/tests/handlers/protocols-configure.spec.js.map +1 -1
  215. package/dist/esm/tests/handlers/protocols-query.spec.js +159 -172
  216. package/dist/esm/tests/handlers/protocols-query.spec.js.map +1 -1
  217. package/dist/esm/tests/handlers/records-count.spec.js +101 -105
  218. package/dist/esm/tests/handlers/records-count.spec.js.map +1 -1
  219. package/dist/esm/tests/handlers/records-delete.spec.js +266 -279
  220. package/dist/esm/tests/handlers/records-delete.spec.js.map +1 -1
  221. package/dist/esm/tests/handlers/records-query.spec.js +984 -996
  222. package/dist/esm/tests/handlers/records-query.spec.js.map +1 -1
  223. package/dist/esm/tests/handlers/records-read.spec.js +542 -671
  224. package/dist/esm/tests/handlers/records-read.spec.js.map +1 -1
  225. package/dist/esm/tests/handlers/records-subscribe.spec.js +433 -302
  226. package/dist/esm/tests/handlers/records-subscribe.spec.js.map +1 -1
  227. package/dist/esm/tests/handlers/records-write.spec.js +1216 -1140
  228. package/dist/esm/tests/handlers/records-write.spec.js.map +1 -1
  229. package/dist/esm/tests/interfaces/messages-get.spec.js +39 -48
  230. package/dist/esm/tests/interfaces/messages-get.spec.js.map +1 -1
  231. package/dist/esm/tests/interfaces/messages-subscribe.spec.js +4 -13
  232. package/dist/esm/tests/interfaces/messages-subscribe.spec.js.map +1 -1
  233. package/dist/esm/tests/interfaces/protocols-configure.spec.js +212 -88
  234. package/dist/esm/tests/interfaces/protocols-configure.spec.js.map +1 -1
  235. package/dist/esm/tests/interfaces/protocols-query.spec.js +8 -17
  236. package/dist/esm/tests/interfaces/protocols-query.spec.js.map +1 -1
  237. package/dist/esm/tests/interfaces/records-delete.spec.js +8 -17
  238. package/dist/esm/tests/interfaces/records-delete.spec.js.map +1 -1
  239. package/dist/esm/tests/interfaces/records-query.spec.js +20 -29
  240. package/dist/esm/tests/interfaces/records-query.spec.js.map +1 -1
  241. package/dist/esm/tests/interfaces/records-read.spec.js +42 -51
  242. package/dist/esm/tests/interfaces/records-read.spec.js.map +1 -1
  243. package/dist/esm/tests/interfaces/records-subscribe.spec.js +16 -25
  244. package/dist/esm/tests/interfaces/records-subscribe.spec.js.map +1 -1
  245. package/dist/esm/tests/interfaces/records-write.spec.js +190 -219
  246. package/dist/esm/tests/interfaces/records-write.spec.js.map +1 -1
  247. package/dist/esm/tests/jose/jws/general.spec.js +36 -45
  248. package/dist/esm/tests/jose/jws/general.spec.js.map +1 -1
  249. package/dist/esm/tests/protocols/permission-grant.spec.js +44 -50
  250. package/dist/esm/tests/protocols/permission-grant.spec.js.map +1 -1
  251. package/dist/esm/tests/protocols/permission-request.spec.js +23 -32
  252. package/dist/esm/tests/protocols/permission-request.spec.js.map +1 -1
  253. package/dist/esm/tests/protocols/permissions.spec.js +49 -55
  254. package/dist/esm/tests/protocols/permissions.spec.js.map +1 -1
  255. package/dist/esm/tests/scenarios/aggregator.spec.js +127 -138
  256. package/dist/esm/tests/scenarios/aggregator.spec.js.map +1 -1
  257. package/dist/esm/tests/scenarios/deleted-record.spec.js +372 -36
  258. package/dist/esm/tests/scenarios/deleted-record.spec.js.map +1 -1
  259. package/dist/esm/tests/scenarios/end-to-end-tests.spec.js +55 -64
  260. package/dist/esm/tests/scenarios/end-to-end-tests.spec.js.map +1 -1
  261. package/dist/esm/tests/scenarios/nested-roles.spec.js +66 -76
  262. package/dist/esm/tests/scenarios/nested-roles.spec.js.map +1 -1
  263. package/dist/esm/tests/scenarios/subscriptions.spec.js +451 -354
  264. package/dist/esm/tests/scenarios/subscriptions.spec.js.map +1 -1
  265. package/dist/esm/tests/smt/smt-store-level.spec.js +76 -87
  266. package/dist/esm/tests/smt/smt-store-level.spec.js.map +1 -1
  267. package/dist/esm/tests/smt/sparse-merkle-tree.spec.js +344 -353
  268. package/dist/esm/tests/smt/sparse-merkle-tree.spec.js.map +1 -1
  269. package/dist/esm/tests/state-index/state-index-level.spec.js +117 -126
  270. package/dist/esm/tests/state-index/state-index-level.spec.js.map +1 -1
  271. package/dist/esm/tests/store/blockstore-level.spec.js +44 -99
  272. package/dist/esm/tests/store/blockstore-level.spec.js.map +1 -1
  273. package/dist/esm/tests/store/blockstore-mock.spec.js +40 -120
  274. package/dist/esm/tests/store/blockstore-mock.spec.js.map +1 -1
  275. package/dist/esm/tests/store/data-store-level.spec.js +160 -108
  276. package/dist/esm/tests/store/data-store-level.spec.js.map +1 -1
  277. package/dist/esm/tests/store/index-level.spec.js +404 -414
  278. package/dist/esm/tests/store/index-level.spec.js.map +1 -1
  279. package/dist/esm/tests/store/message-store-level.spec.js +13 -22
  280. package/dist/esm/tests/store/message-store-level.spec.js.map +1 -1
  281. package/dist/esm/tests/store/message-store.spec.js +229 -238
  282. package/dist/esm/tests/store/message-store.spec.js.map +1 -1
  283. package/dist/esm/tests/test-event-stream.js +12 -13
  284. package/dist/esm/tests/test-event-stream.js.map +1 -1
  285. package/dist/esm/tests/test-stores.js +16 -13
  286. package/dist/esm/tests/test-stores.js.map +1 -1
  287. package/dist/esm/tests/test-suite.js +8 -15
  288. package/dist/esm/tests/test-suite.js.map +1 -1
  289. package/dist/esm/tests/utils/cid.spec.js +24 -33
  290. package/dist/esm/tests/utils/cid.spec.js.map +1 -1
  291. package/dist/esm/tests/utils/data-stream.spec.js +48 -57
  292. package/dist/esm/tests/utils/data-stream.spec.js.map +1 -1
  293. package/dist/esm/tests/utils/encryption-callbacks.spec.js +45 -54
  294. package/dist/esm/tests/utils/encryption-callbacks.spec.js.map +1 -1
  295. package/dist/esm/tests/utils/encryption.spec.js +229 -82
  296. package/dist/esm/tests/utils/encryption.spec.js.map +1 -1
  297. package/dist/esm/tests/utils/filters.spec.js +46 -55
  298. package/dist/esm/tests/utils/filters.spec.js.map +1 -1
  299. package/dist/esm/tests/utils/hd-key.spec.js +10 -19
  300. package/dist/esm/tests/utils/hd-key.spec.js.map +1 -1
  301. package/dist/esm/tests/utils/jws.spec.js +3 -12
  302. package/dist/esm/tests/utils/jws.spec.js.map +1 -1
  303. package/dist/esm/tests/utils/memory-cache.spec.js +9 -18
  304. package/dist/esm/tests/utils/memory-cache.spec.js.map +1 -1
  305. package/dist/esm/tests/utils/messages.spec.js +18 -20
  306. package/dist/esm/tests/utils/messages.spec.js.map +1 -1
  307. package/dist/esm/tests/utils/poller.js +22 -33
  308. package/dist/esm/tests/utils/poller.js.map +1 -1
  309. package/dist/esm/tests/utils/private-key-signer.spec.js +15 -24
  310. package/dist/esm/tests/utils/private-key-signer.spec.js.map +1 -1
  311. package/dist/esm/tests/utils/records.spec.js +14 -27
  312. package/dist/esm/tests/utils/records.spec.js.map +1 -1
  313. package/dist/esm/tests/utils/secp256k1.spec.js +16 -25
  314. package/dist/esm/tests/utils/secp256k1.spec.js.map +1 -1
  315. package/dist/esm/tests/utils/secp256r1.spec.js +18 -27
  316. package/dist/esm/tests/utils/secp256r1.spec.js.map +1 -1
  317. package/dist/esm/tests/utils/test-data-generator.js +446 -467
  318. package/dist/esm/tests/utils/test-data-generator.js.map +1 -1
  319. package/dist/esm/tests/validation/json-schemas/definitions.spec.js +2 -11
  320. package/dist/esm/tests/validation/json-schemas/definitions.spec.js.map +1 -1
  321. package/dist/esm/tests/validation/json-schemas/jwk/general-jwk.spec.js +4 -13
  322. package/dist/esm/tests/validation/json-schemas/jwk/general-jwk.spec.js.map +1 -1
  323. package/dist/esm/tests/validation/json-schemas/jwk/public-jwk.spec.js +8 -17
  324. package/dist/esm/tests/validation/json-schemas/jwk/public-jwk.spec.js.map +1 -1
  325. package/dist/esm/tests/validation/json-schemas/jwk-verification-method.spec.js +3 -12
  326. package/dist/esm/tests/validation/json-schemas/jwk-verification-method.spec.js.map +1 -1
  327. package/dist/esm/tests/validation/json-schemas/protocols/protocols-configure.spec.js +4 -13
  328. package/dist/esm/tests/validation/json-schemas/protocols/protocols-configure.spec.js.map +1 -1
  329. package/dist/esm/tests/validation/json-schemas/records/records-query.spec.js +2 -11
  330. package/dist/esm/tests/validation/json-schemas/records/records-query.spec.js.map +1 -1
  331. package/dist/esm/tests/validation/json-schemas/records/records-read.spec.js +2 -11
  332. package/dist/esm/tests/validation/json-schemas/records/records-read.spec.js.map +1 -1
  333. package/dist/esm/tests/validation/json-schemas/records/records-write.spec.js +44 -24
  334. package/dist/esm/tests/validation/json-schemas/records/records-write.spec.js.map +1 -1
  335. package/dist/types/generated/precompiled-validators.d.ts +49 -40
  336. package/dist/types/generated/precompiled-validators.d.ts.map +1 -1
  337. package/dist/types/src/core/constants.d.ts +11 -0
  338. package/dist/types/src/core/constants.d.ts.map +1 -0
  339. package/dist/types/src/core/core-protocol.d.ts +89 -0
  340. package/dist/types/src/core/core-protocol.d.ts.map +1 -0
  341. package/dist/types/src/core/dwn-error.d.ts +9 -12
  342. package/dist/types/src/core/dwn-error.d.ts.map +1 -1
  343. package/dist/types/src/core/grant-authorization.d.ts +6 -2
  344. package/dist/types/src/core/grant-authorization.d.ts.map +1 -1
  345. package/dist/types/src/core/protocol-authorization-action.d.ts +42 -0
  346. package/dist/types/src/core/protocol-authorization-action.d.ts.map +1 -0
  347. package/dist/types/src/core/protocol-authorization-validation.d.ts +81 -0
  348. package/dist/types/src/core/protocol-authorization-validation.d.ts.map +1 -0
  349. package/dist/types/src/core/protocol-authorization.d.ts +24 -106
  350. package/dist/types/src/core/protocol-authorization.d.ts.map +1 -1
  351. package/dist/types/src/core/record-chain.d.ts +24 -0
  352. package/dist/types/src/core/record-chain.d.ts.map +1 -0
  353. package/dist/types/src/core/records-grant-authorization.d.ts.map +1 -1
  354. package/dist/types/src/dwn.d.ts +19 -7
  355. package/dist/types/src/dwn.d.ts.map +1 -1
  356. package/dist/types/src/event-stream/event-emitter-event-log.d.ts +50 -0
  357. package/dist/types/src/event-stream/event-emitter-event-log.d.ts.map +1 -0
  358. package/dist/types/src/handlers/messages-read.d.ts +3 -8
  359. package/dist/types/src/handlers/messages-read.d.ts.map +1 -1
  360. package/dist/types/src/handlers/messages-subscribe.d.ts +6 -10
  361. package/dist/types/src/handlers/messages-subscribe.d.ts.map +1 -1
  362. package/dist/types/src/handlers/messages-sync.d.ts +3 -8
  363. package/dist/types/src/handlers/messages-sync.d.ts.map +1 -1
  364. package/dist/types/src/handlers/protocols-configure.d.ts +3 -10
  365. package/dist/types/src/handlers/protocols-configure.d.ts.map +1 -1
  366. package/dist/types/src/handlers/protocols-query.d.ts +3 -8
  367. package/dist/types/src/handlers/protocols-query.d.ts.map +1 -1
  368. package/dist/types/src/handlers/records-count.d.ts +3 -6
  369. package/dist/types/src/handlers/records-count.d.ts.map +1 -1
  370. package/dist/types/src/handlers/records-delete.d.ts +3 -8
  371. package/dist/types/src/handlers/records-delete.d.ts.map +1 -1
  372. package/dist/types/src/handlers/records-query.d.ts +3 -8
  373. package/dist/types/src/handlers/records-query.d.ts.map +1 -1
  374. package/dist/types/src/handlers/records-read.d.ts +3 -8
  375. package/dist/types/src/handlers/records-read.d.ts.map +1 -1
  376. package/dist/types/src/handlers/records-subscribe.d.ts +8 -10
  377. package/dist/types/src/handlers/records-subscribe.d.ts.map +1 -1
  378. package/dist/types/src/handlers/records-write.d.ts +4 -24
  379. package/dist/types/src/handlers/records-write.d.ts.map +1 -1
  380. package/dist/types/src/index.d.ts +8 -4
  381. package/dist/types/src/index.d.ts.map +1 -1
  382. package/dist/types/src/interfaces/messages-subscribe.d.ts +5 -0
  383. package/dist/types/src/interfaces/messages-subscribe.d.ts.map +1 -1
  384. package/dist/types/src/interfaces/protocols-configure.d.ts.map +1 -1
  385. package/dist/types/src/interfaces/records-subscribe.d.ts +5 -0
  386. package/dist/types/src/interfaces/records-subscribe.d.ts.map +1 -1
  387. package/dist/types/src/interfaces/records-write-query.d.ts +33 -0
  388. package/dist/types/src/interfaces/records-write-query.d.ts.map +1 -0
  389. package/dist/types/src/interfaces/records-write-signing.d.ts +34 -0
  390. package/dist/types/src/interfaces/records-write-signing.d.ts.map +1 -0
  391. package/dist/types/src/interfaces/records-write.d.ts +13 -53
  392. package/dist/types/src/interfaces/records-write.d.ts.map +1 -1
  393. package/dist/types/src/protocols/permission-grant.d.ts +1 -1
  394. package/dist/types/src/protocols/permission-grant.d.ts.map +1 -1
  395. package/dist/types/src/protocols/permission-request.d.ts +1 -1
  396. package/dist/types/src/protocols/permission-request.d.ts.map +1 -1
  397. package/dist/types/src/protocols/permissions.d.ts +40 -3
  398. package/dist/types/src/protocols/permissions.d.ts.map +1 -1
  399. package/dist/types/src/state-index/state-index-level.d.ts.map +1 -1
  400. package/dist/types/src/store/data-store-level.d.ts +20 -4
  401. package/dist/types/src/store/data-store-level.d.ts.map +1 -1
  402. package/dist/types/src/store/index-level-compound.d.ts +70 -0
  403. package/dist/types/src/store/index-level-compound.d.ts.map +1 -0
  404. package/dist/types/src/store/index-level.d.ts +4 -58
  405. package/dist/types/src/store/index-level.d.ts.map +1 -1
  406. package/dist/types/src/store/storage-controller.d.ts +4 -4
  407. package/dist/types/src/store/storage-controller.d.ts.map +1 -1
  408. package/dist/types/src/types/message-types.d.ts +3 -3
  409. package/dist/types/src/types/message-types.d.ts.map +1 -1
  410. package/dist/types/src/types/messages-types.d.ts +12 -3
  411. package/dist/types/src/types/messages-types.d.ts.map +1 -1
  412. package/dist/types/src/types/method-handler.d.ts +24 -3
  413. package/dist/types/src/types/method-handler.d.ts.map +1 -1
  414. package/dist/types/src/types/permission-types.d.ts +7 -0
  415. package/dist/types/src/types/permission-types.d.ts.map +1 -1
  416. package/dist/types/src/types/protocols-types.d.ts +41 -1
  417. package/dist/types/src/types/protocols-types.d.ts.map +1 -1
  418. package/dist/types/src/types/records-types.d.ts +16 -6
  419. package/dist/types/src/types/records-types.d.ts.map +1 -1
  420. package/dist/types/src/types/subscriptions.d.ts +151 -13
  421. package/dist/types/src/types/subscriptions.d.ts.map +1 -1
  422. package/dist/types/src/utils/hd-key.d.ts +1 -9
  423. package/dist/types/src/utils/hd-key.d.ts.map +1 -1
  424. package/dist/types/src/utils/messages.d.ts +7 -5
  425. package/dist/types/src/utils/messages.d.ts.map +1 -1
  426. package/dist/types/src/utils/protocols.d.ts +5 -0
  427. package/dist/types/src/utils/protocols.d.ts.map +1 -1
  428. package/dist/types/src/utils/records.d.ts +1 -11
  429. package/dist/types/src/utils/records.d.ts.map +1 -1
  430. package/dist/types/tests/dwn.spec.d.ts.map +1 -1
  431. package/dist/types/tests/event-emitter-event-log.spec.d.ts +2 -0
  432. package/dist/types/tests/event-emitter-event-log.spec.d.ts.map +1 -0
  433. package/dist/types/tests/features/author-delegated-grant.spec.d.ts.map +1 -1
  434. package/dist/types/tests/features/owner-delegated-grant.spec.d.ts.map +1 -1
  435. package/dist/types/tests/features/owner-signature.spec.d.ts.map +1 -1
  436. package/dist/types/tests/features/permissions.spec.d.ts.map +1 -1
  437. package/dist/types/tests/features/protocol-composition.spec.d.ts.map +1 -1
  438. package/dist/types/tests/features/records-immutable.spec.d.ts +2 -0
  439. package/dist/types/tests/features/records-immutable.spec.d.ts.map +1 -0
  440. package/dist/types/tests/features/records-record-limit.spec.d.ts +2 -0
  441. package/dist/types/tests/features/records-record-limit.spec.d.ts.map +1 -0
  442. package/dist/types/tests/features/records-tags.spec.d.ts.map +1 -1
  443. package/dist/types/tests/features/resumable-tasks.spec.d.ts.map +1 -1
  444. package/dist/types/tests/handlers/messages-read.spec.d.ts.map +1 -1
  445. package/dist/types/tests/handlers/messages-subscribe.spec.d.ts.map +1 -1
  446. package/dist/types/tests/handlers/messages-sync.spec.d.ts.map +1 -1
  447. package/dist/types/tests/handlers/records-count.spec.d.ts.map +1 -1
  448. package/dist/types/tests/handlers/records-delete.spec.d.ts.map +1 -1
  449. package/dist/types/tests/handlers/records-query.spec.d.ts.map +1 -1
  450. package/dist/types/tests/handlers/records-read.spec.d.ts.map +1 -1
  451. package/dist/types/tests/handlers/records-subscribe.spec.d.ts.map +1 -1
  452. package/dist/types/tests/handlers/records-write.spec.d.ts.map +1 -1
  453. package/dist/types/tests/scenarios/deleted-record.spec.d.ts.map +1 -1
  454. package/dist/types/tests/scenarios/subscriptions.spec.d.ts.map +1 -1
  455. package/dist/types/tests/test-event-stream.d.ts +11 -12
  456. package/dist/types/tests/test-event-stream.d.ts.map +1 -1
  457. package/dist/types/tests/test-suite.d.ts +2 -2
  458. package/dist/types/tests/test-suite.d.ts.map +1 -1
  459. package/dist/types/tests/utils/test-data-generator.d.ts +18 -0
  460. package/dist/types/tests/utils/test-data-generator.d.ts.map +1 -1
  461. package/package.json +5 -4
  462. package/src/core/constants.ts +11 -0
  463. package/src/core/core-protocol.ts +129 -0
  464. package/src/core/dwn-error.ts +15 -12
  465. package/src/core/grant-authorization.ts +20 -3
  466. package/src/core/protocol-authorization-action.ts +377 -0
  467. package/src/core/protocol-authorization-validation.ts +487 -0
  468. package/src/core/protocol-authorization.ts +111 -856
  469. package/src/core/record-chain.ts +99 -0
  470. package/src/core/records-grant-authorization.ts +6 -8
  471. package/src/dwn.ts +58 -73
  472. package/src/event-stream/event-emitter-event-log.ts +283 -0
  473. package/src/handlers/messages-read.ts +8 -9
  474. package/src/handlers/messages-subscribe.ts +24 -28
  475. package/src/handlers/messages-sync.ts +10 -16
  476. package/src/handlers/protocols-configure.ts +47 -32
  477. package/src/handlers/protocols-query.ts +6 -9
  478. package/src/handlers/records-count.ts +11 -10
  479. package/src/handlers/records-delete.ts +12 -21
  480. package/src/handlers/records-query.ts +12 -12
  481. package/src/handlers/records-read.ts +34 -22
  482. package/src/handlers/records-subscribe.ts +47 -26
  483. package/src/handlers/records-write.ts +47 -104
  484. package/src/index.ts +9 -5
  485. package/src/interfaces/messages-subscribe.ts +7 -1
  486. package/src/interfaces/protocols-configure.ts +73 -8
  487. package/src/interfaces/records-count.ts +1 -1
  488. package/src/interfaces/records-delete.ts +1 -1
  489. package/src/interfaces/records-query.ts +1 -1
  490. package/src/interfaces/records-read.ts +1 -1
  491. package/src/interfaces/records-subscribe.ts +8 -1
  492. package/src/interfaces/records-write-query.ts +139 -0
  493. package/src/interfaces/records-write-signing.ts +123 -0
  494. package/src/interfaces/records-write.ts +66 -261
  495. package/src/protocols/permission-grant.ts +1 -1
  496. package/src/protocols/permission-request.ts +1 -1
  497. package/src/protocols/permissions.ts +148 -6
  498. package/src/state-index/state-index-level.ts +5 -7
  499. package/src/store/data-store-level.ts +124 -34
  500. package/src/store/index-level-compound.ts +324 -0
  501. package/src/store/index-level.ts +68 -341
  502. package/src/store/storage-controller.ts +11 -11
  503. package/src/types/message-types.ts +3 -3
  504. package/src/types/messages-types.ts +12 -3
  505. package/src/types/method-handler.ts +26 -4
  506. package/src/types/mitt.d.ts +28 -0
  507. package/src/types/permission-types.ts +7 -0
  508. package/src/types/protocols-types.ts +46 -0
  509. package/src/types/records-types.ts +16 -6
  510. package/src/types/subscriptions.ts +178 -14
  511. package/src/utils/hd-key.ts +0 -9
  512. package/src/utils/messages.ts +17 -37
  513. package/src/utils/protocols.ts +8 -0
  514. package/src/utils/records.ts +8 -59
  515. package/dist/esm/src/event-stream/event-emitter-stream.js +0 -60
  516. package/dist/esm/src/event-stream/event-emitter-stream.js.map +0 -1
  517. package/dist/esm/tests/event-stream/event-emitter-stream.spec.js +0 -77
  518. package/dist/esm/tests/event-stream/event-emitter-stream.spec.js.map +0 -1
  519. package/dist/esm/tests/event-stream/event-stream.spec.js +0 -123
  520. package/dist/esm/tests/event-stream/event-stream.spec.js.map +0 -1
  521. package/dist/types/src/event-stream/event-emitter-stream.d.ts +0 -23
  522. package/dist/types/src/event-stream/event-emitter-stream.d.ts.map +0 -1
  523. package/dist/types/tests/event-stream/event-emitter-stream.spec.d.ts +0 -2
  524. package/dist/types/tests/event-stream/event-emitter-stream.spec.d.ts.map +0 -1
  525. package/dist/types/tests/event-stream/event-stream.spec.d.ts +0 -2
  526. package/dist/types/tests/event-stream/event-stream.spec.d.ts.map +0 -1
  527. package/src/event-stream/event-emitter-stream.ts +0 -69
@@ -1,136 +1,173 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __asyncValues = (this && this.__asyncValues) || function (o) {
11
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
12
- var m = o[Symbol.asyncIterator], i;
13
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
14
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
15
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
16
- };
17
1
  import { BlockstoreLevel } from './blockstore-level.js';
18
2
  import { createLevelDatabase } from './level-wrapper.js';
19
3
  import { DataStream } from '../utils/data-stream.js';
20
4
  import { exporter } from 'ipfs-unixfs-exporter';
21
5
  import { importer } from 'ipfs-unixfs-importer';
6
+ const textEncoder = new TextEncoder();
7
+ const textDecoder = new TextDecoder();
22
8
  /**
23
9
  * A simple implementation of {@link DataStore} that works in both the browser and server-side.
24
10
  * Leverages LevelDB under the hood.
25
11
  *
26
- * It has the following structure (`+` represents an additional sublevel/partition):
27
- * 'data' + <tenant> + <recordId> + <dataCid> -> <data>
12
+ * It has the following sublevel structure (`+` represents an additional sublevel):
13
+ * 'refs' + <tenant> + <recordId> : key <dataCid> JSON { dataSize }
14
+ * 'blocks' + <dataCid> : key <blockCid> → block data (shared)
15
+ * 'refcounts' : key <dataCid> → JSON { count, dataSize }
16
+ *
17
+ * Identical data (same dataCid) is stored only once in the blocks sublevel.
18
+ * Multiple (tenant, recordId) pairs can reference the same blocks.
28
19
  */
29
20
  export class DataStoreLevel {
21
+ config;
22
+ blockstore;
30
23
  constructor(config = {}) {
31
- this.config = Object.assign({ blockstoreLocation: 'DATASTORE', createLevelDatabase }, config);
24
+ this.config = {
25
+ blockstoreLocation: 'DATASTORE',
26
+ createLevelDatabase,
27
+ ...config
28
+ };
32
29
  this.blockstore = new BlockstoreLevel({
33
30
  location: this.config.blockstoreLocation,
34
31
  createLevelDatabase: this.config.createLevelDatabase,
35
32
  });
36
33
  }
37
- open() {
38
- return __awaiter(this, void 0, void 0, function* () {
39
- yield this.blockstore.open();
40
- });
34
+ async open() {
35
+ await this.blockstore.open();
41
36
  }
42
- close() {
43
- return __awaiter(this, void 0, void 0, function* () {
44
- yield this.blockstore.close();
45
- });
37
+ async close() {
38
+ await this.blockstore.close();
46
39
  }
47
- put(tenant, recordId, dataCid, dataStream) {
48
- return __awaiter(this, void 0, void 0, function* () {
49
- var _a, e_1, _b, _c;
50
- var _d, _e;
51
- const blockstoreForData = yield this.getBlockstoreForStoringData(tenant, recordId, dataCid);
52
- const asyncDataBlocks = importer([{ content: DataStream.asAsyncIterable(dataStream) }], blockstoreForData, { cidVersion: 1 });
53
- // NOTE: the last block contains the root CID as well as info to derive the data size
40
+ async put(tenant, recordId, dataCid, dataStream) {
41
+ // Check if this exact ref already exists (idempotent re-put).
42
+ const refsPartition = await this.getRefsPartition(tenant, recordId);
43
+ const existingRef = await refsPartition.get(dataCid);
44
+ if (existingRef) {
45
+ await dataStream.cancel();
46
+ const { dataSize } = JSON.parse(textDecoder.decode(existingRef));
47
+ return { dataSize };
48
+ }
49
+ // Check refcount — if > 0, blocks already exist for this dataCid.
50
+ const refcountsPartition = await this.getRefcountsPartition();
51
+ const rawRefcount = await refcountsPartition.get(dataCid);
52
+ const refcountData = rawRefcount
53
+ ? JSON.parse(textDecoder.decode(rawRefcount))
54
+ : { count: 0, dataSize: 0 };
55
+ let dataSize;
56
+ if (refcountData.count > 0) {
57
+ // Blocks already exist — skip import.
58
+ await dataStream.cancel();
59
+ dataSize = refcountData.dataSize;
60
+ }
61
+ else {
62
+ // First write — import blocks into the shared blocks partition.
63
+ const blocksPartition = await this.getBlocksPartition(dataCid);
64
+ const asyncDataBlocks = importer([{ content: DataStream.asAsyncIterable(dataStream) }], blocksPartition, { cidVersion: 1 });
65
+ // NOTE: the last block contains the root CID as well as info to derive the data size.
54
66
  let dataDagRoot;
55
- try {
56
- for (var _f = true, asyncDataBlocks_1 = __asyncValues(asyncDataBlocks), asyncDataBlocks_1_1; asyncDataBlocks_1_1 = yield asyncDataBlocks_1.next(), _a = asyncDataBlocks_1_1.done, !_a; _f = true) {
57
- _c = asyncDataBlocks_1_1.value;
58
- _f = false;
59
- dataDagRoot = _c;
60
- ;
61
- }
67
+ for await (dataDagRoot of asyncDataBlocks) {
68
+ ;
62
69
  }
63
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
64
- finally {
65
- try {
66
- if (!_f && !_a && (_b = asyncDataBlocks_1.return)) yield _b.call(asyncDataBlocks_1);
67
- }
68
- finally { if (e_1) throw e_1.error; }
69
- }
70
- return {
71
- dataSize: Number((_e = (_d = dataDagRoot.unixfs) === null || _d === void 0 ? void 0 : _d.fileSize()) !== null && _e !== void 0 ? _e : dataDagRoot.size)
72
- };
73
- });
70
+ dataSize = Number(dataDagRoot.unixfs?.fileSize() ?? dataDagRoot.size);
71
+ }
72
+ // Write ref entry.
73
+ await refsPartition.put(dataCid, textEncoder.encode(JSON.stringify({ dataSize })));
74
+ // Increment refcount.
75
+ await refcountsPartition.put(dataCid, textEncoder.encode(JSON.stringify({
76
+ count: refcountData.count + 1,
77
+ dataSize,
78
+ })));
79
+ return { dataSize };
74
80
  }
75
- get(tenant, recordId, dataCid) {
76
- return __awaiter(this, void 0, void 0, function* () {
77
- const blockstoreForData = yield this.getBlockstoreForStoringData(tenant, recordId, dataCid);
78
- const exists = yield blockstoreForData.has(dataCid);
79
- if (!exists) {
80
- return undefined;
81
- }
82
- // data is chunked into dag-pb unixfs blocks. re-inflate the chunks.
83
- const dataDagRoot = yield exporter(dataCid, blockstoreForData);
84
- const contentIterator = dataDagRoot.content();
85
- const dataStream = new ReadableStream({
86
- pull(controller) {
87
- return __awaiter(this, void 0, void 0, function* () {
88
- const result = yield contentIterator.next();
89
- if (result.done) {
90
- controller.close();
91
- }
92
- else {
93
- controller.enqueue(result.value);
94
- }
95
- });
81
+ async get(tenant, recordId, dataCid) {
82
+ // Check ref exists.
83
+ const refsPartition = await this.getRefsPartition(tenant, recordId);
84
+ const rawRef = await refsPartition.get(dataCid);
85
+ if (!rawRef) {
86
+ return undefined;
87
+ }
88
+ const { dataSize } = JSON.parse(textDecoder.decode(rawRef));
89
+ // Export from the shared blocks partition.
90
+ const blocksPartition = await this.getBlocksPartition(dataCid);
91
+ const exists = await blocksPartition.has(dataCid);
92
+ if (!exists) {
93
+ return undefined;
94
+ }
95
+ // Data is chunked into DAG-PB UnixFS blocks. Re-inflate the chunks.
96
+ const dataDagRoot = await exporter(dataCid, blocksPartition);
97
+ const contentIterator = dataDagRoot.content();
98
+ const dataStream = new ReadableStream({
99
+ async pull(controller) {
100
+ const result = await contentIterator.next();
101
+ if (result.done) {
102
+ controller.close();
103
+ }
104
+ else {
105
+ controller.enqueue(result.value);
96
106
  }
97
- });
98
- let dataSize = dataDagRoot.size;
99
- if (dataDagRoot.type === 'file' || dataDagRoot.type === 'directory') {
100
- dataSize = dataDagRoot.unixfs.fileSize();
101
107
  }
102
- return {
103
- dataSize: Number(dataSize),
104
- dataStream,
105
- };
106
108
  });
109
+ return { dataSize, dataStream };
107
110
  }
108
- delete(tenant, recordId, dataCid) {
109
- return __awaiter(this, void 0, void 0, function* () {
110
- const blockstoreForData = yield this.getBlockstoreForStoringData(tenant, recordId, dataCid);
111
- yield blockstoreForData.clear();
112
- });
111
+ async delete(tenant, recordId, dataCid) {
112
+ // Check ref exists.
113
+ const refsPartition = await this.getRefsPartition(tenant, recordId);
114
+ const rawRef = await refsPartition.get(dataCid);
115
+ if (!rawRef) {
116
+ return;
117
+ }
118
+ // Remove ref.
119
+ await refsPartition.delete(dataCid);
120
+ // Decrement refcount and GC blocks if this was the last ref.
121
+ const refcountsPartition = await this.getRefcountsPartition();
122
+ const rawRefcount = await refcountsPartition.get(dataCid);
123
+ if (!rawRefcount) {
124
+ return;
125
+ }
126
+ const refcountData = JSON.parse(textDecoder.decode(rawRefcount));
127
+ const newCount = refcountData.count - 1;
128
+ if (newCount <= 0) {
129
+ // Last reference removed — garbage-collect blocks and refcount entry.
130
+ const blocksPartition = await this.getBlocksPartition(dataCid);
131
+ await blocksPartition.clear();
132
+ await refcountsPartition.delete(dataCid);
133
+ }
134
+ else {
135
+ // Other references remain — update the count.
136
+ await refcountsPartition.put(dataCid, textEncoder.encode(JSON.stringify({
137
+ count: newCount,
138
+ dataSize: refcountData.dataSize,
139
+ })));
140
+ }
113
141
  }
114
142
  /**
115
143
  * Deletes everything in the store. Mainly used in tests.
116
144
  */
117
- clear() {
118
- return __awaiter(this, void 0, void 0, function* () {
119
- yield this.blockstore.clear();
120
- });
145
+ async clear() {
146
+ await this.blockstore.clear();
121
147
  }
122
148
  /**
123
- * Gets the blockstore used for storing data for the given `tenant -> `recordId` -> `dataCid`.
149
+ * Gets the refs sublevel for the given tenant and recordId.
150
+ * Caller uses `dataCid` as the key within the returned partition.
124
151
  */
125
- getBlockstoreForStoringData(tenant, recordId, dataCid) {
126
- return __awaiter(this, void 0, void 0, function* () {
127
- const dataPartitionName = 'data';
128
- const blockstoreForData = yield this.blockstore.partition(dataPartitionName);
129
- const blockstoreOfGivenTenant = yield blockstoreForData.partition(tenant);
130
- const blockstoreOfGivenRecordId = yield blockstoreOfGivenTenant.partition(recordId);
131
- const blockstoreOfGivenDataCidOfRecordId = yield blockstoreOfGivenRecordId.partition(dataCid);
132
- return blockstoreOfGivenDataCidOfRecordId;
133
- });
152
+ async getRefsPartition(tenant, recordId) {
153
+ const refsRoot = await this.blockstore.db.partition('refs');
154
+ const tenantPartition = await refsRoot.partition(tenant);
155
+ return tenantPartition.partition(recordId);
156
+ }
157
+ /**
158
+ * Gets the shared blocks sublevel for the given dataCid.
159
+ * Used as a Blockstore for ipfs-unixfs-importer/exporter.
160
+ */
161
+ async getBlocksPartition(dataCid) {
162
+ const blocksRoot = await this.blockstore.partition('blocks');
163
+ return blocksRoot.partition(dataCid);
164
+ }
165
+ /**
166
+ * Gets the refcounts sublevel.
167
+ * Key: `dataCid` → JSON `{ count, dataSize }`.
168
+ */
169
+ async getRefcountsPartition() {
170
+ return this.blockstore.db.partition('refcounts');
134
171
  }
135
172
  }
136
173
  //# sourceMappingURL=data-store-level.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"data-store-level.js","sourceRoot":"","sources":["../../../../src/store/data-store-level.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,sB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,UAAU,CAAC,KAAK,EAAE,CAAC;IAChC,CAAC;IAED;;;OAGG;IACK,KAAK,CAAC,gBAAgB,CAAC,MAAc,EAAE,QAAgB;QAC7D,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAC5D,MAAM,eAAe,GAAG,MAAM,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACzD,OAAO,eAAe,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAC7C,CAAC;IAED;;;OAGG;IACK,KAAK,CAAC,kBAAkB,CAAC,OAAe;QAC9C,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QAC7D,OAAO,UAAU,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACvC,CAAC;IAED;;;OAGG;IACK,KAAK,CAAC,qBAAqB;QACjC,OAAO,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IACnD,CAAC;CAEF"}
@@ -0,0 +1,246 @@
1
+ import { FilterUtility } from '../utils/filter.js';
2
+ import { SortDirection } from '../types/query-types.js';
3
+ /** Separator between compound key segments (higher than \x00 so prefix scans work correctly). */
4
+ export const COMPOUND_SEGMENT_SEPARATOR = '\x01';
5
+ /**
6
+ * Gets the compound index partition for a given compound index definition.
7
+ * Compound index sublevels use the naming convention `__compound:<name>__`.
8
+ */
9
+ export async function getCompoundIndexPartition(db, tenant, compoundIndex) {
10
+ const partitionName = `__compound:${compoundIndex.name}__`;
11
+ return (await db.partition(tenant)).partition(partitionName);
12
+ }
13
+ /**
14
+ * Builds a compound index key from the given indexes and compound index definition.
15
+ *
16
+ * Key format: `<prop1>\x01<prop2>\x01...\x01<sortValue>\x00<messageCid>`
17
+ *
18
+ * @returns the compound key, or undefined if the indexes don't contain all required properties.
19
+ */
20
+ export function buildCompoundKey(messageCid, indexes, compoundIndex, encodeValue, delimiter) {
21
+ const segments = [];
22
+ for (const property of compoundIndex.properties) {
23
+ const value = indexes[property];
24
+ if (value === undefined || Array.isArray(value)) {
25
+ return undefined; // compound indexes don't support array values or missing properties
26
+ }
27
+ segments.push(encodeValue(value));
28
+ }
29
+ const sortValue = indexes[compoundIndex.sortProperty];
30
+ if (sortValue === undefined || Array.isArray(sortValue)) {
31
+ return undefined;
32
+ }
33
+ // join prefix segments with \x01, then append sort value and messageCid with the standard delimiters
34
+ const prefixPart = segments.join(COMPOUND_SEGMENT_SEPARATOR);
35
+ const sortPart = encodeValue(sortValue);
36
+ return prefixPart + COMPOUND_SEGMENT_SEPARATOR + sortPart + delimiter + messageCid;
37
+ }
38
+ /**
39
+ * Builds the prefix portion of a compound key from filter values (without the sort/messageCid suffix).
40
+ * Used for range scans: all entries with this prefix match the filter.
41
+ */
42
+ export function buildCompoundPrefix(filter, compoundIndex, encodeValue) {
43
+ const segments = [];
44
+ for (const property of compoundIndex.properties) {
45
+ const filterValue = filter[property];
46
+ if (filterValue === undefined || typeof filterValue === 'object') {
47
+ return undefined; // compound prefix only works with equality filters
48
+ }
49
+ segments.push(encodeValue(filterValue));
50
+ }
51
+ return segments.join(COMPOUND_SEGMENT_SEPARATOR) + COMPOUND_SEGMENT_SEPARATOR;
52
+ }
53
+ /**
54
+ * Creates a put operation for a compound index entry.
55
+ * Returns undefined if the indexes don't contain all required compound index properties.
56
+ */
57
+ export function createCompoundIndexPutOperation(db, tenant, item, compoundIndex, encodeValue, delimiter) {
58
+ const key = buildCompoundKey(item.messageCid, item.indexes, compoundIndex, encodeValue, delimiter);
59
+ if (key === undefined) {
60
+ return undefined;
61
+ }
62
+ return createOperationForPartition(db, tenant, `__compound:${compoundIndex.name}__`, {
63
+ type: 'put',
64
+ key,
65
+ value: JSON.stringify(item),
66
+ });
67
+ }
68
+ /**
69
+ * Creates a delete operation for a compound index entry.
70
+ * Returns undefined if the indexes don't contain all required compound index properties.
71
+ */
72
+ export function createCompoundIndexDeleteOperation(db, tenant, messageCid, indexes, compoundIndex, encodeValue, delimiter) {
73
+ const key = buildCompoundKey(messageCid, indexes, compoundIndex, encodeValue, delimiter);
74
+ if (key === undefined) {
75
+ return undefined;
76
+ }
77
+ return createOperationForPartition(db, tenant, `__compound:${compoundIndex.name}__`, {
78
+ type: 'del',
79
+ key,
80
+ });
81
+ }
82
+ /**
83
+ * Generic helper to create a batch operation for any named partition under a tenant.
84
+ */
85
+ export async function createOperationForPartition(db, tenant, partitionName, operation) {
86
+ const tenantPartition = await db.partition(tenant);
87
+ return tenantPartition.createPartitionOperation(partitionName, operation);
88
+ }
89
+ /**
90
+ * Selects the best compound index that covers the given filter and sort requirements.
91
+ *
92
+ * A compound index "covers" a query when:
93
+ * 1. Every property in the compound index definition is present in the filter as an equality filter.
94
+ * 2. The compound index's sort property matches the query's sort property.
95
+ *
96
+ * Among multiple matching compound indexes, the one with the most properties is preferred
97
+ * (more specific = fewer false positives in the prefix scan).
98
+ */
99
+ export function selectCompoundIndex(filter, queryOptions, compoundIndexes) {
100
+ let bestMatch;
101
+ let bestPropertyCount = 0;
102
+ for (const compoundIndex of compoundIndexes) {
103
+ // check that the sort property matches
104
+ if (compoundIndex.sortProperty !== queryOptions.sortProperty) {
105
+ continue;
106
+ }
107
+ // check that all compound properties are present in the filter as equality filters
108
+ let allPropertiesMatch = true;
109
+ for (const property of compoundIndex.properties) {
110
+ const filterValue = filter[property];
111
+ if (filterValue === undefined || typeof filterValue === 'object') {
112
+ allPropertiesMatch = false;
113
+ break;
114
+ }
115
+ }
116
+ if (allPropertiesMatch && compoundIndex.properties.length > bestPropertyCount) {
117
+ bestMatch = compoundIndex;
118
+ bestPropertyCount = compoundIndex.properties.length;
119
+ }
120
+ }
121
+ return bestMatch;
122
+ }
123
+ /**
124
+ * Queries using a compound index. This is the most efficient query strategy: a single LevelDB
125
+ * range scan that filters, sorts, and paginates all at once.
126
+ *
127
+ * The compound key encodes the filter properties as a prefix and the sort property as a suffix,
128
+ * so iterating over keys with the filter prefix yields results in sort order.
129
+ *
130
+ * Any remaining filter properties not covered by the compound index are verified in memory.
131
+ *
132
+ * @param queryWithIteratorPagingFallback callback to fall back to iterator paging if compound prefix fails.
133
+ */
134
+ export async function queryWithCompoundIndex(db, tenant, filter, queryOptions, compoundIndex, encodeValue, delimiter, queryWithIteratorPagingFallback, options) {
135
+ const { sortDirection = SortDirection.Ascending, cursor, limit } = queryOptions;
136
+ const prefix = buildCompoundPrefix(filter, compoundIndex, encodeValue);
137
+ if (prefix === undefined) {
138
+ // should not happen since selectCompoundIndex already validated, but guard against it
139
+ return queryWithIteratorPagingFallback(tenant, [filter], queryOptions, options);
140
+ }
141
+ const partition = await getCompoundIndexPartition(db, tenant, compoundIndex);
142
+ // determine the iterator bounds from the prefix
143
+ const iteratorOptions = {};
144
+ if (cursor !== undefined) {
145
+ // build the full compound key for the cursor position
146
+ const cursorSortEncoded = encodeValue(cursor.value);
147
+ const cursorKey = prefix + cursorSortEncoded + delimiter + cursor.messageCid;
148
+ if (sortDirection === SortDirection.Ascending) {
149
+ iteratorOptions.gt = cursorKey;
150
+ // upper bound: everything with this prefix (prefix + \xff is past all valid compound keys with this prefix)
151
+ iteratorOptions.lt = prefix + '\xff';
152
+ }
153
+ else {
154
+ iteratorOptions.lt = cursorKey;
155
+ iteratorOptions.gt = prefix;
156
+ iteratorOptions.reverse = true;
157
+ }
158
+ }
159
+ else {
160
+ if (sortDirection === SortDirection.Ascending) {
161
+ iteratorOptions.gt = prefix;
162
+ iteratorOptions.lt = prefix + '\xff';
163
+ }
164
+ else {
165
+ // for descending without cursor, start from the end of the prefix range
166
+ iteratorOptions.gt = prefix;
167
+ iteratorOptions.lt = prefix + '\xff';
168
+ iteratorOptions.reverse = true;
169
+ }
170
+ }
171
+ // determine which filter properties are NOT covered by the compound index
172
+ // (need in-memory verification for these)
173
+ // NOTE: the compound index equality properties are fully covered by the prefix scan,
174
+ // but the sort property is only covered for ordering — any range filter on the sort
175
+ // property must still be applied as a residual filter.
176
+ const coveredEqualityProperties = new Set(compoundIndex.properties);
177
+ const residualFilter = {};
178
+ let hasResidualFilter = false;
179
+ for (const property in filter) {
180
+ if (!coveredEqualityProperties.has(property)) {
181
+ residualFilter[property] = filter[property];
182
+ hasResidualFilter = true;
183
+ }
184
+ }
185
+ const matches = [];
186
+ for await (const [_key, value] of partition.iterator(iteratorOptions, options)) {
187
+ if (limit !== undefined && matches.length === limit) {
188
+ break;
189
+ }
190
+ const item = JSON.parse(value);
191
+ // verify any residual filter properties in memory
192
+ if (hasResidualFilter && !FilterUtility.matchFilter(item.indexes, residualFilter)) {
193
+ continue;
194
+ }
195
+ matches.push(item);
196
+ }
197
+ return matches;
198
+ }
199
+ /**
200
+ * Counts items matching a compound index prefix without loading full records.
201
+ * Iterates only keys (not values) for maximum efficiency.
202
+ *
203
+ * @param queryFallback callback to fall back to full query if compound prefix fails.
204
+ */
205
+ export async function countWithCompoundIndex(db, tenant, filter, compoundIndex, encodeValue, queryFallback, options) {
206
+ const prefix = buildCompoundPrefix(filter, compoundIndex, encodeValue);
207
+ if (prefix === undefined) {
208
+ // fallback
209
+ const results = await queryFallback(tenant, [filter], { sortProperty: compoundIndex.sortProperty }, options);
210
+ return results.length;
211
+ }
212
+ const partition = await getCompoundIndexPartition(db, tenant, compoundIndex);
213
+ // determine which filter properties are NOT covered by the compound index
214
+ // (same logic as queryWithCompoundIndex: sort property range filters are residual)
215
+ const coveredEqualityProperties = new Set(compoundIndex.properties);
216
+ let hasResidualFilter = false;
217
+ const residualFilter = {};
218
+ for (const property in filter) {
219
+ if (!coveredEqualityProperties.has(property)) {
220
+ residualFilter[property] = filter[property];
221
+ hasResidualFilter = true;
222
+ }
223
+ }
224
+ const iteratorOptions = {
225
+ gt: prefix,
226
+ lt: prefix + '\xff',
227
+ };
228
+ let count = 0;
229
+ if (hasResidualFilter) {
230
+ // must read values to check residual filter
231
+ for await (const [_key, value] of partition.iterator(iteratorOptions, options)) {
232
+ const item = JSON.parse(value);
233
+ if (FilterUtility.matchFilter(item.indexes, residualFilter)) {
234
+ count++;
235
+ }
236
+ }
237
+ }
238
+ else {
239
+ // no residual filter — iterate keys via iterator without parsing values
240
+ for await (const [_key, _value] of partition.iterator(iteratorOptions, options)) {
241
+ count++;
242
+ }
243
+ }
244
+ return count;
245
+ }
246
+ //# sourceMappingURL=index-level-compound.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-level-compound.js","sourceRoot":"","sources":["../../../../src/store/index-level-compound.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,iGAAiG;AACjG,MAAM,CAAC,MAAM,0BAA0B,GAAG,MAAM,CAAC;AAEjD;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAC7C,EAAwB,EAAE,MAAc,EAAE,aAAsC;IAEhF,MAAM,aAAa,GAAG,cAAc,aAAa,CAAC,IAAI,IAAI,CAAC;IAC3D,OAAO,CAAC,MAAM,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;AAC/D,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAC9B,UAAkB,EAAE,OAAkB,EAAE,aAAsC,EAC9E,WAAyD,EAAE,SAAiB;IAE5E,MAAM,QAAQ,GAAa,EAAE,CAAC;IAE9B,KAAK,MAAM,QAAQ,IAAI,aAAa,CAAC,UAAU,EAAE,CAAC;QAChD,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;QAChC,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAChD,OAAO,SAAS,CAAC,CAAC,oEAAoE;QACxF,CAAC;QACD,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAA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