@lowdefy/helpers 4.7.2 → 5.0.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.
@@ -17,7 +17,26 @@
17
17
  return proto === Object.prototype || proto === null;
18
18
  }
19
19
  const MAX_CAUSE_DEPTH = 3;
20
- function _extractErrorProps(err, seen, depth) {
20
+ const MAX_OBJECT_DEPTH = 5;
21
+ function cleanValue(val, seen, objectDepth, causeDepth) {
22
+ if (objectDepth > MAX_OBJECT_DEPTH) return '[Truncated]';
23
+ if (val === null || typeof val !== 'object') return val;
24
+ if (seen.has(val)) return '[Circular]';
25
+ seen.add(val);
26
+ if (Array.isArray(val)) {
27
+ return val.map((item)=>cleanValue(item, seen, objectDepth + 1, causeDepth));
28
+ }
29
+ if (val instanceof Date) return val;
30
+ if (val instanceof Error) return _extractErrorProps(val, seen, objectDepth, causeDepth);
31
+ if (!isPlainObject(val)) return `[Object: ${val.constructor?.name ?? 'unknown'}]`;
32
+ const cleaned = {};
33
+ for (const [k, v] of Object.entries(val)){
34
+ const cv = cleanValue(v, seen, objectDepth + 1, causeDepth);
35
+ if (cv !== undefined) cleaned[k] = cv;
36
+ }
37
+ return cleaned;
38
+ }
39
+ function _extractErrorProps(err, seen, objectDepth, causeDepth) {
21
40
  if (!err) return err;
22
41
  seen.add(err);
23
42
  const props = {
@@ -26,10 +45,10 @@ function _extractErrorProps(err, seen, depth) {
26
45
  stack: err.stack
27
46
  };
28
47
  if (err.cause !== undefined) {
29
- if (err.cause instanceof Error && !seen.has(err.cause) && depth < MAX_CAUSE_DEPTH) {
30
- props.cause = _extractErrorProps(err.cause, seen, depth + 1);
48
+ if (err.cause instanceof Error && !seen.has(err.cause) && causeDepth < MAX_CAUSE_DEPTH) {
49
+ props.cause = _extractErrorProps(err.cause, seen, objectDepth, causeDepth + 1);
31
50
  } else if (!(err.cause instanceof Error)) {
32
- props.cause = err.cause;
51
+ props.cause = cleanValue(err.cause, seen, objectDepth + 1, causeDepth);
33
52
  }
34
53
  }
35
54
  for (const key of Object.keys(err)){
@@ -37,20 +56,22 @@ function _extractErrorProps(err, seen, depth) {
37
56
  const value = err[key];
38
57
  if (value === null || typeof value !== 'object') {
39
58
  props[key] = value;
40
- } else if (Array.isArray(value) || value instanceof Date) {
59
+ } else if (value instanceof Date) {
41
60
  props[key] = value;
61
+ } else if (Array.isArray(value)) {
62
+ props[key] = cleanValue(value, seen, objectDepth + 1, causeDepth);
42
63
  } else if (value instanceof Error) {
43
64
  if (!seen.has(value)) {
44
- props[key] = _extractErrorProps(value, seen, depth);
65
+ props[key] = _extractErrorProps(value, seen, objectDepth, causeDepth);
45
66
  }
46
67
  } else if (isPlainObject(value)) {
47
- props[key] = value;
68
+ props[key] = cleanValue(value, seen, objectDepth + 1, causeDepth);
48
69
  }
49
70
  // Skip class instances (Socket, Agent, ClientRequest, etc.)
50
71
  }
51
72
  return props;
52
73
  }
53
74
  function extractErrorProps(err) {
54
- return _extractErrorProps(err, new Set(), 0);
75
+ return _extractErrorProps(err, new Set(), 0, 0);
55
76
  }
56
77
  export default extractErrorProps;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/helpers",
3
- "version": "4.7.2",
3
+ "version": "5.0.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -31,14 +31,14 @@
31
31
  "dist/*"
32
32
  ],
33
33
  "dependencies": {
34
- "@lowdefy/errors": "4.7.2",
34
+ "@lowdefy/errors": "5.0.0",
35
35
  "lodash.merge": "4.6.2"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@jest/globals": "28.1.3",
39
- "@swc/cli": "0.1.63",
40
- "@swc/core": "1.3.99",
41
- "@swc/jest": "0.2.29",
39
+ "@swc/cli": "0.8.0",
40
+ "@swc/core": "1.15.18",
41
+ "@swc/jest": "0.2.39",
42
42
  "jest": "28.1.3",
43
43
  "jest-diff": "28.1.3"
44
44
  },
@@ -46,7 +46,7 @@
46
46
  "access": "public"
47
47
  },
48
48
  "scripts": {
49
- "build": "swc src --out-dir dist --config-file ../../../.swcrc --delete-dir-on-start",
49
+ "build": "swc src --out-dir dist --config-file ../../../.swcrc --cli-config-file ../../../.swc-cli.json",
50
50
  "clean": "rm -rf dist",
51
51
  "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
52
52
  }