Skip to content

Rulvar API reference


Rulvar API reference / @rulvar/store-sqlite / SqliteQuotaLimiter

Class: SqliteQuotaLimiter ​

Defined in: packages/store-sqlite/src/quota.ts:105

The cross-process reference implementation of the core QuotaLimiter SPI: engine processes pointing instances at ONE database file (this store's file or its own) enforce one global provider quota. Admission consumes the window counters inside a single BEGIN IMMEDIATE transaction, so two processes can never both take the last slot; reservations are rows, so reconcile settles a grant from any process; both tables are lazily pruned to the current and previous accounting window. The rule model, the fixed epoch-aligned one-minute windows, and the admission decision are the core's own exported functions, so this limiter and memoryQuotaLimiter agree on every verdict. The rules MUST be identical across coordinating processes (buckets key on rule content). Runtime contention queues briefly on the connection's busy_timeout (a hot limiter is EXPECTED to serialize); a call still busy past the bound throws, and the engine's onLimiterError policy decides what that means. Call close() when done.

Implements ​

Constructors ​

Constructor ​

ts
new SqliteQuotaLimiter(options): SqliteQuotaLimiter;

Defined in: packages/store-sqlite/src/quota.ts:114

Parameters ​

ParameterType
optionsSqliteQuotaLimiterOptions

Returns ​

SqliteQuotaLimiter

Methods ​

close() ​

ts
close(): void;

Defined in: packages/store-sqlite/src/quota.ts:358

Returns ​

void


reconcile() ​

ts
reconcile(
   reservationId, 
   usage, 
actual?): Promise<void>;

Defined in: packages/store-sqlite/src/quota.ts:254

Settles a reservation against the attempt's actual usage. The optional actual.requests is the TRUE number of wire requests the reservation ended up covering (RV905: an adapter absorbing provider-side continuations makes several wire calls inside one reserved dispatch); implementations add the difference over the single request the reservation admitted into the same window, so the request cap reflects what the provider actually metered. A settlement never denies retroactively: the wire calls already happened. Implementations written against the two-argument form remain valid; they merely keep the historical undercount.

Parameters ​

ParameterType
reservationIdstring
usageUsage
actual?{ requests?: number; }
actual.requests?number

Returns ​

Promise&lt;void&gt;

Implementation of ​

QuotaLimiter.reconcile


release() ​

ts
release(reservationId): Promise<void>;

Defined in: packages/store-sqlite/src/quota.ts:304

Cancels an UNUSED admission (RV1103, the optional SPI method from RV1013): exactly what admission consumed, the admitted requests and the token estimate, returns to the window, from any process sharing the file. Unknown ids, a double release, and a release after reconcile are no-ops (the row is gone); a rolled-over window already aged the estimate out, so only the row is deleted; a released id settles nothing afterwards. Mirrors memoryQuotaLimiter.release verdict for verdict.

Parameters ​

ParameterType
reservationIdstring

Returns ​

Promise&lt;void&gt;

Implementation of ​

QuotaLimiter.release


reserve() ​

ts
reserve(request): Promise<QuotaDecision>;

Defined in: packages/store-sqlite/src/quota.ts:191

Parameters ​

ParameterType
requestQuotaReservationRequest

Returns ​

Promise&lt;QuotaDecision&gt;

Implementation of ​

QuotaLimiter.reserve


snapshot() ​

ts
snapshot(): {
  requests: number;
  rule: QuotaRule;
  tokens: number;
  windowStart: number;
}[];

Defined in: packages/store-sqlite/src/quota.ts:340

Current-window counters per rule, for telemetry and referees.

Returns ​

{ requests: number; rule: QuotaRule; tokens: number; windowStart: number; }[]