Skip to main content

Class: InMemoryPromptTemplateRepository

Defined in: adapters/in-memory/InMemoryPromptTemplateRepository.ts:39

InMemoryPromptTemplateRepository -- the prompt-template repository in a Map, for tests and the sandbox

About​

Behaves like a database without one: copies in and out, one entry per key + version.

Implements IPromptTemplateRepository so the PromptTemplateStore runs with no infrastructure.

  • Keeps every saved version; loadActive filters, listVersions pages by version number.
  • setActive flips the flags of one key in one call, as a real adapter does in one transaction.

Who needs it​

The gateway tests (gatewayConfigBase) and the dev sandbox; a host app uses its own adapter.

Usage​

When to use it​

Any test or local run that needs templates without a database.

When shouldn't use it​

Production: nothing survives the process.

Implements​

Constructors​

Constructor​

new InMemoryPromptTemplateRepository(): InMemoryPromptTemplateRepository

Returns​

InMemoryPromptTemplateRepository

Methods​

get()​

get(__namedParameters): Promise<IPromptTemplate | null>

Defined in: adapters/in-memory/InMemoryPromptTemplateRepository.ts:72

get -- one version of a key

About​

By key + version; null when it does not exist.

The template as stored, whole.

Who needs it​

PromptTemplateStore.activate, to check the version before it flips.

Parameters​

__namedParameters​
key​

EPromptTemplateKey

version​

number

Returns​

Promise<IPromptTemplate | null>

Implementation of​

IPromptTemplateRepository.get


listVersions()​

listVersions(__namedParameters): Promise<IPage<IPromptTemplate>>

Defined in: adapters/in-memory/InMemoryPromptTemplateRepository.ts:100

listVersions -- one page of a key's versions

About​

Highest version first; the cursors are version numbers.

endingBefore reads the limit versions below it, startingAfter the limit versions right above it (the page next to the cursor, not the highest). A cursor that is not a version of the key is a 404. The store has validated limit and that only one cursor is set.

Who needs it​

PromptTemplateStore.listVersions; addVersion, for the highest version so far.

Parameters​

__namedParameters​
key​

EPromptTemplateKey

page​

IPageArgs<number>

Returns​

Promise<IPage<IPromptTemplate>>

Implementation of​

IPromptTemplateRepository.listVersions


loadActive()​

loadActive(): Promise<IPromptTemplate[]>

Defined in: adapters/in-memory/InMemoryPromptTemplateRepository.ts:55

loadActive -- the active template of every key

About​

At most one per key.

Returns the versions whose isActive is set, in any order.

Who needs it​

PromptTemplateStore.getActive, when the active set is not cached.

Returns​

Promise<IPromptTemplate[]>

Implementation of​

IPromptTemplateRepository.loadActive


save()​

save(__namedParameters): Promise<void>

Defined in: adapters/in-memory/InMemoryPromptTemplateRepository.ts:153

save -- inserts or replaces one version

About​

Upsert by key + version.

The template is stored whole; the same key and version is replaced.

Who needs it​

PromptTemplateStore.addVersion.

Parameters​

__namedParameters​
template​

IPromptTemplate

Returns​

Promise<void>

Implementation of​

IPromptTemplateRepository.save


setActive()​

setActive(__namedParameters): Promise<void>

Defined in: adapters/in-memory/InMemoryPromptTemplateRepository.ts:173

setActive -- activates one version of a key

About​

One operation: the version becomes active, the others of the key inactive.

The version must exist; throws a 404 otherwise. A real adapter does the flip in one transaction, so no reader sees two active versions or none.

Who needs it​

PromptTemplateStore.activate.

Parameters​

__namedParameters​
key​

EPromptTemplateKey

version​

number

Returns​

Promise<void>

Implementation of​

IPromptTemplateRepository.setActive