3xpr 1.14.1 → 1.15.1
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/README.md +18 -18
- package/expression/application/expressions.d.ts +4 -3
- package/expression/application/expressions.js +8 -4
- package/expression/application/expressions.js.map +1 -1
- package/expression/application/index.d.ts +2 -2
- package/expression/application/index.js +2 -2
- package/expression/application/useCases/convert.js.map +1 -1
- package/expression/application/useCases/{evaluate.d.ts → executor.d.ts} +3 -2
- package/expression/application/useCases/executor.js +23 -0
- package/expression/application/useCases/executor.js.map +1 -0
- package/expression/application/useCases/{evaluateObserveDecorator.d.ts → executorObserveDecorator.d.ts} +5 -4
- package/expression/application/useCases/{evaluateObserveDecorator.js → executorObserveDecorator.js} +20 -8
- package/expression/application/useCases/executorObserveDecorator.js.map +1 -0
- package/expression/domain/expressions.d.ts +4 -3
- package/expression/infrastructure/convertFrom/convertFromFunction.js.map +1 -1
- package/expression/infrastructure/convertFrom/convertFromGraphql.js.map +1 -1
- package/expression/infrastructure/expressionsBuilder.js +3 -3
- package/expression/infrastructure/expressionsBuilder.js.map +1 -1
- package/expression/infrastructure/helper.js.map +1 -1
- package/expression/infrastructure/library.js +462 -19
- package/expression/infrastructure/library.js.map +1 -1
- package/model/application/modelService.js +4 -2
- package/model/application/modelService.js.map +1 -1
- package/operand/application/facade.js +4 -4
- package/operand/application/facade.js.map +1 -1
- package/operand/application/services/builderCacheDecorator.js.map +1 -1
- package/operand/application/services/factory.js.map +1 -1
- package/operand/application/services/normalizer.js.map +1 -1
- package/operand/application/services/parameterService.js.map +1 -1
- package/operand/application/services/parser.js.map +1 -1
- package/operand/application/services/serializer.js.map +1 -1
- package/operand/application/services/typeService.js.map +1 -1
- package/operand/application/useCases/build.js +1 -1
- package/operand/application/useCases/build.js.map +1 -1
- package/operand/application/useCases/clone.js.map +1 -1
- package/operand/application/useCases/complete.js.map +1 -1
- package/operand/application/useCases/normalize.js.map +1 -1
- package/operand/application/useCases/reduce.js.map +1 -1
- package/operand/domain/entities.d.ts +7 -0
- package/operand/domain/entities.js +14 -0
- package/operand/domain/entities.js.map +1 -1
- package/operand/infrastructure/constBuilder.js +2 -2
- package/operand/infrastructure/constBuilder.js.map +1 -1
- package/operand/infrastructure/{evaluators/sync.d.ts → executors/expression.d.ts} +11 -1
- package/operand/infrastructure/{evaluators/sync.js → executors/expression.js} +142 -7
- package/operand/infrastructure/executors/expression.js.map +1 -0
- package/operand/infrastructure/{evaluators/async.d.ts → executors/task.d.ts} +1 -1
- package/operand/infrastructure/{evaluators/async.js → executors/task.js} +96 -87
- package/operand/infrastructure/executors/task.js.map +1 -0
- package/operand/infrastructure/facadeBuilder.js +7 -6
- package/operand/infrastructure/facadeBuilder.js.map +1 -1
- package/operand/infrastructure/helper.js.map +1 -1
- package/package.json +5 -5
- package/shared/domain/context.js.map +1 -1
- package/shared/domain/operand.d.ts +4 -0
- package/shared/domain/operand.js +15 -0
- package/shared/domain/operand.js.map +1 -1
- package/expression/application/useCases/evaluate.js +0 -19
- package/expression/application/useCases/evaluate.js.map +0 -1
- package/expression/application/useCases/evaluateObserveDecorator.js.map +0 -1
- package/operand/infrastructure/evaluators/async.js.map +0 -1
- package/operand/infrastructure/evaluators/sync.js.map +0 -1
|
@@ -90,10 +90,9 @@ class CoreLibrary {
|
|
|
90
90
|
model.addOperator('>>=(a:number,b:number):number', new AssignmentRightShift(), { priority: 1 });
|
|
91
91
|
}
|
|
92
92
|
generalFunctions(model) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
// })
|
|
93
|
+
model.addFunction('sleep(ms?: number):void', async (ms = 0) => {
|
|
94
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
95
|
+
}, { async: true });
|
|
97
96
|
model.addFunction('console(value:any):void', (value) => {
|
|
98
97
|
console.log(typeof value === 'object' ? JSON.stringify(value) : value);
|
|
99
98
|
});
|
|
@@ -422,6 +421,14 @@ class And extends domain_2.PrototypeEvaluator {
|
|
|
422
421
|
return false;
|
|
423
422
|
return this.operand.children[1].eval(context);
|
|
424
423
|
}
|
|
424
|
+
async evalAsync(context) {
|
|
425
|
+
if (this.operand === undefined) {
|
|
426
|
+
throw new Error('Operand undefined');
|
|
427
|
+
}
|
|
428
|
+
if (!(await this.operand.children[0].solve(context)))
|
|
429
|
+
return false;
|
|
430
|
+
return await this.operand.children[1].solve(context);
|
|
431
|
+
}
|
|
425
432
|
}
|
|
426
433
|
class Or extends domain_2.PrototypeEvaluator {
|
|
427
434
|
clone(operand) {
|
|
@@ -435,6 +442,14 @@ class Or extends domain_2.PrototypeEvaluator {
|
|
|
435
442
|
return true;
|
|
436
443
|
return this.operand.children[1].eval(context);
|
|
437
444
|
}
|
|
445
|
+
async evalAsync(context) {
|
|
446
|
+
if (this.operand === undefined) {
|
|
447
|
+
throw new Error('Operand undefined');
|
|
448
|
+
}
|
|
449
|
+
if (await this.operand.children[0].solve(context))
|
|
450
|
+
return true;
|
|
451
|
+
return await this.operand.children[1].solve(context);
|
|
452
|
+
}
|
|
438
453
|
}
|
|
439
454
|
class Assignment extends domain_2.PrototypeEvaluator {
|
|
440
455
|
clone(operand) {
|
|
@@ -448,6 +463,14 @@ class Assignment extends domain_2.PrototypeEvaluator {
|
|
|
448
463
|
context.data.set(this.operand.children[0].name, value);
|
|
449
464
|
return value;
|
|
450
465
|
}
|
|
466
|
+
async evalAsync(context) {
|
|
467
|
+
if (this.operand === undefined) {
|
|
468
|
+
throw new Error('Operand undefined');
|
|
469
|
+
}
|
|
470
|
+
const value = await this.operand.children[1].solve(context);
|
|
471
|
+
context.data.set(this.operand.children[0].name, value);
|
|
472
|
+
return value;
|
|
473
|
+
}
|
|
451
474
|
}
|
|
452
475
|
class AssignmentAddition extends domain_2.PrototypeEvaluator {
|
|
453
476
|
clone(operand) {
|
|
@@ -461,6 +484,14 @@ class AssignmentAddition extends domain_2.PrototypeEvaluator {
|
|
|
461
484
|
context.data.set(this.operand.children[0].name, value);
|
|
462
485
|
return value;
|
|
463
486
|
}
|
|
487
|
+
async evalAsync(context) {
|
|
488
|
+
if (this.operand === undefined) {
|
|
489
|
+
throw new Error('Operand undefined');
|
|
490
|
+
}
|
|
491
|
+
const value = (await this.operand.children[0].solve(context)) + (await this.operand.children[1].solve(context));
|
|
492
|
+
context.data.set(this.operand.children[0].name, value);
|
|
493
|
+
return value;
|
|
494
|
+
}
|
|
464
495
|
}
|
|
465
496
|
class AssignmentSubtraction extends domain_2.PrototypeEvaluator {
|
|
466
497
|
clone(operand) {
|
|
@@ -474,6 +505,14 @@ class AssignmentSubtraction extends domain_2.PrototypeEvaluator {
|
|
|
474
505
|
context.data.set(this.operand.children[0].name, value);
|
|
475
506
|
return value;
|
|
476
507
|
}
|
|
508
|
+
async evalAsync(context) {
|
|
509
|
+
if (this.operand === undefined) {
|
|
510
|
+
throw new Error('Operand undefined');
|
|
511
|
+
}
|
|
512
|
+
const value = (await this.operand.children[0].solve(context)) - (await this.operand.children[1].solve(context));
|
|
513
|
+
context.data.set(this.operand.children[0].name, value);
|
|
514
|
+
return value;
|
|
515
|
+
}
|
|
477
516
|
}
|
|
478
517
|
class AssignmentMultiplication extends domain_2.PrototypeEvaluator {
|
|
479
518
|
clone(operand) {
|
|
@@ -487,6 +526,14 @@ class AssignmentMultiplication extends domain_2.PrototypeEvaluator {
|
|
|
487
526
|
context.data.set(this.operand.children[0].name, value);
|
|
488
527
|
return value;
|
|
489
528
|
}
|
|
529
|
+
async evalAsync(context) {
|
|
530
|
+
if (this.operand === undefined) {
|
|
531
|
+
throw new Error('Operand undefined');
|
|
532
|
+
}
|
|
533
|
+
const value = (await this.operand.children[0].solve(context)) * (await this.operand.children[1].solve(context));
|
|
534
|
+
context.data.set(this.operand.children[0].name, value);
|
|
535
|
+
return value;
|
|
536
|
+
}
|
|
490
537
|
}
|
|
491
538
|
class AssignmentDivision extends domain_2.PrototypeEvaluator {
|
|
492
539
|
clone(operand) {
|
|
@@ -500,6 +547,14 @@ class AssignmentDivision extends domain_2.PrototypeEvaluator {
|
|
|
500
547
|
context.data.set(this.operand.children[0].name, value);
|
|
501
548
|
return value;
|
|
502
549
|
}
|
|
550
|
+
async evalAsync(context) {
|
|
551
|
+
if (this.operand === undefined) {
|
|
552
|
+
throw new Error('Operand undefined');
|
|
553
|
+
}
|
|
554
|
+
const value = (await this.operand.children[0].solve(context)) / (await this.operand.children[1].solve(context));
|
|
555
|
+
context.data.set(this.operand.children[0].name, value);
|
|
556
|
+
return value;
|
|
557
|
+
}
|
|
503
558
|
}
|
|
504
559
|
class AssignmentExponentiation extends domain_2.PrototypeEvaluator {
|
|
505
560
|
clone(operand) {
|
|
@@ -513,6 +568,14 @@ class AssignmentExponentiation extends domain_2.PrototypeEvaluator {
|
|
|
513
568
|
context.data.set(this.operand.children[0].name, value);
|
|
514
569
|
return value;
|
|
515
570
|
}
|
|
571
|
+
async evalAsync(context) {
|
|
572
|
+
if (this.operand === undefined) {
|
|
573
|
+
throw new Error('Operand undefined');
|
|
574
|
+
}
|
|
575
|
+
const value = (await this.operand.children[0].solve(context)) ** (await this.operand.children[1].solve(context));
|
|
576
|
+
context.data.set(this.operand.children[0].name, value);
|
|
577
|
+
return value;
|
|
578
|
+
}
|
|
516
579
|
}
|
|
517
580
|
class AssignmentFloorDivision extends domain_2.PrototypeEvaluator {
|
|
518
581
|
clone(operand) {
|
|
@@ -526,6 +589,14 @@ class AssignmentFloorDivision extends domain_2.PrototypeEvaluator {
|
|
|
526
589
|
context.data.set(this.operand.children[0].name, value);
|
|
527
590
|
return value;
|
|
528
591
|
}
|
|
592
|
+
async evalAsync(context) {
|
|
593
|
+
if (this.operand === undefined) {
|
|
594
|
+
throw new Error('Operand undefined');
|
|
595
|
+
}
|
|
596
|
+
const value = Math.floor((await this.operand.children[0].solve(context)) / (await this.operand.children[1].solve(context)));
|
|
597
|
+
context.data.set(this.operand.children[0].name, value);
|
|
598
|
+
return value;
|
|
599
|
+
}
|
|
529
600
|
}
|
|
530
601
|
class AssignmentMod extends domain_2.PrototypeEvaluator {
|
|
531
602
|
clone(operand) {
|
|
@@ -539,6 +610,14 @@ class AssignmentMod extends domain_2.PrototypeEvaluator {
|
|
|
539
610
|
context.data.set(this.operand.children[0].name, value);
|
|
540
611
|
return value;
|
|
541
612
|
}
|
|
613
|
+
async evalAsync(context) {
|
|
614
|
+
if (this.operand === undefined) {
|
|
615
|
+
throw new Error('Operand undefined');
|
|
616
|
+
}
|
|
617
|
+
const value = (await this.operand.children[0].solve(context)) % (await this.operand.children[1].solve(context));
|
|
618
|
+
context.data.set(this.operand.children[0].name, value);
|
|
619
|
+
return value;
|
|
620
|
+
}
|
|
542
621
|
}
|
|
543
622
|
class AssignmentBitAnd extends domain_2.PrototypeEvaluator {
|
|
544
623
|
clone(operand) {
|
|
@@ -552,6 +631,14 @@ class AssignmentBitAnd extends domain_2.PrototypeEvaluator {
|
|
|
552
631
|
context.data.set(this.operand.children[0].name, value);
|
|
553
632
|
return value;
|
|
554
633
|
}
|
|
634
|
+
async evalAsync(context) {
|
|
635
|
+
if (this.operand === undefined) {
|
|
636
|
+
throw new Error('Operand undefined');
|
|
637
|
+
}
|
|
638
|
+
const value = (await this.operand.children[0].solve(context)) & (await this.operand.children[1].solve(context));
|
|
639
|
+
context.data.set(this.operand.children[0].name, value);
|
|
640
|
+
return value;
|
|
641
|
+
}
|
|
555
642
|
}
|
|
556
643
|
class AssignmentBitOr extends domain_2.PrototypeEvaluator {
|
|
557
644
|
clone(operand) {
|
|
@@ -565,6 +652,14 @@ class AssignmentBitOr extends domain_2.PrototypeEvaluator {
|
|
|
565
652
|
context.data.set(this.operand.children[0].name, value);
|
|
566
653
|
return value;
|
|
567
654
|
}
|
|
655
|
+
async evalAsync(context) {
|
|
656
|
+
if (this.operand === undefined) {
|
|
657
|
+
throw new Error('Operand undefined');
|
|
658
|
+
}
|
|
659
|
+
const value = (await this.operand.children[0].solve(context)) | (await this.operand.children[1].solve(context));
|
|
660
|
+
context.data.set(this.operand.children[0].name, value);
|
|
661
|
+
return value;
|
|
662
|
+
}
|
|
568
663
|
}
|
|
569
664
|
class AssignmentBitXor extends domain_2.PrototypeEvaluator {
|
|
570
665
|
clone(operand) {
|
|
@@ -578,6 +673,14 @@ class AssignmentBitXor extends domain_2.PrototypeEvaluator {
|
|
|
578
673
|
context.data.set(this.operand.children[0].name, value);
|
|
579
674
|
return value;
|
|
580
675
|
}
|
|
676
|
+
async evalAsync(context) {
|
|
677
|
+
if (this.operand === undefined) {
|
|
678
|
+
throw new Error('Operand undefined');
|
|
679
|
+
}
|
|
680
|
+
const value = (await this.operand.children[0].solve(context)) ^ (await this.operand.children[1].solve(context));
|
|
681
|
+
context.data.set(this.operand.children[0].name, value);
|
|
682
|
+
return value;
|
|
683
|
+
}
|
|
581
684
|
}
|
|
582
685
|
class AssignmentLeftShift extends domain_2.PrototypeEvaluator {
|
|
583
686
|
clone(operand) {
|
|
@@ -591,6 +694,14 @@ class AssignmentLeftShift extends domain_2.PrototypeEvaluator {
|
|
|
591
694
|
context.data.set(this.operand.children[0].name, value);
|
|
592
695
|
return value;
|
|
593
696
|
}
|
|
697
|
+
async evalAsync(context) {
|
|
698
|
+
if (this.operand === undefined) {
|
|
699
|
+
throw new Error('Operand undefined');
|
|
700
|
+
}
|
|
701
|
+
const value = (await this.operand.children[0].solve(context)) << (await this.operand.children[1].solve(context));
|
|
702
|
+
context.data.set(this.operand.children[0].name, value);
|
|
703
|
+
return value;
|
|
704
|
+
}
|
|
594
705
|
}
|
|
595
706
|
class AssignmentRightShift extends domain_2.PrototypeEvaluator {
|
|
596
707
|
clone(operand) {
|
|
@@ -604,6 +715,14 @@ class AssignmentRightShift extends domain_2.PrototypeEvaluator {
|
|
|
604
715
|
context.data.set(this.operand.children[0].name, value);
|
|
605
716
|
return value;
|
|
606
717
|
}
|
|
718
|
+
async evalAsync(context) {
|
|
719
|
+
if (this.operand === undefined) {
|
|
720
|
+
throw new Error('Operand undefined');
|
|
721
|
+
}
|
|
722
|
+
const value = (await this.operand.children[0].solve(context)) >> (await this.operand.children[1].solve(context));
|
|
723
|
+
context.data.set(this.operand.children[0].name, value);
|
|
724
|
+
return value;
|
|
725
|
+
}
|
|
607
726
|
}
|
|
608
727
|
class Map extends domain_2.PrototypeEvaluator {
|
|
609
728
|
// eslint-disable-next-line no-useless-constructor
|
|
@@ -646,7 +765,7 @@ class Map extends domain_2.PrototypeEvaluator {
|
|
|
646
765
|
const variable = this.operand.children[1];
|
|
647
766
|
for (const key of keys) {
|
|
648
767
|
for (const keyValue of aggregates) {
|
|
649
|
-
const operandCloned = this.cloner.clone(keyValue.children[0], '
|
|
768
|
+
const operandCloned = this.cloner.clone(keyValue.children[0], 'expression');
|
|
650
769
|
const operandResolved = __1.helper.operand.solveAggregates(key.items, variable, operandCloned, context);
|
|
651
770
|
const value = operandResolved.eval(context);
|
|
652
771
|
key.summarizers.push({ name: keyValue.name, value });
|
|
@@ -679,6 +798,70 @@ class Map extends domain_2.PrototypeEvaluator {
|
|
|
679
798
|
}
|
|
680
799
|
return rows;
|
|
681
800
|
}
|
|
801
|
+
async evalAsync(context) {
|
|
802
|
+
if (this.operand === undefined) {
|
|
803
|
+
throw new Error('Operand undefined');
|
|
804
|
+
}
|
|
805
|
+
const rows = [];
|
|
806
|
+
const list = await this.operand.children[0].solve(context);
|
|
807
|
+
if (!list) {
|
|
808
|
+
throw new Error(`Array ${this.operand.children[0].name} undefined`);
|
|
809
|
+
}
|
|
810
|
+
if (this.operand.children[2].type === domain_1.OperandType.Obj) {
|
|
811
|
+
const groupers = [];
|
|
812
|
+
const aggregates = [];
|
|
813
|
+
for (const child of this.operand.children[2].children) {
|
|
814
|
+
// In the case of being an object the value to return, find out if there are fields that are summarized
|
|
815
|
+
const keyValue = child;
|
|
816
|
+
if (keyValue) {
|
|
817
|
+
if (__1.helper.operand.haveAggregates(keyValue.children[0])) {
|
|
818
|
+
aggregates.push(keyValue);
|
|
819
|
+
}
|
|
820
|
+
else {
|
|
821
|
+
groupers.push(keyValue);
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
if (aggregates.length > 0) {
|
|
826
|
+
// case with aggregate functions
|
|
827
|
+
const keys = __1.helper.operand.getKeys(this.operand.children[1], groupers, list, context);
|
|
828
|
+
// once you got all the keys you have to calculate the aggregates fields
|
|
829
|
+
const variable = this.operand.children[1];
|
|
830
|
+
for (const key of keys) {
|
|
831
|
+
for (const keyValue of aggregates) {
|
|
832
|
+
const operandCloned = this.cloner.clone(keyValue.children[0], 'expression');
|
|
833
|
+
const operandResolved = __1.helper.operand.solveAggregates(key.items, variable, operandCloned, context);
|
|
834
|
+
const value = await operandResolved.solve(context);
|
|
835
|
+
key.summarizers.push({ name: keyValue.name, value });
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
// build the list of results
|
|
839
|
+
for (const key of keys) {
|
|
840
|
+
const row = {};
|
|
841
|
+
for (const value of key.values) {
|
|
842
|
+
row[value.name] = value.value;
|
|
843
|
+
}
|
|
844
|
+
for (const summarizer of key.summarizers) {
|
|
845
|
+
row[summarizer.name] = summarizer.value;
|
|
846
|
+
}
|
|
847
|
+
rows.push(row);
|
|
848
|
+
}
|
|
849
|
+
return rows;
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
else if (this.operand.children[2].type === domain_1.OperandType.Var && !Array.isArray(list)) {
|
|
853
|
+
// Example orders.0.number
|
|
854
|
+
return list;
|
|
855
|
+
}
|
|
856
|
+
// simple case without aggregate functions
|
|
857
|
+
const childContext = context.newContext();
|
|
858
|
+
for (const item of list) {
|
|
859
|
+
childContext.data.set(this.operand.children[1].name, item);
|
|
860
|
+
const row = await this.operand.children[2].solve(childContext);
|
|
861
|
+
rows.push(row);
|
|
862
|
+
}
|
|
863
|
+
return rows;
|
|
864
|
+
}
|
|
682
865
|
}
|
|
683
866
|
class Distinct extends domain_2.PrototypeEvaluator {
|
|
684
867
|
clone(operand) {
|
|
@@ -729,6 +912,51 @@ class Distinct extends domain_2.PrototypeEvaluator {
|
|
|
729
912
|
}
|
|
730
913
|
return rows;
|
|
731
914
|
}
|
|
915
|
+
async evalAsync(context) {
|
|
916
|
+
if (this.operand === undefined) {
|
|
917
|
+
throw new Error('Operand undefined');
|
|
918
|
+
}
|
|
919
|
+
const rows = [];
|
|
920
|
+
const list = await this.operand.children[0].solve(context);
|
|
921
|
+
if (!list) {
|
|
922
|
+
throw new Error(`Array ${this.operand.children[0].name} undefined`);
|
|
923
|
+
}
|
|
924
|
+
if (this.operand.children.length === 1) {
|
|
925
|
+
// simple case
|
|
926
|
+
for (const item of list) {
|
|
927
|
+
if (rows.find((p) => p === item) === undefined) {
|
|
928
|
+
rows.push(item);
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
return rows;
|
|
932
|
+
}
|
|
933
|
+
else if (this.operand.children[2].type === domain_1.OperandType.Obj) {
|
|
934
|
+
// case with aggregate functions
|
|
935
|
+
const keys = __1.helper.operand.getKeys(this.operand.children[1], this.operand.children[2].children, list, context.newContext());
|
|
936
|
+
// build the list of results
|
|
937
|
+
for (const key of keys) {
|
|
938
|
+
const row = {};
|
|
939
|
+
for (const value of key.values) {
|
|
940
|
+
row[value.name] = value.value;
|
|
941
|
+
}
|
|
942
|
+
rows.push(row);
|
|
943
|
+
}
|
|
944
|
+
return rows;
|
|
945
|
+
}
|
|
946
|
+
else if (this.operand.children[2].type === domain_1.OperandType.List) {
|
|
947
|
+
throw new Error('Distinct not support Array result');
|
|
948
|
+
}
|
|
949
|
+
// simple case without aggregate functions
|
|
950
|
+
const childContext = context.newContext();
|
|
951
|
+
for (const item of list) {
|
|
952
|
+
childContext.data.set(this.operand.children[1].name, item);
|
|
953
|
+
const value = await this.operand.children[2].solve(childContext);
|
|
954
|
+
if (rows.find((p) => p === value) === undefined) {
|
|
955
|
+
rows.push(value);
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
return rows;
|
|
959
|
+
}
|
|
732
960
|
}
|
|
733
961
|
class Foreach extends domain_2.PrototypeEvaluator {
|
|
734
962
|
clone(operand) {
|
|
@@ -749,6 +977,21 @@ class Foreach extends domain_2.PrototypeEvaluator {
|
|
|
749
977
|
}
|
|
750
978
|
return list;
|
|
751
979
|
}
|
|
980
|
+
async evalAsync(context) {
|
|
981
|
+
if (this.operand === undefined) {
|
|
982
|
+
throw new Error('Operand undefined');
|
|
983
|
+
}
|
|
984
|
+
const list = await this.operand.children[0].solve(context);
|
|
985
|
+
if (!list) {
|
|
986
|
+
throw new Error(`Array ${this.operand.children[0].name} undefined`);
|
|
987
|
+
}
|
|
988
|
+
const childContext = context.newContext();
|
|
989
|
+
for (const item of list) {
|
|
990
|
+
childContext.data.set(this.operand.children[1].name, item);
|
|
991
|
+
await this.operand.children[2].solve(childContext);
|
|
992
|
+
}
|
|
993
|
+
return list;
|
|
994
|
+
}
|
|
752
995
|
}
|
|
753
996
|
class Filter extends domain_2.PrototypeEvaluator {
|
|
754
997
|
clone(operand) {
|
|
@@ -772,6 +1015,24 @@ class Filter extends domain_2.PrototypeEvaluator {
|
|
|
772
1015
|
}
|
|
773
1016
|
return rows;
|
|
774
1017
|
}
|
|
1018
|
+
async evalAsync(context) {
|
|
1019
|
+
if (this.operand === undefined) {
|
|
1020
|
+
throw new Error('Operand undefined');
|
|
1021
|
+
}
|
|
1022
|
+
const rows = [];
|
|
1023
|
+
const list = await this.operand.children[0].solve(context);
|
|
1024
|
+
if (!list) {
|
|
1025
|
+
throw new Error(`Array ${this.operand.children[0].name} undefined`);
|
|
1026
|
+
}
|
|
1027
|
+
const childContext = context.newContext();
|
|
1028
|
+
for (const item of list) {
|
|
1029
|
+
childContext.data.set(this.operand.children[1].name, item);
|
|
1030
|
+
if (await this.operand.children[2].solve(childContext)) {
|
|
1031
|
+
rows.push(item);
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
return rows;
|
|
1035
|
+
}
|
|
775
1036
|
}
|
|
776
1037
|
class Reverse extends domain_2.PrototypeEvaluator {
|
|
777
1038
|
clone(operand) {
|
|
@@ -799,6 +1060,28 @@ class Reverse extends domain_2.PrototypeEvaluator {
|
|
|
799
1060
|
values.reverse();
|
|
800
1061
|
return values.map(p => p.p);
|
|
801
1062
|
}
|
|
1063
|
+
async evalAsync(context) {
|
|
1064
|
+
if (this.operand === undefined) {
|
|
1065
|
+
throw new Error('Operand undefined');
|
|
1066
|
+
}
|
|
1067
|
+
const list = await this.operand.children[0].solve(context);
|
|
1068
|
+
if (!list) {
|
|
1069
|
+
throw new Error(`Array ${this.operand.children[0].name} undefined`);
|
|
1070
|
+
}
|
|
1071
|
+
if (this.operand.children.length === 1) {
|
|
1072
|
+
return list.reverse();
|
|
1073
|
+
}
|
|
1074
|
+
const values = [];
|
|
1075
|
+
const childContext = context.newContext();
|
|
1076
|
+
for (const item of list) {
|
|
1077
|
+
childContext.data.set(this.operand.children[1].name, item);
|
|
1078
|
+
const value = await this.operand.children[2].solve(childContext);
|
|
1079
|
+
values.push({ value, p: item });
|
|
1080
|
+
}
|
|
1081
|
+
values.sort((a, b) => a.value > b.value ? 1 : a.value < b.value ? -1 : 0);
|
|
1082
|
+
values.reverse();
|
|
1083
|
+
return values.map(p => p.p);
|
|
1084
|
+
}
|
|
802
1085
|
}
|
|
803
1086
|
class Sort extends domain_2.PrototypeEvaluator {
|
|
804
1087
|
clone(operand) {
|
|
@@ -825,6 +1108,27 @@ class Sort extends domain_2.PrototypeEvaluator {
|
|
|
825
1108
|
values.sort((a, b) => a.value > b.value ? 1 : a.value < b.value ? -1 : 0);
|
|
826
1109
|
return values.map(p => p.p);
|
|
827
1110
|
}
|
|
1111
|
+
async evalAsync(context) {
|
|
1112
|
+
if (this.operand === undefined) {
|
|
1113
|
+
throw new Error('Operand undefined');
|
|
1114
|
+
}
|
|
1115
|
+
const values = [];
|
|
1116
|
+
const list = await this.operand.children[0].solve(context);
|
|
1117
|
+
if (!list) {
|
|
1118
|
+
throw new Error(`Array ${this.operand.children[0].name} undefined`);
|
|
1119
|
+
}
|
|
1120
|
+
if (this.operand.children.length === 1) {
|
|
1121
|
+
return list.sort();
|
|
1122
|
+
}
|
|
1123
|
+
const childContext = context.newContext();
|
|
1124
|
+
for (const item of list) {
|
|
1125
|
+
childContext.data.set(this.operand.children[1].name, item);
|
|
1126
|
+
const value = await this.operand.children[2].solve(childContext);
|
|
1127
|
+
values.push({ value, p: item });
|
|
1128
|
+
}
|
|
1129
|
+
values.sort((a, b) => a.value > b.value ? 1 : a.value < b.value ? -1 : 0);
|
|
1130
|
+
return values.map(p => p.p);
|
|
1131
|
+
}
|
|
828
1132
|
}
|
|
829
1133
|
class Remove extends domain_2.PrototypeEvaluator {
|
|
830
1134
|
clone(operand) {
|
|
@@ -848,6 +1152,24 @@ class Remove extends domain_2.PrototypeEvaluator {
|
|
|
848
1152
|
}
|
|
849
1153
|
return rows;
|
|
850
1154
|
}
|
|
1155
|
+
async evalAsync(context) {
|
|
1156
|
+
if (this.operand === undefined) {
|
|
1157
|
+
throw new Error('Operand undefined');
|
|
1158
|
+
}
|
|
1159
|
+
const rows = [];
|
|
1160
|
+
const list = await this.operand.children[0].solve(context);
|
|
1161
|
+
if (!list) {
|
|
1162
|
+
throw new Error(`Array ${this.operand.children[0].name} undefined`);
|
|
1163
|
+
}
|
|
1164
|
+
const childContext = context.newContext();
|
|
1165
|
+
for (const item of list) {
|
|
1166
|
+
childContext.data.set(this.operand.children[1].name, item);
|
|
1167
|
+
if (!(await this.operand.children[2].solve(childContext))) {
|
|
1168
|
+
rows.push(item);
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
return rows;
|
|
1172
|
+
}
|
|
851
1173
|
}
|
|
852
1174
|
class First extends domain_2.PrototypeEvaluator {
|
|
853
1175
|
clone(operand) {
|
|
@@ -857,7 +1179,18 @@ class First extends domain_2.PrototypeEvaluator {
|
|
|
857
1179
|
if (this.operand === undefined) {
|
|
858
1180
|
throw new Error('Operand undefined');
|
|
859
1181
|
}
|
|
860
|
-
|
|
1182
|
+
return this.first(this.operand.children[0].eval(context), context);
|
|
1183
|
+
}
|
|
1184
|
+
async evalAsync(context) {
|
|
1185
|
+
if (this.operand === undefined) {
|
|
1186
|
+
throw new Error('Operand undefined');
|
|
1187
|
+
}
|
|
1188
|
+
return this.first(await this.operand.children[0].solve(context), context);
|
|
1189
|
+
}
|
|
1190
|
+
first(list, context) {
|
|
1191
|
+
if (this.operand === undefined) {
|
|
1192
|
+
throw new Error('Operand undefined');
|
|
1193
|
+
}
|
|
861
1194
|
if (!list) {
|
|
862
1195
|
throw new Error(`Array ${this.operand.children[0].name} undefined`);
|
|
863
1196
|
}
|
|
@@ -875,7 +1208,18 @@ class Last extends domain_2.PrototypeEvaluator {
|
|
|
875
1208
|
if (this.operand === undefined) {
|
|
876
1209
|
throw new Error('Operand undefined');
|
|
877
1210
|
}
|
|
878
|
-
|
|
1211
|
+
return this.last(this.operand.children[0].eval(context), context);
|
|
1212
|
+
}
|
|
1213
|
+
async evalAsync(context) {
|
|
1214
|
+
if (this.operand === undefined) {
|
|
1215
|
+
throw new Error('Operand undefined');
|
|
1216
|
+
}
|
|
1217
|
+
return this.last(await this.operand.children[0].solve(context), context);
|
|
1218
|
+
}
|
|
1219
|
+
last(list, context) {
|
|
1220
|
+
if (this.operand === undefined) {
|
|
1221
|
+
throw new Error('Operand undefined');
|
|
1222
|
+
}
|
|
879
1223
|
if (!list) {
|
|
880
1224
|
throw new Error(`Array ${this.operand.children[0].name} undefined`);
|
|
881
1225
|
}
|
|
@@ -893,7 +1237,18 @@ class Count extends domain_2.PrototypeEvaluator {
|
|
|
893
1237
|
if (this.operand === undefined) {
|
|
894
1238
|
throw new Error('Operand undefined');
|
|
895
1239
|
}
|
|
896
|
-
|
|
1240
|
+
return this.count(this.operand.children[0].eval(context), context);
|
|
1241
|
+
}
|
|
1242
|
+
async evalAsync(context) {
|
|
1243
|
+
if (this.operand === undefined) {
|
|
1244
|
+
throw new Error('Operand undefined');
|
|
1245
|
+
}
|
|
1246
|
+
return this.count(await this.operand.children[0].solve(context), context);
|
|
1247
|
+
}
|
|
1248
|
+
count(list, context) {
|
|
1249
|
+
if (this.operand === undefined) {
|
|
1250
|
+
throw new Error('Operand undefined');
|
|
1251
|
+
}
|
|
897
1252
|
if (!list) {
|
|
898
1253
|
throw new Error(`Array ${this.operand.children[0].name} undefined`);
|
|
899
1254
|
}
|
|
@@ -911,7 +1266,18 @@ class Max extends domain_2.PrototypeEvaluator {
|
|
|
911
1266
|
if (this.operand === undefined) {
|
|
912
1267
|
throw new Error('Operand undefined');
|
|
913
1268
|
}
|
|
914
|
-
|
|
1269
|
+
return this.max(this.operand.children[0].eval(context), context);
|
|
1270
|
+
}
|
|
1271
|
+
async evalAsync(context) {
|
|
1272
|
+
if (this.operand === undefined) {
|
|
1273
|
+
throw new Error('Operand undefined');
|
|
1274
|
+
}
|
|
1275
|
+
return this.max(await this.operand.children[0].solve(context), context);
|
|
1276
|
+
}
|
|
1277
|
+
max(list, context) {
|
|
1278
|
+
if (this.operand === undefined) {
|
|
1279
|
+
throw new Error('Operand undefined');
|
|
1280
|
+
}
|
|
915
1281
|
if (!list) {
|
|
916
1282
|
throw new Error(`Array ${this.operand.children[0].name} undefined`);
|
|
917
1283
|
}
|
|
@@ -935,7 +1301,18 @@ class Min extends domain_2.PrototypeEvaluator {
|
|
|
935
1301
|
if (this.operand === undefined) {
|
|
936
1302
|
throw new Error('Operand undefined');
|
|
937
1303
|
}
|
|
938
|
-
|
|
1304
|
+
return this.min(this.operand.children[0].eval(context), context);
|
|
1305
|
+
}
|
|
1306
|
+
async evalAsync(context) {
|
|
1307
|
+
if (this.operand === undefined) {
|
|
1308
|
+
throw new Error('Operand undefined');
|
|
1309
|
+
}
|
|
1310
|
+
return this.min(await this.operand.children[0].solve(context), context);
|
|
1311
|
+
}
|
|
1312
|
+
min(list, context) {
|
|
1313
|
+
if (this.operand === undefined) {
|
|
1314
|
+
throw new Error('Operand undefined');
|
|
1315
|
+
}
|
|
939
1316
|
if (!list) {
|
|
940
1317
|
throw new Error(`Array ${this.operand.children[0].name} undefined`);
|
|
941
1318
|
}
|
|
@@ -959,9 +1336,17 @@ class Avg extends domain_2.PrototypeEvaluator {
|
|
|
959
1336
|
if (this.operand === undefined) {
|
|
960
1337
|
throw new Error('Operand undefined');
|
|
961
1338
|
}
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
1339
|
+
return this.avg(this.operand.children[0].eval(context), context);
|
|
1340
|
+
}
|
|
1341
|
+
async evalAsync(context) {
|
|
1342
|
+
if (this.operand === undefined) {
|
|
1343
|
+
throw new Error('Operand undefined');
|
|
1344
|
+
}
|
|
1345
|
+
return this.avg(await this.operand.children[0].solve(context), context);
|
|
1346
|
+
}
|
|
1347
|
+
avg(list, context) {
|
|
1348
|
+
if (this.operand === undefined) {
|
|
1349
|
+
throw new Error('Operand undefined');
|
|
965
1350
|
}
|
|
966
1351
|
if (this.operand.children.length === 1) {
|
|
967
1352
|
let sum = 0;
|
|
@@ -983,7 +1368,18 @@ class Sum extends domain_2.PrototypeEvaluator {
|
|
|
983
1368
|
if (this.operand === undefined) {
|
|
984
1369
|
throw new Error('Operand undefined');
|
|
985
1370
|
}
|
|
986
|
-
|
|
1371
|
+
return this.sum(this.operand.children[0].eval(context), context);
|
|
1372
|
+
}
|
|
1373
|
+
async evalAsync(context) {
|
|
1374
|
+
if (this.operand === undefined) {
|
|
1375
|
+
throw new Error('Operand undefined');
|
|
1376
|
+
}
|
|
1377
|
+
return this.sum(await this.operand.children[0].solve(context), context);
|
|
1378
|
+
}
|
|
1379
|
+
sum(list, context) {
|
|
1380
|
+
if (this.operand === undefined) {
|
|
1381
|
+
throw new Error('Operand undefined');
|
|
1382
|
+
}
|
|
987
1383
|
if (!list) {
|
|
988
1384
|
throw new Error(`Array ${this.operand.children[0].name} undefined`);
|
|
989
1385
|
}
|
|
@@ -1009,12 +1405,17 @@ class Union extends domain_2.PrototypeEvaluator {
|
|
|
1009
1405
|
}
|
|
1010
1406
|
const a = this.operand.children[0].eval(context);
|
|
1011
1407
|
const b = this.operand.children[1].eval(context);
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
if (
|
|
1016
|
-
throw new Error(
|
|
1408
|
+
return this.union(a, b);
|
|
1409
|
+
}
|
|
1410
|
+
async evalAsync(context) {
|
|
1411
|
+
if (this.operand === undefined) {
|
|
1412
|
+
throw new Error('Operand undefined');
|
|
1017
1413
|
}
|
|
1414
|
+
const a = await this.operand.children[0].solve(context);
|
|
1415
|
+
const b = await this.operand.children[1].solve(context);
|
|
1416
|
+
return this.union(a, b);
|
|
1417
|
+
}
|
|
1418
|
+
union(a, b) {
|
|
1018
1419
|
if (a.length === 0) {
|
|
1019
1420
|
return b;
|
|
1020
1421
|
}
|
|
@@ -1057,6 +1458,20 @@ class Intersection extends domain_2.PrototypeEvaluator {
|
|
|
1057
1458
|
}
|
|
1058
1459
|
const a = this.operand.children[0].eval(context);
|
|
1059
1460
|
const b = this.operand.children[1].eval(context);
|
|
1461
|
+
return this.intersection(a, b);
|
|
1462
|
+
}
|
|
1463
|
+
async evalAsync(context) {
|
|
1464
|
+
if (this.operand === undefined) {
|
|
1465
|
+
throw new Error('Operand undefined');
|
|
1466
|
+
}
|
|
1467
|
+
const a = await this.operand.children[0].solve(context);
|
|
1468
|
+
const b = await this.operand.children[1].solve(context);
|
|
1469
|
+
return this.intersection(a, b);
|
|
1470
|
+
}
|
|
1471
|
+
intersection(a, b) {
|
|
1472
|
+
if (this.operand === undefined) {
|
|
1473
|
+
throw new Error('Operand undefined');
|
|
1474
|
+
}
|
|
1060
1475
|
if (!a) {
|
|
1061
1476
|
throw new Error(`Array ${this.operand.children[0].name} undefined`);
|
|
1062
1477
|
}
|
|
@@ -1100,6 +1515,20 @@ class Difference extends domain_2.PrototypeEvaluator {
|
|
|
1100
1515
|
}
|
|
1101
1516
|
const a = this.operand.children[0].eval(context);
|
|
1102
1517
|
const b = this.operand.children[1].eval(context);
|
|
1518
|
+
return this.difference(a, b);
|
|
1519
|
+
}
|
|
1520
|
+
async evalAsync(context) {
|
|
1521
|
+
if (this.operand === undefined) {
|
|
1522
|
+
throw new Error('Operand undefined');
|
|
1523
|
+
}
|
|
1524
|
+
const a = await this.operand.children[0].solve(context);
|
|
1525
|
+
const b = await this.operand.children[1].solve(context);
|
|
1526
|
+
return this.difference(a, b);
|
|
1527
|
+
}
|
|
1528
|
+
difference(a, b) {
|
|
1529
|
+
if (this.operand === undefined) {
|
|
1530
|
+
throw new Error('Operand undefined');
|
|
1531
|
+
}
|
|
1103
1532
|
if (!a) {
|
|
1104
1533
|
throw new Error(`Array ${this.operand.children[0].name} undefined`);
|
|
1105
1534
|
}
|
|
@@ -1146,6 +1575,20 @@ class SymmetricDifference extends domain_2.PrototypeEvaluator {
|
|
|
1146
1575
|
}
|
|
1147
1576
|
const a = this.operand.children[0].eval(context);
|
|
1148
1577
|
const b = this.operand.children[1].eval(context);
|
|
1578
|
+
return this.symmetricDifference(a, b);
|
|
1579
|
+
}
|
|
1580
|
+
async evalAsync(context) {
|
|
1581
|
+
if (this.operand === undefined) {
|
|
1582
|
+
throw new Error('Operand undefined');
|
|
1583
|
+
}
|
|
1584
|
+
const a = await this.operand.children[0].solve(context);
|
|
1585
|
+
const b = await this.operand.children[1].solve(context);
|
|
1586
|
+
return this.symmetricDifference(a, b);
|
|
1587
|
+
}
|
|
1588
|
+
symmetricDifference(a, b) {
|
|
1589
|
+
if (this.operand === undefined) {
|
|
1590
|
+
throw new Error('Operand undefined');
|
|
1591
|
+
}
|
|
1149
1592
|
if (!a) {
|
|
1150
1593
|
throw new Error(`Array ${this.operand.children[0].name} undefined`);
|
|
1151
1594
|
}
|