@dxos/util 0.8.4-main.f9ba587 → 0.8.4-main.fcfe5033a5
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 +508 -146
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +508 -146
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/array.d.ts +3 -2
- package/dist/types/src/array.d.ts.map +1 -1
- package/dist/types/src/assume.d.ts.map +1 -1
- package/dist/types/src/circular-buffer.d.ts +1 -0
- package/dist/types/src/circular-buffer.d.ts.map +1 -1
- package/dist/types/src/complex.d.ts +15 -0
- package/dist/types/src/complex.d.ts.map +1 -1
- package/dist/types/src/composite-key.d.ts +10 -0
- package/dist/types/src/composite-key.d.ts.map +1 -0
- package/dist/types/src/composite-key.test.d.ts +2 -0
- package/dist/types/src/composite-key.test.d.ts.map +1 -0
- package/dist/types/src/deep.d.ts +0 -3
- package/dist/types/src/deep.d.ts.map +1 -1
- package/dist/types/src/defer.d.ts +1 -1
- package/dist/types/src/defer.d.ts.map +1 -1
- package/dist/types/src/di-key.d.ts +7 -5
- package/dist/types/src/di-key.d.ts.map +1 -1
- package/dist/types/src/error-format.d.ts +5 -0
- package/dist/types/src/error-format.d.ts.map +1 -0
- package/dist/types/src/filename.d.ts +9 -0
- package/dist/types/src/filename.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +6 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/json.d.ts +1 -1
- package/dist/types/src/json.d.ts.map +1 -1
- package/dist/types/src/object.d.ts +3 -0
- package/dist/types/src/object.d.ts.map +1 -1
- package/dist/types/src/platform.d.ts +4 -1
- package/dist/types/src/platform.d.ts.map +1 -1
- package/dist/types/src/retry.d.ts +32 -0
- package/dist/types/src/retry.d.ts.map +1 -0
- package/dist/types/src/safe-parse.d.ts +7 -4
- package/dist/types/src/safe-parse.d.ts.map +1 -1
- package/dist/types/src/safe-stringify.d.ts +22 -0
- package/dist/types/src/safe-stringify.d.ts.map +1 -0
- package/dist/types/src/safe-stringify.test.d.ts +2 -0
- package/dist/types/src/safe-stringify.test.d.ts.map +1 -0
- package/dist/types/src/string.d.ts +8 -0
- package/dist/types/src/string.d.ts.map +1 -1
- package/dist/types/src/string.test.d.ts +2 -0
- package/dist/types/src/string.test.d.ts.map +1 -0
- package/dist/types/src/to-fallback.d.ts +18 -4
- package/dist/types/src/to-fallback.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +24 -6
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/src/unit.d.ts +14 -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/src/weak.d.ts +15 -0
- package/dist/types/src/weak.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +14 -13
- package/src/array.test.ts +1 -1
- package/src/array.ts +9 -4
- package/src/assume.ts +0 -1
- package/src/binder.ts +2 -2
- package/src/circular-buffer.test.ts +27 -1
- package/src/circular-buffer.ts +5 -0
- package/src/complex.test.ts +1 -1
- package/src/complex.ts +32 -0
- package/src/composite-key.test.ts +31 -0
- package/src/composite-key.ts +16 -0
- package/src/deep.ts +2 -6
- package/src/defer.ts +1 -1
- package/src/di-key.ts +10 -8
- package/src/error-format.ts +22 -0
- package/src/filename.ts +16 -0
- package/src/human-hash.test.ts +1 -1
- package/src/index.ts +6 -2
- package/src/json.ts +2 -7
- package/src/object.ts +3 -0
- package/src/platform.ts +35 -3
- package/src/position.test.ts +2 -2
- package/src/retry.ts +74 -0
- package/src/safe-parse.ts +29 -15
- package/src/safe-stringify.test.ts +96 -0
- package/src/safe-stringify.ts +153 -0
- package/src/sort.test.ts +1 -1
- package/src/string.test.ts +19 -0
- package/src/string.ts +36 -0
- package/src/to-fallback.ts +44 -160
- package/src/tree.test.ts +1 -1
- package/src/types.test.ts +11 -1
- package/src/types.ts +40 -12
- package/src/uint8array.test.ts +1 -1
- package/src/unit.test.ts +25 -0
- package/src/unit.ts +83 -0
- package/src/weak.test.ts +1 -1
- package/src/weak.ts +52 -14
- package/dist/types/src/explicit-resource-management-polyfill.d.ts +0 -1
- package/dist/types/src/explicit-resource-management-polyfill.d.ts.map +0 -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/explicit-resource-management-polyfill.ts +0 -13
- package/src/first-two-chars.ts +0 -44
|
@@ -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
|
|
114
|
+
import { promisify } from "node:util";
|
|
107
115
|
var createBinder = (obj) => ({
|
|
108
116
|
fn: (fn) => fn.bind(obj),
|
|
109
|
-
async: (fn) =>
|
|
117
|
+
async: (fn) => promisify(fn.bind(obj))
|
|
110
118
|
});
|
|
111
119
|
|
|
112
120
|
// src/bitfield.ts
|
|
@@ -207,6 +215,7 @@ var CallbackCollection = class {
|
|
|
207
215
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
208
216
|
var __dxlog_file2 = "/__w/dxos/dxos/packages/common/util/src/callback.ts";
|
|
209
217
|
var Callback = class {
|
|
218
|
+
_callback;
|
|
210
219
|
call(...args) {
|
|
211
220
|
invariant2(this._callback, "Callback not set", {
|
|
212
221
|
F: __dxlog_file2,
|
|
@@ -301,9 +310,10 @@ var chunkArray = (array, size) => {
|
|
|
301
310
|
import { invariant as invariant3 } from "@dxos/invariant";
|
|
302
311
|
var __dxlog_file3 = "/__w/dxos/dxos/packages/common/util/src/circular-buffer.ts";
|
|
303
312
|
var CircularBuffer = class {
|
|
313
|
+
_buffer;
|
|
314
|
+
_nextIndex = 0;
|
|
315
|
+
_elementCount = 0;
|
|
304
316
|
constructor(size) {
|
|
305
|
-
this._nextIndex = 0;
|
|
306
|
-
this._elementCount = 0;
|
|
307
317
|
invariant3(size >= 1, void 0, {
|
|
308
318
|
F: __dxlog_file3,
|
|
309
319
|
L: 13,
|
|
@@ -325,6 +335,10 @@ var CircularBuffer = class {
|
|
|
325
335
|
get elementCount() {
|
|
326
336
|
return this._elementCount;
|
|
327
337
|
}
|
|
338
|
+
clear() {
|
|
339
|
+
this._nextIndex = 0;
|
|
340
|
+
this._elementCount = 0;
|
|
341
|
+
}
|
|
328
342
|
getLast() {
|
|
329
343
|
if (this._elementCount === 0) {
|
|
330
344
|
return void 0;
|
|
@@ -374,10 +388,11 @@ import { inspect } from "node:util";
|
|
|
374
388
|
import { inspectObject, raise } from "@dxos/debug";
|
|
375
389
|
var MAX_SERIALIZATION_LENGTH = 10;
|
|
376
390
|
var ComplexSet = class {
|
|
391
|
+
_projection;
|
|
392
|
+
_values = /* @__PURE__ */ new Map();
|
|
377
393
|
// prettier-ignore
|
|
378
394
|
constructor(_projection, values) {
|
|
379
395
|
this._projection = _projection;
|
|
380
|
-
this._values = /* @__PURE__ */ new Map();
|
|
381
396
|
if (values) {
|
|
382
397
|
for (const value of values) {
|
|
383
398
|
this.add(value);
|
|
@@ -467,11 +482,12 @@ var makeSet = (projection) => {
|
|
|
467
482
|
};
|
|
468
483
|
};
|
|
469
484
|
var ComplexMap = class _ComplexMap {
|
|
485
|
+
_keyProjection;
|
|
486
|
+
_keys = /* @__PURE__ */ new Map();
|
|
487
|
+
_values = /* @__PURE__ */ new Map();
|
|
470
488
|
// prettier-ignore
|
|
471
489
|
constructor(_keyProjection, entries2) {
|
|
472
490
|
this._keyProjection = _keyProjection;
|
|
473
|
-
this._keys = /* @__PURE__ */ new Map();
|
|
474
|
-
this._values = /* @__PURE__ */ new Map();
|
|
475
491
|
if (entries2) {
|
|
476
492
|
for (const [key, value] of entries2) {
|
|
477
493
|
this.set(key, value);
|
|
@@ -516,6 +532,36 @@ var ComplexMap = class _ComplexMap {
|
|
|
516
532
|
this._values.set(primitive, value);
|
|
517
533
|
return this;
|
|
518
534
|
}
|
|
535
|
+
/**
|
|
536
|
+
* Returns the value for the given key if present, otherwise inserts and returns the default value.
|
|
537
|
+
* @param key - The key to look up or insert.
|
|
538
|
+
* @param defaultValue - The value to insert if the key is not present.
|
|
539
|
+
* @returns The existing or newly inserted value.
|
|
540
|
+
*/
|
|
541
|
+
getOrInsert(key, defaultValue) {
|
|
542
|
+
const primitive = this._keyProjection(key);
|
|
543
|
+
if (this._values.has(primitive)) {
|
|
544
|
+
return this._values.get(primitive);
|
|
545
|
+
}
|
|
546
|
+
this.set(key, defaultValue);
|
|
547
|
+
return defaultValue;
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* Returns the value for the given key if present, otherwise computes, inserts, and returns a new value.
|
|
551
|
+
* The callback is only invoked when the key is missing.
|
|
552
|
+
* @param key - The key to look up or insert.
|
|
553
|
+
* @param callbackfn - Function to compute the value if the key is not present.
|
|
554
|
+
* @returns The existing or newly computed value.
|
|
555
|
+
*/
|
|
556
|
+
getOrInsertComputed(key, callbackfn) {
|
|
557
|
+
const primitive = this._keyProjection(key);
|
|
558
|
+
if (this._values.has(primitive)) {
|
|
559
|
+
return this._values.get(primitive);
|
|
560
|
+
}
|
|
561
|
+
const value = callbackfn(key);
|
|
562
|
+
this.set(key, value);
|
|
563
|
+
return value;
|
|
564
|
+
}
|
|
519
565
|
get size() {
|
|
520
566
|
return this._keys.size;
|
|
521
567
|
}
|
|
@@ -555,15 +601,18 @@ var makeMap = (keyProjection) => class BoundComplexMap extends ComplexMap {
|
|
|
555
601
|
}
|
|
556
602
|
};
|
|
557
603
|
|
|
604
|
+
// src/composite-key.ts
|
|
605
|
+
var SEPARATOR = ":";
|
|
606
|
+
var compositeKey = (...parts) => parts.join(SEPARATOR);
|
|
607
|
+
var splitCompositeKey = (key) => key.split(SEPARATOR);
|
|
608
|
+
|
|
558
609
|
// src/deep.ts
|
|
559
|
-
import get from "lodash.get";
|
|
560
|
-
import set from "lodash.set";
|
|
561
610
|
import { invariant as invariant4 } from "@dxos/invariant";
|
|
562
611
|
var __dxlog_file4 = "/__w/dxos/dxos/packages/common/util/src/deep.ts";
|
|
563
612
|
var setDeep = (obj, path, value) => {
|
|
564
613
|
invariant4(path.length > 0, void 0, {
|
|
565
614
|
F: __dxlog_file4,
|
|
566
|
-
L:
|
|
615
|
+
L: 12,
|
|
567
616
|
S: void 0,
|
|
568
617
|
A: [
|
|
569
618
|
"path.length > 0",
|
|
@@ -592,13 +641,11 @@ var getDeep = (obj, path) => {
|
|
|
592
641
|
// src/defer-function.ts
|
|
593
642
|
var deferFunction = (fnProvider) => (...args) => fnProvider()(...args);
|
|
594
643
|
|
|
595
|
-
// src/explicit-resource-management-polyfill.ts
|
|
596
|
-
Symbol.dispose ??= Symbol("Symbol.dispose");
|
|
597
|
-
Symbol.asyncDispose ??= Symbol("Symbol.asyncDispose");
|
|
598
|
-
|
|
599
644
|
// src/defer.ts
|
|
645
|
+
import "@hazae41/symbol-dispose-polyfill";
|
|
600
646
|
var defer = (fn) => new DeferGuard(fn);
|
|
601
647
|
var DeferGuard = class {
|
|
648
|
+
_fn;
|
|
602
649
|
/**
|
|
603
650
|
* @internal
|
|
604
651
|
*/
|
|
@@ -614,6 +661,7 @@ var DeferGuard = class {
|
|
|
614
661
|
};
|
|
615
662
|
var deferAsync = (fn) => new DeferAsyncGuard(fn);
|
|
616
663
|
var DeferAsyncGuard = class {
|
|
664
|
+
_fn;
|
|
617
665
|
/**
|
|
618
666
|
* @internal
|
|
619
667
|
*/
|
|
@@ -628,6 +676,8 @@ var DeferAsyncGuard = class {
|
|
|
628
676
|
// src/entry.ts
|
|
629
677
|
var entry = (map, key) => new MapEntry(map, key);
|
|
630
678
|
var MapEntry = class {
|
|
679
|
+
_map;
|
|
680
|
+
_key;
|
|
631
681
|
/**
|
|
632
682
|
* @internal
|
|
633
683
|
*/
|
|
@@ -653,32 +703,11 @@ var MapEntry = class {
|
|
|
653
703
|
}
|
|
654
704
|
};
|
|
655
705
|
|
|
656
|
-
// src/
|
|
657
|
-
var
|
|
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
|
-
}
|
|
679
|
-
}
|
|
680
|
-
return result;
|
|
681
|
-
};
|
|
706
|
+
// src/filename.ts
|
|
707
|
+
var createFilename = ({ parts = [], ext, date = /* @__PURE__ */ new Date() }) => [
|
|
708
|
+
date.toISOString().replace(/[:.]/g, "-"),
|
|
709
|
+
...parts
|
|
710
|
+
].join("_") + (ext ? `.${ext}` : "");
|
|
682
711
|
|
|
683
712
|
// src/for-each-async.ts
|
|
684
713
|
var forEachAsync = (items, fn) => Promise.all(items.map(fn));
|
|
@@ -944,6 +973,7 @@ var DEFAULT_WORDLIST = [
|
|
|
944
973
|
"zulu"
|
|
945
974
|
];
|
|
946
975
|
var HumanHasher = class {
|
|
976
|
+
wordlist;
|
|
947
977
|
/**
|
|
948
978
|
* Transforms hex digests to human-readable strings.
|
|
949
979
|
*
|
|
@@ -1025,7 +1055,7 @@ var defaultMap = (map, key, def) => {
|
|
|
1025
1055
|
};
|
|
1026
1056
|
|
|
1027
1057
|
// src/instance-id.ts
|
|
1028
|
-
var symbol = Symbol.for("dxos.instance-contexts");
|
|
1058
|
+
var symbol = /* @__PURE__ */ Symbol.for("dxos.instance-contexts");
|
|
1029
1059
|
var instanceContexts = globalThis[symbol] ??= /* @__PURE__ */ new WeakMap();
|
|
1030
1060
|
var getPrototypeSpecificInstanceId = (instance) => {
|
|
1031
1061
|
const prototype = Object.getPrototypeOf(instance);
|
|
@@ -1109,7 +1139,7 @@ var arrayToString = (array) => arrayToBuffer(array).toString("hex");
|
|
|
1109
1139
|
// src/json.ts
|
|
1110
1140
|
var MAX_DEPTH = 5;
|
|
1111
1141
|
var LOG_MAX_DEPTH = 7;
|
|
1112
|
-
|
|
1142
|
+
var jsonReplacer = (key, value) => {
|
|
1113
1143
|
if (value !== null && typeof value === "object" && typeof value[inspect2.custom] === "function") {
|
|
1114
1144
|
return value[inspect2.custom]();
|
|
1115
1145
|
}
|
|
@@ -1122,7 +1152,7 @@ function jsonReplacer(key, value) {
|
|
|
1122
1152
|
}
|
|
1123
1153
|
}
|
|
1124
1154
|
return value;
|
|
1125
|
-
}
|
|
1155
|
+
};
|
|
1126
1156
|
var jsonify = (value, depth = 0, visitedObjects = /* @__PURE__ */ new WeakSet()) => {
|
|
1127
1157
|
if (depth > MAX_DEPTH) {
|
|
1128
1158
|
return null;
|
|
@@ -1209,31 +1239,10 @@ var deepMapValues = (value, fn) => {
|
|
|
1209
1239
|
return new DeepMapper(fn).map(value);
|
|
1210
1240
|
};
|
|
1211
1241
|
var DeepMapper = class {
|
|
1242
|
+
_fn;
|
|
1243
|
+
_cyclic = /* @__PURE__ */ new Map();
|
|
1212
1244
|
constructor(_fn) {
|
|
1213
1245
|
this._fn = _fn;
|
|
1214
|
-
this._cyclic = /* @__PURE__ */ new Map();
|
|
1215
|
-
this._recurse = (value) => {
|
|
1216
|
-
if (this._cyclic.has(value)) {
|
|
1217
|
-
return this._cyclic.get(value);
|
|
1218
|
-
}
|
|
1219
|
-
if (Array.isArray(value)) {
|
|
1220
|
-
const res = new Array(value.length);
|
|
1221
|
-
this._cyclic.set(value, res);
|
|
1222
|
-
for (let i = 0; i < value.length; i++) {
|
|
1223
|
-
res[i] = this._map(value[i], i);
|
|
1224
|
-
}
|
|
1225
|
-
return res;
|
|
1226
|
-
} else if (value !== null && typeof value === "object") {
|
|
1227
|
-
const res = {};
|
|
1228
|
-
this._cyclic.set(value, res);
|
|
1229
|
-
for (const key in value) {
|
|
1230
|
-
res[key] = this._map(value[key], key);
|
|
1231
|
-
}
|
|
1232
|
-
return res;
|
|
1233
|
-
} else {
|
|
1234
|
-
return value;
|
|
1235
|
-
}
|
|
1236
|
-
};
|
|
1237
1246
|
}
|
|
1238
1247
|
map(value) {
|
|
1239
1248
|
return this._map(value, void 0);
|
|
@@ -1244,36 +1253,37 @@ var DeepMapper = class {
|
|
|
1244
1253
|
}
|
|
1245
1254
|
return this._fn(value, this._recurse, key);
|
|
1246
1255
|
}
|
|
1256
|
+
_recurse = (value) => {
|
|
1257
|
+
if (this._cyclic.has(value)) {
|
|
1258
|
+
return this._cyclic.get(value);
|
|
1259
|
+
}
|
|
1260
|
+
if (Array.isArray(value)) {
|
|
1261
|
+
const res = new Array(value.length);
|
|
1262
|
+
this._cyclic.set(value, res);
|
|
1263
|
+
for (let i = 0; i < value.length; i++) {
|
|
1264
|
+
res[i] = this._map(value[i], i);
|
|
1265
|
+
}
|
|
1266
|
+
return res;
|
|
1267
|
+
} else if (value !== null && typeof value === "object") {
|
|
1268
|
+
const res = {};
|
|
1269
|
+
this._cyclic.set(value, res);
|
|
1270
|
+
for (const key in value) {
|
|
1271
|
+
res[key] = this._map(value[key], key);
|
|
1272
|
+
}
|
|
1273
|
+
return res;
|
|
1274
|
+
} else {
|
|
1275
|
+
return value;
|
|
1276
|
+
}
|
|
1277
|
+
};
|
|
1247
1278
|
};
|
|
1248
1279
|
var deepMapValuesAsync = (value, fn) => {
|
|
1249
1280
|
return new DeepMapperAsync(fn).map(value);
|
|
1250
1281
|
};
|
|
1251
1282
|
var DeepMapperAsync = class {
|
|
1283
|
+
_fn;
|
|
1284
|
+
_cyclic = /* @__PURE__ */ new Map();
|
|
1252
1285
|
constructor(_fn) {
|
|
1253
1286
|
this._fn = _fn;
|
|
1254
|
-
this._cyclic = /* @__PURE__ */ new Map();
|
|
1255
|
-
this._recurse = async (value) => {
|
|
1256
|
-
if (this._cyclic.has(value)) {
|
|
1257
|
-
return this._cyclic.get(value);
|
|
1258
|
-
}
|
|
1259
|
-
if (Array.isArray(value)) {
|
|
1260
|
-
const res = new Array(value.length);
|
|
1261
|
-
this._cyclic.set(value, res);
|
|
1262
|
-
for (let i = 0; i < value.length; i++) {
|
|
1263
|
-
res[i] = await this._map(value[i], i);
|
|
1264
|
-
}
|
|
1265
|
-
return res;
|
|
1266
|
-
} else if (value !== null && typeof value === "object") {
|
|
1267
|
-
const res = {};
|
|
1268
|
-
this._cyclic.set(value, res);
|
|
1269
|
-
for (const key in value) {
|
|
1270
|
-
res[key] = await this._map(value[key], key);
|
|
1271
|
-
}
|
|
1272
|
-
return res;
|
|
1273
|
-
} else {
|
|
1274
|
-
return value;
|
|
1275
|
-
}
|
|
1276
|
-
};
|
|
1277
1287
|
}
|
|
1278
1288
|
map(value) {
|
|
1279
1289
|
return this._map(value, void 0);
|
|
@@ -1284,6 +1294,28 @@ var DeepMapperAsync = class {
|
|
|
1284
1294
|
}
|
|
1285
1295
|
return this._fn(value, this._recurse, key);
|
|
1286
1296
|
}
|
|
1297
|
+
_recurse = async (value) => {
|
|
1298
|
+
if (this._cyclic.has(value)) {
|
|
1299
|
+
return this._cyclic.get(value);
|
|
1300
|
+
}
|
|
1301
|
+
if (Array.isArray(value)) {
|
|
1302
|
+
const res = new Array(value.length);
|
|
1303
|
+
this._cyclic.set(value, res);
|
|
1304
|
+
for (let i = 0; i < value.length; i++) {
|
|
1305
|
+
res[i] = await this._map(value[i], i);
|
|
1306
|
+
}
|
|
1307
|
+
return res;
|
|
1308
|
+
} else if (value !== null && typeof value === "object") {
|
|
1309
|
+
const res = {};
|
|
1310
|
+
this._cyclic.set(value, res);
|
|
1311
|
+
for (const key in value) {
|
|
1312
|
+
res[key] = await this._map(value[key], key);
|
|
1313
|
+
}
|
|
1314
|
+
return res;
|
|
1315
|
+
} else {
|
|
1316
|
+
return value;
|
|
1317
|
+
}
|
|
1318
|
+
};
|
|
1287
1319
|
};
|
|
1288
1320
|
var visitValues = (object, visitor) => {
|
|
1289
1321
|
if (Array.isArray(object)) {
|
|
@@ -1372,7 +1404,18 @@ var omit = (obj, keys2) => {
|
|
|
1372
1404
|
|
|
1373
1405
|
// src/platform.ts
|
|
1374
1406
|
var isNode = () => typeof process !== "undefined" && process.versions != null && process.versions.node != null;
|
|
1375
|
-
var
|
|
1407
|
+
var isBun = () => globalThis.Bun !== void 0;
|
|
1408
|
+
var isTauri = () => !!globalThis.__TAURI__;
|
|
1409
|
+
var isMobile = () => {
|
|
1410
|
+
let check = false;
|
|
1411
|
+
(function(a) {
|
|
1412
|
+
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))) {
|
|
1413
|
+
check = true;
|
|
1414
|
+
}
|
|
1415
|
+
})(navigator.userAgent || navigator.vendor || window.opera);
|
|
1416
|
+
return check;
|
|
1417
|
+
};
|
|
1418
|
+
var isMobileOrTablet = () => {
|
|
1376
1419
|
let check = false;
|
|
1377
1420
|
((a) => {
|
|
1378
1421
|
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))) {
|
|
@@ -1394,7 +1437,7 @@ var iosCheck = () => {
|
|
|
1394
1437
|
};
|
|
1395
1438
|
var safariCheck = () => typeof navigator !== "undefined" && /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
|
|
1396
1439
|
var getHostPlatform = () => {
|
|
1397
|
-
if (!("navigator" in
|
|
1440
|
+
if (!("navigator" in globalThis)) {
|
|
1398
1441
|
return "unknown";
|
|
1399
1442
|
}
|
|
1400
1443
|
const platform = (navigator.userAgentData?.platform || navigator.platform)?.toLowerCase();
|
|
@@ -1589,7 +1632,7 @@ var safeAwaitAll = async (source, taskFactory, onError) => {
|
|
|
1589
1632
|
};
|
|
1590
1633
|
|
|
1591
1634
|
// src/safe-instanceof.ts
|
|
1592
|
-
var instanceTag = Symbol("instanceTag");
|
|
1635
|
+
var instanceTag = /* @__PURE__ */ Symbol("instanceTag");
|
|
1593
1636
|
var safeInstanceof = (tag) => (target) => {
|
|
1594
1637
|
target.prototype[instanceTag] = tag;
|
|
1595
1638
|
Object.defineProperty(target.prototype, Symbol.hasInstance, {
|
|
@@ -1601,37 +1644,137 @@ var safeInstanceof = (tag) => (target) => {
|
|
|
1601
1644
|
};
|
|
1602
1645
|
|
|
1603
1646
|
// src/safe-parse.ts
|
|
1604
|
-
|
|
1647
|
+
function safeParseInt(str, defaultValue) {
|
|
1648
|
+
try {
|
|
1649
|
+
const value = parseInt(str ?? "");
|
|
1650
|
+
return isNaN(value) ? defaultValue : value;
|
|
1651
|
+
} catch {
|
|
1652
|
+
return defaultValue;
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
function safeParseFloat(str, defaultValue) {
|
|
1605
1656
|
try {
|
|
1606
|
-
const
|
|
1607
|
-
return isNaN(
|
|
1608
|
-
} catch
|
|
1657
|
+
const value = parseFloat(str ?? "");
|
|
1658
|
+
return isNaN(value) ? defaultValue : value;
|
|
1659
|
+
} catch {
|
|
1609
1660
|
return defaultValue;
|
|
1610
1661
|
}
|
|
1662
|
+
}
|
|
1663
|
+
var safeParseJson = (str, defaultValue) => {
|
|
1664
|
+
if (str && str.length > 0) {
|
|
1665
|
+
try {
|
|
1666
|
+
return JSON.parse(str);
|
|
1667
|
+
} catch {
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
return defaultValue;
|
|
1611
1671
|
};
|
|
1612
|
-
var
|
|
1672
|
+
var safeUrl = (str) => {
|
|
1613
1673
|
try {
|
|
1614
|
-
return
|
|
1674
|
+
return new URL(str ?? "");
|
|
1615
1675
|
} catch {
|
|
1616
|
-
return
|
|
1676
|
+
return void 0;
|
|
1617
1677
|
}
|
|
1618
1678
|
};
|
|
1619
|
-
|
|
1620
|
-
|
|
1679
|
+
|
|
1680
|
+
// src/safe-stringify.ts
|
|
1681
|
+
var SKIP = Object.freeze({});
|
|
1682
|
+
function safeStringify(obj, filter = defaultFilter, indent = 2) {
|
|
1683
|
+
const seen = /* @__PURE__ */ new WeakMap();
|
|
1684
|
+
function replacer(key, value) {
|
|
1621
1685
|
try {
|
|
1622
|
-
|
|
1623
|
-
|
|
1686
|
+
let path = key;
|
|
1687
|
+
if (!key) {
|
|
1688
|
+
path = "$";
|
|
1689
|
+
if (value != null && typeof value === "object") {
|
|
1690
|
+
seen.set(value, path);
|
|
1691
|
+
}
|
|
1692
|
+
return value;
|
|
1693
|
+
} else if (this) {
|
|
1694
|
+
const parentPath = seen.get(this);
|
|
1695
|
+
path = parentPath ? `${parentPath}.${key}` : key;
|
|
1696
|
+
}
|
|
1697
|
+
if (value == null) {
|
|
1698
|
+
return value;
|
|
1699
|
+
}
|
|
1700
|
+
if (typeof value === "function") {
|
|
1701
|
+
return void 0;
|
|
1702
|
+
}
|
|
1703
|
+
if (typeof value === "object" && Object.getPrototypeOf(value) !== Object.prototype && !Array.isArray(value)) {
|
|
1704
|
+
return void 0;
|
|
1705
|
+
}
|
|
1706
|
+
if (typeof value === "object" && value !== null) {
|
|
1707
|
+
const exists = seen.get(value);
|
|
1708
|
+
if (exists) {
|
|
1709
|
+
return `[${path} => ${exists}]`;
|
|
1710
|
+
}
|
|
1711
|
+
seen.set(value, path);
|
|
1712
|
+
}
|
|
1713
|
+
if (filter) {
|
|
1714
|
+
const filteredValue = filter?.(key, value);
|
|
1715
|
+
if (filteredValue !== void 0) {
|
|
1716
|
+
return filteredValue === SKIP ? void 0 : filteredValue;
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
return value;
|
|
1720
|
+
} catch (error) {
|
|
1721
|
+
return `ERROR: ${error.message}`;
|
|
1624
1722
|
}
|
|
1625
1723
|
}
|
|
1626
|
-
|
|
1724
|
+
try {
|
|
1725
|
+
return JSON.stringify(obj, replacer, indent);
|
|
1726
|
+
} catch (error) {
|
|
1727
|
+
return `ERROR: ${error.message}`;
|
|
1728
|
+
}
|
|
1729
|
+
}
|
|
1730
|
+
var createReplacer = ({ omit: omit2, parse, maxDepth, maxArrayLen, maxStringLen } = {}) => {
|
|
1731
|
+
let currentDepth = 0;
|
|
1732
|
+
const depthMap = /* @__PURE__ */ new WeakMap();
|
|
1733
|
+
return function(key, value) {
|
|
1734
|
+
if (key === "") {
|
|
1735
|
+
currentDepth = 0;
|
|
1736
|
+
} else if (this && typeof this === "object") {
|
|
1737
|
+
const parentDepth = depthMap.get(this) ?? 0;
|
|
1738
|
+
currentDepth = parentDepth + 1;
|
|
1739
|
+
}
|
|
1740
|
+
if (typeof value === "function") {
|
|
1741
|
+
return SKIP;
|
|
1742
|
+
}
|
|
1743
|
+
if (maxArrayLen != null && Array.isArray(value) && value.length > maxArrayLen) {
|
|
1744
|
+
return `[length: ${value.length}]`;
|
|
1745
|
+
}
|
|
1746
|
+
if (value && typeof value === "object") {
|
|
1747
|
+
depthMap.set(value, currentDepth);
|
|
1748
|
+
if (maxDepth != null && currentDepth >= maxDepth) {
|
|
1749
|
+
return Array.isArray(value) ? `[{ length: ${value.length} }]` : `{ keys: ${Object.keys(value).length} }`;
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
if (omit2?.includes(key)) {
|
|
1753
|
+
return SKIP;
|
|
1754
|
+
}
|
|
1755
|
+
if (parse?.includes(key) && typeof value === "string") {
|
|
1756
|
+
try {
|
|
1757
|
+
return JSON.parse(value);
|
|
1758
|
+
} catch {
|
|
1759
|
+
return value;
|
|
1760
|
+
}
|
|
1761
|
+
}
|
|
1762
|
+
if (maxStringLen != null && typeof value === "string" && value.length > maxStringLen) {
|
|
1763
|
+
return value.slice(0, maxStringLen) + "...";
|
|
1764
|
+
}
|
|
1765
|
+
return value;
|
|
1766
|
+
};
|
|
1627
1767
|
};
|
|
1768
|
+
var defaultFilter = createReplacer();
|
|
1628
1769
|
|
|
1629
1770
|
// src/sliding-window-summary.ts
|
|
1630
1771
|
import { invariant as invariant5 } from "@dxos/invariant";
|
|
1631
1772
|
var __dxlog_file5 = "/__w/dxos/dxos/packages/common/util/src/sliding-window-summary.ts";
|
|
1632
1773
|
var SlidingWindowSummary = class {
|
|
1774
|
+
_buffer;
|
|
1775
|
+
_sum = 0;
|
|
1776
|
+
_precision;
|
|
1633
1777
|
constructor(options) {
|
|
1634
|
-
this._sum = 0;
|
|
1635
1778
|
this._buffer = new CircularBuffer(options.dataPoints);
|
|
1636
1779
|
if (options.precision != null) {
|
|
1637
1780
|
invariant5(options.precision >= 0, void 0, {
|
|
@@ -1711,6 +1854,24 @@ var capitalize = (str) => {
|
|
|
1711
1854
|
}
|
|
1712
1855
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
1713
1856
|
};
|
|
1857
|
+
function trim(strings, ...values) {
|
|
1858
|
+
const raw = strings.reduce((out, str, i) => {
|
|
1859
|
+
out += str;
|
|
1860
|
+
if (i < values.length) {
|
|
1861
|
+
const match = str.match(/(^|\n)([ \t]*)$/);
|
|
1862
|
+
const baseIndent = match ? match[2] : "";
|
|
1863
|
+
const val = String(values[i]).replace(/\r?\n/g, "\n" + baseIndent);
|
|
1864
|
+
out += val;
|
|
1865
|
+
}
|
|
1866
|
+
return out;
|
|
1867
|
+
}, "");
|
|
1868
|
+
const lines = raw.split("\n");
|
|
1869
|
+
while (lines.length && !lines[0].trim()) lines.shift();
|
|
1870
|
+
while (lines.length && !lines[lines.length - 1].trim()) lines.pop();
|
|
1871
|
+
const minIndent = Math.min(...lines.filter((l) => l.trim()).map((l) => l.match(/^[ \t]*/)?.[0].length ?? 0));
|
|
1872
|
+
return lines.map((l) => l.slice(minIndent)).join("\n");
|
|
1873
|
+
}
|
|
1874
|
+
var kebabize = (str) => str.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? "-" : "") + $.toLowerCase());
|
|
1714
1875
|
|
|
1715
1876
|
// src/sum.ts
|
|
1716
1877
|
var sum = (values) => values.reduce((a, b) => a + b, 0);
|
|
@@ -1724,18 +1885,6 @@ var throwUnhandledError = (error) => {
|
|
|
1724
1885
|
|
|
1725
1886
|
// src/to-fallback.ts
|
|
1726
1887
|
var idEmoji = [
|
|
1727
|
-
// When changing this set, please check the result in a console or e.g. RunKit (https://runkit.com/thure/642214441dd6ae000855a8de)
|
|
1728
|
-
// Emoji sometimes use a combination of code points, and some code points aren't visible on their own, so by adding or deleting you may unintentionally create non-visible items.
|
|
1729
|
-
// This set was chosen from the characters in Unicode Emoji v15.0 based on the following criteria:
|
|
1730
|
-
// – not people or isolated anthropomorphic faces
|
|
1731
|
-
// – not flags
|
|
1732
|
-
// – more concrete than abstract
|
|
1733
|
-
// – less culturally specific
|
|
1734
|
-
// – less easily confused with another emoji in the set
|
|
1735
|
-
// – requires less special knowledge to identify
|
|
1736
|
-
// – less likely to evoke negative feelings (no meat, no drugs, no weapons, etc)
|
|
1737
|
-
// – less common as a signifier in UX
|
|
1738
|
-
// NOTE that this is intentionally an array of strings because of the way emoji graphemes work.
|
|
1739
1888
|
"\u{1F47B}",
|
|
1740
1889
|
"\u{1F479}",
|
|
1741
1890
|
"\u{1F47D}",
|
|
@@ -1871,17 +2020,18 @@ var idEmoji = [
|
|
|
1871
2020
|
];
|
|
1872
2021
|
var idHue = [
|
|
1873
2022
|
"red",
|
|
1874
|
-
|
|
2023
|
+
"orange",
|
|
1875
2024
|
"amber",
|
|
1876
|
-
|
|
2025
|
+
"yellow",
|
|
1877
2026
|
"lime",
|
|
1878
2027
|
"green",
|
|
1879
2028
|
"emerald",
|
|
1880
2029
|
"teal",
|
|
1881
2030
|
"cyan",
|
|
1882
|
-
//
|
|
1883
|
-
// '
|
|
1884
|
-
// '
|
|
2031
|
+
// Omit colors similar to primary accent.
|
|
2032
|
+
// 'sky' as const,
|
|
2033
|
+
// 'blue' as const,
|
|
2034
|
+
// 'indigo' as const,
|
|
1885
2035
|
"violet",
|
|
1886
2036
|
"purple",
|
|
1887
2037
|
"fuchsia",
|
|
@@ -1909,10 +2059,8 @@ var toFallback = (hash) => {
|
|
|
1909
2059
|
|
|
1910
2060
|
// src/tracer.ts
|
|
1911
2061
|
var Tracer = class {
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
this._recording = false;
|
|
1915
|
-
}
|
|
2062
|
+
_events = /* @__PURE__ */ new Map();
|
|
2063
|
+
_recording = false;
|
|
1916
2064
|
// TODO(burdon): Start/stop methods for recording data? By id?
|
|
1917
2065
|
// Alternatively, enable subscriptions to track/compute series.
|
|
1918
2066
|
// TODO(burdon): Hierarchical traces?
|
|
@@ -2013,7 +2161,7 @@ var stringifyTree = (node, ancestors = [], rows = []) => {
|
|
|
2013
2161
|
};
|
|
2014
2162
|
|
|
2015
2163
|
// src/types.ts
|
|
2016
|
-
var
|
|
2164
|
+
var isTruthy = (value) => !!value;
|
|
2017
2165
|
var isNonNullable = (value) => value != null;
|
|
2018
2166
|
var doAsync = async (fn) => fn();
|
|
2019
2167
|
var getProviderValue = (provider, arg) => {
|
|
@@ -2043,6 +2191,113 @@ var arrayMove = (array, from, to) => {
|
|
|
2043
2191
|
array.splice(to < 0 ? array.length + to : to, 0, array.splice(from, 1)[0]);
|
|
2044
2192
|
return array;
|
|
2045
2193
|
};
|
|
2194
|
+
function arraySwap(array, from, to) {
|
|
2195
|
+
const current = array[from];
|
|
2196
|
+
array[from] = array[to];
|
|
2197
|
+
array[to] = current;
|
|
2198
|
+
return array;
|
|
2199
|
+
}
|
|
2200
|
+
|
|
2201
|
+
// src/unit.ts
|
|
2202
|
+
var createFormat = (unit) => {
|
|
2203
|
+
return (n, precision = unit.precision ?? 0) => {
|
|
2204
|
+
const value = n / unit.quotient;
|
|
2205
|
+
return {
|
|
2206
|
+
unit,
|
|
2207
|
+
value,
|
|
2208
|
+
formattedValue: value.toFixed(precision),
|
|
2209
|
+
toString: () => `${value.toFixed(precision)}${unit.symbol}`
|
|
2210
|
+
};
|
|
2211
|
+
};
|
|
2212
|
+
};
|
|
2213
|
+
var MS_SECONDS = 1e3;
|
|
2214
|
+
var MS_MINUTES = 60 * MS_SECONDS;
|
|
2215
|
+
var MS_HOURS = 60 * MS_MINUTES;
|
|
2216
|
+
var Unit = {
|
|
2217
|
+
// General.
|
|
2218
|
+
Percent: createFormat({
|
|
2219
|
+
symbol: "%",
|
|
2220
|
+
quotient: 1 / 100,
|
|
2221
|
+
precision: 2
|
|
2222
|
+
}),
|
|
2223
|
+
Thousand: createFormat({
|
|
2224
|
+
symbol: "k",
|
|
2225
|
+
quotient: 1e3,
|
|
2226
|
+
precision: 2
|
|
2227
|
+
}),
|
|
2228
|
+
// Bytes (note KB vs KiB).
|
|
2229
|
+
Gigabyte: createFormat({
|
|
2230
|
+
symbol: "GB",
|
|
2231
|
+
quotient: 1e3 * 1e3 * 1e3,
|
|
2232
|
+
precision: 2
|
|
2233
|
+
}),
|
|
2234
|
+
Megabyte: createFormat({
|
|
2235
|
+
symbol: "MB",
|
|
2236
|
+
quotient: 1e3 * 1e3,
|
|
2237
|
+
precision: 2
|
|
2238
|
+
}),
|
|
2239
|
+
Kilobyte: createFormat({
|
|
2240
|
+
symbol: "KB",
|
|
2241
|
+
quotient: 1e3,
|
|
2242
|
+
precision: 2
|
|
2243
|
+
}),
|
|
2244
|
+
Byte: createFormat({
|
|
2245
|
+
symbol: "B",
|
|
2246
|
+
quotient: 1
|
|
2247
|
+
}),
|
|
2248
|
+
// Time.
|
|
2249
|
+
Hour: createFormat({
|
|
2250
|
+
symbol: "h",
|
|
2251
|
+
quotient: MS_HOURS
|
|
2252
|
+
}),
|
|
2253
|
+
Minute: createFormat({
|
|
2254
|
+
symbol: "m",
|
|
2255
|
+
quotient: MS_MINUTES
|
|
2256
|
+
}),
|
|
2257
|
+
Second: createFormat({
|
|
2258
|
+
symbol: "s",
|
|
2259
|
+
quotient: MS_SECONDS,
|
|
2260
|
+
precision: 1
|
|
2261
|
+
}),
|
|
2262
|
+
Millisecond: createFormat({
|
|
2263
|
+
symbol: "ms",
|
|
2264
|
+
quotient: 1
|
|
2265
|
+
}),
|
|
2266
|
+
Duration: (n) => {
|
|
2267
|
+
const hours = Math.floor(n / MS_HOURS);
|
|
2268
|
+
const minutes = Math.floor(n % MS_HOURS / MS_MINUTES);
|
|
2269
|
+
if (hours) {
|
|
2270
|
+
const formattedValue = minutes ? `${hours}h ${minutes}m` : `${hours}h`;
|
|
2271
|
+
return {
|
|
2272
|
+
unit: {
|
|
2273
|
+
symbol: "h",
|
|
2274
|
+
quotient: MS_HOURS
|
|
2275
|
+
},
|
|
2276
|
+
value: hours,
|
|
2277
|
+
formattedValue,
|
|
2278
|
+
toString: () => formattedValue
|
|
2279
|
+
};
|
|
2280
|
+
}
|
|
2281
|
+
if (minutes) {
|
|
2282
|
+
const seconds2 = (n - MS_MINUTES * minutes) / MS_SECONDS;
|
|
2283
|
+
const formattedValue = seconds2 ? `${minutes}m ${seconds2}s` : `${minutes}m`;
|
|
2284
|
+
return {
|
|
2285
|
+
unit: {
|
|
2286
|
+
symbol: "m",
|
|
2287
|
+
quotient: MS_MINUTES
|
|
2288
|
+
},
|
|
2289
|
+
value: minutes,
|
|
2290
|
+
formattedValue,
|
|
2291
|
+
toString: () => formattedValue
|
|
2292
|
+
};
|
|
2293
|
+
}
|
|
2294
|
+
const seconds = n >= MS_SECONDS;
|
|
2295
|
+
if (seconds) {
|
|
2296
|
+
return Unit.Second(n);
|
|
2297
|
+
}
|
|
2298
|
+
return Unit.Millisecond(n);
|
|
2299
|
+
}
|
|
2300
|
+
};
|
|
2046
2301
|
|
|
2047
2302
|
// src/url.ts
|
|
2048
2303
|
var createUrl = (url, search) => {
|
|
@@ -2055,16 +2310,20 @@ var createUrl = (url, search) => {
|
|
|
2055
2310
|
|
|
2056
2311
|
// src/weak.ts
|
|
2057
2312
|
var WeakDictionary = class {
|
|
2313
|
+
_internal = /* @__PURE__ */ new Map();
|
|
2314
|
+
_finalization = new FinalizationRegistry(({ key, ref }) => {
|
|
2315
|
+
if (this._internal.get(key) === ref) {
|
|
2316
|
+
this._internal.delete(key);
|
|
2317
|
+
}
|
|
2318
|
+
});
|
|
2058
2319
|
constructor(entries2) {
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
]));
|
|
2067
|
-
entries2?.forEach(([key, value]) => this._register(key, value));
|
|
2320
|
+
if (entries2) {
|
|
2321
|
+
for (const [key, value] of entries2) {
|
|
2322
|
+
const ref = new WeakRef(value);
|
|
2323
|
+
this._internal.set(key, ref);
|
|
2324
|
+
this._register(key, value, ref);
|
|
2325
|
+
}
|
|
2326
|
+
}
|
|
2068
2327
|
}
|
|
2069
2328
|
*entries() {
|
|
2070
2329
|
for (const [key, value] of this._internal) {
|
|
@@ -2104,10 +2363,45 @@ var WeakDictionary = class {
|
|
|
2104
2363
|
return this._internal.get(key)?.deref();
|
|
2105
2364
|
}
|
|
2106
2365
|
set(key, value) {
|
|
2107
|
-
this._internal.
|
|
2108
|
-
|
|
2366
|
+
const previous = this._internal.get(key)?.deref();
|
|
2367
|
+
if (previous) {
|
|
2368
|
+
this._unregister(previous);
|
|
2369
|
+
}
|
|
2370
|
+
const ref = new WeakRef(value);
|
|
2371
|
+
this._internal.set(key, ref);
|
|
2372
|
+
this._register(key, value, ref);
|
|
2109
2373
|
return this;
|
|
2110
2374
|
}
|
|
2375
|
+
/**
|
|
2376
|
+
* Returns the value for the given key if present, otherwise inserts and returns the default value.
|
|
2377
|
+
* @param key - The key to look up or insert.
|
|
2378
|
+
* @param defaultValue - The value to insert if the key is not present.
|
|
2379
|
+
* @returns The existing or newly inserted value.
|
|
2380
|
+
*/
|
|
2381
|
+
getOrInsert(key, defaultValue) {
|
|
2382
|
+
const existing = this.get(key);
|
|
2383
|
+
if (existing !== void 0) {
|
|
2384
|
+
return existing;
|
|
2385
|
+
}
|
|
2386
|
+
this.set(key, defaultValue);
|
|
2387
|
+
return defaultValue;
|
|
2388
|
+
}
|
|
2389
|
+
/**
|
|
2390
|
+
* Returns the value for the given key if present, otherwise computes, inserts, and returns a new value.
|
|
2391
|
+
* The callback is only invoked when the key is missing.
|
|
2392
|
+
* @param key - The key to look up or insert.
|
|
2393
|
+
* @param callbackfn - Function to compute the value if the key is not present.
|
|
2394
|
+
* @returns The existing or newly computed value.
|
|
2395
|
+
*/
|
|
2396
|
+
getOrInsertComputed(key, callbackfn) {
|
|
2397
|
+
const existing = this.get(key);
|
|
2398
|
+
if (existing !== void 0) {
|
|
2399
|
+
return existing;
|
|
2400
|
+
}
|
|
2401
|
+
const value = callbackfn(key);
|
|
2402
|
+
this.set(key, value);
|
|
2403
|
+
return value;
|
|
2404
|
+
}
|
|
2111
2405
|
has(key) {
|
|
2112
2406
|
return this._internal.has(key) && this._internal.get(key).deref() !== void 0;
|
|
2113
2407
|
}
|
|
@@ -2138,15 +2432,68 @@ var WeakDictionary = class {
|
|
|
2138
2432
|
}
|
|
2139
2433
|
});
|
|
2140
2434
|
}
|
|
2141
|
-
_register(key, value) {
|
|
2142
|
-
this._finalization.register(value,
|
|
2143
|
-
|
|
2435
|
+
_register(key, value, ref) {
|
|
2436
|
+
this._finalization.register(value, {
|
|
2437
|
+
key,
|
|
2438
|
+
ref
|
|
2144
2439
|
}, value);
|
|
2145
2440
|
}
|
|
2146
2441
|
_unregister(value) {
|
|
2147
2442
|
this._finalization.unregister(value);
|
|
2148
2443
|
}
|
|
2149
2444
|
};
|
|
2445
|
+
|
|
2446
|
+
// src/error-format.ts
|
|
2447
|
+
var formatErrorWithCauses = (error) => {
|
|
2448
|
+
const lines = [];
|
|
2449
|
+
let current = error;
|
|
2450
|
+
let level = 0;
|
|
2451
|
+
while (current) {
|
|
2452
|
+
const prefix = level === 0 ? "" : `Caused by: `;
|
|
2453
|
+
lines.push(prefix + (current.stack ?? String(current)));
|
|
2454
|
+
if (!(current.cause instanceof Error)) break;
|
|
2455
|
+
current = current.cause;
|
|
2456
|
+
level += 1;
|
|
2457
|
+
}
|
|
2458
|
+
return lines.join("\n\n");
|
|
2459
|
+
};
|
|
2460
|
+
|
|
2461
|
+
// src/retry.ts
|
|
2462
|
+
var DEFAULT_RETRY_OPTIONS = {
|
|
2463
|
+
count: 3,
|
|
2464
|
+
delayMs: 100,
|
|
2465
|
+
exponent: 2,
|
|
2466
|
+
retryOnError: async () => true,
|
|
2467
|
+
retryOnValue: async () => false
|
|
2468
|
+
};
|
|
2469
|
+
var retry = async (options, cb) => {
|
|
2470
|
+
const fullOptions = {
|
|
2471
|
+
...DEFAULT_RETRY_OPTIONS,
|
|
2472
|
+
...options
|
|
2473
|
+
};
|
|
2474
|
+
let numRetries = 0, currentDelay = fullOptions.delayMs;
|
|
2475
|
+
while (true) {
|
|
2476
|
+
let result;
|
|
2477
|
+
try {
|
|
2478
|
+
result = await cb();
|
|
2479
|
+
} catch (err) {
|
|
2480
|
+
if (numRetries > fullOptions.count || !await fullOptions.retryOnError(err)) {
|
|
2481
|
+
throw err;
|
|
2482
|
+
}
|
|
2483
|
+
await new Promise((resolve) => setTimeout(resolve, currentDelay));
|
|
2484
|
+
currentDelay *= fullOptions.exponent;
|
|
2485
|
+
numRetries++;
|
|
2486
|
+
continue;
|
|
2487
|
+
}
|
|
2488
|
+
if (!await fullOptions.retryOnValue(result)) {
|
|
2489
|
+
return result;
|
|
2490
|
+
}
|
|
2491
|
+
await new Promise((resolve) => setTimeout(resolve, currentDelay));
|
|
2492
|
+
currentDelay *= fullOptions.exponent;
|
|
2493
|
+
numRetries++;
|
|
2494
|
+
continue;
|
|
2495
|
+
}
|
|
2496
|
+
};
|
|
2150
2497
|
export {
|
|
2151
2498
|
BitField,
|
|
2152
2499
|
Callback,
|
|
@@ -2156,11 +2503,14 @@ export {
|
|
|
2156
2503
|
ComplexSet,
|
|
2157
2504
|
HumanHasher,
|
|
2158
2505
|
MapEntry,
|
|
2506
|
+
SKIP,
|
|
2159
2507
|
SlidingWindowSummary,
|
|
2160
2508
|
Tracer,
|
|
2509
|
+
Unit,
|
|
2161
2510
|
WeakDictionary,
|
|
2162
2511
|
accessBy,
|
|
2163
2512
|
arrayMove,
|
|
2513
|
+
arraySwap,
|
|
2164
2514
|
arrayToBuffer,
|
|
2165
2515
|
arrayToHex,
|
|
2166
2516
|
arrayToString,
|
|
@@ -2172,18 +2522,23 @@ export {
|
|
|
2172
2522
|
chunkArray,
|
|
2173
2523
|
clamp,
|
|
2174
2524
|
clearUndefined,
|
|
2525
|
+
coerceArray,
|
|
2175
2526
|
compareMulti,
|
|
2176
2527
|
compareObject,
|
|
2177
2528
|
compareScalar,
|
|
2178
2529
|
compareString,
|
|
2530
|
+
compositeKey,
|
|
2179
2531
|
createBinder,
|
|
2180
2532
|
createBucketReducer,
|
|
2533
|
+
createFilename,
|
|
2181
2534
|
createGroupReducer,
|
|
2535
|
+
createReplacer,
|
|
2182
2536
|
createSetDispatch,
|
|
2183
2537
|
createUrl,
|
|
2184
2538
|
decamelize,
|
|
2185
2539
|
deepMapValues,
|
|
2186
2540
|
deepMapValuesAsync,
|
|
2541
|
+
defaultFilter,
|
|
2187
2542
|
defaultMap,
|
|
2188
2543
|
defer,
|
|
2189
2544
|
deferAsync,
|
|
@@ -2195,12 +2550,11 @@ export {
|
|
|
2195
2550
|
entry,
|
|
2196
2551
|
exponentialBackoffInterval,
|
|
2197
2552
|
forEachAsync,
|
|
2198
|
-
|
|
2553
|
+
formatErrorWithCauses,
|
|
2199
2554
|
getAsyncProviderValue,
|
|
2200
2555
|
getDate,
|
|
2201
2556
|
getDebugName,
|
|
2202
2557
|
getDeep,
|
|
2203
|
-
getFirstTwoRenderableChars,
|
|
2204
2558
|
getHostPlatform,
|
|
2205
2559
|
getPrototypeSpecificInstanceId,
|
|
2206
2560
|
getProviderValue,
|
|
@@ -2216,14 +2570,19 @@ export {
|
|
|
2216
2570
|
intersectBy,
|
|
2217
2571
|
intersection,
|
|
2218
2572
|
iosCheck,
|
|
2573
|
+
isBun,
|
|
2574
|
+
isMobile,
|
|
2575
|
+
isMobileOrTablet,
|
|
2219
2576
|
isNode,
|
|
2220
2577
|
isNonNullable,
|
|
2221
|
-
|
|
2578
|
+
isTauri,
|
|
2579
|
+
isTruthy,
|
|
2222
2580
|
joinTables,
|
|
2223
2581
|
jsonKeyReplacer,
|
|
2224
2582
|
jsonReplacer,
|
|
2225
2583
|
jsonify,
|
|
2226
2584
|
jsonlogify,
|
|
2585
|
+
kebabize,
|
|
2227
2586
|
keyToEmoji,
|
|
2228
2587
|
keyToFallback,
|
|
2229
2588
|
keyToHue,
|
|
@@ -2232,7 +2591,6 @@ export {
|
|
|
2232
2591
|
makeSet,
|
|
2233
2592
|
mapValues,
|
|
2234
2593
|
median,
|
|
2235
|
-
mobileAndTabletCheck,
|
|
2236
2594
|
numericalValues,
|
|
2237
2595
|
omit,
|
|
2238
2596
|
orderKeys,
|
|
@@ -2248,15 +2606,18 @@ export {
|
|
|
2248
2606
|
removeBy,
|
|
2249
2607
|
removeProperties,
|
|
2250
2608
|
removeUndefinedProperties,
|
|
2609
|
+
retry,
|
|
2251
2610
|
safariCheck,
|
|
2252
2611
|
safeAwaitAll,
|
|
2253
2612
|
safeInstanceof,
|
|
2254
2613
|
safeParseFloat,
|
|
2255
2614
|
safeParseInt,
|
|
2256
2615
|
safeParseJson,
|
|
2257
|
-
|
|
2616
|
+
safeStringify,
|
|
2617
|
+
safeUrl,
|
|
2258
2618
|
setDeep,
|
|
2259
2619
|
sortKeys,
|
|
2620
|
+
splitCompositeKey,
|
|
2260
2621
|
stringToArray,
|
|
2261
2622
|
stringifyTree,
|
|
2262
2623
|
stripUndefined,
|
|
@@ -2266,6 +2627,7 @@ export {
|
|
|
2266
2627
|
toFallback,
|
|
2267
2628
|
toHue,
|
|
2268
2629
|
tracer,
|
|
2630
|
+
trim,
|
|
2269
2631
|
visitValues
|
|
2270
2632
|
};
|
|
2271
2633
|
//# sourceMappingURL=index.mjs.map
|