keri-ts 2.0.1 → 2.2.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 (450) hide show
  1. package/README.md +30 -2
  2. package/esm/keri/npm/src/acdc/authoring.js +195 -0
  3. package/esm/keri/npm/src/acdc/chaining.js +223 -89
  4. package/esm/keri/npm/src/acdc/custody.js +164 -0
  5. package/esm/keri/npm/src/acdc/dhking.js +244 -32
  6. package/esm/keri/npm/src/acdc/observing.js +2 -2
  7. package/esm/keri/npm/src/acdc/regbasing.js +30 -29
  8. package/esm/keri/npm/src/acdc/regengine.js +4 -6
  9. package/esm/keri/npm/src/acdc/registering.js +13 -10
  10. package/esm/keri/npm/src/acdc/registraring.js +4 -9
  11. package/esm/keri/npm/src/acdc/salting.js +143 -26
  12. package/esm/keri/npm/src/acdc/scheming.js +93 -54
  13. package/esm/keri/npm/src/acdc/unblinding.js +120 -99
  14. package/esm/keri/npm/src/app/bootstrap/authenticating.js +4 -6
  15. package/esm/keri/npm/src/app/bootstrap/oobi-resolving.js +41 -0
  16. package/esm/keri/npm/src/app/bootstrap/oobiery.js +5 -7
  17. package/esm/keri/npm/src/app/credentials/credential-revoking.js +1 -0
  18. package/esm/keri/npm/src/app/credentials/credential-workflows.js +2 -0
  19. package/esm/keri/npm/src/app/credentials/registry-settling.js +44 -0
  20. package/esm/keri/npm/src/app/credentials/root-replicating.js +131 -0
  21. package/esm/keri/npm/src/app/credentials/root-replicator.js +198 -0
  22. package/esm/keri/npm/src/app/credentials/tel-completion.js +36 -0
  23. package/esm/keri/npm/src/app/credentials/verifying.js +12 -3
  24. package/esm/keri/npm/src/app/delivery/forwarding.js +64 -9
  25. package/esm/keri/npm/src/app/exchanges/exchanging.js +24 -15
  26. package/esm/keri/npm/src/app/identity/challenging.js +50 -0
  27. package/esm/keri/npm/src/app/identity/configing.js +17 -43
  28. package/esm/keri/npm/src/app/identity/delegating.js +77 -77
  29. package/esm/keri/npm/src/app/identity/delegation-approval.js +333 -0
  30. package/esm/keri/npm/src/app/identity/event-completion.js +154 -0
  31. package/esm/keri/npm/src/app/identity/habbing.js +183 -41
  32. package/esm/keri/npm/src/app/identity/keeping.js +78 -5
  33. package/esm/keri/npm/src/app/identity/lmdb-habery.js +12 -0
  34. package/esm/keri/npm/src/app/ipex/group-ipex.js +327 -0
  35. package/esm/keri/npm/src/app/ipex/group-issuance.js +902 -0
  36. package/esm/keri/npm/src/app/ipex/ipex-admitting.js +120 -0
  37. package/esm/keri/npm/src/app/ipex/ipex-conversation.js +197 -0
  38. package/esm/keri/npm/src/app/ipex/ipex-discloser.js +591 -0
  39. package/esm/keri/npm/src/app/ipex/ipex-granting.js +93 -0
  40. package/esm/keri/npm/src/app/ipex/ipex-graph.js +7 -70
  41. package/esm/keri/npm/src/app/ipex/ipex-grouping.js +42 -16
  42. package/esm/keri/npm/src/app/ipex/ipex-v2.js +21 -5
  43. package/esm/keri/npm/src/app/ipex/ipexing.js +1 -1
  44. package/esm/keri/npm/src/app/ipex/issuance.js +888 -0
  45. package/esm/keri/npm/src/app/ipex/pending-presentations.js +46 -0
  46. package/esm/keri/npm/src/app/ipex/presentation-files.js +200 -0
  47. package/esm/keri/npm/src/app/ipex/presenting.js +401 -0
  48. package/esm/keri/npm/src/app/ipex/receive-issuance.js +86 -0
  49. package/esm/keri/npm/src/app/ipex/unblinding-workflow.js +660 -0
  50. package/esm/keri/npm/src/app/mailbox/ipex-arrival.js +103 -0
  51. package/esm/keri/npm/src/app/mailbox/kel-publisher.js +322 -0
  52. package/esm/keri/npm/src/app/mailbox/kel-publishing.js +65 -0
  53. package/esm/keri/npm/src/app/mailbox/kel-submission.js +24 -0
  54. package/esm/keri/npm/src/app/mailbox/mailbox-admin.js +208 -0
  55. package/esm/keri/npm/src/app/mailbox/mailbox-poller.js +212 -47
  56. package/esm/keri/npm/src/app/mailbox/mailboxing.js +15 -14
  57. package/esm/keri/npm/src/app/multisig/counseling.js +482 -0
  58. package/esm/keri/npm/src/app/multisig/group-members.js +32 -0
  59. package/esm/keri/npm/src/app/multisig/grouping.js +4 -3
  60. package/esm/keri/npm/src/app/multisig/multisig-workflows.js +101 -141
  61. package/esm/keri/npm/src/app/multisig/proposals.js +281 -0
  62. package/esm/keri/npm/src/app/multisig/proposing.js +122 -0
  63. package/esm/keri/npm/src/app/notifications/notifying.js +5 -9
  64. package/esm/keri/npm/src/app/notifications/signaling.js +5 -5
  65. package/esm/keri/npm/src/app/protocol/parsering.js +26 -1
  66. package/esm/keri/npm/src/app/protocol/protocol-processing.js +44 -6
  67. package/esm/keri/npm/src/app/queries/query-workflows.js +98 -0
  68. package/esm/keri/npm/src/app/queries/witness-inquisitor.js +2 -2
  69. package/esm/keri/npm/src/app/runtime/agent-runtime.js +113 -65
  70. package/esm/keri/npm/src/app/runtime/cue-runtime.js +3 -6
  71. package/esm/keri/npm/src/app/runtime/delivery-outbox.js +87 -0
  72. package/esm/keri/npm/src/app/runtime/doing.js +17 -0
  73. package/esm/keri/npm/src/app/runtime/ipex-auxiliaries.js +207 -0
  74. package/esm/keri/npm/src/app/runtime/operation-owners.js +151 -0
  75. package/esm/keri/npm/src/app/runtime/retry-backoff.js +93 -0
  76. package/esm/keri/npm/src/app/runtime/workflow-contract.js +80 -0
  77. package/esm/keri/npm/src/app/transport/byte-source.js +6 -42
  78. package/esm/keri/npm/src/app/transport/cesr-egress.js +77 -13
  79. package/esm/keri/npm/src/app/transport/file-bytes.js +41 -0
  80. package/esm/keri/npm/src/app/transport/http-client.js +25 -6
  81. package/esm/keri/npm/src/app/transport/http-messenger.js +14 -9
  82. package/esm/keri/npm/src/app/transport/message-source.js +1 -1
  83. package/esm/keri/npm/src/app/transport/messengering.js +3 -4
  84. package/esm/keri/npm/src/app/transport/node-http-client.js +21 -0
  85. package/esm/keri/npm/src/app/transport/tcp-dialer.js +14 -0
  86. package/esm/keri/npm/src/app/witness/http-endpoints.js +4 -4
  87. package/esm/keri/npm/src/app/witness/receipt-client.js +2 -2
  88. package/esm/keri/npm/src/cli/common/context.js +2 -2
  89. package/esm/keri/npm/src/cli/common/event-completion.js +49 -0
  90. package/esm/keri/npm/src/cli/common/existing.js +3 -5
  91. package/esm/keri/npm/src/cli/common/runtime-workers.js +23 -0
  92. package/esm/keri/npm/src/cli/credentials/ipex.js +159 -191
  93. package/esm/keri/npm/src/cli/credentials/vc.js +53 -72
  94. package/esm/keri/npm/src/cli/endpoints/did.js +12 -3
  95. package/esm/keri/npm/src/cli/endpoints/oobi-clean.js +4 -3
  96. package/esm/keri/npm/src/cli/endpoints/oobi.js +12 -15
  97. package/esm/keri/npm/src/cli/identity/challenge.js +9 -35
  98. package/esm/keri/npm/src/cli/identity/delegate.js +81 -258
  99. package/esm/keri/npm/src/cli/identity/incept.js +17 -34
  100. package/esm/keri/npm/src/cli/identity/init.js +4 -3
  101. package/esm/keri/npm/src/cli/identity/interact.js +7 -19
  102. package/esm/keri/npm/src/cli/identity/rotate.js +10 -38
  103. package/esm/keri/npm/src/cli/index.js +3 -1
  104. package/esm/keri/npm/src/cli/messaging/exchange.js +2 -2
  105. package/esm/keri/npm/src/cli/messaging/group-join.js +79 -0
  106. package/esm/keri/npm/src/cli/messaging/group-wait.js +88 -0
  107. package/esm/keri/npm/src/cli/messaging/multisig.js +187 -250
  108. package/esm/keri/npm/src/cli/messaging/root-copy-lines.js +31 -0
  109. package/esm/keri/npm/src/cli/tools/annotate.js +2 -1
  110. package/esm/keri/npm/src/cli/tools/benchmark.js +2 -1
  111. package/esm/keri/npm/src/cli/tools/db-dump.js +1 -4
  112. package/esm/keri/npm/src/core/bytes.js +9 -0
  113. package/esm/keri/npm/src/core/kel/delegation-ancestry.js +92 -0
  114. package/esm/keri/npm/src/core/kel/eventing.js +67 -12
  115. package/esm/keri/npm/src/core/kel/kever.js +11 -9
  116. package/esm/keri/npm/src/core/mailbox/kram-policy.js +41 -9
  117. package/esm/keri/npm/src/core/mailbox/kram-pruning.js +15 -22
  118. package/esm/keri/npm/src/core/mailbox/kram-staging.js +2 -2
  119. package/esm/keri/npm/src/core/mailbox/kraming.js +2 -0
  120. package/esm/keri/npm/src/core/records.js +23 -0
  121. package/esm/keri/npm/src/core/routing.js +15 -2
  122. package/esm/keri/npm/src/db/basing.js +183 -205
  123. package/esm/keri/npm/src/db/core/dber.js +1062 -0
  124. package/esm/keri/npm/src/db/core/index.js +4 -2
  125. package/esm/keri/npm/src/db/core/indexeddb-persistence.js +221 -0
  126. package/esm/keri/npm/src/db/core/lmdb-opener.js +30 -0
  127. package/esm/keri/npm/src/db/core/lmdber.js +199 -1067
  128. package/esm/keri/npm/src/db/core/memstore.js +532 -0
  129. package/esm/keri/npm/src/db/core/path-manager.js +109 -223
  130. package/esm/keri/npm/src/db/core/store-owner.js +104 -0
  131. package/esm/keri/npm/src/db/core/webdber.js +252 -0
  132. package/esm/keri/npm/src/db/escrowing.js +2 -2
  133. package/esm/keri/npm/src/db/exchange/exchange-nests.js +3 -2
  134. package/esm/keri/npm/src/db/indexeddb.js +98 -0
  135. package/esm/keri/npm/src/db/keeping.js +38 -123
  136. package/esm/keri/npm/src/db/koming.js +1 -1
  137. package/esm/keri/npm/src/db/lmdb-stores.js +68 -0
  138. package/esm/keri/npm/src/db/lmdb.js +6 -0
  139. package/esm/keri/npm/src/db/mailbox/mailboxing.js +12 -65
  140. package/esm/keri/npm/src/db/noting.js +11 -55
  141. package/esm/keri/npm/src/db/reger.js +43 -105
  142. package/esm/keri/npm/src/db/replay/witness-replay.js +2 -20
  143. package/esm/keri/npm/src/db/store-lock.js +150 -0
  144. package/esm/keri/npm/src/db/subing.js +1 -1
  145. package/esm/keri/npm/src/npm/db-indexeddb.browser.js +2 -0
  146. package/esm/keri/npm/src/npm/db-indexeddb.js +3 -0
  147. package/esm/keri/npm/src/npm/db-lmdb.js +3 -0
  148. package/esm/keri/npm/src/npm/db.browser.js +2 -0
  149. package/esm/keri/npm/src/npm/index.browser.js +9 -0
  150. package/esm/keri/npm/src/npm/runtime-node.js +3 -0
  151. package/esm/keri/npm/src/npm/runtime-web.browser.js +2 -0
  152. package/esm/keri/npm/src/npm/runtime-web.js +3 -0
  153. package/esm/keri/npm/src/npm/runtime.browser.js +2 -0
  154. package/esm/keri/npm/src/runtime/index.js +58 -12
  155. package/esm/keri/npm/src/runtime/node.js +14 -0
  156. package/esm/keri/npm/src/runtime/web/output-barrier.js +47 -0
  157. package/esm/keri/npm/src/runtime/web/persistent-storage.js +37 -0
  158. package/esm/keri/npm/src/runtime/web.js +10 -0
  159. package/esm/keri/npm/src/vdr/eventing.js +1 -1
  160. package/esm/keri/npm/src/vdr/tel-publication.js +19 -3
  161. package/esm/keri/npm/src/version.js +2 -2
  162. package/package.json +24 -4
  163. package/types/acdc/authoring.d.ts +54 -0
  164. package/types/acdc/authoring.d.ts.map +1 -0
  165. package/types/acdc/chaining.d.ts +56 -6
  166. package/types/acdc/chaining.d.ts.map +1 -1
  167. package/types/acdc/custody.d.ts +77 -0
  168. package/types/acdc/custody.d.ts.map +1 -0
  169. package/types/acdc/dhking.d.ts +94 -3
  170. package/types/acdc/dhking.d.ts.map +1 -1
  171. package/types/acdc/regbasing.d.ts +11 -6
  172. package/types/acdc/regbasing.d.ts.map +1 -1
  173. package/types/acdc/regengine.d.ts.map +1 -1
  174. package/types/acdc/registering.d.ts +8 -4
  175. package/types/acdc/registering.d.ts.map +1 -1
  176. package/types/acdc/registraring.d.ts.map +1 -1
  177. package/types/acdc/salting.d.ts +59 -7
  178. package/types/acdc/salting.d.ts.map +1 -1
  179. package/types/acdc/scheming.d.ts +2 -0
  180. package/types/acdc/scheming.d.ts.map +1 -1
  181. package/types/acdc/unblinding.d.ts +58 -19
  182. package/types/acdc/unblinding.d.ts.map +1 -1
  183. package/types/app/bootstrap/authenticating.d.ts +3 -1
  184. package/types/app/bootstrap/authenticating.d.ts.map +1 -1
  185. package/types/app/bootstrap/oobi-resolving.d.ts +92 -0
  186. package/types/app/bootstrap/oobi-resolving.d.ts.map +1 -0
  187. package/types/app/bootstrap/oobiery.d.ts +3 -1
  188. package/types/app/bootstrap/oobiery.d.ts.map +1 -1
  189. package/types/app/credentials/credential-revoking.d.ts +3 -0
  190. package/types/app/credentials/credential-revoking.d.ts.map +1 -1
  191. package/types/app/credentials/credential-workflows.d.ts +5 -0
  192. package/types/app/credentials/credential-workflows.d.ts.map +1 -1
  193. package/types/app/credentials/registry-settling.d.ts +85 -0
  194. package/types/app/credentials/registry-settling.d.ts.map +1 -0
  195. package/types/app/credentials/root-replicating.d.ts +97 -0
  196. package/types/app/credentials/root-replicating.d.ts.map +1 -0
  197. package/types/app/credentials/root-replicator.d.ts +105 -0
  198. package/types/app/credentials/root-replicator.d.ts.map +1 -0
  199. package/types/app/credentials/tel-completion.d.ts +55 -0
  200. package/types/app/credentials/tel-completion.d.ts.map +1 -0
  201. package/types/app/credentials/verifying.d.ts +2 -1
  202. package/types/app/credentials/verifying.d.ts.map +1 -1
  203. package/types/app/delivery/forwarding.d.ts +16 -0
  204. package/types/app/delivery/forwarding.d.ts.map +1 -1
  205. package/types/app/exchanges/exchanging.d.ts +2 -0
  206. package/types/app/exchanges/exchanging.d.ts.map +1 -1
  207. package/types/app/identity/challenging.d.ts +54 -0
  208. package/types/app/identity/challenging.d.ts.map +1 -1
  209. package/types/app/identity/configing.d.ts +7 -5
  210. package/types/app/identity/configing.d.ts.map +1 -1
  211. package/types/app/identity/delegating.d.ts +21 -4
  212. package/types/app/identity/delegating.d.ts.map +1 -1
  213. package/types/app/identity/delegation-approval.d.ts +228 -0
  214. package/types/app/identity/delegation-approval.d.ts.map +1 -0
  215. package/types/app/identity/event-completion.d.ts +151 -0
  216. package/types/app/identity/event-completion.d.ts.map +1 -0
  217. package/types/app/identity/habbing.d.ts +90 -7
  218. package/types/app/identity/habbing.d.ts.map +1 -1
  219. package/types/app/identity/keeping.d.ts +50 -4
  220. package/types/app/identity/keeping.d.ts.map +1 -1
  221. package/types/app/identity/lmdb-habery.d.ts +6 -0
  222. package/types/app/identity/lmdb-habery.d.ts.map +1 -0
  223. package/types/app/ipex/group-ipex.d.ts +247 -0
  224. package/types/app/ipex/group-ipex.d.ts.map +1 -0
  225. package/types/app/ipex/group-issuance.d.ts +281 -0
  226. package/types/app/ipex/group-issuance.d.ts.map +1 -0
  227. package/types/app/ipex/ipex-admitting.d.ts +47 -0
  228. package/types/app/ipex/ipex-admitting.d.ts.map +1 -0
  229. package/types/app/ipex/ipex-conversation.d.ts +195 -0
  230. package/types/app/ipex/ipex-conversation.d.ts.map +1 -0
  231. package/types/app/ipex/ipex-discloser.d.ts +156 -0
  232. package/types/app/ipex/ipex-discloser.d.ts.map +1 -0
  233. package/types/app/ipex/ipex-granting.d.ts +145 -0
  234. package/types/app/ipex/ipex-granting.d.ts.map +1 -0
  235. package/types/app/ipex/ipex-graph.d.ts +4 -4
  236. package/types/app/ipex/ipex-graph.d.ts.map +1 -1
  237. package/types/app/ipex/ipex-grouping.d.ts +18 -0
  238. package/types/app/ipex/ipex-grouping.d.ts.map +1 -1
  239. package/types/app/ipex/ipex-v2.d.ts +11 -2
  240. package/types/app/ipex/ipex-v2.d.ts.map +1 -1
  241. package/types/app/ipex/ipexing.d.ts +3 -0
  242. package/types/app/ipex/ipexing.d.ts.map +1 -1
  243. package/types/app/ipex/issuance.d.ts +443 -0
  244. package/types/app/ipex/issuance.d.ts.map +1 -0
  245. package/types/app/ipex/pending-presentations.d.ts +25 -0
  246. package/types/app/ipex/pending-presentations.d.ts.map +1 -0
  247. package/types/app/ipex/presentation-files.d.ts +47 -0
  248. package/types/app/ipex/presentation-files.d.ts.map +1 -0
  249. package/types/app/ipex/presenting.d.ts +298 -0
  250. package/types/app/ipex/presenting.d.ts.map +1 -0
  251. package/types/app/ipex/receive-issuance.d.ts +99 -0
  252. package/types/app/ipex/receive-issuance.d.ts.map +1 -0
  253. package/types/app/ipex/unblinding-workflow.d.ts +255 -0
  254. package/types/app/ipex/unblinding-workflow.d.ts.map +1 -0
  255. package/types/app/mailbox/ipex-arrival.d.ts +104 -0
  256. package/types/app/mailbox/ipex-arrival.d.ts.map +1 -0
  257. package/types/app/mailbox/kel-publisher.d.ts +141 -0
  258. package/types/app/mailbox/kel-publisher.d.ts.map +1 -0
  259. package/types/app/mailbox/kel-publishing.d.ts +70 -0
  260. package/types/app/mailbox/kel-publishing.d.ts.map +1 -0
  261. package/types/app/mailbox/kel-submission.d.ts +18 -0
  262. package/types/app/mailbox/kel-submission.d.ts.map +1 -0
  263. package/types/app/mailbox/mailbox-admin.d.ts +113 -0
  264. package/types/app/mailbox/mailbox-admin.d.ts.map +1 -0
  265. package/types/app/mailbox/mailbox-poller.d.ts +92 -3
  266. package/types/app/mailbox/mailbox-poller.d.ts.map +1 -1
  267. package/types/app/mailbox/mailboxing.d.ts +4 -1
  268. package/types/app/mailbox/mailboxing.d.ts.map +1 -1
  269. package/types/app/multisig/counseling.d.ts +196 -0
  270. package/types/app/multisig/counseling.d.ts.map +1 -0
  271. package/types/app/multisig/group-members.d.ts +20 -0
  272. package/types/app/multisig/group-members.d.ts.map +1 -1
  273. package/types/app/multisig/grouping.d.ts +39 -20
  274. package/types/app/multisig/grouping.d.ts.map +1 -1
  275. package/types/app/multisig/multisig-workflows.d.ts +93 -23
  276. package/types/app/multisig/multisig-workflows.d.ts.map +1 -1
  277. package/types/app/multisig/proposals.d.ts +129 -0
  278. package/types/app/multisig/proposals.d.ts.map +1 -0
  279. package/types/app/multisig/proposing.d.ts +125 -0
  280. package/types/app/multisig/proposing.d.ts.map +1 -0
  281. package/types/app/notifications/notifying.d.ts +1 -1
  282. package/types/app/notifications/notifying.d.ts.map +1 -1
  283. package/types/app/notifications/signaling.d.ts +3 -1
  284. package/types/app/notifications/signaling.d.ts.map +1 -1
  285. package/types/app/protocol/parsering.d.ts +16 -1
  286. package/types/app/protocol/parsering.d.ts.map +1 -1
  287. package/types/app/protocol/protocol-processing.d.ts +9 -1
  288. package/types/app/protocol/protocol-processing.d.ts.map +1 -1
  289. package/types/app/queries/query-workflows.d.ts +98 -0
  290. package/types/app/queries/query-workflows.d.ts.map +1 -0
  291. package/types/app/runtime/agent-runtime.d.ts +79 -25
  292. package/types/app/runtime/agent-runtime.d.ts.map +1 -1
  293. package/types/app/runtime/cue-runtime.d.ts +2 -1
  294. package/types/app/runtime/cue-runtime.d.ts.map +1 -1
  295. package/types/app/runtime/delivery-outbox.d.ts +68 -0
  296. package/types/app/runtime/delivery-outbox.d.ts.map +1 -0
  297. package/types/app/runtime/doing.d.ts +27 -0
  298. package/types/app/runtime/doing.d.ts.map +1 -0
  299. package/types/app/runtime/ipex-auxiliaries.d.ts +74 -0
  300. package/types/app/runtime/ipex-auxiliaries.d.ts.map +1 -0
  301. package/types/app/runtime/operation-owners.d.ts +137 -0
  302. package/types/app/runtime/operation-owners.d.ts.map +1 -0
  303. package/types/app/runtime/retry-backoff.d.ts +49 -0
  304. package/types/app/runtime/retry-backoff.d.ts.map +1 -0
  305. package/types/app/runtime/workflow-contract.d.ts +79 -0
  306. package/types/app/runtime/workflow-contract.d.ts.map +1 -0
  307. package/types/app/transport/byte-source.d.ts +13 -10
  308. package/types/app/transport/byte-source.d.ts.map +1 -1
  309. package/types/app/transport/cesr-egress.d.ts +21 -7
  310. package/types/app/transport/cesr-egress.d.ts.map +1 -1
  311. package/types/app/transport/file-bytes.d.ts +11 -0
  312. package/types/app/transport/file-bytes.d.ts.map +1 -0
  313. package/types/app/transport/http-client.d.ts +3 -0
  314. package/types/app/transport/http-client.d.ts.map +1 -1
  315. package/types/app/transport/http-messenger.d.ts +15 -10
  316. package/types/app/transport/http-messenger.d.ts.map +1 -1
  317. package/types/app/transport/message-source.d.ts +1 -1
  318. package/types/app/transport/messengering.d.ts +2 -2
  319. package/types/app/transport/messengering.d.ts.map +1 -1
  320. package/types/app/transport/node-http-client.d.ts +10 -0
  321. package/types/app/transport/node-http-client.d.ts.map +1 -0
  322. package/types/app/transport/tcp-dialer.d.ts +21 -0
  323. package/types/app/transport/tcp-dialer.d.ts.map +1 -0
  324. package/types/cli/common/event-completion.d.ts +26 -0
  325. package/types/cli/common/event-completion.d.ts.map +1 -0
  326. package/types/cli/common/existing.d.ts.map +1 -1
  327. package/types/cli/common/runtime-workers.d.ts +23 -0
  328. package/types/cli/common/runtime-workers.d.ts.map +1 -0
  329. package/types/cli/credentials/ipex.d.ts.map +1 -1
  330. package/types/cli/credentials/vc.d.ts +1 -1
  331. package/types/cli/credentials/vc.d.ts.map +1 -1
  332. package/types/cli/endpoints/did.d.ts.map +1 -1
  333. package/types/cli/endpoints/oobi-clean.d.ts.map +1 -1
  334. package/types/cli/endpoints/oobi.d.ts +3 -1
  335. package/types/cli/endpoints/oobi.d.ts.map +1 -1
  336. package/types/cli/identity/challenge.d.ts +1 -1
  337. package/types/cli/identity/challenge.d.ts.map +1 -1
  338. package/types/cli/identity/delegate.d.ts +14 -1
  339. package/types/cli/identity/delegate.d.ts.map +1 -1
  340. package/types/cli/identity/incept.d.ts.map +1 -1
  341. package/types/cli/identity/init.d.ts.map +1 -1
  342. package/types/cli/identity/interact.d.ts.map +1 -1
  343. package/types/cli/identity/rotate.d.ts.map +1 -1
  344. package/types/cli/index.d.ts +4 -2
  345. package/types/cli/index.d.ts.map +1 -1
  346. package/types/cli/messaging/group-join.d.ts +53 -0
  347. package/types/cli/messaging/group-join.d.ts.map +1 -0
  348. package/types/cli/messaging/group-wait.d.ts +34 -0
  349. package/types/cli/messaging/group-wait.d.ts.map +1 -0
  350. package/types/cli/messaging/multisig.d.ts +36 -4
  351. package/types/cli/messaging/multisig.d.ts.map +1 -1
  352. package/types/cli/messaging/root-copy-lines.d.ts +39 -0
  353. package/types/cli/messaging/root-copy-lines.d.ts.map +1 -0
  354. package/types/cli/tools/annotate.d.ts.map +1 -1
  355. package/types/cli/tools/benchmark.d.ts.map +1 -1
  356. package/types/cli/tools/db-dump.d.ts.map +1 -1
  357. package/types/core/bytes.d.ts +2 -0
  358. package/types/core/bytes.d.ts.map +1 -1
  359. package/types/core/cues.d.ts +11 -0
  360. package/types/core/cues.d.ts.map +1 -1
  361. package/types/core/kel/delegation-ancestry.d.ts +41 -0
  362. package/types/core/kel/delegation-ancestry.d.ts.map +1 -0
  363. package/types/core/kel/eventing.d.ts.map +1 -1
  364. package/types/core/kel/kever.d.ts +5 -4
  365. package/types/core/kel/kever.d.ts.map +1 -1
  366. package/types/core/mailbox/kram-policy.d.ts +14 -0
  367. package/types/core/mailbox/kram-policy.d.ts.map +1 -1
  368. package/types/core/mailbox/kram-pruning.d.ts +1 -3
  369. package/types/core/mailbox/kram-pruning.d.ts.map +1 -1
  370. package/types/core/mailbox/kraming.d.ts +1 -1
  371. package/types/core/mailbox/kraming.d.ts.map +1 -1
  372. package/types/core/records.d.ts +61 -0
  373. package/types/core/records.d.ts.map +1 -1
  374. package/types/core/routing.d.ts +6 -0
  375. package/types/core/routing.d.ts.map +1 -1
  376. package/types/db/basing.d.ts +22 -25
  377. package/types/db/basing.d.ts.map +1 -1
  378. package/types/db/core/dber.d.ts +505 -0
  379. package/types/db/core/dber.d.ts.map +1 -0
  380. package/types/db/core/index.d.ts +4 -2
  381. package/types/db/core/index.d.ts.map +1 -1
  382. package/types/db/core/indexeddb-persistence.d.ts +59 -0
  383. package/types/db/core/indexeddb-persistence.d.ts.map +1 -0
  384. package/types/db/core/lmdb-opener.d.ts +17 -0
  385. package/types/db/core/lmdb-opener.d.ts.map +1 -0
  386. package/types/db/core/lmdber.d.ts +60 -383
  387. package/types/db/core/lmdber.d.ts.map +1 -1
  388. package/types/db/core/memstore.d.ts +129 -0
  389. package/types/db/core/memstore.d.ts.map +1 -0
  390. package/types/db/core/path-manager.d.ts +22 -45
  391. package/types/db/core/path-manager.d.ts.map +1 -1
  392. package/types/db/core/store-owner.d.ts +59 -0
  393. package/types/db/core/store-owner.d.ts.map +1 -0
  394. package/types/db/core/webdber.d.ts +127 -0
  395. package/types/db/core/webdber.d.ts.map +1 -0
  396. package/types/db/escrowing.d.ts +3 -3
  397. package/types/db/escrowing.d.ts.map +1 -1
  398. package/types/db/exchange/exchange-nests.d.ts.map +1 -1
  399. package/types/db/indexeddb.d.ts +37 -0
  400. package/types/db/indexeddb.d.ts.map +1 -0
  401. package/types/db/keeping.d.ts +14 -25
  402. package/types/db/keeping.d.ts.map +1 -1
  403. package/types/db/koming.d.ts +7 -8
  404. package/types/db/koming.d.ts.map +1 -1
  405. package/types/db/lmdb-stores.d.ts +45 -0
  406. package/types/db/lmdb-stores.d.ts.map +1 -0
  407. package/types/db/lmdb.d.ts +7 -0
  408. package/types/db/lmdb.d.ts.map +1 -0
  409. package/types/db/mailbox/mailboxing.d.ts +7 -21
  410. package/types/db/mailbox/mailboxing.d.ts.map +1 -1
  411. package/types/db/noting.d.ts +7 -12
  412. package/types/db/noting.d.ts.map +1 -1
  413. package/types/db/reger.d.ts +7 -11
  414. package/types/db/reger.d.ts.map +1 -1
  415. package/types/db/replay/witness-replay.d.ts +0 -2
  416. package/types/db/replay/witness-replay.d.ts.map +1 -1
  417. package/types/db/store-lock.d.ts +72 -0
  418. package/types/db/store-lock.d.ts.map +1 -0
  419. package/types/db/subing.d.ts +24 -25
  420. package/types/db/subing.d.ts.map +1 -1
  421. package/types/npm/db-indexeddb.d.ts +4 -0
  422. package/types/npm/db-indexeddb.d.ts.map +1 -0
  423. package/types/npm/db-lmdb.d.ts +4 -0
  424. package/types/npm/db-lmdb.d.ts.map +1 -0
  425. package/types/npm/runtime-node.d.ts +4 -0
  426. package/types/npm/runtime-node.d.ts.map +1 -0
  427. package/types/npm/runtime-web.d.ts +4 -0
  428. package/types/npm/runtime-web.d.ts.map +1 -0
  429. package/types/runtime/index.d.ts +48 -14
  430. package/types/runtime/index.d.ts.map +1 -1
  431. package/types/runtime/node.d.ts +15 -0
  432. package/types/runtime/node.d.ts.map +1 -0
  433. package/types/runtime/web/output-barrier.d.ts +30 -0
  434. package/types/runtime/web/output-barrier.d.ts.map +1 -0
  435. package/types/runtime/web/persistent-storage.d.ts +36 -0
  436. package/types/runtime/web/persistent-storage.d.ts.map +1 -0
  437. package/types/runtime/web.d.ts +11 -0
  438. package/types/runtime/web.d.ts.map +1 -0
  439. package/types/vdr/tel-publication.d.ts +6 -0
  440. package/types/vdr/tel-publication.d.ts.map +1 -1
  441. package/types/version.d.ts +2 -2
  442. package/esm/keri/npm/src/acdc/relating.js +0 -59
  443. package/esm/keri/npm/src/cli/common/tel-completion.js +0 -24
  444. package/esm/keri/npm/src/db/baser-defaults.js +0 -11
  445. package/types/acdc/relating.d.ts +0 -21
  446. package/types/acdc/relating.d.ts.map +0 -1
  447. package/types/cli/common/tel-completion.d.ts +0 -8
  448. package/types/cli/common/tel-completion.d.ts.map +0 -1
  449. package/types/db/baser-defaults.d.ts +0 -5
  450. package/types/db/baser-defaults.d.ts.map +0 -1
@@ -0,0 +1,532 @@
1
+ /**
2
+ * In-memory `DBer` backend: one bytewise-sorted row array per table.
3
+ *
4
+ * ADR-0015 owns the semantics and `LMDBer` is the reference where the ADR is
5
+ * silent. Nothing here may reach `lmdb`, `node:` or the `Deno` global.
6
+ *
7
+ * Invariants:
8
+ * - each table's `rows` stay sorted by key, then by value on a dupsort table;
9
+ * - stored rows are immutable and every byte array entering or leaving is a
10
+ * fresh copy, so callers can neither reach nor alias store state;
11
+ * - every mutation runs inside `transaction` and logs its exact inverse.
12
+ */
13
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
14
+ if (kind === "m") throw new TypeError("Private method is not writable");
15
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
16
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
17
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
18
+ };
19
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
20
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
21
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
22
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
23
+ };
24
+ var _MemStore_instances, _MemStore_name, _MemStore_base, _MemStore_temp, _MemStore_opened, _MemStore_created, _MemStore_tables, _MemStore_version, _MemStore_writeVersion, _MemStore_undo, _MemStore_depth, _MemStore_discard, _MemStore_walk, _MemStore_resolve, _MemStore_logRow, _MemStore_insert, _MemStore_removeAt, _MemStore_removeRange;
25
+ import { b, bytesHex, t } from "cesr-ts";
26
+ import { compareBytes, startsWith } from "../../core/bytes.js";
27
+ import { DatabaseKeyError, DatabaseNotOpenError, DatabaseOperationError } from "../../core/errors.js";
28
+ import { BaseDBer, MAX_KEY_BYTES } from "./dber.js";
29
+ const DEFAULT_DB_VERSION = "1.0.0";
30
+ const EMPTY = new Uint8Array(0);
31
+ /** Copy into a plain `Uint8Array`; `slice` on a Node `Buffer` would alias its source. */
32
+ function copyBytes(bytes) {
33
+ return new Uint8Array(bytes);
34
+ }
35
+ function assertWritableKey(key) {
36
+ if (key.length === 0 || key.length > MAX_KEY_BYTES) {
37
+ throw new DatabaseKeyError(`Key is empty, too big, or wrong size: ${key.length} bytes`);
38
+ }
39
+ }
40
+ function assertDupValueSize(val) {
41
+ if (val.length === 0 || val.length > MAX_KEY_BYTES) {
42
+ throw new DatabaseKeyError(`Duplicate value is empty or larger than ${MAX_KEY_BYTES} bytes: ${val.length} bytes`);
43
+ }
44
+ }
45
+ /** Point reads and deletes reject an empty key; an over-long key can only be absent. */
46
+ function isStorableKey(key) {
47
+ if (key.length === 0)
48
+ throw new DatabaseKeyError("Key is empty, too big, or wrong size: 0 bytes");
49
+ return key.length <= MAX_KEY_BYTES;
50
+ }
51
+ function isThenable(value) {
52
+ return (typeof value === "object" || typeof value === "function") && value !== null
53
+ && typeof value.then === "function";
54
+ }
55
+ /** One named table. A plain table ignores values when ordering and identifying rows. */
56
+ class MemTable {
57
+ constructor(name, dupsort, rows = []) {
58
+ Object.defineProperty(this, "name", {
59
+ enumerable: true,
60
+ configurable: true,
61
+ writable: true,
62
+ value: name
63
+ });
64
+ Object.defineProperty(this, "dupsort", {
65
+ enumerable: true,
66
+ configurable: true,
67
+ writable: true,
68
+ value: dupsort
69
+ });
70
+ Object.defineProperty(this, "rows", {
71
+ enumerable: true,
72
+ configurable: true,
73
+ writable: true,
74
+ value: rows
75
+ });
76
+ }
77
+ /** Binary search for the first row satisfying a predicate monotone in sort order. */
78
+ seek(isPast) {
79
+ let low = 0;
80
+ let high = this.rows.length;
81
+ while (low < high) {
82
+ const mid = (low + high) >>> 1;
83
+ if (isPast(this.rows[mid])) {
84
+ high = mid;
85
+ }
86
+ else {
87
+ low = mid + 1;
88
+ }
89
+ }
90
+ return low;
91
+ }
92
+ compare(row, key, value) {
93
+ const order = compareBytes(row.key, key);
94
+ return order !== 0 || !this.dupsort || value === undefined ? order : compareBytes(row.value, value);
95
+ }
96
+ /** First row not below `(key, value)`; without a value, the key's first duplicate. */
97
+ lowerBound(key, value) {
98
+ return this.seek((row) => this.compare(row, key, value) >= 0);
99
+ }
100
+ /** First row above `(key, value)`; without a value, the row past every duplicate of the key. */
101
+ upperBound(key, value) {
102
+ return this.seek((row) => this.compare(row, key, value) > 0);
103
+ }
104
+ /** True when `index` holds exactly `(key, value)`, or `key` when no value is given. */
105
+ matches(index, key, value) {
106
+ return index < this.rows.length && this.compare(this.rows[index], key, value) === 0;
107
+ }
108
+ /** The `[low, high)` row range whose keys begin with `top`. */
109
+ branch(top) {
110
+ return [
111
+ this.lowerBound(top),
112
+ this.seek((row) => compareBytes(row.key, top) > 0 && !startsWith(row.key, top)),
113
+ ];
114
+ }
115
+ }
116
+ /**
117
+ * Sorted in-memory store with real commit and rollback.
118
+ *
119
+ * Contents belong to the instance. They survive `close` and `reopen` until
120
+ * `close(true)` or `reopen({ clear: true })`, including on a `temp` store,
121
+ * which is what `LMDBer` does with its reused temp path. Each reopen rebinds
122
+ * table handles, so a handle from before it is refused.
123
+ *
124
+ * Scans hold a position, not an index: each step re-seeks past the last row
125
+ * yielded, so a concurrent insert, delete or rollback cannot skip or repeat an
126
+ * untouched row. A scan inside a writer sees that writer's rows as they change.
127
+ */
128
+ export class MemStore extends BaseDBer {
129
+ constructor(options = {}) {
130
+ super();
131
+ _MemStore_instances.add(this);
132
+ _MemStore_name.set(this, void 0);
133
+ _MemStore_base.set(this, void 0);
134
+ _MemStore_temp.set(this, void 0);
135
+ _MemStore_opened.set(this, false);
136
+ /** True once a writable open has created the contents, like LMDB's data file. */
137
+ _MemStore_created.set(this, false);
138
+ _MemStore_tables.set(this, new Map());
139
+ _MemStore_version.set(this, null);
140
+ _MemStore_writeVersion.set(this, 0);
141
+ /** One log for every transaction depth; a savepoint is just an index into it. */
142
+ _MemStore_undo.set(this, []);
143
+ _MemStore_depth.set(this, 0);
144
+ Object.defineProperty(this, "readonly", {
145
+ enumerable: true,
146
+ configurable: true,
147
+ writable: true,
148
+ value: void 0
149
+ });
150
+ __classPrivateFieldSet(this, _MemStore_name, options.name || "main", "f");
151
+ __classPrivateFieldSet(this, _MemStore_base, options.base || "", "f");
152
+ __classPrivateFieldSet(this, _MemStore_temp, options.temp ?? false, "f");
153
+ this.readonly = options.readonly ?? false;
154
+ }
155
+ get name() {
156
+ return __classPrivateFieldGet(this, _MemStore_name, "f");
157
+ }
158
+ get base() {
159
+ return __classPrivateFieldGet(this, _MemStore_base, "f");
160
+ }
161
+ get opened() {
162
+ return __classPrivateFieldGet(this, _MemStore_opened, "f");
163
+ }
164
+ get temp() {
165
+ return __classPrivateFieldGet(this, _MemStore_temp, "f");
166
+ }
167
+ get inWriteTransaction() {
168
+ this.assertOpen();
169
+ return __classPrivateFieldGet(this, _MemStore_depth, "f") > 0;
170
+ }
171
+ /** Counts commits that wrote rows; it keeps counting across reopen of one instance. */
172
+ get writeVersion() {
173
+ this.assertOpen();
174
+ return __classPrivateFieldGet(this, _MemStore_writeVersion, "f");
175
+ }
176
+ /** Open or reopen the contents. A readonly open of never-created contents reports `false`. */
177
+ *reopen(options = {}) {
178
+ this.readonly = options.readonly ?? this.readonly;
179
+ __classPrivateFieldSet(this, _MemStore_temp, options.temp ?? __classPrivateFieldGet(this, _MemStore_temp, "f"), "f");
180
+ if (options.clear) {
181
+ __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_discard).call(this);
182
+ }
183
+ __classPrivateFieldSet(this, _MemStore_opened, false, "f");
184
+ if (this.readonly && !__classPrivateFieldGet(this, _MemStore_created, "f"))
185
+ return false;
186
+ const existed = __classPrivateFieldGet(this, _MemStore_created, "f");
187
+ __classPrivateFieldSet(this, _MemStore_tables, new Map([...__classPrivateFieldGet(this, _MemStore_tables, "f")].map(([name, table]) => [name, new MemTable(name, table.dupsort, table.rows)])), "f");
188
+ __classPrivateFieldSet(this, _MemStore_created, true, "f");
189
+ __classPrivateFieldSet(this, _MemStore_opened, true, "f");
190
+ if (!this.readonly && (!existed || __classPrivateFieldGet(this, _MemStore_temp, "f"))) {
191
+ this.setVer(DEFAULT_DB_VERSION);
192
+ }
193
+ return true;
194
+ }
195
+ /** Close the store, deleting its contents when `clear` is set. Repeating is harmless. */
196
+ *close(clear = false) {
197
+ if (clear) {
198
+ __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_discard).call(this);
199
+ }
200
+ __classPrivateFieldSet(this, _MemStore_opened, false, "f");
201
+ return true;
202
+ }
203
+ /**
204
+ * Bind a table, creating it on a writable store. The flag from creation wins
205
+ * over a later differing request. An absent table on a readonly store yields
206
+ * no handle, as `LMDBer` does, so optional bindings can probe `hasTable`.
207
+ */
208
+ openTable(name, options = {}) {
209
+ this.assertOpen();
210
+ if (!name)
211
+ throw new DatabaseKeyError("Table name must not be empty");
212
+ const existing = __classPrivateFieldGet(this, _MemStore_tables, "f").get(name);
213
+ if (existing)
214
+ return existing;
215
+ if (this.readonly)
216
+ return undefined;
217
+ const table = new MemTable(name, options.dupsort ?? false);
218
+ __classPrivateFieldGet(this, _MemStore_tables, "f").set(name, table);
219
+ if (__classPrivateFieldGet(this, _MemStore_depth, "f") > 0) {
220
+ __classPrivateFieldGet(this, _MemStore_undo, "f").push({ revert: () => __classPrivateFieldGet(this, _MemStore_tables, "f").delete(name) });
221
+ }
222
+ return table;
223
+ }
224
+ hasTable(name) {
225
+ this.assertOpen();
226
+ if (!name)
227
+ throw new DatabaseKeyError("Table name must not be empty");
228
+ return __classPrivateFieldGet(this, _MemStore_tables, "f").has(name);
229
+ }
230
+ /**
231
+ * Run `fn` atomically. Only the outermost commit publishes; a nested
232
+ * transaction is a savepoint, and any throw restores the state at its start.
233
+ * A thenable result is a caller-contract error, rolled back like a throw.
234
+ */
235
+ transaction(fn) {
236
+ this.assertOpen();
237
+ if (this.readonly)
238
+ throw new DatabaseOperationError(`Store "${__classPrivateFieldGet(this, _MemStore_name, "f")}" is read-only`);
239
+ const savepoint = __classPrivateFieldGet(this, _MemStore_undo, "f").length;
240
+ __classPrivateFieldSet(this, _MemStore_depth, __classPrivateFieldGet(this, _MemStore_depth, "f") + 1, "f");
241
+ try {
242
+ const result = fn();
243
+ if (isThenable(result))
244
+ throw new DatabaseOperationError("Transaction callback must be synchronous");
245
+ if (__classPrivateFieldGet(this, _MemStore_depth, "f") === 1) {
246
+ const changes = __classPrivateFieldGet(this, _MemStore_undo, "f").flatMap((entry) => entry.change ? [entry.change] : []);
247
+ if (changes.length > 0) {
248
+ __classPrivateFieldSet(this, _MemStore_writeVersion, __classPrivateFieldGet(this, _MemStore_writeVersion, "f") + 1, "f");
249
+ this.committed(changes);
250
+ }
251
+ __classPrivateFieldGet(this, _MemStore_undo, "f").length = 0;
252
+ }
253
+ return result;
254
+ }
255
+ catch (error) {
256
+ while (__classPrivateFieldGet(this, _MemStore_undo, "f").length > savepoint) {
257
+ __classPrivateFieldGet(this, _MemStore_undo, "f").pop().revert();
258
+ }
259
+ throw error;
260
+ }
261
+ finally {
262
+ __classPrivateFieldSet(this, _MemStore_depth, __classPrivateFieldGet(this, _MemStore_depth, "f") - 1, "f");
263
+ }
264
+ }
265
+ /** Told each outermost commit that wrote rows, in order. Nothing rolled back ever reaches it. */
266
+ committed(_changes) { }
267
+ /**
268
+ * Replace the contents with a persisted snapshot, for a backend that loads
269
+ * before `reopen`. Rows are copied and sorted here, so a backend's own order
270
+ * cannot break the sorted-row invariant; a repeated row identity is corrupt.
271
+ */
272
+ loadContents(tables, version) {
273
+ __classPrivateFieldSet(this, _MemStore_tables, new Map(tables.map(({ name, dupsort, rows }) => {
274
+ const table = new MemTable(name, dupsort, rows.map((row) => ({ key: copyBytes(row.key), value: copyBytes(row.value) })));
275
+ const order = (a, c) => compareBytes(a.key, c.key) || (dupsort ? compareBytes(a.value, c.value) : 0);
276
+ table.rows.sort(order);
277
+ if (table.rows.some((row, index) => index > 0 && order(table.rows[index - 1], row) === 0)) {
278
+ throw new DatabaseOperationError(`Persisted table "${name}" repeats a row`);
279
+ }
280
+ return [name, table];
281
+ })), "f");
282
+ __classPrivateFieldSet(this, _MemStore_version, version, "f");
283
+ __classPrivateFieldSet(this, _MemStore_created, version !== null || tables.length > 0, "f");
284
+ }
285
+ *flushed() {
286
+ this.assertOpen();
287
+ }
288
+ /** This backend retains no read view, so an open store has nothing to discard. */
289
+ refreshRead() {
290
+ this.assertOpen();
291
+ }
292
+ getVer() {
293
+ this.assertOpen();
294
+ return __classPrivateFieldGet(this, _MemStore_version, "f") || null;
295
+ }
296
+ setVer(val) {
297
+ this.transaction(() => {
298
+ const prior = __classPrivateFieldGet(this, _MemStore_version, "f");
299
+ __classPrivateFieldSet(this, _MemStore_version, t(b(val)), "f");
300
+ __classPrivateFieldGet(this, _MemStore_undo, "f").push({
301
+ change: { kind: "version", before: prior, after: __classPrivateFieldGet(this, _MemStore_version, "f") },
302
+ revert: () => __classPrivateFieldSet(this, _MemStore_version, prior, "f"),
303
+ });
304
+ });
305
+ }
306
+ *scan(table, options = {}) {
307
+ for (const row of __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_walk).call(this, table, options, false)) {
308
+ yield { key: copyBytes(row.key), value: copyBytes(row.value) };
309
+ }
310
+ }
311
+ *scanKeys(table, options = {}) {
312
+ for (const row of __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_walk).call(this, table, options, true)) {
313
+ yield copyBytes(row.key);
314
+ }
315
+ }
316
+ assertOpen() {
317
+ if (!__classPrivateFieldGet(this, _MemStore_opened, "f"))
318
+ throw new DatabaseNotOpenError(`Store "${__classPrivateFieldGet(this, _MemStore_name, "f")}" is not open`);
319
+ }
320
+ putRow(table, key, val) {
321
+ const mem = __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_resolve).call(this, table);
322
+ this.transaction(() => __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_insert).call(this, mem, key, val));
323
+ }
324
+ /** On a dupsort table `val` selects one duplicate; a plain table ignores it, as LMDB does. */
325
+ removeRow(table, key, val) {
326
+ const mem = __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_resolve).call(this, table);
327
+ return this.transaction(() => {
328
+ if (!isStorableKey(key))
329
+ return false;
330
+ if (val === undefined || !mem.dupsort)
331
+ return __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_removeRange).call(this, mem, mem.lowerBound(key), mem.upperBound(key));
332
+ if (val.length === 0)
333
+ return false; // an empty duplicate can never be stored
334
+ assertDupValueSize(val);
335
+ const index = mem.lowerBound(key, val);
336
+ if (!mem.matches(index, key, val))
337
+ return false;
338
+ __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_removeAt).call(this, mem, index);
339
+ return true;
340
+ });
341
+ }
342
+ /** Insert only when `key` is absent; on a dupsort table any existing duplicate counts. */
343
+ putVal(table, key, val) {
344
+ const mem = __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_resolve).call(this, table);
345
+ return this.transaction(() => {
346
+ assertWritableKey(key);
347
+ if (mem.matches(mem.lowerBound(key), key))
348
+ return false;
349
+ __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_insert).call(this, mem, key, val);
350
+ return true;
351
+ });
352
+ }
353
+ /** Overwrite a plain key's value; on a dupsort table this adds a duplicate. */
354
+ setVal(table, key, val) {
355
+ this.putRow(table, key, val);
356
+ return true;
357
+ }
358
+ getVal(table, key) {
359
+ const mem = __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_resolve).call(this, table);
360
+ if (!isStorableKey(key))
361
+ return null;
362
+ const index = mem.lowerBound(key);
363
+ return mem.matches(index, key) ? copyBytes(mem.rows[index].value) : null;
364
+ }
365
+ delVal(table, key, val) {
366
+ return this.removeRow(table, key, val);
367
+ }
368
+ cnt(table) {
369
+ return __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_resolve).call(this, table).rows.length;
370
+ }
371
+ cntAll(table) {
372
+ return this.cnt(table);
373
+ }
374
+ cntTop(table, top = EMPTY) {
375
+ const [low, high] = __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_resolve).call(this, table).branch(top);
376
+ return high - low;
377
+ }
378
+ delTop(table, top = EMPTY) {
379
+ const mem = __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_resolve).call(this, table);
380
+ const [low, high] = mem.branch(top);
381
+ return high > low && this.transaction(() => __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_removeRange).call(this, mem, low, high));
382
+ }
383
+ *getTopItemIter(table, top = EMPTY) {
384
+ for (const row of __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_walk).call(this, table, { start: top }, false)) {
385
+ if (!startsWith(row.key, top))
386
+ return;
387
+ yield [copyBytes(row.key), copyBytes(row.value)];
388
+ }
389
+ }
390
+ /** Add each value not already present; reports `false` if any supplied value existed. */
391
+ putVals(table, key, vals) {
392
+ const mem = __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_resolve).call(this, table);
393
+ const existing = new Set(this.getVals(table, key).map((val) => bytesHex(val)));
394
+ let result = true;
395
+ this.transaction(() => {
396
+ for (const val of vals) {
397
+ const hex = bytesHex(val);
398
+ if (existing.has(hex)) {
399
+ result = false;
400
+ continue;
401
+ }
402
+ __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_insert).call(this, mem, key, val);
403
+ existing.add(hex);
404
+ }
405
+ });
406
+ return result;
407
+ }
408
+ addVal(table, key, val) {
409
+ return this.putVals(table, key, [val]);
410
+ }
411
+ /** Duplicate reads treat an empty or over-long key as simply absent, as `LMDBer` does. */
412
+ getVals(table, key) {
413
+ const mem = __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_resolve).call(this, table);
414
+ if (key.length === 0 || key.length > MAX_KEY_BYTES)
415
+ return [];
416
+ return mem.rows.slice(mem.lowerBound(key), mem.upperBound(key)).map((row) => copyBytes(row.value));
417
+ }
418
+ getValLast(table, key) {
419
+ return this.getVals(table, key).at(-1) ?? null;
420
+ }
421
+ *getValsIter(table, key) {
422
+ yield* this.getVals(table, key);
423
+ }
424
+ /** Count duplicates. Like LMDB, a plain table holding `key` refuses this dupsort-only call. */
425
+ cntVals(table, key) {
426
+ const mem = __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_resolve).call(this, table);
427
+ if (key.length === 0 || key.length > MAX_KEY_BYTES)
428
+ return 0;
429
+ const count = mem.upperBound(key) - mem.lowerBound(key);
430
+ if (count > 0 && !mem.dupsort)
431
+ throw new DatabaseOperationError("Duplicate count requires a dupsort table");
432
+ return count;
433
+ }
434
+ delVals(table, key) {
435
+ return this.removeRow(table, key);
436
+ }
437
+ /** First duplicate at `key` not below `start`; `start` is an unvalidated scan-style bound. */
438
+ seekVal(table, key, start) {
439
+ const mem = __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_resolve).call(this, table);
440
+ if (key.length === 0 || key.length > MAX_KEY_BYTES)
441
+ return null;
442
+ const bound = start?.length ? start : undefined;
443
+ const index = mem.lowerBound(key, bound);
444
+ if (!mem.matches(index, key))
445
+ return null;
446
+ if (bound !== undefined && !mem.dupsort) {
447
+ throw new DatabaseOperationError("Duplicate seek requires a dupsort table");
448
+ }
449
+ return copyBytes(mem.rows[index].value);
450
+ }
451
+ }
452
+ _MemStore_name = new WeakMap(), _MemStore_base = new WeakMap(), _MemStore_temp = new WeakMap(), _MemStore_opened = new WeakMap(), _MemStore_created = new WeakMap(), _MemStore_tables = new WeakMap(), _MemStore_version = new WeakMap(), _MemStore_writeVersion = new WeakMap(), _MemStore_undo = new WeakMap(), _MemStore_depth = new WeakMap(), _MemStore_instances = new WeakSet(), _MemStore_discard = function _MemStore_discard() {
453
+ __classPrivateFieldSet(this, _MemStore_tables, new Map(), "f");
454
+ __classPrivateFieldSet(this, _MemStore_version, null, "f");
455
+ __classPrivateFieldSet(this, _MemStore_created, false, "f");
456
+ }, _MemStore_walk = function
457
+ /**
458
+ * Walk rows in order, re-seeking from the last row after every yield so the
459
+ * table may change between steps. Empty bounds count as absent and a bound
460
+ * applies to the whole key, including all of its duplicates.
461
+ */
462
+ * _MemStore_walk(table, options, distinct) {
463
+ const reverse = options.reverse ?? false;
464
+ const start = options.start?.length ? options.start : undefined;
465
+ const end = options.end?.length ? options.end : undefined;
466
+ let mem = __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_resolve).call(this, table);
467
+ let index;
468
+ if (start === undefined) {
469
+ index = reverse ? mem.rows.length - 1 : 0;
470
+ }
471
+ else if (reverse) {
472
+ index = (options.exclusiveStart ? mem.lowerBound(start) : mem.upperBound(start)) - 1;
473
+ }
474
+ else {
475
+ index = options.exclusiveStart ? mem.upperBound(start) : mem.lowerBound(start);
476
+ }
477
+ for (let count = 0; options.limit === undefined || count < options.limit; count++) {
478
+ const row = mem.rows[index];
479
+ if (row === undefined)
480
+ return;
481
+ if (end !== undefined && (reverse ? compareBytes(row.key, end) <= 0 : compareBytes(row.key, end) >= 0))
482
+ return;
483
+ yield row;
484
+ mem = __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_resolve).call(this, table);
485
+ const value = distinct ? undefined : row.value;
486
+ index = reverse ? mem.lowerBound(row.key, value) - 1 : mem.upperBound(row.key, value);
487
+ }
488
+ }, _MemStore_resolve = function _MemStore_resolve(table) {
489
+ this.assertOpen();
490
+ const mem = table;
491
+ if (!mem || __classPrivateFieldGet(this, _MemStore_tables, "f").get(mem.name) !== mem) {
492
+ throw new DatabaseOperationError("Table handle is not valid for this open store");
493
+ }
494
+ return mem;
495
+ }, _MemStore_logRow = function _MemStore_logRow(mem, before, after, revert) {
496
+ const key = (before ?? after).key;
497
+ const [was, now] = [before?.value ?? null, after?.value ?? null];
498
+ __classPrivateFieldGet(this, _MemStore_undo, "f").push({
499
+ change: { kind: "row", table: mem.name, dupsort: mem.dupsort, key, before: was, after: now },
500
+ revert,
501
+ });
502
+ }, _MemStore_insert = function _MemStore_insert(mem, key, val) {
503
+ assertWritableKey(key);
504
+ if (mem.dupsort) {
505
+ assertDupValueSize(val);
506
+ }
507
+ const index = mem.lowerBound(key, val);
508
+ const row = { key: copyBytes(key), value: copyBytes(val) };
509
+ if (!mem.matches(index, key, val)) {
510
+ mem.rows.splice(index, 0, row);
511
+ __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_logRow).call(this, mem, null, row, () => mem.rows.splice(index, 1));
512
+ }
513
+ else if (!mem.dupsort) {
514
+ const prior = mem.rows[index];
515
+ mem.rows[index] = row;
516
+ __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_logRow).call(this, mem, prior, row, () => mem.rows[index] = prior);
517
+ }
518
+ }, _MemStore_removeAt = function _MemStore_removeAt(mem, index) {
519
+ const [row] = mem.rows.splice(index, 1);
520
+ __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_logRow).call(this, mem, row, null, () => mem.rows.splice(index, 0, row));
521
+ }, _MemStore_removeRange = function _MemStore_removeRange(mem, low, high) {
522
+ for (let index = high - 1; index >= low; index--) {
523
+ __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_removeAt).call(this, mem, index);
524
+ }
525
+ return high > low;
526
+ };
527
+ /** A `StoreOpener` of closed, independent in-memory stores. Place is meaningless here. */
528
+ export class MemStoreOpener {
529
+ create(_family, identity) {
530
+ return new MemStore(identity);
531
+ }
532
+ }