@wener/utils 1.1.53 → 1.1.54
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/lib/errors/Errors.js +201 -2
- package/lib/index.js +9 -8
- package/lib/io/ArrayBuffers.js +559 -2
- package/lib/langs/parseDate.js +20 -0
- package/package.json +2 -2
- package/src/errors/Errors.ts +106 -1
- package/src/index.ts +10 -8
- package/src/io/ArrayBuffers.ts +676 -1
- package/src/langs/parseDate.ts +13 -0
- package/tsconfig.json +4 -13
- package/lib/errors/Errors.mod.js +0 -206
- package/lib/io/ArrayBuffers.mod.js +0 -531
- package/src/errors/Errors.mod.ts +0 -104
- package/src/io/ArrayBuffers.mod.ts +0 -670
package/lib/errors/Errors.js
CHANGED
|
@@ -1,2 +1,201 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
obj[key] = value;
|
|
12
|
+
}
|
|
13
|
+
return obj;
|
|
14
|
+
}
|
|
15
|
+
function _instanceof(left, right) {
|
|
16
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
17
|
+
return !!right[Symbol.hasInstance](left);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
return left instanceof right;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function _object_spread(target) {
|
|
24
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
25
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
26
|
+
var ownKeys = Object.keys(source);
|
|
27
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
28
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
|
|
29
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
ownKeys.forEach(function (key) {
|
|
33
|
+
_define_property(target, key, source[key]);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return target;
|
|
37
|
+
}
|
|
38
|
+
function ownKeys(object, enumerableOnly) {
|
|
39
|
+
var keys = Object.keys(object);
|
|
40
|
+
if (Object.getOwnPropertySymbols) {
|
|
41
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
42
|
+
if (enumerableOnly) {
|
|
43
|
+
symbols = symbols.filter(function (sym) {
|
|
44
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
keys.push.apply(keys, symbols);
|
|
48
|
+
}
|
|
49
|
+
return keys;
|
|
50
|
+
}
|
|
51
|
+
function _object_spread_props(target, source) {
|
|
52
|
+
source = source != null ? source : {};
|
|
53
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
54
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
ownKeys(Object(source)).forEach(function (key) {
|
|
58
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return target;
|
|
62
|
+
}
|
|
63
|
+
import { DetailError, DetailHolder } from "./DetailError.js";
|
|
64
|
+
(function (Errors) {
|
|
65
|
+
Errors.BadRequest = create({
|
|
66
|
+
status: 400
|
|
67
|
+
});
|
|
68
|
+
Errors.Unauthorized = create({
|
|
69
|
+
status: 403
|
|
70
|
+
});
|
|
71
|
+
Errors.Forbidden = create({
|
|
72
|
+
status: 403
|
|
73
|
+
});
|
|
74
|
+
Errors.NotFound = create({
|
|
75
|
+
status: 404
|
|
76
|
+
});
|
|
77
|
+
Errors.InternalServerError = create({
|
|
78
|
+
status: 500
|
|
79
|
+
});
|
|
80
|
+
Errors.NotImplemented = create({
|
|
81
|
+
status: 501
|
|
82
|
+
});
|
|
83
|
+
Errors.BadGateway = create({
|
|
84
|
+
status: 502,
|
|
85
|
+
message: "Bad Gateway"
|
|
86
|
+
});
|
|
87
|
+
Errors.ServiceUnavailable = create({
|
|
88
|
+
status: 503
|
|
89
|
+
});
|
|
90
|
+
Errors.IllegalState = create({
|
|
91
|
+
status: 500,
|
|
92
|
+
message: "Illegal State"
|
|
93
|
+
});
|
|
94
|
+
Errors.UnsupportedOperation = create({
|
|
95
|
+
status: 500,
|
|
96
|
+
message: "Unsupported Operation"
|
|
97
|
+
});
|
|
98
|
+
Errors.IllegalArgument = create({
|
|
99
|
+
status: 400,
|
|
100
|
+
message: "Illegal Argument"
|
|
101
|
+
});
|
|
102
|
+
Errors.InvalidType = create({
|
|
103
|
+
status: 400,
|
|
104
|
+
message: "Invalid Type"
|
|
105
|
+
});
|
|
106
|
+
Errors.resolvers = [];
|
|
107
|
+
function create(init) {
|
|
108
|
+
return new DetailHolder(init);
|
|
109
|
+
}
|
|
110
|
+
Errors.create = create;
|
|
111
|
+
function ok(res, o) {
|
|
112
|
+
if (res.ok) {
|
|
113
|
+
return res;
|
|
114
|
+
}
|
|
115
|
+
throw create(_object_spread_props(_object_spread({
|
|
116
|
+
description: res.statusText,
|
|
117
|
+
status: res.status
|
|
118
|
+
}, o), {
|
|
119
|
+
metadata: _object_spread_props(_object_spread({}, o === null || o === void 0 ? void 0 : o.metadata), {
|
|
120
|
+
response: res
|
|
121
|
+
})
|
|
122
|
+
})).asError();
|
|
123
|
+
}
|
|
124
|
+
Errors.ok = ok;
|
|
125
|
+
function resolve(e) {
|
|
126
|
+
if (_instanceof(e, DetailHolder)) {
|
|
127
|
+
return e;
|
|
128
|
+
}
|
|
129
|
+
if (_instanceof(e, DetailError)) {
|
|
130
|
+
return e.detail;
|
|
131
|
+
}
|
|
132
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
133
|
+
try {
|
|
134
|
+
for (var _iterator = Errors.resolvers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
135
|
+
var resolver = _step.value;
|
|
136
|
+
var r = resolver(e);
|
|
137
|
+
if (r) {
|
|
138
|
+
return r;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
catch (err) {
|
|
143
|
+
_didIteratorError = true;
|
|
144
|
+
_iteratorError = err;
|
|
145
|
+
}
|
|
146
|
+
finally {
|
|
147
|
+
try {
|
|
148
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
149
|
+
_iterator.return();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
finally {
|
|
153
|
+
if (_didIteratorError) {
|
|
154
|
+
throw _iteratorError;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (isError(e)) {
|
|
159
|
+
var message = e.message, code = e.code, status = e.status;
|
|
160
|
+
// can get status from NestJS HttpException
|
|
161
|
+
return new DetailHolder({
|
|
162
|
+
message: message,
|
|
163
|
+
status: parseInt(status) || 500,
|
|
164
|
+
code: code,
|
|
165
|
+
cause: e
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
return new DetailHolder({
|
|
169
|
+
message: e.message,
|
|
170
|
+
status: 500,
|
|
171
|
+
cause: e
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
Errors.resolve = resolve;
|
|
175
|
+
function isError(e) {
|
|
176
|
+
if ("isError" in Error) {
|
|
177
|
+
// will handle cross-realm
|
|
178
|
+
return Error.isError(e);
|
|
179
|
+
}
|
|
180
|
+
return _instanceof(e, Error);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Check if the given value is an Error
|
|
184
|
+
* @see https://github.com/tc39/proposal-is-error
|
|
185
|
+
*/ Errors.isError = isError;
|
|
186
|
+
function isAbort(e) {
|
|
187
|
+
if (!isError(e)) {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
return e.name === "AbortError";
|
|
191
|
+
}
|
|
192
|
+
Errors.isAbort = isAbort;
|
|
193
|
+
function isTimeout(e) {
|
|
194
|
+
if (!isError(e)) {
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
return e.name === "TimeoutError" || e.name === "Timeout";
|
|
198
|
+
}
|
|
199
|
+
Errors.isTimeout = isTimeout;
|
|
200
|
+
})(Errors || (Errors = {}));
|
|
201
|
+
export var Errors;
|
package/lib/index.js
CHANGED
|
@@ -21,23 +21,24 @@ export var sleep = Promises.sleep;
|
|
|
21
21
|
export var isPromise = Promises.isPromise;
|
|
22
22
|
export { timeout, TimeoutError } from "./asyncs/timeout.js";
|
|
23
23
|
// langs
|
|
24
|
-
export {
|
|
25
|
-
export { shallowEqual } from "./langs/shallowEqual.js";
|
|
24
|
+
export { classOf } from "./langs/classOf.js";
|
|
26
25
|
export { deepEqual } from "./langs/deepEqual.js";
|
|
27
26
|
export { deepFreeze } from "./langs/deepFreeze.js";
|
|
28
|
-
export {
|
|
29
|
-
export {
|
|
27
|
+
export { getGlobalStates, setGlobalStates } from "./langs/getGlobalStates.js";
|
|
28
|
+
export { getObjectId } from "./langs/getObjectId.js";
|
|
29
|
+
export { ifPresent } from "./langs/ifPresent.js";
|
|
30
30
|
export { isClass } from "./langs/isClass.js";
|
|
31
31
|
export { isDefined } from "./langs/isDefined.js";
|
|
32
32
|
export { isEmptyObject } from "./langs/isEmptyObject.js";
|
|
33
|
+
export { isNil } from "./langs/isNil.js";
|
|
33
34
|
export { isPlainObject } from "./langs/isPlainObject.js";
|
|
34
|
-
export { ifPresent } from "./langs/ifPresent.js";
|
|
35
|
-
export { parseBoolean } from "./langs/parseBoolean.js";
|
|
36
35
|
export { maybeFunction } from "./langs/MaybeFunction.js";
|
|
37
36
|
export { memoize } from "./langs/memoize.js";
|
|
38
37
|
export { mixin } from "./langs/mixin.js";
|
|
39
|
-
export {
|
|
40
|
-
export {
|
|
38
|
+
export { parseBoolean } from "./langs/parseBoolean.js";
|
|
39
|
+
export { parseDate } from "./langs/parseDate.js";
|
|
40
|
+
export { shallowClone } from "./langs/shallowClone.js";
|
|
41
|
+
export { shallowEqual } from "./langs/shallowEqual.js";
|
|
41
42
|
export { AsyncCloser } from "./langs/AsyncCloser.js";
|
|
42
43
|
export { Closer } from "./langs/Closer.js";
|
|
43
44
|
export { isUUID } from "./validations/isUUID.js";
|