Schema helpers for ClayDB resources
Last updated 3 months ago by realglobe .
Apache-2.0 · Repository · Bugs · Original npm · Tarball
$ cnpm install clay-policy 
SYNC missed versions from official npm registry.


Build Status npm Version JS Standard

Schema helpers for ClayDB resources

Table of Contents


$ npm install clay-policy --save


'use strict'

const clayPolicy = require('clay-policy')
const { STRING, DATE } = clayPolicy.DataTypes

async function tryPolicy () {
  const policy = clayPolicy({
    username: {
      type: STRING,
      required: true
    birthday: {
      type: DATE
    rank: {
      type: STRING,
      oneOf: [ 'GOLD', 'SLIVER', 'BRONZE' ]

  let error = policy.validate({
    username: 'hoge',
    rank: 'SUPER'
  console.error(error.detail.failures) // -> { rank: { reason: 'enums', expects: [ /* ... */ ], actual: 'ULTRA' } }

tryPolicy().catch((err) => console.error(err))

Field Restrictions

Restriction Type Description default
type Type of the field. Possible values are defined as DataTypes in clay-constants package.
oneOf array Enum values for the field (Only for STRING type)
required boolean Value is required for the field
default Default value of the field
unique boolean Add unique constraint on the field
uniqueFor array Names of attributes to make unique for
minimum number Minimum value of the field (Only for NUMBER type)
maximum number Maximum value of the field (Only for NUMBER type)
minLength integer Minimum length of the field
maxLength integer Maximum length of the field
trim boolean Trim value. (Only for STRING type)
pattern string Restrict value with pattern. (Only for STRING type)
multiple boolean Field can contain multiple value. Type restriction will be applied to each items

API Guide

Data Types

Available data types

  • DATE
  • NULL
  • REF
  • ID


This software is released under the Apache-2.0 License.


Today 0
This Week 0
This Month 24
Last Day 0
Last Week 0
Last Month 48
Dependencies (9)
Dev Dependencies (14)
Dependents (2)

Copyright 2014 - 2016 © |