@cero-base/core 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 +9 -9
- package/src/blobs/index.js +2 -2
- package/src/database/changes.js +37 -59
- package/src/database/dispatch.js +31 -45
- package/src/database/index.js +395 -343
- package/src/database/rotation.js +201 -189
- package/src/identity/index.js +3 -3
- package/src/lib/utils.js +50 -18
- package/src/pairing/candidate.js +125 -0
- package/src/pairing/index.js +6 -223
- package/src/pairing/request.js +102 -0
- package/src/storage/index.js +11 -18
- package/types/blobs/codec.d.ts +8 -8
- package/types/blobs/index.d.ts +34 -33
- package/types/blobs/server.d.ts +8 -8
- package/types/database/changes.d.ts +5 -7
- package/types/database/dispatch.d.ts +30 -23
- package/types/database/encryption.d.ts +14 -10
- package/types/database/envelope.d.ts +2 -2
- package/types/database/index.d.ts +173 -181
- package/types/database/rotation.d.ts +53 -30
- package/types/identity/index.d.ts +81 -81
- package/types/index.d.ts +37 -51
- package/types/lib/constants.d.ts +34 -38
- package/types/lib/errors.d.ts +10 -10
- package/types/lib/schema.d.ts +47 -37
- package/types/lib/spec/index.d.ts +29 -55
- package/types/lib/utils.d.ts +27 -17
- package/types/network/discovery.d.ts +7 -7
- package/types/network/index.d.ts +50 -48
- package/types/pairing/candidate.d.ts +37 -0
- package/types/pairing/index.d.ts +87 -139
- package/types/pairing/invite.d.ts +88 -88
- package/types/pairing/request.d.ts +135 -0
- package/types/rpc/client.d.ts +2 -2
- package/types/rpc/index.d.ts +33 -33
- package/types/rpc/peer.d.ts +9 -7
- package/types/rpc/server.d.ts +2 -2
- package/types/storage/index.d.ts +70 -68
- package/src/database/bootstrap.js +0 -133
- package/src/database/hooks.js +0 -112
- package/src/database/membership.js +0 -67
- package/types/database/bootstrap.d.ts +0 -20
- package/types/database/hooks.d.ts +0 -8
- package/types/database/membership.d.ts +0 -7
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
export type KeyPair = {
|
|
2
|
+
publicKey: Uint8Array;
|
|
3
|
+
secretKey: Uint8Array;
|
|
4
|
+
id: string;
|
|
5
|
+
};
|
|
6
|
+
export type IdentityFields = {
|
|
7
|
+
publicKey: Uint8Array;
|
|
8
|
+
secretKey: Uint8Array;
|
|
9
|
+
encryptionKey: Uint8Array;
|
|
10
|
+
seed: Uint8Array;
|
|
11
|
+
};
|
|
1
12
|
/**
|
|
2
13
|
* @typedef {{ publicKey: Uint8Array, secretKey: Uint8Array, id: string }} KeyPair
|
|
3
14
|
* @typedef {{ publicKey: Uint8Array, secretKey: Uint8Array, encryptionKey: Uint8Array, seed: Uint8Array }} IdentityFields
|
|
@@ -7,7 +18,76 @@
|
|
|
7
18
|
* sign keypair, a symmetric encryption key and the canonical id/topic used
|
|
8
19
|
* by every other resource to identify this user.
|
|
9
20
|
*/
|
|
10
|
-
export class Identity {
|
|
21
|
+
export declare class Identity {
|
|
22
|
+
/**
|
|
23
|
+
* Canonical z32-encoded public key.
|
|
24
|
+
*
|
|
25
|
+
* @type {string}
|
|
26
|
+
*/
|
|
27
|
+
id: string;
|
|
28
|
+
/** @type {Uint8Array} */
|
|
29
|
+
publicKey: Uint8Array;
|
|
30
|
+
/** @type {Uint8Array} */
|
|
31
|
+
secretKey: Uint8Array;
|
|
32
|
+
/**
|
|
33
|
+
* Symmetric key for encrypting per-identity payloads.
|
|
34
|
+
*
|
|
35
|
+
* @type {Uint8Array}
|
|
36
|
+
*/
|
|
37
|
+
encryptionKey: Uint8Array;
|
|
38
|
+
/**
|
|
39
|
+
* Hash of the public key — used as the swarm topic.
|
|
40
|
+
*
|
|
41
|
+
* @type {Uint8Array}
|
|
42
|
+
*/
|
|
43
|
+
topic: Uint8Array;
|
|
44
|
+
/**
|
|
45
|
+
* Original 16- or 32-byte entropy.
|
|
46
|
+
*
|
|
47
|
+
* @type {Uint8Array}
|
|
48
|
+
*/
|
|
49
|
+
seed: Uint8Array;
|
|
50
|
+
/** @param {IdentityFields} keys */
|
|
51
|
+
constructor(keys: IdentityFields);
|
|
52
|
+
/**
|
|
53
|
+
* Redacted — secretKey/encryptionKey/seed must never reach JSON.stringify
|
|
54
|
+
* or a structured logger.
|
|
55
|
+
*
|
|
56
|
+
* @returns {{ id: string }}
|
|
57
|
+
*/
|
|
58
|
+
toJSON(): {
|
|
59
|
+
id: string;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Detached Ed25519 signature over `message`.
|
|
63
|
+
*
|
|
64
|
+
* @param {Uint8Array} message
|
|
65
|
+
* @returns {Uint8Array}
|
|
66
|
+
*/
|
|
67
|
+
sign(message: Uint8Array): Uint8Array;
|
|
68
|
+
/**
|
|
69
|
+
* Verify a signature against this identity's public key.
|
|
70
|
+
*
|
|
71
|
+
* @param {Uint8Array} message
|
|
72
|
+
* @param {Uint8Array} signature
|
|
73
|
+
* @returns {boolean}
|
|
74
|
+
*/
|
|
75
|
+
verify(message: Uint8Array, signature: Uint8Array): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Open a sealed box addressed to this identity (any device holding the
|
|
78
|
+
* seed-derived keypair can open it). Returns null when the box is not ours
|
|
79
|
+
* or is corrupt — callers treat that as "not addressed to me".
|
|
80
|
+
*
|
|
81
|
+
* @param {Uint8Array} sealed
|
|
82
|
+
* @returns {Uint8Array | null}
|
|
83
|
+
*/
|
|
84
|
+
unseal(sealed: Uint8Array): Uint8Array | null;
|
|
85
|
+
/**
|
|
86
|
+
* Render the underlying seed as a BIP-39 mnemonic phrase.
|
|
87
|
+
*
|
|
88
|
+
* @returns {string}
|
|
89
|
+
*/
|
|
90
|
+
toPhrase(): string;
|
|
11
91
|
/**
|
|
12
92
|
* Build an identity from 16- or 32-byte entropy.
|
|
13
93
|
*
|
|
@@ -105,84 +185,4 @@ export class Identity {
|
|
|
105
185
|
* @returns {Uint8Array}
|
|
106
186
|
*/
|
|
107
187
|
static randomSeed(words?: 12 | 24): Uint8Array;
|
|
108
|
-
/** @param {IdentityFields} keys */
|
|
109
|
-
constructor(keys: IdentityFields);
|
|
110
|
-
/**
|
|
111
|
-
* Canonical z32-encoded public key.
|
|
112
|
-
*
|
|
113
|
-
* @type {string}
|
|
114
|
-
*/
|
|
115
|
-
id: string;
|
|
116
|
-
/** @type {Uint8Array} */
|
|
117
|
-
publicKey: Uint8Array;
|
|
118
|
-
/** @type {Uint8Array} */
|
|
119
|
-
secretKey: Uint8Array;
|
|
120
|
-
/**
|
|
121
|
-
* Symmetric key for encrypting per-identity payloads.
|
|
122
|
-
*
|
|
123
|
-
* @type {Uint8Array}
|
|
124
|
-
*/
|
|
125
|
-
encryptionKey: Uint8Array;
|
|
126
|
-
/**
|
|
127
|
-
* Hash of the public key — used as the swarm topic.
|
|
128
|
-
*
|
|
129
|
-
* @type {Uint8Array}
|
|
130
|
-
*/
|
|
131
|
-
topic: Uint8Array;
|
|
132
|
-
/**
|
|
133
|
-
* Original 16- or 32-byte entropy.
|
|
134
|
-
*
|
|
135
|
-
* @type {Uint8Array}
|
|
136
|
-
*/
|
|
137
|
-
seed: Uint8Array;
|
|
138
|
-
/**
|
|
139
|
-
* Redacted — secretKey/encryptionKey/seed must never reach JSON.stringify
|
|
140
|
-
* or a structured logger.
|
|
141
|
-
*
|
|
142
|
-
* @returns {{ id: string }}
|
|
143
|
-
*/
|
|
144
|
-
toJSON(): {
|
|
145
|
-
id: string;
|
|
146
|
-
};
|
|
147
|
-
/**
|
|
148
|
-
* Detached Ed25519 signature over `message`.
|
|
149
|
-
*
|
|
150
|
-
* @param {Uint8Array} message
|
|
151
|
-
* @returns {Uint8Array}
|
|
152
|
-
*/
|
|
153
|
-
sign(message: Uint8Array): Uint8Array;
|
|
154
|
-
/**
|
|
155
|
-
* Verify a signature against this identity's public key.
|
|
156
|
-
*
|
|
157
|
-
* @param {Uint8Array} message
|
|
158
|
-
* @param {Uint8Array} signature
|
|
159
|
-
* @returns {boolean}
|
|
160
|
-
*/
|
|
161
|
-
verify(message: Uint8Array, signature: Uint8Array): boolean;
|
|
162
|
-
/**
|
|
163
|
-
* Open a sealed box addressed to this identity (any device holding the
|
|
164
|
-
* seed-derived keypair can open it). Returns null when the box is not ours
|
|
165
|
-
* or is corrupt — callers treat that as "not addressed to me".
|
|
166
|
-
*
|
|
167
|
-
* @param {Uint8Array} sealed
|
|
168
|
-
* @returns {Uint8Array | null}
|
|
169
|
-
*/
|
|
170
|
-
unseal(sealed: Uint8Array): Uint8Array | null;
|
|
171
|
-
/**
|
|
172
|
-
* Render the underlying seed as a BIP-39 mnemonic phrase.
|
|
173
|
-
*
|
|
174
|
-
* @returns {string}
|
|
175
|
-
*/
|
|
176
|
-
toPhrase(): string;
|
|
177
188
|
}
|
|
178
|
-
export type KeyPair = {
|
|
179
|
-
publicKey: Uint8Array;
|
|
180
|
-
secretKey: Uint8Array;
|
|
181
|
-
id: string;
|
|
182
|
-
};
|
|
183
|
-
export type IdentityFields = {
|
|
184
|
-
publicKey: Uint8Array;
|
|
185
|
-
secretKey: Uint8Array;
|
|
186
|
-
encryptionKey: Uint8Array;
|
|
187
|
-
seed: Uint8Array;
|
|
188
|
-
};
|
package/types/index.d.ts
CHANGED
|
@@ -1,59 +1,45 @@
|
|
|
1
|
-
export * from "./identity/index.js";
|
|
2
|
-
export * from "./network/index.js";
|
|
3
|
-
export * from "./database/index.js";
|
|
4
|
-
export * from "./blobs/index.js";
|
|
5
|
-
export * from "./rpc/index.js";
|
|
6
|
-
export * from "./pairing/index.js";
|
|
7
|
-
export * from "./lib/schema.js";
|
|
8
|
-
export * from "./lib/utils.js";
|
|
9
|
-
export * from "./lib/errors.js";
|
|
10
|
-
export { Storage } from "./storage/index.js";
|
|
11
|
-
export { Invite } from "./pairing/invite.js";
|
|
12
1
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
*
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
export type StorageSingleResult = import(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
*/
|
|
29
|
-
export type StorageListResult = import("./storage/index.js").ListResult;
|
|
2
|
+
* @cero-base/core — primitives for building p2p applications. This barrel
|
|
3
|
+
* re-exports the canonical surface: identity, storage, network, database,
|
|
4
|
+
* blobs, rpc, pairing, the schema DSL, the error class, and shared utils.
|
|
5
|
+
*
|
|
6
|
+
* Tree-shake-friendly: subpath imports (`@cero-base/core/identity`, etc.)
|
|
7
|
+
* are also available for consumers that need a smaller graph.
|
|
8
|
+
*/
|
|
9
|
+
export * from './identity/index.js';
|
|
10
|
+
export { Storage } from './storage/index.js';
|
|
11
|
+
export type StorageRef = import('./storage/index.js').Ref;
|
|
12
|
+
export type StorageSingleResult = import('./storage/index.js').SingleResult;
|
|
13
|
+
export type StorageListResult = import('./storage/index.js').ListResult;
|
|
14
|
+
export type StorageOpts = import('./storage/index.js').StorageOpts;
|
|
15
|
+
export type StoredRow = import('./storage/index.js').StoredRow;
|
|
16
|
+
export type GetByIdResult = import('./storage/index.js').GetByIdResult;
|
|
30
17
|
/**
|
|
31
18
|
* `Ref` / `SingleResult` / `ListResult` are JSDoc typedefs (types, not runtime exports), so they
|
|
32
19
|
* are re-exported as namespaced type aliases — `export { Ref as StorageRef }` fails at import
|
|
33
20
|
* because the module provides no runtime `Ref` export.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*/
|
|
41
|
-
export
|
|
42
|
-
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
|
|
47
|
-
export type
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
*/
|
|
51
|
-
export type MintInviteOpts = import("./pairing/invite.js").CreateInviteOpts;
|
|
52
|
-
/**
|
|
53
|
-
* `CreateInviteOpts` is a typedef (not a runtime export); re-export it as a type alias.
|
|
54
|
-
*/
|
|
55
|
-
export type InviteFields = import("./pairing/invite.js").InviteFields;
|
|
21
|
+
* @typedef {import('./storage/index.js').Ref} StorageRef
|
|
22
|
+
* @typedef {import('./storage/index.js').SingleResult} StorageSingleResult
|
|
23
|
+
* @typedef {import('./storage/index.js').ListResult} StorageListResult
|
|
24
|
+
* @typedef {import('./storage/index.js').StorageOpts} StorageOpts
|
|
25
|
+
* @typedef {import('./storage/index.js').StoredRow} StoredRow
|
|
26
|
+
* @typedef {import('./storage/index.js').GetByIdResult} GetByIdResult
|
|
27
|
+
*/
|
|
28
|
+
export * from './network/index.js';
|
|
29
|
+
export * from './database/index.js';
|
|
30
|
+
export * from './blobs/index.js';
|
|
31
|
+
export * from './rpc/index.js';
|
|
32
|
+
export * from './pairing/index.js';
|
|
33
|
+
export { Invite } from './pairing/invite.js';
|
|
34
|
+
export type MintInviteOpts = import('./pairing/invite.js').CreateInviteOpts;
|
|
35
|
+
export type InviteFields = import('./pairing/invite.js').InviteFields;
|
|
36
|
+
export type ParseInviteOpts = import('./pairing/invite.js').ParseInviteOpts;
|
|
56
37
|
/**
|
|
57
38
|
* `CreateInviteOpts` is a typedef (not a runtime export); re-export it as a type alias.
|
|
39
|
+
* @typedef {import('./pairing/invite.js').CreateInviteOpts} MintInviteOpts
|
|
40
|
+
* @typedef {import('./pairing/invite.js').InviteFields} InviteFields
|
|
41
|
+
* @typedef {import('./pairing/invite.js').ParseInviteOpts} ParseInviteOpts
|
|
58
42
|
*/
|
|
59
|
-
export
|
|
43
|
+
export * from './lib/schema.js';
|
|
44
|
+
export * from './lib/utils.js';
|
|
45
|
+
export * from './lib/errors.js';
|
package/types/lib/constants.d.ts
CHANGED
|
@@ -1,38 +1,34 @@
|
|
|
1
|
-
export const SINGLE
|
|
2
|
-
export const COLLECTION
|
|
3
|
-
export const HANDLE
|
|
4
|
-
export const ACTION
|
|
5
|
-
export const ACTIVE
|
|
6
|
-
export const PASSIVE
|
|
7
|
-
export const ROCKS
|
|
8
|
-
export const BEE
|
|
9
|
-
export const OWNER
|
|
10
|
-
export const ADMIN
|
|
11
|
-
export const MEMBER
|
|
12
|
-
export const READER
|
|
13
|
-
export const READ
|
|
14
|
-
export const WRITE
|
|
15
|
-
export const DELETE
|
|
16
|
-
export const INVITE
|
|
17
|
-
export const REMOVE
|
|
18
|
-
export const ASSIGN
|
|
19
|
-
export
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
export
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
export const NAMESPACE: "cero";
|
|
36
|
-
export const QUERY_RESERVED: Set<string>;
|
|
37
|
-
export const COUNTERS: "counters";
|
|
38
|
-
export const EPOCHS: "epochs";
|
|
1
|
+
export declare const SINGLE = "single";
|
|
2
|
+
export declare const COLLECTION = "collection";
|
|
3
|
+
export declare const HANDLE = "handle";
|
|
4
|
+
export declare const ACTION = "action";
|
|
5
|
+
export declare const ACTIVE = "active";
|
|
6
|
+
export declare const PASSIVE = "passive";
|
|
7
|
+
export declare const ROCKS = "rocks";
|
|
8
|
+
export declare const BEE = "bee";
|
|
9
|
+
export declare const OWNER = "owner";
|
|
10
|
+
export declare const ADMIN = "admin";
|
|
11
|
+
export declare const MEMBER = "member";
|
|
12
|
+
export declare const READER = "reader";
|
|
13
|
+
export declare const READ = "read";
|
|
14
|
+
export declare const WRITE = "write";
|
|
15
|
+
export declare const DELETE = "delete";
|
|
16
|
+
export declare const INVITE = "invite";
|
|
17
|
+
export declare const REMOVE = "remove";
|
|
18
|
+
export declare const ASSIGN = "assign";
|
|
19
|
+
export declare const ROLE_PERMS: {
|
|
20
|
+
owner: string[];
|
|
21
|
+
admin: string[];
|
|
22
|
+
member: string[];
|
|
23
|
+
reader: string[];
|
|
24
|
+
};
|
|
25
|
+
export declare const RANK: {
|
|
26
|
+
owner: number;
|
|
27
|
+
admin: number;
|
|
28
|
+
member: number;
|
|
29
|
+
reader: number;
|
|
30
|
+
};
|
|
31
|
+
export declare const NAMESPACE = "cero";
|
|
32
|
+
export declare const QUERY_RESERVED: Set<string>;
|
|
33
|
+
export declare const COUNTERS = "counters";
|
|
34
|
+
export declare const EPOCHS = "epochs";
|
package/types/lib/errors.d.ts
CHANGED
|
@@ -3,7 +3,16 @@
|
|
|
3
3
|
* is also prefixed to the message, so logs stay self-identifying. Static
|
|
4
4
|
* factories produce errors with the right code + a sensible message.
|
|
5
5
|
*/
|
|
6
|
-
export class CeroError extends Error {
|
|
6
|
+
export declare class CeroError extends Error {
|
|
7
|
+
isCeroError: boolean;
|
|
8
|
+
code: string;
|
|
9
|
+
/**
|
|
10
|
+
* @param {string} code Stable identifier (e.g. `REQUIRED`, `EXPIRED`).
|
|
11
|
+
* @param {string} [message] Human-readable detail; appended after the code.
|
|
12
|
+
* @param {Record<string, unknown> | null} [extras] Extra fields copied onto the instance.
|
|
13
|
+
*/
|
|
14
|
+
constructor(code: string, message?: string, extras?: Record<string, unknown> | null);
|
|
15
|
+
get name(): string;
|
|
7
16
|
/**
|
|
8
17
|
* Type-guard for `err instanceof CeroError` that survives realm boundaries.
|
|
9
18
|
*
|
|
@@ -127,13 +136,4 @@ export class CeroError extends Error {
|
|
|
127
136
|
* @param {number} epoch
|
|
128
137
|
*/
|
|
129
138
|
static UNKNOWN_EPOCH(epoch: number): CeroError;
|
|
130
|
-
/**
|
|
131
|
-
* @param {string} code Stable identifier (e.g. `REQUIRED`, `EXPIRED`).
|
|
132
|
-
* @param {string} [message] Human-readable detail; appended after the code.
|
|
133
|
-
* @param {Record<string, unknown> | null} [extras] Extra fields copied onto the instance.
|
|
134
|
-
*/
|
|
135
|
-
constructor(code: string, message?: string, extras?: Record<string, unknown> | null);
|
|
136
|
-
isCeroError: boolean;
|
|
137
|
-
code: string;
|
|
138
|
-
get name(): string;
|
|
139
139
|
}
|
package/types/lib/schema.d.ts
CHANGED
|
@@ -1,28 +1,47 @@
|
|
|
1
|
+
export type Prim = {
|
|
2
|
+
prim: string;
|
|
3
|
+
required?: boolean;
|
|
4
|
+
};
|
|
5
|
+
export type TypeDef = {
|
|
6
|
+
kind: 'single' | 'collection' | 'action';
|
|
7
|
+
fields: Record<string, Prim>;
|
|
8
|
+
};
|
|
9
|
+
export type SchemaDefs = {
|
|
10
|
+
[name: string]: TypeDef | Record<string, TypeDef>;
|
|
11
|
+
} & {
|
|
12
|
+
local?: Record<string, TypeDef>;
|
|
13
|
+
};
|
|
14
|
+
export type Schema = {
|
|
15
|
+
defs: SchemaDefs;
|
|
16
|
+
};
|
|
1
17
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* @param {SchemaDefs} defs
|
|
5
|
-
* @returns {Schema}
|
|
18
|
+
* Schema DSL. Primitive field types and kind-constructors used to describe
|
|
19
|
+
* a database's tables before the builder turns them into a wire spec.
|
|
6
20
|
*/
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
21
|
+
export declare const t: {
|
|
22
|
+
string: Prim;
|
|
23
|
+
uint: Prim;
|
|
24
|
+
int: Prim;
|
|
25
|
+
bool: Prim;
|
|
26
|
+
bytes: Prim;
|
|
27
|
+
json: Prim;
|
|
28
|
+
fixed32: Prim;
|
|
29
|
+
fixed64: Prim;
|
|
30
|
+
file: Prim;
|
|
31
|
+
/**
|
|
32
|
+
* Mark a field as required. Fields are optional by default.
|
|
33
|
+
*
|
|
34
|
+
* @param {Prim} marker
|
|
35
|
+
* @returns {Prim}
|
|
36
|
+
*/
|
|
37
|
+
required: (marker: Prim) => Prim;
|
|
19
38
|
/**
|
|
20
39
|
* Single-row table (one record, set/get by name).
|
|
21
40
|
*
|
|
22
41
|
* @param {Record<string, Prim>} fields
|
|
23
42
|
* @returns {TypeDef}
|
|
24
43
|
*/
|
|
25
|
-
|
|
44
|
+
single(fields: Record<string, Prim>): TypeDef;
|
|
26
45
|
/**
|
|
27
46
|
* Multi-row table keyed by `id`.
|
|
28
47
|
*
|
|
@@ -34,7 +53,7 @@ export namespace t {
|
|
|
34
53
|
* @param {{ indexes?: Record<string, string[]>, own?: boolean }} [opts]
|
|
35
54
|
* @returns {TypeDef}
|
|
36
55
|
*/
|
|
37
|
-
|
|
56
|
+
collection(fields: Record<string, Prim>, opts?: {
|
|
38
57
|
indexes?: Record<string, string[]>;
|
|
39
58
|
own?: boolean;
|
|
40
59
|
}): TypeDef;
|
|
@@ -44,7 +63,7 @@ export namespace t {
|
|
|
44
63
|
* @param {Record<string, Prim>} fields
|
|
45
64
|
* @returns {TypeDef}
|
|
46
65
|
*/
|
|
47
|
-
|
|
66
|
+
action(fields: Record<string, Prim>): TypeDef;
|
|
48
67
|
/**
|
|
49
68
|
* Add fields to a builtin type (members, devices, …). Merged into the
|
|
50
69
|
* builtin's base fields at build time; redeclaring a base field throws.
|
|
@@ -52,24 +71,15 @@ export namespace t {
|
|
|
52
71
|
* @param {Record<string, Prim>} fields
|
|
53
72
|
* @returns {{ kind: 'extend', fields: Record<string, Prim> }}
|
|
54
73
|
*/
|
|
55
|
-
|
|
56
|
-
kind:
|
|
74
|
+
extend(fields: Record<string, Prim>): {
|
|
75
|
+
kind: 'extend';
|
|
57
76
|
fields: Record<string, Prim>;
|
|
58
77
|
};
|
|
59
|
-
}
|
|
60
|
-
export type Prim = {
|
|
61
|
-
prim: string;
|
|
62
|
-
required?: boolean;
|
|
63
|
-
};
|
|
64
|
-
export type TypeDef = {
|
|
65
|
-
kind: "single" | "collection" | "action";
|
|
66
|
-
fields: Record<string, Prim>;
|
|
67
|
-
};
|
|
68
|
-
export type SchemaDefs = {
|
|
69
|
-
[name: string]: TypeDef | Record<string, TypeDef>;
|
|
70
|
-
} & {
|
|
71
|
-
local?: Record<string, TypeDef>;
|
|
72
|
-
};
|
|
73
|
-
export type Schema = {
|
|
74
|
-
defs: SchemaDefs;
|
|
75
78
|
};
|
|
79
|
+
/**
|
|
80
|
+
* Wrap a definitions object so the builder can recognise it as a schema.
|
|
81
|
+
*
|
|
82
|
+
* @param {SchemaDefs} defs
|
|
83
|
+
* @returns {Schema}
|
|
84
|
+
*/
|
|
85
|
+
export declare function schema(defs: SchemaDefs): Schema;
|
|
@@ -1,23 +1,37 @@
|
|
|
1
|
-
|
|
1
|
+
declare let version: number;
|
|
2
|
+
declare function setVersion(v: any): void;
|
|
3
|
+
declare function encode(name: any, value: any, v?: number): any;
|
|
4
|
+
declare function decode(name: any, buffer: any, v?: number): any;
|
|
5
|
+
declare function getEnum(name: any): void;
|
|
6
|
+
declare function getEncoding(name: any): {
|
|
2
7
|
preencode(state: any, m: any): void;
|
|
3
8
|
encode(state: any, m: any): void;
|
|
4
9
|
decode(state: any): {
|
|
5
|
-
prev: any;
|
|
6
|
-
next: any;
|
|
7
|
-
} | {
|
|
8
10
|
status: any;
|
|
9
11
|
reason: any;
|
|
10
12
|
key: any;
|
|
11
13
|
encryptionKey: any;
|
|
12
14
|
extra: any;
|
|
13
|
-
}
|
|
15
|
+
};
|
|
16
|
+
} | {
|
|
17
|
+
preencode(state: any, m: any): void;
|
|
18
|
+
encode(state: any, m: any): void;
|
|
19
|
+
decode(state: any): {
|
|
14
20
|
data: any;
|
|
15
|
-
}
|
|
21
|
+
};
|
|
22
|
+
} | {
|
|
23
|
+
preencode(state: any, m: any): void;
|
|
24
|
+
encode(state: any, m: any): void;
|
|
25
|
+
decode(state: any): {
|
|
16
26
|
id: any;
|
|
17
27
|
name: any;
|
|
18
28
|
role: any;
|
|
19
29
|
noAccept: boolean;
|
|
20
|
-
}
|
|
30
|
+
};
|
|
31
|
+
} | {
|
|
32
|
+
preencode(state: any, m: any): void;
|
|
33
|
+
encode(state: any, m: any): void;
|
|
34
|
+
decode(state: any): {
|
|
21
35
|
coreKey: any;
|
|
22
36
|
blockOffset: any;
|
|
23
37
|
blockLength: any;
|
|
@@ -25,37 +39,15 @@ export function resolveStruct(name: any, v?: number): {
|
|
|
25
39
|
byteLength: any;
|
|
26
40
|
type: any;
|
|
27
41
|
};
|
|
28
|
-
}
|
|
29
|
-
export function getStruct(name: any, v?: number): {
|
|
42
|
+
} | {
|
|
30
43
|
preencode(state: any, m: any): void;
|
|
31
44
|
encode(state: any, m: any): void;
|
|
32
45
|
decode(state: any): {
|
|
33
46
|
prev: any;
|
|
34
47
|
next: any;
|
|
35
|
-
} | {
|
|
36
|
-
status: any;
|
|
37
|
-
reason: any;
|
|
38
|
-
key: any;
|
|
39
|
-
encryptionKey: any;
|
|
40
|
-
extra: any;
|
|
41
|
-
} | {
|
|
42
|
-
data: any;
|
|
43
|
-
} | {
|
|
44
|
-
id: any;
|
|
45
|
-
name: any;
|
|
46
|
-
role: any;
|
|
47
|
-
noAccept: boolean;
|
|
48
|
-
} | {
|
|
49
|
-
coreKey: any;
|
|
50
|
-
blockOffset: any;
|
|
51
|
-
blockLength: any;
|
|
52
|
-
byteOffset: any;
|
|
53
|
-
byteLength: any;
|
|
54
|
-
type: any;
|
|
55
48
|
};
|
|
56
49
|
};
|
|
57
|
-
|
|
58
|
-
export function getEncoding(name: any): {
|
|
50
|
+
declare function getStruct(name: any, v?: number): {
|
|
59
51
|
preencode(state: any, m: any): void;
|
|
60
52
|
encode(state: any, m: any): void;
|
|
61
53
|
decode(state: any): {
|
|
@@ -64,42 +56,24 @@ export function getEncoding(name: any): {
|
|
|
64
56
|
key: any;
|
|
65
57
|
encryptionKey: any;
|
|
66
58
|
extra: any;
|
|
67
|
-
}
|
|
68
|
-
} | {
|
|
69
|
-
preencode(state: any, m: any): void;
|
|
70
|
-
encode(state: any, m: any): void;
|
|
71
|
-
decode(state: any): {
|
|
59
|
+
} | {
|
|
72
60
|
data: any;
|
|
73
|
-
}
|
|
74
|
-
} | {
|
|
75
|
-
preencode(state: any, m: any): void;
|
|
76
|
-
encode(state: any, m: any): void;
|
|
77
|
-
decode(state: any): {
|
|
61
|
+
} | {
|
|
78
62
|
id: any;
|
|
79
63
|
name: any;
|
|
80
64
|
role: any;
|
|
81
65
|
noAccept: boolean;
|
|
82
|
-
}
|
|
83
|
-
} | {
|
|
84
|
-
preencode(state: any, m: any): void;
|
|
85
|
-
encode(state: any, m: any): void;
|
|
86
|
-
decode(state: any): {
|
|
66
|
+
} | {
|
|
87
67
|
coreKey: any;
|
|
88
68
|
blockOffset: any;
|
|
89
69
|
blockLength: any;
|
|
90
70
|
byteOffset: any;
|
|
91
71
|
byteLength: any;
|
|
92
72
|
type: any;
|
|
93
|
-
}
|
|
94
|
-
} | {
|
|
95
|
-
preencode(state: any, m: any): void;
|
|
96
|
-
encode(state: any, m: any): void;
|
|
97
|
-
decode(state: any): {
|
|
73
|
+
} | {
|
|
98
74
|
prev: any;
|
|
99
75
|
next: any;
|
|
100
76
|
};
|
|
101
77
|
};
|
|
102
|
-
|
|
103
|
-
export
|
|
104
|
-
export function setVersion(v: any): void;
|
|
105
|
-
export let version: number;
|
|
78
|
+
declare const resolveStruct: typeof getStruct;
|
|
79
|
+
export { resolveStruct, getStruct, getEnum, getEncoding, encode, decode, setVersion, version };
|