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

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.
@@ -31,9 +31,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
31
31
  mod
32
32
  ));
33
33
 
34
- // node_modules/.pnpm/base32-decode@1.0.0/node_modules/base32-decode/index.js
34
+ // ../../../node_modules/.pnpm/base32-decode@1.0.0/node_modules/base32-decode/index.js
35
35
  var require_base32_decode = __commonJS({
36
- "node_modules/.pnpm/base32-decode@1.0.0/node_modules/base32-decode/index.js"(exports, module) {
36
+ "../../../node_modules/.pnpm/base32-decode@1.0.0/node_modules/base32-decode/index.js"(exports, module) {
37
37
  var RFC46482 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
38
38
  var RFC4648_HEX2 = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
39
39
  var CROCKFORD2 = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
@@ -81,16 +81,16 @@ var require_base32_decode = __commonJS({
81
81
  }
82
82
  });
83
83
 
84
- // packages/common/keys/src/dxn.ts
84
+ // src/dxn.ts
85
85
  import { Schema as Schema3 } from "effect";
86
86
  import { devtoolsFormatter, inspectCustom } from "@dxos/debug";
87
- import { invariant as invariant2 } from "@dxos/invariant";
87
+ import { assertArgument, invariant as invariant2 } from "@dxos/invariant";
88
88
 
89
- // packages/common/keys/src/object-id.ts
89
+ // src/object-id.ts
90
90
  import { Schema } from "effect";
91
91
  import { ulid } from "ulidx";
92
92
  var ObjectIdSchema = Schema.String.pipe(Schema.pattern(/^[0-7][0-9A-HJKMNP-TV-Z]{25}$/i)).annotations({
93
- description: "a Universally Unique Lexicographically Sortable Identifier",
93
+ description: "A Universally Unique Lexicographically Sortable Identifier",
94
94
  pattern: "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
95
95
  });
96
96
  var ObjectId = class extends ObjectIdSchema {
@@ -98,7 +98,7 @@ var ObjectId = class extends ObjectIdSchema {
98
98
  try {
99
99
  Schema.decodeSync(ObjectId)(id);
100
100
  return true;
101
- } catch (err) {
101
+ } catch {
102
102
  return false;
103
103
  }
104
104
  }
@@ -107,10 +107,10 @@ var ObjectId = class extends ObjectIdSchema {
107
107
  }
108
108
  };
109
109
 
110
- // packages/common/keys/src/space-id.ts
110
+ // src/space-id.ts
111
111
  var import_base32_decode = __toESM(require_base32_decode(), 1);
112
112
 
113
- // node_modules/.pnpm/to-data-view@2.0.0/node_modules/to-data-view/index.js
113
+ // ../../../node_modules/.pnpm/to-data-view@2.0.0/node_modules/to-data-view/index.js
114
114
  function toDataView(data) {
115
115
  if (data instanceof Int8Array || data instanceof Uint8Array || data instanceof Uint8ClampedArray) {
116
116
  return new DataView(data.buffer, data.byteOffset, data.byteLength);
@@ -121,7 +121,7 @@ function toDataView(data) {
121
121
  throw new TypeError("Expected `data` to be an ArrayBuffer, Buffer, Int8Array, Uint8Array or Uint8ClampedArray");
122
122
  }
123
123
 
124
- // node_modules/.pnpm/base32-encode@2.0.0/node_modules/base32-encode/index.js
124
+ // ../../../node_modules/.pnpm/base32-encode@2.0.0/node_modules/base32-encode/index.js
125
125
  var RFC4648 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
126
126
  var RFC4648_HEX = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
127
127
  var CROCKFORD = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
@@ -169,11 +169,11 @@ function base32Encode(data, variant, options) {
169
169
  return output;
170
170
  }
171
171
 
172
- // packages/common/keys/src/space-id.ts
172
+ // src/space-id.ts
173
173
  import { Schema as Schema2 } from "effect";
174
174
  import { invariant } from "@dxos/invariant";
175
175
 
176
- // packages/common/keys/src/random-bytes.ts
176
+ // src/random-bytes.ts
177
177
  var randomBytes = (length) => {
178
178
  const webCrypto = globalThis.crypto ?? __require("node:crypto").webcrypto;
179
179
  const bytes = new Uint8Array(length);
@@ -181,122 +181,144 @@ var randomBytes = (length) => {
181
181
  return bytes;
182
182
  };
183
183
 
184
- // packages/common/keys/src/space-id.ts
185
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/common/keys/src/space-id.ts";
184
+ // src/space-id.ts
185
+ function _define_property(obj, key, value) {
186
+ if (key in obj) {
187
+ Object.defineProperty(obj, key, {
188
+ value,
189
+ enumerable: true,
190
+ configurable: true,
191
+ writable: true
192
+ });
193
+ } else {
194
+ obj[key] = value;
195
+ }
196
+ return obj;
197
+ }
198
+ var _Schema_String_pipe;
199
+ var _class;
200
+ var __dxlog_file = "/__w/dxos/dxos/packages/common/keys/src/space-id.ts";
186
201
  var MULTIBASE_PREFIX = "B";
187
202
  var ENCODED_LENGTH = 33;
188
203
  var isValid = (value) => {
189
204
  return typeof value === "string" && value.startsWith(MULTIBASE_PREFIX) && value.length === ENCODED_LENGTH;
190
205
  };
191
- var SpaceId = class extends Schema2.String.pipe(Schema2.filter(isValid)) {
192
- static {
193
- this.byteLength = 20;
194
- }
195
- static {
196
- this.encode = (value) => {
197
- invariant(value instanceof Uint8Array, "Invalid type", {
198
- F: __dxlog_file,
199
- L: 43,
200
- S: this,
201
- A: [
202
- "value instanceof Uint8Array",
203
- "'Invalid type'"
204
- ]
205
- });
206
- invariant(value.length === SpaceId.byteLength, "Invalid length", {
207
- F: __dxlog_file,
208
- L: 44,
209
- S: this,
210
- A: [
211
- "value.length === SpaceId.byteLength",
212
- "'Invalid length'"
213
- ]
214
- });
215
- return MULTIBASE_PREFIX + base32Encode(value, "RFC4648");
216
- };
206
+ var SpaceId = (_class = class extends (_Schema_String_pipe = Schema2.String.pipe(Schema2.filter(isValid))) {
207
+ }, _define_property(_class, "byteLength", 20), _define_property(_class, "encode", (value) => {
208
+ invariant(value instanceof Uint8Array, "Invalid type", {
209
+ F: __dxlog_file,
210
+ L: 43,
211
+ S: _class,
212
+ A: [
213
+ "value instanceof Uint8Array",
214
+ "'Invalid type'"
215
+ ]
216
+ });
217
+ invariant(value.length === SpaceId.byteLength, "Invalid length", {
218
+ F: __dxlog_file,
219
+ L: 44,
220
+ S: _class,
221
+ A: [
222
+ "value.length === SpaceId.byteLength",
223
+ "'Invalid length'"
224
+ ]
225
+ });
226
+ return MULTIBASE_PREFIX + base32Encode(value, "RFC4648");
227
+ }), _define_property(_class, "decode", (value) => {
228
+ invariant(value.startsWith(MULTIBASE_PREFIX), "Invalid multibase32 encoding", {
229
+ F: __dxlog_file,
230
+ L: 49,
231
+ S: _class,
232
+ A: [
233
+ "value.startsWith(MULTIBASE_PREFIX)",
234
+ "'Invalid multibase32 encoding'"
235
+ ]
236
+ });
237
+ return new Uint8Array((0, import_base32_decode.default)(value.slice(1), "RFC4648"));
238
+ }), _define_property(_class, "isValid", isValid), _define_property(_class, "random", () => {
239
+ return SpaceId.encode(randomBytes(SpaceId.byteLength));
240
+ }), _class);
241
+
242
+ // src/dxn.ts
243
+ function _check_private_redeclaration(obj, privateCollection) {
244
+ if (privateCollection.has(obj)) {
245
+ throw new TypeError("Cannot initialize the same private elements twice on an object");
217
246
  }
218
- static {
219
- this.decode = (value) => {
220
- invariant(value.startsWith(MULTIBASE_PREFIX), "Invalid multibase32 encoding", {
221
- F: __dxlog_file,
222
- L: 49,
223
- S: this,
224
- A: [
225
- "value.startsWith(MULTIBASE_PREFIX)",
226
- "'Invalid multibase32 encoding'"
227
- ]
228
- });
229
- return new Uint8Array((0, import_base32_decode.default)(value.slice(1), "RFC4648"));
230
- };
247
+ }
248
+ function _class_apply_descriptor_get(receiver, descriptor) {
249
+ if (descriptor.get) {
250
+ return descriptor.get.call(receiver);
251
+ }
252
+ return descriptor.value;
253
+ }
254
+ function _class_apply_descriptor_set(receiver, descriptor, value) {
255
+ if (descriptor.set) {
256
+ descriptor.set.call(receiver, value);
257
+ } else {
258
+ if (!descriptor.writable) {
259
+ throw new TypeError("attempted to set read only private field");
260
+ }
261
+ descriptor.value = value;
231
262
  }
232
- static {
233
- this.isValid = isValid;
263
+ }
264
+ function _class_extract_field_descriptor(receiver, privateMap, action) {
265
+ if (!privateMap.has(receiver)) {
266
+ throw new TypeError("attempted to " + action + " private field on non-instance");
234
267
  }
235
- static {
236
- this.random = () => {
237
- return SpaceId.encode(randomBytes(SpaceId.byteLength));
238
- };
268
+ return privateMap.get(receiver);
269
+ }
270
+ function _class_private_field_get(receiver, privateMap) {
271
+ var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
272
+ return _class_apply_descriptor_get(receiver, descriptor);
273
+ }
274
+ function _class_private_field_init(obj, privateMap, value) {
275
+ _check_private_redeclaration(obj, privateMap);
276
+ privateMap.set(obj, value);
277
+ }
278
+ function _class_private_field_set(receiver, privateMap, value) {
279
+ var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
280
+ _class_apply_descriptor_set(receiver, descriptor, value);
281
+ return value;
282
+ }
283
+ function _define_property2(obj, key, value) {
284
+ if (key in obj) {
285
+ Object.defineProperty(obj, key, {
286
+ value,
287
+ enumerable: true,
288
+ configurable: true,
289
+ writable: true
290
+ });
291
+ } else {
292
+ obj[key] = value;
239
293
  }
240
- };
241
-
242
- // packages/common/keys/src/dxn.ts
243
- var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/common/keys/src/dxn.ts";
294
+ return obj;
295
+ }
296
+ var __dxlog_file2 = "/__w/dxos/dxos/packages/common/keys/src/dxn.ts";
244
297
  var LOCAL_SPACE_TAG = "@";
298
+ var DXN_ECHO_REGEXP = /@(dxn:[a-zA-Z0-p:@]+)/;
245
299
  var QueueSubspaceTags = Object.freeze({
246
300
  DATA: "data",
247
301
  TRACE: "trace"
248
302
  });
303
+ var _kind = /* @__PURE__ */ new WeakMap();
304
+ var _parts = /* @__PURE__ */ new WeakMap();
305
+ var _inspectCustom = inspectCustom;
306
+ var _devtoolsFormatter = devtoolsFormatter;
249
307
  var DXN = class _DXN {
250
- static {
251
- // TODO(dmaretskyi): Should this be a transformation into the DXN type?
252
- this.Schema = Schema3.NonEmptyString.pipe(
253
- Schema3.pattern(/^dxn:([^:]+):(?:[^:]+:?)+[^:]$/),
254
- // TODO(dmaretskyi): To set the format we need to move the annotation IDs out of the echo-schema package.
255
- // FormatAnnotation.set(FormatEnum.DXN),
256
- Schema3.annotations({
257
- title: "DXN",
258
- description: "DXN URI",
259
- examples: [
260
- "dxn:type:example.com/type/MyType",
261
- "dxn:echo:@:01J00J9B45YHYSGZQTQMSKMGJ6"
262
- ]
263
- })
264
- );
265
- }
266
308
  static hash(dxn) {
267
309
  return dxn.toString();
268
310
  }
269
- static {
270
- /**
271
- * Kind constants.
272
- */
273
- this.kind = Object.freeze({
274
- /**
275
- * dxn:type:<type name>[:<version>]
276
- */
277
- TYPE: "type",
278
- /**
279
- * dxn:echo:<space id>:<echo id>
280
- * dxn:echo:@:<echo id>
281
- */
282
- // TODO(burdon): Rename to OBJECT? (BREAKING CHANGE).
283
- // TODO(burdon): Add separate Kind for space.
284
- ECHO: "echo",
285
- /**
286
- * The subspace tag enables us to partition queues by usage within the context of a space.
287
- * dxn:queue:<subspace_tag>:<space_id>:<queue_id>[:object_id]
288
- * dxn:queue:data:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
289
- * dxn:queue:trace:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
290
- */
291
- QUEUE: "queue"
292
- });
293
- }
294
- get kind() {
295
- return this.#kind;
296
- }
311
+ /**
312
+ * Exactly equals.
313
+ */
297
314
  static equals(a, b) {
298
315
  return a.kind === b.kind && a.parts.length === b.parts.length && a.parts.every((part, i) => part === b.parts[i]);
299
316
  }
317
+ static equalsEchoId(a, b) {
318
+ const a1 = a.asEchoDXN();
319
+ const b1 = b.asEchoDXN();
320
+ return !!a1 && !!b1 && a1.echoId === b1.echoId;
321
+ }
300
322
  // TODO(burdon): Rename isValid.
301
323
  static isDXNString(dxn) {
302
324
  return dxn.startsWith("dxn:");
@@ -320,7 +342,7 @@ var DXN = class _DXN {
320
342
  static tryParse(dxn) {
321
343
  try {
322
344
  return _DXN.parse(dxn);
323
- } catch (error) {
345
+ } catch {
324
346
  return void 0;
325
347
  }
326
348
  }
@@ -343,42 +365,30 @@ var DXN = class _DXN {
343
365
  ]);
344
366
  }
345
367
  /**
368
+ * @example `dxn:echo:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6`
369
+ */
370
+ static fromSpaceAndObjectId(spaceId, objectId) {
371
+ assertArgument(SpaceId.isValid(spaceId), `Invalid space ID: ${spaceId}`);
372
+ assertArgument(ObjectId.isValid(objectId), "objectId", `Invalid object ID: ${objectId}`);
373
+ return new _DXN(_DXN.kind.ECHO, [
374
+ spaceId,
375
+ objectId
376
+ ]);
377
+ }
378
+ /**
346
379
  * @example `dxn:echo:@:01J00J9B45YHYSGZQTQMSKMGJ6`
347
380
  */
348
381
  static fromLocalObjectId(id) {
382
+ assertArgument(ObjectId.isValid(id), "id", `Invalid object ID: ${id}`);
349
383
  return new _DXN(_DXN.kind.ECHO, [
350
384
  LOCAL_SPACE_TAG,
351
385
  id
352
386
  ]);
353
387
  }
354
388
  static fromQueue(subspaceTag, spaceId, queueId, objectId) {
355
- invariant2(SpaceId.isValid(spaceId), void 0, {
356
- F: __dxlog_file2,
357
- L: 150,
358
- S: this,
359
- A: [
360
- "SpaceId.isValid(spaceId)",
361
- ""
362
- ]
363
- });
364
- invariant2(ObjectId.isValid(queueId), void 0, {
365
- F: __dxlog_file2,
366
- L: 151,
367
- S: this,
368
- A: [
369
- "ObjectId.isValid(queueId)",
370
- ""
371
- ]
372
- });
373
- invariant2(!objectId || ObjectId.isValid(objectId), void 0, {
374
- F: __dxlog_file2,
375
- L: 152,
376
- S: this,
377
- A: [
378
- "!objectId || ObjectId.isValid(objectId)",
379
- ""
380
- ]
381
- });
389
+ assertArgument(SpaceId.isValid(spaceId), `Invalid space ID: ${spaceId}`);
390
+ assertArgument(ObjectId.isValid(queueId), "queueId", `Invalid queue ID: ${queueId}`);
391
+ assertArgument(!objectId || ObjectId.isValid(objectId), "objectId", `Invalid object ID: ${objectId}`);
382
392
  return new _DXN(_DXN.kind.QUEUE, [
383
393
  subspaceTag,
384
394
  spaceId,
@@ -388,70 +398,69 @@ var DXN = class _DXN {
388
398
  ] : []
389
399
  ]);
390
400
  }
391
- #kind;
392
- #parts;
393
- constructor(kind, parts) {
394
- invariant2(parts.length > 0, void 0, {
395
- F: __dxlog_file2,
396
- L: 161,
397
- S: this,
398
- A: [
399
- "parts.length > 0",
400
- ""
401
- ]
402
- });
403
- invariant2(parts.every((part) => typeof part === "string" && part.length > 0 && part.indexOf(":") === -1), void 0, {
404
- F: __dxlog_file2,
405
- L: 162,
406
- S: this,
407
- A: [
408
- "parts.every((part) => typeof part === 'string' && part.length > 0 && part.indexOf(':') === -1)",
409
- ""
410
- ]
411
- });
412
- switch (kind) {
413
- case _DXN.kind.TYPE:
414
- if (parts.length > 2) {
415
- throw new Error('Invalid "type" DXN');
416
- }
417
- break;
418
- case _DXN.kind.ECHO:
419
- if (parts.length !== 2) {
420
- throw new Error('Invalid "echo" DXN');
421
- }
422
- break;
423
- }
424
- this.#kind = kind;
425
- this.#parts = parts;
401
+ toString() {
402
+ return `dxn:${_class_private_field_get(this, _kind)}:${_class_private_field_get(this, _parts).join(":")}`;
403
+ }
404
+ toJSON() {
405
+ return this.toString();
406
+ }
407
+ /**
408
+ * Used by Node.js to get textual representation of this object when it's printed with a `console.log` statement.
409
+ */
410
+ [_inspectCustom](depth, options, inspectFn) {
411
+ const printControlCode = (code) => {
412
+ return `\x1B[${code}m`;
413
+ };
414
+ return printControlCode(inspectFn.colors.blueBright[0]) + this.toString() + printControlCode(inspectFn.colors.reset[0]);
415
+ }
416
+ get [_devtoolsFormatter]() {
417
+ return {
418
+ header: () => {
419
+ return [
420
+ "span",
421
+ {
422
+ style: "font-weight: bold;"
423
+ },
424
+ this.toString()
425
+ ];
426
+ }
427
+ };
428
+ }
429
+ get kind() {
430
+ return _class_private_field_get(this, _kind);
426
431
  }
427
432
  get parts() {
428
- return this.#parts;
433
+ return _class_private_field_get(this, _parts);
429
434
  }
430
435
  // TODO(burdon): Should getters fail?
431
436
  get typename() {
432
- invariant2(this.#kind === _DXN.kind.TYPE, void 0, {
437
+ invariant2(_class_private_field_get(this, _kind) === _DXN.kind.TYPE, void 0, {
433
438
  F: __dxlog_file2,
434
- L: 188,
439
+ L: 250,
435
440
  S: this,
436
441
  A: [
437
442
  "this.#kind === DXN.kind.TYPE",
438
443
  ""
439
444
  ]
440
445
  });
441
- return this.#parts[0];
446
+ return _class_private_field_get(this, _parts)[0];
447
+ }
448
+ equals(other) {
449
+ return _DXN.equals(this, other);
442
450
  }
443
451
  hasTypenameOf(typename) {
444
- return this.#kind === _DXN.kind.TYPE && this.#parts.length === 1 && this.#parts[0] === typename;
452
+ 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;
445
453
  }
446
454
  isLocalObjectId() {
447
- return this.#kind === _DXN.kind.ECHO && this.#parts[0] === LOCAL_SPACE_TAG && this.#parts.length === 2;
455
+ 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;
448
456
  }
449
457
  asTypeDXN() {
450
458
  if (this.kind !== _DXN.kind.TYPE) {
451
459
  return void 0;
452
460
  }
453
- const [type, version] = this.#parts;
461
+ const [type, version] = _class_private_field_get(this, _parts);
454
462
  return {
463
+ // TODO(wittjosiah): Should be `typename` for consistency.
455
464
  type,
456
465
  version
457
466
  };
@@ -460,9 +469,10 @@ var DXN = class _DXN {
460
469
  if (this.kind !== _DXN.kind.ECHO) {
461
470
  return void 0;
462
471
  }
463
- const [spaceId, echoId] = this.#parts;
472
+ const [spaceId, echoId] = _class_private_field_get(this, _parts);
464
473
  return {
465
474
  spaceId: spaceId === LOCAL_SPACE_TAG ? void 0 : spaceId,
475
+ // TODO(burdon): objectId.
466
476
  echoId
467
477
  };
468
478
  }
@@ -470,7 +480,7 @@ var DXN = class _DXN {
470
480
  if (this.kind !== _DXN.kind.QUEUE) {
471
481
  return void 0;
472
482
  }
473
- const [subspaceTag, spaceId, queueId, objectId] = this.#parts;
483
+ const [subspaceTag, spaceId, queueId, objectId] = _class_private_field_get(this, _parts);
474
484
  if (typeof queueId !== "string") {
475
485
  return void 0;
476
486
  }
@@ -481,37 +491,80 @@ var DXN = class _DXN {
481
491
  objectId
482
492
  };
483
493
  }
484
- toString() {
485
- return `dxn:${this.#kind}:${this.#parts.join(":")}`;
486
- }
487
494
  /**
488
- * Used by Node.js to get textual representation of this object when it's printed with a `console.log` statement.
495
+ * Produces a new DXN with the given parts appended.
489
496
  */
490
- [inspectCustom](depth, options, inspectFn) {
491
- const printControlCode = (code) => {
492
- return `\x1B[${code}m`;
493
- };
494
- return printControlCode(inspectFn.colors.blueBright[0]) + this.toString() + printControlCode(inspectFn.colors.reset[0]);
497
+ extend(parts) {
498
+ return new _DXN(_class_private_field_get(this, _kind), [
499
+ ..._class_private_field_get(this, _parts),
500
+ ...parts
501
+ ]);
495
502
  }
496
- get [devtoolsFormatter]() {
497
- return {
498
- header: () => {
499
- return [
500
- "span",
501
- {
502
- style: "font-weight: bold;"
503
- },
504
- this.toString()
505
- ];
506
- }
507
- };
503
+ constructor(kind, parts) {
504
+ _class_private_field_init(this, _kind, {
505
+ writable: true,
506
+ value: void 0
507
+ });
508
+ _class_private_field_init(this, _parts, {
509
+ writable: true,
510
+ value: void 0
511
+ });
512
+ assertArgument(parts.length > 0, "parts", `Invalid DXN: ${parts}`);
513
+ assertArgument(parts.every((part) => typeof part === "string" && part.length > 0 && part.indexOf(":") === -1), "parts", `Invalid DXN: ${parts}`);
514
+ switch (kind) {
515
+ case _DXN.kind.TYPE:
516
+ if (parts.length > 2) {
517
+ throw new Error("Invalid DXN.kind.TYPE");
518
+ }
519
+ break;
520
+ case _DXN.kind.ECHO:
521
+ if (parts.length !== 2) {
522
+ throw new Error("Invalid DXN.kind.ECHO");
523
+ }
524
+ break;
525
+ }
526
+ _class_private_field_set(this, _kind, kind);
527
+ _class_private_field_set(this, _parts, parts);
508
528
  }
509
529
  };
530
+ _define_property2(DXN, "Schema", Schema3.NonEmptyString.pipe(
531
+ Schema3.pattern(/^dxn:([^:]+):(?:[^:]+:?)+[^:]$/),
532
+ // TODO(dmaretskyi): To set the format we need to move the annotation IDs out of the echo-schema package.
533
+ // FormatAnnotation.set(FormatEnum.DXN),
534
+ Schema3.annotations({
535
+ title: "DXN",
536
+ description: "DXN URI",
537
+ examples: [
538
+ "dxn:type:example.com/type/MyType",
539
+ "dxn:echo:@:01J00J9B45YHYSGZQTQMSKMGJ6"
540
+ ]
541
+ })
542
+ ));
543
+ _define_property2(DXN, "kind", Object.freeze({
544
+ /**
545
+ * dxn:type:<type_name>[:<version>]
546
+ */
547
+ TYPE: "type",
548
+ /**
549
+ * dxn:echo:<space_id>:<echo_id>
550
+ * dxn:echo:@:<echo_id>
551
+ */
552
+ // TODO(burdon): Rename to OBJECT? (BREAKING CHANGE to update "echo").
553
+ // TODO(burdon): Add separate Kind for space?
554
+ ECHO: "echo",
555
+ /**
556
+ * The subspace tag enables us to partition queues by usage within the context of a space.
557
+ * dxn:queue:<subspace_tag>:<space_id>:<queue_id>[:object_id]
558
+ * dxn:queue:data:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
559
+ * dxn:queue:trace:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
560
+ */
561
+ QUEUE: "queue"
562
+ }));
510
563
 
511
- // packages/common/keys/src/identity-did.ts
564
+ // src/identity-did.ts
512
565
  var import_base32_decode2 = __toESM(require_base32_decode(), 1);
513
566
  import { invariant as invariant3 } from "@dxos/invariant";
514
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/common/keys/src/identity-did.ts";
567
+ var __dxlog_file3 = "/__w/dxos/dxos/packages/common/keys/src/identity-did.ts";
515
568
  var IdentityDid = Object.freeze({
516
569
  byteLength: 20,
517
570
  encode: (value) => {
@@ -558,18 +611,31 @@ var MULTIBASE_PREFIX2 = "B";
558
611
  var DID_PREFIX = "did:halo:";
559
612
  var ENCODED_LENGTH2 = 42;
560
613
 
561
- // packages/common/keys/src/public-key.ts
614
+ // src/public-key.ts
562
615
  var import_base32_decode3 = __toESM(require_base32_decode(), 1);
563
616
  import { devtoolsFormatter as devtoolsFormatter2, equalsSymbol, inspectCustom as inspectCustom2, truncateKey } from "@dxos/debug";
564
617
  import { invariant as invariant4 } from "@dxos/invariant";
565
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/common/keys/src/public-key.ts";
618
+ function _define_property3(obj, key, value) {
619
+ if (key in obj) {
620
+ Object.defineProperty(obj, key, {
621
+ value,
622
+ enumerable: true,
623
+ configurable: true,
624
+ writable: true
625
+ });
626
+ } else {
627
+ obj[key] = value;
628
+ }
629
+ return obj;
630
+ }
631
+ var __dxlog_file4 = "/__w/dxos/dxos/packages/common/keys/src/public-key.ts";
566
632
  var PUBLIC_KEY_LENGTH = 32;
567
633
  var SECRET_KEY_LENGTH = 64;
568
634
  var isLikeArrayBuffer = (value) => typeof value === "object" && value !== null && Object.getPrototypeOf(value).constructor.name === "ArrayBuffer";
635
+ var _inspectCustom2 = inspectCustom2;
636
+ var _devtoolsFormatter2 = devtoolsFormatter2;
637
+ var _equalsSymbol = equalsSymbol;
569
638
  var PublicKey = class _PublicKey {
570
- static {
571
- this.ZERO = _PublicKey.from("00".repeat(PUBLIC_KEY_LENGTH));
572
- }
573
639
  /**
574
640
  * Creates new instance of PublicKey automatically determining the input format.
575
641
  * @param source A Buffer, or Uint8Array, or hex encoded string, or something with an `asUint8Array` method on it
@@ -578,7 +644,7 @@ var PublicKey = class _PublicKey {
578
644
  static from(source) {
579
645
  invariant4(source, void 0, {
580
646
  F: __dxlog_file4,
581
- L: 49,
647
+ L: 50,
582
648
  S: this,
583
649
  A: [
584
650
  "source",
@@ -670,7 +736,7 @@ var PublicKey = class _PublicKey {
670
736
  static bufferize(str) {
671
737
  invariant4(typeof str === "string", "Invalid type", {
672
738
  F: __dxlog_file4,
673
- L: 152,
739
+ L: 153,
674
740
  S: this,
675
741
  A: [
676
742
  "typeof str === 'string'",
@@ -693,7 +759,7 @@ var PublicKey = class _PublicKey {
693
759
  }
694
760
  invariant4(key instanceof Buffer, "Invalid type", {
695
761
  F: __dxlog_file4,
696
- L: 171,
762
+ L: 172,
697
763
  S: this,
698
764
  A: [
699
765
  "key instanceof Buffer",
@@ -712,7 +778,7 @@ var PublicKey = class _PublicKey {
712
778
  static fromMultibase32(encoded) {
713
779
  invariant4(encoded.startsWith("B"), "Invalid multibase32 encoding", {
714
780
  F: __dxlog_file4,
715
- L: 184,
781
+ L: 185,
716
782
  S: this,
717
783
  A: [
718
784
  "encoded.startsWith('B')",
@@ -721,12 +787,6 @@ var PublicKey = class _PublicKey {
721
787
  });
722
788
  return new _PublicKey(new Uint8Array((0, import_base32_decode3.default)(encoded.slice(1), "RFC4648")));
723
789
  }
724
- constructor(_value) {
725
- this._value = _value;
726
- if (!(_value instanceof Uint8Array)) {
727
- throw new TypeError(`Expected Uint8Array, got: ${_value}`);
728
- }
729
- }
730
790
  toString() {
731
791
  return this.toHex();
732
792
  }
@@ -760,7 +820,7 @@ var PublicKey = class _PublicKey {
760
820
  /**
761
821
  * Used by Node.js to get textual representation of this object when it's printed with a `console.log` statement.
762
822
  */
763
- [inspectCustom2](depth, options, inspectFn) {
823
+ [_inspectCustom2](depth, options, inspectFn) {
764
824
  if (!options.colors || typeof process.stdout.hasColors !== "function" || !process.stdout.hasColors()) {
765
825
  return `<PublicKey ${this.truncate()}>`;
766
826
  }
@@ -785,7 +845,7 @@ var PublicKey = class _PublicKey {
785
845
  const color = colors[this.getInsecureHash(colors.length)];
786
846
  return `PublicKey(${printControlCode(inspectFn.colors[color][0])}${this.truncate()}${printControlCode(inspectFn.colors.reset[0])})`;
787
847
  }
788
- get [devtoolsFormatter2]() {
848
+ get [_devtoolsFormatter2]() {
789
849
  return {
790
850
  header: () => {
791
851
  const colors = [
@@ -838,19 +898,28 @@ var PublicKey = class _PublicKey {
838
898
  }
839
899
  let equal = true;
840
900
  for (let i = 0; i < this._value.length; i++) {
841
- equal &&= this._value[i] === otherConverted._value[i];
901
+ equal && (equal = this._value[i] === otherConverted._value[i]);
842
902
  }
843
903
  return equal;
844
904
  }
845
- [equalsSymbol](other) {
905
+ [_equalsSymbol](other) {
846
906
  if (!_PublicKey.isPublicKey(other)) {
847
907
  return false;
848
908
  }
849
909
  return this.equals(other);
850
910
  }
911
+ constructor(_value) {
912
+ _define_property3(this, "_value", void 0);
913
+ this._value = _value;
914
+ if (!(_value instanceof Uint8Array)) {
915
+ throw new TypeError(`Expected Uint8Array, got: ${_value}`);
916
+ }
917
+ }
851
918
  };
919
+ _define_property3(PublicKey, "ZERO", PublicKey.from("00".repeat(PUBLIC_KEY_LENGTH)));
852
920
  export {
853
921
  DXN,
922
+ DXN_ECHO_REGEXP,
854
923
  IdentityDid,
855
924
  LOCAL_SPACE_TAG,
856
925
  ObjectId,