@event-driven-io/emmett-postgresql 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 +216 -123
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -10
- package/dist/index.d.ts +10 -10
- package/dist/index.js +137 -44
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -39,7 +39,7 @@ var ConcurrencyError = class _ConcurrencyError extends EmmettError {
|
|
|
39
39
|
constructor(current, expected, message) {
|
|
40
40
|
super({
|
|
41
41
|
errorCode: EmmettError.Codes.ConcurrencyError,
|
|
42
|
-
message: _nullishCoalesce(message, () => ( `Expected version ${expected.toString()} does not match current ${_optionalChain([current, 'optionalAccess',
|
|
42
|
+
message: _nullishCoalesce(message, () => ( `Expected version ${expected.toString()} does not match current ${_optionalChain([current, 'optionalAccess', _ => _.toString, 'call', _2 => _2()])}`))
|
|
43
43
|
});
|
|
44
44
|
this.current = current;
|
|
45
45
|
this.expected = expected;
|
|
@@ -84,7 +84,7 @@ var assertExpectedVersionMatchesCurrent = (current, expected, defaultVersion) =>
|
|
|
84
84
|
};
|
|
85
85
|
var ExpectedVersionConflictError = class _ExpectedVersionConflictError extends ConcurrencyError {
|
|
86
86
|
constructor(current, expected) {
|
|
87
|
-
super(_optionalChain([current, 'optionalAccess',
|
|
87
|
+
super(_optionalChain([current, 'optionalAccess', _3 => _3.toString, 'call', _4 => _4()]), _optionalChain([expected, 'optionalAccess', _5 => _5.toString, 'call', _6 => _6()]));
|
|
88
88
|
Object.setPrototypeOf(this, _ExpectedVersionConflictError.prototype);
|
|
89
89
|
}
|
|
90
90
|
};
|
|
@@ -297,27 +297,109 @@ var toNormalizedString = (value) => value.toString().padStart(19, "0");
|
|
|
297
297
|
var bigInt = {
|
|
298
298
|
toNormalizedString
|
|
299
299
|
};
|
|
300
|
-
var
|
|
301
|
-
|
|
302
|
-
|
|
300
|
+
var bigIntReplacer = (_key, value) => {
|
|
301
|
+
return typeof value === "bigint" ? value.toString() : value;
|
|
302
|
+
};
|
|
303
|
+
var dateReplacer = (_key, value) => {
|
|
304
|
+
return value instanceof Date ? value.toISOString() : value;
|
|
305
|
+
};
|
|
306
|
+
var isFirstLetterNumeric = (str) => {
|
|
307
|
+
const c = str.charCodeAt(0);
|
|
308
|
+
return c >= 48 && c <= 57;
|
|
309
|
+
};
|
|
310
|
+
var isFirstLetterNumericOrMinus = (str) => {
|
|
311
|
+
const c = str.charCodeAt(0);
|
|
312
|
+
return c >= 48 && c <= 57 || c === 45;
|
|
313
|
+
};
|
|
314
|
+
var bigIntReviver = (_key, value, context) => {
|
|
315
|
+
if (typeof value === "number" && Number.isInteger(value) && !Number.isSafeInteger(value)) {
|
|
316
|
+
try {
|
|
317
|
+
return BigInt(_nullishCoalesce(_optionalChain([context, 'optionalAccess', _7 => _7.source]), () => ( value.toString())));
|
|
318
|
+
} catch (e2) {
|
|
319
|
+
return value;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
if (typeof value === "string" && value.length > 15) {
|
|
323
|
+
if (isFirstLetterNumericOrMinus(value)) {
|
|
324
|
+
const num = Number(value);
|
|
325
|
+
if (Number.isFinite(num) && !Number.isSafeInteger(num)) {
|
|
326
|
+
try {
|
|
327
|
+
return BigInt(value);
|
|
328
|
+
} catch (e3) {
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
303
332
|
}
|
|
333
|
+
return value;
|
|
304
334
|
};
|
|
305
|
-
var
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
(_, v) => typeof v === "bigint" ? v.toString() : v
|
|
312
|
-
);
|
|
313
|
-
},
|
|
314
|
-
parse: (text, options) => {
|
|
315
|
-
const parsed = JSON.parse(text, _optionalChain([options, 'optionalAccess', _9 => _9.reviver]));
|
|
316
|
-
if (_optionalChain([options, 'optionalAccess', _10 => _10.typeCheck]) && !_optionalChain([options, 'optionalAccess', _11 => _11.typeCheck, 'call', _12 => _12(parsed)]))
|
|
317
|
-
throw new ParseError(text);
|
|
318
|
-
return _optionalChain([options, 'optionalAccess', _13 => _13.map]) ? options.map(parsed) : parsed;
|
|
335
|
+
var dateReviver = (_key, value) => {
|
|
336
|
+
if (typeof value === "string" && value.length === 24 && isFirstLetterNumeric(value) && value[10] === "T" && value[23] === "Z") {
|
|
337
|
+
const date = new Date(value);
|
|
338
|
+
if (!isNaN(date.getTime())) {
|
|
339
|
+
return date;
|
|
340
|
+
}
|
|
319
341
|
}
|
|
342
|
+
return value;
|
|
343
|
+
};
|
|
344
|
+
var composeJSONReplacers = (...replacers) => {
|
|
345
|
+
const filteredReplacers = replacers.filter((r) => r !== void 0);
|
|
346
|
+
if (filteredReplacers.length === 0) return void 0;
|
|
347
|
+
return (key, value) => (
|
|
348
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
349
|
+
filteredReplacers.reduce(
|
|
350
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
351
|
+
(accValue, replacer) => replacer(key, accValue),
|
|
352
|
+
value
|
|
353
|
+
)
|
|
354
|
+
);
|
|
320
355
|
};
|
|
356
|
+
var composeJSONRevivers = (...revivers) => {
|
|
357
|
+
const filteredRevivers = revivers.filter((r) => r !== void 0);
|
|
358
|
+
if (filteredRevivers.length === 0) return void 0;
|
|
359
|
+
return (key, value, context) => (
|
|
360
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
361
|
+
filteredRevivers.reduce(
|
|
362
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
363
|
+
(accValue, reviver) => reviver(key, accValue, context),
|
|
364
|
+
value
|
|
365
|
+
)
|
|
366
|
+
);
|
|
367
|
+
};
|
|
368
|
+
var JSONReplacer = (opts) => composeJSONReplacers(
|
|
369
|
+
_optionalChain([opts, 'optionalAccess', _8 => _8.replacer]),
|
|
370
|
+
_optionalChain([opts, 'optionalAccess', _9 => _9.failOnBigIntSerialization]) !== true ? JSONReplacers.bigInt : void 0,
|
|
371
|
+
_optionalChain([opts, 'optionalAccess', _10 => _10.useDefaultDateSerialization]) !== true ? JSONReplacers.date : void 0
|
|
372
|
+
);
|
|
373
|
+
var JSONReviver = (opts) => composeJSONRevivers(
|
|
374
|
+
_optionalChain([opts, 'optionalAccess', _11 => _11.reviver]),
|
|
375
|
+
_optionalChain([opts, 'optionalAccess', _12 => _12.parseBigInts]) === true ? JSONRevivers.bigInt : void 0,
|
|
376
|
+
_optionalChain([opts, 'optionalAccess', _13 => _13.parseDates]) === true ? JSONRevivers.date : void 0
|
|
377
|
+
);
|
|
378
|
+
var JSONReplacers = {
|
|
379
|
+
bigInt: bigIntReplacer,
|
|
380
|
+
date: dateReplacer
|
|
381
|
+
};
|
|
382
|
+
var JSONRevivers = {
|
|
383
|
+
bigInt: bigIntReviver,
|
|
384
|
+
date: dateReviver
|
|
385
|
+
};
|
|
386
|
+
var jsonSerializer = (options) => {
|
|
387
|
+
const defaultReplacer = JSONReplacer(options);
|
|
388
|
+
const defaultReviver = JSONReviver(options);
|
|
389
|
+
return {
|
|
390
|
+
serialize: (object, serializerOptions) => JSON.stringify(
|
|
391
|
+
object,
|
|
392
|
+
serializerOptions ? JSONReplacer(serializerOptions) : defaultReplacer
|
|
393
|
+
),
|
|
394
|
+
deserialize: (payload, deserializerOptions) => JSON.parse(
|
|
395
|
+
payload,
|
|
396
|
+
deserializerOptions ? JSONReviver(deserializerOptions) : defaultReviver
|
|
397
|
+
)
|
|
398
|
+
};
|
|
399
|
+
};
|
|
400
|
+
var JSONSerializer = Object.assign(jsonSerializer(), {
|
|
401
|
+
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)))
|
|
402
|
+
});
|
|
321
403
|
var NoRetries = { retries: 0 };
|
|
322
404
|
var asyncRetry = async (fn, opts) => {
|
|
323
405
|
if (opts === void 0 || opts.retries === 0) return fn();
|
|
@@ -325,14 +407,14 @@ var asyncRetry = async (fn, opts) => {
|
|
|
325
407
|
async (bail) => {
|
|
326
408
|
try {
|
|
327
409
|
const result = await fn();
|
|
328
|
-
if (_optionalChain([opts, 'optionalAccess',
|
|
410
|
+
if (_optionalChain([opts, 'optionalAccess', _20 => _20.shouldRetryResult]) && opts.shouldRetryResult(result)) {
|
|
329
411
|
throw new EmmettError(
|
|
330
|
-
`Retrying because of result: ${
|
|
412
|
+
`Retrying because of result: ${JSONSerializer.serialize(result)}`
|
|
331
413
|
);
|
|
332
414
|
}
|
|
333
415
|
return result;
|
|
334
416
|
} catch (error) {
|
|
335
|
-
if (_optionalChain([opts, 'optionalAccess',
|
|
417
|
+
if (_optionalChain([opts, 'optionalAccess', _21 => _21.shouldRetryError]) && !opts.shouldRetryError(error)) {
|
|
336
418
|
bail(error);
|
|
337
419
|
return void 0;
|
|
338
420
|
}
|
|
@@ -457,7 +539,7 @@ var reactor = (options) => {
|
|
|
457
539
|
}
|
|
458
540
|
if (startFrom && startFrom !== "CURRENT") return startFrom;
|
|
459
541
|
if (checkpoints) {
|
|
460
|
-
const readResult = await _optionalChain([checkpoints, 'optionalAccess',
|
|
542
|
+
const readResult = await _optionalChain([checkpoints, 'optionalAccess', _22 => _22.read, 'call', _23 => _23(
|
|
461
543
|
{
|
|
462
544
|
processorId,
|
|
463
545
|
partition
|
|
@@ -485,7 +567,7 @@ var reactor = (options) => {
|
|
|
485
567
|
const upcasted = upcastRecordedMessage(
|
|
486
568
|
// TODO: Make it smarter
|
|
487
569
|
message2,
|
|
488
|
-
_optionalChain([options, 'access',
|
|
570
|
+
_optionalChain([options, 'access', _24 => _24.messageOptions, 'optionalAccess', _25 => _25.schema, 'optionalAccess', _26 => _26.versioning])
|
|
489
571
|
);
|
|
490
572
|
if (canHandle !== void 0 && !canHandle.includes(upcasted.type))
|
|
491
573
|
continue;
|
|
@@ -538,13 +620,13 @@ var projector = (options) => {
|
|
|
538
620
|
processorId,
|
|
539
621
|
messageOptions: options.projection.eventsOptions,
|
|
540
622
|
hooks: {
|
|
541
|
-
onInit: _optionalChain([options, 'access',
|
|
542
|
-
onStart: options.truncateOnStart && options.projection.truncate || _optionalChain([options, 'access',
|
|
623
|
+
onInit: _optionalChain([options, 'access', _27 => _27.hooks, 'optionalAccess', _28 => _28.onInit]),
|
|
624
|
+
onStart: options.truncateOnStart && options.projection.truncate || _optionalChain([options, 'access', _29 => _29.hooks, 'optionalAccess', _30 => _30.onStart]) ? async (context) => {
|
|
543
625
|
if (options.truncateOnStart && options.projection.truncate)
|
|
544
626
|
await options.projection.truncate(context);
|
|
545
|
-
if (_optionalChain([options, 'access',
|
|
627
|
+
if (_optionalChain([options, 'access', _31 => _31.hooks, 'optionalAccess', _32 => _32.onStart])) await _optionalChain([options, 'access', _33 => _33.hooks, 'optionalAccess', _34 => _34.onStart, 'call', _35 => _35(context)]);
|
|
546
628
|
} : void 0,
|
|
547
|
-
onClose: _optionalChain([options, 'access',
|
|
629
|
+
onClose: _optionalChain([options, 'access', _36 => _36.hooks, 'optionalAccess', _37 => _37.onClose])
|
|
548
630
|
},
|
|
549
631
|
eachMessage: async (event2, context) => projection2.handle([event2], context)
|
|
550
632
|
});
|
|
@@ -573,9 +655,9 @@ var assertDeepEqual = (actual, expected, message2) => {
|
|
|
573
655
|
if (!deepEquals(actual, expected))
|
|
574
656
|
throw new AssertionError(
|
|
575
657
|
_nullishCoalesce(message2, () => ( `subObj:
|
|
576
|
-
${
|
|
658
|
+
${JSONSerializer.serialize(expected)}
|
|
577
659
|
is not equal to
|
|
578
|
-
${
|
|
660
|
+
${JSONSerializer.serialize(actual)}`))
|
|
579
661
|
);
|
|
580
662
|
};
|
|
581
663
|
function assertTrue(condition, message2) {
|
|
@@ -589,14 +671,14 @@ function assertEqual(expected, actual, message2) {
|
|
|
589
671
|
if (expected !== actual)
|
|
590
672
|
throw new AssertionError(
|
|
591
673
|
`${_nullishCoalesce(message2, () => ( "Objects are not equal"))}:
|
|
592
|
-
Expected: ${
|
|
593
|
-
Actual: ${
|
|
674
|
+
Expected: ${JSONSerializer.serialize(expected)}
|
|
675
|
+
Actual: ${JSONSerializer.serialize(actual)}`
|
|
594
676
|
);
|
|
595
677
|
}
|
|
596
678
|
function assertNotEqual(obj, other, message2) {
|
|
597
679
|
if (obj === other)
|
|
598
680
|
throw new AssertionError(
|
|
599
|
-
_nullishCoalesce(message2, () => ( `Objects are equal: ${
|
|
681
|
+
_nullishCoalesce(message2, () => ( `Objects are equal: ${JSONSerializer.serialize(obj)}`))
|
|
600
682
|
);
|
|
601
683
|
}
|
|
602
684
|
function assertIsNotNull(result) {
|
|
@@ -611,7 +693,7 @@ var assertThatArray = (array) => {
|
|
|
611
693
|
isEmpty: () => assertEqual(
|
|
612
694
|
array.length,
|
|
613
695
|
0,
|
|
614
|
-
`Array is not empty ${
|
|
696
|
+
`Array is not empty ${JSONSerializer.serialize(array)}`
|
|
615
697
|
),
|
|
616
698
|
isNotEmpty: () => assertNotEqual(array.length, 0, `Array is empty`),
|
|
617
699
|
hasSize: (length) => assertEqual(array.length, length),
|
|
@@ -668,7 +750,7 @@ var assertThatArray = (array) => {
|
|
|
668
750
|
};
|
|
669
751
|
};
|
|
670
752
|
var downcastRecordedMessage = (recordedMessage, options) => {
|
|
671
|
-
if (!_optionalChain([options, 'optionalAccess',
|
|
753
|
+
if (!_optionalChain([options, 'optionalAccess', _38 => _38.downcast]))
|
|
672
754
|
return recordedMessage;
|
|
673
755
|
const downcasted = options.downcast(
|
|
674
756
|
recordedMessage
|
|
@@ -686,14 +768,14 @@ var downcastRecordedMessage = (recordedMessage, options) => {
|
|
|
686
768
|
};
|
|
687
769
|
};
|
|
688
770
|
var downcastRecordedMessages = (recordedMessages, options) => {
|
|
689
|
-
if (!_optionalChain([options, 'optionalAccess',
|
|
771
|
+
if (!_optionalChain([options, 'optionalAccess', _39 => _39.downcast]))
|
|
690
772
|
return recordedMessages;
|
|
691
773
|
return recordedMessages.map(
|
|
692
774
|
(recordedMessage) => downcastRecordedMessage(recordedMessage, options)
|
|
693
775
|
);
|
|
694
776
|
};
|
|
695
777
|
var upcastRecordedMessage = (recordedMessage, options) => {
|
|
696
|
-
if (!_optionalChain([options, 'optionalAccess',
|
|
778
|
+
if (!_optionalChain([options, 'optionalAccess', _40 => _40.upcast]))
|
|
697
779
|
return recordedMessage;
|
|
698
780
|
const upcasted = options.upcast(
|
|
699
781
|
recordedMessage
|
|
@@ -761,11 +843,11 @@ var createWrappedEvolve = (evolve, workflowName, separateInputInboxFromProcessin
|
|
|
761
843
|
return (state, event2) => {
|
|
762
844
|
const metadata = event2.metadata;
|
|
763
845
|
let processedInputIds = state.processedInputIds;
|
|
764
|
-
if (_optionalChain([metadata, 'optionalAccess',
|
|
846
|
+
if (_optionalChain([metadata, 'optionalAccess', _41 => _41.input]) === true && typeof _optionalChain([metadata, 'optionalAccess', _42 => _42.originalMessageId]) === "string") {
|
|
765
847
|
processedInputIds = new Set(state.processedInputIds);
|
|
766
848
|
processedInputIds.add(metadata.originalMessageId);
|
|
767
849
|
}
|
|
768
|
-
if (separateInputInboxFromProcessing && _optionalChain([metadata, 'optionalAccess',
|
|
850
|
+
if (separateInputInboxFromProcessing && _optionalChain([metadata, 'optionalAccess', _43 => _43.input]) === true) {
|
|
769
851
|
return {
|
|
770
852
|
userState: state.userState,
|
|
771
853
|
processedInputIds
|
|
@@ -795,7 +877,7 @@ var WorkflowHandler = (options) => async (store, message2, handleOptions) => asy
|
|
|
795
877
|
} = options;
|
|
796
878
|
const inputMessageId = (
|
|
797
879
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
798
|
-
_nullishCoalesce(("metadata" in message2 && _optionalChain([message2, 'access',
|
|
880
|
+
_nullishCoalesce(("metadata" in message2 && _optionalChain([message2, 'access', _44 => _44.metadata, 'optionalAccess', _45 => _45.messageId]) ? (
|
|
799
881
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
800
882
|
message2.metadata.messageId
|
|
801
883
|
) : void 0), () => ( _uuid.v7.call(void 0, )))
|
|
@@ -831,7 +913,7 @@ var WorkflowHandler = (options) => async (store, message2, handleOptions) => asy
|
|
|
831
913
|
[inputToStore2],
|
|
832
914
|
{
|
|
833
915
|
...handleOptions,
|
|
834
|
-
expectedStreamVersion: _nullishCoalesce(_optionalChain([handleOptions, 'optionalAccess',
|
|
916
|
+
expectedStreamVersion: _nullishCoalesce(_optionalChain([handleOptions, 'optionalAccess', _46 => _46.expectedStreamVersion]), () => ( NO_CONCURRENCY_CHECK))
|
|
835
917
|
}
|
|
836
918
|
);
|
|
837
919
|
return {
|
|
@@ -852,7 +934,7 @@ var WorkflowHandler = (options) => async (store, message2, handleOptions) => asy
|
|
|
852
934
|
...handleOptions,
|
|
853
935
|
// expected stream version is passed to fail fast
|
|
854
936
|
// if stream is in the wrong state
|
|
855
|
-
expectedStreamVersion: _nullishCoalesce(_optionalChain([handleOptions, 'optionalAccess',
|
|
937
|
+
expectedStreamVersion: _nullishCoalesce(_optionalChain([handleOptions, 'optionalAccess', _47 => _47.expectedStreamVersion]), () => ( NO_CONCURRENCY_CHECK))
|
|
856
938
|
}
|
|
857
939
|
});
|
|
858
940
|
const { currentStreamVersion } = aggregationResult;
|
|
@@ -876,7 +958,7 @@ var WorkflowHandler = (options) => async (store, message2, handleOptions) => asy
|
|
|
876
958
|
metadata: inputMetadata
|
|
877
959
|
};
|
|
878
960
|
const outputMessages = (Array.isArray(result2) ? result2 : [result2]).filter((msg) => msg !== void 0 && msg !== null);
|
|
879
|
-
const outputCommandTypes = _nullishCoalesce(_optionalChain([options, 'access',
|
|
961
|
+
const outputCommandTypes = _nullishCoalesce(_optionalChain([options, 'access', _48 => _48.outputs, 'optionalAccess', _49 => _49.commands]), () => ( []));
|
|
880
962
|
const taggedOutputMessages = outputMessages.map((msg) => {
|
|
881
963
|
const action = outputCommandTypes.includes(
|
|
882
964
|
msg.type
|
|
@@ -887,7 +969,7 @@ var WorkflowHandler = (options) => async (store, message2, handleOptions) => asy
|
|
|
887
969
|
if (messagesToAppend.length === 0) {
|
|
888
970
|
return emptyHandlerResult(currentStreamVersion);
|
|
889
971
|
}
|
|
890
|
-
const expectedStreamVersion = _nullishCoalesce(_optionalChain([handleOptions, 'optionalAccess',
|
|
972
|
+
const expectedStreamVersion = _nullishCoalesce(_optionalChain([handleOptions, 'optionalAccess', _50 => _50.expectedStreamVersion]), () => ( (aggregationResult.streamExists ? currentStreamVersion : STREAM_DOES_NOT_EXIST)));
|
|
891
973
|
const appendResult = await eventStore.appendToStream(
|
|
892
974
|
streamName,
|
|
893
975
|
// TODO: Fix this cast
|
|
@@ -994,7 +1076,7 @@ var readLastMessageGlobalPosition = async (execute, options) => {
|
|
|
994
1076
|
execute.query(
|
|
995
1077
|
_dumbo.SQL`SELECT global_position
|
|
996
1078
|
FROM ${_dumbo.SQL.identifier(messagesTable.name)}
|
|
997
|
-
WHERE partition = ${_nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
1079
|
+
WHERE partition = ${_nullishCoalesce(_optionalChain([options, 'optionalAccess', _51 => _51.partition]), () => ( defaultTag2))} AND is_archived = FALSE AND transaction_id < pg_snapshot_xmin(pg_current_snapshot())
|
|
998
1080
|
ORDER BY transaction_id, global_position
|
|
999
1081
|
LIMIT 1`
|
|
1000
1082
|
)
|
|
@@ -1018,7 +1100,7 @@ var readMessagesBatch = async (execute, options) => {
|
|
|
1018
1100
|
_dumbo.SQL`
|
|
1019
1101
|
SELECT stream_id, stream_position, global_position, message_data, message_metadata, message_schema_version, message_type, message_id
|
|
1020
1102
|
FROM ${_dumbo.SQL.identifier(messagesTable.name)}
|
|
1021
|
-
WHERE partition = ${_nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
1103
|
+
WHERE partition = ${_nullishCoalesce(_optionalChain([options, 'optionalAccess', _52 => _52.partition]), () => ( defaultTag2))} AND is_archived = FALSE AND transaction_id < pg_snapshot_xmin(pg_current_snapshot()) ${fromCondition} ${toCondition}
|
|
1022
1104
|
ORDER BY transaction_id, global_position
|
|
1023
1105
|
${limitCondition}`
|
|
1024
1106
|
),
|
|
@@ -1074,7 +1156,7 @@ var postgreSQLEventStoreMessageBatchPuller = ({
|
|
|
1074
1156
|
batchSize
|
|
1075
1157
|
};
|
|
1076
1158
|
let waitTime = 100;
|
|
1077
|
-
while (isRunning && !_optionalChain([signal, 'optionalAccess',
|
|
1159
|
+
while (isRunning && !_optionalChain([signal, 'optionalAccess', _53 => _53.aborted])) {
|
|
1078
1160
|
const { messages, currentGlobalPosition, areMessagesLeft } = await readMessagesBatch(executor, readMessagesOptions);
|
|
1079
1161
|
if (messages.length > 0) {
|
|
1080
1162
|
const result = await eachBatch(messages);
|
|
@@ -1085,7 +1167,7 @@ var postgreSQLEventStoreMessageBatchPuller = ({
|
|
|
1085
1167
|
}
|
|
1086
1168
|
readMessagesOptions.after = currentGlobalPosition;
|
|
1087
1169
|
await new Promise((resolve) => setTimeout(resolve, waitTime));
|
|
1088
|
-
if (_optionalChain([stopWhen, 'optionalAccess',
|
|
1170
|
+
if (_optionalChain([stopWhen, 'optionalAccess', _54 => _54.noMessagesLeft]) === true && !areMessagesLeft) {
|
|
1089
1171
|
isRunning = false;
|
|
1090
1172
|
break;
|
|
1091
1173
|
}
|
|
@@ -1387,9 +1469,9 @@ var tryAcquireProcessorLock = async (execute, options) => {
|
|
|
1387
1469
|
version: options.version,
|
|
1388
1470
|
partition: options.partition,
|
|
1389
1471
|
processorInstanceId: options.processorInstanceId,
|
|
1390
|
-
projectionName: _nullishCoalesce(_optionalChain([options, 'access',
|
|
1391
|
-
projectionType: _optionalChain([options, 'access',
|
|
1392
|
-
projectionKind: _nullishCoalesce(_optionalChain([options, 'access',
|
|
1472
|
+
projectionName: _nullishCoalesce(_optionalChain([options, 'access', _55 => _55.projection, 'optionalAccess', _56 => _56.name]), () => ( null)),
|
|
1473
|
+
projectionType: _optionalChain([options, 'access', _57 => _57.projection, 'optionalAccess', _58 => _58.handlingType]) ? options.projection.handlingType === "inline" ? "i" : "a" : null,
|
|
1474
|
+
projectionKind: _nullishCoalesce(_optionalChain([options, 'access', _59 => _59.projection, 'optionalAccess', _60 => _60.kind]), () => ( null)),
|
|
1393
1475
|
lockTimeoutSeconds: _nullishCoalesce(options.lockTimeoutSeconds, () => ( PROCESSOR_LOCK_DEFAULT_TIMEOUT_SECONDS))
|
|
1394
1476
|
})
|
|
1395
1477
|
)
|
|
@@ -1441,7 +1523,7 @@ var postgreSQLProcessorLock = (options) => {
|
|
|
1441
1523
|
...options,
|
|
1442
1524
|
lockKey
|
|
1443
1525
|
});
|
|
1444
|
-
if (!result.acquired && _optionalChain([options, 'access',
|
|
1526
|
+
if (!result.acquired && _optionalChain([options, 'access', _61 => _61.lockAcquisitionPolicy, 'optionalAccess', _62 => _62.type]) !== "skip") {
|
|
1445
1527
|
throw new EmmettError(
|
|
1446
1528
|
`Failed to acquire lock for processor '${options.processorId}'`
|
|
1447
1529
|
);
|
|
@@ -1455,7 +1537,7 @@ var postgreSQLProcessorLock = (options) => {
|
|
|
1455
1537
|
await releaseProcessorLock(context.execute, {
|
|
1456
1538
|
...releaseOptions,
|
|
1457
1539
|
lockKey,
|
|
1458
|
-
projectionName: _optionalChain([projection2, 'optionalAccess',
|
|
1540
|
+
projectionName: _optionalChain([projection2, 'optionalAccess', _63 => _63.name])
|
|
1459
1541
|
});
|
|
1460
1542
|
acquired = false;
|
|
1461
1543
|
}
|
|
@@ -1971,8 +2053,12 @@ var expectPongoDocuments = {
|
|
|
1971
2053
|
var PostgreSQLProjectionSpec = {
|
|
1972
2054
|
for: (options) => {
|
|
1973
2055
|
{
|
|
1974
|
-
const { projection: projection2, ...
|
|
1975
|
-
const
|
|
2056
|
+
const { projection: projection2, ...restOptions } = options;
|
|
2057
|
+
const dumboOptions = {
|
|
2058
|
+
...restOptions,
|
|
2059
|
+
serialization: projection2.serialization
|
|
2060
|
+
};
|
|
2061
|
+
const { connectionString } = dumboOptions;
|
|
1976
2062
|
let wasInitialised = false;
|
|
1977
2063
|
const initialize = async (pool) => {
|
|
1978
2064
|
const eventStore = getPostgreSQLEventStore(connectionString, {
|
|
@@ -2002,7 +2088,7 @@ var PostgreSQLProjectionSpec = {
|
|
|
2002
2088
|
const allEvents = [];
|
|
2003
2089
|
const run = async (pool) => {
|
|
2004
2090
|
let globalPosition = 0n;
|
|
2005
|
-
const numberOfTimes = _nullishCoalesce(_optionalChain([options2, 'optionalAccess',
|
|
2091
|
+
const numberOfTimes = _nullishCoalesce(_optionalChain([options2, 'optionalAccess', _64 => _64.numberOfTimes]), () => ( 1));
|
|
2006
2092
|
for (const event of [
|
|
2007
2093
|
...givenEvents,
|
|
2008
2094
|
...Array.from({ length: numberOfTimes }).flatMap(() => events)
|
|
@@ -2038,7 +2124,7 @@ var PostgreSQLProjectionSpec = {
|
|
|
2038
2124
|
};
|
|
2039
2125
|
return {
|
|
2040
2126
|
then: async (assert, message) => {
|
|
2041
|
-
const pool = _dumbo.dumbo.call(void 0,
|
|
2127
|
+
const pool = _dumbo.dumbo.call(void 0, dumboOptions);
|
|
2042
2128
|
try {
|
|
2043
2129
|
await run(pool);
|
|
2044
2130
|
const succeeded = await assert({ pool, connectionString });
|
|
@@ -2051,7 +2137,7 @@ var PostgreSQLProjectionSpec = {
|
|
|
2051
2137
|
}
|
|
2052
2138
|
},
|
|
2053
2139
|
thenThrows: async (...args) => {
|
|
2054
|
-
const pool = _dumbo.dumbo.call(void 0,
|
|
2140
|
+
const pool = _dumbo.dumbo.call(void 0, dumboOptions);
|
|
2055
2141
|
try {
|
|
2056
2142
|
await run(pool);
|
|
2057
2143
|
throw new AssertionError("Handler did not fail as expected");
|
|
@@ -2061,18 +2147,18 @@ var PostgreSQLProjectionSpec = {
|
|
|
2061
2147
|
if (!isErrorConstructor(args[0])) {
|
|
2062
2148
|
assertTrue(
|
|
2063
2149
|
args[0](error),
|
|
2064
|
-
`Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess',
|
|
2150
|
+
`Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess', _65 => _65.toString, 'call', _66 => _66()])}`
|
|
2065
2151
|
);
|
|
2066
2152
|
return;
|
|
2067
2153
|
}
|
|
2068
2154
|
assertTrue(
|
|
2069
2155
|
error instanceof args[0],
|
|
2070
|
-
`Caught error is not an instance of the expected type: ${_optionalChain([error, 'optionalAccess',
|
|
2156
|
+
`Caught error is not an instance of the expected type: ${_optionalChain([error, 'optionalAccess', _67 => _67.toString, 'call', _68 => _68()])}`
|
|
2071
2157
|
);
|
|
2072
2158
|
if (args[1]) {
|
|
2073
2159
|
assertTrue(
|
|
2074
2160
|
args[1](error),
|
|
2075
|
-
`Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess',
|
|
2161
|
+
`Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess', _69 => _69.toString, 'call', _70 => _70()])}`
|
|
2076
2162
|
);
|
|
2077
2163
|
}
|
|
2078
2164
|
} finally {
|
|
@@ -2091,7 +2177,7 @@ var eventInStream = (streamName, event) => {
|
|
|
2091
2177
|
...event,
|
|
2092
2178
|
metadata: {
|
|
2093
2179
|
..._nullishCoalesce(event.metadata, () => ( {})),
|
|
2094
|
-
streamName: _nullishCoalesce(_optionalChain([event, 'access',
|
|
2180
|
+
streamName: _nullishCoalesce(_optionalChain([event, 'access', _71 => _71.metadata, 'optionalAccess', _72 => _72.streamName]), () => ( streamName))
|
|
2095
2181
|
}
|
|
2096
2182
|
};
|
|
2097
2183
|
};
|
|
@@ -2342,7 +2428,7 @@ var appendToStream = (pool, streamName, streamType, messages, options) => pool.w
|
|
|
2342
2428
|
return { success: false, result: { success: false } };
|
|
2343
2429
|
try {
|
|
2344
2430
|
const expectedStreamVersion = toExpectedVersion(
|
|
2345
|
-
_optionalChain([options, 'optionalAccess',
|
|
2431
|
+
_optionalChain([options, 'optionalAccess', _73 => _73.expectedStreamVersion])
|
|
2346
2432
|
);
|
|
2347
2433
|
const messagesToAppend = messages.map((e) => ({
|
|
2348
2434
|
...e,
|
|
@@ -2382,7 +2468,7 @@ var appendToStream = (pool, streamName, streamType, messages, options) => pool.w
|
|
|
2382
2468
|
globalPosition
|
|
2383
2469
|
};
|
|
2384
2470
|
});
|
|
2385
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
2471
|
+
if (_optionalChain([options, 'optionalAccess', _74 => _74.beforeCommitHook]))
|
|
2386
2472
|
await options.beforeCommitHook(messagesToAppend, { transaction });
|
|
2387
2473
|
return {
|
|
2388
2474
|
success: true,
|
|
@@ -2425,8 +2511,8 @@ var appendEventsRaw = (execute, streamId, streamType, messages, options) => _dum
|
|
|
2425
2511
|
messageKinds: messages.map((e) => e.kind === "Event" ? "E" : "C"),
|
|
2426
2512
|
streamId,
|
|
2427
2513
|
streamType,
|
|
2428
|
-
expectedStreamPosition: _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
2429
|
-
partition: _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
2514
|
+
expectedStreamPosition: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _75 => _75.expectedStreamVersion]), () => ( null)),
|
|
2515
|
+
partition: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _76 => _76.partition]), () => ( defaultTag2))
|
|
2430
2516
|
})
|
|
2431
2517
|
)
|
|
2432
2518
|
);
|
|
@@ -4488,7 +4574,7 @@ var readProcessorCheckpoint = async (execute, options) => {
|
|
|
4488
4574
|
execute.query(
|
|
4489
4575
|
_dumbo.SQL`SELECT last_processed_checkpoint
|
|
4490
4576
|
FROM ${_dumbo.SQL.identifier(processorsTable.name)}
|
|
4491
|
-
WHERE partition = ${_nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
4577
|
+
WHERE partition = ${_nullishCoalesce(_optionalChain([options, 'optionalAccess', _77 => _77.partition]), () => ( defaultTag2))} AND processor_id = ${options.processorId} AND version = ${_nullishCoalesce(options.version, () => ( 1))}
|
|
4492
4578
|
LIMIT 1`
|
|
4493
4579
|
)
|
|
4494
4580
|
);
|
|
@@ -4500,16 +4586,16 @@ var readProcessorCheckpoint = async (execute, options) => {
|
|
|
4500
4586
|
// src/eventStore/schema/readStream.ts
|
|
4501
4587
|
|
|
4502
4588
|
var readStream = async (execute, streamId, options) => {
|
|
4503
|
-
const fromCondition = _optionalChain([options, 'optionalAccess',
|
|
4589
|
+
const fromCondition = _optionalChain([options, 'optionalAccess', _78 => _78.from]) ? `AND stream_position >= ${options.from}` : "";
|
|
4504
4590
|
const to = Number(
|
|
4505
|
-
_nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
4591
|
+
_nullishCoalesce(_optionalChain([options, 'optionalAccess', _79 => _79.to]), () => ( (_optionalChain([options, 'optionalAccess', _80 => _80.maxCount]) ? (_nullishCoalesce(options.from, () => ( 0n))) + options.maxCount : NaN)))
|
|
4506
4592
|
);
|
|
4507
4593
|
const toCondition = !isNaN(to) ? `AND stream_position <= ${to}` : "";
|
|
4508
4594
|
const events = await _dumbo.mapRows.call(void 0,
|
|
4509
4595
|
execute.query(
|
|
4510
4596
|
_dumbo.SQL`SELECT stream_id, stream_position, global_position, message_data, message_metadata, message_schema_version, message_type, message_id
|
|
4511
4597
|
FROM ${_dumbo.SQL.identifier(messagesTable.name)}
|
|
4512
|
-
WHERE stream_id = ${streamId} AND partition = ${_nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
4598
|
+
WHERE stream_id = ${streamId} AND partition = ${_nullishCoalesce(_optionalChain([options, 'optionalAccess', _81 => _81.partition]), () => ( defaultTag2))} AND is_archived = FALSE ${_dumbo.SQL.plain(fromCondition)} ${_dumbo.SQL.plain(toCondition)}
|
|
4513
4599
|
ORDER BY stream_position ASC`
|
|
4514
4600
|
),
|
|
4515
4601
|
(row) => {
|
|
@@ -4531,7 +4617,7 @@ var readStream = async (execute, streamId, options) => {
|
|
|
4531
4617
|
kind: "Event",
|
|
4532
4618
|
metadata
|
|
4533
4619
|
};
|
|
4534
|
-
return upcastRecordedMessage(event, _optionalChain([options, 'optionalAccess',
|
|
4620
|
+
return upcastRecordedMessage(event, _optionalChain([options, 'optionalAccess', _82 => _82.schema, 'optionalAccess', _83 => _83.versioning]));
|
|
4535
4621
|
}
|
|
4536
4622
|
);
|
|
4537
4623
|
return events.length > 0 ? {
|
|
@@ -4552,10 +4638,10 @@ var streamExists = async (execute, streamId, options) => {
|
|
|
4552
4638
|
_dumbo.SQL`SELECT EXISTS (
|
|
4553
4639
|
SELECT 1
|
|
4554
4640
|
from ${_dumbo.SQL.identifier(streamsTable.name)}
|
|
4555
|
-
WHERE stream_id = ${streamId} AND partition = ${_nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
4641
|
+
WHERE stream_id = ${streamId} AND partition = ${_nullishCoalesce(_optionalChain([options, 'optionalAccess', _84 => _84.partition]), () => ( defaultTag2))} AND is_archived = FALSE)
|
|
4556
4642
|
`
|
|
4557
4643
|
);
|
|
4558
|
-
return _nullishCoalesce(_optionalChain([queryResult, 'access',
|
|
4644
|
+
return _nullishCoalesce(_optionalChain([queryResult, 'access', _85 => _85.rows, 'access', _86 => _86[0], 'optionalAccess', _87 => _87.exists]), () => ( false));
|
|
4559
4645
|
};
|
|
4560
4646
|
|
|
4561
4647
|
// src/eventStore/schema/index.ts
|
|
@@ -4593,9 +4679,13 @@ var createEventStoreSchema = (connectionString, pool, hooks, options) => {
|
|
|
4593
4679
|
pool,
|
|
4594
4680
|
tx
|
|
4595
4681
|
);
|
|
4596
|
-
const nestedPool = _dumbo.dumbo.call(void 0, {
|
|
4682
|
+
const nestedPool = _dumbo.dumbo.call(void 0, {
|
|
4683
|
+
connectionString,
|
|
4684
|
+
connection: tx.connection,
|
|
4685
|
+
serialization: _optionalChain([options, 'optionalAccess', _88 => _88.serialization])
|
|
4686
|
+
});
|
|
4597
4687
|
try {
|
|
4598
|
-
if (_optionalChain([hooks, 'optionalAccess',
|
|
4688
|
+
if (_optionalChain([hooks, 'optionalAccess', _89 => _89.onBeforeSchemaCreated])) {
|
|
4599
4689
|
await hooks.onBeforeSchemaCreated(context);
|
|
4600
4690
|
}
|
|
4601
4691
|
const result = await _dumbo.runSQLMigrations.call(void 0,
|
|
@@ -4603,7 +4693,7 @@ var createEventStoreSchema = (connectionString, pool, hooks, options) => {
|
|
|
4603
4693
|
eventStoreSchemaMigrations,
|
|
4604
4694
|
options
|
|
4605
4695
|
);
|
|
4606
|
-
if (_optionalChain([hooks, 'optionalAccess',
|
|
4696
|
+
if (_optionalChain([hooks, 'optionalAccess', _90 => _90.onAfterSchemaCreated])) {
|
|
4607
4697
|
await hooks.onAfterSchemaCreated(context);
|
|
4608
4698
|
}
|
|
4609
4699
|
return result;
|
|
@@ -4622,7 +4712,7 @@ var truncateTables = async (execute, options) => {
|
|
|
4622
4712
|
${_dumbo.SQL.identifier(messagesTable.name)},
|
|
4623
4713
|
${_dumbo.SQL.identifier(processorsTable.name)},
|
|
4624
4714
|
${_dumbo.SQL.identifier(projectionsTable.name)}
|
|
4625
|
-
CASCADE${_dumbo.SQL.plain(_optionalChain([options, 'optionalAccess',
|
|
4715
|
+
CASCADE${_dumbo.SQL.plain(_optionalChain([options, 'optionalAccess', _91 => _91.resetSequences]) ? "; ALTER SEQUENCE emt_global_message_position RESTART WITH 1" : "")};`
|
|
4626
4716
|
);
|
|
4627
4717
|
};
|
|
4628
4718
|
|
|
@@ -4637,9 +4727,9 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
|
|
|
4637
4727
|
connectionString,
|
|
4638
4728
|
...options.connectionOptions ? options.connectionOptions : {}
|
|
4639
4729
|
};
|
|
4640
|
-
const pool = "dumbo" in poolOptions ? poolOptions.dumbo : _dumbo.dumbo.call(void 0, poolOptions);
|
|
4730
|
+
const pool = "dumbo" in poolOptions ? poolOptions.dumbo : _dumbo.dumbo.call(void 0, { ...poolOptions, serialization: options.serialization });
|
|
4641
4731
|
let migrateSchema = void 0;
|
|
4642
|
-
const autoGenerateSchema = _optionalChain([options, 'access',
|
|
4732
|
+
const autoGenerateSchema = _optionalChain([options, 'access', _92 => _92.schema, 'optionalAccess', _93 => _93.autoMigration]) === void 0 || _optionalChain([options, 'access', _94 => _94.schema, 'optionalAccess', _95 => _95.autoMigration]) !== "None";
|
|
4643
4733
|
const inlineProjections = (_nullishCoalesce(options.projections, () => ( []))).filter(({ type }) => type === "inline").map(({ projection: projection2 }) => projection2);
|
|
4644
4734
|
const migrate = async (migrationOptions) => {
|
|
4645
4735
|
if (!migrateSchema) {
|
|
@@ -4648,7 +4738,7 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
|
|
|
4648
4738
|
pool,
|
|
4649
4739
|
{
|
|
4650
4740
|
onBeforeSchemaCreated: async (context) => {
|
|
4651
|
-
if (_optionalChain([options, 'access',
|
|
4741
|
+
if (_optionalChain([options, 'access', _96 => _96.hooks, 'optionalAccess', _97 => _97.onBeforeSchemaCreated])) {
|
|
4652
4742
|
await options.hooks.onBeforeSchemaCreated(context);
|
|
4653
4743
|
}
|
|
4654
4744
|
},
|
|
@@ -4663,7 +4753,7 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
|
|
|
4663
4753
|
});
|
|
4664
4754
|
}
|
|
4665
4755
|
}
|
|
4666
|
-
if (_optionalChain([options, 'access',
|
|
4756
|
+
if (_optionalChain([options, 'access', _98 => _98.hooks, 'optionalAccess', _99 => _99.onAfterSchemaCreated])) {
|
|
4667
4757
|
await options.hooks.onAfterSchemaCreated(context);
|
|
4668
4758
|
}
|
|
4669
4759
|
}
|
|
@@ -4705,13 +4795,13 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
|
|
|
4705
4795
|
truncate: (truncateOptions) => pool.withTransaction(async (transaction) => {
|
|
4706
4796
|
await ensureSchemaExists();
|
|
4707
4797
|
await truncateTables(transaction.execute, truncateOptions);
|
|
4708
|
-
if (_optionalChain([truncateOptions, 'optionalAccess',
|
|
4798
|
+
if (_optionalChain([truncateOptions, 'optionalAccess', _100 => _100.truncateProjections])) {
|
|
4709
4799
|
const projectionContext = await transactionToPostgreSQLProjectionHandlerContext(
|
|
4710
4800
|
connectionString,
|
|
4711
4801
|
pool,
|
|
4712
4802
|
transaction
|
|
4713
4803
|
);
|
|
4714
|
-
for (const projection2 of _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
4804
|
+
for (const projection2 of _nullishCoalesce(_optionalChain([options, 'optionalAccess', _101 => _101.projections]), () => ( []))) {
|
|
4715
4805
|
if (projection2.projection.truncate)
|
|
4716
4806
|
await projection2.projection.truncate(projectionContext);
|
|
4717
4807
|
}
|
|
@@ -4721,7 +4811,7 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
|
|
|
4721
4811
|
},
|
|
4722
4812
|
async aggregateStream(streamName, options2) {
|
|
4723
4813
|
const { evolve, initialState, read } = options2;
|
|
4724
|
-
const expectedStreamVersion = _optionalChain([read, 'optionalAccess',
|
|
4814
|
+
const expectedStreamVersion = _optionalChain([read, 'optionalAccess', _102 => _102.expectedStreamVersion]);
|
|
4725
4815
|
let state = initialState();
|
|
4726
4816
|
const result = await this.readStream(
|
|
4727
4817
|
streamName,
|
|
@@ -4743,15 +4833,14 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
|
|
|
4743
4833
|
streamExists: result.streamExists
|
|
4744
4834
|
};
|
|
4745
4835
|
},
|
|
4746
|
-
readStream: async (streamName,
|
|
4836
|
+
readStream: async (streamName, readOptions) => {
|
|
4747
4837
|
await ensureSchemaExists();
|
|
4748
|
-
return readStream(
|
|
4749
|
-
|
|
4750
|
-
|
|
4751
|
-
|
|
4752
|
-
);
|
|
4838
|
+
return readStream(pool.execute, streamName, {
|
|
4839
|
+
...readOptions,
|
|
4840
|
+
serialization: _nullishCoalesce(options.serialization, () => ( _optionalChain([readOptions, 'optionalAccess', _103 => _103.serialization])))
|
|
4841
|
+
});
|
|
4753
4842
|
},
|
|
4754
|
-
appendToStream: async (streamName, events,
|
|
4843
|
+
appendToStream: async (streamName, events, appendOptions) => {
|
|
4755
4844
|
await ensureSchemaExists();
|
|
4756
4845
|
const [firstPart, ...rest] = streamName.split("-");
|
|
4757
4846
|
const streamType = firstPart && rest.length > 0 ? firstPart : unknownTag2;
|
|
@@ -4760,9 +4849,9 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
|
|
|
4760
4849
|
pool,
|
|
4761
4850
|
streamName,
|
|
4762
4851
|
streamType,
|
|
4763
|
-
downcastRecordedMessages(events, _optionalChain([
|
|
4852
|
+
downcastRecordedMessages(events, _optionalChain([appendOptions, 'optionalAccess', _104 => _104.schema, 'optionalAccess', _105 => _105.versioning])),
|
|
4764
4853
|
{
|
|
4765
|
-
...
|
|
4854
|
+
...appendOptions,
|
|
4766
4855
|
beforeCommitHook
|
|
4767
4856
|
}
|
|
4768
4857
|
);
|
|
@@ -4770,7 +4859,7 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
|
|
|
4770
4859
|
throw new ExpectedVersionConflictError(
|
|
4771
4860
|
-1n,
|
|
4772
4861
|
//TODO: Return actual version in case of error
|
|
4773
|
-
_nullishCoalesce(_optionalChain([
|
|
4862
|
+
_nullishCoalesce(_optionalChain([appendOptions, 'optionalAccess', _106 => _106.expectedStreamVersion]), () => ( NO_CONCURRENCY_CHECK))
|
|
4774
4863
|
);
|
|
4775
4864
|
return {
|
|
4776
4865
|
nextExpectedStreamVersion: appendResult.nextStreamPosition,
|
|
@@ -4819,7 +4908,7 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
|
|
|
4819
4908
|
var postgreSQLCheckpointer = () => ({
|
|
4820
4909
|
read: async (options, context) => {
|
|
4821
4910
|
const result = await readProcessorCheckpoint(context.execute, options);
|
|
4822
|
-
return { lastCheckpoint: _optionalChain([result, 'optionalAccess',
|
|
4911
|
+
return { lastCheckpoint: _optionalChain([result, 'optionalAccess', _107 => _107.lastProcessedCheckpoint]) };
|
|
4823
4912
|
},
|
|
4824
4913
|
store: async (options, context) => {
|
|
4825
4914
|
const newCheckpoint = getCheckpoint(options.message);
|
|
@@ -4837,13 +4926,13 @@ var postgreSQLProcessingScope = (options) => {
|
|
|
4837
4926
|
const processorConnectionString = options.connectionString;
|
|
4838
4927
|
const processorPool = options.pool;
|
|
4839
4928
|
const processingScope = async (handler, partialContext) => {
|
|
4840
|
-
const connection = _optionalChain([partialContext, 'optionalAccess',
|
|
4841
|
-
const connectionString = _nullishCoalesce(processorConnectionString, () => ( _optionalChain([connection, 'optionalAccess',
|
|
4929
|
+
const connection = _optionalChain([partialContext, 'optionalAccess', _108 => _108.connection]);
|
|
4930
|
+
const connectionString = _nullishCoalesce(processorConnectionString, () => ( _optionalChain([connection, 'optionalAccess', _109 => _109.connectionString])));
|
|
4842
4931
|
if (!connectionString)
|
|
4843
4932
|
throw new EmmettError(
|
|
4844
4933
|
`PostgreSQL processor '${options.processorId}' is missing connection string. Ensure that you passed it through options`
|
|
4845
4934
|
);
|
|
4846
|
-
const pool = _nullishCoalesce((!processorConnectionString || connectionString == processorConnectionString ? _optionalChain([connection, 'optionalAccess',
|
|
4935
|
+
const pool = _nullishCoalesce((!processorConnectionString || connectionString == processorConnectionString ? _optionalChain([connection, 'optionalAccess', _110 => _110.pool]) : processorPool), () => ( processorPool));
|
|
4847
4936
|
if (!pool)
|
|
4848
4937
|
throw new EmmettError(
|
|
4849
4938
|
`PostgreSQL processor '${options.processorId}' is missing connection string. Ensure that you passed it through options`
|
|
@@ -4875,7 +4964,8 @@ var getProcessorPool = (options) => {
|
|
|
4875
4964
|
const processorConnectionString = "connectionString" in poolOptions ? _nullishCoalesce(poolOptions.connectionString, () => ( null)) : null;
|
|
4876
4965
|
const processorPool = "dumbo" in poolOptions ? poolOptions.dumbo : processorConnectionString ? _dumbo.dumbo.call(void 0, {
|
|
4877
4966
|
connectionString: processorConnectionString,
|
|
4878
|
-
...poolOptions
|
|
4967
|
+
...poolOptions,
|
|
4968
|
+
serialization: options.serialization
|
|
4879
4969
|
}) : null;
|
|
4880
4970
|
return {
|
|
4881
4971
|
pool: processorPool,
|
|
@@ -4887,11 +4977,11 @@ var wrapHooksWithProcessorLocks = (hooks, processorLock) => ({
|
|
|
4887
4977
|
..._nullishCoalesce(hooks, () => ( {})),
|
|
4888
4978
|
onStart: async (context) => {
|
|
4889
4979
|
await processorLock.tryAcquire({ execute: context.execute });
|
|
4890
|
-
if (_optionalChain([hooks, 'optionalAccess',
|
|
4980
|
+
if (_optionalChain([hooks, 'optionalAccess', _111 => _111.onStart])) await hooks.onStart(context);
|
|
4891
4981
|
},
|
|
4892
|
-
onClose: _optionalChain([hooks, 'optionalAccess',
|
|
4982
|
+
onClose: _optionalChain([hooks, 'optionalAccess', _112 => _112.onClose]) || processorLock ? async (context) => {
|
|
4893
4983
|
await processorLock.release({ execute: context.execute });
|
|
4894
|
-
if (_optionalChain([hooks, 'optionalAccess',
|
|
4984
|
+
if (_optionalChain([hooks, 'optionalAccess', _113 => _113.onClose])) await hooks.onClose(context);
|
|
4895
4985
|
} : void 0
|
|
4896
4986
|
});
|
|
4897
4987
|
var postgreSQLProjector = (options) => {
|
|
@@ -4916,13 +5006,13 @@ var postgreSQLProjector = (options) => {
|
|
|
4916
5006
|
version: _nullishCoalesce(options.projection.version, () => ( version)),
|
|
4917
5007
|
handlingType: "async"
|
|
4918
5008
|
} : void 0,
|
|
4919
|
-
lockAcquisitionPolicy: _nullishCoalesce(_optionalChain([lock, 'optionalAccess',
|
|
4920
|
-
lockTimeoutSeconds: _optionalChain([lock, 'optionalAccess',
|
|
5009
|
+
lockAcquisitionPolicy: _nullishCoalesce(_optionalChain([lock, 'optionalAccess', _114 => _114.acquisitionPolicy]), () => ( DefaultPostgreSQLProcessorLockPolicy)),
|
|
5010
|
+
lockTimeoutSeconds: _optionalChain([lock, 'optionalAccess', _115 => _115.timeoutSeconds])
|
|
4921
5011
|
});
|
|
4922
5012
|
const hooks = wrapHooksWithProcessorLocks(
|
|
4923
5013
|
{
|
|
4924
5014
|
..._nullishCoalesce(options.hooks, () => ( {})),
|
|
4925
|
-
onInit: options.projection.init !== void 0 || _optionalChain([options, 'access',
|
|
5015
|
+
onInit: options.projection.init !== void 0 || _optionalChain([options, 'access', _116 => _116.hooks, 'optionalAccess', _117 => _117.onInit]) ? async (context) => {
|
|
4926
5016
|
if (options.projection.init)
|
|
4927
5017
|
await options.projection.init({
|
|
4928
5018
|
version: _nullishCoalesce(options.projection.version, () => ( version)),
|
|
@@ -4933,16 +5023,16 @@ var postgreSQLProjector = (options) => {
|
|
|
4933
5023
|
migrationOptions: options.migrationOptions
|
|
4934
5024
|
}
|
|
4935
5025
|
});
|
|
4936
|
-
if (_optionalChain([options, 'access',
|
|
5026
|
+
if (_optionalChain([options, 'access', _118 => _118.hooks, 'optionalAccess', _119 => _119.onInit]))
|
|
4937
5027
|
await options.hooks.onInit({
|
|
4938
5028
|
...context,
|
|
4939
5029
|
migrationOptions: options.migrationOptions
|
|
4940
5030
|
});
|
|
4941
|
-
} : _optionalChain([options, 'access',
|
|
5031
|
+
} : _optionalChain([options, 'access', _120 => _120.hooks, 'optionalAccess', _121 => _121.onInit]),
|
|
4942
5032
|
onClose: close ? async (context) => {
|
|
4943
|
-
if (_optionalChain([options, 'access',
|
|
5033
|
+
if (_optionalChain([options, 'access', _122 => _122.hooks, 'optionalAccess', _123 => _123.onClose])) await _optionalChain([options, 'access', _124 => _124.hooks, 'optionalAccess', _125 => _125.onClose, 'call', _126 => _126(context)]);
|
|
4944
5034
|
if (close) await close();
|
|
4945
|
-
} : _optionalChain([options, 'access',
|
|
5035
|
+
} : _optionalChain([options, 'access', _127 => _127.hooks, 'optionalAccess', _128 => _128.onClose])
|
|
4946
5036
|
},
|
|
4947
5037
|
processorLock
|
|
4948
5038
|
);
|
|
@@ -4980,17 +5070,17 @@ var postgreSQLWorkflowProcessor = (options) => {
|
|
|
4980
5070
|
partition,
|
|
4981
5071
|
processorInstanceId,
|
|
4982
5072
|
projection: void 0,
|
|
4983
|
-
lockAcquisitionPolicy: _nullishCoalesce(_optionalChain([lock, 'optionalAccess',
|
|
4984
|
-
lockTimeoutSeconds: _optionalChain([lock, 'optionalAccess',
|
|
5073
|
+
lockAcquisitionPolicy: _nullishCoalesce(_optionalChain([lock, 'optionalAccess', _129 => _129.acquisitionPolicy]), () => ( DefaultPostgreSQLProcessorLockPolicy)),
|
|
5074
|
+
lockTimeoutSeconds: _optionalChain([lock, 'optionalAccess', _130 => _130.timeoutSeconds])
|
|
4985
5075
|
});
|
|
4986
5076
|
const hooks = wrapHooksWithProcessorLocks(
|
|
4987
5077
|
{
|
|
4988
5078
|
..._nullishCoalesce(options.hooks, () => ( {})),
|
|
4989
5079
|
onClose: close ? async (context) => {
|
|
4990
|
-
if (_optionalChain([options, 'access',
|
|
4991
|
-
await _optionalChain([options, 'access',
|
|
5080
|
+
if (_optionalChain([options, 'access', _131 => _131.hooks, 'optionalAccess', _132 => _132.onClose]))
|
|
5081
|
+
await _optionalChain([options, 'access', _133 => _133.hooks, 'optionalAccess', _134 => _134.onClose, 'call', _135 => _135(context)]);
|
|
4992
5082
|
if (close) await close();
|
|
4993
|
-
} : _optionalChain([options, 'access',
|
|
5083
|
+
} : _optionalChain([options, 'access', _136 => _136.hooks, 'optionalAccess', _137 => _137.onClose])
|
|
4994
5084
|
},
|
|
4995
5085
|
processorLock
|
|
4996
5086
|
);
|
|
@@ -5025,16 +5115,16 @@ var postgreSQLReactor = (options) => {
|
|
|
5025
5115
|
partition,
|
|
5026
5116
|
processorInstanceId,
|
|
5027
5117
|
projection: void 0,
|
|
5028
|
-
lockAcquisitionPolicy: _nullishCoalesce(_optionalChain([lock, 'optionalAccess',
|
|
5029
|
-
lockTimeoutSeconds: _optionalChain([lock, 'optionalAccess',
|
|
5118
|
+
lockAcquisitionPolicy: _nullishCoalesce(_optionalChain([lock, 'optionalAccess', _138 => _138.acquisitionPolicy]), () => ( DefaultPostgreSQLProcessorLockPolicy)),
|
|
5119
|
+
lockTimeoutSeconds: _optionalChain([lock, 'optionalAccess', _139 => _139.timeoutSeconds])
|
|
5030
5120
|
});
|
|
5031
5121
|
const hooks = wrapHooksWithProcessorLocks(
|
|
5032
5122
|
{
|
|
5033
5123
|
..._nullishCoalesce(options.hooks, () => ( {})),
|
|
5034
5124
|
onClose: close ? async (context) => {
|
|
5035
|
-
if (_optionalChain([options, 'access',
|
|
5125
|
+
if (_optionalChain([options, 'access', _140 => _140.hooks, 'optionalAccess', _141 => _141.onClose])) await _optionalChain([options, 'access', _142 => _142.hooks, 'optionalAccess', _143 => _143.onClose, 'call', _144 => _144(context)]);
|
|
5036
5126
|
if (close) await close();
|
|
5037
|
-
} : _optionalChain([options, 'access',
|
|
5127
|
+
} : _optionalChain([options, 'access', _145 => _145.hooks, 'optionalAccess', _146 => _146.onClose])
|
|
5038
5128
|
},
|
|
5039
5129
|
processorLock
|
|
5040
5130
|
);
|
|
@@ -5064,7 +5154,10 @@ var postgreSQLEventStoreConsumer = (options) => {
|
|
|
5064
5154
|
let abortController = null;
|
|
5065
5155
|
let start;
|
|
5066
5156
|
let messagePuller;
|
|
5067
|
-
const pool = options.pool ? options.pool : _dumbo.dumbo.call(void 0, {
|
|
5157
|
+
const pool = options.pool ? options.pool : _dumbo.dumbo.call(void 0, {
|
|
5158
|
+
connectionString: options.connectionString,
|
|
5159
|
+
serialization: options.serialization
|
|
5160
|
+
});
|
|
5068
5161
|
const eachBatch = async (messagesBatch) => {
|
|
5069
5162
|
const activeProcessors = processors.filter((s) => s.isActive);
|
|
5070
5163
|
if (activeProcessors.length === 0)
|
|
@@ -5083,7 +5176,7 @@ var postgreSQLEventStoreConsumer = (options) => {
|
|
|
5083
5176
|
})
|
|
5084
5177
|
);
|
|
5085
5178
|
return result.some(
|
|
5086
|
-
(r) => r.status === "fulfilled" && _optionalChain([r, 'access',
|
|
5179
|
+
(r) => r.status === "fulfilled" && _optionalChain([r, 'access', _147 => _147.value, 'optionalAccess', _148 => _148.type]) !== "STOP"
|
|
5087
5180
|
) ? void 0 : {
|
|
5088
5181
|
type: "STOP"
|
|
5089
5182
|
};
|
|
@@ -5103,7 +5196,7 @@ var postgreSQLEventStoreConsumer = (options) => {
|
|
|
5103
5196
|
if (!isRunning) return;
|
|
5104
5197
|
isRunning = false;
|
|
5105
5198
|
if (messagePuller) {
|
|
5106
|
-
_optionalChain([abortController, 'optionalAccess',
|
|
5199
|
+
_optionalChain([abortController, 'optionalAccess', _149 => _149.abort, 'call', _150 => _150()]);
|
|
5107
5200
|
await messagePuller.stop();
|
|
5108
5201
|
}
|
|
5109
5202
|
await start;
|
|
@@ -5164,8 +5257,8 @@ var postgreSQLEventStoreConsumer = (options) => {
|
|
|
5164
5257
|
stopWhen: options.stopWhen,
|
|
5165
5258
|
executor: pool.execute,
|
|
5166
5259
|
eachBatch,
|
|
5167
|
-
batchSize: _nullishCoalesce(_optionalChain([pulling, 'optionalAccess',
|
|
5168
|
-
pullingFrequencyInMs: _nullishCoalesce(_optionalChain([pulling, 'optionalAccess',
|
|
5260
|
+
batchSize: _nullishCoalesce(_optionalChain([pulling, 'optionalAccess', _151 => _151.batchSize]), () => ( DefaultPostgreSQLEventStoreProcessorBatchSize)),
|
|
5261
|
+
pullingFrequencyInMs: _nullishCoalesce(_optionalChain([pulling, 'optionalAccess', _152 => _152.pullingFrequencyInMs]), () => ( DefaultPostgreSQLEventStoreProcessorPullingFrequencyInMs)),
|
|
5169
5262
|
signal: abortController.signal
|
|
5170
5263
|
});
|
|
5171
5264
|
start = (async () => {
|