@cero-base/cero 2.11.0 → 3.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 +6 -5
- package/src/build/index.js +296 -57
- package/src/build/internal.js +80 -5
- package/src/build/schemas.js +118 -25
- package/src/extensions/mirror.js +2 -1
- package/src/extensions/profile-sync.js +17 -1
- package/src/handle/index.js +1222 -189
- package/src/index.js +68 -35
- package/src/lib/constants.js +4 -4
- package/src/lib/operators.js +66 -14
- package/src/lib/peek.js +14 -8
- package/src/lib/reserved.js +61 -0
- package/src/lib/spec.js +7 -1
- package/src/lib/swap.js +59 -6
- package/src/local/index.js +6 -2
- package/src/push/index.js +26 -13
- package/src/rpc/client.js +30 -10
- package/src/rpc/push.js +9 -3
- package/src/rpc/server.js +134 -51
- package/types/build/internal.d.ts +57 -0
- package/types/build/schemas.d.ts +58 -5
- package/types/extensions/index.d.ts +3 -0
- package/types/extensions/profile-sync.d.ts +1 -1
- package/types/handle/index.d.ts +123 -15
- package/types/index.d.ts +9 -6
- package/types/lib/constants.d.ts +2 -2
- package/types/lib/operators.d.ts +26 -6
- package/types/lib/peek.d.ts +7 -4
- package/types/lib/reserved.d.ts +1 -0
- package/types/lib/spec.d.ts +35 -2
- package/types/lib/swap.d.ts +28 -3
- package/types/push/index.d.ts +4 -12
- package/types/rpc/client.d.ts +35 -18
- package/types/rpc/server.d.ts +24 -3
- package/src/handle/join.js +0 -139
- package/types/handle/join.d.ts +0 -63
package/types/handle/index.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export type HandleOpts = {
|
|
|
31
31
|
*/
|
|
32
32
|
spec?: Spec;
|
|
33
33
|
/**
|
|
34
|
-
* Root only, and required there: the device store for handle keypairs
|
|
34
|
+
* Root only, and required there: the device store for handle keypairs and mail.
|
|
35
35
|
*/
|
|
36
36
|
local?: Local;
|
|
37
37
|
/**
|
|
@@ -123,7 +123,7 @@ export type Context = Handle & Record<string, import('../lib/refs.js').Ref>;
|
|
|
123
123
|
* @property {Network} [network] Shared swarm. Inherited from `parent` if omitted.
|
|
124
124
|
* @property {import('corestore')} [store] Pre-existing Corestore. Falls back to `parent.store.store`.
|
|
125
125
|
* @property {Spec} [spec] Built cero spec.
|
|
126
|
-
* @property {Local} [local] Root only, and required there: the device store for handle keypairs
|
|
126
|
+
* @property {Local} [local] Root only, and required there: the device store for handle keypairs and mail.
|
|
127
127
|
* @property {import('hypercore-storage')} [storage] Owned HypercoreStorage to close on shutdown.
|
|
128
128
|
* @property {{ destroy(): Promise<void> }} [discovery] Owned identity discovery to destroy on shutdown.
|
|
129
129
|
* @property {string} [dir] Data directory (root handles only).
|
|
@@ -181,14 +181,24 @@ export declare class Handle extends ReadyResource {
|
|
|
181
181
|
/** @private */
|
|
182
182
|
_pending;
|
|
183
183
|
/** @private */
|
|
184
|
+
_ending;
|
|
185
|
+
/** @private */
|
|
184
186
|
_typeHooks;
|
|
185
187
|
/** @private */
|
|
186
188
|
_loading;
|
|
187
189
|
/** @private */
|
|
188
190
|
_joining;
|
|
189
191
|
/** @private */
|
|
192
|
+
_taking;
|
|
193
|
+
/** @private */
|
|
190
194
|
_coreKeys;
|
|
191
195
|
/** @private */
|
|
196
|
+
_offJoins;
|
|
197
|
+
/** @private */
|
|
198
|
+
_departing;
|
|
199
|
+
/** @private */
|
|
200
|
+
_leaving;
|
|
201
|
+
/** @private */
|
|
192
202
|
_fileServer;
|
|
193
203
|
/** @private */
|
|
194
204
|
_blobs;
|
|
@@ -199,9 +209,27 @@ export declare class Handle extends ReadyResource {
|
|
|
199
209
|
/** @private */
|
|
200
210
|
_owned;
|
|
201
211
|
/** @private */
|
|
212
|
+
_kept;
|
|
213
|
+
/** @private */
|
|
214
|
+
_arriving;
|
|
215
|
+
/** @private */
|
|
202
216
|
_refs;
|
|
203
217
|
/** @private */
|
|
218
|
+
_pruning;
|
|
219
|
+
/** @private */
|
|
204
220
|
_idle;
|
|
221
|
+
/** @private */
|
|
222
|
+
_tellings;
|
|
223
|
+
/** @private */
|
|
224
|
+
_waiting;
|
|
225
|
+
/** @private */
|
|
226
|
+
_waiters;
|
|
227
|
+
/** @private */
|
|
228
|
+
_telling;
|
|
229
|
+
/** @private @type {Array<{ stamp: () => Promise<string | null>, tell: (child: Handle) => Promise<void> }> | null} */
|
|
230
|
+
_tellers;
|
|
231
|
+
/** @private */
|
|
232
|
+
_retell;
|
|
205
233
|
store: Database;
|
|
206
234
|
/** @private */
|
|
207
235
|
_pair;
|
|
@@ -213,6 +241,10 @@ export declare class Handle extends ReadyResource {
|
|
|
213
241
|
_live;
|
|
214
242
|
/** @private */
|
|
215
243
|
_ac;
|
|
244
|
+
_queued: {
|
|
245
|
+
root: boolean;
|
|
246
|
+
children: Set<any>;
|
|
247
|
+
};
|
|
216
248
|
_indexing: any;
|
|
217
249
|
/** @param {HandleOpts} [opts] */
|
|
218
250
|
constructor(opts?: HandleOpts);
|
|
@@ -259,9 +291,9 @@ export declare class Handle extends ReadyResource {
|
|
|
259
291
|
/** @private */
|
|
260
292
|
private _close;
|
|
261
293
|
/**
|
|
262
|
-
* Tie a destroyable resource (a `watch` stream, a timer, any `{ destroy }`) to this
|
|
263
|
-
*
|
|
264
|
-
*
|
|
294
|
+
* Tie a destroyable resource (a `watch` stream, a timer, any `{ destroy }`) to this handle, so callers
|
|
295
|
+
* don't track cleanup. Tied by a holder, it is destroyed once the last holder closes the handle; tied by
|
|
296
|
+
* a `handle` listener as it runs, an extension's watch, it follows the handle for as long as it is open.
|
|
265
297
|
*
|
|
266
298
|
* @template {{ destroy?: Function, once?: Function }} T
|
|
267
299
|
* @param {T} resource
|
|
@@ -272,6 +304,8 @@ export declare class Handle extends ReadyResource {
|
|
|
272
304
|
once?: Function;
|
|
273
305
|
}>(resource: T): T;
|
|
274
306
|
/** @private */
|
|
307
|
+
private _disown;
|
|
308
|
+
/** @private */
|
|
275
309
|
private _link;
|
|
276
310
|
/** @private */
|
|
277
311
|
private _invite;
|
|
@@ -282,22 +316,30 @@ export declare class Handle extends ReadyResource {
|
|
|
282
316
|
/** @private */
|
|
283
317
|
private _rotate;
|
|
284
318
|
/** @private */
|
|
319
|
+
private _removed;
|
|
320
|
+
/** @private */
|
|
285
321
|
private _tx;
|
|
286
322
|
/** @private */
|
|
287
323
|
private _leave;
|
|
324
|
+
/** @private */
|
|
325
|
+
private _depart;
|
|
326
|
+
/** @private */
|
|
327
|
+
private _ousted;
|
|
288
328
|
/**
|
|
289
|
-
* One holder done with it: a child stays open for the others. With its last
|
|
290
|
-
*
|
|
329
|
+
* One holder done with it: a child stays open for the others. With its last, what they tied to it ends and it
|
|
330
|
+
* stays open, idle, so a reopen finds it as it is; the root keeps `keepOpen` of them (16 by default) and one more
|
|
331
|
+
* closes the least recently used, on its own. The root closes at once, after any `cero.link` or `cero.restore` on
|
|
332
|
+
* it: one still waiting stops, one taking its place finishes first.
|
|
291
333
|
* @returns {Promise<void>}
|
|
292
334
|
*/
|
|
293
335
|
close(): Promise<void>;
|
|
336
|
+
/** @private one more holder: an idle handle is kept */
|
|
337
|
+
private _hold;
|
|
294
338
|
/**
|
|
295
|
-
* Closed for every holder at once:
|
|
339
|
+
* Closed for every holder at once: pushed out past `keepOpen`, the parent closing, or the handle left for good.
|
|
296
340
|
* @private
|
|
297
341
|
*/
|
|
298
|
-
|
|
299
|
-
private _hold;
|
|
300
|
-
_end(): Promise<void>;
|
|
342
|
+
private _end;
|
|
301
343
|
/** @private */
|
|
302
344
|
private _suspend;
|
|
303
345
|
/** @private */
|
|
@@ -321,15 +363,23 @@ export declare class Handle extends ReadyResource {
|
|
|
321
363
|
/** @private */
|
|
322
364
|
private _onRadio;
|
|
323
365
|
/** @private */
|
|
324
|
-
private
|
|
325
|
-
/** @private */
|
|
326
|
-
private _onLocal;
|
|
366
|
+
private _onTopics;
|
|
327
367
|
/** @private */
|
|
328
368
|
private _topics;
|
|
329
369
|
/** @private */
|
|
330
370
|
private _index;
|
|
331
371
|
/** @private */
|
|
332
|
-
private
|
|
372
|
+
private _seal;
|
|
373
|
+
/** @private */
|
|
374
|
+
private _follow;
|
|
375
|
+
/** @private */
|
|
376
|
+
private _put;
|
|
377
|
+
/** @private */
|
|
378
|
+
private _drop;
|
|
379
|
+
/** @private */
|
|
380
|
+
private _topic;
|
|
381
|
+
/** @private */
|
|
382
|
+
private _row;
|
|
333
383
|
/** @private */
|
|
334
384
|
private _receive;
|
|
335
385
|
/** @private */
|
|
@@ -390,10 +440,36 @@ export declare class Handle extends ReadyResource {
|
|
|
390
440
|
*/
|
|
391
441
|
private _join;
|
|
392
442
|
/** @private */
|
|
443
|
+
private _left;
|
|
444
|
+
/** @private */
|
|
445
|
+
private _landed;
|
|
446
|
+
/** @private */
|
|
447
|
+
private _asked;
|
|
448
|
+
/** @private */
|
|
393
449
|
private _start;
|
|
394
450
|
/** @private */
|
|
451
|
+
private _run;
|
|
452
|
+
/** @private */
|
|
395
453
|
private _cancel;
|
|
396
454
|
/** @private */
|
|
455
|
+
private _check;
|
|
456
|
+
/** @private */
|
|
457
|
+
private _takeBack;
|
|
458
|
+
/** @private */
|
|
459
|
+
private _retract;
|
|
460
|
+
/** @private */
|
|
461
|
+
private _announce;
|
|
462
|
+
/** @private */
|
|
463
|
+
private _forget;
|
|
464
|
+
/** @private */
|
|
465
|
+
private _stop;
|
|
466
|
+
/** @private */
|
|
467
|
+
private _ask;
|
|
468
|
+
/** @private */
|
|
469
|
+
private _stand;
|
|
470
|
+
/** @private */
|
|
471
|
+
private _over;
|
|
472
|
+
/** @private */
|
|
397
473
|
private _joined;
|
|
398
474
|
/**
|
|
399
475
|
* Open a joined handle with the keys its reply delivered, once this writer is admitted.
|
|
@@ -405,6 +481,8 @@ export declare class Handle extends ReadyResource {
|
|
|
405
481
|
*/
|
|
406
482
|
private _enter;
|
|
407
483
|
/** @private */
|
|
484
|
+
private _sweep;
|
|
485
|
+
/** @private */
|
|
408
486
|
private _carryOn;
|
|
409
487
|
/**
|
|
410
488
|
* Get an open child by id, or re-open it. Concurrent calls for the same id share one
|
|
@@ -435,10 +513,40 @@ export declare class Handle extends ReadyResource {
|
|
|
435
513
|
/** @private */
|
|
436
514
|
private _adopt;
|
|
437
515
|
/** @private */
|
|
516
|
+
private _seats;
|
|
517
|
+
/** @private */
|
|
438
518
|
private _prune;
|
|
439
519
|
/** @private */
|
|
520
|
+
private _compare;
|
|
521
|
+
/** @private */
|
|
522
|
+
private _teach;
|
|
523
|
+
/** @private */
|
|
524
|
+
private _record;
|
|
525
|
+
/** @private */
|
|
526
|
+
private _mark;
|
|
527
|
+
/** @private */
|
|
528
|
+
private _unseat;
|
|
529
|
+
/** @private */
|
|
440
530
|
private _pruneAll;
|
|
441
531
|
/** @private */
|
|
532
|
+
private _tellClosed;
|
|
533
|
+
/** @private */
|
|
534
|
+
private _pass;
|
|
535
|
+
/** @private */
|
|
536
|
+
private _marked;
|
|
537
|
+
/** @private */
|
|
538
|
+
private _lists;
|
|
539
|
+
/** @private */
|
|
540
|
+
private _stamp;
|
|
541
|
+
/** @private */
|
|
542
|
+
private _tellOne;
|
|
543
|
+
/** @private */
|
|
544
|
+
private _wait;
|
|
545
|
+
/** @private */
|
|
546
|
+
private _turns;
|
|
547
|
+
/** @private */
|
|
548
|
+
private _tellRoom;
|
|
549
|
+
/** @private */
|
|
442
550
|
private _carry;
|
|
443
551
|
/** @private */
|
|
444
552
|
private _hookType;
|
package/types/index.d.ts
CHANGED
|
@@ -74,9 +74,9 @@ export type CeroOpts = {
|
|
|
74
74
|
*/
|
|
75
75
|
onerror?: (err: Error) => void;
|
|
76
76
|
/**
|
|
77
|
-
*
|
|
77
|
+
* How many handles stay open after their last close, for a reopen; one more closes the least recently used, 0 closes at once. Defaults to 16.
|
|
78
78
|
*/
|
|
79
|
-
|
|
79
|
+
keepOpen?: number;
|
|
80
80
|
/**
|
|
81
81
|
* Max wait to find another device and be admitted, in ms. Defaults to 30000.
|
|
82
82
|
*/
|
|
@@ -120,7 +120,7 @@ export type CeroOpts = {
|
|
|
120
120
|
* @property {Array<string | Uint8Array>} [mirrors] Blind-peer public keys. Handles 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.
|
|
121
121
|
* @property {{ active?: number, announced?: number, idle?: number }} [presence] How many handles search, how many only announce, and the idle ms before the rest leave the swarm.
|
|
122
122
|
* @property {(err: Error) => void} [onerror] Where background errors go; the console without one.
|
|
123
|
-
* @property {number} [
|
|
123
|
+
* @property {number} [keepOpen] How many handles stay open after their last close, for a reopen; one more closes the least recently used, 0 closes at once. Defaults to 16.
|
|
124
124
|
* @property {number} [recoveryTimeout] Max wait to find another device and be admitted, in ms. Defaults to 30000.
|
|
125
125
|
* @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.
|
|
126
126
|
* @property {import('./extensions/index.js').Extension[]} [extensions] The extensions this instance runs, instead of the ones the spec carries. Build with the same list.
|
|
@@ -136,7 +136,9 @@ export type CeroOpts = {
|
|
|
136
136
|
*/
|
|
137
137
|
declare function start(dir: string, spec: import('./lib/spec.js').Spec, opts?: CeroOpts): Promise<Context>;
|
|
138
138
|
/**
|
|
139
|
-
*
|
|
139
|
+
* Switch this device to the identity of a recovery phrase. That identity opens beside `me` and
|
|
140
|
+
* recovers from a device of it; once it has opened, `me` closes and its data is deleted. A failure
|
|
141
|
+
* leaves `me` as it was, and the phrase of `me`'s own identity resolves `me`.
|
|
140
142
|
*
|
|
141
143
|
* @param {Context} me The root to restore.
|
|
142
144
|
* @param {string} phrase The identity's BIP-39 phrase, as `cero.phrase(me)` gives it.
|
|
@@ -144,8 +146,9 @@ declare function start(dir: string, spec: import('./lib/spec.js').Spec, opts?: C
|
|
|
144
146
|
*/
|
|
145
147
|
export declare function restore(me: Context, phrase: string): Promise<Handle>;
|
|
146
148
|
/**
|
|
147
|
-
* Link this device to the identity behind a device invite
|
|
148
|
-
* opens
|
|
149
|
+
* Link this device to the identity behind a device invite, as a new device of it with no phrase on
|
|
150
|
+
* it. It opens beside `me`; once accepted, `me` closes and its data is deleted. A denial or a failure
|
|
151
|
+
* leaves `me` as it was.
|
|
149
152
|
*
|
|
150
153
|
* @param {Context} me The root to replace.
|
|
151
154
|
* @param {string} invite A device invite, as `cero.invite(me)` gives it on a device of that identity.
|
package/types/lib/constants.d.ts
CHANGED
|
@@ -4,6 +4,6 @@ export declare const EPOCHS = "epochs";
|
|
|
4
4
|
export declare const REMOVALS = "removals";
|
|
5
5
|
export declare const REFUSALS = "refusals";
|
|
6
6
|
export declare const SPENT = "spent";
|
|
7
|
+
export declare const ASKS = "owed";
|
|
7
8
|
export declare const TIMEOUT = 30000;
|
|
8
|
-
export declare const
|
|
9
|
-
export declare const LINGER = 20000;
|
|
9
|
+
export declare const KEEP_OPEN = 16;
|
package/types/lib/operators.d.ts
CHANGED
|
@@ -86,6 +86,16 @@ export declare function after(ref: Ref, fn: (ctx: HookContext) => unknown, opts?
|
|
|
86
86
|
* @returns {Promise<SingleResult | ListResult>}
|
|
87
87
|
*/
|
|
88
88
|
export declare function get(ref: Ref, q?: string | Record<string, unknown>): Promise<SingleResult | ListResult>;
|
|
89
|
+
/**
|
|
90
|
+
* Whether a handle has turned on a collection, a single or an action, or a field of one with
|
|
91
|
+
* `field`. What a release holds back with `t.later` turns on once the handle's `status.version`
|
|
92
|
+
* reaches the release that brought it; until then a write naming it fails with `UNSUPPORTED`.
|
|
93
|
+
*
|
|
94
|
+
* @param {Ref} ref A ref of the root or of an open handle (`room.notes`).
|
|
95
|
+
* @param {string} [field]
|
|
96
|
+
* @returns {Promise<boolean>}
|
|
97
|
+
*/
|
|
98
|
+
export declare function supports(ref: Ref, field?: string): Promise<boolean>;
|
|
89
99
|
/**
|
|
90
100
|
* Read a ref as it changes. Each item is what `get(ref, query)` returns now; a slow reader gets
|
|
91
101
|
* only the newest. With `changes: true` in the query each item also carries `changes`, the
|
|
@@ -127,14 +137,14 @@ export declare function invite(ctx: Context, opts?: import('@cero-base/core/pair
|
|
|
127
137
|
* Kill an invite, for every member.
|
|
128
138
|
*
|
|
129
139
|
* @param {Context} ctx
|
|
130
|
-
* @param {string} code
|
|
140
|
+
* @param {string} code The code `invite` returned, or the id its `invites` row holds.
|
|
131
141
|
* @returns {Promise<boolean>} Whether it was live.
|
|
132
142
|
*/
|
|
133
143
|
export declare function revoke(ctx: Context, code: string): Promise<boolean>;
|
|
134
144
|
/**
|
|
135
|
-
*
|
|
136
|
-
* written after. Needs the remove permission. A removal
|
|
137
|
-
*
|
|
145
|
+
* Rotate a handle's key now: a new epoch sealed to its members, so one removed before it reads
|
|
146
|
+
* nothing written after. Needs the remove permission. A removal by an admin or the owner rotates
|
|
147
|
+
* it as it resolves; this is for any other time.
|
|
138
148
|
*
|
|
139
149
|
* @param {Context} ctx
|
|
140
150
|
* @returns {Promise<{ epoch: number }>}
|
|
@@ -178,7 +188,17 @@ export declare function deny(ctx: Context, request: {
|
|
|
178
188
|
id: string;
|
|
179
189
|
}, reason?: string): Promise<void>;
|
|
180
190
|
/**
|
|
181
|
-
*
|
|
191
|
+
* Whether a member is out of a handle for good, as this device has seen it: `'removed'` by another
|
|
192
|
+
* member, `'left'` on her own, or null while she is a member, never was one, or her going has not
|
|
193
|
+
* reached this device. Someone let in again after is a member: null.
|
|
194
|
+
*
|
|
195
|
+
* @param {Context} ctx
|
|
196
|
+
* @param {string} id The member's id.
|
|
197
|
+
* @returns {Promise<'removed' | 'left' | null>}
|
|
198
|
+
*/
|
|
199
|
+
export declare function removed(ctx: Context, id: string): Promise<'removed' | 'left' | null>;
|
|
200
|
+
/**
|
|
201
|
+
* Quit a handle for good: its row reads `leaving`, then `left` once the handle holds it, and it closes.
|
|
182
202
|
*
|
|
183
203
|
* @param {Context} ctx
|
|
184
204
|
* @returns {Promise<void>}
|
|
@@ -248,7 +268,7 @@ export declare function receive(me: Context, payload: Uint8Array): Promise<{
|
|
|
248
268
|
/**
|
|
249
269
|
* Send a value to an address, signed by this identity. Resolves once the outbox keeps it; it is
|
|
250
270
|
* delivered in the background, from a mirror too when the owner is offline. `keep: false` erases
|
|
251
|
-
* this device's copy once
|
|
271
|
+
* this device's copy once a device or a mirror stored it.
|
|
252
272
|
*
|
|
253
273
|
* @param {Context} me
|
|
254
274
|
* @param {string} address As `cero.address(secret)` gives it.
|
package/types/lib/peek.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* What the directory at `dir` holds, read without opening it: nothing yet, an identity, or a recovery or a link
|
|
3
|
+
* still waiting for a device of its identity, which the next `cero(dir, spec)` goes on with.
|
|
4
4
|
*
|
|
5
5
|
* @param {string} dir Cero data directory.
|
|
6
6
|
* @param {import('./spec.js').Spec} spec Built spec, the value passed to `cero(dir, spec)`.
|
|
7
|
-
* @
|
|
7
|
+
* @param {{ storageKey?: Uint8Array }} [opts] The key `cero()` encrypts the local store with, if any.
|
|
8
|
+
* @returns {Promise<'ready' | 'recovering' | 'linking' | null>} `null` when it holds nothing.
|
|
8
9
|
*/
|
|
9
|
-
export declare function peek(dir: string, spec: import('./spec.js').Spec
|
|
10
|
+
export declare function peek(dir: string, spec: import('./spec.js').Spec, { storageKey }?: {
|
|
11
|
+
storageKey?: Uint8Array;
|
|
12
|
+
}): Promise<'ready' | 'recovering' | 'linking' | null>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const reserved: string[];
|
package/types/lib/spec.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export type RefInfo = {
|
|
|
15
15
|
*/
|
|
16
16
|
internal?: boolean;
|
|
17
17
|
/**
|
|
18
|
-
* Computed on the device, never stored: status,
|
|
18
|
+
* Computed on the device, never stored: status, nearby, topics.
|
|
19
19
|
*/
|
|
20
20
|
live?: boolean;
|
|
21
21
|
/**
|
|
@@ -35,6 +35,10 @@ export type RefInfo = {
|
|
|
35
35
|
* Whether a write to this ref pushes a notification.
|
|
36
36
|
*/
|
|
37
37
|
push?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* The contract that brought it, 0 for one the spec had when its history began.
|
|
40
|
+
*/
|
|
41
|
+
since?: number;
|
|
38
42
|
};
|
|
39
43
|
export type SpecMeta = {
|
|
40
44
|
ns?: string;
|
|
@@ -43,6 +47,29 @@ export type SpecMeta = {
|
|
|
43
47
|
*/
|
|
44
48
|
type?: string;
|
|
45
49
|
version?: number;
|
|
50
|
+
/**
|
|
51
|
+
* What a write means to Cero, raised by a release that changes it.
|
|
52
|
+
*/
|
|
53
|
+
rules?: number;
|
|
54
|
+
/**
|
|
55
|
+
* The contract the spec's history begins at.
|
|
56
|
+
*/
|
|
57
|
+
start?: number;
|
|
58
|
+
/**
|
|
59
|
+
* The contract this build asks databases to use.
|
|
60
|
+
*/
|
|
61
|
+
target?: number;
|
|
62
|
+
/**
|
|
63
|
+
* The contract that brought each route, and each field of each stored type, by full name.
|
|
64
|
+
*/
|
|
65
|
+
since?: {
|
|
66
|
+
routes: Record<string, number>;
|
|
67
|
+
types: Record<string, Record<string, number>>;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* The schema version to encode with as of each contract.
|
|
71
|
+
*/
|
|
72
|
+
encoding?: Record<string, number>;
|
|
46
73
|
refs: Record<string, RefInfo>;
|
|
47
74
|
local?: {
|
|
48
75
|
refs: Record<string, RefInfo>;
|
|
@@ -69,17 +96,23 @@ export type Row = import('@cero-base/core/database').Row;
|
|
|
69
96
|
* @property {string} [schema]
|
|
70
97
|
* @property {string} [type] The handle type a `handle` ref opens.
|
|
71
98
|
* @property {boolean} [internal] A builtin: members, devices, files and the like.
|
|
72
|
-
* @property {boolean} [live] Computed on the device, never stored: status,
|
|
99
|
+
* @property {boolean} [live] Computed on the device, never stored: status, nearby, topics.
|
|
73
100
|
* @property {string[]} [fields] The declared fields, in schema order.
|
|
74
101
|
* @property {Record<string, string>} [required] The required fields and their types.
|
|
75
102
|
* @property {string[]} [files] The fields holding file ids.
|
|
76
103
|
* @property {string} [verb]
|
|
77
104
|
* @property {boolean} [push] Whether a write to this ref pushes a notification.
|
|
105
|
+
* @property {number} [since] The contract that brought it, 0 for one the spec had when its history began.
|
|
78
106
|
*
|
|
79
107
|
* @typedef {object} SpecMeta
|
|
80
108
|
* @property {string} [ns]
|
|
81
109
|
* @property {string} [type] The handle type, on a handle's spec.
|
|
82
110
|
* @property {number} [version]
|
|
111
|
+
* @property {number} [rules] What a write means to Cero, raised by a release that changes it.
|
|
112
|
+
* @property {number} [start] The contract the spec's history begins at.
|
|
113
|
+
* @property {number} [target] The contract this build asks databases to use.
|
|
114
|
+
* @property {{ routes: Record<string, number>, types: Record<string, Record<string, number>> }} [since] The contract that brought each route, and each field of each stored type, by full name.
|
|
115
|
+
* @property {Record<string, number>} [encoding] The schema version to encode with as of each contract.
|
|
83
116
|
* @property {Record<string, RefInfo>} refs
|
|
84
117
|
* @property {{ refs: Record<string, RefInfo> }} [local]
|
|
85
118
|
* @property {Record<string, SpecMeta>} [handles]
|
package/types/lib/swap.d.ts
CHANGED
|
@@ -15,12 +15,30 @@ export declare const nextOf: (dir: string) => string;
|
|
|
15
15
|
export declare function current(dir: string): Promise<string>;
|
|
16
16
|
/**
|
|
17
17
|
* A swap killed part way, finished or undone before anything opens `dir`: past its first rename the incoming
|
|
18
|
-
* identity had opened, so it takes main's place; without it the old one comes back.
|
|
19
|
-
* in `main.next` goes, unless a swap is running there.
|
|
18
|
+
* identity had opened, so it takes main's place; without it the old one comes back.
|
|
20
19
|
*
|
|
21
20
|
* @param {string} dir
|
|
22
21
|
*/
|
|
23
22
|
export declare function settle(dir: string): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* The lock on `dir`, a file beside the stores, held from before a store closes or opens until the one in `main` is
|
|
25
|
+
* open: a store's own lock goes with its close and moves with its directory. Another holder is waited for, a try
|
|
26
|
+
* every few ms; a kill frees it.
|
|
27
|
+
*
|
|
28
|
+
* @param {string} dir
|
|
29
|
+
* @param {number} [timeout] The longest wait in ms, 0 for no limit.
|
|
30
|
+
* @returns {Promise<{ close: () => Promise<void> }>} Held until closed.
|
|
31
|
+
*/
|
|
32
|
+
export declare function lock(dir: string, timeout?: number): Promise<{
|
|
33
|
+
close: () => Promise<void>;
|
|
34
|
+
}>;
|
|
35
|
+
/**
|
|
36
|
+
* What a killed swap left in `main.next` goes, unless a swap is running there. Only once `main` is open: a swap in
|
|
37
|
+
* another process keeps main open while the incoming identity opens.
|
|
38
|
+
*
|
|
39
|
+
* @param {string} dir
|
|
40
|
+
*/
|
|
41
|
+
export declare function sweep(dir: string): Promise<void>;
|
|
24
42
|
/**
|
|
25
43
|
* Run `fn` with `dir/main.next` set aside for it, emptied before and after.
|
|
26
44
|
*
|
|
@@ -31,7 +49,14 @@ export declare function settle(dir: string): Promise<void>;
|
|
|
31
49
|
*/
|
|
32
50
|
export declare function staging<T>(dir: string, fn: () => Promise<T>): Promise<T>;
|
|
33
51
|
/**
|
|
34
|
-
* The identity opened and closed in `main.next
|
|
52
|
+
* The identity opened and closed in `main.next`, all of it on disk: a rename that follows never points at data
|
|
53
|
+
* still in a cache.
|
|
54
|
+
*
|
|
55
|
+
* @param {string} dir
|
|
56
|
+
*/
|
|
57
|
+
export declare function flush(dir: string): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* The identity opened, closed and flushed in `main.next` takes main's place. Both must be closed.
|
|
35
60
|
*
|
|
36
61
|
* @param {string} dir
|
|
37
62
|
*/
|
package/types/push/index.d.ts
CHANGED
|
@@ -1,22 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* A push verified against the
|
|
3
|
-
* rode along and this device holds the handle's keys.
|
|
2
|
+
* A push verified against the handle its topic names, read from that handle's `topics` row alone,
|
|
3
|
+
* with the row it wrote when the block rode along and this device holds the handle's keys.
|
|
4
4
|
*
|
|
5
5
|
* @param {import('hypercore-storage')} storage
|
|
6
6
|
* @param {import('../lib/spec.js').Spec} spec
|
|
7
7
|
* @param {Uint8Array} payload
|
|
8
|
-
* @param {
|
|
8
|
+
* @param {import('@cero-base/core/storage').Storage} store The root's local store, which keeps the `topics` rows.
|
|
9
9
|
* @returns {Promise<{ id: string, type: string, name: string | null, newer: boolean, ref: string | null, row: object | null } | null>}
|
|
10
10
|
*/
|
|
11
|
-
export declare function read(storage: import('hypercore-storage'), spec: import('../lib/spec.js').Spec, payload: Uint8Array,
|
|
12
|
-
id: string;
|
|
13
|
-
handle: string;
|
|
14
|
-
type: string;
|
|
15
|
-
key: Uint8Array;
|
|
16
|
-
name: string | null;
|
|
17
|
-
encryptionKey?: Uint8Array | null;
|
|
18
|
-
epochs?: Uint8Array | null;
|
|
19
|
-
}>): Promise<{
|
|
11
|
+
export declare function read(storage: import('hypercore-storage'), spec: import('../lib/spec.js').Spec, payload: Uint8Array, store: import('@cero-base/core/storage').Storage): Promise<{
|
|
20
12
|
id: string;
|
|
21
13
|
type: string;
|
|
22
14
|
name: string | null;
|
package/types/rpc/client.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ declare const remote: {
|
|
|
11
11
|
del(ref: verbs.Ref, id?: string): Promise<void>;
|
|
12
12
|
call(ref: verbs.Ref, d?: verbs.Row): Promise<void>;
|
|
13
13
|
get(ref: verbs.Ref, q?: string | Record<string, unknown>): Promise<verbs.SingleResult | verbs.ListResult>;
|
|
14
|
+
supports(ref: verbs.Ref, field?: string): Promise<boolean>;
|
|
14
15
|
watch(ref: verbs.Ref, query?: string | (Record<string, unknown> & {
|
|
15
16
|
changes?: boolean;
|
|
16
17
|
}), opts?: {
|
|
@@ -34,6 +35,7 @@ declare const remote: {
|
|
|
34
35
|
deny(ctx: verbs.Context, request: {
|
|
35
36
|
id: string;
|
|
36
37
|
}, reason?: string): Promise<void>;
|
|
38
|
+
removed(ctx: verbs.Context, id: string): Promise<'removed' | 'left' | null>;
|
|
37
39
|
leave(ctx: verbs.Context): Promise<void>;
|
|
38
40
|
close(ctx: verbs.Context): Promise<void>;
|
|
39
41
|
cancel(me: verbs.Context, code: string): Promise<boolean>;
|
|
@@ -64,7 +66,7 @@ declare const remote: {
|
|
|
64
66
|
topic?: string;
|
|
65
67
|
}): Promise<void>;
|
|
66
68
|
};
|
|
67
|
-
export declare const put: typeof verbs.put, set: typeof verbs.set, get: typeof verbs.get, del: typeof verbs.del, watch: typeof verbs.watch, call: typeof verbs.call, open: typeof verbs.open, invite: typeof verbs.invite, revoke: typeof verbs.revoke, rotate: typeof verbs.rotate, accept: typeof verbs.accept, deny: typeof verbs.deny, leave: typeof verbs.leave, close: typeof verbs.close, cancel: typeof verbs.cancel, suspend: typeof verbs.suspend, resume: typeof verbs.resume, activate: typeof verbs.activate, deactivate: typeof verbs.deactivate, phrase: typeof verbs.phrase, nearby: typeof verbs.nearby;
|
|
69
|
+
export declare const put: typeof verbs.put, set: typeof verbs.set, get: typeof verbs.get, del: typeof verbs.del, watch: typeof verbs.watch, call: typeof verbs.call, supports: typeof verbs.supports, open: typeof verbs.open, invite: typeof verbs.invite, revoke: typeof verbs.revoke, rotate: typeof verbs.rotate, accept: typeof verbs.accept, deny: typeof verbs.deny, leave: typeof verbs.leave, removed: typeof verbs.removed, close: typeof verbs.close, cancel: typeof verbs.cancel, suspend: typeof verbs.suspend, resume: typeof verbs.resume, activate: typeof verbs.activate, deactivate: typeof verbs.deactivate, phrase: typeof verbs.phrase, nearby: typeof verbs.nearby;
|
|
68
70
|
export { t, schema };
|
|
69
71
|
export type BaseRPCClient = import('@cero-base/core/rpc').RPCClient;
|
|
70
72
|
export type RefInfo = import('../lib/spec.js').RefInfo;
|
|
@@ -78,9 +80,31 @@ export type HandleStub = {
|
|
|
78
80
|
name: string | null;
|
|
79
81
|
};
|
|
80
82
|
export type Context = (Client | Handle) & Record<string, Ref>;
|
|
83
|
+
export type ClientOpts = {
|
|
84
|
+
/**
|
|
85
|
+
* Where the worker's background errors go, the console without one.
|
|
86
|
+
*/
|
|
87
|
+
onerror?: (err: Error) => void;
|
|
88
|
+
/**
|
|
89
|
+
* The platform's messaging service, to follow the handles' push topics.
|
|
90
|
+
*/
|
|
91
|
+
push?: import('./push.js').Messaging;
|
|
92
|
+
/**
|
|
93
|
+
* On a worker whose store is new, it recovers the identity of this phrase, as `cero(dir, spec, { phrase })`.
|
|
94
|
+
*/
|
|
95
|
+
phrase?: string;
|
|
96
|
+
/**
|
|
97
|
+
* On a worker whose store is new, it links to the identity of this device invite, as `cero(dir, spec, { invite })`.
|
|
98
|
+
*/
|
|
99
|
+
invite?: string;
|
|
100
|
+
/**
|
|
101
|
+
* With `invite`: the request's id as it is sent.
|
|
102
|
+
*/
|
|
103
|
+
onrequest?: (id: string) => void;
|
|
104
|
+
};
|
|
81
105
|
/**
|
|
82
|
-
*
|
|
83
|
-
*
|
|
106
|
+
* Switch the app to the identity of a recovery phrase, as `cero.restore` does in the worker: the
|
|
107
|
+
* client is then that identity.
|
|
84
108
|
*
|
|
85
109
|
* @param {Client} me
|
|
86
110
|
* @param {string} phrase
|
|
@@ -125,6 +149,8 @@ declare class LocalRefs {
|
|
|
125
149
|
* across the wire.
|
|
126
150
|
*/
|
|
127
151
|
export declare class Client extends RPCClient {
|
|
152
|
+
/** @private */
|
|
153
|
+
_how;
|
|
128
154
|
/** @private */
|
|
129
155
|
_push;
|
|
130
156
|
/** @private */
|
|
@@ -146,12 +172,9 @@ export declare class Client extends RPCClient {
|
|
|
146
172
|
/**
|
|
147
173
|
* @param {import('streamx').Duplex} ipc Framed IPC stream (must be writable).
|
|
148
174
|
* @param {Spec} spec Compiled cero spec (schema + rpc + handles).
|
|
149
|
-
* @param {
|
|
175
|
+
* @param {ClientOpts} [opts]
|
|
150
176
|
*/
|
|
151
|
-
constructor(ipc: import('streamx').Duplex, spec: Spec, { onerror, push }?:
|
|
152
|
-
onerror?: (err: Error) => void;
|
|
153
|
-
push?: import('./push.js').Messaging;
|
|
154
|
-
});
|
|
177
|
+
constructor(ipc: import('streamx').Duplex, spec: Spec, { onerror, push, phrase, invite, onrequest }?: ClientOpts);
|
|
155
178
|
/** @private */
|
|
156
179
|
private _pumpErrors;
|
|
157
180
|
/** @private */
|
|
@@ -216,26 +239,20 @@ declare class Handle {
|
|
|
216
239
|
*
|
|
217
240
|
* @param {import('streamx').Duplex} ipc
|
|
218
241
|
* @param {Spec} spec
|
|
219
|
-
* @param {
|
|
242
|
+
* @param {ClientOpts} [opts]
|
|
220
243
|
* @returns {Promise<Client>}
|
|
221
244
|
*/
|
|
222
|
-
export declare function connect(ipc: import('streamx').Duplex, spec: Spec, opts?:
|
|
223
|
-
onerror?: (err: Error) => void;
|
|
224
|
-
push?: import('./push.js').Messaging;
|
|
225
|
-
}): Promise<Client>;
|
|
245
|
+
export declare function connect(ipc: import('streamx').Duplex, spec: Spec, opts?: ClientOpts): Promise<Client>;
|
|
226
246
|
/**
|
|
227
247
|
* Symmetric client entry. Mirrors the main `cero`, but `cero(ipc, spec)` connects to a
|
|
228
248
|
* server (via `connect`) instead of opening a local store.
|
|
229
249
|
*
|
|
230
250
|
* @param {import('streamx').Duplex} ipc Framed IPC duplex stream.
|
|
231
251
|
* @param {Spec} spec Built cero spec.
|
|
232
|
-
* @param {
|
|
252
|
+
* @param {ClientOpts} [opts]
|
|
233
253
|
* @returns {Promise<Context>}
|
|
234
254
|
*/
|
|
235
|
-
declare function start(ipc: import('streamx').Duplex, spec: Spec, opts?:
|
|
236
|
-
onerror?: (err: Error) => void;
|
|
237
|
-
push?: import('./push.js').Messaging;
|
|
238
|
-
}): Promise<Context>;
|
|
255
|
+
declare function start(ipc: import('streamx').Duplex, spec: Spec, opts?: ClientOpts): Promise<Context>;
|
|
239
256
|
/** @type {typeof start & typeof remote & { connect: typeof connect, restore: typeof restore, link: typeof link, t: typeof t, schema: typeof schema }} */
|
|
240
257
|
export declare const cero: typeof start & typeof remote & {
|
|
241
258
|
connect: typeof connect;
|