@cero-base/cero 1.18.1 → 1.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -6
- package/package.json +10 -9
- package/src/handle/index.js +17 -37
- package/src/index.js +55 -71
- package/src/lib/operators.js +2 -2
- package/src/lib/refs.js +49 -0
- package/src/local/index.js +2 -2
- package/src/rpc/client.js +7 -5
- package/src/rpc/server.js +6 -5
- package/types/build/builtins.d.ts +46 -50
- package/types/build/index.d.ts +27 -7
- package/types/build/schemas.d.ts +3 -3
- package/types/extensions/handle-sync.d.ts +2 -2
- package/types/extensions/index.d.ts +2 -2
- package/types/extensions/profile-sync.d.ts +2 -2
- package/types/handle/index.d.ts +147 -165
- package/types/index.d.ts +82 -102
- package/types/lib/bluetooth.d.ts +17 -15
- package/types/lib/constants.d.ts +16 -16
- package/types/lib/internal.d.ts +5 -5
- package/types/lib/operators.d.ts +31 -31
- package/types/lib/peek.d.ts +1 -1
- package/types/lib/refs.d.ts +38 -0
- package/types/lib/spec.d.ts +6 -1
- package/types/local/index.d.ts +22 -20
- package/types/rpc/client.d.ts +111 -123
- package/types/rpc/index.d.ts +7 -2
- package/types/rpc/server.d.ts +56 -67
- package/src/lib/utils.js +0 -67
- package/types/lib/utils.d.ts +0 -55
package/types/index.d.ts
CHANGED
|
@@ -1,73 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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 { internal } from './lib/internal.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
|
-
*
|
|
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
|
-
*
|
|
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,73 @@ export type CeroOpts = {
|
|
|
152
90
|
backend?: any;
|
|
153
91
|
maxOutbound?: number;
|
|
154
92
|
maxInbound?: number;
|
|
155
|
-
pipe?:
|
|
93
|
+
pipe?: 'l2cap' | 'gatt';
|
|
156
94
|
};
|
|
157
95
|
};
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
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`. Sets up storage, network and
|
|
122
|
+
* identity, then returns a ready root `Handle` with all schema refs
|
|
123
|
+
* attached as properties.
|
|
124
|
+
*
|
|
125
|
+
* @param {string} dir Data directory.
|
|
126
|
+
* @param {any} spec Built spec — output of `cero/build`.
|
|
127
|
+
* @param {CeroOpts} [opts]
|
|
128
|
+
* @returns {Promise<CeroHandle>}
|
|
129
|
+
*/
|
|
130
|
+
export declare function cero(dir: string, spec: any, opts?: CeroOpts): Promise<CeroHandle>;
|
|
131
|
+
export declare namespace cero {
|
|
132
|
+
export { t };
|
|
133
|
+
export { put };
|
|
134
|
+
export { set };
|
|
135
|
+
export { get };
|
|
136
|
+
export { del };
|
|
137
|
+
export { count };
|
|
138
|
+
export { watch };
|
|
139
|
+
export { changes };
|
|
140
|
+
export { call };
|
|
141
|
+
export { open };
|
|
142
|
+
export { rotate };
|
|
143
|
+
export { before };
|
|
144
|
+
export { after };
|
|
145
|
+
export { peek };
|
|
146
|
+
export { restore };
|
|
147
|
+
export { schema };
|
|
148
|
+
export { bind };
|
|
149
|
+
export { define };
|
|
150
|
+
export { internal as _internal };
|
|
151
|
+
export var use: (...exts: any[]) => void;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Restore a cero instance from a mnemonic phrase. Closes the running
|
|
155
|
+
* instance, wipes the on-disk `main/` tree and re-opens with the phrase, which
|
|
156
|
+
* recovers so the writer slot is re-claimed.
|
|
157
|
+
*
|
|
158
|
+
* @param {Handle} me Existing root handle to restore.
|
|
159
|
+
* @param {string} phrase BIP-39 mnemonic phrase.
|
|
160
|
+
* @returns {Promise<Handle>} Freshly restored root handle.
|
|
161
|
+
*/
|
|
162
|
+
export declare function restore(me: Handle, phrase: string): Promise<Handle>;
|
package/types/lib/bluetooth.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import ReadyResource from 'ready-resource';
|
|
1
2
|
/**
|
|
2
3
|
* `me.bluetooth` — the app-facing surface for nearby (Bluetooth) sync, a thin
|
|
3
4
|
* facade over ble-swarm. Bluetooth only changes how peers meet and carry
|
|
@@ -15,7 +16,18 @@
|
|
|
15
16
|
*
|
|
16
17
|
* @extends ReadyResource
|
|
17
18
|
*/
|
|
18
|
-
export class Bluetooth extends ReadyResource {
|
|
19
|
+
export declare class Bluetooth extends ReadyResource {
|
|
20
|
+
_handle: object;
|
|
21
|
+
_autoStart: boolean;
|
|
22
|
+
/** @type {{ hex: string, count: number, timer: any } | null} active invite rendezvous (single topic — one at a time) */
|
|
23
|
+
_announce: {
|
|
24
|
+
hex: string;
|
|
25
|
+
count: number;
|
|
26
|
+
timer: any;
|
|
27
|
+
} | null;
|
|
28
|
+
_restorePending: boolean;
|
|
29
|
+
_topic: any;
|
|
30
|
+
swarm: any;
|
|
19
31
|
/**
|
|
20
32
|
* @param {object} handle Root cero Handle (network + identity + channel).
|
|
21
33
|
* @param {object} [opts]
|
|
@@ -30,23 +42,13 @@ export class Bluetooth extends ReadyResource {
|
|
|
30
42
|
autoStart?: boolean;
|
|
31
43
|
maxOutbound?: number;
|
|
32
44
|
maxInbound?: number;
|
|
33
|
-
pipe?:
|
|
45
|
+
pipe?: 'l2cap' | 'gatt';
|
|
34
46
|
});
|
|
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
47
|
/** @returns {'unsupported'|'unauthorized'|'off'|'waiting'|'starting'|'on'} */
|
|
47
|
-
get state():
|
|
48
|
+
get state(): 'unsupported' | 'unauthorized' | 'off' | 'waiting' | 'starting' | 'on';
|
|
48
49
|
/** @returns {Map<string, any>} Live BLE links, keyed by peer public key. */
|
|
49
50
|
get peers(): Map<string, any>;
|
|
51
|
+
_open(): Promise<void>;
|
|
50
52
|
/**
|
|
51
53
|
* Begin advertising + scanning. Idempotent; no-op when unsupported.
|
|
52
54
|
*
|
|
@@ -94,5 +96,5 @@ export class Bluetooth extends ReadyResource {
|
|
|
94
96
|
* @returns {Promise<void>}
|
|
95
97
|
*/
|
|
96
98
|
resume(): Promise<void>;
|
|
99
|
+
_close(): Promise<void>;
|
|
97
100
|
}
|
|
98
|
-
import ReadyResource from 'ready-resource';
|
package/types/lib/constants.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
export const NS
|
|
2
|
-
export const COUNTERS
|
|
3
|
-
export const EPOCHS
|
|
4
|
-
export const TIMEOUT
|
|
5
|
-
export const FLUSH
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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;
|
|
6
|
+
export declare const DB_TYPE: {
|
|
7
|
+
string: string;
|
|
8
|
+
uint: string;
|
|
9
|
+
int: string;
|
|
10
|
+
bool: string;
|
|
11
|
+
bytes: string;
|
|
12
|
+
json: string;
|
|
13
|
+
fixed32: string;
|
|
14
|
+
fixed64: string;
|
|
15
|
+
file: string;
|
|
16
|
+
};
|
package/types/lib/internal.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
1
|
+
export declare const internal: {
|
|
2
|
+
extensions: ({
|
|
3
3
|
name: string;
|
|
4
4
|
bundled: boolean;
|
|
5
5
|
schema: {
|
|
6
6
|
profile: import("@cero-base/core").TypeDef;
|
|
7
7
|
members: {
|
|
8
|
-
kind:
|
|
8
|
+
kind: 'extend';
|
|
9
9
|
fields: Record<string, import("@cero-base/core").Prim>;
|
|
10
10
|
};
|
|
11
11
|
};
|
|
@@ -15,10 +15,10 @@ export namespace internal {
|
|
|
15
15
|
bundled: boolean;
|
|
16
16
|
schema: {
|
|
17
17
|
handles: {
|
|
18
|
-
kind:
|
|
18
|
+
kind: 'extend';
|
|
19
19
|
fields: Record<string, import("@cero-base/core").Prim>;
|
|
20
20
|
};
|
|
21
21
|
};
|
|
22
22
|
setup(me: any): void;
|
|
23
23
|
})[];
|
|
24
|
-
}
|
|
24
|
+
};
|
package/types/lib/operators.d.ts
CHANGED
|
@@ -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('./
|
|
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;
|
|
@@ -30,7 +43,7 @@ export function resolveFile(handle: object, id: string, name?: string): {
|
|
|
30
43
|
* @param {Record<string, any>} row
|
|
31
44
|
* @returns {Promise<SingleResult>}
|
|
32
45
|
*/
|
|
33
|
-
export function put(ref: Ref, row: Record<string, any>): Promise<SingleResult>;
|
|
46
|
+
export declare function put(ref: Ref, row: Record<string, any>): Promise<SingleResult>;
|
|
34
47
|
/**
|
|
35
48
|
* Upsert a row on `ref` — merges with the existing row and preserves
|
|
36
49
|
* `createdAt`. Pass `{ upsert: false }` to update-only: a missing row is left
|
|
@@ -41,7 +54,7 @@ export function put(ref: Ref, row: Record<string, any>): Promise<SingleResult>;
|
|
|
41
54
|
* @param {{ upsert?: boolean }} [opts]
|
|
42
55
|
* @returns {Promise<SingleResult>}
|
|
43
56
|
*/
|
|
44
|
-
export function set(ref: Ref, row: Record<string, any>, opts?: {
|
|
57
|
+
export declare function set(ref: Ref, row: Record<string, any>, opts?: {
|
|
45
58
|
upsert?: boolean;
|
|
46
59
|
}): Promise<SingleResult>;
|
|
47
60
|
/**
|
|
@@ -51,7 +64,7 @@ export function set(ref: Ref, row: Record<string, any>, opts?: {
|
|
|
51
64
|
* @param {string} [id]
|
|
52
65
|
* @returns {Promise<void>}
|
|
53
66
|
*/
|
|
54
|
-
export function del(ref: Ref, id?: string): Promise<void>;
|
|
67
|
+
export declare function del(ref: Ref, id?: string): Promise<void>;
|
|
55
68
|
/**
|
|
56
69
|
* Count rows on `ref`, optionally filtered.
|
|
57
70
|
*
|
|
@@ -59,7 +72,7 @@ export function del(ref: Ref, id?: string): Promise<void>;
|
|
|
59
72
|
* @param {Record<string, any>} [q]
|
|
60
73
|
* @returns {Promise<{ data: number }>}
|
|
61
74
|
*/
|
|
62
|
-
export function count(ref: Ref, q?: Record<string, any>): Promise<{
|
|
75
|
+
export declare function count(ref: Ref, q?: Record<string, any>): Promise<{
|
|
63
76
|
data: number;
|
|
64
77
|
}>;
|
|
65
78
|
/**
|
|
@@ -69,7 +82,7 @@ export function count(ref: Ref, q?: Record<string, any>): Promise<{
|
|
|
69
82
|
* @param {Record<string, any>} [d]
|
|
70
83
|
* @returns {Promise<any>}
|
|
71
84
|
*/
|
|
72
|
-
export function call(ref: Ref, d?: Record<string, any>): Promise<any>;
|
|
85
|
+
export declare function call(ref: Ref, d?: Record<string, any>): Promise<any>;
|
|
73
86
|
/**
|
|
74
87
|
* Intercept writes to `ref` before they commit — `fn(ctx)` runs in-path
|
|
75
88
|
* (awaited). Return `false` to cancel the write, or mutate `ctx.row`.
|
|
@@ -80,7 +93,7 @@ export function call(ref: Ref, d?: Record<string, any>): Promise<any>;
|
|
|
80
93
|
* @param {{ signal?: AbortSignal }} [opts]
|
|
81
94
|
* @returns {() => void}
|
|
82
95
|
*/
|
|
83
|
-
export function before(ref: Ref, fn: (ctx: {
|
|
96
|
+
export declare function before(ref: Ref, fn: (ctx: {
|
|
84
97
|
op: string;
|
|
85
98
|
name: string;
|
|
86
99
|
row: any;
|
|
@@ -97,7 +110,7 @@ export function before(ref: Ref, fn: (ctx: {
|
|
|
97
110
|
* @param {{ signal?: AbortSignal }} [opts]
|
|
98
111
|
* @returns {() => void}
|
|
99
112
|
*/
|
|
100
|
-
export function after(ref: Ref, fn: (ctx: {
|
|
113
|
+
export declare function after(ref: Ref, fn: (ctx: {
|
|
101
114
|
op: string;
|
|
102
115
|
name: string;
|
|
103
116
|
row: any;
|
|
@@ -113,7 +126,7 @@ export function after(ref: Ref, fn: (ctx: {
|
|
|
113
126
|
* @param {string | Record<string, any>} [q]
|
|
114
127
|
* @returns {Promise<SingleResult | ListResult | GetByIdResult>}
|
|
115
128
|
*/
|
|
116
|
-
export function get(ref: Ref, q?: string | Record<string, any>): Promise<SingleResult | ListResult | GetByIdResult>;
|
|
129
|
+
export declare function get(ref: Ref, q?: string | Record<string, any>): Promise<SingleResult | ListResult | GetByIdResult>;
|
|
117
130
|
/**
|
|
118
131
|
* Live snapshot stream on `ref` — re-emits the latest `get()` result on
|
|
119
132
|
* every underlying mutation. Tied to `ref.handle`'s lifecycle: closing the
|
|
@@ -125,16 +138,16 @@ export function get(ref: Ref, q?: string | Record<string, any>): Promise<SingleR
|
|
|
125
138
|
* @param {{ signal?: AbortSignal }} [opts]
|
|
126
139
|
* @returns {import('streamx').Readable}
|
|
127
140
|
*/
|
|
128
|
-
export function watch(ref: Ref, q?: Record<string, any>, opts?: {
|
|
141
|
+
export declare function watch(ref: Ref, q?: Record<string, any>, opts?: {
|
|
129
142
|
signal?: AbortSignal;
|
|
130
|
-
}): import(
|
|
143
|
+
}): import('streamx').Readable;
|
|
131
144
|
/**
|
|
132
145
|
* Delta subscription: batches of `{ prev, next }` row pairs instead of
|
|
133
146
|
* full snapshots — lossless under backpressure, self-contained (the first
|
|
134
147
|
* batch, and any batch after a view swap, replays current state as inserts
|
|
135
148
|
* with `reset: true`). File-typed fields resolve on both sides.
|
|
136
149
|
*/
|
|
137
|
-
export function changes(ref: any, q: any, opts: any): any;
|
|
150
|
+
export declare function changes(ref: any, q: any, opts: any): any;
|
|
138
151
|
/**
|
|
139
152
|
* Open (or create / join / load) a child handle through a `handle`-kind
|
|
140
153
|
* ref. Dispatches on the normalize of `arg`:
|
|
@@ -148,7 +161,7 @@ export function changes(ref: any, q: any, opts: any): any;
|
|
|
148
161
|
* @param {string | { invite?: string, id?: string, name?: string, routes?: any, role?: string, accept?: boolean } | undefined} [arg]
|
|
149
162
|
* @returns {Promise<CeroHandle>} The resolved child handle.
|
|
150
163
|
*/
|
|
151
|
-
export function open(ref: Ref, arg?: string | {
|
|
164
|
+
export declare function open(ref: Ref, arg?: string | {
|
|
152
165
|
invite?: string;
|
|
153
166
|
id?: string;
|
|
154
167
|
name?: string;
|
|
@@ -168,7 +181,7 @@ export function open(ref: Ref, arg?: string | {
|
|
|
168
181
|
* @param {any} handle
|
|
169
182
|
* @returns {Promise<{ epoch: number }>}
|
|
170
183
|
*/
|
|
171
|
-
export function rotate(handle: any): Promise<{
|
|
184
|
+
export declare function rotate(handle: any): Promise<{
|
|
172
185
|
epoch: number;
|
|
173
186
|
}>;
|
|
174
187
|
/**
|
|
@@ -184,7 +197,7 @@ export function rotate(handle: any): Promise<{
|
|
|
184
197
|
* @param {Record<string, any> | string | null} arg
|
|
185
198
|
* @returns {any} handle
|
|
186
199
|
*/
|
|
187
|
-
export function bind(handle: any, arg: Record<string, any> | string | null): any;
|
|
200
|
+
export declare function bind(handle: any, arg: Record<string, any> | string | null): any;
|
|
188
201
|
/**
|
|
189
202
|
* Register custom operators by scope. A bare key binds on the root handle; a key
|
|
190
203
|
* that names a child-handle type binds on every handle of that type. Call once
|
|
@@ -192,19 +205,6 @@ export function bind(handle: any, arg: Record<string, any> | string | null): any
|
|
|
192
205
|
*
|
|
193
206
|
* @param {Record<string, any>} map
|
|
194
207
|
*/
|
|
195
|
-
export function define(map: Record<string, any>): void;
|
|
208
|
+
export declare function define(map: Record<string, any>): void;
|
|
196
209
|
/** 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
|
-
};
|
|
210
|
+
export declare function _clearDefined(): void;
|
package/types/lib/peek.d.ts
CHANGED
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
* @param {any} spec Built spec — same value passed to `cero(dir, spec)`.
|
|
8
8
|
* @returns {Promise<boolean>} `true` if a master seed exists on disk.
|
|
9
9
|
*/
|
|
10
|
-
export function peek(dir: string, spec: any): Promise<boolean>;
|
|
10
|
+
export declare function peek(dir: string, spec: any): Promise<boolean>;
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
|
15
|
+
* `Local`. Operators (`put`/`get`/`open`/...) take a `Ref` as their first
|
|
16
|
+
* argument and dispatch through the owning handle's store.
|
|
17
|
+
*/
|
|
18
|
+
export declare class Ref {
|
|
19
|
+
handle: any;
|
|
20
|
+
name: string;
|
|
21
|
+
kind: string;
|
|
22
|
+
schema: string;
|
|
23
|
+
/**
|
|
24
|
+
* @param {any} handle Owner — a `Handle` (or `Local`) the ref lives on.
|
|
25
|
+
* @param {string} name Ref name as declared in the schema.
|
|
26
|
+
* @param {string} kind Ref kind: `'collection'`, `'single'`, `'action'`, or `'handle'`.
|
|
27
|
+
* @param {string | null} [schema] Fully-qualified schema id, if any.
|
|
28
|
+
*/
|
|
29
|
+
constructor(handle: any, name: string, kind: string, schema?: string | null);
|
|
30
|
+
/**
|
|
31
|
+
* Attach a `Ref` property to `target` for every entry in `refs`, so callers
|
|
32
|
+
* write `handle.someRef` instead of looking refs up by name.
|
|
33
|
+
*
|
|
34
|
+
* @param {any} target
|
|
35
|
+
* @param {Record<string, RefInfo>} refs
|
|
36
|
+
*/
|
|
37
|
+
static attach(target: any, refs: Record<string, RefInfo>): void;
|
|
38
|
+
}
|
package/types/lib/spec.d.ts
CHANGED
|
@@ -1 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Re-exports of the schema DSL (`t`) and `schema()` wrapper from
|
|
3
|
+
* `@cero-base/core/schema`, so cero apps can describe their tables without
|
|
4
|
+
* pulling in the core package directly.
|
|
5
|
+
*/
|
|
6
|
+
export { t, schema } from '@cero-base/core/schema';
|
package/types/local/index.d.ts
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
import ReadyResource from 'ready-resource';
|
|
2
|
+
import { Storage } from '@cero-base/core/storage';
|
|
3
|
+
export type LocalOpts = {
|
|
4
|
+
/**
|
|
5
|
+
* Pre-existing HypercoreStorage to reuse.
|
|
6
|
+
*/
|
|
7
|
+
root?: any;
|
|
8
|
+
/**
|
|
9
|
+
* Pre-existing Corestore to reuse.
|
|
10
|
+
*/
|
|
11
|
+
store?: any;
|
|
12
|
+
/**
|
|
13
|
+
* 32-byte key encrypting the local store at rest.
|
|
14
|
+
*/
|
|
15
|
+
storageKey?: Uint8Array;
|
|
16
|
+
};
|
|
1
17
|
/**
|
|
2
18
|
* @typedef {object} LocalOpts
|
|
3
19
|
* @property {any} [root] Pre-existing HypercoreStorage to reuse.
|
|
@@ -9,30 +25,16 @@
|
|
|
9
25
|
* device keypair and any per-handle keypairs. Wraps a hyperbee-backed
|
|
10
26
|
* `Storage` and exposes each local ref as a property of the instance.
|
|
11
27
|
*/
|
|
12
|
-
export class Local extends ReadyResource {
|
|
28
|
+
export declare class Local extends ReadyResource {
|
|
29
|
+
dir: string;
|
|
30
|
+
spec: any;
|
|
31
|
+
store: Storage;
|
|
13
32
|
/**
|
|
14
33
|
* @param {string | null} dir Directory for the local store, or `null` when reusing an external `store`.
|
|
15
34
|
* @param {any} spec Built cero spec — must include `spec.local.database` and `spec.meta.local`.
|
|
16
35
|
* @param {LocalOpts} [opts]
|
|
17
36
|
*/
|
|
18
37
|
constructor(dir: string | null, spec: any, { root, store, storageKey }?: LocalOpts);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
store: Storage;
|
|
38
|
+
_open(): Promise<void>;
|
|
39
|
+
_close(): Promise<void>;
|
|
22
40
|
}
|
|
23
|
-
export type LocalOpts = {
|
|
24
|
-
/**
|
|
25
|
-
* Pre-existing HypercoreStorage to reuse.
|
|
26
|
-
*/
|
|
27
|
-
root?: any;
|
|
28
|
-
/**
|
|
29
|
-
* Pre-existing Corestore to reuse.
|
|
30
|
-
*/
|
|
31
|
-
store?: any;
|
|
32
|
-
/**
|
|
33
|
-
* 32-byte key encrypting the local store at rest.
|
|
34
|
-
*/
|
|
35
|
-
storageKey?: Uint8Array;
|
|
36
|
-
};
|
|
37
|
-
import ReadyResource from 'ready-resource';
|
|
38
|
-
import { Storage } from '@cero-base/core/storage';
|