Decorators

Runtime Decorators

Define feature flags, experiments, progressive rollouts, tenant boundaries, scheduling, and resource quotas with AxilJS semantic decorators.

6 min readUpdated DocumentationEdit this page
On this page16

Runtime decorators describe operational policies that affect feature availability, tenant boundaries, scheduling, and resource consumption.

They express runtime intent as metadata. A cloud platform, scheduler, or other runtime consumer can interpret that metadata and apply the corresponding policy without coupling application code to a specific runtime implementation.

Note

This page covers the Runtime decorator category. It is not the @axiljs/runtime package: that package executes tAudit, tRetry, tTimeout and tRedact / tSensitive, and none of the decorators below. See Runtime.

@tFeatureFlag

Declares that an operation is gated by a feature flag.

TypeScript
TS
1import { tFeatureFlag } from '@axiljs/decorator'
2
3@tFeatureFlag('new-checkout')
4async checkout() {}
5
6@tFeatureFlag('ai-search', { fallback: 'legacy-search' })
7async search(query: string) {}

Feature flags allow runtime consumers to control whether functionality is available without changing the method's implementation.

@tExperiment

Declares an A/B or multivariate experiment.

TypeScript
TS
1import { tExperiment } from '@axiljs/decorator'
2
3@tExperiment({
4  name: 'checkout-v2',
5  variants: ['control', 'new']
6})
7async checkout() {}

An optional key names the value used to assign variants (for example 'userId').

The decorator describes the experiment and its variants so an external runtime or experimentation system can determine how execution should be assigned.

@tRollout

Declares a progressive rollout percentage for a feature or operation.

TypeScript
TS
1import { tRollout } from '@axiljs/decorator'
2
3@tRollout({ percentage: 10 })
4async newFeature() {}

This allows a runtime consumer to gradually expose functionality rather than enabling it for every request at once.

@tTenant

Declares that an operation requires a tenant context.

TypeScript
TS
1import { tTenant } from '@axiljs/decorator'
2
3@tTenant()
4async findUsers() {}
5
6@tTenant({ strategy: 'subdomain' })
7async getTenantData() {}

The tenant context can be resolved according to the strategy understood by the runtime consumer.

@tTenantBoundary

Declares a tenant isolation boundary for an operation.

TypeScript
TS
1import { tTenantBoundary } from '@axiljs/decorator'
2
3@tTenantBoundary('strict')
4async updateUser() {}

Boundary levels

LevelDescription
'strict'Cross-tenant access is forbidden
'soft'Cross-tenant access is logged
'admin'Cross-tenant access is allowed for administrators

This makes the intended tenant boundary explicit at the operation level.

@tCrossTenant

Explicitly declares that an operation is authorized to access data across tenant boundaries.

Because cross-tenant operations are sensitive, they can be composed with audit semantics.

TypeScript
TS
1import { tCrossTenant, tAudit } from '@axiljs/decorator'
2
3@tCrossTenant({ reason: 'platform-admin' })
4@tAudit({ action: 'cross-tenant.inspect' })
5async inspectTenant(tenantId: string) {}

The reason documents why cross-tenant access is permitted, while tAudit provides an explicit audit requirement for the operation.

@tSchedule

Declares that a method should run according to a cron schedule or interval.

TypeScript
TS
1import { tSchedule } from '@axiljs/decorator'
2
3@tSchedule('0 */5 * * *')
4async syncProducts() {}
5
6@tSchedule({
7  cron: '0 0 * * *',
8  timezone: 'Asia/Karachi',
9  overlap: 'skip' // 'skip' | 'queue' | 'allow'
10})
11async dailyCleanup() {}

The options form also accepts interval (ms) instead of cron, and a name.

Scheduling semantics remain separate from the scheduler implementation. A runtime scheduler can consume the metadata and determine when the operation should execute.

@tQuota

Declares a tenant resource quota that an operation consumes.

TypeScript
TS
1import { tQuota } from '@axiljs/decorator'
2
3@tQuota({
4  resource: 'api_calls',
5  amount: 1
6})
7async makeApiCall() {}
8
9@tQuota({
10  resource: 'ai.tokens',
11  amount: 1000
12})
13async generateSummary() {}

Quotas can represent API calls, AI tokens, or other runtime-managed resources.

@tResource

Declares resource requirements for an operation.

TypeScript
TS
1import { tResource } from '@axiljs/decorator'
2
3@tResource({
4  cpu: '500m',
5  memory: '256Mi'
6})
7async generateReport() {}

A runtime scheduler can use these requirements when deciding where and how the operation should execute.

@tInterval

Declares a recurring execution interval.

TypeScript
TS
1import { tInterval } from '@axiljs/decorator'
2
3@tInterval(30_000)
4async healthCheck() {}

The value represents the requested interval in milliseconds.

@tDelay

Declares a delay before execution.

TypeScript
TS
1import { tDelay } from '@axiljs/decorator'
2
3@tDelay(5000)
4async warmUpCache() {}

The delay is expressed in milliseconds.

@tRunAt

Declares a specific execution time.

TypeScript
TS
1import { tRunAt } from '@axiljs/decorator'
2
3@tRunAt('2025-12-31T23:59:59Z')
4async newYearTask() {}

The timestamp is declared as metadata so a scheduling consumer can determine when the operation should run.

Combining Runtime Semantics

Runtime decorators can be composed when an operation has multiple independent runtime requirements.

For example, a scheduled operation can also consume a tenant quota:

TypeScript
TS
1import {
2  tSchedule,
3  tQuota
4} from '@axiljs/decorator'
5
6@tSchedule('0 * * * *')
7@tQuota({
8  resource: 'api_calls',
9  amount: 1
10})
11async syncTenantData() {}

Each decorator describes a separate concern. A scheduler can consume the scheduling metadata, while a quota system can consume the resource constraint.

Semantic Consumer Model

AxilJS decorators do not need to own the runtime implementation.

The application declares intent:

TypeScript
TS
1@tFeatureFlag('new-checkout')
2@tRollout({ percentage: 10 })
3@tQuota({ resource: 'api_calls', amount: 1 })
4async checkout() {}

Independent consumers can interpret these declarations:

  • A feature-flag system evaluates tFeatureFlag.
  • A rollout system evaluates tRollout.
  • A quota system evaluates tQuota.
  • A scheduler consumes tSchedule, tInterval, tDelay, or tRunAt.
  • A tenant-aware runtime evaluates tTenant, tTenantBoundary, and tCrossTenant.

This separation keeps runtime semantics explicit while avoiding unnecessary coupling between application code and a particular infrastructure implementation.

Reference

DecoratorPurpose
tFeatureFlagGate functionality behind a feature flag
tExperimentDeclare an A/B or multivariate experiment
tRolloutDefine progressive rollout percentage
tTenantRequire tenant context
tTenantBoundaryDefine tenant isolation behavior
tCrossTenantAuthorize explicit cross-tenant access
tScheduleDeclare cron or interval scheduling
tQuotaDeclare resource quota consumption
tResourceDeclare runtime resource requirements
tIntervalDefine recurring execution interval
tDelayDefine an execution delay
tRunAtDefine a specific execution timestamp

Runtime decorators turn operational requirements into explicit, machine-readable semantics. The application describes what an operation requires; runtime infrastructure can decide how those requirements are enforced.

Was this page helpful?

Help improve the documentation

AxilJS is open source and documentation improvements are welcome.

AxilJS DocumentationMIT License · Built by SyntaxilitY