UsageLimitStore
@forge/monorepo / backend/src / UsageLimitStore
Interface: UsageLimitStore
Defined in: backend/src/persistence/index.ts:657
Methods
applicable()
applicable(
input):Promise<readonlyUsageLimitRecord[]>
Defined in: backend/src/persistence/index.ts:694
Every limit that applies to this principal on this model — #182.
Not one limit. A person can be subject to a five-hour cap, a monthly cap and a per-model cap at once, and
all three bind: that is what "limits" means everywhere they are used in practice. Returning the single
most-specific one, as resolve does, meant a workspace-wide Opus cap was silently ignored for anybody who
also had a personal overall limit.
The rule is override within a scope, coexist across scopes. One row per (window, model), preferring
the principal's own row over the tenant default for that same scope — so a personal limit replaces the
workspace's for the same window and model, and does not replace one for a different window or model.
A model-scoped row applies only when modelId matches. With no modelId given, model-scoped rows do not
apply at all: an unknown model cannot be checked against a per-model allowance, and guessing would either
refuse the wrong work or let it through.
Implemented in the store, like resolve, because it is a rule — and a rule implemented at two call sites is
a rule with two behaviours. Conformance holds the adapters to the same one.
Parameters
input
TenantScope & object
Returns
Promise<readonly UsageLimitRecord[]>
list()
list(
input):Promise<readonlyUsageLimitRecord[]>
Defined in: backend/src/persistence/index.ts:699
Every configured limit for a tenant, for an admin screen.
Parameters
input
Returns
Promise<readonly UsageLimitRecord[]>
put()
put(
input):Promise<UsageLimitRecord>
Defined in: backend/src/persistence/index.ts:662
Set or replace one limit. Keyed on (tenant, principal, window), so an admin editing a limit updates it
rather than accumulating rows that a resolver would then have to disambiguate.
Parameters
input
TenantScope & object
Returns
Promise<UsageLimitRecord>
remove()
remove(
input):Promise<void>
Defined in: backend/src/persistence/index.ts:702
Remove one. Absent afterwards means "inherit the tenant default", not "zero".
Parameters
input
TenantScope & object
Returns
Promise<void>
resolve()
resolve(
input):Promise<UsageLimitRecord|null>
Defined in: backend/src/persistence/index.ts:671
The limit that applies to this principal in this period — most specific wins.
A principal's own row if there is one, else the tenant default, else null for unbounded. Resolved in the store rather than by the caller because "most specific wins" is a rule, and a rule implemented at two call sites is a rule with two behaviours.
Parameters
input
TenantScope & object
Returns
Promise<UsageLimitRecord | null>