-
Notifications
You must be signed in to change notification settings - Fork 4k
[cloud_firestore] Created firestore platform interface #1686
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
Merged
ditman
merged 21 commits into
firebase:master
from
amrfarid140:firestore_web/platform_interface
Feb 5, 2020
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
0803aef
Created firestore platform interface
amrfarid140 3c57adb
Fixes for multiple apps support
amrfarid140 e309a8e
Fixed format issues
amrfarid140 0c7ccf1
Fix lint issues and remove analysis_options.yml
amrfarid140 d1898fd
Fix typo
amrfarid140 6ce4a4b
Fix analyze issues
amrfarid140 872959d
Added visiblefortesting annotation
amrfarid140 41d5117
Appease analyzer
ditman e53dad1
use instanceFor
amrfarid140 a6b319b
Apply suggestions for cloud_firestore_platform_interface
amrfarid140 5dea377
Merge remote-tracking branch 'origin/firestore_web/platform_interface…
amrfarid140 89d0ddb
add visible for testing annotation on `channel`
amrfarid140 b0e5c5e
Apply suggestions from code review
amrfarid140 49abc85
Merge remote-tracking branch 'origin/firestore_web/platform_interface…
amrfarid140 41e9d92
Formatting fixes
amrfarid140 8747a19
make transaction finish as private
amrfarid140 6f34bec
Use correct Type for Transaction and WriteBatch & revert privatisation
amrfarid140 e2faaaf
Expose transaction finish as ppublic
amrfarid140 595b747
Fixed documentation comments
amrfarid140 8933d26
Added latest changes from @ditman and @collinjackson
amrfarid140 e09e384
Merge branch 'master' of github.com:FirebaseExtended/flutterfire into…
amrfarid140 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
packages/cloud_firestore/cloud_firestore_platform_interface/.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Miscellaneous | ||
*.class | ||
*.log | ||
*.pyc | ||
*.swp | ||
.DS_Store | ||
.atom/ | ||
.buildlog/ | ||
.history | ||
.svn/ | ||
|
||
# IntelliJ related | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea/ | ||
.metadata | ||
|
||
# The .vscode folder contains launch configuration and tasks you configure in | ||
# VS Code which you may wish to be included in version control, so this line | ||
# is commented out by default. | ||
#.vscode/ | ||
|
||
# Flutter/Dart/Pub related | ||
**/doc/api/ | ||
.dart_tool/ | ||
.flutter-plugins | ||
.flutter-plugins-dependencies | ||
.packages | ||
.pub-cache/ | ||
.pub/ | ||
build/ | ||
|
||
# Android related | ||
**/android/**/gradle-wrapper.jar | ||
**/android/.gradle | ||
**/android/captures/ | ||
**/android/gradlew | ||
**/android/gradlew.bat | ||
**/android/local.properties | ||
**/android/**/GeneratedPluginRegistrant.java | ||
|
||
# iOS/XCode related | ||
**/ios/**/*.mode1v3 | ||
**/ios/**/*.mode2v3 | ||
**/ios/**/*.moved-aside | ||
**/ios/**/*.pbxuser | ||
**/ios/**/*.perspectivev3 | ||
**/ios/**/*sync/ | ||
**/ios/**/.sconsign.dblite | ||
**/ios/**/.tags* | ||
**/ios/**/.vagrant/ | ||
**/ios/**/DerivedData/ | ||
**/ios/**/Icon? | ||
**/ios/**/Pods/ | ||
**/ios/**/.symlinks/ | ||
**/ios/**/profile | ||
**/ios/**/xcuserdata | ||
**/ios/.generated/ | ||
**/ios/Flutter/App.framework | ||
**/ios/Flutter/Flutter.framework | ||
**/ios/Flutter/Flutter.podspec | ||
**/ios/Flutter/Generated.xcconfig | ||
**/ios/Flutter/app.flx | ||
**/ios/Flutter/app.zip | ||
**/ios/Flutter/flutter_assets/ | ||
**/ios/Flutter/flutter_export_environment.sh | ||
**/ios/ServiceDefinitions.json | ||
**/ios/Runner/GeneratedPluginRegistrant.* | ||
|
||
# Exceptions to above rules. | ||
!**/ios/**/default.mode1v3 | ||
!**/ios/**/default.mode2v3 | ||
!**/ios/**/default.pbxuser | ||
!**/ios/**/default.perspectivev3 | ||
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages |
3 changes: 3 additions & 0 deletions
3
packages/cloud_firestore/cloud_firestore_platform_interface/CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## [1.0.0] | ||
|
||
* Created Platform Interface |
26 changes: 26 additions & 0 deletions
26
packages/cloud_firestore/cloud_firestore_platform_interface/LICENSE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Copyright 2017, the Chromium project authors. All rights reserved. | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are | ||
met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following | ||
disclaimer in the documentation and/or other materials provided | ||
with the distribution. | ||
* Neither the name of Google Inc. nor the names of its | ||
contributors may be used to endorse or promote products derived | ||
from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 changes: 26 additions & 0 deletions
26
packages/cloud_firestore/cloud_firestore_platform_interface/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# cloud_firestore_platform_interface | ||
|
||
A common platform interface for the [`cloud_firestore`][1] plugin. | ||
|
||
This interface allows platform-specific implementations of the `cloud_firestore` | ||
plugin, as well as the plugin itself, to ensure they are supporting the | ||
same interface. | ||
|
||
# Usage | ||
|
||
To implement a new platform-specific implementation of `cloud_firebase`, extend | ||
[`FirestorePlatform`][2] with an implementation that performs the | ||
platform-specific behavior, and when you register your plugin, set the default | ||
`FirestorePlatform` by calling | ||
`FirestorePlatform.instance = MyFirestore()`. | ||
|
||
# Note on breaking changes | ||
|
||
Strongly prefer non-breaking changes (such as adding a method to the interface) | ||
over breaking changes for this package. | ||
|
||
See https://flutter.dev/go/platform-interface-breaking-changes for a discussion | ||
on why a less-clean interface is preferable to a breaking change. | ||
|
||
[1]: ../cloud_firestore | ||
[2]: lib/cloud_firestore_platform_interface.dart |
156 changes: 156 additions & 0 deletions
156
..._firestore/cloud_firestore_platform_interface/lib/cloud_firestore_platform_interface.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
// Copyright 2017, the Chromium project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
library cloud_firestore_platform_interface; | ||
|
||
import 'dart:async'; | ||
|
||
import 'package:firebase_core/firebase_core.dart'; | ||
import 'package:plugin_platform_interface/plugin_platform_interface.dart'; | ||
|
||
import 'src/method_channel/method_channel_firestore.dart'; | ||
|
||
import 'src/platform_interface/collection_reference.dart'; | ||
import 'src/platform_interface/document_reference.dart'; | ||
import 'src/platform_interface/query.dart'; | ||
import 'src/platform_interface/transaction.dart'; | ||
import 'src/platform_interface/write_batch.dart'; | ||
|
||
// Shared types | ||
export 'src/blob.dart'; | ||
export 'src/document_snapshot.dart'; | ||
export 'src/field_path.dart'; | ||
export 'src/geo_point.dart'; | ||
export 'src/snapshot_metadata.dart'; | ||
export 'src/source.dart'; | ||
export 'src/timestamp.dart'; | ||
|
||
// Platform interface parts | ||
export 'src/platform_interface/collection_reference.dart'; | ||
export 'src/platform_interface/document_change.dart'; | ||
export 'src/platform_interface/document_reference.dart'; | ||
export 'src/platform_interface/field_value_factory.dart'; | ||
export 'src/platform_interface/query.dart'; | ||
export 'src/platform_interface/query_snapshot.dart'; | ||
export 'src/platform_interface/transaction.dart'; | ||
export 'src/platform_interface/write_batch.dart'; | ||
|
||
/// Defines an interface to work with [FirestorePlatform] on web and mobile | ||
abstract class FirestorePlatform extends PlatformInterface { | ||
/// The app associated with this Firestore instance. | ||
final FirebaseApp app; | ||
|
||
/// Create an instance using [app] | ||
FirestorePlatform({FirebaseApp app}) | ||
: app = app ?? FirebaseApp.instance, | ||
super(token: _token); | ||
|
||
static final Object _token = Object(); | ||
|
||
/// Create an instance using [app] using the existing implementation | ||
factory FirestorePlatform.instanceFor({FirebaseApp app}) { | ||
return FirestorePlatform.instance.withApp(app); | ||
} | ||
|
||
/// The current default [FirestorePlatform] instance. | ||
/// | ||
/// It will always default to [MethodChannelFirestore] | ||
/// if no web implementation was provided. | ||
static FirestorePlatform get instance { | ||
if (_instance == null) { | ||
_instance = MethodChannelFirestore(); | ||
} | ||
return _instance; | ||
} | ||
|
||
static FirestorePlatform _instance; | ||
|
||
/// Sets the [FirestorePlatform.instance] | ||
static set instance(FirestorePlatform instance) { | ||
PlatformInterface.verifyToken(instance, _token); | ||
_instance = instance; | ||
} | ||
|
||
/// Create a new [FirestorePlatform] with a [FirebaseApp] instance | ||
FirestorePlatform withApp(FirebaseApp app) { | ||
throw UnimplementedError("withApp() not implemented"); | ||
} | ||
|
||
/// Gets a [CollectionReferencePlatform] for the specified Firestore path. | ||
CollectionReferencePlatform collection(String path) { | ||
throw UnimplementedError('collection() is not implemented'); | ||
} | ||
|
||
/// Gets a [QueryPlatform] for the specified collection group. | ||
QueryPlatform collectionGroup(String path) { | ||
throw UnimplementedError('collectionGroup() is not implemented'); | ||
} | ||
|
||
/// Gets a [DocumentReferencePlatform] for the specified Firestore path. | ||
DocumentReferencePlatform document(String path) { | ||
throw UnimplementedError('document() is not implemented'); | ||
} | ||
|
||
/// Creates a write batch, used for performing multiple writes as a single | ||
/// atomic operation. | ||
/// | ||
/// Unlike transactions, write batches are persisted offline and therefore are | ||
/// preferable when you don’t need to condition your writes on read data. | ||
WriteBatchPlatform batch() { | ||
throw UnimplementedError('batch() is not implemented'); | ||
} | ||
|
||
/// Executes the given [TransactionHandler] and then attempts to commit the | ||
/// changes applied within an atomic transaction. | ||
/// | ||
/// In the [TransactionHandler], a set of reads and writes can be performed | ||
/// atomically using the [MethodChannelTransaction] object passed to the [TransactionHandler]. | ||
/// After the [TransactionHandler] is run, Firestore will attempt to apply the | ||
/// changes to the server. If any of the data read has been modified outside | ||
/// of this transaction since being read, then the transaction will be | ||
/// retried by executing the updateBlock again. If the transaction still | ||
/// fails after 5 retries, then the transaction will fail. | ||
/// | ||
/// The [TransactionHandler] may be executed multiple times, it should be able | ||
/// to handle multiple executions. | ||
/// | ||
/// Data accessed with the transaction will not reflect local changes that | ||
/// have not been committed. For this reason, it is required that all | ||
/// reads are performed before any writes. Transactions must be performed | ||
/// while online. Otherwise, reads will fail, and the final commit will fail. | ||
/// | ||
/// By default transactions are limited to 5 seconds of execution time. This | ||
/// timeout can be adjusted by setting the timeout parameter. | ||
Future<Map<String, dynamic>> runTransaction( | ||
TransactionHandler transactionHandler, | ||
{Duration timeout = const Duration(seconds: 5)}) async { | ||
throw UnimplementedError('runTransaction() is not implemented'); | ||
} | ||
|
||
@deprecated | ||
// Suppressing due to deprecation | ||
// ignore: public_member_api_docs | ||
Future<void> enablePersistence(bool enable) async { | ||
throw UnimplementedError('enablePersistence() is not implemented'); | ||
} | ||
|
||
/// Setup [FirestorePlatform] with settings. | ||
/// | ||
/// If [sslEnabled] has a non-null value, the [host] must have non-null value as well. | ||
/// | ||
/// If [cacheSizeBytes] is `null`, then default values are used. | ||
Future<void> settings( | ||
{bool persistenceEnabled, | ||
String host, | ||
bool sslEnabled, | ||
int cacheSizeBytes}) async { | ||
throw UnimplementedError('settings() is not implemented'); | ||
} | ||
|
||
@override | ||
int get hashCode => app.name.hashCode; | ||
|
||
@override | ||
bool operator ==(dynamic o) => o is FirestorePlatform && o.app == app; | ||
} |
25 changes: 25 additions & 0 deletions
25
packages/cloud_firestore/cloud_firestore_platform_interface/lib/src/blob.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2017, the Chromium project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'dart:typed_data'; | ||
import 'dart:ui'; | ||
|
||
import 'package:collection/collection.dart'; | ||
|
||
/// Represents binary data stored in [Uint8List]. | ||
class Blob { | ||
/// Create a blob. | ||
const Blob(this.bytes); | ||
|
||
/// The bytes that are contained in this blob. | ||
final Uint8List bytes; | ||
|
||
@override | ||
bool operator ==(dynamic other) => | ||
other is Blob && | ||
const DeepCollectionEquality().equals(other.bytes, bytes); | ||
|
||
@override | ||
int get hashCode => hashList(bytes); | ||
} |
39 changes: 39 additions & 0 deletions
39
packages/cloud_firestore/cloud_firestore_platform_interface/lib/src/document_snapshot.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2017, the Chromium project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
import 'package:cloud_firestore_platform_interface/cloud_firestore_platform_interface.dart'; | ||
|
||
/// Contains data read from a document in your Firestore | ||
/// database. | ||
/// | ||
/// The data can be extracted with the [data] property or by using subscript | ||
/// syntax to access a specific field. | ||
class DocumentSnapshotPlatform { | ||
/// Constructs a [DocumentSnapshotPlatform] using the provided [FirestorePlatform]. | ||
DocumentSnapshotPlatform( | ||
this._path, this.data, this.metadata, this.firestore); | ||
|
||
final String _path; | ||
|
||
/// The [FirestorePlatform] used to produce this [DocumentSnapshotPlatform]. | ||
final FirestorePlatform firestore; | ||
|
||
/// The reference that produced this snapshot. | ||
DocumentReferencePlatform get reference => firestore.document(_path); | ||
|
||
/// Contains all the data of this snapshot. | ||
final Map<String, dynamic> data; | ||
|
||
/// Metadata about this snapshot concerning its source and if it has local | ||
/// modifications. | ||
final SnapshotMetadataPlatform metadata; | ||
|
||
/// Reads individual values from the snapshot. | ||
dynamic operator [](String key) => data[key]; | ||
|
||
/// The database ID of the snapshot's document. | ||
String get documentID => _path.split('/').last; | ||
|
||
/// Returns `true` if the document exists. | ||
bool get exists => data != null; | ||
} |
16 changes: 16 additions & 0 deletions
16
packages/cloud_firestore/cloud_firestore_platform_interface/lib/src/field_path.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright 2017, the Chromium project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
import 'internal/field_path_type.dart'; | ||
|
||
/// A [FieldPath] refers to a field in a document. | ||
class FieldPath { | ||
const FieldPath._(this.type); | ||
|
||
/// The type of this field path (used in [FirestoreMessageCodec]) | ||
final FieldPathType type; | ||
|
||
/// The path to the document id, which can be used in queries. | ||
static FieldPath get documentId => | ||
const FieldPath._(FieldPathType.documentId); | ||
} |
20 changes: 20 additions & 0 deletions
20
packages/cloud_firestore/cloud_firestore_platform_interface/lib/src/geo_point.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2017, the Chromium project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
import 'dart:ui'; | ||
|
||
/// Represents a geographical point by its longitude and latitude | ||
class GeoPoint { | ||
/// Create [GeoPoint] instance | ||
const GeoPoint(this.latitude, this.longitude); | ||
|
||
final double latitude; // ignore: public_member_api_docs | ||
final double longitude; // ignore: public_member_api_docs | ||
|
||
@override | ||
bool operator ==(dynamic o) => | ||
o is GeoPoint && o.latitude == latitude && o.longitude == longitude; | ||
|
||
@override | ||
int get hashCode => hashValues(latitude, longitude); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.