Skip to content

Commit

Permalink
Release/0.1.1 (#66)
Browse files Browse the repository at this point in the history
* changing to CFRunLoopRun #63 (#64)

* fixed #62

* fixed #65

* fixing linting issues

Co-authored-by: GitHub Action <[email protected]>
  • Loading branch information
leogdion and actions-user authored Oct 31, 2020
1 parent 8b3d29b commit 4e560f2
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/macOS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

strategy:
matrix:
xcode: ["/Applications/Xcode_11.6.app","/Applications/Xcode_11.7_beta.app","/Applications/Xcode_12_beta.app"]
xcode: ["/Applications/Xcode_11.5.app","/Applications/Xcode_11.6.app","/Applications/Xcode_11.7.app","/Applications/Xcode_12.app"]

steps:
- uses: actions/checkout@v2
Expand All @@ -39,7 +39,7 @@ jobs:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: Build Documentation
if: ${{ matrix.xcode == '/Applications/Xcode_12_beta.app' }}
run: swift run sourcedocs generate build -c --spm-module MistKit
run: swift run sourcedocs generate build -cra
- name: Commit files
if: ${{ matrix.xcode == '/Applications/Xcode_12_beta.app' }}
run: |
Expand Down
2 changes: 1 addition & 1 deletion Documentation/Reference/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@
- [ModifyRecordQueryRequest.Data](typealiases/ModifyRecordQueryRequest.Data.md)
- [ModifyRecordQueryRequest.Response](typealiases/ModifyRecordQueryRequest.Response.md)

This file was generated by [SourceDocs](https://github.com/eneko/SourceDocs) on 2020-09-15 19:42:27 +0000
This file was generated by [SourceDocs](https://github.com/eneko/SourceDocs)
5 changes: 4 additions & 1 deletion Documentation/Reference/extensions/MKDatabase.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ public extension MKDatabase where HttpClient == MKURLSessionClient
### `init(connection:factory:tokenManager:session:)`

```swift
init(connection: MKDatabaseConnection, factory: MKURLBuilderFactory? = nil, tokenManager: MKTokenManagerProtocol? = nil, session: URLSession? = nil)
init(connection: MKDatabaseConnection,
factory: MKURLBuilderFactory? = nil,
tokenManager: MKTokenManagerProtocol? = nil,
session: URLSession? = nil)
```

### `query(_:_:)`
Expand Down
5 changes: 4 additions & 1 deletion Documentation/Reference/structs/MKDatabase.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ public struct MKDatabase<HttpClient: MKHttpClient>
### `init(connection:factory:client:tokenManager:)`

```swift
public init(connection: MKDatabaseConnection, factory: MKURLBuilderFactory? = nil, client: HttpClient, tokenManager: MKTokenManagerProtocol? = nil)
public init(connection: MKDatabaseConnection,
factory: MKURLBuilderFactory? = nil,
client: HttpClient,
tokenManager: MKTokenManagerProtocol? = nil)
```

### `perform(request:returnFailedAuthentication:_:)`
Expand Down
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,30 @@ Swift Package for Server-Side and Command-Line Access to CloudKit Web Services

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


# Table of Contents

* [**Introduction**](#introduction)
* [**Features**](#features)
* [**Installation**](#installation)
* [**Usage**](#usage)
* [Composing Web Service Requests](#composing-web-service-requests)
* [Fetching Records Using a Query (records/query)](#fetching-records-using-a-query-recordsquery)
* [Fetching Records by Record Name (records/lookup)](#fetching-records-by-record-name-recordslookup)
* [Fetching Current User Identity (users/caller)](#fetching-current-user-identity-userscaller)
* [Modifying Records (records/modify)](#modifying-records-recordsmodify)
* [Examples](#examples)
* [Further Code Documentation](#further-code-documentation)
* [**Roadmap**](#roadmap)
* [~~0.1.0~~](#010)
* [**0.2.0**](#020)
* [0.4.0](#040)
* [0.6.0](#060)
* [0.8.0](#080)
* [0.9.0](#090)
* [v1.0.0](#v100)
* [**License**](#license)

# Introduction

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?
Expand Down Expand Up @@ -81,8 +105,25 @@ let request = FetchRecordQueryRequest(
database.query(request) { result in
dump(result)
}

// wait for query here...
```

To wait for the CloudKit query to complete synchronously, you can use [CFRunLoop](https://developer.apple.com/documentation/corefoundation/cfrunloop-rht):

```swift
...
// handle the result
database.query(request) { result in
dump(result)

// nessecary if you need run this synchronously
CFRunLoopStop(CFRunLoopGetMain())
}

// nessecary if you need run this synchronously
CFRunLoopRun()
```
# Features

Here's what's currently implemented with this library:
Expand Down
4 changes: 2 additions & 2 deletions Sources/MistKit/Extensions/Array.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

public extension Array where Element == UInt8 {
internal init(uuid: UUID) {
internal extension Array where Element == UInt8 {
init(uuid: UUID) {
// swiftlint:disable:next force_cast
self = Mirror(reflecting: uuid.uuid).children.map { $0.value as! UInt8 }
}
Expand Down
10 changes: 8 additions & 2 deletions Sources/MistKit/MKDatabase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ public struct MKDatabase<HttpClient: MKHttpClient> {
let decoder: MKDecoder = JSONDecoder()
let client: HttpClient

public init(connection: MKDatabaseConnection, factory: MKURLBuilderFactory? = nil, client: HttpClient, tokenManager: MKTokenManagerProtocol? = nil) {
public init(connection: MKDatabaseConnection,
factory: MKURLBuilderFactory? = nil,
client: HttpClient,
tokenManager: MKTokenManagerProtocol? = nil) {
let factory = factory ?? MKURLBuilderFactory()
urlBuilder = factory.builder(forConnection: connection, withTokenManager: tokenManager)
self.client = client
Expand Down Expand Up @@ -82,7 +85,10 @@ public struct MKDatabase<HttpClient: MKHttpClient> {
#endif

public extension MKDatabase where HttpClient == MKURLSessionClient {
init(connection: MKDatabaseConnection, factory: MKURLBuilderFactory? = nil, tokenManager: MKTokenManagerProtocol? = nil, session: URLSession? = nil) {
init(connection: MKDatabaseConnection,
factory: MKURLBuilderFactory? = nil,
tokenManager: MKTokenManagerProtocol? = nil,
session: URLSession? = nil) {
let factory = factory ?? MKURLBuilderFactory()
urlBuilder = factory.builder(forConnection: connection, withTokenManager: tokenManager)
client = MKURLSessionClient(session: session ?? URLSession.shared)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ public struct ModifiedRecordQueryResult<RecordType: MKQueryRecord> {
public let updated: [RecordType]
}

extension MKDatabase {
public func query<RecordType: MKQueryRecord>(
public extension MKDatabase {
func query<RecordType: MKQueryRecord>(
_ query: FetchRecordQueryRequest<MKQuery<RecordType>>,
_ callback: @escaping ((Result<[RecordType], Error>) -> Void)
) {
Expand All @@ -14,7 +14,7 @@ extension MKDatabase {
}
}

public func perform<RecordType: MKQueryRecord>(
func perform<RecordType: MKQueryRecord>(
operations: ModifyRecordQueryRequest<RecordType>,
_ callback: @escaping ((Result<ModifiedRecordQueryResult<RecordType>, Error>) -> Void)
) {
Expand All @@ -41,7 +41,7 @@ extension MKDatabase {
}
}

public func lookup<RecordType: MKQueryRecord>(
func lookup<RecordType: MKQueryRecord>(
_ lookup: LookupRecordQueryRequest<RecordType>,
_ callback: @escaping ((Result<[RecordType], Error>) -> Void)
) {
Expand Down
12 changes: 11 additions & 1 deletion Sources/mistdemoc/Commands/MistDemoCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,17 @@ import MistKitDemo
import MistKitNIOHTTP1Token

struct MistDemoCommand: ParsableCommand {
static var configuration = CommandConfiguration(commandName: "mistdemoc", subcommands: [ListCommand.self, NewCommand.self, FindCommand.self, DeleteCommand.self, RenameCommand.self, WhoAmICommand.self], defaultSubcommand: ListCommand.self)
static var configuration = CommandConfiguration(
commandName: "mistdemoc",
subcommands: [
ListCommand.self,
NewCommand.self,
FindCommand.self,
DeleteCommand.self,
RenameCommand.self,
WhoAmICommand.self
], defaultSubcommand: ListCommand.self
)

static let defaultBinding: BindTo = .ipAddress(host: "127.0.0.1", port: 7000)
}
13 changes: 6 additions & 7 deletions Sources/mistdemoc/Commands/ParsableAsyncCommand.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ArgumentParser
import CoreFoundation
import Foundation

protocol ParsableAsyncCommand: ParsableCommand {
Expand All @@ -7,17 +8,15 @@ protocol ParsableAsyncCommand: ParsableCommand {

extension ParsableAsyncCommand {
func run() throws {
var result: Result<Void, Error>?
var result: Result<Void, Error>!

runAsync { error in
result = Result(error)
CFRunLoopStop(CFRunLoopGetMain())
}

while true {
RunLoop.main.run(until: .distantPast)
if let result = result {
return try result.get()
}
}
CFRunLoopRun()

return try result.get()
}
}

0 comments on commit 4e560f2

Please sign in to comment.