Skip to content

@yantrix/automata v0.6.0 • Docs


Yantrix API / @yantrix/automata / createPromiseDataAdapter

Function: createPromiseDataAdapter() ​

ts
function createPromiseDataAdapter<EventType, EventMetaType, InputData, OutputData>(opts): [IDataSource<EventType, EventMetaType, OutputData>, IDataDestination<EventType, EventMetaType, null, InputData, OutputData>]

Creates a Data Source and a Data Destination that are connected by a function that resolves a Promise with input data and returns the result as an event.

Type Parameters ​

• EventType extends number

• EventMetaType extends Record<EventType, any>

• InputData extends object

• OutputData = any

Parameters ​

• opts

• opts.id?: string

An optional id for the Data Source and Data Destination

• opts.requestEvents: null | EventType[]

An array of event names that should trigger the request

• opts.requestMapper

A function that maps an event to input data

• opts.resolver

A function that resolves a Promise with input data

• opts.responseMapper

A function that maps the result of the resolver to an event

Returns ​

[IDataSource<EventType, EventMetaType, OutputData>, IDataDestination<EventType, EventMetaType, null, InputData, OutputData>]

  • An array with the Data Source and the Data Destination