Skip to content

Configuration

Providence's configuration options allow you to customize some of its automation. Each state management plugin comes with its own default settings for Providence that handle translating its functionality. Providence tries as much as possible to configure with sane defaults, but you will likely have to override at least a few settings, such as the :js:attr:netCall <ProvidenceClient.netCall> setting in the :js:class:client <ProvidenceClient>.

@opencraft/providence


Interface: GlobalOptions

Defined in: types/GlobalOptions.ts:16

The GlobalOptions object is used to provide context to Providence. Most of the settings (especially those of the transformers) should be provided automatically by the plugin for your state manager. However, some client` functions may need customizing, and you'll want to set up your own validators for any form field validation.

Properties

client

client: ProvidenceClient

Defined in: types/GlobalOptions.ts:23

The client contains functions for contacting your API and deriving data from it. In most cases you will want to customize at least the netCall function.

A default implementation, baseCall, is available.


drivers

drivers: Drivers

Defined in: types/GlobalOptions.ts:39

The Drivers are the means by which we perform meta-operations with the client store, like adding or removing a module. You should not have to set these settings unless you're making your own state management library adapter.


registries

registries: () => ProvidenceRegistries

Defined in: types/GlobalOptions.ts:44

A function which returns the registries' singleton. We make this a function so it can be ignored as a dependency more easily by reactive client frameworks-- otherwise we might have infinite loop changes.

Returns

ProvidenceRegistries


transformers

transformers: Transformers

Defined in: types/GlobalOptions.ts:33

The transformers are a set of functions that adapt the internal structure of Providence objects into something the client state management libraries can use. Unless you're writing a plugin to support a new state management backend, you should not need to specify these manually. The existing plugin should specify them for you.

However, there may be some edge case, for testing or other instrumentation, where you need to spy on relevant calls on all controllers, or otherwise transform their data. You can do so here if you need such functionality.


validators

validators: Validators

Defined in: types/GlobalOptions.ts:50

The set of validators used for field validation. By default, only the example 'email' validator is included. Each key in this object will be used as a reference name for the validators on a field.

@opencraft/providence


Interface: Transformers

Defined in: types/Transformers.ts:7

Properties

controller

controller: \<T>(controller) => T

Defined in: types/Transformers.ts:22

Transforms a generated providence controller in any way necessary to provide its essential functions to the target state manager.

Type Parameters
T

T extends BaseController\<any>

Parameters
controller

T

Any dynamically generated controller, such as a SingleController, that is built by Providence.

Returns

T


fielder

fielder: \<T>(patcher) => T

Defined in: types/Transformers.ts:36

Transforms a generated fielder in any way necessary to provide its essential functions to the target state manager.

Type Parameters
T

T extends Fielder\<any, any>

Parameters
patcher

T

Returns

T


module

module: \<T>(module) => T

Defined in: types/Transformers.ts:14

Transforms a providence module into a pluggable format the target state manager will understand.

Type Parameters
T

T extends BaseModule\<any, any, any>

Parameters
module

T

Any dynamically generated module, such as a Single, that is built by Providence.

Returns

T


patcher

patcher: \<T>(patcher) => T

Defined in: types/Transformers.ts:29

Transforms a generated patcher in any way necessary to provide its essential functions to the target state manager.

Type Parameters
T

T extends Patcher\<any, any>

Parameters
patcher

T

A dynamically generated Patcher.

Returns

T

@opencraft/providence


Interface: ProvidenceClient

Defined in: types/ProvidenceClient.ts:11

Properties

paginator

paginator: Paginator

Defined in: types/ProvidenceClient.ts:41

The paginator is an object full of functions that instruct Providence in how to handle pagination for your API.

Methods

deriveErrors()

deriveErrors\<T>(val, knownFields): FormErrorSet

Defined in: types/ProvidenceClient.ts:37

A function that takes an error raised by netCall and returns a FormErrorSet.

Type Parameters
T

T

Parameters
val

AxiosError

An error raised by netCall when making a network request.

knownFields

keyof T[]

The fields the current interface is aware of. This makes it easy to notice missing fields your frontend doesn't know about but you received an error for-- the ones you don't provide are put into a global error section instead so your users can report them to you.

Returns

FormErrorSet


deriveForm()

deriveForm\<T, K>(args): K

Defined in: types/ProvidenceClient.ts:28

Takes an AxiosResponse from the server and returns the data from the form endpoint.

Type Parameters
T

T

K

K = T

Parameters
args

DeriveFormArgs\<T>

Returns

K


deriveList()

deriveList\<T>(args): PaginationResult\<T>

Defined in: types/ProvidenceClient.ts:24

Takes an AxiosResponse from the server and returns a list with pagination info.

Type Parameters
T

T

Parameters
args

DeriveListArgs\<T>

Returns

PaginationResult\<T>


deriveSingle()

deriveSingle\<T>(args): T

Defined in: types/ProvidenceClient.ts:20

Given an AxiosResponse and the current state of the single module, derive a single from the response.

Type Parameters
T

T

Parameters
args

DeriveSingleArgs\<T>

Returns

T


netCall()

netCall\<T, K>(opts): Promise\<AxiosResponse\<K, any, { }, any>>

Defined in: types/ProvidenceClient.ts:16

A wrapper around Axios's request function. Define this to include things like Authentication headers in your network requests.

Type Parameters
T

T

K

K = T

Parameters
opts

NetCallOptions\<T>

Returns

Promise\<AxiosResponse\<K, any, { }, any>>

@opencraft/providence


Interface: Drivers

Defined in: types/Drivers.ts:4

Properties

makeModuleFactory

makeModuleFactory: (store) => ModuleFactory

Defined in: types/Drivers.ts:13

The makeModuleFactory function should take the upstream library's store, whatever shape it may come in, and create a function which allows you to add a module to this store, if given a MakeModuleOptions object.

This function should return a function, which takes no arguments and returns nothing, that will remove the module from the store.

Parameters
store

any

Returns

ModuleFactory


makeProxyFactory

makeProxyFactory: (store) => StoreProxyFactory

Defined in: types/Drivers.ts:19

The makeProxyFactory function should take the upstream library's store, whatever shape it may come in, and create a function which builds a proxy BoundStore if given a MakeModuleOptions object.

Parameters
store

any

Returns

StoreProxyFactory