diff options
author | 2017-08-07 11:39:39 +0800 | |
---|---|---|
committer | 2017-08-07 11:39:39 +0800 | |
commit | 21d72c4a80fe2937d0c4ddd20624b27adbcd989b (patch) | |
tree | e5013ee12f74f8452e01cbff16e7b0158bc456cb /common/src/main/webapp/usageguide/appserver/node_modules/mongoose/lib/types/subdocument.js | |
parent | f533e73e2ae32e010b16abdcf7985abaf31ab843 (diff) |
Upload the ESR GUI seed code
Issue-ID: AAI-68
Change-Id: Ia50ce0570c2fabecd77199d4e8454f56fe587c4e
Signed-off-by: lizi00164331 <li.zi30@zte.com.cn>
Diffstat (limited to 'common/src/main/webapp/usageguide/appserver/node_modules/mongoose/lib/types/subdocument.js')
-rw-r--r-- | common/src/main/webapp/usageguide/appserver/node_modules/mongoose/lib/types/subdocument.js | 152 |
1 files changed, 152 insertions, 0 deletions
diff --git a/common/src/main/webapp/usageguide/appserver/node_modules/mongoose/lib/types/subdocument.js b/common/src/main/webapp/usageguide/appserver/node_modules/mongoose/lib/types/subdocument.js new file mode 100644 index 0000000..911fdf4 --- /dev/null +++ b/common/src/main/webapp/usageguide/appserver/node_modules/mongoose/lib/types/subdocument.js @@ -0,0 +1,152 @@ +var Document = require('../document'); +var PromiseProvider = require('../promise_provider'); + +module.exports = Subdocument; + +/** + * Subdocument constructor. + * + * @inherits Document + * @api private + */ + +function Subdocument(value, fields) { + this.$isSingleNested = true; + Document.call(this, value, fields); +} + +Subdocument.prototype = Object.create(Document.prototype); + +Subdocument.prototype.toBSON = function() { + return this.toObject({ transform: false }); +}; + +/** + * Used as a stub for [hooks.js](https://github.com/bnoguchi/hooks-js/tree/31ec571cef0332e21121ee7157e0cf9728572cc3) + * + * ####NOTE: + * + * _This is a no-op. Does not actually save the doc to the db._ + * + * @param {Function} [fn] + * @return {Promise} resolved Promise + * @api private + */ + +Subdocument.prototype.save = function(fn) { + var Promise = PromiseProvider.get(); + return new Promise.ES6(function(resolve) { + fn && fn(); + resolve(); + }); +}; + +Subdocument.prototype.$isValid = function(path) { + if (this.$parent) { + return this.$parent.$isValid([this.$basePath, path].join('.')); + } +}; + +Subdocument.prototype.markModified = function(path) { + Document.prototype.markModified.call(this, path); + if (this.$parent) { + if (this.$parent.isDirectModified(this.$basePath)) { + return; + } + this.$parent.markModified([this.$basePath, path].join('.')); + } +}; + +Subdocument.prototype.$markValid = function(path) { + if (this.$parent) { + this.$parent.$markValid([this.$basePath, path].join('.')); + } +}; + +Subdocument.prototype.invalidate = function(path, err, val) { + Document.prototype.invalidate.call(this, path, err, val); + if (this.$parent) { + this.$parent.invalidate([this.$basePath, path].join('.'), err, val); + } else if (err.kind === 'cast' || err.name === 'CastError') { + throw err; + } +}; + +/** + * Returns the top level document of this sub-document. + * + * @return {Document} + */ + +Subdocument.prototype.ownerDocument = function() { + if (this.$__.ownerDocument) { + return this.$__.ownerDocument; + } + + var parent = this.$parent; + if (!parent) { + return this; + } + + while (parent.$parent || parent.__parent) { + parent = parent.$parent || parent.__parent; + } + this.$__.ownerDocument = parent; + return this.$__.ownerDocument; +}; + +/** + * Null-out this subdoc + * + * @param {Object} [options] + * @param {Function} [callback] optional callback for compatibility with Document.prototype.remove + */ + +Subdocument.prototype.remove = function(options, callback) { + if (typeof options === 'function') { + callback = options; + options = null; + } + + // If removing entire doc, no need to remove subdoc + if (!options || !options.noop) { + this.$parent.set(this.$basePath, null); + registerRemoveListener(this); + } + + if (typeof callback === 'function') { + callback(null); + } +}; + +/*! + * ignore + */ + +Subdocument.prototype.populate = function() { + throw new Error('Mongoose does not support calling populate() on nested ' + + 'docs. Instead of `doc.nested.populate("path")`, use ' + + '`doc.populate("nested.path")`'); +}; + +/*! + * Registers remove event listeners for triggering + * on subdocuments. + * + * @param {EmbeddedDocument} sub + * @api private + */ + +function registerRemoveListener(sub) { + var owner = sub.ownerDocument(); + + function emitRemove() { + owner.removeListener('save', emitRemove); + owner.removeListener('remove', emitRemove); + sub.emit('remove', sub); + owner = sub = null; + } + + owner.on('save', emitRemove); + owner.on('remove', emitRemove); +} |