@cero-base/core 1.19.0 → 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/package.json +8 -5
- package/src/blobs/index.js +15 -15
- package/src/blobs/server.js +0 -2
- package/src/database/changes.js +3 -7
- package/src/database/dispatch.js +128 -203
- package/src/database/encryption.js +22 -52
- package/src/database/envelope.js +1 -3
- package/src/database/index.js +336 -387
- 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 +138 -166
- 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 +25 -31
- 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 +2 -6
- package/types/database/encryption.d.ts +8 -20
- package/types/database/index.d.ts +79 -96
- 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 +16 -26
- 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 -20
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
|
-
*
|
|
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
|
|
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
|
|
package/src/storage/index.js
CHANGED
|
@@ -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
|
-
*
|
|
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`.
|
|
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
|
|
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,8 +193,7 @@ 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
|
|
222
|
-
// `data` is already everything — skip the second scan.
|
|
196
|
+
// a limit caps data, so total needs a full count
|
|
223
197
|
const filtered = query && Object.keys(query).length > 0
|
|
224
198
|
const total = filtered ? (await this.db.find(col, {}).toArray()).length : data.length
|
|
225
199
|
return { data, total, size: data.length }
|
|
@@ -294,6 +268,26 @@ export class Storage extends ReadyResource {
|
|
|
294
268
|
await this.db.insert(this._col(ref), row)
|
|
295
269
|
await this.db.flush()
|
|
296
270
|
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Construct a RocksDB-backed Storage.
|
|
274
|
+
*
|
|
275
|
+
* @param {string} dir
|
|
276
|
+
* @param {Omit<StorageOpts, 'backend'>} opts
|
|
277
|
+
*/
|
|
278
|
+
static rocks(dir, opts) {
|
|
279
|
+
return new Storage(dir, { ...opts, backend: ROCKS })
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Construct a Hyperbee-backed Storage.
|
|
284
|
+
*
|
|
285
|
+
* @param {string} dir
|
|
286
|
+
* @param {Omit<StorageOpts, 'backend'>} opts
|
|
287
|
+
*/
|
|
288
|
+
static bee(dir, opts) {
|
|
289
|
+
return new Storage(dir, { ...opts, backend: BEE })
|
|
290
|
+
}
|
|
297
291
|
}
|
|
298
292
|
|
|
299
293
|
// hyperdb bounds are records, a bare id must be wrapped
|
package/types/blobs/index.d.ts
CHANGED
|
@@ -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 };
|
package/types/blobs/server.d.ts
CHANGED
|
@@ -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
|
-
*
|
|
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,7 +9,7 @@ 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 {{
|
|
12
|
+
* @returns {{ dispatch: (value: Buffer, ctx: object) => Promise<void>, apply: (nodes: Array<{ value: Buffer, key: Buffer }>, view: object, host: object) => Promise<void> }}
|
|
17
13
|
*/
|
|
18
14
|
export declare function makeDispatcher({ spec, ns, routes, onerror, key, onepoch }: {
|
|
19
15
|
spec: {
|
|
@@ -39,7 +35,7 @@ export declare function makeDispatcher({ spec, ns, routes, onerror, key, onepoch
|
|
|
39
35
|
commit: Uint8Array;
|
|
40
36
|
}) => Promise<void>;
|
|
41
37
|
}): {
|
|
42
|
-
|
|
38
|
+
dispatch: (value: Buffer, ctx: object) => Promise<void>;
|
|
43
39
|
apply: (nodes: Array<{
|
|
44
40
|
value: Buffer;
|
|
45
41
|
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.
|
|
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.
|
|
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
|
-
*
|
|
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
|
-
*
|
|
89
|
-
*
|
|
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 {};
|
|
@@ -112,10 +112,7 @@ export type HookFn = (ctx: any) => any | Promise<any>;
|
|
|
112
112
|
* @typedef {(ctx: any) => any | Promise<any>} HookFn
|
|
113
113
|
*/
|
|
114
114
|
/**
|
|
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.
|
|
115
|
+
* Multi-writer database built on Autobee + HyperDB.
|
|
119
116
|
*/
|
|
120
117
|
export declare class Database extends ReadyResource {
|
|
121
118
|
store: any;
|
|
@@ -157,7 +154,7 @@ export declare class Database extends ReadyResource {
|
|
|
157
154
|
_onerror: any;
|
|
158
155
|
bee: EpochAutobee;
|
|
159
156
|
dispatcher: {
|
|
160
|
-
|
|
157
|
+
dispatch: (value: Buffer, ctx: object) => Promise<void>;
|
|
161
158
|
apply: (nodes: Array<{
|
|
162
159
|
value: Buffer;
|
|
163
160
|
key: Buffer;
|
|
@@ -175,23 +172,6 @@ export declare class Database extends ReadyResource {
|
|
|
175
172
|
txQueue: any;
|
|
176
173
|
/** @param {Partial<DatabaseOpts>} [opts] */
|
|
177
174
|
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
175
|
/** @returns {Uint8Array | null} discovery key of the underlying bee */
|
|
196
176
|
get discoveryKey(): Uint8Array | null;
|
|
197
177
|
/** @returns {Uint8Array | null} this device's local writer key */
|
|
@@ -202,6 +182,16 @@ export declare class Database extends ReadyResource {
|
|
|
202
182
|
get length(): number;
|
|
203
183
|
/** @returns {object | null} the materialized HyperDB view */
|
|
204
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>;
|
|
205
195
|
/**
|
|
206
196
|
* Register a pre-op hook. Returning `false` from `fn` aborts the op.
|
|
207
197
|
*
|
|
@@ -228,10 +218,7 @@ export declare class Database extends ReadyResource {
|
|
|
228
218
|
*/
|
|
229
219
|
onUpdate(fn: () => void, scope?: string): () => void;
|
|
230
220
|
/**
|
|
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.
|
|
221
|
+
* Observe every applied op — local AND replicated (apply processes the merged log).
|
|
235
222
|
*
|
|
236
223
|
* @param {(event: { op: string, name: string, row: any, writerKey: any, seq: number }) => void} fn
|
|
237
224
|
* @returns {() => void} disposer
|
|
@@ -243,15 +230,6 @@ export declare class Database extends ReadyResource {
|
|
|
243
230
|
writerKey: any;
|
|
244
231
|
seq: number;
|
|
245
232
|
}) => 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
233
|
/**
|
|
256
234
|
* Insert (or overwrite by id) a row, stamping `id`/`createdAt`/`updatedAt`.
|
|
257
235
|
*
|
|
@@ -261,9 +239,7 @@ export declare class Database extends ReadyResource {
|
|
|
261
239
|
*/
|
|
262
240
|
put(name: string, row: Record<string, any>): Promise<SingleResult | null>;
|
|
263
241
|
/**
|
|
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).
|
|
242
|
+
* Upsert by merging with the existing row, preserving `createdAt`.
|
|
267
243
|
*
|
|
268
244
|
* @param {string} name
|
|
269
245
|
* @param {Record<string, any>} row
|
|
@@ -273,13 +249,6 @@ export declare class Database extends ReadyResource {
|
|
|
273
249
|
set(name: string, row: Record<string, any>, opts?: {
|
|
274
250
|
upsert?: boolean;
|
|
275
251
|
}): 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
252
|
/**
|
|
284
253
|
* Delete by id (collection) or wipe the whole single-row table.
|
|
285
254
|
*
|
|
@@ -297,27 +266,17 @@ export declare class Database extends ReadyResource {
|
|
|
297
266
|
*/
|
|
298
267
|
call(op: string, data?: Record<string, any>): Promise<void>;
|
|
299
268
|
/**
|
|
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.
|
|
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.
|
|
306
271
|
*
|
|
307
272
|
* @returns {Promise<{ epoch: number }>}
|
|
308
273
|
*/
|
|
309
274
|
rotate(): Promise<{
|
|
310
275
|
epoch: number;
|
|
311
276
|
}>;
|
|
312
|
-
_onfuture(version: any): void;
|
|
313
277
|
/**
|
|
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.
|
|
278
|
+
* Batch every write made through the transaction handle passed to `fn` into a single
|
|
279
|
+
* autobee append.
|
|
321
280
|
*
|
|
322
281
|
* @template T
|
|
323
282
|
* @param {(tx: Database) => Promise<T> | T} fn
|
|
@@ -332,7 +291,6 @@ export declare class Database extends ReadyResource {
|
|
|
332
291
|
* @returns {Promise<void>}
|
|
333
292
|
*/
|
|
334
293
|
write(ops: Array<[string, any]>): Promise<void>;
|
|
335
|
-
_dryRun(encoded: any): Promise<any>;
|
|
336
294
|
/**
|
|
337
295
|
* Read a row. With no `query`: list all (collection) or fetch the one
|
|
338
296
|
* record (single). With a string id: fetch that specific row.
|
|
@@ -342,21 +300,6 @@ export declare class Database extends ReadyResource {
|
|
|
342
300
|
* @returns {Promise<SingleResult | ListResult>}
|
|
343
301
|
*/
|
|
344
302
|
get(name: string, query?: string | Query): Promise<SingleResult | ListResult>;
|
|
345
|
-
_plan(name: any, query?: {}): {
|
|
346
|
-
path: string;
|
|
347
|
-
range: {
|
|
348
|
-
gte: {};
|
|
349
|
-
lte: {};
|
|
350
|
-
};
|
|
351
|
-
rest: {};
|
|
352
|
-
sorted: boolean;
|
|
353
|
-
} | {
|
|
354
|
-
path: string;
|
|
355
|
-
range: {};
|
|
356
|
-
rest: {};
|
|
357
|
-
sorted: boolean;
|
|
358
|
-
};
|
|
359
|
-
_total(path: any, range: any, rows: any, query: any): Promise<any>;
|
|
360
303
|
/**
|
|
361
304
|
* Number of rows that match `query` (or total if omitted).
|
|
362
305
|
*
|
|
@@ -377,11 +320,7 @@ export declare class Database extends ReadyResource {
|
|
|
377
320
|
*/
|
|
378
321
|
watch(name: string, query?: Query): import('streamx').Readable;
|
|
379
322
|
/**
|
|
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.
|
|
323
|
+
* Delta subscription: batches of `{ prev, next }` row pairs instead of full snapshots.
|
|
385
324
|
*
|
|
386
325
|
* @param {string} name
|
|
387
326
|
* @param {Query} [query]
|
|
@@ -389,11 +328,8 @@ export declare class Database extends ReadyResource {
|
|
|
389
328
|
*/
|
|
390
329
|
changes(name: string, query?: Query): import('streamx').Readable;
|
|
391
330
|
/**
|
|
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.
|
|
331
|
+
* Provision this device. Its writer core was minted when the database opened and this
|
|
332
|
+
* device is its only author, ever.
|
|
397
333
|
*
|
|
398
334
|
* @param {{ name?: string | null, isMobile?: boolean, recovering?: boolean, timeout?: number }} [opts]
|
|
399
335
|
* @returns {Promise<{ id: Uint8Array, writer: import('../identity/index.js').KeyPair }>}
|
|
@@ -408,9 +344,8 @@ export declare class Database extends ReadyResource {
|
|
|
408
344
|
writer: import('../identity/index.js').KeyPair;
|
|
409
345
|
}>;
|
|
410
346
|
/**
|
|
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).
|
|
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.
|
|
414
349
|
*
|
|
415
350
|
* @returns {Promise<void>}
|
|
416
351
|
*/
|
|
@@ -438,14 +373,6 @@ export declare class Database extends ReadyResource {
|
|
|
438
373
|
* @returns {Promise<void>}
|
|
439
374
|
*/
|
|
440
375
|
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
376
|
/**
|
|
450
377
|
* Throw if the handle is closing/closed or the bee isn't ready yet.
|
|
451
378
|
*
|
|
@@ -466,6 +393,62 @@ export declare class Database extends ReadyResource {
|
|
|
466
393
|
* @returns {string}
|
|
467
394
|
*/
|
|
468
395
|
col(ref: Ref): string;
|
|
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?: {}): {
|
|
430
|
+
path: string;
|
|
431
|
+
range: {
|
|
432
|
+
gte: {};
|
|
433
|
+
lte: {};
|
|
434
|
+
};
|
|
435
|
+
rest: {};
|
|
436
|
+
sorted: boolean;
|
|
437
|
+
} | {
|
|
438
|
+
path: string;
|
|
439
|
+
range: {};
|
|
440
|
+
rest: {};
|
|
441
|
+
sorted: boolean;
|
|
442
|
+
};
|
|
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
|
+
};
|
|
469
452
|
_checkFields(name: any, row: any): void;
|
|
470
453
|
_admit(verb: any, hook: any, publicKey: any): Promise<void>;
|
|
471
454
|
}
|
|
@@ -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
|