@dxos/protocols 0.1.58-main.fa022ee → 0.1.58-main.ffb4cc4
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/dist/cjs/src/errors/base-errors.d.ts +27 -0
- package/dist/cjs/src/errors/base-errors.d.ts.map +1 -0
- package/dist/cjs/src/errors/base-errors.js +43 -0
- package/dist/cjs/src/errors/base-errors.js.map +1 -0
- package/dist/cjs/src/errors/encoding.d.ts +1 -1
- package/dist/cjs/src/errors/encoding.d.ts.map +1 -1
- package/dist/cjs/src/errors/encoding.js.map +1 -1
- package/dist/cjs/src/errors/errors.d.ts +2 -28
- package/dist/cjs/src/errors/errors.d.ts.map +1 -1
- package/dist/cjs/src/errors/errors.js +54 -57
- package/dist/cjs/src/errors/errors.js.map +1 -1
- package/dist/cjs/src/errors/errors.test.js +2 -2
- package/dist/cjs/src/errors/errors.test.js.map +1 -1
- package/dist/cjs/src/errors/helpers.d.ts +7 -3
- package/dist/cjs/src/errors/helpers.d.ts.map +1 -1
- package/dist/cjs/src/errors/helpers.js +21 -58
- package/dist/cjs/src/errors/helpers.js.map +1 -1
- package/dist/cjs/src/errors/index.d.ts +1 -0
- package/dist/cjs/src/errors/index.d.ts.map +1 -1
- package/dist/cjs/src/errors/index.js +1 -0
- package/dist/cjs/src/errors/index.js.map +1 -1
- package/dist/cjs/src/index.d.ts +2 -2
- package/dist/cjs/src/index.d.ts.map +1 -1
- package/dist/cjs/src/index.js +2 -2
- package/dist/cjs/src/index.js.map +1 -1
- package/dist/cjs/src/proto/gen/dxos/config.d.ts +51 -5
- package/dist/cjs/src/proto/gen/dxos/config.d.ts.map +1 -1
- package/dist/cjs/src/proto/gen/dxos/config.js.map +1 -1
- package/dist/cjs/src/proto/gen/dxos/error.d.ts +2 -0
- package/dist/cjs/src/proto/gen/dxos/error.d.ts.map +1 -1
- package/dist/cjs/src/proto/gen/index.d.ts +1 -0
- package/dist/cjs/src/proto/gen/index.d.ts.map +1 -1
- package/dist/cjs/src/proto/gen/index.js +1 -1
- package/dist/cjs/src/proto/gen/index.js.map +1 -1
- package/dist/cjs/src/storage.d.ts +2 -3
- package/dist/cjs/src/storage.d.ts.map +1 -1
- package/dist/cjs/src/storage.js +2 -3
- package/dist/cjs/src/storage.js.map +1 -1
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/src/errors/base-errors.d.ts +27 -0
- package/dist/esm/src/errors/base-errors.d.ts.map +1 -0
- package/dist/esm/src/errors/base-errors.js +38 -0
- package/dist/esm/src/errors/base-errors.js.map +1 -0
- package/dist/esm/src/errors/encoding.d.ts +1 -1
- package/dist/esm/src/errors/encoding.d.ts.map +1 -1
- package/dist/esm/src/errors/encoding.js.map +1 -1
- package/dist/esm/src/errors/errors.d.ts +2 -28
- package/dist/esm/src/errors/errors.d.ts.map +1 -1
- package/dist/esm/src/errors/errors.js +32 -36
- package/dist/esm/src/errors/errors.js.map +1 -1
- package/dist/esm/src/errors/errors.test.js +1 -1
- package/dist/esm/src/errors/errors.test.js.map +1 -1
- package/dist/esm/src/errors/helpers.d.ts +7 -3
- package/dist/esm/src/errors/helpers.d.ts.map +1 -1
- package/dist/esm/src/errors/helpers.js +17 -57
- package/dist/esm/src/errors/helpers.js.map +1 -1
- package/dist/esm/src/errors/index.d.ts +1 -0
- package/dist/esm/src/errors/index.d.ts.map +1 -1
- package/dist/esm/src/errors/index.js +1 -0
- package/dist/esm/src/errors/index.js.map +1 -1
- package/dist/esm/src/index.d.ts +2 -2
- package/dist/esm/src/index.d.ts.map +1 -1
- package/dist/esm/src/index.js +2 -2
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/proto/gen/dxos/config.d.ts +51 -5
- package/dist/esm/src/proto/gen/dxos/config.d.ts.map +1 -1
- package/dist/esm/src/proto/gen/dxos/config.js.map +1 -1
- package/dist/esm/src/proto/gen/dxos/error.d.ts +2 -0
- package/dist/esm/src/proto/gen/dxos/error.d.ts.map +1 -1
- package/dist/esm/src/proto/gen/index.d.ts +1 -0
- package/dist/esm/src/proto/gen/index.d.ts.map +1 -1
- package/dist/esm/src/proto/gen/index.js +1 -1
- package/dist/esm/src/proto/gen/index.js.map +1 -1
- package/dist/esm/src/storage.d.ts +2 -3
- package/dist/esm/src/storage.d.ts.map +1 -1
- package/dist/esm/src/storage.js +2 -3
- package/dist/esm/src/storage.js.map +1 -1
- package/package.json +5 -5
- package/src/errors/base-errors.ts +34 -0
- package/src/errors/encoding.ts +1 -1
- package/src/errors/errors.test.ts +1 -1
- package/src/errors/errors.ts +52 -34
- package/src/errors/helpers.ts +20 -94
- package/src/errors/index.ts +1 -0
- package/src/index.ts +2 -2
- package/src/proto/dxos/config.proto +31 -9
- package/src/proto/dxos/error.proto +1 -0
- package/src/proto/gen/dxos/config.ts +51 -5
- package/src/proto/gen/dxos/error.ts +2 -0
- package/src/proto/gen/index.ts +2 -1
- package/src/storage.ts +2 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/proto/gen/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAuDhE,OAAO,aAAa,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/proto/gen/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAuDhE,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAgf7C,MAAM,CAAC,MAAM,UAAU,GAAG,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,uy2FAAuy2F,CAAC,CAAC,CAAC;AACh22F,MAAM,CAAC,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAkB,UAAU,EAAE,aAAa,CAAC,CAAC"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Version for the schema of the stored data as defined in dxos.echo.metadata.EchoMetadata.
|
|
3
|
-
*
|
|
4
|
-
* Should be incremented every time there's a breaking change to the stored data.
|
|
3
|
+
* update when making breaking changes to the protocols or other stored data.
|
|
5
4
|
*/
|
|
6
|
-
export declare const STORAGE_VERSION =
|
|
5
|
+
export declare const STORAGE_VERSION = 2;
|
|
7
6
|
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../../src/storage.ts"],"names":[],"mappings":"AAIA
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../../src/storage.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,eAAO,MAAM,eAAe,IAAI,CAAC"}
|
package/dist/esm/src/storage.js
CHANGED
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
//
|
|
4
4
|
/**
|
|
5
5
|
* Version for the schema of the stored data as defined in dxos.echo.metadata.EchoMetadata.
|
|
6
|
-
*
|
|
7
|
-
* Should be incremented every time there's a breaking change to the stored data.
|
|
6
|
+
* update when making breaking changes to the protocols or other stored data.
|
|
8
7
|
*/
|
|
9
|
-
export const STORAGE_VERSION =
|
|
8
|
+
export const STORAGE_VERSION = 2;
|
|
10
9
|
//# sourceMappingURL=storage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../../../src/storage.ts"],"names":[],"mappings":"AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;AAEF
|
|
1
|
+
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../../../src/storage.ts"],"names":[],"mappings":"AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/protocols",
|
|
3
|
-
"version": "0.1.58-main.
|
|
3
|
+
"version": "0.1.58-main.ffb4cc4",
|
|
4
4
|
"description": "Protobuf definitions for DXOS protocols.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
"src"
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@dxos/codec-protobuf": "0.1.58-main.
|
|
37
|
-
"@dxos/invariant": "0.1.58-main.
|
|
38
|
-
"@dxos/keys": "0.1.58-main.
|
|
39
|
-
"@dxos/timeframe": "0.1.58-main.
|
|
36
|
+
"@dxos/codec-protobuf": "0.1.58-main.ffb4cc4",
|
|
37
|
+
"@dxos/invariant": "0.1.58-main.ffb4cc4",
|
|
38
|
+
"@dxos/keys": "0.1.58-main.ffb4cc4",
|
|
39
|
+
"@dxos/timeframe": "0.1.58-main.ffb4cc4"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"glob": "~7.1.6"
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2021 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* NOTE: Messages should be sentences (Start with a capital letter and end with a period).
|
|
7
|
+
* Errors can optionally include a JSON context object.
|
|
8
|
+
*/
|
|
9
|
+
export class BaseError extends Error {
|
|
10
|
+
constructor(readonly code: string, message?: string, readonly context?: Record<string, any>) {
|
|
11
|
+
super(message ?? code);
|
|
12
|
+
this.name = code;
|
|
13
|
+
// NOTE: Restores prototype chain (https://stackoverflow.com/a/48342359).
|
|
14
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* User facing API Errors.
|
|
20
|
+
* E.g., something was misconfigured.
|
|
21
|
+
*/
|
|
22
|
+
export class ApiError extends BaseError {}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Internal system errors.
|
|
26
|
+
* E.g., unexpected/unrecoverable runtime error.
|
|
27
|
+
*/
|
|
28
|
+
export class SystemError extends BaseError {}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Database errors.
|
|
32
|
+
*/
|
|
33
|
+
// TODO(wittjosiah): Same as ApiError?
|
|
34
|
+
export class DatabaseError extends BaseError {}
|
package/src/errors/encoding.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Error as SerializedErrorProto } from '../proto/gen/dxos/error';
|
|
6
5
|
import { reconstructError } from './helpers';
|
|
6
|
+
import { Error as SerializedErrorProto } from '../proto/gen/dxos/error';
|
|
7
7
|
|
|
8
8
|
export const encodeError = (err: any): SerializedErrorProto => {
|
|
9
9
|
if (typeof err === 'object' && err?.message) {
|
package/src/errors/errors.ts
CHANGED
|
@@ -2,41 +2,12 @@
|
|
|
2
2
|
// Copyright 2021 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import { PublicKey } from '@dxos/keys';
|
|
6
6
|
|
|
7
|
+
import { ApiError, DatabaseError, SystemError, BaseError } from './base-errors';
|
|
8
|
+
import { registerError, registerErrorMessageContext, registerErrorNoArgs } from './helpers';
|
|
7
9
|
import type { ItemID } from '../types';
|
|
8
10
|
|
|
9
|
-
/**
|
|
10
|
-
* NOTE: Messages should be sentences (Start with a capital letter and end with a period).
|
|
11
|
-
* Errors can optionally include a JSON context object.
|
|
12
|
-
*/
|
|
13
|
-
class BaseError extends Error {
|
|
14
|
-
constructor(readonly code: string, message?: string, readonly context?: Record<string, any>) {
|
|
15
|
-
super(message ?? code);
|
|
16
|
-
this.name = code;
|
|
17
|
-
// NOTE: Restores prototype chain (https://stackoverflow.com/a/48342359).
|
|
18
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* User facing API Errors.
|
|
24
|
-
* E.g., something was misconfigured.
|
|
25
|
-
*/
|
|
26
|
-
export class ApiError extends BaseError {}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Internal system errors.
|
|
30
|
-
* E.g., unexpected/unrecoverable runtime error.
|
|
31
|
-
*/
|
|
32
|
-
export class SystemError extends BaseError {}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Database errors.
|
|
36
|
-
*/
|
|
37
|
-
// TODO(wittjosiah): Same as ApiError?
|
|
38
|
-
export class DatabaseError extends BaseError {}
|
|
39
|
-
|
|
40
11
|
/**
|
|
41
12
|
* Thrown when request was terminated because the RPC endpoint has been closed.
|
|
42
13
|
*/
|
|
@@ -46,6 +17,8 @@ export class RpcClosedError extends SystemError {
|
|
|
46
17
|
}
|
|
47
18
|
}
|
|
48
19
|
|
|
20
|
+
registerErrorNoArgs('RPC_CLOSED', RpcClosedError);
|
|
21
|
+
|
|
49
22
|
/**
|
|
50
23
|
* Thrown when `request` is called when RPC has not been opened.
|
|
51
24
|
*/
|
|
@@ -55,18 +28,24 @@ export class RpcNotOpenError extends SystemError {
|
|
|
55
28
|
}
|
|
56
29
|
}
|
|
57
30
|
|
|
31
|
+
registerErrorNoArgs('RPC_NOT_OPEN', RpcNotOpenError);
|
|
32
|
+
|
|
58
33
|
export class CancelledError extends SystemError {
|
|
59
34
|
constructor(message?: string, context?: Record<string, any>) {
|
|
60
35
|
super('CANCELLED', message, context);
|
|
61
36
|
}
|
|
62
37
|
}
|
|
63
38
|
|
|
39
|
+
registerErrorMessageContext('CANCELLED', CancelledError);
|
|
40
|
+
|
|
64
41
|
export class InvalidConfigError extends ApiError {
|
|
65
42
|
constructor(message?: string, context?: Record<string, any>) {
|
|
66
43
|
super('INVALID_CONFIG', message, context);
|
|
67
44
|
}
|
|
68
45
|
}
|
|
69
46
|
|
|
47
|
+
registerErrorMessageContext('INVALID_CONFIG', InvalidConfigError);
|
|
48
|
+
|
|
70
49
|
/**
|
|
71
50
|
* Explicit failure to connect with remote client services.
|
|
72
51
|
*/
|
|
@@ -76,6 +55,8 @@ export class RemoteServiceConnectionError extends ApiError {
|
|
|
76
55
|
}
|
|
77
56
|
}
|
|
78
57
|
|
|
58
|
+
registerErrorMessageContext('REMOTE_SERVICE_CONNECTION_ERROR', RemoteServiceConnectionError);
|
|
59
|
+
|
|
79
60
|
/**
|
|
80
61
|
* Failed to open a connection to remote client services.
|
|
81
62
|
*/
|
|
@@ -85,82 +66,119 @@ export class RemoteServiceConnectionTimeout extends ApiError {
|
|
|
85
66
|
}
|
|
86
67
|
}
|
|
87
68
|
|
|
69
|
+
registerErrorMessageContext('REMOTE_SERVICE_CONNECTION_TIMEOUT', RemoteServiceConnectionTimeout);
|
|
70
|
+
|
|
88
71
|
export class DataCorruptionError extends SystemError {
|
|
89
72
|
constructor(message?: string, context?: Record<string, any>) {
|
|
90
73
|
super('DATA_CORRUPTION', message, context);
|
|
91
74
|
}
|
|
92
75
|
}
|
|
93
76
|
|
|
77
|
+
registerErrorMessageContext('DATA_CORRUPTION', DataCorruptionError);
|
|
78
|
+
|
|
94
79
|
export class InvalidInvitationExtensionRoleError extends SystemError {
|
|
95
80
|
constructor(message?: string, context?: Record<string, any>) {
|
|
96
81
|
super('INVALID_INVITATION_EXTENSION_ROLE', message, context);
|
|
97
82
|
}
|
|
98
83
|
}
|
|
99
84
|
|
|
85
|
+
registerErrorMessageContext('INVALID_INVITATION_EXTENSION_ROLE', InvalidInvitationExtensionRoleError);
|
|
86
|
+
|
|
100
87
|
export class IdentityNotInitializedError extends DatabaseError {
|
|
101
88
|
constructor(message?: string, context?: Record<string, any>) {
|
|
102
89
|
super('IDENTITY_NOT_INITIALIZED', message, context);
|
|
103
90
|
}
|
|
104
91
|
}
|
|
105
92
|
|
|
93
|
+
registerErrorMessageContext('IDENTITY_NOT_INITIALIZED', IdentityNotInitializedError);
|
|
94
|
+
|
|
106
95
|
export class InvalidInvitationError extends DatabaseError {
|
|
107
96
|
constructor(message?: string, context?: Record<string, any>) {
|
|
108
97
|
super('INVALID_INVITATION', message, context);
|
|
109
98
|
}
|
|
110
99
|
}
|
|
111
100
|
|
|
101
|
+
registerErrorMessageContext('INVALID_INVITATION', InvalidInvitationError);
|
|
102
|
+
|
|
112
103
|
export class ConnectionResetError extends BaseError {
|
|
113
104
|
constructor(message?: string, context?: any) {
|
|
114
105
|
super('CONNECTION_RESET', message, context);
|
|
115
106
|
}
|
|
116
107
|
}
|
|
117
108
|
|
|
109
|
+
registerErrorMessageContext('CONNECTION_RESET', ConnectionResetError);
|
|
110
|
+
|
|
118
111
|
export class TimeoutError extends BaseError {
|
|
119
112
|
constructor(message?: string, context?: any) {
|
|
120
113
|
super('TIMEOUT', message, context);
|
|
121
114
|
}
|
|
122
115
|
}
|
|
123
116
|
|
|
124
|
-
|
|
117
|
+
registerErrorMessageContext('TIMEOUT', TimeoutError);
|
|
118
|
+
|
|
119
|
+
// General protocol error.
|
|
125
120
|
export class ProtocolError extends BaseError {
|
|
126
121
|
constructor(message?: string, context?: any) {
|
|
127
122
|
super('PROTOCOL_ERROR', message, context);
|
|
128
123
|
}
|
|
129
124
|
}
|
|
130
125
|
|
|
131
|
-
|
|
126
|
+
registerErrorMessageContext('PROTOCOL_ERROR', ProtocolError);
|
|
127
|
+
|
|
128
|
+
// General connectivity errors.
|
|
132
129
|
export class ConnectivityError extends BaseError {
|
|
133
130
|
constructor(message?: string, context?: any) {
|
|
134
131
|
super('CONNECTIVITY_ERROR', message, context);
|
|
135
132
|
}
|
|
136
133
|
}
|
|
137
134
|
|
|
135
|
+
registerErrorMessageContext('CONNECTIVITY_ERROR', ConnectivityError);
|
|
136
|
+
|
|
138
137
|
// TODO(nf): Rename? the protocol isn't what's unknown...
|
|
139
138
|
export class UnknownProtocolError extends BaseError {
|
|
140
139
|
constructor(message?: string, innerError?: Error) {
|
|
141
140
|
super('UNKNOWN_PROTOCOL_ERROR', message, innerError);
|
|
142
141
|
}
|
|
143
142
|
}
|
|
143
|
+
|
|
144
|
+
registerErrorMessageContext('UNKNOWN_PROTOCOL_ERROR', UnknownProtocolError);
|
|
145
|
+
|
|
144
146
|
export class InvalidStorageVersionError extends DatabaseError {
|
|
145
147
|
constructor(expected: number, actual: number) {
|
|
146
148
|
super('INVALID_STORAGE_VERSION', 'Invalid storage version.', { expected, actual });
|
|
147
149
|
}
|
|
148
150
|
}
|
|
149
151
|
|
|
152
|
+
registerError('INVALID_STORAGE_VERSION', (_, context) => {
|
|
153
|
+
return new InvalidStorageVersionError(context.expected ?? NaN, context.actual ?? NaN);
|
|
154
|
+
});
|
|
155
|
+
|
|
150
156
|
export class SpaceNotFoundError extends DatabaseError {
|
|
151
157
|
constructor(spaceKey: PublicKey) {
|
|
152
158
|
super('SPACE_NOT_FOUND', 'Space not found.', { spaceKey });
|
|
153
159
|
}
|
|
154
160
|
}
|
|
155
161
|
|
|
162
|
+
registerError('SPACE_NOT_FOUND', (_, context) => {
|
|
163
|
+
return new SpaceNotFoundError(PublicKey.safeFrom(context.spaceKey) ?? PublicKey.from('00'));
|
|
164
|
+
});
|
|
165
|
+
|
|
156
166
|
export class EntityNotFoundError extends DatabaseError {
|
|
157
167
|
constructor(entityId: ItemID) {
|
|
158
168
|
super('ITEM_NOT_FOUND', 'Item not found.', { entityId });
|
|
159
169
|
}
|
|
160
170
|
}
|
|
161
171
|
|
|
172
|
+
registerError('ITEM_NOT_FOUND', (_, context) => {
|
|
173
|
+
return new EntityNotFoundError(context.entityId);
|
|
174
|
+
});
|
|
175
|
+
|
|
162
176
|
export class UnknownModelError extends DatabaseError {
|
|
163
177
|
constructor(model: string) {
|
|
164
178
|
super('UNKNOWN_MODEL', 'Unknown model.', { model });
|
|
165
179
|
}
|
|
166
180
|
}
|
|
181
|
+
|
|
182
|
+
registerError('UNKNOWN_MODEL', (_, context) => {
|
|
183
|
+
return new UnknownModelError(context.model);
|
|
184
|
+
});
|
package/src/errors/helpers.ts
CHANGED
|
@@ -3,111 +3,37 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { invariant } from '@dxos/invariant';
|
|
6
|
-
import { PublicKey } from '@dxos/keys';
|
|
7
6
|
|
|
7
|
+
import { SystemError } from './base-errors';
|
|
8
8
|
import { Error as SerializedErrorProto } from '../proto/gen/dxos/error';
|
|
9
|
-
import {
|
|
10
|
-
CancelledError,
|
|
11
|
-
ConnectionResetError,
|
|
12
|
-
ConnectivityError,
|
|
13
|
-
DataCorruptionError,
|
|
14
|
-
EntityNotFoundError,
|
|
15
|
-
IdentityNotInitializedError,
|
|
16
|
-
InvalidConfigError,
|
|
17
|
-
InvalidInvitationError,
|
|
18
|
-
InvalidInvitationExtensionRoleError,
|
|
19
|
-
InvalidStorageVersionError,
|
|
20
|
-
ProtocolError,
|
|
21
|
-
RemoteServiceConnectionError,
|
|
22
|
-
RemoteServiceConnectionTimeout,
|
|
23
|
-
RpcClosedError,
|
|
24
|
-
RpcNotOpenError,
|
|
25
|
-
SpaceNotFoundError,
|
|
26
|
-
SystemError,
|
|
27
|
-
TimeoutError,
|
|
28
|
-
UnknownModelError,
|
|
29
|
-
UnknownProtocolError,
|
|
30
|
-
} from './errors';
|
|
31
9
|
|
|
32
10
|
export const reconstructError = (error: SerializedErrorProto) => {
|
|
33
11
|
const { name, message, context } = error;
|
|
34
12
|
return errorFromCode(name, message, context);
|
|
35
13
|
};
|
|
36
14
|
|
|
37
|
-
|
|
38
|
-
switch (code) {
|
|
39
|
-
case 'RPC_CLOSED':
|
|
40
|
-
return new RpcClosedError();
|
|
41
|
-
|
|
42
|
-
case 'RPC_NOT_OPEN':
|
|
43
|
-
return new RpcNotOpenError();
|
|
44
|
-
|
|
45
|
-
case 'CANCELLED':
|
|
46
|
-
return new CancelledError(message, context);
|
|
47
|
-
|
|
48
|
-
case 'INVALID_CONFIG':
|
|
49
|
-
return new InvalidConfigError(message, context);
|
|
50
|
-
|
|
51
|
-
case 'REMOTE_SERVICE_CONNECTION_ERROR':
|
|
52
|
-
return new RemoteServiceConnectionError(message, context);
|
|
53
|
-
|
|
54
|
-
case 'REMOTE_SERVICE_CONNECTION_TIMEOUT':
|
|
55
|
-
return new RemoteServiceConnectionTimeout(message, context);
|
|
56
|
-
|
|
57
|
-
case 'DATA_CORRUPTION':
|
|
58
|
-
return new DataCorruptionError(message, context);
|
|
59
|
-
|
|
60
|
-
case 'INVALID_INVITATION_EXTENSION_ROLE':
|
|
61
|
-
return new InvalidInvitationExtensionRoleError(message, context);
|
|
62
|
-
|
|
63
|
-
case 'CONNECTION_RESET':
|
|
64
|
-
return new ConnectionResetError(message, context);
|
|
65
|
-
|
|
66
|
-
case 'TIMEOUT':
|
|
67
|
-
return new TimeoutError(message, context);
|
|
15
|
+
const errorRegistry = new Map<string, (message?: string, context?: any) => Error>();
|
|
68
16
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return new ConnectivityError(message, context);
|
|
74
|
-
|
|
75
|
-
case 'UNKNOWN_PROTOCOL_ERROR':
|
|
76
|
-
return new UnknownProtocolError(message, context);
|
|
77
|
-
|
|
78
|
-
case 'IDENTITY_NOT_INITIALIZED':
|
|
79
|
-
return new IdentityNotInitializedError(message, context);
|
|
80
|
-
|
|
81
|
-
case 'INVALID_INVITATION':
|
|
82
|
-
return new InvalidInvitationError(message, context);
|
|
83
|
-
|
|
84
|
-
case 'INVALID_STORAGE_VERSION': {
|
|
85
|
-
const { expected, actual } = context;
|
|
86
|
-
invariant(expected);
|
|
87
|
-
invariant(actual);
|
|
88
|
-
return new InvalidStorageVersionError(expected, actual);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
case 'SPACE_NOT_FOUND': {
|
|
92
|
-
const { spaceKey: key } = context;
|
|
93
|
-
const spaceKey = PublicKey.safeFrom(key);
|
|
94
|
-
invariant(spaceKey);
|
|
95
|
-
return new SpaceNotFoundError(spaceKey);
|
|
96
|
-
}
|
|
17
|
+
export const registerError = (code: string, make: (message?: string, context?: any) => Error) => {
|
|
18
|
+
invariant(!errorRegistry.has(code), `Error code already registered: ${code}`);
|
|
19
|
+
errorRegistry.set(code, make);
|
|
20
|
+
};
|
|
97
21
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
return new EntityNotFoundError(entityId);
|
|
102
|
-
}
|
|
22
|
+
export const registerErrorNoArgs = (code: string, Constructor: { new (): Error }) => {
|
|
23
|
+
registerError(code, () => new Constructor());
|
|
24
|
+
};
|
|
103
25
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
26
|
+
export const registerErrorMessageContext = (
|
|
27
|
+
code: string,
|
|
28
|
+
Constructor: { new (message?: string, context?: any): Error },
|
|
29
|
+
) => {
|
|
30
|
+
registerError(code, (message?: string, context?: string) => new Constructor(message, context));
|
|
31
|
+
};
|
|
109
32
|
|
|
110
|
-
|
|
111
|
-
|
|
33
|
+
export const errorFromCode = (code?: string, message?: string, context?: any) => {
|
|
34
|
+
if (code && errorRegistry.has(code)) {
|
|
35
|
+
return errorRegistry.get(code)!(message, context);
|
|
36
|
+
} else {
|
|
37
|
+
return new SystemError(code ?? 'Error', message, context);
|
|
112
38
|
}
|
|
113
39
|
};
|
package/src/errors/index.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -45,6 +45,9 @@ message Repo {
|
|
|
45
45
|
optional string version = 3;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
//
|
|
49
|
+
// Unit of deployment.
|
|
50
|
+
//
|
|
48
51
|
message Module {
|
|
49
52
|
message Build {
|
|
50
53
|
optional string command = 1;
|
|
@@ -55,22 +58,23 @@ message Module {
|
|
|
55
58
|
optional google.protobuf.Struct env = 10;
|
|
56
59
|
}
|
|
57
60
|
|
|
58
|
-
optional string name = 1; // TODO(burdon): Replace with id (or key?)
|
|
59
61
|
optional string id = 8; // TODO(burdon): Ensured FQ (e.g., 'dxos.app.xxx')
|
|
60
|
-
optional string
|
|
62
|
+
optional string name = 1; // TODO(burdon): Replace with id (or key?)
|
|
63
|
+
optional string type = 2; // TODO(burdon): Define namespace (e.g., 'dxos.org/type/frame' vs. 'dxos.type.frame')
|
|
61
64
|
|
|
62
65
|
// TODO(burdon): Developer info message.
|
|
63
66
|
|
|
67
|
+
// TODO(burdon): Start at 10.
|
|
64
68
|
optional string display_name = 3;
|
|
65
69
|
optional string description = 4;
|
|
66
70
|
repeated string tags = 5;
|
|
67
|
-
optional bytes bundle = 6;
|
|
71
|
+
optional bytes bundle = 6; // TODO(burdon): ???
|
|
68
72
|
|
|
69
73
|
// TODO(burdon): Remove.
|
|
70
74
|
optional bool tunnel = 7;
|
|
71
75
|
|
|
76
|
+
// TODO(burdon): Start at 100.
|
|
72
77
|
repeated Module deps = 10; // TODO(burdon): E.g., types.
|
|
73
|
-
|
|
74
78
|
optional Build build = 100;
|
|
75
79
|
repeated Repo repos = 101;
|
|
76
80
|
|
|
@@ -90,15 +94,15 @@ message Runtime {
|
|
|
90
94
|
NODE = 4;
|
|
91
95
|
WEBFS = 5;
|
|
92
96
|
|
|
93
|
-
// Key storage only
|
|
97
|
+
// Key storage only.
|
|
94
98
|
LEVELJS = 11;
|
|
95
99
|
JSONDOWN = 12;
|
|
96
100
|
}
|
|
97
101
|
|
|
98
|
-
optional bool persistent = 1;
|
|
99
|
-
optional StorageDriver
|
|
100
|
-
optional StorageDriver
|
|
101
|
-
optional string
|
|
102
|
+
optional bool persistent = 1;
|
|
103
|
+
optional StorageDriver key_store = 2;
|
|
104
|
+
optional StorageDriver data_store = 3;
|
|
105
|
+
optional string data_root = 4;
|
|
102
106
|
}
|
|
103
107
|
|
|
104
108
|
message Log {
|
|
@@ -152,7 +156,25 @@ message Runtime {
|
|
|
152
156
|
int32 port = 1;
|
|
153
157
|
}
|
|
154
158
|
|
|
159
|
+
/// Automatic epoch creation.
|
|
160
|
+
message EpochMontior {
|
|
161
|
+
optional bool enabled = 5;
|
|
162
|
+
|
|
163
|
+
/// Number of mutations required since last epoch to trigger a new epoch.
|
|
164
|
+
optional int32 minMessagesBetweenEpochs = 1;
|
|
165
|
+
|
|
166
|
+
/// Amount of time (in milliseconds) required to pass since last epoch to trigger a new epoch.
|
|
167
|
+
optional int32 minTimeBetweenEpochs = 2;
|
|
168
|
+
|
|
169
|
+
/// Amount of time (in milliseconds) required to pass since last mutation to trigger a new epoch.
|
|
170
|
+
optional int32 minInactivityBeforeEpoch = 3;
|
|
171
|
+
|
|
172
|
+
/// Maximum amount of time (in milliseconds) to wait for an inactivity period before triggering a new epoch.
|
|
173
|
+
optional int32 maxInactivityDelay = 4;
|
|
174
|
+
}
|
|
175
|
+
|
|
155
176
|
optional Functions functions = 1;
|
|
177
|
+
optional EpochMontior epoch_monitor = 2;
|
|
156
178
|
}
|
|
157
179
|
|
|
158
180
|
optional Plugins plugins = 1;
|
|
@@ -10,6 +10,7 @@ option go_package = "github.com/dxos/kube/proto/def/dxos/error";
|
|
|
10
10
|
|
|
11
11
|
/// Serialized error.
|
|
12
12
|
message Error {
|
|
13
|
+
/// Also error code. Will be used to reconstruct a known error type.
|
|
13
14
|
optional string name = 1;
|
|
14
15
|
optional string message = 2;
|
|
15
16
|
optional google.protobuf.Struct context = 4;
|
|
@@ -117,12 +117,12 @@ export interface Module {
|
|
|
117
117
|
* Options:
|
|
118
118
|
* - proto3_optional = true
|
|
119
119
|
*/
|
|
120
|
-
|
|
120
|
+
id?: string;
|
|
121
121
|
/**
|
|
122
122
|
* Options:
|
|
123
123
|
* - proto3_optional = true
|
|
124
124
|
*/
|
|
125
|
-
|
|
125
|
+
name?: string;
|
|
126
126
|
/**
|
|
127
127
|
* Options:
|
|
128
128
|
* - proto3_optional = true
|
|
@@ -307,17 +307,17 @@ export namespace Runtime {
|
|
|
307
307
|
* Options:
|
|
308
308
|
* - proto3_optional = true
|
|
309
309
|
*/
|
|
310
|
-
|
|
310
|
+
keyStore?: Runtime.Client.Storage.StorageDriver;
|
|
311
311
|
/**
|
|
312
312
|
* Options:
|
|
313
313
|
* - proto3_optional = true
|
|
314
314
|
*/
|
|
315
|
-
|
|
315
|
+
dataStore?: Runtime.Client.Storage.StorageDriver;
|
|
316
316
|
/**
|
|
317
317
|
* Options:
|
|
318
318
|
* - proto3_optional = true
|
|
319
319
|
*/
|
|
320
|
-
|
|
320
|
+
dataRoot?: string;
|
|
321
321
|
}
|
|
322
322
|
export namespace Storage {
|
|
323
323
|
/**
|
|
@@ -445,6 +445,11 @@ export namespace Runtime {
|
|
|
445
445
|
* - proto3_optional = true
|
|
446
446
|
*/
|
|
447
447
|
functions?: Runtime.Agent.Plugins.Functions;
|
|
448
|
+
/**
|
|
449
|
+
* Options:
|
|
450
|
+
* - proto3_optional = true
|
|
451
|
+
*/
|
|
452
|
+
epochMonitor?: Runtime.Agent.Plugins.EpochMontior;
|
|
448
453
|
}
|
|
449
454
|
export namespace Plugins {
|
|
450
455
|
/**
|
|
@@ -454,6 +459,47 @@ export namespace Runtime {
|
|
|
454
459
|
export interface Functions {
|
|
455
460
|
port: number;
|
|
456
461
|
}
|
|
462
|
+
/**
|
|
463
|
+
* Automatic epoch creation.
|
|
464
|
+
*
|
|
465
|
+
* Defined in:
|
|
466
|
+
* {@link file://./../../dxos/config.proto}
|
|
467
|
+
*/
|
|
468
|
+
export interface EpochMontior {
|
|
469
|
+
/**
|
|
470
|
+
* Options:
|
|
471
|
+
* - proto3_optional = true
|
|
472
|
+
*/
|
|
473
|
+
enabled?: boolean;
|
|
474
|
+
/**
|
|
475
|
+
* Number of mutations required since last epoch to trigger a new epoch.
|
|
476
|
+
*
|
|
477
|
+
* Options:
|
|
478
|
+
* - proto3_optional = true
|
|
479
|
+
*/
|
|
480
|
+
minMessagesBetweenEpochs?: number;
|
|
481
|
+
/**
|
|
482
|
+
* Amount of time (in milliseconds) required to pass since last epoch to trigger a new epoch.
|
|
483
|
+
*
|
|
484
|
+
* Options:
|
|
485
|
+
* - proto3_optional = true
|
|
486
|
+
*/
|
|
487
|
+
minTimeBetweenEpochs?: number;
|
|
488
|
+
/**
|
|
489
|
+
* Amount of time (in milliseconds) required to pass since last mutation to trigger a new epoch.
|
|
490
|
+
*
|
|
491
|
+
* Options:
|
|
492
|
+
* - proto3_optional = true
|
|
493
|
+
*/
|
|
494
|
+
minInactivityBeforeEpoch?: number;
|
|
495
|
+
/**
|
|
496
|
+
* Maximum amount of time (in milliseconds) to wait for an inactivity period before triggering a new epoch.
|
|
497
|
+
*
|
|
498
|
+
* Options:
|
|
499
|
+
* - proto3_optional = true
|
|
500
|
+
*/
|
|
501
|
+
maxInactivityDelay?: number;
|
|
502
|
+
}
|
|
457
503
|
}
|
|
458
504
|
}
|
|
459
505
|
/**
|