@squidcloud/backend
    Preparing search index...

    Function limits

    • A decorator that can be used to rate/quota limit a function. In its simplest form, the decorator can take the query rate that is allowed for the given function and/or how many total calls are permitted and will enforce those limits.

      It will either execute the function or return an Error if the rate/quota limits are exceeded.

      Rate Limit behavior:

      • The rate limit unit is QPS (Queries Per Second).
      • Bursts of up to 3x the given rate are permitted.
      • The consumption bucket refills gradually.

      Quota Limit behavior:

      • Has a renewPeriod field that defaults to "monthly".
      • The "monthly" period is defined as 30 days.
      • The "quarterly" period is defined as 90 days.
      • Renews occur at the top of the hour (##:00 for HH:mm).
      • No carry-over of unused quota from one period to the next.
      • Changes to the limit value for a specific limit combo (function & scope & renewPeriod) will reset the active count. For example, if a user has made 10 calls and the limit is changed from 20 to 15, the user will be able to make 15 more calls (not 5).

      Limits can be defined with more specifics and multiple limits can be defined for a single function.

      Examples:

      • Basic definition using defaults:
        @limits({ rateLimit: 5 }) // Only rate limit.
        @limits({ quotaLimit: 20 }) // Only quota limit.
        @limits({ rateLimit: 5, quotaLimit: 20 }) // Both rate and quota.
        Defaults to "global" scope and "monthly" renewPeriod.
      • As objects defining scope and renewPeriod:
        @limits({
        rateLimit: {
        value: 5,
        scope: 'global'
        },
        quotaLimit: {
        value: 20,
        scope: 'global',
        renewPeriod: 'monthly'
        }
        })
      • As arrays of objects defining scope and renewPeriod
        @limits({
        rateLimit: [
        { value: 5, scope: 'global' },
        { value: 2, scope: 'user' }
        ],
        quotaLimit: [
        { value: 20, scope: 'global', renewPeriod: 'monthly' },
        { value: 5000, scope: 'ip', renewPeriod: 'annually' }
        ]
        })

      All matching limits are consumed for each call. For example, an "IP" scoped limit will be consumed in addition to a "global" scoped limit.

      Parameters

      • options: LimiterConfig

        LimiterConfig object specifying what kind of limits are desired.

      Returns ActionMethodDecorator<LimitsAction>