createQuotaGuard
@forge/monorepo / backend/src / createQuotaGuard
Function: createQuotaGuard()
createQuotaGuard(
deps):object
Defined in: backend/src/usage/quota.ts:305
Parameters
deps
Returns
admit()
admit(
context,about?):Promise<QuotaDecision>
Decide whether a run may start — AC-2.
Reads the current period's rollup, not the ledger: admission is on the hot path of every message, and a check that scanned raw events would make the platform slower in proportion to how much it had been used.
Parameters
context
about?
QuotaSubject = {}
Returns
Promise<QuotaDecision>
assertAdmitted()
assertAdmitted(
context,about?):Promise<QuotaDecision>
Throws the refusal, for a caller that would rather not branch. Same decision, different ergonomics.
Parameters
context
about?
QuotaSubject = {}
Returns
Promise<QuotaDecision>
explain()
explain(
context,about?):Promise<readonlyQuotaExplanation[]>
Every limit with its usage and its reset — #183.
A limit nobody can see is a limit that surprises people, and once several apply at once "how much have I
got left" stops being answerable by reading one number. This is the same read the refusal path uses, so
a panel cannot disagree with enforcement about either the figure or the reset time — the failure that a
second implementation of "how full is it" always eventually produces.
Ordered as the resolver ordered them, shortest span first, which puts the limit most likely to stop you at the top without the caller having to sort by anything.
Parameters
context
about?
QuotaSubject = {}
Returns
Promise<readonly QuotaExplanation[]>
limits()
limits(
context,about?):Promise<readonlyQuotaLimits[]>
The limits in force for this context — an empty list for unlimited.
Exposed so a UI can render "you have used X of Y" without a second source for Y — a panel that took its limit from configuration while enforcement took it from here would eventually disagree, and the version a user sees would be the wrong one.
Parameters
context
about?
QuotaSubject = {}
Returns
Promise<readonly QuotaLimits[]>