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