@dxos/keys 0.8.4-main.84f28bd → 0.8.4-main.a4bbb77

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.
@@ -102,28 +102,149 @@ init_inject_globals();
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
107
  // src/object-id.ts
108
108
  init_inject_globals();
109
109
  import { Schema } from "effect";
110
- import { ulid } from "ulidx";
110
+ import { monotonicFactory } from "ulidx";
111
+ function _check_private_redeclaration(obj, privateCollection) {
112
+ if (privateCollection.has(obj)) {
113
+ throw new TypeError("Cannot initialize the same private elements twice on an object");
114
+ }
115
+ }
116
+ function _class_apply_descriptor_get(receiver, descriptor) {
117
+ if (descriptor.get) {
118
+ return descriptor.get.call(receiver);
119
+ }
120
+ return descriptor.value;
121
+ }
122
+ function _class_apply_descriptor_set(receiver, descriptor, value) {
123
+ if (descriptor.set) {
124
+ descriptor.set.call(receiver, value);
125
+ } else {
126
+ if (!descriptor.writable) {
127
+ throw new TypeError("attempted to set read only private field");
128
+ }
129
+ descriptor.value = value;
130
+ }
131
+ }
132
+ function _class_check_private_static_field_descriptor(descriptor, action) {
133
+ if (descriptor === void 0) {
134
+ throw new TypeError("attempted to " + action + " private static field before its declaration");
135
+ }
136
+ }
137
+ function _class_extract_field_descriptor(receiver, privateMap, action) {
138
+ if (!privateMap.has(receiver)) {
139
+ throw new TypeError("attempted to " + action + " private field on non-instance");
140
+ }
141
+ return privateMap.get(receiver);
142
+ }
143
+ function _class_private_field_get(receiver, privateMap) {
144
+ var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
145
+ return _class_apply_descriptor_get(receiver, descriptor);
146
+ }
147
+ function _class_private_field_init(obj, privateMap, value) {
148
+ _check_private_redeclaration(obj, privateMap);
149
+ privateMap.set(obj, value);
150
+ }
151
+ function _class_private_field_set(receiver, privateMap, value) {
152
+ var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
153
+ _class_apply_descriptor_set(receiver, descriptor, value);
154
+ return value;
155
+ }
156
+ function _class_static_private_field_spec_get(receiver, classConstructor, descriptor) {
157
+ _class_check_private_static_access(receiver, classConstructor);
158
+ _class_check_private_static_field_descriptor(descriptor, "get");
159
+ return _class_apply_descriptor_get(receiver, descriptor);
160
+ }
161
+ function _class_static_private_field_spec_set(receiver, classConstructor, descriptor, value) {
162
+ _class_check_private_static_access(receiver, classConstructor);
163
+ _class_check_private_static_field_descriptor(descriptor, "set");
164
+ _class_apply_descriptor_set(receiver, descriptor, value);
165
+ return value;
166
+ }
167
+ function _class_check_private_static_access(receiver, classConstructor) {
168
+ if (receiver !== classConstructor) {
169
+ throw new TypeError("Private static access of wrong provenance");
170
+ }
171
+ }
172
+ var _class;
173
+ var _factory;
174
+ var _seedTime;
111
175
  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",
176
+ description: "A Universally Unique Lexicographically Sortable Identifier",
113
177
  pattern: "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
114
178
  });
115
- var ObjectId = class extends ObjectIdSchema {
179
+ var ObjectId = (_class = class extends ObjectIdSchema {
116
180
  static isValid(id) {
117
181
  try {
118
182
  Schema.decodeSync(ObjectId)(id);
119
183
  return true;
120
- } catch (err) {
184
+ } catch {
121
185
  return false;
122
186
  }
123
187
  }
124
188
  static random() {
125
- return ulid();
189
+ return _class_static_private_field_spec_get(this, _class, _factory).call(_class, _class_static_private_field_spec_get(this, _class, _seedTime));
190
+ }
191
+ static dangerouslyDisableRandomness() {
192
+ _class_static_private_field_spec_set(this, _class, _factory, monotonicFactory(makeTestPRNG()));
193
+ _class_static_private_field_spec_set(this, _class, _seedTime, (/* @__PURE__ */ new Date("2025-01-01")).getTime());
194
+ }
195
+ }, _factory = {
196
+ writable: true,
197
+ value: monotonicFactory()
198
+ }, _seedTime = {
199
+ writable: true,
200
+ value: void 0
201
+ }, _class);
202
+ var makeTestPRNG = () => {
203
+ const rng = new SimplePRNG();
204
+ return () => {
205
+ return rng.next();
206
+ };
207
+ };
208
+ var _seed = /* @__PURE__ */ new WeakMap();
209
+ var SimplePRNG = class _SimplePRNG {
210
+ /**
211
+ * Generates the next pseudo-random number in the range [0, 1).
212
+ * @returns A pseudo-random number between 0 (inclusive) and 1 (exclusive).
213
+ */
214
+ next() {
215
+ _class_private_field_set(this, _seed, (_class_static_private_field_spec_get(_SimplePRNG, _SimplePRNG, _a) * _class_private_field_get(this, _seed) + _class_static_private_field_spec_get(_SimplePRNG, _SimplePRNG, _c)) % _class_static_private_field_spec_get(_SimplePRNG, _SimplePRNG, _m));
216
+ return _class_private_field_get(this, _seed) / _class_static_private_field_spec_get(_SimplePRNG, _SimplePRNG, _m);
217
+ }
218
+ /**
219
+ * Resets the generator with a new seed.
220
+ * @param seed - New seed value.
221
+ */
222
+ reset(seed) {
223
+ _class_private_field_set(this, _seed, seed);
126
224
  }
225
+ /**
226
+ * Creates a new PRNG instance.
227
+ * @param seed - Initial seed value. If not provided, uses 0.
228
+ */
229
+ constructor(seed = 0) {
230
+ _class_private_field_init(this, _seed, {
231
+ writable: true,
232
+ value: void 0
233
+ });
234
+ _class_private_field_set(this, _seed, seed);
235
+ }
236
+ };
237
+ var _a = {
238
+ writable: true,
239
+ value: 1664525
240
+ };
241
+ var _c = {
242
+ writable: true,
243
+ value: 1013904223
244
+ };
245
+ var _m = {
246
+ writable: true,
247
+ value: Math.pow(2, 32)
127
248
  };
128
249
 
129
250
  // src/space-id.ts
@@ -207,121 +328,143 @@ var randomBytes = (length) => {
207
328
  };
208
329
 
209
330
  // src/space-id.ts
331
+ function _define_property(obj, key, value) {
332
+ if (key in obj) {
333
+ Object.defineProperty(obj, key, {
334
+ value,
335
+ enumerable: true,
336
+ configurable: true,
337
+ writable: true
338
+ });
339
+ } else {
340
+ obj[key] = value;
341
+ }
342
+ return obj;
343
+ }
344
+ var _Schema_String_pipe;
345
+ var _class2;
210
346
  var __dxlog_file = "/__w/dxos/dxos/packages/common/keys/src/space-id.ts";
211
347
  var MULTIBASE_PREFIX = "B";
212
348
  var ENCODED_LENGTH = 33;
213
349
  var isValid = (value) => {
214
350
  return typeof value === "string" && value.startsWith(MULTIBASE_PREFIX) && value.length === ENCODED_LENGTH;
215
351
  };
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
- };
352
+ var SpaceId = (_class2 = class extends (_Schema_String_pipe = Schema2.String.pipe(Schema2.filter(isValid))) {
353
+ }, _define_property(_class2, "byteLength", 20), _define_property(_class2, "encode", (value) => {
354
+ invariant(value instanceof Uint8Array, "Invalid type", {
355
+ F: __dxlog_file,
356
+ L: 43,
357
+ S: _class2,
358
+ A: [
359
+ "value instanceof Uint8Array",
360
+ "'Invalid type'"
361
+ ]
362
+ });
363
+ invariant(value.length === SpaceId.byteLength, "Invalid length", {
364
+ F: __dxlog_file,
365
+ L: 44,
366
+ S: _class2,
367
+ A: [
368
+ "value.length === SpaceId.byteLength",
369
+ "'Invalid length'"
370
+ ]
371
+ });
372
+ return MULTIBASE_PREFIX + base32Encode(value, "RFC4648");
373
+ }), _define_property(_class2, "decode", (value) => {
374
+ invariant(value.startsWith(MULTIBASE_PREFIX), "Invalid multibase32 encoding", {
375
+ F: __dxlog_file,
376
+ L: 49,
377
+ S: _class2,
378
+ A: [
379
+ "value.startsWith(MULTIBASE_PREFIX)",
380
+ "'Invalid multibase32 encoding'"
381
+ ]
382
+ });
383
+ return new Uint8Array((0, import_base32_decode.default)(value.slice(1), "RFC4648"));
384
+ }), _define_property(_class2, "isValid", isValid), _define_property(_class2, "random", () => {
385
+ return SpaceId.encode(randomBytes(SpaceId.byteLength));
386
+ }), _class2);
387
+
388
+ // src/dxn.ts
389
+ function _check_private_redeclaration2(obj, privateCollection) {
390
+ if (privateCollection.has(obj)) {
391
+ throw new TypeError("Cannot initialize the same private elements twice on an object");
242
392
  }
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
- };
393
+ }
394
+ function _class_apply_descriptor_get2(receiver, descriptor) {
395
+ if (descriptor.get) {
396
+ return descriptor.get.call(receiver);
256
397
  }
257
- static {
258
- this.isValid = isValid;
398
+ return descriptor.value;
399
+ }
400
+ function _class_apply_descriptor_set2(receiver, descriptor, value) {
401
+ if (descriptor.set) {
402
+ descriptor.set.call(receiver, value);
403
+ } else {
404
+ if (!descriptor.writable) {
405
+ throw new TypeError("attempted to set read only private field");
406
+ }
407
+ descriptor.value = value;
259
408
  }
260
- static {
261
- this.random = () => {
262
- return SpaceId.encode(randomBytes(SpaceId.byteLength));
263
- };
409
+ }
410
+ function _class_extract_field_descriptor2(receiver, privateMap, action) {
411
+ if (!privateMap.has(receiver)) {
412
+ throw new TypeError("attempted to " + action + " private field on non-instance");
264
413
  }
265
- };
266
-
267
- // src/dxn.ts
414
+ return privateMap.get(receiver);
415
+ }
416
+ function _class_private_field_get2(receiver, privateMap) {
417
+ var descriptor = _class_extract_field_descriptor2(receiver, privateMap, "get");
418
+ return _class_apply_descriptor_get2(receiver, descriptor);
419
+ }
420
+ function _class_private_field_init2(obj, privateMap, value) {
421
+ _check_private_redeclaration2(obj, privateMap);
422
+ privateMap.set(obj, value);
423
+ }
424
+ function _class_private_field_set2(receiver, privateMap, value) {
425
+ var descriptor = _class_extract_field_descriptor2(receiver, privateMap, "set");
426
+ _class_apply_descriptor_set2(receiver, descriptor, value);
427
+ return value;
428
+ }
429
+ function _define_property2(obj, key, value) {
430
+ if (key in obj) {
431
+ Object.defineProperty(obj, key, {
432
+ value,
433
+ enumerable: true,
434
+ configurable: true,
435
+ writable: true
436
+ });
437
+ } else {
438
+ obj[key] = value;
439
+ }
440
+ return obj;
441
+ }
268
442
  var __dxlog_file2 = "/__w/dxos/dxos/packages/common/keys/src/dxn.ts";
269
443
  var LOCAL_SPACE_TAG = "@";
444
+ var DXN_ECHO_REGEXP = /@(dxn:[a-zA-Z0-p:@]+)/;
270
445
  var QueueSubspaceTags = Object.freeze({
271
446
  DATA: "data",
272
447
  TRACE: "trace"
273
448
  });
449
+ var _kind = /* @__PURE__ */ new WeakMap();
450
+ var _parts = /* @__PURE__ */ new WeakMap();
451
+ var _inspectCustom = inspectCustom;
452
+ var _devtoolsFormatter = devtoolsFormatter;
274
453
  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
454
  static hash(dxn) {
292
455
  return dxn.toString();
293
456
  }
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
- }
457
+ /**
458
+ * Exactly equals.
459
+ */
322
460
  static equals(a, b) {
323
461
  return a.kind === b.kind && a.parts.length === b.parts.length && a.parts.every((part, i) => part === b.parts[i]);
324
462
  }
463
+ static equalsEchoId(a, b) {
464
+ const a1 = a.asEchoDXN();
465
+ const b1 = b.asEchoDXN();
466
+ return !!a1 && !!b1 && a1.echoId === b1.echoId;
467
+ }
325
468
  // TODO(burdon): Rename isValid.
326
469
  static isDXNString(dxn) {
327
470
  return dxn.startsWith("dxn:");
@@ -345,7 +488,7 @@ var DXN = class _DXN {
345
488
  static tryParse(dxn) {
346
489
  try {
347
490
  return _DXN.parse(dxn);
348
- } catch (error) {
491
+ } catch {
349
492
  return void 0;
350
493
  }
351
494
  }
@@ -368,42 +511,30 @@ var DXN = class _DXN {
368
511
  ]);
369
512
  }
370
513
  /**
514
+ * @example `dxn:echo:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6`
515
+ */
516
+ static fromSpaceAndObjectId(spaceId, objectId) {
517
+ assertArgument(SpaceId.isValid(spaceId), `Invalid space ID: ${spaceId}`);
518
+ assertArgument(ObjectId.isValid(objectId), "objectId", `Invalid object ID: ${objectId}`);
519
+ return new _DXN(_DXN.kind.ECHO, [
520
+ spaceId,
521
+ objectId
522
+ ]);
523
+ }
524
+ /**
371
525
  * @example `dxn:echo:@:01J00J9B45YHYSGZQTQMSKMGJ6`
372
526
  */
373
527
  static fromLocalObjectId(id) {
528
+ assertArgument(ObjectId.isValid(id), "id", `Invalid object ID: ${id}`);
374
529
  return new _DXN(_DXN.kind.ECHO, [
375
530
  LOCAL_SPACE_TAG,
376
531
  id
377
532
  ]);
378
533
  }
379
534
  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
- });
535
+ assertArgument(SpaceId.isValid(spaceId), `Invalid space ID: ${spaceId}`);
536
+ assertArgument(ObjectId.isValid(queueId), "queueId", `Invalid queue ID: ${queueId}`);
537
+ assertArgument(!objectId || ObjectId.isValid(objectId), "objectId", `Invalid object ID: ${objectId}`);
407
538
  return new _DXN(_DXN.kind.QUEUE, [
408
539
  subspaceTag,
409
540
  spaceId,
@@ -413,44 +544,8 @@ var DXN = class _DXN {
413
544
  ] : []
414
545
  ]);
415
546
  }
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;
451
- }
452
547
  toString() {
453
- return `dxn:${this.#kind}:${this.#parts.join(":")}`;
548
+ return `dxn:${_class_private_field_get2(this, _kind)}:${_class_private_field_get2(this, _parts).join(":")}`;
454
549
  }
455
550
  toJSON() {
456
551
  return this.toString();
@@ -458,13 +553,13 @@ var DXN = class _DXN {
458
553
  /**
459
554
  * Used by Node.js to get textual representation of this object when it's printed with a `console.log` statement.
460
555
  */
461
- [inspectCustom](depth, options, inspectFn) {
556
+ [_inspectCustom](depth, options, inspectFn) {
462
557
  const printControlCode = (code) => {
463
558
  return `\x1B[${code}m`;
464
559
  };
465
560
  return printControlCode(inspectFn.colors.blueBright[0]) + this.toString() + printControlCode(inspectFn.colors.reset[0]);
466
561
  }
467
- get [devtoolsFormatter]() {
562
+ get [_devtoolsFormatter]() {
468
563
  return {
469
564
  header: () => {
470
565
  return [
@@ -477,34 +572,41 @@ var DXN = class _DXN {
477
572
  }
478
573
  };
479
574
  }
575
+ get kind() {
576
+ return _class_private_field_get2(this, _kind);
577
+ }
480
578
  get parts() {
481
- return this.#parts;
579
+ return _class_private_field_get2(this, _parts);
482
580
  }
483
581
  // TODO(burdon): Should getters fail?
484
582
  get typename() {
485
- invariant2(this.#kind === _DXN.kind.TYPE, void 0, {
583
+ invariant2(_class_private_field_get2(this, _kind) === _DXN.kind.TYPE, void 0, {
486
584
  F: __dxlog_file2,
487
- L: 217,
585
+ L: 250,
488
586
  S: this,
489
587
  A: [
490
588
  "this.#kind === DXN.kind.TYPE",
491
589
  ""
492
590
  ]
493
591
  });
494
- return this.#parts[0];
592
+ return _class_private_field_get2(this, _parts)[0];
593
+ }
594
+ equals(other) {
595
+ return _DXN.equals(this, other);
495
596
  }
496
597
  hasTypenameOf(typename) {
497
- return this.#kind === _DXN.kind.TYPE && this.#parts.length === 1 && this.#parts[0] === typename;
598
+ return _class_private_field_get2(this, _kind) === _DXN.kind.TYPE && _class_private_field_get2(this, _parts).length === 1 && _class_private_field_get2(this, _parts)[0] === typename;
498
599
  }
499
600
  isLocalObjectId() {
500
- return this.#kind === _DXN.kind.ECHO && this.#parts[0] === LOCAL_SPACE_TAG && this.#parts.length === 2;
601
+ return _class_private_field_get2(this, _kind) === _DXN.kind.ECHO && _class_private_field_get2(this, _parts)[0] === LOCAL_SPACE_TAG && _class_private_field_get2(this, _parts).length === 2;
501
602
  }
502
603
  asTypeDXN() {
503
604
  if (this.kind !== _DXN.kind.TYPE) {
504
605
  return void 0;
505
606
  }
506
- const [type, version] = this.#parts;
607
+ const [type, version] = _class_private_field_get2(this, _parts);
507
608
  return {
609
+ // TODO(wittjosiah): Should be `typename` for consistency.
508
610
  type,
509
611
  version
510
612
  };
@@ -513,9 +615,10 @@ var DXN = class _DXN {
513
615
  if (this.kind !== _DXN.kind.ECHO) {
514
616
  return void 0;
515
617
  }
516
- const [spaceId, echoId] = this.#parts;
618
+ const [spaceId, echoId] = _class_private_field_get2(this, _parts);
517
619
  return {
518
620
  spaceId: spaceId === LOCAL_SPACE_TAG ? void 0 : spaceId,
621
+ // TODO(burdon): objectId.
519
622
  echoId
520
623
  };
521
624
  }
@@ -523,7 +626,7 @@ var DXN = class _DXN {
523
626
  if (this.kind !== _DXN.kind.QUEUE) {
524
627
  return void 0;
525
628
  }
526
- const [subspaceTag, spaceId, queueId, objectId] = this.#parts;
629
+ const [subspaceTag, spaceId, queueId, objectId] = _class_private_field_get2(this, _parts);
527
630
  if (typeof queueId !== "string") {
528
631
  return void 0;
529
632
  }
@@ -534,7 +637,75 @@ var DXN = class _DXN {
534
637
  objectId
535
638
  };
536
639
  }
640
+ /**
641
+ * Produces a new DXN with the given parts appended.
642
+ */
643
+ extend(parts) {
644
+ return new _DXN(_class_private_field_get2(this, _kind), [
645
+ ..._class_private_field_get2(this, _parts),
646
+ ...parts
647
+ ]);
648
+ }
649
+ constructor(kind, parts) {
650
+ _class_private_field_init2(this, _kind, {
651
+ writable: true,
652
+ value: void 0
653
+ });
654
+ _class_private_field_init2(this, _parts, {
655
+ writable: true,
656
+ value: void 0
657
+ });
658
+ assertArgument(parts.length > 0, "parts", `Invalid DXN: ${parts}`);
659
+ assertArgument(parts.every((part) => typeof part === "string" && part.length > 0 && part.indexOf(":") === -1), "parts", `Invalid DXN: ${parts}`);
660
+ switch (kind) {
661
+ case _DXN.kind.TYPE:
662
+ if (parts.length > 2) {
663
+ throw new Error("Invalid DXN.kind.TYPE");
664
+ }
665
+ break;
666
+ case _DXN.kind.ECHO:
667
+ if (parts.length !== 2) {
668
+ throw new Error("Invalid DXN.kind.ECHO");
669
+ }
670
+ break;
671
+ }
672
+ _class_private_field_set2(this, _kind, kind);
673
+ _class_private_field_set2(this, _parts, parts);
674
+ }
537
675
  };
676
+ _define_property2(DXN, "Schema", Schema3.NonEmptyString.pipe(
677
+ Schema3.pattern(/^dxn:([^:]+):(?:[^:]+:?)+[^:]$/),
678
+ // TODO(dmaretskyi): To set the format we need to move the annotation IDs out of the echo-schema package.
679
+ // FormatAnnotation.set(FormatEnum.DXN),
680
+ Schema3.annotations({
681
+ title: "DXN",
682
+ description: "DXN URI",
683
+ examples: [
684
+ "dxn:type:example.com/type/MyType",
685
+ "dxn:echo:@:01J00J9B45YHYSGZQTQMSKMGJ6"
686
+ ]
687
+ })
688
+ ));
689
+ _define_property2(DXN, "kind", Object.freeze({
690
+ /**
691
+ * dxn:type:<type_name>[:<version>]
692
+ */
693
+ TYPE: "type",
694
+ /**
695
+ * dxn:echo:<space_id>:<echo_id>
696
+ * dxn:echo:@:<echo_id>
697
+ */
698
+ // TODO(burdon): Rename to OBJECT? (BREAKING CHANGE to update "echo").
699
+ // TODO(burdon): Add separate Kind for space?
700
+ ECHO: "echo",
701
+ /**
702
+ * The subspace tag enables us to partition queues by usage within the context of a space.
703
+ * dxn:queue:<subspace_tag>:<space_id>:<queue_id>[:object_id]
704
+ * dxn:queue:data:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
705
+ * dxn:queue:trace:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
706
+ */
707
+ QUEUE: "queue"
708
+ }));
538
709
 
539
710
  // src/identity-did.ts
540
711
  init_inject_globals();
@@ -592,14 +763,27 @@ init_inject_globals();
592
763
  var import_base32_decode3 = __toESM(require_base32_decode(), 1);
593
764
  import { devtoolsFormatter as devtoolsFormatter2, equalsSymbol, inspectCustom as inspectCustom2, truncateKey } from "@dxos/debug";
594
765
  import { invariant as invariant4 } from "@dxos/invariant";
766
+ function _define_property3(obj, key, value) {
767
+ if (key in obj) {
768
+ Object.defineProperty(obj, key, {
769
+ value,
770
+ enumerable: true,
771
+ configurable: true,
772
+ writable: true
773
+ });
774
+ } else {
775
+ obj[key] = value;
776
+ }
777
+ return obj;
778
+ }
595
779
  var __dxlog_file4 = "/__w/dxos/dxos/packages/common/keys/src/public-key.ts";
596
780
  var PUBLIC_KEY_LENGTH = 32;
597
781
  var SECRET_KEY_LENGTH = 64;
598
782
  var isLikeArrayBuffer = (value) => typeof value === "object" && value !== null && Object.getPrototypeOf(value).constructor.name === "ArrayBuffer";
783
+ var _inspectCustom2 = inspectCustom2;
784
+ var _devtoolsFormatter2 = devtoolsFormatter2;
785
+ var _equalsSymbol = equalsSymbol;
599
786
  var PublicKey = class _PublicKey {
600
- static {
601
- this.ZERO = _PublicKey.from("00".repeat(PUBLIC_KEY_LENGTH));
602
- }
603
787
  /**
604
788
  * Creates new instance of PublicKey automatically determining the input format.
605
789
  * @param source A Buffer, or Uint8Array, or hex encoded string, or something with an `asUint8Array` method on it
@@ -608,7 +792,7 @@ var PublicKey = class _PublicKey {
608
792
  static from(source) {
609
793
  invariant4(source, void 0, {
610
794
  F: __dxlog_file4,
611
- L: 49,
795
+ L: 50,
612
796
  S: this,
613
797
  A: [
614
798
  "source",
@@ -700,7 +884,7 @@ var PublicKey = class _PublicKey {
700
884
  static bufferize(str) {
701
885
  invariant4(typeof str === "string", "Invalid type", {
702
886
  F: __dxlog_file4,
703
- L: 152,
887
+ L: 153,
704
888
  S: this,
705
889
  A: [
706
890
  "typeof str === 'string'",
@@ -723,7 +907,7 @@ var PublicKey = class _PublicKey {
723
907
  }
724
908
  invariant4(key instanceof Buffer2, "Invalid type", {
725
909
  F: __dxlog_file4,
726
- L: 171,
910
+ L: 172,
727
911
  S: this,
728
912
  A: [
729
913
  "key instanceof Buffer",
@@ -742,7 +926,7 @@ var PublicKey = class _PublicKey {
742
926
  static fromMultibase32(encoded) {
743
927
  invariant4(encoded.startsWith("B"), "Invalid multibase32 encoding", {
744
928
  F: __dxlog_file4,
745
- L: 184,
929
+ L: 185,
746
930
  S: this,
747
931
  A: [
748
932
  "encoded.startsWith('B')",
@@ -751,12 +935,6 @@ var PublicKey = class _PublicKey {
751
935
  });
752
936
  return new _PublicKey(new Uint8Array((0, import_base32_decode3.default)(encoded.slice(1), "RFC4648")));
753
937
  }
754
- constructor(_value) {
755
- this._value = _value;
756
- if (!(_value instanceof Uint8Array)) {
757
- throw new TypeError(`Expected Uint8Array, got: ${_value}`);
758
- }
759
- }
760
938
  toString() {
761
939
  return this.toHex();
762
940
  }
@@ -790,7 +968,7 @@ var PublicKey = class _PublicKey {
790
968
  /**
791
969
  * Used by Node.js to get textual representation of this object when it's printed with a `console.log` statement.
792
970
  */
793
- [inspectCustom2](depth, options, inspectFn) {
971
+ [_inspectCustom2](depth, options, inspectFn) {
794
972
  if (!options.colors || typeof process.stdout.hasColors !== "function" || !process.stdout.hasColors()) {
795
973
  return `<PublicKey ${this.truncate()}>`;
796
974
  }
@@ -815,7 +993,7 @@ var PublicKey = class _PublicKey {
815
993
  const color = colors[this.getInsecureHash(colors.length)];
816
994
  return `PublicKey(${printControlCode(inspectFn.colors[color][0])}${this.truncate()}${printControlCode(inspectFn.colors.reset[0])})`;
817
995
  }
818
- get [devtoolsFormatter2]() {
996
+ get [_devtoolsFormatter2]() {
819
997
  return {
820
998
  header: () => {
821
999
  const colors = [
@@ -868,19 +1046,28 @@ var PublicKey = class _PublicKey {
868
1046
  }
869
1047
  let equal = true;
870
1048
  for (let i = 0; i < this._value.length; i++) {
871
- equal &&= this._value[i] === otherConverted._value[i];
1049
+ equal && (equal = this._value[i] === otherConverted._value[i]);
872
1050
  }
873
1051
  return equal;
874
1052
  }
875
- [equalsSymbol](other) {
1053
+ [_equalsSymbol](other) {
876
1054
  if (!_PublicKey.isPublicKey(other)) {
877
1055
  return false;
878
1056
  }
879
1057
  return this.equals(other);
880
1058
  }
1059
+ constructor(_value) {
1060
+ _define_property3(this, "_value", void 0);
1061
+ this._value = _value;
1062
+ if (!(_value instanceof Uint8Array)) {
1063
+ throw new TypeError(`Expected Uint8Array, got: ${_value}`);
1064
+ }
1065
+ }
881
1066
  };
1067
+ _define_property3(PublicKey, "ZERO", PublicKey.from("00".repeat(PUBLIC_KEY_LENGTH)));
882
1068
  export {
883
1069
  DXN,
1070
+ DXN_ECHO_REGEXP,
884
1071
  IdentityDid,
885
1072
  LOCAL_SPACE_TAG,
886
1073
  ObjectId,
@@ -888,6 +1075,7 @@ export {
888
1075
  PublicKey,
889
1076
  QueueSubspaceTags,
890
1077
  SECRET_KEY_LENGTH,
1078
+ SimplePRNG,
891
1079
  SpaceId
892
1080
  };
893
1081
  //# sourceMappingURL=index.mjs.map