Type Definitions
TDatabridgeName
A valid name for databridge resources like sources and streams. Specifically, a string of three or more characters starting with a letter and containing only letters, digits, and underscores.
Type:
-
string
TDatabridgeNamePath
A valid name path for potntially nested databridge resources streams. Can be a single valid databridge name as a string, or an array of valid databridge names.
Type:
-
DatabridgeName
|Array.<DatabridgeName>
FDataFetcher()
A valid data fetcher definition. This can be either a single data fetcher callback, or, a potentially nested plain object containing multiple data fether callbacks where all key names are valid databridge resource names.
FDataFetcherCallback() → {PlainObject|Promise}
A data fetcher callback should fetch the data for a given data source, and return it in the form of a plain object that can be serialised to a JSON string.
The data fetched should be formatted as a single JavaScript value that can be serialised to a JSON string without error. The callback can return the data directly, or, return a promise of that data.
The fetcher function can accept arbitrarily many parameters.
When invoked by the databridge, the special this
variable within the
callback will be mapped to the Datasource object
the callback belongs to.
This:
- Datasource
Returns:
- Type:
-
PlainObject
|Promise
must return a plain object that can be serialised as a JSON string, or, a promise that resolves to same.
TPlainObject
A JavaScript plain object as per the isPlainObject() function from validateParams.
Type:
-
Object
FStreamNameGenerator(fetcherParams, fetchOptions) → {DatabridgeName}
A stream name generator callback should convert a list of parpameters for a data fetcher into a unique stream name. This is vital to ensure caching behaves as expected with data fetchers which will be called with varying parameter values.
For exmaple, imagine we have a data fetcher that gets a list of movies released in a given year, and the year is passed as the only argument to the data fetcher. A separate cache needs to be created for each year, and that separation is achieved with the stream name.
If you don't specify your own stream name, or stream name generator, the module use the default stream name generator Datasource.defaultStreamNameGenerator() which will do the right thing most of the time.
- See:
-
- Datasource.defaultStreamNameGenerator
This:
- Datasource
Parameters:
Name | Type | Description |
---|---|---|
fetcherParams |
Array
|
the parameters being passed to the data fetcher. |
fetchOptions |
PlainObject
|
the options passed to the databridge's fetch function. |