@cero-base/cero 1.18.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +38 -644
  2. package/package.json +16 -12
  3. package/src/build/index.js +21 -50
  4. package/src/build/internal.js +121 -0
  5. package/src/build/schemas.js +2 -8
  6. package/src/extensions/handle-sync.js +3 -10
  7. package/src/extensions/index.js +6 -0
  8. package/src/extensions/profile-sync.js +0 -5
  9. package/src/handle/index.js +255 -300
  10. package/src/index.js +65 -112
  11. package/src/lib/bluetooth.js +25 -56
  12. package/src/lib/constants.js +0 -15
  13. package/src/lib/operators.js +24 -74
  14. package/src/lib/peek.js +4 -8
  15. package/src/lib/refs.js +46 -0
  16. package/src/lib/spec.js +2 -3
  17. package/src/local/index.js +4 -5
  18. package/src/rpc/client.js +27 -39
  19. package/src/rpc/index.js +3 -3
  20. package/src/rpc/server.js +29 -40
  21. package/types/build/index.d.ts +19 -7
  22. package/types/build/internal.d.ts +78 -0
  23. package/types/build/schemas.d.ts +3 -3
  24. package/types/extensions/handle-sync.d.ts +4 -9
  25. package/types/extensions/index.d.ts +24 -2
  26. package/types/extensions/profile-sync.d.ts +2 -6
  27. package/types/handle/index.d.ts +218 -254
  28. package/types/index.d.ts +78 -102
  29. package/types/lib/bluetooth.d.ts +24 -46
  30. package/types/lib/constants.d.ts +5 -16
  31. package/types/lib/operators.d.ts +49 -77
  32. package/types/lib/peek.d.ts +3 -4
  33. package/types/lib/refs.d.ts +36 -0
  34. package/types/lib/spec.d.ts +5 -1
  35. package/types/local/index.d.ts +24 -23
  36. package/types/rpc/client.d.ts +107 -127
  37. package/types/rpc/index.d.ts +7 -2
  38. package/types/rpc/server.d.ts +62 -76
  39. package/src/build/builtins.js +0 -174
  40. package/src/lib/internal.js +0 -9
  41. package/src/lib/utils.js +0 -67
  42. package/types/build/builtins.d.ts +0 -100
  43. package/types/lib/internal.d.ts +0 -24
  44. package/types/lib/utils.d.ts +0 -55
package/types/index.d.ts CHANGED
@@ -1,73 +1,15 @@
1
- /**
2
- * @typedef {import('./handle/index.js').CeroHandle} CeroHandle
3
- */
4
- /**
5
- * @typedef {object} CeroOpts
6
- * @property {Identity} [identity] Pre-resolved identity. If absent, derived from `seed`/`phrase` or generated.
7
- * @property {Uint8Array} [seed] 16- or 32-byte seed entropy.
8
- * @property {string} [phrase] BIP-39 mnemonic alternative to `seed`.
9
- * @property {12 | 24} [words] Mnemonic length when generating a fresh identity.
10
- * @property {string | null} [name] Friendly device name persisted on the identity claim.
11
- * @property {boolean} [isMobile] Marks this device as mobile.
12
- * @property {Array<{ host: string, port: number }>} [bootstrap] Custom DHT bootstrap nodes.
13
- * @property {number[]} [backoffs] Swarm reconnect backoff tiers in ms (testing/tuning).
14
- * @property {string} [channel] Optional network-isolation label; only same-channel peers connect.
15
- * @property {Array<string | Uint8Array>} [mirrors] Blind-peer public keys. Rooms and files are mirrored through them so peers sync even when never online at the same time. Mirrors hold only encrypted blocks — they never read your data.
16
- * @property {Uint8Array} [key] Pre-existing database key (skip bootstrap).
17
- * @property {Uint8Array} [encryptionKey] Pre-existing encryption key.
18
- * @property {Record<string, Function>} [routes] Custom RPC routes for the database dispatcher.
19
- * @property {(err: any) => void} [onerror] Background-task error handler.
20
- * @property {boolean} [recovery] Recovery flow — wipe local state and re-claim a writer slot.
21
- * @property {number} [recoveryTimeout] Max wait for peer data + writer capability during recovery.
22
- * @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.
23
- * @property {boolean} [extensions] `false` disables the bundled extensions (profileSync, handleSync) for this instance. Build with `{ extensions: false }` too so the spec matches.
24
- * @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'`.
25
- */
26
- /**
27
- * Open (or create) a cero handle at `dir`. Sets up storage, network and
28
- * identity, then returns a ready root `Handle` with all schema refs
29
- * attached as properties.
30
- *
31
- * @param {string} dir Data directory.
32
- * @param {any} spec Built spec — output of `cero/build`.
33
- * @param {CeroOpts} [opts]
34
- * @returns {Promise<CeroHandle>}
35
- */
36
- export function cero(dir: string, spec: any, opts?: CeroOpts): Promise<CeroHandle>;
37
- export namespace cero {
38
- export { t };
39
- export { put };
40
- export { set };
41
- export { get };
42
- export { del };
43
- export { count };
44
- export { watch };
45
- export { changes };
46
- export { call };
47
- export { open };
48
- export { rotate };
49
- export { before };
50
- export { after };
51
- export { peek };
52
- export { restore };
53
- export { schema };
54
- export { bind };
55
- export { define };
56
- export { internal as _internal };
57
- export function use(...exts: any[]): void;
58
- }
59
- /**
60
- * Restore a cero instance from a mnemonic phrase. Closes the running
61
- * instance, wipes the on-disk `main/` tree and re-opens with `recovery: true`
62
- * so the writer slot is re-claimed.
63
- *
64
- * @param {Handle} me Existing root handle to restore.
65
- * @param {string} phrase BIP-39 mnemonic phrase.
66
- * @returns {Promise<Handle>} Freshly restored root handle.
67
- */
68
- export function restore(me: Handle, phrase: string): Promise<Handle>;
69
- export { peek } from "./lib/peek.js";
70
- export type CeroHandle = import("./handle/index.js").CeroHandle;
1
+ import { Identity } from '@cero-base/core/identity';
2
+ import { Handle, Ref } from './handle/index.js';
3
+ import { Local } from './local/index.js';
4
+ import { put, set, get, del, count, watch, changes, call, open, rotate, before, after, bind, define } from './lib/operators.js';
5
+ import { peek } from './lib/peek.js';
6
+ import { t, schema } from './lib/spec.js';
7
+ import { registry } from './extensions/index.js';
8
+ export { Handle, Ref, Local };
9
+ export { put, set, get, del, count, watch, changes, call, open, rotate, before, after, bind, define } from './lib/operators.js';
10
+ export { peek } from './lib/peek.js';
11
+ export { t, schema } from './lib/spec.js';
12
+ export type CeroHandle = import('./handle/index.js').CeroHandle;
71
13
  export type CeroOpts = {
72
14
  /**
73
15
  * Pre-resolved identity. If absent, derived from `seed`/`phrase` or generated.
@@ -113,7 +55,7 @@ export type CeroOpts = {
113
55
  */
114
56
  mirrors?: Array<string | Uint8Array>;
115
57
  /**
116
- * Pre-existing database key (skip bootstrap).
58
+ * Existing database key to recover into, skipping the pointer lookup.
117
59
  */
118
60
  key?: Uint8Array;
119
61
  /**
@@ -129,11 +71,7 @@ export type CeroOpts = {
129
71
  */
130
72
  onerror?: (err: any) => void;
131
73
  /**
132
- * Recovery flow wipe local state and re-claim a writer slot.
133
- */
134
- recovery?: boolean;
135
- /**
136
- * Max wait for peer data + writer capability during recovery.
74
+ * Max wait to find another device and be admitted, in ms. Defaults to 30000.
137
75
  */
138
76
  recoveryTimeout?: number;
139
77
  /**
@@ -152,31 +90,69 @@ export type CeroOpts = {
152
90
  backend?: any;
153
91
  maxOutbound?: number;
154
92
  maxInbound?: number;
155
- pipe?: "l2cap" | "gatt";
93
+ pipe?: 'l2cap' | 'gatt';
156
94
  };
157
95
  };
158
- import { t } from './lib/spec.js';
159
- import { put } from './lib/operators.js';
160
- import { set } from './lib/operators.js';
161
- import { get } from './lib/operators.js';
162
- import { del } from './lib/operators.js';
163
- import { count } from './lib/operators.js';
164
- import { watch } from './lib/operators.js';
165
- import { changes } from './lib/operators.js';
166
- import { call } from './lib/operators.js';
167
- import { open } from './lib/operators.js';
168
- import { rotate } from './lib/operators.js';
169
- import { before } from './lib/operators.js';
170
- import { after } from './lib/operators.js';
171
- import { peek } from './lib/peek.js';
172
- import { schema } from './lib/spec.js';
173
- import { bind } from './lib/operators.js';
174
- import { define } from './lib/operators.js';
175
- import { internal } from './lib/internal.js';
176
- import { Handle } from './handle/index.js';
177
- import { Ref } from './handle/index.js';
178
- import { Local } from './local/index.js';
179
- import { Identity } from '@cero-base/core/identity';
180
- export { Handle, Ref, Local };
181
- export { put, set, get, del, count, watch, changes, call, open, rotate, before, after, bind, define } from "./lib/operators.js";
182
- export { t, schema } from "./lib/spec.js";
96
+ /**
97
+ * @typedef {import('./handle/index.js').CeroHandle} CeroHandle
98
+ */
99
+ /**
100
+ * @typedef {object} CeroOpts
101
+ * @property {Identity} [identity] Pre-resolved identity. If absent, derived from `seed`/`phrase` or generated.
102
+ * @property {Uint8Array} [seed] 16- or 32-byte seed entropy.
103
+ * @property {string} [phrase] BIP-39 mnemonic — alternative to `seed`.
104
+ * @property {12 | 24} [words] Mnemonic length when generating a fresh identity.
105
+ * @property {string | null} [name] Friendly device name persisted on the identity claim.
106
+ * @property {boolean} [isMobile] Marks this device as mobile.
107
+ * @property {Array<{ host: string, port: number }>} [bootstrap] Custom DHT bootstrap nodes.
108
+ * @property {number[]} [backoffs] Swarm reconnect backoff tiers in ms (testing/tuning).
109
+ * @property {string} [channel] Optional network-isolation label; only same-channel peers connect.
110
+ * @property {Array<string | Uint8Array>} [mirrors] Blind-peer public keys. Rooms and files are mirrored through them so peers sync even when never online at the same time. Mirrors hold only encrypted blocks — they never read your data.
111
+ * @property {Uint8Array} [key] Existing database key to recover into, skipping the pointer lookup.
112
+ * @property {Uint8Array} [encryptionKey] Pre-existing encryption key.
113
+ * @property {Record<string, Function>} [routes] Custom RPC routes for the database dispatcher.
114
+ * @property {(err: any) => void} [onerror] Background-task error handler.
115
+ * @property {number} [recoveryTimeout] Max wait to find another device and be admitted, in ms. Defaults to 30000.
116
+ * @property {Uint8Array} [storageKey] 32-byte key encrypting local key material (master seed, device keypairs) at rest. Source it from the OS keychain — cero never stores it.
117
+ * @property {boolean} [extensions] `false` disables the bundled extensions (profileSync, handleSync) for this instance. Build with `{ extensions: false }` too so the spec matches.
118
+ * @property {boolean | { autoStart?: boolean, backend?: any, maxOutbound?: number, maxInbound?: number, pipe?: 'l2cap' | 'gatt' }} [bluetooth] `true` enables nearby (Bluetooth) sync via `me.bluetooth` (auto-started). `{ autoStart: false }` creates the facade without starting the radio — the app calls `me.bluetooth.start()`/`stop()` (user toggle). `backend` injects a bare-bluetooth-shaped backend (tests). `maxOutbound`/`maxInbound` cap concurrent outbound links and inbound sessions. `pipe` picks the data pipe — `'l2cap'` (default, faster) or `'gatt'`; both peers must match. Absent backend on an unsupported host → `me.bluetooth.state === 'unsupported'`.
119
+ */
120
+ /**
121
+ * Open (or create) a cero handle at `dir`.
122
+ *
123
+ * @param {string} dir Data directory.
124
+ * @param {any} spec Built spec — output of `cero/build`.
125
+ * @param {CeroOpts} [opts]
126
+ * @returns {Promise<CeroHandle>}
127
+ */
128
+ export declare function cero(dir: string, spec: any, opts?: CeroOpts): Promise<CeroHandle>;
129
+ export declare namespace cero {
130
+ export { t };
131
+ export { put };
132
+ export { set };
133
+ export { get };
134
+ export { del };
135
+ export { count };
136
+ export { watch };
137
+ export { changes };
138
+ export { call };
139
+ export { open };
140
+ export { rotate };
141
+ export { before };
142
+ export { after };
143
+ export { peek };
144
+ export { restore };
145
+ export { schema };
146
+ export { bind };
147
+ export { define };
148
+ export { registry as _registry };
149
+ export var use: (...exts: any[]) => void;
150
+ }
151
+ /**
152
+ * Restore a cero instance from a mnemonic phrase.
153
+ *
154
+ * @param {Handle} me Existing root handle to restore.
155
+ * @param {string} phrase BIP-39 mnemonic phrase.
156
+ * @returns {Promise<Handle>} Freshly restored root handle.
157
+ */
158
+ export declare function restore(me: Handle, phrase: string): Promise<Handle>;
@@ -1,21 +1,22 @@
1
+ import ReadyResource from 'ready-resource';
1
2
  /**
2
- * `me.bluetooth` — the app-facing surface for nearby (Bluetooth) sync, a thin
3
- * facade over ble-swarm. Bluetooth only changes how peers meet and carry
4
- * bytes; capability-gated replication still decides what syncs. Discovery is
5
- * one topic-derived service UUID at a time (tag `cero-ble`) — the data service
6
- * sits on a fixed per-tag UUID, so switching topics only retunes the radio.
7
- *
8
- * ```js
9
- * const me = await cero(dir, spec, { channel, bluetooth: true })
10
- * me.bluetooth.state // 'unsupported' | 'unauthorized' | 'off' | 'waiting' | 'starting' | 'on'
11
- * await me.bluetooth.start()
12
- * me.bluetooth.peers // Map of live BLE links
13
- * me.bluetooth.on('update', () => {})
14
- * ```
3
+ * `me.bluetooth` — the app-facing surface for nearby (Bluetooth) sync, a thin facade over
4
+ * ble-swarm.
15
5
  *
16
6
  * @extends ReadyResource
17
7
  */
18
- export class Bluetooth extends ReadyResource {
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) */
12
+ _announce: {
13
+ hex: string;
14
+ count: number;
15
+ timer: any;
16
+ } | null;
17
+ _restorePending: boolean;
18
+ _topic: any;
19
+ swarm: any;
19
20
  /**
20
21
  * @param {object} handle Root cero Handle (network + identity + channel).
21
22
  * @param {object} [opts]
@@ -30,23 +31,14 @@ export class Bluetooth extends ReadyResource {
30
31
  autoStart?: boolean;
31
32
  maxOutbound?: number;
32
33
  maxInbound?: number;
33
- pipe?: "l2cap" | "gatt";
34
+ pipe?: 'l2cap' | 'gatt';
34
35
  });
35
- _handle: any;
36
- _autoStart: boolean;
37
- /** @type {{ hex: string, count: number, timer: any } | null} active invite rendezvous (single topic — one at a time) */
38
- _announce: {
39
- hex: string;
40
- count: number;
41
- timer: any;
42
- } | null;
43
- _restorePending: boolean;
44
- _topic: any;
45
- swarm: any;
46
36
  /** @returns {'unsupported'|'unauthorized'|'off'|'waiting'|'starting'|'on'} */
47
- get state(): "unsupported" | "unauthorized" | "off" | "waiting" | "starting" | "on";
37
+ get state(): 'unsupported' | 'unauthorized' | 'off' | 'waiting' | 'starting' | 'on';
48
38
  /** @returns {Map<string, any>} Live BLE links, keyed by peer public key. */
49
39
  get peers(): Map<string, any>;
40
+ _open(): Promise<void>;
41
+ _close(): Promise<void>;
50
42
  /**
51
43
  * Begin advertising + scanning. Idempotent; no-op when unsupported.
52
44
  *
@@ -54,34 +46,19 @@ export class Bluetooth extends ReadyResource {
54
46
  */
55
47
  start(): Promise<void>;
56
48
  /**
57
- * Stop advertising/scanning and drop links; open invite rendezvous end with
58
- * the radio. Idempotent. Local data and the rest of the network (DHT) are
59
- * untouched.
49
+ * Stop advertising/scanning and drop links; open invite rendezvous end with the radio.
60
50
  *
61
51
  * @returns {Promise<void>}
62
52
  */
63
53
  stop(): Promise<void>;
64
54
  /**
65
- * Offline join rendezvous: retune the radio to the invite-derived topic so
66
- * holder and joiner find each other with zero DHT. One topic at a time —
67
- * announcing a new invite replaces the previous rendezvous. Returns a stop
68
- * function — closing the QR must stop the rendezvous so a photographed
69
- * invite doesn't stay an ambient discovery beacon (admission itself is
70
- * always gated by blind-pairing verifying the invite). The retune back to
71
- * the mesh topic waits for live links to drain: the link a join just
72
- * established survives and carries the joiner's initial replication.
73
- * Auto-stops at the invite's expiry, on `stop()`, and on close.
74
- *
75
- * Only active while nearby sync is on: before `start()` (and after `stop()`)
76
- * this is a no-op — the user controls the radio, and a join must not touch
77
- * Bluetooth (OS permissions, GATT server) they never enabled.
55
+ * Offline join rendezvous: retune the radio to the invite-derived topic so holder and
56
+ * joiner find each other with zero DHT.
78
57
  *
79
58
  * @param {string} invite Z32 invite string.
80
59
  * @returns {() => void}
81
60
  */
82
61
  announce(invite: string): () => void;
83
- _stopAnnounce(): void;
84
- _clearAnnounce(): void;
85
62
  /**
86
63
  * Host-lifecycle pause (app backgrounded): radio down, user intent kept.
87
64
  *
@@ -94,5 +71,6 @@ export class Bluetooth extends ReadyResource {
94
71
  * @returns {Promise<void>}
95
72
  */
96
73
  resume(): Promise<void>;
74
+ _stopAnnounce(): void;
75
+ _clearAnnounce(): void;
97
76
  }
98
- import ReadyResource from 'ready-resource';
@@ -1,16 +1,5 @@
1
- export const NS: "cero";
2
- export const COUNTERS: "counters";
3
- export const EPOCHS: "epochs";
4
- export const TIMEOUT: 30000;
5
- export const FLUSH: 500;
6
- export namespace DB_TYPE {
7
- let string: string;
8
- let uint: string;
9
- let int: string;
10
- let bool: string;
11
- let bytes: string;
12
- let json: string;
13
- let fixed32: string;
14
- let fixed64: string;
15
- let file: string;
16
- }
1
+ export declare const NS = "cero";
2
+ export declare const COUNTERS = "counters";
3
+ export declare const EPOCHS = "epochs";
4
+ export declare const TIMEOUT = 30000;
5
+ export declare const FLUSH = 500;
@@ -1,5 +1,18 @@
1
+ export type Ref = import('./refs.js').Ref;
2
+ export type CeroHandle = import('../handle/index.js').CeroHandle;
3
+ export type SingleResult = {
4
+ data: any;
5
+ };
6
+ export type ListResult = {
7
+ data: any[];
8
+ total: number;
9
+ size: number;
10
+ };
11
+ export type GetByIdResult = {
12
+ data: any | null;
13
+ };
1
14
  /**
2
- * @typedef {import('./utils.js').Ref} Ref
15
+ * @typedef {import('./refs.js').Ref} Ref
3
16
  * @typedef {import('../handle/index.js').CeroHandle} CeroHandle
4
17
  * @typedef {{ data: any }} SingleResult
5
18
  * @typedef {{ data: any[], total: number, size: number }} ListResult
@@ -14,7 +27,7 @@
14
27
  * @param {string} [name]
15
28
  * @returns {{ id: string, type: string, size: number, url: string, name?: string }}
16
29
  */
17
- export function resolveFile(handle: object, id: string, name?: string): {
30
+ export declare function resolveFile(handle: object, id: string, name?: string): {
18
31
  id: string;
19
32
  type: string;
20
33
  size: number;
@@ -22,26 +35,22 @@ export function resolveFile(handle: object, id: string, name?: string): {
22
35
  name?: string;
23
36
  };
24
37
  /**
25
- * Insert (or overwrite by id) a row on `ref`. The `files` builtin is special:
26
- * `put(handle.files, { data, type, name? })` uploads the bytes to this handle's
27
- * blob store, records `{ id, name }`, and resolves the file.
38
+ * Insert (or overwrite by id) a row on `ref`.
28
39
  *
29
40
  * @param {Ref} ref
30
41
  * @param {Record<string, any>} row
31
42
  * @returns {Promise<SingleResult>}
32
43
  */
33
- export function put(ref: Ref, row: Record<string, any>): Promise<SingleResult>;
44
+ export declare function put(ref: Ref, row: Record<string, any>): Promise<SingleResult>;
34
45
  /**
35
- * Upsert a row on `ref` — merges with the existing row and preserves
36
- * `createdAt`. Pass `{ upsert: false }` to update-only: a missing row is left
37
- * untouched instead of created (atomic — never resurrects a deleted row).
46
+ * Upsert a row on `ref` — merges with the existing row and preserves `createdAt`.
38
47
  *
39
48
  * @param {Ref} ref
40
49
  * @param {Record<string, any>} row
41
50
  * @param {{ upsert?: boolean }} [opts]
42
51
  * @returns {Promise<SingleResult>}
43
52
  */
44
- export function set(ref: Ref, row: Record<string, any>, opts?: {
53
+ export declare function set(ref: Ref, row: Record<string, any>, opts?: {
45
54
  upsert?: boolean;
46
55
  }): Promise<SingleResult>;
47
56
  /**
@@ -51,7 +60,7 @@ export function set(ref: Ref, row: Record<string, any>, opts?: {
51
60
  * @param {string} [id]
52
61
  * @returns {Promise<void>}
53
62
  */
54
- export function del(ref: Ref, id?: string): Promise<void>;
63
+ export declare function del(ref: Ref, id?: string): Promise<void>;
55
64
  /**
56
65
  * Count rows on `ref`, optionally filtered.
57
66
  *
@@ -59,7 +68,7 @@ export function del(ref: Ref, id?: string): Promise<void>;
59
68
  * @param {Record<string, any>} [q]
60
69
  * @returns {Promise<{ data: number }>}
61
70
  */
62
- export function count(ref: Ref, q?: Record<string, any>): Promise<{
71
+ export declare function count(ref: Ref, q?: Record<string, any>): Promise<{
63
72
  data: number;
64
73
  }>;
65
74
  /**
@@ -69,18 +78,16 @@ export function count(ref: Ref, q?: Record<string, any>): Promise<{
69
78
  * @param {Record<string, any>} [d]
70
79
  * @returns {Promise<any>}
71
80
  */
72
- export function call(ref: Ref, d?: Record<string, any>): Promise<any>;
81
+ export declare function call(ref: Ref, d?: Record<string, any>): Promise<any>;
73
82
  /**
74
- * Intercept writes to `ref` before they commit — `fn(ctx)` runs in-path
75
- * (awaited). Return `false` to cancel the write, or mutate `ctx.row`.
76
- * Returns an unsubscribe fn; pass `{ signal }` to unsubscribe on abort.
83
+ * Intercept writes to `ref` before they commit — `fn(ctx)` runs in-path (awaited).
77
84
  *
78
85
  * @param {Ref} ref
79
86
  * @param {(ctx: { op: string, name: string, row: any }) => any} fn
80
87
  * @param {{ signal?: AbortSignal }} [opts]
81
88
  * @returns {() => void}
82
89
  */
83
- export function before(ref: Ref, fn: (ctx: {
90
+ export declare function before(ref: Ref, fn: (ctx: {
84
91
  op: string;
85
92
  name: string;
86
93
  row: any;
@@ -88,16 +95,15 @@ export function before(ref: Ref, fn: (ctx: {
88
95
  signal?: AbortSignal;
89
96
  }): () => void;
90
97
  /**
91
- * Subscribe to writes on `ref` — fires after each committed write,
92
- * non-blocking (observe only). Returns an unsubscribe fn; pass `{ signal }`
93
- * to unsubscribe on abort.
98
+ * Subscribe to writes on `ref` — fires after each committed write, non-blocking (observe
99
+ * only).
94
100
  *
95
101
  * @param {Ref} ref
96
102
  * @param {(ctx: { op: string, name: string, row: any }) => void} fn
97
103
  * @param {{ signal?: AbortSignal }} [opts]
98
104
  * @returns {() => void}
99
105
  */
100
- export function after(ref: Ref, fn: (ctx: {
106
+ export declare function after(ref: Ref, fn: (ctx: {
101
107
  op: string;
102
108
  name: string;
103
109
  row: any;
@@ -105,50 +111,39 @@ export function after(ref: Ref, fn: (ctx: {
105
111
  signal?: AbortSignal;
106
112
  }): () => void;
107
113
  /**
108
- * Read from `ref`. For data refs, dispatches to the underlying store. For
109
- * `handle`-kind refs, lists existing child handles of that type from the
110
- * parent's `handles` collection.
114
+ * Read from `ref`. For data refs, dispatches to the underlying store.
111
115
  *
112
116
  * @param {Ref} ref
113
117
  * @param {string | Record<string, any>} [q]
114
118
  * @returns {Promise<SingleResult | ListResult | GetByIdResult>}
115
119
  */
116
- export function get(ref: Ref, q?: string | Record<string, any>): Promise<SingleResult | ListResult | GetByIdResult>;
120
+ export declare function get(ref: Ref, q?: string | Record<string, any>): Promise<SingleResult | ListResult | GetByIdResult>;
117
121
  /**
118
- * Live snapshot stream on `ref` — re-emits the latest `get()` result on
119
- * every underlying mutation. Tied to `ref.handle`'s lifecycle: closing the
120
- * handle destroys it. Pass `{ signal }` to bind it to a finer scope, or
121
- * destroy the stream directly to stop watching sooner.
122
+ * Live snapshot stream on `ref` — re-emits the latest `get()` result on every underlying
123
+ * mutation.
122
124
  *
123
125
  * @param {Ref} ref
124
126
  * @param {Record<string, any>} [q]
125
127
  * @param {{ signal?: AbortSignal }} [opts]
126
128
  * @returns {import('streamx').Readable}
127
129
  */
128
- export function watch(ref: Ref, q?: Record<string, any>, opts?: {
130
+ export declare function watch(ref: Ref, q?: Record<string, any>, opts?: {
129
131
  signal?: AbortSignal;
130
- }): import("streamx").Readable;
132
+ }): import('streamx').Readable;
131
133
  /**
132
- * Delta subscription: batches of `{ prev, next }` row pairs instead of
133
- * full snapshots — lossless under backpressure, self-contained (the first
134
- * batch, and any batch after a view swap, replays current state as inserts
135
- * with `reset: true`). File-typed fields resolve on both sides.
134
+ * Delta subscription: batches of `{ prev, next }` row pairs instead of full snapshots —
135
+ * lossless under backpressure, self-contained (the first batch, and any batch after a view
136
+ * swap, replays current.
136
137
  */
137
- export function changes(ref: any, q: any, opts: any): any;
138
+ export declare function changes(ref: any, q: any, opts: any): any;
138
139
  /**
139
- * Open (or create / join / load) a child handle through a `handle`-kind
140
- * ref. Dispatches on the normalize of `arg`:
141
- *
142
- * - `string` → join via an invite string
143
- * - `{ invite: string }` → join via invite (object form)
144
- * - `{ id: string }` → load an existing handle by id
145
- * - `object | undefined` → create a new handle with the given opts
140
+ * Open (or create / join / load) a child handle through a `handle`-kind ref.
146
141
  *
147
142
  * @param {Ref} ref
148
143
  * @param {string | { invite?: string, id?: string, name?: string, routes?: any, role?: string, accept?: boolean } | undefined} [arg]
149
144
  * @returns {Promise<CeroHandle>} The resolved child handle.
150
145
  */
151
- export function open(ref: Ref, arg?: string | {
146
+ export declare function open(ref: Ref, arg?: string | {
152
147
  invite?: string;
153
148
  id?: string;
154
149
  name?: string;
@@ -157,54 +152,31 @@ export function open(ref: Ref, arg?: string | {
157
152
  accept?: boolean;
158
153
  } | undefined): Promise<CeroHandle>;
159
154
  /**
160
- * Rotate a handle's encryption epoch. A fresh secret is sealed to every
161
- * current member and announced through the log — members removed before the
162
- * rotation cannot decrypt anything written after it. Requires the remove
163
- * permission (admin or owner). Compose with removal:
164
- *
165
- * await cero.del(room.members, memberId)
166
- * await cero.rotate(room)
155
+ * Rotate a handle's encryption epoch. A fresh secret is sealed to every current member and
156
+ * announced through the log — members removed before the rotation cannot decrypt anything
157
+ * written after it.
167
158
  *
168
159
  * @param {any} handle
169
160
  * @returns {Promise<{ epoch: number }>}
170
161
  */
171
- export function rotate(handle: any): Promise<{
162
+ export declare function rotate(handle: any): Promise<{
172
163
  epoch: number;
173
164
  }>;
174
165
  /**
175
166
  * Put custom operators on `handle`, currying it as their first argument so
176
- * `handle.ns.fn(args)` calls `fn(handle, args)`. `arg` is either:
177
- * - a `{ ns: module }` map → bind exactly those, or
178
- * - `null` → the registered root operators, or
179
- * - a child-handle type → the registered operators for that type.
180
- * The scope forms are how cero binds handles automatically; pass a map yourself
181
- * for manual binding.
167
+ * `handle.ns.fn(args)` calls `fn(handle, args)`.
182
168
  *
183
169
  * @param {any} handle
184
170
  * @param {Record<string, any> | string | null} arg
185
171
  * @returns {any} handle
186
172
  */
187
- export function bind(handle: any, arg: Record<string, any> | string | null): any;
173
+ export declare function bind(handle: any, arg: Record<string, any> | string | null): any;
188
174
  /**
189
- * Register custom operators by scope. A bare key binds on the root handle; a key
190
- * that names a child-handle type binds on every handle of that type. Call once
191
- * at startup, before `cero()` / `connect()`, in both processes.
175
+ * Register custom operators by scope. A bare key binds on the root handle; a key that
176
+ * names a child-handle type binds on every handle of that type.
192
177
  *
193
178
  * @param {Record<string, any>} map
194
179
  */
195
- export function define(map: Record<string, any>): void;
180
+ export declare function define(map: Record<string, any>): void;
196
181
  /** Test seam: clear all registered operators. */
197
- export function _clearDefined(): void;
198
- export type Ref = import("./utils.js").Ref;
199
- export type CeroHandle = import("../handle/index.js").CeroHandle;
200
- export type SingleResult = {
201
- data: any;
202
- };
203
- export type ListResult = {
204
- data: any[];
205
- total: number;
206
- size: number;
207
- };
208
- export type GetByIdResult = {
209
- data: any | null;
210
- };
182
+ export declare function _clearDefined(): void;
@@ -1,10 +1,9 @@
1
1
  /**
2
- * Quickly check whether the on-disk directory at `dir` already holds an
3
- * initialised cero identity (i.e. a stored master seed). Opens the local store
4
- * read-only and closes everything before returning.
2
+ * Quickly check whether the on-disk directory at `dir` already holds an initialised cero
3
+ * identity (i.e. a stored master seed).
5
4
  *
6
5
  * @param {string} dir Cero data directory.
7
6
  * @param {any} spec Built spec — same value passed to `cero(dir, spec)`.
8
7
  * @returns {Promise<boolean>} `true` if a master seed exists on disk.
9
8
  */
10
- export function peek(dir: string, spec: any): Promise<boolean>;
9
+ export declare function peek(dir: string, spec: any): Promise<boolean>;
@@ -0,0 +1,36 @@
1
+ export type RefKind = 'collection' | 'single' | 'action' | 'handle';
2
+ export type RefInfo = {
3
+ kind?: string;
4
+ schema?: string;
5
+ };
6
+ /**
7
+ * @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.
12
+ */
13
+ /**
14
+ * Typed pointer to a single ref (table or handle slot) on a `Handle` or `Local`.
15
+ */
16
+ export declare class Ref {
17
+ handle: any;
18
+ name: string;
19
+ kind: string;
20
+ schema: string;
21
+ /**
22
+ * @param {any} handle Owner — a `Handle` (or `Local`) the ref lives on.
23
+ * @param {string} name Ref name as declared in the schema.
24
+ * @param {string} kind Ref kind: `'collection'`, `'single'`, `'action'`, or `'handle'`.
25
+ * @param {string | null} [schema] Fully-qualified schema id, if any.
26
+ */
27
+ constructor(handle: any, name: string, kind: string, schema?: string | null);
28
+ /**
29
+ * Attach a `Ref` property to `target` for every entry in `refs`, so callers
30
+ * write `handle.someRef` instead of looking refs up by name.
31
+ *
32
+ * @param {any} target
33
+ * @param {Record<string, RefInfo>} refs
34
+ */
35
+ static attach(target: any, refs: Record<string, RefInfo>): void;
36
+ }
@@ -1 +1,5 @@
1
- export { t, schema } from "@cero-base/core/schema";
1
+ /**
2
+ * Re-exports of the schema DSL (`t`) and `schema()` wrapper from `@cero-base/core/schema`,
3
+ * so cero apps can describe their tables without pulling in the core package directly.
4
+ */
5
+ export { t, schema } from '@cero-base/core/schema';