Skip to main content

@terascope/data-mate / transforms/record-transform

transforms/record-transform

Variables

repository

const repository: Repository

Source

data-mate/src/transforms/record-transform.ts:6

Functions

copyField()

copyField(input, _parentContext, args): ts.AnyObject | null

Will copy a field to another field

Parameters

ParameterTypeDescription
inputRecordInput-
_parentContextRecordInput-
argsobject
args.fromstring-
args.tostring-

Returns

ts.AnyObject | null

object

Example

const obj = { hello: 'world', other: 'stuff' };
const config = { from: 'other', to: 'myCopy' };
const results = RecordTransform.copyField(cloneDeep(obj), cloneDeep(obj), config);
results; // { hello: 'world', other: 'stuff', myCopy: 'stuff' };

Source

data-mate/src/transforms/record-transform.ts:213


dedupe()

dedupe<T>(input, _parentContext?): T[] | null

returns an array with only unique values

Type parameters

Type parameterValue
Tany

Parameters

ParameterTypeDescription
inputany[]
_parentContext?unknown[]-

Returns

T[] | null

returns null if input is null/undefined

Example

const results = FieldTransform.dedupe([1, 2, 2, 3, 3, 3, undefined, 4])
results === [1, 2, 3, 4]

const results = RecordTransform.dedupe([
{ hello: 'world' },
{ hello: 'world' },
{ other: 'obj' },
])
results === [{ hello: 'world' }, { other: 'obj' }];

Source

data-mate/src/transforms/record-transform.ts:307


dropFields()

dropFields(input, _parentContext, args): ts.AnyObject | null

removes fields from a record

Parameters

ParameterTypeDescription
inputRecordInput-
_parentContextRecordInput-
argsobject
args.fieldsstring[]-

Returns

ts.AnyObject | null

object

Example

const obj = { hello: 'world', other: 'stuff', last: 'thing' };
const config = { fields: ['other', 'last']} ;
const results = RecordTransform.dropFields(cloneDeep(obj), cloneDeep(obj), config);
results; // { hello: 'world' };

Source

data-mate/src/transforms/record-transform.ts:167


renameField()

renameField(input, _parentContext, args): ts.AnyObject | null

This will migrate a fields value to a new field name

Parameters

ParameterTypeDescription
inputRecordInput-
_parentContextRecordInput-
argsobject
args.fromstring-
args.tostring-

Returns

ts.AnyObject | null

object

Example

const obj = { hello: 'world' };
const config = { from: 'hello', to: 'goodbye' };
const results = RecordTransform.renameField(cloneDeep(obj), cloneDeep(obj), config);
results === { goodbye: 'world' };

Source

data-mate/src/transforms/record-transform.ts:80


setField()

setField(input, _parentContext, args): ts.AnyObject | null

Sets a field on a record with the given value

Parameters

ParameterTypeDescription
inputRecordInput-
_parentContextRecordInput-
argsobject
args.fieldstring-
args.valueany-

Returns

ts.AnyObject | null

object

Example

const obj = { hello: 'world' };
const config = { field: 'other', value: 'stuff' };
const results = RecordTransform.setField(cloneDeep(obj), cloneDeep(obj), config);
results === { hello: 'world', other: 'stuff' };

Source

data-mate/src/transforms/record-transform.ts:125


transformRecord()

transformRecord(_input, _parentContext, _args): ts.AnyObject | null

Will execute a jexl expression. Can use data-mate functions inside the jexl expression. You do not need to specify the parent context argument as that is automatically the document used as to call it.

Parameters

ParameterType
_inputRecordInput
_parentContextRecordInput
_argsany

Returns

ts.AnyObject | null

object

Example

const obj = { hello: 'world', other: 'stuff' };
const config = { query: '[hello]', field: 'final' };
const results = RecordTransform.transformRecord(clone, clone, config)
results === { hello: 'world', other: 'stuff', final: ['world'] });

const obj = { foo: 'bar' };
const config = {
jexlExp: 'foo|extract({ jexlExp: "foo|toUpperCase" })', field: 'final'
};

const mixedData = [obj, undefined, null];

const results = RecordTransform.transformRecord(
mixedData, mixedData, config
)

results === [{ foo: 'bar', final: 'BAR' }];

Source

data-mate/src/transforms/record-transform.ts:279