@lowdefy/helpers 4.5.2 → 4.6.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.
package/dist/LRUCache.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2024 Lowdefy, Inc
2
+ Copyright 2020-2026 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2024 Lowdefy, Inc
2
+ Copyright 2020-2026 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2024 Lowdefy, Inc
2
+ Copyright 2020-2026 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -0,0 +1,56 @@
1
+ /*
2
+ Copyright 2020-2026 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ function isPlainObject(val) {
16
+ const proto = Object.getPrototypeOf(val);
17
+ return proto === Object.prototype || proto === null;
18
+ }
19
+ const MAX_CAUSE_DEPTH = 3;
20
+ function _extractErrorProps(err, seen, depth) {
21
+ if (!err) return err;
22
+ seen.add(err);
23
+ const props = {
24
+ message: err.message,
25
+ name: err.name,
26
+ stack: err.stack
27
+ };
28
+ 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);
31
+ } else if (!(err.cause instanceof Error)) {
32
+ props.cause = err.cause;
33
+ }
34
+ }
35
+ for (const key of Object.keys(err)){
36
+ if (key === 'cause') continue;
37
+ const value = err[key];
38
+ if (value === null || typeof value !== 'object') {
39
+ props[key] = value;
40
+ } else if (Array.isArray(value) || value instanceof Date) {
41
+ props[key] = value;
42
+ } else if (value instanceof Error) {
43
+ if (!seen.has(value)) {
44
+ props[key] = _extractErrorProps(value, seen, depth);
45
+ }
46
+ } else if (isPlainObject(value)) {
47
+ props[key] = value;
48
+ }
49
+ // Skip class instances (Socket, Agent, ClientRequest, etc.)
50
+ }
51
+ return props;
52
+ }
53
+ function extractErrorProps(err) {
54
+ return _extractErrorProps(err, new Set(), 0);
55
+ }
56
+ export default extractErrorProps;
package/dist/get.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable no-param-reassign */ /*
2
- Copyright 2020-2024 Lowdefy, Inc
2
+ Copyright 2020-2026 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2024 Lowdefy, Inc
2
+ Copyright 2020-2026 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -14,6 +14,7 @@
14
14
  limitations under the License.
15
15
  */ import applyArrayIndices from './applyArrayIndices.js';
16
16
  import cachedPromises from './cachedPromises.js';
17
+ import extractErrorProps from './extractErrorProps.js';
17
18
  import get from './get.js';
18
19
  import LRUCache from './LRUCache.js';
19
20
  import mergeObjects from './mergeObjects.js';
@@ -26,4 +27,4 @@ import type from './type.js';
26
27
  import unset from './unset.js';
27
28
  import urlQuery from './urlQuery.js';
28
29
  import wait from './wait.js';
29
- export { applyArrayIndices, cachedPromises, get, LRUCache, mergeObjects, omit, serializer, set, stableStringify, swap, type, unset, urlQuery, wait };
30
+ export { applyArrayIndices, cachedPromises, extractErrorProps, get, LRUCache, mergeObjects, omit, serializer, set, stableStringify, swap, type, unset, urlQuery, wait };
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2024 Lowdefy, Inc
2
+ Copyright 2020-2026 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
package/dist/omit.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2024 Lowdefy, Inc
2
+ Copyright 2020-2026 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable no-param-reassign */ /*
2
- Copyright 2020-2024 Lowdefy, Inc
2
+ Copyright 2020-2026 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -12,8 +12,35 @@
12
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
- */ import type from './type.js';
15
+ */ import { ActionError, BlockError, BuildError, ConfigError, ConfigWarning, LowdefyInternalError, OperatorError, PluginError, RequestError, ServiceError, UserError } from '@lowdefy/errors';
16
+ import extractErrorProps from './extractErrorProps.js';
17
+ import type from './type.js';
16
18
  import stableStringify from './stableStringify.js';
19
+ const lowdefyErrorTypes = {
20
+ ActionError,
21
+ BlockError,
22
+ BuildError,
23
+ ConfigError,
24
+ ConfigWarning,
25
+ LowdefyInternalError,
26
+ OperatorError,
27
+ PluginError,
28
+ RequestError,
29
+ ServiceError,
30
+ UserError
31
+ };
32
+ function propsToError(data) {
33
+ const ErrorClass = lowdefyErrorTypes[data.name] || Error;
34
+ const error = Object.create(ErrorClass.prototype);
35
+ for (const [k, v] of Object.entries(data)){
36
+ if (k === 'cause' && v !== null && typeof v === 'object' && v.message !== undefined) {
37
+ error[k] = propsToError(v);
38
+ } else {
39
+ error[k] = v;
40
+ }
41
+ }
42
+ return error;
43
+ }
17
44
  const makeReplacer = (customReplacer, isoStringDates)=>(key, value)=>{
18
45
  let dateReplacer = (date)=>({
19
46
  '~d': date.valueOf()
@@ -29,11 +56,7 @@ const makeReplacer = (customReplacer, isoStringDates)=>(key, value)=>{
29
56
  }
30
57
  if (type.isError(newValue)) {
31
58
  return {
32
- '~e': {
33
- name: newValue.name,
34
- message: newValue.message,
35
- value: newValue.toString()
36
- }
59
+ '~e': extractErrorProps(newValue)
37
60
  };
38
61
  }
39
62
  if (type.isObject(newValue)) {
@@ -62,46 +85,101 @@ const makeReplacer = (customReplacer, isoStringDates)=>(key, value)=>{
62
85
  configurable: true
63
86
  });
64
87
  }
88
+ if (newValue['~l']) {
89
+ Object.defineProperty(newValue, '~l', {
90
+ value: newValue['~l'],
91
+ enumerable: true,
92
+ writable: true,
93
+ configurable: true
94
+ });
95
+ }
65
96
  return newValue;
66
97
  }
67
98
  if (type.isArray(newValue)) {
68
- return newValue.map((item)=>{
99
+ const mappedArray = newValue.map((item)=>{
69
100
  if (type.isDate(item)) {
70
101
  return dateReplacer(item);
71
102
  }
72
103
  return item;
73
104
  });
105
+ // Preserve ~l, ~k, ~r on arrays by wrapping in a marker object
106
+ if (newValue['~l'] !== undefined || newValue['~k'] !== undefined || newValue['~r'] !== undefined) {
107
+ const wrapper = {
108
+ '~arr': mappedArray
109
+ };
110
+ if (newValue['~r'] !== undefined) wrapper['~r'] = newValue['~r'];
111
+ if (newValue['~k'] !== undefined) wrapper['~k'] = newValue['~k'];
112
+ if (newValue['~l'] !== undefined) wrapper['~l'] = newValue['~l'];
113
+ return wrapper;
114
+ }
115
+ return mappedArray;
74
116
  }
75
117
  return newValue;
76
118
  };
77
119
  const makeReviver = (customReviver)=>(key, value)=>{
78
120
  let newValue = value;
79
121
  if (type.isObject(newValue)) {
80
- if (newValue['~r']) {
81
- Object.defineProperty(newValue, '~r', {
82
- value: newValue['~r'],
83
- enumerable: false,
84
- writable: true,
85
- configurable: true
86
- });
87
- }
88
- if (newValue['~k']) {
89
- Object.defineProperty(newValue, '~k', {
90
- value: newValue['~k'],
91
- enumerable: false,
92
- writable: true,
93
- configurable: true
94
- });
122
+ // Restore arrays that were wrapped with ~arr marker
123
+ if (type.isArray(newValue['~arr'])) {
124
+ const arr = newValue['~arr'];
125
+ if (newValue['~r']) {
126
+ Object.defineProperty(arr, '~r', {
127
+ value: newValue['~r'],
128
+ enumerable: false,
129
+ writable: true,
130
+ configurable: true
131
+ });
132
+ }
133
+ if (newValue['~k']) {
134
+ Object.defineProperty(arr, '~k', {
135
+ value: newValue['~k'],
136
+ enumerable: false,
137
+ writable: true,
138
+ configurable: true
139
+ });
140
+ }
141
+ if (newValue['~l']) {
142
+ Object.defineProperty(arr, '~l', {
143
+ value: newValue['~l'],
144
+ enumerable: false,
145
+ writable: true,
146
+ configurable: true
147
+ });
148
+ }
149
+ newValue = arr;
150
+ } else {
151
+ if (newValue['~r']) {
152
+ Object.defineProperty(newValue, '~r', {
153
+ value: newValue['~r'],
154
+ enumerable: false,
155
+ writable: true,
156
+ configurable: true
157
+ });
158
+ }
159
+ if (newValue['~k']) {
160
+ Object.defineProperty(newValue, '~k', {
161
+ value: newValue['~k'],
162
+ enumerable: false,
163
+ writable: true,
164
+ configurable: true
165
+ });
166
+ }
167
+ if (newValue['~l']) {
168
+ Object.defineProperty(newValue, '~l', {
169
+ value: newValue['~l'],
170
+ enumerable: false,
171
+ writable: true,
172
+ configurable: true
173
+ });
174
+ }
95
175
  }
96
176
  }
97
177
  if (customReviver) {
98
- newValue = customReviver(key, value);
178
+ newValue = customReviver(key, newValue);
99
179
  }
100
180
  if (type.isObject(newValue)) {
101
181
  if (!type.isUndefined(newValue['~e'])) {
102
- const error = new Error(newValue['~e'].message);
103
- error.name = newValue['~e'].name;
104
- return error;
182
+ return propsToError(newValue['~e']);
105
183
  }
106
184
  if (!type.isUndefined(newValue['~d'])) {
107
185
  const result = new Date(newValue['~d']);
package/dist/set.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable no-plusplus */ /* eslint-disable no-use-before-define */ /* eslint-disable no-param-reassign */ /*
2
- Copyright 2020-2024 Lowdefy, Inc
2
+ Copyright 2020-2026 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable no-continue */ /* eslint-disable no-plusplus */ /* eslint-disable consistent-return */ /* eslint-disable no-param-reassign */ /*
2
- Copyright 2020-2024 Lowdefy, Inc
2
+ Copyright 2020-2026 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
package/dist/swap.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2024 Lowdefy, Inc
2
+ Copyright 2020-2026 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
package/dist/type.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable indent */ /* eslint-disable default-case */ /*
2
- Copyright 2020-2024 Lowdefy, Inc
2
+ Copyright 2020-2026 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
package/dist/unset.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable no-param-reassign */ /*
2
- Copyright 2020-2024 Lowdefy, Inc
2
+ Copyright 2020-2026 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
package/dist/urlQuery.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2024 Lowdefy, Inc
2
+ Copyright 2020-2026 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
package/dist/wait.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2024 Lowdefy, Inc
2
+ Copyright 2020-2026 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/helpers",
3
- "version": "4.5.2",
3
+ "version": "4.6.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -31,6 +31,7 @@
31
31
  "dist/*"
32
32
  ],
33
33
  "dependencies": {
34
+ "@lowdefy/errors": "4.6.0",
34
35
  "lodash.merge": "4.6.2"
35
36
  },
36
37
  "devDependencies": {