@event-driven-io/emmett-esdb 0.43.0-beta.7 → 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 +145 -63
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +103 -21
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -34,7 +34,7 @@ var ConcurrencyError = class _ConcurrencyError extends EmmettError {
|
|
|
34
34
|
constructor(current, expected, message) {
|
|
35
35
|
super({
|
|
36
36
|
errorCode: EmmettError.Codes.ConcurrencyError,
|
|
37
|
-
message: _nullishCoalesce(message, () => ( `Expected version ${expected.toString()} does not match current ${_optionalChain([current, 'optionalAccess',
|
|
37
|
+
message: _nullishCoalesce(message, () => ( `Expected version ${expected.toString()} does not match current ${_optionalChain([current, 'optionalAccess', _ => _.toString, 'call', _2 => _2()])}`))
|
|
38
38
|
});
|
|
39
39
|
this.current = current;
|
|
40
40
|
this.expected = expected;
|
|
@@ -78,7 +78,7 @@ var assertExpectedVersionMatchesCurrent = (current, expected, defaultVersion) =>
|
|
|
78
78
|
};
|
|
79
79
|
var ExpectedVersionConflictError = class _ExpectedVersionConflictError extends ConcurrencyError {
|
|
80
80
|
constructor(current, expected) {
|
|
81
|
-
super(_optionalChain([current, 'optionalAccess',
|
|
81
|
+
super(_optionalChain([current, 'optionalAccess', _3 => _3.toString, 'call', _4 => _4()]), _optionalChain([expected, 'optionalAccess', _5 => _5.toString, 'call', _6 => _6()]));
|
|
82
82
|
Object.setPrototypeOf(this, _ExpectedVersionConflictError.prototype);
|
|
83
83
|
}
|
|
84
84
|
};
|
|
@@ -287,41 +287,123 @@ var toNormalizedString = (value) => value.toString().padStart(19, "0");
|
|
|
287
287
|
var bigInt = {
|
|
288
288
|
toNormalizedString
|
|
289
289
|
};
|
|
290
|
-
var
|
|
291
|
-
|
|
292
|
-
|
|
290
|
+
var bigIntReplacer = (_key, value) => {
|
|
291
|
+
return typeof value === "bigint" ? value.toString() : value;
|
|
292
|
+
};
|
|
293
|
+
var dateReplacer = (_key, value) => {
|
|
294
|
+
return value instanceof Date ? value.toISOString() : value;
|
|
295
|
+
};
|
|
296
|
+
var isFirstLetterNumeric = (str) => {
|
|
297
|
+
const c = str.charCodeAt(0);
|
|
298
|
+
return c >= 48 && c <= 57;
|
|
299
|
+
};
|
|
300
|
+
var isFirstLetterNumericOrMinus = (str) => {
|
|
301
|
+
const c = str.charCodeAt(0);
|
|
302
|
+
return c >= 48 && c <= 57 || c === 45;
|
|
303
|
+
};
|
|
304
|
+
var bigIntReviver = (_key, value, context) => {
|
|
305
|
+
if (typeof value === "number" && Number.isInteger(value) && !Number.isSafeInteger(value)) {
|
|
306
|
+
try {
|
|
307
|
+
return BigInt(_nullishCoalesce(_optionalChain([context, 'optionalAccess', _7 => _7.source]), () => ( value.toString())));
|
|
308
|
+
} catch (e) {
|
|
309
|
+
return value;
|
|
310
|
+
}
|
|
293
311
|
}
|
|
312
|
+
if (typeof value === "string" && value.length > 15) {
|
|
313
|
+
if (isFirstLetterNumericOrMinus(value)) {
|
|
314
|
+
const num = Number(value);
|
|
315
|
+
if (Number.isFinite(num) && !Number.isSafeInteger(num)) {
|
|
316
|
+
try {
|
|
317
|
+
return BigInt(value);
|
|
318
|
+
} catch (e2) {
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
return value;
|
|
294
324
|
};
|
|
295
|
-
var
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
(_, v) => typeof v === "bigint" ? v.toString() : v
|
|
302
|
-
);
|
|
303
|
-
},
|
|
304
|
-
parse: (text, options) => {
|
|
305
|
-
const parsed = JSON.parse(text, _optionalChain([options, 'optionalAccess', _9 => _9.reviver]));
|
|
306
|
-
if (_optionalChain([options, 'optionalAccess', _10 => _10.typeCheck]) && !_optionalChain([options, 'optionalAccess', _11 => _11.typeCheck, 'call', _12 => _12(parsed)]))
|
|
307
|
-
throw new ParseError(text);
|
|
308
|
-
return _optionalChain([options, 'optionalAccess', _13 => _13.map]) ? options.map(parsed) : parsed;
|
|
325
|
+
var dateReviver = (_key, value) => {
|
|
326
|
+
if (typeof value === "string" && value.length === 24 && isFirstLetterNumeric(value) && value[10] === "T" && value[23] === "Z") {
|
|
327
|
+
const date = new Date(value);
|
|
328
|
+
if (!isNaN(date.getTime())) {
|
|
329
|
+
return date;
|
|
330
|
+
}
|
|
309
331
|
}
|
|
332
|
+
return value;
|
|
310
333
|
};
|
|
334
|
+
var composeJSONReplacers = (...replacers) => {
|
|
335
|
+
const filteredReplacers = replacers.filter((r) => r !== void 0);
|
|
336
|
+
if (filteredReplacers.length === 0) return void 0;
|
|
337
|
+
return (key, value) => (
|
|
338
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
339
|
+
filteredReplacers.reduce(
|
|
340
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
341
|
+
(accValue, replacer) => replacer(key, accValue),
|
|
342
|
+
value
|
|
343
|
+
)
|
|
344
|
+
);
|
|
345
|
+
};
|
|
346
|
+
var composeJSONRevivers = (...revivers) => {
|
|
347
|
+
const filteredRevivers = revivers.filter((r) => r !== void 0);
|
|
348
|
+
if (filteredRevivers.length === 0) return void 0;
|
|
349
|
+
return (key, value, context) => (
|
|
350
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
351
|
+
filteredRevivers.reduce(
|
|
352
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
353
|
+
(accValue, reviver) => reviver(key, accValue, context),
|
|
354
|
+
value
|
|
355
|
+
)
|
|
356
|
+
);
|
|
357
|
+
};
|
|
358
|
+
var JSONReplacer = (opts) => composeJSONReplacers(
|
|
359
|
+
_optionalChain([opts, 'optionalAccess', _8 => _8.replacer]),
|
|
360
|
+
_optionalChain([opts, 'optionalAccess', _9 => _9.failOnBigIntSerialization]) !== true ? JSONReplacers.bigInt : void 0,
|
|
361
|
+
_optionalChain([opts, 'optionalAccess', _10 => _10.useDefaultDateSerialization]) !== true ? JSONReplacers.date : void 0
|
|
362
|
+
);
|
|
363
|
+
var JSONReviver = (opts) => composeJSONRevivers(
|
|
364
|
+
_optionalChain([opts, 'optionalAccess', _11 => _11.reviver]),
|
|
365
|
+
_optionalChain([opts, 'optionalAccess', _12 => _12.parseBigInts]) === true ? JSONRevivers.bigInt : void 0,
|
|
366
|
+
_optionalChain([opts, 'optionalAccess', _13 => _13.parseDates]) === true ? JSONRevivers.date : void 0
|
|
367
|
+
);
|
|
368
|
+
var JSONReplacers = {
|
|
369
|
+
bigInt: bigIntReplacer,
|
|
370
|
+
date: dateReplacer
|
|
371
|
+
};
|
|
372
|
+
var JSONRevivers = {
|
|
373
|
+
bigInt: bigIntReviver,
|
|
374
|
+
date: dateReviver
|
|
375
|
+
};
|
|
376
|
+
var jsonSerializer = (options) => {
|
|
377
|
+
const defaultReplacer = JSONReplacer(options);
|
|
378
|
+
const defaultReviver = JSONReviver(options);
|
|
379
|
+
return {
|
|
380
|
+
serialize: (object, serializerOptions) => JSON.stringify(
|
|
381
|
+
object,
|
|
382
|
+
serializerOptions ? JSONReplacer(serializerOptions) : defaultReplacer
|
|
383
|
+
),
|
|
384
|
+
deserialize: (payload, deserializerOptions) => JSON.parse(
|
|
385
|
+
payload,
|
|
386
|
+
deserializerOptions ? JSONReviver(deserializerOptions) : defaultReviver
|
|
387
|
+
)
|
|
388
|
+
};
|
|
389
|
+
};
|
|
390
|
+
var JSONSerializer = Object.assign(jsonSerializer(), {
|
|
391
|
+
from: (options) => _nullishCoalesce(_optionalChain([options, 'optionalAccess', _14 => _14.serialization, 'optionalAccess', _15 => _15.serializer]), () => ( (_optionalChain([options, 'optionalAccess', _16 => _16.serialization, 'optionalAccess', _17 => _17.options]) ? jsonSerializer(_optionalChain([options, 'optionalAccess', _18 => _18.serialization, 'optionalAccess', _19 => _19.options])) : JSONSerializer)))
|
|
392
|
+
});
|
|
311
393
|
var asyncRetry = async (fn, opts) => {
|
|
312
394
|
if (opts === void 0 || opts.retries === 0) return fn();
|
|
313
395
|
return _asyncretry2.default.call(void 0,
|
|
314
396
|
async (bail) => {
|
|
315
397
|
try {
|
|
316
398
|
const result = await fn();
|
|
317
|
-
if (_optionalChain([opts, 'optionalAccess',
|
|
399
|
+
if (_optionalChain([opts, 'optionalAccess', _20 => _20.shouldRetryResult]) && opts.shouldRetryResult(result)) {
|
|
318
400
|
throw new EmmettError(
|
|
319
|
-
`Retrying because of result: ${
|
|
401
|
+
`Retrying because of result: ${JSONSerializer.serialize(result)}`
|
|
320
402
|
);
|
|
321
403
|
}
|
|
322
404
|
return result;
|
|
323
405
|
} catch (error) {
|
|
324
|
-
if (_optionalChain([opts, 'optionalAccess',
|
|
406
|
+
if (_optionalChain([opts, 'optionalAccess', _21 => _21.shouldRetryError]) && !opts.shouldRetryError(error)) {
|
|
325
407
|
bail(error);
|
|
326
408
|
return void 0;
|
|
327
409
|
}
|
|
@@ -372,11 +454,11 @@ var operationResult = (result, options) => {
|
|
|
372
454
|
const { operationName, collectionName } = options;
|
|
373
455
|
if (!successful)
|
|
374
456
|
throw new ConcurrencyInMemoryDatabaseError(
|
|
375
|
-
_nullishCoalesce(errorMessage, () => ( `${operationName} on ${collectionName} failed. Expected document state does not match current one! Result: ${
|
|
457
|
+
_nullishCoalesce(errorMessage, () => ( `${operationName} on ${collectionName} failed. Expected document state does not match current one! Result: ${JSONSerializer.serialize(result)}!`))
|
|
376
458
|
);
|
|
377
459
|
}
|
|
378
460
|
};
|
|
379
|
-
if (_optionalChain([options, 'access',
|
|
461
|
+
if (_optionalChain([options, 'access', _22 => _22.errors, 'optionalAccess', _23 => _23.throwOnOperationFailures]))
|
|
380
462
|
operationResult2.assertSuccessful();
|
|
381
463
|
return operationResult2;
|
|
382
464
|
};
|
|
@@ -421,14 +503,14 @@ var getInMemoryDatabase = () => {
|
|
|
421
503
|
findOne: (predicate) => {
|
|
422
504
|
ensureCollectionCreated();
|
|
423
505
|
const documentsInCollection = storage.get(collectionName);
|
|
424
|
-
const filteredDocuments = predicate ? _optionalChain([documentsInCollection, 'optionalAccess',
|
|
425
|
-
const firstOne = _nullishCoalesce(_optionalChain([filteredDocuments, 'optionalAccess',
|
|
506
|
+
const filteredDocuments = predicate ? _optionalChain([documentsInCollection, 'optionalAccess', _24 => _24.filter, 'call', _25 => _25((doc) => predicate(doc))]) : documentsInCollection;
|
|
507
|
+
const firstOne = _nullishCoalesce(_optionalChain([filteredDocuments, 'optionalAccess', _26 => _26[0]]), () => ( null));
|
|
426
508
|
return Promise.resolve(firstOne);
|
|
427
509
|
},
|
|
428
510
|
find: (predicate) => {
|
|
429
511
|
ensureCollectionCreated();
|
|
430
512
|
const documentsInCollection = storage.get(collectionName);
|
|
431
|
-
const filteredDocuments = predicate ? _optionalChain([documentsInCollection, 'optionalAccess',
|
|
513
|
+
const filteredDocuments = predicate ? _optionalChain([documentsInCollection, 'optionalAccess', _27 => _27.filter, 'call', _28 => _28((doc) => predicate(doc))]) : documentsInCollection;
|
|
432
514
|
return Promise.resolve(filteredDocuments);
|
|
433
515
|
},
|
|
434
516
|
deleteOne: (predicate) => {
|
|
@@ -500,7 +582,7 @@ var getInMemoryDatabase = () => {
|
|
|
500
582
|
);
|
|
501
583
|
}
|
|
502
584
|
const existing = documentsInCollection[firstIndex];
|
|
503
|
-
if (typeof _optionalChain([options, 'optionalAccess',
|
|
585
|
+
if (typeof _optionalChain([options, 'optionalAccess', _29 => _29.expectedVersion]) === "bigint" && existing._version !== options.expectedVersion) {
|
|
504
586
|
return Promise.resolve(
|
|
505
587
|
operationResult(
|
|
506
588
|
{
|
|
@@ -685,7 +767,7 @@ var reactor = (options) => {
|
|
|
685
767
|
}
|
|
686
768
|
if (startFrom && startFrom !== "CURRENT") return startFrom;
|
|
687
769
|
if (checkpoints) {
|
|
688
|
-
const readResult = await _optionalChain([checkpoints, 'optionalAccess',
|
|
770
|
+
const readResult = await _optionalChain([checkpoints, 'optionalAccess', _30 => _30.read, 'call', _31 => _31(
|
|
689
771
|
{
|
|
690
772
|
processorId,
|
|
691
773
|
partition
|
|
@@ -713,7 +795,7 @@ var reactor = (options) => {
|
|
|
713
795
|
const upcasted = upcastRecordedMessage(
|
|
714
796
|
// TODO: Make it smarter
|
|
715
797
|
message2,
|
|
716
|
-
_optionalChain([options, 'access',
|
|
798
|
+
_optionalChain([options, 'access', _32 => _32.messageOptions, 'optionalAccess', _33 => _33.schema, 'optionalAccess', _34 => _34.versioning])
|
|
717
799
|
);
|
|
718
800
|
if (canHandle !== void 0 && !canHandle.includes(upcasted.type))
|
|
719
801
|
continue;
|
|
@@ -766,13 +848,13 @@ var projector = (options) => {
|
|
|
766
848
|
processorId,
|
|
767
849
|
messageOptions: options.projection.eventsOptions,
|
|
768
850
|
hooks: {
|
|
769
|
-
onInit: _optionalChain([options, 'access',
|
|
770
|
-
onStart: options.truncateOnStart && options.projection.truncate || _optionalChain([options, 'access',
|
|
851
|
+
onInit: _optionalChain([options, 'access', _35 => _35.hooks, 'optionalAccess', _36 => _36.onInit]),
|
|
852
|
+
onStart: options.truncateOnStart && options.projection.truncate || _optionalChain([options, 'access', _37 => _37.hooks, 'optionalAccess', _38 => _38.onStart]) ? async (context) => {
|
|
771
853
|
if (options.truncateOnStart && options.projection.truncate)
|
|
772
854
|
await options.projection.truncate(context);
|
|
773
|
-
if (_optionalChain([options, 'access',
|
|
855
|
+
if (_optionalChain([options, 'access', _39 => _39.hooks, 'optionalAccess', _40 => _40.onStart])) await _optionalChain([options, 'access', _41 => _41.hooks, 'optionalAccess', _42 => _42.onStart, 'call', _43 => _43(context)]);
|
|
774
856
|
} : void 0,
|
|
775
|
-
onClose: _optionalChain([options, 'access',
|
|
857
|
+
onClose: _optionalChain([options, 'access', _44 => _44.hooks, 'optionalAccess', _45 => _45.onClose])
|
|
776
858
|
},
|
|
777
859
|
eachMessage: async (event2, context) => projection2.handle([event2], context)
|
|
778
860
|
});
|
|
@@ -782,7 +864,7 @@ var inMemoryCheckpointer = () => {
|
|
|
782
864
|
read: async ({ processorId }, { database }) => {
|
|
783
865
|
const checkpoint = await database.collection("emt_processor_checkpoints").findOne((d) => d._id === processorId);
|
|
784
866
|
return Promise.resolve({
|
|
785
|
-
lastCheckpoint: _nullishCoalesce(_optionalChain([checkpoint, 'optionalAccess',
|
|
867
|
+
lastCheckpoint: _nullishCoalesce(_optionalChain([checkpoint, 'optionalAccess', _46 => _46.lastCheckpoint]), () => ( null))
|
|
786
868
|
});
|
|
787
869
|
},
|
|
788
870
|
store: async (context, { database }) => {
|
|
@@ -793,7 +875,7 @@ var inMemoryCheckpointer = () => {
|
|
|
793
875
|
const checkpoint = await checkpoints.findOne(
|
|
794
876
|
(d) => d._id === processorId
|
|
795
877
|
);
|
|
796
|
-
const currentPosition = _nullishCoalesce(_optionalChain([checkpoint, 'optionalAccess',
|
|
878
|
+
const currentPosition = _nullishCoalesce(_optionalChain([checkpoint, 'optionalAccess', _47 => _47.lastCheckpoint]), () => ( null));
|
|
797
879
|
const newCheckpoint = getCheckpoint(message2);
|
|
798
880
|
if (currentPosition && (currentPosition === newCheckpoint || currentPosition !== lastCheckpoint)) {
|
|
799
881
|
return {
|
|
@@ -813,7 +895,7 @@ var inMemoryCheckpointer = () => {
|
|
|
813
895
|
var inMemoryProcessingScope = (options) => {
|
|
814
896
|
const processorDatabase = options.database;
|
|
815
897
|
const processingScope = (handler, partialContext) => {
|
|
816
|
-
const database = _nullishCoalesce(processorDatabase, () => ( _optionalChain([partialContext, 'optionalAccess',
|
|
898
|
+
const database = _nullishCoalesce(processorDatabase, () => ( _optionalChain([partialContext, 'optionalAccess', _48 => _48.database])));
|
|
817
899
|
if (!database)
|
|
818
900
|
throw new EmmettError(
|
|
819
901
|
`InMemory processor '${options.processorId}' is missing database. Ensure that you passed it through options`
|
|
@@ -823,12 +905,12 @@ var inMemoryProcessingScope = (options) => {
|
|
|
823
905
|
return processingScope;
|
|
824
906
|
};
|
|
825
907
|
var inMemoryProjector = (options) => {
|
|
826
|
-
const database = _nullishCoalesce(_optionalChain([options, 'access',
|
|
908
|
+
const database = _nullishCoalesce(_optionalChain([options, 'access', _49 => _49.connectionOptions, 'optionalAccess', _50 => _50.database]), () => ( getInMemoryDatabase()));
|
|
827
909
|
const hooks = {
|
|
828
|
-
onInit: _optionalChain([options, 'access',
|
|
829
|
-
onStart: _optionalChain([options, 'access',
|
|
830
|
-
onClose: _optionalChain([options, 'access',
|
|
831
|
-
if (_optionalChain([options, 'access',
|
|
910
|
+
onInit: _optionalChain([options, 'access', _51 => _51.hooks, 'optionalAccess', _52 => _52.onInit]),
|
|
911
|
+
onStart: _optionalChain([options, 'access', _53 => _53.hooks, 'optionalAccess', _54 => _54.onStart]),
|
|
912
|
+
onClose: _optionalChain([options, 'access', _55 => _55.hooks, 'optionalAccess', _56 => _56.onClose]) ? async (context) => {
|
|
913
|
+
if (_optionalChain([options, 'access', _57 => _57.hooks, 'optionalAccess', _58 => _58.onClose])) await _optionalChain([options, 'access', _59 => _59.hooks, 'optionalAccess', _60 => _60.onClose, 'call', _61 => _61(context)]);
|
|
832
914
|
} : void 0
|
|
833
915
|
};
|
|
834
916
|
const processor = projector({
|
|
@@ -843,11 +925,11 @@ var inMemoryProjector = (options) => {
|
|
|
843
925
|
return Object.assign(processor, { database });
|
|
844
926
|
};
|
|
845
927
|
var inMemoryReactor = (options) => {
|
|
846
|
-
const database = _nullishCoalesce(_optionalChain([options, 'access',
|
|
928
|
+
const database = _nullishCoalesce(_optionalChain([options, 'access', _62 => _62.connectionOptions, 'optionalAccess', _63 => _63.database]), () => ( getInMemoryDatabase()));
|
|
847
929
|
const hooks = {
|
|
848
|
-
onInit: _optionalChain([options, 'access',
|
|
849
|
-
onStart: _optionalChain([options, 'access',
|
|
850
|
-
onClose: _optionalChain([options, 'access',
|
|
930
|
+
onInit: _optionalChain([options, 'access', _64 => _64.hooks, 'optionalAccess', _65 => _65.onInit]),
|
|
931
|
+
onStart: _optionalChain([options, 'access', _66 => _66.hooks, 'optionalAccess', _67 => _67.onStart]),
|
|
932
|
+
onClose: _optionalChain([options, 'access', _68 => _68.hooks, 'optionalAccess', _69 => _69.onClose])
|
|
851
933
|
};
|
|
852
934
|
const processor = reactor({
|
|
853
935
|
...options,
|
|
@@ -861,7 +943,7 @@ var inMemoryReactor = (options) => {
|
|
|
861
943
|
return Object.assign(processor, { database });
|
|
862
944
|
};
|
|
863
945
|
var downcastRecordedMessage = (recordedMessage, options) => {
|
|
864
|
-
if (!_optionalChain([options, 'optionalAccess',
|
|
946
|
+
if (!_optionalChain([options, 'optionalAccess', _70 => _70.downcast]))
|
|
865
947
|
return recordedMessage;
|
|
866
948
|
const downcasted = options.downcast(
|
|
867
949
|
recordedMessage
|
|
@@ -879,14 +961,14 @@ var downcastRecordedMessage = (recordedMessage, options) => {
|
|
|
879
961
|
};
|
|
880
962
|
};
|
|
881
963
|
var downcastRecordedMessages = (recordedMessages, options) => {
|
|
882
|
-
if (!_optionalChain([options, 'optionalAccess',
|
|
964
|
+
if (!_optionalChain([options, 'optionalAccess', _71 => _71.downcast]))
|
|
883
965
|
return recordedMessages;
|
|
884
966
|
return recordedMessages.map(
|
|
885
967
|
(recordedMessage) => downcastRecordedMessage(recordedMessage, options)
|
|
886
968
|
);
|
|
887
969
|
};
|
|
888
970
|
var upcastRecordedMessage = (recordedMessage, options) => {
|
|
889
|
-
if (!_optionalChain([options, 'optionalAccess',
|
|
971
|
+
if (!_optionalChain([options, 'optionalAccess', _72 => _72.upcast]))
|
|
890
972
|
return recordedMessage;
|
|
891
973
|
const upcasted = options.upcast(
|
|
892
974
|
recordedMessage
|
|
@@ -938,7 +1020,7 @@ var getEventStoreDBEventStore = (eventStore) => {
|
|
|
938
1020
|
return {
|
|
939
1021
|
async aggregateStream(streamName, options) {
|
|
940
1022
|
const { evolve, initialState, read } = options;
|
|
941
|
-
const expectedStreamVersion = _optionalChain([read, 'optionalAccess',
|
|
1023
|
+
const expectedStreamVersion = _optionalChain([read, 'optionalAccess', _73 => _73.expectedStreamVersion]);
|
|
942
1024
|
let state = initialState();
|
|
943
1025
|
let currentStreamVersion = EventStoreDBEventStoreDefaultStreamVersion;
|
|
944
1026
|
let lastEventGlobalPosition = void 0;
|
|
@@ -953,11 +1035,11 @@ var getEventStoreDBEventStore = (eventStore) => {
|
|
|
953
1035
|
state,
|
|
954
1036
|
upcastRecordedMessage(
|
|
955
1037
|
mapFromESDBEvent(resolvedEvent),
|
|
956
|
-
_optionalChain([options, 'optionalAccess',
|
|
1038
|
+
_optionalChain([options, 'optionalAccess', _74 => _74.read, 'optionalAccess', _75 => _75.schema, 'optionalAccess', _76 => _76.versioning])
|
|
957
1039
|
)
|
|
958
1040
|
);
|
|
959
1041
|
currentStreamVersion = event.revision;
|
|
960
|
-
lastEventGlobalPosition = _optionalChain([event, 'access',
|
|
1042
|
+
lastEventGlobalPosition = _optionalChain([event, 'access', _77 => _77.position, 'optionalAccess', _78 => _78.commit]);
|
|
961
1043
|
}
|
|
962
1044
|
assertExpectedVersionMatchesCurrent(
|
|
963
1045
|
currentStreamVersion,
|
|
@@ -998,7 +1080,7 @@ var getEventStoreDBEventStore = (eventStore) => {
|
|
|
998
1080
|
events.push(
|
|
999
1081
|
upcastRecordedMessage(
|
|
1000
1082
|
mapFromESDBEvent(resolvedEvent),
|
|
1001
|
-
_optionalChain([options, 'optionalAccess',
|
|
1083
|
+
_optionalChain([options, 'optionalAccess', _79 => _79.schema, 'optionalAccess', _80 => _80.versioning])
|
|
1002
1084
|
)
|
|
1003
1085
|
);
|
|
1004
1086
|
currentStreamVersion = event.revision;
|
|
@@ -1023,11 +1105,11 @@ var getEventStoreDBEventStore = (eventStore) => {
|
|
|
1023
1105
|
try {
|
|
1024
1106
|
const eventsToStore = downcastRecordedMessages(
|
|
1025
1107
|
events,
|
|
1026
|
-
_optionalChain([options, 'optionalAccess',
|
|
1108
|
+
_optionalChain([options, 'optionalAccess', _81 => _81.schema, 'optionalAccess', _82 => _82.versioning])
|
|
1027
1109
|
);
|
|
1028
1110
|
const serializedEvents = eventsToStore.map(_dbclient.jsonEvent);
|
|
1029
1111
|
const expectedRevision = toExpectedRevision(
|
|
1030
|
-
_optionalChain([options, 'optionalAccess',
|
|
1112
|
+
_optionalChain([options, 'optionalAccess', _83 => _83.expectedStreamVersion])
|
|
1031
1113
|
);
|
|
1032
1114
|
const appendResult = await eventStore.appendToStream(
|
|
1033
1115
|
streamName,
|
|
@@ -1074,7 +1156,7 @@ var getEventStoreDBEventStore = (eventStore) => {
|
|
|
1074
1156
|
};
|
|
1075
1157
|
};
|
|
1076
1158
|
var getESDBCheckpoint = (resolvedEvent, from) => {
|
|
1077
|
-
return !from || _optionalChain([from, 'optionalAccess',
|
|
1159
|
+
return !from || _optionalChain([from, 'optionalAccess', _84 => _84.stream]) === $all ? _nullishCoalesce(_optionalChain([resolvedEvent, 'access', _85 => _85.link, 'optionalAccess', _86 => _86.position, 'optionalAccess', _87 => _87.commit]), () => ( _optionalChain([resolvedEvent, 'access', _88 => _88.event, 'optionalAccess', _89 => _89.position, 'optionalAccess', _90 => _90.commit]))) : _nullishCoalesce(_optionalChain([resolvedEvent, 'access', _91 => _91.link, 'optionalAccess', _92 => _92.revision]), () => ( resolvedEvent.event.revision));
|
|
1078
1160
|
};
|
|
1079
1161
|
var mapFromESDBEvent = (resolvedEvent, from) => {
|
|
1080
1162
|
const event = resolvedEvent.event;
|
|
@@ -1117,7 +1199,7 @@ var toGlobalPosition = (startFrom) => startFrom === "BEGINNING" ? _dbclient.STAR
|
|
|
1117
1199
|
};
|
|
1118
1200
|
var toStreamPosition = (startFrom) => startFrom === "BEGINNING" ? _dbclient.START : startFrom === "END" ? _dbclient.END : parseBigIntProcessorCheckpoint(startFrom.lastCheckpoint);
|
|
1119
1201
|
var subscribe = (client, from, options) => from == void 0 || from.stream == $all ? client.subscribeToAll({
|
|
1120
|
-
..._nullishCoalesce(_optionalChain([from, 'optionalAccess',
|
|
1202
|
+
..._nullishCoalesce(_optionalChain([from, 'optionalAccess', _93 => _93.options]), () => ( {})),
|
|
1121
1203
|
fromPosition: toGlobalPosition(options.startFrom),
|
|
1122
1204
|
filter: _dbclient.excludeSystemEvents.call(void 0, )
|
|
1123
1205
|
}) : client.subscribeToStream(from.stream, {
|
|
@@ -1176,7 +1258,7 @@ var eventStoreDBSubscription = ({
|
|
|
1176
1258
|
let start;
|
|
1177
1259
|
let processor;
|
|
1178
1260
|
let subscription;
|
|
1179
|
-
const resubscribeOptions = _nullishCoalesce(_optionalChain([resilience, 'optionalAccess',
|
|
1261
|
+
const resubscribeOptions = _nullishCoalesce(_optionalChain([resilience, 'optionalAccess', _94 => _94.resubscribeOptions]), () => ( {
|
|
1180
1262
|
...EventStoreDBResubscribeDefaultOptions,
|
|
1181
1263
|
shouldRetryResult: () => isRunning,
|
|
1182
1264
|
shouldRetryError: (error) => isRunning && EventStoreDBResubscribeDefaultOptions.shouldRetryError(error)
|
|
@@ -1198,7 +1280,7 @@ var eventStoreDBSubscription = ({
|
|
|
1198
1280
|
return;
|
|
1199
1281
|
}
|
|
1200
1282
|
console.info(
|
|
1201
|
-
`Starting subscription. ${retry2++} retries. From: ${
|
|
1283
|
+
`Starting subscription. ${retry2++} retries. From: ${JSONSerializer.serialize(_nullishCoalesce(from, () => ( "$all")))}, Start from: ${JSONSerializer.serialize(
|
|
1202
1284
|
options.startFrom
|
|
1203
1285
|
)}`
|
|
1204
1286
|
);
|
|
@@ -1242,7 +1324,7 @@ var eventStoreDBSubscription = ({
|
|
|
1242
1324
|
return;
|
|
1243
1325
|
}
|
|
1244
1326
|
console.error(
|
|
1245
|
-
`Received error: ${
|
|
1327
|
+
`Received error: ${JSONSerializer.serialize(error)}.`
|
|
1246
1328
|
);
|
|
1247
1329
|
reject(error);
|
|
1248
1330
|
});
|
|
@@ -1299,9 +1381,9 @@ var eventStoreDBEventStoreConsumer = (options) => {
|
|
|
1299
1381
|
return await s.handle(messagesBatch, { client });
|
|
1300
1382
|
})
|
|
1301
1383
|
);
|
|
1302
|
-
const error = _optionalChain([result, 'access',
|
|
1384
|
+
const error = _optionalChain([result, 'access', _95 => _95.find, 'call', _96 => _96((r) => r.status === "rejected"), 'optionalAccess', _97 => _97.reason]);
|
|
1303
1385
|
return result.some(
|
|
1304
|
-
(r) => r.status === "fulfilled" && _optionalChain([r, 'access',
|
|
1386
|
+
(r) => r.status === "fulfilled" && _optionalChain([r, 'access', _98 => _98.value, 'optionalAccess', _99 => _99.type]) !== "STOP"
|
|
1305
1387
|
) ? void 0 : {
|
|
1306
1388
|
type: "STOP",
|
|
1307
1389
|
error: error ? EmmettError.mapFrom(error) : void 0
|
|
@@ -1311,7 +1393,7 @@ var eventStoreDBEventStoreConsumer = (options) => {
|
|
|
1311
1393
|
client,
|
|
1312
1394
|
from: options.from,
|
|
1313
1395
|
eachBatch,
|
|
1314
|
-
batchSize: _nullishCoalesce(_optionalChain([pulling, 'optionalAccess',
|
|
1396
|
+
batchSize: _nullishCoalesce(_optionalChain([pulling, 'optionalAccess', _100 => _100.batchSize]), () => ( DefaultEventStoreDBEventStoreProcessorBatchSize)),
|
|
1315
1397
|
resilience: options.resilience
|
|
1316
1398
|
});
|
|
1317
1399
|
const stop = async () => {
|