orm/src/schema/Type.js

/**
 * @module flitter-orm/src/schema/Type
 */

/**
 * Base class for all schema types. Used to determine
 * the validity of a value and to coerce that value to
 * the proper type to fit the schema.
 */
class Type {
    /**
     * Determines if the specified value can be cast to this type.
     * @param {*} value
     * @returns {boolean}
     */
    static validate(value) {
        return true
    }

    /**
     * Casts the specified value to this type.
     * Note that, for recursive types (array, object), this
     * will leave their sub-structures intact.
     *
     * @param {*} value
     * @returns {*}
     */
    static cast(value) {
        return value
    }
}

module.exports = exports = Type