@nr1e/commons 0.0.3-alpha.0 → 0.0.3-alpha.10
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/LICENSE +1 -1
- package/dist/bitsnbytes/b64.d.ts +39 -0
- package/dist/bitsnbytes/b64.js +130 -0
- package/dist/bitsnbytes/b64.js.map +1 -0
- package/dist/bitsnbytes/index.d.ts +1 -0
- package/dist/bitsnbytes/index.js +2 -0
- package/dist/bitsnbytes/index.js.map +1 -0
- package/{errors → dist/errors}/errors.d.ts +73 -36
- package/dist/errors/errors.js +230 -0
- package/dist/errors/errors.js.map +1 -0
- package/dist/errors/index.js +2 -0
- package/dist/errors/index.js.map +1 -0
- package/{http → dist/http}/http-method.js +2 -5
- package/dist/http/http-method.js.map +1 -0
- package/{http → dist/http}/http-status-code.js +2 -5
- package/dist/http/http-status-code.js.map +1 -0
- package/dist/http/index.js +3 -0
- package/dist/http/index.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/{lang → dist/lang}/index.d.ts +1 -0
- package/dist/lang/index.js +3 -0
- package/dist/lang/index.js.map +1 -0
- package/dist/lang/sleep.d.ts +6 -0
- package/dist/lang/sleep.js +9 -0
- package/dist/lang/sleep.js.map +1 -0
- package/dist/lang/type-functions.js +10 -0
- package/dist/lang/type-functions.js.map +1 -0
- package/dist/validator/index.js +2 -0
- package/dist/validator/index.js.map +1 -0
- package/{validator → dist/validator}/validators.js +37 -64
- package/dist/validator/validators.js.map +1 -0
- package/package.json +12 -6
- package/.prettierrc.js +0 -3
- package/errors/errors.js +0 -238
- package/errors/errors.js.map +0 -1
- package/errors/index.js +0 -18
- package/errors/index.js.map +0 -1
- package/http/http-method.js.map +0 -1
- package/http/http-status-code.js.map +0 -1
- package/http/index.js +0 -19
- package/http/index.js.map +0 -1
- package/index.d.ts +0 -4
- package/index.js +0 -8
- package/index.js.map +0 -1
- package/jest.config.js +0 -8
- package/lang/index.js +0 -18
- package/lang/index.js.map +0 -1
- package/lang/type-functions.js +0 -16
- package/lang/type-functions.js.map +0 -1
- package/validator/index.js +0 -18
- package/validator/index.js.map +0 -1
- package/validator/validators.js.map +0 -1
- /package/{errors → dist/errors}/index.d.ts +0 -0
- /package/{http → dist/http}/http-method.d.ts +0 -0
- /package/{http → dist/http}/http-status-code.d.ts +0 -0
- /package/{http → dist/http}/index.d.ts +0 -0
- /package/{lang → dist/lang}/type-functions.d.ts +0 -0
- /package/{validator → dist/validator}/index.d.ts +0 -0
- /package/{validator → dist/validator}/validators.d.ts +0 -0
package/LICENSE
CHANGED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export declare const BASE64_CHARS: Uint8Array;
|
|
2
|
+
export declare const URL_MODIFIED_BASE64_CHARS: Uint8Array;
|
|
3
|
+
export declare const YUI_BASE64_CHARS: Uint8Array;
|
|
4
|
+
export type Base64CharSet = 'b64' | 'url' | 'yui';
|
|
5
|
+
export interface Base64Options {
|
|
6
|
+
readonly fromIndex?: number;
|
|
7
|
+
readonly toIndex?: number;
|
|
8
|
+
readonly b64chars?: Uint8Array | Base64CharSet;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Returns a base64 character set and validates one if passed in.
|
|
12
|
+
*
|
|
13
|
+
* @param b64chars a base64 character set
|
|
14
|
+
*/
|
|
15
|
+
export declare function b64Charset(b64chars?: Uint8Array | Base64CharSet): Uint8Array;
|
|
16
|
+
/**
|
|
17
|
+
* Base64 encodes a series of bytes.
|
|
18
|
+
*
|
|
19
|
+
* @param buf Bytes to encode
|
|
20
|
+
* @param opts Encoding options
|
|
21
|
+
* @return a base64 string
|
|
22
|
+
*/
|
|
23
|
+
export declare function tob64(buf: Uint8Array, opts?: Base64Options): Uint8Array;
|
|
24
|
+
/**
|
|
25
|
+
* Base64 encodes a series of bytes to a string.
|
|
26
|
+
*
|
|
27
|
+
* @param buf Bytes to encode
|
|
28
|
+
* @param opts Encoding options
|
|
29
|
+
* @return a base64 string
|
|
30
|
+
*/
|
|
31
|
+
export declare function tob64s(buf: Uint8Array, opts?: Base64Options): string;
|
|
32
|
+
/**
|
|
33
|
+
* Base64 encodes a string to a string.
|
|
34
|
+
*
|
|
35
|
+
* @param str String to encode
|
|
36
|
+
* @param opts Encoding options
|
|
37
|
+
* @return a base64 string
|
|
38
|
+
*/
|
|
39
|
+
export declare function stob64s(str: string, opts?: Base64Options): string;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { IllegalArgumentError } from '../errors';
|
|
2
|
+
// eslint-disable-next-line node/no-unsupported-features/node-builtins
|
|
3
|
+
const encoder = new TextEncoder();
|
|
4
|
+
// eslint-disable-next-line node/no-unsupported-features/node-builtins
|
|
5
|
+
const decoder = new TextDecoder();
|
|
6
|
+
export const BASE64_CHARS = new Uint8Array([
|
|
7
|
+
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d,
|
|
8
|
+
0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a,
|
|
9
|
+
0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d,
|
|
10
|
+
0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a,
|
|
11
|
+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2b, 0x2f, 0x3d,
|
|
12
|
+
]);
|
|
13
|
+
// 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
|
|
14
|
+
// 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
|
15
|
+
// 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
|
|
16
|
+
// 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
|
17
|
+
// '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', '='
|
|
18
|
+
export const URL_MODIFIED_BASE64_CHARS = new Uint8Array([
|
|
19
|
+
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d,
|
|
20
|
+
0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a,
|
|
21
|
+
0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d,
|
|
22
|
+
0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a,
|
|
23
|
+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2d, 0x5f,
|
|
24
|
+
]);
|
|
25
|
+
// 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
|
|
26
|
+
// 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
|
27
|
+
// 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
|
|
28
|
+
// 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
|
29
|
+
// '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_',
|
|
30
|
+
export const YUI_BASE64_CHARS = new Uint8Array([
|
|
31
|
+
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d,
|
|
32
|
+
0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a,
|
|
33
|
+
0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d,
|
|
34
|
+
0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a,
|
|
35
|
+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2e, 0x5f, 0x2d,
|
|
36
|
+
]);
|
|
37
|
+
/**
|
|
38
|
+
* Returns a base64 character set and validates one if passed in.
|
|
39
|
+
*
|
|
40
|
+
* @param b64chars a base64 character set
|
|
41
|
+
*/
|
|
42
|
+
export function b64Charset(b64chars) {
|
|
43
|
+
if (b64chars === undefined || b64chars === null) {
|
|
44
|
+
return BASE64_CHARS;
|
|
45
|
+
}
|
|
46
|
+
if (b64chars instanceof Uint8Array) {
|
|
47
|
+
if (b64chars.length !== 65 && b64chars.length !== 64) {
|
|
48
|
+
throw new IllegalArgumentError('b64chars', 'Base 64 character sets must be 64 or 65 characters.');
|
|
49
|
+
}
|
|
50
|
+
return b64chars;
|
|
51
|
+
}
|
|
52
|
+
switch (b64chars) {
|
|
53
|
+
case 'b64':
|
|
54
|
+
return BASE64_CHARS;
|
|
55
|
+
case 'url':
|
|
56
|
+
return URL_MODIFIED_BASE64_CHARS;
|
|
57
|
+
case 'yui':
|
|
58
|
+
return YUI_BASE64_CHARS;
|
|
59
|
+
default:
|
|
60
|
+
throw new IllegalArgumentError('b64chars', `Invalid base64 character set '${b64chars}'`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Base64 encodes a series of bytes.
|
|
65
|
+
*
|
|
66
|
+
* @param buf Bytes to encode
|
|
67
|
+
* @param opts Encoding options
|
|
68
|
+
* @return a base64 string
|
|
69
|
+
*/
|
|
70
|
+
export function tob64(buf, opts) {
|
|
71
|
+
var _a, _b;
|
|
72
|
+
const b64chars = b64Charset(opts === null || opts === void 0 ? void 0 : opts.b64chars);
|
|
73
|
+
const toIndex = (_a = opts === null || opts === void 0 ? void 0 : opts.toIndex) !== null && _a !== void 0 ? _a : buf.length;
|
|
74
|
+
const fromIndex = (_b = opts === null || opts === void 0 ? void 0 : opts.fromIndex) !== null && _b !== void 0 ? _b : 0;
|
|
75
|
+
// every 3 bytes is 4 characters in padded base64 (6 bits per char)
|
|
76
|
+
const num = toIndex - fromIndex;
|
|
77
|
+
const numc = b64chars.length === 65
|
|
78
|
+
? ((num + 2 - ((num + 2) % 3)) / 3) * 4 // padded
|
|
79
|
+
: (num * 8) / 6 + ((num * 8) % 6 !== 0 ? 1 : 0); // not padded
|
|
80
|
+
const b64 = new Uint8Array(numc);
|
|
81
|
+
let n = 0;
|
|
82
|
+
for (let i = 0; i < toIndex; i += 3) {
|
|
83
|
+
const v = ((buf[i] & 0xff) << 16) |
|
|
84
|
+
(i + 1 < toIndex ? (buf[i + 1] & 0xff) << 8 : 0) |
|
|
85
|
+
(i + 2 < toIndex ? buf[i + 2] & 0xff : 0);
|
|
86
|
+
b64[n++] = b64chars[(v >>> 18) & 0x3f];
|
|
87
|
+
b64[n++] = b64chars[(v >>> 12) & 0x3f];
|
|
88
|
+
switch (toIndex - i // calculate bytes remaining to be processed
|
|
89
|
+
) {
|
|
90
|
+
case 1: // 0 bytes left to process
|
|
91
|
+
if (b64chars.length === 65) {
|
|
92
|
+
b64[n++] = b64chars[64];
|
|
93
|
+
b64[n++] = b64chars[64];
|
|
94
|
+
}
|
|
95
|
+
break;
|
|
96
|
+
case 2: // 1 byte left to process
|
|
97
|
+
b64[n++] = b64chars[(v >>> 6) & 0x3f];
|
|
98
|
+
if (b64chars.length === 65) {
|
|
99
|
+
b64[n++] = b64chars[64];
|
|
100
|
+
}
|
|
101
|
+
break;
|
|
102
|
+
default:
|
|
103
|
+
b64[n++] = b64chars[(v >>> 6) & 0x3f];
|
|
104
|
+
b64[n++] = b64chars[v & 0x3f];
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return b64;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Base64 encodes a series of bytes to a string.
|
|
112
|
+
*
|
|
113
|
+
* @param buf Bytes to encode
|
|
114
|
+
* @param opts Encoding options
|
|
115
|
+
* @return a base64 string
|
|
116
|
+
*/
|
|
117
|
+
export function tob64s(buf, opts) {
|
|
118
|
+
return decoder.decode(tob64(buf, opts));
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Base64 encodes a string to a string.
|
|
122
|
+
*
|
|
123
|
+
* @param str String to encode
|
|
124
|
+
* @param opts Encoding options
|
|
125
|
+
* @return a base64 string
|
|
126
|
+
*/
|
|
127
|
+
export function stob64s(str, opts) {
|
|
128
|
+
return tob64s(encoder.encode(str), opts);
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=b64.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"b64.js","sourceRoot":"./src/","sources":["bitsnbytes/b64.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,oBAAoB,EAAC,MAAM,WAAW,CAAC;AAE/C,sEAAsE;AACtE,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAClC,sEAAsE;AACtE,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAElC,MAAM,CAAC,MAAM,YAAY,GAAe,IAAI,UAAU,CAAC;IACrD,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;IAC5E,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAA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R,KAAK,CAAC,EAAE,yBAAyB;gBAC/B,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;gBACtC,IAAI,QAAQ,CAAC,MAAM,KAAK,EAAE,EAAE;oBAC1B,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;iBACzB;gBACD,MAAM;YACR;gBACE,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;gBACtC,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;gBAC9B,MAAM;SACT;KACF;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,MAAM,CAAC,GAAe,EAAE,IAAoB;IAC1D,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;AAC1C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,OAAO,CAAC,GAAW,EAAE,IAAoB;IACvD,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './b64';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"./src/","sources":["bitsnbytes/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC"}
|
|
@@ -1,51 +1,64 @@
|
|
|
1
1
|
import { HttpStatusCode } from '../http';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
2
|
+
export { isError } from '../lang';
|
|
3
|
+
/**
|
|
4
|
+
* An extended version of Error that includes an HttpStatusCode.
|
|
5
|
+
* This can be useful in middleware error handlers to determine http status codes to return to the client.
|
|
6
|
+
*/
|
|
8
7
|
export interface HttpError extends Error {
|
|
8
|
+
/**
|
|
9
|
+
* The HTTP status code.
|
|
10
|
+
*/
|
|
9
11
|
statusCode: HttpStatusCode | number;
|
|
10
12
|
}
|
|
11
13
|
/**
|
|
12
14
|
* Checks if the given parameter is an HttpError.
|
|
13
15
|
*
|
|
14
|
-
* @param e
|
|
16
|
+
* @param e The parameter to check
|
|
17
|
+
*/
|
|
18
|
+
export declare function isHttpError(e?: unknown): e is HttpError;
|
|
19
|
+
/**
|
|
20
|
+
* Thrown when a resource cannot be found.
|
|
15
21
|
*/
|
|
16
|
-
export declare
|
|
22
|
+
export declare class NotFoundError extends Error implements HttpError {
|
|
23
|
+
readonly statusCode = HttpStatusCode.NOT_FOUND;
|
|
24
|
+
/**
|
|
25
|
+
* The max-age value to set in the Cache-Control header if used in a middleware.
|
|
26
|
+
*/
|
|
27
|
+
readonly maxAge?: number;
|
|
28
|
+
constructor(message?: string, maxAge?: number);
|
|
29
|
+
}
|
|
17
30
|
/**
|
|
18
31
|
* Checks if the given parameter is a NotFoundError.
|
|
19
32
|
*
|
|
20
|
-
* @param e
|
|
33
|
+
* @param e The parameter to check
|
|
21
34
|
*/
|
|
22
|
-
export declare function isNotFoundError(e?:
|
|
35
|
+
export declare function isNotFoundError(e?: unknown): e is NotFoundError;
|
|
23
36
|
/**
|
|
24
|
-
* Thrown when a
|
|
37
|
+
* Thrown when a request is missing authentication credentials.
|
|
25
38
|
*/
|
|
26
|
-
export declare class
|
|
27
|
-
readonly statusCode = HttpStatusCode.
|
|
39
|
+
export declare class UnauthorizedError extends Error implements HttpError {
|
|
40
|
+
readonly statusCode = HttpStatusCode.UNAUTHORIZED;
|
|
28
41
|
constructor(message?: string);
|
|
29
42
|
}
|
|
30
43
|
/**
|
|
31
|
-
* Checks if the given parameter is a
|
|
44
|
+
* Checks if the given parameter is a UnauthorizedError.
|
|
32
45
|
*
|
|
33
|
-
* @param e
|
|
46
|
+
* @param e The parameter to check
|
|
34
47
|
*/
|
|
35
|
-
export declare function
|
|
48
|
+
export declare function isUnauthorizedError(e?: unknown): e is UnauthorizedError;
|
|
36
49
|
/**
|
|
37
|
-
* Thrown when
|
|
50
|
+
* Thrown when credentials are present, but the requested operations is not allowed.
|
|
38
51
|
*/
|
|
39
52
|
export declare class ForbiddenError extends Error implements HttpError {
|
|
40
53
|
readonly statusCode = HttpStatusCode.FORBIDDEN;
|
|
41
54
|
constructor(message?: string);
|
|
42
55
|
}
|
|
43
56
|
/**
|
|
44
|
-
* Checks if the given
|
|
57
|
+
* Checks if the given parameter is a ForbiddenError.
|
|
45
58
|
*
|
|
46
|
-
* @param e
|
|
59
|
+
* @param e The parameter to check
|
|
47
60
|
*/
|
|
48
|
-
export declare function
|
|
61
|
+
export declare function isForbiddenError(e?: unknown): e is ForbiddenError;
|
|
49
62
|
/**
|
|
50
63
|
* Thrown when a validation error occurs.
|
|
51
64
|
*/
|
|
@@ -54,11 +67,11 @@ export declare class ValidationError extends Error implements HttpError {
|
|
|
54
67
|
constructor(message?: string);
|
|
55
68
|
}
|
|
56
69
|
/**
|
|
57
|
-
* Checks if the given
|
|
70
|
+
* Checks if the given variable is a ValidationError.
|
|
58
71
|
*
|
|
59
|
-
* @param e
|
|
72
|
+
* @param e The variable to check
|
|
60
73
|
*/
|
|
61
|
-
export declare function
|
|
74
|
+
export declare function isValidationError(e?: unknown): e is ValidationError;
|
|
62
75
|
/**
|
|
63
76
|
* Thrown when a bad request is made.
|
|
64
77
|
*/
|
|
@@ -67,11 +80,11 @@ export declare class BadRequestError extends Error implements HttpError {
|
|
|
67
80
|
constructor(message?: string);
|
|
68
81
|
}
|
|
69
82
|
/**
|
|
70
|
-
* Checks if the given parameter is a
|
|
83
|
+
* Checks if the given parameter is a BadRequestError.
|
|
71
84
|
*
|
|
72
|
-
* @param e
|
|
85
|
+
* @param e The parameter to check
|
|
73
86
|
*/
|
|
74
|
-
export declare function
|
|
87
|
+
export declare function isBadRequestError(e?: unknown): e is BadRequestError;
|
|
75
88
|
/**
|
|
76
89
|
* Throws when an internal server error occurs.
|
|
77
90
|
*/
|
|
@@ -80,11 +93,11 @@ export declare class InternalServerError extends Error implements HttpError {
|
|
|
80
93
|
constructor(message?: string);
|
|
81
94
|
}
|
|
82
95
|
/**
|
|
83
|
-
* Checks if the given parameter is a
|
|
96
|
+
* Checks if the given parameter is a InternalServerError.
|
|
84
97
|
*
|
|
85
|
-
* @param e
|
|
98
|
+
* @param e The parameter to check
|
|
86
99
|
*/
|
|
87
|
-
export declare function
|
|
100
|
+
export declare function isInternalServerError(e?: unknown): e is InternalServerError;
|
|
88
101
|
/**
|
|
89
102
|
* Thrown when a conflict occurs.
|
|
90
103
|
*/
|
|
@@ -93,11 +106,11 @@ export declare class ConflictError extends Error implements HttpError {
|
|
|
93
106
|
constructor(message?: string);
|
|
94
107
|
}
|
|
95
108
|
/**
|
|
96
|
-
* Checks if the given parameter is a
|
|
109
|
+
* Checks if the given parameter is a ConflictError.
|
|
97
110
|
*
|
|
98
|
-
* @param e
|
|
111
|
+
* @param e The parameter to check
|
|
99
112
|
*/
|
|
100
|
-
export declare function
|
|
113
|
+
export declare function isConflictError(e?: unknown): e is ConflictError;
|
|
101
114
|
/**
|
|
102
115
|
* Thrown when a unsupported media type is used.
|
|
103
116
|
*/
|
|
@@ -106,11 +119,11 @@ export declare class UnsupportedMediaTypeError extends Error implements HttpErro
|
|
|
106
119
|
constructor(message?: string);
|
|
107
120
|
}
|
|
108
121
|
/**
|
|
109
|
-
* Checks if the given parameter is a
|
|
122
|
+
* Checks if the given parameter is a UnsupportedMediaTypeError.
|
|
110
123
|
*
|
|
111
|
-
* @param e
|
|
124
|
+
* @param e The parameter to check
|
|
112
125
|
*/
|
|
113
|
-
export declare function
|
|
126
|
+
export declare function isUnsupportedMediaTypeError(e?: unknown): e is UnsupportedMediaTypeError;
|
|
114
127
|
/**
|
|
115
128
|
* Thrown when a requested operation is not implemented.
|
|
116
129
|
*/
|
|
@@ -119,5 +132,29 @@ export declare class NotImplementedError extends Error implements HttpError {
|
|
|
119
132
|
readonly expose = true;
|
|
120
133
|
constructor(message?: string);
|
|
121
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Checks if the given parameter is a NotImplementedError.
|
|
137
|
+
*
|
|
138
|
+
* @param e The parameter to check
|
|
139
|
+
*/
|
|
140
|
+
export declare function isNotImplementedError(e?: unknown): e is NotImplementedError;
|
|
141
|
+
/**
|
|
142
|
+
* Thrown when an illegal argument is passed to a function.
|
|
143
|
+
*/
|
|
144
|
+
export declare class IllegalArgumentError extends Error {
|
|
145
|
+
readonly argName: string;
|
|
146
|
+
constructor(argName: string, message?: string);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Checks if the given parameter is a IllegalArgumentError.
|
|
150
|
+
*
|
|
151
|
+
* @param e The parameter to check
|
|
152
|
+
*/
|
|
153
|
+
export declare function isIllegalArgumentError(e?: unknown): e is IllegalArgumentError;
|
|
154
|
+
/**
|
|
155
|
+
* Converts the given parameter to an HttpError.
|
|
156
|
+
*
|
|
157
|
+
* @param code The HTTP status code
|
|
158
|
+
* @param message The error message
|
|
159
|
+
*/
|
|
122
160
|
export declare function toError(code: number | HttpStatusCode, message?: string): Error;
|
|
123
|
-
export {};
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { HttpStatusCode } from '../http';
|
|
2
|
+
import { isError, isObject } from '../lang';
|
|
3
|
+
export { isError } from '../lang';
|
|
4
|
+
/**
|
|
5
|
+
* Checks if the given parameter is an HttpError.
|
|
6
|
+
*
|
|
7
|
+
* @param e The parameter to check
|
|
8
|
+
*/
|
|
9
|
+
export function isHttpError(e) {
|
|
10
|
+
return isObject(e) && !!(e && e.stack && e.statusCode && e.message && e.name);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Thrown when a resource cannot be found.
|
|
14
|
+
*/
|
|
15
|
+
export class NotFoundError extends Error {
|
|
16
|
+
constructor(message, maxAge) {
|
|
17
|
+
message = message !== null && message !== void 0 ? message : 'Not found';
|
|
18
|
+
super(message);
|
|
19
|
+
this.statusCode = HttpStatusCode.NOT_FOUND;
|
|
20
|
+
this.name = 'NotFoundError';
|
|
21
|
+
this.maxAge = maxAge;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Checks if the given parameter is a NotFoundError.
|
|
26
|
+
*
|
|
27
|
+
* @param e The parameter to check
|
|
28
|
+
*/
|
|
29
|
+
export function isNotFoundError(e) {
|
|
30
|
+
return isHttpError(e) && e.name === 'NotFoundError';
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Thrown when a request is missing authentication credentials.
|
|
34
|
+
*/
|
|
35
|
+
export class UnauthorizedError extends Error {
|
|
36
|
+
constructor(message) {
|
|
37
|
+
message = message !== null && message !== void 0 ? message : 'Unauthorized';
|
|
38
|
+
super(message);
|
|
39
|
+
this.statusCode = HttpStatusCode.UNAUTHORIZED;
|
|
40
|
+
this.name = 'UnauthorizedError';
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Checks if the given parameter is a UnauthorizedError.
|
|
45
|
+
*
|
|
46
|
+
* @param e The parameter to check
|
|
47
|
+
*/
|
|
48
|
+
export function isUnauthorizedError(e) {
|
|
49
|
+
return isHttpError(e) && e.name === 'UnauthorizedError';
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Thrown when credentials are present, but the requested operations is not allowed.
|
|
53
|
+
*/
|
|
54
|
+
export class ForbiddenError extends Error {
|
|
55
|
+
constructor(message) {
|
|
56
|
+
message = message !== null && message !== void 0 ? message : 'Forbidden';
|
|
57
|
+
super(message);
|
|
58
|
+
this.statusCode = HttpStatusCode.FORBIDDEN;
|
|
59
|
+
this.name = 'ForbiddenError';
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Checks if the given parameter is a ForbiddenError.
|
|
64
|
+
*
|
|
65
|
+
* @param e The parameter to check
|
|
66
|
+
*/
|
|
67
|
+
export function isForbiddenError(e) {
|
|
68
|
+
return isHttpError(e) && e.name === 'ForbiddenError';
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Thrown when a validation error occurs.
|
|
72
|
+
*/
|
|
73
|
+
export class ValidationError extends Error {
|
|
74
|
+
constructor(message) {
|
|
75
|
+
message = message !== null && message !== void 0 ? message : 'Validation error';
|
|
76
|
+
super(message);
|
|
77
|
+
this.statusCode = HttpStatusCode.BAD_REQUEST;
|
|
78
|
+
this.name = 'ValidationError';
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Checks if the given variable is a ValidationError.
|
|
83
|
+
*
|
|
84
|
+
* @param e The variable to check
|
|
85
|
+
*/
|
|
86
|
+
export function isValidationError(e) {
|
|
87
|
+
return isHttpError(e) && e.name === 'ValidationError';
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Thrown when a bad request is made.
|
|
91
|
+
*/
|
|
92
|
+
export class BadRequestError extends Error {
|
|
93
|
+
constructor(message) {
|
|
94
|
+
message = message !== null && message !== void 0 ? message : 'Bad request';
|
|
95
|
+
super(message !== null && message !== void 0 ? message : 'Bad request');
|
|
96
|
+
this.statusCode = HttpStatusCode.BAD_REQUEST;
|
|
97
|
+
this.name = 'BadRequestError';
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Checks if the given parameter is a BadRequestError.
|
|
102
|
+
*
|
|
103
|
+
* @param e The parameter to check
|
|
104
|
+
*/
|
|
105
|
+
export function isBadRequestError(e) {
|
|
106
|
+
return isHttpError(e) && e.name === 'BadRequestError';
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Throws when an internal server error occurs.
|
|
110
|
+
*/
|
|
111
|
+
export class InternalServerError extends Error {
|
|
112
|
+
constructor(message) {
|
|
113
|
+
message = message !== null && message !== void 0 ? message : 'Internal server error';
|
|
114
|
+
super(message);
|
|
115
|
+
this.statusCode = HttpStatusCode.INTERNAL_SERVER_ERROR;
|
|
116
|
+
this.name = 'InternalServerError';
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Checks if the given parameter is a InternalServerError.
|
|
121
|
+
*
|
|
122
|
+
* @param e The parameter to check
|
|
123
|
+
*/
|
|
124
|
+
export function isInternalServerError(e) {
|
|
125
|
+
return isHttpError(e) && e.name === 'InternalServerError';
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Thrown when a conflict occurs.
|
|
129
|
+
*/
|
|
130
|
+
export class ConflictError extends Error {
|
|
131
|
+
constructor(message) {
|
|
132
|
+
message = message !== null && message !== void 0 ? message : 'Conflict';
|
|
133
|
+
super(message);
|
|
134
|
+
this.statusCode = HttpStatusCode.CONFLICT;
|
|
135
|
+
this.name = 'ConflictError';
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Checks if the given parameter is a ConflictError.
|
|
140
|
+
*
|
|
141
|
+
* @param e The parameter to check
|
|
142
|
+
*/
|
|
143
|
+
export function isConflictError(e) {
|
|
144
|
+
return isHttpError(e) && e.name === 'ConflictError';
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Thrown when a unsupported media type is used.
|
|
148
|
+
*/
|
|
149
|
+
export class UnsupportedMediaTypeError extends Error {
|
|
150
|
+
constructor(message) {
|
|
151
|
+
message = message !== null && message !== void 0 ? message : 'Unsupported media type';
|
|
152
|
+
super(message);
|
|
153
|
+
this.statusCode = HttpStatusCode.UNSUPPORTED_MEDIA_TYPE;
|
|
154
|
+
this.name = 'UnsupportedMediaTypeError';
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Checks if the given parameter is a UnsupportedMediaTypeError.
|
|
159
|
+
*
|
|
160
|
+
* @param e The parameter to check
|
|
161
|
+
*/
|
|
162
|
+
export function isUnsupportedMediaTypeError(e) {
|
|
163
|
+
return isHttpError(e) && e.name === 'UnsupportedMediaTypeError';
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Thrown when a requested operation is not implemented.
|
|
167
|
+
*/
|
|
168
|
+
export class NotImplementedError extends Error {
|
|
169
|
+
constructor(message) {
|
|
170
|
+
message = message !== null && message !== void 0 ? message : 'Not implemented';
|
|
171
|
+
super(message);
|
|
172
|
+
this.statusCode = HttpStatusCode.NOT_IMPLEMENTED;
|
|
173
|
+
this.expose = true;
|
|
174
|
+
this.name = 'NotImplementedError';
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Checks if the given parameter is a NotImplementedError.
|
|
179
|
+
*
|
|
180
|
+
* @param e The parameter to check
|
|
181
|
+
*/
|
|
182
|
+
export function isNotImplementedError(e) {
|
|
183
|
+
return isHttpError(e) && e.name === 'NotImplementedError';
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Thrown when an illegal argument is passed to a function.
|
|
187
|
+
*/
|
|
188
|
+
export class IllegalArgumentError extends Error {
|
|
189
|
+
constructor(argName, message) {
|
|
190
|
+
message = message !== null && message !== void 0 ? message : `Illegal argument ${argName}`;
|
|
191
|
+
super(message);
|
|
192
|
+
this.argName = argName;
|
|
193
|
+
this.name = 'IllegalArgumentError';
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Checks if the given parameter is a IllegalArgumentError.
|
|
198
|
+
*
|
|
199
|
+
* @param e The parameter to check
|
|
200
|
+
*/
|
|
201
|
+
export function isIllegalArgumentError(e) {
|
|
202
|
+
return isError(e) && e.name === 'IllegalArgumentError';
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Converts the given parameter to an HttpError.
|
|
206
|
+
*
|
|
207
|
+
* @param code The HTTP status code
|
|
208
|
+
* @param message The error message
|
|
209
|
+
*/
|
|
210
|
+
export function toError(code, message) {
|
|
211
|
+
switch (code) {
|
|
212
|
+
case HttpStatusCode.NOT_FOUND:
|
|
213
|
+
return new NotFoundError(message);
|
|
214
|
+
case HttpStatusCode.FORBIDDEN:
|
|
215
|
+
return new ForbiddenError(message);
|
|
216
|
+
case HttpStatusCode.BAD_REQUEST:
|
|
217
|
+
return new BadRequestError(message);
|
|
218
|
+
case HttpStatusCode.INTERNAL_SERVER_ERROR:
|
|
219
|
+
return new InternalServerError(message);
|
|
220
|
+
case HttpStatusCode.CONFLICT:
|
|
221
|
+
return new ConflictError(message);
|
|
222
|
+
case HttpStatusCode.UNSUPPORTED_MEDIA_TYPE:
|
|
223
|
+
return new UnsupportedMediaTypeError(message);
|
|
224
|
+
case HttpStatusCode.NOT_IMPLEMENTED:
|
|
225
|
+
return new NotImplementedError(message);
|
|
226
|
+
default:
|
|
227
|
+
return new Error(message);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"./src/","sources":["errors/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,SAAS,CAAC;AACvC,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAC,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAC,OAAO,EAAC,MAAM,SAAS,CAAC;AAahC;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,CAAW;IACrC,OAAO,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;AAChF,CAAC;AAED;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,KAAK;IAMtC,YAAY,OAAgB,EAAE,MAAe;QAC3C,OAAO,GAAG,OAAO,aAAP,OAA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AAC;QAC1C;YACE,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;KAC7B;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"./src/","sources":["errors/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HttpMethod = void 0;
|
|
4
|
-
var HttpMethod;
|
|
1
|
+
export var HttpMethod;
|
|
5
2
|
(function (HttpMethod) {
|
|
6
3
|
HttpMethod["GET"] = "GET";
|
|
7
4
|
HttpMethod["POST"] = "POST";
|
|
@@ -10,5 +7,5 @@ var HttpMethod;
|
|
|
10
7
|
HttpMethod["DELETE"] = "DELETE";
|
|
11
8
|
HttpMethod["HEAD"] = "HEAD";
|
|
12
9
|
HttpMethod["OPTIONS"] = "OPTIONS";
|
|
13
|
-
})(HttpMethod || (
|
|
10
|
+
})(HttpMethod || (HttpMethod = {}));
|
|
14
11
|
//# sourceMappingURL=http-method.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-method.js","sourceRoot":"./src/","sources":["http/http-method.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,UAQX;AARD,WAAY,UAAU;IACpB,yBAAW,CAAA;IACX,2BAAa,CAAA;IACb,yBAAW,CAAA;IACX,6BAAe,CAAA;IACf,+BAAiB,CAAA;IACjB,2BAAa,CAAA;IACb,iCAAmB,CAAA;AACrB,CAAC,EARW,UAAU,KAAV,UAAU,QAQrB"}
|