@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.cjs CHANGED
@@ -1,33 +1,43 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;// ../emmett/dist/chunk-O2VMBOV4.js
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2;// ../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) => {
5
5
  return typeof expect === "function" && expect.prototype && // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
6
6
  expect.prototype.constructor === expect;
7
7
  };
8
- var EmmettError = class _EmmettError extends Error {
8
+ var EmmettError = (_class = class _EmmettError extends Error {
9
+ static __initStatic() {this.Codes = {
10
+ ValidationError: 400,
11
+ IllegalStateError: 403,
12
+ NotFoundError: 404,
13
+ ConcurrencyError: 412,
14
+ InternalServerError: 500
15
+ }}
9
16
 
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: _nullishCoalesce(error.message, () => ( "An unknown error occurred"))
24
31
  });
25
32
  }
26
- };
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
+ }
36
+ }, _class.__initStatic(), _class);
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: _nullishCoalesce(message, () => ( `Expected version ${expected.toString()} does not match current ${_optionalChain([current, 'optionalAccess', _2 => _2.toString, 'call', _3 => _3()])}`))
32
42
  });
33
43
  this.current = current;
@@ -646,7 +656,7 @@ var mongoDBEventStoreStorage = (options) => {
646
656
 
647
657
  // src/eventStore/mongoDBEventStore.ts
648
658
  var MongoDBEventStoreDefaultStreamVersion = 0n;
649
- var MongoDBEventStoreImplementation = (_class = class {
659
+ var MongoDBEventStoreImplementation = (_class2 = class {
650
660
 
651
661
 
652
662
 
@@ -654,7 +664,7 @@ var MongoDBEventStoreImplementation = (_class = class {
654
664
 
655
665
 
656
666
 
657
- constructor(options) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);_class.prototype.__init4.call(this);
667
+ constructor(options) {;_class2.prototype.__init.call(this);_class2.prototype.__init2.call(this);_class2.prototype.__init3.call(this);_class2.prototype.__init4.call(this);
658
668
  this.options = options;
659
669
  this.client = "client" in options && options.client ? options.client : new (0, _mongodb.MongoClient)(options.connectionString, options.clientOptions);
660
670
  this.shouldManageClientLifetime = !("client" in options);
@@ -912,7 +922,7 @@ var MongoDBEventStoreImplementation = (_class = class {
912
922
  if (!this.isClosed) await this.client.connect();
913
923
  return this.client;
914
924
  }}
915
- }, _class);
925
+ }, _class2);
916
926
  function parseSingleProjectionQueryStreamFilter(streamFilter) {
917
927
  const projectionName = _nullishCoalesce(streamFilter.projectionName, () => ( MongoDBDefaultInlineProjectionName));
918
928
  if ("streamName" in streamFilter) {