@nr1e/commons 0.0.2-alpha.2 → 0.0.2-alpha.20

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,123 @@
1
+ import { HttpStatusCode } from '../http';
2
+ interface IError {
3
+ stack?: string;
4
+ name?: string;
5
+ message?: string;
6
+ statusCode?: HttpStatusCode | number;
7
+ }
8
+ export interface HttpError extends Error {
9
+ statusCode: HttpStatusCode | number;
10
+ }
11
+ /**
12
+ * Checks if the given parameter is an HttpError.
13
+ *
14
+ * @param e the parameter to check
15
+ */
16
+ export declare function isHttpError(e?: IError | null): e is HttpError;
17
+ /**
18
+ * Checks if the given parameter is a NotFoundError.
19
+ *
20
+ * @param e the parameter to check
21
+ */
22
+ export declare function isNotFoundError(e?: IError | null): e is NotFoundError;
23
+ /**
24
+ * Thrown when a resource cannot be found.
25
+ */
26
+ export declare class NotFoundError extends Error implements HttpError {
27
+ readonly statusCode = HttpStatusCode.NOT_FOUND;
28
+ constructor(message?: string);
29
+ }
30
+ /**
31
+ * Checks if the given parameter is a ForbiddenError.
32
+ *
33
+ * @param e the parameter to check
34
+ */
35
+ export declare function isForbiddenError(e?: IError | null): e is ForbiddenError;
36
+ /**
37
+ * Thrown when a requested operations is not allowed.
38
+ */
39
+ export declare class ForbiddenError extends Error implements HttpError {
40
+ readonly statusCode = HttpStatusCode.FORBIDDEN;
41
+ constructor(message?: string);
42
+ }
43
+ /**
44
+ * Checks if the given variable is a ValidationError.
45
+ *
46
+ * @param e the variable to check
47
+ */
48
+ export declare function isValidationError(e?: IError | null): e is ValidationError;
49
+ /**
50
+ * Thrown when a validation error occurs.
51
+ */
52
+ export declare class ValidationError extends Error implements HttpError {
53
+ readonly statusCode = HttpStatusCode.BAD_REQUEST;
54
+ constructor(message?: string);
55
+ }
56
+ /**
57
+ * Checks if the given parameter is a BadRequestError.
58
+ *
59
+ * @param e the parameter to check
60
+ */
61
+ export declare function isBadRequestError(e?: IError | null): e is BadRequestError;
62
+ /**
63
+ * Thrown when a bad request is made.
64
+ */
65
+ export declare class BadRequestError extends Error implements HttpError {
66
+ readonly statusCode = HttpStatusCode.BAD_REQUEST;
67
+ constructor(message?: string);
68
+ }
69
+ /**
70
+ * Checks if the given parameter is a InternalServerError.
71
+ *
72
+ * @param e the parameter to check
73
+ */
74
+ export declare function isInternalServerError(e?: IError | null): e is InternalServerError;
75
+ /**
76
+ * Throws when an internal server error occurs.
77
+ */
78
+ export declare class InternalServerError extends Error implements HttpError {
79
+ readonly statusCode = HttpStatusCode.INTERNAL_SERVER_ERROR;
80
+ constructor(message?: string);
81
+ }
82
+ /**
83
+ * Checks if the given parameter is a ConflictError.
84
+ *
85
+ * @param e the parameter to check
86
+ */
87
+ export declare function isConflictError(e?: IError | null): e is ConflictError;
88
+ /**
89
+ * Thrown when a conflict occurs.
90
+ */
91
+ export declare class ConflictError extends Error implements HttpError {
92
+ readonly statusCode = HttpStatusCode.CONFLICT;
93
+ constructor(message?: string);
94
+ }
95
+ /**
96
+ * Checks if the given parameter is a UnsupportedMediaTypeError.
97
+ *
98
+ * @param e the parameter to check
99
+ */
100
+ export declare function isUnsupportedMediaTypeError(e?: IError | null): e is UnsupportedMediaTypeError;
101
+ /**
102
+ * Thrown when a unsupported media type is used.
103
+ */
104
+ export declare class UnsupportedMediaTypeError extends Error implements HttpError {
105
+ readonly statusCode = HttpStatusCode.UNSUPPORTED_MEDIA_TYPE;
106
+ constructor(message?: string);
107
+ }
108
+ /**
109
+ * Checks if the given parameter is a NotImplementedError.
110
+ *
111
+ * @param e the parameter to check
112
+ */
113
+ export declare function isNotImplementedError(e?: IError | null): e is NotImplementedError;
114
+ /**
115
+ * Thrown when a requested operation is not implemented.
116
+ */
117
+ export declare class NotImplementedError extends Error implements HttpError {
118
+ readonly statusCode = HttpStatusCode.NOT_IMPLEMENTED;
119
+ readonly expose = true;
120
+ constructor(message?: string);
121
+ }
122
+ export declare function toError(code: number | HttpStatusCode, message?: string): Error;
123
+ export {};
@@ -0,0 +1,238 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toError = exports.NotImplementedError = exports.isNotImplementedError = exports.UnsupportedMediaTypeError = exports.isUnsupportedMediaTypeError = exports.ConflictError = exports.isConflictError = exports.InternalServerError = exports.isInternalServerError = exports.BadRequestError = exports.isBadRequestError = exports.ValidationError = exports.isValidationError = exports.ForbiddenError = exports.isForbiddenError = exports.NotFoundError = exports.isNotFoundError = exports.isHttpError = void 0;
4
+ const http_1 = require("../http");
5
+ /**
6
+ * Checks if the given parameter is an HttpError.
7
+ *
8
+ * @param e the parameter to check
9
+ */
10
+ function isHttpError(e) {
11
+ return !!(e && e.stack && e.statusCode && e.message && e.name);
12
+ }
13
+ exports.isHttpError = isHttpError;
14
+ /**
15
+ * Checks if the given parameter is a NotFoundError.
16
+ *
17
+ * @param e the parameter to check
18
+ */
19
+ function isNotFoundError(e) {
20
+ return !!(e &&
21
+ e.stack &&
22
+ e.statusCode &&
23
+ e.message &&
24
+ e.name &&
25
+ e.name === 'NotFoundError');
26
+ }
27
+ exports.isNotFoundError = isNotFoundError;
28
+ /**
29
+ * Thrown when a resource cannot be found.
30
+ */
31
+ class NotFoundError extends Error {
32
+ constructor(message) {
33
+ message = message !== null && message !== void 0 ? message : 'Not found';
34
+ super(message);
35
+ this.statusCode = http_1.HttpStatusCode.NOT_FOUND;
36
+ this.name = 'NotFoundError';
37
+ }
38
+ }
39
+ exports.NotFoundError = NotFoundError;
40
+ /**
41
+ * Checks if the given parameter is a ForbiddenError.
42
+ *
43
+ * @param e the parameter to check
44
+ */
45
+ function isForbiddenError(e) {
46
+ return !!(e &&
47
+ e.stack &&
48
+ e.statusCode &&
49
+ e.message &&
50
+ e.name &&
51
+ e.name === 'ForbiddenError');
52
+ }
53
+ exports.isForbiddenError = isForbiddenError;
54
+ /**
55
+ * Thrown when a requested operations is not allowed.
56
+ */
57
+ class ForbiddenError extends Error {
58
+ constructor(message) {
59
+ message = message !== null && message !== void 0 ? message : 'Forbidden';
60
+ super(message);
61
+ this.statusCode = http_1.HttpStatusCode.FORBIDDEN;
62
+ this.name = 'ForbiddenError';
63
+ }
64
+ }
65
+ exports.ForbiddenError = ForbiddenError;
66
+ /**
67
+ * Checks if the given variable is a ValidationError.
68
+ *
69
+ * @param e the variable to check
70
+ */
71
+ function isValidationError(e) {
72
+ return !!(e &&
73
+ e.stack &&
74
+ e.statusCode &&
75
+ e.message &&
76
+ e.name === 'ValidationError');
77
+ }
78
+ exports.isValidationError = isValidationError;
79
+ /**
80
+ * Thrown when a validation error occurs.
81
+ */
82
+ class ValidationError extends Error {
83
+ constructor(message) {
84
+ message = message !== null && message !== void 0 ? message : 'Validation error';
85
+ super(message);
86
+ this.statusCode = http_1.HttpStatusCode.BAD_REQUEST;
87
+ this.name = 'ValidationError';
88
+ }
89
+ }
90
+ exports.ValidationError = ValidationError;
91
+ /**
92
+ * Checks if the given parameter is a BadRequestError.
93
+ *
94
+ * @param e the parameter to check
95
+ */
96
+ function isBadRequestError(e) {
97
+ return !!(e &&
98
+ e.stack &&
99
+ e.statusCode &&
100
+ e.message &&
101
+ e.name === 'BadRequestError');
102
+ }
103
+ exports.isBadRequestError = isBadRequestError;
104
+ /**
105
+ * Thrown when a bad request is made.
106
+ */
107
+ class BadRequestError extends Error {
108
+ constructor(message) {
109
+ message = message !== null && message !== void 0 ? message : 'Bad request';
110
+ super(message !== null && message !== void 0 ? message : 'Bad request');
111
+ this.statusCode = http_1.HttpStatusCode.BAD_REQUEST;
112
+ this.name = 'BadRequestError';
113
+ }
114
+ }
115
+ exports.BadRequestError = BadRequestError;
116
+ /**
117
+ * Checks if the given parameter is a InternalServerError.
118
+ *
119
+ * @param e the parameter to check
120
+ */
121
+ function isInternalServerError(e) {
122
+ return !!(e &&
123
+ e.stack &&
124
+ e.statusCode &&
125
+ e.message &&
126
+ e.name === 'InternalServerError');
127
+ }
128
+ exports.isInternalServerError = isInternalServerError;
129
+ /**
130
+ * Throws when an internal server error occurs.
131
+ */
132
+ class InternalServerError extends Error {
133
+ constructor(message) {
134
+ message = message !== null && message !== void 0 ? message : 'Internal server error';
135
+ super(message);
136
+ this.statusCode = http_1.HttpStatusCode.INTERNAL_SERVER_ERROR;
137
+ this.name = 'InternalServerError';
138
+ }
139
+ }
140
+ exports.InternalServerError = InternalServerError;
141
+ /**
142
+ * Checks if the given parameter is a ConflictError.
143
+ *
144
+ * @param e the parameter to check
145
+ */
146
+ function isConflictError(e) {
147
+ return !!(e &&
148
+ e.stack &&
149
+ e.statusCode &&
150
+ e.message &&
151
+ e.name === 'ConflictError');
152
+ }
153
+ exports.isConflictError = isConflictError;
154
+ /**
155
+ * Thrown when a conflict occurs.
156
+ */
157
+ class ConflictError extends Error {
158
+ constructor(message) {
159
+ message = message !== null && message !== void 0 ? message : 'Conflict';
160
+ super(message);
161
+ this.statusCode = http_1.HttpStatusCode.CONFLICT;
162
+ this.name = 'ConflictError';
163
+ }
164
+ }
165
+ exports.ConflictError = ConflictError;
166
+ /**
167
+ * Checks if the given parameter is a UnsupportedMediaTypeError.
168
+ *
169
+ * @param e the parameter to check
170
+ */
171
+ function isUnsupportedMediaTypeError(e) {
172
+ return !!(e &&
173
+ e.stack &&
174
+ e.statusCode &&
175
+ e.message &&
176
+ e.name === 'UnsupportedMediaTypeError');
177
+ }
178
+ exports.isUnsupportedMediaTypeError = isUnsupportedMediaTypeError;
179
+ /**
180
+ * Thrown when a unsupported media type is used.
181
+ */
182
+ class UnsupportedMediaTypeError extends Error {
183
+ constructor(message) {
184
+ message = message !== null && message !== void 0 ? message : 'Unsupported media type';
185
+ super(message);
186
+ this.statusCode = http_1.HttpStatusCode.UNSUPPORTED_MEDIA_TYPE;
187
+ this.name = 'UnsupportedMediaTypeError';
188
+ }
189
+ }
190
+ exports.UnsupportedMediaTypeError = UnsupportedMediaTypeError;
191
+ /**
192
+ * Checks if the given parameter is a NotImplementedError.
193
+ *
194
+ * @param e the parameter to check
195
+ */
196
+ function isNotImplementedError(e) {
197
+ return !!(e &&
198
+ e.stack &&
199
+ e.statusCode &&
200
+ e.message &&
201
+ e.name === 'NotImplementedError');
202
+ }
203
+ exports.isNotImplementedError = isNotImplementedError;
204
+ /**
205
+ * Thrown when a requested operation is not implemented.
206
+ */
207
+ class NotImplementedError extends Error {
208
+ constructor(message) {
209
+ message = message !== null && message !== void 0 ? message : 'Not implemented';
210
+ super(message);
211
+ this.statusCode = http_1.HttpStatusCode.NOT_IMPLEMENTED;
212
+ this.expose = true;
213
+ this.name = 'NotImplementedError';
214
+ }
215
+ }
216
+ exports.NotImplementedError = NotImplementedError;
217
+ function toError(code, message) {
218
+ switch (code) {
219
+ case http_1.HttpStatusCode.NOT_FOUND:
220
+ return new NotFoundError(message);
221
+ case http_1.HttpStatusCode.FORBIDDEN:
222
+ return new ForbiddenError(message);
223
+ case http_1.HttpStatusCode.BAD_REQUEST:
224
+ return new BadRequestError(message);
225
+ case http_1.HttpStatusCode.INTERNAL_SERVER_ERROR:
226
+ return new InternalServerError(message);
227
+ case http_1.HttpStatusCode.CONFLICT:
228
+ return new ConflictError(message);
229
+ case http_1.HttpStatusCode.UNSUPPORTED_MEDIA_TYPE:
230
+ return new UnsupportedMediaTypeError(message);
231
+ case http_1.HttpStatusCode.NOT_IMPLEMENTED:
232
+ return new NotImplementedError(message);
233
+ default:
234
+ return new Error(message);
235
+ }
236
+ }
237
+ exports.toError = toError;
238
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["errors.ts"],"names":[],"mappings":";;;AAAA,kCAAuC;AAavC;;;;GAIG;AACH,SAAgB,WAAW,CAAC,CAAiB;IAC3C,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;AACjE,CAAC;AAFD,kCAEC;AAED;;;;GAIG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ACH,CAAC;AAtBD,0BAsBC"}
@@ -0,0 +1 @@
1
+ export * from './errors';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./errors"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB"}
@@ -0,0 +1,9 @@
1
+ export declare enum HttpMethod {
2
+ GET = "GET",
3
+ POST = "POST",
4
+ PUT = "PUT",
5
+ PATCH = "PATCH",
6
+ DELETE = "DELETE",
7
+ HEAD = "HEAD",
8
+ OPTIONS = "OPTIONS"
9
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpMethod = void 0;
4
+ var HttpMethod;
5
+ (function (HttpMethod) {
6
+ HttpMethod["GET"] = "GET";
7
+ HttpMethod["POST"] = "POST";
8
+ HttpMethod["PUT"] = "PUT";
9
+ HttpMethod["PATCH"] = "PATCH";
10
+ HttpMethod["DELETE"] = "DELETE";
11
+ HttpMethod["HEAD"] = "HEAD";
12
+ HttpMethod["OPTIONS"] = "OPTIONS";
13
+ })(HttpMethod || (exports.HttpMethod = HttpMethod = {}));
14
+ //# sourceMappingURL=http-method.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-method.js","sourceRoot":"","sources":["http-method.ts"],"names":[],"mappings":";;;AAAA,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,0BAAV,UAAU,QAQrB"}
@@ -0,0 +1,42 @@
1
+ export declare enum HttpStatusCode {
2
+ CONTINUE = 100,
3
+ SWITCHING_PROTOCOLS = 101,
4
+ OK = 200,
5
+ CREATED = 201,
6
+ ACCEPTED = 202,
7
+ NON_AUTHORITATIVE_INFORMATION = 203,
8
+ NO_CONTENT = 204,
9
+ RESET_CONTENT = 205,
10
+ PARTIAL_CONTENT = 206,
11
+ MULTIPLE_CHOICES = 300,
12
+ PERMANENT_REDIRECT = 301,
13
+ FOUND = 302,
14
+ SEE_OTHER = 303,
15
+ NOT_MODIFIED = 304,
16
+ USE_PROXY = 305,
17
+ TEMPORARY_REDIRECT = 307,
18
+ BAD_REQUEST = 400,
19
+ UNAUTHORIZED = 401,
20
+ PAYMENT_REQUIRED = 402,
21
+ FORBIDDEN = 403,
22
+ NOT_FOUND = 404,
23
+ METHOD_NOT_ALLOWED = 405,
24
+ NOT_ACCEPTABLE = 406,
25
+ PROXY_AUTHENTICATION_REQUIRED = 407,
26
+ REQUEST_TIMEOUT = 408,
27
+ CONFLICT = 409,
28
+ GONE = 410,
29
+ LENGTH_REQUIRED = 411,
30
+ PRECONDITION_FAILED = 412,
31
+ REQUEST_ENTITY_TOO_LARGE = 413,
32
+ REQUEST_URI_TOO_LONG = 414,
33
+ UNSUPPORTED_MEDIA_TYPE = 415,
34
+ RANGE_NOT_SATISFIABLE = 416,
35
+ EXPECTATION_FAILED = 417,
36
+ INTERNAL_SERVER_ERROR = 500,
37
+ NOT_IMPLEMENTED = 501,
38
+ BAD_GATEWAY = 502,
39
+ SERVICE_UNAVAILABLE = 503,
40
+ GATEWAY_TIMEOUT = 504,
41
+ HTTP_VERSION_NOT_SUPPORTED = 505
42
+ }
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpStatusCode = void 0;
4
+ var HttpStatusCode;
5
+ (function (HttpStatusCode) {
6
+ HttpStatusCode[HttpStatusCode["CONTINUE"] = 100] = "CONTINUE";
7
+ HttpStatusCode[HttpStatusCode["SWITCHING_PROTOCOLS"] = 101] = "SWITCHING_PROTOCOLS";
8
+ HttpStatusCode[HttpStatusCode["OK"] = 200] = "OK";
9
+ HttpStatusCode[HttpStatusCode["CREATED"] = 201] = "CREATED";
10
+ HttpStatusCode[HttpStatusCode["ACCEPTED"] = 202] = "ACCEPTED";
11
+ HttpStatusCode[HttpStatusCode["NON_AUTHORITATIVE_INFORMATION"] = 203] = "NON_AUTHORITATIVE_INFORMATION";
12
+ HttpStatusCode[HttpStatusCode["NO_CONTENT"] = 204] = "NO_CONTENT";
13
+ HttpStatusCode[HttpStatusCode["RESET_CONTENT"] = 205] = "RESET_CONTENT";
14
+ HttpStatusCode[HttpStatusCode["PARTIAL_CONTENT"] = 206] = "PARTIAL_CONTENT";
15
+ HttpStatusCode[HttpStatusCode["MULTIPLE_CHOICES"] = 300] = "MULTIPLE_CHOICES";
16
+ HttpStatusCode[HttpStatusCode["PERMANENT_REDIRECT"] = 301] = "PERMANENT_REDIRECT";
17
+ HttpStatusCode[HttpStatusCode["FOUND"] = 302] = "FOUND";
18
+ HttpStatusCode[HttpStatusCode["SEE_OTHER"] = 303] = "SEE_OTHER";
19
+ HttpStatusCode[HttpStatusCode["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
20
+ HttpStatusCode[HttpStatusCode["USE_PROXY"] = 305] = "USE_PROXY";
21
+ HttpStatusCode[HttpStatusCode["TEMPORARY_REDIRECT"] = 307] = "TEMPORARY_REDIRECT";
22
+ HttpStatusCode[HttpStatusCode["BAD_REQUEST"] = 400] = "BAD_REQUEST";
23
+ HttpStatusCode[HttpStatusCode["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
24
+ HttpStatusCode[HttpStatusCode["PAYMENT_REQUIRED"] = 402] = "PAYMENT_REQUIRED";
25
+ HttpStatusCode[HttpStatusCode["FORBIDDEN"] = 403] = "FORBIDDEN";
26
+ HttpStatusCode[HttpStatusCode["NOT_FOUND"] = 404] = "NOT_FOUND";
27
+ HttpStatusCode[HttpStatusCode["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
28
+ HttpStatusCode[HttpStatusCode["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
29
+ HttpStatusCode[HttpStatusCode["PROXY_AUTHENTICATION_REQUIRED"] = 407] = "PROXY_AUTHENTICATION_REQUIRED";
30
+ HttpStatusCode[HttpStatusCode["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
31
+ HttpStatusCode[HttpStatusCode["CONFLICT"] = 409] = "CONFLICT";
32
+ HttpStatusCode[HttpStatusCode["GONE"] = 410] = "GONE";
33
+ HttpStatusCode[HttpStatusCode["LENGTH_REQUIRED"] = 411] = "LENGTH_REQUIRED";
34
+ HttpStatusCode[HttpStatusCode["PRECONDITION_FAILED"] = 412] = "PRECONDITION_FAILED";
35
+ HttpStatusCode[HttpStatusCode["REQUEST_ENTITY_TOO_LARGE"] = 413] = "REQUEST_ENTITY_TOO_LARGE";
36
+ HttpStatusCode[HttpStatusCode["REQUEST_URI_TOO_LONG"] = 414] = "REQUEST_URI_TOO_LONG";
37
+ HttpStatusCode[HttpStatusCode["UNSUPPORTED_MEDIA_TYPE"] = 415] = "UNSUPPORTED_MEDIA_TYPE";
38
+ HttpStatusCode[HttpStatusCode["RANGE_NOT_SATISFIABLE"] = 416] = "RANGE_NOT_SATISFIABLE";
39
+ HttpStatusCode[HttpStatusCode["EXPECTATION_FAILED"] = 417] = "EXPECTATION_FAILED";
40
+ HttpStatusCode[HttpStatusCode["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
41
+ HttpStatusCode[HttpStatusCode["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
42
+ HttpStatusCode[HttpStatusCode["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
43
+ HttpStatusCode[HttpStatusCode["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
44
+ HttpStatusCode[HttpStatusCode["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
45
+ HttpStatusCode[HttpStatusCode["HTTP_VERSION_NOT_SUPPORTED"] = 505] = "HTTP_VERSION_NOT_SUPPORTED";
46
+ })(HttpStatusCode || (exports.HttpStatusCode = HttpStatusCode = {}));
47
+ //# sourceMappingURL=http-status-code.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-status-code.js","sourceRoot":"","sources":["http-status-code.ts"],"names":[],"mappings":";;;AAAA,IAAY,cAyCX;AAzCD,WAAY,cAAc;IACxB,6DAAc,CAAA;IACd,mFAAyB,CAAA;IACzB,iDAAQ,CAAA;IACR,2DAAa,CAAA;IACb,6DAAc,CAAA;IACd,uGAAmC,CAAA;IACnC,iEAAgB,CAAA;IAChB,uEAAmB,CAAA;IACnB,2EAAqB,CAAA;IACrB,6EAAsB,CAAA;IACtB,iFAAwB,CAAA;IACxB,uDAAW,CAAA;IACX,+DAAe,CAAA;IACf,qEAAkB,CAAA;IAClB,+DAAe,CAAA;IACf,iFAAwB,CAAA;IACxB,mEAAiB,CAAA;IACjB,qEAAkB,CAAA;IAClB,6EAAsB,CAAA;IACtB,+DAAe,CAAA;IACf,+DAAe,CAAA;IACf,iFAAwB,CAAA;IACxB,yEAAoB,CAAA;IACpB,uGAAmC,CAAA;IACnC,2EAAqB,CAAA;IACrB,6DAAc,CAAA;IACd,qDAAU,CAAA;IACV,2EAAqB,CAAA;IACrB,mFAAyB,CAAA;IACzB,6FAA8B,CAAA;IAC9B,qFAA0B,CAAA;IAC1B,yFAA4B,CAAA;IAC5B,uFAA2B,CAAA;IAC3B,iFAAwB,CAAA;IACxB,uFAA2B,CAAA;IAC3B,2EAAqB,CAAA;IACrB,mEAAiB,CAAA;IACjB,mFAAyB,CAAA;IACzB,2EAAqB,CAAA;IACrB,iGAAgC,CAAA;AAClC,CAAC,EAzCW,cAAc,8BAAd,cAAc,QAyCzB"}
@@ -0,0 +1,2 @@
1
+ export * from './http-status-code';
2
+ export * from './http-method';
package/http/index.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./http-status-code"), exports);
18
+ __exportStar(require("./http-method"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,gDAA8B"}
package/index.d.ts CHANGED
@@ -1 +1,3 @@
1
1
  export * as validator from './validator';
2
+ export * as errors from './errors';
3
+ export * as http from './http';
package/index.js CHANGED
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validator = void 0;
3
+ exports.http = exports.errors = exports.validator = void 0;
4
4
  exports.validator = require("./validator");
5
+ exports.errors = require("./errors");
6
+ exports.http = require("./http");
5
7
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AAAA,2CAAyC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AAAA,2CAAyC;AACzC,qCAAmC;AACnC,iCAA+B"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nr1e/commons",
3
3
  "description": "Provides common patterns for validation",
4
- "version": "0.0.2-alpha.2",
4
+ "version": "0.0.2-alpha.20",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
7
7
  "author": "NR1E, Inc.",
@@ -25,24 +25,25 @@
25
25
  "gts": "^5.2.0",
26
26
  "jest": "^29.7.0",
27
27
  "ts-jest": "^29.1.1",
28
+ "typedoc": "^0.25.6",
28
29
  "typescript": "~5.1.6"
29
30
  },
30
31
  "exports": {
31
32
  ".": "./index.js",
32
33
  "./package.json": "./package.json",
34
+ "./http": "./http/index.js",
35
+ "./errors": "./errors/index.js",
33
36
  "./validator": "./validator/index.js"
34
37
  },
35
38
  "scripts": {
36
39
  "build": "tsc",
40
+ "postbuild": "prettier --check . && gts lint",
37
41
  "watch": "tsc -w",
38
42
  "test": "jest",
39
43
  "lint": "gts lint",
40
- "clean": "gts clean",
41
- "compile": "tsc",
44
+ "clean": "find . -depth 1 \\( -name '*.js' -o -name '*.d.ts' -o -name '*.map' \\) ! -name '.*' ! -name 'jest.config.js' -delete",
42
45
  "fix": "gts fix",
43
- "pretest": "pnpm run compile",
44
- "posttest": "pnpm run lint",
45
- "check": "prettier --check .",
46
- "makepretty": "prettier --write ."
46
+ "makepretty": "prettier --write .",
47
+ "site": "typedoc --out site index.ts"
47
48
  }
48
49
  }
@@ -1,2 +1 @@
1
1
  export * from './validators';
2
- export * from './validation-error';
@@ -15,5 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./validators"), exports);
18
- __exportStar(require("./validation-error"), exports);
19
18
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,qDAAmC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B"}
@@ -1,3 +1,9 @@
1
+ /**
2
+ * Tests if a value is null or undefined.
3
+ *
4
+ * @param o the value to check
5
+ */
6
+ export declare function isNotNull(o?: unknown): o is NonNullable<unknown>;
1
7
  /**
2
8
  * Throws a ValidationError if the value is null or undefined.
3
9
  * This function also asserts the value to be NonNullable if the check passes.
@@ -6,6 +12,12 @@
6
12
  * @param o the value to check
7
13
  */
8
14
  export declare function notNull(name: string, o?: unknown): asserts o is NonNullable<unknown>;
15
+ /**
16
+ * Tests if a value is empty, null, undefined or has a length of 0.
17
+ *
18
+ * @param o the value to check
19
+ */
20
+ export declare function isNotEmpty(o?: unknown): o is NonNullable<unknown>;
9
21
  /**
10
22
  * Throws a ValidationError if the value is null, undefined or the length is 0.
11
23
  * This function also asserts the value to be NonNullable if the check passes.
@@ -14,6 +26,12 @@ export declare function notNull(name: string, o?: unknown): asserts o is NonNull
14
26
  * @param o the value to check
15
27
  */
16
28
  export declare function notEmpty(name: string, o?: unknown): asserts o is NonNullable<unknown>;
29
+ /**
30
+ * Tests if a value is null, undefined, has a length of 0 or contains only whitespace.
31
+ *
32
+ * @param o the value to check
33
+ */
34
+ export declare function isNotBlank(o?: unknown): o is NonNullable<unknown>;
17
35
  /**
18
36
  * Throws a ValidationError if the value is null, undefined, has a length of 0 or contains only whitespace.
19
37
  * This function also asserts the value to be NonNullable if the check passes.
@@ -23,14 +41,29 @@ export declare function notEmpty(name: string, o?: unknown): asserts o is NonNul
23
41
  */
24
42
  export declare function notBlank(name: string, o?: unknown): asserts o is NonNullable<unknown>;
25
43
  /**
26
- * Throws a ValidationError if the value does not match the regular expression provided.
44
+ * Tests if a value does not match the regular expression provided.
45
+ * Undefined and null values are skipped and not tested.
46
+ *
47
+ * @param regex the regular expression to test with
48
+ * @param o the value to check
49
+ */
50
+ export declare function isMatch(regex: RegExp, o?: string | null): o is string;
51
+ /**
52
+ * Throws a ValidationError if the value matches the regular expression provided.
27
53
  * Undefined and null values are skipped and not validated.
28
54
  *
29
55
  * @param name the name of the variable
30
56
  * @param regex the regular expression to validate with
31
57
  * @param o the value to check
32
58
  */
33
- export declare function matches(name: string, regex: RegExp, o?: string | null): void;
59
+ export declare function match(name: string, regex: RegExp, o?: string | null): void;
60
+ /**
61
+ * Tests if a value is a valid email address.
62
+ * Undefined and null values are skipped and not validated.
63
+ *
64
+ * @param o the value to check
65
+ */
66
+ export declare function isEmail(o?: string | null): o is string;
34
67
  /**
35
68
  * Throws a ValidationError if the value provided is not an email.
36
69
  * Undefined and null values are skipped and not validated.
@@ -38,7 +71,15 @@ export declare function matches(name: string, regex: RegExp, o?: string | null):
38
71
  * @param name the name of the variable
39
72
  * @param o the value to check
40
73
  */
41
- export declare function isEmail(name: string, o?: string | null): void;
74
+ export declare function email(name: string, o?: string | null): void;
75
+ /**
76
+ * Tests if a value has a length that is less than the provided length.
77
+ * Undefined and null values are skipped and not validated.
78
+ *
79
+ * @param length the maximum length of the variable
80
+ * @param o the value to check
81
+ */
82
+ export declare function isMaxLength(length: number, o?: string | unknown[] | null): boolean;
42
83
  /**
43
84
  * Throws a ValidationError if the value provided has a length that exceeds the provided length.
44
85
  * Undefined and null values are skipped and not validated.
@@ -48,6 +89,14 @@ export declare function isEmail(name: string, o?: string | null): void;
48
89
  * @param o the value to check
49
90
  */
50
91
  export declare function maxLength(name: string, length: number, o?: string | unknown[] | null): void;
92
+ /**
93
+ * Tests if a value has a length that is greater than the provided length.
94
+ * Undefined and null values are skipped and not validated.
95
+ *
96
+ * @param length the minimum length of the variable
97
+ * @param o the value to check
98
+ */
99
+ export declare function isMinLength(length: number, o?: string | unknown[] | null): boolean;
51
100
  /**
52
101
  * Throws a ValidationError if the value provided has a length that is less than the provided length.
53
102
  * Undefined and null values are skipped and not validated.
@@ -57,6 +106,13 @@ export declare function maxLength(name: string, length: number, o?: string | unk
57
106
  * @param o the value to check
58
107
  */
59
108
  export declare function minLength(name: string, length: number, o?: string | unknown[] | null): void;
109
+ /**
110
+ * Tests if a value provided is a number.
111
+ * Undefined and null values are skipped and not validated.
112
+ *
113
+ * @param o the value to check
114
+ */
115
+ export declare function isNumber(o?: string | null | number): boolean;
60
116
  /**
61
117
  * Throws a ValidationError if the value provided is not a number.
62
118
  * Undefined and null values are skipped and not validated.
@@ -64,7 +120,15 @@ export declare function minLength(name: string, length: number, o?: string | unk
64
120
  * @param name the name of the variable
65
121
  * @param o the value to check
66
122
  */
67
- export declare function isNumber(name: string, o?: string | null | number): void;
123
+ export declare function number(name: string, o?: string | null | number): void;
124
+ /**
125
+ * Tests if a value is less than the provided minimum value.
126
+ * Undefined and null values are skipped and not validated.
127
+ *
128
+ * @param minValue the minimum value allowed
129
+ * @param o the value to check
130
+ */
131
+ export declare function isMinValue(minValue: number, o?: string | number | null): boolean;
68
132
  /**
69
133
  * Throws a ValidationError if the value is less than the provided minimum value.
70
134
  * Undefined and null values are skipped and not validated.
@@ -74,6 +138,14 @@ export declare function isNumber(name: string, o?: string | null | number): void
74
138
  * @param o the value to check
75
139
  */
76
140
  export declare function minValue(name: string, minValue: number, o?: number | string | null): void;
141
+ /**
142
+ * Tests if a value is more than the provided maximum value.
143
+ * Undefined and null values are skipped and not validated.
144
+ *
145
+ * @param maxValue the maximum value allowed
146
+ * @param o the value to check
147
+ */
148
+ export declare function isMaxValue(maxValue: number, o?: string | number | null): boolean;
77
149
  /**
78
150
  * Throws a ValidationError if the value is more than the provided maximum value.
79
151
  * Undefined and null values are skipped and not validated.
@@ -83,6 +155,15 @@ export declare function minValue(name: string, minValue: number, o?: number | st
83
155
  * @param o the value to check
84
156
  */
85
157
  export declare function maxValue(name: string, maxValue: number, o?: number | string | null): void;
158
+ /**
159
+ * Tests if the value is between the provided minimum and maximum values inclusive.
160
+ * Undefined and null values are skipped and not validated.
161
+ *
162
+ * @param minValue the minimum value allowed
163
+ * @param maxValue the maximum value allowed
164
+ * @param o the value to check
165
+ */
166
+ export declare function isBetweenValues(minValue: number, maxValue: number, o?: string | number | null): boolean;
86
167
  /**
87
168
  * Throws a ValidationError if the value is not between the provided minimum and maximum values inclusive.
88
169
  * Undefined and null values are skipped and not validated.
@@ -94,14 +175,14 @@ export declare function maxValue(name: string, maxValue: number, o?: number | st
94
175
  */
95
176
  export declare function betweenValues(name: string, minValue: number, maxValue: number, o?: string | number | null): void;
96
177
  export interface StringValidationOptions {
97
- readonly name: string;
98
178
  readonly required: boolean;
99
179
  readonly minLength?: number;
100
180
  readonly maxLength?: number;
101
181
  readonly regex?: RegExp;
102
182
  readonly notBlank?: boolean;
103
183
  readonly notEmpty?: boolean;
104
- readonly isEmail?: boolean;
105
- readonly isNumber?: boolean;
184
+ readonly email?: boolean;
185
+ readonly number?: boolean;
106
186
  }
107
- export declare function validateString(options: StringValidationOptions, value?: unknown): void;
187
+ export declare function isValidString(options: StringValidationOptions, value?: unknown): value is string;
188
+ export declare function validString(name: string, options: StringValidationOptions, value?: unknown): void;
@@ -1,7 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateString = exports.betweenValues = exports.maxValue = exports.minValue = exports.isNumber = exports.minLength = exports.maxLength = exports.isEmail = exports.matches = exports.notBlank = exports.notEmpty = exports.notNull = void 0;
4
- const validation_error_1 = require("./validation-error");
3
+ exports.validString = exports.isValidString = exports.betweenValues = exports.isBetweenValues = exports.maxValue = exports.isMaxValue = exports.minValue = exports.isMinValue = exports.number = exports.isNumber = exports.minLength = exports.isMinLength = exports.maxLength = exports.isMaxLength = exports.email = exports.isEmail = exports.match = exports.isMatch = exports.notBlank = exports.isNotBlank = exports.notEmpty = exports.isNotEmpty = exports.notNull = exports.isNotNull = void 0;
4
+ const errors_1 = require("../errors");
5
+ /**
6
+ * Tests if a value is null or undefined.
7
+ *
8
+ * @param o the value to check
9
+ */
10
+ function isNotNull(o) {
11
+ return o !== undefined && o !== null;
12
+ }
13
+ exports.isNotNull = isNotNull;
5
14
  /**
6
15
  * Throws a ValidationError if the value is null or undefined.
7
16
  * This function also asserts the value to be NonNullable if the check passes.
@@ -10,11 +19,20 @@ const validation_error_1 = require("./validation-error");
10
19
  * @param o the value to check
11
20
  */
12
21
  function notNull(name, o) {
13
- if (o === undefined || o === null) {
14
- throw new validation_error_1.ValidationError(`${name} may not be null or undefined`);
22
+ if (!isNotNull(o)) {
23
+ throw new errors_1.ValidationError(`${name} may not be null or undefined`);
15
24
  }
16
25
  }
17
26
  exports.notNull = notNull;
27
+ /**
28
+ * Tests if a value is empty, null, undefined or has a length of 0.
29
+ *
30
+ * @param o the value to check
31
+ */
32
+ function isNotEmpty(o) {
33
+ return !(o === undefined || o === null || o.toString().length === 0);
34
+ }
35
+ exports.isNotEmpty = isNotEmpty;
18
36
  /**
19
37
  * Throws a ValidationError if the value is null, undefined or the length is 0.
20
38
  * This function also asserts the value to be NonNullable if the check passes.
@@ -23,11 +41,20 @@ exports.notNull = notNull;
23
41
  * @param o the value to check
24
42
  */
25
43
  function notEmpty(name, o) {
26
- if (o === undefined || o === null || o.toString().length === 0) {
27
- throw new validation_error_1.ValidationError(`${name} may not be empty`);
44
+ if (!isNotEmpty(o)) {
45
+ throw new errors_1.ValidationError(`${name} may not be empty`);
28
46
  }
29
47
  }
30
48
  exports.notEmpty = notEmpty;
49
+ /**
50
+ * Tests if a value is null, undefined, has a length of 0 or contains only whitespace.
51
+ *
52
+ * @param o the value to check
53
+ */
54
+ function isNotBlank(o) {
55
+ return !(o === undefined || o === null || o.toString().trim().length === 0);
56
+ }
57
+ exports.isNotBlank = isNotBlank;
31
58
  /**
32
59
  * Throws a ValidationError if the value is null, undefined, has a length of 0 or contains only whitespace.
33
60
  * This function also asserts the value to be NonNullable if the check passes.
@@ -36,25 +63,50 @@ exports.notEmpty = notEmpty;
36
63
  * @param o the value to check
37
64
  */
38
65
  function notBlank(name, o) {
39
- if (o === undefined || o === null || o.toString().trim().length === 0) {
40
- throw new validation_error_1.ValidationError(`${name} may not be blank`);
66
+ if (!isNotBlank(o)) {
67
+ throw new errors_1.ValidationError(`${name} may not be blank`);
41
68
  }
42
69
  }
43
70
  exports.notBlank = notBlank;
44
71
  /**
45
- * Throws a ValidationError if the value does not match the regular expression provided.
72
+ * Tests if a value does not match the regular expression provided.
73
+ * Undefined and null values are skipped and not tested.
74
+ *
75
+ * @param regex the regular expression to test with
76
+ * @param o the value to check
77
+ */
78
+ function isMatch(regex, o) {
79
+ if (o === undefined || o === null) {
80
+ return true;
81
+ }
82
+ return o.match(regex) !== null;
83
+ }
84
+ exports.isMatch = isMatch;
85
+ /**
86
+ * Throws a ValidationError if the value matches the regular expression provided.
46
87
  * Undefined and null values are skipped and not validated.
47
88
  *
48
89
  * @param name the name of the variable
49
90
  * @param regex the regular expression to validate with
50
91
  * @param o the value to check
51
92
  */
52
- function matches(name, regex, o) {
53
- if (o !== undefined && o !== null && !o.match(regex)) {
54
- throw new validation_error_1.ValidationError(`${name} must match ${regex}`);
93
+ function match(name, regex, o) {
94
+ if (!isMatch(regex, o)) {
95
+ throw new errors_1.ValidationError(`${name} must match ${regex}`);
55
96
  }
56
97
  }
57
- exports.matches = matches;
98
+ exports.match = match;
99
+ /**
100
+ * Tests if a value is a valid email address.
101
+ * Undefined and null values are skipped and not validated.
102
+ *
103
+ * @param o the value to check
104
+ */
105
+ function isEmail(o) {
106
+ const expression = /^(?=.{1,254}$)(?=.{1,64}@)[-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+(\.[-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+)*@[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?(\.[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?)*$/;
107
+ return !(o !== undefined && o !== null && !expression.test(o));
108
+ }
109
+ exports.isEmail = isEmail;
58
110
  /**
59
111
  * Throws a ValidationError if the value provided is not an email.
60
112
  * Undefined and null values are skipped and not validated.
@@ -62,13 +114,23 @@ exports.matches = matches;
62
114
  * @param name the name of the variable
63
115
  * @param o the value to check
64
116
  */
65
- function isEmail(name, o) {
66
- const expression = /^(?=.{1,254}$)(?=.{1,64}@)[-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+(\.[-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+)*@[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?(\.[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?)*$/;
67
- if (o !== undefined && o !== null && !expression.test(o)) {
68
- throw new validation_error_1.ValidationError(`${name} is not a valid email address`);
117
+ function email(name, o) {
118
+ if (!isEmail(o)) {
119
+ throw new errors_1.ValidationError(`${name} is not a valid email address`);
69
120
  }
70
121
  }
71
- exports.isEmail = isEmail;
122
+ exports.email = email;
123
+ /**
124
+ * Tests if a value has a length that is less than the provided length.
125
+ * Undefined and null values are skipped and not validated.
126
+ *
127
+ * @param length the maximum length of the variable
128
+ * @param o the value to check
129
+ */
130
+ function isMaxLength(length, o) {
131
+ return !(o !== undefined && o !== null && o.length > length);
132
+ }
133
+ exports.isMaxLength = isMaxLength;
72
134
  /**
73
135
  * Throws a ValidationError if the value provided has a length that exceeds the provided length.
74
136
  * Undefined and null values are skipped and not validated.
@@ -78,11 +140,22 @@ exports.isEmail = isEmail;
78
140
  * @param o the value to check
79
141
  */
80
142
  function maxLength(name, length, o) {
81
- if (o !== undefined && o !== null && o.length > length) {
82
- throw new validation_error_1.ValidationError(`length of ${name} may not exceed ${length}`);
143
+ if (!isMaxLength(length, o)) {
144
+ throw new errors_1.ValidationError(`length of ${name} may not exceed ${length}`);
83
145
  }
84
146
  }
85
147
  exports.maxLength = maxLength;
148
+ /**
149
+ * Tests if a value has a length that is greater than the provided length.
150
+ * Undefined and null values are skipped and not validated.
151
+ *
152
+ * @param length the minimum length of the variable
153
+ * @param o the value to check
154
+ */
155
+ function isMinLength(length, o) {
156
+ return !(o !== undefined && o !== null && o.length < length);
157
+ }
158
+ exports.isMinLength = isMinLength;
86
159
  /**
87
160
  * Throws a ValidationError if the value provided has a length that is less than the provided length.
88
161
  * Undefined and null values are skipped and not validated.
@@ -92,11 +165,21 @@ exports.maxLength = maxLength;
92
165
  * @param o the value to check
93
166
  */
94
167
  function minLength(name, length, o) {
95
- if (o !== undefined && o !== null && o.length < length) {
96
- throw new validation_error_1.ValidationError(`length of ${name} may not be less than ${length}`);
168
+ if (!isMinLength(length, o)) {
169
+ throw new errors_1.ValidationError(`length of ${name} may not be less than ${length}`);
97
170
  }
98
171
  }
99
172
  exports.minLength = minLength;
173
+ /**
174
+ * Tests if a value provided is a number.
175
+ * Undefined and null values are skipped and not validated.
176
+ *
177
+ * @param o the value to check
178
+ */
179
+ function isNumber(o) {
180
+ return o === undefined || o === null || !isNaN(+o);
181
+ }
182
+ exports.isNumber = isNumber;
100
183
  /**
101
184
  * Throws a ValidationError if the value provided is not a number.
102
185
  * Undefined and null values are skipped and not validated.
@@ -104,12 +187,23 @@ exports.minLength = minLength;
104
187
  * @param name the name of the variable
105
188
  * @param o the value to check
106
189
  */
107
- function isNumber(name, o) {
108
- if (o !== undefined && o !== null && isNaN(Number(o))) {
109
- throw new validation_error_1.ValidationError(`${name} is not a number`);
190
+ function number(name, o) {
191
+ if (!isNumber(o)) {
192
+ throw new errors_1.ValidationError(`${name} is not a number`);
110
193
  }
111
194
  }
112
- exports.isNumber = isNumber;
195
+ exports.number = number;
196
+ /**
197
+ * Tests if a value is less than the provided minimum value.
198
+ * Undefined and null values are skipped and not validated.
199
+ *
200
+ * @param minValue the minimum value allowed
201
+ * @param o the value to check
202
+ */
203
+ function isMinValue(minValue, o) {
204
+ return o === undefined || o === null || +o >= minValue;
205
+ }
206
+ exports.isMinValue = isMinValue;
113
207
  /**
114
208
  * Throws a ValidationError if the value is less than the provided minimum value.
115
209
  * Undefined and null values are skipped and not validated.
@@ -119,16 +213,22 @@ exports.isNumber = isNumber;
119
213
  * @param o the value to check
120
214
  */
121
215
  function minValue(name, minValue, o) {
122
- if (o !== undefined && o !== null) {
123
- if (typeof o === 'string') {
124
- isNumber(name, o);
125
- }
126
- if (+o < minValue) {
127
- throw new validation_error_1.ValidationError(`${name} may not be less than ${minValue}`);
128
- }
216
+ if (!isMinValue(minValue, o)) {
217
+ throw new errors_1.ValidationError(`${name} may not be less than ${minValue}`);
129
218
  }
130
219
  }
131
220
  exports.minValue = minValue;
221
+ /**
222
+ * Tests if a value is more than the provided maximum value.
223
+ * Undefined and null values are skipped and not validated.
224
+ *
225
+ * @param maxValue the maximum value allowed
226
+ * @param o the value to check
227
+ */
228
+ function isMaxValue(maxValue, o) {
229
+ return !(o !== undefined && o !== null && +o > maxValue);
230
+ }
231
+ exports.isMaxValue = isMaxValue;
132
232
  /**
133
233
  * Throws a ValidationError if the value is more than the provided maximum value.
134
234
  * Undefined and null values are skipped and not validated.
@@ -138,16 +238,23 @@ exports.minValue = minValue;
138
238
  * @param o the value to check
139
239
  */
140
240
  function maxValue(name, maxValue, o) {
141
- if (o !== undefined && o !== null) {
142
- if (typeof o === 'string') {
143
- isNumber(name, o);
144
- }
145
- if (+o > maxValue) {
146
- throw new validation_error_1.ValidationError(`${name} may not be greater than ${maxValue}`);
147
- }
241
+ if (!isMaxValue(maxValue, o)) {
242
+ throw new errors_1.ValidationError(`${name} may not be greater than ${maxValue}`);
148
243
  }
149
244
  }
150
245
  exports.maxValue = maxValue;
246
+ /**
247
+ * Tests if the value is between the provided minimum and maximum values inclusive.
248
+ * Undefined and null values are skipped and not validated.
249
+ *
250
+ * @param minValue the minimum value allowed
251
+ * @param maxValue the maximum value allowed
252
+ * @param o the value to check
253
+ */
254
+ function isBetweenValues(minValue, maxValue, o) {
255
+ return !(o !== undefined && o !== null && (+o < minValue || +o > maxValue));
256
+ }
257
+ exports.isBetweenValues = isBetweenValues;
151
258
  /**
152
259
  * Throws a ValidationError if the value is not between the provided minimum and maximum values inclusive.
153
260
  * Undefined and null values are skipped and not validated.
@@ -158,48 +265,65 @@ exports.maxValue = maxValue;
158
265
  * @param o the value to check
159
266
  */
160
267
  function betweenValues(name, minValue, maxValue, o) {
161
- if (o !== undefined && o !== null) {
162
- if (typeof o === 'string') {
163
- isNumber(name, o);
164
- }
165
- if (+o < minValue || +o > maxValue) {
166
- throw new validation_error_1.ValidationError(`${name} must be between ${minValue} and ${maxValue}`);
167
- }
268
+ if (!isBetweenValues(minValue, maxValue, o)) {
269
+ throw new errors_1.ValidationError(`${name} must be between ${minValue} and ${maxValue}`);
168
270
  }
169
271
  }
170
272
  exports.betweenValues = betweenValues;
171
273
  const isString = (value) => typeof value === 'string';
172
- function validateString(options, value) {
274
+ function isValidString(options, value) {
173
275
  if (options.required) {
174
- notNull(options.name, value);
276
+ if (!isNotNull(value)) {
277
+ return false;
278
+ }
175
279
  }
176
280
  else if (value === undefined || value === null) {
177
- return;
281
+ return true;
178
282
  }
179
283
  if (!isString(value)) {
180
- throw new validation_error_1.ValidationError(`${options.name} must be a string`);
284
+ return false;
181
285
  }
182
- if (options.minLength !== undefined && value.length < options.minLength) {
183
- throw new validation_error_1.ValidationError(`${options.name} must be at least ${options.minLength} characters`);
286
+ if (options.minLength && !isMinLength(options.minLength, value)) {
287
+ return false;
184
288
  }
185
- if (options.maxLength !== undefined && value.length > options.maxLength) {
186
- throw new validation_error_1.ValidationError(`${options.name} must be at most ${options.maxLength} characters`);
289
+ if (options.maxLength && !isMaxLength(options.maxLength, value)) {
290
+ return false;
187
291
  }
188
- if (options.regex !== undefined && !options.regex.test(value)) {
189
- throw new validation_error_1.ValidationError(`${options.name} must match ${options.regex}`);
292
+ if (options.regex && !isMatch(options.regex, value)) {
293
+ return false;
190
294
  }
191
- if (options.notBlank !== undefined && options.notBlank) {
192
- notBlank(options.name, value);
295
+ if (options.notBlank && !isNotBlank(value)) {
296
+ return false;
193
297
  }
194
- if (options.notEmpty !== undefined && options.notEmpty) {
195
- notEmpty(options.name, value);
298
+ if (options.notEmpty && !isNotEmpty(value)) {
299
+ return false;
196
300
  }
197
- if (options.isEmail !== undefined && options.isEmail) {
198
- isEmail(options.name, value);
301
+ if (options.email && !isEmail(value)) {
302
+ return false;
199
303
  }
200
- if (options.isNumber !== undefined && options.isNumber) {
201
- isNumber(options.name, value);
304
+ if (options.number && !isNumber(value)) {
305
+ return false;
306
+ }
307
+ return true;
308
+ }
309
+ exports.isValidString = isValidString;
310
+ function validString(name, options, value) {
311
+ if (options.required) {
312
+ notNull(name, value);
313
+ }
314
+ else if (value === undefined || value === null) {
315
+ return;
316
+ }
317
+ if (!isString(value)) {
318
+ throw new errors_1.ValidationError(`${name} must be a string`);
202
319
  }
320
+ options.minLength && minLength(name, options.minLength, value);
321
+ options.maxLength && maxLength(name, options.maxLength, value);
322
+ options.regex && match(name, options.regex, value);
323
+ options.notBlank && notBlank(name, value);
324
+ options.notEmpty && notEmpty(name, value);
325
+ options.email && email(name, value);
326
+ options.number && number(name, value);
203
327
  }
204
- exports.validateString = validateString;
328
+ exports.validString = validString;
205
329
  //# sourceMappingURL=validators.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"validators.js","sourceRoot":"","sources":["validators.ts"],"names":[],"mappings":";;;AAAA,yDAAmD;AAEnD;;;;;;GAMG;AACH,SAAgB,OAAO,CACrB,IAAY,EACZ,CAAW;IAEX,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,IAAI,EAAE;QACjC,MAAM,IAAI,kCAAe,CAAC,GAAG,IAAI,+BAA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AC,CAAC;KACtB;SAAM,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE;QAChD,OAAO;KACR;IACD,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;QACpB,MAAM,IAAI,wBAAe,CAAC,GAAG,IAAI,mBAAmB,CAAC,CAAC;KACvD;IACD,OAAO,CAAC,SAAS,IAAI,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAC/D,OAAO,CAAC,SAAS,IAAI,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAC/D,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACnD,OAAO,CAAC,QAAQ,IAAI,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC1C,OAAO,CAAC,QAAQ,IAAI,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC1C,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACpC,OAAO,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AACxC,CAAC;AApBD,kCAoBC"}
@@ -1,19 +0,0 @@
1
- export type PossibleValidationError = {
2
- stack?: string;
3
- message?: string;
4
- name?: string;
5
- statusCode?: number;
6
- };
7
- /**
8
- * Checks if the given variable is a ValidationError.
9
- *
10
- * @param e the variable to check
11
- */
12
- export declare function isValidationError(e?: PossibleValidationError): e is ValidationError;
13
- /**
14
- * Thrown when a validation error occurs.
15
- */
16
- export declare class ValidationError extends Error {
17
- statusCode: number;
18
- constructor(message?: string, statusCode?: number);
19
- }
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ValidationError = exports.isValidationError = void 0;
4
- /**
5
- * Checks if the given variable is a ValidationError.
6
- *
7
- * @param e the variable to check
8
- */
9
- function isValidationError(e) {
10
- return !!(e &&
11
- e.stack &&
12
- e.message &&
13
- e.statusCode &&
14
- e.name === 'ValidationError');
15
- }
16
- exports.isValidationError = isValidationError;
17
- /**
18
- * Thrown when a validation error occurs.
19
- */
20
- class ValidationError extends Error {
21
- constructor(message, statusCode) {
22
- super(message !== null && message !== void 0 ? message : 'Validation error');
23
- this.name = 'ValidationError';
24
- this.statusCode = statusCode !== null && statusCode !== void 0 ? statusCode : 400;
25
- }
26
- }
27
- exports.ValidationError = ValidationError;
28
- //# sourceMappingURL=validation-error.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validation-error.js","sourceRoot":"","sources":["validation-error.ts"],"names":[],"mappings":";;;AAOA;;;;GAIG;AACH,SAAgB,iBAAiB,CAC/B,CAA2B;IAE3B,OAAO,CAAC,CAAC,CACP,CAAC;QACD,CAAC,CAAC,KAAK;QACP,CAAC,CAAC,OAAO;QACT,CAAC,CAAC,UAAU;QACZ,CAAC,CAAC,IAAI,KAAK,iBAAiB,CAC7B,CAAC;AACJ,CAAC;AAVD,8CAUC;AAED;;GAEG;AACH,MAAa,eAAgB,SAAQ,KAAK;IAGxC,YAAY,OAAgB,EAAE,UAAmB;QAC/C,KAAK,CAAC,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,kBAAkB,CAAC,CAAC;QACrC,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;QAC9B,IAAI,CAAC,UAAU,GAAG,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,GAAG,CAAC;IACtC,CAAC;CACF;AARD,0CAQC"}