LogoLogo
  • Introduction
  • Features
  • Getting Started
    • Cortex User Guide
      • Organizations
      • Log in
      • Generate an API key
      • Make your first API request
      • Configure the org settings
      • Set up a data model
        • Create custom objects
        • Add custom properties
      • One-to-many relationships
      • Read and write data
      • Making a Request
      • Handling responses
      • Authentication
      • Two-factor authentication
      • Set third-party cookies
      • Connections
      • Upload files
      • Cortex iOS
      • Get started with Swift
      • Cortex service accounts
      • Cortex developer tools
      • Automated Account Notifications
  • Cortex API
    • Overview
    • Objects
      • Objects Overview
      • Organization
      • Account
      • Connections
      • Notifications
      • Stats
      • Logs
      • Export
      • Events
      • Room
    • Object Definition
      • Object Properties
        • Any
        • Binary
        • Boolean
        • Date
        • Document
        • File
        • Geometry
        • List
        • Number
        • ObjectId
        • Reference
        • String
    • Object Types
    • Access Control
    • Querying
      • Query Operators
      • Property Selection
      • Property Access
    • Aggregating
      • Aggregation Operators
    • Scripting
      • Script Types
      • Script Limits
      • ObjectId
      • CortexObject
        • Accounts
        • Views
      • Cursors
      • Operations
      • Script Modules
        • API Module
        • Base64 Module
        • Cache Module
        • Connections Module
        • Console Module
        • Consts Module
        • Counters Module
        • Crypto Module
        • HTTP Module
        • Logger Module
        • Notifications Module
        • Request Module
        • Response Module
        • SAML Module
        • Schemas Modules
        • Script Module
        • Session Module
        • Util.id Module
        • Util.ip Module
        • Util.paths Module
        • XML Module
        • Developer
        • Config
        • Renderer
        • SFTP
        • FTP
        • DB
          • Cursors
          • Driver
      • Static Methods
        • Accounts
        • Views
        • Cursors
      • Audit
      • Environments
      • HTTP Driver
      • Notifications
        • Firebase Cloud Messaging (FCM)
        • Tencent Push Notification Service Configuration
      • Televisit
      • Transforms
      • Localization
      • Available Javascript Libraries
    • Decorators
      • Runtime
        • Acl
        • As
        • Log
        • Profile
      • Static
        • Env
        • Job
        • Object
        • On
        • Policy
        • Route
        • Transform
        • Trigger
    • Expressions
      • Primer
      • Pipelines
      • Operators
      • Accumulators
      • Variables
      • Conditionals
      • Transforms
      • Triggers
      • On
      • Events
    • Faults
      • Fault Reference
  • Releases
    • Cortex Release Notes
      • Cortex API 2.28.3 (R3.4.6)
      • Cortex API 2.28.1 (R3.4.3)
      • Cortex API 2.27.2 (R3.4.1)
      • Cortex API 2.27.1 (R3.3.5)
      • SQL DB Connector 1.3.4 (R3.3.3)
      • Cortex API 2.26.2 (R3.3.1)
      • Cortex API 2.26.1 (R3.2.2)
      • Cortex API 2.26.0 (R3.2.1)
      • SQL DB Connector 1.3.3
      • Cortex API 2.25.0 (R3.1.1)
      • SQL DB Connector 1.3.2 (R3.1.0)
      • Cortex API 2.24.2 (R3.0.2)
      • SQL DB Connector 1.3.1 (R3.0.0)
      • Cortex API 2.24.1 (R2.3.3)
      • Cortex API 2.24.0 (R2.3.2)
      • SQL DB Connector 1.3.0 (R2.3.0)
      • Cortex API 2.23.0 (R2.2.4)
      • SQL DB Connector 1.2.0 (R2.2.0)
      • Cortex API 2.22.2 (R2.1.2)
      • Cortex API 2.22.1 and SQL DB Connector 1.1.1 (R2.0.1)
      • Cortex API 2.22.0
      • Cortex API 2.21.3
      • Cortex API 2.21.2
      • Cortex Web 4.16.0
      • Cortex Web 4.15.1
      • Cortex API 2.20.1
      • Cortex Web 4.14.0
      • Cortex Renderer 1.3.3
      • Cortex API 2.19.4
      • Cortex API 2.19.3 and Cortex Web 4.13.1
      • Cortex Renderer 1.3.2
      • Cortex API 2.19.1
      • Cortex API 2.18.0
      • Cortex API 2.17.6
      • Cortex API 2.17.5
      • Cortex API 2.17.4
      • Cortex API 2.17.3
      • Cortex API 2.17.2
      • Cortex API 2.17.1
      • Cortex API 2.16.0
      • Cortex API 2.15.9
      • Cortex API 2.15.8-1
      • Cortex 2.15.8
      • Cortex API 2.18.1
      • Cortex API 2.16.1
      • Cortex Renderer 1.3.1
      • Cortex Renderer 1.3.0
      • Cortex Renderer 1.2.2
      • Cortex Renderer 1.2.1
      • Cortex Renderer 1.2.0
    • Third-Party License Attribution

© 2025 Medable, Inc. All rights reserved.

On this page

Was this helpful?

  1. Cortex API
  2. Decorators

Static

Static Decorators

Using static decorators, a script can declare environment behavior that is picked up and merged into the runtime. Because static decorators are processed at compile-time, they must not include variables in their declarations.

Only object expressions, array literals, primitives, and numeric literals preceded by the - unary expression are allowed.

const { job } = require('decorators'),
      cron = '*/10 * * * *'

class Jobs {

  @job(cron) // invalid. contains a variable
  @job('*/10 * * * *') // valid
  @job('*/10 * * * *', { weight: -1 }) // valid
  @job('*/10 * * * *', { weight: +1 }) // invalid
  @job('*/10 * * * *', { weight: 1 }) // valid
  @job('*/10 * * * *', { principal: script.principal }) // invalid
  @job('*/10 * * * *', { principal: consts.principals.anonymous }) // invalid. contains a variable
  @job('*/10 * * * *', { principal: 'anonymous' }) // valid
  doJob() {
  }
}

Stored objects, scripts and policies can be named, and must be unique. If declared with a static decorator, a developer can override named items by duplicating the name and assigning a greater weight. See each decorator's documentation for runtime sorting details. the default weight is 0.

const { job } = require('decorators')     

// overrides a saved job script by the same name
class Jobs {

  @job('*/10 * * * *', { name: 'c_existing_job', weight: 1})
  doJob() {    
  }  
}

// overrides the statically declared job of the same name and changes the job frequency
class CustomJobs extends Jobs {

  @job('*/5 * * * *', { name: 'c_existing_job', weight: 2})
  doJob(...args) {    
    super.doJob(...args)
  }  
}

Any number of decorators may stack on top of one another and will all be added to the runtime. Although their order is determined by weight and priority (depending on the type), not the order in which they are declared.

const { route, trigger } = require('decorators')
class Foo {

  @route('GET foos/:param') // called second
  getFoos() {    
  }  

  @route('GET foos/bars', { priority: 10 }) // called first.        
  getFooBars() {
  } 

}

If two or more similarly named static decorator declarations are made that share the same weight, the one selected is arbitrary and must be determined via examining the environment runtime to determined which was selected (org.runtime). As such, it's recommended to always assign weights to named declarations.

const { route } = require('decorators')
class Foo {

  @route('GET foos', { c_name: 'c_existing_saved_foo_route' }) // may or may not be selected, though only 1 will be added.
  getFoos() {  
  }  

  @route('GET bars', { c_name: 'c_existing_saved_bar_route', weight: 1 }) // overrides saved route script with default weight
  getBars() {  
  }

  @route('GET foos', { priority: 999 }) // no name, so will stack and run based on priority alone.
  @route('GET bars', { priority: 999 }) 
  getBeforeBars({ body, next }) {
    if (body.isArray()) {
      body(body.getLength(), 'pushed')
    }
    next() // allow the next route to run.
  }

}

When combining static environment decorators with runtime decorators, the order of the decorators does not apply; static decorators are always applied prior to the script being allocated a sandbox.

In the following example, the principal will be c_service_account_with_site_manager_role even though @as precedes @route (which runs as the runtime caller by default) because @as is evaluated at runtime. Also, the route will only allow a caller with the c_site_manager role to run the route because the @as decorator does not assign the c_service_account_with_site_manager_role until after the @route has been evaluated.

const { as, route } = require('decorators')
class Foo {

  @as('c_service_account_with_site_manager_role')
  @route('GET foos', { acl: 'role.c_site_manager'})
  getFoos() {
    return script.principal // c_service_account
  }  

}

Last updated 3 years ago

Was this helpful?