Upgrading from 2.x to 3.x

The main reason behind the new major release is shift to json-schema model definitions as described by json schema specification
The json-schema support is provided by Ajv library which comes with other features like extended validation support, dynamic defaults etc.. see ajv API for more details.

Why?
It allows model schemas to be further integrated with your REST APIs. Unified schema definitions throughout your service implementations make it easier for interfaces to be implemented and documentation to be auto-generated.
It reduces the complexity of your code by getting rid of the proprietary and somewhat limited schema format.


Note that in the time of v3 release, v3 includes numerous bugfixes which have not been backported to v2.
For full list of changes, please see the CHANGELOG

The following is description of breaking changes:

All models` schemas must be updated

From:

{
    type: DataType.HASH_TABLE,
    schema: {
        username: {
            type: DataType.STRING,
            allowEmptyValue: true
        },
        email: {
            type: DataType.STRING
        },
        age: {
            type: DataType.INT
        },
        apps: {
            type: DataType.ARRAY,
            allowEmptyValue: true,
            schema: {
                type: DataType.STRING
            }
        }
    }
}

To:

{
    type: 'object',
    required: ['email', 'age'],
    additionalProperties: false,
    properties: {
        username: {type: 'string'},
        email: {
            type: 'string',
            format: 'email'
        },
        age: {type: 'integer'},
        apps: {
            type: 'array',
            items: {
                type: 'string'
            }
        }
    }
}

modelInstance.update method:

The method behaves as one would expect, that is, its syntax sugar for instance.setData() followed by instance.save() ... with addition that when the operation fails, the instance data are restored to the previous state.
This also fixes the method design issue of v2.x which broke beforeUpdate & afterUpdate hooks for the update method.

modelInstance.sanitize method:

does not accept any options

comments powered by Disqus