Setu-TS
    Preparing search index...

    Interface ITransactionalIdempotencyStore

    The store port a tier-C (within) provider writes through: the work and its idempotency record commit in ONE transaction, so a lost race rolls the business writes back with the claim.

    Every method returns a promise that REJECTS on failure and never throws synchronously. A read requires kind to equal IDEMPOTENCY_RECORD_KIND, and a row of another kind is treated as missing; a custom store must honour both rules.

    0.9.0

    interface ITransactionalIdempotencyStore {
        find(id: string): Promise<TransactionalIdempotencyRecord | undefined>;
        purge(before: number, limit: number): Promise<number>;
        run<R>(
            claim: TransactionalIdempotencyClaim,
            work: (scope: unknown) => Promise<{ result: string; value: R }>,
        ): Promise<R>;
        verify(): Promise<void>;
    }
    Index
    • Deletes the rows of up to limit records whose expiresAt < before.

      Parameters

      • before: number

        Epoch milliseconds

      • limit: number

        Maximum records deleted

      Returns Promise<number>

      The number of records deleted

    • ONE transaction: creates the claim row (claim.id) FIRST, runs work with the transaction's scope, then creates the result row (${claim.id}.r) from the result work returns, and commits.

      Only creates — no update and no delete — so every supported backend can perform it. Rejects, rolling everything back, when a create or the commit is refused or when work throws.

      Type Parameters

      • R

        The caller's result type, unconstrained

      Parameters

      • claim: TransactionalIdempotencyClaim

        The claim to create first

      • work: (scope: unknown) => Promise<{ result: string; value: R }>

        The work, given the transaction's scope, returning the encoded result and the caller's value

      Returns Promise<R>

      What work returned

    • Refuses, at startup, a backend that cannot serve tier C, by name, by running exactly run's write pattern (two creates on distinct keys) in a transaction that always rolls back. Leaves no row.

      Returns Promise<void>

      A promise that rejects naming why the store cannot serve