\n */\n AV.GeoPoint = function (arg1, arg2) {\n if (_.isArray(arg1)) {\n AV.GeoPoint._validate(arg1[0], arg1[1]);\n\n this.latitude = arg1[0];\n this.longitude = arg1[1];\n } else if (_.isObject(arg1)) {\n AV.GeoPoint._validate(arg1.latitude, arg1.longitude);\n\n this.latitude = arg1.latitude;\n this.longitude = arg1.longitude;\n } else if (_.isNumber(arg1) && _.isNumber(arg2)) {\n AV.GeoPoint._validate(arg1, arg2);\n\n this.latitude = arg1;\n this.longitude = arg2;\n } else {\n this.latitude = 0;\n this.longitude = 0;\n } // Add properties so that anyone using Webkit or Mozilla will get an error\n // if they try to set values that are out of bounds.\n\n\n var self = this;\n\n if (this.__defineGetter__ && this.__defineSetter__) {\n // Use _latitude and _longitude to actually store the values, and add\n // getters and setters for latitude and longitude.\n this._latitude = this.latitude;\n this._longitude = this.longitude;\n\n this.__defineGetter__('latitude', function () {\n return self._latitude;\n });\n\n this.__defineGetter__('longitude', function () {\n return self._longitude;\n });\n\n this.__defineSetter__('latitude', function (val) {\n AV.GeoPoint._validate(val, self.longitude);\n\n self._latitude = val;\n });\n\n this.__defineSetter__('longitude', function (val) {\n AV.GeoPoint._validate(self.latitude, val);\n\n self._longitude = val;\n });\n }\n };\n /**\n * @lends AV.GeoPoint.prototype\n * @property {float} latitude North-south portion of the coordinate, in range\n * [-90, 90]. Throws an exception if set out of range in a modern browser.\n * @property {float} longitude East-west portion of the coordinate, in range\n * [-180, 180]. Throws if set out of range in a modern browser.\n */\n\n /**\n * Throws an exception if the given lat-long is out of bounds.\n * @private\n */\n\n\n AV.GeoPoint._validate = function (latitude, longitude) {\n if (latitude < -90.0) {\n throw new Error('AV.GeoPoint latitude ' + latitude + ' < -90.0.');\n }\n\n if (latitude > 90.0) {\n throw new Error('AV.GeoPoint latitude ' + latitude + ' > 90.0.');\n }\n\n if (longitude < -180.0) {\n throw new Error('AV.GeoPoint longitude ' + longitude + ' < -180.0.');\n }\n\n if (longitude > 180.0) {\n throw new Error('AV.GeoPoint longitude ' + longitude + ' > 180.0.');\n }\n };\n /**\n * Creates a GeoPoint with the user's current location, if available.\n * @return {Promise.}\n */\n\n\n AV.GeoPoint.current = function () {\n return new _promise.default(function (resolve, reject) {\n navigator.geolocation.getCurrentPosition(function (location) {\n resolve(new AV.GeoPoint({\n latitude: location.coords.latitude,\n longitude: location.coords.longitude\n }));\n }, reject);\n });\n };\n\n _.extend(AV.GeoPoint.prototype,\n /** @lends AV.GeoPoint.prototype */\n {\n /**\n * Returns a JSON representation of the GeoPoint, suitable for AV.\n * @return {Object}\n */\n toJSON: function toJSON() {\n AV.GeoPoint._validate(this.latitude, this.longitude);\n\n return {\n __type: 'GeoPoint',\n latitude: this.latitude,\n longitude: this.longitude\n };\n },\n\n /**\n * Returns the distance from this GeoPoint to another in radians.\n * @param {AV.GeoPoint} point the other AV.GeoPoint.\n * @return {Number}\n */\n radiansTo: function radiansTo(point) {\n var d2r = Math.PI / 180.0;\n var lat1rad = this.latitude * d2r;\n var long1rad = this.longitude * d2r;\n var lat2rad = point.latitude * d2r;\n var long2rad = point.longitude * d2r;\n var deltaLat = lat1rad - lat2rad;\n var deltaLong = long1rad - long2rad;\n var sinDeltaLatDiv2 = Math.sin(deltaLat / 2);\n var sinDeltaLongDiv2 = Math.sin(deltaLong / 2); // Square of half the straight line chord distance between both points.\n\n var a = sinDeltaLatDiv2 * sinDeltaLatDiv2 + Math.cos(lat1rad) * Math.cos(lat2rad) * sinDeltaLongDiv2 * sinDeltaLongDiv2;\n a = Math.min(1.0, a);\n return 2 * Math.asin(Math.sqrt(a));\n },\n\n /**\n * Returns the distance from this GeoPoint to another in kilometers.\n * @param {AV.GeoPoint} point the other AV.GeoPoint.\n * @return {Number}\n */\n kilometersTo: function kilometersTo(point) {\n return this.radiansTo(point) * 6371.0;\n },\n\n /**\n * Returns the distance from this GeoPoint to another in miles.\n * @param {AV.GeoPoint} point the other AV.GeoPoint.\n * @return {Number}\n */\n milesTo: function milesTo(point) {\n return this.radiansTo(point) * 3958.8;\n }\n });\n};\n\n/***/ }),\n/* 438 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\n\nvar _ = __webpack_require__(1);\n\nmodule.exports = function (AV) {\n var PUBLIC_KEY = '*';\n /**\n * Creates a new ACL.\n * If no argument is given, the ACL has no permissions for anyone.\n * If the argument is a AV.User, the ACL will have read and write\n * permission for only that user.\n * If the argument is any other JSON object, that object will be interpretted\n * as a serialized ACL created with toJSON().\n * @see AV.Object#setACL\n * @class\n *\n *
An ACL, or Access Control List can be added to any\n * AV.Object to restrict access to only a subset of users\n * of your application.
\n */\n\n AV.ACL = function (arg1) {\n var self = this;\n self.permissionsById = {};\n\n if (_.isObject(arg1)) {\n if (arg1 instanceof AV.User) {\n self.setReadAccess(arg1, true);\n self.setWriteAccess(arg1, true);\n } else {\n if (_.isFunction(arg1)) {\n throw new Error('AV.ACL() called with a function. Did you forget ()?');\n }\n\n AV._objectEach(arg1, function (accessList, userId) {\n if (!_.isString(userId)) {\n throw new Error('Tried to create an ACL with an invalid userId.');\n }\n\n self.permissionsById[userId] = {};\n\n AV._objectEach(accessList, function (allowed, permission) {\n if (permission !== 'read' && permission !== 'write') {\n throw new Error('Tried to create an ACL with an invalid permission type.');\n }\n\n if (!_.isBoolean(allowed)) {\n throw new Error('Tried to create an ACL with an invalid permission value.');\n }\n\n self.permissionsById[userId][permission] = allowed;\n });\n });\n }\n }\n };\n /**\n * Returns a JSON-encoded version of the ACL.\n * @return {Object}\n */\n\n\n AV.ACL.prototype.toJSON = function () {\n return _.clone(this.permissionsById);\n };\n\n AV.ACL.prototype._setAccess = function (accessType, userId, allowed) {\n if (userId instanceof AV.User) {\n userId = userId.id;\n } else if (userId instanceof AV.Role) {\n userId = 'role:' + userId.getName();\n }\n\n if (!_.isString(userId)) {\n throw new Error('userId must be a string.');\n }\n\n if (!_.isBoolean(allowed)) {\n throw new Error('allowed must be either true or false.');\n }\n\n var permissions = this.permissionsById[userId];\n\n if (!permissions) {\n if (!allowed) {\n // The user already doesn't have this permission, so no action needed.\n return;\n } else {\n permissions = {};\n this.permissionsById[userId] = permissions;\n }\n }\n\n if (allowed) {\n this.permissionsById[userId][accessType] = true;\n } else {\n delete permissions[accessType];\n\n if (_.isEmpty(permissions)) {\n delete this.permissionsById[userId];\n }\n }\n };\n\n AV.ACL.prototype._getAccess = function (accessType, userId) {\n if (userId instanceof AV.User) {\n userId = userId.id;\n } else if (userId instanceof AV.Role) {\n userId = 'role:' + userId.getName();\n }\n\n var permissions = this.permissionsById[userId];\n\n if (!permissions) {\n return false;\n }\n\n return permissions[accessType] ? true : false;\n };\n /**\n * Set whether the given user is allowed to read this object.\n * @param userId An instance of AV.User or its objectId.\n * @param {Boolean} allowed Whether that user should have read access.\n */\n\n\n AV.ACL.prototype.setReadAccess = function (userId, allowed) {\n this._setAccess('read', userId, allowed);\n };\n /**\n * Get whether the given user id is *explicitly* allowed to read this object.\n * Even if this returns false, the user may still be able to access it if\n * getPublicReadAccess returns true or a role that the user belongs to has\n * write access.\n * @param userId An instance of AV.User or its objectId, or a AV.Role.\n * @return {Boolean}\n */\n\n\n AV.ACL.prototype.getReadAccess = function (userId) {\n return this._getAccess('read', userId);\n };\n /**\n * Set whether the given user id is allowed to write this object.\n * @param userId An instance of AV.User or its objectId, or a AV.Role..\n * @param {Boolean} allowed Whether that user should have write access.\n */\n\n\n AV.ACL.prototype.setWriteAccess = function (userId, allowed) {\n this._setAccess('write', userId, allowed);\n };\n /**\n * Get whether the given user id is *explicitly* allowed to write this object.\n * Even if this returns false, the user may still be able to write it if\n * getPublicWriteAccess returns true or a role that the user belongs to has\n * write access.\n * @param userId An instance of AV.User or its objectId, or a AV.Role.\n * @return {Boolean}\n */\n\n\n AV.ACL.prototype.getWriteAccess = function (userId) {\n return this._getAccess('write', userId);\n };\n /**\n * Set whether the public is allowed to read this object.\n * @param {Boolean} allowed\n */\n\n\n AV.ACL.prototype.setPublicReadAccess = function (allowed) {\n this.setReadAccess(PUBLIC_KEY, allowed);\n };\n /**\n * Get whether the public is allowed to read this object.\n * @return {Boolean}\n */\n\n\n AV.ACL.prototype.getPublicReadAccess = function () {\n return this.getReadAccess(PUBLIC_KEY);\n };\n /**\n * Set whether the public is allowed to write this object.\n * @param {Boolean} allowed\n */\n\n\n AV.ACL.prototype.setPublicWriteAccess = function (allowed) {\n this.setWriteAccess(PUBLIC_KEY, allowed);\n };\n /**\n * Get whether the public is allowed to write this object.\n * @return {Boolean}\n */\n\n\n AV.ACL.prototype.getPublicWriteAccess = function () {\n return this.getWriteAccess(PUBLIC_KEY);\n };\n /**\n * Get whether users belonging to the given role are allowed\n * to read this object. Even if this returns false, the role may\n * still be able to write it if a parent role has read access.\n *\n * @param role The name of the role, or a AV.Role object.\n * @return {Boolean} true if the role has read access. false otherwise.\n * @throws {String} If role is neither a AV.Role nor a String.\n */\n\n\n AV.ACL.prototype.getRoleReadAccess = function (role) {\n if (role instanceof AV.Role) {\n // Normalize to the String name\n role = role.getName();\n }\n\n if (_.isString(role)) {\n return this.getReadAccess('role:' + role);\n }\n\n throw new Error('role must be a AV.Role or a String');\n };\n /**\n * Get whether users belonging to the given role are allowed\n * to write this object. Even if this returns false, the role may\n * still be able to write it if a parent role has write access.\n *\n * @param role The name of the role, or a AV.Role object.\n * @return {Boolean} true if the role has write access. false otherwise.\n * @throws {String} If role is neither a AV.Role nor a String.\n */\n\n\n AV.ACL.prototype.getRoleWriteAccess = function (role) {\n if (role instanceof AV.Role) {\n // Normalize to the String name\n role = role.getName();\n }\n\n if (_.isString(role)) {\n return this.getWriteAccess('role:' + role);\n }\n\n throw new Error('role must be a AV.Role or a String');\n };\n /**\n * Set whether users belonging to the given role are allowed\n * to read this object.\n *\n * @param role The name of the role, or a AV.Role object.\n * @param {Boolean} allowed Whether the given role can read this object.\n * @throws {String} If role is neither a AV.Role nor a String.\n */\n\n\n AV.ACL.prototype.setRoleReadAccess = function (role, allowed) {\n if (role instanceof AV.Role) {\n // Normalize to the String name\n role = role.getName();\n }\n\n if (_.isString(role)) {\n this.setReadAccess('role:' + role, allowed);\n return;\n }\n\n throw new Error('role must be a AV.Role or a String');\n };\n /**\n * Set whether users belonging to the given role are allowed\n * to write this object.\n *\n * @param role The name of the role, or a AV.Role object.\n * @param {Boolean} allowed Whether the given role can write this object.\n * @throws {String} If role is neither a AV.Role nor a String.\n */\n\n\n AV.ACL.prototype.setRoleWriteAccess = function (role, allowed) {\n if (role instanceof AV.Role) {\n // Normalize to the String name\n role = role.getName();\n }\n\n if (_.isString(role)) {\n this.setWriteAccess('role:' + role, allowed);\n return;\n }\n\n throw new Error('role must be a AV.Role or a String');\n };\n};\n\n/***/ }),\n/* 439 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\n\nvar _interopRequireDefault = __webpack_require__(2);\n\nvar _concat = _interopRequireDefault(__webpack_require__(29));\n\nvar _find = _interopRequireDefault(__webpack_require__(104));\n\nvar _indexOf = _interopRequireDefault(__webpack_require__(102));\n\nvar _map = _interopRequireDefault(__webpack_require__(39));\n\nvar _ = __webpack_require__(1);\n\nmodule.exports = function (AV) {\n /**\n * @private\n * @class\n * A AV.Op is an atomic operation that can be applied to a field in a\n * AV.Object. For example, calling object.set(\"foo\", \"bar\")\n * is an example of a AV.Op.Set. Calling object.unset(\"foo\")\n * is a AV.Op.Unset. These operations are stored in a AV.Object and\n * sent to the server as part of object.save() operations.\n * Instances of AV.Op should be immutable.\n *\n * You should not create subclasses of AV.Op or instantiate AV.Op\n * directly.\n */\n AV.Op = function () {\n this._initialize.apply(this, arguments);\n };\n\n _.extend(AV.Op.prototype,\n /** @lends AV.Op.prototype */\n {\n _initialize: function _initialize() {}\n });\n\n _.extend(AV.Op, {\n /**\n * To create a new Op, call AV.Op._extend();\n * @private\n */\n _extend: AV._extend,\n // A map of __op string to decoder function.\n _opDecoderMap: {},\n\n /**\n * Registers a function to convert a json object with an __op field into an\n * instance of a subclass of AV.Op.\n * @private\n */\n _registerDecoder: function _registerDecoder(opName, decoder) {\n AV.Op._opDecoderMap[opName] = decoder;\n },\n\n /**\n * Converts a json object into an instance of a subclass of AV.Op.\n * @private\n */\n _decode: function _decode(json) {\n var decoder = AV.Op._opDecoderMap[json.__op];\n\n if (decoder) {\n return decoder(json);\n } else {\n return undefined;\n }\n }\n });\n /*\n * Add a handler for Batch ops.\n */\n\n\n AV.Op._registerDecoder('Batch', function (json) {\n var op = null;\n\n AV._arrayEach(json.ops, function (nextOp) {\n nextOp = AV.Op._decode(nextOp);\n op = nextOp._mergeWithPrevious(op);\n });\n\n return op;\n });\n /**\n * @private\n * @class\n * A Set operation indicates that either the field was changed using\n * AV.Object.set, or it is a mutable container that was detected as being\n * changed.\n */\n\n\n AV.Op.Set = AV.Op._extend(\n /** @lends AV.Op.Set.prototype */\n {\n _initialize: function _initialize(value) {\n this._value = value;\n },\n\n /**\n * Returns the new value of this field after the set.\n */\n value: function value() {\n return this._value;\n },\n\n /**\n * Returns a JSON version of the operation suitable for sending to AV.\n * @return {Object}\n */\n toJSON: function toJSON() {\n return AV._encode(this.value());\n },\n _mergeWithPrevious: function _mergeWithPrevious(previous) {\n return this;\n },\n _estimate: function _estimate(oldValue) {\n return this.value();\n }\n });\n /**\n * A sentinel value that is returned by AV.Op.Unset._estimate to\n * indicate the field should be deleted. Basically, if you find _UNSET as a\n * value in your object, you should remove that key.\n */\n\n AV.Op._UNSET = {};\n /**\n * @private\n * @class\n * An Unset operation indicates that this field has been deleted from the\n * object.\n */\n\n AV.Op.Unset = AV.Op._extend(\n /** @lends AV.Op.Unset.prototype */\n {\n /**\n * Returns a JSON version of the operation suitable for sending to AV.\n * @return {Object}\n */\n toJSON: function toJSON() {\n return {\n __op: 'Delete'\n };\n },\n _mergeWithPrevious: function _mergeWithPrevious(previous) {\n return this;\n },\n _estimate: function _estimate(oldValue) {\n return AV.Op._UNSET;\n }\n });\n\n AV.Op._registerDecoder('Delete', function (json) {\n return new AV.Op.Unset();\n });\n /**\n * @private\n * @class\n * An Increment is an atomic operation where the numeric value for the field\n * will be increased by a given amount.\n */\n\n\n AV.Op.Increment = AV.Op._extend(\n /** @lends AV.Op.Increment.prototype */\n {\n _initialize: function _initialize(amount) {\n this._amount = amount;\n },\n\n /**\n * Returns the amount to increment by.\n * @return {Number} the amount to increment by.\n */\n amount: function amount() {\n return this._amount;\n },\n\n /**\n * Returns a JSON version of the operation suitable for sending to AV.\n * @return {Object}\n */\n toJSON: function toJSON() {\n return {\n __op: 'Increment',\n amount: this._amount\n };\n },\n _mergeWithPrevious: function _mergeWithPrevious(previous) {\n if (!previous) {\n return this;\n } else if (previous instanceof AV.Op.Unset) {\n return new AV.Op.Set(this.amount());\n } else if (previous instanceof AV.Op.Set) {\n return new AV.Op.Set(previous.value() + this.amount());\n } else if (previous instanceof AV.Op.Increment) {\n return new AV.Op.Increment(this.amount() + previous.amount());\n } else {\n throw new Error('Op is invalid after previous op.');\n }\n },\n _estimate: function _estimate(oldValue) {\n if (!oldValue) {\n return this.amount();\n }\n\n return oldValue + this.amount();\n }\n });\n\n AV.Op._registerDecoder('Increment', function (json) {\n return new AV.Op.Increment(json.amount);\n });\n /**\n * @private\n * @class\n * BitAnd is an atomic operation where the given value will be bit and to the\n * value than is stored in this field.\n */\n\n\n AV.Op.BitAnd = AV.Op._extend(\n /** @lends AV.Op.BitAnd.prototype */\n {\n _initialize: function _initialize(value) {\n this._value = value;\n },\n value: function value() {\n return this._value;\n },\n\n /**\n * Returns a JSON version of the operation suitable for sending to AV.\n * @return {Object}\n */\n toJSON: function toJSON() {\n return {\n __op: 'BitAnd',\n value: this.value()\n };\n },\n _mergeWithPrevious: function _mergeWithPrevious(previous) {\n if (!previous) {\n return this;\n } else if (previous instanceof AV.Op.Unset) {\n return new AV.Op.Set(0);\n } else if (previous instanceof AV.Op.Set) {\n return new AV.Op.Set(previous.value() & this.value());\n } else {\n throw new Error('Op is invalid after previous op.');\n }\n },\n _estimate: function _estimate(oldValue) {\n return oldValue & this.value();\n }\n });\n\n AV.Op._registerDecoder('BitAnd', function (json) {\n return new AV.Op.BitAnd(json.value);\n });\n /**\n * @private\n * @class\n * BitOr is an atomic operation where the given value will be bit and to the\n * value than is stored in this field.\n */\n\n\n AV.Op.BitOr = AV.Op._extend(\n /** @lends AV.Op.BitOr.prototype */\n {\n _initialize: function _initialize(value) {\n this._value = value;\n },\n value: function value() {\n return this._value;\n },\n\n /**\n * Returns a JSON version of the operation suitable for sending to AV.\n * @return {Object}\n */\n toJSON: function toJSON() {\n return {\n __op: 'BitOr',\n value: this.value()\n };\n },\n _mergeWithPrevious: function _mergeWithPrevious(previous) {\n if (!previous) {\n return this;\n } else if (previous instanceof AV.Op.Unset) {\n return new AV.Op.Set(this.value());\n } else if (previous instanceof AV.Op.Set) {\n return new AV.Op.Set(previous.value() | this.value());\n } else {\n throw new Error('Op is invalid after previous op.');\n }\n },\n _estimate: function _estimate(oldValue) {\n return oldValue | this.value();\n }\n });\n\n AV.Op._registerDecoder('BitOr', function (json) {\n return new AV.Op.BitOr(json.value);\n });\n /**\n * @private\n * @class\n * BitXor is an atomic operation where the given value will be bit and to the\n * value than is stored in this field.\n */\n\n\n AV.Op.BitXor = AV.Op._extend(\n /** @lends AV.Op.BitXor.prototype */\n {\n _initialize: function _initialize(value) {\n this._value = value;\n },\n value: function value() {\n return this._value;\n },\n\n /**\n * Returns a JSON version of the operation suitable for sending to AV.\n * @return {Object}\n */\n toJSON: function toJSON() {\n return {\n __op: 'BitXor',\n value: this.value()\n };\n },\n _mergeWithPrevious: function _mergeWithPrevious(previous) {\n if (!previous) {\n return this;\n } else if (previous instanceof AV.Op.Unset) {\n return new AV.Op.Set(this.value());\n } else if (previous instanceof AV.Op.Set) {\n return new AV.Op.Set(previous.value() ^ this.value());\n } else {\n throw new Error('Op is invalid after previous op.');\n }\n },\n _estimate: function _estimate(oldValue) {\n return oldValue ^ this.value();\n }\n });\n\n AV.Op._registerDecoder('BitXor', function (json) {\n return new AV.Op.BitXor(json.value);\n });\n /**\n * @private\n * @class\n * Add is an atomic operation where the given objects will be appended to the\n * array that is stored in this field.\n */\n\n\n AV.Op.Add = AV.Op._extend(\n /** @lends AV.Op.Add.prototype */\n {\n _initialize: function _initialize(objects) {\n this._objects = objects;\n },\n\n /**\n * Returns the objects to be added to the array.\n * @return {Array} The objects to be added to the array.\n */\n objects: function objects() {\n return this._objects;\n },\n\n /**\n * Returns a JSON version of the operation suitable for sending to AV.\n * @return {Object}\n */\n toJSON: function toJSON() {\n return {\n __op: 'Add',\n objects: AV._encode(this.objects())\n };\n },\n _mergeWithPrevious: function _mergeWithPrevious(previous) {\n if (!previous) {\n return this;\n } else if (previous instanceof AV.Op.Unset) {\n return new AV.Op.Set(this.objects());\n } else if (previous instanceof AV.Op.Set) {\n return new AV.Op.Set(this._estimate(previous.value()));\n } else if (previous instanceof AV.Op.Add) {\n var _context;\n\n return new AV.Op.Add((0, _concat.default)(_context = previous.objects()).call(_context, this.objects()));\n } else {\n throw new Error('Op is invalid after previous op.');\n }\n },\n _estimate: function _estimate(oldValue) {\n if (!oldValue) {\n return _.clone(this.objects());\n } else {\n return (0, _concat.default)(oldValue).call(oldValue, this.objects());\n }\n }\n });\n\n AV.Op._registerDecoder('Add', function (json) {\n return new AV.Op.Add(AV._decode(json.objects));\n });\n /**\n * @private\n * @class\n * AddUnique is an atomic operation where the given items will be appended to\n * the array that is stored in this field only if they were not already\n * present in the array.\n */\n\n\n AV.Op.AddUnique = AV.Op._extend(\n /** @lends AV.Op.AddUnique.prototype */\n {\n _initialize: function _initialize(objects) {\n this._objects = _.uniq(objects);\n },\n\n /**\n * Returns the objects to be added to the array.\n * @return {Array} The objects to be added to the array.\n */\n objects: function objects() {\n return this._objects;\n },\n\n /**\n * Returns a JSON version of the operation suitable for sending to AV.\n * @return {Object}\n */\n toJSON: function toJSON() {\n return {\n __op: 'AddUnique',\n objects: AV._encode(this.objects())\n };\n },\n _mergeWithPrevious: function _mergeWithPrevious(previous) {\n if (!previous) {\n return this;\n } else if (previous instanceof AV.Op.Unset) {\n return new AV.Op.Set(this.objects());\n } else if (previous instanceof AV.Op.Set) {\n return new AV.Op.Set(this._estimate(previous.value()));\n } else if (previous instanceof AV.Op.AddUnique) {\n return new AV.Op.AddUnique(this._estimate(previous.objects()));\n } else {\n throw new Error('Op is invalid after previous op.');\n }\n },\n _estimate: function _estimate(oldValue) {\n if (!oldValue) {\n return _.clone(this.objects());\n } else {\n // We can't just take the _.uniq(_.union(...)) of oldValue and\n // this.objects, because the uniqueness may not apply to oldValue\n // (especially if the oldValue was set via .set())\n var newValue = _.clone(oldValue);\n\n AV._arrayEach(this.objects(), function (obj) {\n if (obj instanceof AV.Object && obj.id) {\n var matchingObj = (0, _find.default)(_).call(_, newValue, function (anObj) {\n return anObj instanceof AV.Object && anObj.id === obj.id;\n });\n\n if (!matchingObj) {\n newValue.push(obj);\n } else {\n var index = (0, _indexOf.default)(_).call(_, newValue, matchingObj);\n newValue[index] = obj;\n }\n } else if (!_.contains(newValue, obj)) {\n newValue.push(obj);\n }\n });\n\n return newValue;\n }\n }\n });\n\n AV.Op._registerDecoder('AddUnique', function (json) {\n return new AV.Op.AddUnique(AV._decode(json.objects));\n });\n /**\n * @private\n * @class\n * Remove is an atomic operation where the given objects will be removed from\n * the array that is stored in this field.\n */\n\n\n AV.Op.Remove = AV.Op._extend(\n /** @lends AV.Op.Remove.prototype */\n {\n _initialize: function _initialize(objects) {\n this._objects = _.uniq(objects);\n },\n\n /**\n * Returns the objects to be removed from the array.\n * @return {Array} The objects to be removed from the array.\n */\n objects: function objects() {\n return this._objects;\n },\n\n /**\n * Returns a JSON version of the operation suitable for sending to AV.\n * @return {Object}\n */\n toJSON: function toJSON() {\n return {\n __op: 'Remove',\n objects: AV._encode(this.objects())\n };\n },\n _mergeWithPrevious: function _mergeWithPrevious(previous) {\n if (!previous) {\n return this;\n } else if (previous instanceof AV.Op.Unset) {\n return previous;\n } else if (previous instanceof AV.Op.Set) {\n return new AV.Op.Set(this._estimate(previous.value()));\n } else if (previous instanceof AV.Op.Remove) {\n return new AV.Op.Remove(_.union(previous.objects(), this.objects()));\n } else {\n throw new Error('Op is invalid after previous op.');\n }\n },\n _estimate: function _estimate(oldValue) {\n if (!oldValue) {\n return [];\n } else {\n var newValue = _.difference(oldValue, this.objects()); // If there are saved AV Objects being removed, also remove them.\n\n\n AV._arrayEach(this.objects(), function (obj) {\n if (obj instanceof AV.Object && obj.id) {\n newValue = _.reject(newValue, function (other) {\n return other instanceof AV.Object && other.id === obj.id;\n });\n }\n });\n\n return newValue;\n }\n }\n });\n\n AV.Op._registerDecoder('Remove', function (json) {\n return new AV.Op.Remove(AV._decode(json.objects));\n });\n /**\n * @private\n * @class\n * A Relation operation indicates that the field is an instance of\n * AV.Relation, and objects are being added to, or removed from, that\n * relation.\n */\n\n\n AV.Op.Relation = AV.Op._extend(\n /** @lends AV.Op.Relation.prototype */\n {\n _initialize: function _initialize(adds, removes) {\n this._targetClassName = null;\n var self = this;\n\n var pointerToId = function pointerToId(object) {\n if (object instanceof AV.Object) {\n if (!object.id) {\n throw new Error(\"You can't add an unsaved AV.Object to a relation.\");\n }\n\n if (!self._targetClassName) {\n self._targetClassName = object.className;\n }\n\n if (self._targetClassName !== object.className) {\n throw new Error('Tried to create a AV.Relation with 2 different types: ' + self._targetClassName + ' and ' + object.className + '.');\n }\n\n return object.id;\n }\n\n return object;\n };\n\n this.relationsToAdd = _.uniq((0, _map.default)(_).call(_, adds, pointerToId));\n this.relationsToRemove = _.uniq((0, _map.default)(_).call(_, removes, pointerToId));\n },\n\n /**\n * Returns an array of unfetched AV.Object that are being added to the\n * relation.\n * @return {Array}\n */\n added: function added() {\n var self = this;\n return (0, _map.default)(_).call(_, this.relationsToAdd, function (objectId) {\n var object = AV.Object._create(self._targetClassName);\n\n object.id = objectId;\n return object;\n });\n },\n\n /**\n * Returns an array of unfetched AV.Object that are being removed from\n * the relation.\n * @return {Array}\n */\n removed: function removed() {\n var self = this;\n return (0, _map.default)(_).call(_, this.relationsToRemove, function (objectId) {\n var object = AV.Object._create(self._targetClassName);\n\n object.id = objectId;\n return object;\n });\n },\n\n /**\n * Returns a JSON version of the operation suitable for sending to AV.\n * @return {Object}\n */\n toJSON: function toJSON() {\n var adds = null;\n var removes = null;\n var self = this;\n\n var idToPointer = function idToPointer(id) {\n return {\n __type: 'Pointer',\n className: self._targetClassName,\n objectId: id\n };\n };\n\n var pointers = null;\n\n if (this.relationsToAdd.length > 0) {\n pointers = (0, _map.default)(_).call(_, this.relationsToAdd, idToPointer);\n adds = {\n __op: 'AddRelation',\n objects: pointers\n };\n }\n\n if (this.relationsToRemove.length > 0) {\n pointers = (0, _map.default)(_).call(_, this.relationsToRemove, idToPointer);\n removes = {\n __op: 'RemoveRelation',\n objects: pointers\n };\n }\n\n if (adds && removes) {\n return {\n __op: 'Batch',\n ops: [adds, removes]\n };\n }\n\n return adds || removes || {};\n },\n _mergeWithPrevious: function _mergeWithPrevious(previous) {\n if (!previous) {\n return this;\n } else if (previous instanceof AV.Op.Unset) {\n throw new Error(\"You can't modify a relation after deleting it.\");\n } else if (previous instanceof AV.Op.Relation) {\n if (previous._targetClassName && previous._targetClassName !== this._targetClassName) {\n throw new Error('Related object must be of class ' + previous._targetClassName + ', but ' + this._targetClassName + ' was passed in.');\n }\n\n var newAdd = _.union(_.difference(previous.relationsToAdd, this.relationsToRemove), this.relationsToAdd);\n\n var newRemove = _.union(_.difference(previous.relationsToRemove, this.relationsToAdd), this.relationsToRemove);\n\n var newRelation = new AV.Op.Relation(newAdd, newRemove);\n newRelation._targetClassName = this._targetClassName;\n return newRelation;\n } else {\n throw new Error('Op is invalid after previous op.');\n }\n },\n _estimate: function _estimate(oldValue, object, key) {\n if (!oldValue) {\n var relation = new AV.Relation(object, key);\n relation.targetClassName = this._targetClassName;\n } else if (oldValue instanceof AV.Relation) {\n if (this._targetClassName) {\n if (oldValue.targetClassName) {\n if (oldValue.targetClassName !== this._targetClassName) {\n throw new Error('Related object must be a ' + oldValue.targetClassName + ', but a ' + this._targetClassName + ' was passed in.');\n }\n } else {\n oldValue.targetClassName = this._targetClassName;\n }\n }\n\n return oldValue;\n } else {\n throw new Error('Op is invalid after previous op.');\n }\n }\n });\n\n AV.Op._registerDecoder('AddRelation', function (json) {\n return new AV.Op.Relation(AV._decode(json.objects), []);\n });\n\n AV.Op._registerDecoder('RemoveRelation', function (json) {\n return new AV.Op.Relation([], AV._decode(json.objects));\n });\n};\n\n/***/ }),\n/* 440 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar parent = __webpack_require__(441);\n\nmodule.exports = parent;\n\n\n/***/ }),\n/* 441 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar isPrototypeOf = __webpack_require__(20);\nvar method = __webpack_require__(442);\n\nvar ArrayPrototype = Array.prototype;\n\nmodule.exports = function (it) {\n var own = it.find;\n return it === ArrayPrototype || (isPrototypeOf(ArrayPrototype, it) && own === ArrayPrototype.find) ? method : own;\n};\n\n\n/***/ }),\n/* 442 */\n/***/ (function(module, exports, __webpack_require__) {\n\n__webpack_require__(443);\nvar entryVirtual = __webpack_require__(38);\n\nmodule.exports = entryVirtual('Array').find;\n\n\n/***/ }),\n/* 443 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\nvar $ = __webpack_require__(0);\nvar $find = __webpack_require__(101).find;\nvar addToUnscopables = __webpack_require__(152);\n\nvar FIND = 'find';\nvar SKIPS_HOLES = true;\n\n// Shouldn't skip holes\nif (FIND in []) Array(1)[FIND](function () { SKIPS_HOLES = false; });\n\n// `Array.prototype.find` method\n// https://tc39.es/ecma262/#sec-array.prototype.find\n$({ target: 'Array', proto: true, forced: SKIPS_HOLES }, {\n find: function find(callbackfn /* , that = undefined */) {\n return $find(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);\n }\n});\n\n// https://tc39.es/ecma262/#sec-array.prototype-@@unscopables\naddToUnscopables(FIND);\n\n\n/***/ }),\n/* 444 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\n\nvar _ = __webpack_require__(1);\n\nmodule.exports = function (AV) {\n /**\n * Creates a new Relation for the given parent object and key. This\n * constructor should rarely be used directly, but rather created by\n * {@link AV.Object#relation}.\n * @param {AV.Object} parent The parent of this relation.\n * @param {String} key The key for this relation on the parent.\n * @see AV.Object#relation\n * @class\n *\n *
\n * A class that is used to access all of the children of a many-to-many\n * relationship. Each instance of AV.Relation is associated with a\n * particular parent object and key.\n *
\n */\n AV.Relation = function (parent, key) {\n if (!_.isString(key)) {\n throw new TypeError('key must be a string');\n }\n\n this.parent = parent;\n this.key = key;\n this.targetClassName = null;\n };\n /**\n * Creates a query that can be used to query the parent objects in this relation.\n * @param {String} parentClass The parent class or name.\n * @param {String} relationKey The relation field key in parent.\n * @param {AV.Object} child The child object.\n * @return {AV.Query}\n */\n\n\n AV.Relation.reverseQuery = function (parentClass, relationKey, child) {\n var query = new AV.Query(parentClass);\n query.equalTo(relationKey, child._toPointer());\n return query;\n };\n\n _.extend(AV.Relation.prototype,\n /** @lends AV.Relation.prototype */\n {\n /**\n * Makes sure that this relation has the right parent and key.\n * @private\n */\n _ensureParentAndKey: function _ensureParentAndKey(parent, key) {\n this.parent = this.parent || parent;\n this.key = this.key || key;\n\n if (this.parent !== parent) {\n throw new Error('Internal Error. Relation retrieved from two different Objects.');\n }\n\n if (this.key !== key) {\n throw new Error('Internal Error. Relation retrieved from two different keys.');\n }\n },\n\n /**\n * Adds a AV.Object or an array of AV.Objects to the relation.\n * @param {AV.Object|AV.Object[]} objects The item or items to add.\n */\n add: function add(objects) {\n if (!_.isArray(objects)) {\n objects = [objects];\n }\n\n var change = new AV.Op.Relation(objects, []);\n this.parent.set(this.key, change);\n this.targetClassName = change._targetClassName;\n },\n\n /**\n * Removes a AV.Object or an array of AV.Objects from this relation.\n * @param {AV.Object|AV.Object[]} objects The item or items to remove.\n */\n remove: function remove(objects) {\n if (!_.isArray(objects)) {\n objects = [objects];\n }\n\n var change = new AV.Op.Relation([], objects);\n this.parent.set(this.key, change);\n this.targetClassName = change._targetClassName;\n },\n\n /**\n * Returns a JSON version of the object suitable for saving to disk.\n * @return {Object}\n */\n toJSON: function toJSON() {\n return {\n __type: 'Relation',\n className: this.targetClassName\n };\n },\n\n /**\n * Returns a AV.Query that is limited to objects in this\n * relation.\n * @return {AV.Query}\n */\n query: function query() {\n var targetClass;\n var query;\n\n if (!this.targetClassName) {\n targetClass = AV.Object._getSubclass(this.parent.className);\n query = new AV.Query(targetClass);\n query._defaultParams.redirectClassNameForKey = this.key;\n } else {\n targetClass = AV.Object._getSubclass(this.targetClassName);\n query = new AV.Query(targetClass);\n }\n\n query._addCondition('$relatedTo', 'object', this.parent._toPointer());\n\n query._addCondition('$relatedTo', 'key', this.key);\n\n return query;\n }\n });\n};\n\n/***/ }),\n/* 445 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\n\nvar _interopRequireDefault = __webpack_require__(2);\n\nvar _promise = _interopRequireDefault(__webpack_require__(10));\n\nvar _ = __webpack_require__(1);\n\nvar cos = __webpack_require__(446);\n\nvar qiniu = __webpack_require__(447);\n\nvar s3 = __webpack_require__(495);\n\nvar AVError = __webpack_require__(40);\n\nvar _require = __webpack_require__(25),\n request = _require.request,\n AVRequest = _require._request;\n\nvar _require2 = __webpack_require__(28),\n tap = _require2.tap,\n transformFetchOptions = _require2.transformFetchOptions;\n\nvar debug = __webpack_require__(60)('leancloud:file');\n\nvar parseBase64 = __webpack_require__(499);\n\nmodule.exports = function (AV) {\n // port from browserify path module\n // since react-native packager won't shim node modules.\n var extname = function extname(path) {\n if (!_.isString(path)) return '';\n return path.match(/^(\\/?|)([\\s\\S]*?)((?:\\.{1,2}|[^\\/]+?|)(\\.[^.\\/]*|))(?:[\\/]*)$/)[4];\n };\n\n var b64Digit = function b64Digit(number) {\n if (number < 26) {\n return String.fromCharCode(65 + number);\n }\n\n if (number < 52) {\n return String.fromCharCode(97 + (number - 26));\n }\n\n if (number < 62) {\n return String.fromCharCode(48 + (number - 52));\n }\n\n if (number === 62) {\n return '+';\n }\n\n if (number === 63) {\n return '/';\n }\n\n throw new Error('Tried to encode large digit ' + number + ' in base64.');\n };\n\n var encodeBase64 = function encodeBase64(array) {\n var chunks = [];\n chunks.length = Math.ceil(array.length / 3);\n\n _.times(chunks.length, function (i) {\n var b1 = array[i * 3];\n var b2 = array[i * 3 + 1] || 0;\n var b3 = array[i * 3 + 2] || 0;\n var has2 = i * 3 + 1 < array.length;\n var has3 = i * 3 + 2 < array.length;\n chunks[i] = [b64Digit(b1 >> 2 & 0x3f), b64Digit(b1 << 4 & 0x30 | b2 >> 4 & 0x0f), has2 ? b64Digit(b2 << 2 & 0x3c | b3 >> 6 & 0x03) : '=', has3 ? b64Digit(b3 & 0x3f) : '='].join('');\n });\n\n return chunks.join('');\n };\n /**\n * An AV.File is a local representation of a file that is saved to the AV\n * cloud.\n * @param name {String} The file's name. This will change to a unique value\n * once the file has finished saving.\n * @param data {Array} The data for the file, as either:\n * 1. an Array of byte value Numbers, or\n * 2. an Object like { base64: \"...\" } with a base64-encoded String.\n * 3. a Blob(File) selected with a file upload control in a browser.\n * 4. an Object like { blob: {uri: \"...\"} } that mimics Blob\n * in some non-browser environments such as React Native.\n * 5. a Buffer in Node.js runtime.\n * 6. a Stream in Node.js runtime.\n *\n * For example:
\n * var fileUploadControl = $(\"#profilePhotoFileUpload\")[0];\n * if (fileUploadControl.files.length > 0) {\n * var file = fileUploadControl.files[0];\n * var name = \"photo.jpg\";\n * var file = new AV.File(name, file);\n * file.save().then(function() {\n * // The file has been saved to AV.\n * }, function(error) {\n * // The file either could not be read, or could not be saved to AV.\n * });\n * }
\n *\n * @class\n * @param [mimeType] {String} Content-Type header to use for the file. If\n * this is omitted, the content type will be inferred from the name's\n * extension.\n */\n\n\n AV.File = function (name, data, mimeType) {\n this.attributes = {\n name: name,\n url: '',\n metaData: {},\n // 用来存储转换后要上传的 base64 String\n base64: ''\n };\n\n if (_.isString(data)) {\n throw new TypeError('Creating an AV.File from a String is not yet supported.');\n }\n\n if (_.isArray(data)) {\n this.attributes.metaData.size = data.length;\n data = {\n base64: encodeBase64(data)\n };\n }\n\n this._extName = '';\n this._data = data;\n this._uploadHeaders = {};\n\n if (data && data.blob && typeof data.blob.uri === 'string') {\n this._extName = extname(data.blob.uri);\n }\n\n if (typeof Blob !== 'undefined' && data instanceof Blob) {\n if (data.size) {\n this.attributes.metaData.size = data.size;\n }\n\n if (data.name) {\n this._extName = extname(data.name);\n }\n }\n\n var owner;\n\n if (data && data.owner) {\n owner = data.owner;\n } else if (!AV._config.disableCurrentUser) {\n try {\n owner = AV.User.current();\n } catch (error) {\n if ('SYNC_API_NOT_AVAILABLE' !== error.code) {\n throw error;\n }\n }\n }\n\n this.attributes.metaData.owner = owner ? owner.id : 'unknown';\n this.set('mime_type', mimeType);\n };\n /**\n * Creates a fresh AV.File object with exists url for saving to AVOS Cloud.\n * @param {String} name the file name\n * @param {String} url the file url.\n * @param {Object} [metaData] the file metadata object.\n * @param {String} [type] Content-Type header to use for the file. If\n * this is omitted, the content type will be inferred from the name's\n * extension.\n * @return {AV.File} the file object\n */\n\n\n AV.File.withURL = function (name, url, metaData, type) {\n if (!name || !url) {\n throw new Error('Please provide file name and url');\n }\n\n var file = new AV.File(name, null, type); //copy metaData properties to file.\n\n if (metaData) {\n for (var prop in metaData) {\n if (!file.attributes.metaData[prop]) file.attributes.metaData[prop] = metaData[prop];\n }\n }\n\n file.attributes.url = url; //Mark the file is from external source.\n\n file.attributes.metaData.__source = 'external';\n file.attributes.metaData.size = 0;\n return file;\n };\n /**\n * Creates a file object with exists objectId.\n * @param {String} objectId The objectId string\n * @return {AV.File} the file object\n */\n\n\n AV.File.createWithoutData = function (objectId) {\n if (!objectId) {\n throw new TypeError('The objectId must be provided');\n }\n\n var file = new AV.File();\n file.id = objectId;\n return file;\n };\n /**\n * Request file censor.\n * @since 4.13.0\n * @param {String} objectId\n * @return {Promise.}\n */\n\n\n AV.File.censor = function (objectId) {\n if (!AV._config.masterKey) {\n throw new Error('Cannot censor a file without masterKey');\n }\n\n return request({\n method: 'POST',\n path: \"/files/\".concat(objectId, \"/censor\"),\n authOptions: {\n useMasterKey: true\n }\n }).then(function (res) {\n return res.censorResult;\n });\n };\n\n _.extend(AV.File.prototype,\n /** @lends AV.File.prototype */\n {\n className: '_File',\n _toFullJSON: function _toFullJSON(seenObjects) {\n var _this = this;\n\n var full = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;\n\n var json = _.clone(this.attributes);\n\n AV._objectEach(json, function (val, key) {\n json[key] = AV._encode(val, seenObjects, undefined, full);\n });\n\n AV._objectEach(this._operations, function (val, key) {\n json[key] = val;\n });\n\n if (_.has(this, 'id')) {\n json.objectId = this.id;\n }\n\n ['createdAt', 'updatedAt'].forEach(function (key) {\n if (_.has(_this, key)) {\n var val = _this[key];\n json[key] = _.isDate(val) ? val.toJSON() : val;\n }\n });\n\n if (full) {\n json.__type = 'File';\n }\n\n return json;\n },\n\n /**\n * Returns a JSON version of the file with meta data.\n * Inverse to {@link AV.parseJSON}\n * @since 3.0.0\n * @return {Object}\n */\n toFullJSON: function toFullJSON() {\n var seenObjects = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];\n return this._toFullJSON(seenObjects);\n },\n\n /**\n * Returns a JSON version of the object.\n * @return {Object}\n */\n toJSON: function toJSON(key, holder) {\n var seenObjects = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [this];\n return this._toFullJSON(seenObjects, false);\n },\n\n /**\n * Gets a Pointer referencing this file.\n * @private\n */\n _toPointer: function _toPointer() {\n return {\n __type: 'Pointer',\n className: this.className,\n objectId: this.id\n };\n },\n\n /**\n * Returns the ACL for this file.\n * @returns {AV.ACL} An instance of AV.ACL.\n */\n getACL: function getACL() {\n return this._acl;\n },\n\n /**\n * Sets the ACL to be used for this file.\n * @param {AV.ACL} acl An instance of AV.ACL.\n */\n setACL: function setACL(acl) {\n if (!(acl instanceof AV.ACL)) {\n return new AVError(AVError.OTHER_CAUSE, 'ACL must be a AV.ACL.');\n }\n\n this._acl = acl;\n return this;\n },\n\n /**\n * Gets the name of the file. Before save is called, this is the filename\n * given by the user. After save is called, that name gets prefixed with a\n * unique identifier.\n */\n name: function name() {\n return this.get('name');\n },\n\n /**\n * Gets the url of the file. It is only available after you save the file or\n * after you get the file from a AV.Object.\n * @return {String}\n */\n url: function url() {\n return this.get('url');\n },\n\n /**\n * Gets the attributs of the file object.\n * @param {String} The attribute name which want to get.\n * @returns {Any}\n */\n get: function get(attrName) {\n switch (attrName) {\n case 'objectId':\n return this.id;\n\n case 'url':\n case 'name':\n case 'mime_type':\n case 'metaData':\n case 'createdAt':\n case 'updatedAt':\n return this.attributes[attrName];\n\n default:\n return this.attributes.metaData[attrName];\n }\n },\n\n /**\n * Set the metaData of the file object.\n * @param {Object} Object is an key value Object for setting metaData.\n * @param {String} attr is an optional metadata key.\n * @param {Object} value is an optional metadata value.\n * @returns {String|Number|Array|Object}\n */\n set: function set() {\n var _this2 = this;\n\n var set = function set(attrName, value) {\n switch (attrName) {\n case 'name':\n case 'url':\n case 'mime_type':\n case 'base64':\n case 'metaData':\n _this2.attributes[attrName] = value;\n break;\n\n default:\n // File 并非一个 AVObject,不能完全自定义其他属性,所以只能都放在 metaData 上面\n _this2.attributes.metaData[attrName] = value;\n break;\n }\n };\n\n for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {\n args[_key] = arguments[_key];\n }\n\n switch (args.length) {\n case 1:\n // 传入一个 Object\n for (var k in args[0]) {\n set(k, args[0][k]);\n }\n\n break;\n\n case 2:\n set(args[0], args[1]);\n break;\n }\n\n return this;\n },\n\n /**\n * Set a header for the upload request.\n * For more infomation, go to https://url.leanapp.cn/avfile-upload-headers\n *\n * @param {String} key header key\n * @param {String} value header value\n * @return {AV.File} this\n */\n setUploadHeader: function setUploadHeader(key, value) {\n this._uploadHeaders[key] = value;\n return this;\n },\n\n /**\n *
Returns the file's metadata JSON object if no arguments is given.Returns the\n * metadata value if a key is given.Set metadata value if key and value are both given.
\n *
\n * var metadata = file.metaData(); //Get metadata JSON object.\n * var size = file.metaData('size'); // Get the size metadata value.\n * file.metaData('format', 'jpeg'); //set metadata attribute and value.\n *
\n * @return {Object} The file's metadata JSON object.\n * @param {String} attr an optional metadata key.\n * @param {Object} value an optional metadata value.\n **/\n metaData: function metaData(attr, value) {\n if (attr && value) {\n this.attributes.metaData[attr] = value;\n return this;\n } else if (attr && !value) {\n return this.attributes.metaData[attr];\n } else {\n return this.attributes.metaData;\n }\n },\n\n /**\n * 如果文件是图片,获取图片的缩略图URL。可以传入宽度、高度、质量、格式等参数。\n * @return {String} 缩略图URL\n * @param {Number} width 宽度,单位:像素\n * @param {Number} heigth 高度,单位:像素\n * @param {Number} quality 质量,1-100的数字,默认100\n * @param {Number} scaleToFit 是否将图片自适应大小。默认为true。\n * @param {String} fmt 格式,默认为png,也可以为jpeg,gif等格式。\n */\n thumbnailURL: function thumbnailURL(width, height) {\n var quality = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 100;\n var scaleToFit = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;\n var fmt = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 'png';\n var url = this.attributes.url;\n\n if (!url) {\n throw new Error('Invalid url.');\n }\n\n if (!width || !height || width <= 0 || height <= 0) {\n throw new Error('Invalid width or height value.');\n }\n\n if (quality <= 0 || quality > 100) {\n throw new Error('Invalid quality value.');\n }\n\n var mode = scaleToFit ? 2 : 1;\n return url + '?imageView/' + mode + '/w/' + width + '/h/' + height + '/q/' + quality + '/format/' + fmt;\n },\n\n /**\n * Returns the file's size.\n * @return {Number} The file's size in bytes.\n **/\n size: function size() {\n return this.metaData().size;\n },\n\n /**\n * Returns the file's owner.\n * @return {String} The file's owner id.\n */\n ownerId: function ownerId() {\n return this.metaData().owner;\n },\n\n /**\n * Destroy the file.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled when the destroy\n * completes.\n */\n destroy: function destroy(options) {\n if (!this.id) {\n return _promise.default.reject(new Error('The file id does not eixst.'));\n }\n\n var request = AVRequest('files', null, this.id, 'DELETE', null, options);\n return request;\n },\n\n /**\n * Request Qiniu upload token\n * @param {string} type\n * @return {Promise} Resolved with the response\n * @private\n */\n _fileToken: function _fileToken(type, authOptions) {\n var name = this.attributes.name;\n var extName = extname(name);\n\n if (!extName && this._extName) {\n name += this._extName;\n extName = this._extName;\n }\n\n var data = {\n name: name,\n keep_file_name: authOptions.keepFileName,\n key: authOptions.key,\n ACL: this._acl,\n mime_type: type,\n metaData: this.attributes.metaData\n };\n return AVRequest('fileTokens', null, null, 'POST', data, authOptions);\n },\n\n /**\n * @callback UploadProgressCallback\n * @param {XMLHttpRequestProgressEvent} event - The progress event with 'loaded' and 'total' attributes\n */\n\n /**\n * Saves the file to the AV cloud.\n * @param {AuthOptions} [options] AuthOptions plus:\n * @param {UploadProgressCallback} [options.onprogress] 文件上传进度,在 Node.js 中无效,回调参数说明详见 {@link UploadProgressCallback}。\n * @param {boolean} [options.keepFileName = false] 保留下载文件的文件名。\n * @param {string} [options.key] 指定文件的 key。设置该选项需要使用 masterKey\n * @return {Promise} Promise that is resolved when the save finishes.\n */\n save: function save() {\n var _this3 = this;\n\n var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n\n if (this.id) {\n throw new Error('File is already saved.');\n }\n\n if (!this._previousSave) {\n if (this._data) {\n var mimeType = this.get('mime_type');\n this._previousSave = this._fileToken(mimeType, options).then(function (uploadInfo) {\n if (uploadInfo.mime_type) {\n mimeType = uploadInfo.mime_type;\n\n _this3.set('mime_type', mimeType);\n }\n\n _this3._token = uploadInfo.token;\n return _promise.default.resolve().then(function () {\n var data = _this3._data;\n\n if (data && data.base64) {\n return parseBase64(data.base64, mimeType);\n }\n\n if (data && data.blob) {\n if (!data.blob.type && mimeType) {\n data.blob.type = mimeType;\n }\n\n if (!data.blob.name) {\n data.blob.name = _this3.get('name');\n }\n\n return data.blob;\n }\n\n if (typeof Blob !== 'undefined' && data instanceof Blob) {\n return data;\n }\n\n throw new TypeError('malformed file data');\n }).then(function (data) {\n var _options = _.extend({}, options); // filter out download progress events\n\n\n if (options.onprogress) {\n _options.onprogress = function (event) {\n if (event.direction === 'download') return;\n return options.onprogress(event);\n };\n }\n\n switch (uploadInfo.provider) {\n case 's3':\n return s3(uploadInfo, data, _this3, _options);\n\n case 'qcloud':\n return cos(uploadInfo, data, _this3, _options);\n\n case 'qiniu':\n default:\n return qiniu(uploadInfo, data, _this3, _options);\n }\n }).then(tap(function () {\n return _this3._callback(true);\n }), function (error) {\n _this3._callback(false);\n\n throw error;\n });\n });\n } else if (this.attributes.url && this.attributes.metaData.__source === 'external') {\n // external link file.\n var data = {\n name: this.attributes.name,\n ACL: this._acl,\n metaData: this.attributes.metaData,\n mime_type: this.mimeType,\n url: this.attributes.url\n };\n this._previousSave = AVRequest('files', null, null, 'post', data, options).then(function (response) {\n _this3.id = response.objectId;\n return _this3;\n });\n }\n }\n\n return this._previousSave;\n },\n _callback: function _callback(success) {\n AVRequest('fileCallback', null, null, 'post', {\n token: this._token,\n result: success\n }).catch(debug);\n delete this._token;\n delete this._data;\n },\n\n /**\n * fetch the file from server. If the server's representation of the\n * model differs from its current attributes, they will be overriden,\n * @param {Object} fetchOptions Optional options to set 'keys',\n * 'include' and 'includeACL' option.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled when the fetch\n * completes.\n */\n fetch: function fetch(fetchOptions, options) {\n if (!this.id) {\n throw new Error('Cannot fetch unsaved file');\n }\n\n var request = AVRequest('files', null, this.id, 'GET', transformFetchOptions(fetchOptions), options);\n return request.then(this._finishFetch.bind(this));\n },\n _finishFetch: function _finishFetch(response) {\n var value = AV.Object.prototype.parse(response);\n value.attributes = {\n name: value.name,\n url: value.url,\n mime_type: value.mime_type,\n bucket: value.bucket\n };\n value.attributes.metaData = value.metaData || {};\n value.id = value.objectId; // clean\n\n delete value.objectId;\n delete value.metaData;\n delete value.url;\n delete value.name;\n delete value.mime_type;\n delete value.bucket;\n\n _.extend(this, value);\n\n return this;\n },\n\n /**\n * Request file censor\n * @since 4.13.0\n * @return {Promise.}\n */\n censor: function censor() {\n if (!this.id) {\n throw new Error('Cannot censor an unsaved file');\n }\n\n return AV.File.censor(this.id);\n }\n });\n};\n\n/***/ }),\n/* 446 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\n\nvar _require = __webpack_require__(61),\n getAdapter = _require.getAdapter;\n\nvar debug = __webpack_require__(60)('cos');\n\nmodule.exports = function (uploadInfo, data, file) {\n var saveOptions = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};\n var url = uploadInfo.upload_url + '?sign=' + encodeURIComponent(uploadInfo.token);\n var fileFormData = {\n field: 'fileContent',\n data: data,\n name: file.attributes.name\n };\n var options = {\n headers: file._uploadHeaders,\n data: {\n op: 'upload'\n },\n onprogress: saveOptions.onprogress\n };\n debug('url: %s, file: %o, options: %o', url, fileFormData, options);\n var upload = getAdapter('upload');\n return upload(url, fileFormData, options).then(function (response) {\n debug(response.status, response.data);\n\n if (response.ok === false) {\n var error = new Error(response.status);\n error.response = response;\n throw error;\n }\n\n file.attributes.url = uploadInfo.url;\n file._bucket = uploadInfo.bucket;\n file.id = uploadInfo.objectId;\n return file;\n }, function (error) {\n var response = error.response;\n\n if (response) {\n debug(response.status, response.data);\n error.statusCode = response.status;\n error.response = response.data;\n }\n\n throw error;\n });\n};\n\n/***/ }),\n/* 447 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\n\nvar _sliceInstanceProperty2 = __webpack_require__(81);\n\nvar _Array$from = __webpack_require__(448);\n\nvar _Symbol = __webpack_require__(453);\n\nvar _getIteratorMethod = __webpack_require__(231);\n\nvar _Reflect$construct = __webpack_require__(459);\n\nvar _interopRequireDefault = __webpack_require__(2);\n\nvar _inherits2 = _interopRequireDefault(__webpack_require__(463));\n\nvar _possibleConstructorReturn2 = _interopRequireDefault(__webpack_require__(485));\n\nvar _getPrototypeOf2 = _interopRequireDefault(__webpack_require__(487));\n\nvar _classCallCheck2 = _interopRequireDefault(__webpack_require__(492));\n\nvar _createClass2 = _interopRequireDefault(__webpack_require__(493));\n\nvar _stringify = _interopRequireDefault(__webpack_require__(34));\n\nvar _concat = _interopRequireDefault(__webpack_require__(29));\n\nvar _promise = _interopRequireDefault(__webpack_require__(10));\n\nvar _slice = _interopRequireDefault(__webpack_require__(81));\n\nfunction _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = _Reflect$construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }\n\nfunction _isNativeReflectConstruct() { if (typeof Reflect === \"undefined\" || !_Reflect$construct) return false; if (_Reflect$construct.sham) return false; if (typeof Proxy === \"function\") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }\n\nfunction _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof _Symbol !== \"undefined\" && _getIteratorMethod(o) || o[\"@@iterator\"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === \"number\") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError(\"Invalid attempt to iterate non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\"); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }\n\nfunction _unsupportedIterableToArray(o, minLen) { var _context8; if (!o) return; if (typeof o === \"string\") return _arrayLikeToArray(o, minLen); var n = _sliceInstanceProperty2(_context8 = Object.prototype.toString.call(o)).call(_context8, 8, -1); if (n === \"Object\" && o.constructor) n = o.constructor.name; if (n === \"Map\" || n === \"Set\") return _Array$from(o); if (n === \"Arguments\" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }\n\nfunction _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }\n\nvar _require = __webpack_require__(61),\n getAdapter = _require.getAdapter;\n\nvar debug = __webpack_require__(60)('leancloud:qiniu');\n\nvar ajax = __webpack_require__(103);\n\nvar btoa = __webpack_require__(494);\n\nvar SHARD_THRESHOLD = 1024 * 1024 * 64;\nvar CHUNK_SIZE = 1024 * 1024 * 16;\n\nfunction upload(uploadInfo, data, file) {\n var saveOptions = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};\n // Get the uptoken to upload files to qiniu.\n var uptoken = uploadInfo.token;\n var url = uploadInfo.upload_url || 'https://upload.qiniup.com';\n var fileFormData = {\n field: 'file',\n data: data,\n name: file.attributes.name\n };\n var options = {\n headers: file._uploadHeaders,\n data: {\n name: file.attributes.name,\n key: uploadInfo.key,\n token: uptoken\n },\n onprogress: saveOptions.onprogress\n };\n debug('url: %s, file: %o, options: %o', url, fileFormData, options);\n var upload = getAdapter('upload');\n return upload(url, fileFormData, options).then(function (response) {\n debug(response.status, response.data);\n\n if (response.ok === false) {\n var message = response.status;\n\n if (response.data) {\n if (response.data.error) {\n message = response.data.error;\n } else {\n message = (0, _stringify.default)(response.data);\n }\n }\n\n var error = new Error(message);\n error.response = response;\n throw error;\n }\n\n file.attributes.url = uploadInfo.url;\n file._bucket = uploadInfo.bucket;\n file.id = uploadInfo.objectId;\n return file;\n }, function (error) {\n var response = error.response;\n\n if (response) {\n debug(response.status, response.data);\n error.statusCode = response.status;\n error.response = response.data;\n }\n\n throw error;\n });\n}\n\nfunction urlSafeBase64(string) {\n var base64 = btoa(unescape(encodeURIComponent(string)));\n var result = '';\n\n var _iterator = _createForOfIteratorHelper(base64),\n _step;\n\n try {\n for (_iterator.s(); !(_step = _iterator.n()).done;) {\n var ch = _step.value;\n\n switch (ch) {\n case '+':\n result += '-';\n break;\n\n case '/':\n result += '_';\n break;\n\n default:\n result += ch;\n }\n }\n } catch (err) {\n _iterator.e(err);\n } finally {\n _iterator.f();\n }\n\n return result;\n}\n\nvar ShardUploader = /*#__PURE__*/function () {\n function ShardUploader(uploadInfo, data, file, saveOptions) {\n var _context,\n _context2,\n _this = this;\n\n (0, _classCallCheck2.default)(this, ShardUploader);\n this.uploadInfo = uploadInfo;\n this.data = data;\n this.file = file;\n this.size = undefined;\n this.offset = 0;\n this.uploadedChunks = 0;\n var key = urlSafeBase64(uploadInfo.key);\n var uploadURL = uploadInfo.upload_url || 'https://upload.qiniup.com';\n this.baseURL = (0, _concat.default)(_context = (0, _concat.default)(_context2 = \"\".concat(uploadURL, \"/buckets/\")).call(_context2, uploadInfo.bucket, \"/objects/\")).call(_context, key, \"/uploads\");\n this.upToken = 'UpToken ' + uploadInfo.token;\n this.uploaded = 0;\n\n if (saveOptions && saveOptions.onprogress) {\n this.onProgress = function (_ref) {\n var loaded = _ref.loaded;\n loaded += _this.uploadedChunks * CHUNK_SIZE;\n\n if (loaded <= _this.uploaded) {\n return;\n }\n\n if (_this.size) {\n saveOptions.onprogress({\n loaded: loaded,\n total: _this.size,\n percent: loaded / _this.size * 100\n });\n } else {\n saveOptions.onprogress({\n loaded: loaded\n });\n }\n\n _this.uploaded = loaded;\n };\n }\n }\n /**\n * @returns {Promise}\n */\n\n\n (0, _createClass2.default)(ShardUploader, [{\n key: \"getUploadId\",\n value: function getUploadId() {\n return ajax({\n method: 'POST',\n url: this.baseURL,\n headers: {\n Authorization: this.upToken\n }\n }).then(function (res) {\n return res.uploadId;\n });\n }\n }, {\n key: \"getChunk\",\n value: function getChunk() {\n throw new Error('Not implemented');\n }\n /**\n * @param {string} uploadId\n * @param {number} partNumber\n * @param {any} data\n * @returns {Promise<{ partNumber: number, etag: string }>}\n */\n\n }, {\n key: \"uploadPart\",\n value: function uploadPart(uploadId, partNumber, data) {\n var _context3, _context4;\n\n return ajax({\n method: 'PUT',\n url: (0, _concat.default)(_context3 = (0, _concat.default)(_context4 = \"\".concat(this.baseURL, \"/\")).call(_context4, uploadId, \"/\")).call(_context3, partNumber),\n headers: {\n Authorization: this.upToken\n },\n data: data,\n onprogress: this.onProgress\n }).then(function (_ref2) {\n var etag = _ref2.etag;\n return {\n partNumber: partNumber,\n etag: etag\n };\n });\n }\n }, {\n key: \"stopUpload\",\n value: function stopUpload(uploadId) {\n var _context5;\n\n return ajax({\n method: 'DELETE',\n url: (0, _concat.default)(_context5 = \"\".concat(this.baseURL, \"/\")).call(_context5, uploadId),\n headers: {\n Authorization: this.upToken\n }\n });\n }\n }, {\n key: \"upload\",\n value: function upload() {\n var _this2 = this;\n\n var parts = [];\n return this.getUploadId().then(function (uploadId) {\n var uploadPart = function uploadPart() {\n return _promise.default.resolve(_this2.getChunk()).then(function (chunk) {\n if (!chunk) {\n return;\n }\n\n var partNumber = parts.length + 1;\n return _this2.uploadPart(uploadId, partNumber, chunk).then(function (part) {\n parts.push(part);\n _this2.uploadedChunks++;\n return uploadPart();\n });\n }).catch(function (error) {\n return _this2.stopUpload(uploadId).then(function () {\n return _promise.default.reject(error);\n });\n });\n };\n\n return uploadPart().then(function () {\n var _context6;\n\n return ajax({\n method: 'POST',\n url: (0, _concat.default)(_context6 = \"\".concat(_this2.baseURL, \"/\")).call(_context6, uploadId),\n headers: {\n Authorization: _this2.upToken\n },\n data: {\n parts: parts,\n fname: _this2.file.attributes.name,\n mimeType: _this2.file.attributes.mime_type\n }\n });\n });\n }).then(function () {\n _this2.file.attributes.url = _this2.uploadInfo.url;\n _this2.file._bucket = _this2.uploadInfo.bucket;\n _this2.file.id = _this2.uploadInfo.objectId;\n return _this2.file;\n });\n }\n }]);\n return ShardUploader;\n}();\n\nvar BlobUploader = /*#__PURE__*/function (_ShardUploader) {\n (0, _inherits2.default)(BlobUploader, _ShardUploader);\n\n var _super = _createSuper(BlobUploader);\n\n function BlobUploader(uploadInfo, data, file, saveOptions) {\n var _this3;\n\n (0, _classCallCheck2.default)(this, BlobUploader);\n _this3 = _super.call(this, uploadInfo, data, file, saveOptions);\n _this3.size = data.size;\n return _this3;\n }\n /**\n * @returns {Blob | null}\n */\n\n\n (0, _createClass2.default)(BlobUploader, [{\n key: \"getChunk\",\n value: function getChunk() {\n var _context7;\n\n if (this.offset >= this.size) {\n return null;\n }\n\n var chunk = (0, _slice.default)(_context7 = this.data).call(_context7, this.offset, this.offset + CHUNK_SIZE);\n this.offset += chunk.size;\n return chunk;\n }\n }]);\n return BlobUploader;\n}(ShardUploader);\n\nfunction isBlob(data) {\n return typeof Blob !== 'undefined' && data instanceof Blob;\n}\n\nmodule.exports = function (uploadInfo, data, file) {\n var saveOptions = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};\n\n if (isBlob(data) && data.size >= SHARD_THRESHOLD) {\n return new BlobUploader(uploadInfo, data, file, saveOptions).upload();\n }\n\n return upload(uploadInfo, data, file, saveOptions);\n};\n\n/***/ }),\n/* 448 */\n/***/ (function(module, exports, __webpack_require__) {\n\nmodule.exports = __webpack_require__(230);\n\n/***/ }),\n/* 449 */\n/***/ (function(module, exports, __webpack_require__) {\n\n__webpack_require__(95);\n__webpack_require__(450);\nvar path = __webpack_require__(13);\n\nmodule.exports = path.Array.from;\n\n\n/***/ }),\n/* 450 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar $ = __webpack_require__(0);\nvar from = __webpack_require__(451);\nvar checkCorrectnessOfIteration = __webpack_require__(160);\n\nvar INCORRECT_ITERATION = !checkCorrectnessOfIteration(function (iterable) {\n // eslint-disable-next-line es-x/no-array-from -- required for testing\n Array.from(iterable);\n});\n\n// `Array.from` method\n// https://tc39.es/ecma262/#sec-array.from\n$({ target: 'Array', stat: true, forced: INCORRECT_ITERATION }, {\n from: from\n});\n\n\n/***/ }),\n/* 451 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\nvar bind = __webpack_require__(50);\nvar call = __webpack_require__(11);\nvar toObject = __webpack_require__(35);\nvar callWithSafeIterationClosing = __webpack_require__(452);\nvar isArrayIteratorMethod = __webpack_require__(149);\nvar isConstructor = __webpack_require__(93);\nvar lengthOfArrayLike = __webpack_require__(42);\nvar createProperty = __webpack_require__(99);\nvar getIterator = __webpack_require__(150);\nvar getIteratorMethod = __webpack_require__(90);\n\nvar $Array = Array;\n\n// `Array.from` method implementation\n// https://tc39.es/ecma262/#sec-array.from\nmodule.exports = function from(arrayLike /* , mapfn = undefined, thisArg = undefined */) {\n var O = toObject(arrayLike);\n var IS_CONSTRUCTOR = isConstructor(this);\n var argumentsLength = arguments.length;\n var mapfn = argumentsLength > 1 ? arguments[1] : undefined;\n var mapping = mapfn !== undefined;\n if (mapping) mapfn = bind(mapfn, argumentsLength > 2 ? arguments[2] : undefined);\n var iteratorMethod = getIteratorMethod(O);\n var index = 0;\n var length, result, step, iterator, next, value;\n // if the target is not iterable or it's an array with the default iterator - use a simple case\n if (iteratorMethod && !(this === $Array && isArrayIteratorMethod(iteratorMethod))) {\n iterator = getIterator(O, iteratorMethod);\n next = iterator.next;\n result = IS_CONSTRUCTOR ? new this() : [];\n for (;!(step = call(next, iterator)).done; index++) {\n value = mapping ? callWithSafeIterationClosing(iterator, mapfn, [step.value, index], true) : step.value;\n createProperty(result, index, value);\n }\n } else {\n length = lengthOfArrayLike(O);\n result = IS_CONSTRUCTOR ? new this(length) : $Array(length);\n for (;length > index; index++) {\n value = mapping ? mapfn(O[index], index) : O[index];\n createProperty(result, index, value);\n }\n }\n result.length = index;\n return result;\n};\n\n\n/***/ }),\n/* 452 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar anObject = __webpack_require__(21);\nvar iteratorClose = __webpack_require__(151);\n\n// call something on iterator step with safe closing on error\nmodule.exports = function (iterator, fn, value, ENTRIES) {\n try {\n return ENTRIES ? fn(anObject(value)[0], value[1]) : fn(value);\n } catch (error) {\n iteratorClose(iterator, 'throw', error);\n }\n};\n\n\n/***/ }),\n/* 453 */\n/***/ (function(module, exports, __webpack_require__) {\n\nmodule.exports = __webpack_require__(226);\n\n/***/ }),\n/* 454 */\n/***/ (function(module, exports, __webpack_require__) {\n\nmodule.exports = __webpack_require__(455);\n\n\n/***/ }),\n/* 455 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar parent = __webpack_require__(456);\n\nmodule.exports = parent;\n\n\n/***/ }),\n/* 456 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar parent = __webpack_require__(457);\n\nmodule.exports = parent;\n\n\n/***/ }),\n/* 457 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar parent = __webpack_require__(458);\n__webpack_require__(73);\n\nmodule.exports = parent;\n\n\n/***/ }),\n/* 458 */\n/***/ (function(module, exports, __webpack_require__) {\n\n__webpack_require__(70);\n__webpack_require__(95);\nvar getIteratorMethod = __webpack_require__(90);\n\nmodule.exports = getIteratorMethod;\n\n\n/***/ }),\n/* 459 */\n/***/ (function(module, exports, __webpack_require__) {\n\nmodule.exports = __webpack_require__(460);\n\n/***/ }),\n/* 460 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar parent = __webpack_require__(461);\n\nmodule.exports = parent;\n\n\n/***/ }),\n/* 461 */\n/***/ (function(module, exports, __webpack_require__) {\n\n__webpack_require__(462);\nvar path = __webpack_require__(13);\n\nmodule.exports = path.Reflect.construct;\n\n\n/***/ }),\n/* 462 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar $ = __webpack_require__(0);\nvar getBuiltIn = __webpack_require__(16);\nvar apply = __webpack_require__(62);\nvar bind = __webpack_require__(232);\nvar aConstructor = __webpack_require__(156);\nvar anObject = __webpack_require__(21);\nvar isObject = __webpack_require__(17);\nvar create = __webpack_require__(51);\nvar fails = __webpack_require__(4);\n\nvar nativeConstruct = getBuiltIn('Reflect', 'construct');\nvar ObjectPrototype = Object.prototype;\nvar push = [].push;\n\n// `Reflect.construct` method\n// https://tc39.es/ecma262/#sec-reflect.construct\n// MS Edge supports only 2 arguments and argumentsList argument is optional\n// FF Nightly sets third argument as `new.target`, but does not create `this` from it\nvar NEW_TARGET_BUG = fails(function () {\n function F() { /* empty */ }\n return !(nativeConstruct(function () { /* empty */ }, [], F) instanceof F);\n});\n\nvar ARGS_BUG = !fails(function () {\n nativeConstruct(function () { /* empty */ });\n});\n\nvar FORCED = NEW_TARGET_BUG || ARGS_BUG;\n\n$({ target: 'Reflect', stat: true, forced: FORCED, sham: FORCED }, {\n construct: function construct(Target, args /* , newTarget */) {\n aConstructor(Target);\n anObject(args);\n var newTarget = arguments.length < 3 ? Target : aConstructor(arguments[2]);\n if (ARGS_BUG && !NEW_TARGET_BUG) return nativeConstruct(Target, args, newTarget);\n if (Target == newTarget) {\n // w/o altered newTarget, optimization for 0-4 arguments\n switch (args.length) {\n case 0: return new Target();\n case 1: return new Target(args[0]);\n case 2: return new Target(args[0], args[1]);\n case 3: return new Target(args[0], args[1], args[2]);\n case 4: return new Target(args[0], args[1], args[2], args[3]);\n }\n // w/o altered newTarget, lot of arguments case\n var $args = [null];\n apply(push, $args, args);\n return new (apply(bind, Target, $args))();\n }\n // with altered newTarget, not support built-in constructors\n var proto = newTarget.prototype;\n var instance = create(isObject(proto) ? proto : ObjectPrototype);\n var result = apply(Target, instance, args);\n return isObject(result) ? result : instance;\n }\n});\n\n\n/***/ }),\n/* 463 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar _Object$create = __webpack_require__(464);\n\nvar _Object$defineProperty = __webpack_require__(137);\n\nvar setPrototypeOf = __webpack_require__(474);\n\nfunction _inherits(subClass, superClass) {\n if (typeof superClass !== \"function\" && superClass !== null) {\n throw new TypeError(\"Super expression must either be null or a function\");\n }\n\n subClass.prototype = _Object$create(superClass && superClass.prototype, {\n constructor: {\n value: subClass,\n writable: true,\n configurable: true\n }\n });\n\n _Object$defineProperty(subClass, \"prototype\", {\n writable: false\n });\n\n if (superClass) setPrototypeOf(subClass, superClass);\n}\n\nmodule.exports = _inherits, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n/***/ }),\n/* 464 */\n/***/ (function(module, exports, __webpack_require__) {\n\nmodule.exports = __webpack_require__(465);\n\n/***/ }),\n/* 465 */\n/***/ (function(module, exports, __webpack_require__) {\n\nmodule.exports = __webpack_require__(466);\n\n\n/***/ }),\n/* 466 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar parent = __webpack_require__(467);\n\nmodule.exports = parent;\n\n\n/***/ }),\n/* 467 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar parent = __webpack_require__(468);\n\nmodule.exports = parent;\n\n\n/***/ }),\n/* 468 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar parent = __webpack_require__(469);\n\nmodule.exports = parent;\n\n\n/***/ }),\n/* 469 */\n/***/ (function(module, exports, __webpack_require__) {\n\n__webpack_require__(470);\nvar path = __webpack_require__(13);\n\nvar Object = path.Object;\n\nmodule.exports = function create(P, D) {\n return Object.create(P, D);\n};\n\n\n/***/ }),\n/* 470 */\n/***/ (function(module, exports, __webpack_require__) {\n\n// TODO: Remove from `core-js@4`\nvar $ = __webpack_require__(0);\nvar DESCRIPTORS = __webpack_require__(19);\nvar create = __webpack_require__(51);\n\n// `Object.create` method\n// https://tc39.es/ecma262/#sec-object.create\n$({ target: 'Object', stat: true, sham: !DESCRIPTORS }, {\n create: create\n});\n\n\n/***/ }),\n/* 471 */\n/***/ (function(module, exports, __webpack_require__) {\n\nmodule.exports = __webpack_require__(472);\n\n\n/***/ }),\n/* 472 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar parent = __webpack_require__(473);\n\nmodule.exports = parent;\n\n\n/***/ }),\n/* 473 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar parent = __webpack_require__(224);\n\nmodule.exports = parent;\n\n\n/***/ }),\n/* 474 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar _Object$setPrototypeOf = __webpack_require__(233);\n\nvar _bindInstanceProperty = __webpack_require__(234);\n\nfunction _setPrototypeOf(o, p) {\n var _context;\n\n module.exports = _setPrototypeOf = _Object$setPrototypeOf ? _bindInstanceProperty(_context = _Object$setPrototypeOf).call(_context) : function _setPrototypeOf(o, p) {\n o.__proto__ = p;\n return o;\n }, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n return _setPrototypeOf(o, p);\n}\n\nmodule.exports = _setPrototypeOf, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n/***/ }),\n/* 475 */\n/***/ (function(module, exports, __webpack_require__) {\n\nmodule.exports = __webpack_require__(476);\n\n\n/***/ }),\n/* 476 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar parent = __webpack_require__(477);\n\nmodule.exports = parent;\n\n\n/***/ }),\n/* 477 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar parent = __webpack_require__(221);\n\nmodule.exports = parent;\n\n\n/***/ }),\n/* 478 */\n/***/ (function(module, exports, __webpack_require__) {\n\nmodule.exports = __webpack_require__(479);\n\n\n/***/ }),\n/* 479 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar parent = __webpack_require__(480);\n\nmodule.exports = parent;\n\n\n/***/ }),\n/* 480 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar parent = __webpack_require__(481);\n\nmodule.exports = parent;\n\n\n/***/ }),\n/* 481 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar parent = __webpack_require__(482);\n\nmodule.exports = parent;\n\n\n/***/ }),\n/* 482 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar isPrototypeOf = __webpack_require__(20);\nvar method = __webpack_require__(483);\n\nvar FunctionPrototype = Function.prototype;\n\nmodule.exports = function (it) {\n var own = it.bind;\n return it === FunctionPrototype || (isPrototypeOf(FunctionPrototype, it) && own === FunctionPrototype.bind) ? method : own;\n};\n\n\n/***/ }),\n/* 483 */\n/***/ (function(module, exports, __webpack_require__) {\n\n__webpack_require__(484);\nvar entryVirtual = __webpack_require__(38);\n\nmodule.exports = entryVirtual('Function').bind;\n\n\n/***/ }),\n/* 484 */\n/***/ (function(module, exports, __webpack_require__) {\n\n// TODO: Remove from `core-js@4`\nvar $ = __webpack_require__(0);\nvar bind = __webpack_require__(232);\n\n// `Function.prototype.bind` method\n// https://tc39.es/ecma262/#sec-function.prototype.bind\n$({ target: 'Function', proto: true, forced: Function.bind !== bind }, {\n bind: bind\n});\n\n\n/***/ }),\n/* 485 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar _typeof = __webpack_require__(135)[\"default\"];\n\nvar assertThisInitialized = __webpack_require__(486);\n\nfunction _possibleConstructorReturn(self, call) {\n if (call && (_typeof(call) === \"object\" || typeof call === \"function\")) {\n return call;\n } else if (call !== void 0) {\n throw new TypeError(\"Derived constructors may only return object or undefined\");\n }\n\n return assertThisInitialized(self);\n}\n\nmodule.exports = _possibleConstructorReturn, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n/***/ }),\n/* 486 */\n/***/ (function(module, exports) {\n\nfunction _assertThisInitialized(self) {\n if (self === void 0) {\n throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\");\n }\n\n return self;\n}\n\nmodule.exports = _assertThisInitialized, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n/***/ }),\n/* 487 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar _Object$setPrototypeOf = __webpack_require__(233);\n\nvar _bindInstanceProperty = __webpack_require__(234);\n\nvar _Object$getPrototypeOf = __webpack_require__(488);\n\nfunction _getPrototypeOf(o) {\n var _context;\n\n module.exports = _getPrototypeOf = _Object$setPrototypeOf ? _bindInstanceProperty(_context = _Object$getPrototypeOf).call(_context) : function _getPrototypeOf(o) {\n return o.__proto__ || _Object$getPrototypeOf(o);\n }, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n return _getPrototypeOf(o);\n}\n\nmodule.exports = _getPrototypeOf, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n/***/ }),\n/* 488 */\n/***/ (function(module, exports, __webpack_require__) {\n\nmodule.exports = __webpack_require__(489);\n\n/***/ }),\n/* 489 */\n/***/ (function(module, exports, __webpack_require__) {\n\nmodule.exports = __webpack_require__(490);\n\n\n/***/ }),\n/* 490 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar parent = __webpack_require__(491);\n\nmodule.exports = parent;\n\n\n/***/ }),\n/* 491 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar parent = __webpack_require__(216);\n\nmodule.exports = parent;\n\n\n/***/ }),\n/* 492 */\n/***/ (function(module, exports) {\n\nfunction _classCallCheck(instance, Constructor) {\n if (!(instance instanceof Constructor)) {\n throw new TypeError(\"Cannot call a class as a function\");\n }\n}\n\nmodule.exports = _classCallCheck, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n/***/ }),\n/* 493 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar _Object$defineProperty = __webpack_require__(137);\n\nfunction _defineProperties(target, props) {\n for (var i = 0; i < props.length; i++) {\n var descriptor = props[i];\n descriptor.enumerable = descriptor.enumerable || false;\n descriptor.configurable = true;\n if (\"value\" in descriptor) descriptor.writable = true;\n\n _Object$defineProperty(target, descriptor.key, descriptor);\n }\n}\n\nfunction _createClass(Constructor, protoProps, staticProps) {\n if (protoProps) _defineProperties(Constructor.prototype, protoProps);\n if (staticProps) _defineProperties(Constructor, staticProps);\n\n _Object$defineProperty(Constructor, \"prototype\", {\n writable: false\n });\n\n return Constructor;\n}\n\nmodule.exports = _createClass, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n/***/ }),\n/* 494 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\n\nvar _interopRequireDefault = __webpack_require__(2);\n\nvar _slice = _interopRequireDefault(__webpack_require__(81));\n\n// base64 character set, plus padding character (=)\nvar b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';\n\nmodule.exports = function (string) {\n var result = '';\n\n for (var i = 0; i < string.length;) {\n var a = string.charCodeAt(i++);\n var b = string.charCodeAt(i++);\n var c = string.charCodeAt(i++);\n\n if (a > 255 || b > 255 || c > 255) {\n throw new TypeError('Failed to encode base64: The string to be encoded contains characters outside of the Latin1 range.');\n }\n\n var bitmap = a << 16 | b << 8 | c;\n result += b64.charAt(bitmap >> 18 & 63) + b64.charAt(bitmap >> 12 & 63) + b64.charAt(bitmap >> 6 & 63) + b64.charAt(bitmap & 63);\n } // To determine the final padding\n\n\n var rest = string.length % 3; // If there's need of padding, replace the last 'A's with equal signs\n\n return rest ? (0, _slice.default)(result).call(result, 0, rest - 3) + '==='.substring(rest) : result;\n};\n\n/***/ }),\n/* 495 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\n\nvar _ = __webpack_require__(1);\n\nvar ajax = __webpack_require__(103);\n\nmodule.exports = function upload(uploadInfo, data, file) {\n var saveOptions = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};\n return ajax({\n url: uploadInfo.upload_url,\n method: 'PUT',\n data: data,\n headers: _.extend({\n 'Content-Type': file.get('mime_type'),\n 'Cache-Control': 'public, max-age=31536000'\n }, file._uploadHeaders),\n onprogress: saveOptions.onprogress\n }).then(function () {\n file.attributes.url = uploadInfo.url;\n file._bucket = uploadInfo.bucket;\n file.id = uploadInfo.objectId;\n return file;\n });\n};\n\n/***/ }),\n/* 496 */\n/***/ (function(module, exports, __webpack_require__) {\n\n(function(){\r\n var crypt = __webpack_require__(497),\r\n utf8 = __webpack_require__(235).utf8,\r\n isBuffer = __webpack_require__(498),\r\n bin = __webpack_require__(235).bin,\r\n\r\n // The core\r\n md5 = function (message, options) {\r\n // Convert to byte array\r\n if (message.constructor == String)\r\n if (options && options.encoding === 'binary')\r\n message = bin.stringToBytes(message);\r\n else\r\n message = utf8.stringToBytes(message);\r\n else if (isBuffer(message))\r\n message = Array.prototype.slice.call(message, 0);\r\n else if (!Array.isArray(message))\r\n message = message.toString();\r\n // else, assume byte array already\r\n\r\n var m = crypt.bytesToWords(message),\r\n l = message.length * 8,\r\n a = 1732584193,\r\n b = -271733879,\r\n c = -1732584194,\r\n d = 271733878;\r\n\r\n // Swap endian\r\n for (var i = 0; i < m.length; i++) {\r\n m[i] = ((m[i] << 8) | (m[i] >>> 24)) & 0x00FF00FF |\r\n ((m[i] << 24) | (m[i] >>> 8)) & 0xFF00FF00;\r\n }\r\n\r\n // Padding\r\n m[l >>> 5] |= 0x80 << (l % 32);\r\n m[(((l + 64) >>> 9) << 4) + 14] = l;\r\n\r\n // Method shortcuts\r\n var FF = md5._ff,\r\n GG = md5._gg,\r\n HH = md5._hh,\r\n II = md5._ii;\r\n\r\n for (var i = 0; i < m.length; i += 16) {\r\n\r\n var aa = a,\r\n bb = b,\r\n cc = c,\r\n dd = d;\r\n\r\n a = FF(a, b, c, d, m[i+ 0], 7, -680876936);\r\n d = FF(d, a, b, c, m[i+ 1], 12, -389564586);\r\n c = FF(c, d, a, b, m[i+ 2], 17, 606105819);\r\n b = FF(b, c, d, a, m[i+ 3], 22, -1044525330);\r\n a = FF(a, b, c, d, m[i+ 4], 7, -176418897);\r\n d = FF(d, a, b, c, m[i+ 5], 12, 1200080426);\r\n c = FF(c, d, a, b, m[i+ 6], 17, -1473231341);\r\n b = FF(b, c, d, a, m[i+ 7], 22, -45705983);\r\n a = FF(a, b, c, d, m[i+ 8], 7, 1770035416);\r\n d = FF(d, a, b, c, m[i+ 9], 12, -1958414417);\r\n c = FF(c, d, a, b, m[i+10], 17, -42063);\r\n b = FF(b, c, d, a, m[i+11], 22, -1990404162);\r\n a = FF(a, b, c, d, m[i+12], 7, 1804603682);\r\n d = FF(d, a, b, c, m[i+13], 12, -40341101);\r\n c = FF(c, d, a, b, m[i+14], 17, -1502002290);\r\n b = FF(b, c, d, a, m[i+15], 22, 1236535329);\r\n\r\n a = GG(a, b, c, d, m[i+ 1], 5, -165796510);\r\n d = GG(d, a, b, c, m[i+ 6], 9, -1069501632);\r\n c = GG(c, d, a, b, m[i+11], 14, 643717713);\r\n b = GG(b, c, d, a, m[i+ 0], 20, -373897302);\r\n a = GG(a, b, c, d, m[i+ 5], 5, -701558691);\r\n d = GG(d, a, b, c, m[i+10], 9, 38016083);\r\n c = GG(c, d, a, b, m[i+15], 14, -660478335);\r\n b = GG(b, c, d, a, m[i+ 4], 20, -405537848);\r\n a = GG(a, b, c, d, m[i+ 9], 5, 568446438);\r\n d = GG(d, a, b, c, m[i+14], 9, -1019803690);\r\n c = GG(c, d, a, b, m[i+ 3], 14, -187363961);\r\n b = GG(b, c, d, a, m[i+ 8], 20, 1163531501);\r\n a = GG(a, b, c, d, m[i+13], 5, -1444681467);\r\n d = GG(d, a, b, c, m[i+ 2], 9, -51403784);\r\n c = GG(c, d, a, b, m[i+ 7], 14, 1735328473);\r\n b = GG(b, c, d, a, m[i+12], 20, -1926607734);\r\n\r\n a = HH(a, b, c, d, m[i+ 5], 4, -378558);\r\n d = HH(d, a, b, c, m[i+ 8], 11, -2022574463);\r\n c = HH(c, d, a, b, m[i+11], 16, 1839030562);\r\n b = HH(b, c, d, a, m[i+14], 23, -35309556);\r\n a = HH(a, b, c, d, m[i+ 1], 4, -1530992060);\r\n d = HH(d, a, b, c, m[i+ 4], 11, 1272893353);\r\n c = HH(c, d, a, b, m[i+ 7], 16, -155497632);\r\n b = HH(b, c, d, a, m[i+10], 23, -1094730640);\r\n a = HH(a, b, c, d, m[i+13], 4, 681279174);\r\n d = HH(d, a, b, c, m[i+ 0], 11, -358537222);\r\n c = HH(c, d, a, b, m[i+ 3], 16, -722521979);\r\n b = HH(b, c, d, a, m[i+ 6], 23, 76029189);\r\n a = HH(a, b, c, d, m[i+ 9], 4, -640364487);\r\n d = HH(d, a, b, c, m[i+12], 11, -421815835);\r\n c = HH(c, d, a, b, m[i+15], 16, 530742520);\r\n b = HH(b, c, d, a, m[i+ 2], 23, -995338651);\r\n\r\n a = II(a, b, c, d, m[i+ 0], 6, -198630844);\r\n d = II(d, a, b, c, m[i+ 7], 10, 1126891415);\r\n c = II(c, d, a, b, m[i+14], 15, -1416354905);\r\n b = II(b, c, d, a, m[i+ 5], 21, -57434055);\r\n a = II(a, b, c, d, m[i+12], 6, 1700485571);\r\n d = II(d, a, b, c, m[i+ 3], 10, -1894986606);\r\n c = II(c, d, a, b, m[i+10], 15, -1051523);\r\n b = II(b, c, d, a, m[i+ 1], 21, -2054922799);\r\n a = II(a, b, c, d, m[i+ 8], 6, 1873313359);\r\n d = II(d, a, b, c, m[i+15], 10, -30611744);\r\n c = II(c, d, a, b, m[i+ 6], 15, -1560198380);\r\n b = II(b, c, d, a, m[i+13], 21, 1309151649);\r\n a = II(a, b, c, d, m[i+ 4], 6, -145523070);\r\n d = II(d, a, b, c, m[i+11], 10, -1120210379);\r\n c = II(c, d, a, b, m[i+ 2], 15, 718787259);\r\n b = II(b, c, d, a, m[i+ 9], 21, -343485551);\r\n\r\n a = (a + aa) >>> 0;\r\n b = (b + bb) >>> 0;\r\n c = (c + cc) >>> 0;\r\n d = (d + dd) >>> 0;\r\n }\r\n\r\n return crypt.endian([a, b, c, d]);\r\n };\r\n\r\n // Auxiliary functions\r\n md5._ff = function (a, b, c, d, x, s, t) {\r\n var n = a + (b & c | ~b & d) + (x >>> 0) + t;\r\n return ((n << s) | (n >>> (32 - s))) + b;\r\n };\r\n md5._gg = function (a, b, c, d, x, s, t) {\r\n var n = a + (b & d | c & ~d) + (x >>> 0) + t;\r\n return ((n << s) | (n >>> (32 - s))) + b;\r\n };\r\n md5._hh = function (a, b, c, d, x, s, t) {\r\n var n = a + (b ^ c ^ d) + (x >>> 0) + t;\r\n return ((n << s) | (n >>> (32 - s))) + b;\r\n };\r\n md5._ii = function (a, b, c, d, x, s, t) {\r\n var n = a + (c ^ (b | ~d)) + (x >>> 0) + t;\r\n return ((n << s) | (n >>> (32 - s))) + b;\r\n };\r\n\r\n // Package private blocksize\r\n md5._blocksize = 16;\r\n md5._digestsize = 16;\r\n\r\n module.exports = function (message, options) {\r\n if (message === undefined || message === null)\r\n throw new Error('Illegal argument ' + message);\r\n\r\n var digestbytes = crypt.wordsToBytes(md5(message, options));\r\n return options && options.asBytes ? digestbytes :\r\n options && options.asString ? bin.bytesToString(digestbytes) :\r\n crypt.bytesToHex(digestbytes);\r\n };\r\n\r\n})();\r\n\n\n/***/ }),\n/* 497 */\n/***/ (function(module, exports) {\n\n(function() {\n var base64map\n = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',\n\n crypt = {\n // Bit-wise rotation left\n rotl: function(n, b) {\n return (n << b) | (n >>> (32 - b));\n },\n\n // Bit-wise rotation right\n rotr: function(n, b) {\n return (n << (32 - b)) | (n >>> b);\n },\n\n // Swap big-endian to little-endian and vice versa\n endian: function(n) {\n // If number given, swap endian\n if (n.constructor == Number) {\n return crypt.rotl(n, 8) & 0x00FF00FF | crypt.rotl(n, 24) & 0xFF00FF00;\n }\n\n // Else, assume array and swap all items\n for (var i = 0; i < n.length; i++)\n n[i] = crypt.endian(n[i]);\n return n;\n },\n\n // Generate an array of any length of random bytes\n randomBytes: function(n) {\n for (var bytes = []; n > 0; n--)\n bytes.push(Math.floor(Math.random() * 256));\n return bytes;\n },\n\n // Convert a byte array to big-endian 32-bit words\n bytesToWords: function(bytes) {\n for (var words = [], i = 0, b = 0; i < bytes.length; i++, b += 8)\n words[b >>> 5] |= bytes[i] << (24 - b % 32);\n return words;\n },\n\n // Convert big-endian 32-bit words to a byte array\n wordsToBytes: function(words) {\n for (var bytes = [], b = 0; b < words.length * 32; b += 8)\n bytes.push((words[b >>> 5] >>> (24 - b % 32)) & 0xFF);\n return bytes;\n },\n\n // Convert a byte array to a hex string\n bytesToHex: function(bytes) {\n for (var hex = [], i = 0; i < bytes.length; i++) {\n hex.push((bytes[i] >>> 4).toString(16));\n hex.push((bytes[i] & 0xF).toString(16));\n }\n return hex.join('');\n },\n\n // Convert a hex string to a byte array\n hexToBytes: function(hex) {\n for (var bytes = [], c = 0; c < hex.length; c += 2)\n bytes.push(parseInt(hex.substr(c, 2), 16));\n return bytes;\n },\n\n // Convert a byte array to a base-64 string\n bytesToBase64: function(bytes) {\n for (var base64 = [], i = 0; i < bytes.length; i += 3) {\n var triplet = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2];\n for (var j = 0; j < 4; j++)\n if (i * 8 + j * 6 <= bytes.length * 8)\n base64.push(base64map.charAt((triplet >>> 6 * (3 - j)) & 0x3F));\n else\n base64.push('=');\n }\n return base64.join('');\n },\n\n // Convert a base-64 string to a byte array\n base64ToBytes: function(base64) {\n // Remove non-base-64 characters\n base64 = base64.replace(/[^A-Z0-9+\\/]/ig, '');\n\n for (var bytes = [], i = 0, imod4 = 0; i < base64.length;\n imod4 = ++i % 4) {\n if (imod4 == 0) continue;\n bytes.push(((base64map.indexOf(base64.charAt(i - 1))\n & (Math.pow(2, -2 * imod4 + 8) - 1)) << (imod4 * 2))\n | (base64map.indexOf(base64.charAt(i)) >>> (6 - imod4 * 2)));\n }\n return bytes;\n }\n };\n\n module.exports = crypt;\n})();\n\n\n/***/ }),\n/* 498 */\n/***/ (function(module, exports) {\n\n/*!\n * Determine if an object is a Buffer\n *\n * @author Feross Aboukhadijeh \n * @license MIT\n */\n\n// The _isBuffer check is for Safari 5-7 support, because it's missing\n// Object.prototype.constructor. Remove this eventually\nmodule.exports = function (obj) {\n return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer)\n}\n\nfunction isBuffer (obj) {\n return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)\n}\n\n// For Node v0.10 support. Remove this eventually.\nfunction isSlowBuffer (obj) {\n return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0))\n}\n\n\n/***/ }),\n/* 499 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\n\nvar _interopRequireDefault = __webpack_require__(2);\n\nvar _indexOf = _interopRequireDefault(__webpack_require__(102));\n\nvar dataURItoBlob = function dataURItoBlob(dataURI, type) {\n var _context;\n\n var byteString; // 传入的 base64,不是 dataURL\n\n if ((0, _indexOf.default)(dataURI).call(dataURI, 'base64') < 0) {\n byteString = atob(dataURI);\n } else if ((0, _indexOf.default)(_context = dataURI.split(',')[0]).call(_context, 'base64') >= 0) {\n type = type || dataURI.split(',')[0].split(':')[1].split(';')[0];\n byteString = atob(dataURI.split(',')[1]);\n } else {\n byteString = unescape(dataURI.split(',')[1]);\n }\n\n var ia = new Uint8Array(byteString.length);\n\n for (var i = 0; i < byteString.length; i++) {\n ia[i] = byteString.charCodeAt(i);\n }\n\n return new Blob([ia], {\n type: type\n });\n};\n\nmodule.exports = dataURItoBlob;\n\n/***/ }),\n/* 500 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\n\nvar _interopRequireDefault = __webpack_require__(2);\n\nvar _slicedToArray2 = _interopRequireDefault(__webpack_require__(501));\n\nvar _map = _interopRequireDefault(__webpack_require__(39));\n\nvar _indexOf = _interopRequireDefault(__webpack_require__(102));\n\nvar _find = _interopRequireDefault(__webpack_require__(104));\n\nvar _promise = _interopRequireDefault(__webpack_require__(10));\n\nvar _concat = _interopRequireDefault(__webpack_require__(29));\n\nvar _keys2 = _interopRequireDefault(__webpack_require__(48));\n\nvar _stringify = _interopRequireDefault(__webpack_require__(34));\n\nvar _defineProperty = _interopRequireDefault(__webpack_require__(223));\n\nvar _getOwnPropertyDescriptor = _interopRequireDefault(__webpack_require__(522));\n\nvar _ = __webpack_require__(1);\n\nvar AVError = __webpack_require__(40);\n\nvar _require = __webpack_require__(25),\n _request = _require._request;\n\nvar _require2 = __webpack_require__(28),\n isNullOrUndefined = _require2.isNullOrUndefined,\n ensureArray = _require2.ensureArray,\n transformFetchOptions = _require2.transformFetchOptions,\n setValue = _require2.setValue,\n findValue = _require2.findValue,\n isPlainObject = _require2.isPlainObject,\n continueWhile = _require2.continueWhile;\n\nvar recursiveToPointer = function recursiveToPointer(value) {\n if (_.isArray(value)) return (0, _map.default)(value).call(value, recursiveToPointer);\n if (isPlainObject(value)) return _.mapObject(value, recursiveToPointer);\n if (_.isObject(value) && value._toPointer) return value._toPointer();\n return value;\n};\n\nvar RESERVED_KEYS = ['objectId', 'createdAt', 'updatedAt'];\n\nvar checkReservedKey = function checkReservedKey(key) {\n if ((0, _indexOf.default)(RESERVED_KEYS).call(RESERVED_KEYS, key) !== -1) {\n throw new Error(\"key[\".concat(key, \"] is reserved\"));\n }\n};\n\nvar handleBatchResults = function handleBatchResults(results) {\n var firstError = (0, _find.default)(_).call(_, results, function (result) {\n return result instanceof Error;\n });\n\n if (!firstError) {\n return results;\n }\n\n var error = new AVError(firstError.code, firstError.message);\n error.results = results;\n throw error;\n}; // Helper function to get a value from a Backbone object as a property\n// or as a function.\n\n\nfunction getValue(object, prop) {\n if (!(object && object[prop])) {\n return null;\n }\n\n return _.isFunction(object[prop]) ? object[prop]() : object[prop];\n} // AV.Object is analogous to the Java AVObject.\n// It also implements the same interface as a Backbone model.\n\n\nmodule.exports = function (AV) {\n /**\n * Creates a new model with defined attributes. A client id (cid) is\n * automatically generated and assigned for you.\n *\n *
You won't normally call this method directly. It is recommended that\n * you use a subclass of AV.Object instead, created by calling\n * extend.
\n *\n *
However, if you don't want to use a subclass, or aren't sure which\n * subclass is appropriate, you can use this form:
\n * var object = new AV.Object(\"ClassName\");\n *
\n * That is basically equivalent to:
\n * var MyClass = AV.Object.extend(\"ClassName\");\n * var object = new MyClass();\n *
\n *\n * @param {Object} attributes The initial set of data to store in the object.\n * @param {Object} options A set of Backbone-like options for creating the\n * object. The only option currently supported is \"collection\".\n * @see AV.Object.extend\n *\n * @class\n *\n *
The fundamental unit of AV data, which implements the Backbone Model\n * interface.
\n */\n AV.Object = function (attributes, options) {\n // Allow new AV.Object(\"ClassName\") as a shortcut to _create.\n if (_.isString(attributes)) {\n return AV.Object._create.apply(this, arguments);\n }\n\n attributes = attributes || {};\n\n if (options && options.parse) {\n attributes = this.parse(attributes);\n attributes = this._mergeMagicFields(attributes);\n }\n\n var defaults = getValue(this, 'defaults');\n\n if (defaults) {\n attributes = _.extend({}, defaults, attributes);\n }\n\n if (options && options.collection) {\n this.collection = options.collection;\n }\n\n this._serverData = {}; // The last known data for this object from cloud.\n\n this._opSetQueue = [{}]; // List of sets of changes to the data.\n\n this._flags = {};\n this.attributes = {}; // The best estimate of this's current data.\n\n this._hashedJSON = {}; // Hash of values of containers at last save.\n\n this._escapedAttributes = {};\n this.cid = _.uniqueId('c');\n this.changed = {};\n this._silent = {};\n this._pending = {};\n this.set(attributes, {\n silent: true\n });\n this.changed = {};\n this._silent = {};\n this._pending = {};\n this._hasData = true;\n this._previousAttributes = _.clone(this.attributes);\n this.initialize.apply(this, arguments);\n };\n /**\n * @lends AV.Object.prototype\n * @property {String} id The objectId of the AV Object.\n */\n\n /**\n * Saves the given list of AV.Object.\n * If any error is encountered, stops and calls the error handler.\n *\n * @example\n * AV.Object.saveAll([object1, object2, ...]).then(function(list) {\n * // All the objects were saved.\n * }, function(error) {\n * // An error occurred while saving one of the objects.\n * });\n *\n * @param {Array} list A list of AV.Object.\n */\n\n\n AV.Object.saveAll = function (list, options) {\n return AV.Object._deepSaveAsync(list, null, options);\n };\n /**\n * Fetch the given list of AV.Object.\n *\n * @param {AV.Object[]} objects A list of AV.Object\n * @param {AuthOptions} options\n * @return {Promise.} The given list of AV.Object, updated\n */\n\n\n AV.Object.fetchAll = function (objects, options) {\n return _promise.default.resolve().then(function () {\n return _request('batch', null, null, 'POST', {\n requests: (0, _map.default)(_).call(_, objects, function (object) {\n var _context;\n\n if (!object.className) throw new Error('object must have className to fetch');\n if (!object.id) throw new Error('object must have id to fetch');\n if (object.dirty()) throw new Error('object is modified but not saved');\n return {\n method: 'GET',\n path: (0, _concat.default)(_context = \"/1.1/classes/\".concat(object.className, \"/\")).call(_context, object.id)\n };\n })\n }, options);\n }).then(function (response) {\n var results = (0, _map.default)(_).call(_, objects, function (object, i) {\n if (response[i].success) {\n var fetchedAttrs = object.parse(response[i].success);\n\n object._cleanupUnsetKeys(fetchedAttrs);\n\n object._finishFetch(fetchedAttrs);\n\n return object;\n }\n\n if (response[i].success === null) {\n return new AVError(AVError.OBJECT_NOT_FOUND, 'Object not found.');\n }\n\n return new AVError(response[i].error.code, response[i].error.error);\n });\n return handleBatchResults(results);\n });\n }; // Attach all inheritable methods to the AV.Object prototype.\n\n\n _.extend(AV.Object.prototype, AV.Events,\n /** @lends AV.Object.prototype */\n {\n _fetchWhenSave: false,\n\n /**\n * Initialize is an empty function by default. Override it with your own\n * initialization logic.\n */\n initialize: function initialize() {},\n\n /**\n * Set whether to enable fetchWhenSave option when updating object.\n * When set true, SDK would fetch the latest object after saving.\n * Default is false.\n *\n * @deprecated use AV.Object#save with options.fetchWhenSave instead\n * @param {boolean} enable true to enable fetchWhenSave option.\n */\n fetchWhenSave: function fetchWhenSave(enable) {\n console.warn('AV.Object#fetchWhenSave is deprecated, use AV.Object#save with options.fetchWhenSave instead.');\n\n if (!_.isBoolean(enable)) {\n throw new Error('Expect boolean value for fetchWhenSave');\n }\n\n this._fetchWhenSave = enable;\n },\n\n /**\n * Returns the object's objectId.\n * @return {String} the objectId.\n */\n getObjectId: function getObjectId() {\n return this.id;\n },\n\n /**\n * Returns the object's createdAt attribute.\n * @return {Date}\n */\n getCreatedAt: function getCreatedAt() {\n return this.createdAt;\n },\n\n /**\n * Returns the object's updatedAt attribute.\n * @return {Date}\n */\n getUpdatedAt: function getUpdatedAt() {\n return this.updatedAt;\n },\n\n /**\n * Returns a JSON version of the object.\n * @return {Object}\n */\n toJSON: function toJSON(key, holder) {\n var seenObjects = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];\n return this._toFullJSON(seenObjects, false);\n },\n\n /**\n * Returns a JSON version of the object with meta data.\n * Inverse to {@link AV.parseJSON}\n * @since 3.0.0\n * @return {Object}\n */\n toFullJSON: function toFullJSON() {\n var seenObjects = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];\n return this._toFullJSON(seenObjects);\n },\n _toFullJSON: function _toFullJSON(seenObjects) {\n var _this = this;\n\n var full = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;\n\n var json = _.clone(this.attributes);\n\n if (_.isArray(seenObjects)) {\n var newSeenObjects = (0, _concat.default)(seenObjects).call(seenObjects, this);\n }\n\n AV._objectEach(json, function (val, key) {\n json[key] = AV._encode(val, newSeenObjects, undefined, full);\n });\n\n AV._objectEach(this._operations, function (val, key) {\n json[key] = val;\n });\n\n if (_.has(this, 'id')) {\n json.objectId = this.id;\n }\n\n ['createdAt', 'updatedAt'].forEach(function (key) {\n if (_.has(_this, key)) {\n var val = _this[key];\n json[key] = _.isDate(val) ? val.toJSON() : val;\n }\n });\n\n if (full) {\n json.__type = 'Object';\n if (_.isArray(seenObjects) && seenObjects.length) json.__type = 'Pointer';\n json.className = this.className;\n }\n\n return json;\n },\n\n /**\n * Updates _hashedJSON to reflect the current state of this object.\n * Adds any changed hash values to the set of pending changes.\n * @private\n */\n _refreshCache: function _refreshCache() {\n var self = this;\n\n if (self._refreshingCache) {\n return;\n }\n\n self._refreshingCache = true;\n\n AV._objectEach(this.attributes, function (value, key) {\n if (value instanceof AV.Object) {\n value._refreshCache();\n } else if (_.isObject(value)) {\n if (self._resetCacheForKey(key)) {\n self.set(key, new AV.Op.Set(value), {\n silent: true\n });\n }\n }\n });\n\n delete self._refreshingCache;\n },\n\n /**\n * Returns true if this object has been modified since its last\n * save/refresh. If an attribute is specified, it returns true only if that\n * particular attribute has been modified since the last save/refresh.\n * @param {String} attr An attribute name (optional).\n * @return {Boolean}\n */\n dirty: function dirty(attr) {\n this._refreshCache();\n\n var currentChanges = _.last(this._opSetQueue);\n\n if (attr) {\n return currentChanges[attr] ? true : false;\n }\n\n if (!this.id) {\n return true;\n }\n\n if ((0, _keys2.default)(_).call(_, currentChanges).length > 0) {\n return true;\n }\n\n return false;\n },\n\n /**\n * Returns the keys of the modified attribute since its last save/refresh.\n * @return {String[]}\n */\n dirtyKeys: function dirtyKeys() {\n this._refreshCache();\n\n var currentChanges = _.last(this._opSetQueue);\n\n return (0, _keys2.default)(_).call(_, currentChanges);\n },\n\n /**\n * Gets a Pointer referencing this Object.\n * @private\n */\n _toPointer: function _toPointer() {\n // if (!this.id) {\n // throw new Error(\"Can't serialize an unsaved AV.Object\");\n // }\n return {\n __type: 'Pointer',\n className: this.className,\n objectId: this.id\n };\n },\n\n /**\n * Gets the value of an attribute.\n * @param {String} attr The string name of an attribute.\n */\n get: function get(attr) {\n switch (attr) {\n case 'objectId':\n return this.id;\n\n case 'createdAt':\n case 'updatedAt':\n return this[attr];\n\n default:\n return this.attributes[attr];\n }\n },\n\n /**\n * Gets a relation on the given class for the attribute.\n * @param {String} attr The attribute to get the relation for.\n * @return {AV.Relation}\n */\n relation: function relation(attr) {\n var value = this.get(attr);\n\n if (value) {\n if (!(value instanceof AV.Relation)) {\n throw new Error('Called relation() on non-relation field ' + attr);\n }\n\n value._ensureParentAndKey(this, attr);\n\n return value;\n } else {\n return new AV.Relation(this, attr);\n }\n },\n\n /**\n * Gets the HTML-escaped value of an attribute.\n */\n escape: function escape(attr) {\n var html = this._escapedAttributes[attr];\n\n if (html) {\n return html;\n }\n\n var val = this.attributes[attr];\n var escaped;\n\n if (isNullOrUndefined(val)) {\n escaped = '';\n } else {\n escaped = _.escape(val.toString());\n }\n\n this._escapedAttributes[attr] = escaped;\n return escaped;\n },\n\n /**\n * Returns true if the attribute contains a value that is not\n * null or undefined.\n * @param {String} attr The string name of the attribute.\n * @return {Boolean}\n */\n has: function has(attr) {\n return !isNullOrUndefined(this.attributes[attr]);\n },\n\n /**\n * Pulls \"special\" fields like objectId, createdAt, etc. out of attrs\n * and puts them on \"this\" directly. Removes them from attrs.\n * @param attrs - A dictionary with the data for this AV.Object.\n * @private\n */\n _mergeMagicFields: function _mergeMagicFields(attrs) {\n // Check for changes of magic fields.\n var model = this;\n var specialFields = ['objectId', 'createdAt', 'updatedAt'];\n\n AV._arrayEach(specialFields, function (attr) {\n if (attrs[attr]) {\n if (attr === 'objectId') {\n model.id = attrs[attr];\n } else if ((attr === 'createdAt' || attr === 'updatedAt') && !_.isDate(attrs[attr])) {\n model[attr] = AV._parseDate(attrs[attr]);\n } else {\n model[attr] = attrs[attr];\n }\n\n delete attrs[attr];\n }\n });\n\n return attrs;\n },\n\n /**\n * Returns the json to be sent to the server.\n * @private\n */\n _startSave: function _startSave() {\n this._opSetQueue.push({});\n },\n\n /**\n * Called when a save fails because of an error. Any changes that were part\n * of the save need to be merged with changes made after the save. This\n * might throw an exception is you do conflicting operations. For example,\n * if you do:\n * object.set(\"foo\", \"bar\");\n * object.set(\"invalid field name\", \"baz\");\n * object.save();\n * object.increment(\"foo\");\n * then this will throw when the save fails and the client tries to merge\n * \"bar\" with the +1.\n * @private\n */\n _cancelSave: function _cancelSave() {\n var failedChanges = _.first(this._opSetQueue);\n\n this._opSetQueue = _.rest(this._opSetQueue);\n\n var nextChanges = _.first(this._opSetQueue);\n\n AV._objectEach(failedChanges, function (op, key) {\n var op1 = failedChanges[key];\n var op2 = nextChanges[key];\n\n if (op1 && op2) {\n nextChanges[key] = op2._mergeWithPrevious(op1);\n } else if (op1) {\n nextChanges[key] = op1;\n }\n });\n\n this._saving = this._saving - 1;\n },\n\n /**\n * Called when a save completes successfully. This merges the changes that\n * were saved into the known server data, and overrides it with any data\n * sent directly from the server.\n * @private\n */\n _finishSave: function _finishSave(serverData) {\n var _context2;\n\n // Grab a copy of any object referenced by this object. These instances\n // may have already been fetched, and we don't want to lose their data.\n // Note that doing it like this means we will unify separate copies of the\n // same object, but that's a risk we have to take.\n var fetchedObjects = {};\n\n AV._traverse(this.attributes, function (object) {\n if (object instanceof AV.Object && object.id && object._hasData) {\n fetchedObjects[object.id] = object;\n }\n });\n\n var savedChanges = _.first(this._opSetQueue);\n\n this._opSetQueue = _.rest(this._opSetQueue);\n\n this._applyOpSet(savedChanges, this._serverData);\n\n this._mergeMagicFields(serverData);\n\n var self = this;\n\n AV._objectEach(serverData, function (value, key) {\n self._serverData[key] = AV._decode(value, key); // Look for any objects that might have become unfetched and fix them\n // by replacing their values with the previously observed values.\n\n var fetched = AV._traverse(self._serverData[key], function (object) {\n if (object instanceof AV.Object && fetchedObjects[object.id]) {\n return fetchedObjects[object.id];\n }\n });\n\n if (fetched) {\n self._serverData[key] = fetched;\n }\n });\n\n this._rebuildAllEstimatedData();\n\n var opSetQueue = (0, _map.default)(_context2 = this._opSetQueue).call(_context2, _.clone);\n\n this._refreshCache();\n\n this._opSetQueue = opSetQueue;\n this._saving = this._saving - 1;\n },\n\n /**\n * Called when a fetch or login is complete to set the known server data to\n * the given object.\n * @private\n */\n _finishFetch: function _finishFetch(serverData, hasData) {\n // Clear out any changes the user might have made previously.\n this._opSetQueue = [{}]; // Bring in all the new server data.\n\n this._mergeMagicFields(serverData);\n\n var self = this;\n\n AV._objectEach(serverData, function (value, key) {\n self._serverData[key] = AV._decode(value, key);\n }); // Refresh the attributes.\n\n\n this._rebuildAllEstimatedData(); // Clear out the cache of mutable containers.\n\n\n this._refreshCache();\n\n this._opSetQueue = [{}];\n this._hasData = hasData;\n },\n\n /**\n * Applies the set of AV.Op in opSet to the object target.\n * @private\n */\n _applyOpSet: function _applyOpSet(opSet, target) {\n var self = this;\n\n AV._objectEach(opSet, function (change, key) {\n var _findValue = findValue(target, key),\n _findValue2 = (0, _slicedToArray2.default)(_findValue, 3),\n value = _findValue2[0],\n actualTarget = _findValue2[1],\n actualKey = _findValue2[2];\n\n setValue(target, key, change._estimate(value, self, key));\n\n if (actualTarget && actualTarget[actualKey] === AV.Op._UNSET) {\n delete actualTarget[actualKey];\n }\n });\n },\n\n /**\n * Replaces the cached value for key with the current value.\n * Returns true if the new value is different than the old value.\n * @private\n */\n _resetCacheForKey: function _resetCacheForKey(key) {\n var value = this.attributes[key];\n\n if (_.isObject(value) && !(value instanceof AV.Object) && !(value instanceof AV.File)) {\n var json = (0, _stringify.default)(recursiveToPointer(value));\n\n if (this._hashedJSON[key] !== json) {\n var wasSet = !!this._hashedJSON[key];\n this._hashedJSON[key] = json;\n return wasSet;\n }\n }\n\n return false;\n },\n\n /**\n * Populates attributes[key] by starting with the last known data from the\n * server, and applying all of the local changes that have been made to that\n * key since then.\n * @private\n */\n _rebuildEstimatedDataForKey: function _rebuildEstimatedDataForKey(key) {\n var self = this;\n delete this.attributes[key];\n\n if (this._serverData[key]) {\n this.attributes[key] = this._serverData[key];\n }\n\n AV._arrayEach(this._opSetQueue, function (opSet) {\n var op = opSet[key];\n\n if (op) {\n var _findValue3 = findValue(self.attributes, key),\n _findValue4 = (0, _slicedToArray2.default)(_findValue3, 4),\n value = _findValue4[0],\n actualTarget = _findValue4[1],\n actualKey = _findValue4[2],\n firstKey = _findValue4[3];\n\n setValue(self.attributes, key, op._estimate(value, self, key));\n\n if (actualTarget && actualTarget[actualKey] === AV.Op._UNSET) {\n delete actualTarget[actualKey];\n }\n\n self._resetCacheForKey(firstKey);\n }\n });\n },\n\n /**\n * Populates attributes by starting with the last known data from the\n * server, and applying all of the local changes that have been made since\n * then.\n * @private\n */\n _rebuildAllEstimatedData: function _rebuildAllEstimatedData() {\n var self = this;\n\n var previousAttributes = _.clone(this.attributes);\n\n this.attributes = _.clone(this._serverData);\n\n AV._arrayEach(this._opSetQueue, function (opSet) {\n self._applyOpSet(opSet, self.attributes);\n\n AV._objectEach(opSet, function (op, key) {\n self._resetCacheForKey(key);\n });\n }); // Trigger change events for anything that changed because of the fetch.\n\n\n AV._objectEach(previousAttributes, function (oldValue, key) {\n if (self.attributes[key] !== oldValue) {\n self.trigger('change:' + key, self, self.attributes[key], {});\n }\n });\n\n AV._objectEach(this.attributes, function (newValue, key) {\n if (!_.has(previousAttributes, key)) {\n self.trigger('change:' + key, self, newValue, {});\n }\n });\n },\n\n /**\n * Sets a hash of model attributes on the object, firing\n * \"change\" unless you choose to silence it.\n *\n *
You can call it with an object containing keys and values, or with one\n * key and value. For example:
\n *\n * @example\n * gameTurn.set({\n * player: player1,\n * diceRoll: 2\n * });\n *\n * game.set(\"currentPlayer\", player2);\n *\n * game.set(\"finished\", true);\n *\n * @param {String} key The key to set.\n * @param {Any} value The value to give it.\n * @param {Object} [options]\n * @param {Boolean} [options.silent]\n * @return {AV.Object} self if succeeded, throws if the value is not valid.\n * @see AV.Object#validate\n */\n set: function set(key, value, options) {\n var attrs;\n\n if (_.isObject(key) || isNullOrUndefined(key)) {\n attrs = _.mapObject(key, function (v, k) {\n checkReservedKey(k);\n return AV._decode(v, k);\n });\n options = value;\n } else {\n attrs = {};\n checkReservedKey(key);\n attrs[key] = AV._decode(value, key);\n } // Extract attributes and options.\n\n\n options = options || {};\n\n if (!attrs) {\n return this;\n }\n\n if (attrs instanceof AV.Object) {\n attrs = attrs.attributes;\n } // If the unset option is used, every attribute should be a Unset.\n\n\n if (options.unset) {\n AV._objectEach(attrs, function (unused_value, key) {\n attrs[key] = new AV.Op.Unset();\n });\n } // Apply all the attributes to get the estimated values.\n\n\n var dataToValidate = _.clone(attrs);\n\n var self = this;\n\n AV._objectEach(dataToValidate, function (value, key) {\n if (value instanceof AV.Op) {\n dataToValidate[key] = value._estimate(self.attributes[key], self, key);\n\n if (dataToValidate[key] === AV.Op._UNSET) {\n delete dataToValidate[key];\n }\n }\n }); // Run validation.\n\n\n this._validate(attrs, options);\n\n options.changes = {};\n var escaped = this._escapedAttributes; // Update attributes.\n\n AV._arrayEach((0, _keys2.default)(_).call(_, attrs), function (attr) {\n var val = attrs[attr]; // If this is a relation object we need to set the parent correctly,\n // since the location where it was parsed does not have access to\n // this object.\n\n if (val instanceof AV.Relation) {\n val.parent = self;\n }\n\n if (!(val instanceof AV.Op)) {\n val = new AV.Op.Set(val);\n } // See if this change will actually have any effect.\n\n\n var isRealChange = true;\n\n if (val instanceof AV.Op.Set && _.isEqual(self.attributes[attr], val.value)) {\n isRealChange = false;\n }\n\n if (isRealChange) {\n delete escaped[attr];\n\n if (options.silent) {\n self._silent[attr] = true;\n } else {\n options.changes[attr] = true;\n }\n }\n\n var currentChanges = _.last(self._opSetQueue);\n\n currentChanges[attr] = val._mergeWithPrevious(currentChanges[attr]);\n\n self._rebuildEstimatedDataForKey(attr);\n\n if (isRealChange) {\n self.changed[attr] = self.attributes[attr];\n\n if (!options.silent) {\n self._pending[attr] = true;\n }\n } else {\n delete self.changed[attr];\n delete self._pending[attr];\n }\n });\n\n if (!options.silent) {\n this.change(options);\n }\n\n return this;\n },\n\n /**\n * Remove an attribute from the model, firing \"change\" unless\n * you choose to silence it. This is a noop if the attribute doesn't\n * exist.\n * @param key {String} The key.\n */\n unset: function unset(attr, options) {\n options = options || {};\n options.unset = true;\n return this.set(attr, null, options);\n },\n\n /**\n * Atomically increments the value of the given attribute the next time the\n * object is saved. If no amount is specified, 1 is used by default.\n *\n * @param key {String} The key.\n * @param amount {Number} The amount to increment by.\n */\n increment: function increment(attr, amount) {\n if (_.isUndefined(amount) || _.isNull(amount)) {\n amount = 1;\n }\n\n return this.set(attr, new AV.Op.Increment(amount));\n },\n\n /**\n * Atomically add an object to the end of the array associated with a given\n * key.\n * @param key {String} The key.\n * @param item {} The item to add.\n */\n add: function add(attr, item) {\n return this.set(attr, new AV.Op.Add(ensureArray(item)));\n },\n\n /**\n * Atomically add an object to the array associated with a given key, only\n * if it is not already present in the array. The position of the insert is\n * not guaranteed.\n *\n * @param key {String} The key.\n * @param item {} The object to add.\n */\n addUnique: function addUnique(attr, item) {\n return this.set(attr, new AV.Op.AddUnique(ensureArray(item)));\n },\n\n /**\n * Atomically remove all instances of an object from the array associated\n * with a given key.\n *\n * @param key {String} The key.\n * @param item {} The object to remove.\n */\n remove: function remove(attr, item) {\n return this.set(attr, new AV.Op.Remove(ensureArray(item)));\n },\n\n /**\n * Atomically apply a \"bit and\" operation on the value associated with a\n * given key.\n *\n * @param key {String} The key.\n * @param value {Number} The value to apply.\n */\n bitAnd: function bitAnd(attr, value) {\n return this.set(attr, new AV.Op.BitAnd(value));\n },\n\n /**\n * Atomically apply a \"bit or\" operation on the value associated with a\n * given key.\n *\n * @param key {String} The key.\n * @param value {Number} The value to apply.\n */\n bitOr: function bitOr(attr, value) {\n return this.set(attr, new AV.Op.BitOr(value));\n },\n\n /**\n * Atomically apply a \"bit xor\" operation on the value associated with a\n * given key.\n *\n * @param key {String} The key.\n * @param value {Number} The value to apply.\n */\n bitXor: function bitXor(attr, value) {\n return this.set(attr, new AV.Op.BitXor(value));\n },\n\n /**\n * Returns an instance of a subclass of AV.Op describing what kind of\n * modification has been performed on this field since the last time it was\n * saved. For example, after calling object.increment(\"x\"), calling\n * object.op(\"x\") would return an instance of AV.Op.Increment.\n *\n * @param key {String} The key.\n * @returns {AV.Op} The operation, or undefined if none.\n */\n op: function op(attr) {\n return _.last(this._opSetQueue)[attr];\n },\n\n /**\n * Clear all attributes on the model, firing \"change\" unless\n * you choose to silence it.\n */\n clear: function clear(options) {\n options = options || {};\n options.unset = true;\n\n var keysToClear = _.extend(this.attributes, this._operations);\n\n return this.set(keysToClear, options);\n },\n\n /**\n * Clears any (or specific) changes to the model made since the last save.\n * @param {string|string[]} [keys] specify keys to revert.\n */\n revert: function revert(keys) {\n var lastOp = _.last(this._opSetQueue);\n\n var _keys = ensureArray(keys || (0, _keys2.default)(_).call(_, lastOp));\n\n _keys.forEach(function (key) {\n delete lastOp[key];\n });\n\n this._rebuildAllEstimatedData();\n\n return this;\n },\n\n /**\n * Returns a JSON-encoded set of operations to be sent with the next save\n * request.\n * @private\n */\n _getSaveJSON: function _getSaveJSON() {\n var json = _.clone(_.first(this._opSetQueue));\n\n AV._objectEach(json, function (op, key) {\n json[key] = op.toJSON();\n });\n\n return json;\n },\n\n /**\n * Returns true if this object can be serialized for saving.\n * @private\n */\n _canBeSerialized: function _canBeSerialized() {\n return AV.Object._canBeSerializedAsValue(this.attributes);\n },\n\n /**\n * Fetch the model from the server. If the server's representation of the\n * model differs from its current attributes, they will be overriden,\n * triggering a \"change\" event.\n * @param {Object} fetchOptions Optional options to set 'keys',\n * 'include' and 'includeACL' option.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled when the fetch\n * completes.\n */\n fetch: function fetch() {\n var fetchOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n var options = arguments.length > 1 ? arguments[1] : undefined;\n\n if (!this.id) {\n throw new Error('Cannot fetch unsaved object');\n }\n\n var self = this;\n\n var request = _request('classes', this.className, this.id, 'GET', transformFetchOptions(fetchOptions), options);\n\n return request.then(function (response) {\n var fetchedAttrs = self.parse(response);\n\n self._cleanupUnsetKeys(fetchedAttrs, (0, _keys2.default)(fetchOptions) ? ensureArray((0, _keys2.default)(fetchOptions)).join(',').split(',') : undefined);\n\n self._finishFetch(fetchedAttrs, true);\n\n return self;\n });\n },\n _cleanupUnsetKeys: function _cleanupUnsetKeys(fetchedAttrs) {\n var _this2 = this;\n\n var fetchedKeys = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : (0, _keys2.default)(_).call(_, this._serverData);\n\n _.forEach(fetchedKeys, function (key) {\n if (fetchedAttrs[key] === undefined) delete _this2._serverData[key];\n });\n },\n\n /**\n * Set a hash of model attributes, and save the model to the server.\n * updatedAt will be updated when the request returns.\n * You can either call it as:
\n * object.save();
\n * or
\n * object.save(null, options);
\n * or
\n * object.save(attrs, options);
\n * or
\n * object.save(key, value, options);
\n *\n * @example\n * gameTurn.save({\n * player: \"Jake Cutter\",\n * diceRoll: 2\n * }).then(function(gameTurnAgain) {\n * // The save was successful.\n * }, function(error) {\n * // The save failed. Error is an instance of AVError.\n * });\n *\n * @param {AuthOptions} options AuthOptions plus:\n * @param {Boolean} options.fetchWhenSave fetch and update object after save succeeded\n * @param {AV.Query} options.query Save object only when it matches the query\n * @return {Promise} A promise that is fulfilled when the save\n * completes.\n * @see AVError\n */\n save: function save(arg1, arg2, arg3) {\n var attrs, current, options;\n\n if (_.isObject(arg1) || isNullOrUndefined(arg1)) {\n attrs = arg1;\n options = arg2;\n } else {\n attrs = {};\n attrs[arg1] = arg2;\n options = arg3;\n }\n\n options = _.clone(options) || {};\n\n if (options.wait) {\n current = _.clone(this.attributes);\n }\n\n var setOptions = _.clone(options) || {};\n\n if (setOptions.wait) {\n setOptions.silent = true;\n }\n\n if (attrs) {\n this.set(attrs, setOptions);\n }\n\n var model = this;\n var unsavedChildren = [];\n var unsavedFiles = [];\n\n AV.Object._findUnsavedChildren(model, unsavedChildren, unsavedFiles);\n\n if (unsavedChildren.length + unsavedFiles.length > 1) {\n return AV.Object._deepSaveAsync(this, model, options);\n }\n\n this._startSave();\n\n this._saving = (this._saving || 0) + 1;\n this._allPreviousSaves = this._allPreviousSaves || _promise.default.resolve();\n this._allPreviousSaves = this._allPreviousSaves.catch(function (e) {}).then(function () {\n var method = model.id ? 'PUT' : 'POST';\n\n var json = model._getSaveJSON();\n\n var query = {};\n\n if (model._fetchWhenSave || options.fetchWhenSave) {\n query['new'] = 'true';\n } // user login option\n\n\n if (options._failOnNotExist) {\n query.failOnNotExist = 'true';\n }\n\n if (options.query) {\n var queryParams;\n\n if (typeof options.query._getParams === 'function') {\n queryParams = options.query._getParams();\n\n if (queryParams) {\n query.where = queryParams.where;\n }\n }\n\n if (!query.where) {\n var error = new Error('options.query is not an AV.Query');\n throw error;\n }\n }\n\n _.extend(json, model._flags);\n\n var route = 'classes';\n var className = model.className;\n\n if (model.className === '_User' && !model.id) {\n // Special-case user sign-up.\n route = 'users';\n className = null;\n } //hook makeRequest in options.\n\n\n var makeRequest = options._makeRequest || _request;\n var requestPromise = makeRequest(route, className, model.id, method, json, options, query);\n requestPromise = requestPromise.then(function (resp) {\n var serverAttrs = model.parse(resp);\n\n if (options.wait) {\n serverAttrs = _.extend(attrs || {}, serverAttrs);\n }\n\n model._finishSave(serverAttrs);\n\n if (options.wait) {\n model.set(current, setOptions);\n }\n\n return model;\n }, function (error) {\n model._cancelSave();\n\n throw error;\n });\n return requestPromise;\n });\n return this._allPreviousSaves;\n },\n\n /**\n * Destroy this model on the server if it was already persisted.\n * Optimistically removes the model from its collection, if it has one.\n * @param {AuthOptions} options AuthOptions plus:\n * @param {Boolean} [options.wait] wait for the server to respond\n * before removal.\n *\n * @return {Promise} A promise that is fulfilled when the destroy\n * completes.\n */\n destroy: function destroy(options) {\n options = options || {};\n var model = this;\n\n var triggerDestroy = function triggerDestroy() {\n model.trigger('destroy', model, model.collection, options);\n };\n\n if (!this.id) {\n return triggerDestroy();\n }\n\n if (!options.wait) {\n triggerDestroy();\n }\n\n var request = _request('classes', this.className, this.id, 'DELETE', this._flags, options);\n\n return request.then(function () {\n if (options.wait) {\n triggerDestroy();\n }\n\n return model;\n });\n },\n\n /**\n * Converts a response into the hash of attributes to be set on the model.\n * @ignore\n */\n parse: function parse(resp) {\n var output = _.clone(resp);\n\n ['createdAt', 'updatedAt'].forEach(function (key) {\n if (output[key]) {\n output[key] = AV._parseDate(output[key]);\n }\n });\n\n if (output.createdAt && !output.updatedAt) {\n output.updatedAt = output.createdAt;\n }\n\n return output;\n },\n\n /**\n * Creates a new model with identical attributes to this one.\n * @return {AV.Object}\n */\n clone: function clone() {\n return new this.constructor(this.attributes);\n },\n\n /**\n * Returns true if this object has never been saved to AV.\n * @return {Boolean}\n */\n isNew: function isNew() {\n return !this.id;\n },\n\n /**\n * Call this method to manually fire a `\"change\"` event for this model and\n * a `\"change:attribute\"` event for each changed attribute.\n * Calling this will cause all objects observing the model to update.\n */\n change: function change(options) {\n options = options || {};\n var changing = this._changing;\n this._changing = true; // Silent changes become pending changes.\n\n var self = this;\n\n AV._objectEach(this._silent, function (attr) {\n self._pending[attr] = true;\n }); // Silent changes are triggered.\n\n\n var changes = _.extend({}, options.changes, this._silent);\n\n this._silent = {};\n\n AV._objectEach(changes, function (unused_value, attr) {\n self.trigger('change:' + attr, self, self.get(attr), options);\n });\n\n if (changing) {\n return this;\n } // This is to get around lint not letting us make a function in a loop.\n\n\n var deleteChanged = function deleteChanged(value, attr) {\n if (!self._pending[attr] && !self._silent[attr]) {\n delete self.changed[attr];\n }\n }; // Continue firing `\"change\"` events while there are pending changes.\n\n\n while (!_.isEmpty(this._pending)) {\n this._pending = {};\n this.trigger('change', this, options); // Pending and silent changes still remain.\n\n AV._objectEach(this.changed, deleteChanged);\n\n self._previousAttributes = _.clone(this.attributes);\n }\n\n this._changing = false;\n return this;\n },\n\n /**\n * Gets the previous value of an attribute, recorded at the time the last\n * \"change\" event was fired.\n * @param {String} attr Name of the attribute to get.\n */\n previous: function previous(attr) {\n if (!arguments.length || !this._previousAttributes) {\n return null;\n }\n\n return this._previousAttributes[attr];\n },\n\n /**\n * Gets all of the attributes of the model at the time of the previous\n * \"change\" event.\n * @return {Object}\n */\n previousAttributes: function previousAttributes() {\n return _.clone(this._previousAttributes);\n },\n\n /**\n * Checks if the model is currently in a valid state. It's only possible to\n * get into an *invalid* state if you're using silent changes.\n * @return {Boolean}\n */\n isValid: function isValid() {\n try {\n this.validate(this.attributes);\n } catch (error) {\n return false;\n }\n\n return true;\n },\n\n /**\n * You should not call this function directly unless you subclass\n * AV.Object, in which case you can override this method\n * to provide additional validation on set and\n * save. Your implementation should throw an Error if\n * the attrs is invalid\n *\n * @param {Object} attrs The current data to validate.\n * @see AV.Object#set\n */\n validate: function validate(attrs) {\n if (_.has(attrs, 'ACL') && !(attrs.ACL instanceof AV.ACL)) {\n throw new AVError(AVError.OTHER_CAUSE, 'ACL must be a AV.ACL.');\n }\n },\n\n /**\n * Run validation against a set of incoming attributes, returning `true`\n * if all is well. If a specific `error` callback has been passed,\n * call that instead of firing the general `\"error\"` event.\n * @private\n */\n _validate: function _validate(attrs, options) {\n if (options.silent || !this.validate) {\n return;\n }\n\n attrs = _.extend({}, this.attributes, attrs);\n this.validate(attrs);\n },\n\n /**\n * Returns the ACL for this object.\n * @returns {AV.ACL} An instance of AV.ACL.\n * @see AV.Object#get\n */\n getACL: function getACL() {\n return this.get('ACL');\n },\n\n /**\n * Sets the ACL to be used for this object.\n * @param {AV.ACL} acl An instance of AV.ACL.\n * @param {Object} options Optional Backbone-like options object to be\n * passed in to set.\n * @return {AV.Object} self\n * @see AV.Object#set\n */\n setACL: function setACL(acl, options) {\n return this.set('ACL', acl, options);\n },\n disableBeforeHook: function disableBeforeHook() {\n this.ignoreHook('beforeSave');\n this.ignoreHook('beforeUpdate');\n this.ignoreHook('beforeDelete');\n },\n disableAfterHook: function disableAfterHook() {\n this.ignoreHook('afterSave');\n this.ignoreHook('afterUpdate');\n this.ignoreHook('afterDelete');\n },\n ignoreHook: function ignoreHook(hookName) {\n if (!_.contains(['beforeSave', 'afterSave', 'beforeUpdate', 'afterUpdate', 'beforeDelete', 'afterDelete'], hookName)) {\n throw new Error('Unsupported hookName: ' + hookName);\n }\n\n if (!AV.hookKey) {\n throw new Error('ignoreHook required hookKey');\n }\n\n if (!this._flags.__ignore_hooks) {\n this._flags.__ignore_hooks = [];\n }\n\n this._flags.__ignore_hooks.push(hookName);\n }\n });\n /**\n * Creates an instance of a subclass of AV.Object for the give classname\n * and id.\n * @param {String|Function} class the className or a subclass of AV.Object.\n * @param {String} id The object id of this model.\n * @return {AV.Object} A new subclass instance of AV.Object.\n */\n\n\n AV.Object.createWithoutData = function (klass, id, hasData) {\n var _klass;\n\n if (_.isString(klass)) {\n _klass = AV.Object._getSubclass(klass);\n } else if (klass.prototype && klass.prototype instanceof AV.Object) {\n _klass = klass;\n } else {\n throw new Error('class must be a string or a subclass of AV.Object.');\n }\n\n if (!id) {\n throw new TypeError('The objectId must be provided');\n }\n\n var object = new _klass();\n object.id = id;\n object._hasData = hasData;\n return object;\n };\n /**\n * Delete objects in batch.\n * @param {AV.Object[]} objects The AV.Object array to be deleted.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled when the save\n * completes.\n */\n\n\n AV.Object.destroyAll = function (objects) {\n var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n\n if (!objects || objects.length === 0) {\n return _promise.default.resolve();\n }\n\n var objectsByClassNameAndFlags = _.groupBy(objects, function (object) {\n return (0, _stringify.default)({\n className: object.className,\n flags: object._flags\n });\n });\n\n var body = {\n requests: (0, _map.default)(_).call(_, objectsByClassNameAndFlags, function (objects) {\n var _context3;\n\n var ids = (0, _map.default)(_).call(_, objects, 'id').join(',');\n return {\n method: 'DELETE',\n path: (0, _concat.default)(_context3 = \"/1.1/classes/\".concat(objects[0].className, \"/\")).call(_context3, ids),\n body: objects[0]._flags\n };\n })\n };\n return _request('batch', null, null, 'POST', body, options).then(function (response) {\n var firstError = (0, _find.default)(_).call(_, response, function (result) {\n return !result.success;\n });\n if (firstError) throw new AVError(firstError.error.code, firstError.error.error);\n return undefined;\n });\n };\n /**\n * Returns the appropriate subclass for making new instances of the given\n * className string.\n * @private\n */\n\n\n AV.Object._getSubclass = function (className) {\n if (!_.isString(className)) {\n throw new Error('AV.Object._getSubclass requires a string argument.');\n }\n\n var ObjectClass = AV.Object._classMap[className];\n\n if (!ObjectClass) {\n ObjectClass = AV.Object.extend(className);\n AV.Object._classMap[className] = ObjectClass;\n }\n\n return ObjectClass;\n };\n /**\n * Creates an instance of a subclass of AV.Object for the given classname.\n * @private\n */\n\n\n AV.Object._create = function (className, attributes, options) {\n var ObjectClass = AV.Object._getSubclass(className);\n\n return new ObjectClass(attributes, options);\n }; // Set up a map of className to class so that we can create new instances of\n // AV Objects from JSON automatically.\n\n\n AV.Object._classMap = {};\n AV.Object._extend = AV._extend;\n /**\n * Creates a new model with defined attributes,\n * It's the same with\n *
\n * new AV.Object(attributes, options);\n *
\n * @param {Object} attributes The initial set of data to store in the object.\n * @param {Object} options A set of Backbone-like options for creating the\n * object. The only option currently supported is \"collection\".\n * @return {AV.Object}\n * @since v0.4.4\n * @see AV.Object\n * @see AV.Object.extend\n */\n\n AV.Object['new'] = function (attributes, options) {\n return new AV.Object(attributes, options);\n };\n /**\n * Creates a new subclass of AV.Object for the given AV class name.\n *\n *
Every extension of a AV class will inherit from the most recent\n * previous extension of that class. When a AV.Object is automatically\n * created by parsing JSON, it will use the most recent extension of that\n * class.
\n *\n * @example\n * var MyClass = AV.Object.extend(\"MyClass\", {\n * // Instance properties\n * }, {\n * // Class properties\n * });\n *\n * @param {String} className The name of the AV class backing this model.\n * @param {Object} protoProps Instance properties to add to instances of the\n * class returned from this method.\n * @param {Object} classProps Class properties to add the class returned from\n * this method.\n * @return {Class} A new subclass of AV.Object.\n */\n\n\n AV.Object.extend = function (className, protoProps, classProps) {\n // Handle the case with only two args.\n if (!_.isString(className)) {\n if (className && _.has(className, 'className')) {\n return AV.Object.extend(className.className, className, protoProps);\n } else {\n throw new Error(\"AV.Object.extend's first argument should be the className.\");\n }\n } // If someone tries to subclass \"User\", coerce it to the right type.\n\n\n if (className === 'User') {\n className = '_User';\n }\n\n var NewClassObject = null;\n\n if (_.has(AV.Object._classMap, className)) {\n var OldClassObject = AV.Object._classMap[className]; // This new subclass has been told to extend both from \"this\" and from\n // OldClassObject. This is multiple inheritance, which isn't supported.\n // For now, let's just pick one.\n\n if (protoProps || classProps) {\n NewClassObject = OldClassObject._extend(protoProps, classProps);\n } else {\n return OldClassObject;\n }\n } else {\n protoProps = protoProps || {};\n protoProps._className = className;\n NewClassObject = this._extend(protoProps, classProps);\n } // Extending a subclass should reuse the classname automatically.\n\n\n NewClassObject.extend = function (arg0) {\n var _context4;\n\n if (_.isString(arg0) || arg0 && _.has(arg0, 'className')) {\n return AV.Object.extend.apply(NewClassObject, arguments);\n }\n\n var newArguments = (0, _concat.default)(_context4 = [className]).call(_context4, _.toArray(arguments));\n return AV.Object.extend.apply(NewClassObject, newArguments);\n }; // Add the query property descriptor.\n\n\n (0, _defineProperty.default)(NewClassObject, 'query', (0, _getOwnPropertyDescriptor.default)(AV.Object, 'query'));\n\n NewClassObject['new'] = function (attributes, options) {\n return new NewClassObject(attributes, options);\n };\n\n AV.Object._classMap[className] = NewClassObject;\n return NewClassObject;\n }; // ES6 class syntax support\n\n\n (0, _defineProperty.default)(AV.Object.prototype, 'className', {\n get: function get() {\n var className = this._className || this.constructor._LCClassName || this.constructor.name; // If someone tries to subclass \"User\", coerce it to the right type.\n\n if (className === 'User') {\n return '_User';\n }\n\n return className;\n }\n });\n /**\n * Register a class.\n * If a subclass of AV.Object is defined with your own implement\n * rather then AV.Object.extend, the subclass must be registered.\n * @param {Function} klass A subclass of AV.Object\n * @param {String} [name] Specify the name of the class. Useful when the class might be uglified.\n * @example\n * class Person extend AV.Object {}\n * AV.Object.register(Person);\n */\n\n AV.Object.register = function (klass, name) {\n if (!(klass.prototype instanceof AV.Object)) {\n throw new Error('registered class is not a subclass of AV.Object');\n }\n\n var className = name || klass.name;\n\n if (!className.length) {\n throw new Error('registered class must be named');\n }\n\n if (name) {\n klass._LCClassName = name;\n }\n\n AV.Object._classMap[className] = klass;\n };\n /**\n * Get a new Query of the current class\n * @name query\n * @memberof AV.Object\n * @type AV.Query\n * @readonly\n * @since v3.1.0\n * @example\n * const Post = AV.Object.extend('Post');\n * Post.query.equalTo('author', 'leancloud').find().then();\n */\n\n\n (0, _defineProperty.default)(AV.Object, 'query', {\n get: function get() {\n return new AV.Query(this.prototype.className);\n }\n });\n\n AV.Object._findUnsavedChildren = function (objects, children, files) {\n AV._traverse(objects, function (object) {\n if (object instanceof AV.Object) {\n if (object.dirty()) {\n children.push(object);\n }\n\n return;\n }\n\n if (object instanceof AV.File) {\n if (!object.id) {\n files.push(object);\n }\n\n return;\n }\n });\n };\n\n AV.Object._canBeSerializedAsValue = function (object) {\n var canBeSerializedAsValue = true;\n\n if (object instanceof AV.Object || object instanceof AV.File) {\n canBeSerializedAsValue = !!object.id;\n } else if (_.isArray(object)) {\n AV._arrayEach(object, function (child) {\n if (!AV.Object._canBeSerializedAsValue(child)) {\n canBeSerializedAsValue = false;\n }\n });\n } else if (_.isObject(object)) {\n AV._objectEach(object, function (child) {\n if (!AV.Object._canBeSerializedAsValue(child)) {\n canBeSerializedAsValue = false;\n }\n });\n }\n\n return canBeSerializedAsValue;\n };\n\n AV.Object._deepSaveAsync = function (object, model, options) {\n var unsavedChildren = [];\n var unsavedFiles = [];\n\n AV.Object._findUnsavedChildren(object, unsavedChildren, unsavedFiles);\n\n unsavedFiles = _.uniq(unsavedFiles);\n\n var promise = _promise.default.resolve();\n\n _.each(unsavedFiles, function (file) {\n promise = promise.then(function () {\n return file.save();\n });\n });\n\n var objects = _.uniq(unsavedChildren);\n\n var remaining = _.uniq(objects);\n\n return promise.then(function () {\n return continueWhile(function () {\n return remaining.length > 0;\n }, function () {\n // Gather up all the objects that can be saved in this batch.\n var batch = [];\n var newRemaining = [];\n\n AV._arrayEach(remaining, function (object) {\n if (object._canBeSerialized()) {\n batch.push(object);\n } else {\n newRemaining.push(object);\n }\n });\n\n remaining = newRemaining; // If we can't save any objects, there must be a circular reference.\n\n if (batch.length === 0) {\n return _promise.default.reject(new AVError(AVError.OTHER_CAUSE, 'Tried to save a batch with a cycle.'));\n } // Reserve a spot in every object's save queue.\n\n\n var readyToStart = _promise.default.resolve((0, _map.default)(_).call(_, batch, function (object) {\n return object._allPreviousSaves || _promise.default.resolve();\n })); // Save a single batch, whether previous saves succeeded or failed.\n\n\n var bathSavePromise = readyToStart.then(function () {\n return _request('batch', null, null, 'POST', {\n requests: (0, _map.default)(_).call(_, batch, function (object) {\n var method = object.id ? 'PUT' : 'POST';\n\n var json = object._getSaveJSON();\n\n _.extend(json, object._flags);\n\n var route = 'classes';\n var className = object.className;\n var path = \"/\".concat(route, \"/\").concat(className);\n\n if (object.className === '_User' && !object.id) {\n // Special-case user sign-up.\n path = '/users';\n }\n\n var path = \"/1.1\".concat(path);\n\n if (object.id) {\n path = path + '/' + object.id;\n }\n\n object._startSave();\n\n return {\n method: method,\n path: path,\n body: json,\n params: options && options.fetchWhenSave ? {\n fetchWhenSave: true\n } : undefined\n };\n })\n }, options).then(function (response) {\n var results = (0, _map.default)(_).call(_, batch, function (object, i) {\n if (response[i].success) {\n object._finishSave(object.parse(response[i].success));\n\n return object;\n }\n\n object._cancelSave();\n\n return new AVError(response[i].error.code, response[i].error.error);\n });\n return handleBatchResults(results);\n });\n });\n\n AV._arrayEach(batch, function (object) {\n object._allPreviousSaves = bathSavePromise;\n });\n\n return bathSavePromise;\n });\n }).then(function () {\n return object;\n });\n };\n};\n\n/***/ }),\n/* 501 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar arrayWithHoles = __webpack_require__(502);\n\nvar iterableToArrayLimit = __webpack_require__(510);\n\nvar unsupportedIterableToArray = __webpack_require__(511);\n\nvar nonIterableRest = __webpack_require__(521);\n\nfunction _slicedToArray(arr, i) {\n return arrayWithHoles(arr) || iterableToArrayLimit(arr, i) || unsupportedIterableToArray(arr, i) || nonIterableRest();\n}\n\nmodule.exports = _slicedToArray, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n/***/ }),\n/* 502 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar _Array$isArray = __webpack_require__(503);\n\nfunction _arrayWithHoles(arr) {\n if (_Array$isArray(arr)) return arr;\n}\n\nmodule.exports = _arrayWithHoles, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n/***/ }),\n/* 503 */\n/***/ (function(module, exports, __webpack_require__) {\n\nmodule.exports = __webpack_require__(504);\n\n/***/ }),\n/* 504 */\n/***/ (function(module, exports, __webpack_require__) {\n\nmodule.exports = __webpack_require__(505);\n\n\n/***/ }),\n/* 505 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar parent = __webpack_require__(506);\n\nmodule.exports = parent;\n\n\n/***/ }),\n/* 506 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar parent = __webpack_require__(507);\n\nmodule.exports = parent;\n\n\n/***/ }),\n/* 507 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar parent = __webpack_require__(508);\n\nmodule.exports = parent;\n\n\n/***/ }),\n/* 508 */\n/***/ (function(module, exports, __webpack_require__) {\n\n__webpack_require__(509);\nvar path = __webpack_require__(13);\n\nmodule.exports = path.Array.isArray;\n\n\n/***/ }),\n/* 509 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar $ = __webpack_require__(0);\nvar isArray = __webpack_require__(80);\n\n// `Array.isArray` method\n// https://tc39.es/ecma262/#sec-array.isarray\n$({ target: 'Array', stat: true }, {\n isArray: isArray\n});\n\n\n/***/ }),\n/* 510 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar _Symbol = __webpack_require__(225);\n\nvar _getIteratorMethod = __webpack_require__(231);\n\nfunction _iterableToArrayLimit(arr, i) {\n var _i = arr == null ? null : typeof _Symbol !== \"undefined\" && _getIteratorMethod(arr) || arr[\"@@iterator\"];\n\n if (_i == null) return;\n var _arr = [];\n var _n = true;\n var _d = false;\n\n var _s, _e;\n\n try {\n for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {\n _arr.push(_s.value);\n\n if (i && _arr.length === i) break;\n }\n } catch (err) {\n _d = true;\n _e = err;\n } finally {\n try {\n if (!_n && _i[\"return\"] != null) _i[\"return\"]();\n } finally {\n if (_d) throw _e;\n }\n }\n\n return _arr;\n}\n\nmodule.exports = _iterableToArrayLimit, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n/***/ }),\n/* 511 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar _sliceInstanceProperty = __webpack_require__(512);\n\nvar _Array$from = __webpack_require__(516);\n\nvar arrayLikeToArray = __webpack_require__(520);\n\nfunction _unsupportedIterableToArray(o, minLen) {\n var _context;\n\n if (!o) return;\n if (typeof o === \"string\") return arrayLikeToArray(o, minLen);\n\n var n = _sliceInstanceProperty(_context = Object.prototype.toString.call(o)).call(_context, 8, -1);\n\n if (n === \"Object\" && o.constructor) n = o.constructor.name;\n if (n === \"Map\" || n === \"Set\") return _Array$from(o);\n if (n === \"Arguments\" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return arrayLikeToArray(o, minLen);\n}\n\nmodule.exports = _unsupportedIterableToArray, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n/***/ }),\n/* 512 */\n/***/ (function(module, exports, __webpack_require__) {\n\nmodule.exports = __webpack_require__(513);\n\n/***/ }),\n/* 513 */\n/***/ (function(module, exports, __webpack_require__) {\n\nmodule.exports = __webpack_require__(514);\n\n\n/***/ }),\n/* 514 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar parent = __webpack_require__(515);\n\nmodule.exports = parent;\n\n\n/***/ }),\n/* 515 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar parent = __webpack_require__(222);\n\nmodule.exports = parent;\n\n\n/***/ }),\n/* 516 */\n/***/ (function(module, exports, __webpack_require__) {\n\nmodule.exports = __webpack_require__(517);\n\n/***/ }),\n/* 517 */\n/***/ (function(module, exports, __webpack_require__) {\n\nmodule.exports = __webpack_require__(518);\n\n\n/***/ }),\n/* 518 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar parent = __webpack_require__(519);\n\nmodule.exports = parent;\n\n\n/***/ }),\n/* 519 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar parent = __webpack_require__(230);\n\nmodule.exports = parent;\n\n\n/***/ }),\n/* 520 */\n/***/ (function(module, exports) {\n\nfunction _arrayLikeToArray(arr, len) {\n if (len == null || len > arr.length) len = arr.length;\n\n for (var i = 0, arr2 = new Array(len); i < len; i++) {\n arr2[i] = arr[i];\n }\n\n return arr2;\n}\n\nmodule.exports = _arrayLikeToArray, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n/***/ }),\n/* 521 */\n/***/ (function(module, exports) {\n\nfunction _nonIterableRest() {\n throw new TypeError(\"Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\");\n}\n\nmodule.exports = _nonIterableRest, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n/***/ }),\n/* 522 */\n/***/ (function(module, exports, __webpack_require__) {\n\nmodule.exports = __webpack_require__(523);\n\n/***/ }),\n/* 523 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar parent = __webpack_require__(524);\n\nmodule.exports = parent;\n\n\n/***/ }),\n/* 524 */\n/***/ (function(module, exports, __webpack_require__) {\n\n__webpack_require__(525);\nvar path = __webpack_require__(13);\n\nvar Object = path.Object;\n\nvar getOwnPropertyDescriptor = module.exports = function getOwnPropertyDescriptor(it, key) {\n return Object.getOwnPropertyDescriptor(it, key);\n};\n\nif (Object.getOwnPropertyDescriptor.sham) getOwnPropertyDescriptor.sham = true;\n\n\n/***/ }),\n/* 525 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar $ = __webpack_require__(0);\nvar fails = __webpack_require__(4);\nvar toIndexedObject = __webpack_require__(33);\nvar nativeGetOwnPropertyDescriptor = __webpack_require__(64).f;\nvar DESCRIPTORS = __webpack_require__(19);\n\nvar FAILS_ON_PRIMITIVES = fails(function () { nativeGetOwnPropertyDescriptor(1); });\nvar FORCED = !DESCRIPTORS || FAILS_ON_PRIMITIVES;\n\n// `Object.getOwnPropertyDescriptor` method\n// https://tc39.es/ecma262/#sec-object.getownpropertydescriptor\n$({ target: 'Object', stat: true, forced: FORCED, sham: !DESCRIPTORS }, {\n getOwnPropertyDescriptor: function getOwnPropertyDescriptor(it, key) {\n return nativeGetOwnPropertyDescriptor(toIndexedObject(it), key);\n }\n});\n\n\n/***/ }),\n/* 526 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\n\nvar _ = __webpack_require__(1);\n\nvar AVError = __webpack_require__(40);\n\nmodule.exports = function (AV) {\n AV.Role = AV.Object.extend('_Role',\n /** @lends AV.Role.prototype */\n {\n // Instance Methods\n\n /**\n * Represents a Role on the AV server. Roles represent groupings of\n * Users for the purposes of granting permissions (e.g. specifying an ACL\n * for an Object). Roles are specified by their sets of child users and\n * child roles, all of which are granted any permissions that the parent\n * role has.\n *\n *
Roles must have a name (which cannot be changed after creation of the\n * role), and must specify an ACL.
\n * An AV.Role is a local representation of a role persisted to the AV\n * cloud.\n * @class AV.Role\n * @param {String} name The name of the Role to create.\n * @param {AV.ACL} acl The ACL for this role.\n */\n constructor: function constructor(name, acl) {\n if (_.isString(name)) {\n AV.Object.prototype.constructor.call(this, null, null);\n this.setName(name);\n } else {\n AV.Object.prototype.constructor.call(this, name, acl);\n }\n\n if (acl) {\n if (!(acl instanceof AV.ACL)) {\n throw new TypeError('acl must be an instance of AV.ACL');\n } else {\n this.setACL(acl);\n }\n }\n },\n\n /**\n * Gets the name of the role. You can alternatively call role.get(\"name\")\n *\n * @return {String} the name of the role.\n */\n getName: function getName() {\n return this.get('name');\n },\n\n /**\n * Sets the name for a role. This value must be set before the role has\n * been saved to the server, and cannot be set once the role has been\n * saved.\n *\n *
\n * A role's name can only contain alphanumeric characters, _, -, and\n * spaces.\n *
\n *\n *
This is equivalent to calling role.set(\"name\", name)
\n *\n * @param {String} name The name of the role.\n */\n setName: function setName(name, options) {\n return this.set('name', name, options);\n },\n\n /**\n * Gets the AV.Relation for the AV.Users that are direct\n * children of this role. These users are granted any privileges that this\n * role has been granted (e.g. read or write access through ACLs). You can\n * add or remove users from the role through this relation.\n *\n *
This is equivalent to calling role.relation(\"users\")
\n *\n * @return {AV.Relation} the relation for the users belonging to this\n * role.\n */\n getUsers: function getUsers() {\n return this.relation('users');\n },\n\n /**\n * Gets the AV.Relation for the AV.Roles that are direct\n * children of this role. These roles' users are granted any privileges that\n * this role has been granted (e.g. read or write access through ACLs). You\n * can add or remove child roles from this role through this relation.\n *\n *
This is equivalent to calling role.relation(\"roles\")
\n *\n * @return {AV.Relation} the relation for the roles belonging to this\n * role.\n */\n getRoles: function getRoles() {\n return this.relation('roles');\n },\n\n /**\n * @ignore\n */\n validate: function validate(attrs, options) {\n if ('name' in attrs && attrs.name !== this.getName()) {\n var newName = attrs.name;\n\n if (this.id && this.id !== attrs.objectId) {\n // Check to see if the objectId being set matches this.id.\n // This happens during a fetch -- the id is set before calling fetch.\n // Let the name be set in this case.\n return new AVError(AVError.OTHER_CAUSE, \"A role's name can only be set before it has been saved.\");\n }\n\n if (!_.isString(newName)) {\n return new AVError(AVError.OTHER_CAUSE, \"A role's name must be a String.\");\n }\n\n if (!/^[0-9a-zA-Z\\-_ ]+$/.test(newName)) {\n return new AVError(AVError.OTHER_CAUSE, \"A role's name can only contain alphanumeric characters, _,\" + ' -, and spaces.');\n }\n }\n\n if (AV.Object.prototype.validate) {\n return AV.Object.prototype.validate.call(this, attrs, options);\n }\n\n return false;\n }\n });\n};\n\n/***/ }),\n/* 527 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\n\nvar _interopRequireDefault = __webpack_require__(2);\n\nvar _defineProperty2 = _interopRequireDefault(__webpack_require__(528));\n\nvar _promise = _interopRequireDefault(__webpack_require__(10));\n\nvar _map = _interopRequireDefault(__webpack_require__(39));\n\nvar _find = _interopRequireDefault(__webpack_require__(104));\n\nvar _stringify = _interopRequireDefault(__webpack_require__(34));\n\nvar _ = __webpack_require__(1);\n\nvar uuid = __webpack_require__(214);\n\nvar AVError = __webpack_require__(40);\n\nvar _require = __webpack_require__(25),\n AVRequest = _require._request,\n request = _require.request;\n\nvar _require2 = __webpack_require__(61),\n getAdapter = _require2.getAdapter;\n\nvar PLATFORM_ANONYMOUS = 'anonymous';\nvar PLATFORM_QQAPP = 'lc_qqapp';\n\nvar mergeUnionDataIntoAuthData = function mergeUnionDataIntoAuthData() {\n var defaultUnionIdPlatform = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'weixin';\n return function (authData, unionId) {\n var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},\n _ref$unionIdPlatform = _ref.unionIdPlatform,\n unionIdPlatform = _ref$unionIdPlatform === void 0 ? defaultUnionIdPlatform : _ref$unionIdPlatform,\n _ref$asMainAccount = _ref.asMainAccount,\n asMainAccount = _ref$asMainAccount === void 0 ? false : _ref$asMainAccount;\n\n if (typeof unionId !== 'string') throw new AVError(AVError.OTHER_CAUSE, 'unionId is not a string');\n if (typeof unionIdPlatform !== 'string') throw new AVError(AVError.OTHER_CAUSE, 'unionIdPlatform is not a string');\n return _.extend({}, authData, {\n platform: unionIdPlatform,\n unionid: unionId,\n main_account: Boolean(asMainAccount)\n });\n };\n};\n\nmodule.exports = function (AV) {\n /**\n * @class\n *\n *
An AV.User object is a local representation of a user persisted to the\n * LeanCloud server. This class is a subclass of an AV.Object, and retains the\n * same functionality of an AV.Object, but also extends it with various\n * user specific methods, like authentication, signing up, and validation of\n * uniqueness.
\n */\n AV.User = AV.Object.extend('_User',\n /** @lends AV.User.prototype */\n {\n // Instance Variables\n _isCurrentUser: false,\n // Instance Methods\n\n /**\n * Internal method to handle special fields in a _User response.\n * @private\n */\n _mergeMagicFields: function _mergeMagicFields(attrs) {\n if (attrs.sessionToken) {\n this._sessionToken = attrs.sessionToken;\n delete attrs.sessionToken;\n }\n\n return AV.User.__super__._mergeMagicFields.call(this, attrs);\n },\n\n /**\n * Removes null values from authData (which exist temporarily for\n * unlinking)\n * @private\n */\n _cleanupAuthData: function _cleanupAuthData() {\n if (!this.isCurrent()) {\n return;\n }\n\n var authData = this.get('authData');\n\n if (!authData) {\n return;\n }\n\n AV._objectEach(this.get('authData'), function (value, key) {\n if (!authData[key]) {\n delete authData[key];\n }\n });\n },\n\n /**\n * Synchronizes authData for all providers.\n * @private\n */\n _synchronizeAllAuthData: function _synchronizeAllAuthData() {\n var authData = this.get('authData');\n\n if (!authData) {\n return;\n }\n\n var self = this;\n\n AV._objectEach(this.get('authData'), function (value, key) {\n self._synchronizeAuthData(key);\n });\n },\n\n /**\n * Synchronizes auth data for a provider (e.g. puts the access token in the\n * right place to be used by the Facebook SDK).\n * @private\n */\n _synchronizeAuthData: function _synchronizeAuthData(provider) {\n if (!this.isCurrent()) {\n return;\n }\n\n var authType;\n\n if (_.isString(provider)) {\n authType = provider;\n provider = AV.User._authProviders[authType];\n } else {\n authType = provider.getAuthType();\n }\n\n var authData = this.get('authData');\n\n if (!authData || !provider) {\n return;\n }\n\n var success = provider.restoreAuthentication(authData[authType]);\n\n if (!success) {\n this.dissociateAuthData(provider);\n }\n },\n _handleSaveResult: function _handleSaveResult(makeCurrent) {\n // Clean up and synchronize the authData object, removing any unset values\n if (makeCurrent && !AV._config.disableCurrentUser) {\n this._isCurrentUser = true;\n }\n\n this._cleanupAuthData();\n\n this._synchronizeAllAuthData(); // Don't keep the password around.\n\n\n delete this._serverData.password;\n\n this._rebuildEstimatedDataForKey('password');\n\n this._refreshCache();\n\n if ((makeCurrent || this.isCurrent()) && !AV._config.disableCurrentUser) {\n // Some old version of leanengine-node-sdk will overwrite\n // AV.User._saveCurrentUser which returns no Promise.\n // So we need a Promise wrapper.\n return _promise.default.resolve(AV.User._saveCurrentUser(this));\n } else {\n return _promise.default.resolve();\n }\n },\n\n /**\n * Unlike in the Android/iOS SDKs, logInWith is unnecessary, since you can\n * call linkWith on the user (even if it doesn't exist yet on the server).\n * @private\n */\n _linkWith: function _linkWith(provider, data) {\n var _this = this;\n\n var _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},\n _ref2$failOnNotExist = _ref2.failOnNotExist,\n failOnNotExist = _ref2$failOnNotExist === void 0 ? false : _ref2$failOnNotExist,\n useMasterKey = _ref2.useMasterKey,\n sessionToken = _ref2.sessionToken,\n user = _ref2.user;\n\n var authType;\n\n if (_.isString(provider)) {\n authType = provider;\n provider = AV.User._authProviders[provider];\n } else {\n authType = provider.getAuthType();\n }\n\n if (data) {\n return this.save({\n authData: (0, _defineProperty2.default)({}, authType, data)\n }, {\n useMasterKey: useMasterKey,\n sessionToken: sessionToken,\n user: user,\n fetchWhenSave: !!this.get('authData'),\n _failOnNotExist: failOnNotExist\n }).then(function (model) {\n return model._handleSaveResult(true).then(function () {\n return model;\n });\n });\n } else {\n return provider.authenticate().then(function (result) {\n return _this._linkWith(provider, result);\n });\n }\n },\n\n /**\n * Associate the user with a third party authData.\n * @since 3.3.0\n * @param {Object} authData The response json data returned from third party token, maybe like { openid: 'abc123', access_token: '123abc', expires_in: 1382686496 }\n * @param {string} platform Available platform for sign up.\n * @return {Promise} A promise that is fulfilled with the user when completed.\n * @example user.associateWithAuthData({\n * openid: 'abc123',\n * access_token: '123abc',\n * expires_in: 1382686496\n * }, 'weixin').then(function(user) {\n * //Access user here\n * }).catch(function(error) {\n * //console.error(\"error: \", error);\n * });\n */\n associateWithAuthData: function associateWithAuthData(authData, platform) {\n return this._linkWith(platform, authData);\n },\n\n /**\n * Associate the user with a third party authData and unionId.\n * @since 3.5.0\n * @param {Object} authData The response json data returned from third party token, maybe like { openid: 'abc123', access_token: '123abc', expires_in: 1382686496 }\n * @param {string} platform Available platform for sign up.\n * @param {string} unionId\n * @param {Object} [unionLoginOptions]\n * @param {string} [unionLoginOptions.unionIdPlatform = 'weixin'] unionId platform\n * @param {boolean} [unionLoginOptions.asMainAccount = false] If true, the unionId will be associated with the user.\n * @return {Promise} A promise that is fulfilled with the user when completed.\n * @example user.associateWithAuthDataAndUnionId({\n * openid: 'abc123',\n * access_token: '123abc',\n * expires_in: 1382686496\n * }, 'weixin', 'union123', {\n * unionIdPlatform: 'weixin',\n * asMainAccount: true,\n * }).then(function(user) {\n * //Access user here\n * }).catch(function(error) {\n * //console.error(\"error: \", error);\n * });\n */\n associateWithAuthDataAndUnionId: function associateWithAuthDataAndUnionId(authData, platform, unionId, unionOptions) {\n return this._linkWith(platform, mergeUnionDataIntoAuthData()(authData, unionId, unionOptions));\n },\n\n /**\n * Associate the user with the identity of the current mini-app.\n * @since 4.6.0\n * @param {Object} [authInfo]\n * @param {Object} [option]\n * @param {Boolean} [option.failOnNotExist] If true, the login request will fail when no user matches this authInfo.authData exists.\n * @return {Promise}\n */\n associateWithMiniApp: function associateWithMiniApp(authInfo, option) {\n var _this2 = this;\n\n if (authInfo === undefined) {\n var getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo().then(function (authInfo) {\n return _this2._linkWith(authInfo.provider, authInfo.authData, option);\n });\n }\n\n return this._linkWith(authInfo.provider, authInfo.authData, option);\n },\n\n /**\n * 将用户与 QQ 小程序用户进行关联。适用于为已经在用户系统中存在的用户关联当前使用 QQ 小程序的微信帐号。\n * 仅在 QQ 小程序中可用。\n *\n * @deprecated Please use {@link AV.User#associateWithMiniApp}\n * @since 4.2.0\n * @param {Object} [options]\n * @param {boolean} [options.preferUnionId = false] 如果服务端在登录时获取到了用户的 UnionId,是否将 UnionId 保存在用户账号中。\n * @param {string} [options.unionIdPlatform = 'qq'] (only take effect when preferUnionId) unionId platform\n * @param {boolean} [options.asMainAccount = true] (only take effect when preferUnionId) If true, the unionId will be associated with the user.\n * @return {Promise}\n */\n associateWithQQApp: function associateWithQQApp() {\n var _this3 = this;\n\n var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\n _ref3$preferUnionId = _ref3.preferUnionId,\n preferUnionId = _ref3$preferUnionId === void 0 ? false : _ref3$preferUnionId,\n _ref3$unionIdPlatform = _ref3.unionIdPlatform,\n unionIdPlatform = _ref3$unionIdPlatform === void 0 ? 'qq' : _ref3$unionIdPlatform,\n _ref3$asMainAccount = _ref3.asMainAccount,\n asMainAccount = _ref3$asMainAccount === void 0 ? true : _ref3$asMainAccount;\n\n var getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo({\n preferUnionId: preferUnionId,\n asMainAccount: asMainAccount,\n platform: unionIdPlatform\n }).then(function (authInfo) {\n authInfo.provider = PLATFORM_QQAPP;\n return _this3.associateWithMiniApp(authInfo);\n });\n },\n\n /**\n * 将用户与微信小程序用户进行关联。适用于为已经在用户系统中存在的用户关联当前使用微信小程序的微信帐号。\n * 仅在微信小程序中可用。\n *\n * @deprecated Please use {@link AV.User#associateWithMiniApp}\n * @since 3.13.0\n * @param {Object} [options]\n * @param {boolean} [options.preferUnionId = false] 当用户满足 {@link https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/union-id.html 获取 UnionId 的条件} 时,是否将 UnionId 保存在用户账号中。\n * @param {string} [options.unionIdPlatform = 'weixin'] (only take effect when preferUnionId) unionId platform\n * @param {boolean} [options.asMainAccount = true] (only take effect when preferUnionId) If true, the unionId will be associated with the user.\n * @return {Promise}\n */\n associateWithWeapp: function associateWithWeapp() {\n var _this4 = this;\n\n var _ref4 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\n _ref4$preferUnionId = _ref4.preferUnionId,\n preferUnionId = _ref4$preferUnionId === void 0 ? false : _ref4$preferUnionId,\n _ref4$unionIdPlatform = _ref4.unionIdPlatform,\n unionIdPlatform = _ref4$unionIdPlatform === void 0 ? 'weixin' : _ref4$unionIdPlatform,\n _ref4$asMainAccount = _ref4.asMainAccount,\n asMainAccount = _ref4$asMainAccount === void 0 ? true : _ref4$asMainAccount;\n\n var getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo({\n preferUnionId: preferUnionId,\n asMainAccount: asMainAccount,\n platform: unionIdPlatform\n }).then(function (authInfo) {\n return _this4.associateWithMiniApp(authInfo);\n });\n },\n\n /**\n * @deprecated renamed to {@link AV.User#associateWithWeapp}\n * @return {Promise}\n */\n linkWithWeapp: function linkWithWeapp(options) {\n console.warn('DEPRECATED: User#linkWithWeapp 已废弃,请使用 User#associateWithWeapp 代替');\n return this.associateWithWeapp(options);\n },\n\n /**\n * 将用户与 QQ 小程序用户进行关联。适用于为已经在用户系统中存在的用户关联当前使用 QQ 小程序的 QQ 帐号。\n * 仅在 QQ 小程序中可用。\n *\n * @deprecated Please use {@link AV.User#associateWithMiniApp}\n * @since 4.2.0\n * @param {string} unionId\n * @param {Object} [unionOptions]\n * @param {string} [unionOptions.unionIdPlatform = 'qq'] unionId platform\n * @param {boolean} [unionOptions.asMainAccount = false] If true, the unionId will be associated with the user.\n * @return {Promise}\n */\n associateWithQQAppWithUnionId: function associateWithQQAppWithUnionId(unionId) {\n var _this5 = this;\n\n var _ref5 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},\n _ref5$unionIdPlatform = _ref5.unionIdPlatform,\n unionIdPlatform = _ref5$unionIdPlatform === void 0 ? 'qq' : _ref5$unionIdPlatform,\n _ref5$asMainAccount = _ref5.asMainAccount,\n asMainAccount = _ref5$asMainAccount === void 0 ? false : _ref5$asMainAccount;\n\n var getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo({\n platform: unionIdPlatform\n }).then(function (authInfo) {\n authInfo = AV.User.mergeUnionId(authInfo, unionId, {\n asMainAccount: asMainAccount\n });\n authInfo.provider = PLATFORM_QQAPP;\n return _this5.associateWithMiniApp(authInfo);\n });\n },\n\n /**\n * 将用户与微信小程序用户进行关联。适用于为已经在用户系统中存在的用户关联当前使用微信小程序的微信帐号。\n * 仅在微信小程序中可用。\n *\n * @deprecated Please use {@link AV.User#associateWithMiniApp}\n * @since 3.13.0\n * @param {string} unionId\n * @param {Object} [unionOptions]\n * @param {string} [unionOptions.unionIdPlatform = 'weixin'] unionId platform\n * @param {boolean} [unionOptions.asMainAccount = false] If true, the unionId will be associated with the user.\n * @return {Promise}\n */\n associateWithWeappWithUnionId: function associateWithWeappWithUnionId(unionId) {\n var _this6 = this;\n\n var _ref6 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},\n _ref6$unionIdPlatform = _ref6.unionIdPlatform,\n unionIdPlatform = _ref6$unionIdPlatform === void 0 ? 'weixin' : _ref6$unionIdPlatform,\n _ref6$asMainAccount = _ref6.asMainAccount,\n asMainAccount = _ref6$asMainAccount === void 0 ? false : _ref6$asMainAccount;\n\n var getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo({\n platform: unionIdPlatform\n }).then(function (authInfo) {\n authInfo = AV.User.mergeUnionId(authInfo, unionId, {\n asMainAccount: asMainAccount\n });\n return _this6.associateWithMiniApp(authInfo);\n });\n },\n\n /**\n * Unlinks a user from a service.\n * @param {string} platform\n * @return {Promise}\n * @since 3.3.0\n */\n dissociateAuthData: function dissociateAuthData(provider) {\n this.unset(\"authData.\".concat(provider));\n return this.save().then(function (model) {\n return model._handleSaveResult(true).then(function () {\n return model;\n });\n });\n },\n\n /**\n * @private\n * @deprecated\n */\n _unlinkFrom: function _unlinkFrom(provider) {\n console.warn('DEPRECATED: User#_unlinkFrom 已废弃,请使用 User#dissociateAuthData 代替');\n return this.dissociateAuthData(provider);\n },\n\n /**\n * Checks whether a user is linked to a service.\n * @private\n */\n _isLinked: function _isLinked(provider) {\n var authType;\n\n if (_.isString(provider)) {\n authType = provider;\n } else {\n authType = provider.getAuthType();\n }\n\n var authData = this.get('authData') || {};\n return !!authData[authType];\n },\n\n /**\n * Checks whether a user is anonymous.\n * @since 3.9.0\n * @return {boolean}\n */\n isAnonymous: function isAnonymous() {\n return this._isLinked(PLATFORM_ANONYMOUS);\n },\n logOut: function logOut() {\n this._logOutWithAll();\n\n this._isCurrentUser = false;\n },\n\n /**\n * Deauthenticates all providers.\n * @private\n */\n _logOutWithAll: function _logOutWithAll() {\n var authData = this.get('authData');\n\n if (!authData) {\n return;\n }\n\n var self = this;\n\n AV._objectEach(this.get('authData'), function (value, key) {\n self._logOutWith(key);\n });\n },\n\n /**\n * Deauthenticates a single provider (e.g. removing access tokens from the\n * Facebook SDK).\n * @private\n */\n _logOutWith: function _logOutWith(provider) {\n if (!this.isCurrent()) {\n return;\n }\n\n if (_.isString(provider)) {\n provider = AV.User._authProviders[provider];\n }\n\n if (provider && provider.deauthenticate) {\n provider.deauthenticate();\n }\n },\n\n /**\n * Signs up a new user. You should call this instead of save for\n * new AV.Users. This will create a new AV.User on the server, and\n * also persist the session on disk so that you can access the user using\n * current.\n *\n *
A username and password must be set before calling signUp.
\n *\n * @param {Object} attrs Extra fields to set on the new user, or null.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled when the signup\n * finishes.\n * @see AV.User.signUp\n */\n signUp: function signUp(attrs, options) {\n var error;\n var username = attrs && attrs.username || this.get('username');\n\n if (!username || username === '') {\n error = new AVError(AVError.OTHER_CAUSE, 'Cannot sign up user with an empty name.');\n throw error;\n }\n\n var password = attrs && attrs.password || this.get('password');\n\n if (!password || password === '') {\n error = new AVError(AVError.OTHER_CAUSE, 'Cannot sign up user with an empty password.');\n throw error;\n }\n\n return this.save(attrs, options).then(function (model) {\n if (model.isAnonymous()) {\n model.unset(\"authData.\".concat(PLATFORM_ANONYMOUS));\n model._opSetQueue = [{}];\n }\n\n return model._handleSaveResult(true).then(function () {\n return model;\n });\n });\n },\n\n /**\n * Signs up a new user with mobile phone and sms code.\n * You should call this instead of save for\n * new AV.Users. This will create a new AV.User on the server, and\n * also persist the session on disk so that you can access the user using\n * current.\n *\n *
A username and password must be set before calling signUp.
\n *\n * @param {Object} attrs Extra fields to set on the new user, or null.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled when the signup\n * finishes.\n * @see AV.User.signUpOrlogInWithMobilePhone\n * @see AV.Cloud.requestSmsCode\n */\n signUpOrlogInWithMobilePhone: function signUpOrlogInWithMobilePhone(attrs) {\n var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n var error;\n var mobilePhoneNumber = attrs && attrs.mobilePhoneNumber || this.get('mobilePhoneNumber');\n\n if (!mobilePhoneNumber || mobilePhoneNumber === '') {\n error = new AVError(AVError.OTHER_CAUSE, 'Cannot sign up or login user by mobilePhoneNumber ' + 'with an empty mobilePhoneNumber.');\n throw error;\n }\n\n var smsCode = attrs && attrs.smsCode || this.get('smsCode');\n\n if (!smsCode || smsCode === '') {\n error = new AVError(AVError.OTHER_CAUSE, 'Cannot sign up or login user by mobilePhoneNumber ' + 'with an empty smsCode.');\n throw error;\n }\n\n options._makeRequest = function (route, className, id, method, json) {\n return AVRequest('usersByMobilePhone', null, null, 'POST', json);\n };\n\n return this.save(attrs, options).then(function (model) {\n delete model.attributes.smsCode;\n delete model._serverData.smsCode;\n return model._handleSaveResult(true).then(function () {\n return model;\n });\n });\n },\n\n /**\n * The same with {@link AV.User.loginWithAuthData}, except that you can set attributes before login.\n * @since 3.7.0\n */\n loginWithAuthData: function loginWithAuthData(authData, platform, options) {\n return this._linkWith(platform, authData, options);\n },\n\n /**\n * The same with {@link AV.User.loginWithAuthDataAndUnionId}, except that you can set attributes before login.\n * @since 3.7.0\n */\n loginWithAuthDataAndUnionId: function loginWithAuthDataAndUnionId(authData, platform, unionId, unionLoginOptions) {\n return this.loginWithAuthData(mergeUnionDataIntoAuthData()(authData, unionId, unionLoginOptions), platform, unionLoginOptions);\n },\n\n /**\n * The same with {@link AV.User.loginWithWeapp}, except that you can set attributes before login.\n * @deprecated please use {@link AV.User#loginWithMiniApp}\n * @since 3.7.0\n * @param {Object} [options]\n * @param {boolean} [options.failOnNotExist] If true, the login request will fail when no user matches this authData exists.\n * @param {boolean} [options.preferUnionId] 当用户满足 {@link https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/union-id.html 获取 UnionId 的条件} 时,是否使用 UnionId 登录。(since 3.13.0)\n * @param {string} [options.unionIdPlatform = 'weixin'] (only take effect when preferUnionId) unionId platform\n * @param {boolean} [options.asMainAccount = true] (only take effect when preferUnionId) If true, the unionId will be associated with the user.\n * @return {Promise}\n */\n loginWithWeapp: function loginWithWeapp() {\n var _this7 = this;\n\n var _ref7 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\n _ref7$preferUnionId = _ref7.preferUnionId,\n preferUnionId = _ref7$preferUnionId === void 0 ? false : _ref7$preferUnionId,\n _ref7$unionIdPlatform = _ref7.unionIdPlatform,\n unionIdPlatform = _ref7$unionIdPlatform === void 0 ? 'weixin' : _ref7$unionIdPlatform,\n _ref7$asMainAccount = _ref7.asMainAccount,\n asMainAccount = _ref7$asMainAccount === void 0 ? true : _ref7$asMainAccount,\n _ref7$failOnNotExist = _ref7.failOnNotExist,\n failOnNotExist = _ref7$failOnNotExist === void 0 ? false : _ref7$failOnNotExist,\n useMasterKey = _ref7.useMasterKey,\n sessionToken = _ref7.sessionToken,\n user = _ref7.user;\n\n var getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo({\n preferUnionId: preferUnionId,\n asMainAccount: asMainAccount,\n platform: unionIdPlatform\n }).then(function (authInfo) {\n return _this7.loginWithMiniApp(authInfo, {\n failOnNotExist: failOnNotExist,\n useMasterKey: useMasterKey,\n sessionToken: sessionToken,\n user: user\n });\n });\n },\n\n /**\n * The same with {@link AV.User.loginWithWeappWithUnionId}, except that you can set attributes before login.\n * @deprecated please use {@link AV.User#loginWithMiniApp}\n * @since 3.13.0\n */\n loginWithWeappWithUnionId: function loginWithWeappWithUnionId(unionId) {\n var _this8 = this;\n\n var _ref8 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},\n _ref8$unionIdPlatform = _ref8.unionIdPlatform,\n unionIdPlatform = _ref8$unionIdPlatform === void 0 ? 'weixin' : _ref8$unionIdPlatform,\n _ref8$asMainAccount = _ref8.asMainAccount,\n asMainAccount = _ref8$asMainAccount === void 0 ? false : _ref8$asMainAccount,\n _ref8$failOnNotExist = _ref8.failOnNotExist,\n failOnNotExist = _ref8$failOnNotExist === void 0 ? false : _ref8$failOnNotExist,\n useMasterKey = _ref8.useMasterKey,\n sessionToken = _ref8.sessionToken,\n user = _ref8.user;\n\n var getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo({\n platform: unionIdPlatform\n }).then(function (authInfo) {\n authInfo = AV.User.mergeUnionId(authInfo, unionId, {\n asMainAccount: asMainAccount\n });\n return _this8.loginWithMiniApp(authInfo, {\n failOnNotExist: failOnNotExist,\n useMasterKey: useMasterKey,\n sessionToken: sessionToken,\n user: user\n });\n });\n },\n\n /**\n * The same with {@link AV.User.loginWithQQApp}, except that you can set attributes before login.\n * @deprecated please use {@link AV.User#loginWithMiniApp}\n * @since 4.2.0\n * @param {Object} [options]\n * @param {boolean} [options.failOnNotExist] If true, the login request will fail when no user matches this authData exists.\n * @param {boolean} [options.preferUnionId] 如果服务端在登录时获取到了用户的 UnionId,是否将 UnionId 保存在用户账号中。\n * @param {string} [options.unionIdPlatform = 'qq'] (only take effect when preferUnionId) unionId platform\n * @param {boolean} [options.asMainAccount = true] (only take effect when preferUnionId) If true, the unionId will be associated with the user.\n */\n loginWithQQApp: function loginWithQQApp() {\n var _this9 = this;\n\n var _ref9 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\n _ref9$preferUnionId = _ref9.preferUnionId,\n preferUnionId = _ref9$preferUnionId === void 0 ? false : _ref9$preferUnionId,\n _ref9$unionIdPlatform = _ref9.unionIdPlatform,\n unionIdPlatform = _ref9$unionIdPlatform === void 0 ? 'qq' : _ref9$unionIdPlatform,\n _ref9$asMainAccount = _ref9.asMainAccount,\n asMainAccount = _ref9$asMainAccount === void 0 ? true : _ref9$asMainAccount,\n _ref9$failOnNotExist = _ref9.failOnNotExist,\n failOnNotExist = _ref9$failOnNotExist === void 0 ? false : _ref9$failOnNotExist,\n useMasterKey = _ref9.useMasterKey,\n sessionToken = _ref9.sessionToken,\n user = _ref9.user;\n\n var getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo({\n preferUnionId: preferUnionId,\n asMainAccount: asMainAccount,\n platform: unionIdPlatform\n }).then(function (authInfo) {\n authInfo.provider = PLATFORM_QQAPP;\n return _this9.loginWithMiniApp(authInfo, {\n failOnNotExist: failOnNotExist,\n useMasterKey: useMasterKey,\n sessionToken: sessionToken,\n user: user\n });\n });\n },\n\n /**\n * The same with {@link AV.User.loginWithQQAppWithUnionId}, except that you can set attributes before login.\n * @deprecated please use {@link AV.User#loginWithMiniApp}\n * @since 4.2.0\n */\n loginWithQQAppWithUnionId: function loginWithQQAppWithUnionId(unionId) {\n var _this10 = this;\n\n var _ref10 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},\n _ref10$unionIdPlatfor = _ref10.unionIdPlatform,\n unionIdPlatform = _ref10$unionIdPlatfor === void 0 ? 'qq' : _ref10$unionIdPlatfor,\n _ref10$asMainAccount = _ref10.asMainAccount,\n asMainAccount = _ref10$asMainAccount === void 0 ? false : _ref10$asMainAccount,\n _ref10$failOnNotExist = _ref10.failOnNotExist,\n failOnNotExist = _ref10$failOnNotExist === void 0 ? false : _ref10$failOnNotExist,\n useMasterKey = _ref10.useMasterKey,\n sessionToken = _ref10.sessionToken,\n user = _ref10.user;\n\n var getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo({\n platform: unionIdPlatform\n }).then(function (authInfo) {\n authInfo = AV.User.mergeUnionId(authInfo, unionId, {\n asMainAccount: asMainAccount\n });\n authInfo.provider = PLATFORM_QQAPP;\n return _this10.loginWithMiniApp(authInfo, {\n failOnNotExist: failOnNotExist,\n useMasterKey: useMasterKey,\n sessionToken: sessionToken,\n user: user\n });\n });\n },\n\n /**\n * The same with {@link AV.User.loginWithMiniApp}, except that you can set attributes before login.\n * @since 4.6.0\n */\n loginWithMiniApp: function loginWithMiniApp(authInfo, option) {\n var _this11 = this;\n\n if (authInfo === undefined) {\n var getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo().then(function (authInfo) {\n return _this11.loginWithAuthData(authInfo.authData, authInfo.provider, option);\n });\n }\n\n return this.loginWithAuthData(authInfo.authData, authInfo.provider, option);\n },\n\n /**\n * Logs in a AV.User. On success, this saves the session to localStorage,\n * so you can retrieve the currently logged in user using\n * current.\n *\n *
A username and password must be set before calling logIn.
\n *\n * @see AV.User.logIn\n * @return {Promise} A promise that is fulfilled with the user when\n * the login is complete.\n */\n logIn: function logIn() {\n var model = this;\n var request = AVRequest('login', null, null, 'POST', this.toJSON());\n return request.then(function (resp) {\n var serverAttrs = model.parse(resp);\n\n model._finishFetch(serverAttrs);\n\n return model._handleSaveResult(true).then(function () {\n if (!serverAttrs.smsCode) delete model.attributes['smsCode'];\n return model;\n });\n });\n },\n\n /**\n * @see AV.Object#save\n */\n save: function save(arg1, arg2, arg3) {\n var attrs, options;\n\n if (_.isObject(arg1) || _.isNull(arg1) || _.isUndefined(arg1)) {\n attrs = arg1;\n options = arg2;\n } else {\n attrs = {};\n attrs[arg1] = arg2;\n options = arg3;\n }\n\n options = options || {};\n return AV.Object.prototype.save.call(this, attrs, options).then(function (model) {\n return model._handleSaveResult(false).then(function () {\n return model;\n });\n });\n },\n\n /**\n * Follow a user\n * @since 0.3.0\n * @param {Object | AV.User | String} options if an AV.User or string is given, it will be used as the target user.\n * @param {AV.User | String} options.user The target user or user's objectId to follow.\n * @param {Object} [options.attributes] key-value attributes dictionary to be used as\n * conditions of followerQuery/followeeQuery.\n * @param {AuthOptions} [authOptions]\n */\n follow: function follow(options, authOptions) {\n if (!this.id) {\n throw new Error('Please signin.');\n }\n\n var user;\n var attributes;\n\n if (options.user) {\n user = options.user;\n attributes = options.attributes;\n } else {\n user = options;\n }\n\n var userObjectId = _.isString(user) ? user : user.id;\n\n if (!userObjectId) {\n throw new Error('Invalid target user.');\n }\n\n var route = 'users/' + this.id + '/friendship/' + userObjectId;\n var request = AVRequest(route, null, null, 'POST', AV._encode(attributes), authOptions);\n return request;\n },\n\n /**\n * Unfollow a user.\n * @since 0.3.0\n * @param {Object | AV.User | String} options if an AV.User or string is given, it will be used as the target user.\n * @param {AV.User | String} options.user The target user or user's objectId to unfollow.\n * @param {AuthOptions} [authOptions]\n */\n unfollow: function unfollow(options, authOptions) {\n if (!this.id) {\n throw new Error('Please signin.');\n }\n\n var user;\n\n if (options.user) {\n user = options.user;\n } else {\n user = options;\n }\n\n var userObjectId = _.isString(user) ? user : user.id;\n\n if (!userObjectId) {\n throw new Error('Invalid target user.');\n }\n\n var route = 'users/' + this.id + '/friendship/' + userObjectId;\n var request = AVRequest(route, null, null, 'DELETE', null, authOptions);\n return request;\n },\n\n /**\n * Get the user's followers and followees.\n * @since 4.8.0\n * @param {Object} [options]\n * @param {Number} [options.skip]\n * @param {Number} [options.limit]\n * @param {AuthOptions} [authOptions]\n */\n getFollowersAndFollowees: function getFollowersAndFollowees(options, authOptions) {\n if (!this.id) {\n throw new Error('Please signin.');\n }\n\n return request({\n method: 'GET',\n path: \"/users/\".concat(this.id, \"/followersAndFollowees\"),\n query: {\n skip: options && options.skip,\n limit: options && options.limit,\n include: 'follower,followee',\n keys: 'follower,followee'\n },\n authOptions: authOptions\n }).then(function (_ref11) {\n var followers = _ref11.followers,\n followees = _ref11.followees;\n return {\n followers: (0, _map.default)(followers).call(followers, function (_ref12) {\n var follower = _ref12.follower;\n return AV._decode(follower);\n }),\n followees: (0, _map.default)(followees).call(followees, function (_ref13) {\n var followee = _ref13.followee;\n return AV._decode(followee);\n })\n };\n });\n },\n\n /**\n *Create a follower query to query the user's followers.\n * @since 0.3.0\n * @see AV.User#followerQuery\n */\n followerQuery: function followerQuery() {\n return AV.User.followerQuery(this.id);\n },\n\n /**\n *Create a followee query to query the user's followees.\n * @since 0.3.0\n * @see AV.User#followeeQuery\n */\n followeeQuery: function followeeQuery() {\n return AV.User.followeeQuery(this.id);\n },\n\n /**\n * @see AV.Object#fetch\n */\n fetch: function fetch(fetchOptions, options) {\n return AV.Object.prototype.fetch.call(this, fetchOptions, options).then(function (model) {\n return model._handleSaveResult(false).then(function () {\n return model;\n });\n });\n },\n\n /**\n * Update user's new password safely based on old password.\n * @param {String} oldPassword the old password.\n * @param {String} newPassword the new password.\n * @param {AuthOptions} options\n */\n updatePassword: function updatePassword(oldPassword, newPassword, options) {\n var _this12 = this;\n\n var route = 'users/' + this.id + '/updatePassword';\n var params = {\n old_password: oldPassword,\n new_password: newPassword\n };\n var request = AVRequest(route, null, null, 'PUT', params, options);\n return request.then(function (resp) {\n _this12._finishFetch(_this12.parse(resp));\n\n return _this12._handleSaveResult(true).then(function () {\n return resp;\n });\n });\n },\n\n /**\n * Returns true if current would return this user.\n * @see AV.User#current\n */\n isCurrent: function isCurrent() {\n return this._isCurrentUser;\n },\n\n /**\n * Returns get(\"username\").\n * @return {String}\n * @see AV.Object#get\n */\n getUsername: function getUsername() {\n return this.get('username');\n },\n\n /**\n * Returns get(\"mobilePhoneNumber\").\n * @return {String}\n * @see AV.Object#get\n */\n getMobilePhoneNumber: function getMobilePhoneNumber() {\n return this.get('mobilePhoneNumber');\n },\n\n /**\n * Calls set(\"mobilePhoneNumber\", phoneNumber, options) and returns the result.\n * @param {String} mobilePhoneNumber\n * @return {Boolean}\n * @see AV.Object#set\n */\n setMobilePhoneNumber: function setMobilePhoneNumber(phone, options) {\n return this.set('mobilePhoneNumber', phone, options);\n },\n\n /**\n * Calls set(\"username\", username, options) and returns the result.\n * @param {String} username\n * @return {Boolean}\n * @see AV.Object#set\n */\n setUsername: function setUsername(username, options) {\n return this.set('username', username, options);\n },\n\n /**\n * Calls set(\"password\", password, options) and returns the result.\n * @param {String} password\n * @return {Boolean}\n * @see AV.Object#set\n */\n setPassword: function setPassword(password, options) {\n return this.set('password', password, options);\n },\n\n /**\n * Returns get(\"email\").\n * @return {String}\n * @see AV.Object#get\n */\n getEmail: function getEmail() {\n return this.get('email');\n },\n\n /**\n * Calls set(\"email\", email, options) and returns the result.\n * @param {String} email\n * @param {AuthOptions} options\n * @return {Boolean}\n * @see AV.Object#set\n */\n setEmail: function setEmail(email, options) {\n return this.set('email', email, options);\n },\n\n /**\n * Checks whether this user is the current user and has been authenticated.\n * @deprecated 如果要判断当前用户的登录状态是否有效,请使用 currentUser.isAuthenticated().then(),\n * 如果要判断该用户是否是当前登录用户,请使用 user.id === currentUser.id\n * @return (Boolean) whether this user is the current user and is logged in.\n */\n authenticated: function authenticated() {\n console.warn('DEPRECATED: 如果要判断当前用户的登录状态是否有效,请使用 currentUser.isAuthenticated().then(),如果要判断该用户是否是当前登录用户,请使用 user.id === currentUser.id。');\n return !!this._sessionToken && !AV._config.disableCurrentUser && AV.User.current() && AV.User.current().id === this.id;\n },\n\n /**\n * Detects if current sessionToken is valid.\n *\n * @since 2.0.0\n * @return Promise.\n */\n isAuthenticated: function isAuthenticated() {\n var _this13 = this;\n\n return _promise.default.resolve().then(function () {\n return !!_this13._sessionToken && AV.User._fetchUserBySessionToken(_this13._sessionToken).then(function () {\n return true;\n }, function (error) {\n if (error.code === 211) {\n return false;\n }\n\n throw error;\n });\n });\n },\n\n /**\n * Get sessionToken of current user.\n * @return {String} sessionToken\n */\n getSessionToken: function getSessionToken() {\n return this._sessionToken;\n },\n\n /**\n * Refresh sessionToken of current user.\n * @since 2.1.0\n * @param {AuthOptions} [options]\n * @return {Promise.} user with refreshed sessionToken\n */\n refreshSessionToken: function refreshSessionToken(options) {\n var _this14 = this;\n\n return AVRequest(\"users/\".concat(this.id, \"/refreshSessionToken\"), null, null, 'PUT', null, options).then(function (response) {\n _this14._finishFetch(response);\n\n return _this14._handleSaveResult(true).then(function () {\n return _this14;\n });\n });\n },\n\n /**\n * Get this user's Roles.\n * @param {AuthOptions} [options]\n * @return {Promise.} A promise that is fulfilled with the roles when\n * the query is complete.\n */\n getRoles: function getRoles(options) {\n var _context;\n\n return (0, _find.default)(_context = AV.Relation.reverseQuery('_Role', 'users', this)).call(_context, options);\n }\n },\n /** @lends AV.User */\n {\n // Class Variables\n // The currently logged-in user.\n _currentUser: null,\n // Whether currentUser is known to match the serialized version on disk.\n // This is useful for saving a localstorage check if you try to load\n // _currentUser frequently while there is none stored.\n _currentUserMatchesDisk: false,\n // The localStorage key suffix that the current user is stored under.\n _CURRENT_USER_KEY: 'currentUser',\n // The mapping of auth provider names to actual providers\n _authProviders: {},\n // Class Methods\n\n /**\n * Signs up a new user with a username (or email) and password.\n * This will create a new AV.User on the server, and also persist the\n * session in localStorage so that you can access the user using\n * {@link #current}.\n *\n * @param {String} username The username (or email) to sign up with.\n * @param {String} password The password to sign up with.\n * @param {Object} [attrs] Extra fields to set on the new user.\n * @param {AuthOptions} [options]\n * @return {Promise} A promise that is fulfilled with the user when\n * the signup completes.\n * @see AV.User#signUp\n */\n signUp: function signUp(username, password, attrs, options) {\n attrs = attrs || {};\n attrs.username = username;\n attrs.password = password;\n\n var user = AV.Object._create('_User');\n\n return user.signUp(attrs, options);\n },\n\n /**\n * Logs in a user with a username (or email) and password. On success, this\n * saves the session to disk, so you can retrieve the currently logged in\n * user using current.\n *\n * @param {String} username The username (or email) to log in with.\n * @param {String} password The password to log in with.\n * @return {Promise} A promise that is fulfilled with the user when\n * the login completes.\n * @see AV.User#logIn\n */\n logIn: function logIn(username, password) {\n var user = AV.Object._create('_User');\n\n user._finishFetch({\n username: username,\n password: password\n });\n\n return user.logIn();\n },\n\n /**\n * Logs in a user with a session token. On success, this saves the session\n * to disk, so you can retrieve the currently logged in user using\n * current.\n *\n * @param {String} sessionToken The sessionToken to log in with.\n * @return {Promise} A promise that is fulfilled with the user when\n * the login completes.\n */\n become: function become(sessionToken) {\n return this._fetchUserBySessionToken(sessionToken).then(function (user) {\n return user._handleSaveResult(true).then(function () {\n return user;\n });\n });\n },\n _fetchUserBySessionToken: function _fetchUserBySessionToken(sessionToken) {\n if (sessionToken === undefined) {\n return _promise.default.reject(new Error('The sessionToken cannot be undefined'));\n }\n\n var user = AV.Object._create('_User');\n\n return request({\n method: 'GET',\n path: '/users/me',\n authOptions: {\n sessionToken: sessionToken\n }\n }).then(function (resp) {\n var serverAttrs = user.parse(resp);\n\n user._finishFetch(serverAttrs);\n\n return user;\n });\n },\n\n /**\n * Logs in a user with a mobile phone number and sms code sent by\n * AV.User.requestLoginSmsCode.On success, this\n * saves the session to disk, so you can retrieve the currently logged in\n * user using current.\n *\n * @param {String} mobilePhone The user's mobilePhoneNumber\n * @param {String} smsCode The sms code sent by AV.User.requestLoginSmsCode\n * @return {Promise} A promise that is fulfilled with the user when\n * the login completes.\n * @see AV.User#logIn\n */\n logInWithMobilePhoneSmsCode: function logInWithMobilePhoneSmsCode(mobilePhone, smsCode) {\n var user = AV.Object._create('_User');\n\n user._finishFetch({\n mobilePhoneNumber: mobilePhone,\n smsCode: smsCode\n });\n\n return user.logIn();\n },\n\n /**\n * Signs up or logs in a user with a mobilePhoneNumber and smsCode.\n * On success, this saves the session to disk, so you can retrieve the currently\n * logged in user using current.\n *\n * @param {String} mobilePhoneNumber The user's mobilePhoneNumber.\n * @param {String} smsCode The sms code sent by AV.Cloud.requestSmsCode\n * @param {Object} attributes The user's other attributes such as username etc.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled with the user when\n * the login completes.\n * @see AV.User#signUpOrlogInWithMobilePhone\n * @see AV.Cloud.requestSmsCode\n */\n signUpOrlogInWithMobilePhone: function signUpOrlogInWithMobilePhone(mobilePhoneNumber, smsCode, attrs, options) {\n attrs = attrs || {};\n attrs.mobilePhoneNumber = mobilePhoneNumber;\n attrs.smsCode = smsCode;\n\n var user = AV.Object._create('_User');\n\n return user.signUpOrlogInWithMobilePhone(attrs, options);\n },\n\n /**\n * Logs in a user with a mobile phone number and password. On success, this\n * saves the session to disk, so you can retrieve the currently logged in\n * user using current.\n *\n * @param {String} mobilePhone The user's mobilePhoneNumber\n * @param {String} password The password to log in with.\n * @return {Promise} A promise that is fulfilled with the user when\n * the login completes.\n * @see AV.User#logIn\n */\n logInWithMobilePhone: function logInWithMobilePhone(mobilePhone, password) {\n var user = AV.Object._create('_User');\n\n user._finishFetch({\n mobilePhoneNumber: mobilePhone,\n password: password\n });\n\n return user.logIn();\n },\n\n /**\n * Logs in a user with email and password.\n *\n * @since 3.13.0\n * @param {String} email The user's email.\n * @param {String} password The password to log in with.\n * @return {Promise} A promise that is fulfilled with the user when\n * the login completes.\n */\n loginWithEmail: function loginWithEmail(email, password) {\n var user = AV.Object._create('_User');\n\n user._finishFetch({\n email: email,\n password: password\n });\n\n return user.logIn();\n },\n\n /**\n * Signs up or logs in a user with a third party auth data(AccessToken).\n * On success, this saves the session to disk, so you can retrieve the currently\n * logged in user using current.\n *\n * @since 3.7.0\n * @param {Object} authData The response json data returned from third party token, maybe like { openid: 'abc123', access_token: '123abc', expires_in: 1382686496 }\n * @param {string} platform Available platform for sign up.\n * @param {Object} [options]\n * @param {boolean} [options.failOnNotExist] If true, the login request will fail when no user matches this authData exists.\n * @return {Promise} A promise that is fulfilled with the user when\n * the login completes.\n * @example AV.User.loginWithAuthData({\n * openid: 'abc123',\n * access_token: '123abc',\n * expires_in: 1382686496\n * }, 'weixin').then(function(user) {\n * //Access user here\n * }).catch(function(error) {\n * //console.error(\"error: \", error);\n * });\n * @see {@link https://leancloud.cn/docs/js_guide.html#绑定第三方平台账户}\n */\n loginWithAuthData: function loginWithAuthData(authData, platform, options) {\n return AV.User._logInWith(platform, authData, options);\n },\n\n /**\n * @deprecated renamed to {@link AV.User.loginWithAuthData}\n */\n signUpOrlogInWithAuthData: function signUpOrlogInWithAuthData() {\n console.warn('DEPRECATED: User.signUpOrlogInWithAuthData 已废弃,请使用 User#loginWithAuthData 代替');\n return this.loginWithAuthData.apply(this, arguments);\n },\n\n /**\n * Signs up or logs in a user with a third party authData and unionId.\n * @since 3.7.0\n * @param {Object} authData The response json data returned from third party token, maybe like { openid: 'abc123', access_token: '123abc', expires_in: 1382686496 }\n * @param {string} platform Available platform for sign up.\n * @param {string} unionId\n * @param {Object} [unionLoginOptions]\n * @param {string} [unionLoginOptions.unionIdPlatform = 'weixin'] unionId platform\n * @param {boolean} [unionLoginOptions.asMainAccount = false] If true, the unionId will be associated with the user.\n * @param {boolean} [unionLoginOptions.failOnNotExist] If true, the login request will fail when no user matches this authData exists.\n * @return {Promise} A promise that is fulfilled with the user when completed.\n * @example AV.User.loginWithAuthDataAndUnionId({\n * openid: 'abc123',\n * access_token: '123abc',\n * expires_in: 1382686496\n * }, 'weixin', 'union123', {\n * unionIdPlatform: 'weixin',\n * asMainAccount: true,\n * }).then(function(user) {\n * //Access user here\n * }).catch(function(error) {\n * //console.error(\"error: \", error);\n * });\n */\n loginWithAuthDataAndUnionId: function loginWithAuthDataAndUnionId(authData, platform, unionId, unionLoginOptions) {\n return this.loginWithAuthData(mergeUnionDataIntoAuthData()(authData, unionId, unionLoginOptions), platform, unionLoginOptions);\n },\n\n /**\n * @deprecated renamed to {@link AV.User.loginWithAuthDataAndUnionId}\n * @since 3.5.0\n */\n signUpOrlogInWithAuthDataAndUnionId: function signUpOrlogInWithAuthDataAndUnionId() {\n console.warn('DEPRECATED: User.signUpOrlogInWithAuthDataAndUnionId 已废弃,请使用 User#loginWithAuthDataAndUnionId 代替');\n return this.loginWithAuthDataAndUnionId.apply(this, arguments);\n },\n\n /**\n * Merge unionId into authInfo.\n * @since 4.6.0\n * @param {Object} authInfo\n * @param {String} unionId\n * @param {Object} [unionIdOption]\n * @param {Boolean} [unionIdOption.asMainAccount] If true, the unionId will be associated with the user.\n */\n mergeUnionId: function mergeUnionId(authInfo, unionId) {\n var _ref14 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},\n _ref14$asMainAccount = _ref14.asMainAccount,\n asMainAccount = _ref14$asMainAccount === void 0 ? false : _ref14$asMainAccount;\n\n authInfo = JSON.parse((0, _stringify.default)(authInfo));\n var _authInfo = authInfo,\n authData = _authInfo.authData,\n platform = _authInfo.platform;\n authData.platform = platform;\n authData.main_account = asMainAccount;\n authData.unionid = unionId;\n return authInfo;\n },\n\n /**\n * 使用当前使用微信小程序的微信用户身份注册或登录,成功后用户的 session 会在设备上持久化保存,之后可以使用 AV.User.current() 获取当前登录用户。\n * 仅在微信小程序中可用。\n *\n * @deprecated please use {@link AV.User.loginWithMiniApp}\n * @since 2.0.0\n * @param {Object} [options]\n * @param {boolean} [options.preferUnionId] 当用户满足 {@link https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/union-id.html 获取 UnionId 的条件} 时,是否使用 UnionId 登录。(since 3.13.0)\n * @param {string} [options.unionIdPlatform = 'weixin'] (only take effect when preferUnionId) unionId platform\n * @param {boolean} [options.asMainAccount = true] (only take effect when preferUnionId) If true, the unionId will be associated with the user.\n * @param {boolean} [options.failOnNotExist] If true, the login request will fail when no user matches this authData exists. (since v3.7.0)\n * @return {Promise.}\n */\n loginWithWeapp: function loginWithWeapp() {\n var _this15 = this;\n\n var _ref15 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\n _ref15$preferUnionId = _ref15.preferUnionId,\n preferUnionId = _ref15$preferUnionId === void 0 ? false : _ref15$preferUnionId,\n _ref15$unionIdPlatfor = _ref15.unionIdPlatform,\n unionIdPlatform = _ref15$unionIdPlatfor === void 0 ? 'weixin' : _ref15$unionIdPlatfor,\n _ref15$asMainAccount = _ref15.asMainAccount,\n asMainAccount = _ref15$asMainAccount === void 0 ? true : _ref15$asMainAccount,\n _ref15$failOnNotExist = _ref15.failOnNotExist,\n failOnNotExist = _ref15$failOnNotExist === void 0 ? false : _ref15$failOnNotExist,\n useMasterKey = _ref15.useMasterKey,\n sessionToken = _ref15.sessionToken,\n user = _ref15.user;\n\n var getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo({\n preferUnionId: preferUnionId,\n asMainAccount: asMainAccount,\n platform: unionIdPlatform\n }).then(function (authInfo) {\n return _this15.loginWithMiniApp(authInfo, {\n failOnNotExist: failOnNotExist,\n useMasterKey: useMasterKey,\n sessionToken: sessionToken,\n user: user\n });\n });\n },\n\n /**\n * 使用当前使用微信小程序的微信用户身份注册或登录,\n * 仅在微信小程序中可用。\n *\n * @deprecated please use {@link AV.User.loginWithMiniApp}\n * @since 3.13.0\n * @param {Object} [unionLoginOptions]\n * @param {string} [unionLoginOptions.unionIdPlatform = 'weixin'] unionId platform\n * @param {boolean} [unionLoginOptions.asMainAccount = false] If true, the unionId will be associated with the user.\n * @param {boolean} [unionLoginOptions.failOnNotExist] If true, the login request will fail when no user matches this authData exists. * @return {Promise.}\n */\n loginWithWeappWithUnionId: function loginWithWeappWithUnionId(unionId) {\n var _this16 = this;\n\n var _ref16 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},\n _ref16$unionIdPlatfor = _ref16.unionIdPlatform,\n unionIdPlatform = _ref16$unionIdPlatfor === void 0 ? 'weixin' : _ref16$unionIdPlatfor,\n _ref16$asMainAccount = _ref16.asMainAccount,\n asMainAccount = _ref16$asMainAccount === void 0 ? false : _ref16$asMainAccount,\n _ref16$failOnNotExist = _ref16.failOnNotExist,\n failOnNotExist = _ref16$failOnNotExist === void 0 ? false : _ref16$failOnNotExist,\n useMasterKey = _ref16.useMasterKey,\n sessionToken = _ref16.sessionToken,\n user = _ref16.user;\n\n var getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo({\n platform: unionIdPlatform\n }).then(function (authInfo) {\n authInfo = AV.User.mergeUnionId(authInfo, unionId, {\n asMainAccount: asMainAccount\n });\n return _this16.loginWithMiniApp(authInfo, {\n failOnNotExist: failOnNotExist,\n useMasterKey: useMasterKey,\n sessionToken: sessionToken,\n user: user\n });\n });\n },\n\n /**\n * 使用当前使用 QQ 小程序的 QQ 用户身份注册或登录,成功后用户的 session 会在设备上持久化保存,之后可以使用 AV.User.current() 获取当前登录用户。\n * 仅在 QQ 小程序中可用。\n *\n * @deprecated please use {@link AV.User.loginWithMiniApp}\n * @since 4.2.0\n * @param {Object} [options]\n * @param {boolean} [options.preferUnionId] 如果服务端在登录时获取到了用户的 UnionId,是否将 UnionId 保存在用户账号中。\n * @param {string} [options.unionIdPlatform = 'qq'] (only take effect when preferUnionId) unionId platform\n * @param {boolean} [options.asMainAccount = true] (only take effect when preferUnionId) If true, the unionId will be associated with the user.\n * @param {boolean} [options.failOnNotExist] If true, the login request will fail when no user matches this authData exists. (since v3.7.0)\n * @return {Promise.}\n */\n loginWithQQApp: function loginWithQQApp() {\n var _this17 = this;\n\n var _ref17 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\n _ref17$preferUnionId = _ref17.preferUnionId,\n preferUnionId = _ref17$preferUnionId === void 0 ? false : _ref17$preferUnionId,\n _ref17$unionIdPlatfor = _ref17.unionIdPlatform,\n unionIdPlatform = _ref17$unionIdPlatfor === void 0 ? 'qq' : _ref17$unionIdPlatfor,\n _ref17$asMainAccount = _ref17.asMainAccount,\n asMainAccount = _ref17$asMainAccount === void 0 ? true : _ref17$asMainAccount,\n _ref17$failOnNotExist = _ref17.failOnNotExist,\n failOnNotExist = _ref17$failOnNotExist === void 0 ? false : _ref17$failOnNotExist,\n useMasterKey = _ref17.useMasterKey,\n sessionToken = _ref17.sessionToken,\n user = _ref17.user;\n\n var getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo({\n preferUnionId: preferUnionId,\n asMainAccount: asMainAccount,\n platform: unionIdPlatform\n }).then(function (authInfo) {\n authInfo.provider = PLATFORM_QQAPP;\n return _this17.loginWithMiniApp(authInfo, {\n failOnNotExist: failOnNotExist,\n useMasterKey: useMasterKey,\n sessionToken: sessionToken,\n user: user\n });\n });\n },\n\n /**\n * 使用当前使用 QQ 小程序的 QQ 用户身份注册或登录,\n * 仅在 QQ 小程序中可用。\n *\n * @deprecated please use {@link AV.User.loginWithMiniApp}\n * @since 4.2.0\n * @param {Object} [unionLoginOptions]\n * @param {string} [unionLoginOptions.unionIdPlatform = 'qq'] unionId platform\n * @param {boolean} [unionLoginOptions.asMainAccount = false] If true, the unionId will be associated with the user.\n * @param {boolean} [unionLoginOptions.failOnNotExist] If true, the login request will fail when no user matches this authData exists.\n * @return {Promise.}\n */\n loginWithQQAppWithUnionId: function loginWithQQAppWithUnionId(unionId) {\n var _this18 = this;\n\n var _ref18 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},\n _ref18$unionIdPlatfor = _ref18.unionIdPlatform,\n unionIdPlatform = _ref18$unionIdPlatfor === void 0 ? 'qq' : _ref18$unionIdPlatfor,\n _ref18$asMainAccount = _ref18.asMainAccount,\n asMainAccount = _ref18$asMainAccount === void 0 ? false : _ref18$asMainAccount,\n _ref18$failOnNotExist = _ref18.failOnNotExist,\n failOnNotExist = _ref18$failOnNotExist === void 0 ? false : _ref18$failOnNotExist,\n useMasterKey = _ref18.useMasterKey,\n sessionToken = _ref18.sessionToken,\n user = _ref18.user;\n\n var getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo({\n platform: unionIdPlatform\n }).then(function (authInfo) {\n authInfo = AV.User.mergeUnionId(authInfo, unionId, {\n asMainAccount: asMainAccount\n });\n authInfo.provider = PLATFORM_QQAPP;\n return _this18.loginWithMiniApp(authInfo, {\n failOnNotExist: failOnNotExist,\n useMasterKey: useMasterKey,\n sessionToken: sessionToken,\n user: user\n });\n });\n },\n\n /**\n * Register or login using the identity of the current mini-app.\n * @param {Object} authInfo\n * @param {Object} [option]\n * @param {Boolean} [option.failOnNotExist] If true, the login request will fail when no user matches this authInfo.authData exists.\n */\n loginWithMiniApp: function loginWithMiniApp(authInfo, option) {\n var _this19 = this;\n\n if (authInfo === undefined) {\n var getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo().then(function (authInfo) {\n return _this19.loginWithAuthData(authInfo.authData, authInfo.provider, option);\n });\n }\n\n return this.loginWithAuthData(authInfo.authData, authInfo.provider, option);\n },\n\n /**\n * Only use for DI in tests to produce deterministic IDs.\n */\n _genId: function _genId() {\n return uuid();\n },\n\n /**\n * Creates an anonymous user.\n *\n * @since 3.9.0\n * @return {Promise.}\n */\n loginAnonymously: function loginAnonymously() {\n return this.loginWithAuthData({\n id: AV.User._genId()\n }, 'anonymous');\n },\n associateWithAuthData: function associateWithAuthData(userObj, platform, authData) {\n console.warn('DEPRECATED: User.associateWithAuthData 已废弃,请使用 User#associateWithAuthData 代替');\n return userObj._linkWith(platform, authData);\n },\n\n /**\n * Logs out the currently logged in user session. This will remove the\n * session from disk, log out of linked services, and future calls to\n * current will return null.\n * @return {Promise}\n */\n logOut: function logOut() {\n if (AV._config.disableCurrentUser) {\n console.warn('AV.User.current() was disabled in multi-user environment, call logOut() from user object instead https://leancloud.cn/docs/leanengine-node-sdk-upgrade-1.html');\n return _promise.default.resolve(null);\n }\n\n if (AV.User._currentUser !== null) {\n AV.User._currentUser._logOutWithAll();\n\n AV.User._currentUser._isCurrentUser = false;\n }\n\n AV.User._currentUserMatchesDisk = true;\n AV.User._currentUser = null;\n return AV.localStorage.removeItemAsync(AV._getAVPath(AV.User._CURRENT_USER_KEY)).then(function () {\n return AV._refreshSubscriptionId();\n });\n },\n\n /**\n *Create a follower query for special user to query the user's followers.\n * @param {String} userObjectId The user object id.\n * @return {AV.FriendShipQuery}\n * @since 0.3.0\n */\n followerQuery: function followerQuery(userObjectId) {\n if (!userObjectId || !_.isString(userObjectId)) {\n throw new Error('Invalid user object id.');\n }\n\n var query = new AV.FriendShipQuery('_Follower');\n query._friendshipTag = 'follower';\n query.equalTo('user', AV.Object.createWithoutData('_User', userObjectId));\n return query;\n },\n\n /**\n *Create a followee query for special user to query the user's followees.\n * @param {String} userObjectId The user object id.\n * @return {AV.FriendShipQuery}\n * @since 0.3.0\n */\n followeeQuery: function followeeQuery(userObjectId) {\n if (!userObjectId || !_.isString(userObjectId)) {\n throw new Error('Invalid user object id.');\n }\n\n var query = new AV.FriendShipQuery('_Followee');\n query._friendshipTag = 'followee';\n query.equalTo('user', AV.Object.createWithoutData('_User', userObjectId));\n return query;\n },\n\n /**\n * Requests a password reset email to be sent to the specified email address\n * associated with the user account. This email allows the user to securely\n * reset their password on the AV site.\n *\n * @param {String} email The email address associated with the user that\n * forgot their password.\n * @return {Promise}\n */\n requestPasswordReset: function requestPasswordReset(email) {\n var json = {\n email: email\n };\n var request = AVRequest('requestPasswordReset', null, null, 'POST', json);\n return request;\n },\n\n /**\n * Requests a verify email to be sent to the specified email address\n * associated with the user account. This email allows the user to securely\n * verify their email address on the AV site.\n *\n * @param {String} email The email address associated with the user that\n * doesn't verify their email address.\n * @return {Promise}\n */\n requestEmailVerify: function requestEmailVerify(email) {\n var json = {\n email: email\n };\n var request = AVRequest('requestEmailVerify', null, null, 'POST', json);\n return request;\n },\n\n /**\n * Requests a verify sms code to be sent to the specified mobile phone\n * number associated with the user account. This sms code allows the user to\n * verify their mobile phone number by calling AV.User.verifyMobilePhone\n *\n * @param {String} mobilePhoneNumber The mobile phone number associated with the\n * user that doesn't verify their mobile phone number.\n * @param {SMSAuthOptions} [options]\n * @return {Promise}\n */\n requestMobilePhoneVerify: function requestMobilePhoneVerify(mobilePhoneNumber) {\n var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n var data = {\n mobilePhoneNumber: mobilePhoneNumber\n };\n\n if (options.validateToken) {\n data.validate_token = options.validateToken;\n }\n\n var request = AVRequest('requestMobilePhoneVerify', null, null, 'POST', data, options);\n return request;\n },\n\n /**\n * Requests a reset password sms code to be sent to the specified mobile phone\n * number associated with the user account. This sms code allows the user to\n * reset their account's password by calling AV.User.resetPasswordBySmsCode\n *\n * @param {String} mobilePhoneNumber The mobile phone number associated with the\n * user that doesn't verify their mobile phone number.\n * @param {SMSAuthOptions} [options]\n * @return {Promise}\n */\n requestPasswordResetBySmsCode: function requestPasswordResetBySmsCode(mobilePhoneNumber) {\n var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n var data = {\n mobilePhoneNumber: mobilePhoneNumber\n };\n\n if (options.validateToken) {\n data.validate_token = options.validateToken;\n }\n\n var request = AVRequest('requestPasswordResetBySmsCode', null, null, 'POST', data, options);\n return request;\n },\n\n /**\n * Requests a change mobile phone number sms code to be sent to the mobilePhoneNumber.\n * This sms code allows current user to reset it's mobilePhoneNumber by\n * calling {@link AV.User.changePhoneNumber}\n * @since 4.7.0\n * @param {String} mobilePhoneNumber\n * @param {Number} [ttl] ttl of sms code (default is 6 minutes)\n * @param {SMSAuthOptions} [options]\n * @return {Promise}\n */\n requestChangePhoneNumber: function requestChangePhoneNumber(mobilePhoneNumber, ttl, options) {\n var data = {\n mobilePhoneNumber: mobilePhoneNumber\n };\n\n if (ttl) {\n data.ttl = options.ttl;\n }\n\n if (options && options.validateToken) {\n data.validate_token = options.validateToken;\n }\n\n return AVRequest('requestChangePhoneNumber', null, null, 'POST', data, options);\n },\n\n /**\n * Makes a call to reset user's account mobilePhoneNumber by sms code.\n * The sms code is sent by {@link AV.User.requestChangePhoneNumber}\n * @since 4.7.0\n * @param {String} mobilePhoneNumber\n * @param {String} code The sms code.\n * @return {Promise}\n */\n changePhoneNumber: function changePhoneNumber(mobilePhoneNumber, code) {\n var data = {\n mobilePhoneNumber: mobilePhoneNumber,\n code: code\n };\n return AVRequest('changePhoneNumber', null, null, 'POST', data);\n },\n\n /**\n * Makes a call to reset user's account password by sms code and new password.\n * The sms code is sent by AV.User.requestPasswordResetBySmsCode.\n * @param {String} code The sms code sent by AV.User.Cloud.requestSmsCode\n * @param {String} password The new password.\n * @return {Promise} A promise that will be resolved with the result\n * of the function.\n */\n resetPasswordBySmsCode: function resetPasswordBySmsCode(code, password) {\n var json = {\n password: password\n };\n var request = AVRequest('resetPasswordBySmsCode', null, code, 'PUT', json);\n return request;\n },\n\n /**\n * Makes a call to verify sms code that sent by AV.User.Cloud.requestSmsCode\n * If verify successfully,the user mobilePhoneVerified attribute will be true.\n * @param {String} code The sms code sent by AV.User.Cloud.requestSmsCode\n * @return {Promise} A promise that will be resolved with the result\n * of the function.\n */\n verifyMobilePhone: function verifyMobilePhone(code) {\n var request = AVRequest('verifyMobilePhone', null, code, 'POST', null);\n return request;\n },\n\n /**\n * Requests a logIn sms code to be sent to the specified mobile phone\n * number associated with the user account. This sms code allows the user to\n * login by AV.User.logInWithMobilePhoneSmsCode function.\n *\n * @param {String} mobilePhoneNumber The mobile phone number associated with the\n * user that want to login by AV.User.logInWithMobilePhoneSmsCode\n * @param {SMSAuthOptions} [options]\n * @return {Promise}\n */\n requestLoginSmsCode: function requestLoginSmsCode(mobilePhoneNumber) {\n var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n var data = {\n mobilePhoneNumber: mobilePhoneNumber\n };\n\n if (options.validateToken) {\n data.validate_token = options.validateToken;\n }\n\n var request = AVRequest('requestLoginSmsCode', null, null, 'POST', data, options);\n return request;\n },\n\n /**\n * Retrieves the currently logged in AVUser with a valid session,\n * either from memory or localStorage, if necessary.\n * @return {Promise.} resolved with the currently logged in AV.User.\n */\n currentAsync: function currentAsync() {\n if (AV._config.disableCurrentUser) {\n console.warn('AV.User.currentAsync() was disabled in multi-user environment, access user from request instead https://leancloud.cn/docs/leanengine-node-sdk-upgrade-1.html');\n return _promise.default.resolve(null);\n }\n\n if (AV.User._currentUser) {\n return _promise.default.resolve(AV.User._currentUser);\n }\n\n if (AV.User._currentUserMatchesDisk) {\n return _promise.default.resolve(AV.User._currentUser);\n }\n\n return AV.localStorage.getItemAsync(AV._getAVPath(AV.User._CURRENT_USER_KEY)).then(function (userData) {\n if (!userData) {\n return null;\n } // Load the user from local storage.\n\n\n AV.User._currentUserMatchesDisk = true;\n AV.User._currentUser = AV.Object._create('_User');\n AV.User._currentUser._isCurrentUser = true;\n var json = JSON.parse(userData);\n AV.User._currentUser.id = json._id;\n delete json._id;\n AV.User._currentUser._sessionToken = json._sessionToken;\n delete json._sessionToken;\n\n AV.User._currentUser._finishFetch(json); //AV.User._currentUser.set(json);\n\n\n AV.User._currentUser._synchronizeAllAuthData();\n\n AV.User._currentUser._refreshCache();\n\n AV.User._currentUser._opSetQueue = [{}];\n return AV.User._currentUser;\n });\n },\n\n /**\n * Retrieves the currently logged in AVUser with a valid session,\n * either from memory or localStorage, if necessary.\n * @return {AV.User} The currently logged in AV.User.\n */\n current: function current() {\n if (AV._config.disableCurrentUser) {\n console.warn('AV.User.current() was disabled in multi-user environment, access user from request instead https://leancloud.cn/docs/leanengine-node-sdk-upgrade-1.html');\n return null;\n }\n\n if (AV.localStorage.async) {\n var error = new Error('Synchronous API User.current() is not available in this runtime. Use User.currentAsync() instead.');\n error.code = 'SYNC_API_NOT_AVAILABLE';\n throw error;\n }\n\n if (AV.User._currentUser) {\n return AV.User._currentUser;\n }\n\n if (AV.User._currentUserMatchesDisk) {\n return AV.User._currentUser;\n } // Load the user from local storage.\n\n\n AV.User._currentUserMatchesDisk = true;\n var userData = AV.localStorage.getItem(AV._getAVPath(AV.User._CURRENT_USER_KEY));\n\n if (!userData) {\n return null;\n }\n\n AV.User._currentUser = AV.Object._create('_User');\n AV.User._currentUser._isCurrentUser = true;\n var json = JSON.parse(userData);\n AV.User._currentUser.id = json._id;\n delete json._id;\n AV.User._currentUser._sessionToken = json._sessionToken;\n delete json._sessionToken;\n\n AV.User._currentUser._finishFetch(json); //AV.User._currentUser.set(json);\n\n\n AV.User._currentUser._synchronizeAllAuthData();\n\n AV.User._currentUser._refreshCache();\n\n AV.User._currentUser._opSetQueue = [{}];\n return AV.User._currentUser;\n },\n\n /**\n * Persists a user as currentUser to localStorage, and into the singleton.\n * @private\n */\n _saveCurrentUser: function _saveCurrentUser(user) {\n var promise;\n\n if (AV.User._currentUser !== user) {\n promise = AV.User.logOut();\n } else {\n promise = _promise.default.resolve();\n }\n\n return promise.then(function () {\n user._isCurrentUser = true;\n AV.User._currentUser = user;\n\n var json = user._toFullJSON();\n\n json._id = user.id;\n json._sessionToken = user._sessionToken;\n return AV.localStorage.setItemAsync(AV._getAVPath(AV.User._CURRENT_USER_KEY), (0, _stringify.default)(json)).then(function () {\n AV.User._currentUserMatchesDisk = true;\n return AV._refreshSubscriptionId();\n });\n });\n },\n _registerAuthenticationProvider: function _registerAuthenticationProvider(provider) {\n AV.User._authProviders[provider.getAuthType()] = provider; // Synchronize the current user with the auth provider.\n\n if (!AV._config.disableCurrentUser && AV.User.current()) {\n AV.User.current()._synchronizeAuthData(provider.getAuthType());\n }\n },\n _logInWith: function _logInWith(provider, authData, options) {\n var user = AV.Object._create('_User');\n\n return user._linkWith(provider, authData, options);\n }\n });\n};\n\n/***/ }),\n/* 528 */\n/***/ (function(module, exports, __webpack_require__) {\n\nvar _Object$defineProperty = __webpack_require__(137);\n\nfunction _defineProperty(obj, key, value) {\n if (key in obj) {\n _Object$defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n\n return obj;\n}\n\nmodule.exports = _defineProperty, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n/***/ }),\n/* 529 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\n\nvar _interopRequireDefault = __webpack_require__(2);\n\nvar _map = _interopRequireDefault(__webpack_require__(39));\n\nvar _promise = _interopRequireDefault(__webpack_require__(10));\n\nvar _keys = _interopRequireDefault(__webpack_require__(48));\n\nvar _stringify = _interopRequireDefault(__webpack_require__(34));\n\nvar _find = _interopRequireDefault(__webpack_require__(104));\n\nvar _concat = _interopRequireDefault(__webpack_require__(29));\n\nvar _ = __webpack_require__(1);\n\nvar debug = __webpack_require__(60)('leancloud:query');\n\nvar AVError = __webpack_require__(40);\n\nvar _require = __webpack_require__(25),\n _request = _require._request,\n request = _require.request;\n\nvar _require2 = __webpack_require__(28),\n ensureArray = _require2.ensureArray,\n transformFetchOptions = _require2.transformFetchOptions,\n continueWhile = _require2.continueWhile;\n\nvar requires = function requires(value, message) {\n if (value === undefined) {\n throw new Error(message);\n }\n}; // AV.Query is a way to create a list of AV.Objects.\n\n\nmodule.exports = function (AV) {\n /**\n * Creates a new AV.Query for the given AV.Object subclass.\n * @param {Class|String} objectClass An instance of a subclass of AV.Object, or a AV className string.\n * @class\n *\n *
AV.Query defines a query that is used to fetch AV.Objects. The\n * most common use case is finding all objects that match a query through the\n * find method. For example, this sample code fetches all objects\n * of class MyClass. It calls a different function depending on\n * whether the fetch succeeded or not.\n *\n *
\n * var query = new AV.Query(MyClass);\n * query.find().then(function(results) {\n * // results is an array of AV.Object.\n * }, function(error) {\n * // error is an instance of AVError.\n * });
\n *\n *
An AV.Query can also be used to retrieve a single object whose id is\n * known, through the get method. For example, this sample code fetches an\n * object of class MyClass and id myId. It calls a\n * different function depending on whether the fetch succeeded or not.\n *\n *
\n * var query = new AV.Query(MyClass);\n * query.get(myId).then(function(object) {\n * // object is an instance of AV.Object.\n * }, function(error) {\n * // error is an instance of AVError.\n * });
\n *\n *
An AV.Query can also be used to count the number of objects that match\n * the query without retrieving all of those objects. For example, this\n * sample code counts the number of objects of the class MyClass\n *
\n * var query = new AV.Query(MyClass);\n * query.count().then(function(number) {\n * // There are number instances of MyClass.\n * }, function(error) {\n * // error is an instance of AVError.\n * });
\n */\n AV.Query = function (objectClass) {\n if (_.isString(objectClass)) {\n objectClass = AV.Object._getSubclass(objectClass);\n }\n\n this.objectClass = objectClass;\n this.className = objectClass.prototype.className;\n this._where = {};\n this._include = [];\n this._select = [];\n this._limit = -1; // negative limit means, do not send a limit\n\n this._skip = 0;\n this._defaultParams = {};\n };\n /**\n * Constructs a AV.Query that is the OR of the passed in queries. For\n * example:\n *
var compoundQuery = AV.Query.or(query1, query2, query3);
\n *\n * will create a compoundQuery that is an or of the query1, query2, and\n * query3.\n * @param {...AV.Query} var_args The list of queries to OR.\n * @return {AV.Query} The query that is the OR of the passed in queries.\n */\n\n\n AV.Query.or = function () {\n var queries = _.toArray(arguments);\n\n var className = null;\n\n AV._arrayEach(queries, function (q) {\n if (_.isNull(className)) {\n className = q.className;\n }\n\n if (className !== q.className) {\n throw new Error('All queries must be for the same class');\n }\n });\n\n var query = new AV.Query(className);\n\n query._orQuery(queries);\n\n return query;\n };\n /**\n * Constructs a AV.Query that is the AND of the passed in queries. For\n * example:\n *
var compoundQuery = AV.Query.and(query1, query2, query3);
\n *\n * will create a compoundQuery that is an 'and' of the query1, query2, and\n * query3.\n * @param {...AV.Query} var_args The list of queries to AND.\n * @return {AV.Query} The query that is the AND of the passed in queries.\n */\n\n\n AV.Query.and = function () {\n var queries = _.toArray(arguments);\n\n var className = null;\n\n AV._arrayEach(queries, function (q) {\n if (_.isNull(className)) {\n className = q.className;\n }\n\n if (className !== q.className) {\n throw new Error('All queries must be for the same class');\n }\n });\n\n var query = new AV.Query(className);\n\n query._andQuery(queries);\n\n return query;\n };\n /**\n * Retrieves a list of AVObjects that satisfy the CQL.\n * CQL syntax please see {@link https://leancloud.cn/docs/cql_guide.html CQL Guide}.\n *\n * @param {String} cql A CQL string, see {@link https://leancloud.cn/docs/cql_guide.html CQL Guide}.\n * @param {Array} pvalues An array contains placeholder values.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is resolved with the results when\n * the query completes.\n */\n\n\n AV.Query.doCloudQuery = function (cql, pvalues, options) {\n var params = {\n cql: cql\n };\n\n if (_.isArray(pvalues)) {\n params.pvalues = pvalues;\n } else {\n options = pvalues;\n }\n\n var request = _request('cloudQuery', null, null, 'GET', params, options);\n\n return request.then(function (response) {\n //query to process results.\n var query = new AV.Query(response.className);\n var results = (0, _map.default)(_).call(_, response.results, function (json) {\n var obj = query._newObject(response);\n\n if (obj._finishFetch) {\n obj._finishFetch(query._processResult(json), true);\n }\n\n return obj;\n });\n return {\n results: results,\n count: response.count,\n className: response.className\n };\n });\n };\n /**\n * Return a query with conditions from json.\n * This can be useful to send a query from server side to client side.\n * @since 4.0.0\n * @param {Object} json from {@link AV.Query#toJSON}\n * @return {AV.Query}\n */\n\n\n AV.Query.fromJSON = function (_ref) {\n var className = _ref.className,\n where = _ref.where,\n include = _ref.include,\n select = _ref.select,\n includeACL = _ref.includeACL,\n limit = _ref.limit,\n skip = _ref.skip,\n order = _ref.order;\n\n if (typeof className !== 'string') {\n throw new TypeError('Invalid Query JSON, className must be a String.');\n }\n\n var query = new AV.Query(className);\n\n _.extend(query, {\n _where: where,\n _include: include,\n _select: select,\n _includeACL: includeACL,\n _limit: limit,\n _skip: skip,\n _order: order\n });\n\n return query;\n };\n\n AV.Query._extend = AV._extend;\n\n _.extend(AV.Query.prototype,\n /** @lends AV.Query.prototype */\n {\n //hook to iterate result. Added by dennis.\n _processResult: function _processResult(obj) {\n return obj;\n },\n\n /**\n * Constructs an AV.Object whose id is already known by fetching data from\n * the server.\n *\n * @param {String} objectId The id of the object to be fetched.\n * @param {AuthOptions} options\n * @return {Promise.}\n */\n get: function get(objectId, options) {\n if (!_.isString(objectId)) {\n throw new Error('objectId must be a string');\n }\n\n if (objectId === '') {\n return _promise.default.reject(new AVError(AVError.OBJECT_NOT_FOUND, 'Object not found.'));\n }\n\n var obj = this._newObject();\n\n obj.id = objectId;\n\n var queryJSON = this._getParams();\n\n var fetchOptions = {};\n if ((0, _keys.default)(queryJSON)) fetchOptions.keys = (0, _keys.default)(queryJSON);\n if (queryJSON.include) fetchOptions.include = queryJSON.include;\n if (queryJSON.includeACL) fetchOptions.includeACL = queryJSON.includeACL;\n return _request('classes', this.className, objectId, 'GET', transformFetchOptions(fetchOptions), options).then(function (response) {\n if (_.isEmpty(response)) throw new AVError(AVError.OBJECT_NOT_FOUND, 'Object not found.');\n\n obj._finishFetch(obj.parse(response), true);\n\n return obj;\n });\n },\n\n /**\n * Returns a JSON representation of this query.\n * @return {Object}\n */\n toJSON: function toJSON() {\n var className = this.className,\n where = this._where,\n include = this._include,\n select = this._select,\n includeACL = this._includeACL,\n limit = this._limit,\n skip = this._skip,\n order = this._order;\n return {\n className: className,\n where: where,\n include: include,\n select: select,\n includeACL: includeACL,\n limit: limit,\n skip: skip,\n order: order\n };\n },\n _getParams: function _getParams() {\n var params = _.extend({}, this._defaultParams, {\n where: this._where\n });\n\n if (this._include.length > 0) {\n params.include = this._include.join(',');\n }\n\n if (this._select.length > 0) {\n params.keys = this._select.join(',');\n }\n\n if (this._includeACL !== undefined) {\n params.returnACL = this._includeACL;\n }\n\n if (this._limit >= 0) {\n params.limit = this._limit;\n }\n\n if (this._skip > 0) {\n params.skip = this._skip;\n }\n\n if (this._order !== undefined) {\n params.order = this._order;\n }\n\n return params;\n },\n _newObject: function _newObject(response) {\n var obj;\n\n if (response && response.className) {\n obj = new AV.Object(response.className);\n } else {\n obj = new this.objectClass();\n }\n\n return obj;\n },\n _createRequest: function _createRequest() {\n var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this._getParams();\n var options = arguments.length > 1 ? arguments[1] : undefined;\n var path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : \"/classes/\".concat(this.className);\n\n if (encodeURIComponent((0, _stringify.default)(params)).length > 2000) {\n var body = {\n requests: [{\n method: 'GET',\n path: \"/1.1\".concat(path),\n params: params\n }]\n };\n return request({\n path: '/batch',\n method: 'POST',\n data: body,\n authOptions: options\n }).then(function (response) {\n var result = response[0];\n\n if (result.success) {\n return result.success;\n }\n\n var error = new AVError(result.error.code, result.error.error || 'Unknown batch error');\n throw error;\n });\n }\n\n return request({\n method: 'GET',\n path: path,\n query: params,\n authOptions: options\n });\n },\n _parseResponse: function _parseResponse(response) {\n var _this = this;\n\n return (0, _map.default)(_).call(_, response.results, function (json) {\n var obj = _this._newObject(response);\n\n if (obj._finishFetch) {\n obj._finishFetch(_this._processResult(json), true);\n }\n\n return obj;\n });\n },\n\n /**\n * Retrieves a list of AVObjects that satisfy this query.\n *\n * @param {AuthOptions} options\n * @return {Promise} A promise that is resolved with the results when\n * the query completes.\n */\n find: function find(options) {\n var request = this._createRequest(undefined, options);\n\n return request.then(this._parseResponse.bind(this));\n },\n\n /**\n * Retrieves both AVObjects and total count.\n *\n * @since 4.12.0\n * @param {AuthOptions} options\n * @return {Promise} A tuple contains results and count.\n */\n findAndCount: function findAndCount(options) {\n var _this2 = this;\n\n var params = this._getParams();\n\n params.count = 1;\n\n var request = this._createRequest(params, options);\n\n return request.then(function (response) {\n return [_this2._parseResponse(response), response.count];\n });\n },\n\n /**\n * scan a Query. masterKey required.\n *\n * @since 2.1.0\n * @param {object} [options]\n * @param {string} [options.orderedBy] specify the key to sort\n * @param {number} [options.batchSize] specify the batch size for each request\n * @param {AuthOptions} [authOptions]\n * @return {AsyncIterator.}\n * @example const testIterator = {\n * [Symbol.asyncIterator]() {\n * return new Query('Test').scan(undefined, { useMasterKey: true });\n * },\n * };\n * for await (const test of testIterator) {\n * console.log(test.id);\n * }\n */\n scan: function scan() {\n var _this3 = this;\n\n var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\n orderedBy = _ref2.orderedBy,\n batchSize = _ref2.batchSize;\n\n var authOptions = arguments.length > 1 ? arguments[1] : undefined;\n\n var condition = this._getParams();\n\n debug('scan %O', condition);\n\n if (condition.order) {\n console.warn('The order of the query is ignored for Query#scan. Checkout the orderedBy option of Query#scan.');\n delete condition.order;\n }\n\n if (condition.skip) {\n console.warn('The skip option of the query is ignored for Query#scan.');\n delete condition.skip;\n }\n\n if (condition.limit) {\n console.warn('The limit option of the query is ignored for Query#scan.');\n delete condition.limit;\n }\n\n if (orderedBy) condition.scan_key = orderedBy;\n if (batchSize) condition.limit = batchSize;\n var cursor;\n var remainResults = [];\n return {\n next: function next() {\n if (remainResults.length) {\n return _promise.default.resolve({\n done: false,\n value: remainResults.shift()\n });\n }\n\n if (cursor === null) {\n return _promise.default.resolve({\n done: true\n });\n }\n\n return _request('scan/classes', _this3.className, null, 'GET', cursor ? _.extend({}, condition, {\n cursor: cursor\n }) : condition, authOptions).then(function (response) {\n cursor = response.cursor;\n\n if (response.results.length) {\n var results = _this3._parseResponse(response);\n\n results.forEach(function (result) {\n return remainResults.push(result);\n });\n }\n\n if (cursor === null && remainResults.length === 0) {\n return {\n done: true\n };\n }\n\n return {\n done: false,\n value: remainResults.shift()\n };\n });\n }\n };\n },\n\n /**\n * Delete objects retrieved by this query.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled when the save\n * completes.\n */\n destroyAll: function destroyAll(options) {\n var self = this;\n return (0, _find.default)(self).call(self, options).then(function (objects) {\n return AV.Object.destroyAll(objects, options);\n });\n },\n\n /**\n * Counts the number of objects that match this query.\n *\n * @param {AuthOptions} options\n * @return {Promise} A promise that is resolved with the count when\n * the query completes.\n */\n count: function count(options) {\n var params = this._getParams();\n\n params.limit = 0;\n params.count = 1;\n\n var request = this._createRequest(params, options);\n\n return request.then(function (response) {\n return response.count;\n });\n },\n\n /**\n * Retrieves at most one AV.Object that satisfies this query.\n *\n * @param {AuthOptions} options\n * @return {Promise} A promise that is resolved with the object when\n * the query completes.\n */\n first: function first(options) {\n var self = this;\n\n var params = this._getParams();\n\n params.limit = 1;\n\n var request = this._createRequest(params, options);\n\n return request.then(function (response) {\n return (0, _map.default)(_).call(_, response.results, function (json) {\n var obj = self._newObject();\n\n if (obj._finishFetch) {\n obj._finishFetch(self._processResult(json), true);\n }\n\n return obj;\n })[0];\n });\n },\n\n /**\n * Sets the number of results to skip before returning any results.\n * This is useful for pagination.\n * Default is to skip zero results.\n * @param {Number} n the number of results to skip.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n skip: function skip(n) {\n requires(n, 'undefined is not a valid skip value');\n this._skip = n;\n return this;\n },\n\n /**\n * Sets the limit of the number of results to return. The default limit is\n * 100, with a maximum of 1000 results being returned at a time.\n * @param {Number} n the number of results to limit to.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n limit: function limit(n) {\n requires(n, 'undefined is not a valid limit value');\n this._limit = n;\n return this;\n },\n\n /**\n * Add a constraint to the query that requires a particular key's value to\n * be equal to the provided value.\n * @param {String} key The key to check.\n * @param value The value that the AV.Object must contain.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n equalTo: function equalTo(key, value) {\n requires(key, 'undefined is not a valid key');\n requires(value, 'undefined is not a valid value');\n this._where[key] = AV._encode(value);\n return this;\n },\n\n /**\n * Helper for condition queries\n * @private\n */\n _addCondition: function _addCondition(key, condition, value) {\n requires(key, 'undefined is not a valid condition key');\n requires(condition, 'undefined is not a valid condition');\n requires(value, 'undefined is not a valid condition value'); // Check if we already have a condition\n\n if (!this._where[key]) {\n this._where[key] = {};\n }\n\n this._where[key][condition] = AV._encode(value);\n return this;\n },\n\n /**\n * Add a constraint to the query that requires a particular\n * array key's length to be equal to the provided value.\n * @param {String} key The array key to check.\n * @param {number} value The length value.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n sizeEqualTo: function sizeEqualTo(key, value) {\n this._addCondition(key, '$size', value);\n\n return this;\n },\n\n /**\n * Add a constraint to the query that requires a particular key's value to\n * be not equal to the provided value.\n * @param {String} key The key to check.\n * @param value The value that must not be equalled.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n notEqualTo: function notEqualTo(key, value) {\n this._addCondition(key, '$ne', value);\n\n return this;\n },\n\n /**\n * Add a constraint to the query that requires a particular key's value to\n * be less than the provided value.\n * @param {String} key The key to check.\n * @param value The value that provides an upper bound.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n lessThan: function lessThan(key, value) {\n this._addCondition(key, '$lt', value);\n\n return this;\n },\n\n /**\n * Add a constraint to the query that requires a particular key's value to\n * be greater than the provided value.\n * @param {String} key The key to check.\n * @param value The value that provides an lower bound.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n greaterThan: function greaterThan(key, value) {\n this._addCondition(key, '$gt', value);\n\n return this;\n },\n\n /**\n * Add a constraint to the query that requires a particular key's value to\n * be less than or equal to the provided value.\n * @param {String} key The key to check.\n * @param value The value that provides an upper bound.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n lessThanOrEqualTo: function lessThanOrEqualTo(key, value) {\n this._addCondition(key, '$lte', value);\n\n return this;\n },\n\n /**\n * Add a constraint to the query that requires a particular key's value to\n * be greater than or equal to the provided value.\n * @param {String} key The key to check.\n * @param value The value that provides an lower bound.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n greaterThanOrEqualTo: function greaterThanOrEqualTo(key, value) {\n this._addCondition(key, '$gte', value);\n\n return this;\n },\n\n /**\n * Add a constraint to the query that requires a particular key's value to\n * be contained in the provided list of values.\n * @param {String} key The key to check.\n * @param {Array} values The values that will match.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n containedIn: function containedIn(key, values) {\n this._addCondition(key, '$in', values);\n\n return this;\n },\n\n /**\n * Add a constraint to the query that requires a particular key's value to\n * not be contained in the provided list of values.\n * @param {String} key The key to check.\n * @param {Array} values The values that will not match.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n notContainedIn: function notContainedIn(key, values) {\n this._addCondition(key, '$nin', values);\n\n return this;\n },\n\n /**\n * Add a constraint to the query that requires a particular key's value to\n * contain each one of the provided list of values.\n * @param {String} key The key to check. This key's value must be an array.\n * @param {Array} values The values that will match.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n containsAll: function containsAll(key, values) {\n this._addCondition(key, '$all', values);\n\n return this;\n },\n\n /**\n * Add a constraint for finding objects that contain the given key.\n * @param {String} key The key that should exist.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n exists: function exists(key) {\n this._addCondition(key, '$exists', true);\n\n return this;\n },\n\n /**\n * Add a constraint for finding objects that do not contain a given key.\n * @param {String} key The key that should not exist\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n doesNotExist: function doesNotExist(key) {\n this._addCondition(key, '$exists', false);\n\n return this;\n },\n\n /**\n * Add a regular expression constraint for finding string values that match\n * the provided regular expression.\n * This may be slow for large datasets.\n * @param {String} key The key that the string to match is stored in.\n * @param {RegExp} regex The regular expression pattern to match.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n matches: function matches(key, regex, modifiers) {\n this._addCondition(key, '$regex', regex);\n\n if (!modifiers) {\n modifiers = '';\n } // Javascript regex options support mig as inline options but store them\n // as properties of the object. We support mi & should migrate them to\n // modifiers\n\n\n if (regex.ignoreCase) {\n modifiers += 'i';\n }\n\n if (regex.multiline) {\n modifiers += 'm';\n }\n\n if (modifiers && modifiers.length) {\n this._addCondition(key, '$options', modifiers);\n }\n\n return this;\n },\n\n /**\n * Add a constraint that requires that a key's value matches a AV.Query\n * constraint.\n * @param {String} key The key that the contains the object to match the\n * query.\n * @param {AV.Query} query The query that should match.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n matchesQuery: function matchesQuery(key, query) {\n var queryJSON = query._getParams();\n\n queryJSON.className = query.className;\n\n this._addCondition(key, '$inQuery', queryJSON);\n\n return this;\n },\n\n /**\n * Add a constraint that requires that a key's value not matches a\n * AV.Query constraint.\n * @param {String} key The key that the contains the object to match the\n * query.\n * @param {AV.Query} query The query that should not match.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n doesNotMatchQuery: function doesNotMatchQuery(key, query) {\n var queryJSON = query._getParams();\n\n queryJSON.className = query.className;\n\n this._addCondition(key, '$notInQuery', queryJSON);\n\n return this;\n },\n\n /**\n * Add a constraint that requires that a key's value matches a value in\n * an object returned by a different AV.Query.\n * @param {String} key The key that contains the value that is being\n * matched.\n * @param {String} queryKey The key in the objects returned by the query to\n * match against.\n * @param {AV.Query} query The query to run.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n matchesKeyInQuery: function matchesKeyInQuery(key, queryKey, query) {\n var queryJSON = query._getParams();\n\n queryJSON.className = query.className;\n\n this._addCondition(key, '$select', {\n key: queryKey,\n query: queryJSON\n });\n\n return this;\n },\n\n /**\n * Add a constraint that requires that a key's value not match a value in\n * an object returned by a different AV.Query.\n * @param {String} key The key that contains the value that is being\n * excluded.\n * @param {String} queryKey The key in the objects returned by the query to\n * match against.\n * @param {AV.Query} query The query to run.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n doesNotMatchKeyInQuery: function doesNotMatchKeyInQuery(key, queryKey, query) {\n var queryJSON = query._getParams();\n\n queryJSON.className = query.className;\n\n this._addCondition(key, '$dontSelect', {\n key: queryKey,\n query: queryJSON\n });\n\n return this;\n },\n\n /**\n * Add constraint that at least one of the passed in queries matches.\n * @param {Array} queries\n * @return {AV.Query} Returns the query, so you can chain this call.\n * @private\n */\n _orQuery: function _orQuery(queries) {\n var queryJSON = (0, _map.default)(_).call(_, queries, function (q) {\n return q._getParams().where;\n });\n this._where.$or = queryJSON;\n return this;\n },\n\n /**\n * Add constraint that both of the passed in queries matches.\n * @param {Array} queries\n * @return {AV.Query} Returns the query, so you can chain this call.\n * @private\n */\n _andQuery: function _andQuery(queries) {\n var queryJSON = (0, _map.default)(_).call(_, queries, function (q) {\n return q._getParams().where;\n });\n this._where.$and = queryJSON;\n return this;\n },\n\n /**\n * Converts a string into a regex that matches it.\n * Surrounding with \\Q .. \\E does this, we just need to escape \\E's in\n * the text separately.\n * @private\n */\n _quote: function _quote(s) {\n return '\\\\Q' + s.replace('\\\\E', '\\\\E\\\\\\\\E\\\\Q') + '\\\\E';\n },\n\n /**\n * Add a constraint for finding string values that contain a provided\n * string. This may be slow for large datasets.\n * @param {String} key The key that the string to match is stored in.\n * @param {String} substring The substring that the value must contain.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n contains: function contains(key, value) {\n this._addCondition(key, '$regex', this._quote(value));\n\n return this;\n },\n\n /**\n * Add a constraint for finding string values that start with a provided\n * string. This query will use the backend index, so it will be fast even\n * for large datasets.\n * @param {String} key The key that the string to match is stored in.\n * @param {String} prefix The substring that the value must start with.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n startsWith: function startsWith(key, value) {\n this._addCondition(key, '$regex', '^' + this._quote(value));\n\n return this;\n },\n\n /**\n * Add a constraint for finding string values that end with a provided\n * string. This will be slow for large datasets.\n * @param {String} key The key that the string to match is stored in.\n * @param {String} suffix The substring that the value must end with.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n endsWith: function endsWith(key, value) {\n this._addCondition(key, '$regex', this._quote(value) + '$');\n\n return this;\n },\n\n /**\n * Sorts the results in ascending order by the given key.\n *\n * @param {String} key The key to order by.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n ascending: function ascending(key) {\n requires(key, 'undefined is not a valid key');\n this._order = key;\n return this;\n },\n\n /**\n * Also sorts the results in ascending order by the given key. The previous sort keys have\n * precedence over this key.\n *\n * @param {String} key The key to order by\n * @return {AV.Query} Returns the query so you can chain this call.\n */\n addAscending: function addAscending(key) {\n requires(key, 'undefined is not a valid key');\n if (this._order) this._order += ',' + key;else this._order = key;\n return this;\n },\n\n /**\n * Sorts the results in descending order by the given key.\n *\n * @param {String} key The key to order by.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n descending: function descending(key) {\n requires(key, 'undefined is not a valid key');\n this._order = '-' + key;\n return this;\n },\n\n /**\n * Also sorts the results in descending order by the given key. The previous sort keys have\n * precedence over this key.\n *\n * @param {String} key The key to order by\n * @return {AV.Query} Returns the query so you can chain this call.\n */\n addDescending: function addDescending(key) {\n requires(key, 'undefined is not a valid key');\n if (this._order) this._order += ',-' + key;else this._order = '-' + key;\n return this;\n },\n\n /**\n * Add a proximity based constraint for finding objects with key point\n * values near the point given.\n * @param {String} key The key that the AV.GeoPoint is stored in.\n * @param {AV.GeoPoint} point The reference AV.GeoPoint that is used.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n near: function near(key, point) {\n if (!(point instanceof AV.GeoPoint)) {\n // Try to cast it to a GeoPoint, so that near(\"loc\", [20,30]) works.\n point = new AV.GeoPoint(point);\n }\n\n this._addCondition(key, '$nearSphere', point);\n\n return this;\n },\n\n /**\n * Add a proximity based constraint for finding objects with key point\n * values near the point given and within the maximum distance given.\n * @param {String} key The key that the AV.GeoPoint is stored in.\n * @param {AV.GeoPoint} point The reference AV.GeoPoint that is used.\n * @param maxDistance Maximum distance (in radians) of results to return.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n withinRadians: function withinRadians(key, point, distance) {\n this.near(key, point);\n\n this._addCondition(key, '$maxDistance', distance);\n\n return this;\n },\n\n /**\n * Add a proximity based constraint for finding objects with key point\n * values near the point given and within the maximum distance given.\n * Radius of earth used is 3958.8 miles.\n * @param {String} key The key that the AV.GeoPoint is stored in.\n * @param {AV.GeoPoint} point The reference AV.GeoPoint that is used.\n * @param {Number} maxDistance Maximum distance (in miles) of results to\n * return.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n withinMiles: function withinMiles(key, point, distance) {\n return this.withinRadians(key, point, distance / 3958.8);\n },\n\n /**\n * Add a proximity based constraint for finding objects with key point\n * values near the point given and within the maximum distance given.\n * Radius of earth used is 6371.0 kilometers.\n * @param {String} key The key that the AV.GeoPoint is stored in.\n * @param {AV.GeoPoint} point The reference AV.GeoPoint that is used.\n * @param {Number} maxDistance Maximum distance (in kilometers) of results\n * to return.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n withinKilometers: function withinKilometers(key, point, distance) {\n return this.withinRadians(key, point, distance / 6371.0);\n },\n\n /**\n * Add a constraint to the query that requires a particular key's\n * coordinates be contained within a given rectangular geographic bounding\n * box.\n * @param {String} key The key to be constrained.\n * @param {AV.GeoPoint} southwest\n * The lower-left inclusive corner of the box.\n * @param {AV.GeoPoint} northeast\n * The upper-right inclusive corner of the box.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n withinGeoBox: function withinGeoBox(key, southwest, northeast) {\n if (!(southwest instanceof AV.GeoPoint)) {\n southwest = new AV.GeoPoint(southwest);\n }\n\n if (!(northeast instanceof AV.GeoPoint)) {\n northeast = new AV.GeoPoint(northeast);\n }\n\n this._addCondition(key, '$within', {\n $box: [southwest, northeast]\n });\n\n return this;\n },\n\n /**\n * Include nested AV.Objects for the provided key. You can use dot\n * notation to specify which fields in the included object are also fetch.\n * @param {String[]} keys The name of the key to include.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n include: function include(keys) {\n var _this4 = this;\n\n requires(keys, 'undefined is not a valid key');\n\n _.forEach(arguments, function (keys) {\n var _context;\n\n _this4._include = (0, _concat.default)(_context = _this4._include).call(_context, ensureArray(keys));\n });\n\n return this;\n },\n\n /**\n * Include the ACL.\n * @param {Boolean} [value=true] Whether to include the ACL\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n includeACL: function includeACL() {\n var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;\n this._includeACL = value;\n return this;\n },\n\n /**\n * Restrict the fields of the returned AV.Objects to include only the\n * provided keys. If this is called multiple times, then all of the keys\n * specified in each of the calls will be included.\n * @param {String[]} keys The names of the keys to include.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n select: function select(keys) {\n var _this5 = this;\n\n requires(keys, 'undefined is not a valid key');\n\n _.forEach(arguments, function (keys) {\n var _context2;\n\n _this5._select = (0, _concat.default)(_context2 = _this5._select).call(_context2, ensureArray(keys));\n });\n\n return this;\n },\n\n /**\n * Iterates over each result of a query, calling a callback for each one. If\n * the callback returns a promise, the iteration will not continue until\n * that promise has been fulfilled. If the callback returns a rejected\n * promise, then iteration will stop with that error. The items are\n * processed in an unspecified order. The query may not have any sort order,\n * and may not use limit or skip.\n * @param callback {Function} Callback that will be called with each result\n * of the query.\n * @return {Promise} A promise that will be fulfilled once the\n * iteration has completed.\n */\n each: function each(callback) {\n var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n\n if (this._order || this._skip || this._limit >= 0) {\n var error = new Error('Cannot iterate on a query with sort, skip, or limit.');\n return _promise.default.reject(error);\n }\n\n var query = new AV.Query(this.objectClass); // We can override the batch size from the options.\n // This is undocumented, but useful for testing.\n\n query._limit = options.batchSize || 100;\n query._where = _.clone(this._where);\n query._include = _.clone(this._include);\n query.ascending('objectId');\n var finished = false;\n return continueWhile(function () {\n return !finished;\n }, function () {\n return (0, _find.default)(query).call(query, options).then(function (results) {\n var callbacksDone = _promise.default.resolve();\n\n _.each(results, function (result) {\n callbacksDone = callbacksDone.then(function () {\n return callback(result);\n });\n });\n\n return callbacksDone.then(function () {\n if (results.length >= query._limit) {\n query.greaterThan('objectId', results[results.length - 1].id);\n } else {\n finished = true;\n }\n });\n });\n });\n },\n\n /**\n * Subscribe the changes of this query.\n *\n * LiveQuery is not included in the default bundle: {@link https://url.leanapp.cn/enable-live-query}.\n *\n * @since 3.0.0\n * @return {AV.LiveQuery} An eventemitter which can be used to get LiveQuery updates;\n */\n subscribe: function subscribe(options) {\n return AV.LiveQuery.init(this, options);\n }\n });\n\n AV.FriendShipQuery = AV.Query._extend({\n _newObject: function _newObject() {\n var UserClass = AV.Object._getSubclass('_User');\n\n return new UserClass();\n },\n _processResult: function _processResult(json) {\n if (json && json[this._friendshipTag]) {\n var user = json[this._friendshipTag];\n\n if (user.__type === 'Pointer' && user.className === '_User') {\n delete user.__type;\n delete user.className;\n }\n\n return user;\n } else {\n return null;\n }\n }\n });\n};\n\n/***/ }),\n/* 530 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\n\nvar _interopRequireDefault = __webpack_require__(2);\n\nvar _promise = _interopRequireDefault(__webpack_require__(10));\n\nvar _keys = _interopRequireDefault(__webpack_require__(48));\n\nvar _ = __webpack_require__(1);\n\nvar EventEmitter = __webpack_require__(218);\n\nvar _require = __webpack_require__(28),\n inherits = _require.inherits;\n\nvar _require2 = __webpack_require__(25),\n request = _require2.request;\n\nvar subscribe = function subscribe(queryJSON, subscriptionId) {\n return request({\n method: 'POST',\n path: '/LiveQuery/subscribe',\n data: {\n query: queryJSON,\n id: subscriptionId\n }\n });\n};\n\nmodule.exports = function (AV) {\n var requireRealtime = function requireRealtime() {\n if (!AV._config.realtime) {\n throw new Error('LiveQuery not supported. Please use the LiveQuery bundle. https://url.leanapp.cn/enable-live-query');\n }\n };\n /**\n * @class\n * A LiveQuery, created by {@link AV.Query#subscribe} is an EventEmitter notifies changes of the Query.\n * @since 3.0.0\n */\n\n\n AV.LiveQuery = inherits(EventEmitter,\n /** @lends AV.LiveQuery.prototype */\n {\n constructor: function constructor(id, client, queryJSON, subscriptionId) {\n var _this = this;\n\n EventEmitter.apply(this);\n this.id = id;\n this._client = client;\n\n this._client.register(this);\n\n this._queryJSON = queryJSON;\n this._subscriptionId = subscriptionId;\n this._onMessage = this._dispatch.bind(this);\n\n this._onReconnect = function () {\n subscribe(_this._queryJSON, _this._subscriptionId).catch(function (error) {\n return console.error(\"LiveQuery resubscribe error: \".concat(error.message));\n });\n };\n\n client.on('message', this._onMessage);\n client.on('reconnect', this._onReconnect);\n },\n _dispatch: function _dispatch(message) {\n var _this2 = this;\n\n message.forEach(function (_ref) {\n var op = _ref.op,\n object = _ref.object,\n queryId = _ref.query_id,\n updatedKeys = _ref.updatedKeys;\n if (queryId !== _this2.id) return;\n var target = AV.parseJSON(_.extend({\n __type: object.className === '_File' ? 'File' : 'Object'\n }, object));\n\n if (updatedKeys) {\n /**\n * An existing AV.Object which fulfills the Query you subscribe is updated.\n * @event AV.LiveQuery#update\n * @param {AV.Object|AV.File} target updated object\n * @param {String[]} updatedKeys updated keys\n */\n\n /**\n * An existing AV.Object which doesn't fulfill the Query is updated and now it fulfills the Query.\n * @event AV.LiveQuery#enter\n * @param {AV.Object|AV.File} target updated object\n * @param {String[]} updatedKeys updated keys\n */\n\n /**\n * An existing AV.Object which fulfills the Query is updated and now it doesn't fulfill the Query.\n * @event AV.LiveQuery#leave\n * @param {AV.Object|AV.File} target updated object\n * @param {String[]} updatedKeys updated keys\n */\n _this2.emit(op, target, updatedKeys);\n } else {\n /**\n * A new AV.Object which fulfills the Query you subscribe is created.\n * @event AV.LiveQuery#create\n * @param {AV.Object|AV.File} target updated object\n */\n\n /**\n * An existing AV.Object which fulfills the Query you subscribe is deleted.\n * @event AV.LiveQuery#delete\n * @param {AV.Object|AV.File} target updated object\n */\n _this2.emit(op, target);\n }\n });\n },\n\n /**\n * unsubscribe the query\n *\n * @return {Promise}\n */\n unsubscribe: function unsubscribe() {\n var client = this._client;\n client.off('message', this._onMessage);\n client.off('reconnect', this._onReconnect);\n client.deregister(this);\n return request({\n method: 'POST',\n path: '/LiveQuery/unsubscribe',\n data: {\n id: client.id,\n query_id: this.id\n }\n });\n }\n },\n /** @lends AV.LiveQuery */\n {\n init: function init(query) {\n var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},\n _ref2$subscriptionId = _ref2.subscriptionId,\n userDefinedSubscriptionId = _ref2$subscriptionId === void 0 ? AV._getSubscriptionId() : _ref2$subscriptionId;\n\n requireRealtime();\n if (!(query instanceof AV.Query)) throw new TypeError('LiveQuery must be inited with a Query');\n return _promise.default.resolve(userDefinedSubscriptionId).then(function (subscriptionId) {\n return AV._config.realtime.createLiveQueryClient(subscriptionId).then(function (liveQueryClient) {\n var _query$_getParams = query._getParams(),\n where = _query$_getParams.where,\n keys = (0, _keys.default)(_query$_getParams),\n returnACL = _query$_getParams.returnACL;\n\n var queryJSON = {\n where: where,\n keys: keys,\n returnACL: returnACL,\n className: query.className\n };\n var promise = subscribe(queryJSON, subscriptionId).then(function (_ref3) {\n var queryId = _ref3.query_id;\n return new AV.LiveQuery(queryId, liveQueryClient, queryJSON, subscriptionId);\n }).finally(function () {\n liveQueryClient.deregister(promise);\n });\n liveQueryClient.register(promise);\n return promise;\n });\n });\n },\n\n /**\n * Pause the LiveQuery connection. This is useful to deactivate the SDK when the app is swtiched to background.\n * @static\n * @return void\n */\n pause: function pause() {\n requireRealtime();\n return AV._config.realtime.pause();\n },\n\n /**\n * Resume the LiveQuery connection. All subscriptions will be restored after reconnection.\n * @static\n * @return void\n */\n resume: function resume() {\n requireRealtime();\n return AV._config.realtime.resume();\n }\n });\n};\n\n/***/ }),\n/* 531 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\n\nvar _ = __webpack_require__(1);\n\nvar _require = __webpack_require__(28),\n tap = _require.tap;\n\nmodule.exports = function (AV) {\n /**\n * @class\n * @example\n * AV.Captcha.request().then(captcha => {\n * captcha.bind({\n * textInput: 'code', // the id for textInput\n * image: 'captcha',\n * verifyButton: 'verify',\n * }, {\n * success: (validateCode) => {}, // next step\n * error: (error) => {}, // present error.message to user\n * });\n * });\n */\n AV.Captcha = function Captcha(options, authOptions) {\n this._options = options;\n this._authOptions = authOptions;\n /**\n * The image url of the captcha\n * @type string\n */\n\n this.url = undefined;\n /**\n * The captchaToken of the captcha.\n * @type string\n */\n\n this.captchaToken = undefined;\n /**\n * The validateToken of the captcha.\n * @type string\n */\n\n this.validateToken = undefined;\n };\n /**\n * Refresh the captcha\n * @return {Promise.} a new capcha url\n */\n\n\n AV.Captcha.prototype.refresh = function refresh() {\n var _this = this;\n\n return AV.Cloud._requestCaptcha(this._options, this._authOptions).then(function (_ref) {\n var captchaToken = _ref.captchaToken,\n url = _ref.url;\n\n _.extend(_this, {\n captchaToken: captchaToken,\n url: url\n });\n\n return url;\n });\n };\n /**\n * Verify the captcha\n * @param {String} code The code from user input\n * @return {Promise.} validateToken if the code is valid\n */\n\n\n AV.Captcha.prototype.verify = function verify(code) {\n var _this2 = this;\n\n return AV.Cloud.verifyCaptcha(code, this.captchaToken).then(tap(function (validateToken) {\n return _this2.validateToken = validateToken;\n }));\n };\n\n if (undefined === 'Browser') {\n /**\n * Bind the captcha to HTMLElements. ONLY AVAILABLE in browsers.\n * @param [elements]\n * @param {String|HTMLInputElement} [elements.textInput] An input element typed text, or the id for the element.\n * @param {String|HTMLImageElement} [elements.image] An image element, or the id for the element.\n * @param {String|HTMLElement} [elements.verifyButton] A button element, or the id for the element.\n * @param [callbacks]\n * @param {Function} [callbacks.success] Success callback will be called if the code is verified. The param `validateCode` can be used for further SMS request.\n * @param {Function} [callbacks.error] Error callback will be called if something goes wrong, detailed in param `error.message`.\n */\n AV.Captcha.prototype.bind = function bind(_ref2, _ref3) {\n var _this3 = this;\n\n var textInput = _ref2.textInput,\n image = _ref2.image,\n verifyButton = _ref2.verifyButton;\n var success = _ref3.success,\n error = _ref3.error;\n\n if (typeof textInput === 'string') {\n textInput = document.getElementById(textInput);\n if (!textInput) throw new Error(\"textInput with id \".concat(textInput, \" not found\"));\n }\n\n if (typeof image === 'string') {\n image = document.getElementById(image);\n if (!image) throw new Error(\"image with id \".concat(image, \" not found\"));\n }\n\n if (typeof verifyButton === 'string') {\n verifyButton = document.getElementById(verifyButton);\n if (!verifyButton) throw new Error(\"verifyButton with id \".concat(verifyButton, \" not found\"));\n }\n\n this.__refresh = function () {\n return _this3.refresh().then(function (url) {\n image.src = url;\n\n if (textInput) {\n textInput.value = '';\n textInput.focus();\n }\n }).catch(function (err) {\n return console.warn(\"refresh captcha fail: \".concat(err.message));\n });\n };\n\n if (image) {\n this.__image = image;\n image.src = this.url;\n image.addEventListener('click', this.__refresh);\n }\n\n this.__verify = function () {\n var code = textInput.value;\n\n _this3.verify(code).catch(function (err) {\n _this3.__refresh();\n\n throw err;\n }).then(success, error).catch(function (err) {\n return console.warn(\"verify captcha fail: \".concat(err.message));\n });\n };\n\n if (textInput && verifyButton) {\n this.__verifyButton = verifyButton;\n verifyButton.addEventListener('click', this.__verify);\n }\n };\n /**\n * unbind the captcha from HTMLElements. ONLY AVAILABLE in browsers.\n */\n\n\n AV.Captcha.prototype.unbind = function unbind() {\n if (this.__image) this.__image.removeEventListener('click', this.__refresh);\n if (this.__verifyButton) this.__verifyButton.removeEventListener('click', this.__verify);\n };\n }\n /**\n * Request a captcha\n * @param [options]\n * @param {Number} [options.width] width(px) of the captcha, ranged 60-200\n * @param {Number} [options.height] height(px) of the captcha, ranged 30-100\n * @param {Number} [options.size=4] length of the captcha, ranged 3-6. MasterKey required.\n * @param {Number} [options.ttl=60] time to live(s), ranged 10-180. MasterKey required.\n * @return {Promise.}\n */\n\n\n AV.Captcha.request = function (options, authOptions) {\n var captcha = new AV.Captcha(options, authOptions);\n return captcha.refresh().then(function () {\n return captcha;\n });\n };\n};\n\n/***/ }),\n/* 532 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\n\nvar _interopRequireDefault = __webpack_require__(2);\n\nvar _promise = _interopRequireDefault(__webpack_require__(10));\n\nvar _ = __webpack_require__(1);\n\nvar _require = __webpack_require__(25),\n _request = _require._request,\n request = _require.request;\n\nmodule.exports = function (AV) {\n /**\n * Contains functions for calling and declaring\n *
\n * Some functions are only available from Cloud Code.\n *
\n *\n * @namespace\n * @borrows AV.Captcha.request as requestCaptcha\n */\n AV.Cloud = AV.Cloud || {};\n\n _.extend(AV.Cloud,\n /** @lends AV.Cloud */\n {\n /**\n * Makes a call to a cloud function.\n * @param {String} name The function name.\n * @param {Object} [data] The parameters to send to the cloud function.\n * @param {AuthOptions} [options]\n * @return {Promise} A promise that will be resolved with the result\n * of the function.\n */\n run: function run(name, data, options) {\n return request({\n service: 'engine',\n method: 'POST',\n path: \"/functions/\".concat(name),\n data: AV._encode(data, null, true),\n authOptions: options\n }).then(function (resp) {\n return AV._decode(resp).result;\n });\n },\n\n /**\n * Makes a call to a cloud function, you can send {AV.Object} as param or a field of param; the response\n * from server will also be parsed as an {AV.Object}, array of {AV.Object}, or object includes {AV.Object}\n * @param {String} name The function name.\n * @param {Object} [data] The parameters to send to the cloud function.\n * @param {AuthOptions} [options]\n * @return {Promise} A promise that will be resolved with the result of the function.\n */\n rpc: function rpc(name, data, options) {\n if (_.isArray(data)) {\n return _promise.default.reject(new Error(\"Can't pass Array as the param of rpc function in JavaScript SDK.\"));\n }\n\n return request({\n service: 'engine',\n method: 'POST',\n path: \"/call/\".concat(name),\n data: AV._encodeObjectOrArray(data),\n authOptions: options\n }).then(function (resp) {\n return AV._decode(resp).result;\n });\n },\n\n /**\n * Make a call to request server date time.\n * @return {Promise.} A promise that will be resolved with the result\n * of the function.\n * @since 0.5.9\n */\n getServerDate: function getServerDate() {\n return _request('date', null, null, 'GET').then(function (resp) {\n return AV._decode(resp);\n });\n },\n\n /**\n * Makes a call to request an sms code for operation verification.\n * @param {String|Object} data The mobile phone number string or a JSON\n * object that contains mobilePhoneNumber,template,sign,op,ttl,name etc.\n * @param {String} data.mobilePhoneNumber\n * @param {String} [data.template] sms template name\n * @param {String} [data.sign] sms signature name\n * @param {String} [data.smsType] sending code by `sms` (default) or `voice` call\n * @param {SMSAuthOptions} [options]\n * @return {Promise} A promise that will be resolved if the request succeed\n */\n requestSmsCode: function requestSmsCode(data) {\n var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n\n if (_.isString(data)) {\n data = {\n mobilePhoneNumber: data\n };\n }\n\n if (!data.mobilePhoneNumber) {\n throw new Error('Missing mobilePhoneNumber.');\n }\n\n if (options.validateToken) {\n data = _.extend({}, data, {\n validate_token: options.validateToken\n });\n }\n\n return _request('requestSmsCode', null, null, 'POST', data, options);\n },\n\n /**\n * Makes a call to verify sms code that sent by AV.Cloud.requestSmsCode\n * @param {String} code The sms code sent by AV.Cloud.requestSmsCode\n * @param {phone} phone The mobile phoner number.\n * @return {Promise} A promise that will be resolved with the result\n * of the function.\n */\n verifySmsCode: function verifySmsCode(code, phone) {\n if (!code) throw new Error('Missing sms code.');\n var params = {};\n\n if (_.isString(phone)) {\n params['mobilePhoneNumber'] = phone;\n }\n\n return _request('verifySmsCode', code, null, 'POST', params);\n },\n _requestCaptcha: function _requestCaptcha(options, authOptions) {\n return _request('requestCaptcha', null, null, 'GET', options, authOptions).then(function (_ref) {\n var url = _ref.captcha_url,\n captchaToken = _ref.captcha_token;\n return {\n captchaToken: captchaToken,\n url: url\n };\n });\n },\n\n /**\n * Request a captcha.\n */\n requestCaptcha: AV.Captcha.request,\n\n /**\n * Verify captcha code. This is the low-level API for captcha.\n * Checkout {@link AV.Captcha} for high abstract APIs.\n * @param {String} code the code from user input\n * @param {String} captchaToken captchaToken returned by {@link AV.Cloud.requestCaptcha}\n * @return {Promise.} validateToken if the code is valid\n */\n verifyCaptcha: function verifyCaptcha(code, captchaToken) {\n return _request('verifyCaptcha', null, null, 'POST', {\n captcha_code: code,\n captcha_token: captchaToken\n }).then(function (_ref2) {\n var validateToken = _ref2.validate_token;\n return validateToken;\n });\n }\n });\n};\n\n/***/ }),\n/* 533 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\n\nvar request = __webpack_require__(25).request;\n\nmodule.exports = function (AV) {\n AV.Installation = AV.Object.extend('_Installation');\n /**\n * @namespace\n */\n\n AV.Push = AV.Push || {};\n /**\n * Sends a push notification.\n * @param {Object} data The data of the push notification.\n * @param {String[]} [data.channels] An Array of channels to push to.\n * @param {Date} [data.push_time] A Date object for when to send the push.\n * @param {Date} [data.expiration_time] A Date object for when to expire\n * the push.\n * @param {Number} [data.expiration_interval] The seconds from now to expire the push.\n * @param {Number} [data.flow_control] The clients to notify per second\n * @param {AV.Query} [data.where] An AV.Query over AV.Installation that is used to match\n * a set of installations to push to.\n * @param {String} [data.cql] A CQL statement over AV.Installation that is used to match\n * a set of installations to push to.\n * @param {Object} data.data The data to send as part of the push.\n More details: https://url.leanapp.cn/pushData\n * @param {AuthOptions} [options]\n * @return {Promise}\n */\n\n AV.Push.send = function (data, options) {\n if (data.where) {\n data.where = data.where._getParams().where;\n }\n\n if (data.where && data.cql) {\n throw new Error(\"Both where and cql can't be set\");\n }\n\n if (data.push_time) {\n data.push_time = data.push_time.toJSON();\n }\n\n if (data.expiration_time) {\n data.expiration_time = data.expiration_time.toJSON();\n }\n\n if (data.expiration_time && data.expiration_interval) {\n throw new Error(\"Both expiration_time and expiration_interval can't be set\");\n }\n\n return request({\n service: 'push',\n method: 'POST',\n path: '/push',\n data: data,\n authOptions: options\n });\n };\n};\n\n/***/ }),\n/* 534 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\n\nvar _interopRequireDefault = __webpack_require__(2);\n\nvar _promise = _interopRequireDefault(__webpack_require__(10));\n\nvar _typeof2 = _interopRequireDefault(__webpack_require__(135));\n\nvar _ = __webpack_require__(1);\n\nvar AVRequest = __webpack_require__(25)._request;\n\nvar _require = __webpack_require__(28),\n getSessionToken = _require.getSessionToken;\n\nmodule.exports = function (AV) {\n var getUser = function getUser() {\n var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n var sessionToken = getSessionToken(options);\n\n if (sessionToken) {\n return AV.User._fetchUserBySessionToken(getSessionToken(options));\n }\n\n return AV.User.currentAsync();\n };\n\n var getUserPointer = function getUserPointer(options) {\n return getUser(options).then(function (currUser) {\n return AV.Object.createWithoutData('_User', currUser.id)._toPointer();\n });\n };\n /**\n * Contains functions to deal with Status in LeanCloud.\n * @class\n */\n\n\n AV.Status = function (imageUrl, message) {\n this.data = {};\n this.inboxType = 'default';\n this.query = null;\n\n if (imageUrl && (0, _typeof2.default)(imageUrl) === 'object') {\n this.data = imageUrl;\n } else {\n if (imageUrl) {\n this.data.image = imageUrl;\n }\n\n if (message) {\n this.data.message = message;\n }\n }\n\n return this;\n };\n\n _.extend(AV.Status.prototype,\n /** @lends AV.Status.prototype */\n {\n /**\n * Gets the value of an attribute in status data.\n * @param {String} attr The string name of an attribute.\n */\n get: function get(attr) {\n return this.data[attr];\n },\n\n /**\n * Sets a hash of model attributes on the status data.\n * @param {String} key The key to set.\n * @param {any} value The value to give it.\n */\n set: function set(key, value) {\n this.data[key] = value;\n return this;\n },\n\n /**\n * Destroy this status,then it will not be avaiable in other user's inboxes.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled when the destroy\n * completes.\n */\n destroy: function destroy(options) {\n if (!this.id) return _promise.default.reject(new Error('The status id is not exists.'));\n var request = AVRequest('statuses', null, this.id, 'DELETE', options);\n return request;\n },\n\n /**\n * Cast the AV.Status object to an AV.Object pointer.\n * @return {AV.Object} A AV.Object pointer.\n */\n toObject: function toObject() {\n if (!this.id) return null;\n return AV.Object.createWithoutData('_Status', this.id);\n },\n _getDataJSON: function _getDataJSON() {\n var json = _.clone(this.data);\n\n return AV._encode(json);\n },\n\n /**\n * Send a status by a AV.Query object.\n * @since 0.3.0\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled when the send\n * completes.\n * @example\n * // send a status to male users\n * var status = new AVStatus('image url', 'a message');\n * status.query = new AV.Query('_User');\n * status.query.equalTo('gender', 'male');\n * status.send().then(function(){\n * //send status successfully.\n * }, function(err){\n * //an error threw.\n * console.dir(err);\n * });\n */\n send: function send() {\n var _this = this;\n\n var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n\n if (!getSessionToken(options) && !AV.User.current()) {\n throw new Error('Please signin an user.');\n }\n\n if (!this.query) {\n return AV.Status.sendStatusToFollowers(this, options);\n }\n\n return getUserPointer(options).then(function (currUser) {\n var query = _this.query._getParams();\n\n query.className = _this.query.className;\n var data = {};\n data.query = query;\n _this.data = _this.data || {};\n _this.data.source = _this.data.source || currUser;\n data.data = _this._getDataJSON();\n data.inboxType = _this.inboxType || 'default';\n return AVRequest('statuses', null, null, 'POST', data, options);\n }).then(function (response) {\n _this.id = response.objectId;\n _this.createdAt = AV._parseDate(response.createdAt);\n return _this;\n });\n },\n _finishFetch: function _finishFetch(serverData) {\n this.id = serverData.objectId;\n this.createdAt = AV._parseDate(serverData.createdAt);\n this.updatedAt = AV._parseDate(serverData.updatedAt);\n this.messageId = serverData.messageId;\n delete serverData.messageId;\n delete serverData.objectId;\n delete serverData.createdAt;\n delete serverData.updatedAt;\n this.data = AV._decode(serverData);\n }\n });\n /**\n * Send a status to current signined user's followers.\n * @since 0.3.0\n * @param {AV.Status} status A status object to be send to followers.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled when the send\n * completes.\n * @example\n * var status = new AVStatus('image url', 'a message');\n * AV.Status.sendStatusToFollowers(status).then(function(){\n * //send status successfully.\n * }, function(err){\n * //an error threw.\n * console.dir(err);\n * });\n */\n\n\n AV.Status.sendStatusToFollowers = function (status) {\n var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n\n if (!getSessionToken(options) && !AV.User.current()) {\n throw new Error('Please signin an user.');\n }\n\n return getUserPointer(options).then(function (currUser) {\n var query = {};\n query.className = '_Follower';\n query.keys = 'follower';\n query.where = {\n user: currUser\n };\n var data = {};\n data.query = query;\n status.data = status.data || {};\n status.data.source = status.data.source || currUser;\n data.data = status._getDataJSON();\n data.inboxType = status.inboxType || 'default';\n var request = AVRequest('statuses', null, null, 'POST', data, options);\n return request.then(function (response) {\n status.id = response.objectId;\n status.createdAt = AV._parseDate(response.createdAt);\n return status;\n });\n });\n };\n /**\n *
Send a status from current signined user to other user's private status inbox.
\n * @since 0.3.0\n * @param {AV.Status} status A status object to be send to followers.\n * @param {String} target The target user or user's objectId.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled when the send\n * completes.\n * @example\n * // send a private status to user '52e84e47e4b0f8de283b079b'\n * var status = new AVStatus('image url', 'a message');\n * AV.Status.sendPrivateStatus(status, '52e84e47e4b0f8de283b079b').then(function(){\n * //send status successfully.\n * }, function(err){\n * //an error threw.\n * console.dir(err);\n * });\n */\n\n\n AV.Status.sendPrivateStatus = function (status, target) {\n var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};\n\n if (!getSessionToken(options) && !AV.User.current()) {\n throw new Error('Please signin an user.');\n }\n\n if (!target) {\n throw new Error('Invalid target user.');\n }\n\n var userObjectId = _.isString(target) ? target : target.id;\n\n if (!userObjectId) {\n throw new Error('Invalid target user.');\n }\n\n return getUserPointer(options).then(function (currUser) {\n var query = {};\n query.className = '_User';\n query.where = {\n objectId: userObjectId\n };\n var data = {};\n data.query = query;\n status.data = status.data || {};\n status.data.source = status.data.source || currUser;\n data.data = status._getDataJSON();\n data.inboxType = 'private';\n status.inboxType = 'private';\n var request = AVRequest('statuses', null, null, 'POST', data, options);\n return request.then(function (response) {\n status.id = response.objectId;\n status.createdAt = AV._parseDate(response.createdAt);\n return status;\n });\n });\n };\n /**\n * Count unread statuses in someone's inbox.\n * @since 0.3.0\n * @param {AV.User} owner The status owner.\n * @param {String} inboxType The inbox type, 'default' by default.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled when the count\n * completes.\n * @example\n * AV.Status.countUnreadStatuses(AV.User.current()).then(function(response){\n * console.log(response.unread); //unread statuses number.\n * console.log(response.total); //total statuses number.\n * });\n */\n\n\n AV.Status.countUnreadStatuses = function (owner) {\n var inboxType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'default';\n var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};\n if (!_.isString(inboxType)) options = inboxType;\n\n if (!getSessionToken(options) && owner == null && !AV.User.current()) {\n throw new Error('Please signin an user or pass the owner objectId.');\n }\n\n return _promise.default.resolve(owner || getUser(options)).then(function (owner) {\n var params = {};\n params.inboxType = AV._encode(inboxType);\n params.owner = AV._encode(owner);\n return AVRequest('subscribe/statuses/count', null, null, 'GET', params, options);\n });\n };\n /**\n * reset unread statuses count in someone's inbox.\n * @since 2.1.0\n * @param {AV.User} owner The status owner.\n * @param {String} inboxType The inbox type, 'default' by default.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled when the reset\n * completes.\n * @example\n * AV.Status.resetUnreadCount(AV.User.current()).then(function(response){\n * console.log(response.unread); //unread statuses number.\n * console.log(response.total); //total statuses number.\n * });\n */\n\n\n AV.Status.resetUnreadCount = function (owner) {\n var inboxType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'default';\n var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};\n if (!_.isString(inboxType)) options = inboxType;\n\n if (!getSessionToken(options) && owner == null && !AV.User.current()) {\n throw new Error('Please signin an user or pass the owner objectId.');\n }\n\n return _promise.default.resolve(owner || getUser(options)).then(function (owner) {\n var params = {};\n params.inboxType = AV._encode(inboxType);\n params.owner = AV._encode(owner);\n return AVRequest('subscribe/statuses/resetUnreadCount', null, null, 'POST', params, options);\n });\n };\n /**\n * Create a status query to find someone's published statuses.\n * @since 0.3.0\n * @param {AV.User} source The status source, typically the publisher.\n * @return {AV.Query} The query object for status.\n * @example\n * //Find current user's published statuses.\n * var query = AV.Status.statusQuery(AV.User.current());\n * query.find().then(function(statuses){\n * //process statuses\n * });\n */\n\n\n AV.Status.statusQuery = function (source) {\n var query = new AV.Query('_Status');\n\n if (source) {\n query.equalTo('source', source);\n }\n\n return query;\n };\n /**\n *
AV.InboxQuery defines a query that is used to fetch somebody's inbox statuses.
\n * @class\n */\n\n\n AV.InboxQuery = AV.Query._extend(\n /** @lends AV.InboxQuery.prototype */\n {\n _objectClass: AV.Status,\n _sinceId: 0,\n _maxId: 0,\n _inboxType: 'default',\n _owner: null,\n _newObject: function _newObject() {\n return new AV.Status();\n },\n _createRequest: function _createRequest(params, options) {\n return AV.InboxQuery.__super__._createRequest.call(this, params, options, '/subscribe/statuses');\n },\n\n /**\n * Sets the messageId of results to skip before returning any results.\n * This is useful for pagination.\n * Default is zero.\n * @param {Number} n the mesage id.\n * @return {AV.InboxQuery} Returns the query, so you can chain this call.\n */\n sinceId: function sinceId(id) {\n this._sinceId = id;\n return this;\n },\n\n /**\n * Sets the maximal messageId of results。\n * This is useful for pagination.\n * Default is zero that is no limition.\n * @param {Number} n the mesage id.\n * @return {AV.InboxQuery} Returns the query, so you can chain this call.\n */\n maxId: function maxId(id) {\n this._maxId = id;\n return this;\n },\n\n /**\n * Sets the owner of the querying inbox.\n * @param {AV.User} owner The inbox owner.\n * @return {AV.InboxQuery} Returns the query, so you can chain this call.\n */\n owner: function owner(_owner) {\n this._owner = _owner;\n return this;\n },\n\n /**\n * Sets the querying inbox type.default is 'default'.\n * @param {String} type The inbox type.\n * @return {AV.InboxQuery} Returns the query, so you can chain this call.\n */\n inboxType: function inboxType(type) {\n this._inboxType = type;\n return this;\n },\n _getParams: function _getParams() {\n var params = AV.InboxQuery.__super__._getParams.call(this);\n\n params.owner = AV._encode(this._owner);\n params.inboxType = AV._encode(this._inboxType);\n params.sinceId = AV._encode(this._sinceId);\n params.maxId = AV._encode(this._maxId);\n return params;\n }\n });\n /**\n * Create a inbox status query to find someone's inbox statuses.\n * @since 0.3.0\n * @param {AV.User} owner The inbox's owner\n * @param {String} inboxType The inbox type,'default' by default.\n * @return {AV.InboxQuery} The inbox query object.\n * @see AV.InboxQuery\n * @example\n * //Find current user's default inbox statuses.\n * var query = AV.Status.inboxQuery(AV.User.current());\n * //find the statuses after the last message id\n * query.sinceId(lastMessageId);\n * query.find().then(function(statuses){\n * //process statuses\n * });\n */\n\n AV.Status.inboxQuery = function (owner, inboxType) {\n var query = new AV.InboxQuery(AV.Status);\n\n if (owner) {\n query._owner = owner;\n }\n\n if (inboxType) {\n query._inboxType = inboxType;\n }\n\n return query;\n };\n};\n\n/***/ }),\n/* 535 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\n\nvar _interopRequireDefault = __webpack_require__(2);\n\nvar _stringify = _interopRequireDefault(__webpack_require__(34));\n\nvar _map = _interopRequireDefault(__webpack_require__(39));\n\nvar _ = __webpack_require__(1);\n\nvar AVRequest = __webpack_require__(25)._request;\n\nmodule.exports = function (AV) {\n /**\n * A builder to generate sort string for app searching.For example:\n * @class\n * @since 0.5.1\n * @example\n * var builder = new AV.SearchSortBuilder();\n * builder.ascending('key1').descending('key2','max');\n * var query = new AV.SearchQuery('Player');\n * query.sortBy(builder);\n * query.find().then();\n */\n AV.SearchSortBuilder = function () {\n this._sortFields = [];\n };\n\n _.extend(AV.SearchSortBuilder.prototype,\n /** @lends AV.SearchSortBuilder.prototype */\n {\n _addField: function _addField(key, order, mode, missing) {\n var field = {};\n field[key] = {\n order: order || 'asc',\n mode: mode || 'avg',\n missing: '_' + (missing || 'last')\n };\n\n this._sortFields.push(field);\n\n return this;\n },\n\n /**\n * Sorts the results in ascending order by the given key and options.\n *\n * @param {String} key The key to order by.\n * @param {String} mode The sort mode, default is 'avg', you can choose\n * 'max' or 'min' too.\n * @param {String} missing The missing key behaviour, default is 'last',\n * you can choose 'first' too.\n * @return {AV.SearchSortBuilder} Returns the builder, so you can chain this call.\n */\n ascending: function ascending(key, mode, missing) {\n return this._addField(key, 'asc', mode, missing);\n },\n\n /**\n * Sorts the results in descending order by the given key and options.\n *\n * @param {String} key The key to order by.\n * @param {String} mode The sort mode, default is 'avg', you can choose\n * 'max' or 'min' too.\n * @param {String} missing The missing key behaviour, default is 'last',\n * you can choose 'first' too.\n * @return {AV.SearchSortBuilder} Returns the builder, so you can chain this call.\n */\n descending: function descending(key, mode, missing) {\n return this._addField(key, 'desc', mode, missing);\n },\n\n /**\n * Add a proximity based constraint for finding objects with key point\n * values near the point given.\n * @param {String} key The key that the AV.GeoPoint is stored in.\n * @param {AV.GeoPoint} point The reference AV.GeoPoint that is used.\n * @param {Object} options The other options such as mode,order, unit etc.\n * @return {AV.SearchSortBuilder} Returns the builder, so you can chain this call.\n */\n whereNear: function whereNear(key, point, options) {\n options = options || {};\n var field = {};\n var geo = {\n lat: point.latitude,\n lon: point.longitude\n };\n var m = {\n order: options.order || 'asc',\n mode: options.mode || 'avg',\n unit: options.unit || 'km'\n };\n m[key] = geo;\n field['_geo_distance'] = m;\n\n this._sortFields.push(field);\n\n return this;\n },\n\n /**\n * Build a sort string by configuration.\n * @return {String} the sort string.\n */\n build: function build() {\n return (0, _stringify.default)(AV._encode(this._sortFields));\n }\n });\n /**\n * App searching query.Use just like AV.Query:\n *\n * Visit App Searching Guide\n * for more details.\n * @class\n * @since 0.5.1\n * @example\n * var query = new AV.SearchQuery('Player');\n * query.queryString('*');\n * query.find().then(function(results) {\n * console.log('Found %d objects', query.hits());\n * //Process results\n * });\n */\n\n\n AV.SearchQuery = AV.Query._extend(\n /** @lends AV.SearchQuery.prototype */\n {\n _sid: null,\n _hits: 0,\n _queryString: null,\n _highlights: null,\n _sortBuilder: null,\n _clazz: null,\n constructor: function constructor(className) {\n if (className) {\n this._clazz = className;\n } else {\n className = '__INVALID_CLASS';\n }\n\n AV.Query.call(this, className);\n },\n _createRequest: function _createRequest(params, options) {\n return AVRequest('search/select', null, null, 'GET', params || this._getParams(), options);\n },\n\n /**\n * Sets the sid of app searching query.Default is null.\n * @param {String} sid Scroll id for searching.\n * @return {AV.SearchQuery} Returns the query, so you can chain this call.\n */\n sid: function sid(_sid) {\n this._sid = _sid;\n return this;\n },\n\n /**\n * Sets the query string of app searching.\n * @param {String} q The query string.\n * @return {AV.SearchQuery} Returns the query, so you can chain this call.\n */\n queryString: function queryString(q) {\n this._queryString = q;\n return this;\n },\n\n /**\n * Sets the highlight fields. Such as\n *
\n * @param {String|String[]} highlights a list of fields.\n * @return {AV.SearchQuery} Returns the query, so you can chain this call.\n */\n highlights: function highlights(_highlights) {\n var objects;\n\n if (_highlights && _.isString(_highlights)) {\n objects = _.toArray(arguments);\n } else {\n objects = _highlights;\n }\n\n this._highlights = objects;\n return this;\n },\n\n /**\n * Sets the sort builder for this query.\n * @see AV.SearchSortBuilder\n * @param { AV.SearchSortBuilder} builder The sort builder.\n * @return {AV.SearchQuery} Returns the query, so you can chain this call.\n *\n */\n sortBy: function sortBy(builder) {\n this._sortBuilder = builder;\n return this;\n },\n\n /**\n * Returns the number of objects that match this query.\n * @return {Number}\n */\n hits: function hits() {\n if (!this._hits) {\n this._hits = 0;\n }\n\n return this._hits;\n },\n _processResult: function _processResult(json) {\n delete json['className'];\n delete json['_app_url'];\n delete json['_deeplink'];\n return json;\n },\n\n /**\n * Returns true when there are more documents can be retrieved by this\n * query instance, you can call find function to get more results.\n * @see AV.SearchQuery#find\n * @return {Boolean}\n */\n hasMore: function hasMore() {\n return !this._hitEnd;\n },\n\n /**\n * Reset current query instance state(such as sid, hits etc) except params\n * for a new searching. After resetting, hasMore() will return true.\n */\n reset: function reset() {\n this._hitEnd = false;\n this._sid = null;\n this._hits = 0;\n },\n\n /**\n * Retrieves a list of AVObjects that satisfy this query.\n * Either options.success or options.error is called when the find\n * completes.\n *\n * @see AV.Query#find\n * @param {AuthOptions} options\n * @return {Promise} A promise that is resolved with the results when\n * the query completes.\n */\n find: function find(options) {\n var self = this;\n\n var request = this._createRequest(undefined, options);\n\n return request.then(function (response) {\n //update sid for next querying.\n if (response.sid) {\n self._oldSid = self._sid;\n self._sid = response.sid;\n } else {\n self._sid = null;\n self._hitEnd = true;\n }\n\n self._hits = response.hits || 0;\n return (0, _map.default)(_).call(_, response.results, function (json) {\n if (json.className) {\n response.className = json.className;\n }\n\n var obj = self._newObject(response);\n\n obj.appURL = json['_app_url'];\n\n obj._finishFetch(self._processResult(json), true);\n\n return obj;\n });\n });\n },\n _getParams: function _getParams() {\n var params = AV.SearchQuery.__super__._getParams.call(this);\n\n delete params.where;\n\n if (this._clazz) {\n params.clazz = this.className;\n }\n\n if (this._sid) {\n params.sid = this._sid;\n }\n\n if (!this._queryString) {\n throw new Error('Please set query string.');\n } else {\n params.q = this._queryString;\n }\n\n if (this._highlights) {\n params.highlights = this._highlights.join(',');\n }\n\n if (this._sortBuilder && params.order) {\n throw new Error('sort and order can not be set at same time.');\n }\n\n if (this._sortBuilder) {\n params.sort = this._sortBuilder.build();\n }\n\n return params;\n }\n });\n};\n/**\n * Sorts the results in ascending order by the given key.\n *\n * @method AV.SearchQuery#ascending\n * @param {String} key The key to order by.\n * @return {AV.SearchQuery} Returns the query, so you can chain this call.\n */\n\n/**\n * Also sorts the results in ascending order by the given key. The previous sort keys have\n * precedence over this key.\n *\n * @method AV.SearchQuery#addAscending\n * @param {String} key The key to order by\n * @return {AV.SearchQuery} Returns the query so you can chain this call.\n */\n\n/**\n * Sorts the results in descending order by the given key.\n *\n * @method AV.SearchQuery#descending\n * @param {String} key The key to order by.\n * @return {AV.SearchQuery} Returns the query, so you can chain this call.\n */\n\n/**\n * Also sorts the results in descending order by the given key. The previous sort keys have\n * precedence over this key.\n *\n * @method AV.SearchQuery#addDescending\n * @param {String} key The key to order by\n * @return {AV.SearchQuery} Returns the query so you can chain this call.\n */\n\n/**\n * Include nested AV.Objects for the provided key. You can use dot\n * notation to specify which fields in the included object are also fetch.\n * @method AV.SearchQuery#include\n * @param {String[]} keys The name of the key to include.\n * @return {AV.SearchQuery} Returns the query, so you can chain this call.\n */\n\n/**\n * Sets the number of results to skip before returning any results.\n * This is useful for pagination.\n * Default is to skip zero results.\n * @method AV.SearchQuery#skip\n * @param {Number} n the number of results to skip.\n * @return {AV.SearchQuery} Returns the query, so you can chain this call.\n */\n\n/**\n * Sets the limit of the number of results to return. The default limit is\n * 100, with a maximum of 1000 results being returned at a time.\n * @method AV.SearchQuery#limit\n * @param {Number} n the number of results to limit to.\n * @return {AV.SearchQuery} Returns the query, so you can chain this call.\n */\n\n/***/ }),\n/* 536 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\n\nvar _interopRequireDefault = __webpack_require__(2);\n\nvar _promise = _interopRequireDefault(__webpack_require__(10));\n\nvar _ = __webpack_require__(1);\n\nvar AVError = __webpack_require__(40);\n\nvar _require = __webpack_require__(25),\n request = _require.request;\n\nmodule.exports = function (AV) {\n /**\n * 包含了使用了 LeanCloud\n * 离线数据分析功能的函数。\n *
\n * { \"sql\" : \"select count(*) as c,gender from _User group by gender\",\n * \"saveAs\": {\n * \"className\" : \"UserGender\",\n * \"limit\": 1\n * }\n * }\n *
\n * sql 指定任务执行的 SQL 语句, saveAs(可选) 指定将结果保存在哪张表里,limit 最大 1000。\n * @param {AuthOptions} [options]\n * @return {Promise} A promise that will be resolved with the result\n * of the function.\n */\n startJob: function startJob(jobConfig, options) {\n if (!jobConfig || !jobConfig.sql) {\n throw new Error('Please provide the sql to run the job.');\n }\n\n var data = {\n jobConfig: jobConfig,\n appId: AV.applicationId\n };\n return request({\n path: '/bigquery/jobs',\n method: 'POST',\n data: AV._encode(data, null, true),\n authOptions: options,\n signKey: false\n }).then(function (resp) {\n return AV._decode(resp).id;\n });\n },\n\n /**\n * 监听 Insight 任务事件(未来推出独立部署的离线分析服务后开放)\n *
\n * 仅在云引擎运行环境下有效。\n *
\n * @param {String} event 监听的事件,目前尚不支持。\n * @param {Function} 监听回调函数,接收 (err, id) 两个参数,err 表示错误信息,\n * id 表示任务 id。接下来你可以拿这个 id 使用AV.Insight.JobQuery 查询任务状态和结果。\n *\n */\n on: function on(event, cb) {}\n });\n /**\n * 创建一个对象,用于查询 Insight 任务状态和结果。\n * @class\n * @param {String} id 任务 id\n * @since 0.5.5\n */\n\n\n AV.Insight.JobQuery = function (id, className) {\n if (!id) {\n throw new Error('Please provide the job id.');\n }\n\n this.id = id;\n this.className = className;\n this._skip = 0;\n this._limit = 100;\n };\n\n _.extend(AV.Insight.JobQuery.prototype,\n /** @lends AV.Insight.JobQuery.prototype */\n {\n /**\n * Sets the number of results to skip before returning any results.\n * This is useful for pagination.\n * Default is to skip zero results.\n * @param {Number} n the number of results to skip.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n skip: function skip(n) {\n this._skip = n;\n return this;\n },\n\n /**\n * Sets the limit of the number of results to return. The default limit is\n * 100, with a maximum of 1000 results being returned at a time.\n * @param {Number} n the number of results to limit to.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n limit: function limit(n) {\n this._limit = n;\n return this;\n },\n\n /**\n * 查询任务状态和结果,任务结果为一个 JSON 对象,包括 status 表示任务状态, totalCount 表示总数,\n * results 数组表示任务结果数组,previewCount 表示可以返回的结果总数,任务的开始和截止时间\n * startTime、endTime 等信息。\n *\n * @param {AuthOptions} [options]\n * @return {Promise} A promise that will be resolved with the result\n * of the function.\n *\n */\n find: function find(options) {\n var params = {\n skip: this._skip,\n limit: this._limit\n };\n return request({\n path: \"/bigquery/jobs/\".concat(this.id),\n method: 'GET',\n query: params,\n authOptions: options,\n signKey: false\n }).then(function (response) {\n if (response.error) {\n return _promise.default.reject(new AVError(response.code, response.error));\n }\n\n return _promise.default.resolve(response);\n });\n }\n });\n};\n\n/***/ }),\n/* 537 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\n\nvar _interopRequireDefault = __webpack_require__(2);\n\nvar _promise = _interopRequireDefault(__webpack_require__(10));\n\nvar _ = __webpack_require__(1);\n\nvar _require = __webpack_require__(25),\n LCRequest = _require.request;\n\nvar _require2 = __webpack_require__(28),\n getSessionToken = _require2.getSessionToken;\n\nmodule.exports = function (AV) {\n var getUserWithSessionToken = function getUserWithSessionToken(authOptions) {\n if (authOptions.user) {\n if (!authOptions.user._sessionToken) {\n throw new Error('authOptions.user is not signed in.');\n }\n\n return _promise.default.resolve(authOptions.user);\n }\n\n if (authOptions.sessionToken) {\n return AV.User._fetchUserBySessionToken(authOptions.sessionToken);\n }\n\n return AV.User.currentAsync();\n };\n\n var getSessionTokenAsync = function getSessionTokenAsync(authOptions) {\n var sessionToken = getSessionToken(authOptions);\n\n if (sessionToken) {\n return _promise.default.resolve(sessionToken);\n }\n\n return AV.User.currentAsync().then(function (user) {\n if (user) {\n return user.getSessionToken();\n }\n });\n };\n /**\n * Contains functions to deal with Friendship in LeanCloud.\n * @class\n */\n\n\n AV.Friendship = {\n /**\n * Request friendship.\n * @since 4.8.0\n * @param {String | AV.User | Object} options if an AV.User or string is given, it will be used as the friend.\n * @param {AV.User | string} options.friend The friend (or friend's objectId) to follow.\n * @param {Object} [options.attributes] key-value attributes dictionary to be used as conditions of followeeQuery.\n * @param {AuthOptions} [authOptions]\n * @return {Promise}\n */\n request: function request(options) {\n var authOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n var friend;\n var attributes;\n\n if (options.friend) {\n friend = options.friend;\n attributes = options.attributes;\n } else {\n friend = options;\n }\n\n var friendObj = _.isString(friend) ? AV.Object.createWithoutData('_User', friend) : friend;\n return getUserWithSessionToken(authOptions).then(function (userObj) {\n if (!userObj) {\n throw new Error('Please signin an user.');\n }\n\n return LCRequest({\n method: 'POST',\n path: '/users/friendshipRequests',\n data: {\n user: userObj._toPointer(),\n friend: friendObj._toPointer(),\n friendship: attributes\n },\n authOptions: authOptions\n });\n });\n },\n\n /**\n * Accept a friendship request.\n * @since 4.8.0\n * @param {AV.Object | string | Object} options if an AV.Object or string is given, it will be used as the request in _FriendshipRequest.\n * @param {AV.Object} options.request The request (or it's objectId) to be accepted.\n * @param {Object} [options.attributes] key-value attributes dictionary to be used as conditions of {@link AV#followeeQuery}.\n * @param {AuthOptions} [authOptions]\n * @return {Promise}\n */\n acceptRequest: function acceptRequest(options) {\n var authOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n var request;\n var attributes;\n\n if (options.request) {\n request = options.request;\n attributes = options.attributes;\n } else {\n request = options;\n }\n\n var requestId = _.isString(request) ? request : request.id;\n return getSessionTokenAsync(authOptions).then(function (sessionToken) {\n if (!sessionToken) {\n throw new Error('Please signin an user.');\n }\n\n return LCRequest({\n method: 'PUT',\n path: '/users/friendshipRequests/' + requestId + '/accept',\n data: {\n friendship: AV._encode(attributes)\n },\n authOptions: authOptions\n });\n });\n },\n\n /**\n * Decline a friendship request.\n * @param {AV.Object | string} request The request (or it's objectId) to be declined.\n * @param {AuthOptions} [authOptions]\n * @return {Promise}\n */\n declineRequest: function declineRequest(request) {\n var authOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n var requestId = _.isString(request) ? request : request.id;\n return getSessionTokenAsync(authOptions).then(function (sessionToken) {\n if (!sessionToken) {\n throw new Error('Please signin an user.');\n }\n\n return LCRequest({\n method: 'PUT',\n path: '/users/friendshipRequests/' + requestId + '/decline',\n authOptions: authOptions\n });\n });\n }\n };\n};\n\n/***/ }),\n/* 538 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\n\nvar _interopRequireDefault = __webpack_require__(2);\n\nvar _stringify = _interopRequireDefault(__webpack_require__(34));\n\nvar _ = __webpack_require__(1);\n\nvar _require = __webpack_require__(25),\n _request = _require._request;\n\nvar AV = __webpack_require__(59);\n\nvar serializeMessage = function serializeMessage(message) {\n if (typeof message === 'string') {\n return message;\n }\n\n if (typeof message.getPayload === 'function') {\n return (0, _stringify.default)(message.getPayload());\n }\n\n return (0, _stringify.default)(message);\n};\n/**\n *
An AV.Conversation is a local representation of a LeanCloud realtime's\n * conversation. This class is a subclass of AV.Object, and retains the\n * same functionality of an AV.Object, but also extends it with various\n * conversation specific methods, like get members, creators of this conversation.\n *
\n */\n AV.Cloud.useMasterKey = () => {\n AV._config.useMasterKey = true;\n };\n}\n\n/**\n * Call this method to set production environment variable.\n * @function AV.setProduction\n * @param {Boolean} production True is production environment,and\n * it's true by default.\n */\nAV.setProduction = production => {\n if (!isNullOrUndefined(production)) {\n AV._config.production = production ? 1 : 0;\n } else {\n // change to default value\n AV._config.production = null;\n }\n};\n\nAV._setServerURLs = (urls, disableAppRouter = true) => {\n if (typeof urls !== 'string') {\n extend(AV._config.serverURLs, urls);\n } else {\n AV._config.serverURLs = fillServerURLs(urls);\n }\n if (disableAppRouter) {\n if (AV._appRouter) {\n AV._appRouter.disable();\n } else {\n _disableAppRouter = true;\n }\n }\n};\n/**\n * Set server URLs for services.\n * @function AV.setServerURL\n * @since 4.3.0\n * @param {String|ServerURLs} urls URLs for services. if a string was given, it will be applied for all services.\n * You can also set them when initializing SDK with `options.serverURL`\n */\nAV.setServerURL = urls => AV._setServerURLs(urls);\nAV.setServerURLs = AV.setServerURL;\n\nAV.keepErrorRawMessage = value => {\n AV._sharedConfig.keepErrorRawMessage = value;\n};\n\n/**\n * Set a deadline for requests to complete.\n * Note that file upload requests are not affected.\n * @function AV.setRequestTimeout\n * @since 3.6.0\n * @param {number} ms\n */\nAV.setRequestTimeout = ms => {\n AV._config.requestTimeout = ms;\n};\n\n// backword compatible\nAV.initialize = AV.init;\n\nconst defineConfig = property =>\n Object.defineProperty(AV, property, {\n get() {\n return AV._config[property];\n },\n set(value) {\n AV._config[property] = value;\n },\n });\n\n['applicationId', 'applicationKey', 'masterKey', 'hookKey'].forEach(\n defineConfig\n);\n\n\n\n// WEBPACK FOOTER //\n// ./src/init.js","var isPrototypeOf = require('../../internals/object-is-prototype-of');\nvar method = require('../array/virtual/slice');\n\nvar ArrayPrototype = Array.prototype;\n\nmodule.exports = function (it) {\n var own = it.slice;\n return it === ArrayPrototype || (isPrototypeOf(ArrayPrototype, it) && own === ArrayPrototype.slice) ? method : own;\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/es/instance/slice.js\n// module id = 383\n// module chunks = 0 1","require('../../../modules/es.array.slice');\nvar entryVirtual = require('../../../internals/entry-virtual');\n\nmodule.exports = entryVirtual('Array').slice;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/es/array/virtual/slice.js\n// module id = 384\n// module chunks = 0 1","'use strict';\nvar $ = require('../internals/export');\nvar isArray = require('../internals/is-array');\nvar isConstructor = require('../internals/is-constructor');\nvar isObject = require('../internals/is-object');\nvar toAbsoluteIndex = require('../internals/to-absolute-index');\nvar lengthOfArrayLike = require('../internals/length-of-array-like');\nvar toIndexedObject = require('../internals/to-indexed-object');\nvar createProperty = require('../internals/create-property');\nvar wellKnownSymbol = require('../internals/well-known-symbol');\nvar arrayMethodHasSpeciesSupport = require('../internals/array-method-has-species-support');\nvar un$Slice = require('../internals/array-slice');\n\nvar HAS_SPECIES_SUPPORT = arrayMethodHasSpeciesSupport('slice');\n\nvar SPECIES = wellKnownSymbol('species');\nvar $Array = Array;\nvar max = Math.max;\n\n// `Array.prototype.slice` method\n// https://tc39.es/ecma262/#sec-array.prototype.slice\n// fallback for not array-like ES3 strings and DOM objects\n$({ target: 'Array', proto: true, forced: !HAS_SPECIES_SUPPORT }, {\n slice: function slice(start, end) {\n var O = toIndexedObject(this);\n var length = lengthOfArrayLike(O);\n var k = toAbsoluteIndex(start, length);\n var fin = toAbsoluteIndex(end === undefined ? length : end, length);\n // inline `ArraySpeciesCreate` for usage native `Array#slice` where it's possible\n var Constructor, result, n;\n if (isArray(O)) {\n Constructor = O.constructor;\n // cross-realm fallback\n if (isConstructor(Constructor) && (Constructor === $Array || isArray(Constructor.prototype))) {\n Constructor = undefined;\n } else if (isObject(Constructor)) {\n Constructor = Constructor[SPECIES];\n if (Constructor === null) Constructor = undefined;\n }\n if (Constructor === $Array || Constructor === undefined) {\n return un$Slice(O, k, fin);\n }\n }\n result = new (Constructor === undefined ? $Array : Constructor)(max(fin - k, 0));\n for (n = 0; k < fin; k++, n++) if (k in O) createProperty(result, n, O[k]);\n result.length = n;\n return result;\n }\n});\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.array.slice.js\n// module id = 385\n// module chunks = 0 1","require('../../modules/es.object.define-property');\nvar path = require('../../internals/path');\n\nvar Object = path.Object;\n\nvar defineProperty = module.exports = function defineProperty(it, key, desc) {\n return Object.defineProperty(it, key, desc);\n};\n\nif (Object.defineProperty.sham) defineProperty.sham = true;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/es/object/define-property.js\n// module id = 386\n// module chunks = 0 1","var $ = require('../internals/export');\nvar DESCRIPTORS = require('../internals/descriptors');\nvar defineProperty = require('../internals/object-define-property').f;\n\n// `Object.defineProperty` method\n// https://tc39.es/ecma262/#sec-object.defineproperty\n// eslint-disable-next-line es-x/no-object-defineproperty -- safe\n$({ target: 'Object', stat: true, forced: Object.defineProperty !== defineProperty, sham: !DESCRIPTORS }, {\n defineProperty: defineProperty\n});\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.object.define-property.js\n// module id = 387\n// module chunks = 0 1","const ajax = require('./utils/ajax');\nconst Cache = require('./cache');\n\nfunction AppRouter(AV) {\n this.AV = AV;\n this.lockedUntil = 0;\n Cache.getAsync('serverURLs')\n .then(data => {\n if (this.disabled) return;\n if (!data) return this.lock(0);\n const { serverURLs, lockedUntil } = data;\n this.AV._setServerURLs(serverURLs, false);\n this.lockedUntil = lockedUntil;\n })\n .catch(() => this.lock(0));\n}\n\nAppRouter.prototype.disable = function disable() {\n this.disabled = true;\n};\nAppRouter.prototype.lock = function lock(ttl) {\n this.lockedUntil = Date.now() + ttl;\n};\nAppRouter.prototype.refresh = function refresh() {\n if (this.disabled) return;\n if (Date.now() < this.lockedUntil) return;\n this.lock(10);\n const url = 'https://app-router.com/2/route';\n return ajax({\n method: 'get',\n url,\n query: {\n appId: this.AV.applicationId,\n },\n })\n .then(servers => {\n if (this.disabled) return;\n let ttl = servers.ttl;\n if (!ttl) throw new Error('missing ttl');\n ttl = ttl * 1000;\n const protocal = 'https://';\n const serverURLs = {\n push: protocal + servers.push_server,\n stats: protocal + servers.stats_server,\n engine: protocal + servers.engine_server,\n api: protocal + servers.api_server,\n };\n this.AV._setServerURLs(serverURLs, false);\n this.lock(ttl);\n return Cache.setAsync(\n 'serverURLs',\n {\n serverURLs,\n lockedUntil: this.lockedUntil,\n },\n ttl\n );\n })\n .catch(error => {\n // bypass all errors\n console.warn(`refresh server URLs failed: ${error.message}`);\n this.lock(600);\n });\n};\n\nmodule.exports = AppRouter;\n\n\n\n// WEBPACK FOOTER //\n// ./src/app-router.js","module.exports = require('../../full/symbol');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/features/symbol/index.js\n// module id = 389\n// module chunks = 0 1","var parent = require('../../actual/symbol');\nrequire('../../modules/esnext.symbol.async-dispose');\nrequire('../../modules/esnext.symbol.dispose');\nrequire('../../modules/esnext.symbol.matcher');\nrequire('../../modules/esnext.symbol.metadata-key');\nrequire('../../modules/esnext.symbol.observable');\n// TODO: Remove from `core-js@4`\nrequire('../../modules/esnext.symbol.metadata');\nrequire('../../modules/esnext.symbol.pattern-match');\nrequire('../../modules/esnext.symbol.replace-all');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/full/symbol/index.js\n// module id = 390\n// module chunks = 0 1","var parent = require('../../stable/symbol');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/actual/symbol/index.js\n// module id = 391\n// module chunks = 0 1","require('../../modules/es.array.concat');\nrequire('../../modules/es.object.to-string');\nrequire('../../modules/es.symbol');\nrequire('../../modules/es.symbol.async-iterator');\nrequire('../../modules/es.symbol.description');\nrequire('../../modules/es.symbol.has-instance');\nrequire('../../modules/es.symbol.is-concat-spreadable');\nrequire('../../modules/es.symbol.iterator');\nrequire('../../modules/es.symbol.match');\nrequire('../../modules/es.symbol.match-all');\nrequire('../../modules/es.symbol.replace');\nrequire('../../modules/es.symbol.search');\nrequire('../../modules/es.symbol.species');\nrequire('../../modules/es.symbol.split');\nrequire('../../modules/es.symbol.to-primitive');\nrequire('../../modules/es.symbol.to-string-tag');\nrequire('../../modules/es.symbol.unscopables');\nrequire('../../modules/es.json.to-string-tag');\nrequire('../../modules/es.math.to-string-tag');\nrequire('../../modules/es.reflect.to-string-tag');\nvar path = require('../../internals/path');\n\nmodule.exports = path.Symbol;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/es/symbol/index.js\n// module id = 392\n// module chunks = 0 1","// TODO: Remove this module from `core-js@4` since it's split to modules listed below\nrequire('../modules/es.symbol.constructor');\nrequire('../modules/es.symbol.for');\nrequire('../modules/es.symbol.key-for');\nrequire('../modules/es.json.stringify');\nrequire('../modules/es.object.get-own-property-symbols');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.symbol.js\n// module id = 393\n// module chunks = 0 1","'use strict';\nvar $ = require('../internals/export');\nvar global = require('../internals/global');\nvar call = require('../internals/function-call');\nvar uncurryThis = require('../internals/function-uncurry-this');\nvar IS_PURE = require('../internals/is-pure');\nvar DESCRIPTORS = require('../internals/descriptors');\nvar NATIVE_SYMBOL = require('../internals/native-symbol');\nvar fails = require('../internals/fails');\nvar hasOwn = require('../internals/has-own-property');\nvar isPrototypeOf = require('../internals/object-is-prototype-of');\nvar anObject = require('../internals/an-object');\nvar toIndexedObject = require('../internals/to-indexed-object');\nvar toPropertyKey = require('../internals/to-property-key');\nvar $toString = require('../internals/to-string');\nvar createPropertyDescriptor = require('../internals/create-property-descriptor');\nvar nativeObjectCreate = require('../internals/object-create');\nvar objectKeys = require('../internals/object-keys');\nvar getOwnPropertyNamesModule = require('../internals/object-get-own-property-names');\nvar getOwnPropertyNamesExternal = require('../internals/object-get-own-property-names-external');\nvar getOwnPropertySymbolsModule = require('../internals/object-get-own-property-symbols');\nvar getOwnPropertyDescriptorModule = require('../internals/object-get-own-property-descriptor');\nvar definePropertyModule = require('../internals/object-define-property');\nvar definePropertiesModule = require('../internals/object-define-properties');\nvar propertyIsEnumerableModule = require('../internals/object-property-is-enumerable');\nvar defineBuiltIn = require('../internals/define-built-in');\nvar shared = require('../internals/shared');\nvar sharedKey = require('../internals/shared-key');\nvar hiddenKeys = require('../internals/hidden-keys');\nvar uid = require('../internals/uid');\nvar wellKnownSymbol = require('../internals/well-known-symbol');\nvar wrappedWellKnownSymbolModule = require('../internals/well-known-symbol-wrapped');\nvar defineWellKnownSymbol = require('../internals/define-well-known-symbol');\nvar defineSymbolToPrimitive = require('../internals/symbol-define-to-primitive');\nvar setToStringTag = require('../internals/set-to-string-tag');\nvar InternalStateModule = require('../internals/internal-state');\nvar $forEach = require('../internals/array-iteration').forEach;\n\nvar HIDDEN = sharedKey('hidden');\nvar SYMBOL = 'Symbol';\nvar PROTOTYPE = 'prototype';\n\nvar setInternalState = InternalStateModule.set;\nvar getInternalState = InternalStateModule.getterFor(SYMBOL);\n\nvar ObjectPrototype = Object[PROTOTYPE];\nvar $Symbol = global.Symbol;\nvar SymbolPrototype = $Symbol && $Symbol[PROTOTYPE];\nvar TypeError = global.TypeError;\nvar QObject = global.QObject;\nvar nativeGetOwnPropertyDescriptor = getOwnPropertyDescriptorModule.f;\nvar nativeDefineProperty = definePropertyModule.f;\nvar nativeGetOwnPropertyNames = getOwnPropertyNamesExternal.f;\nvar nativePropertyIsEnumerable = propertyIsEnumerableModule.f;\nvar push = uncurryThis([].push);\n\nvar AllSymbols = shared('symbols');\nvar ObjectPrototypeSymbols = shared('op-symbols');\nvar WellKnownSymbolsStore = shared('wks');\n\n// Don't use setters in Qt Script, https://github.com/zloirock/core-js/issues/173\nvar USE_SETTER = !QObject || !QObject[PROTOTYPE] || !QObject[PROTOTYPE].findChild;\n\n// fallback for old Android, https://code.google.com/p/v8/issues/detail?id=687\nvar setSymbolDescriptor = DESCRIPTORS && fails(function () {\n return nativeObjectCreate(nativeDefineProperty({}, 'a', {\n get: function () { return nativeDefineProperty(this, 'a', { value: 7 }).a; }\n })).a != 7;\n}) ? function (O, P, Attributes) {\n var ObjectPrototypeDescriptor = nativeGetOwnPropertyDescriptor(ObjectPrototype, P);\n if (ObjectPrototypeDescriptor) delete ObjectPrototype[P];\n nativeDefineProperty(O, P, Attributes);\n if (ObjectPrototypeDescriptor && O !== ObjectPrototype) {\n nativeDefineProperty(ObjectPrototype, P, ObjectPrototypeDescriptor);\n }\n} : nativeDefineProperty;\n\nvar wrap = function (tag, description) {\n var symbol = AllSymbols[tag] = nativeObjectCreate(SymbolPrototype);\n setInternalState(symbol, {\n type: SYMBOL,\n tag: tag,\n description: description\n });\n if (!DESCRIPTORS) symbol.description = description;\n return symbol;\n};\n\nvar $defineProperty = function defineProperty(O, P, Attributes) {\n if (O === ObjectPrototype) $defineProperty(ObjectPrototypeSymbols, P, Attributes);\n anObject(O);\n var key = toPropertyKey(P);\n anObject(Attributes);\n if (hasOwn(AllSymbols, key)) {\n if (!Attributes.enumerable) {\n if (!hasOwn(O, HIDDEN)) nativeDefineProperty(O, HIDDEN, createPropertyDescriptor(1, {}));\n O[HIDDEN][key] = true;\n } else {\n if (hasOwn(O, HIDDEN) && O[HIDDEN][key]) O[HIDDEN][key] = false;\n Attributes = nativeObjectCreate(Attributes, { enumerable: createPropertyDescriptor(0, false) });\n } return setSymbolDescriptor(O, key, Attributes);\n } return nativeDefineProperty(O, key, Attributes);\n};\n\nvar $defineProperties = function defineProperties(O, Properties) {\n anObject(O);\n var properties = toIndexedObject(Properties);\n var keys = objectKeys(properties).concat($getOwnPropertySymbols(properties));\n $forEach(keys, function (key) {\n if (!DESCRIPTORS || call($propertyIsEnumerable, properties, key)) $defineProperty(O, key, properties[key]);\n });\n return O;\n};\n\nvar $create = function create(O, Properties) {\n return Properties === undefined ? nativeObjectCreate(O) : $defineProperties(nativeObjectCreate(O), Properties);\n};\n\nvar $propertyIsEnumerable = function propertyIsEnumerable(V) {\n var P = toPropertyKey(V);\n var enumerable = call(nativePropertyIsEnumerable, this, P);\n if (this === ObjectPrototype && hasOwn(AllSymbols, P) && !hasOwn(ObjectPrototypeSymbols, P)) return false;\n return enumerable || !hasOwn(this, P) || !hasOwn(AllSymbols, P) || hasOwn(this, HIDDEN) && this[HIDDEN][P]\n ? enumerable : true;\n};\n\nvar $getOwnPropertyDescriptor = function getOwnPropertyDescriptor(O, P) {\n var it = toIndexedObject(O);\n var key = toPropertyKey(P);\n if (it === ObjectPrototype && hasOwn(AllSymbols, key) && !hasOwn(ObjectPrototypeSymbols, key)) return;\n var descriptor = nativeGetOwnPropertyDescriptor(it, key);\n if (descriptor && hasOwn(AllSymbols, key) && !(hasOwn(it, HIDDEN) && it[HIDDEN][key])) {\n descriptor.enumerable = true;\n }\n return descriptor;\n};\n\nvar $getOwnPropertyNames = function getOwnPropertyNames(O) {\n var names = nativeGetOwnPropertyNames(toIndexedObject(O));\n var result = [];\n $forEach(names, function (key) {\n if (!hasOwn(AllSymbols, key) && !hasOwn(hiddenKeys, key)) push(result, key);\n });\n return result;\n};\n\nvar $getOwnPropertySymbols = function (O) {\n var IS_OBJECT_PROTOTYPE = O === ObjectPrototype;\n var names = nativeGetOwnPropertyNames(IS_OBJECT_PROTOTYPE ? ObjectPrototypeSymbols : toIndexedObject(O));\n var result = [];\n $forEach(names, function (key) {\n if (hasOwn(AllSymbols, key) && (!IS_OBJECT_PROTOTYPE || hasOwn(ObjectPrototype, key))) {\n push(result, AllSymbols[key]);\n }\n });\n return result;\n};\n\n// `Symbol` constructor\n// https://tc39.es/ecma262/#sec-symbol-constructor\nif (!NATIVE_SYMBOL) {\n $Symbol = function Symbol() {\n if (isPrototypeOf(SymbolPrototype, this)) throw TypeError('Symbol is not a constructor');\n var description = !arguments.length || arguments[0] === undefined ? undefined : $toString(arguments[0]);\n var tag = uid(description);\n var setter = function (value) {\n if (this === ObjectPrototype) call(setter, ObjectPrototypeSymbols, value);\n if (hasOwn(this, HIDDEN) && hasOwn(this[HIDDEN], tag)) this[HIDDEN][tag] = false;\n setSymbolDescriptor(this, tag, createPropertyDescriptor(1, value));\n };\n if (DESCRIPTORS && USE_SETTER) setSymbolDescriptor(ObjectPrototype, tag, { configurable: true, set: setter });\n return wrap(tag, description);\n };\n\n SymbolPrototype = $Symbol[PROTOTYPE];\n\n defineBuiltIn(SymbolPrototype, 'toString', function toString() {\n return getInternalState(this).tag;\n });\n\n defineBuiltIn($Symbol, 'withoutSetter', function (description) {\n return wrap(uid(description), description);\n });\n\n propertyIsEnumerableModule.f = $propertyIsEnumerable;\n definePropertyModule.f = $defineProperty;\n definePropertiesModule.f = $defineProperties;\n getOwnPropertyDescriptorModule.f = $getOwnPropertyDescriptor;\n getOwnPropertyNamesModule.f = getOwnPropertyNamesExternal.f = $getOwnPropertyNames;\n getOwnPropertySymbolsModule.f = $getOwnPropertySymbols;\n\n wrappedWellKnownSymbolModule.f = function (name) {\n return wrap(wellKnownSymbol(name), name);\n };\n\n if (DESCRIPTORS) {\n // https://github.com/tc39/proposal-Symbol-description\n nativeDefineProperty(SymbolPrototype, 'description', {\n configurable: true,\n get: function description() {\n return getInternalState(this).description;\n }\n });\n if (!IS_PURE) {\n defineBuiltIn(ObjectPrototype, 'propertyIsEnumerable', $propertyIsEnumerable, { unsafe: true });\n }\n }\n}\n\n$({ global: true, constructor: true, wrap: true, forced: !NATIVE_SYMBOL, sham: !NATIVE_SYMBOL }, {\n Symbol: $Symbol\n});\n\n$forEach(objectKeys(WellKnownSymbolsStore), function (name) {\n defineWellKnownSymbol(name);\n});\n\n$({ target: SYMBOL, stat: true, forced: !NATIVE_SYMBOL }, {\n useSetter: function () { USE_SETTER = true; },\n useSimple: function () { USE_SETTER = false; }\n});\n\n$({ target: 'Object', stat: true, forced: !NATIVE_SYMBOL, sham: !DESCRIPTORS }, {\n // `Object.create` method\n // https://tc39.es/ecma262/#sec-object.create\n create: $create,\n // `Object.defineProperty` method\n // https://tc39.es/ecma262/#sec-object.defineproperty\n defineProperty: $defineProperty,\n // `Object.defineProperties` method\n // https://tc39.es/ecma262/#sec-object.defineproperties\n defineProperties: $defineProperties,\n // `Object.getOwnPropertyDescriptor` method\n // https://tc39.es/ecma262/#sec-object.getownpropertydescriptors\n getOwnPropertyDescriptor: $getOwnPropertyDescriptor\n});\n\n$({ target: 'Object', stat: true, forced: !NATIVE_SYMBOL }, {\n // `Object.getOwnPropertyNames` method\n // https://tc39.es/ecma262/#sec-object.getownpropertynames\n getOwnPropertyNames: $getOwnPropertyNames\n});\n\n// `Symbol.prototype[@@toPrimitive]` method\n// https://tc39.es/ecma262/#sec-symbol.prototype-@@toprimitive\ndefineSymbolToPrimitive();\n\n// `Symbol.prototype[@@toStringTag]` property\n// https://tc39.es/ecma262/#sec-symbol.prototype-@@tostringtag\nsetToStringTag($Symbol, SYMBOL);\n\nhiddenKeys[HIDDEN] = true;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.symbol.constructor.js\n// module id = 394\n// module chunks = 0 1","/* eslint-disable es-x/no-object-getownpropertynames -- safe */\nvar classof = require('../internals/classof-raw');\nvar toIndexedObject = require('../internals/to-indexed-object');\nvar $getOwnPropertyNames = require('../internals/object-get-own-property-names').f;\nvar arraySlice = require('../internals/array-slice-simple');\n\nvar windowNames = typeof window == 'object' && window && Object.getOwnPropertyNames\n ? Object.getOwnPropertyNames(window) : [];\n\nvar getWindowNames = function (it) {\n try {\n return $getOwnPropertyNames(it);\n } catch (error) {\n return arraySlice(windowNames);\n }\n};\n\n// fallback for IE11 buggy Object.getOwnPropertyNames with iframe and window\nmodule.exports.f = function getOwnPropertyNames(it) {\n return windowNames && classof(it) == 'Window'\n ? getWindowNames(it)\n : $getOwnPropertyNames(toIndexedObject(it));\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/internals/object-get-own-property-names-external.js\n// module id = 395\n// module chunks = 0 1","var toAbsoluteIndex = require('../internals/to-absolute-index');\nvar lengthOfArrayLike = require('../internals/length-of-array-like');\nvar createProperty = require('../internals/create-property');\n\nvar $Array = Array;\nvar max = Math.max;\n\nmodule.exports = function (O, start, end) {\n var length = lengthOfArrayLike(O);\n var k = toAbsoluteIndex(start, length);\n var fin = toAbsoluteIndex(end === undefined ? length : end, length);\n var result = $Array(max(fin - k, 0));\n for (var n = 0; k < fin; k++, n++) createProperty(result, n, O[k]);\n result.length = n;\n return result;\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/internals/array-slice-simple.js\n// module id = 396\n// module chunks = 0 1","var $ = require('../internals/export');\nvar getBuiltIn = require('../internals/get-built-in');\nvar hasOwn = require('../internals/has-own-property');\nvar toString = require('../internals/to-string');\nvar shared = require('../internals/shared');\nvar NATIVE_SYMBOL_REGISTRY = require('../internals/native-symbol-registry');\n\nvar StringToSymbolRegistry = shared('string-to-symbol-registry');\nvar SymbolToStringRegistry = shared('symbol-to-string-registry');\n\n// `Symbol.for` method\n// https://tc39.es/ecma262/#sec-symbol.for\n$({ target: 'Symbol', stat: true, forced: !NATIVE_SYMBOL_REGISTRY }, {\n 'for': function (key) {\n var string = toString(key);\n if (hasOwn(StringToSymbolRegistry, string)) return StringToSymbolRegistry[string];\n var symbol = getBuiltIn('Symbol')(string);\n StringToSymbolRegistry[string] = symbol;\n SymbolToStringRegistry[symbol] = string;\n return symbol;\n }\n});\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.symbol.for.js\n// module id = 397\n// module chunks = 0 1","var $ = require('../internals/export');\nvar hasOwn = require('../internals/has-own-property');\nvar isSymbol = require('../internals/is-symbol');\nvar tryToString = require('../internals/try-to-string');\nvar shared = require('../internals/shared');\nvar NATIVE_SYMBOL_REGISTRY = require('../internals/native-symbol-registry');\n\nvar SymbolToStringRegistry = shared('symbol-to-string-registry');\n\n// `Symbol.keyFor` method\n// https://tc39.es/ecma262/#sec-symbol.keyfor\n$({ target: 'Symbol', stat: true, forced: !NATIVE_SYMBOL_REGISTRY }, {\n keyFor: function keyFor(sym) {\n if (!isSymbol(sym)) throw TypeError(tryToString(sym) + ' is not a symbol');\n if (hasOwn(SymbolToStringRegistry, sym)) return SymbolToStringRegistry[sym];\n }\n});\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.symbol.key-for.js\n// module id = 398\n// module chunks = 0 1","var $ = require('../internals/export');\nvar NATIVE_SYMBOL = require('../internals/native-symbol');\nvar fails = require('../internals/fails');\nvar getOwnPropertySymbolsModule = require('../internals/object-get-own-property-symbols');\nvar toObject = require('../internals/to-object');\n\n// V8 ~ Chrome 38 and 39 `Object.getOwnPropertySymbols` fails on primitives\n// https://bugs.chromium.org/p/v8/issues/detail?id=3443\nvar FORCED = !NATIVE_SYMBOL || fails(function () { getOwnPropertySymbolsModule.f(1); });\n\n// `Object.getOwnPropertySymbols` method\n// https://tc39.es/ecma262/#sec-object.getownpropertysymbols\n$({ target: 'Object', stat: true, forced: FORCED }, {\n getOwnPropertySymbols: function getOwnPropertySymbols(it) {\n var $getOwnPropertySymbols = getOwnPropertySymbolsModule.f;\n return $getOwnPropertySymbols ? $getOwnPropertySymbols(toObject(it)) : [];\n }\n});\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.object.get-own-property-symbols.js\n// module id = 399\n// module chunks = 0 1","var defineWellKnownSymbol = require('../internals/define-well-known-symbol');\n\n// `Symbol.asyncIterator` well-known symbol\n// https://tc39.es/ecma262/#sec-symbol.asynciterator\ndefineWellKnownSymbol('asyncIterator');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.symbol.async-iterator.js\n// module id = 400\n// module chunks = 0 1","var defineWellKnownSymbol = require('../internals/define-well-known-symbol');\n\n// `Symbol.hasInstance` well-known symbol\n// https://tc39.es/ecma262/#sec-symbol.hasinstance\ndefineWellKnownSymbol('hasInstance');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.symbol.has-instance.js\n// module id = 402\n// module chunks = 0 1","var defineWellKnownSymbol = require('../internals/define-well-known-symbol');\n\n// `Symbol.isConcatSpreadable` well-known symbol\n// https://tc39.es/ecma262/#sec-symbol.isconcatspreadable\ndefineWellKnownSymbol('isConcatSpreadable');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.symbol.is-concat-spreadable.js\n// module id = 403\n// module chunks = 0 1","var defineWellKnownSymbol = require('../internals/define-well-known-symbol');\n\n// `Symbol.match` well-known symbol\n// https://tc39.es/ecma262/#sec-symbol.match\ndefineWellKnownSymbol('match');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.symbol.match.js\n// module id = 404\n// module chunks = 0 1","var defineWellKnownSymbol = require('../internals/define-well-known-symbol');\n\n// `Symbol.matchAll` well-known symbol\n// https://tc39.es/ecma262/#sec-symbol.matchall\ndefineWellKnownSymbol('matchAll');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.symbol.match-all.js\n// module id = 405\n// module chunks = 0 1","var defineWellKnownSymbol = require('../internals/define-well-known-symbol');\n\n// `Symbol.replace` well-known symbol\n// https://tc39.es/ecma262/#sec-symbol.replace\ndefineWellKnownSymbol('replace');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.symbol.replace.js\n// module id = 406\n// module chunks = 0 1","var defineWellKnownSymbol = require('../internals/define-well-known-symbol');\n\n// `Symbol.search` well-known symbol\n// https://tc39.es/ecma262/#sec-symbol.search\ndefineWellKnownSymbol('search');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.symbol.search.js\n// module id = 407\n// module chunks = 0 1","var defineWellKnownSymbol = require('../internals/define-well-known-symbol');\n\n// `Symbol.species` well-known symbol\n// https://tc39.es/ecma262/#sec-symbol.species\ndefineWellKnownSymbol('species');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.symbol.species.js\n// module id = 408\n// module chunks = 0 1","var defineWellKnownSymbol = require('../internals/define-well-known-symbol');\n\n// `Symbol.split` well-known symbol\n// https://tc39.es/ecma262/#sec-symbol.split\ndefineWellKnownSymbol('split');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.symbol.split.js\n// module id = 409\n// module chunks = 0 1","var defineWellKnownSymbol = require('../internals/define-well-known-symbol');\nvar defineSymbolToPrimitive = require('../internals/symbol-define-to-primitive');\n\n// `Symbol.toPrimitive` well-known symbol\n// https://tc39.es/ecma262/#sec-symbol.toprimitive\ndefineWellKnownSymbol('toPrimitive');\n\n// `Symbol.prototype[@@toPrimitive]` method\n// https://tc39.es/ecma262/#sec-symbol.prototype-@@toprimitive\ndefineSymbolToPrimitive();\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.symbol.to-primitive.js\n// module id = 410\n// module chunks = 0 1","var getBuiltIn = require('../internals/get-built-in');\nvar defineWellKnownSymbol = require('../internals/define-well-known-symbol');\nvar setToStringTag = require('../internals/set-to-string-tag');\n\n// `Symbol.toStringTag` well-known symbol\n// https://tc39.es/ecma262/#sec-symbol.tostringtag\ndefineWellKnownSymbol('toStringTag');\n\n// `Symbol.prototype[@@toStringTag]` property\n// https://tc39.es/ecma262/#sec-symbol.prototype-@@tostringtag\nsetToStringTag(getBuiltIn('Symbol'), 'Symbol');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.symbol.to-string-tag.js\n// module id = 411\n// module chunks = 0 1","var defineWellKnownSymbol = require('../internals/define-well-known-symbol');\n\n// `Symbol.unscopables` well-known symbol\n// https://tc39.es/ecma262/#sec-symbol.unscopables\ndefineWellKnownSymbol('unscopables');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.symbol.unscopables.js\n// module id = 412\n// module chunks = 0 1","var global = require('../internals/global');\nvar setToStringTag = require('../internals/set-to-string-tag');\n\n// JSON[@@toStringTag] property\n// https://tc39.es/ecma262/#sec-json-@@tostringtag\nsetToStringTag(global.JSON, 'JSON', true);\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.json.to-string-tag.js\n// module id = 413\n// module chunks = 0 1","var defineWellKnownSymbol = require('../internals/define-well-known-symbol');\n\n// `Symbol.asyncDispose` well-known symbol\n// https://github.com/tc39/proposal-using-statement\ndefineWellKnownSymbol('asyncDispose');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/esnext.symbol.async-dispose.js\n// module id = 416\n// module chunks = 0 1","var defineWellKnownSymbol = require('../internals/define-well-known-symbol');\n\n// `Symbol.dispose` well-known symbol\n// https://github.com/tc39/proposal-using-statement\ndefineWellKnownSymbol('dispose');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/esnext.symbol.dispose.js\n// module id = 417\n// module chunks = 0 1","var defineWellKnownSymbol = require('../internals/define-well-known-symbol');\n\n// `Symbol.matcher` well-known symbol\n// https://github.com/tc39/proposal-pattern-matching\ndefineWellKnownSymbol('matcher');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/esnext.symbol.matcher.js\n// module id = 418\n// module chunks = 0 1","var defineWellKnownSymbol = require('../internals/define-well-known-symbol');\n\n// `Symbol.metadataKey` well-known symbol\n// https://github.com/tc39/proposal-decorator-metadata\ndefineWellKnownSymbol('metadataKey');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/esnext.symbol.metadata-key.js\n// module id = 419\n// module chunks = 0 1","var defineWellKnownSymbol = require('../internals/define-well-known-symbol');\n\n// `Symbol.observable` well-known symbol\n// https://github.com/tc39/proposal-observable\ndefineWellKnownSymbol('observable');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/esnext.symbol.observable.js\n// module id = 420\n// module chunks = 0 1","// TODO: Remove from `core-js@4`\nvar defineWellKnownSymbol = require('../internals/define-well-known-symbol');\n\n// `Symbol.metadata` well-known symbol\n// https://github.com/tc39/proposal-decorators\ndefineWellKnownSymbol('metadata');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/esnext.symbol.metadata.js\n// module id = 421\n// module chunks = 0 1","// TODO: remove from `core-js@4`\nvar defineWellKnownSymbol = require('../internals/define-well-known-symbol');\n\n// `Symbol.patternMatch` well-known symbol\n// https://github.com/tc39/proposal-pattern-matching\ndefineWellKnownSymbol('patternMatch');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/esnext.symbol.pattern-match.js\n// module id = 422\n// module chunks = 0 1","// TODO: remove from `core-js@4`\nvar defineWellKnownSymbol = require('../internals/define-well-known-symbol');\n\ndefineWellKnownSymbol('replaceAll');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/esnext.symbol.replace-all.js\n// module id = 423\n// module chunks = 0 1","module.exports = require(\"core-js-pure/features/symbol/iterator\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/core-js/symbol/iterator.js\n// module id = 424\n// module chunks = 0 1","module.exports = require('../../full/symbol/iterator');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/features/symbol/iterator.js\n// module id = 425\n// module chunks = 0 1","var parent = require('../../actual/symbol/iterator');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/full/symbol/iterator.js\n// module id = 426\n// module chunks = 0 1","var parent = require('../../stable/symbol/iterator');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/actual/symbol/iterator.js\n// module id = 427\n// module chunks = 0 1","var parent = require('../../es/symbol/iterator');\nrequire('../../modules/web.dom-collections.iterator');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/stable/symbol/iterator.js\n// module id = 428\n// module chunks = 0 1","require('../../modules/es.array.iterator');\nrequire('../../modules/es.object.to-string');\nrequire('../../modules/es.string.iterator');\nrequire('../../modules/es.symbol.iterator');\nvar WrappedWellKnownSymbolModule = require('../../internals/well-known-symbol-wrapped');\n\nmodule.exports = WrappedWellKnownSymbolModule.f('iterator');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/es/symbol/iterator.js\n// module id = 429\n// module chunks = 0 1","module.exports = require(\"core-js-pure/stable/instance/filter\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/core-js-stable/instance/filter.js\n// module id = 430\n// module chunks = 0 1","var parent = require('../../es/instance/filter');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/stable/instance/filter.js\n// module id = 431\n// module chunks = 0 1","var isPrototypeOf = require('../../internals/object-is-prototype-of');\nvar method = require('../array/virtual/filter');\n\nvar ArrayPrototype = Array.prototype;\n\nmodule.exports = function (it) {\n var own = it.filter;\n return it === ArrayPrototype || (isPrototypeOf(ArrayPrototype, it) && own === ArrayPrototype.filter) ? method : own;\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/es/instance/filter.js\n// module id = 432\n// module chunks = 0 1","require('../../../modules/es.array.filter');\nvar entryVirtual = require('../../../internals/entry-virtual');\n\nmodule.exports = entryVirtual('Array').filter;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/es/array/virtual/filter.js\n// module id = 433\n// module chunks = 0 1","'use strict';\nvar $ = require('../internals/export');\nvar $filter = require('../internals/array-iteration').filter;\nvar arrayMethodHasSpeciesSupport = require('../internals/array-method-has-species-support');\n\nvar HAS_SPECIES_SUPPORT = arrayMethodHasSpeciesSupport('filter');\n\n// `Array.prototype.filter` method\n// https://tc39.es/ecma262/#sec-array.prototype.filter\n// with adding support of @@species\n$({ target: 'Array', proto: true, forced: !HAS_SPECIES_SUPPORT }, {\n filter: function filter(callbackfn /* , thisArg */) {\n return $filter(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);\n }\n});\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.array.filter.js\n// module id = 434\n// module chunks = 0 1","// Copyright (c) 2015-2017 David M. Lee, II\n'use strict';\n\n/**\n * Local reference to TimeoutError\n * @private\n */\nvar TimeoutError;\n\n/**\n * Rejects a promise with a {@link TimeoutError} if it does not settle within\n * the specified timeout.\n *\n * @param {Promise} promise The promise.\n * @param {number} timeoutMillis Number of milliseconds to wait on settling.\n * @returns {Promise} Either resolves/rejects with `promise`, or rejects with\n * `TimeoutError`, whichever settles first.\n */\nvar timeout = module.exports.timeout = function(promise, timeoutMillis) {\n var error = new TimeoutError(),\n timeout;\n\n return Promise.race([\n promise,\n new Promise(function(resolve, reject) {\n timeout = setTimeout(function() {\n reject(error);\n }, timeoutMillis);\n }),\n ]).then(function(v) {\n clearTimeout(timeout);\n return v;\n }, function(err) {\n clearTimeout(timeout);\n throw err;\n });\n};\n\n/**\n * Exception indicating that the timeout expired.\n */\nTimeoutError = module.exports.TimeoutError = function() {\n Error.call(this)\n this.stack = Error().stack\n this.message = 'Timeout';\n};\n\nTimeoutError.prototype = Object.create(Error.prototype);\nTimeoutError.prototype.name = \"TimeoutError\";\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/promise-timeout/index.js\n// module id = 435\n// module chunks = 0 1","var _ = require('underscore');\n\nmodule.exports = function(AV) {\n var eventSplitter = /\\s+/;\n var slice = Array.prototype.slice;\n\n /**\n * @class\n *\n *
AV.Events is a fork of Backbone's Events module, provided for your\n * convenience.
\n *\n *
A module that can be mixed in to any object in order to provide\n * it with custom events. You may bind callback functions to an event\n * with `on`, or remove these functions with `off`.\n * Triggering an event fires all callbacks in the order that `on` was\n * called.\n *\n * @private\n * @example\n * var object = {};\n * _.extend(object, AV.Events);\n * object.on('expand', function(){ alert('expanded'); });\n * object.trigger('expand');
\n *\n */\n AV.Events = {\n /**\n * Bind one or more space separated events, `events`, to a `callback`\n * function. Passing `\"all\"` will bind the callback to all events fired.\n */\n on: function(events, callback, context) {\n var calls, event, node, tail, list;\n if (!callback) {\n return this;\n }\n events = events.split(eventSplitter);\n calls = this._callbacks || (this._callbacks = {});\n\n // Create an immutable callback list, allowing traversal during\n // modification. The tail is an empty object that will always be used\n // as the next node.\n event = events.shift();\n while (event) {\n list = calls[event];\n node = list ? list.tail : {};\n node.next = tail = {};\n node.context = context;\n node.callback = callback;\n calls[event] = { tail: tail, next: list ? list.next : node };\n event = events.shift();\n }\n\n return this;\n },\n\n /**\n * Remove one or many callbacks. If `context` is null, removes all callbacks\n * with that function. If `callback` is null, removes all callbacks for the\n * event. If `events` is null, removes all bound callbacks for all events.\n */\n off: function(events, callback, context) {\n var event, calls, node, tail, cb, ctx;\n\n // No events, or removing *all* events.\n if (!(calls = this._callbacks)) {\n return;\n }\n if (!(events || callback || context)) {\n delete this._callbacks;\n return this;\n }\n\n // Loop through the listed events and contexts, splicing them out of the\n // linked list of callbacks if appropriate.\n events = events ? events.split(eventSplitter) : _.keys(calls);\n event = events.shift();\n while (event) {\n node = calls[event];\n delete calls[event];\n if (!node || !(callback || context)) {\n continue;\n }\n // Create a new list, omitting the indicated callbacks.\n tail = node.tail;\n node = node.next;\n while (node !== tail) {\n cb = node.callback;\n ctx = node.context;\n if ((callback && cb !== callback) || (context && ctx !== context)) {\n this.on(event, cb, ctx);\n }\n node = node.next;\n }\n event = events.shift();\n }\n\n return this;\n },\n\n /**\n * Trigger one or many events, firing all bound callbacks. Callbacks are\n * passed the same arguments as `trigger` is, apart from the event name\n * (unless you're listening on `\"all\"`, which will cause your callback to\n * receive the true name of the event as the first argument).\n */\n trigger: function(events) {\n var event, node, calls, tail, args, all, rest;\n if (!(calls = this._callbacks)) {\n return this;\n }\n all = calls.all;\n events = events.split(eventSplitter);\n rest = slice.call(arguments, 1);\n\n // For each event, walk through the linked list of callbacks twice,\n // first to trigger the event, then to trigger any `\"all\"` callbacks.\n event = events.shift();\n while (event) {\n node = calls[event];\n if (node) {\n tail = node.tail;\n while ((node = node.next) !== tail) {\n node.callback.apply(node.context || this, rest);\n }\n }\n node = all;\n if (node) {\n tail = node.tail;\n args = [event].concat(rest);\n while ((node = node.next) !== tail) {\n node.callback.apply(node.context || this, args);\n }\n }\n event = events.shift();\n }\n\n return this;\n },\n };\n\n /**\n * @function\n */\n AV.Events.bind = AV.Events.on;\n\n /**\n * @function\n */\n AV.Events.unbind = AV.Events.off;\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/event.js","var _ = require('underscore');\n\n/*global navigator: false */\nmodule.exports = function(AV) {\n /**\n * Creates a new GeoPoint with any of the following forms: \n * @example\n * new GeoPoint(otherGeoPoint)\n * new GeoPoint(30, 30)\n * new GeoPoint([30, 30])\n * new GeoPoint({latitude: 30, longitude: 30})\n * new GeoPoint() // defaults to (0, 0)\n * @class\n *\n *
Represents a latitude / longitude point that may be associated\n * with a key in a AVObject or used as a reference point for geo queries.\n * This allows proximity-based queries on the key.
\n *\n *
Only one key in a class may contain a GeoPoint.
\n *\n *
Example:
\n * var point = new AV.GeoPoint(30.0, -20.0);\n * var object = new AV.Object(\"PlaceObject\");\n * object.set(\"location\", point);\n * object.save();
\n */\n AV.GeoPoint = function(arg1, arg2) {\n if (_.isArray(arg1)) {\n AV.GeoPoint._validate(arg1[0], arg1[1]);\n this.latitude = arg1[0];\n this.longitude = arg1[1];\n } else if (_.isObject(arg1)) {\n AV.GeoPoint._validate(arg1.latitude, arg1.longitude);\n this.latitude = arg1.latitude;\n this.longitude = arg1.longitude;\n } else if (_.isNumber(arg1) && _.isNumber(arg2)) {\n AV.GeoPoint._validate(arg1, arg2);\n this.latitude = arg1;\n this.longitude = arg2;\n } else {\n this.latitude = 0;\n this.longitude = 0;\n }\n\n // Add properties so that anyone using Webkit or Mozilla will get an error\n // if they try to set values that are out of bounds.\n var self = this;\n if (this.__defineGetter__ && this.__defineSetter__) {\n // Use _latitude and _longitude to actually store the values, and add\n // getters and setters for latitude and longitude.\n this._latitude = this.latitude;\n this._longitude = this.longitude;\n this.__defineGetter__('latitude', function() {\n return self._latitude;\n });\n this.__defineGetter__('longitude', function() {\n return self._longitude;\n });\n this.__defineSetter__('latitude', function(val) {\n AV.GeoPoint._validate(val, self.longitude);\n self._latitude = val;\n });\n this.__defineSetter__('longitude', function(val) {\n AV.GeoPoint._validate(self.latitude, val);\n self._longitude = val;\n });\n }\n };\n\n /**\n * @lends AV.GeoPoint.prototype\n * @property {float} latitude North-south portion of the coordinate, in range\n * [-90, 90]. Throws an exception if set out of range in a modern browser.\n * @property {float} longitude East-west portion of the coordinate, in range\n * [-180, 180]. Throws if set out of range in a modern browser.\n */\n\n /**\n * Throws an exception if the given lat-long is out of bounds.\n * @private\n */\n AV.GeoPoint._validate = function(latitude, longitude) {\n if (latitude < -90.0) {\n throw new Error('AV.GeoPoint latitude ' + latitude + ' < -90.0.');\n }\n if (latitude > 90.0) {\n throw new Error('AV.GeoPoint latitude ' + latitude + ' > 90.0.');\n }\n if (longitude < -180.0) {\n throw new Error('AV.GeoPoint longitude ' + longitude + ' < -180.0.');\n }\n if (longitude > 180.0) {\n throw new Error('AV.GeoPoint longitude ' + longitude + ' > 180.0.');\n }\n };\n\n /**\n * Creates a GeoPoint with the user's current location, if available.\n * @return {Promise.}\n */\n AV.GeoPoint.current = () =>\n new Promise((resolve, reject) => {\n navigator.geolocation.getCurrentPosition(function(location) {\n resolve(\n new AV.GeoPoint({\n latitude: location.coords.latitude,\n longitude: location.coords.longitude,\n })\n );\n }, reject);\n });\n\n _.extend(\n AV.GeoPoint.prototype,\n /** @lends AV.GeoPoint.prototype */ {\n /**\n * Returns a JSON representation of the GeoPoint, suitable for AV.\n * @return {Object}\n */\n toJSON: function() {\n AV.GeoPoint._validate(this.latitude, this.longitude);\n return {\n __type: 'GeoPoint',\n latitude: this.latitude,\n longitude: this.longitude,\n };\n },\n\n /**\n * Returns the distance from this GeoPoint to another in radians.\n * @param {AV.GeoPoint} point the other AV.GeoPoint.\n * @return {Number}\n */\n radiansTo: function(point) {\n var d2r = Math.PI / 180.0;\n var lat1rad = this.latitude * d2r;\n var long1rad = this.longitude * d2r;\n var lat2rad = point.latitude * d2r;\n var long2rad = point.longitude * d2r;\n var deltaLat = lat1rad - lat2rad;\n var deltaLong = long1rad - long2rad;\n var sinDeltaLatDiv2 = Math.sin(deltaLat / 2);\n var sinDeltaLongDiv2 = Math.sin(deltaLong / 2);\n // Square of half the straight line chord distance between both points.\n var a =\n sinDeltaLatDiv2 * sinDeltaLatDiv2 +\n Math.cos(lat1rad) *\n Math.cos(lat2rad) *\n sinDeltaLongDiv2 *\n sinDeltaLongDiv2;\n a = Math.min(1.0, a);\n return 2 * Math.asin(Math.sqrt(a));\n },\n\n /**\n * Returns the distance from this GeoPoint to another in kilometers.\n * @param {AV.GeoPoint} point the other AV.GeoPoint.\n * @return {Number}\n */\n kilometersTo: function(point) {\n return this.radiansTo(point) * 6371.0;\n },\n\n /**\n * Returns the distance from this GeoPoint to another in miles.\n * @param {AV.GeoPoint} point the other AV.GeoPoint.\n * @return {Number}\n */\n milesTo: function(point) {\n return this.radiansTo(point) * 3958.8;\n },\n }\n );\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/geopoint.js","var _ = require('underscore');\n\nmodule.exports = function(AV) {\n var PUBLIC_KEY = '*';\n\n /**\n * Creates a new ACL.\n * If no argument is given, the ACL has no permissions for anyone.\n * If the argument is a AV.User, the ACL will have read and write\n * permission for only that user.\n * If the argument is any other JSON object, that object will be interpretted\n * as a serialized ACL created with toJSON().\n * @see AV.Object#setACL\n * @class\n *\n *
An ACL, or Access Control List can be added to any\n * AV.Object to restrict access to only a subset of users\n * of your application.
\n */\n AV.ACL = function(arg1) {\n var self = this;\n self.permissionsById = {};\n if (_.isObject(arg1)) {\n if (arg1 instanceof AV.User) {\n self.setReadAccess(arg1, true);\n self.setWriteAccess(arg1, true);\n } else {\n if (_.isFunction(arg1)) {\n throw new Error(\n 'AV.ACL() called with a function. Did you forget ()?'\n );\n }\n AV._objectEach(arg1, function(accessList, userId) {\n if (!_.isString(userId)) {\n throw new Error('Tried to create an ACL with an invalid userId.');\n }\n self.permissionsById[userId] = {};\n AV._objectEach(accessList, function(allowed, permission) {\n if (permission !== 'read' && permission !== 'write') {\n throw new Error(\n 'Tried to create an ACL with an invalid permission type.'\n );\n }\n if (!_.isBoolean(allowed)) {\n throw new Error(\n 'Tried to create an ACL with an invalid permission value.'\n );\n }\n self.permissionsById[userId][permission] = allowed;\n });\n });\n }\n }\n };\n\n /**\n * Returns a JSON-encoded version of the ACL.\n * @return {Object}\n */\n AV.ACL.prototype.toJSON = function() {\n return _.clone(this.permissionsById);\n };\n\n AV.ACL.prototype._setAccess = function(accessType, userId, allowed) {\n if (userId instanceof AV.User) {\n userId = userId.id;\n } else if (userId instanceof AV.Role) {\n userId = 'role:' + userId.getName();\n }\n if (!_.isString(userId)) {\n throw new Error('userId must be a string.');\n }\n if (!_.isBoolean(allowed)) {\n throw new Error('allowed must be either true or false.');\n }\n var permissions = this.permissionsById[userId];\n if (!permissions) {\n if (!allowed) {\n // The user already doesn't have this permission, so no action needed.\n return;\n } else {\n permissions = {};\n this.permissionsById[userId] = permissions;\n }\n }\n\n if (allowed) {\n this.permissionsById[userId][accessType] = true;\n } else {\n delete permissions[accessType];\n if (_.isEmpty(permissions)) {\n delete this.permissionsById[userId];\n }\n }\n };\n\n AV.ACL.prototype._getAccess = function(accessType, userId) {\n if (userId instanceof AV.User) {\n userId = userId.id;\n } else if (userId instanceof AV.Role) {\n userId = 'role:' + userId.getName();\n }\n var permissions = this.permissionsById[userId];\n if (!permissions) {\n return false;\n }\n return permissions[accessType] ? true : false;\n };\n\n /**\n * Set whether the given user is allowed to read this object.\n * @param userId An instance of AV.User or its objectId.\n * @param {Boolean} allowed Whether that user should have read access.\n */\n AV.ACL.prototype.setReadAccess = function(userId, allowed) {\n this._setAccess('read', userId, allowed);\n };\n\n /**\n * Get whether the given user id is *explicitly* allowed to read this object.\n * Even if this returns false, the user may still be able to access it if\n * getPublicReadAccess returns true or a role that the user belongs to has\n * write access.\n * @param userId An instance of AV.User or its objectId, or a AV.Role.\n * @return {Boolean}\n */\n AV.ACL.prototype.getReadAccess = function(userId) {\n return this._getAccess('read', userId);\n };\n\n /**\n * Set whether the given user id is allowed to write this object.\n * @param userId An instance of AV.User or its objectId, or a AV.Role..\n * @param {Boolean} allowed Whether that user should have write access.\n */\n AV.ACL.prototype.setWriteAccess = function(userId, allowed) {\n this._setAccess('write', userId, allowed);\n };\n\n /**\n * Get whether the given user id is *explicitly* allowed to write this object.\n * Even if this returns false, the user may still be able to write it if\n * getPublicWriteAccess returns true or a role that the user belongs to has\n * write access.\n * @param userId An instance of AV.User or its objectId, or a AV.Role.\n * @return {Boolean}\n */\n AV.ACL.prototype.getWriteAccess = function(userId) {\n return this._getAccess('write', userId);\n };\n\n /**\n * Set whether the public is allowed to read this object.\n * @param {Boolean} allowed\n */\n AV.ACL.prototype.setPublicReadAccess = function(allowed) {\n this.setReadAccess(PUBLIC_KEY, allowed);\n };\n\n /**\n * Get whether the public is allowed to read this object.\n * @return {Boolean}\n */\n AV.ACL.prototype.getPublicReadAccess = function() {\n return this.getReadAccess(PUBLIC_KEY);\n };\n\n /**\n * Set whether the public is allowed to write this object.\n * @param {Boolean} allowed\n */\n AV.ACL.prototype.setPublicWriteAccess = function(allowed) {\n this.setWriteAccess(PUBLIC_KEY, allowed);\n };\n\n /**\n * Get whether the public is allowed to write this object.\n * @return {Boolean}\n */\n AV.ACL.prototype.getPublicWriteAccess = function() {\n return this.getWriteAccess(PUBLIC_KEY);\n };\n\n /**\n * Get whether users belonging to the given role are allowed\n * to read this object. Even if this returns false, the role may\n * still be able to write it if a parent role has read access.\n *\n * @param role The name of the role, or a AV.Role object.\n * @return {Boolean} true if the role has read access. false otherwise.\n * @throws {String} If role is neither a AV.Role nor a String.\n */\n AV.ACL.prototype.getRoleReadAccess = function(role) {\n if (role instanceof AV.Role) {\n // Normalize to the String name\n role = role.getName();\n }\n if (_.isString(role)) {\n return this.getReadAccess('role:' + role);\n }\n throw new Error('role must be a AV.Role or a String');\n };\n\n /**\n * Get whether users belonging to the given role are allowed\n * to write this object. Even if this returns false, the role may\n * still be able to write it if a parent role has write access.\n *\n * @param role The name of the role, or a AV.Role object.\n * @return {Boolean} true if the role has write access. false otherwise.\n * @throws {String} If role is neither a AV.Role nor a String.\n */\n AV.ACL.prototype.getRoleWriteAccess = function(role) {\n if (role instanceof AV.Role) {\n // Normalize to the String name\n role = role.getName();\n }\n if (_.isString(role)) {\n return this.getWriteAccess('role:' + role);\n }\n throw new Error('role must be a AV.Role or a String');\n };\n\n /**\n * Set whether users belonging to the given role are allowed\n * to read this object.\n *\n * @param role The name of the role, or a AV.Role object.\n * @param {Boolean} allowed Whether the given role can read this object.\n * @throws {String} If role is neither a AV.Role nor a String.\n */\n AV.ACL.prototype.setRoleReadAccess = function(role, allowed) {\n if (role instanceof AV.Role) {\n // Normalize to the String name\n role = role.getName();\n }\n if (_.isString(role)) {\n this.setReadAccess('role:' + role, allowed);\n return;\n }\n throw new Error('role must be a AV.Role or a String');\n };\n\n /**\n * Set whether users belonging to the given role are allowed\n * to write this object.\n *\n * @param role The name of the role, or a AV.Role object.\n * @param {Boolean} allowed Whether the given role can write this object.\n * @throws {String} If role is neither a AV.Role nor a String.\n */\n AV.ACL.prototype.setRoleWriteAccess = function(role, allowed) {\n if (role instanceof AV.Role) {\n // Normalize to the String name\n role = role.getName();\n }\n if (_.isString(role)) {\n this.setWriteAccess('role:' + role, allowed);\n return;\n }\n throw new Error('role must be a AV.Role or a String');\n };\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/acl.js","var _ = require('underscore');\n\nmodule.exports = function(AV) {\n /**\n * @private\n * @class\n * A AV.Op is an atomic operation that can be applied to a field in a\n * AV.Object. For example, calling object.set(\"foo\", \"bar\")\n * is an example of a AV.Op.Set. Calling object.unset(\"foo\")\n * is a AV.Op.Unset. These operations are stored in a AV.Object and\n * sent to the server as part of object.save() operations.\n * Instances of AV.Op should be immutable.\n *\n * You should not create subclasses of AV.Op or instantiate AV.Op\n * directly.\n */\n AV.Op = function() {\n this._initialize.apply(this, arguments);\n };\n\n _.extend(\n AV.Op.prototype,\n /** @lends AV.Op.prototype */ {\n _initialize: function() {},\n }\n );\n\n _.extend(AV.Op, {\n /**\n * To create a new Op, call AV.Op._extend();\n * @private\n */\n _extend: AV._extend,\n\n // A map of __op string to decoder function.\n _opDecoderMap: {},\n\n /**\n * Registers a function to convert a json object with an __op field into an\n * instance of a subclass of AV.Op.\n * @private\n */\n _registerDecoder: function(opName, decoder) {\n AV.Op._opDecoderMap[opName] = decoder;\n },\n\n /**\n * Converts a json object into an instance of a subclass of AV.Op.\n * @private\n */\n _decode: function(json) {\n var decoder = AV.Op._opDecoderMap[json.__op];\n if (decoder) {\n return decoder(json);\n } else {\n return undefined;\n }\n },\n });\n\n /*\n * Add a handler for Batch ops.\n */\n AV.Op._registerDecoder('Batch', function(json) {\n var op = null;\n AV._arrayEach(json.ops, function(nextOp) {\n nextOp = AV.Op._decode(nextOp);\n op = nextOp._mergeWithPrevious(op);\n });\n return op;\n });\n\n /**\n * @private\n * @class\n * A Set operation indicates that either the field was changed using\n * AV.Object.set, or it is a mutable container that was detected as being\n * changed.\n */\n AV.Op.Set = AV.Op._extend(\n /** @lends AV.Op.Set.prototype */ {\n _initialize: function(value) {\n this._value = value;\n },\n\n /**\n * Returns the new value of this field after the set.\n */\n value: function() {\n return this._value;\n },\n\n /**\n * Returns a JSON version of the operation suitable for sending to AV.\n * @return {Object}\n */\n toJSON: function() {\n return AV._encode(this.value());\n },\n\n _mergeWithPrevious: function(previous) {\n return this;\n },\n\n _estimate: function(oldValue) {\n return this.value();\n },\n }\n );\n\n /**\n * A sentinel value that is returned by AV.Op.Unset._estimate to\n * indicate the field should be deleted. Basically, if you find _UNSET as a\n * value in your object, you should remove that key.\n */\n AV.Op._UNSET = {};\n\n /**\n * @private\n * @class\n * An Unset operation indicates that this field has been deleted from the\n * object.\n */\n AV.Op.Unset = AV.Op._extend(\n /** @lends AV.Op.Unset.prototype */ {\n /**\n * Returns a JSON version of the operation suitable for sending to AV.\n * @return {Object}\n */\n toJSON: function() {\n return { __op: 'Delete' };\n },\n\n _mergeWithPrevious: function(previous) {\n return this;\n },\n\n _estimate: function(oldValue) {\n return AV.Op._UNSET;\n },\n }\n );\n\n AV.Op._registerDecoder('Delete', function(json) {\n return new AV.Op.Unset();\n });\n\n /**\n * @private\n * @class\n * An Increment is an atomic operation where the numeric value for the field\n * will be increased by a given amount.\n */\n AV.Op.Increment = AV.Op._extend(\n /** @lends AV.Op.Increment.prototype */ {\n _initialize: function(amount) {\n this._amount = amount;\n },\n\n /**\n * Returns the amount to increment by.\n * @return {Number} the amount to increment by.\n */\n amount: function() {\n return this._amount;\n },\n\n /**\n * Returns a JSON version of the operation suitable for sending to AV.\n * @return {Object}\n */\n toJSON: function() {\n return { __op: 'Increment', amount: this._amount };\n },\n\n _mergeWithPrevious: function(previous) {\n if (!previous) {\n return this;\n } else if (previous instanceof AV.Op.Unset) {\n return new AV.Op.Set(this.amount());\n } else if (previous instanceof AV.Op.Set) {\n return new AV.Op.Set(previous.value() + this.amount());\n } else if (previous instanceof AV.Op.Increment) {\n return new AV.Op.Increment(this.amount() + previous.amount());\n } else {\n throw new Error('Op is invalid after previous op.');\n }\n },\n\n _estimate: function(oldValue) {\n if (!oldValue) {\n return this.amount();\n }\n return oldValue + this.amount();\n },\n }\n );\n\n AV.Op._registerDecoder('Increment', function(json) {\n return new AV.Op.Increment(json.amount);\n });\n\n /**\n * @private\n * @class\n * BitAnd is an atomic operation where the given value will be bit and to the\n * value than is stored in this field.\n */\n AV.Op.BitAnd = AV.Op._extend(\n /** @lends AV.Op.BitAnd.prototype */ {\n _initialize(value) {\n this._value = value;\n },\n\n value() {\n return this._value;\n },\n\n /**\n * Returns a JSON version of the operation suitable for sending to AV.\n * @return {Object}\n */\n toJSON() {\n return { __op: 'BitAnd', value: this.value() };\n },\n\n _mergeWithPrevious(previous) {\n if (!previous) {\n return this;\n } else if (previous instanceof AV.Op.Unset) {\n return new AV.Op.Set(0);\n } else if (previous instanceof AV.Op.Set) {\n return new AV.Op.Set(previous.value() & this.value());\n } else {\n throw new Error('Op is invalid after previous op.');\n }\n },\n\n _estimate(oldValue) {\n return oldValue & this.value();\n },\n }\n );\n\n AV.Op._registerDecoder('BitAnd', function(json) {\n return new AV.Op.BitAnd(json.value);\n });\n\n /**\n * @private\n * @class\n * BitOr is an atomic operation where the given value will be bit and to the\n * value than is stored in this field.\n */\n AV.Op.BitOr = AV.Op._extend(\n /** @lends AV.Op.BitOr.prototype */ {\n _initialize(value) {\n this._value = value;\n },\n\n value() {\n return this._value;\n },\n\n /**\n * Returns a JSON version of the operation suitable for sending to AV.\n * @return {Object}\n */\n toJSON() {\n return { __op: 'BitOr', value: this.value() };\n },\n\n _mergeWithPrevious(previous) {\n if (!previous) {\n return this;\n } else if (previous instanceof AV.Op.Unset) {\n return new AV.Op.Set(this.value());\n } else if (previous instanceof AV.Op.Set) {\n return new AV.Op.Set(previous.value() | this.value());\n } else {\n throw new Error('Op is invalid after previous op.');\n }\n },\n\n _estimate(oldValue) {\n return oldValue | this.value();\n },\n }\n );\n\n AV.Op._registerDecoder('BitOr', function(json) {\n return new AV.Op.BitOr(json.value);\n });\n\n /**\n * @private\n * @class\n * BitXor is an atomic operation where the given value will be bit and to the\n * value than is stored in this field.\n */\n AV.Op.BitXor = AV.Op._extend(\n /** @lends AV.Op.BitXor.prototype */ {\n _initialize(value) {\n this._value = value;\n },\n\n value() {\n return this._value;\n },\n\n /**\n * Returns a JSON version of the operation suitable for sending to AV.\n * @return {Object}\n */\n toJSON() {\n return { __op: 'BitXor', value: this.value() };\n },\n\n _mergeWithPrevious(previous) {\n if (!previous) {\n return this;\n } else if (previous instanceof AV.Op.Unset) {\n return new AV.Op.Set(this.value());\n } else if (previous instanceof AV.Op.Set) {\n return new AV.Op.Set(previous.value() ^ this.value());\n } else {\n throw new Error('Op is invalid after previous op.');\n }\n },\n\n _estimate(oldValue) {\n return oldValue ^ this.value();\n },\n }\n );\n\n AV.Op._registerDecoder('BitXor', function(json) {\n return new AV.Op.BitXor(json.value);\n });\n\n /**\n * @private\n * @class\n * Add is an atomic operation where the given objects will be appended to the\n * array that is stored in this field.\n */\n AV.Op.Add = AV.Op._extend(\n /** @lends AV.Op.Add.prototype */ {\n _initialize: function(objects) {\n this._objects = objects;\n },\n\n /**\n * Returns the objects to be added to the array.\n * @return {Array} The objects to be added to the array.\n */\n objects: function() {\n return this._objects;\n },\n\n /**\n * Returns a JSON version of the operation suitable for sending to AV.\n * @return {Object}\n */\n toJSON: function() {\n return { __op: 'Add', objects: AV._encode(this.objects()) };\n },\n\n _mergeWithPrevious: function(previous) {\n if (!previous) {\n return this;\n } else if (previous instanceof AV.Op.Unset) {\n return new AV.Op.Set(this.objects());\n } else if (previous instanceof AV.Op.Set) {\n return new AV.Op.Set(this._estimate(previous.value()));\n } else if (previous instanceof AV.Op.Add) {\n return new AV.Op.Add(previous.objects().concat(this.objects()));\n } else {\n throw new Error('Op is invalid after previous op.');\n }\n },\n\n _estimate: function(oldValue) {\n if (!oldValue) {\n return _.clone(this.objects());\n } else {\n return oldValue.concat(this.objects());\n }\n },\n }\n );\n\n AV.Op._registerDecoder('Add', function(json) {\n return new AV.Op.Add(AV._decode(json.objects));\n });\n\n /**\n * @private\n * @class\n * AddUnique is an atomic operation where the given items will be appended to\n * the array that is stored in this field only if they were not already\n * present in the array.\n */\n AV.Op.AddUnique = AV.Op._extend(\n /** @lends AV.Op.AddUnique.prototype */ {\n _initialize: function(objects) {\n this._objects = _.uniq(objects);\n },\n\n /**\n * Returns the objects to be added to the array.\n * @return {Array} The objects to be added to the array.\n */\n objects: function() {\n return this._objects;\n },\n\n /**\n * Returns a JSON version of the operation suitable for sending to AV.\n * @return {Object}\n */\n toJSON: function() {\n return { __op: 'AddUnique', objects: AV._encode(this.objects()) };\n },\n\n _mergeWithPrevious: function(previous) {\n if (!previous) {\n return this;\n } else if (previous instanceof AV.Op.Unset) {\n return new AV.Op.Set(this.objects());\n } else if (previous instanceof AV.Op.Set) {\n return new AV.Op.Set(this._estimate(previous.value()));\n } else if (previous instanceof AV.Op.AddUnique) {\n return new AV.Op.AddUnique(this._estimate(previous.objects()));\n } else {\n throw new Error('Op is invalid after previous op.');\n }\n },\n\n _estimate: function(oldValue) {\n if (!oldValue) {\n return _.clone(this.objects());\n } else {\n // We can't just take the _.uniq(_.union(...)) of oldValue and\n // this.objects, because the uniqueness may not apply to oldValue\n // (especially if the oldValue was set via .set())\n var newValue = _.clone(oldValue);\n AV._arrayEach(this.objects(), function(obj) {\n if (obj instanceof AV.Object && obj.id) {\n var matchingObj = _.find(newValue, function(anObj) {\n return anObj instanceof AV.Object && anObj.id === obj.id;\n });\n if (!matchingObj) {\n newValue.push(obj);\n } else {\n var index = _.indexOf(newValue, matchingObj);\n newValue[index] = obj;\n }\n } else if (!_.contains(newValue, obj)) {\n newValue.push(obj);\n }\n });\n return newValue;\n }\n },\n }\n );\n\n AV.Op._registerDecoder('AddUnique', function(json) {\n return new AV.Op.AddUnique(AV._decode(json.objects));\n });\n\n /**\n * @private\n * @class\n * Remove is an atomic operation where the given objects will be removed from\n * the array that is stored in this field.\n */\n AV.Op.Remove = AV.Op._extend(\n /** @lends AV.Op.Remove.prototype */ {\n _initialize: function(objects) {\n this._objects = _.uniq(objects);\n },\n\n /**\n * Returns the objects to be removed from the array.\n * @return {Array} The objects to be removed from the array.\n */\n objects: function() {\n return this._objects;\n },\n\n /**\n * Returns a JSON version of the operation suitable for sending to AV.\n * @return {Object}\n */\n toJSON: function() {\n return { __op: 'Remove', objects: AV._encode(this.objects()) };\n },\n\n _mergeWithPrevious: function(previous) {\n if (!previous) {\n return this;\n } else if (previous instanceof AV.Op.Unset) {\n return previous;\n } else if (previous instanceof AV.Op.Set) {\n return new AV.Op.Set(this._estimate(previous.value()));\n } else if (previous instanceof AV.Op.Remove) {\n return new AV.Op.Remove(_.union(previous.objects(), this.objects()));\n } else {\n throw new Error('Op is invalid after previous op.');\n }\n },\n\n _estimate: function(oldValue) {\n if (!oldValue) {\n return [];\n } else {\n var newValue = _.difference(oldValue, this.objects());\n // If there are saved AV Objects being removed, also remove them.\n AV._arrayEach(this.objects(), function(obj) {\n if (obj instanceof AV.Object && obj.id) {\n newValue = _.reject(newValue, function(other) {\n return other instanceof AV.Object && other.id === obj.id;\n });\n }\n });\n return newValue;\n }\n },\n }\n );\n\n AV.Op._registerDecoder('Remove', function(json) {\n return new AV.Op.Remove(AV._decode(json.objects));\n });\n\n /**\n * @private\n * @class\n * A Relation operation indicates that the field is an instance of\n * AV.Relation, and objects are being added to, or removed from, that\n * relation.\n */\n AV.Op.Relation = AV.Op._extend(\n /** @lends AV.Op.Relation.prototype */ {\n _initialize: function(adds, removes) {\n this._targetClassName = null;\n\n var self = this;\n\n var pointerToId = function(object) {\n if (object instanceof AV.Object) {\n if (!object.id) {\n throw new Error(\n \"You can't add an unsaved AV.Object to a relation.\"\n );\n }\n if (!self._targetClassName) {\n self._targetClassName = object.className;\n }\n if (self._targetClassName !== object.className) {\n throw new Error(\n 'Tried to create a AV.Relation with 2 different types: ' +\n self._targetClassName +\n ' and ' +\n object.className +\n '.'\n );\n }\n return object.id;\n }\n return object;\n };\n\n this.relationsToAdd = _.uniq(_.map(adds, pointerToId));\n this.relationsToRemove = _.uniq(_.map(removes, pointerToId));\n },\n\n /**\n * Returns an array of unfetched AV.Object that are being added to the\n * relation.\n * @return {Array}\n */\n added: function() {\n var self = this;\n return _.map(this.relationsToAdd, function(objectId) {\n var object = AV.Object._create(self._targetClassName);\n object.id = objectId;\n return object;\n });\n },\n\n /**\n * Returns an array of unfetched AV.Object that are being removed from\n * the relation.\n * @return {Array}\n */\n removed: function() {\n var self = this;\n return _.map(this.relationsToRemove, function(objectId) {\n var object = AV.Object._create(self._targetClassName);\n object.id = objectId;\n return object;\n });\n },\n\n /**\n * Returns a JSON version of the operation suitable for sending to AV.\n * @return {Object}\n */\n toJSON: function() {\n var adds = null;\n var removes = null;\n var self = this;\n var idToPointer = function(id) {\n return {\n __type: 'Pointer',\n className: self._targetClassName,\n objectId: id,\n };\n };\n var pointers = null;\n if (this.relationsToAdd.length > 0) {\n pointers = _.map(this.relationsToAdd, idToPointer);\n adds = { __op: 'AddRelation', objects: pointers };\n }\n\n if (this.relationsToRemove.length > 0) {\n pointers = _.map(this.relationsToRemove, idToPointer);\n removes = { __op: 'RemoveRelation', objects: pointers };\n }\n\n if (adds && removes) {\n return { __op: 'Batch', ops: [adds, removes] };\n }\n\n return adds || removes || {};\n },\n\n _mergeWithPrevious: function(previous) {\n if (!previous) {\n return this;\n } else if (previous instanceof AV.Op.Unset) {\n throw new Error(\"You can't modify a relation after deleting it.\");\n } else if (previous instanceof AV.Op.Relation) {\n if (\n previous._targetClassName &&\n previous._targetClassName !== this._targetClassName\n ) {\n throw new Error(\n 'Related object must be of class ' +\n previous._targetClassName +\n ', but ' +\n this._targetClassName +\n ' was passed in.'\n );\n }\n var newAdd = _.union(\n _.difference(previous.relationsToAdd, this.relationsToRemove),\n this.relationsToAdd\n );\n var newRemove = _.union(\n _.difference(previous.relationsToRemove, this.relationsToAdd),\n this.relationsToRemove\n );\n\n var newRelation = new AV.Op.Relation(newAdd, newRemove);\n newRelation._targetClassName = this._targetClassName;\n return newRelation;\n } else {\n throw new Error('Op is invalid after previous op.');\n }\n },\n\n _estimate: function(oldValue, object, key) {\n if (!oldValue) {\n var relation = new AV.Relation(object, key);\n relation.targetClassName = this._targetClassName;\n } else if (oldValue instanceof AV.Relation) {\n if (this._targetClassName) {\n if (oldValue.targetClassName) {\n if (oldValue.targetClassName !== this._targetClassName) {\n throw new Error(\n 'Related object must be a ' +\n oldValue.targetClassName +\n ', but a ' +\n this._targetClassName +\n ' was passed in.'\n );\n }\n } else {\n oldValue.targetClassName = this._targetClassName;\n }\n }\n return oldValue;\n } else {\n throw new Error('Op is invalid after previous op.');\n }\n },\n }\n );\n\n AV.Op._registerDecoder('AddRelation', function(json) {\n return new AV.Op.Relation(AV._decode(json.objects), []);\n });\n AV.Op._registerDecoder('RemoveRelation', function(json) {\n return new AV.Op.Relation([], AV._decode(json.objects));\n });\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/op.js","var parent = require('../../es/instance/find');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/stable/instance/find.js\n// module id = 440\n// module chunks = 0 1","var isPrototypeOf = require('../../internals/object-is-prototype-of');\nvar method = require('../array/virtual/find');\n\nvar ArrayPrototype = Array.prototype;\n\nmodule.exports = function (it) {\n var own = it.find;\n return it === ArrayPrototype || (isPrototypeOf(ArrayPrototype, it) && own === ArrayPrototype.find) ? method : own;\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/es/instance/find.js\n// module id = 441\n// module chunks = 0 1","require('../../../modules/es.array.find');\nvar entryVirtual = require('../../../internals/entry-virtual');\n\nmodule.exports = entryVirtual('Array').find;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/es/array/virtual/find.js\n// module id = 442\n// module chunks = 0 1","'use strict';\nvar $ = require('../internals/export');\nvar $find = require('../internals/array-iteration').find;\nvar addToUnscopables = require('../internals/add-to-unscopables');\n\nvar FIND = 'find';\nvar SKIPS_HOLES = true;\n\n// Shouldn't skip holes\nif (FIND in []) Array(1)[FIND](function () { SKIPS_HOLES = false; });\n\n// `Array.prototype.find` method\n// https://tc39.es/ecma262/#sec-array.prototype.find\n$({ target: 'Array', proto: true, forced: SKIPS_HOLES }, {\n find: function find(callbackfn /* , that = undefined */) {\n return $find(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);\n }\n});\n\n// https://tc39.es/ecma262/#sec-array.prototype-@@unscopables\naddToUnscopables(FIND);\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.array.find.js\n// module id = 443\n// module chunks = 0 1","var _ = require('underscore');\n\nmodule.exports = function(AV) {\n /**\n * Creates a new Relation for the given parent object and key. This\n * constructor should rarely be used directly, but rather created by\n * {@link AV.Object#relation}.\n * @param {AV.Object} parent The parent of this relation.\n * @param {String} key The key for this relation on the parent.\n * @see AV.Object#relation\n * @class\n *\n *
\n * A class that is used to access all of the children of a many-to-many\n * relationship. Each instance of AV.Relation is associated with a\n * particular parent object and key.\n *
\n */\n AV.Relation = function(parent, key) {\n if (!_.isString(key)) {\n throw new TypeError('key must be a string');\n }\n this.parent = parent;\n this.key = key;\n this.targetClassName = null;\n };\n\n /**\n * Creates a query that can be used to query the parent objects in this relation.\n * @param {String} parentClass The parent class or name.\n * @param {String} relationKey The relation field key in parent.\n * @param {AV.Object} child The child object.\n * @return {AV.Query}\n */\n AV.Relation.reverseQuery = function(parentClass, relationKey, child) {\n var query = new AV.Query(parentClass);\n query.equalTo(relationKey, child._toPointer());\n return query;\n };\n\n _.extend(\n AV.Relation.prototype,\n /** @lends AV.Relation.prototype */ {\n /**\n * Makes sure that this relation has the right parent and key.\n * @private\n */\n _ensureParentAndKey: function(parent, key) {\n this.parent = this.parent || parent;\n this.key = this.key || key;\n if (this.parent !== parent) {\n throw new Error(\n 'Internal Error. Relation retrieved from two different Objects.'\n );\n }\n if (this.key !== key) {\n throw new Error(\n 'Internal Error. Relation retrieved from two different keys.'\n );\n }\n },\n\n /**\n * Adds a AV.Object or an array of AV.Objects to the relation.\n * @param {AV.Object|AV.Object[]} objects The item or items to add.\n */\n add: function(objects) {\n if (!_.isArray(objects)) {\n objects = [objects];\n }\n\n var change = new AV.Op.Relation(objects, []);\n this.parent.set(this.key, change);\n this.targetClassName = change._targetClassName;\n },\n\n /**\n * Removes a AV.Object or an array of AV.Objects from this relation.\n * @param {AV.Object|AV.Object[]} objects The item or items to remove.\n */\n remove: function(objects) {\n if (!_.isArray(objects)) {\n objects = [objects];\n }\n\n var change = new AV.Op.Relation([], objects);\n this.parent.set(this.key, change);\n this.targetClassName = change._targetClassName;\n },\n\n /**\n * Returns a JSON version of the object suitable for saving to disk.\n * @return {Object}\n */\n toJSON: function() {\n return { __type: 'Relation', className: this.targetClassName };\n },\n\n /**\n * Returns a AV.Query that is limited to objects in this\n * relation.\n * @return {AV.Query}\n */\n query: function() {\n var targetClass;\n var query;\n if (!this.targetClassName) {\n targetClass = AV.Object._getSubclass(this.parent.className);\n query = new AV.Query(targetClass);\n query._defaultParams.redirectClassNameForKey = this.key;\n } else {\n targetClass = AV.Object._getSubclass(this.targetClassName);\n query = new AV.Query(targetClass);\n }\n query._addCondition('$relatedTo', 'object', this.parent._toPointer());\n query._addCondition('$relatedTo', 'key', this.key);\n\n return query;\n },\n }\n );\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/relation.js","const _ = require('underscore');\nconst cos = require('./uploader/cos');\nconst qiniu = require('./uploader/qiniu');\nconst s3 = require('./uploader/s3');\nconst AVError = require('./error');\nconst { request, _request: AVRequest } = require('./request');\nconst { tap, transformFetchOptions } = require('./utils');\nconst debug = require('debug')('leancloud:file');\nconst parseBase64 = require('./utils/parse-base64');\n\nmodule.exports = function(AV) {\n // port from browserify path module\n // since react-native packager won't shim node modules.\n const extname = path => {\n if (!_.isString(path)) return '';\n return path.match(\n /^(\\/?|)([\\s\\S]*?)((?:\\.{1,2}|[^\\/]+?|)(\\.[^.\\/]*|))(?:[\\/]*)$/\n )[4];\n };\n\n const b64Digit = number => {\n if (number < 26) {\n return String.fromCharCode(65 + number);\n }\n if (number < 52) {\n return String.fromCharCode(97 + (number - 26));\n }\n if (number < 62) {\n return String.fromCharCode(48 + (number - 52));\n }\n if (number === 62) {\n return '+';\n }\n if (number === 63) {\n return '/';\n }\n throw new Error('Tried to encode large digit ' + number + ' in base64.');\n };\n\n var encodeBase64 = function(array) {\n var chunks = [];\n chunks.length = Math.ceil(array.length / 3);\n _.times(chunks.length, function(i) {\n var b1 = array[i * 3];\n var b2 = array[i * 3 + 1] || 0;\n var b3 = array[i * 3 + 2] || 0;\n\n var has2 = i * 3 + 1 < array.length;\n var has3 = i * 3 + 2 < array.length;\n\n chunks[i] = [\n b64Digit((b1 >> 2) & 0x3f),\n b64Digit(((b1 << 4) & 0x30) | ((b2 >> 4) & 0x0f)),\n has2 ? b64Digit(((b2 << 2) & 0x3c) | ((b3 >> 6) & 0x03)) : '=',\n has3 ? b64Digit(b3 & 0x3f) : '=',\n ].join('');\n });\n return chunks.join('');\n };\n\n /**\n * An AV.File is a local representation of a file that is saved to the AV\n * cloud.\n * @param name {String} The file's name. This will change to a unique value\n * once the file has finished saving.\n * @param data {Array} The data for the file, as either:\n * 1. an Array of byte value Numbers, or\n * 2. an Object like { base64: \"...\" } with a base64-encoded String.\n * 3. a Blob(File) selected with a file upload control in a browser.\n * 4. an Object like { blob: {uri: \"...\"} } that mimics Blob\n * in some non-browser environments such as React Native.\n * 5. a Buffer in Node.js runtime.\n * 6. a Stream in Node.js runtime.\n *\n * For example:
\n * var fileUploadControl = $(\"#profilePhotoFileUpload\")[0];\n * if (fileUploadControl.files.length > 0) {\n * var file = fileUploadControl.files[0];\n * var name = \"photo.jpg\";\n * var file = new AV.File(name, file);\n * file.save().then(function() {\n * // The file has been saved to AV.\n * }, function(error) {\n * // The file either could not be read, or could not be saved to AV.\n * });\n * }
\n *\n * @class\n * @param [mimeType] {String} Content-Type header to use for the file. If\n * this is omitted, the content type will be inferred from the name's\n * extension.\n */\n AV.File = function(name, data, mimeType) {\n this.attributes = {\n name,\n url: '',\n metaData: {},\n // 用来存储转换后要上传的 base64 String\n base64: '',\n };\n\n if (_.isString(data)) {\n throw new TypeError(\n 'Creating an AV.File from a String is not yet supported.'\n );\n }\n if (_.isArray(data)) {\n this.attributes.metaData.size = data.length;\n data = { base64: encodeBase64(data) };\n }\n\n this._extName = '';\n this._data = data;\n this._uploadHeaders = {};\n\n if (data && data.blob && typeof data.blob.uri === 'string') {\n this._extName = extname(data.blob.uri);\n }\n\n if (typeof Blob !== 'undefined' && data instanceof Blob) {\n if (data.size) {\n this.attributes.metaData.size = data.size;\n }\n if (data.name) {\n this._extName = extname(data.name);\n }\n }\n\n\n let owner;\n if (data && data.owner) {\n owner = data.owner;\n } else if (!AV._config.disableCurrentUser) {\n try {\n owner = AV.User.current();\n } catch (error) {\n if ('SYNC_API_NOT_AVAILABLE' !== error.code) {\n throw error;\n }\n }\n }\n\n this.attributes.metaData.owner = owner ? owner.id : 'unknown';\n\n this.set('mime_type', mimeType);\n };\n\n /**\n * Creates a fresh AV.File object with exists url for saving to AVOS Cloud.\n * @param {String} name the file name\n * @param {String} url the file url.\n * @param {Object} [metaData] the file metadata object.\n * @param {String} [type] Content-Type header to use for the file. If\n * this is omitted, the content type will be inferred from the name's\n * extension.\n * @return {AV.File} the file object\n */\n AV.File.withURL = function(name, url, metaData, type) {\n if (!name || !url) {\n throw new Error('Please provide file name and url');\n }\n var file = new AV.File(name, null, type);\n //copy metaData properties to file.\n if (metaData) {\n for (var prop in metaData) {\n if (!file.attributes.metaData[prop])\n file.attributes.metaData[prop] = metaData[prop];\n }\n }\n file.attributes.url = url;\n //Mark the file is from external source.\n file.attributes.metaData.__source = 'external';\n file.attributes.metaData.size = 0;\n return file;\n };\n\n /**\n * Creates a file object with exists objectId.\n * @param {String} objectId The objectId string\n * @return {AV.File} the file object\n */\n AV.File.createWithoutData = function(objectId) {\n if (!objectId) {\n throw new TypeError('The objectId must be provided');\n }\n var file = new AV.File();\n file.id = objectId;\n return file;\n };\n\n /**\n * Request file censor.\n * @since 4.13.0\n * @param {String} objectId\n * @return {Promise.}\n */\n AV.File.censor = function(objectId) {\n if (!AV._config.masterKey) {\n throw new Error('Cannot censor a file without masterKey');\n }\n return request({\n method: 'POST',\n path: `/files/${objectId}/censor`,\n authOptions: { useMasterKey: true },\n }).then(res => res.censorResult);\n };\n\n _.extend(\n AV.File.prototype,\n /** @lends AV.File.prototype */ {\n className: '_File',\n\n _toFullJSON(seenObjects, full = true) {\n var json = _.clone(this.attributes);\n AV._objectEach(json, function(val, key) {\n json[key] = AV._encode(val, seenObjects, undefined, full);\n });\n AV._objectEach(this._operations, function(val, key) {\n json[key] = val;\n });\n\n if (_.has(this, 'id')) {\n json.objectId = this.id;\n }\n ['createdAt', 'updatedAt'].forEach(key => {\n if (_.has(this, key)) {\n const val = this[key];\n json[key] = _.isDate(val) ? val.toJSON() : val;\n }\n });\n if (full) {\n json.__type = 'File';\n }\n return json;\n },\n\n /**\n * Returns a JSON version of the file with meta data.\n * Inverse to {@link AV.parseJSON}\n * @since 3.0.0\n * @return {Object}\n */\n toFullJSON(seenObjects = []) {\n return this._toFullJSON(seenObjects);\n },\n\n /**\n * Returns a JSON version of the object.\n * @return {Object}\n */\n toJSON(key, holder, seenObjects = [this]) {\n return this._toFullJSON(seenObjects, false);\n },\n\n /**\n * Gets a Pointer referencing this file.\n * @private\n */\n _toPointer() {\n return {\n __type: 'Pointer',\n className: this.className,\n objectId: this.id,\n };\n },\n\n /**\n * Returns the ACL for this file.\n * @returns {AV.ACL} An instance of AV.ACL.\n */\n getACL() {\n return this._acl;\n },\n\n /**\n * Sets the ACL to be used for this file.\n * @param {AV.ACL} acl An instance of AV.ACL.\n */\n setACL(acl) {\n if (!(acl instanceof AV.ACL)) {\n return new AVError(AVError.OTHER_CAUSE, 'ACL must be a AV.ACL.');\n }\n this._acl = acl;\n return this;\n },\n\n /**\n * Gets the name of the file. Before save is called, this is the filename\n * given by the user. After save is called, that name gets prefixed with a\n * unique identifier.\n */\n name() {\n return this.get('name');\n },\n\n /**\n * Gets the url of the file. It is only available after you save the file or\n * after you get the file from a AV.Object.\n * @return {String}\n */\n url() {\n return this.get('url');\n },\n\n /**\n * Gets the attributs of the file object.\n * @param {String} The attribute name which want to get.\n * @returns {Any}\n */\n get(attrName) {\n switch (attrName) {\n case 'objectId':\n return this.id;\n case 'url':\n case 'name':\n case 'mime_type':\n case 'metaData':\n case 'createdAt':\n case 'updatedAt':\n return this.attributes[attrName];\n default:\n return this.attributes.metaData[attrName];\n }\n },\n\n /**\n * Set the metaData of the file object.\n * @param {Object} Object is an key value Object for setting metaData.\n * @param {String} attr is an optional metadata key.\n * @param {Object} value is an optional metadata value.\n * @returns {String|Number|Array|Object}\n */\n set(...args) {\n const set = (attrName, value) => {\n switch (attrName) {\n case 'name':\n case 'url':\n case 'mime_type':\n case 'base64':\n case 'metaData':\n this.attributes[attrName] = value;\n break;\n default:\n // File 并非一个 AVObject,不能完全自定义其他属性,所以只能都放在 metaData 上面\n this.attributes.metaData[attrName] = value;\n break;\n }\n };\n\n switch (args.length) {\n case 1:\n // 传入一个 Object\n for (var k in args[0]) {\n set(k, args[0][k]);\n }\n break;\n case 2:\n set(args[0], args[1]);\n break;\n }\n return this;\n },\n\n /**\n * Set a header for the upload request.\n * For more infomation, go to https://url.leanapp.cn/avfile-upload-headers\n *\n * @param {String} key header key\n * @param {String} value header value\n * @return {AV.File} this\n */\n setUploadHeader(key, value) {\n this._uploadHeaders[key] = value;\n return this;\n },\n\n /**\n *
Returns the file's metadata JSON object if no arguments is given.Returns the\n * metadata value if a key is given.Set metadata value if key and value are both given.
\n *
\n * var metadata = file.metaData(); //Get metadata JSON object.\n * var size = file.metaData('size'); // Get the size metadata value.\n * file.metaData('format', 'jpeg'); //set metadata attribute and value.\n *
\n * @return {Object} The file's metadata JSON object.\n * @param {String} attr an optional metadata key.\n * @param {Object} value an optional metadata value.\n **/\n metaData(attr, value) {\n if (attr && value) {\n this.attributes.metaData[attr] = value;\n return this;\n } else if (attr && !value) {\n return this.attributes.metaData[attr];\n } else {\n return this.attributes.metaData;\n }\n },\n\n /**\n * 如果文件是图片,获取图片的缩略图URL。可以传入宽度、高度、质量、格式等参数。\n * @return {String} 缩略图URL\n * @param {Number} width 宽度,单位:像素\n * @param {Number} heigth 高度,单位:像素\n * @param {Number} quality 质量,1-100的数字,默认100\n * @param {Number} scaleToFit 是否将图片自适应大小。默认为true。\n * @param {String} fmt 格式,默认为png,也可以为jpeg,gif等格式。\n */\n\n thumbnailURL(\n width,\n height,\n quality = 100,\n scaleToFit = true,\n fmt = 'png'\n ) {\n const url = this.attributes.url;\n if (!url) {\n throw new Error('Invalid url.');\n }\n if (!width || !height || width <= 0 || height <= 0) {\n throw new Error('Invalid width or height value.');\n }\n if (quality <= 0 || quality > 100) {\n throw new Error('Invalid quality value.');\n }\n const mode = scaleToFit ? 2 : 1;\n return (\n url +\n '?imageView/' +\n mode +\n '/w/' +\n width +\n '/h/' +\n height +\n '/q/' +\n quality +\n '/format/' +\n fmt\n );\n },\n\n /**\n * Returns the file's size.\n * @return {Number} The file's size in bytes.\n **/\n size() {\n return this.metaData().size;\n },\n\n /**\n * Returns the file's owner.\n * @return {String} The file's owner id.\n */\n ownerId() {\n return this.metaData().owner;\n },\n\n /**\n * Destroy the file.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled when the destroy\n * completes.\n */\n destroy(options) {\n if (!this.id) {\n return Promise.reject(new Error('The file id does not eixst.'));\n }\n var request = AVRequest(\n 'files',\n null,\n this.id,\n 'DELETE',\n null,\n options\n );\n return request;\n },\n\n /**\n * Request Qiniu upload token\n * @param {string} type\n * @return {Promise} Resolved with the response\n * @private\n */\n _fileToken(type, authOptions) {\n let name = this.attributes.name;\n\n let extName = extname(name);\n if (!extName && this._extName) {\n name += this._extName;\n extName = this._extName;\n }\n const data = {\n name,\n keep_file_name: authOptions.keepFileName,\n key: authOptions.key,\n ACL: this._acl,\n mime_type: type,\n metaData: this.attributes.metaData,\n };\n return AVRequest('fileTokens', null, null, 'POST', data, authOptions);\n },\n\n /**\n * @callback UploadProgressCallback\n * @param {XMLHttpRequestProgressEvent} event - The progress event with 'loaded' and 'total' attributes\n */\n /**\n * Saves the file to the AV cloud.\n * @param {AuthOptions} [options] AuthOptions plus:\n * @param {UploadProgressCallback} [options.onprogress] 文件上传进度,在 Node.js 中无效,回调参数说明详见 {@link UploadProgressCallback}。\n * @param {boolean} [options.keepFileName = false] 保留下载文件的文件名。\n * @param {string} [options.key] 指定文件的 key。设置该选项需要使用 masterKey\n * @return {Promise} Promise that is resolved when the save finishes.\n */\n save(options = {}) {\n if (this.id) {\n throw new Error('File is already saved.');\n }\n if (!this._previousSave) {\n if (this._data) {\n let mimeType = this.get('mime_type');\n this._previousSave = this._fileToken(mimeType, options).then(\n uploadInfo => {\n if (uploadInfo.mime_type) {\n mimeType = uploadInfo.mime_type;\n this.set('mime_type', mimeType);\n }\n this._token = uploadInfo.token;\n return Promise.resolve()\n .then(() => {\n const data = this._data;\n if (data && data.base64) {\n return parseBase64(data.base64, mimeType);\n }\n if (data && data.blob) {\n if (!data.blob.type && mimeType) {\n data.blob.type = mimeType;\n }\n if (!data.blob.name) {\n data.blob.name = this.get('name');\n }\n return data.blob;\n }\n if (typeof Blob !== 'undefined' && data instanceof Blob) {\n return data;\n }\n throw new TypeError('malformed file data');\n })\n .then(data => {\n const _options = _.extend({}, options);\n // filter out download progress events\n if (options.onprogress) {\n _options.onprogress = event => {\n if (event.direction === 'download') return;\n return options.onprogress(event);\n };\n }\n switch (uploadInfo.provider) {\n case 's3':\n return s3(uploadInfo, data, this, _options);\n case 'qcloud':\n return cos(uploadInfo, data, this, _options);\n case 'qiniu':\n default:\n return qiniu(uploadInfo, data, this, _options);\n }\n })\n .then(tap(() => this._callback(true)), error => {\n this._callback(false);\n throw error;\n });\n }\n );\n } else if (\n this.attributes.url &&\n this.attributes.metaData.__source === 'external'\n ) {\n // external link file.\n const data = {\n name: this.attributes.name,\n ACL: this._acl,\n metaData: this.attributes.metaData,\n mime_type: this.mimeType,\n url: this.attributes.url,\n };\n this._previousSave = AVRequest(\n 'files',\n null,\n null,\n 'post',\n data,\n options\n ).then(response => {\n this.id = response.objectId;\n return this;\n });\n }\n }\n return this._previousSave;\n },\n\n _callback(success) {\n AVRequest('fileCallback', null, null, 'post', {\n token: this._token,\n result: success,\n }).catch(debug);\n delete this._token;\n delete this._data;\n },\n\n /**\n * fetch the file from server. If the server's representation of the\n * model differs from its current attributes, they will be overriden,\n * @param {Object} fetchOptions Optional options to set 'keys',\n * 'include' and 'includeACL' option.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled when the fetch\n * completes.\n */\n fetch(fetchOptions, options) {\n if (!this.id) {\n throw new Error('Cannot fetch unsaved file');\n }\n var request = AVRequest(\n 'files',\n null,\n this.id,\n 'GET',\n transformFetchOptions(fetchOptions),\n options\n );\n return request.then(this._finishFetch.bind(this));\n },\n _finishFetch(response) {\n var value = AV.Object.prototype.parse(response);\n value.attributes = {\n name: value.name,\n url: value.url,\n mime_type: value.mime_type,\n bucket: value.bucket,\n };\n value.attributes.metaData = value.metaData || {};\n value.id = value.objectId;\n // clean\n delete value.objectId;\n delete value.metaData;\n delete value.url;\n delete value.name;\n delete value.mime_type;\n delete value.bucket;\n _.extend(this, value);\n return this;\n },\n\n /**\n * Request file censor\n * @since 4.13.0\n * @return {Promise.}\n */\n censor() {\n if (!this.id) {\n throw new Error('Cannot censor an unsaved file');\n }\n return AV.File.censor(this.id);\n },\n }\n );\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/file.js","const { getAdapter } = require('../adapter');\nconst debug = require('debug')('cos');\n\nmodule.exports = function(uploadInfo, data, file, saveOptions = {}) {\n const url =\n uploadInfo.upload_url + '?sign=' + encodeURIComponent(uploadInfo.token);\n const fileFormData = {\n field: 'fileContent',\n data,\n name: file.attributes.name,\n };\n const options = {\n headers: file._uploadHeaders,\n data: {\n op: 'upload',\n },\n onprogress: saveOptions.onprogress,\n };\n debug('url: %s, file: %o, options: %o', url, fileFormData, options);\n const upload = getAdapter('upload');\n return upload(url, fileFormData, options).then(\n response => {\n debug(response.status, response.data);\n if (response.ok === false) {\n const error = new Error(response.status);\n error.response = response;\n throw error;\n }\n file.attributes.url = uploadInfo.url;\n file._bucket = uploadInfo.bucket;\n file.id = uploadInfo.objectId;\n return file;\n },\n error => {\n const { response } = error;\n if (response) {\n debug(response.status, response.data);\n error.statusCode = response.status;\n error.response = response.data;\n }\n throw error;\n }\n );\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/uploader/cos.js","const { getAdapter } = require('../adapter');\nconst debug = require('debug')('leancloud:qiniu');\nconst ajax = require('../utils/ajax');\nconst btoa = require('../utils/btoa');\n\nconst SHARD_THRESHOLD = 1024 * 1024 * 64;\n\nconst CHUNK_SIZE = 1024 * 1024 * 16;\n\nfunction upload(uploadInfo, data, file, saveOptions = {}) {\n // Get the uptoken to upload files to qiniu.\n const uptoken = uploadInfo.token;\n const url = uploadInfo.upload_url || 'https://upload.qiniup.com';\n const fileFormData = {\n field: 'file',\n data,\n name: file.attributes.name,\n };\n const options = {\n headers: file._uploadHeaders,\n data: {\n name: file.attributes.name,\n key: uploadInfo.key,\n token: uptoken,\n },\n onprogress: saveOptions.onprogress,\n };\n debug('url: %s, file: %o, options: %o', url, fileFormData, options);\n const upload = getAdapter('upload');\n return upload(url, fileFormData, options).then(\n response => {\n debug(response.status, response.data);\n if (response.ok === false) {\n let message = response.status;\n if (response.data) {\n if (response.data.error) {\n message = response.data.error;\n } else {\n message = JSON.stringify(response.data);\n }\n }\n const error = new Error(message);\n error.response = response;\n throw error;\n }\n file.attributes.url = uploadInfo.url;\n file._bucket = uploadInfo.bucket;\n file.id = uploadInfo.objectId;\n return file;\n },\n error => {\n const { response } = error;\n if (response) {\n debug(response.status, response.data);\n error.statusCode = response.status;\n error.response = response.data;\n }\n throw error;\n }\n );\n}\n\nfunction urlSafeBase64(string) {\n const base64 = btoa(unescape(encodeURIComponent(string)));\n let result = '';\n for (const ch of base64) {\n switch (ch) {\n case '+':\n result += '-';\n break;\n case '/':\n result += '_';\n break;\n default:\n result += ch;\n }\n }\n return result;\n}\n\nclass ShardUploader {\n constructor(uploadInfo, data, file, saveOptions) {\n this.uploadInfo = uploadInfo;\n this.data = data;\n this.file = file;\n this.size = undefined;\n this.offset = 0;\n this.uploadedChunks = 0;\n\n const key = urlSafeBase64(uploadInfo.key);\n const uploadURL = uploadInfo.upload_url || 'https://upload.qiniup.com';\n this.baseURL = `${uploadURL}/buckets/${uploadInfo.bucket}/objects/${key}/uploads`;\n this.upToken = 'UpToken ' + uploadInfo.token;\n\n this.uploaded = 0;\n if (saveOptions && saveOptions.onprogress) {\n this.onProgress = ({ loaded }) => {\n loaded += this.uploadedChunks * CHUNK_SIZE;\n if (loaded <= this.uploaded) {\n return;\n }\n if (this.size) {\n saveOptions.onprogress({\n loaded,\n total: this.size,\n percent: (loaded / this.size) * 100,\n });\n } else {\n saveOptions.onprogress({ loaded });\n }\n this.uploaded = loaded;\n };\n }\n }\n\n /**\n * @returns {Promise}\n */\n getUploadId() {\n return ajax({\n method: 'POST',\n url: this.baseURL,\n headers: {\n Authorization: this.upToken,\n },\n }).then(res => res.uploadId);\n }\n\n getChunk() {\n throw new Error('Not implemented');\n }\n\n /**\n * @param {string} uploadId\n * @param {number} partNumber\n * @param {any} data\n * @returns {Promise<{ partNumber: number, etag: string }>}\n */\n uploadPart(uploadId, partNumber, data) {\n return ajax({\n method: 'PUT',\n url: `${this.baseURL}/${uploadId}/${partNumber}`,\n headers: {\n Authorization: this.upToken,\n },\n data,\n onprogress: this.onProgress,\n }).then(({ etag }) => ({ partNumber, etag }));\n }\n\n stopUpload(uploadId) {\n return ajax({\n method: 'DELETE',\n url: `${this.baseURL}/${uploadId}`,\n headers: {\n Authorization: this.upToken,\n },\n });\n }\n\n upload() {\n const parts = [];\n return this.getUploadId()\n .then(uploadId => {\n const uploadPart = () => {\n return Promise.resolve(this.getChunk())\n .then(chunk => {\n if (!chunk) {\n return;\n }\n const partNumber = parts.length + 1;\n return this.uploadPart(uploadId, partNumber, chunk).then(part => {\n parts.push(part);\n this.uploadedChunks++;\n return uploadPart();\n });\n })\n .catch(error =>\n this.stopUpload(uploadId).then(() => Promise.reject(error))\n );\n };\n\n return uploadPart().then(() =>\n ajax({\n method: 'POST',\n url: `${this.baseURL}/${uploadId}`,\n headers: {\n Authorization: this.upToken,\n },\n data: {\n parts,\n fname: this.file.attributes.name,\n mimeType: this.file.attributes.mime_type,\n },\n })\n );\n })\n .then(() => {\n this.file.attributes.url = this.uploadInfo.url;\n this.file._bucket = this.uploadInfo.bucket;\n this.file.id = this.uploadInfo.objectId;\n return this.file;\n });\n }\n}\n\nclass BlobUploader extends ShardUploader {\n constructor(uploadInfo, data, file, saveOptions) {\n super(uploadInfo, data, file, saveOptions);\n this.size = data.size;\n }\n\n /**\n * @returns {Blob | null}\n */\n getChunk() {\n if (this.offset >= this.size) {\n return null;\n }\n const chunk = this.data.slice(this.offset, this.offset + CHUNK_SIZE);\n this.offset += chunk.size;\n return chunk;\n }\n}\n\n\n\nfunction isBlob(data) {\n return typeof Blob !== 'undefined' && data instanceof Blob;\n}\n\n\n\nmodule.exports = function(uploadInfo, data, file, saveOptions = {}) {\n if (isBlob(data) && data.size >= SHARD_THRESHOLD) {\n return new BlobUploader(uploadInfo, data, file, saveOptions).upload();\n }\n return upload(uploadInfo, data, file, saveOptions);\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/uploader/qiniu.js","module.exports = require(\"core-js-pure/stable/array/from\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/core-js-stable/array/from.js\n// module id = 448\n// module chunks = 0 1","require('../../modules/es.string.iterator');\nrequire('../../modules/es.array.from');\nvar path = require('../../internals/path');\n\nmodule.exports = path.Array.from;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/es/array/from.js\n// module id = 449\n// module chunks = 0 1","var $ = require('../internals/export');\nvar from = require('../internals/array-from');\nvar checkCorrectnessOfIteration = require('../internals/check-correctness-of-iteration');\n\nvar INCORRECT_ITERATION = !checkCorrectnessOfIteration(function (iterable) {\n // eslint-disable-next-line es-x/no-array-from -- required for testing\n Array.from(iterable);\n});\n\n// `Array.from` method\n// https://tc39.es/ecma262/#sec-array.from\n$({ target: 'Array', stat: true, forced: INCORRECT_ITERATION }, {\n from: from\n});\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.array.from.js\n// module id = 450\n// module chunks = 0 1","'use strict';\nvar bind = require('../internals/function-bind-context');\nvar call = require('../internals/function-call');\nvar toObject = require('../internals/to-object');\nvar callWithSafeIterationClosing = require('../internals/call-with-safe-iteration-closing');\nvar isArrayIteratorMethod = require('../internals/is-array-iterator-method');\nvar isConstructor = require('../internals/is-constructor');\nvar lengthOfArrayLike = require('../internals/length-of-array-like');\nvar createProperty = require('../internals/create-property');\nvar getIterator = require('../internals/get-iterator');\nvar getIteratorMethod = require('../internals/get-iterator-method');\n\nvar $Array = Array;\n\n// `Array.from` method implementation\n// https://tc39.es/ecma262/#sec-array.from\nmodule.exports = function from(arrayLike /* , mapfn = undefined, thisArg = undefined */) {\n var O = toObject(arrayLike);\n var IS_CONSTRUCTOR = isConstructor(this);\n var argumentsLength = arguments.length;\n var mapfn = argumentsLength > 1 ? arguments[1] : undefined;\n var mapping = mapfn !== undefined;\n if (mapping) mapfn = bind(mapfn, argumentsLength > 2 ? arguments[2] : undefined);\n var iteratorMethod = getIteratorMethod(O);\n var index = 0;\n var length, result, step, iterator, next, value;\n // if the target is not iterable or it's an array with the default iterator - use a simple case\n if (iteratorMethod && !(this === $Array && isArrayIteratorMethod(iteratorMethod))) {\n iterator = getIterator(O, iteratorMethod);\n next = iterator.next;\n result = IS_CONSTRUCTOR ? new this() : [];\n for (;!(step = call(next, iterator)).done; index++) {\n value = mapping ? callWithSafeIterationClosing(iterator, mapfn, [step.value, index], true) : step.value;\n createProperty(result, index, value);\n }\n } else {\n length = lengthOfArrayLike(O);\n result = IS_CONSTRUCTOR ? new this(length) : $Array(length);\n for (;length > index; index++) {\n value = mapping ? mapfn(O[index], index) : O[index];\n createProperty(result, index, value);\n }\n }\n result.length = index;\n return result;\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/internals/array-from.js\n// module id = 451\n// module chunks = 0 1","var anObject = require('../internals/an-object');\nvar iteratorClose = require('../internals/iterator-close');\n\n// call something on iterator step with safe closing on error\nmodule.exports = function (iterator, fn, value, ENTRIES) {\n try {\n return ENTRIES ? fn(anObject(value)[0], value[1]) : fn(value);\n } catch (error) {\n iteratorClose(iterator, 'throw', error);\n }\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/internals/call-with-safe-iteration-closing.js\n// module id = 452\n// module chunks = 0 1","module.exports = require(\"core-js-pure/stable/symbol\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/core-js-stable/symbol.js\n// module id = 453\n// module chunks = 0 1","module.exports = require('../full/get-iterator-method');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/features/get-iterator-method.js\n// module id = 454\n// module chunks = 0 1","var parent = require('../actual/get-iterator-method');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/full/get-iterator-method.js\n// module id = 455\n// module chunks = 0 1","var parent = require('../stable/get-iterator-method');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/actual/get-iterator-method.js\n// module id = 456\n// module chunks = 0 1","var parent = require('../es/get-iterator-method');\nrequire('../modules/web.dom-collections.iterator');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/stable/get-iterator-method.js\n// module id = 457\n// module chunks = 0 1","require('../modules/es.array.iterator');\nrequire('../modules/es.string.iterator');\nvar getIteratorMethod = require('../internals/get-iterator-method');\n\nmodule.exports = getIteratorMethod;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/es/get-iterator-method.js\n// module id = 458\n// module chunks = 0 1","module.exports = require(\"core-js-pure/stable/reflect/construct\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/core-js-stable/reflect/construct.js\n// module id = 459\n// module chunks = 0 1","var parent = require('../../es/reflect/construct');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/stable/reflect/construct.js\n// module id = 460\n// module chunks = 0 1","require('../../modules/es.reflect.construct');\nvar path = require('../../internals/path');\n\nmodule.exports = path.Reflect.construct;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/es/reflect/construct.js\n// module id = 461\n// module chunks = 0 1","var $ = require('../internals/export');\nvar getBuiltIn = require('../internals/get-built-in');\nvar apply = require('../internals/function-apply');\nvar bind = require('../internals/function-bind');\nvar aConstructor = require('../internals/a-constructor');\nvar anObject = require('../internals/an-object');\nvar isObject = require('../internals/is-object');\nvar create = require('../internals/object-create');\nvar fails = require('../internals/fails');\n\nvar nativeConstruct = getBuiltIn('Reflect', 'construct');\nvar ObjectPrototype = Object.prototype;\nvar push = [].push;\n\n// `Reflect.construct` method\n// https://tc39.es/ecma262/#sec-reflect.construct\n// MS Edge supports only 2 arguments and argumentsList argument is optional\n// FF Nightly sets third argument as `new.target`, but does not create `this` from it\nvar NEW_TARGET_BUG = fails(function () {\n function F() { /* empty */ }\n return !(nativeConstruct(function () { /* empty */ }, [], F) instanceof F);\n});\n\nvar ARGS_BUG = !fails(function () {\n nativeConstruct(function () { /* empty */ });\n});\n\nvar FORCED = NEW_TARGET_BUG || ARGS_BUG;\n\n$({ target: 'Reflect', stat: true, forced: FORCED, sham: FORCED }, {\n construct: function construct(Target, args /* , newTarget */) {\n aConstructor(Target);\n anObject(args);\n var newTarget = arguments.length < 3 ? Target : aConstructor(arguments[2]);\n if (ARGS_BUG && !NEW_TARGET_BUG) return nativeConstruct(Target, args, newTarget);\n if (Target == newTarget) {\n // w/o altered newTarget, optimization for 0-4 arguments\n switch (args.length) {\n case 0: return new Target();\n case 1: return new Target(args[0]);\n case 2: return new Target(args[0], args[1]);\n case 3: return new Target(args[0], args[1], args[2]);\n case 4: return new Target(args[0], args[1], args[2], args[3]);\n }\n // w/o altered newTarget, lot of arguments case\n var $args = [null];\n apply(push, $args, args);\n return new (apply(bind, Target, $args))();\n }\n // with altered newTarget, not support built-in constructors\n var proto = newTarget.prototype;\n var instance = create(isObject(proto) ? proto : ObjectPrototype);\n var result = apply(Target, instance, args);\n return isObject(result) ? result : instance;\n }\n});\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.reflect.construct.js\n// module id = 462\n// module chunks = 0 1","var _Object$create = require(\"@babel/runtime-corejs3/core-js/object/create\");\n\nvar _Object$defineProperty = require(\"@babel/runtime-corejs3/core-js/object/define-property\");\n\nvar setPrototypeOf = require(\"./setPrototypeOf.js\");\n\nfunction _inherits(subClass, superClass) {\n if (typeof superClass !== \"function\" && superClass !== null) {\n throw new TypeError(\"Super expression must either be null or a function\");\n }\n\n subClass.prototype = _Object$create(superClass && superClass.prototype, {\n constructor: {\n value: subClass,\n writable: true,\n configurable: true\n }\n });\n\n _Object$defineProperty(subClass, \"prototype\", {\n writable: false\n });\n\n if (superClass) setPrototypeOf(subClass, superClass);\n}\n\nmodule.exports = _inherits, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/helpers/inherits.js\n// module id = 463\n// module chunks = 0 1","module.exports = require(\"core-js-pure/features/object/create\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/core-js/object/create.js\n// module id = 464\n// module chunks = 0 1","module.exports = require('../../full/object/create');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/features/object/create.js\n// module id = 465\n// module chunks = 0 1","var parent = require('../../actual/object/create');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/full/object/create.js\n// module id = 466\n// module chunks = 0 1","var parent = require('../../stable/object/create');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/actual/object/create.js\n// module id = 467\n// module chunks = 0 1","var parent = require('../../es/object/create');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/stable/object/create.js\n// module id = 468\n// module chunks = 0 1","require('../../modules/es.object.create');\nvar path = require('../../internals/path');\n\nvar Object = path.Object;\n\nmodule.exports = function create(P, D) {\n return Object.create(P, D);\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/es/object/create.js\n// module id = 469\n// module chunks = 0 1","// TODO: Remove from `core-js@4`\nvar $ = require('../internals/export');\nvar DESCRIPTORS = require('../internals/descriptors');\nvar create = require('../internals/object-create');\n\n// `Object.create` method\n// https://tc39.es/ecma262/#sec-object.create\n$({ target: 'Object', stat: true, sham: !DESCRIPTORS }, {\n create: create\n});\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.object.create.js\n// module id = 470\n// module chunks = 0 1","module.exports = require('../../full/object/define-property');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/features/object/define-property.js\n// module id = 471\n// module chunks = 0 1","var parent = require('../../actual/object/define-property');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/full/object/define-property.js\n// module id = 472\n// module chunks = 0 1","var parent = require('../../stable/object/define-property');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/actual/object/define-property.js\n// module id = 473\n// module chunks = 0 1","var _Object$setPrototypeOf = require(\"@babel/runtime-corejs3/core-js/object/set-prototype-of\");\n\nvar _bindInstanceProperty = require(\"@babel/runtime-corejs3/core-js/instance/bind\");\n\nfunction _setPrototypeOf(o, p) {\n var _context;\n\n module.exports = _setPrototypeOf = _Object$setPrototypeOf ? _bindInstanceProperty(_context = _Object$setPrototypeOf).call(_context) : function _setPrototypeOf(o, p) {\n o.__proto__ = p;\n return o;\n }, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n return _setPrototypeOf(o, p);\n}\n\nmodule.exports = _setPrototypeOf, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/helpers/setPrototypeOf.js\n// module id = 474\n// module chunks = 0 1","module.exports = require('../../full/object/set-prototype-of');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/features/object/set-prototype-of.js\n// module id = 475\n// module chunks = 0 1","var parent = require('../../actual/object/set-prototype-of');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/full/object/set-prototype-of.js\n// module id = 476\n// module chunks = 0 1","var parent = require('../../stable/object/set-prototype-of');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/actual/object/set-prototype-of.js\n// module id = 477\n// module chunks = 0 1","module.exports = require('../../full/instance/bind');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/features/instance/bind.js\n// module id = 478\n// module chunks = 0 1","var parent = require('../../actual/instance/bind');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/full/instance/bind.js\n// module id = 479\n// module chunks = 0 1","var parent = require('../../stable/instance/bind');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/actual/instance/bind.js\n// module id = 480\n// module chunks = 0 1","var parent = require('../../es/instance/bind');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/stable/instance/bind.js\n// module id = 481\n// module chunks = 0 1","var isPrototypeOf = require('../../internals/object-is-prototype-of');\nvar method = require('../function/virtual/bind');\n\nvar FunctionPrototype = Function.prototype;\n\nmodule.exports = function (it) {\n var own = it.bind;\n return it === FunctionPrototype || (isPrototypeOf(FunctionPrototype, it) && own === FunctionPrototype.bind) ? method : own;\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/es/instance/bind.js\n// module id = 482\n// module chunks = 0 1","require('../../../modules/es.function.bind');\nvar entryVirtual = require('../../../internals/entry-virtual');\n\nmodule.exports = entryVirtual('Function').bind;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/es/function/virtual/bind.js\n// module id = 483\n// module chunks = 0 1","// TODO: Remove from `core-js@4`\nvar $ = require('../internals/export');\nvar bind = require('../internals/function-bind');\n\n// `Function.prototype.bind` method\n// https://tc39.es/ecma262/#sec-function.prototype.bind\n$({ target: 'Function', proto: true, forced: Function.bind !== bind }, {\n bind: bind\n});\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.function.bind.js\n// module id = 484\n// module chunks = 0 1","var _typeof = require(\"./typeof.js\")[\"default\"];\n\nvar assertThisInitialized = require(\"./assertThisInitialized.js\");\n\nfunction _possibleConstructorReturn(self, call) {\n if (call && (_typeof(call) === \"object\" || typeof call === \"function\")) {\n return call;\n } else if (call !== void 0) {\n throw new TypeError(\"Derived constructors may only return object or undefined\");\n }\n\n return assertThisInitialized(self);\n}\n\nmodule.exports = _possibleConstructorReturn, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/helpers/possibleConstructorReturn.js\n// module id = 485\n// module chunks = 0 1","function _assertThisInitialized(self) {\n if (self === void 0) {\n throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\");\n }\n\n return self;\n}\n\nmodule.exports = _assertThisInitialized, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/helpers/assertThisInitialized.js\n// module id = 486\n// module chunks = 0 1","var _Object$setPrototypeOf = require(\"@babel/runtime-corejs3/core-js/object/set-prototype-of\");\n\nvar _bindInstanceProperty = require(\"@babel/runtime-corejs3/core-js/instance/bind\");\n\nvar _Object$getPrototypeOf = require(\"@babel/runtime-corejs3/core-js/object/get-prototype-of\");\n\nfunction _getPrototypeOf(o) {\n var _context;\n\n module.exports = _getPrototypeOf = _Object$setPrototypeOf ? _bindInstanceProperty(_context = _Object$getPrototypeOf).call(_context) : function _getPrototypeOf(o) {\n return o.__proto__ || _Object$getPrototypeOf(o);\n }, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n return _getPrototypeOf(o);\n}\n\nmodule.exports = _getPrototypeOf, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/helpers/getPrototypeOf.js\n// module id = 487\n// module chunks = 0 1","module.exports = require(\"core-js-pure/features/object/get-prototype-of\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/core-js/object/get-prototype-of.js\n// module id = 488\n// module chunks = 0 1","module.exports = require('../../full/object/get-prototype-of');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/features/object/get-prototype-of.js\n// module id = 489\n// module chunks = 0 1","var parent = require('../../actual/object/get-prototype-of');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/full/object/get-prototype-of.js\n// module id = 490\n// module chunks = 0 1","var parent = require('../../stable/object/get-prototype-of');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/actual/object/get-prototype-of.js\n// module id = 491\n// module chunks = 0 1","function _classCallCheck(instance, Constructor) {\n if (!(instance instanceof Constructor)) {\n throw new TypeError(\"Cannot call a class as a function\");\n }\n}\n\nmodule.exports = _classCallCheck, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/helpers/classCallCheck.js\n// module id = 492\n// module chunks = 0 1","var _Object$defineProperty = require(\"@babel/runtime-corejs3/core-js/object/define-property\");\n\nfunction _defineProperties(target, props) {\n for (var i = 0; i < props.length; i++) {\n var descriptor = props[i];\n descriptor.enumerable = descriptor.enumerable || false;\n descriptor.configurable = true;\n if (\"value\" in descriptor) descriptor.writable = true;\n\n _Object$defineProperty(target, descriptor.key, descriptor);\n }\n}\n\nfunction _createClass(Constructor, protoProps, staticProps) {\n if (protoProps) _defineProperties(Constructor.prototype, protoProps);\n if (staticProps) _defineProperties(Constructor, staticProps);\n\n _Object$defineProperty(Constructor, \"prototype\", {\n writable: false\n });\n\n return Constructor;\n}\n\nmodule.exports = _createClass, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/helpers/createClass.js\n// module id = 493\n// module chunks = 0 1","// base64 character set, plus padding character (=)\nconst b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';\n\nmodule.exports = string => {\n let result = '';\n\n for (let i = 0; i < string.length; ) {\n const a = string.charCodeAt(i++);\n const b = string.charCodeAt(i++);\n const c = string.charCodeAt(i++);\n if (a > 255 || b > 255 || c > 255) {\n throw new TypeError(\n 'Failed to encode base64: The string to be encoded contains characters outside of the Latin1 range.'\n );\n }\n\n const bitmap = (a << 16) | (b << 8) | c;\n result +=\n b64.charAt((bitmap >> 18) & 63) +\n b64.charAt((bitmap >> 12) & 63) +\n b64.charAt((bitmap >> 6) & 63) +\n b64.charAt(bitmap & 63);\n }\n\n // To determine the final padding\n const rest = string.length % 3;\n // If there's need of padding, replace the last 'A's with equal signs\n return rest ? result.slice(0, rest - 3) + '==='.substring(rest) : result;\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/utils/btoa.js","const _ = require('underscore');\nconst ajax = require('../utils/ajax');\n\nmodule.exports = function upload(uploadInfo, data, file, saveOptions = {}) {\n\n return ajax({\n url: uploadInfo.upload_url,\n method: 'PUT',\n data,\n headers: _.extend(\n {\n 'Content-Type': file.get('mime_type'),\n 'Cache-Control': 'public, max-age=31536000',\n },\n file._uploadHeaders\n ),\n onprogress: saveOptions.onprogress,\n }).then(() => {\n file.attributes.url = uploadInfo.url;\n file._bucket = uploadInfo.bucket;\n file.id = uploadInfo.objectId;\n return file;\n });\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/uploader/s3.js","(function(){\r\n var crypt = require('crypt'),\r\n utf8 = require('charenc').utf8,\r\n isBuffer = require('is-buffer'),\r\n bin = require('charenc').bin,\r\n\r\n // The core\r\n md5 = function (message, options) {\r\n // Convert to byte array\r\n if (message.constructor == String)\r\n if (options && options.encoding === 'binary')\r\n message = bin.stringToBytes(message);\r\n else\r\n message = utf8.stringToBytes(message);\r\n else if (isBuffer(message))\r\n message = Array.prototype.slice.call(message, 0);\r\n else if (!Array.isArray(message))\r\n message = message.toString();\r\n // else, assume byte array already\r\n\r\n var m = crypt.bytesToWords(message),\r\n l = message.length * 8,\r\n a = 1732584193,\r\n b = -271733879,\r\n c = -1732584194,\r\n d = 271733878;\r\n\r\n // Swap endian\r\n for (var i = 0; i < m.length; i++) {\r\n m[i] = ((m[i] << 8) | (m[i] >>> 24)) & 0x00FF00FF |\r\n ((m[i] << 24) | (m[i] >>> 8)) & 0xFF00FF00;\r\n }\r\n\r\n // Padding\r\n m[l >>> 5] |= 0x80 << (l % 32);\r\n m[(((l + 64) >>> 9) << 4) + 14] = l;\r\n\r\n // Method shortcuts\r\n var FF = md5._ff,\r\n GG = md5._gg,\r\n HH = md5._hh,\r\n II = md5._ii;\r\n\r\n for (var i = 0; i < m.length; i += 16) {\r\n\r\n var aa = a,\r\n bb = b,\r\n cc = c,\r\n dd = d;\r\n\r\n a = FF(a, b, c, d, m[i+ 0], 7, -680876936);\r\n d = FF(d, a, b, c, m[i+ 1], 12, -389564586);\r\n c = FF(c, d, a, b, m[i+ 2], 17, 606105819);\r\n b = FF(b, c, d, a, m[i+ 3], 22, -1044525330);\r\n a = FF(a, b, c, d, m[i+ 4], 7, -176418897);\r\n d = FF(d, a, b, c, m[i+ 5], 12, 1200080426);\r\n c = FF(c, d, a, b, m[i+ 6], 17, -1473231341);\r\n b = FF(b, c, d, a, m[i+ 7], 22, -45705983);\r\n a = FF(a, b, c, d, m[i+ 8], 7, 1770035416);\r\n d = FF(d, a, b, c, m[i+ 9], 12, -1958414417);\r\n c = FF(c, d, a, b, m[i+10], 17, -42063);\r\n b = FF(b, c, d, a, m[i+11], 22, -1990404162);\r\n a = FF(a, b, c, d, m[i+12], 7, 1804603682);\r\n d = FF(d, a, b, c, m[i+13], 12, -40341101);\r\n c = FF(c, d, a, b, m[i+14], 17, -1502002290);\r\n b = FF(b, c, d, a, m[i+15], 22, 1236535329);\r\n\r\n a = GG(a, b, c, d, m[i+ 1], 5, -165796510);\r\n d = GG(d, a, b, c, m[i+ 6], 9, -1069501632);\r\n c = GG(c, d, a, b, m[i+11], 14, 643717713);\r\n b = GG(b, c, d, a, m[i+ 0], 20, -373897302);\r\n a = GG(a, b, c, d, m[i+ 5], 5, -701558691);\r\n d = GG(d, a, b, c, m[i+10], 9, 38016083);\r\n c = GG(c, d, a, b, m[i+15], 14, -660478335);\r\n b = GG(b, c, d, a, m[i+ 4], 20, -405537848);\r\n a = GG(a, b, c, d, m[i+ 9], 5, 568446438);\r\n d = GG(d, a, b, c, m[i+14], 9, -1019803690);\r\n c = GG(c, d, a, b, m[i+ 3], 14, -187363961);\r\n b = GG(b, c, d, a, m[i+ 8], 20, 1163531501);\r\n a = GG(a, b, c, d, m[i+13], 5, -1444681467);\r\n d = GG(d, a, b, c, m[i+ 2], 9, -51403784);\r\n c = GG(c, d, a, b, m[i+ 7], 14, 1735328473);\r\n b = GG(b, c, d, a, m[i+12], 20, -1926607734);\r\n\r\n a = HH(a, b, c, d, m[i+ 5], 4, -378558);\r\n d = HH(d, a, b, c, m[i+ 8], 11, -2022574463);\r\n c = HH(c, d, a, b, m[i+11], 16, 1839030562);\r\n b = HH(b, c, d, a, m[i+14], 23, -35309556);\r\n a = HH(a, b, c, d, m[i+ 1], 4, -1530992060);\r\n d = HH(d, a, b, c, m[i+ 4], 11, 1272893353);\r\n c = HH(c, d, a, b, m[i+ 7], 16, -155497632);\r\n b = HH(b, c, d, a, m[i+10], 23, -1094730640);\r\n a = HH(a, b, c, d, m[i+13], 4, 681279174);\r\n d = HH(d, a, b, c, m[i+ 0], 11, -358537222);\r\n c = HH(c, d, a, b, m[i+ 3], 16, -722521979);\r\n b = HH(b, c, d, a, m[i+ 6], 23, 76029189);\r\n a = HH(a, b, c, d, m[i+ 9], 4, -640364487);\r\n d = HH(d, a, b, c, m[i+12], 11, -421815835);\r\n c = HH(c, d, a, b, m[i+15], 16, 530742520);\r\n b = HH(b, c, d, a, m[i+ 2], 23, -995338651);\r\n\r\n a = II(a, b, c, d, m[i+ 0], 6, -198630844);\r\n d = II(d, a, b, c, m[i+ 7], 10, 1126891415);\r\n c = II(c, d, a, b, m[i+14], 15, -1416354905);\r\n b = II(b, c, d, a, m[i+ 5], 21, -57434055);\r\n a = II(a, b, c, d, m[i+12], 6, 1700485571);\r\n d = II(d, a, b, c, m[i+ 3], 10, -1894986606);\r\n c = II(c, d, a, b, m[i+10], 15, -1051523);\r\n b = II(b, c, d, a, m[i+ 1], 21, -2054922799);\r\n a = II(a, b, c, d, m[i+ 8], 6, 1873313359);\r\n d = II(d, a, b, c, m[i+15], 10, -30611744);\r\n c = II(c, d, a, b, m[i+ 6], 15, -1560198380);\r\n b = II(b, c, d, a, m[i+13], 21, 1309151649);\r\n a = II(a, b, c, d, m[i+ 4], 6, -145523070);\r\n d = II(d, a, b, c, m[i+11], 10, -1120210379);\r\n c = II(c, d, a, b, m[i+ 2], 15, 718787259);\r\n b = II(b, c, d, a, m[i+ 9], 21, -343485551);\r\n\r\n a = (a + aa) >>> 0;\r\n b = (b + bb) >>> 0;\r\n c = (c + cc) >>> 0;\r\n d = (d + dd) >>> 0;\r\n }\r\n\r\n return crypt.endian([a, b, c, d]);\r\n };\r\n\r\n // Auxiliary functions\r\n md5._ff = function (a, b, c, d, x, s, t) {\r\n var n = a + (b & c | ~b & d) + (x >>> 0) + t;\r\n return ((n << s) | (n >>> (32 - s))) + b;\r\n };\r\n md5._gg = function (a, b, c, d, x, s, t) {\r\n var n = a + (b & d | c & ~d) + (x >>> 0) + t;\r\n return ((n << s) | (n >>> (32 - s))) + b;\r\n };\r\n md5._hh = function (a, b, c, d, x, s, t) {\r\n var n = a + (b ^ c ^ d) + (x >>> 0) + t;\r\n return ((n << s) | (n >>> (32 - s))) + b;\r\n };\r\n md5._ii = function (a, b, c, d, x, s, t) {\r\n var n = a + (c ^ (b | ~d)) + (x >>> 0) + t;\r\n return ((n << s) | (n >>> (32 - s))) + b;\r\n };\r\n\r\n // Package private blocksize\r\n md5._blocksize = 16;\r\n md5._digestsize = 16;\r\n\r\n module.exports = function (message, options) {\r\n if (message === undefined || message === null)\r\n throw new Error('Illegal argument ' + message);\r\n\r\n var digestbytes = crypt.wordsToBytes(md5(message, options));\r\n return options && options.asBytes ? digestbytes :\r\n options && options.asString ? bin.bytesToString(digestbytes) :\r\n crypt.bytesToHex(digestbytes);\r\n };\r\n\r\n})();\r\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/md5/md5.js\n// module id = 496\n// module chunks = 0 1","(function() {\n var base64map\n = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',\n\n crypt = {\n // Bit-wise rotation left\n rotl: function(n, b) {\n return (n << b) | (n >>> (32 - b));\n },\n\n // Bit-wise rotation right\n rotr: function(n, b) {\n return (n << (32 - b)) | (n >>> b);\n },\n\n // Swap big-endian to little-endian and vice versa\n endian: function(n) {\n // If number given, swap endian\n if (n.constructor == Number) {\n return crypt.rotl(n, 8) & 0x00FF00FF | crypt.rotl(n, 24) & 0xFF00FF00;\n }\n\n // Else, assume array and swap all items\n for (var i = 0; i < n.length; i++)\n n[i] = crypt.endian(n[i]);\n return n;\n },\n\n // Generate an array of any length of random bytes\n randomBytes: function(n) {\n for (var bytes = []; n > 0; n--)\n bytes.push(Math.floor(Math.random() * 256));\n return bytes;\n },\n\n // Convert a byte array to big-endian 32-bit words\n bytesToWords: function(bytes) {\n for (var words = [], i = 0, b = 0; i < bytes.length; i++, b += 8)\n words[b >>> 5] |= bytes[i] << (24 - b % 32);\n return words;\n },\n\n // Convert big-endian 32-bit words to a byte array\n wordsToBytes: function(words) {\n for (var bytes = [], b = 0; b < words.length * 32; b += 8)\n bytes.push((words[b >>> 5] >>> (24 - b % 32)) & 0xFF);\n return bytes;\n },\n\n // Convert a byte array to a hex string\n bytesToHex: function(bytes) {\n for (var hex = [], i = 0; i < bytes.length; i++) {\n hex.push((bytes[i] >>> 4).toString(16));\n hex.push((bytes[i] & 0xF).toString(16));\n }\n return hex.join('');\n },\n\n // Convert a hex string to a byte array\n hexToBytes: function(hex) {\n for (var bytes = [], c = 0; c < hex.length; c += 2)\n bytes.push(parseInt(hex.substr(c, 2), 16));\n return bytes;\n },\n\n // Convert a byte array to a base-64 string\n bytesToBase64: function(bytes) {\n for (var base64 = [], i = 0; i < bytes.length; i += 3) {\n var triplet = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2];\n for (var j = 0; j < 4; j++)\n if (i * 8 + j * 6 <= bytes.length * 8)\n base64.push(base64map.charAt((triplet >>> 6 * (3 - j)) & 0x3F));\n else\n base64.push('=');\n }\n return base64.join('');\n },\n\n // Convert a base-64 string to a byte array\n base64ToBytes: function(base64) {\n // Remove non-base-64 characters\n base64 = base64.replace(/[^A-Z0-9+\\/]/ig, '');\n\n for (var bytes = [], i = 0, imod4 = 0; i < base64.length;\n imod4 = ++i % 4) {\n if (imod4 == 0) continue;\n bytes.push(((base64map.indexOf(base64.charAt(i - 1))\n & (Math.pow(2, -2 * imod4 + 8) - 1)) << (imod4 * 2))\n | (base64map.indexOf(base64.charAt(i)) >>> (6 - imod4 * 2)));\n }\n return bytes;\n }\n };\n\n module.exports = crypt;\n})();\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/crypt/crypt.js\n// module id = 497\n// module chunks = 0 1","/*!\n * Determine if an object is a Buffer\n *\n * @author Feross Aboukhadijeh \n * @license MIT\n */\n\n// The _isBuffer check is for Safari 5-7 support, because it's missing\n// Object.prototype.constructor. Remove this eventually\nmodule.exports = function (obj) {\n return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer)\n}\n\nfunction isBuffer (obj) {\n return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)\n}\n\n// For Node v0.10 support. Remove this eventually.\nfunction isSlowBuffer (obj) {\n return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0))\n}\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/is-buffer/index.js\n// module id = 498\n// module chunks = 0 1","var dataURItoBlob = function(dataURI, type) {\n var byteString;\n\n // 传入的 base64,不是 dataURL\n if (dataURI.indexOf('base64') < 0) {\n byteString = atob(dataURI);\n } else if (dataURI.split(',')[0].indexOf('base64') >= 0) {\n type =\n type ||\n dataURI\n .split(',')[0]\n .split(':')[1]\n .split(';')[0];\n byteString = atob(dataURI.split(',')[1]);\n } else {\n byteString = unescape(dataURI.split(',')[1]);\n }\n var ia = new Uint8Array(byteString.length);\n for (var i = 0; i < byteString.length; i++) {\n ia[i] = byteString.charCodeAt(i);\n }\n return new Blob([ia], { type });\n};\n\nmodule.exports = dataURItoBlob;\n\n\n\n// WEBPACK FOOTER //\n// ./src/utils/parse-base64-browser.js","const _ = require('underscore');\nconst AVError = require('./error');\nconst { _request } = require('./request');\nconst {\n isNullOrUndefined,\n ensureArray,\n transformFetchOptions,\n setValue,\n findValue,\n isPlainObject,\n continueWhile,\n} = require('./utils');\n\nconst recursiveToPointer = value => {\n if (_.isArray(value)) return value.map(recursiveToPointer);\n if (isPlainObject(value)) return _.mapObject(value, recursiveToPointer);\n if (_.isObject(value) && value._toPointer) return value._toPointer();\n return value;\n};\n\nconst RESERVED_KEYS = ['objectId', 'createdAt', 'updatedAt'];\nconst checkReservedKey = key => {\n if (RESERVED_KEYS.indexOf(key) !== -1) {\n throw new Error(`key[${key}] is reserved`);\n }\n};\n\nconst handleBatchResults = results => {\n const firstError = _.find(results, result => result instanceof Error);\n if (!firstError) {\n return results;\n }\n const error = new AVError(firstError.code, firstError.message);\n error.results = results;\n throw error;\n};\n\n// Helper function to get a value from a Backbone object as a property\n// or as a function.\nfunction getValue(object, prop) {\n if (!(object && object[prop])) {\n return null;\n }\n return _.isFunction(object[prop]) ? object[prop]() : object[prop];\n}\n\n// AV.Object is analogous to the Java AVObject.\n// It also implements the same interface as a Backbone model.\n\nmodule.exports = function(AV) {\n /**\n * Creates a new model with defined attributes. A client id (cid) is\n * automatically generated and assigned for you.\n *\n *
You won't normally call this method directly. It is recommended that\n * you use a subclass of AV.Object instead, created by calling\n * extend.
\n *\n *
However, if you don't want to use a subclass, or aren't sure which\n * subclass is appropriate, you can use this form:
\n * var object = new AV.Object(\"ClassName\");\n *
\n * That is basically equivalent to:
\n * var MyClass = AV.Object.extend(\"ClassName\");\n * var object = new MyClass();\n *
\n *\n * @param {Object} attributes The initial set of data to store in the object.\n * @param {Object} options A set of Backbone-like options for creating the\n * object. The only option currently supported is \"collection\".\n * @see AV.Object.extend\n *\n * @class\n *\n *
The fundamental unit of AV data, which implements the Backbone Model\n * interface.
\n */\n AV.Object = function(attributes, options) {\n // Allow new AV.Object(\"ClassName\") as a shortcut to _create.\n if (_.isString(attributes)) {\n return AV.Object._create.apply(this, arguments);\n }\n\n attributes = attributes || {};\n if (options && options.parse) {\n attributes = this.parse(attributes);\n attributes = this._mergeMagicFields(attributes);\n }\n var defaults = getValue(this, 'defaults');\n if (defaults) {\n attributes = _.extend({}, defaults, attributes);\n }\n if (options && options.collection) {\n this.collection = options.collection;\n }\n\n this._serverData = {}; // The last known data for this object from cloud.\n this._opSetQueue = [{}]; // List of sets of changes to the data.\n this._flags = {};\n this.attributes = {}; // The best estimate of this's current data.\n\n this._hashedJSON = {}; // Hash of values of containers at last save.\n this._escapedAttributes = {};\n this.cid = _.uniqueId('c');\n this.changed = {};\n this._silent = {};\n this._pending = {};\n this.set(attributes, { silent: true });\n this.changed = {};\n this._silent = {};\n this._pending = {};\n this._hasData = true;\n this._previousAttributes = _.clone(this.attributes);\n this.initialize.apply(this, arguments);\n };\n\n /**\n * @lends AV.Object.prototype\n * @property {String} id The objectId of the AV Object.\n */\n\n /**\n * Saves the given list of AV.Object.\n * If any error is encountered, stops and calls the error handler.\n *\n * @example\n * AV.Object.saveAll([object1, object2, ...]).then(function(list) {\n * // All the objects were saved.\n * }, function(error) {\n * // An error occurred while saving one of the objects.\n * });\n *\n * @param {Array} list A list of AV.Object.\n */\n AV.Object.saveAll = function(list, options) {\n return AV.Object._deepSaveAsync(list, null, options);\n };\n\n /**\n * Fetch the given list of AV.Object.\n *\n * @param {AV.Object[]} objects A list of AV.Object\n * @param {AuthOptions} options\n * @return {Promise.} The given list of AV.Object, updated\n */\n\n AV.Object.fetchAll = (objects, options) =>\n Promise.resolve()\n .then(() =>\n _request(\n 'batch',\n null,\n null,\n 'POST',\n {\n requests: _.map(objects, object => {\n if (!object.className)\n throw new Error('object must have className to fetch');\n if (!object.id) throw new Error('object must have id to fetch');\n if (object.dirty())\n throw new Error('object is modified but not saved');\n return {\n method: 'GET',\n path: `/1.1/classes/${object.className}/${object.id}`,\n };\n }),\n },\n options\n )\n )\n .then(function(response) {\n const results = _.map(objects, function(object, i) {\n if (response[i].success) {\n const fetchedAttrs = object.parse(response[i].success);\n object._cleanupUnsetKeys(fetchedAttrs);\n object._finishFetch(fetchedAttrs);\n return object;\n }\n if (response[i].success === null) {\n return new AVError(AVError.OBJECT_NOT_FOUND, 'Object not found.');\n }\n return new AVError(response[i].error.code, response[i].error.error);\n });\n return handleBatchResults(results);\n });\n\n // Attach all inheritable methods to the AV.Object prototype.\n _.extend(\n AV.Object.prototype,\n AV.Events,\n /** @lends AV.Object.prototype */ {\n _fetchWhenSave: false,\n\n /**\n * Initialize is an empty function by default. Override it with your own\n * initialization logic.\n */\n initialize: function() {},\n\n /**\n * Set whether to enable fetchWhenSave option when updating object.\n * When set true, SDK would fetch the latest object after saving.\n * Default is false.\n *\n * @deprecated use AV.Object#save with options.fetchWhenSave instead\n * @param {boolean} enable true to enable fetchWhenSave option.\n */\n fetchWhenSave: function(enable) {\n console.warn(\n 'AV.Object#fetchWhenSave is deprecated, use AV.Object#save with options.fetchWhenSave instead.'\n );\n if (!_.isBoolean(enable)) {\n throw new Error('Expect boolean value for fetchWhenSave');\n }\n this._fetchWhenSave = enable;\n },\n\n /**\n * Returns the object's objectId.\n * @return {String} the objectId.\n */\n getObjectId: function() {\n return this.id;\n },\n\n /**\n * Returns the object's createdAt attribute.\n * @return {Date}\n */\n getCreatedAt: function() {\n return this.createdAt;\n },\n\n /**\n * Returns the object's updatedAt attribute.\n * @return {Date}\n */\n getUpdatedAt: function() {\n return this.updatedAt;\n },\n\n /**\n * Returns a JSON version of the object.\n * @return {Object}\n */\n toJSON: function(key, holder, seenObjects = []) {\n return this._toFullJSON(seenObjects, false);\n },\n\n /**\n * Returns a JSON version of the object with meta data.\n * Inverse to {@link AV.parseJSON}\n * @since 3.0.0\n * @return {Object}\n */\n toFullJSON(seenObjects = []) {\n return this._toFullJSON(seenObjects);\n },\n\n _toFullJSON: function(seenObjects, full = true) {\n var json = _.clone(this.attributes);\n if (_.isArray(seenObjects)) {\n var newSeenObjects = seenObjects.concat(this);\n }\n AV._objectEach(json, function(val, key) {\n json[key] = AV._encode(val, newSeenObjects, undefined, full);\n });\n AV._objectEach(this._operations, function(val, key) {\n json[key] = val;\n });\n\n if (_.has(this, 'id')) {\n json.objectId = this.id;\n }\n ['createdAt', 'updatedAt'].forEach(key => {\n if (_.has(this, key)) {\n const val = this[key];\n json[key] = _.isDate(val) ? val.toJSON() : val;\n }\n });\n if (full) {\n json.__type = 'Object';\n if (_.isArray(seenObjects) && seenObjects.length)\n json.__type = 'Pointer';\n json.className = this.className;\n }\n return json;\n },\n\n /**\n * Updates _hashedJSON to reflect the current state of this object.\n * Adds any changed hash values to the set of pending changes.\n * @private\n */\n _refreshCache: function() {\n var self = this;\n if (self._refreshingCache) {\n return;\n }\n self._refreshingCache = true;\n AV._objectEach(this.attributes, function(value, key) {\n if (value instanceof AV.Object) {\n value._refreshCache();\n } else if (_.isObject(value)) {\n if (self._resetCacheForKey(key)) {\n self.set(key, new AV.Op.Set(value), { silent: true });\n }\n }\n });\n delete self._refreshingCache;\n },\n\n /**\n * Returns true if this object has been modified since its last\n * save/refresh. If an attribute is specified, it returns true only if that\n * particular attribute has been modified since the last save/refresh.\n * @param {String} attr An attribute name (optional).\n * @return {Boolean}\n */\n dirty: function(attr) {\n this._refreshCache();\n\n var currentChanges = _.last(this._opSetQueue);\n\n if (attr) {\n return currentChanges[attr] ? true : false;\n }\n if (!this.id) {\n return true;\n }\n if (_.keys(currentChanges).length > 0) {\n return true;\n }\n return false;\n },\n\n /**\n * Returns the keys of the modified attribute since its last save/refresh.\n * @return {String[]}\n */\n dirtyKeys: function() {\n this._refreshCache();\n var currentChanges = _.last(this._opSetQueue);\n return _.keys(currentChanges);\n },\n\n /**\n * Gets a Pointer referencing this Object.\n * @private\n */\n _toPointer: function() {\n // if (!this.id) {\n // throw new Error(\"Can't serialize an unsaved AV.Object\");\n // }\n return {\n __type: 'Pointer',\n className: this.className,\n objectId: this.id,\n };\n },\n\n /**\n * Gets the value of an attribute.\n * @param {String} attr The string name of an attribute.\n */\n get: function(attr) {\n switch (attr) {\n case 'objectId':\n return this.id;\n case 'createdAt':\n case 'updatedAt':\n return this[attr];\n default:\n return this.attributes[attr];\n }\n },\n\n /**\n * Gets a relation on the given class for the attribute.\n * @param {String} attr The attribute to get the relation for.\n * @return {AV.Relation}\n */\n relation: function(attr) {\n var value = this.get(attr);\n if (value) {\n if (!(value instanceof AV.Relation)) {\n throw new Error('Called relation() on non-relation field ' + attr);\n }\n value._ensureParentAndKey(this, attr);\n return value;\n } else {\n return new AV.Relation(this, attr);\n }\n },\n\n /**\n * Gets the HTML-escaped value of an attribute.\n */\n escape: function(attr) {\n var html = this._escapedAttributes[attr];\n if (html) {\n return html;\n }\n var val = this.attributes[attr];\n var escaped;\n if (isNullOrUndefined(val)) {\n escaped = '';\n } else {\n escaped = _.escape(val.toString());\n }\n this._escapedAttributes[attr] = escaped;\n return escaped;\n },\n\n /**\n * Returns true if the attribute contains a value that is not\n * null or undefined.\n * @param {String} attr The string name of the attribute.\n * @return {Boolean}\n */\n has: function(attr) {\n return !isNullOrUndefined(this.attributes[attr]);\n },\n\n /**\n * Pulls \"special\" fields like objectId, createdAt, etc. out of attrs\n * and puts them on \"this\" directly. Removes them from attrs.\n * @param attrs - A dictionary with the data for this AV.Object.\n * @private\n */\n _mergeMagicFields: function(attrs) {\n // Check for changes of magic fields.\n var model = this;\n var specialFields = ['objectId', 'createdAt', 'updatedAt'];\n AV._arrayEach(specialFields, function(attr) {\n if (attrs[attr]) {\n if (attr === 'objectId') {\n model.id = attrs[attr];\n } else if (\n (attr === 'createdAt' || attr === 'updatedAt') &&\n !_.isDate(attrs[attr])\n ) {\n model[attr] = AV._parseDate(attrs[attr]);\n } else {\n model[attr] = attrs[attr];\n }\n delete attrs[attr];\n }\n });\n return attrs;\n },\n\n /**\n * Returns the json to be sent to the server.\n * @private\n */\n _startSave: function() {\n this._opSetQueue.push({});\n },\n\n /**\n * Called when a save fails because of an error. Any changes that were part\n * of the save need to be merged with changes made after the save. This\n * might throw an exception is you do conflicting operations. For example,\n * if you do:\n * object.set(\"foo\", \"bar\");\n * object.set(\"invalid field name\", \"baz\");\n * object.save();\n * object.increment(\"foo\");\n * then this will throw when the save fails and the client tries to merge\n * \"bar\" with the +1.\n * @private\n */\n _cancelSave: function() {\n var failedChanges = _.first(this._opSetQueue);\n this._opSetQueue = _.rest(this._opSetQueue);\n var nextChanges = _.first(this._opSetQueue);\n AV._objectEach(failedChanges, function(op, key) {\n var op1 = failedChanges[key];\n var op2 = nextChanges[key];\n if (op1 && op2) {\n nextChanges[key] = op2._mergeWithPrevious(op1);\n } else if (op1) {\n nextChanges[key] = op1;\n }\n });\n this._saving = this._saving - 1;\n },\n\n /**\n * Called when a save completes successfully. This merges the changes that\n * were saved into the known server data, and overrides it with any data\n * sent directly from the server.\n * @private\n */\n _finishSave: function(serverData) {\n // Grab a copy of any object referenced by this object. These instances\n // may have already been fetched, and we don't want to lose their data.\n // Note that doing it like this means we will unify separate copies of the\n // same object, but that's a risk we have to take.\n var fetchedObjects = {};\n AV._traverse(this.attributes, function(object) {\n if (object instanceof AV.Object && object.id && object._hasData) {\n fetchedObjects[object.id] = object;\n }\n });\n\n var savedChanges = _.first(this._opSetQueue);\n this._opSetQueue = _.rest(this._opSetQueue);\n this._applyOpSet(savedChanges, this._serverData);\n this._mergeMagicFields(serverData);\n var self = this;\n AV._objectEach(serverData, function(value, key) {\n self._serverData[key] = AV._decode(value, key);\n\n // Look for any objects that might have become unfetched and fix them\n // by replacing their values with the previously observed values.\n var fetched = AV._traverse(self._serverData[key], function(object) {\n if (object instanceof AV.Object && fetchedObjects[object.id]) {\n return fetchedObjects[object.id];\n }\n });\n if (fetched) {\n self._serverData[key] = fetched;\n }\n });\n this._rebuildAllEstimatedData();\n const opSetQueue = this._opSetQueue.map(_.clone);\n this._refreshCache();\n this._opSetQueue = opSetQueue;\n this._saving = this._saving - 1;\n },\n\n /**\n * Called when a fetch or login is complete to set the known server data to\n * the given object.\n * @private\n */\n _finishFetch: function(serverData, hasData) {\n // Clear out any changes the user might have made previously.\n this._opSetQueue = [{}];\n\n // Bring in all the new server data.\n this._mergeMagicFields(serverData);\n var self = this;\n AV._objectEach(serverData, function(value, key) {\n self._serverData[key] = AV._decode(value, key);\n });\n\n // Refresh the attributes.\n this._rebuildAllEstimatedData();\n\n // Clear out the cache of mutable containers.\n this._refreshCache();\n this._opSetQueue = [{}];\n\n this._hasData = hasData;\n },\n\n /**\n * Applies the set of AV.Op in opSet to the object target.\n * @private\n */\n _applyOpSet: function(opSet, target) {\n var self = this;\n AV._objectEach(opSet, function(change, key) {\n const [value, actualTarget, actualKey] = findValue(target, key);\n setValue(target, key, change._estimate(value, self, key));\n if (actualTarget && actualTarget[actualKey] === AV.Op._UNSET) {\n delete actualTarget[actualKey];\n }\n });\n },\n\n /**\n * Replaces the cached value for key with the current value.\n * Returns true if the new value is different than the old value.\n * @private\n */\n _resetCacheForKey: function(key) {\n var value = this.attributes[key];\n if (\n _.isObject(value) &&\n !(value instanceof AV.Object) &&\n !(value instanceof AV.File)\n ) {\n var json = JSON.stringify(recursiveToPointer(value));\n if (this._hashedJSON[key] !== json) {\n var wasSet = !!this._hashedJSON[key];\n this._hashedJSON[key] = json;\n return wasSet;\n }\n }\n return false;\n },\n\n /**\n * Populates attributes[key] by starting with the last known data from the\n * server, and applying all of the local changes that have been made to that\n * key since then.\n * @private\n */\n _rebuildEstimatedDataForKey: function(key) {\n var self = this;\n delete this.attributes[key];\n if (this._serverData[key]) {\n this.attributes[key] = this._serverData[key];\n }\n AV._arrayEach(this._opSetQueue, function(opSet) {\n var op = opSet[key];\n if (op) {\n const [value, actualTarget, actualKey, firstKey] = findValue(\n self.attributes,\n key\n );\n setValue(self.attributes, key, op._estimate(value, self, key));\n if (actualTarget && actualTarget[actualKey] === AV.Op._UNSET) {\n delete actualTarget[actualKey];\n }\n self._resetCacheForKey(firstKey);\n }\n });\n },\n\n /**\n * Populates attributes by starting with the last known data from the\n * server, and applying all of the local changes that have been made since\n * then.\n * @private\n */\n _rebuildAllEstimatedData: function() {\n var self = this;\n\n var previousAttributes = _.clone(this.attributes);\n\n this.attributes = _.clone(this._serverData);\n AV._arrayEach(this._opSetQueue, function(opSet) {\n self._applyOpSet(opSet, self.attributes);\n AV._objectEach(opSet, function(op, key) {\n self._resetCacheForKey(key);\n });\n });\n\n // Trigger change events for anything that changed because of the fetch.\n AV._objectEach(previousAttributes, function(oldValue, key) {\n if (self.attributes[key] !== oldValue) {\n self.trigger('change:' + key, self, self.attributes[key], {});\n }\n });\n AV._objectEach(this.attributes, function(newValue, key) {\n if (!_.has(previousAttributes, key)) {\n self.trigger('change:' + key, self, newValue, {});\n }\n });\n },\n\n /**\n * Sets a hash of model attributes on the object, firing\n * \"change\" unless you choose to silence it.\n *\n *
You can call it with an object containing keys and values, or with one\n * key and value. For example:
\n *\n * @example\n * gameTurn.set({\n * player: player1,\n * diceRoll: 2\n * });\n *\n * game.set(\"currentPlayer\", player2);\n *\n * game.set(\"finished\", true);\n *\n * @param {String} key The key to set.\n * @param {Any} value The value to give it.\n * @param {Object} [options]\n * @param {Boolean} [options.silent]\n * @return {AV.Object} self if succeeded, throws if the value is not valid.\n * @see AV.Object#validate\n */\n set: function(key, value, options) {\n var attrs;\n if (_.isObject(key) || isNullOrUndefined(key)) {\n attrs = _.mapObject(key, function(v, k) {\n checkReservedKey(k);\n return AV._decode(v, k);\n });\n options = value;\n } else {\n attrs = {};\n checkReservedKey(key);\n attrs[key] = AV._decode(value, key);\n }\n\n // Extract attributes and options.\n options = options || {};\n if (!attrs) {\n return this;\n }\n if (attrs instanceof AV.Object) {\n attrs = attrs.attributes;\n }\n\n // If the unset option is used, every attribute should be a Unset.\n if (options.unset) {\n AV._objectEach(attrs, function(unused_value, key) {\n attrs[key] = new AV.Op.Unset();\n });\n }\n\n // Apply all the attributes to get the estimated values.\n var dataToValidate = _.clone(attrs);\n var self = this;\n AV._objectEach(dataToValidate, function(value, key) {\n if (value instanceof AV.Op) {\n dataToValidate[key] = value._estimate(\n self.attributes[key],\n self,\n key\n );\n if (dataToValidate[key] === AV.Op._UNSET) {\n delete dataToValidate[key];\n }\n }\n });\n\n // Run validation.\n this._validate(attrs, options);\n\n options.changes = {};\n var escaped = this._escapedAttributes;\n\n // Update attributes.\n AV._arrayEach(_.keys(attrs), function(attr) {\n var val = attrs[attr];\n\n // If this is a relation object we need to set the parent correctly,\n // since the location where it was parsed does not have access to\n // this object.\n if (val instanceof AV.Relation) {\n val.parent = self;\n }\n\n if (!(val instanceof AV.Op)) {\n val = new AV.Op.Set(val);\n }\n\n // See if this change will actually have any effect.\n var isRealChange = true;\n if (\n val instanceof AV.Op.Set &&\n _.isEqual(self.attributes[attr], val.value)\n ) {\n isRealChange = false;\n }\n\n if (isRealChange) {\n delete escaped[attr];\n if (options.silent) {\n self._silent[attr] = true;\n } else {\n options.changes[attr] = true;\n }\n }\n\n var currentChanges = _.last(self._opSetQueue);\n currentChanges[attr] = val._mergeWithPrevious(currentChanges[attr]);\n self._rebuildEstimatedDataForKey(attr);\n\n if (isRealChange) {\n self.changed[attr] = self.attributes[attr];\n if (!options.silent) {\n self._pending[attr] = true;\n }\n } else {\n delete self.changed[attr];\n delete self._pending[attr];\n }\n });\n\n if (!options.silent) {\n this.change(options);\n }\n return this;\n },\n\n /**\n * Remove an attribute from the model, firing \"change\" unless\n * you choose to silence it. This is a noop if the attribute doesn't\n * exist.\n * @param key {String} The key.\n */\n unset: function(attr, options) {\n options = options || {};\n options.unset = true;\n return this.set(attr, null, options);\n },\n\n /**\n * Atomically increments the value of the given attribute the next time the\n * object is saved. If no amount is specified, 1 is used by default.\n *\n * @param key {String} The key.\n * @param amount {Number} The amount to increment by.\n */\n increment: function(attr, amount) {\n if (_.isUndefined(amount) || _.isNull(amount)) {\n amount = 1;\n }\n return this.set(attr, new AV.Op.Increment(amount));\n },\n\n /**\n * Atomically add an object to the end of the array associated with a given\n * key.\n * @param key {String} The key.\n * @param item {} The item to add.\n */\n add: function(attr, item) {\n return this.set(attr, new AV.Op.Add(ensureArray(item)));\n },\n\n /**\n * Atomically add an object to the array associated with a given key, only\n * if it is not already present in the array. The position of the insert is\n * not guaranteed.\n *\n * @param key {String} The key.\n * @param item {} The object to add.\n */\n addUnique: function(attr, item) {\n return this.set(attr, new AV.Op.AddUnique(ensureArray(item)));\n },\n\n /**\n * Atomically remove all instances of an object from the array associated\n * with a given key.\n *\n * @param key {String} The key.\n * @param item {} The object to remove.\n */\n remove: function(attr, item) {\n return this.set(attr, new AV.Op.Remove(ensureArray(item)));\n },\n\n /**\n * Atomically apply a \"bit and\" operation on the value associated with a\n * given key.\n *\n * @param key {String} The key.\n * @param value {Number} The value to apply.\n */\n bitAnd(attr, value) {\n return this.set(attr, new AV.Op.BitAnd(value));\n },\n\n /**\n * Atomically apply a \"bit or\" operation on the value associated with a\n * given key.\n *\n * @param key {String} The key.\n * @param value {Number} The value to apply.\n */\n bitOr(attr, value) {\n return this.set(attr, new AV.Op.BitOr(value));\n },\n\n /**\n * Atomically apply a \"bit xor\" operation on the value associated with a\n * given key.\n *\n * @param key {String} The key.\n * @param value {Number} The value to apply.\n */\n bitXor(attr, value) {\n return this.set(attr, new AV.Op.BitXor(value));\n },\n\n /**\n * Returns an instance of a subclass of AV.Op describing what kind of\n * modification has been performed on this field since the last time it was\n * saved. For example, after calling object.increment(\"x\"), calling\n * object.op(\"x\") would return an instance of AV.Op.Increment.\n *\n * @param key {String} The key.\n * @returns {AV.Op} The operation, or undefined if none.\n */\n op: function(attr) {\n return _.last(this._opSetQueue)[attr];\n },\n\n /**\n * Clear all attributes on the model, firing \"change\" unless\n * you choose to silence it.\n */\n clear: function(options) {\n options = options || {};\n options.unset = true;\n var keysToClear = _.extend(this.attributes, this._operations);\n return this.set(keysToClear, options);\n },\n\n /**\n * Clears any (or specific) changes to the model made since the last save.\n * @param {string|string[]} [keys] specify keys to revert.\n */\n revert(keys) {\n const lastOp = _.last(this._opSetQueue);\n const _keys = ensureArray(keys || _.keys(lastOp));\n _keys.forEach(key => {\n delete lastOp[key];\n });\n this._rebuildAllEstimatedData();\n return this;\n },\n\n /**\n * Returns a JSON-encoded set of operations to be sent with the next save\n * request.\n * @private\n */\n _getSaveJSON: function() {\n var json = _.clone(_.first(this._opSetQueue));\n AV._objectEach(json, function(op, key) {\n json[key] = op.toJSON();\n });\n return json;\n },\n\n /**\n * Returns true if this object can be serialized for saving.\n * @private\n */\n _canBeSerialized: function() {\n return AV.Object._canBeSerializedAsValue(this.attributes);\n },\n\n /**\n * Fetch the model from the server. If the server's representation of the\n * model differs from its current attributes, they will be overriden,\n * triggering a \"change\" event.\n * @param {Object} fetchOptions Optional options to set 'keys',\n * 'include' and 'includeACL' option.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled when the fetch\n * completes.\n */\n fetch: function(fetchOptions = {}, options) {\n if (!this.id) {\n throw new Error('Cannot fetch unsaved object');\n }\n var self = this;\n var request = _request(\n 'classes',\n this.className,\n this.id,\n 'GET',\n transformFetchOptions(fetchOptions),\n options\n );\n return request.then(function(response) {\n const fetchedAttrs = self.parse(response);\n self._cleanupUnsetKeys(\n fetchedAttrs,\n fetchOptions.keys\n ? ensureArray(fetchOptions.keys)\n .join(',')\n .split(',')\n : undefined\n );\n self._finishFetch(fetchedAttrs, true);\n return self;\n });\n },\n\n _cleanupUnsetKeys(fetchedAttrs, fetchedKeys = _.keys(this._serverData)) {\n _.forEach(fetchedKeys, key => {\n if (fetchedAttrs[key] === undefined) delete this._serverData[key];\n });\n },\n\n /**\n * Set a hash of model attributes, and save the model to the server.\n * updatedAt will be updated when the request returns.\n * You can either call it as:
\n * object.save();
\n * or
\n * object.save(null, options);
\n * or
\n * object.save(attrs, options);
\n * or
\n * object.save(key, value, options);
\n *\n * @example\n * gameTurn.save({\n * player: \"Jake Cutter\",\n * diceRoll: 2\n * }).then(function(gameTurnAgain) {\n * // The save was successful.\n * }, function(error) {\n * // The save failed. Error is an instance of AVError.\n * });\n *\n * @param {AuthOptions} options AuthOptions plus:\n * @param {Boolean} options.fetchWhenSave fetch and update object after save succeeded\n * @param {AV.Query} options.query Save object only when it matches the query\n * @return {Promise} A promise that is fulfilled when the save\n * completes.\n * @see AVError\n */\n save: function(arg1, arg2, arg3) {\n var attrs, current, options;\n if (_.isObject(arg1) || isNullOrUndefined(arg1)) {\n attrs = arg1;\n options = arg2;\n } else {\n attrs = {};\n attrs[arg1] = arg2;\n options = arg3;\n }\n\n options = _.clone(options) || {};\n if (options.wait) {\n current = _.clone(this.attributes);\n }\n\n var setOptions = _.clone(options) || {};\n if (setOptions.wait) {\n setOptions.silent = true;\n }\n if (attrs) {\n this.set(attrs, setOptions);\n }\n\n var model = this;\n\n var unsavedChildren = [];\n var unsavedFiles = [];\n AV.Object._findUnsavedChildren(model, unsavedChildren, unsavedFiles);\n if (unsavedChildren.length + unsavedFiles.length > 1) {\n return AV.Object._deepSaveAsync(this, model, options);\n }\n\n this._startSave();\n this._saving = (this._saving || 0) + 1;\n\n this._allPreviousSaves = this._allPreviousSaves || Promise.resolve();\n this._allPreviousSaves = this._allPreviousSaves\n .catch(e => {})\n .then(function() {\n var method = model.id ? 'PUT' : 'POST';\n\n var json = model._getSaveJSON();\n var query = {};\n\n if (model._fetchWhenSave || options.fetchWhenSave) {\n query['new'] = 'true';\n }\n // user login option\n if (options._failOnNotExist) {\n query.failOnNotExist = 'true';\n }\n\n if (options.query) {\n var queryParams;\n if (typeof options.query._getParams === 'function') {\n queryParams = options.query._getParams();\n if (queryParams) {\n query.where = queryParams.where;\n }\n }\n if (!query.where) {\n var error = new Error('options.query is not an AV.Query');\n throw error;\n }\n }\n\n _.extend(json, model._flags);\n\n var route = 'classes';\n var className = model.className;\n if (model.className === '_User' && !model.id) {\n // Special-case user sign-up.\n route = 'users';\n className = null;\n }\n //hook makeRequest in options.\n var makeRequest = options._makeRequest || _request;\n var requestPromise = makeRequest(\n route,\n className,\n model.id,\n method,\n json,\n options,\n query\n );\n\n requestPromise = requestPromise.then(\n function(resp) {\n var serverAttrs = model.parse(resp);\n if (options.wait) {\n serverAttrs = _.extend(attrs || {}, serverAttrs);\n }\n model._finishSave(serverAttrs);\n if (options.wait) {\n model.set(current, setOptions);\n }\n return model;\n },\n function(error) {\n model._cancelSave();\n throw error;\n }\n );\n\n return requestPromise;\n });\n return this._allPreviousSaves;\n },\n\n /**\n * Destroy this model on the server if it was already persisted.\n * Optimistically removes the model from its collection, if it has one.\n * @param {AuthOptions} options AuthOptions plus:\n * @param {Boolean} [options.wait] wait for the server to respond\n * before removal.\n *\n * @return {Promise} A promise that is fulfilled when the destroy\n * completes.\n */\n destroy: function(options) {\n options = options || {};\n var model = this;\n\n var triggerDestroy = function() {\n model.trigger('destroy', model, model.collection, options);\n };\n\n if (!this.id) {\n return triggerDestroy();\n }\n\n if (!options.wait) {\n triggerDestroy();\n }\n\n var request = _request(\n 'classes',\n this.className,\n this.id,\n 'DELETE',\n this._flags,\n options\n );\n return request.then(function() {\n if (options.wait) {\n triggerDestroy();\n }\n return model;\n });\n },\n\n /**\n * Converts a response into the hash of attributes to be set on the model.\n * @ignore\n */\n parse: function(resp) {\n var output = _.clone(resp);\n ['createdAt', 'updatedAt'].forEach(function(key) {\n if (output[key]) {\n output[key] = AV._parseDate(output[key]);\n }\n });\n if (output.createdAt && !output.updatedAt) {\n output.updatedAt = output.createdAt;\n }\n return output;\n },\n\n /**\n * Creates a new model with identical attributes to this one.\n * @return {AV.Object}\n */\n clone: function() {\n return new this.constructor(this.attributes);\n },\n\n /**\n * Returns true if this object has never been saved to AV.\n * @return {Boolean}\n */\n isNew: function() {\n return !this.id;\n },\n\n /**\n * Call this method to manually fire a `\"change\"` event for this model and\n * a `\"change:attribute\"` event for each changed attribute.\n * Calling this will cause all objects observing the model to update.\n */\n change: function(options) {\n options = options || {};\n var changing = this._changing;\n this._changing = true;\n\n // Silent changes become pending changes.\n var self = this;\n AV._objectEach(this._silent, function(attr) {\n self._pending[attr] = true;\n });\n\n // Silent changes are triggered.\n var changes = _.extend({}, options.changes, this._silent);\n this._silent = {};\n AV._objectEach(changes, function(unused_value, attr) {\n self.trigger('change:' + attr, self, self.get(attr), options);\n });\n if (changing) {\n return this;\n }\n\n // This is to get around lint not letting us make a function in a loop.\n var deleteChanged = function(value, attr) {\n if (!self._pending[attr] && !self._silent[attr]) {\n delete self.changed[attr];\n }\n };\n\n // Continue firing `\"change\"` events while there are pending changes.\n while (!_.isEmpty(this._pending)) {\n this._pending = {};\n this.trigger('change', this, options);\n // Pending and silent changes still remain.\n AV._objectEach(this.changed, deleteChanged);\n self._previousAttributes = _.clone(this.attributes);\n }\n\n this._changing = false;\n return this;\n },\n\n /**\n * Gets the previous value of an attribute, recorded at the time the last\n * \"change\" event was fired.\n * @param {String} attr Name of the attribute to get.\n */\n previous: function(attr) {\n if (!arguments.length || !this._previousAttributes) {\n return null;\n }\n return this._previousAttributes[attr];\n },\n\n /**\n * Gets all of the attributes of the model at the time of the previous\n * \"change\" event.\n * @return {Object}\n */\n previousAttributes: function() {\n return _.clone(this._previousAttributes);\n },\n\n /**\n * Checks if the model is currently in a valid state. It's only possible to\n * get into an *invalid* state if you're using silent changes.\n * @return {Boolean}\n */\n isValid: function() {\n try {\n this.validate(this.attributes);\n } catch (error) {\n return false;\n }\n return true;\n },\n\n /**\n * You should not call this function directly unless you subclass\n * AV.Object, in which case you can override this method\n * to provide additional validation on set and\n * save. Your implementation should throw an Error if\n * the attrs is invalid\n *\n * @param {Object} attrs The current data to validate.\n * @see AV.Object#set\n */\n validate: function(attrs) {\n if (_.has(attrs, 'ACL') && !(attrs.ACL instanceof AV.ACL)) {\n throw new AVError(AVError.OTHER_CAUSE, 'ACL must be a AV.ACL.');\n }\n },\n\n /**\n * Run validation against a set of incoming attributes, returning `true`\n * if all is well. If a specific `error` callback has been passed,\n * call that instead of firing the general `\"error\"` event.\n * @private\n */\n _validate: function(attrs, options) {\n if (options.silent || !this.validate) {\n return;\n }\n attrs = _.extend({}, this.attributes, attrs);\n this.validate(attrs);\n },\n\n /**\n * Returns the ACL for this object.\n * @returns {AV.ACL} An instance of AV.ACL.\n * @see AV.Object#get\n */\n getACL: function() {\n return this.get('ACL');\n },\n\n /**\n * Sets the ACL to be used for this object.\n * @param {AV.ACL} acl An instance of AV.ACL.\n * @param {Object} options Optional Backbone-like options object to be\n * passed in to set.\n * @return {AV.Object} self\n * @see AV.Object#set\n */\n setACL: function(acl, options) {\n return this.set('ACL', acl, options);\n },\n\n disableBeforeHook: function() {\n this.ignoreHook('beforeSave');\n this.ignoreHook('beforeUpdate');\n this.ignoreHook('beforeDelete');\n },\n\n disableAfterHook: function() {\n this.ignoreHook('afterSave');\n this.ignoreHook('afterUpdate');\n this.ignoreHook('afterDelete');\n },\n\n ignoreHook: function(hookName) {\n if (\n !_.contains(\n [\n 'beforeSave',\n 'afterSave',\n 'beforeUpdate',\n 'afterUpdate',\n 'beforeDelete',\n 'afterDelete',\n ],\n hookName\n )\n ) {\n throw new Error('Unsupported hookName: ' + hookName);\n }\n\n if (!AV.hookKey) {\n throw new Error('ignoreHook required hookKey');\n }\n\n if (!this._flags.__ignore_hooks) {\n this._flags.__ignore_hooks = [];\n }\n\n this._flags.__ignore_hooks.push(hookName);\n },\n }\n );\n\n /**\n * Creates an instance of a subclass of AV.Object for the give classname\n * and id.\n * @param {String|Function} class the className or a subclass of AV.Object.\n * @param {String} id The object id of this model.\n * @return {AV.Object} A new subclass instance of AV.Object.\n */\n AV.Object.createWithoutData = (klass, id, hasData) => {\n let _klass;\n if (_.isString(klass)) {\n _klass = AV.Object._getSubclass(klass);\n } else if (klass.prototype && klass.prototype instanceof AV.Object) {\n _klass = klass;\n } else {\n throw new Error('class must be a string or a subclass of AV.Object.');\n }\n if (!id) {\n throw new TypeError('The objectId must be provided');\n }\n const object = new _klass();\n object.id = id;\n object._hasData = hasData;\n return object;\n };\n /**\n * Delete objects in batch.\n * @param {AV.Object[]} objects The AV.Object array to be deleted.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled when the save\n * completes.\n */\n AV.Object.destroyAll = function(objects, options = {}) {\n if (!objects || objects.length === 0) {\n return Promise.resolve();\n }\n const objectsByClassNameAndFlags = _.groupBy(objects, object =>\n JSON.stringify({\n className: object.className,\n flags: object._flags,\n })\n );\n const body = {\n requests: _.map(objectsByClassNameAndFlags, objects => {\n const ids = _.map(objects, 'id').join(',');\n return {\n method: 'DELETE',\n path: `/1.1/classes/${objects[0].className}/${ids}`,\n body: objects[0]._flags,\n };\n }),\n };\n return _request('batch', null, null, 'POST', body, options).then(\n response => {\n const firstError = _.find(response, result => !result.success);\n if (firstError)\n throw new AVError(firstError.error.code, firstError.error.error);\n return undefined;\n }\n );\n };\n\n /**\n * Returns the appropriate subclass for making new instances of the given\n * className string.\n * @private\n */\n AV.Object._getSubclass = function(className) {\n if (!_.isString(className)) {\n throw new Error('AV.Object._getSubclass requires a string argument.');\n }\n var ObjectClass = AV.Object._classMap[className];\n if (!ObjectClass) {\n ObjectClass = AV.Object.extend(className);\n AV.Object._classMap[className] = ObjectClass;\n }\n return ObjectClass;\n };\n\n /**\n * Creates an instance of a subclass of AV.Object for the given classname.\n * @private\n */\n AV.Object._create = function(className, attributes, options) {\n var ObjectClass = AV.Object._getSubclass(className);\n return new ObjectClass(attributes, options);\n };\n\n // Set up a map of className to class so that we can create new instances of\n // AV Objects from JSON automatically.\n AV.Object._classMap = {};\n\n AV.Object._extend = AV._extend;\n\n /**\n * Creates a new model with defined attributes,\n * It's the same with\n *
\n * new AV.Object(attributes, options);\n *
\n * @param {Object} attributes The initial set of data to store in the object.\n * @param {Object} options A set of Backbone-like options for creating the\n * object. The only option currently supported is \"collection\".\n * @return {AV.Object}\n * @since v0.4.4\n * @see AV.Object\n * @see AV.Object.extend\n */\n AV.Object['new'] = function(attributes, options) {\n return new AV.Object(attributes, options);\n };\n\n /**\n * Creates a new subclass of AV.Object for the given AV class name.\n *\n *
Every extension of a AV class will inherit from the most recent\n * previous extension of that class. When a AV.Object is automatically\n * created by parsing JSON, it will use the most recent extension of that\n * class.
\n *\n * @example\n * var MyClass = AV.Object.extend(\"MyClass\", {\n * // Instance properties\n * }, {\n * // Class properties\n * });\n *\n * @param {String} className The name of the AV class backing this model.\n * @param {Object} protoProps Instance properties to add to instances of the\n * class returned from this method.\n * @param {Object} classProps Class properties to add the class returned from\n * this method.\n * @return {Class} A new subclass of AV.Object.\n */\n AV.Object.extend = function(className, protoProps, classProps) {\n // Handle the case with only two args.\n if (!_.isString(className)) {\n if (className && _.has(className, 'className')) {\n return AV.Object.extend(className.className, className, protoProps);\n } else {\n throw new Error(\n \"AV.Object.extend's first argument should be the className.\"\n );\n }\n }\n\n // If someone tries to subclass \"User\", coerce it to the right type.\n if (className === 'User') {\n className = '_User';\n }\n\n var NewClassObject = null;\n if (_.has(AV.Object._classMap, className)) {\n var OldClassObject = AV.Object._classMap[className];\n // This new subclass has been told to extend both from \"this\" and from\n // OldClassObject. This is multiple inheritance, which isn't supported.\n // For now, let's just pick one.\n if (protoProps || classProps) {\n NewClassObject = OldClassObject._extend(protoProps, classProps);\n } else {\n return OldClassObject;\n }\n } else {\n protoProps = protoProps || {};\n protoProps._className = className;\n NewClassObject = this._extend(protoProps, classProps);\n }\n // Extending a subclass should reuse the classname automatically.\n NewClassObject.extend = function(arg0) {\n if (_.isString(arg0) || (arg0 && _.has(arg0, 'className'))) {\n return AV.Object.extend.apply(NewClassObject, arguments);\n }\n var newArguments = [className].concat(_.toArray(arguments));\n return AV.Object.extend.apply(NewClassObject, newArguments);\n };\n // Add the query property descriptor.\n Object.defineProperty(\n NewClassObject,\n 'query',\n Object.getOwnPropertyDescriptor(AV.Object, 'query')\n );\n NewClassObject['new'] = function(attributes, options) {\n return new NewClassObject(attributes, options);\n };\n AV.Object._classMap[className] = NewClassObject;\n return NewClassObject;\n };\n\n // ES6 class syntax support\n Object.defineProperty(AV.Object.prototype, 'className', {\n get: function() {\n const className =\n this._className ||\n this.constructor._LCClassName ||\n this.constructor.name;\n // If someone tries to subclass \"User\", coerce it to the right type.\n if (className === 'User') {\n return '_User';\n }\n return className;\n },\n });\n\n /**\n * Register a class.\n * If a subclass of AV.Object is defined with your own implement\n * rather then AV.Object.extend, the subclass must be registered.\n * @param {Function} klass A subclass of AV.Object\n * @param {String} [name] Specify the name of the class. Useful when the class might be uglified.\n * @example\n * class Person extend AV.Object {}\n * AV.Object.register(Person);\n */\n AV.Object.register = (klass, name) => {\n if (!(klass.prototype instanceof AV.Object)) {\n throw new Error('registered class is not a subclass of AV.Object');\n }\n const className = name || klass.name;\n if (!className.length) {\n throw new Error('registered class must be named');\n }\n if (name) {\n klass._LCClassName = name;\n }\n AV.Object._classMap[className] = klass;\n };\n\n /**\n * Get a new Query of the current class\n * @name query\n * @memberof AV.Object\n * @type AV.Query\n * @readonly\n * @since v3.1.0\n * @example\n * const Post = AV.Object.extend('Post');\n * Post.query.equalTo('author', 'leancloud').find().then();\n */\n Object.defineProperty(AV.Object, 'query', {\n get() {\n return new AV.Query(this.prototype.className);\n },\n });\n\n AV.Object._findUnsavedChildren = function(objects, children, files) {\n AV._traverse(objects, function(object) {\n if (object instanceof AV.Object) {\n if (object.dirty()) {\n children.push(object);\n }\n return;\n }\n\n if (object instanceof AV.File) {\n if (!object.id) {\n files.push(object);\n }\n return;\n }\n });\n };\n\n AV.Object._canBeSerializedAsValue = function(object) {\n var canBeSerializedAsValue = true;\n\n if (object instanceof AV.Object || object instanceof AV.File) {\n canBeSerializedAsValue = !!object.id;\n } else if (_.isArray(object)) {\n AV._arrayEach(object, function(child) {\n if (!AV.Object._canBeSerializedAsValue(child)) {\n canBeSerializedAsValue = false;\n }\n });\n } else if (_.isObject(object)) {\n AV._objectEach(object, function(child) {\n if (!AV.Object._canBeSerializedAsValue(child)) {\n canBeSerializedAsValue = false;\n }\n });\n }\n\n return canBeSerializedAsValue;\n };\n\n AV.Object._deepSaveAsync = function(object, model, options) {\n var unsavedChildren = [];\n var unsavedFiles = [];\n AV.Object._findUnsavedChildren(object, unsavedChildren, unsavedFiles);\n\n unsavedFiles = _.uniq(unsavedFiles);\n\n var promise = Promise.resolve();\n _.each(unsavedFiles, function(file) {\n promise = promise.then(function() {\n return file.save();\n });\n });\n\n var objects = _.uniq(unsavedChildren);\n var remaining = _.uniq(objects);\n\n return promise\n .then(function() {\n return continueWhile(\n function() {\n return remaining.length > 0;\n },\n function() {\n // Gather up all the objects that can be saved in this batch.\n var batch = [];\n var newRemaining = [];\n AV._arrayEach(remaining, function(object) {\n if (object._canBeSerialized()) {\n batch.push(object);\n } else {\n newRemaining.push(object);\n }\n });\n remaining = newRemaining;\n\n // If we can't save any objects, there must be a circular reference.\n if (batch.length === 0) {\n return Promise.reject(\n new AVError(\n AVError.OTHER_CAUSE,\n 'Tried to save a batch with a cycle.'\n )\n );\n }\n\n // Reserve a spot in every object's save queue.\n var readyToStart = Promise.resolve(\n _.map(batch, function(object) {\n return object._allPreviousSaves || Promise.resolve();\n })\n );\n\n // Save a single batch, whether previous saves succeeded or failed.\n const bathSavePromise = readyToStart.then(() =>\n _request(\n 'batch',\n null,\n null,\n 'POST',\n {\n requests: _.map(batch, function(object) {\n var method = object.id ? 'PUT' : 'POST';\n\n var json = object._getSaveJSON();\n\n _.extend(json, object._flags);\n\n var route = 'classes';\n var className = object.className;\n var path = `/${route}/${className}`;\n if (object.className === '_User' && !object.id) {\n // Special-case user sign-up.\n path = '/users';\n }\n\n var path = `/1.1${path}`;\n if (object.id) {\n path = path + '/' + object.id;\n }\n\n object._startSave();\n\n return {\n method: method,\n path: path,\n body: json,\n params:\n options && options.fetchWhenSave\n ? { fetchWhenSave: true }\n : undefined,\n };\n }),\n },\n options\n ).then(function(response) {\n const results = _.map(batch, function(object, i) {\n if (response[i].success) {\n object._finishSave(object.parse(response[i].success));\n return object;\n }\n object._cancelSave();\n return new AVError(\n response[i].error.code,\n response[i].error.error\n );\n });\n return handleBatchResults(results);\n })\n );\n AV._arrayEach(batch, function(object) {\n object._allPreviousSaves = bathSavePromise;\n });\n return bathSavePromise;\n }\n );\n })\n .then(function() {\n return object;\n });\n };\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/object.js","var arrayWithHoles = require(\"./arrayWithHoles.js\");\n\nvar iterableToArrayLimit = require(\"./iterableToArrayLimit.js\");\n\nvar unsupportedIterableToArray = require(\"./unsupportedIterableToArray.js\");\n\nvar nonIterableRest = require(\"./nonIterableRest.js\");\n\nfunction _slicedToArray(arr, i) {\n return arrayWithHoles(arr) || iterableToArrayLimit(arr, i) || unsupportedIterableToArray(arr, i) || nonIterableRest();\n}\n\nmodule.exports = _slicedToArray, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/helpers/slicedToArray.js\n// module id = 501\n// module chunks = 0 1","var _Array$isArray = require(\"@babel/runtime-corejs3/core-js/array/is-array\");\n\nfunction _arrayWithHoles(arr) {\n if (_Array$isArray(arr)) return arr;\n}\n\nmodule.exports = _arrayWithHoles, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/helpers/arrayWithHoles.js\n// module id = 502\n// module chunks = 0 1","module.exports = require(\"core-js-pure/features/array/is-array\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/core-js/array/is-array.js\n// module id = 503\n// module chunks = 0 1","module.exports = require('../../full/array/is-array');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/features/array/is-array.js\n// module id = 504\n// module chunks = 0 1","var parent = require('../../actual/array/is-array');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/full/array/is-array.js\n// module id = 505\n// module chunks = 0 1","var parent = require('../../stable/array/is-array');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/actual/array/is-array.js\n// module id = 506\n// module chunks = 0 1","var parent = require('../../es/array/is-array');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/stable/array/is-array.js\n// module id = 507\n// module chunks = 0 1","require('../../modules/es.array.is-array');\nvar path = require('../../internals/path');\n\nmodule.exports = path.Array.isArray;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/es/array/is-array.js\n// module id = 508\n// module chunks = 0 1","var $ = require('../internals/export');\nvar isArray = require('../internals/is-array');\n\n// `Array.isArray` method\n// https://tc39.es/ecma262/#sec-array.isarray\n$({ target: 'Array', stat: true }, {\n isArray: isArray\n});\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.array.is-array.js\n// module id = 509\n// module chunks = 0 1","var _Symbol = require(\"@babel/runtime-corejs3/core-js/symbol\");\n\nvar _getIteratorMethod = require(\"@babel/runtime-corejs3/core-js/get-iterator-method\");\n\nfunction _iterableToArrayLimit(arr, i) {\n var _i = arr == null ? null : typeof _Symbol !== \"undefined\" && _getIteratorMethod(arr) || arr[\"@@iterator\"];\n\n if (_i == null) return;\n var _arr = [];\n var _n = true;\n var _d = false;\n\n var _s, _e;\n\n try {\n for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {\n _arr.push(_s.value);\n\n if (i && _arr.length === i) break;\n }\n } catch (err) {\n _d = true;\n _e = err;\n } finally {\n try {\n if (!_n && _i[\"return\"] != null) _i[\"return\"]();\n } finally {\n if (_d) throw _e;\n }\n }\n\n return _arr;\n}\n\nmodule.exports = _iterableToArrayLimit, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/helpers/iterableToArrayLimit.js\n// module id = 510\n// module chunks = 0 1","var _sliceInstanceProperty = require(\"@babel/runtime-corejs3/core-js/instance/slice\");\n\nvar _Array$from = require(\"@babel/runtime-corejs3/core-js/array/from\");\n\nvar arrayLikeToArray = require(\"./arrayLikeToArray.js\");\n\nfunction _unsupportedIterableToArray(o, minLen) {\n var _context;\n\n if (!o) return;\n if (typeof o === \"string\") return arrayLikeToArray(o, minLen);\n\n var n = _sliceInstanceProperty(_context = Object.prototype.toString.call(o)).call(_context, 8, -1);\n\n if (n === \"Object\" && o.constructor) n = o.constructor.name;\n if (n === \"Map\" || n === \"Set\") return _Array$from(o);\n if (n === \"Arguments\" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return arrayLikeToArray(o, minLen);\n}\n\nmodule.exports = _unsupportedIterableToArray, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/helpers/unsupportedIterableToArray.js\n// module id = 511\n// module chunks = 0 1","module.exports = require(\"core-js-pure/features/instance/slice\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/core-js/instance/slice.js\n// module id = 512\n// module chunks = 0 1","module.exports = require('../../full/instance/slice');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/features/instance/slice.js\n// module id = 513\n// module chunks = 0 1","var parent = require('../../actual/instance/slice');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/full/instance/slice.js\n// module id = 514\n// module chunks = 0 1","var parent = require('../../stable/instance/slice');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/actual/instance/slice.js\n// module id = 515\n// module chunks = 0 1","module.exports = require(\"core-js-pure/features/array/from\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/core-js/array/from.js\n// module id = 516\n// module chunks = 0 1","module.exports = require('../../full/array/from');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/features/array/from.js\n// module id = 517\n// module chunks = 0 1","var parent = require('../../actual/array/from');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/full/array/from.js\n// module id = 518\n// module chunks = 0 1","var parent = require('../../stable/array/from');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/actual/array/from.js\n// module id = 519\n// module chunks = 0 1","function _arrayLikeToArray(arr, len) {\n if (len == null || len > arr.length) len = arr.length;\n\n for (var i = 0, arr2 = new Array(len); i < len; i++) {\n arr2[i] = arr[i];\n }\n\n return arr2;\n}\n\nmodule.exports = _arrayLikeToArray, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/helpers/arrayLikeToArray.js\n// module id = 520\n// module chunks = 0 1","function _nonIterableRest() {\n throw new TypeError(\"Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\");\n}\n\nmodule.exports = _nonIterableRest, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/helpers/nonIterableRest.js\n// module id = 521\n// module chunks = 0 1","module.exports = require(\"core-js-pure/stable/object/get-own-property-descriptor\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor.js\n// module id = 522\n// module chunks = 0 1","var parent = require('../../es/object/get-own-property-descriptor');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/stable/object/get-own-property-descriptor.js\n// module id = 523\n// module chunks = 0 1","require('../../modules/es.object.get-own-property-descriptor');\nvar path = require('../../internals/path');\n\nvar Object = path.Object;\n\nvar getOwnPropertyDescriptor = module.exports = function getOwnPropertyDescriptor(it, key) {\n return Object.getOwnPropertyDescriptor(it, key);\n};\n\nif (Object.getOwnPropertyDescriptor.sham) getOwnPropertyDescriptor.sham = true;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/es/object/get-own-property-descriptor.js\n// module id = 524\n// module chunks = 0 1","var $ = require('../internals/export');\nvar fails = require('../internals/fails');\nvar toIndexedObject = require('../internals/to-indexed-object');\nvar nativeGetOwnPropertyDescriptor = require('../internals/object-get-own-property-descriptor').f;\nvar DESCRIPTORS = require('../internals/descriptors');\n\nvar FAILS_ON_PRIMITIVES = fails(function () { nativeGetOwnPropertyDescriptor(1); });\nvar FORCED = !DESCRIPTORS || FAILS_ON_PRIMITIVES;\n\n// `Object.getOwnPropertyDescriptor` method\n// https://tc39.es/ecma262/#sec-object.getownpropertydescriptor\n$({ target: 'Object', stat: true, forced: FORCED, sham: !DESCRIPTORS }, {\n getOwnPropertyDescriptor: function getOwnPropertyDescriptor(it, key) {\n return nativeGetOwnPropertyDescriptor(toIndexedObject(it), key);\n }\n});\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.object.get-own-property-descriptor.js\n// module id = 525\n// module chunks = 0 1","const _ = require('underscore');\nconst AVError = require('./error');\n\nmodule.exports = function(AV) {\n AV.Role = AV.Object.extend(\n '_Role',\n /** @lends AV.Role.prototype */ {\n // Instance Methods\n\n /**\n * Represents a Role on the AV server. Roles represent groupings of\n * Users for the purposes of granting permissions (e.g. specifying an ACL\n * for an Object). Roles are specified by their sets of child users and\n * child roles, all of which are granted any permissions that the parent\n * role has.\n *\n *
Roles must have a name (which cannot be changed after creation of the\n * role), and must specify an ACL.
\n * An AV.Role is a local representation of a role persisted to the AV\n * cloud.\n * @class AV.Role\n * @param {String} name The name of the Role to create.\n * @param {AV.ACL} acl The ACL for this role.\n */\n constructor: function(name, acl) {\n if (_.isString(name)) {\n AV.Object.prototype.constructor.call(this, null, null);\n this.setName(name);\n } else {\n AV.Object.prototype.constructor.call(this, name, acl);\n }\n if (acl) {\n if (!(acl instanceof AV.ACL)) {\n throw new TypeError('acl must be an instance of AV.ACL');\n } else {\n this.setACL(acl);\n }\n }\n },\n\n /**\n * Gets the name of the role. You can alternatively call role.get(\"name\")\n *\n * @return {String} the name of the role.\n */\n getName: function() {\n return this.get('name');\n },\n\n /**\n * Sets the name for a role. This value must be set before the role has\n * been saved to the server, and cannot be set once the role has been\n * saved.\n *\n *
\n * A role's name can only contain alphanumeric characters, _, -, and\n * spaces.\n *
\n *\n *
This is equivalent to calling role.set(\"name\", name)
\n *\n * @param {String} name The name of the role.\n */\n setName: function(name, options) {\n return this.set('name', name, options);\n },\n\n /**\n * Gets the AV.Relation for the AV.Users that are direct\n * children of this role. These users are granted any privileges that this\n * role has been granted (e.g. read or write access through ACLs). You can\n * add or remove users from the role through this relation.\n *\n *
This is equivalent to calling role.relation(\"users\")
\n *\n * @return {AV.Relation} the relation for the users belonging to this\n * role.\n */\n getUsers: function() {\n return this.relation('users');\n },\n\n /**\n * Gets the AV.Relation for the AV.Roles that are direct\n * children of this role. These roles' users are granted any privileges that\n * this role has been granted (e.g. read or write access through ACLs). You\n * can add or remove child roles from this role through this relation.\n *\n *
This is equivalent to calling role.relation(\"roles\")
\n *\n * @return {AV.Relation} the relation for the roles belonging to this\n * role.\n */\n getRoles: function() {\n return this.relation('roles');\n },\n\n /**\n * @ignore\n */\n validate: function(attrs, options) {\n if ('name' in attrs && attrs.name !== this.getName()) {\n var newName = attrs.name;\n if (this.id && this.id !== attrs.objectId) {\n // Check to see if the objectId being set matches this.id.\n // This happens during a fetch -- the id is set before calling fetch.\n // Let the name be set in this case.\n return new AVError(\n AVError.OTHER_CAUSE,\n \"A role's name can only be set before it has been saved.\"\n );\n }\n if (!_.isString(newName)) {\n return new AVError(\n AVError.OTHER_CAUSE,\n \"A role's name must be a String.\"\n );\n }\n if (!/^[0-9a-zA-Z\\-_ ]+$/.test(newName)) {\n return new AVError(\n AVError.OTHER_CAUSE,\n \"A role's name can only contain alphanumeric characters, _,\" +\n ' -, and spaces.'\n );\n }\n }\n if (AV.Object.prototype.validate) {\n return AV.Object.prototype.validate.call(this, attrs, options);\n }\n return false;\n },\n }\n );\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/role.js","const _ = require('underscore');\nconst uuid = require('uuid/v4');\nconst AVError = require('./error');\nconst { _request: AVRequest, request } = require('./request');\nconst { getAdapter } = require('./adapter');\n\nconst PLATFORM_ANONYMOUS = 'anonymous';\nconst PLATFORM_QQAPP = 'lc_qqapp';\n\nconst mergeUnionDataIntoAuthData = (defaultUnionIdPlatform = 'weixin') => (\n authData,\n unionId,\n { unionIdPlatform = defaultUnionIdPlatform, asMainAccount = false } = {}\n) => {\n if (typeof unionId !== 'string')\n throw new AVError(AVError.OTHER_CAUSE, 'unionId is not a string');\n if (typeof unionIdPlatform !== 'string')\n throw new AVError(AVError.OTHER_CAUSE, 'unionIdPlatform is not a string');\n\n return _.extend({}, authData, {\n platform: unionIdPlatform,\n unionid: unionId,\n main_account: Boolean(asMainAccount),\n });\n};\n\nmodule.exports = function(AV) {\n /**\n * @class\n *\n *
An AV.User object is a local representation of a user persisted to the\n * LeanCloud server. This class is a subclass of an AV.Object, and retains the\n * same functionality of an AV.Object, but also extends it with various\n * user specific methods, like authentication, signing up, and validation of\n * uniqueness.
\n */\n AV.User = AV.Object.extend(\n '_User',\n /** @lends AV.User.prototype */ {\n // Instance Variables\n _isCurrentUser: false,\n\n // Instance Methods\n\n /**\n * Internal method to handle special fields in a _User response.\n * @private\n */\n _mergeMagicFields: function(attrs) {\n if (attrs.sessionToken) {\n this._sessionToken = attrs.sessionToken;\n delete attrs.sessionToken;\n }\n return AV.User.__super__._mergeMagicFields.call(this, attrs);\n },\n\n /**\n * Removes null values from authData (which exist temporarily for\n * unlinking)\n * @private\n */\n _cleanupAuthData: function() {\n if (!this.isCurrent()) {\n return;\n }\n var authData = this.get('authData');\n if (!authData) {\n return;\n }\n AV._objectEach(this.get('authData'), function(value, key) {\n if (!authData[key]) {\n delete authData[key];\n }\n });\n },\n\n /**\n * Synchronizes authData for all providers.\n * @private\n */\n _synchronizeAllAuthData: function() {\n var authData = this.get('authData');\n if (!authData) {\n return;\n }\n\n var self = this;\n AV._objectEach(this.get('authData'), function(value, key) {\n self._synchronizeAuthData(key);\n });\n },\n\n /**\n * Synchronizes auth data for a provider (e.g. puts the access token in the\n * right place to be used by the Facebook SDK).\n * @private\n */\n _synchronizeAuthData: function(provider) {\n if (!this.isCurrent()) {\n return;\n }\n var authType;\n if (_.isString(provider)) {\n authType = provider;\n provider = AV.User._authProviders[authType];\n } else {\n authType = provider.getAuthType();\n }\n var authData = this.get('authData');\n if (!authData || !provider) {\n return;\n }\n var success = provider.restoreAuthentication(authData[authType]);\n if (!success) {\n this.dissociateAuthData(provider);\n }\n },\n\n _handleSaveResult: function(makeCurrent) {\n // Clean up and synchronize the authData object, removing any unset values\n if (makeCurrent && !AV._config.disableCurrentUser) {\n this._isCurrentUser = true;\n }\n this._cleanupAuthData();\n this._synchronizeAllAuthData();\n // Don't keep the password around.\n delete this._serverData.password;\n this._rebuildEstimatedDataForKey('password');\n this._refreshCache();\n if (\n (makeCurrent || this.isCurrent()) &&\n !AV._config.disableCurrentUser\n ) {\n // Some old version of leanengine-node-sdk will overwrite\n // AV.User._saveCurrentUser which returns no Promise.\n // So we need a Promise wrapper.\n return Promise.resolve(AV.User._saveCurrentUser(this));\n } else {\n return Promise.resolve();\n }\n },\n\n /**\n * Unlike in the Android/iOS SDKs, logInWith is unnecessary, since you can\n * call linkWith on the user (even if it doesn't exist yet on the server).\n * @private\n */\n _linkWith: function(\n provider,\n data,\n { failOnNotExist = false, useMasterKey, sessionToken, user } = {}\n ) {\n var authType;\n if (_.isString(provider)) {\n authType = provider;\n provider = AV.User._authProviders[provider];\n } else {\n authType = provider.getAuthType();\n }\n if (data) {\n return this.save(\n { authData: { [authType]: data } },\n {\n useMasterKey,\n sessionToken,\n user,\n fetchWhenSave: !!this.get('authData'),\n _failOnNotExist: failOnNotExist,\n }\n ).then(function(model) {\n return model._handleSaveResult(true).then(function() {\n return model;\n });\n });\n } else {\n return provider\n .authenticate()\n .then(result => this._linkWith(provider, result));\n }\n },\n\n /**\n * Associate the user with a third party authData.\n * @since 3.3.0\n * @param {Object} authData The response json data returned from third party token, maybe like { openid: 'abc123', access_token: '123abc', expires_in: 1382686496 }\n * @param {string} platform Available platform for sign up.\n * @return {Promise} A promise that is fulfilled with the user when completed.\n * @example user.associateWithAuthData({\n * openid: 'abc123',\n * access_token: '123abc',\n * expires_in: 1382686496\n * }, 'weixin').then(function(user) {\n * //Access user here\n * }).catch(function(error) {\n * //console.error(\"error: \", error);\n * });\n */\n associateWithAuthData(authData, platform) {\n return this._linkWith(platform, authData);\n },\n\n /**\n * Associate the user with a third party authData and unionId.\n * @since 3.5.0\n * @param {Object} authData The response json data returned from third party token, maybe like { openid: 'abc123', access_token: '123abc', expires_in: 1382686496 }\n * @param {string} platform Available platform for sign up.\n * @param {string} unionId\n * @param {Object} [unionLoginOptions]\n * @param {string} [unionLoginOptions.unionIdPlatform = 'weixin'] unionId platform\n * @param {boolean} [unionLoginOptions.asMainAccount = false] If true, the unionId will be associated with the user.\n * @return {Promise} A promise that is fulfilled with the user when completed.\n * @example user.associateWithAuthDataAndUnionId({\n * openid: 'abc123',\n * access_token: '123abc',\n * expires_in: 1382686496\n * }, 'weixin', 'union123', {\n * unionIdPlatform: 'weixin',\n * asMainAccount: true,\n * }).then(function(user) {\n * //Access user here\n * }).catch(function(error) {\n * //console.error(\"error: \", error);\n * });\n */\n associateWithAuthDataAndUnionId(\n authData,\n platform,\n unionId,\n unionOptions\n ) {\n return this._linkWith(\n platform,\n mergeUnionDataIntoAuthData()(authData, unionId, unionOptions)\n );\n },\n\n /**\n * Associate the user with the identity of the current mini-app.\n * @since 4.6.0\n * @param {Object} [authInfo]\n * @param {Object} [option]\n * @param {Boolean} [option.failOnNotExist] If true, the login request will fail when no user matches this authInfo.authData exists.\n * @return {Promise}\n */\n associateWithMiniApp(authInfo, option) {\n if (authInfo === undefined) {\n const getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo().then(authInfo =>\n this._linkWith(authInfo.provider, authInfo.authData, option)\n );\n }\n return this._linkWith(authInfo.provider, authInfo.authData, option);\n },\n\n /**\n * 将用户与 QQ 小程序用户进行关联。适用于为已经在用户系统中存在的用户关联当前使用 QQ 小程序的微信帐号。\n * 仅在 QQ 小程序中可用。\n *\n * @deprecated Please use {@link AV.User#associateWithMiniApp}\n * @since 4.2.0\n * @param {Object} [options]\n * @param {boolean} [options.preferUnionId = false] 如果服务端在登录时获取到了用户的 UnionId,是否将 UnionId 保存在用户账号中。\n * @param {string} [options.unionIdPlatform = 'qq'] (only take effect when preferUnionId) unionId platform\n * @param {boolean} [options.asMainAccount = true] (only take effect when preferUnionId) If true, the unionId will be associated with the user.\n * @return {Promise}\n */\n associateWithQQApp({\n preferUnionId = false,\n unionIdPlatform = 'qq',\n asMainAccount = true,\n } = {}) {\n const getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo({\n preferUnionId,\n asMainAccount,\n platform: unionIdPlatform,\n }).then(authInfo => {\n authInfo.provider = PLATFORM_QQAPP;\n return this.associateWithMiniApp(authInfo);\n });\n },\n\n /**\n * 将用户与微信小程序用户进行关联。适用于为已经在用户系统中存在的用户关联当前使用微信小程序的微信帐号。\n * 仅在微信小程序中可用。\n *\n * @deprecated Please use {@link AV.User#associateWithMiniApp}\n * @since 3.13.0\n * @param {Object} [options]\n * @param {boolean} [options.preferUnionId = false] 当用户满足 {@link https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/union-id.html 获取 UnionId 的条件} 时,是否将 UnionId 保存在用户账号中。\n * @param {string} [options.unionIdPlatform = 'weixin'] (only take effect when preferUnionId) unionId platform\n * @param {boolean} [options.asMainAccount = true] (only take effect when preferUnionId) If true, the unionId will be associated with the user.\n * @return {Promise}\n */\n associateWithWeapp({\n preferUnionId = false,\n unionIdPlatform = 'weixin',\n asMainAccount = true,\n } = {}) {\n const getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo({\n preferUnionId,\n asMainAccount,\n platform: unionIdPlatform,\n }).then(authInfo => this.associateWithMiniApp(authInfo));\n },\n\n /**\n * @deprecated renamed to {@link AV.User#associateWithWeapp}\n * @return {Promise}\n */\n linkWithWeapp(options) {\n console.warn(\n 'DEPRECATED: User#linkWithWeapp 已废弃,请使用 User#associateWithWeapp 代替'\n );\n return this.associateWithWeapp(options);\n },\n\n /**\n * 将用户与 QQ 小程序用户进行关联。适用于为已经在用户系统中存在的用户关联当前使用 QQ 小程序的 QQ 帐号。\n * 仅在 QQ 小程序中可用。\n *\n * @deprecated Please use {@link AV.User#associateWithMiniApp}\n * @since 4.2.0\n * @param {string} unionId\n * @param {Object} [unionOptions]\n * @param {string} [unionOptions.unionIdPlatform = 'qq'] unionId platform\n * @param {boolean} [unionOptions.asMainAccount = false] If true, the unionId will be associated with the user.\n * @return {Promise}\n */\n associateWithQQAppWithUnionId(\n unionId,\n { unionIdPlatform = 'qq', asMainAccount = false } = {}\n ) {\n const getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo({ platform: unionIdPlatform }).then(authInfo => {\n authInfo = AV.User.mergeUnionId(authInfo, unionId, { asMainAccount });\n authInfo.provider = PLATFORM_QQAPP;\n return this.associateWithMiniApp(authInfo);\n });\n },\n\n /**\n * 将用户与微信小程序用户进行关联。适用于为已经在用户系统中存在的用户关联当前使用微信小程序的微信帐号。\n * 仅在微信小程序中可用。\n *\n * @deprecated Please use {@link AV.User#associateWithMiniApp}\n * @since 3.13.0\n * @param {string} unionId\n * @param {Object} [unionOptions]\n * @param {string} [unionOptions.unionIdPlatform = 'weixin'] unionId platform\n * @param {boolean} [unionOptions.asMainAccount = false] If true, the unionId will be associated with the user.\n * @return {Promise}\n */\n associateWithWeappWithUnionId(\n unionId,\n { unionIdPlatform = 'weixin', asMainAccount = false } = {}\n ) {\n const getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo({ platform: unionIdPlatform }).then(authInfo => {\n authInfo = AV.User.mergeUnionId(authInfo, unionId, { asMainAccount });\n return this.associateWithMiniApp(authInfo);\n });\n },\n\n /**\n * Unlinks a user from a service.\n * @param {string} platform\n * @return {Promise}\n * @since 3.3.0\n */\n dissociateAuthData(provider) {\n this.unset(`authData.${provider}`);\n return this.save().then(model =>\n model._handleSaveResult(true).then(() => model)\n );\n },\n\n /**\n * @private\n * @deprecated\n */\n _unlinkFrom(provider) {\n console.warn(\n 'DEPRECATED: User#_unlinkFrom 已废弃,请使用 User#dissociateAuthData 代替'\n );\n return this.dissociateAuthData(provider);\n },\n\n /**\n * Checks whether a user is linked to a service.\n * @private\n */\n _isLinked: function(provider) {\n var authType;\n if (_.isString(provider)) {\n authType = provider;\n } else {\n authType = provider.getAuthType();\n }\n var authData = this.get('authData') || {};\n return !!authData[authType];\n },\n\n /**\n * Checks whether a user is anonymous.\n * @since 3.9.0\n * @return {boolean}\n */\n isAnonymous() {\n return this._isLinked(PLATFORM_ANONYMOUS);\n },\n\n logOut: function() {\n this._logOutWithAll();\n this._isCurrentUser = false;\n },\n\n /**\n * Deauthenticates all providers.\n * @private\n */\n _logOutWithAll: function() {\n var authData = this.get('authData');\n if (!authData) {\n return;\n }\n var self = this;\n AV._objectEach(this.get('authData'), function(value, key) {\n self._logOutWith(key);\n });\n },\n\n /**\n * Deauthenticates a single provider (e.g. removing access tokens from the\n * Facebook SDK).\n * @private\n */\n _logOutWith: function(provider) {\n if (!this.isCurrent()) {\n return;\n }\n if (_.isString(provider)) {\n provider = AV.User._authProviders[provider];\n }\n if (provider && provider.deauthenticate) {\n provider.deauthenticate();\n }\n },\n\n /**\n * Signs up a new user. You should call this instead of save for\n * new AV.Users. This will create a new AV.User on the server, and\n * also persist the session on disk so that you can access the user using\n * current.\n *\n *
A username and password must be set before calling signUp.
\n *\n * @param {Object} attrs Extra fields to set on the new user, or null.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled when the signup\n * finishes.\n * @see AV.User.signUp\n */\n signUp: function(attrs, options) {\n var error;\n\n var username = (attrs && attrs.username) || this.get('username');\n if (!username || username === '') {\n error = new AVError(\n AVError.OTHER_CAUSE,\n 'Cannot sign up user with an empty name.'\n );\n throw error;\n }\n\n var password = (attrs && attrs.password) || this.get('password');\n if (!password || password === '') {\n error = new AVError(\n AVError.OTHER_CAUSE,\n 'Cannot sign up user with an empty password.'\n );\n throw error;\n }\n\n return this.save(attrs, options).then(function(model) {\n if (model.isAnonymous()) {\n model.unset(`authData.${PLATFORM_ANONYMOUS}`);\n model._opSetQueue = [{}];\n }\n return model._handleSaveResult(true).then(function() {\n return model;\n });\n });\n },\n\n /**\n * Signs up a new user with mobile phone and sms code.\n * You should call this instead of save for\n * new AV.Users. This will create a new AV.User on the server, and\n * also persist the session on disk so that you can access the user using\n * current.\n *\n *
A username and password must be set before calling signUp.
\n *\n * @param {Object} attrs Extra fields to set on the new user, or null.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled when the signup\n * finishes.\n * @see AV.User.signUpOrlogInWithMobilePhone\n * @see AV.Cloud.requestSmsCode\n */\n signUpOrlogInWithMobilePhone: function(attrs, options = {}) {\n var error;\n\n var mobilePhoneNumber =\n (attrs && attrs.mobilePhoneNumber) || this.get('mobilePhoneNumber');\n if (!mobilePhoneNumber || mobilePhoneNumber === '') {\n error = new AVError(\n AVError.OTHER_CAUSE,\n 'Cannot sign up or login user by mobilePhoneNumber ' +\n 'with an empty mobilePhoneNumber.'\n );\n throw error;\n }\n\n var smsCode = (attrs && attrs.smsCode) || this.get('smsCode');\n if (!smsCode || smsCode === '') {\n error = new AVError(\n AVError.OTHER_CAUSE,\n 'Cannot sign up or login user by mobilePhoneNumber ' +\n 'with an empty smsCode.'\n );\n throw error;\n }\n\n options._makeRequest = function(route, className, id, method, json) {\n return AVRequest('usersByMobilePhone', null, null, 'POST', json);\n };\n return this.save(attrs, options).then(function(model) {\n delete model.attributes.smsCode;\n delete model._serverData.smsCode;\n return model._handleSaveResult(true).then(function() {\n return model;\n });\n });\n },\n\n /**\n * The same with {@link AV.User.loginWithAuthData}, except that you can set attributes before login.\n * @since 3.7.0\n */\n loginWithAuthData(authData, platform, options) {\n return this._linkWith(platform, authData, options);\n },\n\n /**\n * The same with {@link AV.User.loginWithAuthDataAndUnionId}, except that you can set attributes before login.\n * @since 3.7.0\n */\n loginWithAuthDataAndUnionId(\n authData,\n platform,\n unionId,\n unionLoginOptions\n ) {\n return this.loginWithAuthData(\n mergeUnionDataIntoAuthData()(authData, unionId, unionLoginOptions),\n platform,\n unionLoginOptions\n );\n },\n\n /**\n * The same with {@link AV.User.loginWithWeapp}, except that you can set attributes before login.\n * @deprecated please use {@link AV.User#loginWithMiniApp}\n * @since 3.7.0\n * @param {Object} [options]\n * @param {boolean} [options.failOnNotExist] If true, the login request will fail when no user matches this authData exists.\n * @param {boolean} [options.preferUnionId] 当用户满足 {@link https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/union-id.html 获取 UnionId 的条件} 时,是否使用 UnionId 登录。(since 3.13.0)\n * @param {string} [options.unionIdPlatform = 'weixin'] (only take effect when preferUnionId) unionId platform\n * @param {boolean} [options.asMainAccount = true] (only take effect when preferUnionId) If true, the unionId will be associated with the user.\n * @return {Promise}\n */\n loginWithWeapp({\n preferUnionId = false,\n unionIdPlatform = 'weixin',\n asMainAccount = true,\n failOnNotExist = false,\n useMasterKey,\n sessionToken,\n user,\n } = {}) {\n const getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo({\n preferUnionId,\n asMainAccount,\n platform: unionIdPlatform,\n }).then(authInfo =>\n this.loginWithMiniApp(authInfo, {\n failOnNotExist,\n useMasterKey,\n sessionToken,\n user,\n })\n );\n },\n\n /**\n * The same with {@link AV.User.loginWithWeappWithUnionId}, except that you can set attributes before login.\n * @deprecated please use {@link AV.User#loginWithMiniApp}\n * @since 3.13.0\n */\n loginWithWeappWithUnionId(\n unionId,\n {\n unionIdPlatform = 'weixin',\n asMainAccount = false,\n failOnNotExist = false,\n useMasterKey,\n sessionToken,\n user,\n } = {}\n ) {\n const getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo({ platform: unionIdPlatform }).then(authInfo => {\n authInfo = AV.User.mergeUnionId(authInfo, unionId, { asMainAccount });\n return this.loginWithMiniApp(authInfo, {\n failOnNotExist,\n useMasterKey,\n sessionToken,\n user,\n });\n });\n },\n\n /**\n * The same with {@link AV.User.loginWithQQApp}, except that you can set attributes before login.\n * @deprecated please use {@link AV.User#loginWithMiniApp}\n * @since 4.2.0\n * @param {Object} [options]\n * @param {boolean} [options.failOnNotExist] If true, the login request will fail when no user matches this authData exists.\n * @param {boolean} [options.preferUnionId] 如果服务端在登录时获取到了用户的 UnionId,是否将 UnionId 保存在用户账号中。\n * @param {string} [options.unionIdPlatform = 'qq'] (only take effect when preferUnionId) unionId platform\n * @param {boolean} [options.asMainAccount = true] (only take effect when preferUnionId) If true, the unionId will be associated with the user.\n */\n loginWithQQApp({\n preferUnionId = false,\n unionIdPlatform = 'qq',\n asMainAccount = true,\n failOnNotExist = false,\n useMasterKey,\n sessionToken,\n user,\n } = {}) {\n const getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo({\n preferUnionId,\n asMainAccount,\n platform: unionIdPlatform,\n }).then(authInfo => {\n authInfo.provider = PLATFORM_QQAPP;\n return this.loginWithMiniApp(authInfo, {\n failOnNotExist,\n useMasterKey,\n sessionToken,\n user,\n });\n });\n },\n\n /**\n * The same with {@link AV.User.loginWithQQAppWithUnionId}, except that you can set attributes before login.\n * @deprecated please use {@link AV.User#loginWithMiniApp}\n * @since 4.2.0\n */\n loginWithQQAppWithUnionId(\n unionId,\n {\n unionIdPlatform = 'qq',\n asMainAccount = false,\n failOnNotExist = false,\n useMasterKey,\n sessionToken,\n user,\n } = {}\n ) {\n const getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo({ platform: unionIdPlatform }).then(authInfo => {\n authInfo = AV.User.mergeUnionId(authInfo, unionId, { asMainAccount });\n authInfo.provider = PLATFORM_QQAPP;\n return this.loginWithMiniApp(authInfo, {\n failOnNotExist,\n useMasterKey,\n sessionToken,\n user,\n });\n });\n },\n\n /**\n * The same with {@link AV.User.loginWithMiniApp}, except that you can set attributes before login.\n * @since 4.6.0\n */\n loginWithMiniApp(authInfo, option) {\n if (authInfo === undefined) {\n const getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo().then(authInfo =>\n this.loginWithAuthData(authInfo.authData, authInfo.provider, option)\n );\n }\n return this.loginWithAuthData(\n authInfo.authData,\n authInfo.provider,\n option\n );\n },\n\n /**\n * Logs in a AV.User. On success, this saves the session to localStorage,\n * so you can retrieve the currently logged in user using\n * current.\n *\n *
A username and password must be set before calling logIn.
\n *\n * @see AV.User.logIn\n * @return {Promise} A promise that is fulfilled with the user when\n * the login is complete.\n */\n logIn: function() {\n var model = this;\n var request = AVRequest('login', null, null, 'POST', this.toJSON());\n return request.then(function(resp) {\n var serverAttrs = model.parse(resp);\n model._finishFetch(serverAttrs);\n return model._handleSaveResult(true).then(function() {\n if (!serverAttrs.smsCode) delete model.attributes['smsCode'];\n return model;\n });\n });\n },\n /**\n * @see AV.Object#save\n */\n save: function(arg1, arg2, arg3) {\n var attrs, options;\n if (_.isObject(arg1) || _.isNull(arg1) || _.isUndefined(arg1)) {\n attrs = arg1;\n options = arg2;\n } else {\n attrs = {};\n attrs[arg1] = arg2;\n options = arg3;\n }\n options = options || {};\n\n return AV.Object.prototype.save\n .call(this, attrs, options)\n .then(function(model) {\n return model._handleSaveResult(false).then(function() {\n return model;\n });\n });\n },\n\n /**\n * Follow a user\n * @since 0.3.0\n * @param {Object | AV.User | String} options if an AV.User or string is given, it will be used as the target user.\n * @param {AV.User | String} options.user The target user or user's objectId to follow.\n * @param {Object} [options.attributes] key-value attributes dictionary to be used as\n * conditions of followerQuery/followeeQuery.\n * @param {AuthOptions} [authOptions]\n */\n follow: function(options, authOptions) {\n if (!this.id) {\n throw new Error('Please signin.');\n }\n let user;\n let attributes;\n if (options.user) {\n user = options.user;\n attributes = options.attributes;\n } else {\n user = options;\n }\n var userObjectId = _.isString(user) ? user : user.id;\n if (!userObjectId) {\n throw new Error('Invalid target user.');\n }\n var route = 'users/' + this.id + '/friendship/' + userObjectId;\n var request = AVRequest(\n route,\n null,\n null,\n 'POST',\n AV._encode(attributes),\n authOptions\n );\n return request;\n },\n\n /**\n * Unfollow a user.\n * @since 0.3.0\n * @param {Object | AV.User | String} options if an AV.User or string is given, it will be used as the target user.\n * @param {AV.User | String} options.user The target user or user's objectId to unfollow.\n * @param {AuthOptions} [authOptions]\n */\n unfollow: function(options, authOptions) {\n if (!this.id) {\n throw new Error('Please signin.');\n }\n let user;\n if (options.user) {\n user = options.user;\n } else {\n user = options;\n }\n var userObjectId = _.isString(user) ? user : user.id;\n if (!userObjectId) {\n throw new Error('Invalid target user.');\n }\n var route = 'users/' + this.id + '/friendship/' + userObjectId;\n var request = AVRequest(route, null, null, 'DELETE', null, authOptions);\n return request;\n },\n\n /**\n * Get the user's followers and followees.\n * @since 4.8.0\n * @param {Object} [options]\n * @param {Number} [options.skip]\n * @param {Number} [options.limit]\n * @param {AuthOptions} [authOptions]\n */\n getFollowersAndFollowees: function(options, authOptions) {\n if (!this.id) {\n throw new Error('Please signin.');\n }\n return request({\n method: 'GET',\n path: `/users/${this.id}/followersAndFollowees`,\n query: {\n skip: options && options.skip,\n limit: options && options.limit,\n include: 'follower,followee',\n keys: 'follower,followee',\n },\n authOptions,\n }).then(({ followers, followees }) => ({\n followers: followers.map(({ follower }) => AV._decode(follower)),\n followees: followees.map(({ followee }) => AV._decode(followee)),\n }));\n },\n\n /**\n *Create a follower query to query the user's followers.\n * @since 0.3.0\n * @see AV.User#followerQuery\n */\n followerQuery: function() {\n return AV.User.followerQuery(this.id);\n },\n\n /**\n *Create a followee query to query the user's followees.\n * @since 0.3.0\n * @see AV.User#followeeQuery\n */\n followeeQuery: function() {\n return AV.User.followeeQuery(this.id);\n },\n\n /**\n * @see AV.Object#fetch\n */\n fetch: function(fetchOptions, options) {\n return AV.Object.prototype.fetch\n .call(this, fetchOptions, options)\n .then(function(model) {\n return model._handleSaveResult(false).then(function() {\n return model;\n });\n });\n },\n\n /**\n * Update user's new password safely based on old password.\n * @param {String} oldPassword the old password.\n * @param {String} newPassword the new password.\n * @param {AuthOptions} options\n */\n updatePassword: function(oldPassword, newPassword, options) {\n var route = 'users/' + this.id + '/updatePassword';\n var params = {\n old_password: oldPassword,\n new_password: newPassword,\n };\n var request = AVRequest(route, null, null, 'PUT', params, options);\n return request.then(resp => {\n this._finishFetch(this.parse(resp));\n return this._handleSaveResult(true).then(() => resp);\n });\n },\n\n /**\n * Returns true if current would return this user.\n * @see AV.User#current\n */\n isCurrent: function() {\n return this._isCurrentUser;\n },\n\n /**\n * Returns get(\"username\").\n * @return {String}\n * @see AV.Object#get\n */\n getUsername: function() {\n return this.get('username');\n },\n\n /**\n * Returns get(\"mobilePhoneNumber\").\n * @return {String}\n * @see AV.Object#get\n */\n getMobilePhoneNumber: function() {\n return this.get('mobilePhoneNumber');\n },\n\n /**\n * Calls set(\"mobilePhoneNumber\", phoneNumber, options) and returns the result.\n * @param {String} mobilePhoneNumber\n * @return {Boolean}\n * @see AV.Object#set\n */\n setMobilePhoneNumber: function(phone, options) {\n return this.set('mobilePhoneNumber', phone, options);\n },\n\n /**\n * Calls set(\"username\", username, options) and returns the result.\n * @param {String} username\n * @return {Boolean}\n * @see AV.Object#set\n */\n setUsername: function(username, options) {\n return this.set('username', username, options);\n },\n\n /**\n * Calls set(\"password\", password, options) and returns the result.\n * @param {String} password\n * @return {Boolean}\n * @see AV.Object#set\n */\n setPassword: function(password, options) {\n return this.set('password', password, options);\n },\n\n /**\n * Returns get(\"email\").\n * @return {String}\n * @see AV.Object#get\n */\n getEmail: function() {\n return this.get('email');\n },\n\n /**\n * Calls set(\"email\", email, options) and returns the result.\n * @param {String} email\n * @param {AuthOptions} options\n * @return {Boolean}\n * @see AV.Object#set\n */\n setEmail: function(email, options) {\n return this.set('email', email, options);\n },\n\n /**\n * Checks whether this user is the current user and has been authenticated.\n * @deprecated 如果要判断当前用户的登录状态是否有效,请使用 currentUser.isAuthenticated().then(),\n * 如果要判断该用户是否是当前登录用户,请使用 user.id === currentUser.id\n * @return (Boolean) whether this user is the current user and is logged in.\n */\n authenticated: function() {\n console.warn(\n 'DEPRECATED: 如果要判断当前用户的登录状态是否有效,请使用 currentUser.isAuthenticated().then(),如果要判断该用户是否是当前登录用户,请使用 user.id === currentUser.id。'\n );\n return (\n !!this._sessionToken &&\n (!AV._config.disableCurrentUser &&\n AV.User.current() &&\n AV.User.current().id === this.id)\n );\n },\n\n /**\n * Detects if current sessionToken is valid.\n *\n * @since 2.0.0\n * @return Promise.\n */\n isAuthenticated() {\n return Promise.resolve().then(\n () =>\n !!this._sessionToken &&\n AV.User._fetchUserBySessionToken(this._sessionToken).then(\n () => true,\n error => {\n if (error.code === 211) {\n return false;\n }\n throw error;\n }\n )\n );\n },\n\n /**\n * Get sessionToken of current user.\n * @return {String} sessionToken\n */\n getSessionToken() {\n return this._sessionToken;\n },\n\n /**\n * Refresh sessionToken of current user.\n * @since 2.1.0\n * @param {AuthOptions} [options]\n * @return {Promise.} user with refreshed sessionToken\n */\n refreshSessionToken(options) {\n return AVRequest(\n `users/${this.id}/refreshSessionToken`,\n null,\n null,\n 'PUT',\n null,\n options\n ).then(response => {\n this._finishFetch(response);\n return this._handleSaveResult(true).then(() => this);\n });\n },\n\n /**\n * Get this user's Roles.\n * @param {AuthOptions} [options]\n * @return {Promise.} A promise that is fulfilled with the roles when\n * the query is complete.\n */\n getRoles(options) {\n return AV.Relation.reverseQuery('_Role', 'users', this).find(options);\n },\n },\n /** @lends AV.User */ {\n // Class Variables\n\n // The currently logged-in user.\n _currentUser: null,\n\n // Whether currentUser is known to match the serialized version on disk.\n // This is useful for saving a localstorage check if you try to load\n // _currentUser frequently while there is none stored.\n _currentUserMatchesDisk: false,\n\n // The localStorage key suffix that the current user is stored under.\n _CURRENT_USER_KEY: 'currentUser',\n\n // The mapping of auth provider names to actual providers\n _authProviders: {},\n\n // Class Methods\n\n /**\n * Signs up a new user with a username (or email) and password.\n * This will create a new AV.User on the server, and also persist the\n * session in localStorage so that you can access the user using\n * {@link #current}.\n *\n * @param {String} username The username (or email) to sign up with.\n * @param {String} password The password to sign up with.\n * @param {Object} [attrs] Extra fields to set on the new user.\n * @param {AuthOptions} [options]\n * @return {Promise} A promise that is fulfilled with the user when\n * the signup completes.\n * @see AV.User#signUp\n */\n signUp: function(username, password, attrs, options) {\n attrs = attrs || {};\n attrs.username = username;\n attrs.password = password;\n var user = AV.Object._create('_User');\n return user.signUp(attrs, options);\n },\n\n /**\n * Logs in a user with a username (or email) and password. On success, this\n * saves the session to disk, so you can retrieve the currently logged in\n * user using current.\n *\n * @param {String} username The username (or email) to log in with.\n * @param {String} password The password to log in with.\n * @return {Promise} A promise that is fulfilled with the user when\n * the login completes.\n * @see AV.User#logIn\n */\n logIn: function(username, password) {\n var user = AV.Object._create('_User');\n user._finishFetch({ username: username, password: password });\n return user.logIn();\n },\n\n /**\n * Logs in a user with a session token. On success, this saves the session\n * to disk, so you can retrieve the currently logged in user using\n * current.\n *\n * @param {String} sessionToken The sessionToken to log in with.\n * @return {Promise} A promise that is fulfilled with the user when\n * the login completes.\n */\n become: function(sessionToken) {\n return this._fetchUserBySessionToken(sessionToken).then(user =>\n user._handleSaveResult(true).then(() => user)\n );\n },\n\n _fetchUserBySessionToken: function(sessionToken) {\n if (sessionToken === undefined) {\n return Promise.reject(\n new Error('The sessionToken cannot be undefined')\n );\n }\n\n var user = AV.Object._create('_User');\n return request({\n method: 'GET',\n path: '/users/me',\n authOptions: {\n sessionToken,\n },\n }).then(function(resp) {\n var serverAttrs = user.parse(resp);\n user._finishFetch(serverAttrs);\n return user;\n });\n },\n\n /**\n * Logs in a user with a mobile phone number and sms code sent by\n * AV.User.requestLoginSmsCode.On success, this\n * saves the session to disk, so you can retrieve the currently logged in\n * user using current.\n *\n * @param {String} mobilePhone The user's mobilePhoneNumber\n * @param {String} smsCode The sms code sent by AV.User.requestLoginSmsCode\n * @return {Promise} A promise that is fulfilled with the user when\n * the login completes.\n * @see AV.User#logIn\n */\n logInWithMobilePhoneSmsCode: function(mobilePhone, smsCode) {\n var user = AV.Object._create('_User');\n user._finishFetch({ mobilePhoneNumber: mobilePhone, smsCode: smsCode });\n return user.logIn();\n },\n\n /**\n * Signs up or logs in a user with a mobilePhoneNumber and smsCode.\n * On success, this saves the session to disk, so you can retrieve the currently\n * logged in user using current.\n *\n * @param {String} mobilePhoneNumber The user's mobilePhoneNumber.\n * @param {String} smsCode The sms code sent by AV.Cloud.requestSmsCode\n * @param {Object} attributes The user's other attributes such as username etc.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled with the user when\n * the login completes.\n * @see AV.User#signUpOrlogInWithMobilePhone\n * @see AV.Cloud.requestSmsCode\n */\n signUpOrlogInWithMobilePhone: function(\n mobilePhoneNumber,\n smsCode,\n attrs,\n options\n ) {\n attrs = attrs || {};\n attrs.mobilePhoneNumber = mobilePhoneNumber;\n attrs.smsCode = smsCode;\n var user = AV.Object._create('_User');\n return user.signUpOrlogInWithMobilePhone(attrs, options);\n },\n\n /**\n * Logs in a user with a mobile phone number and password. On success, this\n * saves the session to disk, so you can retrieve the currently logged in\n * user using current.\n *\n * @param {String} mobilePhone The user's mobilePhoneNumber\n * @param {String} password The password to log in with.\n * @return {Promise} A promise that is fulfilled with the user when\n * the login completes.\n * @see AV.User#logIn\n */\n logInWithMobilePhone: function(mobilePhone, password) {\n var user = AV.Object._create('_User');\n user._finishFetch({\n mobilePhoneNumber: mobilePhone,\n password: password,\n });\n return user.logIn();\n },\n\n /**\n * Logs in a user with email and password.\n *\n * @since 3.13.0\n * @param {String} email The user's email.\n * @param {String} password The password to log in with.\n * @return {Promise} A promise that is fulfilled with the user when\n * the login completes.\n */\n loginWithEmail(email, password) {\n const user = AV.Object._create('_User');\n user._finishFetch({\n email,\n password,\n });\n return user.logIn();\n },\n\n /**\n * Signs up or logs in a user with a third party auth data(AccessToken).\n * On success, this saves the session to disk, so you can retrieve the currently\n * logged in user using current.\n *\n * @since 3.7.0\n * @param {Object} authData The response json data returned from third party token, maybe like { openid: 'abc123', access_token: '123abc', expires_in: 1382686496 }\n * @param {string} platform Available platform for sign up.\n * @param {Object} [options]\n * @param {boolean} [options.failOnNotExist] If true, the login request will fail when no user matches this authData exists.\n * @return {Promise} A promise that is fulfilled with the user when\n * the login completes.\n * @example AV.User.loginWithAuthData({\n * openid: 'abc123',\n * access_token: '123abc',\n * expires_in: 1382686496\n * }, 'weixin').then(function(user) {\n * //Access user here\n * }).catch(function(error) {\n * //console.error(\"error: \", error);\n * });\n * @see {@link https://leancloud.cn/docs/js_guide.html#绑定第三方平台账户}\n */\n loginWithAuthData(authData, platform, options) {\n return AV.User._logInWith(platform, authData, options);\n },\n\n /**\n * @deprecated renamed to {@link AV.User.loginWithAuthData}\n */\n signUpOrlogInWithAuthData(...param) {\n console.warn(\n 'DEPRECATED: User.signUpOrlogInWithAuthData 已废弃,请使用 User#loginWithAuthData 代替'\n );\n return this.loginWithAuthData(...param);\n },\n\n /**\n * Signs up or logs in a user with a third party authData and unionId.\n * @since 3.7.0\n * @param {Object} authData The response json data returned from third party token, maybe like { openid: 'abc123', access_token: '123abc', expires_in: 1382686496 }\n * @param {string} platform Available platform for sign up.\n * @param {string} unionId\n * @param {Object} [unionLoginOptions]\n * @param {string} [unionLoginOptions.unionIdPlatform = 'weixin'] unionId platform\n * @param {boolean} [unionLoginOptions.asMainAccount = false] If true, the unionId will be associated with the user.\n * @param {boolean} [unionLoginOptions.failOnNotExist] If true, the login request will fail when no user matches this authData exists.\n * @return {Promise} A promise that is fulfilled with the user when completed.\n * @example AV.User.loginWithAuthDataAndUnionId({\n * openid: 'abc123',\n * access_token: '123abc',\n * expires_in: 1382686496\n * }, 'weixin', 'union123', {\n * unionIdPlatform: 'weixin',\n * asMainAccount: true,\n * }).then(function(user) {\n * //Access user here\n * }).catch(function(error) {\n * //console.error(\"error: \", error);\n * });\n */\n loginWithAuthDataAndUnionId(\n authData,\n platform,\n unionId,\n unionLoginOptions\n ) {\n return this.loginWithAuthData(\n mergeUnionDataIntoAuthData()(authData, unionId, unionLoginOptions),\n platform,\n unionLoginOptions\n );\n },\n\n /**\n * @deprecated renamed to {@link AV.User.loginWithAuthDataAndUnionId}\n * @since 3.5.0\n */\n signUpOrlogInWithAuthDataAndUnionId(...param) {\n console.warn(\n 'DEPRECATED: User.signUpOrlogInWithAuthDataAndUnionId 已废弃,请使用 User#loginWithAuthDataAndUnionId 代替'\n );\n return this.loginWithAuthDataAndUnionId(...param);\n },\n\n /**\n * Merge unionId into authInfo.\n * @since 4.6.0\n * @param {Object} authInfo\n * @param {String} unionId\n * @param {Object} [unionIdOption]\n * @param {Boolean} [unionIdOption.asMainAccount] If true, the unionId will be associated with the user.\n */\n mergeUnionId(authInfo, unionId, { asMainAccount = false } = {}) {\n authInfo = JSON.parse(JSON.stringify(authInfo));\n const { authData, platform } = authInfo;\n authData.platform = platform;\n authData.main_account = asMainAccount;\n authData.unionid = unionId;\n return authInfo;\n },\n\n /**\n * 使用当前使用微信小程序的微信用户身份注册或登录,成功后用户的 session 会在设备上持久化保存,之后可以使用 AV.User.current() 获取当前登录用户。\n * 仅在微信小程序中可用。\n *\n * @deprecated please use {@link AV.User.loginWithMiniApp}\n * @since 2.0.0\n * @param {Object} [options]\n * @param {boolean} [options.preferUnionId] 当用户满足 {@link https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/union-id.html 获取 UnionId 的条件} 时,是否使用 UnionId 登录。(since 3.13.0)\n * @param {string} [options.unionIdPlatform = 'weixin'] (only take effect when preferUnionId) unionId platform\n * @param {boolean} [options.asMainAccount = true] (only take effect when preferUnionId) If true, the unionId will be associated with the user.\n * @param {boolean} [options.failOnNotExist] If true, the login request will fail when no user matches this authData exists. (since v3.7.0)\n * @return {Promise.}\n */\n loginWithWeapp({\n preferUnionId = false,\n unionIdPlatform = 'weixin',\n asMainAccount = true,\n failOnNotExist = false,\n useMasterKey,\n sessionToken,\n user,\n } = {}) {\n const getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo({\n preferUnionId,\n asMainAccount,\n platform: unionIdPlatform,\n }).then(authInfo =>\n this.loginWithMiniApp(authInfo, {\n failOnNotExist,\n useMasterKey,\n sessionToken,\n user,\n })\n );\n },\n\n /**\n * 使用当前使用微信小程序的微信用户身份注册或登录,\n * 仅在微信小程序中可用。\n *\n * @deprecated please use {@link AV.User.loginWithMiniApp}\n * @since 3.13.0\n * @param {Object} [unionLoginOptions]\n * @param {string} [unionLoginOptions.unionIdPlatform = 'weixin'] unionId platform\n * @param {boolean} [unionLoginOptions.asMainAccount = false] If true, the unionId will be associated with the user.\n * @param {boolean} [unionLoginOptions.failOnNotExist] If true, the login request will fail when no user matches this authData exists. * @return {Promise.}\n */\n loginWithWeappWithUnionId(\n unionId,\n {\n unionIdPlatform = 'weixin',\n asMainAccount = false,\n failOnNotExist = false,\n useMasterKey,\n sessionToken,\n user,\n } = {}\n ) {\n const getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo({ platform: unionIdPlatform }).then(authInfo => {\n authInfo = AV.User.mergeUnionId(authInfo, unionId, { asMainAccount });\n return this.loginWithMiniApp(authInfo, {\n failOnNotExist,\n useMasterKey,\n sessionToken,\n user,\n });\n });\n },\n\n /**\n * 使用当前使用 QQ 小程序的 QQ 用户身份注册或登录,成功后用户的 session 会在设备上持久化保存,之后可以使用 AV.User.current() 获取当前登录用户。\n * 仅在 QQ 小程序中可用。\n *\n * @deprecated please use {@link AV.User.loginWithMiniApp}\n * @since 4.2.0\n * @param {Object} [options]\n * @param {boolean} [options.preferUnionId] 如果服务端在登录时获取到了用户的 UnionId,是否将 UnionId 保存在用户账号中。\n * @param {string} [options.unionIdPlatform = 'qq'] (only take effect when preferUnionId) unionId platform\n * @param {boolean} [options.asMainAccount = true] (only take effect when preferUnionId) If true, the unionId will be associated with the user.\n * @param {boolean} [options.failOnNotExist] If true, the login request will fail when no user matches this authData exists. (since v3.7.0)\n * @return {Promise.}\n */\n loginWithQQApp({\n preferUnionId = false,\n unionIdPlatform = 'qq',\n asMainAccount = true,\n failOnNotExist = false,\n useMasterKey,\n sessionToken,\n user,\n } = {}) {\n const getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo({\n preferUnionId,\n asMainAccount,\n platform: unionIdPlatform,\n }).then(authInfo => {\n authInfo.provider = PLATFORM_QQAPP;\n return this.loginWithMiniApp(authInfo, {\n failOnNotExist,\n useMasterKey,\n sessionToken,\n user,\n });\n });\n },\n\n /**\n * 使用当前使用 QQ 小程序的 QQ 用户身份注册或登录,\n * 仅在 QQ 小程序中可用。\n *\n * @deprecated please use {@link AV.User.loginWithMiniApp}\n * @since 4.2.0\n * @param {Object} [unionLoginOptions]\n * @param {string} [unionLoginOptions.unionIdPlatform = 'qq'] unionId platform\n * @param {boolean} [unionLoginOptions.asMainAccount = false] If true, the unionId will be associated with the user.\n * @param {boolean} [unionLoginOptions.failOnNotExist] If true, the login request will fail when no user matches this authData exists.\n * @return {Promise.}\n */\n loginWithQQAppWithUnionId(\n unionId,\n {\n unionIdPlatform = 'qq',\n asMainAccount = false,\n failOnNotExist = false,\n useMasterKey,\n sessionToken,\n user,\n } = {}\n ) {\n const getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo({ platform: unionIdPlatform }).then(authInfo => {\n authInfo = AV.User.mergeUnionId(authInfo, unionId, { asMainAccount });\n authInfo.provider = PLATFORM_QQAPP;\n return this.loginWithMiniApp(authInfo, {\n failOnNotExist,\n useMasterKey,\n sessionToken,\n user,\n });\n });\n },\n\n /**\n * Register or login using the identity of the current mini-app.\n * @param {Object} authInfo\n * @param {Object} [option]\n * @param {Boolean} [option.failOnNotExist] If true, the login request will fail when no user matches this authInfo.authData exists.\n */\n loginWithMiniApp(authInfo, option) {\n if (authInfo === undefined) {\n const getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo().then(authInfo =>\n this.loginWithAuthData(authInfo.authData, authInfo.provider, option)\n );\n }\n return this.loginWithAuthData(\n authInfo.authData,\n authInfo.provider,\n option\n );\n },\n\n /**\n * Only use for DI in tests to produce deterministic IDs.\n */\n _genId() {\n return uuid();\n },\n\n /**\n * Creates an anonymous user.\n *\n * @since 3.9.0\n * @return {Promise.}\n */\n loginAnonymously() {\n return this.loginWithAuthData(\n {\n id: AV.User._genId(),\n },\n 'anonymous'\n );\n },\n\n associateWithAuthData(userObj, platform, authData) {\n console.warn(\n 'DEPRECATED: User.associateWithAuthData 已废弃,请使用 User#associateWithAuthData 代替'\n );\n return userObj._linkWith(platform, authData);\n },\n /**\n * Logs out the currently logged in user session. This will remove the\n * session from disk, log out of linked services, and future calls to\n * current will return null.\n * @return {Promise}\n */\n logOut: function() {\n if (AV._config.disableCurrentUser) {\n console.warn(\n 'AV.User.current() was disabled in multi-user environment, call logOut() from user object instead https://leancloud.cn/docs/leanengine-node-sdk-upgrade-1.html'\n );\n return Promise.resolve(null);\n }\n\n if (AV.User._currentUser !== null) {\n AV.User._currentUser._logOutWithAll();\n AV.User._currentUser._isCurrentUser = false;\n }\n AV.User._currentUserMatchesDisk = true;\n AV.User._currentUser = null;\n return AV.localStorage\n .removeItemAsync(AV._getAVPath(AV.User._CURRENT_USER_KEY))\n .then(() => AV._refreshSubscriptionId());\n },\n\n /**\n *Create a follower query for special user to query the user's followers.\n * @param {String} userObjectId The user object id.\n * @return {AV.FriendShipQuery}\n * @since 0.3.0\n */\n followerQuery: function(userObjectId) {\n if (!userObjectId || !_.isString(userObjectId)) {\n throw new Error('Invalid user object id.');\n }\n var query = new AV.FriendShipQuery('_Follower');\n query._friendshipTag = 'follower';\n query.equalTo(\n 'user',\n AV.Object.createWithoutData('_User', userObjectId)\n );\n return query;\n },\n\n /**\n *Create a followee query for special user to query the user's followees.\n * @param {String} userObjectId The user object id.\n * @return {AV.FriendShipQuery}\n * @since 0.3.0\n */\n followeeQuery: function(userObjectId) {\n if (!userObjectId || !_.isString(userObjectId)) {\n throw new Error('Invalid user object id.');\n }\n var query = new AV.FriendShipQuery('_Followee');\n query._friendshipTag = 'followee';\n query.equalTo(\n 'user',\n AV.Object.createWithoutData('_User', userObjectId)\n );\n return query;\n },\n\n /**\n * Requests a password reset email to be sent to the specified email address\n * associated with the user account. This email allows the user to securely\n * reset their password on the AV site.\n *\n * @param {String} email The email address associated with the user that\n * forgot their password.\n * @return {Promise}\n */\n requestPasswordReset: function(email) {\n var json = { email: email };\n var request = AVRequest(\n 'requestPasswordReset',\n null,\n null,\n 'POST',\n json\n );\n return request;\n },\n\n /**\n * Requests a verify email to be sent to the specified email address\n * associated with the user account. This email allows the user to securely\n * verify their email address on the AV site.\n *\n * @param {String} email The email address associated with the user that\n * doesn't verify their email address.\n * @return {Promise}\n */\n requestEmailVerify: function(email) {\n var json = { email: email };\n var request = AVRequest('requestEmailVerify', null, null, 'POST', json);\n return request;\n },\n\n /**\n * Requests a verify sms code to be sent to the specified mobile phone\n * number associated with the user account. This sms code allows the user to\n * verify their mobile phone number by calling AV.User.verifyMobilePhone\n *\n * @param {String} mobilePhoneNumber The mobile phone number associated with the\n * user that doesn't verify their mobile phone number.\n * @param {SMSAuthOptions} [options]\n * @return {Promise}\n */\n requestMobilePhoneVerify: function(mobilePhoneNumber, options = {}) {\n const data = {\n mobilePhoneNumber,\n };\n if (options.validateToken) {\n data.validate_token = options.validateToken;\n }\n var request = AVRequest(\n 'requestMobilePhoneVerify',\n null,\n null,\n 'POST',\n data,\n options\n );\n return request;\n },\n\n /**\n * Requests a reset password sms code to be sent to the specified mobile phone\n * number associated with the user account. This sms code allows the user to\n * reset their account's password by calling AV.User.resetPasswordBySmsCode\n *\n * @param {String} mobilePhoneNumber The mobile phone number associated with the\n * user that doesn't verify their mobile phone number.\n * @param {SMSAuthOptions} [options]\n * @return {Promise}\n */\n requestPasswordResetBySmsCode: function(mobilePhoneNumber, options = {}) {\n const data = {\n mobilePhoneNumber,\n };\n if (options.validateToken) {\n data.validate_token = options.validateToken;\n }\n var request = AVRequest(\n 'requestPasswordResetBySmsCode',\n null,\n null,\n 'POST',\n data,\n options\n );\n return request;\n },\n\n /**\n * Requests a change mobile phone number sms code to be sent to the mobilePhoneNumber.\n * This sms code allows current user to reset it's mobilePhoneNumber by\n * calling {@link AV.User.changePhoneNumber}\n * @since 4.7.0\n * @param {String} mobilePhoneNumber\n * @param {Number} [ttl] ttl of sms code (default is 6 minutes)\n * @param {SMSAuthOptions} [options]\n * @return {Promise}\n */\n requestChangePhoneNumber(mobilePhoneNumber, ttl, options) {\n const data = { mobilePhoneNumber };\n if (ttl) {\n data.ttl = options.ttl;\n }\n if (options && options.validateToken) {\n data.validate_token = options.validateToken;\n }\n return AVRequest(\n 'requestChangePhoneNumber',\n null,\n null,\n 'POST',\n data,\n options\n );\n },\n\n /**\n * Makes a call to reset user's account mobilePhoneNumber by sms code.\n * The sms code is sent by {@link AV.User.requestChangePhoneNumber}\n * @since 4.7.0\n * @param {String} mobilePhoneNumber\n * @param {String} code The sms code.\n * @return {Promise}\n */\n changePhoneNumber(mobilePhoneNumber, code) {\n const data = { mobilePhoneNumber, code };\n return AVRequest('changePhoneNumber', null, null, 'POST', data);\n },\n\n /**\n * Makes a call to reset user's account password by sms code and new password.\n * The sms code is sent by AV.User.requestPasswordResetBySmsCode.\n * @param {String} code The sms code sent by AV.User.Cloud.requestSmsCode\n * @param {String} password The new password.\n * @return {Promise} A promise that will be resolved with the result\n * of the function.\n */\n resetPasswordBySmsCode: function(code, password) {\n var json = { password: password };\n var request = AVRequest(\n 'resetPasswordBySmsCode',\n null,\n code,\n 'PUT',\n json\n );\n return request;\n },\n\n /**\n * Makes a call to verify sms code that sent by AV.User.Cloud.requestSmsCode\n * If verify successfully,the user mobilePhoneVerified attribute will be true.\n * @param {String} code The sms code sent by AV.User.Cloud.requestSmsCode\n * @return {Promise} A promise that will be resolved with the result\n * of the function.\n */\n verifyMobilePhone: function(code) {\n var request = AVRequest('verifyMobilePhone', null, code, 'POST', null);\n return request;\n },\n\n /**\n * Requests a logIn sms code to be sent to the specified mobile phone\n * number associated with the user account. This sms code allows the user to\n * login by AV.User.logInWithMobilePhoneSmsCode function.\n *\n * @param {String} mobilePhoneNumber The mobile phone number associated with the\n * user that want to login by AV.User.logInWithMobilePhoneSmsCode\n * @param {SMSAuthOptions} [options]\n * @return {Promise}\n */\n requestLoginSmsCode: function(mobilePhoneNumber, options = {}) {\n const data = {\n mobilePhoneNumber,\n };\n if (options.validateToken) {\n data.validate_token = options.validateToken;\n }\n var request = AVRequest(\n 'requestLoginSmsCode',\n null,\n null,\n 'POST',\n data,\n options\n );\n return request;\n },\n\n /**\n * Retrieves the currently logged in AVUser with a valid session,\n * either from memory or localStorage, if necessary.\n * @return {Promise.} resolved with the currently logged in AV.User.\n */\n currentAsync: function() {\n if (AV._config.disableCurrentUser) {\n console.warn(\n 'AV.User.currentAsync() was disabled in multi-user environment, access user from request instead https://leancloud.cn/docs/leanengine-node-sdk-upgrade-1.html'\n );\n return Promise.resolve(null);\n }\n\n if (AV.User._currentUser) {\n return Promise.resolve(AV.User._currentUser);\n }\n\n if (AV.User._currentUserMatchesDisk) {\n return Promise.resolve(AV.User._currentUser);\n }\n\n return AV.localStorage\n .getItemAsync(AV._getAVPath(AV.User._CURRENT_USER_KEY))\n .then(function(userData) {\n if (!userData) {\n return null;\n }\n\n // Load the user from local storage.\n AV.User._currentUserMatchesDisk = true;\n\n AV.User._currentUser = AV.Object._create('_User');\n AV.User._currentUser._isCurrentUser = true;\n\n var json = JSON.parse(userData);\n AV.User._currentUser.id = json._id;\n delete json._id;\n AV.User._currentUser._sessionToken = json._sessionToken;\n delete json._sessionToken;\n AV.User._currentUser._finishFetch(json);\n //AV.User._currentUser.set(json);\n\n AV.User._currentUser._synchronizeAllAuthData();\n AV.User._currentUser._refreshCache();\n AV.User._currentUser._opSetQueue = [{}];\n return AV.User._currentUser;\n });\n },\n\n /**\n * Retrieves the currently logged in AVUser with a valid session,\n * either from memory or localStorage, if necessary.\n * @return {AV.User} The currently logged in AV.User.\n */\n current: function() {\n if (AV._config.disableCurrentUser) {\n console.warn(\n 'AV.User.current() was disabled in multi-user environment, access user from request instead https://leancloud.cn/docs/leanengine-node-sdk-upgrade-1.html'\n );\n return null;\n }\n\n if (AV.localStorage.async) {\n const error = new Error(\n 'Synchronous API User.current() is not available in this runtime. Use User.currentAsync() instead.'\n );\n error.code = 'SYNC_API_NOT_AVAILABLE';\n throw error;\n }\n\n if (AV.User._currentUser) {\n return AV.User._currentUser;\n }\n\n if (AV.User._currentUserMatchesDisk) {\n return AV.User._currentUser;\n }\n\n // Load the user from local storage.\n AV.User._currentUserMatchesDisk = true;\n\n var userData = AV.localStorage.getItem(\n AV._getAVPath(AV.User._CURRENT_USER_KEY)\n );\n if (!userData) {\n return null;\n }\n AV.User._currentUser = AV.Object._create('_User');\n AV.User._currentUser._isCurrentUser = true;\n\n var json = JSON.parse(userData);\n AV.User._currentUser.id = json._id;\n delete json._id;\n AV.User._currentUser._sessionToken = json._sessionToken;\n delete json._sessionToken;\n AV.User._currentUser._finishFetch(json);\n //AV.User._currentUser.set(json);\n\n AV.User._currentUser._synchronizeAllAuthData();\n AV.User._currentUser._refreshCache();\n AV.User._currentUser._opSetQueue = [{}];\n return AV.User._currentUser;\n },\n\n /**\n * Persists a user as currentUser to localStorage, and into the singleton.\n * @private\n */\n _saveCurrentUser: function(user) {\n var promise;\n if (AV.User._currentUser !== user) {\n promise = AV.User.logOut();\n } else {\n promise = Promise.resolve();\n }\n return promise.then(function() {\n user._isCurrentUser = true;\n AV.User._currentUser = user;\n\n var json = user._toFullJSON();\n json._id = user.id;\n json._sessionToken = user._sessionToken;\n return AV.localStorage\n .setItemAsync(\n AV._getAVPath(AV.User._CURRENT_USER_KEY),\n JSON.stringify(json)\n )\n .then(function() {\n AV.User._currentUserMatchesDisk = true;\n return AV._refreshSubscriptionId();\n });\n });\n },\n\n _registerAuthenticationProvider: function(provider) {\n AV.User._authProviders[provider.getAuthType()] = provider;\n // Synchronize the current user with the auth provider.\n if (!AV._config.disableCurrentUser && AV.User.current()) {\n AV.User.current()._synchronizeAuthData(provider.getAuthType());\n }\n },\n\n _logInWith: function(provider, authData, options) {\n var user = AV.Object._create('_User');\n return user._linkWith(provider, authData, options);\n },\n }\n );\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/user.js","var _Object$defineProperty = require(\"@babel/runtime-corejs3/core-js/object/define-property\");\n\nfunction _defineProperty(obj, key, value) {\n if (key in obj) {\n _Object$defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n\n return obj;\n}\n\nmodule.exports = _defineProperty, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/helpers/defineProperty.js\n// module id = 528\n// module chunks = 0 1","const _ = require('underscore');\nconst debug = require('debug')('leancloud:query');\nconst AVError = require('./error');\nconst { _request, request } = require('./request');\nconst {\n ensureArray,\n transformFetchOptions,\n continueWhile,\n} = require('./utils');\n\nconst requires = (value, message) => {\n if (value === undefined) {\n throw new Error(message);\n }\n};\n\n// AV.Query is a way to create a list of AV.Objects.\nmodule.exports = function(AV) {\n /**\n * Creates a new AV.Query for the given AV.Object subclass.\n * @param {Class|String} objectClass An instance of a subclass of AV.Object, or a AV className string.\n * @class\n *\n *
AV.Query defines a query that is used to fetch AV.Objects. The\n * most common use case is finding all objects that match a query through the\n * find method. For example, this sample code fetches all objects\n * of class MyClass. It calls a different function depending on\n * whether the fetch succeeded or not.\n *\n *
\n * var query = new AV.Query(MyClass);\n * query.find().then(function(results) {\n * // results is an array of AV.Object.\n * }, function(error) {\n * // error is an instance of AVError.\n * });
\n *\n *
An AV.Query can also be used to retrieve a single object whose id is\n * known, through the get method. For example, this sample code fetches an\n * object of class MyClass and id myId. It calls a\n * different function depending on whether the fetch succeeded or not.\n *\n *
\n * var query = new AV.Query(MyClass);\n * query.get(myId).then(function(object) {\n * // object is an instance of AV.Object.\n * }, function(error) {\n * // error is an instance of AVError.\n * });
\n *\n *
An AV.Query can also be used to count the number of objects that match\n * the query without retrieving all of those objects. For example, this\n * sample code counts the number of objects of the class MyClass\n *
\n * var query = new AV.Query(MyClass);\n * query.count().then(function(number) {\n * // There are number instances of MyClass.\n * }, function(error) {\n * // error is an instance of AVError.\n * });
\n */\n AV.Query = function(objectClass) {\n if (_.isString(objectClass)) {\n objectClass = AV.Object._getSubclass(objectClass);\n }\n\n this.objectClass = objectClass;\n\n this.className = objectClass.prototype.className;\n\n this._where = {};\n this._include = [];\n this._select = [];\n this._limit = -1; // negative limit means, do not send a limit\n this._skip = 0;\n this._defaultParams = {};\n };\n\n /**\n * Constructs a AV.Query that is the OR of the passed in queries. For\n * example:\n *
var compoundQuery = AV.Query.or(query1, query2, query3);
\n *\n * will create a compoundQuery that is an or of the query1, query2, and\n * query3.\n * @param {...AV.Query} var_args The list of queries to OR.\n * @return {AV.Query} The query that is the OR of the passed in queries.\n */\n AV.Query.or = function() {\n var queries = _.toArray(arguments);\n var className = null;\n AV._arrayEach(queries, function(q) {\n if (_.isNull(className)) {\n className = q.className;\n }\n\n if (className !== q.className) {\n throw new Error('All queries must be for the same class');\n }\n });\n var query = new AV.Query(className);\n query._orQuery(queries);\n return query;\n };\n\n /**\n * Constructs a AV.Query that is the AND of the passed in queries. For\n * example:\n *
var compoundQuery = AV.Query.and(query1, query2, query3);
\n *\n * will create a compoundQuery that is an 'and' of the query1, query2, and\n * query3.\n * @param {...AV.Query} var_args The list of queries to AND.\n * @return {AV.Query} The query that is the AND of the passed in queries.\n */\n AV.Query.and = function() {\n var queries = _.toArray(arguments);\n var className = null;\n AV._arrayEach(queries, function(q) {\n if (_.isNull(className)) {\n className = q.className;\n }\n\n if (className !== q.className) {\n throw new Error('All queries must be for the same class');\n }\n });\n var query = new AV.Query(className);\n query._andQuery(queries);\n return query;\n };\n\n /**\n * Retrieves a list of AVObjects that satisfy the CQL.\n * CQL syntax please see {@link https://leancloud.cn/docs/cql_guide.html CQL Guide}.\n *\n * @param {String} cql A CQL string, see {@link https://leancloud.cn/docs/cql_guide.html CQL Guide}.\n * @param {Array} pvalues An array contains placeholder values.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is resolved with the results when\n * the query completes.\n */\n AV.Query.doCloudQuery = function(cql, pvalues, options) {\n var params = { cql: cql };\n if (_.isArray(pvalues)) {\n params.pvalues = pvalues;\n } else {\n options = pvalues;\n }\n\n var request = _request('cloudQuery', null, null, 'GET', params, options);\n return request.then(function(response) {\n //query to process results.\n var query = new AV.Query(response.className);\n var results = _.map(response.results, function(json) {\n var obj = query._newObject(response);\n if (obj._finishFetch) {\n obj._finishFetch(query._processResult(json), true);\n }\n return obj;\n });\n return {\n results: results,\n count: response.count,\n className: response.className,\n };\n });\n };\n\n /**\n * Return a query with conditions from json.\n * This can be useful to send a query from server side to client side.\n * @since 4.0.0\n * @param {Object} json from {@link AV.Query#toJSON}\n * @return {AV.Query}\n */\n AV.Query.fromJSON = ({\n className,\n where,\n include,\n select,\n includeACL,\n limit,\n skip,\n order,\n }) => {\n if (typeof className !== 'string') {\n throw new TypeError('Invalid Query JSON, className must be a String.');\n }\n const query = new AV.Query(className);\n _.extend(query, {\n _where: where,\n _include: include,\n _select: select,\n _includeACL: includeACL,\n _limit: limit,\n _skip: skip,\n _order: order,\n });\n return query;\n };\n\n AV.Query._extend = AV._extend;\n\n _.extend(\n AV.Query.prototype,\n /** @lends AV.Query.prototype */ {\n //hook to iterate result. Added by dennis.\n _processResult: function(obj) {\n return obj;\n },\n\n /**\n * Constructs an AV.Object whose id is already known by fetching data from\n * the server.\n *\n * @param {String} objectId The id of the object to be fetched.\n * @param {AuthOptions} options\n * @return {Promise.}\n */\n get: function(objectId, options) {\n if (!_.isString(objectId)) {\n throw new Error('objectId must be a string');\n }\n if (objectId === '') {\n return Promise.reject(\n new AVError(AVError.OBJECT_NOT_FOUND, 'Object not found.')\n );\n }\n\n var obj = this._newObject();\n obj.id = objectId;\n\n var queryJSON = this._getParams();\n var fetchOptions = {};\n\n if (queryJSON.keys) fetchOptions.keys = queryJSON.keys;\n if (queryJSON.include) fetchOptions.include = queryJSON.include;\n if (queryJSON.includeACL)\n fetchOptions.includeACL = queryJSON.includeACL;\n\n return _request(\n 'classes',\n this.className,\n objectId,\n 'GET',\n transformFetchOptions(fetchOptions),\n options\n ).then(response => {\n if (_.isEmpty(response))\n throw new AVError(AVError.OBJECT_NOT_FOUND, 'Object not found.');\n obj._finishFetch(obj.parse(response), true);\n return obj;\n });\n },\n\n /**\n * Returns a JSON representation of this query.\n * @return {Object}\n */\n toJSON() {\n const {\n className,\n _where: where,\n _include: include,\n _select: select,\n _includeACL: includeACL,\n _limit: limit,\n _skip: skip,\n _order: order,\n } = this;\n return {\n className,\n where,\n include,\n select,\n includeACL,\n limit,\n skip,\n order,\n };\n },\n\n _getParams: function() {\n var params = _.extend({}, this._defaultParams, {\n where: this._where,\n });\n\n if (this._include.length > 0) {\n params.include = this._include.join(',');\n }\n if (this._select.length > 0) {\n params.keys = this._select.join(',');\n }\n if (this._includeACL !== undefined) {\n params.returnACL = this._includeACL;\n }\n if (this._limit >= 0) {\n params.limit = this._limit;\n }\n if (this._skip > 0) {\n params.skip = this._skip;\n }\n if (this._order !== undefined) {\n params.order = this._order;\n }\n\n return params;\n },\n\n _newObject: function(response) {\n var obj;\n if (response && response.className) {\n obj = new AV.Object(response.className);\n } else {\n obj = new this.objectClass();\n }\n return obj;\n },\n _createRequest(\n params = this._getParams(),\n options,\n path = `/classes/${this.className}`\n ) {\n if (encodeURIComponent(JSON.stringify(params)).length > 2000) {\n const body = {\n requests: [\n {\n method: 'GET',\n path: `/1.1${path}`,\n params,\n },\n ],\n };\n return request({\n path: '/batch',\n method: 'POST',\n data: body,\n authOptions: options,\n }).then(response => {\n const result = response[0];\n if (result.success) {\n return result.success;\n }\n const error = new AVError(\n result.error.code,\n result.error.error || 'Unknown batch error'\n );\n throw error;\n });\n }\n return request({\n method: 'GET',\n path,\n query: params,\n authOptions: options,\n });\n },\n\n _parseResponse(response) {\n return _.map(response.results, json => {\n var obj = this._newObject(response);\n if (obj._finishFetch) {\n obj._finishFetch(this._processResult(json), true);\n }\n return obj;\n });\n },\n\n /**\n * Retrieves a list of AVObjects that satisfy this query.\n *\n * @param {AuthOptions} options\n * @return {Promise} A promise that is resolved with the results when\n * the query completes.\n */\n find(options) {\n const request = this._createRequest(undefined, options);\n return request.then(this._parseResponse.bind(this));\n },\n\n /**\n * Retrieves both AVObjects and total count.\n *\n * @since 4.12.0\n * @param {AuthOptions} options\n * @return {Promise} A tuple contains results and count.\n */\n findAndCount(options) {\n const params = this._getParams();\n params.count = 1;\n const request = this._createRequest(params, options);\n\n return request.then(response => [\n this._parseResponse(response),\n response.count,\n ]);\n },\n\n /**\n * scan a Query. masterKey required.\n *\n * @since 2.1.0\n * @param {object} [options]\n * @param {string} [options.orderedBy] specify the key to sort\n * @param {number} [options.batchSize] specify the batch size for each request\n * @param {AuthOptions} [authOptions]\n * @return {AsyncIterator.}\n * @example const testIterator = {\n * [Symbol.asyncIterator]() {\n * return new Query('Test').scan(undefined, { useMasterKey: true });\n * },\n * };\n * for await (const test of testIterator) {\n * console.log(test.id);\n * }\n */\n scan({ orderedBy, batchSize } = {}, authOptions) {\n const condition = this._getParams();\n debug('scan %O', condition);\n if (condition.order) {\n console.warn(\n 'The order of the query is ignored for Query#scan. Checkout the orderedBy option of Query#scan.'\n );\n delete condition.order;\n }\n if (condition.skip) {\n console.warn(\n 'The skip option of the query is ignored for Query#scan.'\n );\n delete condition.skip;\n }\n if (condition.limit) {\n console.warn(\n 'The limit option of the query is ignored for Query#scan.'\n );\n delete condition.limit;\n }\n if (orderedBy) condition.scan_key = orderedBy;\n if (batchSize) condition.limit = batchSize;\n let cursor;\n let remainResults = [];\n return {\n next: () => {\n if (remainResults.length) {\n return Promise.resolve({\n done: false,\n value: remainResults.shift(),\n });\n }\n if (cursor === null) {\n return Promise.resolve({ done: true });\n }\n return _request(\n 'scan/classes',\n this.className,\n null,\n 'GET',\n cursor ? _.extend({}, condition, { cursor }) : condition,\n authOptions\n ).then(response => {\n cursor = response.cursor;\n if (response.results.length) {\n const results = this._parseResponse(response);\n results.forEach(result => remainResults.push(result));\n }\n if (cursor === null && remainResults.length === 0) {\n return { done: true };\n }\n return {\n done: false,\n value: remainResults.shift(),\n };\n });\n },\n };\n },\n\n /**\n * Delete objects retrieved by this query.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled when the save\n * completes.\n */\n destroyAll: function(options) {\n var self = this;\n return self.find(options).then(function(objects) {\n return AV.Object.destroyAll(objects, options);\n });\n },\n\n /**\n * Counts the number of objects that match this query.\n *\n * @param {AuthOptions} options\n * @return {Promise} A promise that is resolved with the count when\n * the query completes.\n */\n count: function(options) {\n var params = this._getParams();\n params.limit = 0;\n params.count = 1;\n var request = this._createRequest(params, options);\n\n return request.then(function(response) {\n return response.count;\n });\n },\n\n /**\n * Retrieves at most one AV.Object that satisfies this query.\n *\n * @param {AuthOptions} options\n * @return {Promise} A promise that is resolved with the object when\n * the query completes.\n */\n first: function(options) {\n var self = this;\n\n var params = this._getParams();\n params.limit = 1;\n var request = this._createRequest(params, options);\n\n return request.then(function(response) {\n return _.map(response.results, function(json) {\n var obj = self._newObject();\n if (obj._finishFetch) {\n obj._finishFetch(self._processResult(json), true);\n }\n return obj;\n })[0];\n });\n },\n\n /**\n * Sets the number of results to skip before returning any results.\n * This is useful for pagination.\n * Default is to skip zero results.\n * @param {Number} n the number of results to skip.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n skip: function(n) {\n requires(n, 'undefined is not a valid skip value');\n this._skip = n;\n return this;\n },\n\n /**\n * Sets the limit of the number of results to return. The default limit is\n * 100, with a maximum of 1000 results being returned at a time.\n * @param {Number} n the number of results to limit to.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n limit: function(n) {\n requires(n, 'undefined is not a valid limit value');\n this._limit = n;\n return this;\n },\n\n /**\n * Add a constraint to the query that requires a particular key's value to\n * be equal to the provided value.\n * @param {String} key The key to check.\n * @param value The value that the AV.Object must contain.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n equalTo: function(key, value) {\n requires(key, 'undefined is not a valid key');\n requires(value, 'undefined is not a valid value');\n this._where[key] = AV._encode(value);\n return this;\n },\n\n /**\n * Helper for condition queries\n * @private\n */\n _addCondition: function(key, condition, value) {\n requires(key, 'undefined is not a valid condition key');\n requires(condition, 'undefined is not a valid condition');\n requires(value, 'undefined is not a valid condition value');\n\n // Check if we already have a condition\n if (!this._where[key]) {\n this._where[key] = {};\n }\n this._where[key][condition] = AV._encode(value);\n return this;\n },\n\n /**\n * Add a constraint to the query that requires a particular\n * array key's length to be equal to the provided value.\n * @param {String} key The array key to check.\n * @param {number} value The length value.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n sizeEqualTo: function(key, value) {\n this._addCondition(key, '$size', value);\n return this;\n },\n\n /**\n * Add a constraint to the query that requires a particular key's value to\n * be not equal to the provided value.\n * @param {String} key The key to check.\n * @param value The value that must not be equalled.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n notEqualTo: function(key, value) {\n this._addCondition(key, '$ne', value);\n return this;\n },\n\n /**\n * Add a constraint to the query that requires a particular key's value to\n * be less than the provided value.\n * @param {String} key The key to check.\n * @param value The value that provides an upper bound.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n lessThan: function(key, value) {\n this._addCondition(key, '$lt', value);\n return this;\n },\n\n /**\n * Add a constraint to the query that requires a particular key's value to\n * be greater than the provided value.\n * @param {String} key The key to check.\n * @param value The value that provides an lower bound.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n greaterThan: function(key, value) {\n this._addCondition(key, '$gt', value);\n return this;\n },\n\n /**\n * Add a constraint to the query that requires a particular key's value to\n * be less than or equal to the provided value.\n * @param {String} key The key to check.\n * @param value The value that provides an upper bound.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n lessThanOrEqualTo: function(key, value) {\n this._addCondition(key, '$lte', value);\n return this;\n },\n\n /**\n * Add a constraint to the query that requires a particular key's value to\n * be greater than or equal to the provided value.\n * @param {String} key The key to check.\n * @param value The value that provides an lower bound.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n greaterThanOrEqualTo: function(key, value) {\n this._addCondition(key, '$gte', value);\n return this;\n },\n\n /**\n * Add a constraint to the query that requires a particular key's value to\n * be contained in the provided list of values.\n * @param {String} key The key to check.\n * @param {Array} values The values that will match.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n containedIn: function(key, values) {\n this._addCondition(key, '$in', values);\n return this;\n },\n\n /**\n * Add a constraint to the query that requires a particular key's value to\n * not be contained in the provided list of values.\n * @param {String} key The key to check.\n * @param {Array} values The values that will not match.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n notContainedIn: function(key, values) {\n this._addCondition(key, '$nin', values);\n return this;\n },\n\n /**\n * Add a constraint to the query that requires a particular key's value to\n * contain each one of the provided list of values.\n * @param {String} key The key to check. This key's value must be an array.\n * @param {Array} values The values that will match.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n containsAll: function(key, values) {\n this._addCondition(key, '$all', values);\n return this;\n },\n\n /**\n * Add a constraint for finding objects that contain the given key.\n * @param {String} key The key that should exist.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n exists: function(key) {\n this._addCondition(key, '$exists', true);\n return this;\n },\n\n /**\n * Add a constraint for finding objects that do not contain a given key.\n * @param {String} key The key that should not exist\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n doesNotExist: function(key) {\n this._addCondition(key, '$exists', false);\n return this;\n },\n\n /**\n * Add a regular expression constraint for finding string values that match\n * the provided regular expression.\n * This may be slow for large datasets.\n * @param {String} key The key that the string to match is stored in.\n * @param {RegExp} regex The regular expression pattern to match.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n matches: function(key, regex, modifiers) {\n this._addCondition(key, '$regex', regex);\n if (!modifiers) {\n modifiers = '';\n }\n // Javascript regex options support mig as inline options but store them\n // as properties of the object. We support mi & should migrate them to\n // modifiers\n if (regex.ignoreCase) {\n modifiers += 'i';\n }\n if (regex.multiline) {\n modifiers += 'm';\n }\n\n if (modifiers && modifiers.length) {\n this._addCondition(key, '$options', modifiers);\n }\n return this;\n },\n\n /**\n * Add a constraint that requires that a key's value matches a AV.Query\n * constraint.\n * @param {String} key The key that the contains the object to match the\n * query.\n * @param {AV.Query} query The query that should match.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n matchesQuery: function(key, query) {\n var queryJSON = query._getParams();\n queryJSON.className = query.className;\n this._addCondition(key, '$inQuery', queryJSON);\n return this;\n },\n\n /**\n * Add a constraint that requires that a key's value not matches a\n * AV.Query constraint.\n * @param {String} key The key that the contains the object to match the\n * query.\n * @param {AV.Query} query The query that should not match.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n doesNotMatchQuery: function(key, query) {\n var queryJSON = query._getParams();\n queryJSON.className = query.className;\n this._addCondition(key, '$notInQuery', queryJSON);\n return this;\n },\n\n /**\n * Add a constraint that requires that a key's value matches a value in\n * an object returned by a different AV.Query.\n * @param {String} key The key that contains the value that is being\n * matched.\n * @param {String} queryKey The key in the objects returned by the query to\n * match against.\n * @param {AV.Query} query The query to run.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n matchesKeyInQuery: function(key, queryKey, query) {\n var queryJSON = query._getParams();\n queryJSON.className = query.className;\n this._addCondition(key, '$select', { key: queryKey, query: queryJSON });\n return this;\n },\n\n /**\n * Add a constraint that requires that a key's value not match a value in\n * an object returned by a different AV.Query.\n * @param {String} key The key that contains the value that is being\n * excluded.\n * @param {String} queryKey The key in the objects returned by the query to\n * match against.\n * @param {AV.Query} query The query to run.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n doesNotMatchKeyInQuery: function(key, queryKey, query) {\n var queryJSON = query._getParams();\n queryJSON.className = query.className;\n this._addCondition(key, '$dontSelect', {\n key: queryKey,\n query: queryJSON,\n });\n return this;\n },\n\n /**\n * Add constraint that at least one of the passed in queries matches.\n * @param {Array} queries\n * @return {AV.Query} Returns the query, so you can chain this call.\n * @private\n */\n _orQuery: function(queries) {\n var queryJSON = _.map(queries, function(q) {\n return q._getParams().where;\n });\n\n this._where.$or = queryJSON;\n return this;\n },\n\n /**\n * Add constraint that both of the passed in queries matches.\n * @param {Array} queries\n * @return {AV.Query} Returns the query, so you can chain this call.\n * @private\n */\n _andQuery: function(queries) {\n var queryJSON = _.map(queries, function(q) {\n return q._getParams().where;\n });\n\n this._where.$and = queryJSON;\n return this;\n },\n\n /**\n * Converts a string into a regex that matches it.\n * Surrounding with \\Q .. \\E does this, we just need to escape \\E's in\n * the text separately.\n * @private\n */\n _quote: function(s) {\n return '\\\\Q' + s.replace('\\\\E', '\\\\E\\\\\\\\E\\\\Q') + '\\\\E';\n },\n\n /**\n * Add a constraint for finding string values that contain a provided\n * string. This may be slow for large datasets.\n * @param {String} key The key that the string to match is stored in.\n * @param {String} substring The substring that the value must contain.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n contains: function(key, value) {\n this._addCondition(key, '$regex', this._quote(value));\n return this;\n },\n\n /**\n * Add a constraint for finding string values that start with a provided\n * string. This query will use the backend index, so it will be fast even\n * for large datasets.\n * @param {String} key The key that the string to match is stored in.\n * @param {String} prefix The substring that the value must start with.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n startsWith: function(key, value) {\n this._addCondition(key, '$regex', '^' + this._quote(value));\n return this;\n },\n\n /**\n * Add a constraint for finding string values that end with a provided\n * string. This will be slow for large datasets.\n * @param {String} key The key that the string to match is stored in.\n * @param {String} suffix The substring that the value must end with.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n endsWith: function(key, value) {\n this._addCondition(key, '$regex', this._quote(value) + '$');\n return this;\n },\n\n /**\n * Sorts the results in ascending order by the given key.\n *\n * @param {String} key The key to order by.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n ascending: function(key) {\n requires(key, 'undefined is not a valid key');\n this._order = key;\n return this;\n },\n\n /**\n * Also sorts the results in ascending order by the given key. The previous sort keys have\n * precedence over this key.\n *\n * @param {String} key The key to order by\n * @return {AV.Query} Returns the query so you can chain this call.\n */\n addAscending: function(key) {\n requires(key, 'undefined is not a valid key');\n if (this._order) this._order += ',' + key;\n else this._order = key;\n return this;\n },\n\n /**\n * Sorts the results in descending order by the given key.\n *\n * @param {String} key The key to order by.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n descending: function(key) {\n requires(key, 'undefined is not a valid key');\n this._order = '-' + key;\n return this;\n },\n\n /**\n * Also sorts the results in descending order by the given key. The previous sort keys have\n * precedence over this key.\n *\n * @param {String} key The key to order by\n * @return {AV.Query} Returns the query so you can chain this call.\n */\n addDescending: function(key) {\n requires(key, 'undefined is not a valid key');\n if (this._order) this._order += ',-' + key;\n else this._order = '-' + key;\n return this;\n },\n\n /**\n * Add a proximity based constraint for finding objects with key point\n * values near the point given.\n * @param {String} key The key that the AV.GeoPoint is stored in.\n * @param {AV.GeoPoint} point The reference AV.GeoPoint that is used.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n near: function(key, point) {\n if (!(point instanceof AV.GeoPoint)) {\n // Try to cast it to a GeoPoint, so that near(\"loc\", [20,30]) works.\n point = new AV.GeoPoint(point);\n }\n this._addCondition(key, '$nearSphere', point);\n return this;\n },\n\n /**\n * Add a proximity based constraint for finding objects with key point\n * values near the point given and within the maximum distance given.\n * @param {String} key The key that the AV.GeoPoint is stored in.\n * @param {AV.GeoPoint} point The reference AV.GeoPoint that is used.\n * @param maxDistance Maximum distance (in radians) of results to return.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n withinRadians: function(key, point, distance) {\n this.near(key, point);\n this._addCondition(key, '$maxDistance', distance);\n return this;\n },\n\n /**\n * Add a proximity based constraint for finding objects with key point\n * values near the point given and within the maximum distance given.\n * Radius of earth used is 3958.8 miles.\n * @param {String} key The key that the AV.GeoPoint is stored in.\n * @param {AV.GeoPoint} point The reference AV.GeoPoint that is used.\n * @param {Number} maxDistance Maximum distance (in miles) of results to\n * return.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n withinMiles: function(key, point, distance) {\n return this.withinRadians(key, point, distance / 3958.8);\n },\n\n /**\n * Add a proximity based constraint for finding objects with key point\n * values near the point given and within the maximum distance given.\n * Radius of earth used is 6371.0 kilometers.\n * @param {String} key The key that the AV.GeoPoint is stored in.\n * @param {AV.GeoPoint} point The reference AV.GeoPoint that is used.\n * @param {Number} maxDistance Maximum distance (in kilometers) of results\n * to return.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n withinKilometers: function(key, point, distance) {\n return this.withinRadians(key, point, distance / 6371.0);\n },\n\n /**\n * Add a constraint to the query that requires a particular key's\n * coordinates be contained within a given rectangular geographic bounding\n * box.\n * @param {String} key The key to be constrained.\n * @param {AV.GeoPoint} southwest\n * The lower-left inclusive corner of the box.\n * @param {AV.GeoPoint} northeast\n * The upper-right inclusive corner of the box.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n withinGeoBox: function(key, southwest, northeast) {\n if (!(southwest instanceof AV.GeoPoint)) {\n southwest = new AV.GeoPoint(southwest);\n }\n if (!(northeast instanceof AV.GeoPoint)) {\n northeast = new AV.GeoPoint(northeast);\n }\n this._addCondition(key, '$within', { $box: [southwest, northeast] });\n return this;\n },\n\n /**\n * Include nested AV.Objects for the provided key. You can use dot\n * notation to specify which fields in the included object are also fetch.\n * @param {String[]} keys The name of the key to include.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n include: function(keys) {\n requires(keys, 'undefined is not a valid key');\n _.forEach(arguments, keys => {\n this._include = this._include.concat(ensureArray(keys));\n });\n return this;\n },\n\n /**\n * Include the ACL.\n * @param {Boolean} [value=true] Whether to include the ACL\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n includeACL: function(value = true) {\n this._includeACL = value;\n return this;\n },\n\n /**\n * Restrict the fields of the returned AV.Objects to include only the\n * provided keys. If this is called multiple times, then all of the keys\n * specified in each of the calls will be included.\n * @param {String[]} keys The names of the keys to include.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n select: function(keys) {\n requires(keys, 'undefined is not a valid key');\n _.forEach(arguments, keys => {\n this._select = this._select.concat(ensureArray(keys));\n });\n return this;\n },\n\n /**\n * Iterates over each result of a query, calling a callback for each one. If\n * the callback returns a promise, the iteration will not continue until\n * that promise has been fulfilled. If the callback returns a rejected\n * promise, then iteration will stop with that error. The items are\n * processed in an unspecified order. The query may not have any sort order,\n * and may not use limit or skip.\n * @param callback {Function} Callback that will be called with each result\n * of the query.\n * @return {Promise} A promise that will be fulfilled once the\n * iteration has completed.\n */\n each: function(callback, options = {}) {\n if (this._order || this._skip || this._limit >= 0) {\n var error = new Error(\n 'Cannot iterate on a query with sort, skip, or limit.'\n );\n return Promise.reject(error);\n }\n\n var query = new AV.Query(this.objectClass);\n // We can override the batch size from the options.\n // This is undocumented, but useful for testing.\n query._limit = options.batchSize || 100;\n query._where = _.clone(this._where);\n query._include = _.clone(this._include);\n\n query.ascending('objectId');\n\n var finished = false;\n return continueWhile(\n function() {\n return !finished;\n },\n function() {\n return query.find(options).then(function(results) {\n var callbacksDone = Promise.resolve();\n _.each(results, function(result) {\n callbacksDone = callbacksDone.then(function() {\n return callback(result);\n });\n });\n\n return callbacksDone.then(function() {\n if (results.length >= query._limit) {\n query.greaterThan('objectId', results[results.length - 1].id);\n } else {\n finished = true;\n }\n });\n });\n }\n );\n },\n\n /**\n * Subscribe the changes of this query.\n *\n * LiveQuery is not included in the default bundle: {@link https://url.leanapp.cn/enable-live-query}.\n *\n * @since 3.0.0\n * @return {AV.LiveQuery} An eventemitter which can be used to get LiveQuery updates;\n */\n subscribe(options) {\n return AV.LiveQuery.init(this, options);\n },\n }\n );\n\n AV.FriendShipQuery = AV.Query._extend({\n _newObject: function() {\n const UserClass = AV.Object._getSubclass('_User');\n return new UserClass();\n },\n _processResult: function(json) {\n if (json && json[this._friendshipTag]) {\n var user = json[this._friendshipTag];\n if (user.__type === 'Pointer' && user.className === '_User') {\n delete user.__type;\n delete user.className;\n }\n return user;\n } else {\n return null;\n }\n },\n });\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/query.js","const _ = require('underscore');\nconst EventEmitter = require('eventemitter3');\nconst { inherits } = require('./utils');\nconst { request } = require('./request');\n\nconst subscribe = (queryJSON, subscriptionId) =>\n request({\n method: 'POST',\n path: '/LiveQuery/subscribe',\n data: {\n query: queryJSON,\n id: subscriptionId,\n },\n });\n\nmodule.exports = AV => {\n const requireRealtime = () => {\n if (!AV._config.realtime) {\n throw new Error(\n 'LiveQuery not supported. Please use the LiveQuery bundle. https://url.leanapp.cn/enable-live-query'\n );\n }\n };\n /**\n * @class\n * A LiveQuery, created by {@link AV.Query#subscribe} is an EventEmitter notifies changes of the Query.\n * @since 3.0.0\n */\n AV.LiveQuery = inherits(\n EventEmitter,\n /** @lends AV.LiveQuery.prototype */ {\n constructor(id, client, queryJSON, subscriptionId) {\n EventEmitter.apply(this);\n this.id = id;\n this._client = client;\n this._client.register(this);\n this._queryJSON = queryJSON;\n this._subscriptionId = subscriptionId;\n this._onMessage = this._dispatch.bind(this);\n this._onReconnect = () => {\n subscribe(this._queryJSON, this._subscriptionId).catch(error =>\n console.error(`LiveQuery resubscribe error: ${error.message}`)\n );\n };\n client.on('message', this._onMessage);\n client.on('reconnect', this._onReconnect);\n },\n _dispatch(message) {\n message.forEach(({ op, object, query_id: queryId, updatedKeys }) => {\n if (queryId !== this.id) return;\n const target = AV.parseJSON(\n _.extend(\n {\n __type: object.className === '_File' ? 'File' : 'Object',\n },\n object\n )\n );\n if (updatedKeys) {\n /**\n * An existing AV.Object which fulfills the Query you subscribe is updated.\n * @event AV.LiveQuery#update\n * @param {AV.Object|AV.File} target updated object\n * @param {String[]} updatedKeys updated keys\n */\n /**\n * An existing AV.Object which doesn't fulfill the Query is updated and now it fulfills the Query.\n * @event AV.LiveQuery#enter\n * @param {AV.Object|AV.File} target updated object\n * @param {String[]} updatedKeys updated keys\n */\n /**\n * An existing AV.Object which fulfills the Query is updated and now it doesn't fulfill the Query.\n * @event AV.LiveQuery#leave\n * @param {AV.Object|AV.File} target updated object\n * @param {String[]} updatedKeys updated keys\n */\n this.emit(op, target, updatedKeys);\n } else {\n /**\n * A new AV.Object which fulfills the Query you subscribe is created.\n * @event AV.LiveQuery#create\n * @param {AV.Object|AV.File} target updated object\n */\n /**\n * An existing AV.Object which fulfills the Query you subscribe is deleted.\n * @event AV.LiveQuery#delete\n * @param {AV.Object|AV.File} target updated object\n */\n this.emit(op, target);\n }\n });\n },\n /**\n * unsubscribe the query\n *\n * @return {Promise}\n */\n unsubscribe() {\n const client = this._client;\n client.off('message', this._onMessage);\n client.off('reconnect', this._onReconnect);\n client.deregister(this);\n return request({\n method: 'POST',\n path: '/LiveQuery/unsubscribe',\n data: {\n id: client.id,\n query_id: this.id,\n },\n });\n },\n },\n /** @lends AV.LiveQuery */\n {\n init(\n query,\n {\n subscriptionId: userDefinedSubscriptionId = AV._getSubscriptionId(),\n } = {}\n ) {\n requireRealtime();\n if (!(query instanceof AV.Query))\n throw new TypeError('LiveQuery must be inited with a Query');\n return Promise.resolve(userDefinedSubscriptionId).then(subscriptionId =>\n AV._config.realtime\n .createLiveQueryClient(subscriptionId)\n .then(liveQueryClient => {\n const { where, keys, returnACL } = query._getParams();\n const queryJSON = {\n where,\n keys,\n returnACL,\n className: query.className,\n };\n const promise = subscribe(queryJSON, subscriptionId)\n .then(\n ({ query_id: queryId }) =>\n new AV.LiveQuery(\n queryId,\n liveQueryClient,\n queryJSON,\n subscriptionId\n )\n )\n .finally(() => {\n liveQueryClient.deregister(promise);\n });\n liveQueryClient.register(promise);\n return promise;\n })\n );\n },\n /**\n * Pause the LiveQuery connection. This is useful to deactivate the SDK when the app is swtiched to background.\n * @static\n * @return void\n */\n pause() {\n requireRealtime();\n return AV._config.realtime.pause();\n },\n /**\n * Resume the LiveQuery connection. All subscriptions will be restored after reconnection.\n * @static\n * @return void\n */\n resume() {\n requireRealtime();\n return AV._config.realtime.resume();\n },\n }\n );\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/live-query.js","const _ = require('underscore');\nconst { tap } = require('./utils');\n\nmodule.exports = AV => {\n /**\n * @class\n * @example\n * AV.Captcha.request().then(captcha => {\n * captcha.bind({\n * textInput: 'code', // the id for textInput\n * image: 'captcha',\n * verifyButton: 'verify',\n * }, {\n * success: (validateCode) => {}, // next step\n * error: (error) => {}, // present error.message to user\n * });\n * });\n */\n AV.Captcha = function Captcha(options, authOptions) {\n this._options = options;\n this._authOptions = authOptions;\n /**\n * The image url of the captcha\n * @type string\n */\n this.url = undefined;\n /**\n * The captchaToken of the captcha.\n * @type string\n */\n this.captchaToken = undefined;\n /**\n * The validateToken of the captcha.\n * @type string\n */\n this.validateToken = undefined;\n };\n\n /**\n * Refresh the captcha\n * @return {Promise.} a new capcha url\n */\n AV.Captcha.prototype.refresh = function refresh() {\n return AV.Cloud._requestCaptcha(this._options, this._authOptions).then(\n ({ captchaToken, url }) => {\n _.extend(this, { captchaToken, url });\n return url;\n }\n );\n };\n\n /**\n * Verify the captcha\n * @param {String} code The code from user input\n * @return {Promise.} validateToken if the code is valid\n */\n AV.Captcha.prototype.verify = function verify(code) {\n return AV.Cloud.verifyCaptcha(code, this.captchaToken).then(\n tap(validateToken => (this.validateToken = validateToken))\n );\n };\n\n if (process.env.PLATFORM === 'Browser') {\n /**\n * Bind the captcha to HTMLElements. ONLY AVAILABLE in browsers.\n * @param [elements]\n * @param {String|HTMLInputElement} [elements.textInput] An input element typed text, or the id for the element.\n * @param {String|HTMLImageElement} [elements.image] An image element, or the id for the element.\n * @param {String|HTMLElement} [elements.verifyButton] A button element, or the id for the element.\n * @param [callbacks]\n * @param {Function} [callbacks.success] Success callback will be called if the code is verified. The param `validateCode` can be used for further SMS request.\n * @param {Function} [callbacks.error] Error callback will be called if something goes wrong, detailed in param `error.message`.\n */\n AV.Captcha.prototype.bind = function bind(\n { textInput, image, verifyButton },\n { success, error }\n ) {\n if (typeof textInput === 'string') {\n textInput = document.getElementById(textInput);\n if (!textInput)\n throw new Error(`textInput with id ${textInput} not found`);\n }\n if (typeof image === 'string') {\n image = document.getElementById(image);\n if (!image) throw new Error(`image with id ${image} not found`);\n }\n if (typeof verifyButton === 'string') {\n verifyButton = document.getElementById(verifyButton);\n if (!verifyButton)\n throw new Error(`verifyButton with id ${verifyButton} not found`);\n }\n\n this.__refresh = () =>\n this.refresh()\n .then(url => {\n image.src = url;\n if (textInput) {\n textInput.value = '';\n textInput.focus();\n }\n })\n .catch(err => console.warn(`refresh captcha fail: ${err.message}`));\n if (image) {\n this.__image = image;\n image.src = this.url;\n image.addEventListener('click', this.__refresh);\n }\n\n this.__verify = () => {\n const code = textInput.value;\n this.verify(code)\n .catch(err => {\n this.__refresh();\n throw err;\n })\n .then(success, error)\n .catch(err => console.warn(`verify captcha fail: ${err.message}`));\n };\n if (textInput && verifyButton) {\n this.__verifyButton = verifyButton;\n verifyButton.addEventListener('click', this.__verify);\n }\n };\n\n /**\n * unbind the captcha from HTMLElements. ONLY AVAILABLE in browsers.\n */\n AV.Captcha.prototype.unbind = function unbind() {\n if (this.__image)\n this.__image.removeEventListener('click', this.__refresh);\n if (this.__verifyButton)\n this.__verifyButton.removeEventListener('click', this.__verify);\n };\n }\n\n /**\n * Request a captcha\n * @param [options]\n * @param {Number} [options.width] width(px) of the captcha, ranged 60-200\n * @param {Number} [options.height] height(px) of the captcha, ranged 30-100\n * @param {Number} [options.size=4] length of the captcha, ranged 3-6. MasterKey required.\n * @param {Number} [options.ttl=60] time to live(s), ranged 10-180. MasterKey required.\n * @return {Promise.}\n */\n AV.Captcha.request = (options, authOptions) => {\n const captcha = new AV.Captcha(options, authOptions);\n return captcha.refresh().then(() => captcha);\n };\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/captcha.js","const _ = require('underscore');\nconst { _request, request } = require('./request');\n\nmodule.exports = function(AV) {\n /**\n * Contains functions for calling and declaring\n *
\n * Some functions are only available from Cloud Code.\n *
\n *\n * @namespace\n * @borrows AV.Captcha.request as requestCaptcha\n */\n AV.Cloud = AV.Cloud || {};\n\n _.extend(\n AV.Cloud,\n /** @lends AV.Cloud */ {\n /**\n * Makes a call to a cloud function.\n * @param {String} name The function name.\n * @param {Object} [data] The parameters to send to the cloud function.\n * @param {AuthOptions} [options]\n * @return {Promise} A promise that will be resolved with the result\n * of the function.\n */\n run(name, data, options) {\n return request({\n service: 'engine',\n method: 'POST',\n path: `/functions/${name}`,\n data: AV._encode(data, null, true),\n authOptions: options,\n }).then(resp => {\n return AV._decode(resp).result;\n });\n },\n\n /**\n * Makes a call to a cloud function, you can send {AV.Object} as param or a field of param; the response\n * from server will also be parsed as an {AV.Object}, array of {AV.Object}, or object includes {AV.Object}\n * @param {String} name The function name.\n * @param {Object} [data] The parameters to send to the cloud function.\n * @param {AuthOptions} [options]\n * @return {Promise} A promise that will be resolved with the result of the function.\n */\n rpc(name, data, options) {\n if (_.isArray(data)) {\n return Promise.reject(\n new Error(\n \"Can't pass Array as the param of rpc function in JavaScript SDK.\"\n )\n );\n }\n\n return request({\n service: 'engine',\n method: 'POST',\n path: `/call/${name}`,\n data: AV._encodeObjectOrArray(data),\n authOptions: options,\n }).then(resp => {\n return AV._decode(resp).result;\n });\n },\n\n /**\n * Make a call to request server date time.\n * @return {Promise.} A promise that will be resolved with the result\n * of the function.\n * @since 0.5.9\n */\n getServerDate() {\n return _request('date', null, null, 'GET').then(function(resp) {\n return AV._decode(resp);\n });\n },\n\n /**\n * Makes a call to request an sms code for operation verification.\n * @param {String|Object} data The mobile phone number string or a JSON\n * object that contains mobilePhoneNumber,template,sign,op,ttl,name etc.\n * @param {String} data.mobilePhoneNumber\n * @param {String} [data.template] sms template name\n * @param {String} [data.sign] sms signature name\n * @param {String} [data.smsType] sending code by `sms` (default) or `voice` call\n * @param {SMSAuthOptions} [options]\n * @return {Promise} A promise that will be resolved if the request succeed\n */\n requestSmsCode(data, options = {}) {\n if (_.isString(data)) {\n data = { mobilePhoneNumber: data };\n }\n if (!data.mobilePhoneNumber) {\n throw new Error('Missing mobilePhoneNumber.');\n }\n if (options.validateToken) {\n data = _.extend({}, data, {\n validate_token: options.validateToken,\n });\n }\n return _request('requestSmsCode', null, null, 'POST', data, options);\n },\n\n /**\n * Makes a call to verify sms code that sent by AV.Cloud.requestSmsCode\n * @param {String} code The sms code sent by AV.Cloud.requestSmsCode\n * @param {phone} phone The mobile phoner number.\n * @return {Promise} A promise that will be resolved with the result\n * of the function.\n */\n verifySmsCode(code, phone) {\n if (!code) throw new Error('Missing sms code.');\n var params = {};\n if (_.isString(phone)) {\n params['mobilePhoneNumber'] = phone;\n }\n\n return _request('verifySmsCode', code, null, 'POST', params);\n },\n\n _requestCaptcha(options, authOptions) {\n return _request(\n 'requestCaptcha',\n null,\n null,\n 'GET',\n options,\n authOptions\n ).then(({ captcha_url: url, captcha_token: captchaToken }) => ({\n captchaToken,\n url,\n }));\n },\n\n /**\n * Request a captcha.\n */\n requestCaptcha: AV.Captcha.request,\n\n /**\n * Verify captcha code. This is the low-level API for captcha.\n * Checkout {@link AV.Captcha} for high abstract APIs.\n * @param {String} code the code from user input\n * @param {String} captchaToken captchaToken returned by {@link AV.Cloud.requestCaptcha}\n * @return {Promise.} validateToken if the code is valid\n */\n verifyCaptcha(code, captchaToken) {\n return _request('verifyCaptcha', null, null, 'POST', {\n captcha_code: code,\n captcha_token: captchaToken,\n }).then(({ validate_token: validateToken }) => validateToken);\n },\n }\n );\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/cloudfunction.js","const request = require('./request').request;\n\nmodule.exports = function(AV) {\n AV.Installation = AV.Object.extend('_Installation');\n\n /**\n * @namespace\n */\n AV.Push = AV.Push || {};\n\n /**\n * Sends a push notification.\n * @param {Object} data The data of the push notification.\n * @param {String[]} [data.channels] An Array of channels to push to.\n * @param {Date} [data.push_time] A Date object for when to send the push.\n * @param {Date} [data.expiration_time] A Date object for when to expire\n * the push.\n * @param {Number} [data.expiration_interval] The seconds from now to expire the push.\n * @param {Number} [data.flow_control] The clients to notify per second\n * @param {AV.Query} [data.where] An AV.Query over AV.Installation that is used to match\n * a set of installations to push to.\n * @param {String} [data.cql] A CQL statement over AV.Installation that is used to match\n * a set of installations to push to.\n * @param {Object} data.data The data to send as part of the push.\n More details: https://url.leanapp.cn/pushData\n * @param {AuthOptions} [options]\n * @return {Promise}\n */\n AV.Push.send = function(data, options) {\n if (data.where) {\n data.where = data.where._getParams().where;\n }\n\n if (data.where && data.cql) {\n throw new Error(\"Both where and cql can't be set\");\n }\n\n if (data.push_time) {\n data.push_time = data.push_time.toJSON();\n }\n\n if (data.expiration_time) {\n data.expiration_time = data.expiration_time.toJSON();\n }\n\n if (data.expiration_time && data.expiration_interval) {\n throw new Error(\n \"Both expiration_time and expiration_interval can't be set\"\n );\n }\n\n return request({\n service: 'push',\n method: 'POST',\n path: '/push',\n data,\n authOptions: options,\n });\n };\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/push.js","const _ = require('underscore');\nconst AVRequest = require('./request')._request;\nconst { getSessionToken } = require('./utils');\n\nmodule.exports = function(AV) {\n const getUser = (options = {}) => {\n const sessionToken = getSessionToken(options);\n if (sessionToken) {\n return AV.User._fetchUserBySessionToken(getSessionToken(options));\n }\n return AV.User.currentAsync();\n };\n\n const getUserPointer = options =>\n getUser(options).then(currUser =>\n AV.Object.createWithoutData('_User', currUser.id)._toPointer()\n );\n\n /**\n * Contains functions to deal with Status in LeanCloud.\n * @class\n */\n AV.Status = function(imageUrl, message) {\n this.data = {};\n this.inboxType = 'default';\n this.query = null;\n if (imageUrl && typeof imageUrl === 'object') {\n this.data = imageUrl;\n } else {\n if (imageUrl) {\n this.data.image = imageUrl;\n }\n if (message) {\n this.data.message = message;\n }\n }\n return this;\n };\n\n _.extend(\n AV.Status.prototype,\n /** @lends AV.Status.prototype */ {\n /**\n * Gets the value of an attribute in status data.\n * @param {String} attr The string name of an attribute.\n */\n get: function(attr) {\n return this.data[attr];\n },\n /**\n * Sets a hash of model attributes on the status data.\n * @param {String} key The key to set.\n * @param {any} value The value to give it.\n */\n set: function(key, value) {\n this.data[key] = value;\n return this;\n },\n /**\n * Destroy this status,then it will not be avaiable in other user's inboxes.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled when the destroy\n * completes.\n */\n destroy: function(options) {\n if (!this.id)\n return Promise.reject(new Error('The status id is not exists.'));\n var request = AVRequest('statuses', null, this.id, 'DELETE', options);\n return request;\n },\n /**\n * Cast the AV.Status object to an AV.Object pointer.\n * @return {AV.Object} A AV.Object pointer.\n */\n toObject: function() {\n if (!this.id) return null;\n return AV.Object.createWithoutData('_Status', this.id);\n },\n _getDataJSON: function() {\n var json = _.clone(this.data);\n return AV._encode(json);\n },\n /**\n * Send a status by a AV.Query object.\n * @since 0.3.0\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled when the send\n * completes.\n * @example\n * // send a status to male users\n * var status = new AVStatus('image url', 'a message');\n * status.query = new AV.Query('_User');\n * status.query.equalTo('gender', 'male');\n * status.send().then(function(){\n * //send status successfully.\n * }, function(err){\n * //an error threw.\n * console.dir(err);\n * });\n */\n send: function(options = {}) {\n if (!getSessionToken(options) && !AV.User.current()) {\n throw new Error('Please signin an user.');\n }\n if (!this.query) {\n return AV.Status.sendStatusToFollowers(this, options);\n }\n\n return getUserPointer(options)\n .then(currUser => {\n var query = this.query._getParams();\n query.className = this.query.className;\n var data = {};\n data.query = query;\n this.data = this.data || {};\n this.data.source = this.data.source || currUser;\n data.data = this._getDataJSON();\n data.inboxType = this.inboxType || 'default';\n\n return AVRequest('statuses', null, null, 'POST', data, options);\n })\n .then(response => {\n this.id = response.objectId;\n this.createdAt = AV._parseDate(response.createdAt);\n return this;\n });\n },\n\n _finishFetch: function(serverData) {\n this.id = serverData.objectId;\n this.createdAt = AV._parseDate(serverData.createdAt);\n this.updatedAt = AV._parseDate(serverData.updatedAt);\n this.messageId = serverData.messageId;\n delete serverData.messageId;\n delete serverData.objectId;\n delete serverData.createdAt;\n delete serverData.updatedAt;\n this.data = AV._decode(serverData);\n },\n }\n );\n\n /**\n * Send a status to current signined user's followers.\n * @since 0.3.0\n * @param {AV.Status} status A status object to be send to followers.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled when the send\n * completes.\n * @example\n * var status = new AVStatus('image url', 'a message');\n * AV.Status.sendStatusToFollowers(status).then(function(){\n * //send status successfully.\n * }, function(err){\n * //an error threw.\n * console.dir(err);\n * });\n */\n AV.Status.sendStatusToFollowers = function(status, options = {}) {\n if (!getSessionToken(options) && !AV.User.current()) {\n throw new Error('Please signin an user.');\n }\n return getUserPointer(options).then(currUser => {\n var query = {};\n query.className = '_Follower';\n query.keys = 'follower';\n query.where = { user: currUser };\n var data = {};\n data.query = query;\n status.data = status.data || {};\n status.data.source = status.data.source || currUser;\n data.data = status._getDataJSON();\n data.inboxType = status.inboxType || 'default';\n\n var request = AVRequest('statuses', null, null, 'POST', data, options);\n return request.then(function(response) {\n status.id = response.objectId;\n status.createdAt = AV._parseDate(response.createdAt);\n return status;\n });\n });\n };\n\n /**\n *
Send a status from current signined user to other user's private status inbox.
\n * @since 0.3.0\n * @param {AV.Status} status A status object to be send to followers.\n * @param {String} target The target user or user's objectId.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled when the send\n * completes.\n * @example\n * // send a private status to user '52e84e47e4b0f8de283b079b'\n * var status = new AVStatus('image url', 'a message');\n * AV.Status.sendPrivateStatus(status, '52e84e47e4b0f8de283b079b').then(function(){\n * //send status successfully.\n * }, function(err){\n * //an error threw.\n * console.dir(err);\n * });\n */\n AV.Status.sendPrivateStatus = function(status, target, options = {}) {\n if (!getSessionToken(options) && !AV.User.current()) {\n throw new Error('Please signin an user.');\n }\n if (!target) {\n throw new Error('Invalid target user.');\n }\n var userObjectId = _.isString(target) ? target : target.id;\n if (!userObjectId) {\n throw new Error('Invalid target user.');\n }\n return getUserPointer(options).then(currUser => {\n var query = {};\n query.className = '_User';\n query.where = { objectId: userObjectId };\n var data = {};\n data.query = query;\n status.data = status.data || {};\n status.data.source = status.data.source || currUser;\n data.data = status._getDataJSON();\n data.inboxType = 'private';\n status.inboxType = 'private';\n\n var request = AVRequest('statuses', null, null, 'POST', data, options);\n return request.then(function(response) {\n status.id = response.objectId;\n status.createdAt = AV._parseDate(response.createdAt);\n return status;\n });\n });\n };\n\n /**\n * Count unread statuses in someone's inbox.\n * @since 0.3.0\n * @param {AV.User} owner The status owner.\n * @param {String} inboxType The inbox type, 'default' by default.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled when the count\n * completes.\n * @example\n * AV.Status.countUnreadStatuses(AV.User.current()).then(function(response){\n * console.log(response.unread); //unread statuses number.\n * console.log(response.total); //total statuses number.\n * });\n */\n AV.Status.countUnreadStatuses = function(\n owner,\n inboxType = 'default',\n options = {}\n ) {\n if (!_.isString(inboxType)) options = inboxType;\n if (!getSessionToken(options) && owner == null && !AV.User.current()) {\n throw new Error('Please signin an user or pass the owner objectId.');\n }\n return Promise.resolve(owner || getUser(options)).then(owner => {\n var params = {};\n params.inboxType = AV._encode(inboxType);\n params.owner = AV._encode(owner);\n return AVRequest(\n 'subscribe/statuses/count',\n null,\n null,\n 'GET',\n params,\n options\n );\n });\n };\n\n /**\n * reset unread statuses count in someone's inbox.\n * @since 2.1.0\n * @param {AV.User} owner The status owner.\n * @param {String} inboxType The inbox type, 'default' by default.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled when the reset\n * completes.\n * @example\n * AV.Status.resetUnreadCount(AV.User.current()).then(function(response){\n * console.log(response.unread); //unread statuses number.\n * console.log(response.total); //total statuses number.\n * });\n */\n AV.Status.resetUnreadCount = function(\n owner,\n inboxType = 'default',\n options = {}\n ) {\n if (!_.isString(inboxType)) options = inboxType;\n if (!getSessionToken(options) && owner == null && !AV.User.current()) {\n throw new Error('Please signin an user or pass the owner objectId.');\n }\n return Promise.resolve(owner || getUser(options)).then(owner => {\n var params = {};\n params.inboxType = AV._encode(inboxType);\n params.owner = AV._encode(owner);\n return AVRequest(\n 'subscribe/statuses/resetUnreadCount',\n null,\n null,\n 'POST',\n params,\n options\n );\n });\n };\n\n /**\n * Create a status query to find someone's published statuses.\n * @since 0.3.0\n * @param {AV.User} source The status source, typically the publisher.\n * @return {AV.Query} The query object for status.\n * @example\n * //Find current user's published statuses.\n * var query = AV.Status.statusQuery(AV.User.current());\n * query.find().then(function(statuses){\n * //process statuses\n * });\n */\n AV.Status.statusQuery = function(source) {\n var query = new AV.Query('_Status');\n if (source) {\n query.equalTo('source', source);\n }\n return query;\n };\n\n /**\n *
AV.InboxQuery defines a query that is used to fetch somebody's inbox statuses.
\n * @class\n */\n AV.InboxQuery = AV.Query._extend(\n /** @lends AV.InboxQuery.prototype */ {\n _objectClass: AV.Status,\n _sinceId: 0,\n _maxId: 0,\n _inboxType: 'default',\n _owner: null,\n _newObject: function() {\n return new AV.Status();\n },\n _createRequest: function(params, options) {\n return AV.InboxQuery.__super__._createRequest.call(\n this,\n params,\n options,\n '/subscribe/statuses'\n );\n },\n\n /**\n * Sets the messageId of results to skip before returning any results.\n * This is useful for pagination.\n * Default is zero.\n * @param {Number} n the mesage id.\n * @return {AV.InboxQuery} Returns the query, so you can chain this call.\n */\n sinceId: function(id) {\n this._sinceId = id;\n return this;\n },\n /**\n * Sets the maximal messageId of results。\n * This is useful for pagination.\n * Default is zero that is no limition.\n * @param {Number} n the mesage id.\n * @return {AV.InboxQuery} Returns the query, so you can chain this call.\n */\n maxId: function(id) {\n this._maxId = id;\n return this;\n },\n /**\n * Sets the owner of the querying inbox.\n * @param {AV.User} owner The inbox owner.\n * @return {AV.InboxQuery} Returns the query, so you can chain this call.\n */\n owner: function(owner) {\n this._owner = owner;\n return this;\n },\n /**\n * Sets the querying inbox type.default is 'default'.\n * @param {String} type The inbox type.\n * @return {AV.InboxQuery} Returns the query, so you can chain this call.\n */\n inboxType: function(type) {\n this._inboxType = type;\n return this;\n },\n _getParams: function() {\n var params = AV.InboxQuery.__super__._getParams.call(this);\n params.owner = AV._encode(this._owner);\n params.inboxType = AV._encode(this._inboxType);\n params.sinceId = AV._encode(this._sinceId);\n params.maxId = AV._encode(this._maxId);\n return params;\n },\n }\n );\n\n /**\n * Create a inbox status query to find someone's inbox statuses.\n * @since 0.3.0\n * @param {AV.User} owner The inbox's owner\n * @param {String} inboxType The inbox type,'default' by default.\n * @return {AV.InboxQuery} The inbox query object.\n * @see AV.InboxQuery\n * @example\n * //Find current user's default inbox statuses.\n * var query = AV.Status.inboxQuery(AV.User.current());\n * //find the statuses after the last message id\n * query.sinceId(lastMessageId);\n * query.find().then(function(statuses){\n * //process statuses\n * });\n */\n AV.Status.inboxQuery = function(owner, inboxType) {\n var query = new AV.InboxQuery(AV.Status);\n if (owner) {\n query._owner = owner;\n }\n if (inboxType) {\n query._inboxType = inboxType;\n }\n return query;\n };\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/status.js","const _ = require('underscore');\nconst AVRequest = require('./request')._request;\n\nmodule.exports = function(AV) {\n /**\n * A builder to generate sort string for app searching.For example:\n * @class\n * @since 0.5.1\n * @example\n * var builder = new AV.SearchSortBuilder();\n * builder.ascending('key1').descending('key2','max');\n * var query = new AV.SearchQuery('Player');\n * query.sortBy(builder);\n * query.find().then();\n */\n AV.SearchSortBuilder = function() {\n this._sortFields = [];\n };\n\n _.extend(\n AV.SearchSortBuilder.prototype,\n /** @lends AV.SearchSortBuilder.prototype */ {\n _addField: function(key, order, mode, missing) {\n var field = {};\n field[key] = {\n order: order || 'asc',\n mode: mode || 'avg',\n missing: '_' + (missing || 'last'),\n };\n this._sortFields.push(field);\n return this;\n },\n\n /**\n * Sorts the results in ascending order by the given key and options.\n *\n * @param {String} key The key to order by.\n * @param {String} mode The sort mode, default is 'avg', you can choose\n * 'max' or 'min' too.\n * @param {String} missing The missing key behaviour, default is 'last',\n * you can choose 'first' too.\n * @return {AV.SearchSortBuilder} Returns the builder, so you can chain this call.\n */\n ascending: function(key, mode, missing) {\n return this._addField(key, 'asc', mode, missing);\n },\n\n /**\n * Sorts the results in descending order by the given key and options.\n *\n * @param {String} key The key to order by.\n * @param {String} mode The sort mode, default is 'avg', you can choose\n * 'max' or 'min' too.\n * @param {String} missing The missing key behaviour, default is 'last',\n * you can choose 'first' too.\n * @return {AV.SearchSortBuilder} Returns the builder, so you can chain this call.\n */\n descending: function(key, mode, missing) {\n return this._addField(key, 'desc', mode, missing);\n },\n\n /**\n * Add a proximity based constraint for finding objects with key point\n * values near the point given.\n * @param {String} key The key that the AV.GeoPoint is stored in.\n * @param {AV.GeoPoint} point The reference AV.GeoPoint that is used.\n * @param {Object} options The other options such as mode,order, unit etc.\n * @return {AV.SearchSortBuilder} Returns the builder, so you can chain this call.\n */\n whereNear: function(key, point, options) {\n options = options || {};\n var field = {};\n var geo = {\n lat: point.latitude,\n lon: point.longitude,\n };\n var m = {\n order: options.order || 'asc',\n mode: options.mode || 'avg',\n unit: options.unit || 'km',\n };\n m[key] = geo;\n field['_geo_distance'] = m;\n\n this._sortFields.push(field);\n return this;\n },\n\n /**\n * Build a sort string by configuration.\n * @return {String} the sort string.\n */\n build: function() {\n return JSON.stringify(AV._encode(this._sortFields));\n },\n }\n );\n\n /**\n * App searching query.Use just like AV.Query:\n *\n * Visit App Searching Guide\n * for more details.\n * @class\n * @since 0.5.1\n * @example\n * var query = new AV.SearchQuery('Player');\n * query.queryString('*');\n * query.find().then(function(results) {\n * console.log('Found %d objects', query.hits());\n * //Process results\n * });\n */\n AV.SearchQuery = AV.Query._extend(\n /** @lends AV.SearchQuery.prototype */ {\n _sid: null,\n _hits: 0,\n _queryString: null,\n _highlights: null,\n _sortBuilder: null,\n _clazz: null,\n\n constructor: function(className) {\n if (className) {\n this._clazz = className;\n } else {\n className = '__INVALID_CLASS';\n }\n AV.Query.call(this, className);\n },\n\n _createRequest: function(params, options) {\n return AVRequest(\n 'search/select',\n null,\n null,\n 'GET',\n params || this._getParams(),\n options\n );\n },\n\n /**\n * Sets the sid of app searching query.Default is null.\n * @param {String} sid Scroll id for searching.\n * @return {AV.SearchQuery} Returns the query, so you can chain this call.\n */\n sid: function(sid) {\n this._sid = sid;\n return this;\n },\n\n /**\n * Sets the query string of app searching.\n * @param {String} q The query string.\n * @return {AV.SearchQuery} Returns the query, so you can chain this call.\n */\n queryString: function(q) {\n this._queryString = q;\n return this;\n },\n\n /**\n * Sets the highlight fields. Such as\n *
\n * @param {String|String[]} highlights a list of fields.\n * @return {AV.SearchQuery} Returns the query, so you can chain this call.\n */\n highlights: function(highlights) {\n var objects;\n if (highlights && _.isString(highlights)) {\n objects = _.toArray(arguments);\n } else {\n objects = highlights;\n }\n this._highlights = objects;\n return this;\n },\n\n /**\n * Sets the sort builder for this query.\n * @see AV.SearchSortBuilder\n * @param { AV.SearchSortBuilder} builder The sort builder.\n * @return {AV.SearchQuery} Returns the query, so you can chain this call.\n *\n */\n sortBy: function(builder) {\n this._sortBuilder = builder;\n return this;\n },\n\n /**\n * Returns the number of objects that match this query.\n * @return {Number}\n */\n hits: function() {\n if (!this._hits) {\n this._hits = 0;\n }\n return this._hits;\n },\n\n _processResult: function(json) {\n delete json['className'];\n delete json['_app_url'];\n delete json['_deeplink'];\n return json;\n },\n\n /**\n * Returns true when there are more documents can be retrieved by this\n * query instance, you can call find function to get more results.\n * @see AV.SearchQuery#find\n * @return {Boolean}\n */\n hasMore: function() {\n return !this._hitEnd;\n },\n\n /**\n * Reset current query instance state(such as sid, hits etc) except params\n * for a new searching. After resetting, hasMore() will return true.\n */\n reset: function() {\n this._hitEnd = false;\n this._sid = null;\n this._hits = 0;\n },\n\n /**\n * Retrieves a list of AVObjects that satisfy this query.\n * Either options.success or options.error is called when the find\n * completes.\n *\n * @see AV.Query#find\n * @param {AuthOptions} options\n * @return {Promise} A promise that is resolved with the results when\n * the query completes.\n */\n find: function(options) {\n var self = this;\n\n var request = this._createRequest(undefined, options);\n\n return request.then(function(response) {\n //update sid for next querying.\n if (response.sid) {\n self._oldSid = self._sid;\n self._sid = response.sid;\n } else {\n self._sid = null;\n self._hitEnd = true;\n }\n self._hits = response.hits || 0;\n\n return _.map(response.results, function(json) {\n if (json.className) {\n response.className = json.className;\n }\n var obj = self._newObject(response);\n obj.appURL = json['_app_url'];\n obj._finishFetch(self._processResult(json), true);\n return obj;\n });\n });\n },\n\n _getParams: function() {\n var params = AV.SearchQuery.__super__._getParams.call(this);\n delete params.where;\n if (this._clazz) {\n params.clazz = this.className;\n }\n if (this._sid) {\n params.sid = this._sid;\n }\n if (!this._queryString) {\n throw new Error('Please set query string.');\n } else {\n params.q = this._queryString;\n }\n if (this._highlights) {\n params.highlights = this._highlights.join(',');\n }\n if (this._sortBuilder && params.order) {\n throw new Error('sort and order can not be set at same time.');\n }\n if (this._sortBuilder) {\n params.sort = this._sortBuilder.build();\n }\n\n return params;\n },\n }\n );\n};\n\n/**\n * Sorts the results in ascending order by the given key.\n *\n * @method AV.SearchQuery#ascending\n * @param {String} key The key to order by.\n * @return {AV.SearchQuery} Returns the query, so you can chain this call.\n */\n/**\n * Also sorts the results in ascending order by the given key. The previous sort keys have\n * precedence over this key.\n *\n * @method AV.SearchQuery#addAscending\n * @param {String} key The key to order by\n * @return {AV.SearchQuery} Returns the query so you can chain this call.\n */\n/**\n * Sorts the results in descending order by the given key.\n *\n * @method AV.SearchQuery#descending\n * @param {String} key The key to order by.\n * @return {AV.SearchQuery} Returns the query, so you can chain this call.\n */\n/**\n * Also sorts the results in descending order by the given key. The previous sort keys have\n * precedence over this key.\n *\n * @method AV.SearchQuery#addDescending\n * @param {String} key The key to order by\n * @return {AV.SearchQuery} Returns the query so you can chain this call.\n */\n/**\n * Include nested AV.Objects for the provided key. You can use dot\n * notation to specify which fields in the included object are also fetch.\n * @method AV.SearchQuery#include\n * @param {String[]} keys The name of the key to include.\n * @return {AV.SearchQuery} Returns the query, so you can chain this call.\n */\n/**\n * Sets the number of results to skip before returning any results.\n * This is useful for pagination.\n * Default is to skip zero results.\n * @method AV.SearchQuery#skip\n * @param {Number} n the number of results to skip.\n * @return {AV.SearchQuery} Returns the query, so you can chain this call.\n */\n/**\n * Sets the limit of the number of results to return. The default limit is\n * 100, with a maximum of 1000 results being returned at a time.\n * @method AV.SearchQuery#limit\n * @param {Number} n the number of results to limit to.\n * @return {AV.SearchQuery} Returns the query, so you can chain this call.\n */\n\n\n\n// WEBPACK FOOTER //\n// ./src/search.js","const _ = require('underscore');\nconst AVError = require('./error');\nconst { request } = require('./request');\n\nmodule.exports = function(AV) {\n /**\n * 包含了使用了 LeanCloud\n * 离线数据分析功能的函数。\n *
\n * { \"sql\" : \"select count(*) as c,gender from _User group by gender\",\n * \"saveAs\": {\n * \"className\" : \"UserGender\",\n * \"limit\": 1\n * }\n * }\n *
\n * sql 指定任务执行的 SQL 语句, saveAs(可选) 指定将结果保存在哪张表里,limit 最大 1000。\n * @param {AuthOptions} [options]\n * @return {Promise} A promise that will be resolved with the result\n * of the function.\n */\n startJob: function(jobConfig, options) {\n if (!jobConfig || !jobConfig.sql) {\n throw new Error('Please provide the sql to run the job.');\n }\n var data = {\n jobConfig: jobConfig,\n appId: AV.applicationId,\n };\n return request({\n path: '/bigquery/jobs',\n method: 'POST',\n data: AV._encode(data, null, true),\n authOptions: options,\n signKey: false,\n }).then(resp => AV._decode(resp).id);\n },\n\n /**\n * 监听 Insight 任务事件(未来推出独立部署的离线分析服务后开放)\n *
\n * 仅在云引擎运行环境下有效。\n *
\n * @param {String} event 监听的事件,目前尚不支持。\n * @param {Function} 监听回调函数,接收 (err, id) 两个参数,err 表示错误信息,\n * id 表示任务 id。接下来你可以拿这个 id 使用AV.Insight.JobQuery 查询任务状态和结果。\n *\n */\n on: function(event, cb) {},\n }\n );\n\n /**\n * 创建一个对象,用于查询 Insight 任务状态和结果。\n * @class\n * @param {String} id 任务 id\n * @since 0.5.5\n */\n AV.Insight.JobQuery = function(id, className) {\n if (!id) {\n throw new Error('Please provide the job id.');\n }\n this.id = id;\n this.className = className;\n this._skip = 0;\n this._limit = 100;\n };\n\n _.extend(\n AV.Insight.JobQuery.prototype,\n /** @lends AV.Insight.JobQuery.prototype */ {\n /**\n * Sets the number of results to skip before returning any results.\n * This is useful for pagination.\n * Default is to skip zero results.\n * @param {Number} n the number of results to skip.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n skip: function(n) {\n this._skip = n;\n return this;\n },\n\n /**\n * Sets the limit of the number of results to return. The default limit is\n * 100, with a maximum of 1000 results being returned at a time.\n * @param {Number} n the number of results to limit to.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n limit: function(n) {\n this._limit = n;\n return this;\n },\n\n /**\n * 查询任务状态和结果,任务结果为一个 JSON 对象,包括 status 表示任务状态, totalCount 表示总数,\n * results 数组表示任务结果数组,previewCount 表示可以返回的结果总数,任务的开始和截止时间\n * startTime、endTime 等信息。\n *\n * @param {AuthOptions} [options]\n * @return {Promise} A promise that will be resolved with the result\n * of the function.\n *\n */\n find: function(options) {\n var params = {\n skip: this._skip,\n limit: this._limit,\n };\n\n return request({\n path: `/bigquery/jobs/${this.id}`,\n method: 'GET',\n query: params,\n authOptions: options,\n signKey: false,\n }).then(function(response) {\n if (response.error) {\n return Promise.reject(new AVError(response.code, response.error));\n }\n return Promise.resolve(response);\n });\n },\n }\n );\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/insight.js","const _ = require('underscore');\nconst { request: LCRequest } = require('./request');\nconst { getSessionToken } = require('./utils');\n\nmodule.exports = function(AV) {\n const getUserWithSessionToken = authOptions => {\n if (authOptions.user) {\n if (!authOptions.user._sessionToken) {\n throw new Error('authOptions.user is not signed in.');\n }\n return Promise.resolve(authOptions.user);\n }\n if (authOptions.sessionToken) {\n return AV.User._fetchUserBySessionToken(authOptions.sessionToken);\n }\n return AV.User.currentAsync();\n };\n\n const getSessionTokenAsync = authOptions => {\n const sessionToken = getSessionToken(authOptions);\n if (sessionToken) {\n return Promise.resolve(sessionToken);\n }\n return AV.User.currentAsync().then(user => {\n if (user) {\n return user.getSessionToken();\n }\n });\n };\n\n /**\n * Contains functions to deal with Friendship in LeanCloud.\n * @class\n */\n AV.Friendship = {\n /**\n * Request friendship.\n * @since 4.8.0\n * @param {String | AV.User | Object} options if an AV.User or string is given, it will be used as the friend.\n * @param {AV.User | string} options.friend The friend (or friend's objectId) to follow.\n * @param {Object} [options.attributes] key-value attributes dictionary to be used as conditions of followeeQuery.\n * @param {AuthOptions} [authOptions]\n * @return {Promise}\n */\n request: function(options, authOptions = {}) {\n let friend;\n let attributes;\n\n if (options.friend) {\n friend = options.friend;\n attributes = options.attributes;\n } else {\n friend = options;\n }\n\n const friendObj = _.isString(friend)\n ? AV.Object.createWithoutData('_User', friend)\n : friend;\n\n return getUserWithSessionToken(authOptions).then(userObj => {\n if (!userObj) {\n throw new Error('Please signin an user.');\n }\n return LCRequest({\n method: 'POST',\n path: '/users/friendshipRequests',\n data: {\n user: userObj._toPointer(),\n friend: friendObj._toPointer(),\n friendship: attributes,\n },\n authOptions,\n });\n });\n },\n\n /**\n * Accept a friendship request.\n * @since 4.8.0\n * @param {AV.Object | string | Object} options if an AV.Object or string is given, it will be used as the request in _FriendshipRequest.\n * @param {AV.Object} options.request The request (or it's objectId) to be accepted.\n * @param {Object} [options.attributes] key-value attributes dictionary to be used as conditions of {@link AV#followeeQuery}.\n * @param {AuthOptions} [authOptions]\n * @return {Promise}\n */\n acceptRequest: function(options, authOptions = {}) {\n let request;\n let attributes;\n if (options.request) {\n request = options.request;\n attributes = options.attributes;\n } else {\n request = options;\n }\n const requestId = _.isString(request) ? request : request.id;\n return getSessionTokenAsync(authOptions).then(sessionToken => {\n if (!sessionToken) {\n throw new Error('Please signin an user.');\n }\n return LCRequest({\n method: 'PUT',\n path: '/users/friendshipRequests/' + requestId + '/accept',\n data: {\n friendship: AV._encode(attributes),\n },\n authOptions,\n });\n });\n },\n\n /**\n * Decline a friendship request.\n * @param {AV.Object | string} request The request (or it's objectId) to be declined.\n * @param {AuthOptions} [authOptions]\n * @return {Promise}\n */\n declineRequest: function(request, authOptions = {}) {\n const requestId = _.isString(request) ? request : request.id;\n return getSessionTokenAsync(authOptions).then(sessionToken => {\n if (!sessionToken) {\n throw new Error('Please signin an user.');\n }\n return LCRequest({\n method: 'PUT',\n path: '/users/friendshipRequests/' + requestId + '/decline',\n authOptions,\n });\n });\n },\n };\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/friendship.js","const _ = require('underscore');\nconst { _request } = require('./request');\nconst AV = require('./av');\n\nconst serializeMessage = message => {\n if (typeof message === 'string') {\n return message;\n }\n if (typeof message.getPayload === 'function') {\n return JSON.stringify(message.getPayload());\n }\n return JSON.stringify(message);\n};\n\n/**\n *
An AV.Conversation is a local representation of a LeanCloud realtime's\n * conversation. This class is a subclass of AV.Object, and retains the\n * same functionality of an AV.Object, but also extends it with various\n * conversation specific methods, like get members, creators of this conversation.\n *
AV.Events is a fork of Backbone's Events module, provided for your
+ * convenience.
+ *
+ *
A module that can be mixed in to any object in order to provide
+ * it with custom events. You may bind callback functions to an event
+ * with `on`, or remove these functions with `off`.
+ * Triggering an event fires all callbacks in the order that `on` was
+ * called.
+ *
+ * @private
+ * @example
+ * var object = {};
+ * _.extend(object, AV.Events);
+ * object.on('expand', function(){ alert('expanded'); });
+ * object.trigger('expand');
+ *
+ */
+
+ AV.Events = {
+ /**
+ * Bind one or more space separated events, `events`, to a `callback`
+ * function. Passing `"all"` will bind the callback to all events fired.
+ */
+ on: function on(events, callback, context) {
+ var calls, event, node, tail, list;
+
+ if (!callback) {
+ return this;
+ }
+
+ events = events.split(eventSplitter);
+ calls = this._callbacks || (this._callbacks = {}); // Create an immutable callback list, allowing traversal during
+ // modification. The tail is an empty object that will always be used
+ // as the next node.
+
+ event = events.shift();
+
+ while (event) {
+ list = calls[event];
+ node = list ? list.tail : {};
+ node.next = tail = {};
+ node.context = context;
+ node.callback = callback;
+ calls[event] = {
+ tail: tail,
+ next: list ? list.next : node
+ };
+ event = events.shift();
+ }
+
+ return this;
+ },
+
+ /**
+ * Remove one or many callbacks. If `context` is null, removes all callbacks
+ * with that function. If `callback` is null, removes all callbacks for the
+ * event. If `events` is null, removes all bound callbacks for all events.
+ */
+ off: function off(events, callback, context) {
+ var event, calls, node, tail, cb, ctx; // No events, or removing *all* events.
+
+ if (!(calls = this._callbacks)) {
+ return;
+ }
+
+ if (!(events || callback || context)) {
+ delete this._callbacks;
+ return this;
+ } // Loop through the listed events and contexts, splicing them out of the
+ // linked list of callbacks if appropriate.
+
+
+ events = events ? events.split(eventSplitter) : (0, _keys.default)(_).call(_, calls);
+ event = events.shift();
+
+ while (event) {
+ node = calls[event];
+ delete calls[event];
+
+ if (!node || !(callback || context)) {
+ continue;
+ } // Create a new list, omitting the indicated callbacks.
+
+
+ tail = node.tail;
+ node = node.next;
+
+ while (node !== tail) {
+ cb = node.callback;
+ ctx = node.context;
+
+ if (callback && cb !== callback || context && ctx !== context) {
+ this.on(event, cb, ctx);
+ }
+
+ node = node.next;
+ }
+
+ event = events.shift();
+ }
+
+ return this;
+ },
+
+ /**
+ * Trigger one or many events, firing all bound callbacks. Callbacks are
+ * passed the same arguments as `trigger` is, apart from the event name
+ * (unless you're listening on `"all"`, which will cause your callback to
+ * receive the true name of the event as the first argument).
+ */
+ trigger: function trigger(events) {
+ var event, node, calls, tail, args, all, rest;
+
+ if (!(calls = this._callbacks)) {
+ return this;
+ }
+
+ all = calls.all;
+ events = events.split(eventSplitter);
+ rest = slice.call(arguments, 1); // For each event, walk through the linked list of callbacks twice,
+ // first to trigger the event, then to trigger any `"all"` callbacks.
+
+ event = events.shift();
+
+ while (event) {
+ node = calls[event];
+
+ if (node) {
+ tail = node.tail;
+
+ while ((node = node.next) !== tail) {
+ node.callback.apply(node.context || this, rest);
+ }
+ }
+
+ node = all;
+
+ if (node) {
+ var _context;
+
+ tail = node.tail;
+ args = (0, _concat.default)(_context = [event]).call(_context, rest);
+
+ while ((node = node.next) !== tail) {
+ node.callback.apply(node.context || this, args);
+ }
+ }
+
+ event = events.shift();
+ }
+
+ return this;
+ }
+ };
+ /**
+ * @function
+ */
+
+ AV.Events.bind = AV.Events.on;
+ /**
+ * @function
+ */
+
+ AV.Events.unbind = AV.Events.off;
+};
+
+/***/ }),
+/* 437 */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+var _interopRequireDefault = __webpack_require__(2);
+
+var _promise = _interopRequireDefault(__webpack_require__(10));
+
+var _ = __webpack_require__(1);
+/*global navigator: false */
+
+
+module.exports = function (AV) {
+ /**
+ * Creates a new GeoPoint with any of the following forms:
+ * @example
+ * new GeoPoint(otherGeoPoint)
+ * new GeoPoint(30, 30)
+ * new GeoPoint([30, 30])
+ * new GeoPoint({latitude: 30, longitude: 30})
+ * new GeoPoint() // defaults to (0, 0)
+ * @class
+ *
+ *
Represents a latitude / longitude point that may be associated
+ * with a key in a AVObject or used as a reference point for geo queries.
+ * This allows proximity-based queries on the key.
+ *
+ *
Only one key in a class may contain a GeoPoint.
+ *
+ *
Example:
+ * var point = new AV.GeoPoint(30.0, -20.0);
+ * var object = new AV.Object("PlaceObject");
+ * object.set("location", point);
+ * object.save();
+ */
+ AV.GeoPoint = function (arg1, arg2) {
+ if (_.isArray(arg1)) {
+ AV.GeoPoint._validate(arg1[0], arg1[1]);
+
+ this.latitude = arg1[0];
+ this.longitude = arg1[1];
+ } else if (_.isObject(arg1)) {
+ AV.GeoPoint._validate(arg1.latitude, arg1.longitude);
+
+ this.latitude = arg1.latitude;
+ this.longitude = arg1.longitude;
+ } else if (_.isNumber(arg1) && _.isNumber(arg2)) {
+ AV.GeoPoint._validate(arg1, arg2);
+
+ this.latitude = arg1;
+ this.longitude = arg2;
+ } else {
+ this.latitude = 0;
+ this.longitude = 0;
+ } // Add properties so that anyone using Webkit or Mozilla will get an error
+ // if they try to set values that are out of bounds.
+
+
+ var self = this;
+
+ if (this.__defineGetter__ && this.__defineSetter__) {
+ // Use _latitude and _longitude to actually store the values, and add
+ // getters and setters for latitude and longitude.
+ this._latitude = this.latitude;
+ this._longitude = this.longitude;
+
+ this.__defineGetter__('latitude', function () {
+ return self._latitude;
+ });
+
+ this.__defineGetter__('longitude', function () {
+ return self._longitude;
+ });
+
+ this.__defineSetter__('latitude', function (val) {
+ AV.GeoPoint._validate(val, self.longitude);
+
+ self._latitude = val;
+ });
+
+ this.__defineSetter__('longitude', function (val) {
+ AV.GeoPoint._validate(self.latitude, val);
+
+ self._longitude = val;
+ });
+ }
+ };
+ /**
+ * @lends AV.GeoPoint.prototype
+ * @property {float} latitude North-south portion of the coordinate, in range
+ * [-90, 90]. Throws an exception if set out of range in a modern browser.
+ * @property {float} longitude East-west portion of the coordinate, in range
+ * [-180, 180]. Throws if set out of range in a modern browser.
+ */
+
+ /**
+ * Throws an exception if the given lat-long is out of bounds.
+ * @private
+ */
+
+
+ AV.GeoPoint._validate = function (latitude, longitude) {
+ if (latitude < -90.0) {
+ throw new Error('AV.GeoPoint latitude ' + latitude + ' < -90.0.');
+ }
+
+ if (latitude > 90.0) {
+ throw new Error('AV.GeoPoint latitude ' + latitude + ' > 90.0.');
+ }
+
+ if (longitude < -180.0) {
+ throw new Error('AV.GeoPoint longitude ' + longitude + ' < -180.0.');
+ }
+
+ if (longitude > 180.0) {
+ throw new Error('AV.GeoPoint longitude ' + longitude + ' > 180.0.');
+ }
+ };
+ /**
+ * Creates a GeoPoint with the user's current location, if available.
+ * @return {Promise.}
+ */
+
+
+ AV.GeoPoint.current = function () {
+ return new _promise.default(function (resolve, reject) {
+ navigator.geolocation.getCurrentPosition(function (location) {
+ resolve(new AV.GeoPoint({
+ latitude: location.coords.latitude,
+ longitude: location.coords.longitude
+ }));
+ }, reject);
+ });
+ };
+
+ _.extend(AV.GeoPoint.prototype,
+ /** @lends AV.GeoPoint.prototype */
+ {
+ /**
+ * Returns a JSON representation of the GeoPoint, suitable for AV.
+ * @return {Object}
+ */
+ toJSON: function toJSON() {
+ AV.GeoPoint._validate(this.latitude, this.longitude);
+
+ return {
+ __type: 'GeoPoint',
+ latitude: this.latitude,
+ longitude: this.longitude
+ };
+ },
+
+ /**
+ * Returns the distance from this GeoPoint to another in radians.
+ * @param {AV.GeoPoint} point the other AV.GeoPoint.
+ * @return {Number}
+ */
+ radiansTo: function radiansTo(point) {
+ var d2r = Math.PI / 180.0;
+ var lat1rad = this.latitude * d2r;
+ var long1rad = this.longitude * d2r;
+ var lat2rad = point.latitude * d2r;
+ var long2rad = point.longitude * d2r;
+ var deltaLat = lat1rad - lat2rad;
+ var deltaLong = long1rad - long2rad;
+ var sinDeltaLatDiv2 = Math.sin(deltaLat / 2);
+ var sinDeltaLongDiv2 = Math.sin(deltaLong / 2); // Square of half the straight line chord distance between both points.
+
+ var a = sinDeltaLatDiv2 * sinDeltaLatDiv2 + Math.cos(lat1rad) * Math.cos(lat2rad) * sinDeltaLongDiv2 * sinDeltaLongDiv2;
+ a = Math.min(1.0, a);
+ return 2 * Math.asin(Math.sqrt(a));
+ },
+
+ /**
+ * Returns the distance from this GeoPoint to another in kilometers.
+ * @param {AV.GeoPoint} point the other AV.GeoPoint.
+ * @return {Number}
+ */
+ kilometersTo: function kilometersTo(point) {
+ return this.radiansTo(point) * 6371.0;
+ },
+
+ /**
+ * Returns the distance from this GeoPoint to another in miles.
+ * @param {AV.GeoPoint} point the other AV.GeoPoint.
+ * @return {Number}
+ */
+ milesTo: function milesTo(point) {
+ return this.radiansTo(point) * 3958.8;
+ }
+ });
+};
+
+/***/ }),
+/* 438 */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+var _ = __webpack_require__(1);
+
+module.exports = function (AV) {
+ var PUBLIC_KEY = '*';
+ /**
+ * Creates a new ACL.
+ * If no argument is given, the ACL has no permissions for anyone.
+ * If the argument is a AV.User, the ACL will have read and write
+ * permission for only that user.
+ * If the argument is any other JSON object, that object will be interpretted
+ * as a serialized ACL created with toJSON().
+ * @see AV.Object#setACL
+ * @class
+ *
+ *
An ACL, or Access Control List can be added to any
+ * AV.Object to restrict access to only a subset of users
+ * of your application.
+ */
+
+ AV.ACL = function (arg1) {
+ var self = this;
+ self.permissionsById = {};
+
+ if (_.isObject(arg1)) {
+ if (arg1 instanceof AV.User) {
+ self.setReadAccess(arg1, true);
+ self.setWriteAccess(arg1, true);
+ } else {
+ if (_.isFunction(arg1)) {
+ throw new Error('AV.ACL() called with a function. Did you forget ()?');
+ }
+
+ AV._objectEach(arg1, function (accessList, userId) {
+ if (!_.isString(userId)) {
+ throw new Error('Tried to create an ACL with an invalid userId.');
+ }
+
+ self.permissionsById[userId] = {};
+
+ AV._objectEach(accessList, function (allowed, permission) {
+ if (permission !== 'read' && permission !== 'write') {
+ throw new Error('Tried to create an ACL with an invalid permission type.');
+ }
+
+ if (!_.isBoolean(allowed)) {
+ throw new Error('Tried to create an ACL with an invalid permission value.');
+ }
+
+ self.permissionsById[userId][permission] = allowed;
+ });
+ });
+ }
+ }
+ };
+ /**
+ * Returns a JSON-encoded version of the ACL.
+ * @return {Object}
+ */
+
+
+ AV.ACL.prototype.toJSON = function () {
+ return _.clone(this.permissionsById);
+ };
+
+ AV.ACL.prototype._setAccess = function (accessType, userId, allowed) {
+ if (userId instanceof AV.User) {
+ userId = userId.id;
+ } else if (userId instanceof AV.Role) {
+ userId = 'role:' + userId.getName();
+ }
+
+ if (!_.isString(userId)) {
+ throw new Error('userId must be a string.');
+ }
+
+ if (!_.isBoolean(allowed)) {
+ throw new Error('allowed must be either true or false.');
+ }
+
+ var permissions = this.permissionsById[userId];
+
+ if (!permissions) {
+ if (!allowed) {
+ // The user already doesn't have this permission, so no action needed.
+ return;
+ } else {
+ permissions = {};
+ this.permissionsById[userId] = permissions;
+ }
+ }
+
+ if (allowed) {
+ this.permissionsById[userId][accessType] = true;
+ } else {
+ delete permissions[accessType];
+
+ if (_.isEmpty(permissions)) {
+ delete this.permissionsById[userId];
+ }
+ }
+ };
+
+ AV.ACL.prototype._getAccess = function (accessType, userId) {
+ if (userId instanceof AV.User) {
+ userId = userId.id;
+ } else if (userId instanceof AV.Role) {
+ userId = 'role:' + userId.getName();
+ }
+
+ var permissions = this.permissionsById[userId];
+
+ if (!permissions) {
+ return false;
+ }
+
+ return permissions[accessType] ? true : false;
+ };
+ /**
+ * Set whether the given user is allowed to read this object.
+ * @param userId An instance of AV.User or its objectId.
+ * @param {Boolean} allowed Whether that user should have read access.
+ */
+
+
+ AV.ACL.prototype.setReadAccess = function (userId, allowed) {
+ this._setAccess('read', userId, allowed);
+ };
+ /**
+ * Get whether the given user id is *explicitly* allowed to read this object.
+ * Even if this returns false, the user may still be able to access it if
+ * getPublicReadAccess returns true or a role that the user belongs to has
+ * write access.
+ * @param userId An instance of AV.User or its objectId, or a AV.Role.
+ * @return {Boolean}
+ */
+
+
+ AV.ACL.prototype.getReadAccess = function (userId) {
+ return this._getAccess('read', userId);
+ };
+ /**
+ * Set whether the given user id is allowed to write this object.
+ * @param userId An instance of AV.User or its objectId, or a AV.Role..
+ * @param {Boolean} allowed Whether that user should have write access.
+ */
+
+
+ AV.ACL.prototype.setWriteAccess = function (userId, allowed) {
+ this._setAccess('write', userId, allowed);
+ };
+ /**
+ * Get whether the given user id is *explicitly* allowed to write this object.
+ * Even if this returns false, the user may still be able to write it if
+ * getPublicWriteAccess returns true or a role that the user belongs to has
+ * write access.
+ * @param userId An instance of AV.User or its objectId, or a AV.Role.
+ * @return {Boolean}
+ */
+
+
+ AV.ACL.prototype.getWriteAccess = function (userId) {
+ return this._getAccess('write', userId);
+ };
+ /**
+ * Set whether the public is allowed to read this object.
+ * @param {Boolean} allowed
+ */
+
+
+ AV.ACL.prototype.setPublicReadAccess = function (allowed) {
+ this.setReadAccess(PUBLIC_KEY, allowed);
+ };
+ /**
+ * Get whether the public is allowed to read this object.
+ * @return {Boolean}
+ */
+
+
+ AV.ACL.prototype.getPublicReadAccess = function () {
+ return this.getReadAccess(PUBLIC_KEY);
+ };
+ /**
+ * Set whether the public is allowed to write this object.
+ * @param {Boolean} allowed
+ */
+
+
+ AV.ACL.prototype.setPublicWriteAccess = function (allowed) {
+ this.setWriteAccess(PUBLIC_KEY, allowed);
+ };
+ /**
+ * Get whether the public is allowed to write this object.
+ * @return {Boolean}
+ */
+
+
+ AV.ACL.prototype.getPublicWriteAccess = function () {
+ return this.getWriteAccess(PUBLIC_KEY);
+ };
+ /**
+ * Get whether users belonging to the given role are allowed
+ * to read this object. Even if this returns false, the role may
+ * still be able to write it if a parent role has read access.
+ *
+ * @param role The name of the role, or a AV.Role object.
+ * @return {Boolean} true if the role has read access. false otherwise.
+ * @throws {String} If role is neither a AV.Role nor a String.
+ */
+
+
+ AV.ACL.prototype.getRoleReadAccess = function (role) {
+ if (role instanceof AV.Role) {
+ // Normalize to the String name
+ role = role.getName();
+ }
+
+ if (_.isString(role)) {
+ return this.getReadAccess('role:' + role);
+ }
+
+ throw new Error('role must be a AV.Role or a String');
+ };
+ /**
+ * Get whether users belonging to the given role are allowed
+ * to write this object. Even if this returns false, the role may
+ * still be able to write it if a parent role has write access.
+ *
+ * @param role The name of the role, or a AV.Role object.
+ * @return {Boolean} true if the role has write access. false otherwise.
+ * @throws {String} If role is neither a AV.Role nor a String.
+ */
+
+
+ AV.ACL.prototype.getRoleWriteAccess = function (role) {
+ if (role instanceof AV.Role) {
+ // Normalize to the String name
+ role = role.getName();
+ }
+
+ if (_.isString(role)) {
+ return this.getWriteAccess('role:' + role);
+ }
+
+ throw new Error('role must be a AV.Role or a String');
+ };
+ /**
+ * Set whether users belonging to the given role are allowed
+ * to read this object.
+ *
+ * @param role The name of the role, or a AV.Role object.
+ * @param {Boolean} allowed Whether the given role can read this object.
+ * @throws {String} If role is neither a AV.Role nor a String.
+ */
+
+
+ AV.ACL.prototype.setRoleReadAccess = function (role, allowed) {
+ if (role instanceof AV.Role) {
+ // Normalize to the String name
+ role = role.getName();
+ }
+
+ if (_.isString(role)) {
+ this.setReadAccess('role:' + role, allowed);
+ return;
+ }
+
+ throw new Error('role must be a AV.Role or a String');
+ };
+ /**
+ * Set whether users belonging to the given role are allowed
+ * to write this object.
+ *
+ * @param role The name of the role, or a AV.Role object.
+ * @param {Boolean} allowed Whether the given role can write this object.
+ * @throws {String} If role is neither a AV.Role nor a String.
+ */
+
+
+ AV.ACL.prototype.setRoleWriteAccess = function (role, allowed) {
+ if (role instanceof AV.Role) {
+ // Normalize to the String name
+ role = role.getName();
+ }
+
+ if (_.isString(role)) {
+ this.setWriteAccess('role:' + role, allowed);
+ return;
+ }
+
+ throw new Error('role must be a AV.Role or a String');
+ };
+};
+
+/***/ }),
+/* 439 */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+var _interopRequireDefault = __webpack_require__(2);
+
+var _concat = _interopRequireDefault(__webpack_require__(29));
+
+var _find = _interopRequireDefault(__webpack_require__(104));
+
+var _indexOf = _interopRequireDefault(__webpack_require__(102));
+
+var _map = _interopRequireDefault(__webpack_require__(39));
+
+var _ = __webpack_require__(1);
+
+module.exports = function (AV) {
+ /**
+ * @private
+ * @class
+ * A AV.Op is an atomic operation that can be applied to a field in a
+ * AV.Object. For example, calling object.set("foo", "bar")
+ * is an example of a AV.Op.Set. Calling object.unset("foo")
+ * is a AV.Op.Unset. These operations are stored in a AV.Object and
+ * sent to the server as part of object.save() operations.
+ * Instances of AV.Op should be immutable.
+ *
+ * You should not create subclasses of AV.Op or instantiate AV.Op
+ * directly.
+ */
+ AV.Op = function () {
+ this._initialize.apply(this, arguments);
+ };
+
+ _.extend(AV.Op.prototype,
+ /** @lends AV.Op.prototype */
+ {
+ _initialize: function _initialize() {}
+ });
+
+ _.extend(AV.Op, {
+ /**
+ * To create a new Op, call AV.Op._extend();
+ * @private
+ */
+ _extend: AV._extend,
+ // A map of __op string to decoder function.
+ _opDecoderMap: {},
+
+ /**
+ * Registers a function to convert a json object with an __op field into an
+ * instance of a subclass of AV.Op.
+ * @private
+ */
+ _registerDecoder: function _registerDecoder(opName, decoder) {
+ AV.Op._opDecoderMap[opName] = decoder;
+ },
+
+ /**
+ * Converts a json object into an instance of a subclass of AV.Op.
+ * @private
+ */
+ _decode: function _decode(json) {
+ var decoder = AV.Op._opDecoderMap[json.__op];
+
+ if (decoder) {
+ return decoder(json);
+ } else {
+ return undefined;
+ }
+ }
+ });
+ /*
+ * Add a handler for Batch ops.
+ */
+
+
+ AV.Op._registerDecoder('Batch', function (json) {
+ var op = null;
+
+ AV._arrayEach(json.ops, function (nextOp) {
+ nextOp = AV.Op._decode(nextOp);
+ op = nextOp._mergeWithPrevious(op);
+ });
+
+ return op;
+ });
+ /**
+ * @private
+ * @class
+ * A Set operation indicates that either the field was changed using
+ * AV.Object.set, or it is a mutable container that was detected as being
+ * changed.
+ */
+
+
+ AV.Op.Set = AV.Op._extend(
+ /** @lends AV.Op.Set.prototype */
+ {
+ _initialize: function _initialize(value) {
+ this._value = value;
+ },
+
+ /**
+ * Returns the new value of this field after the set.
+ */
+ value: function value() {
+ return this._value;
+ },
+
+ /**
+ * Returns a JSON version of the operation suitable for sending to AV.
+ * @return {Object}
+ */
+ toJSON: function toJSON() {
+ return AV._encode(this.value());
+ },
+ _mergeWithPrevious: function _mergeWithPrevious(previous) {
+ return this;
+ },
+ _estimate: function _estimate(oldValue) {
+ return this.value();
+ }
+ });
+ /**
+ * A sentinel value that is returned by AV.Op.Unset._estimate to
+ * indicate the field should be deleted. Basically, if you find _UNSET as a
+ * value in your object, you should remove that key.
+ */
+
+ AV.Op._UNSET = {};
+ /**
+ * @private
+ * @class
+ * An Unset operation indicates that this field has been deleted from the
+ * object.
+ */
+
+ AV.Op.Unset = AV.Op._extend(
+ /** @lends AV.Op.Unset.prototype */
+ {
+ /**
+ * Returns a JSON version of the operation suitable for sending to AV.
+ * @return {Object}
+ */
+ toJSON: function toJSON() {
+ return {
+ __op: 'Delete'
+ };
+ },
+ _mergeWithPrevious: function _mergeWithPrevious(previous) {
+ return this;
+ },
+ _estimate: function _estimate(oldValue) {
+ return AV.Op._UNSET;
+ }
+ });
+
+ AV.Op._registerDecoder('Delete', function (json) {
+ return new AV.Op.Unset();
+ });
+ /**
+ * @private
+ * @class
+ * An Increment is an atomic operation where the numeric value for the field
+ * will be increased by a given amount.
+ */
+
+
+ AV.Op.Increment = AV.Op._extend(
+ /** @lends AV.Op.Increment.prototype */
+ {
+ _initialize: function _initialize(amount) {
+ this._amount = amount;
+ },
+
+ /**
+ * Returns the amount to increment by.
+ * @return {Number} the amount to increment by.
+ */
+ amount: function amount() {
+ return this._amount;
+ },
+
+ /**
+ * Returns a JSON version of the operation suitable for sending to AV.
+ * @return {Object}
+ */
+ toJSON: function toJSON() {
+ return {
+ __op: 'Increment',
+ amount: this._amount
+ };
+ },
+ _mergeWithPrevious: function _mergeWithPrevious(previous) {
+ if (!previous) {
+ return this;
+ } else if (previous instanceof AV.Op.Unset) {
+ return new AV.Op.Set(this.amount());
+ } else if (previous instanceof AV.Op.Set) {
+ return new AV.Op.Set(previous.value() + this.amount());
+ } else if (previous instanceof AV.Op.Increment) {
+ return new AV.Op.Increment(this.amount() + previous.amount());
+ } else {
+ throw new Error('Op is invalid after previous op.');
+ }
+ },
+ _estimate: function _estimate(oldValue) {
+ if (!oldValue) {
+ return this.amount();
+ }
+
+ return oldValue + this.amount();
+ }
+ });
+
+ AV.Op._registerDecoder('Increment', function (json) {
+ return new AV.Op.Increment(json.amount);
+ });
+ /**
+ * @private
+ * @class
+ * BitAnd is an atomic operation where the given value will be bit and to the
+ * value than is stored in this field.
+ */
+
+
+ AV.Op.BitAnd = AV.Op._extend(
+ /** @lends AV.Op.BitAnd.prototype */
+ {
+ _initialize: function _initialize(value) {
+ this._value = value;
+ },
+ value: function value() {
+ return this._value;
+ },
+
+ /**
+ * Returns a JSON version of the operation suitable for sending to AV.
+ * @return {Object}
+ */
+ toJSON: function toJSON() {
+ return {
+ __op: 'BitAnd',
+ value: this.value()
+ };
+ },
+ _mergeWithPrevious: function _mergeWithPrevious(previous) {
+ if (!previous) {
+ return this;
+ } else if (previous instanceof AV.Op.Unset) {
+ return new AV.Op.Set(0);
+ } else if (previous instanceof AV.Op.Set) {
+ return new AV.Op.Set(previous.value() & this.value());
+ } else {
+ throw new Error('Op is invalid after previous op.');
+ }
+ },
+ _estimate: function _estimate(oldValue) {
+ return oldValue & this.value();
+ }
+ });
+
+ AV.Op._registerDecoder('BitAnd', function (json) {
+ return new AV.Op.BitAnd(json.value);
+ });
+ /**
+ * @private
+ * @class
+ * BitOr is an atomic operation where the given value will be bit and to the
+ * value than is stored in this field.
+ */
+
+
+ AV.Op.BitOr = AV.Op._extend(
+ /** @lends AV.Op.BitOr.prototype */
+ {
+ _initialize: function _initialize(value) {
+ this._value = value;
+ },
+ value: function value() {
+ return this._value;
+ },
+
+ /**
+ * Returns a JSON version of the operation suitable for sending to AV.
+ * @return {Object}
+ */
+ toJSON: function toJSON() {
+ return {
+ __op: 'BitOr',
+ value: this.value()
+ };
+ },
+ _mergeWithPrevious: function _mergeWithPrevious(previous) {
+ if (!previous) {
+ return this;
+ } else if (previous instanceof AV.Op.Unset) {
+ return new AV.Op.Set(this.value());
+ } else if (previous instanceof AV.Op.Set) {
+ return new AV.Op.Set(previous.value() | this.value());
+ } else {
+ throw new Error('Op is invalid after previous op.');
+ }
+ },
+ _estimate: function _estimate(oldValue) {
+ return oldValue | this.value();
+ }
+ });
+
+ AV.Op._registerDecoder('BitOr', function (json) {
+ return new AV.Op.BitOr(json.value);
+ });
+ /**
+ * @private
+ * @class
+ * BitXor is an atomic operation where the given value will be bit and to the
+ * value than is stored in this field.
+ */
+
+
+ AV.Op.BitXor = AV.Op._extend(
+ /** @lends AV.Op.BitXor.prototype */
+ {
+ _initialize: function _initialize(value) {
+ this._value = value;
+ },
+ value: function value() {
+ return this._value;
+ },
+
+ /**
+ * Returns a JSON version of the operation suitable for sending to AV.
+ * @return {Object}
+ */
+ toJSON: function toJSON() {
+ return {
+ __op: 'BitXor',
+ value: this.value()
+ };
+ },
+ _mergeWithPrevious: function _mergeWithPrevious(previous) {
+ if (!previous) {
+ return this;
+ } else if (previous instanceof AV.Op.Unset) {
+ return new AV.Op.Set(this.value());
+ } else if (previous instanceof AV.Op.Set) {
+ return new AV.Op.Set(previous.value() ^ this.value());
+ } else {
+ throw new Error('Op is invalid after previous op.');
+ }
+ },
+ _estimate: function _estimate(oldValue) {
+ return oldValue ^ this.value();
+ }
+ });
+
+ AV.Op._registerDecoder('BitXor', function (json) {
+ return new AV.Op.BitXor(json.value);
+ });
+ /**
+ * @private
+ * @class
+ * Add is an atomic operation where the given objects will be appended to the
+ * array that is stored in this field.
+ */
+
+
+ AV.Op.Add = AV.Op._extend(
+ /** @lends AV.Op.Add.prototype */
+ {
+ _initialize: function _initialize(objects) {
+ this._objects = objects;
+ },
+
+ /**
+ * Returns the objects to be added to the array.
+ * @return {Array} The objects to be added to the array.
+ */
+ objects: function objects() {
+ return this._objects;
+ },
+
+ /**
+ * Returns a JSON version of the operation suitable for sending to AV.
+ * @return {Object}
+ */
+ toJSON: function toJSON() {
+ return {
+ __op: 'Add',
+ objects: AV._encode(this.objects())
+ };
+ },
+ _mergeWithPrevious: function _mergeWithPrevious(previous) {
+ if (!previous) {
+ return this;
+ } else if (previous instanceof AV.Op.Unset) {
+ return new AV.Op.Set(this.objects());
+ } else if (previous instanceof AV.Op.Set) {
+ return new AV.Op.Set(this._estimate(previous.value()));
+ } else if (previous instanceof AV.Op.Add) {
+ var _context;
+
+ return new AV.Op.Add((0, _concat.default)(_context = previous.objects()).call(_context, this.objects()));
+ } else {
+ throw new Error('Op is invalid after previous op.');
+ }
+ },
+ _estimate: function _estimate(oldValue) {
+ if (!oldValue) {
+ return _.clone(this.objects());
+ } else {
+ return (0, _concat.default)(oldValue).call(oldValue, this.objects());
+ }
+ }
+ });
+
+ AV.Op._registerDecoder('Add', function (json) {
+ return new AV.Op.Add(AV._decode(json.objects));
+ });
+ /**
+ * @private
+ * @class
+ * AddUnique is an atomic operation where the given items will be appended to
+ * the array that is stored in this field only if they were not already
+ * present in the array.
+ */
+
+
+ AV.Op.AddUnique = AV.Op._extend(
+ /** @lends AV.Op.AddUnique.prototype */
+ {
+ _initialize: function _initialize(objects) {
+ this._objects = _.uniq(objects);
+ },
+
+ /**
+ * Returns the objects to be added to the array.
+ * @return {Array} The objects to be added to the array.
+ */
+ objects: function objects() {
+ return this._objects;
+ },
+
+ /**
+ * Returns a JSON version of the operation suitable for sending to AV.
+ * @return {Object}
+ */
+ toJSON: function toJSON() {
+ return {
+ __op: 'AddUnique',
+ objects: AV._encode(this.objects())
+ };
+ },
+ _mergeWithPrevious: function _mergeWithPrevious(previous) {
+ if (!previous) {
+ return this;
+ } else if (previous instanceof AV.Op.Unset) {
+ return new AV.Op.Set(this.objects());
+ } else if (previous instanceof AV.Op.Set) {
+ return new AV.Op.Set(this._estimate(previous.value()));
+ } else if (previous instanceof AV.Op.AddUnique) {
+ return new AV.Op.AddUnique(this._estimate(previous.objects()));
+ } else {
+ throw new Error('Op is invalid after previous op.');
+ }
+ },
+ _estimate: function _estimate(oldValue) {
+ if (!oldValue) {
+ return _.clone(this.objects());
+ } else {
+ // We can't just take the _.uniq(_.union(...)) of oldValue and
+ // this.objects, because the uniqueness may not apply to oldValue
+ // (especially if the oldValue was set via .set())
+ var newValue = _.clone(oldValue);
+
+ AV._arrayEach(this.objects(), function (obj) {
+ if (obj instanceof AV.Object && obj.id) {
+ var matchingObj = (0, _find.default)(_).call(_, newValue, function (anObj) {
+ return anObj instanceof AV.Object && anObj.id === obj.id;
+ });
+
+ if (!matchingObj) {
+ newValue.push(obj);
+ } else {
+ var index = (0, _indexOf.default)(_).call(_, newValue, matchingObj);
+ newValue[index] = obj;
+ }
+ } else if (!_.contains(newValue, obj)) {
+ newValue.push(obj);
+ }
+ });
+
+ return newValue;
+ }
+ }
+ });
+
+ AV.Op._registerDecoder('AddUnique', function (json) {
+ return new AV.Op.AddUnique(AV._decode(json.objects));
+ });
+ /**
+ * @private
+ * @class
+ * Remove is an atomic operation where the given objects will be removed from
+ * the array that is stored in this field.
+ */
+
+
+ AV.Op.Remove = AV.Op._extend(
+ /** @lends AV.Op.Remove.prototype */
+ {
+ _initialize: function _initialize(objects) {
+ this._objects = _.uniq(objects);
+ },
+
+ /**
+ * Returns the objects to be removed from the array.
+ * @return {Array} The objects to be removed from the array.
+ */
+ objects: function objects() {
+ return this._objects;
+ },
+
+ /**
+ * Returns a JSON version of the operation suitable for sending to AV.
+ * @return {Object}
+ */
+ toJSON: function toJSON() {
+ return {
+ __op: 'Remove',
+ objects: AV._encode(this.objects())
+ };
+ },
+ _mergeWithPrevious: function _mergeWithPrevious(previous) {
+ if (!previous) {
+ return this;
+ } else if (previous instanceof AV.Op.Unset) {
+ return previous;
+ } else if (previous instanceof AV.Op.Set) {
+ return new AV.Op.Set(this._estimate(previous.value()));
+ } else if (previous instanceof AV.Op.Remove) {
+ return new AV.Op.Remove(_.union(previous.objects(), this.objects()));
+ } else {
+ throw new Error('Op is invalid after previous op.');
+ }
+ },
+ _estimate: function _estimate(oldValue) {
+ if (!oldValue) {
+ return [];
+ } else {
+ var newValue = _.difference(oldValue, this.objects()); // If there are saved AV Objects being removed, also remove them.
+
+
+ AV._arrayEach(this.objects(), function (obj) {
+ if (obj instanceof AV.Object && obj.id) {
+ newValue = _.reject(newValue, function (other) {
+ return other instanceof AV.Object && other.id === obj.id;
+ });
+ }
+ });
+
+ return newValue;
+ }
+ }
+ });
+
+ AV.Op._registerDecoder('Remove', function (json) {
+ return new AV.Op.Remove(AV._decode(json.objects));
+ });
+ /**
+ * @private
+ * @class
+ * A Relation operation indicates that the field is an instance of
+ * AV.Relation, and objects are being added to, or removed from, that
+ * relation.
+ */
+
+
+ AV.Op.Relation = AV.Op._extend(
+ /** @lends AV.Op.Relation.prototype */
+ {
+ _initialize: function _initialize(adds, removes) {
+ this._targetClassName = null;
+ var self = this;
+
+ var pointerToId = function pointerToId(object) {
+ if (object instanceof AV.Object) {
+ if (!object.id) {
+ throw new Error("You can't add an unsaved AV.Object to a relation.");
+ }
+
+ if (!self._targetClassName) {
+ self._targetClassName = object.className;
+ }
+
+ if (self._targetClassName !== object.className) {
+ throw new Error('Tried to create a AV.Relation with 2 different types: ' + self._targetClassName + ' and ' + object.className + '.');
+ }
+
+ return object.id;
+ }
+
+ return object;
+ };
+
+ this.relationsToAdd = _.uniq((0, _map.default)(_).call(_, adds, pointerToId));
+ this.relationsToRemove = _.uniq((0, _map.default)(_).call(_, removes, pointerToId));
+ },
+
+ /**
+ * Returns an array of unfetched AV.Object that are being added to the
+ * relation.
+ * @return {Array}
+ */
+ added: function added() {
+ var self = this;
+ return (0, _map.default)(_).call(_, this.relationsToAdd, function (objectId) {
+ var object = AV.Object._create(self._targetClassName);
+
+ object.id = objectId;
+ return object;
+ });
+ },
+
+ /**
+ * Returns an array of unfetched AV.Object that are being removed from
+ * the relation.
+ * @return {Array}
+ */
+ removed: function removed() {
+ var self = this;
+ return (0, _map.default)(_).call(_, this.relationsToRemove, function (objectId) {
+ var object = AV.Object._create(self._targetClassName);
+
+ object.id = objectId;
+ return object;
+ });
+ },
+
+ /**
+ * Returns a JSON version of the operation suitable for sending to AV.
+ * @return {Object}
+ */
+ toJSON: function toJSON() {
+ var adds = null;
+ var removes = null;
+ var self = this;
+
+ var idToPointer = function idToPointer(id) {
+ return {
+ __type: 'Pointer',
+ className: self._targetClassName,
+ objectId: id
+ };
+ };
+
+ var pointers = null;
+
+ if (this.relationsToAdd.length > 0) {
+ pointers = (0, _map.default)(_).call(_, this.relationsToAdd, idToPointer);
+ adds = {
+ __op: 'AddRelation',
+ objects: pointers
+ };
+ }
+
+ if (this.relationsToRemove.length > 0) {
+ pointers = (0, _map.default)(_).call(_, this.relationsToRemove, idToPointer);
+ removes = {
+ __op: 'RemoveRelation',
+ objects: pointers
+ };
+ }
+
+ if (adds && removes) {
+ return {
+ __op: 'Batch',
+ ops: [adds, removes]
+ };
+ }
+
+ return adds || removes || {};
+ },
+ _mergeWithPrevious: function _mergeWithPrevious(previous) {
+ if (!previous) {
+ return this;
+ } else if (previous instanceof AV.Op.Unset) {
+ throw new Error("You can't modify a relation after deleting it.");
+ } else if (previous instanceof AV.Op.Relation) {
+ if (previous._targetClassName && previous._targetClassName !== this._targetClassName) {
+ throw new Error('Related object must be of class ' + previous._targetClassName + ', but ' + this._targetClassName + ' was passed in.');
+ }
+
+ var newAdd = _.union(_.difference(previous.relationsToAdd, this.relationsToRemove), this.relationsToAdd);
+
+ var newRemove = _.union(_.difference(previous.relationsToRemove, this.relationsToAdd), this.relationsToRemove);
+
+ var newRelation = new AV.Op.Relation(newAdd, newRemove);
+ newRelation._targetClassName = this._targetClassName;
+ return newRelation;
+ } else {
+ throw new Error('Op is invalid after previous op.');
+ }
+ },
+ _estimate: function _estimate(oldValue, object, key) {
+ if (!oldValue) {
+ var relation = new AV.Relation(object, key);
+ relation.targetClassName = this._targetClassName;
+ } else if (oldValue instanceof AV.Relation) {
+ if (this._targetClassName) {
+ if (oldValue.targetClassName) {
+ if (oldValue.targetClassName !== this._targetClassName) {
+ throw new Error('Related object must be a ' + oldValue.targetClassName + ', but a ' + this._targetClassName + ' was passed in.');
+ }
+ } else {
+ oldValue.targetClassName = this._targetClassName;
+ }
+ }
+
+ return oldValue;
+ } else {
+ throw new Error('Op is invalid after previous op.');
+ }
+ }
+ });
+
+ AV.Op._registerDecoder('AddRelation', function (json) {
+ return new AV.Op.Relation(AV._decode(json.objects), []);
+ });
+
+ AV.Op._registerDecoder('RemoveRelation', function (json) {
+ return new AV.Op.Relation([], AV._decode(json.objects));
+ });
+};
+
+/***/ }),
+/* 440 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var parent = __webpack_require__(441);
+
+module.exports = parent;
+
+
+/***/ }),
+/* 441 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var isPrototypeOf = __webpack_require__(20);
+var method = __webpack_require__(442);
+
+var ArrayPrototype = Array.prototype;
+
+module.exports = function (it) {
+ var own = it.find;
+ return it === ArrayPrototype || (isPrototypeOf(ArrayPrototype, it) && own === ArrayPrototype.find) ? method : own;
+};
+
+
+/***/ }),
+/* 442 */
+/***/ (function(module, exports, __webpack_require__) {
+
+__webpack_require__(443);
+var entryVirtual = __webpack_require__(38);
+
+module.exports = entryVirtual('Array').find;
+
+
+/***/ }),
+/* 443 */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+var $ = __webpack_require__(0);
+var $find = __webpack_require__(101).find;
+var addToUnscopables = __webpack_require__(152);
+
+var FIND = 'find';
+var SKIPS_HOLES = true;
+
+// Shouldn't skip holes
+if (FIND in []) Array(1)[FIND](function () { SKIPS_HOLES = false; });
+
+// `Array.prototype.find` method
+// https://tc39.es/ecma262/#sec-array.prototype.find
+$({ target: 'Array', proto: true, forced: SKIPS_HOLES }, {
+ find: function find(callbackfn /* , that = undefined */) {
+ return $find(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
+ }
+});
+
+// https://tc39.es/ecma262/#sec-array.prototype-@@unscopables
+addToUnscopables(FIND);
+
+
+/***/ }),
+/* 444 */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+var _ = __webpack_require__(1);
+
+module.exports = function (AV) {
+ /**
+ * Creates a new Relation for the given parent object and key. This
+ * constructor should rarely be used directly, but rather created by
+ * {@link AV.Object#relation}.
+ * @param {AV.Object} parent The parent of this relation.
+ * @param {String} key The key for this relation on the parent.
+ * @see AV.Object#relation
+ * @class
+ *
+ *
+ * A class that is used to access all of the children of a many-to-many
+ * relationship. Each instance of AV.Relation is associated with a
+ * particular parent object and key.
+ *
+ */
+ AV.Relation = function (parent, key) {
+ if (!_.isString(key)) {
+ throw new TypeError('key must be a string');
+ }
+
+ this.parent = parent;
+ this.key = key;
+ this.targetClassName = null;
+ };
+ /**
+ * Creates a query that can be used to query the parent objects in this relation.
+ * @param {String} parentClass The parent class or name.
+ * @param {String} relationKey The relation field key in parent.
+ * @param {AV.Object} child The child object.
+ * @return {AV.Query}
+ */
+
+
+ AV.Relation.reverseQuery = function (parentClass, relationKey, child) {
+ var query = new AV.Query(parentClass);
+ query.equalTo(relationKey, child._toPointer());
+ return query;
+ };
+
+ _.extend(AV.Relation.prototype,
+ /** @lends AV.Relation.prototype */
+ {
+ /**
+ * Makes sure that this relation has the right parent and key.
+ * @private
+ */
+ _ensureParentAndKey: function _ensureParentAndKey(parent, key) {
+ this.parent = this.parent || parent;
+ this.key = this.key || key;
+
+ if (this.parent !== parent) {
+ throw new Error('Internal Error. Relation retrieved from two different Objects.');
+ }
+
+ if (this.key !== key) {
+ throw new Error('Internal Error. Relation retrieved from two different keys.');
+ }
+ },
+
+ /**
+ * Adds a AV.Object or an array of AV.Objects to the relation.
+ * @param {AV.Object|AV.Object[]} objects The item or items to add.
+ */
+ add: function add(objects) {
+ if (!_.isArray(objects)) {
+ objects = [objects];
+ }
+
+ var change = new AV.Op.Relation(objects, []);
+ this.parent.set(this.key, change);
+ this.targetClassName = change._targetClassName;
+ },
+
+ /**
+ * Removes a AV.Object or an array of AV.Objects from this relation.
+ * @param {AV.Object|AV.Object[]} objects The item or items to remove.
+ */
+ remove: function remove(objects) {
+ if (!_.isArray(objects)) {
+ objects = [objects];
+ }
+
+ var change = new AV.Op.Relation([], objects);
+ this.parent.set(this.key, change);
+ this.targetClassName = change._targetClassName;
+ },
+
+ /**
+ * Returns a JSON version of the object suitable for saving to disk.
+ * @return {Object}
+ */
+ toJSON: function toJSON() {
+ return {
+ __type: 'Relation',
+ className: this.targetClassName
+ };
+ },
+
+ /**
+ * Returns a AV.Query that is limited to objects in this
+ * relation.
+ * @return {AV.Query}
+ */
+ query: function query() {
+ var targetClass;
+ var query;
+
+ if (!this.targetClassName) {
+ targetClass = AV.Object._getSubclass(this.parent.className);
+ query = new AV.Query(targetClass);
+ query._defaultParams.redirectClassNameForKey = this.key;
+ } else {
+ targetClass = AV.Object._getSubclass(this.targetClassName);
+ query = new AV.Query(targetClass);
+ }
+
+ query._addCondition('$relatedTo', 'object', this.parent._toPointer());
+
+ query._addCondition('$relatedTo', 'key', this.key);
+
+ return query;
+ }
+ });
+};
+
+/***/ }),
+/* 445 */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+var _interopRequireDefault = __webpack_require__(2);
+
+var _promise = _interopRequireDefault(__webpack_require__(10));
+
+var _ = __webpack_require__(1);
+
+var cos = __webpack_require__(446);
+
+var qiniu = __webpack_require__(447);
+
+var s3 = __webpack_require__(495);
+
+var AVError = __webpack_require__(40);
+
+var _require = __webpack_require__(25),
+ request = _require.request,
+ AVRequest = _require._request;
+
+var _require2 = __webpack_require__(28),
+ tap = _require2.tap,
+ transformFetchOptions = _require2.transformFetchOptions;
+
+var debug = __webpack_require__(60)('leancloud:file');
+
+var parseBase64 = __webpack_require__(499);
+
+module.exports = function (AV) {
+ // port from browserify path module
+ // since react-native packager won't shim node modules.
+ var extname = function extname(path) {
+ if (!_.isString(path)) return '';
+ return path.match(/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/)[4];
+ };
+
+ var b64Digit = function b64Digit(number) {
+ if (number < 26) {
+ return String.fromCharCode(65 + number);
+ }
+
+ if (number < 52) {
+ return String.fromCharCode(97 + (number - 26));
+ }
+
+ if (number < 62) {
+ return String.fromCharCode(48 + (number - 52));
+ }
+
+ if (number === 62) {
+ return '+';
+ }
+
+ if (number === 63) {
+ return '/';
+ }
+
+ throw new Error('Tried to encode large digit ' + number + ' in base64.');
+ };
+
+ var encodeBase64 = function encodeBase64(array) {
+ var chunks = [];
+ chunks.length = Math.ceil(array.length / 3);
+
+ _.times(chunks.length, function (i) {
+ var b1 = array[i * 3];
+ var b2 = array[i * 3 + 1] || 0;
+ var b3 = array[i * 3 + 2] || 0;
+ var has2 = i * 3 + 1 < array.length;
+ var has3 = i * 3 + 2 < array.length;
+ chunks[i] = [b64Digit(b1 >> 2 & 0x3f), b64Digit(b1 << 4 & 0x30 | b2 >> 4 & 0x0f), has2 ? b64Digit(b2 << 2 & 0x3c | b3 >> 6 & 0x03) : '=', has3 ? b64Digit(b3 & 0x3f) : '='].join('');
+ });
+
+ return chunks.join('');
+ };
+ /**
+ * An AV.File is a local representation of a file that is saved to the AV
+ * cloud.
+ * @param name {String} The file's name. This will change to a unique value
+ * once the file has finished saving.
+ * @param data {Array} The data for the file, as either:
+ * 1. an Array of byte value Numbers, or
+ * 2. an Object like { base64: "..." } with a base64-encoded String.
+ * 3. a Blob(File) selected with a file upload control in a browser.
+ * 4. an Object like { blob: {uri: "..."} } that mimics Blob
+ * in some non-browser environments such as React Native.
+ * 5. a Buffer in Node.js runtime.
+ * 6. a Stream in Node.js runtime.
+ *
+ * For example:
+ * var fileUploadControl = $("#profilePhotoFileUpload")[0];
+ * if (fileUploadControl.files.length > 0) {
+ * var file = fileUploadControl.files[0];
+ * var name = "photo.jpg";
+ * var file = new AV.File(name, file);
+ * file.save().then(function() {
+ * // The file has been saved to AV.
+ * }, function(error) {
+ * // The file either could not be read, or could not be saved to AV.
+ * });
+ * }
+ *
+ * @class
+ * @param [mimeType] {String} Content-Type header to use for the file. If
+ * this is omitted, the content type will be inferred from the name's
+ * extension.
+ */
+
+
+ AV.File = function (name, data, mimeType) {
+ this.attributes = {
+ name: name,
+ url: '',
+ metaData: {},
+ // 用来存储转换后要上传的 base64 String
+ base64: ''
+ };
+
+ if (_.isString(data)) {
+ throw new TypeError('Creating an AV.File from a String is not yet supported.');
+ }
+
+ if (_.isArray(data)) {
+ this.attributes.metaData.size = data.length;
+ data = {
+ base64: encodeBase64(data)
+ };
+ }
+
+ this._extName = '';
+ this._data = data;
+ this._uploadHeaders = {};
+
+ if (data && data.blob && typeof data.blob.uri === 'string') {
+ this._extName = extname(data.blob.uri);
+ }
+
+ if (typeof Blob !== 'undefined' && data instanceof Blob) {
+ if (data.size) {
+ this.attributes.metaData.size = data.size;
+ }
+
+ if (data.name) {
+ this._extName = extname(data.name);
+ }
+ }
+
+ var owner;
+
+ if (data && data.owner) {
+ owner = data.owner;
+ } else if (!AV._config.disableCurrentUser) {
+ try {
+ owner = AV.User.current();
+ } catch (error) {
+ if ('SYNC_API_NOT_AVAILABLE' !== error.code) {
+ throw error;
+ }
+ }
+ }
+
+ this.attributes.metaData.owner = owner ? owner.id : 'unknown';
+ this.set('mime_type', mimeType);
+ };
+ /**
+ * Creates a fresh AV.File object with exists url for saving to AVOS Cloud.
+ * @param {String} name the file name
+ * @param {String} url the file url.
+ * @param {Object} [metaData] the file metadata object.
+ * @param {String} [type] Content-Type header to use for the file. If
+ * this is omitted, the content type will be inferred from the name's
+ * extension.
+ * @return {AV.File} the file object
+ */
+
+
+ AV.File.withURL = function (name, url, metaData, type) {
+ if (!name || !url) {
+ throw new Error('Please provide file name and url');
+ }
+
+ var file = new AV.File(name, null, type); //copy metaData properties to file.
+
+ if (metaData) {
+ for (var prop in metaData) {
+ if (!file.attributes.metaData[prop]) file.attributes.metaData[prop] = metaData[prop];
+ }
+ }
+
+ file.attributes.url = url; //Mark the file is from external source.
+
+ file.attributes.metaData.__source = 'external';
+ file.attributes.metaData.size = 0;
+ return file;
+ };
+ /**
+ * Creates a file object with exists objectId.
+ * @param {String} objectId The objectId string
+ * @return {AV.File} the file object
+ */
+
+
+ AV.File.createWithoutData = function (objectId) {
+ if (!objectId) {
+ throw new TypeError('The objectId must be provided');
+ }
+
+ var file = new AV.File();
+ file.id = objectId;
+ return file;
+ };
+ /**
+ * Request file censor.
+ * @since 4.13.0
+ * @param {String} objectId
+ * @return {Promise.}
+ */
+
+
+ AV.File.censor = function (objectId) {
+ if (!AV._config.masterKey) {
+ throw new Error('Cannot censor a file without masterKey');
+ }
+
+ return request({
+ method: 'POST',
+ path: "/files/".concat(objectId, "/censor"),
+ authOptions: {
+ useMasterKey: true
+ }
+ }).then(function (res) {
+ return res.censorResult;
+ });
+ };
+
+ _.extend(AV.File.prototype,
+ /** @lends AV.File.prototype */
+ {
+ className: '_File',
+ _toFullJSON: function _toFullJSON(seenObjects) {
+ var _this = this;
+
+ var full = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
+
+ var json = _.clone(this.attributes);
+
+ AV._objectEach(json, function (val, key) {
+ json[key] = AV._encode(val, seenObjects, undefined, full);
+ });
+
+ AV._objectEach(this._operations, function (val, key) {
+ json[key] = val;
+ });
+
+ if (_.has(this, 'id')) {
+ json.objectId = this.id;
+ }
+
+ ['createdAt', 'updatedAt'].forEach(function (key) {
+ if (_.has(_this, key)) {
+ var val = _this[key];
+ json[key] = _.isDate(val) ? val.toJSON() : val;
+ }
+ });
+
+ if (full) {
+ json.__type = 'File';
+ }
+
+ return json;
+ },
+
+ /**
+ * Returns a JSON version of the file with meta data.
+ * Inverse to {@link AV.parseJSON}
+ * @since 3.0.0
+ * @return {Object}
+ */
+ toFullJSON: function toFullJSON() {
+ var seenObjects = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
+ return this._toFullJSON(seenObjects);
+ },
+
+ /**
+ * Returns a JSON version of the object.
+ * @return {Object}
+ */
+ toJSON: function toJSON(key, holder) {
+ var seenObjects = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [this];
+ return this._toFullJSON(seenObjects, false);
+ },
+
+ /**
+ * Gets a Pointer referencing this file.
+ * @private
+ */
+ _toPointer: function _toPointer() {
+ return {
+ __type: 'Pointer',
+ className: this.className,
+ objectId: this.id
+ };
+ },
+
+ /**
+ * Returns the ACL for this file.
+ * @returns {AV.ACL} An instance of AV.ACL.
+ */
+ getACL: function getACL() {
+ return this._acl;
+ },
+
+ /**
+ * Sets the ACL to be used for this file.
+ * @param {AV.ACL} acl An instance of AV.ACL.
+ */
+ setACL: function setACL(acl) {
+ if (!(acl instanceof AV.ACL)) {
+ return new AVError(AVError.OTHER_CAUSE, 'ACL must be a AV.ACL.');
+ }
+
+ this._acl = acl;
+ return this;
+ },
+
+ /**
+ * Gets the name of the file. Before save is called, this is the filename
+ * given by the user. After save is called, that name gets prefixed with a
+ * unique identifier.
+ */
+ name: function name() {
+ return this.get('name');
+ },
+
+ /**
+ * Gets the url of the file. It is only available after you save the file or
+ * after you get the file from a AV.Object.
+ * @return {String}
+ */
+ url: function url() {
+ return this.get('url');
+ },
+
+ /**
+ * Gets the attributs of the file object.
+ * @param {String} The attribute name which want to get.
+ * @returns {Any}
+ */
+ get: function get(attrName) {
+ switch (attrName) {
+ case 'objectId':
+ return this.id;
+
+ case 'url':
+ case 'name':
+ case 'mime_type':
+ case 'metaData':
+ case 'createdAt':
+ case 'updatedAt':
+ return this.attributes[attrName];
+
+ default:
+ return this.attributes.metaData[attrName];
+ }
+ },
+
+ /**
+ * Set the metaData of the file object.
+ * @param {Object} Object is an key value Object for setting metaData.
+ * @param {String} attr is an optional metadata key.
+ * @param {Object} value is an optional metadata value.
+ * @returns {String|Number|Array|Object}
+ */
+ set: function set() {
+ var _this2 = this;
+
+ var set = function set(attrName, value) {
+ switch (attrName) {
+ case 'name':
+ case 'url':
+ case 'mime_type':
+ case 'base64':
+ case 'metaData':
+ _this2.attributes[attrName] = value;
+ break;
+
+ default:
+ // File 并非一个 AVObject,不能完全自定义其他属性,所以只能都放在 metaData 上面
+ _this2.attributes.metaData[attrName] = value;
+ break;
+ }
+ };
+
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
+ args[_key] = arguments[_key];
+ }
+
+ switch (args.length) {
+ case 1:
+ // 传入一个 Object
+ for (var k in args[0]) {
+ set(k, args[0][k]);
+ }
+
+ break;
+
+ case 2:
+ set(args[0], args[1]);
+ break;
+ }
+
+ return this;
+ },
+
+ /**
+ * Set a header for the upload request.
+ * For more infomation, go to https://url.leanapp.cn/avfile-upload-headers
+ *
+ * @param {String} key header key
+ * @param {String} value header value
+ * @return {AV.File} this
+ */
+ setUploadHeader: function setUploadHeader(key, value) {
+ this._uploadHeaders[key] = value;
+ return this;
+ },
+
+ /**
+ *
Returns the file's metadata JSON object if no arguments is given.Returns the
+ * metadata value if a key is given.Set metadata value if key and value are both given.
+ *
+ * var metadata = file.metaData(); //Get metadata JSON object.
+ * var size = file.metaData('size'); // Get the size metadata value.
+ * file.metaData('format', 'jpeg'); //set metadata attribute and value.
+ *
+ * @return {Object} The file's metadata JSON object.
+ * @param {String} attr an optional metadata key.
+ * @param {Object} value an optional metadata value.
+ **/
+ metaData: function metaData(attr, value) {
+ if (attr && value) {
+ this.attributes.metaData[attr] = value;
+ return this;
+ } else if (attr && !value) {
+ return this.attributes.metaData[attr];
+ } else {
+ return this.attributes.metaData;
+ }
+ },
+
+ /**
+ * 如果文件是图片,获取图片的缩略图URL。可以传入宽度、高度、质量、格式等参数。
+ * @return {String} 缩略图URL
+ * @param {Number} width 宽度,单位:像素
+ * @param {Number} heigth 高度,单位:像素
+ * @param {Number} quality 质量,1-100的数字,默认100
+ * @param {Number} scaleToFit 是否将图片自适应大小。默认为true。
+ * @param {String} fmt 格式,默认为png,也可以为jpeg,gif等格式。
+ */
+ thumbnailURL: function thumbnailURL(width, height) {
+ var quality = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 100;
+ var scaleToFit = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
+ var fmt = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 'png';
+ var url = this.attributes.url;
+
+ if (!url) {
+ throw new Error('Invalid url.');
+ }
+
+ if (!width || !height || width <= 0 || height <= 0) {
+ throw new Error('Invalid width or height value.');
+ }
+
+ if (quality <= 0 || quality > 100) {
+ throw new Error('Invalid quality value.');
+ }
+
+ var mode = scaleToFit ? 2 : 1;
+ return url + '?imageView/' + mode + '/w/' + width + '/h/' + height + '/q/' + quality + '/format/' + fmt;
+ },
+
+ /**
+ * Returns the file's size.
+ * @return {Number} The file's size in bytes.
+ **/
+ size: function size() {
+ return this.metaData().size;
+ },
+
+ /**
+ * Returns the file's owner.
+ * @return {String} The file's owner id.
+ */
+ ownerId: function ownerId() {
+ return this.metaData().owner;
+ },
+
+ /**
+ * Destroy the file.
+ * @param {AuthOptions} options
+ * @return {Promise} A promise that is fulfilled when the destroy
+ * completes.
+ */
+ destroy: function destroy(options) {
+ if (!this.id) {
+ return _promise.default.reject(new Error('The file id does not eixst.'));
+ }
+
+ var request = AVRequest('files', null, this.id, 'DELETE', null, options);
+ return request;
+ },
+
+ /**
+ * Request Qiniu upload token
+ * @param {string} type
+ * @return {Promise} Resolved with the response
+ * @private
+ */
+ _fileToken: function _fileToken(type, authOptions) {
+ var name = this.attributes.name;
+ var extName = extname(name);
+
+ if (!extName && this._extName) {
+ name += this._extName;
+ extName = this._extName;
+ }
+
+ var data = {
+ name: name,
+ keep_file_name: authOptions.keepFileName,
+ key: authOptions.key,
+ ACL: this._acl,
+ mime_type: type,
+ metaData: this.attributes.metaData
+ };
+ return AVRequest('fileTokens', null, null, 'POST', data, authOptions);
+ },
+
+ /**
+ * @callback UploadProgressCallback
+ * @param {XMLHttpRequestProgressEvent} event - The progress event with 'loaded' and 'total' attributes
+ */
+
+ /**
+ * Saves the file to the AV cloud.
+ * @param {AuthOptions} [options] AuthOptions plus:
+ * @param {UploadProgressCallback} [options.onprogress] 文件上传进度,在 Node.js 中无效,回调参数说明详见 {@link UploadProgressCallback}。
+ * @param {boolean} [options.keepFileName = false] 保留下载文件的文件名。
+ * @param {string} [options.key] 指定文件的 key。设置该选项需要使用 masterKey
+ * @return {Promise} Promise that is resolved when the save finishes.
+ */
+ save: function save() {
+ var _this3 = this;
+
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
+
+ if (this.id) {
+ throw new Error('File is already saved.');
+ }
+
+ if (!this._previousSave) {
+ if (this._data) {
+ var mimeType = this.get('mime_type');
+ this._previousSave = this._fileToken(mimeType, options).then(function (uploadInfo) {
+ if (uploadInfo.mime_type) {
+ mimeType = uploadInfo.mime_type;
+
+ _this3.set('mime_type', mimeType);
+ }
+
+ _this3._token = uploadInfo.token;
+ return _promise.default.resolve().then(function () {
+ var data = _this3._data;
+
+ if (data && data.base64) {
+ return parseBase64(data.base64, mimeType);
+ }
+
+ if (data && data.blob) {
+ if (!data.blob.type && mimeType) {
+ data.blob.type = mimeType;
+ }
+
+ if (!data.blob.name) {
+ data.blob.name = _this3.get('name');
+ }
+
+ return data.blob;
+ }
+
+ if (typeof Blob !== 'undefined' && data instanceof Blob) {
+ return data;
+ }
+
+ throw new TypeError('malformed file data');
+ }).then(function (data) {
+ var _options = _.extend({}, options); // filter out download progress events
+
+
+ if (options.onprogress) {
+ _options.onprogress = function (event) {
+ if (event.direction === 'download') return;
+ return options.onprogress(event);
+ };
+ }
+
+ switch (uploadInfo.provider) {
+ case 's3':
+ return s3(uploadInfo, data, _this3, _options);
+
+ case 'qcloud':
+ return cos(uploadInfo, data, _this3, _options);
+
+ case 'qiniu':
+ default:
+ return qiniu(uploadInfo, data, _this3, _options);
+ }
+ }).then(tap(function () {
+ return _this3._callback(true);
+ }), function (error) {
+ _this3._callback(false);
+
+ throw error;
+ });
+ });
+ } else if (this.attributes.url && this.attributes.metaData.__source === 'external') {
+ // external link file.
+ var data = {
+ name: this.attributes.name,
+ ACL: this._acl,
+ metaData: this.attributes.metaData,
+ mime_type: this.mimeType,
+ url: this.attributes.url
+ };
+ this._previousSave = AVRequest('files', null, null, 'post', data, options).then(function (response) {
+ _this3.id = response.objectId;
+ return _this3;
+ });
+ }
+ }
+
+ return this._previousSave;
+ },
+ _callback: function _callback(success) {
+ AVRequest('fileCallback', null, null, 'post', {
+ token: this._token,
+ result: success
+ }).catch(debug);
+ delete this._token;
+ delete this._data;
+ },
+
+ /**
+ * fetch the file from server. If the server's representation of the
+ * model differs from its current attributes, they will be overriden,
+ * @param {Object} fetchOptions Optional options to set 'keys',
+ * 'include' and 'includeACL' option.
+ * @param {AuthOptions} options
+ * @return {Promise} A promise that is fulfilled when the fetch
+ * completes.
+ */
+ fetch: function fetch(fetchOptions, options) {
+ if (!this.id) {
+ throw new Error('Cannot fetch unsaved file');
+ }
+
+ var request = AVRequest('files', null, this.id, 'GET', transformFetchOptions(fetchOptions), options);
+ return request.then(this._finishFetch.bind(this));
+ },
+ _finishFetch: function _finishFetch(response) {
+ var value = AV.Object.prototype.parse(response);
+ value.attributes = {
+ name: value.name,
+ url: value.url,
+ mime_type: value.mime_type,
+ bucket: value.bucket
+ };
+ value.attributes.metaData = value.metaData || {};
+ value.id = value.objectId; // clean
+
+ delete value.objectId;
+ delete value.metaData;
+ delete value.url;
+ delete value.name;
+ delete value.mime_type;
+ delete value.bucket;
+
+ _.extend(this, value);
+
+ return this;
+ },
+
+ /**
+ * Request file censor
+ * @since 4.13.0
+ * @return {Promise.}
+ */
+ censor: function censor() {
+ if (!this.id) {
+ throw new Error('Cannot censor an unsaved file');
+ }
+
+ return AV.File.censor(this.id);
+ }
+ });
+};
+
+/***/ }),
+/* 446 */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+var _require = __webpack_require__(61),
+ getAdapter = _require.getAdapter;
+
+var debug = __webpack_require__(60)('cos');
+
+module.exports = function (uploadInfo, data, file) {
+ var saveOptions = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
+ var url = uploadInfo.upload_url + '?sign=' + encodeURIComponent(uploadInfo.token);
+ var fileFormData = {
+ field: 'fileContent',
+ data: data,
+ name: file.attributes.name
+ };
+ var options = {
+ headers: file._uploadHeaders,
+ data: {
+ op: 'upload'
+ },
+ onprogress: saveOptions.onprogress
+ };
+ debug('url: %s, file: %o, options: %o', url, fileFormData, options);
+ var upload = getAdapter('upload');
+ return upload(url, fileFormData, options).then(function (response) {
+ debug(response.status, response.data);
+
+ if (response.ok === false) {
+ var error = new Error(response.status);
+ error.response = response;
+ throw error;
+ }
+
+ file.attributes.url = uploadInfo.url;
+ file._bucket = uploadInfo.bucket;
+ file.id = uploadInfo.objectId;
+ return file;
+ }, function (error) {
+ var response = error.response;
+
+ if (response) {
+ debug(response.status, response.data);
+ error.statusCode = response.status;
+ error.response = response.data;
+ }
+
+ throw error;
+ });
+};
+
+/***/ }),
+/* 447 */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+var _sliceInstanceProperty2 = __webpack_require__(81);
+
+var _Array$from = __webpack_require__(448);
+
+var _Symbol = __webpack_require__(453);
+
+var _getIteratorMethod = __webpack_require__(231);
+
+var _Reflect$construct = __webpack_require__(459);
+
+var _interopRequireDefault = __webpack_require__(2);
+
+var _inherits2 = _interopRequireDefault(__webpack_require__(463));
+
+var _possibleConstructorReturn2 = _interopRequireDefault(__webpack_require__(485));
+
+var _getPrototypeOf2 = _interopRequireDefault(__webpack_require__(487));
+
+var _classCallCheck2 = _interopRequireDefault(__webpack_require__(492));
+
+var _createClass2 = _interopRequireDefault(__webpack_require__(493));
+
+var _stringify = _interopRequireDefault(__webpack_require__(34));
+
+var _concat = _interopRequireDefault(__webpack_require__(29));
+
+var _promise = _interopRequireDefault(__webpack_require__(10));
+
+var _slice = _interopRequireDefault(__webpack_require__(81));
+
+function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = _Reflect$construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
+
+function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct) return false; if (_Reflect$construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
+
+function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof _Symbol !== "undefined" && _getIteratorMethod(o) || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
+
+function _unsupportedIterableToArray(o, minLen) { var _context8; if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = _sliceInstanceProperty2(_context8 = Object.prototype.toString.call(o)).call(_context8, 8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return _Array$from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
+
+function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
+
+var _require = __webpack_require__(61),
+ getAdapter = _require.getAdapter;
+
+var debug = __webpack_require__(60)('leancloud:qiniu');
+
+var ajax = __webpack_require__(103);
+
+var btoa = __webpack_require__(494);
+
+var SHARD_THRESHOLD = 1024 * 1024 * 64;
+var CHUNK_SIZE = 1024 * 1024 * 16;
+
+function upload(uploadInfo, data, file) {
+ var saveOptions = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
+ // Get the uptoken to upload files to qiniu.
+ var uptoken = uploadInfo.token;
+ var url = uploadInfo.upload_url || 'https://upload.qiniup.com';
+ var fileFormData = {
+ field: 'file',
+ data: data,
+ name: file.attributes.name
+ };
+ var options = {
+ headers: file._uploadHeaders,
+ data: {
+ name: file.attributes.name,
+ key: uploadInfo.key,
+ token: uptoken
+ },
+ onprogress: saveOptions.onprogress
+ };
+ debug('url: %s, file: %o, options: %o', url, fileFormData, options);
+ var upload = getAdapter('upload');
+ return upload(url, fileFormData, options).then(function (response) {
+ debug(response.status, response.data);
+
+ if (response.ok === false) {
+ var message = response.status;
+
+ if (response.data) {
+ if (response.data.error) {
+ message = response.data.error;
+ } else {
+ message = (0, _stringify.default)(response.data);
+ }
+ }
+
+ var error = new Error(message);
+ error.response = response;
+ throw error;
+ }
+
+ file.attributes.url = uploadInfo.url;
+ file._bucket = uploadInfo.bucket;
+ file.id = uploadInfo.objectId;
+ return file;
+ }, function (error) {
+ var response = error.response;
+
+ if (response) {
+ debug(response.status, response.data);
+ error.statusCode = response.status;
+ error.response = response.data;
+ }
+
+ throw error;
+ });
+}
+
+function urlSafeBase64(string) {
+ var base64 = btoa(unescape(encodeURIComponent(string)));
+ var result = '';
+
+ var _iterator = _createForOfIteratorHelper(base64),
+ _step;
+
+ try {
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
+ var ch = _step.value;
+
+ switch (ch) {
+ case '+':
+ result += '-';
+ break;
+
+ case '/':
+ result += '_';
+ break;
+
+ default:
+ result += ch;
+ }
+ }
+ } catch (err) {
+ _iterator.e(err);
+ } finally {
+ _iterator.f();
+ }
+
+ return result;
+}
+
+var ShardUploader = /*#__PURE__*/function () {
+ function ShardUploader(uploadInfo, data, file, saveOptions) {
+ var _context,
+ _context2,
+ _this = this;
+
+ (0, _classCallCheck2.default)(this, ShardUploader);
+ this.uploadInfo = uploadInfo;
+ this.data = data;
+ this.file = file;
+ this.size = undefined;
+ this.offset = 0;
+ this.uploadedChunks = 0;
+ var key = urlSafeBase64(uploadInfo.key);
+ var uploadURL = uploadInfo.upload_url || 'https://upload.qiniup.com';
+ this.baseURL = (0, _concat.default)(_context = (0, _concat.default)(_context2 = "".concat(uploadURL, "/buckets/")).call(_context2, uploadInfo.bucket, "/objects/")).call(_context, key, "/uploads");
+ this.upToken = 'UpToken ' + uploadInfo.token;
+ this.uploaded = 0;
+
+ if (saveOptions && saveOptions.onprogress) {
+ this.onProgress = function (_ref) {
+ var loaded = _ref.loaded;
+ loaded += _this.uploadedChunks * CHUNK_SIZE;
+
+ if (loaded <= _this.uploaded) {
+ return;
+ }
+
+ if (_this.size) {
+ saveOptions.onprogress({
+ loaded: loaded,
+ total: _this.size,
+ percent: loaded / _this.size * 100
+ });
+ } else {
+ saveOptions.onprogress({
+ loaded: loaded
+ });
+ }
+
+ _this.uploaded = loaded;
+ };
+ }
+ }
+ /**
+ * @returns {Promise}
+ */
+
+
+ (0, _createClass2.default)(ShardUploader, [{
+ key: "getUploadId",
+ value: function getUploadId() {
+ return ajax({
+ method: 'POST',
+ url: this.baseURL,
+ headers: {
+ Authorization: this.upToken
+ }
+ }).then(function (res) {
+ return res.uploadId;
+ });
+ }
+ }, {
+ key: "getChunk",
+ value: function getChunk() {
+ throw new Error('Not implemented');
+ }
+ /**
+ * @param {string} uploadId
+ * @param {number} partNumber
+ * @param {any} data
+ * @returns {Promise<{ partNumber: number, etag: string }>}
+ */
+
+ }, {
+ key: "uploadPart",
+ value: function uploadPart(uploadId, partNumber, data) {
+ var _context3, _context4;
+
+ return ajax({
+ method: 'PUT',
+ url: (0, _concat.default)(_context3 = (0, _concat.default)(_context4 = "".concat(this.baseURL, "/")).call(_context4, uploadId, "/")).call(_context3, partNumber),
+ headers: {
+ Authorization: this.upToken
+ },
+ data: data,
+ onprogress: this.onProgress
+ }).then(function (_ref2) {
+ var etag = _ref2.etag;
+ return {
+ partNumber: partNumber,
+ etag: etag
+ };
+ });
+ }
+ }, {
+ key: "stopUpload",
+ value: function stopUpload(uploadId) {
+ var _context5;
+
+ return ajax({
+ method: 'DELETE',
+ url: (0, _concat.default)(_context5 = "".concat(this.baseURL, "/")).call(_context5, uploadId),
+ headers: {
+ Authorization: this.upToken
+ }
+ });
+ }
+ }, {
+ key: "upload",
+ value: function upload() {
+ var _this2 = this;
+
+ var parts = [];
+ return this.getUploadId().then(function (uploadId) {
+ var uploadPart = function uploadPart() {
+ return _promise.default.resolve(_this2.getChunk()).then(function (chunk) {
+ if (!chunk) {
+ return;
+ }
+
+ var partNumber = parts.length + 1;
+ return _this2.uploadPart(uploadId, partNumber, chunk).then(function (part) {
+ parts.push(part);
+ _this2.uploadedChunks++;
+ return uploadPart();
+ });
+ }).catch(function (error) {
+ return _this2.stopUpload(uploadId).then(function () {
+ return _promise.default.reject(error);
+ });
+ });
+ };
+
+ return uploadPart().then(function () {
+ var _context6;
+
+ return ajax({
+ method: 'POST',
+ url: (0, _concat.default)(_context6 = "".concat(_this2.baseURL, "/")).call(_context6, uploadId),
+ headers: {
+ Authorization: _this2.upToken
+ },
+ data: {
+ parts: parts,
+ fname: _this2.file.attributes.name,
+ mimeType: _this2.file.attributes.mime_type
+ }
+ });
+ });
+ }).then(function () {
+ _this2.file.attributes.url = _this2.uploadInfo.url;
+ _this2.file._bucket = _this2.uploadInfo.bucket;
+ _this2.file.id = _this2.uploadInfo.objectId;
+ return _this2.file;
+ });
+ }
+ }]);
+ return ShardUploader;
+}();
+
+var BlobUploader = /*#__PURE__*/function (_ShardUploader) {
+ (0, _inherits2.default)(BlobUploader, _ShardUploader);
+
+ var _super = _createSuper(BlobUploader);
+
+ function BlobUploader(uploadInfo, data, file, saveOptions) {
+ var _this3;
+
+ (0, _classCallCheck2.default)(this, BlobUploader);
+ _this3 = _super.call(this, uploadInfo, data, file, saveOptions);
+ _this3.size = data.size;
+ return _this3;
+ }
+ /**
+ * @returns {Blob | null}
+ */
+
+
+ (0, _createClass2.default)(BlobUploader, [{
+ key: "getChunk",
+ value: function getChunk() {
+ var _context7;
+
+ if (this.offset >= this.size) {
+ return null;
+ }
+
+ var chunk = (0, _slice.default)(_context7 = this.data).call(_context7, this.offset, this.offset + CHUNK_SIZE);
+ this.offset += chunk.size;
+ return chunk;
+ }
+ }]);
+ return BlobUploader;
+}(ShardUploader);
+
+function isBlob(data) {
+ return typeof Blob !== 'undefined' && data instanceof Blob;
+}
+
+module.exports = function (uploadInfo, data, file) {
+ var saveOptions = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
+
+ if (isBlob(data) && data.size >= SHARD_THRESHOLD) {
+ return new BlobUploader(uploadInfo, data, file, saveOptions).upload();
+ }
+
+ return upload(uploadInfo, data, file, saveOptions);
+};
+
+/***/ }),
+/* 448 */
+/***/ (function(module, exports, __webpack_require__) {
+
+module.exports = __webpack_require__(230);
+
+/***/ }),
+/* 449 */
+/***/ (function(module, exports, __webpack_require__) {
+
+__webpack_require__(95);
+__webpack_require__(450);
+var path = __webpack_require__(13);
+
+module.exports = path.Array.from;
+
+
+/***/ }),
+/* 450 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var $ = __webpack_require__(0);
+var from = __webpack_require__(451);
+var checkCorrectnessOfIteration = __webpack_require__(160);
+
+var INCORRECT_ITERATION = !checkCorrectnessOfIteration(function (iterable) {
+ // eslint-disable-next-line es-x/no-array-from -- required for testing
+ Array.from(iterable);
+});
+
+// `Array.from` method
+// https://tc39.es/ecma262/#sec-array.from
+$({ target: 'Array', stat: true, forced: INCORRECT_ITERATION }, {
+ from: from
+});
+
+
+/***/ }),
+/* 451 */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+var bind = __webpack_require__(50);
+var call = __webpack_require__(11);
+var toObject = __webpack_require__(35);
+var callWithSafeIterationClosing = __webpack_require__(452);
+var isArrayIteratorMethod = __webpack_require__(149);
+var isConstructor = __webpack_require__(93);
+var lengthOfArrayLike = __webpack_require__(42);
+var createProperty = __webpack_require__(99);
+var getIterator = __webpack_require__(150);
+var getIteratorMethod = __webpack_require__(90);
+
+var $Array = Array;
+
+// `Array.from` method implementation
+// https://tc39.es/ecma262/#sec-array.from
+module.exports = function from(arrayLike /* , mapfn = undefined, thisArg = undefined */) {
+ var O = toObject(arrayLike);
+ var IS_CONSTRUCTOR = isConstructor(this);
+ var argumentsLength = arguments.length;
+ var mapfn = argumentsLength > 1 ? arguments[1] : undefined;
+ var mapping = mapfn !== undefined;
+ if (mapping) mapfn = bind(mapfn, argumentsLength > 2 ? arguments[2] : undefined);
+ var iteratorMethod = getIteratorMethod(O);
+ var index = 0;
+ var length, result, step, iterator, next, value;
+ // if the target is not iterable or it's an array with the default iterator - use a simple case
+ if (iteratorMethod && !(this === $Array && isArrayIteratorMethod(iteratorMethod))) {
+ iterator = getIterator(O, iteratorMethod);
+ next = iterator.next;
+ result = IS_CONSTRUCTOR ? new this() : [];
+ for (;!(step = call(next, iterator)).done; index++) {
+ value = mapping ? callWithSafeIterationClosing(iterator, mapfn, [step.value, index], true) : step.value;
+ createProperty(result, index, value);
+ }
+ } else {
+ length = lengthOfArrayLike(O);
+ result = IS_CONSTRUCTOR ? new this(length) : $Array(length);
+ for (;length > index; index++) {
+ value = mapping ? mapfn(O[index], index) : O[index];
+ createProperty(result, index, value);
+ }
+ }
+ result.length = index;
+ return result;
+};
+
+
+/***/ }),
+/* 452 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var anObject = __webpack_require__(21);
+var iteratorClose = __webpack_require__(151);
+
+// call something on iterator step with safe closing on error
+module.exports = function (iterator, fn, value, ENTRIES) {
+ try {
+ return ENTRIES ? fn(anObject(value)[0], value[1]) : fn(value);
+ } catch (error) {
+ iteratorClose(iterator, 'throw', error);
+ }
+};
+
+
+/***/ }),
+/* 453 */
+/***/ (function(module, exports, __webpack_require__) {
+
+module.exports = __webpack_require__(226);
+
+/***/ }),
+/* 454 */
+/***/ (function(module, exports, __webpack_require__) {
+
+module.exports = __webpack_require__(455);
+
+
+/***/ }),
+/* 455 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var parent = __webpack_require__(456);
+
+module.exports = parent;
+
+
+/***/ }),
+/* 456 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var parent = __webpack_require__(457);
+
+module.exports = parent;
+
+
+/***/ }),
+/* 457 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var parent = __webpack_require__(458);
+__webpack_require__(73);
+
+module.exports = parent;
+
+
+/***/ }),
+/* 458 */
+/***/ (function(module, exports, __webpack_require__) {
+
+__webpack_require__(70);
+__webpack_require__(95);
+var getIteratorMethod = __webpack_require__(90);
+
+module.exports = getIteratorMethod;
+
+
+/***/ }),
+/* 459 */
+/***/ (function(module, exports, __webpack_require__) {
+
+module.exports = __webpack_require__(460);
+
+/***/ }),
+/* 460 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var parent = __webpack_require__(461);
+
+module.exports = parent;
+
+
+/***/ }),
+/* 461 */
+/***/ (function(module, exports, __webpack_require__) {
+
+__webpack_require__(462);
+var path = __webpack_require__(13);
+
+module.exports = path.Reflect.construct;
+
+
+/***/ }),
+/* 462 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var $ = __webpack_require__(0);
+var getBuiltIn = __webpack_require__(16);
+var apply = __webpack_require__(62);
+var bind = __webpack_require__(232);
+var aConstructor = __webpack_require__(156);
+var anObject = __webpack_require__(21);
+var isObject = __webpack_require__(17);
+var create = __webpack_require__(51);
+var fails = __webpack_require__(4);
+
+var nativeConstruct = getBuiltIn('Reflect', 'construct');
+var ObjectPrototype = Object.prototype;
+var push = [].push;
+
+// `Reflect.construct` method
+// https://tc39.es/ecma262/#sec-reflect.construct
+// MS Edge supports only 2 arguments and argumentsList argument is optional
+// FF Nightly sets third argument as `new.target`, but does not create `this` from it
+var NEW_TARGET_BUG = fails(function () {
+ function F() { /* empty */ }
+ return !(nativeConstruct(function () { /* empty */ }, [], F) instanceof F);
+});
+
+var ARGS_BUG = !fails(function () {
+ nativeConstruct(function () { /* empty */ });
+});
+
+var FORCED = NEW_TARGET_BUG || ARGS_BUG;
+
+$({ target: 'Reflect', stat: true, forced: FORCED, sham: FORCED }, {
+ construct: function construct(Target, args /* , newTarget */) {
+ aConstructor(Target);
+ anObject(args);
+ var newTarget = arguments.length < 3 ? Target : aConstructor(arguments[2]);
+ if (ARGS_BUG && !NEW_TARGET_BUG) return nativeConstruct(Target, args, newTarget);
+ if (Target == newTarget) {
+ // w/o altered newTarget, optimization for 0-4 arguments
+ switch (args.length) {
+ case 0: return new Target();
+ case 1: return new Target(args[0]);
+ case 2: return new Target(args[0], args[1]);
+ case 3: return new Target(args[0], args[1], args[2]);
+ case 4: return new Target(args[0], args[1], args[2], args[3]);
+ }
+ // w/o altered newTarget, lot of arguments case
+ var $args = [null];
+ apply(push, $args, args);
+ return new (apply(bind, Target, $args))();
+ }
+ // with altered newTarget, not support built-in constructors
+ var proto = newTarget.prototype;
+ var instance = create(isObject(proto) ? proto : ObjectPrototype);
+ var result = apply(Target, instance, args);
+ return isObject(result) ? result : instance;
+ }
+});
+
+
+/***/ }),
+/* 463 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var _Object$create = __webpack_require__(464);
+
+var _Object$defineProperty = __webpack_require__(137);
+
+var setPrototypeOf = __webpack_require__(474);
+
+function _inherits(subClass, superClass) {
+ if (typeof superClass !== "function" && superClass !== null) {
+ throw new TypeError("Super expression must either be null or a function");
+ }
+
+ subClass.prototype = _Object$create(superClass && superClass.prototype, {
+ constructor: {
+ value: subClass,
+ writable: true,
+ configurable: true
+ }
+ });
+
+ _Object$defineProperty(subClass, "prototype", {
+ writable: false
+ });
+
+ if (superClass) setPrototypeOf(subClass, superClass);
+}
+
+module.exports = _inherits, module.exports.__esModule = true, module.exports["default"] = module.exports;
+
+/***/ }),
+/* 464 */
+/***/ (function(module, exports, __webpack_require__) {
+
+module.exports = __webpack_require__(465);
+
+/***/ }),
+/* 465 */
+/***/ (function(module, exports, __webpack_require__) {
+
+module.exports = __webpack_require__(466);
+
+
+/***/ }),
+/* 466 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var parent = __webpack_require__(467);
+
+module.exports = parent;
+
+
+/***/ }),
+/* 467 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var parent = __webpack_require__(468);
+
+module.exports = parent;
+
+
+/***/ }),
+/* 468 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var parent = __webpack_require__(469);
+
+module.exports = parent;
+
+
+/***/ }),
+/* 469 */
+/***/ (function(module, exports, __webpack_require__) {
+
+__webpack_require__(470);
+var path = __webpack_require__(13);
+
+var Object = path.Object;
+
+module.exports = function create(P, D) {
+ return Object.create(P, D);
+};
+
+
+/***/ }),
+/* 470 */
+/***/ (function(module, exports, __webpack_require__) {
+
+// TODO: Remove from `core-js@4`
+var $ = __webpack_require__(0);
+var DESCRIPTORS = __webpack_require__(19);
+var create = __webpack_require__(51);
+
+// `Object.create` method
+// https://tc39.es/ecma262/#sec-object.create
+$({ target: 'Object', stat: true, sham: !DESCRIPTORS }, {
+ create: create
+});
+
+
+/***/ }),
+/* 471 */
+/***/ (function(module, exports, __webpack_require__) {
+
+module.exports = __webpack_require__(472);
+
+
+/***/ }),
+/* 472 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var parent = __webpack_require__(473);
+
+module.exports = parent;
+
+
+/***/ }),
+/* 473 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var parent = __webpack_require__(224);
+
+module.exports = parent;
+
+
+/***/ }),
+/* 474 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var _Object$setPrototypeOf = __webpack_require__(233);
+
+var _bindInstanceProperty = __webpack_require__(234);
+
+function _setPrototypeOf(o, p) {
+ var _context;
+
+ module.exports = _setPrototypeOf = _Object$setPrototypeOf ? _bindInstanceProperty(_context = _Object$setPrototypeOf).call(_context) : function _setPrototypeOf(o, p) {
+ o.__proto__ = p;
+ return o;
+ }, module.exports.__esModule = true, module.exports["default"] = module.exports;
+ return _setPrototypeOf(o, p);
+}
+
+module.exports = _setPrototypeOf, module.exports.__esModule = true, module.exports["default"] = module.exports;
+
+/***/ }),
+/* 475 */
+/***/ (function(module, exports, __webpack_require__) {
+
+module.exports = __webpack_require__(476);
+
+
+/***/ }),
+/* 476 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var parent = __webpack_require__(477);
+
+module.exports = parent;
+
+
+/***/ }),
+/* 477 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var parent = __webpack_require__(221);
+
+module.exports = parent;
+
+
+/***/ }),
+/* 478 */
+/***/ (function(module, exports, __webpack_require__) {
+
+module.exports = __webpack_require__(479);
+
+
+/***/ }),
+/* 479 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var parent = __webpack_require__(480);
+
+module.exports = parent;
+
+
+/***/ }),
+/* 480 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var parent = __webpack_require__(481);
+
+module.exports = parent;
+
+
+/***/ }),
+/* 481 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var parent = __webpack_require__(482);
+
+module.exports = parent;
+
+
+/***/ }),
+/* 482 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var isPrototypeOf = __webpack_require__(20);
+var method = __webpack_require__(483);
+
+var FunctionPrototype = Function.prototype;
+
+module.exports = function (it) {
+ var own = it.bind;
+ return it === FunctionPrototype || (isPrototypeOf(FunctionPrototype, it) && own === FunctionPrototype.bind) ? method : own;
+};
+
+
+/***/ }),
+/* 483 */
+/***/ (function(module, exports, __webpack_require__) {
+
+__webpack_require__(484);
+var entryVirtual = __webpack_require__(38);
+
+module.exports = entryVirtual('Function').bind;
+
+
+/***/ }),
+/* 484 */
+/***/ (function(module, exports, __webpack_require__) {
+
+// TODO: Remove from `core-js@4`
+var $ = __webpack_require__(0);
+var bind = __webpack_require__(232);
+
+// `Function.prototype.bind` method
+// https://tc39.es/ecma262/#sec-function.prototype.bind
+$({ target: 'Function', proto: true, forced: Function.bind !== bind }, {
+ bind: bind
+});
+
+
+/***/ }),
+/* 485 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var _typeof = __webpack_require__(135)["default"];
+
+var assertThisInitialized = __webpack_require__(486);
+
+function _possibleConstructorReturn(self, call) {
+ if (call && (_typeof(call) === "object" || typeof call === "function")) {
+ return call;
+ } else if (call !== void 0) {
+ throw new TypeError("Derived constructors may only return object or undefined");
+ }
+
+ return assertThisInitialized(self);
+}
+
+module.exports = _possibleConstructorReturn, module.exports.__esModule = true, module.exports["default"] = module.exports;
+
+/***/ }),
+/* 486 */
+/***/ (function(module, exports) {
+
+function _assertThisInitialized(self) {
+ if (self === void 0) {
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
+ }
+
+ return self;
+}
+
+module.exports = _assertThisInitialized, module.exports.__esModule = true, module.exports["default"] = module.exports;
+
+/***/ }),
+/* 487 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var _Object$setPrototypeOf = __webpack_require__(233);
+
+var _bindInstanceProperty = __webpack_require__(234);
+
+var _Object$getPrototypeOf = __webpack_require__(488);
+
+function _getPrototypeOf(o) {
+ var _context;
+
+ module.exports = _getPrototypeOf = _Object$setPrototypeOf ? _bindInstanceProperty(_context = _Object$getPrototypeOf).call(_context) : function _getPrototypeOf(o) {
+ return o.__proto__ || _Object$getPrototypeOf(o);
+ }, module.exports.__esModule = true, module.exports["default"] = module.exports;
+ return _getPrototypeOf(o);
+}
+
+module.exports = _getPrototypeOf, module.exports.__esModule = true, module.exports["default"] = module.exports;
+
+/***/ }),
+/* 488 */
+/***/ (function(module, exports, __webpack_require__) {
+
+module.exports = __webpack_require__(489);
+
+/***/ }),
+/* 489 */
+/***/ (function(module, exports, __webpack_require__) {
+
+module.exports = __webpack_require__(490);
+
+
+/***/ }),
+/* 490 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var parent = __webpack_require__(491);
+
+module.exports = parent;
+
+
+/***/ }),
+/* 491 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var parent = __webpack_require__(216);
+
+module.exports = parent;
+
+
+/***/ }),
+/* 492 */
+/***/ (function(module, exports) {
+
+function _classCallCheck(instance, Constructor) {
+ if (!(instance instanceof Constructor)) {
+ throw new TypeError("Cannot call a class as a function");
+ }
+}
+
+module.exports = _classCallCheck, module.exports.__esModule = true, module.exports["default"] = module.exports;
+
+/***/ }),
+/* 493 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var _Object$defineProperty = __webpack_require__(137);
+
+function _defineProperties(target, props) {
+ for (var i = 0; i < props.length; i++) {
+ var descriptor = props[i];
+ descriptor.enumerable = descriptor.enumerable || false;
+ descriptor.configurable = true;
+ if ("value" in descriptor) descriptor.writable = true;
+
+ _Object$defineProperty(target, descriptor.key, descriptor);
+ }
+}
+
+function _createClass(Constructor, protoProps, staticProps) {
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
+ if (staticProps) _defineProperties(Constructor, staticProps);
+
+ _Object$defineProperty(Constructor, "prototype", {
+ writable: false
+ });
+
+ return Constructor;
+}
+
+module.exports = _createClass, module.exports.__esModule = true, module.exports["default"] = module.exports;
+
+/***/ }),
+/* 494 */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+var _interopRequireDefault = __webpack_require__(2);
+
+var _slice = _interopRequireDefault(__webpack_require__(81));
+
+// base64 character set, plus padding character (=)
+var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
+
+module.exports = function (string) {
+ var result = '';
+
+ for (var i = 0; i < string.length;) {
+ var a = string.charCodeAt(i++);
+ var b = string.charCodeAt(i++);
+ var c = string.charCodeAt(i++);
+
+ if (a > 255 || b > 255 || c > 255) {
+ throw new TypeError('Failed to encode base64: The string to be encoded contains characters outside of the Latin1 range.');
+ }
+
+ var bitmap = a << 16 | b << 8 | c;
+ result += b64.charAt(bitmap >> 18 & 63) + b64.charAt(bitmap >> 12 & 63) + b64.charAt(bitmap >> 6 & 63) + b64.charAt(bitmap & 63);
+ } // To determine the final padding
+
+
+ var rest = string.length % 3; // If there's need of padding, replace the last 'A's with equal signs
+
+ return rest ? (0, _slice.default)(result).call(result, 0, rest - 3) + '==='.substring(rest) : result;
+};
+
+/***/ }),
+/* 495 */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+var _ = __webpack_require__(1);
+
+var ajax = __webpack_require__(103);
+
+module.exports = function upload(uploadInfo, data, file) {
+ var saveOptions = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
+ return ajax({
+ url: uploadInfo.upload_url,
+ method: 'PUT',
+ data: data,
+ headers: _.extend({
+ 'Content-Type': file.get('mime_type'),
+ 'Cache-Control': 'public, max-age=31536000'
+ }, file._uploadHeaders),
+ onprogress: saveOptions.onprogress
+ }).then(function () {
+ file.attributes.url = uploadInfo.url;
+ file._bucket = uploadInfo.bucket;
+ file.id = uploadInfo.objectId;
+ return file;
+ });
+};
+
+/***/ }),
+/* 496 */
+/***/ (function(module, exports, __webpack_require__) {
+
+(function(){
+ var crypt = __webpack_require__(497),
+ utf8 = __webpack_require__(235).utf8,
+ isBuffer = __webpack_require__(498),
+ bin = __webpack_require__(235).bin,
+
+ // The core
+ md5 = function (message, options) {
+ // Convert to byte array
+ if (message.constructor == String)
+ if (options && options.encoding === 'binary')
+ message = bin.stringToBytes(message);
+ else
+ message = utf8.stringToBytes(message);
+ else if (isBuffer(message))
+ message = Array.prototype.slice.call(message, 0);
+ else if (!Array.isArray(message))
+ message = message.toString();
+ // else, assume byte array already
+
+ var m = crypt.bytesToWords(message),
+ l = message.length * 8,
+ a = 1732584193,
+ b = -271733879,
+ c = -1732584194,
+ d = 271733878;
+
+ // Swap endian
+ for (var i = 0; i < m.length; i++) {
+ m[i] = ((m[i] << 8) | (m[i] >>> 24)) & 0x00FF00FF |
+ ((m[i] << 24) | (m[i] >>> 8)) & 0xFF00FF00;
+ }
+
+ // Padding
+ m[l >>> 5] |= 0x80 << (l % 32);
+ m[(((l + 64) >>> 9) << 4) + 14] = l;
+
+ // Method shortcuts
+ var FF = md5._ff,
+ GG = md5._gg,
+ HH = md5._hh,
+ II = md5._ii;
+
+ for (var i = 0; i < m.length; i += 16) {
+
+ var aa = a,
+ bb = b,
+ cc = c,
+ dd = d;
+
+ a = FF(a, b, c, d, m[i+ 0], 7, -680876936);
+ d = FF(d, a, b, c, m[i+ 1], 12, -389564586);
+ c = FF(c, d, a, b, m[i+ 2], 17, 606105819);
+ b = FF(b, c, d, a, m[i+ 3], 22, -1044525330);
+ a = FF(a, b, c, d, m[i+ 4], 7, -176418897);
+ d = FF(d, a, b, c, m[i+ 5], 12, 1200080426);
+ c = FF(c, d, a, b, m[i+ 6], 17, -1473231341);
+ b = FF(b, c, d, a, m[i+ 7], 22, -45705983);
+ a = FF(a, b, c, d, m[i+ 8], 7, 1770035416);
+ d = FF(d, a, b, c, m[i+ 9], 12, -1958414417);
+ c = FF(c, d, a, b, m[i+10], 17, -42063);
+ b = FF(b, c, d, a, m[i+11], 22, -1990404162);
+ a = FF(a, b, c, d, m[i+12], 7, 1804603682);
+ d = FF(d, a, b, c, m[i+13], 12, -40341101);
+ c = FF(c, d, a, b, m[i+14], 17, -1502002290);
+ b = FF(b, c, d, a, m[i+15], 22, 1236535329);
+
+ a = GG(a, b, c, d, m[i+ 1], 5, -165796510);
+ d = GG(d, a, b, c, m[i+ 6], 9, -1069501632);
+ c = GG(c, d, a, b, m[i+11], 14, 643717713);
+ b = GG(b, c, d, a, m[i+ 0], 20, -373897302);
+ a = GG(a, b, c, d, m[i+ 5], 5, -701558691);
+ d = GG(d, a, b, c, m[i+10], 9, 38016083);
+ c = GG(c, d, a, b, m[i+15], 14, -660478335);
+ b = GG(b, c, d, a, m[i+ 4], 20, -405537848);
+ a = GG(a, b, c, d, m[i+ 9], 5, 568446438);
+ d = GG(d, a, b, c, m[i+14], 9, -1019803690);
+ c = GG(c, d, a, b, m[i+ 3], 14, -187363961);
+ b = GG(b, c, d, a, m[i+ 8], 20, 1163531501);
+ a = GG(a, b, c, d, m[i+13], 5, -1444681467);
+ d = GG(d, a, b, c, m[i+ 2], 9, -51403784);
+ c = GG(c, d, a, b, m[i+ 7], 14, 1735328473);
+ b = GG(b, c, d, a, m[i+12], 20, -1926607734);
+
+ a = HH(a, b, c, d, m[i+ 5], 4, -378558);
+ d = HH(d, a, b, c, m[i+ 8], 11, -2022574463);
+ c = HH(c, d, a, b, m[i+11], 16, 1839030562);
+ b = HH(b, c, d, a, m[i+14], 23, -35309556);
+ a = HH(a, b, c, d, m[i+ 1], 4, -1530992060);
+ d = HH(d, a, b, c, m[i+ 4], 11, 1272893353);
+ c = HH(c, d, a, b, m[i+ 7], 16, -155497632);
+ b = HH(b, c, d, a, m[i+10], 23, -1094730640);
+ a = HH(a, b, c, d, m[i+13], 4, 681279174);
+ d = HH(d, a, b, c, m[i+ 0], 11, -358537222);
+ c = HH(c, d, a, b, m[i+ 3], 16, -722521979);
+ b = HH(b, c, d, a, m[i+ 6], 23, 76029189);
+ a = HH(a, b, c, d, m[i+ 9], 4, -640364487);
+ d = HH(d, a, b, c, m[i+12], 11, -421815835);
+ c = HH(c, d, a, b, m[i+15], 16, 530742520);
+ b = HH(b, c, d, a, m[i+ 2], 23, -995338651);
+
+ a = II(a, b, c, d, m[i+ 0], 6, -198630844);
+ d = II(d, a, b, c, m[i+ 7], 10, 1126891415);
+ c = II(c, d, a, b, m[i+14], 15, -1416354905);
+ b = II(b, c, d, a, m[i+ 5], 21, -57434055);
+ a = II(a, b, c, d, m[i+12], 6, 1700485571);
+ d = II(d, a, b, c, m[i+ 3], 10, -1894986606);
+ c = II(c, d, a, b, m[i+10], 15, -1051523);
+ b = II(b, c, d, a, m[i+ 1], 21, -2054922799);
+ a = II(a, b, c, d, m[i+ 8], 6, 1873313359);
+ d = II(d, a, b, c, m[i+15], 10, -30611744);
+ c = II(c, d, a, b, m[i+ 6], 15, -1560198380);
+ b = II(b, c, d, a, m[i+13], 21, 1309151649);
+ a = II(a, b, c, d, m[i+ 4], 6, -145523070);
+ d = II(d, a, b, c, m[i+11], 10, -1120210379);
+ c = II(c, d, a, b, m[i+ 2], 15, 718787259);
+ b = II(b, c, d, a, m[i+ 9], 21, -343485551);
+
+ a = (a + aa) >>> 0;
+ b = (b + bb) >>> 0;
+ c = (c + cc) >>> 0;
+ d = (d + dd) >>> 0;
+ }
+
+ return crypt.endian([a, b, c, d]);
+ };
+
+ // Auxiliary functions
+ md5._ff = function (a, b, c, d, x, s, t) {
+ var n = a + (b & c | ~b & d) + (x >>> 0) + t;
+ return ((n << s) | (n >>> (32 - s))) + b;
+ };
+ md5._gg = function (a, b, c, d, x, s, t) {
+ var n = a + (b & d | c & ~d) + (x >>> 0) + t;
+ return ((n << s) | (n >>> (32 - s))) + b;
+ };
+ md5._hh = function (a, b, c, d, x, s, t) {
+ var n = a + (b ^ c ^ d) + (x >>> 0) + t;
+ return ((n << s) | (n >>> (32 - s))) + b;
+ };
+ md5._ii = function (a, b, c, d, x, s, t) {
+ var n = a + (c ^ (b | ~d)) + (x >>> 0) + t;
+ return ((n << s) | (n >>> (32 - s))) + b;
+ };
+
+ // Package private blocksize
+ md5._blocksize = 16;
+ md5._digestsize = 16;
+
+ module.exports = function (message, options) {
+ if (message === undefined || message === null)
+ throw new Error('Illegal argument ' + message);
+
+ var digestbytes = crypt.wordsToBytes(md5(message, options));
+ return options && options.asBytes ? digestbytes :
+ options && options.asString ? bin.bytesToString(digestbytes) :
+ crypt.bytesToHex(digestbytes);
+ };
+
+})();
+
+
+/***/ }),
+/* 497 */
+/***/ (function(module, exports) {
+
+(function() {
+ var base64map
+ = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
+
+ crypt = {
+ // Bit-wise rotation left
+ rotl: function(n, b) {
+ return (n << b) | (n >>> (32 - b));
+ },
+
+ // Bit-wise rotation right
+ rotr: function(n, b) {
+ return (n << (32 - b)) | (n >>> b);
+ },
+
+ // Swap big-endian to little-endian and vice versa
+ endian: function(n) {
+ // If number given, swap endian
+ if (n.constructor == Number) {
+ return crypt.rotl(n, 8) & 0x00FF00FF | crypt.rotl(n, 24) & 0xFF00FF00;
+ }
+
+ // Else, assume array and swap all items
+ for (var i = 0; i < n.length; i++)
+ n[i] = crypt.endian(n[i]);
+ return n;
+ },
+
+ // Generate an array of any length of random bytes
+ randomBytes: function(n) {
+ for (var bytes = []; n > 0; n--)
+ bytes.push(Math.floor(Math.random() * 256));
+ return bytes;
+ },
+
+ // Convert a byte array to big-endian 32-bit words
+ bytesToWords: function(bytes) {
+ for (var words = [], i = 0, b = 0; i < bytes.length; i++, b += 8)
+ words[b >>> 5] |= bytes[i] << (24 - b % 32);
+ return words;
+ },
+
+ // Convert big-endian 32-bit words to a byte array
+ wordsToBytes: function(words) {
+ for (var bytes = [], b = 0; b < words.length * 32; b += 8)
+ bytes.push((words[b >>> 5] >>> (24 - b % 32)) & 0xFF);
+ return bytes;
+ },
+
+ // Convert a byte array to a hex string
+ bytesToHex: function(bytes) {
+ for (var hex = [], i = 0; i < bytes.length; i++) {
+ hex.push((bytes[i] >>> 4).toString(16));
+ hex.push((bytes[i] & 0xF).toString(16));
+ }
+ return hex.join('');
+ },
+
+ // Convert a hex string to a byte array
+ hexToBytes: function(hex) {
+ for (var bytes = [], c = 0; c < hex.length; c += 2)
+ bytes.push(parseInt(hex.substr(c, 2), 16));
+ return bytes;
+ },
+
+ // Convert a byte array to a base-64 string
+ bytesToBase64: function(bytes) {
+ for (var base64 = [], i = 0; i < bytes.length; i += 3) {
+ var triplet = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2];
+ for (var j = 0; j < 4; j++)
+ if (i * 8 + j * 6 <= bytes.length * 8)
+ base64.push(base64map.charAt((triplet >>> 6 * (3 - j)) & 0x3F));
+ else
+ base64.push('=');
+ }
+ return base64.join('');
+ },
+
+ // Convert a base-64 string to a byte array
+ base64ToBytes: function(base64) {
+ // Remove non-base-64 characters
+ base64 = base64.replace(/[^A-Z0-9+\/]/ig, '');
+
+ for (var bytes = [], i = 0, imod4 = 0; i < base64.length;
+ imod4 = ++i % 4) {
+ if (imod4 == 0) continue;
+ bytes.push(((base64map.indexOf(base64.charAt(i - 1))
+ & (Math.pow(2, -2 * imod4 + 8) - 1)) << (imod4 * 2))
+ | (base64map.indexOf(base64.charAt(i)) >>> (6 - imod4 * 2)));
+ }
+ return bytes;
+ }
+ };
+
+ module.exports = crypt;
+})();
+
+
+/***/ }),
+/* 498 */
+/***/ (function(module, exports) {
+
+/*!
+ * Determine if an object is a Buffer
+ *
+ * @author Feross Aboukhadijeh
+ * @license MIT
+ */
+
+// The _isBuffer check is for Safari 5-7 support, because it's missing
+// Object.prototype.constructor. Remove this eventually
+module.exports = function (obj) {
+ return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer)
+}
+
+function isBuffer (obj) {
+ return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
+}
+
+// For Node v0.10 support. Remove this eventually.
+function isSlowBuffer (obj) {
+ return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0))
+}
+
+
+/***/ }),
+/* 499 */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+var _interopRequireDefault = __webpack_require__(2);
+
+var _indexOf = _interopRequireDefault(__webpack_require__(102));
+
+var dataURItoBlob = function dataURItoBlob(dataURI, type) {
+ var _context;
+
+ var byteString; // 传入的 base64,不是 dataURL
+
+ if ((0, _indexOf.default)(dataURI).call(dataURI, 'base64') < 0) {
+ byteString = atob(dataURI);
+ } else if ((0, _indexOf.default)(_context = dataURI.split(',')[0]).call(_context, 'base64') >= 0) {
+ type = type || dataURI.split(',')[0].split(':')[1].split(';')[0];
+ byteString = atob(dataURI.split(',')[1]);
+ } else {
+ byteString = unescape(dataURI.split(',')[1]);
+ }
+
+ var ia = new Uint8Array(byteString.length);
+
+ for (var i = 0; i < byteString.length; i++) {
+ ia[i] = byteString.charCodeAt(i);
+ }
+
+ return new Blob([ia], {
+ type: type
+ });
+};
+
+module.exports = dataURItoBlob;
+
+/***/ }),
+/* 500 */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+var _interopRequireDefault = __webpack_require__(2);
+
+var _slicedToArray2 = _interopRequireDefault(__webpack_require__(501));
+
+var _map = _interopRequireDefault(__webpack_require__(39));
+
+var _indexOf = _interopRequireDefault(__webpack_require__(102));
+
+var _find = _interopRequireDefault(__webpack_require__(104));
+
+var _promise = _interopRequireDefault(__webpack_require__(10));
+
+var _concat = _interopRequireDefault(__webpack_require__(29));
+
+var _keys2 = _interopRequireDefault(__webpack_require__(48));
+
+var _stringify = _interopRequireDefault(__webpack_require__(34));
+
+var _defineProperty = _interopRequireDefault(__webpack_require__(223));
+
+var _getOwnPropertyDescriptor = _interopRequireDefault(__webpack_require__(522));
+
+var _ = __webpack_require__(1);
+
+var AVError = __webpack_require__(40);
+
+var _require = __webpack_require__(25),
+ _request = _require._request;
+
+var _require2 = __webpack_require__(28),
+ isNullOrUndefined = _require2.isNullOrUndefined,
+ ensureArray = _require2.ensureArray,
+ transformFetchOptions = _require2.transformFetchOptions,
+ setValue = _require2.setValue,
+ findValue = _require2.findValue,
+ isPlainObject = _require2.isPlainObject,
+ continueWhile = _require2.continueWhile;
+
+var recursiveToPointer = function recursiveToPointer(value) {
+ if (_.isArray(value)) return (0, _map.default)(value).call(value, recursiveToPointer);
+ if (isPlainObject(value)) return _.mapObject(value, recursiveToPointer);
+ if (_.isObject(value) && value._toPointer) return value._toPointer();
+ return value;
+};
+
+var RESERVED_KEYS = ['objectId', 'createdAt', 'updatedAt'];
+
+var checkReservedKey = function checkReservedKey(key) {
+ if ((0, _indexOf.default)(RESERVED_KEYS).call(RESERVED_KEYS, key) !== -1) {
+ throw new Error("key[".concat(key, "] is reserved"));
+ }
+};
+
+var handleBatchResults = function handleBatchResults(results) {
+ var firstError = (0, _find.default)(_).call(_, results, function (result) {
+ return result instanceof Error;
+ });
+
+ if (!firstError) {
+ return results;
+ }
+
+ var error = new AVError(firstError.code, firstError.message);
+ error.results = results;
+ throw error;
+}; // Helper function to get a value from a Backbone object as a property
+// or as a function.
+
+
+function getValue(object, prop) {
+ if (!(object && object[prop])) {
+ return null;
+ }
+
+ return _.isFunction(object[prop]) ? object[prop]() : object[prop];
+} // AV.Object is analogous to the Java AVObject.
+// It also implements the same interface as a Backbone model.
+
+
+module.exports = function (AV) {
+ /**
+ * Creates a new model with defined attributes. A client id (cid) is
+ * automatically generated and assigned for you.
+ *
+ *
You won't normally call this method directly. It is recommended that
+ * you use a subclass of AV.Object instead, created by calling
+ * extend.
+ *
+ *
However, if you don't want to use a subclass, or aren't sure which
+ * subclass is appropriate, you can use this form:
+ * var object = new AV.Object("ClassName");
+ *
+ * That is basically equivalent to:
+ * var MyClass = AV.Object.extend("ClassName");
+ * var object = new MyClass();
+ *
+ *
+ * @param {Object} attributes The initial set of data to store in the object.
+ * @param {Object} options A set of Backbone-like options for creating the
+ * object. The only option currently supported is "collection".
+ * @see AV.Object.extend
+ *
+ * @class
+ *
+ *
The fundamental unit of AV data, which implements the Backbone Model
+ * interface.
+ */
+ AV.Object = function (attributes, options) {
+ // Allow new AV.Object("ClassName") as a shortcut to _create.
+ if (_.isString(attributes)) {
+ return AV.Object._create.apply(this, arguments);
+ }
+
+ attributes = attributes || {};
+
+ if (options && options.parse) {
+ attributes = this.parse(attributes);
+ attributes = this._mergeMagicFields(attributes);
+ }
+
+ var defaults = getValue(this, 'defaults');
+
+ if (defaults) {
+ attributes = _.extend({}, defaults, attributes);
+ }
+
+ if (options && options.collection) {
+ this.collection = options.collection;
+ }
+
+ this._serverData = {}; // The last known data for this object from cloud.
+
+ this._opSetQueue = [{}]; // List of sets of changes to the data.
+
+ this._flags = {};
+ this.attributes = {}; // The best estimate of this's current data.
+
+ this._hashedJSON = {}; // Hash of values of containers at last save.
+
+ this._escapedAttributes = {};
+ this.cid = _.uniqueId('c');
+ this.changed = {};
+ this._silent = {};
+ this._pending = {};
+ this.set(attributes, {
+ silent: true
+ });
+ this.changed = {};
+ this._silent = {};
+ this._pending = {};
+ this._hasData = true;
+ this._previousAttributes = _.clone(this.attributes);
+ this.initialize.apply(this, arguments);
+ };
+ /**
+ * @lends AV.Object.prototype
+ * @property {String} id The objectId of the AV Object.
+ */
+
+ /**
+ * Saves the given list of AV.Object.
+ * If any error is encountered, stops and calls the error handler.
+ *
+ * @example
+ * AV.Object.saveAll([object1, object2, ...]).then(function(list) {
+ * // All the objects were saved.
+ * }, function(error) {
+ * // An error occurred while saving one of the objects.
+ * });
+ *
+ * @param {Array} list A list of AV.Object.
+ */
+
+
+ AV.Object.saveAll = function (list, options) {
+ return AV.Object._deepSaveAsync(list, null, options);
+ };
+ /**
+ * Fetch the given list of AV.Object.
+ *
+ * @param {AV.Object[]} objects A list of AV.Object
+ * @param {AuthOptions} options
+ * @return {Promise.} The given list of AV.Object, updated
+ */
+
+
+ AV.Object.fetchAll = function (objects, options) {
+ return _promise.default.resolve().then(function () {
+ return _request('batch', null, null, 'POST', {
+ requests: (0, _map.default)(_).call(_, objects, function (object) {
+ var _context;
+
+ if (!object.className) throw new Error('object must have className to fetch');
+ if (!object.id) throw new Error('object must have id to fetch');
+ if (object.dirty()) throw new Error('object is modified but not saved');
+ return {
+ method: 'GET',
+ path: (0, _concat.default)(_context = "/1.1/classes/".concat(object.className, "/")).call(_context, object.id)
+ };
+ })
+ }, options);
+ }).then(function (response) {
+ var results = (0, _map.default)(_).call(_, objects, function (object, i) {
+ if (response[i].success) {
+ var fetchedAttrs = object.parse(response[i].success);
+
+ object._cleanupUnsetKeys(fetchedAttrs);
+
+ object._finishFetch(fetchedAttrs);
+
+ return object;
+ }
+
+ if (response[i].success === null) {
+ return new AVError(AVError.OBJECT_NOT_FOUND, 'Object not found.');
+ }
+
+ return new AVError(response[i].error.code, response[i].error.error);
+ });
+ return handleBatchResults(results);
+ });
+ }; // Attach all inheritable methods to the AV.Object prototype.
+
+
+ _.extend(AV.Object.prototype, AV.Events,
+ /** @lends AV.Object.prototype */
+ {
+ _fetchWhenSave: false,
+
+ /**
+ * Initialize is an empty function by default. Override it with your own
+ * initialization logic.
+ */
+ initialize: function initialize() {},
+
+ /**
+ * Set whether to enable fetchWhenSave option when updating object.
+ * When set true, SDK would fetch the latest object after saving.
+ * Default is false.
+ *
+ * @deprecated use AV.Object#save with options.fetchWhenSave instead
+ * @param {boolean} enable true to enable fetchWhenSave option.
+ */
+ fetchWhenSave: function fetchWhenSave(enable) {
+ console.warn('AV.Object#fetchWhenSave is deprecated, use AV.Object#save with options.fetchWhenSave instead.');
+
+ if (!_.isBoolean(enable)) {
+ throw new Error('Expect boolean value for fetchWhenSave');
+ }
+
+ this._fetchWhenSave = enable;
+ },
+
+ /**
+ * Returns the object's objectId.
+ * @return {String} the objectId.
+ */
+ getObjectId: function getObjectId() {
+ return this.id;
+ },
+
+ /**
+ * Returns the object's createdAt attribute.
+ * @return {Date}
+ */
+ getCreatedAt: function getCreatedAt() {
+ return this.createdAt;
+ },
+
+ /**
+ * Returns the object's updatedAt attribute.
+ * @return {Date}
+ */
+ getUpdatedAt: function getUpdatedAt() {
+ return this.updatedAt;
+ },
+
+ /**
+ * Returns a JSON version of the object.
+ * @return {Object}
+ */
+ toJSON: function toJSON(key, holder) {
+ var seenObjects = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
+ return this._toFullJSON(seenObjects, false);
+ },
+
+ /**
+ * Returns a JSON version of the object with meta data.
+ * Inverse to {@link AV.parseJSON}
+ * @since 3.0.0
+ * @return {Object}
+ */
+ toFullJSON: function toFullJSON() {
+ var seenObjects = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
+ return this._toFullJSON(seenObjects);
+ },
+ _toFullJSON: function _toFullJSON(seenObjects) {
+ var _this = this;
+
+ var full = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
+
+ var json = _.clone(this.attributes);
+
+ if (_.isArray(seenObjects)) {
+ var newSeenObjects = (0, _concat.default)(seenObjects).call(seenObjects, this);
+ }
+
+ AV._objectEach(json, function (val, key) {
+ json[key] = AV._encode(val, newSeenObjects, undefined, full);
+ });
+
+ AV._objectEach(this._operations, function (val, key) {
+ json[key] = val;
+ });
+
+ if (_.has(this, 'id')) {
+ json.objectId = this.id;
+ }
+
+ ['createdAt', 'updatedAt'].forEach(function (key) {
+ if (_.has(_this, key)) {
+ var val = _this[key];
+ json[key] = _.isDate(val) ? val.toJSON() : val;
+ }
+ });
+
+ if (full) {
+ json.__type = 'Object';
+ if (_.isArray(seenObjects) && seenObjects.length) json.__type = 'Pointer';
+ json.className = this.className;
+ }
+
+ return json;
+ },
+
+ /**
+ * Updates _hashedJSON to reflect the current state of this object.
+ * Adds any changed hash values to the set of pending changes.
+ * @private
+ */
+ _refreshCache: function _refreshCache() {
+ var self = this;
+
+ if (self._refreshingCache) {
+ return;
+ }
+
+ self._refreshingCache = true;
+
+ AV._objectEach(this.attributes, function (value, key) {
+ if (value instanceof AV.Object) {
+ value._refreshCache();
+ } else if (_.isObject(value)) {
+ if (self._resetCacheForKey(key)) {
+ self.set(key, new AV.Op.Set(value), {
+ silent: true
+ });
+ }
+ }
+ });
+
+ delete self._refreshingCache;
+ },
+
+ /**
+ * Returns true if this object has been modified since its last
+ * save/refresh. If an attribute is specified, it returns true only if that
+ * particular attribute has been modified since the last save/refresh.
+ * @param {String} attr An attribute name (optional).
+ * @return {Boolean}
+ */
+ dirty: function dirty(attr) {
+ this._refreshCache();
+
+ var currentChanges = _.last(this._opSetQueue);
+
+ if (attr) {
+ return currentChanges[attr] ? true : false;
+ }
+
+ if (!this.id) {
+ return true;
+ }
+
+ if ((0, _keys2.default)(_).call(_, currentChanges).length > 0) {
+ return true;
+ }
+
+ return false;
+ },
+
+ /**
+ * Returns the keys of the modified attribute since its last save/refresh.
+ * @return {String[]}
+ */
+ dirtyKeys: function dirtyKeys() {
+ this._refreshCache();
+
+ var currentChanges = _.last(this._opSetQueue);
+
+ return (0, _keys2.default)(_).call(_, currentChanges);
+ },
+
+ /**
+ * Gets a Pointer referencing this Object.
+ * @private
+ */
+ _toPointer: function _toPointer() {
+ // if (!this.id) {
+ // throw new Error("Can't serialize an unsaved AV.Object");
+ // }
+ return {
+ __type: 'Pointer',
+ className: this.className,
+ objectId: this.id
+ };
+ },
+
+ /**
+ * Gets the value of an attribute.
+ * @param {String} attr The string name of an attribute.
+ */
+ get: function get(attr) {
+ switch (attr) {
+ case 'objectId':
+ return this.id;
+
+ case 'createdAt':
+ case 'updatedAt':
+ return this[attr];
+
+ default:
+ return this.attributes[attr];
+ }
+ },
+
+ /**
+ * Gets a relation on the given class for the attribute.
+ * @param {String} attr The attribute to get the relation for.
+ * @return {AV.Relation}
+ */
+ relation: function relation(attr) {
+ var value = this.get(attr);
+
+ if (value) {
+ if (!(value instanceof AV.Relation)) {
+ throw new Error('Called relation() on non-relation field ' + attr);
+ }
+
+ value._ensureParentAndKey(this, attr);
+
+ return value;
+ } else {
+ return new AV.Relation(this, attr);
+ }
+ },
+
+ /**
+ * Gets the HTML-escaped value of an attribute.
+ */
+ escape: function escape(attr) {
+ var html = this._escapedAttributes[attr];
+
+ if (html) {
+ return html;
+ }
+
+ var val = this.attributes[attr];
+ var escaped;
+
+ if (isNullOrUndefined(val)) {
+ escaped = '';
+ } else {
+ escaped = _.escape(val.toString());
+ }
+
+ this._escapedAttributes[attr] = escaped;
+ return escaped;
+ },
+
+ /**
+ * Returns true if the attribute contains a value that is not
+ * null or undefined.
+ * @param {String} attr The string name of the attribute.
+ * @return {Boolean}
+ */
+ has: function has(attr) {
+ return !isNullOrUndefined(this.attributes[attr]);
+ },
+
+ /**
+ * Pulls "special" fields like objectId, createdAt, etc. out of attrs
+ * and puts them on "this" directly. Removes them from attrs.
+ * @param attrs - A dictionary with the data for this AV.Object.
+ * @private
+ */
+ _mergeMagicFields: function _mergeMagicFields(attrs) {
+ // Check for changes of magic fields.
+ var model = this;
+ var specialFields = ['objectId', 'createdAt', 'updatedAt'];
+
+ AV._arrayEach(specialFields, function (attr) {
+ if (attrs[attr]) {
+ if (attr === 'objectId') {
+ model.id = attrs[attr];
+ } else if ((attr === 'createdAt' || attr === 'updatedAt') && !_.isDate(attrs[attr])) {
+ model[attr] = AV._parseDate(attrs[attr]);
+ } else {
+ model[attr] = attrs[attr];
+ }
+
+ delete attrs[attr];
+ }
+ });
+
+ return attrs;
+ },
+
+ /**
+ * Returns the json to be sent to the server.
+ * @private
+ */
+ _startSave: function _startSave() {
+ this._opSetQueue.push({});
+ },
+
+ /**
+ * Called when a save fails because of an error. Any changes that were part
+ * of the save need to be merged with changes made after the save. This
+ * might throw an exception is you do conflicting operations. For example,
+ * if you do:
+ * object.set("foo", "bar");
+ * object.set("invalid field name", "baz");
+ * object.save();
+ * object.increment("foo");
+ * then this will throw when the save fails and the client tries to merge
+ * "bar" with the +1.
+ * @private
+ */
+ _cancelSave: function _cancelSave() {
+ var failedChanges = _.first(this._opSetQueue);
+
+ this._opSetQueue = _.rest(this._opSetQueue);
+
+ var nextChanges = _.first(this._opSetQueue);
+
+ AV._objectEach(failedChanges, function (op, key) {
+ var op1 = failedChanges[key];
+ var op2 = nextChanges[key];
+
+ if (op1 && op2) {
+ nextChanges[key] = op2._mergeWithPrevious(op1);
+ } else if (op1) {
+ nextChanges[key] = op1;
+ }
+ });
+
+ this._saving = this._saving - 1;
+ },
+
+ /**
+ * Called when a save completes successfully. This merges the changes that
+ * were saved into the known server data, and overrides it with any data
+ * sent directly from the server.
+ * @private
+ */
+ _finishSave: function _finishSave(serverData) {
+ var _context2;
+
+ // Grab a copy of any object referenced by this object. These instances
+ // may have already been fetched, and we don't want to lose their data.
+ // Note that doing it like this means we will unify separate copies of the
+ // same object, but that's a risk we have to take.
+ var fetchedObjects = {};
+
+ AV._traverse(this.attributes, function (object) {
+ if (object instanceof AV.Object && object.id && object._hasData) {
+ fetchedObjects[object.id] = object;
+ }
+ });
+
+ var savedChanges = _.first(this._opSetQueue);
+
+ this._opSetQueue = _.rest(this._opSetQueue);
+
+ this._applyOpSet(savedChanges, this._serverData);
+
+ this._mergeMagicFields(serverData);
+
+ var self = this;
+
+ AV._objectEach(serverData, function (value, key) {
+ self._serverData[key] = AV._decode(value, key); // Look for any objects that might have become unfetched and fix them
+ // by replacing their values with the previously observed values.
+
+ var fetched = AV._traverse(self._serverData[key], function (object) {
+ if (object instanceof AV.Object && fetchedObjects[object.id]) {
+ return fetchedObjects[object.id];
+ }
+ });
+
+ if (fetched) {
+ self._serverData[key] = fetched;
+ }
+ });
+
+ this._rebuildAllEstimatedData();
+
+ var opSetQueue = (0, _map.default)(_context2 = this._opSetQueue).call(_context2, _.clone);
+
+ this._refreshCache();
+
+ this._opSetQueue = opSetQueue;
+ this._saving = this._saving - 1;
+ },
+
+ /**
+ * Called when a fetch or login is complete to set the known server data to
+ * the given object.
+ * @private
+ */
+ _finishFetch: function _finishFetch(serverData, hasData) {
+ // Clear out any changes the user might have made previously.
+ this._opSetQueue = [{}]; // Bring in all the new server data.
+
+ this._mergeMagicFields(serverData);
+
+ var self = this;
+
+ AV._objectEach(serverData, function (value, key) {
+ self._serverData[key] = AV._decode(value, key);
+ }); // Refresh the attributes.
+
+
+ this._rebuildAllEstimatedData(); // Clear out the cache of mutable containers.
+
+
+ this._refreshCache();
+
+ this._opSetQueue = [{}];
+ this._hasData = hasData;
+ },
+
+ /**
+ * Applies the set of AV.Op in opSet to the object target.
+ * @private
+ */
+ _applyOpSet: function _applyOpSet(opSet, target) {
+ var self = this;
+
+ AV._objectEach(opSet, function (change, key) {
+ var _findValue = findValue(target, key),
+ _findValue2 = (0, _slicedToArray2.default)(_findValue, 3),
+ value = _findValue2[0],
+ actualTarget = _findValue2[1],
+ actualKey = _findValue2[2];
+
+ setValue(target, key, change._estimate(value, self, key));
+
+ if (actualTarget && actualTarget[actualKey] === AV.Op._UNSET) {
+ delete actualTarget[actualKey];
+ }
+ });
+ },
+
+ /**
+ * Replaces the cached value for key with the current value.
+ * Returns true if the new value is different than the old value.
+ * @private
+ */
+ _resetCacheForKey: function _resetCacheForKey(key) {
+ var value = this.attributes[key];
+
+ if (_.isObject(value) && !(value instanceof AV.Object) && !(value instanceof AV.File)) {
+ var json = (0, _stringify.default)(recursiveToPointer(value));
+
+ if (this._hashedJSON[key] !== json) {
+ var wasSet = !!this._hashedJSON[key];
+ this._hashedJSON[key] = json;
+ return wasSet;
+ }
+ }
+
+ return false;
+ },
+
+ /**
+ * Populates attributes[key] by starting with the last known data from the
+ * server, and applying all of the local changes that have been made to that
+ * key since then.
+ * @private
+ */
+ _rebuildEstimatedDataForKey: function _rebuildEstimatedDataForKey(key) {
+ var self = this;
+ delete this.attributes[key];
+
+ if (this._serverData[key]) {
+ this.attributes[key] = this._serverData[key];
+ }
+
+ AV._arrayEach(this._opSetQueue, function (opSet) {
+ var op = opSet[key];
+
+ if (op) {
+ var _findValue3 = findValue(self.attributes, key),
+ _findValue4 = (0, _slicedToArray2.default)(_findValue3, 4),
+ value = _findValue4[0],
+ actualTarget = _findValue4[1],
+ actualKey = _findValue4[2],
+ firstKey = _findValue4[3];
+
+ setValue(self.attributes, key, op._estimate(value, self, key));
+
+ if (actualTarget && actualTarget[actualKey] === AV.Op._UNSET) {
+ delete actualTarget[actualKey];
+ }
+
+ self._resetCacheForKey(firstKey);
+ }
+ });
+ },
+
+ /**
+ * Populates attributes by starting with the last known data from the
+ * server, and applying all of the local changes that have been made since
+ * then.
+ * @private
+ */
+ _rebuildAllEstimatedData: function _rebuildAllEstimatedData() {
+ var self = this;
+
+ var previousAttributes = _.clone(this.attributes);
+
+ this.attributes = _.clone(this._serverData);
+
+ AV._arrayEach(this._opSetQueue, function (opSet) {
+ self._applyOpSet(opSet, self.attributes);
+
+ AV._objectEach(opSet, function (op, key) {
+ self._resetCacheForKey(key);
+ });
+ }); // Trigger change events for anything that changed because of the fetch.
+
+
+ AV._objectEach(previousAttributes, function (oldValue, key) {
+ if (self.attributes[key] !== oldValue) {
+ self.trigger('change:' + key, self, self.attributes[key], {});
+ }
+ });
+
+ AV._objectEach(this.attributes, function (newValue, key) {
+ if (!_.has(previousAttributes, key)) {
+ self.trigger('change:' + key, self, newValue, {});
+ }
+ });
+ },
+
+ /**
+ * Sets a hash of model attributes on the object, firing
+ * "change" unless you choose to silence it.
+ *
+ *
You can call it with an object containing keys and values, or with one
+ * key and value. For example:
+ *
+ * @example
+ * gameTurn.set({
+ * player: player1,
+ * diceRoll: 2
+ * });
+ *
+ * game.set("currentPlayer", player2);
+ *
+ * game.set("finished", true);
+ *
+ * @param {String} key The key to set.
+ * @param {Any} value The value to give it.
+ * @param {Object} [options]
+ * @param {Boolean} [options.silent]
+ * @return {AV.Object} self if succeeded, throws if the value is not valid.
+ * @see AV.Object#validate
+ */
+ set: function set(key, value, options) {
+ var attrs;
+
+ if (_.isObject(key) || isNullOrUndefined(key)) {
+ attrs = _.mapObject(key, function (v, k) {
+ checkReservedKey(k);
+ return AV._decode(v, k);
+ });
+ options = value;
+ } else {
+ attrs = {};
+ checkReservedKey(key);
+ attrs[key] = AV._decode(value, key);
+ } // Extract attributes and options.
+
+
+ options = options || {};
+
+ if (!attrs) {
+ return this;
+ }
+
+ if (attrs instanceof AV.Object) {
+ attrs = attrs.attributes;
+ } // If the unset option is used, every attribute should be a Unset.
+
+
+ if (options.unset) {
+ AV._objectEach(attrs, function (unused_value, key) {
+ attrs[key] = new AV.Op.Unset();
+ });
+ } // Apply all the attributes to get the estimated values.
+
+
+ var dataToValidate = _.clone(attrs);
+
+ var self = this;
+
+ AV._objectEach(dataToValidate, function (value, key) {
+ if (value instanceof AV.Op) {
+ dataToValidate[key] = value._estimate(self.attributes[key], self, key);
+
+ if (dataToValidate[key] === AV.Op._UNSET) {
+ delete dataToValidate[key];
+ }
+ }
+ }); // Run validation.
+
+
+ this._validate(attrs, options);
+
+ options.changes = {};
+ var escaped = this._escapedAttributes; // Update attributes.
+
+ AV._arrayEach((0, _keys2.default)(_).call(_, attrs), function (attr) {
+ var val = attrs[attr]; // If this is a relation object we need to set the parent correctly,
+ // since the location where it was parsed does not have access to
+ // this object.
+
+ if (val instanceof AV.Relation) {
+ val.parent = self;
+ }
+
+ if (!(val instanceof AV.Op)) {
+ val = new AV.Op.Set(val);
+ } // See if this change will actually have any effect.
+
+
+ var isRealChange = true;
+
+ if (val instanceof AV.Op.Set && _.isEqual(self.attributes[attr], val.value)) {
+ isRealChange = false;
+ }
+
+ if (isRealChange) {
+ delete escaped[attr];
+
+ if (options.silent) {
+ self._silent[attr] = true;
+ } else {
+ options.changes[attr] = true;
+ }
+ }
+
+ var currentChanges = _.last(self._opSetQueue);
+
+ currentChanges[attr] = val._mergeWithPrevious(currentChanges[attr]);
+
+ self._rebuildEstimatedDataForKey(attr);
+
+ if (isRealChange) {
+ self.changed[attr] = self.attributes[attr];
+
+ if (!options.silent) {
+ self._pending[attr] = true;
+ }
+ } else {
+ delete self.changed[attr];
+ delete self._pending[attr];
+ }
+ });
+
+ if (!options.silent) {
+ this.change(options);
+ }
+
+ return this;
+ },
+
+ /**
+ * Remove an attribute from the model, firing "change" unless
+ * you choose to silence it. This is a noop if the attribute doesn't
+ * exist.
+ * @param key {String} The key.
+ */
+ unset: function unset(attr, options) {
+ options = options || {};
+ options.unset = true;
+ return this.set(attr, null, options);
+ },
+
+ /**
+ * Atomically increments the value of the given attribute the next time the
+ * object is saved. If no amount is specified, 1 is used by default.
+ *
+ * @param key {String} The key.
+ * @param amount {Number} The amount to increment by.
+ */
+ increment: function increment(attr, amount) {
+ if (_.isUndefined(amount) || _.isNull(amount)) {
+ amount = 1;
+ }
+
+ return this.set(attr, new AV.Op.Increment(amount));
+ },
+
+ /**
+ * Atomically add an object to the end of the array associated with a given
+ * key.
+ * @param key {String} The key.
+ * @param item {} The item to add.
+ */
+ add: function add(attr, item) {
+ return this.set(attr, new AV.Op.Add(ensureArray(item)));
+ },
+
+ /**
+ * Atomically add an object to the array associated with a given key, only
+ * if it is not already present in the array. The position of the insert is
+ * not guaranteed.
+ *
+ * @param key {String} The key.
+ * @param item {} The object to add.
+ */
+ addUnique: function addUnique(attr, item) {
+ return this.set(attr, new AV.Op.AddUnique(ensureArray(item)));
+ },
+
+ /**
+ * Atomically remove all instances of an object from the array associated
+ * with a given key.
+ *
+ * @param key {String} The key.
+ * @param item {} The object to remove.
+ */
+ remove: function remove(attr, item) {
+ return this.set(attr, new AV.Op.Remove(ensureArray(item)));
+ },
+
+ /**
+ * Atomically apply a "bit and" operation on the value associated with a
+ * given key.
+ *
+ * @param key {String} The key.
+ * @param value {Number} The value to apply.
+ */
+ bitAnd: function bitAnd(attr, value) {
+ return this.set(attr, new AV.Op.BitAnd(value));
+ },
+
+ /**
+ * Atomically apply a "bit or" operation on the value associated with a
+ * given key.
+ *
+ * @param key {String} The key.
+ * @param value {Number} The value to apply.
+ */
+ bitOr: function bitOr(attr, value) {
+ return this.set(attr, new AV.Op.BitOr(value));
+ },
+
+ /**
+ * Atomically apply a "bit xor" operation on the value associated with a
+ * given key.
+ *
+ * @param key {String} The key.
+ * @param value {Number} The value to apply.
+ */
+ bitXor: function bitXor(attr, value) {
+ return this.set(attr, new AV.Op.BitXor(value));
+ },
+
+ /**
+ * Returns an instance of a subclass of AV.Op describing what kind of
+ * modification has been performed on this field since the last time it was
+ * saved. For example, after calling object.increment("x"), calling
+ * object.op("x") would return an instance of AV.Op.Increment.
+ *
+ * @param key {String} The key.
+ * @returns {AV.Op} The operation, or undefined if none.
+ */
+ op: function op(attr) {
+ return _.last(this._opSetQueue)[attr];
+ },
+
+ /**
+ * Clear all attributes on the model, firing "change" unless
+ * you choose to silence it.
+ */
+ clear: function clear(options) {
+ options = options || {};
+ options.unset = true;
+
+ var keysToClear = _.extend(this.attributes, this._operations);
+
+ return this.set(keysToClear, options);
+ },
+
+ /**
+ * Clears any (or specific) changes to the model made since the last save.
+ * @param {string|string[]} [keys] specify keys to revert.
+ */
+ revert: function revert(keys) {
+ var lastOp = _.last(this._opSetQueue);
+
+ var _keys = ensureArray(keys || (0, _keys2.default)(_).call(_, lastOp));
+
+ _keys.forEach(function (key) {
+ delete lastOp[key];
+ });
+
+ this._rebuildAllEstimatedData();
+
+ return this;
+ },
+
+ /**
+ * Returns a JSON-encoded set of operations to be sent with the next save
+ * request.
+ * @private
+ */
+ _getSaveJSON: function _getSaveJSON() {
+ var json = _.clone(_.first(this._opSetQueue));
+
+ AV._objectEach(json, function (op, key) {
+ json[key] = op.toJSON();
+ });
+
+ return json;
+ },
+
+ /**
+ * Returns true if this object can be serialized for saving.
+ * @private
+ */
+ _canBeSerialized: function _canBeSerialized() {
+ return AV.Object._canBeSerializedAsValue(this.attributes);
+ },
+
+ /**
+ * Fetch the model from the server. If the server's representation of the
+ * model differs from its current attributes, they will be overriden,
+ * triggering a "change" event.
+ * @param {Object} fetchOptions Optional options to set 'keys',
+ * 'include' and 'includeACL' option.
+ * @param {AuthOptions} options
+ * @return {Promise} A promise that is fulfilled when the fetch
+ * completes.
+ */
+ fetch: function fetch() {
+ var fetchOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
+ var options = arguments.length > 1 ? arguments[1] : undefined;
+
+ if (!this.id) {
+ throw new Error('Cannot fetch unsaved object');
+ }
+
+ var self = this;
+
+ var request = _request('classes', this.className, this.id, 'GET', transformFetchOptions(fetchOptions), options);
+
+ return request.then(function (response) {
+ var fetchedAttrs = self.parse(response);
+
+ self._cleanupUnsetKeys(fetchedAttrs, (0, _keys2.default)(fetchOptions) ? ensureArray((0, _keys2.default)(fetchOptions)).join(',').split(',') : undefined);
+
+ self._finishFetch(fetchedAttrs, true);
+
+ return self;
+ });
+ },
+ _cleanupUnsetKeys: function _cleanupUnsetKeys(fetchedAttrs) {
+ var _this2 = this;
+
+ var fetchedKeys = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : (0, _keys2.default)(_).call(_, this._serverData);
+
+ _.forEach(fetchedKeys, function (key) {
+ if (fetchedAttrs[key] === undefined) delete _this2._serverData[key];
+ });
+ },
+
+ /**
+ * Set a hash of model attributes, and save the model to the server.
+ * updatedAt will be updated when the request returns.
+ * You can either call it as:
+ * object.save();
+ * or
+ * object.save(null, options);
+ * or
+ * object.save(attrs, options);
+ * or
+ * object.save(key, value, options);
+ *
+ * @example
+ * gameTurn.save({
+ * player: "Jake Cutter",
+ * diceRoll: 2
+ * }).then(function(gameTurnAgain) {
+ * // The save was successful.
+ * }, function(error) {
+ * // The save failed. Error is an instance of AVError.
+ * });
+ *
+ * @param {AuthOptions} options AuthOptions plus:
+ * @param {Boolean} options.fetchWhenSave fetch and update object after save succeeded
+ * @param {AV.Query} options.query Save object only when it matches the query
+ * @return {Promise} A promise that is fulfilled when the save
+ * completes.
+ * @see AVError
+ */
+ save: function save(arg1, arg2, arg3) {
+ var attrs, current, options;
+
+ if (_.isObject(arg1) || isNullOrUndefined(arg1)) {
+ attrs = arg1;
+ options = arg2;
+ } else {
+ attrs = {};
+ attrs[arg1] = arg2;
+ options = arg3;
+ }
+
+ options = _.clone(options) || {};
+
+ if (options.wait) {
+ current = _.clone(this.attributes);
+ }
+
+ var setOptions = _.clone(options) || {};
+
+ if (setOptions.wait) {
+ setOptions.silent = true;
+ }
+
+ if (attrs) {
+ this.set(attrs, setOptions);
+ }
+
+ var model = this;
+ var unsavedChildren = [];
+ var unsavedFiles = [];
+
+ AV.Object._findUnsavedChildren(model, unsavedChildren, unsavedFiles);
+
+ if (unsavedChildren.length + unsavedFiles.length > 1) {
+ return AV.Object._deepSaveAsync(this, model, options);
+ }
+
+ this._startSave();
+
+ this._saving = (this._saving || 0) + 1;
+ this._allPreviousSaves = this._allPreviousSaves || _promise.default.resolve();
+ this._allPreviousSaves = this._allPreviousSaves.catch(function (e) {}).then(function () {
+ var method = model.id ? 'PUT' : 'POST';
+
+ var json = model._getSaveJSON();
+
+ var query = {};
+
+ if (model._fetchWhenSave || options.fetchWhenSave) {
+ query['new'] = 'true';
+ } // user login option
+
+
+ if (options._failOnNotExist) {
+ query.failOnNotExist = 'true';
+ }
+
+ if (options.query) {
+ var queryParams;
+
+ if (typeof options.query._getParams === 'function') {
+ queryParams = options.query._getParams();
+
+ if (queryParams) {
+ query.where = queryParams.where;
+ }
+ }
+
+ if (!query.where) {
+ var error = new Error('options.query is not an AV.Query');
+ throw error;
+ }
+ }
+
+ _.extend(json, model._flags);
+
+ var route = 'classes';
+ var className = model.className;
+
+ if (model.className === '_User' && !model.id) {
+ // Special-case user sign-up.
+ route = 'users';
+ className = null;
+ } //hook makeRequest in options.
+
+
+ var makeRequest = options._makeRequest || _request;
+ var requestPromise = makeRequest(route, className, model.id, method, json, options, query);
+ requestPromise = requestPromise.then(function (resp) {
+ var serverAttrs = model.parse(resp);
+
+ if (options.wait) {
+ serverAttrs = _.extend(attrs || {}, serverAttrs);
+ }
+
+ model._finishSave(serverAttrs);
+
+ if (options.wait) {
+ model.set(current, setOptions);
+ }
+
+ return model;
+ }, function (error) {
+ model._cancelSave();
+
+ throw error;
+ });
+ return requestPromise;
+ });
+ return this._allPreviousSaves;
+ },
+
+ /**
+ * Destroy this model on the server if it was already persisted.
+ * Optimistically removes the model from its collection, if it has one.
+ * @param {AuthOptions} options AuthOptions plus:
+ * @param {Boolean} [options.wait] wait for the server to respond
+ * before removal.
+ *
+ * @return {Promise} A promise that is fulfilled when the destroy
+ * completes.
+ */
+ destroy: function destroy(options) {
+ options = options || {};
+ var model = this;
+
+ var triggerDestroy = function triggerDestroy() {
+ model.trigger('destroy', model, model.collection, options);
+ };
+
+ if (!this.id) {
+ return triggerDestroy();
+ }
+
+ if (!options.wait) {
+ triggerDestroy();
+ }
+
+ var request = _request('classes', this.className, this.id, 'DELETE', this._flags, options);
+
+ return request.then(function () {
+ if (options.wait) {
+ triggerDestroy();
+ }
+
+ return model;
+ });
+ },
+
+ /**
+ * Converts a response into the hash of attributes to be set on the model.
+ * @ignore
+ */
+ parse: function parse(resp) {
+ var output = _.clone(resp);
+
+ ['createdAt', 'updatedAt'].forEach(function (key) {
+ if (output[key]) {
+ output[key] = AV._parseDate(output[key]);
+ }
+ });
+
+ if (output.createdAt && !output.updatedAt) {
+ output.updatedAt = output.createdAt;
+ }
+
+ return output;
+ },
+
+ /**
+ * Creates a new model with identical attributes to this one.
+ * @return {AV.Object}
+ */
+ clone: function clone() {
+ return new this.constructor(this.attributes);
+ },
+
+ /**
+ * Returns true if this object has never been saved to AV.
+ * @return {Boolean}
+ */
+ isNew: function isNew() {
+ return !this.id;
+ },
+
+ /**
+ * Call this method to manually fire a `"change"` event for this model and
+ * a `"change:attribute"` event for each changed attribute.
+ * Calling this will cause all objects observing the model to update.
+ */
+ change: function change(options) {
+ options = options || {};
+ var changing = this._changing;
+ this._changing = true; // Silent changes become pending changes.
+
+ var self = this;
+
+ AV._objectEach(this._silent, function (attr) {
+ self._pending[attr] = true;
+ }); // Silent changes are triggered.
+
+
+ var changes = _.extend({}, options.changes, this._silent);
+
+ this._silent = {};
+
+ AV._objectEach(changes, function (unused_value, attr) {
+ self.trigger('change:' + attr, self, self.get(attr), options);
+ });
+
+ if (changing) {
+ return this;
+ } // This is to get around lint not letting us make a function in a loop.
+
+
+ var deleteChanged = function deleteChanged(value, attr) {
+ if (!self._pending[attr] && !self._silent[attr]) {
+ delete self.changed[attr];
+ }
+ }; // Continue firing `"change"` events while there are pending changes.
+
+
+ while (!_.isEmpty(this._pending)) {
+ this._pending = {};
+ this.trigger('change', this, options); // Pending and silent changes still remain.
+
+ AV._objectEach(this.changed, deleteChanged);
+
+ self._previousAttributes = _.clone(this.attributes);
+ }
+
+ this._changing = false;
+ return this;
+ },
+
+ /**
+ * Gets the previous value of an attribute, recorded at the time the last
+ * "change" event was fired.
+ * @param {String} attr Name of the attribute to get.
+ */
+ previous: function previous(attr) {
+ if (!arguments.length || !this._previousAttributes) {
+ return null;
+ }
+
+ return this._previousAttributes[attr];
+ },
+
+ /**
+ * Gets all of the attributes of the model at the time of the previous
+ * "change" event.
+ * @return {Object}
+ */
+ previousAttributes: function previousAttributes() {
+ return _.clone(this._previousAttributes);
+ },
+
+ /**
+ * Checks if the model is currently in a valid state. It's only possible to
+ * get into an *invalid* state if you're using silent changes.
+ * @return {Boolean}
+ */
+ isValid: function isValid() {
+ try {
+ this.validate(this.attributes);
+ } catch (error) {
+ return false;
+ }
+
+ return true;
+ },
+
+ /**
+ * You should not call this function directly unless you subclass
+ * AV.Object, in which case you can override this method
+ * to provide additional validation on set and
+ * save. Your implementation should throw an Error if
+ * the attrs is invalid
+ *
+ * @param {Object} attrs The current data to validate.
+ * @see AV.Object#set
+ */
+ validate: function validate(attrs) {
+ if (_.has(attrs, 'ACL') && !(attrs.ACL instanceof AV.ACL)) {
+ throw new AVError(AVError.OTHER_CAUSE, 'ACL must be a AV.ACL.');
+ }
+ },
+
+ /**
+ * Run validation against a set of incoming attributes, returning `true`
+ * if all is well. If a specific `error` callback has been passed,
+ * call that instead of firing the general `"error"` event.
+ * @private
+ */
+ _validate: function _validate(attrs, options) {
+ if (options.silent || !this.validate) {
+ return;
+ }
+
+ attrs = _.extend({}, this.attributes, attrs);
+ this.validate(attrs);
+ },
+
+ /**
+ * Returns the ACL for this object.
+ * @returns {AV.ACL} An instance of AV.ACL.
+ * @see AV.Object#get
+ */
+ getACL: function getACL() {
+ return this.get('ACL');
+ },
+
+ /**
+ * Sets the ACL to be used for this object.
+ * @param {AV.ACL} acl An instance of AV.ACL.
+ * @param {Object} options Optional Backbone-like options object to be
+ * passed in to set.
+ * @return {AV.Object} self
+ * @see AV.Object#set
+ */
+ setACL: function setACL(acl, options) {
+ return this.set('ACL', acl, options);
+ },
+ disableBeforeHook: function disableBeforeHook() {
+ this.ignoreHook('beforeSave');
+ this.ignoreHook('beforeUpdate');
+ this.ignoreHook('beforeDelete');
+ },
+ disableAfterHook: function disableAfterHook() {
+ this.ignoreHook('afterSave');
+ this.ignoreHook('afterUpdate');
+ this.ignoreHook('afterDelete');
+ },
+ ignoreHook: function ignoreHook(hookName) {
+ if (!_.contains(['beforeSave', 'afterSave', 'beforeUpdate', 'afterUpdate', 'beforeDelete', 'afterDelete'], hookName)) {
+ throw new Error('Unsupported hookName: ' + hookName);
+ }
+
+ if (!AV.hookKey) {
+ throw new Error('ignoreHook required hookKey');
+ }
+
+ if (!this._flags.__ignore_hooks) {
+ this._flags.__ignore_hooks = [];
+ }
+
+ this._flags.__ignore_hooks.push(hookName);
+ }
+ });
+ /**
+ * Creates an instance of a subclass of AV.Object for the give classname
+ * and id.
+ * @param {String|Function} class the className or a subclass of AV.Object.
+ * @param {String} id The object id of this model.
+ * @return {AV.Object} A new subclass instance of AV.Object.
+ */
+
+
+ AV.Object.createWithoutData = function (klass, id, hasData) {
+ var _klass;
+
+ if (_.isString(klass)) {
+ _klass = AV.Object._getSubclass(klass);
+ } else if (klass.prototype && klass.prototype instanceof AV.Object) {
+ _klass = klass;
+ } else {
+ throw new Error('class must be a string or a subclass of AV.Object.');
+ }
+
+ if (!id) {
+ throw new TypeError('The objectId must be provided');
+ }
+
+ var object = new _klass();
+ object.id = id;
+ object._hasData = hasData;
+ return object;
+ };
+ /**
+ * Delete objects in batch.
+ * @param {AV.Object[]} objects The AV.Object array to be deleted.
+ * @param {AuthOptions} options
+ * @return {Promise} A promise that is fulfilled when the save
+ * completes.
+ */
+
+
+ AV.Object.destroyAll = function (objects) {
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
+
+ if (!objects || objects.length === 0) {
+ return _promise.default.resolve();
+ }
+
+ var objectsByClassNameAndFlags = _.groupBy(objects, function (object) {
+ return (0, _stringify.default)({
+ className: object.className,
+ flags: object._flags
+ });
+ });
+
+ var body = {
+ requests: (0, _map.default)(_).call(_, objectsByClassNameAndFlags, function (objects) {
+ var _context3;
+
+ var ids = (0, _map.default)(_).call(_, objects, 'id').join(',');
+ return {
+ method: 'DELETE',
+ path: (0, _concat.default)(_context3 = "/1.1/classes/".concat(objects[0].className, "/")).call(_context3, ids),
+ body: objects[0]._flags
+ };
+ })
+ };
+ return _request('batch', null, null, 'POST', body, options).then(function (response) {
+ var firstError = (0, _find.default)(_).call(_, response, function (result) {
+ return !result.success;
+ });
+ if (firstError) throw new AVError(firstError.error.code, firstError.error.error);
+ return undefined;
+ });
+ };
+ /**
+ * Returns the appropriate subclass for making new instances of the given
+ * className string.
+ * @private
+ */
+
+
+ AV.Object._getSubclass = function (className) {
+ if (!_.isString(className)) {
+ throw new Error('AV.Object._getSubclass requires a string argument.');
+ }
+
+ var ObjectClass = AV.Object._classMap[className];
+
+ if (!ObjectClass) {
+ ObjectClass = AV.Object.extend(className);
+ AV.Object._classMap[className] = ObjectClass;
+ }
+
+ return ObjectClass;
+ };
+ /**
+ * Creates an instance of a subclass of AV.Object for the given classname.
+ * @private
+ */
+
+
+ AV.Object._create = function (className, attributes, options) {
+ var ObjectClass = AV.Object._getSubclass(className);
+
+ return new ObjectClass(attributes, options);
+ }; // Set up a map of className to class so that we can create new instances of
+ // AV Objects from JSON automatically.
+
+
+ AV.Object._classMap = {};
+ AV.Object._extend = AV._extend;
+ /**
+ * Creates a new model with defined attributes,
+ * It's the same with
+ *
+ * new AV.Object(attributes, options);
+ *
+ * @param {Object} attributes The initial set of data to store in the object.
+ * @param {Object} options A set of Backbone-like options for creating the
+ * object. The only option currently supported is "collection".
+ * @return {AV.Object}
+ * @since v0.4.4
+ * @see AV.Object
+ * @see AV.Object.extend
+ */
+
+ AV.Object['new'] = function (attributes, options) {
+ return new AV.Object(attributes, options);
+ };
+ /**
+ * Creates a new subclass of AV.Object for the given AV class name.
+ *
+ *
Every extension of a AV class will inherit from the most recent
+ * previous extension of that class. When a AV.Object is automatically
+ * created by parsing JSON, it will use the most recent extension of that
+ * class.
+ *
+ * @example
+ * var MyClass = AV.Object.extend("MyClass", {
+ * // Instance properties
+ * }, {
+ * // Class properties
+ * });
+ *
+ * @param {String} className The name of the AV class backing this model.
+ * @param {Object} protoProps Instance properties to add to instances of the
+ * class returned from this method.
+ * @param {Object} classProps Class properties to add the class returned from
+ * this method.
+ * @return {Class} A new subclass of AV.Object.
+ */
+
+
+ AV.Object.extend = function (className, protoProps, classProps) {
+ // Handle the case with only two args.
+ if (!_.isString(className)) {
+ if (className && _.has(className, 'className')) {
+ return AV.Object.extend(className.className, className, protoProps);
+ } else {
+ throw new Error("AV.Object.extend's first argument should be the className.");
+ }
+ } // If someone tries to subclass "User", coerce it to the right type.
+
+
+ if (className === 'User') {
+ className = '_User';
+ }
+
+ var NewClassObject = null;
+
+ if (_.has(AV.Object._classMap, className)) {
+ var OldClassObject = AV.Object._classMap[className]; // This new subclass has been told to extend both from "this" and from
+ // OldClassObject. This is multiple inheritance, which isn't supported.
+ // For now, let's just pick one.
+
+ if (protoProps || classProps) {
+ NewClassObject = OldClassObject._extend(protoProps, classProps);
+ } else {
+ return OldClassObject;
+ }
+ } else {
+ protoProps = protoProps || {};
+ protoProps._className = className;
+ NewClassObject = this._extend(protoProps, classProps);
+ } // Extending a subclass should reuse the classname automatically.
+
+
+ NewClassObject.extend = function (arg0) {
+ var _context4;
+
+ if (_.isString(arg0) || arg0 && _.has(arg0, 'className')) {
+ return AV.Object.extend.apply(NewClassObject, arguments);
+ }
+
+ var newArguments = (0, _concat.default)(_context4 = [className]).call(_context4, _.toArray(arguments));
+ return AV.Object.extend.apply(NewClassObject, newArguments);
+ }; // Add the query property descriptor.
+
+
+ (0, _defineProperty.default)(NewClassObject, 'query', (0, _getOwnPropertyDescriptor.default)(AV.Object, 'query'));
+
+ NewClassObject['new'] = function (attributes, options) {
+ return new NewClassObject(attributes, options);
+ };
+
+ AV.Object._classMap[className] = NewClassObject;
+ return NewClassObject;
+ }; // ES6 class syntax support
+
+
+ (0, _defineProperty.default)(AV.Object.prototype, 'className', {
+ get: function get() {
+ var className = this._className || this.constructor._LCClassName || this.constructor.name; // If someone tries to subclass "User", coerce it to the right type.
+
+ if (className === 'User') {
+ return '_User';
+ }
+
+ return className;
+ }
+ });
+ /**
+ * Register a class.
+ * If a subclass of AV.Object is defined with your own implement
+ * rather then AV.Object.extend, the subclass must be registered.
+ * @param {Function} klass A subclass of AV.Object
+ * @param {String} [name] Specify the name of the class. Useful when the class might be uglified.
+ * @example
+ * class Person extend AV.Object {}
+ * AV.Object.register(Person);
+ */
+
+ AV.Object.register = function (klass, name) {
+ if (!(klass.prototype instanceof AV.Object)) {
+ throw new Error('registered class is not a subclass of AV.Object');
+ }
+
+ var className = name || klass.name;
+
+ if (!className.length) {
+ throw new Error('registered class must be named');
+ }
+
+ if (name) {
+ klass._LCClassName = name;
+ }
+
+ AV.Object._classMap[className] = klass;
+ };
+ /**
+ * Get a new Query of the current class
+ * @name query
+ * @memberof AV.Object
+ * @type AV.Query
+ * @readonly
+ * @since v3.1.0
+ * @example
+ * const Post = AV.Object.extend('Post');
+ * Post.query.equalTo('author', 'leancloud').find().then();
+ */
+
+
+ (0, _defineProperty.default)(AV.Object, 'query', {
+ get: function get() {
+ return new AV.Query(this.prototype.className);
+ }
+ });
+
+ AV.Object._findUnsavedChildren = function (objects, children, files) {
+ AV._traverse(objects, function (object) {
+ if (object instanceof AV.Object) {
+ if (object.dirty()) {
+ children.push(object);
+ }
+
+ return;
+ }
+
+ if (object instanceof AV.File) {
+ if (!object.id) {
+ files.push(object);
+ }
+
+ return;
+ }
+ });
+ };
+
+ AV.Object._canBeSerializedAsValue = function (object) {
+ var canBeSerializedAsValue = true;
+
+ if (object instanceof AV.Object || object instanceof AV.File) {
+ canBeSerializedAsValue = !!object.id;
+ } else if (_.isArray(object)) {
+ AV._arrayEach(object, function (child) {
+ if (!AV.Object._canBeSerializedAsValue(child)) {
+ canBeSerializedAsValue = false;
+ }
+ });
+ } else if (_.isObject(object)) {
+ AV._objectEach(object, function (child) {
+ if (!AV.Object._canBeSerializedAsValue(child)) {
+ canBeSerializedAsValue = false;
+ }
+ });
+ }
+
+ return canBeSerializedAsValue;
+ };
+
+ AV.Object._deepSaveAsync = function (object, model, options) {
+ var unsavedChildren = [];
+ var unsavedFiles = [];
+
+ AV.Object._findUnsavedChildren(object, unsavedChildren, unsavedFiles);
+
+ unsavedFiles = _.uniq(unsavedFiles);
+
+ var promise = _promise.default.resolve();
+
+ _.each(unsavedFiles, function (file) {
+ promise = promise.then(function () {
+ return file.save();
+ });
+ });
+
+ var objects = _.uniq(unsavedChildren);
+
+ var remaining = _.uniq(objects);
+
+ return promise.then(function () {
+ return continueWhile(function () {
+ return remaining.length > 0;
+ }, function () {
+ // Gather up all the objects that can be saved in this batch.
+ var batch = [];
+ var newRemaining = [];
+
+ AV._arrayEach(remaining, function (object) {
+ if (object._canBeSerialized()) {
+ batch.push(object);
+ } else {
+ newRemaining.push(object);
+ }
+ });
+
+ remaining = newRemaining; // If we can't save any objects, there must be a circular reference.
+
+ if (batch.length === 0) {
+ return _promise.default.reject(new AVError(AVError.OTHER_CAUSE, 'Tried to save a batch with a cycle.'));
+ } // Reserve a spot in every object's save queue.
+
+
+ var readyToStart = _promise.default.resolve((0, _map.default)(_).call(_, batch, function (object) {
+ return object._allPreviousSaves || _promise.default.resolve();
+ })); // Save a single batch, whether previous saves succeeded or failed.
+
+
+ var bathSavePromise = readyToStart.then(function () {
+ return _request('batch', null, null, 'POST', {
+ requests: (0, _map.default)(_).call(_, batch, function (object) {
+ var method = object.id ? 'PUT' : 'POST';
+
+ var json = object._getSaveJSON();
+
+ _.extend(json, object._flags);
+
+ var route = 'classes';
+ var className = object.className;
+ var path = "/".concat(route, "/").concat(className);
+
+ if (object.className === '_User' && !object.id) {
+ // Special-case user sign-up.
+ path = '/users';
+ }
+
+ var path = "/1.1".concat(path);
+
+ if (object.id) {
+ path = path + '/' + object.id;
+ }
+
+ object._startSave();
+
+ return {
+ method: method,
+ path: path,
+ body: json,
+ params: options && options.fetchWhenSave ? {
+ fetchWhenSave: true
+ } : undefined
+ };
+ })
+ }, options).then(function (response) {
+ var results = (0, _map.default)(_).call(_, batch, function (object, i) {
+ if (response[i].success) {
+ object._finishSave(object.parse(response[i].success));
+
+ return object;
+ }
+
+ object._cancelSave();
+
+ return new AVError(response[i].error.code, response[i].error.error);
+ });
+ return handleBatchResults(results);
+ });
+ });
+
+ AV._arrayEach(batch, function (object) {
+ object._allPreviousSaves = bathSavePromise;
+ });
+
+ return bathSavePromise;
+ });
+ }).then(function () {
+ return object;
+ });
+ };
+};
+
+/***/ }),
+/* 501 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var arrayWithHoles = __webpack_require__(502);
+
+var iterableToArrayLimit = __webpack_require__(510);
+
+var unsupportedIterableToArray = __webpack_require__(511);
+
+var nonIterableRest = __webpack_require__(521);
+
+function _slicedToArray(arr, i) {
+ return arrayWithHoles(arr) || iterableToArrayLimit(arr, i) || unsupportedIterableToArray(arr, i) || nonIterableRest();
+}
+
+module.exports = _slicedToArray, module.exports.__esModule = true, module.exports["default"] = module.exports;
+
+/***/ }),
+/* 502 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var _Array$isArray = __webpack_require__(503);
+
+function _arrayWithHoles(arr) {
+ if (_Array$isArray(arr)) return arr;
+}
+
+module.exports = _arrayWithHoles, module.exports.__esModule = true, module.exports["default"] = module.exports;
+
+/***/ }),
+/* 503 */
+/***/ (function(module, exports, __webpack_require__) {
+
+module.exports = __webpack_require__(504);
+
+/***/ }),
+/* 504 */
+/***/ (function(module, exports, __webpack_require__) {
+
+module.exports = __webpack_require__(505);
+
+
+/***/ }),
+/* 505 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var parent = __webpack_require__(506);
+
+module.exports = parent;
+
+
+/***/ }),
+/* 506 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var parent = __webpack_require__(507);
+
+module.exports = parent;
+
+
+/***/ }),
+/* 507 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var parent = __webpack_require__(508);
+
+module.exports = parent;
+
+
+/***/ }),
+/* 508 */
+/***/ (function(module, exports, __webpack_require__) {
+
+__webpack_require__(509);
+var path = __webpack_require__(13);
+
+module.exports = path.Array.isArray;
+
+
+/***/ }),
+/* 509 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var $ = __webpack_require__(0);
+var isArray = __webpack_require__(80);
+
+// `Array.isArray` method
+// https://tc39.es/ecma262/#sec-array.isarray
+$({ target: 'Array', stat: true }, {
+ isArray: isArray
+});
+
+
+/***/ }),
+/* 510 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var _Symbol = __webpack_require__(225);
+
+var _getIteratorMethod = __webpack_require__(231);
+
+function _iterableToArrayLimit(arr, i) {
+ var _i = arr == null ? null : typeof _Symbol !== "undefined" && _getIteratorMethod(arr) || arr["@@iterator"];
+
+ if (_i == null) return;
+ var _arr = [];
+ var _n = true;
+ var _d = false;
+
+ var _s, _e;
+
+ try {
+ for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
+ _arr.push(_s.value);
+
+ if (i && _arr.length === i) break;
+ }
+ } catch (err) {
+ _d = true;
+ _e = err;
+ } finally {
+ try {
+ if (!_n && _i["return"] != null) _i["return"]();
+ } finally {
+ if (_d) throw _e;
+ }
+ }
+
+ return _arr;
+}
+
+module.exports = _iterableToArrayLimit, module.exports.__esModule = true, module.exports["default"] = module.exports;
+
+/***/ }),
+/* 511 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var _sliceInstanceProperty = __webpack_require__(512);
+
+var _Array$from = __webpack_require__(516);
+
+var arrayLikeToArray = __webpack_require__(520);
+
+function _unsupportedIterableToArray(o, minLen) {
+ var _context;
+
+ if (!o) return;
+ if (typeof o === "string") return arrayLikeToArray(o, minLen);
+
+ var n = _sliceInstanceProperty(_context = Object.prototype.toString.call(o)).call(_context, 8, -1);
+
+ if (n === "Object" && o.constructor) n = o.constructor.name;
+ if (n === "Map" || n === "Set") return _Array$from(o);
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return arrayLikeToArray(o, minLen);
+}
+
+module.exports = _unsupportedIterableToArray, module.exports.__esModule = true, module.exports["default"] = module.exports;
+
+/***/ }),
+/* 512 */
+/***/ (function(module, exports, __webpack_require__) {
+
+module.exports = __webpack_require__(513);
+
+/***/ }),
+/* 513 */
+/***/ (function(module, exports, __webpack_require__) {
+
+module.exports = __webpack_require__(514);
+
+
+/***/ }),
+/* 514 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var parent = __webpack_require__(515);
+
+module.exports = parent;
+
+
+/***/ }),
+/* 515 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var parent = __webpack_require__(222);
+
+module.exports = parent;
+
+
+/***/ }),
+/* 516 */
+/***/ (function(module, exports, __webpack_require__) {
+
+module.exports = __webpack_require__(517);
+
+/***/ }),
+/* 517 */
+/***/ (function(module, exports, __webpack_require__) {
+
+module.exports = __webpack_require__(518);
+
+
+/***/ }),
+/* 518 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var parent = __webpack_require__(519);
+
+module.exports = parent;
+
+
+/***/ }),
+/* 519 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var parent = __webpack_require__(230);
+
+module.exports = parent;
+
+
+/***/ }),
+/* 520 */
+/***/ (function(module, exports) {
+
+function _arrayLikeToArray(arr, len) {
+ if (len == null || len > arr.length) len = arr.length;
+
+ for (var i = 0, arr2 = new Array(len); i < len; i++) {
+ arr2[i] = arr[i];
+ }
+
+ return arr2;
+}
+
+module.exports = _arrayLikeToArray, module.exports.__esModule = true, module.exports["default"] = module.exports;
+
+/***/ }),
+/* 521 */
+/***/ (function(module, exports) {
+
+function _nonIterableRest() {
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
+}
+
+module.exports = _nonIterableRest, module.exports.__esModule = true, module.exports["default"] = module.exports;
+
+/***/ }),
+/* 522 */
+/***/ (function(module, exports, __webpack_require__) {
+
+module.exports = __webpack_require__(523);
+
+/***/ }),
+/* 523 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var parent = __webpack_require__(524);
+
+module.exports = parent;
+
+
+/***/ }),
+/* 524 */
+/***/ (function(module, exports, __webpack_require__) {
+
+__webpack_require__(525);
+var path = __webpack_require__(13);
+
+var Object = path.Object;
+
+var getOwnPropertyDescriptor = module.exports = function getOwnPropertyDescriptor(it, key) {
+ return Object.getOwnPropertyDescriptor(it, key);
+};
+
+if (Object.getOwnPropertyDescriptor.sham) getOwnPropertyDescriptor.sham = true;
+
+
+/***/ }),
+/* 525 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var $ = __webpack_require__(0);
+var fails = __webpack_require__(4);
+var toIndexedObject = __webpack_require__(33);
+var nativeGetOwnPropertyDescriptor = __webpack_require__(64).f;
+var DESCRIPTORS = __webpack_require__(19);
+
+var FAILS_ON_PRIMITIVES = fails(function () { nativeGetOwnPropertyDescriptor(1); });
+var FORCED = !DESCRIPTORS || FAILS_ON_PRIMITIVES;
+
+// `Object.getOwnPropertyDescriptor` method
+// https://tc39.es/ecma262/#sec-object.getownpropertydescriptor
+$({ target: 'Object', stat: true, forced: FORCED, sham: !DESCRIPTORS }, {
+ getOwnPropertyDescriptor: function getOwnPropertyDescriptor(it, key) {
+ return nativeGetOwnPropertyDescriptor(toIndexedObject(it), key);
+ }
+});
+
+
+/***/ }),
+/* 526 */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+var _ = __webpack_require__(1);
+
+var AVError = __webpack_require__(40);
+
+module.exports = function (AV) {
+ AV.Role = AV.Object.extend('_Role',
+ /** @lends AV.Role.prototype */
+ {
+ // Instance Methods
+
+ /**
+ * Represents a Role on the AV server. Roles represent groupings of
+ * Users for the purposes of granting permissions (e.g. specifying an ACL
+ * for an Object). Roles are specified by their sets of child users and
+ * child roles, all of which are granted any permissions that the parent
+ * role has.
+ *
+ *
Roles must have a name (which cannot be changed after creation of the
+ * role), and must specify an ACL.
+ * An AV.Role is a local representation of a role persisted to the AV
+ * cloud.
+ * @class AV.Role
+ * @param {String} name The name of the Role to create.
+ * @param {AV.ACL} acl The ACL for this role.
+ */
+ constructor: function constructor(name, acl) {
+ if (_.isString(name)) {
+ AV.Object.prototype.constructor.call(this, null, null);
+ this.setName(name);
+ } else {
+ AV.Object.prototype.constructor.call(this, name, acl);
+ }
+
+ if (acl) {
+ if (!(acl instanceof AV.ACL)) {
+ throw new TypeError('acl must be an instance of AV.ACL');
+ } else {
+ this.setACL(acl);
+ }
+ }
+ },
+
+ /**
+ * Gets the name of the role. You can alternatively call role.get("name")
+ *
+ * @return {String} the name of the role.
+ */
+ getName: function getName() {
+ return this.get('name');
+ },
+
+ /**
+ * Sets the name for a role. This value must be set before the role has
+ * been saved to the server, and cannot be set once the role has been
+ * saved.
+ *
+ *
+ * A role's name can only contain alphanumeric characters, _, -, and
+ * spaces.
+ *
+ *
+ *
This is equivalent to calling role.set("name", name)
+ *
+ * @param {String} name The name of the role.
+ */
+ setName: function setName(name, options) {
+ return this.set('name', name, options);
+ },
+
+ /**
+ * Gets the AV.Relation for the AV.Users that are direct
+ * children of this role. These users are granted any privileges that this
+ * role has been granted (e.g. read or write access through ACLs). You can
+ * add or remove users from the role through this relation.
+ *
+ *
This is equivalent to calling role.relation("users")
+ *
+ * @return {AV.Relation} the relation for the users belonging to this
+ * role.
+ */
+ getUsers: function getUsers() {
+ return this.relation('users');
+ },
+
+ /**
+ * Gets the AV.Relation for the AV.Roles that are direct
+ * children of this role. These roles' users are granted any privileges that
+ * this role has been granted (e.g. read or write access through ACLs). You
+ * can add or remove child roles from this role through this relation.
+ *
+ *
This is equivalent to calling role.relation("roles")
+ *
+ * @return {AV.Relation} the relation for the roles belonging to this
+ * role.
+ */
+ getRoles: function getRoles() {
+ return this.relation('roles');
+ },
+
+ /**
+ * @ignore
+ */
+ validate: function validate(attrs, options) {
+ if ('name' in attrs && attrs.name !== this.getName()) {
+ var newName = attrs.name;
+
+ if (this.id && this.id !== attrs.objectId) {
+ // Check to see if the objectId being set matches this.id.
+ // This happens during a fetch -- the id is set before calling fetch.
+ // Let the name be set in this case.
+ return new AVError(AVError.OTHER_CAUSE, "A role's name can only be set before it has been saved.");
+ }
+
+ if (!_.isString(newName)) {
+ return new AVError(AVError.OTHER_CAUSE, "A role's name must be a String.");
+ }
+
+ if (!/^[0-9a-zA-Z\-_ ]+$/.test(newName)) {
+ return new AVError(AVError.OTHER_CAUSE, "A role's name can only contain alphanumeric characters, _," + ' -, and spaces.');
+ }
+ }
+
+ if (AV.Object.prototype.validate) {
+ return AV.Object.prototype.validate.call(this, attrs, options);
+ }
+
+ return false;
+ }
+ });
+};
+
+/***/ }),
+/* 527 */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+var _interopRequireDefault = __webpack_require__(2);
+
+var _defineProperty2 = _interopRequireDefault(__webpack_require__(528));
+
+var _promise = _interopRequireDefault(__webpack_require__(10));
+
+var _map = _interopRequireDefault(__webpack_require__(39));
+
+var _find = _interopRequireDefault(__webpack_require__(104));
+
+var _stringify = _interopRequireDefault(__webpack_require__(34));
+
+var _ = __webpack_require__(1);
+
+var uuid = __webpack_require__(214);
+
+var AVError = __webpack_require__(40);
+
+var _require = __webpack_require__(25),
+ AVRequest = _require._request,
+ request = _require.request;
+
+var _require2 = __webpack_require__(61),
+ getAdapter = _require2.getAdapter;
+
+var PLATFORM_ANONYMOUS = 'anonymous';
+var PLATFORM_QQAPP = 'lc_qqapp';
+
+var mergeUnionDataIntoAuthData = function mergeUnionDataIntoAuthData() {
+ var defaultUnionIdPlatform = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'weixin';
+ return function (authData, unionId) {
+ var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
+ _ref$unionIdPlatform = _ref.unionIdPlatform,
+ unionIdPlatform = _ref$unionIdPlatform === void 0 ? defaultUnionIdPlatform : _ref$unionIdPlatform,
+ _ref$asMainAccount = _ref.asMainAccount,
+ asMainAccount = _ref$asMainAccount === void 0 ? false : _ref$asMainAccount;
+
+ if (typeof unionId !== 'string') throw new AVError(AVError.OTHER_CAUSE, 'unionId is not a string');
+ if (typeof unionIdPlatform !== 'string') throw new AVError(AVError.OTHER_CAUSE, 'unionIdPlatform is not a string');
+ return _.extend({}, authData, {
+ platform: unionIdPlatform,
+ unionid: unionId,
+ main_account: Boolean(asMainAccount)
+ });
+ };
+};
+
+module.exports = function (AV) {
+ /**
+ * @class
+ *
+ *
An AV.User object is a local representation of a user persisted to the
+ * LeanCloud server. This class is a subclass of an AV.Object, and retains the
+ * same functionality of an AV.Object, but also extends it with various
+ * user specific methods, like authentication, signing up, and validation of
+ * uniqueness.
+ */
+ AV.User = AV.Object.extend('_User',
+ /** @lends AV.User.prototype */
+ {
+ // Instance Variables
+ _isCurrentUser: false,
+ // Instance Methods
+
+ /**
+ * Internal method to handle special fields in a _User response.
+ * @private
+ */
+ _mergeMagicFields: function _mergeMagicFields(attrs) {
+ if (attrs.sessionToken) {
+ this._sessionToken = attrs.sessionToken;
+ delete attrs.sessionToken;
+ }
+
+ return AV.User.__super__._mergeMagicFields.call(this, attrs);
+ },
+
+ /**
+ * Removes null values from authData (which exist temporarily for
+ * unlinking)
+ * @private
+ */
+ _cleanupAuthData: function _cleanupAuthData() {
+ if (!this.isCurrent()) {
+ return;
+ }
+
+ var authData = this.get('authData');
+
+ if (!authData) {
+ return;
+ }
+
+ AV._objectEach(this.get('authData'), function (value, key) {
+ if (!authData[key]) {
+ delete authData[key];
+ }
+ });
+ },
+
+ /**
+ * Synchronizes authData for all providers.
+ * @private
+ */
+ _synchronizeAllAuthData: function _synchronizeAllAuthData() {
+ var authData = this.get('authData');
+
+ if (!authData) {
+ return;
+ }
+
+ var self = this;
+
+ AV._objectEach(this.get('authData'), function (value, key) {
+ self._synchronizeAuthData(key);
+ });
+ },
+
+ /**
+ * Synchronizes auth data for a provider (e.g. puts the access token in the
+ * right place to be used by the Facebook SDK).
+ * @private
+ */
+ _synchronizeAuthData: function _synchronizeAuthData(provider) {
+ if (!this.isCurrent()) {
+ return;
+ }
+
+ var authType;
+
+ if (_.isString(provider)) {
+ authType = provider;
+ provider = AV.User._authProviders[authType];
+ } else {
+ authType = provider.getAuthType();
+ }
+
+ var authData = this.get('authData');
+
+ if (!authData || !provider) {
+ return;
+ }
+
+ var success = provider.restoreAuthentication(authData[authType]);
+
+ if (!success) {
+ this.dissociateAuthData(provider);
+ }
+ },
+ _handleSaveResult: function _handleSaveResult(makeCurrent) {
+ // Clean up and synchronize the authData object, removing any unset values
+ if (makeCurrent && !AV._config.disableCurrentUser) {
+ this._isCurrentUser = true;
+ }
+
+ this._cleanupAuthData();
+
+ this._synchronizeAllAuthData(); // Don't keep the password around.
+
+
+ delete this._serverData.password;
+
+ this._rebuildEstimatedDataForKey('password');
+
+ this._refreshCache();
+
+ if ((makeCurrent || this.isCurrent()) && !AV._config.disableCurrentUser) {
+ // Some old version of leanengine-node-sdk will overwrite
+ // AV.User._saveCurrentUser which returns no Promise.
+ // So we need a Promise wrapper.
+ return _promise.default.resolve(AV.User._saveCurrentUser(this));
+ } else {
+ return _promise.default.resolve();
+ }
+ },
+
+ /**
+ * Unlike in the Android/iOS SDKs, logInWith is unnecessary, since you can
+ * call linkWith on the user (even if it doesn't exist yet on the server).
+ * @private
+ */
+ _linkWith: function _linkWith(provider, data) {
+ var _this = this;
+
+ var _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
+ _ref2$failOnNotExist = _ref2.failOnNotExist,
+ failOnNotExist = _ref2$failOnNotExist === void 0 ? false : _ref2$failOnNotExist,
+ useMasterKey = _ref2.useMasterKey,
+ sessionToken = _ref2.sessionToken,
+ user = _ref2.user;
+
+ var authType;
+
+ if (_.isString(provider)) {
+ authType = provider;
+ provider = AV.User._authProviders[provider];
+ } else {
+ authType = provider.getAuthType();
+ }
+
+ if (data) {
+ return this.save({
+ authData: (0, _defineProperty2.default)({}, authType, data)
+ }, {
+ useMasterKey: useMasterKey,
+ sessionToken: sessionToken,
+ user: user,
+ fetchWhenSave: !!this.get('authData'),
+ _failOnNotExist: failOnNotExist
+ }).then(function (model) {
+ return model._handleSaveResult(true).then(function () {
+ return model;
+ });
+ });
+ } else {
+ return provider.authenticate().then(function (result) {
+ return _this._linkWith(provider, result);
+ });
+ }
+ },
+
+ /**
+ * Associate the user with a third party authData.
+ * @since 3.3.0
+ * @param {Object} authData The response json data returned from third party token, maybe like { openid: 'abc123', access_token: '123abc', expires_in: 1382686496 }
+ * @param {string} platform Available platform for sign up.
+ * @return {Promise} A promise that is fulfilled with the user when completed.
+ * @example user.associateWithAuthData({
+ * openid: 'abc123',
+ * access_token: '123abc',
+ * expires_in: 1382686496
+ * }, 'weixin').then(function(user) {
+ * //Access user here
+ * }).catch(function(error) {
+ * //console.error("error: ", error);
+ * });
+ */
+ associateWithAuthData: function associateWithAuthData(authData, platform) {
+ return this._linkWith(platform, authData);
+ },
+
+ /**
+ * Associate the user with a third party authData and unionId.
+ * @since 3.5.0
+ * @param {Object} authData The response json data returned from third party token, maybe like { openid: 'abc123', access_token: '123abc', expires_in: 1382686496 }
+ * @param {string} platform Available platform for sign up.
+ * @param {string} unionId
+ * @param {Object} [unionLoginOptions]
+ * @param {string} [unionLoginOptions.unionIdPlatform = 'weixin'] unionId platform
+ * @param {boolean} [unionLoginOptions.asMainAccount = false] If true, the unionId will be associated with the user.
+ * @return {Promise} A promise that is fulfilled with the user when completed.
+ * @example user.associateWithAuthDataAndUnionId({
+ * openid: 'abc123',
+ * access_token: '123abc',
+ * expires_in: 1382686496
+ * }, 'weixin', 'union123', {
+ * unionIdPlatform: 'weixin',
+ * asMainAccount: true,
+ * }).then(function(user) {
+ * //Access user here
+ * }).catch(function(error) {
+ * //console.error("error: ", error);
+ * });
+ */
+ associateWithAuthDataAndUnionId: function associateWithAuthDataAndUnionId(authData, platform, unionId, unionOptions) {
+ return this._linkWith(platform, mergeUnionDataIntoAuthData()(authData, unionId, unionOptions));
+ },
+
+ /**
+ * Associate the user with the identity of the current mini-app.
+ * @since 4.6.0
+ * @param {Object} [authInfo]
+ * @param {Object} [option]
+ * @param {Boolean} [option.failOnNotExist] If true, the login request will fail when no user matches this authInfo.authData exists.
+ * @return {Promise}
+ */
+ associateWithMiniApp: function associateWithMiniApp(authInfo, option) {
+ var _this2 = this;
+
+ if (authInfo === undefined) {
+ var getAuthInfo = getAdapter('getAuthInfo');
+ return getAuthInfo().then(function (authInfo) {
+ return _this2._linkWith(authInfo.provider, authInfo.authData, option);
+ });
+ }
+
+ return this._linkWith(authInfo.provider, authInfo.authData, option);
+ },
+
+ /**
+ * 将用户与 QQ 小程序用户进行关联。适用于为已经在用户系统中存在的用户关联当前使用 QQ 小程序的微信帐号。
+ * 仅在 QQ 小程序中可用。
+ *
+ * @deprecated Please use {@link AV.User#associateWithMiniApp}
+ * @since 4.2.0
+ * @param {Object} [options]
+ * @param {boolean} [options.preferUnionId = false] 如果服务端在登录时获取到了用户的 UnionId,是否将 UnionId 保存在用户账号中。
+ * @param {string} [options.unionIdPlatform = 'qq'] (only take effect when preferUnionId) unionId platform
+ * @param {boolean} [options.asMainAccount = true] (only take effect when preferUnionId) If true, the unionId will be associated with the user.
+ * @return {Promise}
+ */
+ associateWithQQApp: function associateWithQQApp() {
+ var _this3 = this;
+
+ var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
+ _ref3$preferUnionId = _ref3.preferUnionId,
+ preferUnionId = _ref3$preferUnionId === void 0 ? false : _ref3$preferUnionId,
+ _ref3$unionIdPlatform = _ref3.unionIdPlatform,
+ unionIdPlatform = _ref3$unionIdPlatform === void 0 ? 'qq' : _ref3$unionIdPlatform,
+ _ref3$asMainAccount = _ref3.asMainAccount,
+ asMainAccount = _ref3$asMainAccount === void 0 ? true : _ref3$asMainAccount;
+
+ var getAuthInfo = getAdapter('getAuthInfo');
+ return getAuthInfo({
+ preferUnionId: preferUnionId,
+ asMainAccount: asMainAccount,
+ platform: unionIdPlatform
+ }).then(function (authInfo) {
+ authInfo.provider = PLATFORM_QQAPP;
+ return _this3.associateWithMiniApp(authInfo);
+ });
+ },
+
+ /**
+ * 将用户与微信小程序用户进行关联。适用于为已经在用户系统中存在的用户关联当前使用微信小程序的微信帐号。
+ * 仅在微信小程序中可用。
+ *
+ * @deprecated Please use {@link AV.User#associateWithMiniApp}
+ * @since 3.13.0
+ * @param {Object} [options]
+ * @param {boolean} [options.preferUnionId = false] 当用户满足 {@link https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/union-id.html 获取 UnionId 的条件} 时,是否将 UnionId 保存在用户账号中。
+ * @param {string} [options.unionIdPlatform = 'weixin'] (only take effect when preferUnionId) unionId platform
+ * @param {boolean} [options.asMainAccount = true] (only take effect when preferUnionId) If true, the unionId will be associated with the user.
+ * @return {Promise}
+ */
+ associateWithWeapp: function associateWithWeapp() {
+ var _this4 = this;
+
+ var _ref4 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
+ _ref4$preferUnionId = _ref4.preferUnionId,
+ preferUnionId = _ref4$preferUnionId === void 0 ? false : _ref4$preferUnionId,
+ _ref4$unionIdPlatform = _ref4.unionIdPlatform,
+ unionIdPlatform = _ref4$unionIdPlatform === void 0 ? 'weixin' : _ref4$unionIdPlatform,
+ _ref4$asMainAccount = _ref4.asMainAccount,
+ asMainAccount = _ref4$asMainAccount === void 0 ? true : _ref4$asMainAccount;
+
+ var getAuthInfo = getAdapter('getAuthInfo');
+ return getAuthInfo({
+ preferUnionId: preferUnionId,
+ asMainAccount: asMainAccount,
+ platform: unionIdPlatform
+ }).then(function (authInfo) {
+ return _this4.associateWithMiniApp(authInfo);
+ });
+ },
+
+ /**
+ * @deprecated renamed to {@link AV.User#associateWithWeapp}
+ * @return {Promise}
+ */
+ linkWithWeapp: function linkWithWeapp(options) {
+ console.warn('DEPRECATED: User#linkWithWeapp 已废弃,请使用 User#associateWithWeapp 代替');
+ return this.associateWithWeapp(options);
+ },
+
+ /**
+ * 将用户与 QQ 小程序用户进行关联。适用于为已经在用户系统中存在的用户关联当前使用 QQ 小程序的 QQ 帐号。
+ * 仅在 QQ 小程序中可用。
+ *
+ * @deprecated Please use {@link AV.User#associateWithMiniApp}
+ * @since 4.2.0
+ * @param {string} unionId
+ * @param {Object} [unionOptions]
+ * @param {string} [unionOptions.unionIdPlatform = 'qq'] unionId platform
+ * @param {boolean} [unionOptions.asMainAccount = false] If true, the unionId will be associated with the user.
+ * @return {Promise}
+ */
+ associateWithQQAppWithUnionId: function associateWithQQAppWithUnionId(unionId) {
+ var _this5 = this;
+
+ var _ref5 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
+ _ref5$unionIdPlatform = _ref5.unionIdPlatform,
+ unionIdPlatform = _ref5$unionIdPlatform === void 0 ? 'qq' : _ref5$unionIdPlatform,
+ _ref5$asMainAccount = _ref5.asMainAccount,
+ asMainAccount = _ref5$asMainAccount === void 0 ? false : _ref5$asMainAccount;
+
+ var getAuthInfo = getAdapter('getAuthInfo');
+ return getAuthInfo({
+ platform: unionIdPlatform
+ }).then(function (authInfo) {
+ authInfo = AV.User.mergeUnionId(authInfo, unionId, {
+ asMainAccount: asMainAccount
+ });
+ authInfo.provider = PLATFORM_QQAPP;
+ return _this5.associateWithMiniApp(authInfo);
+ });
+ },
+
+ /**
+ * 将用户与微信小程序用户进行关联。适用于为已经在用户系统中存在的用户关联当前使用微信小程序的微信帐号。
+ * 仅在微信小程序中可用。
+ *
+ * @deprecated Please use {@link AV.User#associateWithMiniApp}
+ * @since 3.13.0
+ * @param {string} unionId
+ * @param {Object} [unionOptions]
+ * @param {string} [unionOptions.unionIdPlatform = 'weixin'] unionId platform
+ * @param {boolean} [unionOptions.asMainAccount = false] If true, the unionId will be associated with the user.
+ * @return {Promise}
+ */
+ associateWithWeappWithUnionId: function associateWithWeappWithUnionId(unionId) {
+ var _this6 = this;
+
+ var _ref6 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
+ _ref6$unionIdPlatform = _ref6.unionIdPlatform,
+ unionIdPlatform = _ref6$unionIdPlatform === void 0 ? 'weixin' : _ref6$unionIdPlatform,
+ _ref6$asMainAccount = _ref6.asMainAccount,
+ asMainAccount = _ref6$asMainAccount === void 0 ? false : _ref6$asMainAccount;
+
+ var getAuthInfo = getAdapter('getAuthInfo');
+ return getAuthInfo({
+ platform: unionIdPlatform
+ }).then(function (authInfo) {
+ authInfo = AV.User.mergeUnionId(authInfo, unionId, {
+ asMainAccount: asMainAccount
+ });
+ return _this6.associateWithMiniApp(authInfo);
+ });
+ },
+
+ /**
+ * Unlinks a user from a service.
+ * @param {string} platform
+ * @return {Promise}
+ * @since 3.3.0
+ */
+ dissociateAuthData: function dissociateAuthData(provider) {
+ this.unset("authData.".concat(provider));
+ return this.save().then(function (model) {
+ return model._handleSaveResult(true).then(function () {
+ return model;
+ });
+ });
+ },
+
+ /**
+ * @private
+ * @deprecated
+ */
+ _unlinkFrom: function _unlinkFrom(provider) {
+ console.warn('DEPRECATED: User#_unlinkFrom 已废弃,请使用 User#dissociateAuthData 代替');
+ return this.dissociateAuthData(provider);
+ },
+
+ /**
+ * Checks whether a user is linked to a service.
+ * @private
+ */
+ _isLinked: function _isLinked(provider) {
+ var authType;
+
+ if (_.isString(provider)) {
+ authType = provider;
+ } else {
+ authType = provider.getAuthType();
+ }
+
+ var authData = this.get('authData') || {};
+ return !!authData[authType];
+ },
+
+ /**
+ * Checks whether a user is anonymous.
+ * @since 3.9.0
+ * @return {boolean}
+ */
+ isAnonymous: function isAnonymous() {
+ return this._isLinked(PLATFORM_ANONYMOUS);
+ },
+ logOut: function logOut() {
+ this._logOutWithAll();
+
+ this._isCurrentUser = false;
+ },
+
+ /**
+ * Deauthenticates all providers.
+ * @private
+ */
+ _logOutWithAll: function _logOutWithAll() {
+ var authData = this.get('authData');
+
+ if (!authData) {
+ return;
+ }
+
+ var self = this;
+
+ AV._objectEach(this.get('authData'), function (value, key) {
+ self._logOutWith(key);
+ });
+ },
+
+ /**
+ * Deauthenticates a single provider (e.g. removing access tokens from the
+ * Facebook SDK).
+ * @private
+ */
+ _logOutWith: function _logOutWith(provider) {
+ if (!this.isCurrent()) {
+ return;
+ }
+
+ if (_.isString(provider)) {
+ provider = AV.User._authProviders[provider];
+ }
+
+ if (provider && provider.deauthenticate) {
+ provider.deauthenticate();
+ }
+ },
+
+ /**
+ * Signs up a new user. You should call this instead of save for
+ * new AV.Users. This will create a new AV.User on the server, and
+ * also persist the session on disk so that you can access the user using
+ * current.
+ *
+ *
A username and password must be set before calling signUp.
+ *
+ * @param {Object} attrs Extra fields to set on the new user, or null.
+ * @param {AuthOptions} options
+ * @return {Promise} A promise that is fulfilled when the signup
+ * finishes.
+ * @see AV.User.signUp
+ */
+ signUp: function signUp(attrs, options) {
+ var error;
+ var username = attrs && attrs.username || this.get('username');
+
+ if (!username || username === '') {
+ error = new AVError(AVError.OTHER_CAUSE, 'Cannot sign up user with an empty name.');
+ throw error;
+ }
+
+ var password = attrs && attrs.password || this.get('password');
+
+ if (!password || password === '') {
+ error = new AVError(AVError.OTHER_CAUSE, 'Cannot sign up user with an empty password.');
+ throw error;
+ }
+
+ return this.save(attrs, options).then(function (model) {
+ if (model.isAnonymous()) {
+ model.unset("authData.".concat(PLATFORM_ANONYMOUS));
+ model._opSetQueue = [{}];
+ }
+
+ return model._handleSaveResult(true).then(function () {
+ return model;
+ });
+ });
+ },
+
+ /**
+ * Signs up a new user with mobile phone and sms code.
+ * You should call this instead of save for
+ * new AV.Users. This will create a new AV.User on the server, and
+ * also persist the session on disk so that you can access the user using
+ * current.
+ *
+ *
A username and password must be set before calling signUp.
+ *
+ * @param {Object} attrs Extra fields to set on the new user, or null.
+ * @param {AuthOptions} options
+ * @return {Promise} A promise that is fulfilled when the signup
+ * finishes.
+ * @see AV.User.signUpOrlogInWithMobilePhone
+ * @see AV.Cloud.requestSmsCode
+ */
+ signUpOrlogInWithMobilePhone: function signUpOrlogInWithMobilePhone(attrs) {
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
+ var error;
+ var mobilePhoneNumber = attrs && attrs.mobilePhoneNumber || this.get('mobilePhoneNumber');
+
+ if (!mobilePhoneNumber || mobilePhoneNumber === '') {
+ error = new AVError(AVError.OTHER_CAUSE, 'Cannot sign up or login user by mobilePhoneNumber ' + 'with an empty mobilePhoneNumber.');
+ throw error;
+ }
+
+ var smsCode = attrs && attrs.smsCode || this.get('smsCode');
+
+ if (!smsCode || smsCode === '') {
+ error = new AVError(AVError.OTHER_CAUSE, 'Cannot sign up or login user by mobilePhoneNumber ' + 'with an empty smsCode.');
+ throw error;
+ }
+
+ options._makeRequest = function (route, className, id, method, json) {
+ return AVRequest('usersByMobilePhone', null, null, 'POST', json);
+ };
+
+ return this.save(attrs, options).then(function (model) {
+ delete model.attributes.smsCode;
+ delete model._serverData.smsCode;
+ return model._handleSaveResult(true).then(function () {
+ return model;
+ });
+ });
+ },
+
+ /**
+ * The same with {@link AV.User.loginWithAuthData}, except that you can set attributes before login.
+ * @since 3.7.0
+ */
+ loginWithAuthData: function loginWithAuthData(authData, platform, options) {
+ return this._linkWith(platform, authData, options);
+ },
+
+ /**
+ * The same with {@link AV.User.loginWithAuthDataAndUnionId}, except that you can set attributes before login.
+ * @since 3.7.0
+ */
+ loginWithAuthDataAndUnionId: function loginWithAuthDataAndUnionId(authData, platform, unionId, unionLoginOptions) {
+ return this.loginWithAuthData(mergeUnionDataIntoAuthData()(authData, unionId, unionLoginOptions), platform, unionLoginOptions);
+ },
+
+ /**
+ * The same with {@link AV.User.loginWithWeapp}, except that you can set attributes before login.
+ * @deprecated please use {@link AV.User#loginWithMiniApp}
+ * @since 3.7.0
+ * @param {Object} [options]
+ * @param {boolean} [options.failOnNotExist] If true, the login request will fail when no user matches this authData exists.
+ * @param {boolean} [options.preferUnionId] 当用户满足 {@link https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/union-id.html 获取 UnionId 的条件} 时,是否使用 UnionId 登录。(since 3.13.0)
+ * @param {string} [options.unionIdPlatform = 'weixin'] (only take effect when preferUnionId) unionId platform
+ * @param {boolean} [options.asMainAccount = true] (only take effect when preferUnionId) If true, the unionId will be associated with the user.
+ * @return {Promise}
+ */
+ loginWithWeapp: function loginWithWeapp() {
+ var _this7 = this;
+
+ var _ref7 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
+ _ref7$preferUnionId = _ref7.preferUnionId,
+ preferUnionId = _ref7$preferUnionId === void 0 ? false : _ref7$preferUnionId,
+ _ref7$unionIdPlatform = _ref7.unionIdPlatform,
+ unionIdPlatform = _ref7$unionIdPlatform === void 0 ? 'weixin' : _ref7$unionIdPlatform,
+ _ref7$asMainAccount = _ref7.asMainAccount,
+ asMainAccount = _ref7$asMainAccount === void 0 ? true : _ref7$asMainAccount,
+ _ref7$failOnNotExist = _ref7.failOnNotExist,
+ failOnNotExist = _ref7$failOnNotExist === void 0 ? false : _ref7$failOnNotExist,
+ useMasterKey = _ref7.useMasterKey,
+ sessionToken = _ref7.sessionToken,
+ user = _ref7.user;
+
+ var getAuthInfo = getAdapter('getAuthInfo');
+ return getAuthInfo({
+ preferUnionId: preferUnionId,
+ asMainAccount: asMainAccount,
+ platform: unionIdPlatform
+ }).then(function (authInfo) {
+ return _this7.loginWithMiniApp(authInfo, {
+ failOnNotExist: failOnNotExist,
+ useMasterKey: useMasterKey,
+ sessionToken: sessionToken,
+ user: user
+ });
+ });
+ },
+
+ /**
+ * The same with {@link AV.User.loginWithWeappWithUnionId}, except that you can set attributes before login.
+ * @deprecated please use {@link AV.User#loginWithMiniApp}
+ * @since 3.13.0
+ */
+ loginWithWeappWithUnionId: function loginWithWeappWithUnionId(unionId) {
+ var _this8 = this;
+
+ var _ref8 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
+ _ref8$unionIdPlatform = _ref8.unionIdPlatform,
+ unionIdPlatform = _ref8$unionIdPlatform === void 0 ? 'weixin' : _ref8$unionIdPlatform,
+ _ref8$asMainAccount = _ref8.asMainAccount,
+ asMainAccount = _ref8$asMainAccount === void 0 ? false : _ref8$asMainAccount,
+ _ref8$failOnNotExist = _ref8.failOnNotExist,
+ failOnNotExist = _ref8$failOnNotExist === void 0 ? false : _ref8$failOnNotExist,
+ useMasterKey = _ref8.useMasterKey,
+ sessionToken = _ref8.sessionToken,
+ user = _ref8.user;
+
+ var getAuthInfo = getAdapter('getAuthInfo');
+ return getAuthInfo({
+ platform: unionIdPlatform
+ }).then(function (authInfo) {
+ authInfo = AV.User.mergeUnionId(authInfo, unionId, {
+ asMainAccount: asMainAccount
+ });
+ return _this8.loginWithMiniApp(authInfo, {
+ failOnNotExist: failOnNotExist,
+ useMasterKey: useMasterKey,
+ sessionToken: sessionToken,
+ user: user
+ });
+ });
+ },
+
+ /**
+ * The same with {@link AV.User.loginWithQQApp}, except that you can set attributes before login.
+ * @deprecated please use {@link AV.User#loginWithMiniApp}
+ * @since 4.2.0
+ * @param {Object} [options]
+ * @param {boolean} [options.failOnNotExist] If true, the login request will fail when no user matches this authData exists.
+ * @param {boolean} [options.preferUnionId] 如果服务端在登录时获取到了用户的 UnionId,是否将 UnionId 保存在用户账号中。
+ * @param {string} [options.unionIdPlatform = 'qq'] (only take effect when preferUnionId) unionId platform
+ * @param {boolean} [options.asMainAccount = true] (only take effect when preferUnionId) If true, the unionId will be associated with the user.
+ */
+ loginWithQQApp: function loginWithQQApp() {
+ var _this9 = this;
+
+ var _ref9 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
+ _ref9$preferUnionId = _ref9.preferUnionId,
+ preferUnionId = _ref9$preferUnionId === void 0 ? false : _ref9$preferUnionId,
+ _ref9$unionIdPlatform = _ref9.unionIdPlatform,
+ unionIdPlatform = _ref9$unionIdPlatform === void 0 ? 'qq' : _ref9$unionIdPlatform,
+ _ref9$asMainAccount = _ref9.asMainAccount,
+ asMainAccount = _ref9$asMainAccount === void 0 ? true : _ref9$asMainAccount,
+ _ref9$failOnNotExist = _ref9.failOnNotExist,
+ failOnNotExist = _ref9$failOnNotExist === void 0 ? false : _ref9$failOnNotExist,
+ useMasterKey = _ref9.useMasterKey,
+ sessionToken = _ref9.sessionToken,
+ user = _ref9.user;
+
+ var getAuthInfo = getAdapter('getAuthInfo');
+ return getAuthInfo({
+ preferUnionId: preferUnionId,
+ asMainAccount: asMainAccount,
+ platform: unionIdPlatform
+ }).then(function (authInfo) {
+ authInfo.provider = PLATFORM_QQAPP;
+ return _this9.loginWithMiniApp(authInfo, {
+ failOnNotExist: failOnNotExist,
+ useMasterKey: useMasterKey,
+ sessionToken: sessionToken,
+ user: user
+ });
+ });
+ },
+
+ /**
+ * The same with {@link AV.User.loginWithQQAppWithUnionId}, except that you can set attributes before login.
+ * @deprecated please use {@link AV.User#loginWithMiniApp}
+ * @since 4.2.0
+ */
+ loginWithQQAppWithUnionId: function loginWithQQAppWithUnionId(unionId) {
+ var _this10 = this;
+
+ var _ref10 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
+ _ref10$unionIdPlatfor = _ref10.unionIdPlatform,
+ unionIdPlatform = _ref10$unionIdPlatfor === void 0 ? 'qq' : _ref10$unionIdPlatfor,
+ _ref10$asMainAccount = _ref10.asMainAccount,
+ asMainAccount = _ref10$asMainAccount === void 0 ? false : _ref10$asMainAccount,
+ _ref10$failOnNotExist = _ref10.failOnNotExist,
+ failOnNotExist = _ref10$failOnNotExist === void 0 ? false : _ref10$failOnNotExist,
+ useMasterKey = _ref10.useMasterKey,
+ sessionToken = _ref10.sessionToken,
+ user = _ref10.user;
+
+ var getAuthInfo = getAdapter('getAuthInfo');
+ return getAuthInfo({
+ platform: unionIdPlatform
+ }).then(function (authInfo) {
+ authInfo = AV.User.mergeUnionId(authInfo, unionId, {
+ asMainAccount: asMainAccount
+ });
+ authInfo.provider = PLATFORM_QQAPP;
+ return _this10.loginWithMiniApp(authInfo, {
+ failOnNotExist: failOnNotExist,
+ useMasterKey: useMasterKey,
+ sessionToken: sessionToken,
+ user: user
+ });
+ });
+ },
+
+ /**
+ * The same with {@link AV.User.loginWithMiniApp}, except that you can set attributes before login.
+ * @since 4.6.0
+ */
+ loginWithMiniApp: function loginWithMiniApp(authInfo, option) {
+ var _this11 = this;
+
+ if (authInfo === undefined) {
+ var getAuthInfo = getAdapter('getAuthInfo');
+ return getAuthInfo().then(function (authInfo) {
+ return _this11.loginWithAuthData(authInfo.authData, authInfo.provider, option);
+ });
+ }
+
+ return this.loginWithAuthData(authInfo.authData, authInfo.provider, option);
+ },
+
+ /**
+ * Logs in a AV.User. On success, this saves the session to localStorage,
+ * so you can retrieve the currently logged in user using
+ * current.
+ *
+ *
A username and password must be set before calling logIn.
+ *
+ * @see AV.User.logIn
+ * @return {Promise} A promise that is fulfilled with the user when
+ * the login is complete.
+ */
+ logIn: function logIn() {
+ var model = this;
+ var request = AVRequest('login', null, null, 'POST', this.toJSON());
+ return request.then(function (resp) {
+ var serverAttrs = model.parse(resp);
+
+ model._finishFetch(serverAttrs);
+
+ return model._handleSaveResult(true).then(function () {
+ if (!serverAttrs.smsCode) delete model.attributes['smsCode'];
+ return model;
+ });
+ });
+ },
+
+ /**
+ * @see AV.Object#save
+ */
+ save: function save(arg1, arg2, arg3) {
+ var attrs, options;
+
+ if (_.isObject(arg1) || _.isNull(arg1) || _.isUndefined(arg1)) {
+ attrs = arg1;
+ options = arg2;
+ } else {
+ attrs = {};
+ attrs[arg1] = arg2;
+ options = arg3;
+ }
+
+ options = options || {};
+ return AV.Object.prototype.save.call(this, attrs, options).then(function (model) {
+ return model._handleSaveResult(false).then(function () {
+ return model;
+ });
+ });
+ },
+
+ /**
+ * Follow a user
+ * @since 0.3.0
+ * @param {Object | AV.User | String} options if an AV.User or string is given, it will be used as the target user.
+ * @param {AV.User | String} options.user The target user or user's objectId to follow.
+ * @param {Object} [options.attributes] key-value attributes dictionary to be used as
+ * conditions of followerQuery/followeeQuery.
+ * @param {AuthOptions} [authOptions]
+ */
+ follow: function follow(options, authOptions) {
+ if (!this.id) {
+ throw new Error('Please signin.');
+ }
+
+ var user;
+ var attributes;
+
+ if (options.user) {
+ user = options.user;
+ attributes = options.attributes;
+ } else {
+ user = options;
+ }
+
+ var userObjectId = _.isString(user) ? user : user.id;
+
+ if (!userObjectId) {
+ throw new Error('Invalid target user.');
+ }
+
+ var route = 'users/' + this.id + '/friendship/' + userObjectId;
+ var request = AVRequest(route, null, null, 'POST', AV._encode(attributes), authOptions);
+ return request;
+ },
+
+ /**
+ * Unfollow a user.
+ * @since 0.3.0
+ * @param {Object | AV.User | String} options if an AV.User or string is given, it will be used as the target user.
+ * @param {AV.User | String} options.user The target user or user's objectId to unfollow.
+ * @param {AuthOptions} [authOptions]
+ */
+ unfollow: function unfollow(options, authOptions) {
+ if (!this.id) {
+ throw new Error('Please signin.');
+ }
+
+ var user;
+
+ if (options.user) {
+ user = options.user;
+ } else {
+ user = options;
+ }
+
+ var userObjectId = _.isString(user) ? user : user.id;
+
+ if (!userObjectId) {
+ throw new Error('Invalid target user.');
+ }
+
+ var route = 'users/' + this.id + '/friendship/' + userObjectId;
+ var request = AVRequest(route, null, null, 'DELETE', null, authOptions);
+ return request;
+ },
+
+ /**
+ * Get the user's followers and followees.
+ * @since 4.8.0
+ * @param {Object} [options]
+ * @param {Number} [options.skip]
+ * @param {Number} [options.limit]
+ * @param {AuthOptions} [authOptions]
+ */
+ getFollowersAndFollowees: function getFollowersAndFollowees(options, authOptions) {
+ if (!this.id) {
+ throw new Error('Please signin.');
+ }
+
+ return request({
+ method: 'GET',
+ path: "/users/".concat(this.id, "/followersAndFollowees"),
+ query: {
+ skip: options && options.skip,
+ limit: options && options.limit,
+ include: 'follower,followee',
+ keys: 'follower,followee'
+ },
+ authOptions: authOptions
+ }).then(function (_ref11) {
+ var followers = _ref11.followers,
+ followees = _ref11.followees;
+ return {
+ followers: (0, _map.default)(followers).call(followers, function (_ref12) {
+ var follower = _ref12.follower;
+ return AV._decode(follower);
+ }),
+ followees: (0, _map.default)(followees).call(followees, function (_ref13) {
+ var followee = _ref13.followee;
+ return AV._decode(followee);
+ })
+ };
+ });
+ },
+
+ /**
+ *Create a follower query to query the user's followers.
+ * @since 0.3.0
+ * @see AV.User#followerQuery
+ */
+ followerQuery: function followerQuery() {
+ return AV.User.followerQuery(this.id);
+ },
+
+ /**
+ *Create a followee query to query the user's followees.
+ * @since 0.3.0
+ * @see AV.User#followeeQuery
+ */
+ followeeQuery: function followeeQuery() {
+ return AV.User.followeeQuery(this.id);
+ },
+
+ /**
+ * @see AV.Object#fetch
+ */
+ fetch: function fetch(fetchOptions, options) {
+ return AV.Object.prototype.fetch.call(this, fetchOptions, options).then(function (model) {
+ return model._handleSaveResult(false).then(function () {
+ return model;
+ });
+ });
+ },
+
+ /**
+ * Update user's new password safely based on old password.
+ * @param {String} oldPassword the old password.
+ * @param {String} newPassword the new password.
+ * @param {AuthOptions} options
+ */
+ updatePassword: function updatePassword(oldPassword, newPassword, options) {
+ var _this12 = this;
+
+ var route = 'users/' + this.id + '/updatePassword';
+ var params = {
+ old_password: oldPassword,
+ new_password: newPassword
+ };
+ var request = AVRequest(route, null, null, 'PUT', params, options);
+ return request.then(function (resp) {
+ _this12._finishFetch(_this12.parse(resp));
+
+ return _this12._handleSaveResult(true).then(function () {
+ return resp;
+ });
+ });
+ },
+
+ /**
+ * Returns true if current would return this user.
+ * @see AV.User#current
+ */
+ isCurrent: function isCurrent() {
+ return this._isCurrentUser;
+ },
+
+ /**
+ * Returns get("username").
+ * @return {String}
+ * @see AV.Object#get
+ */
+ getUsername: function getUsername() {
+ return this.get('username');
+ },
+
+ /**
+ * Returns get("mobilePhoneNumber").
+ * @return {String}
+ * @see AV.Object#get
+ */
+ getMobilePhoneNumber: function getMobilePhoneNumber() {
+ return this.get('mobilePhoneNumber');
+ },
+
+ /**
+ * Calls set("mobilePhoneNumber", phoneNumber, options) and returns the result.
+ * @param {String} mobilePhoneNumber
+ * @return {Boolean}
+ * @see AV.Object#set
+ */
+ setMobilePhoneNumber: function setMobilePhoneNumber(phone, options) {
+ return this.set('mobilePhoneNumber', phone, options);
+ },
+
+ /**
+ * Calls set("username", username, options) and returns the result.
+ * @param {String} username
+ * @return {Boolean}
+ * @see AV.Object#set
+ */
+ setUsername: function setUsername(username, options) {
+ return this.set('username', username, options);
+ },
+
+ /**
+ * Calls set("password", password, options) and returns the result.
+ * @param {String} password
+ * @return {Boolean}
+ * @see AV.Object#set
+ */
+ setPassword: function setPassword(password, options) {
+ return this.set('password', password, options);
+ },
+
+ /**
+ * Returns get("email").
+ * @return {String}
+ * @see AV.Object#get
+ */
+ getEmail: function getEmail() {
+ return this.get('email');
+ },
+
+ /**
+ * Calls set("email", email, options) and returns the result.
+ * @param {String} email
+ * @param {AuthOptions} options
+ * @return {Boolean}
+ * @see AV.Object#set
+ */
+ setEmail: function setEmail(email, options) {
+ return this.set('email', email, options);
+ },
+
+ /**
+ * Checks whether this user is the current user and has been authenticated.
+ * @deprecated 如果要判断当前用户的登录状态是否有效,请使用 currentUser.isAuthenticated().then(),
+ * 如果要判断该用户是否是当前登录用户,请使用 user.id === currentUser.id
+ * @return (Boolean) whether this user is the current user and is logged in.
+ */
+ authenticated: function authenticated() {
+ console.warn('DEPRECATED: 如果要判断当前用户的登录状态是否有效,请使用 currentUser.isAuthenticated().then(),如果要判断该用户是否是当前登录用户,请使用 user.id === currentUser.id。');
+ return !!this._sessionToken && !AV._config.disableCurrentUser && AV.User.current() && AV.User.current().id === this.id;
+ },
+
+ /**
+ * Detects if current sessionToken is valid.
+ *
+ * @since 2.0.0
+ * @return Promise.
+ */
+ isAuthenticated: function isAuthenticated() {
+ var _this13 = this;
+
+ return _promise.default.resolve().then(function () {
+ return !!_this13._sessionToken && AV.User._fetchUserBySessionToken(_this13._sessionToken).then(function () {
+ return true;
+ }, function (error) {
+ if (error.code === 211) {
+ return false;
+ }
+
+ throw error;
+ });
+ });
+ },
+
+ /**
+ * Get sessionToken of current user.
+ * @return {String} sessionToken
+ */
+ getSessionToken: function getSessionToken() {
+ return this._sessionToken;
+ },
+
+ /**
+ * Refresh sessionToken of current user.
+ * @since 2.1.0
+ * @param {AuthOptions} [options]
+ * @return {Promise.} user with refreshed sessionToken
+ */
+ refreshSessionToken: function refreshSessionToken(options) {
+ var _this14 = this;
+
+ return AVRequest("users/".concat(this.id, "/refreshSessionToken"), null, null, 'PUT', null, options).then(function (response) {
+ _this14._finishFetch(response);
+
+ return _this14._handleSaveResult(true).then(function () {
+ return _this14;
+ });
+ });
+ },
+
+ /**
+ * Get this user's Roles.
+ * @param {AuthOptions} [options]
+ * @return {Promise.} A promise that is fulfilled with the roles when
+ * the query is complete.
+ */
+ getRoles: function getRoles(options) {
+ var _context;
+
+ return (0, _find.default)(_context = AV.Relation.reverseQuery('_Role', 'users', this)).call(_context, options);
+ }
+ },
+ /** @lends AV.User */
+ {
+ // Class Variables
+ // The currently logged-in user.
+ _currentUser: null,
+ // Whether currentUser is known to match the serialized version on disk.
+ // This is useful for saving a localstorage check if you try to load
+ // _currentUser frequently while there is none stored.
+ _currentUserMatchesDisk: false,
+ // The localStorage key suffix that the current user is stored under.
+ _CURRENT_USER_KEY: 'currentUser',
+ // The mapping of auth provider names to actual providers
+ _authProviders: {},
+ // Class Methods
+
+ /**
+ * Signs up a new user with a username (or email) and password.
+ * This will create a new AV.User on the server, and also persist the
+ * session in localStorage so that you can access the user using
+ * {@link #current}.
+ *
+ * @param {String} username The username (or email) to sign up with.
+ * @param {String} password The password to sign up with.
+ * @param {Object} [attrs] Extra fields to set on the new user.
+ * @param {AuthOptions} [options]
+ * @return {Promise} A promise that is fulfilled with the user when
+ * the signup completes.
+ * @see AV.User#signUp
+ */
+ signUp: function signUp(username, password, attrs, options) {
+ attrs = attrs || {};
+ attrs.username = username;
+ attrs.password = password;
+
+ var user = AV.Object._create('_User');
+
+ return user.signUp(attrs, options);
+ },
+
+ /**
+ * Logs in a user with a username (or email) and password. On success, this
+ * saves the session to disk, so you can retrieve the currently logged in
+ * user using current.
+ *
+ * @param {String} username The username (or email) to log in with.
+ * @param {String} password The password to log in with.
+ * @return {Promise} A promise that is fulfilled with the user when
+ * the login completes.
+ * @see AV.User#logIn
+ */
+ logIn: function logIn(username, password) {
+ var user = AV.Object._create('_User');
+
+ user._finishFetch({
+ username: username,
+ password: password
+ });
+
+ return user.logIn();
+ },
+
+ /**
+ * Logs in a user with a session token. On success, this saves the session
+ * to disk, so you can retrieve the currently logged in user using
+ * current.
+ *
+ * @param {String} sessionToken The sessionToken to log in with.
+ * @return {Promise} A promise that is fulfilled with the user when
+ * the login completes.
+ */
+ become: function become(sessionToken) {
+ return this._fetchUserBySessionToken(sessionToken).then(function (user) {
+ return user._handleSaveResult(true).then(function () {
+ return user;
+ });
+ });
+ },
+ _fetchUserBySessionToken: function _fetchUserBySessionToken(sessionToken) {
+ if (sessionToken === undefined) {
+ return _promise.default.reject(new Error('The sessionToken cannot be undefined'));
+ }
+
+ var user = AV.Object._create('_User');
+
+ return request({
+ method: 'GET',
+ path: '/users/me',
+ authOptions: {
+ sessionToken: sessionToken
+ }
+ }).then(function (resp) {
+ var serverAttrs = user.parse(resp);
+
+ user._finishFetch(serverAttrs);
+
+ return user;
+ });
+ },
+
+ /**
+ * Logs in a user with a mobile phone number and sms code sent by
+ * AV.User.requestLoginSmsCode.On success, this
+ * saves the session to disk, so you can retrieve the currently logged in
+ * user using current.
+ *
+ * @param {String} mobilePhone The user's mobilePhoneNumber
+ * @param {String} smsCode The sms code sent by AV.User.requestLoginSmsCode
+ * @return {Promise} A promise that is fulfilled with the user when
+ * the login completes.
+ * @see AV.User#logIn
+ */
+ logInWithMobilePhoneSmsCode: function logInWithMobilePhoneSmsCode(mobilePhone, smsCode) {
+ var user = AV.Object._create('_User');
+
+ user._finishFetch({
+ mobilePhoneNumber: mobilePhone,
+ smsCode: smsCode
+ });
+
+ return user.logIn();
+ },
+
+ /**
+ * Signs up or logs in a user with a mobilePhoneNumber and smsCode.
+ * On success, this saves the session to disk, so you can retrieve the currently
+ * logged in user using current.
+ *
+ * @param {String} mobilePhoneNumber The user's mobilePhoneNumber.
+ * @param {String} smsCode The sms code sent by AV.Cloud.requestSmsCode
+ * @param {Object} attributes The user's other attributes such as username etc.
+ * @param {AuthOptions} options
+ * @return {Promise} A promise that is fulfilled with the user when
+ * the login completes.
+ * @see AV.User#signUpOrlogInWithMobilePhone
+ * @see AV.Cloud.requestSmsCode
+ */
+ signUpOrlogInWithMobilePhone: function signUpOrlogInWithMobilePhone(mobilePhoneNumber, smsCode, attrs, options) {
+ attrs = attrs || {};
+ attrs.mobilePhoneNumber = mobilePhoneNumber;
+ attrs.smsCode = smsCode;
+
+ var user = AV.Object._create('_User');
+
+ return user.signUpOrlogInWithMobilePhone(attrs, options);
+ },
+
+ /**
+ * Logs in a user with a mobile phone number and password. On success, this
+ * saves the session to disk, so you can retrieve the currently logged in
+ * user using current.
+ *
+ * @param {String} mobilePhone The user's mobilePhoneNumber
+ * @param {String} password The password to log in with.
+ * @return {Promise} A promise that is fulfilled with the user when
+ * the login completes.
+ * @see AV.User#logIn
+ */
+ logInWithMobilePhone: function logInWithMobilePhone(mobilePhone, password) {
+ var user = AV.Object._create('_User');
+
+ user._finishFetch({
+ mobilePhoneNumber: mobilePhone,
+ password: password
+ });
+
+ return user.logIn();
+ },
+
+ /**
+ * Logs in a user with email and password.
+ *
+ * @since 3.13.0
+ * @param {String} email The user's email.
+ * @param {String} password The password to log in with.
+ * @return {Promise} A promise that is fulfilled with the user when
+ * the login completes.
+ */
+ loginWithEmail: function loginWithEmail(email, password) {
+ var user = AV.Object._create('_User');
+
+ user._finishFetch({
+ email: email,
+ password: password
+ });
+
+ return user.logIn();
+ },
+
+ /**
+ * Signs up or logs in a user with a third party auth data(AccessToken).
+ * On success, this saves the session to disk, so you can retrieve the currently
+ * logged in user using current.
+ *
+ * @since 3.7.0
+ * @param {Object} authData The response json data returned from third party token, maybe like { openid: 'abc123', access_token: '123abc', expires_in: 1382686496 }
+ * @param {string} platform Available platform for sign up.
+ * @param {Object} [options]
+ * @param {boolean} [options.failOnNotExist] If true, the login request will fail when no user matches this authData exists.
+ * @return {Promise} A promise that is fulfilled with the user when
+ * the login completes.
+ * @example AV.User.loginWithAuthData({
+ * openid: 'abc123',
+ * access_token: '123abc',
+ * expires_in: 1382686496
+ * }, 'weixin').then(function(user) {
+ * //Access user here
+ * }).catch(function(error) {
+ * //console.error("error: ", error);
+ * });
+ * @see {@link https://leancloud.cn/docs/js_guide.html#绑定第三方平台账户}
+ */
+ loginWithAuthData: function loginWithAuthData(authData, platform, options) {
+ return AV.User._logInWith(platform, authData, options);
+ },
+
+ /**
+ * @deprecated renamed to {@link AV.User.loginWithAuthData}
+ */
+ signUpOrlogInWithAuthData: function signUpOrlogInWithAuthData() {
+ console.warn('DEPRECATED: User.signUpOrlogInWithAuthData 已废弃,请使用 User#loginWithAuthData 代替');
+ return this.loginWithAuthData.apply(this, arguments);
+ },
+
+ /**
+ * Signs up or logs in a user with a third party authData and unionId.
+ * @since 3.7.0
+ * @param {Object} authData The response json data returned from third party token, maybe like { openid: 'abc123', access_token: '123abc', expires_in: 1382686496 }
+ * @param {string} platform Available platform for sign up.
+ * @param {string} unionId
+ * @param {Object} [unionLoginOptions]
+ * @param {string} [unionLoginOptions.unionIdPlatform = 'weixin'] unionId platform
+ * @param {boolean} [unionLoginOptions.asMainAccount = false] If true, the unionId will be associated with the user.
+ * @param {boolean} [unionLoginOptions.failOnNotExist] If true, the login request will fail when no user matches this authData exists.
+ * @return {Promise} A promise that is fulfilled with the user when completed.
+ * @example AV.User.loginWithAuthDataAndUnionId({
+ * openid: 'abc123',
+ * access_token: '123abc',
+ * expires_in: 1382686496
+ * }, 'weixin', 'union123', {
+ * unionIdPlatform: 'weixin',
+ * asMainAccount: true,
+ * }).then(function(user) {
+ * //Access user here
+ * }).catch(function(error) {
+ * //console.error("error: ", error);
+ * });
+ */
+ loginWithAuthDataAndUnionId: function loginWithAuthDataAndUnionId(authData, platform, unionId, unionLoginOptions) {
+ return this.loginWithAuthData(mergeUnionDataIntoAuthData()(authData, unionId, unionLoginOptions), platform, unionLoginOptions);
+ },
+
+ /**
+ * @deprecated renamed to {@link AV.User.loginWithAuthDataAndUnionId}
+ * @since 3.5.0
+ */
+ signUpOrlogInWithAuthDataAndUnionId: function signUpOrlogInWithAuthDataAndUnionId() {
+ console.warn('DEPRECATED: User.signUpOrlogInWithAuthDataAndUnionId 已废弃,请使用 User#loginWithAuthDataAndUnionId 代替');
+ return this.loginWithAuthDataAndUnionId.apply(this, arguments);
+ },
+
+ /**
+ * Merge unionId into authInfo.
+ * @since 4.6.0
+ * @param {Object} authInfo
+ * @param {String} unionId
+ * @param {Object} [unionIdOption]
+ * @param {Boolean} [unionIdOption.asMainAccount] If true, the unionId will be associated with the user.
+ */
+ mergeUnionId: function mergeUnionId(authInfo, unionId) {
+ var _ref14 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
+ _ref14$asMainAccount = _ref14.asMainAccount,
+ asMainAccount = _ref14$asMainAccount === void 0 ? false : _ref14$asMainAccount;
+
+ authInfo = JSON.parse((0, _stringify.default)(authInfo));
+ var _authInfo = authInfo,
+ authData = _authInfo.authData,
+ platform = _authInfo.platform;
+ authData.platform = platform;
+ authData.main_account = asMainAccount;
+ authData.unionid = unionId;
+ return authInfo;
+ },
+
+ /**
+ * 使用当前使用微信小程序的微信用户身份注册或登录,成功后用户的 session 会在设备上持久化保存,之后可以使用 AV.User.current() 获取当前登录用户。
+ * 仅在微信小程序中可用。
+ *
+ * @deprecated please use {@link AV.User.loginWithMiniApp}
+ * @since 2.0.0
+ * @param {Object} [options]
+ * @param {boolean} [options.preferUnionId] 当用户满足 {@link https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/union-id.html 获取 UnionId 的条件} 时,是否使用 UnionId 登录。(since 3.13.0)
+ * @param {string} [options.unionIdPlatform = 'weixin'] (only take effect when preferUnionId) unionId platform
+ * @param {boolean} [options.asMainAccount = true] (only take effect when preferUnionId) If true, the unionId will be associated with the user.
+ * @param {boolean} [options.failOnNotExist] If true, the login request will fail when no user matches this authData exists. (since v3.7.0)
+ * @return {Promise.}
+ */
+ loginWithWeapp: function loginWithWeapp() {
+ var _this15 = this;
+
+ var _ref15 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
+ _ref15$preferUnionId = _ref15.preferUnionId,
+ preferUnionId = _ref15$preferUnionId === void 0 ? false : _ref15$preferUnionId,
+ _ref15$unionIdPlatfor = _ref15.unionIdPlatform,
+ unionIdPlatform = _ref15$unionIdPlatfor === void 0 ? 'weixin' : _ref15$unionIdPlatfor,
+ _ref15$asMainAccount = _ref15.asMainAccount,
+ asMainAccount = _ref15$asMainAccount === void 0 ? true : _ref15$asMainAccount,
+ _ref15$failOnNotExist = _ref15.failOnNotExist,
+ failOnNotExist = _ref15$failOnNotExist === void 0 ? false : _ref15$failOnNotExist,
+ useMasterKey = _ref15.useMasterKey,
+ sessionToken = _ref15.sessionToken,
+ user = _ref15.user;
+
+ var getAuthInfo = getAdapter('getAuthInfo');
+ return getAuthInfo({
+ preferUnionId: preferUnionId,
+ asMainAccount: asMainAccount,
+ platform: unionIdPlatform
+ }).then(function (authInfo) {
+ return _this15.loginWithMiniApp(authInfo, {
+ failOnNotExist: failOnNotExist,
+ useMasterKey: useMasterKey,
+ sessionToken: sessionToken,
+ user: user
+ });
+ });
+ },
+
+ /**
+ * 使用当前使用微信小程序的微信用户身份注册或登录,
+ * 仅在微信小程序中可用。
+ *
+ * @deprecated please use {@link AV.User.loginWithMiniApp}
+ * @since 3.13.0
+ * @param {Object} [unionLoginOptions]
+ * @param {string} [unionLoginOptions.unionIdPlatform = 'weixin'] unionId platform
+ * @param {boolean} [unionLoginOptions.asMainAccount = false] If true, the unionId will be associated with the user.
+ * @param {boolean} [unionLoginOptions.failOnNotExist] If true, the login request will fail when no user matches this authData exists. * @return {Promise.}
+ */
+ loginWithWeappWithUnionId: function loginWithWeappWithUnionId(unionId) {
+ var _this16 = this;
+
+ var _ref16 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
+ _ref16$unionIdPlatfor = _ref16.unionIdPlatform,
+ unionIdPlatform = _ref16$unionIdPlatfor === void 0 ? 'weixin' : _ref16$unionIdPlatfor,
+ _ref16$asMainAccount = _ref16.asMainAccount,
+ asMainAccount = _ref16$asMainAccount === void 0 ? false : _ref16$asMainAccount,
+ _ref16$failOnNotExist = _ref16.failOnNotExist,
+ failOnNotExist = _ref16$failOnNotExist === void 0 ? false : _ref16$failOnNotExist,
+ useMasterKey = _ref16.useMasterKey,
+ sessionToken = _ref16.sessionToken,
+ user = _ref16.user;
+
+ var getAuthInfo = getAdapter('getAuthInfo');
+ return getAuthInfo({
+ platform: unionIdPlatform
+ }).then(function (authInfo) {
+ authInfo = AV.User.mergeUnionId(authInfo, unionId, {
+ asMainAccount: asMainAccount
+ });
+ return _this16.loginWithMiniApp(authInfo, {
+ failOnNotExist: failOnNotExist,
+ useMasterKey: useMasterKey,
+ sessionToken: sessionToken,
+ user: user
+ });
+ });
+ },
+
+ /**
+ * 使用当前使用 QQ 小程序的 QQ 用户身份注册或登录,成功后用户的 session 会在设备上持久化保存,之后可以使用 AV.User.current() 获取当前登录用户。
+ * 仅在 QQ 小程序中可用。
+ *
+ * @deprecated please use {@link AV.User.loginWithMiniApp}
+ * @since 4.2.0
+ * @param {Object} [options]
+ * @param {boolean} [options.preferUnionId] 如果服务端在登录时获取到了用户的 UnionId,是否将 UnionId 保存在用户账号中。
+ * @param {string} [options.unionIdPlatform = 'qq'] (only take effect when preferUnionId) unionId platform
+ * @param {boolean} [options.asMainAccount = true] (only take effect when preferUnionId) If true, the unionId will be associated with the user.
+ * @param {boolean} [options.failOnNotExist] If true, the login request will fail when no user matches this authData exists. (since v3.7.0)
+ * @return {Promise.}
+ */
+ loginWithQQApp: function loginWithQQApp() {
+ var _this17 = this;
+
+ var _ref17 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
+ _ref17$preferUnionId = _ref17.preferUnionId,
+ preferUnionId = _ref17$preferUnionId === void 0 ? false : _ref17$preferUnionId,
+ _ref17$unionIdPlatfor = _ref17.unionIdPlatform,
+ unionIdPlatform = _ref17$unionIdPlatfor === void 0 ? 'qq' : _ref17$unionIdPlatfor,
+ _ref17$asMainAccount = _ref17.asMainAccount,
+ asMainAccount = _ref17$asMainAccount === void 0 ? true : _ref17$asMainAccount,
+ _ref17$failOnNotExist = _ref17.failOnNotExist,
+ failOnNotExist = _ref17$failOnNotExist === void 0 ? false : _ref17$failOnNotExist,
+ useMasterKey = _ref17.useMasterKey,
+ sessionToken = _ref17.sessionToken,
+ user = _ref17.user;
+
+ var getAuthInfo = getAdapter('getAuthInfo');
+ return getAuthInfo({
+ preferUnionId: preferUnionId,
+ asMainAccount: asMainAccount,
+ platform: unionIdPlatform
+ }).then(function (authInfo) {
+ authInfo.provider = PLATFORM_QQAPP;
+ return _this17.loginWithMiniApp(authInfo, {
+ failOnNotExist: failOnNotExist,
+ useMasterKey: useMasterKey,
+ sessionToken: sessionToken,
+ user: user
+ });
+ });
+ },
+
+ /**
+ * 使用当前使用 QQ 小程序的 QQ 用户身份注册或登录,
+ * 仅在 QQ 小程序中可用。
+ *
+ * @deprecated please use {@link AV.User.loginWithMiniApp}
+ * @since 4.2.0
+ * @param {Object} [unionLoginOptions]
+ * @param {string} [unionLoginOptions.unionIdPlatform = 'qq'] unionId platform
+ * @param {boolean} [unionLoginOptions.asMainAccount = false] If true, the unionId will be associated with the user.
+ * @param {boolean} [unionLoginOptions.failOnNotExist] If true, the login request will fail when no user matches this authData exists.
+ * @return {Promise.}
+ */
+ loginWithQQAppWithUnionId: function loginWithQQAppWithUnionId(unionId) {
+ var _this18 = this;
+
+ var _ref18 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
+ _ref18$unionIdPlatfor = _ref18.unionIdPlatform,
+ unionIdPlatform = _ref18$unionIdPlatfor === void 0 ? 'qq' : _ref18$unionIdPlatfor,
+ _ref18$asMainAccount = _ref18.asMainAccount,
+ asMainAccount = _ref18$asMainAccount === void 0 ? false : _ref18$asMainAccount,
+ _ref18$failOnNotExist = _ref18.failOnNotExist,
+ failOnNotExist = _ref18$failOnNotExist === void 0 ? false : _ref18$failOnNotExist,
+ useMasterKey = _ref18.useMasterKey,
+ sessionToken = _ref18.sessionToken,
+ user = _ref18.user;
+
+ var getAuthInfo = getAdapter('getAuthInfo');
+ return getAuthInfo({
+ platform: unionIdPlatform
+ }).then(function (authInfo) {
+ authInfo = AV.User.mergeUnionId(authInfo, unionId, {
+ asMainAccount: asMainAccount
+ });
+ authInfo.provider = PLATFORM_QQAPP;
+ return _this18.loginWithMiniApp(authInfo, {
+ failOnNotExist: failOnNotExist,
+ useMasterKey: useMasterKey,
+ sessionToken: sessionToken,
+ user: user
+ });
+ });
+ },
+
+ /**
+ * Register or login using the identity of the current mini-app.
+ * @param {Object} authInfo
+ * @param {Object} [option]
+ * @param {Boolean} [option.failOnNotExist] If true, the login request will fail when no user matches this authInfo.authData exists.
+ */
+ loginWithMiniApp: function loginWithMiniApp(authInfo, option) {
+ var _this19 = this;
+
+ if (authInfo === undefined) {
+ var getAuthInfo = getAdapter('getAuthInfo');
+ return getAuthInfo().then(function (authInfo) {
+ return _this19.loginWithAuthData(authInfo.authData, authInfo.provider, option);
+ });
+ }
+
+ return this.loginWithAuthData(authInfo.authData, authInfo.provider, option);
+ },
+
+ /**
+ * Only use for DI in tests to produce deterministic IDs.
+ */
+ _genId: function _genId() {
+ return uuid();
+ },
+
+ /**
+ * Creates an anonymous user.
+ *
+ * @since 3.9.0
+ * @return {Promise.}
+ */
+ loginAnonymously: function loginAnonymously() {
+ return this.loginWithAuthData({
+ id: AV.User._genId()
+ }, 'anonymous');
+ },
+ associateWithAuthData: function associateWithAuthData(userObj, platform, authData) {
+ console.warn('DEPRECATED: User.associateWithAuthData 已废弃,请使用 User#associateWithAuthData 代替');
+ return userObj._linkWith(platform, authData);
+ },
+
+ /**
+ * Logs out the currently logged in user session. This will remove the
+ * session from disk, log out of linked services, and future calls to
+ * current will return null.
+ * @return {Promise}
+ */
+ logOut: function logOut() {
+ if (AV._config.disableCurrentUser) {
+ console.warn('AV.User.current() was disabled in multi-user environment, call logOut() from user object instead https://leancloud.cn/docs/leanengine-node-sdk-upgrade-1.html');
+ return _promise.default.resolve(null);
+ }
+
+ if (AV.User._currentUser !== null) {
+ AV.User._currentUser._logOutWithAll();
+
+ AV.User._currentUser._isCurrentUser = false;
+ }
+
+ AV.User._currentUserMatchesDisk = true;
+ AV.User._currentUser = null;
+ return AV.localStorage.removeItemAsync(AV._getAVPath(AV.User._CURRENT_USER_KEY)).then(function () {
+ return AV._refreshSubscriptionId();
+ });
+ },
+
+ /**
+ *Create a follower query for special user to query the user's followers.
+ * @param {String} userObjectId The user object id.
+ * @return {AV.FriendShipQuery}
+ * @since 0.3.0
+ */
+ followerQuery: function followerQuery(userObjectId) {
+ if (!userObjectId || !_.isString(userObjectId)) {
+ throw new Error('Invalid user object id.');
+ }
+
+ var query = new AV.FriendShipQuery('_Follower');
+ query._friendshipTag = 'follower';
+ query.equalTo('user', AV.Object.createWithoutData('_User', userObjectId));
+ return query;
+ },
+
+ /**
+ *Create a followee query for special user to query the user's followees.
+ * @param {String} userObjectId The user object id.
+ * @return {AV.FriendShipQuery}
+ * @since 0.3.0
+ */
+ followeeQuery: function followeeQuery(userObjectId) {
+ if (!userObjectId || !_.isString(userObjectId)) {
+ throw new Error('Invalid user object id.');
+ }
+
+ var query = new AV.FriendShipQuery('_Followee');
+ query._friendshipTag = 'followee';
+ query.equalTo('user', AV.Object.createWithoutData('_User', userObjectId));
+ return query;
+ },
+
+ /**
+ * Requests a password reset email to be sent to the specified email address
+ * associated with the user account. This email allows the user to securely
+ * reset their password on the AV site.
+ *
+ * @param {String} email The email address associated with the user that
+ * forgot their password.
+ * @return {Promise}
+ */
+ requestPasswordReset: function requestPasswordReset(email) {
+ var json = {
+ email: email
+ };
+ var request = AVRequest('requestPasswordReset', null, null, 'POST', json);
+ return request;
+ },
+
+ /**
+ * Requests a verify email to be sent to the specified email address
+ * associated with the user account. This email allows the user to securely
+ * verify their email address on the AV site.
+ *
+ * @param {String} email The email address associated with the user that
+ * doesn't verify their email address.
+ * @return {Promise}
+ */
+ requestEmailVerify: function requestEmailVerify(email) {
+ var json = {
+ email: email
+ };
+ var request = AVRequest('requestEmailVerify', null, null, 'POST', json);
+ return request;
+ },
+
+ /**
+ * Requests a verify sms code to be sent to the specified mobile phone
+ * number associated with the user account. This sms code allows the user to
+ * verify their mobile phone number by calling AV.User.verifyMobilePhone
+ *
+ * @param {String} mobilePhoneNumber The mobile phone number associated with the
+ * user that doesn't verify their mobile phone number.
+ * @param {SMSAuthOptions} [options]
+ * @return {Promise}
+ */
+ requestMobilePhoneVerify: function requestMobilePhoneVerify(mobilePhoneNumber) {
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
+ var data = {
+ mobilePhoneNumber: mobilePhoneNumber
+ };
+
+ if (options.validateToken) {
+ data.validate_token = options.validateToken;
+ }
+
+ var request = AVRequest('requestMobilePhoneVerify', null, null, 'POST', data, options);
+ return request;
+ },
+
+ /**
+ * Requests a reset password sms code to be sent to the specified mobile phone
+ * number associated with the user account. This sms code allows the user to
+ * reset their account's password by calling AV.User.resetPasswordBySmsCode
+ *
+ * @param {String} mobilePhoneNumber The mobile phone number associated with the
+ * user that doesn't verify their mobile phone number.
+ * @param {SMSAuthOptions} [options]
+ * @return {Promise}
+ */
+ requestPasswordResetBySmsCode: function requestPasswordResetBySmsCode(mobilePhoneNumber) {
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
+ var data = {
+ mobilePhoneNumber: mobilePhoneNumber
+ };
+
+ if (options.validateToken) {
+ data.validate_token = options.validateToken;
+ }
+
+ var request = AVRequest('requestPasswordResetBySmsCode', null, null, 'POST', data, options);
+ return request;
+ },
+
+ /**
+ * Requests a change mobile phone number sms code to be sent to the mobilePhoneNumber.
+ * This sms code allows current user to reset it's mobilePhoneNumber by
+ * calling {@link AV.User.changePhoneNumber}
+ * @since 4.7.0
+ * @param {String} mobilePhoneNumber
+ * @param {Number} [ttl] ttl of sms code (default is 6 minutes)
+ * @param {SMSAuthOptions} [options]
+ * @return {Promise}
+ */
+ requestChangePhoneNumber: function requestChangePhoneNumber(mobilePhoneNumber, ttl, options) {
+ var data = {
+ mobilePhoneNumber: mobilePhoneNumber
+ };
+
+ if (ttl) {
+ data.ttl = options.ttl;
+ }
+
+ if (options && options.validateToken) {
+ data.validate_token = options.validateToken;
+ }
+
+ return AVRequest('requestChangePhoneNumber', null, null, 'POST', data, options);
+ },
+
+ /**
+ * Makes a call to reset user's account mobilePhoneNumber by sms code.
+ * The sms code is sent by {@link AV.User.requestChangePhoneNumber}
+ * @since 4.7.0
+ * @param {String} mobilePhoneNumber
+ * @param {String} code The sms code.
+ * @return {Promise}
+ */
+ changePhoneNumber: function changePhoneNumber(mobilePhoneNumber, code) {
+ var data = {
+ mobilePhoneNumber: mobilePhoneNumber,
+ code: code
+ };
+ return AVRequest('changePhoneNumber', null, null, 'POST', data);
+ },
+
+ /**
+ * Makes a call to reset user's account password by sms code and new password.
+ * The sms code is sent by AV.User.requestPasswordResetBySmsCode.
+ * @param {String} code The sms code sent by AV.User.Cloud.requestSmsCode
+ * @param {String} password The new password.
+ * @return {Promise} A promise that will be resolved with the result
+ * of the function.
+ */
+ resetPasswordBySmsCode: function resetPasswordBySmsCode(code, password) {
+ var json = {
+ password: password
+ };
+ var request = AVRequest('resetPasswordBySmsCode', null, code, 'PUT', json);
+ return request;
+ },
+
+ /**
+ * Makes a call to verify sms code that sent by AV.User.Cloud.requestSmsCode
+ * If verify successfully,the user mobilePhoneVerified attribute will be true.
+ * @param {String} code The sms code sent by AV.User.Cloud.requestSmsCode
+ * @return {Promise} A promise that will be resolved with the result
+ * of the function.
+ */
+ verifyMobilePhone: function verifyMobilePhone(code) {
+ var request = AVRequest('verifyMobilePhone', null, code, 'POST', null);
+ return request;
+ },
+
+ /**
+ * Requests a logIn sms code to be sent to the specified mobile phone
+ * number associated with the user account. This sms code allows the user to
+ * login by AV.User.logInWithMobilePhoneSmsCode function.
+ *
+ * @param {String} mobilePhoneNumber The mobile phone number associated with the
+ * user that want to login by AV.User.logInWithMobilePhoneSmsCode
+ * @param {SMSAuthOptions} [options]
+ * @return {Promise}
+ */
+ requestLoginSmsCode: function requestLoginSmsCode(mobilePhoneNumber) {
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
+ var data = {
+ mobilePhoneNumber: mobilePhoneNumber
+ };
+
+ if (options.validateToken) {
+ data.validate_token = options.validateToken;
+ }
+
+ var request = AVRequest('requestLoginSmsCode', null, null, 'POST', data, options);
+ return request;
+ },
+
+ /**
+ * Retrieves the currently logged in AVUser with a valid session,
+ * either from memory or localStorage, if necessary.
+ * @return {Promise.} resolved with the currently logged in AV.User.
+ */
+ currentAsync: function currentAsync() {
+ if (AV._config.disableCurrentUser) {
+ console.warn('AV.User.currentAsync() was disabled in multi-user environment, access user from request instead https://leancloud.cn/docs/leanengine-node-sdk-upgrade-1.html');
+ return _promise.default.resolve(null);
+ }
+
+ if (AV.User._currentUser) {
+ return _promise.default.resolve(AV.User._currentUser);
+ }
+
+ if (AV.User._currentUserMatchesDisk) {
+ return _promise.default.resolve(AV.User._currentUser);
+ }
+
+ return AV.localStorage.getItemAsync(AV._getAVPath(AV.User._CURRENT_USER_KEY)).then(function (userData) {
+ if (!userData) {
+ return null;
+ } // Load the user from local storage.
+
+
+ AV.User._currentUserMatchesDisk = true;
+ AV.User._currentUser = AV.Object._create('_User');
+ AV.User._currentUser._isCurrentUser = true;
+ var json = JSON.parse(userData);
+ AV.User._currentUser.id = json._id;
+ delete json._id;
+ AV.User._currentUser._sessionToken = json._sessionToken;
+ delete json._sessionToken;
+
+ AV.User._currentUser._finishFetch(json); //AV.User._currentUser.set(json);
+
+
+ AV.User._currentUser._synchronizeAllAuthData();
+
+ AV.User._currentUser._refreshCache();
+
+ AV.User._currentUser._opSetQueue = [{}];
+ return AV.User._currentUser;
+ });
+ },
+
+ /**
+ * Retrieves the currently logged in AVUser with a valid session,
+ * either from memory or localStorage, if necessary.
+ * @return {AV.User} The currently logged in AV.User.
+ */
+ current: function current() {
+ if (AV._config.disableCurrentUser) {
+ console.warn('AV.User.current() was disabled in multi-user environment, access user from request instead https://leancloud.cn/docs/leanengine-node-sdk-upgrade-1.html');
+ return null;
+ }
+
+ if (AV.localStorage.async) {
+ var error = new Error('Synchronous API User.current() is not available in this runtime. Use User.currentAsync() instead.');
+ error.code = 'SYNC_API_NOT_AVAILABLE';
+ throw error;
+ }
+
+ if (AV.User._currentUser) {
+ return AV.User._currentUser;
+ }
+
+ if (AV.User._currentUserMatchesDisk) {
+ return AV.User._currentUser;
+ } // Load the user from local storage.
+
+
+ AV.User._currentUserMatchesDisk = true;
+ var userData = AV.localStorage.getItem(AV._getAVPath(AV.User._CURRENT_USER_KEY));
+
+ if (!userData) {
+ return null;
+ }
+
+ AV.User._currentUser = AV.Object._create('_User');
+ AV.User._currentUser._isCurrentUser = true;
+ var json = JSON.parse(userData);
+ AV.User._currentUser.id = json._id;
+ delete json._id;
+ AV.User._currentUser._sessionToken = json._sessionToken;
+ delete json._sessionToken;
+
+ AV.User._currentUser._finishFetch(json); //AV.User._currentUser.set(json);
+
+
+ AV.User._currentUser._synchronizeAllAuthData();
+
+ AV.User._currentUser._refreshCache();
+
+ AV.User._currentUser._opSetQueue = [{}];
+ return AV.User._currentUser;
+ },
+
+ /**
+ * Persists a user as currentUser to localStorage, and into the singleton.
+ * @private
+ */
+ _saveCurrentUser: function _saveCurrentUser(user) {
+ var promise;
+
+ if (AV.User._currentUser !== user) {
+ promise = AV.User.logOut();
+ } else {
+ promise = _promise.default.resolve();
+ }
+
+ return promise.then(function () {
+ user._isCurrentUser = true;
+ AV.User._currentUser = user;
+
+ var json = user._toFullJSON();
+
+ json._id = user.id;
+ json._sessionToken = user._sessionToken;
+ return AV.localStorage.setItemAsync(AV._getAVPath(AV.User._CURRENT_USER_KEY), (0, _stringify.default)(json)).then(function () {
+ AV.User._currentUserMatchesDisk = true;
+ return AV._refreshSubscriptionId();
+ });
+ });
+ },
+ _registerAuthenticationProvider: function _registerAuthenticationProvider(provider) {
+ AV.User._authProviders[provider.getAuthType()] = provider; // Synchronize the current user with the auth provider.
+
+ if (!AV._config.disableCurrentUser && AV.User.current()) {
+ AV.User.current()._synchronizeAuthData(provider.getAuthType());
+ }
+ },
+ _logInWith: function _logInWith(provider, authData, options) {
+ var user = AV.Object._create('_User');
+
+ return user._linkWith(provider, authData, options);
+ }
+ });
+};
+
+/***/ }),
+/* 528 */
+/***/ (function(module, exports, __webpack_require__) {
+
+var _Object$defineProperty = __webpack_require__(137);
+
+function _defineProperty(obj, key, value) {
+ if (key in obj) {
+ _Object$defineProperty(obj, key, {
+ value: value,
+ enumerable: true,
+ configurable: true,
+ writable: true
+ });
+ } else {
+ obj[key] = value;
+ }
+
+ return obj;
+}
+
+module.exports = _defineProperty, module.exports.__esModule = true, module.exports["default"] = module.exports;
+
+/***/ }),
+/* 529 */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+var _interopRequireDefault = __webpack_require__(2);
+
+var _map = _interopRequireDefault(__webpack_require__(39));
+
+var _promise = _interopRequireDefault(__webpack_require__(10));
+
+var _keys = _interopRequireDefault(__webpack_require__(48));
+
+var _stringify = _interopRequireDefault(__webpack_require__(34));
+
+var _find = _interopRequireDefault(__webpack_require__(104));
+
+var _concat = _interopRequireDefault(__webpack_require__(29));
+
+var _ = __webpack_require__(1);
+
+var debug = __webpack_require__(60)('leancloud:query');
+
+var AVError = __webpack_require__(40);
+
+var _require = __webpack_require__(25),
+ _request = _require._request,
+ request = _require.request;
+
+var _require2 = __webpack_require__(28),
+ ensureArray = _require2.ensureArray,
+ transformFetchOptions = _require2.transformFetchOptions,
+ continueWhile = _require2.continueWhile;
+
+var requires = function requires(value, message) {
+ if (value === undefined) {
+ throw new Error(message);
+ }
+}; // AV.Query is a way to create a list of AV.Objects.
+
+
+module.exports = function (AV) {
+ /**
+ * Creates a new AV.Query for the given AV.Object subclass.
+ * @param {Class|String} objectClass An instance of a subclass of AV.Object, or a AV className string.
+ * @class
+ *
+ *
AV.Query defines a query that is used to fetch AV.Objects. The
+ * most common use case is finding all objects that match a query through the
+ * find method. For example, this sample code fetches all objects
+ * of class MyClass. It calls a different function depending on
+ * whether the fetch succeeded or not.
+ *
+ *
+ * var query = new AV.Query(MyClass);
+ * query.find().then(function(results) {
+ * // results is an array of AV.Object.
+ * }, function(error) {
+ * // error is an instance of AVError.
+ * });
+ *
+ *
An AV.Query can also be used to retrieve a single object whose id is
+ * known, through the get method. For example, this sample code fetches an
+ * object of class MyClass and id myId. It calls a
+ * different function depending on whether the fetch succeeded or not.
+ *
+ *
+ * var query = new AV.Query(MyClass);
+ * query.get(myId).then(function(object) {
+ * // object is an instance of AV.Object.
+ * }, function(error) {
+ * // error is an instance of AVError.
+ * });
+ *
+ *
An AV.Query can also be used to count the number of objects that match
+ * the query without retrieving all of those objects. For example, this
+ * sample code counts the number of objects of the class MyClass
+ *
+ * var query = new AV.Query(MyClass);
+ * query.count().then(function(number) {
+ * // There are number instances of MyClass.
+ * }, function(error) {
+ * // error is an instance of AVError.
+ * });
+ */
+ AV.Query = function (objectClass) {
+ if (_.isString(objectClass)) {
+ objectClass = AV.Object._getSubclass(objectClass);
+ }
+
+ this.objectClass = objectClass;
+ this.className = objectClass.prototype.className;
+ this._where = {};
+ this._include = [];
+ this._select = [];
+ this._limit = -1; // negative limit means, do not send a limit
+
+ this._skip = 0;
+ this._defaultParams = {};
+ };
+ /**
+ * Constructs a AV.Query that is the OR of the passed in queries. For
+ * example:
+ *
var compoundQuery = AV.Query.or(query1, query2, query3);
+ *
+ * will create a compoundQuery that is an or of the query1, query2, and
+ * query3.
+ * @param {...AV.Query} var_args The list of queries to OR.
+ * @return {AV.Query} The query that is the OR of the passed in queries.
+ */
+
+
+ AV.Query.or = function () {
+ var queries = _.toArray(arguments);
+
+ var className = null;
+
+ AV._arrayEach(queries, function (q) {
+ if (_.isNull(className)) {
+ className = q.className;
+ }
+
+ if (className !== q.className) {
+ throw new Error('All queries must be for the same class');
+ }
+ });
+
+ var query = new AV.Query(className);
+
+ query._orQuery(queries);
+
+ return query;
+ };
+ /**
+ * Constructs a AV.Query that is the AND of the passed in queries. For
+ * example:
+ *
var compoundQuery = AV.Query.and(query1, query2, query3);
+ *
+ * will create a compoundQuery that is an 'and' of the query1, query2, and
+ * query3.
+ * @param {...AV.Query} var_args The list of queries to AND.
+ * @return {AV.Query} The query that is the AND of the passed in queries.
+ */
+
+
+ AV.Query.and = function () {
+ var queries = _.toArray(arguments);
+
+ var className = null;
+
+ AV._arrayEach(queries, function (q) {
+ if (_.isNull(className)) {
+ className = q.className;
+ }
+
+ if (className !== q.className) {
+ throw new Error('All queries must be for the same class');
+ }
+ });
+
+ var query = new AV.Query(className);
+
+ query._andQuery(queries);
+
+ return query;
+ };
+ /**
+ * Retrieves a list of AVObjects that satisfy the CQL.
+ * CQL syntax please see {@link https://leancloud.cn/docs/cql_guide.html CQL Guide}.
+ *
+ * @param {String} cql A CQL string, see {@link https://leancloud.cn/docs/cql_guide.html CQL Guide}.
+ * @param {Array} pvalues An array contains placeholder values.
+ * @param {AuthOptions} options
+ * @return {Promise} A promise that is resolved with the results when
+ * the query completes.
+ */
+
+
+ AV.Query.doCloudQuery = function (cql, pvalues, options) {
+ var params = {
+ cql: cql
+ };
+
+ if (_.isArray(pvalues)) {
+ params.pvalues = pvalues;
+ } else {
+ options = pvalues;
+ }
+
+ var request = _request('cloudQuery', null, null, 'GET', params, options);
+
+ return request.then(function (response) {
+ //query to process results.
+ var query = new AV.Query(response.className);
+ var results = (0, _map.default)(_).call(_, response.results, function (json) {
+ var obj = query._newObject(response);
+
+ if (obj._finishFetch) {
+ obj._finishFetch(query._processResult(json), true);
+ }
+
+ return obj;
+ });
+ return {
+ results: results,
+ count: response.count,
+ className: response.className
+ };
+ });
+ };
+ /**
+ * Return a query with conditions from json.
+ * This can be useful to send a query from server side to client side.
+ * @since 4.0.0
+ * @param {Object} json from {@link AV.Query#toJSON}
+ * @return {AV.Query}
+ */
+
+
+ AV.Query.fromJSON = function (_ref) {
+ var className = _ref.className,
+ where = _ref.where,
+ include = _ref.include,
+ select = _ref.select,
+ includeACL = _ref.includeACL,
+ limit = _ref.limit,
+ skip = _ref.skip,
+ order = _ref.order;
+
+ if (typeof className !== 'string') {
+ throw new TypeError('Invalid Query JSON, className must be a String.');
+ }
+
+ var query = new AV.Query(className);
+
+ _.extend(query, {
+ _where: where,
+ _include: include,
+ _select: select,
+ _includeACL: includeACL,
+ _limit: limit,
+ _skip: skip,
+ _order: order
+ });
+
+ return query;
+ };
+
+ AV.Query._extend = AV._extend;
+
+ _.extend(AV.Query.prototype,
+ /** @lends AV.Query.prototype */
+ {
+ //hook to iterate result. Added by dennis.
+ _processResult: function _processResult(obj) {
+ return obj;
+ },
+
+ /**
+ * Constructs an AV.Object whose id is already known by fetching data from
+ * the server.
+ *
+ * @param {String} objectId The id of the object to be fetched.
+ * @param {AuthOptions} options
+ * @return {Promise.}
+ */
+ get: function get(objectId, options) {
+ if (!_.isString(objectId)) {
+ throw new Error('objectId must be a string');
+ }
+
+ if (objectId === '') {
+ return _promise.default.reject(new AVError(AVError.OBJECT_NOT_FOUND, 'Object not found.'));
+ }
+
+ var obj = this._newObject();
+
+ obj.id = objectId;
+
+ var queryJSON = this._getParams();
+
+ var fetchOptions = {};
+ if ((0, _keys.default)(queryJSON)) fetchOptions.keys = (0, _keys.default)(queryJSON);
+ if (queryJSON.include) fetchOptions.include = queryJSON.include;
+ if (queryJSON.includeACL) fetchOptions.includeACL = queryJSON.includeACL;
+ return _request('classes', this.className, objectId, 'GET', transformFetchOptions(fetchOptions), options).then(function (response) {
+ if (_.isEmpty(response)) throw new AVError(AVError.OBJECT_NOT_FOUND, 'Object not found.');
+
+ obj._finishFetch(obj.parse(response), true);
+
+ return obj;
+ });
+ },
+
+ /**
+ * Returns a JSON representation of this query.
+ * @return {Object}
+ */
+ toJSON: function toJSON() {
+ var className = this.className,
+ where = this._where,
+ include = this._include,
+ select = this._select,
+ includeACL = this._includeACL,
+ limit = this._limit,
+ skip = this._skip,
+ order = this._order;
+ return {
+ className: className,
+ where: where,
+ include: include,
+ select: select,
+ includeACL: includeACL,
+ limit: limit,
+ skip: skip,
+ order: order
+ };
+ },
+ _getParams: function _getParams() {
+ var params = _.extend({}, this._defaultParams, {
+ where: this._where
+ });
+
+ if (this._include.length > 0) {
+ params.include = this._include.join(',');
+ }
+
+ if (this._select.length > 0) {
+ params.keys = this._select.join(',');
+ }
+
+ if (this._includeACL !== undefined) {
+ params.returnACL = this._includeACL;
+ }
+
+ if (this._limit >= 0) {
+ params.limit = this._limit;
+ }
+
+ if (this._skip > 0) {
+ params.skip = this._skip;
+ }
+
+ if (this._order !== undefined) {
+ params.order = this._order;
+ }
+
+ return params;
+ },
+ _newObject: function _newObject(response) {
+ var obj;
+
+ if (response && response.className) {
+ obj = new AV.Object(response.className);
+ } else {
+ obj = new this.objectClass();
+ }
+
+ return obj;
+ },
+ _createRequest: function _createRequest() {
+ var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this._getParams();
+ var options = arguments.length > 1 ? arguments[1] : undefined;
+ var path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "/classes/".concat(this.className);
+
+ if (encodeURIComponent((0, _stringify.default)(params)).length > 2000) {
+ var body = {
+ requests: [{
+ method: 'GET',
+ path: "/1.1".concat(path),
+ params: params
+ }]
+ };
+ return request({
+ path: '/batch',
+ method: 'POST',
+ data: body,
+ authOptions: options
+ }).then(function (response) {
+ var result = response[0];
+
+ if (result.success) {
+ return result.success;
+ }
+
+ var error = new AVError(result.error.code, result.error.error || 'Unknown batch error');
+ throw error;
+ });
+ }
+
+ return request({
+ method: 'GET',
+ path: path,
+ query: params,
+ authOptions: options
+ });
+ },
+ _parseResponse: function _parseResponse(response) {
+ var _this = this;
+
+ return (0, _map.default)(_).call(_, response.results, function (json) {
+ var obj = _this._newObject(response);
+
+ if (obj._finishFetch) {
+ obj._finishFetch(_this._processResult(json), true);
+ }
+
+ return obj;
+ });
+ },
+
+ /**
+ * Retrieves a list of AVObjects that satisfy this query.
+ *
+ * @param {AuthOptions} options
+ * @return {Promise} A promise that is resolved with the results when
+ * the query completes.
+ */
+ find: function find(options) {
+ var request = this._createRequest(undefined, options);
+
+ return request.then(this._parseResponse.bind(this));
+ },
+
+ /**
+ * Retrieves both AVObjects and total count.
+ *
+ * @since 4.12.0
+ * @param {AuthOptions} options
+ * @return {Promise} A tuple contains results and count.
+ */
+ findAndCount: function findAndCount(options) {
+ var _this2 = this;
+
+ var params = this._getParams();
+
+ params.count = 1;
+
+ var request = this._createRequest(params, options);
+
+ return request.then(function (response) {
+ return [_this2._parseResponse(response), response.count];
+ });
+ },
+
+ /**
+ * scan a Query. masterKey required.
+ *
+ * @since 2.1.0
+ * @param {object} [options]
+ * @param {string} [options.orderedBy] specify the key to sort
+ * @param {number} [options.batchSize] specify the batch size for each request
+ * @param {AuthOptions} [authOptions]
+ * @return {AsyncIterator.}
+ * @example const testIterator = {
+ * [Symbol.asyncIterator]() {
+ * return new Query('Test').scan(undefined, { useMasterKey: true });
+ * },
+ * };
+ * for await (const test of testIterator) {
+ * console.log(test.id);
+ * }
+ */
+ scan: function scan() {
+ var _this3 = this;
+
+ var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
+ orderedBy = _ref2.orderedBy,
+ batchSize = _ref2.batchSize;
+
+ var authOptions = arguments.length > 1 ? arguments[1] : undefined;
+
+ var condition = this._getParams();
+
+ debug('scan %O', condition);
+
+ if (condition.order) {
+ console.warn('The order of the query is ignored for Query#scan. Checkout the orderedBy option of Query#scan.');
+ delete condition.order;
+ }
+
+ if (condition.skip) {
+ console.warn('The skip option of the query is ignored for Query#scan.');
+ delete condition.skip;
+ }
+
+ if (condition.limit) {
+ console.warn('The limit option of the query is ignored for Query#scan.');
+ delete condition.limit;
+ }
+
+ if (orderedBy) condition.scan_key = orderedBy;
+ if (batchSize) condition.limit = batchSize;
+ var cursor;
+ var remainResults = [];
+ return {
+ next: function next() {
+ if (remainResults.length) {
+ return _promise.default.resolve({
+ done: false,
+ value: remainResults.shift()
+ });
+ }
+
+ if (cursor === null) {
+ return _promise.default.resolve({
+ done: true
+ });
+ }
+
+ return _request('scan/classes', _this3.className, null, 'GET', cursor ? _.extend({}, condition, {
+ cursor: cursor
+ }) : condition, authOptions).then(function (response) {
+ cursor = response.cursor;
+
+ if (response.results.length) {
+ var results = _this3._parseResponse(response);
+
+ results.forEach(function (result) {
+ return remainResults.push(result);
+ });
+ }
+
+ if (cursor === null && remainResults.length === 0) {
+ return {
+ done: true
+ };
+ }
+
+ return {
+ done: false,
+ value: remainResults.shift()
+ };
+ });
+ }
+ };
+ },
+
+ /**
+ * Delete objects retrieved by this query.
+ * @param {AuthOptions} options
+ * @return {Promise} A promise that is fulfilled when the save
+ * completes.
+ */
+ destroyAll: function destroyAll(options) {
+ var self = this;
+ return (0, _find.default)(self).call(self, options).then(function (objects) {
+ return AV.Object.destroyAll(objects, options);
+ });
+ },
+
+ /**
+ * Counts the number of objects that match this query.
+ *
+ * @param {AuthOptions} options
+ * @return {Promise} A promise that is resolved with the count when
+ * the query completes.
+ */
+ count: function count(options) {
+ var params = this._getParams();
+
+ params.limit = 0;
+ params.count = 1;
+
+ var request = this._createRequest(params, options);
+
+ return request.then(function (response) {
+ return response.count;
+ });
+ },
+
+ /**
+ * Retrieves at most one AV.Object that satisfies this query.
+ *
+ * @param {AuthOptions} options
+ * @return {Promise} A promise that is resolved with the object when
+ * the query completes.
+ */
+ first: function first(options) {
+ var self = this;
+
+ var params = this._getParams();
+
+ params.limit = 1;
+
+ var request = this._createRequest(params, options);
+
+ return request.then(function (response) {
+ return (0, _map.default)(_).call(_, response.results, function (json) {
+ var obj = self._newObject();
+
+ if (obj._finishFetch) {
+ obj._finishFetch(self._processResult(json), true);
+ }
+
+ return obj;
+ })[0];
+ });
+ },
+
+ /**
+ * Sets the number of results to skip before returning any results.
+ * This is useful for pagination.
+ * Default is to skip zero results.
+ * @param {Number} n the number of results to skip.
+ * @return {AV.Query} Returns the query, so you can chain this call.
+ */
+ skip: function skip(n) {
+ requires(n, 'undefined is not a valid skip value');
+ this._skip = n;
+ return this;
+ },
+
+ /**
+ * Sets the limit of the number of results to return. The default limit is
+ * 100, with a maximum of 1000 results being returned at a time.
+ * @param {Number} n the number of results to limit to.
+ * @return {AV.Query} Returns the query, so you can chain this call.
+ */
+ limit: function limit(n) {
+ requires(n, 'undefined is not a valid limit value');
+ this._limit = n;
+ return this;
+ },
+
+ /**
+ * Add a constraint to the query that requires a particular key's value to
+ * be equal to the provided value.
+ * @param {String} key The key to check.
+ * @param value The value that the AV.Object must contain.
+ * @return {AV.Query} Returns the query, so you can chain this call.
+ */
+ equalTo: function equalTo(key, value) {
+ requires(key, 'undefined is not a valid key');
+ requires(value, 'undefined is not a valid value');
+ this._where[key] = AV._encode(value);
+ return this;
+ },
+
+ /**
+ * Helper for condition queries
+ * @private
+ */
+ _addCondition: function _addCondition(key, condition, value) {
+ requires(key, 'undefined is not a valid condition key');
+ requires(condition, 'undefined is not a valid condition');
+ requires(value, 'undefined is not a valid condition value'); // Check if we already have a condition
+
+ if (!this._where[key]) {
+ this._where[key] = {};
+ }
+
+ this._where[key][condition] = AV._encode(value);
+ return this;
+ },
+
+ /**
+ * Add a constraint to the query that requires a particular
+ * array key's length to be equal to the provided value.
+ * @param {String} key The array key to check.
+ * @param {number} value The length value.
+ * @return {AV.Query} Returns the query, so you can chain this call.
+ */
+ sizeEqualTo: function sizeEqualTo(key, value) {
+ this._addCondition(key, '$size', value);
+
+ return this;
+ },
+
+ /**
+ * Add a constraint to the query that requires a particular key's value to
+ * be not equal to the provided value.
+ * @param {String} key The key to check.
+ * @param value The value that must not be equalled.
+ * @return {AV.Query} Returns the query, so you can chain this call.
+ */
+ notEqualTo: function notEqualTo(key, value) {
+ this._addCondition(key, '$ne', value);
+
+ return this;
+ },
+
+ /**
+ * Add a constraint to the query that requires a particular key's value to
+ * be less than the provided value.
+ * @param {String} key The key to check.
+ * @param value The value that provides an upper bound.
+ * @return {AV.Query} Returns the query, so you can chain this call.
+ */
+ lessThan: function lessThan(key, value) {
+ this._addCondition(key, '$lt', value);
+
+ return this;
+ },
+
+ /**
+ * Add a constraint to the query that requires a particular key's value to
+ * be greater than the provided value.
+ * @param {String} key The key to check.
+ * @param value The value that provides an lower bound.
+ * @return {AV.Query} Returns the query, so you can chain this call.
+ */
+ greaterThan: function greaterThan(key, value) {
+ this._addCondition(key, '$gt', value);
+
+ return this;
+ },
+
+ /**
+ * Add a constraint to the query that requires a particular key's value to
+ * be less than or equal to the provided value.
+ * @param {String} key The key to check.
+ * @param value The value that provides an upper bound.
+ * @return {AV.Query} Returns the query, so you can chain this call.
+ */
+ lessThanOrEqualTo: function lessThanOrEqualTo(key, value) {
+ this._addCondition(key, '$lte', value);
+
+ return this;
+ },
+
+ /**
+ * Add a constraint to the query that requires a particular key's value to
+ * be greater than or equal to the provided value.
+ * @param {String} key The key to check.
+ * @param value The value that provides an lower bound.
+ * @return {AV.Query} Returns the query, so you can chain this call.
+ */
+ greaterThanOrEqualTo: function greaterThanOrEqualTo(key, value) {
+ this._addCondition(key, '$gte', value);
+
+ return this;
+ },
+
+ /**
+ * Add a constraint to the query that requires a particular key's value to
+ * be contained in the provided list of values.
+ * @param {String} key The key to check.
+ * @param {Array} values The values that will match.
+ * @return {AV.Query} Returns the query, so you can chain this call.
+ */
+ containedIn: function containedIn(key, values) {
+ this._addCondition(key, '$in', values);
+
+ return this;
+ },
+
+ /**
+ * Add a constraint to the query that requires a particular key's value to
+ * not be contained in the provided list of values.
+ * @param {String} key The key to check.
+ * @param {Array} values The values that will not match.
+ * @return {AV.Query} Returns the query, so you can chain this call.
+ */
+ notContainedIn: function notContainedIn(key, values) {
+ this._addCondition(key, '$nin', values);
+
+ return this;
+ },
+
+ /**
+ * Add a constraint to the query that requires a particular key's value to
+ * contain each one of the provided list of values.
+ * @param {String} key The key to check. This key's value must be an array.
+ * @param {Array} values The values that will match.
+ * @return {AV.Query} Returns the query, so you can chain this call.
+ */
+ containsAll: function containsAll(key, values) {
+ this._addCondition(key, '$all', values);
+
+ return this;
+ },
+
+ /**
+ * Add a constraint for finding objects that contain the given key.
+ * @param {String} key The key that should exist.
+ * @return {AV.Query} Returns the query, so you can chain this call.
+ */
+ exists: function exists(key) {
+ this._addCondition(key, '$exists', true);
+
+ return this;
+ },
+
+ /**
+ * Add a constraint for finding objects that do not contain a given key.
+ * @param {String} key The key that should not exist
+ * @return {AV.Query} Returns the query, so you can chain this call.
+ */
+ doesNotExist: function doesNotExist(key) {
+ this._addCondition(key, '$exists', false);
+
+ return this;
+ },
+
+ /**
+ * Add a regular expression constraint for finding string values that match
+ * the provided regular expression.
+ * This may be slow for large datasets.
+ * @param {String} key The key that the string to match is stored in.
+ * @param {RegExp} regex The regular expression pattern to match.
+ * @return {AV.Query} Returns the query, so you can chain this call.
+ */
+ matches: function matches(key, regex, modifiers) {
+ this._addCondition(key, '$regex', regex);
+
+ if (!modifiers) {
+ modifiers = '';
+ } // Javascript regex options support mig as inline options but store them
+ // as properties of the object. We support mi & should migrate them to
+ // modifiers
+
+
+ if (regex.ignoreCase) {
+ modifiers += 'i';
+ }
+
+ if (regex.multiline) {
+ modifiers += 'm';
+ }
+
+ if (modifiers && modifiers.length) {
+ this._addCondition(key, '$options', modifiers);
+ }
+
+ return this;
+ },
+
+ /**
+ * Add a constraint that requires that a key's value matches a AV.Query
+ * constraint.
+ * @param {String} key The key that the contains the object to match the
+ * query.
+ * @param {AV.Query} query The query that should match.
+ * @return {AV.Query} Returns the query, so you can chain this call.
+ */
+ matchesQuery: function matchesQuery(key, query) {
+ var queryJSON = query._getParams();
+
+ queryJSON.className = query.className;
+
+ this._addCondition(key, '$inQuery', queryJSON);
+
+ return this;
+ },
+
+ /**
+ * Add a constraint that requires that a key's value not matches a
+ * AV.Query constraint.
+ * @param {String} key The key that the contains the object to match the
+ * query.
+ * @param {AV.Query} query The query that should not match.
+ * @return {AV.Query} Returns the query, so you can chain this call.
+ */
+ doesNotMatchQuery: function doesNotMatchQuery(key, query) {
+ var queryJSON = query._getParams();
+
+ queryJSON.className = query.className;
+
+ this._addCondition(key, '$notInQuery', queryJSON);
+
+ return this;
+ },
+
+ /**
+ * Add a constraint that requires that a key's value matches a value in
+ * an object returned by a different AV.Query.
+ * @param {String} key The key that contains the value that is being
+ * matched.
+ * @param {String} queryKey The key in the objects returned by the query to
+ * match against.
+ * @param {AV.Query} query The query to run.
+ * @return {AV.Query} Returns the query, so you can chain this call.
+ */
+ matchesKeyInQuery: function matchesKeyInQuery(key, queryKey, query) {
+ var queryJSON = query._getParams();
+
+ queryJSON.className = query.className;
+
+ this._addCondition(key, '$select', {
+ key: queryKey,
+ query: queryJSON
+ });
+
+ return this;
+ },
+
+ /**
+ * Add a constraint that requires that a key's value not match a value in
+ * an object returned by a different AV.Query.
+ * @param {String} key The key that contains the value that is being
+ * excluded.
+ * @param {String} queryKey The key in the objects returned by the query to
+ * match against.
+ * @param {AV.Query} query The query to run.
+ * @return {AV.Query} Returns the query, so you can chain this call.
+ */
+ doesNotMatchKeyInQuery: function doesNotMatchKeyInQuery(key, queryKey, query) {
+ var queryJSON = query._getParams();
+
+ queryJSON.className = query.className;
+
+ this._addCondition(key, '$dontSelect', {
+ key: queryKey,
+ query: queryJSON
+ });
+
+ return this;
+ },
+
+ /**
+ * Add constraint that at least one of the passed in queries matches.
+ * @param {Array} queries
+ * @return {AV.Query} Returns the query, so you can chain this call.
+ * @private
+ */
+ _orQuery: function _orQuery(queries) {
+ var queryJSON = (0, _map.default)(_).call(_, queries, function (q) {
+ return q._getParams().where;
+ });
+ this._where.$or = queryJSON;
+ return this;
+ },
+
+ /**
+ * Add constraint that both of the passed in queries matches.
+ * @param {Array} queries
+ * @return {AV.Query} Returns the query, so you can chain this call.
+ * @private
+ */
+ _andQuery: function _andQuery(queries) {
+ var queryJSON = (0, _map.default)(_).call(_, queries, function (q) {
+ return q._getParams().where;
+ });
+ this._where.$and = queryJSON;
+ return this;
+ },
+
+ /**
+ * Converts a string into a regex that matches it.
+ * Surrounding with \Q .. \E does this, we just need to escape \E's in
+ * the text separately.
+ * @private
+ */
+ _quote: function _quote(s) {
+ return '\\Q' + s.replace('\\E', '\\E\\\\E\\Q') + '\\E';
+ },
+
+ /**
+ * Add a constraint for finding string values that contain a provided
+ * string. This may be slow for large datasets.
+ * @param {String} key The key that the string to match is stored in.
+ * @param {String} substring The substring that the value must contain.
+ * @return {AV.Query} Returns the query, so you can chain this call.
+ */
+ contains: function contains(key, value) {
+ this._addCondition(key, '$regex', this._quote(value));
+
+ return this;
+ },
+
+ /**
+ * Add a constraint for finding string values that start with a provided
+ * string. This query will use the backend index, so it will be fast even
+ * for large datasets.
+ * @param {String} key The key that the string to match is stored in.
+ * @param {String} prefix The substring that the value must start with.
+ * @return {AV.Query} Returns the query, so you can chain this call.
+ */
+ startsWith: function startsWith(key, value) {
+ this._addCondition(key, '$regex', '^' + this._quote(value));
+
+ return this;
+ },
+
+ /**
+ * Add a constraint for finding string values that end with a provided
+ * string. This will be slow for large datasets.
+ * @param {String} key The key that the string to match is stored in.
+ * @param {String} suffix The substring that the value must end with.
+ * @return {AV.Query} Returns the query, so you can chain this call.
+ */
+ endsWith: function endsWith(key, value) {
+ this._addCondition(key, '$regex', this._quote(value) + '$');
+
+ return this;
+ },
+
+ /**
+ * Sorts the results in ascending order by the given key.
+ *
+ * @param {String} key The key to order by.
+ * @return {AV.Query} Returns the query, so you can chain this call.
+ */
+ ascending: function ascending(key) {
+ requires(key, 'undefined is not a valid key');
+ this._order = key;
+ return this;
+ },
+
+ /**
+ * Also sorts the results in ascending order by the given key. The previous sort keys have
+ * precedence over this key.
+ *
+ * @param {String} key The key to order by
+ * @return {AV.Query} Returns the query so you can chain this call.
+ */
+ addAscending: function addAscending(key) {
+ requires(key, 'undefined is not a valid key');
+ if (this._order) this._order += ',' + key;else this._order = key;
+ return this;
+ },
+
+ /**
+ * Sorts the results in descending order by the given key.
+ *
+ * @param {String} key The key to order by.
+ * @return {AV.Query} Returns the query, so you can chain this call.
+ */
+ descending: function descending(key) {
+ requires(key, 'undefined is not a valid key');
+ this._order = '-' + key;
+ return this;
+ },
+
+ /**
+ * Also sorts the results in descending order by the given key. The previous sort keys have
+ * precedence over this key.
+ *
+ * @param {String} key The key to order by
+ * @return {AV.Query} Returns the query so you can chain this call.
+ */
+ addDescending: function addDescending(key) {
+ requires(key, 'undefined is not a valid key');
+ if (this._order) this._order += ',-' + key;else this._order = '-' + key;
+ return this;
+ },
+
+ /**
+ * Add a proximity based constraint for finding objects with key point
+ * values near the point given.
+ * @param {String} key The key that the AV.GeoPoint is stored in.
+ * @param {AV.GeoPoint} point The reference AV.GeoPoint that is used.
+ * @return {AV.Query} Returns the query, so you can chain this call.
+ */
+ near: function near(key, point) {
+ if (!(point instanceof AV.GeoPoint)) {
+ // Try to cast it to a GeoPoint, so that near("loc", [20,30]) works.
+ point = new AV.GeoPoint(point);
+ }
+
+ this._addCondition(key, '$nearSphere', point);
+
+ return this;
+ },
+
+ /**
+ * Add a proximity based constraint for finding objects with key point
+ * values near the point given and within the maximum distance given.
+ * @param {String} key The key that the AV.GeoPoint is stored in.
+ * @param {AV.GeoPoint} point The reference AV.GeoPoint that is used.
+ * @param maxDistance Maximum distance (in radians) of results to return.
+ * @return {AV.Query} Returns the query, so you can chain this call.
+ */
+ withinRadians: function withinRadians(key, point, distance) {
+ this.near(key, point);
+
+ this._addCondition(key, '$maxDistance', distance);
+
+ return this;
+ },
+
+ /**
+ * Add a proximity based constraint for finding objects with key point
+ * values near the point given and within the maximum distance given.
+ * Radius of earth used is 3958.8 miles.
+ * @param {String} key The key that the AV.GeoPoint is stored in.
+ * @param {AV.GeoPoint} point The reference AV.GeoPoint that is used.
+ * @param {Number} maxDistance Maximum distance (in miles) of results to
+ * return.
+ * @return {AV.Query} Returns the query, so you can chain this call.
+ */
+ withinMiles: function withinMiles(key, point, distance) {
+ return this.withinRadians(key, point, distance / 3958.8);
+ },
+
+ /**
+ * Add a proximity based constraint for finding objects with key point
+ * values near the point given and within the maximum distance given.
+ * Radius of earth used is 6371.0 kilometers.
+ * @param {String} key The key that the AV.GeoPoint is stored in.
+ * @param {AV.GeoPoint} point The reference AV.GeoPoint that is used.
+ * @param {Number} maxDistance Maximum distance (in kilometers) of results
+ * to return.
+ * @return {AV.Query} Returns the query, so you can chain this call.
+ */
+ withinKilometers: function withinKilometers(key, point, distance) {
+ return this.withinRadians(key, point, distance / 6371.0);
+ },
+
+ /**
+ * Add a constraint to the query that requires a particular key's
+ * coordinates be contained within a given rectangular geographic bounding
+ * box.
+ * @param {String} key The key to be constrained.
+ * @param {AV.GeoPoint} southwest
+ * The lower-left inclusive corner of the box.
+ * @param {AV.GeoPoint} northeast
+ * The upper-right inclusive corner of the box.
+ * @return {AV.Query} Returns the query, so you can chain this call.
+ */
+ withinGeoBox: function withinGeoBox(key, southwest, northeast) {
+ if (!(southwest instanceof AV.GeoPoint)) {
+ southwest = new AV.GeoPoint(southwest);
+ }
+
+ if (!(northeast instanceof AV.GeoPoint)) {
+ northeast = new AV.GeoPoint(northeast);
+ }
+
+ this._addCondition(key, '$within', {
+ $box: [southwest, northeast]
+ });
+
+ return this;
+ },
+
+ /**
+ * Include nested AV.Objects for the provided key. You can use dot
+ * notation to specify which fields in the included object are also fetch.
+ * @param {String[]} keys The name of the key to include.
+ * @return {AV.Query} Returns the query, so you can chain this call.
+ */
+ include: function include(keys) {
+ var _this4 = this;
+
+ requires(keys, 'undefined is not a valid key');
+
+ _.forEach(arguments, function (keys) {
+ var _context;
+
+ _this4._include = (0, _concat.default)(_context = _this4._include).call(_context, ensureArray(keys));
+ });
+
+ return this;
+ },
+
+ /**
+ * Include the ACL.
+ * @param {Boolean} [value=true] Whether to include the ACL
+ * @return {AV.Query} Returns the query, so you can chain this call.
+ */
+ includeACL: function includeACL() {
+ var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
+ this._includeACL = value;
+ return this;
+ },
+
+ /**
+ * Restrict the fields of the returned AV.Objects to include only the
+ * provided keys. If this is called multiple times, then all of the keys
+ * specified in each of the calls will be included.
+ * @param {String[]} keys The names of the keys to include.
+ * @return {AV.Query} Returns the query, so you can chain this call.
+ */
+ select: function select(keys) {
+ var _this5 = this;
+
+ requires(keys, 'undefined is not a valid key');
+
+ _.forEach(arguments, function (keys) {
+ var _context2;
+
+ _this5._select = (0, _concat.default)(_context2 = _this5._select).call(_context2, ensureArray(keys));
+ });
+
+ return this;
+ },
+
+ /**
+ * Iterates over each result of a query, calling a callback for each one. If
+ * the callback returns a promise, the iteration will not continue until
+ * that promise has been fulfilled. If the callback returns a rejected
+ * promise, then iteration will stop with that error. The items are
+ * processed in an unspecified order. The query may not have any sort order,
+ * and may not use limit or skip.
+ * @param callback {Function} Callback that will be called with each result
+ * of the query.
+ * @return {Promise} A promise that will be fulfilled once the
+ * iteration has completed.
+ */
+ each: function each(callback) {
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
+
+ if (this._order || this._skip || this._limit >= 0) {
+ var error = new Error('Cannot iterate on a query with sort, skip, or limit.');
+ return _promise.default.reject(error);
+ }
+
+ var query = new AV.Query(this.objectClass); // We can override the batch size from the options.
+ // This is undocumented, but useful for testing.
+
+ query._limit = options.batchSize || 100;
+ query._where = _.clone(this._where);
+ query._include = _.clone(this._include);
+ query.ascending('objectId');
+ var finished = false;
+ return continueWhile(function () {
+ return !finished;
+ }, function () {
+ return (0, _find.default)(query).call(query, options).then(function (results) {
+ var callbacksDone = _promise.default.resolve();
+
+ _.each(results, function (result) {
+ callbacksDone = callbacksDone.then(function () {
+ return callback(result);
+ });
+ });
+
+ return callbacksDone.then(function () {
+ if (results.length >= query._limit) {
+ query.greaterThan('objectId', results[results.length - 1].id);
+ } else {
+ finished = true;
+ }
+ });
+ });
+ });
+ },
+
+ /**
+ * Subscribe the changes of this query.
+ *
+ * LiveQuery is not included in the default bundle: {@link https://url.leanapp.cn/enable-live-query}.
+ *
+ * @since 3.0.0
+ * @return {AV.LiveQuery} An eventemitter which can be used to get LiveQuery updates;
+ */
+ subscribe: function subscribe(options) {
+ return AV.LiveQuery.init(this, options);
+ }
+ });
+
+ AV.FriendShipQuery = AV.Query._extend({
+ _newObject: function _newObject() {
+ var UserClass = AV.Object._getSubclass('_User');
+
+ return new UserClass();
+ },
+ _processResult: function _processResult(json) {
+ if (json && json[this._friendshipTag]) {
+ var user = json[this._friendshipTag];
+
+ if (user.__type === 'Pointer' && user.className === '_User') {
+ delete user.__type;
+ delete user.className;
+ }
+
+ return user;
+ } else {
+ return null;
+ }
+ }
+ });
+};
+
+/***/ }),
+/* 530 */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+var _interopRequireDefault = __webpack_require__(2);
+
+var _promise = _interopRequireDefault(__webpack_require__(10));
+
+var _keys = _interopRequireDefault(__webpack_require__(48));
+
+var _ = __webpack_require__(1);
+
+var EventEmitter = __webpack_require__(218);
+
+var _require = __webpack_require__(28),
+ inherits = _require.inherits;
+
+var _require2 = __webpack_require__(25),
+ request = _require2.request;
+
+var subscribe = function subscribe(queryJSON, subscriptionId) {
+ return request({
+ method: 'POST',
+ path: '/LiveQuery/subscribe',
+ data: {
+ query: queryJSON,
+ id: subscriptionId
+ }
+ });
+};
+
+module.exports = function (AV) {
+ var requireRealtime = function requireRealtime() {
+ if (!AV._config.realtime) {
+ throw new Error('LiveQuery not supported. Please use the LiveQuery bundle. https://url.leanapp.cn/enable-live-query');
+ }
+ };
+ /**
+ * @class
+ * A LiveQuery, created by {@link AV.Query#subscribe} is an EventEmitter notifies changes of the Query.
+ * @since 3.0.0
+ */
+
+
+ AV.LiveQuery = inherits(EventEmitter,
+ /** @lends AV.LiveQuery.prototype */
+ {
+ constructor: function constructor(id, client, queryJSON, subscriptionId) {
+ var _this = this;
+
+ EventEmitter.apply(this);
+ this.id = id;
+ this._client = client;
+
+ this._client.register(this);
+
+ this._queryJSON = queryJSON;
+ this._subscriptionId = subscriptionId;
+ this._onMessage = this._dispatch.bind(this);
+
+ this._onReconnect = function () {
+ subscribe(_this._queryJSON, _this._subscriptionId).catch(function (error) {
+ return console.error("LiveQuery resubscribe error: ".concat(error.message));
+ });
+ };
+
+ client.on('message', this._onMessage);
+ client.on('reconnect', this._onReconnect);
+ },
+ _dispatch: function _dispatch(message) {
+ var _this2 = this;
+
+ message.forEach(function (_ref) {
+ var op = _ref.op,
+ object = _ref.object,
+ queryId = _ref.query_id,
+ updatedKeys = _ref.updatedKeys;
+ if (queryId !== _this2.id) return;
+ var target = AV.parseJSON(_.extend({
+ __type: object.className === '_File' ? 'File' : 'Object'
+ }, object));
+
+ if (updatedKeys) {
+ /**
+ * An existing AV.Object which fulfills the Query you subscribe is updated.
+ * @event AV.LiveQuery#update
+ * @param {AV.Object|AV.File} target updated object
+ * @param {String[]} updatedKeys updated keys
+ */
+
+ /**
+ * An existing AV.Object which doesn't fulfill the Query is updated and now it fulfills the Query.
+ * @event AV.LiveQuery#enter
+ * @param {AV.Object|AV.File} target updated object
+ * @param {String[]} updatedKeys updated keys
+ */
+
+ /**
+ * An existing AV.Object which fulfills the Query is updated and now it doesn't fulfill the Query.
+ * @event AV.LiveQuery#leave
+ * @param {AV.Object|AV.File} target updated object
+ * @param {String[]} updatedKeys updated keys
+ */
+ _this2.emit(op, target, updatedKeys);
+ } else {
+ /**
+ * A new AV.Object which fulfills the Query you subscribe is created.
+ * @event AV.LiveQuery#create
+ * @param {AV.Object|AV.File} target updated object
+ */
+
+ /**
+ * An existing AV.Object which fulfills the Query you subscribe is deleted.
+ * @event AV.LiveQuery#delete
+ * @param {AV.Object|AV.File} target updated object
+ */
+ _this2.emit(op, target);
+ }
+ });
+ },
+
+ /**
+ * unsubscribe the query
+ *
+ * @return {Promise}
+ */
+ unsubscribe: function unsubscribe() {
+ var client = this._client;
+ client.off('message', this._onMessage);
+ client.off('reconnect', this._onReconnect);
+ client.deregister(this);
+ return request({
+ method: 'POST',
+ path: '/LiveQuery/unsubscribe',
+ data: {
+ id: client.id,
+ query_id: this.id
+ }
+ });
+ }
+ },
+ /** @lends AV.LiveQuery */
+ {
+ init: function init(query) {
+ var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
+ _ref2$subscriptionId = _ref2.subscriptionId,
+ userDefinedSubscriptionId = _ref2$subscriptionId === void 0 ? AV._getSubscriptionId() : _ref2$subscriptionId;
+
+ requireRealtime();
+ if (!(query instanceof AV.Query)) throw new TypeError('LiveQuery must be inited with a Query');
+ return _promise.default.resolve(userDefinedSubscriptionId).then(function (subscriptionId) {
+ return AV._config.realtime.createLiveQueryClient(subscriptionId).then(function (liveQueryClient) {
+ var _query$_getParams = query._getParams(),
+ where = _query$_getParams.where,
+ keys = (0, _keys.default)(_query$_getParams),
+ returnACL = _query$_getParams.returnACL;
+
+ var queryJSON = {
+ where: where,
+ keys: keys,
+ returnACL: returnACL,
+ className: query.className
+ };
+ var promise = subscribe(queryJSON, subscriptionId).then(function (_ref3) {
+ var queryId = _ref3.query_id;
+ return new AV.LiveQuery(queryId, liveQueryClient, queryJSON, subscriptionId);
+ }).finally(function () {
+ liveQueryClient.deregister(promise);
+ });
+ liveQueryClient.register(promise);
+ return promise;
+ });
+ });
+ },
+
+ /**
+ * Pause the LiveQuery connection. This is useful to deactivate the SDK when the app is swtiched to background.
+ * @static
+ * @return void
+ */
+ pause: function pause() {
+ requireRealtime();
+ return AV._config.realtime.pause();
+ },
+
+ /**
+ * Resume the LiveQuery connection. All subscriptions will be restored after reconnection.
+ * @static
+ * @return void
+ */
+ resume: function resume() {
+ requireRealtime();
+ return AV._config.realtime.resume();
+ }
+ });
+};
+
+/***/ }),
+/* 531 */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+var _ = __webpack_require__(1);
+
+var _require = __webpack_require__(28),
+ tap = _require.tap;
+
+module.exports = function (AV) {
+ /**
+ * @class
+ * @example
+ * AV.Captcha.request().then(captcha => {
+ * captcha.bind({
+ * textInput: 'code', // the id for textInput
+ * image: 'captcha',
+ * verifyButton: 'verify',
+ * }, {
+ * success: (validateCode) => {}, // next step
+ * error: (error) => {}, // present error.message to user
+ * });
+ * });
+ */
+ AV.Captcha = function Captcha(options, authOptions) {
+ this._options = options;
+ this._authOptions = authOptions;
+ /**
+ * The image url of the captcha
+ * @type string
+ */
+
+ this.url = undefined;
+ /**
+ * The captchaToken of the captcha.
+ * @type string
+ */
+
+ this.captchaToken = undefined;
+ /**
+ * The validateToken of the captcha.
+ * @type string
+ */
+
+ this.validateToken = undefined;
+ };
+ /**
+ * Refresh the captcha
+ * @return {Promise.} a new capcha url
+ */
+
+
+ AV.Captcha.prototype.refresh = function refresh() {
+ var _this = this;
+
+ return AV.Cloud._requestCaptcha(this._options, this._authOptions).then(function (_ref) {
+ var captchaToken = _ref.captchaToken,
+ url = _ref.url;
+
+ _.extend(_this, {
+ captchaToken: captchaToken,
+ url: url
+ });
+
+ return url;
+ });
+ };
+ /**
+ * Verify the captcha
+ * @param {String} code The code from user input
+ * @return {Promise.} validateToken if the code is valid
+ */
+
+
+ AV.Captcha.prototype.verify = function verify(code) {
+ var _this2 = this;
+
+ return AV.Cloud.verifyCaptcha(code, this.captchaToken).then(tap(function (validateToken) {
+ return _this2.validateToken = validateToken;
+ }));
+ };
+
+ if (undefined === 'Browser') {
+ /**
+ * Bind the captcha to HTMLElements. ONLY AVAILABLE in browsers.
+ * @param [elements]
+ * @param {String|HTMLInputElement} [elements.textInput] An input element typed text, or the id for the element.
+ * @param {String|HTMLImageElement} [elements.image] An image element, or the id for the element.
+ * @param {String|HTMLElement} [elements.verifyButton] A button element, or the id for the element.
+ * @param [callbacks]
+ * @param {Function} [callbacks.success] Success callback will be called if the code is verified. The param `validateCode` can be used for further SMS request.
+ * @param {Function} [callbacks.error] Error callback will be called if something goes wrong, detailed in param `error.message`.
+ */
+ AV.Captcha.prototype.bind = function bind(_ref2, _ref3) {
+ var _this3 = this;
+
+ var textInput = _ref2.textInput,
+ image = _ref2.image,
+ verifyButton = _ref2.verifyButton;
+ var success = _ref3.success,
+ error = _ref3.error;
+
+ if (typeof textInput === 'string') {
+ textInput = document.getElementById(textInput);
+ if (!textInput) throw new Error("textInput with id ".concat(textInput, " not found"));
+ }
+
+ if (typeof image === 'string') {
+ image = document.getElementById(image);
+ if (!image) throw new Error("image with id ".concat(image, " not found"));
+ }
+
+ if (typeof verifyButton === 'string') {
+ verifyButton = document.getElementById(verifyButton);
+ if (!verifyButton) throw new Error("verifyButton with id ".concat(verifyButton, " not found"));
+ }
+
+ this.__refresh = function () {
+ return _this3.refresh().then(function (url) {
+ image.src = url;
+
+ if (textInput) {
+ textInput.value = '';
+ textInput.focus();
+ }
+ }).catch(function (err) {
+ return console.warn("refresh captcha fail: ".concat(err.message));
+ });
+ };
+
+ if (image) {
+ this.__image = image;
+ image.src = this.url;
+ image.addEventListener('click', this.__refresh);
+ }
+
+ this.__verify = function () {
+ var code = textInput.value;
+
+ _this3.verify(code).catch(function (err) {
+ _this3.__refresh();
+
+ throw err;
+ }).then(success, error).catch(function (err) {
+ return console.warn("verify captcha fail: ".concat(err.message));
+ });
+ };
+
+ if (textInput && verifyButton) {
+ this.__verifyButton = verifyButton;
+ verifyButton.addEventListener('click', this.__verify);
+ }
+ };
+ /**
+ * unbind the captcha from HTMLElements. ONLY AVAILABLE in browsers.
+ */
+
+
+ AV.Captcha.prototype.unbind = function unbind() {
+ if (this.__image) this.__image.removeEventListener('click', this.__refresh);
+ if (this.__verifyButton) this.__verifyButton.removeEventListener('click', this.__verify);
+ };
+ }
+ /**
+ * Request a captcha
+ * @param [options]
+ * @param {Number} [options.width] width(px) of the captcha, ranged 60-200
+ * @param {Number} [options.height] height(px) of the captcha, ranged 30-100
+ * @param {Number} [options.size=4] length of the captcha, ranged 3-6. MasterKey required.
+ * @param {Number} [options.ttl=60] time to live(s), ranged 10-180. MasterKey required.
+ * @return {Promise.}
+ */
+
+
+ AV.Captcha.request = function (options, authOptions) {
+ var captcha = new AV.Captcha(options, authOptions);
+ return captcha.refresh().then(function () {
+ return captcha;
+ });
+ };
+};
+
+/***/ }),
+/* 532 */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+var _interopRequireDefault = __webpack_require__(2);
+
+var _promise = _interopRequireDefault(__webpack_require__(10));
+
+var _ = __webpack_require__(1);
+
+var _require = __webpack_require__(25),
+ _request = _require._request,
+ request = _require.request;
+
+module.exports = function (AV) {
+ /**
+ * Contains functions for calling and declaring
+ *
+ * Some functions are only available from Cloud Code.
+ *
+ *
+ * @namespace
+ * @borrows AV.Captcha.request as requestCaptcha
+ */
+ AV.Cloud = AV.Cloud || {};
+
+ _.extend(AV.Cloud,
+ /** @lends AV.Cloud */
+ {
+ /**
+ * Makes a call to a cloud function.
+ * @param {String} name The function name.
+ * @param {Object} [data] The parameters to send to the cloud function.
+ * @param {AuthOptions} [options]
+ * @return {Promise} A promise that will be resolved with the result
+ * of the function.
+ */
+ run: function run(name, data, options) {
+ return request({
+ service: 'engine',
+ method: 'POST',
+ path: "/functions/".concat(name),
+ data: AV._encode(data, null, true),
+ authOptions: options
+ }).then(function (resp) {
+ return AV._decode(resp).result;
+ });
+ },
+
+ /**
+ * Makes a call to a cloud function, you can send {AV.Object} as param or a field of param; the response
+ * from server will also be parsed as an {AV.Object}, array of {AV.Object}, or object includes {AV.Object}
+ * @param {String} name The function name.
+ * @param {Object} [data] The parameters to send to the cloud function.
+ * @param {AuthOptions} [options]
+ * @return {Promise} A promise that will be resolved with the result of the function.
+ */
+ rpc: function rpc(name, data, options) {
+ if (_.isArray(data)) {
+ return _promise.default.reject(new Error("Can't pass Array as the param of rpc function in JavaScript SDK."));
+ }
+
+ return request({
+ service: 'engine',
+ method: 'POST',
+ path: "/call/".concat(name),
+ data: AV._encodeObjectOrArray(data),
+ authOptions: options
+ }).then(function (resp) {
+ return AV._decode(resp).result;
+ });
+ },
+
+ /**
+ * Make a call to request server date time.
+ * @return {Promise.} A promise that will be resolved with the result
+ * of the function.
+ * @since 0.5.9
+ */
+ getServerDate: function getServerDate() {
+ return _request('date', null, null, 'GET').then(function (resp) {
+ return AV._decode(resp);
+ });
+ },
+
+ /**
+ * Makes a call to request an sms code for operation verification.
+ * @param {String|Object} data The mobile phone number string or a JSON
+ * object that contains mobilePhoneNumber,template,sign,op,ttl,name etc.
+ * @param {String} data.mobilePhoneNumber
+ * @param {String} [data.template] sms template name
+ * @param {String} [data.sign] sms signature name
+ * @param {String} [data.smsType] sending code by `sms` (default) or `voice` call
+ * @param {SMSAuthOptions} [options]
+ * @return {Promise} A promise that will be resolved if the request succeed
+ */
+ requestSmsCode: function requestSmsCode(data) {
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
+
+ if (_.isString(data)) {
+ data = {
+ mobilePhoneNumber: data
+ };
+ }
+
+ if (!data.mobilePhoneNumber) {
+ throw new Error('Missing mobilePhoneNumber.');
+ }
+
+ if (options.validateToken) {
+ data = _.extend({}, data, {
+ validate_token: options.validateToken
+ });
+ }
+
+ return _request('requestSmsCode', null, null, 'POST', data, options);
+ },
+
+ /**
+ * Makes a call to verify sms code that sent by AV.Cloud.requestSmsCode
+ * @param {String} code The sms code sent by AV.Cloud.requestSmsCode
+ * @param {phone} phone The mobile phoner number.
+ * @return {Promise} A promise that will be resolved with the result
+ * of the function.
+ */
+ verifySmsCode: function verifySmsCode(code, phone) {
+ if (!code) throw new Error('Missing sms code.');
+ var params = {};
+
+ if (_.isString(phone)) {
+ params['mobilePhoneNumber'] = phone;
+ }
+
+ return _request('verifySmsCode', code, null, 'POST', params);
+ },
+ _requestCaptcha: function _requestCaptcha(options, authOptions) {
+ return _request('requestCaptcha', null, null, 'GET', options, authOptions).then(function (_ref) {
+ var url = _ref.captcha_url,
+ captchaToken = _ref.captcha_token;
+ return {
+ captchaToken: captchaToken,
+ url: url
+ };
+ });
+ },
+
+ /**
+ * Request a captcha.
+ */
+ requestCaptcha: AV.Captcha.request,
+
+ /**
+ * Verify captcha code. This is the low-level API for captcha.
+ * Checkout {@link AV.Captcha} for high abstract APIs.
+ * @param {String} code the code from user input
+ * @param {String} captchaToken captchaToken returned by {@link AV.Cloud.requestCaptcha}
+ * @return {Promise.} validateToken if the code is valid
+ */
+ verifyCaptcha: function verifyCaptcha(code, captchaToken) {
+ return _request('verifyCaptcha', null, null, 'POST', {
+ captcha_code: code,
+ captcha_token: captchaToken
+ }).then(function (_ref2) {
+ var validateToken = _ref2.validate_token;
+ return validateToken;
+ });
+ }
+ });
+};
+
+/***/ }),
+/* 533 */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+var request = __webpack_require__(25).request;
+
+module.exports = function (AV) {
+ AV.Installation = AV.Object.extend('_Installation');
+ /**
+ * @namespace
+ */
+
+ AV.Push = AV.Push || {};
+ /**
+ * Sends a push notification.
+ * @param {Object} data The data of the push notification.
+ * @param {String[]} [data.channels] An Array of channels to push to.
+ * @param {Date} [data.push_time] A Date object for when to send the push.
+ * @param {Date} [data.expiration_time] A Date object for when to expire
+ * the push.
+ * @param {Number} [data.expiration_interval] The seconds from now to expire the push.
+ * @param {Number} [data.flow_control] The clients to notify per second
+ * @param {AV.Query} [data.where] An AV.Query over AV.Installation that is used to match
+ * a set of installations to push to.
+ * @param {String} [data.cql] A CQL statement over AV.Installation that is used to match
+ * a set of installations to push to.
+ * @param {Object} data.data The data to send as part of the push.
+ More details: https://url.leanapp.cn/pushData
+ * @param {AuthOptions} [options]
+ * @return {Promise}
+ */
+
+ AV.Push.send = function (data, options) {
+ if (data.where) {
+ data.where = data.where._getParams().where;
+ }
+
+ if (data.where && data.cql) {
+ throw new Error("Both where and cql can't be set");
+ }
+
+ if (data.push_time) {
+ data.push_time = data.push_time.toJSON();
+ }
+
+ if (data.expiration_time) {
+ data.expiration_time = data.expiration_time.toJSON();
+ }
+
+ if (data.expiration_time && data.expiration_interval) {
+ throw new Error("Both expiration_time and expiration_interval can't be set");
+ }
+
+ return request({
+ service: 'push',
+ method: 'POST',
+ path: '/push',
+ data: data,
+ authOptions: options
+ });
+ };
+};
+
+/***/ }),
+/* 534 */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+var _interopRequireDefault = __webpack_require__(2);
+
+var _promise = _interopRequireDefault(__webpack_require__(10));
+
+var _typeof2 = _interopRequireDefault(__webpack_require__(135));
+
+var _ = __webpack_require__(1);
+
+var AVRequest = __webpack_require__(25)._request;
+
+var _require = __webpack_require__(28),
+ getSessionToken = _require.getSessionToken;
+
+module.exports = function (AV) {
+ var getUser = function getUser() {
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
+ var sessionToken = getSessionToken(options);
+
+ if (sessionToken) {
+ return AV.User._fetchUserBySessionToken(getSessionToken(options));
+ }
+
+ return AV.User.currentAsync();
+ };
+
+ var getUserPointer = function getUserPointer(options) {
+ return getUser(options).then(function (currUser) {
+ return AV.Object.createWithoutData('_User', currUser.id)._toPointer();
+ });
+ };
+ /**
+ * Contains functions to deal with Status in LeanCloud.
+ * @class
+ */
+
+
+ AV.Status = function (imageUrl, message) {
+ this.data = {};
+ this.inboxType = 'default';
+ this.query = null;
+
+ if (imageUrl && (0, _typeof2.default)(imageUrl) === 'object') {
+ this.data = imageUrl;
+ } else {
+ if (imageUrl) {
+ this.data.image = imageUrl;
+ }
+
+ if (message) {
+ this.data.message = message;
+ }
+ }
+
+ return this;
+ };
+
+ _.extend(AV.Status.prototype,
+ /** @lends AV.Status.prototype */
+ {
+ /**
+ * Gets the value of an attribute in status data.
+ * @param {String} attr The string name of an attribute.
+ */
+ get: function get(attr) {
+ return this.data[attr];
+ },
+
+ /**
+ * Sets a hash of model attributes on the status data.
+ * @param {String} key The key to set.
+ * @param {any} value The value to give it.
+ */
+ set: function set(key, value) {
+ this.data[key] = value;
+ return this;
+ },
+
+ /**
+ * Destroy this status,then it will not be avaiable in other user's inboxes.
+ * @param {AuthOptions} options
+ * @return {Promise} A promise that is fulfilled when the destroy
+ * completes.
+ */
+ destroy: function destroy(options) {
+ if (!this.id) return _promise.default.reject(new Error('The status id is not exists.'));
+ var request = AVRequest('statuses', null, this.id, 'DELETE', options);
+ return request;
+ },
+
+ /**
+ * Cast the AV.Status object to an AV.Object pointer.
+ * @return {AV.Object} A AV.Object pointer.
+ */
+ toObject: function toObject() {
+ if (!this.id) return null;
+ return AV.Object.createWithoutData('_Status', this.id);
+ },
+ _getDataJSON: function _getDataJSON() {
+ var json = _.clone(this.data);
+
+ return AV._encode(json);
+ },
+
+ /**
+ * Send a status by a AV.Query object.
+ * @since 0.3.0
+ * @param {AuthOptions} options
+ * @return {Promise} A promise that is fulfilled when the send
+ * completes.
+ * @example
+ * // send a status to male users
+ * var status = new AVStatus('image url', 'a message');
+ * status.query = new AV.Query('_User');
+ * status.query.equalTo('gender', 'male');
+ * status.send().then(function(){
+ * //send status successfully.
+ * }, function(err){
+ * //an error threw.
+ * console.dir(err);
+ * });
+ */
+ send: function send() {
+ var _this = this;
+
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
+
+ if (!getSessionToken(options) && !AV.User.current()) {
+ throw new Error('Please signin an user.');
+ }
+
+ if (!this.query) {
+ return AV.Status.sendStatusToFollowers(this, options);
+ }
+
+ return getUserPointer(options).then(function (currUser) {
+ var query = _this.query._getParams();
+
+ query.className = _this.query.className;
+ var data = {};
+ data.query = query;
+ _this.data = _this.data || {};
+ _this.data.source = _this.data.source || currUser;
+ data.data = _this._getDataJSON();
+ data.inboxType = _this.inboxType || 'default';
+ return AVRequest('statuses', null, null, 'POST', data, options);
+ }).then(function (response) {
+ _this.id = response.objectId;
+ _this.createdAt = AV._parseDate(response.createdAt);
+ return _this;
+ });
+ },
+ _finishFetch: function _finishFetch(serverData) {
+ this.id = serverData.objectId;
+ this.createdAt = AV._parseDate(serverData.createdAt);
+ this.updatedAt = AV._parseDate(serverData.updatedAt);
+ this.messageId = serverData.messageId;
+ delete serverData.messageId;
+ delete serverData.objectId;
+ delete serverData.createdAt;
+ delete serverData.updatedAt;
+ this.data = AV._decode(serverData);
+ }
+ });
+ /**
+ * Send a status to current signined user's followers.
+ * @since 0.3.0
+ * @param {AV.Status} status A status object to be send to followers.
+ * @param {AuthOptions} options
+ * @return {Promise} A promise that is fulfilled when the send
+ * completes.
+ * @example
+ * var status = new AVStatus('image url', 'a message');
+ * AV.Status.sendStatusToFollowers(status).then(function(){
+ * //send status successfully.
+ * }, function(err){
+ * //an error threw.
+ * console.dir(err);
+ * });
+ */
+
+
+ AV.Status.sendStatusToFollowers = function (status) {
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
+
+ if (!getSessionToken(options) && !AV.User.current()) {
+ throw new Error('Please signin an user.');
+ }
+
+ return getUserPointer(options).then(function (currUser) {
+ var query = {};
+ query.className = '_Follower';
+ query.keys = 'follower';
+ query.where = {
+ user: currUser
+ };
+ var data = {};
+ data.query = query;
+ status.data = status.data || {};
+ status.data.source = status.data.source || currUser;
+ data.data = status._getDataJSON();
+ data.inboxType = status.inboxType || 'default';
+ var request = AVRequest('statuses', null, null, 'POST', data, options);
+ return request.then(function (response) {
+ status.id = response.objectId;
+ status.createdAt = AV._parseDate(response.createdAt);
+ return status;
+ });
+ });
+ };
+ /**
+ *
Send a status from current signined user to other user's private status inbox.
+ * @since 0.3.0
+ * @param {AV.Status} status A status object to be send to followers.
+ * @param {String} target The target user or user's objectId.
+ * @param {AuthOptions} options
+ * @return {Promise} A promise that is fulfilled when the send
+ * completes.
+ * @example
+ * // send a private status to user '52e84e47e4b0f8de283b079b'
+ * var status = new AVStatus('image url', 'a message');
+ * AV.Status.sendPrivateStatus(status, '52e84e47e4b0f8de283b079b').then(function(){
+ * //send status successfully.
+ * }, function(err){
+ * //an error threw.
+ * console.dir(err);
+ * });
+ */
+
+
+ AV.Status.sendPrivateStatus = function (status, target) {
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
+
+ if (!getSessionToken(options) && !AV.User.current()) {
+ throw new Error('Please signin an user.');
+ }
+
+ if (!target) {
+ throw new Error('Invalid target user.');
+ }
+
+ var userObjectId = _.isString(target) ? target : target.id;
+
+ if (!userObjectId) {
+ throw new Error('Invalid target user.');
+ }
+
+ return getUserPointer(options).then(function (currUser) {
+ var query = {};
+ query.className = '_User';
+ query.where = {
+ objectId: userObjectId
+ };
+ var data = {};
+ data.query = query;
+ status.data = status.data || {};
+ status.data.source = status.data.source || currUser;
+ data.data = status._getDataJSON();
+ data.inboxType = 'private';
+ status.inboxType = 'private';
+ var request = AVRequest('statuses', null, null, 'POST', data, options);
+ return request.then(function (response) {
+ status.id = response.objectId;
+ status.createdAt = AV._parseDate(response.createdAt);
+ return status;
+ });
+ });
+ };
+ /**
+ * Count unread statuses in someone's inbox.
+ * @since 0.3.0
+ * @param {AV.User} owner The status owner.
+ * @param {String} inboxType The inbox type, 'default' by default.
+ * @param {AuthOptions} options
+ * @return {Promise} A promise that is fulfilled when the count
+ * completes.
+ * @example
+ * AV.Status.countUnreadStatuses(AV.User.current()).then(function(response){
+ * console.log(response.unread); //unread statuses number.
+ * console.log(response.total); //total statuses number.
+ * });
+ */
+
+
+ AV.Status.countUnreadStatuses = function (owner) {
+ var inboxType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'default';
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
+ if (!_.isString(inboxType)) options = inboxType;
+
+ if (!getSessionToken(options) && owner == null && !AV.User.current()) {
+ throw new Error('Please signin an user or pass the owner objectId.');
+ }
+
+ return _promise.default.resolve(owner || getUser(options)).then(function (owner) {
+ var params = {};
+ params.inboxType = AV._encode(inboxType);
+ params.owner = AV._encode(owner);
+ return AVRequest('subscribe/statuses/count', null, null, 'GET', params, options);
+ });
+ };
+ /**
+ * reset unread statuses count in someone's inbox.
+ * @since 2.1.0
+ * @param {AV.User} owner The status owner.
+ * @param {String} inboxType The inbox type, 'default' by default.
+ * @param {AuthOptions} options
+ * @return {Promise} A promise that is fulfilled when the reset
+ * completes.
+ * @example
+ * AV.Status.resetUnreadCount(AV.User.current()).then(function(response){
+ * console.log(response.unread); //unread statuses number.
+ * console.log(response.total); //total statuses number.
+ * });
+ */
+
+
+ AV.Status.resetUnreadCount = function (owner) {
+ var inboxType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'default';
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
+ if (!_.isString(inboxType)) options = inboxType;
+
+ if (!getSessionToken(options) && owner == null && !AV.User.current()) {
+ throw new Error('Please signin an user or pass the owner objectId.');
+ }
+
+ return _promise.default.resolve(owner || getUser(options)).then(function (owner) {
+ var params = {};
+ params.inboxType = AV._encode(inboxType);
+ params.owner = AV._encode(owner);
+ return AVRequest('subscribe/statuses/resetUnreadCount', null, null, 'POST', params, options);
+ });
+ };
+ /**
+ * Create a status query to find someone's published statuses.
+ * @since 0.3.0
+ * @param {AV.User} source The status source, typically the publisher.
+ * @return {AV.Query} The query object for status.
+ * @example
+ * //Find current user's published statuses.
+ * var query = AV.Status.statusQuery(AV.User.current());
+ * query.find().then(function(statuses){
+ * //process statuses
+ * });
+ */
+
+
+ AV.Status.statusQuery = function (source) {
+ var query = new AV.Query('_Status');
+
+ if (source) {
+ query.equalTo('source', source);
+ }
+
+ return query;
+ };
+ /**
+ *
AV.InboxQuery defines a query that is used to fetch somebody's inbox statuses.
+ * @class
+ */
+
+
+ AV.InboxQuery = AV.Query._extend(
+ /** @lends AV.InboxQuery.prototype */
+ {
+ _objectClass: AV.Status,
+ _sinceId: 0,
+ _maxId: 0,
+ _inboxType: 'default',
+ _owner: null,
+ _newObject: function _newObject() {
+ return new AV.Status();
+ },
+ _createRequest: function _createRequest(params, options) {
+ return AV.InboxQuery.__super__._createRequest.call(this, params, options, '/subscribe/statuses');
+ },
+
+ /**
+ * Sets the messageId of results to skip before returning any results.
+ * This is useful for pagination.
+ * Default is zero.
+ * @param {Number} n the mesage id.
+ * @return {AV.InboxQuery} Returns the query, so you can chain this call.
+ */
+ sinceId: function sinceId(id) {
+ this._sinceId = id;
+ return this;
+ },
+
+ /**
+ * Sets the maximal messageId of results。
+ * This is useful for pagination.
+ * Default is zero that is no limition.
+ * @param {Number} n the mesage id.
+ * @return {AV.InboxQuery} Returns the query, so you can chain this call.
+ */
+ maxId: function maxId(id) {
+ this._maxId = id;
+ return this;
+ },
+
+ /**
+ * Sets the owner of the querying inbox.
+ * @param {AV.User} owner The inbox owner.
+ * @return {AV.InboxQuery} Returns the query, so you can chain this call.
+ */
+ owner: function owner(_owner) {
+ this._owner = _owner;
+ return this;
+ },
+
+ /**
+ * Sets the querying inbox type.default is 'default'.
+ * @param {String} type The inbox type.
+ * @return {AV.InboxQuery} Returns the query, so you can chain this call.
+ */
+ inboxType: function inboxType(type) {
+ this._inboxType = type;
+ return this;
+ },
+ _getParams: function _getParams() {
+ var params = AV.InboxQuery.__super__._getParams.call(this);
+
+ params.owner = AV._encode(this._owner);
+ params.inboxType = AV._encode(this._inboxType);
+ params.sinceId = AV._encode(this._sinceId);
+ params.maxId = AV._encode(this._maxId);
+ return params;
+ }
+ });
+ /**
+ * Create a inbox status query to find someone's inbox statuses.
+ * @since 0.3.0
+ * @param {AV.User} owner The inbox's owner
+ * @param {String} inboxType The inbox type,'default' by default.
+ * @return {AV.InboxQuery} The inbox query object.
+ * @see AV.InboxQuery
+ * @example
+ * //Find current user's default inbox statuses.
+ * var query = AV.Status.inboxQuery(AV.User.current());
+ * //find the statuses after the last message id
+ * query.sinceId(lastMessageId);
+ * query.find().then(function(statuses){
+ * //process statuses
+ * });
+ */
+
+ AV.Status.inboxQuery = function (owner, inboxType) {
+ var query = new AV.InboxQuery(AV.Status);
+
+ if (owner) {
+ query._owner = owner;
+ }
+
+ if (inboxType) {
+ query._inboxType = inboxType;
+ }
+
+ return query;
+ };
+};
+
+/***/ }),
+/* 535 */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+var _interopRequireDefault = __webpack_require__(2);
+
+var _stringify = _interopRequireDefault(__webpack_require__(34));
+
+var _map = _interopRequireDefault(__webpack_require__(39));
+
+var _ = __webpack_require__(1);
+
+var AVRequest = __webpack_require__(25)._request;
+
+module.exports = function (AV) {
+ /**
+ * A builder to generate sort string for app searching.For example:
+ * @class
+ * @since 0.5.1
+ * @example
+ * var builder = new AV.SearchSortBuilder();
+ * builder.ascending('key1').descending('key2','max');
+ * var query = new AV.SearchQuery('Player');
+ * query.sortBy(builder);
+ * query.find().then();
+ */
+ AV.SearchSortBuilder = function () {
+ this._sortFields = [];
+ };
+
+ _.extend(AV.SearchSortBuilder.prototype,
+ /** @lends AV.SearchSortBuilder.prototype */
+ {
+ _addField: function _addField(key, order, mode, missing) {
+ var field = {};
+ field[key] = {
+ order: order || 'asc',
+ mode: mode || 'avg',
+ missing: '_' + (missing || 'last')
+ };
+
+ this._sortFields.push(field);
+
+ return this;
+ },
+
+ /**
+ * Sorts the results in ascending order by the given key and options.
+ *
+ * @param {String} key The key to order by.
+ * @param {String} mode The sort mode, default is 'avg', you can choose
+ * 'max' or 'min' too.
+ * @param {String} missing The missing key behaviour, default is 'last',
+ * you can choose 'first' too.
+ * @return {AV.SearchSortBuilder} Returns the builder, so you can chain this call.
+ */
+ ascending: function ascending(key, mode, missing) {
+ return this._addField(key, 'asc', mode, missing);
+ },
+
+ /**
+ * Sorts the results in descending order by the given key and options.
+ *
+ * @param {String} key The key to order by.
+ * @param {String} mode The sort mode, default is 'avg', you can choose
+ * 'max' or 'min' too.
+ * @param {String} missing The missing key behaviour, default is 'last',
+ * you can choose 'first' too.
+ * @return {AV.SearchSortBuilder} Returns the builder, so you can chain this call.
+ */
+ descending: function descending(key, mode, missing) {
+ return this._addField(key, 'desc', mode, missing);
+ },
+
+ /**
+ * Add a proximity based constraint for finding objects with key point
+ * values near the point given.
+ * @param {String} key The key that the AV.GeoPoint is stored in.
+ * @param {AV.GeoPoint} point The reference AV.GeoPoint that is used.
+ * @param {Object} options The other options such as mode,order, unit etc.
+ * @return {AV.SearchSortBuilder} Returns the builder, so you can chain this call.
+ */
+ whereNear: function whereNear(key, point, options) {
+ options = options || {};
+ var field = {};
+ var geo = {
+ lat: point.latitude,
+ lon: point.longitude
+ };
+ var m = {
+ order: options.order || 'asc',
+ mode: options.mode || 'avg',
+ unit: options.unit || 'km'
+ };
+ m[key] = geo;
+ field['_geo_distance'] = m;
+
+ this._sortFields.push(field);
+
+ return this;
+ },
+
+ /**
+ * Build a sort string by configuration.
+ * @return {String} the sort string.
+ */
+ build: function build() {
+ return (0, _stringify.default)(AV._encode(this._sortFields));
+ }
+ });
+ /**
+ * App searching query.Use just like AV.Query:
+ *
+ * Visit App Searching Guide
+ * for more details.
+ * @class
+ * @since 0.5.1
+ * @example
+ * var query = new AV.SearchQuery('Player');
+ * query.queryString('*');
+ * query.find().then(function(results) {
+ * console.log('Found %d objects', query.hits());
+ * //Process results
+ * });
+ */
+
+
+ AV.SearchQuery = AV.Query._extend(
+ /** @lends AV.SearchQuery.prototype */
+ {
+ _sid: null,
+ _hits: 0,
+ _queryString: null,
+ _highlights: null,
+ _sortBuilder: null,
+ _clazz: null,
+ constructor: function constructor(className) {
+ if (className) {
+ this._clazz = className;
+ } else {
+ className = '__INVALID_CLASS';
+ }
+
+ AV.Query.call(this, className);
+ },
+ _createRequest: function _createRequest(params, options) {
+ return AVRequest('search/select', null, null, 'GET', params || this._getParams(), options);
+ },
+
+ /**
+ * Sets the sid of app searching query.Default is null.
+ * @param {String} sid Scroll id for searching.
+ * @return {AV.SearchQuery} Returns the query, so you can chain this call.
+ */
+ sid: function sid(_sid) {
+ this._sid = _sid;
+ return this;
+ },
+
+ /**
+ * Sets the query string of app searching.
+ * @param {String} q The query string.
+ * @return {AV.SearchQuery} Returns the query, so you can chain this call.
+ */
+ queryString: function queryString(q) {
+ this._queryString = q;
+ return this;
+ },
+
+ /**
+ * Sets the highlight fields. Such as
+ *
+ * @param {String|String[]} highlights a list of fields.
+ * @return {AV.SearchQuery} Returns the query, so you can chain this call.
+ */
+ highlights: function highlights(_highlights) {
+ var objects;
+
+ if (_highlights && _.isString(_highlights)) {
+ objects = _.toArray(arguments);
+ } else {
+ objects = _highlights;
+ }
+
+ this._highlights = objects;
+ return this;
+ },
+
+ /**
+ * Sets the sort builder for this query.
+ * @see AV.SearchSortBuilder
+ * @param { AV.SearchSortBuilder} builder The sort builder.
+ * @return {AV.SearchQuery} Returns the query, so you can chain this call.
+ *
+ */
+ sortBy: function sortBy(builder) {
+ this._sortBuilder = builder;
+ return this;
+ },
+
+ /**
+ * Returns the number of objects that match this query.
+ * @return {Number}
+ */
+ hits: function hits() {
+ if (!this._hits) {
+ this._hits = 0;
+ }
+
+ return this._hits;
+ },
+ _processResult: function _processResult(json) {
+ delete json['className'];
+ delete json['_app_url'];
+ delete json['_deeplink'];
+ return json;
+ },
+
+ /**
+ * Returns true when there are more documents can be retrieved by this
+ * query instance, you can call find function to get more results.
+ * @see AV.SearchQuery#find
+ * @return {Boolean}
+ */
+ hasMore: function hasMore() {
+ return !this._hitEnd;
+ },
+
+ /**
+ * Reset current query instance state(such as sid, hits etc) except params
+ * for a new searching. After resetting, hasMore() will return true.
+ */
+ reset: function reset() {
+ this._hitEnd = false;
+ this._sid = null;
+ this._hits = 0;
+ },
+
+ /**
+ * Retrieves a list of AVObjects that satisfy this query.
+ * Either options.success or options.error is called when the find
+ * completes.
+ *
+ * @see AV.Query#find
+ * @param {AuthOptions} options
+ * @return {Promise} A promise that is resolved with the results when
+ * the query completes.
+ */
+ find: function find(options) {
+ var self = this;
+
+ var request = this._createRequest(undefined, options);
+
+ return request.then(function (response) {
+ //update sid for next querying.
+ if (response.sid) {
+ self._oldSid = self._sid;
+ self._sid = response.sid;
+ } else {
+ self._sid = null;
+ self._hitEnd = true;
+ }
+
+ self._hits = response.hits || 0;
+ return (0, _map.default)(_).call(_, response.results, function (json) {
+ if (json.className) {
+ response.className = json.className;
+ }
+
+ var obj = self._newObject(response);
+
+ obj.appURL = json['_app_url'];
+
+ obj._finishFetch(self._processResult(json), true);
+
+ return obj;
+ });
+ });
+ },
+ _getParams: function _getParams() {
+ var params = AV.SearchQuery.__super__._getParams.call(this);
+
+ delete params.where;
+
+ if (this._clazz) {
+ params.clazz = this.className;
+ }
+
+ if (this._sid) {
+ params.sid = this._sid;
+ }
+
+ if (!this._queryString) {
+ throw new Error('Please set query string.');
+ } else {
+ params.q = this._queryString;
+ }
+
+ if (this._highlights) {
+ params.highlights = this._highlights.join(',');
+ }
+
+ if (this._sortBuilder && params.order) {
+ throw new Error('sort and order can not be set at same time.');
+ }
+
+ if (this._sortBuilder) {
+ params.sort = this._sortBuilder.build();
+ }
+
+ return params;
+ }
+ });
+};
+/**
+ * Sorts the results in ascending order by the given key.
+ *
+ * @method AV.SearchQuery#ascending
+ * @param {String} key The key to order by.
+ * @return {AV.SearchQuery} Returns the query, so you can chain this call.
+ */
+
+/**
+ * Also sorts the results in ascending order by the given key. The previous sort keys have
+ * precedence over this key.
+ *
+ * @method AV.SearchQuery#addAscending
+ * @param {String} key The key to order by
+ * @return {AV.SearchQuery} Returns the query so you can chain this call.
+ */
+
+/**
+ * Sorts the results in descending order by the given key.
+ *
+ * @method AV.SearchQuery#descending
+ * @param {String} key The key to order by.
+ * @return {AV.SearchQuery} Returns the query, so you can chain this call.
+ */
+
+/**
+ * Also sorts the results in descending order by the given key. The previous sort keys have
+ * precedence over this key.
+ *
+ * @method AV.SearchQuery#addDescending
+ * @param {String} key The key to order by
+ * @return {AV.SearchQuery} Returns the query so you can chain this call.
+ */
+
+/**
+ * Include nested AV.Objects for the provided key. You can use dot
+ * notation to specify which fields in the included object are also fetch.
+ * @method AV.SearchQuery#include
+ * @param {String[]} keys The name of the key to include.
+ * @return {AV.SearchQuery} Returns the query, so you can chain this call.
+ */
+
+/**
+ * Sets the number of results to skip before returning any results.
+ * This is useful for pagination.
+ * Default is to skip zero results.
+ * @method AV.SearchQuery#skip
+ * @param {Number} n the number of results to skip.
+ * @return {AV.SearchQuery} Returns the query, so you can chain this call.
+ */
+
+/**
+ * Sets the limit of the number of results to return. The default limit is
+ * 100, with a maximum of 1000 results being returned at a time.
+ * @method AV.SearchQuery#limit
+ * @param {Number} n the number of results to limit to.
+ * @return {AV.SearchQuery} Returns the query, so you can chain this call.
+ */
+
+/***/ }),
+/* 536 */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+var _interopRequireDefault = __webpack_require__(2);
+
+var _promise = _interopRequireDefault(__webpack_require__(10));
+
+var _ = __webpack_require__(1);
+
+var AVError = __webpack_require__(40);
+
+var _require = __webpack_require__(25),
+ request = _require.request;
+
+module.exports = function (AV) {
+ /**
+ * 包含了使用了 LeanCloud
+ * 离线数据分析功能的函数。
+ *
+ * { "sql" : "select count(*) as c,gender from _User group by gender",
+ * "saveAs": {
+ * "className" : "UserGender",
+ * "limit": 1
+ * }
+ * }
+ *
+ * sql 指定任务执行的 SQL 语句, saveAs(可选) 指定将结果保存在哪张表里,limit 最大 1000。
+ * @param {AuthOptions} [options]
+ * @return {Promise} A promise that will be resolved with the result
+ * of the function.
+ */
+ startJob: function startJob(jobConfig, options) {
+ if (!jobConfig || !jobConfig.sql) {
+ throw new Error('Please provide the sql to run the job.');
+ }
+
+ var data = {
+ jobConfig: jobConfig,
+ appId: AV.applicationId
+ };
+ return request({
+ path: '/bigquery/jobs',
+ method: 'POST',
+ data: AV._encode(data, null, true),
+ authOptions: options,
+ signKey: false
+ }).then(function (resp) {
+ return AV._decode(resp).id;
+ });
+ },
+
+ /**
+ * 监听 Insight 任务事件(未来推出独立部署的离线分析服务后开放)
+ *
+ * 仅在云引擎运行环境下有效。
+ *
+ * @param {String} event 监听的事件,目前尚不支持。
+ * @param {Function} 监听回调函数,接收 (err, id) 两个参数,err 表示错误信息,
+ * id 表示任务 id。接下来你可以拿这个 id 使用AV.Insight.JobQuery 查询任务状态和结果。
+ *
+ */
+ on: function on(event, cb) {}
+ });
+ /**
+ * 创建一个对象,用于查询 Insight 任务状态和结果。
+ * @class
+ * @param {String} id 任务 id
+ * @since 0.5.5
+ */
+
+
+ AV.Insight.JobQuery = function (id, className) {
+ if (!id) {
+ throw new Error('Please provide the job id.');
+ }
+
+ this.id = id;
+ this.className = className;
+ this._skip = 0;
+ this._limit = 100;
+ };
+
+ _.extend(AV.Insight.JobQuery.prototype,
+ /** @lends AV.Insight.JobQuery.prototype */
+ {
+ /**
+ * Sets the number of results to skip before returning any results.
+ * This is useful for pagination.
+ * Default is to skip zero results.
+ * @param {Number} n the number of results to skip.
+ * @return {AV.Query} Returns the query, so you can chain this call.
+ */
+ skip: function skip(n) {
+ this._skip = n;
+ return this;
+ },
+
+ /**
+ * Sets the limit of the number of results to return. The default limit is
+ * 100, with a maximum of 1000 results being returned at a time.
+ * @param {Number} n the number of results to limit to.
+ * @return {AV.Query} Returns the query, so you can chain this call.
+ */
+ limit: function limit(n) {
+ this._limit = n;
+ return this;
+ },
+
+ /**
+ * 查询任务状态和结果,任务结果为一个 JSON 对象,包括 status 表示任务状态, totalCount 表示总数,
+ * results 数组表示任务结果数组,previewCount 表示可以返回的结果总数,任务的开始和截止时间
+ * startTime、endTime 等信息。
+ *
+ * @param {AuthOptions} [options]
+ * @return {Promise} A promise that will be resolved with the result
+ * of the function.
+ *
+ */
+ find: function find(options) {
+ var params = {
+ skip: this._skip,
+ limit: this._limit
+ };
+ return request({
+ path: "/bigquery/jobs/".concat(this.id),
+ method: 'GET',
+ query: params,
+ authOptions: options,
+ signKey: false
+ }).then(function (response) {
+ if (response.error) {
+ return _promise.default.reject(new AVError(response.code, response.error));
+ }
+
+ return _promise.default.resolve(response);
+ });
+ }
+ });
+};
+
+/***/ }),
+/* 537 */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+var _interopRequireDefault = __webpack_require__(2);
+
+var _promise = _interopRequireDefault(__webpack_require__(10));
+
+var _ = __webpack_require__(1);
+
+var _require = __webpack_require__(25),
+ LCRequest = _require.request;
+
+var _require2 = __webpack_require__(28),
+ getSessionToken = _require2.getSessionToken;
+
+module.exports = function (AV) {
+ var getUserWithSessionToken = function getUserWithSessionToken(authOptions) {
+ if (authOptions.user) {
+ if (!authOptions.user._sessionToken) {
+ throw new Error('authOptions.user is not signed in.');
+ }
+
+ return _promise.default.resolve(authOptions.user);
+ }
+
+ if (authOptions.sessionToken) {
+ return AV.User._fetchUserBySessionToken(authOptions.sessionToken);
+ }
+
+ return AV.User.currentAsync();
+ };
+
+ var getSessionTokenAsync = function getSessionTokenAsync(authOptions) {
+ var sessionToken = getSessionToken(authOptions);
+
+ if (sessionToken) {
+ return _promise.default.resolve(sessionToken);
+ }
+
+ return AV.User.currentAsync().then(function (user) {
+ if (user) {
+ return user.getSessionToken();
+ }
+ });
+ };
+ /**
+ * Contains functions to deal with Friendship in LeanCloud.
+ * @class
+ */
+
+
+ AV.Friendship = {
+ /**
+ * Request friendship.
+ * @since 4.8.0
+ * @param {String | AV.User | Object} options if an AV.User or string is given, it will be used as the friend.
+ * @param {AV.User | string} options.friend The friend (or friend's objectId) to follow.
+ * @param {Object} [options.attributes] key-value attributes dictionary to be used as conditions of followeeQuery.
+ * @param {AuthOptions} [authOptions]
+ * @return {Promise}
+ */
+ request: function request(options) {
+ var authOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
+ var friend;
+ var attributes;
+
+ if (options.friend) {
+ friend = options.friend;
+ attributes = options.attributes;
+ } else {
+ friend = options;
+ }
+
+ var friendObj = _.isString(friend) ? AV.Object.createWithoutData('_User', friend) : friend;
+ return getUserWithSessionToken(authOptions).then(function (userObj) {
+ if (!userObj) {
+ throw new Error('Please signin an user.');
+ }
+
+ return LCRequest({
+ method: 'POST',
+ path: '/users/friendshipRequests',
+ data: {
+ user: userObj._toPointer(),
+ friend: friendObj._toPointer(),
+ friendship: attributes
+ },
+ authOptions: authOptions
+ });
+ });
+ },
+
+ /**
+ * Accept a friendship request.
+ * @since 4.8.0
+ * @param {AV.Object | string | Object} options if an AV.Object or string is given, it will be used as the request in _FriendshipRequest.
+ * @param {AV.Object} options.request The request (or it's objectId) to be accepted.
+ * @param {Object} [options.attributes] key-value attributes dictionary to be used as conditions of {@link AV#followeeQuery}.
+ * @param {AuthOptions} [authOptions]
+ * @return {Promise}
+ */
+ acceptRequest: function acceptRequest(options) {
+ var authOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
+ var request;
+ var attributes;
+
+ if (options.request) {
+ request = options.request;
+ attributes = options.attributes;
+ } else {
+ request = options;
+ }
+
+ var requestId = _.isString(request) ? request : request.id;
+ return getSessionTokenAsync(authOptions).then(function (sessionToken) {
+ if (!sessionToken) {
+ throw new Error('Please signin an user.');
+ }
+
+ return LCRequest({
+ method: 'PUT',
+ path: '/users/friendshipRequests/' + requestId + '/accept',
+ data: {
+ friendship: AV._encode(attributes)
+ },
+ authOptions: authOptions
+ });
+ });
+ },
+
+ /**
+ * Decline a friendship request.
+ * @param {AV.Object | string} request The request (or it's objectId) to be declined.
+ * @param {AuthOptions} [authOptions]
+ * @return {Promise}
+ */
+ declineRequest: function declineRequest(request) {
+ var authOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
+ var requestId = _.isString(request) ? request : request.id;
+ return getSessionTokenAsync(authOptions).then(function (sessionToken) {
+ if (!sessionToken) {
+ throw new Error('Please signin an user.');
+ }
+
+ return LCRequest({
+ method: 'PUT',
+ path: '/users/friendshipRequests/' + requestId + '/decline',
+ authOptions: authOptions
+ });
+ });
+ }
+ };
+};
+
+/***/ }),
+/* 538 */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+var _interopRequireDefault = __webpack_require__(2);
+
+var _stringify = _interopRequireDefault(__webpack_require__(34));
+
+var _ = __webpack_require__(1);
+
+var _require = __webpack_require__(25),
+ _request = _require._request;
+
+var AV = __webpack_require__(59);
+
+var serializeMessage = function serializeMessage(message) {
+ if (typeof message === 'string') {
+ return message;
+ }
+
+ if (typeof message.getPayload === 'function') {
+ return (0, _stringify.default)(message.getPayload());
+ }
+
+ return (0, _stringify.default)(message);
+};
+/**
+ *
An AV.Conversation is a local representation of a LeanCloud realtime's
+ * conversation. This class is a subclass of AV.Object, and retains the
+ * same functionality of an AV.Object, but also extends it with various
+ * conversation specific methods, like get members, creators of this conversation.
+ *
\n */\n AV.Cloud.useMasterKey = () => {\n AV._config.useMasterKey = true;\n };\n}\n\n/**\n * Call this method to set production environment variable.\n * @function AV.setProduction\n * @param {Boolean} production True is production environment,and\n * it's true by default.\n */\nAV.setProduction = production => {\n if (!isNullOrUndefined(production)) {\n AV._config.production = production ? 1 : 0;\n } else {\n // change to default value\n AV._config.production = null;\n }\n};\n\nAV._setServerURLs = (urls, disableAppRouter = true) => {\n if (typeof urls !== 'string') {\n extend(AV._config.serverURLs, urls);\n } else {\n AV._config.serverURLs = fillServerURLs(urls);\n }\n if (disableAppRouter) {\n if (AV._appRouter) {\n AV._appRouter.disable();\n } else {\n _disableAppRouter = true;\n }\n }\n};\n/**\n * Set server URLs for services.\n * @function AV.setServerURL\n * @since 4.3.0\n * @param {String|ServerURLs} urls URLs for services. if a string was given, it will be applied for all services.\n * You can also set them when initializing SDK with `options.serverURL`\n */\nAV.setServerURL = urls => AV._setServerURLs(urls);\nAV.setServerURLs = AV.setServerURL;\n\nAV.keepErrorRawMessage = value => {\n AV._sharedConfig.keepErrorRawMessage = value;\n};\n\n/**\n * Set a deadline for requests to complete.\n * Note that file upload requests are not affected.\n * @function AV.setRequestTimeout\n * @since 3.6.0\n * @param {number} ms\n */\nAV.setRequestTimeout = ms => {\n AV._config.requestTimeout = ms;\n};\n\n// backword compatible\nAV.initialize = AV.init;\n\nconst defineConfig = property =>\n Object.defineProperty(AV, property, {\n get() {\n return AV._config[property];\n },\n set(value) {\n AV._config[property] = value;\n },\n });\n\n['applicationId', 'applicationKey', 'masterKey', 'hookKey'].forEach(\n defineConfig\n);\n\n\n\n// WEBPACK FOOTER //\n// ./src/init.js","var isPrototypeOf = require('../../internals/object-is-prototype-of');\nvar method = require('../array/virtual/slice');\n\nvar ArrayPrototype = Array.prototype;\n\nmodule.exports = function (it) {\n var own = it.slice;\n return it === ArrayPrototype || (isPrototypeOf(ArrayPrototype, it) && own === ArrayPrototype.slice) ? method : own;\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/es/instance/slice.js\n// module id = 383\n// module chunks = 0 1","require('../../../modules/es.array.slice');\nvar entryVirtual = require('../../../internals/entry-virtual');\n\nmodule.exports = entryVirtual('Array').slice;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/es/array/virtual/slice.js\n// module id = 384\n// module chunks = 0 1","'use strict';\nvar $ = require('../internals/export');\nvar isArray = require('../internals/is-array');\nvar isConstructor = require('../internals/is-constructor');\nvar isObject = require('../internals/is-object');\nvar toAbsoluteIndex = require('../internals/to-absolute-index');\nvar lengthOfArrayLike = require('../internals/length-of-array-like');\nvar toIndexedObject = require('../internals/to-indexed-object');\nvar createProperty = require('../internals/create-property');\nvar wellKnownSymbol = require('../internals/well-known-symbol');\nvar arrayMethodHasSpeciesSupport = require('../internals/array-method-has-species-support');\nvar un$Slice = require('../internals/array-slice');\n\nvar HAS_SPECIES_SUPPORT = arrayMethodHasSpeciesSupport('slice');\n\nvar SPECIES = wellKnownSymbol('species');\nvar $Array = Array;\nvar max = Math.max;\n\n// `Array.prototype.slice` method\n// https://tc39.es/ecma262/#sec-array.prototype.slice\n// fallback for not array-like ES3 strings and DOM objects\n$({ target: 'Array', proto: true, forced: !HAS_SPECIES_SUPPORT }, {\n slice: function slice(start, end) {\n var O = toIndexedObject(this);\n var length = lengthOfArrayLike(O);\n var k = toAbsoluteIndex(start, length);\n var fin = toAbsoluteIndex(end === undefined ? length : end, length);\n // inline `ArraySpeciesCreate` for usage native `Array#slice` where it's possible\n var Constructor, result, n;\n if (isArray(O)) {\n Constructor = O.constructor;\n // cross-realm fallback\n if (isConstructor(Constructor) && (Constructor === $Array || isArray(Constructor.prototype))) {\n Constructor = undefined;\n } else if (isObject(Constructor)) {\n Constructor = Constructor[SPECIES];\n if (Constructor === null) Constructor = undefined;\n }\n if (Constructor === $Array || Constructor === undefined) {\n return un$Slice(O, k, fin);\n }\n }\n result = new (Constructor === undefined ? $Array : Constructor)(max(fin - k, 0));\n for (n = 0; k < fin; k++, n++) if (k in O) createProperty(result, n, O[k]);\n result.length = n;\n return result;\n }\n});\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.array.slice.js\n// module id = 385\n// module chunks = 0 1","require('../../modules/es.object.define-property');\nvar path = require('../../internals/path');\n\nvar Object = path.Object;\n\nvar defineProperty = module.exports = function defineProperty(it, key, desc) {\n return Object.defineProperty(it, key, desc);\n};\n\nif (Object.defineProperty.sham) defineProperty.sham = true;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/es/object/define-property.js\n// module id = 386\n// module chunks = 0 1","var $ = require('../internals/export');\nvar DESCRIPTORS = require('../internals/descriptors');\nvar defineProperty = require('../internals/object-define-property').f;\n\n// `Object.defineProperty` method\n// https://tc39.es/ecma262/#sec-object.defineproperty\n// eslint-disable-next-line es-x/no-object-defineproperty -- safe\n$({ target: 'Object', stat: true, forced: Object.defineProperty !== defineProperty, sham: !DESCRIPTORS }, {\n defineProperty: defineProperty\n});\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.object.define-property.js\n// module id = 387\n// module chunks = 0 1","const ajax = require('./utils/ajax');\nconst Cache = require('./cache');\n\nfunction AppRouter(AV) {\n this.AV = AV;\n this.lockedUntil = 0;\n Cache.getAsync('serverURLs')\n .then(data => {\n if (this.disabled) return;\n if (!data) return this.lock(0);\n const { serverURLs, lockedUntil } = data;\n this.AV._setServerURLs(serverURLs, false);\n this.lockedUntil = lockedUntil;\n })\n .catch(() => this.lock(0));\n}\n\nAppRouter.prototype.disable = function disable() {\n this.disabled = true;\n};\nAppRouter.prototype.lock = function lock(ttl) {\n this.lockedUntil = Date.now() + ttl;\n};\nAppRouter.prototype.refresh = function refresh() {\n if (this.disabled) return;\n if (Date.now() < this.lockedUntil) return;\n this.lock(10);\n const url = 'https://app-router.com/2/route';\n return ajax({\n method: 'get',\n url,\n query: {\n appId: this.AV.applicationId,\n },\n })\n .then(servers => {\n if (this.disabled) return;\n let ttl = servers.ttl;\n if (!ttl) throw new Error('missing ttl');\n ttl = ttl * 1000;\n const protocal = 'https://';\n const serverURLs = {\n push: protocal + servers.push_server,\n stats: protocal + servers.stats_server,\n engine: protocal + servers.engine_server,\n api: protocal + servers.api_server,\n };\n this.AV._setServerURLs(serverURLs, false);\n this.lock(ttl);\n return Cache.setAsync(\n 'serverURLs',\n {\n serverURLs,\n lockedUntil: this.lockedUntil,\n },\n ttl\n );\n })\n .catch(error => {\n // bypass all errors\n console.warn(`refresh server URLs failed: ${error.message}`);\n this.lock(600);\n });\n};\n\nmodule.exports = AppRouter;\n\n\n\n// WEBPACK FOOTER //\n// ./src/app-router.js","module.exports = require('../../full/symbol');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/features/symbol/index.js\n// module id = 389\n// module chunks = 0 1","var parent = require('../../actual/symbol');\nrequire('../../modules/esnext.symbol.async-dispose');\nrequire('../../modules/esnext.symbol.dispose');\nrequire('../../modules/esnext.symbol.matcher');\nrequire('../../modules/esnext.symbol.metadata-key');\nrequire('../../modules/esnext.symbol.observable');\n// TODO: Remove from `core-js@4`\nrequire('../../modules/esnext.symbol.metadata');\nrequire('../../modules/esnext.symbol.pattern-match');\nrequire('../../modules/esnext.symbol.replace-all');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/full/symbol/index.js\n// module id = 390\n// module chunks = 0 1","var parent = require('../../stable/symbol');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/actual/symbol/index.js\n// module id = 391\n// module chunks = 0 1","require('../../modules/es.array.concat');\nrequire('../../modules/es.object.to-string');\nrequire('../../modules/es.symbol');\nrequire('../../modules/es.symbol.async-iterator');\nrequire('../../modules/es.symbol.description');\nrequire('../../modules/es.symbol.has-instance');\nrequire('../../modules/es.symbol.is-concat-spreadable');\nrequire('../../modules/es.symbol.iterator');\nrequire('../../modules/es.symbol.match');\nrequire('../../modules/es.symbol.match-all');\nrequire('../../modules/es.symbol.replace');\nrequire('../../modules/es.symbol.search');\nrequire('../../modules/es.symbol.species');\nrequire('../../modules/es.symbol.split');\nrequire('../../modules/es.symbol.to-primitive');\nrequire('../../modules/es.symbol.to-string-tag');\nrequire('../../modules/es.symbol.unscopables');\nrequire('../../modules/es.json.to-string-tag');\nrequire('../../modules/es.math.to-string-tag');\nrequire('../../modules/es.reflect.to-string-tag');\nvar path = require('../../internals/path');\n\nmodule.exports = path.Symbol;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/es/symbol/index.js\n// module id = 392\n// module chunks = 0 1","// TODO: Remove this module from `core-js@4` since it's split to modules listed below\nrequire('../modules/es.symbol.constructor');\nrequire('../modules/es.symbol.for');\nrequire('../modules/es.symbol.key-for');\nrequire('../modules/es.json.stringify');\nrequire('../modules/es.object.get-own-property-symbols');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.symbol.js\n// module id = 393\n// module chunks = 0 1","'use strict';\nvar $ = require('../internals/export');\nvar global = require('../internals/global');\nvar call = require('../internals/function-call');\nvar uncurryThis = require('../internals/function-uncurry-this');\nvar IS_PURE = require('../internals/is-pure');\nvar DESCRIPTORS = require('../internals/descriptors');\nvar NATIVE_SYMBOL = require('../internals/native-symbol');\nvar fails = require('../internals/fails');\nvar hasOwn = require('../internals/has-own-property');\nvar isPrototypeOf = require('../internals/object-is-prototype-of');\nvar anObject = require('../internals/an-object');\nvar toIndexedObject = require('../internals/to-indexed-object');\nvar toPropertyKey = require('../internals/to-property-key');\nvar $toString = require('../internals/to-string');\nvar createPropertyDescriptor = require('../internals/create-property-descriptor');\nvar nativeObjectCreate = require('../internals/object-create');\nvar objectKeys = require('../internals/object-keys');\nvar getOwnPropertyNamesModule = require('../internals/object-get-own-property-names');\nvar getOwnPropertyNamesExternal = require('../internals/object-get-own-property-names-external');\nvar getOwnPropertySymbolsModule = require('../internals/object-get-own-property-symbols');\nvar getOwnPropertyDescriptorModule = require('../internals/object-get-own-property-descriptor');\nvar definePropertyModule = require('../internals/object-define-property');\nvar definePropertiesModule = require('../internals/object-define-properties');\nvar propertyIsEnumerableModule = require('../internals/object-property-is-enumerable');\nvar defineBuiltIn = require('../internals/define-built-in');\nvar shared = require('../internals/shared');\nvar sharedKey = require('../internals/shared-key');\nvar hiddenKeys = require('../internals/hidden-keys');\nvar uid = require('../internals/uid');\nvar wellKnownSymbol = require('../internals/well-known-symbol');\nvar wrappedWellKnownSymbolModule = require('../internals/well-known-symbol-wrapped');\nvar defineWellKnownSymbol = require('../internals/define-well-known-symbol');\nvar defineSymbolToPrimitive = require('../internals/symbol-define-to-primitive');\nvar setToStringTag = require('../internals/set-to-string-tag');\nvar InternalStateModule = require('../internals/internal-state');\nvar $forEach = require('../internals/array-iteration').forEach;\n\nvar HIDDEN = sharedKey('hidden');\nvar SYMBOL = 'Symbol';\nvar PROTOTYPE = 'prototype';\n\nvar setInternalState = InternalStateModule.set;\nvar getInternalState = InternalStateModule.getterFor(SYMBOL);\n\nvar ObjectPrototype = Object[PROTOTYPE];\nvar $Symbol = global.Symbol;\nvar SymbolPrototype = $Symbol && $Symbol[PROTOTYPE];\nvar TypeError = global.TypeError;\nvar QObject = global.QObject;\nvar nativeGetOwnPropertyDescriptor = getOwnPropertyDescriptorModule.f;\nvar nativeDefineProperty = definePropertyModule.f;\nvar nativeGetOwnPropertyNames = getOwnPropertyNamesExternal.f;\nvar nativePropertyIsEnumerable = propertyIsEnumerableModule.f;\nvar push = uncurryThis([].push);\n\nvar AllSymbols = shared('symbols');\nvar ObjectPrototypeSymbols = shared('op-symbols');\nvar WellKnownSymbolsStore = shared('wks');\n\n// Don't use setters in Qt Script, https://github.com/zloirock/core-js/issues/173\nvar USE_SETTER = !QObject || !QObject[PROTOTYPE] || !QObject[PROTOTYPE].findChild;\n\n// fallback for old Android, https://code.google.com/p/v8/issues/detail?id=687\nvar setSymbolDescriptor = DESCRIPTORS && fails(function () {\n return nativeObjectCreate(nativeDefineProperty({}, 'a', {\n get: function () { return nativeDefineProperty(this, 'a', { value: 7 }).a; }\n })).a != 7;\n}) ? function (O, P, Attributes) {\n var ObjectPrototypeDescriptor = nativeGetOwnPropertyDescriptor(ObjectPrototype, P);\n if (ObjectPrototypeDescriptor) delete ObjectPrototype[P];\n nativeDefineProperty(O, P, Attributes);\n if (ObjectPrototypeDescriptor && O !== ObjectPrototype) {\n nativeDefineProperty(ObjectPrototype, P, ObjectPrototypeDescriptor);\n }\n} : nativeDefineProperty;\n\nvar wrap = function (tag, description) {\n var symbol = AllSymbols[tag] = nativeObjectCreate(SymbolPrototype);\n setInternalState(symbol, {\n type: SYMBOL,\n tag: tag,\n description: description\n });\n if (!DESCRIPTORS) symbol.description = description;\n return symbol;\n};\n\nvar $defineProperty = function defineProperty(O, P, Attributes) {\n if (O === ObjectPrototype) $defineProperty(ObjectPrototypeSymbols, P, Attributes);\n anObject(O);\n var key = toPropertyKey(P);\n anObject(Attributes);\n if (hasOwn(AllSymbols, key)) {\n if (!Attributes.enumerable) {\n if (!hasOwn(O, HIDDEN)) nativeDefineProperty(O, HIDDEN, createPropertyDescriptor(1, {}));\n O[HIDDEN][key] = true;\n } else {\n if (hasOwn(O, HIDDEN) && O[HIDDEN][key]) O[HIDDEN][key] = false;\n Attributes = nativeObjectCreate(Attributes, { enumerable: createPropertyDescriptor(0, false) });\n } return setSymbolDescriptor(O, key, Attributes);\n } return nativeDefineProperty(O, key, Attributes);\n};\n\nvar $defineProperties = function defineProperties(O, Properties) {\n anObject(O);\n var properties = toIndexedObject(Properties);\n var keys = objectKeys(properties).concat($getOwnPropertySymbols(properties));\n $forEach(keys, function (key) {\n if (!DESCRIPTORS || call($propertyIsEnumerable, properties, key)) $defineProperty(O, key, properties[key]);\n });\n return O;\n};\n\nvar $create = function create(O, Properties) {\n return Properties === undefined ? nativeObjectCreate(O) : $defineProperties(nativeObjectCreate(O), Properties);\n};\n\nvar $propertyIsEnumerable = function propertyIsEnumerable(V) {\n var P = toPropertyKey(V);\n var enumerable = call(nativePropertyIsEnumerable, this, P);\n if (this === ObjectPrototype && hasOwn(AllSymbols, P) && !hasOwn(ObjectPrototypeSymbols, P)) return false;\n return enumerable || !hasOwn(this, P) || !hasOwn(AllSymbols, P) || hasOwn(this, HIDDEN) && this[HIDDEN][P]\n ? enumerable : true;\n};\n\nvar $getOwnPropertyDescriptor = function getOwnPropertyDescriptor(O, P) {\n var it = toIndexedObject(O);\n var key = toPropertyKey(P);\n if (it === ObjectPrototype && hasOwn(AllSymbols, key) && !hasOwn(ObjectPrototypeSymbols, key)) return;\n var descriptor = nativeGetOwnPropertyDescriptor(it, key);\n if (descriptor && hasOwn(AllSymbols, key) && !(hasOwn(it, HIDDEN) && it[HIDDEN][key])) {\n descriptor.enumerable = true;\n }\n return descriptor;\n};\n\nvar $getOwnPropertyNames = function getOwnPropertyNames(O) {\n var names = nativeGetOwnPropertyNames(toIndexedObject(O));\n var result = [];\n $forEach(names, function (key) {\n if (!hasOwn(AllSymbols, key) && !hasOwn(hiddenKeys, key)) push(result, key);\n });\n return result;\n};\n\nvar $getOwnPropertySymbols = function (O) {\n var IS_OBJECT_PROTOTYPE = O === ObjectPrototype;\n var names = nativeGetOwnPropertyNames(IS_OBJECT_PROTOTYPE ? ObjectPrototypeSymbols : toIndexedObject(O));\n var result = [];\n $forEach(names, function (key) {\n if (hasOwn(AllSymbols, key) && (!IS_OBJECT_PROTOTYPE || hasOwn(ObjectPrototype, key))) {\n push(result, AllSymbols[key]);\n }\n });\n return result;\n};\n\n// `Symbol` constructor\n// https://tc39.es/ecma262/#sec-symbol-constructor\nif (!NATIVE_SYMBOL) {\n $Symbol = function Symbol() {\n if (isPrototypeOf(SymbolPrototype, this)) throw TypeError('Symbol is not a constructor');\n var description = !arguments.length || arguments[0] === undefined ? undefined : $toString(arguments[0]);\n var tag = uid(description);\n var setter = function (value) {\n if (this === ObjectPrototype) call(setter, ObjectPrototypeSymbols, value);\n if (hasOwn(this, HIDDEN) && hasOwn(this[HIDDEN], tag)) this[HIDDEN][tag] = false;\n setSymbolDescriptor(this, tag, createPropertyDescriptor(1, value));\n };\n if (DESCRIPTORS && USE_SETTER) setSymbolDescriptor(ObjectPrototype, tag, { configurable: true, set: setter });\n return wrap(tag, description);\n };\n\n SymbolPrototype = $Symbol[PROTOTYPE];\n\n defineBuiltIn(SymbolPrototype, 'toString', function toString() {\n return getInternalState(this).tag;\n });\n\n defineBuiltIn($Symbol, 'withoutSetter', function (description) {\n return wrap(uid(description), description);\n });\n\n propertyIsEnumerableModule.f = $propertyIsEnumerable;\n definePropertyModule.f = $defineProperty;\n definePropertiesModule.f = $defineProperties;\n getOwnPropertyDescriptorModule.f = $getOwnPropertyDescriptor;\n getOwnPropertyNamesModule.f = getOwnPropertyNamesExternal.f = $getOwnPropertyNames;\n getOwnPropertySymbolsModule.f = $getOwnPropertySymbols;\n\n wrappedWellKnownSymbolModule.f = function (name) {\n return wrap(wellKnownSymbol(name), name);\n };\n\n if (DESCRIPTORS) {\n // https://github.com/tc39/proposal-Symbol-description\n nativeDefineProperty(SymbolPrototype, 'description', {\n configurable: true,\n get: function description() {\n return getInternalState(this).description;\n }\n });\n if (!IS_PURE) {\n defineBuiltIn(ObjectPrototype, 'propertyIsEnumerable', $propertyIsEnumerable, { unsafe: true });\n }\n }\n}\n\n$({ global: true, constructor: true, wrap: true, forced: !NATIVE_SYMBOL, sham: !NATIVE_SYMBOL }, {\n Symbol: $Symbol\n});\n\n$forEach(objectKeys(WellKnownSymbolsStore), function (name) {\n defineWellKnownSymbol(name);\n});\n\n$({ target: SYMBOL, stat: true, forced: !NATIVE_SYMBOL }, {\n useSetter: function () { USE_SETTER = true; },\n useSimple: function () { USE_SETTER = false; }\n});\n\n$({ target: 'Object', stat: true, forced: !NATIVE_SYMBOL, sham: !DESCRIPTORS }, {\n // `Object.create` method\n // https://tc39.es/ecma262/#sec-object.create\n create: $create,\n // `Object.defineProperty` method\n // https://tc39.es/ecma262/#sec-object.defineproperty\n defineProperty: $defineProperty,\n // `Object.defineProperties` method\n // https://tc39.es/ecma262/#sec-object.defineproperties\n defineProperties: $defineProperties,\n // `Object.getOwnPropertyDescriptor` method\n // https://tc39.es/ecma262/#sec-object.getownpropertydescriptors\n getOwnPropertyDescriptor: $getOwnPropertyDescriptor\n});\n\n$({ target: 'Object', stat: true, forced: !NATIVE_SYMBOL }, {\n // `Object.getOwnPropertyNames` method\n // https://tc39.es/ecma262/#sec-object.getownpropertynames\n getOwnPropertyNames: $getOwnPropertyNames\n});\n\n// `Symbol.prototype[@@toPrimitive]` method\n// https://tc39.es/ecma262/#sec-symbol.prototype-@@toprimitive\ndefineSymbolToPrimitive();\n\n// `Symbol.prototype[@@toStringTag]` property\n// https://tc39.es/ecma262/#sec-symbol.prototype-@@tostringtag\nsetToStringTag($Symbol, SYMBOL);\n\nhiddenKeys[HIDDEN] = true;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.symbol.constructor.js\n// module id = 394\n// module chunks = 0 1","/* eslint-disable es-x/no-object-getownpropertynames -- safe */\nvar classof = require('../internals/classof-raw');\nvar toIndexedObject = require('../internals/to-indexed-object');\nvar $getOwnPropertyNames = require('../internals/object-get-own-property-names').f;\nvar arraySlice = require('../internals/array-slice-simple');\n\nvar windowNames = typeof window == 'object' && window && Object.getOwnPropertyNames\n ? Object.getOwnPropertyNames(window) : [];\n\nvar getWindowNames = function (it) {\n try {\n return $getOwnPropertyNames(it);\n } catch (error) {\n return arraySlice(windowNames);\n }\n};\n\n// fallback for IE11 buggy Object.getOwnPropertyNames with iframe and window\nmodule.exports.f = function getOwnPropertyNames(it) {\n return windowNames && classof(it) == 'Window'\n ? getWindowNames(it)\n : $getOwnPropertyNames(toIndexedObject(it));\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/internals/object-get-own-property-names-external.js\n// module id = 395\n// module chunks = 0 1","var toAbsoluteIndex = require('../internals/to-absolute-index');\nvar lengthOfArrayLike = require('../internals/length-of-array-like');\nvar createProperty = require('../internals/create-property');\n\nvar $Array = Array;\nvar max = Math.max;\n\nmodule.exports = function (O, start, end) {\n var length = lengthOfArrayLike(O);\n var k = toAbsoluteIndex(start, length);\n var fin = toAbsoluteIndex(end === undefined ? length : end, length);\n var result = $Array(max(fin - k, 0));\n for (var n = 0; k < fin; k++, n++) createProperty(result, n, O[k]);\n result.length = n;\n return result;\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/internals/array-slice-simple.js\n// module id = 396\n// module chunks = 0 1","var $ = require('../internals/export');\nvar getBuiltIn = require('../internals/get-built-in');\nvar hasOwn = require('../internals/has-own-property');\nvar toString = require('../internals/to-string');\nvar shared = require('../internals/shared');\nvar NATIVE_SYMBOL_REGISTRY = require('../internals/native-symbol-registry');\n\nvar StringToSymbolRegistry = shared('string-to-symbol-registry');\nvar SymbolToStringRegistry = shared('symbol-to-string-registry');\n\n// `Symbol.for` method\n// https://tc39.es/ecma262/#sec-symbol.for\n$({ target: 'Symbol', stat: true, forced: !NATIVE_SYMBOL_REGISTRY }, {\n 'for': function (key) {\n var string = toString(key);\n if (hasOwn(StringToSymbolRegistry, string)) return StringToSymbolRegistry[string];\n var symbol = getBuiltIn('Symbol')(string);\n StringToSymbolRegistry[string] = symbol;\n SymbolToStringRegistry[symbol] = string;\n return symbol;\n }\n});\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.symbol.for.js\n// module id = 397\n// module chunks = 0 1","var $ = require('../internals/export');\nvar hasOwn = require('../internals/has-own-property');\nvar isSymbol = require('../internals/is-symbol');\nvar tryToString = require('../internals/try-to-string');\nvar shared = require('../internals/shared');\nvar NATIVE_SYMBOL_REGISTRY = require('../internals/native-symbol-registry');\n\nvar SymbolToStringRegistry = shared('symbol-to-string-registry');\n\n// `Symbol.keyFor` method\n// https://tc39.es/ecma262/#sec-symbol.keyfor\n$({ target: 'Symbol', stat: true, forced: !NATIVE_SYMBOL_REGISTRY }, {\n keyFor: function keyFor(sym) {\n if (!isSymbol(sym)) throw TypeError(tryToString(sym) + ' is not a symbol');\n if (hasOwn(SymbolToStringRegistry, sym)) return SymbolToStringRegistry[sym];\n }\n});\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.symbol.key-for.js\n// module id = 398\n// module chunks = 0 1","var $ = require('../internals/export');\nvar NATIVE_SYMBOL = require('../internals/native-symbol');\nvar fails = require('../internals/fails');\nvar getOwnPropertySymbolsModule = require('../internals/object-get-own-property-symbols');\nvar toObject = require('../internals/to-object');\n\n// V8 ~ Chrome 38 and 39 `Object.getOwnPropertySymbols` fails on primitives\n// https://bugs.chromium.org/p/v8/issues/detail?id=3443\nvar FORCED = !NATIVE_SYMBOL || fails(function () { getOwnPropertySymbolsModule.f(1); });\n\n// `Object.getOwnPropertySymbols` method\n// https://tc39.es/ecma262/#sec-object.getownpropertysymbols\n$({ target: 'Object', stat: true, forced: FORCED }, {\n getOwnPropertySymbols: function getOwnPropertySymbols(it) {\n var $getOwnPropertySymbols = getOwnPropertySymbolsModule.f;\n return $getOwnPropertySymbols ? $getOwnPropertySymbols(toObject(it)) : [];\n }\n});\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.object.get-own-property-symbols.js\n// module id = 399\n// module chunks = 0 1","var defineWellKnownSymbol = require('../internals/define-well-known-symbol');\n\n// `Symbol.asyncIterator` well-known symbol\n// https://tc39.es/ecma262/#sec-symbol.asynciterator\ndefineWellKnownSymbol('asyncIterator');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.symbol.async-iterator.js\n// module id = 400\n// module chunks = 0 1","// empty\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.symbol.description.js\n// module id = 401\n// module chunks = 0 1","var defineWellKnownSymbol = require('../internals/define-well-known-symbol');\n\n// `Symbol.hasInstance` well-known symbol\n// https://tc39.es/ecma262/#sec-symbol.hasinstance\ndefineWellKnownSymbol('hasInstance');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.symbol.has-instance.js\n// module id = 402\n// module chunks = 0 1","var defineWellKnownSymbol = require('../internals/define-well-known-symbol');\n\n// `Symbol.isConcatSpreadable` well-known symbol\n// https://tc39.es/ecma262/#sec-symbol.isconcatspreadable\ndefineWellKnownSymbol('isConcatSpreadable');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.symbol.is-concat-spreadable.js\n// module id = 403\n// module chunks = 0 1","var defineWellKnownSymbol = require('../internals/define-well-known-symbol');\n\n// `Symbol.match` well-known symbol\n// https://tc39.es/ecma262/#sec-symbol.match\ndefineWellKnownSymbol('match');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.symbol.match.js\n// module id = 404\n// module chunks = 0 1","var defineWellKnownSymbol = require('../internals/define-well-known-symbol');\n\n// `Symbol.matchAll` well-known symbol\n// https://tc39.es/ecma262/#sec-symbol.matchall\ndefineWellKnownSymbol('matchAll');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.symbol.match-all.js\n// module id = 405\n// module chunks = 0 1","var defineWellKnownSymbol = require('../internals/define-well-known-symbol');\n\n// `Symbol.replace` well-known symbol\n// https://tc39.es/ecma262/#sec-symbol.replace\ndefineWellKnownSymbol('replace');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.symbol.replace.js\n// module id = 406\n// module chunks = 0 1","var defineWellKnownSymbol = require('../internals/define-well-known-symbol');\n\n// `Symbol.search` well-known symbol\n// https://tc39.es/ecma262/#sec-symbol.search\ndefineWellKnownSymbol('search');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.symbol.search.js\n// module id = 407\n// module chunks = 0 1","var defineWellKnownSymbol = require('../internals/define-well-known-symbol');\n\n// `Symbol.species` well-known symbol\n// https://tc39.es/ecma262/#sec-symbol.species\ndefineWellKnownSymbol('species');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.symbol.species.js\n// module id = 408\n// module chunks = 0 1","var defineWellKnownSymbol = require('../internals/define-well-known-symbol');\n\n// `Symbol.split` well-known symbol\n// https://tc39.es/ecma262/#sec-symbol.split\ndefineWellKnownSymbol('split');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.symbol.split.js\n// module id = 409\n// module chunks = 0 1","var defineWellKnownSymbol = require('../internals/define-well-known-symbol');\nvar defineSymbolToPrimitive = require('../internals/symbol-define-to-primitive');\n\n// `Symbol.toPrimitive` well-known symbol\n// https://tc39.es/ecma262/#sec-symbol.toprimitive\ndefineWellKnownSymbol('toPrimitive');\n\n// `Symbol.prototype[@@toPrimitive]` method\n// https://tc39.es/ecma262/#sec-symbol.prototype-@@toprimitive\ndefineSymbolToPrimitive();\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.symbol.to-primitive.js\n// module id = 410\n// module chunks = 0 1","var getBuiltIn = require('../internals/get-built-in');\nvar defineWellKnownSymbol = require('../internals/define-well-known-symbol');\nvar setToStringTag = require('../internals/set-to-string-tag');\n\n// `Symbol.toStringTag` well-known symbol\n// https://tc39.es/ecma262/#sec-symbol.tostringtag\ndefineWellKnownSymbol('toStringTag');\n\n// `Symbol.prototype[@@toStringTag]` property\n// https://tc39.es/ecma262/#sec-symbol.prototype-@@tostringtag\nsetToStringTag(getBuiltIn('Symbol'), 'Symbol');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.symbol.to-string-tag.js\n// module id = 411\n// module chunks = 0 1","var defineWellKnownSymbol = require('../internals/define-well-known-symbol');\n\n// `Symbol.unscopables` well-known symbol\n// https://tc39.es/ecma262/#sec-symbol.unscopables\ndefineWellKnownSymbol('unscopables');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.symbol.unscopables.js\n// module id = 412\n// module chunks = 0 1","var global = require('../internals/global');\nvar setToStringTag = require('../internals/set-to-string-tag');\n\n// JSON[@@toStringTag] property\n// https://tc39.es/ecma262/#sec-json-@@tostringtag\nsetToStringTag(global.JSON, 'JSON', true);\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.json.to-string-tag.js\n// module id = 413\n// module chunks = 0 1","// empty\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.math.to-string-tag.js\n// module id = 414\n// module chunks = 0 1","// empty\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.reflect.to-string-tag.js\n// module id = 415\n// module chunks = 0 1","var defineWellKnownSymbol = require('../internals/define-well-known-symbol');\n\n// `Symbol.asyncDispose` well-known symbol\n// https://github.com/tc39/proposal-using-statement\ndefineWellKnownSymbol('asyncDispose');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/esnext.symbol.async-dispose.js\n// module id = 416\n// module chunks = 0 1","var defineWellKnownSymbol = require('../internals/define-well-known-symbol');\n\n// `Symbol.dispose` well-known symbol\n// https://github.com/tc39/proposal-using-statement\ndefineWellKnownSymbol('dispose');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/esnext.symbol.dispose.js\n// module id = 417\n// module chunks = 0 1","var defineWellKnownSymbol = require('../internals/define-well-known-symbol');\n\n// `Symbol.matcher` well-known symbol\n// https://github.com/tc39/proposal-pattern-matching\ndefineWellKnownSymbol('matcher');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/esnext.symbol.matcher.js\n// module id = 418\n// module chunks = 0 1","var defineWellKnownSymbol = require('../internals/define-well-known-symbol');\n\n// `Symbol.metadataKey` well-known symbol\n// https://github.com/tc39/proposal-decorator-metadata\ndefineWellKnownSymbol('metadataKey');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/esnext.symbol.metadata-key.js\n// module id = 419\n// module chunks = 0 1","var defineWellKnownSymbol = require('../internals/define-well-known-symbol');\n\n// `Symbol.observable` well-known symbol\n// https://github.com/tc39/proposal-observable\ndefineWellKnownSymbol('observable');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/esnext.symbol.observable.js\n// module id = 420\n// module chunks = 0 1","// TODO: Remove from `core-js@4`\nvar defineWellKnownSymbol = require('../internals/define-well-known-symbol');\n\n// `Symbol.metadata` well-known symbol\n// https://github.com/tc39/proposal-decorators\ndefineWellKnownSymbol('metadata');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/esnext.symbol.metadata.js\n// module id = 421\n// module chunks = 0 1","// TODO: remove from `core-js@4`\nvar defineWellKnownSymbol = require('../internals/define-well-known-symbol');\n\n// `Symbol.patternMatch` well-known symbol\n// https://github.com/tc39/proposal-pattern-matching\ndefineWellKnownSymbol('patternMatch');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/esnext.symbol.pattern-match.js\n// module id = 422\n// module chunks = 0 1","// TODO: remove from `core-js@4`\nvar defineWellKnownSymbol = require('../internals/define-well-known-symbol');\n\ndefineWellKnownSymbol('replaceAll');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/esnext.symbol.replace-all.js\n// module id = 423\n// module chunks = 0 1","module.exports = require(\"core-js-pure/features/symbol/iterator\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/core-js/symbol/iterator.js\n// module id = 424\n// module chunks = 0 1","module.exports = require('../../full/symbol/iterator');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/features/symbol/iterator.js\n// module id = 425\n// module chunks = 0 1","var parent = require('../../actual/symbol/iterator');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/full/symbol/iterator.js\n// module id = 426\n// module chunks = 0 1","var parent = require('../../stable/symbol/iterator');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/actual/symbol/iterator.js\n// module id = 427\n// module chunks = 0 1","var parent = require('../../es/symbol/iterator');\nrequire('../../modules/web.dom-collections.iterator');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/stable/symbol/iterator.js\n// module id = 428\n// module chunks = 0 1","require('../../modules/es.array.iterator');\nrequire('../../modules/es.object.to-string');\nrequire('../../modules/es.string.iterator');\nrequire('../../modules/es.symbol.iterator');\nvar WrappedWellKnownSymbolModule = require('../../internals/well-known-symbol-wrapped');\n\nmodule.exports = WrappedWellKnownSymbolModule.f('iterator');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/es/symbol/iterator.js\n// module id = 429\n// module chunks = 0 1","module.exports = require(\"core-js-pure/stable/instance/filter\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/core-js-stable/instance/filter.js\n// module id = 430\n// module chunks = 0 1","var parent = require('../../es/instance/filter');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/stable/instance/filter.js\n// module id = 431\n// module chunks = 0 1","var isPrototypeOf = require('../../internals/object-is-prototype-of');\nvar method = require('../array/virtual/filter');\n\nvar ArrayPrototype = Array.prototype;\n\nmodule.exports = function (it) {\n var own = it.filter;\n return it === ArrayPrototype || (isPrototypeOf(ArrayPrototype, it) && own === ArrayPrototype.filter) ? method : own;\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/es/instance/filter.js\n// module id = 432\n// module chunks = 0 1","require('../../../modules/es.array.filter');\nvar entryVirtual = require('../../../internals/entry-virtual');\n\nmodule.exports = entryVirtual('Array').filter;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/es/array/virtual/filter.js\n// module id = 433\n// module chunks = 0 1","'use strict';\nvar $ = require('../internals/export');\nvar $filter = require('../internals/array-iteration').filter;\nvar arrayMethodHasSpeciesSupport = require('../internals/array-method-has-species-support');\n\nvar HAS_SPECIES_SUPPORT = arrayMethodHasSpeciesSupport('filter');\n\n// `Array.prototype.filter` method\n// https://tc39.es/ecma262/#sec-array.prototype.filter\n// with adding support of @@species\n$({ target: 'Array', proto: true, forced: !HAS_SPECIES_SUPPORT }, {\n filter: function filter(callbackfn /* , thisArg */) {\n return $filter(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);\n }\n});\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.array.filter.js\n// module id = 434\n// module chunks = 0 1","// Copyright (c) 2015-2017 David M. Lee, II\n'use strict';\n\n/**\n * Local reference to TimeoutError\n * @private\n */\nvar TimeoutError;\n\n/**\n * Rejects a promise with a {@link TimeoutError} if it does not settle within\n * the specified timeout.\n *\n * @param {Promise} promise The promise.\n * @param {number} timeoutMillis Number of milliseconds to wait on settling.\n * @returns {Promise} Either resolves/rejects with `promise`, or rejects with\n * `TimeoutError`, whichever settles first.\n */\nvar timeout = module.exports.timeout = function(promise, timeoutMillis) {\n var error = new TimeoutError(),\n timeout;\n\n return Promise.race([\n promise,\n new Promise(function(resolve, reject) {\n timeout = setTimeout(function() {\n reject(error);\n }, timeoutMillis);\n }),\n ]).then(function(v) {\n clearTimeout(timeout);\n return v;\n }, function(err) {\n clearTimeout(timeout);\n throw err;\n });\n};\n\n/**\n * Exception indicating that the timeout expired.\n */\nTimeoutError = module.exports.TimeoutError = function() {\n Error.call(this)\n this.stack = Error().stack\n this.message = 'Timeout';\n};\n\nTimeoutError.prototype = Object.create(Error.prototype);\nTimeoutError.prototype.name = \"TimeoutError\";\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/promise-timeout/index.js\n// module id = 435\n// module chunks = 0 1","var _ = require('underscore');\n\nmodule.exports = function(AV) {\n var eventSplitter = /\\s+/;\n var slice = Array.prototype.slice;\n\n /**\n * @class\n *\n *
AV.Events is a fork of Backbone's Events module, provided for your\n * convenience.
\n *\n *
A module that can be mixed in to any object in order to provide\n * it with custom events. You may bind callback functions to an event\n * with `on`, or remove these functions with `off`.\n * Triggering an event fires all callbacks in the order that `on` was\n * called.\n *\n * @private\n * @example\n * var object = {};\n * _.extend(object, AV.Events);\n * object.on('expand', function(){ alert('expanded'); });\n * object.trigger('expand');
\n *\n */\n AV.Events = {\n /**\n * Bind one or more space separated events, `events`, to a `callback`\n * function. Passing `\"all\"` will bind the callback to all events fired.\n */\n on: function(events, callback, context) {\n var calls, event, node, tail, list;\n if (!callback) {\n return this;\n }\n events = events.split(eventSplitter);\n calls = this._callbacks || (this._callbacks = {});\n\n // Create an immutable callback list, allowing traversal during\n // modification. The tail is an empty object that will always be used\n // as the next node.\n event = events.shift();\n while (event) {\n list = calls[event];\n node = list ? list.tail : {};\n node.next = tail = {};\n node.context = context;\n node.callback = callback;\n calls[event] = { tail: tail, next: list ? list.next : node };\n event = events.shift();\n }\n\n return this;\n },\n\n /**\n * Remove one or many callbacks. If `context` is null, removes all callbacks\n * with that function. If `callback` is null, removes all callbacks for the\n * event. If `events` is null, removes all bound callbacks for all events.\n */\n off: function(events, callback, context) {\n var event, calls, node, tail, cb, ctx;\n\n // No events, or removing *all* events.\n if (!(calls = this._callbacks)) {\n return;\n }\n if (!(events || callback || context)) {\n delete this._callbacks;\n return this;\n }\n\n // Loop through the listed events and contexts, splicing them out of the\n // linked list of callbacks if appropriate.\n events = events ? events.split(eventSplitter) : _.keys(calls);\n event = events.shift();\n while (event) {\n node = calls[event];\n delete calls[event];\n if (!node || !(callback || context)) {\n continue;\n }\n // Create a new list, omitting the indicated callbacks.\n tail = node.tail;\n node = node.next;\n while (node !== tail) {\n cb = node.callback;\n ctx = node.context;\n if ((callback && cb !== callback) || (context && ctx !== context)) {\n this.on(event, cb, ctx);\n }\n node = node.next;\n }\n event = events.shift();\n }\n\n return this;\n },\n\n /**\n * Trigger one or many events, firing all bound callbacks. Callbacks are\n * passed the same arguments as `trigger` is, apart from the event name\n * (unless you're listening on `\"all\"`, which will cause your callback to\n * receive the true name of the event as the first argument).\n */\n trigger: function(events) {\n var event, node, calls, tail, args, all, rest;\n if (!(calls = this._callbacks)) {\n return this;\n }\n all = calls.all;\n events = events.split(eventSplitter);\n rest = slice.call(arguments, 1);\n\n // For each event, walk through the linked list of callbacks twice,\n // first to trigger the event, then to trigger any `\"all\"` callbacks.\n event = events.shift();\n while (event) {\n node = calls[event];\n if (node) {\n tail = node.tail;\n while ((node = node.next) !== tail) {\n node.callback.apply(node.context || this, rest);\n }\n }\n node = all;\n if (node) {\n tail = node.tail;\n args = [event].concat(rest);\n while ((node = node.next) !== tail) {\n node.callback.apply(node.context || this, args);\n }\n }\n event = events.shift();\n }\n\n return this;\n },\n };\n\n /**\n * @function\n */\n AV.Events.bind = AV.Events.on;\n\n /**\n * @function\n */\n AV.Events.unbind = AV.Events.off;\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/event.js","var _ = require('underscore');\n\n/*global navigator: false */\nmodule.exports = function(AV) {\n /**\n * Creates a new GeoPoint with any of the following forms: \n * @example\n * new GeoPoint(otherGeoPoint)\n * new GeoPoint(30, 30)\n * new GeoPoint([30, 30])\n * new GeoPoint({latitude: 30, longitude: 30})\n * new GeoPoint() // defaults to (0, 0)\n * @class\n *\n *
Represents a latitude / longitude point that may be associated\n * with a key in a AVObject or used as a reference point for geo queries.\n * This allows proximity-based queries on the key.
\n *\n *
Only one key in a class may contain a GeoPoint.
\n *\n *
Example:
\n * var point = new AV.GeoPoint(30.0, -20.0);\n * var object = new AV.Object(\"PlaceObject\");\n * object.set(\"location\", point);\n * object.save();
\n */\n AV.GeoPoint = function(arg1, arg2) {\n if (_.isArray(arg1)) {\n AV.GeoPoint._validate(arg1[0], arg1[1]);\n this.latitude = arg1[0];\n this.longitude = arg1[1];\n } else if (_.isObject(arg1)) {\n AV.GeoPoint._validate(arg1.latitude, arg1.longitude);\n this.latitude = arg1.latitude;\n this.longitude = arg1.longitude;\n } else if (_.isNumber(arg1) && _.isNumber(arg2)) {\n AV.GeoPoint._validate(arg1, arg2);\n this.latitude = arg1;\n this.longitude = arg2;\n } else {\n this.latitude = 0;\n this.longitude = 0;\n }\n\n // Add properties so that anyone using Webkit or Mozilla will get an error\n // if they try to set values that are out of bounds.\n var self = this;\n if (this.__defineGetter__ && this.__defineSetter__) {\n // Use _latitude and _longitude to actually store the values, and add\n // getters and setters for latitude and longitude.\n this._latitude = this.latitude;\n this._longitude = this.longitude;\n this.__defineGetter__('latitude', function() {\n return self._latitude;\n });\n this.__defineGetter__('longitude', function() {\n return self._longitude;\n });\n this.__defineSetter__('latitude', function(val) {\n AV.GeoPoint._validate(val, self.longitude);\n self._latitude = val;\n });\n this.__defineSetter__('longitude', function(val) {\n AV.GeoPoint._validate(self.latitude, val);\n self._longitude = val;\n });\n }\n };\n\n /**\n * @lends AV.GeoPoint.prototype\n * @property {float} latitude North-south portion of the coordinate, in range\n * [-90, 90]. Throws an exception if set out of range in a modern browser.\n * @property {float} longitude East-west portion of the coordinate, in range\n * [-180, 180]. Throws if set out of range in a modern browser.\n */\n\n /**\n * Throws an exception if the given lat-long is out of bounds.\n * @private\n */\n AV.GeoPoint._validate = function(latitude, longitude) {\n if (latitude < -90.0) {\n throw new Error('AV.GeoPoint latitude ' + latitude + ' < -90.0.');\n }\n if (latitude > 90.0) {\n throw new Error('AV.GeoPoint latitude ' + latitude + ' > 90.0.');\n }\n if (longitude < -180.0) {\n throw new Error('AV.GeoPoint longitude ' + longitude + ' < -180.0.');\n }\n if (longitude > 180.0) {\n throw new Error('AV.GeoPoint longitude ' + longitude + ' > 180.0.');\n }\n };\n\n /**\n * Creates a GeoPoint with the user's current location, if available.\n * @return {Promise.}\n */\n AV.GeoPoint.current = () =>\n new Promise((resolve, reject) => {\n navigator.geolocation.getCurrentPosition(function(location) {\n resolve(\n new AV.GeoPoint({\n latitude: location.coords.latitude,\n longitude: location.coords.longitude,\n })\n );\n }, reject);\n });\n\n _.extend(\n AV.GeoPoint.prototype,\n /** @lends AV.GeoPoint.prototype */ {\n /**\n * Returns a JSON representation of the GeoPoint, suitable for AV.\n * @return {Object}\n */\n toJSON: function() {\n AV.GeoPoint._validate(this.latitude, this.longitude);\n return {\n __type: 'GeoPoint',\n latitude: this.latitude,\n longitude: this.longitude,\n };\n },\n\n /**\n * Returns the distance from this GeoPoint to another in radians.\n * @param {AV.GeoPoint} point the other AV.GeoPoint.\n * @return {Number}\n */\n radiansTo: function(point) {\n var d2r = Math.PI / 180.0;\n var lat1rad = this.latitude * d2r;\n var long1rad = this.longitude * d2r;\n var lat2rad = point.latitude * d2r;\n var long2rad = point.longitude * d2r;\n var deltaLat = lat1rad - lat2rad;\n var deltaLong = long1rad - long2rad;\n var sinDeltaLatDiv2 = Math.sin(deltaLat / 2);\n var sinDeltaLongDiv2 = Math.sin(deltaLong / 2);\n // Square of half the straight line chord distance between both points.\n var a =\n sinDeltaLatDiv2 * sinDeltaLatDiv2 +\n Math.cos(lat1rad) *\n Math.cos(lat2rad) *\n sinDeltaLongDiv2 *\n sinDeltaLongDiv2;\n a = Math.min(1.0, a);\n return 2 * Math.asin(Math.sqrt(a));\n },\n\n /**\n * Returns the distance from this GeoPoint to another in kilometers.\n * @param {AV.GeoPoint} point the other AV.GeoPoint.\n * @return {Number}\n */\n kilometersTo: function(point) {\n return this.radiansTo(point) * 6371.0;\n },\n\n /**\n * Returns the distance from this GeoPoint to another in miles.\n * @param {AV.GeoPoint} point the other AV.GeoPoint.\n * @return {Number}\n */\n milesTo: function(point) {\n return this.radiansTo(point) * 3958.8;\n },\n }\n );\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/geopoint.js","var _ = require('underscore');\n\nmodule.exports = function(AV) {\n var PUBLIC_KEY = '*';\n\n /**\n * Creates a new ACL.\n * If no argument is given, the ACL has no permissions for anyone.\n * If the argument is a AV.User, the ACL will have read and write\n * permission for only that user.\n * If the argument is any other JSON object, that object will be interpretted\n * as a serialized ACL created with toJSON().\n * @see AV.Object#setACL\n * @class\n *\n *
An ACL, or Access Control List can be added to any\n * AV.Object to restrict access to only a subset of users\n * of your application.
\n */\n AV.ACL = function(arg1) {\n var self = this;\n self.permissionsById = {};\n if (_.isObject(arg1)) {\n if (arg1 instanceof AV.User) {\n self.setReadAccess(arg1, true);\n self.setWriteAccess(arg1, true);\n } else {\n if (_.isFunction(arg1)) {\n throw new Error(\n 'AV.ACL() called with a function. Did you forget ()?'\n );\n }\n AV._objectEach(arg1, function(accessList, userId) {\n if (!_.isString(userId)) {\n throw new Error('Tried to create an ACL with an invalid userId.');\n }\n self.permissionsById[userId] = {};\n AV._objectEach(accessList, function(allowed, permission) {\n if (permission !== 'read' && permission !== 'write') {\n throw new Error(\n 'Tried to create an ACL with an invalid permission type.'\n );\n }\n if (!_.isBoolean(allowed)) {\n throw new Error(\n 'Tried to create an ACL with an invalid permission value.'\n );\n }\n self.permissionsById[userId][permission] = allowed;\n });\n });\n }\n }\n };\n\n /**\n * Returns a JSON-encoded version of the ACL.\n * @return {Object}\n */\n AV.ACL.prototype.toJSON = function() {\n return _.clone(this.permissionsById);\n };\n\n AV.ACL.prototype._setAccess = function(accessType, userId, allowed) {\n if (userId instanceof AV.User) {\n userId = userId.id;\n } else if (userId instanceof AV.Role) {\n userId = 'role:' + userId.getName();\n }\n if (!_.isString(userId)) {\n throw new Error('userId must be a string.');\n }\n if (!_.isBoolean(allowed)) {\n throw new Error('allowed must be either true or false.');\n }\n var permissions = this.permissionsById[userId];\n if (!permissions) {\n if (!allowed) {\n // The user already doesn't have this permission, so no action needed.\n return;\n } else {\n permissions = {};\n this.permissionsById[userId] = permissions;\n }\n }\n\n if (allowed) {\n this.permissionsById[userId][accessType] = true;\n } else {\n delete permissions[accessType];\n if (_.isEmpty(permissions)) {\n delete this.permissionsById[userId];\n }\n }\n };\n\n AV.ACL.prototype._getAccess = function(accessType, userId) {\n if (userId instanceof AV.User) {\n userId = userId.id;\n } else if (userId instanceof AV.Role) {\n userId = 'role:' + userId.getName();\n }\n var permissions = this.permissionsById[userId];\n if (!permissions) {\n return false;\n }\n return permissions[accessType] ? true : false;\n };\n\n /**\n * Set whether the given user is allowed to read this object.\n * @param userId An instance of AV.User or its objectId.\n * @param {Boolean} allowed Whether that user should have read access.\n */\n AV.ACL.prototype.setReadAccess = function(userId, allowed) {\n this._setAccess('read', userId, allowed);\n };\n\n /**\n * Get whether the given user id is *explicitly* allowed to read this object.\n * Even if this returns false, the user may still be able to access it if\n * getPublicReadAccess returns true or a role that the user belongs to has\n * write access.\n * @param userId An instance of AV.User or its objectId, or a AV.Role.\n * @return {Boolean}\n */\n AV.ACL.prototype.getReadAccess = function(userId) {\n return this._getAccess('read', userId);\n };\n\n /**\n * Set whether the given user id is allowed to write this object.\n * @param userId An instance of AV.User or its objectId, or a AV.Role..\n * @param {Boolean} allowed Whether that user should have write access.\n */\n AV.ACL.prototype.setWriteAccess = function(userId, allowed) {\n this._setAccess('write', userId, allowed);\n };\n\n /**\n * Get whether the given user id is *explicitly* allowed to write this object.\n * Even if this returns false, the user may still be able to write it if\n * getPublicWriteAccess returns true or a role that the user belongs to has\n * write access.\n * @param userId An instance of AV.User or its objectId, or a AV.Role.\n * @return {Boolean}\n */\n AV.ACL.prototype.getWriteAccess = function(userId) {\n return this._getAccess('write', userId);\n };\n\n /**\n * Set whether the public is allowed to read this object.\n * @param {Boolean} allowed\n */\n AV.ACL.prototype.setPublicReadAccess = function(allowed) {\n this.setReadAccess(PUBLIC_KEY, allowed);\n };\n\n /**\n * Get whether the public is allowed to read this object.\n * @return {Boolean}\n */\n AV.ACL.prototype.getPublicReadAccess = function() {\n return this.getReadAccess(PUBLIC_KEY);\n };\n\n /**\n * Set whether the public is allowed to write this object.\n * @param {Boolean} allowed\n */\n AV.ACL.prototype.setPublicWriteAccess = function(allowed) {\n this.setWriteAccess(PUBLIC_KEY, allowed);\n };\n\n /**\n * Get whether the public is allowed to write this object.\n * @return {Boolean}\n */\n AV.ACL.prototype.getPublicWriteAccess = function() {\n return this.getWriteAccess(PUBLIC_KEY);\n };\n\n /**\n * Get whether users belonging to the given role are allowed\n * to read this object. Even if this returns false, the role may\n * still be able to write it if a parent role has read access.\n *\n * @param role The name of the role, or a AV.Role object.\n * @return {Boolean} true if the role has read access. false otherwise.\n * @throws {String} If role is neither a AV.Role nor a String.\n */\n AV.ACL.prototype.getRoleReadAccess = function(role) {\n if (role instanceof AV.Role) {\n // Normalize to the String name\n role = role.getName();\n }\n if (_.isString(role)) {\n return this.getReadAccess('role:' + role);\n }\n throw new Error('role must be a AV.Role or a String');\n };\n\n /**\n * Get whether users belonging to the given role are allowed\n * to write this object. Even if this returns false, the role may\n * still be able to write it if a parent role has write access.\n *\n * @param role The name of the role, or a AV.Role object.\n * @return {Boolean} true if the role has write access. false otherwise.\n * @throws {String} If role is neither a AV.Role nor a String.\n */\n AV.ACL.prototype.getRoleWriteAccess = function(role) {\n if (role instanceof AV.Role) {\n // Normalize to the String name\n role = role.getName();\n }\n if (_.isString(role)) {\n return this.getWriteAccess('role:' + role);\n }\n throw new Error('role must be a AV.Role or a String');\n };\n\n /**\n * Set whether users belonging to the given role are allowed\n * to read this object.\n *\n * @param role The name of the role, or a AV.Role object.\n * @param {Boolean} allowed Whether the given role can read this object.\n * @throws {String} If role is neither a AV.Role nor a String.\n */\n AV.ACL.prototype.setRoleReadAccess = function(role, allowed) {\n if (role instanceof AV.Role) {\n // Normalize to the String name\n role = role.getName();\n }\n if (_.isString(role)) {\n this.setReadAccess('role:' + role, allowed);\n return;\n }\n throw new Error('role must be a AV.Role or a String');\n };\n\n /**\n * Set whether users belonging to the given role are allowed\n * to write this object.\n *\n * @param role The name of the role, or a AV.Role object.\n * @param {Boolean} allowed Whether the given role can write this object.\n * @throws {String} If role is neither a AV.Role nor a String.\n */\n AV.ACL.prototype.setRoleWriteAccess = function(role, allowed) {\n if (role instanceof AV.Role) {\n // Normalize to the String name\n role = role.getName();\n }\n if (_.isString(role)) {\n this.setWriteAccess('role:' + role, allowed);\n return;\n }\n throw new Error('role must be a AV.Role or a String');\n };\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/acl.js","var _ = require('underscore');\n\nmodule.exports = function(AV) {\n /**\n * @private\n * @class\n * A AV.Op is an atomic operation that can be applied to a field in a\n * AV.Object. For example, calling object.set(\"foo\", \"bar\")\n * is an example of a AV.Op.Set. Calling object.unset(\"foo\")\n * is a AV.Op.Unset. These operations are stored in a AV.Object and\n * sent to the server as part of object.save() operations.\n * Instances of AV.Op should be immutable.\n *\n * You should not create subclasses of AV.Op or instantiate AV.Op\n * directly.\n */\n AV.Op = function() {\n this._initialize.apply(this, arguments);\n };\n\n _.extend(\n AV.Op.prototype,\n /** @lends AV.Op.prototype */ {\n _initialize: function() {},\n }\n );\n\n _.extend(AV.Op, {\n /**\n * To create a new Op, call AV.Op._extend();\n * @private\n */\n _extend: AV._extend,\n\n // A map of __op string to decoder function.\n _opDecoderMap: {},\n\n /**\n * Registers a function to convert a json object with an __op field into an\n * instance of a subclass of AV.Op.\n * @private\n */\n _registerDecoder: function(opName, decoder) {\n AV.Op._opDecoderMap[opName] = decoder;\n },\n\n /**\n * Converts a json object into an instance of a subclass of AV.Op.\n * @private\n */\n _decode: function(json) {\n var decoder = AV.Op._opDecoderMap[json.__op];\n if (decoder) {\n return decoder(json);\n } else {\n return undefined;\n }\n },\n });\n\n /*\n * Add a handler for Batch ops.\n */\n AV.Op._registerDecoder('Batch', function(json) {\n var op = null;\n AV._arrayEach(json.ops, function(nextOp) {\n nextOp = AV.Op._decode(nextOp);\n op = nextOp._mergeWithPrevious(op);\n });\n return op;\n });\n\n /**\n * @private\n * @class\n * A Set operation indicates that either the field was changed using\n * AV.Object.set, or it is a mutable container that was detected as being\n * changed.\n */\n AV.Op.Set = AV.Op._extend(\n /** @lends AV.Op.Set.prototype */ {\n _initialize: function(value) {\n this._value = value;\n },\n\n /**\n * Returns the new value of this field after the set.\n */\n value: function() {\n return this._value;\n },\n\n /**\n * Returns a JSON version of the operation suitable for sending to AV.\n * @return {Object}\n */\n toJSON: function() {\n return AV._encode(this.value());\n },\n\n _mergeWithPrevious: function(previous) {\n return this;\n },\n\n _estimate: function(oldValue) {\n return this.value();\n },\n }\n );\n\n /**\n * A sentinel value that is returned by AV.Op.Unset._estimate to\n * indicate the field should be deleted. Basically, if you find _UNSET as a\n * value in your object, you should remove that key.\n */\n AV.Op._UNSET = {};\n\n /**\n * @private\n * @class\n * An Unset operation indicates that this field has been deleted from the\n * object.\n */\n AV.Op.Unset = AV.Op._extend(\n /** @lends AV.Op.Unset.prototype */ {\n /**\n * Returns a JSON version of the operation suitable for sending to AV.\n * @return {Object}\n */\n toJSON: function() {\n return { __op: 'Delete' };\n },\n\n _mergeWithPrevious: function(previous) {\n return this;\n },\n\n _estimate: function(oldValue) {\n return AV.Op._UNSET;\n },\n }\n );\n\n AV.Op._registerDecoder('Delete', function(json) {\n return new AV.Op.Unset();\n });\n\n /**\n * @private\n * @class\n * An Increment is an atomic operation where the numeric value for the field\n * will be increased by a given amount.\n */\n AV.Op.Increment = AV.Op._extend(\n /** @lends AV.Op.Increment.prototype */ {\n _initialize: function(amount) {\n this._amount = amount;\n },\n\n /**\n * Returns the amount to increment by.\n * @return {Number} the amount to increment by.\n */\n amount: function() {\n return this._amount;\n },\n\n /**\n * Returns a JSON version of the operation suitable for sending to AV.\n * @return {Object}\n */\n toJSON: function() {\n return { __op: 'Increment', amount: this._amount };\n },\n\n _mergeWithPrevious: function(previous) {\n if (!previous) {\n return this;\n } else if (previous instanceof AV.Op.Unset) {\n return new AV.Op.Set(this.amount());\n } else if (previous instanceof AV.Op.Set) {\n return new AV.Op.Set(previous.value() + this.amount());\n } else if (previous instanceof AV.Op.Increment) {\n return new AV.Op.Increment(this.amount() + previous.amount());\n } else {\n throw new Error('Op is invalid after previous op.');\n }\n },\n\n _estimate: function(oldValue) {\n if (!oldValue) {\n return this.amount();\n }\n return oldValue + this.amount();\n },\n }\n );\n\n AV.Op._registerDecoder('Increment', function(json) {\n return new AV.Op.Increment(json.amount);\n });\n\n /**\n * @private\n * @class\n * BitAnd is an atomic operation where the given value will be bit and to the\n * value than is stored in this field.\n */\n AV.Op.BitAnd = AV.Op._extend(\n /** @lends AV.Op.BitAnd.prototype */ {\n _initialize(value) {\n this._value = value;\n },\n\n value() {\n return this._value;\n },\n\n /**\n * Returns a JSON version of the operation suitable for sending to AV.\n * @return {Object}\n */\n toJSON() {\n return { __op: 'BitAnd', value: this.value() };\n },\n\n _mergeWithPrevious(previous) {\n if (!previous) {\n return this;\n } else if (previous instanceof AV.Op.Unset) {\n return new AV.Op.Set(0);\n } else if (previous instanceof AV.Op.Set) {\n return new AV.Op.Set(previous.value() & this.value());\n } else {\n throw new Error('Op is invalid after previous op.');\n }\n },\n\n _estimate(oldValue) {\n return oldValue & this.value();\n },\n }\n );\n\n AV.Op._registerDecoder('BitAnd', function(json) {\n return new AV.Op.BitAnd(json.value);\n });\n\n /**\n * @private\n * @class\n * BitOr is an atomic operation where the given value will be bit and to the\n * value than is stored in this field.\n */\n AV.Op.BitOr = AV.Op._extend(\n /** @lends AV.Op.BitOr.prototype */ {\n _initialize(value) {\n this._value = value;\n },\n\n value() {\n return this._value;\n },\n\n /**\n * Returns a JSON version of the operation suitable for sending to AV.\n * @return {Object}\n */\n toJSON() {\n return { __op: 'BitOr', value: this.value() };\n },\n\n _mergeWithPrevious(previous) {\n if (!previous) {\n return this;\n } else if (previous instanceof AV.Op.Unset) {\n return new AV.Op.Set(this.value());\n } else if (previous instanceof AV.Op.Set) {\n return new AV.Op.Set(previous.value() | this.value());\n } else {\n throw new Error('Op is invalid after previous op.');\n }\n },\n\n _estimate(oldValue) {\n return oldValue | this.value();\n },\n }\n );\n\n AV.Op._registerDecoder('BitOr', function(json) {\n return new AV.Op.BitOr(json.value);\n });\n\n /**\n * @private\n * @class\n * BitXor is an atomic operation where the given value will be bit and to the\n * value than is stored in this field.\n */\n AV.Op.BitXor = AV.Op._extend(\n /** @lends AV.Op.BitXor.prototype */ {\n _initialize(value) {\n this._value = value;\n },\n\n value() {\n return this._value;\n },\n\n /**\n * Returns a JSON version of the operation suitable for sending to AV.\n * @return {Object}\n */\n toJSON() {\n return { __op: 'BitXor', value: this.value() };\n },\n\n _mergeWithPrevious(previous) {\n if (!previous) {\n return this;\n } else if (previous instanceof AV.Op.Unset) {\n return new AV.Op.Set(this.value());\n } else if (previous instanceof AV.Op.Set) {\n return new AV.Op.Set(previous.value() ^ this.value());\n } else {\n throw new Error('Op is invalid after previous op.');\n }\n },\n\n _estimate(oldValue) {\n return oldValue ^ this.value();\n },\n }\n );\n\n AV.Op._registerDecoder('BitXor', function(json) {\n return new AV.Op.BitXor(json.value);\n });\n\n /**\n * @private\n * @class\n * Add is an atomic operation where the given objects will be appended to the\n * array that is stored in this field.\n */\n AV.Op.Add = AV.Op._extend(\n /** @lends AV.Op.Add.prototype */ {\n _initialize: function(objects) {\n this._objects = objects;\n },\n\n /**\n * Returns the objects to be added to the array.\n * @return {Array} The objects to be added to the array.\n */\n objects: function() {\n return this._objects;\n },\n\n /**\n * Returns a JSON version of the operation suitable for sending to AV.\n * @return {Object}\n */\n toJSON: function() {\n return { __op: 'Add', objects: AV._encode(this.objects()) };\n },\n\n _mergeWithPrevious: function(previous) {\n if (!previous) {\n return this;\n } else if (previous instanceof AV.Op.Unset) {\n return new AV.Op.Set(this.objects());\n } else if (previous instanceof AV.Op.Set) {\n return new AV.Op.Set(this._estimate(previous.value()));\n } else if (previous instanceof AV.Op.Add) {\n return new AV.Op.Add(previous.objects().concat(this.objects()));\n } else {\n throw new Error('Op is invalid after previous op.');\n }\n },\n\n _estimate: function(oldValue) {\n if (!oldValue) {\n return _.clone(this.objects());\n } else {\n return oldValue.concat(this.objects());\n }\n },\n }\n );\n\n AV.Op._registerDecoder('Add', function(json) {\n return new AV.Op.Add(AV._decode(json.objects));\n });\n\n /**\n * @private\n * @class\n * AddUnique is an atomic operation where the given items will be appended to\n * the array that is stored in this field only if they were not already\n * present in the array.\n */\n AV.Op.AddUnique = AV.Op._extend(\n /** @lends AV.Op.AddUnique.prototype */ {\n _initialize: function(objects) {\n this._objects = _.uniq(objects);\n },\n\n /**\n * Returns the objects to be added to the array.\n * @return {Array} The objects to be added to the array.\n */\n objects: function() {\n return this._objects;\n },\n\n /**\n * Returns a JSON version of the operation suitable for sending to AV.\n * @return {Object}\n */\n toJSON: function() {\n return { __op: 'AddUnique', objects: AV._encode(this.objects()) };\n },\n\n _mergeWithPrevious: function(previous) {\n if (!previous) {\n return this;\n } else if (previous instanceof AV.Op.Unset) {\n return new AV.Op.Set(this.objects());\n } else if (previous instanceof AV.Op.Set) {\n return new AV.Op.Set(this._estimate(previous.value()));\n } else if (previous instanceof AV.Op.AddUnique) {\n return new AV.Op.AddUnique(this._estimate(previous.objects()));\n } else {\n throw new Error('Op is invalid after previous op.');\n }\n },\n\n _estimate: function(oldValue) {\n if (!oldValue) {\n return _.clone(this.objects());\n } else {\n // We can't just take the _.uniq(_.union(...)) of oldValue and\n // this.objects, because the uniqueness may not apply to oldValue\n // (especially if the oldValue was set via .set())\n var newValue = _.clone(oldValue);\n AV._arrayEach(this.objects(), function(obj) {\n if (obj instanceof AV.Object && obj.id) {\n var matchingObj = _.find(newValue, function(anObj) {\n return anObj instanceof AV.Object && anObj.id === obj.id;\n });\n if (!matchingObj) {\n newValue.push(obj);\n } else {\n var index = _.indexOf(newValue, matchingObj);\n newValue[index] = obj;\n }\n } else if (!_.contains(newValue, obj)) {\n newValue.push(obj);\n }\n });\n return newValue;\n }\n },\n }\n );\n\n AV.Op._registerDecoder('AddUnique', function(json) {\n return new AV.Op.AddUnique(AV._decode(json.objects));\n });\n\n /**\n * @private\n * @class\n * Remove is an atomic operation where the given objects will be removed from\n * the array that is stored in this field.\n */\n AV.Op.Remove = AV.Op._extend(\n /** @lends AV.Op.Remove.prototype */ {\n _initialize: function(objects) {\n this._objects = _.uniq(objects);\n },\n\n /**\n * Returns the objects to be removed from the array.\n * @return {Array} The objects to be removed from the array.\n */\n objects: function() {\n return this._objects;\n },\n\n /**\n * Returns a JSON version of the operation suitable for sending to AV.\n * @return {Object}\n */\n toJSON: function() {\n return { __op: 'Remove', objects: AV._encode(this.objects()) };\n },\n\n _mergeWithPrevious: function(previous) {\n if (!previous) {\n return this;\n } else if (previous instanceof AV.Op.Unset) {\n return previous;\n } else if (previous instanceof AV.Op.Set) {\n return new AV.Op.Set(this._estimate(previous.value()));\n } else if (previous instanceof AV.Op.Remove) {\n return new AV.Op.Remove(_.union(previous.objects(), this.objects()));\n } else {\n throw new Error('Op is invalid after previous op.');\n }\n },\n\n _estimate: function(oldValue) {\n if (!oldValue) {\n return [];\n } else {\n var newValue = _.difference(oldValue, this.objects());\n // If there are saved AV Objects being removed, also remove them.\n AV._arrayEach(this.objects(), function(obj) {\n if (obj instanceof AV.Object && obj.id) {\n newValue = _.reject(newValue, function(other) {\n return other instanceof AV.Object && other.id === obj.id;\n });\n }\n });\n return newValue;\n }\n },\n }\n );\n\n AV.Op._registerDecoder('Remove', function(json) {\n return new AV.Op.Remove(AV._decode(json.objects));\n });\n\n /**\n * @private\n * @class\n * A Relation operation indicates that the field is an instance of\n * AV.Relation, and objects are being added to, or removed from, that\n * relation.\n */\n AV.Op.Relation = AV.Op._extend(\n /** @lends AV.Op.Relation.prototype */ {\n _initialize: function(adds, removes) {\n this._targetClassName = null;\n\n var self = this;\n\n var pointerToId = function(object) {\n if (object instanceof AV.Object) {\n if (!object.id) {\n throw new Error(\n \"You can't add an unsaved AV.Object to a relation.\"\n );\n }\n if (!self._targetClassName) {\n self._targetClassName = object.className;\n }\n if (self._targetClassName !== object.className) {\n throw new Error(\n 'Tried to create a AV.Relation with 2 different types: ' +\n self._targetClassName +\n ' and ' +\n object.className +\n '.'\n );\n }\n return object.id;\n }\n return object;\n };\n\n this.relationsToAdd = _.uniq(_.map(adds, pointerToId));\n this.relationsToRemove = _.uniq(_.map(removes, pointerToId));\n },\n\n /**\n * Returns an array of unfetched AV.Object that are being added to the\n * relation.\n * @return {Array}\n */\n added: function() {\n var self = this;\n return _.map(this.relationsToAdd, function(objectId) {\n var object = AV.Object._create(self._targetClassName);\n object.id = objectId;\n return object;\n });\n },\n\n /**\n * Returns an array of unfetched AV.Object that are being removed from\n * the relation.\n * @return {Array}\n */\n removed: function() {\n var self = this;\n return _.map(this.relationsToRemove, function(objectId) {\n var object = AV.Object._create(self._targetClassName);\n object.id = objectId;\n return object;\n });\n },\n\n /**\n * Returns a JSON version of the operation suitable for sending to AV.\n * @return {Object}\n */\n toJSON: function() {\n var adds = null;\n var removes = null;\n var self = this;\n var idToPointer = function(id) {\n return {\n __type: 'Pointer',\n className: self._targetClassName,\n objectId: id,\n };\n };\n var pointers = null;\n if (this.relationsToAdd.length > 0) {\n pointers = _.map(this.relationsToAdd, idToPointer);\n adds = { __op: 'AddRelation', objects: pointers };\n }\n\n if (this.relationsToRemove.length > 0) {\n pointers = _.map(this.relationsToRemove, idToPointer);\n removes = { __op: 'RemoveRelation', objects: pointers };\n }\n\n if (adds && removes) {\n return { __op: 'Batch', ops: [adds, removes] };\n }\n\n return adds || removes || {};\n },\n\n _mergeWithPrevious: function(previous) {\n if (!previous) {\n return this;\n } else if (previous instanceof AV.Op.Unset) {\n throw new Error(\"You can't modify a relation after deleting it.\");\n } else if (previous instanceof AV.Op.Relation) {\n if (\n previous._targetClassName &&\n previous._targetClassName !== this._targetClassName\n ) {\n throw new Error(\n 'Related object must be of class ' +\n previous._targetClassName +\n ', but ' +\n this._targetClassName +\n ' was passed in.'\n );\n }\n var newAdd = _.union(\n _.difference(previous.relationsToAdd, this.relationsToRemove),\n this.relationsToAdd\n );\n var newRemove = _.union(\n _.difference(previous.relationsToRemove, this.relationsToAdd),\n this.relationsToRemove\n );\n\n var newRelation = new AV.Op.Relation(newAdd, newRemove);\n newRelation._targetClassName = this._targetClassName;\n return newRelation;\n } else {\n throw new Error('Op is invalid after previous op.');\n }\n },\n\n _estimate: function(oldValue, object, key) {\n if (!oldValue) {\n var relation = new AV.Relation(object, key);\n relation.targetClassName = this._targetClassName;\n } else if (oldValue instanceof AV.Relation) {\n if (this._targetClassName) {\n if (oldValue.targetClassName) {\n if (oldValue.targetClassName !== this._targetClassName) {\n throw new Error(\n 'Related object must be a ' +\n oldValue.targetClassName +\n ', but a ' +\n this._targetClassName +\n ' was passed in.'\n );\n }\n } else {\n oldValue.targetClassName = this._targetClassName;\n }\n }\n return oldValue;\n } else {\n throw new Error('Op is invalid after previous op.');\n }\n },\n }\n );\n\n AV.Op._registerDecoder('AddRelation', function(json) {\n return new AV.Op.Relation(AV._decode(json.objects), []);\n });\n AV.Op._registerDecoder('RemoveRelation', function(json) {\n return new AV.Op.Relation([], AV._decode(json.objects));\n });\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/op.js","var parent = require('../../es/instance/find');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/stable/instance/find.js\n// module id = 440\n// module chunks = 0 1","var isPrototypeOf = require('../../internals/object-is-prototype-of');\nvar method = require('../array/virtual/find');\n\nvar ArrayPrototype = Array.prototype;\n\nmodule.exports = function (it) {\n var own = it.find;\n return it === ArrayPrototype || (isPrototypeOf(ArrayPrototype, it) && own === ArrayPrototype.find) ? method : own;\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/es/instance/find.js\n// module id = 441\n// module chunks = 0 1","require('../../../modules/es.array.find');\nvar entryVirtual = require('../../../internals/entry-virtual');\n\nmodule.exports = entryVirtual('Array').find;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/es/array/virtual/find.js\n// module id = 442\n// module chunks = 0 1","'use strict';\nvar $ = require('../internals/export');\nvar $find = require('../internals/array-iteration').find;\nvar addToUnscopables = require('../internals/add-to-unscopables');\n\nvar FIND = 'find';\nvar SKIPS_HOLES = true;\n\n// Shouldn't skip holes\nif (FIND in []) Array(1)[FIND](function () { SKIPS_HOLES = false; });\n\n// `Array.prototype.find` method\n// https://tc39.es/ecma262/#sec-array.prototype.find\n$({ target: 'Array', proto: true, forced: SKIPS_HOLES }, {\n find: function find(callbackfn /* , that = undefined */) {\n return $find(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);\n }\n});\n\n// https://tc39.es/ecma262/#sec-array.prototype-@@unscopables\naddToUnscopables(FIND);\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.array.find.js\n// module id = 443\n// module chunks = 0 1","var _ = require('underscore');\n\nmodule.exports = function(AV) {\n /**\n * Creates a new Relation for the given parent object and key. This\n * constructor should rarely be used directly, but rather created by\n * {@link AV.Object#relation}.\n * @param {AV.Object} parent The parent of this relation.\n * @param {String} key The key for this relation on the parent.\n * @see AV.Object#relation\n * @class\n *\n *
\n * A class that is used to access all of the children of a many-to-many\n * relationship. Each instance of AV.Relation is associated with a\n * particular parent object and key.\n *
\n */\n AV.Relation = function(parent, key) {\n if (!_.isString(key)) {\n throw new TypeError('key must be a string');\n }\n this.parent = parent;\n this.key = key;\n this.targetClassName = null;\n };\n\n /**\n * Creates a query that can be used to query the parent objects in this relation.\n * @param {String} parentClass The parent class or name.\n * @param {String} relationKey The relation field key in parent.\n * @param {AV.Object} child The child object.\n * @return {AV.Query}\n */\n AV.Relation.reverseQuery = function(parentClass, relationKey, child) {\n var query = new AV.Query(parentClass);\n query.equalTo(relationKey, child._toPointer());\n return query;\n };\n\n _.extend(\n AV.Relation.prototype,\n /** @lends AV.Relation.prototype */ {\n /**\n * Makes sure that this relation has the right parent and key.\n * @private\n */\n _ensureParentAndKey: function(parent, key) {\n this.parent = this.parent || parent;\n this.key = this.key || key;\n if (this.parent !== parent) {\n throw new Error(\n 'Internal Error. Relation retrieved from two different Objects.'\n );\n }\n if (this.key !== key) {\n throw new Error(\n 'Internal Error. Relation retrieved from two different keys.'\n );\n }\n },\n\n /**\n * Adds a AV.Object or an array of AV.Objects to the relation.\n * @param {AV.Object|AV.Object[]} objects The item or items to add.\n */\n add: function(objects) {\n if (!_.isArray(objects)) {\n objects = [objects];\n }\n\n var change = new AV.Op.Relation(objects, []);\n this.parent.set(this.key, change);\n this.targetClassName = change._targetClassName;\n },\n\n /**\n * Removes a AV.Object or an array of AV.Objects from this relation.\n * @param {AV.Object|AV.Object[]} objects The item or items to remove.\n */\n remove: function(objects) {\n if (!_.isArray(objects)) {\n objects = [objects];\n }\n\n var change = new AV.Op.Relation([], objects);\n this.parent.set(this.key, change);\n this.targetClassName = change._targetClassName;\n },\n\n /**\n * Returns a JSON version of the object suitable for saving to disk.\n * @return {Object}\n */\n toJSON: function() {\n return { __type: 'Relation', className: this.targetClassName };\n },\n\n /**\n * Returns a AV.Query that is limited to objects in this\n * relation.\n * @return {AV.Query}\n */\n query: function() {\n var targetClass;\n var query;\n if (!this.targetClassName) {\n targetClass = AV.Object._getSubclass(this.parent.className);\n query = new AV.Query(targetClass);\n query._defaultParams.redirectClassNameForKey = this.key;\n } else {\n targetClass = AV.Object._getSubclass(this.targetClassName);\n query = new AV.Query(targetClass);\n }\n query._addCondition('$relatedTo', 'object', this.parent._toPointer());\n query._addCondition('$relatedTo', 'key', this.key);\n\n return query;\n },\n }\n );\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/relation.js","const _ = require('underscore');\nconst cos = require('./uploader/cos');\nconst qiniu = require('./uploader/qiniu');\nconst s3 = require('./uploader/s3');\nconst AVError = require('./error');\nconst { request, _request: AVRequest } = require('./request');\nconst { tap, transformFetchOptions } = require('./utils');\nconst debug = require('debug')('leancloud:file');\nconst parseBase64 = require('./utils/parse-base64');\n\nmodule.exports = function(AV) {\n // port from browserify path module\n // since react-native packager won't shim node modules.\n const extname = path => {\n if (!_.isString(path)) return '';\n return path.match(\n /^(\\/?|)([\\s\\S]*?)((?:\\.{1,2}|[^\\/]+?|)(\\.[^.\\/]*|))(?:[\\/]*)$/\n )[4];\n };\n\n const b64Digit = number => {\n if (number < 26) {\n return String.fromCharCode(65 + number);\n }\n if (number < 52) {\n return String.fromCharCode(97 + (number - 26));\n }\n if (number < 62) {\n return String.fromCharCode(48 + (number - 52));\n }\n if (number === 62) {\n return '+';\n }\n if (number === 63) {\n return '/';\n }\n throw new Error('Tried to encode large digit ' + number + ' in base64.');\n };\n\n var encodeBase64 = function(array) {\n var chunks = [];\n chunks.length = Math.ceil(array.length / 3);\n _.times(chunks.length, function(i) {\n var b1 = array[i * 3];\n var b2 = array[i * 3 + 1] || 0;\n var b3 = array[i * 3 + 2] || 0;\n\n var has2 = i * 3 + 1 < array.length;\n var has3 = i * 3 + 2 < array.length;\n\n chunks[i] = [\n b64Digit((b1 >> 2) & 0x3f),\n b64Digit(((b1 << 4) & 0x30) | ((b2 >> 4) & 0x0f)),\n has2 ? b64Digit(((b2 << 2) & 0x3c) | ((b3 >> 6) & 0x03)) : '=',\n has3 ? b64Digit(b3 & 0x3f) : '=',\n ].join('');\n });\n return chunks.join('');\n };\n\n /**\n * An AV.File is a local representation of a file that is saved to the AV\n * cloud.\n * @param name {String} The file's name. This will change to a unique value\n * once the file has finished saving.\n * @param data {Array} The data for the file, as either:\n * 1. an Array of byte value Numbers, or\n * 2. an Object like { base64: \"...\" } with a base64-encoded String.\n * 3. a Blob(File) selected with a file upload control in a browser.\n * 4. an Object like { blob: {uri: \"...\"} } that mimics Blob\n * in some non-browser environments such as React Native.\n * 5. a Buffer in Node.js runtime.\n * 6. a Stream in Node.js runtime.\n *\n * For example:
\n * var fileUploadControl = $(\"#profilePhotoFileUpload\")[0];\n * if (fileUploadControl.files.length > 0) {\n * var file = fileUploadControl.files[0];\n * var name = \"photo.jpg\";\n * var file = new AV.File(name, file);\n * file.save().then(function() {\n * // The file has been saved to AV.\n * }, function(error) {\n * // The file either could not be read, or could not be saved to AV.\n * });\n * }
\n *\n * @class\n * @param [mimeType] {String} Content-Type header to use for the file. If\n * this is omitted, the content type will be inferred from the name's\n * extension.\n */\n AV.File = function(name, data, mimeType) {\n this.attributes = {\n name,\n url: '',\n metaData: {},\n // 用来存储转换后要上传的 base64 String\n base64: '',\n };\n\n if (_.isString(data)) {\n throw new TypeError(\n 'Creating an AV.File from a String is not yet supported.'\n );\n }\n if (_.isArray(data)) {\n this.attributes.metaData.size = data.length;\n data = { base64: encodeBase64(data) };\n }\n\n this._extName = '';\n this._data = data;\n this._uploadHeaders = {};\n\n if (data && data.blob && typeof data.blob.uri === 'string') {\n this._extName = extname(data.blob.uri);\n }\n\n if (typeof Blob !== 'undefined' && data instanceof Blob) {\n if (data.size) {\n this.attributes.metaData.size = data.size;\n }\n if (data.name) {\n this._extName = extname(data.name);\n }\n }\n\n\n let owner;\n if (data && data.owner) {\n owner = data.owner;\n } else if (!AV._config.disableCurrentUser) {\n try {\n owner = AV.User.current();\n } catch (error) {\n if ('SYNC_API_NOT_AVAILABLE' !== error.code) {\n throw error;\n }\n }\n }\n\n this.attributes.metaData.owner = owner ? owner.id : 'unknown';\n\n this.set('mime_type', mimeType);\n };\n\n /**\n * Creates a fresh AV.File object with exists url for saving to AVOS Cloud.\n * @param {String} name the file name\n * @param {String} url the file url.\n * @param {Object} [metaData] the file metadata object.\n * @param {String} [type] Content-Type header to use for the file. If\n * this is omitted, the content type will be inferred from the name's\n * extension.\n * @return {AV.File} the file object\n */\n AV.File.withURL = function(name, url, metaData, type) {\n if (!name || !url) {\n throw new Error('Please provide file name and url');\n }\n var file = new AV.File(name, null, type);\n //copy metaData properties to file.\n if (metaData) {\n for (var prop in metaData) {\n if (!file.attributes.metaData[prop])\n file.attributes.metaData[prop] = metaData[prop];\n }\n }\n file.attributes.url = url;\n //Mark the file is from external source.\n file.attributes.metaData.__source = 'external';\n file.attributes.metaData.size = 0;\n return file;\n };\n\n /**\n * Creates a file object with exists objectId.\n * @param {String} objectId The objectId string\n * @return {AV.File} the file object\n */\n AV.File.createWithoutData = function(objectId) {\n if (!objectId) {\n throw new TypeError('The objectId must be provided');\n }\n var file = new AV.File();\n file.id = objectId;\n return file;\n };\n\n /**\n * Request file censor.\n * @since 4.13.0\n * @param {String} objectId\n * @return {Promise.}\n */\n AV.File.censor = function(objectId) {\n if (!AV._config.masterKey) {\n throw new Error('Cannot censor a file without masterKey');\n }\n return request({\n method: 'POST',\n path: `/files/${objectId}/censor`,\n authOptions: { useMasterKey: true },\n }).then(res => res.censorResult);\n };\n\n _.extend(\n AV.File.prototype,\n /** @lends AV.File.prototype */ {\n className: '_File',\n\n _toFullJSON(seenObjects, full = true) {\n var json = _.clone(this.attributes);\n AV._objectEach(json, function(val, key) {\n json[key] = AV._encode(val, seenObjects, undefined, full);\n });\n AV._objectEach(this._operations, function(val, key) {\n json[key] = val;\n });\n\n if (_.has(this, 'id')) {\n json.objectId = this.id;\n }\n ['createdAt', 'updatedAt'].forEach(key => {\n if (_.has(this, key)) {\n const val = this[key];\n json[key] = _.isDate(val) ? val.toJSON() : val;\n }\n });\n if (full) {\n json.__type = 'File';\n }\n return json;\n },\n\n /**\n * Returns a JSON version of the file with meta data.\n * Inverse to {@link AV.parseJSON}\n * @since 3.0.0\n * @return {Object}\n */\n toFullJSON(seenObjects = []) {\n return this._toFullJSON(seenObjects);\n },\n\n /**\n * Returns a JSON version of the object.\n * @return {Object}\n */\n toJSON(key, holder, seenObjects = [this]) {\n return this._toFullJSON(seenObjects, false);\n },\n\n /**\n * Gets a Pointer referencing this file.\n * @private\n */\n _toPointer() {\n return {\n __type: 'Pointer',\n className: this.className,\n objectId: this.id,\n };\n },\n\n /**\n * Returns the ACL for this file.\n * @returns {AV.ACL} An instance of AV.ACL.\n */\n getACL() {\n return this._acl;\n },\n\n /**\n * Sets the ACL to be used for this file.\n * @param {AV.ACL} acl An instance of AV.ACL.\n */\n setACL(acl) {\n if (!(acl instanceof AV.ACL)) {\n return new AVError(AVError.OTHER_CAUSE, 'ACL must be a AV.ACL.');\n }\n this._acl = acl;\n return this;\n },\n\n /**\n * Gets the name of the file. Before save is called, this is the filename\n * given by the user. After save is called, that name gets prefixed with a\n * unique identifier.\n */\n name() {\n return this.get('name');\n },\n\n /**\n * Gets the url of the file. It is only available after you save the file or\n * after you get the file from a AV.Object.\n * @return {String}\n */\n url() {\n return this.get('url');\n },\n\n /**\n * Gets the attributs of the file object.\n * @param {String} The attribute name which want to get.\n * @returns {Any}\n */\n get(attrName) {\n switch (attrName) {\n case 'objectId':\n return this.id;\n case 'url':\n case 'name':\n case 'mime_type':\n case 'metaData':\n case 'createdAt':\n case 'updatedAt':\n return this.attributes[attrName];\n default:\n return this.attributes.metaData[attrName];\n }\n },\n\n /**\n * Set the metaData of the file object.\n * @param {Object} Object is an key value Object for setting metaData.\n * @param {String} attr is an optional metadata key.\n * @param {Object} value is an optional metadata value.\n * @returns {String|Number|Array|Object}\n */\n set(...args) {\n const set = (attrName, value) => {\n switch (attrName) {\n case 'name':\n case 'url':\n case 'mime_type':\n case 'base64':\n case 'metaData':\n this.attributes[attrName] = value;\n break;\n default:\n // File 并非一个 AVObject,不能完全自定义其他属性,所以只能都放在 metaData 上面\n this.attributes.metaData[attrName] = value;\n break;\n }\n };\n\n switch (args.length) {\n case 1:\n // 传入一个 Object\n for (var k in args[0]) {\n set(k, args[0][k]);\n }\n break;\n case 2:\n set(args[0], args[1]);\n break;\n }\n return this;\n },\n\n /**\n * Set a header for the upload request.\n * For more infomation, go to https://url.leanapp.cn/avfile-upload-headers\n *\n * @param {String} key header key\n * @param {String} value header value\n * @return {AV.File} this\n */\n setUploadHeader(key, value) {\n this._uploadHeaders[key] = value;\n return this;\n },\n\n /**\n *
Returns the file's metadata JSON object if no arguments is given.Returns the\n * metadata value if a key is given.Set metadata value if key and value are both given.
\n *
\n * var metadata = file.metaData(); //Get metadata JSON object.\n * var size = file.metaData('size'); // Get the size metadata value.\n * file.metaData('format', 'jpeg'); //set metadata attribute and value.\n *
\n * @return {Object} The file's metadata JSON object.\n * @param {String} attr an optional metadata key.\n * @param {Object} value an optional metadata value.\n **/\n metaData(attr, value) {\n if (attr && value) {\n this.attributes.metaData[attr] = value;\n return this;\n } else if (attr && !value) {\n return this.attributes.metaData[attr];\n } else {\n return this.attributes.metaData;\n }\n },\n\n /**\n * 如果文件是图片,获取图片的缩略图URL。可以传入宽度、高度、质量、格式等参数。\n * @return {String} 缩略图URL\n * @param {Number} width 宽度,单位:像素\n * @param {Number} heigth 高度,单位:像素\n * @param {Number} quality 质量,1-100的数字,默认100\n * @param {Number} scaleToFit 是否将图片自适应大小。默认为true。\n * @param {String} fmt 格式,默认为png,也可以为jpeg,gif等格式。\n */\n\n thumbnailURL(\n width,\n height,\n quality = 100,\n scaleToFit = true,\n fmt = 'png'\n ) {\n const url = this.attributes.url;\n if (!url) {\n throw new Error('Invalid url.');\n }\n if (!width || !height || width <= 0 || height <= 0) {\n throw new Error('Invalid width or height value.');\n }\n if (quality <= 0 || quality > 100) {\n throw new Error('Invalid quality value.');\n }\n const mode = scaleToFit ? 2 : 1;\n return (\n url +\n '?imageView/' +\n mode +\n '/w/' +\n width +\n '/h/' +\n height +\n '/q/' +\n quality +\n '/format/' +\n fmt\n );\n },\n\n /**\n * Returns the file's size.\n * @return {Number} The file's size in bytes.\n **/\n size() {\n return this.metaData().size;\n },\n\n /**\n * Returns the file's owner.\n * @return {String} The file's owner id.\n */\n ownerId() {\n return this.metaData().owner;\n },\n\n /**\n * Destroy the file.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled when the destroy\n * completes.\n */\n destroy(options) {\n if (!this.id) {\n return Promise.reject(new Error('The file id does not eixst.'));\n }\n var request = AVRequest(\n 'files',\n null,\n this.id,\n 'DELETE',\n null,\n options\n );\n return request;\n },\n\n /**\n * Request Qiniu upload token\n * @param {string} type\n * @return {Promise} Resolved with the response\n * @private\n */\n _fileToken(type, authOptions) {\n let name = this.attributes.name;\n\n let extName = extname(name);\n if (!extName && this._extName) {\n name += this._extName;\n extName = this._extName;\n }\n const data = {\n name,\n keep_file_name: authOptions.keepFileName,\n key: authOptions.key,\n ACL: this._acl,\n mime_type: type,\n metaData: this.attributes.metaData,\n };\n return AVRequest('fileTokens', null, null, 'POST', data, authOptions);\n },\n\n /**\n * @callback UploadProgressCallback\n * @param {XMLHttpRequestProgressEvent} event - The progress event with 'loaded' and 'total' attributes\n */\n /**\n * Saves the file to the AV cloud.\n * @param {AuthOptions} [options] AuthOptions plus:\n * @param {UploadProgressCallback} [options.onprogress] 文件上传进度,在 Node.js 中无效,回调参数说明详见 {@link UploadProgressCallback}。\n * @param {boolean} [options.keepFileName = false] 保留下载文件的文件名。\n * @param {string} [options.key] 指定文件的 key。设置该选项需要使用 masterKey\n * @return {Promise} Promise that is resolved when the save finishes.\n */\n save(options = {}) {\n if (this.id) {\n throw new Error('File is already saved.');\n }\n if (!this._previousSave) {\n if (this._data) {\n let mimeType = this.get('mime_type');\n this._previousSave = this._fileToken(mimeType, options).then(\n uploadInfo => {\n if (uploadInfo.mime_type) {\n mimeType = uploadInfo.mime_type;\n this.set('mime_type', mimeType);\n }\n this._token = uploadInfo.token;\n return Promise.resolve()\n .then(() => {\n const data = this._data;\n if (data && data.base64) {\n return parseBase64(data.base64, mimeType);\n }\n if (data && data.blob) {\n if (!data.blob.type && mimeType) {\n data.blob.type = mimeType;\n }\n if (!data.blob.name) {\n data.blob.name = this.get('name');\n }\n return data.blob;\n }\n if (typeof Blob !== 'undefined' && data instanceof Blob) {\n return data;\n }\n throw new TypeError('malformed file data');\n })\n .then(data => {\n const _options = _.extend({}, options);\n // filter out download progress events\n if (options.onprogress) {\n _options.onprogress = event => {\n if (event.direction === 'download') return;\n return options.onprogress(event);\n };\n }\n switch (uploadInfo.provider) {\n case 's3':\n return s3(uploadInfo, data, this, _options);\n case 'qcloud':\n return cos(uploadInfo, data, this, _options);\n case 'qiniu':\n default:\n return qiniu(uploadInfo, data, this, _options);\n }\n })\n .then(tap(() => this._callback(true)), error => {\n this._callback(false);\n throw error;\n });\n }\n );\n } else if (\n this.attributes.url &&\n this.attributes.metaData.__source === 'external'\n ) {\n // external link file.\n const data = {\n name: this.attributes.name,\n ACL: this._acl,\n metaData: this.attributes.metaData,\n mime_type: this.mimeType,\n url: this.attributes.url,\n };\n this._previousSave = AVRequest(\n 'files',\n null,\n null,\n 'post',\n data,\n options\n ).then(response => {\n this.id = response.objectId;\n return this;\n });\n }\n }\n return this._previousSave;\n },\n\n _callback(success) {\n AVRequest('fileCallback', null, null, 'post', {\n token: this._token,\n result: success,\n }).catch(debug);\n delete this._token;\n delete this._data;\n },\n\n /**\n * fetch the file from server. If the server's representation of the\n * model differs from its current attributes, they will be overriden,\n * @param {Object} fetchOptions Optional options to set 'keys',\n * 'include' and 'includeACL' option.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled when the fetch\n * completes.\n */\n fetch(fetchOptions, options) {\n if (!this.id) {\n throw new Error('Cannot fetch unsaved file');\n }\n var request = AVRequest(\n 'files',\n null,\n this.id,\n 'GET',\n transformFetchOptions(fetchOptions),\n options\n );\n return request.then(this._finishFetch.bind(this));\n },\n _finishFetch(response) {\n var value = AV.Object.prototype.parse(response);\n value.attributes = {\n name: value.name,\n url: value.url,\n mime_type: value.mime_type,\n bucket: value.bucket,\n };\n value.attributes.metaData = value.metaData || {};\n value.id = value.objectId;\n // clean\n delete value.objectId;\n delete value.metaData;\n delete value.url;\n delete value.name;\n delete value.mime_type;\n delete value.bucket;\n _.extend(this, value);\n return this;\n },\n\n /**\n * Request file censor\n * @since 4.13.0\n * @return {Promise.}\n */\n censor() {\n if (!this.id) {\n throw new Error('Cannot censor an unsaved file');\n }\n return AV.File.censor(this.id);\n },\n }\n );\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/file.js","const { getAdapter } = require('../adapter');\nconst debug = require('debug')('cos');\n\nmodule.exports = function(uploadInfo, data, file, saveOptions = {}) {\n const url =\n uploadInfo.upload_url + '?sign=' + encodeURIComponent(uploadInfo.token);\n const fileFormData = {\n field: 'fileContent',\n data,\n name: file.attributes.name,\n };\n const options = {\n headers: file._uploadHeaders,\n data: {\n op: 'upload',\n },\n onprogress: saveOptions.onprogress,\n };\n debug('url: %s, file: %o, options: %o', url, fileFormData, options);\n const upload = getAdapter('upload');\n return upload(url, fileFormData, options).then(\n response => {\n debug(response.status, response.data);\n if (response.ok === false) {\n const error = new Error(response.status);\n error.response = response;\n throw error;\n }\n file.attributes.url = uploadInfo.url;\n file._bucket = uploadInfo.bucket;\n file.id = uploadInfo.objectId;\n return file;\n },\n error => {\n const { response } = error;\n if (response) {\n debug(response.status, response.data);\n error.statusCode = response.status;\n error.response = response.data;\n }\n throw error;\n }\n );\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/uploader/cos.js","const { getAdapter } = require('../adapter');\nconst debug = require('debug')('leancloud:qiniu');\nconst ajax = require('../utils/ajax');\nconst btoa = require('../utils/btoa');\n\nconst SHARD_THRESHOLD = 1024 * 1024 * 64;\n\nconst CHUNK_SIZE = 1024 * 1024 * 16;\n\nfunction upload(uploadInfo, data, file, saveOptions = {}) {\n // Get the uptoken to upload files to qiniu.\n const uptoken = uploadInfo.token;\n const url = uploadInfo.upload_url || 'https://upload.qiniup.com';\n const fileFormData = {\n field: 'file',\n data,\n name: file.attributes.name,\n };\n const options = {\n headers: file._uploadHeaders,\n data: {\n name: file.attributes.name,\n key: uploadInfo.key,\n token: uptoken,\n },\n onprogress: saveOptions.onprogress,\n };\n debug('url: %s, file: %o, options: %o', url, fileFormData, options);\n const upload = getAdapter('upload');\n return upload(url, fileFormData, options).then(\n response => {\n debug(response.status, response.data);\n if (response.ok === false) {\n let message = response.status;\n if (response.data) {\n if (response.data.error) {\n message = response.data.error;\n } else {\n message = JSON.stringify(response.data);\n }\n }\n const error = new Error(message);\n error.response = response;\n throw error;\n }\n file.attributes.url = uploadInfo.url;\n file._bucket = uploadInfo.bucket;\n file.id = uploadInfo.objectId;\n return file;\n },\n error => {\n const { response } = error;\n if (response) {\n debug(response.status, response.data);\n error.statusCode = response.status;\n error.response = response.data;\n }\n throw error;\n }\n );\n}\n\nfunction urlSafeBase64(string) {\n const base64 = btoa(unescape(encodeURIComponent(string)));\n let result = '';\n for (const ch of base64) {\n switch (ch) {\n case '+':\n result += '-';\n break;\n case '/':\n result += '_';\n break;\n default:\n result += ch;\n }\n }\n return result;\n}\n\nclass ShardUploader {\n constructor(uploadInfo, data, file, saveOptions) {\n this.uploadInfo = uploadInfo;\n this.data = data;\n this.file = file;\n this.size = undefined;\n this.offset = 0;\n this.uploadedChunks = 0;\n\n const key = urlSafeBase64(uploadInfo.key);\n const uploadURL = uploadInfo.upload_url || 'https://upload.qiniup.com';\n this.baseURL = `${uploadURL}/buckets/${uploadInfo.bucket}/objects/${key}/uploads`;\n this.upToken = 'UpToken ' + uploadInfo.token;\n\n this.uploaded = 0;\n if (saveOptions && saveOptions.onprogress) {\n this.onProgress = ({ loaded }) => {\n loaded += this.uploadedChunks * CHUNK_SIZE;\n if (loaded <= this.uploaded) {\n return;\n }\n if (this.size) {\n saveOptions.onprogress({\n loaded,\n total: this.size,\n percent: (loaded / this.size) * 100,\n });\n } else {\n saveOptions.onprogress({ loaded });\n }\n this.uploaded = loaded;\n };\n }\n }\n\n /**\n * @returns {Promise}\n */\n getUploadId() {\n return ajax({\n method: 'POST',\n url: this.baseURL,\n headers: {\n Authorization: this.upToken,\n },\n }).then(res => res.uploadId);\n }\n\n getChunk() {\n throw new Error('Not implemented');\n }\n\n /**\n * @param {string} uploadId\n * @param {number} partNumber\n * @param {any} data\n * @returns {Promise<{ partNumber: number, etag: string }>}\n */\n uploadPart(uploadId, partNumber, data) {\n return ajax({\n method: 'PUT',\n url: `${this.baseURL}/${uploadId}/${partNumber}`,\n headers: {\n Authorization: this.upToken,\n },\n data,\n onprogress: this.onProgress,\n }).then(({ etag }) => ({ partNumber, etag }));\n }\n\n stopUpload(uploadId) {\n return ajax({\n method: 'DELETE',\n url: `${this.baseURL}/${uploadId}`,\n headers: {\n Authorization: this.upToken,\n },\n });\n }\n\n upload() {\n const parts = [];\n return this.getUploadId()\n .then(uploadId => {\n const uploadPart = () => {\n return Promise.resolve(this.getChunk())\n .then(chunk => {\n if (!chunk) {\n return;\n }\n const partNumber = parts.length + 1;\n return this.uploadPart(uploadId, partNumber, chunk).then(part => {\n parts.push(part);\n this.uploadedChunks++;\n return uploadPart();\n });\n })\n .catch(error =>\n this.stopUpload(uploadId).then(() => Promise.reject(error))\n );\n };\n\n return uploadPart().then(() =>\n ajax({\n method: 'POST',\n url: `${this.baseURL}/${uploadId}`,\n headers: {\n Authorization: this.upToken,\n },\n data: {\n parts,\n fname: this.file.attributes.name,\n mimeType: this.file.attributes.mime_type,\n },\n })\n );\n })\n .then(() => {\n this.file.attributes.url = this.uploadInfo.url;\n this.file._bucket = this.uploadInfo.bucket;\n this.file.id = this.uploadInfo.objectId;\n return this.file;\n });\n }\n}\n\nclass BlobUploader extends ShardUploader {\n constructor(uploadInfo, data, file, saveOptions) {\n super(uploadInfo, data, file, saveOptions);\n this.size = data.size;\n }\n\n /**\n * @returns {Blob | null}\n */\n getChunk() {\n if (this.offset >= this.size) {\n return null;\n }\n const chunk = this.data.slice(this.offset, this.offset + CHUNK_SIZE);\n this.offset += chunk.size;\n return chunk;\n }\n}\n\n\n\nfunction isBlob(data) {\n return typeof Blob !== 'undefined' && data instanceof Blob;\n}\n\n\n\nmodule.exports = function(uploadInfo, data, file, saveOptions = {}) {\n if (isBlob(data) && data.size >= SHARD_THRESHOLD) {\n return new BlobUploader(uploadInfo, data, file, saveOptions).upload();\n }\n return upload(uploadInfo, data, file, saveOptions);\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/uploader/qiniu.js","module.exports = require(\"core-js-pure/stable/array/from\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/core-js-stable/array/from.js\n// module id = 448\n// module chunks = 0 1","require('../../modules/es.string.iterator');\nrequire('../../modules/es.array.from');\nvar path = require('../../internals/path');\n\nmodule.exports = path.Array.from;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/es/array/from.js\n// module id = 449\n// module chunks = 0 1","var $ = require('../internals/export');\nvar from = require('../internals/array-from');\nvar checkCorrectnessOfIteration = require('../internals/check-correctness-of-iteration');\n\nvar INCORRECT_ITERATION = !checkCorrectnessOfIteration(function (iterable) {\n // eslint-disable-next-line es-x/no-array-from -- required for testing\n Array.from(iterable);\n});\n\n// `Array.from` method\n// https://tc39.es/ecma262/#sec-array.from\n$({ target: 'Array', stat: true, forced: INCORRECT_ITERATION }, {\n from: from\n});\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.array.from.js\n// module id = 450\n// module chunks = 0 1","'use strict';\nvar bind = require('../internals/function-bind-context');\nvar call = require('../internals/function-call');\nvar toObject = require('../internals/to-object');\nvar callWithSafeIterationClosing = require('../internals/call-with-safe-iteration-closing');\nvar isArrayIteratorMethod = require('../internals/is-array-iterator-method');\nvar isConstructor = require('../internals/is-constructor');\nvar lengthOfArrayLike = require('../internals/length-of-array-like');\nvar createProperty = require('../internals/create-property');\nvar getIterator = require('../internals/get-iterator');\nvar getIteratorMethod = require('../internals/get-iterator-method');\n\nvar $Array = Array;\n\n// `Array.from` method implementation\n// https://tc39.es/ecma262/#sec-array.from\nmodule.exports = function from(arrayLike /* , mapfn = undefined, thisArg = undefined */) {\n var O = toObject(arrayLike);\n var IS_CONSTRUCTOR = isConstructor(this);\n var argumentsLength = arguments.length;\n var mapfn = argumentsLength > 1 ? arguments[1] : undefined;\n var mapping = mapfn !== undefined;\n if (mapping) mapfn = bind(mapfn, argumentsLength > 2 ? arguments[2] : undefined);\n var iteratorMethod = getIteratorMethod(O);\n var index = 0;\n var length, result, step, iterator, next, value;\n // if the target is not iterable or it's an array with the default iterator - use a simple case\n if (iteratorMethod && !(this === $Array && isArrayIteratorMethod(iteratorMethod))) {\n iterator = getIterator(O, iteratorMethod);\n next = iterator.next;\n result = IS_CONSTRUCTOR ? new this() : [];\n for (;!(step = call(next, iterator)).done; index++) {\n value = mapping ? callWithSafeIterationClosing(iterator, mapfn, [step.value, index], true) : step.value;\n createProperty(result, index, value);\n }\n } else {\n length = lengthOfArrayLike(O);\n result = IS_CONSTRUCTOR ? new this(length) : $Array(length);\n for (;length > index; index++) {\n value = mapping ? mapfn(O[index], index) : O[index];\n createProperty(result, index, value);\n }\n }\n result.length = index;\n return result;\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/internals/array-from.js\n// module id = 451\n// module chunks = 0 1","var anObject = require('../internals/an-object');\nvar iteratorClose = require('../internals/iterator-close');\n\n// call something on iterator step with safe closing on error\nmodule.exports = function (iterator, fn, value, ENTRIES) {\n try {\n return ENTRIES ? fn(anObject(value)[0], value[1]) : fn(value);\n } catch (error) {\n iteratorClose(iterator, 'throw', error);\n }\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/internals/call-with-safe-iteration-closing.js\n// module id = 452\n// module chunks = 0 1","module.exports = require(\"core-js-pure/stable/symbol\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/core-js-stable/symbol.js\n// module id = 453\n// module chunks = 0 1","module.exports = require('../full/get-iterator-method');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/features/get-iterator-method.js\n// module id = 454\n// module chunks = 0 1","var parent = require('../actual/get-iterator-method');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/full/get-iterator-method.js\n// module id = 455\n// module chunks = 0 1","var parent = require('../stable/get-iterator-method');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/actual/get-iterator-method.js\n// module id = 456\n// module chunks = 0 1","var parent = require('../es/get-iterator-method');\nrequire('../modules/web.dom-collections.iterator');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/stable/get-iterator-method.js\n// module id = 457\n// module chunks = 0 1","require('../modules/es.array.iterator');\nrequire('../modules/es.string.iterator');\nvar getIteratorMethod = require('../internals/get-iterator-method');\n\nmodule.exports = getIteratorMethod;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/es/get-iterator-method.js\n// module id = 458\n// module chunks = 0 1","module.exports = require(\"core-js-pure/stable/reflect/construct\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/core-js-stable/reflect/construct.js\n// module id = 459\n// module chunks = 0 1","var parent = require('../../es/reflect/construct');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/stable/reflect/construct.js\n// module id = 460\n// module chunks = 0 1","require('../../modules/es.reflect.construct');\nvar path = require('../../internals/path');\n\nmodule.exports = path.Reflect.construct;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/es/reflect/construct.js\n// module id = 461\n// module chunks = 0 1","var $ = require('../internals/export');\nvar getBuiltIn = require('../internals/get-built-in');\nvar apply = require('../internals/function-apply');\nvar bind = require('../internals/function-bind');\nvar aConstructor = require('../internals/a-constructor');\nvar anObject = require('../internals/an-object');\nvar isObject = require('../internals/is-object');\nvar create = require('../internals/object-create');\nvar fails = require('../internals/fails');\n\nvar nativeConstruct = getBuiltIn('Reflect', 'construct');\nvar ObjectPrototype = Object.prototype;\nvar push = [].push;\n\n// `Reflect.construct` method\n// https://tc39.es/ecma262/#sec-reflect.construct\n// MS Edge supports only 2 arguments and argumentsList argument is optional\n// FF Nightly sets third argument as `new.target`, but does not create `this` from it\nvar NEW_TARGET_BUG = fails(function () {\n function F() { /* empty */ }\n return !(nativeConstruct(function () { /* empty */ }, [], F) instanceof F);\n});\n\nvar ARGS_BUG = !fails(function () {\n nativeConstruct(function () { /* empty */ });\n});\n\nvar FORCED = NEW_TARGET_BUG || ARGS_BUG;\n\n$({ target: 'Reflect', stat: true, forced: FORCED, sham: FORCED }, {\n construct: function construct(Target, args /* , newTarget */) {\n aConstructor(Target);\n anObject(args);\n var newTarget = arguments.length < 3 ? Target : aConstructor(arguments[2]);\n if (ARGS_BUG && !NEW_TARGET_BUG) return nativeConstruct(Target, args, newTarget);\n if (Target == newTarget) {\n // w/o altered newTarget, optimization for 0-4 arguments\n switch (args.length) {\n case 0: return new Target();\n case 1: return new Target(args[0]);\n case 2: return new Target(args[0], args[1]);\n case 3: return new Target(args[0], args[1], args[2]);\n case 4: return new Target(args[0], args[1], args[2], args[3]);\n }\n // w/o altered newTarget, lot of arguments case\n var $args = [null];\n apply(push, $args, args);\n return new (apply(bind, Target, $args))();\n }\n // with altered newTarget, not support built-in constructors\n var proto = newTarget.prototype;\n var instance = create(isObject(proto) ? proto : ObjectPrototype);\n var result = apply(Target, instance, args);\n return isObject(result) ? result : instance;\n }\n});\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.reflect.construct.js\n// module id = 462\n// module chunks = 0 1","var _Object$create = require(\"@babel/runtime-corejs3/core-js/object/create\");\n\nvar _Object$defineProperty = require(\"@babel/runtime-corejs3/core-js/object/define-property\");\n\nvar setPrototypeOf = require(\"./setPrototypeOf.js\");\n\nfunction _inherits(subClass, superClass) {\n if (typeof superClass !== \"function\" && superClass !== null) {\n throw new TypeError(\"Super expression must either be null or a function\");\n }\n\n subClass.prototype = _Object$create(superClass && superClass.prototype, {\n constructor: {\n value: subClass,\n writable: true,\n configurable: true\n }\n });\n\n _Object$defineProperty(subClass, \"prototype\", {\n writable: false\n });\n\n if (superClass) setPrototypeOf(subClass, superClass);\n}\n\nmodule.exports = _inherits, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/helpers/inherits.js\n// module id = 463\n// module chunks = 0 1","module.exports = require(\"core-js-pure/features/object/create\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/core-js/object/create.js\n// module id = 464\n// module chunks = 0 1","module.exports = require('../../full/object/create');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/features/object/create.js\n// module id = 465\n// module chunks = 0 1","var parent = require('../../actual/object/create');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/full/object/create.js\n// module id = 466\n// module chunks = 0 1","var parent = require('../../stable/object/create');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/actual/object/create.js\n// module id = 467\n// module chunks = 0 1","var parent = require('../../es/object/create');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/stable/object/create.js\n// module id = 468\n// module chunks = 0 1","require('../../modules/es.object.create');\nvar path = require('../../internals/path');\n\nvar Object = path.Object;\n\nmodule.exports = function create(P, D) {\n return Object.create(P, D);\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/es/object/create.js\n// module id = 469\n// module chunks = 0 1","// TODO: Remove from `core-js@4`\nvar $ = require('../internals/export');\nvar DESCRIPTORS = require('../internals/descriptors');\nvar create = require('../internals/object-create');\n\n// `Object.create` method\n// https://tc39.es/ecma262/#sec-object.create\n$({ target: 'Object', stat: true, sham: !DESCRIPTORS }, {\n create: create\n});\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.object.create.js\n// module id = 470\n// module chunks = 0 1","module.exports = require('../../full/object/define-property');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/features/object/define-property.js\n// module id = 471\n// module chunks = 0 1","var parent = require('../../actual/object/define-property');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/full/object/define-property.js\n// module id = 472\n// module chunks = 0 1","var parent = require('../../stable/object/define-property');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/actual/object/define-property.js\n// module id = 473\n// module chunks = 0 1","var _Object$setPrototypeOf = require(\"@babel/runtime-corejs3/core-js/object/set-prototype-of\");\n\nvar _bindInstanceProperty = require(\"@babel/runtime-corejs3/core-js/instance/bind\");\n\nfunction _setPrototypeOf(o, p) {\n var _context;\n\n module.exports = _setPrototypeOf = _Object$setPrototypeOf ? _bindInstanceProperty(_context = _Object$setPrototypeOf).call(_context) : function _setPrototypeOf(o, p) {\n o.__proto__ = p;\n return o;\n }, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n return _setPrototypeOf(o, p);\n}\n\nmodule.exports = _setPrototypeOf, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/helpers/setPrototypeOf.js\n// module id = 474\n// module chunks = 0 1","module.exports = require('../../full/object/set-prototype-of');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/features/object/set-prototype-of.js\n// module id = 475\n// module chunks = 0 1","var parent = require('../../actual/object/set-prototype-of');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/full/object/set-prototype-of.js\n// module id = 476\n// module chunks = 0 1","var parent = require('../../stable/object/set-prototype-of');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/actual/object/set-prototype-of.js\n// module id = 477\n// module chunks = 0 1","module.exports = require('../../full/instance/bind');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/features/instance/bind.js\n// module id = 478\n// module chunks = 0 1","var parent = require('../../actual/instance/bind');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/full/instance/bind.js\n// module id = 479\n// module chunks = 0 1","var parent = require('../../stable/instance/bind');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/actual/instance/bind.js\n// module id = 480\n// module chunks = 0 1","var parent = require('../../es/instance/bind');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/stable/instance/bind.js\n// module id = 481\n// module chunks = 0 1","var isPrototypeOf = require('../../internals/object-is-prototype-of');\nvar method = require('../function/virtual/bind');\n\nvar FunctionPrototype = Function.prototype;\n\nmodule.exports = function (it) {\n var own = it.bind;\n return it === FunctionPrototype || (isPrototypeOf(FunctionPrototype, it) && own === FunctionPrototype.bind) ? method : own;\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/es/instance/bind.js\n// module id = 482\n// module chunks = 0 1","require('../../../modules/es.function.bind');\nvar entryVirtual = require('../../../internals/entry-virtual');\n\nmodule.exports = entryVirtual('Function').bind;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/es/function/virtual/bind.js\n// module id = 483\n// module chunks = 0 1","// TODO: Remove from `core-js@4`\nvar $ = require('../internals/export');\nvar bind = require('../internals/function-bind');\n\n// `Function.prototype.bind` method\n// https://tc39.es/ecma262/#sec-function.prototype.bind\n$({ target: 'Function', proto: true, forced: Function.bind !== bind }, {\n bind: bind\n});\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.function.bind.js\n// module id = 484\n// module chunks = 0 1","var _typeof = require(\"./typeof.js\")[\"default\"];\n\nvar assertThisInitialized = require(\"./assertThisInitialized.js\");\n\nfunction _possibleConstructorReturn(self, call) {\n if (call && (_typeof(call) === \"object\" || typeof call === \"function\")) {\n return call;\n } else if (call !== void 0) {\n throw new TypeError(\"Derived constructors may only return object or undefined\");\n }\n\n return assertThisInitialized(self);\n}\n\nmodule.exports = _possibleConstructorReturn, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/helpers/possibleConstructorReturn.js\n// module id = 485\n// module chunks = 0 1","function _assertThisInitialized(self) {\n if (self === void 0) {\n throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\");\n }\n\n return self;\n}\n\nmodule.exports = _assertThisInitialized, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/helpers/assertThisInitialized.js\n// module id = 486\n// module chunks = 0 1","var _Object$setPrototypeOf = require(\"@babel/runtime-corejs3/core-js/object/set-prototype-of\");\n\nvar _bindInstanceProperty = require(\"@babel/runtime-corejs3/core-js/instance/bind\");\n\nvar _Object$getPrototypeOf = require(\"@babel/runtime-corejs3/core-js/object/get-prototype-of\");\n\nfunction _getPrototypeOf(o) {\n var _context;\n\n module.exports = _getPrototypeOf = _Object$setPrototypeOf ? _bindInstanceProperty(_context = _Object$getPrototypeOf).call(_context) : function _getPrototypeOf(o) {\n return o.__proto__ || _Object$getPrototypeOf(o);\n }, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n return _getPrototypeOf(o);\n}\n\nmodule.exports = _getPrototypeOf, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/helpers/getPrototypeOf.js\n// module id = 487\n// module chunks = 0 1","module.exports = require(\"core-js-pure/features/object/get-prototype-of\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/core-js/object/get-prototype-of.js\n// module id = 488\n// module chunks = 0 1","module.exports = require('../../full/object/get-prototype-of');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/features/object/get-prototype-of.js\n// module id = 489\n// module chunks = 0 1","var parent = require('../../actual/object/get-prototype-of');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/full/object/get-prototype-of.js\n// module id = 490\n// module chunks = 0 1","var parent = require('../../stable/object/get-prototype-of');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/actual/object/get-prototype-of.js\n// module id = 491\n// module chunks = 0 1","function _classCallCheck(instance, Constructor) {\n if (!(instance instanceof Constructor)) {\n throw new TypeError(\"Cannot call a class as a function\");\n }\n}\n\nmodule.exports = _classCallCheck, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/helpers/classCallCheck.js\n// module id = 492\n// module chunks = 0 1","var _Object$defineProperty = require(\"@babel/runtime-corejs3/core-js/object/define-property\");\n\nfunction _defineProperties(target, props) {\n for (var i = 0; i < props.length; i++) {\n var descriptor = props[i];\n descriptor.enumerable = descriptor.enumerable || false;\n descriptor.configurable = true;\n if (\"value\" in descriptor) descriptor.writable = true;\n\n _Object$defineProperty(target, descriptor.key, descriptor);\n }\n}\n\nfunction _createClass(Constructor, protoProps, staticProps) {\n if (protoProps) _defineProperties(Constructor.prototype, protoProps);\n if (staticProps) _defineProperties(Constructor, staticProps);\n\n _Object$defineProperty(Constructor, \"prototype\", {\n writable: false\n });\n\n return Constructor;\n}\n\nmodule.exports = _createClass, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/helpers/createClass.js\n// module id = 493\n// module chunks = 0 1","// base64 character set, plus padding character (=)\nconst b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';\n\nmodule.exports = string => {\n let result = '';\n\n for (let i = 0; i < string.length; ) {\n const a = string.charCodeAt(i++);\n const b = string.charCodeAt(i++);\n const c = string.charCodeAt(i++);\n if (a > 255 || b > 255 || c > 255) {\n throw new TypeError(\n 'Failed to encode base64: The string to be encoded contains characters outside of the Latin1 range.'\n );\n }\n\n const bitmap = (a << 16) | (b << 8) | c;\n result +=\n b64.charAt((bitmap >> 18) & 63) +\n b64.charAt((bitmap >> 12) & 63) +\n b64.charAt((bitmap >> 6) & 63) +\n b64.charAt(bitmap & 63);\n }\n\n // To determine the final padding\n const rest = string.length % 3;\n // If there's need of padding, replace the last 'A's with equal signs\n return rest ? result.slice(0, rest - 3) + '==='.substring(rest) : result;\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/utils/btoa.js","const _ = require('underscore');\nconst ajax = require('../utils/ajax');\n\nmodule.exports = function upload(uploadInfo, data, file, saveOptions = {}) {\n\n return ajax({\n url: uploadInfo.upload_url,\n method: 'PUT',\n data,\n headers: _.extend(\n {\n 'Content-Type': file.get('mime_type'),\n 'Cache-Control': 'public, max-age=31536000',\n },\n file._uploadHeaders\n ),\n onprogress: saveOptions.onprogress,\n }).then(() => {\n file.attributes.url = uploadInfo.url;\n file._bucket = uploadInfo.bucket;\n file.id = uploadInfo.objectId;\n return file;\n });\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/uploader/s3.js","(function(){\r\n var crypt = require('crypt'),\r\n utf8 = require('charenc').utf8,\r\n isBuffer = require('is-buffer'),\r\n bin = require('charenc').bin,\r\n\r\n // The core\r\n md5 = function (message, options) {\r\n // Convert to byte array\r\n if (message.constructor == String)\r\n if (options && options.encoding === 'binary')\r\n message = bin.stringToBytes(message);\r\n else\r\n message = utf8.stringToBytes(message);\r\n else if (isBuffer(message))\r\n message = Array.prototype.slice.call(message, 0);\r\n else if (!Array.isArray(message))\r\n message = message.toString();\r\n // else, assume byte array already\r\n\r\n var m = crypt.bytesToWords(message),\r\n l = message.length * 8,\r\n a = 1732584193,\r\n b = -271733879,\r\n c = -1732584194,\r\n d = 271733878;\r\n\r\n // Swap endian\r\n for (var i = 0; i < m.length; i++) {\r\n m[i] = ((m[i] << 8) | (m[i] >>> 24)) & 0x00FF00FF |\r\n ((m[i] << 24) | (m[i] >>> 8)) & 0xFF00FF00;\r\n }\r\n\r\n // Padding\r\n m[l >>> 5] |= 0x80 << (l % 32);\r\n m[(((l + 64) >>> 9) << 4) + 14] = l;\r\n\r\n // Method shortcuts\r\n var FF = md5._ff,\r\n GG = md5._gg,\r\n HH = md5._hh,\r\n II = md5._ii;\r\n\r\n for (var i = 0; i < m.length; i += 16) {\r\n\r\n var aa = a,\r\n bb = b,\r\n cc = c,\r\n dd = d;\r\n\r\n a = FF(a, b, c, d, m[i+ 0], 7, -680876936);\r\n d = FF(d, a, b, c, m[i+ 1], 12, -389564586);\r\n c = FF(c, d, a, b, m[i+ 2], 17, 606105819);\r\n b = FF(b, c, d, a, m[i+ 3], 22, -1044525330);\r\n a = FF(a, b, c, d, m[i+ 4], 7, -176418897);\r\n d = FF(d, a, b, c, m[i+ 5], 12, 1200080426);\r\n c = FF(c, d, a, b, m[i+ 6], 17, -1473231341);\r\n b = FF(b, c, d, a, m[i+ 7], 22, -45705983);\r\n a = FF(a, b, c, d, m[i+ 8], 7, 1770035416);\r\n d = FF(d, a, b, c, m[i+ 9], 12, -1958414417);\r\n c = FF(c, d, a, b, m[i+10], 17, -42063);\r\n b = FF(b, c, d, a, m[i+11], 22, -1990404162);\r\n a = FF(a, b, c, d, m[i+12], 7, 1804603682);\r\n d = FF(d, a, b, c, m[i+13], 12, -40341101);\r\n c = FF(c, d, a, b, m[i+14], 17, -1502002290);\r\n b = FF(b, c, d, a, m[i+15], 22, 1236535329);\r\n\r\n a = GG(a, b, c, d, m[i+ 1], 5, -165796510);\r\n d = GG(d, a, b, c, m[i+ 6], 9, -1069501632);\r\n c = GG(c, d, a, b, m[i+11], 14, 643717713);\r\n b = GG(b, c, d, a, m[i+ 0], 20, -373897302);\r\n a = GG(a, b, c, d, m[i+ 5], 5, -701558691);\r\n d = GG(d, a, b, c, m[i+10], 9, 38016083);\r\n c = GG(c, d, a, b, m[i+15], 14, -660478335);\r\n b = GG(b, c, d, a, m[i+ 4], 20, -405537848);\r\n a = GG(a, b, c, d, m[i+ 9], 5, 568446438);\r\n d = GG(d, a, b, c, m[i+14], 9, -1019803690);\r\n c = GG(c, d, a, b, m[i+ 3], 14, -187363961);\r\n b = GG(b, c, d, a, m[i+ 8], 20, 1163531501);\r\n a = GG(a, b, c, d, m[i+13], 5, -1444681467);\r\n d = GG(d, a, b, c, m[i+ 2], 9, -51403784);\r\n c = GG(c, d, a, b, m[i+ 7], 14, 1735328473);\r\n b = GG(b, c, d, a, m[i+12], 20, -1926607734);\r\n\r\n a = HH(a, b, c, d, m[i+ 5], 4, -378558);\r\n d = HH(d, a, b, c, m[i+ 8], 11, -2022574463);\r\n c = HH(c, d, a, b, m[i+11], 16, 1839030562);\r\n b = HH(b, c, d, a, m[i+14], 23, -35309556);\r\n a = HH(a, b, c, d, m[i+ 1], 4, -1530992060);\r\n d = HH(d, a, b, c, m[i+ 4], 11, 1272893353);\r\n c = HH(c, d, a, b, m[i+ 7], 16, -155497632);\r\n b = HH(b, c, d, a, m[i+10], 23, -1094730640);\r\n a = HH(a, b, c, d, m[i+13], 4, 681279174);\r\n d = HH(d, a, b, c, m[i+ 0], 11, -358537222);\r\n c = HH(c, d, a, b, m[i+ 3], 16, -722521979);\r\n b = HH(b, c, d, a, m[i+ 6], 23, 76029189);\r\n a = HH(a, b, c, d, m[i+ 9], 4, -640364487);\r\n d = HH(d, a, b, c, m[i+12], 11, -421815835);\r\n c = HH(c, d, a, b, m[i+15], 16, 530742520);\r\n b = HH(b, c, d, a, m[i+ 2], 23, -995338651);\r\n\r\n a = II(a, b, c, d, m[i+ 0], 6, -198630844);\r\n d = II(d, a, b, c, m[i+ 7], 10, 1126891415);\r\n c = II(c, d, a, b, m[i+14], 15, -1416354905);\r\n b = II(b, c, d, a, m[i+ 5], 21, -57434055);\r\n a = II(a, b, c, d, m[i+12], 6, 1700485571);\r\n d = II(d, a, b, c, m[i+ 3], 10, -1894986606);\r\n c = II(c, d, a, b, m[i+10], 15, -1051523);\r\n b = II(b, c, d, a, m[i+ 1], 21, -2054922799);\r\n a = II(a, b, c, d, m[i+ 8], 6, 1873313359);\r\n d = II(d, a, b, c, m[i+15], 10, -30611744);\r\n c = II(c, d, a, b, m[i+ 6], 15, -1560198380);\r\n b = II(b, c, d, a, m[i+13], 21, 1309151649);\r\n a = II(a, b, c, d, m[i+ 4], 6, -145523070);\r\n d = II(d, a, b, c, m[i+11], 10, -1120210379);\r\n c = II(c, d, a, b, m[i+ 2], 15, 718787259);\r\n b = II(b, c, d, a, m[i+ 9], 21, -343485551);\r\n\r\n a = (a + aa) >>> 0;\r\n b = (b + bb) >>> 0;\r\n c = (c + cc) >>> 0;\r\n d = (d + dd) >>> 0;\r\n }\r\n\r\n return crypt.endian([a, b, c, d]);\r\n };\r\n\r\n // Auxiliary functions\r\n md5._ff = function (a, b, c, d, x, s, t) {\r\n var n = a + (b & c | ~b & d) + (x >>> 0) + t;\r\n return ((n << s) | (n >>> (32 - s))) + b;\r\n };\r\n md5._gg = function (a, b, c, d, x, s, t) {\r\n var n = a + (b & d | c & ~d) + (x >>> 0) + t;\r\n return ((n << s) | (n >>> (32 - s))) + b;\r\n };\r\n md5._hh = function (a, b, c, d, x, s, t) {\r\n var n = a + (b ^ c ^ d) + (x >>> 0) + t;\r\n return ((n << s) | (n >>> (32 - s))) + b;\r\n };\r\n md5._ii = function (a, b, c, d, x, s, t) {\r\n var n = a + (c ^ (b | ~d)) + (x >>> 0) + t;\r\n return ((n << s) | (n >>> (32 - s))) + b;\r\n };\r\n\r\n // Package private blocksize\r\n md5._blocksize = 16;\r\n md5._digestsize = 16;\r\n\r\n module.exports = function (message, options) {\r\n if (message === undefined || message === null)\r\n throw new Error('Illegal argument ' + message);\r\n\r\n var digestbytes = crypt.wordsToBytes(md5(message, options));\r\n return options && options.asBytes ? digestbytes :\r\n options && options.asString ? bin.bytesToString(digestbytes) :\r\n crypt.bytesToHex(digestbytes);\r\n };\r\n\r\n})();\r\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/md5/md5.js\n// module id = 496\n// module chunks = 0 1","(function() {\n var base64map\n = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',\n\n crypt = {\n // Bit-wise rotation left\n rotl: function(n, b) {\n return (n << b) | (n >>> (32 - b));\n },\n\n // Bit-wise rotation right\n rotr: function(n, b) {\n return (n << (32 - b)) | (n >>> b);\n },\n\n // Swap big-endian to little-endian and vice versa\n endian: function(n) {\n // If number given, swap endian\n if (n.constructor == Number) {\n return crypt.rotl(n, 8) & 0x00FF00FF | crypt.rotl(n, 24) & 0xFF00FF00;\n }\n\n // Else, assume array and swap all items\n for (var i = 0; i < n.length; i++)\n n[i] = crypt.endian(n[i]);\n return n;\n },\n\n // Generate an array of any length of random bytes\n randomBytes: function(n) {\n for (var bytes = []; n > 0; n--)\n bytes.push(Math.floor(Math.random() * 256));\n return bytes;\n },\n\n // Convert a byte array to big-endian 32-bit words\n bytesToWords: function(bytes) {\n for (var words = [], i = 0, b = 0; i < bytes.length; i++, b += 8)\n words[b >>> 5] |= bytes[i] << (24 - b % 32);\n return words;\n },\n\n // Convert big-endian 32-bit words to a byte array\n wordsToBytes: function(words) {\n for (var bytes = [], b = 0; b < words.length * 32; b += 8)\n bytes.push((words[b >>> 5] >>> (24 - b % 32)) & 0xFF);\n return bytes;\n },\n\n // Convert a byte array to a hex string\n bytesToHex: function(bytes) {\n for (var hex = [], i = 0; i < bytes.length; i++) {\n hex.push((bytes[i] >>> 4).toString(16));\n hex.push((bytes[i] & 0xF).toString(16));\n }\n return hex.join('');\n },\n\n // Convert a hex string to a byte array\n hexToBytes: function(hex) {\n for (var bytes = [], c = 0; c < hex.length; c += 2)\n bytes.push(parseInt(hex.substr(c, 2), 16));\n return bytes;\n },\n\n // Convert a byte array to a base-64 string\n bytesToBase64: function(bytes) {\n for (var base64 = [], i = 0; i < bytes.length; i += 3) {\n var triplet = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2];\n for (var j = 0; j < 4; j++)\n if (i * 8 + j * 6 <= bytes.length * 8)\n base64.push(base64map.charAt((triplet >>> 6 * (3 - j)) & 0x3F));\n else\n base64.push('=');\n }\n return base64.join('');\n },\n\n // Convert a base-64 string to a byte array\n base64ToBytes: function(base64) {\n // Remove non-base-64 characters\n base64 = base64.replace(/[^A-Z0-9+\\/]/ig, '');\n\n for (var bytes = [], i = 0, imod4 = 0; i < base64.length;\n imod4 = ++i % 4) {\n if (imod4 == 0) continue;\n bytes.push(((base64map.indexOf(base64.charAt(i - 1))\n & (Math.pow(2, -2 * imod4 + 8) - 1)) << (imod4 * 2))\n | (base64map.indexOf(base64.charAt(i)) >>> (6 - imod4 * 2)));\n }\n return bytes;\n }\n };\n\n module.exports = crypt;\n})();\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/crypt/crypt.js\n// module id = 497\n// module chunks = 0 1","/*!\n * Determine if an object is a Buffer\n *\n * @author Feross Aboukhadijeh \n * @license MIT\n */\n\n// The _isBuffer check is for Safari 5-7 support, because it's missing\n// Object.prototype.constructor. Remove this eventually\nmodule.exports = function (obj) {\n return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer)\n}\n\nfunction isBuffer (obj) {\n return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)\n}\n\n// For Node v0.10 support. Remove this eventually.\nfunction isSlowBuffer (obj) {\n return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0))\n}\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/is-buffer/index.js\n// module id = 498\n// module chunks = 0 1","var dataURItoBlob = function(dataURI, type) {\n var byteString;\n\n // 传入的 base64,不是 dataURL\n if (dataURI.indexOf('base64') < 0) {\n byteString = atob(dataURI);\n } else if (dataURI.split(',')[0].indexOf('base64') >= 0) {\n type =\n type ||\n dataURI\n .split(',')[0]\n .split(':')[1]\n .split(';')[0];\n byteString = atob(dataURI.split(',')[1]);\n } else {\n byteString = unescape(dataURI.split(',')[1]);\n }\n var ia = new Uint8Array(byteString.length);\n for (var i = 0; i < byteString.length; i++) {\n ia[i] = byteString.charCodeAt(i);\n }\n return new Blob([ia], { type });\n};\n\nmodule.exports = dataURItoBlob;\n\n\n\n// WEBPACK FOOTER //\n// ./src/utils/parse-base64-browser.js","const _ = require('underscore');\nconst AVError = require('./error');\nconst { _request } = require('./request');\nconst {\n isNullOrUndefined,\n ensureArray,\n transformFetchOptions,\n setValue,\n findValue,\n isPlainObject,\n continueWhile,\n} = require('./utils');\n\nconst recursiveToPointer = value => {\n if (_.isArray(value)) return value.map(recursiveToPointer);\n if (isPlainObject(value)) return _.mapObject(value, recursiveToPointer);\n if (_.isObject(value) && value._toPointer) return value._toPointer();\n return value;\n};\n\nconst RESERVED_KEYS = ['objectId', 'createdAt', 'updatedAt'];\nconst checkReservedKey = key => {\n if (RESERVED_KEYS.indexOf(key) !== -1) {\n throw new Error(`key[${key}] is reserved`);\n }\n};\n\nconst handleBatchResults = results => {\n const firstError = _.find(results, result => result instanceof Error);\n if (!firstError) {\n return results;\n }\n const error = new AVError(firstError.code, firstError.message);\n error.results = results;\n throw error;\n};\n\n// Helper function to get a value from a Backbone object as a property\n// or as a function.\nfunction getValue(object, prop) {\n if (!(object && object[prop])) {\n return null;\n }\n return _.isFunction(object[prop]) ? object[prop]() : object[prop];\n}\n\n// AV.Object is analogous to the Java AVObject.\n// It also implements the same interface as a Backbone model.\n\nmodule.exports = function(AV) {\n /**\n * Creates a new model with defined attributes. A client id (cid) is\n * automatically generated and assigned for you.\n *\n *
You won't normally call this method directly. It is recommended that\n * you use a subclass of AV.Object instead, created by calling\n * extend.
\n *\n *
However, if you don't want to use a subclass, or aren't sure which\n * subclass is appropriate, you can use this form:
\n * var object = new AV.Object(\"ClassName\");\n *
\n * That is basically equivalent to:
\n * var MyClass = AV.Object.extend(\"ClassName\");\n * var object = new MyClass();\n *
\n *\n * @param {Object} attributes The initial set of data to store in the object.\n * @param {Object} options A set of Backbone-like options for creating the\n * object. The only option currently supported is \"collection\".\n * @see AV.Object.extend\n *\n * @class\n *\n *
The fundamental unit of AV data, which implements the Backbone Model\n * interface.
\n */\n AV.Object = function(attributes, options) {\n // Allow new AV.Object(\"ClassName\") as a shortcut to _create.\n if (_.isString(attributes)) {\n return AV.Object._create.apply(this, arguments);\n }\n\n attributes = attributes || {};\n if (options && options.parse) {\n attributes = this.parse(attributes);\n attributes = this._mergeMagicFields(attributes);\n }\n var defaults = getValue(this, 'defaults');\n if (defaults) {\n attributes = _.extend({}, defaults, attributes);\n }\n if (options && options.collection) {\n this.collection = options.collection;\n }\n\n this._serverData = {}; // The last known data for this object from cloud.\n this._opSetQueue = [{}]; // List of sets of changes to the data.\n this._flags = {};\n this.attributes = {}; // The best estimate of this's current data.\n\n this._hashedJSON = {}; // Hash of values of containers at last save.\n this._escapedAttributes = {};\n this.cid = _.uniqueId('c');\n this.changed = {};\n this._silent = {};\n this._pending = {};\n this.set(attributes, { silent: true });\n this.changed = {};\n this._silent = {};\n this._pending = {};\n this._hasData = true;\n this._previousAttributes = _.clone(this.attributes);\n this.initialize.apply(this, arguments);\n };\n\n /**\n * @lends AV.Object.prototype\n * @property {String} id The objectId of the AV Object.\n */\n\n /**\n * Saves the given list of AV.Object.\n * If any error is encountered, stops and calls the error handler.\n *\n * @example\n * AV.Object.saveAll([object1, object2, ...]).then(function(list) {\n * // All the objects were saved.\n * }, function(error) {\n * // An error occurred while saving one of the objects.\n * });\n *\n * @param {Array} list A list of AV.Object.\n */\n AV.Object.saveAll = function(list, options) {\n return AV.Object._deepSaveAsync(list, null, options);\n };\n\n /**\n * Fetch the given list of AV.Object.\n *\n * @param {AV.Object[]} objects A list of AV.Object\n * @param {AuthOptions} options\n * @return {Promise.} The given list of AV.Object, updated\n */\n\n AV.Object.fetchAll = (objects, options) =>\n Promise.resolve()\n .then(() =>\n _request(\n 'batch',\n null,\n null,\n 'POST',\n {\n requests: _.map(objects, object => {\n if (!object.className)\n throw new Error('object must have className to fetch');\n if (!object.id) throw new Error('object must have id to fetch');\n if (object.dirty())\n throw new Error('object is modified but not saved');\n return {\n method: 'GET',\n path: `/1.1/classes/${object.className}/${object.id}`,\n };\n }),\n },\n options\n )\n )\n .then(function(response) {\n const results = _.map(objects, function(object, i) {\n if (response[i].success) {\n const fetchedAttrs = object.parse(response[i].success);\n object._cleanupUnsetKeys(fetchedAttrs);\n object._finishFetch(fetchedAttrs);\n return object;\n }\n if (response[i].success === null) {\n return new AVError(AVError.OBJECT_NOT_FOUND, 'Object not found.');\n }\n return new AVError(response[i].error.code, response[i].error.error);\n });\n return handleBatchResults(results);\n });\n\n // Attach all inheritable methods to the AV.Object prototype.\n _.extend(\n AV.Object.prototype,\n AV.Events,\n /** @lends AV.Object.prototype */ {\n _fetchWhenSave: false,\n\n /**\n * Initialize is an empty function by default. Override it with your own\n * initialization logic.\n */\n initialize: function() {},\n\n /**\n * Set whether to enable fetchWhenSave option when updating object.\n * When set true, SDK would fetch the latest object after saving.\n * Default is false.\n *\n * @deprecated use AV.Object#save with options.fetchWhenSave instead\n * @param {boolean} enable true to enable fetchWhenSave option.\n */\n fetchWhenSave: function(enable) {\n console.warn(\n 'AV.Object#fetchWhenSave is deprecated, use AV.Object#save with options.fetchWhenSave instead.'\n );\n if (!_.isBoolean(enable)) {\n throw new Error('Expect boolean value for fetchWhenSave');\n }\n this._fetchWhenSave = enable;\n },\n\n /**\n * Returns the object's objectId.\n * @return {String} the objectId.\n */\n getObjectId: function() {\n return this.id;\n },\n\n /**\n * Returns the object's createdAt attribute.\n * @return {Date}\n */\n getCreatedAt: function() {\n return this.createdAt;\n },\n\n /**\n * Returns the object's updatedAt attribute.\n * @return {Date}\n */\n getUpdatedAt: function() {\n return this.updatedAt;\n },\n\n /**\n * Returns a JSON version of the object.\n * @return {Object}\n */\n toJSON: function(key, holder, seenObjects = []) {\n return this._toFullJSON(seenObjects, false);\n },\n\n /**\n * Returns a JSON version of the object with meta data.\n * Inverse to {@link AV.parseJSON}\n * @since 3.0.0\n * @return {Object}\n */\n toFullJSON(seenObjects = []) {\n return this._toFullJSON(seenObjects);\n },\n\n _toFullJSON: function(seenObjects, full = true) {\n var json = _.clone(this.attributes);\n if (_.isArray(seenObjects)) {\n var newSeenObjects = seenObjects.concat(this);\n }\n AV._objectEach(json, function(val, key) {\n json[key] = AV._encode(val, newSeenObjects, undefined, full);\n });\n AV._objectEach(this._operations, function(val, key) {\n json[key] = val;\n });\n\n if (_.has(this, 'id')) {\n json.objectId = this.id;\n }\n ['createdAt', 'updatedAt'].forEach(key => {\n if (_.has(this, key)) {\n const val = this[key];\n json[key] = _.isDate(val) ? val.toJSON() : val;\n }\n });\n if (full) {\n json.__type = 'Object';\n if (_.isArray(seenObjects) && seenObjects.length)\n json.__type = 'Pointer';\n json.className = this.className;\n }\n return json;\n },\n\n /**\n * Updates _hashedJSON to reflect the current state of this object.\n * Adds any changed hash values to the set of pending changes.\n * @private\n */\n _refreshCache: function() {\n var self = this;\n if (self._refreshingCache) {\n return;\n }\n self._refreshingCache = true;\n AV._objectEach(this.attributes, function(value, key) {\n if (value instanceof AV.Object) {\n value._refreshCache();\n } else if (_.isObject(value)) {\n if (self._resetCacheForKey(key)) {\n self.set(key, new AV.Op.Set(value), { silent: true });\n }\n }\n });\n delete self._refreshingCache;\n },\n\n /**\n * Returns true if this object has been modified since its last\n * save/refresh. If an attribute is specified, it returns true only if that\n * particular attribute has been modified since the last save/refresh.\n * @param {String} attr An attribute name (optional).\n * @return {Boolean}\n */\n dirty: function(attr) {\n this._refreshCache();\n\n var currentChanges = _.last(this._opSetQueue);\n\n if (attr) {\n return currentChanges[attr] ? true : false;\n }\n if (!this.id) {\n return true;\n }\n if (_.keys(currentChanges).length > 0) {\n return true;\n }\n return false;\n },\n\n /**\n * Returns the keys of the modified attribute since its last save/refresh.\n * @return {String[]}\n */\n dirtyKeys: function() {\n this._refreshCache();\n var currentChanges = _.last(this._opSetQueue);\n return _.keys(currentChanges);\n },\n\n /**\n * Gets a Pointer referencing this Object.\n * @private\n */\n _toPointer: function() {\n // if (!this.id) {\n // throw new Error(\"Can't serialize an unsaved AV.Object\");\n // }\n return {\n __type: 'Pointer',\n className: this.className,\n objectId: this.id,\n };\n },\n\n /**\n * Gets the value of an attribute.\n * @param {String} attr The string name of an attribute.\n */\n get: function(attr) {\n switch (attr) {\n case 'objectId':\n return this.id;\n case 'createdAt':\n case 'updatedAt':\n return this[attr];\n default:\n return this.attributes[attr];\n }\n },\n\n /**\n * Gets a relation on the given class for the attribute.\n * @param {String} attr The attribute to get the relation for.\n * @return {AV.Relation}\n */\n relation: function(attr) {\n var value = this.get(attr);\n if (value) {\n if (!(value instanceof AV.Relation)) {\n throw new Error('Called relation() on non-relation field ' + attr);\n }\n value._ensureParentAndKey(this, attr);\n return value;\n } else {\n return new AV.Relation(this, attr);\n }\n },\n\n /**\n * Gets the HTML-escaped value of an attribute.\n */\n escape: function(attr) {\n var html = this._escapedAttributes[attr];\n if (html) {\n return html;\n }\n var val = this.attributes[attr];\n var escaped;\n if (isNullOrUndefined(val)) {\n escaped = '';\n } else {\n escaped = _.escape(val.toString());\n }\n this._escapedAttributes[attr] = escaped;\n return escaped;\n },\n\n /**\n * Returns true if the attribute contains a value that is not\n * null or undefined.\n * @param {String} attr The string name of the attribute.\n * @return {Boolean}\n */\n has: function(attr) {\n return !isNullOrUndefined(this.attributes[attr]);\n },\n\n /**\n * Pulls \"special\" fields like objectId, createdAt, etc. out of attrs\n * and puts them on \"this\" directly. Removes them from attrs.\n * @param attrs - A dictionary with the data for this AV.Object.\n * @private\n */\n _mergeMagicFields: function(attrs) {\n // Check for changes of magic fields.\n var model = this;\n var specialFields = ['objectId', 'createdAt', 'updatedAt'];\n AV._arrayEach(specialFields, function(attr) {\n if (attrs[attr]) {\n if (attr === 'objectId') {\n model.id = attrs[attr];\n } else if (\n (attr === 'createdAt' || attr === 'updatedAt') &&\n !_.isDate(attrs[attr])\n ) {\n model[attr] = AV._parseDate(attrs[attr]);\n } else {\n model[attr] = attrs[attr];\n }\n delete attrs[attr];\n }\n });\n return attrs;\n },\n\n /**\n * Returns the json to be sent to the server.\n * @private\n */\n _startSave: function() {\n this._opSetQueue.push({});\n },\n\n /**\n * Called when a save fails because of an error. Any changes that were part\n * of the save need to be merged with changes made after the save. This\n * might throw an exception is you do conflicting operations. For example,\n * if you do:\n * object.set(\"foo\", \"bar\");\n * object.set(\"invalid field name\", \"baz\");\n * object.save();\n * object.increment(\"foo\");\n * then this will throw when the save fails and the client tries to merge\n * \"bar\" with the +1.\n * @private\n */\n _cancelSave: function() {\n var failedChanges = _.first(this._opSetQueue);\n this._opSetQueue = _.rest(this._opSetQueue);\n var nextChanges = _.first(this._opSetQueue);\n AV._objectEach(failedChanges, function(op, key) {\n var op1 = failedChanges[key];\n var op2 = nextChanges[key];\n if (op1 && op2) {\n nextChanges[key] = op2._mergeWithPrevious(op1);\n } else if (op1) {\n nextChanges[key] = op1;\n }\n });\n this._saving = this._saving - 1;\n },\n\n /**\n * Called when a save completes successfully. This merges the changes that\n * were saved into the known server data, and overrides it with any data\n * sent directly from the server.\n * @private\n */\n _finishSave: function(serverData) {\n // Grab a copy of any object referenced by this object. These instances\n // may have already been fetched, and we don't want to lose their data.\n // Note that doing it like this means we will unify separate copies of the\n // same object, but that's a risk we have to take.\n var fetchedObjects = {};\n AV._traverse(this.attributes, function(object) {\n if (object instanceof AV.Object && object.id && object._hasData) {\n fetchedObjects[object.id] = object;\n }\n });\n\n var savedChanges = _.first(this._opSetQueue);\n this._opSetQueue = _.rest(this._opSetQueue);\n this._applyOpSet(savedChanges, this._serverData);\n this._mergeMagicFields(serverData);\n var self = this;\n AV._objectEach(serverData, function(value, key) {\n self._serverData[key] = AV._decode(value, key);\n\n // Look for any objects that might have become unfetched and fix them\n // by replacing their values with the previously observed values.\n var fetched = AV._traverse(self._serverData[key], function(object) {\n if (object instanceof AV.Object && fetchedObjects[object.id]) {\n return fetchedObjects[object.id];\n }\n });\n if (fetched) {\n self._serverData[key] = fetched;\n }\n });\n this._rebuildAllEstimatedData();\n const opSetQueue = this._opSetQueue.map(_.clone);\n this._refreshCache();\n this._opSetQueue = opSetQueue;\n this._saving = this._saving - 1;\n },\n\n /**\n * Called when a fetch or login is complete to set the known server data to\n * the given object.\n * @private\n */\n _finishFetch: function(serverData, hasData) {\n // Clear out any changes the user might have made previously.\n this._opSetQueue = [{}];\n\n // Bring in all the new server data.\n this._mergeMagicFields(serverData);\n var self = this;\n AV._objectEach(serverData, function(value, key) {\n self._serverData[key] = AV._decode(value, key);\n });\n\n // Refresh the attributes.\n this._rebuildAllEstimatedData();\n\n // Clear out the cache of mutable containers.\n this._refreshCache();\n this._opSetQueue = [{}];\n\n this._hasData = hasData;\n },\n\n /**\n * Applies the set of AV.Op in opSet to the object target.\n * @private\n */\n _applyOpSet: function(opSet, target) {\n var self = this;\n AV._objectEach(opSet, function(change, key) {\n const [value, actualTarget, actualKey] = findValue(target, key);\n setValue(target, key, change._estimate(value, self, key));\n if (actualTarget && actualTarget[actualKey] === AV.Op._UNSET) {\n delete actualTarget[actualKey];\n }\n });\n },\n\n /**\n * Replaces the cached value for key with the current value.\n * Returns true if the new value is different than the old value.\n * @private\n */\n _resetCacheForKey: function(key) {\n var value = this.attributes[key];\n if (\n _.isObject(value) &&\n !(value instanceof AV.Object) &&\n !(value instanceof AV.File)\n ) {\n var json = JSON.stringify(recursiveToPointer(value));\n if (this._hashedJSON[key] !== json) {\n var wasSet = !!this._hashedJSON[key];\n this._hashedJSON[key] = json;\n return wasSet;\n }\n }\n return false;\n },\n\n /**\n * Populates attributes[key] by starting with the last known data from the\n * server, and applying all of the local changes that have been made to that\n * key since then.\n * @private\n */\n _rebuildEstimatedDataForKey: function(key) {\n var self = this;\n delete this.attributes[key];\n if (this._serverData[key]) {\n this.attributes[key] = this._serverData[key];\n }\n AV._arrayEach(this._opSetQueue, function(opSet) {\n var op = opSet[key];\n if (op) {\n const [value, actualTarget, actualKey, firstKey] = findValue(\n self.attributes,\n key\n );\n setValue(self.attributes, key, op._estimate(value, self, key));\n if (actualTarget && actualTarget[actualKey] === AV.Op._UNSET) {\n delete actualTarget[actualKey];\n }\n self._resetCacheForKey(firstKey);\n }\n });\n },\n\n /**\n * Populates attributes by starting with the last known data from the\n * server, and applying all of the local changes that have been made since\n * then.\n * @private\n */\n _rebuildAllEstimatedData: function() {\n var self = this;\n\n var previousAttributes = _.clone(this.attributes);\n\n this.attributes = _.clone(this._serverData);\n AV._arrayEach(this._opSetQueue, function(opSet) {\n self._applyOpSet(opSet, self.attributes);\n AV._objectEach(opSet, function(op, key) {\n self._resetCacheForKey(key);\n });\n });\n\n // Trigger change events for anything that changed because of the fetch.\n AV._objectEach(previousAttributes, function(oldValue, key) {\n if (self.attributes[key] !== oldValue) {\n self.trigger('change:' + key, self, self.attributes[key], {});\n }\n });\n AV._objectEach(this.attributes, function(newValue, key) {\n if (!_.has(previousAttributes, key)) {\n self.trigger('change:' + key, self, newValue, {});\n }\n });\n },\n\n /**\n * Sets a hash of model attributes on the object, firing\n * \"change\" unless you choose to silence it.\n *\n *
You can call it with an object containing keys and values, or with one\n * key and value. For example:
\n *\n * @example\n * gameTurn.set({\n * player: player1,\n * diceRoll: 2\n * });\n *\n * game.set(\"currentPlayer\", player2);\n *\n * game.set(\"finished\", true);\n *\n * @param {String} key The key to set.\n * @param {Any} value The value to give it.\n * @param {Object} [options]\n * @param {Boolean} [options.silent]\n * @return {AV.Object} self if succeeded, throws if the value is not valid.\n * @see AV.Object#validate\n */\n set: function(key, value, options) {\n var attrs;\n if (_.isObject(key) || isNullOrUndefined(key)) {\n attrs = _.mapObject(key, function(v, k) {\n checkReservedKey(k);\n return AV._decode(v, k);\n });\n options = value;\n } else {\n attrs = {};\n checkReservedKey(key);\n attrs[key] = AV._decode(value, key);\n }\n\n // Extract attributes and options.\n options = options || {};\n if (!attrs) {\n return this;\n }\n if (attrs instanceof AV.Object) {\n attrs = attrs.attributes;\n }\n\n // If the unset option is used, every attribute should be a Unset.\n if (options.unset) {\n AV._objectEach(attrs, function(unused_value, key) {\n attrs[key] = new AV.Op.Unset();\n });\n }\n\n // Apply all the attributes to get the estimated values.\n var dataToValidate = _.clone(attrs);\n var self = this;\n AV._objectEach(dataToValidate, function(value, key) {\n if (value instanceof AV.Op) {\n dataToValidate[key] = value._estimate(\n self.attributes[key],\n self,\n key\n );\n if (dataToValidate[key] === AV.Op._UNSET) {\n delete dataToValidate[key];\n }\n }\n });\n\n // Run validation.\n this._validate(attrs, options);\n\n options.changes = {};\n var escaped = this._escapedAttributes;\n\n // Update attributes.\n AV._arrayEach(_.keys(attrs), function(attr) {\n var val = attrs[attr];\n\n // If this is a relation object we need to set the parent correctly,\n // since the location where it was parsed does not have access to\n // this object.\n if (val instanceof AV.Relation) {\n val.parent = self;\n }\n\n if (!(val instanceof AV.Op)) {\n val = new AV.Op.Set(val);\n }\n\n // See if this change will actually have any effect.\n var isRealChange = true;\n if (\n val instanceof AV.Op.Set &&\n _.isEqual(self.attributes[attr], val.value)\n ) {\n isRealChange = false;\n }\n\n if (isRealChange) {\n delete escaped[attr];\n if (options.silent) {\n self._silent[attr] = true;\n } else {\n options.changes[attr] = true;\n }\n }\n\n var currentChanges = _.last(self._opSetQueue);\n currentChanges[attr] = val._mergeWithPrevious(currentChanges[attr]);\n self._rebuildEstimatedDataForKey(attr);\n\n if (isRealChange) {\n self.changed[attr] = self.attributes[attr];\n if (!options.silent) {\n self._pending[attr] = true;\n }\n } else {\n delete self.changed[attr];\n delete self._pending[attr];\n }\n });\n\n if (!options.silent) {\n this.change(options);\n }\n return this;\n },\n\n /**\n * Remove an attribute from the model, firing \"change\" unless\n * you choose to silence it. This is a noop if the attribute doesn't\n * exist.\n * @param key {String} The key.\n */\n unset: function(attr, options) {\n options = options || {};\n options.unset = true;\n return this.set(attr, null, options);\n },\n\n /**\n * Atomically increments the value of the given attribute the next time the\n * object is saved. If no amount is specified, 1 is used by default.\n *\n * @param key {String} The key.\n * @param amount {Number} The amount to increment by.\n */\n increment: function(attr, amount) {\n if (_.isUndefined(amount) || _.isNull(amount)) {\n amount = 1;\n }\n return this.set(attr, new AV.Op.Increment(amount));\n },\n\n /**\n * Atomically add an object to the end of the array associated with a given\n * key.\n * @param key {String} The key.\n * @param item {} The item to add.\n */\n add: function(attr, item) {\n return this.set(attr, new AV.Op.Add(ensureArray(item)));\n },\n\n /**\n * Atomically add an object to the array associated with a given key, only\n * if it is not already present in the array. The position of the insert is\n * not guaranteed.\n *\n * @param key {String} The key.\n * @param item {} The object to add.\n */\n addUnique: function(attr, item) {\n return this.set(attr, new AV.Op.AddUnique(ensureArray(item)));\n },\n\n /**\n * Atomically remove all instances of an object from the array associated\n * with a given key.\n *\n * @param key {String} The key.\n * @param item {} The object to remove.\n */\n remove: function(attr, item) {\n return this.set(attr, new AV.Op.Remove(ensureArray(item)));\n },\n\n /**\n * Atomically apply a \"bit and\" operation on the value associated with a\n * given key.\n *\n * @param key {String} The key.\n * @param value {Number} The value to apply.\n */\n bitAnd(attr, value) {\n return this.set(attr, new AV.Op.BitAnd(value));\n },\n\n /**\n * Atomically apply a \"bit or\" operation on the value associated with a\n * given key.\n *\n * @param key {String} The key.\n * @param value {Number} The value to apply.\n */\n bitOr(attr, value) {\n return this.set(attr, new AV.Op.BitOr(value));\n },\n\n /**\n * Atomically apply a \"bit xor\" operation on the value associated with a\n * given key.\n *\n * @param key {String} The key.\n * @param value {Number} The value to apply.\n */\n bitXor(attr, value) {\n return this.set(attr, new AV.Op.BitXor(value));\n },\n\n /**\n * Returns an instance of a subclass of AV.Op describing what kind of\n * modification has been performed on this field since the last time it was\n * saved. For example, after calling object.increment(\"x\"), calling\n * object.op(\"x\") would return an instance of AV.Op.Increment.\n *\n * @param key {String} The key.\n * @returns {AV.Op} The operation, or undefined if none.\n */\n op: function(attr) {\n return _.last(this._opSetQueue)[attr];\n },\n\n /**\n * Clear all attributes on the model, firing \"change\" unless\n * you choose to silence it.\n */\n clear: function(options) {\n options = options || {};\n options.unset = true;\n var keysToClear = _.extend(this.attributes, this._operations);\n return this.set(keysToClear, options);\n },\n\n /**\n * Clears any (or specific) changes to the model made since the last save.\n * @param {string|string[]} [keys] specify keys to revert.\n */\n revert(keys) {\n const lastOp = _.last(this._opSetQueue);\n const _keys = ensureArray(keys || _.keys(lastOp));\n _keys.forEach(key => {\n delete lastOp[key];\n });\n this._rebuildAllEstimatedData();\n return this;\n },\n\n /**\n * Returns a JSON-encoded set of operations to be sent with the next save\n * request.\n * @private\n */\n _getSaveJSON: function() {\n var json = _.clone(_.first(this._opSetQueue));\n AV._objectEach(json, function(op, key) {\n json[key] = op.toJSON();\n });\n return json;\n },\n\n /**\n * Returns true if this object can be serialized for saving.\n * @private\n */\n _canBeSerialized: function() {\n return AV.Object._canBeSerializedAsValue(this.attributes);\n },\n\n /**\n * Fetch the model from the server. If the server's representation of the\n * model differs from its current attributes, they will be overriden,\n * triggering a \"change\" event.\n * @param {Object} fetchOptions Optional options to set 'keys',\n * 'include' and 'includeACL' option.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled when the fetch\n * completes.\n */\n fetch: function(fetchOptions = {}, options) {\n if (!this.id) {\n throw new Error('Cannot fetch unsaved object');\n }\n var self = this;\n var request = _request(\n 'classes',\n this.className,\n this.id,\n 'GET',\n transformFetchOptions(fetchOptions),\n options\n );\n return request.then(function(response) {\n const fetchedAttrs = self.parse(response);\n self._cleanupUnsetKeys(\n fetchedAttrs,\n fetchOptions.keys\n ? ensureArray(fetchOptions.keys)\n .join(',')\n .split(',')\n : undefined\n );\n self._finishFetch(fetchedAttrs, true);\n return self;\n });\n },\n\n _cleanupUnsetKeys(fetchedAttrs, fetchedKeys = _.keys(this._serverData)) {\n _.forEach(fetchedKeys, key => {\n if (fetchedAttrs[key] === undefined) delete this._serverData[key];\n });\n },\n\n /**\n * Set a hash of model attributes, and save the model to the server.\n * updatedAt will be updated when the request returns.\n * You can either call it as:
\n * object.save();
\n * or
\n * object.save(null, options);
\n * or
\n * object.save(attrs, options);
\n * or
\n * object.save(key, value, options);
\n *\n * @example\n * gameTurn.save({\n * player: \"Jake Cutter\",\n * diceRoll: 2\n * }).then(function(gameTurnAgain) {\n * // The save was successful.\n * }, function(error) {\n * // The save failed. Error is an instance of AVError.\n * });\n *\n * @param {AuthOptions} options AuthOptions plus:\n * @param {Boolean} options.fetchWhenSave fetch and update object after save succeeded\n * @param {AV.Query} options.query Save object only when it matches the query\n * @return {Promise} A promise that is fulfilled when the save\n * completes.\n * @see AVError\n */\n save: function(arg1, arg2, arg3) {\n var attrs, current, options;\n if (_.isObject(arg1) || isNullOrUndefined(arg1)) {\n attrs = arg1;\n options = arg2;\n } else {\n attrs = {};\n attrs[arg1] = arg2;\n options = arg3;\n }\n\n options = _.clone(options) || {};\n if (options.wait) {\n current = _.clone(this.attributes);\n }\n\n var setOptions = _.clone(options) || {};\n if (setOptions.wait) {\n setOptions.silent = true;\n }\n if (attrs) {\n this.set(attrs, setOptions);\n }\n\n var model = this;\n\n var unsavedChildren = [];\n var unsavedFiles = [];\n AV.Object._findUnsavedChildren(model, unsavedChildren, unsavedFiles);\n if (unsavedChildren.length + unsavedFiles.length > 1) {\n return AV.Object._deepSaveAsync(this, model, options);\n }\n\n this._startSave();\n this._saving = (this._saving || 0) + 1;\n\n this._allPreviousSaves = this._allPreviousSaves || Promise.resolve();\n this._allPreviousSaves = this._allPreviousSaves\n .catch(e => {})\n .then(function() {\n var method = model.id ? 'PUT' : 'POST';\n\n var json = model._getSaveJSON();\n var query = {};\n\n if (model._fetchWhenSave || options.fetchWhenSave) {\n query['new'] = 'true';\n }\n // user login option\n if (options._failOnNotExist) {\n query.failOnNotExist = 'true';\n }\n\n if (options.query) {\n var queryParams;\n if (typeof options.query._getParams === 'function') {\n queryParams = options.query._getParams();\n if (queryParams) {\n query.where = queryParams.where;\n }\n }\n if (!query.where) {\n var error = new Error('options.query is not an AV.Query');\n throw error;\n }\n }\n\n _.extend(json, model._flags);\n\n var route = 'classes';\n var className = model.className;\n if (model.className === '_User' && !model.id) {\n // Special-case user sign-up.\n route = 'users';\n className = null;\n }\n //hook makeRequest in options.\n var makeRequest = options._makeRequest || _request;\n var requestPromise = makeRequest(\n route,\n className,\n model.id,\n method,\n json,\n options,\n query\n );\n\n requestPromise = requestPromise.then(\n function(resp) {\n var serverAttrs = model.parse(resp);\n if (options.wait) {\n serverAttrs = _.extend(attrs || {}, serverAttrs);\n }\n model._finishSave(serverAttrs);\n if (options.wait) {\n model.set(current, setOptions);\n }\n return model;\n },\n function(error) {\n model._cancelSave();\n throw error;\n }\n );\n\n return requestPromise;\n });\n return this._allPreviousSaves;\n },\n\n /**\n * Destroy this model on the server if it was already persisted.\n * Optimistically removes the model from its collection, if it has one.\n * @param {AuthOptions} options AuthOptions plus:\n * @param {Boolean} [options.wait] wait for the server to respond\n * before removal.\n *\n * @return {Promise} A promise that is fulfilled when the destroy\n * completes.\n */\n destroy: function(options) {\n options = options || {};\n var model = this;\n\n var triggerDestroy = function() {\n model.trigger('destroy', model, model.collection, options);\n };\n\n if (!this.id) {\n return triggerDestroy();\n }\n\n if (!options.wait) {\n triggerDestroy();\n }\n\n var request = _request(\n 'classes',\n this.className,\n this.id,\n 'DELETE',\n this._flags,\n options\n );\n return request.then(function() {\n if (options.wait) {\n triggerDestroy();\n }\n return model;\n });\n },\n\n /**\n * Converts a response into the hash of attributes to be set on the model.\n * @ignore\n */\n parse: function(resp) {\n var output = _.clone(resp);\n ['createdAt', 'updatedAt'].forEach(function(key) {\n if (output[key]) {\n output[key] = AV._parseDate(output[key]);\n }\n });\n if (output.createdAt && !output.updatedAt) {\n output.updatedAt = output.createdAt;\n }\n return output;\n },\n\n /**\n * Creates a new model with identical attributes to this one.\n * @return {AV.Object}\n */\n clone: function() {\n return new this.constructor(this.attributes);\n },\n\n /**\n * Returns true if this object has never been saved to AV.\n * @return {Boolean}\n */\n isNew: function() {\n return !this.id;\n },\n\n /**\n * Call this method to manually fire a `\"change\"` event for this model and\n * a `\"change:attribute\"` event for each changed attribute.\n * Calling this will cause all objects observing the model to update.\n */\n change: function(options) {\n options = options || {};\n var changing = this._changing;\n this._changing = true;\n\n // Silent changes become pending changes.\n var self = this;\n AV._objectEach(this._silent, function(attr) {\n self._pending[attr] = true;\n });\n\n // Silent changes are triggered.\n var changes = _.extend({}, options.changes, this._silent);\n this._silent = {};\n AV._objectEach(changes, function(unused_value, attr) {\n self.trigger('change:' + attr, self, self.get(attr), options);\n });\n if (changing) {\n return this;\n }\n\n // This is to get around lint not letting us make a function in a loop.\n var deleteChanged = function(value, attr) {\n if (!self._pending[attr] && !self._silent[attr]) {\n delete self.changed[attr];\n }\n };\n\n // Continue firing `\"change\"` events while there are pending changes.\n while (!_.isEmpty(this._pending)) {\n this._pending = {};\n this.trigger('change', this, options);\n // Pending and silent changes still remain.\n AV._objectEach(this.changed, deleteChanged);\n self._previousAttributes = _.clone(this.attributes);\n }\n\n this._changing = false;\n return this;\n },\n\n /**\n * Gets the previous value of an attribute, recorded at the time the last\n * \"change\" event was fired.\n * @param {String} attr Name of the attribute to get.\n */\n previous: function(attr) {\n if (!arguments.length || !this._previousAttributes) {\n return null;\n }\n return this._previousAttributes[attr];\n },\n\n /**\n * Gets all of the attributes of the model at the time of the previous\n * \"change\" event.\n * @return {Object}\n */\n previousAttributes: function() {\n return _.clone(this._previousAttributes);\n },\n\n /**\n * Checks if the model is currently in a valid state. It's only possible to\n * get into an *invalid* state if you're using silent changes.\n * @return {Boolean}\n */\n isValid: function() {\n try {\n this.validate(this.attributes);\n } catch (error) {\n return false;\n }\n return true;\n },\n\n /**\n * You should not call this function directly unless you subclass\n * AV.Object, in which case you can override this method\n * to provide additional validation on set and\n * save. Your implementation should throw an Error if\n * the attrs is invalid\n *\n * @param {Object} attrs The current data to validate.\n * @see AV.Object#set\n */\n validate: function(attrs) {\n if (_.has(attrs, 'ACL') && !(attrs.ACL instanceof AV.ACL)) {\n throw new AVError(AVError.OTHER_CAUSE, 'ACL must be a AV.ACL.');\n }\n },\n\n /**\n * Run validation against a set of incoming attributes, returning `true`\n * if all is well. If a specific `error` callback has been passed,\n * call that instead of firing the general `\"error\"` event.\n * @private\n */\n _validate: function(attrs, options) {\n if (options.silent || !this.validate) {\n return;\n }\n attrs = _.extend({}, this.attributes, attrs);\n this.validate(attrs);\n },\n\n /**\n * Returns the ACL for this object.\n * @returns {AV.ACL} An instance of AV.ACL.\n * @see AV.Object#get\n */\n getACL: function() {\n return this.get('ACL');\n },\n\n /**\n * Sets the ACL to be used for this object.\n * @param {AV.ACL} acl An instance of AV.ACL.\n * @param {Object} options Optional Backbone-like options object to be\n * passed in to set.\n * @return {AV.Object} self\n * @see AV.Object#set\n */\n setACL: function(acl, options) {\n return this.set('ACL', acl, options);\n },\n\n disableBeforeHook: function() {\n this.ignoreHook('beforeSave');\n this.ignoreHook('beforeUpdate');\n this.ignoreHook('beforeDelete');\n },\n\n disableAfterHook: function() {\n this.ignoreHook('afterSave');\n this.ignoreHook('afterUpdate');\n this.ignoreHook('afterDelete');\n },\n\n ignoreHook: function(hookName) {\n if (\n !_.contains(\n [\n 'beforeSave',\n 'afterSave',\n 'beforeUpdate',\n 'afterUpdate',\n 'beforeDelete',\n 'afterDelete',\n ],\n hookName\n )\n ) {\n throw new Error('Unsupported hookName: ' + hookName);\n }\n\n if (!AV.hookKey) {\n throw new Error('ignoreHook required hookKey');\n }\n\n if (!this._flags.__ignore_hooks) {\n this._flags.__ignore_hooks = [];\n }\n\n this._flags.__ignore_hooks.push(hookName);\n },\n }\n );\n\n /**\n * Creates an instance of a subclass of AV.Object for the give classname\n * and id.\n * @param {String|Function} class the className or a subclass of AV.Object.\n * @param {String} id The object id of this model.\n * @return {AV.Object} A new subclass instance of AV.Object.\n */\n AV.Object.createWithoutData = (klass, id, hasData) => {\n let _klass;\n if (_.isString(klass)) {\n _klass = AV.Object._getSubclass(klass);\n } else if (klass.prototype && klass.prototype instanceof AV.Object) {\n _klass = klass;\n } else {\n throw new Error('class must be a string or a subclass of AV.Object.');\n }\n if (!id) {\n throw new TypeError('The objectId must be provided');\n }\n const object = new _klass();\n object.id = id;\n object._hasData = hasData;\n return object;\n };\n /**\n * Delete objects in batch.\n * @param {AV.Object[]} objects The AV.Object array to be deleted.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled when the save\n * completes.\n */\n AV.Object.destroyAll = function(objects, options = {}) {\n if (!objects || objects.length === 0) {\n return Promise.resolve();\n }\n const objectsByClassNameAndFlags = _.groupBy(objects, object =>\n JSON.stringify({\n className: object.className,\n flags: object._flags,\n })\n );\n const body = {\n requests: _.map(objectsByClassNameAndFlags, objects => {\n const ids = _.map(objects, 'id').join(',');\n return {\n method: 'DELETE',\n path: `/1.1/classes/${objects[0].className}/${ids}`,\n body: objects[0]._flags,\n };\n }),\n };\n return _request('batch', null, null, 'POST', body, options).then(\n response => {\n const firstError = _.find(response, result => !result.success);\n if (firstError)\n throw new AVError(firstError.error.code, firstError.error.error);\n return undefined;\n }\n );\n };\n\n /**\n * Returns the appropriate subclass for making new instances of the given\n * className string.\n * @private\n */\n AV.Object._getSubclass = function(className) {\n if (!_.isString(className)) {\n throw new Error('AV.Object._getSubclass requires a string argument.');\n }\n var ObjectClass = AV.Object._classMap[className];\n if (!ObjectClass) {\n ObjectClass = AV.Object.extend(className);\n AV.Object._classMap[className] = ObjectClass;\n }\n return ObjectClass;\n };\n\n /**\n * Creates an instance of a subclass of AV.Object for the given classname.\n * @private\n */\n AV.Object._create = function(className, attributes, options) {\n var ObjectClass = AV.Object._getSubclass(className);\n return new ObjectClass(attributes, options);\n };\n\n // Set up a map of className to class so that we can create new instances of\n // AV Objects from JSON automatically.\n AV.Object._classMap = {};\n\n AV.Object._extend = AV._extend;\n\n /**\n * Creates a new model with defined attributes,\n * It's the same with\n *
\n * new AV.Object(attributes, options);\n *
\n * @param {Object} attributes The initial set of data to store in the object.\n * @param {Object} options A set of Backbone-like options for creating the\n * object. The only option currently supported is \"collection\".\n * @return {AV.Object}\n * @since v0.4.4\n * @see AV.Object\n * @see AV.Object.extend\n */\n AV.Object['new'] = function(attributes, options) {\n return new AV.Object(attributes, options);\n };\n\n /**\n * Creates a new subclass of AV.Object for the given AV class name.\n *\n *
Every extension of a AV class will inherit from the most recent\n * previous extension of that class. When a AV.Object is automatically\n * created by parsing JSON, it will use the most recent extension of that\n * class.
\n *\n * @example\n * var MyClass = AV.Object.extend(\"MyClass\", {\n * // Instance properties\n * }, {\n * // Class properties\n * });\n *\n * @param {String} className The name of the AV class backing this model.\n * @param {Object} protoProps Instance properties to add to instances of the\n * class returned from this method.\n * @param {Object} classProps Class properties to add the class returned from\n * this method.\n * @return {Class} A new subclass of AV.Object.\n */\n AV.Object.extend = function(className, protoProps, classProps) {\n // Handle the case with only two args.\n if (!_.isString(className)) {\n if (className && _.has(className, 'className')) {\n return AV.Object.extend(className.className, className, protoProps);\n } else {\n throw new Error(\n \"AV.Object.extend's first argument should be the className.\"\n );\n }\n }\n\n // If someone tries to subclass \"User\", coerce it to the right type.\n if (className === 'User') {\n className = '_User';\n }\n\n var NewClassObject = null;\n if (_.has(AV.Object._classMap, className)) {\n var OldClassObject = AV.Object._classMap[className];\n // This new subclass has been told to extend both from \"this\" and from\n // OldClassObject. This is multiple inheritance, which isn't supported.\n // For now, let's just pick one.\n if (protoProps || classProps) {\n NewClassObject = OldClassObject._extend(protoProps, classProps);\n } else {\n return OldClassObject;\n }\n } else {\n protoProps = protoProps || {};\n protoProps._className = className;\n NewClassObject = this._extend(protoProps, classProps);\n }\n // Extending a subclass should reuse the classname automatically.\n NewClassObject.extend = function(arg0) {\n if (_.isString(arg0) || (arg0 && _.has(arg0, 'className'))) {\n return AV.Object.extend.apply(NewClassObject, arguments);\n }\n var newArguments = [className].concat(_.toArray(arguments));\n return AV.Object.extend.apply(NewClassObject, newArguments);\n };\n // Add the query property descriptor.\n Object.defineProperty(\n NewClassObject,\n 'query',\n Object.getOwnPropertyDescriptor(AV.Object, 'query')\n );\n NewClassObject['new'] = function(attributes, options) {\n return new NewClassObject(attributes, options);\n };\n AV.Object._classMap[className] = NewClassObject;\n return NewClassObject;\n };\n\n // ES6 class syntax support\n Object.defineProperty(AV.Object.prototype, 'className', {\n get: function() {\n const className =\n this._className ||\n this.constructor._LCClassName ||\n this.constructor.name;\n // If someone tries to subclass \"User\", coerce it to the right type.\n if (className === 'User') {\n return '_User';\n }\n return className;\n },\n });\n\n /**\n * Register a class.\n * If a subclass of AV.Object is defined with your own implement\n * rather then AV.Object.extend, the subclass must be registered.\n * @param {Function} klass A subclass of AV.Object\n * @param {String} [name] Specify the name of the class. Useful when the class might be uglified.\n * @example\n * class Person extend AV.Object {}\n * AV.Object.register(Person);\n */\n AV.Object.register = (klass, name) => {\n if (!(klass.prototype instanceof AV.Object)) {\n throw new Error('registered class is not a subclass of AV.Object');\n }\n const className = name || klass.name;\n if (!className.length) {\n throw new Error('registered class must be named');\n }\n if (name) {\n klass._LCClassName = name;\n }\n AV.Object._classMap[className] = klass;\n };\n\n /**\n * Get a new Query of the current class\n * @name query\n * @memberof AV.Object\n * @type AV.Query\n * @readonly\n * @since v3.1.0\n * @example\n * const Post = AV.Object.extend('Post');\n * Post.query.equalTo('author', 'leancloud').find().then();\n */\n Object.defineProperty(AV.Object, 'query', {\n get() {\n return new AV.Query(this.prototype.className);\n },\n });\n\n AV.Object._findUnsavedChildren = function(objects, children, files) {\n AV._traverse(objects, function(object) {\n if (object instanceof AV.Object) {\n if (object.dirty()) {\n children.push(object);\n }\n return;\n }\n\n if (object instanceof AV.File) {\n if (!object.id) {\n files.push(object);\n }\n return;\n }\n });\n };\n\n AV.Object._canBeSerializedAsValue = function(object) {\n var canBeSerializedAsValue = true;\n\n if (object instanceof AV.Object || object instanceof AV.File) {\n canBeSerializedAsValue = !!object.id;\n } else if (_.isArray(object)) {\n AV._arrayEach(object, function(child) {\n if (!AV.Object._canBeSerializedAsValue(child)) {\n canBeSerializedAsValue = false;\n }\n });\n } else if (_.isObject(object)) {\n AV._objectEach(object, function(child) {\n if (!AV.Object._canBeSerializedAsValue(child)) {\n canBeSerializedAsValue = false;\n }\n });\n }\n\n return canBeSerializedAsValue;\n };\n\n AV.Object._deepSaveAsync = function(object, model, options) {\n var unsavedChildren = [];\n var unsavedFiles = [];\n AV.Object._findUnsavedChildren(object, unsavedChildren, unsavedFiles);\n\n unsavedFiles = _.uniq(unsavedFiles);\n\n var promise = Promise.resolve();\n _.each(unsavedFiles, function(file) {\n promise = promise.then(function() {\n return file.save();\n });\n });\n\n var objects = _.uniq(unsavedChildren);\n var remaining = _.uniq(objects);\n\n return promise\n .then(function() {\n return continueWhile(\n function() {\n return remaining.length > 0;\n },\n function() {\n // Gather up all the objects that can be saved in this batch.\n var batch = [];\n var newRemaining = [];\n AV._arrayEach(remaining, function(object) {\n if (object._canBeSerialized()) {\n batch.push(object);\n } else {\n newRemaining.push(object);\n }\n });\n remaining = newRemaining;\n\n // If we can't save any objects, there must be a circular reference.\n if (batch.length === 0) {\n return Promise.reject(\n new AVError(\n AVError.OTHER_CAUSE,\n 'Tried to save a batch with a cycle.'\n )\n );\n }\n\n // Reserve a spot in every object's save queue.\n var readyToStart = Promise.resolve(\n _.map(batch, function(object) {\n return object._allPreviousSaves || Promise.resolve();\n })\n );\n\n // Save a single batch, whether previous saves succeeded or failed.\n const bathSavePromise = readyToStart.then(() =>\n _request(\n 'batch',\n null,\n null,\n 'POST',\n {\n requests: _.map(batch, function(object) {\n var method = object.id ? 'PUT' : 'POST';\n\n var json = object._getSaveJSON();\n\n _.extend(json, object._flags);\n\n var route = 'classes';\n var className = object.className;\n var path = `/${route}/${className}`;\n if (object.className === '_User' && !object.id) {\n // Special-case user sign-up.\n path = '/users';\n }\n\n var path = `/1.1${path}`;\n if (object.id) {\n path = path + '/' + object.id;\n }\n\n object._startSave();\n\n return {\n method: method,\n path: path,\n body: json,\n params:\n options && options.fetchWhenSave\n ? { fetchWhenSave: true }\n : undefined,\n };\n }),\n },\n options\n ).then(function(response) {\n const results = _.map(batch, function(object, i) {\n if (response[i].success) {\n object._finishSave(object.parse(response[i].success));\n return object;\n }\n object._cancelSave();\n return new AVError(\n response[i].error.code,\n response[i].error.error\n );\n });\n return handleBatchResults(results);\n })\n );\n AV._arrayEach(batch, function(object) {\n object._allPreviousSaves = bathSavePromise;\n });\n return bathSavePromise;\n }\n );\n })\n .then(function() {\n return object;\n });\n };\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/object.js","var arrayWithHoles = require(\"./arrayWithHoles.js\");\n\nvar iterableToArrayLimit = require(\"./iterableToArrayLimit.js\");\n\nvar unsupportedIterableToArray = require(\"./unsupportedIterableToArray.js\");\n\nvar nonIterableRest = require(\"./nonIterableRest.js\");\n\nfunction _slicedToArray(arr, i) {\n return arrayWithHoles(arr) || iterableToArrayLimit(arr, i) || unsupportedIterableToArray(arr, i) || nonIterableRest();\n}\n\nmodule.exports = _slicedToArray, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/helpers/slicedToArray.js\n// module id = 501\n// module chunks = 0 1","var _Array$isArray = require(\"@babel/runtime-corejs3/core-js/array/is-array\");\n\nfunction _arrayWithHoles(arr) {\n if (_Array$isArray(arr)) return arr;\n}\n\nmodule.exports = _arrayWithHoles, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/helpers/arrayWithHoles.js\n// module id = 502\n// module chunks = 0 1","module.exports = require(\"core-js-pure/features/array/is-array\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/core-js/array/is-array.js\n// module id = 503\n// module chunks = 0 1","module.exports = require('../../full/array/is-array');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/features/array/is-array.js\n// module id = 504\n// module chunks = 0 1","var parent = require('../../actual/array/is-array');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/full/array/is-array.js\n// module id = 505\n// module chunks = 0 1","var parent = require('../../stable/array/is-array');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/actual/array/is-array.js\n// module id = 506\n// module chunks = 0 1","var parent = require('../../es/array/is-array');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/stable/array/is-array.js\n// module id = 507\n// module chunks = 0 1","require('../../modules/es.array.is-array');\nvar path = require('../../internals/path');\n\nmodule.exports = path.Array.isArray;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/es/array/is-array.js\n// module id = 508\n// module chunks = 0 1","var $ = require('../internals/export');\nvar isArray = require('../internals/is-array');\n\n// `Array.isArray` method\n// https://tc39.es/ecma262/#sec-array.isarray\n$({ target: 'Array', stat: true }, {\n isArray: isArray\n});\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.array.is-array.js\n// module id = 509\n// module chunks = 0 1","var _Symbol = require(\"@babel/runtime-corejs3/core-js/symbol\");\n\nvar _getIteratorMethod = require(\"@babel/runtime-corejs3/core-js/get-iterator-method\");\n\nfunction _iterableToArrayLimit(arr, i) {\n var _i = arr == null ? null : typeof _Symbol !== \"undefined\" && _getIteratorMethod(arr) || arr[\"@@iterator\"];\n\n if (_i == null) return;\n var _arr = [];\n var _n = true;\n var _d = false;\n\n var _s, _e;\n\n try {\n for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {\n _arr.push(_s.value);\n\n if (i && _arr.length === i) break;\n }\n } catch (err) {\n _d = true;\n _e = err;\n } finally {\n try {\n if (!_n && _i[\"return\"] != null) _i[\"return\"]();\n } finally {\n if (_d) throw _e;\n }\n }\n\n return _arr;\n}\n\nmodule.exports = _iterableToArrayLimit, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/helpers/iterableToArrayLimit.js\n// module id = 510\n// module chunks = 0 1","var _sliceInstanceProperty = require(\"@babel/runtime-corejs3/core-js/instance/slice\");\n\nvar _Array$from = require(\"@babel/runtime-corejs3/core-js/array/from\");\n\nvar arrayLikeToArray = require(\"./arrayLikeToArray.js\");\n\nfunction _unsupportedIterableToArray(o, minLen) {\n var _context;\n\n if (!o) return;\n if (typeof o === \"string\") return arrayLikeToArray(o, minLen);\n\n var n = _sliceInstanceProperty(_context = Object.prototype.toString.call(o)).call(_context, 8, -1);\n\n if (n === \"Object\" && o.constructor) n = o.constructor.name;\n if (n === \"Map\" || n === \"Set\") return _Array$from(o);\n if (n === \"Arguments\" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return arrayLikeToArray(o, minLen);\n}\n\nmodule.exports = _unsupportedIterableToArray, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/helpers/unsupportedIterableToArray.js\n// module id = 511\n// module chunks = 0 1","module.exports = require(\"core-js-pure/features/instance/slice\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/core-js/instance/slice.js\n// module id = 512\n// module chunks = 0 1","module.exports = require('../../full/instance/slice');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/features/instance/slice.js\n// module id = 513\n// module chunks = 0 1","var parent = require('../../actual/instance/slice');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/full/instance/slice.js\n// module id = 514\n// module chunks = 0 1","var parent = require('../../stable/instance/slice');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/actual/instance/slice.js\n// module id = 515\n// module chunks = 0 1","module.exports = require(\"core-js-pure/features/array/from\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/core-js/array/from.js\n// module id = 516\n// module chunks = 0 1","module.exports = require('../../full/array/from');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/features/array/from.js\n// module id = 517\n// module chunks = 0 1","var parent = require('../../actual/array/from');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/full/array/from.js\n// module id = 518\n// module chunks = 0 1","var parent = require('../../stable/array/from');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/actual/array/from.js\n// module id = 519\n// module chunks = 0 1","function _arrayLikeToArray(arr, len) {\n if (len == null || len > arr.length) len = arr.length;\n\n for (var i = 0, arr2 = new Array(len); i < len; i++) {\n arr2[i] = arr[i];\n }\n\n return arr2;\n}\n\nmodule.exports = _arrayLikeToArray, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/helpers/arrayLikeToArray.js\n// module id = 520\n// module chunks = 0 1","function _nonIterableRest() {\n throw new TypeError(\"Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\");\n}\n\nmodule.exports = _nonIterableRest, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/helpers/nonIterableRest.js\n// module id = 521\n// module chunks = 0 1","module.exports = require(\"core-js-pure/stable/object/get-own-property-descriptor\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor.js\n// module id = 522\n// module chunks = 0 1","var parent = require('../../es/object/get-own-property-descriptor');\n\nmodule.exports = parent;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/stable/object/get-own-property-descriptor.js\n// module id = 523\n// module chunks = 0 1","require('../../modules/es.object.get-own-property-descriptor');\nvar path = require('../../internals/path');\n\nvar Object = path.Object;\n\nvar getOwnPropertyDescriptor = module.exports = function getOwnPropertyDescriptor(it, key) {\n return Object.getOwnPropertyDescriptor(it, key);\n};\n\nif (Object.getOwnPropertyDescriptor.sham) getOwnPropertyDescriptor.sham = true;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/es/object/get-own-property-descriptor.js\n// module id = 524\n// module chunks = 0 1","var $ = require('../internals/export');\nvar fails = require('../internals/fails');\nvar toIndexedObject = require('../internals/to-indexed-object');\nvar nativeGetOwnPropertyDescriptor = require('../internals/object-get-own-property-descriptor').f;\nvar DESCRIPTORS = require('../internals/descriptors');\n\nvar FAILS_ON_PRIMITIVES = fails(function () { nativeGetOwnPropertyDescriptor(1); });\nvar FORCED = !DESCRIPTORS || FAILS_ON_PRIMITIVES;\n\n// `Object.getOwnPropertyDescriptor` method\n// https://tc39.es/ecma262/#sec-object.getownpropertydescriptor\n$({ target: 'Object', stat: true, forced: FORCED, sham: !DESCRIPTORS }, {\n getOwnPropertyDescriptor: function getOwnPropertyDescriptor(it, key) {\n return nativeGetOwnPropertyDescriptor(toIndexedObject(it), key);\n }\n});\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/core-js-pure/modules/es.object.get-own-property-descriptor.js\n// module id = 525\n// module chunks = 0 1","const _ = require('underscore');\nconst AVError = require('./error');\n\nmodule.exports = function(AV) {\n AV.Role = AV.Object.extend(\n '_Role',\n /** @lends AV.Role.prototype */ {\n // Instance Methods\n\n /**\n * Represents a Role on the AV server. Roles represent groupings of\n * Users for the purposes of granting permissions (e.g. specifying an ACL\n * for an Object). Roles are specified by their sets of child users and\n * child roles, all of which are granted any permissions that the parent\n * role has.\n *\n *
Roles must have a name (which cannot be changed after creation of the\n * role), and must specify an ACL.
\n * An AV.Role is a local representation of a role persisted to the AV\n * cloud.\n * @class AV.Role\n * @param {String} name The name of the Role to create.\n * @param {AV.ACL} acl The ACL for this role.\n */\n constructor: function(name, acl) {\n if (_.isString(name)) {\n AV.Object.prototype.constructor.call(this, null, null);\n this.setName(name);\n } else {\n AV.Object.prototype.constructor.call(this, name, acl);\n }\n if (acl) {\n if (!(acl instanceof AV.ACL)) {\n throw new TypeError('acl must be an instance of AV.ACL');\n } else {\n this.setACL(acl);\n }\n }\n },\n\n /**\n * Gets the name of the role. You can alternatively call role.get(\"name\")\n *\n * @return {String} the name of the role.\n */\n getName: function() {\n return this.get('name');\n },\n\n /**\n * Sets the name for a role. This value must be set before the role has\n * been saved to the server, and cannot be set once the role has been\n * saved.\n *\n *
\n * A role's name can only contain alphanumeric characters, _, -, and\n * spaces.\n *
\n *\n *
This is equivalent to calling role.set(\"name\", name)
\n *\n * @param {String} name The name of the role.\n */\n setName: function(name, options) {\n return this.set('name', name, options);\n },\n\n /**\n * Gets the AV.Relation for the AV.Users that are direct\n * children of this role. These users are granted any privileges that this\n * role has been granted (e.g. read or write access through ACLs). You can\n * add or remove users from the role through this relation.\n *\n *
This is equivalent to calling role.relation(\"users\")
\n *\n * @return {AV.Relation} the relation for the users belonging to this\n * role.\n */\n getUsers: function() {\n return this.relation('users');\n },\n\n /**\n * Gets the AV.Relation for the AV.Roles that are direct\n * children of this role. These roles' users are granted any privileges that\n * this role has been granted (e.g. read or write access through ACLs). You\n * can add or remove child roles from this role through this relation.\n *\n *
This is equivalent to calling role.relation(\"roles\")
\n *\n * @return {AV.Relation} the relation for the roles belonging to this\n * role.\n */\n getRoles: function() {\n return this.relation('roles');\n },\n\n /**\n * @ignore\n */\n validate: function(attrs, options) {\n if ('name' in attrs && attrs.name !== this.getName()) {\n var newName = attrs.name;\n if (this.id && this.id !== attrs.objectId) {\n // Check to see if the objectId being set matches this.id.\n // This happens during a fetch -- the id is set before calling fetch.\n // Let the name be set in this case.\n return new AVError(\n AVError.OTHER_CAUSE,\n \"A role's name can only be set before it has been saved.\"\n );\n }\n if (!_.isString(newName)) {\n return new AVError(\n AVError.OTHER_CAUSE,\n \"A role's name must be a String.\"\n );\n }\n if (!/^[0-9a-zA-Z\\-_ ]+$/.test(newName)) {\n return new AVError(\n AVError.OTHER_CAUSE,\n \"A role's name can only contain alphanumeric characters, _,\" +\n ' -, and spaces.'\n );\n }\n }\n if (AV.Object.prototype.validate) {\n return AV.Object.prototype.validate.call(this, attrs, options);\n }\n return false;\n },\n }\n );\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/role.js","const _ = require('underscore');\nconst uuid = require('uuid/v4');\nconst AVError = require('./error');\nconst { _request: AVRequest, request } = require('./request');\nconst { getAdapter } = require('./adapter');\n\nconst PLATFORM_ANONYMOUS = 'anonymous';\nconst PLATFORM_QQAPP = 'lc_qqapp';\n\nconst mergeUnionDataIntoAuthData = (defaultUnionIdPlatform = 'weixin') => (\n authData,\n unionId,\n { unionIdPlatform = defaultUnionIdPlatform, asMainAccount = false } = {}\n) => {\n if (typeof unionId !== 'string')\n throw new AVError(AVError.OTHER_CAUSE, 'unionId is not a string');\n if (typeof unionIdPlatform !== 'string')\n throw new AVError(AVError.OTHER_CAUSE, 'unionIdPlatform is not a string');\n\n return _.extend({}, authData, {\n platform: unionIdPlatform,\n unionid: unionId,\n main_account: Boolean(asMainAccount),\n });\n};\n\nmodule.exports = function(AV) {\n /**\n * @class\n *\n *
An AV.User object is a local representation of a user persisted to the\n * LeanCloud server. This class is a subclass of an AV.Object, and retains the\n * same functionality of an AV.Object, but also extends it with various\n * user specific methods, like authentication, signing up, and validation of\n * uniqueness.
\n */\n AV.User = AV.Object.extend(\n '_User',\n /** @lends AV.User.prototype */ {\n // Instance Variables\n _isCurrentUser: false,\n\n // Instance Methods\n\n /**\n * Internal method to handle special fields in a _User response.\n * @private\n */\n _mergeMagicFields: function(attrs) {\n if (attrs.sessionToken) {\n this._sessionToken = attrs.sessionToken;\n delete attrs.sessionToken;\n }\n return AV.User.__super__._mergeMagicFields.call(this, attrs);\n },\n\n /**\n * Removes null values from authData (which exist temporarily for\n * unlinking)\n * @private\n */\n _cleanupAuthData: function() {\n if (!this.isCurrent()) {\n return;\n }\n var authData = this.get('authData');\n if (!authData) {\n return;\n }\n AV._objectEach(this.get('authData'), function(value, key) {\n if (!authData[key]) {\n delete authData[key];\n }\n });\n },\n\n /**\n * Synchronizes authData for all providers.\n * @private\n */\n _synchronizeAllAuthData: function() {\n var authData = this.get('authData');\n if (!authData) {\n return;\n }\n\n var self = this;\n AV._objectEach(this.get('authData'), function(value, key) {\n self._synchronizeAuthData(key);\n });\n },\n\n /**\n * Synchronizes auth data for a provider (e.g. puts the access token in the\n * right place to be used by the Facebook SDK).\n * @private\n */\n _synchronizeAuthData: function(provider) {\n if (!this.isCurrent()) {\n return;\n }\n var authType;\n if (_.isString(provider)) {\n authType = provider;\n provider = AV.User._authProviders[authType];\n } else {\n authType = provider.getAuthType();\n }\n var authData = this.get('authData');\n if (!authData || !provider) {\n return;\n }\n var success = provider.restoreAuthentication(authData[authType]);\n if (!success) {\n this.dissociateAuthData(provider);\n }\n },\n\n _handleSaveResult: function(makeCurrent) {\n // Clean up and synchronize the authData object, removing any unset values\n if (makeCurrent && !AV._config.disableCurrentUser) {\n this._isCurrentUser = true;\n }\n this._cleanupAuthData();\n this._synchronizeAllAuthData();\n // Don't keep the password around.\n delete this._serverData.password;\n this._rebuildEstimatedDataForKey('password');\n this._refreshCache();\n if (\n (makeCurrent || this.isCurrent()) &&\n !AV._config.disableCurrentUser\n ) {\n // Some old version of leanengine-node-sdk will overwrite\n // AV.User._saveCurrentUser which returns no Promise.\n // So we need a Promise wrapper.\n return Promise.resolve(AV.User._saveCurrentUser(this));\n } else {\n return Promise.resolve();\n }\n },\n\n /**\n * Unlike in the Android/iOS SDKs, logInWith is unnecessary, since you can\n * call linkWith on the user (even if it doesn't exist yet on the server).\n * @private\n */\n _linkWith: function(\n provider,\n data,\n { failOnNotExist = false, useMasterKey, sessionToken, user } = {}\n ) {\n var authType;\n if (_.isString(provider)) {\n authType = provider;\n provider = AV.User._authProviders[provider];\n } else {\n authType = provider.getAuthType();\n }\n if (data) {\n return this.save(\n { authData: { [authType]: data } },\n {\n useMasterKey,\n sessionToken,\n user,\n fetchWhenSave: !!this.get('authData'),\n _failOnNotExist: failOnNotExist,\n }\n ).then(function(model) {\n return model._handleSaveResult(true).then(function() {\n return model;\n });\n });\n } else {\n return provider\n .authenticate()\n .then(result => this._linkWith(provider, result));\n }\n },\n\n /**\n * Associate the user with a third party authData.\n * @since 3.3.0\n * @param {Object} authData The response json data returned from third party token, maybe like { openid: 'abc123', access_token: '123abc', expires_in: 1382686496 }\n * @param {string} platform Available platform for sign up.\n * @return {Promise} A promise that is fulfilled with the user when completed.\n * @example user.associateWithAuthData({\n * openid: 'abc123',\n * access_token: '123abc',\n * expires_in: 1382686496\n * }, 'weixin').then(function(user) {\n * //Access user here\n * }).catch(function(error) {\n * //console.error(\"error: \", error);\n * });\n */\n associateWithAuthData(authData, platform) {\n return this._linkWith(platform, authData);\n },\n\n /**\n * Associate the user with a third party authData and unionId.\n * @since 3.5.0\n * @param {Object} authData The response json data returned from third party token, maybe like { openid: 'abc123', access_token: '123abc', expires_in: 1382686496 }\n * @param {string} platform Available platform for sign up.\n * @param {string} unionId\n * @param {Object} [unionLoginOptions]\n * @param {string} [unionLoginOptions.unionIdPlatform = 'weixin'] unionId platform\n * @param {boolean} [unionLoginOptions.asMainAccount = false] If true, the unionId will be associated with the user.\n * @return {Promise} A promise that is fulfilled with the user when completed.\n * @example user.associateWithAuthDataAndUnionId({\n * openid: 'abc123',\n * access_token: '123abc',\n * expires_in: 1382686496\n * }, 'weixin', 'union123', {\n * unionIdPlatform: 'weixin',\n * asMainAccount: true,\n * }).then(function(user) {\n * //Access user here\n * }).catch(function(error) {\n * //console.error(\"error: \", error);\n * });\n */\n associateWithAuthDataAndUnionId(\n authData,\n platform,\n unionId,\n unionOptions\n ) {\n return this._linkWith(\n platform,\n mergeUnionDataIntoAuthData()(authData, unionId, unionOptions)\n );\n },\n\n /**\n * Associate the user with the identity of the current mini-app.\n * @since 4.6.0\n * @param {Object} [authInfo]\n * @param {Object} [option]\n * @param {Boolean} [option.failOnNotExist] If true, the login request will fail when no user matches this authInfo.authData exists.\n * @return {Promise}\n */\n associateWithMiniApp(authInfo, option) {\n if (authInfo === undefined) {\n const getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo().then(authInfo =>\n this._linkWith(authInfo.provider, authInfo.authData, option)\n );\n }\n return this._linkWith(authInfo.provider, authInfo.authData, option);\n },\n\n /**\n * 将用户与 QQ 小程序用户进行关联。适用于为已经在用户系统中存在的用户关联当前使用 QQ 小程序的微信帐号。\n * 仅在 QQ 小程序中可用。\n *\n * @deprecated Please use {@link AV.User#associateWithMiniApp}\n * @since 4.2.0\n * @param {Object} [options]\n * @param {boolean} [options.preferUnionId = false] 如果服务端在登录时获取到了用户的 UnionId,是否将 UnionId 保存在用户账号中。\n * @param {string} [options.unionIdPlatform = 'qq'] (only take effect when preferUnionId) unionId platform\n * @param {boolean} [options.asMainAccount = true] (only take effect when preferUnionId) If true, the unionId will be associated with the user.\n * @return {Promise}\n */\n associateWithQQApp({\n preferUnionId = false,\n unionIdPlatform = 'qq',\n asMainAccount = true,\n } = {}) {\n const getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo({\n preferUnionId,\n asMainAccount,\n platform: unionIdPlatform,\n }).then(authInfo => {\n authInfo.provider = PLATFORM_QQAPP;\n return this.associateWithMiniApp(authInfo);\n });\n },\n\n /**\n * 将用户与微信小程序用户进行关联。适用于为已经在用户系统中存在的用户关联当前使用微信小程序的微信帐号。\n * 仅在微信小程序中可用。\n *\n * @deprecated Please use {@link AV.User#associateWithMiniApp}\n * @since 3.13.0\n * @param {Object} [options]\n * @param {boolean} [options.preferUnionId = false] 当用户满足 {@link https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/union-id.html 获取 UnionId 的条件} 时,是否将 UnionId 保存在用户账号中。\n * @param {string} [options.unionIdPlatform = 'weixin'] (only take effect when preferUnionId) unionId platform\n * @param {boolean} [options.asMainAccount = true] (only take effect when preferUnionId) If true, the unionId will be associated with the user.\n * @return {Promise}\n */\n associateWithWeapp({\n preferUnionId = false,\n unionIdPlatform = 'weixin',\n asMainAccount = true,\n } = {}) {\n const getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo({\n preferUnionId,\n asMainAccount,\n platform: unionIdPlatform,\n }).then(authInfo => this.associateWithMiniApp(authInfo));\n },\n\n /**\n * @deprecated renamed to {@link AV.User#associateWithWeapp}\n * @return {Promise}\n */\n linkWithWeapp(options) {\n console.warn(\n 'DEPRECATED: User#linkWithWeapp 已废弃,请使用 User#associateWithWeapp 代替'\n );\n return this.associateWithWeapp(options);\n },\n\n /**\n * 将用户与 QQ 小程序用户进行关联。适用于为已经在用户系统中存在的用户关联当前使用 QQ 小程序的 QQ 帐号。\n * 仅在 QQ 小程序中可用。\n *\n * @deprecated Please use {@link AV.User#associateWithMiniApp}\n * @since 4.2.0\n * @param {string} unionId\n * @param {Object} [unionOptions]\n * @param {string} [unionOptions.unionIdPlatform = 'qq'] unionId platform\n * @param {boolean} [unionOptions.asMainAccount = false] If true, the unionId will be associated with the user.\n * @return {Promise}\n */\n associateWithQQAppWithUnionId(\n unionId,\n { unionIdPlatform = 'qq', asMainAccount = false } = {}\n ) {\n const getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo({ platform: unionIdPlatform }).then(authInfo => {\n authInfo = AV.User.mergeUnionId(authInfo, unionId, { asMainAccount });\n authInfo.provider = PLATFORM_QQAPP;\n return this.associateWithMiniApp(authInfo);\n });\n },\n\n /**\n * 将用户与微信小程序用户进行关联。适用于为已经在用户系统中存在的用户关联当前使用微信小程序的微信帐号。\n * 仅在微信小程序中可用。\n *\n * @deprecated Please use {@link AV.User#associateWithMiniApp}\n * @since 3.13.0\n * @param {string} unionId\n * @param {Object} [unionOptions]\n * @param {string} [unionOptions.unionIdPlatform = 'weixin'] unionId platform\n * @param {boolean} [unionOptions.asMainAccount = false] If true, the unionId will be associated with the user.\n * @return {Promise}\n */\n associateWithWeappWithUnionId(\n unionId,\n { unionIdPlatform = 'weixin', asMainAccount = false } = {}\n ) {\n const getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo({ platform: unionIdPlatform }).then(authInfo => {\n authInfo = AV.User.mergeUnionId(authInfo, unionId, { asMainAccount });\n return this.associateWithMiniApp(authInfo);\n });\n },\n\n /**\n * Unlinks a user from a service.\n * @param {string} platform\n * @return {Promise}\n * @since 3.3.0\n */\n dissociateAuthData(provider) {\n this.unset(`authData.${provider}`);\n return this.save().then(model =>\n model._handleSaveResult(true).then(() => model)\n );\n },\n\n /**\n * @private\n * @deprecated\n */\n _unlinkFrom(provider) {\n console.warn(\n 'DEPRECATED: User#_unlinkFrom 已废弃,请使用 User#dissociateAuthData 代替'\n );\n return this.dissociateAuthData(provider);\n },\n\n /**\n * Checks whether a user is linked to a service.\n * @private\n */\n _isLinked: function(provider) {\n var authType;\n if (_.isString(provider)) {\n authType = provider;\n } else {\n authType = provider.getAuthType();\n }\n var authData = this.get('authData') || {};\n return !!authData[authType];\n },\n\n /**\n * Checks whether a user is anonymous.\n * @since 3.9.0\n * @return {boolean}\n */\n isAnonymous() {\n return this._isLinked(PLATFORM_ANONYMOUS);\n },\n\n logOut: function() {\n this._logOutWithAll();\n this._isCurrentUser = false;\n },\n\n /**\n * Deauthenticates all providers.\n * @private\n */\n _logOutWithAll: function() {\n var authData = this.get('authData');\n if (!authData) {\n return;\n }\n var self = this;\n AV._objectEach(this.get('authData'), function(value, key) {\n self._logOutWith(key);\n });\n },\n\n /**\n * Deauthenticates a single provider (e.g. removing access tokens from the\n * Facebook SDK).\n * @private\n */\n _logOutWith: function(provider) {\n if (!this.isCurrent()) {\n return;\n }\n if (_.isString(provider)) {\n provider = AV.User._authProviders[provider];\n }\n if (provider && provider.deauthenticate) {\n provider.deauthenticate();\n }\n },\n\n /**\n * Signs up a new user. You should call this instead of save for\n * new AV.Users. This will create a new AV.User on the server, and\n * also persist the session on disk so that you can access the user using\n * current.\n *\n *
A username and password must be set before calling signUp.
\n *\n * @param {Object} attrs Extra fields to set on the new user, or null.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled when the signup\n * finishes.\n * @see AV.User.signUp\n */\n signUp: function(attrs, options) {\n var error;\n\n var username = (attrs && attrs.username) || this.get('username');\n if (!username || username === '') {\n error = new AVError(\n AVError.OTHER_CAUSE,\n 'Cannot sign up user with an empty name.'\n );\n throw error;\n }\n\n var password = (attrs && attrs.password) || this.get('password');\n if (!password || password === '') {\n error = new AVError(\n AVError.OTHER_CAUSE,\n 'Cannot sign up user with an empty password.'\n );\n throw error;\n }\n\n return this.save(attrs, options).then(function(model) {\n if (model.isAnonymous()) {\n model.unset(`authData.${PLATFORM_ANONYMOUS}`);\n model._opSetQueue = [{}];\n }\n return model._handleSaveResult(true).then(function() {\n return model;\n });\n });\n },\n\n /**\n * Signs up a new user with mobile phone and sms code.\n * You should call this instead of save for\n * new AV.Users. This will create a new AV.User on the server, and\n * also persist the session on disk so that you can access the user using\n * current.\n *\n *
A username and password must be set before calling signUp.
\n *\n * @param {Object} attrs Extra fields to set on the new user, or null.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled when the signup\n * finishes.\n * @see AV.User.signUpOrlogInWithMobilePhone\n * @see AV.Cloud.requestSmsCode\n */\n signUpOrlogInWithMobilePhone: function(attrs, options = {}) {\n var error;\n\n var mobilePhoneNumber =\n (attrs && attrs.mobilePhoneNumber) || this.get('mobilePhoneNumber');\n if (!mobilePhoneNumber || mobilePhoneNumber === '') {\n error = new AVError(\n AVError.OTHER_CAUSE,\n 'Cannot sign up or login user by mobilePhoneNumber ' +\n 'with an empty mobilePhoneNumber.'\n );\n throw error;\n }\n\n var smsCode = (attrs && attrs.smsCode) || this.get('smsCode');\n if (!smsCode || smsCode === '') {\n error = new AVError(\n AVError.OTHER_CAUSE,\n 'Cannot sign up or login user by mobilePhoneNumber ' +\n 'with an empty smsCode.'\n );\n throw error;\n }\n\n options._makeRequest = function(route, className, id, method, json) {\n return AVRequest('usersByMobilePhone', null, null, 'POST', json);\n };\n return this.save(attrs, options).then(function(model) {\n delete model.attributes.smsCode;\n delete model._serverData.smsCode;\n return model._handleSaveResult(true).then(function() {\n return model;\n });\n });\n },\n\n /**\n * The same with {@link AV.User.loginWithAuthData}, except that you can set attributes before login.\n * @since 3.7.0\n */\n loginWithAuthData(authData, platform, options) {\n return this._linkWith(platform, authData, options);\n },\n\n /**\n * The same with {@link AV.User.loginWithAuthDataAndUnionId}, except that you can set attributes before login.\n * @since 3.7.0\n */\n loginWithAuthDataAndUnionId(\n authData,\n platform,\n unionId,\n unionLoginOptions\n ) {\n return this.loginWithAuthData(\n mergeUnionDataIntoAuthData()(authData, unionId, unionLoginOptions),\n platform,\n unionLoginOptions\n );\n },\n\n /**\n * The same with {@link AV.User.loginWithWeapp}, except that you can set attributes before login.\n * @deprecated please use {@link AV.User#loginWithMiniApp}\n * @since 3.7.0\n * @param {Object} [options]\n * @param {boolean} [options.failOnNotExist] If true, the login request will fail when no user matches this authData exists.\n * @param {boolean} [options.preferUnionId] 当用户满足 {@link https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/union-id.html 获取 UnionId 的条件} 时,是否使用 UnionId 登录。(since 3.13.0)\n * @param {string} [options.unionIdPlatform = 'weixin'] (only take effect when preferUnionId) unionId platform\n * @param {boolean} [options.asMainAccount = true] (only take effect when preferUnionId) If true, the unionId will be associated with the user.\n * @return {Promise}\n */\n loginWithWeapp({\n preferUnionId = false,\n unionIdPlatform = 'weixin',\n asMainAccount = true,\n failOnNotExist = false,\n useMasterKey,\n sessionToken,\n user,\n } = {}) {\n const getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo({\n preferUnionId,\n asMainAccount,\n platform: unionIdPlatform,\n }).then(authInfo =>\n this.loginWithMiniApp(authInfo, {\n failOnNotExist,\n useMasterKey,\n sessionToken,\n user,\n })\n );\n },\n\n /**\n * The same with {@link AV.User.loginWithWeappWithUnionId}, except that you can set attributes before login.\n * @deprecated please use {@link AV.User#loginWithMiniApp}\n * @since 3.13.0\n */\n loginWithWeappWithUnionId(\n unionId,\n {\n unionIdPlatform = 'weixin',\n asMainAccount = false,\n failOnNotExist = false,\n useMasterKey,\n sessionToken,\n user,\n } = {}\n ) {\n const getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo({ platform: unionIdPlatform }).then(authInfo => {\n authInfo = AV.User.mergeUnionId(authInfo, unionId, { asMainAccount });\n return this.loginWithMiniApp(authInfo, {\n failOnNotExist,\n useMasterKey,\n sessionToken,\n user,\n });\n });\n },\n\n /**\n * The same with {@link AV.User.loginWithQQApp}, except that you can set attributes before login.\n * @deprecated please use {@link AV.User#loginWithMiniApp}\n * @since 4.2.0\n * @param {Object} [options]\n * @param {boolean} [options.failOnNotExist] If true, the login request will fail when no user matches this authData exists.\n * @param {boolean} [options.preferUnionId] 如果服务端在登录时获取到了用户的 UnionId,是否将 UnionId 保存在用户账号中。\n * @param {string} [options.unionIdPlatform = 'qq'] (only take effect when preferUnionId) unionId platform\n * @param {boolean} [options.asMainAccount = true] (only take effect when preferUnionId) If true, the unionId will be associated with the user.\n */\n loginWithQQApp({\n preferUnionId = false,\n unionIdPlatform = 'qq',\n asMainAccount = true,\n failOnNotExist = false,\n useMasterKey,\n sessionToken,\n user,\n } = {}) {\n const getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo({\n preferUnionId,\n asMainAccount,\n platform: unionIdPlatform,\n }).then(authInfo => {\n authInfo.provider = PLATFORM_QQAPP;\n return this.loginWithMiniApp(authInfo, {\n failOnNotExist,\n useMasterKey,\n sessionToken,\n user,\n });\n });\n },\n\n /**\n * The same with {@link AV.User.loginWithQQAppWithUnionId}, except that you can set attributes before login.\n * @deprecated please use {@link AV.User#loginWithMiniApp}\n * @since 4.2.0\n */\n loginWithQQAppWithUnionId(\n unionId,\n {\n unionIdPlatform = 'qq',\n asMainAccount = false,\n failOnNotExist = false,\n useMasterKey,\n sessionToken,\n user,\n } = {}\n ) {\n const getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo({ platform: unionIdPlatform }).then(authInfo => {\n authInfo = AV.User.mergeUnionId(authInfo, unionId, { asMainAccount });\n authInfo.provider = PLATFORM_QQAPP;\n return this.loginWithMiniApp(authInfo, {\n failOnNotExist,\n useMasterKey,\n sessionToken,\n user,\n });\n });\n },\n\n /**\n * The same with {@link AV.User.loginWithMiniApp}, except that you can set attributes before login.\n * @since 4.6.0\n */\n loginWithMiniApp(authInfo, option) {\n if (authInfo === undefined) {\n const getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo().then(authInfo =>\n this.loginWithAuthData(authInfo.authData, authInfo.provider, option)\n );\n }\n return this.loginWithAuthData(\n authInfo.authData,\n authInfo.provider,\n option\n );\n },\n\n /**\n * Logs in a AV.User. On success, this saves the session to localStorage,\n * so you can retrieve the currently logged in user using\n * current.\n *\n *
A username and password must be set before calling logIn.
\n *\n * @see AV.User.logIn\n * @return {Promise} A promise that is fulfilled with the user when\n * the login is complete.\n */\n logIn: function() {\n var model = this;\n var request = AVRequest('login', null, null, 'POST', this.toJSON());\n return request.then(function(resp) {\n var serverAttrs = model.parse(resp);\n model._finishFetch(serverAttrs);\n return model._handleSaveResult(true).then(function() {\n if (!serverAttrs.smsCode) delete model.attributes['smsCode'];\n return model;\n });\n });\n },\n /**\n * @see AV.Object#save\n */\n save: function(arg1, arg2, arg3) {\n var attrs, options;\n if (_.isObject(arg1) || _.isNull(arg1) || _.isUndefined(arg1)) {\n attrs = arg1;\n options = arg2;\n } else {\n attrs = {};\n attrs[arg1] = arg2;\n options = arg3;\n }\n options = options || {};\n\n return AV.Object.prototype.save\n .call(this, attrs, options)\n .then(function(model) {\n return model._handleSaveResult(false).then(function() {\n return model;\n });\n });\n },\n\n /**\n * Follow a user\n * @since 0.3.0\n * @param {Object | AV.User | String} options if an AV.User or string is given, it will be used as the target user.\n * @param {AV.User | String} options.user The target user or user's objectId to follow.\n * @param {Object} [options.attributes] key-value attributes dictionary to be used as\n * conditions of followerQuery/followeeQuery.\n * @param {AuthOptions} [authOptions]\n */\n follow: function(options, authOptions) {\n if (!this.id) {\n throw new Error('Please signin.');\n }\n let user;\n let attributes;\n if (options.user) {\n user = options.user;\n attributes = options.attributes;\n } else {\n user = options;\n }\n var userObjectId = _.isString(user) ? user : user.id;\n if (!userObjectId) {\n throw new Error('Invalid target user.');\n }\n var route = 'users/' + this.id + '/friendship/' + userObjectId;\n var request = AVRequest(\n route,\n null,\n null,\n 'POST',\n AV._encode(attributes),\n authOptions\n );\n return request;\n },\n\n /**\n * Unfollow a user.\n * @since 0.3.0\n * @param {Object | AV.User | String} options if an AV.User or string is given, it will be used as the target user.\n * @param {AV.User | String} options.user The target user or user's objectId to unfollow.\n * @param {AuthOptions} [authOptions]\n */\n unfollow: function(options, authOptions) {\n if (!this.id) {\n throw new Error('Please signin.');\n }\n let user;\n if (options.user) {\n user = options.user;\n } else {\n user = options;\n }\n var userObjectId = _.isString(user) ? user : user.id;\n if (!userObjectId) {\n throw new Error('Invalid target user.');\n }\n var route = 'users/' + this.id + '/friendship/' + userObjectId;\n var request = AVRequest(route, null, null, 'DELETE', null, authOptions);\n return request;\n },\n\n /**\n * Get the user's followers and followees.\n * @since 4.8.0\n * @param {Object} [options]\n * @param {Number} [options.skip]\n * @param {Number} [options.limit]\n * @param {AuthOptions} [authOptions]\n */\n getFollowersAndFollowees: function(options, authOptions) {\n if (!this.id) {\n throw new Error('Please signin.');\n }\n return request({\n method: 'GET',\n path: `/users/${this.id}/followersAndFollowees`,\n query: {\n skip: options && options.skip,\n limit: options && options.limit,\n include: 'follower,followee',\n keys: 'follower,followee',\n },\n authOptions,\n }).then(({ followers, followees }) => ({\n followers: followers.map(({ follower }) => AV._decode(follower)),\n followees: followees.map(({ followee }) => AV._decode(followee)),\n }));\n },\n\n /**\n *Create a follower query to query the user's followers.\n * @since 0.3.0\n * @see AV.User#followerQuery\n */\n followerQuery: function() {\n return AV.User.followerQuery(this.id);\n },\n\n /**\n *Create a followee query to query the user's followees.\n * @since 0.3.0\n * @see AV.User#followeeQuery\n */\n followeeQuery: function() {\n return AV.User.followeeQuery(this.id);\n },\n\n /**\n * @see AV.Object#fetch\n */\n fetch: function(fetchOptions, options) {\n return AV.Object.prototype.fetch\n .call(this, fetchOptions, options)\n .then(function(model) {\n return model._handleSaveResult(false).then(function() {\n return model;\n });\n });\n },\n\n /**\n * Update user's new password safely based on old password.\n * @param {String} oldPassword the old password.\n * @param {String} newPassword the new password.\n * @param {AuthOptions} options\n */\n updatePassword: function(oldPassword, newPassword, options) {\n var route = 'users/' + this.id + '/updatePassword';\n var params = {\n old_password: oldPassword,\n new_password: newPassword,\n };\n var request = AVRequest(route, null, null, 'PUT', params, options);\n return request.then(resp => {\n this._finishFetch(this.parse(resp));\n return this._handleSaveResult(true).then(() => resp);\n });\n },\n\n /**\n * Returns true if current would return this user.\n * @see AV.User#current\n */\n isCurrent: function() {\n return this._isCurrentUser;\n },\n\n /**\n * Returns get(\"username\").\n * @return {String}\n * @see AV.Object#get\n */\n getUsername: function() {\n return this.get('username');\n },\n\n /**\n * Returns get(\"mobilePhoneNumber\").\n * @return {String}\n * @see AV.Object#get\n */\n getMobilePhoneNumber: function() {\n return this.get('mobilePhoneNumber');\n },\n\n /**\n * Calls set(\"mobilePhoneNumber\", phoneNumber, options) and returns the result.\n * @param {String} mobilePhoneNumber\n * @return {Boolean}\n * @see AV.Object#set\n */\n setMobilePhoneNumber: function(phone, options) {\n return this.set('mobilePhoneNumber', phone, options);\n },\n\n /**\n * Calls set(\"username\", username, options) and returns the result.\n * @param {String} username\n * @return {Boolean}\n * @see AV.Object#set\n */\n setUsername: function(username, options) {\n return this.set('username', username, options);\n },\n\n /**\n * Calls set(\"password\", password, options) and returns the result.\n * @param {String} password\n * @return {Boolean}\n * @see AV.Object#set\n */\n setPassword: function(password, options) {\n return this.set('password', password, options);\n },\n\n /**\n * Returns get(\"email\").\n * @return {String}\n * @see AV.Object#get\n */\n getEmail: function() {\n return this.get('email');\n },\n\n /**\n * Calls set(\"email\", email, options) and returns the result.\n * @param {String} email\n * @param {AuthOptions} options\n * @return {Boolean}\n * @see AV.Object#set\n */\n setEmail: function(email, options) {\n return this.set('email', email, options);\n },\n\n /**\n * Checks whether this user is the current user and has been authenticated.\n * @deprecated 如果要判断当前用户的登录状态是否有效,请使用 currentUser.isAuthenticated().then(),\n * 如果要判断该用户是否是当前登录用户,请使用 user.id === currentUser.id\n * @return (Boolean) whether this user is the current user and is logged in.\n */\n authenticated: function() {\n console.warn(\n 'DEPRECATED: 如果要判断当前用户的登录状态是否有效,请使用 currentUser.isAuthenticated().then(),如果要判断该用户是否是当前登录用户,请使用 user.id === currentUser.id。'\n );\n return (\n !!this._sessionToken &&\n (!AV._config.disableCurrentUser &&\n AV.User.current() &&\n AV.User.current().id === this.id)\n );\n },\n\n /**\n * Detects if current sessionToken is valid.\n *\n * @since 2.0.0\n * @return Promise.\n */\n isAuthenticated() {\n return Promise.resolve().then(\n () =>\n !!this._sessionToken &&\n AV.User._fetchUserBySessionToken(this._sessionToken).then(\n () => true,\n error => {\n if (error.code === 211) {\n return false;\n }\n throw error;\n }\n )\n );\n },\n\n /**\n * Get sessionToken of current user.\n * @return {String} sessionToken\n */\n getSessionToken() {\n return this._sessionToken;\n },\n\n /**\n * Refresh sessionToken of current user.\n * @since 2.1.0\n * @param {AuthOptions} [options]\n * @return {Promise.} user with refreshed sessionToken\n */\n refreshSessionToken(options) {\n return AVRequest(\n `users/${this.id}/refreshSessionToken`,\n null,\n null,\n 'PUT',\n null,\n options\n ).then(response => {\n this._finishFetch(response);\n return this._handleSaveResult(true).then(() => this);\n });\n },\n\n /**\n * Get this user's Roles.\n * @param {AuthOptions} [options]\n * @return {Promise.} A promise that is fulfilled with the roles when\n * the query is complete.\n */\n getRoles(options) {\n return AV.Relation.reverseQuery('_Role', 'users', this).find(options);\n },\n },\n /** @lends AV.User */ {\n // Class Variables\n\n // The currently logged-in user.\n _currentUser: null,\n\n // Whether currentUser is known to match the serialized version on disk.\n // This is useful for saving a localstorage check if you try to load\n // _currentUser frequently while there is none stored.\n _currentUserMatchesDisk: false,\n\n // The localStorage key suffix that the current user is stored under.\n _CURRENT_USER_KEY: 'currentUser',\n\n // The mapping of auth provider names to actual providers\n _authProviders: {},\n\n // Class Methods\n\n /**\n * Signs up a new user with a username (or email) and password.\n * This will create a new AV.User on the server, and also persist the\n * session in localStorage so that you can access the user using\n * {@link #current}.\n *\n * @param {String} username The username (or email) to sign up with.\n * @param {String} password The password to sign up with.\n * @param {Object} [attrs] Extra fields to set on the new user.\n * @param {AuthOptions} [options]\n * @return {Promise} A promise that is fulfilled with the user when\n * the signup completes.\n * @see AV.User#signUp\n */\n signUp: function(username, password, attrs, options) {\n attrs = attrs || {};\n attrs.username = username;\n attrs.password = password;\n var user = AV.Object._create('_User');\n return user.signUp(attrs, options);\n },\n\n /**\n * Logs in a user with a username (or email) and password. On success, this\n * saves the session to disk, so you can retrieve the currently logged in\n * user using current.\n *\n * @param {String} username The username (or email) to log in with.\n * @param {String} password The password to log in with.\n * @return {Promise} A promise that is fulfilled with the user when\n * the login completes.\n * @see AV.User#logIn\n */\n logIn: function(username, password) {\n var user = AV.Object._create('_User');\n user._finishFetch({ username: username, password: password });\n return user.logIn();\n },\n\n /**\n * Logs in a user with a session token. On success, this saves the session\n * to disk, so you can retrieve the currently logged in user using\n * current.\n *\n * @param {String} sessionToken The sessionToken to log in with.\n * @return {Promise} A promise that is fulfilled with the user when\n * the login completes.\n */\n become: function(sessionToken) {\n return this._fetchUserBySessionToken(sessionToken).then(user =>\n user._handleSaveResult(true).then(() => user)\n );\n },\n\n _fetchUserBySessionToken: function(sessionToken) {\n if (sessionToken === undefined) {\n return Promise.reject(\n new Error('The sessionToken cannot be undefined')\n );\n }\n\n var user = AV.Object._create('_User');\n return request({\n method: 'GET',\n path: '/users/me',\n authOptions: {\n sessionToken,\n },\n }).then(function(resp) {\n var serverAttrs = user.parse(resp);\n user._finishFetch(serverAttrs);\n return user;\n });\n },\n\n /**\n * Logs in a user with a mobile phone number and sms code sent by\n * AV.User.requestLoginSmsCode.On success, this\n * saves the session to disk, so you can retrieve the currently logged in\n * user using current.\n *\n * @param {String} mobilePhone The user's mobilePhoneNumber\n * @param {String} smsCode The sms code sent by AV.User.requestLoginSmsCode\n * @return {Promise} A promise that is fulfilled with the user when\n * the login completes.\n * @see AV.User#logIn\n */\n logInWithMobilePhoneSmsCode: function(mobilePhone, smsCode) {\n var user = AV.Object._create('_User');\n user._finishFetch({ mobilePhoneNumber: mobilePhone, smsCode: smsCode });\n return user.logIn();\n },\n\n /**\n * Signs up or logs in a user with a mobilePhoneNumber and smsCode.\n * On success, this saves the session to disk, so you can retrieve the currently\n * logged in user using current.\n *\n * @param {String} mobilePhoneNumber The user's mobilePhoneNumber.\n * @param {String} smsCode The sms code sent by AV.Cloud.requestSmsCode\n * @param {Object} attributes The user's other attributes such as username etc.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled with the user when\n * the login completes.\n * @see AV.User#signUpOrlogInWithMobilePhone\n * @see AV.Cloud.requestSmsCode\n */\n signUpOrlogInWithMobilePhone: function(\n mobilePhoneNumber,\n smsCode,\n attrs,\n options\n ) {\n attrs = attrs || {};\n attrs.mobilePhoneNumber = mobilePhoneNumber;\n attrs.smsCode = smsCode;\n var user = AV.Object._create('_User');\n return user.signUpOrlogInWithMobilePhone(attrs, options);\n },\n\n /**\n * Logs in a user with a mobile phone number and password. On success, this\n * saves the session to disk, so you can retrieve the currently logged in\n * user using current.\n *\n * @param {String} mobilePhone The user's mobilePhoneNumber\n * @param {String} password The password to log in with.\n * @return {Promise} A promise that is fulfilled with the user when\n * the login completes.\n * @see AV.User#logIn\n */\n logInWithMobilePhone: function(mobilePhone, password) {\n var user = AV.Object._create('_User');\n user._finishFetch({\n mobilePhoneNumber: mobilePhone,\n password: password,\n });\n return user.logIn();\n },\n\n /**\n * Logs in a user with email and password.\n *\n * @since 3.13.0\n * @param {String} email The user's email.\n * @param {String} password The password to log in with.\n * @return {Promise} A promise that is fulfilled with the user when\n * the login completes.\n */\n loginWithEmail(email, password) {\n const user = AV.Object._create('_User');\n user._finishFetch({\n email,\n password,\n });\n return user.logIn();\n },\n\n /**\n * Signs up or logs in a user with a third party auth data(AccessToken).\n * On success, this saves the session to disk, so you can retrieve the currently\n * logged in user using current.\n *\n * @since 3.7.0\n * @param {Object} authData The response json data returned from third party token, maybe like { openid: 'abc123', access_token: '123abc', expires_in: 1382686496 }\n * @param {string} platform Available platform for sign up.\n * @param {Object} [options]\n * @param {boolean} [options.failOnNotExist] If true, the login request will fail when no user matches this authData exists.\n * @return {Promise} A promise that is fulfilled with the user when\n * the login completes.\n * @example AV.User.loginWithAuthData({\n * openid: 'abc123',\n * access_token: '123abc',\n * expires_in: 1382686496\n * }, 'weixin').then(function(user) {\n * //Access user here\n * }).catch(function(error) {\n * //console.error(\"error: \", error);\n * });\n * @see {@link https://leancloud.cn/docs/js_guide.html#绑定第三方平台账户}\n */\n loginWithAuthData(authData, platform, options) {\n return AV.User._logInWith(platform, authData, options);\n },\n\n /**\n * @deprecated renamed to {@link AV.User.loginWithAuthData}\n */\n signUpOrlogInWithAuthData(...param) {\n console.warn(\n 'DEPRECATED: User.signUpOrlogInWithAuthData 已废弃,请使用 User#loginWithAuthData 代替'\n );\n return this.loginWithAuthData(...param);\n },\n\n /**\n * Signs up or logs in a user with a third party authData and unionId.\n * @since 3.7.0\n * @param {Object} authData The response json data returned from third party token, maybe like { openid: 'abc123', access_token: '123abc', expires_in: 1382686496 }\n * @param {string} platform Available platform for sign up.\n * @param {string} unionId\n * @param {Object} [unionLoginOptions]\n * @param {string} [unionLoginOptions.unionIdPlatform = 'weixin'] unionId platform\n * @param {boolean} [unionLoginOptions.asMainAccount = false] If true, the unionId will be associated with the user.\n * @param {boolean} [unionLoginOptions.failOnNotExist] If true, the login request will fail when no user matches this authData exists.\n * @return {Promise} A promise that is fulfilled with the user when completed.\n * @example AV.User.loginWithAuthDataAndUnionId({\n * openid: 'abc123',\n * access_token: '123abc',\n * expires_in: 1382686496\n * }, 'weixin', 'union123', {\n * unionIdPlatform: 'weixin',\n * asMainAccount: true,\n * }).then(function(user) {\n * //Access user here\n * }).catch(function(error) {\n * //console.error(\"error: \", error);\n * });\n */\n loginWithAuthDataAndUnionId(\n authData,\n platform,\n unionId,\n unionLoginOptions\n ) {\n return this.loginWithAuthData(\n mergeUnionDataIntoAuthData()(authData, unionId, unionLoginOptions),\n platform,\n unionLoginOptions\n );\n },\n\n /**\n * @deprecated renamed to {@link AV.User.loginWithAuthDataAndUnionId}\n * @since 3.5.0\n */\n signUpOrlogInWithAuthDataAndUnionId(...param) {\n console.warn(\n 'DEPRECATED: User.signUpOrlogInWithAuthDataAndUnionId 已废弃,请使用 User#loginWithAuthDataAndUnionId 代替'\n );\n return this.loginWithAuthDataAndUnionId(...param);\n },\n\n /**\n * Merge unionId into authInfo.\n * @since 4.6.0\n * @param {Object} authInfo\n * @param {String} unionId\n * @param {Object} [unionIdOption]\n * @param {Boolean} [unionIdOption.asMainAccount] If true, the unionId will be associated with the user.\n */\n mergeUnionId(authInfo, unionId, { asMainAccount = false } = {}) {\n authInfo = JSON.parse(JSON.stringify(authInfo));\n const { authData, platform } = authInfo;\n authData.platform = platform;\n authData.main_account = asMainAccount;\n authData.unionid = unionId;\n return authInfo;\n },\n\n /**\n * 使用当前使用微信小程序的微信用户身份注册或登录,成功后用户的 session 会在设备上持久化保存,之后可以使用 AV.User.current() 获取当前登录用户。\n * 仅在微信小程序中可用。\n *\n * @deprecated please use {@link AV.User.loginWithMiniApp}\n * @since 2.0.0\n * @param {Object} [options]\n * @param {boolean} [options.preferUnionId] 当用户满足 {@link https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/union-id.html 获取 UnionId 的条件} 时,是否使用 UnionId 登录。(since 3.13.0)\n * @param {string} [options.unionIdPlatform = 'weixin'] (only take effect when preferUnionId) unionId platform\n * @param {boolean} [options.asMainAccount = true] (only take effect when preferUnionId) If true, the unionId will be associated with the user.\n * @param {boolean} [options.failOnNotExist] If true, the login request will fail when no user matches this authData exists. (since v3.7.0)\n * @return {Promise.}\n */\n loginWithWeapp({\n preferUnionId = false,\n unionIdPlatform = 'weixin',\n asMainAccount = true,\n failOnNotExist = false,\n useMasterKey,\n sessionToken,\n user,\n } = {}) {\n const getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo({\n preferUnionId,\n asMainAccount,\n platform: unionIdPlatform,\n }).then(authInfo =>\n this.loginWithMiniApp(authInfo, {\n failOnNotExist,\n useMasterKey,\n sessionToken,\n user,\n })\n );\n },\n\n /**\n * 使用当前使用微信小程序的微信用户身份注册或登录,\n * 仅在微信小程序中可用。\n *\n * @deprecated please use {@link AV.User.loginWithMiniApp}\n * @since 3.13.0\n * @param {Object} [unionLoginOptions]\n * @param {string} [unionLoginOptions.unionIdPlatform = 'weixin'] unionId platform\n * @param {boolean} [unionLoginOptions.asMainAccount = false] If true, the unionId will be associated with the user.\n * @param {boolean} [unionLoginOptions.failOnNotExist] If true, the login request will fail when no user matches this authData exists. * @return {Promise.}\n */\n loginWithWeappWithUnionId(\n unionId,\n {\n unionIdPlatform = 'weixin',\n asMainAccount = false,\n failOnNotExist = false,\n useMasterKey,\n sessionToken,\n user,\n } = {}\n ) {\n const getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo({ platform: unionIdPlatform }).then(authInfo => {\n authInfo = AV.User.mergeUnionId(authInfo, unionId, { asMainAccount });\n return this.loginWithMiniApp(authInfo, {\n failOnNotExist,\n useMasterKey,\n sessionToken,\n user,\n });\n });\n },\n\n /**\n * 使用当前使用 QQ 小程序的 QQ 用户身份注册或登录,成功后用户的 session 会在设备上持久化保存,之后可以使用 AV.User.current() 获取当前登录用户。\n * 仅在 QQ 小程序中可用。\n *\n * @deprecated please use {@link AV.User.loginWithMiniApp}\n * @since 4.2.0\n * @param {Object} [options]\n * @param {boolean} [options.preferUnionId] 如果服务端在登录时获取到了用户的 UnionId,是否将 UnionId 保存在用户账号中。\n * @param {string} [options.unionIdPlatform = 'qq'] (only take effect when preferUnionId) unionId platform\n * @param {boolean} [options.asMainAccount = true] (only take effect when preferUnionId) If true, the unionId will be associated with the user.\n * @param {boolean} [options.failOnNotExist] If true, the login request will fail when no user matches this authData exists. (since v3.7.0)\n * @return {Promise.}\n */\n loginWithQQApp({\n preferUnionId = false,\n unionIdPlatform = 'qq',\n asMainAccount = true,\n failOnNotExist = false,\n useMasterKey,\n sessionToken,\n user,\n } = {}) {\n const getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo({\n preferUnionId,\n asMainAccount,\n platform: unionIdPlatform,\n }).then(authInfo => {\n authInfo.provider = PLATFORM_QQAPP;\n return this.loginWithMiniApp(authInfo, {\n failOnNotExist,\n useMasterKey,\n sessionToken,\n user,\n });\n });\n },\n\n /**\n * 使用当前使用 QQ 小程序的 QQ 用户身份注册或登录,\n * 仅在 QQ 小程序中可用。\n *\n * @deprecated please use {@link AV.User.loginWithMiniApp}\n * @since 4.2.0\n * @param {Object} [unionLoginOptions]\n * @param {string} [unionLoginOptions.unionIdPlatform = 'qq'] unionId platform\n * @param {boolean} [unionLoginOptions.asMainAccount = false] If true, the unionId will be associated with the user.\n * @param {boolean} [unionLoginOptions.failOnNotExist] If true, the login request will fail when no user matches this authData exists.\n * @return {Promise.}\n */\n loginWithQQAppWithUnionId(\n unionId,\n {\n unionIdPlatform = 'qq',\n asMainAccount = false,\n failOnNotExist = false,\n useMasterKey,\n sessionToken,\n user,\n } = {}\n ) {\n const getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo({ platform: unionIdPlatform }).then(authInfo => {\n authInfo = AV.User.mergeUnionId(authInfo, unionId, { asMainAccount });\n authInfo.provider = PLATFORM_QQAPP;\n return this.loginWithMiniApp(authInfo, {\n failOnNotExist,\n useMasterKey,\n sessionToken,\n user,\n });\n });\n },\n\n /**\n * Register or login using the identity of the current mini-app.\n * @param {Object} authInfo\n * @param {Object} [option]\n * @param {Boolean} [option.failOnNotExist] If true, the login request will fail when no user matches this authInfo.authData exists.\n */\n loginWithMiniApp(authInfo, option) {\n if (authInfo === undefined) {\n const getAuthInfo = getAdapter('getAuthInfo');\n return getAuthInfo().then(authInfo =>\n this.loginWithAuthData(authInfo.authData, authInfo.provider, option)\n );\n }\n return this.loginWithAuthData(\n authInfo.authData,\n authInfo.provider,\n option\n );\n },\n\n /**\n * Only use for DI in tests to produce deterministic IDs.\n */\n _genId() {\n return uuid();\n },\n\n /**\n * Creates an anonymous user.\n *\n * @since 3.9.0\n * @return {Promise.}\n */\n loginAnonymously() {\n return this.loginWithAuthData(\n {\n id: AV.User._genId(),\n },\n 'anonymous'\n );\n },\n\n associateWithAuthData(userObj, platform, authData) {\n console.warn(\n 'DEPRECATED: User.associateWithAuthData 已废弃,请使用 User#associateWithAuthData 代替'\n );\n return userObj._linkWith(platform, authData);\n },\n /**\n * Logs out the currently logged in user session. This will remove the\n * session from disk, log out of linked services, and future calls to\n * current will return null.\n * @return {Promise}\n */\n logOut: function() {\n if (AV._config.disableCurrentUser) {\n console.warn(\n 'AV.User.current() was disabled in multi-user environment, call logOut() from user object instead https://leancloud.cn/docs/leanengine-node-sdk-upgrade-1.html'\n );\n return Promise.resolve(null);\n }\n\n if (AV.User._currentUser !== null) {\n AV.User._currentUser._logOutWithAll();\n AV.User._currentUser._isCurrentUser = false;\n }\n AV.User._currentUserMatchesDisk = true;\n AV.User._currentUser = null;\n return AV.localStorage\n .removeItemAsync(AV._getAVPath(AV.User._CURRENT_USER_KEY))\n .then(() => AV._refreshSubscriptionId());\n },\n\n /**\n *Create a follower query for special user to query the user's followers.\n * @param {String} userObjectId The user object id.\n * @return {AV.FriendShipQuery}\n * @since 0.3.0\n */\n followerQuery: function(userObjectId) {\n if (!userObjectId || !_.isString(userObjectId)) {\n throw new Error('Invalid user object id.');\n }\n var query = new AV.FriendShipQuery('_Follower');\n query._friendshipTag = 'follower';\n query.equalTo(\n 'user',\n AV.Object.createWithoutData('_User', userObjectId)\n );\n return query;\n },\n\n /**\n *Create a followee query for special user to query the user's followees.\n * @param {String} userObjectId The user object id.\n * @return {AV.FriendShipQuery}\n * @since 0.3.0\n */\n followeeQuery: function(userObjectId) {\n if (!userObjectId || !_.isString(userObjectId)) {\n throw new Error('Invalid user object id.');\n }\n var query = new AV.FriendShipQuery('_Followee');\n query._friendshipTag = 'followee';\n query.equalTo(\n 'user',\n AV.Object.createWithoutData('_User', userObjectId)\n );\n return query;\n },\n\n /**\n * Requests a password reset email to be sent to the specified email address\n * associated with the user account. This email allows the user to securely\n * reset their password on the AV site.\n *\n * @param {String} email The email address associated with the user that\n * forgot their password.\n * @return {Promise}\n */\n requestPasswordReset: function(email) {\n var json = { email: email };\n var request = AVRequest(\n 'requestPasswordReset',\n null,\n null,\n 'POST',\n json\n );\n return request;\n },\n\n /**\n * Requests a verify email to be sent to the specified email address\n * associated with the user account. This email allows the user to securely\n * verify their email address on the AV site.\n *\n * @param {String} email The email address associated with the user that\n * doesn't verify their email address.\n * @return {Promise}\n */\n requestEmailVerify: function(email) {\n var json = { email: email };\n var request = AVRequest('requestEmailVerify', null, null, 'POST', json);\n return request;\n },\n\n /**\n * Requests a verify sms code to be sent to the specified mobile phone\n * number associated with the user account. This sms code allows the user to\n * verify their mobile phone number by calling AV.User.verifyMobilePhone\n *\n * @param {String} mobilePhoneNumber The mobile phone number associated with the\n * user that doesn't verify their mobile phone number.\n * @param {SMSAuthOptions} [options]\n * @return {Promise}\n */\n requestMobilePhoneVerify: function(mobilePhoneNumber, options = {}) {\n const data = {\n mobilePhoneNumber,\n };\n if (options.validateToken) {\n data.validate_token = options.validateToken;\n }\n var request = AVRequest(\n 'requestMobilePhoneVerify',\n null,\n null,\n 'POST',\n data,\n options\n );\n return request;\n },\n\n /**\n * Requests a reset password sms code to be sent to the specified mobile phone\n * number associated with the user account. This sms code allows the user to\n * reset their account's password by calling AV.User.resetPasswordBySmsCode\n *\n * @param {String} mobilePhoneNumber The mobile phone number associated with the\n * user that doesn't verify their mobile phone number.\n * @param {SMSAuthOptions} [options]\n * @return {Promise}\n */\n requestPasswordResetBySmsCode: function(mobilePhoneNumber, options = {}) {\n const data = {\n mobilePhoneNumber,\n };\n if (options.validateToken) {\n data.validate_token = options.validateToken;\n }\n var request = AVRequest(\n 'requestPasswordResetBySmsCode',\n null,\n null,\n 'POST',\n data,\n options\n );\n return request;\n },\n\n /**\n * Requests a change mobile phone number sms code to be sent to the mobilePhoneNumber.\n * This sms code allows current user to reset it's mobilePhoneNumber by\n * calling {@link AV.User.changePhoneNumber}\n * @since 4.7.0\n * @param {String} mobilePhoneNumber\n * @param {Number} [ttl] ttl of sms code (default is 6 minutes)\n * @param {SMSAuthOptions} [options]\n * @return {Promise}\n */\n requestChangePhoneNumber(mobilePhoneNumber, ttl, options) {\n const data = { mobilePhoneNumber };\n if (ttl) {\n data.ttl = options.ttl;\n }\n if (options && options.validateToken) {\n data.validate_token = options.validateToken;\n }\n return AVRequest(\n 'requestChangePhoneNumber',\n null,\n null,\n 'POST',\n data,\n options\n );\n },\n\n /**\n * Makes a call to reset user's account mobilePhoneNumber by sms code.\n * The sms code is sent by {@link AV.User.requestChangePhoneNumber}\n * @since 4.7.0\n * @param {String} mobilePhoneNumber\n * @param {String} code The sms code.\n * @return {Promise}\n */\n changePhoneNumber(mobilePhoneNumber, code) {\n const data = { mobilePhoneNumber, code };\n return AVRequest('changePhoneNumber', null, null, 'POST', data);\n },\n\n /**\n * Makes a call to reset user's account password by sms code and new password.\n * The sms code is sent by AV.User.requestPasswordResetBySmsCode.\n * @param {String} code The sms code sent by AV.User.Cloud.requestSmsCode\n * @param {String} password The new password.\n * @return {Promise} A promise that will be resolved with the result\n * of the function.\n */\n resetPasswordBySmsCode: function(code, password) {\n var json = { password: password };\n var request = AVRequest(\n 'resetPasswordBySmsCode',\n null,\n code,\n 'PUT',\n json\n );\n return request;\n },\n\n /**\n * Makes a call to verify sms code that sent by AV.User.Cloud.requestSmsCode\n * If verify successfully,the user mobilePhoneVerified attribute will be true.\n * @param {String} code The sms code sent by AV.User.Cloud.requestSmsCode\n * @return {Promise} A promise that will be resolved with the result\n * of the function.\n */\n verifyMobilePhone: function(code) {\n var request = AVRequest('verifyMobilePhone', null, code, 'POST', null);\n return request;\n },\n\n /**\n * Requests a logIn sms code to be sent to the specified mobile phone\n * number associated with the user account. This sms code allows the user to\n * login by AV.User.logInWithMobilePhoneSmsCode function.\n *\n * @param {String} mobilePhoneNumber The mobile phone number associated with the\n * user that want to login by AV.User.logInWithMobilePhoneSmsCode\n * @param {SMSAuthOptions} [options]\n * @return {Promise}\n */\n requestLoginSmsCode: function(mobilePhoneNumber, options = {}) {\n const data = {\n mobilePhoneNumber,\n };\n if (options.validateToken) {\n data.validate_token = options.validateToken;\n }\n var request = AVRequest(\n 'requestLoginSmsCode',\n null,\n null,\n 'POST',\n data,\n options\n );\n return request;\n },\n\n /**\n * Retrieves the currently logged in AVUser with a valid session,\n * either from memory or localStorage, if necessary.\n * @return {Promise.} resolved with the currently logged in AV.User.\n */\n currentAsync: function() {\n if (AV._config.disableCurrentUser) {\n console.warn(\n 'AV.User.currentAsync() was disabled in multi-user environment, access user from request instead https://leancloud.cn/docs/leanengine-node-sdk-upgrade-1.html'\n );\n return Promise.resolve(null);\n }\n\n if (AV.User._currentUser) {\n return Promise.resolve(AV.User._currentUser);\n }\n\n if (AV.User._currentUserMatchesDisk) {\n return Promise.resolve(AV.User._currentUser);\n }\n\n return AV.localStorage\n .getItemAsync(AV._getAVPath(AV.User._CURRENT_USER_KEY))\n .then(function(userData) {\n if (!userData) {\n return null;\n }\n\n // Load the user from local storage.\n AV.User._currentUserMatchesDisk = true;\n\n AV.User._currentUser = AV.Object._create('_User');\n AV.User._currentUser._isCurrentUser = true;\n\n var json = JSON.parse(userData);\n AV.User._currentUser.id = json._id;\n delete json._id;\n AV.User._currentUser._sessionToken = json._sessionToken;\n delete json._sessionToken;\n AV.User._currentUser._finishFetch(json);\n //AV.User._currentUser.set(json);\n\n AV.User._currentUser._synchronizeAllAuthData();\n AV.User._currentUser._refreshCache();\n AV.User._currentUser._opSetQueue = [{}];\n return AV.User._currentUser;\n });\n },\n\n /**\n * Retrieves the currently logged in AVUser with a valid session,\n * either from memory or localStorage, if necessary.\n * @return {AV.User} The currently logged in AV.User.\n */\n current: function() {\n if (AV._config.disableCurrentUser) {\n console.warn(\n 'AV.User.current() was disabled in multi-user environment, access user from request instead https://leancloud.cn/docs/leanengine-node-sdk-upgrade-1.html'\n );\n return null;\n }\n\n if (AV.localStorage.async) {\n const error = new Error(\n 'Synchronous API User.current() is not available in this runtime. Use User.currentAsync() instead.'\n );\n error.code = 'SYNC_API_NOT_AVAILABLE';\n throw error;\n }\n\n if (AV.User._currentUser) {\n return AV.User._currentUser;\n }\n\n if (AV.User._currentUserMatchesDisk) {\n return AV.User._currentUser;\n }\n\n // Load the user from local storage.\n AV.User._currentUserMatchesDisk = true;\n\n var userData = AV.localStorage.getItem(\n AV._getAVPath(AV.User._CURRENT_USER_KEY)\n );\n if (!userData) {\n return null;\n }\n AV.User._currentUser = AV.Object._create('_User');\n AV.User._currentUser._isCurrentUser = true;\n\n var json = JSON.parse(userData);\n AV.User._currentUser.id = json._id;\n delete json._id;\n AV.User._currentUser._sessionToken = json._sessionToken;\n delete json._sessionToken;\n AV.User._currentUser._finishFetch(json);\n //AV.User._currentUser.set(json);\n\n AV.User._currentUser._synchronizeAllAuthData();\n AV.User._currentUser._refreshCache();\n AV.User._currentUser._opSetQueue = [{}];\n return AV.User._currentUser;\n },\n\n /**\n * Persists a user as currentUser to localStorage, and into the singleton.\n * @private\n */\n _saveCurrentUser: function(user) {\n var promise;\n if (AV.User._currentUser !== user) {\n promise = AV.User.logOut();\n } else {\n promise = Promise.resolve();\n }\n return promise.then(function() {\n user._isCurrentUser = true;\n AV.User._currentUser = user;\n\n var json = user._toFullJSON();\n json._id = user.id;\n json._sessionToken = user._sessionToken;\n return AV.localStorage\n .setItemAsync(\n AV._getAVPath(AV.User._CURRENT_USER_KEY),\n JSON.stringify(json)\n )\n .then(function() {\n AV.User._currentUserMatchesDisk = true;\n return AV._refreshSubscriptionId();\n });\n });\n },\n\n _registerAuthenticationProvider: function(provider) {\n AV.User._authProviders[provider.getAuthType()] = provider;\n // Synchronize the current user with the auth provider.\n if (!AV._config.disableCurrentUser && AV.User.current()) {\n AV.User.current()._synchronizeAuthData(provider.getAuthType());\n }\n },\n\n _logInWith: function(provider, authData, options) {\n var user = AV.Object._create('_User');\n return user._linkWith(provider, authData, options);\n },\n }\n );\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/user.js","var _Object$defineProperty = require(\"@babel/runtime-corejs3/core-js/object/define-property\");\n\nfunction _defineProperty(obj, key, value) {\n if (key in obj) {\n _Object$defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n\n return obj;\n}\n\nmodule.exports = _defineProperty, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/@babel/runtime-corejs3/helpers/defineProperty.js\n// module id = 528\n// module chunks = 0 1","const _ = require('underscore');\nconst debug = require('debug')('leancloud:query');\nconst AVError = require('./error');\nconst { _request, request } = require('./request');\nconst {\n ensureArray,\n transformFetchOptions,\n continueWhile,\n} = require('./utils');\n\nconst requires = (value, message) => {\n if (value === undefined) {\n throw new Error(message);\n }\n};\n\n// AV.Query is a way to create a list of AV.Objects.\nmodule.exports = function(AV) {\n /**\n * Creates a new AV.Query for the given AV.Object subclass.\n * @param {Class|String} objectClass An instance of a subclass of AV.Object, or a AV className string.\n * @class\n *\n *
AV.Query defines a query that is used to fetch AV.Objects. The\n * most common use case is finding all objects that match a query through the\n * find method. For example, this sample code fetches all objects\n * of class MyClass. It calls a different function depending on\n * whether the fetch succeeded or not.\n *\n *
\n * var query = new AV.Query(MyClass);\n * query.find().then(function(results) {\n * // results is an array of AV.Object.\n * }, function(error) {\n * // error is an instance of AVError.\n * });
\n *\n *
An AV.Query can also be used to retrieve a single object whose id is\n * known, through the get method. For example, this sample code fetches an\n * object of class MyClass and id myId. It calls a\n * different function depending on whether the fetch succeeded or not.\n *\n *
\n * var query = new AV.Query(MyClass);\n * query.get(myId).then(function(object) {\n * // object is an instance of AV.Object.\n * }, function(error) {\n * // error is an instance of AVError.\n * });
\n *\n *
An AV.Query can also be used to count the number of objects that match\n * the query without retrieving all of those objects. For example, this\n * sample code counts the number of objects of the class MyClass\n *
\n * var query = new AV.Query(MyClass);\n * query.count().then(function(number) {\n * // There are number instances of MyClass.\n * }, function(error) {\n * // error is an instance of AVError.\n * });
\n */\n AV.Query = function(objectClass) {\n if (_.isString(objectClass)) {\n objectClass = AV.Object._getSubclass(objectClass);\n }\n\n this.objectClass = objectClass;\n\n this.className = objectClass.prototype.className;\n\n this._where = {};\n this._include = [];\n this._select = [];\n this._limit = -1; // negative limit means, do not send a limit\n this._skip = 0;\n this._defaultParams = {};\n };\n\n /**\n * Constructs a AV.Query that is the OR of the passed in queries. For\n * example:\n *
var compoundQuery = AV.Query.or(query1, query2, query3);
\n *\n * will create a compoundQuery that is an or of the query1, query2, and\n * query3.\n * @param {...AV.Query} var_args The list of queries to OR.\n * @return {AV.Query} The query that is the OR of the passed in queries.\n */\n AV.Query.or = function() {\n var queries = _.toArray(arguments);\n var className = null;\n AV._arrayEach(queries, function(q) {\n if (_.isNull(className)) {\n className = q.className;\n }\n\n if (className !== q.className) {\n throw new Error('All queries must be for the same class');\n }\n });\n var query = new AV.Query(className);\n query._orQuery(queries);\n return query;\n };\n\n /**\n * Constructs a AV.Query that is the AND of the passed in queries. For\n * example:\n *
var compoundQuery = AV.Query.and(query1, query2, query3);
\n *\n * will create a compoundQuery that is an 'and' of the query1, query2, and\n * query3.\n * @param {...AV.Query} var_args The list of queries to AND.\n * @return {AV.Query} The query that is the AND of the passed in queries.\n */\n AV.Query.and = function() {\n var queries = _.toArray(arguments);\n var className = null;\n AV._arrayEach(queries, function(q) {\n if (_.isNull(className)) {\n className = q.className;\n }\n\n if (className !== q.className) {\n throw new Error('All queries must be for the same class');\n }\n });\n var query = new AV.Query(className);\n query._andQuery(queries);\n return query;\n };\n\n /**\n * Retrieves a list of AVObjects that satisfy the CQL.\n * CQL syntax please see {@link https://leancloud.cn/docs/cql_guide.html CQL Guide}.\n *\n * @param {String} cql A CQL string, see {@link https://leancloud.cn/docs/cql_guide.html CQL Guide}.\n * @param {Array} pvalues An array contains placeholder values.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is resolved with the results when\n * the query completes.\n */\n AV.Query.doCloudQuery = function(cql, pvalues, options) {\n var params = { cql: cql };\n if (_.isArray(pvalues)) {\n params.pvalues = pvalues;\n } else {\n options = pvalues;\n }\n\n var request = _request('cloudQuery', null, null, 'GET', params, options);\n return request.then(function(response) {\n //query to process results.\n var query = new AV.Query(response.className);\n var results = _.map(response.results, function(json) {\n var obj = query._newObject(response);\n if (obj._finishFetch) {\n obj._finishFetch(query._processResult(json), true);\n }\n return obj;\n });\n return {\n results: results,\n count: response.count,\n className: response.className,\n };\n });\n };\n\n /**\n * Return a query with conditions from json.\n * This can be useful to send a query from server side to client side.\n * @since 4.0.0\n * @param {Object} json from {@link AV.Query#toJSON}\n * @return {AV.Query}\n */\n AV.Query.fromJSON = ({\n className,\n where,\n include,\n select,\n includeACL,\n limit,\n skip,\n order,\n }) => {\n if (typeof className !== 'string') {\n throw new TypeError('Invalid Query JSON, className must be a String.');\n }\n const query = new AV.Query(className);\n _.extend(query, {\n _where: where,\n _include: include,\n _select: select,\n _includeACL: includeACL,\n _limit: limit,\n _skip: skip,\n _order: order,\n });\n return query;\n };\n\n AV.Query._extend = AV._extend;\n\n _.extend(\n AV.Query.prototype,\n /** @lends AV.Query.prototype */ {\n //hook to iterate result. Added by dennis.\n _processResult: function(obj) {\n return obj;\n },\n\n /**\n * Constructs an AV.Object whose id is already known by fetching data from\n * the server.\n *\n * @param {String} objectId The id of the object to be fetched.\n * @param {AuthOptions} options\n * @return {Promise.}\n */\n get: function(objectId, options) {\n if (!_.isString(objectId)) {\n throw new Error('objectId must be a string');\n }\n if (objectId === '') {\n return Promise.reject(\n new AVError(AVError.OBJECT_NOT_FOUND, 'Object not found.')\n );\n }\n\n var obj = this._newObject();\n obj.id = objectId;\n\n var queryJSON = this._getParams();\n var fetchOptions = {};\n\n if (queryJSON.keys) fetchOptions.keys = queryJSON.keys;\n if (queryJSON.include) fetchOptions.include = queryJSON.include;\n if (queryJSON.includeACL)\n fetchOptions.includeACL = queryJSON.includeACL;\n\n return _request(\n 'classes',\n this.className,\n objectId,\n 'GET',\n transformFetchOptions(fetchOptions),\n options\n ).then(response => {\n if (_.isEmpty(response))\n throw new AVError(AVError.OBJECT_NOT_FOUND, 'Object not found.');\n obj._finishFetch(obj.parse(response), true);\n return obj;\n });\n },\n\n /**\n * Returns a JSON representation of this query.\n * @return {Object}\n */\n toJSON() {\n const {\n className,\n _where: where,\n _include: include,\n _select: select,\n _includeACL: includeACL,\n _limit: limit,\n _skip: skip,\n _order: order,\n } = this;\n return {\n className,\n where,\n include,\n select,\n includeACL,\n limit,\n skip,\n order,\n };\n },\n\n _getParams: function() {\n var params = _.extend({}, this._defaultParams, {\n where: this._where,\n });\n\n if (this._include.length > 0) {\n params.include = this._include.join(',');\n }\n if (this._select.length > 0) {\n params.keys = this._select.join(',');\n }\n if (this._includeACL !== undefined) {\n params.returnACL = this._includeACL;\n }\n if (this._limit >= 0) {\n params.limit = this._limit;\n }\n if (this._skip > 0) {\n params.skip = this._skip;\n }\n if (this._order !== undefined) {\n params.order = this._order;\n }\n\n return params;\n },\n\n _newObject: function(response) {\n var obj;\n if (response && response.className) {\n obj = new AV.Object(response.className);\n } else {\n obj = new this.objectClass();\n }\n return obj;\n },\n _createRequest(\n params = this._getParams(),\n options,\n path = `/classes/${this.className}`\n ) {\n if (encodeURIComponent(JSON.stringify(params)).length > 2000) {\n const body = {\n requests: [\n {\n method: 'GET',\n path: `/1.1${path}`,\n params,\n },\n ],\n };\n return request({\n path: '/batch',\n method: 'POST',\n data: body,\n authOptions: options,\n }).then(response => {\n const result = response[0];\n if (result.success) {\n return result.success;\n }\n const error = new AVError(\n result.error.code,\n result.error.error || 'Unknown batch error'\n );\n throw error;\n });\n }\n return request({\n method: 'GET',\n path,\n query: params,\n authOptions: options,\n });\n },\n\n _parseResponse(response) {\n return _.map(response.results, json => {\n var obj = this._newObject(response);\n if (obj._finishFetch) {\n obj._finishFetch(this._processResult(json), true);\n }\n return obj;\n });\n },\n\n /**\n * Retrieves a list of AVObjects that satisfy this query.\n *\n * @param {AuthOptions} options\n * @return {Promise} A promise that is resolved with the results when\n * the query completes.\n */\n find(options) {\n const request = this._createRequest(undefined, options);\n return request.then(this._parseResponse.bind(this));\n },\n\n /**\n * Retrieves both AVObjects and total count.\n *\n * @since 4.12.0\n * @param {AuthOptions} options\n * @return {Promise} A tuple contains results and count.\n */\n findAndCount(options) {\n const params = this._getParams();\n params.count = 1;\n const request = this._createRequest(params, options);\n\n return request.then(response => [\n this._parseResponse(response),\n response.count,\n ]);\n },\n\n /**\n * scan a Query. masterKey required.\n *\n * @since 2.1.0\n * @param {object} [options]\n * @param {string} [options.orderedBy] specify the key to sort\n * @param {number} [options.batchSize] specify the batch size for each request\n * @param {AuthOptions} [authOptions]\n * @return {AsyncIterator.}\n * @example const testIterator = {\n * [Symbol.asyncIterator]() {\n * return new Query('Test').scan(undefined, { useMasterKey: true });\n * },\n * };\n * for await (const test of testIterator) {\n * console.log(test.id);\n * }\n */\n scan({ orderedBy, batchSize } = {}, authOptions) {\n const condition = this._getParams();\n debug('scan %O', condition);\n if (condition.order) {\n console.warn(\n 'The order of the query is ignored for Query#scan. Checkout the orderedBy option of Query#scan.'\n );\n delete condition.order;\n }\n if (condition.skip) {\n console.warn(\n 'The skip option of the query is ignored for Query#scan.'\n );\n delete condition.skip;\n }\n if (condition.limit) {\n console.warn(\n 'The limit option of the query is ignored for Query#scan.'\n );\n delete condition.limit;\n }\n if (orderedBy) condition.scan_key = orderedBy;\n if (batchSize) condition.limit = batchSize;\n let cursor;\n let remainResults = [];\n return {\n next: () => {\n if (remainResults.length) {\n return Promise.resolve({\n done: false,\n value: remainResults.shift(),\n });\n }\n if (cursor === null) {\n return Promise.resolve({ done: true });\n }\n return _request(\n 'scan/classes',\n this.className,\n null,\n 'GET',\n cursor ? _.extend({}, condition, { cursor }) : condition,\n authOptions\n ).then(response => {\n cursor = response.cursor;\n if (response.results.length) {\n const results = this._parseResponse(response);\n results.forEach(result => remainResults.push(result));\n }\n if (cursor === null && remainResults.length === 0) {\n return { done: true };\n }\n return {\n done: false,\n value: remainResults.shift(),\n };\n });\n },\n };\n },\n\n /**\n * Delete objects retrieved by this query.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled when the save\n * completes.\n */\n destroyAll: function(options) {\n var self = this;\n return self.find(options).then(function(objects) {\n return AV.Object.destroyAll(objects, options);\n });\n },\n\n /**\n * Counts the number of objects that match this query.\n *\n * @param {AuthOptions} options\n * @return {Promise} A promise that is resolved with the count when\n * the query completes.\n */\n count: function(options) {\n var params = this._getParams();\n params.limit = 0;\n params.count = 1;\n var request = this._createRequest(params, options);\n\n return request.then(function(response) {\n return response.count;\n });\n },\n\n /**\n * Retrieves at most one AV.Object that satisfies this query.\n *\n * @param {AuthOptions} options\n * @return {Promise} A promise that is resolved with the object when\n * the query completes.\n */\n first: function(options) {\n var self = this;\n\n var params = this._getParams();\n params.limit = 1;\n var request = this._createRequest(params, options);\n\n return request.then(function(response) {\n return _.map(response.results, function(json) {\n var obj = self._newObject();\n if (obj._finishFetch) {\n obj._finishFetch(self._processResult(json), true);\n }\n return obj;\n })[0];\n });\n },\n\n /**\n * Sets the number of results to skip before returning any results.\n * This is useful for pagination.\n * Default is to skip zero results.\n * @param {Number} n the number of results to skip.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n skip: function(n) {\n requires(n, 'undefined is not a valid skip value');\n this._skip = n;\n return this;\n },\n\n /**\n * Sets the limit of the number of results to return. The default limit is\n * 100, with a maximum of 1000 results being returned at a time.\n * @param {Number} n the number of results to limit to.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n limit: function(n) {\n requires(n, 'undefined is not a valid limit value');\n this._limit = n;\n return this;\n },\n\n /**\n * Add a constraint to the query that requires a particular key's value to\n * be equal to the provided value.\n * @param {String} key The key to check.\n * @param value The value that the AV.Object must contain.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n equalTo: function(key, value) {\n requires(key, 'undefined is not a valid key');\n requires(value, 'undefined is not a valid value');\n this._where[key] = AV._encode(value);\n return this;\n },\n\n /**\n * Helper for condition queries\n * @private\n */\n _addCondition: function(key, condition, value) {\n requires(key, 'undefined is not a valid condition key');\n requires(condition, 'undefined is not a valid condition');\n requires(value, 'undefined is not a valid condition value');\n\n // Check if we already have a condition\n if (!this._where[key]) {\n this._where[key] = {};\n }\n this._where[key][condition] = AV._encode(value);\n return this;\n },\n\n /**\n * Add a constraint to the query that requires a particular\n * array key's length to be equal to the provided value.\n * @param {String} key The array key to check.\n * @param {number} value The length value.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n sizeEqualTo: function(key, value) {\n this._addCondition(key, '$size', value);\n return this;\n },\n\n /**\n * Add a constraint to the query that requires a particular key's value to\n * be not equal to the provided value.\n * @param {String} key The key to check.\n * @param value The value that must not be equalled.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n notEqualTo: function(key, value) {\n this._addCondition(key, '$ne', value);\n return this;\n },\n\n /**\n * Add a constraint to the query that requires a particular key's value to\n * be less than the provided value.\n * @param {String} key The key to check.\n * @param value The value that provides an upper bound.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n lessThan: function(key, value) {\n this._addCondition(key, '$lt', value);\n return this;\n },\n\n /**\n * Add a constraint to the query that requires a particular key's value to\n * be greater than the provided value.\n * @param {String} key The key to check.\n * @param value The value that provides an lower bound.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n greaterThan: function(key, value) {\n this._addCondition(key, '$gt', value);\n return this;\n },\n\n /**\n * Add a constraint to the query that requires a particular key's value to\n * be less than or equal to the provided value.\n * @param {String} key The key to check.\n * @param value The value that provides an upper bound.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n lessThanOrEqualTo: function(key, value) {\n this._addCondition(key, '$lte', value);\n return this;\n },\n\n /**\n * Add a constraint to the query that requires a particular key's value to\n * be greater than or equal to the provided value.\n * @param {String} key The key to check.\n * @param value The value that provides an lower bound.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n greaterThanOrEqualTo: function(key, value) {\n this._addCondition(key, '$gte', value);\n return this;\n },\n\n /**\n * Add a constraint to the query that requires a particular key's value to\n * be contained in the provided list of values.\n * @param {String} key The key to check.\n * @param {Array} values The values that will match.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n containedIn: function(key, values) {\n this._addCondition(key, '$in', values);\n return this;\n },\n\n /**\n * Add a constraint to the query that requires a particular key's value to\n * not be contained in the provided list of values.\n * @param {String} key The key to check.\n * @param {Array} values The values that will not match.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n notContainedIn: function(key, values) {\n this._addCondition(key, '$nin', values);\n return this;\n },\n\n /**\n * Add a constraint to the query that requires a particular key's value to\n * contain each one of the provided list of values.\n * @param {String} key The key to check. This key's value must be an array.\n * @param {Array} values The values that will match.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n containsAll: function(key, values) {\n this._addCondition(key, '$all', values);\n return this;\n },\n\n /**\n * Add a constraint for finding objects that contain the given key.\n * @param {String} key The key that should exist.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n exists: function(key) {\n this._addCondition(key, '$exists', true);\n return this;\n },\n\n /**\n * Add a constraint for finding objects that do not contain a given key.\n * @param {String} key The key that should not exist\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n doesNotExist: function(key) {\n this._addCondition(key, '$exists', false);\n return this;\n },\n\n /**\n * Add a regular expression constraint for finding string values that match\n * the provided regular expression.\n * This may be slow for large datasets.\n * @param {String} key The key that the string to match is stored in.\n * @param {RegExp} regex The regular expression pattern to match.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n matches: function(key, regex, modifiers) {\n this._addCondition(key, '$regex', regex);\n if (!modifiers) {\n modifiers = '';\n }\n // Javascript regex options support mig as inline options but store them\n // as properties of the object. We support mi & should migrate them to\n // modifiers\n if (regex.ignoreCase) {\n modifiers += 'i';\n }\n if (regex.multiline) {\n modifiers += 'm';\n }\n\n if (modifiers && modifiers.length) {\n this._addCondition(key, '$options', modifiers);\n }\n return this;\n },\n\n /**\n * Add a constraint that requires that a key's value matches a AV.Query\n * constraint.\n * @param {String} key The key that the contains the object to match the\n * query.\n * @param {AV.Query} query The query that should match.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n matchesQuery: function(key, query) {\n var queryJSON = query._getParams();\n queryJSON.className = query.className;\n this._addCondition(key, '$inQuery', queryJSON);\n return this;\n },\n\n /**\n * Add a constraint that requires that a key's value not matches a\n * AV.Query constraint.\n * @param {String} key The key that the contains the object to match the\n * query.\n * @param {AV.Query} query The query that should not match.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n doesNotMatchQuery: function(key, query) {\n var queryJSON = query._getParams();\n queryJSON.className = query.className;\n this._addCondition(key, '$notInQuery', queryJSON);\n return this;\n },\n\n /**\n * Add a constraint that requires that a key's value matches a value in\n * an object returned by a different AV.Query.\n * @param {String} key The key that contains the value that is being\n * matched.\n * @param {String} queryKey The key in the objects returned by the query to\n * match against.\n * @param {AV.Query} query The query to run.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n matchesKeyInQuery: function(key, queryKey, query) {\n var queryJSON = query._getParams();\n queryJSON.className = query.className;\n this._addCondition(key, '$select', { key: queryKey, query: queryJSON });\n return this;\n },\n\n /**\n * Add a constraint that requires that a key's value not match a value in\n * an object returned by a different AV.Query.\n * @param {String} key The key that contains the value that is being\n * excluded.\n * @param {String} queryKey The key in the objects returned by the query to\n * match against.\n * @param {AV.Query} query The query to run.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n doesNotMatchKeyInQuery: function(key, queryKey, query) {\n var queryJSON = query._getParams();\n queryJSON.className = query.className;\n this._addCondition(key, '$dontSelect', {\n key: queryKey,\n query: queryJSON,\n });\n return this;\n },\n\n /**\n * Add constraint that at least one of the passed in queries matches.\n * @param {Array} queries\n * @return {AV.Query} Returns the query, so you can chain this call.\n * @private\n */\n _orQuery: function(queries) {\n var queryJSON = _.map(queries, function(q) {\n return q._getParams().where;\n });\n\n this._where.$or = queryJSON;\n return this;\n },\n\n /**\n * Add constraint that both of the passed in queries matches.\n * @param {Array} queries\n * @return {AV.Query} Returns the query, so you can chain this call.\n * @private\n */\n _andQuery: function(queries) {\n var queryJSON = _.map(queries, function(q) {\n return q._getParams().where;\n });\n\n this._where.$and = queryJSON;\n return this;\n },\n\n /**\n * Converts a string into a regex that matches it.\n * Surrounding with \\Q .. \\E does this, we just need to escape \\E's in\n * the text separately.\n * @private\n */\n _quote: function(s) {\n return '\\\\Q' + s.replace('\\\\E', '\\\\E\\\\\\\\E\\\\Q') + '\\\\E';\n },\n\n /**\n * Add a constraint for finding string values that contain a provided\n * string. This may be slow for large datasets.\n * @param {String} key The key that the string to match is stored in.\n * @param {String} substring The substring that the value must contain.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n contains: function(key, value) {\n this._addCondition(key, '$regex', this._quote(value));\n return this;\n },\n\n /**\n * Add a constraint for finding string values that start with a provided\n * string. This query will use the backend index, so it will be fast even\n * for large datasets.\n * @param {String} key The key that the string to match is stored in.\n * @param {String} prefix The substring that the value must start with.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n startsWith: function(key, value) {\n this._addCondition(key, '$regex', '^' + this._quote(value));\n return this;\n },\n\n /**\n * Add a constraint for finding string values that end with a provided\n * string. This will be slow for large datasets.\n * @param {String} key The key that the string to match is stored in.\n * @param {String} suffix The substring that the value must end with.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n endsWith: function(key, value) {\n this._addCondition(key, '$regex', this._quote(value) + '$');\n return this;\n },\n\n /**\n * Sorts the results in ascending order by the given key.\n *\n * @param {String} key The key to order by.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n ascending: function(key) {\n requires(key, 'undefined is not a valid key');\n this._order = key;\n return this;\n },\n\n /**\n * Also sorts the results in ascending order by the given key. The previous sort keys have\n * precedence over this key.\n *\n * @param {String} key The key to order by\n * @return {AV.Query} Returns the query so you can chain this call.\n */\n addAscending: function(key) {\n requires(key, 'undefined is not a valid key');\n if (this._order) this._order += ',' + key;\n else this._order = key;\n return this;\n },\n\n /**\n * Sorts the results in descending order by the given key.\n *\n * @param {String} key The key to order by.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n descending: function(key) {\n requires(key, 'undefined is not a valid key');\n this._order = '-' + key;\n return this;\n },\n\n /**\n * Also sorts the results in descending order by the given key. The previous sort keys have\n * precedence over this key.\n *\n * @param {String} key The key to order by\n * @return {AV.Query} Returns the query so you can chain this call.\n */\n addDescending: function(key) {\n requires(key, 'undefined is not a valid key');\n if (this._order) this._order += ',-' + key;\n else this._order = '-' + key;\n return this;\n },\n\n /**\n * Add a proximity based constraint for finding objects with key point\n * values near the point given.\n * @param {String} key The key that the AV.GeoPoint is stored in.\n * @param {AV.GeoPoint} point The reference AV.GeoPoint that is used.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n near: function(key, point) {\n if (!(point instanceof AV.GeoPoint)) {\n // Try to cast it to a GeoPoint, so that near(\"loc\", [20,30]) works.\n point = new AV.GeoPoint(point);\n }\n this._addCondition(key, '$nearSphere', point);\n return this;\n },\n\n /**\n * Add a proximity based constraint for finding objects with key point\n * values near the point given and within the maximum distance given.\n * @param {String} key The key that the AV.GeoPoint is stored in.\n * @param {AV.GeoPoint} point The reference AV.GeoPoint that is used.\n * @param maxDistance Maximum distance (in radians) of results to return.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n withinRadians: function(key, point, distance) {\n this.near(key, point);\n this._addCondition(key, '$maxDistance', distance);\n return this;\n },\n\n /**\n * Add a proximity based constraint for finding objects with key point\n * values near the point given and within the maximum distance given.\n * Radius of earth used is 3958.8 miles.\n * @param {String} key The key that the AV.GeoPoint is stored in.\n * @param {AV.GeoPoint} point The reference AV.GeoPoint that is used.\n * @param {Number} maxDistance Maximum distance (in miles) of results to\n * return.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n withinMiles: function(key, point, distance) {\n return this.withinRadians(key, point, distance / 3958.8);\n },\n\n /**\n * Add a proximity based constraint for finding objects with key point\n * values near the point given and within the maximum distance given.\n * Radius of earth used is 6371.0 kilometers.\n * @param {String} key The key that the AV.GeoPoint is stored in.\n * @param {AV.GeoPoint} point The reference AV.GeoPoint that is used.\n * @param {Number} maxDistance Maximum distance (in kilometers) of results\n * to return.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n withinKilometers: function(key, point, distance) {\n return this.withinRadians(key, point, distance / 6371.0);\n },\n\n /**\n * Add a constraint to the query that requires a particular key's\n * coordinates be contained within a given rectangular geographic bounding\n * box.\n * @param {String} key The key to be constrained.\n * @param {AV.GeoPoint} southwest\n * The lower-left inclusive corner of the box.\n * @param {AV.GeoPoint} northeast\n * The upper-right inclusive corner of the box.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n withinGeoBox: function(key, southwest, northeast) {\n if (!(southwest instanceof AV.GeoPoint)) {\n southwest = new AV.GeoPoint(southwest);\n }\n if (!(northeast instanceof AV.GeoPoint)) {\n northeast = new AV.GeoPoint(northeast);\n }\n this._addCondition(key, '$within', { $box: [southwest, northeast] });\n return this;\n },\n\n /**\n * Include nested AV.Objects for the provided key. You can use dot\n * notation to specify which fields in the included object are also fetch.\n * @param {String[]} keys The name of the key to include.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n include: function(keys) {\n requires(keys, 'undefined is not a valid key');\n _.forEach(arguments, keys => {\n this._include = this._include.concat(ensureArray(keys));\n });\n return this;\n },\n\n /**\n * Include the ACL.\n * @param {Boolean} [value=true] Whether to include the ACL\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n includeACL: function(value = true) {\n this._includeACL = value;\n return this;\n },\n\n /**\n * Restrict the fields of the returned AV.Objects to include only the\n * provided keys. If this is called multiple times, then all of the keys\n * specified in each of the calls will be included.\n * @param {String[]} keys The names of the keys to include.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n select: function(keys) {\n requires(keys, 'undefined is not a valid key');\n _.forEach(arguments, keys => {\n this._select = this._select.concat(ensureArray(keys));\n });\n return this;\n },\n\n /**\n * Iterates over each result of a query, calling a callback for each one. If\n * the callback returns a promise, the iteration will not continue until\n * that promise has been fulfilled. If the callback returns a rejected\n * promise, then iteration will stop with that error. The items are\n * processed in an unspecified order. The query may not have any sort order,\n * and may not use limit or skip.\n * @param callback {Function} Callback that will be called with each result\n * of the query.\n * @return {Promise} A promise that will be fulfilled once the\n * iteration has completed.\n */\n each: function(callback, options = {}) {\n if (this._order || this._skip || this._limit >= 0) {\n var error = new Error(\n 'Cannot iterate on a query with sort, skip, or limit.'\n );\n return Promise.reject(error);\n }\n\n var query = new AV.Query(this.objectClass);\n // We can override the batch size from the options.\n // This is undocumented, but useful for testing.\n query._limit = options.batchSize || 100;\n query._where = _.clone(this._where);\n query._include = _.clone(this._include);\n\n query.ascending('objectId');\n\n var finished = false;\n return continueWhile(\n function() {\n return !finished;\n },\n function() {\n return query.find(options).then(function(results) {\n var callbacksDone = Promise.resolve();\n _.each(results, function(result) {\n callbacksDone = callbacksDone.then(function() {\n return callback(result);\n });\n });\n\n return callbacksDone.then(function() {\n if (results.length >= query._limit) {\n query.greaterThan('objectId', results[results.length - 1].id);\n } else {\n finished = true;\n }\n });\n });\n }\n );\n },\n\n /**\n * Subscribe the changes of this query.\n *\n * LiveQuery is not included in the default bundle: {@link https://url.leanapp.cn/enable-live-query}.\n *\n * @since 3.0.0\n * @return {AV.LiveQuery} An eventemitter which can be used to get LiveQuery updates;\n */\n subscribe(options) {\n return AV.LiveQuery.init(this, options);\n },\n }\n );\n\n AV.FriendShipQuery = AV.Query._extend({\n _newObject: function() {\n const UserClass = AV.Object._getSubclass('_User');\n return new UserClass();\n },\n _processResult: function(json) {\n if (json && json[this._friendshipTag]) {\n var user = json[this._friendshipTag];\n if (user.__type === 'Pointer' && user.className === '_User') {\n delete user.__type;\n delete user.className;\n }\n return user;\n } else {\n return null;\n }\n },\n });\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/query.js","const _ = require('underscore');\nconst EventEmitter = require('eventemitter3');\nconst { inherits } = require('./utils');\nconst { request } = require('./request');\n\nconst subscribe = (queryJSON, subscriptionId) =>\n request({\n method: 'POST',\n path: '/LiveQuery/subscribe',\n data: {\n query: queryJSON,\n id: subscriptionId,\n },\n });\n\nmodule.exports = AV => {\n const requireRealtime = () => {\n if (!AV._config.realtime) {\n throw new Error(\n 'LiveQuery not supported. Please use the LiveQuery bundle. https://url.leanapp.cn/enable-live-query'\n );\n }\n };\n /**\n * @class\n * A LiveQuery, created by {@link AV.Query#subscribe} is an EventEmitter notifies changes of the Query.\n * @since 3.0.0\n */\n AV.LiveQuery = inherits(\n EventEmitter,\n /** @lends AV.LiveQuery.prototype */ {\n constructor(id, client, queryJSON, subscriptionId) {\n EventEmitter.apply(this);\n this.id = id;\n this._client = client;\n this._client.register(this);\n this._queryJSON = queryJSON;\n this._subscriptionId = subscriptionId;\n this._onMessage = this._dispatch.bind(this);\n this._onReconnect = () => {\n subscribe(this._queryJSON, this._subscriptionId).catch(error =>\n console.error(`LiveQuery resubscribe error: ${error.message}`)\n );\n };\n client.on('message', this._onMessage);\n client.on('reconnect', this._onReconnect);\n },\n _dispatch(message) {\n message.forEach(({ op, object, query_id: queryId, updatedKeys }) => {\n if (queryId !== this.id) return;\n const target = AV.parseJSON(\n _.extend(\n {\n __type: object.className === '_File' ? 'File' : 'Object',\n },\n object\n )\n );\n if (updatedKeys) {\n /**\n * An existing AV.Object which fulfills the Query you subscribe is updated.\n * @event AV.LiveQuery#update\n * @param {AV.Object|AV.File} target updated object\n * @param {String[]} updatedKeys updated keys\n */\n /**\n * An existing AV.Object which doesn't fulfill the Query is updated and now it fulfills the Query.\n * @event AV.LiveQuery#enter\n * @param {AV.Object|AV.File} target updated object\n * @param {String[]} updatedKeys updated keys\n */\n /**\n * An existing AV.Object which fulfills the Query is updated and now it doesn't fulfill the Query.\n * @event AV.LiveQuery#leave\n * @param {AV.Object|AV.File} target updated object\n * @param {String[]} updatedKeys updated keys\n */\n this.emit(op, target, updatedKeys);\n } else {\n /**\n * A new AV.Object which fulfills the Query you subscribe is created.\n * @event AV.LiveQuery#create\n * @param {AV.Object|AV.File} target updated object\n */\n /**\n * An existing AV.Object which fulfills the Query you subscribe is deleted.\n * @event AV.LiveQuery#delete\n * @param {AV.Object|AV.File} target updated object\n */\n this.emit(op, target);\n }\n });\n },\n /**\n * unsubscribe the query\n *\n * @return {Promise}\n */\n unsubscribe() {\n const client = this._client;\n client.off('message', this._onMessage);\n client.off('reconnect', this._onReconnect);\n client.deregister(this);\n return request({\n method: 'POST',\n path: '/LiveQuery/unsubscribe',\n data: {\n id: client.id,\n query_id: this.id,\n },\n });\n },\n },\n /** @lends AV.LiveQuery */\n {\n init(\n query,\n {\n subscriptionId: userDefinedSubscriptionId = AV._getSubscriptionId(),\n } = {}\n ) {\n requireRealtime();\n if (!(query instanceof AV.Query))\n throw new TypeError('LiveQuery must be inited with a Query');\n return Promise.resolve(userDefinedSubscriptionId).then(subscriptionId =>\n AV._config.realtime\n .createLiveQueryClient(subscriptionId)\n .then(liveQueryClient => {\n const { where, keys, returnACL } = query._getParams();\n const queryJSON = {\n where,\n keys,\n returnACL,\n className: query.className,\n };\n const promise = subscribe(queryJSON, subscriptionId)\n .then(\n ({ query_id: queryId }) =>\n new AV.LiveQuery(\n queryId,\n liveQueryClient,\n queryJSON,\n subscriptionId\n )\n )\n .finally(() => {\n liveQueryClient.deregister(promise);\n });\n liveQueryClient.register(promise);\n return promise;\n })\n );\n },\n /**\n * Pause the LiveQuery connection. This is useful to deactivate the SDK when the app is swtiched to background.\n * @static\n * @return void\n */\n pause() {\n requireRealtime();\n return AV._config.realtime.pause();\n },\n /**\n * Resume the LiveQuery connection. All subscriptions will be restored after reconnection.\n * @static\n * @return void\n */\n resume() {\n requireRealtime();\n return AV._config.realtime.resume();\n },\n }\n );\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/live-query.js","const _ = require('underscore');\nconst { tap } = require('./utils');\n\nmodule.exports = AV => {\n /**\n * @class\n * @example\n * AV.Captcha.request().then(captcha => {\n * captcha.bind({\n * textInput: 'code', // the id for textInput\n * image: 'captcha',\n * verifyButton: 'verify',\n * }, {\n * success: (validateCode) => {}, // next step\n * error: (error) => {}, // present error.message to user\n * });\n * });\n */\n AV.Captcha = function Captcha(options, authOptions) {\n this._options = options;\n this._authOptions = authOptions;\n /**\n * The image url of the captcha\n * @type string\n */\n this.url = undefined;\n /**\n * The captchaToken of the captcha.\n * @type string\n */\n this.captchaToken = undefined;\n /**\n * The validateToken of the captcha.\n * @type string\n */\n this.validateToken = undefined;\n };\n\n /**\n * Refresh the captcha\n * @return {Promise.} a new capcha url\n */\n AV.Captcha.prototype.refresh = function refresh() {\n return AV.Cloud._requestCaptcha(this._options, this._authOptions).then(\n ({ captchaToken, url }) => {\n _.extend(this, { captchaToken, url });\n return url;\n }\n );\n };\n\n /**\n * Verify the captcha\n * @param {String} code The code from user input\n * @return {Promise.} validateToken if the code is valid\n */\n AV.Captcha.prototype.verify = function verify(code) {\n return AV.Cloud.verifyCaptcha(code, this.captchaToken).then(\n tap(validateToken => (this.validateToken = validateToken))\n );\n };\n\n if (process.env.PLATFORM === 'Browser') {\n /**\n * Bind the captcha to HTMLElements. ONLY AVAILABLE in browsers.\n * @param [elements]\n * @param {String|HTMLInputElement} [elements.textInput] An input element typed text, or the id for the element.\n * @param {String|HTMLImageElement} [elements.image] An image element, or the id for the element.\n * @param {String|HTMLElement} [elements.verifyButton] A button element, or the id for the element.\n * @param [callbacks]\n * @param {Function} [callbacks.success] Success callback will be called if the code is verified. The param `validateCode` can be used for further SMS request.\n * @param {Function} [callbacks.error] Error callback will be called if something goes wrong, detailed in param `error.message`.\n */\n AV.Captcha.prototype.bind = function bind(\n { textInput, image, verifyButton },\n { success, error }\n ) {\n if (typeof textInput === 'string') {\n textInput = document.getElementById(textInput);\n if (!textInput)\n throw new Error(`textInput with id ${textInput} not found`);\n }\n if (typeof image === 'string') {\n image = document.getElementById(image);\n if (!image) throw new Error(`image with id ${image} not found`);\n }\n if (typeof verifyButton === 'string') {\n verifyButton = document.getElementById(verifyButton);\n if (!verifyButton)\n throw new Error(`verifyButton with id ${verifyButton} not found`);\n }\n\n this.__refresh = () =>\n this.refresh()\n .then(url => {\n image.src = url;\n if (textInput) {\n textInput.value = '';\n textInput.focus();\n }\n })\n .catch(err => console.warn(`refresh captcha fail: ${err.message}`));\n if (image) {\n this.__image = image;\n image.src = this.url;\n image.addEventListener('click', this.__refresh);\n }\n\n this.__verify = () => {\n const code = textInput.value;\n this.verify(code)\n .catch(err => {\n this.__refresh();\n throw err;\n })\n .then(success, error)\n .catch(err => console.warn(`verify captcha fail: ${err.message}`));\n };\n if (textInput && verifyButton) {\n this.__verifyButton = verifyButton;\n verifyButton.addEventListener('click', this.__verify);\n }\n };\n\n /**\n * unbind the captcha from HTMLElements. ONLY AVAILABLE in browsers.\n */\n AV.Captcha.prototype.unbind = function unbind() {\n if (this.__image)\n this.__image.removeEventListener('click', this.__refresh);\n if (this.__verifyButton)\n this.__verifyButton.removeEventListener('click', this.__verify);\n };\n }\n\n /**\n * Request a captcha\n * @param [options]\n * @param {Number} [options.width] width(px) of the captcha, ranged 60-200\n * @param {Number} [options.height] height(px) of the captcha, ranged 30-100\n * @param {Number} [options.size=4] length of the captcha, ranged 3-6. MasterKey required.\n * @param {Number} [options.ttl=60] time to live(s), ranged 10-180. MasterKey required.\n * @return {Promise.}\n */\n AV.Captcha.request = (options, authOptions) => {\n const captcha = new AV.Captcha(options, authOptions);\n return captcha.refresh().then(() => captcha);\n };\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/captcha.js","const _ = require('underscore');\nconst { _request, request } = require('./request');\n\nmodule.exports = function(AV) {\n /**\n * Contains functions for calling and declaring\n *
\n * Some functions are only available from Cloud Code.\n *
\n *\n * @namespace\n * @borrows AV.Captcha.request as requestCaptcha\n */\n AV.Cloud = AV.Cloud || {};\n\n _.extend(\n AV.Cloud,\n /** @lends AV.Cloud */ {\n /**\n * Makes a call to a cloud function.\n * @param {String} name The function name.\n * @param {Object} [data] The parameters to send to the cloud function.\n * @param {AuthOptions} [options]\n * @return {Promise} A promise that will be resolved with the result\n * of the function.\n */\n run(name, data, options) {\n return request({\n service: 'engine',\n method: 'POST',\n path: `/functions/${name}`,\n data: AV._encode(data, null, true),\n authOptions: options,\n }).then(resp => {\n return AV._decode(resp).result;\n });\n },\n\n /**\n * Makes a call to a cloud function, you can send {AV.Object} as param or a field of param; the response\n * from server will also be parsed as an {AV.Object}, array of {AV.Object}, or object includes {AV.Object}\n * @param {String} name The function name.\n * @param {Object} [data] The parameters to send to the cloud function.\n * @param {AuthOptions} [options]\n * @return {Promise} A promise that will be resolved with the result of the function.\n */\n rpc(name, data, options) {\n if (_.isArray(data)) {\n return Promise.reject(\n new Error(\n \"Can't pass Array as the param of rpc function in JavaScript SDK.\"\n )\n );\n }\n\n return request({\n service: 'engine',\n method: 'POST',\n path: `/call/${name}`,\n data: AV._encodeObjectOrArray(data),\n authOptions: options,\n }).then(resp => {\n return AV._decode(resp).result;\n });\n },\n\n /**\n * Make a call to request server date time.\n * @return {Promise.} A promise that will be resolved with the result\n * of the function.\n * @since 0.5.9\n */\n getServerDate() {\n return _request('date', null, null, 'GET').then(function(resp) {\n return AV._decode(resp);\n });\n },\n\n /**\n * Makes a call to request an sms code for operation verification.\n * @param {String|Object} data The mobile phone number string or a JSON\n * object that contains mobilePhoneNumber,template,sign,op,ttl,name etc.\n * @param {String} data.mobilePhoneNumber\n * @param {String} [data.template] sms template name\n * @param {String} [data.sign] sms signature name\n * @param {String} [data.smsType] sending code by `sms` (default) or `voice` call\n * @param {SMSAuthOptions} [options]\n * @return {Promise} A promise that will be resolved if the request succeed\n */\n requestSmsCode(data, options = {}) {\n if (_.isString(data)) {\n data = { mobilePhoneNumber: data };\n }\n if (!data.mobilePhoneNumber) {\n throw new Error('Missing mobilePhoneNumber.');\n }\n if (options.validateToken) {\n data = _.extend({}, data, {\n validate_token: options.validateToken,\n });\n }\n return _request('requestSmsCode', null, null, 'POST', data, options);\n },\n\n /**\n * Makes a call to verify sms code that sent by AV.Cloud.requestSmsCode\n * @param {String} code The sms code sent by AV.Cloud.requestSmsCode\n * @param {phone} phone The mobile phoner number.\n * @return {Promise} A promise that will be resolved with the result\n * of the function.\n */\n verifySmsCode(code, phone) {\n if (!code) throw new Error('Missing sms code.');\n var params = {};\n if (_.isString(phone)) {\n params['mobilePhoneNumber'] = phone;\n }\n\n return _request('verifySmsCode', code, null, 'POST', params);\n },\n\n _requestCaptcha(options, authOptions) {\n return _request(\n 'requestCaptcha',\n null,\n null,\n 'GET',\n options,\n authOptions\n ).then(({ captcha_url: url, captcha_token: captchaToken }) => ({\n captchaToken,\n url,\n }));\n },\n\n /**\n * Request a captcha.\n */\n requestCaptcha: AV.Captcha.request,\n\n /**\n * Verify captcha code. This is the low-level API for captcha.\n * Checkout {@link AV.Captcha} for high abstract APIs.\n * @param {String} code the code from user input\n * @param {String} captchaToken captchaToken returned by {@link AV.Cloud.requestCaptcha}\n * @return {Promise.} validateToken if the code is valid\n */\n verifyCaptcha(code, captchaToken) {\n return _request('verifyCaptcha', null, null, 'POST', {\n captcha_code: code,\n captcha_token: captchaToken,\n }).then(({ validate_token: validateToken }) => validateToken);\n },\n }\n );\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/cloudfunction.js","const request = require('./request').request;\n\nmodule.exports = function(AV) {\n AV.Installation = AV.Object.extend('_Installation');\n\n /**\n * @namespace\n */\n AV.Push = AV.Push || {};\n\n /**\n * Sends a push notification.\n * @param {Object} data The data of the push notification.\n * @param {String[]} [data.channels] An Array of channels to push to.\n * @param {Date} [data.push_time] A Date object for when to send the push.\n * @param {Date} [data.expiration_time] A Date object for when to expire\n * the push.\n * @param {Number} [data.expiration_interval] The seconds from now to expire the push.\n * @param {Number} [data.flow_control] The clients to notify per second\n * @param {AV.Query} [data.where] An AV.Query over AV.Installation that is used to match\n * a set of installations to push to.\n * @param {String} [data.cql] A CQL statement over AV.Installation that is used to match\n * a set of installations to push to.\n * @param {Object} data.data The data to send as part of the push.\n More details: https://url.leanapp.cn/pushData\n * @param {AuthOptions} [options]\n * @return {Promise}\n */\n AV.Push.send = function(data, options) {\n if (data.where) {\n data.where = data.where._getParams().where;\n }\n\n if (data.where && data.cql) {\n throw new Error(\"Both where and cql can't be set\");\n }\n\n if (data.push_time) {\n data.push_time = data.push_time.toJSON();\n }\n\n if (data.expiration_time) {\n data.expiration_time = data.expiration_time.toJSON();\n }\n\n if (data.expiration_time && data.expiration_interval) {\n throw new Error(\n \"Both expiration_time and expiration_interval can't be set\"\n );\n }\n\n return request({\n service: 'push',\n method: 'POST',\n path: '/push',\n data,\n authOptions: options,\n });\n };\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/push.js","const _ = require('underscore');\nconst AVRequest = require('./request')._request;\nconst { getSessionToken } = require('./utils');\n\nmodule.exports = function(AV) {\n const getUser = (options = {}) => {\n const sessionToken = getSessionToken(options);\n if (sessionToken) {\n return AV.User._fetchUserBySessionToken(getSessionToken(options));\n }\n return AV.User.currentAsync();\n };\n\n const getUserPointer = options =>\n getUser(options).then(currUser =>\n AV.Object.createWithoutData('_User', currUser.id)._toPointer()\n );\n\n /**\n * Contains functions to deal with Status in LeanCloud.\n * @class\n */\n AV.Status = function(imageUrl, message) {\n this.data = {};\n this.inboxType = 'default';\n this.query = null;\n if (imageUrl && typeof imageUrl === 'object') {\n this.data = imageUrl;\n } else {\n if (imageUrl) {\n this.data.image = imageUrl;\n }\n if (message) {\n this.data.message = message;\n }\n }\n return this;\n };\n\n _.extend(\n AV.Status.prototype,\n /** @lends AV.Status.prototype */ {\n /**\n * Gets the value of an attribute in status data.\n * @param {String} attr The string name of an attribute.\n */\n get: function(attr) {\n return this.data[attr];\n },\n /**\n * Sets a hash of model attributes on the status data.\n * @param {String} key The key to set.\n * @param {any} value The value to give it.\n */\n set: function(key, value) {\n this.data[key] = value;\n return this;\n },\n /**\n * Destroy this status,then it will not be avaiable in other user's inboxes.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled when the destroy\n * completes.\n */\n destroy: function(options) {\n if (!this.id)\n return Promise.reject(new Error('The status id is not exists.'));\n var request = AVRequest('statuses', null, this.id, 'DELETE', options);\n return request;\n },\n /**\n * Cast the AV.Status object to an AV.Object pointer.\n * @return {AV.Object} A AV.Object pointer.\n */\n toObject: function() {\n if (!this.id) return null;\n return AV.Object.createWithoutData('_Status', this.id);\n },\n _getDataJSON: function() {\n var json = _.clone(this.data);\n return AV._encode(json);\n },\n /**\n * Send a status by a AV.Query object.\n * @since 0.3.0\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled when the send\n * completes.\n * @example\n * // send a status to male users\n * var status = new AVStatus('image url', 'a message');\n * status.query = new AV.Query('_User');\n * status.query.equalTo('gender', 'male');\n * status.send().then(function(){\n * //send status successfully.\n * }, function(err){\n * //an error threw.\n * console.dir(err);\n * });\n */\n send: function(options = {}) {\n if (!getSessionToken(options) && !AV.User.current()) {\n throw new Error('Please signin an user.');\n }\n if (!this.query) {\n return AV.Status.sendStatusToFollowers(this, options);\n }\n\n return getUserPointer(options)\n .then(currUser => {\n var query = this.query._getParams();\n query.className = this.query.className;\n var data = {};\n data.query = query;\n this.data = this.data || {};\n this.data.source = this.data.source || currUser;\n data.data = this._getDataJSON();\n data.inboxType = this.inboxType || 'default';\n\n return AVRequest('statuses', null, null, 'POST', data, options);\n })\n .then(response => {\n this.id = response.objectId;\n this.createdAt = AV._parseDate(response.createdAt);\n return this;\n });\n },\n\n _finishFetch: function(serverData) {\n this.id = serverData.objectId;\n this.createdAt = AV._parseDate(serverData.createdAt);\n this.updatedAt = AV._parseDate(serverData.updatedAt);\n this.messageId = serverData.messageId;\n delete serverData.messageId;\n delete serverData.objectId;\n delete serverData.createdAt;\n delete serverData.updatedAt;\n this.data = AV._decode(serverData);\n },\n }\n );\n\n /**\n * Send a status to current signined user's followers.\n * @since 0.3.0\n * @param {AV.Status} status A status object to be send to followers.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled when the send\n * completes.\n * @example\n * var status = new AVStatus('image url', 'a message');\n * AV.Status.sendStatusToFollowers(status).then(function(){\n * //send status successfully.\n * }, function(err){\n * //an error threw.\n * console.dir(err);\n * });\n */\n AV.Status.sendStatusToFollowers = function(status, options = {}) {\n if (!getSessionToken(options) && !AV.User.current()) {\n throw new Error('Please signin an user.');\n }\n return getUserPointer(options).then(currUser => {\n var query = {};\n query.className = '_Follower';\n query.keys = 'follower';\n query.where = { user: currUser };\n var data = {};\n data.query = query;\n status.data = status.data || {};\n status.data.source = status.data.source || currUser;\n data.data = status._getDataJSON();\n data.inboxType = status.inboxType || 'default';\n\n var request = AVRequest('statuses', null, null, 'POST', data, options);\n return request.then(function(response) {\n status.id = response.objectId;\n status.createdAt = AV._parseDate(response.createdAt);\n return status;\n });\n });\n };\n\n /**\n *
Send a status from current signined user to other user's private status inbox.
\n * @since 0.3.0\n * @param {AV.Status} status A status object to be send to followers.\n * @param {String} target The target user or user's objectId.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled when the send\n * completes.\n * @example\n * // send a private status to user '52e84e47e4b0f8de283b079b'\n * var status = new AVStatus('image url', 'a message');\n * AV.Status.sendPrivateStatus(status, '52e84e47e4b0f8de283b079b').then(function(){\n * //send status successfully.\n * }, function(err){\n * //an error threw.\n * console.dir(err);\n * });\n */\n AV.Status.sendPrivateStatus = function(status, target, options = {}) {\n if (!getSessionToken(options) && !AV.User.current()) {\n throw new Error('Please signin an user.');\n }\n if (!target) {\n throw new Error('Invalid target user.');\n }\n var userObjectId = _.isString(target) ? target : target.id;\n if (!userObjectId) {\n throw new Error('Invalid target user.');\n }\n return getUserPointer(options).then(currUser => {\n var query = {};\n query.className = '_User';\n query.where = { objectId: userObjectId };\n var data = {};\n data.query = query;\n status.data = status.data || {};\n status.data.source = status.data.source || currUser;\n data.data = status._getDataJSON();\n data.inboxType = 'private';\n status.inboxType = 'private';\n\n var request = AVRequest('statuses', null, null, 'POST', data, options);\n return request.then(function(response) {\n status.id = response.objectId;\n status.createdAt = AV._parseDate(response.createdAt);\n return status;\n });\n });\n };\n\n /**\n * Count unread statuses in someone's inbox.\n * @since 0.3.0\n * @param {AV.User} owner The status owner.\n * @param {String} inboxType The inbox type, 'default' by default.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled when the count\n * completes.\n * @example\n * AV.Status.countUnreadStatuses(AV.User.current()).then(function(response){\n * console.log(response.unread); //unread statuses number.\n * console.log(response.total); //total statuses number.\n * });\n */\n AV.Status.countUnreadStatuses = function(\n owner,\n inboxType = 'default',\n options = {}\n ) {\n if (!_.isString(inboxType)) options = inboxType;\n if (!getSessionToken(options) && owner == null && !AV.User.current()) {\n throw new Error('Please signin an user or pass the owner objectId.');\n }\n return Promise.resolve(owner || getUser(options)).then(owner => {\n var params = {};\n params.inboxType = AV._encode(inboxType);\n params.owner = AV._encode(owner);\n return AVRequest(\n 'subscribe/statuses/count',\n null,\n null,\n 'GET',\n params,\n options\n );\n });\n };\n\n /**\n * reset unread statuses count in someone's inbox.\n * @since 2.1.0\n * @param {AV.User} owner The status owner.\n * @param {String} inboxType The inbox type, 'default' by default.\n * @param {AuthOptions} options\n * @return {Promise} A promise that is fulfilled when the reset\n * completes.\n * @example\n * AV.Status.resetUnreadCount(AV.User.current()).then(function(response){\n * console.log(response.unread); //unread statuses number.\n * console.log(response.total); //total statuses number.\n * });\n */\n AV.Status.resetUnreadCount = function(\n owner,\n inboxType = 'default',\n options = {}\n ) {\n if (!_.isString(inboxType)) options = inboxType;\n if (!getSessionToken(options) && owner == null && !AV.User.current()) {\n throw new Error('Please signin an user or pass the owner objectId.');\n }\n return Promise.resolve(owner || getUser(options)).then(owner => {\n var params = {};\n params.inboxType = AV._encode(inboxType);\n params.owner = AV._encode(owner);\n return AVRequest(\n 'subscribe/statuses/resetUnreadCount',\n null,\n null,\n 'POST',\n params,\n options\n );\n });\n };\n\n /**\n * Create a status query to find someone's published statuses.\n * @since 0.3.0\n * @param {AV.User} source The status source, typically the publisher.\n * @return {AV.Query} The query object for status.\n * @example\n * //Find current user's published statuses.\n * var query = AV.Status.statusQuery(AV.User.current());\n * query.find().then(function(statuses){\n * //process statuses\n * });\n */\n AV.Status.statusQuery = function(source) {\n var query = new AV.Query('_Status');\n if (source) {\n query.equalTo('source', source);\n }\n return query;\n };\n\n /**\n *
AV.InboxQuery defines a query that is used to fetch somebody's inbox statuses.
\n * @class\n */\n AV.InboxQuery = AV.Query._extend(\n /** @lends AV.InboxQuery.prototype */ {\n _objectClass: AV.Status,\n _sinceId: 0,\n _maxId: 0,\n _inboxType: 'default',\n _owner: null,\n _newObject: function() {\n return new AV.Status();\n },\n _createRequest: function(params, options) {\n return AV.InboxQuery.__super__._createRequest.call(\n this,\n params,\n options,\n '/subscribe/statuses'\n );\n },\n\n /**\n * Sets the messageId of results to skip before returning any results.\n * This is useful for pagination.\n * Default is zero.\n * @param {Number} n the mesage id.\n * @return {AV.InboxQuery} Returns the query, so you can chain this call.\n */\n sinceId: function(id) {\n this._sinceId = id;\n return this;\n },\n /**\n * Sets the maximal messageId of results。\n * This is useful for pagination.\n * Default is zero that is no limition.\n * @param {Number} n the mesage id.\n * @return {AV.InboxQuery} Returns the query, so you can chain this call.\n */\n maxId: function(id) {\n this._maxId = id;\n return this;\n },\n /**\n * Sets the owner of the querying inbox.\n * @param {AV.User} owner The inbox owner.\n * @return {AV.InboxQuery} Returns the query, so you can chain this call.\n */\n owner: function(owner) {\n this._owner = owner;\n return this;\n },\n /**\n * Sets the querying inbox type.default is 'default'.\n * @param {String} type The inbox type.\n * @return {AV.InboxQuery} Returns the query, so you can chain this call.\n */\n inboxType: function(type) {\n this._inboxType = type;\n return this;\n },\n _getParams: function() {\n var params = AV.InboxQuery.__super__._getParams.call(this);\n params.owner = AV._encode(this._owner);\n params.inboxType = AV._encode(this._inboxType);\n params.sinceId = AV._encode(this._sinceId);\n params.maxId = AV._encode(this._maxId);\n return params;\n },\n }\n );\n\n /**\n * Create a inbox status query to find someone's inbox statuses.\n * @since 0.3.0\n * @param {AV.User} owner The inbox's owner\n * @param {String} inboxType The inbox type,'default' by default.\n * @return {AV.InboxQuery} The inbox query object.\n * @see AV.InboxQuery\n * @example\n * //Find current user's default inbox statuses.\n * var query = AV.Status.inboxQuery(AV.User.current());\n * //find the statuses after the last message id\n * query.sinceId(lastMessageId);\n * query.find().then(function(statuses){\n * //process statuses\n * });\n */\n AV.Status.inboxQuery = function(owner, inboxType) {\n var query = new AV.InboxQuery(AV.Status);\n if (owner) {\n query._owner = owner;\n }\n if (inboxType) {\n query._inboxType = inboxType;\n }\n return query;\n };\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/status.js","const _ = require('underscore');\nconst AVRequest = require('./request')._request;\n\nmodule.exports = function(AV) {\n /**\n * A builder to generate sort string for app searching.For example:\n * @class\n * @since 0.5.1\n * @example\n * var builder = new AV.SearchSortBuilder();\n * builder.ascending('key1').descending('key2','max');\n * var query = new AV.SearchQuery('Player');\n * query.sortBy(builder);\n * query.find().then();\n */\n AV.SearchSortBuilder = function() {\n this._sortFields = [];\n };\n\n _.extend(\n AV.SearchSortBuilder.prototype,\n /** @lends AV.SearchSortBuilder.prototype */ {\n _addField: function(key, order, mode, missing) {\n var field = {};\n field[key] = {\n order: order || 'asc',\n mode: mode || 'avg',\n missing: '_' + (missing || 'last'),\n };\n this._sortFields.push(field);\n return this;\n },\n\n /**\n * Sorts the results in ascending order by the given key and options.\n *\n * @param {String} key The key to order by.\n * @param {String} mode The sort mode, default is 'avg', you can choose\n * 'max' or 'min' too.\n * @param {String} missing The missing key behaviour, default is 'last',\n * you can choose 'first' too.\n * @return {AV.SearchSortBuilder} Returns the builder, so you can chain this call.\n */\n ascending: function(key, mode, missing) {\n return this._addField(key, 'asc', mode, missing);\n },\n\n /**\n * Sorts the results in descending order by the given key and options.\n *\n * @param {String} key The key to order by.\n * @param {String} mode The sort mode, default is 'avg', you can choose\n * 'max' or 'min' too.\n * @param {String} missing The missing key behaviour, default is 'last',\n * you can choose 'first' too.\n * @return {AV.SearchSortBuilder} Returns the builder, so you can chain this call.\n */\n descending: function(key, mode, missing) {\n return this._addField(key, 'desc', mode, missing);\n },\n\n /**\n * Add a proximity based constraint for finding objects with key point\n * values near the point given.\n * @param {String} key The key that the AV.GeoPoint is stored in.\n * @param {AV.GeoPoint} point The reference AV.GeoPoint that is used.\n * @param {Object} options The other options such as mode,order, unit etc.\n * @return {AV.SearchSortBuilder} Returns the builder, so you can chain this call.\n */\n whereNear: function(key, point, options) {\n options = options || {};\n var field = {};\n var geo = {\n lat: point.latitude,\n lon: point.longitude,\n };\n var m = {\n order: options.order || 'asc',\n mode: options.mode || 'avg',\n unit: options.unit || 'km',\n };\n m[key] = geo;\n field['_geo_distance'] = m;\n\n this._sortFields.push(field);\n return this;\n },\n\n /**\n * Build a sort string by configuration.\n * @return {String} the sort string.\n */\n build: function() {\n return JSON.stringify(AV._encode(this._sortFields));\n },\n }\n );\n\n /**\n * App searching query.Use just like AV.Query:\n *\n * Visit App Searching Guide\n * for more details.\n * @class\n * @since 0.5.1\n * @example\n * var query = new AV.SearchQuery('Player');\n * query.queryString('*');\n * query.find().then(function(results) {\n * console.log('Found %d objects', query.hits());\n * //Process results\n * });\n */\n AV.SearchQuery = AV.Query._extend(\n /** @lends AV.SearchQuery.prototype */ {\n _sid: null,\n _hits: 0,\n _queryString: null,\n _highlights: null,\n _sortBuilder: null,\n _clazz: null,\n\n constructor: function(className) {\n if (className) {\n this._clazz = className;\n } else {\n className = '__INVALID_CLASS';\n }\n AV.Query.call(this, className);\n },\n\n _createRequest: function(params, options) {\n return AVRequest(\n 'search/select',\n null,\n null,\n 'GET',\n params || this._getParams(),\n options\n );\n },\n\n /**\n * Sets the sid of app searching query.Default is null.\n * @param {String} sid Scroll id for searching.\n * @return {AV.SearchQuery} Returns the query, so you can chain this call.\n */\n sid: function(sid) {\n this._sid = sid;\n return this;\n },\n\n /**\n * Sets the query string of app searching.\n * @param {String} q The query string.\n * @return {AV.SearchQuery} Returns the query, so you can chain this call.\n */\n queryString: function(q) {\n this._queryString = q;\n return this;\n },\n\n /**\n * Sets the highlight fields. Such as\n *
\n * @param {String|String[]} highlights a list of fields.\n * @return {AV.SearchQuery} Returns the query, so you can chain this call.\n */\n highlights: function(highlights) {\n var objects;\n if (highlights && _.isString(highlights)) {\n objects = _.toArray(arguments);\n } else {\n objects = highlights;\n }\n this._highlights = objects;\n return this;\n },\n\n /**\n * Sets the sort builder for this query.\n * @see AV.SearchSortBuilder\n * @param { AV.SearchSortBuilder} builder The sort builder.\n * @return {AV.SearchQuery} Returns the query, so you can chain this call.\n *\n */\n sortBy: function(builder) {\n this._sortBuilder = builder;\n return this;\n },\n\n /**\n * Returns the number of objects that match this query.\n * @return {Number}\n */\n hits: function() {\n if (!this._hits) {\n this._hits = 0;\n }\n return this._hits;\n },\n\n _processResult: function(json) {\n delete json['className'];\n delete json['_app_url'];\n delete json['_deeplink'];\n return json;\n },\n\n /**\n * Returns true when there are more documents can be retrieved by this\n * query instance, you can call find function to get more results.\n * @see AV.SearchQuery#find\n * @return {Boolean}\n */\n hasMore: function() {\n return !this._hitEnd;\n },\n\n /**\n * Reset current query instance state(such as sid, hits etc) except params\n * for a new searching. After resetting, hasMore() will return true.\n */\n reset: function() {\n this._hitEnd = false;\n this._sid = null;\n this._hits = 0;\n },\n\n /**\n * Retrieves a list of AVObjects that satisfy this query.\n * Either options.success or options.error is called when the find\n * completes.\n *\n * @see AV.Query#find\n * @param {AuthOptions} options\n * @return {Promise} A promise that is resolved with the results when\n * the query completes.\n */\n find: function(options) {\n var self = this;\n\n var request = this._createRequest(undefined, options);\n\n return request.then(function(response) {\n //update sid for next querying.\n if (response.sid) {\n self._oldSid = self._sid;\n self._sid = response.sid;\n } else {\n self._sid = null;\n self._hitEnd = true;\n }\n self._hits = response.hits || 0;\n\n return _.map(response.results, function(json) {\n if (json.className) {\n response.className = json.className;\n }\n var obj = self._newObject(response);\n obj.appURL = json['_app_url'];\n obj._finishFetch(self._processResult(json), true);\n return obj;\n });\n });\n },\n\n _getParams: function() {\n var params = AV.SearchQuery.__super__._getParams.call(this);\n delete params.where;\n if (this._clazz) {\n params.clazz = this.className;\n }\n if (this._sid) {\n params.sid = this._sid;\n }\n if (!this._queryString) {\n throw new Error('Please set query string.');\n } else {\n params.q = this._queryString;\n }\n if (this._highlights) {\n params.highlights = this._highlights.join(',');\n }\n if (this._sortBuilder && params.order) {\n throw new Error('sort and order can not be set at same time.');\n }\n if (this._sortBuilder) {\n params.sort = this._sortBuilder.build();\n }\n\n return params;\n },\n }\n );\n};\n\n/**\n * Sorts the results in ascending order by the given key.\n *\n * @method AV.SearchQuery#ascending\n * @param {String} key The key to order by.\n * @return {AV.SearchQuery} Returns the query, so you can chain this call.\n */\n/**\n * Also sorts the results in ascending order by the given key. The previous sort keys have\n * precedence over this key.\n *\n * @method AV.SearchQuery#addAscending\n * @param {String} key The key to order by\n * @return {AV.SearchQuery} Returns the query so you can chain this call.\n */\n/**\n * Sorts the results in descending order by the given key.\n *\n * @method AV.SearchQuery#descending\n * @param {String} key The key to order by.\n * @return {AV.SearchQuery} Returns the query, so you can chain this call.\n */\n/**\n * Also sorts the results in descending order by the given key. The previous sort keys have\n * precedence over this key.\n *\n * @method AV.SearchQuery#addDescending\n * @param {String} key The key to order by\n * @return {AV.SearchQuery} Returns the query so you can chain this call.\n */\n/**\n * Include nested AV.Objects for the provided key. You can use dot\n * notation to specify which fields in the included object are also fetch.\n * @method AV.SearchQuery#include\n * @param {String[]} keys The name of the key to include.\n * @return {AV.SearchQuery} Returns the query, so you can chain this call.\n */\n/**\n * Sets the number of results to skip before returning any results.\n * This is useful for pagination.\n * Default is to skip zero results.\n * @method AV.SearchQuery#skip\n * @param {Number} n the number of results to skip.\n * @return {AV.SearchQuery} Returns the query, so you can chain this call.\n */\n/**\n * Sets the limit of the number of results to return. The default limit is\n * 100, with a maximum of 1000 results being returned at a time.\n * @method AV.SearchQuery#limit\n * @param {Number} n the number of results to limit to.\n * @return {AV.SearchQuery} Returns the query, so you can chain this call.\n */\n\n\n\n// WEBPACK FOOTER //\n// ./src/search.js","const _ = require('underscore');\nconst AVError = require('./error');\nconst { request } = require('./request');\n\nmodule.exports = function(AV) {\n /**\n * 包含了使用了 LeanCloud\n * 离线数据分析功能的函数。\n *
\n * { \"sql\" : \"select count(*) as c,gender from _User group by gender\",\n * \"saveAs\": {\n * \"className\" : \"UserGender\",\n * \"limit\": 1\n * }\n * }\n *
\n * sql 指定任务执行的 SQL 语句, saveAs(可选) 指定将结果保存在哪张表里,limit 最大 1000。\n * @param {AuthOptions} [options]\n * @return {Promise} A promise that will be resolved with the result\n * of the function.\n */\n startJob: function(jobConfig, options) {\n if (!jobConfig || !jobConfig.sql) {\n throw new Error('Please provide the sql to run the job.');\n }\n var data = {\n jobConfig: jobConfig,\n appId: AV.applicationId,\n };\n return request({\n path: '/bigquery/jobs',\n method: 'POST',\n data: AV._encode(data, null, true),\n authOptions: options,\n signKey: false,\n }).then(resp => AV._decode(resp).id);\n },\n\n /**\n * 监听 Insight 任务事件(未来推出独立部署的离线分析服务后开放)\n *
\n * 仅在云引擎运行环境下有效。\n *
\n * @param {String} event 监听的事件,目前尚不支持。\n * @param {Function} 监听回调函数,接收 (err, id) 两个参数,err 表示错误信息,\n * id 表示任务 id。接下来你可以拿这个 id 使用AV.Insight.JobQuery 查询任务状态和结果。\n *\n */\n on: function(event, cb) {},\n }\n );\n\n /**\n * 创建一个对象,用于查询 Insight 任务状态和结果。\n * @class\n * @param {String} id 任务 id\n * @since 0.5.5\n */\n AV.Insight.JobQuery = function(id, className) {\n if (!id) {\n throw new Error('Please provide the job id.');\n }\n this.id = id;\n this.className = className;\n this._skip = 0;\n this._limit = 100;\n };\n\n _.extend(\n AV.Insight.JobQuery.prototype,\n /** @lends AV.Insight.JobQuery.prototype */ {\n /**\n * Sets the number of results to skip before returning any results.\n * This is useful for pagination.\n * Default is to skip zero results.\n * @param {Number} n the number of results to skip.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n skip: function(n) {\n this._skip = n;\n return this;\n },\n\n /**\n * Sets the limit of the number of results to return. The default limit is\n * 100, with a maximum of 1000 results being returned at a time.\n * @param {Number} n the number of results to limit to.\n * @return {AV.Query} Returns the query, so you can chain this call.\n */\n limit: function(n) {\n this._limit = n;\n return this;\n },\n\n /**\n * 查询任务状态和结果,任务结果为一个 JSON 对象,包括 status 表示任务状态, totalCount 表示总数,\n * results 数组表示任务结果数组,previewCount 表示可以返回的结果总数,任务的开始和截止时间\n * startTime、endTime 等信息。\n *\n * @param {AuthOptions} [options]\n * @return {Promise} A promise that will be resolved with the result\n * of the function.\n *\n */\n find: function(options) {\n var params = {\n skip: this._skip,\n limit: this._limit,\n };\n\n return request({\n path: `/bigquery/jobs/${this.id}`,\n method: 'GET',\n query: params,\n authOptions: options,\n signKey: false,\n }).then(function(response) {\n if (response.error) {\n return Promise.reject(new AVError(response.code, response.error));\n }\n return Promise.resolve(response);\n });\n },\n }\n );\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/insight.js","const _ = require('underscore');\nconst { request: LCRequest } = require('./request');\nconst { getSessionToken } = require('./utils');\n\nmodule.exports = function(AV) {\n const getUserWithSessionToken = authOptions => {\n if (authOptions.user) {\n if (!authOptions.user._sessionToken) {\n throw new Error('authOptions.user is not signed in.');\n }\n return Promise.resolve(authOptions.user);\n }\n if (authOptions.sessionToken) {\n return AV.User._fetchUserBySessionToken(authOptions.sessionToken);\n }\n return AV.User.currentAsync();\n };\n\n const getSessionTokenAsync = authOptions => {\n const sessionToken = getSessionToken(authOptions);\n if (sessionToken) {\n return Promise.resolve(sessionToken);\n }\n return AV.User.currentAsync().then(user => {\n if (user) {\n return user.getSessionToken();\n }\n });\n };\n\n /**\n * Contains functions to deal with Friendship in LeanCloud.\n * @class\n */\n AV.Friendship = {\n /**\n * Request friendship.\n * @since 4.8.0\n * @param {String | AV.User | Object} options if an AV.User or string is given, it will be used as the friend.\n * @param {AV.User | string} options.friend The friend (or friend's objectId) to follow.\n * @param {Object} [options.attributes] key-value attributes dictionary to be used as conditions of followeeQuery.\n * @param {AuthOptions} [authOptions]\n * @return {Promise}\n */\n request: function(options, authOptions = {}) {\n let friend;\n let attributes;\n\n if (options.friend) {\n friend = options.friend;\n attributes = options.attributes;\n } else {\n friend = options;\n }\n\n const friendObj = _.isString(friend)\n ? AV.Object.createWithoutData('_User', friend)\n : friend;\n\n return getUserWithSessionToken(authOptions).then(userObj => {\n if (!userObj) {\n throw new Error('Please signin an user.');\n }\n return LCRequest({\n method: 'POST',\n path: '/users/friendshipRequests',\n data: {\n user: userObj._toPointer(),\n friend: friendObj._toPointer(),\n friendship: attributes,\n },\n authOptions,\n });\n });\n },\n\n /**\n * Accept a friendship request.\n * @since 4.8.0\n * @param {AV.Object | string | Object} options if an AV.Object or string is given, it will be used as the request in _FriendshipRequest.\n * @param {AV.Object} options.request The request (or it's objectId) to be accepted.\n * @param {Object} [options.attributes] key-value attributes dictionary to be used as conditions of {@link AV#followeeQuery}.\n * @param {AuthOptions} [authOptions]\n * @return {Promise}\n */\n acceptRequest: function(options, authOptions = {}) {\n let request;\n let attributes;\n if (options.request) {\n request = options.request;\n attributes = options.attributes;\n } else {\n request = options;\n }\n const requestId = _.isString(request) ? request : request.id;\n return getSessionTokenAsync(authOptions).then(sessionToken => {\n if (!sessionToken) {\n throw new Error('Please signin an user.');\n }\n return LCRequest({\n method: 'PUT',\n path: '/users/friendshipRequests/' + requestId + '/accept',\n data: {\n friendship: AV._encode(attributes),\n },\n authOptions,\n });\n });\n },\n\n /**\n * Decline a friendship request.\n * @param {AV.Object | string} request The request (or it's objectId) to be declined.\n * @param {AuthOptions} [authOptions]\n * @return {Promise}\n */\n declineRequest: function(request, authOptions = {}) {\n const requestId = _.isString(request) ? request : request.id;\n return getSessionTokenAsync(authOptions).then(sessionToken => {\n if (!sessionToken) {\n throw new Error('Please signin an user.');\n }\n return LCRequest({\n method: 'PUT',\n path: '/users/friendshipRequests/' + requestId + '/decline',\n authOptions,\n });\n });\n },\n };\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/friendship.js","const _ = require('underscore');\nconst { _request } = require('./request');\nconst AV = require('./av');\n\nconst serializeMessage = message => {\n if (typeof message === 'string') {\n return message;\n }\n if (typeof message.getPayload === 'function') {\n return JSON.stringify(message.getPayload());\n }\n return JSON.stringify(message);\n};\n\n/**\n *
An AV.Conversation is a local representation of a LeanCloud realtime's\n * conversation. This class is a subclass of AV.Object, and retains the\n * same functionality of an AV.Object, but also extends it with various\n * conversation specific methods, like get members, creators of this conversation.\n *
\n *\n * @class AV.Conversation\n * @param {String} name The name of the Role to create.\n * @param {Object} [options]\n * @param {Boolean} [options.isSystem] Set this conversation as system conversation.\n * @param {Boolean} [options.isTransient] Set this conversation as transient conversation.\n */\nmodule.exports = AV.Object.extend(\n '_Conversation',\n /** @lends AV.Conversation.prototype */ {\n constructor(name, options = {}) {\n AV.Object.prototype.constructor.call(this, null, null);\n this.set('name', name);\n if (options.isSystem !== undefined) {\n this.set('sys', options.isSystem ? true : false);\n }\n if (options.isTransient !== undefined) {\n this.set('tr', options.isTransient ? true : false);\n }\n },\n /**\n * Get current conversation's creator.\n *\n * @return {String}\n */\n getCreator() {\n return this.get('c');\n },\n\n /**\n * Get the last message's time.\n *\n * @return {Date}\n */\n getLastMessageAt() {\n return this.get('lm');\n },\n\n /**\n * Get this conversation's members\n *\n * @return {String[]}\n */\n getMembers() {\n return this.get('m');\n },\n\n /**\n * Add a member to this conversation\n *\n * @param {String} member\n */\n addMember(member) {\n return this.add('m', member);\n },\n\n /**\n * Get this conversation's members who set this conversation as muted.\n *\n * @return {String[]}\n */\n getMutedMembers() {\n return this.get('mu');\n },\n\n /**\n * Get this conversation's name field.\n *\n * @return String\n */\n getName() {\n return this.get('name');\n },\n\n /**\n * Returns true if this conversation is transient conversation.\n *\n * @return {Boolean}\n */\n isTransient() {\n return this.get('tr');\n },\n\n /**\n * Returns true if this conversation is system conversation.\n *\n * @return {Boolean}\n */\n isSystem() {\n return this.get('sys');\n },\n\n /**\n * Send realtime message to this conversation, using HTTP request.\n *\n * @param {String} fromClient Sender's client id.\n * @param {String|Object} message The message which will send to conversation.\n * It could be a raw string, or an object with a `toJSON` method, like a\n * realtime SDK's Message object. See more: {@link https://leancloud.cn/docs/realtime_guide-js.html#消息}\n * @param {Object} [options]\n * @param {Boolean} [options.transient] Whether send this message as transient message or not.\n * @param {String[]} [options.toClients] Ids of clients to send to. This option can be used only in system conversation.\n * @param {Object} [options.pushData] Push data to this message. See more: {@link https://url.leanapp.cn/pushData 推送消息内容}\n * @param {AuthOptions} [authOptions]\n * @return {Promise}\n */\n send(fromClient, message, options = {}, authOptions = {}) {\n const data = {\n from_peer: fromClient,\n conv_id: this.id,\n transient: false,\n message: serializeMessage(message),\n };\n if (options.toClients !== undefined) {\n data.to_peers = options.toClients;\n }\n if (options.transient !== undefined) {\n data.transient = options.transient ? true : false;\n }\n if (options.pushData !== undefined) {\n data.push_data = options.pushData;\n }\n return _request('rtm', 'messages', null, 'POST', data, authOptions);\n },\n\n /**\n * Send realtime broadcast message to all clients, via this conversation, using HTTP request.\n *\n * @param {String} fromClient Sender's client id.\n * @param {String|Object} message The message which will send to conversation.\n * It could be a raw string, or an object with a `toJSON` method, like a\n * realtime SDK's Message object. See more: {@link https://leancloud.cn/docs/realtime_guide-js.html#消息}.\n * @param {Object} [options]\n * @param {Object} [options.pushData] Push data to this message. See more: {@link https://url.leanapp.cn/pushData 推送消息内容}.\n * @param {Object} [options.validTill] The message will valid till this time.\n * @param {AuthOptions} [authOptions]\n * @return {Promise}\n */\n broadcast(fromClient, message, options = {}, authOptions = {}) {\n const data = {\n from_peer: fromClient,\n conv_id: this.id,\n message: serializeMessage(message),\n };\n if (options.pushData !== undefined) {\n data.push = options.pushData;\n }\n if (options.validTill !== undefined) {\n let ts = options.validTill;\n if (_.isDate(ts)) {\n ts = ts.getTime();\n }\n options.valid_till = ts;\n }\n return _request('rtm', 'broadcast', null, 'POST', data, authOptions);\n },\n }\n);\n\n\n\n// WEBPACK FOOTER //\n// ./src/conversation.js","const _ = require('underscore');\nconst { request } = require('./request');\nconst { ensureArray, parseDate } = require('./utils');\nconst AV = require('./av');\n\n/**\n * The version change interval for Leaderboard\n * @enum\n */\nAV.LeaderboardVersionChangeInterval = {\n NEVER: 'never',\n DAY: 'day',\n WEEK: 'week',\n MONTH: 'month',\n};\n\n/**\n * The order of the leaderboard results\n * @enum\n */\nAV.LeaderboardOrder = {\n ASCENDING: 'ascending',\n DESCENDING: 'descending',\n};\n\n/**\n * The update strategy for Leaderboard\n * @enum\n */\nAV.LeaderboardUpdateStrategy = {\n /** Only keep the best statistic. If the leaderboard is in descending order, the best statistic is the highest one. */\n BETTER: 'better',\n /** Keep the last updated statistic */\n LAST: 'last',\n /** Keep the sum of all updated statistics */\n SUM: 'sum',\n};\n\n/**\n * @typedef {Object} Ranking\n * @property {number} rank Starts at 0\n * @property {number} value the statistic value of this ranking\n * @property {AV.User} user The user of this ranking\n * @property {Statistic[]} [includedStatistics] Other statistics of the user, specified by the `includeStatistic` option of `AV.Leaderboard.getResults()`\n */\n\n/**\n * @typedef {Object} LeaderboardArchive\n * @property {string} statisticName\n * @property {number} version version of the leaderboard\n * @property {string} status\n * @property {string} url URL for the downloadable archive\n * @property {Date} activatedAt time when this version became active\n * @property {Date} deactivatedAt time when this version was deactivated by a version incrementing\n */\n\n/**\n * @class\n */\nfunction Statistic({ name, value, version }) {\n /**\n * @type {string}\n */\n this.name = name;\n /**\n * @type {number}\n */\n this.value = value;\n /**\n * @type {number?}\n */\n this.version = version;\n}\n\nconst parseStatisticData = statisticData => {\n const { statisticName: name, statisticValue: value, version } = AV._decode(\n statisticData\n );\n return new Statistic({ name, value, version });\n};\n\n/**\n * @class\n */\nAV.Leaderboard = function Leaderboard(statisticName) {\n /**\n * @type {string}\n */\n this.statisticName = statisticName;\n /**\n * @type {AV.LeaderboardOrder}\n */\n this.order = undefined;\n /**\n * @type {AV.LeaderboardUpdateStrategy}\n */\n this.updateStrategy = undefined;\n /**\n * @type {AV.LeaderboardVersionChangeInterval}\n */\n this.versionChangeInterval = undefined;\n /**\n * @type {number}\n */\n this.version = undefined;\n /**\n * @type {Date?}\n */\n this.nextResetAt = undefined;\n /**\n * @type {Date?}\n */\n this.createdAt = undefined;\n};\nconst Leaderboard = AV.Leaderboard;\n\n/**\n * Create an instance of Leaderboard for the give statistic name.\n * @param {string} statisticName\n * @return {AV.Leaderboard}\n */\nAV.Leaderboard.createWithoutData = statisticName =>\n new Leaderboard(statisticName);\n/**\n * (masterKey required) Create a new Leaderboard.\n * @param {Object} options\n * @param {string} options.statisticName\n * @param {AV.LeaderboardOrder} options.order\n * @param {AV.LeaderboardVersionChangeInterval} [options.versionChangeInterval] default to WEEK\n * @param {AV.LeaderboardUpdateStrategy} [options.updateStrategy] default to BETTER\n * @param {AuthOptions} [authOptions]\n * @return {Promise}\n */\nAV.Leaderboard.createLeaderboard = (\n { statisticName, order, versionChangeInterval, updateStrategy },\n authOptions\n) =>\n request({\n method: 'POST',\n path: '/leaderboard/leaderboards',\n data: {\n statisticName,\n order,\n versionChangeInterval,\n updateStrategy,\n },\n authOptions,\n }).then(data => {\n const leaderboard = new Leaderboard(statisticName);\n return leaderboard._finishFetch(data);\n });\n/**\n * Get the Leaderboard with the specified statistic name.\n * @param {string} statisticName\n * @param {AuthOptions} [authOptions]\n * @return {Promise}\n */\nAV.Leaderboard.getLeaderboard = (statisticName, authOptions) =>\n Leaderboard.createWithoutData(statisticName).fetch(authOptions);\n/**\n * Get Statistics for the specified user.\n * @param {AV.User} user The specified AV.User pointer.\n * @param {Object} [options]\n * @param {string[]} [options.statisticNames] Specify the statisticNames. If not set, all statistics of the user will be fetched.\n * @param {AuthOptions} [authOptions]\n * @return {Promise}\n */\nAV.Leaderboard.getStatistics = (user, { statisticNames } = {}, authOptions) =>\n Promise.resolve().then(() => {\n if (!(user && user.id)) throw new Error('user must be an AV.User');\n return request({\n method: 'GET',\n path: `/leaderboard/users/${user.id}/statistics`,\n query: {\n statistics: statisticNames\n ? ensureArray(statisticNames).join(',')\n : undefined,\n },\n authOptions,\n }).then(({ results }) => results.map(parseStatisticData));\n });\n\n/**\n * Update Statistics for the specified user.\n * @param {AV.User} user The specified AV.User pointer.\n * @param {Object} statistics A name-value pair representing the statistics to update.\n * @param {AuthOptions} [options] AuthOptions plus:\n * @param {boolean} [options.overwrite] Wethere to overwrite these statistics disregarding the updateStrategy of there leaderboards\n * @return {Promise}\n */\nAV.Leaderboard.updateStatistics = (user, statistics, options = {}) =>\n Promise.resolve().then(() => {\n if (!(user && user.id)) throw new Error('user must be an AV.User');\n const data = _.map(statistics, (value, key) => ({\n statisticName: key,\n statisticValue: value,\n }));\n const { overwrite } = options;\n return request({\n method: 'POST',\n path: `/leaderboard/users/${user.id}/statistics`,\n query: {\n overwrite: overwrite ? 1 : undefined,\n },\n data,\n authOptions: options,\n }).then(({ results }) => results.map(parseStatisticData));\n });\n\n/**\n * Delete Statistics for the specified user.\n * @param {AV.User} user The specified AV.User pointer.\n * @param {Object} statistics A name-value pair representing the statistics to delete.\n * @param {AuthOptions} [options]\n * @return {Promise}\n */\nAV.Leaderboard.deleteStatistics = (user, statisticNames, authOptions) =>\n Promise.resolve().then(() => {\n if (!(user && user.id)) throw new Error('user must be an AV.User');\n return request({\n method: 'DELETE',\n path: `/leaderboard/users/${user.id}/statistics`,\n query: {\n statistics: ensureArray(statisticNames).join(','),\n },\n authOptions,\n }).then(() => undefined);\n });\n\n_.extend(\n Leaderboard.prototype,\n /** @lends AV.Leaderboard.prototype */ {\n _finishFetch(data) {\n _.forEach(data, (value, key) => {\n if (key === 'updatedAt' || key === 'objectId') return;\n if (key === 'expiredAt') {\n key = 'nextResetAt';\n }\n if (key === 'createdAt') {\n value = parseDate(value);\n }\n if (value && value.__type === 'Date') {\n value = parseDate(value.iso);\n }\n this[key] = value;\n });\n return this;\n },\n /**\n * Fetch data from the srever.\n * @param {AuthOptions} [authOptions]\n * @return {Promise}\n */\n fetch(authOptions) {\n return request({\n method: 'GET',\n path: `/leaderboard/leaderboards/${this.statisticName}`,\n authOptions,\n }).then(data => this._finishFetch(data));\n },\n /**\n * Counts the number of users participated in this leaderboard\n * @param {Object} [options]\n * @param {number} [options.version] Specify the version of the leaderboard\n * @param {AuthOptions} [authOptions]\n * @return {Promise}\n */\n count({ version } = {}, authOptions) {\n return request({\n method: 'GET',\n path: `/leaderboard/leaderboards/${this.statisticName}/ranks`,\n query: {\n count: 1,\n limit: 0,\n version,\n },\n authOptions,\n }).then(({ count }) => count);\n },\n _getResults(\n {\n skip,\n limit,\n selectUserKeys,\n includeUserKeys,\n includeStatistics,\n version,\n },\n authOptions,\n userId\n ) {\n return request({\n method: 'GET',\n path: `/leaderboard/leaderboards/${this.statisticName}/ranks${\n userId ? `/${userId}` : ''\n }`,\n query: {\n skip,\n limit,\n selectUserKeys:\n _.union(\n ensureArray(selectUserKeys),\n ensureArray(includeUserKeys)\n ).join(',') || undefined,\n includeUser: includeUserKeys\n ? ensureArray(includeUserKeys).join(',')\n : undefined,\n includeStatistics: includeStatistics\n ? ensureArray(includeStatistics).join(',')\n : undefined,\n version,\n },\n authOptions,\n }).then(({ results: rankings }) =>\n rankings.map(rankingData => {\n const {\n user,\n statisticValue: value,\n rank,\n statistics = [],\n } = AV._decode(rankingData);\n return {\n user,\n value,\n rank,\n includedStatistics: statistics.map(parseStatisticData),\n };\n })\n );\n },\n /**\n * Retrieve a list of ranked users for this Leaderboard.\n * @param {Object} [options]\n * @param {number} [options.skip] The number of results to skip. This is useful for pagination.\n * @param {number} [options.limit] The limit of the number of results.\n * @param {string[]} [options.selectUserKeys] Specify keys of the users to include in the Rankings\n * @param {string[]} [options.includeUserKeys] If the value of a selected user keys is a Pointer, use this options to include its value.\n * @param {string[]} [options.includeStatistics] Specify other statistics to include in the Rankings\n * @param {number} [options.version] Specify the version of the leaderboard\n * @param {AuthOptions} [authOptions]\n * @return {Promise}\n */\n getResults(\n {\n skip,\n limit,\n selectUserKeys,\n includeUserKeys,\n includeStatistics,\n version,\n } = {},\n authOptions\n ) {\n return this._getResults(\n {\n skip,\n limit,\n selectUserKeys,\n includeUserKeys,\n includeStatistics,\n version,\n },\n authOptions\n );\n },\n /**\n * Retrieve a list of ranked users for this Leaderboard, centered on the specified user.\n * @param {AV.User} user The specified AV.User pointer.\n * @param {Object} [options]\n * @param {number} [options.limit] The limit of the number of results.\n * @param {string[]} [options.selectUserKeys] Specify keys of the users to include in the Rankings\n * @param {string[]} [options.includeUserKeys] If the value of a selected user keys is a Pointer, use this options to include its value.\n * @param {string[]} [options.includeStatistics] Specify other statistics to include in the Rankings\n * @param {number} [options.version] Specify the version of the leaderboard\n * @param {AuthOptions} [authOptions]\n * @return {Promise}\n */\n getResultsAroundUser(user, options = {}, authOptions) {\n // getResultsAroundUser(options, authOptions)\n if (user && typeof user.id !== 'string') {\n return this.getResultsAroundUser(undefined, user, options);\n }\n const {\n limit,\n selectUserKeys,\n includeUserKeys,\n includeStatistics,\n version,\n } = options;\n return this._getResults(\n { limit, selectUserKeys, includeUserKeys, includeStatistics, version },\n authOptions,\n user ? user.id : 'self'\n );\n },\n _update(data, authOptions) {\n return request({\n method: 'PUT',\n path: `/leaderboard/leaderboards/${this.statisticName}`,\n data,\n authOptions,\n }).then(result => this._finishFetch(result));\n },\n /**\n * (masterKey required) Update the version change interval of the Leaderboard.\n * @param {AV.LeaderboardVersionChangeInterval} versionChangeInterval\n * @param {AuthOptions} [authOptions]\n * @return {Promise}\n */\n updateVersionChangeInterval(versionChangeInterval, authOptions) {\n return this._update({ versionChangeInterval }, authOptions);\n },\n /**\n * (masterKey required) Update the version change interval of the Leaderboard.\n * @param {AV.LeaderboardUpdateStrategy} updateStrategy\n * @param {AuthOptions} [authOptions]\n * @return {Promise}\n */\n updateUpdateStrategy(updateStrategy, authOptions) {\n return this._update({ updateStrategy }, authOptions);\n },\n /**\n * (masterKey required) Reset the Leaderboard. The version of the Leaderboard will be incremented by 1.\n * @param {AuthOptions} [authOptions]\n * @return {Promise}\n */\n reset(authOptions) {\n return request({\n method: 'PUT',\n path: `/leaderboard/leaderboards/${this.statisticName}/incrementVersion`,\n authOptions,\n }).then(data => this._finishFetch(data));\n },\n /**\n * (masterKey required) Delete the Leaderboard and its all archived versions.\n * @param {AuthOptions} [authOptions]\n * @return {void}\n */\n destroy(authOptions) {\n return AV.request({\n method: 'DELETE',\n path: `/leaderboard/leaderboards/${this.statisticName}`,\n authOptions,\n }).then(() => undefined);\n },\n /**\n * (masterKey required) Get archived versions.\n * @param {Object} [options]\n * @param {number} [options.skip] The number of results to skip. This is useful for pagination.\n * @param {number} [options.limit] The limit of the number of results.\n * @param {AuthOptions} [authOptions]\n * @return {Promise}\n */\n getArchives({ skip, limit } = {}, authOptions) {\n return request({\n method: 'GET',\n path: `/leaderboard/leaderboards/${this.statisticName}/archives`,\n query: {\n skip,\n limit,\n },\n authOptions,\n }).then(({ results }) =>\n results.map(({ version, status, url, activatedAt, deactivatedAt }) => ({\n statisticName: this.statisticName,\n version,\n status,\n url,\n activatedAt: parseDate(activatedAt.iso),\n deactivatedAt: parseDate(deactivatedAt.iso),\n }))\n );\n },\n }\n);\n\n\n\n// WEBPACK FOOTER //\n// ./src/leaderboard.js"],"sourceRoot":""}
\ No newline at end of file
diff --git a/dist/av-live-query-core-min.js b/dist/av-live-query-core-min.js
new file mode 100644
index 000000000..355804550
--- /dev/null
+++ b/dist/av-live-query-core-min.js
@@ -0,0 +1,25 @@
+!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.AV=e():t.AV=e()}("undefined"!=typeof self?self:this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var i=n[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,e),i.l=!0,i.exports}var n={};return e.m=t,e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:r})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=274)}([function(t,e,n){"use strict";var r=n(7),i=n(73),o=n(4),a=n(8),s=n(60).f,u=n(154),c=n(6),f=n(48),l=n(37),h=n(12),d=function(t){var e=function(n,r,o){if(this instanceof e){switch(arguments.length){case 0:return new t;case 1:return new t(n);case 2:return new t(n,r)}return new t(n,r,o)}return i(t,this,arguments)};return e.prototype=t.prototype,e};t.exports=function(t,e){var n,i,p,v,g,m,y,b,_,w=t.target,E=t.global,O=t.stat,T=t.proto,S=E?r:O?r[w]:(r[w]||{}).prototype,x=E?c:c[w]||l(c,w,{})[w],A=x.prototype;for(v in e)n=u(E?v:w+(O?".":"#")+v,t.forced),i=!n&&S&&h(S,v),m=x[v],i&&(t.dontCallGetSet?(_=s(S,v),y=_&&_.value):y=S[v]),g=i&&y?y:e[v],i&&typeof m==typeof g||(b=t.bind&&i?f(g,r):t.wrap&&i?d(g):T&&a(g)?o(g):g,(t.sham||g&&g.sham||m&&m.sham)&&l(b,"sham",!0),l(x,v,b),T&&(p=w+"Prototype",h(c,p)||l(c,p,{}),l(c[p],v,g),t.real&&A&&!A[v]&&l(A,v,g)))}},function(t,e){function n(t){return t&&t.__esModule?t:{default:t}}t.exports=n,t.exports.__esModule=!0,t.exports.default=t.exports},function(t,e){t.exports=function(t){try{return!!t()}catch(t){return!0}}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=n(314);n.d(e,"default",function(){return r.a});var i=n(132);n.d(e,"VERSION",function(){return i.VERSION}),n.d(e,"restArguments",function(){return i.restArguments}),n.d(e,"isObject",function(){return i.isObject}),n.d(e,"isNull",function(){return i.isNull}),n.d(e,"isUndefined",function(){return i.isUndefined}),n.d(e,"isBoolean",function(){return i.isBoolean}),n.d(e,"isElement",function(){return i.isElement}),n.d(e,"isString",function(){return i.isString}),n.d(e,"isNumber",function(){return i.isNumber}),n.d(e,"isDate",function(){return i.isDate}),n.d(e,"isRegExp",function(){return i.isRegExp}),n.d(e,"isError",function(){return i.isError}),n.d(e,"isSymbol",function(){return i.isSymbol}),n.d(e,"isArrayBuffer",function(){return i.isArrayBuffer}),n.d(e,"isDataView",function(){return i.isDataView}),n.d(e,"isArray",function(){return i.isArray}),n.d(e,"isFunction",function(){return i.isFunction}),n.d(e,"isArguments",function(){return i.isArguments}),n.d(e,"isFinite",function(){return i.isFinite}),n.d(e,"isNaN",function(){return i.isNaN}),n.d(e,"isTypedArray",function(){return i.isTypedArray}),n.d(e,"isEmpty",function(){return i.isEmpty}),n.d(e,"isMatch",function(){return i.isMatch}),n.d(e,"isEqual",function(){return i.isEqual}),n.d(e,"isMap",function(){return i.isMap}),n.d(e,"isWeakMap",function(){return i.isWeakMap}),n.d(e,"isSet",function(){return i.isSet}),n.d(e,"isWeakSet",function(){return i.isWeakSet}),n.d(e,"keys",function(){return i.keys}),n.d(e,"allKeys",function(){return i.allKeys}),n.d(e,"values",function(){return i.values}),n.d(e,"pairs",function(){return i.pairs}),n.d(e,"invert",function(){return i.invert}),n.d(e,"functions",function(){return i.functions}),n.d(e,"methods",function(){return i.methods}),n.d(e,"extend",function(){return i.extend}),n.d(e,"extendOwn",function(){return i.extendOwn}),n.d(e,"assign",function(){return i.assign}),n.d(e,"defaults",function(){return i.defaults}),n.d(e,"create",function(){return i.create}),n.d(e,"clone",function(){return i.clone}),n.d(e,"tap",function(){return i.tap}),n.d(e,"get",function(){return i.get}),n.d(e,"has",function(){return i.has}),n.d(e,"mapObject",function(){return i.mapObject}),n.d(e,"identity",function(){return i.identity}),n.d(e,"constant",function(){return i.constant}),n.d(e,"noop",function(){return i.noop}),n.d(e,"toPath",function(){return i.toPath}),n.d(e,"property",function(){return i.property}),n.d(e,"propertyOf",function(){return i.propertyOf}),n.d(e,"matcher",function(){return i.matcher}),n.d(e,"matches",function(){return i.matches}),n.d(e,"times",function(){return i.times}),n.d(e,"random",function(){return i.random}),n.d(e,"now",function(){return i.now}),n.d(e,"escape",function(){return i.escape}),n.d(e,"unescape",function(){return i.unescape}),n.d(e,"templateSettings",function(){return i.templateSettings}),n.d(e,"template",function(){return i.template}),n.d(e,"result",function(){return i.result}),n.d(e,"uniqueId",function(){return i.uniqueId}),n.d(e,"chain",function(){return i.chain}),n.d(e,"iteratee",function(){return i.iteratee}),n.d(e,"partial",function(){return i.partial}),n.d(e,"bind",function(){return i.bind}),n.d(e,"bindAll",function(){return i.bindAll}),n.d(e,"memoize",function(){return i.memoize}),n.d(e,"delay",function(){return i.delay}),n.d(e,"defer",function(){return i.defer}),n.d(e,"throttle",function(){return i.throttle}),n.d(e,"debounce",function(){return i.debounce}),n.d(e,"wrap",function(){return i.wrap}),n.d(e,"negate",function(){return i.negate}),n.d(e,"compose",function(){return i.compose}),n.d(e,"after",function(){return i.after}),n.d(e,"before",function(){return i.before}),n.d(e,"once",function(){return i.once}),n.d(e,"findKey",function(){return i.findKey}),n.d(e,"findIndex",function(){return i.findIndex}),n.d(e,"findLastIndex",function(){return i.findLastIndex}),n.d(e,"sortedIndex",function(){return i.sortedIndex}),n.d(e,"indexOf",function(){return i.indexOf}),n.d(e,"lastIndexOf",function(){return i.lastIndexOf}),n.d(e,"find",function(){return i.find}),n.d(e,"detect",function(){return i.detect}),n.d(e,"findWhere",function(){return i.findWhere}),n.d(e,"each",function(){return i.each}),n.d(e,"forEach",function(){return i.forEach}),n.d(e,"map",function(){return i.map}),n.d(e,"collect",function(){return i.collect}),n.d(e,"reduce",function(){return i.reduce}),n.d(e,"foldl",function(){return i.foldl}),n.d(e,"inject",function(){return i.inject}),n.d(e,"reduceRight",function(){return i.reduceRight}),n.d(e,"foldr",function(){return i.foldr}),n.d(e,"filter",function(){return i.filter}),n.d(e,"select",function(){return i.select}),n.d(e,"reject",function(){return i.reject}),n.d(e,"every",function(){return i.every}),n.d(e,"all",function(){return i.all}),n.d(e,"some",function(){return i.some}),n.d(e,"any",function(){return i.any}),n.d(e,"contains",function(){return i.contains}),n.d(e,"includes",function(){return i.includes}),n.d(e,"include",function(){return i.include}),n.d(e,"invoke",function(){return i.invoke}),n.d(e,"pluck",function(){return i.pluck}),n.d(e,"where",function(){return i.where}),n.d(e,"max",function(){return i.max}),n.d(e,"min",function(){return i.min}),n.d(e,"shuffle",function(){return i.shuffle}),n.d(e,"sample",function(){return i.sample}),n.d(e,"sortBy",function(){return i.sortBy}),n.d(e,"groupBy",function(){return i.groupBy}),n.d(e,"indexBy",function(){return i.indexBy}),n.d(e,"countBy",function(){return i.countBy}),n.d(e,"partition",function(){return i.partition}),n.d(e,"toArray",function(){return i.toArray}),n.d(e,"size",function(){return i.size}),n.d(e,"pick",function(){return i.pick}),n.d(e,"omit",function(){return i.omit}),n.d(e,"first",function(){return i.first}),n.d(e,"head",function(){return i.head}),n.d(e,"take",function(){return i.take}),n.d(e,"initial",function(){return i.initial}),n.d(e,"last",function(){return i.last}),n.d(e,"rest",function(){return i.rest}),n.d(e,"tail",function(){return i.tail}),n.d(e,"drop",function(){return i.drop}),n.d(e,"compact",function(){return i.compact}),n.d(e,"flatten",function(){return i.flatten}),n.d(e,"without",function(){return i.without}),n.d(e,"uniq",function(){return i.uniq}),n.d(e,"unique",function(){return i.unique}),n.d(e,"union",function(){return i.union}),n.d(e,"intersection",function(){return i.intersection}),n.d(e,"difference",function(){return i.difference}),n.d(e,"unzip",function(){return i.unzip}),n.d(e,"transpose",function(){return i.transpose}),n.d(e,"zip",function(){return i.zip}),n.d(e,"object",function(){return i.object}),n.d(e,"range",function(){return i.range}),n.d(e,"chunk",function(){return i.chunk}),n.d(e,"mixin",function(){return i.mixin})},function(t,e,n){var r=n(74),i=Function.prototype,o=i.bind,a=i.call,s=r&&o.bind(a,a);t.exports=r?function(t){return t&&s(t)}:function(t){return t&&function(){return a.apply(t,arguments)}}},function(t,e,n){"use strict";(function(t){n.d(e,"e",function(){return r}),n.d(e,"p",function(){return i}),n.d(e,"a",function(){return o}),n.d(e,"c",function(){return a}),n.d(e,"d",function(){return s}),n.d(e,"o",function(){return u}),n.d(e,"q",function(){return c}),n.d(e,"t",function(){return f}),n.d(e,"i",function(){return l}),n.d(e,"r",function(){return h}),n.d(e,"s",function(){return d}),n.d(e,"k",function(){return p}),n.d(e,"m",function(){return v}),n.d(e,"j",function(){return g}),n.d(e,"l",function(){return m}),n.d(e,"g",function(){return y}),n.d(e,"f",function(){return b}),n.d(e,"h",function(){return _}),n.d(e,"n",function(){return w}),n.d(e,"b",function(){return E});var r="1.12.1",i="object"==typeof self&&self.self===self&&self||"object"==typeof t&&t.global===t&&t||Function("return this")()||{},o=Array.prototype,a=Object.prototype,s="undefined"!=typeof Symbol?Symbol.prototype:null,u=o.push,c=o.slice,f=a.toString,l=a.hasOwnProperty,h="undefined"!=typeof ArrayBuffer,d="undefined"!=typeof DataView,p=Array.isArray,v=Object.keys,g=Object.create,m=h&&ArrayBuffer.isView,y=isNaN,b=isFinite,_=!{toString:null}.propertyIsEnumerable("toString"),w=["valueOf","isPrototypeOf","toString","propertyIsEnumerable","hasOwnProperty","toLocaleString"],E=Math.pow(2,53)-1}).call(e,n(72))},function(t,e){t.exports={}},function(t,e,n){(function(e){var n=function(t){return t&&t.Math==Math&&t};t.exports=n("object"==typeof globalThis&&globalThis)||n("object"==typeof window&&window)||n("object"==typeof self&&self)||n("object"==typeof e&&e)||function(){return this}()||Function("return this")()}).call(e,n(72))},function(t,e){t.exports=function(t){return"function"==typeof t}},function(t,e,n){var r=n(7),i=n(77),o=n(12),a=n(98),s=n(62),u=n(152),c=i("wks"),f=r.Symbol,l=f&&f.for,h=u?f:f&&f.withoutSetter||a;t.exports=function(t){if(!o(c,t)||!s&&"string"!=typeof c[t]){var e="Symbol."+t;s&&o(f,t)?c[t]=f[t]:c[t]=u&&l?l(e):h(e)}return c[t]}},function(t,e,n){var r=n(6),i=n(12),o=n(148),a=n(23).f;t.exports=function(t){var e=r.Symbol||(r.Symbol={});i(e,t)||a(e,t,{value:o.f(t)})}},function(t,e,n){var r=n(8);t.exports=function(t){return"object"==typeof t?null!==t:r(t)}},function(t,e,n){var r=n(4),i=n(34),o=r({}.hasOwnProperty);t.exports=Object.hasOwn||function(t,e){return o(i(t),e)}},function(t,e,n){t.exports=n(277)},function(t,e,n){var r=n(2);t.exports=!r(function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]})},function(t,e,n){var r=n(74),i=Function.prototype.call;t.exports=r?i.bind(i):function(){return i.apply(i,arguments)}},function(t,e,n){"use strict";function r(t){if(!Object(i.a)(t))return[];if(o.m)return Object(o.m)(t);var e=[];for(var n in t)Object(a.a)(t,n)&&e.push(n);return o.h&&Object(s.a)(t,e),e}e.a=r;var i=n(54),o=n(5),a=n(45),s=n(185)},function(t,e,n){"use strict";function r(t){var e="[object "+t+"]";return function(t){return i.t.call(t)===e}}e.a=r;var i=n(5)},function(t,e,n){var r=n(6),i=n(7),o=n(8),a=function(t){return o(t)?t:void 0};t.exports=function(t,e){return arguments.length<2?a(r[t])||a(i[t]):r[t]&&r[t][e]||i[t]&&i[t][e]}},function(t,e,n){var r=n(4);t.exports=r({}.isPrototypeOf)},function(t,e,n){var r=n(11),i=String,o=TypeError;t.exports=function(t){if(r(t))return t;throw o(i(t)+" is not an object")}},function(t,e,n){"use strict";function r(t,e,n){return i.a.iteratee!==a.a?i.a.iteratee(t,e):Object(o.a)(t,e,n)}e.a=r;var i=n(25),o=n(195),a=n(196)},function(t,e,n){t.exports=n(386)},function(t,e,n){var r=n(14),i=n(153),o=n(155),a=n(20),s=n(95),u=TypeError,c=Object.defineProperty,f=Object.getOwnPropertyDescriptor;e.f=r?o?function(t,e,n){if(a(t),e=s(e),a(n),"function"==typeof t&&"prototype"===e&&"value"in n&&"writable"in n&&!n.writable){var r=f(t,e);r&&r.writable&&(t[e]=n.value,n={configurable:"configurable"in n?n.configurable:r.configurable,enumerable:"enumerable"in n?n.enumerable:r.enumerable,writable:!1})}return c(t,e,n)}:c:function(t,e,n){if(a(t),e=s(e),a(n),i)try{return c(t,e,n)}catch(t){}if("get"in n||"set"in n)throw u("Accessors not supported");return"value"in n&&(t[e]=n.value),t}},function(t,e,n){"use strict";function r(t,e){return e=null==e?t.length-1:+e,function(){for(var n=Math.max(arguments.length-e,0),r=Array(n),i=0;i0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0,n={"X-LC-Id":f.applicationId,"Content-Type":"application/json;charset=UTF-8"},r=!1;return"boolean"==typeof t.useMasterKey?r=t.useMasterKey:"boolean"==typeof f._config.useMasterKey&&(r=f._config.useMasterKey),r?f.masterKey?e?n["X-LC-Sign"]=v(f.masterKey,!0):n["X-LC-Key"]="".concat(f.masterKey,",master"):(console.warn("masterKey is not set, fall back to use appKey"),g(n,e)):g(n,e),f.hookKey&&(n["X-LC-Hook-Key"]=f.hookKey),null!==f._config.production&&(n["X-LC-Prod"]=String(f._config.production)),n["X-LC-UA"]=f._sharedConfig.userAgent,o.default.resolve().then(function(){var e=d(t);if(e)n["X-LC-Session"]=e;else if(!f._config.disableCurrentUser)return f.User.currentAsync().then(function(t){return t&&t._sessionToken&&(n["X-LC-Session"]=t._sessionToken),n});return n})},y=function(t){var e=t.service,n=void 0===e?"api":e,r=t.version,i=void 0===r?"1.1":r,o=t.path,a=f._config.serverURLs[n];if(!a)throw new Error("undefined server URL for ".concat(n));return"/"!==a.charAt(a.length-1)&&(a+="/"),a+=i,o&&(a+=o),a},b=function(t){var e=t.service,n=t.version,r=t.method,o=t.path,s=t.query,u=t.data,c=t.authOptions,h=t.signKey,d=void 0===h||h;if(!f.applicationId||!f.applicationKey&&!f.masterKey)throw new Error("Not initialized");f._appRouter&&f._appRouter.refresh();var v=f._config.requestTimeout,g=y({service:e,path:o,version:n});return m(c,d).then(function(t){return p({method:r,url:g,query:s,data:u,headers:t,timeout:v}).catch(function(t){var e={code:t.code||-1,error:t.message||t.responseText};if(t.response&&t.response.code)e=t.response;else if(t.responseText)try{e=JSON.parse(t.responseText)}catch(t){}if(e.rawMessage=e.rawMessage||e.error,!f._sharedConfig.keepErrorRawMessage){var n,o;e.error+=(0,i.default)(n=(0,i.default)(o=" [".concat(t.statusCode||"N/A"," ")).call(o,r," ")).call(n,g,"]")}var s=new l(e.code,e.error);throw delete e.error,a.extend(s,e)})})},_=function(t,e,n,r,i,o,a){var s="";if(t&&(s+="/".concat(t)),e&&(s+="/".concat(e)),n&&(s+="/".concat(n)),i&&i._fetchWhenSave)throw new Error("_fetchWhenSave should be in the query");if(i&&i._where)throw new Error("_where should be in the query");return r&&"get"===r.toLowerCase()&&(a=c({},a,i),i=null),b({method:r,path:s,query:a,data:i,authOptions:o})};f.request=b,t.exports={_request:_,request:b}},function(t,e,n){"use strict";var r=n(17),i=n(5),o=Object(r.a)("Function"),a=i.p.document&&i.p.document.childNodes;"function"!=typeof/./&&"object"!=typeof Int8Array&&"function"!=typeof a&&(o=function(t){return"function"==typeof t||!1}),e.a=o},function(t,e,n){"use strict";var r=n(184);e.a=Object(r.a)("length")},function(t,e,n){"use strict";var r=n(1),i=r(n(57)),o=r(n(228)),a=r(n(13)),s=n(3),u=function(t){return s.isNull(t)||s.isUndefined(t)},c=function(t){return s.isArray(t)?t:void 0===t||null===t?[]:[t]},f=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=(0,i.default)(t),n=t.include,r=t.includeACL,o={};return e&&(o.keys=c(e).join(",")),n&&(o.include=c(n).join(",")),r&&(o.returnACL=r),o},l=function(t){return t.sessionToken?t.sessionToken:t.user&&"function"==typeof t.user.getSessionToken?t.user.getSessionToken():void 0},h=function(t){return function(e){return t(e),e}},d=function(){},p=function(t,e,n){var r;return r=e&&e.hasOwnProperty("constructor")?e.constructor:function(){t.apply(this,arguments)},s.extend(r,t),d.prototype=t.prototype,r.prototype=new d,e&&s.extend(r.prototype,e),n&&s.extend(r,n),r.prototype.constructor=r,r.__super__=t.prototype,r},v="undefined"==typeof wx?function(t){return new Date(t)}:function(t){return new Date(Date.parse(t))},g=function(t,e,n){var r=e.split("."),i=r.pop(),o=t;return r.forEach(function(t){void 0===o[t]&&(o[t]={}),o=o[t]}),o[i]=n,t},m=function(t,e){for(var n=e.split("."),r=n[0],i=n.pop(),o=t,a=0;ay;y++)if((_=j(t[y]))&&c(v,_))return _;return new p(!1)}g=f(t,m)}for(w=g.next;!(E=i(w,g)).done;){try{_=j(E.value)}catch(t){h(g,"throw",t)}if("object"==typeof _&&_&&c(v,_))return _}return new p(!1)}},function(t,e,n){"use strict";var r=n(32),i=n(164),o=n(50),a=n(42),s=n(23).f,u=n(131),c=n(33),f=n(14),l=a.set,h=a.getterFor("Array Iterator");t.exports=u(Array,"Array",function(t,e){l(this,{type:"Array Iterator",target:r(t),index:0,kind:e})},function(){var t=h(this),e=t.target,n=t.kind,r=t.index++;return!e||r>=e.length?(t.target=void 0,{value:void 0,done:!0}):"keys"==n?{value:r,done:!1}:"values"==n?{value:e[r],done:!1}:{value:[r,e[r]],done:!1}},"values");var d=o.Arguments=o.Array;if(i("keys"),i("values"),i("entries"),!c&&f&&"values"!==d.name)try{s(d,"name",{value:"values"})}catch(t){}},function(t,e,n){var r,i,o,a=n(165),s=n(7),u=n(4),c=n(11),f=n(37),l=n(12),h=n(123),d=n(100),p=n(78),v=s.TypeError,g=s.WeakMap,m=function(t){return o(t)?i(t):r(t,{})},y=function(t){return function(e){var n;if(!c(e)||(n=i(e)).type!==t)throw v("Incompatible receiver, "+t+" required");return n}};if(a||h.state){var b=h.state||(h.state=new g),_=u(b.get),w=u(b.has),E=u(b.set);r=function(t,e){if(w(b,t))throw new v("Object already initialized");return e.facade=t,E(b,t,e),e},i=function(t){return _(b,t)||{}},o=function(t){return w(b,t)}}else{var O=d("state");p[O]=!0,r=function(t,e){if(l(t,O))throw new v("Object already initialized");return e.facade=t,f(t,O,e),e},i=function(t){return l(t,O)?t[O]:{}},o=function(t){return l(t,O)}}t.exports={set:r,get:i,has:o,enforce:m,getterFor:y}},function(t,e,n){var r=n(37);t.exports=function(t,e,n,i){return i&&i.enumerable?t[e]=n:r(t,e,n),t}},function(t,e,n){n(41);var r=n(313),i=n(7),o=n(51),a=n(37),s=n(50),u=n(9),c=u("toStringTag");for(var f in r){var l=i[f],h=l&&l.prototype;h&&o(h)!==c&&a(h,c,f),s[f]=s.Array}},function(t,e,n){"use strict";function r(t,e){return null!=t&&i.i.call(t,e)}e.a=r;var i=n(5)},function(t,e,n){"use strict";function r(t,e){if(this instanceof r?this.constructor:void 0){var n=new Error(e);return(0,o.default)(n,(0,a.default)(this)),n.code=t,n}return new r(t,e)}var i=n(1),o=i(n(413)),a=i(n(228)),s=n(3);r.prototype=Object.create(Error.prototype,{constructor:{value:Error,enumerable:!1,writable:!0,configurable:!0}}),(0,o.default)(r,Error),s.extend(r,{OTHER_CAUSE:-1,INTERNAL_SERVER_ERROR:1,CONNECTION_FAILED:100,OBJECT_NOT_FOUND:101,INVALID_QUERY:102,INVALID_CLASS_NAME:103,MISSING_OBJECT_ID:104,INVALID_KEY_NAME:105,INVALID_POINTER:106,INVALID_JSON:107,COMMAND_UNAVAILABLE:108,NOT_INITIALIZED:109,INCORRECT_TYPE:111,INVALID_CHANNEL_NAME:112,PUSH_MISCONFIGURED:115,OBJECT_TOO_LARGE:116,OPERATION_FORBIDDEN:119,CACHE_MISS:120,INVALID_NESTED_KEY:121,INVALID_FILE_NAME:122,INVALID_ACL:123,TIMEOUT:124,INVALID_EMAIL_ADDRESS:125,MISSING_CONTENT_TYPE:126,MISSING_CONTENT_LENGTH:127,INVALID_CONTENT_LENGTH:128,FILE_TOO_LARGE:129,FILE_SAVE_ERROR:130,FILE_DELETE_ERROR:153,DUPLICATE_VALUE:137,INVALID_ROLE_NAME:139,EXCEEDED_QUOTA:140,SCRIPT_FAILED:141,VALIDATION_ERROR:142,INVALID_IMAGE_DATA:150,UNSAVED_FILE_ERROR:151,INVALID_PUSH_TIME_ERROR:152,USERNAME_MISSING:200,PASSWORD_MISSING:201,USERNAME_TAKEN:202,EMAIL_TAKEN:203,EMAIL_MISSING:204,EMAIL_NOT_FOUND:205,SESSION_MISSING:206,MUST_CREATE_USER_THROUGH_SIGNUP:207,ACCOUNT_ALREADY_LINKED:208,LINKED_ID_MISSING:250,INVALID_LINKED_SESSION:251,UNSUPPORTED_SERVICE:252,X_DOMAIN_REQUEST:602}),t.exports=r},function(t,e){t.exports=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}}},function(t,e,n){var r=n(4),i=n(31),o=n(74),a=r(r.bind);t.exports=function(t,e){return i(t),void 0===e?t:o?a(t,e):function(){return t.apply(e,arguments)}}},function(t,e,n){var r,i=n(20),o=n(128),a=n(127),s=n(78),u=n(160),c=n(124),f=n(100),l=f("IE_PROTO"),h=function(){},d=function(t){return"