Classes · @purista/nats-config-store
NatsConfigStore
Config store backed by a NATS JetStream key-value bucket.
Signature
class NatsConfigStore Examples
const store = new NatsConfigStore({
servers: 'nats:___PH0___
keyValueStoreName: 'purista-config-store',
})
await store.setConfig('tenant.acme.prod.app.features', { checkout: true })
const config = await store.getConfig('tenant.acme.prod.app.features39;)
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 config store.
Properties
7 entries
cache
Property
cache: ConfigStoreCacheMap Optional local cache used by store implementations that opt in.
config
Property
config: { cacheTtl: number; enableCache: boolean; enableGet: boolean; enableRemove: boolean; enableSet: boolean; keyValueStoreName: string; ... } Store configuration including operation toggles and cache settings.
connection
Property
connection: NatsConnection | undefined Active NATS connection, created lazily by `getStore`.
kv
Property
kv: KV | undefined Cached JetStream key-value bucket handle.
logger
Property
logger: Logger Child logger scoped to the store name.
name
Property
name: string Store 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.
getConfig
Method
getConfig<ConfigNames>(...configNames: ConfigNames): Promise<ObjectWithKeysFromStringArray<ConfigNames>> Returns the values for given config properties.
getConfigImpl
Method
getConfigImpl<ConfigNames>(...stateNames: ConfigNames): Promise<ObjectWithKeysFromStringArray<ConfigNames>> This method must be overwritten by actual store implementation.
getStore
Method
getStore(): Promise<KV> Returns a healthy JetStream key-value bucket handle.
removeConfig
Method
removeConfig(configName: string): Promise<void> Removes the config item given by config name.
removeConfigImpl
Method
removeConfigImpl(stateName: string): Promise<void> This method must be overwritten by actual store implementation.
setConfig
Method
setConfig(configName: string, configValue: unknown): Promise<void> Sets a config value.
setConfigImpl
Method
setConfigImpl(stateName: string, stateValue: unknown): Promise<void> This method must be overwritten by actual store implementation.