Classes · @purista/nats-state-store
NatsStateStore
State store backed by a NATS JetStream key-value bucket.
Signature
class NatsStateStoreExamples
const store = new NatsStateStore({
servers: 'nats:___PH0___
keyValueStoreName: 'purista-state-store',
})
await store.setState('tenant.acme.prod.cart.session-123', { step: 'shipping' })
const state = await store.getState('tenant.acme.prod.cart.session-12339;)
await store.destroy()Constructors
1 entry
constructor
Constructor
new constructor(config?: { cacheTtl: number; enableCache: boolean; enableGet: boolean; enableRemove: boolean; enableSet: boolean; keyValueStoreName: string; ... })Creates a NATS JetStream-backed state store.
Properties
6 entries
config
Property
config: { cacheTtl: number; enableCache: boolean; enableGet: boolean; enableRemove: boolean; enableSet: boolean; keyValueStoreName: string; ... }Store configuration including operation toggles.
connection
Property
connection: NatsConnection | undefinedActive NATS connection, created lazily by `getStore`.
kv
Property
kv: KV | undefinedCached JetStream key-value bucket handle.
logger
Property
logger: LoggerChild logger scoped to the store name.
name
Property
name: stringStore name used in logs and diagnostics.
sc
Property
sc: Codec<unknown>JSON codec used to encode and decode values in the key-value bucket.
Methods
8 entries
destroy
Method
destroy(): Promise<void>Drains and closes the NATS connection and clears cached handles.
getState
Method
getState<StateNames>(...stateNames: StateNames): Promise<ObjectWithKeysFromStringArray<StateNames>>Get one or more state values by name.
getStateImpl
Method
getStateImpl<StateNames>(...stateNames: StateNames): Promise<ObjectWithKeysFromStringArray<StateNames>>Adapter-specific state lookup implementation.
getStore
Method
getStore(): Promise<KV>Returns a healthy JetStream key-value bucket handle.
removeState
Method
removeState(stateName: string): Promise<void>Remove one state value by name.
removeStateImpl
Method
removeStateImpl(stateName: string): Promise<void>Adapter-specific state removal implementation.
setState
Method
setState(stateName: string, stateValue: unknown): Promise<void>Store or replace one state value.
setStateImpl
Method
setStateImpl(stateName: string, stateValue: unknown): Promise<void>Adapter-specific state write implementation.