@cero-base/core 0.2.0 → 0.4.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 (52) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +180 -136
  3. package/package.json +123 -28
  4. package/src/blobs/index.js +297 -0
  5. package/src/database/CLAUDE.md +3 -0
  6. package/src/database/bootstrap.js +76 -0
  7. package/src/database/dispatch.js +156 -0
  8. package/src/database/index.js +572 -0
  9. package/src/identity/CLAUDE.md +3 -0
  10. package/src/identity/index.js +232 -0
  11. package/src/index.js +20 -1
  12. package/src/lib/CLAUDE.md +3 -0
  13. package/src/lib/constants.js +24 -4
  14. package/src/lib/errors.js +150 -0
  15. package/src/lib/schema.js +58 -440
  16. package/src/lib/spec/index.js +353 -0
  17. package/src/lib/spec/schema.json +284 -0
  18. package/src/lib/utils.js +54 -49
  19. package/src/network/discovery.js +80 -0
  20. package/src/network/index.js +231 -0
  21. package/src/pairing/index.js +482 -0
  22. package/src/pairing/invite.js +199 -0
  23. package/src/rpc/client.js +45 -0
  24. package/src/rpc/index.js +141 -0
  25. package/src/rpc/server.js +45 -0
  26. package/src/storage/index.js +261 -0
  27. package/types/blobs/index.d.ts +169 -0
  28. package/types/database/bootstrap.d.ts +17 -0
  29. package/types/database/dispatch.d.ts +8 -0
  30. package/types/database/index.d.ts +329 -0
  31. package/types/identity/index.d.ts +160 -0
  32. package/types/index.d.ts +11 -0
  33. package/types/lib/constants.d.ts +13 -0
  34. package/types/lib/errors.d.ts +110 -0
  35. package/types/lib/schema.d.ts +53 -0
  36. package/types/lib/spec/index.d.ts +95 -0
  37. package/types/lib/utils.d.ts +39 -0
  38. package/types/network/discovery.d.ts +44 -0
  39. package/types/network/index.d.ts +115 -0
  40. package/types/pairing/index.d.ts +194 -0
  41. package/types/pairing/invite.d.ts +157 -0
  42. package/types/rpc/client.d.ts +18 -0
  43. package/types/rpc/index.d.ts +67 -0
  44. package/types/rpc/server.d.ts +18 -0
  45. package/types/storage/index.d.ts +163 -0
  46. package/src/lib/base.js +0 -84
  47. package/src/lib/batch.js +0 -98
  48. package/src/lib/builder.js +0 -24
  49. package/src/lib/collection.js +0 -252
  50. package/src/lib/crypto.js +0 -6
  51. package/src/lib/index.js +0 -6
  52. package/src/lib/room.js +0 -145
@@ -0,0 +1,329 @@
1
+ /**
2
+ * @typedef {object} DatabaseOpts
3
+ * @property {any} store Corestore (or compatible) used to materialize the autobee.
4
+ * @property {import('../identity/index.js').Identity} identity Long-lived member identity used to sign writer changes.
5
+ * @property {import('../network/index.js').Network} [network] Optional swarm; required for multi-writer replication.
6
+ * @property {{ database: any, dispatch: any, meta?: { ns?: string, refs?: Record<string, { kind?: string, verb?: string }> } }} spec Generated hyperdb + hyperdispatch spec.
7
+ * @property {Record<string, Function>} [routes] Custom action handlers keyed by route name.
8
+ * @property {string} [namespace] Corestore namespace; defaults to `cero`.
9
+ * @property {Uint8Array | null} [encryptionKey] Optional encryption key; falls back to identity's key.
10
+ * @property {(nodes: any, view: any, host: any) => Promise<void>} [apply] Override the default apply function.
11
+ * @property {Uint8Array | null} [key] Existing autobee key to reopen.
12
+ * @property {import('../identity/index.js').KeyPair} [keyPair] Device writer keypair; defaults to identity's keypair.
13
+ *
14
+ * @typedef {{ data: any | null }} SingleResult
15
+ * @typedef {{ data: any[], total: number, size: number }} ListResult
16
+ * @typedef {{ gt?: string, gte?: string, lt?: string, lte?: string, reverse?: boolean, limit?: number }} Query
17
+ * @typedef {{ kind: string, verb: string, name: string }} Ref
18
+ * @typedef {(ctx: any) => any | Promise<any>} HookFn
19
+ */
20
+ /**
21
+ * Multi-writer database built on Autobee + HyperDB. Persists rows via a
22
+ * hyperdispatch-encoded log and exposes a `put/get/...` surface mirroring
23
+ * `Storage`, plus membership ops (claim/addWriter/removeWriter) for the
24
+ * shared writer set.
25
+ */
26
+ export class Database extends ReadyResource {
27
+ /** @param {Partial<DatabaseOpts>} [opts] */
28
+ constructor(opts?: Partial<DatabaseOpts>);
29
+ store: any;
30
+ identity: import("../index.js").Identity;
31
+ network: import("../index.js").Network;
32
+ spec: {
33
+ database: any;
34
+ dispatch: any;
35
+ meta?: {
36
+ ns?: string;
37
+ refs?: Record<string, {
38
+ kind?: string;
39
+ verb?: string;
40
+ }>;
41
+ };
42
+ };
43
+ meta: {
44
+ ns?: string;
45
+ refs?: Record<string, {
46
+ kind?: string;
47
+ verb?: string;
48
+ }>;
49
+ };
50
+ ns: string;
51
+ refs: Record<string, {
52
+ kind?: string;
53
+ verb?: string;
54
+ }>;
55
+ routes: Record<string, Function>;
56
+ namespace: string;
57
+ encryptionKey: Uint8Array<ArrayBufferLike>;
58
+ applyOverride: (nodes: any, view: any, host: any) => Promise<void>;
59
+ key: Uint8Array<ArrayBufferLike>;
60
+ keyPair: import("../identity/index.js").KeyPair | {
61
+ publicKey: Uint8Array<ArrayBufferLike>;
62
+ secretKey: Uint8Array<ArrayBufferLike>;
63
+ };
64
+ bee: any;
65
+ dispatcher: {
66
+ dispatcher: any;
67
+ apply(nodes: any, view: any, host: any): Promise<void>;
68
+ };
69
+ beforeHooks: Map<any, any>;
70
+ afterHooks: Map<any, any>;
71
+ updaters: Set<any>;
72
+ txQueue: any[];
73
+ _discovery: import("../network/discovery.js").Discovery;
74
+ /** Open the underlying autobee, wire dispatcher + apply, attach to network. */
75
+ openBee(): Promise<void>;
76
+ get discoveryKey(): any;
77
+ get writerKey(): any;
78
+ get writable(): boolean;
79
+ get length(): any;
80
+ get view(): any;
81
+ /**
82
+ * Register a pre-op hook. Returning `false` from `fn` aborts the op.
83
+ *
84
+ * @param {string} op
85
+ * @param {HookFn} fn
86
+ * @returns {() => void} disposer
87
+ */
88
+ before(op: string, fn: HookFn): () => void;
89
+ /**
90
+ * Register a post-op hook, fired after the write succeeds.
91
+ *
92
+ * @param {string} op
93
+ * @param {HookFn} fn
94
+ * @returns {() => void} disposer
95
+ */
96
+ after(op: string, fn: HookFn): () => void;
97
+ /**
98
+ * Subscribe to local apply notifications. Fires whenever the view updates.
99
+ *
100
+ * @param {() => void} fn
101
+ * @returns {() => void} disposer
102
+ */
103
+ onUpdate(fn: () => void): () => void;
104
+ /**
105
+ * Run all registered `before:op` hooks and emit the corresponding event.
106
+ *
107
+ * @param {string} op
108
+ * @param {any} ctx
109
+ * @returns {Promise<boolean>} `false` if any hook vetoed the op
110
+ */
111
+ runBefore(op: string, ctx: any): Promise<boolean>;
112
+ /**
113
+ * Run all registered `after:op` hooks and emit the corresponding event.
114
+ *
115
+ * @param {string} op
116
+ * @param {any} ctx
117
+ * @returns {Promise<void>}
118
+ */
119
+ runAfter(op: string, ctx: any): Promise<void>;
120
+ /**
121
+ * Insert (or overwrite by id) a row, stamping `id`/`createdAt`/`updatedAt`.
122
+ *
123
+ * @param {string} name
124
+ * @param {Record<string, any>} row
125
+ * @returns {Promise<SingleResult | null>}
126
+ */
127
+ put(name: string, row: Record<string, any>): Promise<SingleResult | null>;
128
+ /**
129
+ * Upsert by merging with the existing row, preserving `createdAt`.
130
+ *
131
+ * @param {string} name
132
+ * @param {Record<string, any>} row
133
+ * @returns {Promise<SingleResult | null>}
134
+ */
135
+ set(name: string, row: Record<string, any>): Promise<SingleResult | null>;
136
+ /**
137
+ * Delete by id (collection) or wipe the whole single-row table.
138
+ *
139
+ * @param {string} name
140
+ * @param {string} [id]
141
+ * @returns {Promise<void | null>}
142
+ */
143
+ del(name: string, id?: string): Promise<void | null>;
144
+ /**
145
+ * Dispatch a custom action route by name.
146
+ *
147
+ * @param {string} op
148
+ * @param {Record<string, any>} [data]
149
+ * @returns {Promise<void>}
150
+ */
151
+ call(op: string, data?: Record<string, any>): Promise<void>;
152
+ /**
153
+ * Batch every write performed inside `fn` into a single autobee append.
154
+ * Nested calls reuse the outer queue.
155
+ *
156
+ * @template T
157
+ * @param {() => Promise<T> | T} fn
158
+ * @returns {Promise<T>}
159
+ */
160
+ tx<T>(fn: () => Promise<T> | T): Promise<T>;
161
+ /**
162
+ * Encode and append dispatch ops. Buffers into the active `tx` queue if one
163
+ * is open.
164
+ *
165
+ * @param {Array<[string, any]>} ops
166
+ * @returns {Promise<void>}
167
+ */
168
+ write(ops: Array<[string, any]>): Promise<void>;
169
+ /**
170
+ * Read a row. With no `query`: list all (collection) or fetch the one
171
+ * record (single). With a string id: fetch that specific row.
172
+ *
173
+ * @param {string} name
174
+ * @param {string | Query} [query]
175
+ * @returns {Promise<SingleResult | ListResult>}
176
+ */
177
+ get(name: string, query?: string | Query): Promise<SingleResult | ListResult>;
178
+ /**
179
+ * Number of rows that match `query` (or total if omitted).
180
+ *
181
+ * @param {string} name
182
+ * @param {Query} [query]
183
+ * @returns {Promise<{ data: number }>}
184
+ */
185
+ count(name: string, query?: Query): Promise<{
186
+ data: number;
187
+ }>;
188
+ /**
189
+ * Live snapshot stream — re-emits the latest `get()` result on every
190
+ * underlying mutation. Destroy the stream to stop watching.
191
+ *
192
+ * @param {string} name
193
+ * @param {Query} [query]
194
+ * @returns {import('streamx').Readable}
195
+ */
196
+ watch(name: string, query?: Query): any;
197
+ /**
198
+ * First-run bootstrap: create the device writer, save it, and swap into it.
199
+ *
200
+ * @param {{ name?: string | null, isMobile?: boolean, recovering?: boolean }} [opts]
201
+ * @returns {Promise<{ id: Uint8Array, writer: import('../identity/index.js').KeyPair }>}
202
+ */
203
+ bootstrap(opts?: {
204
+ name?: string | null;
205
+ isMobile?: boolean;
206
+ recovering?: boolean;
207
+ }): Promise<{
208
+ id: Uint8Array;
209
+ writer: import("../identity/index.js").KeyPair;
210
+ }>;
211
+ /**
212
+ * Claim writership on an existing room by signing our writer key with the
213
+ * member identity and appending optimistically.
214
+ *
215
+ * @param {{ name?: string | null, isMobile?: boolean }} [opts]
216
+ * @returns {Promise<void>}
217
+ */
218
+ claim({ name, isMobile }?: {
219
+ name?: string | null;
220
+ isMobile?: boolean;
221
+ }): Promise<void>;
222
+ /**
223
+ * Resolve once the bee becomes writable, or reject after `timeout` ms.
224
+ *
225
+ * @param {{ timeout?: number }} [opts]
226
+ * @returns {Promise<void>}
227
+ */
228
+ whenWritable({ timeout }?: {
229
+ timeout?: number;
230
+ }): Promise<void>;
231
+ /**
232
+ * Add a peer's writer key to the indexer set.
233
+ *
234
+ * @param {Uint8Array} publicKey
235
+ * @returns {Promise<void>}
236
+ */
237
+ addWriter(publicKey: Uint8Array): Promise<void>;
238
+ /**
239
+ * Remove a peer's writer key from the indexer set.
240
+ *
241
+ * @param {Uint8Array} publicKey
242
+ * @returns {Promise<void>}
243
+ */
244
+ removeWriter(publicKey: Uint8Array): Promise<void>;
245
+ guard(): void;
246
+ ref(name: any): {
247
+ name: string;
248
+ kind: string;
249
+ verb: string;
250
+ };
251
+ col(ref: any): string;
252
+ _addHook(map: any, op: any, fn: any): () => void;
253
+ _write(verb: any, hook: any, publicKey: any): Promise<void>;
254
+ }
255
+ export type DatabaseOpts = {
256
+ /**
257
+ * Corestore (or compatible) used to materialize the autobee.
258
+ */
259
+ store: any;
260
+ /**
261
+ * Long-lived member identity used to sign writer changes.
262
+ */
263
+ identity: import("../identity/index.js").Identity;
264
+ /**
265
+ * Optional swarm; required for multi-writer replication.
266
+ */
267
+ network?: import("../network/index.js").Network;
268
+ /**
269
+ * Generated hyperdb + hyperdispatch spec.
270
+ */
271
+ spec: {
272
+ database: any;
273
+ dispatch: any;
274
+ meta?: {
275
+ ns?: string;
276
+ refs?: Record<string, {
277
+ kind?: string;
278
+ verb?: string;
279
+ }>;
280
+ };
281
+ };
282
+ /**
283
+ * Custom action handlers keyed by route name.
284
+ */
285
+ routes?: Record<string, Function>;
286
+ /**
287
+ * Corestore namespace; defaults to `cero`.
288
+ */
289
+ namespace?: string;
290
+ /**
291
+ * Optional encryption key; falls back to identity's key.
292
+ */
293
+ encryptionKey?: Uint8Array | null;
294
+ /**
295
+ * Override the default apply function.
296
+ */
297
+ apply?: (nodes: any, view: any, host: any) => Promise<void>;
298
+ /**
299
+ * Existing autobee key to reopen.
300
+ */
301
+ key?: Uint8Array | null;
302
+ /**
303
+ * Device writer keypair; defaults to identity's keypair.
304
+ */
305
+ keyPair?: import("../identity/index.js").KeyPair;
306
+ };
307
+ export type SingleResult = {
308
+ data: any | null;
309
+ };
310
+ export type ListResult = {
311
+ data: any[];
312
+ total: number;
313
+ size: number;
314
+ };
315
+ export type Query = {
316
+ gt?: string;
317
+ gte?: string;
318
+ lt?: string;
319
+ lte?: string;
320
+ reverse?: boolean;
321
+ limit?: number;
322
+ };
323
+ export type Ref = {
324
+ kind: string;
325
+ verb: string;
326
+ name: string;
327
+ };
328
+ export type HookFn = (ctx: any) => any | Promise<any>;
329
+ import ReadyResource from 'ready-resource';
@@ -0,0 +1,160 @@
1
+ /**
2
+ * @typedef {{ publicKey: Uint8Array, secretKey: Uint8Array, id: string }} KeyPair
3
+ * @typedef {{ publicKey: Uint8Array, secretKey: Uint8Array, encryptionKey: Uint8Array, seed: Uint8Array }} IdentityFields
4
+ */
5
+ /**
6
+ * Long-lived user identity derived from a BIP-39 seed phrase. Holds the
7
+ * sign keypair, a symmetric encryption key and the canonical id/topic used
8
+ * by every other resource to identify this user.
9
+ */
10
+ export class Identity {
11
+ /**
12
+ * Build an identity from 16- or 32-byte entropy.
13
+ *
14
+ * @param {Uint8Array} seed
15
+ * @returns {Promise<Identity>}
16
+ */
17
+ static fromSeed(seed: Uint8Array): Promise<Identity>;
18
+ /**
19
+ * Build an identity from a BIP-39 mnemonic.
20
+ *
21
+ * @param {string} phrase
22
+ * @returns {Promise<Identity>}
23
+ */
24
+ static fromPhrase(phrase: string): Promise<Identity>;
25
+ /**
26
+ * Generate a fresh identity from CSPRNG entropy.
27
+ *
28
+ * @param {{ words?: 12 | 24 }} [opts]
29
+ * @returns {Promise<Identity>}
30
+ */
31
+ static generate({ words }?: {
32
+ words?: 12 | 24;
33
+ }): Promise<Identity>;
34
+ /**
35
+ * Generate a random BIP-39 mnemonic.
36
+ *
37
+ * @param {12 | 24} [words]
38
+ * @returns {string}
39
+ */
40
+ static genPhrase(words?: 12 | 24): string;
41
+ /**
42
+ * Phrase → seed entropy.
43
+ *
44
+ * @param {string} phrase
45
+ * @returns {Uint8Array}
46
+ */
47
+ static toSeed(phrase: string): Uint8Array;
48
+ /**
49
+ * Seed entropy → phrase.
50
+ *
51
+ * @param {Uint8Array} seed
52
+ * @returns {string}
53
+ */
54
+ static toPhrase(seed: Uint8Array): string;
55
+ /**
56
+ * Validate that a value is a 16- or 32-byte buffer.
57
+ *
58
+ * @param {any} x
59
+ * @returns {x is Uint8Array}
60
+ */
61
+ static isSeed(x: any): x is Uint8Array;
62
+ /**
63
+ * Validate that a string is a BIP-39 mnemonic.
64
+ *
65
+ * @param {unknown} x
66
+ * @returns {x is string}
67
+ */
68
+ static isPhrase(x: unknown): x is string;
69
+ /**
70
+ * Verify a signature against an arbitrary public key.
71
+ *
72
+ * @param {Uint8Array} publicKey
73
+ * @param {Uint8Array} message
74
+ * @param {Uint8Array} signature
75
+ * @returns {boolean}
76
+ */
77
+ static verify(publicKey: Uint8Array, message: Uint8Array, signature: Uint8Array): boolean;
78
+ /**
79
+ * Generate a fresh Ed25519 keypair (for devices, blind invites, etc.).
80
+ *
81
+ * @returns {KeyPair}
82
+ */
83
+ static randomKeyPair(): KeyPair;
84
+ /**
85
+ * N bytes from a CSPRNG.
86
+ *
87
+ * @param {number} [n]
88
+ * @returns {Uint8Array}
89
+ */
90
+ static randomBytes(n?: number): Uint8Array;
91
+ /**
92
+ * Fresh seed entropy sized for the chosen mnemonic length.
93
+ *
94
+ * @param {12 | 24} [words]
95
+ * @returns {Uint8Array}
96
+ */
97
+ static randomSeed(words?: 12 | 24): Uint8Array;
98
+ /** @param {IdentityFields} keys */
99
+ constructor(keys: IdentityFields);
100
+ /**
101
+ * Canonical z32-encoded public key.
102
+ *
103
+ * @type {string}
104
+ */
105
+ id: string;
106
+ /** @type {Uint8Array} */
107
+ publicKey: Uint8Array;
108
+ /** @type {Uint8Array} */
109
+ secretKey: Uint8Array;
110
+ /**
111
+ * Symmetric key for encrypting per-identity payloads.
112
+ *
113
+ * @type {Uint8Array}
114
+ */
115
+ encryptionKey: Uint8Array;
116
+ /**
117
+ * Hash of the public key — used as the swarm topic.
118
+ *
119
+ * @type {Uint8Array}
120
+ */
121
+ topic: Uint8Array;
122
+ /**
123
+ * Original 16- or 32-byte entropy.
124
+ *
125
+ * @type {Uint8Array}
126
+ */
127
+ seed: Uint8Array;
128
+ /**
129
+ * Detached Ed25519 signature over `message`.
130
+ *
131
+ * @param {Uint8Array} message
132
+ * @returns {Uint8Array}
133
+ */
134
+ sign(message: Uint8Array): Uint8Array;
135
+ /**
136
+ * Verify a signature against this identity's public key.
137
+ *
138
+ * @param {Uint8Array} message
139
+ * @param {Uint8Array} signature
140
+ * @returns {boolean}
141
+ */
142
+ verify(message: Uint8Array, signature: Uint8Array): boolean;
143
+ /**
144
+ * Render the underlying seed as a BIP-39 mnemonic phrase.
145
+ *
146
+ * @returns {string}
147
+ */
148
+ toPhrase(): string;
149
+ }
150
+ export type KeyPair = {
151
+ publicKey: Uint8Array;
152
+ secretKey: Uint8Array;
153
+ id: string;
154
+ };
155
+ export type IdentityFields = {
156
+ publicKey: Uint8Array;
157
+ secretKey: Uint8Array;
158
+ encryptionKey: Uint8Array;
159
+ seed: Uint8Array;
160
+ };
@@ -0,0 +1,11 @@
1
+ export { Identity } from "./identity/index.js";
2
+ export { Storage } from "./storage/index.js";
3
+ export { Network } from "./network/index.js";
4
+ export { Database } from "./database/index.js";
5
+ export { Blobs } from "./blobs/index.js";
6
+ export { Pairing } from "./pairing/index.js";
7
+ export { Invite } from "./pairing/invite.js";
8
+ export { CeroError } from "./lib/errors.js";
9
+ export { RPCServer, RPCClient, bindCodec } from "./rpc/index.js";
10
+ export { t, schema } from "./lib/schema.js";
11
+ export { genId, toId, toKey, isKeyId, subscribe } from "./lib/utils.js";
@@ -0,0 +1,13 @@
1
+ export const SINGLE: "single";
2
+ export const COLLECTION: "collection";
3
+ export const HANDLE: "handle";
4
+ export const ACTION: "action";
5
+ export const ACTIVE: "active";
6
+ export const PASSIVE: "passive";
7
+ export const ROCKS: "rocks";
8
+ export const BEE: "bee";
9
+ export const OWNER: "owner";
10
+ export const WRITE: "write";
11
+ export const READ: "read";
12
+ export const NAMESPACE: "cero";
13
+ export const COUNTERS: "counters";
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Canonical error class. Every instance carries a stable `code` field which
3
+ * is also prefixed to the message, so logs stay self-identifying. Static
4
+ * factories produce errors with the right code + a sensible message.
5
+ */
6
+ export class CeroError extends Error {
7
+ /**
8
+ * Type-guard for `err instanceof CeroError` that survives realm boundaries.
9
+ *
10
+ * @param {any} err
11
+ * @returns {err is CeroError}
12
+ */
13
+ static isCeroError(err: any): err is CeroError;
14
+ /**
15
+ * Missing required argument.
16
+ *
17
+ * @param {string} name
18
+ */
19
+ static REQUIRED(name: string): CeroError;
20
+ /**
21
+ * Argument failed validation.
22
+ *
23
+ * @param {string} msg
24
+ */
25
+ static INVALID(msg: string): CeroError;
26
+ /**
27
+ * Operation on a closed resource.
28
+ *
29
+ * @param {string} resource
30
+ */
31
+ static CLOSED(resource: string): CeroError;
32
+ /**
33
+ * Operation before `ready()` resolved.
34
+ *
35
+ * @param {string} resource
36
+ * @param {string} name
37
+ */
38
+ static NOT_READY(resource: string, name: string): CeroError;
39
+ /**
40
+ * Resource has been destroyed.
41
+ *
42
+ * @param {string} resource
43
+ */
44
+ static DESTROYED(resource: string): CeroError;
45
+ /**
46
+ * Lookup failed for a typed id.
47
+ *
48
+ * @param {string} kind
49
+ * @param {string} id
50
+ */
51
+ static UNKNOWN(kind: string, id: string): CeroError;
52
+ /**
53
+ * Write attempted on a read-only handle.
54
+ *
55
+ * @param {string} resource
56
+ */
57
+ static NOT_WRITABLE(resource: string): CeroError;
58
+ /**
59
+ * Async operation exceeded its deadline.
60
+ *
61
+ * @param {string} what
62
+ */
63
+ static TIMED_OUT(what: string): CeroError;
64
+ /**
65
+ * Feature is not yet implemented.
66
+ *
67
+ * @param {string} what
68
+ */
69
+ static UNSUPPORTED(what: string): CeroError;
70
+ /**
71
+ * Invite payload failed to parse or verify.
72
+ *
73
+ * @param {string} [msg]
74
+ */
75
+ static INVALID_INVITE(msg?: string): CeroError;
76
+ /**
77
+ * Invite is past its TTL.
78
+ *
79
+ * @param {string} [msg]
80
+ */
81
+ static EXPIRED(msg?: string): CeroError;
82
+ /**
83
+ * Host refused the join — `reason` is exposed on the instance.
84
+ *
85
+ * @param {string | null} [reason]
86
+ * @param {string} [msg]
87
+ */
88
+ static DENIED(reason?: string | null, msg?: string): CeroError;
89
+ /**
90
+ * Pairing handshake did not complete in time.
91
+ *
92
+ * @param {string} [msg]
93
+ */
94
+ static TIMEOUT(msg?: string): CeroError;
95
+ /**
96
+ * Underlying swarm/transport failure.
97
+ *
98
+ * @param {string} [msg]
99
+ */
100
+ static NETWORK_ERROR(msg?: string): CeroError;
101
+ /**
102
+ * @param {string} code Stable identifier (e.g. `REQUIRED`, `EXPIRED`).
103
+ * @param {string} [message] Human-readable detail; appended after the code.
104
+ * @param {Record<string, unknown> | null} [extras] Extra fields copied onto the instance.
105
+ */
106
+ constructor(code: string, message?: string, extras?: Record<string, unknown> | null);
107
+ isCeroError: boolean;
108
+ code: string;
109
+ get name(): string;
110
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Wrap a definitions object so the builder can recognise it as a schema.
3
+ *
4
+ * @param {SchemaDefs} defs
5
+ * @returns {Schema}
6
+ */
7
+ export function schema(defs: SchemaDefs): Schema;
8
+ export namespace t {
9
+ let string: Prim;
10
+ let uint: Prim;
11
+ let int: Prim;
12
+ let bool: Prim;
13
+ let bytes: Prim;
14
+ let json: Prim;
15
+ let fixed32: Prim;
16
+ let fixed64: Prim;
17
+ /**
18
+ * Single-row table (one record, set/get by name).
19
+ *
20
+ * @param {Record<string, Prim>} fields
21
+ * @returns {TypeDef}
22
+ */
23
+ function single(fields: Record<string, Prim>): TypeDef;
24
+ /**
25
+ * Multi-row table keyed by `id`.
26
+ *
27
+ * @param {Record<string, Prim>} fields
28
+ * @returns {TypeDef}
29
+ */
30
+ function collection(fields: Record<string, Prim>): TypeDef;
31
+ /**
32
+ * RPC-style mutation that doesn't persist a row.
33
+ *
34
+ * @param {Record<string, Prim>} fields
35
+ * @returns {TypeDef}
36
+ */
37
+ function action(fields: Record<string, Prim>): TypeDef;
38
+ }
39
+ export type Prim = {
40
+ prim: string;
41
+ };
42
+ export type TypeDef = {
43
+ kind: "single" | "collection" | "action";
44
+ fields: Record<string, Prim>;
45
+ };
46
+ export type SchemaDefs = {
47
+ [name: string]: TypeDef | Record<string, TypeDef>;
48
+ } & {
49
+ local?: Record<string, TypeDef>;
50
+ };
51
+ export type Schema = {
52
+ defs: SchemaDefs;
53
+ };