# Transform

Declares transforms by name for use in policies, views, cursors, etc.

For backwards compatibility (cortex < 2.13.0), any transform not assigned a name takes on the `export` property of the library in which it is defined.

A transform can extend `require('runtime.transform').Transform` or not. If it does, the transform can tweak the default limits for the `each()` cycle in the constructor.

See the section on scripting transforms for more examples.

```javascript
const { transform } = require('decorators'),
      { Transform } = require('runtime.transform')

@transform('c_random_transform', { environment: 'production', weight: 1 })
class AddRandomTransform extends Transform {

    constructor(transformOptions, runtimeOptions) {
      super({
        opsThreshold: 0.65, // defaults to .8. exits the each() cycle after 65% ops usage.
        msThreshold: 0.65,  // defaults to .8. exits the each() cycle after 65% time usage.
        minMs: 1000, // defaults to null. exits the each() cycle when less that minMs time is left.
        minOps: 100000 // defaults to null. exits the each() cycle when less that minOps ops are left.
      })
    }

    each( object ) {
        return { ...object, random: Math.random() }
    }

    // a particularly long running after script could cause the transform to
    // fail so the defaults have been tweaked.
    after() {

    }

}
```

## @transform(name, options) / @transform(options)

*Arguments*

* `options` { Object } Options object
  * `name` { String } The custom (`c_`) name of the transform. Used to register and override existing transforms.
  * `environment` { String = *"\*"* } Limits registering to an environment. Possible values (\*, production, development).
  * `weight` { Number = *0* } The transform weight.&#x20;

## Constructor Options

* `transformOptions` { Object } Unused
* `runtimeOptions` { Object } Options passed to the transform class constructor
  * `runtime` { Object }
    * `name` { String }
    * `environment` { String = *"\*"* }
    * `weight` { Number = *0* }
    * `metadata` { Object }
      * `resource` { String }
      * `className` { String }
      * `methodName` { String }
      * `static` { Boolean }
      * `loc` { Object }
        * `line` { String }
        * `column` { String }


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.medable.com/cortex-api/decorators/static/transform.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
