@dxos/util 0.8.4-main.f5c0578 → 0.8.4-main.fbb7a13
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 +351 -106
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +351 -106
- 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/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 +3 -3
- 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 +5 -1
- package/dist/types/src/index.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 +6 -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/string.d.ts +4 -0
- 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 +23 -5
- 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/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -7
- package/src/array.ts +9 -2
- package/src/binder.ts +2 -2
- package/src/deep.ts +2 -0
- package/src/defer.ts +1 -1
- package/src/error-format.ts +22 -0
- package/src/filename.ts +16 -0
- package/src/index.ts +5 -1
- package/src/platform.ts +11 -1
- package/src/retry.ts +74 -0
- package/src/safe-parse.ts +21 -17
- package/src/safe-stringify.ts +146 -0
- package/src/string.ts +7 -0
- package/src/to-fallback.ts +5 -4
- package/src/types.test.ts +11 -1
- package/src/types.ts +38 -10
- package/src/unit.test.ts +25 -0
- package/src/unit.ts +83 -0
- 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
|
|
@@ -377,11 +385,10 @@ import { inspectObject, raise } from "@dxos/debug";
|
|
|
377
385
|
var MAX_SERIALIZATION_LENGTH = 10;
|
|
378
386
|
var ComplexSet = class {
|
|
379
387
|
_projection;
|
|
380
|
-
_values;
|
|
388
|
+
_values = /* @__PURE__ */ new Map();
|
|
381
389
|
// prettier-ignore
|
|
382
390
|
constructor(_projection, values) {
|
|
383
391
|
this._projection = _projection;
|
|
384
|
-
this._values = /* @__PURE__ */ new Map();
|
|
385
392
|
if (values) {
|
|
386
393
|
for (const value of values) {
|
|
387
394
|
this.add(value);
|
|
@@ -472,13 +479,11 @@ var makeSet = (projection) => {
|
|
|
472
479
|
};
|
|
473
480
|
var ComplexMap = class _ComplexMap {
|
|
474
481
|
_keyProjection;
|
|
475
|
-
_keys;
|
|
476
|
-
_values;
|
|
482
|
+
_keys = /* @__PURE__ */ new Map();
|
|
483
|
+
_values = /* @__PURE__ */ new Map();
|
|
477
484
|
// prettier-ignore
|
|
478
485
|
constructor(_keyProjection, entries2) {
|
|
479
486
|
this._keyProjection = _keyProjection;
|
|
480
|
-
this._keys = /* @__PURE__ */ new Map();
|
|
481
|
-
this._values = /* @__PURE__ */ new Map();
|
|
482
487
|
if (entries2) {
|
|
483
488
|
for (const [key, value] of entries2) {
|
|
484
489
|
this.set(key, value);
|
|
@@ -599,11 +604,8 @@ var getDeep = (obj, path) => {
|
|
|
599
604
|
// src/defer-function.ts
|
|
600
605
|
var deferFunction = (fnProvider) => (...args) => fnProvider()(...args);
|
|
601
606
|
|
|
602
|
-
// src/explicit-resource-management-polyfill.ts
|
|
603
|
-
Symbol.dispose ??= Symbol("Symbol.dispose");
|
|
604
|
-
Symbol.asyncDispose ??= Symbol("Symbol.asyncDispose");
|
|
605
|
-
|
|
606
607
|
// src/defer.ts
|
|
608
|
+
import "@hazae41/symbol-dispose-polyfill";
|
|
607
609
|
var defer = (fn) => new DeferGuard(fn);
|
|
608
610
|
var DeferGuard = class {
|
|
609
611
|
_fn;
|
|
@@ -664,32 +666,11 @@ var MapEntry = class {
|
|
|
664
666
|
}
|
|
665
667
|
};
|
|
666
668
|
|
|
667
|
-
// src/
|
|
668
|
-
var
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
"",
|
|
673
|
-
""
|
|
674
|
-
];
|
|
675
|
-
let foundFirst = false;
|
|
676
|
-
for (let i = 0; i < characters.length; i++) {
|
|
677
|
-
const char = characters[i];
|
|
678
|
-
if (renderableCharRegex.test(char)) {
|
|
679
|
-
if (!foundFirst) {
|
|
680
|
-
result[0] = char;
|
|
681
|
-
foundFirst = true;
|
|
682
|
-
} else {
|
|
683
|
-
const textBetween = characters.slice(result[0].length, i).join("");
|
|
684
|
-
if (/[^\p{L}\p{N}_]/u.test(textBetween)) {
|
|
685
|
-
result[1] = char;
|
|
686
|
-
break;
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
return result;
|
|
692
|
-
};
|
|
669
|
+
// src/filename.ts
|
|
670
|
+
var createFilename = ({ parts = [], ext, date = /* @__PURE__ */ new Date() }) => [
|
|
671
|
+
date.toISOString().replace(/[:.]/g, "-"),
|
|
672
|
+
...parts
|
|
673
|
+
].join("_") + (ext ? `.${ext}` : "");
|
|
693
674
|
|
|
694
675
|
// src/for-each-async.ts
|
|
695
676
|
var forEachAsync = (items, fn) => Promise.all(items.map(fn));
|
|
@@ -1222,32 +1203,9 @@ var deepMapValues = (value, fn) => {
|
|
|
1222
1203
|
};
|
|
1223
1204
|
var DeepMapper = class {
|
|
1224
1205
|
_fn;
|
|
1225
|
-
_cyclic;
|
|
1206
|
+
_cyclic = /* @__PURE__ */ new Map();
|
|
1226
1207
|
constructor(_fn) {
|
|
1227
1208
|
this._fn = _fn;
|
|
1228
|
-
this._cyclic = /* @__PURE__ */ new Map();
|
|
1229
|
-
this._recurse = (value) => {
|
|
1230
|
-
if (this._cyclic.has(value)) {
|
|
1231
|
-
return this._cyclic.get(value);
|
|
1232
|
-
}
|
|
1233
|
-
if (Array.isArray(value)) {
|
|
1234
|
-
const res = new Array(value.length);
|
|
1235
|
-
this._cyclic.set(value, res);
|
|
1236
|
-
for (let i = 0; i < value.length; i++) {
|
|
1237
|
-
res[i] = this._map(value[i], i);
|
|
1238
|
-
}
|
|
1239
|
-
return res;
|
|
1240
|
-
} else if (value !== null && typeof value === "object") {
|
|
1241
|
-
const res = {};
|
|
1242
|
-
this._cyclic.set(value, res);
|
|
1243
|
-
for (const key in value) {
|
|
1244
|
-
res[key] = this._map(value[key], key);
|
|
1245
|
-
}
|
|
1246
|
-
return res;
|
|
1247
|
-
} else {
|
|
1248
|
-
return value;
|
|
1249
|
-
}
|
|
1250
|
-
};
|
|
1251
1209
|
}
|
|
1252
1210
|
map(value) {
|
|
1253
1211
|
return this._map(value, void 0);
|
|
@@ -1258,39 +1216,37 @@ var DeepMapper = class {
|
|
|
1258
1216
|
}
|
|
1259
1217
|
return this._fn(value, this._recurse, key);
|
|
1260
1218
|
}
|
|
1261
|
-
_recurse
|
|
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);
|
|
1228
|
+
}
|
|
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);
|
|
1235
|
+
}
|
|
1236
|
+
return res;
|
|
1237
|
+
} else {
|
|
1238
|
+
return value;
|
|
1239
|
+
}
|
|
1240
|
+
};
|
|
1262
1241
|
};
|
|
1263
1242
|
var deepMapValuesAsync = (value, fn) => {
|
|
1264
1243
|
return new DeepMapperAsync(fn).map(value);
|
|
1265
1244
|
};
|
|
1266
1245
|
var DeepMapperAsync = class {
|
|
1267
1246
|
_fn;
|
|
1268
|
-
_cyclic;
|
|
1247
|
+
_cyclic = /* @__PURE__ */ new Map();
|
|
1269
1248
|
constructor(_fn) {
|
|
1270
1249
|
this._fn = _fn;
|
|
1271
|
-
this._cyclic = /* @__PURE__ */ new Map();
|
|
1272
|
-
this._recurse = async (value) => {
|
|
1273
|
-
if (this._cyclic.has(value)) {
|
|
1274
|
-
return this._cyclic.get(value);
|
|
1275
|
-
}
|
|
1276
|
-
if (Array.isArray(value)) {
|
|
1277
|
-
const res = new Array(value.length);
|
|
1278
|
-
this._cyclic.set(value, res);
|
|
1279
|
-
for (let i = 0; i < value.length; i++) {
|
|
1280
|
-
res[i] = await this._map(value[i], i);
|
|
1281
|
-
}
|
|
1282
|
-
return res;
|
|
1283
|
-
} else if (value !== null && typeof value === "object") {
|
|
1284
|
-
const res = {};
|
|
1285
|
-
this._cyclic.set(value, res);
|
|
1286
|
-
for (const key in value) {
|
|
1287
|
-
res[key] = await this._map(value[key], key);
|
|
1288
|
-
}
|
|
1289
|
-
return res;
|
|
1290
|
-
} else {
|
|
1291
|
-
return value;
|
|
1292
|
-
}
|
|
1293
|
-
};
|
|
1294
1250
|
}
|
|
1295
1251
|
map(value) {
|
|
1296
1252
|
return this._map(value, void 0);
|
|
@@ -1301,7 +1257,28 @@ var DeepMapperAsync = class {
|
|
|
1301
1257
|
}
|
|
1302
1258
|
return this._fn(value, this._recurse, key);
|
|
1303
1259
|
}
|
|
1304
|
-
_recurse
|
|
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);
|
|
1269
|
+
}
|
|
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);
|
|
1276
|
+
}
|
|
1277
|
+
return res;
|
|
1278
|
+
} else {
|
|
1279
|
+
return value;
|
|
1280
|
+
}
|
|
1281
|
+
};
|
|
1305
1282
|
};
|
|
1306
1283
|
var visitValues = (object, visitor) => {
|
|
1307
1284
|
if (Array.isArray(object)) {
|
|
@@ -1390,7 +1367,18 @@ var omit = (obj, keys2) => {
|
|
|
1390
1367
|
|
|
1391
1368
|
// src/platform.ts
|
|
1392
1369
|
var isNode = () => typeof process !== "undefined" && process.versions != null && process.versions.node != null;
|
|
1393
|
-
var
|
|
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 = () => {
|
|
1394
1382
|
let check = false;
|
|
1395
1383
|
((a) => {
|
|
1396
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))) {
|
|
@@ -1619,31 +1607,115 @@ var safeInstanceof = (tag) => (target) => {
|
|
|
1619
1607
|
};
|
|
1620
1608
|
|
|
1621
1609
|
// src/safe-parse.ts
|
|
1622
|
-
|
|
1610
|
+
function safeParseInt(str, defaultValue) {
|
|
1623
1611
|
try {
|
|
1624
|
-
const
|
|
1625
|
-
return isNaN(
|
|
1626
|
-
} catch
|
|
1612
|
+
const value = parseInt(str ?? "");
|
|
1613
|
+
return isNaN(value) ? defaultValue : value;
|
|
1614
|
+
} catch {
|
|
1627
1615
|
return defaultValue;
|
|
1628
1616
|
}
|
|
1629
|
-
}
|
|
1630
|
-
|
|
1617
|
+
}
|
|
1618
|
+
function safeParseFloat(str, defaultValue) {
|
|
1631
1619
|
try {
|
|
1632
|
-
|
|
1620
|
+
const value = parseFloat(str ?? "");
|
|
1621
|
+
return isNaN(value) ? defaultValue : value;
|
|
1633
1622
|
} catch {
|
|
1634
|
-
return defaultValue
|
|
1623
|
+
return defaultValue;
|
|
1635
1624
|
}
|
|
1636
|
-
}
|
|
1637
|
-
var safeParseJson = (
|
|
1638
|
-
if (
|
|
1625
|
+
}
|
|
1626
|
+
var safeParseJson = (str, defaultValue) => {
|
|
1627
|
+
if (str && str.length > 0) {
|
|
1639
1628
|
try {
|
|
1640
|
-
return JSON.parse(
|
|
1641
|
-
} catch
|
|
1629
|
+
return JSON.parse(str);
|
|
1630
|
+
} catch {
|
|
1642
1631
|
}
|
|
1643
1632
|
}
|
|
1644
1633
|
return defaultValue;
|
|
1645
1634
|
};
|
|
1646
1635
|
|
|
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
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
return JSON.stringify(obj, replacer, indent);
|
|
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
|
+
|
|
1647
1719
|
// src/sliding-window-summary.ts
|
|
1648
1720
|
import { invariant as invariant5 } from "@dxos/invariant";
|
|
1649
1721
|
var __dxlog_file5 = "/__w/dxos/dxos/packages/common/util/src/sliding-window-summary.ts";
|
|
@@ -1748,6 +1820,7 @@ function trim(strings, ...values) {
|
|
|
1748
1820
|
const minIndent = Math.min(...lines.filter((l) => l.trim()).map((l) => l.match(/^[ \t]*/)?.[0].length ?? 0));
|
|
1749
1821
|
return lines.map((l) => l.slice(minIndent)).join("\n");
|
|
1750
1822
|
}
|
|
1823
|
+
var kebabize = (str) => str.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? "-" : "") + $.toLowerCase());
|
|
1751
1824
|
|
|
1752
1825
|
// src/sum.ts
|
|
1753
1826
|
var sum = (values) => values.reduce((a, b) => a + b, 0);
|
|
@@ -2048,7 +2121,7 @@ var stringifyTree = (node, ancestors = [], rows = []) => {
|
|
|
2048
2121
|
};
|
|
2049
2122
|
|
|
2050
2123
|
// src/types.ts
|
|
2051
|
-
var
|
|
2124
|
+
var isTruthy = (value) => !!value;
|
|
2052
2125
|
var isNonNullable = (value) => value != null;
|
|
2053
2126
|
var doAsync = async (fn) => fn();
|
|
2054
2127
|
var getProviderValue = (provider, arg) => {
|
|
@@ -2078,6 +2151,113 @@ var arrayMove = (array, from, to) => {
|
|
|
2078
2151
|
array.splice(to < 0 ? array.length + to : to, 0, array.splice(from, 1)[0]);
|
|
2079
2152
|
return array;
|
|
2080
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
|
+
}
|
|
2160
|
+
|
|
2161
|
+
// src/unit.ts
|
|
2162
|
+
var createFormat = (unit) => {
|
|
2163
|
+
return (n, precision = unit.precision ?? 0) => {
|
|
2164
|
+
const value = n / unit.quotient;
|
|
2165
|
+
return {
|
|
2166
|
+
unit,
|
|
2167
|
+
value,
|
|
2168
|
+
formattedValue: value.toFixed(precision),
|
|
2169
|
+
toString: () => `${value.toFixed(precision)}${unit.symbol}`
|
|
2170
|
+
};
|
|
2171
|
+
};
|
|
2172
|
+
};
|
|
2173
|
+
var MS_SECONDS = 1e3;
|
|
2174
|
+
var MS_MINUTES = 60 * MS_SECONDS;
|
|
2175
|
+
var MS_HOURS = 60 * MS_MINUTES;
|
|
2176
|
+
var Unit = {
|
|
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({
|
|
2210
|
+
symbol: "h",
|
|
2211
|
+
quotient: MS_HOURS
|
|
2212
|
+
}),
|
|
2213
|
+
Minute: createFormat({
|
|
2214
|
+
symbol: "m",
|
|
2215
|
+
quotient: MS_MINUTES
|
|
2216
|
+
}),
|
|
2217
|
+
Second: createFormat({
|
|
2218
|
+
symbol: "s",
|
|
2219
|
+
quotient: MS_SECONDS,
|
|
2220
|
+
precision: 1
|
|
2221
|
+
}),
|
|
2222
|
+
Millisecond: createFormat({
|
|
2223
|
+
symbol: "ms",
|
|
2224
|
+
quotient: 1
|
|
2225
|
+
}),
|
|
2226
|
+
Duration: (n) => {
|
|
2227
|
+
const hours = Math.floor(n / MS_HOURS);
|
|
2228
|
+
const minutes = Math.floor(n % MS_HOURS / MS_MINUTES);
|
|
2229
|
+
if (hours) {
|
|
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
|
+
};
|
|
2240
|
+
}
|
|
2241
|
+
if (minutes) {
|
|
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
|
+
};
|
|
2253
|
+
}
|
|
2254
|
+
const seconds = n >= MS_SECONDS;
|
|
2255
|
+
if (seconds) {
|
|
2256
|
+
return Unit.Second(n);
|
|
2257
|
+
}
|
|
2258
|
+
return Unit.Millisecond(n);
|
|
2259
|
+
}
|
|
2260
|
+
};
|
|
2081
2261
|
|
|
2082
2262
|
// src/url.ts
|
|
2083
2263
|
var createUrl = (url, search) => {
|
|
@@ -2182,6 +2362,58 @@ var WeakDictionary = class {
|
|
|
2182
2362
|
this._finalization.unregister(value);
|
|
2183
2363
|
}
|
|
2184
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;
|
|
2415
|
+
}
|
|
2416
|
+
};
|
|
2185
2417
|
export {
|
|
2186
2418
|
BitField,
|
|
2187
2419
|
Callback,
|
|
@@ -2191,11 +2423,14 @@ export {
|
|
|
2191
2423
|
ComplexSet,
|
|
2192
2424
|
HumanHasher,
|
|
2193
2425
|
MapEntry,
|
|
2426
|
+
SKIP,
|
|
2194
2427
|
SlidingWindowSummary,
|
|
2195
2428
|
Tracer,
|
|
2429
|
+
Unit,
|
|
2196
2430
|
WeakDictionary,
|
|
2197
2431
|
accessBy,
|
|
2198
2432
|
arrayMove,
|
|
2433
|
+
arraySwap,
|
|
2199
2434
|
arrayToBuffer,
|
|
2200
2435
|
arrayToHex,
|
|
2201
2436
|
arrayToString,
|
|
@@ -2207,18 +2442,22 @@ export {
|
|
|
2207
2442
|
chunkArray,
|
|
2208
2443
|
clamp,
|
|
2209
2444
|
clearUndefined,
|
|
2445
|
+
coerceArray,
|
|
2210
2446
|
compareMulti,
|
|
2211
2447
|
compareObject,
|
|
2212
2448
|
compareScalar,
|
|
2213
2449
|
compareString,
|
|
2214
2450
|
createBinder,
|
|
2215
2451
|
createBucketReducer,
|
|
2452
|
+
createFilename,
|
|
2216
2453
|
createGroupReducer,
|
|
2454
|
+
createReplacer,
|
|
2217
2455
|
createSetDispatch,
|
|
2218
2456
|
createUrl,
|
|
2219
2457
|
decamelize,
|
|
2220
2458
|
deepMapValues,
|
|
2221
2459
|
deepMapValuesAsync,
|
|
2460
|
+
defaultFilter,
|
|
2222
2461
|
defaultMap,
|
|
2223
2462
|
defer,
|
|
2224
2463
|
deferAsync,
|
|
@@ -2230,12 +2469,12 @@ export {
|
|
|
2230
2469
|
entry,
|
|
2231
2470
|
exponentialBackoffInterval,
|
|
2232
2471
|
forEachAsync,
|
|
2472
|
+
formatErrorWithCauses,
|
|
2233
2473
|
get,
|
|
2234
2474
|
getAsyncProviderValue,
|
|
2235
2475
|
getDate,
|
|
2236
2476
|
getDebugName,
|
|
2237
2477
|
getDeep,
|
|
2238
|
-
getFirstTwoRenderableChars,
|
|
2239
2478
|
getHostPlatform,
|
|
2240
2479
|
getPrototypeSpecificInstanceId,
|
|
2241
2480
|
getProviderValue,
|
|
@@ -2251,14 +2490,19 @@ export {
|
|
|
2251
2490
|
intersectBy,
|
|
2252
2491
|
intersection,
|
|
2253
2492
|
iosCheck,
|
|
2493
|
+
isBun,
|
|
2494
|
+
isMobile,
|
|
2495
|
+
isMobileOrTablet,
|
|
2254
2496
|
isNode,
|
|
2255
2497
|
isNonNullable,
|
|
2256
|
-
|
|
2498
|
+
isTauri,
|
|
2499
|
+
isTruthy,
|
|
2257
2500
|
joinTables,
|
|
2258
2501
|
jsonKeyReplacer,
|
|
2259
2502
|
jsonReplacer,
|
|
2260
2503
|
jsonify,
|
|
2261
2504
|
jsonlogify,
|
|
2505
|
+
kebabize,
|
|
2262
2506
|
keyToEmoji,
|
|
2263
2507
|
keyToFallback,
|
|
2264
2508
|
keyToHue,
|
|
@@ -2267,7 +2511,6 @@ export {
|
|
|
2267
2511
|
makeSet,
|
|
2268
2512
|
mapValues,
|
|
2269
2513
|
median,
|
|
2270
|
-
mobileAndTabletCheck,
|
|
2271
2514
|
numericalValues,
|
|
2272
2515
|
omit,
|
|
2273
2516
|
orderKeys,
|
|
@@ -2283,12 +2526,14 @@ export {
|
|
|
2283
2526
|
removeBy,
|
|
2284
2527
|
removeProperties,
|
|
2285
2528
|
removeUndefinedProperties,
|
|
2529
|
+
retry,
|
|
2286
2530
|
safariCheck,
|
|
2287
2531
|
safeAwaitAll,
|
|
2288
2532
|
safeInstanceof,
|
|
2289
2533
|
safeParseFloat,
|
|
2290
2534
|
safeParseInt,
|
|
2291
2535
|
safeParseJson,
|
|
2536
|
+
safeStringify,
|
|
2292
2537
|
set,
|
|
2293
2538
|
setDeep,
|
|
2294
2539
|
sortKeys,
|