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

adonis-lucid-mongodb

Package Overview
Dependencies
Maintainers
1
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

adonis-lucid-mongodb - npm Package Compare versions

Comparing version 1.0.40 to 1.0.41

6

package.json

@@ -8,3 +8,3 @@ {

},
"version": "1.0.40",
"version": "1.0.41",
"scripts": {

@@ -64,3 +64,3 @@ "lint": "standard",

"harmony-reflect": "^1.5.1",
"inflect": "^0.3.0",
"inflect": "^0.4.0",
"lodash": "^4.17.4",

@@ -70,3 +70,3 @@ "moment": "^2.17.1",

"mquery": "^2.2.3",
"node-exceptions": "^1.0.3",
"node-exceptions": "^2.0.1",
"pretty-hrtime": "^1.0.3",

@@ -73,0 +73,0 @@ "require-all": "^2.2.0",

@@ -114,2 +114,3 @@ 'use strict'

this.setJSON(values)
return this
}

@@ -116,0 +117,0 @@

@@ -61,3 +61,3 @@ 'use strict'

*
* @method getPersistanceFormat
* @method getPersistanceValues
*

@@ -69,22 +69,32 @@ * @param {Object} values

*/
FieldTypes.getPersistanceFormat = function (values) {
FieldTypes.getPersistanceValues = function (values) {
return _(values).transform((result, value, key) => {
if (_.includes(this.constructor.boolFields, key)) {
result[key] = !!value
} else if (this.getTimestampKey(key) || _.includes(this.constructor.dateFields, key)) {
result[key] = moment.isMoment(value) ? value.toDate() : value
} else if (_.includes(this.constructor.geoFields, key) && value instanceof GeoPoint) {
result[key] = {
type: 'Point',
coordinates: [
value.longitude(),
value.latitude()
]
}
} else {
result[key] = value
}
result[key] = this.getPersistanceValue(key, value)
}).value()
}
FieldTypes.getPersistanceValue = function (key, value) {
const self = this
if (_.isArray(value)) {
return _.map(value, val => self.getPersistanceValue(key, val))
}
if (_.includes(this.constructor.boolFields, key)) {
return !!value
} else if (this.getTimestampKey(key) || _.includes(this.constructor.dateFields, key)) {
return moment.isMoment(value) ? value.toDate() : value
} else if (_.includes(this.constructor.geoFields, key) && value instanceof GeoPoint) {
return {
type: 'Point',
coordinates: [
value.longitude(),
value.latitude()
]
}
} else if (_.includes(this.constructor.objectIdFields, key)) {
return _.isString(value) ? objectId(value) : value
} else {
return value
}
}
/**

@@ -91,0 +101,0 @@ *

@@ -32,3 +32,3 @@ 'use strict'

const insertHandler = function * () {
const values = this.getPersistanceFormat(this.attributes)
const values = this.attributes
if (!values || _.size(values) < 1) {

@@ -69,3 +69,3 @@ throw CE.ModelException.invalidState(`Cannot save empty ${this.constructor.name} model`)

// yield query.connect()
let dirtyValues = this.getPersistanceFormat(this.$dirty)
let dirtyValues = this.$dirty
if (!_.size(dirtyValues) && !this.unsetFields.length) {

@@ -72,0 +72,0 @@ return 0

@@ -32,2 +32,3 @@ 'use strict'

this.eagerLoad = new EagerLoad()
this.replaceMethods()
return new Proxy(this, proxyHandler)

@@ -43,4 +44,30 @@ }

}
replaceMethods () {
const conditionMethods = [
'eq',
'ne',
'gt',
'gte',
'lt',
'lte',
'in',
'nin',
'all',
'intersects'
]
const queryBuilder = this.modelQueryBuilder
const model = this.HostModel
for (let name of conditionMethods) {
let originMethod = this.modelQueryBuilder[name]
this.modelQueryBuilder[name] = function (param) {
const key = queryBuilder._path
param = model.prototype.getPersistanceValue(key, param)
originMethod.apply(queryBuilder, [param])
return this
}
}
}
}
module.exports = QueryBuilder

@@ -87,2 +87,3 @@ 'use strict'

values = target.HostModel.prototype.setUpdateTimestamp(values)
values = target.HostModel.prototype.getPersistanceValues(values)
yield target.connect()

@@ -106,2 +107,3 @@ debug('insert', target.HostModel.collection, values)

values = target.HostModel.prototype.setUpdateTimestamp(values)
values = target.HostModel.prototype.getPersistanceValues(values)
yield target.connect()

@@ -614,3 +616,3 @@ return yield target.modelQueryBuilder.setOptions({ multi: true }).update(values)

return function (key, values) {
target.modelQueryBuilder.where(key).in(_formatValue(target.HostModel, key, values))
target.modelQueryBuilder.where(key).in(values)
return this

@@ -767,3 +769,2 @@ }

if (k !== 'maxDistance' && k !== 'minDistance') {
c = _formatValue(target.HostModel, key, c)
target.modelQueryBuilder.where(key)[k](c)

@@ -776,7 +777,14 @@ }

} else {
target.modelQueryBuilder.where(key, _formatValue(target.HostModel, key, conditions))
const value = target.HostModel.prototype.getPersistanceValue(key, conditions)
target.modelQueryBuilder.where(key, value)
}
})
} else {
target.modelQueryBuilder.where(arguments[0], _formatValue(target.HostModel, arguments[0], arguments[1]))
if (arguments.length === 2) {
const key = arguments[0]
const value = target.HostModel.prototype.getPersistanceValue(arguments[0], arguments[1])
target.modelQueryBuilder.where(key, value)
} else {
target.modelQueryBuilder.where(arguments[0])
}
}

@@ -787,19 +795,8 @@ return this

function _formatValue (model, key, value) {
if (_.isArray(value)) {
return _.map(value, v => _formatValue(model, key, v))
}
if (_.includes(model.boolFields, key)) {
return !!value
} else if (_.includes(model.dateFields, key) && _.isString(value)) {
return value instanceof Date ? value : moment.utc(value).toDate()
} else if ((key === model.createTimestamp || key === model.updateTimestamp || key === model.deleteTimestamp) && _.isString(value)) {
return value instanceof Date ? value : moment.utc(value).toDate()
} else if (_.includes(model.objectIdFields, key) && _.isString(value)) {
return objectId(value)
}
// function _formatValue (model, key, value) {
// const values = {}
// values[key] = value
// return model.prototype.getPersistanceValues(values)[key]
// }
return value
}
/**

@@ -806,0 +803,0 @@ * Aggregate count

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