@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/rpc/client.d.ts
CHANGED
|
@@ -1,108 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* @param {string} phrase
|
|
7
|
-
* @returns {Promise<Client>}
|
|
8
|
-
*/
|
|
9
|
-
export function restore(me: Client, phrase: string): Promise<Client>;
|
|
10
|
-
/**
|
|
11
|
-
* Construct a `Client`, wait for `init` to complete, and return it.
|
|
12
|
-
*
|
|
13
|
-
* @param {any} ipc
|
|
14
|
-
* @param {object} spec
|
|
15
|
-
* @returns {Promise<Client>}
|
|
16
|
-
*/
|
|
17
|
-
export function connect(ipc: any, spec: object): Promise<Client>;
|
|
18
|
-
/**
|
|
19
|
-
* Symmetric client entry. Mirrors the main `cero`, but `cero(ipc, spec)` connects
|
|
20
|
-
* to a server (via `connect`) instead of opening a local store. The same operator
|
|
21
|
-
* surface is attached, so `import { cero } from '@cero-base/cero/client'` works
|
|
22
|
-
* just like `import { cero } from '@cero-base/cero'`.
|
|
23
|
-
*
|
|
24
|
-
* Note: `before`/`after`/`peek` are intentionally not exposed here — they hook the
|
|
25
|
-
* local write path / probe a local store, which a client proxy has no notion of.
|
|
26
|
-
*
|
|
27
|
-
* @param {any} ipc Framed IPC duplex stream.
|
|
28
|
-
* @param {any} spec Built cero spec.
|
|
29
|
-
* @returns {Promise<Client>}
|
|
30
|
-
*/
|
|
31
|
-
export function cero(ipc: any, spec: any): Promise<Client>;
|
|
32
|
-
export namespace cero {
|
|
33
|
-
export { connect };
|
|
34
|
-
export { restore };
|
|
35
|
-
export { t };
|
|
36
|
-
export { put };
|
|
37
|
-
export { set };
|
|
38
|
-
export { get };
|
|
39
|
-
export { del };
|
|
40
|
-
export { count };
|
|
41
|
-
export { watch };
|
|
42
|
-
export { call };
|
|
43
|
-
export { open };
|
|
44
|
-
export { rotate };
|
|
45
|
-
export { bind };
|
|
46
|
-
export { define };
|
|
47
|
-
export { schema };
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* IPC-side RPC client for cero. Wraps an `hrpc` channel and exposes the
|
|
51
|
-
* same handle/ref/row API as a local cero instance, transparently
|
|
52
|
-
* routing every operation across the wire.
|
|
53
|
-
*/
|
|
54
|
-
export class Client extends RPCClient {
|
|
55
|
-
/**
|
|
56
|
-
* @param {any} ipc Framed IPC stream (must be writable).
|
|
57
|
-
* @param {Spec} spec Compiled cero spec (schema + rpc + handles).
|
|
58
|
-
*/
|
|
59
|
-
constructor(ipc: any, spec: Spec);
|
|
60
|
-
id: any;
|
|
61
|
-
deviceId: any;
|
|
62
|
-
store: this;
|
|
63
|
-
local: LocalRefs;
|
|
64
|
-
_fileBase: any;
|
|
65
|
-
_fileToken: any;
|
|
66
|
-
identity: {
|
|
67
|
-
id: any;
|
|
68
|
-
toPhrase: () => Promise<any>;
|
|
69
|
-
};
|
|
70
|
-
/**
|
|
71
|
-
* Create a new child handle of the given type.
|
|
72
|
-
*
|
|
73
|
-
* @param {string} type
|
|
74
|
-
* @param {Record<string, any>} [opts]
|
|
75
|
-
* @returns {Promise<Handle>}
|
|
76
|
-
*/
|
|
77
|
-
_create(type: string, opts?: Record<string, any>): Promise<Handle>;
|
|
78
|
-
/**
|
|
79
|
-
* Load an existing child handle by id.
|
|
80
|
-
*
|
|
81
|
-
* @param {string} type
|
|
82
|
-
* @param {string} id
|
|
83
|
-
* @returns {Promise<Handle>}
|
|
84
|
-
*/
|
|
85
|
-
_load(type: string, id: string): Promise<Handle>;
|
|
86
|
-
/**
|
|
87
|
-
* Join a child handle via invite.
|
|
88
|
-
*
|
|
89
|
-
* @param {string} invite
|
|
90
|
-
* @param {string} type
|
|
91
|
-
* @returns {Promise<Handle>}
|
|
92
|
-
*/
|
|
93
|
-
_join(invite: string, type: string): Promise<Handle>;
|
|
94
|
-
}
|
|
95
|
-
export type BaseRPCClient = import("@cero-base/core/rpc").RPCClient;
|
|
1
|
+
import { RPCClient } from '@cero-base/core/rpc';
|
|
2
|
+
import { put, set, get, del, count, watch, changes, call, open, rotate, bind, define } from '../lib/operators.js';
|
|
3
|
+
import { t, schema } from '../lib/spec.js';
|
|
4
|
+
export { put, set, get, del, count, watch, changes, call, open, rotate, bind, define, t, schema };
|
|
5
|
+
export type BaseRPCClient = import('@cero-base/core/rpc').RPCClient;
|
|
96
6
|
export type RefInfo = {
|
|
97
|
-
kind?:
|
|
7
|
+
kind?: 'single' | 'collection' | 'action' | 'handle';
|
|
98
8
|
schema?: string;
|
|
99
9
|
type?: string;
|
|
100
10
|
builtin?: boolean;
|
|
101
11
|
};
|
|
102
|
-
|
|
103
|
-
* Built cero spec (schema + rpc + per-handle child specs).
|
|
104
|
-
*/
|
|
105
|
-
export type Spec = import("@cero-base/core/rpc").Spec & {
|
|
12
|
+
export type Spec = import('@cero-base/core/rpc').Spec & {
|
|
106
13
|
meta: {
|
|
107
14
|
ns?: string;
|
|
108
15
|
refs: Record<string, RefInfo>;
|
|
@@ -133,20 +40,15 @@ export type HandleStub = {
|
|
|
133
40
|
type: string;
|
|
134
41
|
name: string | null;
|
|
135
42
|
};
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
import { rotate } from '../lib/operators.js';
|
|
146
|
-
import { bind } from '../lib/operators.js';
|
|
147
|
-
import { define } from '../lib/operators.js';
|
|
148
|
-
import { schema } from '../lib/spec.js';
|
|
149
|
-
import { RPCClient } from '@cero-base/core/rpc';
|
|
43
|
+
/**
|
|
44
|
+
* Re-initialize a `Client` from a recovery phrase. Closes the existing
|
|
45
|
+
* local state and reseeds identity from the phrase.
|
|
46
|
+
*
|
|
47
|
+
* @param {Client} me
|
|
48
|
+
* @param {string} phrase
|
|
49
|
+
* @returns {Promise<Client>}
|
|
50
|
+
*/
|
|
51
|
+
export declare function restore(me: Client, phrase: string): Promise<Client>;
|
|
150
52
|
/**
|
|
151
53
|
* Per-device `local`-namespace surface on a Client. Exposes each app-defined
|
|
152
54
|
* local ref (e.g. `client.local.settings`) and routes ops over RPC with
|
|
@@ -154,23 +56,76 @@ import { RPCClient } from '@cero-base/core/rpc';
|
|
|
154
56
|
* replicate. Built-in local refs (identity master/keypair) are not exposed.
|
|
155
57
|
*/
|
|
156
58
|
declare class LocalRefs {
|
|
157
|
-
/** @param {Client} client */
|
|
158
|
-
constructor(client: Client);
|
|
159
59
|
parent: Client;
|
|
160
60
|
spec: import("@cero-base/core").Spec;
|
|
161
61
|
store: this;
|
|
162
62
|
_local: boolean;
|
|
63
|
+
/** @param {Client} client */
|
|
64
|
+
constructor(client: Client);
|
|
163
65
|
/** Underlying RPC channel borrowed from the parent. */
|
|
164
66
|
get rpc(): any;
|
|
165
67
|
/** Root handle id (local ops are resolved against the root's local store). */
|
|
166
68
|
get id(): any;
|
|
167
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* IPC-side RPC client for cero. Wraps an `hrpc` channel and exposes the
|
|
72
|
+
* same handle/ref/row API as a local cero instance, transparently
|
|
73
|
+
* routing every operation across the wire.
|
|
74
|
+
*/
|
|
75
|
+
export declare class Client extends RPCClient {
|
|
76
|
+
id: any;
|
|
77
|
+
deviceId: any;
|
|
78
|
+
store: this;
|
|
79
|
+
local: LocalRefs;
|
|
80
|
+
_fileBase: any;
|
|
81
|
+
_fileToken: any;
|
|
82
|
+
identity: {
|
|
83
|
+
id: any;
|
|
84
|
+
toPhrase: () => Promise<any>;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* @param {any} ipc Framed IPC stream (must be writable).
|
|
88
|
+
* @param {Spec} spec Compiled cero spec (schema + rpc + handles).
|
|
89
|
+
*/
|
|
90
|
+
constructor(ipc: any, spec: Spec);
|
|
91
|
+
_open(): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Create a new child handle of the given type.
|
|
94
|
+
*
|
|
95
|
+
* @param {string} type
|
|
96
|
+
* @param {Record<string, any>} [opts]
|
|
97
|
+
* @returns {Promise<Handle>}
|
|
98
|
+
*/
|
|
99
|
+
_create(type: string, opts?: Record<string, any>): Promise<Handle>;
|
|
100
|
+
/**
|
|
101
|
+
* Load an existing child handle by id.
|
|
102
|
+
*
|
|
103
|
+
* @param {string} type
|
|
104
|
+
* @param {string} id
|
|
105
|
+
* @returns {Promise<Handle>}
|
|
106
|
+
*/
|
|
107
|
+
_load(type: string, id: string): Promise<Handle>;
|
|
108
|
+
/**
|
|
109
|
+
* Join a child handle via invite.
|
|
110
|
+
*
|
|
111
|
+
* @param {string} invite
|
|
112
|
+
* @param {string} type
|
|
113
|
+
* @returns {Promise<Handle>}
|
|
114
|
+
*/
|
|
115
|
+
_join(invite: string, type: string): Promise<Handle>;
|
|
116
|
+
}
|
|
168
117
|
/**
|
|
169
118
|
* Client-side proxy for a remote handle. Exposes the same row-ops surface
|
|
170
119
|
* as `Client` but scoped to a single child handle id, and routes every
|
|
171
120
|
* call through the parent's RPC channel.
|
|
172
121
|
*/
|
|
173
122
|
declare class Handle {
|
|
123
|
+
parent: Client;
|
|
124
|
+
id: string;
|
|
125
|
+
type: string;
|
|
126
|
+
name: string;
|
|
127
|
+
spec: Spec;
|
|
128
|
+
store: this;
|
|
174
129
|
/**
|
|
175
130
|
* @param {Client} parent
|
|
176
131
|
* @param {string} id
|
|
@@ -178,12 +133,6 @@ declare class Handle {
|
|
|
178
133
|
* @param {string|null} name
|
|
179
134
|
*/
|
|
180
135
|
constructor(parent: Client, id: string, type: string, name: string | null);
|
|
181
|
-
parent: Client;
|
|
182
|
-
id: string;
|
|
183
|
-
type: string;
|
|
184
|
-
name: string;
|
|
185
|
-
spec: Spec;
|
|
186
|
-
store: this;
|
|
187
136
|
/** Underlying RPC channel borrowed from the parent. */
|
|
188
137
|
get rpc(): any;
|
|
189
138
|
/** Tear down the remote handle without leaving the room. */
|
|
@@ -191,4 +140,43 @@ declare class Handle {
|
|
|
191
140
|
/** Tear down the remote handle and drop membership. */
|
|
192
141
|
leave(): any;
|
|
193
142
|
}
|
|
194
|
-
|
|
143
|
+
/**
|
|
144
|
+
* Construct a `Client`, wait for `init` to complete, and return it.
|
|
145
|
+
*
|
|
146
|
+
* @param {any} ipc
|
|
147
|
+
* @param {object} spec
|
|
148
|
+
* @returns {Promise<Client>}
|
|
149
|
+
*/
|
|
150
|
+
export declare function connect(ipc: any, spec: object): Promise<Client>;
|
|
151
|
+
/**
|
|
152
|
+
* Symmetric client entry. Mirrors the main `cero`, but `cero(ipc, spec)` connects
|
|
153
|
+
* to a server (via `connect`) instead of opening a local store. The same operator
|
|
154
|
+
* surface is attached, so `import { cero } from '@cero-base/cero/client'` works
|
|
155
|
+
* just like `import { cero } from '@cero-base/cero'`.
|
|
156
|
+
*
|
|
157
|
+
* Note: `before`/`after`/`peek` are intentionally not exposed here — they hook the
|
|
158
|
+
* local write path / probe a local store, which a client proxy has no notion of.
|
|
159
|
+
*
|
|
160
|
+
* @param {any} ipc Framed IPC duplex stream.
|
|
161
|
+
* @param {any} spec Built cero spec.
|
|
162
|
+
* @returns {Promise<Client>}
|
|
163
|
+
*/
|
|
164
|
+
export declare function cero(ipc: any, spec: any): Promise<Client>;
|
|
165
|
+
export declare namespace cero {
|
|
166
|
+
export { connect };
|
|
167
|
+
export { restore };
|
|
168
|
+
export { t };
|
|
169
|
+
export { put };
|
|
170
|
+
export { set };
|
|
171
|
+
export { get };
|
|
172
|
+
export { del };
|
|
173
|
+
export { count };
|
|
174
|
+
export { watch };
|
|
175
|
+
export { changes };
|
|
176
|
+
export { call };
|
|
177
|
+
export { open };
|
|
178
|
+
export { rotate };
|
|
179
|
+
export { bind };
|
|
180
|
+
export { define };
|
|
181
|
+
export { schema };
|
|
182
|
+
}
|
package/types/rpc/index.d.ts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* RPC barrel — re-exports the `Server`/`Client` classes and their
|
|
3
|
+
* `serve()`/`connect()` helpers so consumers can spin up either side
|
|
4
|
+
* of the cero IPC bridge from a single import.
|
|
5
|
+
*/
|
|
6
|
+
export { Server, serve } from './server.js';
|
|
7
|
+
export { Client, connect } from './client.js';
|
package/types/rpc/server.d.ts
CHANGED
|
@@ -1,17 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { RPCServer } from '@cero-base/core/rpc';
|
|
2
|
+
export type BaseRPCServer = import('@cero-base/core/rpc').RPCServer;
|
|
3
|
+
export type ServerOpts = {
|
|
4
|
+
/**
|
|
5
|
+
* Directory passed to `cero()` for the local store.
|
|
6
|
+
*/
|
|
7
|
+
storage: string;
|
|
8
|
+
/**
|
|
9
|
+
* Optional display name forwarded to `cero()`.
|
|
10
|
+
*/
|
|
11
|
+
name?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Custom DHT bootstrap.
|
|
14
|
+
*/
|
|
15
|
+
bootstrap?: Array<{
|
|
16
|
+
host: string;
|
|
17
|
+
port: number;
|
|
18
|
+
}>;
|
|
19
|
+
isMobile?: boolean;
|
|
20
|
+
onerror?: (err: Error) => void;
|
|
21
|
+
};
|
|
22
|
+
export type Identity = {
|
|
23
|
+
/**
|
|
24
|
+
* Long-lived cero identity id.
|
|
25
|
+
*/
|
|
26
|
+
id: string;
|
|
27
|
+
/**
|
|
28
|
+
* Per-device id (empty when no `local` spec).
|
|
29
|
+
*/
|
|
30
|
+
deviceId: string;
|
|
31
|
+
};
|
|
32
|
+
export type RefAndCodec = {
|
|
33
|
+
ref: any;
|
|
34
|
+
codec: any;
|
|
35
|
+
};
|
|
36
|
+
export type GetResult = {
|
|
37
|
+
data: any;
|
|
38
|
+
total?: number;
|
|
39
|
+
size?: number;
|
|
40
|
+
};
|
|
9
41
|
/**
|
|
10
42
|
* @typedef {import('@cero-base/core/rpc').RPCServer} BaseRPCServer
|
|
11
43
|
*
|
|
12
44
|
* @typedef {object} ServerOpts
|
|
13
45
|
* @property {string} storage Directory passed to `cero()` for the local store.
|
|
14
|
-
* @property {object} spec Compiled cero spec (schema + rpc + handles).
|
|
15
46
|
* @property {string} [name] Optional display name forwarded to `cero()`.
|
|
16
47
|
* @property {Array<{ host: string, port: number }>} [bootstrap] Custom DHT bootstrap.
|
|
17
48
|
* @property {boolean} [isMobile]
|
|
@@ -31,21 +62,10 @@ export function serve(ipc: any, opts: ServerOpts): Promise<Server>;
|
|
|
31
62
|
* `init` call, then exposes data ops, pairing, and handle lifecycle
|
|
32
63
|
* over the wire using the spec-bound codec.
|
|
33
64
|
*/
|
|
34
|
-
export class Server extends RPCServer {
|
|
35
|
-
/**
|
|
36
|
-
* @param {any} ipc Framed IPC stream (must be writable).
|
|
37
|
-
* @param {Partial<ServerOpts>} [opts]
|
|
38
|
-
*/
|
|
39
|
-
constructor(ipc: any, { storage, spec, ...opts }?: Partial<ServerOpts>);
|
|
65
|
+
export declare class Server extends RPCServer {
|
|
40
66
|
storage: string;
|
|
41
67
|
opts: {
|
|
42
|
-
/**
|
|
43
|
-
* Optional display name forwarded to `cero()`.
|
|
44
|
-
*/
|
|
45
68
|
name?: string;
|
|
46
|
-
/**
|
|
47
|
-
* Custom DHT bootstrap.
|
|
48
|
-
*/
|
|
49
69
|
bootstrap?: Array<{
|
|
50
70
|
host: string;
|
|
51
71
|
port: number;
|
|
@@ -53,10 +73,16 @@ export class Server extends RPCServer {
|
|
|
53
73
|
isMobile?: boolean;
|
|
54
74
|
onerror?: (err: Error) => void;
|
|
55
75
|
};
|
|
56
|
-
me:
|
|
76
|
+
me: import("../handle/index.js").CeroHandle;
|
|
57
77
|
handles: Map<any, any>;
|
|
58
78
|
/** @type {Map<string, Set<object>>} handle id → its open watch streams */
|
|
59
79
|
_watchStreams: Map<string, Set<object>>;
|
|
80
|
+
/**
|
|
81
|
+
* @param {any} ipc Framed IPC stream (must be writable).
|
|
82
|
+
* @param {object} spec
|
|
83
|
+
* @param {Partial<ServerOpts>} [opts]
|
|
84
|
+
*/
|
|
85
|
+
constructor(ipc: any, spec: object, { storage, ...opts }?: Partial<ServerOpts>);
|
|
60
86
|
/** End every watch stream bound to a handle (e.g. when it closes or leaves). */
|
|
61
87
|
_endWatches(handle: any): void;
|
|
62
88
|
/**
|
|
@@ -71,6 +97,7 @@ export class Server extends RPCServer {
|
|
|
71
97
|
* @returns {any}
|
|
72
98
|
*/
|
|
73
99
|
get identity(): any;
|
|
100
|
+
_close(): Promise<void>;
|
|
74
101
|
/** Wire the `init` handler that lazily constructs the root cero handle. */
|
|
75
102
|
_wireInit(): void;
|
|
76
103
|
/** Wire the `restore` handler that rebuilds the local store from a phrase. */
|
|
@@ -109,50 +136,12 @@ export class Server extends RPCServer {
|
|
|
109
136
|
/** Wire the on-demand `seed` handler — surfaces the recovery phrase only when asked. */
|
|
110
137
|
_wireSeed(): void;
|
|
111
138
|
}
|
|
112
|
-
export type BaseRPCServer = import("@cero-base/core/rpc").RPCServer;
|
|
113
|
-
export type ServerOpts = {
|
|
114
|
-
/**
|
|
115
|
-
* Directory passed to `cero()` for the local store.
|
|
116
|
-
*/
|
|
117
|
-
storage: string;
|
|
118
|
-
/**
|
|
119
|
-
* Compiled cero spec (schema + rpc + handles).
|
|
120
|
-
*/
|
|
121
|
-
spec: object;
|
|
122
|
-
/**
|
|
123
|
-
* Optional display name forwarded to `cero()`.
|
|
124
|
-
*/
|
|
125
|
-
name?: string;
|
|
126
|
-
/**
|
|
127
|
-
* Custom DHT bootstrap.
|
|
128
|
-
*/
|
|
129
|
-
bootstrap?: Array<{
|
|
130
|
-
host: string;
|
|
131
|
-
port: number;
|
|
132
|
-
}>;
|
|
133
|
-
isMobile?: boolean;
|
|
134
|
-
onerror?: (err: Error) => void;
|
|
135
|
-
};
|
|
136
|
-
export type Identity = {
|
|
137
|
-
/**
|
|
138
|
-
* Long-lived cero identity id.
|
|
139
|
-
*/
|
|
140
|
-
id: string;
|
|
141
|
-
/**
|
|
142
|
-
* Per-device id (empty when no `local` spec).
|
|
143
|
-
*/
|
|
144
|
-
deviceId: string;
|
|
145
|
-
};
|
|
146
|
-
export type RefAndCodec = {
|
|
147
|
-
ref: any;
|
|
148
|
-
codec: any;
|
|
149
|
-
};
|
|
150
139
|
/**
|
|
151
|
-
*
|
|
140
|
+
* Construct a `Server`, wait for it to be ready, and return it.
|
|
141
|
+
*
|
|
142
|
+
* @param {any} ipc
|
|
143
|
+
* @param {object} spec
|
|
144
|
+
* @param {ServerOpts} opts
|
|
145
|
+
* @returns {Promise<Server>}
|
|
152
146
|
*/
|
|
153
|
-
export
|
|
154
|
-
data: any;
|
|
155
|
-
total?: number;
|
|
156
|
-
size?: number;
|
|
157
|
-
};
|
|
158
|
-
import { RPCServer } from '@cero-base/core/rpc';
|
|
147
|
+
export declare function serve(ipc: any, spec: object, opts: ServerOpts): Promise<Server>;
|
package/src/lib/utils.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { CeroError } from '@cero-base/core/errors'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @typedef {'collection' | 'single' | 'action' | 'handle'} RefKind
|
|
5
|
-
* @typedef {{ kind?: string, schema?: string }} RefInfo
|
|
6
|
-
* Shape of the entries in `meta.refs` — describes a single ref name.
|
|
7
|
-
* `kind` is one of {@link RefKind}, kept as `string` since it originates
|
|
8
|
-
* from a generated spec.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Typed pointer to a single ref (table or handle slot) on a `Handle` or
|
|
13
|
-
* `Local`. Operators (`put`/`get`/`open`/...) take a `Ref` as their first
|
|
14
|
-
* argument and dispatch through the owning handle's store.
|
|
15
|
-
*/
|
|
16
|
-
export class Ref {
|
|
17
|
-
/**
|
|
18
|
-
* @param {any} handle Owner — a `Handle` (or `Local`) the ref lives on.
|
|
19
|
-
* @param {string} name Ref name as declared in the schema.
|
|
20
|
-
* @param {string} kind Ref kind: `'collection'`, `'single'`, `'action'`, or `'handle'`.
|
|
21
|
-
* @param {string | null} [schema] Fully-qualified schema id, if any.
|
|
22
|
-
*/
|
|
23
|
-
constructor(handle, name, kind, schema = null) {
|
|
24
|
-
this.handle = handle
|
|
25
|
-
this.name = name
|
|
26
|
-
this.kind = kind
|
|
27
|
-
this.schema = schema
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Attach a `Ref` property to `target` for every entry in `refs`. Used by
|
|
33
|
-
* `Handle` and `Local` during `_open()` so callers can write
|
|
34
|
-
* `handle.someRef` instead of looking refs up by name.
|
|
35
|
-
*
|
|
36
|
-
* @param {any} target
|
|
37
|
-
* @param {Record<string, RefInfo>} refs
|
|
38
|
-
*/
|
|
39
|
-
export function attachRefs(target, refs) {
|
|
40
|
-
for (const [name, info] of Object.entries(refs || {})) {
|
|
41
|
-
// Fail loud rather than silently overwrite a method/property (close, on,
|
|
42
|
-
// store, …) when a schema declares a ref named like a reserved member.
|
|
43
|
-
if (name in target) {
|
|
44
|
-
throw CeroError.INVALID(
|
|
45
|
-
`schema ref '${name}' collides with a reserved ${target.constructor?.name || 'handle'} member — rename it`
|
|
46
|
-
)
|
|
47
|
-
}
|
|
48
|
-
target[name] = new Ref(target, name, info.kind, info.schema)
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Run `cb` when `signal` aborts — or immediately if it already has. No-op
|
|
54
|
-
* without a signal. The listener removes itself on fire. Returns a disposer that
|
|
55
|
-
* detaches the listener early, so a manual unsubscribe doesn't leave it lingering
|
|
56
|
-
* on a long-lived signal.
|
|
57
|
-
*
|
|
58
|
-
* @param {AbortSignal | undefined} signal
|
|
59
|
-
* @param {() => void} cb
|
|
60
|
-
* @returns {(() => void) | undefined}
|
|
61
|
-
*/
|
|
62
|
-
export function onAbort(signal, cb) {
|
|
63
|
-
if (!signal) return
|
|
64
|
-
if (signal.aborted) return void cb()
|
|
65
|
-
signal.addEventListener('abort', cb, { once: true })
|
|
66
|
-
return () => signal.removeEventListener('abort', cb)
|
|
67
|
-
}
|
package/types/lib/utils.d.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Attach a `Ref` property to `target` for every entry in `refs`. Used by
|
|
3
|
-
* `Handle` and `Local` during `_open()` so callers can write
|
|
4
|
-
* `handle.someRef` instead of looking refs up by name.
|
|
5
|
-
*
|
|
6
|
-
* @param {any} target
|
|
7
|
-
* @param {Record<string, RefInfo>} refs
|
|
8
|
-
*/
|
|
9
|
-
export function attachRefs(target: any, refs: Record<string, RefInfo>): void;
|
|
10
|
-
/**
|
|
11
|
-
* Run `cb` when `signal` aborts — or immediately if it already has. No-op
|
|
12
|
-
* without a signal. The listener removes itself on fire. Returns a disposer that
|
|
13
|
-
* detaches the listener early, so a manual unsubscribe doesn't leave it lingering
|
|
14
|
-
* on a long-lived signal.
|
|
15
|
-
*
|
|
16
|
-
* @param {AbortSignal | undefined} signal
|
|
17
|
-
* @param {() => void} cb
|
|
18
|
-
* @returns {(() => void) | undefined}
|
|
19
|
-
*/
|
|
20
|
-
export function onAbort(signal: AbortSignal | undefined, cb: () => void): (() => void) | undefined;
|
|
21
|
-
/**
|
|
22
|
-
* @typedef {'collection' | 'single' | 'action' | 'handle'} RefKind
|
|
23
|
-
* @typedef {{ kind?: string, schema?: string }} RefInfo
|
|
24
|
-
* Shape of the entries in `meta.refs` — describes a single ref name.
|
|
25
|
-
* `kind` is one of {@link RefKind}, kept as `string` since it originates
|
|
26
|
-
* from a generated spec.
|
|
27
|
-
*/
|
|
28
|
-
/**
|
|
29
|
-
* Typed pointer to a single ref (table or handle slot) on a `Handle` or
|
|
30
|
-
* `Local`. Operators (`put`/`get`/`open`/...) take a `Ref` as their first
|
|
31
|
-
* argument and dispatch through the owning handle's store.
|
|
32
|
-
*/
|
|
33
|
-
export class Ref {
|
|
34
|
-
/**
|
|
35
|
-
* @param {any} handle Owner — a `Handle` (or `Local`) the ref lives on.
|
|
36
|
-
* @param {string} name Ref name as declared in the schema.
|
|
37
|
-
* @param {string} kind Ref kind: `'collection'`, `'single'`, `'action'`, or `'handle'`.
|
|
38
|
-
* @param {string | null} [schema] Fully-qualified schema id, if any.
|
|
39
|
-
*/
|
|
40
|
-
constructor(handle: any, name: string, kind: string, schema?: string | null);
|
|
41
|
-
handle: any;
|
|
42
|
-
name: string;
|
|
43
|
-
kind: string;
|
|
44
|
-
schema: string;
|
|
45
|
-
}
|
|
46
|
-
export type RefKind = "collection" | "single" | "action" | "handle";
|
|
47
|
-
/**
|
|
48
|
-
* Shape of the entries in `meta.refs` — describes a single ref name.
|
|
49
|
-
* `kind` is one of {@link RefKind}, kept as `string` since it originates
|
|
50
|
-
* from a generated spec.
|
|
51
|
-
*/
|
|
52
|
-
export type RefInfo = {
|
|
53
|
-
kind?: string;
|
|
54
|
-
schema?: string;
|
|
55
|
-
};
|