Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions Parse/Internal/Commands/PFRESTCommand.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import "PFRESTCommand.h"
#import "PFRESTCommand_Private.h"

#import "PFAssert.h"
#import "PFCoreManager.h"
#import "PFFieldOperation.h"
#import "PFHTTPRequest.h"
Expand Down Expand Up @@ -159,10 +160,8 @@ - (void)maybeChangeServerOperation {
}
}

if ([self.httpMethod isEqualToString:PFHTTPRequestMethodDELETE] && !objectId) {
[NSException raise:NSInternalInconsistencyException
format:@"Attempt to delete non-existent object."];
}
PFConsistencyAssert(![self.httpMethod isEqualToString:PFHTTPRequestMethodDELETE] || objectId,
@"Attempt to delete non-existent object.");
}
}

Expand Down
30 changes: 6 additions & 24 deletions Parse/Internal/Commands/PFRESTQueryCommand.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#import "PFRESTQueryCommand.h"

#import "PFAssert.h"
#import "PFEncoder.h"
#import "PFHTTPRequest.h"
#import "PFQueryPrivate.h"
Expand Down Expand Up @@ -133,30 +134,11 @@ + (NSDictionary *)findCommandParametersWithOrder:(NSString *)order
NSMutableArray *newArray = [NSMutableArray array];
for (PFQuery *subquery in array) {
// TODO: (nlutsenko) Move this validation into PFQuery/PFQueryState.
if (subquery.state.limit >= 0) {
[NSException raise:NSInvalidArgumentException
format:@"OR queries do not support sub queries with limits"];
}

if (subquery.state.skip > 0) {
[NSException raise:NSInvalidArgumentException
format:@"OR queries do not support sub queries with skip"];
}

if ([subquery.state.sortKeys count]) {
[NSException raise:NSInvalidArgumentException
format:@"OR queries do not support sub queries with order"];
}

if ([subquery.state.includedKeys count] > 0) {
[NSException raise:NSInvalidArgumentException
format:@"OR queries do not support sub-queries with includes"];
}

if (subquery.state.selectedKeys) {
[NSException raise:NSInvalidArgumentException
format:@"OR queries do not support sub-queries with selectKeys"];
}
PFParameterAssert(subquery.state.limit < 0, @"OR queries do not support sub queries with limits");
PFParameterAssert(subquery.state.skip == 0, @"OR queries do not support sub queries with skip");
PFParameterAssert(subquery.state.sortKeys.count == 0, @"OR queries do not support sub queries with order");
PFParameterAssert(subquery.state.includedKeys.count == 0, @"OR queries do not support sub-queries with includes");
PFParameterAssert(subquery.state.selectedKeys == nil, @"OR queries do not support sub-queries with selectKeys");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a .count like the others? I wasn't sure as it seemed suspect.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be checking for nil, since empty array there would mean that we should not fetch any keys explicitly.


NSDictionary *queryDict = [self findCommandParametersWithOrder:subquery.state.sortOrderString
conditions:subquery.state.conditions
Expand Down
168 changes: 67 additions & 101 deletions Parse/Internal/FieldOperation/PFFieldOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,9 @@ - (PFFieldOperation *)mergeWithPrevious:(PFFieldOperation *)previous {
NSNumber *newAmount = [PFInternalUtils addNumber:self.amount
withNumber:((PFIncrementOperation *)previous).amount];
return [PFIncrementOperation incrementWithAmount:newAmount];
} else {
@throw [NSException exceptionWithName:NSInternalInconsistencyException
reason:@"Operation is invalid after previous operation."
userInfo:nil];
}
[NSException raise:NSInternalInconsistencyException format:@"Operation is invalid after previous operation."];
return nil;
}

- (id)applyToValue:(id)oldValue forKey:(NSString *)key {
Expand Down Expand Up @@ -210,31 +208,26 @@ - (PFFieldOperation *)mergeWithPrevious:(PFFieldOperation *)previous {
NSArray *newArray = [oldArray arrayByAddingObjectsFromArray:self.objects];
return [PFSetOperation setWithValue:newArray];
} else {
@throw [NSException exceptionWithName:NSInternalInconsistencyException
reason:@"You can't add an item to a non-array."
userInfo:nil];
[NSException raise:NSInternalInconsistencyException format:@"You can't add an item to a non-array."];
return nil;
}
} else if ([previous isKindOfClass:[PFAddOperation class]]) {
NSMutableArray *newObjects = [((PFAddOperation *)previous).objects mutableCopy];
[newObjects addObjectsFromArray:self.objects];
return [[self class] addWithObjects:newObjects];
} else {
@throw [NSException exceptionWithName:NSInternalInconsistencyException
reason:@"Operation is invalid after previous operation."
userInfo:nil];
}
[NSException raise:NSInternalInconsistencyException format:@"Operation is invalid after previous operation."];
return nil;
}

- (id)applyToValue:(id)oldValue forKey:(NSString *)key {
if (!oldValue) {
return [self.objects mutableCopy];
} else if ([oldValue isKindOfClass:[NSArray class]]) {
return [((NSArray *)oldValue)arrayByAddingObjectsFromArray:self.objects];
} else {
@throw [NSException exceptionWithName:NSInternalInconsistencyException
reason:@"Operation is invalid after previous operation."
userInfo:nil];
}
[NSException raise:NSInternalInconsistencyException format:@"Operation is invalid after previous operation."];
return nil;
}

@end
Expand Down Expand Up @@ -274,18 +267,15 @@ - (PFFieldOperation *)mergeWithPrevious:(PFFieldOperation *)previous {
NSArray *oldArray = (((PFSetOperation *)previous).value);
return [PFSetOperation setWithValue:[self applyToValue:oldArray forKey:nil]];
} else {
@throw [NSException exceptionWithName:NSInternalInconsistencyException
reason:@"You can't add an item to a non-array."
userInfo:nil];
[NSException raise:NSInternalInconsistencyException format:@"Operation is invalid after previous operation."];
return nil;
}
} else if ([previous isKindOfClass:[PFAddUniqueOperation class]]) {
NSArray *previousObjects = ((PFAddUniqueOperation *)previous).objects;
return [[self class] addUniqueWithObjects:[self applyToValue:previousObjects forKey:nil]];
} else {
@throw [NSException exceptionWithName:NSInternalInconsistencyException
reason:@"Operation is invalid after previous operation."
userInfo:nil];
}
[NSException raise:NSInternalInconsistencyException format:@"Operation is invalid after previous operation."];
return nil;
}

- (id)applyToValue:(id)oldValue forKey:(NSString *)key {
Expand All @@ -311,11 +301,9 @@ - (id)applyToValue:(id)oldValue forKey:(NSString *)key {
}
}
return newValue;
} else {
@throw [NSException exceptionWithName:NSInternalInconsistencyException
reason:@"Operation is invalid after previous operation."
userInfo:nil];
}
[NSException raise:NSInternalInconsistencyException format:@"Operation is invalid after previous operation."];
return nil;
}

@end
Expand Down Expand Up @@ -348,26 +336,23 @@ - (PFFieldOperation *)mergeWithPrevious:(PFFieldOperation *)previous {
if (!previous) {
return self;
} else if ([previous isKindOfClass:[PFDeleteOperation class]]) {
@throw [NSException exceptionWithName:NSInternalInconsistencyException
reason:@"You can't remove items from a deleted array."
userInfo:nil];
[NSException raise:NSInternalInconsistencyException format:@"Operation is invalid after previous operation."];
return nil;
} else if ([previous isKindOfClass:[PFSetOperation class]]) {
if ([((PFSetOperation *)previous).value isKindOfClass:[NSArray class]]) {
NSArray *oldArray = ((PFSetOperation *)previous).value;
return [PFSetOperation setWithValue:[self applyToValue:oldArray forKey:nil]];
} else {
@throw [NSException exceptionWithName:NSInternalInconsistencyException
reason:@"You can't add an item to a non-array."
userInfo:nil];
[NSException raise:NSInternalInconsistencyException format:@"Operation is invalid after previous operation."];
return nil;
}
} else if ([previous isKindOfClass:[PFRemoveOperation class]]) {
NSArray *newObjects = [((PFRemoveOperation *)previous).objects arrayByAddingObjectsFromArray:self.objects];
return [PFRemoveOperation removeWithObjects:newObjects];
} else {
@throw [NSException exceptionWithName:NSInternalInconsistencyException
reason:@"Operation is invalid after previous operation."
userInfo:nil];
}

[NSException raise:NSInternalInconsistencyException format:@"Operation is invalid after previous operation."];
return nil;
}

- (id)applyToValue:(id)oldValue forKey:(NSString *)key {
Expand All @@ -393,11 +378,9 @@ - (id)applyToValue:(id)oldValue forKey:(NSString *)key {
}
}
return newValue;
} else {
@throw [NSException exceptionWithName:NSInternalInconsistencyException
reason:@"Operation is invalid after previous operation."
userInfo:nil];
}
[NSException raise:NSInternalInconsistencyException format:@"Operation is invalid after previous operation."];
return nil;
}

@end
Expand Down Expand Up @@ -426,10 +409,8 @@ + (instancetype)addRelationToObjects:(NSArray *)targets {
}

for (PFObject *target in targets) {
if (![[target parseClassName] isEqualToString:op.targetClass]) {
[NSException raise:NSInvalidArgumentException
format:@"All objects in a relation must be of the same class."];
}
PFParameterAssert([target.parseClassName isEqualToString:op.targetClass],
@"All objects in a relation must be of the same class.");
[op.relationsToAdd addObject:target];
}

Expand All @@ -443,10 +424,8 @@ + (instancetype)removeRelationToObjects:(NSArray *)targets {
}

for (PFObject *target in targets) {
if (![[target parseClassName] isEqualToString:operation.targetClass]) {
[NSException raise:NSInvalidArgumentException
format:@"All objects in a relation must be of the same class."];
}
PFParameterAssert([target.parseClassName isEqualToString:operation.targetClass],
@"All objects in a relation must be of the same class.");
[operation.relationsToRemove addObject:target];
}

Expand Down Expand Up @@ -496,57 +475,48 @@ - (id)encodeWithObjectEncoder:(PFEncoder *)objectEncoder {
return removeDict;
}

@throw [NSException exceptionWithName:NSInternalInconsistencyException
reason:@"A PFRelationOperation was created without any data."
userInfo:nil];
[NSException raise:NSInternalInconsistencyException format:@"A PFRelationOperation was created without any data."];
return nil;
}

- (PFFieldOperation *)mergeWithPrevious:(PFFieldOperation *)previous {
if (!previous) {
return self;
} else if ([previous isKindOfClass:[PFDeleteOperation class]]) {
@throw [NSException exceptionWithName:NSInternalInconsistencyException
reason:@"You can't modify a relation after deleting it."
userInfo:nil];
} else if ([previous isKindOfClass:[PFRelationOperation class]]) {
PFRelationOperation *previousOperation = (PFRelationOperation *)previous;
if (previousOperation.targetClass &&
![previousOperation.targetClass isEqualToString:self.targetClass]) {
[NSException raise:NSInvalidArgumentException
format:@"Related object object must be of class %@, but %@ was passed in",
previousOperation.targetClass,
self.targetClass];
} else {
//TODO: (nlutsenko) This logic seems to be messed up. We should return a new operation here, also merging logic seems funky.
NSSet *newRelationsToAdd = [self.relationsToAdd copy];
NSSet *newRelationsToRemove = [self.relationsToRemove copy];
[self.relationsToAdd removeAllObjects];
[self.relationsToRemove removeAllObjects];

for (NSString *objectId in previousOperation.relationsToAdd) {
[self.relationsToRemove removeObject:objectId];
[self.relationsToAdd addObject:objectId];
}
for (NSString *objectId in previousOperation.relationsToRemove) {
[self.relationsToRemove removeObject:objectId];
[self.relationsToRemove addObject:objectId];
}
}

for (NSString *objectId in newRelationsToAdd) {
[self.relationsToRemove removeObject:objectId];
[self.relationsToAdd addObject:objectId];
}
for (NSString *objectId in newRelationsToRemove) {
[self.relationsToRemove removeObject:objectId];
[self.relationsToRemove addObject:objectId];
}
}
return self;
} else {
@throw [NSException exceptionWithName:NSInternalInconsistencyException
reason:@"Operation is invalid after previous operation."
userInfo:nil];
PFConsistencyAssert(![previous isKindOfClass:[PFDeleteOperation class]], @"You can't modify a relation after deleting it");
PFConsistencyAssert([previous isKindOfClass:[PFRelationOperation class]], @"Operation is invalid after previous operation");

PFRelationOperation *previousOperation = (PFRelationOperation *)previous;

PFParameterAssert(!previousOperation.targetClass || [previousOperation.targetClass isEqualToString:self.targetClass],
@"Related object object must be of class %@, but %@ was passed in",
previousOperation.targetClass, self.targetClass);

//TODO: (nlutsenko) This logic seems to be messed up. We should return a new operation here, also merging logic seems funky.
NSSet *newRelationsToAdd = [self.relationsToAdd copy];
NSSet *newRelationsToRemove = [self.relationsToRemove copy];
[self.relationsToAdd removeAllObjects];
[self.relationsToRemove removeAllObjects];

for (NSString *objectId in previousOperation.relationsToAdd) {
[self.relationsToRemove removeObject:objectId];
[self.relationsToAdd addObject:objectId];
}
for (NSString *objectId in previousOperation.relationsToRemove) {
[self.relationsToRemove removeObject:objectId];
[self.relationsToRemove addObject:objectId];
}

for (NSString *objectId in newRelationsToAdd) {
[self.relationsToRemove removeObject:objectId];
[self.relationsToAdd addObject:objectId];
}
for (NSString *objectId in newRelationsToRemove) {
[self.relationsToRemove removeObject:objectId];
[self.relationsToRemove addObject:objectId];
}
return self;
}

- (id)applyToValue:(id)oldValue forKey:(NSString *)key {
Expand All @@ -557,20 +527,16 @@ - (id)applyToValue:(id)oldValue forKey:(NSString *)key {
relation = oldValue;
if (self.targetClass) {
if (relation.targetClass) {
if (![relation.targetClass isEqualToString:targetClass]) {
[NSException raise:NSInvalidArgumentException
format:@"Related object object must be of class %@, but %@ was passed in",
relation.targetClass,
self.targetClass];
}
PFParameterAssert([relation.targetClass isEqualToString:targetClass],
@"Related object object must be of class %@, but %@ was passed in",
relation.targetClass, self.targetClass);
} else {
relation.targetClass = self.targetClass;
}
}
} else {
@throw [NSException exceptionWithName:NSInternalInconsistencyException
reason:@"Operation is invalid after previous operation."
userInfo:nil];
[NSException raise:NSInternalInconsistencyException format:@"Operation is invalid after previous operation."];
return nil;
}

for (PFObject *object in self.relationsToAdd) {
Expand Down
Loading