@omegup/msync 0.0.37 → 0.0.39
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/index.d.ts +1 -1
- package/index.esm.js +372 -374
- package/index.js +372 -374
- package/package.json +1 -1
package/index.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { SynchronousPromise } from 'synchronous-promise';
|
|
2
1
|
import { UUID, MongoClient } from 'mongodb';
|
|
2
|
+
import { SynchronousPromise } from 'synchronous-promise';
|
|
3
3
|
import crypto$1 from 'crypto';
|
|
4
4
|
import { writeFile } from 'fs/promises';
|
|
5
5
|
|
|
@@ -646,131 +646,390 @@ const $setDelta = (updater) => {
|
|
|
646
646
|
.with($setEach(k => to(nil), dict)).stages;
|
|
647
647
|
};
|
|
648
648
|
|
|
649
|
-
const
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
649
|
+
const dayAndMonthPart = (date) => asExpr({
|
|
650
|
+
raw: f => asExprRaw({ $dateToString: { date: date.raw(f).get(), format: '%m-%d' } }),
|
|
651
|
+
});
|
|
652
|
+
const now = () => asExpr({
|
|
653
|
+
raw: f => asExprRaw('$$NOW'),
|
|
654
|
+
});
|
|
655
|
+
const monthPart = (date) => asExpr({
|
|
656
|
+
raw: f => asExprRaw({ $dateToString: { date: date.raw(f).get(), format: '%Y-%m' } }),
|
|
657
|
+
});
|
|
658
|
+
const weekPart = (date) => asExpr({
|
|
659
|
+
raw: f => asExprRaw({ $dateToString: { date: date.raw(f).get(), format: '%Y-%U' } }),
|
|
660
|
+
});
|
|
661
|
+
const year = (date) => asExpr({
|
|
662
|
+
raw: f => asExprRaw({ $year: date.raw(f).get() }),
|
|
663
|
+
});
|
|
664
|
+
const dateAdd = (date, amount, unit) => asExpr({
|
|
665
|
+
raw: f => asExprRaw({
|
|
666
|
+
$dateAdd: {
|
|
667
|
+
startDate: date.raw(f).get(),
|
|
668
|
+
unit: unit.raw(f).get(),
|
|
669
|
+
amount: amount.raw(f).get(),
|
|
670
|
+
},
|
|
671
|
+
}),
|
|
672
|
+
});
|
|
673
|
+
const maxDate = (expr) => asExpr({
|
|
674
|
+
raw: f => asExprRaw({ $max: expr.raw(f).get() }),
|
|
675
|
+
});
|
|
676
|
+
const minDate = (expr) => asExpr({
|
|
677
|
+
raw: f => asExprRaw({ $min: expr.raw(f).get() }),
|
|
678
|
+
});
|
|
679
|
+
const datePart = (date) => asExpr({
|
|
680
|
+
raw: f => asExprRaw({ $dateToString: { date: date.raw(f).get(), format: '%Y-%m-%d' } }),
|
|
681
|
+
});
|
|
682
|
+
const startOf = (startDate, freq, offset) => asExpr({
|
|
683
|
+
raw: f => asExprRaw({
|
|
684
|
+
$let: {
|
|
685
|
+
vars: { d: startDate.raw(f).get(), f: freq.raw(f).get(), i: offset.raw(f).get() },
|
|
686
|
+
in: {
|
|
687
|
+
$switch: {
|
|
688
|
+
branches: [
|
|
659
689
|
{
|
|
660
|
-
$
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
690
|
+
case: { $eq: ['$$f', 'week'] },
|
|
691
|
+
then: {
|
|
692
|
+
$dateFromParts: {
|
|
693
|
+
isoWeekYear: { $isoWeekYear: '$$d' },
|
|
694
|
+
isoWeek: {
|
|
695
|
+
$add: [
|
|
696
|
+
{ $isoWeek: '$$d' },
|
|
697
|
+
{
|
|
698
|
+
$cond: {
|
|
699
|
+
if: {
|
|
700
|
+
$lt: ['$$i', { $isoDayOfWeek: '$$d' }],
|
|
701
|
+
},
|
|
702
|
+
then: 1,
|
|
703
|
+
else: 0,
|
|
704
|
+
},
|
|
705
|
+
},
|
|
706
|
+
],
|
|
707
|
+
},
|
|
708
|
+
isoDayOfWeek: '$$i',
|
|
709
|
+
},
|
|
664
710
|
},
|
|
665
711
|
},
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
input: `$after.${k2}`,
|
|
685
|
-
as: 'a',
|
|
686
|
-
cond: { $eq: ['$$a._id', '$$b._id'] },
|
|
687
|
-
},
|
|
712
|
+
{
|
|
713
|
+
case: { $eq: ['$$f', 'month'] },
|
|
714
|
+
then: {
|
|
715
|
+
$dateFromParts: {
|
|
716
|
+
year: { $year: '$$d' },
|
|
717
|
+
month: {
|
|
718
|
+
$add: [
|
|
719
|
+
{ $month: '$$d' },
|
|
720
|
+
{
|
|
721
|
+
$cond: {
|
|
722
|
+
if: {
|
|
723
|
+
$lt: ['$$i', { $dayOfMonth: '$$d' }],
|
|
724
|
+
},
|
|
725
|
+
then: 1,
|
|
726
|
+
else: 0,
|
|
727
|
+
},
|
|
728
|
+
},
|
|
729
|
+
],
|
|
688
730
|
},
|
|
731
|
+
day: '$$i',
|
|
689
732
|
},
|
|
690
|
-
|
|
691
|
-
|
|
733
|
+
},
|
|
734
|
+
},
|
|
735
|
+
{
|
|
736
|
+
case: { $eq: ['$$f', 'year'] },
|
|
737
|
+
then: {
|
|
738
|
+
$dateFromParts: {
|
|
739
|
+
year: {
|
|
740
|
+
$add: [
|
|
741
|
+
{ $year: '$$d' },
|
|
742
|
+
{
|
|
743
|
+
$cond: {
|
|
744
|
+
if: {
|
|
745
|
+
$or: [
|
|
746
|
+
{
|
|
747
|
+
$lt: [{ $floor: { $divide: ['$$i', 100] } }, { $month: '$$d' }],
|
|
748
|
+
},
|
|
749
|
+
{
|
|
750
|
+
$and: [
|
|
751
|
+
{
|
|
752
|
+
$eq: [
|
|
753
|
+
{ $floor: { $divide: ['$$i', 100] } },
|
|
754
|
+
{ $month: '$$d' },
|
|
755
|
+
],
|
|
756
|
+
},
|
|
757
|
+
{
|
|
758
|
+
$lt: [{ $mod: ['$$i', 100] }, { $dayOfMonth: '$$d' }],
|
|
759
|
+
},
|
|
760
|
+
],
|
|
761
|
+
},
|
|
762
|
+
],
|
|
763
|
+
},
|
|
764
|
+
then: 1,
|
|
765
|
+
else: 0,
|
|
766
|
+
},
|
|
767
|
+
},
|
|
768
|
+
],
|
|
769
|
+
},
|
|
770
|
+
month: { $floor: { $divide: ['$$i', 100] } },
|
|
771
|
+
day: { $mod: ['$$i', 100] },
|
|
772
|
+
},
|
|
773
|
+
},
|
|
774
|
+
},
|
|
775
|
+
],
|
|
776
|
+
default: {
|
|
777
|
+
$dateFromParts: {
|
|
778
|
+
year: { $year: '$$d' },
|
|
779
|
+
month: { $month: '$$d' },
|
|
780
|
+
day: { $add: [{ $dayOfMonth: '$$d' }, '$$i'] },
|
|
692
781
|
},
|
|
693
782
|
},
|
|
694
783
|
},
|
|
695
784
|
},
|
|
696
|
-
as: 'a',
|
|
697
|
-
cond: { $ne: ['$$a.before', '$$a.after'] },
|
|
698
785
|
},
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
$
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
? ifNull(k, part)
|
|
709
|
-
: {
|
|
710
|
-
$concat: interDot([k1, k2].sort().map(k => ifNull(k, part))),
|
|
711
|
-
},
|
|
712
|
-
[k1]: `$${k1}.${part}`,
|
|
713
|
-
[k2]: outer
|
|
714
|
-
? {
|
|
715
|
-
$cond: {
|
|
716
|
-
if: `$${k2}.${part}._id`,
|
|
717
|
-
then: `$${k2}.${part}`,
|
|
718
|
-
else: null,
|
|
719
|
-
},
|
|
720
|
-
}
|
|
721
|
-
: `$${k2}.${part}`,
|
|
786
|
+
}),
|
|
787
|
+
});
|
|
788
|
+
const dateDiff = ({ end, unit, start, }) => asExpr({
|
|
789
|
+
raw: f => asExprRaw({
|
|
790
|
+
$let: {
|
|
791
|
+
vars: {
|
|
792
|
+
f: unit.raw(f).get(),
|
|
793
|
+
end: end.raw(f).get(),
|
|
794
|
+
start: start.raw(f).get(),
|
|
722
795
|
},
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
796
|
+
in: {
|
|
797
|
+
$let: {
|
|
798
|
+
vars: {
|
|
799
|
+
diff: {
|
|
800
|
+
$dateDiff: {
|
|
801
|
+
startDate: '$$start',
|
|
802
|
+
endDate: '$$end',
|
|
803
|
+
unit: '$$f',
|
|
804
|
+
},
|
|
805
|
+
},
|
|
806
|
+
},
|
|
807
|
+
in: {
|
|
808
|
+
$switch: {
|
|
809
|
+
branches: [
|
|
810
|
+
{
|
|
811
|
+
case: { $eq: ['$$f', 'month'] },
|
|
739
812
|
then: {
|
|
740
813
|
$cond: {
|
|
741
|
-
if: {
|
|
742
|
-
|
|
743
|
-
|
|
814
|
+
if: {
|
|
815
|
+
$lte: [{ $dayOfMonth: '$$start' }, { $dayOfMonth: '$$end' }],
|
|
816
|
+
},
|
|
817
|
+
then: '$$diff',
|
|
818
|
+
else: { $subtract: ['$$diff', 1] },
|
|
744
819
|
},
|
|
745
820
|
},
|
|
746
|
-
else: oldItems,
|
|
747
821
|
},
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
$map: {
|
|
752
|
-
input: outer
|
|
753
|
-
? {
|
|
822
|
+
{
|
|
823
|
+
case: { $eq: ['$$f', 'week'] },
|
|
824
|
+
then: {
|
|
754
825
|
$cond: {
|
|
755
826
|
if: {
|
|
756
|
-
$
|
|
827
|
+
$lte: [{ $isoDayOfWeek: '$$start' }, { $isoDayOfWeek: '$$end' }],
|
|
757
828
|
},
|
|
758
|
-
then:
|
|
759
|
-
else:
|
|
829
|
+
then: '$$diff',
|
|
830
|
+
else: { $subtract: ['$$diff', 1] },
|
|
760
831
|
},
|
|
761
|
-
}
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
832
|
+
},
|
|
833
|
+
},
|
|
834
|
+
{
|
|
835
|
+
case: { $eq: ['$$f', 'year'] },
|
|
836
|
+
then: {
|
|
837
|
+
$cond: {
|
|
838
|
+
if: {
|
|
839
|
+
$or: [
|
|
840
|
+
{
|
|
841
|
+
$lt: [{ $month: '$$start' }, { $month: '$$end' }],
|
|
842
|
+
},
|
|
843
|
+
{
|
|
844
|
+
$and: [
|
|
845
|
+
{
|
|
846
|
+
$eq: [{ $month: '$$start' }, { $month: '$$end' }],
|
|
847
|
+
},
|
|
848
|
+
{
|
|
849
|
+
$lte: [{ $dayOfMonth: '$$start' }, { $dayOfMonth: '$$end' }],
|
|
850
|
+
},
|
|
851
|
+
],
|
|
852
|
+
},
|
|
853
|
+
],
|
|
854
|
+
},
|
|
855
|
+
then: '$$diff',
|
|
856
|
+
else: { $subtract: ['$$diff', 1] },
|
|
857
|
+
},
|
|
858
|
+
},
|
|
859
|
+
},
|
|
860
|
+
],
|
|
861
|
+
default: '$$diff',
|
|
862
|
+
},
|
|
863
|
+
},
|
|
864
|
+
},
|
|
865
|
+
},
|
|
866
|
+
},
|
|
867
|
+
}),
|
|
868
|
+
});
|
|
869
|
+
|
|
870
|
+
const range = (start, end, step) => asExpr({
|
|
871
|
+
raw: f => asExprRaw({ $range: [start.raw(f).get(), end.raw(f).get(), step?.raw(f).get() ?? 1] }),
|
|
872
|
+
});
|
|
873
|
+
const $map1 = (ex, map) => asExpr({
|
|
874
|
+
raw: f => asExprRaw({
|
|
875
|
+
$map: {
|
|
876
|
+
input: ex.raw(f).get(),
|
|
877
|
+
as: 'item',
|
|
878
|
+
in: map(ctx()('item')).raw(f).get(),
|
|
879
|
+
},
|
|
880
|
+
}),
|
|
881
|
+
});
|
|
882
|
+
const $map = (ex, map) => $map1(ex, i => map(i.expr()));
|
|
883
|
+
|
|
884
|
+
const operator = () => (op) => (operand) => {
|
|
885
|
+
return {
|
|
886
|
+
raw: { [op]: operand },
|
|
887
|
+
expr: (field) => asExpr({
|
|
888
|
+
raw: f => asExprRaw({ [op]: [$ifNull(field.expr(), nil).raw(f).get(), operand] }),
|
|
889
|
+
}),
|
|
890
|
+
};
|
|
891
|
+
};
|
|
892
|
+
|
|
893
|
+
const dualEq = operator();
|
|
894
|
+
const $eq = dualEq('$eq');
|
|
895
|
+
const $ne = dualEq('$ne');
|
|
896
|
+
const comp = operator();
|
|
897
|
+
const $gt = comp('$gt');
|
|
898
|
+
const $gtTs = comp('$gt');
|
|
899
|
+
const $gteTs = comp('$gte');
|
|
900
|
+
const $lt = comp('$lt');
|
|
901
|
+
const dateLt = comp('$lt');
|
|
902
|
+
const $gte = comp('$gte');
|
|
903
|
+
const $lte = comp('$lte');
|
|
904
|
+
|
|
905
|
+
const $expr = (expr) => ({
|
|
906
|
+
raw: f => ({ $expr: expr.raw(f).get() }),
|
|
907
|
+
});
|
|
908
|
+
|
|
909
|
+
const dualIn = operator();
|
|
910
|
+
const $in = dualIn('$in');
|
|
911
|
+
const $nin = dualIn('$nin');
|
|
912
|
+
|
|
913
|
+
const $unwindDelta = (k1, k2, k, includeNull) => {
|
|
914
|
+
const outer = includeNull === null;
|
|
915
|
+
const newItems = {
|
|
916
|
+
$filter: {
|
|
917
|
+
input: { $ifNull: [`$after.${k2}`, []] },
|
|
918
|
+
as: 'a',
|
|
919
|
+
cond: {
|
|
920
|
+
$not: {
|
|
921
|
+
$in: [
|
|
922
|
+
'$$a._id',
|
|
923
|
+
{
|
|
924
|
+
$map: {
|
|
925
|
+
input: { $ifNull: [`$before.${k2}`, []] },
|
|
926
|
+
as: 'b',
|
|
927
|
+
in: '$$b._id',
|
|
928
|
+
},
|
|
929
|
+
},
|
|
930
|
+
],
|
|
931
|
+
},
|
|
932
|
+
},
|
|
933
|
+
},
|
|
934
|
+
};
|
|
935
|
+
const oldItems = {
|
|
936
|
+
$map: {
|
|
937
|
+
input: { $ifNull: [`$before.${k2}`, []] },
|
|
938
|
+
as: 'b',
|
|
939
|
+
in: {
|
|
940
|
+
before: '$$b',
|
|
941
|
+
after: {
|
|
942
|
+
$ifNull: [
|
|
943
|
+
{
|
|
944
|
+
$first: {
|
|
945
|
+
$filter: {
|
|
946
|
+
input: `$after.${k2}`,
|
|
947
|
+
as: 'a',
|
|
948
|
+
cond: { $eq: ['$$a._id', '$$b._id'] },
|
|
949
|
+
},
|
|
950
|
+
},
|
|
951
|
+
},
|
|
952
|
+
null,
|
|
953
|
+
],
|
|
954
|
+
},
|
|
955
|
+
},
|
|
956
|
+
},
|
|
957
|
+
};
|
|
958
|
+
const ifNull = (k, part, str = `$${k}.${part}._id`) => outer && k == k2 ? { $ifNull: [str, 'null'] } : str;
|
|
959
|
+
const interDot = ([a, b]) => [a, '.', b];
|
|
960
|
+
const partReplace = (part) => ({
|
|
961
|
+
$cond: {
|
|
962
|
+
if: { $or: [{ $eq: [`$${k1}.${part}`, null] }, { $eq: [`$${k2}.${part}`, null] }] },
|
|
963
|
+
then: null,
|
|
964
|
+
else: {
|
|
965
|
+
_id: k
|
|
966
|
+
? ifNull(k, part)
|
|
967
|
+
: {
|
|
968
|
+
$concat: interDot([k1, k2].sort().map(k => ifNull(k, part))),
|
|
969
|
+
},
|
|
970
|
+
[k1]: `$${k1}.${part}`,
|
|
971
|
+
[k2]: outer
|
|
972
|
+
? {
|
|
973
|
+
$cond: {
|
|
974
|
+
if: `$${k2}.${part}._id`,
|
|
975
|
+
then: `$${k2}.${part}`,
|
|
976
|
+
else: null,
|
|
977
|
+
},
|
|
978
|
+
}
|
|
979
|
+
: `$${k2}.${part}`,
|
|
980
|
+
},
|
|
981
|
+
},
|
|
982
|
+
});
|
|
983
|
+
const part = (k) => root().of(k).expr();
|
|
984
|
+
const stages = link()
|
|
985
|
+
.with(asStages([
|
|
986
|
+
{
|
|
987
|
+
$set: {
|
|
988
|
+
[k1]: {
|
|
989
|
+
before: { $ifNull: [`$before.${k1}`, null] },
|
|
990
|
+
after: { $ifNull: [`$after.${k1}`, null] },
|
|
991
|
+
},
|
|
992
|
+
[k2]: {
|
|
993
|
+
$concatArrays: [
|
|
994
|
+
outer
|
|
995
|
+
? {
|
|
996
|
+
$cond: {
|
|
997
|
+
if: { $eq: [`$before.${k2}`, []] },
|
|
998
|
+
then: {
|
|
999
|
+
$cond: {
|
|
1000
|
+
if: { $eq: [`$after.${k2}`, []] },
|
|
1001
|
+
then: [],
|
|
1002
|
+
else: [{ before: {}, after: null }],
|
|
1003
|
+
},
|
|
1004
|
+
},
|
|
1005
|
+
else: oldItems,
|
|
1006
|
+
},
|
|
1007
|
+
}
|
|
1008
|
+
: oldItems,
|
|
1009
|
+
{
|
|
1010
|
+
$map: {
|
|
1011
|
+
input: outer
|
|
1012
|
+
? {
|
|
1013
|
+
$cond: {
|
|
1014
|
+
if: {
|
|
1015
|
+
$and: [{ $ne: [`$before.${k2}`, []] }, { $eq: [`$after.${k2}`, []] }],
|
|
1016
|
+
},
|
|
1017
|
+
then: [{}],
|
|
1018
|
+
else: newItems,
|
|
1019
|
+
},
|
|
1020
|
+
}
|
|
1021
|
+
: newItems,
|
|
1022
|
+
as: 'a',
|
|
1023
|
+
in: { before: null, after: '$$a' },
|
|
1024
|
+
},
|
|
1025
|
+
},
|
|
1026
|
+
],
|
|
1027
|
+
},
|
|
1028
|
+
},
|
|
1029
|
+
},
|
|
1030
|
+
]))
|
|
1031
|
+
.with($unwind_(k2))
|
|
1032
|
+
.with(asStages([
|
|
774
1033
|
{
|
|
775
1034
|
$replaceWith: {
|
|
776
1035
|
_id: '$_id',
|
|
@@ -778,7 +1037,8 @@ const $unwindDelta = (k1, k2, k, includeNull) => {
|
|
|
778
1037
|
after: partReplace('after'),
|
|
779
1038
|
},
|
|
780
1039
|
},
|
|
781
|
-
]))
|
|
1040
|
+
]))
|
|
1041
|
+
.with($match_($expr(ne(part('before'))(part('after'))))).stages;
|
|
782
1042
|
return stages;
|
|
783
1043
|
};
|
|
784
1044
|
|
|
@@ -827,10 +1087,6 @@ const $lookupDelta = ({ field1, field2 }, { coll, exec, input }, k1, k2, k, incl
|
|
|
827
1087
|
})).with($unwindDelta(k1, k2, k, includeNull)).stages;
|
|
828
1088
|
};
|
|
829
1089
|
|
|
830
|
-
const $expr = (expr) => ({
|
|
831
|
-
raw: f => ({ $expr: expr.raw(f).get() }),
|
|
832
|
-
});
|
|
833
|
-
|
|
834
1090
|
const $lookupRaw = ({ field1, field2 }, { coll, exec, input }, k2, k) => (f) => {
|
|
835
1091
|
root().of('_id').expr();
|
|
836
1092
|
root().of(k2).of('_id').expr();
|
|
@@ -958,8 +1214,7 @@ const runCont = async (it, cb) => {
|
|
|
958
1214
|
return runCont(stop, cb);
|
|
959
1215
|
}
|
|
960
1216
|
const { cont, info } = res.next;
|
|
961
|
-
|
|
962
|
-
if (stopped) {
|
|
1217
|
+
if (cb?.(info)) {
|
|
963
1218
|
await clear();
|
|
964
1219
|
throw new Error('Machine stopped');
|
|
965
1220
|
}
|
|
@@ -1012,31 +1267,6 @@ const $outerLookup = (p, outer) => (l) => $lookup1({
|
|
|
1012
1267
|
left: l(emptyDelta()),
|
|
1013
1268
|
}, outer);
|
|
1014
1269
|
|
|
1015
|
-
const operator = () => (op) => (operand) => {
|
|
1016
|
-
return {
|
|
1017
|
-
raw: { [op]: operand },
|
|
1018
|
-
expr: (field) => asExpr({
|
|
1019
|
-
raw: f => asExprRaw({ [op]: [$ifNull(field.expr(), nil).raw(f).get(), operand] }),
|
|
1020
|
-
}),
|
|
1021
|
-
};
|
|
1022
|
-
};
|
|
1023
|
-
|
|
1024
|
-
const dualEq = operator();
|
|
1025
|
-
const $eq = dualEq('$eq');
|
|
1026
|
-
const $ne = dualEq('$ne');
|
|
1027
|
-
const comp = operator();
|
|
1028
|
-
const $gt = comp('$gt');
|
|
1029
|
-
const $gtTs = comp('$gt');
|
|
1030
|
-
const $gteTs = comp('$gte');
|
|
1031
|
-
const $lt = comp('$lt');
|
|
1032
|
-
const dateLt = comp('$lt');
|
|
1033
|
-
const $gte = comp('$gte');
|
|
1034
|
-
const $lte = comp('$lte');
|
|
1035
|
-
|
|
1036
|
-
const dualIn = operator();
|
|
1037
|
-
const $in = dualIn('$in');
|
|
1038
|
-
const $nin = dualIn('$nin');
|
|
1039
|
-
|
|
1040
1270
|
const make = (alter) => {
|
|
1041
1271
|
return (op, args) => alter(op, args.filter(defined));
|
|
1042
1272
|
};
|
|
@@ -1394,7 +1624,10 @@ const executes$1 = (view, input, streamName) => {
|
|
|
1394
1624
|
return step8(l);
|
|
1395
1625
|
};
|
|
1396
1626
|
const step8 = (l) => {
|
|
1397
|
-
return nextData(l.aggResult.cursor.firstBatch)(() => l.stream
|
|
1627
|
+
return nextData(l.aggResult.cursor.firstBatch)(() => l.stream
|
|
1628
|
+
.tryNext()
|
|
1629
|
+
.catch(_ => 1)
|
|
1630
|
+
.then(doc => (doc ? next(step2, 'restart') : step8(l))), 'wait for change');
|
|
1398
1631
|
};
|
|
1399
1632
|
return stop;
|
|
1400
1633
|
};
|
|
@@ -1515,241 +1748,6 @@ const executes = (view, input, streamName) => {
|
|
|
1515
1748
|
const emptyLin = () => ({ lin: link().stages });
|
|
1516
1749
|
const from = (view, streamName) => pipe(input => executes(view, input.lin, streamName), { lin: link().stages }, ({ lin: a }, { lin: b }) => ({ lin: concatStages(a, b) }), emptyLin);
|
|
1517
1750
|
|
|
1518
|
-
const dayAndMonthPart = (date) => asExpr({
|
|
1519
|
-
raw: f => asExprRaw({ $dateToString: { date: date.raw(f).get(), format: '%m-%d' } }),
|
|
1520
|
-
});
|
|
1521
|
-
const now = () => asExpr({
|
|
1522
|
-
raw: f => asExprRaw('$$NOW'),
|
|
1523
|
-
});
|
|
1524
|
-
const monthPart = (date) => asExpr({
|
|
1525
|
-
raw: f => asExprRaw({ $dateToString: { date: date.raw(f).get(), format: '%Y-%m' } }),
|
|
1526
|
-
});
|
|
1527
|
-
const weekPart = (date) => asExpr({
|
|
1528
|
-
raw: f => asExprRaw({ $dateToString: { date: date.raw(f).get(), format: '%Y-%U' } }),
|
|
1529
|
-
});
|
|
1530
|
-
const year = (date) => asExpr({
|
|
1531
|
-
raw: f => asExprRaw({ $year: date.raw(f).get() }),
|
|
1532
|
-
});
|
|
1533
|
-
const dateAdd = (date, amount, unit) => asExpr({
|
|
1534
|
-
raw: f => asExprRaw({
|
|
1535
|
-
$dateAdd: {
|
|
1536
|
-
startDate: date.raw(f).get(),
|
|
1537
|
-
unit: unit.raw(f).get(),
|
|
1538
|
-
amount: amount.raw(f).get(),
|
|
1539
|
-
},
|
|
1540
|
-
}),
|
|
1541
|
-
});
|
|
1542
|
-
const maxDate = (expr) => asExpr({
|
|
1543
|
-
raw: f => asExprRaw({ $max: expr.raw(f).get() }),
|
|
1544
|
-
});
|
|
1545
|
-
const minDate = (expr) => asExpr({
|
|
1546
|
-
raw: f => asExprRaw({ $min: expr.raw(f).get() }),
|
|
1547
|
-
});
|
|
1548
|
-
const datePart = (date) => asExpr({
|
|
1549
|
-
raw: f => asExprRaw({ $dateToString: { date: date.raw(f).get(), format: '%Y-%m-%d' } }),
|
|
1550
|
-
});
|
|
1551
|
-
const startOf = (startDate, freq, offset) => asExpr({
|
|
1552
|
-
raw: f => asExprRaw({
|
|
1553
|
-
$let: {
|
|
1554
|
-
vars: { d: startDate.raw(f).get(), f: freq.raw(f).get(), i: offset.raw(f).get() },
|
|
1555
|
-
in: {
|
|
1556
|
-
$switch: {
|
|
1557
|
-
branches: [
|
|
1558
|
-
{
|
|
1559
|
-
case: { $eq: ['$$f', 'week'] },
|
|
1560
|
-
then: {
|
|
1561
|
-
$dateFromParts: {
|
|
1562
|
-
isoWeekYear: { $isoWeekYear: '$$d' },
|
|
1563
|
-
isoWeek: {
|
|
1564
|
-
$add: [
|
|
1565
|
-
{ $isoWeek: '$$d' },
|
|
1566
|
-
{
|
|
1567
|
-
$cond: {
|
|
1568
|
-
if: {
|
|
1569
|
-
$lt: ['$$i', { $isoDayOfWeek: '$$d' }],
|
|
1570
|
-
},
|
|
1571
|
-
then: 1,
|
|
1572
|
-
else: 0,
|
|
1573
|
-
},
|
|
1574
|
-
},
|
|
1575
|
-
],
|
|
1576
|
-
},
|
|
1577
|
-
isoDayOfWeek: '$$i',
|
|
1578
|
-
},
|
|
1579
|
-
},
|
|
1580
|
-
},
|
|
1581
|
-
{
|
|
1582
|
-
case: { $eq: ['$$f', 'month'] },
|
|
1583
|
-
then: {
|
|
1584
|
-
$dateFromParts: {
|
|
1585
|
-
year: { $year: '$$d' },
|
|
1586
|
-
month: {
|
|
1587
|
-
$add: [
|
|
1588
|
-
{ $month: '$$d' },
|
|
1589
|
-
{
|
|
1590
|
-
$cond: {
|
|
1591
|
-
if: {
|
|
1592
|
-
$lt: ['$$i', { $dayOfMonth: '$$d' }],
|
|
1593
|
-
},
|
|
1594
|
-
then: 1,
|
|
1595
|
-
else: 0,
|
|
1596
|
-
},
|
|
1597
|
-
},
|
|
1598
|
-
],
|
|
1599
|
-
},
|
|
1600
|
-
day: '$$i',
|
|
1601
|
-
},
|
|
1602
|
-
},
|
|
1603
|
-
},
|
|
1604
|
-
{
|
|
1605
|
-
case: { $eq: ['$$f', 'year'] },
|
|
1606
|
-
then: {
|
|
1607
|
-
$dateFromParts: {
|
|
1608
|
-
year: {
|
|
1609
|
-
$add: [
|
|
1610
|
-
{ $year: '$$d' },
|
|
1611
|
-
{
|
|
1612
|
-
$cond: {
|
|
1613
|
-
if: {
|
|
1614
|
-
$or: [
|
|
1615
|
-
{
|
|
1616
|
-
$lt: [{ $floor: { $divide: ['$$i', 100] } }, { $month: '$$d' }],
|
|
1617
|
-
},
|
|
1618
|
-
{
|
|
1619
|
-
$and: [
|
|
1620
|
-
{
|
|
1621
|
-
$eq: [
|
|
1622
|
-
{ $floor: { $divide: ['$$i', 100] } },
|
|
1623
|
-
{ $month: '$$d' },
|
|
1624
|
-
],
|
|
1625
|
-
},
|
|
1626
|
-
{
|
|
1627
|
-
$lt: [{ $mod: ['$$i', 100] }, { $dayOfMonth: '$$d' }],
|
|
1628
|
-
},
|
|
1629
|
-
],
|
|
1630
|
-
},
|
|
1631
|
-
],
|
|
1632
|
-
},
|
|
1633
|
-
then: 1,
|
|
1634
|
-
else: 0,
|
|
1635
|
-
},
|
|
1636
|
-
},
|
|
1637
|
-
],
|
|
1638
|
-
},
|
|
1639
|
-
month: { $floor: { $divide: ['$$i', 100] } },
|
|
1640
|
-
day: { $mod: ['$$i', 100] },
|
|
1641
|
-
},
|
|
1642
|
-
},
|
|
1643
|
-
},
|
|
1644
|
-
],
|
|
1645
|
-
default: {
|
|
1646
|
-
$dateFromParts: {
|
|
1647
|
-
year: { $year: '$$d' },
|
|
1648
|
-
month: { $month: '$$d' },
|
|
1649
|
-
day: { $add: [{ $dayOfMonth: '$$d' }, '$$i'] },
|
|
1650
|
-
},
|
|
1651
|
-
},
|
|
1652
|
-
},
|
|
1653
|
-
},
|
|
1654
|
-
},
|
|
1655
|
-
}),
|
|
1656
|
-
});
|
|
1657
|
-
const dateDiff = ({ end, unit, start, }) => asExpr({
|
|
1658
|
-
raw: f => asExprRaw({
|
|
1659
|
-
$let: {
|
|
1660
|
-
vars: {
|
|
1661
|
-
f: unit.raw(f).get(),
|
|
1662
|
-
end: end.raw(f).get(),
|
|
1663
|
-
start: start.raw(f).get(),
|
|
1664
|
-
},
|
|
1665
|
-
in: {
|
|
1666
|
-
$let: {
|
|
1667
|
-
vars: {
|
|
1668
|
-
diff: {
|
|
1669
|
-
$dateDiff: {
|
|
1670
|
-
startDate: '$$start',
|
|
1671
|
-
endDate: '$$end',
|
|
1672
|
-
unit: '$$f',
|
|
1673
|
-
},
|
|
1674
|
-
},
|
|
1675
|
-
},
|
|
1676
|
-
in: {
|
|
1677
|
-
$switch: {
|
|
1678
|
-
branches: [
|
|
1679
|
-
{
|
|
1680
|
-
case: { $eq: ['$$f', 'month'] },
|
|
1681
|
-
then: {
|
|
1682
|
-
$cond: {
|
|
1683
|
-
if: {
|
|
1684
|
-
$lte: [{ $dayOfMonth: '$$start' }, { $dayOfMonth: '$$end' }],
|
|
1685
|
-
},
|
|
1686
|
-
then: '$$diff',
|
|
1687
|
-
else: { $subtract: ['$$diff', 1] },
|
|
1688
|
-
},
|
|
1689
|
-
},
|
|
1690
|
-
},
|
|
1691
|
-
{
|
|
1692
|
-
case: { $eq: ['$$f', 'week'] },
|
|
1693
|
-
then: {
|
|
1694
|
-
$cond: {
|
|
1695
|
-
if: {
|
|
1696
|
-
$lte: [{ $isoDayOfWeek: '$$start' }, { $isoDayOfWeek: '$$end' }],
|
|
1697
|
-
},
|
|
1698
|
-
then: '$$diff',
|
|
1699
|
-
else: { $subtract: ['$$diff', 1] },
|
|
1700
|
-
},
|
|
1701
|
-
},
|
|
1702
|
-
},
|
|
1703
|
-
{
|
|
1704
|
-
case: { $eq: ['$$f', 'year'] },
|
|
1705
|
-
then: {
|
|
1706
|
-
$cond: {
|
|
1707
|
-
if: {
|
|
1708
|
-
$or: [
|
|
1709
|
-
{
|
|
1710
|
-
$lt: [{ $month: '$$start' }, { $month: '$$end' }],
|
|
1711
|
-
},
|
|
1712
|
-
{
|
|
1713
|
-
$and: [
|
|
1714
|
-
{
|
|
1715
|
-
$eq: [{ $month: '$$start' }, { $month: '$$end' }],
|
|
1716
|
-
},
|
|
1717
|
-
{
|
|
1718
|
-
$lte: [{ $dayOfMonth: '$$start' }, { $dayOfMonth: '$$end' }],
|
|
1719
|
-
},
|
|
1720
|
-
],
|
|
1721
|
-
},
|
|
1722
|
-
],
|
|
1723
|
-
},
|
|
1724
|
-
then: '$$diff',
|
|
1725
|
-
else: { $subtract: ['$$diff', 1] },
|
|
1726
|
-
},
|
|
1727
|
-
},
|
|
1728
|
-
},
|
|
1729
|
-
],
|
|
1730
|
-
default: '$$diff',
|
|
1731
|
-
},
|
|
1732
|
-
},
|
|
1733
|
-
},
|
|
1734
|
-
},
|
|
1735
|
-
},
|
|
1736
|
-
}),
|
|
1737
|
-
});
|
|
1738
|
-
|
|
1739
|
-
const range = (start, end, step) => asExpr({
|
|
1740
|
-
raw: f => asExprRaw({ $range: [start.raw(f).get(), end.raw(f).get(), step?.raw(f).get() ?? 1] }),
|
|
1741
|
-
});
|
|
1742
|
-
const $map1 = (ex, map) => asExpr({
|
|
1743
|
-
raw: f => asExprRaw({
|
|
1744
|
-
$map: {
|
|
1745
|
-
input: ex.raw(f).get(),
|
|
1746
|
-
as: 'item',
|
|
1747
|
-
in: map(ctx()('item')).raw(f).get(),
|
|
1748
|
-
},
|
|
1749
|
-
}),
|
|
1750
|
-
});
|
|
1751
|
-
const $map = (ex, map) => $map1(ex, i => map(i.expr()));
|
|
1752
|
-
|
|
1753
1751
|
require('dotenv').config();
|
|
1754
1752
|
const uri = process.env['MONGO_URL'];
|
|
1755
1753
|
|