Search…
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.
1
const { transform } = require('decorators'),
2
{ Transform } = require('runtime.transform')
3
4
@transform('c_random_transform', { environment: 'production', weight: 1 })
5
class AddRandomTransform extends Transform {
6
7
constructor(transformOptions, runtimeOptions) {
8
super({
9
opsThreshold: 0.65, // defaults to .8. exits the each() cycle after 65% ops usage.
10
msThreshold: 0.65, // defaults to .8. exits the each() cycle after 65% time usage.
11
minMs: 1000, // defaults to null. exits the each() cycle when less that minMs time is left.
12
minOps: 100000 // defaults to null. exits the each() cycle when less that minOps ops are left.
13
})
14
}
15
16
each( object ) {
17
return { ...object, random: Math.random() }
18
}
19
20
// a particularly long running after script could cause the transform to
21
// fail so the defaults have been tweaked.
22
after() {
23
24
}
25
26
}
Copied!

@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.

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 }
Last modified 2mo ago