@likec4/log 1.46.0 → 1.48.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.
@@ -0,0 +1,746 @@
1
+ import { t as main_default$7 } from "./is-error-instance.mjs";
2
+ import { t as isPlainObject } from "./is-plain-obj.mjs";
3
+
4
+ //#region ../../node_modules/.pnpm/normalize-exception@4.0.1/node_modules/normalize-exception/build/src/descriptors.js
5
+ const normalizeDescriptors = (error) => {
6
+ CORE_ERROR_PROPS.forEach((propName) => {
7
+ normalizeDescriptor$1(error, propName);
8
+ });
9
+ };
10
+ const CORE_ERROR_PROPS = [
11
+ "name",
12
+ "message",
13
+ "stack",
14
+ "cause",
15
+ "errors"
16
+ ];
17
+ const normalizeDescriptor$1 = (error, propName) => {
18
+ const descriptor = getDescriptor(error, propName);
19
+ if (descriptor === void 0) return;
20
+ if (isReadonlyGetter(descriptor)) {
21
+ setErrorProperty$1(error, propName, error[propName]);
22
+ return;
23
+ }
24
+ if (isInvalidDescriptor(descriptor)) setErrorDescriptor(error, propName, descriptor);
25
+ };
26
+ const getDescriptor = (value, propName) => {
27
+ const descriptor = Object.getOwnPropertyDescriptor(value, propName);
28
+ if (descriptor !== void 0) return descriptor;
29
+ const prototype = Object.getPrototypeOf(value);
30
+ return prototype === null ? void 0 : getDescriptor(prototype, propName);
31
+ };
32
+ const isReadonlyGetter = ({ get, set }) => get !== void 0 && set === void 0;
33
+ const isInvalidDescriptor = ({ enumerable, writable }) => enumerable || !writable;
34
+ const setErrorProperty$1 = (error, propName, value) => {
35
+ setErrorDescriptor(error, propName, { value });
36
+ };
37
+ const setErrorDescriptor = (error, propName, descriptor) => {
38
+ Object.defineProperty(error, propName, {
39
+ ...descriptor,
40
+ ..."get" in descriptor || "set" in descriptor ? {} : { writable: true },
41
+ enumerable: false,
42
+ configurable: true
43
+ });
44
+ };
45
+
46
+ //#endregion
47
+ //#region ../../node_modules/.pnpm/normalize-exception@4.0.1/node_modules/normalize-exception/build/src/aggregate.js
48
+ const normalizeAggregate = (error, recurse) => {
49
+ if (Array.isArray(error.errors)) setErrorProperty$1(error, "errors", error.errors.filter(isDefined).map(recurse).filter(Boolean));
50
+ else if (isAggregateError(error)) setErrorProperty$1(error, "errors", []);
51
+ else if (error.errors !== void 0) deleteAggregateErrors(error);
52
+ };
53
+ const isDefined = (error) => error !== void 0;
54
+ const isAggregateError = (error) => "AggregateError" in globalThis && (error.name === "AggregateError" || error instanceof AggregateError);
55
+ const deleteAggregateErrors = (error) => {
56
+ delete error.errors;
57
+ if (error.errors !== void 0) setErrorProperty$1(error, "errors", []);
58
+ };
59
+
60
+ //#endregion
61
+ //#region ../../node_modules/.pnpm/normalize-exception@4.0.1/node_modules/normalize-exception/build/src/cause.js
62
+ const normalizeCause = (error, recurse) => {
63
+ if (!("cause" in error)) return;
64
+ const cause = error.cause === void 0 ? error.cause : recurse(error.cause);
65
+ if (cause === void 0) delete error.cause;
66
+ else setErrorProperty$1(error, "cause", cause);
67
+ };
68
+
69
+ //#endregion
70
+ //#region ../../node_modules/.pnpm/normalize-exception@4.0.1/node_modules/normalize-exception/build/src/create/modifiable.js
71
+ const isNonModifiableError = (error) => !Object.isExtensible(error) || CORE_ERROR_PROPS.some((propName) => isNonConfigurableProp(error, propName) || isThrowingProp(error, propName));
72
+ const isNonConfigurableProp = (error, propName) => {
73
+ const descriptor = Object.getOwnPropertyDescriptor(error, propName);
74
+ return descriptor !== void 0 && !descriptor.configurable;
75
+ };
76
+ const isThrowingProp = (error, propName) => {
77
+ try {
78
+ error[propName];
79
+ return false;
80
+ } catch {
81
+ return true;
82
+ }
83
+ };
84
+
85
+ //#endregion
86
+ //#region ../../node_modules/.pnpm/normalize-exception@4.0.1/node_modules/normalize-exception/build/src/stack.js
87
+ const setStack = (error) => {
88
+ setErrorProperty$1(error, "stack", getStack$3(error.message, error.name));
89
+ };
90
+ const getStack$3 = (message = "", name = "Error") => {
91
+ const { stack } = new (getErrorClass(name))(message);
92
+ return typeof stack === "string" && stack !== "" ? stack : `${name}: ${message}`;
93
+ };
94
+ const getErrorClass = (name) => {
95
+ const descriptor = {
96
+ value: name,
97
+ enumerable: false,
98
+ writable: true,
99
+ configurable: true
100
+ };
101
+ const StackError = Object.defineProperty(class extends Error {}, "name", descriptor);
102
+ Object.defineProperty(StackError.prototype, "name", descriptor);
103
+ return StackError;
104
+ };
105
+
106
+ //#endregion
107
+ //#region ../../node_modules/.pnpm/normalize-exception@4.0.1/node_modules/normalize-exception/build/src/create/copy.js
108
+ const copyObject = (object) => {
109
+ const objectCopy = {};
110
+ for (const propName of getPropsToCopy(object)) try {
111
+ const value = object[propName];
112
+ const { enumerable, configurable, writable = true } = getDescriptor(object, propName);
113
+ Object.defineProperty(objectCopy, propName, {
114
+ value,
115
+ enumerable,
116
+ configurable,
117
+ writable
118
+ });
119
+ } catch {}
120
+ return objectCopy;
121
+ };
122
+ const getPropsToCopy = (object) => {
123
+ const propNames = getOwnKeys(object);
124
+ for (const propName of CORE_ERROR_PROPS) if (isInheritedProp(object, propName)) propNames.push(propName);
125
+ return propNames;
126
+ };
127
+ const getOwnKeys = (object) => {
128
+ try {
129
+ return Reflect.ownKeys(object);
130
+ } catch {
131
+ return [];
132
+ }
133
+ };
134
+ const isInheritedProp = (object, propName) => {
135
+ try {
136
+ return propName in object && !Object.hasOwn(object, propName);
137
+ } catch {
138
+ return false;
139
+ }
140
+ };
141
+
142
+ //#endregion
143
+ //#region ../../node_modules/.pnpm/normalize-exception@4.0.1/node_modules/normalize-exception/build/src/create/object.js
144
+ const objectifyError = (object) => {
145
+ const { name, message, stack, cause, errors, ...objectA } = copyObject(object);
146
+ const messageA = getMessage$1(message, objectA);
147
+ const error = newError(name, messageA);
148
+ if (message === messageA) assignObjectProps(error, objectA);
149
+ Object.entries({
150
+ name,
151
+ stack,
152
+ cause,
153
+ errors
154
+ }).forEach(([propName, propValue]) => {
155
+ setNewErrorProperty(error, propName, propValue);
156
+ });
157
+ if (stack === void 0) setStack(error);
158
+ return error;
159
+ };
160
+ const getMessage$1 = (message, object) => typeof message === "string" && message !== "" ? message : truncateMessage(safeJsonStringify(object));
161
+ const safeJsonStringify = (object) => {
162
+ try {
163
+ return JSON.stringify(object);
164
+ } catch {
165
+ return safeStringify(object);
166
+ }
167
+ };
168
+ const safeStringify = (object) => {
169
+ try {
170
+ return String(object);
171
+ } catch {
172
+ return "Invalid error";
173
+ }
174
+ };
175
+ const truncateMessage = (message) => message.length < MESSAGE_MAX_SIZE ? message : `${message.slice(0, MESSAGE_MAX_SIZE)}...`;
176
+ const MESSAGE_MAX_SIZE = 1e3;
177
+ const newError = (name, message) => {
178
+ if (name === "AggregateError" && "AggregateError" in globalThis) return new AggregateError([], message);
179
+ if (name in NATIVE_ERRORS) return new NATIVE_ERRORS[name](message);
180
+ return new Error(message);
181
+ };
182
+ const NATIVE_ERRORS = {
183
+ Error,
184
+ ReferenceError,
185
+ TypeError,
186
+ SyntaxError,
187
+ RangeError,
188
+ URIError,
189
+ EvalError
190
+ };
191
+ const assignObjectProps = (error, object) => {
192
+ for (const propName in object) if (!(propName in error)) error[propName] = object[propName];
193
+ };
194
+ const setNewErrorProperty = (error, propName, propValue) => {
195
+ if (propValue !== void 0) setErrorProperty$1(error, propName, propValue);
196
+ };
197
+
198
+ //#endregion
199
+ //#region ../../node_modules/.pnpm/normalize-exception@4.0.1/node_modules/normalize-exception/build/src/create/string.js
200
+ const stringifyError = (value) => {
201
+ try {
202
+ const error = new Error(String(value));
203
+ setStack(error);
204
+ return error;
205
+ } catch (error_) {
206
+ return error_;
207
+ }
208
+ };
209
+
210
+ //#endregion
211
+ //#region ../../node_modules/.pnpm/normalize-exception@4.0.1/node_modules/normalize-exception/build/src/create/main.js
212
+ const { toString: objectToString } = Object.prototype;
213
+ const createError = (value) => {
214
+ if (isErrorPlainObj(value)) return objectifyError(value);
215
+ if (!main_default$7(value)) return stringifyError(value);
216
+ if (isInvalidError(value)) return objectifyError(value);
217
+ return value;
218
+ };
219
+ const isErrorPlainObj = (value) => {
220
+ try {
221
+ return isPlainObject(value);
222
+ } catch {
223
+ return false;
224
+ }
225
+ };
226
+ const isInvalidError = (value) => isProxy(value) || isNonModifiableError(value) || hasInvalidConstructor(value);
227
+ const isProxy = (value) => {
228
+ try {
229
+ return objectToString.call(value) === "[object Object]";
230
+ } catch {
231
+ return true;
232
+ }
233
+ };
234
+ const hasInvalidConstructor = (error) => typeof error.constructor !== "function" || typeof error.constructor.name !== "string" || error.constructor.name === "" || error.constructor.prototype !== Object.getPrototypeOf(error);
235
+
236
+ //#endregion
237
+ //#region ../../node_modules/.pnpm/normalize-exception@4.0.1/node_modules/normalize-exception/build/src/main.js
238
+ const normalizeException = (error, { shallow = false } = {}) => recurseException(error, [], shallow);
239
+ var main_default$6 = normalizeException;
240
+ const recurseException = (error, parents, shallow) => {
241
+ if (parents.includes(error)) return;
242
+ const recurse = shallow ? identity : (innerError) => recurseException(innerError, [...parents, error], shallow);
243
+ const errorA = createError(error);
244
+ normalizeProps(errorA, recurse);
245
+ return errorA;
246
+ };
247
+ const identity = (error) => error;
248
+ const normalizeProps = (error, recurse) => {
249
+ normalizeName(error);
250
+ normalizeMessage(error);
251
+ normalizeStack(error);
252
+ normalizeCause(error, recurse);
253
+ normalizeAggregate(error, recurse);
254
+ normalizeDescriptors(error);
255
+ };
256
+ const normalizeName = (error) => {
257
+ if (isDefinedString$1(error.name)) return;
258
+ const prototypeName = Object.getPrototypeOf(error).name;
259
+ setErrorProperty$1(error, "name", isDefinedString$1(prototypeName) ? prototypeName : error.constructor.name);
260
+ };
261
+ const normalizeMessage = (error) => {
262
+ if (!isDefinedString$1(error.message)) setErrorProperty$1(error, "message", "");
263
+ };
264
+ const normalizeStack = (error) => {
265
+ if (!isDefinedString$1(error.stack)) setStack(error);
266
+ };
267
+ const isDefinedString$1 = (value) => typeof value === "string" && value !== "";
268
+
269
+ //#endregion
270
+ //#region ../../node_modules/.pnpm/set-error-class@3.0.1/node_modules/set-error-class/build/src/args.js
271
+ const normalizeArgs$1 = (error, ErrorClass, currentName = error.name) => {
272
+ validateErrorClass(ErrorClass);
273
+ if (typeof currentName !== "string") throw new TypeError(`currentName must be a string: ${currentName}`);
274
+ return currentName;
275
+ };
276
+ const validateErrorClass = (ErrorClass) => {
277
+ if (!isClass(ErrorClass)) throw new TypeError(`ErrorClass must be a class: ${ErrorClass}`);
278
+ if (!isErrorClass(ErrorClass.prototype)) throw new TypeError(`ErrorClass must inherit from Error: ${ErrorClass}`);
279
+ if (!hasConstructor(ErrorClass)) throw new TypeError(`ErrorClass must be have a valid constructor: ${ErrorClass}`);
280
+ };
281
+ const isClass = (ErrorClass) => typeof ErrorClass === "function" && typeof ErrorClass.prototype === "object" && ErrorClass.prototype !== null;
282
+ const isErrorClass = (prototype) => prototype !== null && (prototype.name === "Error" || isErrorClass(Object.getPrototypeOf(prototype)));
283
+ const hasConstructor = (ErrorClass) => typeof ErrorClass.prototype.constructor === "function";
284
+
285
+ //#endregion
286
+ //#region ../../node_modules/.pnpm/set-error-class@3.0.1/node_modules/set-error-class/build/src/enum.js
287
+ const setNonEnumProp$1 = (error, propName, value) => {
288
+ Object.defineProperty(error, propName, {
289
+ value,
290
+ enumerable: false,
291
+ writable: true,
292
+ configurable: true
293
+ });
294
+ };
295
+
296
+ //#endregion
297
+ //#region ../../node_modules/.pnpm/set-error-class@3.0.1/node_modules/set-error-class/build/src/prototype.js
298
+ const updatePrototype = (error, ErrorClass) => {
299
+ if (Object.getPrototypeOf(error) === ErrorClass.prototype) return;
300
+ setPrototype(error, ErrorClass);
301
+ deleteOwnProperty(error, "constructor");
302
+ fixName(error, ErrorClass);
303
+ };
304
+ const setPrototype = (error, ErrorClass) => {
305
+ Object.setPrototypeOf(error, ErrorClass.prototype);
306
+ };
307
+ const fixName = (error, ErrorClass) => {
308
+ deleteOwnProperty(error, "name");
309
+ const prototypeName = getClassName(ErrorClass.prototype);
310
+ if (error.name !== prototypeName) setNonEnumProp$1(error, "name", prototypeName);
311
+ };
312
+ const getClassName = (prototype) => getPrototypeName(prototype) ?? getConstructorName(prototype) ?? getClassName(Object.getPrototypeOf(prototype));
313
+ const getPrototypeName = (prototype) => Object.hasOwn(prototype, "name") && isDefinedString(prototype.name) ? prototype.name : void 0;
314
+ const getConstructorName = (prototype) => typeof prototype.constructor === "function" && isDefinedString(prototype.constructor.name) ? prototype.constructor.name : void 0;
315
+ const isDefinedString = (value) => typeof value === "string" && value !== "";
316
+ const deleteOwnProperty = (error, propName) => {
317
+ if (Object.hasOwn(error, propName)) delete error[propName];
318
+ };
319
+
320
+ //#endregion
321
+ //#region ../../node_modules/.pnpm/set-error-class@3.0.1/node_modules/set-error-class/build/src/stack.js
322
+ const updateStack$1 = (error, currentName) => {
323
+ if (!shouldUpdateStack(error, currentName)) return;
324
+ setNonEnumProp$1(error, "stack", getStack$2(error, currentName));
325
+ };
326
+ const shouldUpdateStack = (error, currentName) => currentName !== error.name && currentName !== "" && error.stack.includes(currentName) && stackIncludesName();
327
+ const stackIncludesName = () => {
328
+ class StackError extends Error {}
329
+ const descriptor = {
330
+ value: EXAMPLE_NAME,
331
+ enumerable: false,
332
+ writable: true,
333
+ configurable: true
334
+ };
335
+ Object.defineProperty(StackError, "name", descriptor);
336
+ Object.defineProperty(StackError.prototype, "name", descriptor);
337
+ const { stack } = new StackError("");
338
+ return typeof stack === "string" && stack.includes(EXAMPLE_NAME);
339
+ };
340
+ const EXAMPLE_NAME = "SetErrorClassError";
341
+ const getStack$2 = ({ name, stack }, currentName) => {
342
+ if (stack.startsWith(`${currentName}: `)) return stack.replace(currentName, name);
343
+ const [fromA, to] = getReplacers$1(currentName, name).find(([from]) => stack.includes(from));
344
+ return stack.replace(fromA, to);
345
+ };
346
+ const getReplacers$1 = (currentName, newName) => [
347
+ [`\n${currentName}: `, `\n${newName}: `],
348
+ [`${currentName}: `, `${newName}: `],
349
+ [`${currentName} `, `${newName} `],
350
+ [currentName, newName]
351
+ ];
352
+
353
+ //#endregion
354
+ //#region ../../node_modules/.pnpm/set-error-class@3.0.1/node_modules/set-error-class/build/src/main.js
355
+ const setErrorClass = (error, ErrorClass, currentName) => {
356
+ const errorA = main_default$6(error);
357
+ const currentNameA = normalizeArgs$1(errorA, ErrorClass, currentName);
358
+ updatePrototype(errorA, ErrorClass);
359
+ updateStack$1(errorA, currentNameA);
360
+ return errorA;
361
+ };
362
+ var main_default$5 = setErrorClass;
363
+
364
+ //#endregion
365
+ //#region ../../node_modules/.pnpm/redefine-property@3.0.1/node_modules/redefine-property/build/src/merge.js
366
+ const mergeDescriptors = (newDescriptor, currentDescriptor) => currentDescriptor.configurable === false ? mergeNonConfig(newDescriptor, currentDescriptor) : mergeConfig(newDescriptor, currentDescriptor);
367
+ const mergeNonConfig = (newDescriptor, currentDescriptor) => ({
368
+ ...currentDescriptor,
369
+ ...getNonConfigWritable(newDescriptor, currentDescriptor),
370
+ ...getNonConfigValue(newDescriptor, currentDescriptor)
371
+ });
372
+ const getNonConfigWritable = (newDescriptor, currentDescriptor) => currentDescriptor.writable === true && newDescriptor.writable === false ? { writable: false } : {};
373
+ const getNonConfigValue = (newDescriptor, currentDescriptor) => newDescriptor.hasValue && "value" in currentDescriptor && currentDescriptor.writable === true ? { value: newDescriptor.value } : {};
374
+ const mergeConfig = (newDescriptor, currentDescriptor) => {
375
+ const enumerable = mergeDescriptor(newDescriptor.enumerable, currentDescriptor.enumerable, true);
376
+ const writable = mergeDescriptor(newDescriptor.writable, currentDescriptor.writable, true);
377
+ const configurable = mergeDescriptor(newDescriptor.configurable, currentDescriptor.configurable, true);
378
+ return {
379
+ ...mergeValue(newDescriptor, currentDescriptor, writable),
380
+ enumerable,
381
+ configurable
382
+ };
383
+ };
384
+ const mergeValue = (newDescriptor, currentDescriptor, writable) => {
385
+ if (newDescriptor.hasValue) return {
386
+ value: newDescriptor.value,
387
+ writable
388
+ };
389
+ if (!hasGetSet(newDescriptor) && !hasGetSet(currentDescriptor)) return {
390
+ value: currentDescriptor.value,
391
+ writable
392
+ };
393
+ return {
394
+ get: mergeDescriptor(newDescriptor.get, currentDescriptor.get),
395
+ set: mergeDescriptor(newDescriptor.set, currentDescriptor.set)
396
+ };
397
+ };
398
+ const hasGetSet = ({ get, set }) => get !== void 0 || set !== void 0;
399
+ const mergeDescriptor = (newValue, currentValue, defaultValue) => newValue ?? currentValue ?? defaultValue;
400
+
401
+ //#endregion
402
+ //#region ../../node_modules/.pnpm/redefine-property@3.0.1/node_modules/redefine-property/build/src/normalize.js
403
+ const normalizeInput = (input, key, newDescriptor) => {
404
+ if (!isAnyObj(input)) throw new TypeError(`Argument must be an object: ${input}`);
405
+ if (!isValidKey(key)) throw new TypeError(`Property key must be a string, a symbol or an integer: ${key}`);
406
+ return normalizeDescriptor(newDescriptor);
407
+ };
408
+ const isAnyObj = (value) => typeof value === "object" && value !== null;
409
+ const isValidKey = (key) => {
410
+ const type = typeof key;
411
+ return type === "string" || type === "symbol" || type === "number";
412
+ };
413
+ const normalizeDescriptor = (newDescriptor) => {
414
+ if (!isPlainObject(newDescriptor)) throw new TypeError(`Descriptor must be a plain object: ${newDescriptor}`);
415
+ const { enumerable, writable, configurable, value, get, set, ...unknownProps } = newDescriptor;
416
+ const hasValue = "value" in newDescriptor;
417
+ validateDescriptor({
418
+ enumerable,
419
+ writable,
420
+ configurable,
421
+ get,
422
+ set,
423
+ unknownProps,
424
+ hasValue
425
+ });
426
+ return {
427
+ enumerable,
428
+ writable,
429
+ configurable,
430
+ value,
431
+ get,
432
+ set,
433
+ hasValue
434
+ };
435
+ };
436
+ const validateDescriptor = ({ enumerable, writable, configurable, get, set, unknownProps, hasValue }) => {
437
+ validateGetSet(hasValue, get, "get");
438
+ validateGetSet(hasValue, set, "set");
439
+ validateBoolean(enumerable, "enumerable");
440
+ validateBoolean(writable, "writable");
441
+ validateBoolean(configurable, "configurable");
442
+ validateUnknownProps(unknownProps);
443
+ };
444
+ const validateGetSet = (hasValue, getSet, propName) => {
445
+ validateFunction(getSet, propName);
446
+ if (hasValue && getSet !== void 0) throw new TypeError(`Descriptor property "value" and "${propName}" must not both be defined: ${getSet}`);
447
+ };
448
+ const validateFunction = (propValue, propName) => {
449
+ if (propValue !== void 0 && typeof propValue !== "function") throw new TypeError(`Descriptor property "${propName}" must be a function: ${propValue}`);
450
+ };
451
+ const validateBoolean = (propValue, propName) => {
452
+ if (propValue !== void 0 && typeof propValue !== "boolean") throw new TypeError(`Descriptor property "${propName}" must be a boolean: ${propValue}`);
453
+ };
454
+ const validateUnknownProps = (unknownProps) => {
455
+ const [unknownProp] = Object.keys(unknownProps);
456
+ if (unknownProp !== void 0) throw new TypeError(`Unknown descriptor property "${unknownProp}": ${unknownProps[unknownProp]}`);
457
+ };
458
+
459
+ //#endregion
460
+ //#region ../../node_modules/.pnpm/redefine-property@3.0.1/node_modules/redefine-property/build/src/main.js
461
+ const redefineProperty = (input, key, newDescriptor) => {
462
+ setProperty(input, key, mergeDescriptors(normalizeInput(input, key, newDescriptor), getCurrentDescriptor(input, key)));
463
+ return input;
464
+ };
465
+ var main_default$4 = redefineProperty;
466
+ const getCurrentDescriptor = (input, key) => {
467
+ const descriptor = Object.getOwnPropertyDescriptor(input, key);
468
+ if (descriptor !== void 0) return descriptor;
469
+ const prototype = Object.getPrototypeOf(input);
470
+ return prototype === null ? {} : getCurrentDescriptor(prototype, key);
471
+ };
472
+ const setProperty = (input, key, finalDescriptor) => {
473
+ try {
474
+ Object.defineProperty(input, key, finalDescriptor);
475
+ } catch {}
476
+ };
477
+
478
+ //#endregion
479
+ //#region ../../node_modules/.pnpm/set-error-props@6.0.1/node_modules/set-error-props/build/src/assign.js
480
+ const assignProp = (error, propName, propValue) => {
481
+ if (propValue !== void 0) return setProp(error, propName, propValue);
482
+ try {
483
+ delete error[propName];
484
+ } catch {}
485
+ if (error[propName] !== void 0) return setProp(error, propName);
486
+ };
487
+ const setProp = (error, propName, propValue) => {
488
+ main_default$4(error, propName, {
489
+ value: propValue,
490
+ ...getNonEnum(propName)
491
+ });
492
+ };
493
+ const getNonEnum = (propName) => typeof propName === "string" && propName.startsWith("_") ? { enumerable: false } : {};
494
+
495
+ //#endregion
496
+ //#region ../../node_modules/.pnpm/set-error-props@6.0.1/node_modules/set-error-props/build/src/options.js
497
+ const normalizeOptions = (error, props, opts = {}) => {
498
+ validateErrorOrObject(error, "First argument");
499
+ validateErrorOrObject(props, "Second argument");
500
+ if (!isPlainObject(opts)) throw new TypeError(`Options must be a plain object: ${opts}`);
501
+ const { soft = false } = opts;
502
+ if (typeof soft !== "boolean") throw new TypeError(`Option "soft" must be a boolean: ${soft}`);
503
+ return { soft };
504
+ };
505
+ const validateErrorOrObject = (value, prefix) => {
506
+ if (value === void 0) throw new TypeError(`${prefix} is required.`);
507
+ if (!isErrorOrObject(value)) throw new TypeError(`${prefix} must be a plain object or an error: ${value}`);
508
+ };
509
+ const isErrorOrObject = (value) => isPlainObject(value) || main_default$7(value);
510
+
511
+ //#endregion
512
+ //#region ../../node_modules/.pnpm/set-error-props@6.0.1/node_modules/set-error-props/build/src/skip.js
513
+ const shouldSkipProp = ({ error, props, propName, soft }) => isIgnoredPropName(propName) || !isEnum.call(props, propName) || soft && error[propName] !== void 0;
514
+ const isIgnoredPropName = (propName) => propName in CHECK_ERROR || IGNORED_PROPS.has(propName);
515
+ const CHECK_ERROR = /* @__PURE__ */ new Error("check");
516
+ const IGNORED_PROPS = new Set([
517
+ "prototype",
518
+ "errors",
519
+ "cause"
520
+ ]);
521
+ const { propertyIsEnumerable: isEnum } = Object.prototype;
522
+
523
+ //#endregion
524
+ //#region ../../node_modules/.pnpm/set-error-props@6.0.1/node_modules/set-error-props/build/src/main.js
525
+ const setErrorProps = (error, props, opts) => {
526
+ const { soft } = normalizeOptions(error, props, opts);
527
+ for (const propName of Reflect.ownKeys(props)) setErrorProp({
528
+ error,
529
+ props,
530
+ propName,
531
+ soft
532
+ });
533
+ return error;
534
+ };
535
+ var main_default$3 = setErrorProps;
536
+ const setErrorProp = ({ error, props, propName, soft }) => {
537
+ if (!shouldSkipProp({
538
+ error,
539
+ props,
540
+ propName,
541
+ soft
542
+ })) assignProp(error, propName, props[propName]);
543
+ };
544
+
545
+ //#endregion
546
+ //#region ../../node_modules/.pnpm/merge-error-cause@5.0.2/node_modules/merge-error-cause/build/src/set.js
547
+ const setErrorProperty = (error, propName, value) => {
548
+ Object.defineProperty(error, propName, {
549
+ value,
550
+ writable: true,
551
+ enumerable: false,
552
+ configurable: true
553
+ });
554
+ };
555
+
556
+ //#endregion
557
+ //#region ../../node_modules/.pnpm/merge-error-cause@5.0.2/node_modules/merge-error-cause/build/src/aggregate.js
558
+ const mergeAggregateCauses = (parent, recurse) => {
559
+ if (parent.errors === void 0) return;
560
+ setErrorProperty(parent, "errors", parent.errors.map((error) => recurse(error).error).filter(Boolean));
561
+ };
562
+ const mergeAggregateErrors = ({ target, source, parent, child }) => {
563
+ if (!hasErrors(target)) {
564
+ mergeSourceErrors(target, source);
565
+ return;
566
+ }
567
+ if (hasErrors(source)) setErrorProperty(target, "errors", [...child.errors, ...parent.errors]);
568
+ };
569
+ const mergeSourceErrors = (target, source) => {
570
+ if (source.errors !== void 0) setErrorProperty(target, "errors", source.errors);
571
+ };
572
+ const hasErrors = (targetOrSource) => targetOrSource.errors !== void 0 && targetOrSource.errors.length !== 0;
573
+
574
+ //#endregion
575
+ //#region ../../node_modules/.pnpm/set-error-message@3.0.1/node_modules/set-error-message/build/src/args.js
576
+ const normalizeArgs = (error, newMessage, currentMessage = error.message) => {
577
+ if (typeof newMessage !== "string") throw new TypeError(`newMessage must be a string: ${newMessage}`);
578
+ if (typeof currentMessage !== "string") throw new TypeError(`currentMessage must be a string: ${currentMessage}`);
579
+ return currentMessage;
580
+ };
581
+
582
+ //#endregion
583
+ //#region ../../node_modules/.pnpm/set-error-message@3.0.1/node_modules/set-error-message/build/src/stack.js
584
+ const getStack$1 = ({ name, stack }, newMessage, currentMessage) => currentMessage !== "" && stack.includes(currentMessage) ? replaceMessage({
585
+ name,
586
+ stack,
587
+ newMessage,
588
+ currentMessage
589
+ }) : insertMessage(name, stack, newMessage);
590
+ const replaceMessage = ({ name, stack, newMessage, currentMessage }) => {
591
+ const [fromA, to] = getReplacers(name, newMessage, currentMessage).find(([from]) => stack.includes(from));
592
+ return stack.replace(fromA, to);
593
+ };
594
+ const getReplacers = (name, newMessage, currentMessage) => [
595
+ [`${name}: ${currentMessage}`, `${name}: ${newMessage}`],
596
+ [`: ${currentMessage}`, `: ${newMessage}`],
597
+ [`\n${currentMessage}`, `\n${newMessage}`],
598
+ [` ${currentMessage}`, ` ${newMessage}`],
599
+ [currentMessage, newMessage]
600
+ ];
601
+ const insertMessage = (name, stack, newMessage) => {
602
+ const nameAndColon = `${name}: `;
603
+ const newMessageA = newMessage.trimEnd();
604
+ if (stack === name || stack.startsWith(`${name}\n`)) return stack.replace(name, `${nameAndColon}${newMessageA}`);
605
+ return stack.startsWith(nameAndColon) ? stack.replace(nameAndColon, `${nameAndColon}${newMessageA}\n`) : `${nameAndColon}${newMessageA}\n${stack}`;
606
+ };
607
+
608
+ //#endregion
609
+ //#region ../../node_modules/.pnpm/set-error-message@3.0.1/node_modules/set-error-message/build/src/main.js
610
+ const setErrorMessage = (error, newMessage, currentMessage) => {
611
+ const errorA = main_default$6(error);
612
+ const currentMessageA = normalizeArgs(errorA, newMessage, currentMessage);
613
+ setNonEnumProp(errorA, "message", newMessage);
614
+ updateStack(errorA, newMessage, currentMessageA);
615
+ return errorA;
616
+ };
617
+ var main_default$2 = setErrorMessage;
618
+ const updateStack = (error, newMessage, currentMessage) => {
619
+ if (newMessage === currentMessage || !stackIncludesMessage()) return;
620
+ setNonEnumProp(error, "stack", getStack$1(error, newMessage, currentMessage));
621
+ };
622
+ const stackIncludesMessage = () => {
623
+ const { stack } = new Error(EXAMPLE_MESSAGE);
624
+ return typeof stack === "string" && stack.includes(EXAMPLE_MESSAGE);
625
+ };
626
+ const EXAMPLE_MESSAGE = "set-error-message test message";
627
+ const setNonEnumProp = (error, propName, value) => {
628
+ Object.defineProperty(error, propName, {
629
+ value,
630
+ enumerable: false,
631
+ writable: true,
632
+ configurable: true
633
+ });
634
+ };
635
+
636
+ //#endregion
637
+ //#region ../../node_modules/.pnpm/wrap-error-message@3.0.1/node_modules/wrap-error-message/build/src/main.js
638
+ const wrapErrorMessage = (error, newMessage, oldMessage) => {
639
+ if (typeof newMessage !== "string") throw new TypeError(`Second argument must be a message string: ${newMessage}`);
640
+ const errorA = main_default$6(error);
641
+ return main_default$2(errorA, getMessage(newMessage, errorA.message), oldMessage);
642
+ };
643
+ var main_default$1 = wrapErrorMessage;
644
+ const getMessage = (rawNewMessage, rawCurrentMessage) => {
645
+ const newMessage = rawNewMessage.trim();
646
+ const currentMessage = rawCurrentMessage.trim();
647
+ if (newMessage === "") return currentMessage;
648
+ if (currentMessage === "") return newMessage;
649
+ return concatMessages(newMessage, currentMessage, rawNewMessage);
650
+ };
651
+ const concatMessages = (newMessage, currentMessage, rawNewMessage) => {
652
+ if (!newMessage.endsWith(PREPEND_CHAR)) return `${currentMessage}\n${newMessage}`;
653
+ return rawNewMessage.endsWith(PREPEND_NEWLINE_CHAR) ? `${newMessage}\n${currentMessage}` : `${newMessage} ${currentMessage}`;
654
+ };
655
+ const PREPEND_CHAR = ":";
656
+ const PREPEND_NEWLINE_CHAR = "\n";
657
+
658
+ //#endregion
659
+ //#region ../../node_modules/.pnpm/merge-error-cause@5.0.2/node_modules/merge-error-cause/build/src/message.js
660
+ const mergeMessage = ({ parent, child, target, stackError }) => {
661
+ const parentMessage = parent.message;
662
+ const stackErrorMessage = stackError.message;
663
+ target.message = child.message;
664
+ return main_default$1(target, parentMessage, stackErrorMessage);
665
+ };
666
+
667
+ //#endregion
668
+ //#region ../../node_modules/.pnpm/merge-error-cause@5.0.2/node_modules/merge-error-cause/build/src/stack.js
669
+ const hasStack = (error, stack) => getStack(error) === stack;
670
+ const getStack = (error) => typeof error === "object" && error !== null ? error.stack : void 0;
671
+ const mergeStack = ({ wrap, target, source, childHasStack }) => {
672
+ if (wrap === childHasStack) return target;
673
+ setErrorProperty(target, "stack", source.stack);
674
+ return source;
675
+ };
676
+
677
+ //#endregion
678
+ //#region ../../node_modules/.pnpm/merge-error-cause@5.0.2/node_modules/merge-error-cause/build/src/wrap.js
679
+ const getWrap = (parent) => {
680
+ const { wrap, name } = parent;
681
+ if (typeof wrap !== "boolean") return name === "Error";
682
+ if (Object.hasOwn(parent, "wrap")) delete parent.wrap;
683
+ return wrap;
684
+ };
685
+
686
+ //#endregion
687
+ //#region ../../node_modules/.pnpm/merge-error-cause@5.0.2/node_modules/merge-error-cause/build/src/main.js
688
+ const mergeErrorCause = (error) => mergeError(error, []).error;
689
+ var main_default = mergeErrorCause;
690
+ const mergeError = (error, parents) => {
691
+ if (parents.includes(error)) return {};
692
+ const recurse = (innerError) => mergeError(innerError, [...parents, error]);
693
+ const stack = getStack(error);
694
+ const errorA = main_default$6(error, { shallow: true });
695
+ const parentHasStack = hasStack(errorA, stack);
696
+ mergeAggregateCauses(errorA, recurse);
697
+ const { parent: errorB, childHasStack } = mergeCause(errorA, recurse);
698
+ return {
699
+ error: errorB,
700
+ errorHasStack: parentHasStack || childHasStack
701
+ };
702
+ };
703
+ const mergeCause = (parent, recurse) => {
704
+ const wrap = getWrap(parent);
705
+ if (parent.cause === void 0) return {
706
+ parent,
707
+ childHasStack: false
708
+ };
709
+ const { error: child, errorHasStack: childHasStack } = recurse(parent.cause);
710
+ delete parent.cause;
711
+ return {
712
+ parent: mergeChild({
713
+ parent,
714
+ child,
715
+ childHasStack,
716
+ wrap
717
+ }),
718
+ childHasStack
719
+ };
720
+ };
721
+ const mergeChild = ({ parent, child, childHasStack, wrap }) => {
722
+ if (child === void 0) return parent;
723
+ const [target, source] = wrap ? [child, parent] : [parent, child];
724
+ const stackError = mergeStack({
725
+ wrap,
726
+ target,
727
+ source,
728
+ childHasStack
729
+ });
730
+ const targetB = mergeMessage({
731
+ parent,
732
+ child,
733
+ target: main_default$5(target, target.constructor, stackError.name),
734
+ stackError
735
+ });
736
+ mergeAggregateErrors({
737
+ target: targetB,
738
+ source,
739
+ parent,
740
+ child
741
+ });
742
+ return main_default$3(targetB, source, { soft: !wrap });
743
+ };
744
+
745
+ //#endregion
746
+ export { main_default$1 as n, main_default as t };