Comparing version 2.14.6 to 2.15.0
@@ -73,11 +73,4 @@ /* UNIQORM | ||
return null; | ||
value = this._parseValue(value); | ||
value = this._parseValue(value, this.name); | ||
if (!(value instanceof Date)) | ||
throw new ValidationError('"%s" accepts Date, Number or date formatted String type only', this.name) | ||
.set({ | ||
reason: 'invalid_type', | ||
field: this.name | ||
}); | ||
if (this.minValue && value.getTime() < this.minValue.getTime()) | ||
@@ -141,2 +134,7 @@ throw new ValidationError('Value is out of range for field "%s". (actual: %s, min: %s)', | ||
} | ||
throw new ValidationError('"%s" accepts Date, Number or date formatted String type only', this.name) | ||
.set({ | ||
reason: 'invalid_type', | ||
field: this.name | ||
}); | ||
} | ||
@@ -143,0 +141,0 @@ |
@@ -18,2 +18,3 @@ /* UNIQORM | ||
const DataField = require('./DataField'); | ||
const CalculatedField = require('./CalculatedField'); | ||
const Op = sqb.Op; | ||
@@ -247,3 +248,3 @@ | ||
const processField = (finder, model, attrKey, v, tableAlias, targetNode) => { | ||
const processField = (finder, model, v, attrKey, tableAlias, targetNode) => { | ||
v = v || attrKey; | ||
@@ -273,2 +274,16 @@ | ||
/* If field is a data field */ | ||
if (field instanceof CalculatedField) { | ||
const attr = targetNode[attrKey] = { | ||
calculate: field.calculate, | ||
cols: [] | ||
}; | ||
for (const x of field.requires) { | ||
const col = finder._addColumn(tableAlias, x); | ||
col.attrName = x; | ||
attr.cols.push(col); | ||
} | ||
return; | ||
} | ||
let fnd = finder; | ||
@@ -367,3 +382,3 @@ | ||
processField(fnd, fld.foreignModel, | ||
fname, v, tableAlias, targetNode); | ||
v, fname, tableAlias, targetNode); | ||
} | ||
@@ -378,4 +393,4 @@ } | ||
for (const attrKey of Object.keys(srcProperties)) { | ||
processField(this, this.model, attrKey, | ||
srcProperties[attrKey], 't', this._attrNode); | ||
processField(this, this.model, srcProperties[attrKey], | ||
attrKey, 't', this._attrNode); | ||
} | ||
@@ -484,4 +499,8 @@ } | ||
_wrapRec(source, target, attrMap) { | ||
for (const n of Object.getOwnPropertyNames(attrMap)) { | ||
const attrKeys = Object.getOwnPropertyNames(attrMap); | ||
let hasCalcField; | ||
for (const n of attrKeys) { | ||
const attr = attrMap[n]; | ||
if (attr.calculate) | ||
hasCalcField = true; | ||
if (attr.column) { | ||
@@ -499,2 +518,17 @@ target[n] = source[attr.column.colName]; | ||
} | ||
/* Call calculate methods */ | ||
if (hasCalcField) { | ||
for (const n of attrKeys) { | ||
const attr = attrMap[n]; | ||
if (attr.calculate) { | ||
const values = {}; | ||
for (const col of attr.cols) { | ||
values[col.attrName] = source[col.colName]; | ||
} | ||
target[n] = attr.calculate(values, this.context); | ||
} | ||
} | ||
} | ||
return target; | ||
@@ -501,0 +535,0 @@ } |
@@ -242,5 +242,6 @@ /* UNIQORM | ||
modifyModelName(row.foreign_table_name), | ||
key: (key.length > 1 ? key : key[0]), | ||
key: (key.length > 1 ? | ||
/*istanbul ignore next*/ key : key[0]), | ||
foreignKey: (foreignKey.length > 1 ? | ||
foreignKey : foreignKey[0]) | ||
/*istanbul ignore next*/ foreignKey : foreignKey[0]) | ||
}); | ||
@@ -273,2 +274,3 @@ } | ||
function camelize(str) { | ||
/*istanbul ignore next*/ | ||
return str.replace(/[-_]+(.)?/g, function(arg$, c) { | ||
@@ -275,0 +277,0 @@ return (c != null ? c : '').toUpperCase(); |
@@ -22,2 +22,3 @@ /* UNIQORM | ||
const AssociatedField = require('./AssociatedField'); | ||
const CalculatedField = require('./CalculatedField'); | ||
const DataField = require('./DataField'); | ||
@@ -189,5 +190,16 @@ const Finder = require('./Finder'); | ||
if (def.foreignModel) | ||
if (def.foreignModel) { | ||
if (def.dataType) | ||
throw new ArgumentError('Invalid field definition for "%s". You can\'t define "dataType" for associated fields', name); | ||
if (def.calculate) | ||
throw new ArgumentError('Invalid field definition for "%s". You can\'t define "calculate" method for associated fields', name); | ||
return (this.fields[name] = new AssociatedField(name, this, def)); | ||
} | ||
if (def.calculate) { | ||
if (def.dataType) | ||
throw new ArgumentError('Invalid field definition for "%s". You can\'t define "dataType" for calculated fields', name); | ||
return (this.fields[name] = new CalculatedField(name, this, def)); | ||
} | ||
if (!def.dataType) | ||
@@ -433,5 +445,6 @@ throw new ArgumentError('You must provide "dataType" property'); | ||
*/ | ||
destroyMany(options = {}) { | ||
destroyMany(/*istanbul ignore next*/ options = {}) { | ||
return promisify(() => { | ||
/*istanbul ignore else*/ | ||
if (options.where) { | ||
@@ -507,5 +520,6 @@ options.where = this._mapConditions(options.where); | ||
if (keyValues[f] === undefined) | ||
throw new ArgumentError('You must all provide all key values in object instance.'); | ||
throw new ArgumentError('You must provide all key values in object instance.'); | ||
result[f] = keyValues[f]; | ||
} | ||
/*istanbul ignore else */ | ||
if (typeof keyValues === 'object') | ||
@@ -512,0 +526,0 @@ merge(result, keyValues, {adjunct: true}); |
{ | ||
"name": "uniqorm", | ||
"description": "Multi dialect and multi schema ORM framework for enterprise level NodeJS applications", | ||
"version": "2.14.6", | ||
"version": "2.15.0", | ||
"author": "Panates Ltd.", | ||
@@ -35,11 +35,11 @@ "contributors": [ | ||
"babel-eslint": "^10.0.1", | ||
"eslint": "^5.13.0", | ||
"eslint": "^5.15.3", | ||
"eslint-config-google": "^0.12.0", | ||
"mocha": "^5.2.0", | ||
"nyc": "^13.2.0", | ||
"sqb": "^3.7.5", | ||
"sqb-connect-pg": "^3.1.2", | ||
"fecha": "^3.0.2", | ||
"glob": "^7.1.3", | ||
"mocha": "^6.0.2", | ||
"nyc": "^13.3.0", | ||
"rejected-or-not": "^1.0.1", | ||
"glob": "^7.1.3", | ||
"fecha": "^3.0.2" | ||
"sqb": "^3.7.6", | ||
"sqb-connect-pg": "^3.1.4" | ||
}, | ||
@@ -46,0 +46,0 @@ "peerDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
97950
34
3217