diff --git a/CHANGELOG.md b/CHANGELOG.md index b57580ef..f3aa24a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Change Log +## 27.2.0 + +* Added: `DocumentsDB` and `VectorsDB` services for document and vector database access +* Added: `userId`, `emailHash` and `name` parameters to `Avatars.getPhoto()` +* Added: `CLOUDFLARE` and `RESEND` values to `OAuthProvider` enum +* Added: `AUTO` value to `ImageGravity` enum +* Fixed: `Client.setEndpoint` and `setEndpointRealtime` are fluent when called from Java +* Updated: `x-appwrite-response-format` header to `2.0.0` + ## 27.1.0 * Added: `Realtime.onError`, `onOpen`, and `onClose` lifecycle callbacks diff --git a/README.md b/README.md index 62e9d751..e8e30481 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,12 @@ ![Maven Central](https://img.shields.io/maven-central/v/io.appwrite/sdk-for-android.svg?color=green&style=flat-square) ![License](https://img.shields.io/github/license/appwrite/sdk-for-android.svg?style=flat-square) -![Version](https://img.shields.io/badge/api%20version-1.9.6-blue.svg?style=flat-square) +![Version](https://img.shields.io/badge/api%20version-2.0.0-blue.svg?style=flat-square) [![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator) [![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) -**This SDK is compatible with Appwrite server version 1.9.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-android/releases).** +**This SDK targets Appwrite server version 2.0.x as shipped on Appwrite Cloud.** Self-hosted releases can lag behind Cloud — if you run an older self-hosted build, use a matching older SDK from [previous releases](https://github.com/appwrite/sdk-for-android/releases) when APIs differ. 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 Android 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) @@ -38,7 +38,7 @@ repositories { Next, add the dependency to your project's `build.gradle(.kts)` file: ```groovy -implementation("io.appwrite:sdk-for-android:27.0.0") +implementation("io.appwrite:sdk-for-android:27.2.0") ``` ### Maven @@ -49,7 +49,7 @@ Add this to your project's `pom.xml` file: io.appwrite sdk-for-android - 27.0.0 + 27.2.0 ``` diff --git a/build.gradle.kts b/build.gradle.kts index 252363de..2239ad56 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,8 +2,8 @@ import java.util.Properties plugins { id("io.github.gradle-nexus.publish-plugin") version "2.0.0" - id("com.android.library") version "9.3.2" apply false - id("com.android.application") version "9.3.2" apply false + id("com.android.library") version "9.4.0" apply false + id("com.android.application") version "9.4.0" apply false } version = System.getenv("SDK_VERSION") ?: "0.0.0" diff --git a/docs/examples/java/avatars/get-initials.md b/docs/examples/java/avatars/get-initials.md index 1b781b67..08f5bea9 100644 --- a/docs/examples/java/avatars/get-initials.md +++ b/docs/examples/java/avatars/get-initials.md @@ -15,7 +15,7 @@ avatars.getInitials( "", // name (optional) 0, // width (optional) 0, // height (optional) - "", // background (optional) + "FFFFFF", // background (optional) new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); diff --git a/docs/examples/java/avatars/get-photo.md b/docs/examples/java/avatars/get-photo.md index b1d14dca..2204db78 100644 --- a/docs/examples/java/avatars/get-photo.md +++ b/docs/examples/java/avatars/get-photo.md @@ -17,6 +17,9 @@ avatars.getPhoto( 0, // quality (optional) "png", // output (optional) "g", // rating (optional) + "current()", // userId (optional) + "", // emailHash (optional) + "", // name (optional) new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); diff --git a/docs/examples/java/databases/decrement-document-attribute.md b/docs/examples/java/databases/decrement-document-attribute.md index f069abbf..1a2f23e2 100644 --- a/docs/examples/java/databases/decrement-document-attribute.md +++ b/docs/examples/java/databases/decrement-document-attribute.md @@ -15,8 +15,8 @@ databases.decrementDocumentAttribute( "", // databaseId "", // collectionId "", // documentId - "", // attribute - 0, // value (optional) + "", // attribute + 1, // value (optional) 0, // min (optional) "", // transactionId (optional) new CoroutineCallback<>((result, error) -> { diff --git a/docs/examples/java/databases/increment-document-attribute.md b/docs/examples/java/databases/increment-document-attribute.md index c41a9071..fe363592 100644 --- a/docs/examples/java/databases/increment-document-attribute.md +++ b/docs/examples/java/databases/increment-document-attribute.md @@ -15,9 +15,9 @@ databases.incrementDocumentAttribute( "", // databaseId "", // collectionId "", // documentId - "", // attribute - 0, // value (optional) - 0, // max (optional) + "", // attribute + 1, // value (optional) + 100, // max (optional) "", // transactionId (optional) new CoroutineCallback<>((result, error) -> { if (error != null) { diff --git a/docs/examples/java/documentsdb/create-document.md b/docs/examples/java/documentsdb/create-document.md new file mode 100644 index 00000000..77f034d8 --- /dev/null +++ b/docs/examples/java/documentsdb/create-document.md @@ -0,0 +1,39 @@ +```java +import android.util.Log; + +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.Permission; +import io.appwrite.Role; +import io.appwrite.services.DocumentsDB; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject(""); // Your project ID + +DocumentsDB documentsDB = new DocumentsDB(client); + +documentsDB.createDocument( + "", // databaseId + "", // collectionId + "", // documentId + Map.of( + "username", "walter.obrien", + "email", "walter.obrien@example.com", + "fullName", "Walter O'Brien", + "age", 30, + "isAdmin", false + ), // data + List.of(Permission.read(Role.any())), // permissions (optional) + "", // transactionId (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); + +``` diff --git a/docs/examples/java/documentsdb/create-documents.md b/docs/examples/java/documentsdb/create-documents.md new file mode 100644 index 00000000..c52433a2 --- /dev/null +++ b/docs/examples/java/documentsdb/create-documents.md @@ -0,0 +1,29 @@ +```java +import android.util.Log; + +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.DocumentsDB; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject(""); // Your project ID + +DocumentsDB documentsDB = new DocumentsDB(client); + +documentsDB.createDocuments( + "", // databaseId + "", // collectionId + List.of(), // documents + "", // transactionId (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); + +``` diff --git a/docs/examples/java/documentsdb/create-operations.md b/docs/examples/java/documentsdb/create-operations.md new file mode 100644 index 00000000..961a5501 --- /dev/null +++ b/docs/examples/java/documentsdb/create-operations.md @@ -0,0 +1,35 @@ +```java +import android.util.Log; + +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.DocumentsDB; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject(""); // Your project ID + +DocumentsDB documentsDB = new DocumentsDB(client); + +documentsDB.createOperations( + "", // transactionId + List.of(Map.of( + "action", "create", + "databaseId", "", + "collectionId", "", + "documentId", "", + "data", Map.of( + "name", "Walter O'Brien" + ) + )), // operations (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); + +``` diff --git a/docs/examples/java/documentsdb/create-transaction.md b/docs/examples/java/documentsdb/create-transaction.md new file mode 100644 index 00000000..da91c5c8 --- /dev/null +++ b/docs/examples/java/documentsdb/create-transaction.md @@ -0,0 +1,26 @@ +```java +import android.util.Log; + +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.DocumentsDB; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject(""); // Your project ID + +DocumentsDB documentsDB = new DocumentsDB(client); + +documentsDB.createTransaction( + 60, // ttl (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); + +``` diff --git a/docs/examples/java/documentsdb/decrement-document-attribute.md b/docs/examples/java/documentsdb/decrement-document-attribute.md new file mode 100644 index 00000000..f1853ac6 --- /dev/null +++ b/docs/examples/java/documentsdb/decrement-document-attribute.md @@ -0,0 +1,32 @@ +```java +import android.util.Log; + +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.DocumentsDB; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject(""); // Your project ID + +DocumentsDB documentsDB = new DocumentsDB(client); + +documentsDB.decrementDocumentAttribute( + "", // databaseId + "", // collectionId + "", // documentId + "", // attribute + 1, // value (optional) + 0, // min (optional) + "", // transactionId (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); + +``` diff --git a/docs/examples/java/documentsdb/delete-document.md b/docs/examples/java/documentsdb/delete-document.md new file mode 100644 index 00000000..247a63aa --- /dev/null +++ b/docs/examples/java/documentsdb/delete-document.md @@ -0,0 +1,29 @@ +```java +import android.util.Log; + +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.DocumentsDB; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject(""); // Your project ID + +DocumentsDB documentsDB = new DocumentsDB(client); + +documentsDB.deleteDocument( + "", // databaseId + "", // collectionId + "", // documentId + "", // transactionId (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); + +``` diff --git a/docs/examples/java/documentsdb/delete-transaction.md b/docs/examples/java/documentsdb/delete-transaction.md new file mode 100644 index 00000000..0b0a7616 --- /dev/null +++ b/docs/examples/java/documentsdb/delete-transaction.md @@ -0,0 +1,26 @@ +```java +import android.util.Log; + +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.DocumentsDB; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject(""); // Your project ID + +DocumentsDB documentsDB = new DocumentsDB(client); + +documentsDB.deleteTransaction( + "", // transactionId + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); + +``` diff --git a/docs/examples/java/documentsdb/get-document.md b/docs/examples/java/documentsdb/get-document.md new file mode 100644 index 00000000..7bd66e1e --- /dev/null +++ b/docs/examples/java/documentsdb/get-document.md @@ -0,0 +1,30 @@ +```java +import android.util.Log; + +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.DocumentsDB; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject(""); // Your project ID + +DocumentsDB documentsDB = new DocumentsDB(client); + +documentsDB.getDocument( + "", // databaseId + "", // collectionId + "", // documentId + List.of(), // queries (optional) + "", // transactionId (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); + +``` diff --git a/docs/examples/java/documentsdb/get-transaction.md b/docs/examples/java/documentsdb/get-transaction.md new file mode 100644 index 00000000..12c42243 --- /dev/null +++ b/docs/examples/java/documentsdb/get-transaction.md @@ -0,0 +1,26 @@ +```java +import android.util.Log; + +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.DocumentsDB; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject(""); // Your project ID + +DocumentsDB documentsDB = new DocumentsDB(client); + +documentsDB.getTransaction( + "", // transactionId + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); + +``` diff --git a/docs/examples/java/documentsdb/increment-document-attribute.md b/docs/examples/java/documentsdb/increment-document-attribute.md new file mode 100644 index 00000000..fab214e9 --- /dev/null +++ b/docs/examples/java/documentsdb/increment-document-attribute.md @@ -0,0 +1,32 @@ +```java +import android.util.Log; + +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.DocumentsDB; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject(""); // Your project ID + +DocumentsDB documentsDB = new DocumentsDB(client); + +documentsDB.incrementDocumentAttribute( + "", // databaseId + "", // collectionId + "", // documentId + "", // attribute + 1, // value (optional) + 100, // max (optional) + "", // transactionId (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); + +``` diff --git a/docs/examples/java/documentsdb/list-documents.md b/docs/examples/java/documentsdb/list-documents.md new file mode 100644 index 00000000..0abb6734 --- /dev/null +++ b/docs/examples/java/documentsdb/list-documents.md @@ -0,0 +1,31 @@ +```java +import android.util.Log; + +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.DocumentsDB; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject(""); // Your project ID + +DocumentsDB documentsDB = new DocumentsDB(client); + +documentsDB.listDocuments( + "", // databaseId + "", // collectionId + List.of(), // queries (optional) + "", // transactionId (optional) + false, // total (optional) + 0, // ttl (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); + +``` diff --git a/docs/examples/java/documentsdb/list-transactions.md b/docs/examples/java/documentsdb/list-transactions.md new file mode 100644 index 00000000..9b8fcd7b --- /dev/null +++ b/docs/examples/java/documentsdb/list-transactions.md @@ -0,0 +1,26 @@ +```java +import android.util.Log; + +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.DocumentsDB; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject(""); // Your project ID + +DocumentsDB documentsDB = new DocumentsDB(client); + +documentsDB.listTransactions( + List.of(), // queries (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); + +``` diff --git a/docs/examples/java/documentsdb/update-document.md b/docs/examples/java/documentsdb/update-document.md new file mode 100644 index 00000000..da8475fa --- /dev/null +++ b/docs/examples/java/documentsdb/update-document.md @@ -0,0 +1,33 @@ +```java +import android.util.Log; + +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.Permission; +import io.appwrite.Role; +import io.appwrite.services.DocumentsDB; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject(""); // Your project ID + +DocumentsDB documentsDB = new DocumentsDB(client); + +documentsDB.updateDocument( + "", // databaseId + "", // collectionId + "", // documentId + Map.of("a", "b"), // data (optional) + List.of(Permission.read(Role.any())), // permissions (optional) + "", // transactionId (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); + +``` diff --git a/docs/examples/java/documentsdb/update-transaction.md b/docs/examples/java/documentsdb/update-transaction.md new file mode 100644 index 00000000..9d95dfcd --- /dev/null +++ b/docs/examples/java/documentsdb/update-transaction.md @@ -0,0 +1,28 @@ +```java +import android.util.Log; + +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.DocumentsDB; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject(""); // Your project ID + +DocumentsDB documentsDB = new DocumentsDB(client); + +documentsDB.updateTransaction( + "", // transactionId + false, // commit (optional) + false, // rollback (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); + +``` diff --git a/docs/examples/java/documentsdb/upsert-document.md b/docs/examples/java/documentsdb/upsert-document.md new file mode 100644 index 00000000..82e90a40 --- /dev/null +++ b/docs/examples/java/documentsdb/upsert-document.md @@ -0,0 +1,33 @@ +```java +import android.util.Log; + +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.Permission; +import io.appwrite.Role; +import io.appwrite.services.DocumentsDB; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject(""); // Your project ID + +DocumentsDB documentsDB = new DocumentsDB(client); + +documentsDB.upsertDocument( + "", // databaseId + "", // collectionId + "", // documentId + Map.of("a", "b"), // data (optional) + List.of(Permission.read(Role.any())), // permissions (optional) + "", // transactionId (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); + +``` diff --git a/docs/examples/java/storage/create-file.md b/docs/examples/java/storage/create-file.md index bcc8296b..e441255e 100644 --- a/docs/examples/java/storage/create-file.md +++ b/docs/examples/java/storage/create-file.md @@ -19,7 +19,7 @@ storage.createFile( "", // fileId InputFile.fromPath("file.png"), // file List.of(Permission.read(Role.any())), // permissions (optional) - "", // folder (optional) + "photos/2026", // folder (optional) new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); diff --git a/docs/examples/java/storage/get-file-preview.md b/docs/examples/java/storage/get-file-preview.md index f7282076..3d753c44 100644 --- a/docs/examples/java/storage/get-file-preview.md +++ b/docs/examples/java/storage/get-file-preview.md @@ -18,14 +18,14 @@ storage.getFilePreview( "", // fileId 0, // width (optional) 0, // height (optional) - ImageGravity.CENTER, // gravity (optional) + ImageGravity.AUTO, // gravity (optional) -1, // quality (optional) 0, // borderWidth (optional) - "", // borderColor (optional) + "FFFFFF", // borderColor (optional) 0, // borderRadius (optional) 0, // opacity (optional) -360, // rotation (optional) - "", // background (optional) + "FFFFFF", // background (optional) ImageFormat.JPG, // output (optional) "", // token (optional) new CoroutineCallback<>((result, error) -> { diff --git a/docs/examples/java/tablesdb/decrement-row-column.md b/docs/examples/java/tablesdb/decrement-row-column.md index 5f9b7ce1..c998b442 100644 --- a/docs/examples/java/tablesdb/decrement-row-column.md +++ b/docs/examples/java/tablesdb/decrement-row-column.md @@ -15,8 +15,8 @@ tablesDB.decrementRowColumn( "", // databaseId "", // tableId "", // rowId - "", // column - 0, // value (optional) + "", // column + 1, // value (optional) 0, // min (optional) "", // transactionId (optional) new CoroutineCallback<>((result, error) -> { diff --git a/docs/examples/java/tablesdb/increment-row-column.md b/docs/examples/java/tablesdb/increment-row-column.md index ae97cdb8..5fb7189e 100644 --- a/docs/examples/java/tablesdb/increment-row-column.md +++ b/docs/examples/java/tablesdb/increment-row-column.md @@ -15,9 +15,9 @@ tablesDB.incrementRowColumn( "", // databaseId "", // tableId "", // rowId - "", // column - 0, // value (optional) - 0, // max (optional) + "", // column + 1, // value (optional) + 100, // max (optional) "", // transactionId (optional) new CoroutineCallback<>((result, error) -> { if (error != null) { diff --git a/docs/examples/java/vectorsdb/create-document.md b/docs/examples/java/vectorsdb/create-document.md new file mode 100644 index 00000000..8a3d7f9e --- /dev/null +++ b/docs/examples/java/vectorsdb/create-document.md @@ -0,0 +1,38 @@ +```java +import android.util.Log; + +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.Permission; +import io.appwrite.Role; +import io.appwrite.services.VectorsDB; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject(""); // Your project ID + +VectorsDB vectorsDB = new VectorsDB(client); + +vectorsDB.createDocument( + "", // databaseId + "", // collectionId + "", // documentId + Map.of( + "embeddings", List.of(0.12, -0.55, 0.88, 1.02), + "metadata", Map.of( + "key", "value" + ) + ), // data + List.of(Permission.read(Role.any())), // permissions (optional) + "", // transactionId (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); + +``` diff --git a/docs/examples/java/vectorsdb/create-operations.md b/docs/examples/java/vectorsdb/create-operations.md new file mode 100644 index 00000000..7e503634 --- /dev/null +++ b/docs/examples/java/vectorsdb/create-operations.md @@ -0,0 +1,35 @@ +```java +import android.util.Log; + +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.VectorsDB; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject(""); // Your project ID + +VectorsDB vectorsDB = new VectorsDB(client); + +vectorsDB.createOperations( + "", // transactionId + List.of(Map.of( + "action", "create", + "databaseId", "", + "collectionId", "", + "documentId", "", + "data", Map.of( + "name", "Walter O'Brien" + ) + )), // operations (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); + +``` diff --git a/docs/examples/java/vectorsdb/create-query.md b/docs/examples/java/vectorsdb/create-query.md new file mode 100644 index 00000000..3f1cfd5c --- /dev/null +++ b/docs/examples/java/vectorsdb/create-query.md @@ -0,0 +1,31 @@ +```java +import android.util.Log; + +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.VectorsDB; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject(""); // Your project ID + +VectorsDB vectorsDB = new VectorsDB(client); + +vectorsDB.createQuery( + "", // databaseId + "", // collectionId + List.of(), // queries (optional) + "", // transactionId (optional) + false, // total (optional) + 0, // ttl (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); + +``` diff --git a/docs/examples/java/vectorsdb/create-transaction.md b/docs/examples/java/vectorsdb/create-transaction.md new file mode 100644 index 00000000..4784fc47 --- /dev/null +++ b/docs/examples/java/vectorsdb/create-transaction.md @@ -0,0 +1,26 @@ +```java +import android.util.Log; + +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.VectorsDB; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject(""); // Your project ID + +VectorsDB vectorsDB = new VectorsDB(client); + +vectorsDB.createTransaction( + 60, // ttl (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); + +``` diff --git a/docs/examples/java/vectorsdb/delete-document.md b/docs/examples/java/vectorsdb/delete-document.md new file mode 100644 index 00000000..d8067301 --- /dev/null +++ b/docs/examples/java/vectorsdb/delete-document.md @@ -0,0 +1,29 @@ +```java +import android.util.Log; + +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.VectorsDB; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject(""); // Your project ID + +VectorsDB vectorsDB = new VectorsDB(client); + +vectorsDB.deleteDocument( + "", // databaseId + "", // collectionId + "", // documentId + "", // transactionId (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); + +``` diff --git a/docs/examples/java/vectorsdb/delete-transaction.md b/docs/examples/java/vectorsdb/delete-transaction.md new file mode 100644 index 00000000..04b9c4da --- /dev/null +++ b/docs/examples/java/vectorsdb/delete-transaction.md @@ -0,0 +1,26 @@ +```java +import android.util.Log; + +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.VectorsDB; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject(""); // Your project ID + +VectorsDB vectorsDB = new VectorsDB(client); + +vectorsDB.deleteTransaction( + "", // transactionId + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); + +``` diff --git a/docs/examples/java/vectorsdb/get-document.md b/docs/examples/java/vectorsdb/get-document.md new file mode 100644 index 00000000..15ddf82d --- /dev/null +++ b/docs/examples/java/vectorsdb/get-document.md @@ -0,0 +1,30 @@ +```java +import android.util.Log; + +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.VectorsDB; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject(""); // Your project ID + +VectorsDB vectorsDB = new VectorsDB(client); + +vectorsDB.getDocument( + "", // databaseId + "", // collectionId + "", // documentId + List.of(), // queries (optional) + "", // transactionId (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); + +``` diff --git a/docs/examples/java/vectorsdb/get-transaction.md b/docs/examples/java/vectorsdb/get-transaction.md new file mode 100644 index 00000000..987ca6e7 --- /dev/null +++ b/docs/examples/java/vectorsdb/get-transaction.md @@ -0,0 +1,26 @@ +```java +import android.util.Log; + +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.VectorsDB; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject(""); // Your project ID + +VectorsDB vectorsDB = new VectorsDB(client); + +vectorsDB.getTransaction( + "", // transactionId + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); + +``` diff --git a/docs/examples/java/vectorsdb/list-documents.md b/docs/examples/java/vectorsdb/list-documents.md new file mode 100644 index 00000000..12ef1f0c --- /dev/null +++ b/docs/examples/java/vectorsdb/list-documents.md @@ -0,0 +1,31 @@ +```java +import android.util.Log; + +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.VectorsDB; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject(""); // Your project ID + +VectorsDB vectorsDB = new VectorsDB(client); + +vectorsDB.listDocuments( + "", // databaseId + "", // collectionId + List.of(), // queries (optional) + "", // transactionId (optional) + false, // total (optional) + 0, // ttl (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); + +``` diff --git a/docs/examples/java/vectorsdb/list-transactions.md b/docs/examples/java/vectorsdb/list-transactions.md new file mode 100644 index 00000000..18ef0e55 --- /dev/null +++ b/docs/examples/java/vectorsdb/list-transactions.md @@ -0,0 +1,26 @@ +```java +import android.util.Log; + +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.VectorsDB; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject(""); // Your project ID + +VectorsDB vectorsDB = new VectorsDB(client); + +vectorsDB.listTransactions( + List.of(), // queries (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); + +``` diff --git a/docs/examples/java/vectorsdb/update-document.md b/docs/examples/java/vectorsdb/update-document.md new file mode 100644 index 00000000..4acb5cce --- /dev/null +++ b/docs/examples/java/vectorsdb/update-document.md @@ -0,0 +1,33 @@ +```java +import android.util.Log; + +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.Permission; +import io.appwrite.Role; +import io.appwrite.services.VectorsDB; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject(""); // Your project ID + +VectorsDB vectorsDB = new VectorsDB(client); + +vectorsDB.updateDocument( + "", // databaseId + "", // collectionId + "", // documentId + Map.of("a", "b"), // data (optional) + List.of(Permission.read(Role.any())), // permissions (optional) + "", // transactionId (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); + +``` diff --git a/docs/examples/java/vectorsdb/update-transaction.md b/docs/examples/java/vectorsdb/update-transaction.md new file mode 100644 index 00000000..a21aad1a --- /dev/null +++ b/docs/examples/java/vectorsdb/update-transaction.md @@ -0,0 +1,28 @@ +```java +import android.util.Log; + +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.VectorsDB; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject(""); // Your project ID + +VectorsDB vectorsDB = new VectorsDB(client); + +vectorsDB.updateTransaction( + "", // transactionId + false, // commit (optional) + false, // rollback (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); + +``` diff --git a/docs/examples/java/vectorsdb/upsert-document.md b/docs/examples/java/vectorsdb/upsert-document.md new file mode 100644 index 00000000..58ac9a9a --- /dev/null +++ b/docs/examples/java/vectorsdb/upsert-document.md @@ -0,0 +1,33 @@ +```java +import android.util.Log; + +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.Permission; +import io.appwrite.Role; +import io.appwrite.services.VectorsDB; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject(""); // Your project ID + +VectorsDB vectorsDB = new VectorsDB(client); + +vectorsDB.upsertDocument( + "", // databaseId + "", // collectionId + "", // documentId + Map.of("a", "b"), // data (optional) + List.of(Permission.read(Role.any())), // permissions (optional) + "", // transactionId (optional) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); + +``` diff --git a/docs/examples/kotlin/avatars/get-initials.md b/docs/examples/kotlin/avatars/get-initials.md index 1cb76a18..31b1f474 100644 --- a/docs/examples/kotlin/avatars/get-initials.md +++ b/docs/examples/kotlin/avatars/get-initials.md @@ -13,6 +13,6 @@ val result = avatars.getInitials( name = "", // (optional) width = 0, // (optional) height = 0, // (optional) - background = "", // (optional) + background = "FFFFFF", // (optional) ) ``` diff --git a/docs/examples/kotlin/avatars/get-photo.md b/docs/examples/kotlin/avatars/get-photo.md index a05805fb..d1127ba6 100644 --- a/docs/examples/kotlin/avatars/get-photo.md +++ b/docs/examples/kotlin/avatars/get-photo.md @@ -15,5 +15,8 @@ val result = avatars.getPhoto( quality = 0, // (optional) output = "png", // (optional) rating = "g", // (optional) + userId = "current()", // (optional) + emailHash = "", // (optional) + name = "", // (optional) ) ``` diff --git a/docs/examples/kotlin/databases/decrement-document-attribute.md b/docs/examples/kotlin/databases/decrement-document-attribute.md index 9ca780fd..c32a6002 100644 --- a/docs/examples/kotlin/databases/decrement-document-attribute.md +++ b/docs/examples/kotlin/databases/decrement-document-attribute.md @@ -13,8 +13,8 @@ val result = databases.decrementDocumentAttribute( databaseId = "", collectionId = "", documentId = "", - attribute = "", - value = 0, // (optional) + attribute = "", + value = 1, // (optional) min = 0, // (optional) transactionId = "", // (optional) ) diff --git a/docs/examples/kotlin/databases/increment-document-attribute.md b/docs/examples/kotlin/databases/increment-document-attribute.md index 20afc996..daaa6d6a 100644 --- a/docs/examples/kotlin/databases/increment-document-attribute.md +++ b/docs/examples/kotlin/databases/increment-document-attribute.md @@ -13,9 +13,9 @@ val result = databases.incrementDocumentAttribute( databaseId = "", collectionId = "", documentId = "", - attribute = "", - value = 0, // (optional) - max = 0, // (optional) + attribute = "", + value = 1, // (optional) + max = 100, // (optional) transactionId = "", // (optional) ) ``` diff --git a/docs/examples/kotlin/documentsdb/create-document.md b/docs/examples/kotlin/documentsdb/create-document.md new file mode 100644 index 00000000..e2e493f8 --- /dev/null +++ b/docs/examples/kotlin/documentsdb/create-document.md @@ -0,0 +1,28 @@ +```kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.DocumentsDB +import io.appwrite.Permission +import io.appwrite.Role + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +val documentsDB = DocumentsDB(client) + +val result = documentsDB.createDocument( + databaseId = "", + collectionId = "", + documentId = "", + data = mapOf( + "username" to "walter.obrien", + "email" to "walter.obrien@example.com", + "fullName" to "Walter O'Brien", + "age" to 30, + "isAdmin" to false + ), + permissions = listOf(Permission.read(Role.any())), // (optional) + transactionId = "", // (optional) +) +``` diff --git a/docs/examples/kotlin/documentsdb/create-documents.md b/docs/examples/kotlin/documentsdb/create-documents.md new file mode 100644 index 00000000..2923c100 --- /dev/null +++ b/docs/examples/kotlin/documentsdb/create-documents.md @@ -0,0 +1,18 @@ +```kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.DocumentsDB + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +val documentsDB = DocumentsDB(client) + +val result = documentsDB.createDocuments( + databaseId = "", + collectionId = "", + documents = listOf(), + transactionId = "", // (optional) +) +``` diff --git a/docs/examples/kotlin/documentsdb/create-operations.md b/docs/examples/kotlin/documentsdb/create-operations.md new file mode 100644 index 00000000..c6258095 --- /dev/null +++ b/docs/examples/kotlin/documentsdb/create-operations.md @@ -0,0 +1,24 @@ +```kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.DocumentsDB + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +val documentsDB = DocumentsDB(client) + +val result = documentsDB.createOperations( + transactionId = "", + operations = listOf(mapOf( + "action" to "create", + "databaseId" to "", + "collectionId" to "", + "documentId" to "", + "data" to mapOf( + "name" to "Walter O'Brien" + ) + )), // (optional) +) +``` diff --git a/docs/examples/kotlin/documentsdb/create-transaction.md b/docs/examples/kotlin/documentsdb/create-transaction.md new file mode 100644 index 00000000..ad1f0b21 --- /dev/null +++ b/docs/examples/kotlin/documentsdb/create-transaction.md @@ -0,0 +1,15 @@ +```kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.DocumentsDB + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +val documentsDB = DocumentsDB(client) + +val result = documentsDB.createTransaction( + ttl = 60, // (optional) +) +``` diff --git a/docs/examples/kotlin/documentsdb/decrement-document-attribute.md b/docs/examples/kotlin/documentsdb/decrement-document-attribute.md new file mode 100644 index 00000000..fdb11fe0 --- /dev/null +++ b/docs/examples/kotlin/documentsdb/decrement-document-attribute.md @@ -0,0 +1,21 @@ +```kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.DocumentsDB + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +val documentsDB = DocumentsDB(client) + +val result = documentsDB.decrementDocumentAttribute( + databaseId = "", + collectionId = "", + documentId = "", + attribute = "", + value = 1, // (optional) + min = 0, // (optional) + transactionId = "", // (optional) +) +``` diff --git a/docs/examples/kotlin/documentsdb/delete-document.md b/docs/examples/kotlin/documentsdb/delete-document.md new file mode 100644 index 00000000..648a83ca --- /dev/null +++ b/docs/examples/kotlin/documentsdb/delete-document.md @@ -0,0 +1,18 @@ +```kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.DocumentsDB + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +val documentsDB = DocumentsDB(client) + +val result = documentsDB.deleteDocument( + databaseId = "", + collectionId = "", + documentId = "", + transactionId = "", // (optional) +) +``` diff --git a/docs/examples/kotlin/documentsdb/delete-transaction.md b/docs/examples/kotlin/documentsdb/delete-transaction.md new file mode 100644 index 00000000..d991466f --- /dev/null +++ b/docs/examples/kotlin/documentsdb/delete-transaction.md @@ -0,0 +1,15 @@ +```kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.DocumentsDB + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +val documentsDB = DocumentsDB(client) + +val result = documentsDB.deleteTransaction( + transactionId = "", +) +``` diff --git a/docs/examples/kotlin/documentsdb/get-document.md b/docs/examples/kotlin/documentsdb/get-document.md new file mode 100644 index 00000000..1988e002 --- /dev/null +++ b/docs/examples/kotlin/documentsdb/get-document.md @@ -0,0 +1,19 @@ +```kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.DocumentsDB + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +val documentsDB = DocumentsDB(client) + +val result = documentsDB.getDocument( + databaseId = "", + collectionId = "", + documentId = "", + queries = listOf(), // (optional) + transactionId = "", // (optional) +) +``` diff --git a/docs/examples/kotlin/documentsdb/get-transaction.md b/docs/examples/kotlin/documentsdb/get-transaction.md new file mode 100644 index 00000000..695412e7 --- /dev/null +++ b/docs/examples/kotlin/documentsdb/get-transaction.md @@ -0,0 +1,15 @@ +```kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.DocumentsDB + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +val documentsDB = DocumentsDB(client) + +val result = documentsDB.getTransaction( + transactionId = "", +) +``` diff --git a/docs/examples/kotlin/documentsdb/increment-document-attribute.md b/docs/examples/kotlin/documentsdb/increment-document-attribute.md new file mode 100644 index 00000000..8286ad44 --- /dev/null +++ b/docs/examples/kotlin/documentsdb/increment-document-attribute.md @@ -0,0 +1,21 @@ +```kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.DocumentsDB + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +val documentsDB = DocumentsDB(client) + +val result = documentsDB.incrementDocumentAttribute( + databaseId = "", + collectionId = "", + documentId = "", + attribute = "", + value = 1, // (optional) + max = 100, // (optional) + transactionId = "", // (optional) +) +``` diff --git a/docs/examples/kotlin/documentsdb/list-documents.md b/docs/examples/kotlin/documentsdb/list-documents.md new file mode 100644 index 00000000..a8c1b66b --- /dev/null +++ b/docs/examples/kotlin/documentsdb/list-documents.md @@ -0,0 +1,20 @@ +```kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.DocumentsDB + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +val documentsDB = DocumentsDB(client) + +val result = documentsDB.listDocuments( + databaseId = "", + collectionId = "", + queries = listOf(), // (optional) + transactionId = "", // (optional) + total = false, // (optional) + ttl = 0, // (optional) +) +``` diff --git a/docs/examples/kotlin/documentsdb/list-transactions.md b/docs/examples/kotlin/documentsdb/list-transactions.md new file mode 100644 index 00000000..46571468 --- /dev/null +++ b/docs/examples/kotlin/documentsdb/list-transactions.md @@ -0,0 +1,15 @@ +```kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.DocumentsDB + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +val documentsDB = DocumentsDB(client) + +val result = documentsDB.listTransactions( + queries = listOf(), // (optional) +) +``` diff --git a/docs/examples/kotlin/documentsdb/update-document.md b/docs/examples/kotlin/documentsdb/update-document.md new file mode 100644 index 00000000..69668863 --- /dev/null +++ b/docs/examples/kotlin/documentsdb/update-document.md @@ -0,0 +1,22 @@ +```kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.DocumentsDB +import io.appwrite.Permission +import io.appwrite.Role + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +val documentsDB = DocumentsDB(client) + +val result = documentsDB.updateDocument( + databaseId = "", + collectionId = "", + documentId = "", + data = mapOf( "a" to "b" ), // (optional) + permissions = listOf(Permission.read(Role.any())), // (optional) + transactionId = "", // (optional) +) +``` diff --git a/docs/examples/kotlin/documentsdb/update-transaction.md b/docs/examples/kotlin/documentsdb/update-transaction.md new file mode 100644 index 00000000..78fb3e7b --- /dev/null +++ b/docs/examples/kotlin/documentsdb/update-transaction.md @@ -0,0 +1,17 @@ +```kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.DocumentsDB + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +val documentsDB = DocumentsDB(client) + +val result = documentsDB.updateTransaction( + transactionId = "", + commit = false, // (optional) + rollback = false, // (optional) +) +``` diff --git a/docs/examples/kotlin/documentsdb/upsert-document.md b/docs/examples/kotlin/documentsdb/upsert-document.md new file mode 100644 index 00000000..defc50a2 --- /dev/null +++ b/docs/examples/kotlin/documentsdb/upsert-document.md @@ -0,0 +1,22 @@ +```kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.DocumentsDB +import io.appwrite.Permission +import io.appwrite.Role + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +val documentsDB = DocumentsDB(client) + +val result = documentsDB.upsertDocument( + databaseId = "", + collectionId = "", + documentId = "", + data = mapOf( "a" to "b" ), // (optional) + permissions = listOf(Permission.read(Role.any())), // (optional) + transactionId = "", // (optional) +) +``` diff --git a/docs/examples/kotlin/storage/create-file.md b/docs/examples/kotlin/storage/create-file.md index 44d3ac8b..0e095d2d 100644 --- a/docs/examples/kotlin/storage/create-file.md +++ b/docs/examples/kotlin/storage/create-file.md @@ -17,6 +17,6 @@ val result = storage.createFile( fileId = "", file = InputFile.fromPath("file.png"), permissions = listOf(Permission.read(Role.any())), // (optional) - folder = "", // (optional) + folder = "photos/2026", // (optional) ) ``` diff --git a/docs/examples/kotlin/storage/get-file-preview.md b/docs/examples/kotlin/storage/get-file-preview.md index 2bb8cffd..e2d2851d 100644 --- a/docs/examples/kotlin/storage/get-file-preview.md +++ b/docs/examples/kotlin/storage/get-file-preview.md @@ -16,14 +16,14 @@ val result = storage.getFilePreview( fileId = "", width = 0, // (optional) height = 0, // (optional) - gravity = ImageGravity.CENTER, // (optional) + gravity = ImageGravity.AUTO, // (optional) quality = -1, // (optional) borderWidth = 0, // (optional) - borderColor = "", // (optional) + borderColor = "FFFFFF", // (optional) borderRadius = 0, // (optional) opacity = 0, // (optional) rotation = -360, // (optional) - background = "", // (optional) + background = "FFFFFF", // (optional) output = ImageFormat.JPG, // (optional) token = "", // (optional) ) diff --git a/docs/examples/kotlin/tablesdb/decrement-row-column.md b/docs/examples/kotlin/tablesdb/decrement-row-column.md index 848eea97..157c3d11 100644 --- a/docs/examples/kotlin/tablesdb/decrement-row-column.md +++ b/docs/examples/kotlin/tablesdb/decrement-row-column.md @@ -13,8 +13,8 @@ val result = tablesDB.decrementRowColumn( databaseId = "", tableId = "", rowId = "", - column = "", - value = 0, // (optional) + column = "", + value = 1, // (optional) min = 0, // (optional) transactionId = "", // (optional) ) diff --git a/docs/examples/kotlin/tablesdb/increment-row-column.md b/docs/examples/kotlin/tablesdb/increment-row-column.md index 85c03791..802c6a2b 100644 --- a/docs/examples/kotlin/tablesdb/increment-row-column.md +++ b/docs/examples/kotlin/tablesdb/increment-row-column.md @@ -13,9 +13,9 @@ val result = tablesDB.incrementRowColumn( databaseId = "", tableId = "", rowId = "", - column = "", - value = 0, // (optional) - max = 0, // (optional) + column = "", + value = 1, // (optional) + max = 100, // (optional) transactionId = "", // (optional) ) ``` diff --git a/docs/examples/kotlin/vectorsdb/create-document.md b/docs/examples/kotlin/vectorsdb/create-document.md new file mode 100644 index 00000000..960654fa --- /dev/null +++ b/docs/examples/kotlin/vectorsdb/create-document.md @@ -0,0 +1,27 @@ +```kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.VectorsDB +import io.appwrite.Permission +import io.appwrite.Role + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +val vectorsDB = VectorsDB(client) + +val result = vectorsDB.createDocument( + databaseId = "", + collectionId = "", + documentId = "", + data = mapOf( + "embeddings" to listOf(0.12, -0.55, 0.88, 1.02), + "metadata" to mapOf( + "key" to "value" + ) + ), + permissions = listOf(Permission.read(Role.any())), // (optional) + transactionId = "", // (optional) +) +``` diff --git a/docs/examples/kotlin/vectorsdb/create-operations.md b/docs/examples/kotlin/vectorsdb/create-operations.md new file mode 100644 index 00000000..1a2908af --- /dev/null +++ b/docs/examples/kotlin/vectorsdb/create-operations.md @@ -0,0 +1,24 @@ +```kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.VectorsDB + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +val vectorsDB = VectorsDB(client) + +val result = vectorsDB.createOperations( + transactionId = "", + operations = listOf(mapOf( + "action" to "create", + "databaseId" to "", + "collectionId" to "", + "documentId" to "", + "data" to mapOf( + "name" to "Walter O'Brien" + ) + )), // (optional) +) +``` diff --git a/docs/examples/kotlin/vectorsdb/create-query.md b/docs/examples/kotlin/vectorsdb/create-query.md new file mode 100644 index 00000000..0e8aaf25 --- /dev/null +++ b/docs/examples/kotlin/vectorsdb/create-query.md @@ -0,0 +1,20 @@ +```kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.VectorsDB + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +val vectorsDB = VectorsDB(client) + +val result = vectorsDB.createQuery( + databaseId = "", + collectionId = "", + queries = listOf(), // (optional) + transactionId = "", // (optional) + total = false, // (optional) + ttl = 0, // (optional) +) +``` diff --git a/docs/examples/kotlin/vectorsdb/create-transaction.md b/docs/examples/kotlin/vectorsdb/create-transaction.md new file mode 100644 index 00000000..9ca3de5c --- /dev/null +++ b/docs/examples/kotlin/vectorsdb/create-transaction.md @@ -0,0 +1,15 @@ +```kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.VectorsDB + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +val vectorsDB = VectorsDB(client) + +val result = vectorsDB.createTransaction( + ttl = 60, // (optional) +) +``` diff --git a/docs/examples/kotlin/vectorsdb/delete-document.md b/docs/examples/kotlin/vectorsdb/delete-document.md new file mode 100644 index 00000000..9cc1856f --- /dev/null +++ b/docs/examples/kotlin/vectorsdb/delete-document.md @@ -0,0 +1,18 @@ +```kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.VectorsDB + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +val vectorsDB = VectorsDB(client) + +val result = vectorsDB.deleteDocument( + databaseId = "", + collectionId = "", + documentId = "", + transactionId = "", // (optional) +) +``` diff --git a/docs/examples/kotlin/vectorsdb/delete-transaction.md b/docs/examples/kotlin/vectorsdb/delete-transaction.md new file mode 100644 index 00000000..e97ab53a --- /dev/null +++ b/docs/examples/kotlin/vectorsdb/delete-transaction.md @@ -0,0 +1,15 @@ +```kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.VectorsDB + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +val vectorsDB = VectorsDB(client) + +val result = vectorsDB.deleteTransaction( + transactionId = "", +) +``` diff --git a/docs/examples/kotlin/vectorsdb/get-document.md b/docs/examples/kotlin/vectorsdb/get-document.md new file mode 100644 index 00000000..22584ab1 --- /dev/null +++ b/docs/examples/kotlin/vectorsdb/get-document.md @@ -0,0 +1,19 @@ +```kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.VectorsDB + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +val vectorsDB = VectorsDB(client) + +val result = vectorsDB.getDocument( + databaseId = "", + collectionId = "", + documentId = "", + queries = listOf(), // (optional) + transactionId = "", // (optional) +) +``` diff --git a/docs/examples/kotlin/vectorsdb/get-transaction.md b/docs/examples/kotlin/vectorsdb/get-transaction.md new file mode 100644 index 00000000..2a510ea8 --- /dev/null +++ b/docs/examples/kotlin/vectorsdb/get-transaction.md @@ -0,0 +1,15 @@ +```kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.VectorsDB + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +val vectorsDB = VectorsDB(client) + +val result = vectorsDB.getTransaction( + transactionId = "", +) +``` diff --git a/docs/examples/kotlin/vectorsdb/list-documents.md b/docs/examples/kotlin/vectorsdb/list-documents.md new file mode 100644 index 00000000..90a7f04a --- /dev/null +++ b/docs/examples/kotlin/vectorsdb/list-documents.md @@ -0,0 +1,20 @@ +```kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.VectorsDB + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +val vectorsDB = VectorsDB(client) + +val result = vectorsDB.listDocuments( + databaseId = "", + collectionId = "", + queries = listOf(), // (optional) + transactionId = "", // (optional) + total = false, // (optional) + ttl = 0, // (optional) +) +``` diff --git a/docs/examples/kotlin/vectorsdb/list-transactions.md b/docs/examples/kotlin/vectorsdb/list-transactions.md new file mode 100644 index 00000000..97981c01 --- /dev/null +++ b/docs/examples/kotlin/vectorsdb/list-transactions.md @@ -0,0 +1,15 @@ +```kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.VectorsDB + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +val vectorsDB = VectorsDB(client) + +val result = vectorsDB.listTransactions( + queries = listOf(), // (optional) +) +``` diff --git a/docs/examples/kotlin/vectorsdb/update-document.md b/docs/examples/kotlin/vectorsdb/update-document.md new file mode 100644 index 00000000..13422596 --- /dev/null +++ b/docs/examples/kotlin/vectorsdb/update-document.md @@ -0,0 +1,22 @@ +```kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.VectorsDB +import io.appwrite.Permission +import io.appwrite.Role + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +val vectorsDB = VectorsDB(client) + +val result = vectorsDB.updateDocument( + databaseId = "", + collectionId = "", + documentId = "", + data = mapOf( "a" to "b" ), // (optional) + permissions = listOf(Permission.read(Role.any())), // (optional) + transactionId = "", // (optional) +) +``` diff --git a/docs/examples/kotlin/vectorsdb/update-transaction.md b/docs/examples/kotlin/vectorsdb/update-transaction.md new file mode 100644 index 00000000..c49da348 --- /dev/null +++ b/docs/examples/kotlin/vectorsdb/update-transaction.md @@ -0,0 +1,17 @@ +```kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.VectorsDB + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +val vectorsDB = VectorsDB(client) + +val result = vectorsDB.updateTransaction( + transactionId = "", + commit = false, // (optional) + rollback = false, // (optional) +) +``` diff --git a/docs/examples/kotlin/vectorsdb/upsert-document.md b/docs/examples/kotlin/vectorsdb/upsert-document.md new file mode 100644 index 00000000..111b61c6 --- /dev/null +++ b/docs/examples/kotlin/vectorsdb/upsert-document.md @@ -0,0 +1,22 @@ +```kotlin +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.VectorsDB +import io.appwrite.Permission +import io.appwrite.Role + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +val vectorsDB = VectorsDB(client) + +val result = vectorsDB.upsertDocument( + databaseId = "", + collectionId = "", + documentId = "", + data = mapOf( "a" to "b" ), // (optional) + permissions = listOf(Permission.read(Role.any())), // (optional) + transactionId = "", // (optional) +) +``` diff --git a/example/build.gradle.kts b/example/build.gradle.kts index 2a7b4801..8f1ca9b8 100644 --- a/example/build.gradle.kts +++ b/example/build.gradle.kts @@ -9,7 +9,7 @@ android { defaultConfig { applicationId = "io.appwrite.android" - minSdk = 23 + minSdk = 24 @Suppress("DEPRECATION") targetSdk = 37 versionCode = 1 @@ -41,9 +41,9 @@ dependencies { implementation("androidx.appcompat:appcompat:1.8.0") implementation("com.google.android.material:material:1.14.0") implementation("androidx.constraintlayout:constraintlayout:2.2.2") - implementation("androidx.navigation:navigation-fragment-ktx:2.9.8") + implementation("androidx.navigation:navigation-fragment-ktx:2.10.0") implementation("androidx.fragment:fragment-ktx:1.9.0") - implementation("androidx.navigation:navigation-ui-ktx:2.9.8") + implementation("androidx.navigation:navigation-ui-ktx:2.10.0") implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.11.0") implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.11.0") implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.11.0") diff --git a/library/src/main/java/io/appwrite/Client.kt b/library/src/main/java/io/appwrite/Client.kt index 55f4113a..8b5455ea 100644 --- a/library/src/main/java/io/appwrite/Client.kt +++ b/library/src/main/java/io/appwrite/Client.kt @@ -45,7 +45,9 @@ import kotlin.coroutines.resume class Client @JvmOverloads constructor( context: Context, + @set:JvmSynthetic var endpoint: String = "https://cloud.appwrite.io/v1", + @set:JvmSynthetic var endpointRealtime: String? = null, private var selfSigned: Boolean = false ) : CoroutineScope { @@ -94,8 +96,8 @@ class Client @JvmOverloads constructor( "x-sdk-name" to "Android", "x-sdk-platform" to "client", "x-sdk-language" to "android", - "x-sdk-version" to "27.0.0", - "x-appwrite-response-format" to "1.9.6" + "x-sdk-version" to "27.2.0", + "x-appwrite-response-format" to "2.0.0" ) config = mutableMapOf() diff --git a/library/src/main/java/io/appwrite/enums/ImageGravity.kt b/library/src/main/java/io/appwrite/enums/ImageGravity.kt index 58c51022..21e328e4 100644 --- a/library/src/main/java/io/appwrite/enums/ImageGravity.kt +++ b/library/src/main/java/io/appwrite/enums/ImageGravity.kt @@ -3,6 +3,8 @@ package io.appwrite.enums import com.google.gson.annotations.SerializedName enum class ImageGravity(val value: String) { + @SerializedName("auto") + AUTO("auto"), @SerializedName("center") CENTER("center"), @SerializedName("top-left") diff --git a/library/src/main/java/io/appwrite/enums/OAuthProvider.kt b/library/src/main/java/io/appwrite/enums/OAuthProvider.kt index bc039175..e71acdf2 100644 --- a/library/src/main/java/io/appwrite/enums/OAuthProvider.kt +++ b/library/src/main/java/io/appwrite/enums/OAuthProvider.kt @@ -21,6 +21,8 @@ enum class OAuthProvider(val value: String) { BITLY("bitly"), @SerializedName("box") BOX("box"), + @SerializedName("cloudflare") + CLOUDFLARE("cloudflare"), @SerializedName("dailymotion") DAILYMOTION("dailymotion"), @SerializedName("discord") @@ -65,6 +67,8 @@ enum class OAuthProvider(val value: String) { PAYPALSANDBOX("paypalSandbox"), @SerializedName("podio") PODIO("podio"), + @SerializedName("resend") + RESEND("resend"), @SerializedName("salesforce") SALESFORCE("salesforce"), @SerializedName("slack") diff --git a/library/src/main/java/io/appwrite/services/Account.kt b/library/src/main/java/io/appwrite/services/Account.kt index 495a4e3a..fd2a009e 100644 --- a/library/src/main/java/io/appwrite/services/Account.kt +++ b/library/src/main/java/io/appwrite/services/Account.kt @@ -1633,7 +1633,7 @@ class Account(client: Client) : Service(client) { * A user is limited to 10 active sessions at a time by default. [Learn more about session limits](https://appwrite.io/docs/authentication-security#limits). * * - * @param provider OAuth2 Provider. Currently, supported providers are: amazon, apple, appwrite, auth0, authentik, autodesk, bitbucket, bitly, box, dailymotion, discord, disqus, dropbox, etsy, facebook, figma, fusionauth, github, gitlab, google, huggingface, keycloak, kick, linkedin, microsoft, notion, oidc, okta, paypal, paypalSandbox, podio, salesforce, slack, spotify, stripe, tradeshift, tradeshiftBox, twitch, wordpress, x, yahoo, yammer, yandex, zoho, zoom. + * @param provider OAuth2 Provider. Currently, supported providers are: amazon, apple, appwrite, auth0, authentik, autodesk, bitbucket, bitly, box, cloudflare, dailymotion, discord, disqus, dropbox, etsy, facebook, figma, fusionauth, github, gitlab, google, huggingface, keycloak, kick, linkedin, microsoft, notion, oidc, okta, paypal, paypalSandbox, podio, resend, salesforce, slack, spotify, stripe, tradeshift, tradeshiftBox, twitch, wordpress, x, yahoo, yammer, yandex, zoho, zoom. * @param success URL to redirect back to your app after a successful login attempt. Only URLs from hostnames in your project's platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. * @param failure URL to redirect back to your app after a failed login attempt. Only URLs from hostnames in your project's platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. * @param scopes A list of custom OAuth2 scopes. Check each provider internal docs for a list of supported scopes. Maximum of 100 scopes are allowed, each 4096 characters long. @@ -2098,7 +2098,7 @@ class Account(client: Client) : Service(client) { * * A user is limited to 10 active sessions at a time by default. [Learn more about session limits](https://appwrite.io/docs/authentication-security#limits). * - * @param provider OAuth2 Provider. Currently, supported providers are: amazon, apple, appwrite, auth0, authentik, autodesk, bitbucket, bitly, box, dailymotion, discord, disqus, dropbox, etsy, facebook, figma, fusionauth, github, gitlab, google, huggingface, keycloak, kick, linkedin, microsoft, notion, oidc, okta, paypal, paypalSandbox, podio, salesforce, slack, spotify, stripe, tradeshift, tradeshiftBox, twitch, wordpress, x, yahoo, yammer, yandex, zoho, zoom. + * @param provider OAuth2 Provider. Currently, supported providers are: amazon, apple, appwrite, auth0, authentik, autodesk, bitbucket, bitly, box, cloudflare, dailymotion, discord, disqus, dropbox, etsy, facebook, figma, fusionauth, github, gitlab, google, huggingface, keycloak, kick, linkedin, microsoft, notion, oidc, okta, paypal, paypalSandbox, podio, resend, salesforce, slack, spotify, stripe, tradeshift, tradeshiftBox, twitch, wordpress, x, yahoo, yammer, yandex, zoho, zoom. * @param success URL to redirect back to your app after a successful login attempt. Only URLs from hostnames in your project's platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. * @param failure URL to redirect back to your app after a failed login attempt. Only URLs from hostnames in your project's platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. * @param scopes A list of custom OAuth2 scopes. Check each provider internal docs for a list of supported scopes. Maximum of 100 scopes are allowed, each 4096 characters long. diff --git a/library/src/main/java/io/appwrite/services/Avatars.kt b/library/src/main/java/io/appwrite/services/Avatars.kt index 7541466c..cce2d3da 100644 --- a/library/src/main/java/io/appwrite/services/Avatars.kt +++ b/library/src/main/java/io/appwrite/services/Avatars.kt @@ -240,13 +240,18 @@ class Avatars(client: Client) : Service(client) { } /** - * Returns the best available profile photo for the currently authenticated user. The endpoint tries each source in priority order and returns the first successful result: Gravatar, Libavatar, Appwrite Initials, built-in static fallback file. + * Returns the best available profile photo for a user. The endpoint tries each source in priority order and returns the first successful result: OAuth2 identity photo, Gravatar, Libravatar, Appwrite Initials, built-in static fallback. + * + * Passing `userId` — `current()` for the authenticated user — resolves the photo from everything known about that user: identity photos, email, and name. An explicit `emailHash` or `name` then overrides just that value, and the user's remaining sources stay in the chain. Without `userId`, passing `emailHash` and/or `name` resolves the avatar from those values alone: the hash is looked up on Gravatar and Libravatar, the name is rendered as initials, and the session user stays out of the chain so their own photo never shadows the avatar being asked for. When nothing is passed, the photo resolves for the currently authenticated user. Emails are only ever accepted pre-hashed, so no address ends up in a URL. * * @param width Output image width in pixels. Pass an integer between 0 and 2000. Defaults to 256. * @param height Output image height in pixels. Pass an integer between 0 and 2000. Defaults to 256. * @param quality Output image quality between 0 and 100. Defaults to 100. * @param output Output image format. Defaults to 'png'. * @param rating Maximum image rating to fetch from Gravatar/Libravatar. Defaults to 'g'. + * @param userId User ID to resolve the photo for. Pass 'current()' for the currently authenticated user. When omitted, the session user is used only if no emailHash and no name is passed. + * @param emailHash SHA256 hash of the lowercase, trimmed email address to look up on Gravatar and Libravatar instead of the user's own email. Pass the hash, never the address itself. + * @param name Name to render initials from instead of the user's own name. Max length: 128 chars. * @return [ByteArray] */ @JvmOverloads @@ -256,6 +261,9 @@ class Avatars(client: Client) : Service(client) { quality: Long? = null, output: String? = null, rating: String? = null, + userId: String? = null, + emailHash: String? = null, + name: String? = null, ): ByteArray { val apiPath = "/avatars/photo" val apiParams = mutableMapOf( @@ -264,6 +272,9 @@ class Avatars(client: Client) : Service(client) { "quality" to quality, "output" to output, "rating" to rating, + "userId" to userId, + "emailHash" to emailHash, + "name" to name, ) val apiHeaders = mutableMapOf( "X-Appwrite-Project" to client.config["project"].orEmpty(), diff --git a/library/src/main/java/io/appwrite/services/DocumentsDB.kt b/library/src/main/java/io/appwrite/services/DocumentsDB.kt new file mode 100644 index 00000000..28646d98 --- /dev/null +++ b/library/src/main/java/io/appwrite/services/DocumentsDB.kt @@ -0,0 +1,882 @@ +package io.appwrite.services + +import android.net.Uri +import io.appwrite.Client +import io.appwrite.Service +import io.appwrite.exceptions.AppwriteException +import io.appwrite.extensions.classOf +import io.appwrite.models.* +import okhttp3.Cookie +import java.io.File + +/** + * */ +class DocumentsDB(client: Client) : Service(client) { + /** + * List transactions across all databases. + * + * @param queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). + * @return [io.appwrite.models.TransactionList] + */ + @JvmOverloads + suspend fun listTransactions( + queries: List? = null, + ): io.appwrite.models.TransactionList { + val apiPath = "/documentsdb/transactions" + val apiParams = mutableMapOf( + "queries" to queries, + ) + val apiHeaders = mutableMapOf( + "X-Appwrite-Project" to client.config["project"].orEmpty(), + "accept" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.TransactionList = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.TransactionList.from(map = it as Map) + } + return client.call( + "GET", + apiPath, + apiHeaders, + apiParams, + responseType = io.appwrite.models.TransactionList::class.java, + converter, + ) + } + + /** + * Create a new transaction. + * + * @param ttl Seconds before the transaction expires. + * @return [io.appwrite.models.Transaction] + */ + @JvmOverloads + suspend fun createTransaction( + ttl: Long? = null, + ): io.appwrite.models.Transaction { + val apiPath = "/documentsdb/transactions" + val apiParams = mutableMapOf( + "ttl" to ttl, + ) + val apiHeaders = mutableMapOf( + "X-Appwrite-Project" to client.config["project"].orEmpty(), + "content-type" to "application/json", + "accept" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.Transaction = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.Transaction.from(map = it as Map) + } + return client.call( + "POST", + apiPath, + apiHeaders, + apiParams, + responseType = io.appwrite.models.Transaction::class.java, + converter, + ) + } + + /** + * Get a transaction by its unique ID. + * + * @param transactionId Transaction ID. + * @return [io.appwrite.models.Transaction] + */ + suspend fun getTransaction( + transactionId: String, + ): io.appwrite.models.Transaction { + val apiPath = ("/documentsdb/transactions/{transactionId}" + .replace("{transactionId}", transactionId) + ) + val apiParams = mutableMapOf() + val apiHeaders = mutableMapOf( + "X-Appwrite-Project" to client.config["project"].orEmpty(), + "accept" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.Transaction = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.Transaction.from(map = it as Map) + } + return client.call( + "GET", + apiPath, + apiHeaders, + apiParams, + responseType = io.appwrite.models.Transaction::class.java, + converter, + ) + } + + /** + * Update a transaction, to either commit or roll back its operations. + * + * @param transactionId Transaction ID. + * @param commit Commit transaction? + * @param rollback Rollback transaction? + * @return [io.appwrite.models.Transaction] + */ + @JvmOverloads + suspend fun updateTransaction( + transactionId: String, + commit: Boolean? = null, + rollback: Boolean? = null, + ): io.appwrite.models.Transaction { + val apiPath = ("/documentsdb/transactions/{transactionId}" + .replace("{transactionId}", transactionId) + ) + val apiParams = mutableMapOf( + "commit" to commit, + "rollback" to rollback, + ) + val apiHeaders = mutableMapOf( + "X-Appwrite-Project" to client.config["project"].orEmpty(), + "content-type" to "application/json", + "accept" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.Transaction = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.Transaction.from(map = it as Map) + } + return client.call( + "PATCH", + apiPath, + apiHeaders, + apiParams, + responseType = io.appwrite.models.Transaction::class.java, + converter, + ) + } + + /** + * Delete a transaction by its unique ID. + * + * @param transactionId Transaction ID. + * @return [Any] + */ + suspend fun deleteTransaction( + transactionId: String, + ): Any { + val apiPath = ("/documentsdb/transactions/{transactionId}" + .replace("{transactionId}", transactionId) + ) + val apiParams = mutableMapOf() + val apiHeaders = mutableMapOf( + "X-Appwrite-Project" to client.config["project"].orEmpty(), + "content-type" to "application/json", + ) + return client.call( + "DELETE", + apiPath, + apiHeaders, + apiParams, + responseType = Any::class.java, + ) + } + + /** + * Create multiple operations in a single transaction. + * + * @param transactionId Transaction ID. + * @param operations Array of staged operations. + * @return [io.appwrite.models.Transaction] + */ + @JvmOverloads + suspend fun createOperations( + transactionId: String, + operations: List>? = null, + ): io.appwrite.models.Transaction { + val apiPath = ("/documentsdb/transactions/{transactionId}/operations" + .replace("{transactionId}", transactionId) + ) + val apiParams = mutableMapOf( + "operations" to operations, + ) + val apiHeaders = mutableMapOf( + "X-Appwrite-Project" to client.config["project"].orEmpty(), + "content-type" to "application/json", + "accept" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.Transaction = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.Transaction.from(map = it as Map) + } + return client.call( + "POST", + apiPath, + apiHeaders, + apiParams, + responseType = io.appwrite.models.Transaction::class.java, + converter, + ) + } + + /** + * Get a list of all the user's documents in a given collection. You can use the query params to filter your results. + * + * @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). + * @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. + * @param transactionId Transaction ID to read uncommitted changes within the transaction. + * @param total When set to false, the total count returned will be 0 and will not be calculated. + * @param ttl TTL (seconds) for cached responses when caching is enabled for select queries. Must be between 0 and 86400 (24 hours). + * @return [io.appwrite.models.DocumentList] + */ + @JvmOverloads + suspend fun listDocuments( + databaseId: String, + collectionId: String, + queries: List? = null, + transactionId: String? = null, + total: Boolean? = null, + ttl: Long? = null, + nestedType: Class, + ): io.appwrite.models.DocumentList { + val apiPath = ("/documentsdb/{databaseId}/collections/{collectionId}/documents" + .replace("{databaseId}", databaseId) + .replace("{collectionId}", collectionId) + ) + val apiParams = mutableMapOf( + "queries" to queries, + "transactionId" to transactionId, + "total" to total, + "ttl" to ttl, + ) + val apiHeaders = mutableMapOf( + "X-Appwrite-Project" to client.config["project"].orEmpty(), + "accept" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.DocumentList = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.DocumentList.from(map = it as Map, nestedType) + } + return client.call( + "GET", + apiPath, + apiHeaders, + apiParams, + responseType = classOf(), + converter, + ) + } + + /** + * Get a list of all the user's documents in a given collection. You can use the query params to filter your results. + * + * @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). + * @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. + * @param transactionId Transaction ID to read uncommitted changes within the transaction. + * @param total When set to false, the total count returned will be 0 and will not be calculated. + * @param ttl TTL (seconds) for cached responses when caching is enabled for select queries. Must be between 0 and 86400 (24 hours). + * @return [io.appwrite.models.DocumentList] + */ + @JvmOverloads + @Throws(AppwriteException::class) + suspend fun listDocuments( + databaseId: String, + collectionId: String, + queries: List? = null, + transactionId: String? = null, + total: Boolean? = null, + ttl: Long? = null, + ): io.appwrite.models.DocumentList> = listDocuments( + databaseId, + collectionId, + queries, + transactionId, + total, + ttl, + nestedType = classOf(), + ) + + /** + * Create a new Document. Before using this route, you should create a new collection resource using either a [server integration](https://appwrite.io/docs/server/databases#documentsDBCreateCollection) 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. + * @param documentId Document ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. + * @param data Document data as JSON object. + * @param permissions An array of permissions strings. By default, only the current user is granted all permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). + * @param transactionId Transaction ID for staging the operation. + * @return [io.appwrite.models.Document] + */ + @JvmOverloads + suspend fun createDocument( + databaseId: String, + collectionId: String, + documentId: String, + data: Map, + permissions: List? = null, + transactionId: String? = null, + nestedType: Class, + ): io.appwrite.models.Document { + val apiPath = ("/documentsdb/{databaseId}/collections/{collectionId}/documents" + .replace("{databaseId}", databaseId) + .replace("{collectionId}", collectionId) + ) + val apiParams = mutableMapOf( + "documentId" to documentId, + "data" to data, + "permissions" to permissions, + "transactionId" to transactionId, + ) + val apiHeaders = mutableMapOf( + "X-Appwrite-Project" to client.config["project"].orEmpty(), + "content-type" to "application/json", + "accept" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.Document = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.Document.from(map = it as Map, nestedType) + } + return client.call( + "POST", + apiPath, + apiHeaders, + apiParams, + responseType = classOf(), + converter, + ) + } + + /** + * Create a new Document. Before using this route, you should create a new collection resource using either a [server integration](https://appwrite.io/docs/server/databases#documentsDBCreateCollection) 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. + * @param documentId Document ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. + * @param data Document data as JSON object. + * @param permissions An array of permissions strings. By default, only the current user is granted all permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). + * @param transactionId Transaction ID for staging the operation. + * @return [io.appwrite.models.Document] + */ + @JvmOverloads + @Throws(AppwriteException::class) + suspend fun createDocument( + databaseId: String, + collectionId: String, + documentId: String, + data: Map, + permissions: List? = null, + transactionId: String? = null, + ): io.appwrite.models.Document> = createDocument( + databaseId, + collectionId, + documentId, + data, + permissions, + transactionId, + nestedType = classOf(), + ) + + /** + * 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#documentsDBCreateCollection) 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. + * @param documents Array of documents data as JSON objects. + * @param transactionId Transaction ID for staging the operation. + * @return [io.appwrite.models.DocumentList] + */ + @JvmOverloads + suspend fun createDocuments( + databaseId: String, + collectionId: String, + documents: List>, + transactionId: String? = null, + nestedType: Class, + ): io.appwrite.models.DocumentList { + val apiPath = ("/documentsdb/{databaseId}/collections/{collectionId}/documents" + .replace("{databaseId}", databaseId) + .replace("{collectionId}", collectionId) + ) + val apiParams = mutableMapOf( + "documents" to documents, + "transactionId" to transactionId, + ) + val apiHeaders = mutableMapOf( + "X-Appwrite-Project" to client.config["project"].orEmpty(), + "content-type" to "application/json", + "accept" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.DocumentList = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.DocumentList.from(map = it as Map, nestedType) + } + return client.call( + "POST", + apiPath, + apiHeaders, + apiParams, + responseType = classOf(), + converter, + ) + } + + /** + * 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#documentsDBCreateCollection) 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. + * @param documents Array of documents data as JSON objects. + * @param transactionId Transaction ID for staging the operation. + * @return [io.appwrite.models.DocumentList] + */ + @JvmOverloads + @Throws(AppwriteException::class) + suspend fun createDocuments( + databaseId: String, + collectionId: String, + documents: List>, + transactionId: String? = null, + ): io.appwrite.models.DocumentList> = createDocuments( + databaseId, + collectionId, + documents, + transactionId, + nestedType = classOf(), + ) + + /** + * Get a document by its unique ID. This endpoint response returns a JSON object with the document data. + * + * @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). + * @param documentId Document 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. + * @param transactionId Transaction ID to read uncommitted changes within the transaction. + * @return [io.appwrite.models.Document] + */ + @JvmOverloads + suspend fun getDocument( + databaseId: String, + collectionId: String, + documentId: String, + queries: List? = null, + transactionId: String? = null, + nestedType: Class, + ): io.appwrite.models.Document { + val apiPath = ("/documentsdb/{databaseId}/collections/{collectionId}/documents/{documentId}" + .replace("{databaseId}", databaseId) + .replace("{collectionId}", collectionId) + .replace("{documentId}", documentId) + ) + val apiParams = mutableMapOf( + "queries" to queries, + "transactionId" to transactionId, + ) + val apiHeaders = mutableMapOf( + "X-Appwrite-Project" to client.config["project"].orEmpty(), + "accept" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.Document = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.Document.from(map = it as Map, nestedType) + } + return client.call( + "GET", + apiPath, + apiHeaders, + apiParams, + responseType = classOf(), + converter, + ) + } + + /** + * Get a document by its unique ID. This endpoint response returns a JSON object with the document data. + * + * @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). + * @param documentId Document 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. + * @param transactionId Transaction ID to read uncommitted changes within the transaction. + * @return [io.appwrite.models.Document] + */ + @JvmOverloads + @Throws(AppwriteException::class) + suspend fun getDocument( + databaseId: String, + collectionId: String, + documentId: String, + queries: List? = null, + transactionId: String? = null, + ): io.appwrite.models.Document> = getDocument( + databaseId, + collectionId, + documentId, + queries, + transactionId, + nestedType = classOf(), + ) + + /** + * 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#documentsDBCreateCollection) 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 fields 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). + * @param transactionId Transaction ID for staging the operation. + * @return [io.appwrite.models.Document] + */ + @JvmOverloads + suspend fun upsertDocument( + databaseId: String, + collectionId: String, + documentId: String, + data: Map? = null, + permissions: List? = null, + transactionId: String? = null, + nestedType: Class, + ): io.appwrite.models.Document { + val apiPath = ("/documentsdb/{databaseId}/collections/{collectionId}/documents/{documentId}" + .replace("{databaseId}", databaseId) + .replace("{collectionId}", collectionId) + .replace("{documentId}", documentId) + ) + val apiParams = mutableMapOf( + "data" to data, + "permissions" to permissions, + "transactionId" to transactionId, + ) + val apiHeaders = mutableMapOf( + "X-Appwrite-Project" to client.config["project"].orEmpty(), + "content-type" to "application/json", + "accept" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.Document = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.Document.from(map = it as Map, nestedType) + } + return client.call( + "PUT", + apiPath, + apiHeaders, + apiParams, + responseType = classOf(), + converter, + ) + } + + /** + * 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#documentsDBCreateCollection) 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 fields 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). + * @param transactionId Transaction ID for staging the operation. + * @return [io.appwrite.models.Document] + */ + @JvmOverloads + @Throws(AppwriteException::class) + suspend fun upsertDocument( + databaseId: String, + collectionId: String, + documentId: String, + data: Map? = null, + permissions: List? = null, + transactionId: String? = null, + ): io.appwrite.models.Document> = upsertDocument( + databaseId, + collectionId, + documentId, + data, + permissions, + transactionId, + nestedType = classOf(), + ) + + /** + * Update a document by its unique ID. Using the patch method you can pass only specific fields that will get updated. + * + * @param databaseId Database ID. + * @param collectionId Collection ID. + * @param documentId Document ID. + * @param data Document data as JSON object. Include only fields and value pairs to be updated. + * @param permissions An array of permissions strings. By default, the current permissions are inherited. [Learn more about permissions](https://appwrite.io/docs/permissions). + * @param transactionId Transaction ID for staging the operation. + * @return [io.appwrite.models.Document] + */ + @JvmOverloads + suspend fun updateDocument( + databaseId: String, + collectionId: String, + documentId: String, + data: Map? = null, + permissions: List? = null, + transactionId: String? = null, + nestedType: Class, + ): io.appwrite.models.Document { + val apiPath = ("/documentsdb/{databaseId}/collections/{collectionId}/documents/{documentId}" + .replace("{databaseId}", databaseId) + .replace("{collectionId}", collectionId) + .replace("{documentId}", documentId) + ) + val apiParams = mutableMapOf( + "data" to data, + "permissions" to permissions, + "transactionId" to transactionId, + ) + val apiHeaders = mutableMapOf( + "X-Appwrite-Project" to client.config["project"].orEmpty(), + "content-type" to "application/json", + "accept" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.Document = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.Document.from(map = it as Map, nestedType) + } + return client.call( + "PATCH", + apiPath, + apiHeaders, + apiParams, + responseType = classOf(), + converter, + ) + } + + /** + * Update a document by its unique ID. Using the patch method you can pass only specific fields that will get updated. + * + * @param databaseId Database ID. + * @param collectionId Collection ID. + * @param documentId Document ID. + * @param data Document data as JSON object. Include only fields and value pairs to be updated. + * @param permissions An array of permissions strings. By default, the current permissions are inherited. [Learn more about permissions](https://appwrite.io/docs/permissions). + * @param transactionId Transaction ID for staging the operation. + * @return [io.appwrite.models.Document] + */ + @JvmOverloads + @Throws(AppwriteException::class) + suspend fun updateDocument( + databaseId: String, + collectionId: String, + documentId: String, + data: Map? = null, + permissions: List? = null, + transactionId: String? = null, + ): io.appwrite.models.Document> = updateDocument( + databaseId, + collectionId, + documentId, + data, + permissions, + transactionId, + nestedType = classOf(), + ) + + /** + * Delete a document by its unique ID. + * + * @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). + * @param documentId Document ID. + * @param transactionId Transaction ID for staging the operation. + * @return [Any] + */ + @JvmOverloads + suspend fun deleteDocument( + databaseId: String, + collectionId: String, + documentId: String, + transactionId: String? = null, + ): Any { + val apiPath = ("/documentsdb/{databaseId}/collections/{collectionId}/documents/{documentId}" + .replace("{databaseId}", databaseId) + .replace("{collectionId}", collectionId) + .replace("{documentId}", documentId) + ) + val apiParams = mutableMapOf( + "transactionId" to transactionId, + ) + val apiHeaders = mutableMapOf( + "X-Appwrite-Project" to client.config["project"].orEmpty(), + "content-type" to "application/json", + ) + return client.call( + "DELETE", + apiPath, + apiHeaders, + apiParams, + responseType = Any::class.java, + ) + } + + /** + * Decrement a specific column of a row 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. + * @param transactionId Transaction ID for staging the operation. + * @return [io.appwrite.models.Document] + */ + @JvmOverloads + suspend fun decrementDocumentAttribute( + databaseId: String, + collectionId: String, + documentId: String, + attribute: String, + value: Double? = null, + min: Double? = null, + transactionId: String? = null, + nestedType: Class, + ): io.appwrite.models.Document { + val apiPath = ("/documentsdb/{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, + "transactionId" to transactionId, + ) + val apiHeaders = mutableMapOf( + "X-Appwrite-Project" to client.config["project"].orEmpty(), + "content-type" to "application/json", + "accept" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.Document = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.Document.from(map = it as Map, nestedType) + } + return client.call( + "PATCH", + apiPath, + apiHeaders, + apiParams, + responseType = classOf(), + converter, + ) + } + + /** + * Decrement a specific column of a row 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. + * @param transactionId Transaction ID for staging the operation. + * @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, + transactionId: String? = null, + ): io.appwrite.models.Document> = decrementDocumentAttribute( + databaseId, + collectionId, + documentId, + attribute, + value, + min, + transactionId, + nestedType = classOf(), + ) + + /** + * Increment a specific column of a row 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. + * @param transactionId Transaction ID for staging the operation. + * @return [io.appwrite.models.Document] + */ + @JvmOverloads + suspend fun incrementDocumentAttribute( + databaseId: String, + collectionId: String, + documentId: String, + attribute: String, + value: Double? = null, + max: Double? = null, + transactionId: String? = null, + nestedType: Class, + ): io.appwrite.models.Document { + val apiPath = ("/documentsdb/{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, + "transactionId" to transactionId, + ) + val apiHeaders = mutableMapOf( + "X-Appwrite-Project" to client.config["project"].orEmpty(), + "content-type" to "application/json", + "accept" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.Document = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.Document.from(map = it as Map, nestedType) + } + return client.call( + "PATCH", + apiPath, + apiHeaders, + apiParams, + responseType = classOf(), + converter, + ) + } + + /** + * Increment a specific column of a row 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. + * @param transactionId Transaction ID for staging the operation. + * @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, + transactionId: String? = null, + ): io.appwrite.models.Document> = incrementDocumentAttribute( + databaseId, + collectionId, + documentId, + attribute, + value, + max, + transactionId, + nestedType = classOf(), + ) +} diff --git a/library/src/main/java/io/appwrite/services/Storage.kt b/library/src/main/java/io/appwrite/services/Storage.kt index 1cf0810c..7c38e0fa 100644 --- a/library/src/main/java/io/appwrite/services/Storage.kt +++ b/library/src/main/java/io/appwrite/services/Storage.kt @@ -261,7 +261,7 @@ class Storage(client: Client) : Service(client) { * @param fileId File ID * @param width Resize preview image width, Pass an integer between 0 to 4000. * @param height Resize preview image height, Pass an integer between 0 to 4000. - * @param gravity Image crop gravity. Can be one of center,top-left,top,top-right,left,right,bottom-left,bottom,bottom-right + * @param gravity Image crop gravity. Can be one of auto,center,top-left,top,top-right,left,right,bottom-left,bottom,bottom-right * @param quality Preview image quality. Pass an integer between 0 to 100. Defaults to keep existing image quality. * @param borderWidth Preview image border in pixels. Pass an integer between 0 to 100. Defaults to 0. * @param borderColor Preview image border color. Use a valid HEX color, no # is needed for prefix. diff --git a/library/src/main/java/io/appwrite/services/VectorsDB.kt b/library/src/main/java/io/appwrite/services/VectorsDB.kt new file mode 100644 index 00000000..47c4d435 --- /dev/null +++ b/library/src/main/java/io/appwrite/services/VectorsDB.kt @@ -0,0 +1,724 @@ +package io.appwrite.services + +import android.net.Uri +import io.appwrite.Client +import io.appwrite.Service +import io.appwrite.exceptions.AppwriteException +import io.appwrite.extensions.classOf +import io.appwrite.models.* +import okhttp3.Cookie +import java.io.File + +/** + * */ +class VectorsDB(client: Client) : Service(client) { + /** + * List transactions across all databases. + * + * @param queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). + * @return [io.appwrite.models.TransactionList] + */ + @JvmOverloads + suspend fun listTransactions( + queries: List? = null, + ): io.appwrite.models.TransactionList { + val apiPath = "/vectorsdb/transactions" + val apiParams = mutableMapOf( + "queries" to queries, + ) + val apiHeaders = mutableMapOf( + "X-Appwrite-Project" to client.config["project"].orEmpty(), + "accept" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.TransactionList = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.TransactionList.from(map = it as Map) + } + return client.call( + "GET", + apiPath, + apiHeaders, + apiParams, + responseType = io.appwrite.models.TransactionList::class.java, + converter, + ) + } + + /** + * Create a new transaction. + * + * @param ttl Seconds before the transaction expires. + * @return [io.appwrite.models.Transaction] + */ + @JvmOverloads + suspend fun createTransaction( + ttl: Long? = null, + ): io.appwrite.models.Transaction { + val apiPath = "/vectorsdb/transactions" + val apiParams = mutableMapOf( + "ttl" to ttl, + ) + val apiHeaders = mutableMapOf( + "X-Appwrite-Project" to client.config["project"].orEmpty(), + "content-type" to "application/json", + "accept" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.Transaction = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.Transaction.from(map = it as Map) + } + return client.call( + "POST", + apiPath, + apiHeaders, + apiParams, + responseType = io.appwrite.models.Transaction::class.java, + converter, + ) + } + + /** + * Get a transaction by its unique ID. + * + * @param transactionId Transaction ID. + * @return [io.appwrite.models.Transaction] + */ + suspend fun getTransaction( + transactionId: String, + ): io.appwrite.models.Transaction { + val apiPath = ("/vectorsdb/transactions/{transactionId}" + .replace("{transactionId}", transactionId) + ) + val apiParams = mutableMapOf() + val apiHeaders = mutableMapOf( + "X-Appwrite-Project" to client.config["project"].orEmpty(), + "accept" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.Transaction = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.Transaction.from(map = it as Map) + } + return client.call( + "GET", + apiPath, + apiHeaders, + apiParams, + responseType = io.appwrite.models.Transaction::class.java, + converter, + ) + } + + /** + * Update a transaction, to either commit or roll back its operations. + * + * @param transactionId Transaction ID. + * @param commit Commit transaction? + * @param rollback Rollback transaction? + * @return [io.appwrite.models.Transaction] + */ + @JvmOverloads + suspend fun updateTransaction( + transactionId: String, + commit: Boolean? = null, + rollback: Boolean? = null, + ): io.appwrite.models.Transaction { + val apiPath = ("/vectorsdb/transactions/{transactionId}" + .replace("{transactionId}", transactionId) + ) + val apiParams = mutableMapOf( + "commit" to commit, + "rollback" to rollback, + ) + val apiHeaders = mutableMapOf( + "X-Appwrite-Project" to client.config["project"].orEmpty(), + "content-type" to "application/json", + "accept" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.Transaction = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.Transaction.from(map = it as Map) + } + return client.call( + "PATCH", + apiPath, + apiHeaders, + apiParams, + responseType = io.appwrite.models.Transaction::class.java, + converter, + ) + } + + /** + * Delete a transaction by its unique ID. + * + * @param transactionId Transaction ID. + * @return [Any] + */ + suspend fun deleteTransaction( + transactionId: String, + ): Any { + val apiPath = ("/vectorsdb/transactions/{transactionId}" + .replace("{transactionId}", transactionId) + ) + val apiParams = mutableMapOf() + val apiHeaders = mutableMapOf( + "X-Appwrite-Project" to client.config["project"].orEmpty(), + "content-type" to "application/json", + ) + return client.call( + "DELETE", + apiPath, + apiHeaders, + apiParams, + responseType = Any::class.java, + ) + } + + /** + * Create multiple operations in a single transaction. + * + * @param transactionId Transaction ID. + * @param operations Array of staged operations. + * @return [io.appwrite.models.Transaction] + */ + @JvmOverloads + suspend fun createOperations( + transactionId: String, + operations: List>? = null, + ): io.appwrite.models.Transaction { + val apiPath = ("/vectorsdb/transactions/{transactionId}/operations" + .replace("{transactionId}", transactionId) + ) + val apiParams = mutableMapOf( + "operations" to operations, + ) + val apiHeaders = mutableMapOf( + "X-Appwrite-Project" to client.config["project"].orEmpty(), + "content-type" to "application/json", + "accept" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.Transaction = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.Transaction.from(map = it as Map) + } + return client.call( + "POST", + apiPath, + apiHeaders, + apiParams, + responseType = io.appwrite.models.Transaction::class.java, + converter, + ) + } + + /** + * Get a list of all the user's documents in a given collection. You can use the query params to filter your results. + * + * @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). + * @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 524288 characters long. + * @param transactionId Transaction ID to read uncommitted changes within the transaction. + * @param total When set to false, the total count returned will be 0 and will not be calculated. + * @param ttl TTL (seconds) for cached responses when caching is enabled for select queries. Must be between 0 and 86400 (24 hours). + * @return [io.appwrite.models.DocumentList] + */ + @JvmOverloads + suspend fun listDocuments( + databaseId: String, + collectionId: String, + queries: List? = null, + transactionId: String? = null, + total: Boolean? = null, + ttl: Long? = null, + nestedType: Class, + ): io.appwrite.models.DocumentList { + val apiPath = ("/vectorsdb/{databaseId}/collections/{collectionId}/documents" + .replace("{databaseId}", databaseId) + .replace("{collectionId}", collectionId) + ) + val apiParams = mutableMapOf( + "queries" to queries, + "transactionId" to transactionId, + "total" to total, + "ttl" to ttl, + ) + val apiHeaders = mutableMapOf( + "X-Appwrite-Project" to client.config["project"].orEmpty(), + "accept" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.DocumentList = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.DocumentList.from(map = it as Map, nestedType) + } + return client.call( + "GET", + apiPath, + apiHeaders, + apiParams, + responseType = classOf(), + converter, + ) + } + + /** + * Get a list of all the user's documents in a given collection. You can use the query params to filter your results. + * + * @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). + * @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 524288 characters long. + * @param transactionId Transaction ID to read uncommitted changes within the transaction. + * @param total When set to false, the total count returned will be 0 and will not be calculated. + * @param ttl TTL (seconds) for cached responses when caching is enabled for select queries. Must be between 0 and 86400 (24 hours). + * @return [io.appwrite.models.DocumentList] + */ + @JvmOverloads + @Throws(AppwriteException::class) + suspend fun listDocuments( + databaseId: String, + collectionId: String, + queries: List? = null, + transactionId: String? = null, + total: Boolean? = null, + ttl: Long? = null, + ): io.appwrite.models.DocumentList> = listDocuments( + databaseId, + collectionId, + queries, + transactionId, + total, + ttl, + nestedType = classOf(), + ) + + /** + * Create a new Document. Before using this route, you should create a new collection resource using either a [server integration](https://appwrite.io/docs/server/databases#documentsDBCreateCollection) 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. + * @param documentId Document ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. + * @param data Document data as JSON object. + * @param permissions An array of permissions strings. By default, only the current user is granted all permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). + * @param transactionId Transaction ID for staging the operation. + * @return [io.appwrite.models.Document] + */ + @JvmOverloads + suspend fun createDocument( + databaseId: String, + collectionId: String, + documentId: String, + data: Map, + permissions: List? = null, + transactionId: String? = null, + nestedType: Class, + ): io.appwrite.models.Document { + val apiPath = ("/vectorsdb/{databaseId}/collections/{collectionId}/documents" + .replace("{databaseId}", databaseId) + .replace("{collectionId}", collectionId) + ) + val apiParams = mutableMapOf( + "documentId" to documentId, + "data" to data, + "permissions" to permissions, + "transactionId" to transactionId, + ) + val apiHeaders = mutableMapOf( + "X-Appwrite-Project" to client.config["project"].orEmpty(), + "content-type" to "application/json", + "accept" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.Document = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.Document.from(map = it as Map, nestedType) + } + return client.call( + "POST", + apiPath, + apiHeaders, + apiParams, + responseType = classOf(), + converter, + ) + } + + /** + * Create a new Document. Before using this route, you should create a new collection resource using either a [server integration](https://appwrite.io/docs/server/databases#documentsDBCreateCollection) 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. + * @param documentId Document ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. + * @param data Document data as JSON object. + * @param permissions An array of permissions strings. By default, only the current user is granted all permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). + * @param transactionId Transaction ID for staging the operation. + * @return [io.appwrite.models.Document] + */ + @JvmOverloads + @Throws(AppwriteException::class) + suspend fun createDocument( + databaseId: String, + collectionId: String, + documentId: String, + data: Map, + permissions: List? = null, + transactionId: String? = null, + ): io.appwrite.models.Document> = createDocument( + databaseId, + collectionId, + documentId, + data, + permissions, + transactionId, + nestedType = classOf(), + ) + + /** + * Get a list of all the user's documents in a given collection using a POST request. This behaves identically to the list documents endpoint but accepts the queries in the request body, allowing much larger `queries` arrays than can fit in a URL query string. + * + * + * @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). + * @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 524288 characters long. + * @param transactionId Transaction ID to read uncommitted changes within the transaction. + * @param total When set to false, the total count returned will be 0 and will not be calculated. + * @param ttl TTL (seconds) for cached responses when caching is enabled for select queries. Must be between 0 and 86400 (24 hours). + * @return [io.appwrite.models.DocumentList] + */ + @JvmOverloads + suspend fun createQuery( + databaseId: String, + collectionId: String, + queries: List? = null, + transactionId: String? = null, + total: Boolean? = null, + ttl: Long? = null, + nestedType: Class, + ): io.appwrite.models.DocumentList { + val apiPath = ("/vectorsdb/{databaseId}/collections/{collectionId}/documents/query" + .replace("{databaseId}", databaseId) + .replace("{collectionId}", collectionId) + ) + val apiParams = mutableMapOf( + "queries" to queries, + "transactionId" to transactionId, + "total" to total, + "ttl" to ttl, + ) + val apiHeaders = mutableMapOf( + "X-Appwrite-Project" to client.config["project"].orEmpty(), + "content-type" to "application/json", + "accept" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.DocumentList = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.DocumentList.from(map = it as Map, nestedType) + } + return client.call( + "POST", + apiPath, + apiHeaders, + apiParams, + responseType = classOf(), + converter, + ) + } + + /** + * Get a list of all the user's documents in a given collection using a POST request. This behaves identically to the list documents endpoint but accepts the queries in the request body, allowing much larger `queries` arrays than can fit in a URL query string. + * + * + * @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). + * @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 524288 characters long. + * @param transactionId Transaction ID to read uncommitted changes within the transaction. + * @param total When set to false, the total count returned will be 0 and will not be calculated. + * @param ttl TTL (seconds) for cached responses when caching is enabled for select queries. Must be between 0 and 86400 (24 hours). + * @return [io.appwrite.models.DocumentList] + */ + @JvmOverloads + @Throws(AppwriteException::class) + suspend fun createQuery( + databaseId: String, + collectionId: String, + queries: List? = null, + transactionId: String? = null, + total: Boolean? = null, + ttl: Long? = null, + ): io.appwrite.models.DocumentList> = createQuery( + databaseId, + collectionId, + queries, + transactionId, + total, + ttl, + nestedType = classOf(), + ) + + /** + * Get a document by its unique ID. This endpoint response returns a JSON object with the document data. + * + * @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). + * @param documentId Document 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. + * @param transactionId Transaction ID to read uncommitted changes within the transaction. + * @return [io.appwrite.models.Document] + */ + @JvmOverloads + suspend fun getDocument( + databaseId: String, + collectionId: String, + documentId: String, + queries: List? = null, + transactionId: String? = null, + nestedType: Class, + ): io.appwrite.models.Document { + val apiPath = ("/vectorsdb/{databaseId}/collections/{collectionId}/documents/{documentId}" + .replace("{databaseId}", databaseId) + .replace("{collectionId}", collectionId) + .replace("{documentId}", documentId) + ) + val apiParams = mutableMapOf( + "queries" to queries, + "transactionId" to transactionId, + ) + val apiHeaders = mutableMapOf( + "X-Appwrite-Project" to client.config["project"].orEmpty(), + "accept" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.Document = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.Document.from(map = it as Map, nestedType) + } + return client.call( + "GET", + apiPath, + apiHeaders, + apiParams, + responseType = classOf(), + converter, + ) + } + + /** + * Get a document by its unique ID. This endpoint response returns a JSON object with the document data. + * + * @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). + * @param documentId Document 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. + * @param transactionId Transaction ID to read uncommitted changes within the transaction. + * @return [io.appwrite.models.Document] + */ + @JvmOverloads + @Throws(AppwriteException::class) + suspend fun getDocument( + databaseId: String, + collectionId: String, + documentId: String, + queries: List? = null, + transactionId: String? = null, + ): io.appwrite.models.Document> = getDocument( + databaseId, + collectionId, + documentId, + queries, + transactionId, + nestedType = classOf(), + ) + + /** + * 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#documentsDBCreateCollection) 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 fields 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). + * @param transactionId Transaction ID for staging the operation. + * @return [io.appwrite.models.Document] + */ + @JvmOverloads + suspend fun upsertDocument( + databaseId: String, + collectionId: String, + documentId: String, + data: Map? = null, + permissions: List? = null, + transactionId: String? = null, + nestedType: Class, + ): io.appwrite.models.Document { + val apiPath = ("/vectorsdb/{databaseId}/collections/{collectionId}/documents/{documentId}" + .replace("{databaseId}", databaseId) + .replace("{collectionId}", collectionId) + .replace("{documentId}", documentId) + ) + val apiParams = mutableMapOf( + "data" to data, + "permissions" to permissions, + "transactionId" to transactionId, + ) + val apiHeaders = mutableMapOf( + "X-Appwrite-Project" to client.config["project"].orEmpty(), + "content-type" to "application/json", + "accept" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.Document = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.Document.from(map = it as Map, nestedType) + } + return client.call( + "PUT", + apiPath, + apiHeaders, + apiParams, + responseType = classOf(), + converter, + ) + } + + /** + * 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#documentsDBCreateCollection) 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 fields 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). + * @param transactionId Transaction ID for staging the operation. + * @return [io.appwrite.models.Document] + */ + @JvmOverloads + @Throws(AppwriteException::class) + suspend fun upsertDocument( + databaseId: String, + collectionId: String, + documentId: String, + data: Map? = null, + permissions: List? = null, + transactionId: String? = null, + ): io.appwrite.models.Document> = upsertDocument( + databaseId, + collectionId, + documentId, + data, + permissions, + transactionId, + nestedType = classOf(), + ) + + /** + * Update a document by its unique ID. Using the patch method you can pass only specific fields that will get updated. + * + * @param databaseId Database ID. + * @param collectionId Collection ID. + * @param documentId Document ID. + * @param data Document data as JSON object. Include only fields and value pairs to be updated. + * @param permissions An array of permissions strings. By default, the current permissions are inherited. [Learn more about permissions](https://appwrite.io/docs/permissions). + * @param transactionId Transaction ID for staging the operation. + * @return [io.appwrite.models.Document] + */ + @JvmOverloads + suspend fun updateDocument( + databaseId: String, + collectionId: String, + documentId: String, + data: Map? = null, + permissions: List? = null, + transactionId: String? = null, + nestedType: Class, + ): io.appwrite.models.Document { + val apiPath = ("/vectorsdb/{databaseId}/collections/{collectionId}/documents/{documentId}" + .replace("{databaseId}", databaseId) + .replace("{collectionId}", collectionId) + .replace("{documentId}", documentId) + ) + val apiParams = mutableMapOf( + "data" to data, + "permissions" to permissions, + "transactionId" to transactionId, + ) + val apiHeaders = mutableMapOf( + "X-Appwrite-Project" to client.config["project"].orEmpty(), + "content-type" to "application/json", + "accept" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.Document = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.Document.from(map = it as Map, nestedType) + } + return client.call( + "PATCH", + apiPath, + apiHeaders, + apiParams, + responseType = classOf(), + converter, + ) + } + + /** + * Update a document by its unique ID. Using the patch method you can pass only specific fields that will get updated. + * + * @param databaseId Database ID. + * @param collectionId Collection ID. + * @param documentId Document ID. + * @param data Document data as JSON object. Include only fields and value pairs to be updated. + * @param permissions An array of permissions strings. By default, the current permissions are inherited. [Learn more about permissions](https://appwrite.io/docs/permissions). + * @param transactionId Transaction ID for staging the operation. + * @return [io.appwrite.models.Document] + */ + @JvmOverloads + @Throws(AppwriteException::class) + suspend fun updateDocument( + databaseId: String, + collectionId: String, + documentId: String, + data: Map? = null, + permissions: List? = null, + transactionId: String? = null, + ): io.appwrite.models.Document> = updateDocument( + databaseId, + collectionId, + documentId, + data, + permissions, + transactionId, + nestedType = classOf(), + ) + + /** + * Delete a document by its unique ID. + * + * @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). + * @param documentId Document ID. + * @param transactionId Transaction ID for staging the operation. + * @return [Any] + */ + @JvmOverloads + suspend fun deleteDocument( + databaseId: String, + collectionId: String, + documentId: String, + transactionId: String? = null, + ): Any { + val apiPath = ("/vectorsdb/{databaseId}/collections/{collectionId}/documents/{documentId}" + .replace("{databaseId}", databaseId) + .replace("{collectionId}", collectionId) + .replace("{documentId}", documentId) + ) + val apiParams = mutableMapOf( + "transactionId" to transactionId, + ) + val apiHeaders = mutableMapOf( + "X-Appwrite-Project" to client.config["project"].orEmpty(), + "content-type" to "application/json", + ) + return client.call( + "DELETE", + apiPath, + apiHeaders, + apiParams, + responseType = Any::class.java, + ) + } +} diff --git a/library/src/test/java/io/appwrite/ClientJavaInteropTest.java b/library/src/test/java/io/appwrite/ClientJavaInteropTest.java new file mode 100644 index 00000000..3019bb94 --- /dev/null +++ b/library/src/test/java/io/appwrite/ClientJavaInteropTest.java @@ -0,0 +1,25 @@ +package io.appwrite; + +import static org.junit.Assert.assertEquals; + +import android.content.Context; +import androidx.test.core.app.ApplicationProvider; +import androidx.test.ext.junit.runners.AndroidJUnit4; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.annotation.Config; + +@Config(manifest = Config.NONE) +@RunWith(AndroidJUnit4.class) +public final class ClientJavaInteropTest { + @Test + public void endpointSettersAreFluentFromJava() { + Context context = ApplicationProvider.getApplicationContext(); + Client client = new Client(context) + .setEndpoint("https://cloud.appwrite.io/v1") + .setEndpointRealtime("wss://cloud.appwrite.io/v1"); + + assertEquals("https://cloud.appwrite.io/v1", client.getEndpoint()); + assertEquals("wss://cloud.appwrite.io/v1", client.getEndpointRealtime()); + } +}