Skip to content

Latest commit

 

History

History
168 lines (96 loc) · 4.45 KB

api.md

File metadata and controls

168 lines (96 loc) · 4.45 KB

clay-policy@2.1.12

Schema helpers for ClayDB resources

Functions

create(args) -> ClayPolicy

Create a ClayPolicy instance

Param Type Description
args *

isPolicy(obj) -> boolean

Param Type Description
obj *

ClayPolicy Class

Type restrictions for clay entity

new ClayPolicy(properties)

Constructor of ClayPolicy class

Param Type Description
properties Object Property config

policy.validate(entity, options) -> PolicyError

Validate an entity

Param Type Description
entity ClayEntity Entity to validate
options Object Optional settings
options.prefix string Error message prefix
options.namespace string Namespace for each fields
options.ignoreMissing boolean Ignore missing

policy.format(entity) -> ClayEntity

Format entity values. Note this method is DESTRUCTIVE.

Param Type Description
entity ClayEntity Entity to format

policy.validateToThrow(entity, options)

Validate an entity and throw error if failed.

Param Type Description
entity ClayEntity Entity to validate
options Object Optional settings

policy.uniqueFilters(entity) -> Array.<Object>

Define unique filter objects for entity

Param Type Description
entity ClayEntity Entity to work with

policy.defaultsFor(entity) -> Object

Get defaults values for an entity. This method does NOT update the passed entity

Param Type Description
entity ClayEntity

policy.testRestriction(restriction, value, options) -> Object

Validate a property value

Param Type Description
restriction PropertyRestriction Property restriction
value * Property value
options Object Optional settings

policy.hasRestrictionFor(name) -> boolean

Check if has restriction for a field

Param Type Description
name string Field name

policy.clone() -> ClayPolicy

Clone this policy

policy.toValues() -> Object

Convert into JSON compatible values

policy.toDigest() -> string

To digest string