Skip to main content

InMemoryNegotiationStore

@totemsdk/edge


@totemsdk/edge / InMemoryNegotiationStore

Class: InMemoryNegotiationStore

In-memory negotiation store. No crash guarantees — for development and tests only. Production must supply a durable implementation.

Implements​

Constructors​

Constructor​

new InMemoryNegotiationStore(outbox?): InMemoryNegotiationStore

Parameters​

outbox?​

OutboxStore

Returns​

InMemoryNegotiationStore

Methods​

compareAndSet()​

compareAndSet(negotiationId, expectedRevision, next): Promise<boolean>

Atomically replace the record only if its current revision equals expectedRevision. Returns false when the record was advanced by another writer (stale transition).

Parameters​

negotiationId​

string

expectedRevision​

number

next​

NegotiationRecord

Returns​

Promise<boolean>

Implementation of​

NegotiationStore.compareAndSet


create()​

create(record): Promise<void>

Parameters​

record​

NegotiationRecord

Returns​

Promise<void>

Implementation of​

NegotiationStore.create


get()​

get(negotiationId): Promise<NegotiationRecord | undefined>

Parameters​

negotiationId​

string

Returns​

Promise<NegotiationRecord | undefined>

Implementation of​

NegotiationStore.get


getOutbox()​

getOutbox(): OutboxStore

Expose the outbox read/write surface (dev mode + tests).

Returns​

OutboxStore


listRecoverable()​

listRecoverable(): Promise<NegotiationRecord[]>

List recoverable (non-terminal) negotiations.

Returns​

Promise<NegotiationRecord[]>

Implementation of​

NegotiationStore.listRecoverable


listUndelivered()​

listUndelivered(): Promise<OutboxEntry[]>

Returns​

Promise<OutboxEntry[]>


markOutboxDelivered()​

markOutboxDelivered(messageId): Promise<void>

Parameters​

messageId​

string

Returns​

Promise<void>


transitionAndEnqueue()​

transitionAndEnqueue(negotiationId, expectedRevision, next, outboxMessages): Promise<boolean>

Atomically perform a negotiation CAS AND enqueue outbox messages in ONE durable transaction. Returns false when the CAS failed (stale revision).

For SQLite/Postgres this MUST be a single DB transaction so that the economic transition and the protocol response commit or fail together.

The default falls back to a two-step (non-transactional) sequence. A durable store MUST override this to keep the crash window closed.

Parameters​

negotiationId​

string

expectedRevision​

number

next​

NegotiationRecord

outboxMessages​

OutboxMessage[]

Returns​

Promise<boolean>

Implementation of​

NegotiationStore.transitionAndEnqueue