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.

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.

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 updated