@dxos/util 0.8.4-main.bc674ce → 0.8.4-main.bd9b33e6c8

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 (41) hide show
  1. package/dist/lib/browser/index.mjs +41 -30
  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 +41 -30
  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/circular-buffer.d.ts +1 -0
  8. package/dist/types/src/circular-buffer.d.ts.map +1 -1
  9. package/dist/types/src/composite-key.d.ts +10 -0
  10. package/dist/types/src/composite-key.d.ts.map +1 -0
  11. package/dist/types/src/composite-key.test.d.ts +2 -0
  12. package/dist/types/src/composite-key.test.d.ts.map +1 -0
  13. package/dist/types/src/deep.d.ts +0 -3
  14. package/dist/types/src/deep.d.ts.map +1 -1
  15. package/dist/types/src/index.d.ts +1 -0
  16. package/dist/types/src/index.d.ts.map +1 -1
  17. package/dist/types/src/platform.d.ts.map +1 -1
  18. package/dist/types/src/safe-parse.d.ts +1 -0
  19. package/dist/types/src/safe-parse.d.ts.map +1 -1
  20. package/dist/types/src/safe-stringify.d.ts +1 -1
  21. package/dist/types/src/safe-stringify.d.ts.map +1 -1
  22. package/dist/types/src/safe-stringify.test.d.ts +2 -0
  23. package/dist/types/src/safe-stringify.test.d.ts.map +1 -0
  24. package/dist/types/src/to-fallback.d.ts +18 -4
  25. package/dist/types/src/to-fallback.d.ts.map +1 -1
  26. package/dist/types/src/types.d.ts +1 -1
  27. package/dist/types/src/types.d.ts.map +1 -1
  28. package/dist/types/tsconfig.tsbuildinfo +1 -1
  29. package/package.json +6 -10
  30. package/src/circular-buffer.test.ts +26 -0
  31. package/src/circular-buffer.ts +5 -0
  32. package/src/composite-key.test.ts +31 -0
  33. package/src/composite-key.ts +16 -0
  34. package/src/deep.ts +0 -6
  35. package/src/index.ts +1 -0
  36. package/src/platform.ts +28 -6
  37. package/src/safe-parse.ts +8 -0
  38. package/src/safe-stringify.test.ts +96 -0
  39. package/src/safe-stringify.ts +15 -8
  40. package/src/to-fallback.ts +39 -156
  41. package/src/types.ts +1 -1
@@ -335,6 +335,10 @@ var CircularBuffer = class {
335
335
  get elementCount() {
336
336
  return this._elementCount;
337
337
  }
338
+ clear() {
339
+ this._nextIndex = 0;
340
+ this._elementCount = 0;
341
+ }
338
342
  getLast() {
339
343
  if (this._elementCount === 0) {
340
344
  return void 0;
@@ -567,15 +571,18 @@ var makeMap = (keyProjection) => class BoundComplexMap extends ComplexMap {
567
571
  }
568
572
  };
569
573
 
574
+ // src/composite-key.ts
575
+ var SEPARATOR = ":";
576
+ var compositeKey = (...parts) => parts.join(SEPARATOR);
577
+ var splitCompositeKey = (key) => key.split(SEPARATOR);
578
+
570
579
  // src/deep.ts
571
- import get from "lodash.get";
572
- import set from "lodash.set";
573
580
  import { invariant as invariant4 } from "@dxos/invariant";
574
581
  var __dxlog_file4 = "/__w/dxos/dxos/packages/common/util/src/deep.ts";
575
582
  var setDeep = (obj, path, value) => {
576
583
  invariant4(path.length > 0, void 0, {
577
584
  F: __dxlog_file4,
578
- L: 18,
585
+ L: 12,
579
586
  S: void 0,
580
587
  A: [
581
588
  "path.length > 0",
@@ -1018,7 +1025,7 @@ var defaultMap = (map, key, def) => {
1018
1025
  };
1019
1026
 
1020
1027
  // src/instance-id.ts
1021
- var symbol = Symbol.for("dxos.instance-contexts");
1028
+ var symbol = /* @__PURE__ */ Symbol.for("dxos.instance-contexts");
1022
1029
  var instanceContexts = globalThis[symbol] ??= /* @__PURE__ */ new WeakMap();
1023
1030
  var getPrototypeSpecificInstanceId = (instance) => {
1024
1031
  const prototype = Object.getPrototypeOf(instance);
@@ -1400,7 +1407,7 @@ var iosCheck = () => {
1400
1407
  };
1401
1408
  var safariCheck = () => typeof navigator !== "undefined" && /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
1402
1409
  var getHostPlatform = () => {
1403
- if (!("navigator" in window)) {
1410
+ if (!("navigator" in globalThis)) {
1404
1411
  return "unknown";
1405
1412
  }
1406
1413
  const platform = (navigator.userAgentData?.platform || navigator.platform)?.toLowerCase();
@@ -1595,7 +1602,7 @@ var safeAwaitAll = async (source, taskFactory, onError) => {
1595
1602
  };
1596
1603
 
1597
1604
  // src/safe-instanceof.ts
1598
- var instanceTag = Symbol("instanceTag");
1605
+ var instanceTag = /* @__PURE__ */ Symbol("instanceTag");
1599
1606
  var safeInstanceof = (tag) => (target) => {
1600
1607
  target.prototype[instanceTag] = tag;
1601
1608
  Object.defineProperty(target.prototype, Symbol.hasInstance, {
@@ -1632,6 +1639,13 @@ var safeParseJson = (str, defaultValue) => {
1632
1639
  }
1633
1640
  return defaultValue;
1634
1641
  };
1642
+ var safeUrl = (str) => {
1643
+ try {
1644
+ return new URL(str ?? "");
1645
+ } catch {
1646
+ return void 0;
1647
+ }
1648
+ };
1635
1649
 
1636
1650
  // src/safe-stringify.ts
1637
1651
  var SKIP = Object.freeze({});
@@ -1642,6 +1656,9 @@ function safeStringify(obj, filter = defaultFilter, indent = 2) {
1642
1656
  let path = key;
1643
1657
  if (!key) {
1644
1658
  path = "$";
1659
+ if (value != null && typeof value === "object") {
1660
+ seen.set(value, path);
1661
+ }
1645
1662
  return value;
1646
1663
  } else if (this) {
1647
1664
  const parentPath = seen.get(this);
@@ -1653,7 +1670,7 @@ function safeStringify(obj, filter = defaultFilter, indent = 2) {
1653
1670
  if (typeof value === "function") {
1654
1671
  return void 0;
1655
1672
  }
1656
- if (typeof value === "object" && Object.getPrototypeOf(value) !== Object.prototype) {
1673
+ if (typeof value === "object" && Object.getPrototypeOf(value) !== Object.prototype && !Array.isArray(value)) {
1657
1674
  return void 0;
1658
1675
  }
1659
1676
  if (typeof value === "object" && value !== null) {
@@ -1674,7 +1691,11 @@ function safeStringify(obj, filter = defaultFilter, indent = 2) {
1674
1691
  return `ERROR: ${error.message}`;
1675
1692
  }
1676
1693
  }
1677
- return JSON.stringify(obj, replacer, indent);
1694
+ try {
1695
+ return JSON.stringify(obj, replacer, indent);
1696
+ } catch (error) {
1697
+ return `ERROR: ${error.message}`;
1698
+ }
1678
1699
  }
1679
1700
  var createReplacer = ({ omit: omit2, parse, maxDepth, maxArrayLen, maxStringLen } = {}) => {
1680
1701
  let currentDepth = 0;
@@ -1689,6 +1710,9 @@ var createReplacer = ({ omit: omit2, parse, maxDepth, maxArrayLen, maxStringLen
1689
1710
  if (typeof value === "function") {
1690
1711
  return SKIP;
1691
1712
  }
1713
+ if (maxArrayLen != null && Array.isArray(value) && value.length > maxArrayLen) {
1714
+ return `[length: ${value.length}]`;
1715
+ }
1692
1716
  if (value && typeof value === "object") {
1693
1717
  depthMap.set(value, currentDepth);
1694
1718
  if (maxDepth != null && currentDepth >= maxDepth) {
@@ -1705,9 +1729,6 @@ var createReplacer = ({ omit: omit2, parse, maxDepth, maxArrayLen, maxStringLen
1705
1729
  return value;
1706
1730
  }
1707
1731
  }
1708
- if (maxArrayLen != null && Array.isArray(value) && value.length > maxArrayLen) {
1709
- return `[length: ${value.length}]`;
1710
- }
1711
1732
  if (maxStringLen != null && typeof value === "string" && value.length > maxStringLen) {
1712
1733
  return value.slice(0, maxStringLen) + "...";
1713
1734
  }
@@ -1834,18 +1855,6 @@ var throwUnhandledError = (error) => {
1834
1855
 
1835
1856
  // src/to-fallback.ts
1836
1857
  var idEmoji = [
1837
- // When changing this set, please check the result in a console or e.g. RunKit (https://runkit.com/thure/642214441dd6ae000855a8de)
1838
- // 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.
1839
- // This set was chosen from the characters in Unicode Emoji v15.0 based on the following criteria:
1840
- // – not people or isolated anthropomorphic faces
1841
- // – not flags
1842
- // – more concrete than abstract
1843
- // – less culturally specific
1844
- // – less easily confused with another emoji in the set
1845
- // – requires less special knowledge to identify
1846
- // – less likely to evoke negative feelings (no meat, no drugs, no weapons, etc)
1847
- // – less common as a signifier in UX
1848
- // NOTE that this is intentionally an array of strings because of the way emoji graphemes work.
1849
1858
  "\u{1F47B}",
1850
1859
  "\u{1F479}",
1851
1860
  "\u{1F47D}",
@@ -1981,17 +1990,18 @@ var idEmoji = [
1981
1990
  ];
1982
1991
  var idHue = [
1983
1992
  "red",
1984
- // 'orange' as const, /* More shades in these palettes are considered “ugly” */
1993
+ "orange",
1985
1994
  "amber",
1986
- // 'yellow' as const, /* More shades in these palettes are considered “ugly” */
1995
+ "yellow",
1987
1996
  "lime",
1988
1997
  "green",
1989
1998
  "emerald",
1990
1999
  "teal",
1991
2000
  "cyan",
1992
- // 'sky' as const, /* Omitted since it is quite similar to the primary accent palette */
1993
- // 'blue' as const, /* Omitted since it is quite similar to the primary accent palette */
1994
- // 'indigo' as const, /* Omitted since it is quite similar to the primary accent palette */
2001
+ // Omit colors similar to primary accent.
2002
+ // 'sky' as const,
2003
+ // 'blue' as const,
2004
+ // 'indigo' as const,
1995
2005
  "violet",
1996
2006
  "purple",
1997
2007
  "fuchsia",
@@ -2447,6 +2457,7 @@ export {
2447
2457
  compareObject,
2448
2458
  compareScalar,
2449
2459
  compareString,
2460
+ compositeKey,
2450
2461
  createBinder,
2451
2462
  createBucketReducer,
2452
2463
  createFilename,
@@ -2470,7 +2481,6 @@ export {
2470
2481
  exponentialBackoffInterval,
2471
2482
  forEachAsync,
2472
2483
  formatErrorWithCauses,
2473
- get,
2474
2484
  getAsyncProviderValue,
2475
2485
  getDate,
2476
2486
  getDebugName,
@@ -2534,9 +2544,10 @@ export {
2534
2544
  safeParseInt,
2535
2545
  safeParseJson,
2536
2546
  safeStringify,
2537
- set,
2547
+ safeUrl,
2538
2548
  setDeep,
2539
2549
  sortKeys,
2550
+ splitCompositeKey,
2540
2551
  stringToArray,
2541
2552
  stringifyTree,
2542
2553
  stripUndefined,