@noldova/context.exceptions 0.0.0-stage → 0.0.2
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 +21 -0
- package/api/index.d.ts +290 -0
- package/api/index.js +14 -0
- package/api/index.js.map +1 -0
- package/exceptions/argument-null.exception.js +19 -0
- package/exceptions/argument-null.exception.js.map +1 -0
- package/exceptions/argument-out-of-range.exception.js +21 -0
- package/exceptions/argument-out-of-range.exception.js.map +1 -0
- package/exceptions/argument.exception.js +33 -0
- package/exceptions/argument.exception.js.map +1 -0
- package/exceptions/exception.js +14 -0
- package/exceptions/exception.js.map +1 -0
- package/exceptions/index-out-of-range.exception.js +15 -0
- package/exceptions/index-out-of-range.exception.js.map +1 -0
- package/models/exception-options.js +14 -0
- package/models/exception-options.js.map +1 -0
- package/package.json +22 -4
- package/resources.js +23 -0
- package/resources.js.map +1 -0
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Noldova
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/api/index.d.ts
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import "@noldova/context.core";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Options shared by every CONTEXT exception. Pass the preceding failure as
|
|
13
|
+
* `cause` when translating an error without losing its original context.
|
|
14
|
+
*/
|
|
15
|
+
export declare class ExceptionOptions implements ErrorOptions {
|
|
16
|
+
/**
|
|
17
|
+
* The preceding failure, or `undefined` when omitted. Any value is retained
|
|
18
|
+
* unchanged, including `null`, `false`, zero, and an empty string. Objects
|
|
19
|
+
* are shared by reference, not cloned or converted into another exception.
|
|
20
|
+
*/
|
|
21
|
+
public readonly cause: unknown;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Records the cause to supply when constructing an exception.
|
|
25
|
+
*
|
|
26
|
+
* @param cause The original caught value or other failure information. It
|
|
27
|
+
* need not be an `Error`; omission leaves {@link ExceptionOptions.cause}
|
|
28
|
+
* undefined. No truthiness check, formatting, or wrapping is performed.
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { ArgumentException, ExceptionOptions } from "@noldova/context.exceptions";
|
|
32
|
+
*
|
|
33
|
+
* const cause = new Error("Invalid encoded input.");
|
|
34
|
+
* const exception = new ArgumentException("Cannot read input.", "input",
|
|
35
|
+
* new ExceptionOptions(cause));
|
|
36
|
+
* exception.cause === cause; // true
|
|
37
|
+
* new ExceptionOptions(0).cause; // 0, not an absent cause.
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
public constructor(cause?: unknown);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The abstract base of CONTEXT exceptions, extending `Error`. The inherited
|
|
45
|
+
* `name` is set to the concrete class name; `cause` retains the supplied
|
|
46
|
+
* preceding failure, and `stack` is supplied by the host.
|
|
47
|
+
*
|
|
48
|
+
* Constructing an exception does not throw it. Raise it with `throw` or an
|
|
49
|
+
* exception-owned guard. Subclasses supply a meaningful concrete identity;
|
|
50
|
+
* they do not need to assign `name` themselves.
|
|
51
|
+
*/
|
|
52
|
+
export declare abstract class Exception extends Error {
|
|
53
|
+
/**
|
|
54
|
+
* Initializes the message, cause, and concrete class name for a subclass.
|
|
55
|
+
*
|
|
56
|
+
* @param message The complete explanation, preserved verbatim. There is no
|
|
57
|
+
* base default, trimming, or rejection of an explicitly empty string.
|
|
58
|
+
* @param options Optional failure context. Omission supplies no cause;
|
|
59
|
+
* otherwise the value of {@link ExceptionOptions.cause} is retained unchanged.
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* import { Exception, type ExceptionOptions } from "@noldova/context.exceptions";
|
|
63
|
+
*
|
|
64
|
+
* class InputException extends Exception {
|
|
65
|
+
* public constructor(message: string, options?: ExceptionOptions) {
|
|
66
|
+
* super(message, options);
|
|
67
|
+
* }
|
|
68
|
+
* }
|
|
69
|
+
* const exception = new InputException("Cannot read input.");
|
|
70
|
+
* exception.name; // "InputException"
|
|
71
|
+
* exception instanceof Error; // true
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
protected constructor(message: string, options?: ExceptionOptions);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The exception that is thrown when an argument does not meet the parameter
|
|
79
|
+
* contract of the called method.
|
|
80
|
+
*/
|
|
81
|
+
export declare class ArgumentException extends Exception {
|
|
82
|
+
/**
|
|
83
|
+
* The supplied parameter name, preserved verbatim, or `undefined` when
|
|
84
|
+
* omitted. A supplied name is also appended to the message as `(Parameter 'name')`.
|
|
85
|
+
*/
|
|
86
|
+
public readonly parameterName: string | undefined;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Creates an invalid-argument exception; the message is the first argument.
|
|
90
|
+
*
|
|
91
|
+
* @param message The explanation before any parameter suffix. Omission or
|
|
92
|
+
* `undefined` uses `"Value does not fall within the expected range."`.
|
|
93
|
+
* An explicitly empty string is preserved.
|
|
94
|
+
* @param parameterName The offending parameter's name, or `undefined` to
|
|
95
|
+
* omit the suffix. A supplied name is stored and appended without normalization.
|
|
96
|
+
* @param options Optional context retaining the original cause unchanged.
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* import { ArgumentException } from "@noldova/context.exceptions";
|
|
100
|
+
*
|
|
101
|
+
* const exception = new ArgumentException("Bad value.", "input");
|
|
102
|
+
* exception.message; // "Bad value. (Parameter 'input')"
|
|
103
|
+
* new ArgumentException("").message; // "", not the default message.
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
public constructor(message?: string, parameterName?: string, options?: ExceptionOptions);
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Requires a present, nonempty string. Returning normally narrows the
|
|
110
|
+
* caller's value to `string`; it does not trim or otherwise change it.
|
|
111
|
+
*
|
|
112
|
+
* @param value The string or nullish value to validate. Nonempty whitespace
|
|
113
|
+
* is accepted; use {@link ArgumentException.throwIfNullOrWhitespace} to reject it.
|
|
114
|
+
* @param parameterName The caller's parameter name, included in the thrown
|
|
115
|
+
* exception's metadata and message. It is supplied explicitly, not inferred.
|
|
116
|
+
* @throws {ArgumentException} If `value` is null, undefined, or empty. This
|
|
117
|
+
* guard uses `ArgumentException` even for nullish input, not `ArgumentNullException`.
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* const input = new Map([["input", "value"]]).get("input");
|
|
121
|
+
* ArgumentException.throwIfNullOrEmpty(input, "input");
|
|
122
|
+
* input.length; // 5; the guard excludes undefined from the lookup result.
|
|
123
|
+
* ArgumentException.throwIfNullOrEmpty(" ", "input"); // Accepted.
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
public static throwIfNullOrEmpty(value: string | null | undefined, parameterName: string): asserts value is string;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Requires a string containing a non-whitespace character. Returning
|
|
130
|
+
* normally narrows the caller's value to `string` without trimming it.
|
|
131
|
+
*
|
|
132
|
+
* @param value The string or nullish value to validate. Whitespace follows
|
|
133
|
+
* the characters removed by the host's `String.trim`, including line terminators.
|
|
134
|
+
* @param parameterName The caller's parameter name, included in the exception.
|
|
135
|
+
* @throws {ArgumentException} If `value` is null, undefined, empty, or
|
|
136
|
+
* whitespace-only. Nullish input still throws `ArgumentException`.
|
|
137
|
+
* @example
|
|
138
|
+
* ```ts
|
|
139
|
+
* import { ArgumentException } from "@noldova/context.exceptions";
|
|
140
|
+
*
|
|
141
|
+
* const input = new Map([["input", " value "]]).get("input");
|
|
142
|
+
* ArgumentException.throwIfNullOrWhitespace(input, "input");
|
|
143
|
+
* input.length; // 7: surrounding spaces are preserved.
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
public static throwIfNullOrWhitespace(value: string | null | undefined, parameterName: string): asserts value is string;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Requires at least one element and narrows the array to a non-empty
|
|
150
|
+
* readonly tuple so its first element can be accessed without an undefined check.
|
|
151
|
+
*
|
|
152
|
+
* @template T The array's element type, which is not inspected or narrowed.
|
|
153
|
+
* @param value The array to validate. It is not copied, mutated, or retained;
|
|
154
|
+
* this check establishes its length at the call, not permanent immutability.
|
|
155
|
+
* @param parameterName The caller's parameter name, included in the exception.
|
|
156
|
+
* @throws {ArgumentException} If the array contains no elements.
|
|
157
|
+
* @example
|
|
158
|
+
* ```ts
|
|
159
|
+
* import { ArgumentException } from "@noldova/context.exceptions";
|
|
160
|
+
*
|
|
161
|
+
* const values: readonly string[] = ["value"];
|
|
162
|
+
* ArgumentException.throwIfEmpty(values, "values");
|
|
163
|
+
* values[0].length; // 5
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
public static throwIfEmpty<T>(value: readonly T[], parameterName: string): asserts value is readonly [T, ...T[]];
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* The exception that is thrown when a null or undefined argument is passed
|
|
171
|
+
* to a method that does not accept one. It specializes {@link ArgumentException};
|
|
172
|
+
* unlike the base constructor, its constructor takes `parameterName` first.
|
|
173
|
+
*/
|
|
174
|
+
export declare class ArgumentNullException extends ArgumentException {
|
|
175
|
+
/**
|
|
176
|
+
* Creates a null-argument exception for the supplied parameter.
|
|
177
|
+
*
|
|
178
|
+
* @param parameterName The offending parameter's name, or `undefined` to
|
|
179
|
+
* omit the message suffix and leave the metadata undefined.
|
|
180
|
+
* @param message The explanation before the suffix. Omission or `undefined`
|
|
181
|
+
* uses `"Value cannot be null or undefined."`; an explicit empty string is kept.
|
|
182
|
+
* @param options Optional context retaining the original cause unchanged.
|
|
183
|
+
* @example
|
|
184
|
+
* ```ts
|
|
185
|
+
* import { ArgumentNullException } from "@noldova/context.exceptions";
|
|
186
|
+
*
|
|
187
|
+
* const exception = new ArgumentNullException("input");
|
|
188
|
+
* exception.parameterName; // "input"
|
|
189
|
+
* exception.message; // "Value cannot be null or undefined. (Parameter 'input')"
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
public constructor(parameterName?: string, message?: string, options?: ExceptionOptions);
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Requires a non-nullish value and narrows it to `NonNullable<T>` on return.
|
|
196
|
+
*
|
|
197
|
+
* @template T The input type, which may include null or undefined.
|
|
198
|
+
* @param value The value to validate without conversion. Other falsy values,
|
|
199
|
+
* including zero, `false`, and the empty string, are accepted unchanged.
|
|
200
|
+
* @param parameterName The caller's parameter name, included in the exception.
|
|
201
|
+
* @throws {ArgumentNullException} If `value` is null or undefined.
|
|
202
|
+
* @example
|
|
203
|
+
* ```ts
|
|
204
|
+
* const count = new Map([["count", 0]]).get("count");
|
|
205
|
+
* ArgumentNullException.throwIfNull(count, "count");
|
|
206
|
+
* count + 1; // 1: zero is a valid non-nullish value.
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
209
|
+
public static throwIfNull<T>(value: T, parameterName: string): asserts value is NonNullable<T>;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* The exception that is thrown when an argument lies outside the range
|
|
214
|
+
* accepted by the called method.
|
|
215
|
+
*/
|
|
216
|
+
export declare class ArgumentOutOfRangeException extends ArgumentException {
|
|
217
|
+
/**
|
|
218
|
+
* The rejected value, or `undefined` when omitted. Objects and other values
|
|
219
|
+
* are retained unchanged, not cloned or converted. This is separate metadata;
|
|
220
|
+
* it is not automatically inserted into the exception message.
|
|
221
|
+
*/
|
|
222
|
+
public readonly actualValue: unknown;
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Creates a range exception; the parameter name and rejected value come first.
|
|
226
|
+
*
|
|
227
|
+
* @param parameterName The offending parameter's name, or `undefined` to
|
|
228
|
+
* omit the suffix and leave {@link ArgumentException.parameterName} undefined.
|
|
229
|
+
* @param actualValue The rejected value to retain for inspection. Omission
|
|
230
|
+
* leaves {@link ArgumentOutOfRangeException.actualValue} undefined.
|
|
231
|
+
* @param message The explanation before the suffix. Omission or `undefined`
|
|
232
|
+
* uses `"The argument must be within the valid range."`; an empty string is kept.
|
|
233
|
+
* @param options Optional context retaining the original cause unchanged.
|
|
234
|
+
* @example
|
|
235
|
+
* ```ts
|
|
236
|
+
* import { ArgumentOutOfRangeException } from "@noldova/context.exceptions";
|
|
237
|
+
*
|
|
238
|
+
* const exception = new ArgumentOutOfRangeException("index", 5, "Invalid index.");
|
|
239
|
+
* exception.actualValue; // 5
|
|
240
|
+
* exception.message; // "Invalid index. (Parameter 'index')"
|
|
241
|
+
* ```
|
|
242
|
+
*/
|
|
243
|
+
public constructor(parameterName?: string, actualValue?: unknown, message?: string, options?: ExceptionOptions);
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Requires a finite positive integer, using the `Number.isInteger` classification.
|
|
247
|
+
* It does not establish a narrower TypeScript type and returns no value.
|
|
248
|
+
*
|
|
249
|
+
* @param value The number to validate. It must be greater than zero and have
|
|
250
|
+
* no fractional part. This is not a safe-integer check; callers enforce any
|
|
251
|
+
* precision requirement or application-specific upper limit separately.
|
|
252
|
+
* @param parameterName The caller's parameter name, included in the exception.
|
|
253
|
+
* @param message An optional explanation replacing the default out-of-range
|
|
254
|
+
* text. The parameter suffix is still appended; an explicit empty message is kept.
|
|
255
|
+
* @throws {ArgumentOutOfRangeException} If the value is zero, negative,
|
|
256
|
+
* fractional, `NaN`, or either infinity. The exception retains `parameterName`
|
|
257
|
+
* and the rejected number as `actualValue`.
|
|
258
|
+
* @example
|
|
259
|
+
* ```ts
|
|
260
|
+
* import { ArgumentOutOfRangeException } from "@noldova/context.exceptions";
|
|
261
|
+
*
|
|
262
|
+
* ArgumentOutOfRangeException.throwIfNotPositiveInteger(1, "count"); // Accepted.
|
|
263
|
+
* ArgumentOutOfRangeException.throwIfNotPositiveInteger(
|
|
264
|
+
* Number.MAX_SAFE_INTEGER + 1, "count"); // Also accepted: no safe-integer limit.
|
|
265
|
+
* ```
|
|
266
|
+
*/
|
|
267
|
+
public static throwIfNotPositiveInteger(value: number, parameterName: string, message?: string): void;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* The exception that is thrown when indexed access addresses no element of
|
|
272
|
+
* the target collection or span.
|
|
273
|
+
*/
|
|
274
|
+
export declare class IndexOutOfRangeException extends Exception {
|
|
275
|
+
/**
|
|
276
|
+
* Creates an exception describing invalid indexed access.
|
|
277
|
+
*
|
|
278
|
+
* @param message The explanation. Omission or `undefined` uses
|
|
279
|
+
* `"The index must be within the valid range."`. An empty string is preserved.
|
|
280
|
+
* @param options Optional context retaining the original cause unchanged.
|
|
281
|
+
* @example
|
|
282
|
+
* ```ts
|
|
283
|
+
* import { IndexOutOfRangeException } from "@noldova/context.exceptions";
|
|
284
|
+
*
|
|
285
|
+
* new IndexOutOfRangeException().message; // "The index must be within the valid range."
|
|
286
|
+
* new IndexOutOfRangeException("").message; // ""
|
|
287
|
+
* ```
|
|
288
|
+
*/
|
|
289
|
+
public constructor(message?: string, options?: ExceptionOptions);
|
|
290
|
+
}
|
package/api/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
export { ArgumentException } from "../exceptions/argument.exception.js";
|
|
9
|
+
export { ArgumentNullException } from "../exceptions/argument-null.exception.js";
|
|
10
|
+
export { ArgumentOutOfRangeException } from "../exceptions/argument-out-of-range.exception.js";
|
|
11
|
+
export { Exception } from "../exceptions/exception.js";
|
|
12
|
+
export { IndexOutOfRangeException } from "../exceptions/index-out-of-range.exception.js";
|
|
13
|
+
export { ExceptionOptions } from "../models/exception-options.js";
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
package/api/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/noldova.context.exceptions/src/api/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAC;AACjF,OAAO,EAAE,2BAA2B,EAAE,MAAM,kDAAkD,CAAC;AAC/F,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+CAA+C,CAAC;AACzF,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { Resources } from "../resources.js";
|
|
9
|
+
import { ArgumentException } from "./argument.exception.js";
|
|
10
|
+
export class ArgumentNullException extends ArgumentException {
|
|
11
|
+
constructor(parameterName, message, options) {
|
|
12
|
+
super(message ?? Resources.argumentNull, parameterName, options);
|
|
13
|
+
}
|
|
14
|
+
static throwIfNull(value, parameterName) {
|
|
15
|
+
if (Object.isNullOrUndefined(value))
|
|
16
|
+
throw new ArgumentNullException(parameterName);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=argument-null.exception.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"argument-null.exception.js","sourceRoot":"","sources":["../../../../src/noldova.context.exceptions/src/exceptions/argument-null.exception.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,MAAM,OAAO,qBAAsB,SAAQ,iBAAiB;IAC1D,YAAmB,aAAsB,EAAE,OAAgB,EAAE,OAA0B;QACrF,KAAK,CAAC,OAAO,IAAI,SAAS,CAAC,YAAY,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;IACnE,CAAC;IAEM,MAAM,CAAC,WAAW,CAAI,KAAQ,EAAE,aAAqB;QAC1D,IAAI,MAAM,CAAC,iBAAiB,CAAC,KAAK,CAAC;YACjC,MAAM,IAAI,qBAAqB,CAAC,aAAa,CAAC,CAAC;IACnD,CAAC;CACF"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { Resources } from "../resources.js";
|
|
9
|
+
import { ArgumentException } from "./argument.exception.js";
|
|
10
|
+
export class ArgumentOutOfRangeException extends ArgumentException {
|
|
11
|
+
actualValue;
|
|
12
|
+
constructor(parameterName, actualValue, message, options) {
|
|
13
|
+
super(message ?? Resources.argumentOutOfRange, parameterName, options);
|
|
14
|
+
this.actualValue = actualValue;
|
|
15
|
+
}
|
|
16
|
+
static throwIfNotPositiveInteger(value, parameterName, message) {
|
|
17
|
+
if (!Number.isInteger(value) || value <= 0)
|
|
18
|
+
throw new ArgumentOutOfRangeException(parameterName, value, message);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=argument-out-of-range.exception.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"argument-out-of-range.exception.js","sourceRoot":"","sources":["../../../../src/noldova.context.exceptions/src/exceptions/argument-out-of-range.exception.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,MAAM,OAAO,2BAA4B,SAAQ,iBAAiB;IAChD,WAAW,CAAU;IAErC,YAAmB,aAAsB,EAAE,WAAqB,EAAE,OAAgB,EAAE,OAA0B;QAC5G,KAAK,CAAC,OAAO,IAAI,SAAS,CAAC,kBAAkB,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;QAEvE,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IAEM,MAAM,CAAC,yBAAyB,CAAC,KAAa,EAAE,aAAqB,EAAE,OAAgB;QAC5F,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC;YACxC,MAAM,IAAI,2BAA2B,CAAC,aAAa,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;IACzE,CAAC;CACF"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import "@noldova/context.core";
|
|
9
|
+
import { Resources } from "../resources.js";
|
|
10
|
+
import { Exception } from "./exception.js";
|
|
11
|
+
export class ArgumentException extends Exception {
|
|
12
|
+
parameterName;
|
|
13
|
+
constructor(message, parameterName, options) {
|
|
14
|
+
super(Resources.formatArgumentMessage(message ?? Resources.argumentInvalid, parameterName), options);
|
|
15
|
+
this.parameterName = parameterName;
|
|
16
|
+
}
|
|
17
|
+
static throwIfNullOrEmpty(value, parameterName) {
|
|
18
|
+
if (Object.isNullOrUndefined(value))
|
|
19
|
+
throw new ArgumentException(Resources.argumentNull, parameterName);
|
|
20
|
+
if (value === String.empty)
|
|
21
|
+
throw new ArgumentException(Resources.argumentEmpty, parameterName);
|
|
22
|
+
}
|
|
23
|
+
static throwIfNullOrWhitespace(value, parameterName) {
|
|
24
|
+
ArgumentException.throwIfNullOrEmpty(value, parameterName);
|
|
25
|
+
if (String.isNullOrWhitespace(value))
|
|
26
|
+
throw new ArgumentException(Resources.argumentWhitespace, parameterName);
|
|
27
|
+
}
|
|
28
|
+
static throwIfEmpty(value, parameterName) {
|
|
29
|
+
if (value.length === 0)
|
|
30
|
+
throw new ArgumentException(Resources.argumentCollectionEmpty, parameterName);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=argument.exception.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"argument.exception.js","sourceRoot":"","sources":["../../../../src/noldova.context.exceptions/src/exceptions/argument.exception.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,uBAAuB,CAAC;AAG/B,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,MAAM,OAAO,iBAAkB,SAAQ,SAAS;IAC9B,aAAa,CAAqB;IAElD,YAAmB,OAAgB,EAAE,aAAsB,EAAE,OAA0B;QACrF,KAAK,CAAC,SAAS,CAAC,qBAAqB,CAAC,OAAO,IAAI,SAAS,CAAC,eAAe,EAAE,aAAa,CAAC,EAAE,OAAO,CAAC,CAAC;QAErG,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;IAEM,MAAM,CAAC,kBAAkB,CAAC,KAAgC,EAAE,aAAqB;QACtF,IAAI,MAAM,CAAC,iBAAiB,CAAC,KAAK,CAAC;YACjC,MAAM,IAAI,iBAAiB,CAAC,SAAS,CAAC,YAAY,EAAE,aAAa,CAAC,CAAC;QAErE,IAAI,KAAK,KAAK,MAAM,CAAC,KAAK;YACxB,MAAM,IAAI,iBAAiB,CAAC,SAAS,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;IACxE,CAAC;IAEM,MAAM,CAAC,uBAAuB,CAAC,KAAgC,EAAE,aAAqB;QAC3F,iBAAiB,CAAC,kBAAkB,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;QAE3D,IAAI,MAAM,CAAC,kBAAkB,CAAC,KAAK,CAAC;YAClC,MAAM,IAAI,iBAAiB,CAAC,SAAS,CAAC,kBAAkB,EAAE,aAAa,CAAC,CAAC;IAC7E,CAAC;IAEM,MAAM,CAAC,YAAY,CAAI,KAAmB,EAAE,aAAqB;QACtE,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;YACpB,MAAM,IAAI,iBAAiB,CAAC,SAAS,CAAC,uBAAuB,EAAE,aAAa,CAAC,CAAC;IAClF,CAAC;CACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
export class Exception extends Error {
|
|
9
|
+
constructor(message, options) {
|
|
10
|
+
super(message, options);
|
|
11
|
+
this.name = new.target.name;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=exception.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exception.js","sourceRoot":"","sources":["../../../../src/noldova.context.exceptions/src/exceptions/exception.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,MAAM,OAAgB,SAAU,SAAQ,KAAK;IAC3C,YAAsB,OAAe,EAAE,OAA0B;QAC/D,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAExB,IAAI,CAAC,IAAI,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC;IAC9B,CAAC;CACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { Resources } from "../resources.js";
|
|
9
|
+
import { Exception } from "./exception.js";
|
|
10
|
+
export class IndexOutOfRangeException extends Exception {
|
|
11
|
+
constructor(message = Resources.indexOutOfRange, options) {
|
|
12
|
+
super(message, options);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=index-out-of-range.exception.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-out-of-range.exception.js","sourceRoot":"","sources":["../../../../src/noldova.context.exceptions/src/exceptions/index-out-of-range.exception.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,MAAM,OAAO,wBAAyB,SAAQ,SAAS;IACrD,YAAmB,OAAO,GAAW,SAAS,CAAC,eAAe,EAAE,OAA0B;QACxF,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC1B,CAAC;CACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
export class ExceptionOptions {
|
|
9
|
+
cause;
|
|
10
|
+
constructor(cause) {
|
|
11
|
+
this.cause = cause;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=exception-options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exception-options.js","sourceRoot":"","sources":["../../../../src/noldova.context.exceptions/src/models/exception-options.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,OAAO,gBAAgB;IACX,KAAK,CAAU;IAE/B,YAAmB,KAAe;QAChC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noldova/context.exceptions",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "api/index.js",
|
|
6
|
+
"types": "api/index.d.ts",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/noldova-com/context.git",
|
|
11
|
+
"directory": "src/noldova.context.exceptions"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/noldova-com/context#readme",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/noldova-com/context/issues"
|
|
16
|
+
},
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public",
|
|
19
|
+
"registry": "https://registry.npmjs.org/"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@noldova/context.core": "0.0.2"
|
|
23
|
+
}
|
|
24
|
+
}
|
package/resources.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import "@noldova/context.core";
|
|
9
|
+
export class Resources {
|
|
10
|
+
static argumentCollectionEmpty = "The collection must contain at least one element.";
|
|
11
|
+
static argumentEmpty = "The value cannot be an empty string.";
|
|
12
|
+
static argumentInvalid = "Value does not fall within the expected range.";
|
|
13
|
+
static argumentNull = "Value cannot be null or undefined.";
|
|
14
|
+
static argumentOutOfRange = "The argument must be within the valid range.";
|
|
15
|
+
static argumentWhitespace = "The value cannot be an empty string or composed entirely of whitespace.";
|
|
16
|
+
static indexOutOfRange = "The index must be within the valid range.";
|
|
17
|
+
static formatArgumentMessage(message, parameterName) {
|
|
18
|
+
if (Object.isUndefined(parameterName))
|
|
19
|
+
return message;
|
|
20
|
+
return `${message} (Parameter '${parameterName}')`;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=resources.js.map
|
package/resources.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resources.js","sourceRoot":"","sources":["../../../src/noldova.context.exceptions/src/resources.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,uBAAuB,CAAC;AAE/B,MAAM,OAAO,SAAS;IACb,MAAM,CAAU,uBAAuB,GAAW,mDAAmD,CAAC;IACtG,MAAM,CAAU,aAAa,GAAW,sCAAsC,CAAC;IAC/E,MAAM,CAAU,eAAe,GAAW,gDAAgD,CAAC;IAC3F,MAAM,CAAU,YAAY,GAAW,oCAAoC,CAAC;IAC5E,MAAM,CAAU,kBAAkB,GAAW,8CAA8C,CAAC;IAC5F,MAAM,CAAU,kBAAkB,GAAW,yEAAyE,CAAC;IACvH,MAAM,CAAU,eAAe,GAAW,2CAA2C,CAAC;IAEtF,MAAM,CAAC,qBAAqB,CAAC,OAAe,EAAE,aAAsB;QACzE,IAAI,MAAM,CAAC,WAAW,CAAC,aAAa,CAAC;YACnC,OAAO,OAAO,CAAC;QAEjB,OAAO,GAAG,OAAO,gBAAgB,aAAa,IAAI,CAAC;IACrD,CAAC;CACF"}
|
package/README.md
DELETED