@dxos/keys 0.8.3 → 0.8.4-main.1f223c7

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.
@@ -44,9 +44,9 @@ var init_inject_globals = __esm({
44
44
  }
45
45
  });
46
46
 
47
- // node_modules/.pnpm/base32-decode@1.0.0/node_modules/base32-decode/index.js
47
+ // ../../../node_modules/.pnpm/base32-decode@1.0.0/node_modules/base32-decode/index.js
48
48
  var require_base32_decode = __commonJS({
49
- "node_modules/.pnpm/base32-decode@1.0.0/node_modules/base32-decode/index.js"(exports, module) {
49
+ "../../../node_modules/.pnpm/base32-decode@1.0.0/node_modules/base32-decode/index.js"(exports, module) {
50
50
  init_inject_globals();
51
51
  var RFC46482 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
52
52
  var RFC4648_HEX2 = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
@@ -95,21 +95,21 @@ var require_base32_decode = __commonJS({
95
95
  }
96
96
  });
97
97
 
98
- // packages/common/keys/src/index.ts
98
+ // src/index.ts
99
99
  init_inject_globals();
100
100
 
101
- // packages/common/keys/src/dxn.ts
101
+ // src/dxn.ts
102
102
  init_inject_globals();
103
103
  import { Schema as Schema3 } from "effect";
104
104
  import { devtoolsFormatter, inspectCustom } from "@dxos/debug";
105
- import { invariant as invariant2 } from "@dxos/invariant";
105
+ import { assertArgument, invariant as invariant2 } from "@dxos/invariant";
106
106
 
107
- // packages/common/keys/src/object-id.ts
107
+ // src/object-id.ts
108
108
  init_inject_globals();
109
109
  import { Schema } from "effect";
110
110
  import { ulid } from "ulidx";
111
111
  var ObjectIdSchema = Schema.String.pipe(Schema.pattern(/^[0-7][0-9A-HJKMNP-TV-Z]{25}$/i)).annotations({
112
- description: "a Universally Unique Lexicographically Sortable Identifier",
112
+ description: "A Universally Unique Lexicographically Sortable Identifier",
113
113
  pattern: "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
114
114
  });
115
115
  var ObjectId = class extends ObjectIdSchema {
@@ -117,7 +117,7 @@ var ObjectId = class extends ObjectIdSchema {
117
117
  try {
118
118
  Schema.decodeSync(ObjectId)(id);
119
119
  return true;
120
- } catch (err) {
120
+ } catch {
121
121
  return false;
122
122
  }
123
123
  }
@@ -126,14 +126,14 @@ var ObjectId = class extends ObjectIdSchema {
126
126
  }
127
127
  };
128
128
 
129
- // packages/common/keys/src/space-id.ts
129
+ // src/space-id.ts
130
130
  init_inject_globals();
131
131
  var import_base32_decode = __toESM(require_base32_decode(), 1);
132
132
 
133
- // node_modules/.pnpm/base32-encode@2.0.0/node_modules/base32-encode/index.js
133
+ // ../../../node_modules/.pnpm/base32-encode@2.0.0/node_modules/base32-encode/index.js
134
134
  init_inject_globals();
135
135
 
136
- // node_modules/.pnpm/to-data-view@2.0.0/node_modules/to-data-view/index.js
136
+ // ../../../node_modules/.pnpm/to-data-view@2.0.0/node_modules/to-data-view/index.js
137
137
  init_inject_globals();
138
138
  function toDataView(data) {
139
139
  if (data instanceof Int8Array || data instanceof Uint8Array || data instanceof Uint8ClampedArray) {
@@ -145,7 +145,7 @@ function toDataView(data) {
145
145
  throw new TypeError("Expected `data` to be an ArrayBuffer, Buffer, Int8Array, Uint8Array or Uint8ClampedArray");
146
146
  }
147
147
 
148
- // node_modules/.pnpm/base32-encode@2.0.0/node_modules/base32-encode/index.js
148
+ // ../../../node_modules/.pnpm/base32-encode@2.0.0/node_modules/base32-encode/index.js
149
149
  var RFC4648 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
150
150
  var RFC4648_HEX = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
151
151
  var CROCKFORD = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
@@ -193,11 +193,11 @@ function base32Encode(data, variant, options) {
193
193
  return output;
194
194
  }
195
195
 
196
- // packages/common/keys/src/space-id.ts
196
+ // src/space-id.ts
197
197
  import { Schema as Schema2 } from "effect";
198
198
  import { invariant } from "@dxos/invariant";
199
199
 
200
- // packages/common/keys/src/random-bytes.ts
200
+ // src/random-bytes.ts
201
201
  init_inject_globals();
202
202
  var randomBytes = (length) => {
203
203
  const webCrypto = globalThis.crypto ?? __require("@dxos/node-std/crypto").webcrypto;
@@ -206,122 +206,144 @@ var randomBytes = (length) => {
206
206
  return bytes;
207
207
  };
208
208
 
209
- // packages/common/keys/src/space-id.ts
210
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/common/keys/src/space-id.ts";
209
+ // src/space-id.ts
210
+ function _define_property(obj, key, value) {
211
+ if (key in obj) {
212
+ Object.defineProperty(obj, key, {
213
+ value,
214
+ enumerable: true,
215
+ configurable: true,
216
+ writable: true
217
+ });
218
+ } else {
219
+ obj[key] = value;
220
+ }
221
+ return obj;
222
+ }
223
+ var _Schema_String_pipe;
224
+ var _class;
225
+ var __dxlog_file = "/__w/dxos/dxos/packages/common/keys/src/space-id.ts";
211
226
  var MULTIBASE_PREFIX = "B";
212
227
  var ENCODED_LENGTH = 33;
213
228
  var isValid = (value) => {
214
229
  return typeof value === "string" && value.startsWith(MULTIBASE_PREFIX) && value.length === ENCODED_LENGTH;
215
230
  };
216
- var SpaceId = class extends Schema2.String.pipe(Schema2.filter(isValid)) {
217
- static {
218
- this.byteLength = 20;
219
- }
220
- static {
221
- this.encode = (value) => {
222
- invariant(value instanceof Uint8Array, "Invalid type", {
223
- F: __dxlog_file,
224
- L: 43,
225
- S: this,
226
- A: [
227
- "value instanceof Uint8Array",
228
- "'Invalid type'"
229
- ]
230
- });
231
- invariant(value.length === SpaceId.byteLength, "Invalid length", {
232
- F: __dxlog_file,
233
- L: 44,
234
- S: this,
235
- A: [
236
- "value.length === SpaceId.byteLength",
237
- "'Invalid length'"
238
- ]
239
- });
240
- return MULTIBASE_PREFIX + base32Encode(value, "RFC4648");
241
- };
231
+ var SpaceId = (_class = class extends (_Schema_String_pipe = Schema2.String.pipe(Schema2.filter(isValid))) {
232
+ }, _define_property(_class, "byteLength", 20), _define_property(_class, "encode", (value) => {
233
+ invariant(value instanceof Uint8Array, "Invalid type", {
234
+ F: __dxlog_file,
235
+ L: 43,
236
+ S: _class,
237
+ A: [
238
+ "value instanceof Uint8Array",
239
+ "'Invalid type'"
240
+ ]
241
+ });
242
+ invariant(value.length === SpaceId.byteLength, "Invalid length", {
243
+ F: __dxlog_file,
244
+ L: 44,
245
+ S: _class,
246
+ A: [
247
+ "value.length === SpaceId.byteLength",
248
+ "'Invalid length'"
249
+ ]
250
+ });
251
+ return MULTIBASE_PREFIX + base32Encode(value, "RFC4648");
252
+ }), _define_property(_class, "decode", (value) => {
253
+ invariant(value.startsWith(MULTIBASE_PREFIX), "Invalid multibase32 encoding", {
254
+ F: __dxlog_file,
255
+ L: 49,
256
+ S: _class,
257
+ A: [
258
+ "value.startsWith(MULTIBASE_PREFIX)",
259
+ "'Invalid multibase32 encoding'"
260
+ ]
261
+ });
262
+ return new Uint8Array((0, import_base32_decode.default)(value.slice(1), "RFC4648"));
263
+ }), _define_property(_class, "isValid", isValid), _define_property(_class, "random", () => {
264
+ return SpaceId.encode(randomBytes(SpaceId.byteLength));
265
+ }), _class);
266
+
267
+ // src/dxn.ts
268
+ function _check_private_redeclaration(obj, privateCollection) {
269
+ if (privateCollection.has(obj)) {
270
+ throw new TypeError("Cannot initialize the same private elements twice on an object");
242
271
  }
243
- static {
244
- this.decode = (value) => {
245
- invariant(value.startsWith(MULTIBASE_PREFIX), "Invalid multibase32 encoding", {
246
- F: __dxlog_file,
247
- L: 49,
248
- S: this,
249
- A: [
250
- "value.startsWith(MULTIBASE_PREFIX)",
251
- "'Invalid multibase32 encoding'"
252
- ]
253
- });
254
- return new Uint8Array((0, import_base32_decode.default)(value.slice(1), "RFC4648"));
255
- };
272
+ }
273
+ function _class_apply_descriptor_get(receiver, descriptor) {
274
+ if (descriptor.get) {
275
+ return descriptor.get.call(receiver);
276
+ }
277
+ return descriptor.value;
278
+ }
279
+ function _class_apply_descriptor_set(receiver, descriptor, value) {
280
+ if (descriptor.set) {
281
+ descriptor.set.call(receiver, value);
282
+ } else {
283
+ if (!descriptor.writable) {
284
+ throw new TypeError("attempted to set read only private field");
285
+ }
286
+ descriptor.value = value;
256
287
  }
257
- static {
258
- this.isValid = isValid;
288
+ }
289
+ function _class_extract_field_descriptor(receiver, privateMap, action) {
290
+ if (!privateMap.has(receiver)) {
291
+ throw new TypeError("attempted to " + action + " private field on non-instance");
259
292
  }
260
- static {
261
- this.random = () => {
262
- return SpaceId.encode(randomBytes(SpaceId.byteLength));
263
- };
293
+ return privateMap.get(receiver);
294
+ }
295
+ function _class_private_field_get(receiver, privateMap) {
296
+ var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
297
+ return _class_apply_descriptor_get(receiver, descriptor);
298
+ }
299
+ function _class_private_field_init(obj, privateMap, value) {
300
+ _check_private_redeclaration(obj, privateMap);
301
+ privateMap.set(obj, value);
302
+ }
303
+ function _class_private_field_set(receiver, privateMap, value) {
304
+ var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
305
+ _class_apply_descriptor_set(receiver, descriptor, value);
306
+ return value;
307
+ }
308
+ function _define_property2(obj, key, value) {
309
+ if (key in obj) {
310
+ Object.defineProperty(obj, key, {
311
+ value,
312
+ enumerable: true,
313
+ configurable: true,
314
+ writable: true
315
+ });
316
+ } else {
317
+ obj[key] = value;
264
318
  }
265
- };
266
-
267
- // packages/common/keys/src/dxn.ts
268
- var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/common/keys/src/dxn.ts";
319
+ return obj;
320
+ }
321
+ var __dxlog_file2 = "/__w/dxos/dxos/packages/common/keys/src/dxn.ts";
269
322
  var LOCAL_SPACE_TAG = "@";
323
+ var DXN_ECHO_REGEXP = /@(dxn:[a-zA-Z0-p:@]+)/;
270
324
  var QueueSubspaceTags = Object.freeze({
271
325
  DATA: "data",
272
326
  TRACE: "trace"
273
327
  });
328
+ var _kind = /* @__PURE__ */ new WeakMap();
329
+ var _parts = /* @__PURE__ */ new WeakMap();
330
+ var _inspectCustom = inspectCustom;
331
+ var _devtoolsFormatter = devtoolsFormatter;
274
332
  var DXN = class _DXN {
275
- static {
276
- // TODO(dmaretskyi): Should this be a transformation into the DXN type?
277
- this.Schema = Schema3.NonEmptyString.pipe(
278
- Schema3.pattern(/^dxn:([^:]+):(?:[^:]+:?)+[^:]$/),
279
- // TODO(dmaretskyi): To set the format we need to move the annotation IDs out of the echo-schema package.
280
- // FormatAnnotation.set(FormatEnum.DXN),
281
- Schema3.annotations({
282
- title: "DXN",
283
- description: "DXN URI",
284
- examples: [
285
- "dxn:type:example.com/type/MyType",
286
- "dxn:echo:@:01J00J9B45YHYSGZQTQMSKMGJ6"
287
- ]
288
- })
289
- );
290
- }
291
333
  static hash(dxn) {
292
334
  return dxn.toString();
293
335
  }
294
- static {
295
- /**
296
- * Kind constants.
297
- */
298
- this.kind = Object.freeze({
299
- /**
300
- * dxn:type:<type name>[:<version>]
301
- */
302
- TYPE: "type",
303
- /**
304
- * dxn:echo:<space id>:<echo id>
305
- * dxn:echo:@:<echo id>
306
- */
307
- // TODO(burdon): Rename to OBJECT? (BREAKING CHANGE).
308
- // TODO(burdon): Add separate Kind for space.
309
- ECHO: "echo",
310
- /**
311
- * The subspace tag enables us to partition queues by usage within the context of a space.
312
- * dxn:queue:<subspace_tag>:<space_id>:<queue_id>[:object_id]
313
- * dxn:queue:data:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
314
- * dxn:queue:trace:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
315
- */
316
- QUEUE: "queue"
317
- });
318
- }
319
- get kind() {
320
- return this.#kind;
321
- }
336
+ /**
337
+ * Exactly equals.
338
+ */
322
339
  static equals(a, b) {
323
340
  return a.kind === b.kind && a.parts.length === b.parts.length && a.parts.every((part, i) => part === b.parts[i]);
324
341
  }
342
+ static equalsEchoId(a, b) {
343
+ const a1 = a.asEchoDXN();
344
+ const b1 = b.asEchoDXN();
345
+ return !!a1 && !!b1 && a1.echoId === b1.echoId;
346
+ }
325
347
  // TODO(burdon): Rename isValid.
326
348
  static isDXNString(dxn) {
327
349
  return dxn.startsWith("dxn:");
@@ -345,7 +367,7 @@ var DXN = class _DXN {
345
367
  static tryParse(dxn) {
346
368
  try {
347
369
  return _DXN.parse(dxn);
348
- } catch (error) {
370
+ } catch {
349
371
  return void 0;
350
372
  }
351
373
  }
@@ -368,42 +390,30 @@ var DXN = class _DXN {
368
390
  ]);
369
391
  }
370
392
  /**
393
+ * @example `dxn:echo:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6`
394
+ */
395
+ static fromSpaceAndObjectId(spaceId, objectId) {
396
+ assertArgument(SpaceId.isValid(spaceId), `Invalid space ID: ${spaceId}`);
397
+ assertArgument(ObjectId.isValid(objectId), "objectId", `Invalid object ID: ${objectId}`);
398
+ return new _DXN(_DXN.kind.ECHO, [
399
+ spaceId,
400
+ objectId
401
+ ]);
402
+ }
403
+ /**
371
404
  * @example `dxn:echo:@:01J00J9B45YHYSGZQTQMSKMGJ6`
372
405
  */
373
406
  static fromLocalObjectId(id) {
407
+ assertArgument(ObjectId.isValid(id), "id", `Invalid object ID: ${id}`);
374
408
  return new _DXN(_DXN.kind.ECHO, [
375
409
  LOCAL_SPACE_TAG,
376
410
  id
377
411
  ]);
378
412
  }
379
413
  static fromQueue(subspaceTag, spaceId, queueId, objectId) {
380
- invariant2(SpaceId.isValid(spaceId), void 0, {
381
- F: __dxlog_file2,
382
- L: 150,
383
- S: this,
384
- A: [
385
- "SpaceId.isValid(spaceId)",
386
- ""
387
- ]
388
- });
389
- invariant2(ObjectId.isValid(queueId), void 0, {
390
- F: __dxlog_file2,
391
- L: 151,
392
- S: this,
393
- A: [
394
- "ObjectId.isValid(queueId)",
395
- ""
396
- ]
397
- });
398
- invariant2(!objectId || ObjectId.isValid(objectId), void 0, {
399
- F: __dxlog_file2,
400
- L: 152,
401
- S: this,
402
- A: [
403
- "!objectId || ObjectId.isValid(objectId)",
404
- ""
405
- ]
406
- });
414
+ assertArgument(SpaceId.isValid(spaceId), `Invalid space ID: ${spaceId}`);
415
+ assertArgument(ObjectId.isValid(queueId), "queueId", `Invalid queue ID: ${queueId}`);
416
+ assertArgument(!objectId || ObjectId.isValid(objectId), "objectId", `Invalid object ID: ${objectId}`);
407
417
  return new _DXN(_DXN.kind.QUEUE, [
408
418
  subspaceTag,
409
419
  spaceId,
@@ -413,70 +423,69 @@ var DXN = class _DXN {
413
423
  ] : []
414
424
  ]);
415
425
  }
416
- #kind;
417
- #parts;
418
- constructor(kind, parts) {
419
- invariant2(parts.length > 0, void 0, {
420
- F: __dxlog_file2,
421
- L: 161,
422
- S: this,
423
- A: [
424
- "parts.length > 0",
425
- ""
426
- ]
427
- });
428
- invariant2(parts.every((part) => typeof part === "string" && part.length > 0 && part.indexOf(":") === -1), void 0, {
429
- F: __dxlog_file2,
430
- L: 162,
431
- S: this,
432
- A: [
433
- "parts.every((part) => typeof part === 'string' && part.length > 0 && part.indexOf(':') === -1)",
434
- ""
435
- ]
436
- });
437
- switch (kind) {
438
- case _DXN.kind.TYPE:
439
- if (parts.length > 2) {
440
- throw new Error('Invalid "type" DXN');
441
- }
442
- break;
443
- case _DXN.kind.ECHO:
444
- if (parts.length !== 2) {
445
- throw new Error('Invalid "echo" DXN');
446
- }
447
- break;
448
- }
449
- this.#kind = kind;
450
- this.#parts = parts;
426
+ toString() {
427
+ return `dxn:${_class_private_field_get(this, _kind)}:${_class_private_field_get(this, _parts).join(":")}`;
428
+ }
429
+ toJSON() {
430
+ return this.toString();
431
+ }
432
+ /**
433
+ * Used by Node.js to get textual representation of this object when it's printed with a `console.log` statement.
434
+ */
435
+ [_inspectCustom](depth, options, inspectFn) {
436
+ const printControlCode = (code) => {
437
+ return `\x1B[${code}m`;
438
+ };
439
+ return printControlCode(inspectFn.colors.blueBright[0]) + this.toString() + printControlCode(inspectFn.colors.reset[0]);
440
+ }
441
+ get [_devtoolsFormatter]() {
442
+ return {
443
+ header: () => {
444
+ return [
445
+ "span",
446
+ {
447
+ style: "font-weight: bold;"
448
+ },
449
+ this.toString()
450
+ ];
451
+ }
452
+ };
453
+ }
454
+ get kind() {
455
+ return _class_private_field_get(this, _kind);
451
456
  }
452
457
  get parts() {
453
- return this.#parts;
458
+ return _class_private_field_get(this, _parts);
454
459
  }
455
460
  // TODO(burdon): Should getters fail?
456
461
  get typename() {
457
- invariant2(this.#kind === _DXN.kind.TYPE, void 0, {
462
+ invariant2(_class_private_field_get(this, _kind) === _DXN.kind.TYPE, void 0, {
458
463
  F: __dxlog_file2,
459
- L: 188,
464
+ L: 250,
460
465
  S: this,
461
466
  A: [
462
467
  "this.#kind === DXN.kind.TYPE",
463
468
  ""
464
469
  ]
465
470
  });
466
- return this.#parts[0];
471
+ return _class_private_field_get(this, _parts)[0];
472
+ }
473
+ equals(other) {
474
+ return _DXN.equals(this, other);
467
475
  }
468
476
  hasTypenameOf(typename) {
469
- return this.#kind === _DXN.kind.TYPE && this.#parts.length === 1 && this.#parts[0] === typename;
477
+ return _class_private_field_get(this, _kind) === _DXN.kind.TYPE && _class_private_field_get(this, _parts).length === 1 && _class_private_field_get(this, _parts)[0] === typename;
470
478
  }
471
479
  isLocalObjectId() {
472
- return this.#kind === _DXN.kind.ECHO && this.#parts[0] === LOCAL_SPACE_TAG && this.#parts.length === 2;
480
+ return _class_private_field_get(this, _kind) === _DXN.kind.ECHO && _class_private_field_get(this, _parts)[0] === LOCAL_SPACE_TAG && _class_private_field_get(this, _parts).length === 2;
473
481
  }
474
482
  asTypeDXN() {
475
483
  if (this.kind !== _DXN.kind.TYPE) {
476
484
  return void 0;
477
485
  }
478
- const [type, version] = this.#parts;
486
+ const [type, version] = _class_private_field_get(this, _parts);
479
487
  return {
488
+ // TODO(wittjosiah): Should be `typename` for consistency.
480
489
  type,
481
490
  version
482
491
  };
@@ -485,9 +494,10 @@ var DXN = class _DXN {
485
494
  if (this.kind !== _DXN.kind.ECHO) {
486
495
  return void 0;
487
496
  }
488
- const [spaceId, echoId] = this.#parts;
497
+ const [spaceId, echoId] = _class_private_field_get(this, _parts);
489
498
  return {
490
499
  spaceId: spaceId === LOCAL_SPACE_TAG ? void 0 : spaceId,
500
+ // TODO(burdon): objectId.
491
501
  echoId
492
502
  };
493
503
  }
@@ -495,7 +505,7 @@ var DXN = class _DXN {
495
505
  if (this.kind !== _DXN.kind.QUEUE) {
496
506
  return void 0;
497
507
  }
498
- const [subspaceTag, spaceId, queueId, objectId] = this.#parts;
508
+ const [subspaceTag, spaceId, queueId, objectId] = _class_private_field_get(this, _parts);
499
509
  if (typeof queueId !== "string") {
500
510
  return void 0;
501
511
  }
@@ -506,38 +516,81 @@ var DXN = class _DXN {
506
516
  objectId
507
517
  };
508
518
  }
509
- toString() {
510
- return `dxn:${this.#kind}:${this.#parts.join(":")}`;
511
- }
512
519
  /**
513
- * Used by Node.js to get textual representation of this object when it's printed with a `console.log` statement.
520
+ * Produces a new DXN with the given parts appended.
514
521
  */
515
- [inspectCustom](depth, options, inspectFn) {
516
- const printControlCode = (code) => {
517
- return `\x1B[${code}m`;
518
- };
519
- return printControlCode(inspectFn.colors.blueBright[0]) + this.toString() + printControlCode(inspectFn.colors.reset[0]);
522
+ extend(parts) {
523
+ return new _DXN(_class_private_field_get(this, _kind), [
524
+ ..._class_private_field_get(this, _parts),
525
+ ...parts
526
+ ]);
520
527
  }
521
- get [devtoolsFormatter]() {
522
- return {
523
- header: () => {
524
- return [
525
- "span",
526
- {
527
- style: "font-weight: bold;"
528
- },
529
- this.toString()
530
- ];
531
- }
532
- };
528
+ constructor(kind, parts) {
529
+ _class_private_field_init(this, _kind, {
530
+ writable: true,
531
+ value: void 0
532
+ });
533
+ _class_private_field_init(this, _parts, {
534
+ writable: true,
535
+ value: void 0
536
+ });
537
+ assertArgument(parts.length > 0, "parts", `Invalid DXN: ${parts}`);
538
+ assertArgument(parts.every((part) => typeof part === "string" && part.length > 0 && part.indexOf(":") === -1), "parts", `Invalid DXN: ${parts}`);
539
+ switch (kind) {
540
+ case _DXN.kind.TYPE:
541
+ if (parts.length > 2) {
542
+ throw new Error("Invalid DXN.kind.TYPE");
543
+ }
544
+ break;
545
+ case _DXN.kind.ECHO:
546
+ if (parts.length !== 2) {
547
+ throw new Error("Invalid DXN.kind.ECHO");
548
+ }
549
+ break;
550
+ }
551
+ _class_private_field_set(this, _kind, kind);
552
+ _class_private_field_set(this, _parts, parts);
533
553
  }
534
554
  };
555
+ _define_property2(DXN, "Schema", Schema3.NonEmptyString.pipe(
556
+ Schema3.pattern(/^dxn:([^:]+):(?:[^:]+:?)+[^:]$/),
557
+ // TODO(dmaretskyi): To set the format we need to move the annotation IDs out of the echo-schema package.
558
+ // FormatAnnotation.set(FormatEnum.DXN),
559
+ Schema3.annotations({
560
+ title: "DXN",
561
+ description: "DXN URI",
562
+ examples: [
563
+ "dxn:type:example.com/type/MyType",
564
+ "dxn:echo:@:01J00J9B45YHYSGZQTQMSKMGJ6"
565
+ ]
566
+ })
567
+ ));
568
+ _define_property2(DXN, "kind", Object.freeze({
569
+ /**
570
+ * dxn:type:<type_name>[:<version>]
571
+ */
572
+ TYPE: "type",
573
+ /**
574
+ * dxn:echo:<space_id>:<echo_id>
575
+ * dxn:echo:@:<echo_id>
576
+ */
577
+ // TODO(burdon): Rename to OBJECT? (BREAKING CHANGE to update "echo").
578
+ // TODO(burdon): Add separate Kind for space?
579
+ ECHO: "echo",
580
+ /**
581
+ * The subspace tag enables us to partition queues by usage within the context of a space.
582
+ * dxn:queue:<subspace_tag>:<space_id>:<queue_id>[:object_id]
583
+ * dxn:queue:data:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
584
+ * dxn:queue:trace:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
585
+ */
586
+ QUEUE: "queue"
587
+ }));
535
588
 
536
- // packages/common/keys/src/identity-did.ts
589
+ // src/identity-did.ts
537
590
  init_inject_globals();
538
591
  var import_base32_decode2 = __toESM(require_base32_decode(), 1);
539
592
  import { invariant as invariant3 } from "@dxos/invariant";
540
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/common/keys/src/identity-did.ts";
593
+ var __dxlog_file3 = "/__w/dxos/dxos/packages/common/keys/src/identity-did.ts";
541
594
  var IdentityDid = Object.freeze({
542
595
  byteLength: 20,
543
596
  encode: (value) => {
@@ -584,19 +637,32 @@ var MULTIBASE_PREFIX2 = "B";
584
637
  var DID_PREFIX = "did:halo:";
585
638
  var ENCODED_LENGTH2 = 42;
586
639
 
587
- // packages/common/keys/src/public-key.ts
640
+ // src/public-key.ts
588
641
  init_inject_globals();
589
642
  var import_base32_decode3 = __toESM(require_base32_decode(), 1);
590
643
  import { devtoolsFormatter as devtoolsFormatter2, equalsSymbol, inspectCustom as inspectCustom2, truncateKey } from "@dxos/debug";
591
644
  import { invariant as invariant4 } from "@dxos/invariant";
592
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/common/keys/src/public-key.ts";
645
+ function _define_property3(obj, key, value) {
646
+ if (key in obj) {
647
+ Object.defineProperty(obj, key, {
648
+ value,
649
+ enumerable: true,
650
+ configurable: true,
651
+ writable: true
652
+ });
653
+ } else {
654
+ obj[key] = value;
655
+ }
656
+ return obj;
657
+ }
658
+ var __dxlog_file4 = "/__w/dxos/dxos/packages/common/keys/src/public-key.ts";
593
659
  var PUBLIC_KEY_LENGTH = 32;
594
660
  var SECRET_KEY_LENGTH = 64;
595
661
  var isLikeArrayBuffer = (value) => typeof value === "object" && value !== null && Object.getPrototypeOf(value).constructor.name === "ArrayBuffer";
662
+ var _inspectCustom2 = inspectCustom2;
663
+ var _devtoolsFormatter2 = devtoolsFormatter2;
664
+ var _equalsSymbol = equalsSymbol;
596
665
  var PublicKey = class _PublicKey {
597
- static {
598
- this.ZERO = _PublicKey.from("00".repeat(PUBLIC_KEY_LENGTH));
599
- }
600
666
  /**
601
667
  * Creates new instance of PublicKey automatically determining the input format.
602
668
  * @param source A Buffer, or Uint8Array, or hex encoded string, or something with an `asUint8Array` method on it
@@ -605,7 +671,7 @@ var PublicKey = class _PublicKey {
605
671
  static from(source) {
606
672
  invariant4(source, void 0, {
607
673
  F: __dxlog_file4,
608
- L: 49,
674
+ L: 50,
609
675
  S: this,
610
676
  A: [
611
677
  "source",
@@ -697,7 +763,7 @@ var PublicKey = class _PublicKey {
697
763
  static bufferize(str) {
698
764
  invariant4(typeof str === "string", "Invalid type", {
699
765
  F: __dxlog_file4,
700
- L: 152,
766
+ L: 153,
701
767
  S: this,
702
768
  A: [
703
769
  "typeof str === 'string'",
@@ -720,7 +786,7 @@ var PublicKey = class _PublicKey {
720
786
  }
721
787
  invariant4(key instanceof Buffer2, "Invalid type", {
722
788
  F: __dxlog_file4,
723
- L: 171,
789
+ L: 172,
724
790
  S: this,
725
791
  A: [
726
792
  "key instanceof Buffer",
@@ -739,7 +805,7 @@ var PublicKey = class _PublicKey {
739
805
  static fromMultibase32(encoded) {
740
806
  invariant4(encoded.startsWith("B"), "Invalid multibase32 encoding", {
741
807
  F: __dxlog_file4,
742
- L: 184,
808
+ L: 185,
743
809
  S: this,
744
810
  A: [
745
811
  "encoded.startsWith('B')",
@@ -748,12 +814,6 @@ var PublicKey = class _PublicKey {
748
814
  });
749
815
  return new _PublicKey(new Uint8Array((0, import_base32_decode3.default)(encoded.slice(1), "RFC4648")));
750
816
  }
751
- constructor(_value) {
752
- this._value = _value;
753
- if (!(_value instanceof Uint8Array)) {
754
- throw new TypeError(`Expected Uint8Array, got: ${_value}`);
755
- }
756
- }
757
817
  toString() {
758
818
  return this.toHex();
759
819
  }
@@ -787,7 +847,7 @@ var PublicKey = class _PublicKey {
787
847
  /**
788
848
  * Used by Node.js to get textual representation of this object when it's printed with a `console.log` statement.
789
849
  */
790
- [inspectCustom2](depth, options, inspectFn) {
850
+ [_inspectCustom2](depth, options, inspectFn) {
791
851
  if (!options.colors || typeof process.stdout.hasColors !== "function" || !process.stdout.hasColors()) {
792
852
  return `<PublicKey ${this.truncate()}>`;
793
853
  }
@@ -812,7 +872,7 @@ var PublicKey = class _PublicKey {
812
872
  const color = colors[this.getInsecureHash(colors.length)];
813
873
  return `PublicKey(${printControlCode(inspectFn.colors[color][0])}${this.truncate()}${printControlCode(inspectFn.colors.reset[0])})`;
814
874
  }
815
- get [devtoolsFormatter2]() {
875
+ get [_devtoolsFormatter2]() {
816
876
  return {
817
877
  header: () => {
818
878
  const colors = [
@@ -865,19 +925,28 @@ var PublicKey = class _PublicKey {
865
925
  }
866
926
  let equal = true;
867
927
  for (let i = 0; i < this._value.length; i++) {
868
- equal &&= this._value[i] === otherConverted._value[i];
928
+ equal && (equal = this._value[i] === otherConverted._value[i]);
869
929
  }
870
930
  return equal;
871
931
  }
872
- [equalsSymbol](other) {
932
+ [_equalsSymbol](other) {
873
933
  if (!_PublicKey.isPublicKey(other)) {
874
934
  return false;
875
935
  }
876
936
  return this.equals(other);
877
937
  }
938
+ constructor(_value) {
939
+ _define_property3(this, "_value", void 0);
940
+ this._value = _value;
941
+ if (!(_value instanceof Uint8Array)) {
942
+ throw new TypeError(`Expected Uint8Array, got: ${_value}`);
943
+ }
944
+ }
878
945
  };
946
+ _define_property3(PublicKey, "ZERO", PublicKey.from("00".repeat(PUBLIC_KEY_LENGTH)));
879
947
  export {
880
948
  DXN,
949
+ DXN_ECHO_REGEXP,
881
950
  IdentityDid,
882
951
  LOCAL_SPACE_TAG,
883
952
  ObjectId,