@dxos/protocols 0.1.58-main.ffbb8a1 → 0.1.58-next.6d0af18

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.
Files changed (134) hide show
  1. package/dist/cjs/src/errors/base-errors.d.ts +27 -0
  2. package/dist/cjs/src/errors/base-errors.d.ts.map +1 -0
  3. package/dist/cjs/src/errors/base-errors.js +43 -0
  4. package/dist/cjs/src/errors/base-errors.js.map +1 -0
  5. package/dist/cjs/src/errors/encoding.d.ts +7 -0
  6. package/dist/cjs/src/errors/encoding.d.ts.map +1 -0
  7. package/dist/cjs/src/errors/encoding.js +41 -0
  8. package/dist/cjs/src/errors/encoding.js.map +1 -0
  9. package/dist/cjs/src/errors/errors.d.ts +73 -0
  10. package/dist/cjs/src/errors/errors.d.ts.map +1 -0
  11. package/dist/cjs/src/errors/errors.js +168 -0
  12. package/dist/cjs/src/errors/errors.js.map +1 -0
  13. package/dist/cjs/src/errors/errors.test.d.ts +2 -0
  14. package/dist/cjs/src/errors/errors.test.d.ts.map +1 -0
  15. package/dist/cjs/src/errors/errors.test.js +45 -0
  16. package/dist/cjs/src/errors/errors.test.js.map +1 -0
  17. package/dist/cjs/src/errors/helpers.d.ts +9 -0
  18. package/dist/cjs/src/errors/helpers.d.ts.map +1 -0
  19. package/dist/cjs/src/errors/helpers.js +37 -0
  20. package/dist/cjs/src/errors/helpers.js.map +1 -0
  21. package/dist/cjs/src/errors/index.d.ts +5 -0
  22. package/dist/cjs/src/errors/index.d.ts.map +1 -0
  23. package/dist/cjs/src/errors/index.js +24 -0
  24. package/dist/cjs/src/errors/index.js.map +1 -0
  25. package/dist/cjs/src/index.d.ts +2 -2
  26. package/dist/cjs/src/index.d.ts.map +1 -1
  27. package/dist/cjs/src/index.js +2 -2
  28. package/dist/cjs/src/index.js.map +1 -1
  29. package/dist/cjs/src/proto/gen/dxos/client/services.d.ts +7 -1
  30. package/dist/cjs/src/proto/gen/dxos/client/services.d.ts.map +1 -1
  31. package/dist/cjs/src/proto/gen/dxos/client/services.js +1 -0
  32. package/dist/cjs/src/proto/gen/dxos/client/services.js.map +1 -1
  33. package/dist/cjs/src/proto/gen/dxos/config.d.ts +51 -5
  34. package/dist/cjs/src/proto/gen/dxos/config.d.ts.map +1 -1
  35. package/dist/cjs/src/proto/gen/dxos/config.js.map +1 -1
  36. package/dist/cjs/src/proto/gen/dxos/error.d.ts +8 -0
  37. package/dist/cjs/src/proto/gen/dxos/error.d.ts.map +1 -1
  38. package/dist/cjs/src/proto/gen/dxos/halo/credentials.d.ts +14 -1
  39. package/dist/cjs/src/proto/gen/dxos/halo/credentials.d.ts.map +1 -1
  40. package/dist/cjs/src/proto/gen/dxos/halo/credentials.js.map +1 -1
  41. package/dist/cjs/src/proto/gen/dxos/iframe.d.ts +5 -10
  42. package/dist/cjs/src/proto/gen/dxos/iframe.d.ts.map +1 -1
  43. package/dist/cjs/src/proto/gen/dxos/iframe.js +5 -3
  44. package/dist/cjs/src/proto/gen/dxos/iframe.js.map +1 -1
  45. package/dist/cjs/src/proto/gen/index.d.ts +2 -0
  46. package/dist/cjs/src/proto/gen/index.d.ts.map +1 -1
  47. package/dist/cjs/src/proto/gen/index.js +1 -1
  48. package/dist/cjs/src/proto/gen/index.js.map +1 -1
  49. package/dist/cjs/src/storage.d.ts +2 -3
  50. package/dist/cjs/src/storage.d.ts.map +1 -1
  51. package/dist/cjs/src/storage.js +2 -3
  52. package/dist/cjs/src/storage.js.map +1 -1
  53. package/dist/cjs/tsconfig.tsbuildinfo +1 -1
  54. package/dist/esm/src/errors/base-errors.d.ts +27 -0
  55. package/dist/esm/src/errors/base-errors.d.ts.map +1 -0
  56. package/dist/esm/src/errors/base-errors.js +38 -0
  57. package/dist/esm/src/errors/base-errors.js.map +1 -0
  58. package/dist/esm/src/errors/encoding.d.ts +7 -0
  59. package/dist/esm/src/errors/encoding.d.ts.map +1 -0
  60. package/dist/esm/src/errors/encoding.js +35 -0
  61. package/dist/esm/src/errors/encoding.js.map +1 -0
  62. package/dist/esm/src/errors/errors.d.ts +73 -0
  63. package/dist/esm/src/errors/errors.d.ts.map +1 -0
  64. package/dist/esm/src/errors/errors.js +144 -0
  65. package/dist/esm/src/errors/errors.js.map +1 -0
  66. package/dist/esm/src/errors/errors.test.d.ts +2 -0
  67. package/dist/esm/src/errors/errors.test.d.ts.map +1 -0
  68. package/dist/esm/src/errors/errors.test.js +17 -0
  69. package/dist/esm/src/errors/errors.test.js.map +1 -0
  70. package/dist/esm/src/errors/helpers.d.ts +9 -0
  71. package/dist/esm/src/errors/helpers.d.ts.map +1 -0
  72. package/dist/esm/src/errors/helpers.js +29 -0
  73. package/dist/esm/src/errors/helpers.js.map +1 -0
  74. package/dist/esm/src/errors/index.d.ts +5 -0
  75. package/dist/esm/src/errors/index.d.ts.map +1 -0
  76. package/dist/esm/src/errors/index.js +8 -0
  77. package/dist/esm/src/errors/index.js.map +1 -0
  78. package/dist/esm/src/index.d.ts +2 -2
  79. package/dist/esm/src/index.d.ts.map +1 -1
  80. package/dist/esm/src/index.js +2 -2
  81. package/dist/esm/src/index.js.map +1 -1
  82. package/dist/esm/src/proto/gen/dxos/client/services.d.ts +7 -1
  83. package/dist/esm/src/proto/gen/dxos/client/services.d.ts.map +1 -1
  84. package/dist/esm/src/proto/gen/dxos/client/services.js +1 -0
  85. package/dist/esm/src/proto/gen/dxos/client/services.js.map +1 -1
  86. package/dist/esm/src/proto/gen/dxos/config.d.ts +51 -5
  87. package/dist/esm/src/proto/gen/dxos/config.d.ts.map +1 -1
  88. package/dist/esm/src/proto/gen/dxos/config.js.map +1 -1
  89. package/dist/esm/src/proto/gen/dxos/error.d.ts +8 -0
  90. package/dist/esm/src/proto/gen/dxos/error.d.ts.map +1 -1
  91. package/dist/esm/src/proto/gen/dxos/halo/credentials.d.ts +14 -1
  92. package/dist/esm/src/proto/gen/dxos/halo/credentials.d.ts.map +1 -1
  93. package/dist/esm/src/proto/gen/dxos/halo/credentials.js.map +1 -1
  94. package/dist/esm/src/proto/gen/dxos/iframe.d.ts +5 -10
  95. package/dist/esm/src/proto/gen/dxos/iframe.d.ts.map +1 -1
  96. package/dist/esm/src/proto/gen/dxos/iframe.js +5 -3
  97. package/dist/esm/src/proto/gen/dxos/iframe.js.map +1 -1
  98. package/dist/esm/src/proto/gen/index.d.ts +2 -0
  99. package/dist/esm/src/proto/gen/index.d.ts.map +1 -1
  100. package/dist/esm/src/proto/gen/index.js +1 -1
  101. package/dist/esm/src/proto/gen/index.js.map +1 -1
  102. package/dist/esm/src/storage.d.ts +2 -3
  103. package/dist/esm/src/storage.d.ts.map +1 -1
  104. package/dist/esm/src/storage.js +2 -3
  105. package/dist/esm/src/storage.js.map +1 -1
  106. package/package.json +5 -4
  107. package/src/errors/base-errors.ts +34 -0
  108. package/src/errors/encoding.ts +40 -0
  109. package/src/errors/errors.test.ts +22 -0
  110. package/src/errors/errors.ts +184 -0
  111. package/src/errors/helpers.ts +39 -0
  112. package/src/errors/index.ts +8 -0
  113. package/src/index.ts +2 -2
  114. package/src/proto/dxos/client/services.proto +2 -0
  115. package/src/proto/dxos/config.proto +31 -9
  116. package/src/proto/dxos/error.proto +2 -0
  117. package/src/proto/dxos/halo/credentials.proto +8 -1
  118. package/src/proto/dxos/iframe.proto +6 -5
  119. package/src/proto/gen/dxos/client/services.ts +7 -1
  120. package/src/proto/gen/dxos/config.ts +51 -5
  121. package/src/proto/gen/dxos/error.ts +7 -0
  122. package/src/proto/gen/dxos/halo/credentials.ts +14 -1
  123. package/src/proto/gen/dxos/iframe.ts +5 -10
  124. package/src/proto/gen/index.ts +3 -1
  125. package/src/storage.ts +2 -3
  126. package/dist/cjs/src/errors.d.ts +0 -25
  127. package/dist/cjs/src/errors.d.ts.map +0 -1
  128. package/dist/cjs/src/errors.js +0 -78
  129. package/dist/cjs/src/errors.js.map +0 -1
  130. package/dist/esm/src/errors.d.ts +0 -25
  131. package/dist/esm/src/errors.d.ts.map +0 -1
  132. package/dist/esm/src/errors.js +0 -69
  133. package/dist/esm/src/errors.js.map +0 -1
  134. package/src/errors.ts +0 -80
@@ -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;AA8e7C,MAAM,CAAC,MAAM,UAAU,GAAG,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,44zFAA44zF,CAAC,CAAC,CAAC;AACr8zF,MAAM,CAAC,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAkB,UAAU,EAAE,aAAa,CAAC,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 = 1;
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;;;;GAIG;AACH,eAAO,MAAM,eAAe,IAAI,CAAC"}
1
+ {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../../src/storage.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,eAAO,MAAM,eAAe,IAAI,CAAC"}
@@ -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 = 1;
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;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC"}
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.ffbb8a1",
3
+ "version": "0.1.58-next.6d0af18",
4
4
  "description": "Protobuf definitions for DXOS protocols.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -33,9 +33,10 @@
33
33
  "src"
34
34
  ],
35
35
  "dependencies": {
36
- "@dxos/codec-protobuf": "0.1.58-main.ffbb8a1",
37
- "@dxos/keys": "0.1.58-main.ffbb8a1",
38
- "@dxos/timeframe": "0.1.58-main.ffbb8a1"
36
+ "@dxos/codec-protobuf": "0.1.58-next.6d0af18",
37
+ "@dxos/invariant": "0.1.58-next.6d0af18",
38
+ "@dxos/keys": "0.1.58-next.6d0af18",
39
+ "@dxos/timeframe": "0.1.58-next.6d0af18"
39
40
  },
40
41
  "devDependencies": {
41
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 {}
@@ -0,0 +1,40 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { reconstructError } from './helpers';
6
+ import { Error as SerializedErrorProto } from '../proto/gen/dxos/error';
7
+
8
+ export const encodeError = (err: any): SerializedErrorProto => {
9
+ if (typeof err === 'object' && err?.message) {
10
+ return {
11
+ name: err.name,
12
+ message: err.message,
13
+ context: err.context,
14
+ stack: err.stack,
15
+ };
16
+ } else if (typeof err === 'string') {
17
+ return {
18
+ message: err,
19
+ };
20
+ } else {
21
+ return {
22
+ message: JSON.stringify(err),
23
+ };
24
+ }
25
+ };
26
+
27
+ export type DecodeOptions = {
28
+ appendStack?: string;
29
+ };
30
+
31
+ export const decodeError = (err: SerializedErrorProto, { appendStack }: DecodeOptions = {}) => {
32
+ const error = reconstructError(err);
33
+ if (appendStack) {
34
+ error.stack = (err.stack ?? `${error.message}\n`) + appendStack;
35
+ } else {
36
+ error.stack = err.stack;
37
+ }
38
+
39
+ return error;
40
+ };
@@ -0,0 +1,22 @@
1
+ //
2
+ // Copyright 2022 DXOS.org
3
+ //
4
+
5
+ import chai, { expect } from 'chai';
6
+ import chaiAsPromised from 'chai-as-promised';
7
+
8
+ import { describe, test } from '@dxos/test';
9
+
10
+ import { ApiError } from './base-errors';
11
+
12
+ chai.use(chaiAsPromised);
13
+
14
+ describe('Errors', () => {
15
+ test('test', async () => {
16
+ const runTest = async () => {
17
+ throw new ApiError('Test error');
18
+ };
19
+
20
+ await expect(runTest()).to.be.rejectedWith('Test error');
21
+ });
22
+ });
@@ -0,0 +1,184 @@
1
+ //
2
+ // Copyright 2021 DXOS.org
3
+ //
4
+
5
+ import { PublicKey } from '@dxos/keys';
6
+
7
+ import { ApiError, DatabaseError, SystemError, BaseError } from './base-errors';
8
+ import { registerError, registerErrorMessageContext, registerErrorNoArgs } from './helpers';
9
+ import type { ItemID } from '../types';
10
+
11
+ /**
12
+ * Thrown when request was terminated because the RPC endpoint has been closed.
13
+ */
14
+ export class RpcClosedError extends SystemError {
15
+ constructor() {
16
+ super('RPC_CLOSED', 'Request was terminated because the RPC endpoint is closed.');
17
+ }
18
+ }
19
+
20
+ registerErrorNoArgs('RPC_CLOSED', RpcClosedError);
21
+
22
+ /**
23
+ * Thrown when `request` is called when RPC has not been opened.
24
+ */
25
+ export class RpcNotOpenError extends SystemError {
26
+ constructor() {
27
+ super('RPC_NOT_OPEN', 'RPC has not been opened.');
28
+ }
29
+ }
30
+
31
+ registerErrorNoArgs('RPC_NOT_OPEN', RpcNotOpenError);
32
+
33
+ export class CancelledError extends SystemError {
34
+ constructor(message?: string, context?: Record<string, any>) {
35
+ super('CANCELLED', message, context);
36
+ }
37
+ }
38
+
39
+ registerErrorMessageContext('CANCELLED', CancelledError);
40
+
41
+ export class InvalidConfigError extends ApiError {
42
+ constructor(message?: string, context?: Record<string, any>) {
43
+ super('INVALID_CONFIG', message, context);
44
+ }
45
+ }
46
+
47
+ registerErrorMessageContext('INVALID_CONFIG', InvalidConfigError);
48
+
49
+ /**
50
+ * Explicit failure to connect with remote client services.
51
+ */
52
+ export class RemoteServiceConnectionError extends ApiError {
53
+ constructor(message?: string, context?: Record<string, any>) {
54
+ super('REMOTE_SERVICE_CONNECTION_ERROR', message, context);
55
+ }
56
+ }
57
+
58
+ registerErrorMessageContext('REMOTE_SERVICE_CONNECTION_ERROR', RemoteServiceConnectionError);
59
+
60
+ /**
61
+ * Failed to open a connection to remote client services.
62
+ */
63
+ export class RemoteServiceConnectionTimeout extends ApiError {
64
+ constructor(message?: string, context?: Record<string, any>) {
65
+ super('REMOTE_SERVICE_CONNECTION_TIMEOUT', message, context);
66
+ }
67
+ }
68
+
69
+ registerErrorMessageContext('REMOTE_SERVICE_CONNECTION_TIMEOUT', RemoteServiceConnectionTimeout);
70
+
71
+ export class DataCorruptionError extends SystemError {
72
+ constructor(message?: string, context?: Record<string, any>) {
73
+ super('DATA_CORRUPTION', message, context);
74
+ }
75
+ }
76
+
77
+ registerErrorMessageContext('DATA_CORRUPTION', DataCorruptionError);
78
+
79
+ export class InvalidInvitationExtensionRoleError extends SystemError {
80
+ constructor(message?: string, context?: Record<string, any>) {
81
+ super('INVALID_INVITATION_EXTENSION_ROLE', message, context);
82
+ }
83
+ }
84
+
85
+ registerErrorMessageContext('INVALID_INVITATION_EXTENSION_ROLE', InvalidInvitationExtensionRoleError);
86
+
87
+ export class IdentityNotInitializedError extends DatabaseError {
88
+ constructor(message?: string, context?: Record<string, any>) {
89
+ super('IDENTITY_NOT_INITIALIZED', message, context);
90
+ }
91
+ }
92
+
93
+ registerErrorMessageContext('IDENTITY_NOT_INITIALIZED', IdentityNotInitializedError);
94
+
95
+ export class InvalidInvitationError extends DatabaseError {
96
+ constructor(message?: string, context?: Record<string, any>) {
97
+ super('INVALID_INVITATION', message, context);
98
+ }
99
+ }
100
+
101
+ registerErrorMessageContext('INVALID_INVITATION', InvalidInvitationError);
102
+
103
+ export class ConnectionResetError extends BaseError {
104
+ constructor(message?: string, context?: any) {
105
+ super('CONNECTION_RESET', message, context);
106
+ }
107
+ }
108
+
109
+ registerErrorMessageContext('CONNECTION_RESET', ConnectionResetError);
110
+
111
+ export class TimeoutError extends BaseError {
112
+ constructor(message?: string, context?: any) {
113
+ super('TIMEOUT', message, context);
114
+ }
115
+ }
116
+
117
+ registerErrorMessageContext('TIMEOUT', TimeoutError);
118
+
119
+ // General protocol error.
120
+ export class ProtocolError extends BaseError {
121
+ constructor(message?: string, context?: any) {
122
+ super('PROTOCOL_ERROR', message, context);
123
+ }
124
+ }
125
+
126
+ registerErrorMessageContext('PROTOCOL_ERROR', ProtocolError);
127
+
128
+ // General connectivity errors.
129
+ export class ConnectivityError extends BaseError {
130
+ constructor(message?: string, context?: any) {
131
+ super('CONNECTIVITY_ERROR', message, context);
132
+ }
133
+ }
134
+
135
+ registerErrorMessageContext('CONNECTIVITY_ERROR', ConnectivityError);
136
+
137
+ // TODO(nf): Rename? the protocol isn't what's unknown...
138
+ export class UnknownProtocolError extends BaseError {
139
+ constructor(message?: string, innerError?: Error) {
140
+ super('UNKNOWN_PROTOCOL_ERROR', message, innerError);
141
+ }
142
+ }
143
+
144
+ registerErrorMessageContext('UNKNOWN_PROTOCOL_ERROR', UnknownProtocolError);
145
+
146
+ export class InvalidStorageVersionError extends DatabaseError {
147
+ constructor(expected: number, actual: number) {
148
+ super('INVALID_STORAGE_VERSION', 'Invalid storage version.', { expected, actual });
149
+ }
150
+ }
151
+
152
+ registerError('INVALID_STORAGE_VERSION', (_, context) => {
153
+ return new InvalidStorageVersionError(context.expected ?? NaN, context.actual ?? NaN);
154
+ });
155
+
156
+ export class SpaceNotFoundError extends DatabaseError {
157
+ constructor(spaceKey: PublicKey) {
158
+ super('SPACE_NOT_FOUND', 'Space not found.', { spaceKey });
159
+ }
160
+ }
161
+
162
+ registerError('SPACE_NOT_FOUND', (_, context) => {
163
+ return new SpaceNotFoundError(PublicKey.safeFrom(context.spaceKey) ?? PublicKey.from('00'));
164
+ });
165
+
166
+ export class EntityNotFoundError extends DatabaseError {
167
+ constructor(entityId: ItemID) {
168
+ super('ITEM_NOT_FOUND', 'Item not found.', { entityId });
169
+ }
170
+ }
171
+
172
+ registerError('ITEM_NOT_FOUND', (_, context) => {
173
+ return new EntityNotFoundError(context.entityId);
174
+ });
175
+
176
+ export class UnknownModelError extends DatabaseError {
177
+ constructor(model: string) {
178
+ super('UNKNOWN_MODEL', 'Unknown model.', { model });
179
+ }
180
+ }
181
+
182
+ registerError('UNKNOWN_MODEL', (_, context) => {
183
+ return new UnknownModelError(context.model);
184
+ });
@@ -0,0 +1,39 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { invariant } from '@dxos/invariant';
6
+
7
+ import { SystemError } from './base-errors';
8
+ import { Error as SerializedErrorProto } from '../proto/gen/dxos/error';
9
+
10
+ export const reconstructError = (error: SerializedErrorProto) => {
11
+ const { name, message, context } = error;
12
+ return errorFromCode(name, message, context);
13
+ };
14
+
15
+ const errorRegistry = new Map<string, (message?: string, context?: any) => Error>();
16
+
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
+ };
21
+
22
+ export const registerErrorNoArgs = (code: string, Constructor: { new (): Error }) => {
23
+ registerError(code, () => new Constructor());
24
+ };
25
+
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
+ };
32
+
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);
38
+ }
39
+ };
@@ -0,0 +1,8 @@
1
+ //
2
+ // Copyright 2022 DXOS.org
3
+ //
4
+
5
+ export * from './encoding';
6
+ export * from './errors';
7
+ export * from './helpers';
8
+ export * from './base-errors';
package/src/index.ts CHANGED
@@ -2,9 +2,9 @@
2
2
  // Copyright 2021 DXOS.org
3
3
  //
4
4
 
5
+ export * from './errors';
5
6
  export * from './proto';
6
7
  export * from './storage';
7
8
  export * from './testing';
8
- export * from './types';
9
9
  export * from './tracing';
10
- export * from './errors';
10
+ export * from './types';
@@ -163,6 +163,7 @@ message SpaceMember {
163
163
  enum PresenceState {
164
164
  OFFLINE = 0;
165
165
  ONLINE = 1;
166
+ REMOVED = 2;
166
167
  }
167
168
 
168
169
  Identity identity = 1;
@@ -301,6 +302,7 @@ message WriteCredentialsRequest {
301
302
 
302
303
  message QueryCredentialsRequest {
303
304
  dxos.keys.PublicKey space_key = 1;
305
+ optional bool no_tail = 2;
304
306
  }
305
307
 
306
308
  message CreateEpochRequest {
@@ -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 type = 2; // TODO(burdon): Define namespace (e.g., 'dxos:type/frame' vs. 'dxos.type.frame')
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; // TODO(burdon): Replace with type.
99
- optional StorageDriver key_storage = 3; // TODO(burdon): Rename key_store.
100
- optional StorageDriver storage_type = 2; // TODO(burdon): Rename data_store.
101
- optional string path = 4; // TODO(burdon): Rename data_path.
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,7 +10,9 @@ 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;
16
+ optional google.protobuf.Struct context = 4;
15
17
  optional string stack = 3;
16
18
  }
@@ -38,6 +38,13 @@ message SpaceGenesis {
38
38
  // Claims can be written directly to a feed or used within Credentials.
39
39
  //
40
40
 
41
+ /**
42
+ * Revocation of another credential.
43
+ * Subject must be the credential id being revoked.
44
+ */
45
+ message Revocation {
46
+ }
47
+
41
48
  // TODO(burdon): Reconcile with dxos.client.SpaceMember.
42
49
  // [ASSERTION]: Agent is authorized to access Space.
43
50
  message SpaceMember {
@@ -219,7 +226,7 @@ message Credential {
219
226
  optional google.protobuf.Timestamp expiration_date = 4;
220
227
  optional bytes expiration_ref = 5; // Could reference blockchain or epoch number.
221
228
  Claim subject = 10;
222
- Proof proof = 11;
229
+ optional Proof proof = 11;
223
230
  }
224
231
 
225
232
  //
@@ -31,10 +31,9 @@ enum ShellDisplay {
31
31
  message AppContextRequest {
32
32
  /// The display mode that shell should use
33
33
  optional ShellDisplay display = 1;
34
+
34
35
  /// The key of the joined space
35
36
  optional dxos.keys.PublicKey space_key = 2;
36
- /// The invitation code which has become invalidated
37
- optional string invalidated_invitation_code = 3;
38
37
  }
39
38
 
40
39
  /// App RPCs for the shell.
@@ -45,9 +44,11 @@ service AppService {
45
44
  enum ShellLayout {
46
45
  DEFAULT = 0;
47
46
  INITIALIZE_IDENTITY = 1;
48
- DEVICE_INVITATIONS = 2;
49
- SPACE_INVITATIONS = 3;
50
- JOIN_SPACE = 4;
47
+ IDENTITY = 2;
48
+ SHARE_IDENTITY = 3;
49
+ EDIT_PROFILE = 4;
50
+ SPACE = 5;
51
+ JOIN_SPACE = 6;
51
52
  }
52
53
 
53
54
  message LayoutRequest {
@@ -442,7 +442,8 @@ export namespace SpaceMember {
442
442
  */
443
443
  export enum PresenceState {
444
444
  OFFLINE = 0,
445
- ONLINE = 1
445
+ ONLINE = 1,
446
+ REMOVED = 2
446
447
  }
447
448
  }
448
449
  /**
@@ -678,6 +679,11 @@ export interface WriteCredentialsRequest {
678
679
  */
679
680
  export interface QueryCredentialsRequest {
680
681
  spaceKey: ReturnType<(typeof substitutions)["dxos.keys.PublicKey"]["decode"]>;
682
+ /**
683
+ * Options:
684
+ * - proto3_optional = true
685
+ */
686
+ noTail?: boolean;
681
687
  }
682
688
  /**
683
689
  * Defined in: