Skip to content

Commit e9a8ad7

Browse files
authored
Merge pull request #98 from appwrite/dev
2 parents 4787056 + 1eca202 commit e9a8ad7

76 files changed

Lines changed: 477 additions & 333 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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+
## 14.0.0
4+
5+
* Add array-based enum parameters (e.g., `permissions: [BrowserPermission]`).
6+
* Breaking change: `Output` enum has been removed; use `ImageFormat` instead.
7+
* Add `Channel` helpers for Realtime.
8+
39
## 13.5.0
410

511
* Add `getScreenshot` method to `Avatars` service

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2025 Appwrite (https://appwrite.io) and individual contributors.
1+
Copyright (c) 2026 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:

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
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.8.0-blue.svg?style=flat-square)
5+
![Version](https://img.shields.io/badge/api%20version-1.8.1-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)
99

1010
**This SDK is compatible with Appwrite server version 1.8.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-apple/releases).**
1111

12-
Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the Apple SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs)
12+
Appwrite is an open-source backend as a service server that abstracts and simplifies complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the Apple SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs)
1313

1414
![Appwrite](https://github.com/appwrite/appwrite/raw/main/public/images/github.png)
1515

@@ -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: "13.5.0"),
34+
.package(url: "git@github.com:appwrite/sdk-for-apple.git", from: "14.0.0"),
3535
],
3636
```
3737

Sources/Appwrite/Channel.swift

Lines changed: 250 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
import Foundation
2+
3+
// Marker structs for type safety (structs work with == constraints in extensions)
4+
public struct _Root {}
5+
public struct _Database {}
6+
public struct _Collection {}
7+
public struct _Document {}
8+
public struct _TablesDB {}
9+
public struct _Table {}
10+
public struct _Row {}
11+
public struct _Bucket {}
12+
public struct _File {}
13+
public struct _Func {}
14+
public struct _Execution {}
15+
public struct _Team {}
16+
public struct _Membership {}
17+
public struct _Resolved {}
18+
19+
// Helper for normalizing IDs
20+
private func normalize(_ id: String) -> String {
21+
let trimmed = id.trimmingCharacters(in: .whitespacesAndNewlines)
22+
return trimmed.isEmpty ? "*" : trimmed
23+
}
24+
25+
/// Channel class with generic type parameter for type-safe method chaining
26+
public class RealtimeChannel<T> {
27+
private let segments: [String]
28+
29+
internal init(_ segments: [String]) {
30+
self.segments = segments
31+
}
32+
33+
/// Internal helper to transition to next state with segment and ID
34+
internal func next<N>(_ segment: String, _ id: String = "*") -> RealtimeChannel<N> {
35+
return RealtimeChannel<N>(segments + [segment, normalize(id)])
36+
}
37+
38+
/// Internal helper for terminal actions (no ID segment)
39+
internal func resolve(_ action: String) -> RealtimeChannel<_Resolved> {
40+
return RealtimeChannel<_Resolved>(segments + [action])
41+
}
42+
43+
/// Convert channel to string representation
44+
public func toString() -> String {
45+
return segments.joined(separator: ".")
46+
}
47+
}
48+
49+
/// Non-generic Channel enum for static factory methods
50+
public enum Channel {
51+
52+
// MARK: - Root Factories
53+
54+
public static func database(_ id: String = "*") -> RealtimeChannel<_Database> {
55+
return RealtimeChannel<_Database>(["databases", normalize(id)])
56+
}
57+
58+
public static func tablesdb(_ id: String = "*") -> RealtimeChannel<_TablesDB> {
59+
return RealtimeChannel<_TablesDB>(["tablesdb", normalize(id)])
60+
}
61+
62+
public static func bucket(_ id: String = "*") -> RealtimeChannel<_Bucket> {
63+
return RealtimeChannel<_Bucket>(["buckets", normalize(id)])
64+
}
65+
66+
public static func function(_ id: String = "*") -> RealtimeChannel<_Func> {
67+
return RealtimeChannel<_Func>(["functions", normalize(id)])
68+
}
69+
70+
public static func team(_ id: String = "*") -> RealtimeChannel<_Team> {
71+
return RealtimeChannel<_Team>(["teams", normalize(id)])
72+
}
73+
74+
public static func membership(_ id: String = "*") -> RealtimeChannel<_Membership> {
75+
return RealtimeChannel<_Membership>(["memberships", normalize(id)])
76+
}
77+
78+
public static func account(_ userId: String = "") -> String {
79+
let id = normalize(userId)
80+
return id == "*" ? "account" : "account.\(id)"
81+
}
82+
83+
// Global events
84+
public static func documents() -> String { "documents" }
85+
public static func rows() -> String { "rows" }
86+
public static func files() -> String { "files" }
87+
public static func executions() -> String { "executions" }
88+
public static func teams() -> String { "teams" }
89+
}
90+
91+
// MARK: - DATABASE ROUTE
92+
// Protocol extensions restricted by receiver type
93+
94+
/// Only available on RealtimeChannel<_Database>
95+
extension RealtimeChannel where T == _Database {
96+
public func collection(_ id: String = "*") -> RealtimeChannel<_Collection> {
97+
return self.next("collections", id)
98+
}
99+
}
100+
101+
/// Only available on RealtimeChannel<_Collection>
102+
extension RealtimeChannel where T == _Collection {
103+
public func document(_ id: String = "*") -> RealtimeChannel<_Document> {
104+
return self.next("documents", id)
105+
}
106+
}
107+
108+
// MARK: - TABLESDB ROUTE
109+
110+
/// Only available on RealtimeChannel<_TablesDB>
111+
extension RealtimeChannel where T == _TablesDB {
112+
public func table(_ id: String = "*") -> RealtimeChannel<_Table> {
113+
return self.next("tables", id)
114+
}
115+
}
116+
117+
/// Only available on RealtimeChannel<_Table>
118+
extension RealtimeChannel where T == _Table {
119+
public func row(_ id: String = "*") -> RealtimeChannel<_Row> {
120+
return self.next("rows", id)
121+
}
122+
}
123+
124+
// MARK: - BUCKET ROUTE
125+
126+
/// Only available on RealtimeChannel<_Bucket>
127+
extension RealtimeChannel where T == _Bucket {
128+
public func file(_ id: String = "*") -> RealtimeChannel<_File> {
129+
return self.next("files", id)
130+
}
131+
}
132+
133+
// MARK: - FUNCTION ROUTE
134+
135+
/// Only available on RealtimeChannel<_Func>
136+
extension RealtimeChannel where T == _Func {
137+
public func execution(_ id: String = "*") -> RealtimeChannel<_Execution> {
138+
return self.next("executions", id)
139+
}
140+
}
141+
142+
// MARK: - TERMINAL ACTIONS
143+
// Restricted to actionable types (_Document, _Row, _File, _Execution, _Team, _Membership)
144+
145+
/// Only available on RealtimeChannel<_Document>
146+
extension RealtimeChannel where T == _Document {
147+
public func create() -> RealtimeChannel<_Resolved> {
148+
return self.resolve("create")
149+
}
150+
151+
public func update() -> RealtimeChannel<_Resolved> {
152+
return self.resolve("update")
153+
}
154+
155+
public func delete() -> RealtimeChannel<_Resolved> {
156+
return self.resolve("delete")
157+
}
158+
}
159+
160+
/// Only available on RealtimeChannel<_Row>
161+
extension RealtimeChannel where T == _Row {
162+
public func create() -> RealtimeChannel<_Resolved> {
163+
return self.resolve("create")
164+
}
165+
166+
public func update() -> RealtimeChannel<_Resolved> {
167+
return self.resolve("update")
168+
}
169+
170+
public func delete() -> RealtimeChannel<_Resolved> {
171+
return self.resolve("delete")
172+
}
173+
}
174+
175+
/// Only available on RealtimeChannel<_File>
176+
extension RealtimeChannel where T == _File {
177+
public func create() -> RealtimeChannel<_Resolved> {
178+
return self.resolve("create")
179+
}
180+
181+
public func update() -> RealtimeChannel<_Resolved> {
182+
return self.resolve("update")
183+
}
184+
185+
public func delete() -> RealtimeChannel<_Resolved> {
186+
return self.resolve("delete")
187+
}
188+
}
189+
190+
/// Only available on RealtimeChannel<_Execution>
191+
extension RealtimeChannel where T == _Execution {
192+
public func create() -> RealtimeChannel<_Resolved> {
193+
return self.resolve("create")
194+
}
195+
196+
public func update() -> RealtimeChannel<_Resolved> {
197+
return self.resolve("update")
198+
}
199+
200+
public func delete() -> RealtimeChannel<_Resolved> {
201+
return self.resolve("delete")
202+
}
203+
}
204+
205+
/// Only available on RealtimeChannel<_Team>
206+
extension RealtimeChannel where T == _Team {
207+
public func create() -> RealtimeChannel<_Resolved> {
208+
return self.resolve("create")
209+
}
210+
211+
public func update() -> RealtimeChannel<_Resolved> {
212+
return self.resolve("update")
213+
}
214+
215+
public func delete() -> RealtimeChannel<_Resolved> {
216+
return self.resolve("delete")
217+
}
218+
}
219+
220+
/// Only available on RealtimeChannel<_Membership>
221+
extension RealtimeChannel where T == _Membership {
222+
public func create() -> RealtimeChannel<_Resolved> {
223+
return self.resolve("create")
224+
}
225+
226+
public func update() -> RealtimeChannel<_Resolved> {
227+
return self.resolve("update")
228+
}
229+
230+
public func delete() -> RealtimeChannel<_Resolved> {
231+
return self.resolve("delete")
232+
}
233+
}
234+
235+
// MARK: - Protocol for backward compatibility
236+
237+
/// Protocol for channel values that can be converted to strings
238+
public protocol ChannelValue {
239+
func toString() -> String
240+
}
241+
242+
// Make String conform to ChannelValue
243+
extension String: ChannelValue {
244+
public func toString() -> String {
245+
return self
246+
}
247+
}
248+
249+
// Make RealtimeChannel conform to ChannelValue
250+
extension RealtimeChannel: ChannelValue {}

Sources/Appwrite/Client.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ open class Client {
2424
"x-sdk-name": "Apple",
2525
"x-sdk-platform": "client",
2626
"x-sdk-language": "apple",
27-
"x-sdk-version": "13.5.0",
27+
"x-sdk-version": "14.0.0",
2828
"x-appwrite-response-format": "1.8.0"
2929
]
3030

@@ -34,7 +34,6 @@ open class Client {
3434

3535
internal var http: HTTPClient
3636

37-
3837
private static let boundaryChars = "abcdefghijklmnopqrstuvwxyz1234567890"
3938

4039
private static let boundary = randomBoundary()
@@ -316,7 +315,6 @@ open class Client {
316315
var request = HTTPClientRequest(url: endPoint + path + queryParameters)
317316
request.method = .RAW(value: method)
318317

319-
320318
for (key, value) in self.headers.merging(headers, uniquingKeysWith: { $1 }) {
321319
request.headers.add(name: key, value: value)
322320
}

Sources/Appwrite/Query.swift

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,20 @@ public struct Query : Codable, CustomStringConvertible {
165165
).description
166166
}
167167

168+
/// Filter resources where attribute matches a regular expression pattern.
169+
///
170+
/// - Parameters:
171+
/// - attribute: The attribute to filter on.
172+
/// - pattern: The regular expression pattern to match.
173+
/// - Returns: The query string.
174+
public static func regex(_ attribute: String, pattern: String) -> String {
175+
return Query(
176+
method: "regex",
177+
attribute: attribute,
178+
values: [pattern]
179+
).description
180+
}
181+
168182
public static func lessThan(_ attribute: String, value: Any) -> String {
169183
return Query(
170184
method: "lessThan",
@@ -211,6 +225,28 @@ public struct Query : Codable, CustomStringConvertible {
211225
).description
212226
}
213227

228+
/// Filter resources where the specified attributes exist.
229+
///
230+
/// - Parameter attributes: The list of attributes that must exist.
231+
/// - Returns: The query string.
232+
public static func exists(_ attributes: [String]) -> String {
233+
return Query(
234+
method: "exists",
235+
values: attributes
236+
).description
237+
}
238+
239+
/// Filter resources where the specified attributes do not exist.
240+
///
241+
/// - Parameter attributes: The list of attributes that must not exist.
242+
/// - Returns: The query string.
243+
public static func notExists(_ attributes: [String]) -> String {
244+
return Query(
245+
method: "notExists",
246+
values: attributes
247+
).description
248+
}
249+
214250
public static func between(_ attribute: String, start: Int, end: Int) -> String {
215251
return Query(
216252
method: "between",
@@ -432,6 +468,28 @@ public struct Query : Codable, CustomStringConvertible {
432468
).description
433469
}
434470

471+
/// Filter array elements where at least one element matches all the specified queries.
472+
///
473+
/// - Parameters:
474+
/// - attribute: The attribute containing the array to filter on.
475+
/// - queries: The list of query strings to match against array elements.
476+
/// - Returns: The query string.
477+
public static func elemMatch(_ attribute: String, queries: [String]) -> String {
478+
let decoder = JSONDecoder()
479+
let decodedQueries = queries.compactMap { queryStr -> Query? in
480+
guard let data = queryStr.data(using: .utf8) else {
481+
return nil
482+
}
483+
return try? decoder.decode(Query.self, from: data)
484+
}
485+
486+
return Query(
487+
method: "elemMatch",
488+
attribute: attribute,
489+
values: decodedQueries
490+
).description
491+
}
492+
435493
public static func distanceEqual(_ attribute: String, values: [Any], distance: Double, meters: Bool = true) -> String {
436494
return Query(
437495
method: "distanceEqual",

0 commit comments

Comments
 (0)