interbit-covenant-tools
v0.4.53
Published
Interbit platform covenants and covenant components
Downloads
9
Readme
interbit-covenant-tools
This library contains reusable covenant components that provide core functionality for managing template deployment and utilities that make it easier to write covenants that conform to standard patterns.
This library is intended to have a small footprint. Any PRs that add external dependencies will be scrutinized carefully and are likely to be rejected.
validate
interbit-covenant-tools
contains a lightweight and flexible validation library for validating action creators and action payloads within covenants.
Usage:
const {
validate,
objectValidationRules: { required, faIconPattern, chainIdPattern }
} = require('@btlgroup/interbit-covenant-tools')
const actionTypes = {
UPDATE_PROJECT: 'project/UPDATE_PROJECT',
REGISTER_PROJECT: 'project/REGISTER_PROJECT'
}
const actionCreators = {
updateProject: ({ projectName, description, icon, launchUrl }) => ({
type: actionTypes.UPDATE_PROJECT,
payload: validate(
{ projectName, description, icon, launchUrl }, // Object to validate
{ projectName: required(), icon: faIconPattern() } // Validation rules attached to properties
)
}),
registerProject: ({ parentChainId }) => ({
type: actionTypes.REGISTER_PROJECT,
payload: validate(
{ parentChainId }, // Object to validate
{ parentChainId: chainIdPattern() } // Validation rules attached to properties
)
})
}