diff options
Diffstat (limited to 'common/src/main/webapp/usageguide/appserver/node_modules/mongoose/lib/types')
7 files changed, 1834 insertions, 0 deletions
diff --git a/common/src/main/webapp/usageguide/appserver/node_modules/mongoose/lib/types/array.js b/common/src/main/webapp/usageguide/appserver/node_modules/mongoose/lib/types/array.js new file mode 100644 index 0000000..715b6b6 --- /dev/null +++ b/common/src/main/webapp/usageguide/appserver/node_modules/mongoose/lib/types/array.js @@ -0,0 +1,778 @@ +/*! + * Module dependencies. + */ + +var EmbeddedDocument = require('./embedded'); +var Document = require('../document'); +var ObjectId = require('./objectid'); +var utils = require('../utils'); +var isMongooseObject = utils.isMongooseObject; + +/** + * Mongoose Array constructor. + * + * ####NOTE: + * + * _Values always have to be passed to the constructor to initialize, otherwise `MongooseArray#push` will mark the array as modified._ + * + * @param {Array} values + * @param {String} path + * @param {Document} doc parent document + * @api private + * @inherits Array + * @see http://bit.ly/f6CnZU + */ + +function MongooseArray(values, path, doc) { + var arr = [].concat(values); + + var keysMA = Object.keys(MongooseArray.mixin); + var numKeys = keysMA.length; + for (var i = 0; i < numKeys; ++i) { + arr[keysMA[i]] = MongooseArray.mixin[keysMA[i]]; + } + + arr._path = path; + arr.isMongooseArray = true; + arr.validators = []; + arr._atomics = {}; + arr._schema = void 0; + + // Because doc comes from the context of another function, doc === global + // can happen if there was a null somewhere up the chain (see #3020) + // RB Jun 17, 2015 updated to check for presence of expected paths instead + // to make more proof against unusual node environments + if (doc && doc instanceof Document) { + arr._parent = doc; + arr._schema = doc.schema.path(path); + } + + return arr; +} + +MongooseArray.mixin = { + /*! + * ignore + */ + toBSON: function() { + return this.toObject({ transform: false }); + }, + + /** + * Stores a queue of atomic operations to perform + * + * @property _atomics + * @api private + */ + + _atomics: undefined, + + /** + * Parent owner document + * + * @property _parent + * @api private + * @receiver MongooseArray + */ + + _parent: undefined, + + /** + * Casts a member based on this arrays schema. + * + * @param {any} value + * @return value the casted value + * @method _cast + * @api private + * @receiver MongooseArray + */ + + _cast: function(value) { + var populated = false; + var Model; + + if (this._parent) { + populated = this._parent.populated(this._path, true); + } + + if (populated && value !== null && value !== undefined) { + // cast to the populated Models schema + Model = populated.options.model; + + // only objects are permitted so we can safely assume that + // non-objects are to be interpreted as _id + if (Buffer.isBuffer(value) || + value instanceof ObjectId || !utils.isObject(value)) { + value = {_id: value}; + } + + // gh-2399 + // we should cast model only when it's not a discriminator + var isDisc = value.schema && value.schema.discriminatorMapping && + value.schema.discriminatorMapping.key !== undefined; + if (!isDisc) { + value = new Model(value); + } + return this._schema.caster.cast(value, this._parent, true); + } + + return this._schema.caster.cast(value, this._parent, false); + }, + + /** + * Marks this array as modified. + * + * If it bubbles up from an embedded document change, then it takes the following arguments (otherwise, takes 0 arguments) + * + * @param {EmbeddedDocument} embeddedDoc the embedded doc that invoked this method on the Array + * @param {String} embeddedPath the path which changed in the embeddedDoc + * @method _markModified + * @api private + * @receiver MongooseArray + */ + + _markModified: function(elem, embeddedPath) { + var parent = this._parent, + dirtyPath; + + if (parent) { + dirtyPath = this._path; + + if (arguments.length) { + if (embeddedPath != null) { + // an embedded doc bubbled up the change + dirtyPath = dirtyPath + '.' + this.indexOf(elem) + '.' + embeddedPath; + } else { + // directly set an index + dirtyPath = dirtyPath + '.' + elem; + } + } + + parent.markModified(dirtyPath); + } + + return this; + }, + + /** + * Register an atomic operation with the parent. + * + * @param {Array} op operation + * @param {any} val + * @method _registerAtomic + * @api private + * @receiver MongooseArray + */ + + _registerAtomic: function(op, val) { + if (op === '$set') { + // $set takes precedence over all other ops. + // mark entire array modified. + this._atomics = {$set: val}; + return this; + } + + var atomics = this._atomics; + + // reset pop/shift after save + if (op === '$pop' && !('$pop' in atomics)) { + var _this = this; + this._parent.once('save', function() { + _this._popped = _this._shifted = null; + }); + } + + // check for impossible $atomic combos (Mongo denies more than one + // $atomic op on a single path + if (this._atomics.$set || + Object.keys(atomics).length && !(op in atomics)) { + // a different op was previously registered. + // save the entire thing. + this._atomics = {$set: this}; + return this; + } + + var selector; + + if (op === '$pullAll' || op === '$pushAll' || op === '$addToSet') { + atomics[op] || (atomics[op] = []); + atomics[op] = atomics[op].concat(val); + } else if (op === '$pullDocs') { + var pullOp = atomics['$pull'] || (atomics['$pull'] = {}); + if (val[0] instanceof EmbeddedDocument) { + selector = pullOp['$or'] || (pullOp['$or'] = []); + Array.prototype.push.apply(selector, val.map(function(v) { + return v.toObject({transform: false}); + })); + } else { + selector = pullOp['_id'] || (pullOp['_id'] = {$in: []}); + selector['$in'] = selector['$in'].concat(val); + } + } else { + atomics[op] = val; + } + + return this; + }, + + /** + * Depopulates stored atomic operation values as necessary for direct insertion to MongoDB. + * + * If no atomics exist, we return all array values after conversion. + * + * @return {Array} + * @method $__getAtomics + * @memberOf MongooseArray + * @api private + */ + + $__getAtomics: function() { + var ret = []; + var keys = Object.keys(this._atomics); + var i = keys.length; + + if (i === 0) { + ret[0] = ['$set', this.toObject({depopulate: 1, transform: false, _isNested: true})]; + return ret; + } + + while (i--) { + var op = keys[i]; + var val = this._atomics[op]; + + // the atomic values which are arrays are not MongooseArrays. we + // need to convert their elements as if they were MongooseArrays + // to handle populated arrays versus DocumentArrays properly. + if (isMongooseObject(val)) { + val = val.toObject({depopulate: 1, transform: false, _isNested: true}); + } else if (Array.isArray(val)) { + val = this.toObject.call(val, {depopulate: 1, transform: false, _isNested: true}); + } else if (val.valueOf) { + val = val.valueOf(); + } + + if (op === '$addToSet') { + val = {$each: val}; + } + + ret.push([op, val]); + } + + return ret; + }, + + /** + * Returns the number of pending atomic operations to send to the db for this array. + * + * @api private + * @return {Number} + * @method hasAtomics + * @receiver MongooseArray + */ + + hasAtomics: function hasAtomics() { + if (!(this._atomics && this._atomics.constructor.name === 'Object')) { + return 0; + } + + return Object.keys(this._atomics).length; + }, + + /** + * Internal helper for .map() + * + * @api private + * @return {Number} + * @method _mapCast + * @receiver MongooseArray + */ + _mapCast: function(val, index) { + return this._cast(val, this.length + index); + }, + + /** + * Wraps [`Array#push`](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/push) with proper change tracking. + * + * @param {Object} [args...] + * @api public + * @method push + * @receiver MongooseArray + */ + + push: function() { + var values = [].map.call(arguments, this._mapCast, this); + values = this._schema.applySetters(values, this._parent, undefined, + undefined, {skipDocumentArrayCast: true}); + var ret = [].push.apply(this, values); + + // $pushAll might be fibbed (could be $push). But it makes it easier to + // handle what could have been $push, $pushAll combos + this._registerAtomic('$pushAll', values); + this._markModified(); + return ret; + }, + + /** + * Pushes items to the array non-atomically. + * + * ####NOTE: + * + * _marks the entire array as modified, which if saved, will store it as a `$set` operation, potentially overwritting any changes that happen between when you retrieved the object and when you save it._ + * + * @param {any} [args...] + * @api public + * @method nonAtomicPush + * @receiver MongooseArray + */ + + nonAtomicPush: function() { + var values = [].map.call(arguments, this._mapCast, this); + var ret = [].push.apply(this, values); + this._registerAtomic('$set', this); + this._markModified(); + return ret; + }, + + /** + * Pops the array atomically at most one time per document `save()`. + * + * #### NOTE: + * + * _Calling this mulitple times on an array before saving sends the same command as calling it once._ + * _This update is implemented using the MongoDB [$pop](http://www.mongodb.org/display/DOCS/Updating/#Updating-%24pop) method which enforces this restriction._ + * + * doc.array = [1,2,3]; + * + * var popped = doc.array.$pop(); + * console.log(popped); // 3 + * console.log(doc.array); // [1,2] + * + * // no affect + * popped = doc.array.$pop(); + * console.log(doc.array); // [1,2] + * + * doc.save(function (err) { + * if (err) return handleError(err); + * + * // we saved, now $pop works again + * popped = doc.array.$pop(); + * console.log(popped); // 2 + * console.log(doc.array); // [1] + * }) + * + * @api public + * @method $pop + * @memberOf MongooseArray + * @see mongodb http://www.mongodb.org/display/DOCS/Updating/#Updating-%24pop + * @method $pop + * @receiver MongooseArray + */ + + $pop: function() { + this._registerAtomic('$pop', 1); + this._markModified(); + + // only allow popping once + if (this._popped) { + return; + } + this._popped = true; + + return [].pop.call(this); + }, + + /** + * Wraps [`Array#pop`](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/pop) with proper change tracking. + * + * ####Note: + * + * _marks the entire array as modified which will pass the entire thing to $set potentially overwritting any changes that happen between when you retrieved the object and when you save it._ + * + * @see MongooseArray#$pop #types_array_MongooseArray-%24pop + * @api public + * @method pop + * @receiver MongooseArray + */ + + pop: function() { + var ret = [].pop.call(this); + this._registerAtomic('$set', this); + this._markModified(); + return ret; + }, + + /** + * Atomically shifts the array at most one time per document `save()`. + * + * ####NOTE: + * + * _Calling this mulitple times on an array before saving sends the same command as calling it once._ + * _This update is implemented using the MongoDB [$pop](http://www.mongodb.org/display/DOCS/Updating/#Updating-%24pop) method which enforces this restriction._ + * + * doc.array = [1,2,3]; + * + * var shifted = doc.array.$shift(); + * console.log(shifted); // 1 + * console.log(doc.array); // [2,3] + * + * // no affect + * shifted = doc.array.$shift(); + * console.log(doc.array); // [2,3] + * + * doc.save(function (err) { + * if (err) return handleError(err); + * + * // we saved, now $shift works again + * shifted = doc.array.$shift(); + * console.log(shifted ); // 2 + * console.log(doc.array); // [3] + * }) + * + * @api public + * @memberOf MongooseArray + * @method $shift + * @see mongodb http://www.mongodb.org/display/DOCS/Updating/#Updating-%24pop + */ + + $shift: function $shift() { + this._registerAtomic('$pop', -1); + this._markModified(); + + // only allow shifting once + if (this._shifted) { + return; + } + this._shifted = true; + + return [].shift.call(this); + }, + + /** + * Wraps [`Array#shift`](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/unshift) with proper change tracking. + * + * ####Example: + * + * doc.array = [2,3]; + * var res = doc.array.shift(); + * console.log(res) // 2 + * console.log(doc.array) // [3] + * + * ####Note: + * + * _marks the entire array as modified, which if saved, will store it as a `$set` operation, potentially overwritting any changes that happen between when you retrieved the object and when you save it._ + * + * @api public + * @method shift + * @receiver MongooseArray + */ + + shift: function() { + var ret = [].shift.call(this); + this._registerAtomic('$set', this); + this._markModified(); + return ret; + }, + + /** + * Pulls items from the array atomically. Equality is determined by casting + * the provided value to an embedded document and comparing using + * [the `Document.equals()` function.](./api.html#document_Document-equals) + * + * ####Examples: + * + * doc.array.pull(ObjectId) + * doc.array.pull({ _id: 'someId' }) + * doc.array.pull(36) + * doc.array.pull('tag 1', 'tag 2') + * + * To remove a document from a subdocument array we may pass an object with a matching `_id`. + * + * doc.subdocs.push({ _id: 4815162342 }) + * doc.subdocs.pull({ _id: 4815162342 }) // removed + * + * Or we may passing the _id directly and let mongoose take care of it. + * + * doc.subdocs.push({ _id: 4815162342 }) + * doc.subdocs.pull(4815162342); // works + * + * The first pull call will result in a atomic operation on the database, if pull is called repeatedly without saving the document, a $set operation is used on the complete array instead, overwriting possible changes that happened on the database in the meantime. + * + * @param {any} [args...] + * @see mongodb http://www.mongodb.org/display/DOCS/Updating/#Updating-%24pull + * @api public + * @method pull + * @receiver MongooseArray + */ + + pull: function() { + var values = [].map.call(arguments, this._cast, this), + cur = this._parent.get(this._path), + i = cur.length, + mem; + + while (i--) { + mem = cur[i]; + if (mem instanceof Document) { + var some = values.some(function(v) { + return mem.equals(v); + }); + if (some) { + [].splice.call(cur, i, 1); + } + } else if (~cur.indexOf.call(values, mem)) { + [].splice.call(cur, i, 1); + } + } + + if (values[0] instanceof EmbeddedDocument) { + this._registerAtomic('$pullDocs', values.map(function(v) { + return v._id || v; + })); + } else { + this._registerAtomic('$pullAll', values); + } + + this._markModified(); + return this; + }, + + /** + * Wraps [`Array#splice`](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/splice) with proper change tracking and casting. + * + * ####Note: + * + * _marks the entire array as modified, which if saved, will store it as a `$set` operation, potentially overwritting any changes that happen between when you retrieved the object and when you save it._ + * + * @api public + * @method splice + * @receiver MongooseArray + */ + + splice: function splice() { + var ret, vals, i; + + if (arguments.length) { + vals = []; + for (i = 0; i < arguments.length; ++i) { + vals[i] = i < 2 + ? arguments[i] + : this._cast(arguments[i], arguments[0] + (i - 2)); + } + ret = [].splice.apply(this, vals); + this._registerAtomic('$set', this); + this._markModified(); + } + + return ret; + }, + + /** + * Wraps [`Array#unshift`](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/unshift) with proper change tracking. + * + * ####Note: + * + * _marks the entire array as modified, which if saved, will store it as a `$set` operation, potentially overwritting any changes that happen between when you retrieved the object and when you save it._ + * + * @api public + * @method unshift + * @receiver MongooseArray + */ + + unshift: function() { + var values = [].map.call(arguments, this._cast, this); + values = this._schema.applySetters(values, this._parent); + [].unshift.apply(this, values); + this._registerAtomic('$set', this); + this._markModified(); + return this.length; + }, + + /** + * Wraps [`Array#sort`](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/sort) with proper change tracking. + * + * ####NOTE: + * + * _marks the entire array as modified, which if saved, will store it as a `$set` operation, potentially overwritting any changes that happen between when you retrieved the object and when you save it._ + * + * @api public + * @method sort + * @receiver MongooseArray + */ + + sort: function() { + var ret = [].sort.apply(this, arguments); + this._registerAtomic('$set', this); + this._markModified(); + return ret; + }, + + /** + * Adds values to the array if not already present. + * + * ####Example: + * + * console.log(doc.array) // [2,3,4] + * var added = doc.array.addToSet(4,5); + * console.log(doc.array) // [2,3,4,5] + * console.log(added) // [5] + * + * @param {any} [args...] + * @return {Array} the values that were added + * @receiver MongooseArray + * @api public + * @method addToSet + */ + + addToSet: function addToSet() { + var values = [].map.call(arguments, this._mapCast, this); + values = this._schema.applySetters(values, this._parent); + var added = []; + var type = ''; + if (values[0] instanceof EmbeddedDocument) { + type = 'doc'; + } else if (values[0] instanceof Date) { + type = 'date'; + } + + values.forEach(function(v) { + var found; + switch (type) { + case 'doc': + found = this.some(function(doc) { + return doc.equals(v); + }); + break; + case 'date': + var val = +v; + found = this.some(function(d) { + return +d === val; + }); + break; + default: + found = ~this.indexOf(v); + } + + if (!found) { + [].push.call(this, v); + this._registerAtomic('$addToSet', v); + this._markModified(); + [].push.call(added, v); + } + }, this); + + return added; + }, + + /** + * Sets the casted `val` at index `i` and marks the array modified. + * + * ####Example: + * + * // given documents based on the following + * var Doc = mongoose.model('Doc', new Schema({ array: [Number] })); + * + * var doc = new Doc({ array: [2,3,4] }) + * + * console.log(doc.array) // [2,3,4] + * + * doc.array.set(1,"5"); + * console.log(doc.array); // [2,5,4] // properly cast to number + * doc.save() // the change is saved + * + * // VS not using array#set + * doc.array[1] = "5"; + * console.log(doc.array); // [2,"5",4] // no casting + * doc.save() // change is not saved + * + * @return {Array} this + * @api public + * @method set + * @receiver MongooseArray + */ + + set: function set(i, val) { + var value = this._cast(val, i); + value = this._schema.caster instanceof EmbeddedDocument ? + value : + this._schema.caster.applySetters(val, this._parent) + ; + this[i] = value; + this._markModified(i); + return this; + }, + + /** + * Returns a native js Array. + * + * @param {Object} options + * @return {Array} + * @api public + * @method toObject + * @receiver MongooseArray + */ + + toObject: function(options) { + if (options && options.depopulate) { + options._isNested = true; + return this.map(function(doc) { + return doc instanceof Document + ? doc.toObject(options) + : doc; + }); + } + + return this.slice(); + }, + + /** + * Helper for console.log + * + * @api public + * @method inspect + * @receiver MongooseArray + */ + + inspect: function() { + return JSON.stringify(this); + }, + + /** + * Return the index of `obj` or `-1` if not found. + * + * @param {Object} obj the item to look for + * @return {Number} + * @api public + * @method indexOf + * @receiver MongooseArray + */ + + indexOf: function indexOf(obj) { + if (obj instanceof ObjectId) { + obj = obj.toString(); + } + for (var i = 0, len = this.length; i < len; ++i) { + if (obj == this[i]) { + return i; + } + } + return -1; + } +}; + +/** + * Alias of [pull](#types_array_MongooseArray-pull) + * + * @see MongooseArray#pull #types_array_MongooseArray-pull + * @see mongodb http://www.mongodb.org/display/DOCS/Updating/#Updating-%24pull + * @api public + * @memberOf MongooseArray + * @method remove + */ + +MongooseArray.mixin.remove = MongooseArray.mixin.pull; + +/*! + * Module exports. + */ + +module.exports = exports = MongooseArray; diff --git a/common/src/main/webapp/usageguide/appserver/node_modules/mongoose/lib/types/buffer.js b/common/src/main/webapp/usageguide/appserver/node_modules/mongoose/lib/types/buffer.js new file mode 100644 index 0000000..8be67c8 --- /dev/null +++ b/common/src/main/webapp/usageguide/appserver/node_modules/mongoose/lib/types/buffer.js @@ -0,0 +1,273 @@ +/*! + * Module dependencies. + */ + +var Binary = require('../drivers').Binary, + utils = require('../utils'); + +/** + * Mongoose Buffer constructor. + * + * Values always have to be passed to the constructor to initialize. + * + * @param {Buffer} value + * @param {String} encode + * @param {Number} offset + * @api private + * @inherits Buffer + * @see http://bit.ly/f6CnZU + */ + +function MongooseBuffer(value, encode, offset) { + var length = arguments.length; + var val; + + if (length === 0 || arguments[0] === null || arguments[0] === undefined) { + val = 0; + } else { + val = value; + } + + var encoding; + var path; + var doc; + + if (Array.isArray(encode)) { + // internal casting + path = encode[0]; + doc = encode[1]; + } else { + encoding = encode; + } + + var buf = new Buffer(val, encoding, offset); + utils.decorate(buf, MongooseBuffer.mixin); + buf.isMongooseBuffer = true; + + // make sure these internal props don't show up in Object.keys() + Object.defineProperties(buf, { + validators: {value: []}, + _path: {value: path}, + _parent: {value: doc} + }); + + if (doc && typeof path === 'string') { + Object.defineProperty(buf, '_schema', { + value: doc.schema.path(path) + }); + } + + buf._subtype = 0; + return buf; +} + +/*! + * Inherit from Buffer. + */ + +// MongooseBuffer.prototype = new Buffer(0); + +MongooseBuffer.mixin = { + + /** + * Parent owner document + * + * @api private + * @property _parent + * @receiver MongooseBuffer + */ + + _parent: undefined, + + /** + * Default subtype for the Binary representing this Buffer + * + * @api private + * @property _subtype + * @receiver MongooseBuffer + */ + + _subtype: undefined, + + /** + * Marks this buffer as modified. + * + * @api private + * @method _markModified + * @receiver MongooseBuffer + */ + + _markModified: function() { + var parent = this._parent; + + if (parent) { + parent.markModified(this._path); + } + return this; + }, + + /** + * Writes the buffer. + * + * @api public + * @method write + * @receiver MongooseBuffer + */ + + write: function() { + var written = Buffer.prototype.write.apply(this, arguments); + + if (written > 0) { + this._markModified(); + } + + return written; + }, + + /** + * Copies the buffer. + * + * ####Note: + * + * `Buffer#copy` does not mark `target` as modified so you must copy from a `MongooseBuffer` for it to work as expected. This is a work around since `copy` modifies the target, not this. + * + * @return {Number} The number of bytes copied. + * @param {Buffer} target + * @method copy + * @receiver MongooseBuffer + */ + + copy: function(target) { + var ret = Buffer.prototype.copy.apply(this, arguments); + + if (target && target.isMongooseBuffer) { + target._markModified(); + } + + return ret; + } +}; + +/*! + * Compile other Buffer methods marking this buffer as modified. + */ + +( +// node < 0.5 + 'writeUInt8 writeUInt16 writeUInt32 writeInt8 writeInt16 writeInt32 ' + + 'writeFloat writeDouble fill ' + + 'utf8Write binaryWrite asciiWrite set ' + + +// node >= 0.5 + 'writeUInt16LE writeUInt16BE writeUInt32LE writeUInt32BE ' + + 'writeInt16LE writeInt16BE writeInt32LE writeInt32BE ' + + 'writeFloatLE writeFloatBE writeDoubleLE writeDoubleBE' +).split(' ').forEach(function(method) { + if (!Buffer.prototype[method]) { + return; + } + MongooseBuffer.mixin[method] = function() { + var ret = Buffer.prototype[method].apply(this, arguments); + this._markModified(); + return ret; + }; +}); + +/** + * Converts this buffer to its Binary type representation. + * + * ####SubTypes: + * + * var bson = require('bson') + * bson.BSON_BINARY_SUBTYPE_DEFAULT + * bson.BSON_BINARY_SUBTYPE_FUNCTION + * bson.BSON_BINARY_SUBTYPE_BYTE_ARRAY + * bson.BSON_BINARY_SUBTYPE_UUID + * bson.BSON_BINARY_SUBTYPE_MD5 + * bson.BSON_BINARY_SUBTYPE_USER_DEFINED + * + * doc.buffer.toObject(bson.BSON_BINARY_SUBTYPE_USER_DEFINED); + * + * @see http://bsonspec.org/#/specification + * @param {Hex} [subtype] + * @return {Binary} + * @api public + * @method toObject + * @receiver MongooseBuffer + */ + +MongooseBuffer.mixin.toObject = function(options) { + var subtype = typeof options === 'number' + ? options + : (this._subtype || 0); + return new Binary(this, subtype); +}; + +/** + * Determines if this buffer is equals to `other` buffer + * + * @param {Buffer} other + * @return {Boolean} + * @method equals + * @receiver MongooseBuffer + */ + +MongooseBuffer.mixin.equals = function(other) { + if (!Buffer.isBuffer(other)) { + return false; + } + + if (this.length !== other.length) { + return false; + } + + for (var i = 0; i < this.length; ++i) { + if (this[i] !== other[i]) { + return false; + } + } + + return true; +}; + +/** + * Sets the subtype option and marks the buffer modified. + * + * ####SubTypes: + * + * var bson = require('bson') + * bson.BSON_BINARY_SUBTYPE_DEFAULT + * bson.BSON_BINARY_SUBTYPE_FUNCTION + * bson.BSON_BINARY_SUBTYPE_BYTE_ARRAY + * bson.BSON_BINARY_SUBTYPE_UUID + * bson.BSON_BINARY_SUBTYPE_MD5 + * bson.BSON_BINARY_SUBTYPE_USER_DEFINED + * + * doc.buffer.subtype(bson.BSON_BINARY_SUBTYPE_UUID); + * + * @see http://bsonspec.org/#/specification + * @param {Hex} subtype + * @api public + * @method subtype + * @receiver MongooseBuffer + */ + +MongooseBuffer.mixin.subtype = function(subtype) { + if (typeof subtype !== 'number') { + throw new TypeError('Invalid subtype. Expected a number'); + } + + if (this._subtype !== subtype) { + this._markModified(); + } + + this._subtype = subtype; +}; + +/*! + * Module exports. + */ + +MongooseBuffer.Binary = Binary; + +module.exports = MongooseBuffer; diff --git a/common/src/main/webapp/usageguide/appserver/node_modules/mongoose/lib/types/documentarray.js b/common/src/main/webapp/usageguide/appserver/node_modules/mongoose/lib/types/documentarray.js new file mode 100644 index 0000000..f6fb227 --- /dev/null +++ b/common/src/main/webapp/usageguide/appserver/node_modules/mongoose/lib/types/documentarray.js @@ -0,0 +1,256 @@ +/*! + * Module dependencies. + */ + +var MongooseArray = require('./array'), + ObjectId = require('./objectid'), + ObjectIdSchema = require('../schema/objectid'), + utils = require('../utils'), + Document = require('../document'); + +/** + * DocumentArray constructor + * + * @param {Array} values + * @param {String} path the path to this array + * @param {Document} doc parent document + * @api private + * @return {MongooseDocumentArray} + * @inherits MongooseArray + * @see http://bit.ly/f6CnZU + */ + +function MongooseDocumentArray(values, path, doc) { + var arr = [].concat(values); + arr._path = path; + + var props = { + isMongooseArray: true, + isMongooseDocumentArray: true, + validators: [], + _atomics: {}, + _schema: void 0, + _handlers: void 0 + }; + + // Values always have to be passed to the constructor to initialize, since + // otherwise MongooseArray#push will mark the array as modified to the parent. + var keysMA = Object.keys(MongooseArray.mixin); + var numKeys = keysMA.length; + for (var j = 0; j < numKeys; ++j) { + arr[keysMA[j]] = MongooseArray.mixin[keysMA[j]]; + } + + var keysMDA = Object.keys(MongooseDocumentArray.mixin); + numKeys = keysMDA.length; + for (var i = 0; i < numKeys; ++i) { + arr[keysMDA[i]] = MongooseDocumentArray.mixin[keysMDA[i]]; + } + + var keysP = Object.keys(props); + numKeys = keysP.length; + for (var k = 0; k < numKeys; ++k) { + arr[keysP[k]] = props[keysP[k]]; + } + + // Because doc comes from the context of another function, doc === global + // can happen if there was a null somewhere up the chain (see #3020 && #3034) + // RB Jun 17, 2015 updated to check for presence of expected paths instead + // to make more proof against unusual node environments + if (doc && doc instanceof Document) { + arr._parent = doc; + arr._schema = doc.schema.path(path); + arr._handlers = { + isNew: arr.notify('isNew'), + save: arr.notify('save') + }; + + doc.on('save', arr._handlers.save); + doc.on('isNew', arr._handlers.isNew); + } + + return arr; +} + +/*! + * Inherits from MongooseArray + */ +// MongooseDocumentArray.mixin = Object.create( MongooseArray.mixin ); +MongooseDocumentArray.mixin = { + /*! + * ignore + */ + toBSON: function() { + return this.toObject({ transform: false }); + }, + + /** + * Overrides MongooseArray#cast + * + * @method _cast + * @api private + * @receiver MongooseDocumentArray + */ + + _cast: function(value, index) { + if (value instanceof this._schema.casterConstructor) { + if (!(value.__parent && value.__parentArray)) { + // value may have been created using array.create() + value.__parent = this._parent; + value.__parentArray = this; + } + value.__index = index; + return value; + } + + if (value === undefined || value === null) { + return null; + } + + // handle cast('string') or cast(ObjectId) etc. + // only objects are permitted so we can safely assume that + // non-objects are to be interpreted as _id + if (Buffer.isBuffer(value) || + value instanceof ObjectId || !utils.isObject(value)) { + value = {_id: value}; + } + return new this._schema.casterConstructor(value, this, undefined, undefined, index); + }, + + /** + * Searches array items for the first document with a matching _id. + * + * ####Example: + * + * var embeddedDoc = m.array.id(some_id); + * + * @return {EmbeddedDocument|null} the subdocument or null if not found. + * @param {ObjectId|String|Number|Buffer} id + * @TODO cast to the _id based on schema for proper comparison + * @method id + * @api public + * @receiver MongooseDocumentArray + */ + + id: function(id) { + var casted, + sid, + _id; + + try { + var casted_ = ObjectIdSchema.prototype.cast.call({}, id); + if (casted_) { + casted = String(casted_); + } + } catch (e) { + casted = null; + } + + for (var i = 0, l = this.length; i < l; i++) { + _id = this[i].get('_id'); + + if (_id === null || typeof _id === 'undefined') { + continue; + } else if (_id instanceof Document) { + sid || (sid = String(id)); + if (sid == _id._id) { + return this[i]; + } + } else if (!(id instanceof ObjectId) && !(_id instanceof ObjectId)) { + if (utils.deepEqual(id, _id)) { + return this[i]; + } + } else if (casted == _id) { + return this[i]; + } + } + + return null; + }, + + /** + * Returns a native js Array of plain js objects + * + * ####NOTE: + * + * _Each sub-document is converted to a plain object by calling its `#toObject` method._ + * + * @param {Object} [options] optional options to pass to each documents `toObject` method call during conversion + * @return {Array} + * @method toObject + * @api public + * @receiver MongooseDocumentArray + */ + + toObject: function(options) { + return this.map(function(doc) { + return doc && doc.toObject(options) || null; + }); + }, + + /** + * Helper for console.log + * + * @method inspect + * @api public + * @receiver MongooseDocumentArray + */ + + inspect: function() { + return Array.prototype.slice.call(this); + }, + + /** + * Creates a subdocument casted to this schema. + * + * This is the same subdocument constructor used for casting. + * + * @param {Object} obj the value to cast to this arrays SubDocument schema + * @method create + * @api public + * @receiver MongooseDocumentArray + */ + + create: function(obj) { + return new this._schema.casterConstructor(obj); + }, + + /** + * Creates a fn that notifies all child docs of `event`. + * + * @param {String} event + * @return {Function} + * @method notify + * @api private + * @receiver MongooseDocumentArray + */ + + notify: function notify(event) { + var _this = this; + return function notify(val) { + var i = _this.length; + while (i--) { + if (!_this[i]) { + continue; + } + switch (event) { + // only swap for save event for now, we may change this to all event types later + case 'save': + val = _this[i]; + break; + default: + // NO-OP + break; + } + _this[i].emit(event, val); + } + }; + } + +}; + +/*! + * Module exports. + */ + +module.exports = MongooseDocumentArray; diff --git a/common/src/main/webapp/usageguide/appserver/node_modules/mongoose/lib/types/embedded.js b/common/src/main/webapp/usageguide/appserver/node_modules/mongoose/lib/types/embedded.js new file mode 100644 index 0000000..fbeaf6a --- /dev/null +++ b/common/src/main/webapp/usageguide/appserver/node_modules/mongoose/lib/types/embedded.js @@ -0,0 +1,347 @@ +/* eslint no-func-assign: 1 */ + +/*! + * Module dependencies. + */ + +var Document = require('../document_provider')(); +var PromiseProvider = require('../promise_provider'); + +/** + * EmbeddedDocument constructor. + * + * @param {Object} obj js object returned from the db + * @param {MongooseDocumentArray} parentArr the parent array of this document + * @param {Boolean} skipId + * @inherits Document + * @api private + */ + +function EmbeddedDocument(obj, parentArr, skipId, fields, index) { + if (parentArr) { + this.__parentArray = parentArr; + this.__parent = parentArr._parent; + } else { + this.__parentArray = undefined; + this.__parent = undefined; + } + this.__index = index; + + Document.call(this, obj, fields, skipId); + + var _this = this; + this.on('isNew', function(val) { + _this.isNew = val; + }); +} + +/*! + * Inherit from Document + */ +EmbeddedDocument.prototype = Object.create(Document.prototype); +EmbeddedDocument.prototype.constructor = EmbeddedDocument; + +EmbeddedDocument.prototype.toBSON = function() { + return this.toObject({ transform: false }); +}; + +/** + * Marks the embedded doc modified. + * + * ####Example: + * + * var doc = blogpost.comments.id(hexstring); + * doc.mixed.type = 'changed'; + * doc.markModified('mixed.type'); + * + * @param {String} path the path which changed + * @api public + * @receiver EmbeddedDocument + */ + +EmbeddedDocument.prototype.markModified = function(path) { + this.$__.activePaths.modify(path); + if (!this.__parentArray) { + return; + } + + if (this.isNew) { + // Mark the WHOLE parent array as modified + // if this is a new document (i.e., we are initializing + // a document), + this.__parentArray._markModified(); + } else { + this.__parentArray._markModified(this, path); + } +}; + +/*! + * ignore + */ + +EmbeddedDocument.prototype.populate = function() { + throw new Error('Mongoose does not support calling populate() on nested ' + + 'docs. Instead of `doc.arr[0].populate("path")`, use ' + + '`doc.populate("arr.0.path")`'); +}; + +/** + * 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 + */ + +EmbeddedDocument.prototype.save = function(fn) { + var Promise = PromiseProvider.get(); + return new Promise.ES6(function(resolve) { + fn && fn(); + resolve(); + }); +}; + +/*! + * 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); +} + +/** + * Removes the subdocument from its parent array. + * + * @param {Object} [options] + * @param {Function} [fn] + * @api public + */ + +EmbeddedDocument.prototype.remove = function(options, fn) { + if ( typeof options === 'function' && !fn ) { + fn = options; + options = undefined; + } + if (!this.__parentArray || (options && options.noop)) { + fn && fn(null); + return this; + } + + var _id; + if (!this.willRemove) { + _id = this._doc._id; + if (!_id) { + throw new Error('For your own good, Mongoose does not know ' + + 'how to remove an EmbeddedDocument that has no _id'); + } + this.__parentArray.pull({_id: _id}); + this.willRemove = true; + registerRemoveListener(this); + } + + if (fn) { + fn(null); + } + + return this; +}; + +/** + * Override #update method of parent documents. + * @api private + */ + +EmbeddedDocument.prototype.update = function() { + throw new Error('The #update method is not available on EmbeddedDocuments'); +}; + +/** + * Helper for console.log + * + * @api public + */ + +EmbeddedDocument.prototype.inspect = function() { + return this.toObject({ transform: false, retainKeyOrder: true }); +}; + +/** + * Marks a path as invalid, causing validation to fail. + * + * @param {String} path the field to invalidate + * @param {String|Error} err error which states the reason `path` was invalid + * @return {Boolean} + * @api public + */ + +EmbeddedDocument.prototype.invalidate = function(path, err, val, first) { + if (!this.__parent) { + Document.prototype.invalidate.call(this, path, err, val); + if (err.name === 'ValidatorError') { + return true; + } + throw err; + } + + var index = this.__index; + if (typeof index !== 'undefined') { + var parentPath = this.__parentArray._path; + var fullPath = [parentPath, index, path].join('.'); + this.__parent.invalidate(fullPath, err, val); + } + + if (first) { + this.$__.validationError = this.ownerDocument().$__.validationError; + } + + return true; +}; + +/** + * Marks a path as valid, removing existing validation errors. + * + * @param {String} path the field to mark as valid + * @api private + * @method $markValid + * @receiver EmbeddedDocument + */ + +EmbeddedDocument.prototype.$markValid = function(path) { + if (!this.__parent) { + return; + } + + var index = this.__index; + if (typeof index !== 'undefined') { + var parentPath = this.__parentArray._path; + var fullPath = [parentPath, index, path].join('.'); + this.__parent.$markValid(fullPath); + } +}; + +/** + * Checks if a path is invalid + * + * @param {String} path the field to check + * @api private + * @method $isValid + * @receiver EmbeddedDocument + */ + +EmbeddedDocument.prototype.$isValid = function(path) { + var index = this.__index; + if (typeof index !== 'undefined' && this.__parent) { + return !this.__parent.$__.validationError || + !this.__parent.$__.validationError.errors[this.$__fullPath(path)]; + } + + return true; +}; + +/** + * Returns the top level document of this sub-document. + * + * @return {Document} + */ + +EmbeddedDocument.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; +}; + +/** + * Returns the full path to this document. If optional `path` is passed, it is appended to the full path. + * + * @param {String} [path] + * @return {String} + * @api private + * @method $__fullPath + * @memberOf EmbeddedDocument + */ + +EmbeddedDocument.prototype.$__fullPath = function(path) { + if (!this.$__.fullPath) { + var parent = this; // eslint-disable-line consistent-this + if (!parent.__parent) { + return path; + } + + var paths = []; + while (parent.__parent || parent.$parent) { + if (parent.__parent) { + paths.unshift(parent.__parentArray._path); + } else { + paths.unshift(parent.$basePath); + } + parent = parent.__parent || parent.$parent; + } + + this.$__.fullPath = paths.join('.'); + + if (!this.$__.ownerDocument) { + // optimization + this.$__.ownerDocument = parent; + } + } + + return path + ? this.$__.fullPath + '.' + path + : this.$__.fullPath; +}; + +/** + * Returns this sub-documents parent document. + * + * @api public + */ + +EmbeddedDocument.prototype.parent = function() { + return this.__parent; +}; + +/** + * Returns this sub-documents parent array. + * + * @api public + */ + +EmbeddedDocument.prototype.parentArray = function() { + return this.__parentArray; +}; + +/*! + * Module exports. + */ + +module.exports = EmbeddedDocument; diff --git a/common/src/main/webapp/usageguide/appserver/node_modules/mongoose/lib/types/index.js b/common/src/main/webapp/usageguide/appserver/node_modules/mongoose/lib/types/index.js new file mode 100644 index 0000000..0d01923 --- /dev/null +++ b/common/src/main/webapp/usageguide/appserver/node_modules/mongoose/lib/types/index.js @@ -0,0 +1,15 @@ + +/*! + * Module exports. + */ + +exports.Array = require('./array'); +exports.Buffer = require('./buffer'); + +exports.Document = // @deprecate +exports.Embedded = require('./embedded'); + +exports.DocumentArray = require('./documentarray'); +exports.ObjectId = require('./objectid'); + +exports.Subdocument = require('./subdocument'); diff --git a/common/src/main/webapp/usageguide/appserver/node_modules/mongoose/lib/types/objectid.js b/common/src/main/webapp/usageguide/appserver/node_modules/mongoose/lib/types/objectid.js new file mode 100644 index 0000000..9fe0b97 --- /dev/null +++ b/common/src/main/webapp/usageguide/appserver/node_modules/mongoose/lib/types/objectid.js @@ -0,0 +1,13 @@ +/** + * ObjectId type constructor + * + * ####Example + * + * var id = new mongoose.Types.ObjectId; + * + * @constructor ObjectId + */ + +var ObjectId = require('../drivers').ObjectId; + +module.exports = ObjectId; 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); +} |