Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Upgrade to Dart v2.9.3 #11

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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions .github/workflows/dart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
72 changes: 44 additions & 28 deletions cloud_firestore_server/lib/cloud_firestore_server.dart
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
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';
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';
Expand Down Expand Up @@ -47,22 +45,28 @@ class Firestore {
http.Client? innerClient,
}) async {
/// Haven't tested [ServiceAccountCredentials.applicationDefault] yet.
final _credentials =
final credentials0 =
credentials ?? ServiceAccountCredentials.applicationDefault();
Comment on lines +48 to 49
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
final credentials0 =
credentials ?? ServiceAccountCredentials.applicationDefault();
credentials =
credentials ?? ServiceAccountCredentials.applicationDefault();


return Firestore._(await createInstanceResources(
_credentials,
innerClient: innerClient,
));
return Firestore._(
await createInstanceResources(
credentials0,
innerClient: innerClient,
),
);
}

@visibleForTesting
static Future<Firestore> internal({
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);
Expand All @@ -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,
Expand All @@ -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);
}

Expand Down
16 changes: 12 additions & 4 deletions cloud_firestore_server/lib/src/bulk_writer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
5 changes: 3 additions & 2 deletions cloud_firestore_server/lib/src/collection_group.dart
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
13 changes: 5 additions & 8 deletions cloud_firestore_server/lib/src/collection_reference.dart
Original file line number Diff line number Diff line change
@@ -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]).
Expand All @@ -16,7 +13,7 @@ class CollectionReference extends Query {
CollectionReference(
InstanceResources instanceResources, {
required String path,
}) : _path = path,
}) : _path = path,
_instanceResources = instanceResources,
super(
instanceResources,
Expand Down Expand Up @@ -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.
Expand Down
37 changes: 22 additions & 15 deletions cloud_firestore_server/lib/src/document_reference.dart
Original file line number Diff line number Diff line change
@@ -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.
///
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<String, dynamic>?)?['status']
as String?,
message: e.message,
);
}
Expand Down
6 changes: 3 additions & 3 deletions cloud_firestore_server/lib/src/document_snapshot.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
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(
this.id,
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
Expand Down
9 changes: 5 additions & 4 deletions cloud_firestore_server/lib/src/field_path.dart
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<Document>> runQueryFixed(RunQueryRequest request,
{required http.Client client, required String? parent}) async {
Future<List<Document>> 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<dynamic> decoded = json.decode(resBody) as List;
final List<Map<String, dynamic>> decoded =
json.decode(resBody) as List<Map<String, dynamic>>;
if (decoded[0]['error'] != null) {
throw Exception('Firestore Error: $resBody!');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, dynamic> {
Map<String, Value> toFirestoreMap() {
Expand All @@ -15,6 +15,7 @@ extension MapToFirestoreMap on Map<String, dynamic> {
extension ToFirestoreValueList<T> on Iterable<T> {
Value toFirestoreValue() {
final arrVal = ArrayValue()
// ignore: avoid_dynamic_calls
..values = map<Value>((e) => (e as dynamic).toFirestoreValue() as Value)
.toList();
return Value()..arrayValue = arrVal;
Expand Down
Loading