@dxos/util 0.8.4-main.406dc2a → 0.8.4-main.52d7546f51

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.
Files changed (49) hide show
  1. package/dist/lib/browser/index.mjs +447 -430
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/node-esm/index.mjs +447 -430
  5. package/dist/lib/node-esm/index.mjs.map +4 -4
  6. package/dist/lib/node-esm/meta.json +1 -1
  7. package/dist/types/src/array.d.ts +3 -2
  8. package/dist/types/src/array.d.ts.map +1 -1
  9. package/dist/types/src/deep.d.ts.map +1 -1
  10. package/dist/types/src/defer.d.ts +1 -1
  11. package/dist/types/src/defer.d.ts.map +1 -1
  12. package/dist/types/src/error-format.d.ts +5 -0
  13. package/dist/types/src/error-format.d.ts.map +1 -0
  14. package/dist/types/src/filename.d.ts +9 -0
  15. package/dist/types/src/filename.d.ts.map +1 -0
  16. package/dist/types/src/index.d.ts +4 -0
  17. package/dist/types/src/index.d.ts.map +1 -1
  18. package/dist/types/src/platform.d.ts +4 -1
  19. package/dist/types/src/platform.d.ts.map +1 -1
  20. package/dist/types/src/retry.d.ts +32 -0
  21. package/dist/types/src/retry.d.ts.map +1 -0
  22. package/dist/types/src/safe-parse.d.ts +6 -4
  23. package/dist/types/src/safe-parse.d.ts.map +1 -1
  24. package/dist/types/src/safe-stringify.d.ts +22 -0
  25. package/dist/types/src/safe-stringify.d.ts.map +1 -0
  26. package/dist/types/src/types.d.ts +22 -4
  27. package/dist/types/src/types.d.ts.map +1 -1
  28. package/dist/types/src/unit.d.ts +12 -13
  29. package/dist/types/src/unit.d.ts.map +1 -1
  30. package/dist/types/tsconfig.tsbuildinfo +1 -1
  31. package/package.json +12 -7
  32. package/src/array.ts +9 -2
  33. package/src/binder.ts +2 -2
  34. package/src/deep.ts +2 -0
  35. package/src/defer.ts +1 -1
  36. package/src/error-format.ts +22 -0
  37. package/src/filename.ts +16 -0
  38. package/src/index.ts +4 -0
  39. package/src/platform.ts +12 -2
  40. package/src/retry.ts +74 -0
  41. package/src/safe-parse.ts +19 -16
  42. package/src/safe-stringify.ts +146 -0
  43. package/src/types.test.ts +11 -1
  44. package/src/types.ts +37 -10
  45. package/src/unit.test.ts +1 -1
  46. package/src/unit.ts +59 -28
  47. package/dist/types/src/explicit-resource-management-polyfill.d.ts +0 -1
  48. package/dist/types/src/explicit-resource-management-polyfill.d.ts.map +0 -1
  49. package/src/explicit-resource-management-polyfill.ts +0 -13
@@ -97,16 +97,24 @@ var intersectBy = (arrays, selector) => {
97
97
  return lookups.every((lookup) => lookup.has(key));
98
98
  });
99
99
  };
100
+ var coerceArray = (arr) => {
101
+ if (arr === void 0) {
102
+ return [];
103
+ }
104
+ return Array.isArray(arr) ? arr : [
105
+ arr
106
+ ];
107
+ };
100
108
 
101
109
  // src/assume.ts
102
110
  function assumeType(value) {
103
111
  }
104
112
 
105
113
  // src/binder.ts
106
- import util from "@dxos/node-std/util";
114
+ import { promisify } from "@dxos/node-std/util";
107
115
  var createBinder = (obj) => ({
108
116
  fn: (fn) => fn.bind(obj),
109
- async: (fn) => util.promisify(fn.bind(obj))
117
+ async: (fn) => promisify(fn.bind(obj))
110
118
  });
111
119
 
112
120
  // src/bitfield.ts
@@ -180,92 +188,34 @@ var BitField = class _BitField {
180
188
  };
181
189
 
182
190
  // 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();
224
191
  var CallbackCollection = class {
192
+ #callbacks = [];
225
193
  append(callback) {
226
- _class_private_field_get(this, _callbacks).push(callback);
194
+ this.#callbacks.push(callback);
227
195
  }
228
196
  prepend(callback) {
229
- _class_private_field_get(this, _callbacks).unshift(callback);
197
+ this.#callbacks.unshift(callback);
230
198
  }
231
199
  remove(callback) {
232
- _class_private_field_set(this, _callbacks, _class_private_field_get(this, _callbacks).filter((c) => c !== callback));
200
+ this.#callbacks = this.#callbacks.filter((c) => c !== callback);
233
201
  }
234
202
  callParallel(...args) {
235
- return Promise.all(_class_private_field_get(this, _callbacks).map((callback) => callback(...args)));
203
+ return Promise.all(this.#callbacks.map((callback) => callback(...args)));
236
204
  }
237
205
  async callSerial(...args) {
238
206
  const results = [];
239
- for (const callback of _class_private_field_get(this, _callbacks)) {
207
+ for (const callback of this.#callbacks) {
240
208
  results.push(await callback(...args));
241
209
  }
242
210
  return results;
243
211
  }
244
- constructor() {
245
- _class_private_field_init(this, _callbacks, {
246
- writable: true,
247
- value: []
248
- });
249
- }
250
212
  };
251
213
 
252
214
  // src/callback.ts
253
215
  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
- }
267
216
  var __dxlog_file2 = "/__w/dxos/dxos/packages/common/util/src/callback.ts";
268
217
  var Callback = class {
218
+ _callback;
269
219
  call(...args) {
270
220
  invariant2(this._callback, "Callback not set", {
271
221
  F: __dxlog_file2,
@@ -296,9 +246,6 @@ var Callback = class {
296
246
  isSet() {
297
247
  return !!this._callback;
298
248
  }
299
- constructor() {
300
- _define_property(this, "_callback", void 0);
301
- }
302
249
  };
303
250
  var createSetDispatch = ({ handlers }) => {
304
251
  return new Proxy({
@@ -361,21 +308,23 @@ var chunkArray = (array, size) => {
361
308
 
362
309
  // src/circular-buffer.ts
363
310
  import { invariant as invariant3 } from "@dxos/invariant";
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
371
- });
372
- } else {
373
- obj[key] = value;
374
- }
375
- return obj;
376
- }
377
311
  var __dxlog_file3 = "/__w/dxos/dxos/packages/common/util/src/circular-buffer.ts";
378
312
  var CircularBuffer = class {
313
+ _buffer;
314
+ _nextIndex = 0;
315
+ _elementCount = 0;
316
+ constructor(size) {
317
+ invariant3(size >= 1, void 0, {
318
+ F: __dxlog_file3,
319
+ L: 13,
320
+ S: this,
321
+ A: [
322
+ "size >= 1",
323
+ ""
324
+ ]
325
+ });
326
+ this._buffer = new Array(size);
327
+ }
379
328
  push(element) {
380
329
  const evicted = this._elementCount === this._buffer.length ? this._buffer[this._nextIndex] : void 0;
381
330
  this._buffer[this._nextIndex] = element;
@@ -415,21 +364,6 @@ var CircularBuffer = class {
415
364
  yield this._buffer[i];
416
365
  }
417
366
  }
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
- }
433
367
  };
434
368
 
435
369
  // src/clear-undefined.ts
@@ -448,22 +382,19 @@ var clearUndefined = (obj) => {
448
382
  // src/complex.ts
449
383
  import { inspect } from "@dxos/node-std/util";
450
384
  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
- }
464
385
  var MAX_SERIALIZATION_LENGTH = 10;
465
- var _inspect_custom = inspect.custom;
466
386
  var ComplexSet = class {
387
+ _projection;
388
+ _values = /* @__PURE__ */ new Map();
389
+ // prettier-ignore
390
+ constructor(_projection, values) {
391
+ this._projection = _projection;
392
+ if (values) {
393
+ for (const value of values) {
394
+ this.add(value);
395
+ }
396
+ }
397
+ }
467
398
  toString() {
468
399
  return inspectObject(this);
469
400
  }
@@ -472,7 +403,7 @@ var ComplexSet = class {
472
403
  size: this._values.size
473
404
  } : Array.from(this._values.values());
474
405
  }
475
- [_inspect_custom]() {
406
+ [inspect.custom]() {
476
407
  return inspectObject(this);
477
408
  }
478
409
  add(value) {
@@ -538,18 +469,6 @@ var ComplexSet = class {
538
469
  isDisjointFrom(other) {
539
470
  throw new Error("Method not implemented.");
540
471
  }
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
- }
553
472
  };
554
473
  var makeSet = (projection) => {
555
474
  return class BoundComplexSet extends ComplexSet {
@@ -558,8 +477,19 @@ var makeSet = (projection) => {
558
477
  }
559
478
  };
560
479
  };
561
- var _inspect_custom1 = inspect.custom;
562
480
  var ComplexMap = class _ComplexMap {
481
+ _keyProjection;
482
+ _keys = /* @__PURE__ */ new Map();
483
+ _values = /* @__PURE__ */ new Map();
484
+ // prettier-ignore
485
+ constructor(_keyProjection, entries2) {
486
+ this._keyProjection = _keyProjection;
487
+ if (entries2) {
488
+ for (const [key, value] of entries2) {
489
+ this.set(key, value);
490
+ }
491
+ }
492
+ }
563
493
  toString() {
564
494
  return inspectObject(this);
565
495
  }
@@ -568,7 +498,7 @@ var ComplexMap = class _ComplexMap {
568
498
  size: this._values.size
569
499
  } : Array.from(this._values.values());
570
500
  }
571
- [_inspect_custom1]() {
501
+ [inspect.custom]() {
572
502
  return inspectObject(this);
573
503
  }
574
504
  clear() {
@@ -630,28 +560,11 @@ var ComplexMap = class _ComplexMap {
630
560
  get [Symbol.toStringTag]() {
631
561
  return "ComplexMap";
632
562
  }
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
- }
647
563
  };
648
- var makeMap = (keyProjection) => {
649
- class BoundComplexMap extends ComplexMap {
650
- constructor(entries2) {
651
- super(keyProjection, entries2);
652
- }
564
+ var makeMap = (keyProjection) => class BoundComplexMap extends ComplexMap {
565
+ constructor(entries2) {
566
+ super(keyProjection, entries2);
653
567
  }
654
- return BoundComplexMap;
655
568
  };
656
569
 
657
570
  // src/deep.ts
@@ -691,72 +604,51 @@ var getDeep = (obj, path) => {
691
604
  // src/defer-function.ts
692
605
  var deferFunction = (fnProvider) => (...args) => fnProvider()(...args);
693
606
 
694
- // src/explicit-resource-management-polyfill.ts
695
- var _Symbol;
696
- var _Symbol1;
697
- (_Symbol = Symbol).dispose ?? (_Symbol.dispose = Symbol("Symbol.dispose"));
698
- (_Symbol1 = Symbol).asyncDispose ?? (_Symbol1.asyncDispose = Symbol("Symbol.asyncDispose"));
699
-
700
607
  // 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
- }
608
+ import "@hazae41/symbol-dispose-polyfill";
714
609
  var defer = (fn) => new DeferGuard(fn);
715
610
  var DeferGuard = class {
716
- [Symbol.dispose]() {
717
- const result = this._fn();
718
- if (result instanceof Promise) {
719
- throw new Error("Async functions in defer are not supported. Use deferAsync instead.");
720
- }
721
- }
611
+ _fn;
722
612
  /**
723
613
  * @internal
724
614
  */
725
615
  constructor(_fn) {
726
- _define_property4(this, "_fn", void 0);
727
616
  this._fn = _fn;
728
617
  }
618
+ [Symbol.dispose]() {
619
+ const result = this._fn();
620
+ if (result instanceof Promise) {
621
+ throw new Error("Async functions in defer are not supported. Use deferAsync instead.");
622
+ }
623
+ }
729
624
  };
730
625
  var deferAsync = (fn) => new DeferAsyncGuard(fn);
731
626
  var DeferAsyncGuard = class {
732
- async [Symbol.asyncDispose]() {
733
- await this._fn();
734
- }
627
+ _fn;
735
628
  /**
736
629
  * @internal
737
630
  */
738
631
  constructor(_fn) {
739
- _define_property4(this, "_fn", void 0);
740
632
  this._fn = _fn;
741
633
  }
634
+ async [Symbol.asyncDispose]() {
635
+ await this._fn();
636
+ }
742
637
  };
743
638
 
744
639
  // 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
- }
758
640
  var entry = (map, key) => new MapEntry(map, key);
759
641
  var MapEntry = class {
642
+ _map;
643
+ _key;
644
+ /**
645
+ * @internal
646
+ */
647
+ // prettier-ignore
648
+ constructor(_map, _key) {
649
+ this._map = _map;
650
+ this._key = _key;
651
+ }
760
652
  get key() {
761
653
  return this._key;
762
654
  }
@@ -772,36 +664,19 @@ var MapEntry = class {
772
664
  deep(key) {
773
665
  return entry(this.value, key);
774
666
  }
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;
784
- }
785
667
  };
786
668
 
669
+ // src/filename.ts
670
+ var createFilename = ({ parts = [], ext, date = /* @__PURE__ */ new Date() }) => [
671
+ date.toISOString().replace(/[:.]/g, "-"),
672
+ ...parts
673
+ ].join("_") + (ext ? `.${ext}` : "");
674
+
787
675
  // src/for-each-async.ts
788
676
  var forEachAsync = (items, fn) => Promise.all(items.map(fn));
789
677
 
790
678
  // src/human-hash.ts
791
679
  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
- }
805
680
  var DEFAULT_WORDLIST = [
806
681
  "ack",
807
682
  "alabama",
@@ -1061,6 +936,27 @@ var DEFAULT_WORDLIST = [
1061
936
  "zulu"
1062
937
  ];
1063
938
  var HumanHasher = class {
939
+ wordlist;
940
+ /**
941
+ * Transforms hex digests to human-readable strings.
942
+ *
943
+ * The format of these strings will look something like:
944
+ * `victor-bacon-zulu-lima`. The output is obtained by compressing the input
945
+ * digest to a fixed number of bytes, then mapping those bytes to one of 256
946
+ * words. A default wordlist is provided, but you can override this if you
947
+ * prefer.
948
+ * As long as you use the same wordlist, the output will be consistent (i.e.
949
+ * the same digest will always render the same representation).
950
+ *
951
+ * @param wordlist A list of exactly 256 words to choose from
952
+ */
953
+ constructor(wordlist = DEFAULT_WORDLIST) {
954
+ this.wordlist = wordlist;
955
+ if (wordlist.length !== 256) {
956
+ throw new Error("Wordlist must have exactly 256 items");
957
+ }
958
+ this.wordlist = wordlist;
959
+ }
1064
960
  /**
1065
961
  * Humanize a given hexadecimal digest.
1066
962
  *
@@ -1100,27 +996,6 @@ var HumanHasher = class {
1100
996
  const checksums = segments.map((x) => x.reduce((acc, curr) => acc ^ curr));
1101
997
  return checksums;
1102
998
  }
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
- }
1124
999
  };
1125
1000
  var hasher = new HumanHasher();
1126
1001
  var humanize = (value) => {
@@ -1143,10 +1018,8 @@ var defaultMap = (map, key, def) => {
1143
1018
  };
1144
1019
 
1145
1020
  // src/instance-id.ts
1146
- var _globalThis;
1147
- var _symbol;
1148
1021
  var symbol = Symbol.for("dxos.instance-contexts");
1149
- var instanceContexts = (_globalThis = globalThis)[_symbol = symbol] ?? (_globalThis[_symbol] = /* @__PURE__ */ new WeakMap());
1022
+ var instanceContexts = globalThis[symbol] ??= /* @__PURE__ */ new WeakMap();
1150
1023
  var getPrototypeSpecificInstanceId = (instance) => {
1151
1024
  const prototype = Object.getPrototypeOf(instance);
1152
1025
  const instanceCtx = defaultMap(instanceContexts, prototype, () => ({
@@ -1318,19 +1191,6 @@ var jsonKeyReplacer = (options = {}) => (key, value) => {
1318
1191
  };
1319
1192
 
1320
1193
  // 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
- }
1334
1194
  var mapValues = (obj, fn) => {
1335
1195
  const result = {};
1336
1196
  Object.keys(obj).forEach((key) => {
@@ -1342,6 +1202,11 @@ var deepMapValues = (value, fn) => {
1342
1202
  return new DeepMapper(fn).map(value);
1343
1203
  };
1344
1204
  var DeepMapper = class {
1205
+ _fn;
1206
+ _cyclic = /* @__PURE__ */ new Map();
1207
+ constructor(_fn) {
1208
+ this._fn = _fn;
1209
+ }
1345
1210
  map(value) {
1346
1211
  return this._map(value, void 0);
1347
1212
  }
@@ -1351,40 +1216,38 @@ var DeepMapper = class {
1351
1216
  }
1352
1217
  return this._fn(value, this._recurse, key);
1353
1218
  }
1354
- constructor(_fn) {
1355
- _define_property7(this, "_fn", void 0);
1356
- _define_property7(this, "_cyclic", void 0);
1357
- _define_property7(this, "_recurse", void 0);
1358
- this._fn = _fn;
1359
- this._cyclic = /* @__PURE__ */ new Map();
1360
- this._recurse = (value) => {
1361
- if (this._cyclic.has(value)) {
1362
- return this._cyclic.get(value);
1219
+ _recurse = (value) => {
1220
+ if (this._cyclic.has(value)) {
1221
+ return this._cyclic.get(value);
1222
+ }
1223
+ if (Array.isArray(value)) {
1224
+ const res = new Array(value.length);
1225
+ this._cyclic.set(value, res);
1226
+ for (let i = 0; i < value.length; i++) {
1227
+ res[i] = this._map(value[i], i);
1363
1228
  }
1364
- if (Array.isArray(value)) {
1365
- const res = new Array(value.length);
1366
- this._cyclic.set(value, res);
1367
- for (let i = 0; i < value.length; i++) {
1368
- res[i] = this._map(value[i], i);
1369
- }
1370
- return res;
1371
- } else if (value !== null && typeof value === "object") {
1372
- const res = {};
1373
- this._cyclic.set(value, res);
1374
- for (const key in value) {
1375
- res[key] = this._map(value[key], key);
1376
- }
1377
- return res;
1378
- } else {
1379
- return value;
1229
+ return res;
1230
+ } else if (value !== null && typeof value === "object") {
1231
+ const res = {};
1232
+ this._cyclic.set(value, res);
1233
+ for (const key in value) {
1234
+ res[key] = this._map(value[key], key);
1380
1235
  }
1381
- };
1382
- }
1236
+ return res;
1237
+ } else {
1238
+ return value;
1239
+ }
1240
+ };
1383
1241
  };
1384
1242
  var deepMapValuesAsync = (value, fn) => {
1385
1243
  return new DeepMapperAsync(fn).map(value);
1386
1244
  };
1387
1245
  var DeepMapperAsync = class {
1246
+ _fn;
1247
+ _cyclic = /* @__PURE__ */ new Map();
1248
+ constructor(_fn) {
1249
+ this._fn = _fn;
1250
+ }
1388
1251
  map(value) {
1389
1252
  return this._map(value, void 0);
1390
1253
  }
@@ -1394,35 +1257,28 @@ var DeepMapperAsync = class {
1394
1257
  }
1395
1258
  return this._fn(value, this._recurse, key);
1396
1259
  }
1397
- constructor(_fn) {
1398
- _define_property7(this, "_fn", void 0);
1399
- _define_property7(this, "_cyclic", void 0);
1400
- _define_property7(this, "_recurse", void 0);
1401
- this._fn = _fn;
1402
- this._cyclic = /* @__PURE__ */ new Map();
1403
- this._recurse = async (value) => {
1404
- if (this._cyclic.has(value)) {
1405
- return this._cyclic.get(value);
1260
+ _recurse = async (value) => {
1261
+ if (this._cyclic.has(value)) {
1262
+ return this._cyclic.get(value);
1263
+ }
1264
+ if (Array.isArray(value)) {
1265
+ const res = new Array(value.length);
1266
+ this._cyclic.set(value, res);
1267
+ for (let i = 0; i < value.length; i++) {
1268
+ res[i] = await this._map(value[i], i);
1406
1269
  }
1407
- if (Array.isArray(value)) {
1408
- const res = new Array(value.length);
1409
- this._cyclic.set(value, res);
1410
- for (let i = 0; i < value.length; i++) {
1411
- res[i] = await this._map(value[i], i);
1412
- }
1413
- return res;
1414
- } else if (value !== null && typeof value === "object") {
1415
- const res = {};
1416
- this._cyclic.set(value, res);
1417
- for (const key in value) {
1418
- res[key] = await this._map(value[key], key);
1419
- }
1420
- return res;
1421
- } else {
1422
- return value;
1270
+ return res;
1271
+ } else if (value !== null && typeof value === "object") {
1272
+ const res = {};
1273
+ this._cyclic.set(value, res);
1274
+ for (const key in value) {
1275
+ res[key] = await this._map(value[key], key);
1423
1276
  }
1424
- };
1425
- }
1277
+ return res;
1278
+ } else {
1279
+ return value;
1280
+ }
1281
+ };
1426
1282
  };
1427
1283
  var visitValues = (object, visitor) => {
1428
1284
  if (Array.isArray(object)) {
@@ -1511,7 +1367,18 @@ var omit = (obj, keys2) => {
1511
1367
 
1512
1368
  // src/platform.ts
1513
1369
  var isNode = () => typeof process !== "undefined" && process.versions != null && process.versions.node != null;
1514
- var mobileAndTabletCheck = () => {
1370
+ var isBun = () => globalThis.Bun !== void 0;
1371
+ var isTauri = () => !!globalThis.__TAURI__;
1372
+ var isMobile = () => {
1373
+ let check = false;
1374
+ (function(a) {
1375
+ if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4))) {
1376
+ check = true;
1377
+ }
1378
+ })(navigator.userAgent || navigator.vendor || window.opera);
1379
+ return check;
1380
+ };
1381
+ var isMobileOrTablet = () => {
1515
1382
  let check = false;
1516
1383
  ((a) => {
1517
1384
  if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4))) {
@@ -1533,7 +1400,7 @@ var iosCheck = () => {
1533
1400
  };
1534
1401
  var safariCheck = () => typeof navigator !== "undefined" && /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
1535
1402
  var getHostPlatform = () => {
1536
- if (!("navigator" in window)) {
1403
+ if (!("navigator" in globalThis)) {
1537
1404
  return "unknown";
1538
1405
  }
1539
1406
  const platform = (navigator.userAgentData?.platform || navigator.platform)?.toLowerCase();
@@ -1740,48 +1607,137 @@ var safeInstanceof = (tag) => (target) => {
1740
1607
  };
1741
1608
 
1742
1609
  // src/safe-parse.ts
1743
- var safeParseInt = (value, defaultValue) => {
1610
+ function safeParseInt(str, defaultValue) {
1744
1611
  try {
1745
- const n = parseInt(value ?? "");
1746
- return isNaN(n) ? defaultValue : n;
1612
+ const value = parseInt(str ?? "");
1613
+ return isNaN(value) ? defaultValue : value;
1747
1614
  } catch {
1748
1615
  return defaultValue;
1749
1616
  }
1750
- };
1751
- var safeParseFloat = (str, defaultValue) => {
1617
+ }
1618
+ function safeParseFloat(str, defaultValue) {
1752
1619
  try {
1753
- return parseFloat(str);
1620
+ const value = parseFloat(str ?? "");
1621
+ return isNaN(value) ? defaultValue : value;
1754
1622
  } catch {
1755
- return defaultValue ?? 0;
1623
+ return defaultValue;
1756
1624
  }
1757
- };
1758
- var safeParseJson = (data, defaultValue) => {
1759
- if (data && data.length > 0) {
1625
+ }
1626
+ var safeParseJson = (str, defaultValue) => {
1627
+ if (str && str.length > 0) {
1760
1628
  try {
1761
- return JSON.parse(data);
1629
+ return JSON.parse(str);
1762
1630
  } catch {
1763
1631
  }
1764
1632
  }
1765
1633
  return defaultValue;
1766
1634
  };
1767
1635
 
1768
- // src/sliding-window-summary.ts
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;
1636
+ // src/safe-stringify.ts
1637
+ var SKIP = Object.freeze({});
1638
+ function safeStringify(obj, filter = defaultFilter, indent = 2) {
1639
+ const seen = /* @__PURE__ */ new WeakMap();
1640
+ function replacer(key, value) {
1641
+ try {
1642
+ let path = key;
1643
+ if (!key) {
1644
+ path = "$";
1645
+ return value;
1646
+ } else if (this) {
1647
+ const parentPath = seen.get(this);
1648
+ path = parentPath ? `${parentPath}.${key}` : key;
1649
+ }
1650
+ if (value == null) {
1651
+ return value;
1652
+ }
1653
+ if (typeof value === "function") {
1654
+ return void 0;
1655
+ }
1656
+ if (typeof value === "object" && Object.getPrototypeOf(value) !== Object.prototype) {
1657
+ return void 0;
1658
+ }
1659
+ if (typeof value === "object" && value !== null) {
1660
+ const exists = seen.get(value);
1661
+ if (exists) {
1662
+ return `[${path} => ${exists}]`;
1663
+ }
1664
+ seen.set(value, path);
1665
+ }
1666
+ if (filter) {
1667
+ const filteredValue = filter?.(key, value);
1668
+ if (filteredValue !== void 0) {
1669
+ return filteredValue === SKIP ? void 0 : filteredValue;
1670
+ }
1671
+ }
1672
+ return value;
1673
+ } catch (error) {
1674
+ return `ERROR: ${error.message}`;
1675
+ }
1780
1676
  }
1781
- return obj;
1677
+ return JSON.stringify(obj, replacer, indent);
1782
1678
  }
1679
+ var createReplacer = ({ omit: omit2, parse, maxDepth, maxArrayLen, maxStringLen } = {}) => {
1680
+ let currentDepth = 0;
1681
+ const depthMap = /* @__PURE__ */ new WeakMap();
1682
+ return function(key, value) {
1683
+ if (key === "") {
1684
+ currentDepth = 0;
1685
+ } else if (this && typeof this === "object") {
1686
+ const parentDepth = depthMap.get(this) ?? 0;
1687
+ currentDepth = parentDepth + 1;
1688
+ }
1689
+ if (typeof value === "function") {
1690
+ return SKIP;
1691
+ }
1692
+ if (value && typeof value === "object") {
1693
+ depthMap.set(value, currentDepth);
1694
+ if (maxDepth != null && currentDepth >= maxDepth) {
1695
+ return Array.isArray(value) ? `[{ length: ${value.length} }]` : `{ keys: ${Object.keys(value).length} }`;
1696
+ }
1697
+ }
1698
+ if (omit2?.includes(key)) {
1699
+ return SKIP;
1700
+ }
1701
+ if (parse?.includes(key) && typeof value === "string") {
1702
+ try {
1703
+ return JSON.parse(value);
1704
+ } catch {
1705
+ return value;
1706
+ }
1707
+ }
1708
+ if (maxArrayLen != null && Array.isArray(value) && value.length > maxArrayLen) {
1709
+ return `[length: ${value.length}]`;
1710
+ }
1711
+ if (maxStringLen != null && typeof value === "string" && value.length > maxStringLen) {
1712
+ return value.slice(0, maxStringLen) + "...";
1713
+ }
1714
+ return value;
1715
+ };
1716
+ };
1717
+ var defaultFilter = createReplacer();
1718
+
1719
+ // src/sliding-window-summary.ts
1720
+ import { invariant as invariant5 } from "@dxos/invariant";
1783
1721
  var __dxlog_file5 = "/__w/dxos/dxos/packages/common/util/src/sliding-window-summary.ts";
1784
1722
  var SlidingWindowSummary = class {
1723
+ _buffer;
1724
+ _sum = 0;
1725
+ _precision;
1726
+ constructor(options) {
1727
+ this._buffer = new CircularBuffer(options.dataPoints);
1728
+ if (options.precision != null) {
1729
+ invariant5(options.precision >= 0, void 0, {
1730
+ F: __dxlog_file5,
1731
+ L: 26,
1732
+ S: this,
1733
+ A: [
1734
+ "options.precision >= 0",
1735
+ ""
1736
+ ]
1737
+ });
1738
+ this._precision = Math.pow(10, options.precision);
1739
+ }
1740
+ }
1785
1741
  record(value) {
1786
1742
  const evicted = this._buffer.push(value);
1787
1743
  this._sum += value - (evicted ?? 0);
@@ -1816,24 +1772,6 @@ var SlidingWindowSummary = class {
1816
1772
  }
1817
1773
  return Math.round(value * this._precision) / this._precision;
1818
1774
  }
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
- }
1837
1775
  };
1838
1776
 
1839
1777
  // src/sort.ts
@@ -2080,20 +2018,9 @@ var toFallback = (hash) => {
2080
2018
  };
2081
2019
 
2082
2020
  // src/tracer.ts
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;
2093
- }
2094
- return obj;
2095
- }
2096
2021
  var Tracer = class {
2022
+ _events = /* @__PURE__ */ new Map();
2023
+ _recording = false;
2097
2024
  // TODO(burdon): Start/stop methods for recording data? By id?
2098
2025
  // Alternatively, enable subscriptions to track/compute series.
2099
2026
  // TODO(burdon): Hierarchical traces?
@@ -2150,10 +2077,6 @@ var Tracer = class {
2150
2077
  defaultMap(this._events, event.id, []).push(event);
2151
2078
  }
2152
2079
  }
2153
- constructor() {
2154
- _define_property9(this, "_events", /* @__PURE__ */ new Map());
2155
- _define_property9(this, "_recording", false);
2156
- }
2157
2080
  };
2158
2081
  var tracer = new Tracer();
2159
2082
 
@@ -2228,69 +2151,112 @@ var arrayMove = (array, from, to) => {
2228
2151
  array.splice(to < 0 ? array.length + to : to, 0, array.splice(from, 1)[0]);
2229
2152
  return array;
2230
2153
  };
2154
+ function arraySwap(array, from, to) {
2155
+ const current = array[from];
2156
+ array[from] = array[to];
2157
+ array[to] = current;
2158
+ return array;
2159
+ }
2231
2160
 
2232
2161
  // src/unit.ts
2233
- var Formatter = (unit) => {
2234
- return (n, precision = 2) => {
2162
+ var createFormat = (unit) => {
2163
+ return (n, precision = unit.precision ?? 0) => {
2235
2164
  const value = n / unit.quotient;
2236
- return `${value.toFixed(precision)}${unit.symbol}`;
2165
+ return {
2166
+ unit,
2167
+ value,
2168
+ formattedValue: value.toFixed(precision),
2169
+ toString: () => `${value.toFixed(precision)}${unit.symbol}`
2170
+ };
2237
2171
  };
2238
2172
  };
2173
+ var MS_SECONDS = 1e3;
2174
+ var MS_MINUTES = 60 * MS_SECONDS;
2175
+ var MS_HOURS = 60 * MS_MINUTES;
2239
2176
  var Unit = {
2240
- // ms.
2241
- Hour: Formatter({
2177
+ // General.
2178
+ Percent: createFormat({
2179
+ symbol: "%",
2180
+ quotient: 1 / 100,
2181
+ precision: 2
2182
+ }),
2183
+ Thousand: createFormat({
2184
+ symbol: "k",
2185
+ quotient: 1e3,
2186
+ precision: 2
2187
+ }),
2188
+ // Bytes (note KB vs KiB).
2189
+ Gigabyte: createFormat({
2190
+ symbol: "GB",
2191
+ quotient: 1e3 * 1e3 * 1e3,
2192
+ precision: 2
2193
+ }),
2194
+ Megabyte: createFormat({
2195
+ symbol: "MB",
2196
+ quotient: 1e3 * 1e3,
2197
+ precision: 2
2198
+ }),
2199
+ Kilobyte: createFormat({
2200
+ symbol: "KB",
2201
+ quotient: 1e3,
2202
+ precision: 2
2203
+ }),
2204
+ Byte: createFormat({
2205
+ symbol: "B",
2206
+ quotient: 1
2207
+ }),
2208
+ // Time.
2209
+ Hour: createFormat({
2242
2210
  symbol: "h",
2243
- quotient: 60 * 60 * 1e3
2211
+ quotient: MS_HOURS
2244
2212
  }),
2245
- Minute: Formatter({
2213
+ Minute: createFormat({
2246
2214
  symbol: "m",
2247
- quotient: 60 * 1e3
2215
+ quotient: MS_MINUTES
2248
2216
  }),
2249
- Second: Formatter({
2217
+ Second: createFormat({
2250
2218
  symbol: "s",
2251
- quotient: 1e3
2219
+ quotient: MS_SECONDS,
2220
+ precision: 1
2252
2221
  }),
2253
- Millisecond: Formatter({
2222
+ Millisecond: createFormat({
2254
2223
  symbol: "ms",
2255
2224
  quotient: 1
2256
2225
  }),
2257
2226
  Duration: (n) => {
2258
- const hours = Math.floor(n / (60 * 60 * 1e3));
2259
- const minutes = Math.floor(n % (60 * 60 * 1e3) / (60 * 1e3));
2227
+ const hours = Math.floor(n / MS_HOURS);
2228
+ const minutes = Math.floor(n % MS_HOURS / MS_MINUTES);
2260
2229
  if (hours) {
2261
- return minutes ? `${hours}h ${minutes}m` : `${hours}h`;
2230
+ const formattedValue = minutes ? `${hours}h ${minutes}m` : `${hours}h`;
2231
+ return {
2232
+ unit: {
2233
+ symbol: "h",
2234
+ quotient: MS_HOURS
2235
+ },
2236
+ value: hours,
2237
+ formattedValue,
2238
+ toString: () => formattedValue
2239
+ };
2262
2240
  }
2263
- const seconds = Math.floor(n % (60 * 1e3) / 1e3);
2264
2241
  if (minutes) {
2265
- return seconds ? `${minutes}m ${seconds}s` : `${minutes}m`;
2242
+ const seconds2 = (n - MS_MINUTES * minutes) / MS_SECONDS;
2243
+ const formattedValue = seconds2 ? `${minutes}m ${seconds2}s` : `${minutes}m`;
2244
+ return {
2245
+ unit: {
2246
+ symbol: "m",
2247
+ quotient: MS_MINUTES
2248
+ },
2249
+ value: minutes,
2250
+ formattedValue,
2251
+ toString: () => formattedValue
2252
+ };
2266
2253
  }
2254
+ const seconds = n >= MS_SECONDS;
2267
2255
  if (seconds) {
2268
- return `${(n / 1e3).toFixed(1)}s`;
2256
+ return Unit.Second(n);
2269
2257
  }
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
- })
2258
+ return Unit.Millisecond(n);
2259
+ }
2294
2260
  };
2295
2261
 
2296
2262
  // src/url.ts
@@ -2303,20 +2269,18 @@ var createUrl = (url, search) => {
2303
2269
  };
2304
2270
 
2305
2271
  // src/weak.ts
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
2313
- });
2314
- } else {
2315
- obj[key] = value;
2316
- }
2317
- return obj;
2318
- }
2319
2272
  var WeakDictionary = class {
2273
+ _internal = /* @__PURE__ */ new Map();
2274
+ _finalization = new FinalizationRegistry((cleanUpCallback) => {
2275
+ cleanUpCallback();
2276
+ });
2277
+ constructor(entries2) {
2278
+ this._internal = new Map(entries2?.map(([key, value]) => [
2279
+ key,
2280
+ new WeakRef(value)
2281
+ ]));
2282
+ entries2?.forEach(([key, value]) => this._register(key, value));
2283
+ }
2320
2284
  *entries() {
2321
2285
  for (const [key, value] of this._internal) {
2322
2286
  yield [
@@ -2397,16 +2361,57 @@ var WeakDictionary = class {
2397
2361
  _unregister(value) {
2398
2362
  this._finalization.unregister(value);
2399
2363
  }
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));
2364
+ };
2365
+
2366
+ // src/error-format.ts
2367
+ var formatErrorWithCauses = (error) => {
2368
+ const lines = [];
2369
+ let current = error;
2370
+ let level = 0;
2371
+ while (current) {
2372
+ const prefix = level === 0 ? "" : `Caused by: `;
2373
+ lines.push(prefix + (current.stack ?? String(current)));
2374
+ if (!(current.cause instanceof Error)) break;
2375
+ current = current.cause;
2376
+ level += 1;
2377
+ }
2378
+ return lines.join("\n\n");
2379
+ };
2380
+
2381
+ // src/retry.ts
2382
+ var DEFAULT_RETRY_OPTIONS = {
2383
+ count: 3,
2384
+ delayMs: 100,
2385
+ exponent: 2,
2386
+ retryOnError: async () => true,
2387
+ retryOnValue: async () => false
2388
+ };
2389
+ var retry = async (options, cb) => {
2390
+ const fullOptions = {
2391
+ ...DEFAULT_RETRY_OPTIONS,
2392
+ ...options
2393
+ };
2394
+ let numRetries = 0, currentDelay = fullOptions.delayMs;
2395
+ while (true) {
2396
+ let result;
2397
+ try {
2398
+ result = await cb();
2399
+ } catch (err) {
2400
+ if (numRetries > fullOptions.count || !await fullOptions.retryOnError(err)) {
2401
+ throw err;
2402
+ }
2403
+ await new Promise((resolve) => setTimeout(resolve, currentDelay));
2404
+ currentDelay *= fullOptions.exponent;
2405
+ numRetries++;
2406
+ continue;
2407
+ }
2408
+ if (!await fullOptions.retryOnValue(result)) {
2409
+ return result;
2410
+ }
2411
+ await new Promise((resolve) => setTimeout(resolve, currentDelay));
2412
+ currentDelay *= fullOptions.exponent;
2413
+ numRetries++;
2414
+ continue;
2410
2415
  }
2411
2416
  };
2412
2417
  export {
@@ -2418,12 +2423,14 @@ export {
2418
2423
  ComplexSet,
2419
2424
  HumanHasher,
2420
2425
  MapEntry,
2426
+ SKIP,
2421
2427
  SlidingWindowSummary,
2422
2428
  Tracer,
2423
2429
  Unit,
2424
2430
  WeakDictionary,
2425
2431
  accessBy,
2426
2432
  arrayMove,
2433
+ arraySwap,
2427
2434
  arrayToBuffer,
2428
2435
  arrayToHex,
2429
2436
  arrayToString,
@@ -2435,18 +2442,22 @@ export {
2435
2442
  chunkArray,
2436
2443
  clamp,
2437
2444
  clearUndefined,
2445
+ coerceArray,
2438
2446
  compareMulti,
2439
2447
  compareObject,
2440
2448
  compareScalar,
2441
2449
  compareString,
2442
2450
  createBinder,
2443
2451
  createBucketReducer,
2452
+ createFilename,
2444
2453
  createGroupReducer,
2454
+ createReplacer,
2445
2455
  createSetDispatch,
2446
2456
  createUrl,
2447
2457
  decamelize,
2448
2458
  deepMapValues,
2449
2459
  deepMapValuesAsync,
2460
+ defaultFilter,
2450
2461
  defaultMap,
2451
2462
  defer,
2452
2463
  deferAsync,
@@ -2458,6 +2469,7 @@ export {
2458
2469
  entry,
2459
2470
  exponentialBackoffInterval,
2460
2471
  forEachAsync,
2472
+ formatErrorWithCauses,
2461
2473
  get,
2462
2474
  getAsyncProviderValue,
2463
2475
  getDate,
@@ -2478,8 +2490,12 @@ export {
2478
2490
  intersectBy,
2479
2491
  intersection,
2480
2492
  iosCheck,
2493
+ isBun,
2494
+ isMobile,
2495
+ isMobileOrTablet,
2481
2496
  isNode,
2482
2497
  isNonNullable,
2498
+ isTauri,
2483
2499
  isTruthy,
2484
2500
  joinTables,
2485
2501
  jsonKeyReplacer,
@@ -2495,7 +2511,6 @@ export {
2495
2511
  makeSet,
2496
2512
  mapValues,
2497
2513
  median,
2498
- mobileAndTabletCheck,
2499
2514
  numericalValues,
2500
2515
  omit,
2501
2516
  orderKeys,
@@ -2511,12 +2526,14 @@ export {
2511
2526
  removeBy,
2512
2527
  removeProperties,
2513
2528
  removeUndefinedProperties,
2529
+ retry,
2514
2530
  safariCheck,
2515
2531
  safeAwaitAll,
2516
2532
  safeInstanceof,
2517
2533
  safeParseFloat,
2518
2534
  safeParseInt,
2519
2535
  safeParseJson,
2536
+ safeStringify,
2520
2537
  set,
2521
2538
  setDeep,
2522
2539
  sortKeys,