Skip to content

Commit 7f9fc03

Browse files
fix: remove unwanted changes
1 parent 628a9a7 commit 7f9fc03

File tree

1 file changed

+43
-43
lines changed

1 file changed

+43
-43
lines changed

src/Adapters/Storage/Mongo/MongoTransform.js

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -651,10 +651,10 @@ function transformTopLevelAtom(atom, field) {
651651
// If it is not a valid constraint but it could be a valid something
652652
// else, return CannotTransform.
653653
// inArray is whether this is an array field.
654-
function transformConstraint(constraint, field, key, count = false) {
654+
function transformConstraint(constraint, field, queryKey, count = false) {
655655
const inArray = field && field.type && field.type === 'Array';
656656
// Check wether the given key has `.`
657-
const isNestedKey = key.indexOf('.') > -1;
657+
const isNestedKey = queryKey.indexOf('.') > -1;
658658
if (typeof constraint !== 'object' || !constraint) {
659659
return CannotTransform;
660660
}
@@ -671,18 +671,18 @@ function transformConstraint(constraint, field, key, count = false) {
671671
// This is a hack so that:
672672
// $regex is handled before $options
673673
// $nearSphere is handled before $maxDistance
674-
var constraintKeys = Object.keys(constraint).sort().reverse();
674+
var keys = Object.keys(constraint).sort().reverse();
675675
var answer = {};
676-
for (var constraintKey of constraintKeys) {
677-
switch (constraintKey) {
676+
for (var key of keys) {
677+
switch (key) {
678678
case '$lt':
679679
case '$lte':
680680
case '$gt':
681681
case '$gte':
682682
case '$exists':
683683
case '$ne':
684684
case '$eq': {
685-
const val = constraint[constraintKey];
685+
const val = constraint[key];
686686
if (val && typeof val === 'object' && val.$relativeTime) {
687687
if (field && field.type !== 'Date') {
688688
throw new Parse.Error(
@@ -691,7 +691,7 @@ function transformConstraint(constraint, field, key, count = false) {
691691
);
692692
}
693693

694-
switch (constraintKey) {
694+
switch (key) {
695695
case '$exists':
696696
case '$ne':
697697
case '$eq':
@@ -703,28 +703,28 @@ function transformConstraint(constraint, field, key, count = false) {
703703

704704
const parserResult = Utils.relativeTimeToDate(val.$relativeTime);
705705
if (parserResult.status === 'success') {
706-
answer[constraintKey] = parserResult.result;
706+
answer[key] = parserResult.result;
707707
break;
708708
}
709709

710710
log.info('Error while parsing relative date', parserResult);
711711
throw new Parse.Error(
712712
Parse.Error.INVALID_JSON,
713-
`bad $relativeTime (${constraintKey}) value. ${parserResult.info}`
713+
`bad $relativeTime (${key}) value. ${parserResult.info}`
714714
);
715715
}
716716

717-
answer[constraintKey] = transformer(val);
717+
answer[key] = transformer(val);
718718
break;
719719
}
720720

721721
case '$in':
722722
case '$nin': {
723-
const arr = constraint[constraintKey];
723+
const arr = constraint[key];
724724
if (!(arr instanceof Array)) {
725-
throw new Parse.Error(Parse.Error.INVALID_JSON, 'bad ' + constraintKey + ' value');
725+
throw new Parse.Error(Parse.Error.INVALID_JSON, 'bad ' + key + ' value');
726726
}
727-
answer[constraintKey] = _.flatMap(arr, value => {
727+
answer[key] = _.flatMap(arr, value => {
728728
return (atom => {
729729
if (Array.isArray(atom)) {
730730
return value.map(transformer);
@@ -736,13 +736,13 @@ function transformConstraint(constraint, field, key, count = false) {
736736
break;
737737
}
738738
case '$all': {
739-
const arr = constraint[constraintKey];
739+
const arr = constraint[key];
740740
if (!(arr instanceof Array)) {
741-
throw new Parse.Error(Parse.Error.INVALID_JSON, 'bad ' + constraintKey + ' value');
741+
throw new Parse.Error(Parse.Error.INVALID_JSON, 'bad ' + key + ' value');
742742
}
743-
answer[constraintKey] = arr.map(transformInteriorAtom);
743+
answer[key] = arr.map(transformInteriorAtom);
744744

745-
const values = answer[constraintKey];
745+
const values = answer[key];
746746
if (isAnyValueRegex(values) && !isAllValuesRegexOrNone(values)) {
747747
throw new Parse.Error(
748748
Parse.Error.INVALID_JSON,
@@ -753,15 +753,15 @@ function transformConstraint(constraint, field, key, count = false) {
753753
break;
754754
}
755755
case '$regex':
756-
var s = constraint[constraintKey];
756+
var s = constraint[key];
757757
if (typeof s !== 'string') {
758758
throw new Parse.Error(Parse.Error.INVALID_JSON, 'bad regex: ' + s);
759759
}
760-
answer[constraintKey] = s;
760+
answer[key] = s;
761761
break;
762762

763763
case '$containedBy': {
764-
const arr = constraint[constraintKey];
764+
const arr = constraint[key];
765765
if (!(arr instanceof Array)) {
766766
throw new Parse.Error(Parse.Error.INVALID_JSON, `bad $containedBy: should be an array`);
767767
}
@@ -771,87 +771,87 @@ function transformConstraint(constraint, field, key, count = false) {
771771
break;
772772
}
773773
case '$options':
774-
answer[constraintKey] = constraint[constraintKey];
774+
answer[key] = constraint[key];
775775
break;
776776

777777
case '$text': {
778-
const search = constraint[constraintKey].$search;
778+
const search = constraint[key].$search;
779779
if (typeof search !== 'object') {
780780
throw new Parse.Error(Parse.Error.INVALID_JSON, `bad $text: $search, should be object`);
781781
}
782782
if (!search.$term || typeof search.$term !== 'string') {
783783
throw new Parse.Error(Parse.Error.INVALID_JSON, `bad $text: $term, should be string`);
784784
} else {
785-
answer[constraintKey] = {
785+
answer[key] = {
786786
$search: search.$term,
787787
};
788788
}
789789
if (search.$language && typeof search.$language !== 'string') {
790790
throw new Parse.Error(Parse.Error.INVALID_JSON, `bad $text: $language, should be string`);
791791
} else if (search.$language) {
792-
answer[constraintKey].$language = search.$language;
792+
answer[key].$language = search.$language;
793793
}
794794
if (search.$caseSensitive && typeof search.$caseSensitive !== 'boolean') {
795795
throw new Parse.Error(
796796
Parse.Error.INVALID_JSON,
797797
`bad $text: $caseSensitive, should be boolean`
798798
);
799799
} else if (search.$caseSensitive) {
800-
answer[constraintKey].$caseSensitive = search.$caseSensitive;
800+
answer[key].$caseSensitive = search.$caseSensitive;
801801
}
802802
if (search.$diacriticSensitive && typeof search.$diacriticSensitive !== 'boolean') {
803803
throw new Parse.Error(
804804
Parse.Error.INVALID_JSON,
805805
`bad $text: $diacriticSensitive, should be boolean`
806806
);
807807
} else if (search.$diacriticSensitive) {
808-
answer[constraintKey].$diacriticSensitive = search.$diacriticSensitive;
808+
answer[key].$diacriticSensitive = search.$diacriticSensitive;
809809
}
810810
break;
811811
}
812812
case '$nearSphere': {
813-
const point = constraint[constraintKey];
813+
const point = constraint[key];
814814
if (count) {
815815
answer.$geoWithin = {
816816
$centerSphere: [[point.longitude, point.latitude], constraint.$maxDistance],
817817
};
818818
} else {
819-
answer[constraintKey] = [point.longitude, point.latitude];
819+
answer[key] = [point.longitude, point.latitude];
820820
}
821821
break;
822822
}
823823
case '$maxDistance': {
824824
if (count) {
825825
break;
826826
}
827-
answer[constraintKey] = constraint[constraintKey];
827+
answer[key] = constraint[key];
828828
break;
829829
}
830830
// The SDKs don't seem to use these but they are documented in the
831831
// REST API docs.
832832
case '$maxDistanceInRadians':
833-
answer['$maxDistance'] = constraint[constraintKey];
833+
answer['$maxDistance'] = constraint[key];
834834
break;
835835
case '$maxDistanceInMiles':
836-
answer['$maxDistance'] = constraint[constraintKey] / 3959;
836+
answer['$maxDistance'] = constraint[key] / 3959;
837837
break;
838838
case '$maxDistanceInKilometers':
839-
answer['$maxDistance'] = constraint[constraintKey] / 6371;
839+
answer['$maxDistance'] = constraint[key] / 6371;
840840
break;
841841

842842
case '$select':
843843
case '$dontSelect':
844844
throw new Parse.Error(
845845
Parse.Error.COMMAND_UNAVAILABLE,
846-
'the ' + constraintKey + ' constraint is not supported yet'
846+
'the ' + key + ' constraint is not supported yet'
847847
);
848848

849849
case '$within':
850-
var box = constraint[constraintKey]['$box'];
850+
var box = constraint[key]['$box'];
851851
if (!box || box.length != 2) {
852852
throw new Parse.Error(Parse.Error.INVALID_JSON, 'malformatted $within arg');
853853
}
854-
answer[constraintKey] = {
854+
answer[key] = {
855855
$box: [
856856
[box[0].longitude, box[0].latitude],
857857
[box[1].longitude, box[1].latitude],
@@ -860,8 +860,8 @@ function transformConstraint(constraint, field, key, count = false) {
860860
break;
861861

862862
case '$geoWithin': {
863-
const polygon = constraint[constraintKey]['$polygon'];
864-
const centerSphere = constraint[constraintKey]['$centerSphere'];
863+
const polygon = constraint[key]['$polygon'];
864+
const centerSphere = constraint[key]['$centerSphere'];
865865
if (polygon !== undefined) {
866866
let points;
867867
if (typeof polygon === 'object' && polygon.__type === 'Polygon') {
@@ -898,7 +898,7 @@ function transformConstraint(constraint, field, key, count = false) {
898898
}
899899
return [point.longitude, point.latitude];
900900
});
901-
answer[constraintKey] = {
901+
answer[key] = {
902902
$polygon: points,
903903
};
904904
} else if (centerSphere !== undefined) {
@@ -927,14 +927,14 @@ function transformConstraint(constraint, field, key, count = false) {
927927
'bad $geoWithin value; $centerSphere distance invalid'
928928
);
929929
}
930-
answer[constraintKey] = {
930+
answer[key] = {
931931
$centerSphere: [[point.longitude, point.latitude], distance],
932932
};
933933
}
934934
break;
935935
}
936936
case '$geoIntersects': {
937-
const point = constraint[constraintKey]['$point'];
937+
const point = constraint[key]['$point'];
938938
if (!GeoPointCoder.isValidJSON(point)) {
939939
throw new Parse.Error(
940940
Parse.Error.INVALID_JSON,
@@ -943,7 +943,7 @@ function transformConstraint(constraint, field, key, count = false) {
943943
} else {
944944
Parse.GeoPoint._validate(point.latitude, point.longitude);
945945
}
946-
answer[constraintKey] = {
946+
answer[key] = {
947947
$geometry: {
948948
type: 'Point',
949949
coordinates: [point.longitude, point.latitude],
@@ -952,8 +952,8 @@ function transformConstraint(constraint, field, key, count = false) {
952952
break;
953953
}
954954
default:
955-
if (constraintKey.match(/^\$+/)) {
956-
throw new Parse.Error(Parse.Error.INVALID_JSON, 'bad constraint: ' + constraintKey);
955+
if (key.match(/^\$+/)) {
956+
throw new Parse.Error(Parse.Error.INVALID_JSON, 'bad constraint: ' + key);
957957
}
958958
return CannotTransform;
959959
}

0 commit comments

Comments
 (0)