ParseQuery.js 106 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
  3. var _sliceInstanceProperty2 = require("@babel/runtime-corejs3/core-js-stable/instance/slice");
  4. var _reverseInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/reverse");
  5. var _Promise2 = require("@babel/runtime-corejs3/core-js-stable/promise");
  6. var _Object$setPrototypeOf = require("@babel/runtime-corejs3/core-js-stable/object/set-prototype-of");
  7. var _typeof3 = require("@babel/runtime-corejs3/helpers/typeof");
  8. var _forEachInstanceProperty2 = require("@babel/runtime-corejs3/core-js-stable/instance/for-each");
  9. var _Object$getPrototypeOf = require("@babel/runtime-corejs3/core-js-stable/object/get-prototype-of");
  10. var _Object$create = require("@babel/runtime-corejs3/core-js-stable/object/create");
  11. var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
  12. var _Symbol = require("@babel/runtime-corejs3/core-js-stable/symbol");
  13. _Object$defineProperty(exports, "__esModule", {
  14. value: true
  15. });
  16. exports.default = void 0;
  17. var _entries = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/entries"));
  18. var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
  19. var _isArray = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/is-array"));
  20. var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/toConsumableArray"));
  21. var _find = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/find"));
  22. var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
  23. var _splice = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/splice"));
  24. var _sort = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/sort"));
  25. var _includes = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/includes"));
  26. var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
  27. var _keys = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/keys"));
  28. var _filter2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));
  29. var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/asyncToGenerator"));
  30. var _map2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
  31. var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/classCallCheck"));
  32. var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/createClass"));
  33. var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
  34. var _slice = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/slice"));
  35. var _keys2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/keys"));
  36. var _typeof2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/typeof"));
  37. var _indexOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/index-of"));
  38. var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));
  39. var _CoreManager = _interopRequireDefault(require("./CoreManager"));
  40. var _encode = _interopRequireDefault(require("./encode"));
  41. var _promiseUtils = require("./promiseUtils");
  42. var _ParseError = _interopRequireDefault(require("./ParseError"));
  43. var _ParseGeoPoint = _interopRequireDefault(require("./ParseGeoPoint"));
  44. var _ParseObject = _interopRequireDefault(require("./ParseObject"));
  45. var _OfflineQuery = _interopRequireDefault(require("./OfflineQuery"));
  46. var _LocalDatastoreUtils = require("./LocalDatastoreUtils");
  47. function _regeneratorRuntime() {
  48. "use strict";
  49. /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
  50. _regeneratorRuntime = function () {
  51. return exports;
  52. };
  53. var exports = {},
  54. Op = Object.prototype,
  55. hasOwn = Op.hasOwnProperty,
  56. $Symbol = "function" == typeof _Symbol ? _Symbol : {},
  57. iteratorSymbol = $Symbol.iterator || "@@iterator",
  58. asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
  59. toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
  60. function define(obj, key, value) {
  61. return _Object$defineProperty(obj, key, {
  62. value: value,
  63. enumerable: !0,
  64. configurable: !0,
  65. writable: !0
  66. }), obj[key];
  67. }
  68. try {
  69. define({}, "");
  70. } catch (err) {
  71. define = function (obj, key, value) {
  72. return obj[key] = value;
  73. };
  74. }
  75. function wrap(innerFn, outerFn, self, tryLocsList) {
  76. var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
  77. generator = _Object$create(protoGenerator.prototype),
  78. context = new Context(tryLocsList || []);
  79. return generator._invoke = function (innerFn, self, context) {
  80. var state = "suspendedStart";
  81. return function (method, arg) {
  82. if ("executing" === state) throw new Error("Generator is already running");
  83. if ("completed" === state) {
  84. if ("throw" === method) throw arg;
  85. return doneResult();
  86. }
  87. for (context.method = method, context.arg = arg;;) {
  88. var delegate = context.delegate;
  89. if (delegate) {
  90. var delegateResult = maybeInvokeDelegate(delegate, context);
  91. if (delegateResult) {
  92. if (delegateResult === ContinueSentinel) continue;
  93. return delegateResult;
  94. }
  95. }
  96. if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
  97. if ("suspendedStart" === state) throw state = "completed", context.arg;
  98. context.dispatchException(context.arg);
  99. } else "return" === context.method && context.abrupt("return", context.arg);
  100. state = "executing";
  101. var record = tryCatch(innerFn, self, context);
  102. if ("normal" === record.type) {
  103. if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
  104. return {
  105. value: record.arg,
  106. done: context.done
  107. };
  108. }
  109. "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
  110. }
  111. };
  112. }(innerFn, self, context), generator;
  113. }
  114. function tryCatch(fn, obj, arg) {
  115. try {
  116. return {
  117. type: "normal",
  118. arg: fn.call(obj, arg)
  119. };
  120. } catch (err) {
  121. return {
  122. type: "throw",
  123. arg: err
  124. };
  125. }
  126. }
  127. exports.wrap = wrap;
  128. var ContinueSentinel = {};
  129. function Generator() {}
  130. function GeneratorFunction() {}
  131. function GeneratorFunctionPrototype() {}
  132. var IteratorPrototype = {};
  133. define(IteratorPrototype, iteratorSymbol, function () {
  134. return this;
  135. });
  136. var getProto = _Object$getPrototypeOf,
  137. NativeIteratorPrototype = getProto && getProto(getProto(values([])));
  138. NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
  139. var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = _Object$create(IteratorPrototype);
  140. function defineIteratorMethods(prototype) {
  141. var _context23;
  142. _forEachInstanceProperty2(_context23 = ["next", "throw", "return"]).call(_context23, function (method) {
  143. define(prototype, method, function (arg) {
  144. return this._invoke(method, arg);
  145. });
  146. });
  147. }
  148. function AsyncIterator(generator, PromiseImpl) {
  149. function invoke(method, arg, resolve, reject) {
  150. var record = tryCatch(generator[method], generator, arg);
  151. if ("throw" !== record.type) {
  152. var result = record.arg,
  153. value = result.value;
  154. return value && "object" == _typeof3(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
  155. invoke("next", value, resolve, reject);
  156. }, function (err) {
  157. invoke("throw", err, resolve, reject);
  158. }) : PromiseImpl.resolve(value).then(function (unwrapped) {
  159. result.value = unwrapped, resolve(result);
  160. }, function (error) {
  161. return invoke("throw", error, resolve, reject);
  162. });
  163. }
  164. reject(record.arg);
  165. }
  166. var previousPromise;
  167. this._invoke = function (method, arg) {
  168. function callInvokeWithMethodAndArg() {
  169. return new PromiseImpl(function (resolve, reject) {
  170. invoke(method, arg, resolve, reject);
  171. });
  172. }
  173. return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
  174. };
  175. }
  176. function maybeInvokeDelegate(delegate, context) {
  177. var method = delegate.iterator[context.method];
  178. if (undefined === method) {
  179. if (context.delegate = null, "throw" === context.method) {
  180. if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel;
  181. context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method");
  182. }
  183. return ContinueSentinel;
  184. }
  185. var record = tryCatch(method, delegate.iterator, context.arg);
  186. if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
  187. var info = record.arg;
  188. return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
  189. }
  190. function pushTryEntry(locs) {
  191. var entry = {
  192. tryLoc: locs[0]
  193. };
  194. 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
  195. }
  196. function resetTryEntry(entry) {
  197. var record = entry.completion || {};
  198. record.type = "normal", delete record.arg, entry.completion = record;
  199. }
  200. function Context(tryLocsList) {
  201. this.tryEntries = [{
  202. tryLoc: "root"
  203. }], _forEachInstanceProperty2(tryLocsList).call(tryLocsList, pushTryEntry, this), this.reset(!0);
  204. }
  205. function values(iterable) {
  206. if (iterable) {
  207. var iteratorMethod = iterable[iteratorSymbol];
  208. if (iteratorMethod) return iteratorMethod.call(iterable);
  209. if ("function" == typeof iterable.next) return iterable;
  210. if (!isNaN(iterable.length)) {
  211. var i = -1,
  212. next = function next() {
  213. for (; ++i < iterable.length;) {
  214. if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
  215. }
  216. return next.value = undefined, next.done = !0, next;
  217. };
  218. return next.next = next;
  219. }
  220. }
  221. return {
  222. next: doneResult
  223. };
  224. }
  225. function doneResult() {
  226. return {
  227. value: undefined,
  228. done: !0
  229. };
  230. }
  231. return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
  232. var ctor = "function" == typeof genFun && genFun.constructor;
  233. return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
  234. }, exports.mark = function (genFun) {
  235. return _Object$setPrototypeOf ? _Object$setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = _Object$create(Gp), genFun;
  236. }, exports.awrap = function (arg) {
  237. return {
  238. __await: arg
  239. };
  240. }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
  241. return this;
  242. }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
  243. void 0 === PromiseImpl && (PromiseImpl = _Promise2);
  244. var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
  245. return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
  246. return result.done ? result.value : iter.next();
  247. });
  248. }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
  249. return this;
  250. }), define(Gp, "toString", function () {
  251. return "[object Generator]";
  252. }), exports.keys = function (object) {
  253. var keys = [];
  254. for (var key in object) {
  255. keys.push(key);
  256. }
  257. return _reverseInstanceProperty(keys).call(keys), function next() {
  258. for (; keys.length;) {
  259. var key = keys.pop();
  260. if (key in object) return next.value = key, next.done = !1, next;
  261. }
  262. return next.done = !0, next;
  263. };
  264. }, exports.values = values, Context.prototype = {
  265. constructor: Context,
  266. reset: function (skipTempReset) {
  267. var _context24;
  268. if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, _forEachInstanceProperty2(_context24 = this.tryEntries).call(_context24, resetTryEntry), !skipTempReset) for (var name in this) {
  269. "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+_sliceInstanceProperty2(name).call(name, 1)) && (this[name] = undefined);
  270. }
  271. },
  272. stop: function () {
  273. this.done = !0;
  274. var rootRecord = this.tryEntries[0].completion;
  275. if ("throw" === rootRecord.type) throw rootRecord.arg;
  276. return this.rval;
  277. },
  278. dispatchException: function (exception) {
  279. if (this.done) throw exception;
  280. var context = this;
  281. function handle(loc, caught) {
  282. return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
  283. }
  284. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  285. var entry = this.tryEntries[i],
  286. record = entry.completion;
  287. if ("root" === entry.tryLoc) return handle("end");
  288. if (entry.tryLoc <= this.prev) {
  289. var hasCatch = hasOwn.call(entry, "catchLoc"),
  290. hasFinally = hasOwn.call(entry, "finallyLoc");
  291. if (hasCatch && hasFinally) {
  292. if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
  293. if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
  294. } else if (hasCatch) {
  295. if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
  296. } else {
  297. if (!hasFinally) throw new Error("try statement without catch or finally");
  298. if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
  299. }
  300. }
  301. }
  302. },
  303. abrupt: function (type, arg) {
  304. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  305. var entry = this.tryEntries[i];
  306. if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
  307. var finallyEntry = entry;
  308. break;
  309. }
  310. }
  311. finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
  312. var record = finallyEntry ? finallyEntry.completion : {};
  313. return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
  314. },
  315. complete: function (record, afterLoc) {
  316. if ("throw" === record.type) throw record.arg;
  317. return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
  318. },
  319. finish: function (finallyLoc) {
  320. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  321. var entry = this.tryEntries[i];
  322. if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
  323. }
  324. },
  325. catch: function (tryLoc) {
  326. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  327. var entry = this.tryEntries[i];
  328. if (entry.tryLoc === tryLoc) {
  329. var record = entry.completion;
  330. if ("throw" === record.type) {
  331. var thrown = record.arg;
  332. resetTryEntry(entry);
  333. }
  334. return thrown;
  335. }
  336. }
  337. throw new Error("illegal catch attempt");
  338. },
  339. delegateYield: function (iterable, resultName, nextLoc) {
  340. return this.delegate = {
  341. iterator: values(iterable),
  342. resultName: resultName,
  343. nextLoc: nextLoc
  344. }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
  345. }
  346. }, exports;
  347. }
  348. /**
  349. * Converts a string into a regex that matches it.
  350. * Surrounding with \Q .. \E does this, we just need to escape any \E's in
  351. * the text separately.
  352. *
  353. * @param s
  354. * @private
  355. * @returns {string}
  356. */
  357. function quote(s
  358. /*: string*/
  359. )
  360. /*: string*/
  361. {
  362. return '\\Q' + s.replace('\\E', '\\E\\\\E\\Q') + '\\E';
  363. }
  364. /**
  365. * Extracts the class name from queries. If not all queries have the same
  366. * class name an error will be thrown.
  367. *
  368. * @param queries
  369. * @private
  370. * @returns {string}
  371. */
  372. function _getClassNameFromQueries(queries
  373. /*: Array<ParseQuery>*/
  374. )
  375. /*: ?string*/
  376. {
  377. var className = null;
  378. (0, _forEach.default)(queries).call(queries, function (q) {
  379. if (!className) {
  380. className = q.className;
  381. }
  382. if (className !== q.className) {
  383. throw new Error('All queries must be for the same class.');
  384. }
  385. });
  386. return className;
  387. }
  388. /*
  389. * Handles pre-populating the result data of a query with select fields,
  390. * making sure that the data object contains keys for all objects that have
  391. * been requested with a select, so that our cached state updates correctly.
  392. */
  393. function handleSelectResult(data
  394. /*: any*/
  395. , select
  396. /*: Array<string>*/
  397. ) {
  398. var serverDataMask = {};
  399. (0, _forEach.default)(select).call(select, function (field) {
  400. var hasSubObjectSelect = (0, _indexOf.default)(field).call(field, '.') !== -1;
  401. if (!hasSubObjectSelect && !data.hasOwnProperty(field)) {
  402. // this field was selected, but is missing from the retrieved data
  403. data[field] = undefined;
  404. } else if (hasSubObjectSelect) {
  405. // this field references a sub-object,
  406. // so we need to walk down the path components
  407. var pathComponents = field.split('.');
  408. var _obj = data;
  409. var serverMask = serverDataMask;
  410. (0, _forEach.default)(pathComponents).call(pathComponents, function (component, index, arr) {
  411. // add keys if the expected data is missing
  412. if (_obj && !_obj.hasOwnProperty(component)) {
  413. _obj[component] = undefined;
  414. }
  415. if (_obj && (0, _typeof2.default)(_obj) === 'object') {
  416. _obj = _obj[component];
  417. } //add this path component to the server mask so we can fill it in later if needed
  418. if (index < arr.length - 1) {
  419. if (!serverMask[component]) {
  420. serverMask[component] = {};
  421. }
  422. serverMask = serverMask[component];
  423. }
  424. });
  425. }
  426. });
  427. if ((0, _keys2.default)(serverDataMask).length > 0) {
  428. // When selecting from sub-objects, we don't want to blow away the missing
  429. // information that we may have retrieved before. We've already added any
  430. // missing selected keys to sub-objects, but we still need to add in the
  431. // data for any previously retrieved sub-objects that were not selected.
  432. var serverData = _CoreManager.default.getObjectStateController().getServerData({
  433. id: data.objectId,
  434. className: data.className
  435. });
  436. copyMissingDataWithMask(serverData, data, serverDataMask, false);
  437. }
  438. }
  439. function copyMissingDataWithMask(src, dest, mask, copyThisLevel) {
  440. //copy missing elements at this level
  441. if (copyThisLevel) {
  442. for (var _key in src) {
  443. if (src.hasOwnProperty(_key) && !dest.hasOwnProperty(_key)) {
  444. dest[_key] = src[_key];
  445. }
  446. }
  447. }
  448. for (var _key2 in mask) {
  449. if (dest[_key2] !== undefined && dest[_key2] !== null && src !== undefined && src !== null) {
  450. //traverse into objects as needed
  451. copyMissingDataWithMask(src[_key2], dest[_key2], mask[_key2], true);
  452. }
  453. }
  454. }
  455. function handleOfflineSort(a, b, sorts) {
  456. var order = sorts[0];
  457. var operator = (0, _slice.default)(order).call(order, 0, 1);
  458. var isDescending = operator === '-';
  459. if (isDescending) {
  460. order = order.substring(1);
  461. }
  462. if (order === '_created_at') {
  463. order = 'createdAt';
  464. }
  465. if (order === '_updated_at') {
  466. order = 'updatedAt';
  467. }
  468. if (!/^[A-Za-z][0-9A-Za-z_]*$/.test(order) || order === 'password') {
  469. throw new _ParseError.default(_ParseError.default.INVALID_KEY_NAME, "Invalid Key: ".concat(order));
  470. }
  471. var field1 = a.get(order);
  472. var field2 = b.get(order);
  473. if (field1 < field2) {
  474. return isDescending ? 1 : -1;
  475. }
  476. if (field1 > field2) {
  477. return isDescending ? -1 : 1;
  478. }
  479. if (sorts.length > 1) {
  480. var remainingSorts = (0, _slice.default)(sorts).call(sorts, 1);
  481. return handleOfflineSort(a, b, remainingSorts);
  482. }
  483. return 0;
  484. }
  485. /**
  486. * Creates a new parse Parse.Query for the given Parse.Object subclass.
  487. *
  488. * <p>Parse.Query defines a query that is used to fetch Parse.Objects. The
  489. * most common use case is finding all objects that match a query through the
  490. * <code>find</code> method. for example, this sample code fetches all objects
  491. * of class <code>myclass</code>. it calls a different function depending on
  492. * whether the fetch succeeded or not.
  493. *
  494. * <pre>
  495. * var query = new Parse.Query(myclass);
  496. * query.find().then((results) => {
  497. * // results is an array of parse.object.
  498. * }).catch((error) => {
  499. * // error is an instance of parse.error.
  500. * });</pre></p>
  501. *
  502. * <p>a Parse.Query can also be used to retrieve a single object whose id is
  503. * known, through the get method. for example, this sample code fetches an
  504. * object of class <code>myclass</code> and id <code>myid</code>. it calls a
  505. * different function depending on whether the fetch succeeded or not.
  506. *
  507. * <pre>
  508. * var query = new Parse.Query(myclass);
  509. * query.get(myid).then((object) => {
  510. * // object is an instance of parse.object.
  511. * }).catch((error) => {
  512. * // error is an instance of parse.error.
  513. * });</pre></p>
  514. *
  515. * <p>a Parse.Query can also be used to count the number of objects that match
  516. * the query without retrieving all of those objects. for example, this
  517. * sample code counts the number of objects of the class <code>myclass</code>
  518. * <pre>
  519. * var query = new Parse.Query(myclass);
  520. * query.count().then((number) => {
  521. * // there are number instances of myclass.
  522. * }).catch((error) => {
  523. * // error is an instance of Parse.Error.
  524. * });</pre></p>
  525. *
  526. * @alias Parse.Query
  527. */
  528. var ParseQuery = /*#__PURE__*/function () {
  529. /**
  530. * @property {string} className
  531. */
  532. /**
  533. * @param {(string | Parse.Object)} objectClass An instance of a subclass of Parse.Object, or a Parse className string.
  534. */
  535. function ParseQuery(objectClass
  536. /*: string | ParseObject*/
  537. ) {
  538. (0, _classCallCheck2.default)(this, ParseQuery);
  539. (0, _defineProperty2.default)(this, "className", void 0);
  540. (0, _defineProperty2.default)(this, "_where", void 0);
  541. (0, _defineProperty2.default)(this, "_include", void 0);
  542. (0, _defineProperty2.default)(this, "_exclude", void 0);
  543. (0, _defineProperty2.default)(this, "_select", void 0);
  544. (0, _defineProperty2.default)(this, "_limit", void 0);
  545. (0, _defineProperty2.default)(this, "_skip", void 0);
  546. (0, _defineProperty2.default)(this, "_count", void 0);
  547. (0, _defineProperty2.default)(this, "_order", void 0);
  548. (0, _defineProperty2.default)(this, "_readPreference", void 0);
  549. (0, _defineProperty2.default)(this, "_includeReadPreference", void 0);
  550. (0, _defineProperty2.default)(this, "_subqueryReadPreference", void 0);
  551. (0, _defineProperty2.default)(this, "_queriesLocalDatastore", void 0);
  552. (0, _defineProperty2.default)(this, "_localDatastorePinName", void 0);
  553. (0, _defineProperty2.default)(this, "_extraOptions", void 0);
  554. (0, _defineProperty2.default)(this, "_hint", void 0);
  555. (0, _defineProperty2.default)(this, "_explain", void 0);
  556. (0, _defineProperty2.default)(this, "_xhrRequest", void 0);
  557. if (typeof objectClass === 'string') {
  558. if (objectClass === 'User' && _CoreManager.default.get('PERFORM_USER_REWRITE')) {
  559. this.className = '_User';
  560. } else {
  561. this.className = objectClass;
  562. }
  563. } else if (objectClass instanceof _ParseObject.default) {
  564. this.className = objectClass.className;
  565. } else if (typeof objectClass === 'function') {
  566. if (typeof objectClass.className === 'string') {
  567. this.className = objectClass.className;
  568. } else {
  569. var _obj2 = new objectClass();
  570. this.className = _obj2.className;
  571. }
  572. } else {
  573. throw new TypeError('A ParseQuery must be constructed with a ParseObject or class name.');
  574. }
  575. this._where = {};
  576. this._include = [];
  577. this._exclude = [];
  578. this._count = false;
  579. this._limit = -1; // negative limit is not sent in the server request
  580. this._skip = 0;
  581. this._readPreference = null;
  582. this._includeReadPreference = null;
  583. this._subqueryReadPreference = null;
  584. this._queriesLocalDatastore = false;
  585. this._localDatastorePinName = null;
  586. this._extraOptions = {};
  587. this._xhrRequest = {
  588. task: null,
  589. onchange: function () {}
  590. };
  591. }
  592. /**
  593. * Adds constraint that at least one of the passed in queries matches.
  594. *
  595. * @param {Array} queries
  596. * @returns {Parse.Query} Returns the query, so you can chain this call.
  597. */
  598. (0, _createClass2.default)(ParseQuery, [{
  599. key: "_orQuery",
  600. value: function (queries
  601. /*: Array<ParseQuery>*/
  602. )
  603. /*: ParseQuery*/
  604. {
  605. var queryJSON = (0, _map2.default)(queries).call(queries, function (q) {
  606. return q.toJSON().where;
  607. });
  608. this._where.$or = queryJSON;
  609. return this;
  610. }
  611. /**
  612. * Adds constraint that all of the passed in queries match.
  613. *
  614. * @param {Array} queries
  615. * @returns {Parse.Query} Returns the query, so you can chain this call.
  616. */
  617. }, {
  618. key: "_andQuery",
  619. value: function (queries
  620. /*: Array<ParseQuery>*/
  621. )
  622. /*: ParseQuery*/
  623. {
  624. var queryJSON = (0, _map2.default)(queries).call(queries, function (q) {
  625. return q.toJSON().where;
  626. });
  627. this._where.$and = queryJSON;
  628. return this;
  629. }
  630. /**
  631. * Adds constraint that none of the passed in queries match.
  632. *
  633. * @param {Array} queries
  634. * @returns {Parse.Query} Returns the query, so you can chain this call.
  635. */
  636. }, {
  637. key: "_norQuery",
  638. value: function (queries
  639. /*: Array<ParseQuery>*/
  640. )
  641. /*: ParseQuery*/
  642. {
  643. var queryJSON = (0, _map2.default)(queries).call(queries, function (q) {
  644. return q.toJSON().where;
  645. });
  646. this._where.$nor = queryJSON;
  647. return this;
  648. }
  649. /**
  650. * Helper for condition queries
  651. *
  652. * @param key
  653. * @param condition
  654. * @param value
  655. * @returns {Parse.Query}
  656. */
  657. }, {
  658. key: "_addCondition",
  659. value: function (key
  660. /*: string*/
  661. , condition
  662. /*: string*/
  663. , value
  664. /*: mixed*/
  665. )
  666. /*: ParseQuery*/
  667. {
  668. if (!this._where[key] || typeof this._where[key] === 'string') {
  669. this._where[key] = {};
  670. }
  671. this._where[key][condition] = (0, _encode.default)(value, false, true);
  672. return this;
  673. }
  674. /**
  675. * Converts string for regular expression at the beginning
  676. *
  677. * @param string
  678. * @returns {string}
  679. */
  680. }, {
  681. key: "_regexStartWith",
  682. value: function (string
  683. /*: string*/
  684. )
  685. /*: string*/
  686. {
  687. return '^' + quote(string);
  688. }
  689. }, {
  690. key: "_handleOfflineQuery",
  691. value: function () {
  692. var _handleOfflineQuery2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params
  693. /*: any*/
  694. ) {
  695. var _context,
  696. _this2 = this;
  697. var localDatastore, objects, results, keys, alwaysSelectedKeys, sorts, count, limit;
  698. return _regeneratorRuntime().wrap(function (_context3) {
  699. while (1) {
  700. switch (_context3.prev = _context3.next) {
  701. case 0:
  702. _OfflineQuery.default.validateQuery(this);
  703. localDatastore = _CoreManager.default.getLocalDatastore();
  704. _context3.next = 4;
  705. return localDatastore._serializeObjectsFromPinName(this._localDatastorePinName);
  706. case 4:
  707. objects = _context3.sent;
  708. results = (0, _filter2.default)(_context = (0, _map2.default)(objects).call(objects, function (json, index, arr) {
  709. var object = _ParseObject.default.fromJSON(json, false);
  710. if (json._localId && !json.objectId) {
  711. object._localId = json._localId;
  712. }
  713. if (!_OfflineQuery.default.matchesQuery(_this2.className, object, arr, _this2)) {
  714. return null;
  715. }
  716. return object;
  717. })).call(_context, function (object) {
  718. return object !== null;
  719. });
  720. if ((0, _keys.default)(params)) {
  721. keys = (0, _keys.default)(params).split(',');
  722. alwaysSelectedKeys = ['className', 'objectId', 'createdAt', 'updatedAt', 'ACL'];
  723. keys = (0, _concat.default)(keys).call(keys, alwaysSelectedKeys);
  724. results = (0, _map2.default)(results).call(results, function (object) {
  725. var _context2;
  726. var json = object._toFullJSON();
  727. (0, _forEach.default)(_context2 = (0, _keys2.default)(json)).call(_context2, function (key) {
  728. if (!(0, _includes.default)(keys).call(keys, key)) {
  729. delete json[key];
  730. }
  731. });
  732. return _ParseObject.default.fromJSON(json, false);
  733. });
  734. }
  735. if (params.order) {
  736. sorts = params.order.split(',');
  737. (0, _sort.default)(results).call(results, function (a, b) {
  738. return handleOfflineSort(a, b, sorts);
  739. });
  740. } // count total before applying limit/skip
  741. if (params.count) {
  742. count = results.length; // total count from response
  743. }
  744. if (params.skip) {
  745. if (params.skip >= results.length) {
  746. results = [];
  747. } else {
  748. results = (0, _splice.default)(results).call(results, params.skip, results.length);
  749. }
  750. }
  751. limit = results.length;
  752. if (params.limit !== 0 && params.limit < results.length) {
  753. limit = params.limit;
  754. }
  755. results = (0, _splice.default)(results).call(results, 0, limit);
  756. if (!(typeof count === 'number')) {
  757. _context3.next = 15;
  758. break;
  759. }
  760. return _context3.abrupt("return", {
  761. results: results,
  762. count: count
  763. });
  764. case 15:
  765. return _context3.abrupt("return", results);
  766. case 16:
  767. case "end":
  768. return _context3.stop();
  769. }
  770. }
  771. }, _callee, this);
  772. }));
  773. function _handleOfflineQuery() {
  774. return _handleOfflineQuery2.apply(this, arguments);
  775. }
  776. return _handleOfflineQuery;
  777. }()
  778. /**
  779. * Returns a JSON representation of this query.
  780. *
  781. * @returns {object} The JSON representation of the query.
  782. */
  783. }, {
  784. key: "toJSON",
  785. value: function ()
  786. /*: QueryJSON*/
  787. {
  788. var params
  789. /*: QueryJSON*/
  790. = {
  791. where: this._where
  792. };
  793. if (this._include.length) {
  794. params.include = this._include.join(',');
  795. }
  796. if (this._exclude.length) {
  797. params.excludeKeys = this._exclude.join(',');
  798. }
  799. if (this._select) {
  800. params.keys = this._select.join(',');
  801. }
  802. if (this._count) {
  803. params.count = 1;
  804. }
  805. if (this._limit >= 0) {
  806. params.limit = this._limit;
  807. }
  808. if (this._skip > 0) {
  809. params.skip = this._skip;
  810. }
  811. if (this._order) {
  812. params.order = this._order.join(',');
  813. }
  814. if (this._readPreference) {
  815. params.readPreference = this._readPreference;
  816. }
  817. if (this._includeReadPreference) {
  818. params.includeReadPreference = this._includeReadPreference;
  819. }
  820. if (this._subqueryReadPreference) {
  821. params.subqueryReadPreference = this._subqueryReadPreference;
  822. }
  823. if (this._hint) {
  824. params.hint = this._hint;
  825. }
  826. if (this._explain) {
  827. params.explain = true;
  828. }
  829. for (var _key3 in this._extraOptions) {
  830. params[_key3] = this._extraOptions[_key3];
  831. }
  832. return params;
  833. }
  834. /**
  835. * Return a query with conditions from json, can be useful to send query from server side to client
  836. * Not static, all query conditions was set before calling this method will be deleted.
  837. * For example on the server side we have
  838. * var query = new Parse.Query("className");
  839. * query.equalTo(key: value);
  840. * query.limit(100);
  841. * ... (others queries)
  842. * Create JSON representation of Query Object
  843. * var jsonFromServer = query.fromJSON();
  844. *
  845. * On client side getting query:
  846. * var query = new Parse.Query("className");
  847. * query.fromJSON(jsonFromServer);
  848. *
  849. * and continue to query...
  850. * query.skip(100).find().then(...);
  851. *
  852. * @param {QueryJSON} json from Parse.Query.toJSON() method
  853. * @returns {Parse.Query} Returns the query, so you can chain this call.
  854. */
  855. }, {
  856. key: "withJSON",
  857. value: function (json
  858. /*: QueryJSON*/
  859. )
  860. /*: ParseQuery*/
  861. {
  862. if (json.where) {
  863. this._where = json.where;
  864. }
  865. if (json.include) {
  866. this._include = json.include.split(',');
  867. }
  868. if ((0, _keys.default)(json)) {
  869. this._select = (0, _keys.default)(json).split(',');
  870. }
  871. if (json.excludeKeys) {
  872. this._exclude = json.excludeKeys.split(',');
  873. }
  874. if (json.count) {
  875. this._count = json.count === 1;
  876. }
  877. if (json.limit) {
  878. this._limit = json.limit;
  879. }
  880. if (json.skip) {
  881. this._skip = json.skip;
  882. }
  883. if (json.order) {
  884. this._order = json.order.split(',');
  885. }
  886. if (json.readPreference) {
  887. this._readPreference = json.readPreference;
  888. }
  889. if (json.includeReadPreference) {
  890. this._includeReadPreference = json.includeReadPreference;
  891. }
  892. if (json.subqueryReadPreference) {
  893. this._subqueryReadPreference = json.subqueryReadPreference;
  894. }
  895. if (json.hint) {
  896. this._hint = json.hint;
  897. }
  898. if (json.explain) {
  899. this._explain = !!json.explain;
  900. }
  901. for (var _key4 in json) {
  902. if (json.hasOwnProperty(_key4)) {
  903. var _context4;
  904. if ((0, _indexOf.default)(_context4 = ['where', 'include', 'keys', 'count', 'limit', 'skip', 'order', 'readPreference', 'includeReadPreference', 'subqueryReadPreference', 'hint', 'explain']).call(_context4, _key4) === -1) {
  905. this._extraOptions[_key4] = json[_key4];
  906. }
  907. }
  908. }
  909. return this;
  910. }
  911. /**
  912. * Static method to restore Parse.Query by json representation
  913. * Internally calling Parse.Query.withJSON
  914. *
  915. * @param {string} className
  916. * @param {QueryJSON} json from Parse.Query.toJSON() method
  917. * @returns {Parse.Query} new created query
  918. */
  919. }, {
  920. key: "get",
  921. value:
  922. /**
  923. * Constructs a Parse.Object whose id is already known by fetching data from
  924. * the server. Unlike the <code>first</code> method, it never returns undefined.
  925. *
  926. * @param {string} objectId The id of the object to be fetched.
  927. * @param {object} options
  928. * Valid options are:<ul>
  929. * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
  930. * be used for this request.
  931. * <li>sessionToken: A valid session token, used for making a request on
  932. * behalf of a specific user.
  933. * <li>context: A dictionary that is accessible in Cloud Code `beforeFind` trigger.
  934. * <li>json: Return raw json without converting to Parse.Object
  935. * </ul>
  936. *
  937. * @returns {Promise} A promise that is resolved with the result when
  938. * the query completes.
  939. */
  940. function (objectId
  941. /*: string*/
  942. , options
  943. /*:: ?: FullOptions*/
  944. )
  945. /*: Promise<ParseObject>*/
  946. {
  947. this.equalTo('objectId', objectId);
  948. var firstOptions = {};
  949. if (options && options.hasOwnProperty('useMasterKey')) {
  950. firstOptions.useMasterKey = options.useMasterKey;
  951. }
  952. if (options && options.hasOwnProperty('sessionToken')) {
  953. firstOptions.sessionToken = options.sessionToken;
  954. }
  955. if (options && options.hasOwnProperty('context') && (0, _typeof2.default)(options.context) === 'object') {
  956. firstOptions.context = options.context;
  957. }
  958. if (options && options.hasOwnProperty('json')) {
  959. firstOptions.json = options.json;
  960. }
  961. return this.first(firstOptions).then(function (response) {
  962. if (response) {
  963. return response;
  964. }
  965. var errorObject = new _ParseError.default(_ParseError.default.OBJECT_NOT_FOUND, 'Object not found.');
  966. return _promise.default.reject(errorObject);
  967. });
  968. }
  969. /**
  970. * Retrieves a list of ParseObjects that satisfy this query.
  971. *
  972. * @param {object} options Valid options
  973. * are:<ul>
  974. * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
  975. * be used for this request.
  976. * <li>sessionToken: A valid session token, used for making a request on
  977. * behalf of a specific user.
  978. * <li>context: A dictionary that is accessible in Cloud Code `beforeFind` trigger.
  979. * <li>json: Return raw json without converting to Parse.Object
  980. * </ul>
  981. *
  982. * @returns {Promise} A promise that is resolved with the results when
  983. * the query completes.
  984. */
  985. }, {
  986. key: "find",
  987. value: function (options
  988. /*:: ?: FullOptions*/
  989. )
  990. /*: Promise<Array<ParseObject>>*/
  991. {
  992. var _this3 = this;
  993. options = options || {};
  994. var findOptions = {};
  995. if (options.hasOwnProperty('useMasterKey')) {
  996. findOptions.useMasterKey = options.useMasterKey;
  997. }
  998. if (options.hasOwnProperty('sessionToken')) {
  999. findOptions.sessionToken = options.sessionToken;
  1000. }
  1001. if (options.hasOwnProperty('context') && (0, _typeof2.default)(options.context) === 'object') {
  1002. findOptions.context = options.context;
  1003. }
  1004. this._setRequestTask(findOptions);
  1005. var controller = _CoreManager.default.getQueryController();
  1006. var select = this._select;
  1007. if (this._queriesLocalDatastore) {
  1008. return this._handleOfflineQuery(this.toJSON());
  1009. }
  1010. return (0, _find.default)(controller).call(controller, this.className, this.toJSON(), findOptions).then(function (response) {
  1011. var _context5; // Return generic object when explain is used
  1012. if (_this3._explain) {
  1013. return response.results;
  1014. }
  1015. var results = (0, _map2.default)(_context5 = response.results).call(_context5, function (data) {
  1016. // In cases of relations, the server may send back a className
  1017. // on the top level of the payload
  1018. var override = response.className || _this3.className;
  1019. if (!data.className) {
  1020. data.className = override;
  1021. } // Make sure the data object contains keys for all objects that
  1022. // have been requested with a select, so that our cached state
  1023. // updates correctly.
  1024. if (select) {
  1025. handleSelectResult(data, select);
  1026. }
  1027. if (options.json) {
  1028. return data;
  1029. } else {
  1030. return _ParseObject.default.fromJSON(data, !select);
  1031. }
  1032. });
  1033. var count = response.count;
  1034. if (typeof count === 'number') {
  1035. return {
  1036. results: results,
  1037. count: count
  1038. };
  1039. } else {
  1040. return results;
  1041. }
  1042. });
  1043. }
  1044. /**
  1045. * Retrieves a complete list of ParseObjects that satisfy this query.
  1046. * Using `eachBatch` under the hood to fetch all the valid objects.
  1047. *
  1048. * @param {object} options Valid options are:<ul>
  1049. * <li>batchSize: How many objects to yield in each batch (default: 100)
  1050. * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
  1051. * be used for this request.
  1052. * <li>sessionToken: A valid session token, used for making a request on
  1053. * behalf of a specific user.
  1054. * </ul>
  1055. * @returns {Promise} A promise that is resolved with the results when
  1056. * the query completes.
  1057. */
  1058. }, {
  1059. key: "findAll",
  1060. value: function () {
  1061. var _findAll = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options
  1062. /*:: ?: BatchOptions*/
  1063. ) {
  1064. var result;
  1065. return _regeneratorRuntime().wrap(function _callee2$(_context7) {
  1066. while (1) {
  1067. switch (_context7.prev = _context7.next) {
  1068. case 0:
  1069. result
  1070. /*: ParseObject[]*/
  1071. = [];
  1072. _context7.next = 3;
  1073. return this.eachBatch(function (objects
  1074. /*: ParseObject[]*/
  1075. ) {
  1076. var _context6;
  1077. result = (0, _concat.default)(_context6 = []).call(_context6, (0, _toConsumableArray2.default)(result), (0, _toConsumableArray2.default)(objects));
  1078. }, options);
  1079. case 3:
  1080. return _context7.abrupt("return", result);
  1081. case 4:
  1082. case "end":
  1083. return _context7.stop();
  1084. }
  1085. }
  1086. }, _callee2, this);
  1087. }));
  1088. function findAll(_x2) {
  1089. return _findAll.apply(this, arguments);
  1090. }
  1091. return findAll;
  1092. }()
  1093. /**
  1094. * Counts the number of objects that match this query.
  1095. *
  1096. * @param {object} options
  1097. * Valid options are:<ul>
  1098. * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
  1099. * be used for this request.
  1100. * <li>sessionToken: A valid session token, used for making a request on
  1101. * behalf of a specific user.
  1102. * </ul>
  1103. *
  1104. * @returns {Promise} A promise that is resolved with the count when
  1105. * the query completes.
  1106. */
  1107. }, {
  1108. key: "count",
  1109. value: function count(options
  1110. /*:: ?: FullOptions*/
  1111. )
  1112. /*: Promise<number>*/
  1113. {
  1114. options = options || {};
  1115. var findOptions = {};
  1116. if (options.hasOwnProperty('useMasterKey')) {
  1117. findOptions.useMasterKey = options.useMasterKey;
  1118. }
  1119. if (options.hasOwnProperty('sessionToken')) {
  1120. findOptions.sessionToken = options.sessionToken;
  1121. }
  1122. this._setRequestTask(findOptions);
  1123. var controller = _CoreManager.default.getQueryController();
  1124. var params = this.toJSON();
  1125. params.limit = 0;
  1126. params.count = 1;
  1127. return (0, _find.default)(controller).call(controller, this.className, params, findOptions).then(function (result) {
  1128. return result.count;
  1129. });
  1130. }
  1131. /**
  1132. * Executes a distinct query and returns unique values
  1133. *
  1134. * @param {string} key A field to find distinct values
  1135. * @param {object} options
  1136. * Valid options are:<ul>
  1137. * <li>sessionToken: A valid session token, used for making a request on
  1138. * behalf of a specific user.
  1139. * </ul>
  1140. *
  1141. * @returns {Promise} A promise that is resolved with the query completes.
  1142. */
  1143. }, {
  1144. key: "distinct",
  1145. value: function distinct(key
  1146. /*: string*/
  1147. , options
  1148. /*:: ?: FullOptions*/
  1149. )
  1150. /*: Promise<Array<mixed>>*/
  1151. {
  1152. options = options || {};
  1153. var distinctOptions = {};
  1154. distinctOptions.useMasterKey = true;
  1155. if (options.hasOwnProperty('sessionToken')) {
  1156. distinctOptions.sessionToken = options.sessionToken;
  1157. }
  1158. this._setRequestTask(distinctOptions);
  1159. var controller = _CoreManager.default.getQueryController();
  1160. var params = {
  1161. distinct: key,
  1162. where: this._where,
  1163. hint: this._hint
  1164. };
  1165. return controller.aggregate(this.className, params, distinctOptions).then(function (results) {
  1166. return results.results;
  1167. });
  1168. }
  1169. /**
  1170. * Executes an aggregate query and returns aggregate results
  1171. *
  1172. * @param {(Array|object)} pipeline Array or Object of stages to process query
  1173. * @param {object} options Valid options are:<ul>
  1174. * <li>sessionToken: A valid session token, used for making a request on
  1175. * behalf of a specific user.
  1176. * </ul>
  1177. *
  1178. * @returns {Promise} A promise that is resolved with the query completes.
  1179. */
  1180. }, {
  1181. key: "aggregate",
  1182. value: function aggregate(pipeline
  1183. /*: mixed*/
  1184. , options
  1185. /*:: ?: FullOptions*/
  1186. )
  1187. /*: Promise<Array<mixed>>*/
  1188. {
  1189. options = options || {};
  1190. var aggregateOptions = {};
  1191. aggregateOptions.useMasterKey = true;
  1192. if (options.hasOwnProperty('sessionToken')) {
  1193. aggregateOptions.sessionToken = options.sessionToken;
  1194. }
  1195. this._setRequestTask(aggregateOptions);
  1196. var controller = _CoreManager.default.getQueryController();
  1197. if (!(0, _isArray.default)(pipeline) && (0, _typeof2.default)(pipeline) !== 'object') {
  1198. throw new Error('Invalid pipeline must be Array or Object');
  1199. }
  1200. if ((0, _keys2.default)(this._where || {}).length) {
  1201. if (!(0, _isArray.default)(pipeline)) {
  1202. pipeline = [pipeline];
  1203. }
  1204. pipeline.unshift({
  1205. match: this._where
  1206. });
  1207. }
  1208. var params = {
  1209. pipeline: pipeline,
  1210. hint: this._hint,
  1211. explain: this._explain,
  1212. readPreference: this._readPreference
  1213. };
  1214. return controller.aggregate(this.className, params, aggregateOptions).then(function (results) {
  1215. return results.results;
  1216. });
  1217. }
  1218. /**
  1219. * Retrieves at most one Parse.Object that satisfies this query.
  1220. *
  1221. * Returns the object if there is one, otherwise undefined.
  1222. *
  1223. * @param {object} options Valid options are:<ul>
  1224. * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
  1225. * be used for this request.
  1226. * <li>sessionToken: A valid session token, used for making a request on
  1227. * behalf of a specific user.
  1228. * <li>context: A dictionary that is accessible in Cloud Code `beforeFind` trigger.
  1229. * <li>json: Return raw json without converting to Parse.Object
  1230. * </ul>
  1231. *
  1232. * @returns {Promise} A promise that is resolved with the object when
  1233. * the query completes.
  1234. */
  1235. }, {
  1236. key: "first",
  1237. value: function first(options
  1238. /*:: ?: FullOptions*/
  1239. )
  1240. /*: Promise<ParseObject | void>*/
  1241. {
  1242. var _this4 = this;
  1243. options = options || {};
  1244. var findOptions = {};
  1245. if (options.hasOwnProperty('useMasterKey')) {
  1246. findOptions.useMasterKey = options.useMasterKey;
  1247. }
  1248. if (options.hasOwnProperty('sessionToken')) {
  1249. findOptions.sessionToken = options.sessionToken;
  1250. }
  1251. if (options.hasOwnProperty('context') && (0, _typeof2.default)(options.context) === 'object') {
  1252. findOptions.context = options.context;
  1253. }
  1254. this._setRequestTask(findOptions);
  1255. var controller = _CoreManager.default.getQueryController();
  1256. var params = this.toJSON();
  1257. params.limit = 1;
  1258. var select = this._select;
  1259. if (this._queriesLocalDatastore) {
  1260. return this._handleOfflineQuery(params).then(function (objects) {
  1261. if (!objects[0]) {
  1262. return undefined;
  1263. }
  1264. return objects[0];
  1265. });
  1266. }
  1267. return (0, _find.default)(controller).call(controller, this.className, params, findOptions).then(function (response) {
  1268. var objects = response.results;
  1269. if (!objects[0]) {
  1270. return undefined;
  1271. }
  1272. if (!objects[0].className) {
  1273. objects[0].className = _this4.className;
  1274. } // Make sure the data object contains keys for all objects that
  1275. // have been requested with a select, so that our cached state
  1276. // updates correctly.
  1277. if (select) {
  1278. handleSelectResult(objects[0], select);
  1279. }
  1280. if (options.json) {
  1281. return objects[0];
  1282. } else {
  1283. return _ParseObject.default.fromJSON(objects[0], !select);
  1284. }
  1285. });
  1286. }
  1287. /**
  1288. * Iterates over objects matching a query, calling a callback for each batch.
  1289. * If the callback returns a promise, the iteration will not continue until
  1290. * that promise has been fulfilled. If the callback returns a rejected
  1291. * promise, then iteration will stop with that error. The items are processed
  1292. * in an unspecified order. The query may not have any sort order, and may
  1293. * not use limit or skip.
  1294. *
  1295. * @param {Function} callback Callback that will be called with each result
  1296. * of the query.
  1297. * @param {object} options Valid options are:<ul>
  1298. * <li>batchSize: How many objects to yield in each batch (default: 100)
  1299. * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
  1300. * be used for this request.
  1301. * <li>sessionToken: A valid session token, used for making a request on
  1302. * behalf of a specific user.
  1303. * <li>context: A dictionary that is accessible in Cloud Code `beforeFind` trigger.
  1304. * </ul>
  1305. * @returns {Promise} A promise that will be fulfilled once the
  1306. * iteration has completed.
  1307. */
  1308. }, {
  1309. key: "eachBatch",
  1310. value: function eachBatch(callback
  1311. /*: (objs: Array<ParseObject>) => Promise<*>*/
  1312. , options
  1313. /*:: ?: BatchOptions*/
  1314. )
  1315. /*: Promise<void>*/
  1316. {
  1317. var _context8;
  1318. options = options || {};
  1319. if (this._order || this._skip || this._limit >= 0) {
  1320. var error = 'Cannot iterate on a query with sort, skip, or limit.';
  1321. return _promise.default.reject(error);
  1322. }
  1323. var query = new ParseQuery(this.className);
  1324. query._limit = options.batchSize || 100;
  1325. query._include = (0, _map2.default)(_context8 = this._include).call(_context8, function (i) {
  1326. return i;
  1327. });
  1328. if (this._select) {
  1329. var _context9;
  1330. query._select = (0, _map2.default)(_context9 = this._select).call(_context9, function (s) {
  1331. return s;
  1332. });
  1333. }
  1334. query._hint = this._hint;
  1335. query._where = {};
  1336. for (var _attr in this._where) {
  1337. var val = this._where[_attr];
  1338. if ((0, _isArray.default)(val)) {
  1339. query._where[_attr] = (0, _map2.default)(val).call(val, function (v) {
  1340. return v;
  1341. });
  1342. } else if (val && (0, _typeof2.default)(val) === 'object') {
  1343. var conditionMap = {};
  1344. query._where[_attr] = conditionMap;
  1345. for (var cond in val) {
  1346. conditionMap[cond] = val[cond];
  1347. }
  1348. } else {
  1349. query._where[_attr] = val;
  1350. }
  1351. }
  1352. query.ascending('objectId');
  1353. var findOptions = {};
  1354. if (options.hasOwnProperty('useMasterKey')) {
  1355. findOptions.useMasterKey = options.useMasterKey;
  1356. }
  1357. if (options.hasOwnProperty('sessionToken')) {
  1358. findOptions.sessionToken = options.sessionToken;
  1359. }
  1360. if (options.hasOwnProperty('context') && (0, _typeof2.default)(options.context) === 'object') {
  1361. findOptions.context = options.context;
  1362. }
  1363. if (options.hasOwnProperty('json')) {
  1364. findOptions.json = options.json;
  1365. }
  1366. var finished = false;
  1367. var previousResults = [];
  1368. return (0, _promiseUtils.continueWhile)(function () {
  1369. return !finished;
  1370. }, /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
  1371. var _yield$Promise$all, _yield$Promise$all2, results;
  1372. return _regeneratorRuntime().wrap(function _callee3$(_context10) {
  1373. while (1) {
  1374. switch (_context10.prev = _context10.next) {
  1375. case 0:
  1376. _context10.next = 2;
  1377. return _promise.default.all([(0, _find.default)(query).call(query, findOptions), _promise.default.resolve(previousResults.length > 0 && callback(previousResults))]);
  1378. case 2:
  1379. _yield$Promise$all = _context10.sent;
  1380. _yield$Promise$all2 = (0, _slicedToArray2.default)(_yield$Promise$all, 1);
  1381. results = _yield$Promise$all2[0];
  1382. if (!(results.length >= query._limit)) {
  1383. _context10.next = 10;
  1384. break;
  1385. }
  1386. query.greaterThan('objectId', results[results.length - 1].id);
  1387. previousResults = results;
  1388. _context10.next = 17;
  1389. break;
  1390. case 10:
  1391. if (!(results.length > 0)) {
  1392. _context10.next = 16;
  1393. break;
  1394. }
  1395. _context10.next = 13;
  1396. return _promise.default.resolve(callback(results));
  1397. case 13:
  1398. finished = true;
  1399. _context10.next = 17;
  1400. break;
  1401. case 16:
  1402. finished = true;
  1403. case 17:
  1404. case "end":
  1405. return _context10.stop();
  1406. }
  1407. }
  1408. }, _callee3);
  1409. })));
  1410. }
  1411. /**
  1412. * Iterates over each result of a query, calling a callback for each one. If
  1413. * the callback returns a promise, the iteration will not continue until
  1414. * that promise has been fulfilled. If the callback returns a rejected
  1415. * promise, then iteration will stop with that error. The items are
  1416. * processed in an unspecified order. The query may not have any sort order,
  1417. * and may not use limit or skip.
  1418. *
  1419. * @param {Function} callback Callback that will be called with each result
  1420. * of the query.
  1421. * @param {object} options Valid options are:<ul>
  1422. * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
  1423. * be used for this request.
  1424. * <li>sessionToken: A valid session token, used for making a request on
  1425. * behalf of a specific user.
  1426. * <li>json: Return raw json without converting to Parse.Object
  1427. * </ul>
  1428. * @returns {Promise} A promise that will be fulfilled once the
  1429. * iteration has completed.
  1430. */
  1431. }, {
  1432. key: "each",
  1433. value: function each(callback
  1434. /*: (obj: ParseObject) => any*/
  1435. , options
  1436. /*:: ?: BatchOptions*/
  1437. )
  1438. /*: Promise<void>*/
  1439. {
  1440. return this.eachBatch(function (results) {
  1441. var callbacksDone = _promise.default.resolve();
  1442. (0, _forEach.default)(results).call(results, function (result) {
  1443. callbacksDone = callbacksDone.then(function () {
  1444. return callback(result);
  1445. });
  1446. });
  1447. return callbacksDone;
  1448. }, options);
  1449. }
  1450. /**
  1451. * Adds a hint to force index selection. (https://docs.mongodb.com/manual/reference/operator/meta/hint/)
  1452. *
  1453. * @param {(string|object)} value String or Object of index that should be used when executing query
  1454. * @returns {Parse.Query} Returns the query, so you can chain this call.
  1455. */
  1456. }, {
  1457. key: "hint",
  1458. value: function hint(value
  1459. /*: mixed*/
  1460. )
  1461. /*: ParseQuery*/
  1462. {
  1463. if (typeof value === 'undefined') {
  1464. delete this._hint;
  1465. }
  1466. this._hint = value;
  1467. return this;
  1468. }
  1469. /**
  1470. * Investigates the query execution plan. Useful for optimizing queries. (https://docs.mongodb.com/manual/reference/operator/meta/explain/)
  1471. *
  1472. * @param {boolean} explain Used to toggle the information on the query plan.
  1473. * @returns {Parse.Query} Returns the query, so you can chain this call.
  1474. */
  1475. }, {
  1476. key: "explain",
  1477. value: function explain()
  1478. /*: ParseQuery*/
  1479. {
  1480. var _explain
  1481. /*: boolean*/
  1482. = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  1483. if (typeof _explain !== 'boolean') {
  1484. throw new Error('You can only set explain to a boolean value');
  1485. }
  1486. this._explain = _explain;
  1487. return this;
  1488. }
  1489. /**
  1490. * Iterates over each result of a query, calling a callback for each one. If
  1491. * the callback returns a promise, the iteration will not continue until
  1492. * that promise has been fulfilled. If the callback returns a rejected
  1493. * promise, then iteration will stop with that error. The items are
  1494. * processed in an unspecified order. The query may not have any sort order,
  1495. * and may not use limit or skip.
  1496. *
  1497. * @param {Function} callback Callback <ul>
  1498. * <li>currentObject: The current Parse.Object being processed in the array.</li>
  1499. * <li>index: The index of the current Parse.Object being processed in the array.</li>
  1500. * <li>query: The query map was called upon.</li>
  1501. * </ul>
  1502. *
  1503. * @param {object} options Valid options are:<ul>
  1504. * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
  1505. * be used for this request.
  1506. * <li>sessionToken: A valid session token, used for making a request on
  1507. * behalf of a specific user.
  1508. * </ul>
  1509. * @returns {Promise} A promise that will be fulfilled once the
  1510. * iteration has completed.
  1511. */
  1512. }, {
  1513. key: "map",
  1514. value: function () {
  1515. var _map = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(callback
  1516. /*: (currentObject: ParseObject, index: number, query: ParseQuery) => any*/
  1517. , options
  1518. /*:: ?: BatchOptions*/
  1519. ) {
  1520. var _this5 = this;
  1521. var array, index;
  1522. return _regeneratorRuntime().wrap(function _callee4$(_context11) {
  1523. while (1) {
  1524. switch (_context11.prev = _context11.next) {
  1525. case 0:
  1526. array = [];
  1527. index = 0;
  1528. _context11.next = 4;
  1529. return this.each(function (object) {
  1530. return _promise.default.resolve(callback(object, index, _this5)).then(function (result) {
  1531. array.push(result);
  1532. index += 1;
  1533. });
  1534. }, options);
  1535. case 4:
  1536. return _context11.abrupt("return", array);
  1537. case 5:
  1538. case "end":
  1539. return _context11.stop();
  1540. }
  1541. }
  1542. }, _callee4, this);
  1543. }));
  1544. function map(_x3, _x4) {
  1545. return _map.apply(this, arguments);
  1546. }
  1547. return map;
  1548. }()
  1549. /**
  1550. * Iterates over each result of a query, calling a callback for each one. If
  1551. * the callback returns a promise, the iteration will not continue until
  1552. * that promise has been fulfilled. If the callback returns a rejected
  1553. * promise, then iteration will stop with that error. The items are
  1554. * processed in an unspecified order. The query may not have any sort order,
  1555. * and may not use limit or skip.
  1556. *
  1557. * @param {Function} callback Callback <ul>
  1558. * <li>accumulator: The accumulator accumulates the callback's return values. It is the accumulated value previously returned in the last invocation of the callback.</li>
  1559. * <li>currentObject: The current Parse.Object being processed in the array.</li>
  1560. * <li>index: The index of the current Parse.Object being processed in the array.</li>
  1561. * </ul>
  1562. * @param {*} initialValue A value to use as the first argument to the first call of the callback. If no initialValue is supplied, the first object in the query will be used and skipped.
  1563. * @param {object} options Valid options are:<ul>
  1564. * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
  1565. * be used for this request.
  1566. * <li>sessionToken: A valid session token, used for making a request on
  1567. * behalf of a specific user.
  1568. * </ul>
  1569. * @returns {Promise} A promise that will be fulfilled once the
  1570. * iteration has completed.
  1571. */
  1572. }, {
  1573. key: "reduce",
  1574. value: function () {
  1575. var _reduce = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(callback
  1576. /*: (accumulator: any, currentObject: ParseObject, index: number) => any*/
  1577. , initialValue
  1578. /*: any*/
  1579. , options
  1580. /*:: ?: BatchOptions*/
  1581. ) {
  1582. var accumulator, index;
  1583. return _regeneratorRuntime().wrap(function _callee5$(_context12) {
  1584. while (1) {
  1585. switch (_context12.prev = _context12.next) {
  1586. case 0:
  1587. accumulator = initialValue;
  1588. index = 0;
  1589. _context12.next = 4;
  1590. return this.each(function (object) {
  1591. // If no initial value was given, we take the first object from the query
  1592. // as the initial value and don't call the callback with it.
  1593. if (index === 0 && initialValue === undefined) {
  1594. accumulator = object;
  1595. index += 1;
  1596. return;
  1597. }
  1598. return _promise.default.resolve(callback(accumulator, object, index)).then(function (result) {
  1599. accumulator = result;
  1600. index += 1;
  1601. });
  1602. }, options);
  1603. case 4:
  1604. if (!(index === 0 && initialValue === undefined)) {
  1605. _context12.next = 6;
  1606. break;
  1607. }
  1608. throw new TypeError('Reducing empty query result set with no initial value');
  1609. case 6:
  1610. return _context12.abrupt("return", accumulator);
  1611. case 7:
  1612. case "end":
  1613. return _context12.stop();
  1614. }
  1615. }
  1616. }, _callee5, this);
  1617. }));
  1618. function reduce(_x5, _x6, _x7) {
  1619. return _reduce.apply(this, arguments);
  1620. }
  1621. return reduce;
  1622. }()
  1623. /**
  1624. * Iterates over each result of a query, calling a callback for each one. If
  1625. * the callback returns a promise, the iteration will not continue until
  1626. * that promise has been fulfilled. If the callback returns a rejected
  1627. * promise, then iteration will stop with that error. The items are
  1628. * processed in an unspecified order. The query may not have any sort order,
  1629. * and may not use limit or skip.
  1630. *
  1631. * @param {Function} callback Callback <ul>
  1632. * <li>currentObject: The current Parse.Object being processed in the array.</li>
  1633. * <li>index: The index of the current Parse.Object being processed in the array.</li>
  1634. * <li>query: The query filter was called upon.</li>
  1635. * </ul>
  1636. *
  1637. * @param {object} options Valid options are:<ul>
  1638. * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
  1639. * be used for this request.
  1640. * <li>sessionToken: A valid session token, used for making a request on
  1641. * behalf of a specific user.
  1642. * </ul>
  1643. * @returns {Promise} A promise that will be fulfilled once the
  1644. * iteration has completed.
  1645. */
  1646. }, {
  1647. key: "filter",
  1648. value: function () {
  1649. var _filter = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(callback
  1650. /*: (currentObject: ParseObject, index: number, query: ParseQuery) => boolean*/
  1651. , options
  1652. /*:: ?: BatchOptions*/
  1653. ) {
  1654. var _this6 = this;
  1655. var array, index;
  1656. return _regeneratorRuntime().wrap(function _callee6$(_context13) {
  1657. while (1) {
  1658. switch (_context13.prev = _context13.next) {
  1659. case 0:
  1660. array = [];
  1661. index = 0;
  1662. _context13.next = 4;
  1663. return this.each(function (object) {
  1664. return _promise.default.resolve(callback(object, index, _this6)).then(function (flag) {
  1665. if (flag) {
  1666. array.push(object);
  1667. }
  1668. index += 1;
  1669. });
  1670. }, options);
  1671. case 4:
  1672. return _context13.abrupt("return", array);
  1673. case 5:
  1674. case "end":
  1675. return _context13.stop();
  1676. }
  1677. }
  1678. }, _callee6, this);
  1679. }));
  1680. function filter(_x8, _x9) {
  1681. return _filter.apply(this, arguments);
  1682. }
  1683. return filter;
  1684. }()
  1685. /** Query Conditions **/
  1686. /**
  1687. * Adds a constraint to the query that requires a particular key's value to
  1688. * be equal to the provided value.
  1689. *
  1690. * @param {string} key The key to check.
  1691. * @param value The value that the Parse.Object must contain.
  1692. * @returns {Parse.Query} Returns the query, so you can chain this call.
  1693. */
  1694. }, {
  1695. key: "equalTo",
  1696. value: function equalTo(key
  1697. /*: string | { [key: string]: any }*/
  1698. , value
  1699. /*: ?mixed*/
  1700. )
  1701. /*: ParseQuery*/
  1702. {
  1703. var _this7 = this;
  1704. if (key && (0, _typeof2.default)(key) === 'object') {
  1705. var _context14;
  1706. (0, _forEach.default)(_context14 = (0, _entries.default)(key)).call(_context14, function (_ref2) {
  1707. var _ref3 = (0, _slicedToArray2.default)(_ref2, 2),
  1708. k = _ref3[0],
  1709. val = _ref3[1];
  1710. return _this7.equalTo(k, val);
  1711. });
  1712. return this;
  1713. }
  1714. if (typeof value === 'undefined') {
  1715. return this.doesNotExist(key);
  1716. }
  1717. this._where[key] = (0, _encode.default)(value, false, true);
  1718. return this;
  1719. }
  1720. /**
  1721. * Adds a constraint to the query that requires a particular key's value to
  1722. * be not equal to the provided value.
  1723. *
  1724. * @param {string} key The key to check.
  1725. * @param value The value that must not be equalled.
  1726. * @returns {Parse.Query} Returns the query, so you can chain this call.
  1727. */
  1728. }, {
  1729. key: "notEqualTo",
  1730. value: function notEqualTo(key
  1731. /*: string | { [key: string]: any }*/
  1732. , value
  1733. /*: ?mixed*/
  1734. )
  1735. /*: ParseQuery*/
  1736. {
  1737. var _this8 = this;
  1738. if (key && (0, _typeof2.default)(key) === 'object') {
  1739. var _context15;
  1740. (0, _forEach.default)(_context15 = (0, _entries.default)(key)).call(_context15, function (_ref4) {
  1741. var _ref5 = (0, _slicedToArray2.default)(_ref4, 2),
  1742. k = _ref5[0],
  1743. val = _ref5[1];
  1744. return _this8.notEqualTo(k, val);
  1745. });
  1746. return this;
  1747. }
  1748. return this._addCondition(key, '$ne', value);
  1749. }
  1750. /**
  1751. * Adds a constraint to the query that requires a particular key's value to
  1752. * be less than the provided value.
  1753. *
  1754. * @param {string} key The key to check.
  1755. * @param value The value that provides an upper bound.
  1756. * @returns {Parse.Query} Returns the query, so you can chain this call.
  1757. */
  1758. }, {
  1759. key: "lessThan",
  1760. value: function lessThan(key
  1761. /*: string*/
  1762. , value
  1763. /*: mixed*/
  1764. )
  1765. /*: ParseQuery*/
  1766. {
  1767. return this._addCondition(key, '$lt', value);
  1768. }
  1769. /**
  1770. * Adds a constraint to the query that requires a particular key's value to
  1771. * be greater than the provided value.
  1772. *
  1773. * @param {string} key The key to check.
  1774. * @param value The value that provides an lower bound.
  1775. * @returns {Parse.Query} Returns the query, so you can chain this call.
  1776. */
  1777. }, {
  1778. key: "greaterThan",
  1779. value: function greaterThan(key
  1780. /*: string*/
  1781. , value
  1782. /*: mixed*/
  1783. )
  1784. /*: ParseQuery*/
  1785. {
  1786. return this._addCondition(key, '$gt', value);
  1787. }
  1788. /**
  1789. * Adds a constraint to the query that requires a particular key's value to
  1790. * be less than or equal to the provided value.
  1791. *
  1792. * @param {string} key The key to check.
  1793. * @param value The value that provides an upper bound.
  1794. * @returns {Parse.Query} Returns the query, so you can chain this call.
  1795. */
  1796. }, {
  1797. key: "lessThanOrEqualTo",
  1798. value: function lessThanOrEqualTo(key
  1799. /*: string*/
  1800. , value
  1801. /*: mixed*/
  1802. )
  1803. /*: ParseQuery*/
  1804. {
  1805. return this._addCondition(key, '$lte', value);
  1806. }
  1807. /**
  1808. * Adds a constraint to the query that requires a particular key's value to
  1809. * be greater than or equal to the provided value.
  1810. *
  1811. * @param {string} key The key to check.
  1812. * @param {*} value The value that provides an lower bound.
  1813. * @returns {Parse.Query} Returns the query, so you can chain this call.
  1814. */
  1815. }, {
  1816. key: "greaterThanOrEqualTo",
  1817. value: function greaterThanOrEqualTo(key
  1818. /*: string*/
  1819. , value
  1820. /*: mixed*/
  1821. )
  1822. /*: ParseQuery*/
  1823. {
  1824. return this._addCondition(key, '$gte', value);
  1825. }
  1826. /**
  1827. * Adds a constraint to the query that requires a particular key's value to
  1828. * be contained in the provided list of values.
  1829. *
  1830. * @param {string} key The key to check.
  1831. * @param {*} value The values that will match.
  1832. * @returns {Parse.Query} Returns the query, so you can chain this call.
  1833. */
  1834. }, {
  1835. key: "containedIn",
  1836. value: function containedIn(key
  1837. /*: string*/
  1838. , value
  1839. /*: mixed*/
  1840. )
  1841. /*: ParseQuery*/
  1842. {
  1843. return this._addCondition(key, '$in', value);
  1844. }
  1845. /**
  1846. * Adds a constraint to the query that requires a particular key's value to
  1847. * not be contained in the provided list of values.
  1848. *
  1849. * @param {string} key The key to check.
  1850. * @param {*} value The values that will not match.
  1851. * @returns {Parse.Query} Returns the query, so you can chain this call.
  1852. */
  1853. }, {
  1854. key: "notContainedIn",
  1855. value: function notContainedIn(key
  1856. /*: string*/
  1857. , value
  1858. /*: mixed*/
  1859. )
  1860. /*: ParseQuery*/
  1861. {
  1862. return this._addCondition(key, '$nin', value);
  1863. }
  1864. /**
  1865. * Adds a constraint to the query that requires a particular key's value to
  1866. * be contained by the provided list of values. Get objects where all array elements match.
  1867. *
  1868. * @param {string} key The key to check.
  1869. * @param {Array} values The values that will match.
  1870. * @returns {Parse.Query} Returns the query, so you can chain this call.
  1871. */
  1872. }, {
  1873. key: "containedBy",
  1874. value: function containedBy(key
  1875. /*: string*/
  1876. , values
  1877. /*: Array<mixed>*/
  1878. )
  1879. /*: ParseQuery*/
  1880. {
  1881. return this._addCondition(key, '$containedBy', values);
  1882. }
  1883. /**
  1884. * Adds a constraint to the query that requires a particular key's value to
  1885. * contain each one of the provided list of values.
  1886. *
  1887. * @param {string} key The key to check. This key's value must be an array.
  1888. * @param {Array} values The values that will match.
  1889. * @returns {Parse.Query} Returns the query, so you can chain this call.
  1890. */
  1891. }, {
  1892. key: "containsAll",
  1893. value: function containsAll(key
  1894. /*: string*/
  1895. , values
  1896. /*: Array<mixed>*/
  1897. )
  1898. /*: ParseQuery*/
  1899. {
  1900. return this._addCondition(key, '$all', values);
  1901. }
  1902. /**
  1903. * Adds a constraint to the query that requires a particular key's value to
  1904. * contain each one of the provided list of values starting with given strings.
  1905. *
  1906. * @param {string} key The key to check. This key's value must be an array.
  1907. * @param {Array<string>} values The string values that will match as starting string.
  1908. * @returns {Parse.Query} Returns the query, so you can chain this call.
  1909. */
  1910. }, {
  1911. key: "containsAllStartingWith",
  1912. value: function containsAllStartingWith(key
  1913. /*: string*/
  1914. , values
  1915. /*: Array<string>*/
  1916. )
  1917. /*: ParseQuery*/
  1918. {
  1919. var _this = this;
  1920. if (!(0, _isArray.default)(values)) {
  1921. values = [values];
  1922. }
  1923. var regexObject = (0, _map2.default)(values).call(values, function (value) {
  1924. return {
  1925. $regex: _this._regexStartWith(value)
  1926. };
  1927. });
  1928. return this.containsAll(key, regexObject);
  1929. }
  1930. /**
  1931. * Adds a constraint for finding objects that contain the given key.
  1932. *
  1933. * @param {string} key The key that should exist.
  1934. * @returns {Parse.Query} Returns the query, so you can chain this call.
  1935. */
  1936. }, {
  1937. key: "exists",
  1938. value: function exists(key
  1939. /*: string*/
  1940. )
  1941. /*: ParseQuery*/
  1942. {
  1943. return this._addCondition(key, '$exists', true);
  1944. }
  1945. /**
  1946. * Adds a constraint for finding objects that do not contain a given key.
  1947. *
  1948. * @param {string} key The key that should not exist
  1949. * @returns {Parse.Query} Returns the query, so you can chain this call.
  1950. */
  1951. }, {
  1952. key: "doesNotExist",
  1953. value: function doesNotExist(key
  1954. /*: string*/
  1955. )
  1956. /*: ParseQuery*/
  1957. {
  1958. return this._addCondition(key, '$exists', false);
  1959. }
  1960. /**
  1961. * Adds a regular expression constraint for finding string values that match
  1962. * the provided regular expression.
  1963. * This may be slow for large datasets.
  1964. *
  1965. * @param {string} key The key that the string to match is stored in.
  1966. * @param {RegExp} regex The regular expression pattern to match.
  1967. * @param {string} modifiers The regular expression mode.
  1968. * @returns {Parse.Query} Returns the query, so you can chain this call.
  1969. */
  1970. }, {
  1971. key: "matches",
  1972. value: function matches(key
  1973. /*: string*/
  1974. , regex
  1975. /*: RegExp*/
  1976. , modifiers
  1977. /*: string*/
  1978. )
  1979. /*: ParseQuery*/
  1980. {
  1981. this._addCondition(key, '$regex', regex);
  1982. if (!modifiers) {
  1983. modifiers = '';
  1984. }
  1985. if (regex.ignoreCase) {
  1986. modifiers += 'i';
  1987. }
  1988. if (regex.multiline) {
  1989. modifiers += 'm';
  1990. }
  1991. if (modifiers.length) {
  1992. this._addCondition(key, '$options', modifiers);
  1993. }
  1994. return this;
  1995. }
  1996. /**
  1997. * Adds a constraint that requires that a key's value matches a Parse.Query
  1998. * constraint.
  1999. *
  2000. * @param {string} key The key that the contains the object to match the
  2001. * query.
  2002. * @param {Parse.Query} query The query that should match.
  2003. * @returns {Parse.Query} Returns the query, so you can chain this call.
  2004. */
  2005. }, {
  2006. key: "matchesQuery",
  2007. value: function matchesQuery(key
  2008. /*: string*/
  2009. , query
  2010. /*: ParseQuery*/
  2011. )
  2012. /*: ParseQuery*/
  2013. {
  2014. var queryJSON = query.toJSON();
  2015. queryJSON.className = query.className;
  2016. return this._addCondition(key, '$inQuery', queryJSON);
  2017. }
  2018. /**
  2019. * Adds a constraint that requires that a key's value not matches a
  2020. * Parse.Query constraint.
  2021. *
  2022. * @param {string} key The key that the contains the object to match the
  2023. * query.
  2024. * @param {Parse.Query} query The query that should not match.
  2025. * @returns {Parse.Query} Returns the query, so you can chain this call.
  2026. */
  2027. }, {
  2028. key: "doesNotMatchQuery",
  2029. value: function doesNotMatchQuery(key
  2030. /*: string*/
  2031. , query
  2032. /*: ParseQuery*/
  2033. )
  2034. /*: ParseQuery*/
  2035. {
  2036. var queryJSON = query.toJSON();
  2037. queryJSON.className = query.className;
  2038. return this._addCondition(key, '$notInQuery', queryJSON);
  2039. }
  2040. /**
  2041. * Adds a constraint that requires that a key's value matches a value in
  2042. * an object returned by a different Parse.Query.
  2043. *
  2044. * @param {string} key The key that contains the value that is being
  2045. * matched.
  2046. * @param {string} queryKey The key in the objects returned by the query to
  2047. * match against.
  2048. * @param {Parse.Query} query The query to run.
  2049. * @returns {Parse.Query} Returns the query, so you can chain this call.
  2050. */
  2051. }, {
  2052. key: "matchesKeyInQuery",
  2053. value: function matchesKeyInQuery(key
  2054. /*: string*/
  2055. , queryKey
  2056. /*: string*/
  2057. , query
  2058. /*: ParseQuery*/
  2059. )
  2060. /*: ParseQuery*/
  2061. {
  2062. var queryJSON = query.toJSON();
  2063. queryJSON.className = query.className;
  2064. return this._addCondition(key, '$select', {
  2065. key: queryKey,
  2066. query: queryJSON
  2067. });
  2068. }
  2069. /**
  2070. * Adds a constraint that requires that a key's value not match a value in
  2071. * an object returned by a different Parse.Query.
  2072. *
  2073. * @param {string} key The key that contains the value that is being
  2074. * excluded.
  2075. * @param {string} queryKey The key in the objects returned by the query to
  2076. * match against.
  2077. * @param {Parse.Query} query The query to run.
  2078. * @returns {Parse.Query} Returns the query, so you can chain this call.
  2079. */
  2080. }, {
  2081. key: "doesNotMatchKeyInQuery",
  2082. value: function doesNotMatchKeyInQuery(key
  2083. /*: string*/
  2084. , queryKey
  2085. /*: string*/
  2086. , query
  2087. /*: ParseQuery*/
  2088. )
  2089. /*: ParseQuery*/
  2090. {
  2091. var queryJSON = query.toJSON();
  2092. queryJSON.className = query.className;
  2093. return this._addCondition(key, '$dontSelect', {
  2094. key: queryKey,
  2095. query: queryJSON
  2096. });
  2097. }
  2098. /**
  2099. * Adds a constraint for finding string values that contain a provided
  2100. * string. This may be slow for large datasets.
  2101. *
  2102. * @param {string} key The key that the string to match is stored in.
  2103. * @param {string} substring The substring that the value must contain.
  2104. * @returns {Parse.Query} Returns the query, so you can chain this call.
  2105. */
  2106. }, {
  2107. key: "contains",
  2108. value: function contains(key
  2109. /*: string*/
  2110. , substring
  2111. /*: string*/
  2112. )
  2113. /*: ParseQuery*/
  2114. {
  2115. if (typeof substring !== 'string') {
  2116. throw new Error('The value being searched for must be a string.');
  2117. }
  2118. return this._addCondition(key, '$regex', quote(substring));
  2119. }
  2120. /**
  2121. * Adds a constraint for finding string values that contain a provided
  2122. * string. This may be slow for large datasets. Requires Parse-Server > 2.5.0
  2123. *
  2124. * In order to sort you must use select and ascending ($score is required)
  2125. * <pre>
  2126. * query.fullText('field', 'term');
  2127. * query.ascending('$score');
  2128. * query.select('$score');
  2129. * </pre>
  2130. *
  2131. * To retrieve the weight / rank
  2132. * <pre>
  2133. * object->get('score');
  2134. * </pre>
  2135. *
  2136. * You can define optionals by providing an object as a third parameter
  2137. * <pre>
  2138. * query.fullText('field', 'term', { language: 'es', diacriticSensitive: true });
  2139. * </pre>
  2140. *
  2141. * @param {string} key The key that the string to match is stored in.
  2142. * @param {string} value The string to search
  2143. * @param {object} options (Optional)
  2144. * @param {string} options.language The language that determines the list of stop words for the search and the rules for the stemmer and tokenizer.
  2145. * @param {boolean} options.caseSensitive A boolean flag to enable or disable case sensitive search.
  2146. * @param {boolean} options.diacriticSensitive A boolean flag to enable or disable diacritic sensitive search.
  2147. * @returns {Parse.Query} Returns the query, so you can chain this call.
  2148. */
  2149. }, {
  2150. key: "fullText",
  2151. value: function fullText(key
  2152. /*: string*/
  2153. , value
  2154. /*: string*/
  2155. , options
  2156. /*: ?Object*/
  2157. )
  2158. /*: ParseQuery*/
  2159. {
  2160. options = options || {};
  2161. if (!key) {
  2162. throw new Error('A key is required.');
  2163. }
  2164. if (!value) {
  2165. throw new Error('A search term is required');
  2166. }
  2167. if (typeof value !== 'string') {
  2168. throw new Error('The value being searched for must be a string.');
  2169. }
  2170. var fullOptions = {};
  2171. fullOptions.$term = value;
  2172. for (var option in options) {
  2173. switch (option) {
  2174. case 'language':
  2175. fullOptions.$language = options[option];
  2176. break;
  2177. case 'caseSensitive':
  2178. fullOptions.$caseSensitive = options[option];
  2179. break;
  2180. case 'diacriticSensitive':
  2181. fullOptions.$diacriticSensitive = options[option];
  2182. break;
  2183. default:
  2184. throw new Error("Unknown option: ".concat(option));
  2185. }
  2186. }
  2187. return this._addCondition(key, '$text', {
  2188. $search: fullOptions
  2189. });
  2190. }
  2191. /**
  2192. * Method to sort the full text search by text score
  2193. *
  2194. * @returns {Parse.Query} Returns the query, so you can chain this call.
  2195. */
  2196. }, {
  2197. key: "sortByTextScore",
  2198. value: function sortByTextScore() {
  2199. this.ascending('$score');
  2200. this.select(['$score']);
  2201. return this;
  2202. }
  2203. /**
  2204. * Adds a constraint for finding string values that start with a provided
  2205. * string. This query will use the backend index, so it will be fast even
  2206. * for large datasets.
  2207. *
  2208. * @param {string} key The key that the string to match is stored in.
  2209. * @param {string} prefix The substring that the value must start with.
  2210. * @param {string} modifiers The regular expression mode.
  2211. * @returns {Parse.Query} Returns the query, so you can chain this call.
  2212. */
  2213. }, {
  2214. key: "startsWith",
  2215. value: function startsWith(key
  2216. /*: string*/
  2217. , prefix
  2218. /*: string*/
  2219. , modifiers
  2220. /*: string*/
  2221. )
  2222. /*: ParseQuery*/
  2223. {
  2224. if (typeof prefix !== 'string') {
  2225. throw new Error('The value being searched for must be a string.');
  2226. }
  2227. return this.matches(key, this._regexStartWith(prefix), modifiers);
  2228. }
  2229. /**
  2230. * Adds a constraint for finding string values that end with a provided
  2231. * string. This will be slow for large datasets.
  2232. *
  2233. * @param {string} key The key that the string to match is stored in.
  2234. * @param {string} suffix The substring that the value must end with.
  2235. * @param {string} modifiers The regular expression mode.
  2236. * @returns {Parse.Query} Returns the query, so you can chain this call.
  2237. */
  2238. }, {
  2239. key: "endsWith",
  2240. value: function endsWith(key
  2241. /*: string*/
  2242. , suffix
  2243. /*: string*/
  2244. , modifiers
  2245. /*: string*/
  2246. )
  2247. /*: ParseQuery*/
  2248. {
  2249. if (typeof suffix !== 'string') {
  2250. throw new Error('The value being searched for must be a string.');
  2251. }
  2252. return this.matches(key, quote(suffix) + '$', modifiers);
  2253. }
  2254. /**
  2255. * Adds a proximity based constraint for finding objects with key point
  2256. * values near the point given.
  2257. *
  2258. * @param {string} key The key that the Parse.GeoPoint is stored in.
  2259. * @param {Parse.GeoPoint} point The reference Parse.GeoPoint that is used.
  2260. * @returns {Parse.Query} Returns the query, so you can chain this call.
  2261. */
  2262. }, {
  2263. key: "near",
  2264. value: function near(key
  2265. /*: string*/
  2266. , point
  2267. /*: ParseGeoPoint*/
  2268. )
  2269. /*: ParseQuery*/
  2270. {
  2271. if (!(point instanceof _ParseGeoPoint.default)) {
  2272. // Try to cast it as a GeoPoint
  2273. point = new _ParseGeoPoint.default(point);
  2274. }
  2275. return this._addCondition(key, '$nearSphere', point);
  2276. }
  2277. /**
  2278. * Adds a proximity based constraint for finding objects with key point
  2279. * values near the point given and within the maximum distance given.
  2280. *
  2281. * @param {string} key The key that the Parse.GeoPoint is stored in.
  2282. * @param {Parse.GeoPoint} point The reference Parse.GeoPoint that is used.
  2283. * @param {number} maxDistance Maximum distance (in radians) of results to return.
  2284. * @param {boolean} sorted A Bool value that is true if results should be
  2285. * sorted by distance ascending, false is no sorting is required,
  2286. * defaults to true.
  2287. * @returns {Parse.Query} Returns the query, so you can chain this call.
  2288. */
  2289. }, {
  2290. key: "withinRadians",
  2291. value: function withinRadians(key
  2292. /*: string*/
  2293. , point
  2294. /*: ParseGeoPoint*/
  2295. , maxDistance
  2296. /*: number*/
  2297. , sorted
  2298. /*: boolean*/
  2299. )
  2300. /*: ParseQuery*/
  2301. {
  2302. if (sorted || sorted === undefined) {
  2303. this.near(key, point);
  2304. return this._addCondition(key, '$maxDistance', maxDistance);
  2305. } else {
  2306. return this._addCondition(key, '$geoWithin', {
  2307. $centerSphere: [[point.longitude, point.latitude], maxDistance]
  2308. });
  2309. }
  2310. }
  2311. /**
  2312. * Adds a proximity based constraint for finding objects with key point
  2313. * values near the point given and within the maximum distance given.
  2314. * Radius of earth used is 3958.8 miles.
  2315. *
  2316. * @param {string} key The key that the Parse.GeoPoint is stored in.
  2317. * @param {Parse.GeoPoint} point The reference Parse.GeoPoint that is used.
  2318. * @param {number} maxDistance Maximum distance (in miles) of results to return.
  2319. * @param {boolean} sorted A Bool value that is true if results should be
  2320. * sorted by distance ascending, false is no sorting is required,
  2321. * defaults to true.
  2322. * @returns {Parse.Query} Returns the query, so you can chain this call.
  2323. */
  2324. }, {
  2325. key: "withinMiles",
  2326. value: function withinMiles(key
  2327. /*: string*/
  2328. , point
  2329. /*: ParseGeoPoint*/
  2330. , maxDistance
  2331. /*: number*/
  2332. , sorted
  2333. /*: boolean*/
  2334. )
  2335. /*: ParseQuery*/
  2336. {
  2337. return this.withinRadians(key, point, maxDistance / 3958.8, sorted);
  2338. }
  2339. /**
  2340. * Adds a proximity based constraint for finding objects with key point
  2341. * values near the point given and within the maximum distance given.
  2342. * Radius of earth used is 6371.0 kilometers.
  2343. *
  2344. * @param {string} key The key that the Parse.GeoPoint is stored in.
  2345. * @param {Parse.GeoPoint} point The reference Parse.GeoPoint that is used.
  2346. * @param {number} maxDistance Maximum distance (in kilometers) of results to return.
  2347. * @param {boolean} sorted A Bool value that is true if results should be
  2348. * sorted by distance ascending, false is no sorting is required,
  2349. * defaults to true.
  2350. * @returns {Parse.Query} Returns the query, so you can chain this call.
  2351. */
  2352. }, {
  2353. key: "withinKilometers",
  2354. value: function withinKilometers(key
  2355. /*: string*/
  2356. , point
  2357. /*: ParseGeoPoint*/
  2358. , maxDistance
  2359. /*: number*/
  2360. , sorted
  2361. /*: boolean*/
  2362. )
  2363. /*: ParseQuery*/
  2364. {
  2365. return this.withinRadians(key, point, maxDistance / 6371.0, sorted);
  2366. }
  2367. /**
  2368. * Adds a constraint to the query that requires a particular key's
  2369. * coordinates be contained within a given rectangular geographic bounding
  2370. * box.
  2371. *
  2372. * @param {string} key The key to be constrained.
  2373. * @param {Parse.GeoPoint} southwest
  2374. * The lower-left inclusive corner of the box.
  2375. * @param {Parse.GeoPoint} northeast
  2376. * The upper-right inclusive corner of the box.
  2377. * @returns {Parse.Query} Returns the query, so you can chain this call.
  2378. */
  2379. }, {
  2380. key: "withinGeoBox",
  2381. value: function withinGeoBox(key
  2382. /*: string*/
  2383. , southwest
  2384. /*: ParseGeoPoint*/
  2385. , northeast
  2386. /*: ParseGeoPoint*/
  2387. )
  2388. /*: ParseQuery*/
  2389. {
  2390. if (!(southwest instanceof _ParseGeoPoint.default)) {
  2391. southwest = new _ParseGeoPoint.default(southwest);
  2392. }
  2393. if (!(northeast instanceof _ParseGeoPoint.default)) {
  2394. northeast = new _ParseGeoPoint.default(northeast);
  2395. }
  2396. this._addCondition(key, '$within', {
  2397. $box: [southwest, northeast]
  2398. });
  2399. return this;
  2400. }
  2401. /**
  2402. * Adds a constraint to the query that requires a particular key's
  2403. * coordinates be contained within and on the bounds of a given polygon.
  2404. * Supports closed and open (last point is connected to first) paths
  2405. *
  2406. * Polygon must have at least 3 points
  2407. *
  2408. * @param {string} key The key to be constrained.
  2409. * @param {Array} points Array of Coordinates / GeoPoints
  2410. * @returns {Parse.Query} Returns the query, so you can chain this call.
  2411. */
  2412. }, {
  2413. key: "withinPolygon",
  2414. value: function withinPolygon(key
  2415. /*: string*/
  2416. , points
  2417. /*: Array<Array<number>>*/
  2418. )
  2419. /*: ParseQuery*/
  2420. {
  2421. return this._addCondition(key, '$geoWithin', {
  2422. $polygon: points
  2423. });
  2424. }
  2425. /**
  2426. * Add a constraint to the query that requires a particular key's
  2427. * coordinates that contains a ParseGeoPoint
  2428. *
  2429. * @param {string} key The key to be constrained.
  2430. * @param {Parse.GeoPoint} point
  2431. * @returns {Parse.Query} Returns the query, so you can chain this call.
  2432. */
  2433. }, {
  2434. key: "polygonContains",
  2435. value: function polygonContains(key
  2436. /*: string*/
  2437. , point
  2438. /*: ParseGeoPoint*/
  2439. )
  2440. /*: ParseQuery*/
  2441. {
  2442. return this._addCondition(key, '$geoIntersects', {
  2443. $point: point
  2444. });
  2445. }
  2446. /** Query Orderings **/
  2447. /**
  2448. * Sorts the results in ascending order by the given key.
  2449. *
  2450. * @param {(string|string[])} keys The key to order by, which is a
  2451. * string of comma separated values, or an Array of keys, or multiple keys.
  2452. * @returns {Parse.Query} Returns the query, so you can chain this call.
  2453. */
  2454. }, {
  2455. key: "ascending",
  2456. value: function ascending()
  2457. /*: ParseQuery*/
  2458. {
  2459. this._order = [];
  2460. for (var _len = arguments.length, keys = new Array(_len), _key5 = 0; _key5 < _len; _key5++) {
  2461. keys[_key5] = arguments[_key5];
  2462. }
  2463. return this.addAscending.apply(this, keys);
  2464. }
  2465. /**
  2466. * Sorts the results in ascending order by the given key,
  2467. * but can also add secondary sort descriptors without overwriting _order.
  2468. *
  2469. * @param {(string|string[])} keys The key to order by, which is a
  2470. * string of comma separated values, or an Array of keys, or multiple keys.
  2471. * @returns {Parse.Query} Returns the query, so you can chain this call.
  2472. */
  2473. }, {
  2474. key: "addAscending",
  2475. value: function addAscending()
  2476. /*: ParseQuery*/
  2477. {
  2478. var _this9 = this;
  2479. if (!this._order) {
  2480. this._order = [];
  2481. }
  2482. for (var _len2 = arguments.length, keys = new Array(_len2), _key6 = 0; _key6 < _len2; _key6++) {
  2483. keys[_key6] = arguments[_key6];
  2484. }
  2485. (0, _forEach.default)(keys).call(keys, function (key) {
  2486. var _context16;
  2487. if ((0, _isArray.default)(key)) {
  2488. key = key.join();
  2489. }
  2490. _this9._order = (0, _concat.default)(_context16 = _this9._order).call(_context16, key.replace(/\s/g, '').split(','));
  2491. });
  2492. return this;
  2493. }
  2494. /**
  2495. * Sorts the results in descending order by the given key.
  2496. *
  2497. * @param {(string|string[])} keys The key to order by, which is a
  2498. * string of comma separated values, or an Array of keys, or multiple keys.
  2499. * @returns {Parse.Query} Returns the query, so you can chain this call.
  2500. */
  2501. }, {
  2502. key: "descending",
  2503. value: function descending()
  2504. /*: ParseQuery*/
  2505. {
  2506. this._order = [];
  2507. for (var _len3 = arguments.length, keys = new Array(_len3), _key7 = 0; _key7 < _len3; _key7++) {
  2508. keys[_key7] = arguments[_key7];
  2509. }
  2510. return this.addDescending.apply(this, keys);
  2511. }
  2512. /**
  2513. * Sorts the results in descending order by the given key,
  2514. * but can also add secondary sort descriptors without overwriting _order.
  2515. *
  2516. * @param {(string|string[])} keys The key to order by, which is a
  2517. * string of comma separated values, or an Array of keys, or multiple keys.
  2518. * @returns {Parse.Query} Returns the query, so you can chain this call.
  2519. */
  2520. }, {
  2521. key: "addDescending",
  2522. value: function addDescending()
  2523. /*: ParseQuery*/
  2524. {
  2525. var _this10 = this;
  2526. if (!this._order) {
  2527. this._order = [];
  2528. }
  2529. for (var _len4 = arguments.length, keys = new Array(_len4), _key8 = 0; _key8 < _len4; _key8++) {
  2530. keys[_key8] = arguments[_key8];
  2531. }
  2532. (0, _forEach.default)(keys).call(keys, function (key) {
  2533. var _context17, _context18;
  2534. if ((0, _isArray.default)(key)) {
  2535. key = key.join();
  2536. }
  2537. _this10._order = (0, _concat.default)(_context17 = _this10._order).call(_context17, (0, _map2.default)(_context18 = key.replace(/\s/g, '').split(',')).call(_context18, function (k) {
  2538. return '-' + k;
  2539. }));
  2540. });
  2541. return this;
  2542. }
  2543. /** Query Options **/
  2544. /**
  2545. * Sets the number of results to skip before returning any results.
  2546. * This is useful for pagination.
  2547. * Default is to skip zero results.
  2548. *
  2549. * @param {number} n the number of results to skip.
  2550. * @returns {Parse.Query} Returns the query, so you can chain this call.
  2551. */
  2552. }, {
  2553. key: "skip",
  2554. value: function skip(n
  2555. /*: number*/
  2556. )
  2557. /*: ParseQuery*/
  2558. {
  2559. if (typeof n !== 'number' || n < 0) {
  2560. throw new Error('You can only skip by a positive number');
  2561. }
  2562. this._skip = n;
  2563. return this;
  2564. }
  2565. /**
  2566. * Sets the limit of the number of results to return. The default limit is 100.
  2567. *
  2568. * @param {number} n the number of results to limit to.
  2569. * @returns {Parse.Query} Returns the query, so you can chain this call.
  2570. */
  2571. }, {
  2572. key: "limit",
  2573. value: function limit(n
  2574. /*: number*/
  2575. )
  2576. /*: ParseQuery*/
  2577. {
  2578. if (typeof n !== 'number') {
  2579. throw new Error('You can only set the limit to a numeric value');
  2580. }
  2581. this._limit = n;
  2582. return this;
  2583. }
  2584. /**
  2585. * Sets the flag to include with response the total number of objects satisfying this query,
  2586. * despite limits/skip. Might be useful for pagination.
  2587. * Note that result of this query will be wrapped as an object with
  2588. * `results`: holding {ParseObject} array and `count`: integer holding total number
  2589. *
  2590. * @param {boolean} includeCount false - disable, true - enable.
  2591. * @returns {Parse.Query} Returns the query, so you can chain this call.
  2592. */
  2593. }, {
  2594. key: "withCount",
  2595. value: function withCount()
  2596. /*: ParseQuery*/
  2597. {
  2598. var includeCount
  2599. /*: boolean*/
  2600. = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  2601. if (typeof includeCount !== 'boolean') {
  2602. throw new Error('You can only set withCount to a boolean value');
  2603. }
  2604. this._count = includeCount;
  2605. return this;
  2606. }
  2607. /**
  2608. * Includes nested Parse.Objects for the provided key. You can use dot
  2609. * notation to specify which fields in the included object are also fetched.
  2610. *
  2611. * You can include all nested Parse.Objects by passing in '*'.
  2612. * Requires Parse Server 3.0.0+
  2613. * <pre>query.include('*');</pre>
  2614. *
  2615. * @param {...string|Array<string>} keys The name(s) of the key(s) to include.
  2616. * @returns {Parse.Query} Returns the query, so you can chain this call.
  2617. */
  2618. }, {
  2619. key: "include",
  2620. value: function include()
  2621. /*: ParseQuery*/
  2622. {
  2623. var _this11 = this;
  2624. for (var _len5 = arguments.length, keys = new Array(_len5), _key9 = 0; _key9 < _len5; _key9++) {
  2625. keys[_key9] = arguments[_key9];
  2626. }
  2627. (0, _forEach.default)(keys).call(keys, function (key) {
  2628. if ((0, _isArray.default)(key)) {
  2629. var _context19;
  2630. _this11._include = (0, _concat.default)(_context19 = _this11._include).call(_context19, key);
  2631. } else {
  2632. _this11._include.push(key);
  2633. }
  2634. });
  2635. return this;
  2636. }
  2637. /**
  2638. * Includes all nested Parse.Objects one level deep.
  2639. *
  2640. * Requires Parse Server 3.0.0+
  2641. *
  2642. * @returns {Parse.Query} Returns the query, so you can chain this call.
  2643. */
  2644. }, {
  2645. key: "includeAll",
  2646. value: function includeAll()
  2647. /*: ParseQuery*/
  2648. {
  2649. return this.include('*');
  2650. }
  2651. /**
  2652. * Restricts the fields of the returned Parse.Objects to include only the
  2653. * provided keys. If this is called multiple times, then all of the keys
  2654. * specified in each of the calls will be included.
  2655. *
  2656. * @param {...string|Array<string>} keys The name(s) of the key(s) to include.
  2657. * @returns {Parse.Query} Returns the query, so you can chain this call.
  2658. */
  2659. }, {
  2660. key: "select",
  2661. value: function select()
  2662. /*: ParseQuery*/
  2663. {
  2664. var _this12 = this;
  2665. if (!this._select) {
  2666. this._select = [];
  2667. }
  2668. for (var _len6 = arguments.length, keys = new Array(_len6), _key10 = 0; _key10 < _len6; _key10++) {
  2669. keys[_key10] = arguments[_key10];
  2670. }
  2671. (0, _forEach.default)(keys).call(keys, function (key) {
  2672. if ((0, _isArray.default)(key)) {
  2673. var _context20;
  2674. _this12._select = (0, _concat.default)(_context20 = _this12._select).call(_context20, key);
  2675. } else {
  2676. _this12._select.push(key);
  2677. }
  2678. });
  2679. return this;
  2680. }
  2681. /**
  2682. * Restricts the fields of the returned Parse.Objects to all keys except the
  2683. * provided keys. Exclude takes precedence over select and include.
  2684. *
  2685. * Requires Parse Server 3.6.0+
  2686. *
  2687. * @param {...string|Array<string>} keys The name(s) of the key(s) to exclude.
  2688. * @returns {Parse.Query} Returns the query, so you can chain this call.
  2689. */
  2690. }, {
  2691. key: "exclude",
  2692. value: function exclude()
  2693. /*: ParseQuery*/
  2694. {
  2695. var _this13 = this;
  2696. for (var _len7 = arguments.length, keys = new Array(_len7), _key11 = 0; _key11 < _len7; _key11++) {
  2697. keys[_key11] = arguments[_key11];
  2698. }
  2699. (0, _forEach.default)(keys).call(keys, function (key) {
  2700. if ((0, _isArray.default)(key)) {
  2701. var _context21;
  2702. _this13._exclude = (0, _concat.default)(_context21 = _this13._exclude).call(_context21, key);
  2703. } else {
  2704. _this13._exclude.push(key);
  2705. }
  2706. });
  2707. return this;
  2708. }
  2709. /**
  2710. * Changes the read preference that the backend will use when performing the query to the database.
  2711. *
  2712. * @param {string} readPreference The read preference for the main query.
  2713. * @param {string} includeReadPreference The read preference for the queries to include pointers.
  2714. * @param {string} subqueryReadPreference The read preference for the sub queries.
  2715. * @returns {Parse.Query} Returns the query, so you can chain this call.
  2716. */
  2717. }, {
  2718. key: "readPreference",
  2719. value: function readPreference(_readPreference
  2720. /*: string*/
  2721. , includeReadPreference
  2722. /*:: ?: string*/
  2723. , subqueryReadPreference
  2724. /*:: ?: string*/
  2725. )
  2726. /*: ParseQuery*/
  2727. {
  2728. this._readPreference = _readPreference;
  2729. this._includeReadPreference = includeReadPreference;
  2730. this._subqueryReadPreference = subqueryReadPreference;
  2731. return this;
  2732. }
  2733. /**
  2734. * Subscribe this query to get liveQuery updates
  2735. *
  2736. * @param {string} sessionToken (optional) Defaults to the currentUser
  2737. * @returns {Promise<LiveQuerySubscription>} Returns the liveQuerySubscription, it's an event emitter
  2738. * which can be used to get liveQuery updates.
  2739. */
  2740. }, {
  2741. key: "subscribe",
  2742. value: function () {
  2743. var _subscribe = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(sessionToken
  2744. /*:: ?: string*/
  2745. ) {
  2746. var currentUser, liveQueryClient, subscription;
  2747. return _regeneratorRuntime().wrap(function _callee7$(_context22) {
  2748. while (1) {
  2749. switch (_context22.prev = _context22.next) {
  2750. case 0:
  2751. _context22.next = 2;
  2752. return _CoreManager.default.getUserController().currentUserAsync();
  2753. case 2:
  2754. currentUser = _context22.sent;
  2755. if (!sessionToken) {
  2756. sessionToken = currentUser ? currentUser.getSessionToken() : undefined;
  2757. }
  2758. _context22.next = 6;
  2759. return _CoreManager.default.getLiveQueryController().getDefaultLiveQueryClient();
  2760. case 6:
  2761. liveQueryClient = _context22.sent;
  2762. if (liveQueryClient.shouldOpen()) {
  2763. liveQueryClient.open();
  2764. }
  2765. subscription = liveQueryClient.subscribe(this, sessionToken);
  2766. return _context22.abrupt("return", subscription.subscribePromise.then(function () {
  2767. return subscription;
  2768. }));
  2769. case 10:
  2770. case "end":
  2771. return _context22.stop();
  2772. }
  2773. }
  2774. }, _callee7, this);
  2775. }));
  2776. function subscribe(_x10) {
  2777. return _subscribe.apply(this, arguments);
  2778. }
  2779. return subscribe;
  2780. }()
  2781. /**
  2782. * Constructs a Parse.Query that is the OR of the passed in queries. For
  2783. * example:
  2784. * <pre>var compoundQuery = Parse.Query.or(query1, query2, query3);</pre>
  2785. *
  2786. * will create a compoundQuery that is an or of the query1, query2, and
  2787. * query3.
  2788. *
  2789. * @param {...Parse.Query} queries The list of queries to OR.
  2790. * @static
  2791. * @returns {Parse.Query} The query that is the OR of the passed in queries.
  2792. */
  2793. }, {
  2794. key: "fromNetwork",
  2795. value:
  2796. /**
  2797. * Change the source of this query to the server.
  2798. *
  2799. * @returns {Parse.Query} Returns the query, so you can chain this call.
  2800. */
  2801. function fromNetwork()
  2802. /*: ParseQuery*/
  2803. {
  2804. this._queriesLocalDatastore = false;
  2805. this._localDatastorePinName = null;
  2806. return this;
  2807. }
  2808. /**
  2809. * Changes the source of this query to all pinned objects.
  2810. *
  2811. * @returns {Parse.Query} Returns the query, so you can chain this call.
  2812. */
  2813. }, {
  2814. key: "fromLocalDatastore",
  2815. value: function fromLocalDatastore()
  2816. /*: ParseQuery*/
  2817. {
  2818. return this.fromPinWithName(null);
  2819. }
  2820. /**
  2821. * Changes the source of this query to the default group of pinned objects.
  2822. *
  2823. * @returns {Parse.Query} Returns the query, so you can chain this call.
  2824. */
  2825. }, {
  2826. key: "fromPin",
  2827. value: function fromPin()
  2828. /*: ParseQuery*/
  2829. {
  2830. return this.fromPinWithName(_LocalDatastoreUtils.DEFAULT_PIN);
  2831. }
  2832. /**
  2833. * Changes the source of this query to a specific group of pinned objects.
  2834. *
  2835. * @param {string} name The name of query source.
  2836. * @returns {Parse.Query} Returns the query, so you can chain this call.
  2837. */
  2838. }, {
  2839. key: "fromPinWithName",
  2840. value: function fromPinWithName(name
  2841. /*:: ?: string*/
  2842. )
  2843. /*: ParseQuery*/
  2844. {
  2845. var localDatastore = _CoreManager.default.getLocalDatastore();
  2846. if (localDatastore.checkIfEnabled()) {
  2847. this._queriesLocalDatastore = true;
  2848. this._localDatastorePinName = name;
  2849. }
  2850. return this;
  2851. }
  2852. /**
  2853. * Cancels the current network request (if any is running).
  2854. *
  2855. * @returns {Parse.Query} Returns the query, so you can chain this call.
  2856. */
  2857. }, {
  2858. key: "cancel",
  2859. value: function cancel()
  2860. /*: ParseQuery*/
  2861. {
  2862. var _this14 = this;
  2863. if (this._xhrRequest.task && typeof this._xhrRequest.task.abort === 'function') {
  2864. this._xhrRequest.task._aborted = true;
  2865. this._xhrRequest.task.abort();
  2866. this._xhrRequest.task = null;
  2867. this._xhrRequest.onchange = function () {};
  2868. return this;
  2869. }
  2870. return this._xhrRequest.onchange = function () {
  2871. return _this14.cancel();
  2872. };
  2873. }
  2874. }, {
  2875. key: "_setRequestTask",
  2876. value: function _setRequestTask(options) {
  2877. var _this15 = this;
  2878. options.requestTask = function (task) {
  2879. _this15._xhrRequest.task = task;
  2880. _this15._xhrRequest.onchange();
  2881. };
  2882. }
  2883. }], [{
  2884. key: "fromJSON",
  2885. value: function fromJSON(className
  2886. /*: string*/
  2887. , json
  2888. /*: QueryJSON*/
  2889. )
  2890. /*: ParseQuery*/
  2891. {
  2892. var query = new ParseQuery(className);
  2893. return query.withJSON(json);
  2894. }
  2895. }, {
  2896. key: "or",
  2897. value: function or()
  2898. /*: ParseQuery*/
  2899. {
  2900. for (var _len8 = arguments.length, queries = new Array(_len8), _key12 = 0; _key12 < _len8; _key12++) {
  2901. queries[_key12] = arguments[_key12];
  2902. }
  2903. var className = _getClassNameFromQueries(queries);
  2904. var query = new ParseQuery(className);
  2905. query._orQuery(queries);
  2906. return query;
  2907. }
  2908. /**
  2909. * Constructs a Parse.Query that is the AND of the passed in queries. For
  2910. * example:
  2911. * <pre>var compoundQuery = Parse.Query.and(query1, query2, query3);</pre>
  2912. *
  2913. * will create a compoundQuery that is an and of the query1, query2, and
  2914. * query3.
  2915. *
  2916. * @param {...Parse.Query} queries The list of queries to AND.
  2917. * @static
  2918. * @returns {Parse.Query} The query that is the AND of the passed in queries.
  2919. */
  2920. }, {
  2921. key: "and",
  2922. value: function and()
  2923. /*: ParseQuery*/
  2924. {
  2925. for (var _len9 = arguments.length, queries = new Array(_len9), _key13 = 0; _key13 < _len9; _key13++) {
  2926. queries[_key13] = arguments[_key13];
  2927. }
  2928. var className = _getClassNameFromQueries(queries);
  2929. var query = new ParseQuery(className);
  2930. query._andQuery(queries);
  2931. return query;
  2932. }
  2933. /**
  2934. * Constructs a Parse.Query that is the NOR of the passed in queries. For
  2935. * example:
  2936. * <pre>const compoundQuery = Parse.Query.nor(query1, query2, query3);</pre>
  2937. *
  2938. * will create a compoundQuery that is a nor of the query1, query2, and
  2939. * query3.
  2940. *
  2941. * @param {...Parse.Query} queries The list of queries to NOR.
  2942. * @static
  2943. * @returns {Parse.Query} The query that is the NOR of the passed in queries.
  2944. */
  2945. }, {
  2946. key: "nor",
  2947. value: function nor()
  2948. /*: ParseQuery*/
  2949. {
  2950. for (var _len10 = arguments.length, queries = new Array(_len10), _key14 = 0; _key14 < _len10; _key14++) {
  2951. queries[_key14] = arguments[_key14];
  2952. }
  2953. var className = _getClassNameFromQueries(queries);
  2954. var query = new ParseQuery(className);
  2955. query._norQuery(queries);
  2956. return query;
  2957. }
  2958. }]);
  2959. return ParseQuery;
  2960. }();
  2961. var DefaultController = {
  2962. find: function find(className
  2963. /*: string*/
  2964. , params
  2965. /*: QueryJSON*/
  2966. , options
  2967. /*: RequestOptions*/
  2968. )
  2969. /*: Promise<Array<ParseObject>>*/
  2970. {
  2971. var RESTController = _CoreManager.default.getRESTController();
  2972. return RESTController.request('GET', 'classes/' + className, params, options);
  2973. },
  2974. aggregate: function aggregate(className
  2975. /*: string*/
  2976. , params
  2977. /*: any*/
  2978. , options
  2979. /*: RequestOptions*/
  2980. )
  2981. /*: Promise<Array<mixed>>*/
  2982. {
  2983. var RESTController = _CoreManager.default.getRESTController();
  2984. return RESTController.request('GET', 'aggregate/' + className, params, options);
  2985. }
  2986. };
  2987. _CoreManager.default.setQueryController(DefaultController);
  2988. var _default = ParseQuery;
  2989. exports.default = _default;