@event-driven-io/emmett 0.21.1 → 0.22.0-alpha.3

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
@@ -442,17 +442,25 @@ var CommandHandler = (options) => async (store, id, handle, handleOptions) => as
442
442
  read: {
443
443
  // expected stream version is passed to fail fast
444
444
  // if stream is in the wrong state
445
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
445
446
  expectedStreamVersion: _nullishCoalesce(_optionalChain([handleOptions, 'optionalAccess', _15 => _15.expectedStreamVersion]), () => ( NO_CONCURRENCY_CHECK))
446
447
  }
447
448
  });
448
- const state = aggregationResult.state;
449
- const currentStreamVersion = aggregationResult.currentStreamVersion;
449
+ const {
450
+ state,
451
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
452
+ currentStreamVersion,
453
+ streamExists: _streamExists,
454
+ ...restOfAggregationResult
455
+ } = aggregationResult;
450
456
  const result2 = await handle(state);
451
457
  const newEvents = Array.isArray(result2) ? result2 : [result2];
452
458
  if (newEvents.length === 0) {
453
459
  return {
460
+ ...restOfAggregationResult,
454
461
  newEvents: [],
455
462
  newState: state,
463
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
456
464
  nextExpectedStreamVersion: currentStreamVersion,
457
465
  createdNewStream: false
458
466
  };
@@ -957,22 +965,42 @@ var assertFails = (message) => {
957
965
  var assertThrowsAsync = async (fun, errorCheck) => {
958
966
  try {
959
967
  await fun();
960
- throw new AssertionError("Function didn't throw expected error");
961
968
  } catch (error2) {
962
969
  const typedError = error2;
963
- if (errorCheck) assertTrue(errorCheck(typedError));
970
+ if (typedError instanceof AssertionError || !errorCheck) {
971
+ assertFalse(
972
+ typedError instanceof AssertionError,
973
+ "Function didn't throw expected error"
974
+ );
975
+ return typedError;
976
+ }
977
+ assertTrue(
978
+ errorCheck(typedError),
979
+ `Error doesn't match the expected condition: ${JSON.stringify(error2)}`
980
+ );
964
981
  return typedError;
965
982
  }
983
+ throw new AssertionError("Function didn't throw expected error");
966
984
  };
967
985
  var assertThrows = (fun, errorCheck) => {
968
986
  try {
969
987
  fun();
970
- throw new AssertionError("Function didn't throw expected error");
971
988
  } catch (error2) {
972
989
  const typedError = error2;
973
- if (errorCheck) assertTrue(errorCheck(typedError));
990
+ if (errorCheck) {
991
+ assertTrue(
992
+ errorCheck(typedError),
993
+ `Error doesn't match the expected condition: ${JSON.stringify(error2)}`
994
+ );
995
+ } else if (typedError instanceof AssertionError) {
996
+ assertFalse(
997
+ typedError instanceof AssertionError,
998
+ "Function didn't throw expected error"
999
+ );
1000
+ }
974
1001
  return typedError;
975
1002
  }
1003
+ throw new AssertionError("Function didn't throw expected error");
976
1004
  };
977
1005
  var assertRejects = async (promise, errorCheck) => {
978
1006
  try {
@@ -1017,10 +1045,12 @@ var assertThat = (item) => {
1017
1045
  };
1018
1046
  };
1019
1047
  function assertFalse(condition, message) {
1020
- if (condition) throw new AssertionError(_nullishCoalesce(message, () => ( `Condition is false`)));
1048
+ if (condition !== false)
1049
+ throw new AssertionError(_nullishCoalesce(message, () => ( `Condition is true`)));
1021
1050
  }
1022
1051
  function assertTrue(condition, message) {
1023
- if (!condition) throw new AssertionError(_nullishCoalesce(message, () => ( `Condition is false`)));
1052
+ if (condition !== true)
1053
+ throw new AssertionError(_nullishCoalesce(message, () => ( `Condition is false`)));
1024
1054
  }
1025
1055
  function assertOk(obj, message) {
1026
1056
  if (!obj) throw new AssertionError(_nullishCoalesce(message, () => ( `Condition is not truthy`)));
@@ -1095,10 +1125,17 @@ var assertThatArray = (array) => {
1095
1125
  isEmpty: () => assertEqual(array.length, 0),
1096
1126
  isNotEmpty: () => assertNotEqual(array.length, 0),
1097
1127
  hasSize: (length) => assertEqual(array.length, length),
1098
- containsElements: (...other) => {
1099
- assertTrue(other.every((ts) => other.some((o) => deepEquals(ts, o))));
1128
+ containsElements: (other) => {
1129
+ assertTrue(other.every((ts) => array.some((o) => deepEquals(ts, o))));
1130
+ },
1131
+ containsElementsMatching: (other) => {
1132
+ assertTrue(other.every((ts) => array.some((o) => isSubset(o, ts))));
1133
+ },
1134
+ containsOnlyElementsMatching: (other) => {
1135
+ assertEqual(array.length, other.length);
1136
+ assertTrue(other.every((ts) => array.some((o) => isSubset(o, ts))));
1100
1137
  },
1101
- containsExactlyInAnyOrder: (...other) => {
1138
+ containsExactlyInAnyOrder: (other) => {
1102
1139
  assertEqual(array.length, other.length);
1103
1140
  assertTrue(array.every((ts) => other.some((o) => deepEquals(ts, o))));
1104
1141
  },
@@ -1124,7 +1161,7 @@ var assertThatArray = (array) => {
1124
1161
  other.map((o) => array.filter((a) => deepEquals(a, o)).length).filter((a) => a === 1).length === other.length
1125
1162
  );
1126
1163
  },
1127
- containsAnyOf: (...other) => {
1164
+ containsAnyOf: (other) => {
1128
1165
  assertTrue(array.some((a) => other.some((o) => deepEquals(a, o))));
1129
1166
  },
1130
1167
  allMatch: (matches) => {
@@ -1200,12 +1237,15 @@ var DeciderSpecification = {
1200
1237
  // src/testing/wrapEventStore.ts
1201
1238
  var WrapEventStore = (eventStore) => {
1202
1239
  const appendedEvents = /* @__PURE__ */ new Map();
1203
- return {
1204
- async aggregateStream(streamName, options) {
1240
+ const wrapped = {
1241
+ aggregateStream(streamName, options) {
1205
1242
  return eventStore.aggregateStream(streamName, options);
1206
1243
  },
1207
- readStream(streamName, options) {
1208
- return eventStore.readStream(streamName, options);
1244
+ async readStream(streamName, options) {
1245
+ return await eventStore.readStream(
1246
+ streamName,
1247
+ options
1248
+ );
1209
1249
  },
1210
1250
  appendToStream: async (streamName, events, options) => {
1211
1251
  const result = await eventStore.appendToStream(
@@ -1231,6 +1271,7 @@ var WrapEventStore = (eventStore) => {
1231
1271
  // return eventStore.streamEvents();
1232
1272
  // },
1233
1273
  };
1274
+ return wrapped;
1234
1275
  };
1235
1276
 
1236
1277