Comparing version 3.0.0 to 3.1.0
@@ -0,1 +1,6 @@ | ||
## 3.1.0/2017-08-19 | ||
- tweak error stack | ||
- update README | ||
## 3.0.0/2017-08-18 | ||
@@ -2,0 +7,0 @@ |
@@ -64,3 +64,3 @@ 'use strict'; | ||
exec(cb) { | ||
exec() { | ||
return Promise.resolve() | ||
@@ -80,3 +80,3 @@ .then(() => execBeforePlugins.call(this)) | ||
cursor(cb) { | ||
cursor() { | ||
return Promise.resolve() | ||
@@ -195,4 +195,5 @@ .then(() => execBeforePlugins.call(this)) | ||
function addMongoErrorDetail(e) { | ||
// concat extra error stack | ||
e.stack = `${e.stack}${os.EOL}----- Mongolass error stack -----${os.EOL}${this.stack}`; | ||
const stackArr = this.stack.split(os.EOL); | ||
stackArr[0] = e.message; | ||
e.stack = stackArr.join(os.EOL); | ||
// only for mongoError | ||
@@ -199,0 +200,0 @@ if (!e.model) { |
{ | ||
"name": "mongolass", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "Elegant MongoDB driver for Node.js.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
127
README.md
@@ -43,3 +43,3 @@ ## Mongolass | ||
'use strict'; | ||
const Mongolass = require('mongolass'); | ||
@@ -54,3 +54,3 @@ const Schema = Mongolass.Schema; | ||
const User = mongolass.model('User', UserSchema); | ||
/* | ||
@@ -63,4 +63,4 @@ equal to: | ||
will create inner schema named `UserSchema`. | ||
*/ | ||
*/ | ||
User | ||
@@ -70,8 +70,15 @@ .insertOne({ name: 'nswbmw', age: 'wrong age' }) | ||
.then(console.log) | ||
.catch(function (e) { | ||
console.error(e); | ||
console.error(e.stack); | ||
}); | ||
.catch(console.error); | ||
/* | ||
{ [Error: ($.age: "wrong age") ✖ (type: number)] | ||
{ ($.age: "wrong age") ✖ (type: number) | ||
at Model.insertOne (/Users/nswbmw/Desktop/test/node_modules/mongolass/lib/query.js:105:16) | ||
at Object.<anonymous> (/Users/nswbmw/Desktop/test/app.js:23:4) | ||
at Module._compile (module.js:573:30) | ||
at Object.Module._extensions..js (module.js:584:10) | ||
at Module.load (module.js:507:32) | ||
at tryModuleLoad (module.js:470:12) | ||
at Function.Module._load (module.js:462:3) | ||
at Function.Module.runMain (module.js:609:10) | ||
at startup (bootstrap_node.js:158:16) | ||
at bootstrap_node.js:598:3 | ||
validator: 'type', | ||
@@ -86,31 +93,3 @@ actual: 'wrong age', | ||
args: [] } | ||
Error: ($.age: "wrong age") ✖ (type: number) | ||
at throwError (/Users/nswbmw/Desktop/mongolass-demo/node_modules/another-json-schema/index.js:215:17) | ||
at validate (/Users/nswbmw/Desktop/mongolass-demo/node_modules/another-json-schema/index.js:184:7) | ||
at validateLeaf (/Users/nswbmw/Desktop/mongolass-demo/node_modules/another-json-schema/index.js:175:12) | ||
at iterator (/Users/nswbmw/Desktop/mongolass-demo/node_modules/another-json-schema/index.js:120:14) | ||
at iterator (/Users/nswbmw/Desktop/mongolass-demo/node_modules/another-json-schema/index.js:133:29) | ||
at _validateObject (/Users/nswbmw/Desktop/mongolass-demo/node_modules/another-json-schema/index.js:108:11) | ||
at _Schema.validate (/Users/nswbmw/Desktop/mongolass-demo/node_modules/another-json-schema/index.js:38:10) | ||
at formatCreate (/Users/nswbmw/Desktop/mongolass-demo/node_modules/mongolass/lib/schema.js:183:25) | ||
at Query.beforeInsertOne (/Users/nswbmw/Desktop/mongolass-demo/node_modules/mongolass/lib/schema.js:94:7) | ||
at /Users/nswbmw/Desktop/mongolass-demo/node_modules/mongolass/lib/query.js:146:44 | ||
at next (native) | ||
at onFulfilled (/Users/nswbmw/Desktop/mongolass-demo/node_modules/co/index.js:65:19) | ||
at /Users/nswbmw/Desktop/mongolass-demo/node_modules/co/index.js:54:5 | ||
at co (/Users/nswbmw/Desktop/mongolass-demo/node_modules/co/index.js:50:10) | ||
at Query.execBeforePlugins (/Users/nswbmw/Desktop/mongolass-demo/node_modules/mongolass/lib/query.js:142:10) | ||
at /Users/nswbmw/Desktop/mongolass-demo/node_modules/mongolass/lib/query.js:67:39 | ||
----- Mongolass error stack ----- | ||
Error | ||
at Model.insertOne (/Users/nswbmw/Desktop/mongolass-demo/node_modules/mongolass/lib/query.js:108:16) | ||
at Object.<anonymous> (/Users/nswbmw/Desktop/mongolass-demo/app.js:23:4) | ||
at Module._compile (module.js:409:26) | ||
at Object.Module._extensions..js (module.js:416:10) | ||
at Module.load (module.js:343:32) | ||
at Function.Module._load (module.js:300:12) | ||
at Function.Module.runMain (module.js:441:10) | ||
at startup (node.js:139:18) | ||
at node.js:974:3 | ||
*/ | ||
*/ | ||
``` | ||
@@ -155,21 +134,25 @@ | ||
1. Pure Schema. In Mongoose, Schema and Model and Entry are confused. | ||
1. Pure Schema. In Mongoose, Schema and Model and Entity are confused. | ||
> Schemas not only define the structure of your document and casting of properties, they also define document instance methods, static Model methods, compound indexes and document lifecycle hooks called middleware. | ||
In Mongolass, Schema is only used for defining the structure of your document and casting of properties, Model used for retrievaling data from mongodb and register plugins, Entry(as result) is plain object. Schema is also optional. | ||
In Mongolass, Schema is only used for defining the structure of your document and casting of properties, Model used for retrievaling data from mongodb and register plugins, Entity(as result) is plain object. Schema is also optional. | ||
2. Awesome Plugin System. Mongoose plugin system is not strong enough, eg: `.pre`, `.post`, then async `next()`. In Mongolass, we can register a plugin for Model or global mongolass instance. like: | ||
2. Awesome plugin system. Mongoose plugin system is not strong enough, eg: `.pre`, `.post`, use async `next()`. In Mongolass, we can register a plugin for Model or global mongolass instance. like: | ||
``` | ||
User.plugin('xx', { | ||
beforeFind: function (...args) {}, | ||
afterFind: function* (result, ...args) {// or function return Promise | ||
beforeFind: function (...args) {},// or function return Promise | ||
afterFind: function* (result, ...args) { | ||
console.log(result, args); | ||
... | ||
} | ||
}, | ||
// afterFind: async function (result, ...args) { | ||
// console.log(result, args); | ||
// ... | ||
// } | ||
}); | ||
``` | ||
``` | ||
Above added two hook function for `User`, when `User.find().xx().exec()` is called, the execution order is as follows: | ||
Above added two hook functions for `User`, when `User.find().xx().exec()` is called, the execution order is as follows: | ||
@@ -180,6 +163,5 @@ ``` | ||
**NOTE**: Different order of calling plugins will output different results. The priority of Model's plugins is greater than global's. | ||
Mongolass's plugins could be substituted for Mongoose's (document instance methods + static Model methods + plugins). | ||
3. Damn Detailed Error Information. see [usage](https://github.com/mongolass/mongolass#usage). | ||
3. Detailed error informations. see [usage](https://github.com/mongolass/mongolass#usage). | ||
@@ -191,8 +173,15 @@ ``` | ||
.then(console.log) | ||
.catch(function (e) { | ||
console.error(e); | ||
console.error(e.stack); | ||
}); | ||
.catch(console.error); | ||
/* | ||
{ [Error: ($.age: "wrong age") ✖ (type: number)] | ||
{ ($.age: "wrong age") ✖ (type: number) | ||
at Model.insertOne (/Users/nswbmw/Desktop/test/node_modules/mongolass/lib/query.js:105:16) | ||
at Object.<anonymous> (/Users/nswbmw/Desktop/test/app.js:23:4) | ||
at Module._compile (module.js:573:30) | ||
at Object.Module._extensions..js (module.js:584:10) | ||
at Module.load (module.js:507:32) | ||
at tryModuleLoad (module.js:470:12) | ||
at Function.Module._load (module.js:462:3) | ||
at Function.Module.runMain (module.js:609:10) | ||
at startup (bootstrap_node.js:158:16) | ||
at bootstrap_node.js:598:3 | ||
validator: 'type', | ||
@@ -207,30 +196,3 @@ actual: 'wrong age', | ||
args: [] } | ||
Error: ($.age: "wrong age") ✖ (type: number) | ||
at throwError (/Users/nswbmw/Desktop/mongolass-demo/node_modules/another-json-schema/index.js:215:17) | ||
at validate (/Users/nswbmw/Desktop/mongolass-demo/node_modules/another-json-schema/index.js:184:7) | ||
at validateLeaf (/Users/nswbmw/Desktop/mongolass-demo/node_modules/another-json-schema/index.js:175:12) | ||
at iterator (/Users/nswbmw/Desktop/mongolass-demo/node_modules/another-json-schema/index.js:120:14) | ||
at iterator (/Users/nswbmw/Desktop/mongolass-demo/node_modules/another-json-schema/index.js:133:29) | ||
at _validateObject (/Users/nswbmw/Desktop/mongolass-demo/node_modules/another-json-schema/index.js:108:11) | ||
at _Schema.validate (/Users/nswbmw/Desktop/mongolass-demo/node_modules/another-json-schema/index.js:38:10) | ||
at formatCreate (/Users/nswbmw/Desktop/mongolass-demo/node_modules/mongolass/lib/schema.js:183:25) | ||
at Query.beforeInsertOne (/Users/nswbmw/Desktop/mongolass-demo/node_modules/mongolass/lib/schema.js:94:7) | ||
at /Users/nswbmw/Desktop/mongolass-demo/node_modules/mongolass/lib/query.js:146:44 | ||
at next (native) | ||
at onFulfilled (/Users/nswbmw/Desktop/mongolass-demo/node_modules/co/index.js:65:19) | ||
at /Users/nswbmw/Desktop/mongolass-demo/node_modules/co/index.js:54:5 | ||
at co (/Users/nswbmw/Desktop/mongolass-demo/node_modules/co/index.js:50:10) | ||
at Query.execBeforePlugins (/Users/nswbmw/Desktop/mongolass-demo/node_modules/mongolass/lib/query.js:142:10) | ||
at /Users/nswbmw/Desktop/mongolass-demo/node_modules/mongolass/lib/query.js:67:39 | ||
----- Mongolass error stack ----- | ||
Error | ||
at Model.insertOne (/Users/nswbmw/Desktop/mongolass-demo/node_modules/mongolass/lib/query.js:108:16) | ||
at Object.<anonymous> (/Users/nswbmw/Desktop/mongolass-demo/app.js:23:4) | ||
at Module._compile (module.js:409:26) | ||
at Object.Module._extensions..js (module.js:416:10) | ||
at Module.load (module.js:343:32) | ||
at Function.Module._load (module.js:300:12) | ||
at Function.Module.runMain (module.js:441:10) | ||
at startup (node.js:139:18) | ||
at node.js:974:3 | ||
*/ | ||
``` | ||
@@ -288,3 +250,4 @@ | ||
co(function* () { | ||
yield User.insert({ firstname: 'san', lastname: 'zhang' }).addCreatedAt('YYYY-MM-DD');// when use yield, .exec() is omissible. | ||
// when use yield, .exec() is omissible. | ||
yield User.insert({ firstname: 'san', lastname: 'zhang' }).addCreatedAt('YYYY-MM-DD'); | ||
console.log(yield User.findOne().addFullname({ sep: '-' })); | ||
@@ -291,0 +254,0 @@ // { _id: 5850186544c3b82d23a82e45, |
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
1986
78810
365