diff --git a/CHANGELOG.md b/CHANGELOG.md index 9794709e..7ff4a445 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Change Log +## 19.0.0 + +* Rename `CreditCard` enum value `unionChinaPay` to `unionPay` +* Add time between query support +* Add spatial query support + ## 18.0.0 * Support for Appwrite 1.8 diff --git a/README.md b/README.md index 22703b2d..64344868 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Add this to your package's `pubspec.yaml` file: ```yml dependencies: - appwrite: ^18.0.0 + appwrite: ^19.0.0 ``` You can install packages from the command line: diff --git a/docs/examples/account/update-prefs.md b/docs/examples/account/update-prefs.md index 81fa362f..a084c13e 100644 --- a/docs/examples/account/update-prefs.md +++ b/docs/examples/account/update-prefs.md @@ -7,5 +7,9 @@ Client client = Client() Account account = Account(client); User result = await account.updatePrefs( - prefs: {}, + prefs: { + "language": "en", + "timezone": "UTC", + "darkTheme": true + }, ); diff --git a/docs/examples/databases/create-document.md b/docs/examples/databases/create-document.md index 27efc345..3becbcf1 100644 --- a/docs/examples/databases/create-document.md +++ b/docs/examples/databases/create-document.md @@ -10,6 +10,12 @@ Document result = await databases.createDocument( databaseId: '', collectionId: '', documentId: '', - data: {}, + data: { + "username": "walter.obrien", + "email": "walter.obrien@example.com", + "fullName": "Walter O'Brien", + "age": 30, + "isAdmin": false + }, permissions: ["read("any")"], // optional ); diff --git a/docs/examples/tablesdb/create-row.md b/docs/examples/tablesdb/create-row.md index f546133b..038bb2ba 100644 --- a/docs/examples/tablesdb/create-row.md +++ b/docs/examples/tablesdb/create-row.md @@ -10,6 +10,12 @@ Row result = await tablesDB.createRow( databaseId: '', tableId: '', rowId: '', - data: {}, + data: { + "username": "walter.obrien", + "email": "walter.obrien@example.com", + "fullName": "Walter O'Brien", + "age": 30, + "isAdmin": false + }, permissions: ["read("any")"], // optional ); diff --git a/lib/query.dart b/lib/query.dart index 2c523869..5a4184e1 100644 --- a/lib/query.dart +++ b/lib/query.dart @@ -9,17 +9,19 @@ class Query { Query._(this.method, [this.attribute = null, this.values = null]); Map toJson() { - final map = {'method': method}; + final result = {}; + + result['method'] = method; if (attribute != null) { - map['attribute'] = attribute; + result['attribute'] = attribute; } if (values != null) { - map['values'] = values is List ? values : [values]; + result['values'] = values is List ? values : [values]; } - return map; + return result; } @override @@ -35,7 +37,7 @@ class Query { /// Filter resources where [attribute] is not equal to [value]. static String notEqual(String attribute, dynamic value) => - Query._('notEqual', attribute, [value]).toString(); + Query._('notEqual', attribute, value).toString(); /// Filter resources where [attribute] is less than [value]. static String lessThan(String attribute, dynamic value) => @@ -111,6 +113,10 @@ class Query { static String createdAfter(String value) => Query._('createdAfter', null, value).toString(); + /// Filter resources where document was created between [start] and [end] (inclusive). + static String createdBetween(String start, String end) => + Query._('createdBetween', null, [start, end]).toString(); + /// Filter resources where document was updated before [value]. static String updatedBefore(String value) => Query._('updatedBefore', null, value).toString(); @@ -119,6 +125,10 @@ class Query { static String updatedAfter(String value) => Query._('updatedAfter', null, value).toString(); + /// Filter resources where document was updated between [start] and [end] (inclusive). + static String updatedBetween(String start, String end) => + Query._('updatedBetween', null, [start, end]).toString(); + static String or(List queries) => Query._( 'or', null, @@ -166,4 +176,68 @@ class Query { /// docs for more information. static String offset(int offset) => Query._('offset', null, offset).toString(); + + /// Filter resources where [attribute] is at a specific distance from the given coordinates. + static String distanceEqual( + String attribute, List values, num distance, + [bool meters = true]) => + Query._('distanceEqual', attribute, [ + [values, distance, meters] + ]).toString(); + + /// Filter resources where [attribute] is not at a specific distance from the given coordinates. + static String distanceNotEqual( + String attribute, List values, num distance, + [bool meters = true]) => + Query._('distanceNotEqual', attribute, [ + [values, distance, meters] + ]).toString(); + + /// Filter resources where [attribute] is at a distance greater than the specified value from the given coordinates. + static String distanceGreaterThan( + String attribute, List values, num distance, + [bool meters = true]) => + Query._('distanceGreaterThan', attribute, [ + [values, distance, meters] + ]).toString(); + + /// Filter resources where [attribute] is at a distance less than the specified value from the given coordinates. + static String distanceLessThan( + String attribute, List values, num distance, + [bool meters = true]) => + Query._('distanceLessThan', attribute, [ + [values, distance, meters] + ]).toString(); + + /// Filter resources where [attribute] intersects with the given geometry. + static String intersects(String attribute, List values) => + Query._('intersects', attribute, [values]).toString(); + + /// Filter resources where [attribute] does not intersect with the given geometry. + static String notIntersects(String attribute, List values) => + Query._('notIntersects', attribute, [values]).toString(); + + /// Filter resources where [attribute] crosses the given geometry. + static String crosses(String attribute, List values) => + Query._('crosses', attribute, [values]).toString(); + + /// Filter resources where [attribute] does not cross the given geometry. + static String notCrosses(String attribute, List values) => + Query._('notCrosses', attribute, [values]).toString(); + + /// Filter resources where [attribute] overlaps with the given geometry. + static String overlaps(String attribute, List values) => + Query._('overlaps', attribute, [values]).toString(); + + /// Filter resources where [attribute] does not overlap with the given geometry. + static String notOverlaps(String attribute, List values) => + Query._('notOverlaps', attribute, [values]).toString(); + + /// Filter resources where [attribute] touches the given geometry. + static String touches(String attribute, List values) => + Query._('touches', attribute, [values]).toString(); + + /// Filter resources where [attribute] does not touch the given geometry. + static String notTouches(String attribute, List values) => + Query._('notTouches', attribute, [values]).toString(); } diff --git a/lib/services/databases.dart b/lib/services/databases.dart index 8e165559..899b39db 100644 --- a/lib/services/databases.dart +++ b/lib/services/databases.dart @@ -9,28 +9,24 @@ class Databases extends Service { /// Get a list of all the user's documents in a given collection. You can use /// the query params to filter your results. @Deprecated( - 'This API has been deprecated since 1.8.0. Please use `TablesDB.listRows` instead.', - ) - Future listDocuments({ - required String databaseId, - required String collectionId, - List? queries, - }) async { + 'This API has been deprecated since 1.8.0. Please use `TablesDB.listRows` instead.') + Future listDocuments( + {required String databaseId, + required String collectionId, + List? queries}) async { final String apiPath = '/databases/{databaseId}/collections/{collectionId}/documents' .replaceAll('{databaseId}', databaseId) .replaceAll('{collectionId}', collectionId); - final Map apiParams = {'queries': queries}; + final Map apiParams = { + 'queries': queries, + }; final Map apiHeaders = {}; - final res = await client.call( - HttpMethod.get, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); return models.DocumentList.fromMap(res.data); } @@ -40,15 +36,13 @@ class Databases extends Service { /// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) /// API or directly from your database console. @Deprecated( - 'This API has been deprecated since 1.8.0. Please use `TablesDB.createRow` instead.', - ) - Future createDocument({ - required String databaseId, - required String collectionId, - required String documentId, - required Map data, - List? permissions, - }) async { + 'This API has been deprecated since 1.8.0. Please use `TablesDB.createRow` instead.') + Future createDocument( + {required String databaseId, + required String collectionId, + required String documentId, + required Map data, + List? permissions}) async { final String apiPath = '/databases/{databaseId}/collections/{collectionId}/documents' .replaceAll('{databaseId}', databaseId) @@ -60,14 +54,12 @@ class Databases extends Service { 'permissions': permissions, }; - final Map apiHeaders = {'content-type': 'application/json'}; + final Map apiHeaders = { + 'content-type': 'application/json', + }; - final res = await client.call( - HttpMethod.post, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); return models.Document.fromMap(res.data); } @@ -75,30 +67,26 @@ class Databases extends Service { /// Get a document by its unique ID. This endpoint response returns a JSON /// object with the document data. @Deprecated( - 'This API has been deprecated since 1.8.0. Please use `TablesDB.getRow` instead.', - ) - Future getDocument({ - required String databaseId, - required String collectionId, - required String documentId, - List? queries, - }) async { + 'This API has been deprecated since 1.8.0. Please use `TablesDB.getRow` instead.') + Future getDocument( + {required String databaseId, + required String collectionId, + required String documentId, + List? queries}) async { final String apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}' .replaceAll('{databaseId}', databaseId) .replaceAll('{collectionId}', collectionId) .replaceAll('{documentId}', documentId); - final Map apiParams = {'queries': queries}; + final Map apiParams = { + 'queries': queries, + }; final Map apiHeaders = {}; - final res = await client.call( - HttpMethod.get, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); return models.Document.fromMap(res.data); } @@ -108,15 +96,13 @@ class Databases extends Service { /// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) /// API or directly from your database console. @Deprecated( - 'This API has been deprecated since 1.8.0. Please use `TablesDB.upsertRow` instead.', - ) - Future upsertDocument({ - required String databaseId, - required String collectionId, - required String documentId, - required Map data, - List? permissions, - }) async { + 'This API has been deprecated since 1.8.0. Please use `TablesDB.upsertRow` instead.') + Future upsertDocument( + {required String databaseId, + required String collectionId, + required String documentId, + required Map data, + List? permissions}) async { final String apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}' .replaceAll('{databaseId}', databaseId) @@ -128,14 +114,12 @@ class Databases extends Service { 'permissions': permissions, }; - final Map apiHeaders = {'content-type': 'application/json'}; + final Map apiHeaders = { + 'content-type': 'application/json', + }; - final res = await client.call( - HttpMethod.put, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); return models.Document.fromMap(res.data); } @@ -143,15 +127,13 @@ class Databases extends Service { /// Update a document by its unique ID. Using the patch method you can pass /// only specific fields that will get updated. @Deprecated( - 'This API has been deprecated since 1.8.0. Please use `TablesDB.updateRow` instead.', - ) - Future updateDocument({ - required String databaseId, - required String collectionId, - required String documentId, - Map? data, - List? permissions, - }) async { + 'This API has been deprecated since 1.8.0. Please use `TablesDB.updateRow` instead.') + Future updateDocument( + {required String databaseId, + required String collectionId, + required String documentId, + Map? data, + List? permissions}) async { final String apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}' .replaceAll('{databaseId}', databaseId) @@ -163,27 +145,23 @@ class Databases extends Service { 'permissions': permissions, }; - final Map apiHeaders = {'content-type': 'application/json'}; + final Map apiHeaders = { + 'content-type': 'application/json', + }; - final res = await client.call( - HttpMethod.patch, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); return models.Document.fromMap(res.data); } /// Delete a document by its unique ID. @Deprecated( - 'This API has been deprecated since 1.8.0. Please use `TablesDB.deleteRow` instead.', - ) - Future deleteDocument({ - required String databaseId, - required String collectionId, - required String documentId, - }) async { + 'This API has been deprecated since 1.8.0. Please use `TablesDB.deleteRow` instead.') + Future deleteDocument( + {required String databaseId, + required String collectionId, + required String documentId}) async { final String apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}' .replaceAll('{databaseId}', databaseId) @@ -192,30 +170,26 @@ class Databases extends Service { final Map apiParams = {}; - final Map apiHeaders = {'content-type': 'application/json'}; + final Map apiHeaders = { + 'content-type': 'application/json', + }; - final res = await client.call( - HttpMethod.delete, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); return res.data; } /// Decrement a specific attribute of a document by a given value. @Deprecated( - 'This API has been deprecated since 1.8.0. Please use `TablesDB.decrementRowColumn` instead.', - ) - Future decrementDocumentAttribute({ - required String databaseId, - required String collectionId, - required String documentId, - required String attribute, - double? value, - double? min, - }) async { + 'This API has been deprecated since 1.8.0. Please use `TablesDB.decrementRowColumn` instead.') + Future 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) @@ -223,32 +197,31 @@ class Databases extends Service { .replaceAll('{documentId}', documentId) .replaceAll('{attribute}', attribute); - final Map apiParams = {'value': value, 'min': min}; + final Map apiParams = { + 'value': value, + 'min': min, + }; - final Map apiHeaders = {'content-type': 'application/json'}; + final Map apiHeaders = { + 'content-type': 'application/json', + }; - final res = await client.call( - HttpMethod.patch, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + 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. @Deprecated( - 'This API has been deprecated since 1.8.0. Please use `TablesDB.incrementRowColumn` instead.', - ) - Future incrementDocumentAttribute({ - required String databaseId, - required String collectionId, - required String documentId, - required String attribute, - double? value, - double? max, - }) async { + 'This API has been deprecated since 1.8.0. Please use `TablesDB.incrementRowColumn` instead.') + Future 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) @@ -256,16 +229,17 @@ class Databases extends Service { .replaceAll('{documentId}', documentId) .replaceAll('{attribute}', attribute); - final Map apiParams = {'value': value, 'max': max}; + final Map apiParams = { + 'value': value, + 'max': max, + }; - final Map apiHeaders = {'content-type': 'application/json'}; + final Map apiHeaders = { + 'content-type': 'application/json', + }; - final res = await client.call( - HttpMethod.patch, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); return models.Document.fromMap(res.data); } diff --git a/lib/services/functions.dart b/lib/services/functions.dart index d8924273..8b8f9c1e 100644 --- a/lib/services/functions.dart +++ b/lib/services/functions.dart @@ -8,25 +8,19 @@ class Functions extends Service { /// Get a list of all the current user function execution logs. You can use the /// query params to filter your results. - Future listExecutions({ - required String functionId, - List? queries, - }) async { - final String apiPath = '/functions/{functionId}/executions'.replaceAll( - '{functionId}', - functionId, - ); + Future listExecutions( + {required String functionId, List? queries}) async { + final String apiPath = '/functions/{functionId}/executions' + .replaceAll('{functionId}', functionId); - final Map apiParams = {'queries': queries}; + final Map apiParams = { + 'queries': queries, + }; final Map apiHeaders = {}; - final res = await client.call( - HttpMethod.get, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); return models.ExecutionList.fromMap(res.data); } @@ -35,19 +29,16 @@ class Functions extends Service { /// current execution status. You can ping the `Get Execution` endpoint to get /// updates on the current execution status. Once this endpoint is called, your /// function execution process will start asynchronously. - Future createExecution({ - required String functionId, - String? body, - bool? xasync, - String? path, - enums.ExecutionMethod? method, - Map? headers, - String? scheduledAt, - }) async { - final String apiPath = '/functions/{functionId}/executions'.replaceAll( - '{functionId}', - functionId, - ); + Future createExecution( + {required String functionId, + String? body, + bool? xasync, + String? path, + enums.ExecutionMethod? method, + Map? headers, + String? scheduledAt}) async { + final String apiPath = '/functions/{functionId}/executions' + .replaceAll('{functionId}', functionId); final Map apiParams = { 'body': body, @@ -58,23 +49,19 @@ class Functions extends Service { 'scheduledAt': scheduledAt, }; - final Map apiHeaders = {'content-type': 'application/json'}; + final Map apiHeaders = { + 'content-type': 'application/json', + }; - final res = await client.call( - HttpMethod.post, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); return models.Execution.fromMap(res.data); } /// Get a function execution log by its unique ID. - Future getExecution({ - required String functionId, - required String executionId, - }) async { + Future getExecution( + {required String functionId, required String executionId}) async { final String apiPath = '/functions/{functionId}/executions/{executionId}' .replaceAll('{functionId}', functionId) .replaceAll('{executionId}', executionId); @@ -83,12 +70,8 @@ class Functions extends Service { final Map apiHeaders = {}; - final res = await client.call( - HttpMethod.get, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); return models.Execution.fromMap(res.data); } diff --git a/lib/services/graphql.dart b/lib/services/graphql.dart index 32ea107f..ff4e17d4 100644 --- a/lib/services/graphql.dart +++ b/lib/services/graphql.dart @@ -10,19 +10,17 @@ class Graphql extends Service { Future query({required Map query}) async { const String apiPath = '/graphql'; - final Map apiParams = {'query': query}; + final Map apiParams = { + 'query': query, + }; final Map apiHeaders = { 'x-sdk-graphql': 'true', 'content-type': 'application/json', }; - final res = await client.call( - HttpMethod.post, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); return res.data; } @@ -31,19 +29,17 @@ class Graphql extends Service { Future mutation({required Map query}) async { const String apiPath = '/graphql/mutation'; - final Map apiParams = {'query': query}; + final Map apiParams = { + 'query': query, + }; final Map apiHeaders = { 'x-sdk-graphql': 'true', 'content-type': 'application/json', }; - final res = await client.call( - HttpMethod.post, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); return res.data; } diff --git a/lib/services/locale.dart b/lib/services/locale.dart index fbd04e4a..dd9a5fef 100644 --- a/lib/services/locale.dart +++ b/lib/services/locale.dart @@ -19,12 +19,8 @@ class Locale extends Service { final Map apiHeaders = {}; - final res = await client.call( - HttpMethod.get, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); return models.Locale.fromMap(res.data); } @@ -38,12 +34,8 @@ class Locale extends Service { final Map apiHeaders = {}; - final res = await client.call( - HttpMethod.get, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); return models.LocaleCodeList.fromMap(res.data); } @@ -57,12 +49,8 @@ class Locale extends Service { final Map apiHeaders = {}; - final res = await client.call( - HttpMethod.get, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); return models.ContinentList.fromMap(res.data); } @@ -76,12 +64,8 @@ class Locale extends Service { final Map apiHeaders = {}; - final res = await client.call( - HttpMethod.get, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); return models.CountryList.fromMap(res.data); } @@ -95,12 +79,8 @@ class Locale extends Service { final Map apiHeaders = {}; - final res = await client.call( - HttpMethod.get, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); return models.CountryList.fromMap(res.data); } @@ -114,12 +94,8 @@ class Locale extends Service { final Map apiHeaders = {}; - final res = await client.call( - HttpMethod.get, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); return models.PhoneList.fromMap(res.data); } @@ -134,12 +110,8 @@ class Locale extends Service { final Map apiHeaders = {}; - final res = await client.call( - HttpMethod.get, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); return models.CurrencyList.fromMap(res.data); } @@ -153,12 +125,8 @@ class Locale extends Service { final Map apiHeaders = {}; - final res = await client.call( - HttpMethod.get, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); return models.LanguageList.fromMap(res.data); } diff --git a/lib/services/messaging.dart b/lib/services/messaging.dart index 236037fa..87760d50 100644 --- a/lib/services/messaging.dart +++ b/lib/services/messaging.dart @@ -7,38 +7,31 @@ class Messaging extends Service { Messaging(super.client); /// Create a new subscriber. - Future createSubscriber({ - required String topicId, - required String subscriberId, - required String targetId, - }) async { - final String apiPath = '/messaging/topics/{topicId}/subscribers'.replaceAll( - '{topicId}', - topicId, - ); + Future createSubscriber( + {required String topicId, + required String subscriberId, + required String targetId}) async { + final String apiPath = '/messaging/topics/{topicId}/subscribers' + .replaceAll('{topicId}', topicId); final Map apiParams = { 'subscriberId': subscriberId, 'targetId': targetId, }; - final Map apiHeaders = {'content-type': 'application/json'}; + final Map apiHeaders = { + 'content-type': 'application/json', + }; - final res = await client.call( - HttpMethod.post, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); return models.Subscriber.fromMap(res.data); } /// Delete a subscriber by its unique ID. - Future deleteSubscriber({ - required String topicId, - required String subscriberId, - }) async { + Future deleteSubscriber( + {required String topicId, required String subscriberId}) async { final String apiPath = '/messaging/topics/{topicId}/subscribers/{subscriberId}' .replaceAll('{topicId}', topicId) @@ -46,14 +39,12 @@ class Messaging extends Service { final Map apiParams = {}; - final Map apiHeaders = {'content-type': 'application/json'}; + final Map apiHeaders = { + 'content-type': 'application/json', + }; - final res = await client.call( - HttpMethod.delete, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); return res.data; } diff --git a/lib/services/tables_db.dart b/lib/services/tables_db.dart index 2c6f1c09..48c632e2 100644 --- a/lib/services/tables_db.dart +++ b/lib/services/tables_db.dart @@ -6,25 +6,22 @@ class TablesDB extends Service { /// Get a list of all the user's rows in a given table. You can use the query /// params to filter your results. - Future listRows({ - required String databaseId, - required String tableId, - List? queries, - }) async { + Future listRows( + {required String databaseId, + required String tableId, + List? queries}) async { final String apiPath = '/tablesdb/{databaseId}/tables/{tableId}/rows' .replaceAll('{databaseId}', databaseId) .replaceAll('{tableId}', tableId); - final Map apiParams = {'queries': queries}; + final Map apiParams = { + 'queries': queries, + }; final Map apiHeaders = {}; - final res = await client.call( - HttpMethod.get, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); return models.RowList.fromMap(res.data); } @@ -33,13 +30,12 @@ class TablesDB extends Service { /// resource using either a [server /// integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreateTable) /// API or directly from your database console. - Future createRow({ - required String databaseId, - required String tableId, - required String rowId, - required Map data, - List? permissions, - }) async { + Future createRow( + {required String databaseId, + required String tableId, + required String rowId, + required Map data, + List? permissions}) async { final String apiPath = '/tablesdb/{databaseId}/tables/{tableId}/rows' .replaceAll('{databaseId}', databaseId) .replaceAll('{tableId}', tableId); @@ -50,42 +46,37 @@ class TablesDB extends Service { 'permissions': permissions, }; - final Map apiHeaders = {'content-type': 'application/json'}; + final Map apiHeaders = { + 'content-type': 'application/json', + }; - final res = await client.call( - HttpMethod.post, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); return models.Row.fromMap(res.data); } /// Get a row by its unique ID. This endpoint response returns a JSON object /// with the row data. - Future getRow({ - required String databaseId, - required String tableId, - required String rowId, - List? queries, - }) async { + Future getRow( + {required String databaseId, + required String tableId, + required String rowId, + List? queries}) async { final String apiPath = '/tablesdb/{databaseId}/tables/{tableId}/rows/{rowId}' .replaceAll('{databaseId}', databaseId) .replaceAll('{tableId}', tableId) .replaceAll('{rowId}', rowId); - final Map apiParams = {'queries': queries}; + final Map apiParams = { + 'queries': queries, + }; final Map apiHeaders = {}; - final res = await client.call( - HttpMethod.get, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); return models.Row.fromMap(res.data); } @@ -94,13 +85,12 @@ class TablesDB extends Service { /// table resource using either a [server /// integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreateTable) /// API or directly from your database console. - Future upsertRow({ - required String databaseId, - required String tableId, - required String rowId, - Map? data, - List? permissions, - }) async { + Future upsertRow( + {required String databaseId, + required String tableId, + required String rowId, + Map? data, + List? permissions}) async { final String apiPath = '/tablesdb/{databaseId}/tables/{tableId}/rows/{rowId}' .replaceAll('{databaseId}', databaseId) @@ -112,27 +102,24 @@ class TablesDB extends Service { 'permissions': permissions, }; - final Map apiHeaders = {'content-type': 'application/json'}; + final Map apiHeaders = { + 'content-type': 'application/json', + }; - final res = await client.call( - HttpMethod.put, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); return models.Row.fromMap(res.data); } /// Update a row by its unique ID. Using the patch method you can pass only /// specific fields that will get updated. - Future updateRow({ - required String databaseId, - required String tableId, - required String rowId, - Map? data, - List? permissions, - }) async { + Future updateRow( + {required String databaseId, + required String tableId, + required String rowId, + Map? data, + List? permissions}) async { final String apiPath = '/tablesdb/{databaseId}/tables/{tableId}/rows/{rowId}' .replaceAll('{databaseId}', databaseId) @@ -144,24 +131,21 @@ class TablesDB extends Service { 'permissions': permissions, }; - final Map apiHeaders = {'content-type': 'application/json'}; + final Map apiHeaders = { + 'content-type': 'application/json', + }; - final res = await client.call( - HttpMethod.patch, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); return models.Row.fromMap(res.data); } /// Delete a row by its unique ID. - Future deleteRow({ - required String databaseId, - required String tableId, - required String rowId, - }) async { + Future deleteRow( + {required String databaseId, + required String tableId, + required String rowId}) async { final String apiPath = '/tablesdb/{databaseId}/tables/{tableId}/rows/{rowId}' .replaceAll('{databaseId}', databaseId) @@ -170,27 +154,24 @@ class TablesDB extends Service { final Map apiParams = {}; - final Map apiHeaders = {'content-type': 'application/json'}; + final Map apiHeaders = { + 'content-type': 'application/json', + }; - final res = await client.call( - HttpMethod.delete, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); return res.data; } /// Decrement a specific column of a row by a given value. - Future decrementRowColumn({ - required String databaseId, - required String tableId, - required String rowId, - required String column, - double? value, - double? min, - }) async { + Future decrementRowColumn( + {required String databaseId, + required String tableId, + required String rowId, + required String column, + double? value, + double? min}) async { final String apiPath = '/tablesdb/{databaseId}/tables/{tableId}/rows/{rowId}/{column}/decrement' .replaceAll('{databaseId}', databaseId) @@ -198,29 +179,29 @@ class TablesDB extends Service { .replaceAll('{rowId}', rowId) .replaceAll('{column}', column); - final Map apiParams = {'value': value, 'min': min}; + final Map apiParams = { + 'value': value, + 'min': min, + }; - final Map apiHeaders = {'content-type': 'application/json'}; + final Map apiHeaders = { + 'content-type': 'application/json', + }; - final res = await client.call( - HttpMethod.patch, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); return models.Row.fromMap(res.data); } /// Increment a specific column of a row by a given value. - Future incrementRowColumn({ - required String databaseId, - required String tableId, - required String rowId, - required String column, - double? value, - double? max, - }) async { + Future incrementRowColumn( + {required String databaseId, + required String tableId, + required String rowId, + required String column, + double? value, + double? max}) async { final String apiPath = '/tablesdb/{databaseId}/tables/{tableId}/rows/{rowId}/{column}/increment' .replaceAll('{databaseId}', databaseId) @@ -228,16 +209,17 @@ class TablesDB extends Service { .replaceAll('{rowId}', rowId) .replaceAll('{column}', column); - final Map apiParams = {'value': value, 'max': max}; + final Map apiParams = { + 'value': value, + 'max': max, + }; - final Map apiHeaders = {'content-type': 'application/json'}; + final Map apiHeaders = { + 'content-type': 'application/json', + }; - final res = await client.call( - HttpMethod.patch, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); return models.Row.fromMap(res.data); } diff --git a/lib/services/teams.dart b/lib/services/teams.dart index 24089628..4da8936a 100644 --- a/lib/services/teams.dart +++ b/lib/services/teams.dart @@ -18,12 +18,8 @@ class Teams extends Service { final Map apiHeaders = {}; - final res = await client.call( - HttpMethod.get, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); return models.TeamList.fromMap(res.data); } @@ -31,11 +27,10 @@ class Teams extends Service { /// Create a new team. The user who creates the team will automatically be /// assigned as the owner of the team. Only the users with the owner role can /// invite new members, add new owners and delete or update the team. - Future create({ - required String teamId, - required String name, - List? roles, - }) async { + Future create( + {required String teamId, + required String name, + List? roles}) async { const String apiPath = '/teams'; final Map apiParams = { @@ -44,14 +39,12 @@ class Teams extends Service { 'roles': roles, }; - final Map apiHeaders = {'content-type': 'application/json'}; + final Map apiHeaders = { + 'content-type': 'application/json', + }; - final res = await client.call( - HttpMethod.post, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); return models.Team.fromMap(res.data); } @@ -64,33 +57,27 @@ class Teams extends Service { final Map apiHeaders = {}; - final res = await client.call( - HttpMethod.get, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); return models.Team.fromMap(res.data); } /// Update the team's name by its unique ID. - Future updateName({ - required String teamId, - required String name, - }) async { + Future updateName( + {required String teamId, required String name}) async { final String apiPath = '/teams/{teamId}'.replaceAll('{teamId}', teamId); - final Map apiParams = {'name': name}; + final Map apiParams = { + 'name': name, + }; - final Map apiHeaders = {'content-type': 'application/json'}; + final Map apiHeaders = { + 'content-type': 'application/json', + }; - final res = await client.call( - HttpMethod.put, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); return models.Team.fromMap(res.data); } @@ -102,14 +89,12 @@ class Teams extends Service { final Map apiParams = {}; - final Map apiHeaders = {'content-type': 'application/json'}; + final Map apiHeaders = { + 'content-type': 'application/json', + }; - final res = await client.call( - HttpMethod.delete, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); return res.data; } @@ -117,15 +102,10 @@ class Teams extends Service { /// Use this endpoint to list a team's members using the team's ID. All team /// members have read access to this endpoint. Hide sensitive attributes from /// the response by toggling membership privacy in the Console. - Future listMemberships({ - required String teamId, - List? queries, - String? search, - }) async { - final String apiPath = '/teams/{teamId}/memberships'.replaceAll( - '{teamId}', - teamId, - ); + Future listMemberships( + {required String teamId, List? queries, String? search}) async { + final String apiPath = + '/teams/{teamId}/memberships'.replaceAll('{teamId}', teamId); final Map apiParams = { 'queries': queries, @@ -134,12 +114,8 @@ class Teams extends Service { final Map apiHeaders = {}; - final res = await client.call( - HttpMethod.get, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); return models.MembershipList.fromMap(res.data); } @@ -165,19 +141,16 @@ class Teams extends Service { /// Appwrite will accept the only redirect URLs under the domains you have /// added as a platform on the Appwrite Console. /// - Future createMembership({ - required String teamId, - required List roles, - String? email, - String? userId, - String? phone, - String? url, - String? name, - }) async { - final String apiPath = '/teams/{teamId}/memberships'.replaceAll( - '{teamId}', - teamId, - ); + Future createMembership( + {required String teamId, + required List roles, + String? email, + String? userId, + String? phone, + String? url, + String? name}) async { + final String apiPath = + '/teams/{teamId}/memberships'.replaceAll('{teamId}', teamId); final Map apiParams = { 'email': email, @@ -188,14 +161,12 @@ class Teams extends Service { 'name': name, }; - final Map apiHeaders = {'content-type': 'application/json'}; + final Map apiHeaders = { + 'content-type': 'application/json', + }; - final res = await client.call( - HttpMethod.post, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); return models.Membership.fromMap(res.data); } @@ -203,10 +174,8 @@ class Teams extends Service { /// Get a team member by the membership unique id. All team members have read /// access for this resource. Hide sensitive attributes from the response by /// toggling membership privacy in the Console. - Future getMembership({ - required String teamId, - required String membershipId, - }) async { + Future getMembership( + {required String teamId, required String membershipId}) async { final String apiPath = '/teams/{teamId}/memberships/{membershipId}' .replaceAll('{teamId}', teamId) .replaceAll('{membershipId}', membershipId); @@ -215,12 +184,8 @@ class Teams extends Service { final Map apiHeaders = {}; - final res = await client.call( - HttpMethod.get, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); return models.Membership.fromMap(res.data); } @@ -229,25 +194,24 @@ class Teams extends Service { /// have access to this endpoint. Learn more about [roles and /// permissions](https://appwrite.io/docs/permissions). /// - Future updateMembership({ - required String teamId, - required String membershipId, - required List roles, - }) async { + Future updateMembership( + {required String teamId, + required String membershipId, + required List roles}) async { final String apiPath = '/teams/{teamId}/memberships/{membershipId}' .replaceAll('{teamId}', teamId) .replaceAll('{membershipId}', membershipId); - final Map apiParams = {'roles': roles}; + final Map apiParams = { + 'roles': roles, + }; - final Map apiHeaders = {'content-type': 'application/json'}; + final Map apiHeaders = { + 'content-type': 'application/json', + }; - final res = await client.call( - HttpMethod.patch, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); return models.Membership.fromMap(res.data); } @@ -255,24 +219,20 @@ class Teams extends Service { /// This endpoint allows a user to leave a team or for a team owner to delete /// the membership of any other team member. You can also use this endpoint to /// delete a user membership even if it is not accepted. - Future deleteMembership({ - required String teamId, - required String membershipId, - }) async { + Future deleteMembership( + {required String teamId, required String membershipId}) async { final String apiPath = '/teams/{teamId}/memberships/{membershipId}' .replaceAll('{teamId}', teamId) .replaceAll('{membershipId}', membershipId); final Map apiParams = {}; - final Map apiHeaders = {'content-type': 'application/json'}; + final Map apiHeaders = { + 'content-type': 'application/json', + }; - final res = await client.call( - HttpMethod.delete, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); return res.data; } @@ -284,26 +244,26 @@ class Teams extends Service { /// If the request is successful, a session for the user is automatically /// created. /// - Future updateMembershipStatus({ - required String teamId, - required String membershipId, - required String userId, - required String secret, - }) async { + Future updateMembershipStatus( + {required String teamId, + required String membershipId, + required String userId, + required String secret}) async { final String apiPath = '/teams/{teamId}/memberships/{membershipId}/status' .replaceAll('{teamId}', teamId) .replaceAll('{membershipId}', membershipId); - final Map apiParams = {'userId': userId, 'secret': secret}; + final Map apiParams = { + 'userId': userId, + 'secret': secret, + }; - final Map apiHeaders = {'content-type': 'application/json'}; + final Map apiHeaders = { + 'content-type': 'application/json', + }; - final res = await client.call( - HttpMethod.patch, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); return models.Membership.fromMap(res.data); } @@ -312,21 +272,15 @@ class Teams extends Service { /// need to be shared by all team members, prefer storing them in [user /// preferences](https://appwrite.io/docs/references/cloud/client-web/account#getPrefs). Future getPrefs({required String teamId}) async { - final String apiPath = '/teams/{teamId}/prefs'.replaceAll( - '{teamId}', - teamId, - ); + final String apiPath = + '/teams/{teamId}/prefs'.replaceAll('{teamId}', teamId); final Map apiParams = {}; final Map apiHeaders = {}; - final res = await client.call( - HttpMethod.get, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); return models.Preferences.fromMap(res.data); } @@ -334,25 +288,21 @@ class Teams extends Service { /// Update the team's preferences by its unique ID. The object you pass is /// stored as is and replaces any previous value. The maximum allowed prefs /// size is 64kB and throws an error if exceeded. - Future updatePrefs({ - required String teamId, - required Map prefs, - }) async { - final String apiPath = '/teams/{teamId}/prefs'.replaceAll( - '{teamId}', - teamId, - ); - - final Map apiParams = {'prefs': prefs}; - - final Map apiHeaders = {'content-type': 'application/json'}; - - final res = await client.call( - HttpMethod.put, - path: apiPath, - params: apiParams, - headers: apiHeaders, - ); + Future updatePrefs( + {required String teamId, required Map prefs}) async { + final String apiPath = + '/teams/{teamId}/prefs'.replaceAll('{teamId}', teamId); + + final Map apiParams = { + 'prefs': prefs, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); return models.Preferences.fromMap(res.data); } diff --git a/lib/src/client_browser.dart b/lib/src/client_browser.dart index 7b4d47a5..c1595bf3 100644 --- a/lib/src/client_browser.dart +++ b/lib/src/client_browser.dart @@ -40,7 +40,7 @@ class ClientBrowser extends ClientBase with ClientMixin { 'x-sdk-name': 'Flutter', 'x-sdk-platform': 'client', 'x-sdk-language': 'flutter', - 'x-sdk-version': '18.0.0', + 'x-sdk-version': '19.0.0', 'X-Appwrite-Response-Format': '1.8.0', }; diff --git a/lib/src/client_io.dart b/lib/src/client_io.dart index 2ff7f93e..d3e33109 100644 --- a/lib/src/client_io.dart +++ b/lib/src/client_io.dart @@ -58,7 +58,7 @@ class ClientIO extends ClientBase with ClientMixin { 'x-sdk-name': 'Flutter', 'x-sdk-platform': 'client', 'x-sdk-language': 'flutter', - 'x-sdk-version': '18.0.0', + 'x-sdk-version': '19.0.0', 'X-Appwrite-Response-Format': '1.8.0', }; diff --git a/lib/src/client_mixin.dart b/lib/src/client_mixin.dart index 06c9ebe3..0c6b3593 100644 --- a/lib/src/client_mixin.dart +++ b/lib/src/client_mixin.dart @@ -123,11 +123,10 @@ mixin ClientMixin { return http.Response( '', streamedResponse.statusCode, - headers: streamedResponse.headers.map( - (k, v) => k.toLowerCase() == 'content-type' - ? MapEntry(k, 'text/plain') - : MapEntry(k, v), - ), + headers: streamedResponse.headers.map((k, v) => + k.toLowerCase() == 'content-type' + ? MapEntry(k, 'text/plain') + : MapEntry(k, v)), request: streamedResponse.request, isRedirect: streamedResponse.isRedirect, persistentConnection: streamedResponse.persistentConnection, diff --git a/lib/src/cookie_manager.dart b/lib/src/cookie_manager.dart index c345e705..6b1e67cd 100644 --- a/lib/src/cookie_manager.dart +++ b/lib/src/cookie_manager.dart @@ -11,7 +11,9 @@ class CookieManager extends Interceptor { CookieManager(this.cookieJar); @override - FutureOr onRequest(http.BaseRequest request) async { + FutureOr onRequest( + http.BaseRequest request, + ) async { await cookieJar .loadForRequest(Uri(scheme: request.url.scheme, host: request.url.host)) .then((cookies) { @@ -41,9 +43,8 @@ class CookieManager extends Interceptor { var cookies = cookie.split(exp); await cookieJar.saveFromResponse( Uri( - scheme: response.request!.url.scheme, - host: response.request!.url.host, - ), + scheme: response.request!.url.scheme, + host: response.request!.url.host), cookies.map((str) => Cookie.fromSetCookieValue(str)).toList(), ); } diff --git a/lib/src/enums.dart b/lib/src/enums.dart index 0f250ea3..595afdc2 100644 --- a/lib/src/enums.dart +++ b/lib/src/enums.dart @@ -17,5 +17,5 @@ enum ResponseType { plain, /// Get original bytes, the type of response will be `List` - bytes, + bytes } diff --git a/lib/src/enums/credit_card.dart b/lib/src/enums/credit_card.dart index 1bae5c8a..28c2a1b3 100644 --- a/lib/src/enums/credit_card.dart +++ b/lib/src/enums/credit_card.dart @@ -13,7 +13,7 @@ enum CreditCard { mastercard(value: 'mastercard'), naranja(value: 'naranja'), tarjetaShopping(value: 'targeta-shopping'), - unionChinaPay(value: 'union-china-pay'), + unionPay(value: 'unionpay'), visa(value: 'visa'), mIR(value: 'mir'), maestro(value: 'maestro'), diff --git a/lib/src/enums/execution_method.dart b/lib/src/enums/execution_method.dart index 42954430..44de4907 100644 --- a/lib/src/enums/execution_method.dart +++ b/lib/src/enums/execution_method.dart @@ -6,7 +6,8 @@ enum ExecutionMethod { pUT(value: 'PUT'), pATCH(value: 'PATCH'), dELETE(value: 'DELETE'), - oPTIONS(value: 'OPTIONS'); + oPTIONS(value: 'OPTIONS'), + hEAD(value: 'HEAD'); const ExecutionMethod({required this.value}); diff --git a/lib/src/models/algo_bcrypt.dart b/lib/src/models/algo_bcrypt.dart index 4e901476..2ba0c398 100644 --- a/lib/src/models/algo_bcrypt.dart +++ b/lib/src/models/algo_bcrypt.dart @@ -5,13 +5,19 @@ class AlgoBcrypt implements Model { /// Algo type. final String type; - AlgoBcrypt({required this.type}); + AlgoBcrypt({ + required this.type, + }); factory AlgoBcrypt.fromMap(Map map) { - return AlgoBcrypt(type: map['type'].toString()); + return AlgoBcrypt( + type: map['type'].toString(), + ); } Map toMap() { - return {"type": type}; + return { + "type": type, + }; } } diff --git a/lib/src/models/algo_md5.dart b/lib/src/models/algo_md5.dart index 35c7b767..8bdfca6f 100644 --- a/lib/src/models/algo_md5.dart +++ b/lib/src/models/algo_md5.dart @@ -5,13 +5,19 @@ class AlgoMd5 implements Model { /// Algo type. final String type; - AlgoMd5({required this.type}); + AlgoMd5({ + required this.type, + }); factory AlgoMd5.fromMap(Map map) { - return AlgoMd5(type: map['type'].toString()); + return AlgoMd5( + type: map['type'].toString(), + ); } Map toMap() { - return {"type": type}; + return { + "type": type, + }; } } diff --git a/lib/src/models/algo_phpass.dart b/lib/src/models/algo_phpass.dart index 7d27adba..4f5f9179 100644 --- a/lib/src/models/algo_phpass.dart +++ b/lib/src/models/algo_phpass.dart @@ -5,13 +5,19 @@ class AlgoPhpass implements Model { /// Algo type. final String type; - AlgoPhpass({required this.type}); + AlgoPhpass({ + required this.type, + }); factory AlgoPhpass.fromMap(Map map) { - return AlgoPhpass(type: map['type'].toString()); + return AlgoPhpass( + type: map['type'].toString(), + ); } Map toMap() { - return {"type": type}; + return { + "type": type, + }; } } diff --git a/lib/src/models/algo_sha.dart b/lib/src/models/algo_sha.dart index bae6618f..47068be0 100644 --- a/lib/src/models/algo_sha.dart +++ b/lib/src/models/algo_sha.dart @@ -5,13 +5,19 @@ class AlgoSha implements Model { /// Algo type. final String type; - AlgoSha({required this.type}); + AlgoSha({ + required this.type, + }); factory AlgoSha.fromMap(Map map) { - return AlgoSha(type: map['type'].toString()); + return AlgoSha( + type: map['type'].toString(), + ); } Map toMap() { - return {"type": type}; + return { + "type": type, + }; } } diff --git a/lib/src/models/continent.dart b/lib/src/models/continent.dart index 7318b7ad..990b1064 100644 --- a/lib/src/models/continent.dart +++ b/lib/src/models/continent.dart @@ -8,7 +8,10 @@ class Continent implements Model { /// Continent two letter code. final String code; - Continent({required this.name, required this.code}); + Continent({ + required this.name, + required this.code, + }); factory Continent.fromMap(Map map) { return Continent( @@ -18,6 +21,9 @@ class Continent implements Model { } Map toMap() { - return {"name": name, "code": code}; + return { + "name": name, + "code": code, + }; } } diff --git a/lib/src/models/continent_list.dart b/lib/src/models/continent_list.dart index ec2c0755..97b7d84c 100644 --- a/lib/src/models/continent_list.dart +++ b/lib/src/models/continent_list.dart @@ -8,14 +8,16 @@ class ContinentList implements Model { /// List of continents. final List continents; - ContinentList({required this.total, required this.continents}); + ContinentList({ + required this.total, + required this.continents, + }); factory ContinentList.fromMap(Map map) { return ContinentList( total: map['total'], continents: List.from( - map['continents'].map((p) => Continent.fromMap(p)), - ), + map['continents'].map((p) => Continent.fromMap(p))), ); } diff --git a/lib/src/models/country.dart b/lib/src/models/country.dart index c52b50f2..d11c55db 100644 --- a/lib/src/models/country.dart +++ b/lib/src/models/country.dart @@ -8,13 +8,22 @@ class Country implements Model { /// Country two-character ISO 3166-1 alpha code. final String code; - Country({required this.name, required this.code}); + Country({ + required this.name, + required this.code, + }); factory Country.fromMap(Map map) { - return Country(name: map['name'].toString(), code: map['code'].toString()); + return Country( + name: map['name'].toString(), + code: map['code'].toString(), + ); } Map toMap() { - return {"name": name, "code": code}; + return { + "name": name, + "code": code, + }; } } diff --git a/lib/src/models/country_list.dart b/lib/src/models/country_list.dart index 65e13be3..0765c718 100644 --- a/lib/src/models/country_list.dart +++ b/lib/src/models/country_list.dart @@ -8,14 +8,16 @@ class CountryList implements Model { /// List of countries. final List countries; - CountryList({required this.total, required this.countries}); + CountryList({ + required this.total, + required this.countries, + }); factory CountryList.fromMap(Map map) { return CountryList( total: map['total'], - countries: List.from( - map['countries'].map((p) => Country.fromMap(p)), - ), + countries: + List.from(map['countries'].map((p) => Country.fromMap(p))), ); } diff --git a/lib/src/models/currency_list.dart b/lib/src/models/currency_list.dart index 7a957f1a..46377f23 100644 --- a/lib/src/models/currency_list.dart +++ b/lib/src/models/currency_list.dart @@ -8,14 +8,16 @@ class CurrencyList implements Model { /// List of currencies. final List currencies; - CurrencyList({required this.total, required this.currencies}); + CurrencyList({ + required this.total, + required this.currencies, + }); factory CurrencyList.fromMap(Map map) { return CurrencyList( total: map['total'], currencies: List.from( - map['currencies'].map((p) => Currency.fromMap(p)), - ), + map['currencies'].map((p) => Currency.fromMap(p))), ); } diff --git a/lib/src/models/document_list.dart b/lib/src/models/document_list.dart index 4065e17b..2fa82c23 100644 --- a/lib/src/models/document_list.dart +++ b/lib/src/models/document_list.dart @@ -8,14 +8,16 @@ class DocumentList implements Model { /// List of documents. final List documents; - DocumentList({required this.total, required this.documents}); + DocumentList({ + required this.total, + required this.documents, + }); factory DocumentList.fromMap(Map map) { return DocumentList( total: map['total'], - documents: List.from( - map['documents'].map((p) => Document.fromMap(p)), - ), + documents: + List.from(map['documents'].map((p) => Document.fromMap(p))), ); } diff --git a/lib/src/models/execution.dart b/lib/src/models/execution.dart index 8dfbeab6..e67bbd8a 100644 --- a/lib/src/models/execution.dart +++ b/lib/src/models/execution.dart @@ -90,13 +90,11 @@ class Execution implements Model { requestMethod: map['requestMethod'].toString(), requestPath: map['requestPath'].toString(), requestHeaders: List.from( - map['requestHeaders'].map((p) => Headers.fromMap(p)), - ), + map['requestHeaders'].map((p) => Headers.fromMap(p))), responseStatusCode: map['responseStatusCode'], responseBody: map['responseBody'].toString(), responseHeaders: List.from( - map['responseHeaders'].map((p) => Headers.fromMap(p)), - ), + map['responseHeaders'].map((p) => Headers.fromMap(p))), logs: map['logs'].toString(), errors: map['errors'].toString(), duration: map['duration'].toDouble(), diff --git a/lib/src/models/execution_list.dart b/lib/src/models/execution_list.dart index 4ed73943..5024dd66 100644 --- a/lib/src/models/execution_list.dart +++ b/lib/src/models/execution_list.dart @@ -8,14 +8,16 @@ class ExecutionList implements Model { /// List of executions. final List executions; - ExecutionList({required this.total, required this.executions}); + ExecutionList({ + required this.total, + required this.executions, + }); factory ExecutionList.fromMap(Map map) { return ExecutionList( total: map['total'], executions: List.from( - map['executions'].map((p) => Execution.fromMap(p)), - ), + map['executions'].map((p) => Execution.fromMap(p))), ); } diff --git a/lib/src/models/file_list.dart b/lib/src/models/file_list.dart index 63f49abc..1e0dcbfa 100644 --- a/lib/src/models/file_list.dart +++ b/lib/src/models/file_list.dart @@ -8,7 +8,10 @@ class FileList implements Model { /// List of files. final List files; - FileList({required this.total, required this.files}); + FileList({ + required this.total, + required this.files, + }); factory FileList.fromMap(Map map) { return FileList( @@ -18,6 +21,9 @@ class FileList implements Model { } Map toMap() { - return {"total": total, "files": files.map((p) => p.toMap()).toList()}; + return { + "total": total, + "files": files.map((p) => p.toMap()).toList(), + }; } } diff --git a/lib/src/models/headers.dart b/lib/src/models/headers.dart index 463cf696..22494998 100644 --- a/lib/src/models/headers.dart +++ b/lib/src/models/headers.dart @@ -8,7 +8,10 @@ class Headers implements Model { /// Header value. final String value; - Headers({required this.name, required this.value}); + Headers({ + required this.name, + required this.value, + }); factory Headers.fromMap(Map map) { return Headers( @@ -18,6 +21,9 @@ class Headers implements Model { } Map toMap() { - return {"name": name, "value": value}; + return { + "name": name, + "value": value, + }; } } diff --git a/lib/src/models/identity_list.dart b/lib/src/models/identity_list.dart index b4c63f7d..d63ab259 100644 --- a/lib/src/models/identity_list.dart +++ b/lib/src/models/identity_list.dart @@ -8,14 +8,16 @@ class IdentityList implements Model { /// List of identities. final List identities; - IdentityList({required this.total, required this.identities}); + IdentityList({ + required this.total, + required this.identities, + }); factory IdentityList.fromMap(Map map) { return IdentityList( total: map['total'], identities: List.from( - map['identities'].map((p) => Identity.fromMap(p)), - ), + map['identities'].map((p) => Identity.fromMap(p))), ); } diff --git a/lib/src/models/jwt.dart b/lib/src/models/jwt.dart index 490a1824..e2e31bd2 100644 --- a/lib/src/models/jwt.dart +++ b/lib/src/models/jwt.dart @@ -5,13 +5,19 @@ class Jwt implements Model { /// JWT encoded string. final String jwt; - Jwt({required this.jwt}); + Jwt({ + required this.jwt, + }); factory Jwt.fromMap(Map map) { - return Jwt(jwt: map['jwt'].toString()); + return Jwt( + jwt: map['jwt'].toString(), + ); } Map toMap() { - return {"jwt": jwt}; + return { + "jwt": jwt, + }; } } diff --git a/lib/src/models/language.dart b/lib/src/models/language.dart index 9c45adb1..b6ec6121 100644 --- a/lib/src/models/language.dart +++ b/lib/src/models/language.dart @@ -11,7 +11,11 @@ class Language implements Model { /// Language native name. final String nativeName; - Language({required this.name, required this.code, required this.nativeName}); + Language({ + required this.name, + required this.code, + required this.nativeName, + }); factory Language.fromMap(Map map) { return Language( @@ -22,6 +26,10 @@ class Language implements Model { } Map toMap() { - return {"name": name, "code": code, "nativeName": nativeName}; + return { + "name": name, + "code": code, + "nativeName": nativeName, + }; } } diff --git a/lib/src/models/language_list.dart b/lib/src/models/language_list.dart index 2e65839e..d9ab36f3 100644 --- a/lib/src/models/language_list.dart +++ b/lib/src/models/language_list.dart @@ -8,14 +8,16 @@ class LanguageList implements Model { /// List of languages. final List languages; - LanguageList({required this.total, required this.languages}); + LanguageList({ + required this.total, + required this.languages, + }); factory LanguageList.fromMap(Map map) { return LanguageList( total: map['total'], - languages: List.from( - map['languages'].map((p) => Language.fromMap(p)), - ), + languages: + List.from(map['languages'].map((p) => Language.fromMap(p))), ); } diff --git a/lib/src/models/locale_code.dart b/lib/src/models/locale_code.dart index cd5a1155..678e40c4 100644 --- a/lib/src/models/locale_code.dart +++ b/lib/src/models/locale_code.dart @@ -8,7 +8,10 @@ class LocaleCode implements Model { /// Locale name final String name; - LocaleCode({required this.code, required this.name}); + LocaleCode({ + required this.code, + required this.name, + }); factory LocaleCode.fromMap(Map map) { return LocaleCode( @@ -18,6 +21,9 @@ class LocaleCode implements Model { } Map toMap() { - return {"code": code, "name": name}; + return { + "code": code, + "name": name, + }; } } diff --git a/lib/src/models/locale_code_list.dart b/lib/src/models/locale_code_list.dart index be6ddb1f..db6cd869 100644 --- a/lib/src/models/locale_code_list.dart +++ b/lib/src/models/locale_code_list.dart @@ -8,14 +8,16 @@ class LocaleCodeList implements Model { /// List of localeCodes. final List localeCodes; - LocaleCodeList({required this.total, required this.localeCodes}); + LocaleCodeList({ + required this.total, + required this.localeCodes, + }); factory LocaleCodeList.fromMap(Map map) { return LocaleCodeList( total: map['total'], localeCodes: List.from( - map['localeCodes'].map((p) => LocaleCode.fromMap(p)), - ), + map['localeCodes'].map((p) => LocaleCode.fromMap(p))), ); } diff --git a/lib/src/models/log_list.dart b/lib/src/models/log_list.dart index 22273a8c..29399cb9 100644 --- a/lib/src/models/log_list.dart +++ b/lib/src/models/log_list.dart @@ -8,7 +8,10 @@ class LogList implements Model { /// List of logs. final List logs; - LogList({required this.total, required this.logs}); + LogList({ + required this.total, + required this.logs, + }); factory LogList.fromMap(Map map) { return LogList( @@ -18,6 +21,9 @@ class LogList implements Model { } Map toMap() { - return {"total": total, "logs": logs.map((p) => p.toMap()).toList()}; + return { + "total": total, + "logs": logs.map((p) => p.toMap()).toList(), + }; } } diff --git a/lib/src/models/membership_list.dart b/lib/src/models/membership_list.dart index a4d39dca..bcfb227c 100644 --- a/lib/src/models/membership_list.dart +++ b/lib/src/models/membership_list.dart @@ -8,14 +8,16 @@ class MembershipList implements Model { /// List of memberships. final List memberships; - MembershipList({required this.total, required this.memberships}); + MembershipList({ + required this.total, + required this.memberships, + }); factory MembershipList.fromMap(Map map) { return MembershipList( total: map['total'], memberships: List.from( - map['memberships'].map((p) => Membership.fromMap(p)), - ), + map['memberships'].map((p) => Membership.fromMap(p))), ); } diff --git a/lib/src/models/mfa_recovery_codes.dart b/lib/src/models/mfa_recovery_codes.dart index 63411988..425539e8 100644 --- a/lib/src/models/mfa_recovery_codes.dart +++ b/lib/src/models/mfa_recovery_codes.dart @@ -5,7 +5,9 @@ class MfaRecoveryCodes implements Model { /// Recovery codes. final List recoveryCodes; - MfaRecoveryCodes({required this.recoveryCodes}); + MfaRecoveryCodes({ + required this.recoveryCodes, + }); factory MfaRecoveryCodes.fromMap(Map map) { return MfaRecoveryCodes( @@ -14,6 +16,8 @@ class MfaRecoveryCodes implements Model { } Map toMap() { - return {"recoveryCodes": recoveryCodes}; + return { + "recoveryCodes": recoveryCodes, + }; } } diff --git a/lib/src/models/mfa_type.dart b/lib/src/models/mfa_type.dart index fa57cb8b..0573166e 100644 --- a/lib/src/models/mfa_type.dart +++ b/lib/src/models/mfa_type.dart @@ -8,7 +8,10 @@ class MfaType implements Model { /// URI for authenticator apps. final String uri; - MfaType({required this.secret, required this.uri}); + MfaType({ + required this.secret, + required this.uri, + }); factory MfaType.fromMap(Map map) { return MfaType( @@ -18,6 +21,9 @@ class MfaType implements Model { } Map toMap() { - return {"secret": secret, "uri": uri}; + return { + "secret": secret, + "uri": uri, + }; } } diff --git a/lib/src/models/phone_list.dart b/lib/src/models/phone_list.dart index 879edbc4..cf703f96 100644 --- a/lib/src/models/phone_list.dart +++ b/lib/src/models/phone_list.dart @@ -8,7 +8,10 @@ class PhoneList implements Model { /// List of phones. final List phones; - PhoneList({required this.total, required this.phones}); + PhoneList({ + required this.total, + required this.phones, + }); factory PhoneList.fromMap(Map map) { return PhoneList( @@ -18,6 +21,9 @@ class PhoneList implements Model { } Map toMap() { - return {"total": total, "phones": phones.map((p) => p.toMap()).toList()}; + return { + "total": total, + "phones": phones.map((p) => p.toMap()).toList(), + }; } } diff --git a/lib/src/models/preferences.dart b/lib/src/models/preferences.dart index 7bc3abc9..aa9cb4ed 100644 --- a/lib/src/models/preferences.dart +++ b/lib/src/models/preferences.dart @@ -4,14 +4,20 @@ part of '../../models.dart'; class Preferences implements Model { final Map data; - Preferences({required this.data}); + Preferences({ + required this.data, + }); factory Preferences.fromMap(Map map) { - return Preferences(data: map); + return Preferences( + data: map, + ); } Map toMap() { - return {"data": data}; + return { + "data": data, + }; } T convertTo(T Function(Map) fromJson) => fromJson(data); diff --git a/lib/src/models/row_list.dart b/lib/src/models/row_list.dart index 01f046c6..50525e63 100644 --- a/lib/src/models/row_list.dart +++ b/lib/src/models/row_list.dart @@ -8,7 +8,10 @@ class RowList implements Model { /// List of rows. final List rows; - RowList({required this.total, required this.rows}); + RowList({ + required this.total, + required this.rows, + }); factory RowList.fromMap(Map map) { return RowList( @@ -18,7 +21,10 @@ class RowList implements Model { } Map toMap() { - return {"total": total, "rows": rows.map((p) => p.toMap()).toList()}; + return { + "total": total, + "rows": rows.map((p) => p.toMap()).toList(), + }; } List convertTo(T Function(Map) fromJson) => diff --git a/lib/src/models/session_list.dart b/lib/src/models/session_list.dart index e9c478af..997a1952 100644 --- a/lib/src/models/session_list.dart +++ b/lib/src/models/session_list.dart @@ -8,14 +8,16 @@ class SessionList implements Model { /// List of sessions. final List sessions; - SessionList({required this.total, required this.sessions}); + SessionList({ + required this.total, + required this.sessions, + }); factory SessionList.fromMap(Map map) { return SessionList( total: map['total'], - sessions: List.from( - map['sessions'].map((p) => Session.fromMap(p)), - ), + sessions: + List.from(map['sessions'].map((p) => Session.fromMap(p))), ); } diff --git a/lib/src/models/team_list.dart b/lib/src/models/team_list.dart index a3994c06..351123c9 100644 --- a/lib/src/models/team_list.dart +++ b/lib/src/models/team_list.dart @@ -8,7 +8,10 @@ class TeamList implements Model { /// List of teams. final List teams; - TeamList({required this.total, required this.teams}); + TeamList({ + required this.total, + required this.teams, + }); factory TeamList.fromMap(Map map) { return TeamList( @@ -18,6 +21,9 @@ class TeamList implements Model { } Map toMap() { - return {"total": total, "teams": teams.map((p) => p.toMap()).toList()}; + return { + "total": total, + "teams": teams.map((p) => p.toMap()).toList(), + }; } } diff --git a/lib/src/realtime_io.dart b/lib/src/realtime_io.dart index 00311650..60dc68c7 100644 --- a/lib/src/realtime_io.dart +++ b/lib/src/realtime_io.dart @@ -32,11 +32,9 @@ class RealtimeIO extends RealtimeBase with RealtimeMixin { final cookies = await (client as ClientIO).cookieJar.loadForRequest(uri); headers = {HttpHeaders.cookieHeader: CookieManager.getCookies(cookies)}; - final _websok = IOWebSocketChannel( - (client as ClientIO).selfSigned - ? await _connectForSelfSignedCert(uri, headers) - : await WebSocket.connect(uri.toString(), headers: headers), - ); + final _websok = IOWebSocketChannel((client as ClientIO).selfSigned + ? await _connectForSelfSignedCert(uri, headers) + : await WebSocket.connect(uri.toString(), headers: headers)); return _websok; } @@ -52,9 +50,7 @@ class RealtimeIO extends RealtimeBase with RealtimeMixin { // https://github.com/jonataslaw/getsocket/blob/f25b3a264d8cc6f82458c949b86d286cd0343792/lib/src/io.dart#L104 // and from official dart sdk websocket_impl.dart connect method Future _connectForSelfSignedCert( - Uri uri, - Map headers, - ) async { + Uri uri, Map headers) async { try { var r = Random(); var key = base64.encode(List.generate(16, (_) => r.nextInt(255))); diff --git a/lib/src/realtime_mixin.dart b/lib/src/realtime_mixin.dart index 830b6d5e..01e76552 100644 --- a/lib/src/realtime_mixin.dart +++ b/lib/src/realtime_mixin.dart @@ -70,57 +70,53 @@ mixin RealtimeMixin { } debugPrint('subscription: $_lastUrl'); _retries = 0; - _websocketSubscription = _websok?.stream.listen( - (response) { - final data = RealtimeResponse.fromJson(response); - switch (data.type) { - case 'error': - handleError(data); - break; - case 'connected': - // channels, user? - final message = RealtimeResponseConnected.fromMap(data.data); - if (message.user.isEmpty) { - // send fallback cookie if exists - final cookie = getFallbackCookie?.call(); - if (cookie != null) { - _websok?.sink.add( - jsonEncode({ - "type": "authentication", - "data": {"session": cookie}, - }), - ); - } + _websocketSubscription = _websok?.stream.listen((response) { + final data = RealtimeResponse.fromJson(response); + switch (data.type) { + case 'error': + handleError(data); + break; + case 'connected': + // channels, user? + final message = RealtimeResponseConnected.fromMap(data.data); + if (message.user.isEmpty) { + // send fallback cookie if exists + final cookie = getFallbackCookie?.call(); + if (cookie != null) { + _websok?.sink.add(jsonEncode({ + "type": "authentication", + "data": { + "session": cookie, + }, + })); } - _startHeartbeat(); // Start heartbeat after successful connection - break; - case 'pong': - debugPrint('Received heartbeat response from realtime server'); - break; - case 'event': - final message = RealtimeMessage.fromMap(data.data); - for (var subscription in _subscriptions.values) { - for (var channel in message.channels) { - if (subscription.channels.contains(channel)) { - subscription.controller.add(message); - } + } + _startHeartbeat(); // Start heartbeat after successful connection + break; + case 'pong': + debugPrint('Received heartbeat response from realtime server'); + break; + case 'event': + final message = RealtimeMessage.fromMap(data.data); + for (var subscription in _subscriptions.values) { + for (var channel in message.channels) { + if (subscription.channels.contains(channel)) { + subscription.controller.add(message); } } - break; - } - }, - onDone: () { - _stopHeartbeat(); - _retry(); - }, - onError: (err, stack) { - _stopHeartbeat(); - for (var subscription in _subscriptions.values) { - subscription.controller.addError(err, stack); - } - _retry(); - }, - ); + } + break; + } + }, onDone: () { + _stopHeartbeat(); + _retry(); + }, onError: (err, stack) { + _stopHeartbeat(); + for (var subscription in _subscriptions.values) { + subscription.controller.addError(err, stack); + } + _retry(); + }); } catch (e) { if (e is AppwriteException) { rethrow; @@ -155,8 +151,7 @@ mixin RealtimeMixin { Uri _prepareUri() { if (client.endPointRealtime == null) { throw AppwriteException( - "Please set endPointRealtime to connect to realtime server", - ); + "Please set endPointRealtime to connect to realtime server"); } var uri = Uri.parse(client.endPointRealtime!); return Uri( @@ -177,29 +172,27 @@ mixin RealtimeMixin { Future.delayed(Duration.zero, () => _createSocket()); int id = DateTime.now().microsecondsSinceEpoch; RealtimeSubscription subscription = RealtimeSubscription( - controller: controller, - channels: channels, - close: () async { - _subscriptions.remove(id); - controller.close(); - _cleanup(channels); + controller: controller, + channels: channels, + close: () async { + _subscriptions.remove(id); + controller.close(); + _cleanup(channels); - if (_channels.isNotEmpty) { - await Future.delayed(Duration.zero, () => _createSocket()); - } else { - await _closeConnection(); - } - }, - ); + if (_channels.isNotEmpty) { + await Future.delayed(Duration.zero, () => _createSocket()); + } else { + await _closeConnection(); + } + }); _subscriptions[id] = subscription; return subscription; } void _cleanup(List channels) { for (var channel in channels) { - bool found = _subscriptions.values.any( - (subscription) => subscription.channels.contains(channel), - ); + bool found = _subscriptions.values + .any((subscription) => subscription.channels.contains(channel)); if (!found) { _channels.remove(channel); } diff --git a/lib/src/realtime_response.dart b/lib/src/realtime_response.dart index e444cd0b..b0356111 100644 --- a/lib/src/realtime_response.dart +++ b/lib/src/realtime_response.dart @@ -4,14 +4,26 @@ import 'package:flutter/foundation.dart'; class RealtimeResponse { final String type; // error, event, connected, response final Map data; - RealtimeResponse({required this.type, required this.data}); - - RealtimeResponse copyWith({String? type, Map? data}) { - return RealtimeResponse(type: type ?? this.type, data: data ?? this.data); + RealtimeResponse({ + required this.type, + required this.data, + }); + + RealtimeResponse copyWith({ + String? type, + Map? data, + }) { + return RealtimeResponse( + type: type ?? this.type, + data: data ?? this.data, + ); } Map toMap() { - return {'type': type, 'data': data}; + return { + 'type': type, + 'data': data, + }; } factory RealtimeResponse.fromMap(Map map) { diff --git a/lib/src/realtime_response_connected.dart b/lib/src/realtime_response_connected.dart index 99949587..dce0840d 100644 --- a/lib/src/realtime_response_connected.dart +++ b/lib/src/realtime_response_connected.dart @@ -4,7 +4,10 @@ import 'package:flutter/foundation.dart'; class RealtimeResponseConnected { final List channels; final Map user; - RealtimeResponseConnected({required this.channels, this.user = const {}}); + RealtimeResponseConnected({ + required this.channels, + this.user = const {}, + }); RealtimeResponseConnected copyWith({ List? channels, @@ -17,7 +20,10 @@ class RealtimeResponseConnected { } Map toMap() { - return {'channels': channels, 'user': user}; + return { + 'channels': channels, + 'user': user, + }; } factory RealtimeResponseConnected.fromMap(Map map) { diff --git a/pubspec.yaml b/pubspec.yaml index 9b82125a..62d93e2b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: appwrite -version: 18.0.0 +version: 19.0.0 description: Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API homepage: https://appwrite.io repository: https://github.com/appwrite/sdk-for-flutter diff --git a/test/query_test.dart b/test/query_test.dart index 4030bc36..4b5697bb 100644 --- a/test/query_test.dart +++ b/test/query_test.dart @@ -279,6 +279,13 @@ void main() { expect(query['method'], 'createdAfter'); }); + test('returns createdBetween', () { + final query = jsonDecode(Query.createdBetween('2023-01-01', '2023-12-31')); + expect(query['attribute'], null); + expect(query['values'], ['2023-01-01', '2023-12-31']); + expect(query['method'], 'createdBetween'); + }); + test('returns updatedBefore', () { final query = jsonDecode(Query.updatedBefore('2023-01-01')); expect(query['attribute'], null); @@ -292,4 +299,11 @@ void main() { expect(query['values'], ['2023-01-01']); expect(query['method'], 'updatedAfter'); }); + + test('returns updatedBetween', () { + final query = jsonDecode(Query.updatedBetween('2023-01-01', '2023-12-31')); + expect(query['attribute'], null); + expect(query['values'], ['2023-01-01', '2023-12-31']); + expect(query['method'], 'updatedBetween'); + }); }