@dxos/util 0.8.4-main.b97322e → 0.8.4-main.c4373fc
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/dist/lib/browser/index.mjs +424 -167
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +424 -167
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/di-key.d.ts +3 -3
- package/dist/types/src/di-key.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/safe-parse.d.ts.map +1 -1
- package/dist/types/src/string.d.ts +5 -1
- package/dist/types/src/string.d.ts.map +1 -1
- package/dist/types/src/to-fallback.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +1 -1
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/src/unit.d.ts +15 -0
- package/dist/types/src/unit.d.ts.map +1 -0
- package/dist/types/src/unit.test.d.ts +2 -0
- package/dist/types/src/unit.test.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -8
- package/src/array.test.ts +1 -1
- package/src/circular-buffer.test.ts +1 -1
- package/src/complex.test.ts +1 -1
- package/src/human-hash.test.ts +1 -1
- package/src/index.ts +1 -1
- package/src/position.test.ts +2 -2
- package/src/safe-parse.ts +4 -3
- package/src/sort.test.ts +1 -1
- package/src/string.test.ts +1 -1
- package/src/string.ts +32 -6
- package/src/to-fallback.ts +5 -4
- package/src/tree.test.ts +1 -1
- package/src/types.ts +2 -1
- package/src/uint8array.test.ts +1 -1
- package/src/unit.test.ts +25 -0
- package/src/unit.ts +52 -0
- package/src/weak.test.ts +1 -1
- package/dist/types/src/first-two-chars.d.ts +0 -9
- package/dist/types/src/first-two-chars.d.ts.map +0 -1
- package/src/first-two-chars.ts +0 -44
|
@@ -180,31 +180,90 @@ var BitField = class _BitField {
|
|
|
180
180
|
};
|
|
181
181
|
|
|
182
182
|
// src/callback-collection.ts
|
|
183
|
+
function _check_private_redeclaration(obj, privateCollection) {
|
|
184
|
+
if (privateCollection.has(obj)) {
|
|
185
|
+
throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
function _class_apply_descriptor_get(receiver, descriptor) {
|
|
189
|
+
if (descriptor.get) {
|
|
190
|
+
return descriptor.get.call(receiver);
|
|
191
|
+
}
|
|
192
|
+
return descriptor.value;
|
|
193
|
+
}
|
|
194
|
+
function _class_apply_descriptor_set(receiver, descriptor, value) {
|
|
195
|
+
if (descriptor.set) {
|
|
196
|
+
descriptor.set.call(receiver, value);
|
|
197
|
+
} else {
|
|
198
|
+
if (!descriptor.writable) {
|
|
199
|
+
throw new TypeError("attempted to set read only private field");
|
|
200
|
+
}
|
|
201
|
+
descriptor.value = value;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
function _class_extract_field_descriptor(receiver, privateMap, action) {
|
|
205
|
+
if (!privateMap.has(receiver)) {
|
|
206
|
+
throw new TypeError("attempted to " + action + " private field on non-instance");
|
|
207
|
+
}
|
|
208
|
+
return privateMap.get(receiver);
|
|
209
|
+
}
|
|
210
|
+
function _class_private_field_get(receiver, privateMap) {
|
|
211
|
+
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
|
|
212
|
+
return _class_apply_descriptor_get(receiver, descriptor);
|
|
213
|
+
}
|
|
214
|
+
function _class_private_field_init(obj, privateMap, value) {
|
|
215
|
+
_check_private_redeclaration(obj, privateMap);
|
|
216
|
+
privateMap.set(obj, value);
|
|
217
|
+
}
|
|
218
|
+
function _class_private_field_set(receiver, privateMap, value) {
|
|
219
|
+
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
|
|
220
|
+
_class_apply_descriptor_set(receiver, descriptor, value);
|
|
221
|
+
return value;
|
|
222
|
+
}
|
|
223
|
+
var _callbacks = /* @__PURE__ */ new WeakMap();
|
|
183
224
|
var CallbackCollection = class {
|
|
184
|
-
#callbacks = [];
|
|
185
225
|
append(callback) {
|
|
186
|
-
this
|
|
226
|
+
_class_private_field_get(this, _callbacks).push(callback);
|
|
187
227
|
}
|
|
188
228
|
prepend(callback) {
|
|
189
|
-
this
|
|
229
|
+
_class_private_field_get(this, _callbacks).unshift(callback);
|
|
190
230
|
}
|
|
191
231
|
remove(callback) {
|
|
192
|
-
this
|
|
232
|
+
_class_private_field_set(this, _callbacks, _class_private_field_get(this, _callbacks).filter((c) => c !== callback));
|
|
193
233
|
}
|
|
194
234
|
callParallel(...args) {
|
|
195
|
-
return Promise.all(this
|
|
235
|
+
return Promise.all(_class_private_field_get(this, _callbacks).map((callback) => callback(...args)));
|
|
196
236
|
}
|
|
197
237
|
async callSerial(...args) {
|
|
198
238
|
const results = [];
|
|
199
|
-
for (const callback of this
|
|
239
|
+
for (const callback of _class_private_field_get(this, _callbacks)) {
|
|
200
240
|
results.push(await callback(...args));
|
|
201
241
|
}
|
|
202
242
|
return results;
|
|
203
243
|
}
|
|
244
|
+
constructor() {
|
|
245
|
+
_class_private_field_init(this, _callbacks, {
|
|
246
|
+
writable: true,
|
|
247
|
+
value: []
|
|
248
|
+
});
|
|
249
|
+
}
|
|
204
250
|
};
|
|
205
251
|
|
|
206
252
|
// src/callback.ts
|
|
207
253
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
254
|
+
function _define_property(obj, key, value) {
|
|
255
|
+
if (key in obj) {
|
|
256
|
+
Object.defineProperty(obj, key, {
|
|
257
|
+
value,
|
|
258
|
+
enumerable: true,
|
|
259
|
+
configurable: true,
|
|
260
|
+
writable: true
|
|
261
|
+
});
|
|
262
|
+
} else {
|
|
263
|
+
obj[key] = value;
|
|
264
|
+
}
|
|
265
|
+
return obj;
|
|
266
|
+
}
|
|
208
267
|
var __dxlog_file2 = "/__w/dxos/dxos/packages/common/util/src/callback.ts";
|
|
209
268
|
var Callback = class {
|
|
210
269
|
call(...args) {
|
|
@@ -237,6 +296,9 @@ var Callback = class {
|
|
|
237
296
|
isSet() {
|
|
238
297
|
return !!this._callback;
|
|
239
298
|
}
|
|
299
|
+
constructor() {
|
|
300
|
+
_define_property(this, "_callback", void 0);
|
|
301
|
+
}
|
|
240
302
|
};
|
|
241
303
|
var createSetDispatch = ({ handlers }) => {
|
|
242
304
|
return new Proxy({
|
|
@@ -299,22 +361,21 @@ var chunkArray = (array, size) => {
|
|
|
299
361
|
|
|
300
362
|
// src/circular-buffer.ts
|
|
301
363
|
import { invariant as invariant3 } from "@dxos/invariant";
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
L: 13,
|
|
310
|
-
S: this,
|
|
311
|
-
A: [
|
|
312
|
-
"size >= 1",
|
|
313
|
-
""
|
|
314
|
-
]
|
|
364
|
+
function _define_property2(obj, key, value) {
|
|
365
|
+
if (key in obj) {
|
|
366
|
+
Object.defineProperty(obj, key, {
|
|
367
|
+
value,
|
|
368
|
+
enumerable: true,
|
|
369
|
+
configurable: true,
|
|
370
|
+
writable: true
|
|
315
371
|
});
|
|
316
|
-
|
|
372
|
+
} else {
|
|
373
|
+
obj[key] = value;
|
|
317
374
|
}
|
|
375
|
+
return obj;
|
|
376
|
+
}
|
|
377
|
+
var __dxlog_file3 = "/__w/dxos/dxos/packages/common/util/src/circular-buffer.ts";
|
|
378
|
+
var CircularBuffer = class {
|
|
318
379
|
push(element) {
|
|
319
380
|
const evicted = this._elementCount === this._buffer.length ? this._buffer[this._nextIndex] : void 0;
|
|
320
381
|
this._buffer[this._nextIndex] = element;
|
|
@@ -354,6 +415,21 @@ var CircularBuffer = class {
|
|
|
354
415
|
yield this._buffer[i];
|
|
355
416
|
}
|
|
356
417
|
}
|
|
418
|
+
constructor(size) {
|
|
419
|
+
_define_property2(this, "_buffer", void 0);
|
|
420
|
+
_define_property2(this, "_nextIndex", 0);
|
|
421
|
+
_define_property2(this, "_elementCount", 0);
|
|
422
|
+
invariant3(size >= 1, void 0, {
|
|
423
|
+
F: __dxlog_file3,
|
|
424
|
+
L: 13,
|
|
425
|
+
S: this,
|
|
426
|
+
A: [
|
|
427
|
+
"size >= 1",
|
|
428
|
+
""
|
|
429
|
+
]
|
|
430
|
+
});
|
|
431
|
+
this._buffer = new Array(size);
|
|
432
|
+
}
|
|
357
433
|
};
|
|
358
434
|
|
|
359
435
|
// src/clear-undefined.ts
|
|
@@ -372,18 +448,22 @@ var clearUndefined = (obj) => {
|
|
|
372
448
|
// src/complex.ts
|
|
373
449
|
import { inspect } from "@dxos/node-std/util";
|
|
374
450
|
import { inspectObject, raise } from "@dxos/debug";
|
|
451
|
+
function _define_property3(obj, key, value) {
|
|
452
|
+
if (key in obj) {
|
|
453
|
+
Object.defineProperty(obj, key, {
|
|
454
|
+
value,
|
|
455
|
+
enumerable: true,
|
|
456
|
+
configurable: true,
|
|
457
|
+
writable: true
|
|
458
|
+
});
|
|
459
|
+
} else {
|
|
460
|
+
obj[key] = value;
|
|
461
|
+
}
|
|
462
|
+
return obj;
|
|
463
|
+
}
|
|
375
464
|
var MAX_SERIALIZATION_LENGTH = 10;
|
|
465
|
+
var _inspect_custom = inspect.custom;
|
|
376
466
|
var ComplexSet = class {
|
|
377
|
-
// prettier-ignore
|
|
378
|
-
constructor(_projection, values) {
|
|
379
|
-
this._projection = _projection;
|
|
380
|
-
this._values = /* @__PURE__ */ new Map();
|
|
381
|
-
if (values) {
|
|
382
|
-
for (const value of values) {
|
|
383
|
-
this.add(value);
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
467
|
toString() {
|
|
388
468
|
return inspectObject(this);
|
|
389
469
|
}
|
|
@@ -392,7 +472,7 @@ var ComplexSet = class {
|
|
|
392
472
|
size: this._values.size
|
|
393
473
|
} : Array.from(this._values.values());
|
|
394
474
|
}
|
|
395
|
-
[
|
|
475
|
+
[_inspect_custom]() {
|
|
396
476
|
return inspectObject(this);
|
|
397
477
|
}
|
|
398
478
|
add(value) {
|
|
@@ -458,6 +538,18 @@ var ComplexSet = class {
|
|
|
458
538
|
isDisjointFrom(other) {
|
|
459
539
|
throw new Error("Method not implemented.");
|
|
460
540
|
}
|
|
541
|
+
// prettier-ignore
|
|
542
|
+
constructor(_projection, values) {
|
|
543
|
+
_define_property3(this, "_projection", void 0);
|
|
544
|
+
_define_property3(this, "_values", void 0);
|
|
545
|
+
this._projection = _projection;
|
|
546
|
+
this._values = /* @__PURE__ */ new Map();
|
|
547
|
+
if (values) {
|
|
548
|
+
for (const value of values) {
|
|
549
|
+
this.add(value);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
}
|
|
461
553
|
};
|
|
462
554
|
var makeSet = (projection) => {
|
|
463
555
|
return class BoundComplexSet extends ComplexSet {
|
|
@@ -466,18 +558,8 @@ var makeSet = (projection) => {
|
|
|
466
558
|
}
|
|
467
559
|
};
|
|
468
560
|
};
|
|
561
|
+
var _inspect_custom1 = inspect.custom;
|
|
469
562
|
var ComplexMap = class _ComplexMap {
|
|
470
|
-
// prettier-ignore
|
|
471
|
-
constructor(_keyProjection, entries2) {
|
|
472
|
-
this._keyProjection = _keyProjection;
|
|
473
|
-
this._keys = /* @__PURE__ */ new Map();
|
|
474
|
-
this._values = /* @__PURE__ */ new Map();
|
|
475
|
-
if (entries2) {
|
|
476
|
-
for (const [key, value] of entries2) {
|
|
477
|
-
this.set(key, value);
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
563
|
toString() {
|
|
482
564
|
return inspectObject(this);
|
|
483
565
|
}
|
|
@@ -486,7 +568,7 @@ var ComplexMap = class _ComplexMap {
|
|
|
486
568
|
size: this._values.size
|
|
487
569
|
} : Array.from(this._values.values());
|
|
488
570
|
}
|
|
489
|
-
[
|
|
571
|
+
[_inspect_custom1]() {
|
|
490
572
|
return inspectObject(this);
|
|
491
573
|
}
|
|
492
574
|
clear() {
|
|
@@ -548,11 +630,28 @@ var ComplexMap = class _ComplexMap {
|
|
|
548
630
|
get [Symbol.toStringTag]() {
|
|
549
631
|
return "ComplexMap";
|
|
550
632
|
}
|
|
633
|
+
// prettier-ignore
|
|
634
|
+
constructor(_keyProjection, entries2) {
|
|
635
|
+
_define_property3(this, "_keyProjection", void 0);
|
|
636
|
+
_define_property3(this, "_keys", void 0);
|
|
637
|
+
_define_property3(this, "_values", void 0);
|
|
638
|
+
this._keyProjection = _keyProjection;
|
|
639
|
+
this._keys = /* @__PURE__ */ new Map();
|
|
640
|
+
this._values = /* @__PURE__ */ new Map();
|
|
641
|
+
if (entries2) {
|
|
642
|
+
for (const [key, value] of entries2) {
|
|
643
|
+
this.set(key, value);
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
}
|
|
551
647
|
};
|
|
552
|
-
var makeMap = (keyProjection) =>
|
|
553
|
-
|
|
554
|
-
|
|
648
|
+
var makeMap = (keyProjection) => {
|
|
649
|
+
class BoundComplexMap extends ComplexMap {
|
|
650
|
+
constructor(entries2) {
|
|
651
|
+
super(keyProjection, entries2);
|
|
652
|
+
}
|
|
555
653
|
}
|
|
654
|
+
return BoundComplexMap;
|
|
556
655
|
};
|
|
557
656
|
|
|
558
657
|
// src/deep.ts
|
|
@@ -593,49 +692,71 @@ var getDeep = (obj, path) => {
|
|
|
593
692
|
var deferFunction = (fnProvider) => (...args) => fnProvider()(...args);
|
|
594
693
|
|
|
595
694
|
// src/explicit-resource-management-polyfill.ts
|
|
596
|
-
|
|
597
|
-
|
|
695
|
+
var _Symbol;
|
|
696
|
+
var _Symbol1;
|
|
697
|
+
(_Symbol = Symbol).dispose ?? (_Symbol.dispose = Symbol("Symbol.dispose"));
|
|
698
|
+
(_Symbol1 = Symbol).asyncDispose ?? (_Symbol1.asyncDispose = Symbol("Symbol.asyncDispose"));
|
|
598
699
|
|
|
599
700
|
// src/defer.ts
|
|
701
|
+
function _define_property4(obj, key, value) {
|
|
702
|
+
if (key in obj) {
|
|
703
|
+
Object.defineProperty(obj, key, {
|
|
704
|
+
value,
|
|
705
|
+
enumerable: true,
|
|
706
|
+
configurable: true,
|
|
707
|
+
writable: true
|
|
708
|
+
});
|
|
709
|
+
} else {
|
|
710
|
+
obj[key] = value;
|
|
711
|
+
}
|
|
712
|
+
return obj;
|
|
713
|
+
}
|
|
600
714
|
var defer = (fn) => new DeferGuard(fn);
|
|
601
715
|
var DeferGuard = class {
|
|
602
|
-
/**
|
|
603
|
-
* @internal
|
|
604
|
-
*/
|
|
605
|
-
constructor(_fn) {
|
|
606
|
-
this._fn = _fn;
|
|
607
|
-
}
|
|
608
716
|
[Symbol.dispose]() {
|
|
609
717
|
const result = this._fn();
|
|
610
718
|
if (result instanceof Promise) {
|
|
611
719
|
throw new Error("Async functions in defer are not supported. Use deferAsync instead.");
|
|
612
720
|
}
|
|
613
721
|
}
|
|
614
|
-
};
|
|
615
|
-
var deferAsync = (fn) => new DeferAsyncGuard(fn);
|
|
616
|
-
var DeferAsyncGuard = class {
|
|
617
722
|
/**
|
|
618
723
|
* @internal
|
|
619
724
|
*/
|
|
620
725
|
constructor(_fn) {
|
|
726
|
+
_define_property4(this, "_fn", void 0);
|
|
621
727
|
this._fn = _fn;
|
|
622
728
|
}
|
|
729
|
+
};
|
|
730
|
+
var deferAsync = (fn) => new DeferAsyncGuard(fn);
|
|
731
|
+
var DeferAsyncGuard = class {
|
|
623
732
|
async [Symbol.asyncDispose]() {
|
|
624
733
|
await this._fn();
|
|
625
734
|
}
|
|
735
|
+
/**
|
|
736
|
+
* @internal
|
|
737
|
+
*/
|
|
738
|
+
constructor(_fn) {
|
|
739
|
+
_define_property4(this, "_fn", void 0);
|
|
740
|
+
this._fn = _fn;
|
|
741
|
+
}
|
|
626
742
|
};
|
|
627
743
|
|
|
628
744
|
// src/entry.ts
|
|
745
|
+
function _define_property5(obj, key, value) {
|
|
746
|
+
if (key in obj) {
|
|
747
|
+
Object.defineProperty(obj, key, {
|
|
748
|
+
value,
|
|
749
|
+
enumerable: true,
|
|
750
|
+
configurable: true,
|
|
751
|
+
writable: true
|
|
752
|
+
});
|
|
753
|
+
} else {
|
|
754
|
+
obj[key] = value;
|
|
755
|
+
}
|
|
756
|
+
return obj;
|
|
757
|
+
}
|
|
629
758
|
var entry = (map, key) => new MapEntry(map, key);
|
|
630
759
|
var MapEntry = class {
|
|
631
|
-
/**
|
|
632
|
-
* @internal
|
|
633
|
-
*/
|
|
634
|
-
// prettier-ignore
|
|
635
|
-
constructor(_map, _key) {
|
|
636
|
-
this._map = _map;
|
|
637
|
-
this._key = _key;
|
|
638
|
-
}
|
|
639
760
|
get key() {
|
|
640
761
|
return this._key;
|
|
641
762
|
}
|
|
@@ -651,33 +772,16 @@ var MapEntry = class {
|
|
|
651
772
|
deep(key) {
|
|
652
773
|
return entry(this.value, key);
|
|
653
774
|
}
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
];
|
|
664
|
-
let foundFirst = false;
|
|
665
|
-
for (let i = 0; i < characters.length; i++) {
|
|
666
|
-
const char = characters[i];
|
|
667
|
-
if (renderableCharRegex.test(char)) {
|
|
668
|
-
if (!foundFirst) {
|
|
669
|
-
result[0] = char;
|
|
670
|
-
foundFirst = true;
|
|
671
|
-
} else {
|
|
672
|
-
const textBetween = characters.slice(result[0].length, i).join("");
|
|
673
|
-
if (/[^\p{L}\p{N}_]/u.test(textBetween)) {
|
|
674
|
-
result[1] = char;
|
|
675
|
-
break;
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
}
|
|
775
|
+
/**
|
|
776
|
+
* @internal
|
|
777
|
+
*/
|
|
778
|
+
// prettier-ignore
|
|
779
|
+
constructor(_map, _key) {
|
|
780
|
+
_define_property5(this, "_map", void 0);
|
|
781
|
+
_define_property5(this, "_key", void 0);
|
|
782
|
+
this._map = _map;
|
|
783
|
+
this._key = _key;
|
|
679
784
|
}
|
|
680
|
-
return result;
|
|
681
785
|
};
|
|
682
786
|
|
|
683
787
|
// src/for-each-async.ts
|
|
@@ -685,6 +789,19 @@ var forEachAsync = (items, fn) => Promise.all(items.map(fn));
|
|
|
685
789
|
|
|
686
790
|
// src/human-hash.ts
|
|
687
791
|
import { PublicKey } from "@dxos/keys";
|
|
792
|
+
function _define_property6(obj, key, value) {
|
|
793
|
+
if (key in obj) {
|
|
794
|
+
Object.defineProperty(obj, key, {
|
|
795
|
+
value,
|
|
796
|
+
enumerable: true,
|
|
797
|
+
configurable: true,
|
|
798
|
+
writable: true
|
|
799
|
+
});
|
|
800
|
+
} else {
|
|
801
|
+
obj[key] = value;
|
|
802
|
+
}
|
|
803
|
+
return obj;
|
|
804
|
+
}
|
|
688
805
|
var DEFAULT_WORDLIST = [
|
|
689
806
|
"ack",
|
|
690
807
|
"alabama",
|
|
@@ -944,26 +1061,6 @@ var DEFAULT_WORDLIST = [
|
|
|
944
1061
|
"zulu"
|
|
945
1062
|
];
|
|
946
1063
|
var HumanHasher = class {
|
|
947
|
-
/**
|
|
948
|
-
* Transforms hex digests to human-readable strings.
|
|
949
|
-
*
|
|
950
|
-
* The format of these strings will look something like:
|
|
951
|
-
* `victor-bacon-zulu-lima`. The output is obtained by compressing the input
|
|
952
|
-
* digest to a fixed number of bytes, then mapping those bytes to one of 256
|
|
953
|
-
* words. A default wordlist is provided, but you can override this if you
|
|
954
|
-
* prefer.
|
|
955
|
-
* As long as you use the same wordlist, the output will be consistent (i.e.
|
|
956
|
-
* the same digest will always render the same representation).
|
|
957
|
-
*
|
|
958
|
-
* @param wordlist A list of exactly 256 words to choose from
|
|
959
|
-
*/
|
|
960
|
-
constructor(wordlist = DEFAULT_WORDLIST) {
|
|
961
|
-
this.wordlist = wordlist;
|
|
962
|
-
if (wordlist.length !== 256) {
|
|
963
|
-
throw new Error("Wordlist must have exactly 256 items");
|
|
964
|
-
}
|
|
965
|
-
this.wordlist = wordlist;
|
|
966
|
-
}
|
|
967
1064
|
/**
|
|
968
1065
|
* Humanize a given hexadecimal digest.
|
|
969
1066
|
*
|
|
@@ -1003,6 +1100,27 @@ var HumanHasher = class {
|
|
|
1003
1100
|
const checksums = segments.map((x) => x.reduce((acc, curr) => acc ^ curr));
|
|
1004
1101
|
return checksums;
|
|
1005
1102
|
}
|
|
1103
|
+
/**
|
|
1104
|
+
* Transforms hex digests to human-readable strings.
|
|
1105
|
+
*
|
|
1106
|
+
* The format of these strings will look something like:
|
|
1107
|
+
* `victor-bacon-zulu-lima`. The output is obtained by compressing the input
|
|
1108
|
+
* digest to a fixed number of bytes, then mapping those bytes to one of 256
|
|
1109
|
+
* words. A default wordlist is provided, but you can override this if you
|
|
1110
|
+
* prefer.
|
|
1111
|
+
* As long as you use the same wordlist, the output will be consistent (i.e.
|
|
1112
|
+
* the same digest will always render the same representation).
|
|
1113
|
+
*
|
|
1114
|
+
* @param wordlist A list of exactly 256 words to choose from
|
|
1115
|
+
*/
|
|
1116
|
+
constructor(wordlist = DEFAULT_WORDLIST) {
|
|
1117
|
+
_define_property6(this, "wordlist", void 0);
|
|
1118
|
+
this.wordlist = wordlist;
|
|
1119
|
+
if (wordlist.length !== 256) {
|
|
1120
|
+
throw new Error("Wordlist must have exactly 256 items");
|
|
1121
|
+
}
|
|
1122
|
+
this.wordlist = wordlist;
|
|
1123
|
+
}
|
|
1006
1124
|
};
|
|
1007
1125
|
var hasher = new HumanHasher();
|
|
1008
1126
|
var humanize = (value) => {
|
|
@@ -1025,8 +1143,10 @@ var defaultMap = (map, key, def) => {
|
|
|
1025
1143
|
};
|
|
1026
1144
|
|
|
1027
1145
|
// src/instance-id.ts
|
|
1146
|
+
var _globalThis;
|
|
1147
|
+
var _symbol;
|
|
1028
1148
|
var symbol = Symbol.for("dxos.instance-contexts");
|
|
1029
|
-
var instanceContexts = globalThis[symbol]
|
|
1149
|
+
var instanceContexts = (_globalThis = globalThis)[_symbol = symbol] ?? (_globalThis[_symbol] = /* @__PURE__ */ new WeakMap());
|
|
1030
1150
|
var getPrototypeSpecificInstanceId = (instance) => {
|
|
1031
1151
|
const prototype = Object.getPrototypeOf(instance);
|
|
1032
1152
|
const instanceCtx = defaultMap(instanceContexts, prototype, () => ({
|
|
@@ -1198,6 +1318,19 @@ var jsonKeyReplacer = (options = {}) => (key, value) => {
|
|
|
1198
1318
|
};
|
|
1199
1319
|
|
|
1200
1320
|
// src/map-values.ts
|
|
1321
|
+
function _define_property7(obj, key, value) {
|
|
1322
|
+
if (key in obj) {
|
|
1323
|
+
Object.defineProperty(obj, key, {
|
|
1324
|
+
value,
|
|
1325
|
+
enumerable: true,
|
|
1326
|
+
configurable: true,
|
|
1327
|
+
writable: true
|
|
1328
|
+
});
|
|
1329
|
+
} else {
|
|
1330
|
+
obj[key] = value;
|
|
1331
|
+
}
|
|
1332
|
+
return obj;
|
|
1333
|
+
}
|
|
1201
1334
|
var mapValues = (obj, fn) => {
|
|
1202
1335
|
const result = {};
|
|
1203
1336
|
Object.keys(obj).forEach((key) => {
|
|
@@ -1209,7 +1342,19 @@ var deepMapValues = (value, fn) => {
|
|
|
1209
1342
|
return new DeepMapper(fn).map(value);
|
|
1210
1343
|
};
|
|
1211
1344
|
var DeepMapper = class {
|
|
1345
|
+
map(value) {
|
|
1346
|
+
return this._map(value, void 0);
|
|
1347
|
+
}
|
|
1348
|
+
_map(value, key) {
|
|
1349
|
+
if (this._cyclic.has(value)) {
|
|
1350
|
+
return this._cyclic.get(value);
|
|
1351
|
+
}
|
|
1352
|
+
return this._fn(value, this._recurse, key);
|
|
1353
|
+
}
|
|
1212
1354
|
constructor(_fn) {
|
|
1355
|
+
_define_property7(this, "_fn", void 0);
|
|
1356
|
+
_define_property7(this, "_cyclic", void 0);
|
|
1357
|
+
_define_property7(this, "_recurse", void 0);
|
|
1213
1358
|
this._fn = _fn;
|
|
1214
1359
|
this._cyclic = /* @__PURE__ */ new Map();
|
|
1215
1360
|
this._recurse = (value) => {
|
|
@@ -1235,6 +1380,11 @@ var DeepMapper = class {
|
|
|
1235
1380
|
}
|
|
1236
1381
|
};
|
|
1237
1382
|
}
|
|
1383
|
+
};
|
|
1384
|
+
var deepMapValuesAsync = (value, fn) => {
|
|
1385
|
+
return new DeepMapperAsync(fn).map(value);
|
|
1386
|
+
};
|
|
1387
|
+
var DeepMapperAsync = class {
|
|
1238
1388
|
map(value) {
|
|
1239
1389
|
return this._map(value, void 0);
|
|
1240
1390
|
}
|
|
@@ -1244,12 +1394,10 @@ var DeepMapper = class {
|
|
|
1244
1394
|
}
|
|
1245
1395
|
return this._fn(value, this._recurse, key);
|
|
1246
1396
|
}
|
|
1247
|
-
};
|
|
1248
|
-
var deepMapValuesAsync = (value, fn) => {
|
|
1249
|
-
return new DeepMapperAsync(fn).map(value);
|
|
1250
|
-
};
|
|
1251
|
-
var DeepMapperAsync = class {
|
|
1252
1397
|
constructor(_fn) {
|
|
1398
|
+
_define_property7(this, "_fn", void 0);
|
|
1399
|
+
_define_property7(this, "_cyclic", void 0);
|
|
1400
|
+
_define_property7(this, "_recurse", void 0);
|
|
1253
1401
|
this._fn = _fn;
|
|
1254
1402
|
this._cyclic = /* @__PURE__ */ new Map();
|
|
1255
1403
|
this._recurse = async (value) => {
|
|
@@ -1275,15 +1423,6 @@ var DeepMapperAsync = class {
|
|
|
1275
1423
|
}
|
|
1276
1424
|
};
|
|
1277
1425
|
}
|
|
1278
|
-
map(value) {
|
|
1279
|
-
return this._map(value, void 0);
|
|
1280
|
-
}
|
|
1281
|
-
_map(value, key) {
|
|
1282
|
-
if (this._cyclic.has(value)) {
|
|
1283
|
-
return this._cyclic.get(value);
|
|
1284
|
-
}
|
|
1285
|
-
return this._fn(value, this._recurse, key);
|
|
1286
|
-
}
|
|
1287
1426
|
};
|
|
1288
1427
|
var visitValues = (object, visitor) => {
|
|
1289
1428
|
if (Array.isArray(object)) {
|
|
@@ -1605,7 +1744,7 @@ var safeParseInt = (value, defaultValue) => {
|
|
|
1605
1744
|
try {
|
|
1606
1745
|
const n = parseInt(value ?? "");
|
|
1607
1746
|
return isNaN(n) ? defaultValue : n;
|
|
1608
|
-
} catch
|
|
1747
|
+
} catch {
|
|
1609
1748
|
return defaultValue;
|
|
1610
1749
|
}
|
|
1611
1750
|
};
|
|
@@ -1620,7 +1759,7 @@ var safeParseJson = (data, defaultValue) => {
|
|
|
1620
1759
|
if (data && data.length > 0) {
|
|
1621
1760
|
try {
|
|
1622
1761
|
return JSON.parse(data);
|
|
1623
|
-
} catch
|
|
1762
|
+
} catch {
|
|
1624
1763
|
}
|
|
1625
1764
|
}
|
|
1626
1765
|
return defaultValue;
|
|
@@ -1628,24 +1767,21 @@ var safeParseJson = (data, defaultValue) => {
|
|
|
1628
1767
|
|
|
1629
1768
|
// src/sliding-window-summary.ts
|
|
1630
1769
|
import { invariant as invariant5 } from "@dxos/invariant";
|
|
1770
|
+
function _define_property8(obj, key, value) {
|
|
1771
|
+
if (key in obj) {
|
|
1772
|
+
Object.defineProperty(obj, key, {
|
|
1773
|
+
value,
|
|
1774
|
+
enumerable: true,
|
|
1775
|
+
configurable: true,
|
|
1776
|
+
writable: true
|
|
1777
|
+
});
|
|
1778
|
+
} else {
|
|
1779
|
+
obj[key] = value;
|
|
1780
|
+
}
|
|
1781
|
+
return obj;
|
|
1782
|
+
}
|
|
1631
1783
|
var __dxlog_file5 = "/__w/dxos/dxos/packages/common/util/src/sliding-window-summary.ts";
|
|
1632
1784
|
var SlidingWindowSummary = class {
|
|
1633
|
-
constructor(options) {
|
|
1634
|
-
this._sum = 0;
|
|
1635
|
-
this._buffer = new CircularBuffer(options.dataPoints);
|
|
1636
|
-
if (options.precision != null) {
|
|
1637
|
-
invariant5(options.precision >= 0, void 0, {
|
|
1638
|
-
F: __dxlog_file5,
|
|
1639
|
-
L: 26,
|
|
1640
|
-
S: this,
|
|
1641
|
-
A: [
|
|
1642
|
-
"options.precision >= 0",
|
|
1643
|
-
""
|
|
1644
|
-
]
|
|
1645
|
-
});
|
|
1646
|
-
this._precision = Math.pow(10, options.precision);
|
|
1647
|
-
}
|
|
1648
|
-
}
|
|
1649
1785
|
record(value) {
|
|
1650
1786
|
const evicted = this._buffer.push(value);
|
|
1651
1787
|
this._sum += value - (evicted ?? 0);
|
|
@@ -1680,6 +1816,24 @@ var SlidingWindowSummary = class {
|
|
|
1680
1816
|
}
|
|
1681
1817
|
return Math.round(value * this._precision) / this._precision;
|
|
1682
1818
|
}
|
|
1819
|
+
constructor(options) {
|
|
1820
|
+
_define_property8(this, "_buffer", void 0);
|
|
1821
|
+
_define_property8(this, "_sum", 0);
|
|
1822
|
+
_define_property8(this, "_precision", void 0);
|
|
1823
|
+
this._buffer = new CircularBuffer(options.dataPoints);
|
|
1824
|
+
if (options.precision != null) {
|
|
1825
|
+
invariant5(options.precision >= 0, void 0, {
|
|
1826
|
+
F: __dxlog_file5,
|
|
1827
|
+
L: 26,
|
|
1828
|
+
S: this,
|
|
1829
|
+
A: [
|
|
1830
|
+
"options.precision >= 0",
|
|
1831
|
+
""
|
|
1832
|
+
]
|
|
1833
|
+
});
|
|
1834
|
+
this._precision = Math.pow(10, options.precision);
|
|
1835
|
+
}
|
|
1836
|
+
}
|
|
1683
1837
|
};
|
|
1684
1838
|
|
|
1685
1839
|
// src/sort.ts
|
|
@@ -1711,12 +1865,24 @@ var capitalize = (str) => {
|
|
|
1711
1865
|
}
|
|
1712
1866
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
1713
1867
|
};
|
|
1714
|
-
|
|
1715
|
-
const
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1868
|
+
function trim(strings, ...values) {
|
|
1869
|
+
const raw = strings.reduce((out, str, i) => {
|
|
1870
|
+
out += str;
|
|
1871
|
+
if (i < values.length) {
|
|
1872
|
+
const match = str.match(/(^|\n)([ \t]*)$/);
|
|
1873
|
+
const baseIndent = match ? match[2] : "";
|
|
1874
|
+
const val = String(values[i]).replace(/\r?\n/g, "\n" + baseIndent);
|
|
1875
|
+
out += val;
|
|
1876
|
+
}
|
|
1877
|
+
return out;
|
|
1878
|
+
}, "");
|
|
1879
|
+
const lines = raw.split("\n");
|
|
1880
|
+
while (lines.length && !lines[0].trim()) lines.shift();
|
|
1881
|
+
while (lines.length && !lines[lines.length - 1].trim()) lines.pop();
|
|
1882
|
+
const minIndent = Math.min(...lines.filter((l) => l.trim()).map((l) => l.match(/^[ \t]*/)?.[0].length ?? 0));
|
|
1883
|
+
return lines.map((l) => l.slice(minIndent)).join("\n");
|
|
1884
|
+
}
|
|
1885
|
+
var kebabize = (str) => str.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? "-" : "") + $.toLowerCase());
|
|
1720
1886
|
|
|
1721
1887
|
// src/sum.ts
|
|
1722
1888
|
var sum = (values) => values.reduce((a, b) => a + b, 0);
|
|
@@ -1914,11 +2080,20 @@ var toFallback = (hash) => {
|
|
|
1914
2080
|
};
|
|
1915
2081
|
|
|
1916
2082
|
// src/tracer.ts
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
2083
|
+
function _define_property9(obj, key, value) {
|
|
2084
|
+
if (key in obj) {
|
|
2085
|
+
Object.defineProperty(obj, key, {
|
|
2086
|
+
value,
|
|
2087
|
+
enumerable: true,
|
|
2088
|
+
configurable: true,
|
|
2089
|
+
writable: true
|
|
2090
|
+
});
|
|
2091
|
+
} else {
|
|
2092
|
+
obj[key] = value;
|
|
1921
2093
|
}
|
|
2094
|
+
return obj;
|
|
2095
|
+
}
|
|
2096
|
+
var Tracer = class {
|
|
1922
2097
|
// TODO(burdon): Start/stop methods for recording data? By id?
|
|
1923
2098
|
// Alternatively, enable subscriptions to track/compute series.
|
|
1924
2099
|
// TODO(burdon): Hierarchical traces?
|
|
@@ -1975,6 +2150,10 @@ var Tracer = class {
|
|
|
1975
2150
|
defaultMap(this._events, event.id, []).push(event);
|
|
1976
2151
|
}
|
|
1977
2152
|
}
|
|
2153
|
+
constructor() {
|
|
2154
|
+
_define_property9(this, "_events", /* @__PURE__ */ new Map());
|
|
2155
|
+
_define_property9(this, "_recording", false);
|
|
2156
|
+
}
|
|
1978
2157
|
};
|
|
1979
2158
|
var tracer = new Tracer();
|
|
1980
2159
|
|
|
@@ -2019,7 +2198,7 @@ var stringifyTree = (node, ancestors = [], rows = []) => {
|
|
|
2019
2198
|
};
|
|
2020
2199
|
|
|
2021
2200
|
// src/types.ts
|
|
2022
|
-
var
|
|
2201
|
+
var isTruthy = (value) => !!value;
|
|
2023
2202
|
var isNonNullable = (value) => value != null;
|
|
2024
2203
|
var doAsync = async (fn) => fn();
|
|
2025
2204
|
var getProviderValue = (provider, arg) => {
|
|
@@ -2050,6 +2229,70 @@ var arrayMove = (array, from, to) => {
|
|
|
2050
2229
|
return array;
|
|
2051
2230
|
};
|
|
2052
2231
|
|
|
2232
|
+
// src/unit.ts
|
|
2233
|
+
var Formatter = (unit) => {
|
|
2234
|
+
return (n, precision = 2) => {
|
|
2235
|
+
const value = n / unit.quotient;
|
|
2236
|
+
return `${value.toFixed(precision)}${unit.symbol}`;
|
|
2237
|
+
};
|
|
2238
|
+
};
|
|
2239
|
+
var Unit = {
|
|
2240
|
+
// ms.
|
|
2241
|
+
Hour: Formatter({
|
|
2242
|
+
symbol: "h",
|
|
2243
|
+
quotient: 60 * 60 * 1e3
|
|
2244
|
+
}),
|
|
2245
|
+
Minute: Formatter({
|
|
2246
|
+
symbol: "m",
|
|
2247
|
+
quotient: 60 * 1e3
|
|
2248
|
+
}),
|
|
2249
|
+
Second: Formatter({
|
|
2250
|
+
symbol: "s",
|
|
2251
|
+
quotient: 1e3
|
|
2252
|
+
}),
|
|
2253
|
+
Millisecond: Formatter({
|
|
2254
|
+
symbol: "ms",
|
|
2255
|
+
quotient: 1
|
|
2256
|
+
}),
|
|
2257
|
+
Duration: (n) => {
|
|
2258
|
+
const hours = Math.floor(n / (60 * 60 * 1e3));
|
|
2259
|
+
const minutes = Math.floor(n % (60 * 60 * 1e3) / (60 * 1e3));
|
|
2260
|
+
if (hours) {
|
|
2261
|
+
return minutes ? `${hours}h ${minutes}m` : `${hours}h`;
|
|
2262
|
+
}
|
|
2263
|
+
const seconds = Math.floor(n % (60 * 1e3) / 1e3);
|
|
2264
|
+
if (minutes) {
|
|
2265
|
+
return seconds ? `${minutes}m ${seconds}s` : `${minutes}m`;
|
|
2266
|
+
}
|
|
2267
|
+
if (seconds) {
|
|
2268
|
+
return `${(n / 1e3).toFixed(1)}s`;
|
|
2269
|
+
}
|
|
2270
|
+
return `${n}ms`;
|
|
2271
|
+
},
|
|
2272
|
+
// bytes (note KB via KiB).
|
|
2273
|
+
Gigabyte: Formatter({
|
|
2274
|
+
symbol: "GB",
|
|
2275
|
+
quotient: 1e3 * 1e3 * 1e3
|
|
2276
|
+
}),
|
|
2277
|
+
Megabyte: Formatter({
|
|
2278
|
+
symbol: "MB",
|
|
2279
|
+
quotient: 1e3 * 1e3
|
|
2280
|
+
}),
|
|
2281
|
+
Kilobyte: Formatter({
|
|
2282
|
+
symbol: "KB",
|
|
2283
|
+
quotient: 1e3
|
|
2284
|
+
}),
|
|
2285
|
+
// general.
|
|
2286
|
+
Thousand: Formatter({
|
|
2287
|
+
symbol: "k",
|
|
2288
|
+
quotient: 1e3
|
|
2289
|
+
}),
|
|
2290
|
+
Percent: Formatter({
|
|
2291
|
+
symbol: "%",
|
|
2292
|
+
quotient: 1 / 100
|
|
2293
|
+
})
|
|
2294
|
+
};
|
|
2295
|
+
|
|
2053
2296
|
// src/url.ts
|
|
2054
2297
|
var createUrl = (url, search) => {
|
|
2055
2298
|
const base = typeof url === "string" ? new URL(url) : url;
|
|
@@ -2060,18 +2303,20 @@ var createUrl = (url, search) => {
|
|
|
2060
2303
|
};
|
|
2061
2304
|
|
|
2062
2305
|
// src/weak.ts
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2306
|
+
function _define_property10(obj, key, value) {
|
|
2307
|
+
if (key in obj) {
|
|
2308
|
+
Object.defineProperty(obj, key, {
|
|
2309
|
+
value,
|
|
2310
|
+
enumerable: true,
|
|
2311
|
+
configurable: true,
|
|
2312
|
+
writable: true
|
|
2068
2313
|
});
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
new WeakRef(value)
|
|
2072
|
-
]));
|
|
2073
|
-
entries2?.forEach(([key, value]) => this._register(key, value));
|
|
2314
|
+
} else {
|
|
2315
|
+
obj[key] = value;
|
|
2074
2316
|
}
|
|
2317
|
+
return obj;
|
|
2318
|
+
}
|
|
2319
|
+
var WeakDictionary = class {
|
|
2075
2320
|
*entries() {
|
|
2076
2321
|
for (const [key, value] of this._internal) {
|
|
2077
2322
|
yield [
|
|
@@ -2152,6 +2397,17 @@ var WeakDictionary = class {
|
|
|
2152
2397
|
_unregister(value) {
|
|
2153
2398
|
this._finalization.unregister(value);
|
|
2154
2399
|
}
|
|
2400
|
+
constructor(entries2) {
|
|
2401
|
+
_define_property10(this, "_internal", /* @__PURE__ */ new Map());
|
|
2402
|
+
_define_property10(this, "_finalization", new FinalizationRegistry((cleanUpCallback) => {
|
|
2403
|
+
cleanUpCallback();
|
|
2404
|
+
}));
|
|
2405
|
+
this._internal = new Map(entries2?.map(([key, value]) => [
|
|
2406
|
+
key,
|
|
2407
|
+
new WeakRef(value)
|
|
2408
|
+
]));
|
|
2409
|
+
entries2?.forEach(([key, value]) => this._register(key, value));
|
|
2410
|
+
}
|
|
2155
2411
|
};
|
|
2156
2412
|
export {
|
|
2157
2413
|
BitField,
|
|
@@ -2164,6 +2420,7 @@ export {
|
|
|
2164
2420
|
MapEntry,
|
|
2165
2421
|
SlidingWindowSummary,
|
|
2166
2422
|
Tracer,
|
|
2423
|
+
Unit,
|
|
2167
2424
|
WeakDictionary,
|
|
2168
2425
|
accessBy,
|
|
2169
2426
|
arrayMove,
|
|
@@ -2206,7 +2463,6 @@ export {
|
|
|
2206
2463
|
getDate,
|
|
2207
2464
|
getDebugName,
|
|
2208
2465
|
getDeep,
|
|
2209
|
-
getFirstTwoRenderableChars,
|
|
2210
2466
|
getHostPlatform,
|
|
2211
2467
|
getPrototypeSpecificInstanceId,
|
|
2212
2468
|
getProviderValue,
|
|
@@ -2224,12 +2480,13 @@ export {
|
|
|
2224
2480
|
iosCheck,
|
|
2225
2481
|
isNode,
|
|
2226
2482
|
isNonNullable,
|
|
2227
|
-
|
|
2483
|
+
isTruthy,
|
|
2228
2484
|
joinTables,
|
|
2229
2485
|
jsonKeyReplacer,
|
|
2230
2486
|
jsonReplacer,
|
|
2231
2487
|
jsonify,
|
|
2232
2488
|
jsonlogify,
|
|
2489
|
+
kebabize,
|
|
2233
2490
|
keyToEmoji,
|
|
2234
2491
|
keyToFallback,
|
|
2235
2492
|
keyToHue,
|