@event-driven-io/emmett-mongodb 0.39.0 → 0.40.0

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/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- // ../emmett/dist/chunk-O2VMBOV4.js
1
+ // ../emmett/dist/chunk-AZDDB5SF.js
2
2
  var isNumber = (val) => typeof val === "number" && val === val;
3
3
  var isString = (val) => typeof val === "string";
4
4
  var isErrorConstructor = (expect) => {
@@ -6,28 +6,38 @@ var isErrorConstructor = (expect) => {
6
6
  expect.prototype.constructor === expect;
7
7
  };
8
8
  var EmmettError = class _EmmettError extends Error {
9
+ static Codes = {
10
+ ValidationError: 400,
11
+ IllegalStateError: 403,
12
+ NotFoundError: 404,
13
+ ConcurrencyError: 412,
14
+ InternalServerError: 500
15
+ };
9
16
  errorCode;
10
17
  constructor(options) {
11
- const errorCode = options && typeof options === "object" && "errorCode" in options ? options.errorCode : isNumber(options) ? options : 500;
18
+ const errorCode = options && typeof options === "object" && "errorCode" in options ? options.errorCode : isNumber(options) ? options : _EmmettError.Codes.InternalServerError;
12
19
  const message = options && typeof options === "object" && "message" in options ? options.message : isString(options) ? options : `Error with status code '${errorCode}' ocurred during Emmett processing`;
13
20
  super(message);
14
21
  this.errorCode = errorCode;
15
22
  Object.setPrototypeOf(this, _EmmettError.prototype);
16
23
  }
17
24
  static mapFrom(error) {
18
- if (error instanceof _EmmettError) {
25
+ if (_EmmettError.isInstanceOf(error)) {
19
26
  return error;
20
27
  }
21
28
  return new _EmmettError({
22
- errorCode: "errorCode" in error && error.errorCode !== void 0 && error.errorCode !== null ? error.errorCode : 500,
29
+ errorCode: "errorCode" in error && error.errorCode !== void 0 && error.errorCode !== null ? error.errorCode : _EmmettError.Codes.InternalServerError,
23
30
  message: error.message ?? "An unknown error occurred"
24
31
  });
25
32
  }
33
+ static isInstanceOf(error, errorCode) {
34
+ return typeof error === "object" && error !== null && "errorCode" in error && isNumber(error.errorCode) && (errorCode === void 0 || error.errorCode === errorCode);
35
+ }
26
36
  };
27
37
  var ConcurrencyError = class _ConcurrencyError extends EmmettError {
28
38
  constructor(current, expected, message) {
29
39
  super({
30
- errorCode: 412,
40
+ errorCode: EmmettError.Codes.ConcurrencyError,
31
41
  message: message ?? `Expected version ${expected.toString()} does not match current ${current?.toString()}`
32
42
  });
33
43
  this.current = current;