From 975424c0423caa6bdf18ce75cae913be8b16579b Mon Sep 17 00:00:00 2001 From: miker Date: Fri, 20 Apr 2018 22:37:26 -0400 Subject: [PATCH 1/8] Updated using ES6 Transpiled extends --- index.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 16f84d4..7c71b42 100644 --- a/index.js +++ b/index.js @@ -1,11 +1,22 @@ -const mongoose = require('mongoose'); +const mongoose = require("mongoose"); -function extendSchema (Schema, definition, options) { - return new mongoose.Schema( - Object.assign({}, Schema.obj, definition), - options - ); +function extendSchema(parent, child, options) { + let updated_schema = Object.assign({}, parent.obj, child); + let updated_child_object = new mongoose.Schema(updated_schema, options); + __extends(updated_child_object, parent); + return updated_child_object; } -module.exports = extendSchema; +var __extends = + (this && this.__extends) || + function(d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { + this.constructor = d; + } + d.prototype = + b === null ? Object.create(b) : ((__.prototype = b.prototype), new __()); + }; + +module.exports = extendSchema; \ No newline at end of file From afe18ff4cfbe6a497f232a27bafca8a1f0c25c1c Mon Sep 17 00:00:00 2001 From: miker Date: Fri, 20 Apr 2018 22:39:04 -0400 Subject: [PATCH 2/8] Updated readme.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9acaaba..8a23650 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Mongoose schema inheritance -This npm module extends mongoose schema (returning new one) +This npm module extends mongoose schema (returning new one) modified to use ES6 transpiled extends NOT ~~mongoose-schema-extend~~ but **mongoose-extend-schema** @@ -84,4 +84,4 @@ module.exports = extendSchema; Author ---- -@doasync +@thxmike From a7133ec038a2b1f02146c4c2f218f14cb31266a1 Mon Sep 17 00:00:00 2001 From: miker Date: Mon, 23 Apr 2018 10:01:43 -0400 Subject: [PATCH 3/8] Fix problem with schema --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 7c71b42..129d28f 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,7 @@ const mongoose = require("mongoose"); function extendSchema(parent, child, options) { - let updated_schema = Object.assign({}, parent.obj, child); + let updated_schema = Object.assign(parent.obj, child); let updated_child_object = new mongoose.Schema(updated_schema, options); __extends(updated_child_object, parent); return updated_child_object; From e6abd670f15999b8a9fc0c717687e6b4945ee1a0 Mon Sep 17 00:00:00 2001 From: miker Date: Mon, 23 Apr 2018 13:26:19 -0400 Subject: [PATCH 4/8] Updates to handle arrays --- index.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 129d28f..982211e 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,7 @@ - const mongoose = require("mongoose"); function extendSchema(parent, child, options) { - let updated_schema = Object.assign(parent.obj, child); + let updated_schema = Object.assign({}, parent.obj, child); let updated_child_object = new mongoose.Schema(updated_schema, options); __extends(updated_child_object, parent); return updated_child_object; @@ -11,7 +10,16 @@ function extendSchema(parent, child, options) { var __extends = (this && this.__extends) || function(d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + for (var p in b) + if (b.hasOwnProperty(p)) { + //array + if (Array.isArray(b[p]) && Array.isArray(d[p])) { + d[p] = Array.from(new Set(d[p].concat(b[p]))); + } else { + //actual object + d[p] = Object.assign({}, b[p], d[p]); + } + } function __() { this.constructor = d; } @@ -19,4 +27,4 @@ var __extends = b === null ? Object.create(b) : ((__.prototype = b.prototype), new __()); }; -module.exports = extendSchema; \ No newline at end of file +module.exports = extendSchema; From c2cb251cf2b4d42cf5f0a3e93cf20cec3faceb6b Mon Sep 17 00:00:00 2001 From: miker Date: Mon, 23 Apr 2018 13:28:50 -0400 Subject: [PATCH 5/8] Updates to readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8a23650..f2f1551 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ NOT ~~mongoose-schema-extend~~ but **mongoose-extend-schema** ### Installation ```sh -$ npm i --save mongoose-extend-schema +$ npm install thxmike/mongoose-extend-schema --save ``` ### Usage From f1c90f1a944d02218e1483b6f662668aebe2dfce Mon Sep 17 00:00:00 2001 From: miker Date: Fri, 6 Jul 2018 15:41:57 -0400 Subject: [PATCH 6/8] Added mongoose injection --- index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 982211e..a3160f1 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,13 @@ const mongoose = require("mongoose"); -function extendSchema(parent, child, options) { +function extendSchema(parent, child, options, injected_mongoose) { let updated_schema = Object.assign({}, parent.obj, child); - let updated_child_object = new mongoose.Schema(updated_schema, options); + if (ex_mongoose){ + this._mongoose = injected_mongoose; + } else { + this._mongoose = mongoose; + } + let updated_child_object = new this._mongoose.Schema(updated_schema, options); __extends(updated_child_object, parent); return updated_child_object; } From 934f98c22b35ee20f573fc003a827c368a17c39f Mon Sep 17 00:00:00 2001 From: miker Date: Fri, 6 Jul 2018 15:54:13 -0400 Subject: [PATCH 7/8] Added mongoose injection --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index a3160f1..908c0d6 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,7 @@ const mongoose = require("mongoose"); function extendSchema(parent, child, options, injected_mongoose) { let updated_schema = Object.assign({}, parent.obj, child); - if (ex_mongoose){ + if (injected_mongoose){ this._mongoose = injected_mongoose; } else { this._mongoose = mongoose; From bc009a09c272060608aad08f2efc1828f84b63ce Mon Sep 17 00:00:00 2001 From: miker Date: Fri, 16 Aug 2019 08:08:38 -0400 Subject: [PATCH 8/8] Updated Dependency and Updated package.json --- package.json | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index ddc5a4a..e0407c7 100644 --- a/package.json +++ b/package.json @@ -1,21 +1,20 @@ { "name": "mongoose-extend-schema", "description": "Extends mongoose schema", - "version": "1.0.0", + "version": "1.0.1", "author": { - "name": "doasync", - "email": "doasync@gmail.com" + "name": "Michael Rivera" }, "repository": { "type": "git", - "url": "git://github.com/doasync/mongoose-extend-schema.git" + "url": "https://github.com/thxmike/mongoose-extend-schema.git" }, "engines": { "node": ">= 8.2.1", "npm": ">= 5.3.0" }, "dependencies": { - "mongoose": "*" + "mongoose": "5.6.6" }, "main": "index.js", "license": "MIT"