Skip to content

Commit 846134d

Browse files
Merge pull request #28 from appwrite/dev
Fix nested models
2 parents 744b65f + 655b68e commit 846134d

File tree

7 files changed

+131
-38
lines changed

7 files changed

+131
-38
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2022 Appwrite (https://appwrite.io) and individual contributors.
1+
Copyright (c) 2023 Appwrite (https://appwrite.io) and individual contributors.
22
All rights reserved.
33

44
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Package.resolved

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
{
2+
"object": {
3+
"pins": [
4+
{
5+
"package": "async-http-client",
6+
"repositoryURL": "https://github.com/swift-server/async-http-client.git",
7+
"state": {
8+
"branch": null,
9+
"revision": "03b3e7b34153299e9b4c4b5c2a6ac790a582a3ac",
10+
"version": "1.12.0"
11+
}
12+
},
13+
{
14+
"package": "swift-atomics",
15+
"repositoryURL": "https://github.com/apple/swift-atomics.git",
16+
"state": {
17+
"branch": null,
18+
"revision": "919eb1d83e02121cdb434c7bfc1f0c66ef17febe",
19+
"version": "1.0.2"
20+
}
21+
},
22+
{
23+
"package": "swift-collections",
24+
"repositoryURL": "https://github.com/apple/swift-collections.git",
25+
"state": {
26+
"branch": null,
27+
"revision": "f504716c27d2e5d4144fa4794b12129301d17729",
28+
"version": "1.0.3"
29+
}
30+
},
31+
{
32+
"package": "swift-log",
33+
"repositoryURL": "https://github.com/apple/swift-log.git",
34+
"state": {
35+
"branch": null,
36+
"revision": "6fe203dc33195667ce1759bf0182975e4653ba1c",
37+
"version": "1.4.4"
38+
}
39+
},
40+
{
41+
"package": "swift-nio",
42+
"repositoryURL": "https://github.com/apple/swift-nio.git",
43+
"state": {
44+
"branch": null,
45+
"revision": "bc4c55b9f9584f09eb971d67d956e28d08caa9d0",
46+
"version": "2.43.1"
47+
}
48+
},
49+
{
50+
"package": "swift-nio-extras",
51+
"repositoryURL": "https://github.com/apple/swift-nio-extras.git",
52+
"state": {
53+
"branch": null,
54+
"revision": "6c84d247754ad77487a6f0694273b89b83efd056",
55+
"version": "1.14.0"
56+
}
57+
},
58+
{
59+
"package": "swift-nio-http2",
60+
"repositoryURL": "https://github.com/apple/swift-nio-http2.git",
61+
"state": {
62+
"branch": null,
63+
"revision": "00576e6f1efa5c46dca2ca3081dc56dd233b402d",
64+
"version": "1.23.0"
65+
}
66+
},
67+
{
68+
"package": "swift-nio-ssl",
69+
"repositoryURL": "https://github.com/apple/swift-nio-ssl.git",
70+
"state": {
71+
"branch": null,
72+
"revision": "4fb7ead803e38949eb1d6fabb849206a72c580f3",
73+
"version": "2.23.0"
74+
}
75+
},
76+
{
77+
"package": "swift-nio-transport-services",
78+
"repositoryURL": "https://github.com/apple/swift-nio-transport-services.git",
79+
"state": {
80+
"branch": null,
81+
"revision": "c0d9a144cfaec8d3d596aadde3039286a266c15c",
82+
"version": "1.15.0"
83+
}
84+
}
85+
]
86+
},
87+
"version": 1
88+
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Add the package to your `Package.swift` dependencies:
3131

3232
```swift
3333
dependencies: [
34-
.package(url: "[email protected]:appwrite/sdk-for-apple.git", from: "1.2.0"),
34+
.package(url: "[email protected]:appwrite/sdk-for-apple.git", from: "1.2.1"),
3535
],
3636
```
3737

Sources/Appwrite/Client.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ open class Client {
2323
"x-sdk-name": "Apple",
2424
"x-sdk-platform": "client",
2525
"x-sdk-language": "apple",
26-
"x-sdk-version": "1.2.0",
26+
"x-sdk-version": "1.2.1",
2727
"X-Appwrite-Response-Format": "1.0.0"
2828
]
2929

Sources/Appwrite/Services/Account.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ open class Account: Service {
1515
/// @return array
1616
///
1717
open func get<T>(
18-
nestedType: T.Type,
18+
nestedType: T.Type
1919
) async throws -> AppwriteModels.Account<T> {
2020
let path: String = "/account"
2121

@@ -74,8 +74,8 @@ open class Account: Service {
7474
userId: String,
7575
email: String,
7676
password: String,
77-
name: String? = nil
78-
nestedType: T.Type,
77+
name: String? = nil,
78+
nestedType: T.Type
7979
) async throws -> AppwriteModels.Account<T> {
8080
let path: String = "/account"
8181

@@ -154,8 +154,8 @@ open class Account: Service {
154154
///
155155
open func updateEmail<T>(
156156
email: String,
157-
password: String
158-
nestedType: T.Type,
157+
password: String,
158+
nestedType: T.Type
159159
) async throws -> AppwriteModels.Account<T> {
160160
let path: String = "/account/email"
161161

@@ -290,8 +290,8 @@ open class Account: Service {
290290
/// @return array
291291
///
292292
open func updateName<T>(
293-
name: String
294-
nestedType: T.Type,
293+
name: String,
294+
nestedType: T.Type
295295
) async throws -> AppwriteModels.Account<T> {
296296
let path: String = "/account/name"
297297

@@ -348,8 +348,8 @@ open class Account: Service {
348348
///
349349
open func updatePassword<T>(
350350
password: String,
351-
oldPassword: String? = nil
352-
nestedType: T.Type,
351+
oldPassword: String? = nil,
352+
nestedType: T.Type
353353
) async throws -> AppwriteModels.Account<T> {
354354
let path: String = "/account/password"
355355

@@ -414,8 +414,8 @@ open class Account: Service {
414414
///
415415
open func updatePhone<T>(
416416
phone: String,
417-
password: String
418-
nestedType: T.Type,
417+
password: String,
418+
nestedType: T.Type
419419
) async throws -> AppwriteModels.Account<T> {
420420
let path: String = "/account/phone"
421421

@@ -475,7 +475,7 @@ open class Account: Service {
475475
/// @return array
476476
///
477477
open func getPrefs<T>(
478-
nestedType: T.Type,
478+
nestedType: T.Type
479479
) async throws -> AppwriteModels.Preferences<T> {
480480
let path: String = "/account/prefs"
481481

@@ -525,8 +525,8 @@ open class Account: Service {
525525
/// @return array
526526
///
527527
open func updatePrefs<T>(
528-
prefs: T
529-
nestedType: T.Type,
528+
prefs: T,
529+
nestedType: T.Type
530530
) async throws -> AppwriteModels.Account<T> {
531531
let path: String = "/account/prefs"
532532

@@ -938,7 +938,7 @@ open class Account: Service {
938938
success: String? = nil,
939939
failure: String? = nil,
940940
scopes: [String]? = nil
941-
) async throws -> Bool {
941+
) throws -> Bool {
942942
let path: String = "/account/sessions/oauth2/{provider}"
943943
.replacingOccurrences(of: "{provider}", with: provider)
944944

@@ -1164,7 +1164,7 @@ open class Account: Service {
11641164
/// @return array
11651165
///
11661166
open func updateStatus<T>(
1167-
nestedType: T.Type,
1167+
nestedType: T.Type
11681168
) async throws -> AppwriteModels.Account<T> {
11691169
let path: String = "/account/status"
11701170

Sources/Appwrite/Services/Databases.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ open class Databases: Service {
2121
open func listDocuments<T>(
2222
databaseId: String,
2323
collectionId: String,
24-
queries: [String]? = nil
25-
nestedType: T.Type,
24+
queries: [String]? = nil,
25+
nestedType: T.Type
2626
) async throws -> AppwriteModels.DocumentList<T> {
2727
let path: String = "/databases/{databaseId}/collections/{collectionId}/documents"
2828
.replacingOccurrences(of: "{databaseId}", with: databaseId)
@@ -95,8 +95,8 @@ open class Databases: Service {
9595
collectionId: String,
9696
documentId: String,
9797
data: T,
98-
permissions: [String]? = nil
99-
nestedType: T.Type,
98+
permissions: [String]? = nil,
99+
nestedType: T.Type
100100
) async throws -> AppwriteModels.Document<T> {
101101
let path: String = "/databases/{databaseId}/collections/{collectionId}/documents"
102102
.replacingOccurrences(of: "{databaseId}", with: databaseId)
@@ -173,8 +173,8 @@ open class Databases: Service {
173173
open func getDocument<T>(
174174
databaseId: String,
175175
collectionId: String,
176-
documentId: String
177-
nestedType: T.Type,
176+
documentId: String,
177+
nestedType: T.Type
178178
) async throws -> AppwriteModels.Document<T> {
179179
let path: String = "/databases/{databaseId}/collections/{collectionId}/documents/{documentId}"
180180
.replacingOccurrences(of: "{databaseId}", with: databaseId)
@@ -244,8 +244,8 @@ open class Databases: Service {
244244
collectionId: String,
245245
documentId: String,
246246
data: T? = nil,
247-
permissions: [String]? = nil
248-
nestedType: T.Type,
247+
permissions: [String]? = nil,
248+
nestedType: T.Type
249249
) async throws -> AppwriteModels.Document<T> {
250250
let path: String = "/databases/{databaseId}/collections/{collectionId}/documents/{documentId}"
251251
.replacingOccurrences(of: "{databaseId}", with: databaseId)

Sources/Appwrite/WebSockets/WebSocketClient.swift

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ public class WebSocketClient {
2626
var channel: Channel? = nil
2727
var tlsEnabled: Bool = false
2828
var closeSent: Bool = false
29-
30-
let upgradedSignalled = DispatchSemaphore(value: 0)
31-
let locker = DispatchQueue(label: WEBSOCKET_LOCKER_QUEUE)
32-
let threadGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
29+
30+
let locker = DispatchQueue(label: WEBSOCKET_LOCKER_QUEUE, qos: .background)
31+
32+
var threadGroup: MultiThreadedEventLoopGroup? = nil
3333

3434
weak var delegate: WebSocketClientDelegate? = nil
3535

@@ -184,6 +184,10 @@ public class WebSocketClient {
184184
self.maxFrameSize = maxFrameSize
185185
self.tlsEnabled = tlsEnabled
186186
self.delegate = delegate
187+
188+
DispatchQueue.global(qos: .background).async {
189+
self.threadGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
190+
}
187191
}
188192

189193
/// Create a new `WebSocketClient`.
@@ -207,10 +211,14 @@ public class WebSocketClient {
207211
self.maxFrameSize = 24
208212
self.tlsEnabled = tlsEnabled
209213
self.delegate = delegate
214+
215+
DispatchQueue.global(qos: .background).async {
216+
self.threadGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
217+
}
210218
}
211219

212220
deinit {
213-
try! threadGroup.syncShutdownGracefully()
221+
try! threadGroup!.syncShutdownGracefully()
214222
}
215223

216224
// MARK: - Open connection
@@ -221,16 +229,16 @@ public class WebSocketClient {
221229
SocketOptionLevel(SOL_SOCKET),
222230
SO_REUSEPORT
223231
)
232+
233+
while(threadGroup == nil) {}
224234

225-
let bootstrap = ClientBootstrap(group: threadGroup)
235+
let bootstrap = ClientBootstrap(group: threadGroup!)
226236
.channelOption(socketOptions, value: 1)
227237
.channelInitializer(self.openChannel)
228238

229239
_ = try bootstrap
230240
.connect(host: self.host, port: self.port)
231241
.wait()
232-
233-
self.upgradedSignalled.wait()
234242
}
235243

236244
private func openChannel(channel: Channel) -> EventLoopFuture<Void> {
@@ -260,13 +268,10 @@ public class WebSocketClient {
260268
}
261269

262270
private func upgradePipelineHandler(channel: Channel, response: HTTPResponseHead) -> EventLoopFuture<Void> {
263-
self.onOpen(channel)
264-
265271
let handler = MessageHandler(client: self)
266272

267273
if response.status == .switchingProtocols {
268274
self.channel = channel
269-
self.upgradedSignalled.signal()
270275
}
271276

272277
return channel.pipeline.addHandler(handler)

0 commit comments

Comments
 (0)