proto.io 0.0.215 → 0.0.217

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 (48) hide show
  1. package/dist/adapters/file/aliyun-oss.d.ts +3 -3
  2. package/dist/adapters/file/database.d.ts +2 -2
  3. package/dist/adapters/file/database.js +1 -1
  4. package/dist/adapters/file/database.mjs +2 -2
  5. package/dist/adapters/file/filesystem.d.ts +3 -3
  6. package/dist/adapters/file/google-cloud-storage.d.ts +3 -3
  7. package/dist/adapters/storage/progres.d.ts +8 -10
  8. package/dist/adapters/storage/progres.js +833 -451
  9. package/dist/adapters/storage/progres.js.map +1 -1
  10. package/dist/adapters/storage/progres.mjs +834 -452
  11. package/dist/adapters/storage/progres.mjs.map +1 -1
  12. package/dist/client.d.ts +3 -3
  13. package/dist/client.js +1 -7
  14. package/dist/client.js.map +1 -1
  15. package/dist/client.mjs +3 -3
  16. package/dist/client.mjs.map +1 -1
  17. package/dist/index.d.ts +3 -3
  18. package/dist/index.js +9 -16
  19. package/dist/index.js.map +1 -1
  20. package/dist/index.mjs +11 -12
  21. package/dist/index.mjs.map +1 -1
  22. package/dist/internals/{base-Cp5le5dC.d.ts → base-CWnOBKD5.d.ts} +2 -2
  23. package/dist/internals/base-CWnOBKD5.d.ts.map +1 -0
  24. package/dist/internals/{chunk--Vo2-p-z.d.ts → chunk-CNNSQpRF.d.ts} +3 -3
  25. package/dist/internals/chunk-CNNSQpRF.d.ts.map +1 -0
  26. package/dist/internals/{index-CZUGnb-y.d.ts → index-BRIlS3mY.d.ts} +3 -9
  27. package/dist/internals/index-BRIlS3mY.d.ts.map +1 -0
  28. package/dist/internals/{index-YLrO0f2D.d.ts → index-Bs8n7Q8f.d.ts} +60 -20
  29. package/dist/internals/index-Bs8n7Q8f.d.ts.map +1 -0
  30. package/dist/internals/{index-al1N-qi7.mjs → index-BzDsTt4R.mjs} +2 -2
  31. package/dist/internals/{index-al1N-qi7.mjs.map → index-BzDsTt4R.mjs.map} +1 -1
  32. package/dist/internals/{index-ZPbBr9Db.mjs → index-DfqABzjr.mjs} +135 -142
  33. package/dist/internals/index-DfqABzjr.mjs.map +1 -0
  34. package/dist/internals/{index-DfnPpl1I.js → index-DylUjD_1.js} +133 -146
  35. package/dist/internals/index-DylUjD_1.js.map +1 -0
  36. package/dist/internals/{validator-ChrCrz_C.mjs → validator-CEcBF4Cn.mjs} +730 -27
  37. package/dist/internals/validator-CEcBF4Cn.mjs.map +1 -0
  38. package/dist/internals/{validator-m6wY35c6.js → validator-mcBCJP4P.js} +737 -27
  39. package/dist/internals/validator-mcBCJP4P.js.map +1 -0
  40. package/package.json +1 -1
  41. package/dist/internals/base-Cp5le5dC.d.ts.map +0 -1
  42. package/dist/internals/chunk--Vo2-p-z.d.ts.map +0 -1
  43. package/dist/internals/index-CZUGnb-y.d.ts.map +0 -1
  44. package/dist/internals/index-DfnPpl1I.js.map +0 -1
  45. package/dist/internals/index-YLrO0f2D.d.ts.map +0 -1
  46. package/dist/internals/index-ZPbBr9Db.mjs.map +0 -1
  47. package/dist/internals/validator-ChrCrz_C.mjs.map +0 -1
  48. package/dist/internals/validator-m6wY35c6.js.map +0 -1
@@ -1,8 +1,99 @@
1
1
  import _ from 'lodash';
2
- import { T as TObject, l as isPrimitiveValue, m as isValue, _ as _isTypeof, c as isPrimitive, f as isVector, b as isShape, s as shapePaths, a as isRelation, i as isPointer, k as _typeof } from './index-al1N-qi7.mjs';
2
+ import { T as TObject, l as isPrimitiveValue, m as isValue, c as isPrimitive, j as isVector, k as _isTypeof, b as isShape, s as shapePaths, a as isRelation, i as isPointer, h as _typeof } from './index-BzDsTt4R.mjs';
3
3
  import Decimal from 'decimal.js';
4
4
  import { P as PVK } from './private-CNw40LZ7.mjs';
5
5
 
6
+ //
7
+ // expressions.ts
8
+ //
9
+ // The MIT License
10
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
11
+ //
12
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ // of this software and associated documentation files (the "Software"), to deal
14
+ // in the Software without restriction, including without limitation the rights
15
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ // copies of the Software, and to permit persons to whom the Software is
17
+ // furnished to do so, subject to the following conditions:
18
+ //
19
+ // The above copyright notice and this permission notice shall be included in
20
+ // all copies or substantial portions of the Software.
21
+ //
22
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28
+ // THE SOFTWARE.
29
+ //
30
+ const TZeroParamExprKeys = [
31
+ '$now',
32
+ '$rand',
33
+ ];
34
+ const TUnaryExprKeys = [
35
+ '$abs',
36
+ '$neg',
37
+ '$sqrt',
38
+ '$cbrt',
39
+ '$ceil',
40
+ '$floor',
41
+ '$round',
42
+ '$exp',
43
+ '$ln',
44
+ '$log2',
45
+ '$log10',
46
+ '$sin',
47
+ '$cos',
48
+ '$tan',
49
+ '$asin',
50
+ '$acos',
51
+ '$atan',
52
+ '$asinh',
53
+ '$acosh',
54
+ '$atanh',
55
+ '$sinh',
56
+ '$cosh',
57
+ '$tanh',
58
+ '$degrees',
59
+ '$radians',
60
+ '$sign',
61
+ '$size',
62
+ '$lower',
63
+ '$upper',
64
+ ];
65
+ const TBinaryExprKeys = [
66
+ '$divide',
67
+ '$subtract',
68
+ '$log',
69
+ '$pow',
70
+ '$atan2',
71
+ '$trim',
72
+ '$ltrim',
73
+ '$rtrim',
74
+ '$first',
75
+ '$last',
76
+ '$ldrop',
77
+ '$rdrop',
78
+ ];
79
+ const TTernaryExprKeys = [
80
+ '$lpad',
81
+ '$rpad',
82
+ ];
83
+ const TListExprKeys = [
84
+ '$add',
85
+ '$multiply',
86
+ '$ifNull',
87
+ '$concat',
88
+ ];
89
+ const TDistanceExprKeys = [
90
+ '$distance',
91
+ '$innerProduct',
92
+ '$negInnerProduct',
93
+ '$cosineDistance',
94
+ '$rectilinearDistance',
95
+ ];
96
+
6
97
  //
7
98
  // keys.ts
8
99
  //
@@ -49,13 +140,6 @@ const TConditionalKeys = [
49
140
  '$nor',
50
141
  '$or',
51
142
  ];
52
- const TDistanceKeys = [
53
- '$distance',
54
- '$innerProduct',
55
- '$negInnerProduct',
56
- '$cosineDistance',
57
- '$rectilinearDistance',
58
- ];
59
143
 
60
144
  //
61
145
  // utils.ts
@@ -81,7 +165,7 @@ const TDistanceKeys = [
81
165
  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
82
166
  // THE SOFTWARE.
83
167
  //
84
- const isNum = (x) => _.isNumber(x) || x instanceof BigInt || x instanceof Decimal;
168
+ const isNum$1 = (x) => _.isNumber(x) || x instanceof BigInt || x instanceof Decimal;
85
169
  const equalNum = (lhs, rhs) => {
86
170
  if (lhs instanceof Decimal && rhs instanceof Decimal) {
87
171
  return lhs.equals(rhs);
@@ -113,7 +197,7 @@ const lessNum = (lhs, rhs) => {
113
197
  const equal = (lhs, rhs) => {
114
198
  if (_.isNil(lhs) && _.isNil(rhs))
115
199
  return true;
116
- if (isNum(lhs) && isNum(rhs))
200
+ if (isNum$1(lhs) && isNum$1(rhs))
117
201
  return equalNum(lhs, rhs);
118
202
  if (lhs instanceof TObject && rhs instanceof TObject) {
119
203
  if (lhs.className !== rhs.className)
@@ -146,7 +230,7 @@ const lessThan = (lhs, rhs) => {
146
230
  return lhs < rhs;
147
231
  if (_.isDate(lhs) && _.isDate(rhs))
148
232
  return lhs < rhs;
149
- if (isNum(lhs) && isNum(rhs))
233
+ if (isNum$1(lhs) && isNum$1(rhs))
150
234
  return lessNum(lhs, rhs);
151
235
  if (_.isArray(lhs) && _.isArray(rhs)) {
152
236
  for (const i of _.range(Math.min(lhs.length, rhs.length))) {
@@ -225,6 +309,272 @@ const cosine = (v1, v2) => {
225
309
  return _.sumBy(_.zip(v1, v2), ([a, b]) => a * b) / Math.sqrt(s1 * s2);
226
310
  };
227
311
 
312
+ //
313
+ // utils.ts
314
+ //
315
+ // The MIT License
316
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
317
+ //
318
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
319
+ // of this software and associated documentation files (the "Software"), to deal
320
+ // in the Software without restriction, including without limitation the rights
321
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
322
+ // copies of the Software, and to permit persons to whom the Software is
323
+ // furnished to do so, subject to the following conditions:
324
+ //
325
+ // The above copyright notice and this permission notice shall be included in
326
+ // all copies or substantial portions of the Software.
327
+ //
328
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
329
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
330
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
331
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
332
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
333
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
334
+ // THE SOFTWARE.
335
+ //
336
+ const isNum = (x) => _.isNumber(x) || x instanceof Decimal;
337
+ const MathUtils = {
338
+ sum: (lhs, rhs) => {
339
+ if (!isNum(lhs) || !isNum(rhs))
340
+ throw Error('Invalid operation');
341
+ if (lhs instanceof Decimal || rhs instanceof Decimal)
342
+ return Decimal.add(lhs, rhs);
343
+ return lhs + rhs;
344
+ },
345
+ subtract: (lhs, rhs) => {
346
+ if (!isNum(lhs) || !isNum(rhs))
347
+ throw Error('Invalid operation');
348
+ if (lhs instanceof Decimal || rhs instanceof Decimal)
349
+ return Decimal.sub(lhs, rhs);
350
+ return lhs - rhs;
351
+ },
352
+ multiply: (lhs, rhs) => {
353
+ if (!isNum(lhs) || !isNum(rhs))
354
+ throw Error('Invalid operation');
355
+ if (lhs instanceof Decimal || rhs instanceof Decimal)
356
+ return Decimal.mul(lhs, rhs);
357
+ return lhs * rhs;
358
+ },
359
+ divide: (lhs, rhs) => {
360
+ if (!isNum(lhs) || !isNum(rhs))
361
+ throw Error('Invalid operation');
362
+ if (lhs instanceof Decimal || rhs instanceof Decimal)
363
+ return Decimal.div(lhs, rhs);
364
+ return lhs / rhs;
365
+ },
366
+ abs: (lhs) => {
367
+ if (!isNum(lhs))
368
+ throw Error('Invalid operation');
369
+ if (lhs instanceof Decimal)
370
+ return lhs.abs();
371
+ return Math.abs(lhs);
372
+ },
373
+ neg: (lhs) => {
374
+ if (!isNum(lhs))
375
+ throw Error('Invalid operation');
376
+ if (lhs instanceof Decimal)
377
+ return lhs.neg();
378
+ return -lhs;
379
+ },
380
+ ceil: (lhs) => {
381
+ if (!isNum(lhs))
382
+ throw Error('Invalid operation');
383
+ if (lhs instanceof Decimal)
384
+ return lhs.ceil();
385
+ return Math.ceil(lhs);
386
+ },
387
+ floor: (lhs) => {
388
+ if (!isNum(lhs))
389
+ throw Error('Invalid operation');
390
+ if (lhs instanceof Decimal)
391
+ return lhs.floor();
392
+ return Math.floor(lhs);
393
+ },
394
+ round: (lhs) => {
395
+ if (!isNum(lhs))
396
+ throw Error('Invalid operation');
397
+ if (lhs instanceof Decimal)
398
+ return lhs.round();
399
+ return Math.round(lhs);
400
+ },
401
+ exp: (lhs) => {
402
+ if (!isNum(lhs))
403
+ throw Error('Invalid operation');
404
+ if (lhs instanceof Decimal)
405
+ return lhs.exp();
406
+ return Math.exp(lhs);
407
+ },
408
+ sqrt: (lhs) => {
409
+ if (!isNum(lhs))
410
+ throw Error('Invalid operation');
411
+ if (lhs instanceof Decimal)
412
+ return lhs.sqrt();
413
+ return Math.sqrt(lhs);
414
+ },
415
+ cbrt: (lhs) => {
416
+ if (!isNum(lhs))
417
+ throw Error('Invalid operation');
418
+ if (lhs instanceof Decimal)
419
+ return lhs.cbrt();
420
+ return Math.cbrt(lhs);
421
+ },
422
+ mod: (lhs, rhs) => {
423
+ if (!isNum(lhs) || !isNum(rhs))
424
+ throw Error('Invalid operation');
425
+ if (lhs instanceof Decimal || rhs instanceof Decimal)
426
+ return Decimal.mod(lhs, rhs);
427
+ return lhs % rhs;
428
+ },
429
+ pow: (lhs, rhs) => {
430
+ if (!isNum(lhs) || !isNum(rhs))
431
+ throw Error('Invalid operation');
432
+ if (lhs instanceof Decimal || rhs instanceof Decimal)
433
+ return Decimal.pow(lhs, rhs);
434
+ return Math.pow(lhs, rhs);
435
+ },
436
+ log: (lhs, rhs) => {
437
+ if (!isNum(lhs) || !isNum(rhs))
438
+ throw Error('Invalid operation');
439
+ if (lhs instanceof Decimal || rhs instanceof Decimal)
440
+ return Decimal.log(lhs, rhs);
441
+ return Math.log(lhs) / Math.log(rhs);
442
+ },
443
+ log10: (lhs) => {
444
+ if (!isNum(lhs))
445
+ throw Error('Invalid operation');
446
+ if (lhs instanceof Decimal)
447
+ return lhs.log();
448
+ return Math.log10(lhs);
449
+ },
450
+ log2: (lhs) => {
451
+ if (!isNum(lhs))
452
+ throw Error('Invalid operation');
453
+ if (lhs instanceof Decimal)
454
+ return lhs.log(2);
455
+ return Math.log2(lhs);
456
+ },
457
+ ln: (lhs) => {
458
+ if (!isNum(lhs))
459
+ throw Error('Invalid operation');
460
+ if (lhs instanceof Decimal)
461
+ return lhs.ln();
462
+ return Math.log(lhs);
463
+ },
464
+ sin: (lhs) => {
465
+ if (!isNum(lhs))
466
+ throw Error('Invalid operation');
467
+ if (lhs instanceof Decimal)
468
+ return lhs.sin();
469
+ return Math.sin(lhs);
470
+ },
471
+ cos: (lhs) => {
472
+ if (!isNum(lhs))
473
+ throw Error('Invalid operation');
474
+ if (lhs instanceof Decimal)
475
+ return lhs.cos();
476
+ return Math.cos(lhs);
477
+ },
478
+ tan: (lhs) => {
479
+ if (!isNum(lhs))
480
+ throw Error('Invalid operation');
481
+ if (lhs instanceof Decimal)
482
+ return lhs.tan();
483
+ return Math.tan(lhs);
484
+ },
485
+ asin: (lhs) => {
486
+ if (!isNum(lhs))
487
+ throw Error('Invalid operation');
488
+ if (lhs instanceof Decimal)
489
+ return lhs.asin();
490
+ return Math.asin(lhs);
491
+ },
492
+ acos: (lhs) => {
493
+ if (!isNum(lhs))
494
+ throw Error('Invalid operation');
495
+ if (lhs instanceof Decimal)
496
+ return lhs.acos();
497
+ return Math.acos(lhs);
498
+ },
499
+ atan: (lhs) => {
500
+ if (!isNum(lhs))
501
+ throw Error('Invalid operation');
502
+ if (lhs instanceof Decimal)
503
+ return lhs.atan();
504
+ return Math.atan(lhs);
505
+ },
506
+ sinh: (lhs) => {
507
+ if (!isNum(lhs))
508
+ throw Error('Invalid operation');
509
+ if (lhs instanceof Decimal)
510
+ return lhs.sinh();
511
+ return Math.sinh(lhs);
512
+ },
513
+ cosh: (lhs) => {
514
+ if (!isNum(lhs))
515
+ throw Error('Invalid operation');
516
+ if (lhs instanceof Decimal)
517
+ return lhs.cosh();
518
+ return Math.cosh(lhs);
519
+ },
520
+ tanh: (lhs) => {
521
+ if (!isNum(lhs))
522
+ throw Error('Invalid operation');
523
+ if (lhs instanceof Decimal)
524
+ return lhs.tanh();
525
+ return Math.tanh(lhs);
526
+ },
527
+ asinh: (lhs) => {
528
+ if (!isNum(lhs))
529
+ throw Error('Invalid operation');
530
+ if (lhs instanceof Decimal)
531
+ return lhs.asinh();
532
+ return Math.asinh(lhs);
533
+ },
534
+ acosh: (lhs) => {
535
+ if (!isNum(lhs))
536
+ throw Error('Invalid operation');
537
+ if (lhs instanceof Decimal)
538
+ return lhs.acosh();
539
+ return Math.acosh(lhs);
540
+ },
541
+ atanh: (lhs) => {
542
+ if (!isNum(lhs))
543
+ throw Error('Invalid operation');
544
+ if (lhs instanceof Decimal)
545
+ return lhs.atanh();
546
+ return Math.atanh(lhs);
547
+ },
548
+ atan2: (lhs, rhs) => {
549
+ if (!isNum(lhs) || !isNum(rhs))
550
+ throw Error('Invalid operation');
551
+ if (lhs instanceof Decimal || rhs instanceof Decimal)
552
+ return Decimal.atan2(lhs, rhs);
553
+ return Math.atan2(lhs, rhs);
554
+ },
555
+ degrees: (lhs) => {
556
+ if (!isNum(lhs))
557
+ throw Error('Invalid operation');
558
+ if (lhs instanceof Decimal)
559
+ return Decimal.div(Decimal.mul(lhs, 180), Math.PI);
560
+ return (lhs * 180) / Math.PI;
561
+ },
562
+ radians: (lhs) => {
563
+ if (!isNum(lhs))
564
+ throw Error('Invalid operation');
565
+ if (lhs instanceof Decimal)
566
+ return Decimal.div(Decimal.mul(lhs, Math.PI), 180);
567
+ return (lhs * Math.PI) / 180;
568
+ },
569
+ sign: (lhs) => {
570
+ if (!isNum(lhs))
571
+ throw Error('Invalid operation');
572
+ if (lhs instanceof Decimal)
573
+ return Decimal.sign(lhs);
574
+ return Math.sign(lhs);
575
+ },
576
+ };
577
+
228
578
  //
229
579
  // expressions.ts
230
580
  //
@@ -249,6 +599,9 @@ const cosine = (v1, v2) => {
249
599
  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
250
600
  // THE SOFTWARE.
251
601
  //
602
+ const combineNumericTypes = (...list) => {
603
+ return _.some(_.flattenDeep(list), x => x === 'decimal') ? ['decimal'] : ['number'];
604
+ };
252
605
  class QueryExpression {
253
606
  static decode(expr, dollerSign) {
254
607
  const exprs = [];
@@ -257,16 +610,45 @@ class QueryExpression {
257
610
  if (_.includes(TConditionalKeys, key) && _.isArray(query)) {
258
611
  exprs.push(new QueryCoditionalExpression(key, _.map(query, x => QueryExpression.decode(x, dollerSign))));
259
612
  }
613
+ else if (_.includes(TZeroParamExprKeys, key)) {
614
+ exprs.push(new QueryZeroParamExpression(key));
615
+ }
616
+ else if (_.includes(TUnaryExprKeys, key)) {
617
+ exprs.push(new QueryUnaryExpression(key, QueryExpression.decode(query, dollerSign)));
618
+ }
619
+ else if (_.includes(TBinaryExprKeys, key) && _.isArray(query) && query.length === 2) {
620
+ const [left, right] = query;
621
+ exprs.push(new QueryBinaryExpression(key, QueryExpression.decode(left, dollerSign), QueryExpression.decode(right, dollerSign)));
622
+ }
623
+ else if (_.includes(TTernaryExprKeys, key) && _.isArray(query) && query.length === 3) {
624
+ const [first, second, last] = query;
625
+ exprs.push(new QueryTernaryExpression(key, QueryExpression.decode(first, dollerSign), QueryExpression.decode(second, dollerSign), QueryExpression.decode(last, dollerSign)));
626
+ }
627
+ else if (_.includes(TListExprKeys, key) && _.isArray(query)) {
628
+ if (query.length === 0)
629
+ throw Error('Invalid expression');
630
+ exprs.push(new QueryListExpression(key, _.map(query, x => QueryExpression.decode(x, dollerSign))));
631
+ }
260
632
  else if (_.includes(TComparisonKeys, key) && _.isArray(query) && query.length === 2) {
261
633
  const [left, right] = query;
262
634
  exprs.push(new QueryComparisonExpression(key, QueryExpression.decode(left, dollerSign), QueryExpression.decode(right, dollerSign)));
263
635
  }
264
- else if (_.includes(TDistanceKeys, key) && _.isArray(query) && query.length === 2) {
636
+ else if (_.includes(TDistanceExprKeys, key) && _.isArray(query) && query.length === 2) {
265
637
  const [left, right] = query;
266
638
  const _left = _.isArray(left) ? _.map(left, x => QueryExpression.decode(x, dollerSign)) : QueryExpression.decode(left, dollerSign);
267
639
  const _right = _.isArray(right) ? _.map(right, x => QueryExpression.decode(x, dollerSign)) : QueryExpression.decode(right, dollerSign);
268
640
  exprs.push(new QueryDistanceExpression(key, _.castArray(_left), _.castArray(_right)));
269
641
  }
642
+ else if (key === '$cond' && _.isPlainObject(query)) {
643
+ const { branch: _branch, default: defaultCase } = query;
644
+ const branch = _.castArray(_branch ?? []);
645
+ if (branch.length === 0)
646
+ throw Error('Invalid expression');
647
+ exprs.push(new QueryCondExpression(_.map(branch, ({ case: c, then: t }) => ({
648
+ case: QueryExpression.decode(c, dollerSign),
649
+ then: QueryExpression.decode(t, dollerSign),
650
+ })), QueryExpression.decode(defaultCase, dollerSign)));
651
+ }
270
652
  else if (key === '$not') {
271
653
  exprs.push(new QueryNotExpression(QueryExpression.decode(query, dollerSign)));
272
654
  }
@@ -430,6 +812,317 @@ class QueryArrayExpression extends QueryExpression {
430
812
  return ['array'];
431
813
  }
432
814
  }
815
+ class QueryZeroParamExpression extends QueryExpression {
816
+ type;
817
+ constructor(type) {
818
+ super();
819
+ this.type = type;
820
+ }
821
+ eval(value) {
822
+ switch (this.type) {
823
+ case '$now': return new Date();
824
+ case '$rand': return Math.random();
825
+ }
826
+ }
827
+ evalType(schema, className) {
828
+ switch (this.type) {
829
+ case '$now': return ['date'];
830
+ case '$rand': return ['number', 'decimal'];
831
+ }
832
+ }
833
+ }
834
+ class QueryUnaryExpression extends QueryExpression {
835
+ type;
836
+ expr;
837
+ constructor(type, expr) {
838
+ super();
839
+ this.type = type;
840
+ this.expr = expr;
841
+ }
842
+ simplify() {
843
+ return new QueryUnaryExpression(this.type, this.expr.simplify());
844
+ }
845
+ keyPaths() {
846
+ return this.expr.keyPaths();
847
+ }
848
+ mapKey(callback) {
849
+ return new QueryUnaryExpression(this.type, this.expr.mapKey(callback));
850
+ }
851
+ eval(value) {
852
+ switch (this.type) {
853
+ case '$abs': return MathUtils.abs(this.expr.eval(value));
854
+ case '$neg': return MathUtils.neg(this.expr.eval(value));
855
+ case '$sqrt': return MathUtils.sqrt(this.expr.eval(value));
856
+ case '$cbrt': return MathUtils.cbrt(this.expr.eval(value));
857
+ case '$ceil': return MathUtils.ceil(this.expr.eval(value));
858
+ case '$floor': return MathUtils.floor(this.expr.eval(value));
859
+ case '$round': return MathUtils.round(this.expr.eval(value));
860
+ case '$exp': return MathUtils.exp(this.expr.eval(value));
861
+ case '$ln': return MathUtils.ln(this.expr.eval(value));
862
+ case '$log2': return MathUtils.log2(this.expr.eval(value));
863
+ case '$log10': return MathUtils.log10(this.expr.eval(value));
864
+ case '$sin': return MathUtils.sin(this.expr.eval(value));
865
+ case '$cos': return MathUtils.cos(this.expr.eval(value));
866
+ case '$tan': return MathUtils.tan(this.expr.eval(value));
867
+ case '$asin': return MathUtils.asin(this.expr.eval(value));
868
+ case '$acos': return MathUtils.acos(this.expr.eval(value));
869
+ case '$atan': return MathUtils.atan(this.expr.eval(value));
870
+ case '$asinh': return MathUtils.asinh(this.expr.eval(value));
871
+ case '$acosh': return MathUtils.acosh(this.expr.eval(value));
872
+ case '$atanh': return MathUtils.atanh(this.expr.eval(value));
873
+ case '$sinh': return MathUtils.sinh(this.expr.eval(value));
874
+ case '$cosh': return MathUtils.cosh(this.expr.eval(value));
875
+ case '$tanh': return MathUtils.tanh(this.expr.eval(value));
876
+ case '$degrees': return MathUtils.degrees(this.expr.eval(value));
877
+ case '$radians': return MathUtils.radians(this.expr.eval(value));
878
+ case '$sign': return MathUtils.sign(this.expr.eval(value));
879
+ case '$size':
880
+ {
881
+ const v = this.expr.eval(value);
882
+ if (!_.isArray(v) && !_.isString(v))
883
+ throw Error('Invalid value');
884
+ return v.length;
885
+ }
886
+ case '$lower': return _.toLower(this.expr.eval(value));
887
+ case '$upper': return _.toUpper(this.expr.eval(value));
888
+ }
889
+ }
890
+ evalType(schema, className) {
891
+ switch (this.type) {
892
+ case '$abs': return combineNumericTypes(this.expr.evalType(schema, className));
893
+ case '$neg': return combineNumericTypes(this.expr.evalType(schema, className));
894
+ case '$sqrt': return combineNumericTypes(this.expr.evalType(schema, className));
895
+ case '$cbrt': return combineNumericTypes(this.expr.evalType(schema, className));
896
+ case '$ceil': return combineNumericTypes(this.expr.evalType(schema, className));
897
+ case '$floor': return combineNumericTypes(this.expr.evalType(schema, className));
898
+ case '$round': return combineNumericTypes(this.expr.evalType(schema, className));
899
+ case '$exp': return combineNumericTypes(this.expr.evalType(schema, className));
900
+ case '$ln': return combineNumericTypes(this.expr.evalType(schema, className));
901
+ case '$log2': return combineNumericTypes(this.expr.evalType(schema, className));
902
+ case '$log10': return combineNumericTypes(this.expr.evalType(schema, className));
903
+ case '$sin': return combineNumericTypes(this.expr.evalType(schema, className));
904
+ case '$cos': return combineNumericTypes(this.expr.evalType(schema, className));
905
+ case '$tan': return combineNumericTypes(this.expr.evalType(schema, className));
906
+ case '$asin': return combineNumericTypes(this.expr.evalType(schema, className));
907
+ case '$acos': return combineNumericTypes(this.expr.evalType(schema, className));
908
+ case '$atan': return combineNumericTypes(this.expr.evalType(schema, className));
909
+ case '$asinh': return combineNumericTypes(this.expr.evalType(schema, className));
910
+ case '$acosh': return combineNumericTypes(this.expr.evalType(schema, className));
911
+ case '$atanh': return combineNumericTypes(this.expr.evalType(schema, className));
912
+ case '$sinh': return combineNumericTypes(this.expr.evalType(schema, className));
913
+ case '$cosh': return combineNumericTypes(this.expr.evalType(schema, className));
914
+ case '$tanh': return combineNumericTypes(this.expr.evalType(schema, className));
915
+ case '$degrees': return combineNumericTypes(this.expr.evalType(schema, className));
916
+ case '$radians': return combineNumericTypes(this.expr.evalType(schema, className));
917
+ case '$sign': return combineNumericTypes(this.expr.evalType(schema, className));
918
+ case '$size': return ['number'];
919
+ case '$lower': return ['string'];
920
+ case '$upper': return ['string'];
921
+ }
922
+ }
923
+ }
924
+ class QueryBinaryExpression extends QueryExpression {
925
+ type;
926
+ left;
927
+ right;
928
+ constructor(type, left, right) {
929
+ super();
930
+ this.type = type;
931
+ this.left = left;
932
+ this.right = right;
933
+ }
934
+ simplify() {
935
+ return new QueryBinaryExpression(this.type, this.left.simplify(), this.right.simplify());
936
+ }
937
+ keyPaths() {
938
+ return _.uniq([
939
+ ...this.left.keyPaths(),
940
+ ...this.right.keyPaths(),
941
+ ]);
942
+ }
943
+ mapKey(callback) {
944
+ return new QueryBinaryExpression(this.type, this.left.mapKey(callback), this.right.mapKey(callback));
945
+ }
946
+ eval(value) {
947
+ const left = this.left.eval(value);
948
+ const right = this.right?.eval(value);
949
+ switch (this.type) {
950
+ case '$divide': return MathUtils.divide(left, right);
951
+ case '$subtract': return MathUtils.subtract(left, right);
952
+ case '$log': return MathUtils.log(left, right);
953
+ case '$pow': return MathUtils.pow(left, right);
954
+ case '$atan2': return MathUtils.atan2(left, right);
955
+ case '$trim':
956
+ if (!_.isString(left) || !_.isString(right))
957
+ throw Error('Invalid value');
958
+ return _.trim(left, right);
959
+ case '$ltrim':
960
+ if (!_.isString(left) || !_.isString(right))
961
+ throw Error('Invalid value');
962
+ return _.trimStart(left, right);
963
+ case '$rtrim':
964
+ if (!_.isString(left) || !_.isString(right))
965
+ throw Error('Invalid value');
966
+ return _.trimEnd(left, right);
967
+ case '$first':
968
+ if (!_.isArray(left) && !_.isString(left))
969
+ throw Error('Invalid value');
970
+ if (!_.isSafeInteger(right) || right <= 0)
971
+ throw Error('Invalid value');
972
+ return _.isString(left) ? left.slice(0, right) : _.take(left, right);
973
+ case '$last':
974
+ if (!_.isArray(left) && !_.isString(left))
975
+ throw Error('Invalid value');
976
+ if (!_.isSafeInteger(right) || right <= 0)
977
+ throw Error('Invalid value');
978
+ return _.isString(left) ? left.slice(-right) : _.takeRight(left, right);
979
+ case '$ldrop':
980
+ if (!_.isArray(left) && !_.isString(left))
981
+ throw Error('Invalid value');
982
+ if (!_.isSafeInteger(right) || right <= 0)
983
+ throw Error('Invalid value');
984
+ return _.isString(left) ? left.slice(right) : _.drop(left, right);
985
+ case '$rdrop':
986
+ if (!_.isArray(left) && !_.isString(left))
987
+ throw Error('Invalid value');
988
+ if (!_.isSafeInteger(right) || right <= 0)
989
+ throw Error('Invalid value');
990
+ return _.isString(left) ? left.slice(0, -right) : _.dropRight(left, right);
991
+ }
992
+ }
993
+ evalType(schema, className) {
994
+ switch (this.type) {
995
+ case '$divide':
996
+ case '$subtract':
997
+ case '$log':
998
+ case '$pow':
999
+ case '$atan2':
1000
+ return combineNumericTypes(this.left.evalType(schema, className), this.right.evalType(schema, className));
1001
+ case '$trim':
1002
+ case '$ltrim':
1003
+ case '$rtrim':
1004
+ return ['string'];
1005
+ case '$first':
1006
+ case '$last':
1007
+ case '$ldrop':
1008
+ case '$rdrop':
1009
+ return _.intersection(this.left.evalType(schema, className), ['string', 'string[]', 'array']);
1010
+ }
1011
+ }
1012
+ }
1013
+ class QueryTernaryExpression extends QueryExpression {
1014
+ type;
1015
+ first;
1016
+ second;
1017
+ last;
1018
+ constructor(type, first, second, last) {
1019
+ super();
1020
+ this.type = type;
1021
+ this.first = first;
1022
+ this.second = second;
1023
+ this.last = last;
1024
+ }
1025
+ simplify() {
1026
+ return new QueryTernaryExpression(this.type, this.first.simplify(), this.second.simplify(), this.last.simplify());
1027
+ }
1028
+ keyPaths() {
1029
+ return _.uniq([
1030
+ ...this.first.keyPaths(),
1031
+ ...this.second.keyPaths(),
1032
+ ...this.last.keyPaths(),
1033
+ ]);
1034
+ }
1035
+ mapKey(callback) {
1036
+ return new QueryTernaryExpression(this.type, this.first.mapKey(callback), this.second.mapKey(callback), this.last.mapKey(callback));
1037
+ }
1038
+ eval(value) {
1039
+ const first = this.first.eval(value);
1040
+ const second = this.second.eval(value);
1041
+ const last = this.last.eval(value);
1042
+ switch (this.type) {
1043
+ case '$lpad':
1044
+ if (!_.isString(first) || !_.isSafeInteger(second) || !_.isString(last))
1045
+ throw Error('Invalid value');
1046
+ return _.padStart(first, second, last);
1047
+ case '$rpad':
1048
+ if (!_.isString(first) || !_.isSafeInteger(second) || !_.isString(last))
1049
+ throw Error('Invalid value');
1050
+ return _.padEnd(first, second, last);
1051
+ }
1052
+ }
1053
+ evalType(schema, className) {
1054
+ switch (this.type) {
1055
+ case '$lpad':
1056
+ case '$rpad':
1057
+ return ['string'];
1058
+ }
1059
+ }
1060
+ }
1061
+ class QueryListExpression extends QueryExpression {
1062
+ type;
1063
+ exprs;
1064
+ constructor(type, exprs) {
1065
+ super();
1066
+ this.type = type;
1067
+ this.exprs = exprs;
1068
+ }
1069
+ simplify() {
1070
+ return new QueryListExpression(this.type, _.map(this.exprs, x => x.simplify()));
1071
+ }
1072
+ keyPaths() {
1073
+ return _.uniq(_.flatMap(this.exprs, x => x.keyPaths()));
1074
+ }
1075
+ mapKey(callback) {
1076
+ return new QueryListExpression(this.type, _.map(this.exprs, x => x.mapKey(callback)));
1077
+ }
1078
+ eval(value) {
1079
+ switch (this.type) {
1080
+ case '$add': return _.isEmpty(this.exprs) ? undefined : _.reduce(this.exprs, (a, b) => MathUtils.sum(a, b.eval(value)), 0);
1081
+ case '$multiply': return _.isEmpty(this.exprs) ? undefined : _.reduce(this.exprs, (a, b) => MathUtils.multiply(a, b.eval(value)), 1);
1082
+ case '$ifNull': return _.find(_.map(this.exprs, x => x.eval(value)), x => !_.isNil(x));
1083
+ case '$concat': return _.join(_.map(this.exprs, x => x.eval(value)), '');
1084
+ }
1085
+ }
1086
+ evalType(schema, className) {
1087
+ switch (this.type) {
1088
+ case '$add': return combineNumericTypes(..._.map(this.exprs, x => x.evalType(schema, className)));
1089
+ case '$multiply': return combineNumericTypes(..._.map(this.exprs, x => x.evalType(schema, className)));
1090
+ case '$ifNull': return _.intersection(..._.map(this.exprs, x => x.evalType(schema, className)));
1091
+ case '$concat': return ['string'];
1092
+ }
1093
+ }
1094
+ }
1095
+ class QueryCondExpression extends QueryExpression {
1096
+ branch;
1097
+ default;
1098
+ constructor(branch, defaultCase) {
1099
+ super();
1100
+ this.branch = branch;
1101
+ this.default = defaultCase;
1102
+ }
1103
+ simplify() {
1104
+ return new QueryCondExpression(_.map(this.branch, ({ case: c, then: t }) => ({ case: c.simplify(), then: t.simplify() })), this.default.simplify());
1105
+ }
1106
+ keyPaths() {
1107
+ return _.uniq([
1108
+ ..._.flatMap(this.branch, ({ case: c, then: t }) => [...c.keyPaths(), ...t.keyPaths()]),
1109
+ ...this.default.keyPaths(),
1110
+ ]);
1111
+ }
1112
+ mapKey(callback) {
1113
+ return new QueryCondExpression(_.map(this.branch, ({ case: c, then: t }) => ({ case: c.mapKey(callback), then: t.mapKey(callback) })), this.default.mapKey(callback));
1114
+ }
1115
+ eval(value) {
1116
+ for (const { case: c, then: t } of this.branch) {
1117
+ if (c.eval(value))
1118
+ return t.eval(value);
1119
+ }
1120
+ return this.default.eval(value);
1121
+ }
1122
+ evalType(schema, className) {
1123
+ return _.intersection(..._.map(this.branch, ({ then: t }) => t.evalType(schema, className)), this.default.evalType(schema, className));
1124
+ }
1125
+ }
433
1126
  class QueryDistanceExpression extends QueryExpression {
434
1127
  type;
435
1128
  left;
@@ -488,7 +1181,15 @@ class QueryKeyExpression extends QueryExpression {
488
1181
  }
489
1182
  evalType(schema, className) {
490
1183
  const { paths: [, ...subpath], dataType } = resolveColumn(schema, className, this.key);
491
- return _.isEmpty(subpath) ? [dataType] : [];
1184
+ if (!_.isEmpty(subpath))
1185
+ return [];
1186
+ if (_.isString(dataType))
1187
+ return [dataType];
1188
+ if (isPrimitive(dataType))
1189
+ return [dataType.type];
1190
+ if (isVector(dataType))
1191
+ return [_.omit(dataType, 'default')];
1192
+ return [dataType];
492
1193
  }
493
1194
  }
494
1195
  class QueryValueExpression extends QueryExpression {
@@ -510,9 +1211,9 @@ class QueryValueExpression extends QueryExpression {
510
1211
  if (_.isString(this.value))
511
1212
  return ['string'];
512
1213
  if (_.isNumber(this.value))
513
- return ['number', 'decimal'];
1214
+ return ['number'];
514
1215
  if (this.value instanceof Decimal)
515
- return ['decimal', 'number'];
1216
+ return ['decimal'];
516
1217
  return [];
517
1218
  }
518
1219
  }
@@ -834,9 +1535,10 @@ class QueryExpressionSelector extends QuerySelector {
834
1535
  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
835
1536
  // THE SOFTWARE.
836
1537
  //
837
- const accumulatorExprKeys = [
1538
+ const TUnaryAccumulatorKeys = [
838
1539
  '$max',
839
1540
  '$min',
1541
+ '$most',
840
1542
  '$sum',
841
1543
  '$avg',
842
1544
  '$stdDevPop',
@@ -844,7 +1546,7 @@ const accumulatorExprKeys = [
844
1546
  '$varPop',
845
1547
  '$varSamp'
846
1548
  ];
847
- const accumulatorNoParamKeys = [
1549
+ const TZeroParamAccumulatorKeys = [
848
1550
  '$count'
849
1551
  ];
850
1552
 
@@ -875,11 +1577,11 @@ const accumulatorNoParamKeys = [
875
1577
  class QueryAccumulator {
876
1578
  static decode(query) {
877
1579
  for (const [key, expr] of _.toPairs(query)) {
878
- if (_.includes(accumulatorExprKeys, key)) {
879
- return new QueryExprAccumulator(key, QueryExpression.decode(expr ?? [], false));
1580
+ if (_.includes(TUnaryAccumulatorKeys, key)) {
1581
+ return new QueryUnaryAccumulator(key, QueryExpression.decode(expr ?? [], false));
880
1582
  }
881
- else if (_.includes(accumulatorNoParamKeys, key)) {
882
- return new QueryNoParamAccumulator(key);
1583
+ else if (_.includes(TZeroParamAccumulatorKeys, key)) {
1584
+ return new QueryZeroParamAccumulator(key);
883
1585
  }
884
1586
  else if (key === '$percentile') {
885
1587
  const { input, p, mode = 'discrete' } = expr ?? {};
@@ -908,7 +1610,7 @@ class QueryAccumulator {
908
1610
  return;
909
1611
  }
910
1612
  }
911
- class QueryNoParamAccumulator extends QueryAccumulator {
1613
+ class QueryZeroParamAccumulator extends QueryAccumulator {
912
1614
  type;
913
1615
  constructor(type) {
914
1616
  super();
@@ -929,7 +1631,7 @@ class QueryNoParamAccumulator extends QueryAccumulator {
929
1631
  }
930
1632
  }
931
1633
  }
932
- class QueryExprAccumulator extends QueryAccumulator {
1634
+ class QueryUnaryAccumulator extends QueryAccumulator {
933
1635
  type;
934
1636
  expr;
935
1637
  constructor(type, expr) {
@@ -938,13 +1640,13 @@ class QueryExprAccumulator extends QueryAccumulator {
938
1640
  this.expr = expr;
939
1641
  }
940
1642
  simplify() {
941
- return new QueryExprAccumulator(this.type, this.expr.simplify());
1643
+ return new QueryUnaryAccumulator(this.type, this.expr.simplify());
942
1644
  }
943
1645
  keyPaths() {
944
1646
  return this.expr.keyPaths();
945
1647
  }
946
1648
  mapKey(callback) {
947
- return new QueryExprAccumulator(this.type, this.expr.mapKey(callback));
1649
+ return new QueryUnaryAccumulator(this.type, this.expr.mapKey(callback));
948
1650
  }
949
1651
  evalType(schema, className) {
950
1652
  const [dataType] = this.expr.evalType(schema, className);
@@ -953,6 +1655,7 @@ class QueryExprAccumulator extends QueryAccumulator {
953
1655
  switch (this.type) {
954
1656
  case '$max': return _isTypeof(dataType, ['number', 'decimal', 'string', 'date']) ? dataType : undefined;
955
1657
  case '$min': return _isTypeof(dataType, ['number', 'decimal', 'string', 'date']) ? dataType : undefined;
1658
+ case '$most': return _isTypeof(dataType, ['number', 'decimal', 'string', 'date']) ? dataType : undefined;
956
1659
  case '$avg': return _isTypeof(dataType, ['number', 'decimal']) ? dataType : undefined;
957
1660
  case '$sum': return _isTypeof(dataType, ['number', 'decimal']) ? dataType : undefined;
958
1661
  case '$stdDevPop': return _isTypeof(dataType, ['number', 'decimal']) ? dataType : undefined;
@@ -1387,5 +2090,5 @@ class QueryValidator {
1387
2090
  }
1388
2091
  }
1389
2092
 
1390
- export { FieldSelectorExpression as F, QueryValidator as Q, resolveDataType as a, QuerySelector as b, QueryCoditionalSelector as c, QueryFieldSelector as d, QueryExpressionSelector as e, QueryDistanceExpression as f, QueryKeyExpression as g, QueryValueExpression as h, QueryCoditionalExpression as i, QueryComparisonExpression as j, QueryNotExpression as k, QueryArrayExpression as l, QueryNoParamAccumulator as m, QueryExprAccumulator as n, QueryPercentileAccumulator as o, resolveColumn as r };
1391
- //# sourceMappingURL=validator-ChrCrz_C.mjs.map
2093
+ export { FieldSelectorExpression as F, QueryValidator as Q, QueryExpression as a, resolveDataType as b, QuerySelector as c, QueryCoditionalSelector as d, QueryFieldSelector as e, QueryExpressionSelector as f, QueryArrayExpression as g, QueryValueExpression as h, QueryKeyExpression as i, QueryCoditionalExpression as j, QueryComparisonExpression as k, QueryNotExpression as l, QueryDistanceExpression as m, QueryZeroParamExpression as n, QueryUnaryExpression as o, QueryBinaryExpression as p, QueryListExpression as q, resolveColumn as r, QueryTernaryExpression as s, QueryCondExpression as t, QueryZeroParamAccumulator as u, QueryUnaryAccumulator as v, QueryPercentileAccumulator as w };
2094
+ //# sourceMappingURL=validator-CEcBF4Cn.mjs.map