Registry / database / consequent-postgres

consequent-postgres

JSON →
library2.0.3jsnpmunverified

PostgreSQL storage adapters for the Consequent event sourcing framework. Current version is 2.0.3 (ESM-only, requires Node >=18, PostgreSQL >=12). Provides actor (snapshot), event, and search storage implementations backed by PostgreSQL, with TypeScript type declarations included. Key differentiators: designed specifically for Consequent's event sourcing model, supports JSONB-based queries, ID mapping between system and aggregate IDs, and does not support siblings (optimized for microservice architectures).

npm install consequent-postgres
INSTALL
IMPORT
SIG · CONSEQUENT-POSTGRE
C
consequent-postgres
databasejavascriptv2.0.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

initialize
✓ import { initialize } from 'consequent-postgres'
✗ const { initialize } = require('consequent-postgres')
ESM-only; CommonJS require is not supported.
ConsequentPostgres
✓ import type { ConsequentPostgres } from 'consequent-postgres'
✗ import { ConsequentPostgres } from 'consequent-postgres'
This is a TypeScript type, not a runtime value. Use 'import type' for types to avoid errors.
Actor
✓ import type { Actor, Event } from 'consequent-postgres'
✗ import { Actor } from 'consequent-postgres'
Actor and Event are TypeScript types/interfaces, not constructors.

Demonstrates initializing the PostgreSQL adapter, creating an actor store, storing and retrieving an actor snapshot, and closing the connection.

import { initialize } from 'consequent-postgres'; const adapter = initialize({ connectionString: process.env.DATABASE_URL ?? 'postgresql://user:password@localhost:5432/mydb' }); const actors = await adapter.actor.create('user'); await actors.store('user-123', 'a:1', { id: 'user-123', name: 'John Doe', email: 'john@example.com', lastEventId: 'evt-456', lastCommandId: 'cmd-789', lastCommandHandledOn: new Date().toISOString(), lastEventAppliedOn: new Date().toISOString() }); const actor = await actors.fetch('user-123'); await adapter.close();
Debug
Known issues
breakingVersion 2.0.0+ is ESM-only; requires Node >=18 and cannot be used with CommonJS require().
fix
Use import syntax and ensure your project is configured for ESM (e.g., type: module in package.json or .mjs extension).
affects: >=2.0.0
breakinginitialize() no longer accepts a callback; returns a promise. You must await it.
fix
Use const adapter = await initialize(config);
affects: >=2.0.0
deprecatedThe method `fetchByLastEventDate` is deprecated and may be removed in a future version.
fix
Use `fetchByLastEventId` with the appropriate event ID instead.
affects: >=2.0.0
gotchaThe adapter does not support siblings (multiple actor records per aggregate). Designed for microservice architectures where services own their database.
fix
Ensure your domain model does not require siblings; route writes by aggregate ID consistently.
affects: *
gotchaThe event store's `storeEvents` expects an array of events with a `vector` property as a string (e.g., 'a:1'). The vector must be provided; it is not auto-generated.
fix
Always include a vector string that matches the expected format (e.g., incrementing a version counter).
affects: *
Errors
Common errors & fixes
TypeError: Cannot use import statement outside a module
ESM-only package used in a CommonJS project without ESM configuration.
fix
Add "type": "module" to your package.json or rename file to .mjs.
Error: connect ECONNREFUSED ::1:5432
PostgreSQL is not running or connection string is incorrect.
fix
Ensure PostgreSQL is started and connectionString points to the correct host/port (e.g., localhost:5432).
TypeError: adapter.actor.create is not a function
Likely using `initialize` without await (common mistake in async context).
fix
Make sure to await the initialize() call: const adapter = await initialize(config);
Upgrade
Version history
2.0.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
21 hits · last 30 days
node
10
Bingbot
9
OpenAI (training)
1
Resources
consequent-postgres — npm install consequent-postgres · libregistry