@event-driven-io/emmett-postgresql 0.42.0-rc.1 → 0.42.0-rc.2

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
@@ -1589,7 +1589,7 @@ var pongoMultiStreamProjection = (options) => {
1589
1589
  await pongo.db().collection(
1590
1590
  collectionNameWithVersion,
1591
1591
  options.collectionOptions
1592
- ).schema.migrate();
1592
+ ).schema.migrate(context.migrationOptions);
1593
1593
  } finally {
1594
1594
  await pongo.close();
1595
1595
  }
@@ -4166,8 +4166,8 @@ var eventStoreSchemaMigrations = [
4166
4166
  migration_0_42_0_2_AddProcessorProjectionFunctions,
4167
4167
  schemaMigration
4168
4168
  ];
4169
- var createEventStoreSchema = async (connectionString, pool, hooks) => {
4170
- await pool.withTransaction(async (tx) => {
4169
+ var createEventStoreSchema = (connectionString, pool, hooks, options) => {
4170
+ return pool.withTransaction(async (tx) => {
4171
4171
  const client = await tx.connection.open();
4172
4172
  const context = {
4173
4173
  execute: tx.execute,
@@ -4183,10 +4183,15 @@ var createEventStoreSchema = async (connectionString, pool, hooks) => {
4183
4183
  if (_optionalChain([hooks, 'optionalAccess', _65 => _65.onBeforeSchemaCreated])) {
4184
4184
  await hooks.onBeforeSchemaCreated(context);
4185
4185
  }
4186
- await _dumbo.runPostgreSQLMigrations.call(void 0, nestedPool, eventStoreSchemaMigrations);
4186
+ const result = await _dumbo.runPostgreSQLMigrations.call(void 0,
4187
+ nestedPool,
4188
+ eventStoreSchemaMigrations,
4189
+ options
4190
+ );
4187
4191
  if (_optionalChain([hooks, 'optionalAccess', _66 => _66.onAfterSchemaCreated])) {
4188
4192
  await hooks.onAfterSchemaCreated(context);
4189
4193
  }
4194
+ return result;
4190
4195
  } finally {
4191
4196
  await nestedPool.close();
4192
4197
  }
@@ -4218,30 +4223,35 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
4218
4223
  let migrateSchema = void 0;
4219
4224
  const autoGenerateSchema = _optionalChain([options, 'access', _68 => _68.schema, 'optionalAccess', _69 => _69.autoMigration]) === void 0 || _optionalChain([options, 'access', _70 => _70.schema, 'optionalAccess', _71 => _71.autoMigration]) !== "None";
4220
4225
  const inlineProjections = (_nullishCoalesce(options.projections, () => ( []))).filter(({ type }) => type === "inline").map(({ projection: projection2 }) => projection2);
4221
- const migrate = async () => {
4226
+ const migrate = async (migrationOptions) => {
4222
4227
  if (!migrateSchema) {
4223
- migrateSchema = createEventStoreSchema(connectionString, pool, {
4224
- onBeforeSchemaCreated: async (context) => {
4225
- if (_optionalChain([options, 'access', _72 => _72.hooks, 'optionalAccess', _73 => _73.onBeforeSchemaCreated])) {
4226
- await options.hooks.onBeforeSchemaCreated(context);
4227
- }
4228
- },
4229
- onAfterSchemaCreated: async (context) => {
4230
- for (const projection2 of inlineProjections) {
4231
- if (projection2.init) {
4232
- await projection2.init({
4233
- version: _nullishCoalesce(projection2.version, () => ( 1)),
4234
- status: "active",
4235
- registrationType: "inline",
4236
- context
4237
- });
4228
+ migrateSchema = createEventStoreSchema(
4229
+ connectionString,
4230
+ pool,
4231
+ {
4232
+ onBeforeSchemaCreated: async (context) => {
4233
+ if (_optionalChain([options, 'access', _72 => _72.hooks, 'optionalAccess', _73 => _73.onBeforeSchemaCreated])) {
4234
+ await options.hooks.onBeforeSchemaCreated(context);
4235
+ }
4236
+ },
4237
+ onAfterSchemaCreated: async (context) => {
4238
+ for (const projection2 of inlineProjections) {
4239
+ if (projection2.init) {
4240
+ await projection2.init({
4241
+ version: _nullishCoalesce(projection2.version, () => ( 1)),
4242
+ status: "active",
4243
+ registrationType: "inline",
4244
+ context: { ...context, migrationOptions }
4245
+ });
4246
+ }
4247
+ }
4248
+ if (_optionalChain([options, 'access', _74 => _74.hooks, 'optionalAccess', _75 => _75.onAfterSchemaCreated])) {
4249
+ await options.hooks.onAfterSchemaCreated(context);
4238
4250
  }
4239
4251
  }
4240
- if (_optionalChain([options, 'access', _74 => _74.hooks, 'optionalAccess', _75 => _75.onAfterSchemaCreated])) {
4241
- await options.hooks.onAfterSchemaCreated(context);
4242
- }
4243
- }
4244
- });
4252
+ },
4253
+ migrationOptions
4254
+ );
4245
4255
  }
4246
4256
  return migrateSchema;
4247
4257
  };
@@ -4740,9 +4750,16 @@ var postgreSQLProjector = (options) => {
4740
4750
  version: _nullishCoalesce(options.projection.version, () => ( version)),
4741
4751
  status: "active",
4742
4752
  registrationType: "async",
4743
- context
4753
+ context: {
4754
+ ...context,
4755
+ migrationOptions: options.migrationOptions
4756
+ }
4757
+ });
4758
+ if (_optionalChain([options, 'access', _100 => _100.hooks, 'optionalAccess', _101 => _101.onInit]))
4759
+ await options.hooks.onInit({
4760
+ ...context,
4761
+ migrationOptions: options.migrationOptions
4744
4762
  });
4745
- if (_optionalChain([options, 'access', _100 => _100.hooks, 'optionalAccess', _101 => _101.onInit])) await options.hooks.onInit(context);
4746
4763
  } : _optionalChain([options, 'access', _102 => _102.hooks, 'optionalAccess', _103 => _103.onInit]),
4747
4764
  onClose: close ? async (context) => {
4748
4765
  if (_optionalChain([options, 'access', _104 => _104.hooks, 'optionalAccess', _105 => _105.onClose])) await _optionalChain([options, 'access', _106 => _106.hooks, 'optionalAccess', _107 => _107.onClose, 'call', _108 => _108(context)]);