Skip to content

Commit 4e560f2

Browse files
Release/0.1.1 (#66)
* changing to CFRunLoopRun #63 (#64) * fixed #62 * fixed #65 * fixing linting issues Co-authored-by: GitHub Action <action@github.com>
1 parent 8b3d29b commit 4e560f2

10 files changed

Lines changed: 83 additions & 21 deletions

File tree

.github/workflows/macOS.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717

1818
strategy:
1919
matrix:
20-
xcode: ["/Applications/Xcode_11.6.app","/Applications/Xcode_11.7_beta.app","/Applications/Xcode_12_beta.app"]
20+
xcode: ["/Applications/Xcode_11.5.app","/Applications/Xcode_11.6.app","/Applications/Xcode_11.7.app","/Applications/Xcode_12.app"]
2121

2222
steps:
2323
- uses: actions/checkout@v2
@@ -39,7 +39,7 @@ jobs:
3939
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
4040
- name: Build Documentation
4141
if: ${{ matrix.xcode == '/Applications/Xcode_12_beta.app' }}
42-
run: swift run sourcedocs generate build -c --spm-module MistKit
42+
run: swift run sourcedocs generate build -cra
4343
- name: Commit files
4444
if: ${{ matrix.xcode == '/Applications/Xcode_12_beta.app' }}
4545
run: |

Documentation/Reference/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,4 @@
8888
- [ModifyRecordQueryRequest.Data](typealiases/ModifyRecordQueryRequest.Data.md)
8989
- [ModifyRecordQueryRequest.Response](typealiases/ModifyRecordQueryRequest.Response.md)
9090

91-
This file was generated by [SourceDocs](https://github.com/eneko/SourceDocs) on 2020-09-15 19:42:27 +0000
91+
This file was generated by [SourceDocs](https://github.com/eneko/SourceDocs)

Documentation/Reference/extensions/MKDatabase.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ public extension MKDatabase where HttpClient == MKURLSessionClient
99
### `init(connection:factory:tokenManager:session:)`
1010

1111
```swift
12-
init(connection: MKDatabaseConnection, factory: MKURLBuilderFactory? = nil, tokenManager: MKTokenManagerProtocol? = nil, session: URLSession? = nil)
12+
init(connection: MKDatabaseConnection,
13+
factory: MKURLBuilderFactory? = nil,
14+
tokenManager: MKTokenManagerProtocol? = nil,
15+
session: URLSession? = nil)
1316
```
1417

1518
### `query(_:_:)`

Documentation/Reference/structs/MKDatabase.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ public struct MKDatabase<HttpClient: MKHttpClient>
1010
### `init(connection:factory:client:tokenManager:)`
1111

1212
```swift
13-
public init(connection: MKDatabaseConnection, factory: MKURLBuilderFactory? = nil, client: HttpClient, tokenManager: MKTokenManagerProtocol? = nil)
13+
public init(connection: MKDatabaseConnection,
14+
factory: MKURLBuilderFactory? = nil,
15+
client: HttpClient,
16+
tokenManager: MKTokenManagerProtocol? = nil)
1417
```
1518

1619
### `perform(request:returnFailedAuthentication:_:)`

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,30 @@ Swift Package for Server-Side and Command-Line Access to CloudKit Web Services
2727

2828
![Demonstration of MistKit via Command-Line App `mistdemoc`](Assets/MistKitDemo.gif)
2929

30+
31+
# Table of Contents
32+
33+
* [**Introduction**](#introduction)
34+
* [**Features**](#features)
35+
* [**Installation**](#installation)
36+
* [**Usage**](#usage)
37+
* [Composing Web Service Requests](#composing-web-service-requests)
38+
* [Fetching Records Using a Query (records/query)](#fetching-records-using-a-query-recordsquery)
39+
* [Fetching Records by Record Name (records/lookup)](#fetching-records-by-record-name-recordslookup)
40+
* [Fetching Current User Identity (users/caller)](#fetching-current-user-identity-userscaller)
41+
* [Modifying Records (records/modify)](#modifying-records-recordsmodify)
42+
* [Examples](#examples)
43+
* [Further Code Documentation](#further-code-documentation)
44+
* [**Roadmap**](#roadmap)
45+
* [~~0.1.0~~](#010)
46+
* [**0.2.0**](#020)
47+
* [0.4.0](#040)
48+
* [0.6.0](#060)
49+
* [0.8.0](#080)
50+
* [0.9.0](#090)
51+
* [v1.0.0](#v100)
52+
* [**License**](#license)
53+
3054
# Introduction
3155

3256
Rather than the CloudKit framework this Swift package uses [CloudKit Web Services.](https://developer.apple.com/library/archive/documentation/DataManagement/Conceptual/CloudKitWebServicesReference/index.html#//apple_ref/doc/uid/TP40015240-CH41-SW1). Why?
@@ -81,8 +105,25 @@ let request = FetchRecordQueryRequest(
81105
database.query(request) { result in
82106
dump(result)
83107
}
108+
109+
// wait for query here...
84110
```
85111

112+
To wait for the CloudKit query to complete synchronously, you can use [CFRunLoop](https://developer.apple.com/documentation/corefoundation/cfrunloop-rht):
113+
114+
```swift
115+
...
116+
// handle the result
117+
database.query(request) { result in
118+
dump(result)
119+
120+
// nessecary if you need run this synchronously
121+
CFRunLoopStop(CFRunLoopGetMain())
122+
}
123+
124+
// nessecary if you need run this synchronously
125+
CFRunLoopRun()
126+
```
86127
# Features
87128

88129
Here's what's currently implemented with this library:

Sources/MistKit/Extensions/Array.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Foundation
22

3-
public extension Array where Element == UInt8 {
4-
internal init(uuid: UUID) {
3+
internal extension Array where Element == UInt8 {
4+
init(uuid: UUID) {
55
// swiftlint:disable:next force_cast
66
self = Mirror(reflecting: uuid.uuid).children.map { $0.value as! UInt8 }
77
}

Sources/MistKit/MKDatabase.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ public struct MKDatabase<HttpClient: MKHttpClient> {
66
let decoder: MKDecoder = JSONDecoder()
77
let client: HttpClient
88

9-
public init(connection: MKDatabaseConnection, factory: MKURLBuilderFactory? = nil, client: HttpClient, tokenManager: MKTokenManagerProtocol? = nil) {
9+
public init(connection: MKDatabaseConnection,
10+
factory: MKURLBuilderFactory? = nil,
11+
client: HttpClient,
12+
tokenManager: MKTokenManagerProtocol? = nil) {
1013
let factory = factory ?? MKURLBuilderFactory()
1114
urlBuilder = factory.builder(forConnection: connection, withTokenManager: tokenManager)
1215
self.client = client
@@ -82,7 +85,10 @@ public struct MKDatabase<HttpClient: MKHttpClient> {
8285
#endif
8386

8487
public extension MKDatabase where HttpClient == MKURLSessionClient {
85-
init(connection: MKDatabaseConnection, factory: MKURLBuilderFactory? = nil, tokenManager: MKTokenManagerProtocol? = nil, session: URLSession? = nil) {
88+
init(connection: MKDatabaseConnection,
89+
factory: MKURLBuilderFactory? = nil,
90+
tokenManager: MKTokenManagerProtocol? = nil,
91+
session: URLSession? = nil) {
8692
let factory = factory ?? MKURLBuilderFactory()
8793
urlBuilder = factory.builder(forConnection: connection, withTokenManager: tokenManager)
8894
client = MKURLSessionClient(session: session ?? URLSession.shared)

Sources/MistKit/Requests/RecordsModify/ModifiedRecordQueryResult.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ public struct ModifiedRecordQueryResult<RecordType: MKQueryRecord> {
44
public let updated: [RecordType]
55
}
66

7-
extension MKDatabase {
8-
public func query<RecordType: MKQueryRecord>(
7+
public extension MKDatabase {
8+
func query<RecordType: MKQueryRecord>(
99
_ query: FetchRecordQueryRequest<MKQuery<RecordType>>,
1010
_ callback: @escaping ((Result<[RecordType], Error>) -> Void)
1111
) {
@@ -14,7 +14,7 @@ extension MKDatabase {
1414
}
1515
}
1616

17-
public func perform<RecordType: MKQueryRecord>(
17+
func perform<RecordType: MKQueryRecord>(
1818
operations: ModifyRecordQueryRequest<RecordType>,
1919
_ callback: @escaping ((Result<ModifiedRecordQueryResult<RecordType>, Error>) -> Void)
2020
) {
@@ -41,7 +41,7 @@ extension MKDatabase {
4141
}
4242
}
4343

44-
public func lookup<RecordType: MKQueryRecord>(
44+
func lookup<RecordType: MKQueryRecord>(
4545
_ lookup: LookupRecordQueryRequest<RecordType>,
4646
_ callback: @escaping ((Result<[RecordType], Error>) -> Void)
4747
) {

Sources/mistdemoc/Commands/MistDemoCommand.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,17 @@ import MistKitDemo
55
import MistKitNIOHTTP1Token
66

77
struct MistDemoCommand: ParsableCommand {
8-
static var configuration = CommandConfiguration(commandName: "mistdemoc", subcommands: [ListCommand.self, NewCommand.self, FindCommand.self, DeleteCommand.self, RenameCommand.self, WhoAmICommand.self], defaultSubcommand: ListCommand.self)
8+
static var configuration = CommandConfiguration(
9+
commandName: "mistdemoc",
10+
subcommands: [
11+
ListCommand.self,
12+
NewCommand.self,
13+
FindCommand.self,
14+
DeleteCommand.self,
15+
RenameCommand.self,
16+
WhoAmICommand.self
17+
], defaultSubcommand: ListCommand.self
18+
)
919

1020
static let defaultBinding: BindTo = .ipAddress(host: "127.0.0.1", port: 7000)
1121
}
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import ArgumentParser
2+
import CoreFoundation
23
import Foundation
34

45
protocol ParsableAsyncCommand: ParsableCommand {
@@ -7,17 +8,15 @@ protocol ParsableAsyncCommand: ParsableCommand {
78

89
extension ParsableAsyncCommand {
910
func run() throws {
10-
var result: Result<Void, Error>?
11+
var result: Result<Void, Error>!
1112

1213
runAsync { error in
1314
result = Result(error)
15+
CFRunLoopStop(CFRunLoopGetMain())
1416
}
1517

16-
while true {
17-
RunLoop.main.run(until: .distantPast)
18-
if let result = result {
19-
return try result.get()
20-
}
21-
}
18+
CFRunLoopRun()
19+
20+
return try result.get()
2221
}
2322
}

0 commit comments

Comments
 (0)