@lowdefy/helpers 4.5.2 → 4.7.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,9 +12,36 @@
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';
17
- const makeReplacer = (customReplacer, isoStringDates)=>(key, value)=>{
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
+ }
44
+ const makeReplacer = (customReplacer, isoStringDates, skipMarkers)=>(key, value)=>{
18
45
  let dateReplacer = (date)=>({
19
46
  '~d': date.valueOf()
20
47
  });
@@ -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)) {
@@ -46,62 +69,131 @@ const makeReplacer = (customReplacer, isoStringDates)=>(key, value)=>{
46
69
  newValue[k] = dateReplacer(newValue[k]);
47
70
  }
48
71
  });
49
- if (newValue['~r']) {
50
- Object.defineProperty(newValue, '~r', {
51
- value: newValue['~r'],
52
- enumerable: true,
53
- writable: true,
54
- configurable: true
55
- });
56
- }
57
- if (newValue['~k']) {
58
- Object.defineProperty(newValue, '~k', {
59
- value: newValue['~k'],
60
- enumerable: true,
61
- writable: true,
62
- configurable: true
63
- });
72
+ if (!skipMarkers) {
73
+ // Capture marker values before shallow copy (spread doesn't copy non-enumerable props)
74
+ const markerR = newValue['~r'];
75
+ const markerK = newValue['~k'];
76
+ const markerL = newValue['~l'];
77
+ if (markerR || markerK || markerL) {
78
+ // Shallow copy to avoid mutating the original object's property descriptors
79
+ if (newValue === value) {
80
+ newValue = {
81
+ ...newValue
82
+ };
83
+ }
84
+ if (markerR) {
85
+ Object.defineProperty(newValue, '~r', {
86
+ value: markerR,
87
+ enumerable: true,
88
+ writable: true,
89
+ configurable: true
90
+ });
91
+ }
92
+ if (markerK) {
93
+ Object.defineProperty(newValue, '~k', {
94
+ value: markerK,
95
+ enumerable: true,
96
+ writable: true,
97
+ configurable: true
98
+ });
99
+ }
100
+ if (markerL) {
101
+ Object.defineProperty(newValue, '~l', {
102
+ value: markerL,
103
+ enumerable: true,
104
+ writable: true,
105
+ configurable: true
106
+ });
107
+ }
108
+ }
64
109
  }
65
110
  return newValue;
66
111
  }
67
112
  if (type.isArray(newValue)) {
68
- return newValue.map((item)=>{
113
+ const mappedArray = newValue.map((item)=>{
69
114
  if (type.isDate(item)) {
70
115
  return dateReplacer(item);
71
116
  }
72
117
  return item;
73
118
  });
119
+ // Preserve ~l, ~k, ~r on arrays by wrapping in a marker object
120
+ if (!skipMarkers && (newValue['~l'] !== undefined || newValue['~k'] !== undefined || newValue['~r'] !== undefined)) {
121
+ const wrapper = {
122
+ '~arr': mappedArray
123
+ };
124
+ if (newValue['~r'] !== undefined) wrapper['~r'] = newValue['~r'];
125
+ if (newValue['~k'] !== undefined) wrapper['~k'] = newValue['~k'];
126
+ if (newValue['~l'] !== undefined) wrapper['~l'] = newValue['~l'];
127
+ return wrapper;
128
+ }
129
+ return mappedArray;
74
130
  }
75
131
  return newValue;
76
132
  };
77
133
  const makeReviver = (customReviver)=>(key, value)=>{
78
134
  let newValue = value;
79
135
  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
- });
136
+ // Restore arrays that were wrapped with ~arr marker
137
+ if (type.isArray(newValue['~arr'])) {
138
+ const arr = newValue['~arr'];
139
+ if (newValue['~r']) {
140
+ Object.defineProperty(arr, '~r', {
141
+ value: newValue['~r'],
142
+ enumerable: false,
143
+ writable: true,
144
+ configurable: true
145
+ });
146
+ }
147
+ if (newValue['~k']) {
148
+ Object.defineProperty(arr, '~k', {
149
+ value: newValue['~k'],
150
+ enumerable: false,
151
+ writable: true,
152
+ configurable: true
153
+ });
154
+ }
155
+ if (newValue['~l']) {
156
+ Object.defineProperty(arr, '~l', {
157
+ value: newValue['~l'],
158
+ enumerable: false,
159
+ writable: true,
160
+ configurable: true
161
+ });
162
+ }
163
+ newValue = arr;
164
+ } else {
165
+ if (newValue['~r']) {
166
+ Object.defineProperty(newValue, '~r', {
167
+ value: newValue['~r'],
168
+ enumerable: false,
169
+ writable: true,
170
+ configurable: true
171
+ });
172
+ }
173
+ if (newValue['~k']) {
174
+ Object.defineProperty(newValue, '~k', {
175
+ value: newValue['~k'],
176
+ enumerable: false,
177
+ writable: true,
178
+ configurable: true
179
+ });
180
+ }
181
+ if (newValue['~l']) {
182
+ Object.defineProperty(newValue, '~l', {
183
+ value: newValue['~l'],
184
+ enumerable: false,
185
+ writable: true,
186
+ configurable: true
187
+ });
188
+ }
95
189
  }
96
190
  }
97
191
  if (customReviver) {
98
- newValue = customReviver(key, value);
192
+ newValue = customReviver(key, newValue);
99
193
  }
100
194
  if (type.isObject(newValue)) {
101
195
  if (!type.isUndefined(newValue['~e'])) {
102
- const error = new Error(newValue['~e'].message);
103
- error.name = newValue['~e'].name;
104
- return error;
196
+ return propsToError(newValue['~e']);
105
197
  }
106
198
  if (!type.isUndefined(newValue['~d'])) {
107
199
  const result = new Date(newValue['~d']);
@@ -137,11 +229,11 @@ const serializeToString = (json, options = {})=>{
137
229
  }
138
230
  if (options.stable) {
139
231
  return stableStringify(json, {
140
- replacer: makeReplacer(options.replacer),
232
+ replacer: makeReplacer(options.replacer, undefined, options.skipMarkers),
141
233
  space: options.space
142
234
  });
143
235
  }
144
- return JSON.stringify(json, makeReplacer(options.replacer, options.isoStringDates), options.space);
236
+ return JSON.stringify(json, makeReplacer(options.replacer, options.isoStringDates, options.skipMarkers), options.space);
145
237
  };
146
238
  const deserialize = (json, options = {})=>{
147
239
  if (type.isUndefined(json)) return json;
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.7.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.7.0",
34
35
  "lodash.merge": "4.6.2"
35
36
  },
36
37
  "devDependencies": {