2.1.13 • Published 6 years ago

clay-policy v2.1.13

Weekly downloads
219
License
Apache-2.0
Repository
github
Last release
6 years ago

clay-policy

Build Status npm Version JS Standard

Schema helpers for ClayDB resources

Table of Contents

Installation

$ npm install clay-policy --save

Usage

'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']
    }
  })

  const 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

RestrictionTypeDescriptiondefault
typeType of the field. Possible values are defined as DataTypes in clay-constants package.
oneOfarrayEnum values for the field (Only for STRING type)
requiredbooleanValue is required for the field
defaultDefault value of the field
uniquebooleanAdd unique constraint on the field
uniqueForarrayNames of attributes to make unique for
minimumnumberMinimum value of the field (Only for NUMBER type)
maximumnumberMaximum value of the field (Only for NUMBER type)
minLengthintegerMinimum length of the field
maxLengthintegerMaximum length of the field
trimbooleanTrim value. (Only for STRING type)
patternstringRestrict value with pattern. (Only for STRING type)
multiplebooleanField can contain multiple value. Type restriction will be applied to each items

API Guide

Data Types

Available data types

  • NUMBER
  • STRING
  • BOOLEAN
  • DATE
  • OBJECT
  • NULL
  • REF
  • ENTITY
  • ID

License

This software is released under the Apache-2.0 License.

Links

2.1.13

6 years ago

2.1.12

6 years ago

2.1.11

7 years ago

2.1.10

7 years ago

2.1.9

7 years ago

2.1.8

7 years ago

2.1.7

7 years ago

2.1.6

8 years ago

2.1.5

8 years ago

2.1.4

8 years ago

2.1.2

8 years ago

2.1.1

8 years ago

2.0.17

8 years ago

2.0.16

8 years ago

2.0.15

8 years ago

2.0.14

8 years ago

2.0.13

8 years ago

2.0.12

8 years ago

2.0.11

8 years ago

2.0.10

8 years ago

2.0.9

8 years ago

2.0.8

8 years ago

2.0.7

8 years ago

2.0.6

8 years ago

2.0.5

8 years ago

2.0.4

8 years ago

2.0.3

8 years ago

2.0.2

8 years ago

2.0.1

8 years ago