*/
AV.Cloud.useMasterKey = function () {
AV._config.useMasterKey = true;
};
}
/**
* Call this method to set production environment variable.
* @function AV.setProduction
* @param {Boolean} production True is production environment,and
* it's true by default.
*/
AV.setProduction = function (production) {
if (!isNullOrUndefined(production)) {
AV._config.production = production ? 1 : 0;
} else {
// change to default value
AV._config.production = null;
}
};
AV._setServerURLs = function (urls) {
var disableAppRouter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
if (typeof urls !== 'string') {
extend(AV._config.serverURLs, urls);
} else {
AV._config.serverURLs = fillServerURLs(urls);
}
if (disableAppRouter) {
if (AV._appRouter) {
AV._appRouter.disable();
} else {
_disableAppRouter = true;
}
}
};
/**
* Set server URLs for services.
* @function AV.setServerURL
* @since 4.3.0
* @param {String|ServerURLs} urls URLs for services. if a string was given, it will be applied for all services.
* You can also set them when initializing SDK with `options.serverURL`
*/
AV.setServerURL = function (urls) {
return AV._setServerURLs(urls);
};
AV.setServerURLs = AV.setServerURL;
AV.keepErrorRawMessage = function (value) {
AV._sharedConfig.keepErrorRawMessage = value;
};
/**
* Set a deadline for requests to complete.
* Note that file upload requests are not affected.
* @function AV.setRequestTimeout
* @since 3.6.0
* @param {number} ms
*/
AV.setRequestTimeout = function (ms) {
AV._config.requestTimeout = ms;
}; // backword compatible
AV.initialize = AV.init;
var defineConfig = function defineConfig(property) {
return (0, _defineProperty.default)(AV, property, {
get: function get() {
return AV._config[property];
},
set: function set(value) {
AV._config[property] = value;
}
});
};
['applicationId', 'applicationKey', 'masterKey', 'hookKey'].forEach(defineConfig);
/***/ }),
/* 420 */
/***/ (function(module, exports, __webpack_require__) {
var isPrototypeOf = __webpack_require__(19);
var method = __webpack_require__(421);
var ArrayPrototype = Array.prototype;
module.exports = function (it) {
var own = it.slice;
return it === ArrayPrototype || (isPrototypeOf(ArrayPrototype, it) && own === ArrayPrototype.slice) ? method : own;
};
/***/ }),
/* 421 */
/***/ (function(module, exports, __webpack_require__) {
__webpack_require__(422);
var entryVirtual = __webpack_require__(40);
module.exports = entryVirtual('Array').slice;
/***/ }),
/* 422 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var $ = __webpack_require__(0);
var isArray = __webpack_require__(90);
var isConstructor = __webpack_require__(109);
var isObject = __webpack_require__(11);
var toAbsoluteIndex = __webpack_require__(125);
var lengthOfArrayLike = __webpack_require__(41);
var toIndexedObject = __webpack_require__(32);
var createProperty = __webpack_require__(91);
var wellKnownSymbol = __webpack_require__(9);
var arrayMethodHasSpeciesSupport = __webpack_require__(114);
var un$Slice = __webpack_require__(110);
var HAS_SPECIES_SUPPORT = arrayMethodHasSpeciesSupport('slice');
var SPECIES = wellKnownSymbol('species');
var $Array = Array;
var max = Math.max;
// `Array.prototype.slice` method
// https://tc39.es/ecma262/#sec-array.prototype.slice
// fallback for not array-like ES3 strings and DOM objects
$({ target: 'Array', proto: true, forced: !HAS_SPECIES_SUPPORT }, {
slice: function slice(start, end) {
var O = toIndexedObject(this);
var length = lengthOfArrayLike(O);
var k = toAbsoluteIndex(start, length);
var fin = toAbsoluteIndex(end === undefined ? length : end, length);
// inline `ArraySpeciesCreate` for usage native `Array#slice` where it's possible
var Constructor, result, n;
if (isArray(O)) {
Constructor = O.constructor;
// cross-realm fallback
if (isConstructor(Constructor) && (Constructor === $Array || isArray(Constructor.prototype))) {
Constructor = undefined;
} else if (isObject(Constructor)) {
Constructor = Constructor[SPECIES];
if (Constructor === null) Constructor = undefined;
}
if (Constructor === $Array || Constructor === undefined) {
return un$Slice(O, k, fin);
}
}
result = new (Constructor === undefined ? $Array : Constructor)(max(fin - k, 0));
for (n = 0; k < fin; k++, n++) if (k in O) createProperty(result, n, O[k]);
result.length = n;
return result;
}
});
/***/ }),
/* 423 */
/***/ (function(module, exports, __webpack_require__) {
__webpack_require__(424);
var path = __webpack_require__(5);
var Object = path.Object;
var defineProperty = module.exports = function defineProperty(it, key, desc) {
return Object.defineProperty(it, key, desc);
};
if (Object.defineProperty.sham) defineProperty.sham = true;
/***/ }),
/* 424 */
/***/ (function(module, exports, __webpack_require__) {
var $ = __webpack_require__(0);
var DESCRIPTORS = __webpack_require__(14);
var defineProperty = __webpack_require__(23).f;
// `Object.defineProperty` method
// https://tc39.es/ecma262/#sec-object.defineproperty
// eslint-disable-next-line es-x/no-object-defineproperty -- safe
$({ target: 'Object', stat: true, forced: Object.defineProperty !== defineProperty, sham: !DESCRIPTORS }, {
defineProperty: defineProperty
});
/***/ }),
/* 425 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var ajax = __webpack_require__(116);
var Cache = __webpack_require__(237);
function AppRouter(AV) {
var _this = this;
this.AV = AV;
this.lockedUntil = 0;
Cache.getAsync('serverURLs').then(function (data) {
if (_this.disabled) return;
if (!data) return _this.lock(0);
var serverURLs = data.serverURLs,
lockedUntil = data.lockedUntil;
_this.AV._setServerURLs(serverURLs, false);
_this.lockedUntil = lockedUntil;
}).catch(function () {
return _this.lock(0);
});
}
AppRouter.prototype.disable = function disable() {
this.disabled = true;
};
AppRouter.prototype.lock = function lock(ttl) {
this.lockedUntil = Date.now() + ttl;
};
AppRouter.prototype.refresh = function refresh() {
var _this2 = this;
if (this.disabled) return;
if (Date.now() < this.lockedUntil) return;
this.lock(10);
var url = 'https://app-router.com/2/route';
return ajax({
method: 'get',
url: url,
query: {
appId: this.AV.applicationId
}
}).then(function (servers) {
if (_this2.disabled) return;
var ttl = servers.ttl;
if (!ttl) throw new Error('missing ttl');
ttl = ttl * 1000;
var protocal = 'https://';
var serverURLs = {
push: protocal + servers.push_server,
stats: protocal + servers.stats_server,
engine: protocal + servers.engine_server,
api: protocal + servers.api_server
};
_this2.AV._setServerURLs(serverURLs, false);
_this2.lock(ttl);
return Cache.setAsync('serverURLs', {
serverURLs: serverURLs,
lockedUntil: _this2.lockedUntil
}, ttl);
}).catch(function (error) {
// bypass all errors
console.warn("refresh server URLs failed: ".concat(error.message));
_this2.lock(600);
});
};
module.exports = AppRouter;
/***/ }),
/* 426 */
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(427);
/***/ }),
/* 427 */
/***/ (function(module, exports, __webpack_require__) {
var parent = __webpack_require__(428);
__webpack_require__(451);
__webpack_require__(452);
__webpack_require__(453);
__webpack_require__(454);
__webpack_require__(455);
// TODO: Remove from `core-js@4`
__webpack_require__(456);
__webpack_require__(457);
__webpack_require__(458);
module.exports = parent;
/***/ }),
/* 428 */
/***/ (function(module, exports, __webpack_require__) {
var parent = __webpack_require__(243);
module.exports = parent;
/***/ }),
/* 429 */
/***/ (function(module, exports, __webpack_require__) {
__webpack_require__(228);
__webpack_require__(53);
__webpack_require__(244);
__webpack_require__(435);
__webpack_require__(436);
__webpack_require__(437);
__webpack_require__(438);
__webpack_require__(248);
__webpack_require__(439);
__webpack_require__(440);
__webpack_require__(441);
__webpack_require__(442);
__webpack_require__(443);
__webpack_require__(444);
__webpack_require__(445);
__webpack_require__(446);
__webpack_require__(447);
__webpack_require__(448);
__webpack_require__(449);
__webpack_require__(450);
var path = __webpack_require__(5);
module.exports = path.Symbol;
/***/ }),
/* 430 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var $ = __webpack_require__(0);
var global = __webpack_require__(7);
var call = __webpack_require__(15);
var uncurryThis = __webpack_require__(4);
var IS_PURE = __webpack_require__(33);
var DESCRIPTORS = __webpack_require__(14);
var NATIVE_SYMBOL = __webpack_require__(64);
var fails = __webpack_require__(2);
var hasOwn = __webpack_require__(13);
var isPrototypeOf = __webpack_require__(19);
var anObject = __webpack_require__(20);
var toIndexedObject = __webpack_require__(32);
var toPropertyKey = __webpack_require__(96);
var $toString = __webpack_require__(81);
var createPropertyDescriptor = __webpack_require__(47);
var nativeObjectCreate = __webpack_require__(49);
var objectKeys = __webpack_require__(105);
var getOwnPropertyNamesModule = __webpack_require__(103);
var getOwnPropertyNamesExternal = __webpack_require__(245);
var getOwnPropertySymbolsModule = __webpack_require__(104);
var getOwnPropertyDescriptorModule = __webpack_require__(62);
var definePropertyModule = __webpack_require__(23);
var definePropertiesModule = __webpack_require__(128);
var propertyIsEnumerableModule = __webpack_require__(120);
var defineBuiltIn = __webpack_require__(44);
var shared = __webpack_require__(79);
var sharedKey = __webpack_require__(101);
var hiddenKeys = __webpack_require__(80);
var uid = __webpack_require__(99);
var wellKnownSymbol = __webpack_require__(9);
var wrappedWellKnownSymbolModule = __webpack_require__(148);
var defineWellKnownSymbol = __webpack_require__(10);
var defineSymbolToPrimitive = __webpack_require__(246);
var setToStringTag = __webpack_require__(52);
var InternalStateModule = __webpack_require__(43);
var $forEach = __webpack_require__(70).forEach;
var HIDDEN = sharedKey('hidden');
var SYMBOL = 'Symbol';
var PROTOTYPE = 'prototype';
var setInternalState = InternalStateModule.set;
var getInternalState = InternalStateModule.getterFor(SYMBOL);
var ObjectPrototype = Object[PROTOTYPE];
var $Symbol = global.Symbol;
var SymbolPrototype = $Symbol && $Symbol[PROTOTYPE];
var TypeError = global.TypeError;
var QObject = global.QObject;
var nativeGetOwnPropertyDescriptor = getOwnPropertyDescriptorModule.f;
var nativeDefineProperty = definePropertyModule.f;
var nativeGetOwnPropertyNames = getOwnPropertyNamesExternal.f;
var nativePropertyIsEnumerable = propertyIsEnumerableModule.f;
var push = uncurryThis([].push);
var AllSymbols = shared('symbols');
var ObjectPrototypeSymbols = shared('op-symbols');
var WellKnownSymbolsStore = shared('wks');
// Don't use setters in Qt Script, https://github.com/zloirock/core-js/issues/173
var USE_SETTER = !QObject || !QObject[PROTOTYPE] || !QObject[PROTOTYPE].findChild;
// fallback for old Android, https://code.google.com/p/v8/issues/detail?id=687
var setSymbolDescriptor = DESCRIPTORS && fails(function () {
return nativeObjectCreate(nativeDefineProperty({}, 'a', {
get: function () { return nativeDefineProperty(this, 'a', { value: 7 }).a; }
})).a != 7;
}) ? function (O, P, Attributes) {
var ObjectPrototypeDescriptor = nativeGetOwnPropertyDescriptor(ObjectPrototype, P);
if (ObjectPrototypeDescriptor) delete ObjectPrototype[P];
nativeDefineProperty(O, P, Attributes);
if (ObjectPrototypeDescriptor && O !== ObjectPrototype) {
nativeDefineProperty(ObjectPrototype, P, ObjectPrototypeDescriptor);
}
} : nativeDefineProperty;
var wrap = function (tag, description) {
var symbol = AllSymbols[tag] = nativeObjectCreate(SymbolPrototype);
setInternalState(symbol, {
type: SYMBOL,
tag: tag,
description: description
});
if (!DESCRIPTORS) symbol.description = description;
return symbol;
};
var $defineProperty = function defineProperty(O, P, Attributes) {
if (O === ObjectPrototype) $defineProperty(ObjectPrototypeSymbols, P, Attributes);
anObject(O);
var key = toPropertyKey(P);
anObject(Attributes);
if (hasOwn(AllSymbols, key)) {
if (!Attributes.enumerable) {
if (!hasOwn(O, HIDDEN)) nativeDefineProperty(O, HIDDEN, createPropertyDescriptor(1, {}));
O[HIDDEN][key] = true;
} else {
if (hasOwn(O, HIDDEN) && O[HIDDEN][key]) O[HIDDEN][key] = false;
Attributes = nativeObjectCreate(Attributes, { enumerable: createPropertyDescriptor(0, false) });
} return setSymbolDescriptor(O, key, Attributes);
} return nativeDefineProperty(O, key, Attributes);
};
var $defineProperties = function defineProperties(O, Properties) {
anObject(O);
var properties = toIndexedObject(Properties);
var keys = objectKeys(properties).concat($getOwnPropertySymbols(properties));
$forEach(keys, function (key) {
if (!DESCRIPTORS || call($propertyIsEnumerable, properties, key)) $defineProperty(O, key, properties[key]);
});
return O;
};
var $create = function create(O, Properties) {
return Properties === undefined ? nativeObjectCreate(O) : $defineProperties(nativeObjectCreate(O), Properties);
};
var $propertyIsEnumerable = function propertyIsEnumerable(V) {
var P = toPropertyKey(V);
var enumerable = call(nativePropertyIsEnumerable, this, P);
if (this === ObjectPrototype && hasOwn(AllSymbols, P) && !hasOwn(ObjectPrototypeSymbols, P)) return false;
return enumerable || !hasOwn(this, P) || !hasOwn(AllSymbols, P) || hasOwn(this, HIDDEN) && this[HIDDEN][P]
? enumerable : true;
};
var $getOwnPropertyDescriptor = function getOwnPropertyDescriptor(O, P) {
var it = toIndexedObject(O);
var key = toPropertyKey(P);
if (it === ObjectPrototype && hasOwn(AllSymbols, key) && !hasOwn(ObjectPrototypeSymbols, key)) return;
var descriptor = nativeGetOwnPropertyDescriptor(it, key);
if (descriptor && hasOwn(AllSymbols, key) && !(hasOwn(it, HIDDEN) && it[HIDDEN][key])) {
descriptor.enumerable = true;
}
return descriptor;
};
var $getOwnPropertyNames = function getOwnPropertyNames(O) {
var names = nativeGetOwnPropertyNames(toIndexedObject(O));
var result = [];
$forEach(names, function (key) {
if (!hasOwn(AllSymbols, key) && !hasOwn(hiddenKeys, key)) push(result, key);
});
return result;
};
var $getOwnPropertySymbols = function (O) {
var IS_OBJECT_PROTOTYPE = O === ObjectPrototype;
var names = nativeGetOwnPropertyNames(IS_OBJECT_PROTOTYPE ? ObjectPrototypeSymbols : toIndexedObject(O));
var result = [];
$forEach(names, function (key) {
if (hasOwn(AllSymbols, key) && (!IS_OBJECT_PROTOTYPE || hasOwn(ObjectPrototype, key))) {
push(result, AllSymbols[key]);
}
});
return result;
};
// `Symbol` constructor
// https://tc39.es/ecma262/#sec-symbol-constructor
if (!NATIVE_SYMBOL) {
$Symbol = function Symbol() {
if (isPrototypeOf(SymbolPrototype, this)) throw TypeError('Symbol is not a constructor');
var description = !arguments.length || arguments[0] === undefined ? undefined : $toString(arguments[0]);
var tag = uid(description);
var setter = function (value) {
if (this === ObjectPrototype) call(setter, ObjectPrototypeSymbols, value);
if (hasOwn(this, HIDDEN) && hasOwn(this[HIDDEN], tag)) this[HIDDEN][tag] = false;
setSymbolDescriptor(this, tag, createPropertyDescriptor(1, value));
};
if (DESCRIPTORS && USE_SETTER) setSymbolDescriptor(ObjectPrototype, tag, { configurable: true, set: setter });
return wrap(tag, description);
};
SymbolPrototype = $Symbol[PROTOTYPE];
defineBuiltIn(SymbolPrototype, 'toString', function toString() {
return getInternalState(this).tag;
});
defineBuiltIn($Symbol, 'withoutSetter', function (description) {
return wrap(uid(description), description);
});
propertyIsEnumerableModule.f = $propertyIsEnumerable;
definePropertyModule.f = $defineProperty;
definePropertiesModule.f = $defineProperties;
getOwnPropertyDescriptorModule.f = $getOwnPropertyDescriptor;
getOwnPropertyNamesModule.f = getOwnPropertyNamesExternal.f = $getOwnPropertyNames;
getOwnPropertySymbolsModule.f = $getOwnPropertySymbols;
wrappedWellKnownSymbolModule.f = function (name) {
return wrap(wellKnownSymbol(name), name);
};
if (DESCRIPTORS) {
// https://github.com/tc39/proposal-Symbol-description
nativeDefineProperty(SymbolPrototype, 'description', {
configurable: true,
get: function description() {
return getInternalState(this).description;
}
});
if (!IS_PURE) {
defineBuiltIn(ObjectPrototype, 'propertyIsEnumerable', $propertyIsEnumerable, { unsafe: true });
}
}
}
$({ global: true, constructor: true, wrap: true, forced: !NATIVE_SYMBOL, sham: !NATIVE_SYMBOL }, {
Symbol: $Symbol
});
$forEach(objectKeys(WellKnownSymbolsStore), function (name) {
defineWellKnownSymbol(name);
});
$({ target: SYMBOL, stat: true, forced: !NATIVE_SYMBOL }, {
useSetter: function () { USE_SETTER = true; },
useSimple: function () { USE_SETTER = false; }
});
$({ target: 'Object', stat: true, forced: !NATIVE_SYMBOL, sham: !DESCRIPTORS }, {
// `Object.create` method
// https://tc39.es/ecma262/#sec-object.create
create: $create,
// `Object.defineProperty` method
// https://tc39.es/ecma262/#sec-object.defineproperty
defineProperty: $defineProperty,
// `Object.defineProperties` method
// https://tc39.es/ecma262/#sec-object.defineproperties
defineProperties: $defineProperties,
// `Object.getOwnPropertyDescriptor` method
// https://tc39.es/ecma262/#sec-object.getownpropertydescriptors
getOwnPropertyDescriptor: $getOwnPropertyDescriptor
});
$({ target: 'Object', stat: true, forced: !NATIVE_SYMBOL }, {
// `Object.getOwnPropertyNames` method
// https://tc39.es/ecma262/#sec-object.getownpropertynames
getOwnPropertyNames: $getOwnPropertyNames
});
// `Symbol.prototype[@@toPrimitive]` method
// https://tc39.es/ecma262/#sec-symbol.prototype-@@toprimitive
defineSymbolToPrimitive();
// `Symbol.prototype[@@toStringTag]` property
// https://tc39.es/ecma262/#sec-symbol.prototype-@@tostringtag
setToStringTag($Symbol, SYMBOL);
hiddenKeys[HIDDEN] = true;
/***/ }),
/* 431 */
/***/ (function(module, exports, __webpack_require__) {
var toAbsoluteIndex = __webpack_require__(125);
var lengthOfArrayLike = __webpack_require__(41);
var createProperty = __webpack_require__(91);
var $Array = Array;
var max = Math.max;
module.exports = function (O, start, end) {
var length = lengthOfArrayLike(O);
var k = toAbsoluteIndex(start, length);
var fin = toAbsoluteIndex(end === undefined ? length : end, length);
var result = $Array(max(fin - k, 0));
for (var n = 0; k < fin; k++, n++) createProperty(result, n, O[k]);
result.length = n;
return result;
};
/***/ }),
/* 432 */
/***/ (function(module, exports, __webpack_require__) {
var $ = __webpack_require__(0);
var getBuiltIn = __webpack_require__(18);
var hasOwn = __webpack_require__(13);
var toString = __webpack_require__(81);
var shared = __webpack_require__(79);
var NATIVE_SYMBOL_REGISTRY = __webpack_require__(247);
var StringToSymbolRegistry = shared('string-to-symbol-registry');
var SymbolToStringRegistry = shared('symbol-to-string-registry');
// `Symbol.for` method
// https://tc39.es/ecma262/#sec-symbol.for
$({ target: 'Symbol', stat: true, forced: !NATIVE_SYMBOL_REGISTRY }, {
'for': function (key) {
var string = toString(key);
if (hasOwn(StringToSymbolRegistry, string)) return StringToSymbolRegistry[string];
var symbol = getBuiltIn('Symbol')(string);
StringToSymbolRegistry[string] = symbol;
SymbolToStringRegistry[symbol] = string;
return symbol;
}
});
/***/ }),
/* 433 */
/***/ (function(module, exports, __webpack_require__) {
var $ = __webpack_require__(0);
var hasOwn = __webpack_require__(13);
var isSymbol = __webpack_require__(97);
var tryToString = __webpack_require__(78);
var shared = __webpack_require__(79);
var NATIVE_SYMBOL_REGISTRY = __webpack_require__(247);
var SymbolToStringRegistry = shared('symbol-to-string-registry');
// `Symbol.keyFor` method
// https://tc39.es/ecma262/#sec-symbol.keyfor
$({ target: 'Symbol', stat: true, forced: !NATIVE_SYMBOL_REGISTRY }, {
keyFor: function keyFor(sym) {
if (!isSymbol(sym)) throw TypeError(tryToString(sym) + ' is not a symbol');
if (hasOwn(SymbolToStringRegistry, sym)) return SymbolToStringRegistry[sym];
}
});
/***/ }),
/* 434 */
/***/ (function(module, exports, __webpack_require__) {
var $ = __webpack_require__(0);
var NATIVE_SYMBOL = __webpack_require__(64);
var fails = __webpack_require__(2);
var getOwnPropertySymbolsModule = __webpack_require__(104);
var toObject = __webpack_require__(34);
// V8 ~ Chrome 38 and 39 `Object.getOwnPropertySymbols` fails on primitives
// https://bugs.chromium.org/p/v8/issues/detail?id=3443
var FORCED = !NATIVE_SYMBOL || fails(function () { getOwnPropertySymbolsModule.f(1); });
// `Object.getOwnPropertySymbols` method
// https://tc39.es/ecma262/#sec-object.getownpropertysymbols
$({ target: 'Object', stat: true, forced: FORCED }, {
getOwnPropertySymbols: function getOwnPropertySymbols(it) {
var $getOwnPropertySymbols = getOwnPropertySymbolsModule.f;
return $getOwnPropertySymbols ? $getOwnPropertySymbols(toObject(it)) : [];
}
});
/***/ }),
/* 435 */
/***/ (function(module, exports, __webpack_require__) {
var defineWellKnownSymbol = __webpack_require__(10);
// `Symbol.asyncIterator` well-known symbol
// https://tc39.es/ecma262/#sec-symbol.asynciterator
defineWellKnownSymbol('asyncIterator');
/***/ }),
/* 436 */
/***/ (function(module, exports) {
// empty
/***/ }),
/* 437 */
/***/ (function(module, exports, __webpack_require__) {
var defineWellKnownSymbol = __webpack_require__(10);
// `Symbol.hasInstance` well-known symbol
// https://tc39.es/ecma262/#sec-symbol.hasinstance
defineWellKnownSymbol('hasInstance');
/***/ }),
/* 438 */
/***/ (function(module, exports, __webpack_require__) {
var defineWellKnownSymbol = __webpack_require__(10);
// `Symbol.isConcatSpreadable` well-known symbol
// https://tc39.es/ecma262/#sec-symbol.isconcatspreadable
defineWellKnownSymbol('isConcatSpreadable');
/***/ }),
/* 439 */
/***/ (function(module, exports, __webpack_require__) {
var defineWellKnownSymbol = __webpack_require__(10);
// `Symbol.match` well-known symbol
// https://tc39.es/ecma262/#sec-symbol.match
defineWellKnownSymbol('match');
/***/ }),
/* 440 */
/***/ (function(module, exports, __webpack_require__) {
var defineWellKnownSymbol = __webpack_require__(10);
// `Symbol.matchAll` well-known symbol
// https://tc39.es/ecma262/#sec-symbol.matchall
defineWellKnownSymbol('matchAll');
/***/ }),
/* 441 */
/***/ (function(module, exports, __webpack_require__) {
var defineWellKnownSymbol = __webpack_require__(10);
// `Symbol.replace` well-known symbol
// https://tc39.es/ecma262/#sec-symbol.replace
defineWellKnownSymbol('replace');
/***/ }),
/* 442 */
/***/ (function(module, exports, __webpack_require__) {
var defineWellKnownSymbol = __webpack_require__(10);
// `Symbol.search` well-known symbol
// https://tc39.es/ecma262/#sec-symbol.search
defineWellKnownSymbol('search');
/***/ }),
/* 443 */
/***/ (function(module, exports, __webpack_require__) {
var defineWellKnownSymbol = __webpack_require__(10);
// `Symbol.species` well-known symbol
// https://tc39.es/ecma262/#sec-symbol.species
defineWellKnownSymbol('species');
/***/ }),
/* 444 */
/***/ (function(module, exports, __webpack_require__) {
var defineWellKnownSymbol = __webpack_require__(10);
// `Symbol.split` well-known symbol
// https://tc39.es/ecma262/#sec-symbol.split
defineWellKnownSymbol('split');
/***/ }),
/* 445 */
/***/ (function(module, exports, __webpack_require__) {
var defineWellKnownSymbol = __webpack_require__(10);
var defineSymbolToPrimitive = __webpack_require__(246);
// `Symbol.toPrimitive` well-known symbol
// https://tc39.es/ecma262/#sec-symbol.toprimitive
defineWellKnownSymbol('toPrimitive');
// `Symbol.prototype[@@toPrimitive]` method
// https://tc39.es/ecma262/#sec-symbol.prototype-@@toprimitive
defineSymbolToPrimitive();
/***/ }),
/* 446 */
/***/ (function(module, exports, __webpack_require__) {
var getBuiltIn = __webpack_require__(18);
var defineWellKnownSymbol = __webpack_require__(10);
var setToStringTag = __webpack_require__(52);
// `Symbol.toStringTag` well-known symbol
// https://tc39.es/ecma262/#sec-symbol.tostringtag
defineWellKnownSymbol('toStringTag');
// `Symbol.prototype[@@toStringTag]` property
// https://tc39.es/ecma262/#sec-symbol.prototype-@@tostringtag
setToStringTag(getBuiltIn('Symbol'), 'Symbol');
/***/ }),
/* 447 */
/***/ (function(module, exports, __webpack_require__) {
var defineWellKnownSymbol = __webpack_require__(10);
// `Symbol.unscopables` well-known symbol
// https://tc39.es/ecma262/#sec-symbol.unscopables
defineWellKnownSymbol('unscopables');
/***/ }),
/* 448 */
/***/ (function(module, exports, __webpack_require__) {
var global = __webpack_require__(7);
var setToStringTag = __webpack_require__(52);
// JSON[@@toStringTag] property
// https://tc39.es/ecma262/#sec-json-@@tostringtag
setToStringTag(global.JSON, 'JSON', true);
/***/ }),
/* 449 */
/***/ (function(module, exports) {
// empty
/***/ }),
/* 450 */
/***/ (function(module, exports) {
// empty
/***/ }),
/* 451 */
/***/ (function(module, exports, __webpack_require__) {
var defineWellKnownSymbol = __webpack_require__(10);
// `Symbol.asyncDispose` well-known symbol
// https://github.com/tc39/proposal-using-statement
defineWellKnownSymbol('asyncDispose');
/***/ }),
/* 452 */
/***/ (function(module, exports, __webpack_require__) {
var defineWellKnownSymbol = __webpack_require__(10);
// `Symbol.dispose` well-known symbol
// https://github.com/tc39/proposal-using-statement
defineWellKnownSymbol('dispose');
/***/ }),
/* 453 */
/***/ (function(module, exports, __webpack_require__) {
var defineWellKnownSymbol = __webpack_require__(10);
// `Symbol.matcher` well-known symbol
// https://github.com/tc39/proposal-pattern-matching
defineWellKnownSymbol('matcher');
/***/ }),
/* 454 */
/***/ (function(module, exports, __webpack_require__) {
var defineWellKnownSymbol = __webpack_require__(10);
// `Symbol.metadataKey` well-known symbol
// https://github.com/tc39/proposal-decorator-metadata
defineWellKnownSymbol('metadataKey');
/***/ }),
/* 455 */
/***/ (function(module, exports, __webpack_require__) {
var defineWellKnownSymbol = __webpack_require__(10);
// `Symbol.observable` well-known symbol
// https://github.com/tc39/proposal-observable
defineWellKnownSymbol('observable');
/***/ }),
/* 456 */
/***/ (function(module, exports, __webpack_require__) {
// TODO: Remove from `core-js@4`
var defineWellKnownSymbol = __webpack_require__(10);
// `Symbol.metadata` well-known symbol
// https://github.com/tc39/proposal-decorators
defineWellKnownSymbol('metadata');
/***/ }),
/* 457 */
/***/ (function(module, exports, __webpack_require__) {
// TODO: remove from `core-js@4`
var defineWellKnownSymbol = __webpack_require__(10);
// `Symbol.patternMatch` well-known symbol
// https://github.com/tc39/proposal-pattern-matching
defineWellKnownSymbol('patternMatch');
/***/ }),
/* 458 */
/***/ (function(module, exports, __webpack_require__) {
// TODO: remove from `core-js@4`
var defineWellKnownSymbol = __webpack_require__(10);
defineWellKnownSymbol('replaceAll');
/***/ }),
/* 459 */
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(460);
/***/ }),
/* 460 */
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(461);
/***/ }),
/* 461 */
/***/ (function(module, exports, __webpack_require__) {
var parent = __webpack_require__(462);
module.exports = parent;
/***/ }),
/* 462 */
/***/ (function(module, exports, __webpack_require__) {
var parent = __webpack_require__(249);
module.exports = parent;
/***/ }),
/* 463 */
/***/ (function(module, exports, __webpack_require__) {
__webpack_require__(38);
__webpack_require__(53);
__webpack_require__(55);
__webpack_require__(248);
var WrappedWellKnownSymbolModule = __webpack_require__(148);
module.exports = WrappedWellKnownSymbolModule.f('iterator');
/***/ }),
/* 464 */
/***/ (function(module, exports, __webpack_require__) {
var parent = __webpack_require__(465);
module.exports = parent;
/***/ }),
/* 465 */
/***/ (function(module, exports, __webpack_require__) {
var isPrototypeOf = __webpack_require__(19);
var method = __webpack_require__(466);
var ArrayPrototype = Array.prototype;
module.exports = function (it) {
var own = it.filter;
return it === ArrayPrototype || (isPrototypeOf(ArrayPrototype, it) && own === ArrayPrototype.filter) ? method : own;
};
/***/ }),
/* 466 */
/***/ (function(module, exports, __webpack_require__) {
__webpack_require__(467);
var entryVirtual = __webpack_require__(40);
module.exports = entryVirtual('Array').filter;
/***/ }),
/* 467 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var $ = __webpack_require__(0);
var $filter = __webpack_require__(70).filter;
var arrayMethodHasSpeciesSupport = __webpack_require__(114);
var HAS_SPECIES_SUPPORT = arrayMethodHasSpeciesSupport('filter');
// `Array.prototype.filter` method
// https://tc39.es/ecma262/#sec-array.prototype.filter
// with adding support of @@species
$({ target: 'Array', proto: true, forced: !HAS_SPECIES_SUPPORT }, {
filter: function filter(callbackfn /* , thisArg */) {
return $filter(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
}
});
/***/ }),
/* 468 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var _interopRequireDefault = __webpack_require__(1);
var _slice = _interopRequireDefault(__webpack_require__(61));
var _keys = _interopRequireDefault(__webpack_require__(59));
var _concat = _interopRequireDefault(__webpack_require__(22));
var _ = __webpack_require__(3);
module.exports = function (AV) {
var eventSplitter = /\s+/;
var slice = (0, _slice.default)(Array.prototype);
/**
* @class
*
*
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;
};
/***/ }),
/* 469 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var _interopRequireDefault = __webpack_require__(1);
var _promise = _interopRequireDefault(__webpack_require__(12));
var _ = __webpack_require__(3);
/*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;
}
});
};
/***/ }),
/* 470 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var _ = __webpack_require__(3);
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');
};
};
/***/ }),
/* 471 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var _interopRequireDefault = __webpack_require__(1);
var _concat = _interopRequireDefault(__webpack_require__(22));
var _find = _interopRequireDefault(__webpack_require__(93));
var _indexOf = _interopRequireDefault(__webpack_require__(71));
var _map = _interopRequireDefault(__webpack_require__(35));
var _ = __webpack_require__(3);
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));
});
};
/***/ }),
/* 472 */
/***/ (function(module, exports, __webpack_require__) {
var parent = __webpack_require__(473);
module.exports = parent;
/***/ }),
/* 473 */
/***/ (function(module, exports, __webpack_require__) {
var isPrototypeOf = __webpack_require__(19);
var method = __webpack_require__(474);
var ArrayPrototype = Array.prototype;
module.exports = function (it) {
var own = it.find;
return it === ArrayPrototype || (isPrototypeOf(ArrayPrototype, it) && own === ArrayPrototype.find) ? method : own;
};
/***/ }),
/* 474 */
/***/ (function(module, exports, __webpack_require__) {
__webpack_require__(475);
var entryVirtual = __webpack_require__(40);
module.exports = entryVirtual('Array').find;
/***/ }),
/* 475 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var $ = __webpack_require__(0);
var $find = __webpack_require__(70).find;
var addToUnscopables = __webpack_require__(169);
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);
/***/ }),
/* 476 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var _ = __webpack_require__(3);
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;
}
});
};
/***/ }),
/* 477 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var _interopRequireDefault = __webpack_require__(1);
var _promise = _interopRequireDefault(__webpack_require__(12));
var _ = __webpack_require__(3);
var cos = __webpack_require__(478);
var qiniu = __webpack_require__(479);
var s3 = __webpack_require__(525);
var AVError = __webpack_require__(46);
var _require = __webpack_require__(27),
request = _require.request,
AVRequest = _require._request;
var _require2 = __webpack_require__(30),
tap = _require2.tap,
transformFetchOptions = _require2.transformFetchOptions;
var debug = __webpack_require__(60)('leancloud:file');
var parseBase64 = __webpack_require__(529);
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);
}
});
};
/***/ }),
/* 478 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var _require = __webpack_require__(72),
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;
});
};
/***/ }),
/* 479 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var _sliceInstanceProperty2 = __webpack_require__(61);
var _Array$from = __webpack_require__(252);
var _Symbol = __webpack_require__(149);
var _getIteratorMethod = __webpack_require__(254);
var _Reflect$construct = __webpack_require__(489);
var _interopRequireDefault = __webpack_require__(1);
var _inherits2 = _interopRequireDefault(__webpack_require__(493));
var _possibleConstructorReturn2 = _interopRequireDefault(__webpack_require__(515));
var _getPrototypeOf2 = _interopRequireDefault(__webpack_require__(517));
var _classCallCheck2 = _interopRequireDefault(__webpack_require__(522));
var _createClass2 = _interopRequireDefault(__webpack_require__(523));
var _stringify = _interopRequireDefault(__webpack_require__(36));
var _concat = _interopRequireDefault(__webpack_require__(22));
var _promise = _interopRequireDefault(__webpack_require__(12));
var _slice = _interopRequireDefault(__webpack_require__(61));
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__(72),
getAdapter = _require.getAdapter;
var debug = __webpack_require__(60)('leancloud:qiniu');
var ajax = __webpack_require__(116);
var btoa = __webpack_require__(524);
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);
};
/***/ }),
/* 480 */
/***/ (function(module, exports, __webpack_require__) {
__webpack_require__(55);
__webpack_require__(481);
var path = __webpack_require__(5);
module.exports = path.Array.from;
/***/ }),
/* 481 */
/***/ (function(module, exports, __webpack_require__) {
var $ = __webpack_require__(0);
var from = __webpack_require__(482);
var checkCorrectnessOfIteration = __webpack_require__(178);
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
});
/***/ }),
/* 482 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var bind = __webpack_require__(48);
var call = __webpack_require__(15);
var toObject = __webpack_require__(34);
var callWithSafeIterationClosing = __webpack_require__(483);
var isArrayIteratorMethod = __webpack_require__(166);
var isConstructor = __webpack_require__(109);
var lengthOfArrayLike = __webpack_require__(41);
var createProperty = __webpack_require__(91);
var getIterator = __webpack_require__(167);
var getIteratorMethod = __webpack_require__(106);
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;
};
/***/ }),
/* 483 */
/***/ (function(module, exports, __webpack_require__) {
var anObject = __webpack_require__(20);
var iteratorClose = __webpack_require__(168);
// 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);
}
};
/***/ }),
/* 484 */
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(485);
/***/ }),
/* 485 */
/***/ (function(module, exports, __webpack_require__) {
var parent = __webpack_require__(486);
module.exports = parent;
/***/ }),
/* 486 */
/***/ (function(module, exports, __webpack_require__) {
var parent = __webpack_require__(487);
module.exports = parent;
/***/ }),
/* 487 */
/***/ (function(module, exports, __webpack_require__) {
var parent = __webpack_require__(488);
__webpack_require__(39);
module.exports = parent;
/***/ }),
/* 488 */
/***/ (function(module, exports, __webpack_require__) {
__webpack_require__(38);
__webpack_require__(55);
var getIteratorMethod = __webpack_require__(106);
module.exports = getIteratorMethod;
/***/ }),
/* 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__) {
__webpack_require__(492);
var path = __webpack_require__(5);
module.exports = path.Reflect.construct;
/***/ }),
/* 492 */
/***/ (function(module, exports, __webpack_require__) {
var $ = __webpack_require__(0);
var getBuiltIn = __webpack_require__(18);
var apply = __webpack_require__(75);
var bind = __webpack_require__(255);
var aConstructor = __webpack_require__(174);
var anObject = __webpack_require__(20);
var isObject = __webpack_require__(11);
var create = __webpack_require__(49);
var fails = __webpack_require__(2);
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;
}
});
/***/ }),
/* 493 */
/***/ (function(module, exports, __webpack_require__) {
var _Object$create = __webpack_require__(494);
var _Object$defineProperty = __webpack_require__(150);
var setPrototypeOf = __webpack_require__(504);
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;
/***/ }),
/* 494 */
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(495);
/***/ }),
/* 495 */
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(496);
/***/ }),
/* 496 */
/***/ (function(module, exports, __webpack_require__) {
var parent = __webpack_require__(497);
module.exports = parent;
/***/ }),
/* 497 */
/***/ (function(module, exports, __webpack_require__) {
var parent = __webpack_require__(498);
module.exports = parent;
/***/ }),
/* 498 */
/***/ (function(module, exports, __webpack_require__) {
var parent = __webpack_require__(499);
module.exports = parent;
/***/ }),
/* 499 */
/***/ (function(module, exports, __webpack_require__) {
__webpack_require__(500);
var path = __webpack_require__(5);
var Object = path.Object;
module.exports = function create(P, D) {
return Object.create(P, D);
};
/***/ }),
/* 500 */
/***/ (function(module, exports, __webpack_require__) {
// TODO: Remove from `core-js@4`
var $ = __webpack_require__(0);
var DESCRIPTORS = __webpack_require__(14);
var create = __webpack_require__(49);
// `Object.create` method
// https://tc39.es/ecma262/#sec-object.create
$({ target: 'Object', stat: true, sham: !DESCRIPTORS }, {
create: create
});
/***/ }),
/* 501 */
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(502);
/***/ }),
/* 502 */
/***/ (function(module, exports, __webpack_require__) {
var parent = __webpack_require__(503);
module.exports = parent;
/***/ }),
/* 503 */
/***/ (function(module, exports, __webpack_require__) {
var parent = __webpack_require__(241);
module.exports = parent;
/***/ }),
/* 504 */
/***/ (function(module, exports, __webpack_require__) {
var _Object$setPrototypeOf = __webpack_require__(256);
var _bindInstanceProperty = __webpack_require__(257);
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;
/***/ }),
/* 505 */
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(506);
/***/ }),
/* 506 */
/***/ (function(module, exports, __webpack_require__) {
var parent = __webpack_require__(507);
module.exports = parent;
/***/ }),
/* 507 */
/***/ (function(module, exports, __webpack_require__) {
var parent = __webpack_require__(239);
module.exports = parent;
/***/ }),
/* 508 */
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(509);
/***/ }),
/* 509 */
/***/ (function(module, exports, __webpack_require__) {
var parent = __webpack_require__(510);
module.exports = parent;
/***/ }),
/* 510 */
/***/ (function(module, exports, __webpack_require__) {
var parent = __webpack_require__(511);
module.exports = parent;
/***/ }),
/* 511 */
/***/ (function(module, exports, __webpack_require__) {
var parent = __webpack_require__(512);
module.exports = parent;
/***/ }),
/* 512 */
/***/ (function(module, exports, __webpack_require__) {
var isPrototypeOf = __webpack_require__(19);
var method = __webpack_require__(513);
var FunctionPrototype = Function.prototype;
module.exports = function (it) {
var own = it.bind;
return it === FunctionPrototype || (isPrototypeOf(FunctionPrototype, it) && own === FunctionPrototype.bind) ? method : own;
};
/***/ }),
/* 513 */
/***/ (function(module, exports, __webpack_require__) {
__webpack_require__(514);
var entryVirtual = __webpack_require__(40);
module.exports = entryVirtual('Function').bind;
/***/ }),
/* 514 */
/***/ (function(module, exports, __webpack_require__) {
// TODO: Remove from `core-js@4`
var $ = __webpack_require__(0);
var bind = __webpack_require__(255);
// `Function.prototype.bind` method
// https://tc39.es/ecma262/#sec-function.prototype.bind
$({ target: 'Function', proto: true, forced: Function.bind !== bind }, {
bind: bind
});
/***/ }),
/* 515 */
/***/ (function(module, exports, __webpack_require__) {
var _typeof = __webpack_require__(73)["default"];
var assertThisInitialized = __webpack_require__(516);
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;
/***/ }),
/* 516 */
/***/ (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;
/***/ }),
/* 517 */
/***/ (function(module, exports, __webpack_require__) {
var _Object$setPrototypeOf = __webpack_require__(256);
var _bindInstanceProperty = __webpack_require__(257);
var _Object$getPrototypeOf = __webpack_require__(518);
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;
/***/ }),
/* 518 */
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(519);
/***/ }),
/* 519 */
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(520);
/***/ }),
/* 520 */
/***/ (function(module, exports, __webpack_require__) {
var parent = __webpack_require__(521);
module.exports = parent;
/***/ }),
/* 521 */
/***/ (function(module, exports, __webpack_require__) {
var parent = __webpack_require__(233);
module.exports = parent;
/***/ }),
/* 522 */
/***/ (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;
/***/ }),
/* 523 */
/***/ (function(module, exports, __webpack_require__) {
var _Object$defineProperty = __webpack_require__(150);
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;
/***/ }),
/* 524 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var _interopRequireDefault = __webpack_require__(1);
var _slice = _interopRequireDefault(__webpack_require__(61));
// 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;
};
/***/ }),
/* 525 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var _ = __webpack_require__(3);
var ajax = __webpack_require__(116);
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;
});
};
/***/ }),
/* 526 */
/***/ (function(module, exports, __webpack_require__) {
(function(){
var crypt = __webpack_require__(527),
utf8 = __webpack_require__(258).utf8,
isBuffer = __webpack_require__(528),
bin = __webpack_require__(258).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);
};
})();
/***/ }),
/* 527 */
/***/ (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;
})();
/***/ }),
/* 528 */
/***/ (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))
}
/***/ }),
/* 529 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var _interopRequireDefault = __webpack_require__(1);
var _indexOf = _interopRequireDefault(__webpack_require__(71));
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;
/***/ }),
/* 530 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var _interopRequireDefault = __webpack_require__(1);
var _slicedToArray2 = _interopRequireDefault(__webpack_require__(531));
var _map = _interopRequireDefault(__webpack_require__(35));
var _indexOf = _interopRequireDefault(__webpack_require__(71));
var _find = _interopRequireDefault(__webpack_require__(93));
var _promise = _interopRequireDefault(__webpack_require__(12));
var _concat = _interopRequireDefault(__webpack_require__(22));
var _keys2 = _interopRequireDefault(__webpack_require__(59));
var _stringify = _interopRequireDefault(__webpack_require__(36));
var _defineProperty = _interopRequireDefault(__webpack_require__(92));
var _getOwnPropertyDescriptor = _interopRequireDefault(__webpack_require__(151));
var _ = __webpack_require__(3);
var AVError = __webpack_require__(46);
var _require = __webpack_require__(27),
_request = _require._request;
var _require2 = __webpack_require__(30),
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;
});
};
};
/***/ }),
/* 531 */
/***/ (function(module, exports, __webpack_require__) {
var arrayWithHoles = __webpack_require__(532);
var iterableToArrayLimit = __webpack_require__(540);
var unsupportedIterableToArray = __webpack_require__(541);
var nonIterableRest = __webpack_require__(551);
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;
/***/ }),
/* 532 */
/***/ (function(module, exports, __webpack_require__) {
var _Array$isArray = __webpack_require__(533);
function _arrayWithHoles(arr) {
if (_Array$isArray(arr)) return arr;
}
module.exports = _arrayWithHoles, module.exports.__esModule = true, module.exports["default"] = module.exports;
/***/ }),
/* 533 */
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(534);
/***/ }),
/* 534 */
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(535);
/***/ }),
/* 535 */
/***/ (function(module, exports, __webpack_require__) {
var parent = __webpack_require__(536);
module.exports = parent;
/***/ }),
/* 536 */
/***/ (function(module, exports, __webpack_require__) {
var parent = __webpack_require__(537);
module.exports = parent;
/***/ }),
/* 537 */
/***/ (function(module, exports, __webpack_require__) {
var parent = __webpack_require__(538);
module.exports = parent;
/***/ }),
/* 538 */
/***/ (function(module, exports, __webpack_require__) {
__webpack_require__(539);
var path = __webpack_require__(5);
module.exports = path.Array.isArray;
/***/ }),
/* 539 */
/***/ (function(module, exports, __webpack_require__) {
var $ = __webpack_require__(0);
var isArray = __webpack_require__(90);
// `Array.isArray` method
// https://tc39.es/ecma262/#sec-array.isarray
$({ target: 'Array', stat: true }, {
isArray: isArray
});
/***/ }),
/* 540 */
/***/ (function(module, exports, __webpack_require__) {
var _Symbol = __webpack_require__(242);
var _getIteratorMethod = __webpack_require__(254);
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;
/***/ }),
/* 541 */
/***/ (function(module, exports, __webpack_require__) {
var _sliceInstanceProperty = __webpack_require__(542);
var _Array$from = __webpack_require__(546);
var arrayLikeToArray = __webpack_require__(550);
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;
/***/ }),
/* 542 */
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(543);
/***/ }),
/* 543 */
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(544);
/***/ }),
/* 544 */
/***/ (function(module, exports, __webpack_require__) {
var parent = __webpack_require__(545);
module.exports = parent;
/***/ }),
/* 545 */
/***/ (function(module, exports, __webpack_require__) {
var parent = __webpack_require__(240);
module.exports = parent;
/***/ }),
/* 546 */
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(547);
/***/ }),
/* 547 */
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(548);
/***/ }),
/* 548 */
/***/ (function(module, exports, __webpack_require__) {
var parent = __webpack_require__(549);
module.exports = parent;
/***/ }),
/* 549 */
/***/ (function(module, exports, __webpack_require__) {
var parent = __webpack_require__(253);
module.exports = parent;
/***/ }),
/* 550 */
/***/ (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;
/***/ }),
/* 551 */
/***/ (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;
/***/ }),
/* 552 */
/***/ (function(module, exports, __webpack_require__) {
var parent = __webpack_require__(553);
module.exports = parent;
/***/ }),
/* 553 */
/***/ (function(module, exports, __webpack_require__) {
__webpack_require__(554);
var path = __webpack_require__(5);
var Object = path.Object;
var getOwnPropertyDescriptor = module.exports = function getOwnPropertyDescriptor(it, key) {
return Object.getOwnPropertyDescriptor(it, key);
};
if (Object.getOwnPropertyDescriptor.sham) getOwnPropertyDescriptor.sham = true;
/***/ }),
/* 554 */
/***/ (function(module, exports, __webpack_require__) {
var $ = __webpack_require__(0);
var fails = __webpack_require__(2);
var toIndexedObject = __webpack_require__(32);
var nativeGetOwnPropertyDescriptor = __webpack_require__(62).f;
var DESCRIPTORS = __webpack_require__(14);
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);
}
});
/***/ }),
/* 555 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var _ = __webpack_require__(3);
var AVError = __webpack_require__(46);
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;
}
});
};
/***/ }),
/* 556 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var _interopRequireDefault = __webpack_require__(1);
var _defineProperty2 = _interopRequireDefault(__webpack_require__(557));
var _promise = _interopRequireDefault(__webpack_require__(12));
var _map = _interopRequireDefault(__webpack_require__(35));
var _find = _interopRequireDefault(__webpack_require__(93));
var _stringify = _interopRequireDefault(__webpack_require__(36));
var _ = __webpack_require__(3);
var uuid = __webpack_require__(232);
var AVError = __webpack_require__(46);
var _require = __webpack_require__(27),
AVRequest = _require._request,
request = _require.request;
var _require2 = __webpack_require__(72),
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;
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)
}, {
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;
var getAuthInfo = getAdapter('getAuthInfo');
return getAuthInfo({
preferUnionId: preferUnionId,
asMainAccount: asMainAccount,
platform: unionIdPlatform
}).then(function (authInfo) {
return _this7.loginWithMiniApp(authInfo, {
failOnNotExist: failOnNotExist
});
});
},
/**
* 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;
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
});
});
},
/**
* 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;
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
});
});
},
/**
* 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;
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
});
});
},
/**
* 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;
var getAuthInfo = getAdapter('getAuthInfo');
return getAuthInfo({
preferUnionId: preferUnionId,
asMainAccount: asMainAccount,
platform: unionIdPlatform
}).then(function (authInfo) {
return _this15.loginWithMiniApp(authInfo, {
failOnNotExist: failOnNotExist
});
});
},
/**
* 使用当前使用微信小程序的微信用户身份注册或登录,
* 仅在微信小程序中可用。
*
* @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;
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
});
});
},
/**
* 使用当前使用 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;
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
});
});
},
/**
* 使用当前使用 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;
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
});
});
},
/**
* 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);
}
});
};
/***/ }),
/* 557 */
/***/ (function(module, exports, __webpack_require__) {
var _Object$defineProperty = __webpack_require__(150);
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;
/***/ }),
/* 558 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var _interopRequireDefault = __webpack_require__(1);
var _map = _interopRequireDefault(__webpack_require__(35));
var _promise = _interopRequireDefault(__webpack_require__(12));
var _keys = _interopRequireDefault(__webpack_require__(59));
var _stringify = _interopRequireDefault(__webpack_require__(36));
var _find = _interopRequireDefault(__webpack_require__(93));
var _concat = _interopRequireDefault(__webpack_require__(22));
var _ = __webpack_require__(3);
var debug = __webpack_require__(60)('leancloud:query');
var AVError = __webpack_require__(46);
var _require = __webpack_require__(27),
_request = _require._request,
request = _require.request;
var _require2 = __webpack_require__(30),
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;
}
}
});
};
/***/ }),
/* 559 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var _interopRequireDefault = __webpack_require__(1);
var _promise = _interopRequireDefault(__webpack_require__(12));
var _keys = _interopRequireDefault(__webpack_require__(59));
var _ = __webpack_require__(3);
var EventEmitter = __webpack_require__(235);
var _require = __webpack_require__(30),
inherits = _require.inherits;
var _require2 = __webpack_require__(27),
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();
}
});
};
/***/ }),
/* 560 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var _ = __webpack_require__(3);
var _require = __webpack_require__(30),
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 (false) {
/**
* 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;
});
};
};
/***/ }),
/* 561 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var _interopRequireDefault = __webpack_require__(1);
var _promise = _interopRequireDefault(__webpack_require__(12));
var _ = __webpack_require__(3);
var _require = __webpack_require__(27),
_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;
});
}
});
};
/***/ }),
/* 562 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var request = __webpack_require__(27).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
});
};
};
/***/ }),
/* 563 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var _interopRequireDefault = __webpack_require__(1);
var _promise = _interopRequireDefault(__webpack_require__(12));
var _typeof2 = _interopRequireDefault(__webpack_require__(73));
var _ = __webpack_require__(3);
var AVRequest = __webpack_require__(27)._request;
var _require = __webpack_require__(30),
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;
};
};
/***/ }),
/* 564 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var _interopRequireDefault = __webpack_require__(1);
var _stringify = _interopRequireDefault(__webpack_require__(36));
var _map = _interopRequireDefault(__webpack_require__(35));
var _ = __webpack_require__(3);
var AVRequest = __webpack_require__(27)._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.
*/
/***/ }),
/* 565 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var _interopRequireDefault = __webpack_require__(1);
var _promise = _interopRequireDefault(__webpack_require__(12));
var _ = __webpack_require__(3);
var AVError = __webpack_require__(46);
var _require = __webpack_require__(27),
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);
});
}
});
};
/***/ }),
/* 566 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var _interopRequireDefault = __webpack_require__(1);
var _promise = _interopRequireDefault(__webpack_require__(12));
var _ = __webpack_require__(3);
var _require = __webpack_require__(27),
LCRequest = _require.request;
var _require2 = __webpack_require__(30),
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
});
});
}
};
};
/***/ }),
/* 567 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var _interopRequireDefault = __webpack_require__(1);
var _stringify = _interopRequireDefault(__webpack_require__(36));
var _ = __webpack_require__(3);
var _require = __webpack_require__(27),
_request = _require._request;
var AV = __webpack_require__(69);
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.
*
*
* @class AV.Conversation
* @param {String} name The name of the Role to create.
* @param {Object} [options]
* @param {Boolean} [options.isSystem] Set this conversation as system conversation.
* @param {Boolean} [options.isTransient] Set this conversation as transient conversation.
*/
module.exports = AV.Object.extend('_Conversation',
/** @lends AV.Conversation.prototype */
{
constructor: function constructor(name) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
AV.Object.prototype.constructor.call(this, null, null);
this.set('name', name);
if (options.isSystem !== undefined) {
this.set('sys', options.isSystem ? true : false);
}
if (options.isTransient !== undefined) {
this.set('tr', options.isTransient ? true : false);
}
},
/**
* Get current conversation's creator.
*
* @return {String}
*/
getCreator: function getCreator() {
return this.get('c');
},
/**
* Get the last message's time.
*
* @return {Date}
*/
getLastMessageAt: function getLastMessageAt() {
return this.get('lm');
},
/**
* Get this conversation's members
*
* @return {String[]}
*/
getMembers: function getMembers() {
return this.get('m');
},
/**
* Add a member to this conversation
*
* @param {String} member
*/
addMember: function addMember(member) {
return this.add('m', member);
},
/**
* Get this conversation's members who set this conversation as muted.
*
* @return {String[]}
*/
getMutedMembers: function getMutedMembers() {
return this.get('mu');
},
/**
* Get this conversation's name field.
*
* @return String
*/
getName: function getName() {
return this.get('name');
},
/**
* Returns true if this conversation is transient conversation.
*
* @return {Boolean}
*/
isTransient: function isTransient() {
return this.get('tr');
},
/**
* Returns true if this conversation is system conversation.
*
* @return {Boolean}
*/
isSystem: function isSystem() {
return this.get('sys');
},
/**
* Send realtime message to this conversation, using HTTP request.
*
* @param {String} fromClient Sender's client id.
* @param {String|Object} message The message which will send to conversation.
* It could be a raw string, or an object with a `toJSON` method, like a
* realtime SDK's Message object. See more: {@link https://leancloud.cn/docs/realtime_guide-js.html#消息}
* @param {Object} [options]
* @param {Boolean} [options.transient] Whether send this message as transient message or not.
* @param {String[]} [options.toClients] Ids of clients to send to. This option can be used only in system conversation.
* @param {Object} [options.pushData] Push data to this message. See more: {@link https://url.leanapp.cn/pushData 推送消息内容}
* @param {AuthOptions} [authOptions]
* @return {Promise}
*/
send: function send(fromClient, message) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var authOptions = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
var data = {
from_peer: fromClient,
conv_id: this.id,
transient: false,
message: serializeMessage(message)
};
if (options.toClients !== undefined) {
data.to_peers = options.toClients;
}
if (options.transient !== undefined) {
data.transient = options.transient ? true : false;
}
if (options.pushData !== undefined) {
data.push_data = options.pushData;
}
return _request('rtm', 'messages', null, 'POST', data, authOptions);
},
/**
* Send realtime broadcast message to all clients, via this conversation, using HTTP request.
*
* @param {String} fromClient Sender's client id.
* @param {String|Object} message The message which will send to conversation.
* It could be a raw string, or an object with a `toJSON` method, like a
* realtime SDK's Message object. See more: {@link https://leancloud.cn/docs/realtime_guide-js.html#消息}.
* @param {Object} [options]
* @param {Object} [options.pushData] Push data to this message. See more: {@link https://url.leanapp.cn/pushData 推送消息内容}.
* @param {Object} [options.validTill] The message will valid till this time.
* @param {AuthOptions} [authOptions]
* @return {Promise}
*/
broadcast: function broadcast(fromClient, message) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var authOptions = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
var data = {
from_peer: fromClient,
conv_id: this.id,
message: serializeMessage(message)
};
if (options.pushData !== undefined) {
data.push = options.pushData;
}
if (options.validTill !== undefined) {
var ts = options.validTill;
if (_.isDate(ts)) {
ts = ts.getTime();
}
options.valid_till = ts;
}
return _request('rtm', 'broadcast', null, 'POST', data, authOptions);
}
});
/***/ }),
/* 568 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var _interopRequireDefault = __webpack_require__(1);
var _promise = _interopRequireDefault(__webpack_require__(12));
var _map = _interopRequireDefault(__webpack_require__(35));
var _concat = _interopRequireDefault(__webpack_require__(22));
var _ = __webpack_require__(3);
var _require = __webpack_require__(27),
request = _require.request;
var _require2 = __webpack_require__(30),
ensureArray = _require2.ensureArray,
parseDate = _require2.parseDate;
var AV = __webpack_require__(69);
/**
* The version change interval for Leaderboard
* @enum
*/
AV.LeaderboardVersionChangeInterval = {
NEVER: 'never',
DAY: 'day',
WEEK: 'week',
MONTH: 'month'
};
/**
* The order of the leaderboard results
* @enum
*/
AV.LeaderboardOrder = {
ASCENDING: 'ascending',
DESCENDING: 'descending'
};
/**
* The update strategy for Leaderboard
* @enum
*/
AV.LeaderboardUpdateStrategy = {
/** Only keep the best statistic. If the leaderboard is in descending order, the best statistic is the highest one. */
BETTER: 'better',
/** Keep the last updated statistic */
LAST: 'last',
/** Keep the sum of all updated statistics */
SUM: 'sum'
};
/**
* @typedef {Object} Ranking
* @property {number} rank Starts at 0
* @property {number} value the statistic value of this ranking
* @property {AV.User} user The user of this ranking
* @property {Statistic[]} [includedStatistics] Other statistics of the user, specified by the `includeStatistic` option of `AV.Leaderboard.getResults()`
*/
/**
* @typedef {Object} LeaderboardArchive
* @property {string} statisticName
* @property {number} version version of the leaderboard
* @property {string} status
* @property {string} url URL for the downloadable archive
* @property {Date} activatedAt time when this version became active
* @property {Date} deactivatedAt time when this version was deactivated by a version incrementing
*/
/**
* @class
*/
function Statistic(_ref) {
var name = _ref.name,
value = _ref.value,
version = _ref.version;
/**
* @type {string}
*/
this.name = name;
/**
* @type {number}
*/
this.value = value;
/**
* @type {number?}
*/
this.version = version;
}
var parseStatisticData = function parseStatisticData(statisticData) {
var _AV$_decode = AV._decode(statisticData),
name = _AV$_decode.statisticName,
value = _AV$_decode.statisticValue,
version = _AV$_decode.version;
return new Statistic({
name: name,
value: value,
version: version
});
};
/**
* @class
*/
AV.Leaderboard = function Leaderboard(statisticName) {
/**
* @type {string}
*/
this.statisticName = statisticName;
/**
* @type {AV.LeaderboardOrder}
*/
this.order = undefined;
/**
* @type {AV.LeaderboardUpdateStrategy}
*/
this.updateStrategy = undefined;
/**
* @type {AV.LeaderboardVersionChangeInterval}
*/
this.versionChangeInterval = undefined;
/**
* @type {number}
*/
this.version = undefined;
/**
* @type {Date?}
*/
this.nextResetAt = undefined;
/**
* @type {Date?}
*/
this.createdAt = undefined;
};
var Leaderboard = AV.Leaderboard;
/**
* Create an instance of Leaderboard for the give statistic name.
* @param {string} statisticName
* @return {AV.Leaderboard}
*/
AV.Leaderboard.createWithoutData = function (statisticName) {
return new Leaderboard(statisticName);
};
/**
* (masterKey required) Create a new Leaderboard.
* @param {Object} options
* @param {string} options.statisticName
* @param {AV.LeaderboardOrder} options.order
* @param {AV.LeaderboardVersionChangeInterval} [options.versionChangeInterval] default to WEEK
* @param {AV.LeaderboardUpdateStrategy} [options.updateStrategy] default to BETTER
* @param {AuthOptions} [authOptions]
* @return {Promise}
*/
AV.Leaderboard.createLeaderboard = function (_ref2, authOptions) {
var statisticName = _ref2.statisticName,
order = _ref2.order,
versionChangeInterval = _ref2.versionChangeInterval,
updateStrategy = _ref2.updateStrategy;
return request({
method: 'POST',
path: '/leaderboard/leaderboards',
data: {
statisticName: statisticName,
order: order,
versionChangeInterval: versionChangeInterval,
updateStrategy: updateStrategy
},
authOptions: authOptions
}).then(function (data) {
var leaderboard = new Leaderboard(statisticName);
return leaderboard._finishFetch(data);
});
};
/**
* Get the Leaderboard with the specified statistic name.
* @param {string} statisticName
* @param {AuthOptions} [authOptions]
* @return {Promise}
*/
AV.Leaderboard.getLeaderboard = function (statisticName, authOptions) {
return Leaderboard.createWithoutData(statisticName).fetch(authOptions);
};
/**
* Get Statistics for the specified user.
* @param {AV.User} user The specified AV.User pointer.
* @param {Object} [options]
* @param {string[]} [options.statisticNames] Specify the statisticNames. If not set, all statistics of the user will be fetched.
* @param {AuthOptions} [authOptions]
* @return {Promise}
*/
AV.Leaderboard.getStatistics = function (user) {
var _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
statisticNames = _ref3.statisticNames;
var authOptions = arguments.length > 2 ? arguments[2] : undefined;
return _promise.default.resolve().then(function () {
if (!(user && user.id)) throw new Error('user must be an AV.User');
return request({
method: 'GET',
path: "/leaderboard/users/".concat(user.id, "/statistics"),
query: {
statistics: statisticNames ? ensureArray(statisticNames).join(',') : undefined
},
authOptions: authOptions
}).then(function (_ref4) {
var results = _ref4.results;
return (0, _map.default)(results).call(results, parseStatisticData);
});
});
};
/**
* Update Statistics for the specified user.
* @param {AV.User} user The specified AV.User pointer.
* @param {Object} statistics A name-value pair representing the statistics to update.
* @param {AuthOptions} [options] AuthOptions plus:
* @param {boolean} [options.overwrite] Wethere to overwrite these statistics disregarding the updateStrategy of there leaderboards
* @return {Promise}
*/
AV.Leaderboard.updateStatistics = function (user, statistics) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
return _promise.default.resolve().then(function () {
if (!(user && user.id)) throw new Error('user must be an AV.User');
var data = (0, _map.default)(_).call(_, statistics, function (value, key) {
return {
statisticName: key,
statisticValue: value
};
});
var overwrite = options.overwrite;
return request({
method: 'POST',
path: "/leaderboard/users/".concat(user.id, "/statistics"),
query: {
overwrite: overwrite ? 1 : undefined
},
data: data,
authOptions: options
}).then(function (_ref5) {
var results = _ref5.results;
return (0, _map.default)(results).call(results, parseStatisticData);
});
});
};
/**
* Delete Statistics for the specified user.
* @param {AV.User} user The specified AV.User pointer.
* @param {Object} statistics A name-value pair representing the statistics to delete.
* @param {AuthOptions} [options]
* @return {Promise}
*/
AV.Leaderboard.deleteStatistics = function (user, statisticNames, authOptions) {
return _promise.default.resolve().then(function () {
if (!(user && user.id)) throw new Error('user must be an AV.User');
return request({
method: 'DELETE',
path: "/leaderboard/users/".concat(user.id, "/statistics"),
query: {
statistics: ensureArray(statisticNames).join(',')
},
authOptions: authOptions
}).then(function () {
return undefined;
});
});
};
_.extend(Leaderboard.prototype,
/** @lends AV.Leaderboard.prototype */
{
_finishFetch: function _finishFetch(data) {
var _this = this;
_.forEach(data, function (value, key) {
if (key === 'updatedAt' || key === 'objectId') return;
if (key === 'expiredAt') {
key = 'nextResetAt';
}
if (key === 'createdAt') {
value = parseDate(value);
}
if (value && value.__type === 'Date') {
value = parseDate(value.iso);
}
_this[key] = value;
});
return this;
},
/**
* Fetch data from the srever.
* @param {AuthOptions} [authOptions]
* @return {Promise}
*/
fetch: function fetch(authOptions) {
var _this2 = this;
return request({
method: 'GET',
path: "/leaderboard/leaderboards/".concat(this.statisticName),
authOptions: authOptions
}).then(function (data) {
return _this2._finishFetch(data);
});
},
/**
* Counts the number of users participated in this leaderboard
* @param {Object} [options]
* @param {number} [options.version] Specify the version of the leaderboard
* @param {AuthOptions} [authOptions]
* @return {Promise}
*/
count: function count() {
var _ref6 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
version = _ref6.version;
var authOptions = arguments.length > 1 ? arguments[1] : undefined;
return request({
method: 'GET',
path: "/leaderboard/leaderboards/".concat(this.statisticName, "/ranks"),
query: {
count: 1,
limit: 0,
version: version
},
authOptions: authOptions
}).then(function (_ref7) {
var count = _ref7.count;
return count;
});
},
_getResults: function _getResults(_ref8, authOptions, userId) {
var _context;
var skip = _ref8.skip,
limit = _ref8.limit,
selectUserKeys = _ref8.selectUserKeys,
includeUserKeys = _ref8.includeUserKeys,
includeStatistics = _ref8.includeStatistics,
version = _ref8.version;
return request({
method: 'GET',
path: (0, _concat.default)(_context = "/leaderboard/leaderboards/".concat(this.statisticName, "/ranks")).call(_context, userId ? "/".concat(userId) : ''),
query: {
skip: skip,
limit: limit,
selectUserKeys: _.union(ensureArray(selectUserKeys), ensureArray(includeUserKeys)).join(',') || undefined,
includeUser: includeUserKeys ? ensureArray(includeUserKeys).join(',') : undefined,
includeStatistics: includeStatistics ? ensureArray(includeStatistics).join(',') : undefined,
version: version
},
authOptions: authOptions
}).then(function (_ref9) {
var rankings = _ref9.results;
return (0, _map.default)(rankings).call(rankings, function (rankingData) {
var _AV$_decode2 = AV._decode(rankingData),
user = _AV$_decode2.user,
value = _AV$_decode2.statisticValue,
rank = _AV$_decode2.rank,
_AV$_decode2$statisti = _AV$_decode2.statistics,
statistics = _AV$_decode2$statisti === void 0 ? [] : _AV$_decode2$statisti;
return {
user: user,
value: value,
rank: rank,
includedStatistics: (0, _map.default)(statistics).call(statistics, parseStatisticData)
};
});
});
},
/**
* Retrieve a list of ranked users for this Leaderboard.
* @param {Object} [options]
* @param {number} [options.skip] The number of results to skip. This is useful for pagination.
* @param {number} [options.limit] The limit of the number of results.
* @param {string[]} [options.selectUserKeys] Specify keys of the users to include in the Rankings
* @param {string[]} [options.includeUserKeys] If the value of a selected user keys is a Pointer, use this options to include its value.
* @param {string[]} [options.includeStatistics] Specify other statistics to include in the Rankings
* @param {number} [options.version] Specify the version of the leaderboard
* @param {AuthOptions} [authOptions]
* @return {Promise}
*/
getResults: function getResults() {
var _ref10 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
skip = _ref10.skip,
limit = _ref10.limit,
selectUserKeys = _ref10.selectUserKeys,
includeUserKeys = _ref10.includeUserKeys,
includeStatistics = _ref10.includeStatistics,
version = _ref10.version;
var authOptions = arguments.length > 1 ? arguments[1] : undefined;
return this._getResults({
skip: skip,
limit: limit,
selectUserKeys: selectUserKeys,
includeUserKeys: includeUserKeys,
includeStatistics: includeStatistics,
version: version
}, authOptions);
},
/**
* Retrieve a list of ranked users for this Leaderboard, centered on the specified user.
* @param {AV.User} user The specified AV.User pointer.
* @param {Object} [options]
* @param {number} [options.limit] The limit of the number of results.
* @param {string[]} [options.selectUserKeys] Specify keys of the users to include in the Rankings
* @param {string[]} [options.includeUserKeys] If the value of a selected user keys is a Pointer, use this options to include its value.
* @param {string[]} [options.includeStatistics] Specify other statistics to include in the Rankings
* @param {number} [options.version] Specify the version of the leaderboard
* @param {AuthOptions} [authOptions]
* @return {Promise}
*/
getResultsAroundUser: function getResultsAroundUser(user) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var authOptions = arguments.length > 2 ? arguments[2] : undefined;
// getResultsAroundUser(options, authOptions)
if (user && typeof user.id !== 'string') {
return this.getResultsAroundUser(undefined, user, options);
}
var limit = options.limit,
selectUserKeys = options.selectUserKeys,
includeUserKeys = options.includeUserKeys,
includeStatistics = options.includeStatistics,
version = options.version;
return this._getResults({
limit: limit,
selectUserKeys: selectUserKeys,
includeUserKeys: includeUserKeys,
includeStatistics: includeStatistics,
version: version
}, authOptions, user ? user.id : 'self');
},
_update: function _update(data, authOptions) {
var _this3 = this;
return request({
method: 'PUT',
path: "/leaderboard/leaderboards/".concat(this.statisticName),
data: data,
authOptions: authOptions
}).then(function (result) {
return _this3._finishFetch(result);
});
},
/**
* (masterKey required) Update the version change interval of the Leaderboard.
* @param {AV.LeaderboardVersionChangeInterval} versionChangeInterval
* @param {AuthOptions} [authOptions]
* @return {Promise}
*/
updateVersionChangeInterval: function updateVersionChangeInterval(versionChangeInterval, authOptions) {
return this._update({
versionChangeInterval: versionChangeInterval
}, authOptions);
},
/**
* (masterKey required) Update the version change interval of the Leaderboard.
* @param {AV.LeaderboardUpdateStrategy} updateStrategy
* @param {AuthOptions} [authOptions]
* @return {Promise}
*/
updateUpdateStrategy: function updateUpdateStrategy(updateStrategy, authOptions) {
return this._update({
updateStrategy: updateStrategy
}, authOptions);
},
/**
* (masterKey required) Reset the Leaderboard. The version of the Leaderboard will be incremented by 1.
* @param {AuthOptions} [authOptions]
* @return {Promise}
*/
reset: function reset(authOptions) {
var _this4 = this;
return request({
method: 'PUT',
path: "/leaderboard/leaderboards/".concat(this.statisticName, "/incrementVersion"),
authOptions: authOptions
}).then(function (data) {
return _this4._finishFetch(data);
});
},
/**
* (masterKey required) Delete the Leaderboard and its all archived versions.
* @param {AuthOptions} [authOptions]
* @return {void}
*/
destroy: function destroy(authOptions) {
return AV.request({
method: 'DELETE',
path: "/leaderboard/leaderboards/".concat(this.statisticName),
authOptions: authOptions
}).then(function () {
return undefined;
});
},
/**
* (masterKey required) Get archived versions.
* @param {Object} [options]
* @param {number} [options.skip] The number of results to skip. This is useful for pagination.
* @param {number} [options.limit] The limit of the number of results.
* @param {AuthOptions} [authOptions]
* @return {Promise}
*/
getArchives: function getArchives() {
var _this5 = this;
var _ref11 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
skip = _ref11.skip,
limit = _ref11.limit;
var authOptions = arguments.length > 1 ? arguments[1] : undefined;
return request({
method: 'GET',
path: "/leaderboard/leaderboards/".concat(this.statisticName, "/archives"),
query: {
skip: skip,
limit: limit
},
authOptions: authOptions
}).then(function (_ref12) {
var results = _ref12.results;
return (0, _map.default)(results).call(results, function (_ref13) {
var version = _ref13.version,
status = _ref13.status,
url = _ref13.url,
activatedAt = _ref13.activatedAt,
deactivatedAt = _ref13.deactivatedAt;
return {
statisticName: _this5.statisticName,
version: version,
status: status,
url: url,
activatedAt: parseDate(activatedAt.iso),
deactivatedAt: parseDate(deactivatedAt.iso)
};
});
});
}
});
/***/ }),
/* 569 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var _interopRequireDefault = __webpack_require__(1);
var _typeof2 = _interopRequireDefault(__webpack_require__(73));
var _defineProperty = _interopRequireDefault(__webpack_require__(92));
var _setPrototypeOf = _interopRequireDefault(__webpack_require__(238));
var _assign2 = _interopRequireDefault(__webpack_require__(152));
var _indexOf = _interopRequireDefault(__webpack_require__(71));
var _getOwnPropertySymbols = _interopRequireDefault(__webpack_require__(153));
var _promise = _interopRequireDefault(__webpack_require__(12));
var _symbol = _interopRequireDefault(__webpack_require__(149));
var _iterator = _interopRequireDefault(__webpack_require__(576));
var _weakMap = _interopRequireDefault(__webpack_require__(260));
var _keys = _interopRequireDefault(__webpack_require__(115));
var _getOwnPropertyDescriptor = _interopRequireDefault(__webpack_require__(151));
var _getPrototypeOf = _interopRequireDefault(__webpack_require__(147));
var _map = _interopRequireDefault(__webpack_require__(583));
(0, _defineProperty.default)(exports, '__esModule', {
value: true
});
/******************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise */
var _extendStatics$ = function extendStatics$1(d, b) {
_extendStatics$ = _setPrototypeOf.default || {
__proto__: []
} instanceof Array && function (d, b) {
d.__proto__ = b;
} || function (d, b) {
for (var p in b) {
if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
}
};
return _extendStatics$(d, b);
};
function __extends$1(d, b) {
if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
_extendStatics$(d, b);
function __() {
this.constructor = d;
}
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var _assign = function __assign() {
_assign = _assign2.default || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) {
if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
}
return t;
};
return _assign.apply(this, arguments);
};
function __rest(s, e) {
var t = {};
for (var p in s) {
if (Object.prototype.hasOwnProperty.call(s, p) && (0, _indexOf.default)(e).call(e, p) < 0) t[p] = s[p];
}
if (s != null && typeof _getOwnPropertySymbols.default === "function") for (var i = 0, p = (0, _getOwnPropertySymbols.default)(s); i < p.length; i++) {
if ((0, _indexOf.default)(e).call(e, p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
}
return t;
}
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) {
return value instanceof P ? value : new P(function (resolve) {
resolve(value);
});
}
return new (P || (P = _promise.default))(function (resolve, reject) {
function fulfilled(value) {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
}
function rejected(value) {
try {
step(generator["throw"](value));
} catch (e) {
reject(e);
}
}
function step(result) {
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
}
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = {
label: 0,
sent: function sent() {
if (t[0] & 1) throw t[1];
return t[1];
},
trys: [],
ops: []
},
f,
y,
t,
g;
return g = {
next: verb(0),
"throw": verb(1),
"return": verb(2)
}, typeof _symbol.default === "function" && (g[_iterator.default] = function () {
return this;
}), g;
function verb(n) {
return function (v) {
return step([n, v]);
};
}
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) {
try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0:
case 1:
t = op;
break;
case 4:
_.label++;
return {
value: op[1],
done: false
};
case 5:
_.label++;
y = op[1];
op = [0];
continue;
case 7:
op = _.ops.pop();
_.trys.pop();
continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
_ = 0;
continue;
}
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
_.label = op[1];
break;
}
if (op[0] === 6 && _.label < t[1]) {
_.label = t[1];
t = op;
break;
}
if (t && _.label < t[2]) {
_.label = t[2];
_.ops.push(op);
break;
}
if (t[2]) _.ops.pop();
_.trys.pop();
continue;
}
op = body.call(thisArg, _);
} catch (e) {
op = [6, e];
y = 0;
} finally {
f = t = 0;
}
}
if (op[0] & 5) throw op[1];
return {
value: op[0] ? op[1] : void 0,
done: true
};
}
}
var PROVIDER = "lc_weapp";
var PLATFORM = "weixin";
function getLoginCode() {
return new _promise.default(function (resolve, reject) {
wx.login({
success: function success(res) {
return res.code ? resolve(res.code) : reject(new Error(res.errMsg));
},
fail: function fail(_a) {
var errMsg = _a.errMsg;
return reject(new Error(errMsg));
}
});
});
}
var getAuthInfo = function getAuthInfo(_a) {
var _b = _a === void 0 ? {} : _a,
_c = _b.platform,
platform = _c === void 0 ? PLATFORM : _c,
_d = _b.preferUnionId,
preferUnionId = _d === void 0 ? false : _d,
_e = _b.asMainAccount,
asMainAccount = _e === void 0 ? false : _e;
return __awaiter(this, void 0, void 0, function () {
var code, authData;
return __generator(this, function (_f) {
switch (_f.label) {
case 0:
return [4
/*yield*/
, getLoginCode()];
case 1:
code = _f.sent();
authData = {
code: code
};
if (preferUnionId) {
authData.platform = platform;
authData.main_account = asMainAccount;
}
return [2
/*return*/
, {
authData: authData,
platform: platform,
provider: PROVIDER
}];
}
});
});
};
var storage = {
getItem: function getItem(key) {
return wx.getStorageSync(key);
},
setItem: function setItem(key, value) {
return wx.setStorageSync(key, value);
},
removeItem: function removeItem(key) {
return wx.removeStorageSync(key);
},
clear: function clear() {
return wx.clearStorageSync();
}
};
/******************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise */
var _extendStatics = function extendStatics(d, b) {
_extendStatics = _setPrototypeOf.default || {
__proto__: []
} instanceof Array && function (d, b) {
d.__proto__ = b;
} || function (d, b) {
for (var p in b) {
if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
}
};
return _extendStatics(d, b);
};
function __extends(d, b) {
if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
_extendStatics(d, b);
function __() {
this.constructor = d;
}
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var AbortError =
/** @class */
function (_super) {
__extends(AbortError, _super);
function AbortError() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.name = "AbortError";
return _this;
}
return AbortError;
}(Error);
var request = function request(url, options) {
if (options === void 0) {
options = {};
}
var method = options.method,
data = options.data,
headers = options.headers,
signal = options.signal;
if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
return _promise.default.reject(new AbortError("Request aborted"));
}
return new _promise.default(function (resolve, reject) {
var task = wx.request({
url: url,
method: method,
data: data,
header: headers,
complete: function complete(res) {
signal === null || signal === void 0 ? void 0 : signal.removeEventListener("abort", abortListener);
if (!res.statusCode) {
reject(new Error(res.errMsg));
return;
}
resolve({
ok: !(res.statusCode >= 400),
status: res.statusCode,
headers: res.header,
data: res.data
});
}
});
var abortListener = function abortListener() {
reject(new AbortError("Request aborted"));
task.abort();
};
signal === null || signal === void 0 ? void 0 : signal.addEventListener("abort", abortListener);
});
};
var upload = function upload(url, file, options) {
if (options === void 0) {
options = {};
}
var headers = options.headers,
data = options.data,
onprogress = options.onprogress,
signal = options.signal;
if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
return _promise.default.reject(new AbortError("Request aborted"));
}
if (!(file && file.data && file.data.uri)) {
return _promise.default.reject(new TypeError("File data must be an object like { uri: localPath }."));
}
return new _promise.default(function (resolve, reject) {
var task = wx.uploadFile({
url: url,
header: headers,
filePath: file.data.uri,
name: file.field,
formData: data,
success: function success(response) {
var status = response.statusCode,
data = response.data,
rest = __rest(response, ["statusCode", "data"]);
resolve(_assign(_assign({}, rest), {
data: typeof data === "string" ? JSON.parse(data) : data,
status: status,
ok: !(status >= 400)
}));
},
fail: function fail(response) {
reject(new Error(response.errMsg));
},
complete: function complete() {
signal === null || signal === void 0 ? void 0 : signal.removeEventListener("abort", abortListener);
}
});
var abortListener = function abortListener() {
reject(new AbortError("Request aborted"));
task.abort();
};
signal === null || signal === void 0 ? void 0 : signal.addEventListener("abort", abortListener);
if (onprogress) {
task.onProgressUpdate(function (event) {
return onprogress({
loaded: event.totalBytesSent,
total: event.totalBytesExpectedToSend,
percent: event.progress
});
});
}
});
};
/**
* @author Toru Nagashima
* @copyright 2015 Toru Nagashima. All rights reserved.
* See LICENSE file in root directory for full license.
*/
/**
* @typedef {object} PrivateData
* @property {EventTarget} eventTarget The event target.
* @property {{type:string}} event The original event object.
* @property {number} eventPhase The current event phase.
* @property {EventTarget|null} currentTarget The current event target.
* @property {boolean} canceled The flag to prevent default.
* @property {boolean} stopped The flag to stop propagation.
* @property {boolean} immediateStopped The flag to stop propagation immediately.
* @property {Function|null} passiveListener The listener if the current listener is passive. Otherwise this is null.
* @property {number} timeStamp The unix time.
* @private
*/
/**
* Private data for event wrappers.
* @type {WeakMap}
* @private
*/
var privateData = new _weakMap.default();
/**
* Cache for wrapper classes.
* @type {WeakMap