@cero-base/cero 1.18.2 → 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.
@@ -1,14 +1,50 @@
1
- export function getHyperdbType(prim: any): any;
2
- export function builtinRefs(ns: any, scope: any): {
1
+ export declare const refs: {
2
+ main: {
3
+ members: {
4
+ type: string;
5
+ };
6
+ devices: {
7
+ type: string;
8
+ };
9
+ invites: {
10
+ type: string;
11
+ };
12
+ handles: {
13
+ type: string;
14
+ };
15
+ files: {
16
+ type: string;
17
+ };
18
+ };
19
+ local: {
20
+ master: {
21
+ type: string;
22
+ kind: string;
23
+ };
24
+ keypair: {
25
+ type: string;
26
+ kind: string;
27
+ };
28
+ 'handle-keypairs': {
29
+ type: string;
30
+ };
31
+ environment: {
32
+ type: string;
33
+ kind: string;
34
+ };
35
+ };
36
+ };
37
+ export declare function getHyperdbType(prim: any): any;
38
+ export declare function builtinRefs(ns: any, scope: any): {
3
39
  [k: string]: {
4
- schema: string;
5
- verb: any;
6
40
  kind: any;
7
41
  path: string[];
8
42
  builtin: boolean;
43
+ verb: any;
44
+ schema: string;
9
45
  };
10
46
  };
11
- export function builtinTypes(scope: any, extend: any): {
47
+ export declare function builtinTypes(scope: any, extend: any): {
12
48
  name: string;
13
49
  compact: boolean;
14
50
  fields: {
@@ -17,7 +53,7 @@ export function builtinTypes(scope: any, extend: any): {
17
53
  required: boolean;
18
54
  }[];
19
55
  }[];
20
- export function rpcTypes(): {
56
+ export declare function rpcTypes(): {
21
57
  name: string;
22
58
  compact: boolean;
23
59
  fields: {
@@ -26,20 +62,20 @@ export function rpcTypes(): {
26
62
  required: boolean;
27
63
  }[];
28
64
  }[];
29
- export function builtinCollections(ns: any, scope: any): {
65
+ export declare function builtinCollections(ns: any, scope: any): {
30
66
  name: string;
31
67
  schema: string;
32
68
  key: string[];
33
69
  }[];
34
- export function builtinDispatches(ns: any): {
70
+ export declare function builtinDispatches(ns: any): {
35
71
  name: string;
36
72
  requestType: string;
37
73
  }[];
38
- export function rotateDispatch(ns: any): {
74
+ export declare function rotateDispatch(ns: any): {
39
75
  name: string;
40
76
  requestType: string;
41
77
  };
42
- export function rpcCommands(ns: any): ({
78
+ export declare function rpcCommands(ns: any): ({
43
79
  name: string;
44
80
  request: {
45
81
  name: string;
@@ -58,43 +94,3 @@ export function rpcCommands(ns: any): ({
58
94
  stream: boolean;
59
95
  };
60
96
  })[];
61
- export namespace refs {
62
- namespace main {
63
- namespace members {
64
- let type: string;
65
- }
66
- namespace devices {
67
- let type_1: string;
68
- export { type_1 as type };
69
- }
70
- namespace invites {
71
- let type_2: string;
72
- export { type_2 as type };
73
- }
74
- namespace handles {
75
- let type_3: string;
76
- export { type_3 as type };
77
- }
78
- namespace files {
79
- let type_4: string;
80
- export { type_4 as type };
81
- }
82
- }
83
- let local: {
84
- master: {
85
- type: string;
86
- kind: string;
87
- };
88
- keypair: {
89
- type: string;
90
- kind: string;
91
- };
92
- 'handle-keypairs': {
93
- type: string;
94
- };
95
- environment: {
96
- type: string;
97
- kind: string;
98
- };
99
- };
100
- }
@@ -1,10 +1,5 @@
1
- export function build(specDir: any, schema: any, { ns, extensions }?: {
2
- ns?: string;
3
- extensions?: boolean;
4
- }): Promise<void>;
5
- export { getHyperdbType } from "./builtins.js";
6
- export type Schema = import("@cero-base/core/schema").Schema;
7
- export type SchemaDefs = import("@cero-base/core/schema").SchemaDefs;
1
+ export type Schema = import('@cero-base/core/schema').Schema;
2
+ export type SchemaDefs = import('@cero-base/core/schema').SchemaDefs;
8
3
  export type SchemaInput = Schema | (SchemaDefs & {
9
4
  local?: SchemaDefs;
10
5
  });
@@ -14,3 +9,28 @@ export type BuildOpts = {
14
9
  */
15
10
  ns?: string;
16
11
  };
12
+ /**
13
+ * @typedef {import('@cero-base/core/schema').Schema} Schema
14
+ * @typedef {import('@cero-base/core/schema').SchemaDefs} SchemaDefs
15
+ * @typedef {Schema | (SchemaDefs & { local?: SchemaDefs })} SchemaInput
16
+ *
17
+ * @typedef {object} BuildOpts
18
+ * @property {string} [ns] Namespace prefix for emitted schema ids. Defaults to `'cero'`.
19
+ */
20
+ /**
21
+ * Compile a cero schema into wire-level artifacts and write them to disk.
22
+ *
23
+ * Emits a `main/` tree (schema + hyperdb + dispatch + rpc), a `local/` tree
24
+ * for per-device data, one `handles/<name>/` tree per child handle type, and
25
+ * an `index.js` that re-exports a ready-to-use `spec` object.
26
+ *
27
+ * @param {string} specDir Output directory.
28
+ * @param {SchemaInput} schema Either a `schema(...)` wrapper or its raw defs object.
29
+ * @param {BuildOpts} [opts]
30
+ * @returns {Promise<void>}
31
+ */
32
+ export { getHyperdbType } from './builtins.js';
33
+ export declare function build(specDir: any, schema: any, { ns, extensions }?: {
34
+ extensions?: boolean;
35
+ ns?: string;
36
+ }): Promise<void>;
@@ -1,4 +1,4 @@
1
- export const main: {
1
+ export declare const main: {
2
2
  'del-by-id': {
3
3
  id: import("@cero-base/core").Prim;
4
4
  };
@@ -80,7 +80,7 @@ export const main: {
80
80
  stamp: import("@cero-base/core").Prim;
81
81
  };
82
82
  };
83
- export const local: {
83
+ export declare const local: {
84
84
  master: {
85
85
  seed: import("@cero-base/core").Prim;
86
86
  };
@@ -98,7 +98,7 @@ export const local: {
98
98
  channel: import("@cero-base/core").Prim;
99
99
  };
100
100
  };
101
- export const rpc: {
101
+ export declare const rpc: {
102
102
  'req-empty': {
103
103
  ok: import("@cero-base/core").Prim;
104
104
  };
@@ -9,14 +9,14 @@
9
9
  *
10
10
  * @param {{ fields?: Record<string, any> }} [opts]
11
11
  */
12
- export function handleSync({ fields }?: {
12
+ export declare function handleSync({ fields }?: {
13
13
  fields?: Record<string, any>;
14
14
  }): {
15
15
  name: string;
16
16
  bundled: boolean;
17
17
  schema: {
18
18
  handles: {
19
- kind: "extend";
19
+ kind: 'extend';
20
20
  fields: Record<string, import("@cero-base/core").Prim>;
21
21
  };
22
22
  };
@@ -1,2 +1,2 @@
1
- export * from "./profile-sync.js";
2
- export * from "./handle-sync.js";
1
+ export * from './profile-sync.js';
2
+ export * from './handle-sync.js';
@@ -7,7 +7,7 @@
7
7
  *
8
8
  * @param {{ fields?: Record<string, any> }} [opts]
9
9
  */
10
- export function profileSync({ fields }?: {
10
+ export declare function profileSync({ fields }?: {
11
11
  fields?: Record<string, any>;
12
12
  }): {
13
13
  name: string;
@@ -15,7 +15,7 @@ export function profileSync({ fields }?: {
15
15
  schema: {
16
16
  profile: import("@cero-base/core").TypeDef;
17
17
  members: {
18
- kind: "extend";
18
+ kind: 'extend';
19
19
  fields: Record<string, import("@cero-base/core").Prim>;
20
20
  };
21
21
  };
@@ -1,4 +1,131 @@
1
- export { Ref } from "../lib/utils.js";
1
+ import AbortController from 'bare-abort-controller';
2
+ import ReadyResource from 'ready-resource';
3
+ import { Identity } from '@cero-base/core/identity';
4
+ import { Database } from '@cero-base/core/database';
5
+ import { Pairing } from '@cero-base/core/pairing';
6
+ import { Blobs } from '@cero-base/core/blobs';
7
+ import { FileServer } from '@cero-base/core/blobs/server';
8
+ export { Ref } from '../lib/refs.js';
9
+ export type Network = import('@cero-base/core/network').Network;
10
+ export type Local = import('../local/index.js').Local;
11
+ export type KeyPair = import('@cero-base/core/identity').KeyPair;
12
+ export type HandleOpts = {
13
+ /**
14
+ * Parent handle when this is a child slot.
15
+ */
16
+ parent?: Handle;
17
+ /**
18
+ * Long-lived user identity. Inherited from `parent` if omitted.
19
+ */
20
+ identity?: Identity;
21
+ /**
22
+ * Shared swarm. Inherited from `parent` if omitted.
23
+ */
24
+ network?: Network;
25
+ /**
26
+ * Pre-existing Corestore. Falls back to `parent.store.store`.
27
+ */
28
+ store?: any;
29
+ /**
30
+ * Built cero spec.
31
+ */
32
+ spec?: any;
33
+ /**
34
+ * Local store for per-handle keypairs.
35
+ */
36
+ local?: Local;
37
+ /**
38
+ * Owned HypercoreStorage to close on shutdown.
39
+ */
40
+ storage?: any;
41
+ /**
42
+ * Owned identity Discovery to destroy on shutdown.
43
+ */
44
+ discovery?: any;
45
+ /**
46
+ * Data directory (root handles only).
47
+ */
48
+ dir?: string;
49
+ /**
50
+ * Pass-through cero(...) options.
51
+ */
52
+ opts?: any;
53
+ routes?: Record<string, Function>;
54
+ /**
55
+ * Existing database key.
56
+ */
57
+ key?: Uint8Array;
58
+ /**
59
+ * Existing encryption key.
60
+ */
61
+ encryptionKey?: Uint8Array;
62
+ /**
63
+ * Rotation epochs delivered at join.
64
+ */
65
+ epochs?: Array<{
66
+ epoch: number;
67
+ entropy: Uint8Array;
68
+ }>;
69
+ /**
70
+ * Corestore namespace.
71
+ */
72
+ namespace?: string;
73
+ /**
74
+ * Writer keypair.
75
+ */
76
+ keyPair?: KeyPair;
77
+ /**
78
+ * Join discovery server-only; flip later with `setActive`.
79
+ */
80
+ passive?: boolean;
81
+ /**
82
+ * When `false`, skips creating a `Pairing` session.
83
+ */
84
+ pair?: boolean;
85
+ };
86
+ export type CreateChildOpts = {
87
+ name?: string | null;
88
+ routes?: Record<string, Function>;
89
+ role?: string;
90
+ accept?: boolean;
91
+ };
92
+ export type JoinChildOpts = {
93
+ routes?: Record<string, Function>;
94
+ timeout?: number;
95
+ };
96
+ export type StaticJoinOpts = {
97
+ parent?: Handle;
98
+ network?: Network;
99
+ identity?: Identity;
100
+ store?: any;
101
+ spec?: any;
102
+ namespace?: string;
103
+ routes?: Record<string, Function>;
104
+ timeout?: number;
105
+ };
106
+ export type AcceptOpts = {
107
+ /**
108
+ * Role to grant the joining peer. Falls back to the invite's role, then `'member'`.
109
+ */
110
+ role?: string;
111
+ name?: string | null;
112
+ };
113
+ export type HandleExtra = {
114
+ /**
115
+ * Display name; set on child handles by the owner flow.
116
+ */
117
+ name?: string | null;
118
+ /**
119
+ * `profile` ref, attached dynamically when the schema declares one.
120
+ */
121
+ profile?: import('../lib/refs.js').Ref;
122
+ /**
123
+ * `members` ref, attached dynamically when the schema declares one.
124
+ */
125
+ members?: import('../lib/refs.js').Ref;
126
+ };
127
+ export type Child = Handle & HandleExtra;
128
+ export type CeroHandle = Handle & Record<string, import('../lib/refs.js').Ref>;
2
129
  /**
3
130
  * @typedef {import('@cero-base/core/network').Network} Network
4
131
  * @typedef {import('../local/index.js').Local} Local
@@ -48,17 +175,14 @@ export { Ref } from "../lib/utils.js";
48
175
  * @property {string} [role] Role to grant the joining peer. Falls back to the invite's role, then `'member'`.
49
176
  * @property {string | null} [name]
50
177
  *
51
- * @typedef {object} RecoverOpts
52
- * @property {number} [timeout]
53
- *
54
178
  * @typedef {object} HandleExtra
55
179
  * @property {string | null} [name] Display name; set on child handles by the owner flow.
56
- * @property {import('../lib/utils.js').Ref} [profile] `profile` ref, attached dynamically when the schema declares one.
57
- * @property {import('../lib/utils.js').Ref} [members] `members` ref, attached dynamically when the schema declares one.
180
+ * @property {import('../lib/refs.js').Ref} [profile] `profile` ref, attached dynamically when the schema declares one.
181
+ * @property {import('../lib/refs.js').Ref} [members] `members` ref, attached dynamically when the schema declares one.
58
182
  *
59
183
  * @typedef {Handle & HandleExtra} Child A child handle plus its dynamically-attached refs.
60
184
  *
61
- * @typedef {Handle & Record<string, import('../lib/utils.js').Ref>} CeroHandle A handle with every schema ref reachable as a `Ref` property (e.g. `me.profile`, `room.messages`).
185
+ * @typedef {Handle & Record<string, import('../lib/refs.js').Ref>} CeroHandle A handle with every schema ref reachable as a `Ref` property (e.g. `me.profile`, `room.messages`).
62
186
  */
63
187
  /**
64
188
  * A cero handle — a single writable database session attached to a swarm.
@@ -67,18 +191,7 @@ export { Ref } from "../lib/utils.js";
67
191
  * network and corestore. Ref properties (`profile`, `members`, ...) are
68
192
  * attached dynamically per the schema; child handles also carry a `name`.
69
193
  */
70
- export class Handle extends ReadyResource {
71
- /**
72
- * Pair into an existing handle via an invite, returning a brand-new
73
- * `Handle` already configured with the resolved key + encryption key.
74
- *
75
- * @param {string} invite
76
- * @param {StaticJoinOpts} [opts]
77
- * @returns {Promise<Handle>}
78
- */
79
- static join(invite: string, { parent, network, identity, store, spec, namespace, routes, timeout }?: StaticJoinOpts): Promise<Handle>;
80
- /** @param {HandleOpts} [opts] */
81
- constructor(opts?: HandleOpts);
194
+ export declare class Handle extends ReadyResource {
82
195
  identity: any;
83
196
  network: any;
84
197
  spec: any;
@@ -102,6 +215,11 @@ export class Handle extends ReadyResource {
102
215
  pair: Pairing;
103
216
  _wantsPair: boolean;
104
217
  _invitesSync: () => Promise<void>;
218
+ _ac: AbortController;
219
+ /** @param {HandleOpts} [opts] */
220
+ constructor(opts?: HandleOpts);
221
+ _open(): Promise<void>;
222
+ _close(): Promise<void>;
105
223
  /**
106
224
  * Tie a destroyable resource (a `watch` stream, a timer, any `{ destroy }`)
107
225
  * to this handle's lifecycle — it's destroyed automatically on close, so
@@ -123,7 +241,6 @@ export class Handle extends ReadyResource {
123
241
  * @returns {AbortSignal}
124
242
  */
125
243
  get signal(): AbortSignal;
126
- _ac: AbortController;
127
244
  /**
128
245
  * `EventEmitter.on` plus an optional `{ signal }` that removes the listener
129
246
  * when the signal aborts — e.g. `me.on('handle', fn, { signal: me.signal })`.
@@ -190,7 +307,7 @@ export class Handle extends ReadyResource {
190
307
  get id(): any;
191
308
  /** This device's id + name. `null` on child handles. */
192
309
  get device(): {
193
- id: string;
310
+ id: any;
194
311
  name: any;
195
312
  };
196
313
  get suspended(): boolean;
@@ -209,14 +326,6 @@ export class Handle extends ReadyResource {
209
326
  * @returns {Promise<void>}
210
327
  */
211
328
  claim(): Promise<void>;
212
- /**
213
- * Claim + wait until this peer becomes a writer + bring the bee up to date.
214
- * Used by `restore()` after wiping local state.
215
- *
216
- * @param {RecoverOpts} [opts]
217
- * @returns {Promise<void>}
218
- */
219
- recover({ timeout }?: RecoverOpts): Promise<void>;
220
329
  /**
221
330
  * Flip this handle's swarm announce mode — `setActive(false)` demotes an
222
331
  * idle/background room to server-only (still reachable, stops searching);
@@ -324,6 +433,15 @@ export class Handle extends ReadyResource {
324
433
  */
325
434
  resume(): Promise<void>;
326
435
  _resume(): Promise<void>;
436
+ /**
437
+ * Pair into an existing handle via an invite, returning a brand-new
438
+ * `Handle` already configured with the resolved key + encryption key.
439
+ *
440
+ * @param {string} invite
441
+ * @param {StaticJoinOpts} [opts]
442
+ * @returns {Promise<Handle>}
443
+ */
444
+ static join(invite: string, { parent, network, identity, store, spec, namespace, routes, timeout }?: StaticJoinOpts): Promise<Handle>;
327
445
  /**
328
446
  * @param {Handle} child
329
447
  * @param {{ role?: string }} [opts]
@@ -349,139 +467,3 @@ export class Handle extends ReadyResource {
349
467
  secretKey: Uint8Array;
350
468
  } | null>;
351
469
  }
352
- export type Network = import("@cero-base/core/network").Network;
353
- export type Local = import("../local/index.js").Local;
354
- export type KeyPair = import("@cero-base/core/identity").KeyPair;
355
- export type HandleOpts = {
356
- /**
357
- * Parent handle when this is a child slot.
358
- */
359
- parent?: Handle;
360
- /**
361
- * Long-lived user identity. Inherited from `parent` if omitted.
362
- */
363
- identity?: Identity;
364
- /**
365
- * Shared swarm. Inherited from `parent` if omitted.
366
- */
367
- network?: Network;
368
- /**
369
- * Pre-existing Corestore. Falls back to `parent.store.store`.
370
- */
371
- store?: any;
372
- /**
373
- * Built cero spec.
374
- */
375
- spec?: any;
376
- /**
377
- * Local store for per-handle keypairs.
378
- */
379
- local?: Local;
380
- /**
381
- * Owned HypercoreStorage to close on shutdown.
382
- */
383
- storage?: any;
384
- /**
385
- * Owned identity Discovery to destroy on shutdown.
386
- */
387
- discovery?: any;
388
- /**
389
- * Data directory (root handles only).
390
- */
391
- dir?: string;
392
- /**
393
- * Pass-through cero(...) options.
394
- */
395
- opts?: any;
396
- routes?: Record<string, Function>;
397
- /**
398
- * Existing database key.
399
- */
400
- key?: Uint8Array;
401
- /**
402
- * Existing encryption key.
403
- */
404
- encryptionKey?: Uint8Array;
405
- /**
406
- * Rotation epochs delivered at join.
407
- */
408
- epochs?: Array<{
409
- epoch: number;
410
- entropy: Uint8Array;
411
- }>;
412
- /**
413
- * Corestore namespace.
414
- */
415
- namespace?: string;
416
- /**
417
- * Writer keypair.
418
- */
419
- keyPair?: KeyPair;
420
- /**
421
- * Join discovery server-only; flip later with `setActive`.
422
- */
423
- passive?: boolean;
424
- /**
425
- * When `false`, skips creating a `Pairing` session.
426
- */
427
- pair?: boolean;
428
- };
429
- export type CreateChildOpts = {
430
- name?: string | null;
431
- routes?: Record<string, Function>;
432
- role?: string;
433
- accept?: boolean;
434
- };
435
- export type JoinChildOpts = {
436
- routes?: Record<string, Function>;
437
- timeout?: number;
438
- };
439
- export type StaticJoinOpts = {
440
- parent?: Handle;
441
- network?: Network;
442
- identity?: Identity;
443
- store?: any;
444
- spec?: any;
445
- namespace?: string;
446
- routes?: Record<string, Function>;
447
- timeout?: number;
448
- };
449
- export type AcceptOpts = {
450
- /**
451
- * Role to grant the joining peer. Falls back to the invite's role, then `'member'`.
452
- */
453
- role?: string;
454
- name?: string | null;
455
- };
456
- export type RecoverOpts = {
457
- timeout?: number;
458
- };
459
- export type HandleExtra = {
460
- /**
461
- * Display name; set on child handles by the owner flow.
462
- */
463
- name?: string | null;
464
- /**
465
- * `profile` ref, attached dynamically when the schema declares one.
466
- */
467
- profile?: import("../lib/utils.js").Ref;
468
- /**
469
- * `members` ref, attached dynamically when the schema declares one.
470
- */
471
- members?: import("../lib/utils.js").Ref;
472
- };
473
- /**
474
- * A child handle plus its dynamically-attached refs.
475
- */
476
- export type Child = Handle & HandleExtra;
477
- /**
478
- * A handle with every schema ref reachable as a `Ref` property (e.g. `me.profile`, `room.messages`).
479
- */
480
- export type CeroHandle = Handle & Record<string, import("../lib/utils.js").Ref>;
481
- import ReadyResource from 'ready-resource';
482
- import { FileServer } from '@cero-base/core/blobs/server';
483
- import { Blobs } from '@cero-base/core/blobs';
484
- import { Database } from '@cero-base/core/database';
485
- import { Pairing } from '@cero-base/core/pairing';
486
- import AbortController from 'bare-abort-controller';
487
- import { Identity } from '@cero-base/core/identity';