@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.
- package/README.md +1 -1
- package/package.json +9 -6
- package/src/blobs/index.js +15 -15
- package/src/blobs/server.js +0 -2
- package/src/database/changes.js +4 -8
- package/src/database/dispatch.js +296 -227
- package/src/database/encryption.js +22 -52
- package/src/database/envelope.js +1 -3
- package/src/database/index.js +406 -476
- package/src/database/rotation.js +56 -70
- package/src/identity/index.js +5 -9
- package/src/index.js +5 -9
- package/src/lib/constants.js +3 -12
- package/src/lib/errors.js +6 -10
- package/src/lib/schema.js +2 -5
- package/src/lib/utils.js +9 -24
- package/src/network/index.js +144 -167
- package/src/network/presence.js +131 -0
- package/src/pairing/candidate.js +2 -4
- package/src/pairing/index.js +41 -55
- package/src/pairing/invite.js +3 -4
- package/src/pairing/request.js +3 -9
- package/src/rpc/index.js +4 -14
- package/src/rpc/peer.js +3 -7
- package/src/storage/index.js +29 -50
- package/types/blobs/index.d.ts +5 -5
- package/types/blobs/server.d.ts +0 -2
- package/types/database/changes.d.ts +2 -5
- package/types/database/dispatch.d.ts +11 -7
- package/types/database/encryption.d.ts +8 -20
- package/types/database/index.d.ts +164 -141
- package/types/database/rotation.d.ts +14 -20
- package/types/identity/index.d.ts +5 -9
- package/types/index.d.ts +4 -3
- package/types/lib/errors.d.ts +6 -10
- package/types/lib/schema.d.ts +2 -5
- package/types/lib/utils.d.ts +3 -7
- package/types/network/index.d.ts +28 -27
- package/types/network/presence.d.ts +50 -0
- package/types/pairing/candidate.d.ts +1 -2
- package/types/pairing/index.d.ts +22 -30
- package/types/pairing/invite.d.ts +3 -3
- package/types/pairing/request.d.ts +1 -3
- package/types/rpc/index.d.ts +1 -4
- package/types/rpc/peer.d.ts +2 -4
- package/types/storage/index.d.ts +17 -30
|
@@ -53,15 +53,19 @@ export type DatabaseOpts = {
|
|
|
53
53
|
*/
|
|
54
54
|
key?: Uint8Array | null;
|
|
55
55
|
/**
|
|
56
|
-
*
|
|
56
|
+
* Always search and announce, outside the network's presence budget. The root.
|
|
57
57
|
*/
|
|
58
|
-
|
|
58
|
+
pinned?: boolean;
|
|
59
59
|
/**
|
|
60
60
|
* This device's writer keypair; a fresh random one by default. Never the identity's, never the database key.
|
|
61
61
|
*/
|
|
62
62
|
keyPair?: import('../identity/index.js').KeyPair;
|
|
63
63
|
/**
|
|
64
|
-
* Called when a
|
|
64
|
+
* Called when a node is skipped or refused, or the bee errors.
|
|
65
|
+
*
|
|
66
|
+
* Events: `update` (touched refs, a Set, after each applied batch), `apply` (one per applied
|
|
67
|
+
* op: `{ op, name, row, writerKey, seq }`, local and replicated), `writable`, `unwritable`,
|
|
68
|
+
* `behind` (an op from a newer app version was skipped).
|
|
65
69
|
*/
|
|
66
70
|
onerror?: (err: Error) => void;
|
|
67
71
|
};
|
|
@@ -89,7 +93,51 @@ export type Ref = {
|
|
|
89
93
|
verb: string;
|
|
90
94
|
name: string;
|
|
91
95
|
};
|
|
92
|
-
export type
|
|
96
|
+
export type HookContext = {
|
|
97
|
+
/**
|
|
98
|
+
* One of `put`, `set`, `del`, or an action name.
|
|
99
|
+
*/
|
|
100
|
+
op: string;
|
|
101
|
+
/**
|
|
102
|
+
* The ref the op targets.
|
|
103
|
+
*/
|
|
104
|
+
name: string;
|
|
105
|
+
/**
|
|
106
|
+
* The incoming row; mutate it in `before` to change what lands.
|
|
107
|
+
*/
|
|
108
|
+
row: Record<string, unknown> | null;
|
|
109
|
+
/**
|
|
110
|
+
* The stored row, or null.
|
|
111
|
+
*/
|
|
112
|
+
existing: Record<string, unknown> | null;
|
|
113
|
+
/**
|
|
114
|
+
* The row id for a `del`.
|
|
115
|
+
*/
|
|
116
|
+
id: string | null;
|
|
117
|
+
/**
|
|
118
|
+
* The writer's member id.
|
|
119
|
+
*/
|
|
120
|
+
memberId: string;
|
|
121
|
+
/**
|
|
122
|
+
* The writer's role.
|
|
123
|
+
*/
|
|
124
|
+
role: string;
|
|
125
|
+
get: (ref: string | {
|
|
126
|
+
name: string;
|
|
127
|
+
}, query?: string | Record<string, unknown>) => Promise<{
|
|
128
|
+
data: unknown;
|
|
129
|
+
}>;
|
|
130
|
+
put: (ref: string | {
|
|
131
|
+
name: string;
|
|
132
|
+
}, row: Record<string, unknown>) => Promise<void>;
|
|
133
|
+
set: (ref: string | {
|
|
134
|
+
name: string;
|
|
135
|
+
}, row: Record<string, unknown>) => Promise<void>;
|
|
136
|
+
del: (ref: string | {
|
|
137
|
+
name: string;
|
|
138
|
+
}, id?: string) => Promise<void>;
|
|
139
|
+
};
|
|
140
|
+
export type HookFn = (ctx: HookContext) => unknown;
|
|
93
141
|
/**
|
|
94
142
|
* @typedef {object} DatabaseOpts
|
|
95
143
|
* @property {any} store Corestore (or compatible) used to materialize the autobee.
|
|
@@ -101,21 +149,34 @@ export type HookFn = (ctx: any) => any | Promise<any>;
|
|
|
101
149
|
* @property {Uint8Array | null} [encryptionKey] Optional encryption key; falls back to identity's key.
|
|
102
150
|
* @property {Array<{ epoch: number, entropy: Uint8Array }> | null} [epochs] Rotation epochs to prime the keyring with (delivered at join).
|
|
103
151
|
* @property {Uint8Array | null} [key] Existing autobee key to reopen.
|
|
104
|
-
* @property {boolean} [
|
|
152
|
+
* @property {boolean} [pinned] Always search and announce, outside the network's presence budget. The root.
|
|
105
153
|
* @property {import('../identity/index.js').KeyPair} [keyPair] This device's writer keypair; a fresh random one by default. Never the identity's, never the database key.
|
|
106
|
-
* @property {(err: Error) => void} [onerror] Called when a
|
|
154
|
+
* @property {(err: Error) => void} [onerror] Called when a node is skipped or refused, or the bee errors.
|
|
155
|
+
*
|
|
156
|
+
* Events: `update` (touched refs, a Set, after each applied batch), `apply` (one per applied
|
|
157
|
+
* op: `{ op, name, row, writerKey, seq }`, local and replicated), `writable`, `unwritable`,
|
|
158
|
+
* `behind` (an op from a newer app version was skipped).
|
|
107
159
|
*
|
|
108
160
|
* @typedef {{ data: any | null }} SingleResult
|
|
109
161
|
* @typedef {{ data: any[], total: number | null, size: number }} ListResult `total` is null when a limited read skipped the full count — pass `{ total: true }` to force it.
|
|
110
162
|
* @typedef {{ gt?: string, gte?: string, lt?: string, lte?: string, reverse?: boolean, limit?: number, search?: string, fields?: string[], total?: boolean }} Query
|
|
111
163
|
* @typedef {{ kind: string, verb: string, name: string }} Ref
|
|
112
|
-
* @typedef {
|
|
164
|
+
* @typedef {object} HookContext
|
|
165
|
+
* @property {string} op One of `put`, `set`, `del`, or an action name.
|
|
166
|
+
* @property {string} name The ref the op targets.
|
|
167
|
+
* @property {Record<string, unknown> | null} row The incoming row; mutate it in `before` to change what lands.
|
|
168
|
+
* @property {Record<string, unknown> | null} existing The stored row, or null.
|
|
169
|
+
* @property {string | null} id The row id for a `del`.
|
|
170
|
+
* @property {string} memberId The writer's member id.
|
|
171
|
+
* @property {string} role The writer's role.
|
|
172
|
+
* @property {(ref: string | { name: string }, query?: string | Record<string, unknown>) => Promise<{ data: unknown }>} get
|
|
173
|
+
* @property {(ref: string | { name: string }, row: Record<string, unknown>) => Promise<void>} put
|
|
174
|
+
* @property {(ref: string | { name: string }, row: Record<string, unknown>) => Promise<void>} set
|
|
175
|
+
* @property {(ref: string | { name: string }, id?: string) => Promise<void>} del
|
|
176
|
+
* @typedef {(ctx: HookContext) => unknown} HookFn
|
|
113
177
|
*/
|
|
114
178
|
/**
|
|
115
|
-
* Multi-writer database built on Autobee + HyperDB.
|
|
116
|
-
* hyperdispatch-encoded log and exposes a `put/get/...` surface mirroring
|
|
117
|
-
* `Storage`, plus writer ops (claim/addWriter/removeWriter) for the
|
|
118
|
-
* shared writer set.
|
|
179
|
+
* Multi-writer database built on Autobee + HyperDB.
|
|
119
180
|
*/
|
|
120
181
|
export declare class Database extends ReadyResource {
|
|
121
182
|
store: any;
|
|
@@ -152,46 +213,28 @@ export declare class Database extends ReadyResource {
|
|
|
152
213
|
keyring: Keyring;
|
|
153
214
|
rotation: Rotation;
|
|
154
215
|
key: Uint8Array<ArrayBufferLike>;
|
|
155
|
-
|
|
216
|
+
pinned: boolean;
|
|
156
217
|
keyPair: import("../index.js").KeyPair;
|
|
157
218
|
_onerror: any;
|
|
158
219
|
bee: EpochAutobee;
|
|
159
220
|
dispatcher: {
|
|
160
|
-
|
|
221
|
+
dispatch: (value: Buffer, ctx: object) => Promise<void>;
|
|
161
222
|
apply: (nodes: Array<{
|
|
162
223
|
value: Buffer;
|
|
163
224
|
key: Buffer;
|
|
164
225
|
}>, view: object, host: object) => Promise<void>;
|
|
165
226
|
};
|
|
166
|
-
|
|
227
|
+
_presence: import("../network/presence.js").Slot;
|
|
167
228
|
_txChain: any;
|
|
168
229
|
_before: Map<any, any>;
|
|
169
230
|
_after: Map<any, any>;
|
|
170
|
-
|
|
171
|
-
_observers: Set<any>;
|
|
231
|
+
_hooking: number;
|
|
172
232
|
_verbs: Map<any, any>;
|
|
173
233
|
_touched: Set<any>;
|
|
174
234
|
_seq: number;
|
|
175
235
|
txQueue: any;
|
|
176
236
|
/** @param {Partial<DatabaseOpts>} [opts] */
|
|
177
237
|
constructor(opts?: Partial<DatabaseOpts>);
|
|
178
|
-
_open(): Promise<void>;
|
|
179
|
-
_close(): Promise<void>;
|
|
180
|
-
_preload(): Promise<void>;
|
|
181
|
-
_boot(): Promise<void>;
|
|
182
|
-
_replay(): Promise<boolean>;
|
|
183
|
-
_isTrusted(writer: any, view: any): Promise<any>;
|
|
184
|
-
_apply(nodes: any, view: any, host: any): Promise<void>;
|
|
185
|
-
_update(db: any): Promise<void>;
|
|
186
|
-
_joinSwarm(bee: any, discoveryKey: any): void;
|
|
187
|
-
/**
|
|
188
|
-
* Flip announce mode at runtime — passive stays reachable (server) but
|
|
189
|
-
* stops actively looking (client). Cheap; use it to demote idle rooms.
|
|
190
|
-
*
|
|
191
|
-
* @param {boolean} active
|
|
192
|
-
* @returns {Promise<void>}
|
|
193
|
-
*/
|
|
194
|
-
setActive(active: boolean): Promise<void>;
|
|
195
238
|
/** @returns {Uint8Array | null} discovery key of the underlying bee */
|
|
196
239
|
get discoveryKey(): Uint8Array | null;
|
|
197
240
|
/** @returns {Uint8Array | null} this device's local writer key */
|
|
@@ -202,8 +245,18 @@ export declare class Database extends ReadyResource {
|
|
|
202
245
|
get length(): number;
|
|
203
246
|
/** @returns {object | null} the materialized HyperDB view */
|
|
204
247
|
get view(): object | null;
|
|
248
|
+
_open(): Promise<void>;
|
|
249
|
+
_close(): Promise<void>;
|
|
250
|
+
/**
|
|
251
|
+
* `true` ranks this database as just touched, `false` takes it out of the swarm until the
|
|
252
|
+
* next update lands in it.
|
|
253
|
+
*
|
|
254
|
+
* @param {boolean} active
|
|
255
|
+
*/
|
|
256
|
+
setActive(active: boolean): void;
|
|
205
257
|
/**
|
|
206
|
-
* Register a pre-op hook.
|
|
258
|
+
* Register a pre-op hook. It runs at apply on every peer, inside the op's transaction;
|
|
259
|
+
* returning `false` (or throwing) refuses the op everywhere.
|
|
207
260
|
*
|
|
208
261
|
* @param {string} op
|
|
209
262
|
* @param {HookFn} fn
|
|
@@ -211,47 +264,14 @@ export declare class Database extends ReadyResource {
|
|
|
211
264
|
*/
|
|
212
265
|
before(op: string, fn: HookFn): () => void;
|
|
213
266
|
/**
|
|
214
|
-
* Register a post-op hook,
|
|
267
|
+
* Register a post-op hook. It runs at apply on every peer, in the op's transaction, so it
|
|
268
|
+
* may write derived rows through `ctx.put` / `ctx.set` / `ctx.del`.
|
|
215
269
|
*
|
|
216
270
|
* @param {string} op
|
|
217
271
|
* @param {HookFn} fn
|
|
218
272
|
* @returns {() => void} disposer
|
|
219
273
|
*/
|
|
220
274
|
after(op: string, fn: HookFn): () => void;
|
|
221
|
-
/**
|
|
222
|
-
* Subscribe to local apply notifications. Fires whenever the view updates;
|
|
223
|
-
* pass `scope` (a ref name) to fire only when that ref was touched.
|
|
224
|
-
*
|
|
225
|
-
* @param {() => void} fn
|
|
226
|
-
* @param {string} [scope]
|
|
227
|
-
* @returns {() => void} disposer
|
|
228
|
-
*/
|
|
229
|
-
onUpdate(fn: () => void, scope?: string): () => void;
|
|
230
|
-
/**
|
|
231
|
-
* Observe every applied op — local AND replicated (apply processes the merged
|
|
232
|
-
* log). The callback receives `{ op, name, row, writerKey, seq }` and runs
|
|
233
|
-
* synchronously, so it must be cheap and non-blocking (enqueue and return).
|
|
234
|
-
* Gated: zero cost when no subscriber is registered. Returns a disposer.
|
|
235
|
-
*
|
|
236
|
-
* @param {(event: { op: string, name: string, row: any, writerKey: any, seq: number }) => void} fn
|
|
237
|
-
* @returns {() => void} disposer
|
|
238
|
-
*/
|
|
239
|
-
onApply(fn: (event: {
|
|
240
|
-
op: string;
|
|
241
|
-
name: string;
|
|
242
|
-
row: any;
|
|
243
|
-
writerKey: any;
|
|
244
|
-
seq: number;
|
|
245
|
-
}) => void): () => void;
|
|
246
|
-
_runBefore(op: any, ctx: any): Promise<boolean>;
|
|
247
|
-
_runAfter(op: any, ctx: any): Promise<void>;
|
|
248
|
-
_opOf(node: any): {
|
|
249
|
-
op: any;
|
|
250
|
-
name: any;
|
|
251
|
-
value: any;
|
|
252
|
-
};
|
|
253
|
-
_touch(nodes: any): void;
|
|
254
|
-
_observe(nodes: any): void;
|
|
255
275
|
/**
|
|
256
276
|
* Insert (or overwrite by id) a row, stamping `id`/`createdAt`/`updatedAt`.
|
|
257
277
|
*
|
|
@@ -261,9 +281,7 @@ export declare class Database extends ReadyResource {
|
|
|
261
281
|
*/
|
|
262
282
|
put(name: string, row: Record<string, any>): Promise<SingleResult | null>;
|
|
263
283
|
/**
|
|
264
|
-
* Upsert by merging with the existing row, preserving `createdAt`.
|
|
265
|
-
* `{ upsert: false }` to update-only — a missing row is left untouched
|
|
266
|
-
* (checked atomically in the dispatch, so it never resurrects a deleted row).
|
|
284
|
+
* Upsert by merging with the existing row, preserving `createdAt`.
|
|
267
285
|
*
|
|
268
286
|
* @param {string} name
|
|
269
287
|
* @param {Record<string, any>} row
|
|
@@ -273,13 +291,6 @@ export declare class Database extends ReadyResource {
|
|
|
273
291
|
set(name: string, row: Record<string, any>, opts?: {
|
|
274
292
|
upsert?: boolean;
|
|
275
293
|
}): Promise<SingleResult | null>;
|
|
276
|
-
_merge(name: any, row: any, { upsert }?: {
|
|
277
|
-
upsert?: boolean;
|
|
278
|
-
}): Promise<{
|
|
279
|
-
op: string;
|
|
280
|
-
name: any;
|
|
281
|
-
row: any;
|
|
282
|
-
}>;
|
|
283
294
|
/**
|
|
284
295
|
* Delete by id (collection) or wipe the whole single-row table.
|
|
285
296
|
*
|
|
@@ -297,27 +308,17 @@ export declare class Database extends ReadyResource {
|
|
|
297
308
|
*/
|
|
298
309
|
call(op: string, data?: Record<string, any>): Promise<void>;
|
|
299
310
|
/**
|
|
300
|
-
* Rotate the encryption epoch: generate a fresh 32-byte secret, seal it to
|
|
301
|
-
*
|
|
302
|
-
* The announcement is appended under the current epoch (so every member —
|
|
303
|
-
* even one offline for several rotations — can walk the chain forward),
|
|
304
|
-
* and blocks written after it use the new one. Members absent from the
|
|
305
|
-
* envelope set (removed before the rotation) never learn the new key.
|
|
311
|
+
* Rotate the encryption epoch: generate a fresh 32-byte secret, seal it to every current
|
|
312
|
+
* member's identity key, and announce it through the log.
|
|
306
313
|
*
|
|
307
314
|
* @returns {Promise<{ epoch: number }>}
|
|
308
315
|
*/
|
|
309
316
|
rotate(): Promise<{
|
|
310
317
|
epoch: number;
|
|
311
318
|
}>;
|
|
312
|
-
_onfuture(version: any): void;
|
|
313
319
|
/**
|
|
314
|
-
* Batch every write made through the transaction handle passed to `fn`
|
|
315
|
-
*
|
|
316
|
-
* write queue — same surface (`put`/`set`/`del`/`call`), but writes buffer
|
|
317
|
-
* until `fn` returns, and are discarded if it throws. Writes made on the
|
|
318
|
-
* database itself meanwhile append normally: an unrelated concurrent write
|
|
319
|
-
* can never be swallowed into (and rolled back with) a transaction.
|
|
320
|
-
* Nested `tx()` on the handle joins the same batch.
|
|
320
|
+
* Batch every write made through the transaction handle passed to `fn` into a single
|
|
321
|
+
* autobee append.
|
|
321
322
|
*
|
|
322
323
|
* @template T
|
|
323
324
|
* @param {(tx: Database) => Promise<T> | T} fn
|
|
@@ -332,7 +333,6 @@ export declare class Database extends ReadyResource {
|
|
|
332
333
|
* @returns {Promise<void>}
|
|
333
334
|
*/
|
|
334
335
|
write(ops: Array<[string, any]>): Promise<void>;
|
|
335
|
-
_dryRun(encoded: any): Promise<any>;
|
|
336
336
|
/**
|
|
337
337
|
* Read a row. With no `query`: list all (collection) or fetch the one
|
|
338
338
|
* record (single). With a string id: fetch that specific row.
|
|
@@ -342,30 +342,14 @@ export declare class Database extends ReadyResource {
|
|
|
342
342
|
* @returns {Promise<SingleResult | ListResult>}
|
|
343
343
|
*/
|
|
344
344
|
get(name: string, query?: string | Query): Promise<SingleResult | ListResult>;
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
lte: {};
|
|
350
|
-
};
|
|
351
|
-
rest: {};
|
|
352
|
-
sorted: boolean;
|
|
345
|
+
_read(view: any, name: any, query: any): Promise<{
|
|
346
|
+
data: any;
|
|
347
|
+
total?: undefined;
|
|
348
|
+
size?: undefined;
|
|
353
349
|
} | {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
sorted: boolean;
|
|
358
|
-
};
|
|
359
|
-
_total(path: any, range: any, rows: any, query: any): Promise<any>;
|
|
360
|
-
/**
|
|
361
|
-
* Number of rows that match `query` (or total if omitted).
|
|
362
|
-
*
|
|
363
|
-
* @param {string} name
|
|
364
|
-
* @param {Query} [query]
|
|
365
|
-
* @returns {Promise<{ data: number }>}
|
|
366
|
-
*/
|
|
367
|
-
count(name: string, query?: Query): Promise<{
|
|
368
|
-
data: number;
|
|
350
|
+
data: any[];
|
|
351
|
+
total: any;
|
|
352
|
+
size: number;
|
|
369
353
|
}>;
|
|
370
354
|
/**
|
|
371
355
|
* Live snapshot stream — re-emits the latest `get()` result on every
|
|
@@ -377,11 +361,7 @@ export declare class Database extends ReadyResource {
|
|
|
377
361
|
*/
|
|
378
362
|
watch(name: string, query?: Query): import('streamx').Readable;
|
|
379
363
|
/**
|
|
380
|
-
* Delta subscription: batches of `{ prev, next }` row pairs instead of
|
|
381
|
-
* full snapshots. The first batch (and any batch after a view swap) carries
|
|
382
|
-
* the current matching rows as inserts with `reset: true` — replaying every
|
|
383
|
-
* batch into a Map keyed by row id always reconstructs current state.
|
|
384
|
-
* `limit`/`reverse` are not applied; deltas are unwindowed by design.
|
|
364
|
+
* Delta subscription: batches of `{ prev, next }` row pairs instead of full snapshots.
|
|
385
365
|
*
|
|
386
366
|
* @param {string} name
|
|
387
367
|
* @param {Query} [query]
|
|
@@ -389,11 +369,8 @@ export declare class Database extends ReadyResource {
|
|
|
389
369
|
*/
|
|
390
370
|
changes(name: string, query?: Query): import('streamx').Readable;
|
|
391
371
|
/**
|
|
392
|
-
* Provision this device. Its writer core was minted when the database opened
|
|
393
|
-
*
|
|
394
|
-
* a writer and a device in one write. A recovering device waits for the other
|
|
395
|
-
* devices' state, admits itself with the same master-signed add-writer
|
|
396
|
-
* appended optimistically, then records the device.
|
|
372
|
+
* Provision this device. Its writer core was minted when the database opened and this
|
|
373
|
+
* device is its only author, ever.
|
|
397
374
|
*
|
|
398
375
|
* @param {{ name?: string | null, isMobile?: boolean, recovering?: boolean, timeout?: number }} [opts]
|
|
399
376
|
* @returns {Promise<{ id: Uint8Array, writer: import('../identity/index.js').KeyPair }>}
|
|
@@ -408,9 +385,8 @@ export declare class Database extends ReadyResource {
|
|
|
408
385
|
writer: import('../identity/index.js').KeyPair;
|
|
409
386
|
}>;
|
|
410
387
|
/**
|
|
411
|
-
* Claim writership on an existing room by signing our writer key with the
|
|
412
|
-
*
|
|
413
|
-
* Admission only — the device is named separately (bootstrap → set-device).
|
|
388
|
+
* Claim writership on an existing room by signing our writer key with the member identity;
|
|
389
|
+
* the claim rides in the device core as an optimistic node.
|
|
414
390
|
*
|
|
415
391
|
* @returns {Promise<void>}
|
|
416
392
|
*/
|
|
@@ -425,12 +401,14 @@ export declare class Database extends ReadyResource {
|
|
|
425
401
|
timeout?: number;
|
|
426
402
|
}): Promise<void>;
|
|
427
403
|
/**
|
|
428
|
-
*
|
|
404
|
+
* Admit a device as a writer for `memberId`, an existing member. Omit it to
|
|
405
|
+
* admit another device of this identity.
|
|
429
406
|
*
|
|
430
407
|
* @param {Uint8Array} publicKey
|
|
408
|
+
* @param {string} [memberId]
|
|
431
409
|
* @returns {Promise<void>}
|
|
432
410
|
*/
|
|
433
|
-
addWriter(publicKey: Uint8Array): Promise<void>;
|
|
411
|
+
addWriter(publicKey: Uint8Array, memberId?: string): Promise<void>;
|
|
434
412
|
/**
|
|
435
413
|
* Remove a peer's writer key from the indexer set.
|
|
436
414
|
*
|
|
@@ -438,14 +416,6 @@ export declare class Database extends ReadyResource {
|
|
|
438
416
|
* @returns {Promise<void>}
|
|
439
417
|
*/
|
|
440
418
|
removeWriter(publicKey: Uint8Array): Promise<void>;
|
|
441
|
-
_optimistic(op: any, opts: any): Promise<void>;
|
|
442
|
-
_backfilled(timeout: any): Promise<void>;
|
|
443
|
-
_admission(writer: any, ts?: number): {
|
|
444
|
-
master: Uint8Array<ArrayBufferLike>;
|
|
445
|
-
writer: any;
|
|
446
|
-
sig: Uint8Array<ArrayBufferLike>;
|
|
447
|
-
ts: number;
|
|
448
|
-
};
|
|
449
419
|
/**
|
|
450
420
|
* Throw if the handle is closing/closed or the bee isn't ready yet.
|
|
451
421
|
*
|
|
@@ -466,6 +436,59 @@ export declare class Database extends ReadyResource {
|
|
|
466
436
|
* @returns {string}
|
|
467
437
|
*/
|
|
468
438
|
col(ref: Ref): string;
|
|
439
|
+
_preload(): Promise<void>;
|
|
440
|
+
_boot(): Promise<void>;
|
|
441
|
+
_replay(): Promise<boolean>;
|
|
442
|
+
_isTrusted(writer: any, view: any): Promise<any>;
|
|
443
|
+
_apply(nodes: any, view: any, host: any): Promise<void>;
|
|
444
|
+
_update(db: any): Promise<void>;
|
|
445
|
+
_joinSwarm(bee: any, discoveryKey: any): void;
|
|
446
|
+
_hooks(phase: any, op: any): any;
|
|
447
|
+
_inHook(fn: any): (ctx: any) => Promise<any>;
|
|
448
|
+
onUpdate(name: any, fn: any): () => this;
|
|
449
|
+
_opOf(node: any): {
|
|
450
|
+
op: any;
|
|
451
|
+
name: any;
|
|
452
|
+
value: any;
|
|
453
|
+
};
|
|
454
|
+
_notify(nodes: any): void;
|
|
455
|
+
_merge(name: any, row: any, { upsert }?: {
|
|
456
|
+
upsert?: boolean;
|
|
457
|
+
}): Promise<{
|
|
458
|
+
row: any;
|
|
459
|
+
}>;
|
|
460
|
+
_prepare(name: any, row: any): Ref;
|
|
461
|
+
_append(stored: any, verb: any): Promise<{
|
|
462
|
+
row: any;
|
|
463
|
+
}>;
|
|
464
|
+
_done(ctx: any): {
|
|
465
|
+
data: any;
|
|
466
|
+
};
|
|
467
|
+
_onfuture(version: any): void;
|
|
468
|
+
_dryRun(encoded: any): Promise<any>;
|
|
469
|
+
_plan(name: any, query?: {}): {
|
|
470
|
+
path: string;
|
|
471
|
+
range: {
|
|
472
|
+
gte: {};
|
|
473
|
+
lte: {};
|
|
474
|
+
};
|
|
475
|
+
rest: {};
|
|
476
|
+
sorted: boolean;
|
|
477
|
+
} | {
|
|
478
|
+
path: string;
|
|
479
|
+
range: {};
|
|
480
|
+
rest: {};
|
|
481
|
+
sorted: boolean;
|
|
482
|
+
};
|
|
483
|
+
_total(view: any, path: any, range: any, matched: any, query: any): Promise<any>;
|
|
484
|
+
_optimistic(op: any, opts: any): Promise<void>;
|
|
485
|
+
_backfilled(timeout: any): Promise<void>;
|
|
486
|
+
_admission(writer: any, ts?: number): {
|
|
487
|
+
master: Uint8Array<ArrayBufferLike>;
|
|
488
|
+
writer: any;
|
|
489
|
+
sig: Uint8Array<ArrayBufferLike>;
|
|
490
|
+
ts: number;
|
|
491
|
+
};
|
|
469
492
|
_checkFields(name: any, row: any): void;
|
|
470
|
-
_admit(verb: any,
|
|
493
|
+
_admit(verb: any, publicKey: any, memberId: any): Promise<void>;
|
|
471
494
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Epoch key rotation for a database: mint a secret, seal it to every member,
|
|
3
|
-
*
|
|
4
|
-
* to it. A debounced audit re-keys when the current epoch's recipients drift
|
|
5
|
-
* from the member set.
|
|
2
|
+
* Epoch key rotation for a database: mint a secret, seal it to every member, announce it
|
|
3
|
+
* through the log, and on every peer learn the secrets addressed to it.
|
|
6
4
|
*/
|
|
7
5
|
export declare class Rotation {
|
|
8
6
|
db: import("./index.js").Database;
|
|
@@ -20,18 +18,8 @@ export declare class Rotation {
|
|
|
20
18
|
rotate(): Promise<{
|
|
21
19
|
epoch: number;
|
|
22
20
|
}>;
|
|
23
|
-
_rotate(retried: any): any;
|
|
24
|
-
_members(): Promise<any[]>;
|
|
25
|
-
_seal(members: any, entropy: any): any;
|
|
26
|
-
_announce(stamp: any, entropy: any, wrapped: any): Promise<number>;
|
|
27
|
-
_mint(): any;
|
|
28
|
-
_taken(stamp: any): Promise<any>;
|
|
29
|
-
_epochs(): any;
|
|
30
21
|
/**
|
|
31
|
-
* An applied rotation announcement: open our envelope, learn the secret,
|
|
32
|
-
* persist it. Removed members have no envelope and stop here, every block
|
|
33
|
-
* after the announcement is noise to them. Our own in-flight rotation is left
|
|
34
|
-
* to `rotate()`, which adds the secret once the announcement flushed.
|
|
22
|
+
* An applied rotation announcement: open our envelope, learn the secret, persist it.
|
|
35
23
|
*
|
|
36
24
|
* @param {{ epoch: number, stamp: number, wrapped: Uint8Array, commit: Uint8Array }} row
|
|
37
25
|
*/
|
|
@@ -41,15 +29,21 @@ export declare class Rotation {
|
|
|
41
29
|
wrapped: Uint8Array;
|
|
42
30
|
commit: Uint8Array;
|
|
43
31
|
}): Promise<void>;
|
|
44
|
-
_unseal(row: any): Uint8Array<ArrayBufferLike>;
|
|
45
32
|
/**
|
|
46
|
-
* Safety net after boot: an epoch applied but never saved, e.g. a crash
|
|
47
|
-
*
|
|
48
|
-
* collection.
|
|
33
|
+
* Safety net after boot: an epoch applied but never saved, e.g. a crash between a
|
|
34
|
+
* rotation's append and its save, is learned from the epochs collection.
|
|
49
35
|
*/
|
|
50
36
|
hydrate(): Promise<void>;
|
|
51
|
-
_save(): any;
|
|
52
37
|
/** Debounced audit, run after every update. */
|
|
53
38
|
heal(): void;
|
|
39
|
+
_rotate(retried: any): any;
|
|
40
|
+
_members(): Promise<any[]>;
|
|
41
|
+
_seal(members: any, entropy: any): any;
|
|
42
|
+
_announce(stamp: any, entropy: any, wrapped: any): Promise<number>;
|
|
43
|
+
_mint(): any;
|
|
44
|
+
_taken(stamp: any): Promise<any>;
|
|
45
|
+
_epochs(): any;
|
|
46
|
+
_unseal(row: any): Uint8Array<ArrayBufferLike>;
|
|
47
|
+
_save(): any;
|
|
54
48
|
_audit(): Promise<void>;
|
|
55
49
|
}
|
|
@@ -14,9 +14,7 @@ export type IdentityFields = {
|
|
|
14
14
|
* @typedef {{ publicKey: Uint8Array, secretKey: Uint8Array, encryptionKey: Uint8Array, seed: Uint8Array }} IdentityFields
|
|
15
15
|
*/
|
|
16
16
|
/**
|
|
17
|
-
* Long-lived user identity derived from a BIP-39 seed phrase.
|
|
18
|
-
* sign keypair, a symmetric encryption key and the canonical id/topic used
|
|
19
|
-
* by every other resource to identify this user.
|
|
17
|
+
* Long-lived user identity derived from a BIP-39 seed phrase.
|
|
20
18
|
*/
|
|
21
19
|
export declare class Identity {
|
|
22
20
|
/**
|
|
@@ -74,9 +72,8 @@ export declare class Identity {
|
|
|
74
72
|
*/
|
|
75
73
|
verify(message: Uint8Array, signature: Uint8Array): boolean;
|
|
76
74
|
/**
|
|
77
|
-
* Open a sealed box addressed to this identity (any device holding the
|
|
78
|
-
*
|
|
79
|
-
* or is corrupt — callers treat that as "not addressed to me".
|
|
75
|
+
* Open a sealed box addressed to this identity (any device holding the seed-derived
|
|
76
|
+
* keypair can open it).
|
|
80
77
|
*
|
|
81
78
|
* @param {Uint8Array} sealed
|
|
82
79
|
* @returns {Uint8Array | null}
|
|
@@ -156,9 +153,8 @@ export declare class Identity {
|
|
|
156
153
|
*/
|
|
157
154
|
static verify(publicKey: Uint8Array, message: Uint8Array, signature: Uint8Array): boolean;
|
|
158
155
|
/**
|
|
159
|
-
* Seal a message to an identity's Ed25519 public key (sealed box over the
|
|
160
|
-
*
|
|
161
|
-
* i.e. any of that identity's devices — can open it.
|
|
156
|
+
* Seal a message to an identity's Ed25519 public key (sealed box over the curve25519
|
|
157
|
+
* conversion).
|
|
162
158
|
*
|
|
163
159
|
* @param {Uint8Array} publicKey
|
|
164
160
|
* @param {Uint8Array} message
|
package/types/index.d.ts
CHANGED
|
@@ -15,9 +15,10 @@ export type StorageOpts = import('./storage/index.js').StorageOpts;
|
|
|
15
15
|
export type StoredRow = import('./storage/index.js').StoredRow;
|
|
16
16
|
export type GetByIdResult = import('./storage/index.js').GetByIdResult;
|
|
17
17
|
/**
|
|
18
|
-
* `Ref` / `SingleResult` / `ListResult` are JSDoc typedefs (types, not runtime exports),
|
|
19
|
-
* are re-exported as namespaced type aliases — `export { Ref as StorageRef }`
|
|
20
|
-
*
|
|
18
|
+
* `Ref` / `SingleResult` / `ListResult` are JSDoc typedefs (types, not runtime exports),
|
|
19
|
+
* so they are re-exported as namespaced type aliases — `export { Ref as StorageRef }`
|
|
20
|
+
* fails at import because the.
|
|
21
|
+
*
|
|
21
22
|
* @typedef {import('./storage/index.js').Ref} StorageRef
|
|
22
23
|
* @typedef {import('./storage/index.js').SingleResult} StorageSingleResult
|
|
23
24
|
* @typedef {import('./storage/index.js').ListResult} StorageListResult
|
package/types/lib/errors.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Canonical error class. Every instance carries a stable `code` field which
|
|
3
|
-
*
|
|
4
|
-
* factories produce errors with the right code + a sensible message.
|
|
2
|
+
* Canonical error class. Every instance carries a stable `code` field which is also
|
|
3
|
+
* prefixed to the message, so logs stay self-identifying.
|
|
5
4
|
*/
|
|
6
5
|
export declare class CeroError extends Error {
|
|
7
6
|
isCeroError: boolean;
|
|
@@ -39,9 +38,7 @@ export declare class CeroError extends Error {
|
|
|
39
38
|
*/
|
|
40
39
|
static CLOSED(resource: string): CeroError;
|
|
41
40
|
/**
|
|
42
|
-
* A channel-stamped storage was opened under a different channel.
|
|
43
|
-
* does NOT name the stored channel — that label gates the network, so leaking it
|
|
44
|
-
* in an error would hint at a realm the caller isn't on.
|
|
41
|
+
* A channel-stamped storage was opened under a different channel.
|
|
45
42
|
*/
|
|
46
43
|
static CHANNEL_MISMATCH(): CeroError;
|
|
47
44
|
/**
|
|
@@ -108,10 +105,9 @@ export declare class CeroError extends Error {
|
|
|
108
105
|
*/
|
|
109
106
|
static DENIED(reason?: string | null, msg?: string): CeroError;
|
|
110
107
|
/**
|
|
111
|
-
* An apply-time rule refused the op. Every peer reaches this verdict from the
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
* anything that could differ between peers must not abort, or they fork.
|
|
108
|
+
* An apply-time rule refused the op. Every peer reaches this verdict from the same node
|
|
109
|
+
* and the same view, so it aborts the writer's whole batch — which is what makes a
|
|
110
|
+
* transaction atomic.
|
|
115
111
|
*
|
|
116
112
|
* @param {string} rule Which rule refused, e.g. 'write' or 'own'.
|
|
117
113
|
* @param {string} [msg]
|
package/types/lib/schema.d.ts
CHANGED
|
@@ -43,11 +43,8 @@ export declare const t: {
|
|
|
43
43
|
*/
|
|
44
44
|
single(fields: Record<string, Prim>): TypeDef;
|
|
45
45
|
/**
|
|
46
|
-
* Multi-row table keyed by `id`.
|
|
47
|
-
*
|
|
48
|
-
* `own` restricts a row to the member who wrote it — anyone may add rows, but
|
|
49
|
-
* only the author changes or deletes theirs. Members holding REMOVE can still
|
|
50
|
-
* moderate. Without it a writer may edit any row in the collection.
|
|
46
|
+
* Multi-row table keyed by `id`. `own` restricts a row to the member who wrote it — anyone
|
|
47
|
+
* may add rows, but only the author changes or deletes theirs.
|
|
51
48
|
*
|
|
52
49
|
* @param {Record<string, Prim>} fields
|
|
53
50
|
* @param {{ indexes?: Record<string, string[]>, own?: boolean }} [opts]
|
package/types/lib/utils.d.ts
CHANGED
|
@@ -21,9 +21,8 @@ export declare function isRank(role: any): boolean;
|
|
|
21
21
|
export declare function grants(a: any, b: any): boolean;
|
|
22
22
|
export declare function outranks(a: any, b: any): boolean;
|
|
23
23
|
/**
|
|
24
|
-
* Stream-of-snapshots primitive. Couples a `get` (returns the latest value)
|
|
25
|
-
*
|
|
26
|
-
* time `watch` ticks.
|
|
24
|
+
* Stream-of-snapshots primitive. Couples a `get` (returns the latest value) with a `watch`
|
|
25
|
+
* (re-fires on change) and emits the newest snapshot every time `watch` ticks.
|
|
27
26
|
*
|
|
28
27
|
* @template T
|
|
29
28
|
* @param {object} args
|
|
@@ -46,10 +45,7 @@ export declare function searchHit(row: any, term: any, fields: any): boolean;
|
|
|
46
45
|
*/
|
|
47
46
|
export declare function filter(rows: any[], query?: Record<string, any>): any[];
|
|
48
47
|
/**
|
|
49
|
-
* Run `cb` when `signal` aborts — or immediately if it already has.
|
|
50
|
-
* without a signal. The listener removes itself on fire. Returns a disposer that
|
|
51
|
-
* detaches the listener early, so a manual unsubscribe doesn't leave it lingering
|
|
52
|
-
* on a long-lived signal.
|
|
48
|
+
* Run `cb` when `signal` aborts — or immediately if it already has.
|
|
53
49
|
*
|
|
54
50
|
* @param {AbortSignal | undefined} signal
|
|
55
51
|
* @param {() => void} cb
|