Skip to main content

store

@rotorsoft/act-root


@rotorsoft/act-root / act/src / store

Variable: store()

const store: (adapter?) => Store

Defined in: libs/act/src/ports.ts:267

Gets or injects the singleton event store.

By default, Act uses an in-memory store suitable for development and testing. For production, inject a persistent store like PostgresStore before building your application.

Important: Store injection must happen before creating any Act instances. Once set, the store cannot be changed without restarting the application.

Parameters

adapter?

Store

Optional store implementation to inject

Returns

Store

The singleton store instance

Examples

import { store } from "@rotorsoft/act";

const currentStore = store(); // Returns InMemoryStore
import { store } from "@rotorsoft/act";
import { PostgresStore } from "@rotorsoft/act-pg";

// Inject before building your app
store(new PostgresStore({
host: "localhost",
port: 5432,
database: "myapp",
user: "postgres",
password: "secret",
schema: "public",
table: "events"
}));

// Now build your app - it will use PostgreSQL
const app = act()
.withState(Counter)
.build();
import { store } from "@rotorsoft/act";
import { PostgresStore } from "@rotorsoft/act-pg";

if (process.env.NODE_ENV === "production") {
store(new PostgresStore({
host: process.env.DB_HOST,
port: parseInt(process.env.DB_PORT || "5432"),
database: process.env.DB_NAME,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD
}));
}
// Development uses default in-memory store
import { store } from "@rotorsoft/act";

beforeEach(async () => {
// Reset store between tests
await store().seed();
});

afterAll(async () => {
// Cleanup
await store().drop();
});

See

  • Store for the store interface
  • InMemoryStore for the default implementation
  • PostgresStore for production use