Skip to content

Commit f2be462

Browse files
Merge pull request #3 from appwrite/dev
updated to support 1.0.0-RC1
2 parents d3b0a68 + 2f618b6 commit f2be462

File tree

120 files changed

+3097
-1287
lines changed

Some content is hidden

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

120 files changed

+3097
-1287
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ Redistribution and use in source and binary forms, with or without modification,
99

1010
3. Neither the name Appwrite nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
1111

12-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
12+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
![Swift Package Manager](https://img.shields.io/github/v/release/appwrite/sdk-for-swift.svg?color=green&style=flat-square)
44
![License](https://img.shields.io/github/license/appwrite/sdk-for-swift.svg?style=flat-square)
5-
![Version](https://img.shields.io/badge/api%20version-0.15.0-blue.svg?style=flat-square)
5+
![Version](https://img.shields.io/badge/api%20version-1.0.0-RC1-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

10-
**This SDK is compatible with Appwrite server version 0.15.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-swift/releases).**
10+
**This SDK is compatible with Appwrite server version 1.0.0-RC1. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-swift/releases).**
1111

1212
> This is the Swift SDK for integrating with Appwrite from your Swift server-side code. If you're looking for the Apple SDK you should check [appwrite/sdk-for-apple](https://github.com/appwrite/sdk-for-apple)
1313
@@ -33,7 +33,7 @@ Add the package to your `Package.swift` dependencies:
3333

3434
```swift
3535
dependencies: [
36-
.package(url: "git@github.com:appwrite/sdk-for-swift.git", from: "0.6.0"),
36+
.package(url: "git@github.com:appwrite/sdk-for-swift.git", from: "1.0.0-RC1"),
3737
],
3838
```
3939

Sources/Appwrite/Client.swift

+18-11
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ open class Client {
2020

2121
open var headers: [String: String] = [
2222
"content-type": "",
23-
"x-sdk-version": "appwrite:swift:0.6.0",
24-
"X-Appwrite-Response-Format": "0.15.0"
23+
"x-sdk-name": "Swift",
24+
"x-sdk-platform": "server",
25+
"x-sdk-language": "swift",
26+
"x-sdk-version": "1.0.0-RC1",
27+
"X-Appwrite-Response-Format": "1.0.0-RC1"
2528
]
2629

2730
open var config: [String: String] = [:]
@@ -402,15 +405,19 @@ open class Client {
402405

403406
if idParamName != nil && params[idParamName!] as! String != "unique()" {
404407
// Make a request to check if a file already exists
405-
let map = try! await call(
406-
method: "GET",
407-
path: path + "/" + (params[idParamName!] as! String),
408-
headers: headers,
409-
params: [:],
410-
converter: { return $0 }
411-
)
412-
let chunksUploaded = map["chunksUploaded"] as! Int
413-
offset = min(size, (chunksUploaded * Client.chunkSize))
408+
do {
409+
let map = try await call(
410+
method: "GET",
411+
path: path + "/" + (params[idParamName!] as! String),
412+
headers: headers,
413+
params: [:],
414+
converter: { return $0 }
415+
)
416+
let chunksUploaded = map["chunksUploaded"] as! Int
417+
offset = min(size, (chunksUploaded * Client.chunkSize))
418+
} catch {
419+
// File does not exist yet, swallow exception
420+
}
414421
}
415422

416423
while offset < size {

Sources/Appwrite/ID.swift

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
public class ID {
2+
public static func custom(_ id: String) -> String {
3+
return id
4+
}
5+
6+
public static func unique() -> String {
7+
return "unique()"
8+
}
9+
}

Sources/Appwrite/Models/Query.swift

-48
This file was deleted.

Sources/Appwrite/Permission.swift

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
public class Permission {
2+
public static func read(_ role: String) -> String {
3+
return "read(\"\(role)\")"
4+
}
5+
6+
public static func write(_ role: String) -> String {
7+
return "write(\"\(role)\")"
8+
}
9+
10+
public static func create(_ role: String) -> String {
11+
return "create(\"\(role)\")"
12+
}
13+
14+
public static func update(_ role: String) -> String {
15+
return "update(\"\(role)\")"
16+
}
17+
18+
public static func delete(_ role: String) -> String {
19+
return "delete(\"\(role)\")"
20+
}
21+
}

Sources/Appwrite/Query.swift

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
public class Query {
2+
3+
public static func equal(_ attribute: String, value: Any) -> String {
4+
buildQueryWhere(attribute, is: "equal", to: value)
5+
}
6+
7+
public static func notEqual(_ attribute: String, value: Any) -> String {
8+
buildQueryWhere(attribute, is: "notEqual", to: value)
9+
}
10+
11+
public static func lessThan(_ attribute: String, value: Any) -> String {
12+
buildQueryWhere(attribute, is: "lessThan", to: value)
13+
}
14+
15+
public static func lessThanEqual(attribute: String, value: Any) -> String {
16+
buildQueryWhere(attribute, is: "lessThanEqual", to: value)
17+
}
18+
19+
public static func greaterThan(_ attribute: String, value: Any) -> String {
20+
buildQueryWhere(attribute, is: "greaterThan", to: value)
21+
}
22+
23+
public static func greaterThanEqual(_ attribute: String, value: Any) -> String {
24+
buildQueryWhere(attribute, is: "greaterThanEqual", to: value)
25+
}
26+
27+
public static func search(_ attribute: String, value: String) -> String {
28+
buildQueryWhere(attribute, is: "search", to: value)
29+
}
30+
31+
public static func orderAsc(_ attribute: String) -> String {
32+
"orderAsc(\"\(attribute)\")"
33+
}
34+
35+
public static func orderDesc(_ attribute: String) -> String {
36+
"orderDesc(\"\(attribute)\")"
37+
}
38+
39+
public static func cursorBefore(_ id: String) -> String {
40+
"cursorBefore(\"\(id)\")"
41+
}
42+
43+
public static func cursorAfter(_ id: String) -> String {
44+
"cursorAfter(\"\(id)\")"
45+
}
46+
47+
public static func limit(_ limit: Int) -> String {
48+
"limit(\(limit))"
49+
}
50+
51+
public static func offset(_ offset: Int) -> String {
52+
"offset(\(offset))"
53+
}
54+
55+
public static func buildQueryWhere(_ attribute: String, is method: String, to value: Any) -> String {
56+
switch value {
57+
case let value as Array<Any>:
58+
return "\(method)(\"\(attribute)\", [\(value.map { parseValues($0) }.joined(separator: ",") )])"
59+
default:
60+
return "\(method)(\"\(attribute)\", [\(parseValues(value))])"
61+
}
62+
}
63+
64+
private static func parseValues(_ value: Any) -> String {
65+
switch value {
66+
case let value as String:
67+
return "\"\(value)\""
68+
default:
69+
return "\(value)"
70+
}
71+
}
72+
}

Sources/Appwrite/Role.swift

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
public class Role {
2+
public static func any() -> String {
3+
return "any"
4+
}
5+
6+
public static func user(_ id: String) -> String {
7+
return "user:\(id)"
8+
}
9+
10+
public static func users() -> String {
11+
return "users"
12+
}
13+
14+
public static func guests() -> String {
15+
return "guests"
16+
}
17+
18+
public static func team(_ id: String, _ role: String = "") -> String {
19+
if(role.isEmpty) {
20+
return "team:\(id)"
21+
}
22+
return "team:\(id)/\(role)"
23+
}
24+
25+
public static func status(_ status: String) -> String {
26+
return "status:\(status)"
27+
}
28+
}

0 commit comments

Comments
 (0)