@dxos/keys 0.8.3 → 0.8.4-main.3a94e84

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/keys",
3
- "version": "0.8.3",
3
+ "version": "0.8.4-main.3a94e84",
4
4
  "description": "Key utils and definitions.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -27,11 +27,11 @@
27
27
  "src"
28
28
  ],
29
29
  "dependencies": {
30
- "effect": "3.14.21",
30
+ "effect": "3.17.0",
31
31
  "ulidx": "^2.3.0",
32
- "@dxos/invariant": "0.8.3",
33
- "@dxos/debug": "0.8.3",
34
- "@dxos/node-std": "0.8.3"
32
+ "@dxos/debug": "0.8.4-main.3a94e84",
33
+ "@dxos/invariant": "0.8.4-main.3a94e84",
34
+ "@dxos/node-std": "0.8.4-main.3a94e84"
35
35
  },
36
36
  "devDependencies": {
37
37
  "base32-decode": "^1.0.0",
package/src/dxn.ts CHANGED
@@ -6,7 +6,7 @@ import { Schema } from 'effect';
6
6
  import type { inspect, InspectOptionsStylized } from 'node:util';
7
7
 
8
8
  import { devtoolsFormatter, type DevtoolsFormatter, inspectCustom } from '@dxos/debug';
9
- import { invariant } from '@dxos/invariant';
9
+ import { assertArgument, invariant } from '@dxos/invariant';
10
10
 
11
11
  import { ObjectId } from './object-id';
12
12
  import { SpaceId } from './space-id';
@@ -143,6 +143,7 @@ export class DXN {
143
143
  * @example `dxn:echo:@:01J00J9B45YHYSGZQTQMSKMGJ6`
144
144
  */
145
145
  static fromLocalObjectId(id: string): DXN {
146
+ assertArgument(ObjectId.isValid(id), `Invalid object ID: ${id}`);
146
147
  return new DXN(DXN.kind.ECHO, [LOCAL_SPACE_TAG, id]);
147
148
  }
148
149
 
@@ -179,6 +180,35 @@ export class DXN {
179
180
  this.#parts = parts;
180
181
  }
181
182
 
183
+ toString(): DXN.String {
184
+ return `dxn:${this.#kind}:${this.#parts.join(':')}` as DXN.String;
185
+ }
186
+
187
+ toJSON(): string {
188
+ return this.toString();
189
+ }
190
+
191
+ /**
192
+ * Used by Node.js to get textual representation of this object when it's printed with a `console.log` statement.
193
+ */
194
+ [inspectCustom](depth: number, options: InspectOptionsStylized, inspectFn: typeof inspect): string {
195
+ const printControlCode = (code: number) => {
196
+ return `\x1b[${code}m`;
197
+ };
198
+
199
+ return (
200
+ printControlCode(inspectFn.colors.blueBright![0]) + this.toString() + printControlCode(inspectFn.colors.reset![0])
201
+ );
202
+ }
203
+
204
+ get [devtoolsFormatter](): DevtoolsFormatter {
205
+ return {
206
+ header: () => {
207
+ return ['span', { style: 'font-weight: bold;' }, this.toString()];
208
+ },
209
+ };
210
+ }
211
+
182
212
  get parts() {
183
213
  return this.#parts;
184
214
  }
@@ -204,6 +234,7 @@ export class DXN {
204
234
 
205
235
  const [type, version] = this.#parts;
206
236
  return {
237
+ // TODO(wittjosiah): Should be `typename` for consistency.
207
238
  type,
208
239
  version: version as string | undefined,
209
240
  };
@@ -238,31 +269,6 @@ export class DXN {
238
269
  objectId: objectId as string | undefined,
239
270
  };
240
271
  }
241
-
242
- toString(): DXN.String {
243
- return `dxn:${this.#kind}:${this.#parts.join(':')}` as DXN.String;
244
- }
245
-
246
- /**
247
- * Used by Node.js to get textual representation of this object when it's printed with a `console.log` statement.
248
- */
249
- [inspectCustom](depth: number, options: InspectOptionsStylized, inspectFn: typeof inspect): string {
250
- const printControlCode = (code: number) => {
251
- return `\x1b[${code}m`;
252
- };
253
-
254
- return (
255
- printControlCode(inspectFn.colors.blueBright![0]) + this.toString() + printControlCode(inspectFn.colors.reset![0])
256
- );
257
- }
258
-
259
- get [devtoolsFormatter](): DevtoolsFormatter {
260
- return {
261
- header: () => {
262
- return ['span', { style: 'font-weight: bold;' }, this.toString()];
263
- },
264
- };
265
- }
266
272
  }
267
273
 
268
274
  // TODO(dmaretskyi): Fluent API:
package/src/index.ts CHANGED
@@ -7,4 +7,4 @@ export * from './identity-did';
7
7
  export * from './object-id';
8
8
  export * from './public-key';
9
9
  export * from './space-id';
10
- export * from './types';
10
+ export type * from './types';
@@ -4,7 +4,7 @@
4
4
 
5
5
  export const randomBytes = (length: number) => {
6
6
  // globalThis.crypto is not available in Node.js when running in vitest even though the documentation says it should be.
7
- // eslint-disable-next-line @typescript-eslint/no-var-requires
7
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
8
8
  const webCrypto = globalThis.crypto ?? require('node:crypto').webcrypto;
9
9
 
10
10
  const bytes = new Uint8Array(length);