@enbox/dwn-sdk-js 0.0.7 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (368) 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 +817 -911
  4. package/dist/esm/generated/precompiled-validators.js.map +1 -1
  5. package/dist/esm/src/core/constants.js +11 -0
  6. package/dist/esm/src/core/constants.js.map +1 -0
  7. package/dist/esm/src/core/core-protocol.js +44 -0
  8. package/dist/esm/src/core/core-protocol.js.map +1 -0
  9. package/dist/esm/src/core/dwn-error.js +12 -12
  10. package/dist/esm/src/core/dwn-error.js.map +1 -1
  11. package/dist/esm/src/core/grant-authorization.js +16 -3
  12. package/dist/esm/src/core/grant-authorization.js.map +1 -1
  13. package/dist/esm/src/core/protocol-authorization-action.js +5 -0
  14. package/dist/esm/src/core/protocol-authorization-action.js.map +1 -1
  15. package/dist/esm/src/core/protocol-authorization-validation.js +91 -0
  16. package/dist/esm/src/core/protocol-authorization-validation.js.map +1 -1
  17. package/dist/esm/src/core/protocol-authorization.js +53 -30
  18. package/dist/esm/src/core/protocol-authorization.js.map +1 -1
  19. package/dist/esm/src/core/records-grant-authorization.js +6 -8
  20. package/dist/esm/src/core/records-grant-authorization.js.map +1 -1
  21. package/dist/esm/src/core/resumable-task-manager.js +2 -0
  22. package/dist/esm/src/core/resumable-task-manager.js.map +1 -1
  23. package/dist/esm/src/dwn.js +42 -18
  24. package/dist/esm/src/dwn.js.map +1 -1
  25. package/dist/esm/src/event-stream/event-emitter-event-log.js +204 -0
  26. package/dist/esm/src/event-stream/event-emitter-event-log.js.map +1 -0
  27. package/dist/esm/src/handlers/messages-read.js +7 -11
  28. package/dist/esm/src/handlers/messages-read.js.map +1 -1
  29. package/dist/esm/src/handlers/messages-subscribe.js +22 -24
  30. package/dist/esm/src/handlers/messages-subscribe.js.map +1 -1
  31. package/dist/esm/src/handlers/messages-sync.js +11 -15
  32. package/dist/esm/src/handlers/messages-sync.js.map +1 -1
  33. package/dist/esm/src/handlers/protocols-configure.js +37 -27
  34. package/dist/esm/src/handlers/protocols-configure.js.map +1 -1
  35. package/dist/esm/src/handlers/protocols-query.js +7 -11
  36. package/dist/esm/src/handlers/protocols-query.js.map +1 -1
  37. package/dist/esm/src/handlers/records-count.js +10 -12
  38. package/dist/esm/src/handlers/records-count.js.map +1 -1
  39. package/dist/esm/src/handlers/records-delete.js +10 -18
  40. package/dist/esm/src/handlers/records-delete.js.map +1 -1
  41. package/dist/esm/src/handlers/records-query.js +11 -15
  42. package/dist/esm/src/handlers/records-query.js.map +1 -1
  43. package/dist/esm/src/handlers/records-read.js +31 -26
  44. package/dist/esm/src/handlers/records-read.js.map +1 -1
  45. package/dist/esm/src/handlers/records-subscribe.js +39 -26
  46. package/dist/esm/src/handlers/records-subscribe.js.map +1 -1
  47. package/dist/esm/src/handlers/records-write.js +128 -105
  48. package/dist/esm/src/handlers/records-write.js.map +1 -1
  49. package/dist/esm/src/index.js +5 -2
  50. package/dist/esm/src/index.js.map +1 -1
  51. package/dist/esm/src/interfaces/messages-subscribe.js +1 -0
  52. package/dist/esm/src/interfaces/messages-subscribe.js.map +1 -1
  53. package/dist/esm/src/interfaces/protocols-configure.js +33 -3
  54. package/dist/esm/src/interfaces/protocols-configure.js.map +1 -1
  55. package/dist/esm/src/interfaces/records-count.js +1 -1
  56. package/dist/esm/src/interfaces/records-count.js.map +1 -1
  57. package/dist/esm/src/interfaces/records-delete.js +1 -1
  58. package/dist/esm/src/interfaces/records-delete.js.map +1 -1
  59. package/dist/esm/src/interfaces/records-query.js +1 -1
  60. package/dist/esm/src/interfaces/records-query.js.map +1 -1
  61. package/dist/esm/src/interfaces/records-read.js +1 -1
  62. package/dist/esm/src/interfaces/records-read.js.map +1 -1
  63. package/dist/esm/src/interfaces/records-subscribe.js +2 -1
  64. package/dist/esm/src/interfaces/records-subscribe.js.map +1 -1
  65. package/dist/esm/src/interfaces/records-write-signing.js +1 -12
  66. package/dist/esm/src/interfaces/records-write-signing.js.map +1 -1
  67. package/dist/esm/src/interfaces/records-write.js +25 -41
  68. package/dist/esm/src/interfaces/records-write.js.map +1 -1
  69. package/dist/esm/src/protocols/permission-grant.js +1 -1
  70. package/dist/esm/src/protocols/permission-grant.js.map +1 -1
  71. package/dist/esm/src/protocols/permission-request.js +1 -1
  72. package/dist/esm/src/protocols/permission-request.js.map +1 -1
  73. package/dist/esm/src/protocols/permissions.js +113 -5
  74. package/dist/esm/src/protocols/permissions.js.map +1 -1
  75. package/dist/esm/src/state-index/state-index-level.js +5 -7
  76. package/dist/esm/src/state-index/state-index-level.js.map +1 -1
  77. package/dist/esm/src/store/data-store-level.js +110 -33
  78. package/dist/esm/src/store/data-store-level.js.map +1 -1
  79. package/dist/esm/src/store/index-level.js +42 -32
  80. package/dist/esm/src/store/index-level.js.map +1 -1
  81. package/dist/esm/src/store/storage-controller.js +70 -6
  82. package/dist/esm/src/store/storage-controller.js.map +1 -1
  83. package/dist/esm/src/types/permission-types.js.map +1 -1
  84. package/dist/esm/src/types/protocols-types.js +11 -0
  85. package/dist/esm/src/types/protocols-types.js.map +1 -1
  86. package/dist/esm/src/types/records-types.js.map +1 -1
  87. package/dist/esm/src/utils/hd-key.js +0 -8
  88. package/dist/esm/src/utils/hd-key.js.map +1 -1
  89. package/dist/esm/src/utils/messages.js +16 -34
  90. package/dist/esm/src/utils/messages.js.map +1 -1
  91. package/dist/esm/src/utils/records.js +5 -43
  92. package/dist/esm/src/utils/records.js.map +1 -1
  93. package/dist/esm/tests/core/protocol-authorization.spec.js +2 -1
  94. package/dist/esm/tests/core/protocol-authorization.spec.js.map +1 -1
  95. package/dist/esm/tests/dwn.spec.js +32 -43
  96. package/dist/esm/tests/dwn.spec.js.map +1 -1
  97. package/dist/esm/tests/event-emitter-event-log.spec.js +305 -0
  98. package/dist/esm/tests/event-emitter-event-log.spec.js.map +1 -0
  99. package/dist/esm/tests/features/author-delegated-grant.spec.js +14 -7
  100. package/dist/esm/tests/features/author-delegated-grant.spec.js.map +1 -1
  101. package/dist/esm/tests/features/owner-delegated-grant.spec.js +9 -5
  102. package/dist/esm/tests/features/owner-delegated-grant.spec.js.map +1 -1
  103. package/dist/esm/tests/features/owner-signature.spec.js +14 -7
  104. package/dist/esm/tests/features/owner-signature.spec.js.map +1 -1
  105. package/dist/esm/tests/features/permissions.spec.js +12 -12
  106. package/dist/esm/tests/features/permissions.spec.js.map +1 -1
  107. package/dist/esm/tests/features/protocol-composition.spec.js +636 -5
  108. package/dist/esm/tests/features/protocol-composition.spec.js.map +1 -1
  109. package/dist/esm/tests/features/protocol-create-action.spec.js +4 -4
  110. package/dist/esm/tests/features/protocol-create-action.spec.js.map +1 -1
  111. package/dist/esm/tests/features/protocol-delete-action.spec.js +7 -7
  112. package/dist/esm/tests/features/protocol-delete-action.spec.js.map +1 -1
  113. package/dist/esm/tests/features/protocol-update-action.spec.js +4 -4
  114. package/dist/esm/tests/features/protocol-update-action.spec.js.map +1 -1
  115. package/dist/esm/tests/features/records-delivery.spec.js +236 -0
  116. package/dist/esm/tests/features/records-delivery.spec.js.map +1 -0
  117. package/dist/esm/tests/features/records-immutable.spec.js +315 -0
  118. package/dist/esm/tests/features/records-immutable.spec.js.map +1 -0
  119. package/dist/esm/tests/features/records-prune.spec.js +4 -4
  120. package/dist/esm/tests/features/records-prune.spec.js.map +1 -1
  121. package/dist/esm/tests/features/records-record-limit.spec.js +542 -0
  122. package/dist/esm/tests/features/records-record-limit.spec.js.map +1 -0
  123. package/dist/esm/tests/features/records-squash.spec.js +1055 -0
  124. package/dist/esm/tests/features/records-squash.spec.js.map +1 -0
  125. package/dist/esm/tests/features/records-tags.spec.js +16 -4
  126. package/dist/esm/tests/features/records-tags.spec.js.map +1 -1
  127. package/dist/esm/tests/features/resumable-tasks.spec.js +7 -8
  128. package/dist/esm/tests/features/resumable-tasks.spec.js.map +1 -1
  129. package/dist/esm/tests/handlers/messages-read.spec.js +11 -5
  130. package/dist/esm/tests/handlers/messages-read.spec.js.map +1 -1
  131. package/dist/esm/tests/handlers/messages-subscribe.spec.js +169 -22
  132. package/dist/esm/tests/handlers/messages-subscribe.spec.js.map +1 -1
  133. package/dist/esm/tests/handlers/messages-sync.spec.js +103 -21
  134. package/dist/esm/tests/handlers/messages-sync.spec.js.map +1 -1
  135. package/dist/esm/tests/handlers/protocols-configure.spec.js +5 -5
  136. package/dist/esm/tests/handlers/protocols-configure.spec.js.map +1 -1
  137. package/dist/esm/tests/handlers/protocols-query.spec.js +5 -5
  138. package/dist/esm/tests/handlers/protocols-query.spec.js.map +1 -1
  139. package/dist/esm/tests/handlers/records-count.spec.js +9 -4
  140. package/dist/esm/tests/handlers/records-count.spec.js.map +1 -1
  141. package/dist/esm/tests/handlers/records-delete.spec.js +24 -25
  142. package/dist/esm/tests/handlers/records-delete.spec.js.map +1 -1
  143. package/dist/esm/tests/handlers/records-query.spec.js +68 -9
  144. package/dist/esm/tests/handlers/records-query.spec.js.map +1 -1
  145. package/dist/esm/tests/handlers/records-read.spec.js +24 -138
  146. package/dist/esm/tests/handlers/records-read.spec.js.map +1 -1
  147. package/dist/esm/tests/handlers/records-subscribe.spec.js +175 -35
  148. package/dist/esm/tests/handlers/records-subscribe.spec.js.map +1 -1
  149. package/dist/esm/tests/handlers/records-write.spec.js +176 -72
  150. package/dist/esm/tests/handlers/records-write.spec.js.map +1 -1
  151. package/dist/esm/tests/interfaces/records-write.spec.js +52 -68
  152. package/dist/esm/tests/interfaces/records-write.spec.js.map +1 -1
  153. package/dist/esm/tests/protocols/permission-grant.spec.js +6 -6
  154. package/dist/esm/tests/protocols/permission-grant.spec.js.map +1 -1
  155. package/dist/esm/tests/protocols/permission-request.spec.js +4 -4
  156. package/dist/esm/tests/protocols/permission-request.spec.js.map +1 -1
  157. package/dist/esm/tests/protocols/permissions.spec.js +4 -4
  158. package/dist/esm/tests/protocols/permissions.spec.js.map +1 -1
  159. package/dist/esm/tests/scenarios/aggregator.spec.js +4 -4
  160. package/dist/esm/tests/scenarios/aggregator.spec.js.map +1 -1
  161. package/dist/esm/tests/scenarios/deleted-record.spec.js +350 -5
  162. package/dist/esm/tests/scenarios/deleted-record.spec.js.map +1 -1
  163. package/dist/esm/tests/scenarios/end-to-end-tests.spec.js +4 -4
  164. package/dist/esm/tests/scenarios/end-to-end-tests.spec.js.map +1 -1
  165. package/dist/esm/tests/scenarios/nested-roles.spec.js +4 -4
  166. package/dist/esm/tests/scenarios/nested-roles.spec.js.map +1 -1
  167. package/dist/esm/tests/scenarios/subscriptions.spec.js +93 -40
  168. package/dist/esm/tests/scenarios/subscriptions.spec.js.map +1 -1
  169. package/dist/esm/tests/store/data-store-level.spec.js +102 -41
  170. package/dist/esm/tests/store/data-store-level.spec.js.map +1 -1
  171. package/dist/esm/tests/test-event-stream.js +12 -13
  172. package/dist/esm/tests/test-event-stream.js.map +1 -1
  173. package/dist/esm/tests/test-suite.js +10 -4
  174. package/dist/esm/tests/test-suite.js.map +1 -1
  175. package/dist/esm/tests/utils/messages.spec.js +12 -5
  176. package/dist/esm/tests/utils/messages.spec.js.map +1 -1
  177. package/dist/esm/tests/utils/records.spec.js +8 -12
  178. package/dist/esm/tests/utils/records.spec.js.map +1 -1
  179. package/dist/esm/tests/utils/test-data-generator.js +36 -2
  180. package/dist/esm/tests/utils/test-data-generator.js.map +1 -1
  181. package/dist/esm/tests/validation/json-schemas/records/records-write.spec.js +37 -8
  182. package/dist/esm/tests/validation/json-schemas/records/records-write.spec.js.map +1 -1
  183. package/dist/types/generated/precompiled-validators.d.ts +49 -40
  184. package/dist/types/generated/precompiled-validators.d.ts.map +1 -1
  185. package/dist/types/src/core/constants.d.ts +11 -0
  186. package/dist/types/src/core/constants.d.ts.map +1 -0
  187. package/dist/types/src/core/core-protocol.d.ts +89 -0
  188. package/dist/types/src/core/core-protocol.d.ts.map +1 -0
  189. package/dist/types/src/core/dwn-error.d.ts +12 -12
  190. package/dist/types/src/core/dwn-error.d.ts.map +1 -1
  191. package/dist/types/src/core/grant-authorization.d.ts +6 -2
  192. package/dist/types/src/core/grant-authorization.d.ts.map +1 -1
  193. package/dist/types/src/core/protocol-authorization-action.d.ts.map +1 -1
  194. package/dist/types/src/core/protocol-authorization-validation.d.ts +30 -0
  195. package/dist/types/src/core/protocol-authorization-validation.d.ts.map +1 -1
  196. package/dist/types/src/core/protocol-authorization.d.ts +19 -11
  197. package/dist/types/src/core/protocol-authorization.d.ts.map +1 -1
  198. package/dist/types/src/core/records-grant-authorization.d.ts.map +1 -1
  199. package/dist/types/src/core/resumable-task-manager.d.ts +2 -1
  200. package/dist/types/src/core/resumable-task-manager.d.ts.map +1 -1
  201. package/dist/types/src/dwn.d.ts +19 -7
  202. package/dist/types/src/dwn.d.ts.map +1 -1
  203. package/dist/types/src/event-stream/event-emitter-event-log.d.ts +50 -0
  204. package/dist/types/src/event-stream/event-emitter-event-log.d.ts.map +1 -0
  205. package/dist/types/src/handlers/messages-read.d.ts +3 -8
  206. package/dist/types/src/handlers/messages-read.d.ts.map +1 -1
  207. package/dist/types/src/handlers/messages-subscribe.d.ts +6 -10
  208. package/dist/types/src/handlers/messages-subscribe.d.ts.map +1 -1
  209. package/dist/types/src/handlers/messages-sync.d.ts +3 -8
  210. package/dist/types/src/handlers/messages-sync.d.ts.map +1 -1
  211. package/dist/types/src/handlers/protocols-configure.d.ts +3 -10
  212. package/dist/types/src/handlers/protocols-configure.d.ts.map +1 -1
  213. package/dist/types/src/handlers/protocols-query.d.ts +3 -8
  214. package/dist/types/src/handlers/protocols-query.d.ts.map +1 -1
  215. package/dist/types/src/handlers/records-count.d.ts +3 -6
  216. package/dist/types/src/handlers/records-count.d.ts.map +1 -1
  217. package/dist/types/src/handlers/records-delete.d.ts +3 -8
  218. package/dist/types/src/handlers/records-delete.d.ts.map +1 -1
  219. package/dist/types/src/handlers/records-query.d.ts +3 -8
  220. package/dist/types/src/handlers/records-query.d.ts.map +1 -1
  221. package/dist/types/src/handlers/records-read.d.ts +3 -8
  222. package/dist/types/src/handlers/records-read.d.ts.map +1 -1
  223. package/dist/types/src/handlers/records-subscribe.d.ts +8 -10
  224. package/dist/types/src/handlers/records-subscribe.d.ts.map +1 -1
  225. package/dist/types/src/handlers/records-write.d.ts +12 -25
  226. package/dist/types/src/handlers/records-write.d.ts.map +1 -1
  227. package/dist/types/src/index.d.ts +8 -4
  228. package/dist/types/src/index.d.ts.map +1 -1
  229. package/dist/types/src/interfaces/messages-subscribe.d.ts +5 -0
  230. package/dist/types/src/interfaces/messages-subscribe.d.ts.map +1 -1
  231. package/dist/types/src/interfaces/protocols-configure.d.ts.map +1 -1
  232. package/dist/types/src/interfaces/records-subscribe.d.ts +5 -0
  233. package/dist/types/src/interfaces/records-subscribe.d.ts.map +1 -1
  234. package/dist/types/src/interfaces/records-write-signing.d.ts +3 -4
  235. package/dist/types/src/interfaces/records-write-signing.d.ts.map +1 -1
  236. package/dist/types/src/interfaces/records-write.d.ts +11 -11
  237. package/dist/types/src/interfaces/records-write.d.ts.map +1 -1
  238. package/dist/types/src/protocols/permission-grant.d.ts +1 -1
  239. package/dist/types/src/protocols/permission-grant.d.ts.map +1 -1
  240. package/dist/types/src/protocols/permission-request.d.ts +1 -1
  241. package/dist/types/src/protocols/permission-request.d.ts.map +1 -1
  242. package/dist/types/src/protocols/permissions.d.ts +40 -3
  243. package/dist/types/src/protocols/permissions.d.ts.map +1 -1
  244. package/dist/types/src/state-index/state-index-level.d.ts.map +1 -1
  245. package/dist/types/src/store/data-store-level.d.ts +20 -4
  246. package/dist/types/src/store/data-store-level.d.ts.map +1 -1
  247. package/dist/types/src/store/index-level.d.ts +4 -0
  248. package/dist/types/src/store/index-level.d.ts.map +1 -1
  249. package/dist/types/src/store/storage-controller.d.ts +20 -6
  250. package/dist/types/src/store/storage-controller.d.ts.map +1 -1
  251. package/dist/types/src/types/message-types.d.ts +3 -3
  252. package/dist/types/src/types/message-types.d.ts.map +1 -1
  253. package/dist/types/src/types/messages-types.d.ts +12 -3
  254. package/dist/types/src/types/messages-types.d.ts.map +1 -1
  255. package/dist/types/src/types/method-handler.d.ts +24 -3
  256. package/dist/types/src/types/method-handler.d.ts.map +1 -1
  257. package/dist/types/src/types/permission-types.d.ts +7 -0
  258. package/dist/types/src/types/permission-types.d.ts.map +1 -1
  259. package/dist/types/src/types/protocols-types.d.ts +69 -2
  260. package/dist/types/src/types/protocols-types.d.ts.map +1 -1
  261. package/dist/types/src/types/records-types.d.ts +23 -6
  262. package/dist/types/src/types/records-types.d.ts.map +1 -1
  263. package/dist/types/src/types/subscriptions.d.ts +151 -13
  264. package/dist/types/src/types/subscriptions.d.ts.map +1 -1
  265. package/dist/types/src/utils/hd-key.d.ts +1 -9
  266. package/dist/types/src/utils/hd-key.d.ts.map +1 -1
  267. package/dist/types/src/utils/messages.d.ts +7 -5
  268. package/dist/types/src/utils/messages.d.ts.map +1 -1
  269. package/dist/types/src/utils/records.d.ts +1 -11
  270. package/dist/types/src/utils/records.d.ts.map +1 -1
  271. package/dist/types/tests/dwn.spec.d.ts.map +1 -1
  272. package/dist/types/tests/event-emitter-event-log.spec.d.ts +2 -0
  273. package/dist/types/tests/event-emitter-event-log.spec.d.ts.map +1 -0
  274. package/dist/types/tests/features/author-delegated-grant.spec.d.ts.map +1 -1
  275. package/dist/types/tests/features/owner-delegated-grant.spec.d.ts.map +1 -1
  276. package/dist/types/tests/features/owner-signature.spec.d.ts.map +1 -1
  277. package/dist/types/tests/features/protocol-composition.spec.d.ts.map +1 -1
  278. package/dist/types/tests/features/records-delivery.spec.d.ts +2 -0
  279. package/dist/types/tests/features/records-delivery.spec.d.ts.map +1 -0
  280. package/dist/types/tests/features/records-immutable.spec.d.ts +2 -0
  281. package/dist/types/tests/features/records-immutable.spec.d.ts.map +1 -0
  282. package/dist/types/tests/features/records-record-limit.spec.d.ts +2 -0
  283. package/dist/types/tests/features/records-record-limit.spec.d.ts.map +1 -0
  284. package/dist/types/tests/features/records-squash.spec.d.ts +2 -0
  285. package/dist/types/tests/features/records-squash.spec.d.ts.map +1 -0
  286. package/dist/types/tests/features/records-tags.spec.d.ts.map +1 -1
  287. package/dist/types/tests/features/resumable-tasks.spec.d.ts.map +1 -1
  288. package/dist/types/tests/handlers/messages-read.spec.d.ts.map +1 -1
  289. package/dist/types/tests/handlers/messages-subscribe.spec.d.ts.map +1 -1
  290. package/dist/types/tests/handlers/messages-sync.spec.d.ts.map +1 -1
  291. package/dist/types/tests/handlers/records-count.spec.d.ts.map +1 -1
  292. package/dist/types/tests/handlers/records-delete.spec.d.ts.map +1 -1
  293. package/dist/types/tests/handlers/records-query.spec.d.ts.map +1 -1
  294. package/dist/types/tests/handlers/records-read.spec.d.ts.map +1 -1
  295. package/dist/types/tests/handlers/records-subscribe.spec.d.ts.map +1 -1
  296. package/dist/types/tests/handlers/records-write.spec.d.ts.map +1 -1
  297. package/dist/types/tests/scenarios/deleted-record.spec.d.ts.map +1 -1
  298. package/dist/types/tests/scenarios/subscriptions.spec.d.ts.map +1 -1
  299. package/dist/types/tests/test-event-stream.d.ts +11 -12
  300. package/dist/types/tests/test-event-stream.d.ts.map +1 -1
  301. package/dist/types/tests/test-suite.d.ts +2 -2
  302. package/dist/types/tests/test-suite.d.ts.map +1 -1
  303. package/dist/types/tests/utils/test-data-generator.d.ts +19 -0
  304. package/dist/types/tests/utils/test-data-generator.d.ts.map +1 -1
  305. package/package.json +5 -4
  306. package/src/core/constants.ts +11 -0
  307. package/src/core/core-protocol.ts +129 -0
  308. package/src/core/dwn-error.ts +18 -12
  309. package/src/core/grant-authorization.ts +20 -3
  310. package/src/core/protocol-authorization-action.ts +5 -0
  311. package/src/core/protocol-authorization-validation.ts +133 -0
  312. package/src/core/protocol-authorization.ts +71 -23
  313. package/src/core/records-grant-authorization.ts +6 -8
  314. package/src/core/resumable-task-manager.ts +3 -1
  315. package/src/dwn.ts +58 -73
  316. package/src/event-stream/event-emitter-event-log.ts +283 -0
  317. package/src/handlers/messages-read.ts +8 -9
  318. package/src/handlers/messages-subscribe.ts +24 -28
  319. package/src/handlers/messages-sync.ts +10 -16
  320. package/src/handlers/protocols-configure.ts +47 -32
  321. package/src/handlers/protocols-query.ts +6 -9
  322. package/src/handlers/records-count.ts +11 -10
  323. package/src/handlers/records-delete.ts +12 -21
  324. package/src/handlers/records-query.ts +12 -12
  325. package/src/handlers/records-read.ts +34 -22
  326. package/src/handlers/records-subscribe.ts +47 -26
  327. package/src/handlers/records-write.ts +152 -119
  328. package/src/index.ts +9 -5
  329. package/src/interfaces/messages-subscribe.ts +7 -1
  330. package/src/interfaces/protocols-configure.ts +51 -3
  331. package/src/interfaces/records-count.ts +1 -1
  332. package/src/interfaces/records-delete.ts +1 -1
  333. package/src/interfaces/records-query.ts +1 -1
  334. package/src/interfaces/records-read.ts +1 -1
  335. package/src/interfaces/records-subscribe.ts +8 -1
  336. package/src/interfaces/records-write-signing.ts +2 -22
  337. package/src/interfaces/records-write.ts +35 -48
  338. package/src/protocols/permission-grant.ts +1 -1
  339. package/src/protocols/permission-request.ts +1 -1
  340. package/src/protocols/permissions.ts +148 -6
  341. package/src/state-index/state-index-level.ts +5 -7
  342. package/src/store/data-store-level.ts +124 -34
  343. package/src/store/index-level.ts +44 -35
  344. package/src/store/storage-controller.ts +89 -12
  345. package/src/types/message-types.ts +3 -3
  346. package/src/types/messages-types.ts +12 -3
  347. package/src/types/method-handler.ts +26 -4
  348. package/src/types/mitt.d.ts +28 -0
  349. package/src/types/permission-types.ts +7 -0
  350. package/src/types/protocols-types.ts +78 -1
  351. package/src/types/records-types.ts +24 -6
  352. package/src/types/subscriptions.ts +178 -14
  353. package/src/utils/hd-key.ts +0 -9
  354. package/src/utils/messages.ts +17 -37
  355. package/src/utils/records.ts +7 -58
  356. package/dist/esm/src/event-stream/event-emitter-stream.js +0 -46
  357. package/dist/esm/src/event-stream/event-emitter-stream.js.map +0 -1
  358. package/dist/esm/tests/event-stream/event-emitter-stream.spec.js +0 -68
  359. package/dist/esm/tests/event-stream/event-emitter-stream.spec.js.map +0 -1
  360. package/dist/esm/tests/event-stream/event-stream.spec.js +0 -114
  361. package/dist/esm/tests/event-stream/event-stream.spec.js.map +0 -1
  362. package/dist/types/src/event-stream/event-emitter-stream.d.ts +0 -23
  363. package/dist/types/src/event-stream/event-emitter-stream.d.ts.map +0 -1
  364. package/dist/types/tests/event-stream/event-emitter-stream.spec.d.ts +0 -2
  365. package/dist/types/tests/event-stream/event-emitter-stream.spec.d.ts.map +0 -1
  366. package/dist/types/tests/event-stream/event-stream.spec.d.ts +0 -2
  367. package/dist/types/tests/event-stream/event-stream.spec.d.ts.map +0 -1
  368. package/src/event-stream/event-emitter-stream.ts +0 -69
@@ -3,6 +3,8 @@ import type { MessageStore } from '../types/message-store.js';
3
3
  import type { RecordsWriteMessage } from '../types/records-types.js';
4
4
  import type { ProtocolDefinition, ProtocolRuleSet, ProtocolType, ProtocolTypes } from '../types/protocols-types.js';
5
5
 
6
+ import { ProtocolRecordLimitStrategy } from '../types/protocols-types.js';
7
+
6
8
  import type { RecordsWrite } from '../interfaces/records-write.js';
7
9
 
8
10
  import Ajv from 'ajv/dist/2020.js';
@@ -389,3 +391,134 @@ export async function verifyAsRoleRecordIfNeeded(
389
391
  );
390
392
  }
391
393
  }
394
+
395
+ /**
396
+ * Verifies that a new record creation does not exceed the `$recordLimit` defined in the rule set.
397
+ *
398
+ * This check only applies to initial writes (new records). Updates to existing records are not counted.
399
+ * The count is scoped to the same `protocol + protocolPath` within the parent context:
400
+ * - For root-level records: counted across the entire protocol for the tenant.
401
+ * - For nested records: counted within the parent record's context.
402
+ *
403
+ * @throws {DwnError} with `ProtocolAuthorizationRecordLimitExceeded` if the limit is reached and strategy is `reject`.
404
+ * @throws {DwnError} with `ProtocolAuthorizationRecordLimitStrategyNotImplemented` if strategy is not yet implemented.
405
+ */
406
+ export async function verifyRecordLimit(
407
+ tenant: string,
408
+ incomingMessage: RecordsWrite,
409
+ ruleSet: ProtocolRuleSet,
410
+ messageStore: MessageStore,
411
+ ): Promise<void> {
412
+ if (ruleSet.$recordLimit === undefined) {
413
+ return;
414
+ }
415
+
416
+ // Only enforce on initial writes — updates to existing records do not count as new records.
417
+ const isInitialWrite = await incomingMessage.isInitialWrite();
418
+ if (!isInitialWrite) {
419
+ return;
420
+ }
421
+
422
+ const { max, strategy } = ruleSet.$recordLimit;
423
+
424
+ // Build a filter to count existing records at the same protocol path and parent context.
425
+ const protocolPath = incomingMessage.message.descriptor.protocolPath!;
426
+ const filter: Filter = {
427
+ interface : DwnInterfaceName.Records,
428
+ method : DwnMethodName.Write,
429
+ isLatestBaseState : true,
430
+ protocol : incomingMessage.message.descriptor.protocol!,
431
+ protocolPath,
432
+ };
433
+
434
+ // Scope by parent context for nested records.
435
+ const parentContextId = Records.getParentContextFromOfContextId(incomingMessage.message.contextId)!;
436
+ if (parentContextId !== '') {
437
+ const prefixFilter = FilterUtility.constructPrefixFilterAsRangeFilter(parentContextId);
438
+ filter.contextId = prefixFilter;
439
+ }
440
+
441
+ const existingCount = await messageStore.count(tenant, [filter]);
442
+
443
+ if (existingCount >= max) {
444
+ if (strategy === ProtocolRecordLimitStrategy.Reject) {
445
+ throw new DwnError(
446
+ DwnErrorCode.ProtocolAuthorizationRecordLimitExceeded,
447
+ `record limit of ${max} reached at protocol path '${protocolPath}'` +
448
+ `${parentContextId !== '' ? ` under parent context '${parentContextId}'` : ''}` +
449
+ `: new records are rejected until existing records are deleted.`
450
+ );
451
+ }
452
+
453
+ // Future strategies (e.g. purgeOldest) will be implemented here.
454
+ // For now, any non-reject strategy that somehow passes schema validation is rejected.
455
+ throw new DwnError(
456
+ DwnErrorCode.ProtocolAuthorizationRecordLimitStrategyNotImplemented,
457
+ `record limit strategy '${strategy}' is not yet implemented.`
458
+ );
459
+ }
460
+ }
461
+
462
+ /**
463
+ * Verifies that a `RecordsWrite` with `squash: true` is eligible:
464
+ * 1. The protocol rule set at the record's `protocolPath` must have `$squash: true`.
465
+ * 2. The squash write must be an initial write (a new record, not an update).
466
+ *
467
+ * @throws {DwnError} with `ProtocolAuthorizationSquashNotEnabled` if `$squash` is not enabled.
468
+ * @throws {DwnError} with `ProtocolAuthorizationSquashNotInitialWrite` if the squash write is not an initial write.
469
+ */
470
+ export async function verifySquashEligibility(
471
+ incomingMessage: RecordsWrite,
472
+ ruleSet: ProtocolRuleSet,
473
+ ): Promise<void> {
474
+ const squash = incomingMessage.message.descriptor.squash;
475
+
476
+ if (squash !== true) {
477
+ return;
478
+ }
479
+
480
+ // squash write must be at a protocol path with $squash: true
481
+ if (ruleSet.$squash !== true) {
482
+ throw new DwnError(
483
+ DwnErrorCode.ProtocolAuthorizationSquashNotEnabled,
484
+ `squash writes are not enabled at protocol path '${incomingMessage.message.descriptor.protocolPath}': ` +
485
+ `rule set must have $squash: true.`
486
+ );
487
+ }
488
+
489
+ // squash write must be an initial write (a new record, not an update)
490
+ const isInitialWrite = await incomingMessage.isInitialWrite();
491
+ if (!isInitialWrite) {
492
+ throw new DwnError(
493
+ DwnErrorCode.ProtocolAuthorizationSquashNotInitialWrite,
494
+ `squash write must be an initial write (a new record): updates cannot be squash writes.`
495
+ );
496
+ }
497
+ }
498
+
499
+ /**
500
+ * Verifies that an update is not attempted on a record whose protocol path has `$immutable: true`.
501
+ *
502
+ * Only non-initial writes (updates) are rejected — initial writes are always allowed.
503
+ * `RecordsDelete` is not affected by this check; immutability prevents data mutation, not removal.
504
+ *
505
+ * @throws {DwnError} with `ProtocolAuthorizationImmutableRecord` if an update is attempted on an immutable record.
506
+ */
507
+ export async function verifyImmutability(
508
+ incomingMessage: RecordsWrite,
509
+ ruleSet: ProtocolRuleSet,
510
+ ): Promise<void> {
511
+ if (ruleSet.$immutable !== true) {
512
+ return;
513
+ }
514
+
515
+ const isInitialWrite = await incomingMessage.isInitialWrite();
516
+ if (isInitialWrite) {
517
+ return;
518
+ }
519
+
520
+ throw new DwnError(
521
+ DwnErrorCode.ProtocolAuthorizationImmutableRecord,
522
+ `record at protocol path '${incomingMessage.message.descriptor.protocolPath}' is immutable: updates are not allowed.`
523
+ );
524
+ }
@@ -1,6 +1,6 @@
1
+ import type { CoreProtocolRegistry } from './core-protocol.js';
1
2
  import type { Filter } from '../types/query-types.js';
2
3
  import type { MessageStore } from '../types/message-store.js';
3
- import type { ProtocolAction } from '../types/protocols-types.js';
4
4
  import type { RecordsCount } from '../interfaces/records-count.js';
5
5
  import type { RecordsDelete } from '../interfaces/records-delete.js';
6
6
  import type { RecordsQuery } from '../interfaces/records-query.js';
@@ -11,17 +11,19 @@ import type { RecordsWriteMessage } from '../types/records-types.js';
11
11
  import type { ProtocolDefinition, ProtocolRuleSet, ProtocolsConfigureMessage } from '../types/protocols-types.js';
12
12
 
13
13
  import { getRuleSetAtPath } from '../utils/protocols.js';
14
- import { PermissionsProtocol } from '../protocols/permissions.js';
15
14
  import { SortDirection } from '../types/query-types.js';
16
15
  import { DwnError, DwnErrorCode } from './dwn-error.js';
17
16
  import { DwnInterfaceName, DwnMethodName } from '../enums/dwn-interface-method.js';
18
17
 
19
- import { authorizeAgainstAllowedActions, getActionsSeekingARuleMatch, verifyInvokedRole } from './protocol-authorization-action.js';
18
+ import { authorizeAgainstAllowedActions, verifyInvokedRole } from './protocol-authorization-action.js';
20
19
  import { constructRecordChain, fetchInitialWrite, getGoverningTimestamp } from './record-chain.js';
21
20
  import {
22
21
  verifyAsRoleRecordIfNeeded,
22
+ verifyImmutability,
23
23
  verifyProtocolPathAndContextId,
24
+ verifyRecordLimit,
24
25
  verifySizeLimit,
26
+ verifySquashEligibility,
25
27
  verifyTagsIfNeeded,
26
28
  verifyTypeWithComposition,
27
29
  } from './protocol-authorization-validation.js';
@@ -47,6 +49,7 @@ export class ProtocolAuthorization {
47
49
  tenant: string,
48
50
  incomingMessage: RecordsWrite,
49
51
  messageStore: MessageStore,
52
+ coreProtocols?: CoreProtocolRegistry,
50
53
  ): Promise<void> {
51
54
  // Determine the governing timestamp for protocol definition lookup.
52
55
  // For an initial write, this is the message's own timestamp.
@@ -61,19 +64,23 @@ export class ProtocolAuthorization {
61
64
  incomingMessage.message.descriptor.protocol!,
62
65
  messageStore,
63
66
  governingTimestamp,
67
+ coreProtocols,
64
68
  );
65
69
 
70
+ // Create a bound fetch function that captures the registry for downstream callbacks.
71
+ const boundFetchDefinition = ProtocolAuthorization.createBoundFetchDefinition(coreProtocols);
72
+
66
73
  // verify declared protocol type exists in protocol and that it conforms to type specification.
67
74
  // For cross-protocol composition, the type may be defined in a referenced protocol.
68
75
  await verifyTypeWithComposition(
69
76
  tenant, incomingMessage.message, protocolDefinition, messageStore,
70
- ProtocolAuthorization.fetchProtocolDefinition, governingTimestamp
77
+ boundFetchDefinition, governingTimestamp
71
78
  );
72
79
 
73
80
  // validate `protocolPath`
74
81
  await verifyProtocolPathAndContextId(
75
82
  tenant, incomingMessage, messageStore,
76
- ProtocolAuthorization.fetchProtocolDefinition, governingTimestamp,
83
+ boundFetchDefinition, governingTimestamp,
77
84
  );
78
85
 
79
86
  // get the rule set for the inbound message
@@ -95,6 +102,15 @@ export class ProtocolAuthorization {
95
102
 
96
103
  // Verify protocol tags
97
104
  verifyTagsIfNeeded(incomingMessage, ruleSet);
105
+
106
+ // Verify immutability — reject updates to write-once records
107
+ await verifyImmutability(incomingMessage, ruleSet);
108
+
109
+ // Verify squash eligibility — ensure squash writes are at $squash: true paths and are initial writes
110
+ await verifySquashEligibility(incomingMessage, ruleSet);
111
+
112
+ // Verify record count limit
113
+ await verifyRecordLimit(tenant, incomingMessage, ruleSet, messageStore);
98
114
  }
99
115
 
100
116
  /**
@@ -105,6 +121,7 @@ export class ProtocolAuthorization {
105
121
  tenant: string,
106
122
  incomingMessage: RecordsWrite,
107
123
  messageStore: MessageStore,
124
+ coreProtocols?: CoreProtocolRegistry,
108
125
  ): Promise<void> {
109
126
  const existingInitialWrite = await fetchInitialWrite(tenant, incomingMessage.message.recordId, messageStore);
110
127
 
@@ -129,6 +146,7 @@ export class ProtocolAuthorization {
129
146
  incomingMessage.message.descriptor.protocol!,
130
147
  messageStore,
131
148
  governingTimestamp,
149
+ coreProtocols,
132
150
  );
133
151
 
134
152
  // get the rule set for the inbound message
@@ -137,6 +155,8 @@ export class ProtocolAuthorization {
137
155
  protocolDefinition,
138
156
  );
139
157
 
158
+ const boundFetchDefinition = ProtocolAuthorization.createBoundFetchDefinition(coreProtocols);
159
+
140
160
  // If the incoming message has `protocolRole` in the descriptor, validate the invoked role
141
161
  await verifyInvokedRole(
142
162
  tenant,
@@ -145,7 +165,7 @@ export class ProtocolAuthorization {
145
165
  incomingMessage.message.contextId!,
146
166
  protocolDefinition,
147
167
  messageStore,
148
- ProtocolAuthorization.fetchProtocolDefinition,
168
+ boundFetchDefinition,
149
169
  governingTimestamp,
150
170
  );
151
171
 
@@ -170,6 +190,7 @@ export class ProtocolAuthorization {
170
190
  incomingMessage: RecordsRead,
171
191
  newestRecordsWrite: RecordsWrite,
172
192
  messageStore: MessageStore,
193
+ coreProtocols?: CoreProtocolRegistry,
173
194
  ): Promise<void> {
174
195
  // fetch record chain
175
196
  const recordChain: RecordsWriteMessage[] =
@@ -190,6 +211,7 @@ export class ProtocolAuthorization {
190
211
  newestRecordsWrite.message.descriptor.protocol!,
191
212
  messageStore,
192
213
  governingTimestamp,
214
+ coreProtocols,
193
215
  );
194
216
 
195
217
  // get the rule set for the inbound message
@@ -198,6 +220,8 @@ export class ProtocolAuthorization {
198
220
  protocolDefinition,
199
221
  );
200
222
 
223
+ const boundFetchDefinition = ProtocolAuthorization.createBoundFetchDefinition(coreProtocols);
224
+
201
225
  // If the incoming message has `protocolRole` in the descriptor, validate the invoked role
202
226
  await verifyInvokedRole(
203
227
  tenant,
@@ -206,7 +230,7 @@ export class ProtocolAuthorization {
206
230
  newestRecordsWrite.message.contextId!,
207
231
  protocolDefinition,
208
232
  messageStore,
209
- ProtocolAuthorization.fetchProtocolDefinition,
233
+ boundFetchDefinition,
210
234
  governingTimestamp,
211
235
  );
212
236
 
@@ -225,6 +249,7 @@ export class ProtocolAuthorization {
225
249
  tenant: string,
226
250
  incomingMessage: RecordsCount | RecordsQuery | RecordsSubscribe,
227
251
  messageStore: MessageStore,
252
+ coreProtocols?: CoreProtocolRegistry,
228
253
  ): Promise<void> {
229
254
  const { protocol, protocolPath, contextId } = incomingMessage.message.descriptor.filter;
230
255
 
@@ -233,6 +258,8 @@ export class ProtocolAuthorization {
233
258
  tenant,
234
259
  protocol!, // `authorizeQueryOrSubscribe` is only called if `protocol` is present
235
260
  messageStore,
261
+ undefined,
262
+ coreProtocols,
236
263
  );
237
264
 
238
265
  // get the rule set for the inbound message
@@ -241,6 +268,8 @@ export class ProtocolAuthorization {
241
268
  protocolDefinition,
242
269
  );
243
270
 
271
+ const boundFetchDefinition = ProtocolAuthorization.createBoundFetchDefinition(coreProtocols);
272
+
244
273
  // If the incoming message has `protocolRole` in the descriptor, validate the invoked role
245
274
  await verifyInvokedRole(
246
275
  tenant,
@@ -249,7 +278,7 @@ export class ProtocolAuthorization {
249
278
  contextId,
250
279
  protocolDefinition,
251
280
  messageStore,
252
- ProtocolAuthorization.fetchProtocolDefinition,
281
+ boundFetchDefinition,
253
282
  );
254
283
 
255
284
  // verify method invoked against the allowed actions in the rule set
@@ -272,6 +301,7 @@ export class ProtocolAuthorization {
272
301
  incomingMessage: RecordsDelete,
273
302
  recordsWrite: RecordsWrite,
274
303
  messageStore: MessageStore,
304
+ coreProtocols?: CoreProtocolRegistry,
275
305
  ): Promise<void> {
276
306
 
277
307
  // fetch record chain
@@ -292,6 +322,7 @@ export class ProtocolAuthorization {
292
322
  recordsWrite.message.descriptor.protocol!,
293
323
  messageStore,
294
324
  governingTimestamp,
325
+ coreProtocols,
295
326
  );
296
327
 
297
328
  // get the rule set for the inbound message
@@ -300,6 +331,8 @@ export class ProtocolAuthorization {
300
331
  protocolDefinition,
301
332
  );
302
333
 
334
+ const boundFetchDefinition = ProtocolAuthorization.createBoundFetchDefinition(coreProtocols);
335
+
303
336
  // If the incoming message has `protocolRole` in the descriptor, validate the invoked role
304
337
  await verifyInvokedRole(
305
338
  tenant,
@@ -308,7 +341,7 @@ export class ProtocolAuthorization {
308
341
  recordsWrite.message.contextId!,
309
342
  protocolDefinition,
310
343
  messageStore,
311
- ProtocolAuthorization.fetchProtocolDefinition,
344
+ boundFetchDefinition,
312
345
  governingTimestamp,
313
346
  );
314
347
 
@@ -328,16 +361,25 @@ export class ProtocolAuthorization {
328
361
  * When `messageTimestamp` is provided, returns the protocol definition that was active at that
329
362
  * point in time — i.e. the ProtocolsConfigure with the greatest `messageTimestamp` that is <= the
330
363
  * given timestamp. When not provided, returns the latest (current) protocol definition.
364
+ *
365
+ * When `coreProtocols` is provided, core protocol definitions are returned directly from the
366
+ * registry without a message store query. The extra parameter does not affect the
367
+ * `FetchProtocolDefinitionFn` callback type — callers that pass this function as a callback
368
+ * should bind the registry via a closure (see `createBoundFetchDefinition`).
331
369
  */
332
370
  public static async fetchProtocolDefinition(
333
371
  tenant: string,
334
372
  protocolUri: string,
335
373
  messageStore: MessageStore,
336
374
  messageTimestamp?: string,
375
+ coreProtocols?: CoreProtocolRegistry,
337
376
  ): Promise<ProtocolDefinition> {
338
- // if first-class protocol, return the definition from const object directly without going to data store
339
- if (protocolUri === PermissionsProtocol.uri) {
340
- return PermissionsProtocol.definition;
377
+ // if the protocol is a registered core protocol, return the definition directly without a store query
378
+ if (coreProtocols !== undefined) {
379
+ const coreDefinition = coreProtocols.getDefinition(protocolUri);
380
+ if (coreDefinition !== undefined) {
381
+ return coreDefinition;
382
+ }
341
383
  }
342
384
 
343
385
  // fetch the corresponding protocol definition
@@ -370,6 +412,23 @@ export class ProtocolAuthorization {
370
412
  return protocolMessage.descriptor.definition;
371
413
  }
372
414
 
415
+ /**
416
+ * Creates a `FetchProtocolDefinitionFn` closure that binds the given `CoreProtocolRegistry`.
417
+ * This allows core protocol definitions to be resolved from the registry without changing
418
+ * the `FetchProtocolDefinitionFn` type signature — zero ripple to downstream consumers
419
+ * like `protocol-authorization-action.ts` and `protocol-authorization-validation.ts`.
420
+ */
421
+ private static createBoundFetchDefinition(coreProtocols?: CoreProtocolRegistry): FetchProtocolDefinitionFn {
422
+ return (
423
+ tenant: string,
424
+ protocolUri: string,
425
+ messageStore: MessageStore,
426
+ messageTimestamp?: string,
427
+ ): Promise<ProtocolDefinition> => {
428
+ return ProtocolAuthorization.fetchProtocolDefinition(tenant, protocolUri, messageStore, messageTimestamp, coreProtocols);
429
+ };
430
+ }
431
+
373
432
  /**
374
433
  * Gets the rule set corresponding to the given protocolPath.
375
434
  */
@@ -385,15 +444,4 @@ export class ProtocolAuthorization {
385
444
  return ruleSet;
386
445
  }
387
446
 
388
- /**
389
- * Returns all the ProtocolActions that would authorize the incoming message.
390
- * Delegates to the standalone function in `protocol-authorization-action.ts`.
391
- */
392
- private static async getActionsSeekingARuleMatch(
393
- tenant: string,
394
- incomingMessage: RecordsCount | RecordsDelete | RecordsQuery | RecordsRead | RecordsSubscribe | RecordsWrite,
395
- messageStore: MessageStore,
396
- ): Promise<ProtocolAction[]> {
397
- return getActionsSeekingARuleMatch(tenant, incomingMessage, messageStore);
398
- }
399
447
  }
@@ -87,15 +87,14 @@ export class RecordsGrantAuthorization {
87
87
  messageStore
88
88
  });
89
89
 
90
- // If the grant specifies a protocol, the subscribe or query must specify the same protocol.
90
+ // The grant's protocol must match the query/subscribe filter's protocol.
91
91
  // NOTE: validated the invoked permission is for Records in GrantAuthorization.performBaseValidation()
92
92
  const permissionScope = permissionGrant.scope as RecordsPermissionScope;
93
- const protocolInGrant = permissionScope.protocol;
94
93
  const protocolInMessage = incomingMessage.descriptor.filter.protocol;
95
- if (protocolInGrant !== undefined && protocolInMessage !== protocolInGrant) {
94
+ if (protocolInMessage !== permissionScope.protocol) {
96
95
  throw new DwnError(
97
96
  DwnErrorCode.RecordsGrantAuthorizationQueryOrSubscribeProtocolScopeMismatch,
98
- `Grant protocol scope ${protocolInGrant} does not match protocol in message ${protocolInMessage}`
97
+ `Grant protocol scope ${permissionScope.protocol} does not match protocol in message ${protocolInMessage}`
99
98
  );
100
99
  }
101
100
  }
@@ -124,15 +123,14 @@ export class RecordsGrantAuthorization {
124
123
  messageStore
125
124
  });
126
125
 
127
- // If the grant specifies a protocol, the delete must be deleting a record with the same protocol.
126
+ // The grant's protocol must match the protocol of the record being deleted.
128
127
  // NOTE: validated the invoked permission is for Records in GrantAuthorization.performBaseValidation()
129
128
  const permissionScope = permissionGrant.scope as RecordsPermissionScope;
130
- const protocolInGrant = permissionScope.protocol;
131
129
  const protocolOfRecordToDelete = recordsWriteToDelete.descriptor.protocol;
132
- if (protocolInGrant !== undefined && protocolOfRecordToDelete !== protocolInGrant) {
130
+ if (protocolOfRecordToDelete !== permissionScope.protocol) {
133
131
  throw new DwnError(
134
132
  DwnErrorCode.RecordsGrantAuthorizationDeleteProtocolScopeMismatch,
135
- `Grant protocol scope ${protocolInGrant} does not match protocol in record to delete ${protocolOfRecordToDelete}`
133
+ `Grant protocol scope ${permissionScope.protocol} does not match protocol in record to delete ${protocolOfRecordToDelete}`
136
134
  );
137
135
  }
138
136
  }
@@ -3,6 +3,7 @@ import type { ManagedResumableTask, ResumableTaskStore } from '../types/resumabl
3
3
 
4
4
  export enum ResumableTaskName {
5
5
  RecordsDelete = 'RecordsDelete',
6
+ RecordsSquash = 'RecordsSquash',
6
7
  }
7
8
 
8
9
  export type ResumableTask = {
@@ -26,7 +27,8 @@ export class ResumableTaskManager {
26
27
  this.resumableTaskHandlers = {
27
28
  // NOTE: The arrow function is IMPORTANT here, else the `this` context will be lost within the invoked method.
28
29
  // e.g. code within performRecordsDelete() won't know `this` refers to the `storageController` instance.
29
- [ResumableTaskName.RecordsDelete]: async (task): Promise<void> => await storageController.performRecordsDelete(task),
30
+ [ResumableTaskName.RecordsDelete] : async (task): Promise<void> => await storageController.performRecordsDelete(task),
31
+ [ResumableTaskName.RecordsSquash] : async (task): Promise<void> => await storageController.performRecordsSquash(task),
30
32
  };
31
33
  }
32
34