@event-driven-io/emmett-postgresql 0.35.0 → 0.37.0
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 +385 -208
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +144 -181
- package/dist/index.d.ts +144 -181
- package/dist/index.js +369 -192
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -139,22 +139,6 @@ var deepEquals = (left, right) => {
|
|
|
139
139
|
var isEquatable = (left) => {
|
|
140
140
|
return left && typeof left === "object" && "equals" in left && typeof left["equals"] === "function";
|
|
141
141
|
};
|
|
142
|
-
var asyncRetry = async (fn, opts) => {
|
|
143
|
-
if (opts === void 0 || opts.retries === 0) return fn();
|
|
144
|
-
return _asyncretry2.default.call(void 0,
|
|
145
|
-
async (bail) => {
|
|
146
|
-
try {
|
|
147
|
-
return await fn();
|
|
148
|
-
} catch (error2) {
|
|
149
|
-
if (_optionalChain([opts, 'optionalAccess', _10 => _10.shouldRetryError]) && !opts.shouldRetryError(error2)) {
|
|
150
|
-
bail(error2);
|
|
151
|
-
}
|
|
152
|
-
throw error2;
|
|
153
|
-
}
|
|
154
|
-
},
|
|
155
|
-
_nullishCoalesce(opts, () => ( { retries: 0 }))
|
|
156
|
-
);
|
|
157
|
-
};
|
|
158
142
|
var ParseError = class extends Error {
|
|
159
143
|
constructor(text) {
|
|
160
144
|
super(`Cannot parse! ${text}`);
|
|
@@ -163,19 +147,143 @@ var ParseError = class extends Error {
|
|
|
163
147
|
var JSONParser = {
|
|
164
148
|
stringify: (value, options) => {
|
|
165
149
|
return JSON.stringify(
|
|
166
|
-
_optionalChain([options, 'optionalAccess',
|
|
150
|
+
_optionalChain([options, 'optionalAccess', _10 => _10.map]) ? options.map(value) : value,
|
|
167
151
|
//TODO: Consider adding support to DateTime and adding specific format to mark that's a bigint
|
|
168
152
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
169
153
|
(_, v) => typeof v === "bigint" ? v.toString() : v
|
|
170
154
|
);
|
|
171
155
|
},
|
|
172
156
|
parse: (text, options) => {
|
|
173
|
-
const parsed = JSON.parse(text, _optionalChain([options, 'optionalAccess',
|
|
174
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
157
|
+
const parsed = JSON.parse(text, _optionalChain([options, 'optionalAccess', _11 => _11.reviver]));
|
|
158
|
+
if (_optionalChain([options, 'optionalAccess', _12 => _12.typeCheck]) && !_optionalChain([options, 'optionalAccess', _13 => _13.typeCheck, 'call', _14 => _14(parsed)]))
|
|
175
159
|
throw new ParseError(text);
|
|
176
|
-
return _optionalChain([options, 'optionalAccess',
|
|
160
|
+
return _optionalChain([options, 'optionalAccess', _15 => _15.map]) ? options.map(parsed) : parsed;
|
|
177
161
|
}
|
|
178
162
|
};
|
|
163
|
+
var asyncRetry = async (fn, opts) => {
|
|
164
|
+
if (opts === void 0 || opts.retries === 0) return fn();
|
|
165
|
+
return _asyncretry2.default.call(void 0,
|
|
166
|
+
async (bail) => {
|
|
167
|
+
try {
|
|
168
|
+
const result = await fn();
|
|
169
|
+
if (_optionalChain([opts, 'optionalAccess', _16 => _16.shouldRetryResult]) && opts.shouldRetryResult(result)) {
|
|
170
|
+
throw new EmmettError(
|
|
171
|
+
`Retrying because of result: ${JSONParser.stringify(result)}`
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
return result;
|
|
175
|
+
} catch (error2) {
|
|
176
|
+
if (_optionalChain([opts, 'optionalAccess', _17 => _17.shouldRetryError]) && !opts.shouldRetryError(error2)) {
|
|
177
|
+
bail(error2);
|
|
178
|
+
}
|
|
179
|
+
throw error2;
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
_nullishCoalesce(opts, () => ( { retries: 0 }))
|
|
183
|
+
);
|
|
184
|
+
};
|
|
185
|
+
var MessageProcessorType = {
|
|
186
|
+
PROJECTOR: "projector",
|
|
187
|
+
REACTOR: "reactor"
|
|
188
|
+
};
|
|
189
|
+
var defaultProcessingMessageProcessingScope = (handler, partialContext) => handler(partialContext);
|
|
190
|
+
var reactor = (options) => {
|
|
191
|
+
const eachMessage = "eachMessage" in options && options.eachMessage ? options.eachMessage : () => Promise.resolve();
|
|
192
|
+
let isActive = true;
|
|
193
|
+
const { checkpoints, processorId, partition } = options;
|
|
194
|
+
const processingScope = _nullishCoalesce(options.processingScope, () => ( defaultProcessingMessageProcessingScope));
|
|
195
|
+
return {
|
|
196
|
+
id: options.processorId,
|
|
197
|
+
type: _nullishCoalesce(options.type, () => ( MessageProcessorType.REACTOR)),
|
|
198
|
+
close: () => _optionalChain([options, 'access', _18 => _18.hooks, 'optionalAccess', _19 => _19.onClose]) ? _optionalChain([options, 'access', _20 => _20.hooks, 'optionalAccess', _21 => _21.onClose, 'call', _22 => _22()]) : Promise.resolve(),
|
|
199
|
+
start: async (startOptions) => {
|
|
200
|
+
isActive = true;
|
|
201
|
+
return await processingScope(async (context) => {
|
|
202
|
+
if (_optionalChain([options, 'access', _23 => _23.hooks, 'optionalAccess', _24 => _24.onStart])) {
|
|
203
|
+
await _optionalChain([options, 'access', _25 => _25.hooks, 'optionalAccess', _26 => _26.onStart, 'call', _27 => _27(context)]);
|
|
204
|
+
}
|
|
205
|
+
if (options.startFrom !== "CURRENT" && options.startFrom)
|
|
206
|
+
return options.startFrom;
|
|
207
|
+
let lastCheckpoint = null;
|
|
208
|
+
if (checkpoints) {
|
|
209
|
+
const readResult = await _optionalChain([checkpoints, 'optionalAccess', _28 => _28.read, 'call', _29 => _29(
|
|
210
|
+
{
|
|
211
|
+
processorId,
|
|
212
|
+
partition
|
|
213
|
+
},
|
|
214
|
+
startOptions
|
|
215
|
+
)]);
|
|
216
|
+
lastCheckpoint = readResult.lastCheckpoint;
|
|
217
|
+
}
|
|
218
|
+
if (lastCheckpoint === null) return "BEGINNING";
|
|
219
|
+
return {
|
|
220
|
+
lastCheckpoint
|
|
221
|
+
};
|
|
222
|
+
}, startOptions);
|
|
223
|
+
},
|
|
224
|
+
get isActive() {
|
|
225
|
+
return isActive;
|
|
226
|
+
},
|
|
227
|
+
handle: async (messages, partialContext) => {
|
|
228
|
+
if (!isActive) return Promise.resolve();
|
|
229
|
+
return await processingScope(async (context) => {
|
|
230
|
+
let result = void 0;
|
|
231
|
+
let lastCheckpoint = null;
|
|
232
|
+
for (const message2 of messages) {
|
|
233
|
+
const messageProcessingResult = await eachMessage(message2, context);
|
|
234
|
+
if (checkpoints) {
|
|
235
|
+
const storeCheckpointResult = await checkpoints.store(
|
|
236
|
+
{
|
|
237
|
+
processorId: options.processorId,
|
|
238
|
+
version: options.version,
|
|
239
|
+
message: message2,
|
|
240
|
+
lastCheckpoint,
|
|
241
|
+
partition: options.partition
|
|
242
|
+
},
|
|
243
|
+
context
|
|
244
|
+
);
|
|
245
|
+
if (storeCheckpointResult && storeCheckpointResult.success) {
|
|
246
|
+
lastCheckpoint = storeCheckpointResult.newCheckpoint;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
if (messageProcessingResult && messageProcessingResult.type === "STOP") {
|
|
250
|
+
isActive = false;
|
|
251
|
+
result = messageProcessingResult;
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
if (options.stopAfter && options.stopAfter(message2)) {
|
|
255
|
+
isActive = false;
|
|
256
|
+
result = { type: "STOP", reason: "Stop condition reached" };
|
|
257
|
+
break;
|
|
258
|
+
}
|
|
259
|
+
if (messageProcessingResult && messageProcessingResult.type === "SKIP")
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
return result;
|
|
263
|
+
}, partialContext);
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
};
|
|
267
|
+
var projector = (options) => {
|
|
268
|
+
const { projection: projection2, ...rest } = options;
|
|
269
|
+
return reactor({
|
|
270
|
+
...rest,
|
|
271
|
+
type: MessageProcessorType.PROJECTOR,
|
|
272
|
+
processorId: _nullishCoalesce(options.processorId, () => ( `projection:${projection2.name}`)),
|
|
273
|
+
hooks: {
|
|
274
|
+
onStart: options.truncateOnStart && options.projection.truncate || _optionalChain([options, 'access', _30 => _30.hooks, 'optionalAccess', _31 => _31.onStart]) ? async (context) => {
|
|
275
|
+
if (options.truncateOnStart && options.projection.truncate)
|
|
276
|
+
await options.projection.truncate(context);
|
|
277
|
+
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)]);
|
|
278
|
+
} : void 0,
|
|
279
|
+
onClose: _optionalChain([options, 'access', _37 => _37.hooks, 'optionalAccess', _38 => _38.onClose])
|
|
280
|
+
},
|
|
281
|
+
eachMessage: async (event2, context) => {
|
|
282
|
+
if (!projection2.canHandle.includes(event2.type)) return;
|
|
283
|
+
await projection2.handle([event2], context);
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
};
|
|
179
287
|
var projection = (definition) => definition;
|
|
180
288
|
var filter = (filter2) => new (0, _webstreamspolyfill.TransformStream)({
|
|
181
289
|
transform(chunk, controller) {
|
|
@@ -485,7 +593,7 @@ var readLastMessageGlobalPosition = async (execute, options) => {
|
|
|
485
593
|
WHERE partition = %L AND is_archived = FALSE AND transaction_id < pg_snapshot_xmin(pg_current_snapshot())
|
|
486
594
|
ORDER BY transaction_id, global_position
|
|
487
595
|
LIMIT 1`,
|
|
488
|
-
_nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
596
|
+
_nullishCoalesce(_optionalChain([options, 'optionalAccess', _39 => _39.partition]), () => ( defaultTag))
|
|
489
597
|
)
|
|
490
598
|
)
|
|
491
599
|
);
|
|
@@ -502,7 +610,7 @@ var readMessagesBatch = async (execute, options) => {
|
|
|
502
610
|
const fromCondition = from !== -0n ? `AND global_position >= ${from}` : "";
|
|
503
611
|
const toCondition = "to" in options ? `AND global_position <= ${options.to}` : "";
|
|
504
612
|
const limitCondition = "batchSize" in options ? `LIMIT ${options.batchSize}` : "";
|
|
505
|
-
const
|
|
613
|
+
const messages = await _dumbo.mapRows.call(void 0,
|
|
506
614
|
execute.query(
|
|
507
615
|
_dumbo.sql.call(void 0,
|
|
508
616
|
`SELECT stream_id, stream_position, global_position, message_data, message_metadata, message_schema_version, message_type, message_id
|
|
@@ -510,7 +618,7 @@ var readMessagesBatch = async (execute, options) => {
|
|
|
510
618
|
WHERE partition = %L AND is_archived = FALSE AND transaction_id < pg_snapshot_xmin(pg_current_snapshot()) ${fromCondition} ${toCondition}
|
|
511
619
|
ORDER BY transaction_id, global_position
|
|
512
620
|
${limitCondition}`,
|
|
513
|
-
_nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
621
|
+
_nullishCoalesce(_optionalChain([options, 'optionalAccess', _40 => _40.partition]), () => ( defaultTag))
|
|
514
622
|
)
|
|
515
623
|
),
|
|
516
624
|
(row) => {
|
|
@@ -533,14 +641,14 @@ var readMessagesBatch = async (execute, options) => {
|
|
|
533
641
|
};
|
|
534
642
|
}
|
|
535
643
|
);
|
|
536
|
-
return
|
|
537
|
-
currentGlobalPosition:
|
|
538
|
-
messages
|
|
539
|
-
|
|
644
|
+
return messages.length > 0 ? {
|
|
645
|
+
currentGlobalPosition: messages[messages.length - 1].metadata.globalPosition,
|
|
646
|
+
messages,
|
|
647
|
+
areMessagesLeft: messages.length === batchSize
|
|
540
648
|
} : {
|
|
541
649
|
currentGlobalPosition: "from" in options ? options.from : "after" in options ? options.after : 0n,
|
|
542
650
|
messages: [],
|
|
543
|
-
|
|
651
|
+
areMessagesLeft: false
|
|
544
652
|
};
|
|
545
653
|
};
|
|
546
654
|
|
|
@@ -551,21 +659,22 @@ var postgreSQLEventStoreMessageBatchPuller = ({
|
|
|
551
659
|
executor,
|
|
552
660
|
batchSize,
|
|
553
661
|
eachBatch,
|
|
554
|
-
pullingFrequencyInMs
|
|
662
|
+
pullingFrequencyInMs,
|
|
663
|
+
stopWhen
|
|
555
664
|
}) => {
|
|
556
665
|
let isRunning = false;
|
|
557
666
|
let start;
|
|
558
667
|
const pullMessages = async (options) => {
|
|
559
|
-
const after = options.startFrom === "BEGINNING" ? 0n : options.startFrom === "END" ? await _asyncNullishCoalesce((await readLastMessageGlobalPosition(executor)).currentGlobalPosition, async () => ( 0n)) : options.startFrom.
|
|
668
|
+
const after = options.startFrom === "BEGINNING" ? 0n : options.startFrom === "END" ? await _asyncNullishCoalesce((await readLastMessageGlobalPosition(executor)).currentGlobalPosition, async () => ( 0n)) : options.startFrom.lastCheckpoint;
|
|
560
669
|
const readMessagesOptions = {
|
|
561
670
|
after,
|
|
562
671
|
batchSize
|
|
563
672
|
};
|
|
564
673
|
let waitTime = 100;
|
|
565
674
|
do {
|
|
566
|
-
const { messages, currentGlobalPosition,
|
|
675
|
+
const { messages, currentGlobalPosition, areMessagesLeft } = await readMessagesBatch(executor, readMessagesOptions);
|
|
567
676
|
if (messages.length > 0) {
|
|
568
|
-
const result = await eachBatch(
|
|
677
|
+
const result = await eachBatch(messages);
|
|
569
678
|
if (result && result.type === "STOP") {
|
|
570
679
|
isRunning = false;
|
|
571
680
|
break;
|
|
@@ -573,7 +682,11 @@ var postgreSQLEventStoreMessageBatchPuller = ({
|
|
|
573
682
|
}
|
|
574
683
|
readMessagesOptions.after = currentGlobalPosition;
|
|
575
684
|
await new Promise((resolve) => setTimeout(resolve, waitTime));
|
|
576
|
-
if (!
|
|
685
|
+
if (_optionalChain([stopWhen, 'optionalAccess', _41 => _41.noMessagesLeft]) === true && !areMessagesLeft) {
|
|
686
|
+
isRunning = false;
|
|
687
|
+
break;
|
|
688
|
+
}
|
|
689
|
+
if (!areMessagesLeft) {
|
|
577
690
|
waitTime = Math.min(waitTime * 2, 1e3);
|
|
578
691
|
} else {
|
|
579
692
|
waitTime = pullingFrequencyInMs;
|
|
@@ -609,6 +722,7 @@ var zipPostgreSQLEventStoreMessageBatchPullerStartFrom = (options) => {
|
|
|
609
722
|
// src/eventStore/consumers/postgreSQLEventStoreConsumer.ts
|
|
610
723
|
|
|
611
724
|
|
|
725
|
+
|
|
612
726
|
// src/eventStore/consumers/postgreSQLProcessor.ts
|
|
613
727
|
|
|
614
728
|
|
|
@@ -719,7 +833,7 @@ var appendToStream = (pool, streamName, streamType, messages, options) => pool.w
|
|
|
719
833
|
let appendResult;
|
|
720
834
|
try {
|
|
721
835
|
const expectedStreamVersion = toExpectedVersion(
|
|
722
|
-
_optionalChain([options, 'optionalAccess',
|
|
836
|
+
_optionalChain([options, 'optionalAccess', _42 => _42.expectedStreamVersion])
|
|
723
837
|
);
|
|
724
838
|
const messagesToAppend = messages.map((e, i) => ({
|
|
725
839
|
...e,
|
|
@@ -740,7 +854,7 @@ var appendToStream = (pool, streamName, streamType, messages, options) => pool.w
|
|
|
740
854
|
expectedStreamVersion
|
|
741
855
|
}
|
|
742
856
|
);
|
|
743
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
857
|
+
if (_optionalChain([options, 'optionalAccess', _43 => _43.beforeCommitHook]))
|
|
744
858
|
await options.beforeCommitHook(messagesToAppend, { transaction });
|
|
745
859
|
} catch (error) {
|
|
746
860
|
if (!isOptimisticConcurrencyError(error)) throw error;
|
|
@@ -798,8 +912,8 @@ var appendEventsRaw = (execute, streamId, streamType, messages, options) => _dum
|
|
|
798
912
|
messages.map((e) => _dumbo.sql.call(void 0, "%L", e.kind === "Event" ? "E" : "C")).join(","),
|
|
799
913
|
streamId,
|
|
800
914
|
streamType,
|
|
801
|
-
_nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
802
|
-
_nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
915
|
+
_nullishCoalesce(_optionalChain([options, 'optionalAccess', _44 => _44.expectedStreamVersion]), () => ( "NULL")),
|
|
916
|
+
_nullishCoalesce(_optionalChain([options, 'optionalAccess', _45 => _45.partition]), () => ( defaultTag))
|
|
803
917
|
)
|
|
804
918
|
)
|
|
805
919
|
);
|
|
@@ -866,7 +980,7 @@ BEGIN
|
|
|
866
980
|
END;
|
|
867
981
|
$$ LANGUAGE plpgsql;
|
|
868
982
|
`);
|
|
869
|
-
async
|
|
983
|
+
var storeProcessorCheckpoint = async (execute, options) => {
|
|
870
984
|
try {
|
|
871
985
|
const { result } = await _dumbo.single.call(void 0,
|
|
872
986
|
execute.command(
|
|
@@ -885,7 +999,7 @@ async function storeProcessorCheckpoint(execute, options) {
|
|
|
885
999
|
console.log(error);
|
|
886
1000
|
throw error;
|
|
887
1001
|
}
|
|
888
|
-
}
|
|
1002
|
+
};
|
|
889
1003
|
|
|
890
1004
|
// src/eventStore/schema/tables.ts
|
|
891
1005
|
|
|
@@ -1243,7 +1357,7 @@ var readProcessorCheckpoint = async (execute, options) => {
|
|
|
1243
1357
|
FROM ${subscriptionsTable.name}
|
|
1244
1358
|
WHERE partition = %L AND subscription_id = %L
|
|
1245
1359
|
LIMIT 1`,
|
|
1246
|
-
_nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
1360
|
+
_nullishCoalesce(_optionalChain([options, 'optionalAccess', _46 => _46.partition]), () => ( defaultTag)),
|
|
1247
1361
|
options.processorId
|
|
1248
1362
|
)
|
|
1249
1363
|
)
|
|
@@ -1268,7 +1382,7 @@ var readStream = async (execute, streamId, options) => {
|
|
|
1268
1382
|
FROM ${messagesTable.name}
|
|
1269
1383
|
WHERE stream_id = %L AND partition = %L AND is_archived = FALSE ${fromCondition} ${toCondition}`,
|
|
1270
1384
|
streamId,
|
|
1271
|
-
_nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
1385
|
+
_nullishCoalesce(_optionalChain([options, 'optionalAccess', _47 => _47.partition]), () => ( defaultTag))
|
|
1272
1386
|
)
|
|
1273
1387
|
),
|
|
1274
1388
|
(row) => {
|
|
@@ -1324,120 +1438,114 @@ var createEventStoreSchema = async (pool) => {
|
|
|
1324
1438
|
};
|
|
1325
1439
|
|
|
1326
1440
|
// src/eventStore/consumers/postgreSQLProcessor.ts
|
|
1327
|
-
var
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1441
|
+
var postgreSQLCheckpointer = () => ({
|
|
1442
|
+
read: async (options, context) => {
|
|
1443
|
+
const result = await readProcessorCheckpoint(context.execute, options);
|
|
1444
|
+
return { lastCheckpoint: _optionalChain([result, 'optionalAccess', _48 => _48.lastProcessedPosition]) };
|
|
1445
|
+
},
|
|
1446
|
+
store: async (options, context) => {
|
|
1447
|
+
const result = await storeProcessorCheckpoint(context.execute, {
|
|
1448
|
+
lastProcessedPosition: options.lastCheckpoint,
|
|
1449
|
+
newPosition: options.message.metadata.globalPosition,
|
|
1450
|
+
processorId: options.processorId,
|
|
1451
|
+
partition: options.partition,
|
|
1452
|
+
version: options.version
|
|
1453
|
+
});
|
|
1454
|
+
return result.success ? { success: true, newCheckpoint: result.newPosition } : result;
|
|
1337
1455
|
}
|
|
1338
|
-
};
|
|
1339
|
-
var
|
|
1340
|
-
const
|
|
1341
|
-
|
|
1342
|
-
const
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
const processorConnectionString = "connectionString" in poolOptions ? poolOptions.connectionString : null;
|
|
1346
|
-
const processorPool = "dumbo" in poolOptions ? poolOptions.dumbo : processorConnectionString ? _dumbo.dumbo.call(void 0, {
|
|
1347
|
-
connectionString: processorConnectionString,
|
|
1348
|
-
...poolOptions
|
|
1349
|
-
}) : null;
|
|
1350
|
-
const getPool = (context) => {
|
|
1351
|
-
const connectionString = _nullishCoalesce(processorConnectionString, () => ( context.connectionString));
|
|
1456
|
+
});
|
|
1457
|
+
var postgreSQLProcessingScope = (options) => {
|
|
1458
|
+
const processorConnectionString = options.connectionString;
|
|
1459
|
+
const processorPool = options.pool;
|
|
1460
|
+
const processingScope = async (handler, partialContext) => {
|
|
1461
|
+
const connection = _optionalChain([partialContext, 'optionalAccess', _49 => _49.connection]);
|
|
1462
|
+
const connectionString = _nullishCoalesce(processorConnectionString, () => ( _optionalChain([connection, 'optionalAccess', _50 => _50.connectionString])));
|
|
1352
1463
|
if (!connectionString)
|
|
1353
1464
|
throw new EmmettError(
|
|
1354
1465
|
`PostgreSQL processor '${options.processorId}' is missing connection string. Ensure that you passed it through options`
|
|
1355
1466
|
);
|
|
1356
|
-
const pool = _nullishCoalesce((!processorConnectionString || connectionString == processorConnectionString ? _optionalChain([
|
|
1467
|
+
const pool = _nullishCoalesce((!processorConnectionString || connectionString == processorConnectionString ? _optionalChain([connection, 'optionalAccess', _51 => _51.pool]) : processorPool), () => ( processorPool));
|
|
1357
1468
|
if (!pool)
|
|
1358
1469
|
throw new EmmettError(
|
|
1359
1470
|
`PostgreSQL processor '${options.processorId}' is missing connection string. Ensure that you passed it through options`
|
|
1360
1471
|
);
|
|
1361
|
-
return {
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
if (options.startFrom !== "CURRENT") return options.startFrom;
|
|
1371
|
-
const { lastProcessedPosition } = await readProcessorCheckpoint(execute, {
|
|
1372
|
-
processorId: options.processorId,
|
|
1373
|
-
partition: options.partition
|
|
1374
|
-
});
|
|
1375
|
-
if (lastProcessedPosition === null) return "BEGINNING";
|
|
1376
|
-
return { globalPosition: lastProcessedPosition };
|
|
1377
|
-
},
|
|
1378
|
-
get isActive() {
|
|
1379
|
-
return isActive;
|
|
1380
|
-
},
|
|
1381
|
-
handle: async ({ messages }, context) => {
|
|
1382
|
-
if (!isActive) return;
|
|
1383
|
-
const { pool, connectionString } = getPool(context);
|
|
1384
|
-
return pool.withTransaction(async (transaction) => {
|
|
1385
|
-
let result = void 0;
|
|
1386
|
-
let lastProcessedPosition = null;
|
|
1387
|
-
for (const message of messages) {
|
|
1388
|
-
const typedMessage = message;
|
|
1389
|
-
const client = await transaction.connection.open();
|
|
1390
|
-
const messageProcessingResult = await eachMessage(typedMessage, {
|
|
1391
|
-
execute: transaction.execute,
|
|
1392
|
-
connection: {
|
|
1393
|
-
connectionString,
|
|
1394
|
-
pool,
|
|
1395
|
-
transaction,
|
|
1396
|
-
client
|
|
1397
|
-
}
|
|
1398
|
-
});
|
|
1399
|
-
await storeProcessorCheckpoint(transaction.execute, {
|
|
1400
|
-
processorId: options.processorId,
|
|
1401
|
-
version: options.version,
|
|
1402
|
-
lastProcessedPosition,
|
|
1403
|
-
newPosition: typedMessage.metadata.globalPosition,
|
|
1404
|
-
partition: options.partition
|
|
1405
|
-
});
|
|
1406
|
-
lastProcessedPosition = typedMessage.metadata.globalPosition;
|
|
1407
|
-
if (messageProcessingResult && messageProcessingResult.type === "STOP") {
|
|
1408
|
-
isActive = false;
|
|
1409
|
-
result = messageProcessingResult;
|
|
1410
|
-
break;
|
|
1411
|
-
}
|
|
1412
|
-
if (options.stopAfter && options.stopAfter(typedMessage)) {
|
|
1413
|
-
isActive = false;
|
|
1414
|
-
result = { type: "STOP", reason: "Stop condition reached" };
|
|
1415
|
-
break;
|
|
1416
|
-
}
|
|
1417
|
-
if (messageProcessingResult && messageProcessingResult.type === "SKIP")
|
|
1418
|
-
continue;
|
|
1472
|
+
return pool.withTransaction(async (transaction) => {
|
|
1473
|
+
const client = await transaction.connection.open();
|
|
1474
|
+
return handler({
|
|
1475
|
+
execute: transaction.execute,
|
|
1476
|
+
connection: {
|
|
1477
|
+
connectionString,
|
|
1478
|
+
pool,
|
|
1479
|
+
client,
|
|
1480
|
+
transaction
|
|
1419
1481
|
}
|
|
1420
|
-
return result;
|
|
1421
1482
|
});
|
|
1422
|
-
}
|
|
1483
|
+
});
|
|
1423
1484
|
};
|
|
1485
|
+
return processingScope;
|
|
1424
1486
|
};
|
|
1425
|
-
var
|
|
1426
|
-
const
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1487
|
+
var getProcessorPool = (options) => {
|
|
1488
|
+
const poolOptions = {
|
|
1489
|
+
...options.connectionOptions ? options.connectionOptions : {}
|
|
1490
|
+
};
|
|
1491
|
+
const processorConnectionString = "connectionString" in poolOptions ? _nullishCoalesce(poolOptions.connectionString, () => ( null)) : null;
|
|
1492
|
+
const processorPool = "dumbo" in poolOptions ? poolOptions.dumbo : processorConnectionString ? _dumbo.dumbo.call(void 0, {
|
|
1493
|
+
connectionString: processorConnectionString,
|
|
1494
|
+
...poolOptions
|
|
1495
|
+
}) : null;
|
|
1496
|
+
return {
|
|
1497
|
+
pool: processorPool,
|
|
1498
|
+
connectionString: processorConnectionString,
|
|
1499
|
+
close: processorPool != null && !("dumbo" in poolOptions) ? processorPool.close : void 0
|
|
1500
|
+
};
|
|
1501
|
+
};
|
|
1502
|
+
var postgreSQLProjector = (options) => {
|
|
1503
|
+
const { pool, connectionString, close } = getProcessorPool(options);
|
|
1504
|
+
const hooks = {
|
|
1505
|
+
onStart: _optionalChain([options, 'access', _52 => _52.hooks, 'optionalAccess', _53 => _53.onStart]),
|
|
1506
|
+
onClose: _optionalChain([options, 'access', _54 => _54.hooks, 'optionalAccess', _55 => _55.onClose]) || close ? async () => {
|
|
1507
|
+
if (_optionalChain([options, 'access', _56 => _56.hooks, 'optionalAccess', _57 => _57.onClose])) await _optionalChain([options, 'access', _58 => _58.hooks, 'optionalAccess', _59 => _59.onClose, 'call', _60 => _60()]);
|
|
1508
|
+
if (close) await close();
|
|
1509
|
+
} : void 0
|
|
1510
|
+
};
|
|
1511
|
+
return projector({
|
|
1512
|
+
...options,
|
|
1513
|
+
hooks,
|
|
1514
|
+
processingScope: postgreSQLProcessingScope({
|
|
1515
|
+
pool,
|
|
1516
|
+
connectionString,
|
|
1517
|
+
processorId: _nullishCoalesce(options.processorId, () => ( `projection:${options.projection.name}`))
|
|
1518
|
+
}),
|
|
1519
|
+
checkpoints: postgreSQLCheckpointer()
|
|
1434
1520
|
});
|
|
1435
1521
|
};
|
|
1436
|
-
var
|
|
1522
|
+
var postgreSQLReactor = (options) => {
|
|
1523
|
+
const { pool, connectionString, close } = getProcessorPool(options);
|
|
1524
|
+
const hooks = {
|
|
1525
|
+
onStart: _optionalChain([options, 'access', _61 => _61.hooks, 'optionalAccess', _62 => _62.onStart]),
|
|
1526
|
+
onClose: _optionalChain([options, 'access', _63 => _63.hooks, 'optionalAccess', _64 => _64.onClose]) || close ? async () => {
|
|
1527
|
+
if (_optionalChain([options, 'access', _65 => _65.hooks, 'optionalAccess', _66 => _66.onClose])) await _optionalChain([options, 'access', _67 => _67.hooks, 'optionalAccess', _68 => _68.onClose, 'call', _69 => _69()]);
|
|
1528
|
+
if (close) await close();
|
|
1529
|
+
} : void 0
|
|
1530
|
+
};
|
|
1531
|
+
return reactor({
|
|
1532
|
+
...options,
|
|
1533
|
+
hooks,
|
|
1534
|
+
processingScope: postgreSQLProcessingScope({
|
|
1535
|
+
pool,
|
|
1536
|
+
connectionString,
|
|
1537
|
+
processorId: options.processorId
|
|
1538
|
+
}),
|
|
1539
|
+
checkpoints: postgreSQLCheckpointer()
|
|
1540
|
+
});
|
|
1541
|
+
};
|
|
1542
|
+
var postgreSQLMessageProcessor = (options) => {
|
|
1437
1543
|
if ("projection" in options) {
|
|
1438
|
-
return
|
|
1544
|
+
return postgreSQLProjector(
|
|
1545
|
+
options
|
|
1546
|
+
);
|
|
1439
1547
|
}
|
|
1440
|
-
return
|
|
1548
|
+
return postgreSQLReactor(options);
|
|
1441
1549
|
};
|
|
1442
1550
|
|
|
1443
1551
|
// src/eventStore/consumers/postgreSQLEventStoreConsumer.ts
|
|
@@ -1458,22 +1566,25 @@ var postgreSQLEventStoreConsumer = (options) => {
|
|
|
1458
1566
|
const result = await Promise.allSettled(
|
|
1459
1567
|
activeProcessors.map((s) => {
|
|
1460
1568
|
return s.handle(messagesBatch, {
|
|
1461
|
-
|
|
1462
|
-
|
|
1569
|
+
connection: {
|
|
1570
|
+
connectionString: options.connectionString,
|
|
1571
|
+
pool
|
|
1572
|
+
}
|
|
1463
1573
|
});
|
|
1464
1574
|
})
|
|
1465
1575
|
);
|
|
1466
1576
|
return result.some(
|
|
1467
|
-
(r) => r.status === "fulfilled" && _optionalChain([r, 'access',
|
|
1577
|
+
(r) => r.status === "fulfilled" && _optionalChain([r, 'access', _70 => _70.value, 'optionalAccess', _71 => _71.type]) !== "STOP"
|
|
1468
1578
|
) ? void 0 : {
|
|
1469
1579
|
type: "STOP"
|
|
1470
1580
|
};
|
|
1471
1581
|
};
|
|
1472
1582
|
const messagePooler = currentMessagePuller = postgreSQLEventStoreMessageBatchPuller({
|
|
1583
|
+
stopWhen: options.stopWhen,
|
|
1473
1584
|
executor: pool.execute,
|
|
1474
1585
|
eachBatch,
|
|
1475
|
-
batchSize: _nullishCoalesce(_optionalChain([pulling, 'optionalAccess',
|
|
1476
|
-
pullingFrequencyInMs: _nullishCoalesce(_optionalChain([pulling, 'optionalAccess',
|
|
1586
|
+
batchSize: _nullishCoalesce(_optionalChain([pulling, 'optionalAccess', _72 => _72.batchSize]), () => ( DefaultPostgreSQLEventStoreProcessorBatchSize)),
|
|
1587
|
+
pullingFrequencyInMs: _nullishCoalesce(_optionalChain([pulling, 'optionalAccess', _73 => _73.pullingFrequencyInMs]), () => ( DefaultPostgreSQLEventStoreProcessorPullingFrequencyInMs))
|
|
1477
1588
|
});
|
|
1478
1589
|
const stop = async () => {
|
|
1479
1590
|
if (!isRunning) return;
|
|
@@ -1483,15 +1594,20 @@ var postgreSQLEventStoreConsumer = (options) => {
|
|
|
1483
1594
|
currentMessagePuller = void 0;
|
|
1484
1595
|
}
|
|
1485
1596
|
await start;
|
|
1597
|
+
await Promise.all(processors.map((p) => p.close()));
|
|
1486
1598
|
};
|
|
1487
1599
|
return {
|
|
1488
|
-
|
|
1600
|
+
consumerId: _nullishCoalesce(options.consumerId, () => ( _uuid.v7.call(void 0, ))),
|
|
1489
1601
|
get isRunning() {
|
|
1490
1602
|
return isRunning;
|
|
1491
1603
|
},
|
|
1604
|
+
processors,
|
|
1492
1605
|
processor: (options2) => {
|
|
1493
|
-
const processor =
|
|
1494
|
-
processors.push(
|
|
1606
|
+
const processor = postgreSQLMessageProcessor(options2);
|
|
1607
|
+
processors.push(
|
|
1608
|
+
// TODO: change that
|
|
1609
|
+
processor
|
|
1610
|
+
);
|
|
1495
1611
|
return processor;
|
|
1496
1612
|
},
|
|
1497
1613
|
start: () => {
|
|
@@ -1505,7 +1621,18 @@ var postgreSQLEventStoreConsumer = (options) => {
|
|
|
1505
1621
|
);
|
|
1506
1622
|
isRunning = true;
|
|
1507
1623
|
const startFrom = zipPostgreSQLEventStoreMessageBatchPullerStartFrom(
|
|
1508
|
-
await Promise.all(
|
|
1624
|
+
await Promise.all(
|
|
1625
|
+
processors.map(async (o) => {
|
|
1626
|
+
const result = await o.start({
|
|
1627
|
+
execute: pool.execute,
|
|
1628
|
+
connection: {
|
|
1629
|
+
connectionString: options.connectionString,
|
|
1630
|
+
pool
|
|
1631
|
+
}
|
|
1632
|
+
});
|
|
1633
|
+
return result;
|
|
1634
|
+
})
|
|
1635
|
+
)
|
|
1509
1636
|
);
|
|
1510
1637
|
return messagePooler.start({ startFrom });
|
|
1511
1638
|
})();
|
|
@@ -1519,14 +1646,110 @@ var postgreSQLEventStoreConsumer = (options) => {
|
|
|
1519
1646
|
};
|
|
1520
1647
|
};
|
|
1521
1648
|
|
|
1522
|
-
// src/eventStore/
|
|
1649
|
+
// src/eventStore/consumers/rebuildPostgreSQLProjections.ts
|
|
1650
|
+
|
|
1651
|
+
var rebuildPostgreSQLProjections = (options) => {
|
|
1652
|
+
const consumer = postgreSQLEventStoreConsumer({
|
|
1653
|
+
...options,
|
|
1654
|
+
stopWhen: { noMessagesLeft: true }
|
|
1655
|
+
});
|
|
1656
|
+
const projections = "projections" in options ? options.projections.map(
|
|
1657
|
+
(p) => "projection" in p ? {
|
|
1658
|
+
...p,
|
|
1659
|
+
processorId: `projection:${_nullishCoalesce(p.projection.name, () => ( _uuid.v7.call(void 0, )))}-rebuild`,
|
|
1660
|
+
truncateOnStart: _nullishCoalesce(p.truncateOnStart, () => ( true))
|
|
1661
|
+
} : {
|
|
1662
|
+
projection: p,
|
|
1663
|
+
processorId: `projection:${_nullishCoalesce(p.name, () => ( _uuid.v7.call(void 0, )))}-rebuild`,
|
|
1664
|
+
truncateOnStart: true
|
|
1665
|
+
}
|
|
1666
|
+
) : [options];
|
|
1667
|
+
for (const projectionDefinition of projections) {
|
|
1668
|
+
consumer.processor({
|
|
1669
|
+
...projectionDefinition,
|
|
1670
|
+
processorId: _nullishCoalesce(projectionDefinition.processorId, () => ( `projection:${_nullishCoalesce(projectionDefinition.projection.name, () => ( _uuid.v7.call(void 0, )))}-rebuild`)),
|
|
1671
|
+
truncateOnStart: _nullishCoalesce(projectionDefinition.truncateOnStart, () => ( true))
|
|
1672
|
+
});
|
|
1673
|
+
}
|
|
1674
|
+
return consumer;
|
|
1675
|
+
};
|
|
1676
|
+
|
|
1677
|
+
// src/eventStore/projections/pongo/pongoProjections.ts
|
|
1678
|
+
|
|
1523
1679
|
|
|
1680
|
+
var _pongo = require('@event-driven-io/pongo');
|
|
1681
|
+
var pongoProjection = ({
|
|
1682
|
+
truncate,
|
|
1683
|
+
handle,
|
|
1684
|
+
canHandle
|
|
1685
|
+
}) => postgreSQLProjection({
|
|
1686
|
+
canHandle,
|
|
1687
|
+
handle: async (events, context) => {
|
|
1688
|
+
const {
|
|
1689
|
+
connection: { connectionString, client, pool }
|
|
1690
|
+
} = context;
|
|
1691
|
+
const pongo = _pongo.pongoClient.call(void 0, connectionString, {
|
|
1692
|
+
connectionOptions: { client, pool }
|
|
1693
|
+
});
|
|
1694
|
+
await handle(events, {
|
|
1695
|
+
...context,
|
|
1696
|
+
pongo
|
|
1697
|
+
});
|
|
1698
|
+
},
|
|
1699
|
+
truncate: truncate ? (context) => {
|
|
1700
|
+
const {
|
|
1701
|
+
connection: { connectionString, client, pool }
|
|
1702
|
+
} = context;
|
|
1703
|
+
const pongo = _pongo.pongoClient.call(void 0, connectionString, {
|
|
1704
|
+
connectionOptions: { client, pool }
|
|
1705
|
+
});
|
|
1706
|
+
return truncate({
|
|
1707
|
+
...context,
|
|
1708
|
+
pongo
|
|
1709
|
+
});
|
|
1710
|
+
} : void 0
|
|
1711
|
+
});
|
|
1712
|
+
var pongoMultiStreamProjection = (options) => {
|
|
1713
|
+
const { collectionName, getDocumentId, canHandle } = options;
|
|
1714
|
+
return pongoProjection({
|
|
1715
|
+
handle: async (events, { pongo }) => {
|
|
1716
|
+
const collection = pongo.db().collection(collectionName);
|
|
1717
|
+
for (const event of events) {
|
|
1718
|
+
await collection.handle(getDocumentId(event), async (document) => {
|
|
1719
|
+
return "initialState" in options ? await options.evolve(
|
|
1720
|
+
_nullishCoalesce(document, () => ( options.initialState())),
|
|
1721
|
+
event
|
|
1722
|
+
) : await options.evolve(
|
|
1723
|
+
document,
|
|
1724
|
+
event
|
|
1725
|
+
);
|
|
1726
|
+
});
|
|
1727
|
+
}
|
|
1728
|
+
},
|
|
1729
|
+
canHandle,
|
|
1730
|
+
truncate: async (context) => {
|
|
1731
|
+
const {
|
|
1732
|
+
connection: { connectionString, client, pool }
|
|
1733
|
+
} = context;
|
|
1734
|
+
const pongo = _pongo.pongoClient.call(void 0, connectionString, {
|
|
1735
|
+
connectionOptions: { client, pool }
|
|
1736
|
+
});
|
|
1737
|
+
await pongo.db().collection(collectionName).deleteMany();
|
|
1738
|
+
}
|
|
1739
|
+
});
|
|
1740
|
+
};
|
|
1741
|
+
var pongoSingleStreamProjection = (options) => {
|
|
1742
|
+
return pongoMultiStreamProjection({
|
|
1743
|
+
...options,
|
|
1744
|
+
getDocumentId: _nullishCoalesce(options.getDocumentId, () => ( ((event) => event.metadata.streamName)))
|
|
1745
|
+
});
|
|
1746
|
+
};
|
|
1524
1747
|
|
|
1525
1748
|
// src/eventStore/projections/pongo/pongoProjectionSpec.ts
|
|
1526
1749
|
|
|
1527
1750
|
|
|
1528
1751
|
|
|
1529
|
-
|
|
1752
|
+
|
|
1530
1753
|
var withCollection = (handle, options) => {
|
|
1531
1754
|
const { pool, connectionString, inDatabase, inCollection } = options;
|
|
1532
1755
|
return pool.withConnection(async (connection) => {
|
|
@@ -1658,55 +1881,6 @@ var expectPongoDocuments = {
|
|
|
1658
1881
|
}
|
|
1659
1882
|
};
|
|
1660
1883
|
|
|
1661
|
-
// src/eventStore/projections/pongo/projections.ts
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
var pongoProjection = ({
|
|
1666
|
-
handle,
|
|
1667
|
-
canHandle
|
|
1668
|
-
}) => postgreSQLProjection({
|
|
1669
|
-
canHandle,
|
|
1670
|
-
handle: async (events, context) => {
|
|
1671
|
-
const {
|
|
1672
|
-
connection: { connectionString, client }
|
|
1673
|
-
} = context;
|
|
1674
|
-
const pongo = _pongo.pongoClient.call(void 0, connectionString, {
|
|
1675
|
-
connectionOptions: { client }
|
|
1676
|
-
});
|
|
1677
|
-
await handle(events, {
|
|
1678
|
-
...context,
|
|
1679
|
-
pongo
|
|
1680
|
-
});
|
|
1681
|
-
}
|
|
1682
|
-
});
|
|
1683
|
-
var pongoMultiStreamProjection = (options) => {
|
|
1684
|
-
const { collectionName, getDocumentId, canHandle } = options;
|
|
1685
|
-
return pongoProjection({
|
|
1686
|
-
handle: async (events, { pongo }) => {
|
|
1687
|
-
const collection = pongo.db().collection(collectionName);
|
|
1688
|
-
for (const event of events) {
|
|
1689
|
-
await collection.handle(getDocumentId(event), async (document) => {
|
|
1690
|
-
return "initialState" in options ? await options.evolve(
|
|
1691
|
-
_nullishCoalesce(document, () => ( options.initialState())),
|
|
1692
|
-
event
|
|
1693
|
-
) : await options.evolve(
|
|
1694
|
-
document,
|
|
1695
|
-
event
|
|
1696
|
-
);
|
|
1697
|
-
});
|
|
1698
|
-
}
|
|
1699
|
-
},
|
|
1700
|
-
canHandle
|
|
1701
|
-
});
|
|
1702
|
-
};
|
|
1703
|
-
var pongoSingleStreamProjection = (options) => {
|
|
1704
|
-
return pongoMultiStreamProjection({
|
|
1705
|
-
...options,
|
|
1706
|
-
getDocumentId: _nullishCoalesce(options.getDocumentId, () => ( ((event) => event.metadata.streamName)))
|
|
1707
|
-
});
|
|
1708
|
-
};
|
|
1709
|
-
|
|
1710
1884
|
// src/eventStore/projections/postgresProjectionSpec.ts
|
|
1711
1885
|
|
|
1712
1886
|
|
|
@@ -1723,7 +1897,7 @@ var PostgreSQLProjectionSpec = {
|
|
|
1723
1897
|
const allEvents = [];
|
|
1724
1898
|
const run = async (pool) => {
|
|
1725
1899
|
let globalPosition = 0n;
|
|
1726
|
-
const numberOfTimes = _nullishCoalesce(_optionalChain([options2, 'optionalAccess',
|
|
1900
|
+
const numberOfTimes = _nullishCoalesce(_optionalChain([options2, 'optionalAccess', _74 => _74.numberOfTimes]), () => ( 1));
|
|
1727
1901
|
for (const event of [
|
|
1728
1902
|
...givenEvents,
|
|
1729
1903
|
...Array.from({ length: numberOfTimes }).flatMap(() => events)
|
|
@@ -1780,18 +1954,18 @@ var PostgreSQLProjectionSpec = {
|
|
|
1780
1954
|
if (!isErrorConstructor(args[0])) {
|
|
1781
1955
|
assertTrue(
|
|
1782
1956
|
args[0](error),
|
|
1783
|
-
`Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess',
|
|
1957
|
+
`Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess', _75 => _75.toString, 'call', _76 => _76()])}`
|
|
1784
1958
|
);
|
|
1785
1959
|
return;
|
|
1786
1960
|
}
|
|
1787
1961
|
assertTrue(
|
|
1788
1962
|
error instanceof args[0],
|
|
1789
|
-
`Caught error is not an instance of the expected type: ${_optionalChain([error, 'optionalAccess',
|
|
1963
|
+
`Caught error is not an instance of the expected type: ${_optionalChain([error, 'optionalAccess', _77 => _77.toString, 'call', _78 => _78()])}`
|
|
1790
1964
|
);
|
|
1791
1965
|
if (args[1]) {
|
|
1792
1966
|
assertTrue(
|
|
1793
1967
|
args[1](error),
|
|
1794
|
-
`Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess',
|
|
1968
|
+
`Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess', _79 => _79.toString, 'call', _80 => _80()])}`
|
|
1795
1969
|
);
|
|
1796
1970
|
}
|
|
1797
1971
|
} finally {
|
|
@@ -1810,7 +1984,7 @@ var eventInStream = (streamName, event) => {
|
|
|
1810
1984
|
...event,
|
|
1811
1985
|
metadata: {
|
|
1812
1986
|
..._nullishCoalesce(event.metadata, () => ( {})),
|
|
1813
|
-
streamName: _nullishCoalesce(_optionalChain([event, 'access',
|
|
1987
|
+
streamName: _nullishCoalesce(_optionalChain([event, 'access', _81 => _81.metadata, 'optionalAccess', _82 => _82.streamName]), () => ( streamName))
|
|
1814
1988
|
}
|
|
1815
1989
|
};
|
|
1816
1990
|
};
|
|
@@ -1830,7 +2004,8 @@ var expectSQL = {
|
|
|
1830
2004
|
})
|
|
1831
2005
|
};
|
|
1832
2006
|
|
|
1833
|
-
// src/eventStore/projections/
|
|
2007
|
+
// src/eventStore/projections/postgreSQLProjection.ts
|
|
2008
|
+
|
|
1834
2009
|
var handleProjections = async (options) => {
|
|
1835
2010
|
const {
|
|
1836
2011
|
projections: allProjections,
|
|
@@ -1886,7 +2061,7 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
|
|
|
1886
2061
|
};
|
|
1887
2062
|
const pool = "dumbo" in poolOptions ? poolOptions.dumbo : _dumbo.dumbo.call(void 0, poolOptions);
|
|
1888
2063
|
let migrateSchema;
|
|
1889
|
-
const autoGenerateSchema = _optionalChain([options, 'access',
|
|
2064
|
+
const autoGenerateSchema = _optionalChain([options, 'access', _83 => _83.schema, 'optionalAccess', _84 => _84.autoMigration]) === void 0 || _optionalChain([options, 'access', _85 => _85.schema, 'optionalAccess', _86 => _86.autoMigration]) !== "None";
|
|
1890
2065
|
const ensureSchemaExists = () => {
|
|
1891
2066
|
if (!autoGenerateSchema) return Promise.resolve();
|
|
1892
2067
|
if (!migrateSchema) {
|
|
@@ -1916,7 +2091,7 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
|
|
|
1916
2091
|
},
|
|
1917
2092
|
async aggregateStream(streamName, options2) {
|
|
1918
2093
|
const { evolve, initialState, read } = options2;
|
|
1919
|
-
const expectedStreamVersion = _optionalChain([read, 'optionalAccess',
|
|
2094
|
+
const expectedStreamVersion = _optionalChain([read, 'optionalAccess', _87 => _87.expectedStreamVersion]);
|
|
1920
2095
|
let state = initialState();
|
|
1921
2096
|
const result = await this.readStream(streamName, options2.read);
|
|
1922
2097
|
const currentStreamVersion = result.currentStreamVersion;
|
|
@@ -1957,7 +2132,7 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
|
|
|
1957
2132
|
throw new ExpectedVersionConflictError(
|
|
1958
2133
|
-1n,
|
|
1959
2134
|
//TODO: Return actual version in case of error
|
|
1960
|
-
_nullishCoalesce(_optionalChain([options2, 'optionalAccess',
|
|
2135
|
+
_nullishCoalesce(_optionalChain([options2, 'optionalAccess', _88 => _88.expectedStreamVersion]), () => ( NO_CONCURRENCY_CHECK))
|
|
1961
2136
|
);
|
|
1962
2137
|
return {
|
|
1963
2138
|
nextExpectedStreamVersion: appendResult.nextStreamPosition,
|
|
@@ -2051,5 +2226,7 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
|
|
|
2051
2226
|
|
|
2052
2227
|
|
|
2053
2228
|
|
|
2054
|
-
|
|
2229
|
+
|
|
2230
|
+
|
|
2231
|
+
exports.DefaultPostgreSQLEventStoreProcessorBatchSize = DefaultPostgreSQLEventStoreProcessorBatchSize; exports.DefaultPostgreSQLEventStoreProcessorPullingFrequencyInMs = DefaultPostgreSQLEventStoreProcessorPullingFrequencyInMs; exports.PostgreSQLEventStoreDefaultStreamVersion = PostgreSQLEventStoreDefaultStreamVersion; exports.PostgreSQLProjectionSpec = PostgreSQLProjectionSpec; exports.addDefaultPartitionSQL = addDefaultPartitionSQL; exports.addModuleForAllTenantsSQL = addModuleForAllTenantsSQL; exports.addModuleSQL = addModuleSQL; exports.addPartitionSQL = addPartitionSQL; exports.addTablePartitions = addTablePartitions; exports.addTenantForAllModulesSQL = addTenantForAllModulesSQL; exports.addTenantSQL = addTenantSQL; exports.appendToStream = appendToStream; exports.appendToStreamSQL = appendToStreamSQL; exports.assertSQLQueryResultMatches = assertSQLQueryResultMatches; exports.createEventStoreSchema = createEventStoreSchema; exports.defaultPostgreSQLOptions = defaultPostgreSQLOptions; exports.defaultTag = defaultTag; exports.documentDoesNotExist = documentDoesNotExist; exports.documentExists = documentExists; exports.documentMatchingExists = documentMatchingExists; exports.documentsAreTheSame = documentsAreTheSame; exports.documentsMatchingHaveCount = documentsMatchingHaveCount; exports.emmettPrefix = emmettPrefix; exports.eventInStream = eventInStream; exports.eventsInStream = eventsInStream; exports.expectPongoDocuments = expectPongoDocuments; exports.expectSQL = expectSQL; exports.getPostgreSQLEventStore = getPostgreSQLEventStore; exports.globalNames = globalNames; exports.globalTag = globalTag; exports.handleProjections = handleProjections; exports.messagesTable = messagesTable; exports.messagesTableSQL = messagesTableSQL; exports.migrationFromEventsToMessagesSQL = migrationFromEventsToMessagesSQL; exports.newEventsInStream = newEventsInStream; exports.pongoMultiStreamProjection = pongoMultiStreamProjection; exports.pongoProjection = pongoProjection; exports.pongoSingleStreamProjection = pongoSingleStreamProjection; exports.postgreSQLCheckpointer = postgreSQLCheckpointer; exports.postgreSQLEventStoreConsumer = postgreSQLEventStoreConsumer; exports.postgreSQLEventStoreMessageBatchPuller = postgreSQLEventStoreMessageBatchPuller; exports.postgreSQLMessageProcessor = postgreSQLMessageProcessor; exports.postgreSQLProjection = postgreSQLProjection; exports.postgreSQLProjector = postgreSQLProjector; exports.postgreSQLRawBatchSQLProjection = postgreSQLRawBatchSQLProjection; exports.postgreSQLRawSQLProjection = postgreSQLRawSQLProjection; exports.postgreSQLReactor = postgreSQLReactor; exports.readLastMessageGlobalPosition = readLastMessageGlobalPosition; exports.readMessagesBatch = readMessagesBatch; exports.readProcessorCheckpoint = readProcessorCheckpoint; exports.readStream = readStream; exports.rebuildPostgreSQLProjections = rebuildPostgreSQLProjections; exports.sanitizeNameSQL = sanitizeNameSQL; exports.schemaSQL = schemaSQL; exports.storeProcessorCheckpoint = storeProcessorCheckpoint; exports.storeSubscriptionCheckpointSQL = storeSubscriptionCheckpointSQL; exports.streamsTable = streamsTable; exports.streamsTableSQL = streamsTableSQL; exports.subscriptionsTable = subscriptionsTable; exports.subscriptionsTableSQL = subscriptionsTableSQL; exports.zipPostgreSQLEventStoreMessageBatchPullerStartFrom = zipPostgreSQLEventStoreMessageBatchPullerStartFrom;
|
|
2055
2232
|
//# sourceMappingURL=index.cjs.map
|