Class: InMemoryTraceRepository
Defined in: adapters/in-memory/InMemoryTraceRepository.ts:28
InMemoryTraceRepository -- the trace repository in a Map, for tests and the sandbox
About
Behaves like a database without one: copies in and out, queries in insertion order.
Implements ITraceRepository so the Trace runs with no infrastructure. One entry per tenant + trace id, saving again
replaces it; from and to are inclusive. The raw request and result are kept: a test reads what the model was sent.
Who needs it
The gateway tests (gatewayConfigBase), the dev sandbox and the cookbook's first run; a host app uses its own adapter.
Pitfalls
Production: nothing survives the process, nothing is shared between processes.
Implements
Constructors
Constructor
new InMemoryTraceRepository():
InMemoryTraceRepository
Returns
InMemoryTraceRepository
Methods
anonymizeByUser()
anonymizeByUser(
__namedParameters):Promise<number>
Defined in: adapters/in-memory/InMemoryTraceRepository.ts:157
anonymizeByUser -- keeps a user's entries as an audit skeleton
About
GDPR pseudonymisation: the numbers stay, the words go.
userId becomes the pseudonym, request and result are removed; usage, cost, model, kind, chunk ids, issues and dates
stay. Returns how many.
Who needs it
Trace.anonymizeByUser, for the gateway's anonymizeUserData (D54).
Parameters
__namedParameters
pseudonym
string
tenantId
string
userId
string
Returns
Promise<number>
Implementation of
ITraceRepository.anonymizeByUser
delete()
delete(
__namedParameters):Promise<number>
Defined in: adapters/in-memory/InMemoryTraceRepository.ts:122
delete -- hard-deletes the entries of threads
About
"all": every entry of the tenant, the ones without a thread included.
Narrowed to one user when userId is given. Returns how many went.
Who needs it
Trace.delete, for the gateway's delete and deleteUserData (D54, D119).
Parameters
__namedParameters
tenantId
string
threadIds
userId?
string
Returns
Promise<number>
Implementation of
load()
load(
__namedParameters):Promise<ITraceEntry|null>
Defined in: adapters/in-memory/InMemoryTraceRepository.ts:63
load -- one entry by id
About
Null when the tenant has no entry with this id.
The entry as stored, whole.
Who needs it
Trace.annotate, before it merges the gateway's facts into the entry.
Parameters
__namedParameters
tenantId
string
traceId
string
Returns
Promise<ITraceEntry | null>
Implementation of
query()
query(
__namedParameters):Promise<ITraceEntry[]>
Defined in: adapters/in-memory/InMemoryTraceRepository.ts:89
query -- the entries of a tenant, filtered and paged
About
What matches
ITraceFilters, fromskip, at mostlimit.
User, thread, kind and the inclusive from / to dates narrow the set; the order is the adapter's.
Who needs it
Trace.query, for the host's audit pages.
Parameters
__namedParameters
filters
limit
number
skip
number
tenantId
string
Returns
Promise<ITraceEntry[]>
Implementation of
save()
save(
__namedParameters):Promise<void>
Defined in: adapters/in-memory/InMemoryTraceRepository.ts:44
save -- inserts or replaces one entry
About
Upsert by
entry.idwithin the tenant.
The entry whole. A repository that must not keep the raw request or result drops them here.
Who needs it
Trace.record, for every model call; Trace.annotate, to write the entry back.
Parameters
__namedParameters
entry
Returns
Promise<void>