@cero-base/core 2.12.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.
Files changed (39) hide show
  1. package/package.json +8 -8
  2. package/src/blobs/codec.js +25 -0
  3. package/src/blobs/index.js +5 -2
  4. package/src/blobs/server.js +2 -2
  5. package/src/database/dispatch.js +803 -204
  6. package/src/database/encryption.js +25 -21
  7. package/src/database/index.js +720 -123
  8. package/src/database/rotation.js +333 -38
  9. package/src/lib/constants.js +10 -0
  10. package/src/lib/errors.js +8 -0
  11. package/src/lib/schema.js +12 -2
  12. package/src/lib/spec/index.js +10 -5
  13. package/src/lib/spec/schema.json +13 -1
  14. package/src/lib/utils.js +24 -3
  15. package/src/mailbox/inbox.js +368 -41
  16. package/src/mailbox/index.js +75 -20
  17. package/src/mailbox/post.js +13 -8
  18. package/src/network/index.js +12 -5
  19. package/src/pairing/index.js +343 -57
  20. package/src/pairing/invite.js +36 -12
  21. package/src/pairing/response.js +78 -0
  22. package/src/push/index.js +20 -2
  23. package/types/blobs/codec.d.ts +13 -0
  24. package/types/blobs/index.d.ts +2 -0
  25. package/types/database/dispatch.d.ts +51 -7
  26. package/types/database/encryption.d.ts +13 -5
  27. package/types/database/index.d.ts +190 -19
  28. package/types/database/rotation.d.ts +85 -2
  29. package/types/lib/constants.d.ts +4 -0
  30. package/types/lib/errors.d.ts +6 -0
  31. package/types/lib/schema.d.ts +11 -0
  32. package/types/lib/utils.d.ts +2 -0
  33. package/types/mailbox/inbox.d.ts +78 -10
  34. package/types/mailbox/index.d.ts +42 -16
  35. package/types/mailbox/post.d.ts +7 -5
  36. package/types/pairing/index.d.ts +53 -8
  37. package/types/pairing/invite.d.ts +27 -8
  38. package/types/pairing/response.d.ts +50 -0
  39. package/types/push/index.d.ts +12 -2
@@ -31,6 +31,9 @@ export type DatabaseOpts = {
31
31
  meta?: {
32
32
  ns?: string;
33
33
  version?: number;
34
+ rules?: number;
35
+ start?: number;
36
+ target?: number;
34
37
  refs?: Record<string, {
35
38
  kind?: string;
36
39
  verb?: string;
@@ -60,6 +63,10 @@ export type DatabaseOpts = {
60
63
  * Always search and announce, outside the network's presence budget. The root.
61
64
  */
62
65
  pinned?: boolean;
66
+ /**
67
+ * The identity's own database: a device key past a removed one stands while a device of the identity is seated on it.
68
+ */
69
+ root?: boolean;
63
70
  /**
64
71
  * Push a notification through the mirrors after a local write to a ref whose meta declares `push`, naming the ref, so members learn of it while their app is dead.
65
72
  */
@@ -68,12 +75,16 @@ export type DatabaseOpts = {
68
75
  * This device's writer keypair; a fresh random one by default. Never the identity's, never the database key.
69
76
  */
70
77
  keyPair?: import('../identity/index.js').KeyPair;
78
+ /**
79
+ * A database whose members this one follows: behind there, it is behind here too.
80
+ */
81
+ parent?: Database | null;
71
82
  /**
72
83
  * Called when a node is skipped or refused, or the bee errors.
73
84
  *
74
- * Events: `update` (touched refs, a Set, after each applied batch), `apply` (one per applied
75
- * op: `{ op, name, row, writerKey, seq }`, local and replicated), `writable`, `unwritable`,
76
- * `behind` (an op from a newer app version was skipped).
85
+ * Events: `update` (touched refs, a Set, after each applied batch that changed a row), `apply`
86
+ * (one per applied op: `{ op, name, row, writerKey, seq }`, local and replicated), `writable`,
87
+ * `unwritable`, `behind` (the database's version passed this build's contract).
77
88
  */
78
89
  onerror?: (err: Error) => void;
79
90
  };
@@ -156,19 +167,21 @@ export type HookFn = (ctx: HookContext) => unknown;
156
167
  * @property {import('corestore')} store Corestore (or compatible) used to materialize the autobee.
157
168
  * @property {import('../identity/index.js').Identity} identity Long-lived member identity used to sign writer changes.
158
169
  * @property {import('../network/index.js').Network} [network] Optional swarm; required for multi-writer replication; `store` is its store or a session of it.
159
- * @property {{ database: object, dispatch: { Router: new () => object, encode: (name: string, value: unknown) => Uint8Array, decode: (buf: Uint8Array) => { name: string, value: unknown } }, meta?: { ns?: string, version?: number, refs?: Record<string, { kind?: string, verb?: string }> } }} spec Generated hyperdb + hyperdispatch spec.
170
+ * @property {{ database: object, dispatch: { Router: new () => object, encode: (name: string, value: unknown) => Uint8Array, decode: (buf: Uint8Array) => { name: string, value: unknown } }, meta?: { ns?: string, version?: number, rules?: number, start?: number, target?: number, refs?: Record<string, { kind?: string, verb?: string }> } }} spec Generated hyperdb + hyperdispatch spec.
160
171
  * @property {string} [namespace] Corestore namespace; defaults to `cero`.
161
172
  * @property {Uint8Array} encryptionKey Encrypts it; a join hands it out, so never the identity's on a database you pair.
162
173
  * @property {Array<{ epoch: number, entropy: Uint8Array }> | null} [epochs] Rotation epochs to prime the keyring with (delivered at join).
163
174
  * @property {Uint8Array | null} [key] Existing autobee key to reopen.
164
175
  * @property {boolean} [pinned] Always search and announce, outside the network's presence budget. The root.
176
+ * @property {boolean} [root] The identity's own database: a device key past a removed one stands while a device of the identity is seated on it.
165
177
  * @property {boolean} [push] Push a notification through the mirrors after a local write to a ref whose meta declares `push`, naming the ref, so members learn of it while their app is dead.
166
178
  * @property {import('../identity/index.js').KeyPair} [keyPair] This device's writer keypair; a fresh random one by default. Never the identity's, never the database key.
179
+ * @property {Database | null} [parent] A database whose members this one follows: behind there, it is behind here too.
167
180
  * @property {(err: Error) => void} [onerror] Called when a node is skipped or refused, or the bee errors.
168
181
  *
169
- * Events: `update` (touched refs, a Set, after each applied batch), `apply` (one per applied
170
- * op: `{ op, name, row, writerKey, seq }`, local and replicated), `writable`, `unwritable`,
171
- * `behind` (an op from a newer app version was skipped).
182
+ * Events: `update` (touched refs, a Set, after each applied batch that changed a row), `apply`
183
+ * (one per applied op: `{ op, name, row, writerKey, seq }`, local and replicated), `writable`,
184
+ * `unwritable`, `behind` (the database's version passed this build's contract).
172
185
  *
173
186
  * @typedef {Record<string, unknown>} Row A row, fields by name.
174
187
  * @typedef {{ data: Row | null }} SingleResult
@@ -211,6 +224,9 @@ export declare class Database extends ReadyResource {
211
224
  meta?: {
212
225
  ns?: string;
213
226
  version?: number;
227
+ rules?: number;
228
+ start?: number;
229
+ target?: number;
214
230
  refs?: Record<string, {
215
231
  kind?: string;
216
232
  verb?: string;
@@ -220,6 +236,9 @@ export declare class Database extends ReadyResource {
220
236
  meta: {
221
237
  ns?: string;
222
238
  version?: number;
239
+ rules?: number;
240
+ start?: number;
241
+ target?: number;
223
242
  refs?: Record<string, {
224
243
  kind?: string;
225
244
  verb?: string;
@@ -231,8 +250,23 @@ export declare class Database extends ReadyResource {
231
250
  verb?: string;
232
251
  }>;
233
252
  version: number;
234
- /** @type {number | null} */
235
- behind: number | null;
253
+ rules: number;
254
+ start: number;
255
+ target: number;
256
+ /** @type {Database | null} */
257
+ parent: Database | null;
258
+ /** @private */
259
+ _behind;
260
+ /** @private */
261
+ _skipped;
262
+ /** @private */
263
+ _applied;
264
+ /** @private */
265
+ _landed;
266
+ /** @private */
267
+ _rebuilding;
268
+ /** @private */
269
+ _writes;
236
270
  namespace: string;
237
271
  _writable: boolean;
238
272
  encryptionKey: Uint8Array<ArrayBufferLike>;
@@ -242,6 +276,7 @@ export declare class Database extends ReadyResource {
242
276
  rotation: Rotation;
243
277
  key: Uint8Array<ArrayBufferLike>;
244
278
  pinned: boolean;
279
+ root: boolean;
245
280
  push: boolean;
246
281
  /** @private */
247
282
  _pushes;
@@ -252,11 +287,28 @@ export declare class Database extends ReadyResource {
252
287
  _room;
253
288
  bee: EpochAutobee;
254
289
  dispatcher: {
290
+ encode: (route: string, value: unknown, stamp: number) => Uint8Array;
291
+ cut: (route: string, value: Record<string, unknown>, stamp: number) => Record<string, unknown>;
255
292
  dispatch: (value: Buffer, ctx: object) => Promise<void>;
293
+ role: (view: object, writer: Uint8Array) => Promise<string | null>;
294
+ stands: (view: object, chain: Uint8Array[], telling?: {
295
+ removed?: Uint8Array;
296
+ standing?: Uint8Array;
297
+ }) => Promise<boolean>;
298
+ version: (view: object) => Promise<number>;
299
+ built: (view: object) => Promise<Array<number | null> | null>;
256
300
  apply: (nodes: Array<{
257
301
  value: Buffer;
258
302
  key: Buffer;
259
- }>, view: object, host: object) => Promise<void>;
303
+ version: number;
304
+ }>, view: object, host: object) => Promise<{
305
+ landed: Array<{
306
+ value: Buffer;
307
+ key: Buffer;
308
+ version: number;
309
+ }>;
310
+ changed: boolean;
311
+ }>;
260
312
  };
261
313
  /** @private */
262
314
  _presence;
@@ -296,6 +348,8 @@ export declare class Database extends ReadyResource {
296
348
  get address(): Uint8Array | null;
297
349
  /** @returns {Uint8Array | null} this device's local writer key */
298
350
  get writerKey(): Uint8Array | null;
351
+ /** @returns {number | null} the database's version, or its parent's, while it is past this build's contract */
352
+ get behind(): number | null;
299
353
  /** @returns {boolean} whether the bee accepts local writes */
300
354
  get writable(): boolean;
301
355
  /** @returns {number} number of ops in the local writer */
@@ -305,6 +359,8 @@ export declare class Database extends ReadyResource {
305
359
  /** @private */
306
360
  private _open;
307
361
  /** @private */
362
+ private _wire;
363
+ /** @private */
308
364
  private _close;
309
365
  /**
310
366
  * `true` ranks this database as just touched, `false` takes it out of the swarm until the
@@ -393,9 +449,15 @@ export declare class Database extends ReadyResource {
393
449
  * is open.
394
450
  *
395
451
  * @param {Array<[string, unknown]>} ops
396
- * @returns {Promise<void>}
452
+ * @returns {Promise<number | undefined>} The stamp the last op was appended with; nothing when queued or when nothing changed.
397
453
  */
398
- write(ops: Array<[string, unknown]>): Promise<void>;
454
+ write(ops: Array<[string, unknown]>): Promise<number | undefined>;
455
+ /** @private */
456
+ private _frozen;
457
+ /** @private */
458
+ private _write;
459
+ /** @private */
460
+ private _commit;
399
461
  /** @returns {boolean} Whether a push notification is on its way to the mirrors. */
400
462
  get pushing(): boolean;
401
463
  /** @private */
@@ -422,6 +484,51 @@ export declare class Database extends ReadyResource {
422
484
  * @returns {Promise<'removed' | 'left' | null>}
423
485
  */
424
486
  removed(memberId: string): Promise<'removed' | 'left' | null>;
487
+ /**
488
+ * What a member's devices told this database of her device keys, 32 bytes each: those removed, and those that
489
+ * stand.
490
+ *
491
+ * @param {string} memberId
492
+ * @returns {Promise<{ removed: Uint8Array[], standing: Uint8Array[] }>}
493
+ */
494
+ told(memberId: string): Promise<{
495
+ removed: Uint8Array[];
496
+ standing: Uint8Array[];
497
+ }>;
498
+ /**
499
+ * The keys this database holds as removed, 32 bytes each: a device's own, and a removed member's identity.
500
+ *
501
+ * @returns {Promise<Uint8Array[]>}
502
+ */
503
+ removals(): Promise<Uint8Array[]>;
504
+ /**
505
+ * Who removed a member, from the record of her removal: null while none reached this device, and
506
+ * for one who left on her own.
507
+ *
508
+ * @param {string} memberId
509
+ * @returns {Promise<{ by: string | null } | null>}
510
+ */
511
+ removal(memberId: string): Promise<{
512
+ by: string | null;
513
+ } | null>;
514
+ /**
515
+ * Resolves once another device or a mirror holds every block this device wrote.
516
+ *
517
+ * @returns {Promise<void>}
518
+ */
519
+ held(): Promise<void>;
520
+ /**
521
+ * Whether a device seated here, other than this one and those whose keys are `removed`, wrote a
522
+ * node this view applied with every block this device wrote in its causal past, within `timeout`.
523
+ * A peer that only holds those blocks may be a removed device, which passes them on to no one.
524
+ *
525
+ * @param {Uint8Array[]} removed
526
+ * @param {number} timeout
527
+ * @returns {Promise<boolean>}
528
+ */
529
+ heard(removed: Uint8Array[], timeout: number): Promise<boolean>;
530
+ /** @private */
531
+ private _heard;
425
532
  /** @private */
426
533
  private _read;
427
534
  /**
@@ -441,6 +548,24 @@ export declare class Database extends ReadyResource {
441
548
  * @returns {import('streamx').Readable}
442
549
  */
443
550
  changes(name: string, query?: Query): import('streamx').Readable;
551
+ /**
552
+ * The rows of a collection that changed since `settle` was last called under `mark`, a name of the
553
+ * caller's, so what follows a collection row by row goes on after a restart where it stopped. With no
554
+ * point to start from, `reset` is true and `changes` holds every row. A caller that takes changes and
555
+ * does not settle starts over at its next call. The point is kept on this device only.
556
+ *
557
+ * @param {string} name
558
+ * @param {string} mark
559
+ * @returns {Promise<{ changes: Array<{ prev: Row | null, next: Row | null }>, reset: boolean, settle: () => Promise<void> }>}
560
+ */
561
+ since(name: string, mark: string): Promise<{
562
+ changes: Array<{
563
+ prev: Row | null;
564
+ next: Row | null;
565
+ }>;
566
+ reset: boolean;
567
+ settle: () => Promise<void>;
568
+ }>;
444
569
  /**
445
570
  * Provision this device. Its writer core was minted when the database opened and this
446
571
  * device is its only author, ever.
@@ -458,9 +583,13 @@ export declare class Database extends ReadyResource {
458
583
  writer: import('../identity/index.js').KeyPair;
459
584
  }>;
460
585
  /**
461
- * Seat this device's writer where its identity is a member: wait for the member row, append
462
- * the add-writer the identity signs from this device's own core, and resolve once it writes.
463
- * A member whose role cannot write takes no seat.
586
+ * Seat this device's writer where its identity is a member, or was promised to be one: wait
587
+ * for the member row or the promise, append the add-writer the identity signs from this
588
+ * device's own core, and resolve once it writes. A member whose role cannot write takes no
589
+ * seat; a promise made to her is kept all the same, and resolves at this device's row. A claim
590
+ * that left this device nothing is made again once her member row or a promise made to her is
591
+ * new. Rejects `DENIED`, with the reason, once the room shows this writer turned away: its
592
+ * promise withdrawn.
464
593
  *
465
594
  * @param {{ timeout?: number }} [opts]
466
595
  * @returns {Promise<void>}
@@ -481,17 +610,27 @@ export declare class Database extends ReadyResource {
481
610
  private _onwritable;
482
611
  /**
483
612
  * Learn epochs handed over after the open, as a root carries them for a handle. One is kept
484
- * once its announcement applied here and the secret meets the commitment it carries: hand them
485
- * over again when an announcement applies.
613
+ * once its announcement applied here and the secret meets the commitment it carries; one whose
614
+ * announcement has not applied yet waits for it, and is checked then.
486
615
  *
487
616
  * @param {Array<{ epoch: number, stamp: number, entropy: Uint8Array }>} epochs
617
+ * @param {string} [from] The device that sent them, when one did.
488
618
  * @returns {Promise<void>}
489
619
  */
490
620
  learn(epochs: Array<{
491
621
  epoch: number;
492
622
  stamp: number;
493
623
  entropy: Uint8Array;
494
- }>): Promise<void>;
624
+ }>, from?: string): Promise<void>;
625
+ /**
626
+ * @returns {Promise<boolean>} Whether this device asked for keys it lacks and its ask still stands.
627
+ */
628
+ owed(): Promise<boolean>;
629
+ /**
630
+ * @returns {Promise<boolean>} Whether every device this database removed is out of the key this
631
+ * device writes under: no rotation is owed, and this device holds the newest key.
632
+ */
633
+ rotated(): Promise<boolean>;
495
634
  /**
496
635
  * Remove a peer's writer key from the indexer set.
497
636
  *
@@ -522,6 +661,8 @@ export declare class Database extends ReadyResource {
522
661
  /** @private */
523
662
  private _preload;
524
663
  /** @private */
664
+ private _onWriter;
665
+ /** @private */
525
666
  private _boot;
526
667
  /** @private */
527
668
  private _replay;
@@ -544,6 +685,8 @@ export declare class Database extends ReadyResource {
544
685
  /** @param {string} name @param {() => void} fn @returns {() => void} */
545
686
  onUpdate(name: string, fn: () => void): () => void;
546
687
  /** @private */
688
+ private _joins;
689
+ /** @private */
547
690
  private _opOf;
548
691
  /** @private */
549
692
  private _notify;
@@ -556,7 +699,29 @@ export declare class Database extends ReadyResource {
556
699
  /** @private */
557
700
  private _done;
558
701
  /** @private */
559
- private _onfuture;
702
+ private _build;
703
+ /** @private */
704
+ private _foreign;
705
+ /** @private */
706
+ private _onmove;
707
+ /** @private */
708
+ private _rebuild;
709
+ /** @private */
710
+ private _wipe;
711
+ /** @private */
712
+ private _skip;
713
+ /** @private */
714
+ private _track;
715
+ /** @private */
716
+ private _raise;
717
+ /** @private */
718
+ private _raises;
719
+ /** @private */
720
+ private _changes;
721
+ /** @private */
722
+ private _stamp;
723
+ /** @private */
724
+ private _seatless;
560
725
  /** @private */
561
726
  private _dryRun;
562
727
  /** @private */
@@ -566,6 +731,12 @@ export declare class Database extends ReadyResource {
566
731
  /** @private */
567
732
  private _member;
568
733
  /** @private */
734
+ private _standing;
735
+ /** @private */
736
+ private _kept;
737
+ /** @private */
738
+ private _refused;
739
+ /** @private */
569
740
  private _admission;
570
741
  /** @private */
571
742
  private _admit;
@@ -9,12 +9,20 @@ export declare class Rotation {
9
9
  stamp: number;
10
10
  epoch: number;
11
11
  };
12
+ /** @type {Promise<void> | null} Pending while a removal and its rotation go in. */
13
+ carrying: Promise<void> | null;
12
14
  /** @private */
13
15
  _queue;
14
16
  /** @private */
15
17
  _timer;
16
18
  /** @private */
17
19
  _healedFor;
20
+ /** @private */
21
+ _kept;
22
+ /** @private */
23
+ _aside;
24
+ /** @private */
25
+ _met;
18
26
  /** @param {import('./index.js').Database} db */
19
27
  constructor(db: import('./index.js').Database);
20
28
  close(): void;
@@ -27,6 +35,17 @@ export declare class Rotation {
27
35
  rotate(): Promise<{
28
36
  epoch: number;
29
37
  }>;
38
+ /**
39
+ * A removal by a device that may remove carries its rotation: the removal, then the key sealed
40
+ * to the devices that stay and to those still promised a seat, with nothing else of this device
41
+ * in between. The key is a block of its own, so it lands even when a reorder refuses the removal.
42
+ *
43
+ * @param {Array<[string, unknown]>} ops A batch that takes a member or a device out.
44
+ * @returns {Promise<number | undefined>} What the removal's write resolves.
45
+ */
46
+ carry(ops: Array<[string, unknown]>): Promise<number | undefined>;
47
+ /** @private */
48
+ private _queued;
30
49
  /**
31
50
  * An applied rotation announcement: open our envelope, learn the secret, persist it.
32
51
  *
@@ -38,18 +57,71 @@ export declare class Rotation {
38
57
  wrapped: Uint8Array;
39
58
  commit: Uint8Array;
40
59
  }): Promise<void>;
60
+ /**
61
+ * A block met under a key this device does not hold: a rotation set aside is opened now.
62
+ *
63
+ * @param {number} stamp
64
+ * @returns {Uint8Array | null}
65
+ */
66
+ meet(stamp: number): Uint8Array | null;
67
+ /**
68
+ * A secret handed over before its announcement landed here: kept, and checked against the
69
+ * commitment when it does.
70
+ *
71
+ * @param {{ epoch: number, stamp: number, entropy: Uint8Array }} e
72
+ * @param {string} [from] The device that sent it: each sender has slots of its own.
73
+ */
74
+ keep(e: {
75
+ epoch: number;
76
+ stamp: number;
77
+ entropy: Uint8Array;
78
+ }, from?: string): void;
79
+ /** @private */
80
+ private _handed;
81
+ /**
82
+ * @returns {Promise<boolean>} Whether this device cannot open the log's newest key, or one set
83
+ * aside that a block it met was written under.
84
+ */
85
+ lacks(): Promise<boolean>;
86
+ /** @private */
87
+ private _lacking;
41
88
  /**
42
89
  * Safety net after boot: an epoch applied but never saved, e.g. a crash between a
43
90
  * rotation's append and its save, is learned from the epochs collection.
44
91
  */
45
92
  hydrate(): Promise<void>;
46
- /** Debounced audit, run after every update. */
93
+ /**
94
+ * The secret held for a row, if it meets the row's commitment.
95
+ *
96
+ * @param {{ stamp: number, commit: Uint8Array }} row
97
+ * @returns {Uint8Array | null}
98
+ */
99
+ held(row: {
100
+ stamp: number;
101
+ commit: Uint8Array;
102
+ }): Uint8Array | null;
103
+ /**
104
+ * Write under the newest landed epoch whose secret this device holds, so a rotation a reorder
105
+ * dropped is never written under.
106
+ *
107
+ * @param {object} [view]
108
+ */
109
+ pick(view?: object): Promise<void>;
110
+ /** Debounced key check, with the owner's raise beside it, run at open and after every update. */
47
111
  heal(): void;
48
112
  /** @private */
113
+ private _carry;
114
+ /** @private */
115
+ private _staying;
116
+ /** @private */
49
117
  private _rotate;
50
118
  /** @private */
51
119
  private _devices;
52
120
  /** @private */
121
+ private _promised;
122
+ /** @private */
123
+ private _stands;
124
+ /** @private */
53
125
  private _announce;
54
126
  /** @private */
55
127
  private _mint;
@@ -64,5 +136,16 @@ export declare class Rotation {
64
136
  /** @private */
65
137
  private _audit;
66
138
  /** @private */
67
- private _heal;
139
+ private _due;
140
+ /** @private */
141
+ private _drift;
142
+ /** @private */
143
+ private _ask;
144
+ /** @private */
145
+ private _unnamed;
68
146
  }
147
+ /**
148
+ * @param {Array<[string, unknown]>} ops
149
+ * @returns {boolean} Whether a batch takes a member or a device out.
150
+ */
151
+ export declare function removes(ops: Array<[string, unknown]>): boolean;
@@ -29,7 +29,11 @@ export declare const RANK: {
29
29
  export declare const NAMESPACE = "cero";
30
30
  export declare const QUERY_RESERVED: Set<string>;
31
31
  export declare const COUNTERS = "counters";
32
+ export declare const VERSION = "_version";
33
+ export declare const BUILT: string[];
34
+ export declare const OWED = "_owed";
32
35
  export declare const EPOCHS = "epochs";
33
36
  export declare const REMOVALS = "removals";
34
37
  export declare const REFUSALS = "refusals";
35
38
  export declare const SPENT = "spent";
39
+ export declare const ASKS = "owed";
@@ -110,6 +110,12 @@ export declare class CeroError extends Error {
110
110
  * @param {string} [msg]
111
111
  */
112
112
  static DENIED(reason?: string | null, msg?: string): CeroError;
113
+ /**
114
+ * A join given up with `cancel` before it was answered.
115
+ *
116
+ * @param {string} [msg]
117
+ */
118
+ static CANCELLED(msg?: string): CeroError;
113
119
  /**
114
120
  * An apply-time rule refused the op. Every peer reaches this verdict from the same node
115
121
  * and the same view, so it aborts the writer's whole batch — which is what makes a
@@ -1,6 +1,7 @@
1
1
  export type Prim = {
2
2
  prim: string;
3
3
  required?: boolean;
4
+ later?: boolean;
4
5
  };
5
6
  export type TypeDef = {
6
7
  kind: 'single' | 'collection' | 'action';
@@ -8,6 +9,7 @@ export type TypeDef = {
8
9
  indexes?: Record<string, string[]>;
9
10
  own?: boolean;
10
11
  push?: boolean;
12
+ later?: boolean;
11
13
  };
12
14
  export type SchemaDefs = {
13
15
  [name: string]: TypeDef | Record<string, TypeDef>;
@@ -38,6 +40,15 @@ export declare const t: {
38
40
  * @returns {Prim}
39
41
  */
40
42
  required: (marker: Prim) => Prim;
43
+ /**
44
+ * Hold back a field, a collection, a single or an action: a database starts using it once a
45
+ * build without the mark reaches its owner's device. What databases use already cannot be held.
46
+ *
47
+ * @template {Prim | TypeDef} T
48
+ * @param {T} def
49
+ * @returns {T}
50
+ */
51
+ later: <T extends Prim | TypeDef>(def: T) => T;
41
52
  /**
42
53
  * Single-row table (one record, set/get by name).
43
54
  *
@@ -17,6 +17,8 @@ export declare function isRank(role: string): boolean;
17
17
  export declare function grants(a: string, b: string): boolean;
18
18
  /** @type {(a: string, b: string) => boolean} */
19
19
  export declare function outranks(a: string, b: string): boolean;
20
+ /** @type {(value: unknown) => boolean} */
21
+ export declare function isOptions(value: unknown): boolean;
20
22
  /**
21
23
  * Stream-of-snapshots primitive. Couples a `get` (returns the latest value) with a `watch`
22
24
  * (re-fires on change) and emits the newest snapshot every time `watch` ticks.