@feathersjs/client 5.0.0-pre.0 → 5.0.0-pre.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/CHANGELOG.md +229 -0
  2. package/README.md +2 -2
  3. package/dist/core.d.ts +1 -0
  4. package/dist/core.js +1861 -3627
  5. package/dist/core.js.map +1 -1
  6. package/dist/core.min.js +1 -1
  7. package/dist/feathers.d.ts +8 -0
  8. package/dist/feathers.js +5106 -5755
  9. package/dist/feathers.js.map +1 -1
  10. package/dist/feathers.min.js +1 -1
  11. package/package.json +44 -38
  12. package/src/core.ts +1 -0
  13. package/src/feathers.ts +13 -0
  14. package/.babelrc +0 -8
  15. package/.cache/lasso/default/6a3076a5/dependencyFingerprints/cache +0 -0
  16. package/.cache/lasso/default/6a3076a5/key +0 -1
  17. package/.cache/lasso/default/6a3076a5/lasso-require/inspect-/5d47a286cdceb98f64bf9128488dd355fde40e81/cache +0 -0
  18. package/.cache/lasso/default/7be4a25c/dependencyFingerprints/cache +0 -0
  19. package/.cache/lasso/default/7be4a25c/key +0 -1
  20. package/.cache/lasso/default/7be4a25c/lasso-require/inspect/cache +0 -0
  21. package/.mocha-puppeteer/test-page/@feathersjs/adapter-commons$4.5.0/lib/filter-query.js +0 -1998
  22. package/.mocha-puppeteer/test-page/@feathersjs/adapter-commons$4.5.0/lib/index.js +0 -694
  23. package/.mocha-puppeteer/test-page/@feathersjs/adapter-commons$4.5.0/lib/service.js +0 -1636
  24. package/.mocha-puppeteer/test-page/@feathersjs/adapter-commons$4.5.0/lib/sort.js +0 -2259
  25. package/.mocha-puppeteer/test-page/@feathersjs/adapter-commons$4.5.1/lib/filter-query.js +0 -98
  26. package/.mocha-puppeteer/test-page/@feathersjs/adapter-commons$4.5.1/lib/index.js +0 -37
  27. package/.mocha-puppeteer/test-page/@feathersjs/adapter-commons$4.5.1/lib/service.js +0 -94
  28. package/.mocha-puppeteer/test-page/@feathersjs/adapter-commons$4.5.1/lib/sort.js +0 -112
  29. package/.mocha-puppeteer/test-page/@feathersjs/client$4.5.0/browser/test-run.js +0 -1
  30. package/.mocha-puppeteer/test-page/@feathersjs/client$4.5.0/browser/test.js +0 -1037
  31. package/.mocha-puppeteer/test-page/@feathersjs/client$4.5.0/dist/feathers.js +0 -78377
  32. package/.mocha-puppeteer/test-page/@feathersjs/client$4.5.1/browser/test-run.js +0 -1
  33. package/.mocha-puppeteer/test-page/@feathersjs/client$4.5.1/browser/test.js +0 -102
  34. package/.mocha-puppeteer/test-page/@feathersjs/client$4.5.1/dist/feathers.js +0 -5231
  35. package/.mocha-puppeteer/test-page/@feathersjs/commons$4.5.0/lib/hooks.js +0 -2626
  36. package/.mocha-puppeteer/test-page/@feathersjs/commons$4.5.0/lib/index.js +0 -540
  37. package/.mocha-puppeteer/test-page/@feathersjs/commons$4.5.0/lib/utils.js +0 -1991
  38. package/.mocha-puppeteer/test-page/@feathersjs/commons$4.5.1/lib/hooks.js +0 -170
  39. package/.mocha-puppeteer/test-page/@feathersjs/commons$4.5.1/lib/index.js +0 -17
  40. package/.mocha-puppeteer/test-page/@feathersjs/commons$4.5.1/lib/utils.js +0 -102
  41. package/.mocha-puppeteer/test-page/@feathersjs/errors$4.5.0/lib/index.js +0 -2262
  42. package/.mocha-puppeteer/test-page/@feathersjs/errors$4.5.1/lib/index.js +0 -251
  43. package/.mocha-puppeteer/test-page/@feathersjs/tests$4.5.0/lib/client.js +0 -1506
  44. package/.mocha-puppeteer/test-page/@feathersjs/tests$4.5.1/lib/client.js +0 -83
  45. package/.mocha-puppeteer/test-page/assert$1.5.0/assert.js +0 -508
  46. package/.mocha-puppeteer/test-page/debug$4.1.1/src/browser.js +0 -266
  47. package/.mocha-puppeteer/test-page/debug$4.1.1/src/common.js +0 -268
  48. package/.mocha-puppeteer/test-page/feathers-memory$4.1.0/lib/index.js +0 -143
  49. package/.mocha-puppeteer/test-page/inherits$2.0.1/inherits_browser.js +0 -25
  50. package/.mocha-puppeteer/test-page/lasso-modules-client$2.0.5/src/index.js +0 -592
  51. package/.mocha-puppeteer/test-page/lasso-modules-meta.js +0 -28
  52. package/.mocha-puppeteer/test-page/marko$4.18.35/src/runtime/components/boot-run.js +0 -1
  53. package/.mocha-puppeteer/test-page/marko$4.18.35/src/runtime/components/boot.js +0 -95
  54. package/.mocha-puppeteer/test-page/marko$4.18.42/src/runtime/components/boot-run.js +0 -1
  55. package/.mocha-puppeteer/test-page/marko$4.18.42/src/runtime/components/boot.js +0 -95
  56. package/.mocha-puppeteer/test-page/marko$4.19.0/src/runtime/components/boot-run.js +0 -1
  57. package/.mocha-puppeteer/test-page/marko$4.19.0/src/runtime/components/boot.js +0 -3
  58. package/.mocha-puppeteer/test-page/mocha$3.5.3/mocha.css +0 -326
  59. package/.mocha-puppeteer/test-page/mocha$3.5.3/mocha.js +0 -16590
  60. package/.mocha-puppeteer/test-page/mocha-puppeteer$0.14.0/lib/pages/test-page/run-tests-run.js +0 -1
  61. package/.mocha-puppeteer/test-page/mocha-puppeteer$0.14.0/lib/pages/test-page/run-tests.js +0 -53
  62. package/.mocha-puppeteer/test-page/mocha-puppeteer$0.14.0/lib/pages/test-page/setup-run.js +0 -1
  63. package/.mocha-puppeteer/test-page/mocha-puppeteer$0.14.0/lib/pages/test-page/setup.js +0 -10
  64. package/.mocha-puppeteer/test-page/ms$2.1.2/index.js +0 -164
  65. package/.mocha-puppeteer/test-page/object-assign$4.1.1/index.js +0 -92
  66. package/.mocha-puppeteer/test-page/process$0.11.10/browser.js +0 -186
  67. package/.mocha-puppeteer/test-page/sift$8.5.1/lib/index.js +0 -738
  68. package/.mocha-puppeteer/test-page/superagent$3.8.3/superagent.js +0 -2035
  69. package/.mocha-puppeteer/test-page/util$0.10.3/support/isBufferBrowser.js +0 -7
  70. package/.mocha-puppeteer/test-page/util$0.10.3/util.js +0 -588
  71. package/.nyc_output/coverage.json +0 -1
  72. package/authentication.js +0 -1
  73. package/dist/authentication.js +0 -2242
  74. package/dist/authentication.js.map +0 -1
  75. package/dist/authentication.min.js +0 -1
  76. package/dist/rest.js +0 -3287
  77. package/dist/rest.js.map +0 -1
  78. package/dist/rest.min.js +0 -1
  79. package/dist/socketio.js +0 -2384
  80. package/dist/socketio.js.map +0 -1
  81. package/dist/socketio.min.js +0 -1
  82. package/index.d.ts +0 -23
  83. package/index.js +0 -1
  84. package/rest.js +0 -1
  85. package/socketio.js +0 -1
  86. package/webpack.config.js +0 -69
@@ -1,738 +0,0 @@
1
- $_mod.def("/sift$8.5.1/lib/index", function(require, exports, module, __filename, __dirname) { "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
-
7
- var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
8
-
9
- var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
10
-
11
- exports.default = sift;
12
- exports.compare = compare;
13
- exports.comparable = comparable;
14
- /*
15
- *
16
- * Copryright 2018, Craig Condon
17
- * Licensed under MIT
18
- *
19
- * Filter JavaScript objects with mongodb queries
20
- */
21
-
22
- function typeChecker(type) {
23
- var typeString = "[object " + type + "]";
24
- return function (value) {
25
- return Object.prototype.toString.call(value) === typeString;
26
- };
27
- }
28
-
29
- /**
30
- */
31
-
32
- var isArray = typeChecker("Array");
33
- var isObject = typeChecker("Object");
34
- var isFunction = typeChecker("Function");
35
-
36
- function get(obj, key) {
37
- return isFunction(obj.get) ? obj.get(key) : obj[key];
38
- }
39
-
40
- var nestable = function nestable(validator) {
41
- return function (validateOptions, value, key, valueOwner, nestedResults) {
42
- if (nestedResults) {
43
- return Boolean(nestedResults.find(function (_ref) {
44
- var _ref2 = _slicedToArray(_ref, 3),
45
- value = _ref2[0],
46
- key = _ref2[1],
47
- valueOwner = _ref2[2];
48
-
49
- return validator(validateOptions, key, valueOwner);
50
- }));
51
- }
52
-
53
- return validator(validateOptions, value, key, valueOwner);
54
- };
55
- };
56
-
57
- /**
58
- */
59
-
60
- var or = nestable(function (validator) {
61
- return function (validateOptions, value, key, valueOwner, nestedResults) {
62
- if (!isArray(value) || !value.length) {
63
- return validator(validateOptions, value);
64
- }
65
- for (var i = 0, n = value.length; i < n; i++) {
66
- if (validator(validateOptions, get(value, i))) return true;
67
- }
68
- return false;
69
- };
70
- });
71
-
72
- /**
73
- */
74
-
75
- function and(validator) {
76
- return function (validateOptions, value, key, valueOwner) {
77
- if (!isArray(value) || !value.length) {
78
- return validator(validateOptions, value, key, valueOwner);
79
- }
80
- for (var i = 0, n = value.length; i < n; i++) {
81
- if (!validator(validateOptions, get(value, i), value, valueOwner)) return false;
82
- }
83
- return true;
84
- };
85
- }
86
-
87
- function _validate(validator, value, key, valueOwner, nestedResults) {
88
- return validator.validate(validator.options, value, key, valueOwner, nestedResults);
89
- }
90
-
91
- var defaultExpressions = {
92
- /**
93
- */
94
-
95
- $eq: or(function (test, value) {
96
- return test(value);
97
- }),
98
-
99
- /**
100
- */
101
-
102
- $ne: and(function (test, value) {
103
- return test(value);
104
- }),
105
-
106
- /**
107
- */
108
-
109
- $gt: or(function (test, value) {
110
- return test(value);
111
- }),
112
-
113
- /**
114
- */
115
-
116
- $gte: or(function (test, value) {
117
- return test(value);
118
- }),
119
-
120
- /**
121
- */
122
-
123
- $lt: or(function (test, value) {
124
- return test(value);
125
- }),
126
-
127
- /**
128
- */
129
-
130
- $lte: or(function (test, value) {
131
- return test(value);
132
- }),
133
-
134
- /**
135
- */
136
-
137
- $mod: or(function (test, value) {
138
- return test(value);
139
- }),
140
-
141
- /**
142
- */
143
-
144
- $in: function $in(test, value) {
145
- return test(value);
146
- },
147
-
148
-
149
- /**
150
- */
151
-
152
- $nin: function $nin(test, value) {
153
- return test(value);
154
- },
155
-
156
- /**
157
- */
158
-
159
- $not: function $not(test, value, key, valueOwner) {
160
- return test(value, key, valueOwner);
161
- },
162
-
163
- /**
164
- */
165
-
166
- $type: function $type(testType, value) {
167
- return testType(value);
168
- },
169
-
170
- /**
171
- */
172
-
173
- $all: function $all(allOptions, value, key, valueOwner, nestedResults) {
174
- return defaultExpressions.$and(allOptions, value, key, valueOwner, nestedResults);
175
- },
176
-
177
- /**
178
- */
179
-
180
- $size: function $size(sizeMatch, value) {
181
- return value ? sizeMatch === value.length : false;
182
- },
183
-
184
- /**
185
- */
186
-
187
- $or: function $or(orOptions, value, key, valueOwner) {
188
- for (var i = 0, n = orOptions.length; i < n; i++) {
189
- if (_validate(get(orOptions, i), value, key, valueOwner)) {
190
- return true;
191
- }
192
- }
193
- return false;
194
- },
195
-
196
- /**
197
- */
198
-
199
- $nor: function $nor(validateOptions, value, key, valueOwner) {
200
- return !defaultExpressions.$or(validateOptions, value, key, valueOwner);
201
- },
202
-
203
- /**
204
- */
205
-
206
- $and: function $and(validateOptions, value, key, valueOwner, nestedResults) {
207
-
208
- if (nestedResults) {
209
- for (var i = 0, n = validateOptions.length; i < n; i++) {
210
- if (!_validate(get(validateOptions, i), value, key, valueOwner, nestedResults)) {
211
- return false;
212
- }
213
- }
214
- } else {
215
- for (var i = 0, n = validateOptions.length; i < n; i++) {
216
- if (!_validate(get(validateOptions, i), value, key, valueOwner, nestedResults)) {
217
- return false;
218
- }
219
- }
220
- }
221
- return true;
222
- },
223
-
224
- /**
225
- */
226
-
227
- $regex: or(function (validateOptions, value) {
228
- return typeof value === "string" && validateOptions.test(value);
229
- }),
230
-
231
- /**
232
- */
233
-
234
- $where: function $where(validateOptions, value, key, valueOwner) {
235
- return validateOptions.call(value, value, key, valueOwner);
236
- },
237
-
238
- /**
239
- */
240
-
241
- $elemMatch: function $elemMatch(validateOptions, value, key, valueOwner) {
242
- if (isArray(value)) {
243
- return !!~search(value, validateOptions);
244
- }
245
- return _validate(validateOptions, value, key, valueOwner);
246
- },
247
-
248
- /**
249
- */
250
-
251
- $exists: function $exists(validateOptions, value, key, valueOwner) {
252
- return valueOwner.hasOwnProperty(key) === validateOptions;
253
- }
254
- };
255
-
256
- /**
257
- */
258
-
259
- var prepare = {
260
- /**
261
- */
262
-
263
- $eq: function $eq(query, queryOwner, _ref3) {
264
- var comparable = _ref3.comparable,
265
- compare = _ref3.compare;
266
-
267
- if (query instanceof RegExp) {
268
- return or(function (value) {
269
- return typeof value === "string" && query.test(value);
270
- });
271
- } else if (query instanceof Function) {
272
- return or(query);
273
- } else if (isArray(query) && !query.length) {
274
- // Special case of a == []
275
- return or(function (value) {
276
- return isArray(value) && !value.length;
277
- });
278
- } else if (query === null) {
279
- return or(function (value) {
280
- //will match both null and undefined
281
- return value == null;
282
- });
283
- }
284
- return or(function (value) {
285
- return compare(comparable(value), comparable(query)) === 0;
286
- });
287
- },
288
-
289
- $gt: function $gt(query, queryOwner, _ref4) {
290
- var comparable = _ref4.comparable,
291
- compare = _ref4.compare;
292
-
293
- return function (value) {
294
- return compare(comparable(value), comparable(query)) > 0;
295
- };
296
- },
297
-
298
- $gte: function $gte(query, queryOwner, _ref5) {
299
- var comparable = _ref5.comparable,
300
- compare = _ref5.compare;
301
-
302
- return function (value) {
303
- return compare(comparable(value), comparable(query)) >= 0;
304
- };
305
- },
306
-
307
- $lt: function $lt(query, queryOwner, _ref6) {
308
- var comparable = _ref6.comparable,
309
- compare = _ref6.compare;
310
-
311
- return function (value) {
312
- return compare(comparable(value), comparable(query)) < 0;
313
- };
314
- },
315
- $lte: function $lte(query, queryOwner, _ref7) {
316
- var comparable = _ref7.comparable,
317
- compare = _ref7.compare;
318
-
319
- return function (value) {
320
- return compare(comparable(value), comparable(query)) <= 0;
321
- };
322
- },
323
-
324
- $in: function $in(query, queryOwner, options) {
325
- var comparable = options.comparable;
326
-
327
- return function (value) {
328
- if (value instanceof Array) {
329
- for (var i = value.length; i--;) {
330
- if (~query.indexOf(comparable(get(value, i)))) {
331
- return true;
332
- }
333
- }
334
- } else {
335
- var comparableValue = comparable(value);
336
- if (comparableValue === value && (typeof value === "undefined" ? "undefined" : _typeof(value)) === "object") {
337
- for (var i = query.length; i--;) {
338
- if (String(query[i]) === String(value) && String(value) !== "[object Object]") {
339
- return true;
340
- }
341
- }
342
- }
343
-
344
- /*
345
- Handles documents that are undefined, whilst also
346
- having a 'null' element in the parameters to $in.
347
- */
348
- if (typeof comparableValue == "undefined") {
349
- for (var i = query.length; i--;) {
350
- if (query[i] == null) {
351
- return true;
352
- }
353
- }
354
- }
355
-
356
- /*
357
- Handles the case of {'field': {$in: [/regexp1/, /regexp2/, ...]}}
358
- */
359
- for (var i = query.length; i--;) {
360
- var validator = createRootValidator(get(query, i), options);
361
- var result = _validate(validator, comparableValue, i, query);
362
- if (result && String(result) !== "[object Object]" && String(comparableValue) !== "[object Object]") {
363
- return true;
364
- }
365
- }
366
-
367
- return !!~query.indexOf(comparableValue);
368
- }
369
-
370
- return false;
371
- };
372
- },
373
-
374
- $nin: function $nin(query, queryOwner, options) {
375
- var eq = prepare.$in(query, queryOwner, options);
376
- return function (validateOptions, value, key, valueOwner) {
377
- return !eq(validateOptions, value, key, valueOwner);
378
- };
379
- },
380
-
381
- $mod: function $mod(query) {
382
- return function (value) {
383
- return value % query[0] == query[1];
384
- };
385
- },
386
-
387
- /**
388
- */
389
-
390
- $ne: function $ne(query, queryOwner, options) {
391
- var eq = prepare.$eq(query, queryOwner, options);
392
- return and(function (validateOptions, value, key, valueOwner) {
393
- return !eq(validateOptions, value, key, valueOwner);
394
- });
395
- },
396
-
397
- /**
398
- */
399
-
400
- $and: function $and(query, queryOwner, options) {
401
- return query.map(parse(options));
402
- },
403
-
404
- /**
405
- */
406
-
407
- $all: function $all(query, queryOwner, options) {
408
- return prepare.$and(query, queryOwner, options);
409
- },
410
-
411
- /**
412
- */
413
-
414
- $or: function $or(query, queryOwner, options) {
415
- return query.map(parse(options));
416
- },
417
-
418
- /**
419
- */
420
-
421
- $nor: function $nor(query, queryOwner, options) {
422
- return query.map(parse(options));
423
- },
424
-
425
- /**
426
- */
427
-
428
- $not: function $not(query, queryOwner, options) {
429
- var validateOptions = parse(options)(query);
430
- return function (value, key, valueOwner) {
431
- return !_validate(validateOptions, value, key, valueOwner);
432
- };
433
- },
434
-
435
- $type: function $type(query) {
436
- return function (value, key, valueOwner) {
437
- return value != void 0 ? value instanceof query || value.constructor == query : false;
438
- };
439
- },
440
-
441
- /**
442
- */
443
-
444
- $regex: function $regex(query, queryOwner) {
445
- return new RegExp(query, queryOwner.$options);
446
- },
447
-
448
- /**
449
- */
450
-
451
- $where: function $where(query) {
452
- return typeof query === "string" ? new Function("obj", "return " + query) : query;
453
- },
454
-
455
- /**
456
- */
457
-
458
- $elemMatch: function $elemMatch(query, queryOwner, options) {
459
- return parse(options)(query);
460
- },
461
-
462
- /**
463
- */
464
-
465
- $exists: function $exists(query) {
466
- return !!query;
467
- }
468
- };
469
-
470
- /**
471
- */
472
-
473
- function search(array, validator) {
474
- for (var i = 0; i < array.length; i++) {
475
- var result = get(array, i);
476
- if (_validate(validator, get(array, i))) {
477
- return i;
478
- }
479
- }
480
-
481
- return -1;
482
- }
483
-
484
- /**
485
- */
486
-
487
- function createValidator(options, validate) {
488
- return { options: options, validate: validate };
489
- }
490
-
491
- /**
492
- */
493
-
494
- function validatedNested(_ref8, value) {
495
- var keyPath = _ref8.keyPath,
496
- child = _ref8.child,
497
- query = _ref8.query;
498
-
499
- var results = [];
500
- findValues(value, keyPath, 0, value, results);
501
-
502
- if (results.length === 1) {
503
- var _results$ = _slicedToArray(results[0], 3),
504
- _value = _results$[0],
505
- key = _results$[1],
506
- valueOwner = _results$[2];
507
-
508
- return _validate(child, _value, key, valueOwner);
509
- }
510
-
511
- // If the query contains $ne, need to test all elements ANDed together
512
- var inclusive = query && typeof query.$ne !== "undefined";
513
- var allValid = inclusive;
514
- var allValues = results.map(function (_ref9) {
515
- var _ref10 = _slicedToArray(_ref9, 1),
516
- value = _ref10[0];
517
-
518
- return value;
519
- });
520
-
521
- return _validate(child, undefined, undefined, undefined, results);
522
- // for (var i = 0; i < results.length; i++) {
523
- // const [value, key, valueOwner] = results[i];
524
- // var isValid = validate(child, value, key, valueOwner);
525
- // console.log(isValid, value);
526
- // if (inclusive) {
527
- // allValid &= isValid;
528
- // } else {
529
- // allValid |= isValid;
530
- // }
531
- // }
532
- // return allValid;
533
- }
534
-
535
- /**
536
- */
537
-
538
- function findValues(current, keypath, index, object, values) {
539
- if (index === keypath.length || current == void 0) {
540
- values.push([current, keypath[index - 1], object]);
541
- return;
542
- }
543
-
544
- var k = get(keypath, index);
545
-
546
- // ensure that if current is an array, that the current key
547
- // is NOT an array index. This sort of thing needs to work:
548
- // sift({'foo.0':42}, [{foo: [42]}]);
549
- if (isArray(current) && isNaN(Number(k))) {
550
- for (var i = 0, n = current.length; i < n; i++) {
551
- findValues(get(current, i), keypath, index, current, values);
552
- }
553
- } else {
554
- findValues(get(current, k), keypath, index + 1, current, values);
555
- }
556
- }
557
-
558
- /**
559
- */
560
-
561
- function createNestedValidator(keyPath, child, query) {
562
- return createValidator({ keyPath: keyPath, child: child, query: query }, validatedNested);
563
- }
564
-
565
- /**
566
- * flatten the query
567
- */
568
-
569
- function isVanillaObject(value) {
570
- return value && (value.constructor === Object || value.constructor === Array || value.constructor.toString() === "function Object() { [native code] }" || value.constructor.toString() === "function Array() { [native code] }");
571
- }
572
-
573
- function parse(options) {
574
- var comparable = options.comparable,
575
- expressions = options.expressions;
576
-
577
- var wrapQuery = function wrapQuery(query) {
578
- if (!query || !isVanillaObject(query)) {
579
- query = { $eq: query };
580
- }
581
- return query;
582
- };
583
-
584
- var parseQuery = function parseQuery(query) {
585
- query = comparable(query);
586
-
587
- var validators = [];
588
-
589
- for (var key in query) {
590
- var queryValue = query[key];
591
-
592
- if (key === "$options") {
593
- continue;
594
- }
595
-
596
- var expression = defaultExpressions[key] || options && expressions && expressions[key];
597
-
598
- if (expression) {
599
- if (prepare[key]) {
600
- queryValue = prepare[key](queryValue, query, options);
601
- }
602
- validators.push(createValidator(comparable(queryValue), expression));
603
- } else {
604
- if (key.charCodeAt(0) === 36) {
605
- throw new Error("Unknown operation " + key);
606
- }
607
-
608
- var keyParts = key.split(".");
609
-
610
- validators.push(createNestedValidator(keyParts, parseNested(queryValue), queryValue));
611
- }
612
- }
613
-
614
- return validators.length === 1 ? validators[0] : createValidator(validators, defaultExpressions.$and);
615
- };
616
-
617
- var parseNested = function parseNested(query) {
618
- query = wrapQuery(query);
619
- if (isExactObject(query)) {
620
- return createValidator(query, isEqual);
621
- }
622
- return parseQuery(query);
623
- };
624
-
625
- var parseRoot = function parseRoot(query) {
626
- return parseQuery(wrapQuery(query));
627
- };
628
-
629
- return parseRoot;
630
- }
631
-
632
- function isEqual(a, b) {
633
- if (Object.prototype.toString.call(a) !== Object.prototype.toString.call(b)) {
634
- return false;
635
- }
636
-
637
- if (isObject(a)) {
638
- if (Object.keys(a).length !== Object.keys(b).length) {
639
- return false;
640
- }
641
-
642
- for (var key in a) {
643
- if (!isEqual(a[key], b[key])) {
644
- return false;
645
- }
646
- }
647
-
648
- return true;
649
- } else if (isArray(a)) {
650
- if (a.length !== b.length) {
651
- return false;
652
- }
653
- for (var i = 0, n = a.length; i < n; i++) {
654
- if (!isEqual(a[i], b[i])) {
655
- return false;
656
- }
657
- }
658
-
659
- return true;
660
- } else {
661
- return a === b;
662
- }
663
- }
664
-
665
- function getAllKeys(value, keys) {
666
- if (!isObject(value)) {
667
- return keys;
668
- }
669
- for (var key in value) {
670
- keys.push(key);
671
- getAllKeys(value[key], keys);
672
- }
673
- return keys;
674
- }
675
-
676
- function isExactObject(value) {
677
- var allKeysHash = getAllKeys(value, []).join(",");
678
- return allKeysHash.search(/[$.]/) === -1;
679
- }
680
-
681
- /**
682
- */
683
-
684
- function createRootValidator(query, options) {
685
- var validator = parse(options)(query);
686
- if (options && options.select) {
687
- validator = {
688
- options: validator,
689
- validate: function validate(validateOptions, value, key, valueOwner) {
690
- return _validate(validateOptions, value && options.select(value), key, valueOwner);
691
- }
692
- };
693
- }
694
- return validator;
695
- }
696
-
697
- /**
698
- */
699
-
700
- function sift(query, options) {
701
- options = Object.assign({ compare: compare, comparable: comparable }, options);
702
- var validator = createRootValidator(query, options);
703
- return function (value, key, valueOwner) {
704
- return _validate(validator, value, key, valueOwner);
705
- };
706
- }
707
-
708
- /**
709
- */
710
-
711
- function compare(a, b) {
712
- if (isEqual(a, b)) return 0;
713
- if ((typeof a === "undefined" ? "undefined" : _typeof(a)) === (typeof b === "undefined" ? "undefined" : _typeof(b))) {
714
- if (a > b) {
715
- return 1;
716
- }
717
- if (a < b) {
718
- return -1;
719
- }
720
- }
721
- }
722
-
723
- /**
724
- */
725
-
726
- function comparable(value) {
727
- if (value instanceof Date) {
728
- return value.getTime();
729
- } else if (isArray(value)) {
730
- return value.map(comparable);
731
- } else if (value && typeof value.toJSON === "function") {
732
- return value.toJSON();
733
- } else {
734
- return value;
735
- }
736
- }
737
-
738
- });