Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flexible attribute properties patch #96

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions lib/waterline-schema/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ module.exports = function schemaBuilder(collections) {
tableName: collection.tableName,
datastore: collection.datastore || collection.connection,
attributes: _.merge({}, collection.attributes),
//Allow the attribute properties to be flexibly defined,
//e.g. phone: {type:"string", isMobilePhone:true, isXYZProperty:false}
attributeWhitelist: collection.attributeWhitelist && collection.attributeWhitelist === "flexible" || "strict",
// The schema piece will be transformed along the way to reflect the
// underlying datastructure. i.e. expanding out associations into foreign
// keys, etc.
Expand Down Expand Up @@ -234,11 +237,13 @@ module.exports = function schemaBuilder(collections) {
// ╚╝ ╩ ╩╩═╝╩═╩╝╩ ╩ ╩ ╚═╝ ┴ ┴└─└─┘┴ └─┘┴└─ ┴ ┴└─┘└─┘
// If the attribute contains a property that isn't whitelisted, then return
// an error.
_.each(attribute, function parseProperties(propertyValue, propertyName) {
if (_.indexOf(validProperties, propertyName) < 0) {
throw flaverr({ name: 'userError' }, Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model contains invalid properties. The property `' + propertyName + '` isn\'t a recognized property.'));
}
});
if (schemaCollection.attributeWhitelist === "strict") {
_.each(attribute, function parseProperties(propertyValue, propertyName) {
if (_.indexOf(validProperties, propertyName) < 0) {
throw flaverr({ name: 'userError' }, Error('The attribute `' + attributeName + '` on the `' + collection.identity + '` model contains invalid properties. The property `' + propertyName + '` isn\'t a recognized property.'));
}
});
}


// ╦ ╦╔═╗╦ ╦╔╦╗╔═╗╔╦╗╔═╗ ┌─┐┬ ┬ ┌─┐┬ ┬╔╗╔┬ ┬┬ ┬
Expand Down