@devp0nt/error0 1.0.0-next.38 → 1.0.0-next.39
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/cjs/index.cjs +304 -376
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +177 -411
- package/dist/esm/index.d.ts +177 -411
- package/dist/esm/index.js +302 -365
- package/dist/esm/index.js.map +1 -1
- package/package.json +7 -9
- package/src/index.test.ts +315 -483
- package/src/index.ts +636 -534
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,435 +15,365 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
var index_exports = {};
|
|
30
20
|
__export(index_exports, {
|
|
31
|
-
Error0: () => Error0
|
|
21
|
+
Error0: () => Error0,
|
|
22
|
+
ExtensionError0: () => ExtensionError0
|
|
32
23
|
});
|
|
33
24
|
module.exports = __toCommonJS(index_exports);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const toNumberOrUndefined = (value) => {
|
|
44
|
-
if (typeof value === "number") {
|
|
45
|
-
return value;
|
|
46
|
-
}
|
|
47
|
-
const number = Number(value);
|
|
48
|
-
if (typeof value === "string" && !Number.isNaN(number)) {
|
|
49
|
-
return number;
|
|
50
|
-
}
|
|
51
|
-
return void 0;
|
|
52
|
-
};
|
|
53
|
-
const toBooleanOrUndefined = (value) => {
|
|
54
|
-
if (typeof value === "boolean") {
|
|
55
|
-
return value;
|
|
56
|
-
}
|
|
57
|
-
return void 0;
|
|
58
|
-
};
|
|
59
|
-
class Error0 extends Error {
|
|
60
|
-
__I_AM_ERROR_0 = true;
|
|
61
|
-
tag;
|
|
62
|
-
code;
|
|
63
|
-
httpStatus;
|
|
64
|
-
expected;
|
|
65
|
-
clientMessage;
|
|
66
|
-
anyMessage;
|
|
67
|
-
cause;
|
|
68
|
-
meta;
|
|
69
|
-
zodError;
|
|
70
|
-
axiosError;
|
|
71
|
-
static defaultMessage = "Unknown error";
|
|
72
|
-
static defaultCode;
|
|
73
|
-
static defaultHttpStatus;
|
|
74
|
-
static defaultExpected;
|
|
75
|
-
static defaultClientMessage;
|
|
76
|
-
static defaultMeta;
|
|
77
|
-
propsOriginal;
|
|
78
|
-
constructor(...args) {
|
|
79
|
-
const input = {};
|
|
80
|
-
if (args[0] instanceof Error) {
|
|
81
|
-
input.cause = args[0];
|
|
82
|
-
} else if (typeof args[0] === "object" && args[0] !== null) {
|
|
83
|
-
Object.assign(input, args[0]);
|
|
84
|
-
} else if (typeof args[0] === "string") {
|
|
85
|
-
input.message = args[0];
|
|
86
|
-
}
|
|
87
|
-
if (typeof args[1] === "object" && args[1] !== null) {
|
|
88
|
-
Object.assign(input, args[1]);
|
|
89
|
-
}
|
|
90
|
-
const safeInput = Error0._safeParseInput(input);
|
|
91
|
-
const message = safeInput.message || Error0.defaultMessage;
|
|
92
|
-
super(message);
|
|
93
|
-
Object.setPrototypeOf(this, this.constructor.prototype);
|
|
94
|
-
this.name = "Error0";
|
|
95
|
-
this.propsOriginal = this.constructor._getSelfGeneralProps({
|
|
96
|
-
error0Input: safeInput,
|
|
97
|
-
message,
|
|
98
|
-
stack: safeInput.stack || this.stack
|
|
99
|
-
});
|
|
100
|
-
const causesProps = this.constructor._getCausesPropsFromError0Props(
|
|
101
|
-
this.propsOriginal,
|
|
102
|
-
this.constructor.defaultMaxLevel
|
|
103
|
-
);
|
|
104
|
-
const propsFloated = this.constructor._getSelfPropsFloated(causesProps);
|
|
105
|
-
this.tag = propsFloated.tag;
|
|
106
|
-
this.code = propsFloated.code;
|
|
107
|
-
this.httpStatus = propsFloated.httpStatus;
|
|
108
|
-
this.expected = propsFloated.expected;
|
|
109
|
-
this.clientMessage = propsFloated.clientMessage;
|
|
110
|
-
this.cause = propsFloated.cause;
|
|
111
|
-
this.stack = propsFloated.stack;
|
|
112
|
-
this.meta = propsFloated.meta;
|
|
113
|
-
this.zodError = propsFloated.zodError;
|
|
114
|
-
this.axiosError = propsFloated.axiosError;
|
|
115
|
-
}
|
|
116
|
-
// settings
|
|
117
|
-
static defaultMaxLevel = 10;
|
|
118
|
-
// props
|
|
119
|
-
static _safeParseInput(error0Input) {
|
|
120
|
-
const result = {};
|
|
121
|
-
result.message = typeof error0Input.message === "string" ? error0Input.message : void 0;
|
|
122
|
-
result.tag = typeof error0Input.tag === "string" ? error0Input.tag : void 0;
|
|
123
|
-
result.code = typeof error0Input.code === "string" ? error0Input.code : void 0;
|
|
124
|
-
result.httpStatus = typeof error0Input.httpStatus === "number" || typeof error0Input.httpStatus === "string" ? error0Input.httpStatus : void 0;
|
|
125
|
-
result.expected = typeof error0Input.expected === "function" || typeof error0Input.expected === "boolean" ? error0Input.expected : void 0;
|
|
126
|
-
result.clientMessage = typeof error0Input.clientMessage === "string" ? error0Input.clientMessage : void 0;
|
|
127
|
-
result.cause = error0Input.cause;
|
|
128
|
-
result.stack = typeof error0Input.stack === "string" ? error0Input.stack : void 0;
|
|
129
|
-
result.meta = error0Input.meta instanceof import_meta0.Meta0 ? error0Input.meta : typeof error0Input.meta === "object" && error0Input.meta !== null ? error0Input.meta : void 0;
|
|
130
|
-
result.zodError = error0Input.zodError instanceof import_zod.ZodError ? error0Input.zodError : void 0;
|
|
131
|
-
result.axiosError = (0, import_axios.isAxiosError)(error0Input.axiosError) ? error0Input.axiosError : void 0;
|
|
132
|
-
return result;
|
|
133
|
-
}
|
|
134
|
-
static _getSelfGeneralProps({
|
|
135
|
-
error0Input,
|
|
136
|
-
message,
|
|
137
|
-
stack
|
|
138
|
-
}) {
|
|
139
|
-
const meta0 = import_meta0.Meta0.extend(this.defaultMeta, error0Input.meta);
|
|
140
|
-
const meta = meta0.getValue();
|
|
141
|
-
const finalTag = import_meta0_plugin_tag.meta0PluginTag.public.getFullTag(meta0, error0Input.tag);
|
|
142
|
-
delete meta.tagPrefix;
|
|
143
|
-
const clientMessage = error0Input.clientMessage || this.defaultClientMessage;
|
|
144
|
-
const result = {
|
|
145
|
-
message: error0Input.message || this.defaultMessage,
|
|
146
|
-
tag: finalTag,
|
|
147
|
-
code: error0Input.code || toStringOrUndefined(meta.code) || this.defaultCode,
|
|
148
|
-
httpStatus: typeof error0Input.httpStatus === "number" ? error0Input.httpStatus : error0Input.httpStatus && typeof error0Input.httpStatus === "string" && error0Input.httpStatus in import_axios.HttpStatusCode ? import_axios.HttpStatusCode[error0Input.httpStatus] : toNumberOrUndefined(meta.httpStatus) || this.defaultHttpStatus,
|
|
149
|
-
expected: void 0,
|
|
150
|
-
clientMessage,
|
|
151
|
-
anyMessage: clientMessage || message,
|
|
152
|
-
cause: error0Input.cause,
|
|
153
|
-
stack: void 0,
|
|
154
|
-
meta,
|
|
155
|
-
zodError: error0Input.zodError,
|
|
156
|
-
axiosError: error0Input.axiosError
|
|
157
|
-
};
|
|
158
|
-
result.expected = this._normalizeSelfExpected(
|
|
159
|
-
result,
|
|
160
|
-
typeof error0Input.expected === "boolean" || typeof error0Input.expected === "function" ? error0Input.expected : toBooleanOrUndefined(meta.expected) || this.defaultExpected
|
|
161
|
-
);
|
|
162
|
-
result.stack = this._removeConstructorStackPart(stack);
|
|
163
|
-
return result;
|
|
164
|
-
}
|
|
165
|
-
static _getSelfPropsFloated(causesProps) {
|
|
166
|
-
const cause = this._getClosestPropValue(causesProps, "cause");
|
|
167
|
-
const stack = this._mergeStack(causesProps[1]?.stack, causesProps[0]?.stack);
|
|
168
|
-
const closestTag = this._getClosestPropValue(causesProps, "tag");
|
|
169
|
-
const meta = this._getMergedMetaValue(causesProps);
|
|
170
|
-
const tag = import_meta0_plugin_tag.meta0PluginTag.public.getFullTag(meta, closestTag);
|
|
171
|
-
const propsFloated = {
|
|
172
|
-
message: this._getClosestPropValue(causesProps, "message"),
|
|
173
|
-
tag,
|
|
174
|
-
code: this._getClosestPropValue(causesProps, "code"),
|
|
175
|
-
httpStatus: this._getClosestPropValue(causesProps, "httpStatus"),
|
|
176
|
-
expected: this._isExpected(causesProps),
|
|
177
|
-
clientMessage: this._getClosestPropValue(causesProps, "clientMessage"),
|
|
178
|
-
cause,
|
|
179
|
-
stack,
|
|
180
|
-
anyMessage: causesProps[0].anyMessage,
|
|
181
|
-
meta,
|
|
182
|
-
zodError: this._getClosestPropValue(causesProps, "zodError"),
|
|
183
|
-
axiosError: this._getClosestPropValue(causesProps, "axiosError")
|
|
25
|
+
class ExtensionError0 {
|
|
26
|
+
_extension;
|
|
27
|
+
Infer = void 0;
|
|
28
|
+
constructor(extension) {
|
|
29
|
+
this._extension = {
|
|
30
|
+
props: { ...extension?.props ?? {} },
|
|
31
|
+
computed: { ...extension?.computed ?? {} },
|
|
32
|
+
methods: { ...extension?.methods ?? {} },
|
|
33
|
+
refine: [...extension?.refine ?? []]
|
|
184
34
|
};
|
|
185
|
-
return propsFloated;
|
|
186
35
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
return {
|
|
190
|
-
message: `Zod Validation Error: ${zodError.message}`
|
|
191
|
-
};
|
|
36
|
+
prop(key, value) {
|
|
37
|
+
return this.extend("prop", key, value);
|
|
192
38
|
}
|
|
193
|
-
|
|
194
|
-
return
|
|
195
|
-
message: "Axios Error",
|
|
196
|
-
meta: {
|
|
197
|
-
axiosData: (() => {
|
|
198
|
-
try {
|
|
199
|
-
return JSON.stringify(axiosError.response?.data);
|
|
200
|
-
} catch {
|
|
201
|
-
return void 0;
|
|
202
|
-
}
|
|
203
|
-
})(),
|
|
204
|
-
axiosStatus: axiosError.response?.status
|
|
205
|
-
}
|
|
206
|
-
};
|
|
39
|
+
computed(key, value) {
|
|
40
|
+
return this.extend("computed", key, value);
|
|
207
41
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
Object.assign(error0Props, extraError0Props, { meta: metaValue });
|
|
42
|
+
method(key, value) {
|
|
43
|
+
return this.extend("method", key, value);
|
|
211
44
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
if (typeof expectedProvided === "function") {
|
|
215
|
-
return expectedProvided(error0Props);
|
|
216
|
-
}
|
|
217
|
-
return expectedProvided;
|
|
45
|
+
refine(value) {
|
|
46
|
+
return this.extend("refine", value);
|
|
218
47
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
48
|
+
extend(kind, keyOrValue, value) {
|
|
49
|
+
const nextProps = { ...this._extension.props ?? {} };
|
|
50
|
+
const nextComputed = { ...this._extension.computed ?? {} };
|
|
51
|
+
const nextMethods = { ...this._extension.methods ?? {} };
|
|
52
|
+
const nextRefine = [
|
|
53
|
+
...this._extension.refine ?? []
|
|
54
|
+
];
|
|
55
|
+
if (kind === "prop") {
|
|
56
|
+
const key = keyOrValue;
|
|
57
|
+
if (value === void 0) {
|
|
58
|
+
throw new Error('ExtensionError0.extend("prop", key, value) requires value');
|
|
224
59
|
}
|
|
225
|
-
|
|
226
|
-
|
|
60
|
+
nextProps[key] = value;
|
|
61
|
+
} else if (kind === "computed") {
|
|
62
|
+
const key = keyOrValue;
|
|
63
|
+
if (value === void 0) {
|
|
64
|
+
throw new Error('ExtensionError0.extend("computed", key, value) requires value');
|
|
227
65
|
}
|
|
66
|
+
nextComputed[key] = value;
|
|
67
|
+
} else if (kind === "method") {
|
|
68
|
+
const key = keyOrValue;
|
|
69
|
+
if (value === void 0) {
|
|
70
|
+
throw new Error('ExtensionError0.extend("method", key, value) requires value');
|
|
71
|
+
}
|
|
72
|
+
nextMethods[key] = value;
|
|
73
|
+
} else {
|
|
74
|
+
nextRefine.push(keyOrValue);
|
|
228
75
|
}
|
|
229
|
-
return
|
|
76
|
+
return new ExtensionError0({
|
|
77
|
+
props: nextProps,
|
|
78
|
+
computed: nextComputed,
|
|
79
|
+
methods: nextMethods,
|
|
80
|
+
refine: nextRefine
|
|
81
|
+
});
|
|
230
82
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
const message = "message" in error && typeof error.message === "string" ? error.message : void 0;
|
|
250
|
-
const clientMessage = "clientMessage" in error && typeof error.clientMessage === "string" ? error.clientMessage : defaults?.clientMessage || void 0;
|
|
251
|
-
const result = {
|
|
252
|
-
message,
|
|
253
|
-
code: "code" in error && typeof error.code === "string" ? error.code : defaults?.code || void 0,
|
|
254
|
-
clientMessage,
|
|
255
|
-
anyMessage: clientMessage || message || this.defaultMessage,
|
|
256
|
-
expected: void 0,
|
|
257
|
-
stack: "stack" in error && typeof error.stack === "string" ? error.stack : void 0,
|
|
258
|
-
tag: "tag" in error && typeof error.tag === "string" ? error.tag : defaults?.tag || void 0,
|
|
259
|
-
cause: "cause" in error ? error.cause : defaults?.cause || void 0,
|
|
260
|
-
meta: "meta" in error && typeof error.meta === "object" && error.meta !== null ? import_meta0.Meta0.getValue(error.meta) : (
|
|
261
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
262
|
-
import_meta0.Meta0.getValue(defaults?.meta) || {}
|
|
263
|
-
),
|
|
264
|
-
httpStatus: "httpStatus" in error && typeof error.httpStatus === "number" && error.httpStatus in import_axios.HttpStatusCode ? error.httpStatus : typeof defaults?.httpStatus === "string" ? import_axios.HttpStatusCode[defaults.httpStatus] : defaults?.httpStatus,
|
|
265
|
-
zodError: "zodError" in error && error.zodError instanceof import_zod.ZodError ? error.zodError : error instanceof import_zod.ZodError ? error : defaults?.zodError,
|
|
266
|
-
axiosError: "axiosError" in error && (0, import_axios.isAxiosError)(error.axiosError) ? error.axiosError : (0, import_axios.isAxiosError)(error) ? error : defaults?.axiosError
|
|
83
|
+
}
|
|
84
|
+
class Error0 extends Error {
|
|
85
|
+
static __extensionsMap;
|
|
86
|
+
static _extensions = [];
|
|
87
|
+
static _emptyExtension = {
|
|
88
|
+
props: {},
|
|
89
|
+
computed: {},
|
|
90
|
+
methods: {},
|
|
91
|
+
refine: []
|
|
92
|
+
};
|
|
93
|
+
static _getResolvedExtension() {
|
|
94
|
+
const resolved = {
|
|
95
|
+
props: {},
|
|
96
|
+
computed: {},
|
|
97
|
+
methods: {},
|
|
98
|
+
refine: []
|
|
267
99
|
};
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
this._assignError0Props(result, this._getExtraError0PropsByZodError(result.zodError));
|
|
100
|
+
for (const extension of this._extensions) {
|
|
101
|
+
Object.assign(resolved.props, extension.props ?? this._emptyExtension.props);
|
|
102
|
+
Object.assign(resolved.computed, extension.computed ?? this._emptyExtension.computed);
|
|
103
|
+
Object.assign(resolved.methods, extension.methods ?? this._emptyExtension.methods);
|
|
104
|
+
resolved.refine.push(...extension.refine ?? this._emptyExtension.refine);
|
|
274
105
|
}
|
|
275
|
-
|
|
276
|
-
this._assignError0Props(result, this._getExtraError0PropsByAxiosError(result.axiosError));
|
|
277
|
-
}
|
|
278
|
-
return result;
|
|
106
|
+
return resolved;
|
|
279
107
|
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
const
|
|
286
|
-
|
|
287
|
-
|
|
108
|
+
constructor(...args) {
|
|
109
|
+
const [first, second] = args;
|
|
110
|
+
const input = typeof first === "string" ? { message: first, ...second ?? {} } : first;
|
|
111
|
+
super(input.message, { cause: input.cause });
|
|
112
|
+
this.name = "Error0";
|
|
113
|
+
const ctor = this.constructor;
|
|
114
|
+
const extension = ctor._getResolvedExtension();
|
|
115
|
+
for (const [key, prop] of Object.entries(extension.props)) {
|
|
116
|
+
if (key in input) {
|
|
117
|
+
const ownValue = input[key];
|
|
118
|
+
this[key] = prop.input(ownValue);
|
|
119
|
+
} else {
|
|
120
|
+
Object.defineProperty(this, key, {
|
|
121
|
+
get: () => prop.output(this),
|
|
122
|
+
set: (value) => {
|
|
123
|
+
Object.defineProperty(this, key, {
|
|
124
|
+
value,
|
|
125
|
+
writable: true,
|
|
126
|
+
enumerable: true,
|
|
127
|
+
configurable: true
|
|
128
|
+
});
|
|
129
|
+
},
|
|
130
|
+
enumerable: true,
|
|
131
|
+
configurable: true
|
|
132
|
+
});
|
|
133
|
+
}
|
|
288
134
|
}
|
|
289
|
-
|
|
290
|
-
|
|
135
|
+
for (const [key, computed] of Object.entries(extension.computed)) {
|
|
136
|
+
Object.defineProperty(this, key, {
|
|
137
|
+
get: () => computed(this),
|
|
138
|
+
set: (value) => {
|
|
139
|
+
Object.defineProperty(this, key, {
|
|
140
|
+
value,
|
|
141
|
+
writable: true,
|
|
142
|
+
enumerable: true,
|
|
143
|
+
configurable: true
|
|
144
|
+
});
|
|
145
|
+
},
|
|
146
|
+
enumerable: true,
|
|
147
|
+
configurable: true
|
|
148
|
+
});
|
|
291
149
|
}
|
|
292
|
-
return causesProps;
|
|
293
|
-
}
|
|
294
|
-
static _getCausesPropsFromError0Props(error0Props, maxLevel) {
|
|
295
|
-
return [error0Props, ...this._getCausesPropsFromUnknown(error0Props.cause, maxLevel - 1)];
|
|
296
150
|
}
|
|
297
|
-
static
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
151
|
+
static isSelfProperty = (object, key) => {
|
|
152
|
+
const d = Object.getOwnPropertyDescriptor(object, key);
|
|
153
|
+
if (!d) return false;
|
|
154
|
+
if (typeof d.get === "function" || typeof d.set === "function") {
|
|
155
|
+
if ("name" in object && object.name === "Error0") {
|
|
156
|
+
return false;
|
|
157
|
+
} else {
|
|
158
|
+
return true;
|
|
302
159
|
}
|
|
303
160
|
}
|
|
161
|
+
return true;
|
|
162
|
+
};
|
|
163
|
+
static own(error, key) {
|
|
164
|
+
if (this.isSelfProperty(error, key)) {
|
|
165
|
+
return error[key];
|
|
166
|
+
}
|
|
304
167
|
return void 0;
|
|
305
168
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
// }
|
|
316
|
-
// return undefined
|
|
317
|
-
// }
|
|
318
|
-
static _getFilledPropValues(causesProps, propKey) {
|
|
319
|
-
const values = [];
|
|
320
|
-
for (const causeProps of causesProps) {
|
|
321
|
-
const propValue = causeProps[propKey];
|
|
322
|
-
if (isFilled(propValue)) {
|
|
323
|
-
values.push(propValue);
|
|
169
|
+
own(key) {
|
|
170
|
+
const ctor = this.constructor;
|
|
171
|
+
return ctor.own(this, key);
|
|
172
|
+
}
|
|
173
|
+
static flow(error, key, policy = "likeError0") {
|
|
174
|
+
return this.causes(error, policy).map((cause) => {
|
|
175
|
+
const causeRecord = cause;
|
|
176
|
+
if (this.isSelfProperty(causeRecord, key)) {
|
|
177
|
+
return causeRecord[key];
|
|
324
178
|
}
|
|
325
|
-
|
|
326
|
-
|
|
179
|
+
return void 0;
|
|
180
|
+
});
|
|
327
181
|
}
|
|
328
|
-
|
|
329
|
-
const
|
|
330
|
-
|
|
331
|
-
return {};
|
|
332
|
-
} else if (metas.length === 1) {
|
|
333
|
-
return metas[0];
|
|
334
|
-
} else {
|
|
335
|
-
return import_meta0.Meta0.mergeValues(metas[0], ...metas.slice(1));
|
|
336
|
-
}
|
|
182
|
+
flow(key, policy = "likeError0") {
|
|
183
|
+
const ctor = this.constructor;
|
|
184
|
+
return ctor.flow(this, key, policy);
|
|
337
185
|
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
186
|
+
static causes(error, policy = "all") {
|
|
187
|
+
const causes = [];
|
|
188
|
+
let current = error;
|
|
189
|
+
const maxDepth = 99;
|
|
190
|
+
const seen = /* @__PURE__ */ new Set();
|
|
191
|
+
for (let depth = 0; depth < maxDepth; depth += 1) {
|
|
192
|
+
if (!current || typeof current !== "object") {
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
if (seen.has(current)) {
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
if (policy === "instance") {
|
|
199
|
+
if (!this.is(current)) {
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
} else if (policy === "error0") {
|
|
203
|
+
if (!this.isError0(current)) {
|
|
204
|
+
break;
|
|
205
|
+
}
|
|
206
|
+
} else if (policy === "likeError0") {
|
|
207
|
+
if (!this.isLikeError0(current)) {
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
seen.add(current);
|
|
212
|
+
causes.push(current);
|
|
213
|
+
current = current.cause;
|
|
342
214
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
removeAllLinesContains("at _toError0");
|
|
349
|
-
removeAllLinesContains("at Error0.from");
|
|
350
|
-
removeAllLinesContains("at Error0._toError0");
|
|
351
|
-
return lines.join("\n");
|
|
215
|
+
return causes;
|
|
216
|
+
}
|
|
217
|
+
causes(policy = "all") {
|
|
218
|
+
const ctor = this.constructor;
|
|
219
|
+
return ctor.causes(this, policy);
|
|
352
220
|
}
|
|
353
|
-
static
|
|
354
|
-
return
|
|
221
|
+
static is(error) {
|
|
222
|
+
return error instanceof this;
|
|
355
223
|
}
|
|
356
|
-
// transformations
|
|
357
224
|
static isError0(error) {
|
|
358
225
|
return error instanceof Error0;
|
|
359
226
|
}
|
|
360
|
-
static
|
|
361
|
-
|
|
362
|
-
return true;
|
|
363
|
-
}
|
|
364
|
-
if (typeof error === "object" && error !== null) {
|
|
365
|
-
if ("__I_AM_ERROR_0" in error && error.__I_AM_ERROR_0 === true) {
|
|
366
|
-
return true;
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
return false;
|
|
227
|
+
static isLikeError0(error) {
|
|
228
|
+
return error instanceof Error0 || typeof error === "object" && error !== null && "name" in error && error.name === "Error0";
|
|
370
229
|
}
|
|
371
|
-
static
|
|
372
|
-
if (error
|
|
230
|
+
static from(error) {
|
|
231
|
+
if (this.is(error)) {
|
|
373
232
|
return error;
|
|
374
233
|
}
|
|
375
|
-
if (
|
|
376
|
-
return
|
|
234
|
+
if (this.isLikeError0(error)) {
|
|
235
|
+
return this._fromLikeError0(error);
|
|
236
|
+
}
|
|
237
|
+
return this._fromNonError0(error);
|
|
238
|
+
}
|
|
239
|
+
static _applyRefine(error) {
|
|
240
|
+
const extension = this._getResolvedExtension();
|
|
241
|
+
for (const refine of extension.refine) {
|
|
242
|
+
const refined = refine(error);
|
|
243
|
+
if (refined && typeof refined === "object") {
|
|
244
|
+
Object.assign(error, refined);
|
|
245
|
+
}
|
|
377
246
|
}
|
|
247
|
+
return error;
|
|
248
|
+
}
|
|
249
|
+
static _fromLikeError0(error) {
|
|
250
|
+
const message = this._extractMessage(error);
|
|
378
251
|
if (typeof error !== "object" || error === null) {
|
|
379
|
-
return new
|
|
380
|
-
message: this.defaultMessage,
|
|
381
|
-
...inputOverride
|
|
382
|
-
});
|
|
252
|
+
return this._applyRefine(new this(message, { cause: error }));
|
|
383
253
|
}
|
|
384
|
-
const
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
254
|
+
const errorRecord = error;
|
|
255
|
+
const recreated = new this(message);
|
|
256
|
+
const temp = new this(message, { cause: errorRecord });
|
|
257
|
+
const extension = this._getResolvedExtension();
|
|
258
|
+
for (const [key, prop] of Object.entries(extension.props)) {
|
|
259
|
+
const value = prop.output(temp);
|
|
260
|
+
if (value !== void 0) {
|
|
261
|
+
;
|
|
262
|
+
recreated[key] = value;
|
|
388
263
|
}
|
|
389
264
|
}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
}
|
|
265
|
+
;
|
|
266
|
+
recreated.cause = errorRecord.cause;
|
|
267
|
+
if (typeof errorRecord.stack === "string") {
|
|
268
|
+
recreated.stack = errorRecord.stack;
|
|
395
269
|
}
|
|
396
|
-
return
|
|
270
|
+
return this._applyRefine(recreated);
|
|
397
271
|
}
|
|
398
|
-
static
|
|
399
|
-
|
|
272
|
+
static _fromNonError0(error) {
|
|
273
|
+
const message = this._extractMessage(error);
|
|
274
|
+
return this._applyRefine(new this(message, { cause: error }));
|
|
400
275
|
}
|
|
401
|
-
static
|
|
402
|
-
|
|
403
|
-
return class Error0 extends parent {
|
|
404
|
-
static defaultMessage = props.defaultMessage ?? parent.defaultMessage;
|
|
405
|
-
static defaultCode = props.defaultCode ?? parent.defaultCode;
|
|
406
|
-
static defaultHttpStatus = props.defaultHttpStatus ?? parent.defaultHttpStatus;
|
|
407
|
-
static defaultExpected = props.defaultExpected ?? parent.defaultExpected;
|
|
408
|
-
static defaultClientMessage = props.defaultClientMessage ?? parent.defaultClientMessage;
|
|
409
|
-
static defaultMeta = import_meta0.Meta0.extend(parent.defaultMeta, props.defaultMeta);
|
|
410
|
-
};
|
|
276
|
+
static _extractMessage(error) {
|
|
277
|
+
return (typeof error === "string" ? error : typeof error === "object" && error !== null && "message" in error && typeof error.message === "string" ? error.message : void 0) || "Unknown error";
|
|
411
278
|
}
|
|
412
|
-
static
|
|
413
|
-
|
|
279
|
+
static _extendWithExtension(extension) {
|
|
280
|
+
const Base = this;
|
|
281
|
+
const Error0Extended = class Error0 extends Base {
|
|
282
|
+
};
|
|
283
|
+
Error0Extended._extensions = [...Base._extensions, extension];
|
|
284
|
+
const resolved = Error0Extended._getResolvedExtension();
|
|
285
|
+
for (const [key, method] of Object.entries(resolved.methods)) {
|
|
286
|
+
Object.defineProperty(Error0Extended.prototype, key, {
|
|
287
|
+
value: function(...args) {
|
|
288
|
+
return method(this, ...args);
|
|
289
|
+
},
|
|
290
|
+
writable: true,
|
|
291
|
+
enumerable: true,
|
|
292
|
+
configurable: true
|
|
293
|
+
});
|
|
294
|
+
Object.defineProperty(Error0Extended, key, {
|
|
295
|
+
value: function(error, ...args) {
|
|
296
|
+
return method(this.from(error), ...args);
|
|
297
|
+
},
|
|
298
|
+
writable: true,
|
|
299
|
+
enumerable: true,
|
|
300
|
+
configurable: true
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
return Error0Extended;
|
|
414
304
|
}
|
|
415
|
-
|
|
305
|
+
static _extensionFromBuilder(extension) {
|
|
306
|
+
const extensionRecord = extension;
|
|
416
307
|
return {
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
expected: this.expected,
|
|
422
|
-
clientMessage: this.clientMessage,
|
|
423
|
-
anyMessage: this.anyMessage,
|
|
424
|
-
cause: this.cause,
|
|
425
|
-
meta: import_meta0.Meta0.getValue(this.meta),
|
|
426
|
-
stack: this.stack,
|
|
427
|
-
__I_AM_ERROR_0: this.__I_AM_ERROR_0
|
|
308
|
+
props: { ...extensionRecord._extension.props ?? {} },
|
|
309
|
+
computed: { ...extensionRecord._extension.computed ?? {} },
|
|
310
|
+
methods: { ...extensionRecord._extension.methods ?? {} },
|
|
311
|
+
refine: [...extensionRecord._extension.refine ?? []]
|
|
428
312
|
};
|
|
429
313
|
}
|
|
430
|
-
static
|
|
431
|
-
|
|
432
|
-
|
|
314
|
+
static extend(first, key, value) {
|
|
315
|
+
if (first instanceof ExtensionError0) {
|
|
316
|
+
return this._extendWithExtension(this._extensionFromBuilder(first));
|
|
317
|
+
}
|
|
318
|
+
if (first === "refine") {
|
|
319
|
+
if (typeof key !== "function") {
|
|
320
|
+
throw new Error('Error0.extend("refine", value) requires refine function');
|
|
321
|
+
}
|
|
322
|
+
return this._extendWithExtension({
|
|
323
|
+
refine: [key]
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
if (typeof key !== "string" || value === void 0) {
|
|
327
|
+
throw new Error("Error0.extend(kind, key, value) requires key and value");
|
|
328
|
+
}
|
|
329
|
+
if (first === "prop") {
|
|
330
|
+
return this._extendWithExtension({
|
|
331
|
+
props: { [key]: value }
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
if (first === "computed") {
|
|
335
|
+
return this._extendWithExtension({
|
|
336
|
+
computed: { [key]: value }
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
return this._extendWithExtension({
|
|
340
|
+
methods: { [key]: value }
|
|
341
|
+
});
|
|
433
342
|
}
|
|
434
|
-
|
|
435
|
-
return
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
343
|
+
static extension() {
|
|
344
|
+
return new ExtensionError0();
|
|
345
|
+
}
|
|
346
|
+
static serialize(error, isPublic = true) {
|
|
347
|
+
const error0 = this.from(error);
|
|
348
|
+
const jsonWithUndefined = {
|
|
349
|
+
name: error0.name,
|
|
350
|
+
message: error0.message,
|
|
351
|
+
cause: error0.cause,
|
|
352
|
+
stack: error0.stack
|
|
353
|
+
};
|
|
354
|
+
const extension = this._getResolvedExtension();
|
|
355
|
+
for (const [key, prop] of Object.entries(extension.props)) {
|
|
356
|
+
const value = prop.output(error0);
|
|
357
|
+
const jsonValue = prop.serialize(value, isPublic);
|
|
358
|
+
if (jsonValue !== void 0) {
|
|
359
|
+
jsonWithUndefined[key] = jsonValue;
|
|
360
|
+
} else {
|
|
361
|
+
try {
|
|
362
|
+
delete jsonWithUndefined[key];
|
|
363
|
+
} catch {
|
|
364
|
+
}
|
|
443
365
|
}
|
|
444
|
-
|
|
366
|
+
}
|
|
367
|
+
return Object.fromEntries(Object.entries(jsonWithUndefined).filter(([, value]) => value !== void 0));
|
|
368
|
+
}
|
|
369
|
+
serialize(isPublic = true) {
|
|
370
|
+
const ctor = this.constructor;
|
|
371
|
+
return ctor.serialize(this, isPublic);
|
|
445
372
|
}
|
|
446
373
|
}
|
|
447
374
|
// Annotate the CommonJS export names for ESM import in node:
|
|
448
375
|
0 && (module.exports = {
|
|
449
|
-
Error0
|
|
376
|
+
Error0,
|
|
377
|
+
ExtensionError0
|
|
450
378
|
});
|
|
451
379
|
//# sourceMappingURL=index.cjs.map
|