diff --git a/CHANGELOG.md b/CHANGELOG.md index fa4d35e..c7194d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1 +1,29 @@ -# Change Log \ No newline at end of file +# Change Log + +## 9.1.0 + +* Add `incrementDocumentAttribute` and `decrementDocumentAttribute` support to `Databases` service +* Add `dart38` and `flutter332` support to runtime models +* Add `gif` support to `ImageFormat` enum +* Add `encrypt` support to `StringAttribute` model +* Add `sequence` support to `Document` model + +## 9.0.0 + +* Add `` to doc examples due to the new multi region endpoints +* Add doc examples and methods for bulk api transactions: `createDocuments`, `deleteDocuments` etc. +* Add doc examples, class and methods for new `Sites` service +* Add doc examples, class and methods for new `Tokens` service +* Add enums for `BuildRuntime `, `Adapter`, `Framework`, `DeploymentDownloadType` and `VCSDeploymentType` +* Update enum for `runtimes` with Pythonml312, Dart219, Flutter327 and Flutter329 +* Add `token` param to `getFilePreview` and `getFileView` for File tokens usage +* Add `queries` and `search` params to `listMemberships` method +* Remove `search` param from `listExecutions` method + +## 8.0.0 + +* Fix requests failing by removing `Content-Type` header from `GET` and `HEAD` requests + +## 7.0.0 + +* Fix pong response & chunked upload diff --git a/README.md b/README.md index b9997e1..f3824c3 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ![Maven Central](https://img.shields.io/maven-central/v/io.appwrite/sdk-for-kotlin.svg?color=green&style=flat-square) ![License](https://img.shields.io/github/license/appwrite/sdk-for-kotlin.svg?style=flat-square) -![Version](https://img.shields.io/badge/api%20version-1.7.0-blue.svg?style=flat-square) +![Version](https://img.shields.io/badge/api%20version-1.7.4-blue.svg?style=flat-square) [![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite) [![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord) @@ -39,7 +39,7 @@ repositories { Next, add the dependency to your project's `build.gradle(.kts)` file: ```groovy -implementation("io.appwrite:sdk-for-kotlin:9.0.0") +implementation("io.appwrite:sdk-for-kotlin:9.1.0") ``` ### Maven @@ -50,7 +50,7 @@ Add this to your project's `pom.xml` file: io.appwrite sdk-for-kotlin - 9.0.0 + 9.1.0 ``` @@ -115,6 +115,77 @@ suspend fun main() { } ``` +### Type Safety with Models + +The Appwrite Kotlin SDK provides type safety when working with database documents through generic methods. Methods like `listDocuments`, `getDocument`, and others accept a `nestedType` parameter that allows you to specify your custom model type for full type safety. + +```kotlin +data class Book( + val name: String, + val author: String, + val releaseYear: String? = null, + val category: String? = null, + val genre: List? = null, + val isCheckedOut: Boolean +) + +val databases = Databases(client) + +try { + val documents = databases.listDocuments( + databaseId = "your-database-id", + collectionId = "your-collection-id", + nestedType = Book::class.java // Pass in your custom model type + ) + + for (book in documents.documents) { + Log.d("Appwrite", "Book: ${book.name} by ${book.author}") // Now you have full type safety + } +} catch (e: AppwriteException) { + Log.e("Appwrite", e.message ?: "Unknown error") +} +``` + +**Tip**: You can use the `appwrite types` command to automatically generate model definitions based on your Appwrite database schema. Learn more about [type generation](https://appwrite.io/docs/products/databases/type-generation). + +### Working with Model Methods + +All Appwrite models come with built-in methods for data conversion and manipulation: + +**`toMap()`** - Converts a model instance to a Map format, useful for debugging or manual data manipulation: +```kotlin +val account = Account(client) +val user = account.get() +val userMap = user.toMap() +Log.d("Appwrite", userMap.toString()) // Prints all user properties as a Map +``` + +**`from(map:, nestedType:)`** - Creates a model instance from a Map, useful when working with raw data: +```kotlin +val userData: Map = mapOf( + "\$id" to "123", + "name" to "John", + "email" to "john@example.com" +) +val user = User.from(userData, User::class.java) +``` + +**JSON Serialization** - Models can be easily converted to/from JSON using Gson (which the SDK uses internally): +```kotlin +import com.google.gson.Gson + +val account = Account(client) +val user = account.get() + +// Convert to JSON +val gson = Gson() +val jsonString = gson.toJson(user) +Log.d("Appwrite", "User JSON: $jsonString") + +// Convert from JSON +val userFromJson = gson.fromJson(jsonString, User::class.java) +``` + ### Error Handling The Appwrite Kotlin SDK raises `AppwriteException` object with `message`, `code` and `response` properties. You can handle any errors by catching `AppwriteException` and present the `message` to the user or handle it yourself based on the provided error information. Below is an example. diff --git a/docs/examples/java/databases/create-document.md b/docs/examples/java/databases/create-document.md index 368b816..5231be3 100644 --- a/docs/examples/java/databases/create-document.md +++ b/docs/examples/java/databases/create-document.md @@ -4,9 +4,8 @@ import io.appwrite.services.Databases; Client client = new Client() .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint - .setSession("") // The user session to authenticate with - .setKey("") // Your secret API key - .setJWT(""); // Your secret JSON Web Token + .setProject("") // Your project ID + .setSession(""); // The user session to authenticate with Databases databases = new Databases(client); diff --git a/docs/examples/java/databases/create-documents.md b/docs/examples/java/databases/create-documents.md index d816af3..0de0c27 100644 --- a/docs/examples/java/databases/create-documents.md +++ b/docs/examples/java/databases/create-documents.md @@ -4,6 +4,7 @@ import io.appwrite.services.Databases; Client client = new Client() .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID .setKey(""); // Your secret API key Databases databases = new Databases(client); diff --git a/docs/examples/java/databases/decrement-document-attribute.md b/docs/examples/java/databases/decrement-document-attribute.md new file mode 100644 index 0000000..34b7472 --- /dev/null +++ b/docs/examples/java/databases/decrement-document-attribute.md @@ -0,0 +1,28 @@ +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Databases; + +Client client = new Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey(""); // Your secret API key + +Databases databases = new Databases(client); + +databases.decrementDocumentAttribute( + "", // databaseId + "", // collectionId + "", // documentId + "", // attribute + 0, // value (optional) + 0, // min (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + System.out.println(result); + }) +); + diff --git a/docs/examples/java/databases/increment-document-attribute.md b/docs/examples/java/databases/increment-document-attribute.md new file mode 100644 index 0000000..ca9c357 --- /dev/null +++ b/docs/examples/java/databases/increment-document-attribute.md @@ -0,0 +1,28 @@ +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Databases; + +Client client = new Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey(""); // Your secret API key + +Databases databases = new Databases(client); + +databases.incrementDocumentAttribute( + "", // databaseId + "", // collectionId + "", // documentId + "", // attribute + 0, // value (optional) + 0, // max (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + System.out.println(result); + }) +); + diff --git a/docs/examples/java/databases/upsert-document.md b/docs/examples/java/databases/upsert-document.md new file mode 100644 index 0000000..daa4414 --- /dev/null +++ b/docs/examples/java/databases/upsert-document.md @@ -0,0 +1,27 @@ +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Databases; + +Client client = new Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setSession(""); // The user session to authenticate with + +Databases databases = new Databases(client); + +databases.upsertDocument( + "", // databaseId + "", // collectionId + "", // documentId + mapOf( "a" to "b" ), // data + listOf("read("any")"), // permissions (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + System.out.println(result); + }) +); + diff --git a/docs/examples/java/databases/upsert-documents.md b/docs/examples/java/databases/upsert-documents.md index e2f2a46..95e9a33 100644 --- a/docs/examples/java/databases/upsert-documents.md +++ b/docs/examples/java/databases/upsert-documents.md @@ -12,7 +12,7 @@ Databases databases = new Databases(client); databases.upsertDocuments( "", // databaseId "", // collectionId - listOf(), // documents (optional) + listOf(), // documents new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); diff --git a/docs/examples/kotlin/databases/create-document.md b/docs/examples/kotlin/databases/create-document.md index 93da01e..695fdbd 100644 --- a/docs/examples/kotlin/databases/create-document.md +++ b/docs/examples/kotlin/databases/create-document.md @@ -4,9 +4,8 @@ import io.appwrite.services.Databases val client = Client() .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID .setSession("") // The user session to authenticate with - .setKey("") // Your secret API key - .setJWT("") // Your secret JSON Web Token val databases = Databases(client) diff --git a/docs/examples/kotlin/databases/create-documents.md b/docs/examples/kotlin/databases/create-documents.md index 01692c6..41a98dc 100644 --- a/docs/examples/kotlin/databases/create-documents.md +++ b/docs/examples/kotlin/databases/create-documents.md @@ -4,6 +4,7 @@ import io.appwrite.services.Databases val client = Client() .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID .setKey("") // Your secret API key val databases = Databases(client) diff --git a/docs/examples/kotlin/databases/decrement-document-attribute.md b/docs/examples/kotlin/databases/decrement-document-attribute.md new file mode 100644 index 0000000..05204d7 --- /dev/null +++ b/docs/examples/kotlin/databases/decrement-document-attribute.md @@ -0,0 +1,19 @@ +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Databases + +val client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your secret API key + +val databases = Databases(client) + +val response = databases.decrementDocumentAttribute( + databaseId = "", + collectionId = "", + documentId = "", + attribute = "", + value = 0, // optional + min = 0 // optional +) diff --git a/docs/examples/kotlin/databases/increment-document-attribute.md b/docs/examples/kotlin/databases/increment-document-attribute.md new file mode 100644 index 0000000..40c1224 --- /dev/null +++ b/docs/examples/kotlin/databases/increment-document-attribute.md @@ -0,0 +1,19 @@ +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Databases + +val client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your secret API key + +val databases = Databases(client) + +val response = databases.incrementDocumentAttribute( + databaseId = "", + collectionId = "", + documentId = "", + attribute = "", + value = 0, // optional + max = 0 // optional +) diff --git a/docs/examples/kotlin/databases/upsert-document.md b/docs/examples/kotlin/databases/upsert-document.md new file mode 100644 index 0000000..d8be0e1 --- /dev/null +++ b/docs/examples/kotlin/databases/upsert-document.md @@ -0,0 +1,18 @@ +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Databases + +val client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setSession("") // The user session to authenticate with + +val databases = Databases(client) + +val response = databases.upsertDocument( + databaseId = "", + collectionId = "", + documentId = "", + data = mapOf( "a" to "b" ), + permissions = listOf("read("any")") // optional +) diff --git a/docs/examples/kotlin/databases/upsert-documents.md b/docs/examples/kotlin/databases/upsert-documents.md index 7459b38..ca861c6 100644 --- a/docs/examples/kotlin/databases/upsert-documents.md +++ b/docs/examples/kotlin/databases/upsert-documents.md @@ -12,5 +12,5 @@ val databases = Databases(client) val response = databases.upsertDocuments( databaseId = "", collectionId = "", - documents = listOf() // optional + documents = listOf() ) diff --git a/src/main/kotlin/io/appwrite/Client.kt b/src/main/kotlin/io/appwrite/Client.kt index c7824ef..429131e 100644 --- a/src/main/kotlin/io/appwrite/Client.kt +++ b/src/main/kotlin/io/appwrite/Client.kt @@ -58,11 +58,11 @@ class Client @JvmOverloads constructor( init { headers = mutableMapOf( "content-type" to "application/json", - "user-agent" to "AppwriteKotlinSDK/9.0.0 ${System.getProperty("http.agent")}", + "user-agent" to "AppwriteKotlinSDK/9.1.0 ${System.getProperty("http.agent")}", "x-sdk-name" to "Kotlin", "x-sdk-platform" to "server", "x-sdk-language" to "kotlin", - "x-sdk-version" to "9.0.0", + "x-sdk-version" to "9.1.0", "x-appwrite-response-format" to "1.7.0", ) diff --git a/src/main/kotlin/io/appwrite/enums/BuildRuntime.kt b/src/main/kotlin/io/appwrite/enums/BuildRuntime.kt index 71d857d..daa1589 100644 --- a/src/main/kotlin/io/appwrite/enums/BuildRuntime.kt +++ b/src/main/kotlin/io/appwrite/enums/BuildRuntime.kt @@ -77,6 +77,8 @@ enum class BuildRuntime(val value: String) { DART_3_3("dart-3.3"), @SerializedName("dart-3.5") DART_3_5("dart-3.5"), + @SerializedName("dart-3.8") + DART_3_8("dart-3.8"), @SerializedName("dotnet-6.0") DOTNET_6_0("dotnet-6.0"), @SerializedName("dotnet-7.0") @@ -128,7 +130,9 @@ enum class BuildRuntime(val value: String) { @SerializedName("flutter-3.27") FLUTTER_3_27("flutter-3.27"), @SerializedName("flutter-3.29") - FLUTTER_3_29("flutter-3.29"); + FLUTTER_3_29("flutter-3.29"), + @SerializedName("flutter-3.32") + FLUTTER_3_32("flutter-3.32"); override fun toString() = value } \ No newline at end of file diff --git a/src/main/kotlin/io/appwrite/enums/ImageFormat.kt b/src/main/kotlin/io/appwrite/enums/ImageFormat.kt index c3dea06..8e74806 100644 --- a/src/main/kotlin/io/appwrite/enums/ImageFormat.kt +++ b/src/main/kotlin/io/appwrite/enums/ImageFormat.kt @@ -14,7 +14,9 @@ enum class ImageFormat(val value: String) { @SerializedName("heic") HEIC("heic"), @SerializedName("avif") - AVIF("avif"); + AVIF("avif"), + @SerializedName("gif") + GIF("gif"); override fun toString() = value } \ No newline at end of file diff --git a/src/main/kotlin/io/appwrite/enums/Runtime.kt b/src/main/kotlin/io/appwrite/enums/Runtime.kt index dd65f3e..084811e 100644 --- a/src/main/kotlin/io/appwrite/enums/Runtime.kt +++ b/src/main/kotlin/io/appwrite/enums/Runtime.kt @@ -77,6 +77,8 @@ enum class Runtime(val value: String) { DART_3_3("dart-3.3"), @SerializedName("dart-3.5") DART_3_5("dart-3.5"), + @SerializedName("dart-3.8") + DART_3_8("dart-3.8"), @SerializedName("dotnet-6.0") DOTNET_6_0("dotnet-6.0"), @SerializedName("dotnet-7.0") @@ -128,7 +130,9 @@ enum class Runtime(val value: String) { @SerializedName("flutter-3.27") FLUTTER_3_27("flutter-3.27"), @SerializedName("flutter-3.29") - FLUTTER_3_29("flutter-3.29"); + FLUTTER_3_29("flutter-3.29"), + @SerializedName("flutter-3.32") + FLUTTER_3_32("flutter-3.32"); override fun toString() = value } \ No newline at end of file diff --git a/src/main/kotlin/io/appwrite/models/AttributeString.kt b/src/main/kotlin/io/appwrite/models/AttributeString.kt index efae2ba..161d7b8 100644 --- a/src/main/kotlin/io/appwrite/models/AttributeString.kt +++ b/src/main/kotlin/io/appwrite/models/AttributeString.kt @@ -67,6 +67,12 @@ data class AttributeString( @SerializedName("default") var default: String?, + /** + * Defines whether this attribute is encrypted or not. + */ + @SerializedName("encrypt") + var encrypt: Boolean?, + ) { fun toMap(): Map = mapOf( "key" to key as Any, @@ -79,6 +85,7 @@ data class AttributeString( "\$updatedAt" to updatedAt as Any, "size" to size as Any, "default" to default as Any, + "encrypt" to encrypt as Any, ) companion object { @@ -97,6 +104,7 @@ data class AttributeString( updatedAt = map["\$updatedAt"] as String, size = (map["size"] as Number).toLong(), default = map["default"] as? String?, + encrypt = map["encrypt"] as? Boolean?, ) } } \ No newline at end of file diff --git a/src/main/kotlin/io/appwrite/models/Document.kt b/src/main/kotlin/io/appwrite/models/Document.kt index 01204de..c0dfe61 100644 --- a/src/main/kotlin/io/appwrite/models/Document.kt +++ b/src/main/kotlin/io/appwrite/models/Document.kt @@ -13,6 +13,12 @@ data class Document( @SerializedName("\$id") val id: String, + /** + * Document automatically incrementing ID. + */ + @SerializedName("\$sequence") + val sequence: Long, + /** * Collection ID. */ @@ -51,6 +57,7 @@ data class Document( ) { fun toMap(): Map = mapOf( "\$id" to id as Any, + "\$sequence" to sequence as Any, "\$collectionId" to collectionId as Any, "\$databaseId" to databaseId as Any, "\$createdAt" to createdAt as Any, @@ -62,6 +69,7 @@ data class Document( companion object { operator fun invoke( id: String, + sequence: Long, collectionId: String, databaseId: String, createdAt: String, @@ -70,6 +78,7 @@ data class Document( data: Map ) = Document>( id, + sequence, collectionId, databaseId, createdAt, @@ -84,6 +93,7 @@ data class Document( nestedType: Class ) = Document( id = map["\$id"] as String, + sequence = (map["\$sequence"] as Number).toLong(), collectionId = map["\$collectionId"] as String, databaseId = map["\$databaseId"] as String, createdAt = map["\$createdAt"] as String, diff --git a/src/main/kotlin/io/appwrite/services/Databases.kt b/src/main/kotlin/io/appwrite/services/Databases.kt index 143e829..6c57ede 100644 --- a/src/main/kotlin/io/appwrite/services/Databases.kt +++ b/src/main/kotlin/io/appwrite/services/Databases.kt @@ -1590,7 +1590,7 @@ class Databases(client: Client) : Service(client) { ) /** - * Create new Documents. Before using this route, you should create a new collection resource using either a [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) API or directly from your database console. + * **WARNING: Experimental Feature** - This endpoint is experimental and not yet officially supported. It may be subject to breaking changes or removal in future versions.Create new Documents. Before using this route, you should create a new collection resource using either a [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) API or directly from your database console. * * @param databaseId Database ID. * @param collectionId Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection). Make sure to define attributes before creating documents. @@ -1628,7 +1628,7 @@ class Databases(client: Client) : Service(client) { } /** - * Create new Documents. Before using this route, you should create a new collection resource using either a [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) API or directly from your database console. + * **WARNING: Experimental Feature** - This endpoint is experimental and not yet officially supported. It may be subject to breaking changes or removal in future versions.Create new Documents. Before using this route, you should create a new collection resource using either a [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) API or directly from your database console. * * @param databaseId Database ID. * @param collectionId Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection). Make sure to define attributes before creating documents. @@ -1648,19 +1648,18 @@ class Databases(client: Client) : Service(client) { ) /** - * Create or update Documents. Before using this route, you should create a new collection resource using either a [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) API or directly from your database console. + * **WARNING: Experimental Feature** - This endpoint is experimental and not yet officially supported. It may be subject to breaking changes or removal in future versions.Create or update Documents. Before using this route, you should create a new collection resource using either a [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) API or directly from your database console. * * @param databaseId Database ID. * @param collectionId Collection ID. * @param documents Array of document data as JSON objects. May contain partial documents. * @return [io.appwrite.models.DocumentList] */ - @JvmOverloads @Throws(AppwriteException::class) suspend fun upsertDocuments( databaseId: String, collectionId: String, - documents: List? = null, + documents: List, nestedType: Class, ): io.appwrite.models.DocumentList { val apiPath = "/databases/{databaseId}/collections/{collectionId}/documents" @@ -1687,19 +1686,18 @@ class Databases(client: Client) : Service(client) { } /** - * Create or update Documents. Before using this route, you should create a new collection resource using either a [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) API or directly from your database console. + * **WARNING: Experimental Feature** - This endpoint is experimental and not yet officially supported. It may be subject to breaking changes or removal in future versions.Create or update Documents. Before using this route, you should create a new collection resource using either a [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) API or directly from your database console. * * @param databaseId Database ID. * @param collectionId Collection ID. * @param documents Array of document data as JSON objects. May contain partial documents. * @return [io.appwrite.models.DocumentList] */ - @JvmOverloads @Throws(AppwriteException::class) suspend fun upsertDocuments( databaseId: String, collectionId: String, - documents: List? = null, + documents: List, ): io.appwrite.models.DocumentList> = upsertDocuments( databaseId, collectionId, @@ -1708,7 +1706,7 @@ class Databases(client: Client) : Service(client) { ) /** - * Update all documents that match your queries, if no queries are submitted then all documents are updated. You can pass only specific fields to be updated. + * **WARNING: Experimental Feature** - This endpoint is experimental and not yet officially supported. It may be subject to breaking changes or removal in future versions.Update all documents that match your queries, if no queries are submitted then all documents are updated. You can pass only specific fields to be updated. * * @param databaseId Database ID. * @param collectionId Collection ID. @@ -1750,7 +1748,7 @@ class Databases(client: Client) : Service(client) { } /** - * Update all documents that match your queries, if no queries are submitted then all documents are updated. You can pass only specific fields to be updated. + * **WARNING: Experimental Feature** - This endpoint is experimental and not yet officially supported. It may be subject to breaking changes or removal in future versions.Update all documents that match your queries, if no queries are submitted then all documents are updated. You can pass only specific fields to be updated. * * @param databaseId Database ID. * @param collectionId Collection ID. @@ -1774,7 +1772,7 @@ class Databases(client: Client) : Service(client) { ) /** - * Bulk delete documents using queries, if no queries are passed then all documents are deleted. + * **WARNING: Experimental Feature** - This endpoint is experimental and not yet officially supported. It may be subject to breaking changes or removal in future versions.Bulk delete documents using queries, if no queries are passed then all documents are deleted. * * @param databaseId Database ID. * @param collectionId Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection). @@ -1813,7 +1811,7 @@ class Databases(client: Client) : Service(client) { } /** - * Bulk delete documents using queries, if no queries are passed then all documents are deleted. + * **WARNING: Experimental Feature** - This endpoint is experimental and not yet officially supported. It may be subject to breaking changes or removal in future versions.Bulk delete documents using queries, if no queries are passed then all documents are deleted. * * @param databaseId Database ID. * @param collectionId Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection). @@ -1898,6 +1896,78 @@ class Databases(client: Client) : Service(client) { nestedType = classOf(), ) + /** + * **WARNING: Experimental Feature** - This endpoint is experimental and not yet officially supported. It may be subject to breaking changes or removal in future versions.Create or update a Document. Before using this route, you should create a new collection resource using either a [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) API or directly from your database console. + * + * @param databaseId Database ID. + * @param collectionId Collection ID. + * @param documentId Document ID. + * @param data Document data as JSON object. Include all required attributes of the document to be created or updated. + * @param permissions An array of permissions strings. By default, the current permissions are inherited. [Learn more about permissions](https://appwrite.io/docs/permissions). + * @return [io.appwrite.models.Document] + */ + @JvmOverloads + @Throws(AppwriteException::class) + suspend fun upsertDocument( + databaseId: String, + collectionId: String, + documentId: String, + data: Any, + permissions: List? = null, + nestedType: Class, + ): io.appwrite.models.Document { + val apiPath = "/databases/{databaseId}/collections/{collectionId}/documents/{documentId}" + .replace("{databaseId}", databaseId) + .replace("{collectionId}", collectionId) + .replace("{documentId}", documentId) + + val apiParams = mutableMapOf( + "data" to data, + "permissions" to permissions, + ) + val apiHeaders = mutableMapOf( + "content-type" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.Document = { + io.appwrite.models.Document.from(map = it as Map, nestedType) + } + return client.call( + "PUT", + apiPath, + apiHeaders, + apiParams, + responseType = classOf(), + converter, + ) + } + + /** + * **WARNING: Experimental Feature** - This endpoint is experimental and not yet officially supported. It may be subject to breaking changes or removal in future versions.Create or update a Document. Before using this route, you should create a new collection resource using either a [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) API or directly from your database console. + * + * @param databaseId Database ID. + * @param collectionId Collection ID. + * @param documentId Document ID. + * @param data Document data as JSON object. Include all required attributes of the document to be created or updated. + * @param permissions An array of permissions strings. By default, the current permissions are inherited. [Learn more about permissions](https://appwrite.io/docs/permissions). + * @return [io.appwrite.models.Document] + */ + @JvmOverloads + @Throws(AppwriteException::class) + suspend fun upsertDocument( + databaseId: String, + collectionId: String, + documentId: String, + data: Any, + permissions: List? = null, + ): io.appwrite.models.Document> = upsertDocument( + databaseId, + collectionId, + documentId, + data, + permissions, + nestedType = classOf(), + ) + /** * Update a document by its unique ID. Using the patch method you can pass only specific fields that will get updated. * @@ -2003,6 +2073,162 @@ class Databases(client: Client) : Service(client) { ) } + /** + * Decrement a specific attribute of a document by a given value. + * + * @param databaseId Database ID. + * @param collectionId Collection ID. + * @param documentId Document ID. + * @param attribute Attribute key. + * @param value Value to decrement the attribute by. The value must be a number. + * @param min Minimum value for the attribute. If the current value is lesser than this value, an exception will be thrown. + * @return [io.appwrite.models.Document] + */ + @JvmOverloads + @Throws(AppwriteException::class) + suspend fun decrementDocumentAttribute( + databaseId: String, + collectionId: String, + documentId: String, + attribute: String, + value: Double? = null, + min: Double? = null, + nestedType: Class, + ): io.appwrite.models.Document { + val apiPath = "/databases/{databaseId}/collections/{collectionId}/documents/{documentId}/{attribute}/decrement" + .replace("{databaseId}", databaseId) + .replace("{collectionId}", collectionId) + .replace("{documentId}", documentId) + .replace("{attribute}", attribute) + + val apiParams = mutableMapOf( + "value" to value, + "min" to min, + ) + val apiHeaders = mutableMapOf( + "content-type" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.Document = { + io.appwrite.models.Document.from(map = it as Map, nestedType) + } + return client.call( + "PATCH", + apiPath, + apiHeaders, + apiParams, + responseType = classOf(), + converter, + ) + } + + /** + * Decrement a specific attribute of a document by a given value. + * + * @param databaseId Database ID. + * @param collectionId Collection ID. + * @param documentId Document ID. + * @param attribute Attribute key. + * @param value Value to decrement the attribute by. The value must be a number. + * @param min Minimum value for the attribute. If the current value is lesser than this value, an exception will be thrown. + * @return [io.appwrite.models.Document] + */ + @JvmOverloads + @Throws(AppwriteException::class) + suspend fun decrementDocumentAttribute( + databaseId: String, + collectionId: String, + documentId: String, + attribute: String, + value: Double? = null, + min: Double? = null, + ): io.appwrite.models.Document> = decrementDocumentAttribute( + databaseId, + collectionId, + documentId, + attribute, + value, + min, + nestedType = classOf(), + ) + + /** + * Increment a specific attribute of a document by a given value. + * + * @param databaseId Database ID. + * @param collectionId Collection ID. + * @param documentId Document ID. + * @param attribute Attribute key. + * @param value Value to increment the attribute by. The value must be a number. + * @param max Maximum value for the attribute. If the current value is greater than this value, an error will be thrown. + * @return [io.appwrite.models.Document] + */ + @JvmOverloads + @Throws(AppwriteException::class) + suspend fun incrementDocumentAttribute( + databaseId: String, + collectionId: String, + documentId: String, + attribute: String, + value: Double? = null, + max: Double? = null, + nestedType: Class, + ): io.appwrite.models.Document { + val apiPath = "/databases/{databaseId}/collections/{collectionId}/documents/{documentId}/{attribute}/increment" + .replace("{databaseId}", databaseId) + .replace("{collectionId}", collectionId) + .replace("{documentId}", documentId) + .replace("{attribute}", attribute) + + val apiParams = mutableMapOf( + "value" to value, + "max" to max, + ) + val apiHeaders = mutableMapOf( + "content-type" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.Document = { + io.appwrite.models.Document.from(map = it as Map, nestedType) + } + return client.call( + "PATCH", + apiPath, + apiHeaders, + apiParams, + responseType = classOf(), + converter, + ) + } + + /** + * Increment a specific attribute of a document by a given value. + * + * @param databaseId Database ID. + * @param collectionId Collection ID. + * @param documentId Document ID. + * @param attribute Attribute key. + * @param value Value to increment the attribute by. The value must be a number. + * @param max Maximum value for the attribute. If the current value is greater than this value, an error will be thrown. + * @return [io.appwrite.models.Document] + */ + @JvmOverloads + @Throws(AppwriteException::class) + suspend fun incrementDocumentAttribute( + databaseId: String, + collectionId: String, + documentId: String, + attribute: String, + value: Double? = null, + max: Double? = null, + ): io.appwrite.models.Document> = incrementDocumentAttribute( + databaseId, + collectionId, + documentId, + attribute, + value, + max, + nestedType = classOf(), + ) + /** * List indexes in the collection. * diff --git a/src/main/kotlin/io/appwrite/services/Tokens.kt b/src/main/kotlin/io/appwrite/services/Tokens.kt index 059595a..7e485bd 100644 --- a/src/main/kotlin/io/appwrite/services/Tokens.kt +++ b/src/main/kotlin/io/appwrite/services/Tokens.kt @@ -51,7 +51,7 @@ class Tokens(client: Client) : Service(client) { } /** - * Create a new token. A token is linked to a file. Token can be passed as a header or request get parameter. + * Create a new token. A token is linked to a file. Token can be passed as a request URL search parameter. * * @param bucketId Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket). * @param fileId File unique ID. diff --git a/src/main/kotlin/io/appwrite/services/Users.kt b/src/main/kotlin/io/appwrite/services/Users.kt index c98fd79..549e858 100644 --- a/src/main/kotlin/io/appwrite/services/Users.kt +++ b/src/main/kotlin/io/appwrite/services/Users.kt @@ -1631,7 +1631,7 @@ class Users(client: Client) : Service(client) { * List the messaging targets that are associated with a user. * * @param userId User ID. - * @param queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, email, phone, status, passwordUpdate, registration, emailVerification, phoneVerification, labels + * @param queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: userId, providerId, identifier, providerType * @return [io.appwrite.models.TargetList] */ @JvmOverloads