@cero-base/cero 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 +38 -643
- package/package.json +9 -6
- package/src/build/index.js +63 -61
- package/src/build/internal.js +123 -0
- package/src/build/schemas.js +6 -11
- package/src/extensions/handle-sync.js +3 -11
- package/src/extensions/index.js +86 -0
- package/src/extensions/profile-sync.js +15 -16
- package/src/handle/index.js +290 -284
- package/src/index.js +24 -81
- package/src/lib/bluetooth.js +25 -56
- package/src/lib/constants.js +0 -15
- package/src/lib/operators.js +35 -134
- package/src/lib/peek.js +4 -8
- package/src/lib/refs.js +10 -8
- package/src/lib/spec.js +2 -3
- package/src/local/index.js +2 -3
- package/src/rpc/client.js +54 -77
- package/src/rpc/index.js +3 -3
- package/src/rpc/server.js +40 -43
- package/types/build/index.d.ts +11 -9
- package/types/build/{builtins.d.ts → internal.d.ts} +20 -38
- package/types/build/schemas.d.ts +4 -3
- package/types/extensions/handle-sync.d.ts +2 -8
- package/types/extensions/index.d.ts +102 -0
- package/types/extensions/profile-sync.d.ts +0 -5
- package/types/handle/index.d.ts +90 -108
- package/types/index.d.ts +21 -17
- package/types/lib/bluetooth.d.ts +8 -32
- package/types/lib/constants.d.ts +0 -11
- package/types/lib/operators.d.ts +30 -83
- package/types/lib/peek.d.ts +2 -3
- package/types/lib/refs.d.ts +5 -5
- package/types/lib/spec.d.ts +2 -3
- package/types/local/index.d.ts +2 -3
- package/types/rpc/client.d.ts +29 -26
- package/types/rpc/index.d.ts +3 -3
- package/types/rpc/server.d.ts +7 -10
- package/src/build/builtins.js +0 -174
- package/src/lib/internal.js +0 -9
- package/types/lib/internal.d.ts +0 -24
package/types/handle/index.d.ts
CHANGED
|
@@ -74,10 +74,6 @@ export type HandleOpts = {
|
|
|
74
74
|
* Writer keypair.
|
|
75
75
|
*/
|
|
76
76
|
keyPair?: KeyPair;
|
|
77
|
-
/**
|
|
78
|
-
* Join discovery server-only; flip later with `setActive`.
|
|
79
|
-
*/
|
|
80
|
-
passive?: boolean;
|
|
81
77
|
/**
|
|
82
78
|
* When `false`, skips creating a `Pairing` session.
|
|
83
79
|
*/
|
|
@@ -148,7 +144,6 @@ export type CeroHandle = Handle & Record<string, import('../lib/refs.js').Ref>;
|
|
|
148
144
|
* @property {Array<{ epoch: number, entropy: Uint8Array }>} [epochs] Rotation epochs delivered at join.
|
|
149
145
|
* @property {string} [namespace] Corestore namespace.
|
|
150
146
|
* @property {KeyPair} [keyPair] Writer keypair.
|
|
151
|
-
* @property {boolean} [passive] Join discovery server-only; flip later with `setActive`.
|
|
152
147
|
* @property {boolean} [pair] When `false`, skips creating a `Pairing` session.
|
|
153
148
|
*
|
|
154
149
|
* @typedef {object} CreateChildOpts
|
|
@@ -186,10 +181,6 @@ export type CeroHandle = Handle & Record<string, import('../lib/refs.js').Ref>;
|
|
|
186
181
|
*/
|
|
187
182
|
/**
|
|
188
183
|
* A cero handle — a single writable database session attached to a swarm.
|
|
189
|
-
* The "root" handle is the user's facade; child handles (created via
|
|
190
|
-
* `_create`/`_join`/`_load`) live under it and share the same identity,
|
|
191
|
-
* network and corestore. Ref properties (`profile`, `members`, ...) are
|
|
192
|
-
* attached dynamically per the schema; child handles also carry a `name`.
|
|
193
184
|
*/
|
|
194
185
|
export declare class Handle extends ReadyResource {
|
|
195
186
|
identity: any;
|
|
@@ -201,8 +192,11 @@ export declare class Handle extends ReadyResource {
|
|
|
201
192
|
_discovery: any;
|
|
202
193
|
_dir: string;
|
|
203
194
|
_opts: any;
|
|
195
|
+
extensions: any;
|
|
196
|
+
operators: any;
|
|
204
197
|
_onerror: any;
|
|
205
198
|
children: Set<any>;
|
|
199
|
+
_typeHooks: Set<any>;
|
|
206
200
|
_loading: Map<any, any>;
|
|
207
201
|
_joining: Map<any, any>;
|
|
208
202
|
_coreKeys: Map<any, any>;
|
|
@@ -214,16 +208,47 @@ export declare class Handle extends ReadyResource {
|
|
|
214
208
|
store: Database;
|
|
215
209
|
pair: Pairing;
|
|
216
210
|
_wantsPair: boolean;
|
|
217
|
-
_invitesSync: () => Promise<void>;
|
|
218
211
|
_ac: AbortController;
|
|
212
|
+
_invitesSync: (touched: any) => void;
|
|
219
213
|
/** @param {HandleOpts} [opts] */
|
|
220
214
|
constructor(opts?: HandleOpts);
|
|
215
|
+
/**
|
|
216
|
+
* An `AbortSignal` that fires when this handle closes.
|
|
217
|
+
*
|
|
218
|
+
* @returns {AbortSignal}
|
|
219
|
+
*/
|
|
220
|
+
get signal(): AbortSignal;
|
|
221
|
+
/** The top-most handle in the parent chain — itself for a root handle. */
|
|
222
|
+
get root(): this;
|
|
223
|
+
/**
|
|
224
|
+
* Lazily-built file server for this identity. Root-only — child handles
|
|
225
|
+
* reach it through `this.root.fileServer`.
|
|
226
|
+
*
|
|
227
|
+
* @returns {FileServer}
|
|
228
|
+
*/
|
|
229
|
+
get fileServer(): FileServer;
|
|
230
|
+
/**
|
|
231
|
+
* Lazily-built blob store for THIS handle's writing device, at the current rotation epoch.
|
|
232
|
+
*
|
|
233
|
+
* @returns {Blobs}
|
|
234
|
+
*/
|
|
235
|
+
get blobs(): Blobs;
|
|
236
|
+
/** The handle type of a child, null on the root. */
|
|
237
|
+
get type(): any;
|
|
238
|
+
/** Canonical id — identity id for the root handle, store key for children. */
|
|
239
|
+
get id(): any;
|
|
240
|
+
/** This device's id + name. `null` on child handles. */
|
|
241
|
+
get device(): {
|
|
242
|
+
id: any;
|
|
243
|
+
name: any;
|
|
244
|
+
};
|
|
245
|
+
get suspended(): boolean;
|
|
221
246
|
_open(): Promise<void>;
|
|
222
247
|
_close(): Promise<void>;
|
|
223
248
|
/**
|
|
224
|
-
* Tie a destroyable resource (a `watch` stream, a timer, any `{ destroy }`)
|
|
225
|
-
*
|
|
226
|
-
*
|
|
249
|
+
* Tie a destroyable resource (a `watch` stream, a timer, any `{ destroy }`) to this
|
|
250
|
+
* handle's lifecycle — it's destroyed automatically on close, so callers don't track
|
|
251
|
+
* cleanup.
|
|
227
252
|
*
|
|
228
253
|
* @template {{ destroy?: Function, once?: Function }} T
|
|
229
254
|
* @param {T} resource
|
|
@@ -233,14 +258,6 @@ export declare class Handle extends ReadyResource {
|
|
|
233
258
|
destroy?: Function;
|
|
234
259
|
once?: Function;
|
|
235
260
|
}>(resource: T): T;
|
|
236
|
-
/**
|
|
237
|
-
* An `AbortSignal` that fires when this handle closes. Pass it as
|
|
238
|
-
* `{ signal }` to `on`/`after`/`before`/`watch` to drop a subscription on
|
|
239
|
-
* close — or use your own `AbortController` for a finer scope.
|
|
240
|
-
*
|
|
241
|
-
* @returns {AbortSignal}
|
|
242
|
-
*/
|
|
243
|
-
get signal(): AbortSignal;
|
|
244
261
|
/**
|
|
245
262
|
* `EventEmitter.on` plus an optional `{ signal }` that removes the listener
|
|
246
263
|
* when the signal aborts — e.g. `me.on('handle', fn, { signal: me.signal })`.
|
|
@@ -253,24 +270,6 @@ export declare class Handle extends ReadyResource {
|
|
|
253
270
|
on(event: string, fn: (...args: any[]) => void, opts?: {
|
|
254
271
|
signal?: AbortSignal;
|
|
255
272
|
}): this;
|
|
256
|
-
/** The top-most handle in the parent chain — itself for a root handle. */
|
|
257
|
-
get root(): this;
|
|
258
|
-
/**
|
|
259
|
-
* Lazily-built file server for this identity. Root-only — child handles
|
|
260
|
-
* reach it through `this.root.fileServer`.
|
|
261
|
-
*
|
|
262
|
-
* @returns {FileServer}
|
|
263
|
-
*/
|
|
264
|
-
get fileServer(): FileServer;
|
|
265
|
-
/**
|
|
266
|
-
* @param {Uint8Array} coreKey
|
|
267
|
-
* @param {object} info
|
|
268
|
-
* @returns {{ key: Uint8Array, encryptionKey: Uint8Array } | null}
|
|
269
|
-
*/
|
|
270
|
-
_resolveCore(coreKey: Uint8Array, info: object): {
|
|
271
|
-
key: Uint8Array;
|
|
272
|
-
encryptionKey: Uint8Array;
|
|
273
|
-
} | null;
|
|
274
273
|
/**
|
|
275
274
|
* Resolve a durable file id to an ephemeral download url via this identity's
|
|
276
275
|
* file server.
|
|
@@ -279,38 +278,6 @@ export declare class Handle extends ReadyResource {
|
|
|
279
278
|
* @returns {string}
|
|
280
279
|
*/
|
|
281
280
|
getLink(id: string): string;
|
|
282
|
-
/**
|
|
283
|
-
* Lazily-built blob store for THIS handle's writing device, at the current
|
|
284
|
-
* rotation epoch. One core per writer per epoch that writes files: the base
|
|
285
|
-
* era uses the handle's encryptionKey, rotated epochs use a key derived
|
|
286
|
-
* from the epoch entropy — so a removed member cannot decrypt files added
|
|
287
|
-
* after the rotation. Instances carry `.stamp` so the file row records
|
|
288
|
-
* which era its core belongs to.
|
|
289
|
-
*
|
|
290
|
-
* @returns {Blobs}
|
|
291
|
-
*/
|
|
292
|
-
get blobs(): Blobs;
|
|
293
|
-
_baseBlobs(): Blobs;
|
|
294
|
-
_makeBlobs(name: any, encryptionKey: any, stamp: any): Blobs;
|
|
295
|
-
/**
|
|
296
|
-
* Remember the blob-core key a file id points at so the file server can
|
|
297
|
-
* open the core. Lives on the Handle (not the shared operators) because the
|
|
298
|
-
* epoch-key derivation pulls native crypto — the RPC client must stay
|
|
299
|
-
* bundleable without it.
|
|
300
|
-
*
|
|
301
|
-
* @param {string} id
|
|
302
|
-
* @param {number} [stamp]
|
|
303
|
-
*/
|
|
304
|
-
_registerBlobCore(id: string, stamp?: number): void;
|
|
305
|
-
_blobCoreKey(stamp: any): Uint8Array<ArrayBufferLike>;
|
|
306
|
-
/** Canonical id — identity id for the root handle, store key for children. */
|
|
307
|
-
get id(): any;
|
|
308
|
-
/** This device's id + name. `null` on child handles. */
|
|
309
|
-
get device(): {
|
|
310
|
-
id: any;
|
|
311
|
-
name: any;
|
|
312
|
-
};
|
|
313
|
-
get suspended(): boolean;
|
|
314
281
|
/**
|
|
315
282
|
* Initialise a fresh database: write the genesis claim, derive the writer.
|
|
316
283
|
* Forwards to `Database.bootstrap`.
|
|
@@ -327,14 +294,12 @@ export declare class Handle extends ReadyResource {
|
|
|
327
294
|
*/
|
|
328
295
|
claim(): Promise<void>;
|
|
329
296
|
/**
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
* `setActive(true)` promotes it back on focus. Cheap, safe to call often.
|
|
297
|
+
* `true` ranks this handle as just touched, `false` takes it out of the swarm until the
|
|
298
|
+
* next update lands in it.
|
|
333
299
|
*
|
|
334
300
|
* @param {boolean} active
|
|
335
|
-
* @returns {Promise<void>}
|
|
336
301
|
*/
|
|
337
|
-
setActive(active: boolean):
|
|
302
|
+
setActive(active: boolean): void;
|
|
338
303
|
/**
|
|
339
304
|
* Mint a pairing invite for this handle.
|
|
340
305
|
*
|
|
@@ -346,7 +311,6 @@ export declare class Handle extends ReadyResource {
|
|
|
346
311
|
expiresIn?: number;
|
|
347
312
|
data?: any;
|
|
348
313
|
}): Promise<string>;
|
|
349
|
-
_syncInvites(): Promise<void>;
|
|
350
314
|
/**
|
|
351
315
|
* Revoke a previously-minted invite by its string form.
|
|
352
316
|
*
|
|
@@ -363,7 +327,6 @@ export declare class Handle extends ReadyResource {
|
|
|
363
327
|
* @returns {Promise<void>}
|
|
364
328
|
*/
|
|
365
329
|
accept(candidate: any, { role, name }?: AcceptOpts): Promise<void>;
|
|
366
|
-
_checkGrant(role: any): Promise<void>;
|
|
367
330
|
/**
|
|
368
331
|
* Leave a child handle — removes it from the parent's `handles` collection
|
|
369
332
|
* and closes the session. No-op on root handles.
|
|
@@ -372,9 +335,41 @@ export declare class Handle extends ReadyResource {
|
|
|
372
335
|
*/
|
|
373
336
|
leave(): Promise<void>;
|
|
374
337
|
/**
|
|
375
|
-
*
|
|
376
|
-
*
|
|
377
|
-
*
|
|
338
|
+
* Pause networking + storage. Idempotent; no-op on child handles.
|
|
339
|
+
*
|
|
340
|
+
* @returns {Promise<void>}
|
|
341
|
+
*/
|
|
342
|
+
suspend(): Promise<void>;
|
|
343
|
+
/**
|
|
344
|
+
* Resume a suspended root handle. Idempotent; no-op on child handles.
|
|
345
|
+
*
|
|
346
|
+
* @returns {Promise<void>}
|
|
347
|
+
*/
|
|
348
|
+
resume(): Promise<void>;
|
|
349
|
+
/**
|
|
350
|
+
* @param {Uint8Array} coreKey
|
|
351
|
+
* @param {object} info
|
|
352
|
+
* @returns {{ key: Uint8Array, encryptionKey: Uint8Array } | null}
|
|
353
|
+
*/
|
|
354
|
+
_resolveCore(coreKey: Uint8Array, info: object): {
|
|
355
|
+
key: Uint8Array;
|
|
356
|
+
encryptionKey: Uint8Array;
|
|
357
|
+
} | null;
|
|
358
|
+
_baseBlobs(): Blobs;
|
|
359
|
+
_makeBlobs(name: any, encryptionKey: any, stamp: any): Blobs;
|
|
360
|
+
/**
|
|
361
|
+
* Remember the blob-core key a file id points at so the file server can open the core.
|
|
362
|
+
*
|
|
363
|
+
* @param {string} id
|
|
364
|
+
* @param {number} [stamp]
|
|
365
|
+
*/
|
|
366
|
+
_registerBlobCore(id: string, stamp?: number): void;
|
|
367
|
+
_blobCoreKey(stamp: any): Uint8Array<ArrayBufferLike>;
|
|
368
|
+
_syncInvites(): Promise<void>;
|
|
369
|
+
_checkGrant(role: any): Promise<void>;
|
|
370
|
+
/**
|
|
371
|
+
* Create a new child handle of `type`. Owner-flow — generates a fresh writer, adds it as a
|
|
372
|
+
* writer + member, and registers the child on the parent's `handles` collection.
|
|
378
373
|
*
|
|
379
374
|
* @param {string} type
|
|
380
375
|
* @param {CreateChildOpts} [opts]
|
|
@@ -382,9 +377,7 @@ export declare class Handle extends ReadyResource {
|
|
|
382
377
|
*/
|
|
383
378
|
_create(type: string, { name, routes, role, accept }?: CreateChildOpts): Promise<Handle>;
|
|
384
379
|
/**
|
|
385
|
-
* Join a child handle by invite (joiner-flow).
|
|
386
|
-
* capability and registers the child on the parent's `handles`
|
|
387
|
-
* collection.
|
|
380
|
+
* Join a child handle by invite (joiner-flow).
|
|
388
381
|
*
|
|
389
382
|
* @param {string} invite
|
|
390
383
|
* @param {string} type
|
|
@@ -401,9 +394,8 @@ export declare class Handle extends ReadyResource {
|
|
|
401
394
|
*/
|
|
402
395
|
_pair(invite: string, type: string, { routes, timeout }?: JoinChildOpts, target?: Uint8Array | null): Promise<Handle>;
|
|
403
396
|
/**
|
|
404
|
-
* Get an open child by id, or re-open it. Concurrent calls for the same id
|
|
405
|
-
*
|
|
406
|
-
* exactly once.
|
|
397
|
+
* Get an open child by id, or re-open it. Concurrent calls for the same id share one
|
|
398
|
+
* in-flight load, so the child is built — and `handle` emitted — exactly once.
|
|
407
399
|
*
|
|
408
400
|
* @param {string} type
|
|
409
401
|
* @param {string} id
|
|
@@ -419,29 +411,10 @@ export declare class Handle extends ReadyResource {
|
|
|
419
411
|
* @returns {Promise<Handle>}
|
|
420
412
|
*/
|
|
421
413
|
_reopen(type: string, id: string, opts: any): Promise<Handle>;
|
|
422
|
-
/**
|
|
423
|
-
* Pause networking + storage. Idempotent; no-op on child handles.
|
|
424
|
-
*
|
|
425
|
-
* @returns {Promise<void>}
|
|
426
|
-
*/
|
|
427
|
-
suspend(): Promise<void>;
|
|
428
414
|
_suspend(): Promise<void>;
|
|
429
|
-
/**
|
|
430
|
-
* Resume a suspended root handle. Idempotent; no-op on child handles.
|
|
431
|
-
*
|
|
432
|
-
* @returns {Promise<void>}
|
|
433
|
-
*/
|
|
434
|
-
resume(): Promise<void>;
|
|
435
415
|
_resume(): Promise<void>;
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
* `Handle` already configured with the resolved key + encryption key.
|
|
439
|
-
*
|
|
440
|
-
* @param {string} invite
|
|
441
|
-
* @param {StaticJoinOpts} [opts]
|
|
442
|
-
* @returns {Promise<Handle>}
|
|
443
|
-
*/
|
|
444
|
-
static join(invite: string, { parent, network, identity, store, spec, namespace, routes, timeout }?: StaticJoinOpts): Promise<Handle>;
|
|
416
|
+
_adopt(child: any, info: any): void;
|
|
417
|
+
_hookType(op: any, ref: any, fn: any, opts: any): () => void;
|
|
445
418
|
/**
|
|
446
419
|
* @param {Handle} child
|
|
447
420
|
* @param {{ role?: string }} [opts]
|
|
@@ -466,4 +439,13 @@ export declare class Handle extends ReadyResource {
|
|
|
466
439
|
publicKey: Uint8Array;
|
|
467
440
|
secretKey: Uint8Array;
|
|
468
441
|
} | null>;
|
|
442
|
+
/**
|
|
443
|
+
* Pair into an existing handle via an invite, returning a brand-new
|
|
444
|
+
* `Handle` already configured with the resolved key + encryption key.
|
|
445
|
+
*
|
|
446
|
+
* @param {string} invite
|
|
447
|
+
* @param {StaticJoinOpts} [opts]
|
|
448
|
+
* @returns {Promise<Handle>}
|
|
449
|
+
*/
|
|
450
|
+
static join(invite: string, { parent, network, identity, store, spec, namespace, routes, timeout }?: StaticJoinOpts): Promise<Handle>;
|
|
469
451
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { Identity } from '@cero-base/core/identity';
|
|
2
2
|
import { Handle, Ref } from './handle/index.js';
|
|
3
3
|
import { Local } from './local/index.js';
|
|
4
|
-
import { put, set, get, del,
|
|
4
|
+
import { put, set, get, del, watch, changes, call, open, rotate, before, after } from './lib/operators.js';
|
|
5
5
|
import { peek } from './lib/peek.js';
|
|
6
6
|
import { t, schema } from './lib/spec.js';
|
|
7
|
-
import { internal } from './lib/internal.js';
|
|
8
7
|
export { Handle, Ref, Local };
|
|
9
|
-
export { put, set, get, del,
|
|
8
|
+
export { put, set, get, del, watch, changes, call, open, rotate, before, after } from './lib/operators.js';
|
|
10
9
|
export { peek } from './lib/peek.js';
|
|
11
10
|
export { t, schema } from './lib/spec.js';
|
|
12
11
|
export type CeroHandle = import('./handle/index.js').CeroHandle;
|
|
@@ -54,6 +53,14 @@ export type CeroOpts = {
|
|
|
54
53
|
* Blind-peer public keys. Rooms and files are mirrored through them so peers sync even when never online at the same time. Mirrors hold only encrypted blocks — they never read your data.
|
|
55
54
|
*/
|
|
56
55
|
mirrors?: Array<string | Uint8Array>;
|
|
56
|
+
/**
|
|
57
|
+
* How many rooms search, how many only announce, and the idle ms before the rest leave the swarm.
|
|
58
|
+
*/
|
|
59
|
+
presence?: {
|
|
60
|
+
active?: number;
|
|
61
|
+
announced?: number;
|
|
62
|
+
idle?: number;
|
|
63
|
+
};
|
|
57
64
|
/**
|
|
58
65
|
* Existing database key to recover into, skipping the pointer lookup.
|
|
59
66
|
*/
|
|
@@ -79,9 +86,13 @@ export type CeroOpts = {
|
|
|
79
86
|
*/
|
|
80
87
|
storageKey?: Uint8Array;
|
|
81
88
|
/**
|
|
82
|
-
*
|
|
89
|
+
* The extensions this instance runs, instead of the ones the spec carries. Build with the same list.
|
|
90
|
+
*/
|
|
91
|
+
extensions?: import('./extensions/index.js').Extension[];
|
|
92
|
+
/**
|
|
93
|
+
* The operators to bind, instead of the ones the spec carries.
|
|
83
94
|
*/
|
|
84
|
-
|
|
95
|
+
operators?: Record<string, any>;
|
|
85
96
|
/**
|
|
86
97
|
* `true` enables nearby (Bluetooth) sync via `me.bluetooth` (auto-started). `{ autoStart: false }` creates the facade without starting the radio — the app calls `me.bluetooth.start()`/`stop()` (user toggle). `backend` injects a bare-bluetooth-shaped backend (tests). `maxOutbound`/`maxInbound` cap concurrent outbound links and inbound sessions. `pipe` picks the data pipe — `'l2cap'` (default, faster) or `'gatt'`; both peers must match. Absent backend on an unsupported host → `me.bluetooth.state === 'unsupported'`.
|
|
87
98
|
*/
|
|
@@ -108,19 +119,19 @@ export type CeroOpts = {
|
|
|
108
119
|
* @property {number[]} [backoffs] Swarm reconnect backoff tiers in ms (testing/tuning).
|
|
109
120
|
* @property {string} [channel] Optional network-isolation label; only same-channel peers connect.
|
|
110
121
|
* @property {Array<string | Uint8Array>} [mirrors] Blind-peer public keys. Rooms and files are mirrored through them so peers sync even when never online at the same time. Mirrors hold only encrypted blocks — they never read your data.
|
|
122
|
+
* @property {{ active?: number, announced?: number, idle?: number }} [presence] How many rooms search, how many only announce, and the idle ms before the rest leave the swarm.
|
|
111
123
|
* @property {Uint8Array} [key] Existing database key to recover into, skipping the pointer lookup.
|
|
112
124
|
* @property {Uint8Array} [encryptionKey] Pre-existing encryption key.
|
|
113
125
|
* @property {Record<string, Function>} [routes] Custom RPC routes for the database dispatcher.
|
|
114
126
|
* @property {(err: any) => void} [onerror] Background-task error handler.
|
|
115
127
|
* @property {number} [recoveryTimeout] Max wait to find another device and be admitted, in ms. Defaults to 30000.
|
|
116
128
|
* @property {Uint8Array} [storageKey] 32-byte key encrypting local key material (master seed, device keypairs) at rest. Source it from the OS keychain — cero never stores it.
|
|
117
|
-
* @property {
|
|
129
|
+
* @property {import('./extensions/index.js').Extension[]} [extensions] The extensions this instance runs, instead of the ones the spec carries. Build with the same list.
|
|
130
|
+
* @property {Record<string, any>} [operators] The operators to bind, instead of the ones the spec carries.
|
|
118
131
|
* @property {boolean | { autoStart?: boolean, backend?: any, maxOutbound?: number, maxInbound?: number, pipe?: 'l2cap' | 'gatt' }} [bluetooth] `true` enables nearby (Bluetooth) sync via `me.bluetooth` (auto-started). `{ autoStart: false }` creates the facade without starting the radio — the app calls `me.bluetooth.start()`/`stop()` (user toggle). `backend` injects a bare-bluetooth-shaped backend (tests). `maxOutbound`/`maxInbound` cap concurrent outbound links and inbound sessions. `pipe` picks the data pipe — `'l2cap'` (default, faster) or `'gatt'`; both peers must match. Absent backend on an unsupported host → `me.bluetooth.state === 'unsupported'`.
|
|
119
132
|
*/
|
|
120
133
|
/**
|
|
121
|
-
* Open (or create) a cero handle at `dir`.
|
|
122
|
-
* identity, then returns a ready root `Handle` with all schema refs
|
|
123
|
-
* attached as properties.
|
|
134
|
+
* Open (or create) a cero handle at `dir`.
|
|
124
135
|
*
|
|
125
136
|
* @param {string} dir Data directory.
|
|
126
137
|
* @param {any} spec Built spec — output of `cero/build`.
|
|
@@ -134,7 +145,6 @@ export declare namespace cero {
|
|
|
134
145
|
export { set };
|
|
135
146
|
export { get };
|
|
136
147
|
export { del };
|
|
137
|
-
export { count };
|
|
138
148
|
export { watch };
|
|
139
149
|
export { changes };
|
|
140
150
|
export { call };
|
|
@@ -145,15 +155,9 @@ export declare namespace cero {
|
|
|
145
155
|
export { peek };
|
|
146
156
|
export { restore };
|
|
147
157
|
export { schema };
|
|
148
|
-
export { bind };
|
|
149
|
-
export { define };
|
|
150
|
-
export { internal as _internal };
|
|
151
|
-
export var use: (...exts: any[]) => void;
|
|
152
158
|
}
|
|
153
159
|
/**
|
|
154
|
-
* Restore a cero instance from a mnemonic phrase.
|
|
155
|
-
* instance, wipes the on-disk `main/` tree and re-opens with the phrase, which
|
|
156
|
-
* recovers so the writer slot is re-claimed.
|
|
160
|
+
* Restore a cero instance from a mnemonic phrase.
|
|
157
161
|
*
|
|
158
162
|
* @param {Handle} me Existing root handle to restore.
|
|
159
163
|
* @param {string} phrase BIP-39 mnemonic phrase.
|
package/types/lib/bluetooth.d.ts
CHANGED
|
@@ -1,18 +1,7 @@
|
|
|
1
1
|
import ReadyResource from 'ready-resource';
|
|
2
2
|
/**
|
|
3
|
-
* `me.bluetooth` — the app-facing surface for nearby (Bluetooth) sync, a thin
|
|
4
|
-
*
|
|
5
|
-
* bytes; capability-gated replication still decides what syncs. Discovery is
|
|
6
|
-
* one topic-derived service UUID at a time (tag `cero-ble`) — the data service
|
|
7
|
-
* sits on a fixed per-tag UUID, so switching topics only retunes the radio.
|
|
8
|
-
*
|
|
9
|
-
* ```js
|
|
10
|
-
* const me = await cero(dir, spec, { channel, bluetooth: true })
|
|
11
|
-
* me.bluetooth.state // 'unsupported' | 'unauthorized' | 'off' | 'waiting' | 'starting' | 'on'
|
|
12
|
-
* await me.bluetooth.start()
|
|
13
|
-
* me.bluetooth.peers // Map of live BLE links
|
|
14
|
-
* me.bluetooth.on('update', () => {})
|
|
15
|
-
* ```
|
|
3
|
+
* `me.bluetooth` — the app-facing surface for nearby (Bluetooth) sync, a thin facade over
|
|
4
|
+
* ble-swarm.
|
|
16
5
|
*
|
|
17
6
|
* @extends ReadyResource
|
|
18
7
|
*/
|
|
@@ -49,6 +38,7 @@ export declare class Bluetooth extends ReadyResource {
|
|
|
49
38
|
/** @returns {Map<string, any>} Live BLE links, keyed by peer public key. */
|
|
50
39
|
get peers(): Map<string, any>;
|
|
51
40
|
_open(): Promise<void>;
|
|
41
|
+
_close(): Promise<void>;
|
|
52
42
|
/**
|
|
53
43
|
* Begin advertising + scanning. Idempotent; no-op when unsupported.
|
|
54
44
|
*
|
|
@@ -56,34 +46,19 @@ export declare class Bluetooth extends ReadyResource {
|
|
|
56
46
|
*/
|
|
57
47
|
start(): Promise<void>;
|
|
58
48
|
/**
|
|
59
|
-
* Stop advertising/scanning and drop links; open invite rendezvous end with
|
|
60
|
-
* the radio. Idempotent. Local data and the rest of the network (DHT) are
|
|
61
|
-
* untouched.
|
|
49
|
+
* Stop advertising/scanning and drop links; open invite rendezvous end with the radio.
|
|
62
50
|
*
|
|
63
51
|
* @returns {Promise<void>}
|
|
64
52
|
*/
|
|
65
53
|
stop(): Promise<void>;
|
|
66
54
|
/**
|
|
67
|
-
* Offline join rendezvous: retune the radio to the invite-derived topic so
|
|
68
|
-
*
|
|
69
|
-
* announcing a new invite replaces the previous rendezvous. Returns a stop
|
|
70
|
-
* function — closing the QR must stop the rendezvous so a photographed
|
|
71
|
-
* invite doesn't stay an ambient discovery beacon (admission itself is
|
|
72
|
-
* always gated by blind-pairing verifying the invite). The retune back to
|
|
73
|
-
* the mesh topic waits for live links to drain: the link a join just
|
|
74
|
-
* established survives and carries the joiner's initial replication.
|
|
75
|
-
* Auto-stops at the invite's expiry, on `stop()`, and on close.
|
|
76
|
-
*
|
|
77
|
-
* Only active while nearby sync is on: before `start()` (and after `stop()`)
|
|
78
|
-
* this is a no-op — the user controls the radio, and a join must not touch
|
|
79
|
-
* Bluetooth (OS permissions, GATT server) they never enabled.
|
|
55
|
+
* Offline join rendezvous: retune the radio to the invite-derived topic so holder and
|
|
56
|
+
* joiner find each other with zero DHT.
|
|
80
57
|
*
|
|
81
58
|
* @param {string} invite Z32 invite string.
|
|
82
59
|
* @returns {() => void}
|
|
83
60
|
*/
|
|
84
61
|
announce(invite: string): () => void;
|
|
85
|
-
_stopAnnounce(): void;
|
|
86
|
-
_clearAnnounce(): void;
|
|
87
62
|
/**
|
|
88
63
|
* Host-lifecycle pause (app backgrounded): radio down, user intent kept.
|
|
89
64
|
*
|
|
@@ -96,5 +71,6 @@ export declare class Bluetooth extends ReadyResource {
|
|
|
96
71
|
* @returns {Promise<void>}
|
|
97
72
|
*/
|
|
98
73
|
resume(): Promise<void>;
|
|
99
|
-
|
|
74
|
+
_stopAnnounce(): void;
|
|
75
|
+
_clearAnnounce(): void;
|
|
100
76
|
}
|
package/types/lib/constants.d.ts
CHANGED
|
@@ -3,14 +3,3 @@ export declare const COUNTERS = "counters";
|
|
|
3
3
|
export declare const EPOCHS = "epochs";
|
|
4
4
|
export declare const TIMEOUT = 30000;
|
|
5
5
|
export declare const FLUSH = 500;
|
|
6
|
-
export declare const DB_TYPE: {
|
|
7
|
-
string: string;
|
|
8
|
-
uint: string;
|
|
9
|
-
int: string;
|
|
10
|
-
bool: string;
|
|
11
|
-
bytes: string;
|
|
12
|
-
json: string;
|
|
13
|
-
fixed32: string;
|
|
14
|
-
fixed64: string;
|
|
15
|
-
file: string;
|
|
16
|
-
};
|