@ls-stack/utils 3.12.3 → 3.14.0

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 (50) hide show
  1. package/lib/arrayUtils.cjs +5 -2
  2. package/lib/arrayUtils.js +3 -2
  3. package/lib/assertions.cjs +42 -34
  4. package/lib/assertions.d.cts +175 -11
  5. package/lib/assertions.d.ts +175 -11
  6. package/lib/assertions.js +2 -1
  7. package/lib/cache.cjs +7 -4
  8. package/lib/cache.js +2 -1
  9. package/lib/{chunk-UTFE4P3P.js → chunk-DMW5Q4T2.js} +1 -1
  10. package/lib/{chunk-OHHF4CJZ.js → chunk-GKOTKAIV.js} +1 -1
  11. package/lib/chunk-NH2LCAQS.js +56 -0
  12. package/lib/chunk-SSKW673U.js +36 -0
  13. package/lib/chunk-WS4WEVHU.js +57 -0
  14. package/lib/concurrentCalls.cjs +20 -14
  15. package/lib/concurrentCalls.d.cts +2 -0
  16. package/lib/concurrentCalls.d.ts +2 -0
  17. package/lib/concurrentCalls.js +5 -2
  18. package/lib/createThrottleController.cjs +5 -2
  19. package/lib/createThrottleController.js +3 -2
  20. package/lib/enhancedMap.cjs +5 -2
  21. package/lib/enhancedMap.js +3 -2
  22. package/lib/getCompositeKey.cjs +86 -0
  23. package/lib/getCompositeKey.d.cts +10 -0
  24. package/lib/getCompositeKey.d.ts +10 -0
  25. package/lib/getCompositeKey.js +8 -0
  26. package/lib/getValueStableKey.cjs +10 -4
  27. package/lib/getValueStableKey.d.cts +5 -1
  28. package/lib/getValueStableKey.d.ts +5 -1
  29. package/lib/getValueStableKey.js +5 -49
  30. package/lib/interpolate.cjs +2 -2
  31. package/lib/interpolate.js +2 -1
  32. package/lib/objUtils.d.cts +1 -0
  33. package/lib/objUtils.d.ts +1 -0
  34. package/lib/parallelAsyncCalls.cjs +10 -7
  35. package/lib/parallelAsyncCalls.js +2 -1
  36. package/lib/saferTyping.d.cts +11 -1
  37. package/lib/saferTyping.d.ts +11 -1
  38. package/lib/serializeXML.js +3 -2
  39. package/lib/testUtils.cjs +5 -2
  40. package/lib/testUtils.js +3 -2
  41. package/lib/tsResult.cjs +9 -4
  42. package/lib/tsResult.js +2 -1
  43. package/lib/typeGuards.cjs +65 -0
  44. package/lib/typeGuards.d.cts +109 -0
  45. package/lib/typeGuards.d.ts +109 -0
  46. package/lib/typeGuards.js +16 -0
  47. package/lib/yamlStringify.cjs +17 -9
  48. package/lib/yamlStringify.js +7 -2
  49. package/package.json +9 -1
  50. package/lib/chunk-3XCS7FVO.js +0 -66
@@ -0,0 +1,36 @@
1
+ // src/typeGuards.ts
2
+ function isObject(value) {
3
+ return typeof value === "object" && value !== null && !Array.isArray(value);
4
+ }
5
+ function isFunction(value) {
6
+ return typeof value === "function";
7
+ }
8
+ function isPromise(value) {
9
+ return isObject(value) && "then" in value && isFunction(value.then);
10
+ }
11
+ function isPlainObject(value) {
12
+ if (!value || typeof value !== "object") return false;
13
+ const proto = Object.getPrototypeOf(value);
14
+ if (proto === null) {
15
+ return true;
16
+ }
17
+ const Ctor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor;
18
+ if (Ctor === Object) return true;
19
+ const objectCtorString = Object.prototype.constructor.toString();
20
+ return typeof Ctor == "function" && Function.toString.call(Ctor) === objectCtorString;
21
+ }
22
+ function isNonEmptyArray(value) {
23
+ return value.length > 0;
24
+ }
25
+ function arrayHasAtLeastXItems(array, minLength) {
26
+ return array.length >= minLength;
27
+ }
28
+
29
+ export {
30
+ isObject,
31
+ isFunction,
32
+ isPromise,
33
+ isPlainObject,
34
+ isNonEmptyArray,
35
+ arrayHasAtLeastXItems
36
+ };
@@ -0,0 +1,57 @@
1
+ import {
2
+ isFunction,
3
+ isObject,
4
+ isPlainObject,
5
+ isPromise
6
+ } from "./chunk-SSKW673U.js";
7
+
8
+ // src/assertions.ts
9
+ var undefErrMsg = "not undefined assertion failed";
10
+ var nullishErrMsg = "not nullish assertion failed";
11
+ function notUndefined(value, error = undefErrMsg) {
12
+ if (value === void 0) {
13
+ throw typeof error === "function" ? error() : new Error(error);
14
+ }
15
+ return value;
16
+ }
17
+ function notNullish(value, error = nullishErrMsg) {
18
+ if (value === void 0 || value === null) {
19
+ throw typeof error === "function" ? error() : new Error(error);
20
+ }
21
+ return value;
22
+ }
23
+ function assertIsNotNullish(value, error = nullishErrMsg) {
24
+ if (value === void 0 || value === null) {
25
+ throw typeof error === "function" ? error() : new Error(error);
26
+ }
27
+ }
28
+ function assertIsNotUndefined(value, error = undefErrMsg) {
29
+ if (value === void 0) {
30
+ throw typeof error === "function" ? error() : new Error(error);
31
+ }
32
+ }
33
+ function invariant(condition, error = "Invariant violation") {
34
+ if (!condition) {
35
+ throw typeof error === "function" ? error() : new Error(`Invariant violation: ${error}`);
36
+ }
37
+ }
38
+ function exhaustiveCheck(narrowedType) {
39
+ return new Error("This should never happen");
40
+ }
41
+ var isFunction2 = isFunction;
42
+ var isObject2 = isObject;
43
+ var isPlainObject2 = isPlainObject;
44
+ var isPromise2 = isPromise;
45
+
46
+ export {
47
+ notUndefined,
48
+ notNullish,
49
+ assertIsNotNullish,
50
+ assertIsNotUndefined,
51
+ invariant,
52
+ exhaustiveCheck,
53
+ isFunction2 as isFunction,
54
+ isObject2 as isObject,
55
+ isPlainObject2 as isPlainObject,
56
+ isPromise2 as isPromise
57
+ };
@@ -26,12 +26,7 @@ __export(concurrentCalls_exports, {
26
26
  module.exports = __toCommonJS(concurrentCalls_exports);
27
27
  var import_t_result = require("t-result");
28
28
 
29
- // src/assertions.ts
30
- function invariant(condition, errorMsg = "Invariant violation") {
31
- if (!condition) {
32
- throw new Error(`Invariant violation: ${errorMsg}`);
33
- }
34
- }
29
+ // src/typeGuards.ts
35
30
  function isObject(value) {
36
31
  return typeof value === "object" && value !== null && !Array.isArray(value);
37
32
  }
@@ -42,12 +37,21 @@ function isPromise(value) {
42
37
  return isObject(value) && "then" in value && isFunction(value.then);
43
38
  }
44
39
 
40
+ // src/assertions.ts
41
+ function invariant(condition, error = "Invariant violation") {
42
+ if (!condition) {
43
+ throw typeof error === "function" ? error() : new Error(`Invariant violation: ${error}`);
44
+ }
45
+ }
46
+ var isFunction2 = isFunction;
47
+ var isPromise2 = isPromise;
48
+
45
49
  // src/arrayUtils.ts
46
50
  function truncateArray(array, maxLength, appendIfTruncated) {
47
51
  const truncate = array.length > maxLength;
48
52
  const result = truncate ? [...array.slice(0, maxLength)] : array;
49
53
  if (truncate && appendIfTruncated) {
50
- if (isFunction(appendIfTruncated)) {
54
+ if (isFunction2(appendIfTruncated)) {
51
55
  return [...result, appendIfTruncated(array.length - maxLength)];
52
56
  }
53
57
  return [...result, appendIfTruncated];
@@ -76,14 +80,14 @@ var ConcurrentCalls = class {
76
80
  }
77
81
  resultifyAdd(...calls) {
78
82
  const processedCalls = calls.map((call) => {
79
- if (isPromise(call)) {
83
+ if (isPromise2(call)) {
80
84
  return call.then((value) => import_t_result.Result.ok(value)).catch((err) => import_t_result.Result.err((0, import_t_result.unknownToError)(err)));
81
85
  } else {
82
86
  const originalFn = call;
83
87
  return async () => {
84
88
  try {
85
89
  const valueOrPromise = originalFn();
86
- const value = isPromise(valueOrPromise) ? await valueOrPromise : valueOrPromise;
90
+ const value = isPromise2(valueOrPromise) ? await valueOrPromise : valueOrPromise;
87
91
  return import_t_result.Result.ok(value);
88
92
  } catch (err) {
89
93
  return import_t_result.Result.err((0, import_t_result.unknownToError)(err));
@@ -101,7 +105,7 @@ var ConcurrentCalls = class {
101
105
  const asyncResults = await Promise.all(
102
106
  this.#pendingCalls.map(async (fn, i) => {
103
107
  try {
104
- const isP = isPromise(fn);
108
+ const isP = isPromise2(fn);
105
109
  if (delayStart) {
106
110
  invariant(
107
111
  !isP,
@@ -131,7 +135,7 @@ var ConcurrentCalls = class {
131
135
  const settledResults = await Promise.allSettled(
132
136
  this.#pendingCalls.map(async (callOrPromise, i) => {
133
137
  try {
134
- const isP = isPromise(callOrPromise);
138
+ const isP = isPromise2(callOrPromise);
135
139
  if (delayStart) {
136
140
  invariant(
137
141
  !isP,
@@ -186,7 +190,7 @@ var ConcurrentCallsWithMetadata = class {
186
190
  }
187
191
  resultifyAdd(...items) {
188
192
  const processedItems = items.map(({ fn, metadata }) => {
189
- const cb = isPromise(fn) ? (0, import_t_result.resultify)(fn) : () => (0, import_t_result.resultify)(async () => {
193
+ const cb = isPromise2(fn) ? (0, import_t_result.resultify)(fn) : () => (0, import_t_result.resultify)(async () => {
190
194
  const result = await fn();
191
195
  return result;
192
196
  });
@@ -210,7 +214,7 @@ var ConcurrentCallsWithMetadata = class {
210
214
  if (delayStart) {
211
215
  await sleep(delayStart(i));
212
216
  }
213
- const result = await (isPromise(call.fn) ? call.fn : call.fn());
217
+ const result = await (isPromise2(call.fn) ? call.fn : call.fn());
214
218
  if (!result.ok) {
215
219
  throw { metadata: call.metadata, error: result.error };
216
220
  }
@@ -244,6 +248,7 @@ var ConcurrentCallsWithMetadata = class {
244
248
  return {
245
249
  succeeded: [],
246
250
  failed: [],
251
+ failures: [],
247
252
  results: [],
248
253
  allFailed: false,
249
254
  total: 0,
@@ -256,7 +261,7 @@ var ConcurrentCallsWithMetadata = class {
256
261
  if (delayStart) {
257
262
  await sleep(delayStart(i));
258
263
  }
259
- const result = await (isPromise(call.fn) ? call.fn : call.fn());
264
+ const result = await (isPromise2(call.fn) ? call.fn : call.fn());
260
265
  if (!result.ok) {
261
266
  throw result.error;
262
267
  }
@@ -294,6 +299,7 @@ var ConcurrentCallsWithMetadata = class {
294
299
  return {
295
300
  succeeded: succeededProcessing,
296
301
  failed: failedProcessing,
302
+ failures: failedProcessing,
297
303
  results: resultsProcessing,
298
304
  allFailed,
299
305
  total,
@@ -56,7 +56,9 @@ declare class ConcurrentCallsWithMetadata<M extends ValidMetadata, R = unknown,
56
56
  runAll({ delayStart }?: RunProps): Promise<Result<SucceededCall<R, M>[], FailedCall<M, E>>>;
57
57
  runAllSettled({ delayStart }?: RunProps): Promise<{
58
58
  allFailed: boolean;
59
+ /** @deprecated Use failures property instead */
59
60
  failed: FailedCall<M, E>[];
61
+ failures: FailedCall<M, E>[];
60
62
  succeeded: SucceededCall<R, M>[];
61
63
  total: number;
62
64
  results: SettledResultWithMetadata<R, M, E>[];
@@ -56,7 +56,9 @@ declare class ConcurrentCallsWithMetadata<M extends ValidMetadata, R = unknown,
56
56
  runAll({ delayStart }?: RunProps): Promise<Result<SucceededCall<R, M>[], FailedCall<M, E>>>;
57
57
  runAllSettled({ delayStart }?: RunProps): Promise<{
58
58
  allFailed: boolean;
59
+ /** @deprecated Use failures property instead */
59
60
  failed: FailedCall<M, E>[];
61
+ failures: FailedCall<M, E>[];
60
62
  succeeded: SucceededCall<R, M>[];
61
63
  total: number;
62
64
  results: SettledResultWithMetadata<R, M, E>[];
@@ -6,11 +6,12 @@ import {
6
6
  } from "./chunk-5DZT3Z5Z.js";
7
7
  import {
8
8
  truncateArray
9
- } from "./chunk-UTFE4P3P.js";
9
+ } from "./chunk-DMW5Q4T2.js";
10
10
  import {
11
11
  invariant,
12
12
  isPromise
13
- } from "./chunk-3XCS7FVO.js";
13
+ } from "./chunk-WS4WEVHU.js";
14
+ import "./chunk-SSKW673U.js";
14
15
 
15
16
  // src/concurrentCalls.ts
16
17
  import { Result, resultify, unknownToError } from "t-result";
@@ -191,6 +192,7 @@ var ConcurrentCallsWithMetadata = class {
191
192
  return {
192
193
  succeeded: [],
193
194
  failed: [],
195
+ failures: [],
194
196
  results: [],
195
197
  allFailed: false,
196
198
  total: 0,
@@ -241,6 +243,7 @@ var ConcurrentCallsWithMetadata = class {
241
243
  return {
242
244
  succeeded: succeededProcessing,
243
245
  failed: failedProcessing,
246
+ failures: failedProcessing,
244
247
  results: resultsProcessing,
245
248
  allFailed,
246
249
  total,
@@ -24,11 +24,14 @@ __export(createThrottleController_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(createThrottleController_exports);
26
26
 
27
- // src/assertions.ts
27
+ // src/typeGuards.ts
28
28
  function isFunction(value) {
29
29
  return typeof value === "function";
30
30
  }
31
31
 
32
+ // src/assertions.ts
33
+ var isFunction2 = isFunction;
34
+
32
35
  // src/enhancedMap.ts
33
36
  var enhancedMapReject = Symbol();
34
37
  var EnhancedMap = class _EnhancedMap extends Map {
@@ -103,7 +106,7 @@ var EnhancedMap = class _EnhancedMap extends Map {
103
106
  static from(array, mapFunction) {
104
107
  const map = new _EnhancedMap();
105
108
  if (!array) return map;
106
- const isFn = isFunction(mapFunction);
109
+ const isFn = isFunction2(mapFunction);
107
110
  for (const item of array) {
108
111
  if (isFn) {
109
112
  const result = mapFunction(item);
@@ -1,12 +1,13 @@
1
1
  import {
2
2
  EnhancedMap
3
- } from "./chunk-OHHF4CJZ.js";
3
+ } from "./chunk-GKOTKAIV.js";
4
4
  import {
5
5
  durationObjToMs
6
6
  } from "./chunk-5MNYPLZI.js";
7
7
  import "./chunk-HTCYUMDR.js";
8
8
  import "./chunk-II4R3VVX.js";
9
- import "./chunk-3XCS7FVO.js";
9
+ import "./chunk-WS4WEVHU.js";
10
+ import "./chunk-SSKW673U.js";
10
11
 
11
12
  // src/createThrottleController.ts
12
13
  function createThrottleController({
@@ -25,11 +25,14 @@ __export(enhancedMap_exports, {
25
25
  });
26
26
  module.exports = __toCommonJS(enhancedMap_exports);
27
27
 
28
- // src/assertions.ts
28
+ // src/typeGuards.ts
29
29
  function isFunction(value) {
30
30
  return typeof value === "function";
31
31
  }
32
32
 
33
+ // src/assertions.ts
34
+ var isFunction2 = isFunction;
35
+
33
36
  // src/enhancedMap.ts
34
37
  var enhancedMapReject = Symbol();
35
38
  var EnhancedMap = class _EnhancedMap extends Map {
@@ -104,7 +107,7 @@ var EnhancedMap = class _EnhancedMap extends Map {
104
107
  static from(array, mapFunction) {
105
108
  const map = new _EnhancedMap();
106
109
  if (!array) return map;
107
- const isFn = isFunction(mapFunction);
110
+ const isFn = isFunction2(mapFunction);
108
111
  for (const item of array) {
109
112
  if (isFn) {
110
113
  const result = mapFunction(item);
@@ -1,8 +1,9 @@
1
1
  import {
2
2
  EnhancedMap,
3
3
  enhancedMapReject
4
- } from "./chunk-OHHF4CJZ.js";
5
- import "./chunk-3XCS7FVO.js";
4
+ } from "./chunk-GKOTKAIV.js";
5
+ import "./chunk-WS4WEVHU.js";
6
+ import "./chunk-SSKW673U.js";
6
7
  export {
7
8
  EnhancedMap,
8
9
  enhancedMapReject
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/getCompositeKey.ts
21
+ var getCompositeKey_exports = {};
22
+ __export(getCompositeKey_exports, {
23
+ getCompositeKey: () => getCompositeKey
24
+ });
25
+ module.exports = __toCommonJS(getCompositeKey_exports);
26
+
27
+ // src/typeGuards.ts
28
+ function isObject(value) {
29
+ return typeof value === "object" && value !== null && !Array.isArray(value);
30
+ }
31
+
32
+ // src/assertions.ts
33
+ var isObject2 = isObject;
34
+
35
+ // src/getCompositeKey.ts
36
+ function getCompositeKey(input, maxSortingDepth = 3) {
37
+ if (typeof input === "string") return `"${input}`;
38
+ if (!input || typeof input !== "object") return `$${input}`;
39
+ return stringifyCompact(input, maxSortingDepth, 0, /* @__PURE__ */ new WeakSet());
40
+ }
41
+ function stringifyCompact(input, maxSortingDepth, depth, refs) {
42
+ const isJsObj = input && typeof input === "object";
43
+ if (isJsObj) {
44
+ if (refs.has(input)) {
45
+ throw new Error("Circular reference detected");
46
+ }
47
+ refs.add(input);
48
+ }
49
+ let result;
50
+ if (Array.isArray(input)) {
51
+ result = "[";
52
+ for (const v of input) {
53
+ if (result.length > 1) result += ",";
54
+ result += stringifyCompact(v, maxSortingDepth, depth + 1, refs);
55
+ }
56
+ result += "]";
57
+ } else if (isObject2(input)) {
58
+ let entries = Object.entries(input);
59
+ if (entries.length === 0) {
60
+ result = "{}";
61
+ } else {
62
+ if (depth < maxSortingDepth) {
63
+ entries = entries.sort(
64
+ ([a], [b]) => a < b ? -1 : a > b ? 1 : 0
65
+ );
66
+ }
67
+ result = "{";
68
+ for (const [k, v] of entries) {
69
+ if (v === void 0) continue;
70
+ if (result.length > 1) result += ",";
71
+ result += `${k}:${stringifyCompact(v, maxSortingDepth, depth + 1, refs)}`;
72
+ }
73
+ result += "}";
74
+ }
75
+ } else {
76
+ result = JSON.stringify(input);
77
+ }
78
+ if (isJsObj) {
79
+ refs.delete(input);
80
+ }
81
+ return result;
82
+ }
83
+ // Annotate the CommonJS export names for ESM import in node:
84
+ 0 && (module.exports = {
85
+ getCompositeKey
86
+ });
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Returns a stable key for the input value.
3
+ *
4
+ * @param input - The value to get a stable key for.
5
+ * @param maxSortingDepth - The maximum depth to sort the input value. Default is 3.
6
+ * @returns A stable key for the input value.
7
+ */
8
+ declare function getCompositeKey(input: unknown, maxSortingDepth?: number): string;
9
+
10
+ export { getCompositeKey };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Returns a stable key for the input value.
3
+ *
4
+ * @param input - The value to get a stable key for.
5
+ * @param maxSortingDepth - The maximum depth to sort the input value. Default is 3.
6
+ * @returns A stable key for the input value.
7
+ */
8
+ declare function getCompositeKey(input: unknown, maxSortingDepth?: number): string;
9
+
10
+ export { getCompositeKey };
@@ -0,0 +1,8 @@
1
+ import {
2
+ getCompositeKey
3
+ } from "./chunk-NH2LCAQS.js";
4
+ import "./chunk-WS4WEVHU.js";
5
+ import "./chunk-SSKW673U.js";
6
+ export {
7
+ getCompositeKey
8
+ };
@@ -24,13 +24,16 @@ __export(getValueStableKey_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(getValueStableKey_exports);
26
26
 
27
- // src/assertions.ts
27
+ // src/typeGuards.ts
28
28
  function isObject(value) {
29
29
  return typeof value === "object" && value !== null && !Array.isArray(value);
30
30
  }
31
31
 
32
- // src/getValueStableKey.ts
33
- function getValueStableKey(input, maxSortingDepth = 3) {
32
+ // src/assertions.ts
33
+ var isObject2 = isObject;
34
+
35
+ // src/getCompositeKey.ts
36
+ function getCompositeKey(input, maxSortingDepth = 3) {
34
37
  if (typeof input === "string") return `"${input}`;
35
38
  if (!input || typeof input !== "object") return `$${input}`;
36
39
  return stringifyCompact(input, maxSortingDepth, 0, /* @__PURE__ */ new WeakSet());
@@ -51,7 +54,7 @@ function stringifyCompact(input, maxSortingDepth, depth, refs) {
51
54
  result += stringifyCompact(v, maxSortingDepth, depth + 1, refs);
52
55
  }
53
56
  result += "]";
54
- } else if (isObject(input)) {
57
+ } else if (isObject2(input)) {
55
58
  let entries = Object.entries(input);
56
59
  if (entries.length === 0) {
57
60
  result = "{}";
@@ -77,6 +80,9 @@ function stringifyCompact(input, maxSortingDepth, depth, refs) {
77
80
  }
78
81
  return result;
79
82
  }
83
+
84
+ // src/getValueStableKey.ts
85
+ var getValueStableKey = getCompositeKey;
80
86
  // Annotate the CommonJS export names for ESM import in node:
81
87
  0 && (module.exports = {
82
88
  getValueStableKey
@@ -1,10 +1,14 @@
1
+ import { getCompositeKey } from './getCompositeKey.cjs';
2
+
1
3
  /**
2
4
  * Returns a stable key for the input value.
3
5
  *
4
6
  * @param input - The value to get a stable key for.
5
7
  * @param maxSortingDepth - The maximum depth to sort the input value. Default is 3.
6
8
  * @returns A stable key for the input value.
9
+ *
10
+ * @deprecated Use `getCompositeKey` from `@ls-stack/utils/getCompositeKey` instead.
7
11
  */
8
- declare function getValueStableKey(input: unknown, maxSortingDepth?: number): string;
12
+ declare const getValueStableKey: typeof getCompositeKey;
9
13
 
10
14
  export { getValueStableKey };
@@ -1,10 +1,14 @@
1
+ import { getCompositeKey } from './getCompositeKey.js';
2
+
1
3
  /**
2
4
  * Returns a stable key for the input value.
3
5
  *
4
6
  * @param input - The value to get a stable key for.
5
7
  * @param maxSortingDepth - The maximum depth to sort the input value. Default is 3.
6
8
  * @returns A stable key for the input value.
9
+ *
10
+ * @deprecated Use `getCompositeKey` from `@ls-stack/utils/getCompositeKey` instead.
7
11
  */
8
- declare function getValueStableKey(input: unknown, maxSortingDepth?: number): string;
12
+ declare const getValueStableKey: typeof getCompositeKey;
9
13
 
10
14
  export { getValueStableKey };
@@ -1,55 +1,11 @@
1
1
  import {
2
- isObject
3
- } from "./chunk-3XCS7FVO.js";
2
+ getCompositeKey
3
+ } from "./chunk-NH2LCAQS.js";
4
+ import "./chunk-WS4WEVHU.js";
5
+ import "./chunk-SSKW673U.js";
4
6
 
5
7
  // src/getValueStableKey.ts
6
- function getValueStableKey(input, maxSortingDepth = 3) {
7
- if (typeof input === "string") return `"${input}`;
8
- if (!input || typeof input !== "object") return `$${input}`;
9
- return stringifyCompact(input, maxSortingDepth, 0, /* @__PURE__ */ new WeakSet());
10
- }
11
- function stringifyCompact(input, maxSortingDepth, depth, refs) {
12
- const isJsObj = input && typeof input === "object";
13
- if (isJsObj) {
14
- if (refs.has(input)) {
15
- throw new Error("Circular reference detected");
16
- }
17
- refs.add(input);
18
- }
19
- let result;
20
- if (Array.isArray(input)) {
21
- result = "[";
22
- for (const v of input) {
23
- if (result.length > 1) result += ",";
24
- result += stringifyCompact(v, maxSortingDepth, depth + 1, refs);
25
- }
26
- result += "]";
27
- } else if (isObject(input)) {
28
- let entries = Object.entries(input);
29
- if (entries.length === 0) {
30
- result = "{}";
31
- } else {
32
- if (depth < maxSortingDepth) {
33
- entries = entries.sort(
34
- ([a], [b]) => a < b ? -1 : a > b ? 1 : 0
35
- );
36
- }
37
- result = "{";
38
- for (const [k, v] of entries) {
39
- if (v === void 0) continue;
40
- if (result.length > 1) result += ",";
41
- result += `${k}:${stringifyCompact(v, maxSortingDepth, depth + 1, refs)}`;
42
- }
43
- result += "}";
44
- }
45
- } else {
46
- result = JSON.stringify(input);
47
- }
48
- if (isJsObj) {
49
- refs.delete(input);
50
- }
51
- return result;
52
- }
8
+ var getValueStableKey = getCompositeKey;
53
9
  export {
54
10
  getValueStableKey
55
11
  };
@@ -26,9 +26,9 @@ __export(interpolate_exports, {
26
26
  module.exports = __toCommonJS(interpolate_exports);
27
27
 
28
28
  // src/assertions.ts
29
- function invariant(condition, errorMsg = "Invariant violation") {
29
+ function invariant(condition, error = "Invariant violation") {
30
30
  if (!condition) {
31
- throw new Error(`Invariant violation: ${errorMsg}`);
31
+ throw typeof error === "function" ? error() : new Error(`Invariant violation: ${error}`);
32
32
  }
33
33
  }
34
34
 
@@ -5,7 +5,8 @@ import {
5
5
  } from "./chunk-HTCYUMDR.js";
6
6
  import {
7
7
  invariant
8
- } from "./chunk-3XCS7FVO.js";
8
+ } from "./chunk-WS4WEVHU.js";
9
+ import "./chunk-SSKW673U.js";
9
10
 
10
11
  // src/interpolate.ts
11
12
  function mod(n, m) {
@@ -1,3 +1,4 @@
1
+ /** @deprecated use typedObjectEntries from @ls-stack/utils/typingFnUtils instead */
1
2
  declare function objectTypedEntries<T extends Record<string, unknown>>(obj: T): [Extract<keyof T, string>, T[keyof T]][];
2
3
  declare function pick<T, K extends keyof T>(obj: T | undefined, keys: K[], rename?: Partial<Record<K, string>>): Record<string, unknown>;
3
4
  declare function mapArrayToObject<T, K extends string, O>(array: T[], mapper: (item: T, index: number) => [K, O]): Record<K, O>;
package/lib/objUtils.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /** @deprecated use typedObjectEntries from @ls-stack/utils/typingFnUtils instead */
1
2
  declare function objectTypedEntries<T extends Record<string, unknown>>(obj: T): [Extract<keyof T, string>, T[keyof T]][];
2
3
  declare function pick<T, K extends keyof T>(obj: T | undefined, keys: K[], rename?: Partial<Record<K, string>>): Record<string, unknown>;
3
4
  declare function mapArrayToObject<T, K extends string, O>(array: T[], mapper: (item: T, index: number) => [K, O]): Record<K, O>;
@@ -25,15 +25,18 @@ __export(parallelAsyncCalls_exports, {
25
25
  module.exports = __toCommonJS(parallelAsyncCalls_exports);
26
26
  var import_t_result = require("t-result");
27
27
 
28
+ // src/typeGuards.ts
29
+ function isObject(value) {
30
+ return typeof value === "object" && value !== null && !Array.isArray(value);
31
+ }
32
+
28
33
  // src/assertions.ts
29
- function invariant(condition, errorMsg = "Invariant violation") {
34
+ function invariant(condition, error = "Invariant violation") {
30
35
  if (!condition) {
31
- throw new Error(`Invariant violation: ${errorMsg}`);
36
+ throw typeof error === "function" ? error() : new Error(`Invariant violation: ${error}`);
32
37
  }
33
38
  }
34
- function isObject(value) {
35
- return typeof value === "object" && value !== null && !Array.isArray(value);
36
- }
39
+ var isObject2 = isObject;
37
40
 
38
41
  // src/sleep.ts
39
42
  function sleep(ms) {
@@ -48,7 +51,7 @@ var ParallelAsyncResultCalls = class {
48
51
  }
49
52
  add(call) {
50
53
  this.pendingCalls.push(
51
- isObject(call) ? call : { metadata: void 0, fn: call }
54
+ isObject2(call) ? call : { metadata: void 0, fn: call }
52
55
  );
53
56
  return this;
54
57
  }
@@ -56,7 +59,7 @@ var ParallelAsyncResultCalls = class {
56
59
  addTuple(...calls) {
57
60
  for (const call of calls) {
58
61
  this.pendingCalls.push(
59
- isObject(call) ? call : { metadata: void 0, fn: call }
62
+ isObject2(call) ? call : { metadata: void 0, fn: call }
60
63
  );
61
64
  }
62
65
  return {