@cero-base/core 0.8.9 → 1.0.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.
- package/package.json +25 -9
- package/src/blobs/codec.js +52 -0
- package/src/blobs/index.js +42 -164
- package/src/blobs/server.js +48 -0
- package/src/database/bootstrap.js +24 -12
- package/src/database/dispatch.js +91 -17
- package/src/database/index.js +112 -26
- package/src/identity/index.js +1 -1
- package/src/index.js +25 -2
- package/src/lib/constants.js +21 -1
- package/src/lib/schema.js +2 -0
- package/src/lib/spec/index.js +106 -120
- package/src/lib/spec/schema.json +74 -80
- package/src/lib/utils.js +33 -2
- package/src/network/index.js +1 -1
- package/src/pairing/index.js +57 -56
- package/src/pairing/invite.js +19 -18
- package/src/rpc/client.js +4 -42
- package/src/rpc/index.js +8 -4
- package/src/rpc/peer.js +46 -0
- package/src/rpc/server.js +4 -42
- package/src/storage/index.js +16 -6
- package/types/blobs/codec.d.ts +26 -0
- package/types/blobs/index.d.ts +25 -90
- package/types/blobs/server.d.ts +35 -0
- package/types/database/bootstrap.d.ts +1 -1
- package/types/database/dispatch.d.ts +26 -3
- package/types/database/index.d.ts +53 -17
- package/types/index.d.ts +50 -2
- package/types/lib/constants.d.ts +24 -1
- package/types/lib/schema.d.ts +1 -0
- package/types/lib/spec/index.d.ts +9 -12
- package/types/lib/utils.d.ts +12 -2
- package/types/pairing/index.d.ts +15 -4
- package/types/pairing/invite.d.ts +11 -11
- package/types/rpc/client.d.ts +4 -15
- package/types/rpc/peer.d.ts +18 -0
- package/types/rpc/server.d.ts +4 -15
- package/types/storage/index.d.ts +9 -4
package/types/pairing/index.d.ts
CHANGED
|
@@ -5,11 +5,13 @@
|
|
|
5
5
|
* @property {Uint8Array} [topic] Optional override topic; defaults to `identity.publicKey`.
|
|
6
6
|
* @property {any} [inviteEncoding] compact-encoding type for the invite payload `data`.
|
|
7
7
|
* @property {any} [joinerEncoding] compact-encoding type for the joiner-supplied `userData`.
|
|
8
|
+
* @property {(err: Error) => void} [onerror] Called when a background candidate fails to process.
|
|
8
9
|
*
|
|
9
10
|
* @typedef {object} CreateInviteOpts
|
|
10
11
|
* @property {string} [role] Role tag bound into the invite.
|
|
11
12
|
* @property {number} [expiresIn] TTL in ms; `0`/omitted = no expiry.
|
|
12
13
|
* @property {any} [data] Arbitrary payload (encoded via `inviteEncoding` when set).
|
|
14
|
+
* @property {boolean} [multiUse] Reusable until expiry/revoke; default `false` (consumed on first settle).
|
|
13
15
|
*
|
|
14
16
|
* @typedef {object} JoinOpts
|
|
15
17
|
* @property {any} [userData] Payload sent with the candidate request.
|
|
@@ -22,7 +24,7 @@
|
|
|
22
24
|
*
|
|
23
25
|
* @typedef {{ key: Uint8Array, encryptionKey: Uint8Array | null, additional: Uint8Array | null }} JoinResult
|
|
24
26
|
*
|
|
25
|
-
* @typedef {object}
|
|
27
|
+
* @typedef {object} RequestOpts
|
|
26
28
|
* @property {Pairing} pairing Owning Pairing instance.
|
|
27
29
|
* @property {any} req blind-pairing candidate request being answered.
|
|
28
30
|
* @property {Invite} invite Invite the candidate paired against.
|
|
@@ -54,12 +56,13 @@ export class Pairing extends ReadyResource {
|
|
|
54
56
|
*/
|
|
55
57
|
static isInvite(str: unknown): boolean;
|
|
56
58
|
/** @param {PairingOpts} [opts] */
|
|
57
|
-
constructor({ network, identity, topic, inviteEncoding, joinerEncoding }?: PairingOpts);
|
|
59
|
+
constructor({ network, identity, topic, inviteEncoding, joinerEncoding, onerror }?: PairingOpts);
|
|
58
60
|
network: import("../index.js").Network;
|
|
59
61
|
identity: import("../index.js").Identity;
|
|
60
62
|
topic: Uint8Array<ArrayBufferLike>;
|
|
61
63
|
inviteEncoding: any;
|
|
62
64
|
joinerEncoding: any;
|
|
65
|
+
_onerror: (err: Error) => void;
|
|
63
66
|
_blind: any;
|
|
64
67
|
_member: any;
|
|
65
68
|
_invites: Map<any, any>;
|
|
@@ -70,7 +73,7 @@ export class Pairing extends ReadyResource {
|
|
|
70
73
|
* @param {CreateInviteOpts} [opts]
|
|
71
74
|
* @returns {Promise<string>}
|
|
72
75
|
*/
|
|
73
|
-
createInvite({ role, expiresIn, data }?: CreateInviteOpts): Promise<string>;
|
|
76
|
+
createInvite({ role, expiresIn, data, multiUse }?: CreateInviteOpts): Promise<string>;
|
|
74
77
|
/**
|
|
75
78
|
* Forget a previously-minted invite. New candidates carrying it will be
|
|
76
79
|
* dropped silently.
|
|
@@ -129,6 +132,10 @@ export type PairingOpts = {
|
|
|
129
132
|
* compact-encoding type for the joiner-supplied `userData`.
|
|
130
133
|
*/
|
|
131
134
|
joinerEncoding?: any;
|
|
135
|
+
/**
|
|
136
|
+
* Called when a background candidate fails to process.
|
|
137
|
+
*/
|
|
138
|
+
onerror?: (err: Error) => void;
|
|
132
139
|
};
|
|
133
140
|
export type CreateInviteOpts = {
|
|
134
141
|
/**
|
|
@@ -143,6 +150,10 @@ export type CreateInviteOpts = {
|
|
|
143
150
|
* Arbitrary payload (encoded via `inviteEncoding` when set).
|
|
144
151
|
*/
|
|
145
152
|
data?: any;
|
|
153
|
+
/**
|
|
154
|
+
* Reusable until expiry/revoke; default `false` (consumed on first settle).
|
|
155
|
+
*/
|
|
156
|
+
multiUse?: boolean;
|
|
146
157
|
};
|
|
147
158
|
export type JoinOpts = {
|
|
148
159
|
/**
|
|
@@ -173,7 +184,7 @@ export type JoinResult = {
|
|
|
173
184
|
encryptionKey: Uint8Array | null;
|
|
174
185
|
additional: Uint8Array | null;
|
|
175
186
|
};
|
|
176
|
-
export type
|
|
187
|
+
export type RequestOpts = {
|
|
177
188
|
/**
|
|
178
189
|
* Owning Pairing instance.
|
|
179
190
|
*/
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @property {string} role Optional role tag baked into the signed body.
|
|
5
5
|
* @property {number} expires Absolute expiry timestamp; `0` means never.
|
|
6
6
|
* @property {Uint8Array | null} data Encoded payload (raw or via `encoding`).
|
|
7
|
-
* @property {Uint8Array}
|
|
7
|
+
* @property {Uint8Array} blind Raw blind-pairing invite handed to candidates.
|
|
8
8
|
* @property {Uint8Array} [sig] Ed25519 signature over the canonical body.
|
|
9
9
|
* @property {string | null} [_str] Cached z32 string form.
|
|
10
10
|
*
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* @property {string} role Optional role tag for the joiner.
|
|
15
15
|
* @property {number} expiresIn TTL in ms from now; `0` means never expires.
|
|
16
16
|
* @property {any} data Caller payload; encoded via `encoding` when provided.
|
|
17
|
-
* @property {Uint8Array}
|
|
17
|
+
* @property {Uint8Array} blind Raw blind-pairing invite to wrap.
|
|
18
18
|
* @property {any} [encoding] compact-encoding type used to encode `data`.
|
|
19
19
|
*
|
|
20
20
|
* @typedef {object} ParseInviteOpts
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
* authenticated by the joiner before any handshake happens.
|
|
27
27
|
*
|
|
28
28
|
* @property {any} [_rawData] Decoded payload kept alongside the encoded `data` for convenience.
|
|
29
|
-
* @property {
|
|
29
|
+
* @property {Uint8Array} _discoveryKey Cached discovery key of the wrapped blind invite.
|
|
30
30
|
*/
|
|
31
31
|
export class Invite {
|
|
32
32
|
/**
|
|
@@ -35,7 +35,7 @@ export class Invite {
|
|
|
35
35
|
* @param {CreateInviteOpts} opts
|
|
36
36
|
* @returns {Invite}
|
|
37
37
|
*/
|
|
38
|
-
static create({ secretKey, publicKey, role, expiresIn, data,
|
|
38
|
+
static create({ secretKey, publicKey, role, expiresIn, data, blind, encoding }: CreateInviteOpts): Invite;
|
|
39
39
|
/**
|
|
40
40
|
* Parse a z32 invite string, verify its signature and (optionally) decode
|
|
41
41
|
* its payload.
|
|
@@ -60,10 +60,10 @@ export class Invite {
|
|
|
60
60
|
role: string;
|
|
61
61
|
expires: number;
|
|
62
62
|
data: Uint8Array<ArrayBufferLike>;
|
|
63
|
-
|
|
63
|
+
blind: Uint8Array<ArrayBufferLike>;
|
|
64
64
|
sig: Uint8Array<ArrayBufferLike>;
|
|
65
65
|
_str: string;
|
|
66
|
-
|
|
66
|
+
_discoveryKey: any;
|
|
67
67
|
/**
|
|
68
68
|
* Whether the invite is past its TTL (always `false` when `expires === 0`).
|
|
69
69
|
*
|
|
@@ -71,11 +71,11 @@ export class Invite {
|
|
|
71
71
|
*/
|
|
72
72
|
get expired(): boolean;
|
|
73
73
|
/**
|
|
74
|
-
*
|
|
74
|
+
* Discovery key of the wrapped blind-pairing invite — the topic it targets.
|
|
75
75
|
*
|
|
76
|
-
* @returns {
|
|
76
|
+
* @returns {Uint8Array}
|
|
77
77
|
*/
|
|
78
|
-
get
|
|
78
|
+
get discoveryKey(): Uint8Array;
|
|
79
79
|
/**
|
|
80
80
|
* Verify the embedded signature against the encoded body.
|
|
81
81
|
*
|
|
@@ -109,7 +109,7 @@ export type InviteFields = {
|
|
|
109
109
|
/**
|
|
110
110
|
* Raw blind-pairing invite handed to candidates.
|
|
111
111
|
*/
|
|
112
|
-
|
|
112
|
+
blind: Uint8Array;
|
|
113
113
|
/**
|
|
114
114
|
* Ed25519 signature over the canonical body.
|
|
115
115
|
*/
|
|
@@ -143,7 +143,7 @@ export type CreateInviteOpts = {
|
|
|
143
143
|
/**
|
|
144
144
|
* Raw blind-pairing invite to wrap.
|
|
145
145
|
*/
|
|
146
|
-
|
|
146
|
+
blind: Uint8Array;
|
|
147
147
|
/**
|
|
148
148
|
* compact-encoding type used to encode `data`.
|
|
149
149
|
*/
|
package/types/rpc/client.d.ts
CHANGED
|
@@ -1,18 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Client-side RPC adapter
|
|
3
|
-
*
|
|
4
|
-
* to issue requests. Frames are paused until `_open` runs so handlers
|
|
5
|
-
* registered before `ready()` see a clean slate.
|
|
2
|
+
* Client-side RPC adapter — issues requests over the framed IPC stream.
|
|
3
|
+
* All wiring lives in {@link RPCPeer}; this is the client-named role.
|
|
6
4
|
*/
|
|
7
|
-
export class RPCClient extends
|
|
8
|
-
/**
|
|
9
|
-
* @param {any} ipc Duplex IPC stream (e.g. a socket or pipe).
|
|
10
|
-
* @param {import('./index.js').Spec} spec Spec object exposing `rpc` and `schema`.
|
|
11
|
-
*/
|
|
12
|
-
constructor(ipc: any, spec: import("./index.js").Spec);
|
|
13
|
-
ipc: any;
|
|
14
|
-
spec: import("./index.js").Spec;
|
|
15
|
-
framed: any;
|
|
16
|
-
rpc: any;
|
|
5
|
+
export class RPCClient extends RPCPeer {
|
|
17
6
|
}
|
|
18
|
-
import
|
|
7
|
+
import { RPCPeer } from './peer.js';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared RPC peer: wraps an IPC duplex in a length-framed stream and constructs
|
|
3
|
+
* the spec's hrpc binding. Frames are paused until `_open` runs so handlers
|
|
4
|
+
* registered before `ready()` see a clean slate. `RPCClient` and `RPCServer`
|
|
5
|
+
* are thin named subclasses — identical wiring, distinct roles.
|
|
6
|
+
*/
|
|
7
|
+
export class RPCPeer extends ReadyResource {
|
|
8
|
+
/**
|
|
9
|
+
* @param {any} ipc Duplex IPC stream (e.g. a socket or pipe).
|
|
10
|
+
* @param {import('./index.js').Spec} spec Spec object exposing `rpc` and `schema`.
|
|
11
|
+
*/
|
|
12
|
+
constructor(ipc: any, spec: import("./index.js").Spec);
|
|
13
|
+
ipc: any;
|
|
14
|
+
spec: import("./index.js").Spec;
|
|
15
|
+
framed: any;
|
|
16
|
+
rpc: any;
|
|
17
|
+
}
|
|
18
|
+
import ReadyResource from 'ready-resource';
|
package/types/rpc/server.d.ts
CHANGED
|
@@ -1,18 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Server-side RPC adapter
|
|
3
|
-
*
|
|
4
|
-
* envelope encoders. Reads are paused until `_open` runs so the
|
|
5
|
-
* application has a chance to register handlers before frames flow.
|
|
2
|
+
* Server-side RPC adapter — serves the spec's handlers over the framed IPC
|
|
3
|
+
* stream. All wiring lives in {@link RPCPeer}; this is the server-named role.
|
|
6
4
|
*/
|
|
7
|
-
export class RPCServer extends
|
|
8
|
-
/**
|
|
9
|
-
* @param {any} ipc Duplex IPC stream (e.g. a socket or pipe).
|
|
10
|
-
* @param {import('./index.js').Spec} spec Spec object exposing `rpc` and `schema`.
|
|
11
|
-
*/
|
|
12
|
-
constructor(ipc: any, spec: import("./index.js").Spec);
|
|
13
|
-
ipc: any;
|
|
14
|
-
spec: import("./index.js").Spec;
|
|
15
|
-
framed: any;
|
|
16
|
-
rpc: any;
|
|
5
|
+
export class RPCServer extends RPCPeer {
|
|
17
6
|
}
|
|
18
|
-
import
|
|
7
|
+
import { RPCPeer } from './peer.js';
|
package/types/storage/index.d.ts
CHANGED
|
@@ -66,13 +66,18 @@ export class Storage extends ReadyResource {
|
|
|
66
66
|
*/
|
|
67
67
|
put(name: string, row: Record<string, any>): Promise<SingleResult>;
|
|
68
68
|
/**
|
|
69
|
-
* Upsert by merging with the existing row, preserving `createdAt`.
|
|
69
|
+
* Upsert by merging with the existing row, preserving `createdAt`. Pass
|
|
70
|
+
* `{ upsert: false }` to update-only — a missing row is left untouched
|
|
71
|
+
* (returns `null`) instead of created. Mirrors `Database.set`.
|
|
70
72
|
*
|
|
71
73
|
* @param {string} name
|
|
72
74
|
* @param {Record<string, any>} row
|
|
73
|
-
* @
|
|
75
|
+
* @param {{ upsert?: boolean }} [opts]
|
|
76
|
+
* @returns {Promise<SingleResult | null>}
|
|
74
77
|
*/
|
|
75
|
-
set(name: string, row: Record<string, any
|
|
78
|
+
set(name: string, row: Record<string, any>, { upsert }?: {
|
|
79
|
+
upsert?: boolean;
|
|
80
|
+
}): Promise<SingleResult | null>;
|
|
76
81
|
/**
|
|
77
82
|
* Delete by id (collection) or wipe the whole single-row table.
|
|
78
83
|
*
|
|
@@ -108,7 +113,7 @@ export class Storage extends ReadyResource {
|
|
|
108
113
|
* @param {Record<string, any>} [query]
|
|
109
114
|
* @returns {import('streamx').Readable}
|
|
110
115
|
*/
|
|
111
|
-
watch(name: string, query?: Record<string, any>):
|
|
116
|
+
watch(name: string, query?: Record<string, any>): import("streamx").Readable;
|
|
112
117
|
_guard(): void;
|
|
113
118
|
/** @param {string} name @returns {Ref} */
|
|
114
119
|
_ref(name: string): Ref;
|