@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
Parameter | Type | Description |
---|---|---|
input | RecordInput | - |
_parentContext | RecordInput | - |
args | object | |
args.from | string | - |
args.to | string | - |
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 parameter | Value |
---|---|
T | any |
Parameters
Parameter | Type | Description |
---|---|---|
input | any [] | |
_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
Parameter | Type | Description |
---|---|---|
input | RecordInput | - |
_parentContext | RecordInput | - |
args | object | |
args.fields | string [] | - |
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
Parameter | Type | Description |
---|---|---|
input | RecordInput | - |
_parentContext | RecordInput | - |
args | object | |
args.from | string | - |
args.to | string | - |
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
Parameter | Type | Description |
---|---|---|
input | RecordInput | - |
_parentContext | RecordInput | - |
args | object | |
args.field | string | - |
args.value | any | - |
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
Parameter | Type |
---|---|
_input | RecordInput |
_parentContext | RecordInput |
_args | any |
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' }];