@cero-base/cero 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/README.md +38 -643
- package/package.json +9 -6
- package/src/build/index.js +21 -50
- package/src/build/internal.js +121 -0
- package/src/build/schemas.js +2 -8
- package/src/extensions/handle-sync.js +3 -10
- package/src/extensions/index.js +6 -0
- package/src/extensions/profile-sync.js +0 -5
- package/src/handle/index.js +241 -266
- package/src/index.js +20 -51
- package/src/lib/bluetooth.js +25 -56
- package/src/lib/constants.js +0 -15
- package/src/lib/operators.js +22 -72
- package/src/lib/peek.js +4 -8
- package/src/lib/refs.js +2 -5
- package/src/lib/spec.js +2 -3
- package/src/local/index.js +2 -3
- package/src/rpc/client.js +20 -34
- package/src/rpc/index.js +3 -3
- package/src/rpc/server.js +23 -35
- package/types/build/index.d.ts +1 -9
- package/types/build/{builtins.d.ts → internal.d.ts} +20 -38
- package/types/extensions/handle-sync.d.ts +2 -7
- package/types/extensions/index.d.ts +22 -0
- package/types/extensions/profile-sync.d.ts +0 -4
- package/types/handle/index.d.ts +83 -101
- package/types/index.d.ts +4 -8
- package/types/lib/bluetooth.d.ts +8 -32
- package/types/lib/constants.d.ts +0 -11
- package/types/lib/operators.d.ts +18 -46
- package/types/lib/peek.d.ts +2 -3
- package/types/lib/refs.d.ts +1 -3
- package/types/lib/spec.d.ts +2 -3
- package/types/local/index.d.ts +2 -3
- package/types/rpc/client.d.ts +10 -18
- package/types/rpc/index.d.ts +3 -3
- package/types/rpc/server.d.ts +6 -9
- 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
|
@@ -186,10 +186,6 @@ export type CeroHandle = Handle & Record<string, import('../lib/refs.js').Ref>;
|
|
|
186
186
|
*/
|
|
187
187
|
/**
|
|
188
188
|
* 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
189
|
*/
|
|
194
190
|
export declare class Handle extends ReadyResource {
|
|
195
191
|
identity: any;
|
|
@@ -214,16 +210,45 @@ export declare class Handle extends ReadyResource {
|
|
|
214
210
|
store: Database;
|
|
215
211
|
pair: Pairing;
|
|
216
212
|
_wantsPair: boolean;
|
|
217
|
-
_invitesSync: () => Promise<void>;
|
|
218
213
|
_ac: AbortController;
|
|
214
|
+
_invitesSync: () => Promise<void>;
|
|
219
215
|
/** @param {HandleOpts} [opts] */
|
|
220
216
|
constructor(opts?: HandleOpts);
|
|
217
|
+
/**
|
|
218
|
+
* An `AbortSignal` that fires when this handle closes.
|
|
219
|
+
*
|
|
220
|
+
* @returns {AbortSignal}
|
|
221
|
+
*/
|
|
222
|
+
get signal(): AbortSignal;
|
|
223
|
+
/** The top-most handle in the parent chain — itself for a root handle. */
|
|
224
|
+
get root(): this;
|
|
225
|
+
/**
|
|
226
|
+
* Lazily-built file server for this identity. Root-only — child handles
|
|
227
|
+
* reach it through `this.root.fileServer`.
|
|
228
|
+
*
|
|
229
|
+
* @returns {FileServer}
|
|
230
|
+
*/
|
|
231
|
+
get fileServer(): FileServer;
|
|
232
|
+
/**
|
|
233
|
+
* Lazily-built blob store for THIS handle's writing device, at the current rotation epoch.
|
|
234
|
+
*
|
|
235
|
+
* @returns {Blobs}
|
|
236
|
+
*/
|
|
237
|
+
get blobs(): Blobs;
|
|
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,9 +294,9 @@ export declare class Handle extends ReadyResource {
|
|
|
327
294
|
*/
|
|
328
295
|
claim(): Promise<void>;
|
|
329
296
|
/**
|
|
330
|
-
* Flip this handle's swarm announce mode — `setActive(false)` demotes an
|
|
331
|
-
*
|
|
332
|
-
*
|
|
297
|
+
* Flip this handle's swarm announce mode — `setActive(false)` demotes an idle/background
|
|
298
|
+
* room to server-only (still reachable, stops searching); `setActive(true)` promotes it
|
|
299
|
+
* back on focus.
|
|
333
300
|
*
|
|
334
301
|
* @param {boolean} active
|
|
335
302
|
* @returns {Promise<void>}
|
|
@@ -346,7 +313,6 @@ export declare class Handle extends ReadyResource {
|
|
|
346
313
|
expiresIn?: number;
|
|
347
314
|
data?: any;
|
|
348
315
|
}): Promise<string>;
|
|
349
|
-
_syncInvites(): Promise<void>;
|
|
350
316
|
/**
|
|
351
317
|
* Revoke a previously-minted invite by its string form.
|
|
352
318
|
*
|
|
@@ -363,7 +329,6 @@ export declare class Handle extends ReadyResource {
|
|
|
363
329
|
* @returns {Promise<void>}
|
|
364
330
|
*/
|
|
365
331
|
accept(candidate: any, { role, name }?: AcceptOpts): Promise<void>;
|
|
366
|
-
_checkGrant(role: any): Promise<void>;
|
|
367
332
|
/**
|
|
368
333
|
* Leave a child handle — removes it from the parent's `handles` collection
|
|
369
334
|
* and closes the session. No-op on root handles.
|
|
@@ -372,9 +337,41 @@ export declare class Handle extends ReadyResource {
|
|
|
372
337
|
*/
|
|
373
338
|
leave(): Promise<void>;
|
|
374
339
|
/**
|
|
375
|
-
*
|
|
376
|
-
*
|
|
377
|
-
*
|
|
340
|
+
* Pause networking + storage. Idempotent; no-op on child handles.
|
|
341
|
+
*
|
|
342
|
+
* @returns {Promise<void>}
|
|
343
|
+
*/
|
|
344
|
+
suspend(): Promise<void>;
|
|
345
|
+
/**
|
|
346
|
+
* Resume a suspended root handle. Idempotent; no-op on child handles.
|
|
347
|
+
*
|
|
348
|
+
* @returns {Promise<void>}
|
|
349
|
+
*/
|
|
350
|
+
resume(): Promise<void>;
|
|
351
|
+
/**
|
|
352
|
+
* @param {Uint8Array} coreKey
|
|
353
|
+
* @param {object} info
|
|
354
|
+
* @returns {{ key: Uint8Array, encryptionKey: Uint8Array } | null}
|
|
355
|
+
*/
|
|
356
|
+
_resolveCore(coreKey: Uint8Array, info: object): {
|
|
357
|
+
key: Uint8Array;
|
|
358
|
+
encryptionKey: Uint8Array;
|
|
359
|
+
} | null;
|
|
360
|
+
_baseBlobs(): Blobs;
|
|
361
|
+
_makeBlobs(name: any, encryptionKey: any, stamp: any): Blobs;
|
|
362
|
+
/**
|
|
363
|
+
* Remember the blob-core key a file id points at so the file server can open the core.
|
|
364
|
+
*
|
|
365
|
+
* @param {string} id
|
|
366
|
+
* @param {number} [stamp]
|
|
367
|
+
*/
|
|
368
|
+
_registerBlobCore(id: string, stamp?: number): void;
|
|
369
|
+
_blobCoreKey(stamp: any): Uint8Array<ArrayBufferLike>;
|
|
370
|
+
_syncInvites(): Promise<void>;
|
|
371
|
+
_checkGrant(role: any): Promise<void>;
|
|
372
|
+
/**
|
|
373
|
+
* Create a new child handle of `type`. Owner-flow — generates a fresh writer, adds it as a
|
|
374
|
+
* writer + member, and registers the child on the parent's `handles` collection.
|
|
378
375
|
*
|
|
379
376
|
* @param {string} type
|
|
380
377
|
* @param {CreateChildOpts} [opts]
|
|
@@ -382,9 +379,7 @@ export declare class Handle extends ReadyResource {
|
|
|
382
379
|
*/
|
|
383
380
|
_create(type: string, { name, routes, role, accept }?: CreateChildOpts): Promise<Handle>;
|
|
384
381
|
/**
|
|
385
|
-
* Join a child handle by invite (joiner-flow).
|
|
386
|
-
* capability and registers the child on the parent's `handles`
|
|
387
|
-
* collection.
|
|
382
|
+
* Join a child handle by invite (joiner-flow).
|
|
388
383
|
*
|
|
389
384
|
* @param {string} invite
|
|
390
385
|
* @param {string} type
|
|
@@ -401,9 +396,8 @@ export declare class Handle extends ReadyResource {
|
|
|
401
396
|
*/
|
|
402
397
|
_pair(invite: string, type: string, { routes, timeout }?: JoinChildOpts, target?: Uint8Array | null): Promise<Handle>;
|
|
403
398
|
/**
|
|
404
|
-
* Get an open child by id, or re-open it. Concurrent calls for the same id
|
|
405
|
-
*
|
|
406
|
-
* exactly once.
|
|
399
|
+
* Get an open child by id, or re-open it. Concurrent calls for the same id share one
|
|
400
|
+
* in-flight load, so the child is built — and `handle` emitted — exactly once.
|
|
407
401
|
*
|
|
408
402
|
* @param {string} type
|
|
409
403
|
* @param {string} id
|
|
@@ -419,29 +413,8 @@ export declare class Handle extends ReadyResource {
|
|
|
419
413
|
* @returns {Promise<Handle>}
|
|
420
414
|
*/
|
|
421
415
|
_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
416
|
_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
417
|
_resume(): Promise<void>;
|
|
436
|
-
/**
|
|
437
|
-
* Pair into an existing handle via an invite, returning a brand-new
|
|
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>;
|
|
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
|
@@ -4,7 +4,7 @@ import { Local } from './local/index.js';
|
|
|
4
4
|
import { put, set, get, del, count, watch, changes, call, open, rotate, before, after, bind, define } from './lib/operators.js';
|
|
5
5
|
import { peek } from './lib/peek.js';
|
|
6
6
|
import { t, schema } from './lib/spec.js';
|
|
7
|
-
import {
|
|
7
|
+
import { registry } from './extensions/index.js';
|
|
8
8
|
export { Handle, Ref, Local };
|
|
9
9
|
export { put, set, get, del, count, watch, changes, call, open, rotate, before, after, bind, define } from './lib/operators.js';
|
|
10
10
|
export { peek } from './lib/peek.js';
|
|
@@ -118,9 +118,7 @@ export type CeroOpts = {
|
|
|
118
118
|
* @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
119
|
*/
|
|
120
120
|
/**
|
|
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.
|
|
121
|
+
* Open (or create) a cero handle at `dir`.
|
|
124
122
|
*
|
|
125
123
|
* @param {string} dir Data directory.
|
|
126
124
|
* @param {any} spec Built spec — output of `cero/build`.
|
|
@@ -147,13 +145,11 @@ export declare namespace cero {
|
|
|
147
145
|
export { schema };
|
|
148
146
|
export { bind };
|
|
149
147
|
export { define };
|
|
150
|
-
export {
|
|
148
|
+
export { registry as _registry };
|
|
151
149
|
export var use: (...exts: any[]) => void;
|
|
152
150
|
}
|
|
153
151
|
/**
|
|
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.
|
|
152
|
+
* Restore a cero instance from a mnemonic phrase.
|
|
157
153
|
*
|
|
158
154
|
* @param {Handle} me Existing root handle to restore.
|
|
159
155
|
* @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
|
-
};
|
package/types/lib/operators.d.ts
CHANGED
|
@@ -35,9 +35,7 @@ export declare function resolveFile(handle: object, id: string, name?: string):
|
|
|
35
35
|
name?: string;
|
|
36
36
|
};
|
|
37
37
|
/**
|
|
38
|
-
* Insert (or overwrite by id) a row on `ref`.
|
|
39
|
-
* `put(handle.files, { data, type, name? })` uploads the bytes to this handle's
|
|
40
|
-
* blob store, records `{ id, name }`, and resolves the file.
|
|
38
|
+
* Insert (or overwrite by id) a row on `ref`.
|
|
41
39
|
*
|
|
42
40
|
* @param {Ref} ref
|
|
43
41
|
* @param {Record<string, any>} row
|
|
@@ -45,9 +43,7 @@ export declare function resolveFile(handle: object, id: string, name?: string):
|
|
|
45
43
|
*/
|
|
46
44
|
export declare function put(ref: Ref, row: Record<string, any>): Promise<SingleResult>;
|
|
47
45
|
/**
|
|
48
|
-
* Upsert a row on `ref` — merges with the existing row and preserves
|
|
49
|
-
* `createdAt`. Pass `{ upsert: false }` to update-only: a missing row is left
|
|
50
|
-
* untouched instead of created (atomic — never resurrects a deleted row).
|
|
46
|
+
* Upsert a row on `ref` — merges with the existing row and preserves `createdAt`.
|
|
51
47
|
*
|
|
52
48
|
* @param {Ref} ref
|
|
53
49
|
* @param {Record<string, any>} row
|
|
@@ -84,9 +80,7 @@ export declare function count(ref: Ref, q?: Record<string, any>): Promise<{
|
|
|
84
80
|
*/
|
|
85
81
|
export declare function call(ref: Ref, d?: Record<string, any>): Promise<any>;
|
|
86
82
|
/**
|
|
87
|
-
* Intercept writes to `ref` before they commit — `fn(ctx)` runs in-path
|
|
88
|
-
* (awaited). Return `false` to cancel the write, or mutate `ctx.row`.
|
|
89
|
-
* Returns an unsubscribe fn; pass `{ signal }` to unsubscribe on abort.
|
|
83
|
+
* Intercept writes to `ref` before they commit — `fn(ctx)` runs in-path (awaited).
|
|
90
84
|
*
|
|
91
85
|
* @param {Ref} ref
|
|
92
86
|
* @param {(ctx: { op: string, name: string, row: any }) => any} fn
|
|
@@ -101,9 +95,8 @@ export declare function before(ref: Ref, fn: (ctx: {
|
|
|
101
95
|
signal?: AbortSignal;
|
|
102
96
|
}): () => void;
|
|
103
97
|
/**
|
|
104
|
-
* Subscribe to writes on `ref` — fires after each committed write,
|
|
105
|
-
*
|
|
106
|
-
* to unsubscribe on abort.
|
|
98
|
+
* Subscribe to writes on `ref` — fires after each committed write, non-blocking (observe
|
|
99
|
+
* only).
|
|
107
100
|
*
|
|
108
101
|
* @param {Ref} ref
|
|
109
102
|
* @param {(ctx: { op: string, name: string, row: any }) => void} fn
|
|
@@ -118,9 +111,7 @@ export declare function after(ref: Ref, fn: (ctx: {
|
|
|
118
111
|
signal?: AbortSignal;
|
|
119
112
|
}): () => void;
|
|
120
113
|
/**
|
|
121
|
-
* Read from `ref`. For data refs, dispatches to the underlying store.
|
|
122
|
-
* `handle`-kind refs, lists existing child handles of that type from the
|
|
123
|
-
* parent's `handles` collection.
|
|
114
|
+
* Read from `ref`. For data refs, dispatches to the underlying store.
|
|
124
115
|
*
|
|
125
116
|
* @param {Ref} ref
|
|
126
117
|
* @param {string | Record<string, any>} [q]
|
|
@@ -128,10 +119,8 @@ export declare function after(ref: Ref, fn: (ctx: {
|
|
|
128
119
|
*/
|
|
129
120
|
export declare function get(ref: Ref, q?: string | Record<string, any>): Promise<SingleResult | ListResult | GetByIdResult>;
|
|
130
121
|
/**
|
|
131
|
-
* Live snapshot stream on `ref` — re-emits the latest `get()` result on
|
|
132
|
-
*
|
|
133
|
-
* handle destroys it. Pass `{ signal }` to bind it to a finer scope, or
|
|
134
|
-
* destroy the stream directly to stop watching sooner.
|
|
122
|
+
* Live snapshot stream on `ref` — re-emits the latest `get()` result on every underlying
|
|
123
|
+
* mutation.
|
|
135
124
|
*
|
|
136
125
|
* @param {Ref} ref
|
|
137
126
|
* @param {Record<string, any>} [q]
|
|
@@ -142,20 +131,13 @@ export declare function watch(ref: Ref, q?: Record<string, any>, opts?: {
|
|
|
142
131
|
signal?: AbortSignal;
|
|
143
132
|
}): import('streamx').Readable;
|
|
144
133
|
/**
|
|
145
|
-
* Delta subscription: batches of `{ prev, next }` row pairs instead of
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
* with `reset: true`). File-typed fields resolve on both sides.
|
|
134
|
+
* Delta subscription: batches of `{ prev, next }` row pairs instead of full snapshots —
|
|
135
|
+
* lossless under backpressure, self-contained (the first batch, and any batch after a view
|
|
136
|
+
* swap, replays current.
|
|
149
137
|
*/
|
|
150
138
|
export declare function changes(ref: any, q: any, opts: any): any;
|
|
151
139
|
/**
|
|
152
|
-
* Open (or create / join / load) a child handle through a `handle`-kind
|
|
153
|
-
* ref. Dispatches on the normalize of `arg`:
|
|
154
|
-
*
|
|
155
|
-
* - `string` → join via an invite string
|
|
156
|
-
* - `{ invite: string }` → join via invite (object form)
|
|
157
|
-
* - `{ id: string }` → load an existing handle by id
|
|
158
|
-
* - `object | undefined` → create a new handle with the given opts
|
|
140
|
+
* Open (or create / join / load) a child handle through a `handle`-kind ref.
|
|
159
141
|
*
|
|
160
142
|
* @param {Ref} ref
|
|
161
143
|
* @param {string | { invite?: string, id?: string, name?: string, routes?: any, role?: string, accept?: boolean } | undefined} [arg]
|
|
@@ -170,13 +152,9 @@ export declare function open(ref: Ref, arg?: string | {
|
|
|
170
152
|
accept?: boolean;
|
|
171
153
|
} | undefined): Promise<CeroHandle>;
|
|
172
154
|
/**
|
|
173
|
-
* Rotate a handle's encryption epoch. A fresh secret is sealed to every
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
* permission (admin or owner). Compose with removal:
|
|
177
|
-
*
|
|
178
|
-
* await cero.del(room.members, memberId)
|
|
179
|
-
* await cero.rotate(room)
|
|
155
|
+
* Rotate a handle's encryption epoch. A fresh secret is sealed to every current member and
|
|
156
|
+
* announced through the log — members removed before the rotation cannot decrypt anything
|
|
157
|
+
* written after it.
|
|
180
158
|
*
|
|
181
159
|
* @param {any} handle
|
|
182
160
|
* @returns {Promise<{ epoch: number }>}
|
|
@@ -186,12 +164,7 @@ export declare function rotate(handle: any): Promise<{
|
|
|
186
164
|
}>;
|
|
187
165
|
/**
|
|
188
166
|
* Put custom operators on `handle`, currying it as their first argument so
|
|
189
|
-
* `handle.ns.fn(args)` calls `fn(handle, args)`.
|
|
190
|
-
* - a `{ ns: module }` map → bind exactly those, or
|
|
191
|
-
* - `null` → the registered root operators, or
|
|
192
|
-
* - a child-handle type → the registered operators for that type.
|
|
193
|
-
* The scope forms are how cero binds handles automatically; pass a map yourself
|
|
194
|
-
* for manual binding.
|
|
167
|
+
* `handle.ns.fn(args)` calls `fn(handle, args)`.
|
|
195
168
|
*
|
|
196
169
|
* @param {any} handle
|
|
197
170
|
* @param {Record<string, any> | string | null} arg
|
|
@@ -199,9 +172,8 @@ export declare function rotate(handle: any): Promise<{
|
|
|
199
172
|
*/
|
|
200
173
|
export declare function bind(handle: any, arg: Record<string, any> | string | null): any;
|
|
201
174
|
/**
|
|
202
|
-
* Register custom operators by scope. A bare key binds on the root handle; a key
|
|
203
|
-
*
|
|
204
|
-
* at startup, before `cero()` / `connect()`, in both processes.
|
|
175
|
+
* Register custom operators by scope. A bare key binds on the root handle; a key that
|
|
176
|
+
* names a child-handle type binds on every handle of that type.
|
|
205
177
|
*
|
|
206
178
|
* @param {Record<string, any>} map
|
|
207
179
|
*/
|
package/types/lib/peek.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Quickly check whether the on-disk directory at `dir` already holds an
|
|
3
|
-
*
|
|
4
|
-
* read-only and closes everything before returning.
|
|
2
|
+
* Quickly check whether the on-disk directory at `dir` already holds an initialised cero
|
|
3
|
+
* identity (i.e. a stored master seed).
|
|
5
4
|
*
|
|
6
5
|
* @param {string} dir Cero data directory.
|
|
7
6
|
* @param {any} spec Built spec — same value passed to `cero(dir, spec)`.
|
package/types/lib/refs.d.ts
CHANGED
|
@@ -11,9 +11,7 @@ export type RefInfo = {
|
|
|
11
11
|
* from a generated spec.
|
|
12
12
|
*/
|
|
13
13
|
/**
|
|
14
|
-
* Typed pointer to a single ref (table or handle slot) on a `Handle` or
|
|
15
|
-
* `Local`. Operators (`put`/`get`/`open`/...) take a `Ref` as their first
|
|
16
|
-
* argument and dispatch through the owning handle's store.
|
|
14
|
+
* Typed pointer to a single ref (table or handle slot) on a `Handle` or `Local`.
|
|
17
15
|
*/
|
|
18
16
|
export declare class Ref {
|
|
19
17
|
handle: any;
|
package/types/lib/spec.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Re-exports of the schema DSL (`t`) and `schema()` wrapper from
|
|
3
|
-
*
|
|
4
|
-
* pulling in the core package directly.
|
|
2
|
+
* Re-exports of the schema DSL (`t`) and `schema()` wrapper from `@cero-base/core/schema`,
|
|
3
|
+
* so cero apps can describe their tables without pulling in the core package directly.
|
|
5
4
|
*/
|
|
6
5
|
export { t, schema } from '@cero-base/core/schema';
|
package/types/local/index.d.ts
CHANGED
|
@@ -21,9 +21,8 @@ export type LocalOpts = {
|
|
|
21
21
|
* @property {Uint8Array} [storageKey] 32-byte key encrypting the local store at rest.
|
|
22
22
|
*/
|
|
23
23
|
/**
|
|
24
|
-
* Per-device, single-writer storage for cero — holds the master seed,
|
|
25
|
-
*
|
|
26
|
-
* `Storage` and exposes each local ref as a property of the instance.
|
|
24
|
+
* Per-device, single-writer storage for cero — holds the master seed, device keypair and
|
|
25
|
+
* any per-handle keypairs.
|
|
27
26
|
*/
|
|
28
27
|
export declare class Local extends ReadyResource {
|
|
29
28
|
dir: string;
|
package/types/rpc/client.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export type RefInfo = {
|
|
|
7
7
|
kind?: 'single' | 'collection' | 'action' | 'handle';
|
|
8
8
|
schema?: string;
|
|
9
9
|
type?: string;
|
|
10
|
-
|
|
10
|
+
internal?: boolean;
|
|
11
11
|
};
|
|
12
12
|
export type Spec = import('@cero-base/core/rpc').Spec & {
|
|
13
13
|
meta: {
|
|
@@ -50,10 +50,7 @@ export type HandleStub = {
|
|
|
50
50
|
*/
|
|
51
51
|
export declare function restore(me: Client, phrase: string): Promise<Client>;
|
|
52
52
|
/**
|
|
53
|
-
* Per-device `local`-namespace surface on a Client.
|
|
54
|
-
* local ref (e.g. `client.local.settings`) and routes ops over RPC with
|
|
55
|
-
* `local: true`, so they hit the server's per-device store and never
|
|
56
|
-
* replicate. Built-in local refs (identity master/keypair) are not exposed.
|
|
53
|
+
* Per-device `local`-namespace surface on a Client.
|
|
57
54
|
*/
|
|
58
55
|
declare class LocalRefs {
|
|
59
56
|
parent: Client;
|
|
@@ -68,9 +65,9 @@ declare class LocalRefs {
|
|
|
68
65
|
get id(): any;
|
|
69
66
|
}
|
|
70
67
|
/**
|
|
71
|
-
* IPC-side RPC client for cero. Wraps an `hrpc` channel and exposes the
|
|
72
|
-
*
|
|
73
|
-
*
|
|
68
|
+
* IPC-side RPC client for cero. Wraps an `hrpc` channel and exposes the same
|
|
69
|
+
* handle/ref/row API as a local cero instance, transparently routing every operation
|
|
70
|
+
* across the wire.
|
|
74
71
|
*/
|
|
75
72
|
export declare class Client extends RPCClient {
|
|
76
73
|
id: any;
|
|
@@ -115,9 +112,9 @@ export declare class Client extends RPCClient {
|
|
|
115
112
|
_join(invite: string, type: string): Promise<Handle>;
|
|
116
113
|
}
|
|
117
114
|
/**
|
|
118
|
-
* Client-side proxy for a remote handle. Exposes the same row-ops surface
|
|
119
|
-
*
|
|
120
|
-
*
|
|
115
|
+
* Client-side proxy for a remote handle. Exposes the same row-ops surface as `Client` but
|
|
116
|
+
* scoped to a single child handle id, and routes every call through the parent's RPC
|
|
117
|
+
* channel.
|
|
121
118
|
*/
|
|
122
119
|
declare class Handle {
|
|
123
120
|
parent: Client;
|
|
@@ -149,13 +146,8 @@ declare class Handle {
|
|
|
149
146
|
*/
|
|
150
147
|
export declare function connect(ipc: any, spec: object): Promise<Client>;
|
|
151
148
|
/**
|
|
152
|
-
* Symmetric client entry. Mirrors the main `cero`, but `cero(ipc, spec)` connects
|
|
153
|
-
*
|
|
154
|
-
* surface is attached, so `import { cero } from '@cero-base/cero/client'` works
|
|
155
|
-
* just like `import { cero } from '@cero-base/cero'`.
|
|
156
|
-
*
|
|
157
|
-
* Note: `before`/`after`/`peek` are intentionally not exposed here — they hook the
|
|
158
|
-
* local write path / probe a local store, which a client proxy has no notion of.
|
|
149
|
+
* Symmetric client entry. Mirrors the main `cero`, but `cero(ipc, spec)` connects to a
|
|
150
|
+
* server (via `connect`) instead of opening a local store.
|
|
159
151
|
*
|
|
160
152
|
* @param {any} ipc Framed IPC duplex stream.
|
|
161
153
|
* @param {any} spec Built cero spec.
|
package/types/rpc/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* RPC barrel — re-exports the `Server`/`Client` classes and their
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* RPC barrel — re-exports the `Server`/`Client` classes and their `serve()`/`connect()`
|
|
3
|
+
* helpers so consumers can spin up either side of the cero IPC bridge from a single
|
|
4
|
+
* import.
|
|
5
5
|
*/
|
|
6
6
|
export { Server, serve } from './server.js';
|
|
7
7
|
export { Client, connect } from './client.js';
|