@event-driven-io/emmett-mongodb 0.36.0 → 0.37.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 +39 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +22 -16
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -182,22 +182,6 @@ var deepEquals = (left, right) => {
|
|
|
182
182
|
var isEquatable = (left) => {
|
|
183
183
|
return left && typeof left === "object" && "equals" in left && typeof left["equals"] === "function";
|
|
184
184
|
};
|
|
185
|
-
var asyncRetry = async (fn, opts) => {
|
|
186
|
-
if (opts === void 0 || opts.retries === 0) return fn();
|
|
187
|
-
return _asyncretry2.default.call(void 0,
|
|
188
|
-
async (bail) => {
|
|
189
|
-
try {
|
|
190
|
-
return await fn();
|
|
191
|
-
} catch (error2) {
|
|
192
|
-
if (_optionalChain([opts, 'optionalAccess', _13 => _13.shouldRetryError]) && !opts.shouldRetryError(error2)) {
|
|
193
|
-
bail(error2);
|
|
194
|
-
}
|
|
195
|
-
throw error2;
|
|
196
|
-
}
|
|
197
|
-
},
|
|
198
|
-
_nullishCoalesce(opts, () => ( { retries: 0 }))
|
|
199
|
-
);
|
|
200
|
-
};
|
|
201
185
|
var ParseError = class extends Error {
|
|
202
186
|
constructor(text) {
|
|
203
187
|
super(`Cannot parse! ${text}`);
|
|
@@ -206,19 +190,41 @@ var ParseError = class extends Error {
|
|
|
206
190
|
var JSONParser = {
|
|
207
191
|
stringify: (value, options) => {
|
|
208
192
|
return JSON.stringify(
|
|
209
|
-
_optionalChain([options, 'optionalAccess',
|
|
193
|
+
_optionalChain([options, 'optionalAccess', _13 => _13.map]) ? options.map(value) : value,
|
|
210
194
|
//TODO: Consider adding support to DateTime and adding specific format to mark that's a bigint
|
|
211
195
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
212
196
|
(_, v) => typeof v === "bigint" ? v.toString() : v
|
|
213
197
|
);
|
|
214
198
|
},
|
|
215
199
|
parse: (text, options) => {
|
|
216
|
-
const parsed = JSON.parse(text, _optionalChain([options, 'optionalAccess',
|
|
217
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
200
|
+
const parsed = JSON.parse(text, _optionalChain([options, 'optionalAccess', _14 => _14.reviver]));
|
|
201
|
+
if (_optionalChain([options, 'optionalAccess', _15 => _15.typeCheck]) && !_optionalChain([options, 'optionalAccess', _16 => _16.typeCheck, 'call', _17 => _17(parsed)]))
|
|
218
202
|
throw new ParseError(text);
|
|
219
|
-
return _optionalChain([options, 'optionalAccess',
|
|
203
|
+
return _optionalChain([options, 'optionalAccess', _18 => _18.map]) ? options.map(parsed) : parsed;
|
|
220
204
|
}
|
|
221
205
|
};
|
|
206
|
+
var asyncRetry = async (fn, opts) => {
|
|
207
|
+
if (opts === void 0 || opts.retries === 0) return fn();
|
|
208
|
+
return _asyncretry2.default.call(void 0,
|
|
209
|
+
async (bail) => {
|
|
210
|
+
try {
|
|
211
|
+
const result = await fn();
|
|
212
|
+
if (_optionalChain([opts, 'optionalAccess', _19 => _19.shouldRetryResult]) && opts.shouldRetryResult(result)) {
|
|
213
|
+
throw new EmmettError(
|
|
214
|
+
`Retrying because of result: ${JSONParser.stringify(result)}`
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
return result;
|
|
218
|
+
} catch (error2) {
|
|
219
|
+
if (_optionalChain([opts, 'optionalAccess', _20 => _20.shouldRetryError]) && !opts.shouldRetryError(error2)) {
|
|
220
|
+
bail(error2);
|
|
221
|
+
}
|
|
222
|
+
throw error2;
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
_nullishCoalesce(opts, () => ( { retries: 0 }))
|
|
226
|
+
);
|
|
227
|
+
};
|
|
222
228
|
var filterProjections = (type, projections2) => {
|
|
223
229
|
const inlineProjections2 = projections2.filter((projection2) => projection2.type === type).map(({ projection: projection2 }) => projection2);
|
|
224
230
|
const duplicateRegistrations = arrayUtils.getDuplicates(
|
|
@@ -524,18 +530,18 @@ var MongoDBInlineProjectionSpec = {
|
|
|
524
530
|
if (!isErrorConstructor(args[0])) {
|
|
525
531
|
assertTrue(
|
|
526
532
|
args[0](error),
|
|
527
|
-
`Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess',
|
|
533
|
+
`Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess', _21 => _21.toString, 'call', _22 => _22()])}`
|
|
528
534
|
);
|
|
529
535
|
return;
|
|
530
536
|
}
|
|
531
537
|
assertTrue(
|
|
532
538
|
error instanceof args[0],
|
|
533
|
-
`Caught error is not an instance of the expected type: ${_optionalChain([error, 'optionalAccess',
|
|
539
|
+
`Caught error is not an instance of the expected type: ${_optionalChain([error, 'optionalAccess', _23 => _23.toString, 'call', _24 => _24()])}`
|
|
534
540
|
);
|
|
535
541
|
if (args[1]) {
|
|
536
542
|
assertTrue(
|
|
537
543
|
args[1](error),
|
|
538
|
-
`Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess',
|
|
544
|
+
`Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess', _25 => _25.toString, 'call', _26 => _26()])}`
|
|
539
545
|
);
|
|
540
546
|
}
|
|
541
547
|
} finally {
|
|
@@ -705,7 +711,7 @@ var MongoDBEventStoreImplementation = (_class4 = class {
|
|
|
705
711
|
}
|
|
706
712
|
async readStream(streamName, options) {
|
|
707
713
|
const { streamType } = fromStreamName(streamName);
|
|
708
|
-
const expectedStreamVersion = _optionalChain([options, 'optionalAccess',
|
|
714
|
+
const expectedStreamVersion = _optionalChain([options, 'optionalAccess', _27 => _27.expectedStreamVersion]);
|
|
709
715
|
const collection = await this.storage.collectionFor(streamType);
|
|
710
716
|
const filter2 = {
|
|
711
717
|
streamName: { $eq: streamName }
|
|
@@ -746,7 +752,7 @@ var MongoDBEventStoreImplementation = (_class4 = class {
|
|
|
746
752
|
};
|
|
747
753
|
}
|
|
748
754
|
async aggregateStream(streamName, options) {
|
|
749
|
-
const stream = await this.readStream(streamName, _optionalChain([options, 'optionalAccess',
|
|
755
|
+
const stream = await this.readStream(streamName, _optionalChain([options, 'optionalAccess', _28 => _28.read]));
|
|
750
756
|
const state = stream.events.reduce(options.evolve, options.initialState());
|
|
751
757
|
return {
|
|
752
758
|
state,
|
|
@@ -756,7 +762,7 @@ var MongoDBEventStoreImplementation = (_class4 = class {
|
|
|
756
762
|
}
|
|
757
763
|
async appendToStream(streamName, events, options) {
|
|
758
764
|
const { streamId, streamType } = fromStreamName(streamName);
|
|
759
|
-
const expectedStreamVersion = _optionalChain([options, 'optionalAccess',
|
|
765
|
+
const expectedStreamVersion = _optionalChain([options, 'optionalAccess', _29 => _29.expectedStreamVersion]);
|
|
760
766
|
const collection = await this.storage.collectionFor(streamType);
|
|
761
767
|
const stream = await collection.findOne(
|
|
762
768
|
{ streamName: { $eq: streamName } },
|
|
@@ -768,7 +774,7 @@ var MongoDBEventStoreImplementation = (_class4 = class {
|
|
|
768
774
|
}
|
|
769
775
|
}
|
|
770
776
|
);
|
|
771
|
-
const currentStreamVersion = _nullishCoalesce(_optionalChain([stream, 'optionalAccess',
|
|
777
|
+
const currentStreamVersion = _nullishCoalesce(_optionalChain([stream, 'optionalAccess', _30 => _30.metadata, 'access', _31 => _31.streamPosition]), () => ( MongoDBEventStoreDefaultStreamVersion));
|
|
772
778
|
assertExpectedVersionMatchesCurrent(
|
|
773
779
|
currentStreamVersion,
|
|
774
780
|
expectedStreamVersion,
|
|
@@ -806,7 +812,7 @@ var MongoDBEventStoreImplementation = (_class4 = class {
|
|
|
806
812
|
};
|
|
807
813
|
if (this.inlineProjections) {
|
|
808
814
|
await handleInlineProjections({
|
|
809
|
-
readModels: _nullishCoalesce(_optionalChain([stream, 'optionalAccess',
|
|
815
|
+
readModels: _nullishCoalesce(_optionalChain([stream, 'optionalAccess', _32 => _32.projections]), () => ( {})),
|
|
810
816
|
streamId,
|
|
811
817
|
events: eventsToAppend,
|
|
812
818
|
projections: this.inlineProjections,
|
|
@@ -826,7 +832,7 @@ var MongoDBEventStoreImplementation = (_class4 = class {
|
|
|
826
832
|
if (!updatedStream) {
|
|
827
833
|
throw new ExpectedVersionConflictError(
|
|
828
834
|
currentStreamVersion,
|
|
829
|
-
_nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
835
|
+
_nullishCoalesce(_optionalChain([options, 'optionalAccess', _33 => _33.expectedStreamVersion]), () => ( 0n))
|
|
830
836
|
);
|
|
831
837
|
}
|
|
832
838
|
await tryPublishMessagesAfterCommit(
|
|
@@ -877,7 +883,7 @@ var MongoDBEventStoreImplementation = (_class4 = class {
|
|
|
877
883
|
projection: { [`projections.${projectionName}`]: 1 }
|
|
878
884
|
}
|
|
879
885
|
);
|
|
880
|
-
return _nullishCoalesce(_optionalChain([result, 'optionalAccess',
|
|
886
|
+
return _nullishCoalesce(_optionalChain([result, 'optionalAccess', _34 => _34.projections, 'optionalAccess', _35 => _35[projectionName]]), () => ( null));
|
|
881
887
|
}
|
|
882
888
|
async findInlineProjection(streamFilter, projectionQuery, queryOptions) {
|
|
883
889
|
const parsedStreamFilter = parseMultiProjectionQueryStreamFilter(streamFilter);
|
|
@@ -902,13 +908,13 @@ var MongoDBEventStoreImplementation = (_class4 = class {
|
|
|
902
908
|
projection: { [`projections.${projectionName}`]: 1 }
|
|
903
909
|
}
|
|
904
910
|
);
|
|
905
|
-
if (_optionalChain([queryOptions, 'optionalAccess',
|
|
911
|
+
if (_optionalChain([queryOptions, 'optionalAccess', _36 => _36.skip])) {
|
|
906
912
|
query = query.skip(queryOptions.skip);
|
|
907
913
|
}
|
|
908
|
-
if (_optionalChain([queryOptions, 'optionalAccess',
|
|
914
|
+
if (_optionalChain([queryOptions, 'optionalAccess', _37 => _37.limit])) {
|
|
909
915
|
query = query.limit(queryOptions.limit);
|
|
910
916
|
}
|
|
911
|
-
if (_optionalChain([queryOptions, 'optionalAccess',
|
|
917
|
+
if (_optionalChain([queryOptions, 'optionalAccess', _38 => _38.sort])) {
|
|
912
918
|
const sort = prependMongoFilterWithProjectionPrefix(
|
|
913
919
|
queryOptions.sort,
|
|
914
920
|
prefix
|