DataConnector

Factory class to define a bunch of action handlers.

Type parameters

Type parameterValue
P extends PatchItemPatch

Constructors

new DataConnector()

new DataConnector<P>(client): DataConnector<P>

Parameters

ParameterType
clientDataConnectorClient

Returns

DataConnector<P>

new DataConnector()

new DataConnector<P>(client, optPatchParser): DataConnector<P>

Parameters

ParameterType
clientDataConnectorClient
optPatchParserP extends ItemPatch ? never : PatchParser<P>

Returns

DataConnector<P>


Properties

actions

actions: Record<string, object | object> = {};

routes

routes: Record<string, DataConnectorRoute> = {};

Methods

defineAction()

defineAction<T>(
   name, 
   request, 
asynchronous): DataConnector<P>

Factory to define an action request handler

Type parameters

Type parameter
T extends string

Parameters

ParameterTypeDefault value
nameTundefined
requestActionTypeForName<P, T, boolean>undefined
asynchronousbooleanfalse

Returns

DataConnector<P>


defineAsynchronousAction()

defineAsynchronousAction<T>(name, request): DataConnector<P>

Factory to define an asynchronous action request handler

Type parameters

Type parameter
T extends string

Parameters

ParameterType
nameT
requestActionTypeForName<P, T, true>

Returns

DataConnector<P>


defineRoute()

defineRoute(name, request): DataConnector<P>

Factory to define a route handler

Parameters

ParameterType
namestring
requestDataConnectorRoute

Returns

DataConnector<P>


routeDebugServer()

routeDebugServer(options): ExpressAppLike

Add a route to the given express app (or generate a new app) to serve this data connector

Parameters

ParameterType
optionsRunDebugServerOptions

Returns

ExpressAppLike


runAction()

runAction(
   url, 
   headers, 
body): Promise<object>

Call a defined action handler and gather its serialized response

Parameters

ParameterType
urlstring
headersRecord<string, undefined | string | string[]>
bodyunknown

Returns

Promise<object>

body
body: unknown;
status
status: number;

runDebugServer()

runDebugServer(options): void

Serve this data connector as a simple express app for debugging purposes

Parameters

ParameterType
optionsRunDebugServerOptions

Returns

void