@cero-base/core 1.18.2 → 2.0.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 +5 -6
- package/package.json +14 -11
- package/src/blobs/index.js +17 -17
- package/src/blobs/server.js +0 -2
- package/src/database/changes.js +34 -60
- package/src/database/dispatch.js +156 -245
- package/src/database/encryption.js +22 -52
- package/src/database/envelope.js +1 -3
- package/src/database/index.js +514 -513
- package/src/database/rotation.js +191 -193
- package/src/identity/index.js +8 -12
- 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 +55 -38
- package/src/network/index.js +138 -166
- package/src/pairing/candidate.js +123 -0
- package/src/pairing/index.js +36 -267
- package/src/pairing/invite.js +3 -4
- package/src/pairing/request.js +96 -0
- package/src/rpc/index.js +4 -14
- package/src/rpc/peer.js +3 -7
- package/src/storage/index.js +36 -49
- package/types/blobs/codec.d.ts +8 -8
- package/types/blobs/index.d.ts +38 -37
- package/types/blobs/server.d.ts +8 -10
- package/types/database/changes.d.ts +3 -8
- package/types/database/dispatch.d.ts +28 -25
- package/types/database/encryption.d.ts +22 -30
- package/types/database/envelope.d.ts +2 -2
- package/types/database/index.d.ts +196 -221
- package/types/database/rotation.d.ts +47 -30
- package/types/identity/index.d.ts +83 -87
- package/types/index.d.ts +42 -55
- package/types/lib/constants.d.ts +34 -38
- package/types/lib/errors.d.ts +16 -20
- package/types/lib/schema.d.ts +49 -42
- package/types/lib/spec/index.d.ts +29 -55
- package/types/lib/utils.d.ts +26 -20
- package/types/network/discovery.d.ts +7 -7
- package/types/network/index.d.ts +64 -72
- package/types/pairing/candidate.d.ts +36 -0
- package/types/pairing/index.d.ts +91 -151
- package/types/pairing/invite.d.ts +91 -91
- package/types/pairing/request.d.ts +133 -0
- package/types/rpc/client.d.ts +2 -2
- package/types/rpc/index.d.ts +30 -33
- package/types/rpc/peer.d.ts +11 -11
- package/types/rpc/server.d.ts +2 -2
- package/types/storage/index.d.ts +70 -71
- package/src/database/bootstrap.js +0 -133
- package/src/database/hooks.js +0 -112
- package/src/database/membership.js +0 -67
- package/types/database/bootstrap.d.ts +0 -20
- package/types/database/hooks.d.ts +0 -8
- package/types/database/membership.d.ts +0 -7
|
@@ -1,3 +1,95 @@
|
|
|
1
|
+
import ReadyResource from 'ready-resource';
|
|
2
|
+
import { EpochAutobee, Keyring } from './encryption.js';
|
|
3
|
+
import { Identity } from '../identity/index.js';
|
|
4
|
+
import { Rotation } from './rotation.js';
|
|
5
|
+
export type DatabaseOpts = {
|
|
6
|
+
/**
|
|
7
|
+
* Corestore (or compatible) used to materialize the autobee.
|
|
8
|
+
*/
|
|
9
|
+
store: any;
|
|
10
|
+
/**
|
|
11
|
+
* Long-lived member identity used to sign writer changes.
|
|
12
|
+
*/
|
|
13
|
+
identity: import('../identity/index.js').Identity;
|
|
14
|
+
/**
|
|
15
|
+
* Optional swarm; required for multi-writer replication.
|
|
16
|
+
*/
|
|
17
|
+
network?: import('../network/index.js').Network;
|
|
18
|
+
/**
|
|
19
|
+
* Generated hyperdb + hyperdispatch spec.
|
|
20
|
+
*/
|
|
21
|
+
spec: {
|
|
22
|
+
database: any;
|
|
23
|
+
dispatch: any;
|
|
24
|
+
meta?: {
|
|
25
|
+
ns?: string;
|
|
26
|
+
refs?: Record<string, {
|
|
27
|
+
kind?: string;
|
|
28
|
+
verb?: string;
|
|
29
|
+
}>;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Custom action handlers keyed by route name.
|
|
34
|
+
*/
|
|
35
|
+
routes?: Record<string, Function>;
|
|
36
|
+
/**
|
|
37
|
+
* Corestore namespace; defaults to `cero`.
|
|
38
|
+
*/
|
|
39
|
+
namespace?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Optional encryption key; falls back to identity's key.
|
|
42
|
+
*/
|
|
43
|
+
encryptionKey?: Uint8Array | null;
|
|
44
|
+
/**
|
|
45
|
+
* Rotation epochs to prime the keyring with (delivered at join).
|
|
46
|
+
*/
|
|
47
|
+
epochs?: Array<{
|
|
48
|
+
epoch: number;
|
|
49
|
+
entropy: Uint8Array;
|
|
50
|
+
}> | null;
|
|
51
|
+
/**
|
|
52
|
+
* Existing autobee key to reopen.
|
|
53
|
+
*/
|
|
54
|
+
key?: Uint8Array | null;
|
|
55
|
+
/**
|
|
56
|
+
* Join discovery server-only (reachable but not searching). Flip at runtime with `setActive`.
|
|
57
|
+
*/
|
|
58
|
+
passive?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* This device's writer keypair; a fresh random one by default. Never the identity's, never the database key.
|
|
61
|
+
*/
|
|
62
|
+
keyPair?: import('../identity/index.js').KeyPair;
|
|
63
|
+
/**
|
|
64
|
+
* Called when a background after-hook or onApply callback fails, a malformed node is skipped, or the bee errors.
|
|
65
|
+
*/
|
|
66
|
+
onerror?: (err: Error) => void;
|
|
67
|
+
};
|
|
68
|
+
export type SingleResult = {
|
|
69
|
+
data: any | null;
|
|
70
|
+
};
|
|
71
|
+
export type ListResult = {
|
|
72
|
+
data: any[];
|
|
73
|
+
total: number | null;
|
|
74
|
+
size: number;
|
|
75
|
+
};
|
|
76
|
+
export type Query = {
|
|
77
|
+
gt?: string;
|
|
78
|
+
gte?: string;
|
|
79
|
+
lt?: string;
|
|
80
|
+
lte?: string;
|
|
81
|
+
reverse?: boolean;
|
|
82
|
+
limit?: number;
|
|
83
|
+
search?: string;
|
|
84
|
+
fields?: string[];
|
|
85
|
+
total?: boolean;
|
|
86
|
+
};
|
|
87
|
+
export type Ref = {
|
|
88
|
+
kind: string;
|
|
89
|
+
verb: string;
|
|
90
|
+
name: string;
|
|
91
|
+
};
|
|
92
|
+
export type HookFn = (ctx: any) => any | Promise<any>;
|
|
1
93
|
/**
|
|
2
94
|
* @typedef {object} DatabaseOpts
|
|
3
95
|
* @property {any} store Corestore (or compatible) used to materialize the autobee.
|
|
@@ -8,10 +100,9 @@
|
|
|
8
100
|
* @property {string} [namespace] Corestore namespace; defaults to `cero`.
|
|
9
101
|
* @property {Uint8Array | null} [encryptionKey] Optional encryption key; falls back to identity's key.
|
|
10
102
|
* @property {Array<{ epoch: number, entropy: Uint8Array }> | null} [epochs] Rotation epochs to prime the keyring with (delivered at join).
|
|
11
|
-
* @property {(nodes: any, view: any, host: any) => Promise<void>} [apply] Override the default apply function.
|
|
12
103
|
* @property {Uint8Array | null} [key] Existing autobee key to reopen.
|
|
13
104
|
* @property {boolean} [passive] Join discovery server-only (reachable but not searching). Flip at runtime with `setActive`.
|
|
14
|
-
* @property {import('../identity/index.js').KeyPair} [keyPair]
|
|
105
|
+
* @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.
|
|
15
106
|
* @property {(err: Error) => void} [onerror] Called when a background after-hook or onApply callback fails, a malformed node is skipped, or the bee errors.
|
|
16
107
|
*
|
|
17
108
|
* @typedef {{ data: any | null }} SingleResult
|
|
@@ -21,16 +112,11 @@
|
|
|
21
112
|
* @typedef {(ctx: any) => any | Promise<any>} HookFn
|
|
22
113
|
*/
|
|
23
114
|
/**
|
|
24
|
-
* Multi-writer database built on Autobee + HyperDB.
|
|
25
|
-
* hyperdispatch-encoded log and exposes a `put/get/...` surface mirroring
|
|
26
|
-
* `Storage`, plus membership ops (claim/addWriter/removeWriter) for the
|
|
27
|
-
* shared writer set.
|
|
115
|
+
* Multi-writer database built on Autobee + HyperDB.
|
|
28
116
|
*/
|
|
29
|
-
export class Database extends ReadyResource {
|
|
30
|
-
/** @param {Partial<DatabaseOpts>} [opts] */
|
|
31
|
-
constructor(opts?: Partial<DatabaseOpts>);
|
|
117
|
+
export declare class Database extends ReadyResource {
|
|
32
118
|
store: any;
|
|
33
|
-
identity:
|
|
119
|
+
identity: Identity;
|
|
34
120
|
network: import("../index.js").Network;
|
|
35
121
|
spec: {
|
|
36
122
|
database: any;
|
|
@@ -56,49 +142,36 @@ export class Database extends ReadyResource {
|
|
|
56
142
|
verb?: string;
|
|
57
143
|
}>;
|
|
58
144
|
version: any;
|
|
59
|
-
behind:
|
|
145
|
+
behind: any;
|
|
60
146
|
routes: Record<string, Function>;
|
|
61
147
|
namespace: string;
|
|
62
148
|
encryptionKey: Uint8Array<ArrayBufferLike>;
|
|
63
149
|
keyring: Keyring;
|
|
64
|
-
|
|
65
|
-
_healTimer: any;
|
|
66
|
-
_healedFor: any;
|
|
67
|
-
applyOverride: (nodes: any, view: any, host: any) => Promise<void>;
|
|
150
|
+
rotation: Rotation;
|
|
68
151
|
key: Uint8Array<ArrayBufferLike>;
|
|
69
152
|
passive: boolean;
|
|
70
|
-
keyPair: import("../index.js").KeyPair
|
|
71
|
-
publicKey: Uint8Array<ArrayBufferLike>;
|
|
72
|
-
secretKey: Uint8Array<ArrayBufferLike>;
|
|
73
|
-
};
|
|
153
|
+
keyPair: import("../index.js").KeyPair;
|
|
74
154
|
_onerror: any;
|
|
75
155
|
bee: EpochAutobee;
|
|
76
156
|
dispatcher: {
|
|
77
|
-
|
|
157
|
+
dispatch: (value: Buffer, ctx: object) => Promise<void>;
|
|
78
158
|
apply: (nodes: Array<{
|
|
79
159
|
value: Buffer;
|
|
80
160
|
key: Buffer;
|
|
81
161
|
}>, view: object, host: object) => Promise<void>;
|
|
82
162
|
};
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
163
|
+
_discovery: import("../network/discovery.js").Discovery;
|
|
164
|
+
_txChain: any;
|
|
165
|
+
_before: Map<any, any>;
|
|
166
|
+
_after: Map<any, any>;
|
|
167
|
+
_updaters: Map<any, any>;
|
|
168
|
+
_observers: Set<any>;
|
|
169
|
+
_verbs: Map<any, any>;
|
|
88
170
|
_touched: Set<any>;
|
|
171
|
+
_seq: number;
|
|
89
172
|
txQueue: any;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
openBee(): Promise<void>;
|
|
93
|
-
_joinSwarm(bee: any, discoveryKey: any): void;
|
|
94
|
-
/**
|
|
95
|
-
* Flip announce mode at runtime — passive stays reachable (server) but
|
|
96
|
-
* stops actively looking (client). Cheap; use it to demote idle rooms.
|
|
97
|
-
*
|
|
98
|
-
* @param {boolean} active
|
|
99
|
-
* @returns {Promise<void>}
|
|
100
|
-
*/
|
|
101
|
-
setActive(active: boolean): Promise<void>;
|
|
173
|
+
/** @param {Partial<DatabaseOpts>} [opts] */
|
|
174
|
+
constructor(opts?: Partial<DatabaseOpts>);
|
|
102
175
|
/** @returns {Uint8Array | null} discovery key of the underlying bee */
|
|
103
176
|
get discoveryKey(): Uint8Array | null;
|
|
104
177
|
/** @returns {Uint8Array | null} this device's local writer key */
|
|
@@ -109,6 +182,16 @@ export class Database extends ReadyResource {
|
|
|
109
182
|
get length(): number;
|
|
110
183
|
/** @returns {object | null} the materialized HyperDB view */
|
|
111
184
|
get view(): object | null;
|
|
185
|
+
_open(): Promise<void>;
|
|
186
|
+
_close(): Promise<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>;
|
|
112
195
|
/**
|
|
113
196
|
* Register a pre-op hook. Returning `false` from `fn` aborts the op.
|
|
114
197
|
*
|
|
@@ -135,10 +218,7 @@ export class Database extends ReadyResource {
|
|
|
135
218
|
*/
|
|
136
219
|
onUpdate(fn: () => void, scope?: string): () => void;
|
|
137
220
|
/**
|
|
138
|
-
* Observe every applied op — local AND replicated (apply processes the merged
|
|
139
|
-
* log). The callback receives `{ op, name, row, writerKey, seq }` and runs
|
|
140
|
-
* synchronously, so it must be cheap and non-blocking (enqueue and return).
|
|
141
|
-
* Gated: zero cost when no subscriber is registered. Returns a disposer.
|
|
221
|
+
* Observe every applied op — local AND replicated (apply processes the merged log).
|
|
142
222
|
*
|
|
143
223
|
* @param {(event: { op: string, name: string, row: any, writerKey: any, seq: number }) => void} fn
|
|
144
224
|
* @returns {() => void} disposer
|
|
@@ -150,22 +230,6 @@ export class Database extends ReadyResource {
|
|
|
150
230
|
writerKey: any;
|
|
151
231
|
seq: number;
|
|
152
232
|
}) => void): () => void;
|
|
153
|
-
/**
|
|
154
|
-
* Run all registered `before:op` hooks and emit the corresponding event.
|
|
155
|
-
*
|
|
156
|
-
* @param {string} op
|
|
157
|
-
* @param {any} ctx
|
|
158
|
-
* @returns {Promise<boolean>} `false` if any hook vetoed the op
|
|
159
|
-
*/
|
|
160
|
-
runBefore(op: string, ctx: any): Promise<boolean>;
|
|
161
|
-
/**
|
|
162
|
-
* Run all registered `after:op` hooks and emit the corresponding event.
|
|
163
|
-
*
|
|
164
|
-
* @param {string} op
|
|
165
|
-
* @param {any} ctx
|
|
166
|
-
* @returns {Promise<void>}
|
|
167
|
-
*/
|
|
168
|
-
runAfter(op: string, ctx: any): Promise<void>;
|
|
169
233
|
/**
|
|
170
234
|
* Insert (or overwrite by id) a row, stamping `id`/`createdAt`/`updatedAt`.
|
|
171
235
|
*
|
|
@@ -175,16 +239,14 @@ export class Database extends ReadyResource {
|
|
|
175
239
|
*/
|
|
176
240
|
put(name: string, row: Record<string, any>): Promise<SingleResult | null>;
|
|
177
241
|
/**
|
|
178
|
-
* Upsert by merging with the existing row, preserving `createdAt`.
|
|
179
|
-
* `{ upsert: false }` to update-only — a missing row is left untouched
|
|
180
|
-
* (checked atomically in the dispatch, so it never resurrects a deleted row).
|
|
242
|
+
* Upsert by merging with the existing row, preserving `createdAt`.
|
|
181
243
|
*
|
|
182
244
|
* @param {string} name
|
|
183
245
|
* @param {Record<string, any>} row
|
|
184
246
|
* @param {{ upsert?: boolean }} [opts]
|
|
185
247
|
* @returns {Promise<SingleResult | null>}
|
|
186
248
|
*/
|
|
187
|
-
set(name: string, row: Record<string, any>,
|
|
249
|
+
set(name: string, row: Record<string, any>, opts?: {
|
|
188
250
|
upsert?: boolean;
|
|
189
251
|
}): Promise<SingleResult | null>;
|
|
190
252
|
/**
|
|
@@ -204,35 +266,23 @@ export class Database extends ReadyResource {
|
|
|
204
266
|
*/
|
|
205
267
|
call(op: string, data?: Record<string, any>): Promise<void>;
|
|
206
268
|
/**
|
|
207
|
-
* Rotate the encryption epoch: generate a fresh 32-byte secret, seal it to
|
|
208
|
-
*
|
|
209
|
-
* The announcement is appended under the current epoch (so every member —
|
|
210
|
-
* even one offline for several rotations — can walk the chain forward),
|
|
211
|
-
* and blocks written after it use the new one. Members absent from the
|
|
212
|
-
* envelope set (removed before the rotation) never learn the new key.
|
|
269
|
+
* Rotate the encryption epoch: generate a fresh 32-byte secret, seal it to every current
|
|
270
|
+
* member's identity key, and announce it through the log.
|
|
213
271
|
*
|
|
214
272
|
* @returns {Promise<{ epoch: number }>}
|
|
215
273
|
*/
|
|
216
|
-
rotate(
|
|
274
|
+
rotate(): Promise<{
|
|
217
275
|
epoch: number;
|
|
218
276
|
}>;
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
* Batch every write made through the transaction handle passed to `fn`
|
|
223
|
-
* into a single autobee append. The handle is this database with its own
|
|
224
|
-
* write queue — same surface (`put`/`set`/`del`/`call`), but writes buffer
|
|
225
|
-
* until `fn` returns, and are discarded if it throws. Writes made on the
|
|
226
|
-
* database itself meanwhile append normally: an unrelated concurrent write
|
|
227
|
-
* can never be swallowed into (and rolled back with) a transaction.
|
|
228
|
-
* Nested `tx()` on the handle joins the same batch.
|
|
277
|
+
/**
|
|
278
|
+
* Batch every write made through the transaction handle passed to `fn` into a single
|
|
279
|
+
* autobee append.
|
|
229
280
|
*
|
|
230
281
|
* @template T
|
|
231
282
|
* @param {(tx: Database) => Promise<T> | T} fn
|
|
232
283
|
* @returns {Promise<T>}
|
|
233
284
|
*/
|
|
234
285
|
tx<T>(fn: (tx: Database) => Promise<T> | T): Promise<T>;
|
|
235
|
-
_txChain: any;
|
|
236
286
|
/**
|
|
237
287
|
* Encode and append dispatch ops. Buffers into the active `tx` queue if one
|
|
238
288
|
* is open.
|
|
@@ -241,17 +291,6 @@ export class Database extends ReadyResource {
|
|
|
241
291
|
* @returns {Promise<void>}
|
|
242
292
|
*/
|
|
243
293
|
write(ops: Array<[string, any]>): Promise<void>;
|
|
244
|
-
/**
|
|
245
|
-
* Validate ops against the committed view before appending: each op runs in
|
|
246
|
-
* a throwaway transaction with host effects stubbed, so a throwing handler
|
|
247
|
-
* rejects the write and nothing enters the permanent log. Permission gates
|
|
248
|
-
* that `return` are not rejections — apply stays the authority at
|
|
249
|
-
* linearization time.
|
|
250
|
-
*
|
|
251
|
-
* @param {Uint8Array[]} encoded
|
|
252
|
-
* @returns {Promise<boolean>} whether the ops change anything
|
|
253
|
-
*/
|
|
254
|
-
_dryRun(encoded: Uint8Array[]): Promise<boolean>;
|
|
255
294
|
/**
|
|
256
295
|
* Read a row. With no `query`: list all (collection) or fetch the one
|
|
257
296
|
* record (single). With a string id: fetch that specific row.
|
|
@@ -261,9 +300,6 @@ export class Database extends ReadyResource {
|
|
|
261
300
|
* @returns {Promise<SingleResult | ListResult>}
|
|
262
301
|
*/
|
|
263
302
|
get(name: string, query?: string | Query): Promise<SingleResult | ListResult>;
|
|
264
|
-
_orderReady(name: any, col: any): Promise<any>;
|
|
265
|
-
_orderOk: Map<any, any>;
|
|
266
|
-
_total(col: any, query: any, rows: any): Promise<any>;
|
|
267
303
|
/**
|
|
268
304
|
* Number of rows that match `query` (or total if omitted).
|
|
269
305
|
*
|
|
@@ -282,50 +318,45 @@ export class Database extends ReadyResource {
|
|
|
282
318
|
* @param {Query} [query]
|
|
283
319
|
* @returns {import('streamx').Readable}
|
|
284
320
|
*/
|
|
285
|
-
watch(name: string, query?: Query): import(
|
|
321
|
+
watch(name: string, query?: Query): import('streamx').Readable;
|
|
286
322
|
/**
|
|
287
|
-
* Delta subscription: batches of `{ prev, next }` row pairs instead of
|
|
288
|
-
* full snapshots. The first batch (and any batch after a view swap) carries
|
|
289
|
-
* the current matching rows as inserts with `reset: true` — replaying every
|
|
290
|
-
* batch into a Map keyed by row id always reconstructs current state.
|
|
291
|
-
* `limit`/`reverse` are not applied; deltas are unwindowed by design.
|
|
323
|
+
* Delta subscription: batches of `{ prev, next }` row pairs instead of full snapshots.
|
|
292
324
|
*
|
|
293
325
|
* @param {string} name
|
|
294
326
|
* @param {Query} [query]
|
|
295
327
|
* @returns {import('streamx').Readable}
|
|
296
328
|
*/
|
|
297
|
-
changes(name: string, query?: Query): import(
|
|
329
|
+
changes(name: string, query?: Query): import('streamx').Readable;
|
|
298
330
|
/**
|
|
299
|
-
*
|
|
331
|
+
* Provision this device. Its writer core was minted when the database opened and this
|
|
332
|
+
* device is its only author, ever.
|
|
300
333
|
*
|
|
301
|
-
* @param {{ name?: string | null, isMobile?: boolean, recovering?: boolean }} [opts]
|
|
334
|
+
* @param {{ name?: string | null, isMobile?: boolean, recovering?: boolean, timeout?: number }} [opts]
|
|
302
335
|
* @returns {Promise<{ id: Uint8Array, writer: import('../identity/index.js').KeyPair }>}
|
|
303
336
|
*/
|
|
304
|
-
bootstrap(
|
|
337
|
+
bootstrap({ name, isMobile, recovering, timeout }?: {
|
|
305
338
|
name?: string | null;
|
|
306
339
|
isMobile?: boolean;
|
|
307
340
|
recovering?: boolean;
|
|
341
|
+
timeout?: number;
|
|
308
342
|
}): Promise<{
|
|
309
343
|
id: Uint8Array;
|
|
310
|
-
writer: import(
|
|
344
|
+
writer: import('../identity/index.js').KeyPair;
|
|
311
345
|
}>;
|
|
312
346
|
/**
|
|
313
|
-
* Claim writership on an existing room by signing our writer key with the
|
|
314
|
-
*
|
|
315
|
-
* Admission only — the device is named separately (bootstrap → set-device).
|
|
347
|
+
* Claim writership on an existing room by signing our writer key with the member identity;
|
|
348
|
+
* the claim rides in the device core as an optimistic node.
|
|
316
349
|
*
|
|
317
350
|
* @returns {Promise<void>}
|
|
318
351
|
*/
|
|
319
352
|
claim(): Promise<void>;
|
|
320
|
-
/** The claim-writer op for this device, signed by the member identity. */
|
|
321
|
-
claimOp(): any;
|
|
322
353
|
/**
|
|
323
354
|
* Resolve once the bee becomes writable, or reject after `timeout` ms.
|
|
324
355
|
*
|
|
325
356
|
* @param {{ timeout?: number }} [opts]
|
|
326
357
|
* @returns {Promise<void>}
|
|
327
358
|
*/
|
|
328
|
-
whenWritable(
|
|
359
|
+
whenWritable({ timeout }?: {
|
|
329
360
|
timeout?: number;
|
|
330
361
|
}): Promise<void>;
|
|
331
362
|
/**
|
|
@@ -362,118 +393,62 @@ export class Database extends ReadyResource {
|
|
|
362
393
|
* @returns {string}
|
|
363
394
|
*/
|
|
364
395
|
col(ref: Ref): string;
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
396
|
+
_preload(): Promise<void>;
|
|
397
|
+
_boot(): Promise<void>;
|
|
398
|
+
_replay(): Promise<boolean>;
|
|
399
|
+
_isTrusted(writer: any, view: any): Promise<any>;
|
|
400
|
+
_apply(nodes: any, view: any, host: any): Promise<void>;
|
|
401
|
+
_update(db: any): Promise<void>;
|
|
402
|
+
_joinSwarm(bee: any, discoveryKey: any): void;
|
|
403
|
+
_runBefore(op: any, ctx: any): Promise<boolean>;
|
|
404
|
+
_runAfter(op: any, ctx: any): Promise<void>;
|
|
405
|
+
_opOf(node: any): {
|
|
406
|
+
op: any;
|
|
407
|
+
name: any;
|
|
408
|
+
value: any;
|
|
409
|
+
};
|
|
410
|
+
_notify(nodes: any): void;
|
|
411
|
+
_merge(name: any, row: any, { upsert }?: {
|
|
412
|
+
upsert?: boolean;
|
|
413
|
+
}): Promise<{
|
|
414
|
+
op: any;
|
|
415
|
+
name: any;
|
|
416
|
+
row: any;
|
|
417
|
+
}>;
|
|
418
|
+
_prepare(name: any, row: any): Ref;
|
|
419
|
+
_append(op: any, name: any, stored: any, verb: any): Promise<{
|
|
420
|
+
op: any;
|
|
421
|
+
name: any;
|
|
422
|
+
row: any;
|
|
423
|
+
}>;
|
|
424
|
+
_done(op: any, ctx: any): Promise<{
|
|
425
|
+
data: any;
|
|
426
|
+
}>;
|
|
427
|
+
_onfuture(version: any): void;
|
|
428
|
+
_dryRun(encoded: any): Promise<any>;
|
|
429
|
+
_plan(name: any, query?: {}): {
|
|
374
430
|
path: string;
|
|
375
431
|
range: {
|
|
376
|
-
gte:
|
|
377
|
-
lte:
|
|
378
|
-
};
|
|
379
|
-
} | null;
|
|
380
|
-
_write(verb: any, hook: any, publicKey: any): Promise<void>;
|
|
381
|
-
}
|
|
382
|
-
export type DatabaseOpts = {
|
|
383
|
-
/**
|
|
384
|
-
* Corestore (or compatible) used to materialize the autobee.
|
|
385
|
-
*/
|
|
386
|
-
store: any;
|
|
387
|
-
/**
|
|
388
|
-
* Long-lived member identity used to sign writer changes.
|
|
389
|
-
*/
|
|
390
|
-
identity: import("../identity/index.js").Identity;
|
|
391
|
-
/**
|
|
392
|
-
* Optional swarm; required for multi-writer replication.
|
|
393
|
-
*/
|
|
394
|
-
network?: import("../network/index.js").Network;
|
|
395
|
-
/**
|
|
396
|
-
* Generated hyperdb + hyperdispatch spec.
|
|
397
|
-
*/
|
|
398
|
-
spec: {
|
|
399
|
-
database: any;
|
|
400
|
-
dispatch: any;
|
|
401
|
-
meta?: {
|
|
402
|
-
ns?: string;
|
|
403
|
-
refs?: Record<string, {
|
|
404
|
-
kind?: string;
|
|
405
|
-
verb?: string;
|
|
406
|
-
}>;
|
|
432
|
+
gte: {};
|
|
433
|
+
lte: {};
|
|
407
434
|
};
|
|
435
|
+
rest: {};
|
|
436
|
+
sorted: boolean;
|
|
437
|
+
} | {
|
|
438
|
+
path: string;
|
|
439
|
+
range: {};
|
|
440
|
+
rest: {};
|
|
441
|
+
sorted: boolean;
|
|
408
442
|
};
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
/**
|
|
422
|
-
* Rotation epochs to prime the keyring with (delivered at join).
|
|
423
|
-
*/
|
|
424
|
-
epochs?: Array<{
|
|
425
|
-
epoch: number;
|
|
426
|
-
entropy: Uint8Array;
|
|
427
|
-
}> | null;
|
|
428
|
-
/**
|
|
429
|
-
* Override the default apply function.
|
|
430
|
-
*/
|
|
431
|
-
apply?: (nodes: any, view: any, host: any) => Promise<void>;
|
|
432
|
-
/**
|
|
433
|
-
* Existing autobee key to reopen.
|
|
434
|
-
*/
|
|
435
|
-
key?: Uint8Array | null;
|
|
436
|
-
/**
|
|
437
|
-
* Join discovery server-only (reachable but not searching). Flip at runtime with `setActive`.
|
|
438
|
-
*/
|
|
439
|
-
passive?: boolean;
|
|
440
|
-
/**
|
|
441
|
-
* Device writer keypair; defaults to identity's keypair.
|
|
442
|
-
*/
|
|
443
|
-
keyPair?: import("../identity/index.js").KeyPair;
|
|
444
|
-
/**
|
|
445
|
-
* Called when a background after-hook or onApply callback fails, a malformed node is skipped, or the bee errors.
|
|
446
|
-
*/
|
|
447
|
-
onerror?: (err: Error) => void;
|
|
448
|
-
};
|
|
449
|
-
export type SingleResult = {
|
|
450
|
-
data: any | null;
|
|
451
|
-
};
|
|
452
|
-
/**
|
|
453
|
-
* `total` is null when a limited read skipped the full count — pass `{ total: true }` to force it.
|
|
454
|
-
*/
|
|
455
|
-
export type ListResult = {
|
|
456
|
-
data: any[];
|
|
457
|
-
total: number | null;
|
|
458
|
-
size: number;
|
|
459
|
-
};
|
|
460
|
-
export type Query = {
|
|
461
|
-
gt?: string;
|
|
462
|
-
gte?: string;
|
|
463
|
-
lt?: string;
|
|
464
|
-
lte?: string;
|
|
465
|
-
reverse?: boolean;
|
|
466
|
-
limit?: number;
|
|
467
|
-
search?: string;
|
|
468
|
-
fields?: string[];
|
|
469
|
-
total?: boolean;
|
|
470
|
-
};
|
|
471
|
-
export type Ref = {
|
|
472
|
-
kind: string;
|
|
473
|
-
verb: string;
|
|
474
|
-
name: string;
|
|
475
|
-
};
|
|
476
|
-
export type HookFn = (ctx: any) => any | Promise<any>;
|
|
477
|
-
import ReadyResource from 'ready-resource';
|
|
478
|
-
import { Keyring } from './encryption.js';
|
|
479
|
-
import { EpochAutobee } from './encryption.js';
|
|
443
|
+
_total(path: any, range: any, rows: any, query: any): Promise<any>;
|
|
444
|
+
_optimistic(op: any, opts: any): Promise<void>;
|
|
445
|
+
_backfilled(timeout: any): Promise<void>;
|
|
446
|
+
_admission(writer: any, ts?: number): {
|
|
447
|
+
master: Uint8Array<ArrayBufferLike>;
|
|
448
|
+
writer: any;
|
|
449
|
+
sig: Uint8Array<ArrayBufferLike>;
|
|
450
|
+
ts: number;
|
|
451
|
+
};
|
|
452
|
+
_checkFields(name: any, row: any): void;
|
|
453
|
+
_admit(verb: any, hook: any, publicKey: any): Promise<void>;
|
|
454
|
+
}
|
|
@@ -1,32 +1,49 @@
|
|
|
1
|
-
export function rotate(db: any, retried?: boolean): Promise<any>;
|
|
2
1
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* simply stop here — every block after the announcement is noise to them.
|
|
6
|
-
* Our own in-flight rotation is deferred to `rotate()` (see above).
|
|
7
|
-
*
|
|
8
|
-
* @param {import('./index.js').Database} db
|
|
9
|
-
* @param {{ epoch: number, wrapped: Uint8Array, createdAt: number }} row
|
|
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.
|
|
10
4
|
*/
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
5
|
+
export declare class Rotation {
|
|
6
|
+
db: import("./index.js").Database;
|
|
7
|
+
current: {
|
|
8
|
+
entropy: Uint8Array<ArrayBufferLike>;
|
|
9
|
+
stamp: any;
|
|
10
|
+
epoch: number;
|
|
11
|
+
};
|
|
12
|
+
_timer: number;
|
|
13
|
+
_healedFor: any;
|
|
14
|
+
/** @param {import('./index.js').Database} db */
|
|
15
|
+
constructor(db: import('./index.js').Database);
|
|
16
|
+
close(): void;
|
|
17
|
+
/** @returns {Promise<{ epoch: number }>} */
|
|
18
|
+
rotate(): Promise<{
|
|
19
|
+
epoch: number;
|
|
20
|
+
}>;
|
|
21
|
+
/**
|
|
22
|
+
* An applied rotation announcement: open our envelope, learn the secret, persist it.
|
|
23
|
+
*
|
|
24
|
+
* @param {{ epoch: number, stamp: number, wrapped: Uint8Array, commit: Uint8Array }} row
|
|
25
|
+
*/
|
|
26
|
+
learn(row: {
|
|
27
|
+
epoch: number;
|
|
28
|
+
stamp: number;
|
|
29
|
+
wrapped: Uint8Array;
|
|
30
|
+
commit: Uint8Array;
|
|
31
|
+
}): Promise<void>;
|
|
32
|
+
/**
|
|
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.
|
|
35
|
+
*/
|
|
36
|
+
hydrate(): Promise<void>;
|
|
37
|
+
/** Debounced audit, run after every update. */
|
|
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;
|
|
48
|
+
_audit(): Promise<void>;
|
|
49
|
+
}
|