@pwngh/economy-lab
    Preparing search index...

    Interface TrustStore

    Tracks how much each subject has spent recently — the risk gate's input. Two views: the store-level instance commits on its own connection, the Unit view writes inside the money transaction, so every attempt is counted exactly once whether its operation commits or rolls back.

    interface TrustStore {
        bump(
            subject: string,
            attempt: Attempt,
            options?: CallOptions,
        ): Promise<void>;
        read(subject: string, options?: CallOptions): Promise<Velocity>;
        record(
            subject: string,
            attempt: Attempt,
            options?: CallOptions,
        ): Promise<Velocity>;
    }
    Index
    • Idempotent on attempt.idempotencyKey, so a genuine retry doesn't double-count.

      Parameters

      Returns Promise<void>

    • The subject's velocity over the trailing window ending now; attempts age out as the window slides, with no fixed reset boundary. A subject with no live attempts reads as zero spent and zero attempts, so new subjects need no seeding.

      Parameters

      Returns Promise<Velocity>

    • Records the attempt (idempotent on attempt.idempotencyKey) and returns the subject's windowed velocity including it, in one atomic step serialized per subject — record-and-measure must be one step (the velocity-limit TOCTOU; see screenRisk in economy.ts).

      Parameters

      Returns Promise<Velocity>