This is the basic schema type. All schema types should inherit from this class. For example:

class SchemaTypeCustom extends SchemaType {};

Query operators

To add a query operator, defines a method whose name is started with q$. For example:

SchemaTypeCustom.q$foo = function(value, query, data){
// ...
};

The value parameter is the value of specified field; the query parameter is the value passed to the query operator; the data parameter is the complete data.

The return value must be a boolean indicating whether the data passed.

Update operators

To add a update operator, defines a method whose name is started with u$. For example:

SchemaTypeCustom.u$foo = function(value, update, data){
// ...
};

The value parameter is the value of specified field; the update parameter is the value passed to the update operator; the data parameter is the complete data.

The return value will replace the original data.

Type Parameters

  • T

Hierarchy (view full)

Constructors

  • SchemaType constructor.

    Type Parameters

    • T

    Parameters

    • name: string = ''
    • Optional options: {
          default?: T | (() => T);
          required?: boolean;
      }
      • Optional default?: T | (() => T)
      • Optional required?: boolean

    Returns default<T>

Properties

default: (() => T)

Type declaration

    • (): T
    • Returns T

name: string = ''
options: {
    default?: T | (() => T);
    required: boolean;
}

Type declaration

  • Optional default?: T | (() => T)
  • required: boolean
q$exists: ((value, query, data?) => boolean)

Type declaration

    • (value, query, data?): boolean
    • Checks the existance of data.

      Parameters

      • value: unknown
      • query: unknown
      • Optional data: unknown

      Returns boolean

q$max: ((value, query, data?) => boolean)

Type declaration

    • (value, query, data?): boolean
    • Checks whether value is less than or equal to (i.e. <=) the query.

      Parameters

      • value: unknown
      • query: unknown
      • Optional data: unknown

      Returns boolean

q$min: ((value, query, data?) => boolean)

Type declaration

    • (value, query, data?): boolean
    • Checks whether value is greater than or equal to (i.e. >=) the query.

      Parameters

      • value: unknown
      • query: unknown
      • Optional data: unknown

      Returns boolean

Methods

  • Casts data. This function is used by getters to cast an object to document instances. If the value is null, the default value will be returned.

    Parameters

    • Optional value: unknown
    • Optional data: unknown

    Returns unknown

  • Compares data. This function is used when sorting.

    Parameters

    • a: unknown
    • b: unknown

    Returns number

  • Checks the equality of data.

    Parameters

    • value: T
    • query: unknown
    • Optional data: unknown

    Returns boolean

  • Parses data. This function is used when restoring data from database files.

    Parameters

    • value: unknown

    Returns any

  • Checks the existance of data.

    Parameters

    • value: unknown
    • query: unknown
    • Optional data: unknown

    Returns boolean

  • Checks whether value is greater than (i.e. >) the query.

    Parameters

    • value: unknown
    • query: unknown
    • Optional data: unknown

    Returns boolean

  • Checks whether value is greater than or equal to (i.e. >=) the query.

    Parameters

    • value: unknown
    • query: unknown
    • Optional data: unknown

    Returns boolean

  • Checks whether value is equal to one of elements in query.

    Parameters

    • value: unknown
    • query: unknown[]
    • Optional data: unknown

    Returns boolean

  • Checks whether value is less than (i.e. <) the query.

    Parameters

    • value: unknown
    • query: unknown
    • Optional data: unknown

    Returns boolean

  • Checks whether value is less than or equal to (i.e. <=) the query.

    Parameters

    • value: unknown
    • query: unknown
    • Optional data: unknown

    Returns boolean

  • Checks the equality of data. Returns true if the value doesn't match.

    Parameters

    • value: T
    • query: unknown
    • Optional data: unknown

    Returns boolean

  • Checks whether value is not equal to any elements in query.

    Parameters

    • value: unknown
    • query: unknown[]
    • Optional data: unknown

    Returns boolean

  • Renames a field.

    Parameters

    • value: unknown
    • update: unknown
    • data: unknown

    Returns void

  • Sets the value.

    Type Parameters

    • T

    Parameters

    • value: unknown
    • update: T
    • Optional data: unknown

    Returns T

  • Unsets the value.

    Type Parameters

    • T

    Parameters

    • value: T
    • update: boolean
    • Optional data: unknown

    Returns T

  • Validates data. This function is used by setters.

    Parameters

    • value: unknown
    • Optional data: unknown

    Returns unknown

  • Transforms value. This function is used when saving data to database files.

    Parameters

    • value: unknown
    • Optional data: unknown

    Returns any