@dxos/keys 0.7.4 → 0.7.5-feature-compute.4d9d99a

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.
@@ -1,5 +1,6 @@
1
1
  import type { inspect, InspectOptionsStylized } from 'node:util';
2
2
  import { inspectCustom } from '@dxos/debug';
3
+ import type { SpaceId } from './space-id';
3
4
  /**
4
5
  * DXN unambiguously names a resource like an ECHO object, schema definition, plugin, etc.
5
6
  * Each DXN starts with a dx prefix, followed by a resource kind.
@@ -23,19 +24,46 @@ export declare class DXN {
23
24
  * Kind constants.
24
25
  */
25
26
  static kind: Readonly<{
27
+ /**
28
+ * dxn:type:<type name>[:<version>]
29
+ */
26
30
  TYPE: "type";
31
+ /**
32
+ * dxn:echo:<space id>:<echo id>
33
+ * dxn:echo:@:<echo id>
34
+ */
27
35
  ECHO: "echo";
36
+ /**
37
+ * dxn:queue:<subspace tag>:<space id>:<queue id>[:object id]
38
+ * dxn:queue:data:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
39
+ * dxn:queue:trace:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
40
+ */
41
+ QUEUE: "queue";
28
42
  }>;
29
43
  static equals(a: DXN, b: DXN): boolean;
30
44
  static isDXNString(dxn: string): boolean;
31
45
  static parse(dxn: string): DXN;
46
+ static parse(dxn: string, noThrow: boolean): DXN | undefined;
47
+ /**
48
+ * @example `dxn:type:example.com/type/Contact`
49
+ */
32
50
  static fromTypename(type: string): DXN;
51
+ /**
52
+ * @example `dxn:type:example.com/type/Contact:0.1.0`
53
+ */
54
+ static fromTypenameAndVersion(type: string, version: string): DXN;
55
+ /**
56
+ * @example `dxn:echo:@:01J00J9B45YHYSGZQTQMSKMGJ6`
57
+ */
33
58
  static fromLocalObjectId(id: string): DXN;
34
59
  constructor(kind: string, parts: string[]);
35
60
  get kind(): string;
36
61
  get parts(): string[];
37
62
  toTypename(): string;
38
63
  hasTypenameOf(typename: string): boolean;
64
+ asTypeDXN(): DXN.TypeDXN | undefined;
65
+ asEchoDXN(): DXN.EchoDXN | undefined;
66
+ asQueueDXN(): DXN.QueueDXN | undefined;
39
67
  isLocalObjectId(): boolean;
40
68
  toString(): string;
41
69
  /**
@@ -43,8 +71,28 @@ export declare class DXN {
43
71
  */
44
72
  [inspectCustom](depth: number, options: InspectOptionsStylized, inspectFn: typeof inspect): string;
45
73
  }
74
+ export declare namespace DXN {
75
+ type TypeDXN = {
76
+ type: string;
77
+ version?: string;
78
+ };
79
+ type EchoDXN = {
80
+ spaceId?: SpaceId;
81
+ echoId: string;
82
+ };
83
+ type QueueDXN = {
84
+ subspaceTag: string;
85
+ spaceId: SpaceId;
86
+ queueId: string;
87
+ objectId?: string;
88
+ };
89
+ }
46
90
  /**
47
91
  * Tags for ECHO DXNs that should resolve the object ID in the local space.
48
92
  */
49
93
  export declare const LOCAL_SPACE_TAG = "@";
94
+ export declare const QueueSubspaceTags: Readonly<{
95
+ DATA: "data";
96
+ TRACE: "trace";
97
+ }>;
50
98
  //# sourceMappingURL=dxn.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dxn.d.ts","sourceRoot":"","sources":["../../../src/dxn.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAEjE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,GAAG;;IACd;;OAEG;IACH,MAAM,CAAC,IAAI;;;OAGR;IAEH,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG;IAI5B,MAAM,CAAC,WAAW,CAAC,GAAG,EAAE,MAAM;IAI9B,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG;IAkB9B,MAAM,CAAC,YAA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O,EAAE,MAAM;IAI3D;;OAEG;IACH,MAAM,CAAC,iBAAiB,CAAC,EAAE,EAAE,MAAM;gBAOvB,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE;IAsBzC,IAAI,IAAI,WAEP;IAED,IAAI,KAAK,aAER;IAED,UAAU;IAKV,aAAa,CAAC,QAAQ,EAAE,MAAM;IAI9B,SAAS,IAAI,GAAG,CAAC,OAAO,GAAG,SAAS;IAYpC,SAAS,IAAI,GAAG,CAAC,OAAO,GAAG,SAAS;IAYpC,UAAU,IAAI,GAAG,CAAC,QAAQ,GAAG,SAAS;IAiBtC,eAAe;IAIf,QAAQ;IAIR;;OAEG;IACH,CAAC,aAAa,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,sBAAsB,EAAE,SAAS,EAAE,OAAO,OAAO;CAS1F;AAED,MAAM,CAAC,OAAO,WAAW,GAAG,CAAC;IAC3B,KAAY,OAAO,GAAG;QACpB,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;IAEF,KAAY,OAAO,GAAG;QACpB,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;IAEF,KAAY,QAAQ,GAAG;QACrB,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,EAAE,OAAO,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;QAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;CACH;AAED;;GAEG;AACH,eAAO,MAAM,eAAe,MAAM,CAAC;AAEnC,eAAO,MAAM,iBAAiB;;;EAG5B,CAAC"}
@@ -1,2 +1,2 @@
1
- export declare const randomBytes: (length: number) => Uint8Array;
1
+ export declare const randomBytes: (length: number) => Uint8Array<ArrayBuffer>;
2
2
  //# sourceMappingURL=random-bytes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"random-bytes.d.ts","sourceRoot":"","sources":["../../../src/random-bytes.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,WAAW,WAAY,MAAM,eAQzC,CAAC"}
1
+ {"version":3,"file":"random-bytes.d.ts","sourceRoot":"","sources":["../../../src/random-bytes.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,WAAW,WAAY,MAAM,4BAQzC,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":"5.7.2"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/keys",
3
- "version": "0.7.4",
3
+ "version": "0.7.5-feature-compute.4d9d99a",
4
4
  "description": "Key utils and definitions.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -26,9 +26,9 @@
26
26
  "src"
27
27
  ],
28
28
  "dependencies": {
29
- "@dxos/invariant": "0.7.4",
30
- "@dxos/debug": "0.7.4",
31
- "@dxos/node-std": "0.7.4"
29
+ "@dxos/debug": "0.7.5-feature-compute.4d9d99a",
30
+ "@dxos/invariant": "0.7.5-feature-compute.4d9d99a",
31
+ "@dxos/node-std": "0.7.5-feature-compute.4d9d99a"
32
32
  },
33
33
  "devDependencies": {
34
34
  "base32-decode": "^1.0.0",
package/src/dxn.ts CHANGED
@@ -7,6 +7,8 @@ import type { inspect, InspectOptionsStylized } from 'node:util';
7
7
  import { inspectCustom } from '@dxos/debug';
8
8
  import { invariant } from '@dxos/invariant';
9
9
 
10
+ import type { SpaceId } from './space-id';
11
+
10
12
  /**
11
13
  * DXN unambiguously names a resource like an ECHO object, schema definition, plugin, etc.
12
14
  * Each DXN starts with a dx prefix, followed by a resource kind.
@@ -29,8 +31,21 @@ export class DXN {
29
31
  * Kind constants.
30
32
  */
31
33
  static kind = Object.freeze({
34
+ /**
35
+ * dxn:type:<type name>[:<version>]
36
+ */
32
37
  TYPE: 'type',
38
+ /**
39
+ * dxn:echo:<space id>:<echo id>
40
+ * dxn:echo:@:<echo id>
41
+ */
33
42
  ECHO: 'echo',
43
+ /**
44
+ * dxn:queue:<subspace tag>:<space id>:<queue id>[:object id]
45
+ * dxn:queue:data:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
46
+ * dxn:queue:trace:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
47
+ */
48
+ QUEUE: 'queue',
34
49
  });
35
50
 
36
51
  static equals(a: DXN, b: DXN) {
@@ -41,28 +56,56 @@ export class DXN {
41
56
  return dxn.startsWith('dxn:');
42
57
  }
43
58
 
44
- static parse(dxn: string): DXN {
59
+ static parse(dxn: string): DXN;
60
+ static parse(dxn: string, noThrow: boolean): DXN | undefined;
61
+ static parse(dxn: string, noThrow?: boolean): DXN | undefined {
45
62
  if (typeof dxn !== 'string') {
46
- throw new Error('Invalid DXN');
63
+ if (noThrow) {
64
+ return undefined;
65
+ }
66
+ throw new Error(`Invalid DXN: ${dxn}`);
47
67
  }
48
68
  const [prefix, kind, ...parts] = dxn.split(':');
49
69
  if (!(prefix === 'dxn')) {
50
- throw new Error('Invalid DXN');
70
+ if (noThrow) {
71
+ return undefined;
72
+ }
73
+ throw new Error(`Invalid DXN: ${dxn}`);
51
74
  }
52
75
  if (!(typeof kind === 'string' && kind.length > 0)) {
53
- throw new Error('Invalid DXN');
76
+ if (noThrow) {
77
+ return undefined;
78
+ }
79
+ throw new Error(`Invalid DXN: ${dxn}`);
54
80
  }
55
81
  if (!(parts.length > 0)) {
56
- throw new Error('Invalid DXN');
82
+ if (noThrow) {
83
+ return undefined;
84
+ }
85
+ throw new Error(`Invalid DXN: ${dxn}`);
57
86
  }
58
87
 
59
88
  return new DXN(kind, parts);
60
89
  }
61
90
 
91
+ /**
92
+ * @example `dxn:type:example.com/type/Contact`
93
+ */
62
94
  static fromTypename(type: string) {
63
95
  return new DXN(DXN.kind.TYPE, [type]);
64
96
  }
65
97
 
98
+ /**
99
+ * @example `dxn:type:example.com/type/Contact:0.1.0`
100
+ */
101
+ // TODO(dmaretskyi): Consider using @ as the version separator.
102
+ static fromTypenameAndVersion(type: string, version: string) {
103
+ return new DXN(DXN.kind.TYPE, [type, version]);
104
+ }
105
+
106
+ /**
107
+ * @example `dxn:echo:@:01J00J9B45YHYSGZQTQMSKMGJ6`
108
+ */
66
109
  static fromLocalObjectId(id: string) {
67
110
  return new DXN(DXN.kind.ECHO, [LOCAL_SPACE_TAG, id]);
68
111
  }
@@ -77,7 +120,7 @@ export class DXN {
77
120
  // Per-type validation.
78
121
  switch (kind) {
79
122
  case DXN.kind.TYPE:
80
- if (parts.length !== 1) {
123
+ if (parts.length > 2) {
81
124
  throw new Error('Invalid "type" DXN');
82
125
  }
83
126
  break;
@@ -109,6 +152,47 @@ export class DXN {
109
152
  return this.#kind === DXN.kind.TYPE && this.#parts.length === 1 && this.#parts[0] === typename;
110
153
  }
111
154
 
155
+ asTypeDXN(): DXN.TypeDXN | undefined {
156
+ if (this.kind !== DXN.kind.TYPE) {
157
+ return undefined;
158
+ }
159
+
160
+ const [type, version] = this.#parts;
161
+ return {
162
+ type,
163
+ version: version as string | undefined,
164
+ };
165
+ }
166
+
167
+ asEchoDXN(): DXN.EchoDXN | undefined {
168
+ if (this.kind !== DXN.kind.ECHO) {
169
+ return undefined;
170
+ }
171
+
172
+ const [spaceId, echoId] = this.#parts;
173
+ return {
174
+ spaceId: spaceId === LOCAL_SPACE_TAG ? undefined : (spaceId as SpaceId | undefined),
175
+ echoId,
176
+ };
177
+ }
178
+
179
+ asQueueDXN(): DXN.QueueDXN | undefined {
180
+ if (this.kind !== DXN.kind.QUEUE) {
181
+ return undefined;
182
+ }
183
+
184
+ const [subspaceTag, spaceId, queueId, objectId] = this.#parts;
185
+ if (typeof queueId !== 'string') {
186
+ return undefined;
187
+ }
188
+ return {
189
+ subspaceTag,
190
+ spaceId: spaceId as SpaceId,
191
+ queueId,
192
+ objectId: objectId as string | undefined,
193
+ };
194
+ }
195
+
112
196
  isLocalObjectId() {
113
197
  return this.#kind === DXN.kind.ECHO && this.#parts[0] === LOCAL_SPACE_TAG && this.#parts.length === 2;
114
198
  }
@@ -131,7 +215,31 @@ export class DXN {
131
215
  }
132
216
  }
133
217
 
218
+ export declare namespace DXN {
219
+ export type TypeDXN = {
220
+ type: string;
221
+ version?: string;
222
+ };
223
+
224
+ export type EchoDXN = {
225
+ spaceId?: SpaceId;
226
+ echoId: string; // TODO(dmaretskyi): ObjectId.
227
+ };
228
+
229
+ export type QueueDXN = {
230
+ subspaceTag: string;
231
+ spaceId: SpaceId;
232
+ queueId: string; // TODO(dmaretskyi): ObjectId.
233
+ objectId?: string; // TODO(dmaretskyi): ObjectId.
234
+ };
235
+ }
236
+
134
237
  /**
135
238
  * Tags for ECHO DXNs that should resolve the object ID in the local space.
136
239
  */
137
240
  export const LOCAL_SPACE_TAG = '@';
241
+
242
+ export const QueueSubspaceTags = Object.freeze({
243
+ DATA: 'data',
244
+ TRACE: 'trace',
245
+ });