Classes · @purista/nats-config-store

NatsConfigStore

Config store backed by a NATS JetStream key-value bucket.

Signature

NatsConfigStore.ts typescript
class NatsConfigStore

Examples

example-1.ts typescript
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.features')
await store.destroy()

Constructors

1 entry

constructor

Constructor

Source
constructor.ts typescript
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.ts typescript
cache: ConfigStoreCacheMap

Optional local cache used by store implementations that opt in.

config

Property

config.ts typescript
config: { cacheTtl: number; enableCache: boolean; enableGet: boolean; enableRemove: boolean; enableSet: boolean; keyValueStoreName: string; ... }

Store configuration including operation toggles and cache settings.

connection

Property

Source
connection.ts typescript
connection: NatsConnection | undefined

Active NATS connection, created lazily by `getStore`.

kv

Property

Source
kv.ts typescript
kv: KV | undefined

Cached JetStream key-value bucket handle.

logger

Property

logger.ts typescript
logger: Logger

Child logger scoped to the store name.

name

Property

name.ts typescript
name: string

Store name used in logs and diagnostics.

sc

Property

Source
sc.ts typescript
sc: Codec<unknown>

JSON codec used to encode and decode values in the key-value bucket.

Methods

8 entries

destroy

Method

Source
destroy.ts typescript
destroy(): Promise<void>

Drains and closes the NATS connection and clears cached handles.

getConfig

Method

getConfig.ts typescript
getConfig<ConfigNames>(...configNames: ConfigNames): Promise<ObjectWithKeysFromStringArray<ConfigNames>>

Returns the values for given config properties.

getConfigImpl

Method

Source
getConfigImpl.ts typescript
getConfigImpl<ConfigNames>(...stateNames: ConfigNames): Promise<ObjectWithKeysFromStringArray<ConfigNames>>

This method must be overwritten by actual store implementation.

getStore

Method

Source
getStore.ts typescript
getStore(): Promise<KV>

Returns a healthy JetStream key-value bucket handle.

removeConfig

Method

removeConfig.ts typescript
removeConfig(configName: string): Promise<void>

Removes the config item given by config name.

removeConfigImpl

Method

Source
removeConfigImpl.ts typescript
removeConfigImpl(stateName: string): Promise<void>

This method must be overwritten by actual store implementation.

setConfig

Method

setConfig.ts typescript
setConfig(configName: string, configValue: unknown): Promise<void>

Sets a config value.

setConfigImpl

Method

Source
setConfigImpl.ts typescript
setConfigImpl(stateName: string, stateValue: unknown): Promise<void>

This method must be overwritten by actual store implementation.