Interface: IThreadRepository
Defined in: internal/thread-store/types.ts:313
Persistence seam. Only the store calls it.
Methods
acquireLease()
acquireLease(
args):Promise<boolean>
Defined in: internal/thread-store/types.ts:474
acquireLease -- takes the thread's lease atomically
About
Check-and-set (D77): one caller at a time on a thread.
Sets the lease to {token, expiresAt} and returns true only when the thread has no lease or its lease has expired at
now; otherwise changes nothing and returns false. One database operation (Mongo: findOneAndUpdate with the condition
in the filter), never a load followed by a save.
Who needs it
ThreadStore.acquireLease, before every call on a thread.
Parameters
args
expiresAt
Date
now
Date
tenantId
string
threadId
string
token
string
Returns
Promise<boolean>
anonymizeByUser()
anonymizeByUser(
args):Promise<IThreadCounts>
Defined in: internal/thread-store/types.ts:454
anonymizeByUser -- keeps a user's threads as skeletons
About
GDPR pseudonymisation: the words go, the record stays.
userId becomes the pseudonym, the title and the working memory are emptied, the status becomes CLOSED, the turns are
deleted; id, turnCount and dates stay. Returns how many of each.
Who needs it
ThreadStore.anonymizeByUser, for the gateway's anonymizeUserData.
Parameters
args
pseudonym
string
tenantId
string
userId
string
Returns
Promise<IThreadCounts>
appendTurn()
appendTurn(
args):Promise<void>
Defined in: internal/thread-store/types.ts:378
appendTurn -- stores one turn at the end of the thread
About
The order of appending is the order
loadTurnsreturns.
The turn whole: role, parts, dates. The thread's counts are the store's, saved with saveThread.
Who needs it
ThreadStore.appendTurn.
Parameters
args
tenantId
string
threadId
string
turn
Returns
Promise<void>
delete()
delete(
args):Promise<IThreadCounts>
Defined in: internal/thread-store/types.ts:435
delete -- hard-deletes threads with their turns and working memory
About
The listed ids, or every thread of the tenant for
"all".
Narrowed to one user when userId is given. An unknown id or one of another tenant or user is ignored. Returns the
counts of the threads and of the turns deleted.
Who needs it
ThreadStore.delete, for the gateway's delete and deleteUserData.
Parameters
args
tenantId
string
threadIds
userId?
string
Returns
Promise<IThreadCounts>
listThreadIds()
listThreadIds(
args):Promise<string[]>
Defined in: internal/thread-store/types.ts:417
listThreadIds -- the ids of the tenant's threads
About
Of one user when
userIdis given; deleted threads excluded.
The ids only, in any order, for a bulk operation over every thread.
Who needs it
ThreadStore.listThreadIds, for the gateway's delete with "all".
Parameters
args
tenantId
string
userId?
string
Returns
Promise<string[]>
listThreads()
Defined in: internal/thread-store/types.ts:360
listThreads -- one page of a user's threads
About
Newest first by
createdAt, the id as the tie-break (D37); the cursors are thread ids.
A thread whose deletedAt is set is not listed. endingBefore reads the limit threads older than it, startingAfter
the limit threads right after it (the page next to the cursor, not the newest). A cursor that is not a listed thread of
this user is a 404. The store has validated limit and that only one cursor is set.
Who needs it
ThreadStore.listThreads.
Parameters
args
page
tenantId
string
userId
string
Returns
loadThread()
loadThread(
args):Promise<IThread|null>
Defined in: internal/thread-store/types.ts:341
loadThread -- the thread of a tenant by id
About
As stored,
deletedAtincluded; null when the tenant has no thread with this id.
The thread record whole, without its turns.
Who needs it
ThreadStore.getThread and findThread.
Parameters
args
tenantId
string
threadId
string
Returns
Promise<IThread | null>
loadTurns()
loadTurns(
args):Promise<ITurn[]>
Defined in: internal/thread-store/types.ts:396
loadTurns -- a slice of the thread's turns
About
In the order they were appended, reversed when
desc;skipandlimitcut it.
The turns whole, as stored.
Who needs it
ThreadStore.getTurns and getLastTurns.
Parameters
args
desc
boolean
Newest first when true.
limit
number
skip
number
tenantId
string
threadId
string
Returns
Promise<ITurn[]>
releaseLease()
releaseLease(
args):Promise<void>
Defined in: internal/thread-store/types.ts:494
releaseLease -- gives the thread's lease back
About
Only the holder's token clears it.
Clears the lease when it carries this token; a lease another call took meanwhile stays.
Who needs it
ThreadStore.releaseLease, when the call ends.
Parameters
args
tenantId
string
threadId
string
token
string
Returns
Promise<void>
saveThread()
saveThread(
args):Promise<void>
Defined in: internal/thread-store/types.ts:327
saveThread -- inserts or replaces the thread
About
By
thread.idwithinthread.tenantId; the turns are not part of it.
The thread record whole: title, status, working memory, lease, dates.
Who needs it
ThreadStore.createThread, updateThread, appendTurn (the counts), setWorkingMemory.
Parameters
args
thread
Returns
Promise<void>