@cero-base/cero 2.2.1 → 2.3.1

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 (42) hide show
  1. package/README.md +24 -16
  2. package/package.json +7 -6
  3. package/src/build/index.js +38 -34
  4. package/src/build/internal.js +96 -11
  5. package/src/build/schemas.js +119 -19
  6. package/src/extensions/handle-sync.js +8 -12
  7. package/src/extensions/index.js +17 -63
  8. package/src/extensions/mirror.js +44 -0
  9. package/src/extensions/profile-sync.js +10 -12
  10. package/src/handle/index.js +499 -374
  11. package/src/handle/join.js +144 -0
  12. package/src/index.js +91 -119
  13. package/src/lib/bluetooth.js +83 -19
  14. package/src/lib/constants.js +1 -0
  15. package/src/lib/operators.js +296 -128
  16. package/src/lib/peek.js +1 -1
  17. package/src/lib/refs.js +7 -7
  18. package/src/lib/spec.js +32 -0
  19. package/src/local/index.js +27 -3
  20. package/src/rpc/client.js +247 -205
  21. package/src/rpc/server.js +186 -133
  22. package/types/build/index.d.ts +3 -8
  23. package/types/build/internal.d.ts +86 -27
  24. package/types/build/schemas.d.ts +91 -12
  25. package/types/extensions/handle-sync.d.ts +4 -12
  26. package/types/extensions/index.d.ts +59 -59
  27. package/types/extensions/mirror.d.ts +13 -0
  28. package/types/extensions/profile-sync.d.ts +4 -13
  29. package/types/handle/index.d.ts +229 -198
  30. package/types/handle/join.d.ts +63 -0
  31. package/types/index.d.ts +36 -53
  32. package/types/lib/bluetooth.d.ts +57 -19
  33. package/types/lib/constants.d.ts +1 -0
  34. package/types/lib/operators.d.ts +166 -81
  35. package/types/lib/peek.d.ts +2 -2
  36. package/types/lib/refs.d.ts +14 -15
  37. package/types/lib/spec.d.ts +87 -0
  38. package/types/local/index.d.ts +19 -9
  39. package/types/rpc/client.d.ts +110 -93
  40. package/types/rpc/server.d.ts +91 -50
  41. package/src/rpc/index.js +0 -8
  42. package/types/rpc/index.d.ts +0 -7
package/types/index.d.ts CHANGED
@@ -1,27 +1,23 @@
1
1
  import { Identity } from '@cero-base/core/identity';
2
2
  import { Handle, Ref } from './handle/index.js';
3
3
  import { Local } from './local/index.js';
4
- import { put, set, get, del, watch, changes, call, open, rotate, before, after } from './lib/operators.js';
4
+ import * as verbs from './lib/operators.js';
5
5
  import { peek } from './lib/peek.js';
6
6
  import { t, schema } from './lib/spec.js';
7
7
  export { Handle, Ref, Local };
8
- export { put, set, get, del, watch, changes, call, open, rotate, before, after } from './lib/operators.js';
8
+ export * from './lib/operators.js';
9
9
  export { peek } from './lib/peek.js';
10
10
  export { t, schema } from './lib/spec.js';
11
- export type CeroHandle = import('./handle/index.js').CeroHandle;
11
+ export type Context = import('./handle/index.js').Context;
12
12
  export type CeroOpts = {
13
13
  /**
14
- * Pre-resolved identity. If absent, derived from `seed`/`phrase` or generated.
14
+ * Pre-resolved identity. If absent, derived from `seed` or generated.
15
15
  */
16
16
  identity?: Identity;
17
17
  /**
18
- * 16- or 32-byte seed entropy.
18
+ * 16- or 32-byte seed entropy: `toSeed(phrase)` restores from a phrase.
19
19
  */
20
20
  seed?: Uint8Array;
21
- /**
22
- * BIP-39 mnemonic — alternative to `seed`.
23
- */
24
- phrase?: string;
25
21
  /**
26
22
  * Mnemonic length when generating a fresh identity.
27
23
  */
@@ -70,13 +66,9 @@ export type CeroOpts = {
70
66
  */
71
67
  encryptionKey?: Uint8Array;
72
68
  /**
73
- * Custom RPC routes for the database dispatcher.
69
+ * Where background errors go; the console without one.
74
70
  */
75
- routes?: Record<string, Function>;
76
- /**
77
- * Background-task error handler; without one, errors emit 'error' on the root handle.
78
- */
79
- onerror?: (err: any) => void;
71
+ onerror?: (err: Error) => void;
80
72
  /**
81
73
  * Max wait to find another device and be admitted, in ms. Defaults to 30000.
82
74
  */
@@ -90,28 +82,23 @@ export type CeroOpts = {
90
82
  */
91
83
  extensions?: import('./extensions/index.js').Extension[];
92
84
  /**
93
- * The operators to bind, instead of the ones the spec carries.
94
- */
95
- operators?: Record<string, any>;
96
- /**
97
- * `true` enables nearby (Bluetooth) sync via `me.bluetooth` (auto-started). `{ autoStart: false }` creates the facade without starting the radio — the app calls `me.bluetooth.start()`/`stop()` (user toggle). `backend` injects a bare-bluetooth-shaped backend (tests). `maxOutbound`/`maxInbound` cap concurrent outbound links and inbound sessions. `pipe` picks the data pipe — `'l2cap'` (default, faster) or `'gatt'`; both peers must match. Absent backend on an unsupported host → `me.bluetooth.state === 'unsupported'`.
85
+ * `true` enables nearby (Bluetooth) sync, the radio on. `{ autoStart: false }` leaves it off until `cero.nearby(me, true)`. `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. Without a backend on the host, `me.status` reports `nearby: 'unsupported'`.
98
86
  */
99
87
  bluetooth?: boolean | {
100
88
  autoStart?: boolean;
101
- backend?: any;
89
+ backend?: object;
102
90
  maxOutbound?: number;
103
91
  maxInbound?: number;
104
92
  pipe?: 'l2cap' | 'gatt';
105
93
  };
106
94
  };
107
95
  /**
108
- * @typedef {import('./handle/index.js').CeroHandle} CeroHandle
96
+ * @typedef {import('./handle/index.js').Context} Context
109
97
  */
110
98
  /**
111
99
  * @typedef {object} CeroOpts
112
- * @property {Identity} [identity] Pre-resolved identity. If absent, derived from `seed`/`phrase` or generated.
113
- * @property {Uint8Array} [seed] 16- or 32-byte seed entropy.
114
- * @property {string} [phrase] BIP-39 mnemonic — alternative to `seed`.
100
+ * @property {Identity} [identity] Pre-resolved identity. If absent, derived from `seed` or generated.
101
+ * @property {Uint8Array} [seed] 16- or 32-byte seed entropy: `toSeed(phrase)` restores from a phrase.
115
102
  * @property {12 | 24} [words] Mnemonic length when generating a fresh identity.
116
103
  * @property {string | null} [name] Friendly device name persisted on the identity claim.
117
104
  * @property {boolean} [isMobile] Marks this device as mobile.
@@ -122,45 +109,41 @@ export type CeroOpts = {
122
109
  * @property {{ active?: number, announced?: number, idle?: number }} [presence] How many rooms search, how many only announce, and the idle ms before the rest leave the swarm.
123
110
  * @property {Uint8Array} [key] Existing database key to recover into, skipping the pointer lookup.
124
111
  * @property {Uint8Array} [encryptionKey] Pre-existing encryption key.
125
- * @property {Record<string, Function>} [routes] Custom RPC routes for the database dispatcher.
126
- * @property {(err: any) => void} [onerror] Background-task error handler; without one, errors emit 'error' on the root handle.
112
+ * @property {(err: Error) => void} [onerror] Where background errors go; the console without one.
127
113
  * @property {number} [recoveryTimeout] Max wait to find another device and be admitted, in ms. Defaults to 30000.
128
114
  * @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.
129
115
  * @property {import('./extensions/index.js').Extension[]} [extensions] The extensions this instance runs, instead of the ones the spec carries. Build with the same list.
130
- * @property {Record<string, any>} [operators] The operators to bind, instead of the ones the spec carries.
131
- * @property {boolean | { autoStart?: boolean, backend?: any, maxOutbound?: number, maxInbound?: number, pipe?: 'l2cap' | 'gatt' }} [bluetooth] `true` enables nearby (Bluetooth) sync via `me.bluetooth` (auto-started). `{ autoStart: false }` creates the facade without starting the radio — the app calls `me.bluetooth.start()`/`stop()` (user toggle). `backend` injects a bare-bluetooth-shaped backend (tests). `maxOutbound`/`maxInbound` cap concurrent outbound links and inbound sessions. `pipe` picks the data pipe — `'l2cap'` (default, faster) or `'gatt'`; both peers must match. Absent backend on an unsupported host → `me.bluetooth.state === 'unsupported'`.
116
+ * @property {boolean | { autoStart?: boolean, backend?: object, maxOutbound?: number, maxInbound?: number, pipe?: 'l2cap' | 'gatt' }} [bluetooth] `true` enables nearby (Bluetooth) sync, the radio on. `{ autoStart: false }` leaves it off until `cero.nearby(me, true)`. `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. Without a backend on the host, `me.status` reports `nearby: 'unsupported'`.
132
117
  */
133
118
  /**
134
119
  * Open (or create) a cero handle at `dir`.
135
120
  *
136
121
  * @param {string} dir Data directory.
137
- * @param {any} spec Built spec — output of `cero/build`.
122
+ * @param {import('./lib/spec.js').Spec} spec Built spec, the output of `cero/build`.
138
123
  * @param {CeroOpts} [opts]
139
- * @returns {Promise<CeroHandle>}
124
+ * @returns {Promise<Context>}
140
125
  */
141
- export declare function cero(dir: string, spec: any, opts?: CeroOpts): Promise<CeroHandle>;
142
- export declare namespace cero {
143
- export { t };
144
- export { put };
145
- export { set };
146
- export { get };
147
- export { del };
148
- export { watch };
149
- export { changes };
150
- export { call };
151
- export { open };
152
- export { rotate };
153
- export { before };
154
- export { after };
155
- export { peek };
156
- export { restore };
157
- export { schema };
158
- }
126
+ declare function start(dir: string, spec: import('./lib/spec.js').Spec, opts?: CeroOpts): Promise<Context>;
159
127
  /**
160
- * Restore a cero instance from a mnemonic phrase.
128
+ * Restore a cero instance from a seed.
161
129
  *
162
- * @param {Handle} me Existing root handle to restore.
163
- * @param {string} phrase BIP-39 mnemonic phrase.
130
+ * @param {Context} me The root to restore.
131
+ * @param {Uint8Array} seed The identity's seed: `toSeed(phrase)` from a phrase.
164
132
  * @returns {Promise<Handle>} Freshly restored root handle.
165
133
  */
166
- export declare function restore(me: Handle, phrase: string): Promise<Handle>;
134
+ export declare function restore(me: Context, seed: Uint8Array): Promise<Handle>;
135
+ /**
136
+ * The seed a BIP-39 phrase writes out, for `cero(dir, spec, { seed })` and `restore(me, seed)`.
137
+ *
138
+ * @param {string} phrase
139
+ * @returns {Uint8Array}
140
+ */
141
+ export declare function toSeed(phrase: string): Uint8Array;
142
+ /** @type {typeof start & typeof verbs & { t: typeof t, schema: typeof schema, peek: typeof peek, restore: typeof restore, toSeed: typeof toSeed }} */
143
+ export declare const cero: typeof start & typeof verbs & {
144
+ t: typeof t;
145
+ schema: typeof schema;
146
+ peek: typeof peek;
147
+ restore: typeof restore;
148
+ toSeed: typeof toSeed;
149
+ };
@@ -6,28 +6,41 @@ import ReadyResource from 'ready-resource';
6
6
  * @extends ReadyResource
7
7
  */
8
8
  export declare class Bluetooth extends ReadyResource {
9
- _handle: object;
10
- _autoStart: boolean;
11
- /** @type {{ hex: string, count: number, timer: any } | null} active invite rendezvous (single topic — one at a time) */
9
+ /** @private */
10
+ _network;
11
+ /** @private */
12
+ _autoStart;
13
+ /** @type {{ hex: string, count: number, timer: ReturnType<typeof setTimeout> | null } | null} active invite rendezvous (single topic — one at a time) */
12
14
  _announce: {
13
15
  hex: string;
14
16
  count: number;
15
- timer: any;
17
+ timer: ReturnType<typeof setTimeout> | null;
16
18
  } | null;
17
- _restorePending: boolean;
18
- _topic: any;
19
- swarm: any;
19
+ /** @private */
20
+ _restorePending;
21
+ /** @private */
22
+ _topic;
23
+ /** @private */
24
+ _id;
25
+ /** @private */
26
+ _proof;
27
+ /** @type {import('ble-swarm')} */
28
+ swarm: import('ble-swarm');
20
29
  /**
21
- * @param {object} handle Root cero Handle (network + identity + channel).
22
- * @param {object} [opts]
23
- * @param {any} [opts.backend] Injected bare-bluetooth-shaped backend (tests); omitted → ble-swarm loads its own, null/false → unsupported.
24
- * @param {boolean} [opts.autoStart] Start on handle open (from `cero({ bluetooth: true })`).
30
+ * @param {import('@cero-base/core/network').Network} network Where links go: its channel scopes the mesh.
31
+ * @param {object} opts
32
+ * @param {import('@cero-base/core/identity').Identity} opts.identity Signs this device's key for the peers it links with.
33
+ * @param {import('@cero-base/core/identity').KeyPair} opts.keyPair This device's writer keypair.
34
+ * @param {object | null} [opts.backend] Injected bare-bluetooth-shaped backend (tests); omitted → ble-swarm loads its own, null/false → unsupported.
35
+ * @param {boolean} [opts.autoStart] Start on open (from `cero({ bluetooth: true })`).
25
36
  * @param {number} [opts.maxOutbound] Max concurrent outbound links; gossip covers the rest.
26
37
  * @param {number} [opts.maxInbound] Max concurrent inbound sessions; newcomers past this are refused.
27
38
  * @param {'l2cap' | 'gatt'} [opts.pipe] Data pipe — 'l2cap' (default, faster) or 'gatt'. Both peers must match.
28
39
  */
29
- constructor(handle: object, { backend, autoStart, maxOutbound, maxInbound, pipe }?: {
30
- backend?: any;
40
+ constructor(network: import('@cero-base/core/network').Network, { identity, keyPair, backend, autoStart, maxOutbound, maxInbound, pipe }: {
41
+ identity: import('@cero-base/core/identity').Identity;
42
+ keyPair: import('@cero-base/core/identity').KeyPair;
43
+ backend?: object | null;
31
44
  autoStart?: boolean;
32
45
  maxOutbound?: number;
33
46
  maxInbound?: number;
@@ -35,10 +48,33 @@ export declare class Bluetooth extends ReadyResource {
35
48
  });
36
49
  /** @returns {'unsupported'|'unauthorized'|'off'|'waiting'|'starting'|'on'} */
37
50
  get state(): 'unsupported' | 'unauthorized' | 'off' | 'waiting' | 'starting' | 'on';
38
- /** @returns {Map<string, any>} Live BLE links, keyed by peer public key. */
39
- get peers(): Map<string, any>;
40
- _open(): Promise<void>;
41
- _close(): Promise<void>;
51
+ /** @returns {Map<string, object>} Live BLE links, keyed by peer public key. */
52
+ get peers(): Map<string, object>;
53
+ /** @private */
54
+ private _open;
55
+ /** @private */
56
+ private _close;
57
+ /**
58
+ * What a peer hears when a Bluetooth link opens: whose device this is, signed, with `info`.
59
+ *
60
+ * @param {{ name: string | null, isMobile: boolean }} info
61
+ */
62
+ tell({ name, isMobile }: {
63
+ name: string | null;
64
+ isMobile: boolean;
65
+ }): void;
66
+ /**
67
+ * Who a linked device says it is: its person, who signed the key it links with, its name and
68
+ * whether it is a phone. `null` until it said, or when that signature is not its person's.
69
+ *
70
+ * @param {string} hex A key of `peers`.
71
+ * @returns {{ id: string, name: string | null, isMobile: boolean } | null}
72
+ */
73
+ told(hex: string): {
74
+ id: string;
75
+ name: string | null;
76
+ isMobile: boolean;
77
+ } | null;
42
78
  /**
43
79
  * Begin advertising + scanning. Idempotent; no-op when unsupported.
44
80
  *
@@ -71,6 +107,8 @@ export declare class Bluetooth extends ReadyResource {
71
107
  * @returns {Promise<void>}
72
108
  */
73
109
  resume(): Promise<void>;
74
- _stopAnnounce(): void;
75
- _clearAnnounce(): void;
110
+ /** @private */
111
+ private _stopAnnounce;
112
+ /** @private */
113
+ private _clearAnnounce;
76
114
  }
@@ -1,5 +1,6 @@
1
1
  export declare const NS = "cero";
2
2
  export declare const COUNTERS = "counters";
3
3
  export declare const EPOCHS = "epochs";
4
+ export declare const REMOVALS = "removals";
4
5
  export declare const TIMEOUT = 30000;
5
6
  export declare const FLUSH = 500;
@@ -1,60 +1,28 @@
1
1
  export type Ref = import('./refs.js').Ref;
2
2
  export type HookContext = import('@cero-base/core/database').HookContext;
3
- export type CeroHandle = import('../handle/index.js').CeroHandle;
4
- export type SingleResult = {
5
- data: any;
6
- };
7
- export type ListResult = {
8
- data: any[];
9
- total: number;
10
- size: number;
11
- };
12
- export type GetByIdResult = {
13
- data: any | null;
14
- };
15
- /**
16
- * @typedef {import('./refs.js').Ref} Ref
17
- * @typedef {import('@cero-base/core/database').HookContext} HookContext
18
- * @typedef {import('../handle/index.js').CeroHandle} CeroHandle
19
- * @typedef {{ data: any }} SingleResult
20
- * @typedef {{ data: any[], total: number, size: number }} ListResult
21
- * @typedef {{ data: any | null }} GetByIdResult
22
- */
23
- /**
24
- * Resolve a durable file id (+ optional name) to the read shape returned
25
- * everywhere: `{ id, name?, type, size, url }`.
26
- *
27
- * @param {object} handle
28
- * @param {string} id
29
- * @param {string} [name]
30
- * @returns {{ id: string, type: string, size: number, url: string, name?: string }}
31
- */
32
- export declare function resolveFile(handle: object, id: string, name?: string): {
33
- id: string;
34
- type: string;
35
- size: number;
36
- url: string;
37
- name?: string;
38
- };
3
+ export type Context = import('../handle/index.js').Context | import('../rpc/client.js').Context;
4
+ export type Row = import('@cero-base/core/database').Row;
5
+ export type SingleResult = import('@cero-base/core/database').SingleResult;
6
+ export type ListResult = import('@cero-base/core/database').ListResult;
39
7
  /**
40
8
  * Insert (or overwrite by id) a row on `ref`.
41
9
  *
42
10
  * @param {Ref} ref
43
- * @param {Record<string, any>} row
11
+ * @param {Row} row
44
12
  * @returns {Promise<SingleResult>}
45
13
  */
46
- export declare function put(ref: Ref, row: Record<string, any>): Promise<SingleResult>;
14
+ export declare function put(ref: Ref, row: Row): Promise<SingleResult>;
47
15
  /**
48
16
  * Upsert a row on `ref` — merges with the existing row and preserves `createdAt`.
49
17
  *
50
18
  * @param {Ref} ref
51
- * @param {Record<string, any>} row
19
+ * @param {Row} row
52
20
  * @param {{ upsert?: boolean }} [opts]
53
- * @returns {Promise<SingleResult>}
21
+ * @returns {Promise<SingleResult | null>}
54
22
  */
55
- export declare function set(ref: Ref, row: Record<string, any>, opts?: {
23
+ export declare function set(ref: Ref, row: Row, opts?: {
56
24
  upsert?: boolean;
57
- }): Promise<SingleResult>;
25
+ }): Promise<SingleResult | null>;
58
26
  /**
59
27
  * Delete a row by id (collection refs), or wipe the row (single refs).
60
28
  *
@@ -67,19 +35,20 @@ export declare function del(ref: Ref, id?: string): Promise<void>;
67
35
  * Invoke an `action`-kind ref (a custom mutation declared in the schema).
68
36
  *
69
37
  * @param {Ref} ref
70
- * @param {Record<string, any>} [d]
71
- * @returns {Promise<any>}
38
+ * @param {Row} [d]
39
+ * @returns {Promise<void>}
72
40
  */
73
- export declare function call(ref: Ref, d?: Record<string, any>): Promise<any>;
41
+ export declare function call(ref: Ref, d?: Row): Promise<void>;
74
42
  /**
75
- * Rule that runs before a write to `ref` lands — at apply, on every peer, inside the op's
76
- * transaction. Return `false` to refuse it: the writer's own call rejects with `REFUSED`.
77
- * `ctx` is `{ op, name, row, existing, id, memberId, role, get, put, set, del }`; mutate
78
- * `ctx.row` to rewrite what is stored. `op` is the op as it applies, so an upsert on a
79
- * collection is a `put`. The four operators on `ctx` read and write the room as it stands at
80
- * this op, inside the transaction. Must be deterministic — read only `ctx`, never a clock or
81
- * local state — and registered before any op applies, in the process that owns the data. The
82
- * imported operators throw inside a hook; use the ones on `ctx`. Not available over RPC.
43
+ * Rule that runs before a write to `ref` lands, or before an action does: at apply, on every
44
+ * peer, inside the op's transaction. Return `false` to refuse it: the writer's own call rejects
45
+ * with `REFUSED`. `ctx` is `{ op, name, row, existing, id, memberId, role, get, put, set, del }`;
46
+ * mutate `ctx.row` to rewrite what is stored. `op` is the op as it applies, so an upsert on a
47
+ * collection is a `put`. The four operators on `ctx` read and write the room as it stands at this
48
+ * op, inside the transaction. Must be deterministic: read only `ctx`, never a clock or local
49
+ * state. On a type ref (`me.room.notes`) it reaches every room of the type before the room
50
+ * opens; register in an extension's `setup` to see every op the root applies too. The imported
51
+ * operators throw inside a hook; use the ones on `ctx`. Not available over RPC.
83
52
  *
84
53
  * @param {Ref} ref
85
54
  * @param {(ctx: HookContext) => unknown} fn
@@ -90,10 +59,10 @@ export declare function before(ref: Ref, fn: (ctx: HookContext) => unknown, opts
90
59
  signal?: AbortSignal;
91
60
  }): () => void;
92
61
  /**
93
- * Rule that runs after a write to `ref` lands — at apply, on every peer, inside the op's
94
- * transaction. Write derived rows through `ctx.put` / `ctx.set` / `ctx.del`; a throw refuses
95
- * the whole op. Same `ctx` and the same determinism and registration rules as `before`. Use
96
- * `changes(ref)` instead to observe writes locally.
62
+ * Rule that runs after a write to `ref` lands, at apply, on every peer, inside the op's
63
+ * transaction. On an action it is what the action does. Write derived rows through `ctx.put` /
64
+ * `ctx.set` / `ctx.del`; a throw refuses the whole op. Same `ctx`, determinism and reach as
65
+ * `before`. Use `watch(ref)` instead to observe writes locally.
97
66
  *
98
67
  * @param {Ref} ref
99
68
  * @param {(ctx: HookContext) => unknown} fn
@@ -107,51 +76,167 @@ export declare function after(ref: Ref, fn: (ctx: HookContext) => unknown, opts?
107
76
  * Read from `ref`. For data refs, dispatches to the underlying store.
108
77
  *
109
78
  * @param {Ref} ref
110
- * @param {string | Record<string, any>} [q]
111
- * @returns {Promise<SingleResult | ListResult | GetByIdResult>}
79
+ * @param {string | Record<string, unknown>} [q]
80
+ * @returns {Promise<SingleResult | ListResult>}
112
81
  */
113
- export declare function get(ref: Ref, q?: string | Record<string, any>): Promise<SingleResult | ListResult | GetByIdResult>;
82
+ export declare function get(ref: Ref, q?: string | Record<string, unknown>): Promise<SingleResult | ListResult>;
114
83
  /**
115
- * Live snapshot stream on `ref` — re-emits the latest `get()` result on every underlying
116
- * mutation.
84
+ * Read a ref as it changes. Each item is what `get(ref, query)` returns now; a slow reader gets
85
+ * only the newest. With `changes: true` in the query each item also carries `changes`, the
86
+ * `{ prev, next }` rows that changed since the item before, so a slow reader gets fewer items,
87
+ * never fewer changes, and `reset`, set on the first item, whose changes list every row with
88
+ * `prev: null`.
117
89
  *
118
90
  * @param {Ref} ref
119
- * @param {Record<string, any>} [q]
91
+ * @param {string | Record<string, unknown> & { changes?: boolean }} [query]
120
92
  * @param {{ signal?: AbortSignal }} [opts]
121
93
  * @returns {import('streamx').Readable}
122
94
  */
123
- export declare function watch(ref: Ref, q?: Record<string, any>, opts?: {
95
+ export declare function watch(ref: Ref, query?: string | (Record<string, unknown> & {
96
+ changes?: boolean;
97
+ }), opts?: {
124
98
  signal?: AbortSignal;
125
99
  }): import('streamx').Readable;
126
- /**
127
- * Delta subscription: batches of `{ prev, next }` row pairs instead of full snapshots —
128
- * lossless under backpressure, self-contained (the first batch, and any batch after a view
129
- * swap, replays current.
130
- */
131
- export declare function changes(ref: any, q: any, opts: any): any;
132
100
  /**
133
101
  * Open (or create / join / load) a child handle through a `handle`-kind ref.
134
102
  *
135
103
  * @param {Ref} ref
136
- * @param {string | { invite?: string, id?: string, name?: string, routes?: any, role?: string, accept?: boolean } | undefined} [arg]
137
- * @returns {Promise<CeroHandle>} The resolved child handle.
104
+ * @param {string | { invite?: string, id?: string, name?: string } | undefined} [arg]
105
+ * @returns {Promise<Context>} The resolved child handle.
138
106
  */
139
107
  export declare function open(ref: Ref, arg?: string | {
140
108
  invite?: string;
141
109
  id?: string;
142
110
  name?: string;
143
- routes?: any;
144
- role?: string;
145
- accept?: boolean;
146
- } | undefined): Promise<CeroHandle>;
111
+ } | undefined): Promise<Context>;
112
+ /**
113
+ * Mint an invite code into a room.
114
+ *
115
+ * @param {Context} ctx
116
+ * @param {import('@cero-base/core/pairing').InviteOpts} [opts]
117
+ * @returns {Promise<string>}
118
+ */
119
+ export declare function invite(ctx: Context, opts?: import('@cero-base/core/pairing').InviteOpts): Promise<string>;
120
+ /**
121
+ * Kill an invite, for every member.
122
+ *
123
+ * @param {Context} ctx
124
+ * @param {string} code
125
+ * @returns {Promise<boolean>} Whether it was live.
126
+ */
127
+ export declare function revoke(ctx: Context, code: string): Promise<boolean>;
147
128
  /**
148
- * Rotate a handle's encryption epoch. A fresh secret is sealed to every current member and
149
- * announced through the log — members removed before the rotation cannot decrypt anything
150
- * written after it.
129
+ * Re-key a room now: a new epoch sealed to its members, so one removed before it reads nothing
130
+ * written after. Needs the remove permission. A removal also re-keys on its own shortly after it
131
+ * lands; this is the one to await.
151
132
  *
152
- * @param {any} handle
133
+ * @param {Context} ctx
153
134
  * @returns {Promise<{ epoch: number }>}
154
135
  */
155
- export declare function rotate(handle: any): Promise<{
136
+ export declare function rotate(ctx: Context): Promise<{
156
137
  epoch: number;
157
138
  }>;
139
+ /**
140
+ * Write atomically: every write `fn` makes through `tx`, the context it is handed, lands as one
141
+ * batch, or none does. Reads through `tx` see the room as it was before the batch. Not available
142
+ * over RPC.
143
+ *
144
+ * @template T
145
+ * @param {Context} ctx
146
+ * @param {(tx: Context) => Promise<T>} fn
147
+ * @returns {Promise<T>}
148
+ */
149
+ export declare function tx<T>(ctx: Context, fn: (tx: Context) => Promise<T>): Promise<T>;
150
+ /**
151
+ * Let in a join waiting on a `confirm` invite. `role` is the invite's by default, never above it.
152
+ *
153
+ * @param {Context} ctx
154
+ * @param {{ id: string }} request A row of `ctx.requests`.
155
+ * @param {{ role?: string }} [opts]
156
+ * @returns {Promise<void>}
157
+ */
158
+ export declare function accept(ctx: Context, request: {
159
+ id: string;
160
+ }, { role }?: {
161
+ role?: string;
162
+ }): Promise<void>;
163
+ /**
164
+ * Turn away a join waiting on a `confirm` invite. The joiner's `open` rejects with `DENIED`.
165
+ *
166
+ * @param {Context} ctx
167
+ * @param {{ id: string }} request A row of `ctx.requests`.
168
+ * @param {string} [reason]
169
+ * @returns {Promise<void>}
170
+ */
171
+ export declare function deny(ctx: Context, request: {
172
+ id: string;
173
+ }, reason?: string): Promise<void>;
174
+ /**
175
+ * Quit a room for good: it leaves your list and closes on this device.
176
+ *
177
+ * @param {Context} ctx
178
+ * @returns {Promise<void>}
179
+ */
180
+ export declare function leave(ctx: Context): Promise<void>;
181
+ /**
182
+ * Stop using a context on this device; everything stays. Closing the root closes it all.
183
+ *
184
+ * @param {Context} ctx
185
+ * @returns {Promise<void>}
186
+ */
187
+ export declare function close(ctx: Context): Promise<void>;
188
+ /**
189
+ * Give up a join still waiting for an answer, for good: it is not resumed on the next boot.
190
+ *
191
+ * @param {Context} me
192
+ * @param {string} code
193
+ * @returns {Promise<boolean>} Whether a join was waiting.
194
+ */
195
+ export declare function cancel(me: Context, code: string): Promise<boolean>;
196
+ /**
197
+ * The app goes to the background: networking, storage and the Bluetooth radio pause together,
198
+ * and every context reports `status.suspended`. On `me` only.
199
+ *
200
+ * @param {Context} me
201
+ * @returns {Promise<void>}
202
+ */
203
+ export declare function suspend(me: Context): Promise<void>;
204
+ /**
205
+ * The app is back in the foreground: everything `suspend` paused resumes. On `me` only.
206
+ *
207
+ * @param {Context} me
208
+ * @returns {Promise<void>}
209
+ */
210
+ export declare function resume(me: Context): Promise<void>;
211
+ /**
212
+ * Mark a room as the one in use: it ranks first on the swarm, searching and announcing. Rooms are
213
+ * otherwise ranked by their last update.
214
+ *
215
+ * @param {Context} room
216
+ * @returns {Promise<void>}
217
+ */
218
+ export declare function activate(room: Context): Promise<void>;
219
+ /**
220
+ * Take a room off the swarm until something lands in it.
221
+ *
222
+ * @param {Context} room
223
+ * @returns {Promise<void>}
224
+ */
225
+ export declare function deactivate(room: Context): Promise<void>;
226
+ /**
227
+ * Reveal the recovery phrase.
228
+ *
229
+ * @param {Context} me
230
+ * @returns {Promise<string>}
231
+ */
232
+ export declare function phrase(me: Context): Promise<string>;
233
+ /**
234
+ * Choose what the device's Bluetooth radio does: find the mesh (`true`), nothing (`false`), or
235
+ * hold one invite's rendezvous (its code) so a joiner in range finds this device with no internet,
236
+ * until the next call or the invite expires.
237
+ *
238
+ * @param {Context} ctx
239
+ * @param {boolean | string} mode
240
+ * @returns {Promise<void>}
241
+ */
242
+ export declare function nearby(ctx: Context, mode: boolean | string): Promise<void>;
@@ -3,7 +3,7 @@
3
3
  * identity (i.e. a stored master seed).
4
4
  *
5
5
  * @param {string} dir Cero data directory.
6
- * @param {any} spec Built spec — same value passed to `cero(dir, spec)`.
6
+ * @param {import('./spec.js').Spec} spec Built spec, the value passed to `cero(dir, spec)`.
7
7
  * @returns {Promise<boolean>} `true` if a master seed exists on disk.
8
8
  */
9
- export declare function peek(dir: string, spec: any): Promise<boolean>;
9
+ export declare function peek(dir: string, spec: import('./spec.js').Spec): Promise<boolean>;
@@ -1,38 +1,37 @@
1
1
  export type RefKind = 'collection' | 'single' | 'action' | 'handle';
2
- export type RefInfo = {
3
- kind?: string;
4
- schema?: string;
5
- };
2
+ export type RefInfo = import('./spec.js').RefInfo;
3
+ export type Spec = import('./spec.js').Spec;
4
+ export type Owner = import('../handle/index.js').Context | import('../local/index.js').Local;
6
5
  /**
7
6
  * @typedef {'collection' | 'single' | 'action' | 'handle'} RefKind
8
- * @typedef {{ kind?: string, schema?: string }} RefInfo
9
- * Shape of the entries in `meta.refs` — describes a single ref name.
10
- * `kind` is one of {@link RefKind}, kept as `string` since it originates
11
- * from a generated spec.
7
+ * @typedef {import('./spec.js').RefInfo} RefInfo
8
+ * @typedef {import('./spec.js').Spec} Spec
9
+ * @typedef {import('../handle/index.js').Context | import('../local/index.js').Local} Owner
12
10
  */
13
11
  /**
14
12
  * Typed pointer to a single ref (table or handle slot) on a `Handle` or `Local`.
15
13
  */
16
14
  export declare class Ref {
17
- handle: any;
15
+ handle: Owner;
18
16
  name: string;
19
17
  kind: string;
20
18
  schema: string;
21
- type: any;
19
+ type: string;
22
20
  /**
23
- * @param {any} handle Owner — a `Handle` (or `Local`) the ref lives on.
21
+ * @param {Owner} handle The root, a room or the local store the ref lives on.
24
22
  * @param {string} name Ref name as declared in the schema.
25
23
  * @param {string} kind Ref kind: `'collection'`, `'single'`, `'action'`, or `'handle'`.
26
24
  * @param {string | null} [schema] Fully-qualified schema id, if any.
25
+ * @param {string | null} [type] On a ref under a handle type (`me.room.notes`), that type.
27
26
  */
28
- constructor(handle: any, name: string, kind: string, schema?: string | null, type?: any);
27
+ constructor(handle: Owner, name: string, kind: string, schema?: string | null, type?: string | null);
29
28
  /**
30
29
  * Attach a `Ref` property to `target` for every entry in `refs`, so callers
31
30
  * write `handle.someRef` instead of looking refs up by name.
32
31
  *
33
- * @param {any} target
32
+ * @param {Owner} target
34
33
  * @param {Record<string, RefInfo>} refs
35
- * @param {Record<string, any>} [handles] The handle types, so `target.room.notes` names every room's notes.
34
+ * @param {Record<string, Spec>} [handles] The handle types, so `target.room.notes` names every room's notes.
36
35
  */
37
- static attach(target: any, refs: Record<string, RefInfo>, handles?: Record<string, any>): void;
36
+ static attach(target: Owner, refs: Record<string, RefInfo>, handles?: Record<string, Spec>): void;
38
37
  }