Skip to main content

common@1.7.5

Functions

execute(operations)Promise

Execute a sequence of operations. Main outer API for executing expressions.

alterState(func)Operation

alias for "fn()"

fn(func)Operation

Creates a custom step (or operation) for more flexible job writing.

jsonValue(obj, path)Operation

Picks out a single value from a JSON object. If a JSONPath returns more than one value for the reference, the first item will be returned.

sourceValue(path)Operation

Picks out a single value from source data. If a JSONPath returns more than one value for the reference, the first item will be returned.

source(path)Array.<(String|Object)>

Picks out a value from source data. Will return whatever JSONPath returns, which will always be an array. If you need a single value use sourceValue instead.

dataPath(path)string

Ensures a path points at the data.

dataValue(path)Operation

Picks out a single value from the source data object—usually state.data. If a JSONPath returns more than one value for the reference, the first item will be returned.

referencePath(path)string

Ensures a path points at references.

lastReferenceValue(path)Operation

Picks out the last reference value from source data.

map(path, operation, state)State

Scopes an array of data based on a JSONPath. Useful when the source data has n items you would like to map to an operation. The operation will receive a slice of the data based of each item of the JSONPath provided.

asData(data, state)array

Simple switcher allowing other expressions to use either a JSONPath or object literals as a data source.

  • JSONPath referencing a point in state
  • Object Literal of the data itself.
  • Function to be called with state.
each(dataSource, operation)Operation

Scopes an array of data based on a JSONPath. Useful when the source data has n items you would like to map to an operation. The operation will receive a slice of the data based of each item of the JSONPath provided.

It also ensures the results of an operation make their way back into the state's references.

combine(operations)Operation

Combines two operations into one

join(targetPath, sourcePath, targetKey)Operation

Adds data from a target object

expandReferences(value, [skipFilter])Operation

Recursively resolves objects that have resolvable values (functions).

field(key, value)Field

Returns a key, value pair in an array.

fields(fields)Object

Zips key value pairs into an object.

merge(dataSource, fields)DataSource

Merges fields into each item in an array.

index()DataSource

Returns the index of the current array being iterated. To be used with each as a data source.

arrayToString(arr, separator)string

Turns an array into a string, separated by X.

toArray(arg)array

Ensures primitive data types are wrapped in an array. Does not affect array objects.

composeNextState(state, response)State

Prepares next state

humanProper(str)string

Substitutes underscores for spaces and proper-cases a string

scrubEmojis(text, replacementChars)string

Replaces emojis in a string.

chunk(array, chunkSize)Object

Chunks an array into an array of arrays, each with no more than a certain size.

each(dataSource, operation)Operation

Scopes an array of data based on a JSONPath. Useful when the source data has n items you would like to map to an operation. The operation will receive a slice of the data based of each item of the JSONPath provided.

It also ensures the results of an operation make their way back into the state's references.

expandRequestReferences(value)Operation

Recursively resolves objects that have resolvable values (functions), but omits HTTP request specific modules like FormData.

withAgent(params)Operation

Creates an https agent for axios from the agentOptions key passed in params.

get(requestParams)Operation

Make a GET request

post(requestParams)Operation

Make a POST request

del(requestParams)Operation

Make a DELETE request

head(requestParams)Operation

Make a HEAD request

put(requestParams)Operation

Make a PUT request

patch(requestParams)Operation

Make a PATCH request

options(requestParams)Operation

Make a OPTIONS request

execute(operations) ⇒ Promise

Execute a sequence of operations. Main outer API for executing expressions.

Kind: global function
Access: public

ParamTypeDescription
operationsOperationsOperations to be performed.

Example

execute(
create('foo'),
delete('bar')
)

alterState(func) ⇒ Operation

alias for "fn()"

Kind: global function

ParamTypeDescription
funcfunctionis the function

fn(func) ⇒ Operation

Creates a custom step (or operation) for more flexible job writing.

Kind: global function
Access: public

ParamTypeDescription
funcfunctionis the function

Example

fn(state => {
// do some things to state
return state;
});

jsonValue(obj, path) ⇒ Operation

Picks out a single value from a JSON object. If a JSONPath returns more than one value for the reference, the first item will be returned.

Kind: global function
Access: public

ParamTypeDescription
objobjectA valid JSON object.
pathStringJSONPath referencing a point in given JSON object.

Example

jsonValue({ a:1 }, 'a')

sourceValue(path) ⇒ Operation

Picks out a single value from source data. If a JSONPath returns more than one value for the reference, the first item will be returned.

Kind: global function
Access: public

ParamTypeDescription
pathStringJSONPath referencing a point in state.

Example

sourceValue('$.key')

source(path) ⇒ Array.<(String|Object)>

Picks out a value from source data. Will return whatever JSONPath returns, which will always be an array. If you need a single value use sourceValue instead.

Kind: global function
Access: public

ParamTypeDescription
pathStringJSONPath referencing a point in state.

Example

source('$.key')

dataPath(path) ⇒ string

Ensures a path points at the data.

Kind: global function
Access: public

ParamTypeDescription
pathstringJSONPath referencing a point in data.

Example

dataPath('key')

dataValue(path) ⇒ Operation

Picks out a single value from the source data object—usually state.data. If a JSONPath returns more than one value for the reference, the first item will be returned.

Kind: global function
Access: public

ParamTypeDescription
pathStringJSONPath referencing a point in data.

Example

dataValue('key')

referencePath(path) ⇒ string

Ensures a path points at references.

Kind: global function
Access: public

ParamTypeDescription
pathstringJSONPath referencing a point in references.

Example

referencePath('key')

lastReferenceValue(path) ⇒ Operation

Picks out the last reference value from source data.

Kind: global function
Access: public

ParamTypeDescription
pathStringJSONPath referencing a point in references.

Example

lastReferenceValue('key')

map(path, operation, state) ⇒ State

Scopes an array of data based on a JSONPath. Useful when the source data has n items you would like to map to an operation. The operation will receive a slice of the data based of each item of the JSONPath provided.

Kind: global function
Access: public

ParamTypeDescription
pathstringJSONPath referencing a point in state.data.
operationfunctionThe operation needed to be repeated.
stateStateRuntime state.

Example

map("$.[*]",
create("SObject",
field("FirstName", sourceValue("$.firstName"))
)
)

asData(data, state) ⇒ array

Simple switcher allowing other expressions to use either a JSONPath or object literals as a data source.

  • JSONPath referencing a point in state
  • Object Literal of the data itself.
  • Function to be called with state.

Kind: global function
Access: public

ParamTypeDescription
dataString | object | function
stateobjectThe current state.

Example

asData('$.key'| key | callback)

each(dataSource, operation) ⇒ Operation

Scopes an array of data based on a JSONPath. Useful when the source data has n items you would like to map to an operation. The operation will receive a slice of the data based of each item of the JSONPath provided.

It also ensures the results of an operation make their way back into the state's references.

Kind: global function
Access: public

ParamTypeDescription
dataSourceDataSourceJSONPath referencing a point in state.
operationOperationThe operation needed to be repeated.

Example

each("$.[*]",
create("SObject",
field("FirstName", sourceValue("$.firstName"))
)
)

combine(operations) ⇒ Operation

Combines two operations into one

Kind: global function
Access: public

ParamTypeDescription
operationsOperationsOperations to be performed.

Example

combine(
create('foo'),
delete('bar')
)

join(targetPath, sourcePath, targetKey) ⇒ Operation

Adds data from a target object

Kind: global function
Access: public

ParamTypeDescription
targetPathStringTarget path
sourcePathStringSource path
targetKeyStringTarget Key

Example

join('$.key','$.data','newKey')

expandReferences(value, [skipFilter]) ⇒ Operation

Recursively resolves objects that have resolvable values (functions).

Kind: global function
Access: public

ParamTypeDescription
valueobjectdata
[skipFilter]functiona function which returns true if a value should be skipped

field(key, value) ⇒ Field

Returns a key, value pair in an array.

Kind: global function
Access: public

ParamTypeDescription
keystringName of the field
valueValueThe value itself or a sourceable operation.

Example

field('destination_field_name__c', 'value')

fields(fields) ⇒ Object

Zips key value pairs into an object.

Kind: global function
Access: public

ParamTypeDescription
fieldsFieldsa list of fields

Example

fields(list_of_fields)

merge(dataSource, fields) ⇒ DataSource

Merges fields into each item in an array.

Kind: global function
Access: public

ParamTypeDescription
dataSourceDataSource
fieldsObjectGroup of fields to merge in.

Example

merge(
"$.books[*]",
fields(
field( "publisher", sourceValue("$.publisher") )
)
)

index() ⇒ DataSource

Returns the index of the current array being iterated. To be used with each as a data source.

Kind: global function
Access: public
Example

index()

arrayToString(arr, separator) ⇒ string

Turns an array into a string, separated by X.

Kind: global function
Access: public

ParamTypeDescription
arrarrayArray of toString'able primatives.
separatorstringSeparator string.

Example

field("destination_string__c", function(state) {
return arrayToString(dataValue("path_of_array")(state), ', ')
})

toArray(arg) ⇒ array

Ensures primitive data types are wrapped in an array. Does not affect array objects.

Kind: global function
Access: public

ParamTypeDescription
arganyData required to be in an array

Example

each(function(state) {
return toArray( dataValue("path_of_array")(state) )
}, ...)

composeNextState(state, response) ⇒ State

Prepares next state

Kind: global function
Access: public

ParamTypeDescription
stateStatestate
responseObjectResponse to be added

Example

composeNextState(state, response)

humanProper(str) ⇒ string

Substitutes underscores for spaces and proper-cases a string

Kind: global function
Access: public

ParamTypeDescription
strstringString that needs converting

Example

field("destination_string__c", humanProper(state.data.path_to_string))

scrubEmojis(text, replacementChars) ⇒ string

Replaces emojis in a string.

Kind: global function
Access: public

ParamTypeDescription
textstringString that needs to be cleaned
replacementCharsstringCharacters that replace the emojis

Example

scrubEmojis('Dove🕊️⭐ 29')

chunk(array, chunkSize) ⇒ Object

Chunks an array into an array of arrays, each with no more than a certain size.

Kind: global function
Access: public

ParamTypeDescription
arrayObjectArray to be chunked
chunkSizeIntegerThe maxiumum size of each chunks

Example

chunk([1,2,3,4,5], 2)

each(dataSource, operation) ⇒ Operation

Scopes an array of data based on a JSONPath. Useful when the source data has n items you would like to map to an operation. The operation will receive a slice of the data based of each item of the JSONPath provided.

It also ensures the results of an operation make their way back into the state's references.

Kind: global function
Access: public

ParamTypeDescription
dataSourceDataSourceJSONPath referencing a point in state.
operationOperationThe operation needed to be repeated.

Example

each("$.[*]",
create("SObject",
field("FirstName", sourceValue("$.firstName")))
)

expandRequestReferences(value) ⇒ Operation

Recursively resolves objects that have resolvable values (functions), but omits HTTP request specific modules like FormData.

Kind: global function
Access: public

ParamTypeDescription
valueobjectdata

withAgent(params) ⇒ Operation

Creates an https agent for axios from the agentOptions key passed in params.

Kind: global function

ParamTypeDescription
paramsobjectdata

get(requestParams) ⇒ Operation

Make a GET request

Kind: global function
Returns: Operation - - Function which takes state and returns a Promise
Access: public

ParamTypeDescription
requestParamsobjectSupports the exact parameters as Axios. See here

Example (Get an item with a specified id from state)

 get({
url: state => `https://www.example.com/api/items/${state.id},
headers: {"content-type": "application/json"}
});

post(requestParams) ⇒ Operation

Make a POST request

Kind: global function
Returns: Operation - - Function which takes state and returns a Promise
Access: public

ParamTypeDescription
requestParamsobjectSupports the exact parameters as Axios. See here

Example (Sending a payload with data that comes from state)

post({
url: "https://example.com",
data: (state) => state.data
});

Example ( Capturing the response for later use in state )

alterState((state) => {
return post({
url: "https://example.com",
data: (state) => state.data
})(state).then(({response}) => {
state.responseData = response.data
})
});

del(requestParams) ⇒ Operation

Make a DELETE request

Kind: global function
Returns: Operation - - Function which takes state and returns a Promise
Access: public

ParamTypeDescription
requestParamsobjectSupports the exact parameters as Axios. See here

Example (Deleting a record with data that comes from state)

delete({
url: state => `https://www.example.com/api/items/${state.id}`,
})(state);

head(requestParams) ⇒ Operation

Make a HEAD request

Kind: global function
Returns: Operation - - Function which takes state and returns a Promise
Access: public

ParamTypeDescription
requestParamsobjectSupports the exact parameters as Axios. See here

Example (Gets the headers that would be returned if the HEAD request's URL was instead requested with the HTTP GET method)

head({
url: 'https://www.example.com/api/items',
});

put(requestParams) ⇒ Operation

Make a PUT request

Kind: global function
Returns: Operation - - Function which takes state and returns a Promise
Access: public

ParamTypeDescription
requestParamsobjectSupports the exact parameters as Axios. See here

Example (Creates a new resource or replaces a representation of the target resource with the request payload, with data from state.)

put({
url: state => `https://www.example.com/api/items/${state.id}`,
data: state => state.data
});

patch(requestParams) ⇒ Operation

Make a PATCH request

Kind: global function
Returns: Operation - - Function which takes state and returns a Promise
Access: public

ParamTypeDescription
requestParamsobjectSupports the exact parameters as Axios. See here

Example (Applies partial modifications to a resource, with data from state.)

patch({
url: state => `https://www.example.com/api/items/${state.id}`,
data: state => state.data
});

options(requestParams) ⇒ Operation

Make a OPTIONS request

Kind: global function
Returns: Operation - - Function which takes state and returns a Promise
Access: public

ParamTypeDescription
requestParamsobjectSupports the exact parameters as Axios. See here

Example (Requests permitted communication options for a given URL or server, with data from state.)

options({
url: 'https://www.example.com/api/items',
});