Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

uniqorm

Package Overview
Dependencies
Maintainers
1
Versions
123
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

uniqorm - npm Package Compare versions

Comparing version 2.16.3 to 2.16.4

92

lib/Model.js

@@ -314,7 +314,9 @@ /* UNIQORM

if (typeof values !== 'object' || Array.isArray(values))
throw new ArgumentError('You must provide object instance which contains values');
throw new ArgumentError('You must provide values');
const silent = options.silent != null ?
options.silent : this.orm.options.silent;
values = this._normalizeValues(values, silent);
this.validateValuesForCreate(values, {silent});
const dataValues = this._normalizeValues(values);
const returning = this._prepareReturningOptions(options.returning, silent);

@@ -324,3 +326,3 @@

return dbobj
.insert(this.tableNameFull, values)
.insert(this.tableNameFull, dataValues)
.returning(returning && returning.dataTypes)

@@ -395,8 +397,6 @@ .execute({

if (typeof values !== 'object' || Array.isArray(values))
throw new ArgumentError('You must provide object instance which contains values');
const silent = options.silent != null ?
options.silent : this.orm.options.silent;
values = this._normalizeValues(values, silent, true);
this.validateValuesForUpdate(values, {silent});
const dataValues = this._normalizeValues(values);
const returning = this._prepareReturningOptions(options.returning, silent);

@@ -409,3 +409,3 @@

return dbobj
.update(this.tableNameFull, values)
.update(this.tableNameFull, dataValues)
.where(...where)

@@ -675,11 +675,39 @@ .returning(returning && returning.dataTypes)

* @param {Object} values
* @param {Boolean} silent
* @param {Boolean} [forUpdate]
* @param {Object} [options]
* @param {boolean} [options.silent=false]
* @param {boolean} [options.normalize=false]
* @return {Object}
*/
validateValuesForCreate(values, options = {}) {
options.forCreate = true;
return this._validateValues(values, options);
}
/**
*
* @param {Object} values
* @param {Object} [options]
* @param {boolean} [options.silent=false]
* @param {boolean} [options.normalize=false]
* @return {Object}
*/
validateValuesForUpdate(values, options = {}) {
options.forCreate = false;
return this._validateValues(values, options);
}
/**
*
* @param {Object} values
* @param {Object} [options]
* @param {boolean} [options.silent=false]
* @param {boolean} [options.forCreate=false]
* @private
*/
_normalizeValues(values, silent, forUpdate) {
_validateValues(values, options = {}) {
if (typeof values !== 'object' || Array.isArray(values))
throw new ArgumentError('You must provide values');
/* istanbul ignore else */
if (!silent) {
if (!options.silent) {
for (const name of Object.keys(values)) {

@@ -690,3 +718,2 @@ this.getField(name);

const result = {};
for (const name of Object.keys(this.fields)) {

@@ -698,15 +725,14 @@ const field = this.fields[name];

// Validate required
if (field.notNull && field.required && field.defaultValue == null && (
(!forUpdate && (v == null || v === '')) ||
(forUpdate && (v === null || v === ''))
)) {
throw new ValidationError('Value required for field "%s"', name)
.set({
reason: 'value_required',
field: name
});
if (options.forCreate) {
if (v == null && field.required && field.defaultValue == null) {
throw new ValidationError('Value required for field "%s"', name)
.set({
reason: 'value_required',
field: name
});
}
}
if (v !== undefined) {
if (v != null) {
// Validate char length
if (field.charLength && v != null && v.length > field.charLength)
if (field.charLength && String(v).length > field.charLength)
throw new ValidationError('Value too large for field "%s" (actual: %d, maximum: %d)',

@@ -720,5 +746,21 @@ name, v.length, field.charLength)

});
}
}
}
/**
*
* @param {Object} values
* @return {Object}
* @private
*/
_normalizeValues(values) {
const result = {};
for (const name of Object.keys(this.fields)) {
const field = this.fields[name];
if (!(field instanceof DataField))
continue;
const v = values[name];
if (v !== undefined)
result[field.fieldName] = field.parseValue(v);
}
}

@@ -725,0 +767,0 @@ return result;

{
"name": "uniqorm",
"description": "Multi dialect and multi schema ORM framework for enterprise level NodeJS applications",
"version": "2.16.3",
"version": "2.16.4",
"author": "Panates Ltd.",

@@ -27,3 +27,3 @@ "contributors": [

"dependencies": {
"errorex": "^2.3.0",
"errorex": "^2.3.1",
"putil-isplainobject": "^1.0.1",

@@ -44,3 +44,3 @@ "putil-merge": "^3.2.0",

"sqb": "^3.7.7",
"sqb-connect-pg": "^3.1.5"
"sqb-connect-pg": "^3.1.7"
},

@@ -47,0 +47,0 @@ "peerDependencies": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc