Options
All
  • Public
  • Public/Protected
  • All
Menu

human-schema NPM version Downloads Build Status

Human Schema is a user-friendly declarative schema system similar to JSONSchema but: simpler, more geospatial types, and built with intuitive UI generation in mind. This library should be used in conjunction with other libraries in the ecosystem like iris-ql, object-transform-stack, and others.

Install

npm install human-schema --save

Basic Schema Example

{
  "id": "911-call",
  "name": "911 Call",
  "notes": "A 911 call.",
  "schema": {
    "receivedAt": {
      "name": "Received",
      "type": "date",
      "validation": {
        "required": true
      }
    },
    "dispatchedAt": {
      "name": "Dispatched",
      "type": "date"
    },
    "arrivedAt": {
      "name": "Arrived",
      "type": "date"
    },
    "units": {
      "name": "Units",
      "type": "array",
      "validation": {
        "notEmpty": true,
        "maxItems": 2048
      },
      "items": {
        "name": "Unit ID",
        "type": "text",
        "validation": {
          "required": true,
          "notEmpty": true,
          "maxLength": 2048
        }
      }
    },
    "officers": {
      "name": "Officers",
      "type": "array",
      "validation": {
        "notEmpty": true,
        "maxItems": 2048
      },
      "items": {
        "name": "Officer ID",
        "type": "text",
        "validation": {
          "required": true,
          "notEmpty": true,
          "maxLength": 2048
        }
      }
    },
    "code": {
      "name": "Code",
      "type": "text",
      "validation": {
        "notEmpty": true,
        "maxLength": 2048
      }
    },
    "type": {
      "name": "Type",
      "type": "text",
      "validation": {
        "notEmpty": true,
        "maxLength": 2048
      }
    },
    "notes": {
      "name": "Notes",
      "type": "text",
      "validation": {
        "notEmpty": true
      }
    },
    "images": {
      "name": "Images",
      "type": "array",
      "validation": {
        "notEmpty": true,
        "maxItems": 2048
      },
      "items": {
        "name": "Image",
        "type": "text",
        "validation": {
          "required": true,
          "image": true
        }
      }
    },
    "address": {
      "name": "Address",
      "type": "text",
      "validation": {
        "notEmpty": true,
        "maxLength": 2048
      }
    },
    "location": {
      "name": "Location",
      "type": "point",
      "validation": {
        "required": true
      }
    }
  }
}

DB Support

If you optionally want deep geospatial validation, you can provide a postgres connection to an instance with PostGIS installed. In the future, via node-gdal-next this library will handle deep geo validation without querying a DB.

Index

Namespaces

Variables

Functions

Variables

Const utils

utils: { isValidCoordinate: (__namedParameters: Coordinate) => string | true; isValidGeoJSON: __module; isValidGeometry: __module; lat: (lat: number) => string | true; lon: (lon: number) => string | true } = ...

Type declaration

  • isValidCoordinate: (__namedParameters: Coordinate) => string | true
      • (__namedParameters: Coordinate): string | true
      • Parameters

        • __namedParameters: Coordinate

        Returns string | true

  • isValidGeoJSON: __module
  • isValidGeometry: __module
  • lat: (lat: number) => string | true
      • (lat: number): string | true
      • Parameters

        • lat: number

        Returns string | true

  • lon: (lon: number) => string | true
      • (lon: number): string | true
      • Parameters

        • lon: number

        Returns string | true

Functions

Const clean

  • clean(dataType: DataType): DataType
  • Parameters

    • dataType: DataType

    Returns DataType

Const validate

  • validate(dataType: DataType, __namedParameters?: { full: any }): true | object[]
  • Parameters

    • dataType: DataType
    • __namedParameters: { full: any } = ...

    Returns true | object[]

Const validateItem

  • validateItem(dataType: DataType, item: Object, conn?: Object): Promise<true | object[]>
  • Parameters

    • dataType: DataType
    • item: Object
    • Optional conn: Object

    Returns Promise<true | object[]>

Legend

Generated using TypeDoc