Skip to content

Add inc/dec #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## 16.0.0

* Add `<REGION>` to doc examples due to the new multi region endpoints
* Add `<REGION>` to doc examples due to the new multi region endpoints
* Add doc examples and methods for bulk api transactions: `createDocuments`, `deleteDocuments` etc.
* Add doc examples, class and methods for new `Sites` service
* Add doc examples, class and methods for new `Tokens` service
Expand All @@ -15,13 +15,13 @@
## 14.0.0

* Breaking changes:
* Changed the typing of `AppwriteException`&#039;s response parameter from a `dynamic` object to an optional string (`?String`).
* Changed the typing of `AppwriteException`'s response parameter from a `dynamic` object to an optional string (`?String`).

## 13.0.0

* Fixed realtime pong response.
* Fixed issues with `chunkedUpload` method.
* Fixed type mismatch bug where `List&lt;dynamic&gt;` was incorrectly causing runtime type errors.
* Fixed type mismatch bug where `List<dynamic>` was incorrectly causing runtime type errors.
* Updated return type of `updateMfaChallenge()` from raw data to properly typed `models.Session` object.

## 12.0.0
Expand Down Expand Up @@ -151,7 +151,7 @@ You can find the new syntax for breaking changes in the [Appwrite API references
* The `number` argument in phone endpoints have been renamed to `phone`
* List endpoints no longer support `limit`, `offset`, `cursor`, `cursorDirection`, `orderAttributes`, `orderTypes` as they have been moved to the `queries` array
* `read` and `write` permission have been deprecated and they are now included in the `permissions` array
* Parameter `permission` for collections and buckets are now renamed to `documentSecurity` &amp; `fileSecurity` respectively
* Parameter `permission` for collections and buckets are now renamed to `documentSecurity` & `fileSecurity` respectively
* Renamed methods of the Query helper
1. `lesser` renamed to `lessThan`
2. `lesserEqual` renamed to `lessThanEqual`
Expand All @@ -167,8 +167,8 @@ You can find the new syntax for breaking changes in the [Appwrite API references

## 6.0.0
* Support for Appwrite 0.15
* **BREAKING** `Database` -&gt; `Databases`
* **BREAKING** `account.createSession()` -&gt; `account.createEmailSession()`
* **BREAKING** `Database` -> `Databases`
* **BREAKING** `account.createSession()` -> `account.createEmailSession()`
* **BREAKING** `dateCreated` attribute removed from `Team`, `Execution`, `File` models
* **BREAKING** `dateCreated` and `dateUpdated` attribute removed from `Func`, `Deployment`, `Bucket` models
* **BREAKING** Realtime channels
Expand All @@ -182,7 +182,7 @@ You can find the new syntax for breaking changes in the [Appwrite API references

## 5.0.0
* Support for Appwrite 0.14
* **BREAKING** `account.delete()` -&gt; `account.updateStatus()`
* **BREAKING** `account.delete()` -> `account.updateStatus()`
* **BREAKING** Execution model `stdout` renamed to `response`
* **BREAKING** Membership model `name` renamed to `userName` and `email` renamed to `userEmail`
* Added `teamName` to Membership model
Expand All @@ -200,7 +200,7 @@ You can find the new syntax for breaking changes in the [Appwrite API references
* **BREAKING** **Tags** have been renamed to **Deployments**
* **BREAKING** `createFile` function expects Bucket ID as the first parameter
* **BREAKING** `createDeployment` and `createFile` functions expect an instance **InputFile** rather than the instance of **MultipartFile**
* **BREAKING** `list&lt;Entity&gt;` endpoints now contain a `total` attribute instead of `sum`
* **BREAKING** `list<Entity>` endpoints now contain a `total` attribute instead of `sum`
* `onProgress()` callback function for endpoints supporting file uploads
* Support for synchronous function executions
* Bug fixes and Improvements
Expand Down Expand Up @@ -237,7 +237,7 @@ You can find the new syntax for breaking changes in the [Appwrite API references

## 0.7.0
- Support for Appwrite 0.9
- Breaking - removed order type enum, now you should pass string &#039;ASC&#039; or &#039;DESC&#039;
- Breaking - removed order type enum, now you should pass string 'ASC' or 'DESC'
- Breaking - changed param name from `env` to `runtime` in the **Functions** API
- Image Crop Gravity support in image preview service
- New endpoint in Account getSession to get session by ID
Expand All @@ -258,7 +258,7 @@ You can find the new syntax for breaking changes in the [Appwrite API references
- Upgraded all underlying dependencies to null safe version
- BREAKING Renamed users.deleteUser to users.delete
- BREAKING Renamed parameter inviteId to membershipId on teams.updateMembershipStatus, teams.deleteMembership
- JWT Support client.setJWT(&#039;JWT_GENERATED_IN_CLIENT&#039;)
- JWT Support client.setJWT('JWT_GENERATED_IN_CLIENT')
- [Update membership roles](https://appwrite.io/docs/references/cloud/server-dart/teams?sdk=dart#updateMembershipRoles)
- New awesome image preview features, supports borderRadius, borderColor, borderWidth

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Add this to your package's `pubspec.yaml` file:

```yml
dependencies:
dart_appwrite: ^16.0.0
dart_appwrite: ^16.1.0
```

You can install packages from the command line:
Expand Down
1 change: 1 addition & 0 deletions docs/examples/databases/create-document.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:dart_appwrite/dart_appwrite.dart';

Client client = Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
.setAdmin('') //
.setSession('') // The user session to authenticate with
.setKey('<YOUR_API_KEY>') // Your secret API key
.setJWT('<YOUR_JWT>'); // Your secret JSON Web Token
Expand Down
17 changes: 17 additions & 0 deletions docs/examples/databases/decrement-document-attribute.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:dart_appwrite/dart_appwrite.dart';

Client client = Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
.setProject('<YOUR_PROJECT_ID>') // Your project ID
.setKey('<YOUR_API_KEY>'); // Your secret API key

Databases databases = Databases(client);

Document result = await databases.decrementDocumentAttribute(
databaseId: '<DATABASE_ID>',
collectionId: '<COLLECTION_ID>',
documentId: '<DOCUMENT_ID>',
attribute: '',
value: 0, // (optional)
min: 0, // (optional)
);
17 changes: 17 additions & 0 deletions docs/examples/databases/increment-document-attribute.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:dart_appwrite/dart_appwrite.dart';

Client client = Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
.setProject('<YOUR_PROJECT_ID>') // Your project ID
.setKey('<YOUR_API_KEY>'); // Your secret API key

Databases databases = Databases(client);

Document result = await databases.incrementDocumentAttribute(
databaseId: '<DATABASE_ID>',
collectionId: '<COLLECTION_ID>',
documentId: '<DOCUMENT_ID>',
attribute: '',
value: 0, // (optional)
max: 0, // (optional)
);
16 changes: 16 additions & 0 deletions docs/examples/databases/upsert-document.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:dart_appwrite/dart_appwrite.dart';

Client client = Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
.setProject('<YOUR_PROJECT_ID>') // Your project ID
.setSession(''); // The user session to authenticate with

Databases databases = Databases(client);

Document result = await databases.upsertDocument(
databaseId: '<DATABASE_ID>',
collectionId: '<COLLECTION_ID>',
documentId: '<DOCUMENT_ID>',
data: {},
permissions: ["read("any")"], // (optional)
);
2 changes: 1 addition & 1 deletion docs/examples/databases/upsert-documents.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ Databases databases = Databases(client);
DocumentList result = await databases.upsertDocuments(
databaseId: '<DATABASE_ID>',
collectionId: '<COLLECTION_ID>',
documents: [], // (optional)
documents: [],
);
24 changes: 11 additions & 13 deletions lib/query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,17 @@ class Query {
static String contains(String attribute, dynamic value) =>
Query._('contains', attribute, value).toString();

static String or(List<String> queries) =>
Query._(
'or',
null,
queries.map((query) => jsonDecode(query)).toList(),
).toString();

static String and(List<String> queries) =>
Query._(
'and',
null,
queries.map((query) => jsonDecode(query)).toList(),
).toString();
static String or(List<String> queries) => Query._(
'or',
null,
queries.map((query) => jsonDecode(query)).toList(),
).toString();

static String and(List<String> queries) => Query._(
'and',
null,
queries.map((query) => jsonDecode(query)).toList(),
).toString();

/// Specify which attributes should be returned by the API call.
static String select(List<String> attributes) =>
Expand Down
117 changes: 115 additions & 2 deletions lib/services/databases.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,10 @@ class Databases extends Service {
return models.Document.fromMap(res.data);
}

/// **WARNING: Experimental Feature** - This endpoint is experimental and not
/// yet officially supported. It may be subject to breaking changes or removal
/// in future versions.
///
/// Create new Documents. Before using this route, you should create a new
/// collection resource using either a [server
/// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection)
Expand Down Expand Up @@ -1156,15 +1160,18 @@ class Databases extends Service {
return models.DocumentList.fromMap(res.data);
}

/// **WARNING: Experimental Feature** - This endpoint is experimental and not
/// yet officially supported. It may be subject to breaking changes or removal
/// in future versions.
///
/// Create or update Documents. Before using this route, you should create a
/// new collection resource using either a [server
/// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection)
/// API or directly from your database console.
///
Future<models.DocumentList> upsertDocuments({
required String databaseId,
required String collectionId,
List<Map>? documents,
required List<Map> documents,
}) async {
final String apiPath =
'/databases/{databaseId}/collections/{collectionId}/documents'
Expand All @@ -1185,6 +1192,10 @@ class Databases extends Service {
return models.DocumentList.fromMap(res.data);
}

/// **WARNING: Experimental Feature** - This endpoint is experimental and not
/// yet officially supported. It may be subject to breaking changes or removal
/// in future versions.
///
/// Update all documents that match your queries, if no queries are submitted
/// then all documents are updated. You can pass only specific fields to be
/// updated.
Expand Down Expand Up @@ -1213,6 +1224,10 @@ class Databases extends Service {
return models.DocumentList.fromMap(res.data);
}

/// **WARNING: Experimental Feature** - This endpoint is experimental and not
/// yet officially supported. It may be subject to breaking changes or removal
/// in future versions.
///
/// Bulk delete documents using queries, if no queries are passed then all
/// documents are deleted.
Future<models.DocumentList> deleteDocuments({
Expand Down Expand Up @@ -1267,6 +1282,44 @@ class Databases extends Service {
return models.Document.fromMap(res.data);
}

/// **WARNING: Experimental Feature** - This endpoint is experimental and not
/// yet officially supported. It may be subject to breaking changes or removal
/// in future versions.
///
/// Create or update a Document. Before using this route, you should create a
/// new collection resource using either a [server
/// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection)
/// API or directly from your database console.
Future<models.Document> upsertDocument({
required String databaseId,
required String collectionId,
required String documentId,
required Map data,
List<String>? permissions,
}) async {
final String apiPath =
'/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'
.replaceAll('{databaseId}', databaseId)
.replaceAll('{collectionId}', collectionId)
.replaceAll('{documentId}', documentId);

final Map<String, dynamic> apiParams = {
'data': data,
'permissions': permissions,
};

final Map<String, String> apiHeaders = {'content-type': 'application/json'};

final res = await client.call(
HttpMethod.put,
path: apiPath,
params: apiParams,
headers: apiHeaders,
);

return models.Document.fromMap(res.data);
}

/// Update a document by its unique ID. Using the patch method you can pass
/// only specific fields that will get updated.
Future<models.Document> updateDocument({
Expand Down Expand Up @@ -1325,6 +1378,66 @@ class Databases extends Service {
return res.data;
}

/// Decrement a specific attribute of a document by a given value.
Future<models.Document> decrementDocumentAttribute({
required String databaseId,
required String collectionId,
required String documentId,
required String attribute,
double? value,
double? min,
}) async {
final String apiPath =
'/databases/{databaseId}/collections/{collectionId}/documents/{documentId}/{attribute}/decrement'
.replaceAll('{databaseId}', databaseId)
.replaceAll('{collectionId}', collectionId)
.replaceAll('{documentId}', documentId)
.replaceAll('{attribute}', attribute);

final Map<String, dynamic> apiParams = {'value': value, 'min': min};

final Map<String, String> apiHeaders = {'content-type': 'application/json'};

final res = await client.call(
HttpMethod.patch,
path: apiPath,
params: apiParams,
headers: apiHeaders,
);

return models.Document.fromMap(res.data);
}

/// Increment a specific attribute of a document by a given value.
Future<models.Document> incrementDocumentAttribute({
required String databaseId,
required String collectionId,
required String documentId,
required String attribute,
double? value,
double? max,
}) async {
final String apiPath =
'/databases/{databaseId}/collections/{collectionId}/documents/{documentId}/{attribute}/increment'
.replaceAll('{databaseId}', databaseId)
.replaceAll('{collectionId}', collectionId)
.replaceAll('{documentId}', documentId)
.replaceAll('{attribute}', attribute);

final Map<String, dynamic> apiParams = {'value': value, 'max': max};

final Map<String, String> apiHeaders = {'content-type': 'application/json'};

final res = await client.call(
HttpMethod.patch,
path: apiPath,
params: apiParams,
headers: apiHeaders,
);

return models.Document.fromMap(res.data);
}

/// List indexes in the collection.
Future<models.IndexList> listIndexes({
required String databaseId,
Expand Down
2 changes: 1 addition & 1 deletion lib/services/tokens.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Tokens extends Service {
}

/// Create a new token. A token is linked to a file. Token can be passed as a
/// header or request get parameter.
/// request URL search parameter.
Future<models.ResourceToken> createFileToken({
required String bucketId,
required String fileId,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/client_browser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ClientBrowser extends ClientBase with ClientMixin {
'x-sdk-name': 'Dart',
'x-sdk-platform': 'server',
'x-sdk-language': 'dart',
'x-sdk-version': '16.0.0',
'x-sdk-version': '16.1.0',
'X-Appwrite-Response-Format': '1.7.0',
};

Expand Down
11 changes: 5 additions & 6 deletions lib/src/client_io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,19 @@ class ClientIO extends ClientBase with ClientMixin {
String endPoint = 'https://cloud.appwrite.io/v1',
bool selfSigned = false,
}) : _endPoint = endPoint {
_nativeClient =
HttpClient()
..badCertificateCallback =
((X509Certificate cert, String host, int port) => selfSigned);
_nativeClient = HttpClient()
..badCertificateCallback =
((X509Certificate cert, String host, int port) => selfSigned);
_httpClient = IOClient(_nativeClient);
_endPoint = endPoint;
_headers = {
'content-type': 'application/json',
'x-sdk-name': 'Dart',
'x-sdk-platform': 'server',
'x-sdk-language': 'dart',
'x-sdk-version': '16.0.0',
'x-sdk-version': '16.1.0',
'user-agent':
'AppwriteDartSDK/16.0.0 (${Platform.operatingSystem}; ${Platform.operatingSystemVersion})',
'AppwriteDartSDK/16.1.0 (${Platform.operatingSystem}; ${Platform.operatingSystemVersion})',
'X-Appwrite-Response-Format': '1.7.0',
};

Expand Down
Loading