OfflineQuery.js 22 KB

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