@event-driven-io/emmett-postgresql 0.43.0-alpha.1 → 0.43.0-alpha.3
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 +141 -146
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +125 -130
- package/dist/index.js.map +1 -1
- package/package.json +4 -7
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;// src/eventStore/
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;// src/eventStore/schema/readLastMessageGlobalPosition.ts
|
|
2
2
|
var _dumbo = require('@event-driven-io/dumbo');
|
|
3
3
|
|
|
4
|
-
// src/eventStore/schema/readLastMessageGlobalPosition.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
4
|
// src/eventStore/schema/typing.ts
|
|
8
5
|
var emmettPrefix = "emt";
|
|
9
6
|
var globalTag = "global";
|
|
@@ -58,6 +55,122 @@ var readLastMessageGlobalPosition = async (execute, options) => {
|
|
|
58
55
|
|
|
59
56
|
// src/eventStore/schema/readMessagesBatch.ts
|
|
60
57
|
|
|
58
|
+
var readMessagesBatch = async (execute, options) => {
|
|
59
|
+
const from = "from" in options ? options.from : "after" in options ? options.after + 1n : 0n;
|
|
60
|
+
const batchSize = options && "batchSize" in options ? options.batchSize : options.to - options.from;
|
|
61
|
+
const fromCondition = from !== -0n ? `AND global_position >= ${from}` : "";
|
|
62
|
+
const toCondition = "to" in options ? `AND global_position <= ${options.to}` : "";
|
|
63
|
+
const limitCondition = "batchSize" in options ? `LIMIT ${options.batchSize}` : "";
|
|
64
|
+
const messages = await _dumbo.mapRows.call(void 0,
|
|
65
|
+
execute.query(
|
|
66
|
+
_dumbo.SQL`
|
|
67
|
+
SELECT stream_id, stream_position, global_position, message_data, message_metadata, message_schema_version, message_type, message_id
|
|
68
|
+
FROM ${_dumbo.SQL.identifier(messagesTable.name)}
|
|
69
|
+
WHERE partition = ${_nullishCoalesce(_optionalChain([options, 'optionalAccess', _3 => _3.partition]), () => ( defaultTag))} AND is_archived = FALSE AND transaction_id < pg_snapshot_xmin(pg_current_snapshot()) ${_dumbo.SQL.plain(fromCondition)} ${_dumbo.SQL.plain(toCondition)}
|
|
70
|
+
ORDER BY transaction_id, global_position
|
|
71
|
+
${_dumbo.SQL.plain(limitCondition)}`
|
|
72
|
+
),
|
|
73
|
+
(row) => {
|
|
74
|
+
const rawEvent = {
|
|
75
|
+
type: row.message_type,
|
|
76
|
+
data: row.message_data,
|
|
77
|
+
metadata: row.message_metadata
|
|
78
|
+
};
|
|
79
|
+
const metadata = {
|
|
80
|
+
..."metadata" in rawEvent ? _nullishCoalesce(rawEvent.metadata, () => ( {})) : {},
|
|
81
|
+
messageId: row.message_id,
|
|
82
|
+
streamName: row.stream_id,
|
|
83
|
+
streamPosition: BigInt(row.stream_position),
|
|
84
|
+
globalPosition: BigInt(row.global_position)
|
|
85
|
+
};
|
|
86
|
+
return {
|
|
87
|
+
...rawEvent,
|
|
88
|
+
kind: "Event",
|
|
89
|
+
metadata
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
);
|
|
93
|
+
return messages.length > 0 ? {
|
|
94
|
+
currentGlobalPosition: messages[messages.length - 1].metadata.globalPosition,
|
|
95
|
+
messages,
|
|
96
|
+
areMessagesLeft: messages.length === batchSize
|
|
97
|
+
} : {
|
|
98
|
+
currentGlobalPosition: "from" in options ? options.from : "after" in options ? options.after : 0n,
|
|
99
|
+
messages: [],
|
|
100
|
+
areMessagesLeft: false
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
// src/eventStore/consumers/messageBatchProcessing/index.ts
|
|
105
|
+
var DefaultPostgreSQLEventStoreProcessorBatchSize = 100;
|
|
106
|
+
var DefaultPostgreSQLEventStoreProcessorPullingFrequencyInMs = 50;
|
|
107
|
+
var postgreSQLEventStoreMessageBatchPuller = ({
|
|
108
|
+
executor,
|
|
109
|
+
batchSize,
|
|
110
|
+
eachBatch,
|
|
111
|
+
pullingFrequencyInMs,
|
|
112
|
+
stopWhen,
|
|
113
|
+
signal
|
|
114
|
+
}) => {
|
|
115
|
+
let isRunning = false;
|
|
116
|
+
let start;
|
|
117
|
+
const pullMessages = async (options) => {
|
|
118
|
+
const after = options.startFrom === "BEGINNING" ? 0n : options.startFrom === "END" ? await _asyncNullishCoalesce((await readLastMessageGlobalPosition(executor)).currentGlobalPosition, async () => ( 0n)) : options.startFrom.lastCheckpoint;
|
|
119
|
+
const readMessagesOptions = {
|
|
120
|
+
after,
|
|
121
|
+
batchSize
|
|
122
|
+
};
|
|
123
|
+
let waitTime = 100;
|
|
124
|
+
while (isRunning && !_optionalChain([signal, 'optionalAccess', _4 => _4.aborted])) {
|
|
125
|
+
const { messages, currentGlobalPosition, areMessagesLeft } = await readMessagesBatch(executor, readMessagesOptions);
|
|
126
|
+
if (messages.length > 0) {
|
|
127
|
+
const result = await eachBatch(messages);
|
|
128
|
+
if (result && result.type === "STOP") {
|
|
129
|
+
isRunning = false;
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
readMessagesOptions.after = currentGlobalPosition;
|
|
134
|
+
await new Promise((resolve) => setTimeout(resolve, waitTime));
|
|
135
|
+
if (_optionalChain([stopWhen, 'optionalAccess', _5 => _5.noMessagesLeft]) === true && !areMessagesLeft) {
|
|
136
|
+
isRunning = false;
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
if (!areMessagesLeft) {
|
|
140
|
+
waitTime = Math.min(waitTime * 2, 1e3);
|
|
141
|
+
} else {
|
|
142
|
+
waitTime = pullingFrequencyInMs;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
return {
|
|
147
|
+
get isRunning() {
|
|
148
|
+
return isRunning;
|
|
149
|
+
},
|
|
150
|
+
start: (options) => {
|
|
151
|
+
if (isRunning) return start;
|
|
152
|
+
isRunning = true;
|
|
153
|
+
start = (async () => {
|
|
154
|
+
return pullMessages(options);
|
|
155
|
+
})();
|
|
156
|
+
return start;
|
|
157
|
+
},
|
|
158
|
+
stop: async () => {
|
|
159
|
+
if (!isRunning) return;
|
|
160
|
+
isRunning = false;
|
|
161
|
+
await start;
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
var zipPostgreSQLEventStoreMessageBatchPullerStartFrom = (options) => {
|
|
166
|
+
if (options.length === 0 || options.some((o) => o === void 0 || o === "BEGINNING"))
|
|
167
|
+
return "BEGINNING";
|
|
168
|
+
if (options.every((o) => o === "END")) return "END";
|
|
169
|
+
return options.filter((o) => o !== void 0 && o !== "BEGINNING" && o !== "END").sort((a, b) => a > b ? 1 : -1)[0];
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
// src/eventStore/consumers/postgreSQLEventStoreConsumer.ts
|
|
173
|
+
|
|
61
174
|
|
|
62
175
|
// ../emmett/dist/chunk-AZDDB5SF.js
|
|
63
176
|
var isNumber = (val) => typeof val === "number" && val === val;
|
|
@@ -100,7 +213,7 @@ var ConcurrencyError = class _ConcurrencyError extends EmmettError {
|
|
|
100
213
|
constructor(current, expected, message) {
|
|
101
214
|
super({
|
|
102
215
|
errorCode: EmmettError.Codes.ConcurrencyError,
|
|
103
|
-
message: _nullishCoalesce(message, () => ( `Expected version ${expected.toString()} does not match current ${_optionalChain([current, 'optionalAccess',
|
|
216
|
+
message: _nullishCoalesce(message, () => ( `Expected version ${expected.toString()} does not match current ${_optionalChain([current, 'optionalAccess', _6 => _6.toString, 'call', _7 => _7()])}`))
|
|
104
217
|
});
|
|
105
218
|
this.current = current;
|
|
106
219
|
this.expected = expected;
|
|
@@ -133,7 +246,7 @@ var assertExpectedVersionMatchesCurrent = (current, expected, defaultVersion) =>
|
|
|
133
246
|
};
|
|
134
247
|
var ExpectedVersionConflictError = class _ExpectedVersionConflictError extends ConcurrencyError {
|
|
135
248
|
constructor(current, expected) {
|
|
136
|
-
super(_optionalChain([current, 'optionalAccess',
|
|
249
|
+
super(_optionalChain([current, 'optionalAccess', _8 => _8.toString, 'call', _9 => _9()]), _optionalChain([expected, 'optionalAccess', _10 => _10.toString, 'call', _11 => _11()]));
|
|
137
250
|
Object.setPrototypeOf(this, _ExpectedVersionConflictError.prototype);
|
|
138
251
|
}
|
|
139
252
|
};
|
|
@@ -350,17 +463,17 @@ var ParseError = class extends Error {
|
|
|
350
463
|
var JSONParser = {
|
|
351
464
|
stringify: (value, options) => {
|
|
352
465
|
return JSON.stringify(
|
|
353
|
-
_optionalChain([options, 'optionalAccess',
|
|
466
|
+
_optionalChain([options, 'optionalAccess', _12 => _12.map]) ? options.map(value) : value,
|
|
354
467
|
//TODO: Consider adding support to DateTime and adding specific format to mark that's a bigint
|
|
355
468
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
356
469
|
(_, v) => typeof v === "bigint" ? v.toString() : v
|
|
357
470
|
);
|
|
358
471
|
},
|
|
359
472
|
parse: (text, options) => {
|
|
360
|
-
const parsed = JSON.parse(text, _optionalChain([options, 'optionalAccess',
|
|
361
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
473
|
+
const parsed = JSON.parse(text, _optionalChain([options, 'optionalAccess', _13 => _13.reviver]));
|
|
474
|
+
if (_optionalChain([options, 'optionalAccess', _14 => _14.typeCheck]) && !_optionalChain([options, 'optionalAccess', _15 => _15.typeCheck, 'call', _16 => _16(parsed)]))
|
|
362
475
|
throw new ParseError(text);
|
|
363
|
-
return _optionalChain([options, 'optionalAccess',
|
|
476
|
+
return _optionalChain([options, 'optionalAccess', _17 => _17.map]) ? options.map(parsed) : parsed;
|
|
364
477
|
}
|
|
365
478
|
};
|
|
366
479
|
var asyncRetry = async (fn, opts) => {
|
|
@@ -369,14 +482,14 @@ var asyncRetry = async (fn, opts) => {
|
|
|
369
482
|
async (bail) => {
|
|
370
483
|
try {
|
|
371
484
|
const result = await fn();
|
|
372
|
-
if (_optionalChain([opts, 'optionalAccess',
|
|
485
|
+
if (_optionalChain([opts, 'optionalAccess', _18 => _18.shouldRetryResult]) && opts.shouldRetryResult(result)) {
|
|
373
486
|
throw new EmmettError(
|
|
374
487
|
`Retrying because of result: ${JSONParser.stringify(result)}`
|
|
375
488
|
);
|
|
376
489
|
}
|
|
377
490
|
return result;
|
|
378
491
|
} catch (error2) {
|
|
379
|
-
if (_optionalChain([opts, 'optionalAccess',
|
|
492
|
+
if (_optionalChain([opts, 'optionalAccess', _19 => _19.shouldRetryError]) && !opts.shouldRetryError(error2)) {
|
|
380
493
|
bail(error2);
|
|
381
494
|
return void 0;
|
|
382
495
|
}
|
|
@@ -537,7 +650,7 @@ var assertThatArray = (array) => {
|
|
|
537
650
|
};
|
|
538
651
|
};
|
|
539
652
|
var downcastRecordedMessage = (recordedMessage, options) => {
|
|
540
|
-
if (!_optionalChain([options, 'optionalAccess',
|
|
653
|
+
if (!_optionalChain([options, 'optionalAccess', _20 => _20.downcast]))
|
|
541
654
|
return recordedMessage;
|
|
542
655
|
const downcasted = options.downcast(
|
|
543
656
|
recordedMessage
|
|
@@ -555,14 +668,14 @@ var downcastRecordedMessage = (recordedMessage, options) => {
|
|
|
555
668
|
};
|
|
556
669
|
};
|
|
557
670
|
var downcastRecordedMessages = (recordedMessages, options) => {
|
|
558
|
-
if (!_optionalChain([options, 'optionalAccess',
|
|
671
|
+
if (!_optionalChain([options, 'optionalAccess', _21 => _21.downcast]))
|
|
559
672
|
return recordedMessages;
|
|
560
673
|
return recordedMessages.map(
|
|
561
674
|
(recordedMessage) => downcastRecordedMessage(recordedMessage, options)
|
|
562
675
|
);
|
|
563
676
|
};
|
|
564
677
|
var upcastRecordedMessage = (recordedMessage, options) => {
|
|
565
|
-
if (!_optionalChain([options, 'optionalAccess',
|
|
678
|
+
if (!_optionalChain([options, 'optionalAccess', _22 => _22.upcast]))
|
|
566
679
|
return recordedMessage;
|
|
567
680
|
const upcasted = options.upcast(
|
|
568
681
|
recordedMessage
|
|
@@ -668,7 +781,7 @@ var reactor = (options) => {
|
|
|
668
781
|
}
|
|
669
782
|
if (startFrom && startFrom !== "CURRENT") return startFrom;
|
|
670
783
|
if (checkpoints) {
|
|
671
|
-
const readResult = await _optionalChain([checkpoints, 'optionalAccess',
|
|
784
|
+
const readResult = await _optionalChain([checkpoints, 'optionalAccess', _23 => _23.read, 'call', _24 => _24(
|
|
672
785
|
{
|
|
673
786
|
processorId,
|
|
674
787
|
partition
|
|
@@ -696,7 +809,7 @@ var reactor = (options) => {
|
|
|
696
809
|
const upcasted = upcastRecordedMessage(
|
|
697
810
|
// TODO: Make it smarter
|
|
698
811
|
message2,
|
|
699
|
-
_optionalChain([options, 'access',
|
|
812
|
+
_optionalChain([options, 'access', _25 => _25.messageOptions, 'optionalAccess', _26 => _26.schema, 'optionalAccess', _27 => _27.versioning])
|
|
700
813
|
);
|
|
701
814
|
if (canHandle !== void 0 && !canHandle.includes(upcasted.type))
|
|
702
815
|
continue;
|
|
@@ -749,142 +862,24 @@ var projector = (options) => {
|
|
|
749
862
|
processorId,
|
|
750
863
|
messageOptions: options.projection.eventsOptions,
|
|
751
864
|
hooks: {
|
|
752
|
-
onInit: _optionalChain([options, 'access',
|
|
753
|
-
onStart: options.truncateOnStart && options.projection.truncate || _optionalChain([options, 'access',
|
|
865
|
+
onInit: _optionalChain([options, 'access', _28 => _28.hooks, 'optionalAccess', _29 => _29.onInit]),
|
|
866
|
+
onStart: options.truncateOnStart && options.projection.truncate || _optionalChain([options, 'access', _30 => _30.hooks, 'optionalAccess', _31 => _31.onStart]) ? async (context) => {
|
|
754
867
|
if (options.truncateOnStart && options.projection.truncate)
|
|
755
868
|
await options.projection.truncate(context);
|
|
756
|
-
if (_optionalChain([options, 'access',
|
|
869
|
+
if (_optionalChain([options, 'access', _32 => _32.hooks, 'optionalAccess', _33 => _33.onStart])) await _optionalChain([options, 'access', _34 => _34.hooks, 'optionalAccess', _35 => _35.onStart, 'call', _36 => _36(context)]);
|
|
757
870
|
} : void 0,
|
|
758
|
-
onClose: _optionalChain([options, 'access',
|
|
871
|
+
onClose: _optionalChain([options, 'access', _37 => _37.hooks, 'optionalAccess', _38 => _38.onClose])
|
|
759
872
|
},
|
|
760
873
|
eachMessage: async (event2, context) => projection2.handle([event2], context)
|
|
761
874
|
});
|
|
762
875
|
};
|
|
763
876
|
var projection = (definition) => definition;
|
|
764
877
|
|
|
765
|
-
// src/eventStore/schema/readMessagesBatch.ts
|
|
766
|
-
var readMessagesBatch = async (execute, options) => {
|
|
767
|
-
const from = "from" in options ? options.from : "after" in options ? options.after + 1n : 0n;
|
|
768
|
-
const batchSize = options && "batchSize" in options ? options.batchSize : options.to - options.from;
|
|
769
|
-
const fromCondition = from !== -0n ? `AND global_position >= ${from}` : "";
|
|
770
|
-
const toCondition = "to" in options ? `AND global_position <= ${options.to}` : "";
|
|
771
|
-
const limitCondition = "batchSize" in options ? `LIMIT ${options.batchSize}` : "";
|
|
772
|
-
const messages = await _dumbo.mapRows.call(void 0,
|
|
773
|
-
execute.query(
|
|
774
|
-
_dumbo.SQL`
|
|
775
|
-
SELECT stream_id, stream_position, global_position, message_data, message_metadata, message_schema_version, message_type, message_id
|
|
776
|
-
FROM ${_dumbo.SQL.identifier(messagesTable.name)}
|
|
777
|
-
WHERE partition = ${_nullishCoalesce(_optionalChain([options, 'optionalAccess', _36 => _36.partition]), () => ( defaultTag))} AND is_archived = FALSE AND transaction_id < pg_snapshot_xmin(pg_current_snapshot()) ${_dumbo.SQL.plain(fromCondition)} ${_dumbo.SQL.plain(toCondition)}
|
|
778
|
-
ORDER BY transaction_id, global_position
|
|
779
|
-
${_dumbo.SQL.plain(limitCondition)}`
|
|
780
|
-
),
|
|
781
|
-
(row) => {
|
|
782
|
-
const rawEvent = {
|
|
783
|
-
type: row.message_type,
|
|
784
|
-
data: row.message_data,
|
|
785
|
-
metadata: row.message_metadata
|
|
786
|
-
};
|
|
787
|
-
const metadata = {
|
|
788
|
-
..."metadata" in rawEvent ? _nullishCoalesce(rawEvent.metadata, () => ( {})) : {},
|
|
789
|
-
messageId: row.message_id,
|
|
790
|
-
streamName: row.stream_id,
|
|
791
|
-
streamPosition: BigInt(row.stream_position),
|
|
792
|
-
globalPosition: BigInt(row.global_position)
|
|
793
|
-
};
|
|
794
|
-
return {
|
|
795
|
-
...rawEvent,
|
|
796
|
-
kind: "Event",
|
|
797
|
-
metadata
|
|
798
|
-
};
|
|
799
|
-
}
|
|
800
|
-
);
|
|
801
|
-
return messages.length > 0 ? {
|
|
802
|
-
currentGlobalPosition: messages[messages.length - 1].metadata.globalPosition,
|
|
803
|
-
messages,
|
|
804
|
-
areMessagesLeft: messages.length === batchSize
|
|
805
|
-
} : {
|
|
806
|
-
currentGlobalPosition: "from" in options ? options.from : "after" in options ? options.after : 0n,
|
|
807
|
-
messages: [],
|
|
808
|
-
areMessagesLeft: false
|
|
809
|
-
};
|
|
810
|
-
};
|
|
811
|
-
|
|
812
|
-
// src/eventStore/consumers/messageBatchProcessing/index.ts
|
|
813
|
-
var DefaultPostgreSQLEventStoreProcessorBatchSize = 100;
|
|
814
|
-
var DefaultPostgreSQLEventStoreProcessorPullingFrequencyInMs = 50;
|
|
815
|
-
var postgreSQLEventStoreMessageBatchPuller = ({
|
|
816
|
-
executor,
|
|
817
|
-
batchSize,
|
|
818
|
-
eachBatch,
|
|
819
|
-
pullingFrequencyInMs,
|
|
820
|
-
stopWhen,
|
|
821
|
-
signal
|
|
822
|
-
}) => {
|
|
823
|
-
let isRunning = false;
|
|
824
|
-
let start;
|
|
825
|
-
const pullMessages = async (options) => {
|
|
826
|
-
const after = options.startFrom === "BEGINNING" ? 0n : options.startFrom === "END" ? await _asyncNullishCoalesce((await readLastMessageGlobalPosition(executor)).currentGlobalPosition, async () => ( 0n)) : options.startFrom.lastCheckpoint;
|
|
827
|
-
const readMessagesOptions = {
|
|
828
|
-
after,
|
|
829
|
-
batchSize
|
|
830
|
-
};
|
|
831
|
-
let waitTime = 100;
|
|
832
|
-
while (isRunning && !_optionalChain([signal, 'optionalAccess', _37 => _37.aborted])) {
|
|
833
|
-
const { messages, currentGlobalPosition, areMessagesLeft } = await readMessagesBatch(executor, readMessagesOptions);
|
|
834
|
-
if (messages.length > 0) {
|
|
835
|
-
const result = await eachBatch(messages);
|
|
836
|
-
if (result && result.type === "STOP") {
|
|
837
|
-
isRunning = false;
|
|
838
|
-
break;
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
readMessagesOptions.after = currentGlobalPosition;
|
|
842
|
-
await new Promise((resolve) => setTimeout(resolve, waitTime));
|
|
843
|
-
if (_optionalChain([stopWhen, 'optionalAccess', _38 => _38.noMessagesLeft]) === true && !areMessagesLeft) {
|
|
844
|
-
isRunning = false;
|
|
845
|
-
break;
|
|
846
|
-
}
|
|
847
|
-
if (!areMessagesLeft) {
|
|
848
|
-
waitTime = Math.min(waitTime * 2, 1e3);
|
|
849
|
-
} else {
|
|
850
|
-
waitTime = pullingFrequencyInMs;
|
|
851
|
-
}
|
|
852
|
-
}
|
|
853
|
-
};
|
|
854
|
-
return {
|
|
855
|
-
get isRunning() {
|
|
856
|
-
return isRunning;
|
|
857
|
-
},
|
|
858
|
-
start: (options) => {
|
|
859
|
-
if (isRunning) return start;
|
|
860
|
-
isRunning = true;
|
|
861
|
-
start = (async () => {
|
|
862
|
-
return pullMessages(options);
|
|
863
|
-
})();
|
|
864
|
-
return start;
|
|
865
|
-
},
|
|
866
|
-
stop: async () => {
|
|
867
|
-
if (!isRunning) return;
|
|
868
|
-
isRunning = false;
|
|
869
|
-
await start;
|
|
870
|
-
}
|
|
871
|
-
};
|
|
872
|
-
};
|
|
873
|
-
var zipPostgreSQLEventStoreMessageBatchPullerStartFrom = (options) => {
|
|
874
|
-
if (options.length === 0 || options.some((o) => o === void 0 || o === "BEGINNING"))
|
|
875
|
-
return "BEGINNING";
|
|
876
|
-
if (options.every((o) => o === "END")) return "END";
|
|
877
|
-
return options.filter((o) => o !== void 0 && o !== "BEGINNING" && o !== "END").sort((a, b) => a > b ? 1 : -1)[0];
|
|
878
|
-
};
|
|
879
|
-
|
|
880
878
|
// src/eventStore/consumers/postgreSQLEventStoreConsumer.ts
|
|
881
879
|
|
|
882
880
|
|
|
883
|
-
|
|
884
881
|
// src/eventStore/consumers/postgreSQLProcessor.ts
|
|
885
882
|
|
|
886
|
-
require('@event-driven-io/dumbo/pg');
|
|
887
|
-
require('pg');
|
|
888
883
|
|
|
889
884
|
// src/eventStore/projections/locks/tryAcquireProcessorLock.ts
|
|
890
885
|
|
|
@@ -1579,7 +1574,6 @@ var pongoSingleStreamProjection = (options) => {
|
|
|
1579
1574
|
|
|
1580
1575
|
|
|
1581
1576
|
|
|
1582
|
-
|
|
1583
1577
|
var withCollection = (handle, options) => {
|
|
1584
1578
|
const { pool, connectionString, inDatabase, inCollection } = options;
|
|
1585
1579
|
return pool.withConnection(async (connection) => {
|
|
@@ -1719,7 +1713,6 @@ var expectPongoDocuments = {
|
|
|
1719
1713
|
|
|
1720
1714
|
|
|
1721
1715
|
|
|
1722
|
-
|
|
1723
1716
|
// src/eventStore/postgreSQLEventStore.ts
|
|
1724
1717
|
|
|
1725
1718
|
|
|
@@ -1728,8 +1721,6 @@ var expectPongoDocuments = {
|
|
|
1728
1721
|
|
|
1729
1722
|
|
|
1730
1723
|
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
1724
|
// src/eventStore/schema/index.ts
|
|
1734
1725
|
|
|
1735
1726
|
|
|
@@ -1741,6 +1732,10 @@ var expectPongoDocuments = {
|
|
|
1741
1732
|
|
|
1742
1733
|
|
|
1743
1734
|
|
|
1735
|
+
|
|
1736
|
+
|
|
1737
|
+
|
|
1738
|
+
|
|
1744
1739
|
var appendToStreamSQL = createFunctionIfDoesNotExistSQL(
|
|
1745
1740
|
"emt_append_to_stream",
|
|
1746
1741
|
_dumbo.SQL`CREATE OR REPLACE FUNCTION emt_append_to_stream(
|
|
@@ -1919,7 +1914,9 @@ var toExpectedVersion = (expected) => {
|
|
|
1919
1914
|
if (expected == STREAM_EXISTS) return null;
|
|
1920
1915
|
return expected;
|
|
1921
1916
|
};
|
|
1922
|
-
var isOptimisticConcurrencyError = (error) => error
|
|
1917
|
+
var isOptimisticConcurrencyError = (error) => _dumbo.DumboError.isInstanceOf(error, {
|
|
1918
|
+
errorType: _dumbo.UniqueConstraintError.ErrorType
|
|
1919
|
+
});
|
|
1923
1920
|
var appendEventsRaw = (execute, streamId, streamType, messages, options) => _dumbo.single.call(void 0,
|
|
1924
1921
|
execute.command(
|
|
1925
1922
|
callAppendToStream({
|
|
@@ -4467,8 +4464,6 @@ var expectSQL = {
|
|
|
4467
4464
|
};
|
|
4468
4465
|
|
|
4469
4466
|
// src/eventStore/projections/postgreSQLProjection.ts
|
|
4470
|
-
|
|
4471
|
-
|
|
4472
4467
|
var transactionToPostgreSQLProjectionHandlerContext = async (connectionString, pool, transaction) => ({
|
|
4473
4468
|
execute: transaction.execute,
|
|
4474
4469
|
connection: {
|