@event-driven-io/emmett-postgresql 0.43.0-beta.24 → 0.43.0-beta.27
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 +52 -46
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -6
- package/dist/index.d.ts +3 -6
- package/dist/index.js +54 -47
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -866,7 +866,8 @@ const getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOp
|
|
|
866
866
|
return streamExists(pool.execute, streamName, options);
|
|
867
867
|
},
|
|
868
868
|
consumer: (consumerOptions) => postgreSQLEventStoreConsumer({
|
|
869
|
-
...
|
|
869
|
+
...consumerOptions,
|
|
870
|
+
observability: (0, _event_driven_io_emmett.mergeObservability)(options.observability, consumerOptions?.observability),
|
|
870
871
|
pool,
|
|
871
872
|
connectionString
|
|
872
873
|
}),
|
|
@@ -3037,11 +3038,6 @@ const postgreSQLEventStoreMessageBatchPuller = ({ executor, batchSize, eachBatch
|
|
|
3037
3038
|
}
|
|
3038
3039
|
};
|
|
3039
3040
|
};
|
|
3040
|
-
const zipPostgreSQLEventStoreMessageBatchPullerStartFrom = (options) => {
|
|
3041
|
-
if (options.length === 0 || options.some((o) => o === void 0 || o === "BEGINNING")) return "BEGINNING";
|
|
3042
|
-
if (options.every((o) => o === "END")) return "END";
|
|
3043
|
-
return options.filter((o) => o !== void 0 && o !== "BEGINNING" && o !== "END").sort((a, b) => a > b ? 1 : -1)[0];
|
|
3044
|
-
};
|
|
3045
3041
|
|
|
3046
3042
|
//#endregion
|
|
3047
3043
|
//#region src/eventStore/consumers/postgreSQLProcessor.ts
|
|
@@ -3169,7 +3165,7 @@ const postgreSQLProjector = (options) => {
|
|
|
3169
3165
|
processorId,
|
|
3170
3166
|
partition
|
|
3171
3167
|
}),
|
|
3172
|
-
checkpoints: postgreSQLCheckpointer()
|
|
3168
|
+
checkpoints: options.checkpoints === "DISABLED" ? (0, _event_driven_io_emmett.inMemoryCheckpointer)() : postgreSQLCheckpointer()
|
|
3173
3169
|
});
|
|
3174
3170
|
};
|
|
3175
3171
|
const postgreSQLWorkflowProcessor = (options) => {
|
|
@@ -3204,7 +3200,7 @@ const postgreSQLWorkflowProcessor = (options) => {
|
|
|
3204
3200
|
processorId,
|
|
3205
3201
|
partition
|
|
3206
3202
|
}),
|
|
3207
|
-
checkpoints: postgreSQLCheckpointer()
|
|
3203
|
+
checkpoints: options.checkpoints === "DISABLED" ? (0, _event_driven_io_emmett.inMemoryCheckpointer)() : postgreSQLCheckpointer()
|
|
3208
3204
|
});
|
|
3209
3205
|
};
|
|
3210
3206
|
const postgreSQLReactor = (options) => {
|
|
@@ -3239,7 +3235,7 @@ const postgreSQLReactor = (options) => {
|
|
|
3239
3235
|
processorId,
|
|
3240
3236
|
partition
|
|
3241
3237
|
}),
|
|
3242
|
-
checkpoints: postgreSQLCheckpointer()
|
|
3238
|
+
checkpoints: options.checkpoints === "DISABLED" ? (0, _event_driven_io_emmett.inMemoryCheckpointer)() : postgreSQLCheckpointer()
|
|
3243
3239
|
});
|
|
3244
3240
|
};
|
|
3245
3241
|
|
|
@@ -3259,24 +3255,6 @@ const postgreSQLEventStoreConsumer = (options) => {
|
|
|
3259
3255
|
connectionString: options.connectionString,
|
|
3260
3256
|
serialization: options.serialization
|
|
3261
3257
|
});
|
|
3262
|
-
const eachBatch = async (messagesBatch) => {
|
|
3263
|
-
const activeProcessors = processors.filter((s) => s.isActive);
|
|
3264
|
-
if (activeProcessors.length === 0) return {
|
|
3265
|
-
type: "STOP",
|
|
3266
|
-
reason: "No active processors"
|
|
3267
|
-
};
|
|
3268
|
-
return (await Promise.allSettled(activeProcessors.map(async (s) => {
|
|
3269
|
-
try {
|
|
3270
|
-
return await s.handle(messagesBatch, { connection: {
|
|
3271
|
-
connectionString: options.connectionString,
|
|
3272
|
-
pool
|
|
3273
|
-
} });
|
|
3274
|
-
} catch (error) {
|
|
3275
|
-
console.log(`Error during message batch processing for processor: ${s.id}`, error);
|
|
3276
|
-
throw error;
|
|
3277
|
-
}
|
|
3278
|
-
}))).some((r) => r.status === "fulfilled" && r.value?.type !== "STOP") ? void 0 : { type: "STOP" };
|
|
3279
|
-
};
|
|
3280
3258
|
const processorContext = {
|
|
3281
3259
|
execute: pool.execute,
|
|
3282
3260
|
connection: {
|
|
@@ -3328,17 +3306,26 @@ const postgreSQLEventStoreConsumer = (options) => {
|
|
|
3328
3306
|
processors,
|
|
3329
3307
|
init,
|
|
3330
3308
|
reactor: (processorOptions) => {
|
|
3331
|
-
const processor = postgreSQLReactor(
|
|
3309
|
+
const processor = postgreSQLReactor({
|
|
3310
|
+
...processorOptions,
|
|
3311
|
+
observability: (0, _event_driven_io_emmett.mergeObservability)(options.observability, processorOptions.observability)
|
|
3312
|
+
});
|
|
3332
3313
|
processors.push(processor);
|
|
3333
3314
|
return processor;
|
|
3334
3315
|
},
|
|
3335
3316
|
projector: (processorOptions) => {
|
|
3336
|
-
const processor = postgreSQLProjector(
|
|
3317
|
+
const processor = postgreSQLProjector({
|
|
3318
|
+
...processorOptions,
|
|
3319
|
+
observability: (0, _event_driven_io_emmett.mergeObservability)(options.observability, processorOptions.observability)
|
|
3320
|
+
});
|
|
3337
3321
|
processors.push(processor);
|
|
3338
3322
|
return processor;
|
|
3339
3323
|
},
|
|
3340
3324
|
workflowProcessor: (processorOptions) => {
|
|
3341
|
-
const processor = postgreSQLWorkflowProcessor(
|
|
3325
|
+
const processor = postgreSQLWorkflowProcessor({
|
|
3326
|
+
...processorOptions,
|
|
3327
|
+
observability: (0, _event_driven_io_emmett.mergeObservability)(options.observability, processorOptions.observability)
|
|
3328
|
+
});
|
|
3342
3329
|
processors.push(processor);
|
|
3343
3330
|
return processor;
|
|
3344
3331
|
},
|
|
@@ -3358,6 +3345,26 @@ const postgreSQLEventStoreConsumer = (options) => {
|
|
|
3358
3345
|
abortController = new AbortController();
|
|
3359
3346
|
start = (async () => {
|
|
3360
3347
|
if (!isRunning) return;
|
|
3348
|
+
let startPositions = void 0;
|
|
3349
|
+
const eachBatch = async (messagesBatch) => {
|
|
3350
|
+
const activeProcessors = processors.filter((s) => s.isActive);
|
|
3351
|
+
if (activeProcessors.length === 0) return {
|
|
3352
|
+
type: "STOP",
|
|
3353
|
+
reason: "No active processors"
|
|
3354
|
+
};
|
|
3355
|
+
return (await Promise.allSettled(activeProcessors.map(async (s) => {
|
|
3356
|
+
const batch = startPositions.afterStartPosition(s.id, messagesBatch);
|
|
3357
|
+
try {
|
|
3358
|
+
return await s.handle(batch, { connection: {
|
|
3359
|
+
connectionString: options.connectionString,
|
|
3360
|
+
pool
|
|
3361
|
+
} });
|
|
3362
|
+
} catch (error) {
|
|
3363
|
+
console.log(`Error during message batch processing for processor: ${s.id}`, error);
|
|
3364
|
+
throw error;
|
|
3365
|
+
}
|
|
3366
|
+
}))).some((r) => r.status === "fulfilled" && r.value?.type !== "STOP") ? void 0 : { type: "STOP" };
|
|
3367
|
+
};
|
|
3361
3368
|
try {
|
|
3362
3369
|
messagePuller = postgreSQLEventStoreMessageBatchPuller({
|
|
3363
3370
|
stopWhen: options.stopWhen,
|
|
@@ -3371,23 +3378,23 @@ const postgreSQLEventStoreConsumer = (options) => {
|
|
|
3371
3378
|
console.log("Initializing consumer before starting message pulling.");
|
|
3372
3379
|
await init();
|
|
3373
3380
|
}
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3381
|
+
startPositions = await pool.withConnection((connection) => _event_driven_io_emmett.ConsumerStartPositions.resolve({
|
|
3382
|
+
processors,
|
|
3383
|
+
handlerContext: {
|
|
3384
|
+
execute: pool.execute,
|
|
3385
|
+
connection: {
|
|
3386
|
+
connectionString: options.connectionString,
|
|
3387
|
+
pool
|
|
3388
|
+
}
|
|
3389
|
+
},
|
|
3390
|
+
readLastMessageCheckpoint: async () => {
|
|
3391
|
+
const { currentCheckpoint } = await readLastMessageCheckpoint(connection.execute);
|
|
3392
|
+
return currentCheckpoint !== null ? PostgreSQLEventStoreCheckpoint.toProcessorCheckpoint(currentCheckpoint) : null;
|
|
3386
3393
|
}
|
|
3387
|
-
}))
|
|
3388
|
-
console.log(`Starting message pulling with start position: ${_event_driven_io_dumbo.JSONSerializer.serialize(
|
|
3394
|
+
}));
|
|
3395
|
+
console.log(`Starting message pulling with start position: ${_event_driven_io_dumbo.JSONSerializer.serialize(startPositions.earliestPosition)}. Waiting for messages...`);
|
|
3389
3396
|
await messagePuller.start({
|
|
3390
|
-
startFrom,
|
|
3397
|
+
startFrom: startPositions.earliestPosition,
|
|
3391
3398
|
started: startedAwaiter
|
|
3392
3399
|
});
|
|
3393
3400
|
} catch (error) {
|
|
@@ -3527,5 +3534,4 @@ exports.toProjectionLockKey = toProjectionLockKey;
|
|
|
3527
3534
|
exports.transactionToPostgreSQLProjectionHandlerContext = transactionToPostgreSQLProjectionHandlerContext;
|
|
3528
3535
|
exports.tryAcquireProcessorLockSQL = tryAcquireProcessorLockSQL;
|
|
3529
3536
|
exports.tryAcquireProjectionLockSQL = tryAcquireProjectionLockSQL;
|
|
3530
|
-
exports.zipPostgreSQLEventStoreMessageBatchPullerStartFrom = zipPostgreSQLEventStoreMessageBatchPullerStartFrom;
|
|
3531
3537
|
//# sourceMappingURL=index.cjs.map
|