Skip to content

Commit 18d37e5

Browse files
feat: SDK update for version 17.0.0 (#110)
* chore: update Apple SDK to 16.1.0 * chore: update Apple SDK to 16.2.0 * chore: sync generated SDK for latest Made-with: Cursor * chore: restore .github metadata Made-with: Cursor * chore: update Apple SDK to 17.0.0
1 parent 842cc7c commit 18d37e5

16 files changed

Lines changed: 350 additions & 226 deletions

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## 17.0.0
4+
5+
* Breaking: Added `unsubscribe()`, `update()`, and `close()` for Realtime subscription lifecycle.
6+
* Added: Added `userPhone` to the `Membership` model.
7+
* Updated: Updated `X-Appwrite-Response-Format` header to `1.9.2`.
8+
39
## 16.1.0
410

511
* Added `x` OAuth provider to `OAuthProvider` enum

README.md

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

33
![Swift Package Manager](https://img.shields.io/github/v/release/appwrite/sdk-for-apple.svg?color=green&style=flat-square)
44
![License](https://img.shields.io/github/license/appwrite/sdk-for-apple.svg?style=flat-square)
5-
![Version](https://img.shields.io/badge/api%20version-1.9.1-blue.svg?style=flat-square)
5+
![Version](https://img.shields.io/badge/api%20version-1.9.2-blue.svg?style=flat-square)
66
[![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator)
77
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite)
88
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)
@@ -31,7 +31,7 @@ Add the package to your `Package.swift` dependencies:
3131

3232
```swift
3333
dependencies: [
34-
.package(url: "git@github.com:appwrite/sdk-for-apple.git", from: "16.1.0"),
34+
.package(url: "git@github.com:appwrite/sdk-for-apple.git", from: "17.0.0"),
3535
],
3636
```
3737

Sources/Appwrite/Client.swift

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ open class Client {
2626
"x-sdk-name": "Apple",
2727
"x-sdk-platform": "client",
2828
"x-sdk-language": "apple",
29-
"x-sdk-version": "16.1.0",
30-
"x-appwrite-response-format": "1.9.1"
29+
"x-sdk-version": "17.0.0",
30+
"x-appwrite-response-format": "1.9.2"
3131
]
3232

3333
internal var config: [String: String] = [:]
@@ -355,7 +355,7 @@ open class Client {
355355
headers: [String: String] = [:],
356356
params: [String: Any?] = [:],
357357
sink: ((ByteBuffer) -> Void)? = nil,
358-
converter: ((Any) -> T)? = nil
358+
converter: ((Any) throws -> T)? = nil
359359
) async throws -> T {
360360
let validParams = params.filter { $0.value != nil }
361361

@@ -395,7 +395,7 @@ open class Client {
395395
private func execute<T>(
396396
_ request: HTTPClientRequest,
397397
withSink bufferSink: ((ByteBuffer) -> Void)? = nil,
398-
converter: ((Any) -> T)? = nil
398+
converter: ((Any) throws -> T)? = nil
399399
) async throws -> T {
400400
let response = try await http.execute(
401401
request,
@@ -431,7 +431,11 @@ open class Client {
431431
}
432432
let dict = try JSONSerialization.jsonObject(with: Data(data.readableBytesView)) as? [String: Any]
433433

434-
return converter?(dict!) ?? dict! as! T
434+
if let converter = converter {
435+
return try converter(dict!)
436+
}
437+
438+
return dict! as! T
435439
}
436440
default:
437441
var message = ""
@@ -464,7 +468,7 @@ open class Client {
464468
params: inout [String: Any?],
465469
paramName: String,
466470
idParamName: String? = nil,
467-
converter: ((Any) -> T)? = nil,
471+
converter: ((Any) throws -> T)? = nil,
468472
onProgress: ((UploadProgress) -> Void)? = nil
469473
) async throws -> T {
470474
let input = params[paramName] as! InputFile
@@ -537,7 +541,7 @@ open class Client {
537541
))
538542
}
539543

540-
return converter!(result)
544+
return try converter!(result)
541545
}
542546

543547
private static func randomBoundary() -> String {

Sources/Appwrite/Models/RealtimeModels.swift

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,60 @@
11
import Foundation
22

3+
public class RealtimeSubscriptionUpdate {
4+
public let channels: [ChannelValue]?
5+
public let queries: [String]?
6+
7+
public init(channels: [ChannelValue]? = nil, queries: [String]? = nil) {
8+
self.channels = channels
9+
self.queries = queries
10+
}
11+
}
12+
313
public class RealtimeSubscription {
4-
private var close: () async throws -> Void
14+
private var unsubscribeAction: () async throws -> Void
15+
private var updateAction: (RealtimeSubscriptionUpdate) async throws -> Void
16+
private var closeAction: () async throws -> Void
17+
18+
init(
19+
unsubscribe: @escaping () async throws -> Void,
20+
update: @escaping (RealtimeSubscriptionUpdate) async throws -> Void,
21+
close: @escaping () async throws -> Void
22+
) {
23+
self.unsubscribeAction = unsubscribe
24+
self.updateAction = update
25+
self.closeAction = close
26+
}
27+
28+
/// Remove this subscription only. The WebSocket stays open so other subscriptions keep
29+
/// receiving events; use `Realtime.disconnect()` to shut the connection down.
30+
public func unsubscribe() async throws {
31+
try await self.unsubscribeAction()
32+
}
533

6-
init(close: @escaping () async throws-> Void) {
7-
self.close = close
34+
/// Replace the channels and/or queries on this subscription without recreating it.
35+
public func update(_ changes: RealtimeSubscriptionUpdate) async throws {
36+
try await self.updateAction(changes)
837
}
938

39+
/// Alias of `unsubscribe()` that also tears the socket down when this was the last active
40+
/// subscription. Prefer `unsubscribe()` plus `Realtime.disconnect()` for explicit control.
1041
public func close() async throws {
11-
try await self.close()
42+
try await self.closeAction()
1243
}
1344
}
1445

1546
public class RealtimeCallback {
16-
public let channels: Set<String>
47+
public var channels: Set<String>
48+
public var queries: [String]
1749
public let callback: (RealtimeResponseEvent) -> Void
1850

1951
init(
2052
for channels: Set<String>,
53+
queries: [String],
2154
with callback: @escaping (RealtimeResponseEvent) -> Void
2255
) {
2356
self.channels = channels
57+
self.queries = queries
2458
self.callback = callback
2559
}
2660
}

0 commit comments

Comments
 (0)