@event-driven-io/emmett 0.43.0-beta.8 → 0.43.0-beta.9
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 +227 -118
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +76 -25
- package/dist/index.d.ts +76 -25
- package/dist/index.js +152 -43
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -21,9 +21,9 @@ var _chunkWND32L6Pcjs = require('./chunk-WND32L6P.cjs');
|
|
|
21
21
|
|
|
22
22
|
// src/eventStore/afterCommit/afterEventStoreCommitHandler.ts
|
|
23
23
|
async function tryPublishMessagesAfterCommit(messages, options, context) {
|
|
24
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
24
|
+
if (_optionalChain([options, 'optionalAccess', _ => _.onAfterCommit]) === void 0) return false;
|
|
25
25
|
try {
|
|
26
|
-
await _optionalChain([options, 'optionalAccess',
|
|
26
|
+
await _optionalChain([options, 'optionalAccess', _2 => _2.onAfterCommit, 'call', _3 => _3(messages, context)]);
|
|
27
27
|
return true;
|
|
28
28
|
} catch (error) {
|
|
29
29
|
console.error(`Error in on after commit hook`, error);
|
|
@@ -65,7 +65,7 @@ var unknownTag = `${emmettPrefix}:unknown`;
|
|
|
65
65
|
// src/eventStore/events/index.ts
|
|
66
66
|
var GlobalStreamCaughtUpType = "__emt:GlobalStreamCaughtUp";
|
|
67
67
|
var isGlobalStreamCaughtUp = (event2) => event2.type === GlobalStreamCaughtUpType;
|
|
68
|
-
var caughtUpEventFrom = (position) => (event2) => event2.type === GlobalStreamCaughtUpType && _optionalChain([event2, 'access',
|
|
68
|
+
var caughtUpEventFrom = (position) => (event2) => event2.type === GlobalStreamCaughtUpType && _optionalChain([event2, 'access', _4 => _4.metadata, 'optionalAccess', _5 => _5.globalPosition]) >= position;
|
|
69
69
|
var globalStreamCaughtUp = (data) => event(GlobalStreamCaughtUpType, data, {
|
|
70
70
|
globalPosition: data.globalPosition
|
|
71
71
|
});
|
|
@@ -101,7 +101,7 @@ var assertExpectedVersionMatchesCurrent = (current, expected, defaultVersion) =>
|
|
|
101
101
|
};
|
|
102
102
|
var ExpectedVersionConflictError = class _ExpectedVersionConflictError extends _chunkWND32L6Pcjs.ConcurrencyError {
|
|
103
103
|
constructor(current, expected) {
|
|
104
|
-
super(_optionalChain([current, 'optionalAccess',
|
|
104
|
+
super(_optionalChain([current, 'optionalAccess', _6 => _6.toString, 'call', _7 => _7()]), _optionalChain([expected, 'optionalAccess', _8 => _8.toString, 'call', _9 => _9()]));
|
|
105
105
|
Object.setPrototypeOf(this, _ExpectedVersionConflictError.prototype);
|
|
106
106
|
}
|
|
107
107
|
};
|
|
@@ -406,7 +406,7 @@ var TaskProcessor = (_class = class {
|
|
|
406
406
|
this.stopped = true;
|
|
407
407
|
this.queue.length = 0;
|
|
408
408
|
this.activeGroups.clear();
|
|
409
|
-
if (!_optionalChain([options, 'optionalAccess',
|
|
409
|
+
if (!_optionalChain([options, 'optionalAccess', _14 => _14.force])) {
|
|
410
410
|
await this.waitForEndOfProcessing();
|
|
411
411
|
}
|
|
412
412
|
}
|
|
@@ -442,7 +442,7 @@ var TaskProcessor = (_class = class {
|
|
|
442
442
|
while (this.activeTasks < this.options.maxActiveTasks && this.queue.length > 0) {
|
|
443
443
|
const item = this.takeFirstAvailableItem();
|
|
444
444
|
if (item === null) return;
|
|
445
|
-
const groupId = _optionalChain([item, 'access',
|
|
445
|
+
const groupId = _optionalChain([item, 'access', _15 => _15.options, 'optionalAccess', _16 => _16.taskGroupId]);
|
|
446
446
|
if (groupId) {
|
|
447
447
|
this.activeGroups.add(groupId);
|
|
448
448
|
}
|
|
@@ -472,7 +472,7 @@ var TaskProcessor = (_class = class {
|
|
|
472
472
|
}
|
|
473
473
|
__init6() {this.takeFirstAvailableItem = () => {
|
|
474
474
|
const taskIndex = this.queue.findIndex(
|
|
475
|
-
(item2) => !_optionalChain([item2, 'access',
|
|
475
|
+
(item2) => !_optionalChain([item2, 'access', _17 => _17.options, 'optionalAccess', _18 => _18.taskGroupId]) || !this.activeGroups.has(item2.options.taskGroupId)
|
|
476
476
|
);
|
|
477
477
|
if (taskIndex === -1) {
|
|
478
478
|
return null;
|
|
@@ -481,7 +481,7 @@ var TaskProcessor = (_class = class {
|
|
|
481
481
|
return _nullishCoalesce(item, () => ( null));
|
|
482
482
|
}}
|
|
483
483
|
__init7() {this.hasItemsToProcess = () => this.queue.findIndex(
|
|
484
|
-
(item) => !_optionalChain([item, 'access',
|
|
484
|
+
(item) => !_optionalChain([item, 'access', _19 => _19.options, 'optionalAccess', _20 => _20.taskGroupId]) || !this.activeGroups.has(item.options.taskGroupId)
|
|
485
485
|
) !== -1}
|
|
486
486
|
}, _class);
|
|
487
487
|
var DEFAULT_PROMISE_DEADLINE = 2147483647;
|
|
@@ -522,7 +522,7 @@ var promiseWithDeadline = (executor, options) => {
|
|
|
522
522
|
var guardExclusiveAccess = (options) => {
|
|
523
523
|
const taskProcessor = new TaskProcessor({
|
|
524
524
|
maxActiveTasks: 1,
|
|
525
|
-
maxQueueSize: _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
525
|
+
maxQueueSize: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _21 => _21.maxQueueSize]), () => ( 1e3))
|
|
526
526
|
});
|
|
527
527
|
return {
|
|
528
528
|
execute: (operation) => taskProcessor.enqueue(async ({ ack }) => {
|
|
@@ -588,7 +588,7 @@ var guardBoundedAccess = (getResource, options) => {
|
|
|
588
588
|
stop: async (stopOptions) => {
|
|
589
589
|
if (isStopped) return;
|
|
590
590
|
isStopped = true;
|
|
591
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
591
|
+
if (_optionalChain([options, 'optionalAccess', _22 => _22.closeResource])) {
|
|
592
592
|
const resources = [...allResources];
|
|
593
593
|
allResources.clear();
|
|
594
594
|
resourcePool.length = 0;
|
|
@@ -606,7 +606,7 @@ var guardInitializedOnce = (initialize, options) => {
|
|
|
606
606
|
let initPromise = null;
|
|
607
607
|
const taskProcessor = new TaskProcessor({
|
|
608
608
|
maxActiveTasks: 1,
|
|
609
|
-
maxQueueSize: _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
609
|
+
maxQueueSize: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _23 => _23.maxQueueSize]), () => ( 1e3))
|
|
610
610
|
});
|
|
611
611
|
const ensureInitialized = async (retryCount = 0) => {
|
|
612
612
|
if (initPromise !== null) {
|
|
@@ -627,7 +627,7 @@ var guardInitializedOnce = (initialize, options) => {
|
|
|
627
627
|
} catch (error) {
|
|
628
628
|
initPromise = null;
|
|
629
629
|
ack();
|
|
630
|
-
const maxRetries = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
630
|
+
const maxRetries = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _24 => _24.maxRetries]), () => ( 3));
|
|
631
631
|
if (retryCount < maxRetries) {
|
|
632
632
|
return ensureInitialized(retryCount + 1);
|
|
633
633
|
}
|
|
@@ -723,27 +723,126 @@ var asyncAwaiter = () => {
|
|
|
723
723
|
// src/utils/retry.ts
|
|
724
724
|
var _asyncretry = require('async-retry'); var _asyncretry2 = _interopRequireDefault(_asyncretry);
|
|
725
725
|
|
|
726
|
-
// src/serialization/json/
|
|
727
|
-
var
|
|
728
|
-
|
|
729
|
-
|
|
726
|
+
// src/serialization/json/jsonSerializer.ts
|
|
727
|
+
var bigIntReplacer = (_key, value) => {
|
|
728
|
+
return typeof value === "bigint" ? value.toString() : value;
|
|
729
|
+
};
|
|
730
|
+
var dateReplacer = (_key, value) => {
|
|
731
|
+
return value instanceof Date ? value.toISOString() : value;
|
|
732
|
+
};
|
|
733
|
+
var isFirstLetterNumeric = (str) => {
|
|
734
|
+
const c = str.charCodeAt(0);
|
|
735
|
+
return c >= 48 && c <= 57;
|
|
736
|
+
};
|
|
737
|
+
var isFirstLetterNumericOrMinus = (str) => {
|
|
738
|
+
const c = str.charCodeAt(0);
|
|
739
|
+
return c >= 48 && c <= 57 || c === 45;
|
|
740
|
+
};
|
|
741
|
+
var bigIntReviver = (_key, value, context) => {
|
|
742
|
+
if (typeof value === "number" && Number.isInteger(value) && !Number.isSafeInteger(value)) {
|
|
743
|
+
try {
|
|
744
|
+
return BigInt(_nullishCoalesce(_optionalChain([context, 'optionalAccess', _25 => _25.source]), () => ( value.toString())));
|
|
745
|
+
} catch (e2) {
|
|
746
|
+
return value;
|
|
747
|
+
}
|
|
730
748
|
}
|
|
749
|
+
if (typeof value === "string" && value.length > 15) {
|
|
750
|
+
if (isFirstLetterNumericOrMinus(value)) {
|
|
751
|
+
const num = Number(value);
|
|
752
|
+
if (Number.isFinite(num) && !Number.isSafeInteger(num)) {
|
|
753
|
+
try {
|
|
754
|
+
return BigInt(value);
|
|
755
|
+
} catch (e3) {
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
return value;
|
|
731
761
|
};
|
|
732
|
-
var
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
(_, v) => typeof v === "bigint" ? v.toString() : v
|
|
739
|
-
);
|
|
740
|
-
},
|
|
741
|
-
parse: (text, options) => {
|
|
742
|
-
const parsed = JSON.parse(text, _optionalChain([options, 'optionalAccess', _27 => _27.reviver]));
|
|
743
|
-
if (_optionalChain([options, 'optionalAccess', _28 => _28.typeCheck]) && !_optionalChain([options, 'optionalAccess', _29 => _29.typeCheck, 'call', _30 => _30(parsed)]))
|
|
744
|
-
throw new ParseError(text);
|
|
745
|
-
return _optionalChain([options, 'optionalAccess', _31 => _31.map]) ? options.map(parsed) : parsed;
|
|
762
|
+
var dateReviver = (_key, value) => {
|
|
763
|
+
if (typeof value === "string" && value.length === 24 && isFirstLetterNumeric(value) && value[10] === "T" && value[23] === "Z") {
|
|
764
|
+
const date = new Date(value);
|
|
765
|
+
if (!isNaN(date.getTime())) {
|
|
766
|
+
return date;
|
|
767
|
+
}
|
|
746
768
|
}
|
|
769
|
+
return value;
|
|
770
|
+
};
|
|
771
|
+
var composeJSONReplacers = (...replacers) => {
|
|
772
|
+
const filteredReplacers = replacers.filter((r) => r !== void 0);
|
|
773
|
+
if (filteredReplacers.length === 0) return void 0;
|
|
774
|
+
return (key, value) => (
|
|
775
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
776
|
+
filteredReplacers.reduce(
|
|
777
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
778
|
+
(accValue, replacer) => replacer(key, accValue),
|
|
779
|
+
value
|
|
780
|
+
)
|
|
781
|
+
);
|
|
782
|
+
};
|
|
783
|
+
var composeJSONRevivers = (...revivers) => {
|
|
784
|
+
const filteredRevivers = revivers.filter((r) => r !== void 0);
|
|
785
|
+
if (filteredRevivers.length === 0) return void 0;
|
|
786
|
+
return (key, value, context) => (
|
|
787
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
788
|
+
filteredRevivers.reduce(
|
|
789
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
790
|
+
(accValue, reviver) => reviver(key, accValue, context),
|
|
791
|
+
value
|
|
792
|
+
)
|
|
793
|
+
);
|
|
794
|
+
};
|
|
795
|
+
var JSONReplacer = (opts) => composeJSONReplacers(
|
|
796
|
+
_optionalChain([opts, 'optionalAccess', _26 => _26.replacer]),
|
|
797
|
+
_optionalChain([opts, 'optionalAccess', _27 => _27.failOnBigIntSerialization]) !== true ? JSONReplacers.bigInt : void 0,
|
|
798
|
+
_optionalChain([opts, 'optionalAccess', _28 => _28.useDefaultDateSerialization]) !== true ? JSONReplacers.date : void 0
|
|
799
|
+
);
|
|
800
|
+
var JSONReviver = (opts) => composeJSONRevivers(
|
|
801
|
+
_optionalChain([opts, 'optionalAccess', _29 => _29.reviver]),
|
|
802
|
+
_optionalChain([opts, 'optionalAccess', _30 => _30.parseBigInts]) === true ? JSONRevivers.bigInt : void 0,
|
|
803
|
+
_optionalChain([opts, 'optionalAccess', _31 => _31.parseDates]) === true ? JSONRevivers.date : void 0
|
|
804
|
+
);
|
|
805
|
+
var JSONReplacers = {
|
|
806
|
+
bigInt: bigIntReplacer,
|
|
807
|
+
date: dateReplacer
|
|
808
|
+
};
|
|
809
|
+
var JSONRevivers = {
|
|
810
|
+
bigInt: bigIntReviver,
|
|
811
|
+
date: dateReviver
|
|
812
|
+
};
|
|
813
|
+
var jsonSerializer = (options) => {
|
|
814
|
+
const defaultReplacer = JSONReplacer(options);
|
|
815
|
+
const defaultReviver = JSONReviver(options);
|
|
816
|
+
return {
|
|
817
|
+
serialize: (object, serializerOptions) => JSON.stringify(
|
|
818
|
+
object,
|
|
819
|
+
serializerOptions ? JSONReplacer(serializerOptions) : defaultReplacer
|
|
820
|
+
),
|
|
821
|
+
deserialize: (payload, deserializerOptions) => JSON.parse(
|
|
822
|
+
payload,
|
|
823
|
+
deserializerOptions ? JSONReviver(deserializerOptions) : defaultReviver
|
|
824
|
+
)
|
|
825
|
+
};
|
|
826
|
+
};
|
|
827
|
+
var JSONSerializer = Object.assign(jsonSerializer(), {
|
|
828
|
+
from: (options) => _nullishCoalesce(_optionalChain([options, 'optionalAccess', _32 => _32.serialization, 'optionalAccess', _33 => _33.serializer]), () => ( (_optionalChain([options, 'optionalAccess', _34 => _34.serialization, 'optionalAccess', _35 => _35.options]) ? jsonSerializer(_optionalChain([options, 'optionalAccess', _36 => _36.serialization, 'optionalAccess', _37 => _37.options])) : JSONSerializer)))
|
|
829
|
+
});
|
|
830
|
+
var JSONCodec = (options) => {
|
|
831
|
+
const serializer = "serializer" in options && options.serializer ? options.serializer : jsonSerializer(
|
|
832
|
+
"serializerOptions" in options ? options.serializerOptions : void 0
|
|
833
|
+
);
|
|
834
|
+
const upcast = _nullishCoalesce(options.upcast, () => ( ((doc) => doc)));
|
|
835
|
+
const downcast = _nullishCoalesce(options.downcast, () => ( ((doc) => doc)));
|
|
836
|
+
return {
|
|
837
|
+
decode: (payload, decodeOptions) => {
|
|
838
|
+
const deserialized = decodeOptions ? serializer.deserialize(payload, decodeOptions) : serializer.deserialize(payload);
|
|
839
|
+
return upcast(deserialized);
|
|
840
|
+
},
|
|
841
|
+
encode: (object, encodeOptions) => {
|
|
842
|
+
const downcasted = downcast(object);
|
|
843
|
+
return encodeOptions ? serializer.serialize(downcasted, encodeOptions) : serializer.serialize(downcasted);
|
|
844
|
+
}
|
|
845
|
+
};
|
|
747
846
|
};
|
|
748
847
|
|
|
749
848
|
// src/utils/retry.ts
|
|
@@ -754,14 +853,14 @@ var asyncRetry = async (fn, opts) => {
|
|
|
754
853
|
async (bail) => {
|
|
755
854
|
try {
|
|
756
855
|
const result = await fn();
|
|
757
|
-
if (_optionalChain([opts, 'optionalAccess',
|
|
856
|
+
if (_optionalChain([opts, 'optionalAccess', _38 => _38.shouldRetryResult]) && opts.shouldRetryResult(result)) {
|
|
758
857
|
throw new (0, _chunkWND32L6Pcjs.EmmettError)(
|
|
759
|
-
`Retrying because of result: ${
|
|
858
|
+
`Retrying because of result: ${JSONSerializer.serialize(result)}`
|
|
760
859
|
);
|
|
761
860
|
}
|
|
762
861
|
return result;
|
|
763
862
|
} catch (error) {
|
|
764
|
-
if (_optionalChain([opts, 'optionalAccess',
|
|
863
|
+
if (_optionalChain([opts, 'optionalAccess', _39 => _39.shouldRetryError]) && !opts.shouldRetryError(error)) {
|
|
765
864
|
bail(error);
|
|
766
865
|
return void 0;
|
|
767
866
|
}
|
|
@@ -826,11 +925,11 @@ var operationResult = (result, options) => {
|
|
|
826
925
|
const { operationName, collectionName } = options;
|
|
827
926
|
if (!successful)
|
|
828
927
|
throw new (0, _chunkWND32L6Pcjs.ConcurrencyInMemoryDatabaseError)(
|
|
829
|
-
_nullishCoalesce(errorMessage, () => ( `${operationName} on ${collectionName} failed. Expected document state does not match current one! Result: ${
|
|
928
|
+
_nullishCoalesce(errorMessage, () => ( `${operationName} on ${collectionName} failed. Expected document state does not match current one! Result: ${JSONSerializer.serialize(result)}!`))
|
|
830
929
|
);
|
|
831
930
|
}
|
|
832
931
|
};
|
|
833
|
-
if (_optionalChain([options, 'access',
|
|
932
|
+
if (_optionalChain([options, 'access', _40 => _40.errors, 'optionalAccess', _41 => _41.throwOnOperationFailures]))
|
|
834
933
|
operationResult2.assertSuccessful();
|
|
835
934
|
return operationResult2;
|
|
836
935
|
};
|
|
@@ -877,14 +976,14 @@ var getInMemoryDatabase = () => {
|
|
|
877
976
|
findOne: (predicate) => {
|
|
878
977
|
ensureCollectionCreated();
|
|
879
978
|
const documentsInCollection = storage.get(collectionName);
|
|
880
|
-
const filteredDocuments = predicate ? _optionalChain([documentsInCollection, 'optionalAccess',
|
|
881
|
-
const firstOne = _nullishCoalesce(_optionalChain([filteredDocuments, 'optionalAccess',
|
|
979
|
+
const filteredDocuments = predicate ? _optionalChain([documentsInCollection, 'optionalAccess', _42 => _42.filter, 'call', _43 => _43((doc) => predicate(doc))]) : documentsInCollection;
|
|
980
|
+
const firstOne = _nullishCoalesce(_optionalChain([filteredDocuments, 'optionalAccess', _44 => _44[0]]), () => ( null));
|
|
882
981
|
return Promise.resolve(firstOne);
|
|
883
982
|
},
|
|
884
983
|
find: (predicate) => {
|
|
885
984
|
ensureCollectionCreated();
|
|
886
985
|
const documentsInCollection = storage.get(collectionName);
|
|
887
|
-
const filteredDocuments = predicate ? _optionalChain([documentsInCollection, 'optionalAccess',
|
|
986
|
+
const filteredDocuments = predicate ? _optionalChain([documentsInCollection, 'optionalAccess', _45 => _45.filter, 'call', _46 => _46((doc) => predicate(doc))]) : documentsInCollection;
|
|
888
987
|
return Promise.resolve(filteredDocuments);
|
|
889
988
|
},
|
|
890
989
|
deleteOne: (predicate) => {
|
|
@@ -956,7 +1055,7 @@ var getInMemoryDatabase = () => {
|
|
|
956
1055
|
);
|
|
957
1056
|
}
|
|
958
1057
|
const existing = documentsInCollection[firstIndex];
|
|
959
|
-
if (typeof _optionalChain([options, 'optionalAccess',
|
|
1058
|
+
if (typeof _optionalChain([options, 'optionalAccess', _47 => _47.expectedVersion]) === "bigint" && existing._version !== options.expectedVersion) {
|
|
960
1059
|
return Promise.resolve(
|
|
961
1060
|
operationResult(
|
|
962
1061
|
{
|
|
@@ -1156,7 +1255,7 @@ var reactor = (options) => {
|
|
|
1156
1255
|
}
|
|
1157
1256
|
if (startFrom && startFrom !== "CURRENT") return startFrom;
|
|
1158
1257
|
if (checkpoints) {
|
|
1159
|
-
const readResult = await _optionalChain([checkpoints, 'optionalAccess',
|
|
1258
|
+
const readResult = await _optionalChain([checkpoints, 'optionalAccess', _48 => _48.read, 'call', _49 => _49(
|
|
1160
1259
|
{
|
|
1161
1260
|
processorId,
|
|
1162
1261
|
partition
|
|
@@ -1184,7 +1283,7 @@ var reactor = (options) => {
|
|
|
1184
1283
|
const upcasted = upcastRecordedMessage(
|
|
1185
1284
|
// TODO: Make it smarter
|
|
1186
1285
|
message2,
|
|
1187
|
-
_optionalChain([options, 'access',
|
|
1286
|
+
_optionalChain([options, 'access', _50 => _50.messageOptions, 'optionalAccess', _51 => _51.schema, 'optionalAccess', _52 => _52.versioning])
|
|
1188
1287
|
);
|
|
1189
1288
|
if (canHandle !== void 0 && !canHandle.includes(upcasted.type))
|
|
1190
1289
|
continue;
|
|
@@ -1237,13 +1336,13 @@ var projector = (options) => {
|
|
|
1237
1336
|
processorId,
|
|
1238
1337
|
messageOptions: options.projection.eventsOptions,
|
|
1239
1338
|
hooks: {
|
|
1240
|
-
onInit: _optionalChain([options, 'access',
|
|
1241
|
-
onStart: options.truncateOnStart && options.projection.truncate || _optionalChain([options, 'access',
|
|
1339
|
+
onInit: _optionalChain([options, 'access', _53 => _53.hooks, 'optionalAccess', _54 => _54.onInit]),
|
|
1340
|
+
onStart: options.truncateOnStart && options.projection.truncate || _optionalChain([options, 'access', _55 => _55.hooks, 'optionalAccess', _56 => _56.onStart]) ? async (context) => {
|
|
1242
1341
|
if (options.truncateOnStart && options.projection.truncate)
|
|
1243
1342
|
await options.projection.truncate(context);
|
|
1244
|
-
if (_optionalChain([options, 'access',
|
|
1343
|
+
if (_optionalChain([options, 'access', _57 => _57.hooks, 'optionalAccess', _58 => _58.onStart])) await _optionalChain([options, 'access', _59 => _59.hooks, 'optionalAccess', _60 => _60.onStart, 'call', _61 => _61(context)]);
|
|
1245
1344
|
} : void 0,
|
|
1246
|
-
onClose: _optionalChain([options, 'access',
|
|
1345
|
+
onClose: _optionalChain([options, 'access', _62 => _62.hooks, 'optionalAccess', _63 => _63.onClose])
|
|
1247
1346
|
},
|
|
1248
1347
|
eachMessage: async (event2, context) => projection2.handle([event2], context)
|
|
1249
1348
|
});
|
|
@@ -1255,7 +1354,7 @@ var inMemoryCheckpointer = () => {
|
|
|
1255
1354
|
read: async ({ processorId }, { database }) => {
|
|
1256
1355
|
const checkpoint = await database.collection("emt_processor_checkpoints").findOne((d) => d._id === processorId);
|
|
1257
1356
|
return Promise.resolve({
|
|
1258
|
-
lastCheckpoint: _nullishCoalesce(_optionalChain([checkpoint, 'optionalAccess',
|
|
1357
|
+
lastCheckpoint: _nullishCoalesce(_optionalChain([checkpoint, 'optionalAccess', _64 => _64.lastCheckpoint]), () => ( null))
|
|
1259
1358
|
});
|
|
1260
1359
|
},
|
|
1261
1360
|
store: async (context, { database }) => {
|
|
@@ -1266,7 +1365,7 @@ var inMemoryCheckpointer = () => {
|
|
|
1266
1365
|
const checkpoint = await checkpoints.findOne(
|
|
1267
1366
|
(d) => d._id === processorId
|
|
1268
1367
|
);
|
|
1269
|
-
const currentPosition = _nullishCoalesce(_optionalChain([checkpoint, 'optionalAccess',
|
|
1368
|
+
const currentPosition = _nullishCoalesce(_optionalChain([checkpoint, 'optionalAccess', _65 => _65.lastCheckpoint]), () => ( null));
|
|
1270
1369
|
const newCheckpoint = getCheckpoint(message2);
|
|
1271
1370
|
if (currentPosition && (currentPosition === newCheckpoint || currentPosition !== lastCheckpoint)) {
|
|
1272
1371
|
return {
|
|
@@ -1286,7 +1385,7 @@ var inMemoryCheckpointer = () => {
|
|
|
1286
1385
|
var inMemoryProcessingScope = (options) => {
|
|
1287
1386
|
const processorDatabase = options.database;
|
|
1288
1387
|
const processingScope = (handler, partialContext) => {
|
|
1289
|
-
const database = _nullishCoalesce(processorDatabase, () => ( _optionalChain([partialContext, 'optionalAccess',
|
|
1388
|
+
const database = _nullishCoalesce(processorDatabase, () => ( _optionalChain([partialContext, 'optionalAccess', _66 => _66.database])));
|
|
1290
1389
|
if (!database)
|
|
1291
1390
|
throw new (0, _chunkWND32L6Pcjs.EmmettError)(
|
|
1292
1391
|
`InMemory processor '${options.processorId}' is missing database. Ensure that you passed it through options`
|
|
@@ -1296,12 +1395,12 @@ var inMemoryProcessingScope = (options) => {
|
|
|
1296
1395
|
return processingScope;
|
|
1297
1396
|
};
|
|
1298
1397
|
var inMemoryProjector = (options) => {
|
|
1299
|
-
const database = _nullishCoalesce(_optionalChain([options, 'access',
|
|
1398
|
+
const database = _nullishCoalesce(_optionalChain([options, 'access', _67 => _67.connectionOptions, 'optionalAccess', _68 => _68.database]), () => ( getInMemoryDatabase()));
|
|
1300
1399
|
const hooks = {
|
|
1301
|
-
onInit: _optionalChain([options, 'access',
|
|
1302
|
-
onStart: _optionalChain([options, 'access',
|
|
1303
|
-
onClose: _optionalChain([options, 'access',
|
|
1304
|
-
if (_optionalChain([options, 'access',
|
|
1400
|
+
onInit: _optionalChain([options, 'access', _69 => _69.hooks, 'optionalAccess', _70 => _70.onInit]),
|
|
1401
|
+
onStart: _optionalChain([options, 'access', _71 => _71.hooks, 'optionalAccess', _72 => _72.onStart]),
|
|
1402
|
+
onClose: _optionalChain([options, 'access', _73 => _73.hooks, 'optionalAccess', _74 => _74.onClose]) ? async (context) => {
|
|
1403
|
+
if (_optionalChain([options, 'access', _75 => _75.hooks, 'optionalAccess', _76 => _76.onClose])) await _optionalChain([options, 'access', _77 => _77.hooks, 'optionalAccess', _78 => _78.onClose, 'call', _79 => _79(context)]);
|
|
1305
1404
|
} : void 0
|
|
1306
1405
|
};
|
|
1307
1406
|
const processor = projector({
|
|
@@ -1316,11 +1415,11 @@ var inMemoryProjector = (options) => {
|
|
|
1316
1415
|
return Object.assign(processor, { database });
|
|
1317
1416
|
};
|
|
1318
1417
|
var inMemoryReactor = (options) => {
|
|
1319
|
-
const database = _nullishCoalesce(_optionalChain([options, 'access',
|
|
1418
|
+
const database = _nullishCoalesce(_optionalChain([options, 'access', _80 => _80.connectionOptions, 'optionalAccess', _81 => _81.database]), () => ( getInMemoryDatabase()));
|
|
1320
1419
|
const hooks = {
|
|
1321
|
-
onInit: _optionalChain([options, 'access',
|
|
1322
|
-
onStart: _optionalChain([options, 'access',
|
|
1323
|
-
onClose: _optionalChain([options, 'access',
|
|
1420
|
+
onInit: _optionalChain([options, 'access', _82 => _82.hooks, 'optionalAccess', _83 => _83.onInit]),
|
|
1421
|
+
onStart: _optionalChain([options, 'access', _84 => _84.hooks, 'optionalAccess', _85 => _85.onStart]),
|
|
1422
|
+
onClose: _optionalChain([options, 'access', _86 => _86.hooks, 'optionalAccess', _87 => _87.onClose])
|
|
1324
1423
|
};
|
|
1325
1424
|
const processor = reactor({
|
|
1326
1425
|
...options,
|
|
@@ -1449,7 +1548,7 @@ var assertThrowsAsync = async (fun, errorCheck) => {
|
|
|
1449
1548
|
}
|
|
1450
1549
|
assertTrue(
|
|
1451
1550
|
errorCheck(typedError),
|
|
1452
|
-
`Error doesn't match the expected condition: ${
|
|
1551
|
+
`Error doesn't match the expected condition: ${JSONSerializer.serialize(error)}`
|
|
1453
1552
|
);
|
|
1454
1553
|
return typedError;
|
|
1455
1554
|
}
|
|
@@ -1463,7 +1562,7 @@ var assertThrows = (fun, errorCheck) => {
|
|
|
1463
1562
|
if (errorCheck) {
|
|
1464
1563
|
assertTrue(
|
|
1465
1564
|
errorCheck(typedError),
|
|
1466
|
-
`Error doesn't match the expected condition: ${
|
|
1565
|
+
`Error doesn't match the expected condition: ${JSONSerializer.serialize(error)}`
|
|
1467
1566
|
);
|
|
1468
1567
|
} else if (typedError instanceof AssertionError) {
|
|
1469
1568
|
assertFalse(
|
|
@@ -1484,10 +1583,12 @@ var assertDoesNotThrow = (fun, errorCheck) => {
|
|
|
1484
1583
|
if (errorCheck) {
|
|
1485
1584
|
assertFalse(
|
|
1486
1585
|
errorCheck(typedError),
|
|
1487
|
-
`Error matching the expected condition was thrown!: ${
|
|
1586
|
+
`Error matching the expected condition was thrown!: ${JSONSerializer.serialize(error)}`
|
|
1488
1587
|
);
|
|
1489
1588
|
} else {
|
|
1490
|
-
assertFails(
|
|
1589
|
+
assertFails(
|
|
1590
|
+
`Function threw an error: ${JSONSerializer.serialize(error)}`
|
|
1591
|
+
);
|
|
1491
1592
|
}
|
|
1492
1593
|
return typedError;
|
|
1493
1594
|
}
|
|
@@ -1506,27 +1607,27 @@ var assertMatches = (actual, expected, message2) => {
|
|
|
1506
1607
|
if (!isSubset(actual, expected))
|
|
1507
1608
|
throw new AssertionError(
|
|
1508
1609
|
_nullishCoalesce(message2, () => ( `subObj:
|
|
1509
|
-
${
|
|
1610
|
+
${JSONSerializer.serialize(expected)}
|
|
1510
1611
|
is not subset of
|
|
1511
|
-
${
|
|
1612
|
+
${JSONSerializer.serialize(actual)}`))
|
|
1512
1613
|
);
|
|
1513
1614
|
};
|
|
1514
1615
|
var assertDeepEqual = (actual, expected, message2) => {
|
|
1515
1616
|
if (!deepEquals(actual, expected))
|
|
1516
1617
|
throw new AssertionError(
|
|
1517
1618
|
_nullishCoalesce(message2, () => ( `subObj:
|
|
1518
|
-
${
|
|
1619
|
+
${JSONSerializer.serialize(expected)}
|
|
1519
1620
|
is not equal to
|
|
1520
|
-
${
|
|
1621
|
+
${JSONSerializer.serialize(actual)}`))
|
|
1521
1622
|
);
|
|
1522
1623
|
};
|
|
1523
1624
|
var assertNotDeepEqual = (actual, expected, message2) => {
|
|
1524
1625
|
if (deepEquals(actual, expected))
|
|
1525
1626
|
throw new AssertionError(
|
|
1526
1627
|
_nullishCoalesce(message2, () => ( `subObj:
|
|
1527
|
-
${
|
|
1628
|
+
${JSONSerializer.serialize(expected)}
|
|
1528
1629
|
is equals to
|
|
1529
|
-
${
|
|
1630
|
+
${JSONSerializer.serialize(actual)}`))
|
|
1530
1631
|
);
|
|
1531
1632
|
};
|
|
1532
1633
|
var assertThat = (item) => {
|
|
@@ -1552,14 +1653,14 @@ function assertEqual(expected, actual, message2) {
|
|
|
1552
1653
|
if (expected !== actual)
|
|
1553
1654
|
throw new AssertionError(
|
|
1554
1655
|
`${_nullishCoalesce(message2, () => ( "Objects are not equal"))}:
|
|
1555
|
-
Expected: ${
|
|
1556
|
-
Actual: ${
|
|
1656
|
+
Expected: ${JSONSerializer.serialize(expected)}
|
|
1657
|
+
Actual: ${JSONSerializer.serialize(actual)}`
|
|
1557
1658
|
);
|
|
1558
1659
|
}
|
|
1559
1660
|
function assertNotEqual(obj, other, message2) {
|
|
1560
1661
|
if (obj === other)
|
|
1561
1662
|
throw new AssertionError(
|
|
1562
|
-
_nullishCoalesce(message2, () => ( `Objects are equal: ${
|
|
1663
|
+
_nullishCoalesce(message2, () => ( `Objects are equal: ${JSONSerializer.serialize(obj)}`))
|
|
1563
1664
|
);
|
|
1564
1665
|
}
|
|
1565
1666
|
function assertIsNotNull(result) {
|
|
@@ -1574,39 +1675,39 @@ var argMatches = (matches) => (arg) => matches(arg);
|
|
|
1574
1675
|
function verifyThat(fn) {
|
|
1575
1676
|
return {
|
|
1576
1677
|
calledTimes: (times) => {
|
|
1577
|
-
assertEqual(_optionalChain([fn, 'access',
|
|
1678
|
+
assertEqual(_optionalChain([fn, 'access', _88 => _88.mock, 'optionalAccess', _89 => _89.calls, 'optionalAccess', _90 => _90.length]), times);
|
|
1578
1679
|
},
|
|
1579
1680
|
notCalled: () => {
|
|
1580
|
-
assertEqual(_optionalChain([fn, 'optionalAccess',
|
|
1681
|
+
assertEqual(_optionalChain([fn, 'optionalAccess', _91 => _91.mock, 'optionalAccess', _92 => _92.calls, 'optionalAccess', _93 => _93.length]), 0);
|
|
1581
1682
|
},
|
|
1582
1683
|
called: () => {
|
|
1583
1684
|
assertTrue(
|
|
1584
|
-
_optionalChain([fn, 'access',
|
|
1685
|
+
_optionalChain([fn, 'access', _94 => _94.mock, 'optionalAccess', _95 => _95.calls, 'access', _96 => _96.length]) !== void 0 && fn.mock.calls.length > 0
|
|
1585
1686
|
);
|
|
1586
1687
|
},
|
|
1587
1688
|
calledWith: (...args) => {
|
|
1588
1689
|
assertTrue(
|
|
1589
|
-
_optionalChain([fn, 'access',
|
|
1690
|
+
_optionalChain([fn, 'access', _97 => _97.mock, 'optionalAccess', _98 => _98.calls, 'access', _99 => _99.length]) !== void 0 && fn.mock.calls.length >= 1 && fn.mock.calls.some((call) => deepEquals(call.arguments, args))
|
|
1590
1691
|
);
|
|
1591
1692
|
},
|
|
1592
1693
|
calledOnceWith: (...args) => {
|
|
1593
1694
|
assertTrue(
|
|
1594
|
-
_optionalChain([fn, 'access',
|
|
1695
|
+
_optionalChain([fn, 'access', _100 => _100.mock, 'optionalAccess', _101 => _101.calls, 'access', _102 => _102.length]) !== void 0 && fn.mock.calls.length === 1 && fn.mock.calls.some((call) => deepEquals(call.arguments, args))
|
|
1595
1696
|
);
|
|
1596
1697
|
},
|
|
1597
1698
|
calledWithArgumentMatching: (...matches) => {
|
|
1598
1699
|
assertTrue(
|
|
1599
|
-
_optionalChain([fn, 'access',
|
|
1700
|
+
_optionalChain([fn, 'access', _103 => _103.mock, 'optionalAccess', _104 => _104.calls, 'access', _105 => _105.length]) !== void 0 && fn.mock.calls.length >= 1
|
|
1600
1701
|
);
|
|
1601
1702
|
assertTrue(
|
|
1602
|
-
_optionalChain([fn, 'access',
|
|
1703
|
+
_optionalChain([fn, 'access', _106 => _106.mock, 'optionalAccess', _107 => _107.calls, 'access', _108 => _108.length]) !== void 0 && fn.mock.calls.length >= 1 && fn.mock.calls.some(
|
|
1603
1704
|
(call) => call.arguments && call.arguments.length >= matches.length && matches.every((match, index) => match(call.arguments[index]))
|
|
1604
1705
|
)
|
|
1605
1706
|
);
|
|
1606
1707
|
},
|
|
1607
1708
|
notCalledWithArgumentMatching: (...matches) => {
|
|
1608
1709
|
assertFalse(
|
|
1609
|
-
_optionalChain([fn, 'access',
|
|
1710
|
+
_optionalChain([fn, 'access', _109 => _109.mock, 'optionalAccess', _110 => _110.calls, 'access', _111 => _111.length]) !== void 0 && fn.mock.calls.length >= 1 && fn.mock.calls[0].arguments && fn.mock.calls[0].arguments.length >= matches.length && matches.every(
|
|
1610
1711
|
(match, index) => match(fn.mock.calls[0].arguments[index])
|
|
1611
1712
|
)
|
|
1612
1713
|
);
|
|
@@ -1618,7 +1719,7 @@ var assertThatArray = (array) => {
|
|
|
1618
1719
|
isEmpty: () => assertEqual(
|
|
1619
1720
|
array.length,
|
|
1620
1721
|
0,
|
|
1621
|
-
`Array is not empty ${
|
|
1722
|
+
`Array is not empty ${JSONSerializer.serialize(array)}`
|
|
1622
1723
|
),
|
|
1623
1724
|
isNotEmpty: () => assertNotEqual(array.length, 0, `Array is empty`),
|
|
1624
1725
|
hasSize: (length) => assertEqual(array.length, length),
|
|
@@ -1751,18 +1852,18 @@ function thenThrowsErrorHandler(error, args) {
|
|
|
1751
1852
|
if (!_chunkWND32L6Pcjs.isErrorConstructor.call(void 0, args[0])) {
|
|
1752
1853
|
assertTrue(
|
|
1753
1854
|
args[0](error),
|
|
1754
|
-
`Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess',
|
|
1855
|
+
`Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess', _112 => _112.toString, 'call', _113 => _113()])}`
|
|
1755
1856
|
);
|
|
1756
1857
|
return;
|
|
1757
1858
|
}
|
|
1758
1859
|
assertTrue(
|
|
1759
1860
|
error instanceof args[0],
|
|
1760
|
-
`Caught error is not an instance of the expected type: ${_optionalChain([error, 'optionalAccess',
|
|
1861
|
+
`Caught error is not an instance of the expected type: ${_optionalChain([error, 'optionalAccess', _114 => _114.toString, 'call', _115 => _115()])}`
|
|
1761
1862
|
);
|
|
1762
1863
|
if (args[1]) {
|
|
1763
1864
|
assertTrue(
|
|
1764
1865
|
args[1](error),
|
|
1765
|
-
`Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess',
|
|
1866
|
+
`Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess', _116 => _116.toString, 'call', _117 => _117()])}`
|
|
1766
1867
|
);
|
|
1767
1868
|
}
|
|
1768
1869
|
}
|
|
@@ -1820,18 +1921,18 @@ function thenThrowsErrorHandler2(error, args) {
|
|
|
1820
1921
|
if (!_chunkWND32L6Pcjs.isErrorConstructor.call(void 0, args[0])) {
|
|
1821
1922
|
assertTrue(
|
|
1822
1923
|
args[0](error),
|
|
1823
|
-
`Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess',
|
|
1924
|
+
`Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess', _118 => _118.toString, 'call', _119 => _119()])}`
|
|
1824
1925
|
);
|
|
1825
1926
|
return;
|
|
1826
1927
|
}
|
|
1827
1928
|
assertTrue(
|
|
1828
1929
|
error instanceof args[0],
|
|
1829
|
-
`Caught error is not an instance of the expected type: ${_optionalChain([error, 'optionalAccess',
|
|
1930
|
+
`Caught error is not an instance of the expected type: ${_optionalChain([error, 'optionalAccess', _120 => _120.toString, 'call', _121 => _121()])}`
|
|
1830
1931
|
);
|
|
1831
1932
|
if (args[1]) {
|
|
1832
1933
|
assertTrue(
|
|
1833
1934
|
args[1](error),
|
|
1834
|
-
`Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess',
|
|
1935
|
+
`Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess', _122 => _122.toString, 'call', _123 => _123()])}`
|
|
1835
1936
|
);
|
|
1836
1937
|
}
|
|
1837
1938
|
}
|
|
@@ -1887,7 +1988,7 @@ var InMemoryProjectionSpec = {
|
|
|
1887
1988
|
const allEvents = [];
|
|
1888
1989
|
const run = async (database) => {
|
|
1889
1990
|
let globalPosition = 0n;
|
|
1890
|
-
const numberOfTimes = _nullishCoalesce(_optionalChain([options2, 'optionalAccess',
|
|
1991
|
+
const numberOfTimes = _nullishCoalesce(_optionalChain([options2, 'optionalAccess', _124 => _124.numberOfTimes]), () => ( 1));
|
|
1891
1992
|
for (const event2 of [
|
|
1892
1993
|
...givenEvents,
|
|
1893
1994
|
...Array.from({ length: numberOfTimes }).flatMap(() => events)
|
|
@@ -1896,7 +1997,7 @@ var InMemoryProjectionSpec = {
|
|
|
1896
1997
|
checkpoint: bigIntProcessorCheckpoint(++globalPosition),
|
|
1897
1998
|
globalPosition,
|
|
1898
1999
|
streamPosition: globalPosition,
|
|
1899
|
-
streamName: _nullishCoalesce(_optionalChain([event2, 'access',
|
|
2000
|
+
streamName: _nullishCoalesce(_optionalChain([event2, 'access', _125 => _125.metadata, 'optionalAccess', _126 => _126.streamName]), () => ( `test-${_uuid.v4.call(void 0, )}`)),
|
|
1900
2001
|
messageId: _uuid.v4.call(void 0, )
|
|
1901
2002
|
};
|
|
1902
2003
|
allEvents.push({
|
|
@@ -1963,18 +2064,18 @@ var InMemoryProjectionSpec = {
|
|
|
1963
2064
|
if (!_chunkWND32L6Pcjs.isErrorConstructor.call(void 0, args[0])) {
|
|
1964
2065
|
assertTrue(
|
|
1965
2066
|
args[0](error),
|
|
1966
|
-
`Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess',
|
|
2067
|
+
`Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess', _127 => _127.toString, 'call', _128 => _128()])}`
|
|
1967
2068
|
);
|
|
1968
2069
|
return;
|
|
1969
2070
|
}
|
|
1970
2071
|
assertTrue(
|
|
1971
2072
|
error instanceof args[0],
|
|
1972
|
-
`Caught error is not an instance of the expected type: ${_optionalChain([error, 'optionalAccess',
|
|
2073
|
+
`Caught error is not an instance of the expected type: ${_optionalChain([error, 'optionalAccess', _129 => _129.toString, 'call', _130 => _130()])}`
|
|
1973
2074
|
);
|
|
1974
2075
|
if (args[1]) {
|
|
1975
2076
|
assertTrue(
|
|
1976
2077
|
args[1](error),
|
|
1977
|
-
`Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess',
|
|
2078
|
+
`Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess', _131 => _131.toString, 'call', _132 => _132()])}`
|
|
1978
2079
|
);
|
|
1979
2080
|
}
|
|
1980
2081
|
}
|
|
@@ -1990,7 +2091,7 @@ var eventInStream = (streamName, event2) => {
|
|
|
1990
2091
|
...event2,
|
|
1991
2092
|
metadata: {
|
|
1992
2093
|
..._nullishCoalesce(event2.metadata, () => ( {})),
|
|
1993
|
-
streamName: _nullishCoalesce(_optionalChain([event2, 'access',
|
|
2094
|
+
streamName: _nullishCoalesce(_optionalChain([event2, 'access', _133 => _133.metadata, 'optionalAccess', _134 => _134.streamName]), () => ( streamName))
|
|
1994
2095
|
}
|
|
1995
2096
|
};
|
|
1996
2097
|
};
|
|
@@ -2013,7 +2114,7 @@ function documentExists(expected, options) {
|
|
|
2013
2114
|
}
|
|
2014
2115
|
for (const [key, value] of Object.entries(expected)) {
|
|
2015
2116
|
const propKey = key;
|
|
2016
|
-
if (!(key in document) ||
|
|
2117
|
+
if (!(key in document) || JSONSerializer.serialize(document[propKey]) !== JSONSerializer.serialize(value)) {
|
|
2017
2118
|
assertFails(`Property ${key} doesn't match the expected value`);
|
|
2018
2119
|
return Promise.resolve(false);
|
|
2019
2120
|
}
|
|
@@ -2034,7 +2135,7 @@ var expectInMemoryDocuments = {
|
|
|
2034
2135
|
|
|
2035
2136
|
// src/eventStore/versioning/downcasting.ts
|
|
2036
2137
|
var downcastRecordedMessage = (recordedMessage, options) => {
|
|
2037
|
-
if (!_optionalChain([options, 'optionalAccess',
|
|
2138
|
+
if (!_optionalChain([options, 'optionalAccess', _135 => _135.downcast]))
|
|
2038
2139
|
return recordedMessage;
|
|
2039
2140
|
const downcasted = options.downcast(
|
|
2040
2141
|
recordedMessage
|
|
@@ -2052,7 +2153,7 @@ var downcastRecordedMessage = (recordedMessage, options) => {
|
|
|
2052
2153
|
};
|
|
2053
2154
|
};
|
|
2054
2155
|
var downcastRecordedMessages = (recordedMessages, options) => {
|
|
2055
|
-
if (!_optionalChain([options, 'optionalAccess',
|
|
2156
|
+
if (!_optionalChain([options, 'optionalAccess', _136 => _136.downcast]))
|
|
2056
2157
|
return recordedMessages;
|
|
2057
2158
|
return recordedMessages.map(
|
|
2058
2159
|
(recordedMessage) => downcastRecordedMessage(recordedMessage, options)
|
|
@@ -2061,7 +2162,7 @@ var downcastRecordedMessages = (recordedMessages, options) => {
|
|
|
2061
2162
|
|
|
2062
2163
|
// src/eventStore/versioning/upcasting.ts
|
|
2063
2164
|
var upcastRecordedMessage = (recordedMessage, options) => {
|
|
2064
|
-
if (!_optionalChain([options, 'optionalAccess',
|
|
2165
|
+
if (!_optionalChain([options, 'optionalAccess', _137 => _137.upcast]))
|
|
2065
2166
|
return recordedMessage;
|
|
2066
2167
|
const upcasted = options.upcast(
|
|
2067
2168
|
recordedMessage
|
|
@@ -2079,7 +2180,7 @@ var upcastRecordedMessage = (recordedMessage, options) => {
|
|
|
2079
2180
|
};
|
|
2080
2181
|
};
|
|
2081
2182
|
var upcastRecordedMessages = (recordedMessages, options) => {
|
|
2082
|
-
if (!_optionalChain([options, 'optionalAccess',
|
|
2183
|
+
if (!_optionalChain([options, 'optionalAccess', _138 => _138.upcast]))
|
|
2083
2184
|
return recordedMessages;
|
|
2084
2185
|
return recordedMessages.map(
|
|
2085
2186
|
(recordedMessage) => upcastRecordedMessage(recordedMessage, options)
|
|
@@ -2093,8 +2194,8 @@ var getInMemoryEventStore = (eventStoreOptions) => {
|
|
|
2093
2194
|
const getAllEventsCount = () => {
|
|
2094
2195
|
return Array.from(streams.values()).map((s) => s.length).reduce((p, c) => p + c, 0);
|
|
2095
2196
|
};
|
|
2096
|
-
const database = _optionalChain([eventStoreOptions, 'optionalAccess',
|
|
2097
|
-
const inlineProjections2 = (_nullishCoalesce(_optionalChain([eventStoreOptions, 'optionalAccess',
|
|
2197
|
+
const database = _optionalChain([eventStoreOptions, 'optionalAccess', _139 => _139.database]) || getInMemoryDatabase();
|
|
2198
|
+
const inlineProjections2 = (_nullishCoalesce(_optionalChain([eventStoreOptions, 'optionalAccess', _140 => _140.projections]), () => ( []))).filter(({ type }) => type === "inline").map(({ projection: projection2 }) => projection2);
|
|
2098
2199
|
const eventStore = {
|
|
2099
2200
|
database,
|
|
2100
2201
|
async aggregateStream(streamName, options) {
|
|
@@ -2103,7 +2204,7 @@ var getInMemoryEventStore = (eventStoreOptions) => {
|
|
|
2103
2204
|
streamName,
|
|
2104
2205
|
read
|
|
2105
2206
|
);
|
|
2106
|
-
const events = _nullishCoalesce(_optionalChain([result, 'optionalAccess',
|
|
2207
|
+
const events = _nullishCoalesce(_optionalChain([result, 'optionalAccess', _141 => _141.events]), () => ( []));
|
|
2107
2208
|
const state = events.reduce((s, e) => evolve(s, e), initialState());
|
|
2108
2209
|
return {
|
|
2109
2210
|
currentStreamVersion: BigInt(events.length),
|
|
@@ -2111,21 +2212,21 @@ var getInMemoryEventStore = (eventStoreOptions) => {
|
|
|
2111
2212
|
streamExists: result.streamExists
|
|
2112
2213
|
};
|
|
2113
2214
|
},
|
|
2114
|
-
readStream: (streamName,
|
|
2215
|
+
readStream: (streamName, readOptions) => {
|
|
2115
2216
|
const events = streams.get(streamName);
|
|
2116
2217
|
const currentStreamVersion = events ? BigInt(events.length) : InMemoryEventStoreDefaultStreamVersion;
|
|
2117
2218
|
assertExpectedVersionMatchesCurrent(
|
|
2118
2219
|
currentStreamVersion,
|
|
2119
|
-
_optionalChain([
|
|
2220
|
+
_optionalChain([readOptions, 'optionalAccess', _142 => _142.expectedStreamVersion]),
|
|
2120
2221
|
InMemoryEventStoreDefaultStreamVersion
|
|
2121
2222
|
);
|
|
2122
|
-
const from = Number(_nullishCoalesce(_optionalChain([
|
|
2223
|
+
const from = Number(_nullishCoalesce(_optionalChain([readOptions, 'optionalAccess', _143 => _143.from]), () => ( 0)));
|
|
2123
2224
|
const to = Number(
|
|
2124
|
-
_nullishCoalesce(_optionalChain([
|
|
2225
|
+
_nullishCoalesce(_optionalChain([readOptions, 'optionalAccess', _144 => _144.to]), () => ( (_optionalChain([readOptions, 'optionalAccess', _145 => _145.maxCount]) ? (_nullishCoalesce(readOptions.from, () => ( 0n))) + readOptions.maxCount : _nullishCoalesce(_optionalChain([events, 'optionalAccess', _146 => _146.length]), () => ( 1)))))
|
|
2125
2226
|
);
|
|
2126
2227
|
const resultEvents = events !== void 0 && events.length > 0 ? upcastRecordedMessages(
|
|
2127
2228
|
events.slice(from, to),
|
|
2128
|
-
_optionalChain([
|
|
2229
|
+
_optionalChain([readOptions, 'optionalAccess', _147 => _147.schema, 'optionalAccess', _148 => _148.versioning])
|
|
2129
2230
|
) : [];
|
|
2130
2231
|
const result = {
|
|
2131
2232
|
currentStreamVersion,
|
|
@@ -2139,7 +2240,7 @@ var getInMemoryEventStore = (eventStoreOptions) => {
|
|
|
2139
2240
|
const currentStreamVersion = currentEvents.length > 0 ? BigInt(currentEvents.length) : InMemoryEventStoreDefaultStreamVersion;
|
|
2140
2241
|
assertExpectedVersionMatchesCurrent(
|
|
2141
2242
|
currentStreamVersion,
|
|
2142
|
-
_optionalChain([options, 'optionalAccess',
|
|
2243
|
+
_optionalChain([options, 'optionalAccess', _149 => _149.expectedStreamVersion]),
|
|
2143
2244
|
InMemoryEventStoreDefaultStreamVersion
|
|
2144
2245
|
);
|
|
2145
2246
|
const newEvents = events.map((event2, index) => {
|
|
@@ -2165,7 +2266,7 @@ var getInMemoryEventStore = (eventStoreOptions) => {
|
|
|
2165
2266
|
);
|
|
2166
2267
|
streams.set(streamName, [
|
|
2167
2268
|
...currentEvents,
|
|
2168
|
-
...downcastRecordedMessages(newEvents, _optionalChain([options, 'optionalAccess',
|
|
2269
|
+
...downcastRecordedMessages(newEvents, _optionalChain([options, 'optionalAccess', _150 => _150.schema, 'optionalAccess', _151 => _151.versioning]))
|
|
2169
2270
|
]);
|
|
2170
2271
|
if (inlineProjections2.length > 0) {
|
|
2171
2272
|
await handleInMemoryProjections({
|
|
@@ -2181,7 +2282,7 @@ var getInMemoryEventStore = (eventStoreOptions) => {
|
|
|
2181
2282
|
};
|
|
2182
2283
|
await tryPublishMessagesAfterCommit(
|
|
2183
2284
|
newEvents,
|
|
2184
|
-
_optionalChain([eventStoreOptions, 'optionalAccess',
|
|
2285
|
+
_optionalChain([eventStoreOptions, 'optionalAccess', _152 => _152.hooks])
|
|
2185
2286
|
);
|
|
2186
2287
|
return result;
|
|
2187
2288
|
},
|
|
@@ -2226,9 +2327,10 @@ var CommandHandler = (options) => async (store, id, handle, handleOptions) => as
|
|
|
2226
2327
|
read: {
|
|
2227
2328
|
schema: options.schema,
|
|
2228
2329
|
...handleOptions,
|
|
2330
|
+
serialization: options.serialization,
|
|
2229
2331
|
// expected stream version is passed to fail fast
|
|
2230
2332
|
// if stream is in the wrong state
|
|
2231
|
-
expectedStreamVersion: _nullishCoalesce(_optionalChain([handleOptions, 'optionalAccess',
|
|
2333
|
+
expectedStreamVersion: _nullishCoalesce(_optionalChain([handleOptions, 'optionalAccess', _153 => _153.expectedStreamVersion]), () => ( NO_CONCURRENCY_CHECK))
|
|
2232
2334
|
}
|
|
2233
2335
|
});
|
|
2234
2336
|
const {
|
|
@@ -2256,7 +2358,7 @@ var CommandHandler = (options) => async (store, id, handle, handleOptions) => as
|
|
|
2256
2358
|
createdNewStream: false
|
|
2257
2359
|
};
|
|
2258
2360
|
}
|
|
2259
|
-
const expectedStreamVersion = _nullishCoalesce(_optionalChain([handleOptions, 'optionalAccess',
|
|
2361
|
+
const expectedStreamVersion = _nullishCoalesce(_optionalChain([handleOptions, 'optionalAccess', _154 => _154.expectedStreamVersion]), () => ( (aggregationResult.streamExists ? currentStreamVersion : STREAM_DOES_NOT_EXIST)));
|
|
2260
2362
|
const appendResult = await eventStore.appendToStream(
|
|
2261
2363
|
streamName,
|
|
2262
2364
|
eventsToAppend,
|
|
@@ -2361,7 +2463,7 @@ var filterProjections = (type, projections2) => {
|
|
|
2361
2463
|
if (duplicateRegistrations.length > 0) {
|
|
2362
2464
|
throw new (0, _chunkWND32L6Pcjs.EmmettError)(`You cannot register multiple projections with the same name (or without the name).
|
|
2363
2465
|
Ensure that:
|
|
2364
|
-
${
|
|
2466
|
+
${JSONSerializer.serialize(duplicateRegistrations)}
|
|
2365
2467
|
have different names`);
|
|
2366
2468
|
}
|
|
2367
2469
|
return inlineProjections2;
|
|
@@ -2432,11 +2534,11 @@ var createWrappedEvolve = (evolve, workflowName, separateInputInboxFromProcessin
|
|
|
2432
2534
|
return (state, event2) => {
|
|
2433
2535
|
const metadata = event2.metadata;
|
|
2434
2536
|
let processedInputIds = state.processedInputIds;
|
|
2435
|
-
if (_optionalChain([metadata, 'optionalAccess',
|
|
2537
|
+
if (_optionalChain([metadata, 'optionalAccess', _155 => _155.input]) === true && typeof _optionalChain([metadata, 'optionalAccess', _156 => _156.originalMessageId]) === "string") {
|
|
2436
2538
|
processedInputIds = new Set(state.processedInputIds);
|
|
2437
2539
|
processedInputIds.add(metadata.originalMessageId);
|
|
2438
2540
|
}
|
|
2439
|
-
if (separateInputInboxFromProcessing && _optionalChain([metadata, 'optionalAccess',
|
|
2541
|
+
if (separateInputInboxFromProcessing && _optionalChain([metadata, 'optionalAccess', _157 => _157.input]) === true) {
|
|
2440
2542
|
return {
|
|
2441
2543
|
userState: state.userState,
|
|
2442
2544
|
processedInputIds
|
|
@@ -2466,7 +2568,7 @@ var WorkflowHandler = (options) => async (store, message2, handleOptions) => asy
|
|
|
2466
2568
|
} = options;
|
|
2467
2569
|
const inputMessageId = (
|
|
2468
2570
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
2469
|
-
_nullishCoalesce(("metadata" in message2 && _optionalChain([message2, 'access',
|
|
2571
|
+
_nullishCoalesce(("metadata" in message2 && _optionalChain([message2, 'access', _158 => _158.metadata, 'optionalAccess', _159 => _159.messageId]) ? (
|
|
2470
2572
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
2471
2573
|
message2.metadata.messageId
|
|
2472
2574
|
) : void 0), () => ( _uuid.v7.call(void 0, )))
|
|
@@ -2502,7 +2604,7 @@ var WorkflowHandler = (options) => async (store, message2, handleOptions) => asy
|
|
|
2502
2604
|
[inputToStore2],
|
|
2503
2605
|
{
|
|
2504
2606
|
...handleOptions,
|
|
2505
|
-
expectedStreamVersion: _nullishCoalesce(_optionalChain([handleOptions, 'optionalAccess',
|
|
2607
|
+
expectedStreamVersion: _nullishCoalesce(_optionalChain([handleOptions, 'optionalAccess', _160 => _160.expectedStreamVersion]), () => ( NO_CONCURRENCY_CHECK))
|
|
2506
2608
|
}
|
|
2507
2609
|
);
|
|
2508
2610
|
return {
|
|
@@ -2523,7 +2625,7 @@ var WorkflowHandler = (options) => async (store, message2, handleOptions) => asy
|
|
|
2523
2625
|
...handleOptions,
|
|
2524
2626
|
// expected stream version is passed to fail fast
|
|
2525
2627
|
// if stream is in the wrong state
|
|
2526
|
-
expectedStreamVersion: _nullishCoalesce(_optionalChain([handleOptions, 'optionalAccess',
|
|
2628
|
+
expectedStreamVersion: _nullishCoalesce(_optionalChain([handleOptions, 'optionalAccess', _161 => _161.expectedStreamVersion]), () => ( NO_CONCURRENCY_CHECK))
|
|
2527
2629
|
}
|
|
2528
2630
|
});
|
|
2529
2631
|
const { currentStreamVersion } = aggregationResult;
|
|
@@ -2547,7 +2649,7 @@ var WorkflowHandler = (options) => async (store, message2, handleOptions) => asy
|
|
|
2547
2649
|
metadata: inputMetadata
|
|
2548
2650
|
};
|
|
2549
2651
|
const outputMessages = (Array.isArray(result2) ? result2 : [result2]).filter((msg) => msg !== void 0 && msg !== null);
|
|
2550
|
-
const outputCommandTypes = _nullishCoalesce(_optionalChain([options, 'access',
|
|
2652
|
+
const outputCommandTypes = _nullishCoalesce(_optionalChain([options, 'access', _162 => _162.outputs, 'optionalAccess', _163 => _163.commands]), () => ( []));
|
|
2551
2653
|
const taggedOutputMessages = outputMessages.map((msg) => {
|
|
2552
2654
|
const action = outputCommandTypes.includes(
|
|
2553
2655
|
msg.type
|
|
@@ -2558,7 +2660,7 @@ var WorkflowHandler = (options) => async (store, message2, handleOptions) => asy
|
|
|
2558
2660
|
if (messagesToAppend.length === 0) {
|
|
2559
2661
|
return emptyHandlerResult(currentStreamVersion);
|
|
2560
2662
|
}
|
|
2561
|
-
const expectedStreamVersion = _nullishCoalesce(_optionalChain([handleOptions, 'optionalAccess',
|
|
2663
|
+
const expectedStreamVersion = _nullishCoalesce(_optionalChain([handleOptions, 'optionalAccess', _164 => _164.expectedStreamVersion]), () => ( (aggregationResult.streamExists ? currentStreamVersion : STREAM_DOES_NOT_EXIST)));
|
|
2562
2664
|
const appendResult = await eventStore.appendToStream(
|
|
2563
2665
|
streamName,
|
|
2564
2666
|
// TODO: Fix this cast
|
|
@@ -2764,5 +2866,12 @@ var workflowProcessor = (options) => {
|
|
|
2764
2866
|
|
|
2765
2867
|
|
|
2766
2868
|
|
|
2767
|
-
|
|
2869
|
+
|
|
2870
|
+
|
|
2871
|
+
|
|
2872
|
+
|
|
2873
|
+
|
|
2874
|
+
|
|
2875
|
+
|
|
2876
|
+
exports.AssertionError = AssertionError; exports.CommandHandler = CommandHandler; exports.CommandHandlerStreamVersionConflictRetryOptions = CommandHandlerStreamVersionConflictRetryOptions; exports.ConcurrencyError = _chunkWND32L6Pcjs.ConcurrencyError; exports.ConcurrencyInMemoryDatabaseError = _chunkWND32L6Pcjs.ConcurrencyInMemoryDatabaseError; exports.DATABASE_REQUIRED_ERROR_MESSAGE = DATABASE_REQUIRED_ERROR_MESSAGE; exports.DeciderCommandHandler = DeciderCommandHandler; exports.DeciderSpecification = DeciderSpecification; exports.EmmettError = _chunkWND32L6Pcjs.EmmettError; exports.ExpectedVersionConflictError = ExpectedVersionConflictError; exports.GlobalStreamCaughtUpType = GlobalStreamCaughtUpType; exports.IllegalStateError = _chunkWND32L6Pcjs.IllegalStateError; exports.InMemoryEventStoreDefaultStreamVersion = InMemoryEventStoreDefaultStreamVersion; exports.InMemoryProjectionSpec = InMemoryProjectionSpec; exports.InProcessLock = InProcessLock; exports.JSONCodec = JSONCodec; exports.JSONReplacer = JSONReplacer; exports.JSONReplacers = JSONReplacers; exports.JSONReviver = JSONReviver; exports.JSONRevivers = JSONRevivers; exports.JSONSerializer = JSONSerializer; exports.MessageProcessor = MessageProcessor; exports.MessageProcessorType = MessageProcessorType; exports.NO_CONCURRENCY_CHECK = NO_CONCURRENCY_CHECK; exports.NoRetries = NoRetries; exports.NotFoundError = _chunkWND32L6Pcjs.NotFoundError; exports.STREAM_DOES_NOT_EXIST = STREAM_DOES_NOT_EXIST; exports.STREAM_EXISTS = STREAM_EXISTS; exports.TaskProcessor = TaskProcessor; exports.ValidationError = _chunkWND32L6Pcjs.ValidationError; exports.ValidationErrors = _chunkWND32L6Pcjs.ValidationErrors; exports.Workflow = Workflow; exports.WorkflowHandler = WorkflowHandler; exports.WorkflowHandlerStreamVersionConflictRetryOptions = WorkflowHandlerStreamVersionConflictRetryOptions; exports.WorkflowSpecification = WorkflowSpecification; exports.WrapEventStore = WrapEventStore; exports.argMatches = argMatches; exports.argValue = argValue; exports.arrayUtils = arrayUtils; exports.assertDeepEqual = assertDeepEqual; exports.assertDefined = assertDefined; exports.assertDoesNotThrow = assertDoesNotThrow; exports.assertEqual = assertEqual; exports.assertExpectedVersionMatchesCurrent = assertExpectedVersionMatchesCurrent; exports.assertFails = assertFails; exports.assertFalse = assertFalse; exports.assertIsNotNull = assertIsNotNull; exports.assertIsNull = assertIsNull; exports.assertMatches = assertMatches; exports.assertNotDeepEqual = assertNotDeepEqual; exports.assertNotEmptyString = _chunkWND32L6Pcjs.assertNotEmptyString; exports.assertNotEqual = assertNotEqual; exports.assertOk = assertOk; exports.assertPositiveNumber = _chunkWND32L6Pcjs.assertPositiveNumber; exports.assertRejects = assertRejects; exports.assertThat = assertThat; exports.assertThatArray = assertThatArray; exports.assertThrows = assertThrows; exports.assertThrowsAsync = assertThrowsAsync; exports.assertTrue = assertTrue; exports.assertUnsignedBigInt = _chunkWND32L6Pcjs.assertUnsignedBigInt; exports.asyncAwaiter = asyncAwaiter; exports.asyncProjections = asyncProjections; exports.asyncRetry = asyncRetry; exports.bigInt = bigInt; exports.bigIntProcessorCheckpoint = bigIntProcessorCheckpoint; exports.canCreateEventStoreSession = canCreateEventStoreSession; exports.caughtUpEventFrom = caughtUpEventFrom; exports.command = command; exports.composeJSONReplacers = composeJSONReplacers; exports.composeJSONRevivers = composeJSONRevivers; exports.deepEquals = deepEquals; exports.defaultProcessingMessageProcessingScope = defaultProcessingMessageProcessingScope; exports.defaultProcessorPartition = defaultProcessorPartition; exports.defaultProcessorVersion = defaultProcessorVersion; exports.defaultTag = defaultTag; exports.delay = delay; exports.documentExists = documentExists; exports.downcastRecordedMessage = downcastRecordedMessage; exports.downcastRecordedMessages = downcastRecordedMessages; exports.emmettPrefix = emmettPrefix; exports.event = event; exports.eventInStream = eventInStream; exports.eventsInStream = eventsInStream; exports.expectInMemoryDocuments = expectInMemoryDocuments; exports.filterProjections = filterProjections; exports.formatDateToUtcYYYYMMDD = _chunkWND32L6Pcjs.formatDateToUtcYYYYMMDD; exports.forwardToMessageBus = forwardToMessageBus; exports.getCheckpoint = getCheckpoint; exports.getInMemoryDatabase = getInMemoryDatabase; exports.getInMemoryEventStore = getInMemoryEventStore; exports.getInMemoryMessageBus = getInMemoryMessageBus; exports.getProcessorInstanceId = getProcessorInstanceId; exports.getProjectorId = getProjectorId; exports.getWorkflowId = getWorkflowId; exports.globalStreamCaughtUp = globalStreamCaughtUp; exports.globalTag = globalTag; exports.guardBoundedAccess = guardBoundedAccess; exports.guardExclusiveAccess = guardExclusiveAccess; exports.guardInitializedOnce = guardInitializedOnce; exports.handleInMemoryProjections = handleInMemoryProjections; exports.hashText = hashText; exports.inMemoryCheckpointer = inMemoryCheckpointer; exports.inMemoryMultiStreamProjection = inMemoryMultiStreamProjection; exports.inMemoryProjection = inMemoryProjection; exports.inMemoryProjector = inMemoryProjector; exports.inMemoryReactor = inMemoryReactor; exports.inMemorySingleStreamProjection = inMemorySingleStreamProjection; exports.inlineProjections = inlineProjections; exports.isBigint = _chunkWND32L6Pcjs.isBigint; exports.isEquatable = isEquatable; exports.isErrorConstructor = _chunkWND32L6Pcjs.isErrorConstructor; exports.isExpectedVersionConflictError = isExpectedVersionConflictError; exports.isGlobalStreamCaughtUp = isGlobalStreamCaughtUp; exports.isNotInternalEvent = isNotInternalEvent; exports.isNumber = _chunkWND32L6Pcjs.isNumber; exports.isPluginConfig = _chunkWND32L6Pcjs.isPluginConfig; exports.isString = _chunkWND32L6Pcjs.isString; exports.isSubscriptionEvent = isSubscriptionEvent; exports.isSubset = isSubset; exports.isValidYYYYMMDD = _chunkWND32L6Pcjs.isValidYYYYMMDD; exports.jsonSerializer = jsonSerializer; exports.matchesExpectedVersion = matchesExpectedVersion; exports.merge = merge; exports.message = message; exports.newEventsInStream = newEventsInStream; exports.nulloSessionFactory = nulloSessionFactory; exports.onShutdown = onShutdown; exports.parseBigIntProcessorCheckpoint = parseBigIntProcessorCheckpoint; exports.parseDateFromUtcYYYYMMDD = _chunkWND32L6Pcjs.parseDateFromUtcYYYYMMDD; exports.projection = projection; exports.projections = projections; exports.projector = projector; exports.reactor = reactor; exports.sum = sum; exports.toNormalizedString = toNormalizedString; exports.tryPublishMessagesAfterCommit = tryPublishMessagesAfterCommit; exports.unknownTag = unknownTag; exports.upcastRecordedMessage = upcastRecordedMessage; exports.upcastRecordedMessages = upcastRecordedMessages; exports.verifyThat = verifyThat; exports.wasMessageHandled = wasMessageHandled; exports.workflowProcessor = workflowProcessor; exports.workflowStreamName = workflowStreamName;
|
|
2768
2877
|
//# sourceMappingURL=index.cjs.map
|