@noldova/context.exceptions 0.0.9 → 0.0.11

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/README.md CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  The exceptions CONTEXT libraries throw: an abstract `Exception` base that names
4
4
  itself after its concrete class, argument exceptions with guards that check a
5
- value and narrow its type in one call, and an index exception.
5
+ value and narrow its type in one call, an index exception, and the exceptions
6
+ for a call an object can't serve in its current state and for a missing key.
6
7
 
7
8
  ## Install
8
9
 
@@ -34,8 +35,8 @@ new InputException("Cannot read input.", new ExceptionOptions(new Error("Bad enc
34
35
 
35
36
  `ArgumentException`, `ArgumentNullException` and `ArgumentOutOfRangeException`
36
37
  keep the parameter name as a field, and `ArgumentOutOfRangeException` also keeps
37
- the rejected value. `IndexOutOfRangeException` carries a message and, where
38
- given, a cause. The declaration file `api/index.d.ts` documents every member
38
+ the rejected value. `IndexOutOfRangeException`, `InvalidOperationException`
39
+ and `KeyNotFoundException` carry a message and, where given, a cause. The declaration file `api/index.d.ts` documents every member
39
40
  with its contract and examples.
40
41
 
41
42
  ## License
package/api/index.d.ts CHANGED
@@ -242,6 +242,50 @@ export declare class ArgumentOutOfRangeException extends ArgumentException {
242
242
  */
243
243
  public constructor(parameterName?: string, actualValue?: unknown, message?: string, options?: ExceptionOptions);
244
244
 
245
+ /**
246
+ * Requires a number that is not below zero. Fractional values, `NaN` and
247
+ * positive infinity pass; pair it with
248
+ * {@link ArgumentOutOfRangeException.throwIfNotInteger} to require a
249
+ * non-negative integer. It returns no value.
250
+ *
251
+ * @param value The number to validate.
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 below zero, negative
256
+ * infinity included; `-0` passes. The exception retains `parameterName` and the
257
+ * rejected number as `actualValue`.
258
+ * @example
259
+ * ```ts
260
+ * import { ArgumentOutOfRangeException } from "@noldova/context.exceptions";
261
+ *
262
+ * ArgumentOutOfRangeException.throwIfNegative(0, "count"); // Accepted.
263
+ * ArgumentOutOfRangeException.throwIfNegative(-1, "count"); // Throws.
264
+ * ```
265
+ */
266
+ public static throwIfNegative(value: number, parameterName: string, message?: string): void;
267
+
268
+ /**
269
+ * Requires a finite integer, using the `Number.isInteger` classification.
270
+ * Zero and negative integers pass. It returns no value.
271
+ *
272
+ * @param value The number to validate. This is not a safe-integer check.
273
+ * @param parameterName The caller's parameter name, included in the exception.
274
+ * @param message An optional explanation replacing the default out-of-range
275
+ * text. The parameter suffix is still appended; an explicit empty message is kept.
276
+ * @throws {ArgumentOutOfRangeException} If the value is fractional, `NaN`, or
277
+ * either infinity. The exception retains `parameterName` and the rejected
278
+ * number as `actualValue`.
279
+ * @example
280
+ * ```ts
281
+ * import { ArgumentOutOfRangeException } from "@noldova/context.exceptions";
282
+ *
283
+ * ArgumentOutOfRangeException.throwIfNotInteger(-3, "start"); // Accepted.
284
+ * ArgumentOutOfRangeException.throwIfNotInteger(1.5, "start"); // Throws.
285
+ * ```
286
+ */
287
+ public static throwIfNotInteger(value: number, parameterName: string, message?: string): void;
288
+
245
289
  /**
246
290
  * Requires a finite positive integer, using the `Number.isInteger` classification.
247
291
  * It does not establish a narrower TypeScript type and returns no value.
@@ -288,3 +332,47 @@ export declare class IndexOutOfRangeException extends Exception {
288
332
  */
289
333
  public constructor(message?: string, options?: ExceptionOptions);
290
334
  }
335
+
336
+ /**
337
+ * The exception that is thrown when a call is not valid in its object's current state,
338
+ * such as reading the first element of an empty sequence.
339
+ */
340
+ export declare class InvalidOperationException extends Exception {
341
+ /**
342
+ * Creates an exception describing a call its object can't serve in its current state.
343
+ *
344
+ * @param message The explanation. Omission or `undefined` uses
345
+ * `"The operation is not valid in the object's current state."`. An empty string is preserved.
346
+ * @param options Optional context retaining the original cause unchanged.
347
+ * @example
348
+ * ```ts
349
+ * import { InvalidOperationException } from "@noldova/context.exceptions";
350
+ *
351
+ * new InvalidOperationException().message; // "The operation is not valid in the object's current state."
352
+ * new InvalidOperationException("The sequence contains no elements.").message; // "The sequence contains no elements."
353
+ * ```
354
+ */
355
+ public constructor(message?: string, options?: ExceptionOptions);
356
+ }
357
+
358
+ /**
359
+ * The exception that is thrown when a lookup that requires its key finds no entry
360
+ * with that key.
361
+ */
362
+ export declare class KeyNotFoundException extends Exception {
363
+ /**
364
+ * Creates an exception describing a key the collection doesn't hold.
365
+ *
366
+ * @param message The explanation. Omission or `undefined` uses
367
+ * `"The key is not present in the collection."`. An empty string is preserved.
368
+ * @param options Optional context retaining the original cause unchanged.
369
+ * @example
370
+ * ```ts
371
+ * import { KeyNotFoundException } from "@noldova/context.exceptions";
372
+ *
373
+ * new KeyNotFoundException().message; // "The key is not present in the collection."
374
+ * new KeyNotFoundException("").message; // ""
375
+ * ```
376
+ */
377
+ public constructor(message?: string, options?: ExceptionOptions);
378
+ }
package/api/index.js CHANGED
@@ -10,5 +10,7 @@ export { ArgumentNullException } from "../exceptions/argument-null.exception.js"
10
10
  export { ArgumentOutOfRangeException } from "../exceptions/argument-out-of-range.exception.js";
11
11
  export { Exception } from "../exceptions/exception.js";
12
12
  export { IndexOutOfRangeException } from "../exceptions/index-out-of-range.exception.js";
13
+ export { InvalidOperationException } from "../exceptions/invalid-operation.exception.js";
14
+ export { KeyNotFoundException } from "../exceptions/key-not-found.exception.js";
13
15
  export { ExceptionOptions } from "../models/exception-options.js";
14
16
  //# sourceMappingURL=index.js.map
package/api/index.js.map CHANGED
@@ -1 +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"}
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,yBAAyB,EAAE,MAAM,8CAA8C,CAAC;AACzF,OAAO,EAAE,oBAAoB,EAAE,MAAM,0CAA0C,CAAC;AAChF,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC"}
@@ -13,6 +13,14 @@ export class ArgumentOutOfRangeException extends ArgumentException {
13
13
  super(message ?? Resources.argumentOutOfRange, parameterName, options);
14
14
  this.actualValue = actualValue;
15
15
  }
16
+ static throwIfNegative(value, parameterName, message) {
17
+ if (value < 0)
18
+ throw new ArgumentOutOfRangeException(parameterName, value, message);
19
+ }
20
+ static throwIfNotInteger(value, parameterName, message) {
21
+ if (!Number.isInteger(value))
22
+ throw new ArgumentOutOfRangeException(parameterName, value, message);
23
+ }
16
24
  static throwIfNotPositiveInteger(value, parameterName, message) {
17
25
  if (!Number.isInteger(value) || value <= 0)
18
26
  throw new ArgumentOutOfRangeException(parameterName, value, message);
@@ -1 +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"}
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,eAAe,CAAC,KAAa,EAAE,aAAqB,EAAE,OAAgB;QAClF,IAAI,KAAK,GAAG,CAAC;YACX,MAAM,IAAI,2BAA2B,CAAC,aAAa,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;IACzE,CAAC;IAEM,MAAM,CAAC,iBAAiB,CAAC,KAAa,EAAE,aAAqB,EAAE,OAAgB;QACpF,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC;YAC1B,MAAM,IAAI,2BAA2B,CAAC,aAAa,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;IACzE,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,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 InvalidOperationException extends Exception {
11
+ constructor(message = Resources.invalidOperation, options) {
12
+ super(message, options);
13
+ }
14
+ }
15
+ //# sourceMappingURL=invalid-operation.exception.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invalid-operation.exception.js","sourceRoot":"","sources":["../../../../src/noldova.context.exceptions/src/exceptions/invalid-operation.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,yBAA0B,SAAQ,SAAS;IACtD,YAAmB,OAAO,GAAW,SAAS,CAAC,gBAAgB,EAAE,OAA0B;QACzF,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC1B,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 KeyNotFoundException extends Exception {
11
+ constructor(message = Resources.keyNotFound, options) {
12
+ super(message, options);
13
+ }
14
+ }
15
+ //# sourceMappingURL=key-not-found.exception.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"key-not-found.exception.js","sourceRoot":"","sources":["../../../../src/noldova.context.exceptions/src/exceptions/key-not-found.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,oBAAqB,SAAQ,SAAS;IACjD,YAAmB,OAAO,GAAW,SAAS,CAAC,WAAW,EAAE,OAA0B;QACpF,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC1B,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noldova/context.exceptions",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "type": "module",
5
5
  "main": "api/index.js",
6
6
  "types": "api/index.d.ts",
@@ -19,7 +19,7 @@
19
19
  "registry": "https://registry.npmjs.org/"
20
20
  },
21
21
  "peerDependencies": {
22
- "@noldova/context.core": ">=0.0.9 <0.1.0"
22
+ "@noldova/context.core": ">=0.0.11 <0.1.0"
23
23
  },
24
- "gitHead": "739f94fdfd82cfca7901164d7719be5275012451"
24
+ "gitHead": "7f0d162aae71d04bc8aa6f955f8ee95cac60d89c"
25
25
  }
package/resources.js CHANGED
@@ -14,6 +14,8 @@ export class Resources {
14
14
  static argumentOutOfRange = "The argument must be within the valid range.";
15
15
  static argumentWhitespace = "The value cannot be an empty string or composed entirely of whitespace.";
16
16
  static indexOutOfRange = "The index must be within the valid range.";
17
+ static invalidOperation = "The operation is not valid in the object's current state.";
18
+ static keyNotFound = "The key is not present in the collection.";
17
19
  static formatArgumentMessage(message, parameterName) {
18
20
  if (Object.isUndefined(parameterName))
19
21
  return message;
package/resources.js.map CHANGED
@@ -1 +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"}
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;IACtF,MAAM,CAAU,gBAAgB,GAAW,2DAA2D,CAAC;IACvG,MAAM,CAAU,WAAW,GAAW,2CAA2C,CAAC;IAElF,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"}