Transforms
Script transforms operate on results and cursors to transform them in-flight. Transforms can be applied to Views, Policies and inline for Cursors and BulkOperations.
class Transform
const { transform } = require('decorators-transform')
@transform
class Transformer {
/**
* Called if there is an error in the source operation. If the method
* does not throw an error, Cortex throws the original error.
*
* @param err {Fault} thrown fault.
*/
error(err) {
throw err
}
/**
* Called if the result is not a cursor (but a single result value).
* The method must return a result if it's to be transformed. If the
* method does not return a value, Cortex outputs the original result value.
*
* @param result {*}
* @returns {*}
*/
result(result) {
return result
}
/**
* Cursor handler called only once and before all other processing.
*
* @param memo { Object } An empty object that can be modified and is saved
* for the duration of the transformation.
* @param cursor {Cursor} The output cursor.
*/
beforeAll(memo, { cursor }) {
}
/**
* Cursor handler called before each script run, and shares
* the current script context with each and after.
*
* @param memo { Object }
* @param cursor {Cursor}
*/
before(memo, { cursor }) {
}
/**
* Cursor handler called with each cursor object. Returning undefined
* filters the object from the output stream.
*
* @param object { Object } the current output document
* @param memo { Object }
* @param cursor {Cursor}\
* @returns {*} a value to be pushed to the output cursor.
*/
each(object, memo, { cursor }) {
return object
}
/**
* Cursor handler called after before() and each() was called.
*
* @param memo { Object }
* @param cursor {Cursor}
* @param count { Number } The number of documents pushed by the script
* runtime during the current execution.
*/
after(memo, { cursor, count }) {
}
/**
* Cursor handler called only once and after the cursor is exhausted.
*
* @param memo { Object }
* @param cursor {Cursor}
*/
afterAll(memo, { cursor }) {
}
}Types
Policy Transform
View Transform
Inline Cursor Transform
Bulk Operations
Examples
CSV View Transform
Inline CSV Transform
Account Policy
Last updated
Was this helpful?