@cero-base/core 1.19.0 → 2.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 (46) hide show
  1. package/README.md +1 -1
  2. package/package.json +9 -6
  3. package/src/blobs/index.js +15 -15
  4. package/src/blobs/server.js +0 -2
  5. package/src/database/changes.js +4 -8
  6. package/src/database/dispatch.js +296 -227
  7. package/src/database/encryption.js +22 -52
  8. package/src/database/envelope.js +1 -3
  9. package/src/database/index.js +406 -476
  10. package/src/database/rotation.js +56 -70
  11. package/src/identity/index.js +5 -9
  12. package/src/index.js +5 -9
  13. package/src/lib/constants.js +3 -12
  14. package/src/lib/errors.js +6 -10
  15. package/src/lib/schema.js +2 -5
  16. package/src/lib/utils.js +9 -24
  17. package/src/network/index.js +144 -167
  18. package/src/network/presence.js +131 -0
  19. package/src/pairing/candidate.js +2 -4
  20. package/src/pairing/index.js +41 -55
  21. package/src/pairing/invite.js +3 -4
  22. package/src/pairing/request.js +3 -9
  23. package/src/rpc/index.js +4 -14
  24. package/src/rpc/peer.js +3 -7
  25. package/src/storage/index.js +29 -50
  26. package/types/blobs/index.d.ts +5 -5
  27. package/types/blobs/server.d.ts +0 -2
  28. package/types/database/changes.d.ts +2 -5
  29. package/types/database/dispatch.d.ts +11 -7
  30. package/types/database/encryption.d.ts +8 -20
  31. package/types/database/index.d.ts +164 -141
  32. package/types/database/rotation.d.ts +14 -20
  33. package/types/identity/index.d.ts +5 -9
  34. package/types/index.d.ts +4 -3
  35. package/types/lib/errors.d.ts +6 -10
  36. package/types/lib/schema.d.ts +2 -5
  37. package/types/lib/utils.d.ts +3 -7
  38. package/types/network/index.d.ts +28 -27
  39. package/types/network/presence.d.ts +50 -0
  40. package/types/pairing/candidate.d.ts +1 -2
  41. package/types/pairing/index.d.ts +22 -30
  42. package/types/pairing/invite.d.ts +3 -3
  43. package/types/pairing/request.d.ts +1 -3
  44. package/types/rpc/index.d.ts +1 -4
  45. package/types/rpc/peer.d.ts +2 -4
  46. package/types/storage/index.d.ts +17 -30
@@ -35,10 +35,8 @@ import { CeroError } from '../lib/errors.js'
35
35
  */
36
36
 
37
37
  /**
38
- * Blind-pairing membership wrapper. Hosts invites, dispatches incoming
39
- * candidates to the application for accept/deny, and provides the joiner
40
- * side of the handshake. All wire payloads are signed and routed through
41
- * the supplied network.
38
+ * Blind-pairing membership wrapper. Hosts invites, dispatches incoming candidates to the
39
+ * application for accept/deny, and provides the joiner side of the handshake.
42
40
  */
43
41
  export class Pairing extends ReadyResource {
44
42
  /** @param {PairingOpts} [opts] */
@@ -63,8 +61,7 @@ export class Pairing extends ReadyResource {
63
61
  this.inviteEncoding = inviteEncoding
64
62
  this.joinerEncoding = joinerEncoding
65
63
  this._onerror = onerror
66
- // Fired with an invite's hex id when this instance stops serving it
67
- // (single-use settled, or expired) — lets the owner drop its persisted row.
64
+ // fired when this instance stops serving an invite, so the owner drops its row
68
65
  this.onconsume = onconsume
69
66
 
70
67
  this._blind = null
@@ -73,14 +70,21 @@ export class Pairing extends ReadyResource {
73
70
  this._candidates = new Set() // active joiner candidates
74
71
  }
75
72
 
73
+ /**
74
+ * Whether the underlying blind-pairing layer is suspended.
75
+ *
76
+ * @returns {boolean}
77
+ */
78
+ get suspended() {
79
+ return this._blind?.suspended === true
80
+ }
81
+
76
82
  async _open() {
77
83
  await this.network.ready()
78
84
  // shared instance — one set of swarm/DHT listeners for every handle
79
85
  this._blind = await this.network.blind()
80
86
 
81
- // blind-pairing allows ONE member listener per discovery key — a join-only
82
- // pairing must not register one, or concurrent joins under the same
83
- // identity throw 'Active member already exist'
87
+ // blind-pairing allows one member listener per discovery key
84
88
  if (this.host) {
85
89
  this._member = this._blind.addMember({
86
90
  // channel-scoped; the candidate hashes identically (no channel → identity)
@@ -104,22 +108,6 @@ export class Pairing extends ReadyResource {
104
108
  this._invites.clear()
105
109
  }
106
110
 
107
- /**
108
- * Resolve the resource discovery key an invite targets — without pairing.
109
- * Lets callers detect "already joined" before any handshake. Returns `null`
110
- * for an unparseable invite.
111
- *
112
- * @param {string} invite
113
- * @returns {Uint8Array | null}
114
- */
115
- static inviteTopic(invite) {
116
- try {
117
- return Invite.parse(invite).discoveryKey
118
- } catch {
119
- return null
120
- }
121
- }
122
-
123
111
  /**
124
112
  * Mint a new pairing invite. Returns its canonical wire form (z32 string).
125
113
  *
@@ -128,13 +116,11 @@ export class Pairing extends ReadyResource {
128
116
  */
129
117
  async createInvite({ role = '', expiresIn = 0, data = null, reuse = false } = {}) {
130
118
  if (this.closing || this.closed) throw CeroError.CLOSED('Pairing')
131
- // a join-only pairing has no member listener — an invite it mints would
132
- // never be served, so fail loudly instead of handing out a dead invite
119
+ // a join-only pairing serves no invites
133
120
  if (!this.host) throw CeroError.INVALID('cannot create invites on a join-only Pairing')
134
121
  if (!this.opened) await this.ready()
135
122
 
136
- // Rendezvous key matches the Member topic so candidates land on the right
137
- // Pairing instance (per-handle keys avoid identity-wide collisions).
123
+ // the rendezvous key matches the member topic
138
124
  const blind = BlindPairing.createInvite(this.topic)
139
125
 
140
126
  const invite = Invite.create({
@@ -154,8 +140,7 @@ export class Pairing extends ReadyResource {
154
140
  publicKey: blind.publicKey,
155
141
  invite,
156
142
  reuse,
157
- // minted here and possibly not yet persisted/replicated — syncRows must
158
- // never drop it for being absent from the store
143
+ // minted here, maybe not persisted yet: syncRows must keep it
159
144
  local: true
160
145
  })
161
146
 
@@ -176,11 +161,7 @@ export class Pairing extends ReadyResource {
176
161
  }
177
162
 
178
163
  /**
179
- * Reconcile the served-invite set with persisted rows (the room's `invites`
180
- * collection). Adds unknown rows so ANY member replica can serve them across
181
- * restarts; drops replicated records whose row disappeared (revoked or
182
- * consumed elsewhere). Locally-minted records not yet visible as rows are
183
- * kept.
164
+ * Reconcile the served-invite set with persisted rows (the room's `invites` collection).
184
165
  *
185
166
  * @param {Array<{ id: string, invite: Uint8Array, publicKey: Uint8Array, seed: Uint8Array, reuse?: boolean }>} rows
186
167
  */
@@ -232,16 +213,6 @@ export class Pairing extends ReadyResource {
232
213
  return false
233
214
  }
234
215
 
235
- /**
236
- * Cheap structural test for a candidate invite string.
237
- *
238
- * @param {unknown} str
239
- * @returns {boolean}
240
- */
241
- static isInvite(str) {
242
- return Invite.isInvite(str)
243
- }
244
-
245
216
  /**
246
217
  * Joiner side — start a pairing handshake against `inviteStr` and resolve
247
218
  * with the host's response when the host confirms.
@@ -269,15 +240,6 @@ export class Pairing extends ReadyResource {
269
240
  return candidate.start()
270
241
  }
271
242
 
272
- /**
273
- * Whether the underlying blind-pairing layer is suspended.
274
- *
275
- * @returns {boolean}
276
- */
277
- get suspended() {
278
- return this._blind?.suspended === true
279
- }
280
-
281
243
  /**
282
244
  * Pause blind-pairing — keeps state, drops sockets. Idempotent.
283
245
  *
@@ -343,6 +305,30 @@ export class Pairing extends ReadyResource {
343
305
 
344
306
  this.emit('candidate', request)
345
307
  }
308
+
309
+ /**
310
+ * Resolve the resource discovery key an invite targets — without pairing.
311
+ *
312
+ * @param {string} invite
313
+ * @returns {Uint8Array | null}
314
+ */
315
+ static inviteTopic(invite) {
316
+ try {
317
+ return Invite.parse(invite).discoveryKey
318
+ } catch {
319
+ return null
320
+ }
321
+ }
322
+
323
+ /**
324
+ * Cheap structural test for a candidate invite string.
325
+ *
326
+ * @param {unknown} str
327
+ * @returns {boolean}
328
+ */
329
+ static isInvite(str) {
330
+ return Invite.isInvite(str)
331
+ }
346
332
  }
347
333
 
348
334
  function encodeUserData(data, encoding) {
@@ -35,9 +35,9 @@ const SignBody = getEncoding('@cero/invite-body')
35
35
  */
36
36
 
37
37
  /**
38
- * Signed, expirable pairing invite. Wraps a blind-pairing invite with a
39
- * role, optional payload and an Ed25519 signature so the host can be
40
- * authenticated by the joiner before any handshake happens.
38
+ * Signed, expirable pairing invite. Wraps a blind-pairing invite with a role, optional
39
+ * payload and an Ed25519 signature so the host can be authenticated by the joiner before
40
+ * any handshake happens.
41
41
  *
42
42
  * @property {any} [_rawData] Decoded payload kept alongside the encoded `data` for convenience.
43
43
  * @property {Uint8Array} _discoveryKey Cached discovery key of the wrapped blind invite.
@@ -54,7 +54,6 @@ export class Invite {
54
54
  this.sig = fields.sig
55
55
  this._str = fields._str || null
56
56
 
57
- // cached discovery key of the wrapped blind invite
58
57
  this._discoveryKey = null
59
58
  }
60
59
 
@@ -8,10 +8,7 @@ import { CeroError } from '../lib/errors.js'
8
8
  export const STATUS_ACCEPTED = 0
9
9
  export const STATUS_DENIED = 1
10
10
 
11
- // Wire envelope carried in BlindPairing's `additional.data` on the confirm response.
12
- // We piggyback on the confirm path for *both* success and deny — blind-pairing's
13
- // native deny() has no payload field, and its discoveryKey check pins the wire
14
- // `key` to the invite, so the real resource key flows through this envelope.
11
+ // success and deny both ride the confirm response
15
12
  export const Response = getEncoding('@cero/confirm')
16
13
 
17
14
  /**
@@ -31,9 +28,7 @@ export const Response = getEncoding('@cero/confirm')
31
28
 
32
29
  /**
33
30
  * Internal — a pairing request from an incoming candidate, awaiting the host's
34
- * accept/deny. Built in `_oncandidate` and emitted on the `'candidate'` event so
35
- * the host can decide via `confirm` / `deny`. (The candidate is the joiner; this
36
- * is the host's handle to answer it.)
31
+ * accept/deny.
37
32
  *
38
33
  * @property {boolean} _settled Whether confirm/deny has already run.
39
34
  */
@@ -86,8 +81,7 @@ export class Request {
86
81
  })
87
82
  }
88
83
 
89
- // sign the envelope with the per-invite seed and answer the candidate
90
- // (callers guard idempotency before this runs)
84
+ // signed with the per-invite seed
91
85
  _respond(envelope) {
92
86
  this._settled = true
93
87
  this._onsettle()
package/src/rpc/index.js CHANGED
@@ -9,8 +9,7 @@ export { RPCClient } from './client.js'
9
9
 
10
10
  const EMPTY = b4a.alloc(0)
11
11
 
12
- // Default envelope encodings for the @cero namespace, used when the supplied
13
- // spec does not provide its own rows/query/create types in its schema.
12
+ // fallback envelope encodings when the spec has none
14
13
  const DEFAULT_ROWS = getEncoding('@cero/rows')
15
14
  const DEFAULT_CHANGES = getEncoding('@cero/changes')
16
15
  const DEFAULT_QUERY = getEncoding('@cero/query')
@@ -39,10 +38,7 @@ const DEFAULT_CREATE = getEncoding('@cero/create')
39
38
  */
40
39
 
41
40
  /**
42
- * Attach a `codec` namespace to a hyperschema-shaped `spec`. Looks up
43
- * envelope types using the spec's namespace (`@<ns>/rows` etc.) and falls
44
- * back to the bundled `@cero/*` envelopes when the spec has not declared
45
- * its own. Returns the spec for chaining.
41
+ * Attach a `codec` namespace to a hyperschema-shaped `spec`.
46
42
  *
47
43
  * @param {Spec} spec
48
44
  * @returns {Spec}
@@ -107,11 +103,7 @@ export function bindCodec(spec) {
107
103
  if (!buf || buf.length === 0) return undefined
108
104
  const env = decodeEnvelope(schema, QUERY, DEFAULT_QUERY, buf)
109
105
  const out = {}
110
- // Hyperschema fills optional uint/bool with 0/false defaults, so we can only
111
- // recover fields the encoder actually wrote (truthy). KNOWN LIMITATION: a
112
- // `limit: 0` query (degenerate — "return nothing") is indistinguishable from
113
- // "no limit" over the wire and is treated as unset. Falsy cursors (gt: '')
114
- // are harmless — an empty-string bound matches everything anyway.
106
+ // hyperschema fills optional fields with 0/false, so only truthy fields are recovered; limit: 0 is lost
115
107
  if (env.gt) out.gt = env.gt
116
108
  if (env.gte) out.gte = env.gte
117
109
  if (env.lt) out.lt = env.lt
@@ -145,9 +137,7 @@ export function bindCodec(spec) {
145
137
  return spec
146
138
  }
147
139
 
148
- // Tries the spec's own envelope type first; falls back to the built-in @cero
149
- // encoding bundled with this primitive. This lets callers point a foreign spec
150
- // at the codec without re-declaring the rows/query/create envelopes.
140
+ // the spec's own envelope type first, the built-in @cero encoding as fallback
151
141
  function encodeEnvelope(schema, fqn, fallback, value) {
152
142
  if (fqn && schemaHas(schema, fqn)) return schema.encode(fqn, value)
153
143
  return c.encode(fallback, value)
package/src/rpc/peer.js CHANGED
@@ -6,10 +6,8 @@ import { bindCodec } from './index.js'
6
6
  import { CeroError } from '../lib/errors.js'
7
7
 
8
8
  /**
9
- * Shared RPC peer: wraps an IPC duplex in a length-framed stream and constructs
10
- * the spec's hrpc binding. Frames are paused until `_open` runs so handlers
11
- * registered before `ready()` see a clean slate. `RPCClient` and `RPCServer`
12
- * are thin named subclasses — identical wiring, distinct roles.
9
+ * Shared RPC peer: wraps an IPC duplex in a length-framed stream and constructs the spec's
10
+ * hrpc binding.
13
11
  */
14
12
  export class RPCPeer extends ReadyResource {
15
13
  /**
@@ -26,9 +24,7 @@ export class RPCPeer extends ReadyResource {
26
24
  this.spec = spec
27
25
  this.framed = new FramedStream(ipc)
28
26
  this.rpc = new spec.rpc(this.framed)
29
- // pause AFTER hrpc attaches its 'data' listener — streamx re-resumes a
30
- // paused stream the moment a listener attaches, so pausing first holds
31
- // nothing and early frames would dispatch before the codec is bound
27
+ // pause after hrpc attaches its listener, streamx resumes on attach
32
28
  this.framed.pause()
33
29
  }
34
30
 
@@ -25,9 +25,8 @@ import { CeroError } from '../lib/errors.js'
25
25
  */
26
26
 
27
27
  /**
28
- * Local, single-writer storage. Backed by either RocksDB (`rocks`) or a
29
- * Hyperbee on top of corestore (`bee`). Exposes the same `put/get/...`
30
- * surface as `Database` but without networking or multi-writer apply.
28
+ * Local, single-writer storage. Backed by either RocksDB (`rocks`) or a Hyperbee on top of
29
+ * corestore (`bee`).
31
30
  */
32
31
  export class Storage extends ReadyResource {
33
32
  /**
@@ -65,26 +64,6 @@ export class Storage extends ReadyResource {
65
64
  this.db = null
66
65
  }
67
66
 
68
- /**
69
- * Construct a RocksDB-backed Storage.
70
- *
71
- * @param {string} dir
72
- * @param {Omit<StorageOpts, 'backend'>} opts
73
- */
74
- static rocks(dir, opts) {
75
- return new Storage(dir, { ...opts, backend: ROCKS })
76
- }
77
-
78
- /**
79
- * Construct a Hyperbee-backed Storage.
80
- *
81
- * @param {string} dir
82
- * @param {Omit<StorageOpts, 'backend'>} opts
83
- */
84
- static bee(dir, opts) {
85
- return new Storage(dir, { ...opts, backend: BEE })
86
- }
87
-
88
67
  async _open() {
89
68
  if (this._ownsRoot) {
90
69
  this.root = new HypercoreStorage(this.dir, { columnFamilies: [this._cf] })
@@ -145,9 +124,7 @@ export class Storage extends ReadyResource {
145
124
  }
146
125
 
147
126
  /**
148
- * Upsert by merging with the existing row, preserving `createdAt`. Pass
149
- * `{ upsert: false }` to update-only — a missing row is left untouched
150
- * (returns `null`) instead of created. Mirrors `Database.set`.
127
+ * Upsert by merging with the existing row, preserving `createdAt`.
151
128
  *
152
129
  * @param {string} name
153
130
  * @param {Record<string, any>} row
@@ -202,13 +179,11 @@ export class Storage extends ReadyResource {
202
179
 
203
180
  if (ref.kind === SINGLE) return { data: await this.db.findOne(col, {}) }
204
181
 
205
- // keyed lookup, not a full scan + in-memory find
206
182
  if (typeof query === 'string') {
207
183
  return { data: (await this.db.get(col, { id: query })) ?? null }
208
184
  }
209
185
 
210
- // hyperdb only honors range/limit operators — equality fields and search
211
- // must be applied here or they are silently ignored and every row comes back
186
+ // hyperdb ignores equality fields and search, apply them here
212
187
  const eq = Object.keys(query || {}).filter((k) => !QUERY_RESERVED.has(k))
213
188
  if (eq.length || query?.search) {
214
189
  const rows = await this.db.find(col, {}).toArray()
@@ -218,30 +193,14 @@ export class Storage extends ReadyResource {
218
193
  }
219
194
 
220
195
  const data = await this.db.find(col, range(query)).toArray()
221
- // a limit caps `data`, so `total` needs a full count; with no query
222
- // `data` is already everything — skip the second scan.
223
- const filtered = query && Object.keys(query).length > 0
224
- const total = filtered ? (await this.db.find(col, {}).toArray()).length : data.length
196
+ // a limit caps data, so total needs the unlimited range
197
+ const total =
198
+ query?.limit != null
199
+ ? (await this.db.find(col, range({ ...query, limit: undefined })).toArray()).length
200
+ : data.length
225
201
  return { data, total, size: data.length }
226
202
  }
227
203
 
228
- /**
229
- * Number of rows that match `query` (or total if omitted).
230
- *
231
- * @param {string} name
232
- * @param {Record<string, any>} [query]
233
- * @returns {Promise<{ data: number }>}
234
- */
235
- async count(name, query) {
236
- this._guard()
237
- const ref = this._ref(name)
238
- const col = this._col(ref)
239
- const eq = Object.keys(query || {}).filter((k) => !QUERY_RESERVED.has(k))
240
- const filtered = eq.length || query?.search
241
- const rows = await this.db.find(col, filtered ? {} : range(query)).toArray()
242
- return { data: (filtered ? filter(rows, query) : rows).length }
243
- }
244
-
245
204
  /**
246
205
  * Live snapshot stream — re-emits the latest `get()` result on every
247
206
  * underlying mutation. Destroy the stream to stop watching.
@@ -294,6 +253,26 @@ export class Storage extends ReadyResource {
294
253
  await this.db.insert(this._col(ref), row)
295
254
  await this.db.flush()
296
255
  }
256
+
257
+ /**
258
+ * Construct a RocksDB-backed Storage.
259
+ *
260
+ * @param {string} dir
261
+ * @param {Omit<StorageOpts, 'backend'>} opts
262
+ */
263
+ static rocks(dir, opts) {
264
+ return new Storage(dir, { ...opts, backend: ROCKS })
265
+ }
266
+
267
+ /**
268
+ * Construct a Hyperbee-backed Storage.
269
+ *
270
+ * @param {string} dir
271
+ * @param {Omit<StorageOpts, 'backend'>} opts
272
+ */
273
+ static bee(dir, opts) {
274
+ return new Storage(dir, { ...opts, backend: BEE })
275
+ }
297
276
  }
298
277
 
299
278
  // hyperdb bounds are records, a bare id must be wrapped
@@ -73,11 +73,6 @@ export declare class Blobs extends ReadyResource {
73
73
  * @returns {Promise<RawBlobId>}
74
74
  */
75
75
  put(input: Uint8Array | import('streamx').Readable): Promise<RawBlobId>;
76
- /**
77
- * @param {import('streamx').Readable} input
78
- * @returns {Promise<RawBlobId>}
79
- */
80
- _putStream(input: import('streamx').Readable): Promise<RawBlobId>;
81
76
  /**
82
77
  * Resolve the blob bytes for a raw blobId. Fetches from peers if not local.
83
78
  *
@@ -101,6 +96,11 @@ export declare class Blobs extends ReadyResource {
101
96
  * @returns {Promise<void>}
102
97
  */
103
98
  clear(blobId: RawBlobId): Promise<void>;
99
+ /**
100
+ * @param {import('streamx').Readable} input
101
+ * @returns {Promise<RawBlobId>}
102
+ */
103
+ _putStream(input: import('streamx').Readable): Promise<RawBlobId>;
104
104
  _guard(): void;
105
105
  }
106
106
  export { encodeId, decodeId };
@@ -7,8 +7,6 @@ export type Resolved = {
7
7
  */
8
8
  /**
9
9
  * HTTP server that turns a string file id into a renderable localhost URL.
10
- * Wraps hypercore-blob-server; the underlying store session is owned by
11
- * BlobServer and closed when `close()` is called.
12
10
  */
13
11
  export declare class FileServer {
14
12
  resolve: (coreKey: Buffer, info: object) => Resolved | null | Promise<Resolved | null>;
@@ -1,9 +1,6 @@
1
1
  /**
2
- * Pull-driven delta stream over a collection: batches of `{ prev, next }`
3
- * pairs diffed from the head this stream last reported. Update ticks only
4
- * mark the stream dirty, the diff runs when the reader asks, so bursts fold
5
- * into one batch and nothing is dropped. The first batch, and any batch after
6
- * the view moved to another core, is the full matching state with `reset: true`.
2
+ * Pull-driven delta stream over a collection: batches of `{ prev, next }` pairs diffed
3
+ * from the head this stream last reported.
7
4
  *
8
5
  * @param {import('./index.js').Database} db
9
6
  * @param {string} name Ref name (scopes the update ticks).
@@ -1,7 +1,3 @@
1
- export declare const BUILTINS: {
2
- name: string;
3
- verb: string;
4
- }[];
5
1
  /**
6
2
  * Build the hyperdispatch router for a spec: wires membership, builtin, and
7
3
  * spec-defined collection/action ops, returning the router plus an apply loop.
@@ -13,9 +9,13 @@ export declare const BUILTINS: {
13
9
  * @param {(err: Error) => void} opts.onerror Called when a malformed node is skipped.
14
10
  * @param {() => Uint8Array | null} opts.key The database key, null until the bee booted.
15
11
  * @param {(row: { epoch: number, stamp: number, wrapped: Uint8Array, commit: Uint8Array }) => Promise<void>} opts.onepoch Per-peer side of an applied rotation (skipped in dry runs).
16
- * @returns {{ dispatcher: object, apply: (nodes: Array<{ value: Buffer, key: Buffer }>, view: object, host: object) => Promise<void> }}
12
+ * @param {(phase: 'before' | 'after', op: string) => Function[]} [opts.hooks] Registered hooks for an op, run inside its transaction.
13
+ * @param {(name: string) => void} [opts.touch] Marks a ref written by a hook, so its watchers tick.
14
+ * @param {(view: object, name: string, query?: any) => Promise<any>} [opts.read] Planned read against a given view, for a hook's `ctx.get`.
15
+ * @param {(fn: Function) => Function} [opts.inHook] Wraps a route so operators called inside it throw, like a hook.
16
+ * @returns {{ dispatch: (value: Buffer, ctx: object) => Promise<void>, apply: (nodes: Array<{ value: Buffer, key: Buffer }>, view: object, host: object) => Promise<void> }}
17
17
  */
18
- export declare function makeDispatcher({ spec, ns, routes, onerror, key, onepoch }: {
18
+ export declare function makeDispatcher({ spec, ns, routes, onerror, key, onepoch, hooks, touch, read, inHook }: {
19
19
  spec: {
20
20
  dispatch: {
21
21
  Router: Function;
@@ -38,8 +38,12 @@ export declare function makeDispatcher({ spec, ns, routes, onerror, key, onepoch
38
38
  wrapped: Uint8Array;
39
39
  commit: Uint8Array;
40
40
  }) => Promise<void>;
41
+ hooks?: (phase: 'before' | 'after', op: string) => Function[];
42
+ touch?: (name: string) => void;
43
+ read?: (view: object, name: string, query?: any) => Promise<any>;
44
+ inHook?: (fn: Function) => Function;
41
45
  }): {
42
- dispatcher: object;
46
+ dispatch: (value: Buffer, ctx: object) => Promise<void>;
43
47
  apply: (nodes: Array<{
44
48
  value: Buffer;
45
49
  key: Buffer;
@@ -2,9 +2,7 @@ import Autobee from 'autobee';
2
2
  import c from 'compact-encoding';
3
3
  declare const WriterEncryption: any;
4
4
  /**
5
- * Encryption key for a rotation epoch's blob cores. New files land in a core
6
- * keyed by the epoch entropy, so file confidentiality rotates with the room:
7
- * only holders of the epoch secret can derive the core key.
5
+ * Encryption key for a rotation epoch's blob cores.
8
6
  *
9
7
  * @param {Uint8Array} entropy
10
8
  * @returns {Uint8Array}
@@ -22,8 +20,6 @@ export declare const wraps: c.Encoder<any[], {
22
20
  }[]>;
23
21
  /**
24
22
  * Wire codec for locally persisted / pairing-delivered epoch secrets.
25
- * `epoch` is the apply-order sequence; `stamp` is the content-addressed
26
- * uint32 written into block headers.
27
23
  */
28
24
  export declare const epochEntries: c.Encoder<any[], {
29
25
  epoch: number;
@@ -31,14 +27,7 @@ export declare const epochEntries: c.Encoder<any[], {
31
27
  entropy: Uint8Array<ArrayBufferLike>;
32
28
  }[]>;
33
29
  /**
34
- * Per-database registry of rotation epochs. Stamp 0 is the base key era
35
- * (no entry needed — it derives from the upstream GENESIS_ENTROPY path).
36
- * Every rotation adds an entry keyed by its content-addressed `stamp` (the
37
- * uint32 written into block headers, chosen randomly by the rotator and
38
- * validated unique at apply) alongside its apply-order `seq`. Because the
39
- * stamp is chosen before any block is written and can never be renumbered
40
- * by linearization, a block's header always identifies its true key —
41
- * concurrent rotations cannot make blocks undecryptable.
30
+ * Per-database registry of rotation epochs.
42
31
  */
43
32
  export declare class Keyring {
44
33
  /** @type {Map<number, Uint8Array>} stamp → entropy */
@@ -77,16 +66,15 @@ export declare class Keyring {
77
66
  remove(stamp: number): void;
78
67
  }
79
68
  /**
80
- * The epoch-aware provider — the class itself is upstream WriterEncryption;
81
- * the epoch behavior lives on the (patched) base prototype above. Named for
82
- * call sites and tests.
69
+ * The epoch-aware provider — the class itself is upstream WriterEncryption; the epoch
70
+ * behavior lives on the (patched) base prototype above.
83
71
  */
84
72
  export declare class EpochEncryption extends WriterEncryption {
85
73
  }
86
74
  /**
87
- * Autobee with a rotation keyring. Every provider autobee constructs
88
- * (view/system factory, foreign cores, ActiveWriters) picks the epochs up
89
- * through the patched base class and this `keyring` property.
75
+ * Autobee with a rotation keyring. Every provider autobee constructs (view/system factory,
76
+ * foreign cores, ActiveWriters) picks the epochs up through the patched base class and
77
+ * this `keyring` property.
90
78
  */
91
79
  export declare class EpochAutobee extends Autobee {
92
80
  keyring: any;
@@ -95,9 +83,9 @@ export declare class EpochAutobee extends Autobee {
95
83
  _epochRetryDelay: number;
96
84
  _epochRetrySeen: number;
97
85
  constructor(store: any, key: any, handlers?: {});
86
+ _close(): Promise<any>;
98
87
  _bumpPendingWriters(...args: any[]): Promise<any>;
99
88
  _applyWakeupHints(): Promise<any>;
100
89
  _scheduleEpochRetry(): void;
101
- _close(): Promise<any>;
102
90
  }
103
91
  export {};