(attribute)
| 1315 | } |
| 1316 | |
| 1317 | normalizeAttribute(attribute) { |
| 1318 | if (!_.isPlainObject(attribute)) { |
| 1319 | attribute = { type: attribute }; |
| 1320 | } |
| 1321 | |
| 1322 | if (!attribute.type) return attribute; |
| 1323 | |
| 1324 | attribute.type = this.normalizeDataType(attribute.type); |
| 1325 | |
| 1326 | if (Object.prototype.hasOwnProperty.call(attribute, 'defaultValue')) { |
| 1327 | if (typeof attribute.defaultValue === 'function' && |
| 1328 | [DataTypes.NOW, DataTypes.UUIDV1, DataTypes.UUIDV4].includes(attribute.defaultValue) |
| 1329 | ) { |
| 1330 | attribute.defaultValue = new attribute.defaultValue(); |
| 1331 | } |
| 1332 | } |
| 1333 | |
| 1334 | if (attribute.type instanceof DataTypes.ENUM) { |
| 1335 | // The ENUM is a special case where the type is an object containing the values |
| 1336 | if (attribute.values) { |
| 1337 | attribute.type.values = attribute.type.options.values = attribute.values; |
| 1338 | } else { |
| 1339 | attribute.values = attribute.type.values; |
| 1340 | } |
| 1341 | |
| 1342 | if (!attribute.values.length) { |
| 1343 | throw new Error('Values for ENUM have not been defined.'); |
| 1344 | } |
| 1345 | } |
| 1346 | |
| 1347 | return attribute; |
| 1348 | } |
| 1349 | } |
| 1350 | |
| 1351 | // Aliases |
no test coverage detected