Options
All
  • Public
  • Public/Protected
  • All
Menu

Data schema and validation

Index

Types

Json

Json: null | number | string | boolean | JsonArray | JsonObject

Simple Json type definition

Lookup

Lookup: (path: string) => Json

Type declaration

    • (path: string): Json
    • Type of lookup function used in validation rules.

      Parameters

      • path: string

      Returns Json

RuleFunc

RuleFunc: (param: Json, value: Json, lookup: Lookup, rules: Rules) => true | MgError

Type declaration

Rules

Rules: Record<string, RuleFunc>

Named set of Rule functions.

Schema

Schema: Record<string, Json>

The schema is modeled after JSON Schema.

SchemaDb

SchemaDb: Record<string, Schema>

Compiled schema.
You can lookup a schema by a normalized path.

Mdr

Mdr: { invalid?: boolean; error?: MgError; touched?: boolean; input?: string; value?: Json }

Mdr (abbreviation of Meta data record) is where meta data of each value of the model data comes.

Type declaration

  • Optional invalid?: boolean

    true if the value is invalid.

  • Optional error?: MgError

    Non-null if the value has error.

  • Optional touched?: boolean

    true if the user changed this value.

  • Optional input?: string

    Raw string of user input.

  • Optional value?: Json

    the value itself of this value.

Validate

Validate: (value: any, mdr: Mdr, schema: Schema, lookup: Lookup) => Mdr

Type declaration

Entries

Const nullable

  • nullable(type: string): boolean
  • Returns true if type specification allows null.

    Parameters

    • type: string

    Returns boolean

Const buildDb

defaultRules

defaultRules: Rules = ...

default validation rules. Rules prefixed by '$' is registered by its true name. Use defaultRules.if instead of defaultRules.$if.

Const validate

  • Validates a value with a schema. It is a shallow validation.

    Parameters

    • rules: Rules

      set of validation rules, which means that you can add your own rules.

    Returns Validate

Const applyRules

Const coerce

  • Executes coercion. Coercion is a process that interpretes a user input of string into a value of schema-specified type.

    Parameters

    Returns Mdr

Generated using TypeDoc