@cero-base/core 1.18.2 → 2.0.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 +14 -11
- package/src/blobs/index.js +17 -17
- package/src/blobs/server.js +0 -2
- package/src/database/changes.js +34 -60
- package/src/database/dispatch.js +156 -245
- package/src/database/encryption.js +22 -52
- package/src/database/envelope.js +1 -3
- package/src/database/index.js +514 -513
- package/src/database/rotation.js +191 -193
- package/src/identity/index.js +8 -12
- package/src/index.js +5 -9
- package/src/lib/constants.js +3 -12
- package/src/lib/errors.js +6 -10
- package/src/lib/schema.js +2 -5
- package/src/lib/utils.js +55 -38
- package/src/network/index.js +138 -166
- package/src/pairing/candidate.js +123 -0
- package/src/pairing/index.js +36 -267
- package/src/pairing/invite.js +3 -4
- package/src/pairing/request.js +96 -0
- package/src/rpc/index.js +4 -14
- package/src/rpc/peer.js +3 -7
- package/src/storage/index.js +36 -49
- package/types/blobs/codec.d.ts +8 -8
- package/types/blobs/index.d.ts +38 -37
- package/types/blobs/server.d.ts +8 -10
- package/types/database/changes.d.ts +3 -8
- package/types/database/dispatch.d.ts +28 -25
- package/types/database/encryption.d.ts +22 -30
- package/types/database/envelope.d.ts +2 -2
- package/types/database/index.d.ts +196 -221
- package/types/database/rotation.d.ts +47 -30
- package/types/identity/index.d.ts +83 -87
- package/types/index.d.ts +42 -55
- package/types/lib/constants.d.ts +34 -38
- package/types/lib/errors.d.ts +16 -20
- package/types/lib/schema.d.ts +49 -42
- package/types/lib/spec/index.d.ts +29 -55
- package/types/lib/utils.d.ts +26 -20
- package/types/network/discovery.d.ts +7 -7
- package/types/network/index.d.ts +64 -72
- package/types/pairing/candidate.d.ts +36 -0
- package/types/pairing/index.d.ts +91 -151
- package/types/pairing/invite.d.ts +91 -91
- package/types/pairing/request.d.ts +133 -0
- package/types/rpc/client.d.ts +2 -2
- package/types/rpc/index.d.ts +30 -33
- package/types/rpc/peer.d.ts +11 -11
- package/types/rpc/server.d.ts +2 -2
- package/types/storage/index.d.ts +70 -71
- 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,13 +1,90 @@
|
|
|
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
|
|
4
15
|
*/
|
|
5
16
|
/**
|
|
6
|
-
* Long-lived user identity derived from a BIP-39 seed phrase.
|
|
7
|
-
* sign keypair, a symmetric encryption key and the canonical id/topic used
|
|
8
|
-
* by every other resource to identify this user.
|
|
17
|
+
* Long-lived user identity derived from a BIP-39 seed phrase.
|
|
9
18
|
*/
|
|
10
|
-
export class Identity {
|
|
19
|
+
export declare class Identity {
|
|
20
|
+
/**
|
|
21
|
+
* Canonical z32-encoded public key.
|
|
22
|
+
*
|
|
23
|
+
* @type {string}
|
|
24
|
+
*/
|
|
25
|
+
id: string;
|
|
26
|
+
/** @type {Uint8Array} */
|
|
27
|
+
publicKey: Uint8Array;
|
|
28
|
+
/** @type {Uint8Array} */
|
|
29
|
+
secretKey: Uint8Array;
|
|
30
|
+
/**
|
|
31
|
+
* Symmetric key for encrypting per-identity payloads.
|
|
32
|
+
*
|
|
33
|
+
* @type {Uint8Array}
|
|
34
|
+
*/
|
|
35
|
+
encryptionKey: Uint8Array;
|
|
36
|
+
/**
|
|
37
|
+
* Hash of the public key — used as the swarm topic.
|
|
38
|
+
*
|
|
39
|
+
* @type {Uint8Array}
|
|
40
|
+
*/
|
|
41
|
+
topic: Uint8Array;
|
|
42
|
+
/**
|
|
43
|
+
* Original 16- or 32-byte entropy.
|
|
44
|
+
*
|
|
45
|
+
* @type {Uint8Array}
|
|
46
|
+
*/
|
|
47
|
+
seed: Uint8Array;
|
|
48
|
+
/** @param {IdentityFields} keys */
|
|
49
|
+
constructor(keys: IdentityFields);
|
|
50
|
+
/**
|
|
51
|
+
* Redacted — secretKey/encryptionKey/seed must never reach JSON.stringify
|
|
52
|
+
* or a structured logger.
|
|
53
|
+
*
|
|
54
|
+
* @returns {{ id: string }}
|
|
55
|
+
*/
|
|
56
|
+
toJSON(): {
|
|
57
|
+
id: string;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Detached Ed25519 signature over `message`.
|
|
61
|
+
*
|
|
62
|
+
* @param {Uint8Array} message
|
|
63
|
+
* @returns {Uint8Array}
|
|
64
|
+
*/
|
|
65
|
+
sign(message: Uint8Array): Uint8Array;
|
|
66
|
+
/**
|
|
67
|
+
* Verify a signature against this identity's public key.
|
|
68
|
+
*
|
|
69
|
+
* @param {Uint8Array} message
|
|
70
|
+
* @param {Uint8Array} signature
|
|
71
|
+
* @returns {boolean}
|
|
72
|
+
*/
|
|
73
|
+
verify(message: Uint8Array, signature: Uint8Array): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Open a sealed box addressed to this identity (any device holding the seed-derived
|
|
76
|
+
* keypair can open it).
|
|
77
|
+
*
|
|
78
|
+
* @param {Uint8Array} sealed
|
|
79
|
+
* @returns {Uint8Array | null}
|
|
80
|
+
*/
|
|
81
|
+
unseal(sealed: Uint8Array): Uint8Array | null;
|
|
82
|
+
/**
|
|
83
|
+
* Render the underlying seed as a BIP-39 mnemonic phrase.
|
|
84
|
+
*
|
|
85
|
+
* @returns {string}
|
|
86
|
+
*/
|
|
87
|
+
toPhrase(): string;
|
|
11
88
|
/**
|
|
12
89
|
* Build an identity from 16- or 32-byte entropy.
|
|
13
90
|
*
|
|
@@ -76,9 +153,8 @@ export class Identity {
|
|
|
76
153
|
*/
|
|
77
154
|
static verify(publicKey: Uint8Array, message: Uint8Array, signature: Uint8Array): boolean;
|
|
78
155
|
/**
|
|
79
|
-
* Seal a message to an identity's Ed25519 public key (sealed box over the
|
|
80
|
-
*
|
|
81
|
-
* i.e. any of that identity's devices — can open it.
|
|
156
|
+
* Seal a message to an identity's Ed25519 public key (sealed box over the curve25519
|
|
157
|
+
* conversion).
|
|
82
158
|
*
|
|
83
159
|
* @param {Uint8Array} publicKey
|
|
84
160
|
* @param {Uint8Array} message
|
|
@@ -105,84 +181,4 @@ export class Identity {
|
|
|
105
181
|
* @returns {Uint8Array}
|
|
106
182
|
*/
|
|
107
183
|
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
184
|
}
|
|
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,46 @@
|
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
export
|
|
42
|
-
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
export type
|
|
48
|
-
|
|
49
|
-
* `CreateInviteOpts` is a typedef (not a runtime export); re-export it as a type alias.
|
|
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;
|
|
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;
|
|
17
|
+
/**
|
|
18
|
+
* `Ref` / `SingleResult` / `ListResult` are JSDoc typedefs (types, not runtime exports),
|
|
19
|
+
* so they are re-exported as namespaced type aliases — `export { Ref as StorageRef }`
|
|
20
|
+
* fails at import because the.
|
|
21
|
+
*
|
|
22
|
+
* @typedef {import('./storage/index.js').Ref} StorageRef
|
|
23
|
+
* @typedef {import('./storage/index.js').SingleResult} StorageSingleResult
|
|
24
|
+
* @typedef {import('./storage/index.js').ListResult} StorageListResult
|
|
25
|
+
* @typedef {import('./storage/index.js').StorageOpts} StorageOpts
|
|
26
|
+
* @typedef {import('./storage/index.js').StoredRow} StoredRow
|
|
27
|
+
* @typedef {import('./storage/index.js').GetByIdResult} GetByIdResult
|
|
28
|
+
*/
|
|
29
|
+
export * from './network/index.js';
|
|
30
|
+
export * from './database/index.js';
|
|
31
|
+
export * from './blobs/index.js';
|
|
32
|
+
export * from './rpc/index.js';
|
|
33
|
+
export * from './pairing/index.js';
|
|
34
|
+
export { Invite } from './pairing/invite.js';
|
|
35
|
+
export type MintInviteOpts = import('./pairing/invite.js').CreateInviteOpts;
|
|
36
|
+
export type InviteFields = import('./pairing/invite.js').InviteFields;
|
|
37
|
+
export type ParseInviteOpts = import('./pairing/invite.js').ParseInviteOpts;
|
|
56
38
|
/**
|
|
57
39
|
* `CreateInviteOpts` is a typedef (not a runtime export); re-export it as a type alias.
|
|
40
|
+
* @typedef {import('./pairing/invite.js').CreateInviteOpts} MintInviteOpts
|
|
41
|
+
* @typedef {import('./pairing/invite.js').InviteFields} InviteFields
|
|
42
|
+
* @typedef {import('./pairing/invite.js').ParseInviteOpts} ParseInviteOpts
|
|
58
43
|
*/
|
|
59
|
-
export
|
|
44
|
+
export * from './lib/schema.js';
|
|
45
|
+
export * from './lib/utils.js';
|
|
46
|
+
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
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Canonical error class. Every instance carries a stable `code` field which
|
|
3
|
-
*
|
|
4
|
-
* factories produce errors with the right code + a sensible message.
|
|
2
|
+
* Canonical error class. Every instance carries a stable `code` field which is also
|
|
3
|
+
* prefixed to the message, so logs stay self-identifying.
|
|
5
4
|
*/
|
|
6
|
-
export class CeroError extends Error {
|
|
5
|
+
export declare class CeroError extends Error {
|
|
6
|
+
isCeroError: boolean;
|
|
7
|
+
code: string;
|
|
8
|
+
/**
|
|
9
|
+
* @param {string} code Stable identifier (e.g. `REQUIRED`, `EXPIRED`).
|
|
10
|
+
* @param {string} [message] Human-readable detail; appended after the code.
|
|
11
|
+
* @param {Record<string, unknown> | null} [extras] Extra fields copied onto the instance.
|
|
12
|
+
*/
|
|
13
|
+
constructor(code: string, message?: string, extras?: Record<string, unknown> | null);
|
|
14
|
+
get name(): string;
|
|
7
15
|
/**
|
|
8
16
|
* Type-guard for `err instanceof CeroError` that survives realm boundaries.
|
|
9
17
|
*
|
|
@@ -30,9 +38,7 @@ export class CeroError extends Error {
|
|
|
30
38
|
*/
|
|
31
39
|
static CLOSED(resource: string): CeroError;
|
|
32
40
|
/**
|
|
33
|
-
* A channel-stamped storage was opened under a different channel.
|
|
34
|
-
* does NOT name the stored channel — that label gates the network, so leaking it
|
|
35
|
-
* in an error would hint at a realm the caller isn't on.
|
|
41
|
+
* A channel-stamped storage was opened under a different channel.
|
|
36
42
|
*/
|
|
37
43
|
static CHANNEL_MISMATCH(): CeroError;
|
|
38
44
|
/**
|
|
@@ -99,10 +105,9 @@ export class CeroError extends Error {
|
|
|
99
105
|
*/
|
|
100
106
|
static DENIED(reason?: string | null, msg?: string): CeroError;
|
|
101
107
|
/**
|
|
102
|
-
* An apply-time rule refused the op. Every peer reaches this verdict from the
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
* anything that could differ between peers must not abort, or they fork.
|
|
108
|
+
* An apply-time rule refused the op. Every peer reaches this verdict from the same node
|
|
109
|
+
* and the same view, so it aborts the writer's whole batch — which is what makes a
|
|
110
|
+
* transaction atomic.
|
|
106
111
|
*
|
|
107
112
|
* @param {string} rule Which rule refused, e.g. 'write' or 'own'.
|
|
108
113
|
* @param {string} [msg]
|
|
@@ -127,13 +132,4 @@ export class CeroError extends Error {
|
|
|
127
132
|
* @param {number} epoch
|
|
128
133
|
*/
|
|
129
134
|
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
135
|
}
|
package/types/lib/schema.d.ts
CHANGED
|
@@ -1,40 +1,56 @@
|
|
|
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
|
-
* Multi-row table keyed by `id`.
|
|
28
|
-
*
|
|
29
|
-
* `own` restricts a row to the member who wrote it — anyone may add rows, but
|
|
30
|
-
* only the author changes or deletes theirs. Members holding REMOVE can still
|
|
31
|
-
* moderate. Without it a writer may edit any row in the collection.
|
|
46
|
+
* Multi-row table keyed by `id`. `own` restricts a row to the member who wrote it — anyone
|
|
47
|
+
* may add rows, but only the author changes or deletes theirs.
|
|
32
48
|
*
|
|
33
49
|
* @param {Record<string, Prim>} fields
|
|
34
50
|
* @param {{ indexes?: Record<string, string[]>, own?: boolean }} [opts]
|
|
35
51
|
* @returns {TypeDef}
|
|
36
52
|
*/
|
|
37
|
-
|
|
53
|
+
collection(fields: Record<string, Prim>, opts?: {
|
|
38
54
|
indexes?: Record<string, string[]>;
|
|
39
55
|
own?: boolean;
|
|
40
56
|
}): TypeDef;
|
|
@@ -44,7 +60,7 @@ export namespace t {
|
|
|
44
60
|
* @param {Record<string, Prim>} fields
|
|
45
61
|
* @returns {TypeDef}
|
|
46
62
|
*/
|
|
47
|
-
|
|
63
|
+
action(fields: Record<string, Prim>): TypeDef;
|
|
48
64
|
/**
|
|
49
65
|
* Add fields to a builtin type (members, devices, …). Merged into the
|
|
50
66
|
* builtin's base fields at build time; redeclaring a base field throws.
|
|
@@ -52,24 +68,15 @@ export namespace t {
|
|
|
52
68
|
* @param {Record<string, Prim>} fields
|
|
53
69
|
* @returns {{ kind: 'extend', fields: Record<string, Prim> }}
|
|
54
70
|
*/
|
|
55
|
-
|
|
56
|
-
kind:
|
|
71
|
+
extend(fields: Record<string, Prim>): {
|
|
72
|
+
kind: 'extend';
|
|
57
73
|
fields: Record<string, Prim>;
|
|
58
74
|
};
|
|
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
75
|
};
|
|
76
|
+
/**
|
|
77
|
+
* Wrap a definitions object so the builder can recognise it as a schema.
|
|
78
|
+
*
|
|
79
|
+
* @param {SchemaDefs} defs
|
|
80
|
+
* @returns {Schema}
|
|
81
|
+
*/
|
|
82
|
+
export declare function schema(defs: SchemaDefs): Schema;
|