Skip to content
This repository has been archived by the owner on Sep 30, 2020. It is now read-only.

swift5 #23

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "antitypical/Result" ~> 3.2.0
github "antitypical/Result" ~> 4.1.0
5 changes: 3 additions & 2 deletions JSONRPCKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
);
Expand Down Expand Up @@ -445,7 +446,7 @@
PRODUCT_NAME = "$(PROJECT_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -467,7 +468,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.bricklife.JSONRPCKit;
PRODUCT_NAME = "$(PROJECT_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand Down
8 changes: 8 additions & 0 deletions JSONRPCKit.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
42 changes: 21 additions & 21 deletions Sources/JSONRPCKit/Batch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public struct Batch1<Request: JSONRPCKit.Request>: Batch {
}

public static func responses(from results: Results) throws -> Responses {
return try results.dematerialize()
return try results.get()
}
}

Expand Down Expand Up @@ -85,8 +85,8 @@ public struct Batch2<Request1: Request, Request2: Request>: Batch {

public static func responses(from results: Results) throws -> Responses {
return (
try results.0.dematerialize(),
try results.1.dematerialize()
try results.0.get(),
try results.1.get()
)
}
}
Expand Down Expand Up @@ -137,9 +137,9 @@ public struct Batch3<Request1: Request, Request2: Request, Request3: Request>: B

public static func responses(from results: Results) throws -> Responses {
return (
try results.0.dematerialize(),
try results.1.dematerialize(),
try results.2.dematerialize()
try results.0.get(),
try results.1.get(),
try results.2.get()
)
}
}
Expand Down Expand Up @@ -195,10 +195,10 @@ public struct Batch4<Request1: Request, Request2: Request, Request3: Request, Re

public static func responses(from results: Results) throws -> Responses {
return (
try results.0.dematerialize(),
try results.1.dematerialize(),
try results.2.dematerialize(),
try results.3.dematerialize()
try results.0.get(),
try results.1.get(),
try results.2.get(),
try results.3.get()
)
}
}
Expand Down Expand Up @@ -259,11 +259,11 @@ public struct Batch5<Request1: Request, Request2: Request, Request3: Request, Re

public static func responses(from results: Results) throws -> Responses {
return (
try results.0.dematerialize(),
try results.1.dematerialize(),
try results.2.dematerialize(),
try results.3.dematerialize(),
try results.4.dematerialize()
try results.0.get(),
try results.1.get(),
try results.2.get(),
try results.3.get(),
try results.4.get()
)
}
}
Expand Down Expand Up @@ -329,12 +329,12 @@ public struct Batch6<Request1: Request, Request2: Request, Request3: Request, Re

public static func responses(from results: Results) throws -> Responses {
return (
try results.0.dematerialize(),
try results.1.dematerialize(),
try results.2.dematerialize(),
try results.3.dematerialize(),
try results.4.dematerialize(),
try results.5.dematerialize()
try results.0.get(),
try results.1.get(),
try results.2.get(),
try results.3.get(),
try results.4.get(),
try results.5.get()
)
}
}
18 changes: 9 additions & 9 deletions Sources/JSONRPCKit/BatchElement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal protocol BatchElementProcotol {

internal extension BatchElementProcotol {
/// - Throws: JSONRPCError
internal func response(from object: Any) throws -> Request.Response {
func response(from object: Any) throws -> Request.Response {
switch result(from: object) {
case .success(let response):
return response
Expand All @@ -37,7 +37,7 @@ internal extension BatchElementProcotol {
}

/// - Throws: JSONRPCError
internal func response(from objects: [Any]) throws -> Request.Response {
func response(from objects: [Any]) throws -> Request.Response {
switch result(from: objects) {
case .success(let response):
return response
Expand All @@ -47,7 +47,7 @@ internal extension BatchElementProcotol {
}
}

internal func result(from object: Any) -> Result<Request.Response, JSONRPCError> {
func result(from object: Any) -> Result<Request.Response, JSONRPCError> {
guard let dictionary = object as? [String: Any] else {
return .failure(.unexpectedTypeObject(object))
}
Expand Down Expand Up @@ -80,9 +80,9 @@ internal extension BatchElementProcotol {
}
}

internal func result(from objects: [Any]) -> Result<Request.Response, JSONRPCError> {
func result(from objects: [Any]) -> Result<Request.Response, JSONRPCError> {
let matchedObject = objects
.flatMap { $0 as? [String: Any] }
.compactMap { $0 as? [String: Any] }
.filter { $0["id"].flatMap(Id.init) == id }
.first

Expand All @@ -95,19 +95,19 @@ internal extension BatchElementProcotol {
}

internal extension BatchElementProcotol where Request.Response == Void {
internal func response(_ object: Any) throws -> Request.Response {
func response(_ object: Any) throws -> Request.Response {
return ()
}

internal func response(_ objects: [Any]) throws -> Request.Response {
func response(_ objects: [Any]) throws -> Request.Response {
return ()
}

internal func result(_ object: Any) -> Result<Request.Response, JSONRPCError> {
func result(_ object: Any) -> Result<Request.Response, JSONRPCError> {
return .success(())
}

internal func result(_ objects: [Any]) -> Result<Request.Response, JSONRPCError> {
func result(_ objects: [Any]) -> Result<Request.Response, JSONRPCError> {
return .success(())
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/JSONRPCKit/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>3.0.0</string>
<string>5.0.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
10 changes: 5 additions & 5 deletions Sources/JSONRPCKit/Request.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,25 @@ public protocol Request {
}

public extension Request {
public var parameters: Any? {
var parameters: Any? {
return nil
}

public var extendedFields: [String: Any]? {
var extendedFields: [String: Any]? {
return nil
}

public var isNotification: Bool {
var isNotification: Bool {
return false
}
}

public extension Request where Response == Void {
public var isNotification: Bool {
var isNotification: Bool {
return true
}

public func response(from resultObject: Any) throws -> Response {
func response(from resultObject: Any) throws -> Response {
return ()
}
}