OfflineQuery.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
  3. var _Array$isArray2 = require("@babel/runtime-corejs3/core-js-stable/array/is-array");
  4. var _getIteratorMethod = require("@babel/runtime-corejs3/core-js/get-iterator-method");
  5. var _Symbol = require("@babel/runtime-corejs3/core-js-stable/symbol");
  6. var _Array$from = require("@babel/runtime-corejs3/core-js-stable/array/from");
  7. var _sliceInstanceProperty2 = require("@babel/runtime-corejs3/core-js-stable/instance/slice");
  8. var _keys = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/keys"));
  9. var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));
  10. var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
  11. var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
  12. var _typeof2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/typeof"));
  13. var _isInteger = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/number/is-integer"));
  14. var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
  15. var _slice = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/slice"));
  16. var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));
  17. var _isArray = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/is-array"));
  18. var _indexOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/index-of"));
  19. function _createForOfIteratorHelper(o, allowArrayLike) {
  20. var it = typeof _Symbol !== "undefined" && _getIteratorMethod(o) || o["@@iterator"];
  21. if (!it) {
  22. if (_Array$isArray2(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
  23. if (it) o = it;
  24. var i = 0;
  25. var F = function () {};
  26. return {
  27. s: F,
  28. n: function () {
  29. if (i >= o.length) return {
  30. done: true
  31. };
  32. return {
  33. done: false,
  34. value: o[i++]
  35. };
  36. },
  37. e: function (_e) {
  38. throw _e;
  39. },
  40. f: F
  41. };
  42. }
  43. throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  44. }
  45. var normalCompletion = true,
  46. didErr = false,
  47. err;
  48. return {
  49. s: function () {
  50. it = it.call(o);
  51. },
  52. n: function () {
  53. var step = it.next();
  54. normalCompletion = step.done;
  55. return step;
  56. },
  57. e: function (_e2) {
  58. didErr = true;
  59. err = _e2;
  60. },
  61. f: function () {
  62. try {
  63. if (!normalCompletion && it.return != null) it.return();
  64. } finally {
  65. if (didErr) throw err;
  66. }
  67. }
  68. };
  69. }
  70. function _unsupportedIterableToArray(o, minLen) {
  71. var _context6;
  72. if (!o) return;
  73. if (typeof o === "string") return _arrayLikeToArray(o, minLen);
  74. var n = _sliceInstanceProperty2(_context6 = Object.prototype.toString.call(o)).call(_context6, 8, -1);
  75. if (n === "Object" && o.constructor) n = o.constructor.name;
  76. if (n === "Map" || n === "Set") return _Array$from(o);
  77. if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
  78. }
  79. function _arrayLikeToArray(arr, len) {
  80. if (len == null || len > arr.length) len = arr.length;
  81. for (var i = 0, arr2 = new Array(len); i < len; i++) {
  82. arr2[i] = arr[i];
  83. }
  84. return arr2;
  85. }
  86. var equalObjects = require('./equals').default;
  87. var decode = require('./decode').default;
  88. var ParseError = require('./ParseError').default;
  89. var ParsePolygon = require('./ParsePolygon').default;
  90. var ParseGeoPoint = require('./ParseGeoPoint').default;
  91. /**
  92. * contains -- Determines if an object is contained in a list with special handling for Parse pointers.
  93. *
  94. * @param haystack
  95. * @param needle
  96. * @private
  97. * @returns {boolean}
  98. */
  99. function contains(haystack, needle) {
  100. if (needle && needle.__type && (needle.__type === 'Pointer' || needle.__type === 'Object')) {
  101. for (var i in haystack) {
  102. var ptr = haystack[i];
  103. if (typeof ptr === 'string' && ptr === needle.objectId) {
  104. return true;
  105. }
  106. if (ptr.className === needle.className && ptr.objectId === needle.objectId) {
  107. return true;
  108. }
  109. }
  110. return false;
  111. }
  112. return (0, _indexOf.default)(haystack).call(haystack, needle) > -1;
  113. }
  114. function transformObject(object) {
  115. if (object._toFullJSON) {
  116. return object._toFullJSON();
  117. }
  118. return object;
  119. }
  120. /**
  121. * matchesQuery -- Determines if an object would be returned by a Parse Query
  122. * It's a lightweight, where-clause only implementation of a full query engine.
  123. * Since we find queries that match objects, rather than objects that match
  124. * queries, we can avoid building a full-blown query tool.
  125. *
  126. * @param className
  127. * @param object
  128. * @param objects
  129. * @param query
  130. * @private
  131. * @returns {boolean}
  132. */
  133. function matchesQuery(className, object, objects, query) {
  134. if (object.className !== className) {
  135. return false;
  136. }
  137. var obj = object;
  138. var q = query;
  139. if (object.toJSON) {
  140. obj = object.toJSON();
  141. }
  142. if (query.toJSON) {
  143. q = query.toJSON().where;
  144. }
  145. obj.className = className;
  146. for (var field in q) {
  147. if (!matchesKeyConstraints(className, obj, objects, field, q[field])) {
  148. return false;
  149. }
  150. }
  151. return true;
  152. }
  153. function equalObjectsGeneric(obj, compareTo, eqlFn) {
  154. if ((0, _isArray.default)(obj)) {
  155. for (var i = 0; i < obj.length; i++) {
  156. if (eqlFn(obj[i], compareTo)) {
  157. return true;
  158. }
  159. }
  160. return false;
  161. }
  162. return eqlFn(obj, compareTo);
  163. }
  164. /**
  165. * @typedef RelativeTimeToDateResult
  166. * @property {string} status The conversion status, `error` if conversion failed or
  167. * `success` if conversion succeeded.
  168. * @property {string} info The error message if conversion failed, or the relative
  169. * time indication (`past`, `present`, `future`) if conversion succeeded.
  170. * @property {Date|undefined} result The converted date, or `undefined` if conversion
  171. * failed.
  172. */
  173. /**
  174. * Converts human readable relative date string, for example, 'in 10 days' to a date
  175. * relative to now.
  176. *
  177. * @param {string} text The text to convert.
  178. * @param {Date} [now=new Date()] The date from which add or subtract. Default is now.
  179. * @returns {RelativeTimeToDateResult}
  180. */
  181. function relativeTimeToDate(text) {
  182. var now = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Date();
  183. text = text.toLowerCase();
  184. var parts = text.split(' '); // Filter out whitespace
  185. parts = (0, _filter.default)(parts).call(parts, function (part) {
  186. return part !== '';
  187. });
  188. var future = parts[0] === 'in';
  189. var past = parts[parts.length - 1] === 'ago';
  190. if (!future && !past && text !== 'now') {
  191. return {
  192. status: 'error',
  193. info: "Time should either start with 'in' or end with 'ago'"
  194. };
  195. }
  196. if (future && past) {
  197. return {
  198. status: 'error',
  199. info: "Time cannot have both 'in' and 'ago'"
  200. };
  201. } // strip the 'ago' or 'in'
  202. if (future) {
  203. parts = (0, _slice.default)(parts).call(parts, 1);
  204. } else {
  205. // past
  206. parts = (0, _slice.default)(parts).call(parts, 0, parts.length - 1);
  207. }
  208. if (parts.length % 2 !== 0 && text !== 'now') {
  209. return {
  210. status: 'error',
  211. info: 'Invalid time string. Dangling unit or number.'
  212. };
  213. }
  214. var pairs = [];
  215. while (parts.length) {
  216. pairs.push([parts.shift(), parts.shift()]);
  217. }
  218. var seconds = 0;
  219. for (var _i = 0, _pairs = pairs; _i < _pairs.length; _i++) {
  220. var _pairs$_i = (0, _slicedToArray2.default)(_pairs[_i], 2),
  221. num = _pairs$_i[0],
  222. interval = _pairs$_i[1];
  223. var val = Number(num);
  224. if (!(0, _isInteger.default)(val)) {
  225. return {
  226. status: 'error',
  227. info: "'".concat(num, "' is not an integer.")
  228. };
  229. }
  230. switch (interval) {
  231. case 'yr':
  232. case 'yrs':
  233. case 'year':
  234. case 'years':
  235. seconds += val * 31536000; // 365 * 24 * 60 * 60
  236. break;
  237. case 'wk':
  238. case 'wks':
  239. case 'week':
  240. case 'weeks':
  241. seconds += val * 604800; // 7 * 24 * 60 * 60
  242. break;
  243. case 'd':
  244. case 'day':
  245. case 'days':
  246. seconds += val * 86400; // 24 * 60 * 60
  247. break;
  248. case 'hr':
  249. case 'hrs':
  250. case 'hour':
  251. case 'hours':
  252. seconds += val * 3600; // 60 * 60
  253. break;
  254. case 'min':
  255. case 'mins':
  256. case 'minute':
  257. case 'minutes':
  258. seconds += val * 60;
  259. break;
  260. case 'sec':
  261. case 'secs':
  262. case 'second':
  263. case 'seconds':
  264. seconds += val;
  265. break;
  266. default:
  267. return {
  268. status: 'error',
  269. info: "Invalid interval: '".concat(interval, "'")
  270. };
  271. }
  272. }
  273. var milliseconds = seconds * 1000;
  274. if (future) {
  275. return {
  276. status: 'success',
  277. info: 'future',
  278. result: new Date(now.valueOf() + milliseconds)
  279. };
  280. } else if (past) {
  281. return {
  282. status: 'success',
  283. info: 'past',
  284. result: new Date(now.valueOf() - milliseconds)
  285. };
  286. } else {
  287. return {
  288. status: 'success',
  289. info: 'present',
  290. result: new Date(now.valueOf())
  291. };
  292. }
  293. }
  294. /**
  295. * Determines whether an object matches a single key's constraints
  296. *
  297. * @param className
  298. * @param object
  299. * @param objects
  300. * @param key
  301. * @param constraints
  302. * @private
  303. * @returns {boolean}
  304. */
  305. function matchesKeyConstraints(className, object, objects, key, constraints) {
  306. if (constraints === null) {
  307. return false;
  308. }
  309. if ((0, _indexOf.default)(key).call(key, '.') >= 0) {
  310. // Key references a subobject
  311. var keyComponents = key.split('.');
  312. var subObjectKey = keyComponents[0];
  313. var keyRemainder = (0, _slice.default)(keyComponents).call(keyComponents, 1).join('.');
  314. return matchesKeyConstraints(className, object[subObjectKey] || {}, objects, keyRemainder, constraints);
  315. }
  316. var i;
  317. if (key === '$or') {
  318. for (i = 0; i < constraints.length; i++) {
  319. if (matchesQuery(className, object, objects, constraints[i])) {
  320. return true;
  321. }
  322. }
  323. return false;
  324. }
  325. if (key === '$and') {
  326. for (i = 0; i < constraints.length; i++) {
  327. if (!matchesQuery(className, object, objects, constraints[i])) {
  328. return false;
  329. }
  330. }
  331. return true;
  332. }
  333. if (key === '$nor') {
  334. for (i = 0; i < constraints.length; i++) {
  335. if (matchesQuery(className, object, objects, constraints[i])) {
  336. return false;
  337. }
  338. }
  339. return true;
  340. }
  341. if (key === '$relatedTo') {
  342. // Bail! We can't handle relational queries locally
  343. return false;
  344. }
  345. if (!/^[A-Za-z][0-9A-Za-z_]*$/.test(key)) {
  346. throw new ParseError(ParseError.INVALID_KEY_NAME, "Invalid Key: ".concat(key));
  347. } // Equality (or Array contains) cases
  348. if ((0, _typeof2.default)(constraints) !== 'object') {
  349. if ((0, _isArray.default)(object[key])) {
  350. var _context;
  351. return (0, _indexOf.default)(_context = object[key]).call(_context, constraints) > -1;
  352. }
  353. return object[key] === constraints;
  354. }
  355. var compareTo;
  356. if (constraints.__type) {
  357. if (constraints.__type === 'Pointer') {
  358. return equalObjectsGeneric(object[key], constraints, function (obj, ptr) {
  359. return typeof obj !== 'undefined' && ptr.className === obj.className && ptr.objectId === obj.objectId;
  360. });
  361. }
  362. return equalObjectsGeneric(decode(object[key]), decode(constraints), equalObjects);
  363. } // More complex cases
  364. for (var condition in constraints) {
  365. compareTo = constraints[condition];
  366. if (compareTo.__type) {
  367. compareTo = decode(compareTo);
  368. } // is it a $relativeTime? convert to date
  369. if (compareTo['$relativeTime']) {
  370. var parserResult = relativeTimeToDate(compareTo['$relativeTime']);
  371. if (parserResult.status !== 'success') {
  372. var _context2;
  373. throw new ParseError(ParseError.INVALID_JSON, (0, _concat.default)(_context2 = "bad $relativeTime (".concat(key, ") value. ")).call(_context2, parserResult.info));
  374. }
  375. compareTo = parserResult.result;
  376. } // Compare Date Object or Date String
  377. if (toString.call(compareTo) === '[object Date]' || typeof compareTo === 'string' && new Date(compareTo) !== 'Invalid Date' && !isNaN(new Date(compareTo))) {
  378. object[key] = new Date(object[key].iso ? object[key].iso : object[key]);
  379. }
  380. switch (condition) {
  381. case '$lt':
  382. if (object[key] >= compareTo) {
  383. return false;
  384. }
  385. break;
  386. case '$lte':
  387. if (object[key] > compareTo) {
  388. return false;
  389. }
  390. break;
  391. case '$gt':
  392. if (object[key] <= compareTo) {
  393. return false;
  394. }
  395. break;
  396. case '$gte':
  397. if (object[key] < compareTo) {
  398. return false;
  399. }
  400. break;
  401. case '$ne':
  402. if (equalObjects(object[key], compareTo)) {
  403. return false;
  404. }
  405. break;
  406. case '$in':
  407. if (!contains(compareTo, object[key])) {
  408. return false;
  409. }
  410. break;
  411. case '$nin':
  412. if (contains(compareTo, object[key])) {
  413. return false;
  414. }
  415. break;
  416. case '$all':
  417. for (i = 0; i < compareTo.length; i++) {
  418. var _context3;
  419. if ((0, _indexOf.default)(_context3 = object[key]).call(_context3, compareTo[i]) < 0) {
  420. return false;
  421. }
  422. }
  423. break;
  424. case '$exists':
  425. {
  426. var propertyExists = typeof object[key] !== 'undefined';
  427. var existenceIsRequired = constraints['$exists'];
  428. if (typeof constraints['$exists'] !== 'boolean') {
  429. // The SDK will never submit a non-boolean for $exists, but if someone
  430. // tries to submit a non-boolean for $exits outside the SDKs, just ignore it.
  431. break;
  432. }
  433. if (!propertyExists && existenceIsRequired || propertyExists && !existenceIsRequired) {
  434. return false;
  435. }
  436. break;
  437. }
  438. case '$regex':
  439. {
  440. if ((0, _typeof2.default)(compareTo) === 'object') {
  441. return compareTo.test(object[key]);
  442. } // JS doesn't support perl-style escaping
  443. var expString = '';
  444. var escapeEnd = -2;
  445. var escapeStart = (0, _indexOf.default)(compareTo).call(compareTo, '\\Q');
  446. while (escapeStart > -1) {
  447. // Add the unescaped portion
  448. expString += compareTo.substring(escapeEnd + 2, escapeStart);
  449. escapeEnd = (0, _indexOf.default)(compareTo).call(compareTo, '\\E', escapeStart);
  450. if (escapeEnd > -1) {
  451. expString += compareTo.substring(escapeStart + 2, escapeEnd).replace(/\\\\\\\\E/g, '\\E').replace(/\W/g, '\\$&');
  452. }
  453. escapeStart = (0, _indexOf.default)(compareTo).call(compareTo, '\\Q', escapeEnd);
  454. }
  455. expString += compareTo.substring(Math.max(escapeStart, escapeEnd + 2));
  456. var modifiers = constraints.$options || '';
  457. modifiers = modifiers.replace('x', '').replace('s', ''); // Parse Server / Mongo support x and s modifiers but JS RegExp doesn't
  458. var exp = new RegExp(expString, modifiers);
  459. if (!exp.test(object[key])) {
  460. return false;
  461. }
  462. break;
  463. }
  464. case '$nearSphere':
  465. {
  466. if (!compareTo || !object[key]) {
  467. return false;
  468. }
  469. var distance = compareTo.radiansTo(object[key]);
  470. var max = constraints.$maxDistance || Infinity;
  471. return distance <= max;
  472. }
  473. case '$within':
  474. {
  475. if (!compareTo || !object[key]) {
  476. return false;
  477. }
  478. var southWest = compareTo.$box[0];
  479. var northEast = compareTo.$box[1];
  480. if (southWest.latitude > northEast.latitude || southWest.longitude > northEast.longitude) {
  481. // Invalid box, crosses the date line
  482. return false;
  483. }
  484. return object[key].latitude > southWest.latitude && object[key].latitude < northEast.latitude && object[key].longitude > southWest.longitude && object[key].longitude < northEast.longitude;
  485. }
  486. case '$options':
  487. // Not a query type, but a way to add options to $regex. Ignore and
  488. // avoid the default
  489. break;
  490. case '$maxDistance':
  491. // Not a query type, but a way to add a cap to $nearSphere. Ignore and
  492. // avoid the default
  493. break;
  494. case '$select':
  495. {
  496. var subQueryObjects = (0, _filter.default)(objects).call(objects, function (obj, index, arr) {
  497. return matchesQuery(compareTo.query.className, obj, arr, compareTo.query.where);
  498. });
  499. for (var _i2 = 0; _i2 < subQueryObjects.length; _i2 += 1) {
  500. var subObject = transformObject(subQueryObjects[_i2]);
  501. return equalObjects(object[key], subObject[compareTo.key]);
  502. }
  503. return false;
  504. }
  505. case '$dontSelect':
  506. {
  507. var _subQueryObjects = (0, _filter.default)(objects).call(objects, function (obj, index, arr) {
  508. return matchesQuery(compareTo.query.className, obj, arr, compareTo.query.where);
  509. });
  510. for (var _i3 = 0; _i3 < _subQueryObjects.length; _i3 += 1) {
  511. var _subObject = transformObject(_subQueryObjects[_i3]);
  512. return !equalObjects(object[key], _subObject[compareTo.key]);
  513. }
  514. return false;
  515. }
  516. case '$inQuery':
  517. {
  518. var _subQueryObjects2 = (0, _filter.default)(objects).call(objects, function (obj, index, arr) {
  519. return matchesQuery(compareTo.className, obj, arr, compareTo.where);
  520. });
  521. for (var _i4 = 0; _i4 < _subQueryObjects2.length; _i4 += 1) {
  522. var _subObject2 = transformObject(_subQueryObjects2[_i4]);
  523. if (object[key].className === _subObject2.className && object[key].objectId === _subObject2.objectId) {
  524. return true;
  525. }
  526. }
  527. return false;
  528. }
  529. case '$notInQuery':
  530. {
  531. var _subQueryObjects3 = (0, _filter.default)(objects).call(objects, function (obj, index, arr) {
  532. return matchesQuery(compareTo.className, obj, arr, compareTo.where);
  533. });
  534. for (var _i5 = 0; _i5 < _subQueryObjects3.length; _i5 += 1) {
  535. var _subObject3 = transformObject(_subQueryObjects3[_i5]);
  536. if (object[key].className === _subObject3.className && object[key].objectId === _subObject3.objectId) {
  537. return false;
  538. }
  539. }
  540. return true;
  541. }
  542. case '$containedBy':
  543. {
  544. var _iterator = _createForOfIteratorHelper(object[key]),
  545. _step;
  546. try {
  547. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  548. var value = _step.value;
  549. if (!contains(compareTo, value)) {
  550. return false;
  551. }
  552. }
  553. } catch (err) {
  554. _iterator.e(err);
  555. } finally {
  556. _iterator.f();
  557. }
  558. return true;
  559. }
  560. case '$geoWithin':
  561. {
  562. if (compareTo.$polygon) {
  563. var _context4;
  564. var points = (0, _map.default)(_context4 = compareTo.$polygon).call(_context4, function (geoPoint) {
  565. return [geoPoint.latitude, geoPoint.longitude];
  566. });
  567. var polygon = new ParsePolygon(points);
  568. return polygon.containsPoint(object[key]);
  569. }
  570. if (compareTo.$centerSphere) {
  571. var _compareTo$$centerSph = (0, _slicedToArray2.default)(compareTo.$centerSphere, 2),
  572. WGS84Point = _compareTo$$centerSph[0],
  573. maxDistance = _compareTo$$centerSph[1];
  574. var centerPoint = new ParseGeoPoint({
  575. latitude: WGS84Point[1],
  576. longitude: WGS84Point[0]
  577. });
  578. var point = new ParseGeoPoint(object[key]);
  579. var _distance = point.radiansTo(centerPoint);
  580. return _distance <= maxDistance;
  581. }
  582. break;
  583. }
  584. case '$geoIntersects':
  585. {
  586. var _polygon = new ParsePolygon(object[key].coordinates);
  587. var _point = new ParseGeoPoint(compareTo.$point);
  588. return _polygon.containsPoint(_point);
  589. }
  590. default:
  591. return false;
  592. }
  593. }
  594. return true;
  595. }
  596. function validateQuery(query
  597. /*: any*/
  598. ) {
  599. var _context5;
  600. var q = query;
  601. if (query.toJSON) {
  602. q = query.toJSON().where;
  603. }
  604. var specialQuerykeys = ['$and', '$or', '$nor', '_rperm', '_wperm', '_perishable_token', '_email_verify_token', '_email_verify_token_expires_at', '_account_lockout_expires_at', '_failed_login_count'];
  605. (0, _forEach.default)(_context5 = (0, _keys.default)(q)).call(_context5, function (key) {
  606. if (q && q[key] && q[key].$regex) {
  607. if (typeof q[key].$options === 'string') {
  608. if (!q[key].$options.match(/^[imxs]+$/)) {
  609. throw new ParseError(ParseError.INVALID_QUERY, "Bad $options value for query: ".concat(q[key].$options));
  610. }
  611. }
  612. }
  613. if ((0, _indexOf.default)(specialQuerykeys).call(specialQuerykeys, key) < 0 && !key.match(/^[a-zA-Z][a-zA-Z0-9_\.]*$/)) {
  614. throw new ParseError(ParseError.INVALID_KEY_NAME, "Invalid key name: ".concat(key));
  615. }
  616. });
  617. }
  618. var OfflineQuery = {
  619. matchesQuery: matchesQuery,
  620. validateQuery: validateQuery
  621. };
  622. module.exports = OfflineQuery;