Skip to content

Commit

Permalink
Merge branch 'release/3.5.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Barros committed Jun 5, 2017
2 parents f4d0f0c + f9048b7 commit 3a2e730
Show file tree
Hide file tree
Showing 76 changed files with 2,729 additions and 755 deletions.
3 changes: 0 additions & 3 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
coverage:
range: 80..100
round: down
precision: 2
ignore:
- Kinvey/KinveyApp/**/*
- Kinvey/KinveyTests/**/*
Expand Down
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ before_script:
- if [ ! -d "Carthage/Build/iOS/KIF.framework" ]; then
carthage build --platform iOS KIF;
fi
- if [ ! -d "Carthage/Build/iOS/Nimble.framework" ]; then
carthage build --platform iOS Nimble;
fi
- date
script:
- travis_retry make test
Expand Down
1 change: 1 addition & 0 deletions Cartfile.private
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
github "kif-framework/KIF" ~> 3.5
github "Quick/Nimble" ~> 7.0
5 changes: 3 additions & 2 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
github "kif-framework/KIF" "v3.5.2"
github "kishikawakatsumi/KeychainAccess" "v3.0.2"
github "tjboneman/NSPredicate-MongoDB-Adaptor" "2444d4a790527eb5c9fcb4e4f7b4af417048ae18"
github "Quick/Nimble" "v7.0.0"
github "Hearst-DD/ObjectMapper" "2.2.6"
github "mxcl/PromiseKit" "4.2.0"
github "mxcl/PromiseKit" "4.2.1"
github "DaveWoodCom/XCGLogger" "4.0.0"
github "realm/realm-cocoa" "v2.6.2"
github "realm/realm-cocoa" "v2.7.0"
2 changes: 1 addition & 1 deletion Kinvey.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
#

s.name = "Kinvey"
s.version = "3.5.1"
s.version = "3.5.2"
s.summary = "Kinvey iOS SDK"

# This description is used to generate tags and improve search results.
Expand Down
186 changes: 184 additions & 2 deletions Kinvey/Kinvey.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions Kinvey/Kinvey.xcodeproj/xcshareddata/xcschemes/Kinvey.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,16 @@
ReferencedContainer = "container:Kinvey.xcodeproj">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "5771CD3A1ECF6CDC0057E505"
BuildableName = "KinveyTests Forgot To Call Super.xctest"
BlueprintName = "KinveyTests Forgot To Call Super"
ReferencedContainer = "container:Kinvey.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
Expand All @@ -163,6 +173,11 @@
value = "disable"
isEnabled = "YES">
</EnvironmentVariable>
<EnvironmentVariable
key = "CFNETWORK_DIAGNOSTICS"
value = "3"
isEnabled = "NO">
</EnvironmentVariable>
</EnvironmentVariables>
<AdditionalOptions>
</AdditionalOptions>
Expand Down
83 changes: 35 additions & 48 deletions Kinvey/Kinvey/Acl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,7 @@ class AclTransformType: TransformType {
}

/// This class represents the ACL (Access Control List) for a record.
public final class Acl: Object, Mappable, BuilderType {

static let CreatorKey = "creator"
static let GlobalReadKey = "gr"
static let GlobalWriteKey = "gw"
static let ReadersKey = "r"
static let WritersKey = "w"
public final class Acl: Object, BuilderType {

/// The `userId` of the `User` used to create the record.
open dynamic var creator: String?
Expand Down Expand Up @@ -100,71 +94,64 @@ public final class Acl: Object, Mappable, BuilderType {
}

/// Constructs an Acl instance with the `userId` of the `User` used to create the record.
public init(
public convenience init(
creator: String,
globalRead: Bool? = nil,
globalWrite: Bool? = nil,
readers: [String]? = nil,
writers: [String]? = nil
) {
self.init()
self.creator = creator
self.globalRead.value = globalRead
self.globalWrite.value = globalWrite
super.init()
self.readers = readers
self.writers = writers
}

/// Constructor that validates if the map contains at least the creator.
public required convenience init?(map: Map) {
var creator: String?

creator <- map[Acl.CreatorKey]

guard let creatorValue = creator else {
self.init()
return nil
}

self.init(creator: creatorValue)
}

/// Default Constructor.
public required init() {
super.init()
}

/**
WARNING: This is an internal initializer not intended for public use.
:nodoc:
*/
public required init(value: Any, schema: RLMSchema) {
super.init(value: value, schema: schema)
open override class func ignoredProperties() -> [String] {
return ["readers", "writers"]
}

}

extension Acl: Mappable {

/**
WARNING: This is an internal initializer not intended for public use.
:nodoc:
*/
public required init(realm: RLMRealm, schema: RLMObjectSchema) {
super.init(realm: realm, schema: schema)
/// Constructor that validates if the map contains at least the creator.
public convenience init?(map: Map) {
guard let _: String = map[Acl.Key.creator].value() else {
self.init()
return nil
}

self.init()
}

/// This function is where all variable mappings should occur. It is executed by Mapper during the mapping (serialization and deserialization) process.
open func mapping(map: Map) {
creator <- ("creator", map[Acl.CreatorKey])
globalRead.value <- ("globalRead", map[Acl.GlobalReadKey])
globalWrite.value <- ("globalWrite", map[Acl.GlobalWriteKey])
readers <- ("readers", map[Acl.ReadersKey])
writers <- ("writers", map[Acl.WritersKey])
creator <- ("creator", map[Acl.Key.creator])
globalRead.value <- ("globalRead", map[Acl.Key.globalRead])
globalWrite.value <- ("globalWrite", map[Acl.Key.globalWrite])
readers <- ("readers", map[Acl.Key.readers])
writers <- ("writers", map[Acl.Key.writers])
}

/**
WARNING: This is an internal initializer not intended for public use.
:nodoc:
*/
open override class func ignoredProperties() -> [String] {
return ["readers", "writers"]
}
}

extension Acl {

public struct Key {

static let creator = "creator"
static let globalRead = "gr"
static let globalWrite = "gw"
static let readers = "r"
static let writers = "w"

}

}
9 changes: 4 additions & 5 deletions Kinvey/Kinvey/AggregateOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ class AggregateOperation<T: Persistable>: ReadOperation<T, [JsonDictionary], Swi
func executeLocal(_ completionHandler: CompletionHandler? = nil) -> Request {
let request = LocalRequest()
request.execute { () -> Void in
if let cache = self.cache {
let result = cache.group(aggregation: aggregation, predicate: predicate)
completionHandler?(.success(result))
if let _ = self.cache {
completionHandler?(.failure(Error.invalidOperation(description: "Custom Aggregation not supported against local cache")))
} else {
completionHandler?(.success([]))
}
Expand Down Expand Up @@ -73,8 +72,6 @@ enum Aggregation {

var resultKey: String {
switch self {
case .custom(_, _, _):
fatalError("Custom does not have a resultKey")
case .count:
return "count"
case .sum:
Expand All @@ -85,6 +82,8 @@ enum Aggregation {
return "min"
case .max:
return "max"
case .custom(_, _, _):
fatalError("Custom does not have a resultKey")
}
}

Expand Down
38 changes: 0 additions & 38 deletions Kinvey/Kinvey/Cache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import Foundation

internal protocol CacheType: class {

var persistenceId: String { get }
var collectionName: String { get }
var ttl: TimeInterval? { get set }

associatedtype `Type`: Persistable
Expand All @@ -26,8 +24,6 @@ internal protocol CacheType: class {

func findIdsLmts(byQuery query: Query) -> [String : String]

func findAll() -> [Type]

func count(query: Query?) -> Int

@discardableResult
Expand All @@ -39,14 +35,10 @@ internal protocol CacheType: class {
@discardableResult
func remove(byQuery query: Query) -> Int

func removeAll()

func clear(query: Query?)

func detach(entities: [Type], query: Query?) -> [Type]

func group(aggregation: Aggregation, predicate: NSPredicate?) -> [JsonDictionary]

}

extension CacheType {
Expand Down Expand Up @@ -75,14 +67,6 @@ internal class Cache<T: Persistable> where T: NSObject {

class AnyCache<T: Persistable>: CacheType {

var persistenceId: String {
return _getPersistenceId()
}

var collectionName: String {
return _getCollectionName()
}

var ttl: TimeInterval? {
get {
return _getTTL()
Expand All @@ -92,46 +76,36 @@ class AnyCache<T: Persistable>: CacheType {
}
}

private let _getPersistenceId: () -> String
private let _getCollectionName: () -> String
private let _getTTL: () -> TimeInterval?
private let _setTTL: (TimeInterval?) -> Void
private let _saveEntity: (T) -> Void
private let _saveEntities: ([T]) -> Void
private let _findById: (String) -> T?
private let _findByQuery: (Query) -> [T]
private let _findIdsLmtsByQuery: (Query) -> [String : String]
private let _findAll: () -> [T]
private let _count: (Query?) -> Int
private let _removeEntity: (T) -> Bool
private let _removeEntities: ([T]) -> Bool
private let _removeByQuery: (Query) -> Int
private let _removeAll: () -> Void
private let _clear: (Query?) -> Void
private let _detach: ([T], Query?) -> [T]
private let _group: (Aggregation, NSPredicate?) -> [JsonDictionary]

typealias `Type` = T

init<Cache: CacheType>(_ cache: Cache) where Cache.`Type` == T {
_getPersistenceId = { return cache.persistenceId }
_getCollectionName = { return cache.collectionName }
_getTTL = { return cache.ttl }
_setTTL = { cache.ttl = $0 }
_saveEntity = cache.save(entity:)
_saveEntities = cache.save(entities:)
_findById = cache.find(byId:)
_findByQuery = cache.find(byQuery:)
_findIdsLmtsByQuery = cache.findIdsLmts(byQuery:)
_findAll = cache.findAll
_count = cache.count(query:)
_removeEntity = cache.remove(entity:)
_removeEntities = cache.remove(entities:)
_removeByQuery = cache.remove(byQuery:)
_removeAll = cache.removeAll
_clear = cache.clear(query:)
_detach = cache.detach(entities: query:)
_group = cache.group(aggregation: predicate:)
}

func save(entity: T) {
Expand All @@ -154,10 +128,6 @@ class AnyCache<T: Persistable>: CacheType {
return _findIdsLmtsByQuery(query)
}

func findAll() -> [T] {
return _findAll()
}

func count(query: Query?) -> Int {
return _count(query)
}
Expand All @@ -177,10 +147,6 @@ class AnyCache<T: Persistable>: CacheType {
return _removeByQuery(query)
}

func removeAll() {
_removeAll()
}

func clear(query: Query?) {
_clear(query)
}
Expand All @@ -189,8 +155,4 @@ class AnyCache<T: Persistable>: CacheType {
return _detach(entities, query)
}

func group(aggregation: Aggregation, predicate: NSPredicate?) -> [JsonDictionary] {
return _group(aggregation, predicate)
}

}
4 changes: 2 additions & 2 deletions Kinvey/Kinvey/CacheManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ internal class CacheManager: NSObject {
return AnyCache(RealmCache<T>(persistenceId: persistenceId, fileURL: fileURL, encryptionKey: encryptionKey, schemaVersion: schemaVersion))
}

func fileCache(fileURL: URL? = nil) -> FileCache? {
return RealmFileCache(persistenceId: persistenceId, fileURL: fileURL, encryptionKey: encryptionKey, schemaVersion: schemaVersion)
func fileCache<FileType: File>(fileURL: URL? = nil) -> AnyFileCache<FileType>? {
return AnyFileCache(RealmFileCache<FileType>(persistenceId: persistenceId, fileURL: fileURL, encryptionKey: encryptionKey, schemaVersion: schemaVersion))
}

func clearAll(_ tag: String? = nil) {
Expand Down
11 changes: 8 additions & 3 deletions Kinvey/Kinvey/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ open class Client: Credential {
}
}

internal var clientId: String? {
willSet {
keychain.clientId = clientId
}
}

private var accessGroup: String?

private var keychain: Keychain {
Expand Down Expand Up @@ -145,9 +151,7 @@ open class Client: Credential {

private func validateInitialize(appKey: String, appSecret: String) {
if appKey.isEmpty || appSecret.isEmpty {
let message = "Please provide a valid appKey and appSecret. Your app's key and secret can be found on the Kinvey management console."
log.severe(message)
fatalError(message)
fatalError("Please provide a valid appKey and appSecret. Your app's key and secret can be found on the Kinvey management console.")
}
}

Expand Down Expand Up @@ -269,6 +273,7 @@ open class Client: Credential {
if let user = keychain.user {
user.client = self
activeUser = user
clientId = keychain.clientId
let customUser = user as! U
completionHandler(.success(customUser))
} else if let kinveyAuth = sharedKeychain?.kinveyAuth {
Expand Down
2 changes: 1 addition & 1 deletion Kinvey/Kinvey/CustomEndpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ open class CustomEndpoint {
request.request.httpBody = try! JSONSerialization.data(withJSONObject: object.toJSON().toJson(), options: [])
}
}
request.request.setValue(nil, forHTTPHeaderField: Header.requestId)
request.request.setValue(nil, forHTTPHeaderField: KinveyHeaderField.requestId)
request.execute(completionHandler)
return request
}
Expand Down
Loading

0 comments on commit 3a2e730

Please sign in to comment.