@event-driven-io/emmett-postgresql 0.43.0-beta.23 → 0.43.0-beta.26

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 CHANGED
@@ -865,8 +865,8 @@ const getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOp
865
865
  await ensureSchemaExists();
866
866
  return streamExists(pool.execute, streamName, options);
867
867
  },
868
- consumer: (options) => postgreSQLEventStoreConsumer({
869
- ...options ?? {},
868
+ consumer: (consumerOptions) => postgreSQLEventStoreConsumer({
869
+ ...(0, _event_driven_io_emmett.mergeObservabilityOptions)(consumerOptions ?? {}, options.observability),
870
870
  pool,
871
871
  connectionString
872
872
  }),
@@ -3037,11 +3037,6 @@ const postgreSQLEventStoreMessageBatchPuller = ({ executor, batchSize, eachBatch
3037
3037
  }
3038
3038
  };
3039
3039
  };
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
3040
 
3046
3041
  //#endregion
3047
3042
  //#region src/eventStore/consumers/postgreSQLProcessor.ts
@@ -3169,7 +3164,7 @@ const postgreSQLProjector = (options) => {
3169
3164
  processorId,
3170
3165
  partition
3171
3166
  }),
3172
- checkpoints: postgreSQLCheckpointer()
3167
+ checkpoints: options.checkpoints === "DISABLED" ? (0, _event_driven_io_emmett.inMemoryCheckpointer)() : postgreSQLCheckpointer()
3173
3168
  });
3174
3169
  };
3175
3170
  const postgreSQLWorkflowProcessor = (options) => {
@@ -3204,7 +3199,7 @@ const postgreSQLWorkflowProcessor = (options) => {
3204
3199
  processorId,
3205
3200
  partition
3206
3201
  }),
3207
- checkpoints: postgreSQLCheckpointer()
3202
+ checkpoints: options.checkpoints === "DISABLED" ? (0, _event_driven_io_emmett.inMemoryCheckpointer)() : postgreSQLCheckpointer()
3208
3203
  });
3209
3204
  };
3210
3205
  const postgreSQLReactor = (options) => {
@@ -3239,7 +3234,7 @@ const postgreSQLReactor = (options) => {
3239
3234
  processorId,
3240
3235
  partition
3241
3236
  }),
3242
- checkpoints: postgreSQLCheckpointer()
3237
+ checkpoints: options.checkpoints === "DISABLED" ? (0, _event_driven_io_emmett.inMemoryCheckpointer)() : postgreSQLCheckpointer()
3243
3238
  });
3244
3239
  };
3245
3240
 
@@ -3259,24 +3254,6 @@ const postgreSQLEventStoreConsumer = (options) => {
3259
3254
  connectionString: options.connectionString,
3260
3255
  serialization: options.serialization
3261
3256
  });
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
3257
  const processorContext = {
3281
3258
  execute: pool.execute,
3282
3259
  connection: {
@@ -3327,18 +3304,18 @@ const postgreSQLEventStoreConsumer = (options) => {
3327
3304
  whenStarted: () => startedAwaiter.wait,
3328
3305
  processors,
3329
3306
  init,
3330
- reactor: (options) => {
3331
- const processor = postgreSQLReactor(options);
3307
+ reactor: (processorOptions) => {
3308
+ const processor = postgreSQLReactor((0, _event_driven_io_emmett.mergeObservabilityOptions)(processorOptions, options.observability));
3332
3309
  processors.push(processor);
3333
3310
  return processor;
3334
3311
  },
3335
- projector: (options) => {
3336
- const processor = postgreSQLProjector(options);
3312
+ projector: (processorOptions) => {
3313
+ const processor = postgreSQLProjector((0, _event_driven_io_emmett.mergeObservabilityOptions)(processorOptions, options.observability));
3337
3314
  processors.push(processor);
3338
3315
  return processor;
3339
3316
  },
3340
- workflowProcessor: (options) => {
3341
- const processor = postgreSQLWorkflowProcessor(options);
3317
+ workflowProcessor: (processorOptions) => {
3318
+ const processor = postgreSQLWorkflowProcessor((0, _event_driven_io_emmett.mergeObservabilityOptions)(processorOptions, options.observability));
3342
3319
  processors.push(processor);
3343
3320
  return processor;
3344
3321
  },
@@ -3358,6 +3335,26 @@ const postgreSQLEventStoreConsumer = (options) => {
3358
3335
  abortController = new AbortController();
3359
3336
  start = (async () => {
3360
3337
  if (!isRunning) return;
3338
+ let startPositions = void 0;
3339
+ const eachBatch = async (messagesBatch) => {
3340
+ const activeProcessors = processors.filter((s) => s.isActive);
3341
+ if (activeProcessors.length === 0) return {
3342
+ type: "STOP",
3343
+ reason: "No active processors"
3344
+ };
3345
+ return (await Promise.allSettled(activeProcessors.map(async (s) => {
3346
+ const batch = startPositions.afterStartPosition(s.id, messagesBatch);
3347
+ try {
3348
+ return await s.handle(batch, { connection: {
3349
+ connectionString: options.connectionString,
3350
+ pool
3351
+ } });
3352
+ } catch (error) {
3353
+ console.log(`Error during message batch processing for processor: ${s.id}`, error);
3354
+ throw error;
3355
+ }
3356
+ }))).some((r) => r.status === "fulfilled" && r.value?.type !== "STOP") ? void 0 : { type: "STOP" };
3357
+ };
3361
3358
  try {
3362
3359
  messagePuller = postgreSQLEventStoreMessageBatchPuller({
3363
3360
  stopWhen: options.stopWhen,
@@ -3371,23 +3368,23 @@ const postgreSQLEventStoreConsumer = (options) => {
3371
3368
  console.log("Initializing consumer before starting message pulling.");
3372
3369
  await init();
3373
3370
  }
3374
- const startFrom = zipPostgreSQLEventStoreMessageBatchPullerStartFrom(await Promise.all(processors.map(async (o) => {
3375
- try {
3376
- return await o.start({
3377
- execute: pool.execute,
3378
- connection: {
3379
- connectionString: options.connectionString,
3380
- pool
3381
- }
3382
- });
3383
- } catch (error) {
3384
- console.log(`Error during processor start position retrieval for processor: ${o.id}. Stopping it.`, error);
3385
- throw error;
3371
+ startPositions = await pool.withConnection((connection) => _event_driven_io_emmett.ConsumerStartPositions.resolve({
3372
+ processors,
3373
+ handlerContext: {
3374
+ execute: pool.execute,
3375
+ connection: {
3376
+ connectionString: options.connectionString,
3377
+ pool
3378
+ }
3379
+ },
3380
+ readLastMessageCheckpoint: async () => {
3381
+ const { currentCheckpoint } = await readLastMessageCheckpoint(connection.execute);
3382
+ return currentCheckpoint !== null ? PostgreSQLEventStoreCheckpoint.toProcessorCheckpoint(currentCheckpoint) : null;
3386
3383
  }
3387
- })));
3388
- console.log(`Starting message pulling with start position: ${_event_driven_io_dumbo.JSONSerializer.serialize(startFrom)}. Waiting for messages...`);
3384
+ }));
3385
+ console.log(`Starting message pulling with start position: ${_event_driven_io_dumbo.JSONSerializer.serialize(startPositions.earliestPosition)}. Waiting for messages...`);
3389
3386
  await messagePuller.start({
3390
- startFrom,
3387
+ startFrom: startPositions.earliestPosition,
3391
3388
  started: startedAwaiter
3392
3389
  });
3393
3390
  } catch (error) {
@@ -3527,5 +3524,4 @@ exports.toProjectionLockKey = toProjectionLockKey;
3527
3524
  exports.transactionToPostgreSQLProjectionHandlerContext = transactionToPostgreSQLProjectionHandlerContext;
3528
3525
  exports.tryAcquireProcessorLockSQL = tryAcquireProcessorLockSQL;
3529
3526
  exports.tryAcquireProjectionLockSQL = tryAcquireProjectionLockSQL;
3530
- exports.zipPostgreSQLEventStoreMessageBatchPullerStartFrom = zipPostgreSQLEventStoreMessageBatchPullerStartFrom;
3531
3527
  //# sourceMappingURL=index.cjs.map