Configuration

Event Nest has one persistence module per adapter. Each module builds and exports an event store under the EVENT_STORE injection token. Snapshot storage is configured by each adapter; there is no shared public snapshot module-options type.

Registration methods

All adapters expose the same four static methods.

MethodScopeOptions resolutionResult
forRoot(options)GlobalSynchronous objectEVENT_STORE is available application-wide after one import.
forRootAsync(options)GlobalFactory returning an object or promiseSame global export, after the factory resolves.
register(options)ScopedSynchronous objectEVENT_STORE is available only to the importing module and modules that re-export it.
registerAsync(options)ScopedFactory returning an object or promiseSame scoped export, after the factory resolves.

The corresponding modules are EventNestMongoDbModule, EventNestPostgreSQLModule, and EventNestMSSQLModule. Registration exports only EVENT_STORE; adapter clients, snapshot stores, schema configuration, and emitters are implementation providers, not module exports.

Each asynchronous options type has this shape:

AdapterAsync typeFactory result
MongoDBMongoDbModuleAsyncOptionsMongodbModuleOptions | Promise<MongodbModuleOptions>
PostgreSQLPostgreSQLModuleAsyncOptionsPostgreSQLModuleOptions | Promise<PostgreSQLModuleOptions>
Microsoft SQL ServerMSSQLModuleAsyncOptionsMSSQLModuleOptions | Promise<MSSQLModuleOptions>
OptionTypeRequiredDefaultDescription
useFactory(...parameters: any[]) => Options | Promise<Options>YesNoneProduces that adapter's complete module options.
injectany[]NoundefinedTokens passed to useFactory in order. The async options types do not have an imports property, so dependencies must already be visible in the module context.
EventNestPostgreSQLModule.forRootAsync({
    inject: [ConfigService],
    useFactory: (config: ConfigService) => ({
        aggregatesTableName: "aggregates",
        connectionUri: config.getOrThrow("DATABASE_URL"),
        eventsTableName: "events",
        schemaName: "event_nest"
    })
})
ts

Shared option

CoreModuleOptions contributes one option to every adapter.

OptionTypeRequiredEvent Nest defaultDescription
concurrentSubscriptionsbooleanNofalsefalse dispatches emitted events in order. true dispatches event-handler work concurrently. See subscription behavior .

MongoDB

Install @event-nest/core, @event-nest/mongodb, and its mongodb 7.x peer dependency.

MongodbModuleOptions

OptionTypeRequiredEvent Nest defaultDescription
aggregatesCollectionstringYesNoneCollection holding aggregate IDs and current versions.
connectionUristringYesNoneURI passed as the first MongoClient constructor argument.
eventsCollectionstringYesNoneCollection holding persisted events.
mongoClientConfigurationMongoClientOptionsNoundefinedPassed unchanged as the second MongoClient constructor argument. Driver defaults apply when omitted.
concurrentSubscriptionsbooleanNofalseShared subscription dispatch option.
snapshotCollectionstringConditionalSnapshots disabledSnapshot collection. Must be supplied together with snapshotStrategy.
snapshotStrategySnapshotStrategyConditionalSnapshots disabledSnapshot creation policy. Must be supplied together with snapshotCollection.

The options type is a union: omit both snapshot fields to use NoOpSnapshotStore, or provide both. The provider repeats this check at runtime and throws To use snapshots, both 'snapshotStrategy' and 'snapshotCollection' must be provided. for an incomplete pair.

MongoDB saves and purges with transactions. Use a deployment that supports transactions, such as a replica set or sharded cluster; a standalone server cannot complete those operations.

PostgreSQL

Install @event-nest/core, @event-nest/postgresql, and its pg peer dependency (^8.14.1).

PostgreSQLModuleOptions

OptionTypeRequiredEvent Nest defaultDescription
aggregatesTableNamestringYesNoneAggregate-version table name.
connectionUristringYesNonePostgreSQL connection string passed to Knex.
eventsTableNamestringYesNoneEvent table name.
schemaNamestringYesNoneSchema prepended to configured table names. The schema itself is not created.
connectionPoolConnectionPoolOptionsNoundefinedPassed to Knex as pool; Knex/Tarn defaults apply when omitted.
ensureTablesExistbooleanNofalseChecks for and creates missing aggregate, event, and configured snapshot tables during application bootstrap. Requires DDL permission.
sslSslOptionsNoSSL object omittedWhen supplied, maps certificate to ssl.ca and forwards rejectUnauthorized.
concurrentSubscriptionsbooleanNofalseShared subscription dispatch option.
snapshotTableNamestringConditionalSnapshots disabledSnapshot table name. Must be supplied together with snapshotStrategy.
snapshotStrategySnapshotStrategyConditionalSnapshots disabledSnapshot creation policy. Must be supplied together with snapshotTableName.

An incomplete snapshot pair throws To use snapshots, both 'snapshotStrategy' and 'snapshotTableName' must be provided. When both fields are absent, Event Nest installs NoOpSnapshotStore.

SslOptions

OptionTypeRequiredEvent Nest defaultDescription
rejectUnauthorizedbooleanYesNoneForwarded to the PostgreSQL driver's SSL configuration.
certificatestringNoundefinedCA certificate text forwarded as ssl.ca.

Omitting ssl does not force an SSL setting; the connection consists only of connectionString. Supplying ssl creates an SSL object even when certificate is omitted.

PostgreSQL ConnectionPoolOptions

All fields are optional and passed through to Knex/Tarn. Event Nest assigns no PostgreSQL pool defaults.

OptionTypeDescription
acquireTimeoutMillisnumberMaximum wait when acquiring a resource.
afterCreateFunctionHook run after a connection is created.
createRetryIntervalMillisnumberDelay between create retries.
createTimeoutMillisnumberConnection creation timeout.
destroyTimeoutMillisnumberResource destruction timeout.
idleTimeoutMillisnumberIdle lifetime before reaping.
log(message: string, logLevel: string) => voidPool log callback.
maxnumberMaximum pool size.
minnumberMinimum pool size.
namestringPool name.
priorityRangenumberNumber of priority levels.
propagateCreateErrorbooleanWhether creation errors are propagated immediately.
reapIntervalMillisnumberInterval between idle-resource checks.
refreshIdlebooleanWhether idle resources are refreshed.
returnToHeadbooleanWhether released resources return to the head of the free list.

Microsoft SQL Server

Install @event-nest/core, @event-nest/mssql, and its tedious 20.x peer dependency. Event Nest uses Knex's mssql client internally.

MSSQLModuleOptions

OptionTypeRequiredEvent Nest defaultDescription
aggregatesTableNamestringYesNoneAggregate-version table name.
connectionMSSQLConnectionOptionsYesNoneStructured SQL Server connection settings.
eventsTableNamestringYesNoneEvent table name.
schemaNamestringYesNoneSQL Server schema, commonly dbo. The schema itself is not created.
connectionPoolConnectionPoolOptionsNo{ min: 0 } plus Knex/Tarn defaultsPool settings merged over Event Nest's min: 0.
ensureTablesExistbooleanNofalseCreates missing aggregate, event, and configured snapshot tables at bootstrap. Requires DDL permission.
concurrentSubscriptionsbooleanNofalseShared subscription dispatch option.
snapshotTableNamestringConditionalSnapshots disabledSnapshot table name. Must be supplied together with snapshotStrategy.
snapshotStrategySnapshotStrategyConditionalSnapshots disabledSnapshot creation policy. Must be supplied together with snapshotTableName.

SQL Server validates schemaName, aggregatesTableName, eventsTableName, and, when present, snapshotTableName. Each must be non-empty, at most 128 characters, and contain no dot. Supply schema and table separately.

MSSQLConnectionOptions

OptionTypeRequiredEvent Nest defaultDescription
databasestringYesNoneDatabase name.
passwordstringYesNoneLogin password.
serverstringYesNoneSQL Server host.
userstringYesNoneLogin user.
connectionTimeoutnumberNoDriver defaultForwarded to the connection.
encryptbooleanNotrueTedious encryption option.
instanceNamestringNoundefinedNamed instance. Mutually exclusive with port.
portnumberNoDriver defaultTCP port. Mutually exclusive with instanceName.
requestTimeoutnumberNoDriver defaultRequest timeout.
serverNamestringNoundefinedTLS server name forwarded to Tedious.
trustServerCertificatebooleanNofalseWhether to trust the server certificate without validation.

Event Nest also fixes lowerCaseGuids: true and useUTC: true, and binds JavaScript Date values as DateTime2. Configuring both port and instanceName throws MSSQL connection options cannot provide both 'port' and 'instanceName'.

SQL Server ConnectionPoolOptions

Every field is optional. Event Nest merges this object over { min: 0 }; a provided min overrides it, and all remaining defaults belong to Knex/Tarn.

OptionTypeDescription
acquireTimeoutMillisnumberMaximum wait when acquiring a resource.
afterCreateFunctionHook run after a connection is created.
createRetryIntervalMillisnumberDelay between create retries.
createTimeoutMillisnumberConnection creation timeout.
destroyTimeoutMillisnumberResource destruction timeout.
idleTimeoutMillisnumberIdle lifetime before reaping.
log(message: string, logLevel: string) => voidPool log callback.
maxnumberMaximum pool size.
minnumberMinimum pool size; Event Nest defaults this field to 0.
namestringPool name.
priorityRangenumberNumber of priority levels.
propagateCreateErrorbooleanWhether creation errors are propagated immediately.
reapIntervalMillisnumberInterval between idle-resource checks.
refreshIdlebooleanWhether idle resources are refreshed.
returnToHeadbooleanWhether released resources return to the head of the free list.

Snapshot option dependency

Snapshot support always has three independent requirements:

  1. Configure the adapter's strategy and storage location as a pair.
  2. Add snapshotRevision to @AggregateRootConfig on every aggregate that can match the strategy.
  3. Implement callable toSnapshot() and applySnapshot() methods on those aggregate instances.

The adapter-specific location field is part of its public options. No shared SnapshotsEnabled or SnapshotsDisabled type is exported. See decorators and common snapshot problems .

Sources

Last update at: 2026/09/02 00:14