@event-driven-io/emmett-esdb 0.43.0-beta.1 → 0.43.0-beta.11
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 +152 -67
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +118 -33
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
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;
|
|
@@ -54,9 +54,11 @@ var ConcurrencyInMemoryDatabaseError = class _ConcurrencyInMemoryDatabaseError e
|
|
|
54
54
|
// ../emmett/dist/index.js
|
|
55
55
|
var _uuid = require('uuid');
|
|
56
56
|
|
|
57
|
+
|
|
57
58
|
var _asyncretry = require('async-retry'); var _asyncretry2 = _interopRequireDefault(_asyncretry);
|
|
58
59
|
|
|
59
60
|
|
|
61
|
+
|
|
60
62
|
var emmettPrefix = "emt";
|
|
61
63
|
var defaultTag = `${emmettPrefix}:default`;
|
|
62
64
|
var unknownTag = `${emmettPrefix}:unknown`;
|
|
@@ -76,7 +78,7 @@ var assertExpectedVersionMatchesCurrent = (current, expected, defaultVersion) =>
|
|
|
76
78
|
};
|
|
77
79
|
var ExpectedVersionConflictError = class _ExpectedVersionConflictError extends ConcurrencyError {
|
|
78
80
|
constructor(current, expected) {
|
|
79
|
-
super(_optionalChain([current, 'optionalAccess',
|
|
81
|
+
super(_optionalChain([current, 'optionalAccess', _3 => _3.toString, 'call', _4 => _4()]), _optionalChain([expected, 'optionalAccess', _5 => _5.toString, 'call', _6 => _6()]));
|
|
80
82
|
Object.setPrototypeOf(this, _ExpectedVersionConflictError.prototype);
|
|
81
83
|
}
|
|
82
84
|
};
|
|
@@ -285,45 +287,127 @@ var toNormalizedString = (value) => value.toString().padStart(19, "0");
|
|
|
285
287
|
var bigInt = {
|
|
286
288
|
toNormalizedString
|
|
287
289
|
};
|
|
288
|
-
var
|
|
289
|
-
|
|
290
|
-
|
|
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
|
+
}
|
|
291
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;
|
|
292
324
|
};
|
|
293
|
-
var
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
(_, v) => typeof v === "bigint" ? v.toString() : v
|
|
300
|
-
);
|
|
301
|
-
},
|
|
302
|
-
parse: (text, options) => {
|
|
303
|
-
const parsed = JSON.parse(text, _optionalChain([options, 'optionalAccess', _9 => _9.reviver]));
|
|
304
|
-
if (_optionalChain([options, 'optionalAccess', _10 => _10.typeCheck]) && !_optionalChain([options, 'optionalAccess', _11 => _11.typeCheck, 'call', _12 => _12(parsed)]))
|
|
305
|
-
throw new ParseError(text);
|
|
306
|
-
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
|
+
}
|
|
307
331
|
}
|
|
332
|
+
return value;
|
|
308
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
|
+
});
|
|
309
393
|
var asyncRetry = async (fn, opts) => {
|
|
310
394
|
if (opts === void 0 || opts.retries === 0) return fn();
|
|
311
395
|
return _asyncretry2.default.call(void 0,
|
|
312
396
|
async (bail) => {
|
|
313
397
|
try {
|
|
314
398
|
const result = await fn();
|
|
315
|
-
if (_optionalChain([opts, 'optionalAccess',
|
|
399
|
+
if (_optionalChain([opts, 'optionalAccess', _20 => _20.shouldRetryResult]) && opts.shouldRetryResult(result)) {
|
|
316
400
|
throw new EmmettError(
|
|
317
|
-
`Retrying because of result: ${
|
|
401
|
+
`Retrying because of result: ${JSONSerializer.serialize(result)}`
|
|
318
402
|
);
|
|
319
403
|
}
|
|
320
404
|
return result;
|
|
321
|
-
} catch (
|
|
322
|
-
if (_optionalChain([opts, 'optionalAccess',
|
|
323
|
-
bail(
|
|
405
|
+
} catch (error) {
|
|
406
|
+
if (_optionalChain([opts, 'optionalAccess', _21 => _21.shouldRetryError]) && !opts.shouldRetryError(error)) {
|
|
407
|
+
bail(error);
|
|
324
408
|
return void 0;
|
|
325
409
|
}
|
|
326
|
-
throw
|
|
410
|
+
throw error;
|
|
327
411
|
}
|
|
328
412
|
},
|
|
329
413
|
_nullishCoalesce(opts, () => ( { retries: 0 }))
|
|
@@ -370,11 +454,11 @@ var operationResult = (result, options) => {
|
|
|
370
454
|
const { operationName, collectionName } = options;
|
|
371
455
|
if (!successful)
|
|
372
456
|
throw new ConcurrencyInMemoryDatabaseError(
|
|
373
|
-
_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)}!`))
|
|
374
458
|
);
|
|
375
459
|
}
|
|
376
460
|
};
|
|
377
|
-
if (_optionalChain([options, 'access',
|
|
461
|
+
if (_optionalChain([options, 'access', _22 => _22.errors, 'optionalAccess', _23 => _23.throwOnOperationFailures]))
|
|
378
462
|
operationResult2.assertSuccessful();
|
|
379
463
|
return operationResult2;
|
|
380
464
|
};
|
|
@@ -419,14 +503,14 @@ var getInMemoryDatabase = () => {
|
|
|
419
503
|
findOne: (predicate) => {
|
|
420
504
|
ensureCollectionCreated();
|
|
421
505
|
const documentsInCollection = storage.get(collectionName);
|
|
422
|
-
const filteredDocuments = predicate ? _optionalChain([documentsInCollection, 'optionalAccess',
|
|
423
|
-
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));
|
|
424
508
|
return Promise.resolve(firstOne);
|
|
425
509
|
},
|
|
426
510
|
find: (predicate) => {
|
|
427
511
|
ensureCollectionCreated();
|
|
428
512
|
const documentsInCollection = storage.get(collectionName);
|
|
429
|
-
const filteredDocuments = predicate ? _optionalChain([documentsInCollection, 'optionalAccess',
|
|
513
|
+
const filteredDocuments = predicate ? _optionalChain([documentsInCollection, 'optionalAccess', _27 => _27.filter, 'call', _28 => _28((doc) => predicate(doc))]) : documentsInCollection;
|
|
430
514
|
return Promise.resolve(filteredDocuments);
|
|
431
515
|
},
|
|
432
516
|
deleteOne: (predicate) => {
|
|
@@ -498,7 +582,7 @@ var getInMemoryDatabase = () => {
|
|
|
498
582
|
);
|
|
499
583
|
}
|
|
500
584
|
const existing = documentsInCollection[firstIndex];
|
|
501
|
-
if (typeof _optionalChain([options, 'optionalAccess',
|
|
585
|
+
if (typeof _optionalChain([options, 'optionalAccess', _29 => _29.expectedVersion]) === "bigint" && existing._version !== options.expectedVersion) {
|
|
502
586
|
return Promise.resolve(
|
|
503
587
|
operationResult(
|
|
504
588
|
{
|
|
@@ -666,12 +750,13 @@ var reactor = (options) => {
|
|
|
666
750
|
id: processorId,
|
|
667
751
|
instanceId,
|
|
668
752
|
type,
|
|
753
|
+
canHandle,
|
|
669
754
|
init,
|
|
670
755
|
start: async (startOptions) => {
|
|
671
756
|
if (isActive) return;
|
|
672
757
|
await init(startOptions);
|
|
673
758
|
isActive = true;
|
|
674
|
-
closeSignal = onShutdown(() => close(
|
|
759
|
+
closeSignal = onShutdown(() => close(startOptions));
|
|
675
760
|
if (lastCheckpoint !== null)
|
|
676
761
|
return {
|
|
677
762
|
lastCheckpoint
|
|
@@ -682,7 +767,7 @@ var reactor = (options) => {
|
|
|
682
767
|
}
|
|
683
768
|
if (startFrom && startFrom !== "CURRENT") return startFrom;
|
|
684
769
|
if (checkpoints) {
|
|
685
|
-
const readResult = await _optionalChain([checkpoints, 'optionalAccess',
|
|
770
|
+
const readResult = await _optionalChain([checkpoints, 'optionalAccess', _30 => _30.read, 'call', _31 => _31(
|
|
686
771
|
{
|
|
687
772
|
processorId,
|
|
688
773
|
partition
|
|
@@ -710,7 +795,7 @@ var reactor = (options) => {
|
|
|
710
795
|
const upcasted = upcastRecordedMessage(
|
|
711
796
|
// TODO: Make it smarter
|
|
712
797
|
message2,
|
|
713
|
-
_optionalChain([options, 'access',
|
|
798
|
+
_optionalChain([options, 'access', _32 => _32.messageOptions, 'optionalAccess', _33 => _33.schema, 'optionalAccess', _34 => _34.versioning])
|
|
714
799
|
);
|
|
715
800
|
if (canHandle !== void 0 && !canHandle.includes(upcasted.type))
|
|
716
801
|
continue;
|
|
@@ -763,13 +848,13 @@ var projector = (options) => {
|
|
|
763
848
|
processorId,
|
|
764
849
|
messageOptions: options.projection.eventsOptions,
|
|
765
850
|
hooks: {
|
|
766
|
-
onInit: _optionalChain([options, 'access',
|
|
767
|
-
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) => {
|
|
768
853
|
if (options.truncateOnStart && options.projection.truncate)
|
|
769
854
|
await options.projection.truncate(context);
|
|
770
|
-
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)]);
|
|
771
856
|
} : void 0,
|
|
772
|
-
onClose: _optionalChain([options, 'access',
|
|
857
|
+
onClose: _optionalChain([options, 'access', _44 => _44.hooks, 'optionalAccess', _45 => _45.onClose])
|
|
773
858
|
},
|
|
774
859
|
eachMessage: async (event2, context) => projection2.handle([event2], context)
|
|
775
860
|
});
|
|
@@ -779,7 +864,7 @@ var inMemoryCheckpointer = () => {
|
|
|
779
864
|
read: async ({ processorId }, { database }) => {
|
|
780
865
|
const checkpoint = await database.collection("emt_processor_checkpoints").findOne((d) => d._id === processorId);
|
|
781
866
|
return Promise.resolve({
|
|
782
|
-
lastCheckpoint: _nullishCoalesce(_optionalChain([checkpoint, 'optionalAccess',
|
|
867
|
+
lastCheckpoint: _nullishCoalesce(_optionalChain([checkpoint, 'optionalAccess', _46 => _46.lastCheckpoint]), () => ( null))
|
|
783
868
|
});
|
|
784
869
|
},
|
|
785
870
|
store: async (context, { database }) => {
|
|
@@ -790,7 +875,7 @@ var inMemoryCheckpointer = () => {
|
|
|
790
875
|
const checkpoint = await checkpoints.findOne(
|
|
791
876
|
(d) => d._id === processorId
|
|
792
877
|
);
|
|
793
|
-
const currentPosition = _nullishCoalesce(_optionalChain([checkpoint, 'optionalAccess',
|
|
878
|
+
const currentPosition = _nullishCoalesce(_optionalChain([checkpoint, 'optionalAccess', _47 => _47.lastCheckpoint]), () => ( null));
|
|
794
879
|
const newCheckpoint = getCheckpoint(message2);
|
|
795
880
|
if (currentPosition && (currentPosition === newCheckpoint || currentPosition !== lastCheckpoint)) {
|
|
796
881
|
return {
|
|
@@ -810,7 +895,7 @@ var inMemoryCheckpointer = () => {
|
|
|
810
895
|
var inMemoryProcessingScope = (options) => {
|
|
811
896
|
const processorDatabase = options.database;
|
|
812
897
|
const processingScope = (handler, partialContext) => {
|
|
813
|
-
const database = _nullishCoalesce(processorDatabase, () => ( _optionalChain([partialContext, 'optionalAccess',
|
|
898
|
+
const database = _nullishCoalesce(processorDatabase, () => ( _optionalChain([partialContext, 'optionalAccess', _48 => _48.database])));
|
|
814
899
|
if (!database)
|
|
815
900
|
throw new EmmettError(
|
|
816
901
|
`InMemory processor '${options.processorId}' is missing database. Ensure that you passed it through options`
|
|
@@ -820,12 +905,12 @@ var inMemoryProcessingScope = (options) => {
|
|
|
820
905
|
return processingScope;
|
|
821
906
|
};
|
|
822
907
|
var inMemoryProjector = (options) => {
|
|
823
|
-
const database = _nullishCoalesce(_optionalChain([options, 'access',
|
|
908
|
+
const database = _nullishCoalesce(_optionalChain([options, 'access', _49 => _49.connectionOptions, 'optionalAccess', _50 => _50.database]), () => ( getInMemoryDatabase()));
|
|
824
909
|
const hooks = {
|
|
825
|
-
onInit: _optionalChain([options, 'access',
|
|
826
|
-
onStart: _optionalChain([options, 'access',
|
|
827
|
-
onClose: _optionalChain([options, 'access',
|
|
828
|
-
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)]);
|
|
829
914
|
} : void 0
|
|
830
915
|
};
|
|
831
916
|
const processor = projector({
|
|
@@ -840,11 +925,11 @@ var inMemoryProjector = (options) => {
|
|
|
840
925
|
return Object.assign(processor, { database });
|
|
841
926
|
};
|
|
842
927
|
var inMemoryReactor = (options) => {
|
|
843
|
-
const database = _nullishCoalesce(_optionalChain([options, 'access',
|
|
928
|
+
const database = _nullishCoalesce(_optionalChain([options, 'access', _62 => _62.connectionOptions, 'optionalAccess', _63 => _63.database]), () => ( getInMemoryDatabase()));
|
|
844
929
|
const hooks = {
|
|
845
|
-
onInit: _optionalChain([options, 'access',
|
|
846
|
-
onStart: _optionalChain([options, 'access',
|
|
847
|
-
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])
|
|
848
933
|
};
|
|
849
934
|
const processor = reactor({
|
|
850
935
|
...options,
|
|
@@ -858,7 +943,7 @@ var inMemoryReactor = (options) => {
|
|
|
858
943
|
return Object.assign(processor, { database });
|
|
859
944
|
};
|
|
860
945
|
var downcastRecordedMessage = (recordedMessage, options) => {
|
|
861
|
-
if (!_optionalChain([options, 'optionalAccess',
|
|
946
|
+
if (!_optionalChain([options, 'optionalAccess', _70 => _70.downcast]))
|
|
862
947
|
return recordedMessage;
|
|
863
948
|
const downcasted = options.downcast(
|
|
864
949
|
recordedMessage
|
|
@@ -876,14 +961,14 @@ var downcastRecordedMessage = (recordedMessage, options) => {
|
|
|
876
961
|
};
|
|
877
962
|
};
|
|
878
963
|
var downcastRecordedMessages = (recordedMessages, options) => {
|
|
879
|
-
if (!_optionalChain([options, 'optionalAccess',
|
|
964
|
+
if (!_optionalChain([options, 'optionalAccess', _71 => _71.downcast]))
|
|
880
965
|
return recordedMessages;
|
|
881
966
|
return recordedMessages.map(
|
|
882
967
|
(recordedMessage) => downcastRecordedMessage(recordedMessage, options)
|
|
883
968
|
);
|
|
884
969
|
};
|
|
885
970
|
var upcastRecordedMessage = (recordedMessage, options) => {
|
|
886
|
-
if (!_optionalChain([options, 'optionalAccess',
|
|
971
|
+
if (!_optionalChain([options, 'optionalAccess', _72 => _72.upcast]))
|
|
887
972
|
return recordedMessage;
|
|
888
973
|
const upcasted = options.upcast(
|
|
889
974
|
recordedMessage
|
|
@@ -935,7 +1020,7 @@ var getEventStoreDBEventStore = (eventStore) => {
|
|
|
935
1020
|
return {
|
|
936
1021
|
async aggregateStream(streamName, options) {
|
|
937
1022
|
const { evolve, initialState, read } = options;
|
|
938
|
-
const expectedStreamVersion = _optionalChain([read, 'optionalAccess',
|
|
1023
|
+
const expectedStreamVersion = _optionalChain([read, 'optionalAccess', _73 => _73.expectedStreamVersion]);
|
|
939
1024
|
let state = initialState();
|
|
940
1025
|
let currentStreamVersion = EventStoreDBEventStoreDefaultStreamVersion;
|
|
941
1026
|
let lastEventGlobalPosition = void 0;
|
|
@@ -950,11 +1035,11 @@ var getEventStoreDBEventStore = (eventStore) => {
|
|
|
950
1035
|
state,
|
|
951
1036
|
upcastRecordedMessage(
|
|
952
1037
|
mapFromESDBEvent(resolvedEvent),
|
|
953
|
-
_optionalChain([options, 'optionalAccess',
|
|
1038
|
+
_optionalChain([options, 'optionalAccess', _74 => _74.read, 'optionalAccess', _75 => _75.schema, 'optionalAccess', _76 => _76.versioning])
|
|
954
1039
|
)
|
|
955
1040
|
);
|
|
956
1041
|
currentStreamVersion = event.revision;
|
|
957
|
-
lastEventGlobalPosition = _optionalChain([event, 'access',
|
|
1042
|
+
lastEventGlobalPosition = _optionalChain([event, 'access', _77 => _77.position, 'optionalAccess', _78 => _78.commit]);
|
|
958
1043
|
}
|
|
959
1044
|
assertExpectedVersionMatchesCurrent(
|
|
960
1045
|
currentStreamVersion,
|
|
@@ -995,7 +1080,7 @@ var getEventStoreDBEventStore = (eventStore) => {
|
|
|
995
1080
|
events.push(
|
|
996
1081
|
upcastRecordedMessage(
|
|
997
1082
|
mapFromESDBEvent(resolvedEvent),
|
|
998
|
-
_optionalChain([options, 'optionalAccess',
|
|
1083
|
+
_optionalChain([options, 'optionalAccess', _79 => _79.schema, 'optionalAccess', _80 => _80.versioning])
|
|
999
1084
|
)
|
|
1000
1085
|
);
|
|
1001
1086
|
currentStreamVersion = event.revision;
|
|
@@ -1020,11 +1105,11 @@ var getEventStoreDBEventStore = (eventStore) => {
|
|
|
1020
1105
|
try {
|
|
1021
1106
|
const eventsToStore = downcastRecordedMessages(
|
|
1022
1107
|
events,
|
|
1023
|
-
_optionalChain([options, 'optionalAccess',
|
|
1108
|
+
_optionalChain([options, 'optionalAccess', _81 => _81.schema, 'optionalAccess', _82 => _82.versioning])
|
|
1024
1109
|
);
|
|
1025
1110
|
const serializedEvents = eventsToStore.map(_dbclient.jsonEvent);
|
|
1026
1111
|
const expectedRevision = toExpectedRevision(
|
|
1027
|
-
_optionalChain([options, 'optionalAccess',
|
|
1112
|
+
_optionalChain([options, 'optionalAccess', _83 => _83.expectedStreamVersion])
|
|
1028
1113
|
);
|
|
1029
1114
|
const appendResult = await eventStore.appendToStream(
|
|
1030
1115
|
streamName,
|
|
@@ -1071,7 +1156,7 @@ var getEventStoreDBEventStore = (eventStore) => {
|
|
|
1071
1156
|
};
|
|
1072
1157
|
};
|
|
1073
1158
|
var getESDBCheckpoint = (resolvedEvent, from) => {
|
|
1074
|
-
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));
|
|
1075
1160
|
};
|
|
1076
1161
|
var mapFromESDBEvent = (resolvedEvent, from) => {
|
|
1077
1162
|
const event = resolvedEvent.event;
|
|
@@ -1114,7 +1199,7 @@ var toGlobalPosition = (startFrom) => startFrom === "BEGINNING" ? _dbclient.STAR
|
|
|
1114
1199
|
};
|
|
1115
1200
|
var toStreamPosition = (startFrom) => startFrom === "BEGINNING" ? _dbclient.START : startFrom === "END" ? _dbclient.END : parseBigIntProcessorCheckpoint(startFrom.lastCheckpoint);
|
|
1116
1201
|
var subscribe = (client, from, options) => from == void 0 || from.stream == $all ? client.subscribeToAll({
|
|
1117
|
-
..._nullishCoalesce(_optionalChain([from, 'optionalAccess',
|
|
1202
|
+
..._nullishCoalesce(_optionalChain([from, 'optionalAccess', _93 => _93.options]), () => ( {})),
|
|
1118
1203
|
fromPosition: toGlobalPosition(options.startFrom),
|
|
1119
1204
|
filter: _dbclient.excludeSystemEvents.call(void 0, )
|
|
1120
1205
|
}) : client.subscribeToStream(from.stream, {
|
|
@@ -1173,7 +1258,7 @@ var eventStoreDBSubscription = ({
|
|
|
1173
1258
|
let start;
|
|
1174
1259
|
let processor;
|
|
1175
1260
|
let subscription;
|
|
1176
|
-
const resubscribeOptions = _nullishCoalesce(_optionalChain([resilience, 'optionalAccess',
|
|
1261
|
+
const resubscribeOptions = _nullishCoalesce(_optionalChain([resilience, 'optionalAccess', _94 => _94.resubscribeOptions]), () => ( {
|
|
1177
1262
|
...EventStoreDBResubscribeDefaultOptions,
|
|
1178
1263
|
shouldRetryResult: () => isRunning,
|
|
1179
1264
|
shouldRetryError: (error) => isRunning && EventStoreDBResubscribeDefaultOptions.shouldRetryError(error)
|
|
@@ -1195,7 +1280,7 @@ var eventStoreDBSubscription = ({
|
|
|
1195
1280
|
return;
|
|
1196
1281
|
}
|
|
1197
1282
|
console.info(
|
|
1198
|
-
`Starting subscription. ${retry2++} retries. From: ${
|
|
1283
|
+
`Starting subscription. ${retry2++} retries. From: ${JSONSerializer.serialize(_nullishCoalesce(from, () => ( "$all")))}, Start from: ${JSONSerializer.serialize(
|
|
1199
1284
|
options.startFrom
|
|
1200
1285
|
)}`
|
|
1201
1286
|
);
|
|
@@ -1239,7 +1324,7 @@ var eventStoreDBSubscription = ({
|
|
|
1239
1324
|
return;
|
|
1240
1325
|
}
|
|
1241
1326
|
console.error(
|
|
1242
|
-
`Received error: ${
|
|
1327
|
+
`Received error: ${JSONSerializer.serialize(error)}.`
|
|
1243
1328
|
);
|
|
1244
1329
|
reject(error);
|
|
1245
1330
|
});
|
|
@@ -1296,9 +1381,9 @@ var eventStoreDBEventStoreConsumer = (options) => {
|
|
|
1296
1381
|
return await s.handle(messagesBatch, { client });
|
|
1297
1382
|
})
|
|
1298
1383
|
);
|
|
1299
|
-
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]);
|
|
1300
1385
|
return result.some(
|
|
1301
|
-
(r) => r.status === "fulfilled" && _optionalChain([r, 'access',
|
|
1386
|
+
(r) => r.status === "fulfilled" && _optionalChain([r, 'access', _98 => _98.value, 'optionalAccess', _99 => _99.type]) !== "STOP"
|
|
1302
1387
|
) ? void 0 : {
|
|
1303
1388
|
type: "STOP",
|
|
1304
1389
|
error: error ? EmmettError.mapFrom(error) : void 0
|
|
@@ -1308,7 +1393,7 @@ var eventStoreDBEventStoreConsumer = (options) => {
|
|
|
1308
1393
|
client,
|
|
1309
1394
|
from: options.from,
|
|
1310
1395
|
eachBatch,
|
|
1311
|
-
batchSize: _nullishCoalesce(_optionalChain([pulling, 'optionalAccess',
|
|
1396
|
+
batchSize: _nullishCoalesce(_optionalChain([pulling, 'optionalAccess', _100 => _100.batchSize]), () => ( DefaultEventStoreDBEventStoreProcessorBatchSize)),
|
|
1312
1397
|
resilience: options.resilience
|
|
1313
1398
|
});
|
|
1314
1399
|
const stop = async () => {
|