waterline-schema
Advanced tools
Comparing version 1.0.0-20 to 1.0.0-21
@@ -12,2 +12,3 @@ // ██████╗██╗ ██╗███████╗ ██████╗██╗ ██╗███████╗ | ||
var _ = require('@sailshq/lodash'); | ||
var flaverr = require('flaverr'); | ||
@@ -32,3 +33,3 @@ module.exports = function sanityChecks(schema) { | ||
if (!_.has(attributeInfo, 'columnName')) { | ||
throw new Error('Attribute is missing a columnName property. Each attribute in the schema should have a computed columnName.'); | ||
throw flaverr({ name: 'userError' }, new Error('Attribute is missing a columnName property. Each attribute in the schema should have a computed columnName.')); | ||
} | ||
@@ -46,3 +47,3 @@ | ||
if (columnNames.length !== uniqueColumnNames.length) { | ||
throw new Error('The model `' + collectionName + '` has attributes with non-unique column names. Each attribute in the model must have a unique column name. The column names are currently set to: ' + columnNames + '. You may want to double check the model config to see what default attributes are being applied to the model.'); | ||
throw flaverr({ name: 'userError' }, new Error('The model `' + collectionName + '` has attributes with non-unique column names. Each attribute in the model must have a unique column name. The column names are currently set to: ' + columnNames + '. You may want to double check the model config to see what default attributes are being applied to the model.')); | ||
} | ||
@@ -49,0 +50,0 @@ }); |
@@ -18,2 +18,3 @@ // ███╗ ███╗ █████╗ ██████╗ ███████╗ ██████╗ ██████╗ ███████╗██╗ ██████╗ ███╗ ██╗ | ||
var _ = require('@sailshq/lodash'); | ||
var flaverr = require('flaverr'); | ||
@@ -45,3 +46,3 @@ module.exports = function foreignKeysMapper(schema) { | ||
if (!relatedModel) { | ||
throw new Error('The model association defined for attribute `' + attributeName + '` on the `' + collection.identity + '` model points to a model that doesn\'t exist.'); | ||
throw flaverr({ name: 'userError' }, new Error('The model association defined for attribute `' + attributeName + '` on the `' + collection.identity + '` model points to a model that doesn\'t exist.')); | ||
} | ||
@@ -56,3 +57,3 @@ | ||
if (!relatedPrimaryKey) { | ||
throw new Error('The model association defined for attribute `' + attributeName + '` on the `' + collection.identity + '` model points to a model that doesn\'t have a primary key field.'); | ||
throw flaverr({ name: 'userError' }, new Error('The model association defined for attribute `' + attributeName + '` on the `' + collection.identity + '` model points to a model that doesn\'t have a primary key field.')); | ||
} | ||
@@ -59,0 +60,0 @@ |
@@ -19,4 +19,6 @@ // ███████╗██╗ █████╗ ██████╗ ████████╗██╗ ██╗██████╗ ██████╗ ██╗ ██╗ ██████╗ ██╗ ██╗ | ||
var _ = require('@sailshq/lodash'); | ||
var flaverr = require('flaverr'); | ||
module.exports = function flagThroughTable(collectionName, schema) { | ||
var attributes = schema[collectionName].schema; | ||
@@ -30,3 +32,3 @@ | ||
// Find the collection that is being pointed to | ||
// Find the "through" collection that is being pointed to | ||
var linkedCollectionName = attributeVal.through; | ||
@@ -37,2 +39,13 @@ schema[linkedCollectionName].throughTable = schema[linkedCollectionName].throughTable || {}; | ||
// Find the opposite side of this association, which is linked by the through table. | ||
// e.g. in { collection: 'roles', through: 'userroles', via: 'user_id' }, the opposite collection is `roles`. | ||
var oppositeCollectionName = attributeVal.collection; | ||
// Make sure the opposite side has a reference to this collection via the same through table. | ||
if (!_.any(schema[oppositeCollectionName].schema, function(oppositeAttrVal) { | ||
return oppositeAttrVal.collection === collectionName && (oppositeAttrVal.through === linkedCollectionName || oppositeAttrVal.referenceIdentity === linkedCollectionName); | ||
})) { | ||
throw flaverr({ name: 'userError' }, new Error('A `through` property was set on the attribute `' + attributeName + '` on the `' + collectionName + '` model but no corresponding attribute in the `' + oppositeCollectionName + '` model could be found pointing with the same `through` value (`' + linkedCollectionName + '`).')); | ||
} | ||
// Set the schema value on the through table | ||
@@ -84,3 +97,3 @@ schema[linkedCollectionName].hasSchema = true; | ||
if (!reference) { | ||
throw new Error('A `through` property was set on the attribute `' + attributeName + '` on the `' + collectionName + '` model but no reference in the through model was found.'); | ||
throw flaverr({ name: 'userError' }, new Error('A `through` property was set on the attribute `' + attributeName + '` on the `' + collectionName + '` model but no reference in the through model was found.')); | ||
} | ||
@@ -87,0 +100,0 @@ |
@@ -19,2 +19,3 @@ // ██████╗ ██╗ ██╗██╗██╗ ██████╗ | ||
var _ = require('@sailshq/lodash'); | ||
var flaverr = require('flaverr'); | ||
var buildJoinTableSchema = require('./helpers/build-join-table-schema'); | ||
@@ -57,3 +58,3 @@ var flagThroughTable = require('./helpers/flag-through-table'); | ||
if (!relatedModel) { | ||
throw new Error('The collection association defined for attribute `' + attributeName + '` on the `' + collection.identity + '` model points to a model that doesn\'t exist.'); | ||
throw flaverr({ name: 'userError' }, new Error('The collection association defined for attribute `' + attributeName + '` on the `' + collection.identity + '` model points to a model that doesn\'t exist.')); | ||
} | ||
@@ -64,3 +65,3 @@ | ||
if (_.has(attributeVal, 'via') && !relatedModel.schema[attributeVal.via]) { | ||
throw new Error('The collection association defined for attribute `' + attributeName + '` on the `' + collection.identity + '` model points to an attribute using `via` on the `' + relatedModel.identity + '` model that doesn\'t exist.'); | ||
throw flaverr({ name: 'userError' }, new Error('The collection association defined for attribute `' + attributeName + '` on the `' + collection.identity + '` model points to an attribute using `via` on the `' + relatedModel.identity + '` model that doesn\'t exist.')); | ||
} | ||
@@ -67,0 +68,0 @@ |
@@ -19,2 +19,3 @@ // ███╗ ███╗ █████╗ ██████╗ | ||
var _ = require('@sailshq/lodash'); | ||
var flaverr = require('flaverr'); | ||
@@ -79,3 +80,3 @@ module.exports = function mapReferences(schema) { | ||
if (!reference) { | ||
throw new Error('A `collection` property was set on the attribute `' + attributeName + '` on the ' + collectionName + ' model that points to the ' + linkedCollection + ' model but no reference was found matching that model.'); | ||
throw flaverr({ name: 'userError' }, new Error('A `collection` property was set on the attribute `' + attributeName + '` on the ' + collectionName + ' model that points to the ' + linkedCollection + ' model but no reference was found matching that model.')); | ||
} | ||
@@ -82,0 +83,0 @@ |
@@ -19,2 +19,3 @@ // ██████╗ ██╗ ██╗██╗██╗ ██████╗ | ||
var _ = require('@sailshq/lodash'); | ||
var flaverr = require('flaverr'); | ||
var rttc = require('rttc'); | ||
@@ -53,3 +54,3 @@ var validTypes = require('../../accessible/valid-attribute-types'); | ||
if (!_.has(collection, 'identity')) { | ||
throw new Error('A Model must include an identity or tableName attribute'); | ||
throw flaverr({ name: 'userError' }, new Error('A Model must include an identity or tableName attribute')); | ||
} | ||
@@ -59,3 +60,3 @@ | ||
if (!_.has(collection, 'tableName')) { | ||
throw new Error('A Model must include a tableName attribute'); | ||
throw flaverr({ name: 'userError' }, new Error('A Model must include a tableName attribute')); | ||
} | ||
@@ -70,7 +71,7 @@ | ||
if (_.has(collection, 'autoCreatedAt')) { | ||
throw new Error('A model may not contain a top-level `autoCreatedAt` model option. To set an auto incrementing timestamp set the `autoCreatedAt` flag directly on an attribute.'); | ||
throw flaverr({ name: 'userError' }, new Error('A model may not contain a top-level `autoCreatedAt` model option. To set an auto incrementing timestamp set the `autoCreatedAt` flag directly on an attribute.')); | ||
} | ||
if (_.has(collection, 'autoUpdatedAt')) { | ||
throw new Error('A model may not contain a top-level `autoUpdatedAt` model option. To set an auto incrementing timestamp set the `autoUpdatedAt` flag directly on an attribute.'); | ||
throw flaverr({ name: 'userError' }, new Error('A model may not contain a top-level `autoUpdatedAt` model option. To set an auto incrementing timestamp set the `autoUpdatedAt` flag directly on an attribute.')); | ||
} | ||
@@ -88,3 +89,3 @@ | ||
if (!_.has(collection, 'primaryKey') || !_.isString(collection.primaryKey)) { | ||
throw new Error('Could not find a primary key attribute on the model `' + collection.identity + '`. All models must contain an attribute that acts as the primary key and is guaranteed to be unique.'); | ||
throw flaverr({ name: 'userError' }, new Error('Could not find a primary key attribute on the model `' + collection.identity + '`. All models must contain an attribute that acts as the primary key and is guaranteed to be unique.')); | ||
} | ||
@@ -94,3 +95,3 @@ | ||
if (!_.has(collection.attributes, collection.primaryKey)) { | ||
throw new Error('The model `' + collection.identity + '` defined a primary key of `' + collection.primaryKey + '` but that attribute could not be found on the model.'); | ||
throw flaverr({ name: 'userError' }, new Error('The model `' + collection.identity + '` defined a primary key of `' + collection.primaryKey + '` but that attribute could not be found on the model.')); | ||
} | ||
@@ -101,15 +102,15 @@ | ||
if (_.has(primaryKeyAttribute, 'defaultsTo') && !_.isUndefined(primaryKeyAttribute, 'defaultsTo')) { | ||
throw new Error('The model `' + collection.identity + '` defined a primary key of `' + collection.primaryKey + '` that has a `defaultsTo` value set. Primary keys must be unique therefore can\'t contain a default value.'); | ||
throw flaverr({ name: 'userError' }, new Error('The model `' + collection.identity + '` defined a primary key of `' + collection.primaryKey + '` that has a `defaultsTo` value set. Primary keys must be unique therefore can\'t contain a default value.')); | ||
} | ||
if (_.has(primaryKeyAttribute, 'autoCreatedAt') && primaryKeyAttribute.autoCreatedAt) { | ||
throw new Error('The model `' + collection.identity + '` defined a primary key of `' + collection.primaryKey + '` that has an `autoCreatedAt` value set. Primary keys must be unique therefore can\'t contain a timestamp value because it is not guaranteed to be unique.'); | ||
throw flaverr({ name: 'userError' }, new Error('The model `' + collection.identity + '` defined a primary key of `' + collection.primaryKey + '` that has an `autoCreatedAt` value set. Primary keys must be unique therefore can\'t contain a timestamp value because it is not guaranteed to be unique.')); | ||
} | ||
if (_.has(primaryKeyAttribute, 'autoUpdatedAt') && primaryKeyAttribute.autoUpdatedAt) { | ||
throw new Error('The model `' + collection.identity + '` defined a primary key of `' + collection.primaryKey + '` that has an `autoUpdatedAt` value set. Primary keys must be unique therefore can\'t contain a timestamp value because it is not guaranteed to be unique.'); | ||
throw flaverr({ name: 'userError' }, new Error('The model `' + collection.identity + '` defined a primary key of `' + collection.primaryKey + '` that has an `autoUpdatedAt` value set. Primary keys must be unique therefore can\'t contain a timestamp value because it is not guaranteed to be unique.')); | ||
} | ||
if (primaryKeyAttribute.type !== 'number' && primaryKeyAttribute.type !== 'string') { | ||
throw new Error('The model `' + collection.identity + '` defined a primary key of `' + collection.primaryKey + '` that has an invalid type. Valid primary key types are `number` and `string`'); | ||
throw flaverr({ name: 'userError' }, new Error('The model `' + collection.identity + '` defined a primary key of `' + collection.primaryKey + '` that has an invalid type. Valid primary key types are `number` and `string`')); | ||
} | ||
@@ -172,3 +173,3 @@ | ||
if (_.isFunction(attribute)) { | ||
throw new Error('Functions are not allowed as attributes and instance methods on models have been removed. Please change the `' + attributeName + '` on the `' + collection.identity + '` model.'); | ||
throw flaverr({ name: 'userError' }, Error('Functions are not allowed as attributes and instance methods on models have been removed. Please change the `' + attributeName + '` on the `' + collection.identity + '` model.')); | ||
} | ||
@@ -185,3 +186,3 @@ | ||
if (!_.has(attribute, 'type') && !_.has(attribute, 'model') && !_.has(attribute, 'collection')) { | ||
throw new Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model is missing a type property. All attributes must define what their type is.'); | ||
throw flaverr({ name: 'userError' }, Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model is missing a type property. All attributes must define what their type is.')); | ||
} | ||
@@ -191,3 +192,3 @@ | ||
if (!_.has(attribute, 'model') && !_.has(attribute, 'collection') && _.indexOf(validTypes, attribute.type) < 0) { | ||
throw new Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model uses an invalid type - `' + attribute.type + '`.'); | ||
throw flaverr({ name: 'userError' }, Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model uses an invalid type - `' + attribute.type + '`.')); | ||
} | ||
@@ -197,3 +198,3 @@ | ||
if (_.has(attribute, 'model') && _.has(attribute, 'type') && !_.isUndefined(attribute, 'type')) { | ||
throw new Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model is an association but also specifies a type property. This is not needed and will be automatically determined.'); | ||
throw flaverr({ name: 'userError' }, Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model is an association but also specifies a type property. This is not needed and will be automatically determined.')); | ||
} | ||
@@ -209,3 +210,3 @@ | ||
if (_.has(attribute, 'required') && !_.isBoolean(attribute.required)) { | ||
throw new Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model has a `required` flag but the value is not a boolean.'); | ||
throw flaverr({ name: 'userError' }, Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model has a `required` flag but the value is not a boolean.')); | ||
} | ||
@@ -220,3 +221,3 @@ | ||
if (_.has(attribute, 'collection') && attribute.required) { | ||
throw new Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model is a plural association and can\'t have a required flag set. Plural associations can only be populated.'); | ||
throw flaverr({ name: 'userError' }, Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model is a plural association and can\'t have a required flag set. Plural associations can only be populated.')); | ||
} | ||
@@ -226,3 +227,3 @@ | ||
if (_.has(attribute, 'collection') && _.has(attribute, 'columnName')) { | ||
throw new Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model is a plural association and can\'t have a `columnName` value set. If you\'re trying to customize the join table used for a many-to-many association, use the `through` option.'); | ||
throw flaverr({ name: 'userError' }, Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model is a plural association and can\'t have a `columnName` value set. If you\'re trying to customize the join table used for a many-to-many association, use the `through` option.')); | ||
} | ||
@@ -235,3 +236,3 @@ | ||
if (attribute.via.toLowerCase() === attributeName && attribute.collection.toLowerCase() === collection.identity) { | ||
throw new Error('The `via` property in the `' + attributeName + '` attribute of model `' + collection.identity + '` is invalid because it points at itself. Instead, if you want to indicate that this is a reflexive association with no inverse, simply remove `via`.'); | ||
throw flaverr({ name: 'userError' }, Error('The `via` property in the `' + attributeName + '` attribute of model `' + collection.identity + '` is invalid because it points at itself. Instead, if you want to indicate that this is a reflexive association with no inverse, simply remove `via`.')); | ||
} | ||
@@ -242,3 +243,3 @@ } | ||
if (attribute.required && _.has(attribute, 'defaultsTo') && !_.isUndefined(attribute, 'defaultsTo')) { | ||
throw new Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model is set to `required` but it also has a `defaultsTo` value set. In this case the two checks cancel each other out. Only one of them should be set.'); | ||
throw flaverr({ name: 'userError' }, Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model is set to `required` but it also has a `defaultsTo` value set. In this case the two checks cancel each other out. Only one of them should be set.')); | ||
} | ||
@@ -254,3 +255,3 @@ | ||
if (_.indexOf(validProperties, propertyName) < 0) { | ||
throw new Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model contains invalid properties. The property `' + propertyName + '` isn\'t a recognized property.'); | ||
throw flaverr({ name: 'userError' }, Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model contains invalid properties. The property `' + propertyName + '` isn\'t a recognized property.')); | ||
} | ||
@@ -269,3 +270,3 @@ }); | ||
if (_.has(attribute, 'model') || _.has(attribute, 'collection')) { | ||
throw new Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model contains invalid properties. The `allowNull` flag may not be used on attributes that represent associations. For singular associations `null` is allowed by default.'); | ||
throw flaverr({ name: 'userError' }, Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model contains invalid properties. The `allowNull` flag may not be used on attributes that represent associations. For singular associations `null` is allowed by default.')); | ||
} | ||
@@ -275,3 +276,3 @@ | ||
if (attribute.type.toLowerCase() === 'json' || attribute.type.toLowerCase() === 'ref') { | ||
throw new Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model contains invalid properties. The `allowNull` flag may not be used on attributes with type `json` or type `ref`.'); | ||
throw flaverr({ name: 'userError' }, Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model contains invalid properties. The `allowNull` flag may not be used on attributes with type `json` or type `ref`.')); | ||
} | ||
@@ -281,3 +282,3 @@ | ||
if (collection.primaryKey === attributeName) { | ||
throw new Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model contains invalid properties. The primary key may not allow null values.'); | ||
throw flaverr({ name: 'userError' }, Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model contains invalid properties. The primary key may not allow null values.')); | ||
} | ||
@@ -287,7 +288,7 @@ | ||
if (_.has(attribute, 'autoCreatedAt') && attribute.autoCreatedAt === true) { | ||
throw new Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model contains invalid properties. Auto-timestamp fields may not allow null values to be set.'); | ||
throw flaverr({ name: 'userError' }, Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model contains invalid properties. Auto-timestamp fields may not allow null values to be set.')); | ||
} | ||
if (_.has(attribute, 'autoUpdatedAt') && attribute.autoUpdatedAt === true) { | ||
throw new Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model contains invalid properties. Auto-timestamp fields may not allow null values to be set.'); | ||
throw flaverr({ name: 'userError' }, Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model contains invalid properties. Auto-timestamp fields may not allow null values to be set.')); | ||
} | ||
@@ -297,3 +298,3 @@ | ||
if (_.has(attribute, 'required') && attribute.required === true) { | ||
throw new Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model contains invalid properties. Attributes with a required flag may not allow `null` values to be set.'); | ||
throw flaverr({ name: 'userError' }, Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model contains invalid properties. Attributes with a required flag may not allow `null` values to be set.')); | ||
} | ||
@@ -303,3 +304,3 @@ | ||
if (_.has(attribute, 'defaultsTo') && _.isNull(attribute.defaultsTo)) { | ||
throw new Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model contains invalid properties. The attribute has both a `defaultsTo` value set to `null` and an `allowNull` flag set to true. When the `allowNull` flag is set to true then the default value for the attribute will always be `null` and the `defaultsTo` flag should not be used.'); | ||
throw flaverr({ name: 'userError' }, Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model contains invalid properties. The attribute has both a `defaultsTo` value set to `null` and an `allowNull` flag set to true. When the `allowNull` flag is set to true then the default value for the attribute will always be `null` and the `defaultsTo` flag should not be used.')); | ||
} | ||
@@ -317,3 +318,3 @@ } | ||
if (attributeName.match(/\./g)) { | ||
throw new Error('Invalid Attribute Name: Attributes may not contain a \'.\' character.'); | ||
throw flaverr({ name: 'userError' }, Error('Invalid Attribute Name: Attributes may not contain a \'.\' character.')); | ||
} | ||
@@ -333,3 +334,3 @@ | ||
if (_.has(attribute, 'collection') || _.has(attribute, 'model')) { | ||
throw new Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model is an association and can not have a default value'); | ||
throw flaverr({ name: 'userError' }, Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model is an association and can not have a default value')); | ||
} | ||
@@ -339,3 +340,3 @@ | ||
if (attribute.required) { | ||
throw new Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model contains both a `defaultsTo` value and is set to `required`. The attribute can have either property but not both.'); | ||
throw flaverr({ name: 'userError' }, Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model contains both a `defaultsTo` value and is set to `required`. The attribute can have either property but not both.')); | ||
} | ||
@@ -347,3 +348,3 @@ | ||
} catch (e) { | ||
throw new Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model has a default value that doesn\'t match it\'s set type.'); | ||
throw flaverr({ name: 'userError' }, Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model has a default value that doesn\'t match it\'s set type.')); | ||
} | ||
@@ -360,3 +361,3 @@ } | ||
if (_.has(attribute, 'autoUpdatedAt') && attribute.autoUpdatedAt) { | ||
throw new Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model contains both an `autoUpdatedAt` and an `autoCreatedAt` flag. It can only have one of these.'); | ||
throw flaverr({ name: 'userError' }, Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model contains both an `autoUpdatedAt` and an `autoCreatedAt` flag. It can only have one of these.')); | ||
} | ||
@@ -369,11 +370,11 @@ } | ||
if (_.has(attribute, 'required') && attribute.required) { | ||
throw new Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model contains both an `autoCreatedAt` and an `required` flag. Because this attribute is automatically set, the `required` is not needed.'); | ||
throw flaverr({ name: 'userError' }, Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model contains both an `autoCreatedAt` and an `required` flag. Because this attribute is automatically set, the `required` is not needed.')); | ||
} | ||
if (_.has(attribute, 'defaultsTo')) { | ||
throw new Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model contains both an `autoCreatedAt` flag and a `defaultsTo` value. Because this attribute is automatically set, the `defaultsTo` is not needed.'); | ||
throw flaverr({ name: 'userError' }, Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model contains both an `autoCreatedAt` flag and a `defaultsTo` value. Because this attribute is automatically set, the `defaultsTo` is not needed.')); | ||
} | ||
if (attribute.type !== 'number' && attribute.type !== 'string' && attribute.type !== 'ref') { | ||
throw new Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model contains both an `autoCreatedAt` flag but is not a proper type. Auto timestamps must have either a `number`, `string` or `ref` type set.'); | ||
throw flaverr({ name: 'userError' }, Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model contains both an `autoCreatedAt` flag but is not a proper type. Auto timestamps must have either a `number`, `string` or `ref` type set.')); | ||
} | ||
@@ -384,11 +385,11 @@ } | ||
if (_.has(attribute, 'required') && attribute.required) { | ||
throw new Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model contains both an `autoUpdatedAt` and an `required` flag. Because this attribute is automatically set, the `required` is not needed.'); | ||
throw flaverr({ name: 'userError' }, Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model contains both an `autoUpdatedAt` and an `required` flag. Because this attribute is automatically set, the `required` is not needed.')); | ||
} | ||
if (_.has(attribute, 'defaultsTo')) { | ||
throw new Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model contains both an `autoUpdatedAt` flag and a `defaultsTo` value. Because this attribute is automatically set, the `defaultsTo` is not needed.'); | ||
throw flaverr({ name: 'userError' }, Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model contains both an `autoUpdatedAt` flag and a `defaultsTo` value. Because this attribute is automatically set, the `defaultsTo` is not needed.')); | ||
} | ||
if (attribute.type !== 'number' && attribute.type !== 'string' && attribute.type !== 'ref') { | ||
throw new Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model contains both an `autoUpdatedAt` flag but is not a proper type. Auto timestamps must have either a `number`, `string` or `ref` type set.'); | ||
throw flaverr({ name: 'userError' }, Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model contains both an `autoUpdatedAt` flag but is not a proper type. Auto timestamps must have either a `number`, `string` or `ref` type set.')); | ||
} | ||
@@ -492,3 +493,3 @@ } | ||
if (!_.has(attributeInfo, 'via')) { | ||
throw new Error('The attribute ' + attributeName + ' on the ' + collectionName + ' model is a via-less collection attribute and has a dominant flag set. This should be removed because the generated join table will always use the datastore used by the model.'); | ||
throw flaverr({ name: 'userError' }, Error('The attribute ' + attributeName + ' on the ' + collectionName + ' model is a via-less collection attribute and has a dominant flag set. This should be removed because the generated join table will always use the datastore used by the model.')); | ||
} | ||
@@ -503,3 +504,3 @@ | ||
if (_.has(otherSideAttribute, 'model')) { | ||
throw new Error('The attribute ' + attributeName + ' on the ' + collectionName + ' model is a collection attribute that has a dominant flag and is pointing to the ' + attributeInfo.via + ' attribute on the ' + attributeInfo.collection + ' model which is a model association. Dominant is only valid on many to many associations.'); | ||
throw flaverr({ name: 'userError' }, Error('The attribute ' + attributeName + ' on the ' + collectionName + ' model is a collection attribute that has a dominant flag and is pointing to the ' + attributeInfo.via + ' attribute on the ' + attributeInfo.collection + ' model which is a model association. Dominant is only valid on many to many associations.')); | ||
} | ||
@@ -506,0 +507,0 @@ } |
{ | ||
"name": "waterline-schema", | ||
"description": "The core schema builder used in the Waterline ORM.", | ||
"version": "1.0.0-20", | ||
"version": "1.0.0-21", | ||
"dependencies": { | ||
"@sailshq/lodash": "^3.10.2", | ||
"flaverr": "^1.8.1", | ||
"rttc": "^10.0.0-1" | ||
@@ -8,0 +9,0 @@ }, |
151631
3001
3
+ Addedflaverr@^1.8.1
+ Addedflaverr@1.10.0(transitive)