diff --git a/.github/workflows/dart.yaml b/.github/workflows/dart.yaml index 933c502..2d6cc1a 100644 --- a/.github/workflows/dart.yaml +++ b/.github/workflows/dart.yaml @@ -6,31 +6,37 @@ on: pull_request: branches: [ main ] +env: + DART_VERSION: 2.19.3 + jobs: check-no-lints-and-todos: runs-on: ubuntu-latest - container: - image: google/dart:2.12-dev steps: - uses: actions/checkout@v2 + - uses: dart-lang/setup-dart@v1 + with: + sdk: ${{ env.DART_VERSION }} - name: Check for no lint Errors and no TODO comments run: ./scripts/check_for_lint_errors_and_TODO_comments.sh is-formatted: runs-on: ubuntu-latest - container: - image: google/dart:2.12-dev steps: - uses: actions/checkout@v2 + - uses: dart-lang/setup-dart@v1 + with: + sdk: ${{ env.DART_VERSION }} - name: Check that code is formatted run: ./scripts/check_code_is_formatted.sh run-remote-tests: runs-on: ubuntu-latest - container: - image: google/dart:2.12-dev steps: - uses: actions/checkout@v2 + - uses: dart-lang/setup-dart@v1 + with: + sdk: ${{ env.DART_VERSION }} - name: Run all tests that contact the remote Firestore database. env: FIRESTORE_CREDENTIALS: ${{ secrets.FIRESTORE_CREDENTIALS }} diff --git a/cloud_firestore_server/lib/cloud_firestore_server.dart b/cloud_firestore_server/lib/cloud_firestore_server.dart index e7ffd5d..c12b3aa 100644 --- a/cloud_firestore_server/lib/cloud_firestore_server.dart +++ b/cloud_firestore_server/lib/cloud_firestore_server.dart @@ -1,17 +1,16 @@ +import 'package:cloud_firestore_server/src/bulk_writer.dart'; +import 'package:cloud_firestore_server/src/collection_group.dart'; +import 'package:cloud_firestore_server/src/collection_reference.dart'; +import 'package:cloud_firestore_server/src/credentials/credentials.dart'; +import 'package:cloud_firestore_server/src/document_reference.dart'; import 'package:cloud_firestore_server/src/document_snapshot.dart'; -import 'package:meta/meta.dart'; +import 'package:cloud_firestore_server/src/internal/instance_resources.dart'; +import 'package:cloud_firestore_server/src/internal/path_string_validation.dart'; +import 'package:cloud_firestore_server/src/transaction.dart'; +import 'package:cloud_firestore_server/src/write_batch.dart'; // ignore: import_of_legacy_library_into_null_safe import 'package:http/http.dart' as http; - -import 'src/bulk_writer.dart'; -import 'src/collection_group.dart'; -import 'src/collection_reference.dart'; -import 'src/credentials/credentials.dart'; -import 'src/document_reference.dart'; -import 'src/internal/instance_resources.dart'; -import 'src/internal/path_string_validation.dart'; -import 'src/transaction.dart'; -import 'src/write_batch.dart'; +import 'package:meta/meta.dart'; export 'src/collection_group.dart'; export 'src/collection_reference.dart'; @@ -19,7 +18,6 @@ export 'src/credentials/credentials.dart'; export 'src/document_reference.dart'; export 'src/document_snapshot.dart'; export 'src/field_path.dart'; -export 'src/field_path.dart'; export 'src/firebase_exception.dart'; export 'src/precondition.dart'; export 'src/query.dart'; @@ -47,13 +45,15 @@ class Firestore { http.Client? innerClient, }) async { /// Haven't tested [ServiceAccountCredentials.applicationDefault] yet. - final _credentials = + final credentials0 = credentials ?? ServiceAccountCredentials.applicationDefault(); - return Firestore._(await createInstanceResources( - _credentials, - innerClient: innerClient, - )); + return Firestore._( + await createInstanceResources( + credentials0, + innerClient: innerClient, + ), + ); } @visibleForTesting @@ -61,8 +61,12 @@ class Firestore { String url = 'https://firestore.googleapis.com/', http.Client? innerClient, }) async { - return Firestore._(await createTestInstanceResources( - rootUrl: url, innerClient: innerClient)); + return Firestore._( + await createTestInstanceResources( + rootUrl: url, + innerClient: innerClient, + ), + ); } Firestore._(this._instanceResources); @@ -80,12 +84,18 @@ class Firestore { /// print('Added document at ${documentRef.path}'); /// ``` CollectionReference collection(String collectionPath) { - assert(collectionPath.isNotEmpty, - "a collectionPath path must be a non-empty string"); - assert(!collectionPath.contains("//"), - "a collection path must not contain '//'"); - assert(isValidCollectionPath(collectionPath), - "a collection path must point to a valid collection."); + assert( + collectionPath.isNotEmpty, + "a collectionPath path must be a non-empty string", + ); + assert( + !collectionPath.contains("//"), + "a collection path must not contain '//'", + ); + assert( + isValidCollectionPath(collectionPath), + "a collection path must point to a valid collection.", + ); return CollectionReference( _instanceResources, path: collectionPath, @@ -103,11 +113,17 @@ class Firestore { /// ``` DocumentReference doc(String documentPath) { assert( - documentPath.isNotEmpty, "a document path must be a non-empty string"); + documentPath.isNotEmpty, + "a document path must be a non-empty string", + ); assert( - !documentPath.contains("//"), "a document path must not contain '//'"); + !documentPath.contains("//"), + "a document path must not contain '//'", + ); assert( - documentPath != '/', "a document path must point to a valid document"); + documentPath != '/', + "a document path must point to a valid document", + ); return DocumentReference(_instanceResources, path: documentPath); } diff --git a/cloud_firestore_server/lib/src/bulk_writer.dart b/cloud_firestore_server/lib/src/bulk_writer.dart index 0c35f4b..1ba0cd6 100644 --- a/cloud_firestore_server/lib/src/bulk_writer.dart +++ b/cloud_firestore_server/lib/src/bulk_writer.dart @@ -31,21 +31,29 @@ class BulkWriterOptions { }) : throttlingEnabled = true { if (initialOpsPerSecond.isNegative) { throw ArgumentError.value( - initialOpsPerSecond, 'initialOpsPerSecond', "can't be negative"); + initialOpsPerSecond, + 'initialOpsPerSecond', + "can't be negative", + ); } if (maxOpsPerSecond != null) { if (maxOpsPerSecond!.isNegative) { throw ArgumentError.value( - maxOpsPerSecond, 'maxOpsPerSecond', "can't be negative"); + maxOpsPerSecond, + 'maxOpsPerSecond', + "can't be negative", + ); } if (initialOpsPerSecond > maxOpsPerSecond!) { throw ArgumentError( - "initialOpsPerSecond ($initialOpsPerSecond) can't be higher than maxOpsPerSecond ($maxOpsPerSecond)"); + "initialOpsPerSecond ($initialOpsPerSecond) can't be higher than maxOpsPerSecond ($maxOpsPerSecond)", + ); } } } } @Deprecated( - 'Unimplemented - There neeeds to be some discussion how a good native Dart Api would look like.') + 'Unimplemented - There neeeds to be some discussion how a good native Dart Api would look like.', +) class BulkWriter {} diff --git a/cloud_firestore_server/lib/src/collection_group.dart b/cloud_firestore_server/lib/src/collection_group.dart index 0c9f79e..264dda8 100644 --- a/cloud_firestore_server/lib/src/collection_group.dart +++ b/cloud_firestore_server/lib/src/collection_group.dart @@ -1,12 +1,13 @@ import 'package:cloud_firestore_server/src/internal/instance_resources.dart'; -import 'query.dart'; -import 'query_partition.dart'; +import 'package:cloud_firestore_server/src/query.dart'; +import 'package:cloud_firestore_server/src/query_partition.dart'; /// A [CollectionGroup] refers to all documents that are contained in a /// collection or subcollection with a specific collection ID. @Deprecated('Unimplemented') class CollectionGroup extends Query { + @Deprecated('Unimplemented') CollectionGroup( InstanceResources instanceResources, { required String path, diff --git a/cloud_firestore_server/lib/src/collection_reference.dart b/cloud_firestore_server/lib/src/collection_reference.dart index efd1adc..1050a59 100644 --- a/cloud_firestore_server/lib/src/collection_reference.dart +++ b/cloud_firestore_server/lib/src/collection_reference.dart @@ -1,11 +1,8 @@ import 'package:cloud_firestore_server/cloud_firestore_server.dart'; +import 'package:cloud_firestore_server/src/internal/instance_resources.dart'; +import 'package:cloud_firestore_server/src/internal/pointer.dart'; import 'package:quiver/core.dart'; -import 'document_reference.dart'; -import 'internal/instance_resources.dart'; -import 'internal/pointer.dart'; -import 'query.dart'; - /// A CollectionReference object can be used for adding documents, getting /// document references, and querying for documents (using the methods /// inherited from [Query]). @@ -16,7 +13,7 @@ class CollectionReference extends Query { CollectionReference( InstanceResources instanceResources, { required String path, - }) : _path = path, + }) : _path = path, _instanceResources = instanceResources, super( instanceResources, @@ -69,8 +66,8 @@ class CollectionReference extends Query { if (documentPath == null) { throw UnimplementedError('Automatic ID generation not implemented'); } - final _documentPath = Pointer(path).documentPath(documentPath); - return DocumentReference(_instanceResources, path: _documentPath); + final documentPath0 = Pointer(path).documentPath(documentPath); + return DocumentReference(_instanceResources, path: documentPath0); } /// Retrieves the list of documents in this collection. diff --git a/cloud_firestore_server/lib/src/document_reference.dart b/cloud_firestore_server/lib/src/document_reference.dart index 80f3df3..0fa4fb0 100644 --- a/cloud_firestore_server/lib/src/document_reference.dart +++ b/cloud_firestore_server/lib/src/document_reference.dart @@ -1,13 +1,10 @@ +import 'package:cloud_firestore_server/cloud_firestore_server.dart'; +import 'package:cloud_firestore_server/src/internal/internal.dart'; // ignore: import_of_legacy_library_into_null_safe import 'package:googleapis/firestore/v1.dart' as api; -import 'package:cloud_firestore_server/cloud_firestore_server.dart'; import 'package:meta/meta.dart'; import 'package:quiver/core.dart'; -import 'collection_reference.dart'; -import 'document_snapshot.dart'; -import 'internal/internal.dart'; - /// A DocumentReference refers to a document location in a Firestore database /// and can be used to write, read, or listen to the location. /// @@ -77,12 +74,18 @@ class DocumentReference { /// print(subcollection.path); /// ``` CollectionReference collection(String collectionPath) { - assert(collectionPath.isNotEmpty, - "a collectionPath path must be a non-empty string"); - assert(!collectionPath.contains("//"), - "a collection path must not contain '//'"); - assert(isValidCollectionPath(collectionPath), - "a collection path must point to a valid collection."); + assert( + collectionPath.isNotEmpty, + "a collectionPath path must be a non-empty string", + ); + assert( + !collectionPath.contains("//"), + "a collection path must not contain '//'", + ); + assert( + isValidCollectionPath(collectionPath), + "a collection path must point to a valid collection.", + ); return CollectionReference( _instanceResources, path: Pointer(_path).collectionPath(collectionPath), @@ -169,9 +172,12 @@ class DocumentReference { } rethrow; } - return DocumentSnapshot.existing(doc.id, doc.fields.toPrimitives(), - readTime: Timestamp.now(), - updateTime: doc.updateTime.toTimestampOrThrow()); + return DocumentSnapshot.existing( + doc.id, + doc.fields.toPrimitives(), + readTime: Timestamp.now(), + updateTime: doc.updateTime.toTimestampOrThrow(), + ); } /// Writes to the document referred to by this DocumentReference. If the @@ -264,7 +270,8 @@ class DocumentReference { // We are in the same package why does the linter complain?! // ignore: invalid_use_of_internal_member throw FirebaseException( - code: e.jsonResponse?['error']?['status'] as String?, + code: (e.jsonResponse?['error'] as Map?)?['status'] + as String?, message: e.message, ); } diff --git a/cloud_firestore_server/lib/src/document_snapshot.dart b/cloud_firestore_server/lib/src/document_snapshot.dart index 1a11fe4..7aa0954 100644 --- a/cloud_firestore_server/lib/src/document_snapshot.dart +++ b/cloud_firestore_server/lib/src/document_snapshot.dart @@ -1,5 +1,5 @@ -import 'document_reference.dart'; -import 'timestamp.dart'; +import 'package:cloud_firestore_server/src/document_reference.dart'; +import 'package:cloud_firestore_server/src/timestamp.dart'; class DocumentSnapshot { DocumentSnapshot.existing( @@ -7,7 +7,7 @@ class DocumentSnapshot { this._data, { required this.readTime, required Timestamp updateTime, - }) : exists = true, + }) : exists = true, // With this.updateTime one could pass null which is not allowed for // existing documents. // ignore: prefer_initializing_formals diff --git a/cloud_firestore_server/lib/src/field_path.dart b/cloud_firestore_server/lib/src/field_path.dart index 54dc201..ed19f84 100644 --- a/cloud_firestore_server/lib/src/field_path.dart +++ b/cloud_firestore_server/lib/src/field_path.dart @@ -1,8 +1,7 @@ +import 'package:cloud_firestore_server/src/internal/internal.dart'; import 'package:collection/collection.dart'; import 'package:quiver/core.dart'; -import 'internal/internal.dart'; - String _reserved = "Paths must not contain '~', '*', '/', '[', or ']'."; /// A [FieldPath] refers to a field in a document. @@ -16,8 +15,10 @@ class FieldPath { /// Creates a new [FieldPath]. FieldPath(this.components) : assert(components.isNotEmpty), - assert(components.where((component) => component.isEmpty).isEmpty, - "Expected all FieldPath components to be non-null or non-empty strings."); + assert( + components.where((component) => component.isEmpty).isEmpty, + "Expected all FieldPath components to be non-null or non-empty strings.", + ); /// Returns a special sentinel `FieldPath` to refer to the ID of a document. /// diff --git a/cloud_firestore_server/lib/src/internal/firestore_run_query_fixed_extension.dart b/cloud_firestore_server/lib/src/internal/firestore_run_query_fixed_extension.dart index 0b0ff67..045803f 100644 --- a/cloud_firestore_server/lib/src/internal/firestore_run_query_fixed_extension.dart +++ b/cloud_firestore_server/lib/src/internal/firestore_run_query_fixed_extension.dart @@ -32,15 +32,19 @@ extension FirestoreRunQueryFixedExtension /// /// If the used [http.Client] completes with an error when making a REST call, /// this method will complete with the same error. - Future> runQueryFixed(RunQueryRequest request, - {required http.Client client, required String? parent}) async { + Future> runQueryFixed( + RunQueryRequest request, { + required http.Client client, + required String? parent, + }) async { final urlParentAddition = parent != null ? '/$parent' : ''; final url = 'https://firestore.googleapis.com/v1/projects/sharezone-debug/databases/(default)/documents$urlParentAddition:runQuery'; final body = json.encode(request.toJson()); final response = await client.post(url, body: body); final resBody = response.body; - final List decoded = json.decode(resBody) as List; + final List> decoded = + json.decode(resBody) as List>; if (decoded[0]['error'] != null) { throw Exception('Firestore Error: $resBody!'); } diff --git a/cloud_firestore_server/lib/src/internal/firestore_value_conversion.dart b/cloud_firestore_server/lib/src/internal/firestore_value_conversion.dart index f4ed800..5edd076 100644 --- a/cloud_firestore_server/lib/src/internal/firestore_value_conversion.dart +++ b/cloud_firestore_server/lib/src/internal/firestore_value_conversion.dart @@ -1,6 +1,6 @@ +import 'package:cloud_firestore_server/src/internal/internal.dart'; // ignore: import_of_legacy_library_into_null_safe import 'package:googleapis/firestore/v1.dart'; -import 'internal.dart'; extension MapToFirestoreMap on Map { Map toFirestoreMap() { @@ -15,6 +15,7 @@ extension MapToFirestoreMap on Map { extension ToFirestoreValueList on Iterable { Value toFirestoreValue() { final arrVal = ArrayValue() + // ignore: avoid_dynamic_calls ..values = map((e) => (e as dynamic).toFirestoreValue() as Value) .toList(); return Value()..arrayValue = arrVal; diff --git a/cloud_firestore_server/lib/src/internal/instance_resources.dart b/cloud_firestore_server/lib/src/internal/instance_resources.dart index ee6a0d4..dcc25a6 100644 --- a/cloud_firestore_server/lib/src/internal/instance_resources.dart +++ b/cloud_firestore_server/lib/src/internal/instance_resources.dart @@ -1,7 +1,5 @@ import 'package:cloud_firestore_server/src/credentials/credentials.dart'; // ignore: import_of_legacy_library_into_null_safe -import 'package:googleapis_auth/auth.dart' as googleapis_auth; -// ignore: import_of_legacy_library_into_null_safe import 'package:googleapis/firestore/v1.dart'; // ignore: import_of_legacy_library_into_null_safe import 'package:googleapis_auth/auth_io.dart' as googleapis_auth; @@ -30,13 +28,14 @@ Future createInstanceResources( ServiceAccountCredentials credentials, { http.Client? innerClient, }) async { - final _creds = googleapis_auth.ServiceAccountCredentials( - credentials.email, - googleapis_auth.ClientId.serviceAccount(credentials.clientId), - credentials.privateKey); + final creds = googleapis_auth.ServiceAccountCredentials( + credentials.email, + googleapis_auth.ClientId.serviceAccount(credentials.clientId), + credentials.privateKey, + ); final client = await googleapis_auth.clientViaServiceAccount( - _creds, + creds, [FirestoreApi.DatastoreScope], baseClient: innerClient, ); diff --git a/cloud_firestore_server/lib/src/internal/path_string_validation.dart b/cloud_firestore_server/lib/src/internal/path_string_validation.dart index 9b65548..079d650 100644 --- a/cloud_firestore_server/lib/src/internal/path_string_validation.dart +++ b/cloud_firestore_server/lib/src/internal/path_string_validation.dart @@ -1,4 +1,4 @@ -import 'pointer.dart'; +import 'package:cloud_firestore_server/src/internal/pointer.dart'; /// Helper method exposed to determine whether a given [collectionPath] points to /// a valid Firestore collection. diff --git a/cloud_firestore_server/lib/src/internal/pointer.dart b/cloud_firestore_server/lib/src/internal/pointer.dart index 6cc3576..045b0b5 100644 --- a/cloud_firestore_server/lib/src/internal/pointer.dart +++ b/cloud_firestore_server/lib/src/internal/pointer.dart @@ -32,7 +32,7 @@ class Pointer { /// Collections are paths whose components are not dividable by 2, for example /// "collection/document/sub-collection". bool isCollection() { - return components.length % 2 == 1; + return components.length.isOdd; } /// Returns whether the given path is a pointer to a Firestore document. @@ -40,7 +40,7 @@ class Pointer { /// Documents are paths whose components are dividable by 2, for example /// "collection/document". bool isDocument() { - return components.length % 2 == 0; + return components.length.isEven; } /// Returns a new collection path from the current document pointer. diff --git a/cloud_firestore_server/lib/src/internal/run_query.dart b/cloud_firestore_server/lib/src/internal/run_query.dart index 284b8fc..dba0c02 100644 --- a/cloud_firestore_server/lib/src/internal/run_query.dart +++ b/cloud_firestore_server/lib/src/internal/run_query.dart @@ -1,9 +1,9 @@ +import 'package:cloud_firestore_server/src/internal/firestore_run_query_fixed_extension.dart'; +import 'package:cloud_firestore_server/src/internal/firestore_value_conversion.dart'; // ignore: import_of_legacy_library_into_null_safe import 'package:googleapis/firestore/v1.dart'; // ignore: import_of_legacy_library_into_null_safe import 'package:http/http.dart' as http; -import 'firestore_run_query_fixed_extension.dart'; -import 'firestore_value_conversion.dart'; Future> runQuery({ required String fieldPath, @@ -30,8 +30,11 @@ Future> runQuery({ } final runQueryRequest = RunQueryRequest()..structuredQuery = structuredQuery; - final documents = await api.runQueryFixed(runQueryRequest, - client: client, parent: parentPath); + final documents = await api.runQueryFixed( + runQueryRequest, + client: client, + parent: parentPath, + ); return documents; } @@ -62,8 +65,11 @@ Future> runMultiConditionQuery({ ..from = [CollectionSelector()..collectionId = collectionId]; final runQueryRequest = RunQueryRequest()..structuredQuery = structuredQuery; - final documents = await api.runQueryFixed(runQueryRequest, - client: client, parent: parentPath); + final documents = await api.runQueryFixed( + runQueryRequest, + client: client, + parent: parentPath, + ); return documents; } diff --git a/cloud_firestore_server/lib/src/internal/serilization_and_deserilization/src/enum.dart b/cloud_firestore_server/lib/src/internal/serilization_and_deserilization/src/enum.dart index b591b6f..a5b38de 100644 --- a/cloud_firestore_server/lib/src/internal/serilization_and_deserilization/src/enum.dart +++ b/cloud_firestore_server/lib/src/internal/serilization_and_deserilization/src/enum.dart @@ -1,9 +1,9 @@ -T? enumFromString(List values, dynamic? json, {T? orElse}) => json != null +T? enumFromString(List values, dynamic json, {T? orElse}) => json != null ? values.firstWhere( (it) => - '$it'.split(".")[1].toString().toLowerCase() == - json.toString().toLowerCase(), - orElse: orElse != null ? () => orElse : null) + '$it'.split(".")[1].toLowerCase() == json.toString().toLowerCase(), + orElse: orElse != null ? () => orElse : null, + ) : orElse; String enumToString(T value) => value.toString().split('.')[1]; diff --git a/cloud_firestore_server/lib/src/internal/serilization_and_deserilization/src/list.dart b/cloud_firestore_server/lib/src/internal/serilization_and_deserilization/src/list.dart index 85a219d..1073599 100644 --- a/cloud_firestore_server/lib/src/internal/serilization_and_deserilization/src/list.dart +++ b/cloud_firestore_server/lib/src/internal/serilization_and_deserilization/src/list.dart @@ -21,7 +21,7 @@ typedef ObjectListBuilder = T Function(dynamic decodedMapValue); /// //... /// ); /// ``` -List decodeList(dynamic? data, ObjectListBuilder builder) { +List decodeList(dynamic data, ObjectListBuilder builder) { if (data == null) return []; final originaldata = data as List; return originaldata.map((dynamic value) => builder(value)).toList(); diff --git a/cloud_firestore_server/lib/src/internal/serilization_and_deserilization/src/timestamp.dart b/cloud_firestore_server/lib/src/internal/serilization_and_deserilization/src/timestamp.dart index 877131b..125fdab 100644 --- a/cloud_firestore_server/lib/src/internal/serilization_and_deserilization/src/timestamp.dart +++ b/cloud_firestore_server/lib/src/internal/serilization_and_deserilization/src/timestamp.dart @@ -1,6 +1,6 @@ import 'package:cloud_firestore_server/cloud_firestore_server.dart'; -import 'datetime.dart'; +import 'package:cloud_firestore_server/src/internal/serilization_and_deserilization/src/datetime.dart'; extension StringToTimestamp on String { Timestamp toTimestampOrThrow() => _toTimestamp(this); diff --git a/cloud_firestore_server/lib/src/precondition.dart b/cloud_firestore_server/lib/src/precondition.dart index 7c7fab9..0f5d9a3 100644 --- a/cloud_firestore_server/lib/src/precondition.dart +++ b/cloud_firestore_server/lib/src/precondition.dart @@ -1,4 +1,4 @@ -import 'timestamp.dart'; +import 'package:cloud_firestore_server/src/timestamp.dart'; class Precondition { final bool? exists; diff --git a/cloud_firestore_server/lib/src/query.dart b/cloud_firestore_server/lib/src/query.dart index d1f38fd..ebf9a24 100644 --- a/cloud_firestore_server/lib/src/query.dart +++ b/cloud_firestore_server/lib/src/query.dart @@ -1,9 +1,7 @@ +import 'package:cloud_firestore_server/cloud_firestore_server.dart'; +import 'package:cloud_firestore_server/src/internal/internal.dart'; // ignore: import_of_legacy_library_into_null_safe import 'package:googleapis/firestore/v1.dart' as api; -import 'package:cloud_firestore_server/cloud_firestore_server.dart'; -import 'internal/internal.dart'; -import 'query_document_snapshot.dart'; -import 'query_snapshot.dart'; enum OrderDirection { ascending, @@ -67,12 +65,15 @@ class Query { bool? isNull, }) { return _copyWith( - conditions: List.from(_conditions) - ..add(Condition( + conditions: List.from(_conditions) + ..add( + Condition( fieldPath: field as String, operation: arrayContains != null ? 'ARRAY_CONTAINS' : 'EQUAL', value: arrayContains ?? isEqualTo, - ))); + ), + ), + ); } /// Creates and returns a new [Query] that applies a field mask to the result @@ -120,8 +121,10 @@ class Query { /// } /// ``` @Deprecated('Unimplemented') - Query orderBy(dynamic fieldPath, - {OrderDirection direction = OrderDirection.ascending}) { + Query orderBy( + dynamic fieldPath, { + OrderDirection direction = OrderDirection.ascending, + }) { throw UnimplementedError(); } @@ -343,12 +346,14 @@ class Query { QuerySnapshot _docsToQuerySnapshot(List docs) { final queryDocs = docs - .map((doc) => QueryDocumentSnapshot( - doc.id, - doc.fields.toPrimitives(), - readTime: Timestamp.now(), - updateTime: doc.updateTime.toTimestampOrThrow(), - )) + .map( + (doc) => QueryDocumentSnapshot( + doc.id, + doc.fields.toPrimitives(), + readTime: Timestamp.now(), + updateTime: doc.updateTime.toTimestampOrThrow(), + ), + ) .toList(); return QuerySnapshot(queryDocs); } diff --git a/cloud_firestore_server/lib/src/query_document_snapshot.dart b/cloud_firestore_server/lib/src/query_document_snapshot.dart index 9a461ba..ec4f72f 100644 --- a/cloud_firestore_server/lib/src/query_document_snapshot.dart +++ b/cloud_firestore_server/lib/src/query_document_snapshot.dart @@ -1,5 +1,5 @@ -import 'document_snapshot.dart'; -import 'timestamp.dart'; +import 'package:cloud_firestore_server/src/document_snapshot.dart'; +import 'package:cloud_firestore_server/src/timestamp.dart'; class QueryDocumentSnapshot extends DocumentSnapshot { QueryDocumentSnapshot( diff --git a/cloud_firestore_server/lib/src/query_partition.dart b/cloud_firestore_server/lib/src/query_partition.dart index 2023d38..6764b45 100644 --- a/cloud_firestore_server/lib/src/query_partition.dart +++ b/cloud_firestore_server/lib/src/query_partition.dart @@ -1,4 +1,4 @@ -import 'query.dart'; +import 'package:cloud_firestore_server/src/query.dart'; /// A split point that can be used in a query as a starting and/or end point for /// the query results. The cursors returned by {@link #startAt} and {@link @@ -6,7 +6,11 @@ import 'query.dart'; /// that produced this partition. @Deprecated('Unimplemented') class QueryPartition { - QueryPartition(this.startAt, this.endBefore); + @Deprecated('Unimplemented') + QueryPartition( + @Deprecated('Unimplemented') this.startAt, + @Deprecated('Unimplemented') this.endBefore, + ); /// The cursor that defines the first result for this partition or `null` /// if this is the first partition. The cursor value must be diff --git a/cloud_firestore_server/lib/src/query_snapshot.dart b/cloud_firestore_server/lib/src/query_snapshot.dart index 960d8ea..a4620f2 100644 --- a/cloud_firestore_server/lib/src/query_snapshot.dart +++ b/cloud_firestore_server/lib/src/query_snapshot.dart @@ -1,4 +1,4 @@ -import 'query_document_snapshot.dart'; +import 'package:cloud_firestore_server/src/query_document_snapshot.dart'; class QuerySnapshot { final List docs; diff --git a/cloud_firestore_server/lib/src/timestamp.dart b/cloud_firestore_server/lib/src/timestamp.dart index 56ce7ca..57e7441 100644 --- a/cloud_firestore_server/lib/src/timestamp.dart +++ b/cloud_firestore_server/lib/src/timestamp.dart @@ -28,14 +28,14 @@ class Timestamp implements Comparable { /// Create a [Timestamp] fromMillisecondsSinceEpoch factory Timestamp.fromMillisecondsSinceEpoch(int milliseconds) { - final int seconds = (milliseconds ~/ _kThousand).floor(); + final int seconds = milliseconds ~/ _kThousand; final int nanoseconds = (milliseconds - seconds * _kThousand) * _kMillion; return Timestamp(seconds, nanoseconds); } /// Create a [Timestamp] fromMicrosecondsSinceEpoch factory Timestamp.fromMicrosecondsSinceEpoch(int microseconds) { - final int seconds = (microseconds ~/ _kMillion).floor(); + final int seconds = microseconds ~/ _kMillion; final int nanoseconds = (microseconds - seconds * _kMillion) * _kThousand; return Timestamp(seconds, nanoseconds); } @@ -48,7 +48,8 @@ class Timestamp implements Comparable { /// Create a [Timestamp] from [DateTime].now() factory Timestamp.now() { return Timestamp.fromMicrosecondsSinceEpoch( - DateTime.now().microsecondsSinceEpoch); + DateTime.now().microsecondsSinceEpoch, + ); } final int _seconds; diff --git a/cloud_firestore_server/lib/src/transaction.dart b/cloud_firestore_server/lib/src/transaction.dart index dc289e5..81e1488 100644 --- a/cloud_firestore_server/lib/src/transaction.dart +++ b/cloud_firestore_server/lib/src/transaction.dart @@ -1,8 +1,8 @@ -import 'document_reference.dart'; -import 'document_snapshot.dart'; -import 'precondition.dart'; -import 'query.dart'; -import 'query_snapshot.dart'; +import 'package:cloud_firestore_server/src/document_reference.dart'; +import 'package:cloud_firestore_server/src/document_snapshot.dart'; +import 'package:cloud_firestore_server/src/precondition.dart'; +import 'package:cloud_firestore_server/src/query.dart'; +import 'package:cloud_firestore_server/src/query_snapshot.dart'; /// A reference to a transaction. /// @@ -82,7 +82,9 @@ class Transaction { /// ``` @Deprecated('Unimplemented') Transaction create( - DocumentReference documentReference, Map data) { + DocumentReference documentReference, + Map data, + ) { throw UnimplementedError(); } @@ -132,7 +134,9 @@ class Transaction { /// ``` @Deprecated('Unimplemented') Transaction update( - DocumentReference documentReference, Map data) { + DocumentReference documentReference, + Map data, + ) { throw UnimplementedError(); } @@ -153,8 +157,10 @@ class Transaction { /// }); /// ``` @Deprecated('Unimplemented') - Transaction delete(DocumentReference documentReference, - {Precondition? precondition}) { + Transaction delete( + DocumentReference documentReference, { + Precondition? precondition, + }) { throw UnimplementedError(); } } diff --git a/cloud_firestore_server/lib/src/write_batch.dart b/cloud_firestore_server/lib/src/write_batch.dart index 6f8deb3..8855e16 100644 --- a/cloud_firestore_server/lib/src/write_batch.dart +++ b/cloud_firestore_server/lib/src/write_batch.dart @@ -1,5 +1,5 @@ -import 'document_reference.dart'; -import 'precondition.dart'; +import 'package:cloud_firestore_server/src/document_reference.dart'; +import 'package:cloud_firestore_server/src/precondition.dart'; /// A Firestore [WriteBatch] that can be used to atomically commit multiple /// write operations at once. @@ -49,8 +49,10 @@ class WriteBatch { /// print('Successfully executed batch.'); /// ``` @Deprecated('Unimplemented') - WriteBatch delete(DocumentReference documentRef, - {Precondition? precondition}) { + WriteBatch delete( + DocumentReference documentRef, { + Precondition? precondition, + }) { throw UnimplementedError(); } diff --git a/cloud_firestore_server/test/document_reference_test.dart b/cloud_firestore_server/test/document_reference_test.dart index 4af5f2f..ea3c053 100644 --- a/cloud_firestore_server/test/document_reference_test.dart +++ b/cloud_firestore_server/test/document_reference_test.dart @@ -29,6 +29,7 @@ Future main() async { // Act try { await docRef.delete(precondition: Precondition(exists: true)); + // ignore: use_test_throws_matchers fail('Should throw'); } catch (e) { final exception = e as FirebaseException; @@ -44,7 +45,8 @@ Future main() async { // Act final exec = () => docRef.delete( - precondition: Precondition(lastUpdateTime: Timestamp.now())); + precondition: Precondition(lastUpdateTime: Timestamp.now()), + ); // Assert expect(exec, throwsA(isA())); @@ -63,7 +65,8 @@ Future main() async { // Act await docRef.delete( - precondition: Precondition(lastUpdateTime: updateTime)); + precondition: Precondition(lastUpdateTime: updateTime), + ); // Assert final deletedDoc = await docRef.get(); diff --git a/cloud_firestore_server/test/inner_http_client_test.dart b/cloud_firestore_server/test/inner_http_client_test.dart index 8275915..229956b 100644 --- a/cloud_firestore_server/test/inner_http_client_test.dart +++ b/cloud_firestore_server/test/inner_http_client_test.dart @@ -15,34 +15,47 @@ import 'package:test/test.dart'; /// Locally the remote tests can be skipped via /// `dart --no-sound-null-safety test --exclude-tags remote`. ServiceAccountCredentials getCredentialsFromEnvironment() { - final _creds = Platform.environment['FIRESTORE_CREDENTIALS']; - if (_creds == null) { + final creds = Platform.environment['FIRESTORE_CREDENTIALS']; + if (creds == null) { throw ArgumentError( 'The environment variable "FIRESTORE_CREDENTIALS" does not have the firestore service account credentials. This environment variable is usually provided via Github Secrets.\n' 'If you develop locally you should run only the tests that dont need the credentials. You can do this by running "dart --no-sound-null-safety test --exclude-tags remote".'); } - return ServiceAccountCredentials.fromJson(_creds); + return ServiceAccountCredentials.fromJson(creds); } Future main() async { /// We seperate both as the remote tests can only be run on Github Actions as /// locally one might not have the necessary credentials. - group('(using Emulator)', () { - runTests((innerClient) => Firestore.internal( + group( + '(using Emulator)', + () { + runTests( + (innerClient) => Firestore.internal( url: 'http://localhost:8080/', innerClient: innerClient, - )); - }, tags: 'emulator'); - group('(using remote Firestore)', () { - runTests((innerClient) => Firestore.newInstance( + ), + ); + }, + tags: 'emulator', + ); + group( + '(using remote Firestore)', + () { + runTests( + (innerClient) => Firestore.newInstance( credentials: getCredentialsFromEnvironment(), innerClient: innerClient, - )); - }, tags: 'remote'); + ), + ); + }, + tags: 'remote', + ); } void runTests( - Future Function(SpyingClient innerClient) setupFirestore) { + Future Function(SpyingClient innerClient) setupFirestore, +) { group('innerClient', () { late Firestore firestore; late SpyingClient innerClient;