@cero-base/cero 2.2.1 → 2.3.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 +24 -16
- package/package.json +7 -6
- package/src/build/index.js +38 -34
- package/src/build/internal.js +96 -11
- package/src/build/schemas.js +119 -19
- package/src/extensions/handle-sync.js +8 -12
- package/src/extensions/index.js +17 -63
- package/src/extensions/mirror.js +44 -0
- package/src/extensions/profile-sync.js +10 -12
- package/src/handle/index.js +499 -374
- package/src/handle/join.js +144 -0
- package/src/index.js +89 -118
- package/src/lib/bluetooth.js +83 -19
- package/src/lib/constants.js +1 -0
- package/src/lib/operators.js +298 -128
- package/src/lib/peek.js +1 -1
- package/src/lib/refs.js +7 -7
- package/src/lib/spec.js +32 -0
- package/src/local/index.js +27 -3
- package/src/rpc/client.js +240 -202
- package/src/rpc/server.js +186 -133
- package/types/build/index.d.ts +3 -8
- package/types/build/internal.d.ts +86 -27
- package/types/build/schemas.d.ts +91 -12
- package/types/extensions/handle-sync.d.ts +4 -12
- package/types/extensions/index.d.ts +59 -59
- package/types/extensions/mirror.d.ts +13 -0
- package/types/extensions/profile-sync.d.ts +4 -13
- package/types/handle/index.d.ts +229 -198
- package/types/handle/join.d.ts +63 -0
- package/types/index.d.ts +27 -55
- package/types/lib/bluetooth.d.ts +57 -19
- package/types/lib/constants.d.ts +1 -0
- package/types/lib/operators.d.ts +166 -81
- package/types/lib/peek.d.ts +2 -2
- package/types/lib/refs.d.ts +14 -15
- package/types/lib/spec.d.ts +87 -0
- package/types/local/index.d.ts +19 -9
- package/types/rpc/client.d.ts +55 -112
- package/types/rpc/server.d.ts +91 -50
- package/src/rpc/index.js +0 -8
- package/types/rpc/index.d.ts +0 -7
package/types/lib/spec.d.ts
CHANGED
|
@@ -3,3 +3,90 @@
|
|
|
3
3
|
* so cero apps can describe their tables without pulling in the core package directly.
|
|
4
4
|
*/
|
|
5
5
|
export { t, schema } from '@cero-base/core/schema';
|
|
6
|
+
export type RefInfo = {
|
|
7
|
+
kind?: 'single' | 'collection' | 'action' | 'handle';
|
|
8
|
+
schema?: string;
|
|
9
|
+
/**
|
|
10
|
+
* The handle type a `handle` ref opens.
|
|
11
|
+
*/
|
|
12
|
+
type?: string;
|
|
13
|
+
/**
|
|
14
|
+
* A builtin: members, devices, files and the like.
|
|
15
|
+
*/
|
|
16
|
+
internal?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Computed on the device, never stored: status, joins, nearby.
|
|
19
|
+
*/
|
|
20
|
+
live?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* The declared fields, in schema order.
|
|
23
|
+
*/
|
|
24
|
+
fields?: string[];
|
|
25
|
+
/**
|
|
26
|
+
* The required fields and their types.
|
|
27
|
+
*/
|
|
28
|
+
required?: Record<string, string>;
|
|
29
|
+
/**
|
|
30
|
+
* The fields holding file ids.
|
|
31
|
+
*/
|
|
32
|
+
files?: string[];
|
|
33
|
+
verb?: string;
|
|
34
|
+
};
|
|
35
|
+
export type SpecMeta = {
|
|
36
|
+
ns?: string;
|
|
37
|
+
/**
|
|
38
|
+
* The handle type, on a handle's spec.
|
|
39
|
+
*/
|
|
40
|
+
type?: string;
|
|
41
|
+
version?: number;
|
|
42
|
+
refs: Record<string, RefInfo>;
|
|
43
|
+
local?: {
|
|
44
|
+
refs: Record<string, RefInfo>;
|
|
45
|
+
};
|
|
46
|
+
handles?: Record<string, SpecMeta>;
|
|
47
|
+
};
|
|
48
|
+
export type Spec = import('@cero-base/core/rpc').Spec & {
|
|
49
|
+
meta: SpecMeta;
|
|
50
|
+
database?: object;
|
|
51
|
+
dispatch?: object;
|
|
52
|
+
local?: {
|
|
53
|
+
database: object;
|
|
54
|
+
schema: object;
|
|
55
|
+
meta: SpecMeta;
|
|
56
|
+
codec?: import('@cero-base/core/rpc').Codec;
|
|
57
|
+
};
|
|
58
|
+
extensions?: import('../extensions/index.js').Extension[] | null;
|
|
59
|
+
handles?: Record<string, Spec>;
|
|
60
|
+
};
|
|
61
|
+
export type Row = import('@cero-base/core/database').Row;
|
|
62
|
+
/**
|
|
63
|
+
* @typedef {object} RefInfo One entry of a spec's `meta.refs`.
|
|
64
|
+
* @property {'single' | 'collection' | 'action' | 'handle'} [kind]
|
|
65
|
+
* @property {string} [schema]
|
|
66
|
+
* @property {string} [type] The handle type a `handle` ref opens.
|
|
67
|
+
* @property {boolean} [internal] A builtin: members, devices, files and the like.
|
|
68
|
+
* @property {boolean} [live] Computed on the device, never stored: status, joins, nearby.
|
|
69
|
+
* @property {string[]} [fields] The declared fields, in schema order.
|
|
70
|
+
* @property {Record<string, string>} [required] The required fields and their types.
|
|
71
|
+
* @property {string[]} [files] The fields holding file ids.
|
|
72
|
+
* @property {string} [verb]
|
|
73
|
+
*
|
|
74
|
+
* @typedef {object} SpecMeta
|
|
75
|
+
* @property {string} [ns]
|
|
76
|
+
* @property {string} [type] The handle type, on a handle's spec.
|
|
77
|
+
* @property {number} [version]
|
|
78
|
+
* @property {Record<string, RefInfo>} refs
|
|
79
|
+
* @property {{ refs: Record<string, RefInfo> }} [local]
|
|
80
|
+
* @property {Record<string, SpecMeta>} [handles]
|
|
81
|
+
*
|
|
82
|
+
* @typedef {import('@cero-base/core/rpc').Spec & {
|
|
83
|
+
* meta: SpecMeta,
|
|
84
|
+
* database?: object,
|
|
85
|
+
* dispatch?: object,
|
|
86
|
+
* local?: { database: object, schema: object, meta: SpecMeta, codec?: import('@cero-base/core/rpc').Codec },
|
|
87
|
+
* extensions?: import('../extensions/index.js').Extension[] | null,
|
|
88
|
+
* handles?: Record<string, Spec>
|
|
89
|
+
* }} Spec What `build` writes and `cero()` opens.
|
|
90
|
+
*
|
|
91
|
+
* @typedef {import('@cero-base/core/database').Row} Row
|
|
92
|
+
*/
|
package/types/local/index.d.ts
CHANGED
|
@@ -4,11 +4,11 @@ export type LocalOpts = {
|
|
|
4
4
|
/**
|
|
5
5
|
* Pre-existing HypercoreStorage to reuse.
|
|
6
6
|
*/
|
|
7
|
-
root?:
|
|
7
|
+
root?: import('hypercore-storage');
|
|
8
8
|
/**
|
|
9
9
|
* Pre-existing Corestore to reuse.
|
|
10
10
|
*/
|
|
11
|
-
store?:
|
|
11
|
+
store?: import('corestore');
|
|
12
12
|
/**
|
|
13
13
|
* 32-byte key encrypting the local store at rest.
|
|
14
14
|
*/
|
|
@@ -16,8 +16,8 @@ export type LocalOpts = {
|
|
|
16
16
|
};
|
|
17
17
|
/**
|
|
18
18
|
* @typedef {object} LocalOpts
|
|
19
|
-
* @property {
|
|
20
|
-
* @property {
|
|
19
|
+
* @property {import('hypercore-storage')} [root] Pre-existing HypercoreStorage to reuse.
|
|
20
|
+
* @property {import('corestore')} [store] Pre-existing Corestore to reuse.
|
|
21
21
|
* @property {Uint8Array} [storageKey] 32-byte key encrypting the local store at rest.
|
|
22
22
|
*/
|
|
23
23
|
/**
|
|
@@ -26,14 +26,24 @@ export type LocalOpts = {
|
|
|
26
26
|
*/
|
|
27
27
|
export declare class Local extends ReadyResource {
|
|
28
28
|
dir: string;
|
|
29
|
-
spec:
|
|
29
|
+
spec: import("../lib/spec.js").Spec;
|
|
30
30
|
store: Storage;
|
|
31
31
|
/**
|
|
32
32
|
* @param {string | null} dir Directory for the local store, or `null` when reusing an external `store`.
|
|
33
|
-
* @param {
|
|
33
|
+
* @param {import('../lib/spec.js').Spec} spec Built cero spec, with `spec.local.database` and `spec.meta.local`.
|
|
34
34
|
* @param {LocalOpts} [opts]
|
|
35
35
|
*/
|
|
36
|
-
constructor(dir: string | null, spec:
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
constructor(dir: string | null, spec: import('../lib/spec.js').Spec, { root, store, storageKey }?: LocalOpts);
|
|
37
|
+
/** @private */
|
|
38
|
+
private _open;
|
|
39
|
+
/** @private */
|
|
40
|
+
private _close;
|
|
39
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* One of the mailbox's boxes, kept in the local store so mail survives a restart.
|
|
44
|
+
*
|
|
45
|
+
* @param {import('@cero-base/core/storage').Storage} store
|
|
46
|
+
* @param {'inbox' | 'outbox'} name
|
|
47
|
+
* @returns {import('@cero-base/core/mailbox').Box}
|
|
48
|
+
*/
|
|
49
|
+
export declare function box(store: import('@cero-base/core/storage').Storage, name: 'inbox' | 'outbox'): import('@cero-base/core/mailbox').Box;
|
package/types/rpc/client.d.ts
CHANGED
|
@@ -1,40 +1,14 @@
|
|
|
1
1
|
import { RPCClient } from '@cero-base/core/rpc';
|
|
2
|
-
import
|
|
2
|
+
import * as verbs from '../lib/operators.js';
|
|
3
3
|
import { t, schema } from '../lib/spec.js';
|
|
4
|
-
export
|
|
4
|
+
export declare const put: typeof verbs.put, set: typeof verbs.set, get: typeof verbs.get, del: typeof verbs.del, watch: typeof verbs.watch, call: typeof verbs.call, open: typeof verbs.open, invite: typeof verbs.invite, revoke: typeof verbs.revoke, rotate: typeof verbs.rotate, accept: typeof verbs.accept, deny: typeof verbs.deny, leave: typeof verbs.leave, close: typeof verbs.close, cancel: typeof verbs.cancel, suspend: typeof verbs.suspend, resume: typeof verbs.resume, activate: typeof verbs.activate, deactivate: typeof verbs.deactivate, phrase: typeof verbs.phrase, nearby: typeof verbs.nearby;
|
|
5
|
+
export { t, schema };
|
|
5
6
|
export type BaseRPCClient = import('@cero-base/core/rpc').RPCClient;
|
|
6
|
-
export type RefInfo =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
12
|
-
export type Spec = import('@cero-base/core/rpc').Spec & {
|
|
13
|
-
meta: {
|
|
14
|
-
ns?: string;
|
|
15
|
-
refs: Record<string, RefInfo>;
|
|
16
|
-
local?: {
|
|
17
|
-
refs: Record<string, RefInfo>;
|
|
18
|
-
};
|
|
19
|
-
handles?: Record<string, Spec>;
|
|
20
|
-
};
|
|
21
|
-
handles: Record<string, Spec>;
|
|
22
|
-
};
|
|
23
|
-
export type SingleResult = {
|
|
24
|
-
data: any;
|
|
25
|
-
};
|
|
26
|
-
export type ListResult = {
|
|
27
|
-
data: any[];
|
|
28
|
-
total: number;
|
|
29
|
-
size: number;
|
|
30
|
-
};
|
|
31
|
-
export type GetByIdResult = {
|
|
32
|
-
data: any | null;
|
|
33
|
-
};
|
|
34
|
-
export type ClientIdentity = {
|
|
35
|
-
id: string;
|
|
36
|
-
toPhrase: () => string | null;
|
|
37
|
-
};
|
|
7
|
+
export type RefInfo = import('../lib/spec.js').RefInfo;
|
|
8
|
+
export type Spec = import('../lib/spec.js').Spec;
|
|
9
|
+
export type Row = import('../lib/spec.js').Row;
|
|
10
|
+
export type SingleResult = import('../lib/operators.js').SingleResult;
|
|
11
|
+
export type ListResult = import('../lib/operators.js').ListResult;
|
|
38
12
|
export type HandleStub = {
|
|
39
13
|
id: string;
|
|
40
14
|
type: string;
|
|
@@ -56,13 +30,18 @@ declare class LocalRefs {
|
|
|
56
30
|
parent: Client;
|
|
57
31
|
spec: import("@cero-base/core").Spec;
|
|
58
32
|
store: this;
|
|
59
|
-
|
|
33
|
+
/** @private */
|
|
34
|
+
_local;
|
|
60
35
|
/** @param {Client} client */
|
|
61
36
|
constructor(client: Client);
|
|
62
37
|
/** Underlying RPC channel borrowed from the parent. */
|
|
63
|
-
get rpc():
|
|
64
|
-
/**
|
|
65
|
-
|
|
38
|
+
get rpc(): object;
|
|
39
|
+
/**
|
|
40
|
+
* The root's id: local ops resolve against the root's local store.
|
|
41
|
+
*
|
|
42
|
+
* @returns {string | null}
|
|
43
|
+
*/
|
|
44
|
+
get id(): string | null;
|
|
66
45
|
}
|
|
67
46
|
/**
|
|
68
47
|
* IPC-side RPC client for cero. Wraps an `hrpc` channel and exposes the same
|
|
@@ -70,117 +49,81 @@ declare class LocalRefs {
|
|
|
70
49
|
* across the wire.
|
|
71
50
|
*/
|
|
72
51
|
export declare class Client extends RPCClient {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
52
|
+
/** @private */
|
|
53
|
+
_onerror;
|
|
54
|
+
/** @type {string | null} */
|
|
55
|
+
id: string | null;
|
|
56
|
+
/** @type {{ id: string, name: string | null } | null} */
|
|
57
|
+
device: {
|
|
58
|
+
id: string;
|
|
59
|
+
name: string | null;
|
|
60
|
+
} | null;
|
|
76
61
|
store: this;
|
|
77
62
|
local: LocalRefs;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
toPhrase: () => Promise<any>;
|
|
83
|
-
};
|
|
63
|
+
/** @private */
|
|
64
|
+
_fileBase;
|
|
65
|
+
/** @private */
|
|
66
|
+
_fileToken;
|
|
84
67
|
/**
|
|
85
|
-
* @param {
|
|
68
|
+
* @param {import('streamx').Duplex} ipc Framed IPC stream (must be writable).
|
|
86
69
|
* @param {Spec} spec Compiled cero spec (schema + rpc + handles).
|
|
87
|
-
* @param {{
|
|
70
|
+
* @param {{ onerror?: (err: Error) => void }} [opts] Where the worker's background errors go; the console without one.
|
|
88
71
|
*/
|
|
89
|
-
constructor(ipc:
|
|
90
|
-
|
|
72
|
+
constructor(ipc: import('streamx').Duplex, spec: Spec, { onerror }?: {
|
|
73
|
+
onerror?: (err: Error) => void;
|
|
91
74
|
});
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
|
|
96
|
-
/** Resume a suspended server. Idempotent. */
|
|
97
|
-
resume(): Promise<void>;
|
|
75
|
+
/** @private */
|
|
76
|
+
private _pumpErrors;
|
|
77
|
+
/** @private */
|
|
78
|
+
private _open;
|
|
98
79
|
/**
|
|
99
80
|
* Create a new child handle of the given type.
|
|
100
81
|
*
|
|
101
82
|
* @param {string} type
|
|
102
|
-
* @param {
|
|
83
|
+
* @param {{ name?: string | null }} [opts]
|
|
103
84
|
* @returns {Promise<Handle>}
|
|
85
|
+
* @private
|
|
104
86
|
*/
|
|
105
|
-
_create
|
|
87
|
+
private _create;
|
|
106
88
|
/**
|
|
107
89
|
* Load an existing child handle by id.
|
|
108
90
|
*
|
|
109
91
|
* @param {string} type
|
|
110
92
|
* @param {string} id
|
|
111
93
|
* @returns {Promise<Handle>}
|
|
94
|
+
* @private
|
|
112
95
|
*/
|
|
113
|
-
_load
|
|
96
|
+
private _load;
|
|
114
97
|
/**
|
|
115
98
|
* Join a child handle via invite.
|
|
116
99
|
*
|
|
117
100
|
* @param {string} invite
|
|
118
101
|
* @param {string} type
|
|
119
102
|
* @returns {Promise<Handle>}
|
|
103
|
+
* @private
|
|
120
104
|
*/
|
|
121
|
-
_join
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Client-side proxy for a remote handle. Exposes the same row-ops surface as `Client` but
|
|
125
|
-
* scoped to a single child handle id, and routes every call through the parent's RPC
|
|
126
|
-
* channel.
|
|
127
|
-
*/
|
|
128
|
-
declare class Handle {
|
|
129
|
-
parent: Client;
|
|
130
|
-
id: string;
|
|
131
|
-
type: string;
|
|
132
|
-
name: string;
|
|
133
|
-
spec: Spec;
|
|
134
|
-
store: this;
|
|
135
|
-
/**
|
|
136
|
-
* @param {Client} parent
|
|
137
|
-
* @param {string} id
|
|
138
|
-
* @param {string} type
|
|
139
|
-
* @param {string|null} name
|
|
140
|
-
*/
|
|
141
|
-
constructor(parent: Client, id: string, type: string, name: string | null);
|
|
142
|
-
/** Underlying RPC channel borrowed from the parent. */
|
|
143
|
-
get rpc(): any;
|
|
144
|
-
/** Tear down the remote handle without leaving the room. */
|
|
145
|
-
close(): any;
|
|
146
|
-
/** Tear down the remote handle and drop membership. */
|
|
147
|
-
leave(): any;
|
|
105
|
+
private _join;
|
|
148
106
|
}
|
|
149
107
|
/**
|
|
150
108
|
* Construct a `Client`, wait for `init` to complete, and return it.
|
|
151
109
|
*
|
|
152
|
-
* @param {
|
|
153
|
-
* @param {
|
|
154
|
-
* @param {{
|
|
110
|
+
* @param {import('streamx').Duplex} ipc
|
|
111
|
+
* @param {Spec} spec
|
|
112
|
+
* @param {{ onerror?: (err: Error) => void }} [opts]
|
|
155
113
|
* @returns {Promise<Client>}
|
|
156
114
|
*/
|
|
157
|
-
export declare function connect(ipc:
|
|
158
|
-
|
|
115
|
+
export declare function connect(ipc: import('streamx').Duplex, spec: Spec, opts?: {
|
|
116
|
+
onerror?: (err: Error) => void;
|
|
159
117
|
}): Promise<Client>;
|
|
160
118
|
/**
|
|
161
119
|
* Symmetric client entry. Mirrors the main `cero`, but `cero(ipc, spec)` connects to a
|
|
162
120
|
* server (via `connect`) instead of opening a local store.
|
|
163
121
|
*
|
|
164
|
-
* @param {
|
|
165
|
-
* @param {
|
|
166
|
-
* @param {{
|
|
122
|
+
* @param {import('streamx').Duplex} ipc Framed IPC duplex stream.
|
|
123
|
+
* @param {Spec} spec Built cero spec.
|
|
124
|
+
* @param {{ onerror?: (err: Error) => void }} [opts]
|
|
167
125
|
* @returns {Promise<Client>}
|
|
168
126
|
*/
|
|
169
|
-
export declare function cero(ipc:
|
|
170
|
-
|
|
127
|
+
export declare function cero(ipc: import('streamx').Duplex, spec: Spec, opts?: {
|
|
128
|
+
onerror?: (err: Error) => void;
|
|
171
129
|
}): Promise<Client>;
|
|
172
|
-
export declare namespace cero {
|
|
173
|
-
export { connect };
|
|
174
|
-
export { restore };
|
|
175
|
-
export { t };
|
|
176
|
-
export { put };
|
|
177
|
-
export { set };
|
|
178
|
-
export { get };
|
|
179
|
-
export { del };
|
|
180
|
-
export { watch };
|
|
181
|
-
export { changes };
|
|
182
|
-
export { call };
|
|
183
|
-
export { open };
|
|
184
|
-
export { rotate };
|
|
185
|
-
export { schema };
|
|
186
|
-
}
|
package/types/rpc/server.d.ts
CHANGED
|
@@ -28,13 +28,20 @@ export type Identity = {
|
|
|
28
28
|
* Per-device id (empty when no `local` spec).
|
|
29
29
|
*/
|
|
30
30
|
deviceId: string;
|
|
31
|
+
/**
|
|
32
|
+
* This device's name, empty when it has none.
|
|
33
|
+
*/
|
|
34
|
+
deviceName: string;
|
|
31
35
|
};
|
|
32
36
|
export type RefAndCodec = {
|
|
33
|
-
ref:
|
|
34
|
-
codec:
|
|
37
|
+
ref: import('../lib/refs.js').Ref;
|
|
38
|
+
codec: import('@cero-base/core/rpc').Codec;
|
|
39
|
+
info?: import('../lib/spec.js').RefInfo;
|
|
35
40
|
};
|
|
41
|
+
export type Spec = import('../lib/spec.js').Spec;
|
|
42
|
+
export type Context = import('../handle/index.js').Context;
|
|
36
43
|
export type GetResult = {
|
|
37
|
-
data:
|
|
44
|
+
data: import('../lib/spec.js').Row | import('../lib/spec.js').Row[] | null;
|
|
38
45
|
total?: number;
|
|
39
46
|
size?: number;
|
|
40
47
|
};
|
|
@@ -51,74 +58,103 @@ export type GetResult = {
|
|
|
51
58
|
* @typedef {object} Identity
|
|
52
59
|
* @property {string} id Long-lived cero identity id.
|
|
53
60
|
* @property {string} deviceId Per-device id (empty when no `local` spec).
|
|
61
|
+
* @property {string} deviceName This device's name, empty when it has none.
|
|
62
|
+
*
|
|
63
|
+
* @typedef {{ ref: import('../lib/refs.js').Ref, codec: import('@cero-base/core/rpc').Codec, info?: import('../lib/spec.js').RefInfo }} RefAndCodec
|
|
54
64
|
*
|
|
55
|
-
* @typedef {
|
|
65
|
+
* @typedef {import('../lib/spec.js').Spec} Spec
|
|
66
|
+
* @typedef {import('../handle/index.js').Context} Context
|
|
56
67
|
*
|
|
57
|
-
* @typedef {{ data:
|
|
68
|
+
* @typedef {{ data: import('../lib/spec.js').Row | import('../lib/spec.js').Row[] | null, total?: number, size?: number }} GetResult Single-ref get omits `total`/`size`; list/handle refs include them.
|
|
58
69
|
*/
|
|
59
70
|
/**
|
|
60
|
-
* IPC-side RPC server for cero. Bridges an `hrpc` channel to a live `Handle` tree:
|
|
61
|
-
*
|
|
62
|
-
* pairing, and handle lifecycle.
|
|
71
|
+
* IPC-side RPC server for cero. Bridges an `hrpc` channel to a live `Handle` tree: boots the
|
|
72
|
+
* root via `cero()` as soon as it opens, so the network is up while the UI still loads, then
|
|
73
|
+
* exposes data ops, pairing, and handle lifecycle.
|
|
63
74
|
*/
|
|
64
75
|
export declare class Server extends RPCServer {
|
|
65
76
|
storage: string;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
port: number;
|
|
72
|
-
}>;
|
|
73
|
-
isMobile?: boolean;
|
|
74
|
-
onerror: (err: any) => void;
|
|
77
|
+
/** @private */
|
|
78
|
+
_report;
|
|
79
|
+
/** @type {Omit<Partial<ServerOpts>, 'storage'> & { onerror: (err: Error) => void }} */
|
|
80
|
+
opts: Omit<Partial<ServerOpts>, 'storage'> & {
|
|
81
|
+
onerror: (err: Error) => void;
|
|
75
82
|
};
|
|
76
83
|
/** @type {Set<object>} open error streams, one per connected client */
|
|
77
84
|
_errors: Set<object>;
|
|
78
|
-
|
|
79
|
-
|
|
85
|
+
/** @type {Context | null} */
|
|
86
|
+
me: Context | null;
|
|
87
|
+
/** @type {Map<string, Context>} */
|
|
88
|
+
handles: Map<string, Context>;
|
|
80
89
|
/** @type {Map<string, Set<object>>} handle id → its open watch streams */
|
|
81
90
|
_watchStreams: Map<string, Set<object>>;
|
|
91
|
+
/** @private */
|
|
92
|
+
_booting;
|
|
82
93
|
/**
|
|
83
|
-
* @param {
|
|
84
|
-
* @param {
|
|
94
|
+
* @param {import('streamx').Duplex} ipc Framed IPC stream (must be writable).
|
|
95
|
+
* @param {Spec} spec
|
|
85
96
|
* @param {Partial<ServerOpts>} [opts]
|
|
86
97
|
*/
|
|
87
|
-
constructor(ipc:
|
|
98
|
+
constructor(ipc: import('streamx').Duplex, spec: Spec, { storage, ...opts }?: Partial<ServerOpts>);
|
|
88
99
|
/**
|
|
89
|
-
* Root cero id (
|
|
100
|
+
* Root cero id (undefined until booted).
|
|
90
101
|
*
|
|
91
102
|
* @returns {string|undefined}
|
|
92
103
|
*/
|
|
93
104
|
get id(): string | undefined;
|
|
94
105
|
/**
|
|
95
|
-
* Root identity object (
|
|
106
|
+
* Root identity object (undefined until booted).
|
|
96
107
|
*
|
|
97
|
-
* @returns {
|
|
98
|
-
*/
|
|
99
|
-
get identity():
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
108
|
+
* @returns {import('@cero-base/core/identity').Identity | undefined}
|
|
109
|
+
*/
|
|
110
|
+
get identity(): import('@cero-base/core/identity').Identity | undefined;
|
|
111
|
+
/** @private */
|
|
112
|
+
private _open;
|
|
113
|
+
/** @private */
|
|
114
|
+
private _boot;
|
|
115
|
+
/** @private */
|
|
116
|
+
private _close;
|
|
117
|
+
/**
|
|
118
|
+
* End every watch stream bound to a handle (e.g. when it closes or leaves).
|
|
119
|
+
* @private
|
|
120
|
+
*/
|
|
121
|
+
private _endWatches;
|
|
122
|
+
/** @private */
|
|
123
|
+
private _onerror;
|
|
124
|
+
/**
|
|
125
|
+
* Wire the `errors` and `init` handlers: init waits for the boot and attaches the client.
|
|
126
|
+
* @private
|
|
127
|
+
*/
|
|
128
|
+
private _wireInit;
|
|
129
|
+
/**
|
|
130
|
+
* Wire the `restore` handler. The phrase becomes a seed here: the UI cannot load the crypto it takes.
|
|
131
|
+
* @private
|
|
132
|
+
*/
|
|
133
|
+
private _wireRestore;
|
|
134
|
+
/**
|
|
135
|
+
* Register the row-level RPC handlers (put/set/get/del/watch/call).
|
|
136
|
+
* @private
|
|
137
|
+
*/
|
|
138
|
+
private _wireData;
|
|
139
|
+
/**
|
|
140
|
+
* Register invite/revoke/join RPC handlers.
|
|
141
|
+
* @private
|
|
142
|
+
*/
|
|
143
|
+
private _wirePairing;
|
|
144
|
+
/**
|
|
145
|
+
* Register add/open/close/leave RPC handlers for child handles.
|
|
146
|
+
* @private
|
|
147
|
+
*/
|
|
148
|
+
private _wireHandles;
|
|
114
149
|
/**
|
|
115
150
|
* Look up a live handle by id, throwing if unknown. Binds the handle's
|
|
116
151
|
* codec on first use.
|
|
117
152
|
*
|
|
118
153
|
* @param {string} id
|
|
119
|
-
* @returns {
|
|
154
|
+
* @returns {Context}
|
|
155
|
+
* @private
|
|
120
156
|
*/
|
|
121
|
-
_resolve
|
|
157
|
+
private _resolve;
|
|
122
158
|
/**
|
|
123
159
|
* Resolve a `{ handle, ref }` pair to its `Ref` and codec.
|
|
124
160
|
*
|
|
@@ -126,23 +162,28 @@ export declare class Server extends RPCServer {
|
|
|
126
162
|
* @param {string} name
|
|
127
163
|
* @param {boolean} [local]
|
|
128
164
|
* @returns {RefAndCodec}
|
|
165
|
+
* @private
|
|
129
166
|
*/
|
|
130
|
-
_refOf
|
|
167
|
+
private _refOf;
|
|
131
168
|
/**
|
|
132
169
|
* Snapshot the current identity for return to the client.
|
|
133
170
|
*
|
|
134
171
|
* @returns {Identity}
|
|
172
|
+
* @private
|
|
173
|
+
*/
|
|
174
|
+
private _identity;
|
|
175
|
+
/**
|
|
176
|
+
* Wire the on-demand `seed` handler — surfaces the recovery phrase only when asked.
|
|
177
|
+
* @private
|
|
135
178
|
*/
|
|
136
|
-
|
|
137
|
-
/** Wire the on-demand `seed` handler — surfaces the recovery phrase only when asked. */
|
|
138
|
-
_wireSeed(): void;
|
|
179
|
+
private _wireSeed;
|
|
139
180
|
}
|
|
140
181
|
/**
|
|
141
182
|
* Construct a `Server`, wait for it to be ready, and return it.
|
|
142
183
|
*
|
|
143
|
-
* @param {
|
|
144
|
-
* @param {
|
|
184
|
+
* @param {import('streamx').Duplex} ipc
|
|
185
|
+
* @param {Spec} spec
|
|
145
186
|
* @param {ServerOpts} opts
|
|
146
187
|
* @returns {Promise<Server>}
|
|
147
188
|
*/
|
|
148
|
-
export declare function serve(ipc:
|
|
189
|
+
export declare function serve(ipc: import('streamx').Duplex, spec: Spec, opts: ServerOpts): Promise<Server>;
|
package/src/rpc/index.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* RPC barrel — re-exports the `Server`/`Client` classes and their `serve()`/`connect()`
|
|
3
|
-
* helpers so consumers can spin up either side of the cero IPC bridge from a single
|
|
4
|
-
* import.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
export { Server, serve } from './server.js'
|
|
8
|
-
export { Client, connect } from './client.js'
|
package/types/rpc/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* RPC barrel — re-exports the `Server`/`Client` classes and their `serve()`/`connect()`
|
|
3
|
-
* helpers so consumers can spin up either side of the cero IPC bridge from a single
|
|
4
|
-
* import.
|
|
5
|
-
*/
|
|
6
|
-
export { Server, serve } from './server.js';
|
|
7
|
-
export { Client, connect } from './client.js';
|