From 2f520c805c5eea079df3e4e5411605daf3fef0d7 Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Mon, 2 May 2022 19:41:52 +0200 Subject: [PATCH 1/6] feat: Add DateTime and Timestamp support --- .../cloud_firestore_odm/example/.metadata | 38 +- .../cloud_firestore_odm/example/build.yaml | 23 + .../example/lib/integration.g.dart | 316 ------- .../example/lib/integration/query.dart | 34 + .../example/lib/integration/query.g.dart | 849 ++++++++++++++++++ .../example/lib/movie.g.dart | 2 + .../test_driver/query_reference_test.dart | 35 + .../lib/cloud_firestore_odm.dart | 35 + .../cloud_firestore_odm/pubspec.yaml | 1 + .../lib/src/collection_generator.dart | 9 +- 10 files changed, 1022 insertions(+), 320 deletions(-) create mode 100644 packages/cloud_firestore_odm/cloud_firestore_odm/example/build.yaml delete mode 100644 packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration.g.dart create mode 100644 packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/query.dart create mode 100644 packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/query.g.dart diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm/example/.metadata b/packages/cloud_firestore_odm/cloud_firestore_odm/example/.metadata index a5584fc372d9..3ef76cb126d8 100644 --- a/packages/cloud_firestore_odm/cloud_firestore_odm/example/.metadata +++ b/packages/cloud_firestore_odm/cloud_firestore_odm/example/.metadata @@ -1,10 +1,42 @@ # This file tracks properties of this Flutter project. # Used by Flutter tool to assess capabilities and perform upgrades etc. # -# This file should be version controlled and should not be manually edited. +# This file should be version controlled. version: - revision: 18116933e77adc82f80866c928266a5b4f1ed645 - channel: stable + revision: 8662e22bac54c71bc4fa5a4f37e9ee80bfd08a4e + channel: dev project_type: app + +# Tracks metadata for the flutter migrate command +migration: + platforms: + - platform: root + create_revision: 8662e22bac54c71bc4fa5a4f37e9ee80bfd08a4e + base_revision: 8662e22bac54c71bc4fa5a4f37e9ee80bfd08a4e + - platform: android + create_revision: 8662e22bac54c71bc4fa5a4f37e9ee80bfd08a4e + base_revision: 8662e22bac54c71bc4fa5a4f37e9ee80bfd08a4e + - platform: ios + create_revision: 8662e22bac54c71bc4fa5a4f37e9ee80bfd08a4e + base_revision: 8662e22bac54c71bc4fa5a4f37e9ee80bfd08a4e + - platform: macos + create_revision: 8662e22bac54c71bc4fa5a4f37e9ee80bfd08a4e + base_revision: 8662e22bac54c71bc4fa5a4f37e9ee80bfd08a4e + - platform: web + create_revision: 8662e22bac54c71bc4fa5a4f37e9ee80bfd08a4e + base_revision: 8662e22bac54c71bc4fa5a4f37e9ee80bfd08a4e + - platform: windows + create_revision: 8662e22bac54c71bc4fa5a4f37e9ee80bfd08a4e + base_revision: 8662e22bac54c71bc4fa5a4f37e9ee80bfd08a4e + + # User provided section + + # List of Local paths (relative to this file) that should be + # ignored by the migrate tool. + # + # Files that are not part of the templates will be ignored by default. + unmanaged_files: + - 'lib/main.dart' + - 'ios/Runner.xcodeproj/project.pbxproj' diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm/example/build.yaml b/packages/cloud_firestore_odm/cloud_firestore_odm/example/build.yaml new file mode 100644 index 000000000000..1d169179d764 --- /dev/null +++ b/packages/cloud_firestore_odm/cloud_firestore_odm/example/build.yaml @@ -0,0 +1,23 @@ +targets: + $default: + builders: + cloud_firestore_odm_generator: + enabled: true + generate_for: + include: + - lib/* + - lib/** + - test_driver/integration/* + - test_driver/integration/**/* + json_serializable: + enabled: true + generate_for: + include: + - lib/* + - lib/** + - test_driver/integration/* + - test_driver/integration/**/* + source_gen|combining_builder: + options: + ignore_for_file: + - 'type=lint' diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration.g.dart b/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration.g.dart deleted file mode 100644 index 9a877480d906..000000000000 --- a/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration.g.dart +++ /dev/null @@ -1,316 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'integration.dart'; - -// ************************************************************************** -// CollectionGenerator -// ************************************************************************** - -// GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides - -class _Sentinel { - const _Sentinel(); -} - -const _sentinel = _Sentinel(); - -/// A collection reference object can be used for adding documents, -/// getting document references, and querying for documents -/// (using the methods inherited from Query). -abstract class EmptyModelCollectionReference - implements - EmptyModelQuery, - FirestoreCollectionReference { - factory EmptyModelCollectionReference([ - FirebaseFirestore? firestore, - ]) = _$EmptyModelCollectionReference; - - static EmptyModel fromFirestore( - DocumentSnapshot> snapshot, - SnapshotOptions? options, - ) { - return EmptyModel.fromJson(snapshot.data()!); - } - - static Map toFirestore( - EmptyModel value, - SetOptions? options, - ) { - return value.toJson(); - } - - @override - EmptyModelDocumentReference doc([String? id]); - - /// Add a new document to this collection with the specified data, - /// assigning it a document ID automatically. - Future add(EmptyModel value); -} - -class _$EmptyModelCollectionReference extends _$EmptyModelQuery - implements EmptyModelCollectionReference { - factory _$EmptyModelCollectionReference([FirebaseFirestore? firestore]) { - firestore ??= FirebaseFirestore.instance; - - return _$EmptyModelCollectionReference._( - firestore.collection('config').withConverter( - fromFirestore: EmptyModelCollectionReference.fromFirestore, - toFirestore: EmptyModelCollectionReference.toFirestore, - ), - ); - } - - _$EmptyModelCollectionReference._( - CollectionReference reference, - ) : super(reference, reference); - - String get path => reference.path; - - @override - CollectionReference get reference => - super.reference as CollectionReference; - - @override - EmptyModelDocumentReference doc([String? id]) { - return EmptyModelDocumentReference( - reference.doc(id), - ); - } - - @override - Future add(EmptyModel value) { - return reference.add(value).then((ref) => EmptyModelDocumentReference(ref)); - } - - @override - bool operator ==(Object other) { - return other is _$EmptyModelCollectionReference && - other.runtimeType == runtimeType && - other.reference == reference; - } - - @override - int get hashCode => Object.hash(runtimeType, reference); -} - -abstract class EmptyModelDocumentReference - extends FirestoreDocumentReference { - factory EmptyModelDocumentReference(DocumentReference reference) = - _$EmptyModelDocumentReference; - - DocumentReference get reference; - - /// A reference to the [EmptyModelCollectionReference] containing this document. - EmptyModelCollectionReference get parent { - return _$EmptyModelCollectionReference(reference.firestore); - } - - @override - Stream snapshots(); - - @override - Future get([GetOptions? options]); - - @override - Future delete(); - - Future set(EmptyModel value); -} - -class _$EmptyModelDocumentReference - extends FirestoreDocumentReference - implements EmptyModelDocumentReference { - _$EmptyModelDocumentReference(this.reference); - - @override - final DocumentReference reference; - - /// A reference to the [EmptyModelCollectionReference] containing this document. - EmptyModelCollectionReference get parent { - return _$EmptyModelCollectionReference(reference.firestore); - } - - @override - Stream snapshots() { - return reference.snapshots().map((snapshot) { - return EmptyModelDocumentSnapshot._( - snapshot, - snapshot.data(), - ); - }); - } - - @override - Future get([GetOptions? options]) { - return reference.get(options).then((snapshot) { - return EmptyModelDocumentSnapshot._( - snapshot, - snapshot.data(), - ); - }); - } - - @override - Future delete() { - return reference.delete(); - } - - Future set(EmptyModel value) { - return reference.set(value); - } - - @override - bool operator ==(Object other) { - return other is EmptyModelDocumentReference && - other.runtimeType == runtimeType && - other.parent == parent && - other.id == id; - } - - @override - int get hashCode => Object.hash(runtimeType, parent, id); -} - -class EmptyModelDocumentSnapshot extends FirestoreDocumentSnapshot { - EmptyModelDocumentSnapshot._( - this.snapshot, - this.data, - ); - - @override - final DocumentSnapshot snapshot; - - @override - EmptyModelDocumentReference get reference { - return EmptyModelDocumentReference( - snapshot.reference, - ); - } - - @override - final EmptyModel? data; -} - -abstract class EmptyModelQuery - implements QueryReference { - @override - EmptyModelQuery limit(int limit); - - @override - EmptyModelQuery limitToLast(int limit); -} - -class _$EmptyModelQuery extends QueryReference - implements EmptyModelQuery { - _$EmptyModelQuery( - this.reference, - this._collection, - ); - - final CollectionReference _collection; - - @override - final Query reference; - - EmptyModelQuerySnapshot _decodeSnapshot( - QuerySnapshot snapshot, - ) { - final docs = snapshot.docs.map((e) { - return EmptyModelQueryDocumentSnapshot._(e, e.data()); - }).toList(); - - final docChanges = snapshot.docChanges.map((change) { - return FirestoreDocumentChange( - type: change.type, - oldIndex: change.oldIndex, - newIndex: change.newIndex, - doc: EmptyModelDocumentSnapshot._(change.doc, change.doc.data()), - ); - }).toList(); - - return EmptyModelQuerySnapshot._( - snapshot, - docs, - docChanges, - ); - } - - @override - Stream snapshots([SnapshotOptions? options]) { - return reference.snapshots().map(_decodeSnapshot); - } - - @override - Future get([GetOptions? options]) { - return reference.get(options).then(_decodeSnapshot); - } - - @override - EmptyModelQuery limit(int limit) { - return _$EmptyModelQuery( - reference.limit(limit), - _collection, - ); - } - - @override - EmptyModelQuery limitToLast(int limit) { - return _$EmptyModelQuery( - reference.limitToLast(limit), - _collection, - ); - } - - @override - bool operator ==(Object other) { - return other is _$EmptyModelQuery && - other.runtimeType == runtimeType && - other.reference == reference; - } - - @override - int get hashCode => Object.hash(runtimeType, reference); -} - -class EmptyModelQuerySnapshot - extends FirestoreQuerySnapshot { - EmptyModelQuerySnapshot._( - this.snapshot, - this.docs, - this.docChanges, - ); - - final QuerySnapshot snapshot; - - @override - final List docs; - - @override - final List> docChanges; -} - -class EmptyModelQueryDocumentSnapshot extends FirestoreQueryDocumentSnapshot - implements EmptyModelDocumentSnapshot { - EmptyModelQueryDocumentSnapshot._(this.snapshot, this.data); - - @override - final QueryDocumentSnapshot snapshot; - - @override - EmptyModelDocumentReference get reference { - return EmptyModelDocumentReference(snapshot.reference); - } - - @override - final EmptyModel data; -} - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -EmptyModel _$EmptyModelFromJson(Map json) => EmptyModel(); - -Map _$EmptyModelToJson(EmptyModel instance) => - {}; diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/query.dart b/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/query.dart new file mode 100644 index 000000000000..b59ce93c2eea --- /dev/null +++ b/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/query.dart @@ -0,0 +1,34 @@ +import 'package:cloud_firestore/cloud_firestore.dart'; +import 'package:cloud_firestore_odm/cloud_firestore_odm.dart'; +import 'package:json_annotation/json_annotation.dart'; + +part 'query.g.dart'; + +@Collection('firestore-example-app/42/date-time') +final dateTimeQueryRef = DateTimeQueryCollectionReference(); + +@JsonSerializable() +@FirestoreDateTimeConverter() +class DateTimeQuery { + DateTimeQuery(this.time); + final DateTime time; +} + +class FirestoreDateTimeConverter extends JsonConverter { + const FirestoreDateTimeConverter(); + @override + DateTime fromJson(Timestamp json) => json.toDate(); + + @override + Timestamp toJson(DateTime object) => Timestamp.fromDate(object); +} + +@Collection('firestore-example-app/42/timestamp-time') +final timestampQueryRef = TimestampQueryCollectionReference(); + +@JsonSerializable() +@FirestoreTimestampConverter() +class TimestampQuery { + TimestampQuery(this.time); + final Timestamp time; +} diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/query.g.dart b/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/query.g.dart new file mode 100644 index 000000000000..da38ec978754 --- /dev/null +++ b/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/query.g.dart @@ -0,0 +1,849 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +// ignore_for_file: type=lint + +part of 'query.dart'; + +// ************************************************************************** +// CollectionGenerator +// ************************************************************************** + +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides + +class _Sentinel { + const _Sentinel(); +} + +const _sentinel = _Sentinel(); + +/// A collection reference object can be used for adding documents, +/// getting document references, and querying for documents +/// (using the methods inherited from Query). +abstract class DateTimeQueryCollectionReference + implements + DateTimeQueryQuery, + FirestoreCollectionReference { + factory DateTimeQueryCollectionReference([ + FirebaseFirestore? firestore, + ]) = _$DateTimeQueryCollectionReference; + + static DateTimeQuery fromFirestore( + DocumentSnapshot> snapshot, + SnapshotOptions? options, + ) { + return _$DateTimeQueryFromJson(snapshot.data()!); + } + + static Map toFirestore( + DateTimeQuery value, + SetOptions? options, + ) { + return _$DateTimeQueryToJson(value); + } + + @override + DateTimeQueryDocumentReference doc([String? id]); + + /// Add a new document to this collection with the specified data, + /// assigning it a document ID automatically. + Future add(DateTimeQuery value); +} + +class _$DateTimeQueryCollectionReference extends _$DateTimeQueryQuery + implements DateTimeQueryCollectionReference { + factory _$DateTimeQueryCollectionReference([FirebaseFirestore? firestore]) { + firestore ??= FirebaseFirestore.instance; + + return _$DateTimeQueryCollectionReference._( + firestore.collection('firestore-example-app/42/date-time').withConverter( + fromFirestore: DateTimeQueryCollectionReference.fromFirestore, + toFirestore: DateTimeQueryCollectionReference.toFirestore, + ), + ); + } + + _$DateTimeQueryCollectionReference._( + CollectionReference reference, + ) : super(reference, reference); + + String get path => reference.path; + + @override + CollectionReference get reference => + super.reference as CollectionReference; + + @override + DateTimeQueryDocumentReference doc([String? id]) { + return DateTimeQueryDocumentReference( + reference.doc(id), + ); + } + + @override + Future add(DateTimeQuery value) { + return reference + .add(value) + .then((ref) => DateTimeQueryDocumentReference(ref)); + } + + @override + bool operator ==(Object other) { + return other is _$DateTimeQueryCollectionReference && + other.runtimeType == runtimeType && + other.reference == reference; + } + + @override + int get hashCode => Object.hash(runtimeType, reference); +} + +abstract class DateTimeQueryDocumentReference + extends FirestoreDocumentReference { + factory DateTimeQueryDocumentReference( + DocumentReference reference) = + _$DateTimeQueryDocumentReference; + + DocumentReference get reference; + + /// A reference to the [DateTimeQueryCollectionReference] containing this document. + DateTimeQueryCollectionReference get parent { + return _$DateTimeQueryCollectionReference(reference.firestore); + } + + @override + Stream snapshots(); + + @override + Future get([GetOptions? options]); + + @override + Future delete(); + + Future update({ + DateTime time, + }); + + Future set(DateTimeQuery value); +} + +class _$DateTimeQueryDocumentReference + extends FirestoreDocumentReference + implements DateTimeQueryDocumentReference { + _$DateTimeQueryDocumentReference(this.reference); + + @override + final DocumentReference reference; + + /// A reference to the [DateTimeQueryCollectionReference] containing this document. + DateTimeQueryCollectionReference get parent { + return _$DateTimeQueryCollectionReference(reference.firestore); + } + + @override + Stream snapshots() { + return reference.snapshots().map((snapshot) { + return DateTimeQueryDocumentSnapshot._( + snapshot, + snapshot.data(), + ); + }); + } + + @override + Future get([GetOptions? options]) { + return reference.get(options).then((snapshot) { + return DateTimeQueryDocumentSnapshot._( + snapshot, + snapshot.data(), + ); + }); + } + + @override + Future delete() { + return reference.delete(); + } + + Future update({ + Object? time = _sentinel, + }) async { + final json = { + if (time != _sentinel) "time": time as DateTime, + }; + + return reference.update(json); + } + + Future set(DateTimeQuery value) { + return reference.set(value); + } + + @override + bool operator ==(Object other) { + return other is DateTimeQueryDocumentReference && + other.runtimeType == runtimeType && + other.parent == parent && + other.id == id; + } + + @override + int get hashCode => Object.hash(runtimeType, parent, id); +} + +class DateTimeQueryDocumentSnapshot extends FirestoreDocumentSnapshot { + DateTimeQueryDocumentSnapshot._( + this.snapshot, + this.data, + ); + + @override + final DocumentSnapshot snapshot; + + @override + DateTimeQueryDocumentReference get reference { + return DateTimeQueryDocumentReference( + snapshot.reference, + ); + } + + @override + final DateTimeQuery? data; +} + +abstract class DateTimeQueryQuery + implements QueryReference { + @override + DateTimeQueryQuery limit(int limit); + + @override + DateTimeQueryQuery limitToLast(int limit); + + DateTimeQueryQuery whereTime({ + DateTime? isEqualTo, + DateTime? isNotEqualTo, + DateTime? isLessThan, + DateTime? isLessThanOrEqualTo, + DateTime? isGreaterThan, + DateTime? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }); + + DateTimeQueryQuery orderByTime({ + bool descending = false, + DateTime startAt, + DateTime startAfter, + DateTime endAt, + DateTime endBefore, + DateTimeQueryDocumentSnapshot? startAtDocument, + DateTimeQueryDocumentSnapshot? endAtDocument, + DateTimeQueryDocumentSnapshot? endBeforeDocument, + DateTimeQueryDocumentSnapshot? startAfterDocument, + }); +} + +class _$DateTimeQueryQuery extends QueryReference + implements DateTimeQueryQuery { + _$DateTimeQueryQuery( + this.reference, + this._collection, + ); + + final CollectionReference _collection; + + @override + final Query reference; + + DateTimeQueryQuerySnapshot _decodeSnapshot( + QuerySnapshot snapshot, + ) { + final docs = snapshot.docs.map((e) { + return DateTimeQueryQueryDocumentSnapshot._(e, e.data()); + }).toList(); + + final docChanges = snapshot.docChanges.map((change) { + return FirestoreDocumentChange( + type: change.type, + oldIndex: change.oldIndex, + newIndex: change.newIndex, + doc: DateTimeQueryDocumentSnapshot._(change.doc, change.doc.data()), + ); + }).toList(); + + return DateTimeQueryQuerySnapshot._( + snapshot, + docs, + docChanges, + ); + } + + @override + Stream snapshots([SnapshotOptions? options]) { + return reference.snapshots().map(_decodeSnapshot); + } + + @override + Future get([GetOptions? options]) { + return reference.get(options).then(_decodeSnapshot); + } + + @override + DateTimeQueryQuery limit(int limit) { + return _$DateTimeQueryQuery( + reference.limit(limit), + _collection, + ); + } + + @override + DateTimeQueryQuery limitToLast(int limit) { + return _$DateTimeQueryQuery( + reference.limitToLast(limit), + _collection, + ); + } + + DateTimeQueryQuery whereTime({ + DateTime? isEqualTo, + DateTime? isNotEqualTo, + DateTime? isLessThan, + DateTime? isLessThanOrEqualTo, + DateTime? isGreaterThan, + DateTime? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }) { + return _$DateTimeQueryQuery( + reference.where( + 'time', + isEqualTo: isEqualTo, + isNotEqualTo: isNotEqualTo, + isLessThan: isLessThan, + isLessThanOrEqualTo: isLessThanOrEqualTo, + isGreaterThan: isGreaterThan, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isNull: isNull, + whereIn: whereIn, + whereNotIn: whereNotIn, + ), + _collection, + ); + } + + DateTimeQueryQuery orderByTime({ + bool descending = false, + Object? startAt = _sentinel, + Object? startAfter = _sentinel, + Object? endAt = _sentinel, + Object? endBefore = _sentinel, + DateTimeQueryDocumentSnapshot? startAtDocument, + DateTimeQueryDocumentSnapshot? endAtDocument, + DateTimeQueryDocumentSnapshot? endBeforeDocument, + DateTimeQueryDocumentSnapshot? startAfterDocument, + }) { + var query = reference.orderBy('time', descending: descending); + + if (startAtDocument != null) { + query = query.startAtDocument(startAtDocument.snapshot); + } + if (startAfterDocument != null) { + query = query.startAfterDocument(startAfterDocument.snapshot); + } + if (endAtDocument != null) { + query = query.endAtDocument(endAtDocument.snapshot); + } + if (endBeforeDocument != null) { + query = query.endBeforeDocument(endBeforeDocument.snapshot); + } + + if (startAt != _sentinel) { + query = query.startAt([startAt]); + } + if (startAfter != _sentinel) { + query = query.startAfter([startAfter]); + } + if (endAt != _sentinel) { + query = query.endAt([endAt]); + } + if (endBefore != _sentinel) { + query = query.endBefore([endBefore]); + } + + return _$DateTimeQueryQuery(query, _collection); + } + + @override + bool operator ==(Object other) { + return other is _$DateTimeQueryQuery && + other.runtimeType == runtimeType && + other.reference == reference; + } + + @override + int get hashCode => Object.hash(runtimeType, reference); +} + +class DateTimeQueryQuerySnapshot + extends FirestoreQuerySnapshot { + DateTimeQueryQuerySnapshot._( + this.snapshot, + this.docs, + this.docChanges, + ); + + final QuerySnapshot snapshot; + + @override + final List docs; + + @override + final List> docChanges; +} + +class DateTimeQueryQueryDocumentSnapshot extends FirestoreQueryDocumentSnapshot + implements DateTimeQueryDocumentSnapshot { + DateTimeQueryQueryDocumentSnapshot._(this.snapshot, this.data); + + @override + final QueryDocumentSnapshot snapshot; + + @override + DateTimeQueryDocumentReference get reference { + return DateTimeQueryDocumentReference(snapshot.reference); + } + + @override + final DateTimeQuery data; +} + +/// A collection reference object can be used for adding documents, +/// getting document references, and querying for documents +/// (using the methods inherited from Query). +abstract class TimestampQueryCollectionReference + implements + TimestampQueryQuery, + FirestoreCollectionReference { + factory TimestampQueryCollectionReference([ + FirebaseFirestore? firestore, + ]) = _$TimestampQueryCollectionReference; + + static TimestampQuery fromFirestore( + DocumentSnapshot> snapshot, + SnapshotOptions? options, + ) { + return _$TimestampQueryFromJson(snapshot.data()!); + } + + static Map toFirestore( + TimestampQuery value, + SetOptions? options, + ) { + return _$TimestampQueryToJson(value); + } + + @override + TimestampQueryDocumentReference doc([String? id]); + + /// Add a new document to this collection with the specified data, + /// assigning it a document ID automatically. + Future add(TimestampQuery value); +} + +class _$TimestampQueryCollectionReference extends _$TimestampQueryQuery + implements TimestampQueryCollectionReference { + factory _$TimestampQueryCollectionReference([FirebaseFirestore? firestore]) { + firestore ??= FirebaseFirestore.instance; + + return _$TimestampQueryCollectionReference._( + firestore + .collection('firestore-example-app/42/timestamp-time') + .withConverter( + fromFirestore: TimestampQueryCollectionReference.fromFirestore, + toFirestore: TimestampQueryCollectionReference.toFirestore, + ), + ); + } + + _$TimestampQueryCollectionReference._( + CollectionReference reference, + ) : super(reference, reference); + + String get path => reference.path; + + @override + CollectionReference get reference => + super.reference as CollectionReference; + + @override + TimestampQueryDocumentReference doc([String? id]) { + return TimestampQueryDocumentReference( + reference.doc(id), + ); + } + + @override + Future add(TimestampQuery value) { + return reference + .add(value) + .then((ref) => TimestampQueryDocumentReference(ref)); + } + + @override + bool operator ==(Object other) { + return other is _$TimestampQueryCollectionReference && + other.runtimeType == runtimeType && + other.reference == reference; + } + + @override + int get hashCode => Object.hash(runtimeType, reference); +} + +abstract class TimestampQueryDocumentReference + extends FirestoreDocumentReference { + factory TimestampQueryDocumentReference( + DocumentReference reference) = + _$TimestampQueryDocumentReference; + + DocumentReference get reference; + + /// A reference to the [TimestampQueryCollectionReference] containing this document. + TimestampQueryCollectionReference get parent { + return _$TimestampQueryCollectionReference(reference.firestore); + } + + @override + Stream snapshots(); + + @override + Future get([GetOptions? options]); + + @override + Future delete(); + + Future update({ + Timestamp time, + }); + + Future set(TimestampQuery value); +} + +class _$TimestampQueryDocumentReference + extends FirestoreDocumentReference + implements TimestampQueryDocumentReference { + _$TimestampQueryDocumentReference(this.reference); + + @override + final DocumentReference reference; + + /// A reference to the [TimestampQueryCollectionReference] containing this document. + TimestampQueryCollectionReference get parent { + return _$TimestampQueryCollectionReference(reference.firestore); + } + + @override + Stream snapshots() { + return reference.snapshots().map((snapshot) { + return TimestampQueryDocumentSnapshot._( + snapshot, + snapshot.data(), + ); + }); + } + + @override + Future get([GetOptions? options]) { + return reference.get(options).then((snapshot) { + return TimestampQueryDocumentSnapshot._( + snapshot, + snapshot.data(), + ); + }); + } + + @override + Future delete() { + return reference.delete(); + } + + Future update({ + Object? time = _sentinel, + }) async { + final json = { + if (time != _sentinel) "time": time as Timestamp, + }; + + return reference.update(json); + } + + Future set(TimestampQuery value) { + return reference.set(value); + } + + @override + bool operator ==(Object other) { + return other is TimestampQueryDocumentReference && + other.runtimeType == runtimeType && + other.parent == parent && + other.id == id; + } + + @override + int get hashCode => Object.hash(runtimeType, parent, id); +} + +class TimestampQueryDocumentSnapshot extends FirestoreDocumentSnapshot { + TimestampQueryDocumentSnapshot._( + this.snapshot, + this.data, + ); + + @override + final DocumentSnapshot snapshot; + + @override + TimestampQueryDocumentReference get reference { + return TimestampQueryDocumentReference( + snapshot.reference, + ); + } + + @override + final TimestampQuery? data; +} + +abstract class TimestampQueryQuery + implements QueryReference { + @override + TimestampQueryQuery limit(int limit); + + @override + TimestampQueryQuery limitToLast(int limit); + + TimestampQueryQuery whereTime({ + Timestamp? isEqualTo, + Timestamp? isNotEqualTo, + Timestamp? isLessThan, + Timestamp? isLessThanOrEqualTo, + Timestamp? isGreaterThan, + Timestamp? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }); + + TimestampQueryQuery orderByTime({ + bool descending = false, + Timestamp startAt, + Timestamp startAfter, + Timestamp endAt, + Timestamp endBefore, + TimestampQueryDocumentSnapshot? startAtDocument, + TimestampQueryDocumentSnapshot? endAtDocument, + TimestampQueryDocumentSnapshot? endBeforeDocument, + TimestampQueryDocumentSnapshot? startAfterDocument, + }); +} + +class _$TimestampQueryQuery extends QueryReference + implements TimestampQueryQuery { + _$TimestampQueryQuery( + this.reference, + this._collection, + ); + + final CollectionReference _collection; + + @override + final Query reference; + + TimestampQueryQuerySnapshot _decodeSnapshot( + QuerySnapshot snapshot, + ) { + final docs = snapshot.docs.map((e) { + return TimestampQueryQueryDocumentSnapshot._(e, e.data()); + }).toList(); + + final docChanges = snapshot.docChanges.map((change) { + return FirestoreDocumentChange( + type: change.type, + oldIndex: change.oldIndex, + newIndex: change.newIndex, + doc: TimestampQueryDocumentSnapshot._(change.doc, change.doc.data()), + ); + }).toList(); + + return TimestampQueryQuerySnapshot._( + snapshot, + docs, + docChanges, + ); + } + + @override + Stream snapshots([SnapshotOptions? options]) { + return reference.snapshots().map(_decodeSnapshot); + } + + @override + Future get([GetOptions? options]) { + return reference.get(options).then(_decodeSnapshot); + } + + @override + TimestampQueryQuery limit(int limit) { + return _$TimestampQueryQuery( + reference.limit(limit), + _collection, + ); + } + + @override + TimestampQueryQuery limitToLast(int limit) { + return _$TimestampQueryQuery( + reference.limitToLast(limit), + _collection, + ); + } + + TimestampQueryQuery whereTime({ + Timestamp? isEqualTo, + Timestamp? isNotEqualTo, + Timestamp? isLessThan, + Timestamp? isLessThanOrEqualTo, + Timestamp? isGreaterThan, + Timestamp? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }) { + return _$TimestampQueryQuery( + reference.where( + 'time', + isEqualTo: isEqualTo, + isNotEqualTo: isNotEqualTo, + isLessThan: isLessThan, + isLessThanOrEqualTo: isLessThanOrEqualTo, + isGreaterThan: isGreaterThan, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isNull: isNull, + whereIn: whereIn, + whereNotIn: whereNotIn, + ), + _collection, + ); + } + + TimestampQueryQuery orderByTime({ + bool descending = false, + Object? startAt = _sentinel, + Object? startAfter = _sentinel, + Object? endAt = _sentinel, + Object? endBefore = _sentinel, + TimestampQueryDocumentSnapshot? startAtDocument, + TimestampQueryDocumentSnapshot? endAtDocument, + TimestampQueryDocumentSnapshot? endBeforeDocument, + TimestampQueryDocumentSnapshot? startAfterDocument, + }) { + var query = reference.orderBy('time', descending: descending); + + if (startAtDocument != null) { + query = query.startAtDocument(startAtDocument.snapshot); + } + if (startAfterDocument != null) { + query = query.startAfterDocument(startAfterDocument.snapshot); + } + if (endAtDocument != null) { + query = query.endAtDocument(endAtDocument.snapshot); + } + if (endBeforeDocument != null) { + query = query.endBeforeDocument(endBeforeDocument.snapshot); + } + + if (startAt != _sentinel) { + query = query.startAt([startAt]); + } + if (startAfter != _sentinel) { + query = query.startAfter([startAfter]); + } + if (endAt != _sentinel) { + query = query.endAt([endAt]); + } + if (endBefore != _sentinel) { + query = query.endBefore([endBefore]); + } + + return _$TimestampQueryQuery(query, _collection); + } + + @override + bool operator ==(Object other) { + return other is _$TimestampQueryQuery && + other.runtimeType == runtimeType && + other.reference == reference; + } + + @override + int get hashCode => Object.hash(runtimeType, reference); +} + +class TimestampQueryQuerySnapshot + extends FirestoreQuerySnapshot { + TimestampQueryQuerySnapshot._( + this.snapshot, + this.docs, + this.docChanges, + ); + + final QuerySnapshot snapshot; + + @override + final List docs; + + @override + final List> + docChanges; +} + +class TimestampQueryQueryDocumentSnapshot extends FirestoreQueryDocumentSnapshot + implements TimestampQueryDocumentSnapshot { + TimestampQueryQueryDocumentSnapshot._(this.snapshot, this.data); + + @override + final QueryDocumentSnapshot snapshot; + + @override + TimestampQueryDocumentReference get reference { + return TimestampQueryDocumentReference(snapshot.reference); + } + + @override + final TimestampQuery data; +} + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +DateTimeQuery _$DateTimeQueryFromJson(Map json) => + DateTimeQuery( + const FirestoreDateTimeConverter().fromJson(json['time'] as Timestamp), + ); + +Map _$DateTimeQueryToJson(DateTimeQuery instance) => + { + 'time': const FirestoreDateTimeConverter().toJson(instance.time), + }; + +TimestampQuery _$TimestampQueryFromJson(Map json) => + TimestampQuery( + const FirestoreTimestampConverter().fromJson(json['time'] as Timestamp), + ); + +Map _$TimestampQueryToJson(TimestampQuery instance) => + { + 'time': const FirestoreTimestampConverter().toJson(instance.time), + }; diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/movie.g.dart b/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/movie.g.dart index 3049ea072bb0..b02c53b4dc44 100644 --- a/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/movie.g.dart +++ b/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/movie.g.dart @@ -1,5 +1,7 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint + part of 'movie.dart'; // ************************************************************************** diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm/example/test_driver/query_reference_test.dart b/packages/cloud_firestore_odm/cloud_firestore_odm/example/test_driver/query_reference_test.dart index 29b430774605..6956f0418a36 100644 --- a/packages/cloud_firestore_odm/cloud_firestore_odm/example/test_driver/query_reference_test.dart +++ b/packages/cloud_firestore_odm/cloud_firestore_odm/example/test_driver/query_reference_test.dart @@ -3,10 +3,13 @@ // BSD-style license that can be found in the LICENSE file. import 'package:cloud_firestore/cloud_firestore.dart'; +import 'package:cloud_firestore_odm_example/integration/query.dart'; import 'package:cloud_firestore_odm_example/movie.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'common.dart'; + void main() { group('QueryReference', () { late FirebaseFirestore customFirestore; @@ -84,5 +87,37 @@ void main() { ); }); }); + + test('supports DateTimes', () async { + final ref = await initializeTest(dateTimeQueryRef); + + await ref.add(DateTimeQuery(DateTime(1990))); + await ref.add(DateTimeQuery(DateTime(2000))); + await ref.add(DateTimeQuery(DateTime(2010))); + + final snapshot = await ref.orderByTime(startAt: DateTime(2000)).get(); + + expect(snapshot.docs.length, 2); + + expect(snapshot.docs[0].data.time, DateTime(2000)); + expect(snapshot.docs[1].data.time, DateTime(2010)); + }); + + test('supports Timestamp', () async { + final ref = await initializeTest(timestampQueryRef); + + await ref.add(TimestampQuery(Timestamp.fromDate(DateTime(1990)))); + await ref.add(TimestampQuery(Timestamp.fromDate(DateTime(2000)))); + await ref.add(TimestampQuery(Timestamp.fromDate(DateTime(2010)))); + + final snapshot = await ref + .orderByTime(startAt: Timestamp.fromDate(DateTime(2000))) + .get(); + + expect(snapshot.docs.length, 2); + + expect(snapshot.docs[0].data.time, Timestamp.fromDate(DateTime(2000))); + expect(snapshot.docs[1].data.time, Timestamp.fromDate(DateTime(2010))); + }); }); } diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm/lib/cloud_firestore_odm.dart b/packages/cloud_firestore_odm/cloud_firestore_odm/lib/cloud_firestore_odm.dart index 2148a0db4b4b..7ff963c24579 100644 --- a/packages/cloud_firestore_odm/cloud_firestore_odm/lib/cloud_firestore_odm.dart +++ b/packages/cloud_firestore_odm/cloud_firestore_odm/lib/cloud_firestore_odm.dart @@ -1,3 +1,6 @@ +import 'package:cloud_firestore/cloud_firestore.dart'; +import 'package:json_annotation/json_annotation.dart'; + export 'annotation.dart'; export 'src/firestore_builder.dart' show FirestoreBuilder; export 'src/firestore_reference.dart' @@ -11,3 +14,35 @@ export 'src/firestore_reference.dart' FirestoreQuerySnapshot, FirestoreReference, QueryReference; + +/// The list of all [JsonConverter]s that cloud_firestore_odm offers. +/// +/// This list is meant to be passed to [JsonSerializable] as followed: +/// +/// ```dart +/// @JsonSerializable(converters: firestoreJsonConverters) +/// ``` +const firestoreJsonConverters = [ + FirestoreDateTimeConverter(), + FirestoreTimestampConverter(), +]; + +/// A [JsonConverter] that adds support for [Timestamp] objects within ODM models. +class FirestoreTimestampConverter extends JsonConverter { + const FirestoreTimestampConverter(); + @override + Timestamp fromJson(Timestamp json) => json; + + @override + Timestamp toJson(Timestamp object) => object; +} + +/// A [JsonConverter] that adds support for [DateTime] objects within ODM models. +class FirestoreDateTimeConverter extends JsonConverter { + const FirestoreDateTimeConverter(); + @override + DateTime fromJson(Timestamp json) => json.toDate(); + + @override + Timestamp toJson(DateTime object) => Timestamp.fromDate(object); +} diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm/pubspec.yaml b/packages/cloud_firestore_odm/cloud_firestore_odm/pubspec.yaml index 584b4e486374..f89de2639abb 100644 --- a/packages/cloud_firestore_odm/cloud_firestore_odm/pubspec.yaml +++ b/packages/cloud_firestore_odm/cloud_firestore_odm/pubspec.yaml @@ -14,6 +14,7 @@ dependencies: cloud_firestore: ^3.1.12 flutter: sdk: flutter + json_annotation: ^4.5.0 meta: ^1.3.0 dev_dependencies: diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm_generator/lib/src/collection_generator.dart b/packages/cloud_firestore_odm/cloud_firestore_odm_generator/lib/src/collection_generator.dart index 46d457b6c87b..5e6e002d3eeb 100644 --- a/packages/cloud_firestore_odm/cloud_firestore_odm_generator/lib/src/collection_generator.dart +++ b/packages/cloud_firestore_odm/cloud_firestore_odm_generator/lib/src/collection_generator.dart @@ -82,6 +82,11 @@ class Data { } } +const _dateTimeChecker = TypeChecker.fromRuntime(DateTime); +const _timestampChecker = TypeChecker.fromUrl( + 'package:cloud_firestore_platform_interface/src/timestamp.dart#Timestamp', +); + @immutable class CollectionGenerator extends ParserGenerator { final _collectionTemplates = >[ @@ -295,7 +300,9 @@ class CollectionGenerator extends ParserGenerator { f.type.isDartCoreInt || f.type.isDartCoreDouble || f.type.isDartCoreBool || - f.type.isDartCoreList, + f.type.isDartCoreList || + _dateTimeChecker.isAssignableFromType(f.type) || + _timestampChecker.isAssignableFromType(f.type), // TODO filter list other than LIst ) .toList(), From 8ab0bb54d0c2cfaa41009cba87cdc7ddfa7a4507 Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Mon, 2 May 2022 19:46:20 +0200 Subject: [PATCH 2/6] docs: update JsonSerializable usages to match handle custom converters --- docs/firestore-odm/defining-models.mdx | 23 +++++++++++++++-------- docs/firestore-odm/references.mdx | 2 +- docs/firestore-odm/subcollections.mdx | 4 ++-- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/docs/firestore-odm/defining-models.mdx b/docs/firestore-odm/defining-models.mdx index 5a23b98e647b..1b9ee3ddf8b2 100644 --- a/docs/firestore-odm/defining-models.mdx +++ b/docs/firestore-odm/defining-models.mdx @@ -24,7 +24,15 @@ import 'package:cloud_firestore_odm/cloud_firestore_odm.dart'; // This doesn't exist yet...! See "Next Steps" part 'user.g.dart'; -@JsonSerializable(explicitToJson: true) +/// A custom JsonSerializable annotation that supports decoding objects such +/// as Timestamps and DateTimes. +/// This variable can be reused between different models +const firestoreSerializable = JsonSerializable( + explicitToJson: true, + converters: firestoreJsonConverters, +); + +@firestoreSerializable class User { User({ required this.name, @@ -40,13 +48,12 @@ class User { The `User` model defines that a user must have a name and email as a `String` and age as an `int`. - :::caution If your model class is defined in a separate file than the Firestore reference, you will need to explicitly specify `fromJson`/`toJson` functions as followed: ```dart -@JsonSerializable(explicitToJson: true) +@firestoreSerializable class User { User({ required this.name, @@ -63,8 +70,8 @@ class User { Map toJson() => _$UserToJson(this); } ``` -::: +::: ## Model validation @@ -77,7 +84,7 @@ The ODM provides some basic annotation validators which can be used on model pro example, we can take advantage of the `Min` validator: ```dart -@JsonSerializable(explicitToJson: true) +@firestoreSerializable class User { User({ required this.name, @@ -111,7 +118,7 @@ method. Note the name of this class is generated based on the model name (for ex The following annotations are available for `int` properties: | Annotation | Description | -|------------|----------------------------------------------------| +| ---------- | -------------------------------------------------- | | `Min` | Validates a number is not less than this value. | | `Max` | Validates a number is not greater than this value. | @@ -138,7 +145,7 @@ class EmailAddressValidator implements Validator { Within the model, you can then apply the validator to the property: ```dart -@JsonSerializable(explicitToJson: true) +@firestoreSerializable class User { User({ required this.name, @@ -167,7 +174,7 @@ within the Firestore database. For example, the `users` collection in the root o corresponds to the `Users` model we defined previously: ```dart -@JsonSerializable(explicitToJson: true) +@firestoreSerializable class User { // ... } diff --git a/docs/firestore-odm/references.mdx b/docs/firestore-odm/references.mdx index 1720d8be2f87..be99c2df6562 100644 --- a/docs/firestore-odm/references.mdx +++ b/docs/firestore-odm/references.mdx @@ -118,7 +118,7 @@ Models define exactly what our data schema is, therefore this allows the ODM to useful type-safe methods for querying. ```dart -@JsonSerializable(explicitToJson: true) +@@firestoreSerializable class User { User({ required this.name, diff --git a/docs/firestore-odm/subcollections.mdx b/docs/firestore-odm/subcollections.mdx index d2f9ada401f2..0b8f33579ea5 100644 --- a/docs/firestore-odm/subcollections.mdx +++ b/docs/firestore-odm/subcollections.mdx @@ -14,7 +14,7 @@ The ODM provides support for subcollections via the `Collection` annotation. For the root collection as normal: ```dart -@JsonSerializable(explicitToJson: true) +@firestoreSerializable class User { // ... } @@ -27,7 +27,7 @@ Let's assume each user document contains a subcollection containing user address the model for an address: ```dart -@JsonSerializable(explicitToJson: true) +@firestoreSerializable class Address { // ... } From 472b150c13da6f90c23feea38df5fa66ba16c2d4 Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Tue, 3 May 2022 10:33:56 +0200 Subject: [PATCH 3/6] feat: Add support for DocumentReference properties --- .../example/lib/integration/query.dart | 11 + .../example/lib/integration/query.g.dart | 426 ++++++++++++++++++ .../test_driver/query_reference_test.dart | 29 ++ .../lib/cloud_firestore_odm.dart | 25 + .../lib/src/collection_generator.dart | 18 +- 5 files changed, 508 insertions(+), 1 deletion(-) diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/query.dart b/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/query.dart index b59ce93c2eea..0b8881670c66 100644 --- a/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/query.dart +++ b/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/query.dart @@ -32,3 +32,14 @@ class TimestampQuery { TimestampQuery(this.time); final Timestamp time; } + +@Collection('firestore-example-app/42/doc-ref') +final documentReferenceRef = DocumentReferenceQueryCollectionReference(); + +@JsonSerializable() +@FirestoreDocumentReferenceConverter() +class DocumentReferenceQuery { + DocumentReferenceQuery(this.ref); + + final DocumentReference> ref; +} diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/query.g.dart b/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/query.g.dart index da38ec978754..40009de2b754 100644 --- a/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/query.g.dart +++ b/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/query.g.dart @@ -824,6 +824,419 @@ class TimestampQueryQueryDocumentSnapshot extends FirestoreQueryDocumentSnapshot final TimestampQuery data; } +/// A collection reference object can be used for adding documents, +/// getting document references, and querying for documents +/// (using the methods inherited from Query). +abstract class DocumentReferenceQueryCollectionReference + implements + DocumentReferenceQueryQuery, + FirestoreCollectionReference { + factory DocumentReferenceQueryCollectionReference([ + FirebaseFirestore? firestore, + ]) = _$DocumentReferenceQueryCollectionReference; + + static DocumentReferenceQuery fromFirestore( + DocumentSnapshot> snapshot, + SnapshotOptions? options, + ) { + return _$DocumentReferenceQueryFromJson(snapshot.data()!); + } + + static Map toFirestore( + DocumentReferenceQuery value, + SetOptions? options, + ) { + return _$DocumentReferenceQueryToJson(value); + } + + @override + DocumentReferenceQueryDocumentReference doc([String? id]); + + /// Add a new document to this collection with the specified data, + /// assigning it a document ID automatically. + Future add( + DocumentReferenceQuery value); +} + +class _$DocumentReferenceQueryCollectionReference + extends _$DocumentReferenceQueryQuery + implements DocumentReferenceQueryCollectionReference { + factory _$DocumentReferenceQueryCollectionReference( + [FirebaseFirestore? firestore]) { + firestore ??= FirebaseFirestore.instance; + + return _$DocumentReferenceQueryCollectionReference._( + firestore.collection('firestore-example-app/42/doc-ref').withConverter( + fromFirestore: + DocumentReferenceQueryCollectionReference.fromFirestore, + toFirestore: DocumentReferenceQueryCollectionReference.toFirestore, + ), + ); + } + + _$DocumentReferenceQueryCollectionReference._( + CollectionReference reference, + ) : super(reference, reference); + + String get path => reference.path; + + @override + CollectionReference get reference => + super.reference as CollectionReference; + + @override + DocumentReferenceQueryDocumentReference doc([String? id]) { + return DocumentReferenceQueryDocumentReference( + reference.doc(id), + ); + } + + @override + Future add( + DocumentReferenceQuery value) { + return reference + .add(value) + .then((ref) => DocumentReferenceQueryDocumentReference(ref)); + } + + @override + bool operator ==(Object other) { + return other is _$DocumentReferenceQueryCollectionReference && + other.runtimeType == runtimeType && + other.reference == reference; + } + + @override + int get hashCode => Object.hash(runtimeType, reference); +} + +abstract class DocumentReferenceQueryDocumentReference + extends FirestoreDocumentReference { + factory DocumentReferenceQueryDocumentReference( + DocumentReference reference) = + _$DocumentReferenceQueryDocumentReference; + + DocumentReference get reference; + + /// A reference to the [DocumentReferenceQueryCollectionReference] containing this document. + DocumentReferenceQueryCollectionReference get parent { + return _$DocumentReferenceQueryCollectionReference(reference.firestore); + } + + @override + Stream snapshots(); + + @override + Future get([GetOptions? options]); + + @override + Future delete(); + + Future update({ + DocumentReference> ref, + }); + + Future set(DocumentReferenceQuery value); +} + +class _$DocumentReferenceQueryDocumentReference + extends FirestoreDocumentReference + implements DocumentReferenceQueryDocumentReference { + _$DocumentReferenceQueryDocumentReference(this.reference); + + @override + final DocumentReference reference; + + /// A reference to the [DocumentReferenceQueryCollectionReference] containing this document. + DocumentReferenceQueryCollectionReference get parent { + return _$DocumentReferenceQueryCollectionReference(reference.firestore); + } + + @override + Stream snapshots() { + return reference.snapshots().map((snapshot) { + return DocumentReferenceQueryDocumentSnapshot._( + snapshot, + snapshot.data(), + ); + }); + } + + @override + Future get([GetOptions? options]) { + return reference.get(options).then((snapshot) { + return DocumentReferenceQueryDocumentSnapshot._( + snapshot, + snapshot.data(), + ); + }); + } + + @override + Future delete() { + return reference.delete(); + } + + Future update({ + Object? ref = _sentinel, + }) async { + final json = { + if (ref != _sentinel) + "ref": ref as DocumentReference>, + }; + + return reference.update(json); + } + + Future set(DocumentReferenceQuery value) { + return reference.set(value); + } + + @override + bool operator ==(Object other) { + return other is DocumentReferenceQueryDocumentReference && + other.runtimeType == runtimeType && + other.parent == parent && + other.id == id; + } + + @override + int get hashCode => Object.hash(runtimeType, parent, id); +} + +class DocumentReferenceQueryDocumentSnapshot extends FirestoreDocumentSnapshot { + DocumentReferenceQueryDocumentSnapshot._( + this.snapshot, + this.data, + ); + + @override + final DocumentSnapshot snapshot; + + @override + DocumentReferenceQueryDocumentReference get reference { + return DocumentReferenceQueryDocumentReference( + snapshot.reference, + ); + } + + @override + final DocumentReferenceQuery? data; +} + +abstract class DocumentReferenceQueryQuery + implements QueryReference { + @override + DocumentReferenceQueryQuery limit(int limit); + + @override + DocumentReferenceQueryQuery limitToLast(int limit); + + DocumentReferenceQueryQuery whereRef({ + DocumentReference>? isEqualTo, + DocumentReference>? isNotEqualTo, + DocumentReference>? isLessThan, + DocumentReference>? isLessThanOrEqualTo, + DocumentReference>? isGreaterThan, + DocumentReference>? isGreaterThanOrEqualTo, + bool? isNull, + List>>? whereIn, + List>>? whereNotIn, + }); + + DocumentReferenceQueryQuery orderByRef({ + bool descending = false, + DocumentReference> startAt, + DocumentReference> startAfter, + DocumentReference> endAt, + DocumentReference> endBefore, + DocumentReferenceQueryDocumentSnapshot? startAtDocument, + DocumentReferenceQueryDocumentSnapshot? endAtDocument, + DocumentReferenceQueryDocumentSnapshot? endBeforeDocument, + DocumentReferenceQueryDocumentSnapshot? startAfterDocument, + }); +} + +class _$DocumentReferenceQueryQuery + extends QueryReference + implements DocumentReferenceQueryQuery { + _$DocumentReferenceQueryQuery( + this.reference, + this._collection, + ); + + final CollectionReference _collection; + + @override + final Query reference; + + DocumentReferenceQueryQuerySnapshot _decodeSnapshot( + QuerySnapshot snapshot, + ) { + final docs = snapshot.docs.map((e) { + return DocumentReferenceQueryQueryDocumentSnapshot._(e, e.data()); + }).toList(); + + final docChanges = snapshot.docChanges.map((change) { + return FirestoreDocumentChange( + type: change.type, + oldIndex: change.oldIndex, + newIndex: change.newIndex, + doc: DocumentReferenceQueryDocumentSnapshot._( + change.doc, change.doc.data()), + ); + }).toList(); + + return DocumentReferenceQueryQuerySnapshot._( + snapshot, + docs, + docChanges, + ); + } + + @override + Stream snapshots( + [SnapshotOptions? options]) { + return reference.snapshots().map(_decodeSnapshot); + } + + @override + Future get([GetOptions? options]) { + return reference.get(options).then(_decodeSnapshot); + } + + @override + DocumentReferenceQueryQuery limit(int limit) { + return _$DocumentReferenceQueryQuery( + reference.limit(limit), + _collection, + ); + } + + @override + DocumentReferenceQueryQuery limitToLast(int limit) { + return _$DocumentReferenceQueryQuery( + reference.limitToLast(limit), + _collection, + ); + } + + DocumentReferenceQueryQuery whereRef({ + DocumentReference>? isEqualTo, + DocumentReference>? isNotEqualTo, + DocumentReference>? isLessThan, + DocumentReference>? isLessThanOrEqualTo, + DocumentReference>? isGreaterThan, + DocumentReference>? isGreaterThanOrEqualTo, + bool? isNull, + List>>? whereIn, + List>>? whereNotIn, + }) { + return _$DocumentReferenceQueryQuery( + reference.where( + 'ref', + isEqualTo: isEqualTo, + isNotEqualTo: isNotEqualTo, + isLessThan: isLessThan, + isLessThanOrEqualTo: isLessThanOrEqualTo, + isGreaterThan: isGreaterThan, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isNull: isNull, + whereIn: whereIn, + whereNotIn: whereNotIn, + ), + _collection, + ); + } + + DocumentReferenceQueryQuery orderByRef({ + bool descending = false, + Object? startAt = _sentinel, + Object? startAfter = _sentinel, + Object? endAt = _sentinel, + Object? endBefore = _sentinel, + DocumentReferenceQueryDocumentSnapshot? startAtDocument, + DocumentReferenceQueryDocumentSnapshot? endAtDocument, + DocumentReferenceQueryDocumentSnapshot? endBeforeDocument, + DocumentReferenceQueryDocumentSnapshot? startAfterDocument, + }) { + var query = reference.orderBy('ref', descending: descending); + + if (startAtDocument != null) { + query = query.startAtDocument(startAtDocument.snapshot); + } + if (startAfterDocument != null) { + query = query.startAfterDocument(startAfterDocument.snapshot); + } + if (endAtDocument != null) { + query = query.endAtDocument(endAtDocument.snapshot); + } + if (endBeforeDocument != null) { + query = query.endBeforeDocument(endBeforeDocument.snapshot); + } + + if (startAt != _sentinel) { + query = query.startAt([startAt]); + } + if (startAfter != _sentinel) { + query = query.startAfter([startAfter]); + } + if (endAt != _sentinel) { + query = query.endAt([endAt]); + } + if (endBefore != _sentinel) { + query = query.endBefore([endBefore]); + } + + return _$DocumentReferenceQueryQuery(query, _collection); + } + + @override + bool operator ==(Object other) { + return other is _$DocumentReferenceQueryQuery && + other.runtimeType == runtimeType && + other.reference == reference; + } + + @override + int get hashCode => Object.hash(runtimeType, reference); +} + +class DocumentReferenceQueryQuerySnapshot extends FirestoreQuerySnapshot< + DocumentReferenceQueryQueryDocumentSnapshot> { + DocumentReferenceQueryQuerySnapshot._( + this.snapshot, + this.docs, + this.docChanges, + ); + + final QuerySnapshot snapshot; + + @override + final List docs; + + @override + final List> + docChanges; +} + +class DocumentReferenceQueryQueryDocumentSnapshot + extends FirestoreQueryDocumentSnapshot + implements DocumentReferenceQueryDocumentSnapshot { + DocumentReferenceQueryQueryDocumentSnapshot._(this.snapshot, this.data); + + @override + final QueryDocumentSnapshot snapshot; + + @override + DocumentReferenceQueryDocumentReference get reference { + return DocumentReferenceQueryDocumentReference(snapshot.reference); + } + + @override + final DocumentReferenceQuery data; +} + // ************************************************************************** // JsonSerializableGenerator // ************************************************************************** @@ -847,3 +1260,16 @@ Map _$TimestampQueryToJson(TimestampQuery instance) => { 'time': const FirestoreTimestampConverter().toJson(instance.time), }; + +DocumentReferenceQuery _$DocumentReferenceQueryFromJson( + Map json) => + DocumentReferenceQuery( + const FirestoreDocumentReferenceConverter() + .fromJson(json['ref'] as DocumentReference>), + ); + +Map _$DocumentReferenceQueryToJson( + DocumentReferenceQuery instance) => + { + 'ref': const FirestoreDocumentReferenceConverter().toJson(instance.ref), + }; diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm/example/test_driver/query_reference_test.dart b/packages/cloud_firestore_odm/cloud_firestore_odm/example/test_driver/query_reference_test.dart index 6956f0418a36..34ddacf33561 100644 --- a/packages/cloud_firestore_odm/cloud_firestore_odm/example/test_driver/query_reference_test.dart +++ b/packages/cloud_firestore_odm/cloud_firestore_odm/example/test_driver/query_reference_test.dart @@ -119,5 +119,34 @@ void main() { expect(snapshot.docs[0].data.time, Timestamp.fromDate(DateTime(2000))); expect(snapshot.docs[1].data.time, Timestamp.fromDate(DateTime(2010))); }); + + test('supports DocumentReference', () async { + final ref = await initializeTest(documentReferenceRef); + + await ref.add( + DocumentReferenceQuery(FirebaseFirestore.instance.doc('foo/a')), + ); + await ref.add( + DocumentReferenceQuery(FirebaseFirestore.instance.doc('foo/b')), + ); + await ref.add( + DocumentReferenceQuery(FirebaseFirestore.instance.doc('foo/c')), + ); + + final snapshot = await ref + .orderByRef(startAt: FirebaseFirestore.instance.doc('foo/b')) + .get(); + + expect(snapshot.docs.length, 2); + + expect( + snapshot.docs[0].data.ref, + FirebaseFirestore.instance.doc('foo/b'), + ); + expect( + snapshot.docs[1].data.ref, + FirebaseFirestore.instance.doc('foo/c'), + ); + }); }); } diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm/lib/cloud_firestore_odm.dart b/packages/cloud_firestore_odm/cloud_firestore_odm/lib/cloud_firestore_odm.dart index 7ff963c24579..9a7e7a29141b 100644 --- a/packages/cloud_firestore_odm/cloud_firestore_odm/lib/cloud_firestore_odm.dart +++ b/packages/cloud_firestore_odm/cloud_firestore_odm/lib/cloud_firestore_odm.dart @@ -46,3 +46,28 @@ class FirestoreDateTimeConverter extends JsonConverter { @override Timestamp toJson(DateTime object) => Timestamp.fromDate(object); } + +/// A [JsonConverter] that adds support for [DocumentReference] objects within +/// ODM models. +/// +/// The document reference must receive a `Map` as generic +/// argument. References coming from `withConverter` are not supported. +class FirestoreDocumentReferenceConverter extends JsonConverter< + DocumentReference>, + DocumentReference>> { + const FirestoreDocumentReferenceConverter(); + + @override + DocumentReference> fromJson( + DocumentReference> json, + ) { + return json; + } + + @override + DocumentReference> toJson( + DocumentReference> object, + ) { + return object; + } +} diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm_generator/lib/src/collection_generator.dart b/packages/cloud_firestore_odm/cloud_firestore_odm_generator/lib/src/collection_generator.dart index 5e6e002d3eeb..2a84c88e7a32 100644 --- a/packages/cloud_firestore_odm/cloud_firestore_odm_generator/lib/src/collection_generator.dart +++ b/packages/cloud_firestore_odm/cloud_firestore_odm_generator/lib/src/collection_generator.dart @@ -83,10 +83,15 @@ class Data { } const _dateTimeChecker = TypeChecker.fromRuntime(DateTime); + const _timestampChecker = TypeChecker.fromUrl( 'package:cloud_firestore_platform_interface/src/timestamp.dart#Timestamp', ); +const _docRefChecker = TypeChecker.fromUrl( + 'package:cloud_firestore/src/document_reference.dart#DocumentReference', +); + @immutable class CollectionGenerator extends ParserGenerator { final _collectionTemplates = >[ @@ -302,7 +307,8 @@ class CollectionGenerator extends ParserGenerator { f.type.isDartCoreBool || f.type.isDartCoreList || _dateTimeChecker.isAssignableFromType(f.type) || - _timestampChecker.isAssignableFromType(f.type), + _timestampChecker.isAssignableFromType(f.type) || + f.type.isJsonDocumentReference, // TODO filter list other than LIst ) .toList(), @@ -342,3 +348,13 @@ const _sentinel = _Sentinel(); @override void parseGlobalData(LibraryElement library) {} } + +extension on DartType { + bool get isJsonDocumentReference { + return element?.librarySource?.uri.scheme == 'package' && + const {'cloud_firestore'} + .contains(element?.librarySource?.uri.pathSegments.first) && + element?.name == 'DocumentReference' && + (this as InterfaceType).typeArguments.single.isDartCoreMap; + } +} From 19e94e3738a1f61f3fbb735d0b0938775bf950a1 Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Tue, 3 May 2022 10:55:56 +0200 Subject: [PATCH 4/6] Remove unused variable --- .../lib/src/collection_generator.dart | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm_generator/lib/src/collection_generator.dart b/packages/cloud_firestore_odm/cloud_firestore_odm_generator/lib/src/collection_generator.dart index 2a84c88e7a32..d38b2beaec5e 100644 --- a/packages/cloud_firestore_odm/cloud_firestore_odm_generator/lib/src/collection_generator.dart +++ b/packages/cloud_firestore_odm/cloud_firestore_odm_generator/lib/src/collection_generator.dart @@ -88,10 +88,6 @@ const _timestampChecker = TypeChecker.fromUrl( 'package:cloud_firestore_platform_interface/src/timestamp.dart#Timestamp', ); -const _docRefChecker = TypeChecker.fromUrl( - 'package:cloud_firestore/src/document_reference.dart#DocumentReference', -); - @immutable class CollectionGenerator extends ParserGenerator { final _collectionTemplates = >[ From 54d6aaa246380a9a416b16c01f83755dd0f603c1 Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Wed, 6 Jul 2022 12:04:48 +0200 Subject: [PATCH 5/6] feat: add geopoint support --- .../example/lib/integration/query.dart | 10 + .../example/lib/integration/query.g.dart | 1038 +++++++++++++++-- .../test_driver/query_reference_test.dart | 64 +- .../lib/cloud_firestore_odm.dart | 11 + .../lib/src/collection_generator.dart | 8 +- 5 files changed, 990 insertions(+), 141 deletions(-) diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/query.dart b/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/query.dart index 0b8881670c66..a5c462617b9a 100644 --- a/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/query.dart +++ b/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/query.dart @@ -33,6 +33,16 @@ class TimestampQuery { final Timestamp time; } +@Collection('firestore-example-app/42/geopoint-time') +final geoPointQueryRef = GeoPointQueryCollectionReference(); + +@JsonSerializable() +@FirestoreGeoPointConverter() +class GeoPointQuery { + GeoPointQuery(this.point); + final GeoPoint point; +} + @Collection('firestore-example-app/42/doc-ref') final documentReferenceRef = DocumentReferenceQueryCollectionReference(); diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/query.g.dart b/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/query.g.dart index 40009de2b754..acddef9b87a2 100644 --- a/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/query.g.dart +++ b/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/query.g.dart @@ -75,6 +75,10 @@ class _$DateTimeQueryCollectionReference extends _$DateTimeQueryQuery @override DateTimeQueryDocumentReference doc([String? id]) { + assert( + id == null || id.split('/').length == 1, + 'The document ID cannot be from a different collection', + ); return DateTimeQueryDocumentReference( reference.doc(id), ); @@ -219,6 +223,17 @@ abstract class DateTimeQueryQuery @override DateTimeQueryQuery limitToLast(int limit); + DateTimeQueryQuery whereDocumentId({ + String? isEqualTo, + String? isNotEqualTo, + String? isLessThan, + String? isLessThanOrEqualTo, + String? isGreaterThan, + String? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }); DateTimeQueryQuery whereTime({ DateTime? isEqualTo, DateTime? isNotEqualTo, @@ -231,6 +246,18 @@ abstract class DateTimeQueryQuery List? whereNotIn, }); + DateTimeQueryQuery orderByDocumentId({ + bool descending = false, + String startAt, + String startAfter, + String endAt, + String endBefore, + DateTimeQueryDocumentSnapshot? startAtDocument, + DateTimeQueryDocumentSnapshot? endAtDocument, + DateTimeQueryDocumentSnapshot? endBeforeDocument, + DateTimeQueryDocumentSnapshot? startAfterDocument, + }); + DateTimeQueryQuery orderByTime({ bool descending = false, DateTime startAt, @@ -305,6 +332,34 @@ class _$DateTimeQueryQuery extends QueryReference ); } + DateTimeQueryQuery whereDocumentId({ + String? isEqualTo, + String? isNotEqualTo, + String? isLessThan, + String? isLessThanOrEqualTo, + String? isGreaterThan, + String? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }) { + return _$DateTimeQueryQuery( + reference.where( + FieldPath.documentId, + isEqualTo: isEqualTo, + isNotEqualTo: isNotEqualTo, + isLessThan: isLessThan, + isLessThanOrEqualTo: isLessThanOrEqualTo, + isGreaterThan: isGreaterThan, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isNull: isNull, + whereIn: whereIn, + whereNotIn: whereNotIn, + ), + _collection, + ); + } + DateTimeQueryQuery whereTime({ DateTime? isEqualTo, DateTime? isNotEqualTo, @@ -318,7 +373,7 @@ class _$DateTimeQueryQuery extends QueryReference }) { return _$DateTimeQueryQuery( reference.where( - 'time', + "time", isEqualTo: isEqualTo, isNotEqualTo: isNotEqualTo, isLessThan: isLessThan, @@ -333,6 +388,48 @@ class _$DateTimeQueryQuery extends QueryReference ); } + DateTimeQueryQuery orderByDocumentId({ + bool descending = false, + Object? startAt = _sentinel, + Object? startAfter = _sentinel, + Object? endAt = _sentinel, + Object? endBefore = _sentinel, + DateTimeQueryDocumentSnapshot? startAtDocument, + DateTimeQueryDocumentSnapshot? endAtDocument, + DateTimeQueryDocumentSnapshot? endBeforeDocument, + DateTimeQueryDocumentSnapshot? startAfterDocument, + }) { + var query = reference.orderBy(FieldPath.documentId, descending: descending); + + if (startAtDocument != null) { + query = query.startAtDocument(startAtDocument.snapshot); + } + if (startAfterDocument != null) { + query = query.startAfterDocument(startAfterDocument.snapshot); + } + if (endAtDocument != null) { + query = query.endAtDocument(endAtDocument.snapshot); + } + if (endBeforeDocument != null) { + query = query.endBeforeDocument(endBeforeDocument.snapshot); + } + + if (startAt != _sentinel) { + query = query.startAt([startAt]); + } + if (startAfter != _sentinel) { + query = query.startAfter([startAfter]); + } + if (endAt != _sentinel) { + query = query.endAt([endAt]); + } + if (endBefore != _sentinel) { + query = query.endBefore([endBefore]); + } + + return _$DateTimeQueryQuery(query, _collection); + } + DateTimeQueryQuery orderByTime({ bool descending = false, Object? startAt = _sentinel, @@ -344,7 +441,7 @@ class _$DateTimeQueryQuery extends QueryReference DateTimeQueryDocumentSnapshot? endBeforeDocument, DateTimeQueryDocumentSnapshot? startAfterDocument, }) { - var query = reference.orderBy('time', descending: descending); + var query = reference.orderBy("time", descending: descending); if (startAtDocument != null) { query = query.startAtDocument(startAtDocument.snapshot); @@ -479,6 +576,10 @@ class _$TimestampQueryCollectionReference extends _$TimestampQueryQuery @override TimestampQueryDocumentReference doc([String? id]) { + assert( + id == null || id.split('/').length == 1, + 'The document ID cannot be from a different collection', + ); return TimestampQueryDocumentReference( reference.doc(id), ); @@ -623,6 +724,17 @@ abstract class TimestampQueryQuery @override TimestampQueryQuery limitToLast(int limit); + TimestampQueryQuery whereDocumentId({ + String? isEqualTo, + String? isNotEqualTo, + String? isLessThan, + String? isLessThanOrEqualTo, + String? isGreaterThan, + String? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }); TimestampQueryQuery whereTime({ Timestamp? isEqualTo, Timestamp? isNotEqualTo, @@ -635,6 +747,18 @@ abstract class TimestampQueryQuery List? whereNotIn, }); + TimestampQueryQuery orderByDocumentId({ + bool descending = false, + String startAt, + String startAfter, + String endAt, + String endBefore, + TimestampQueryDocumentSnapshot? startAtDocument, + TimestampQueryDocumentSnapshot? endAtDocument, + TimestampQueryDocumentSnapshot? endBeforeDocument, + TimestampQueryDocumentSnapshot? startAfterDocument, + }); + TimestampQueryQuery orderByTime({ bool descending = false, Timestamp startAt, @@ -709,6 +833,34 @@ class _$TimestampQueryQuery extends QueryReference ); } + TimestampQueryQuery whereDocumentId({ + String? isEqualTo, + String? isNotEqualTo, + String? isLessThan, + String? isLessThanOrEqualTo, + String? isGreaterThan, + String? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }) { + return _$TimestampQueryQuery( + reference.where( + FieldPath.documentId, + isEqualTo: isEqualTo, + isNotEqualTo: isNotEqualTo, + isLessThan: isLessThan, + isLessThanOrEqualTo: isLessThanOrEqualTo, + isGreaterThan: isGreaterThan, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isNull: isNull, + whereIn: whereIn, + whereNotIn: whereNotIn, + ), + _collection, + ); + } + TimestampQueryQuery whereTime({ Timestamp? isEqualTo, Timestamp? isNotEqualTo, @@ -722,7 +874,7 @@ class _$TimestampQueryQuery extends QueryReference }) { return _$TimestampQueryQuery( reference.where( - 'time', + "time", isEqualTo: isEqualTo, isNotEqualTo: isNotEqualTo, isLessThan: isLessThan, @@ -737,6 +889,48 @@ class _$TimestampQueryQuery extends QueryReference ); } + TimestampQueryQuery orderByDocumentId({ + bool descending = false, + Object? startAt = _sentinel, + Object? startAfter = _sentinel, + Object? endAt = _sentinel, + Object? endBefore = _sentinel, + TimestampQueryDocumentSnapshot? startAtDocument, + TimestampQueryDocumentSnapshot? endAtDocument, + TimestampQueryDocumentSnapshot? endBeforeDocument, + TimestampQueryDocumentSnapshot? startAfterDocument, + }) { + var query = reference.orderBy(FieldPath.documentId, descending: descending); + + if (startAtDocument != null) { + query = query.startAtDocument(startAtDocument.snapshot); + } + if (startAfterDocument != null) { + query = query.startAfterDocument(startAfterDocument.snapshot); + } + if (endAtDocument != null) { + query = query.endAtDocument(endAtDocument.snapshot); + } + if (endBeforeDocument != null) { + query = query.endBeforeDocument(endBeforeDocument.snapshot); + } + + if (startAt != _sentinel) { + query = query.startAt([startAt]); + } + if (startAfter != _sentinel) { + query = query.startAfter([startAfter]); + } + if (endAt != _sentinel) { + query = query.endAt([endAt]); + } + if (endBefore != _sentinel) { + query = query.endBefore([endBefore]); + } + + return _$TimestampQueryQuery(query, _collection); + } + TimestampQueryQuery orderByTime({ bool descending = false, Object? startAt = _sentinel, @@ -748,7 +942,7 @@ class _$TimestampQueryQuery extends QueryReference TimestampQueryDocumentSnapshot? endBeforeDocument, TimestampQueryDocumentSnapshot? startAfterDocument, }) { - var query = reference.orderBy('time', descending: descending); + var query = reference.orderBy("time", descending: descending); if (startAtDocument != null) { query = query.startAtDocument(startAtDocument.snapshot); @@ -827,81 +1021,82 @@ class TimestampQueryQueryDocumentSnapshot extends FirestoreQueryDocumentSnapshot /// A collection reference object can be used for adding documents, /// getting document references, and querying for documents /// (using the methods inherited from Query). -abstract class DocumentReferenceQueryCollectionReference +abstract class GeoPointQueryCollectionReference implements - DocumentReferenceQueryQuery, - FirestoreCollectionReference { - factory DocumentReferenceQueryCollectionReference([ + GeoPointQueryQuery, + FirestoreCollectionReference { + factory GeoPointQueryCollectionReference([ FirebaseFirestore? firestore, - ]) = _$DocumentReferenceQueryCollectionReference; + ]) = _$GeoPointQueryCollectionReference; - static DocumentReferenceQuery fromFirestore( + static GeoPointQuery fromFirestore( DocumentSnapshot> snapshot, SnapshotOptions? options, ) { - return _$DocumentReferenceQueryFromJson(snapshot.data()!); + return _$GeoPointQueryFromJson(snapshot.data()!); } static Map toFirestore( - DocumentReferenceQuery value, + GeoPointQuery value, SetOptions? options, ) { - return _$DocumentReferenceQueryToJson(value); + return _$GeoPointQueryToJson(value); } @override - DocumentReferenceQueryDocumentReference doc([String? id]); + GeoPointQueryDocumentReference doc([String? id]); /// Add a new document to this collection with the specified data, /// assigning it a document ID automatically. - Future add( - DocumentReferenceQuery value); + Future add(GeoPointQuery value); } -class _$DocumentReferenceQueryCollectionReference - extends _$DocumentReferenceQueryQuery - implements DocumentReferenceQueryCollectionReference { - factory _$DocumentReferenceQueryCollectionReference( - [FirebaseFirestore? firestore]) { +class _$GeoPointQueryCollectionReference extends _$GeoPointQueryQuery + implements GeoPointQueryCollectionReference { + factory _$GeoPointQueryCollectionReference([FirebaseFirestore? firestore]) { firestore ??= FirebaseFirestore.instance; - return _$DocumentReferenceQueryCollectionReference._( - firestore.collection('firestore-example-app/42/doc-ref').withConverter( - fromFirestore: - DocumentReferenceQueryCollectionReference.fromFirestore, - toFirestore: DocumentReferenceQueryCollectionReference.toFirestore, + return _$GeoPointQueryCollectionReference._( + firestore + .collection('firestore-example-app/42/geopoint-time') + .withConverter( + fromFirestore: GeoPointQueryCollectionReference.fromFirestore, + toFirestore: GeoPointQueryCollectionReference.toFirestore, ), ); } - _$DocumentReferenceQueryCollectionReference._( - CollectionReference reference, + _$GeoPointQueryCollectionReference._( + CollectionReference reference, ) : super(reference, reference); String get path => reference.path; @override - CollectionReference get reference => - super.reference as CollectionReference; + CollectionReference get reference => + super.reference as CollectionReference; @override - DocumentReferenceQueryDocumentReference doc([String? id]) { - return DocumentReferenceQueryDocumentReference( + GeoPointQueryDocumentReference doc([String? id]) { + assert( + id == null || id.split('/').length == 1, + 'The document ID cannot be from a different collection', + ); + return GeoPointQueryDocumentReference( reference.doc(id), ); } @override - Future add( - DocumentReferenceQuery value) { + Future add(GeoPointQuery value) { return reference .add(value) - .then((ref) => DocumentReferenceQueryDocumentReference(ref)); + .then((ref) => GeoPointQueryDocumentReference(ref)); } @override bool operator ==(Object other) { - return other is _$DocumentReferenceQueryCollectionReference && + return other is _$GeoPointQueryCollectionReference && other.runtimeType == runtimeType && other.reference == reference; } @@ -910,52 +1105,52 @@ class _$DocumentReferenceQueryCollectionReference int get hashCode => Object.hash(runtimeType, reference); } -abstract class DocumentReferenceQueryDocumentReference - extends FirestoreDocumentReference { - factory DocumentReferenceQueryDocumentReference( - DocumentReference reference) = - _$DocumentReferenceQueryDocumentReference; +abstract class GeoPointQueryDocumentReference + extends FirestoreDocumentReference { + factory GeoPointQueryDocumentReference( + DocumentReference reference) = + _$GeoPointQueryDocumentReference; - DocumentReference get reference; + DocumentReference get reference; - /// A reference to the [DocumentReferenceQueryCollectionReference] containing this document. - DocumentReferenceQueryCollectionReference get parent { - return _$DocumentReferenceQueryCollectionReference(reference.firestore); + /// A reference to the [GeoPointQueryCollectionReference] containing this document. + GeoPointQueryCollectionReference get parent { + return _$GeoPointQueryCollectionReference(reference.firestore); } @override - Stream snapshots(); + Stream snapshots(); @override - Future get([GetOptions? options]); + Future get([GetOptions? options]); @override Future delete(); Future update({ - DocumentReference> ref, + GeoPoint point, }); - Future set(DocumentReferenceQuery value); + Future set(GeoPointQuery value); } -class _$DocumentReferenceQueryDocumentReference - extends FirestoreDocumentReference - implements DocumentReferenceQueryDocumentReference { - _$DocumentReferenceQueryDocumentReference(this.reference); +class _$GeoPointQueryDocumentReference + extends FirestoreDocumentReference + implements GeoPointQueryDocumentReference { + _$GeoPointQueryDocumentReference(this.reference); @override - final DocumentReference reference; + final DocumentReference reference; - /// A reference to the [DocumentReferenceQueryCollectionReference] containing this document. - DocumentReferenceQueryCollectionReference get parent { - return _$DocumentReferenceQueryCollectionReference(reference.firestore); + /// A reference to the [GeoPointQueryCollectionReference] containing this document. + GeoPointQueryCollectionReference get parent { + return _$GeoPointQueryCollectionReference(reference.firestore); } @override - Stream snapshots() { + Stream snapshots() { return reference.snapshots().map((snapshot) { - return DocumentReferenceQueryDocumentSnapshot._( + return GeoPointQueryDocumentSnapshot._( snapshot, snapshot.data(), ); @@ -963,9 +1158,9 @@ class _$DocumentReferenceQueryDocumentReference } @override - Future get([GetOptions? options]) { + Future get([GetOptions? options]) { return reference.get(options).then((snapshot) { - return DocumentReferenceQueryDocumentSnapshot._( + return GeoPointQueryDocumentSnapshot._( snapshot, snapshot.data(), ); @@ -978,23 +1173,22 @@ class _$DocumentReferenceQueryDocumentReference } Future update({ - Object? ref = _sentinel, + Object? point = _sentinel, }) async { final json = { - if (ref != _sentinel) - "ref": ref as DocumentReference>, + if (point != _sentinel) "point": point as GeoPoint, }; return reference.update(json); } - Future set(DocumentReferenceQuery value) { + Future set(GeoPointQuery value) { return reference.set(value); } @override bool operator ==(Object other) { - return other is DocumentReferenceQueryDocumentReference && + return other is GeoPointQueryDocumentReference && other.runtimeType == runtimeType && other.parent == parent && other.id == id; @@ -1004,63 +1198,85 @@ class _$DocumentReferenceQueryDocumentReference int get hashCode => Object.hash(runtimeType, parent, id); } -class DocumentReferenceQueryDocumentSnapshot extends FirestoreDocumentSnapshot { - DocumentReferenceQueryDocumentSnapshot._( +class GeoPointQueryDocumentSnapshot extends FirestoreDocumentSnapshot { + GeoPointQueryDocumentSnapshot._( this.snapshot, this.data, ); @override - final DocumentSnapshot snapshot; + final DocumentSnapshot snapshot; @override - DocumentReferenceQueryDocumentReference get reference { - return DocumentReferenceQueryDocumentReference( + GeoPointQueryDocumentReference get reference { + return GeoPointQueryDocumentReference( snapshot.reference, ); } @override - final DocumentReferenceQuery? data; + final GeoPointQuery? data; } -abstract class DocumentReferenceQueryQuery - implements QueryReference { +abstract class GeoPointQueryQuery + implements QueryReference { @override - DocumentReferenceQueryQuery limit(int limit); + GeoPointQueryQuery limit(int limit); @override - DocumentReferenceQueryQuery limitToLast(int limit); + GeoPointQueryQuery limitToLast(int limit); - DocumentReferenceQueryQuery whereRef({ - DocumentReference>? isEqualTo, - DocumentReference>? isNotEqualTo, - DocumentReference>? isLessThan, - DocumentReference>? isLessThanOrEqualTo, - DocumentReference>? isGreaterThan, - DocumentReference>? isGreaterThanOrEqualTo, + GeoPointQueryQuery whereDocumentId({ + String? isEqualTo, + String? isNotEqualTo, + String? isLessThan, + String? isLessThanOrEqualTo, + String? isGreaterThan, + String? isGreaterThanOrEqualTo, bool? isNull, - List>>? whereIn, - List>>? whereNotIn, + List? whereIn, + List? whereNotIn, + }); + GeoPointQueryQuery wherePoint({ + GeoPoint? isEqualTo, + GeoPoint? isNotEqualTo, + GeoPoint? isLessThan, + GeoPoint? isLessThanOrEqualTo, + GeoPoint? isGreaterThan, + GeoPoint? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, }); - DocumentReferenceQueryQuery orderByRef({ + GeoPointQueryQuery orderByDocumentId({ bool descending = false, - DocumentReference> startAt, - DocumentReference> startAfter, - DocumentReference> endAt, - DocumentReference> endBefore, - DocumentReferenceQueryDocumentSnapshot? startAtDocument, - DocumentReferenceQueryDocumentSnapshot? endAtDocument, - DocumentReferenceQueryDocumentSnapshot? endBeforeDocument, - DocumentReferenceQueryDocumentSnapshot? startAfterDocument, + String startAt, + String startAfter, + String endAt, + String endBefore, + GeoPointQueryDocumentSnapshot? startAtDocument, + GeoPointQueryDocumentSnapshot? endAtDocument, + GeoPointQueryDocumentSnapshot? endBeforeDocument, + GeoPointQueryDocumentSnapshot? startAfterDocument, + }); + + GeoPointQueryQuery orderByPoint({ + bool descending = false, + GeoPoint startAt, + GeoPoint startAfter, + GeoPoint endAt, + GeoPoint endBefore, + GeoPointQueryDocumentSnapshot? startAtDocument, + GeoPointQueryDocumentSnapshot? endAtDocument, + GeoPointQueryDocumentSnapshot? endBeforeDocument, + GeoPointQueryDocumentSnapshot? startAfterDocument, }); } -class _$DocumentReferenceQueryQuery - extends QueryReference - implements DocumentReferenceQueryQuery { - _$DocumentReferenceQueryQuery( +class _$GeoPointQueryQuery extends QueryReference + implements GeoPointQueryQuery { + _$GeoPointQueryQuery( this.reference, this._collection, ); @@ -1068,26 +1284,25 @@ class _$DocumentReferenceQueryQuery final CollectionReference _collection; @override - final Query reference; + final Query reference; - DocumentReferenceQueryQuerySnapshot _decodeSnapshot( - QuerySnapshot snapshot, + GeoPointQueryQuerySnapshot _decodeSnapshot( + QuerySnapshot snapshot, ) { final docs = snapshot.docs.map((e) { - return DocumentReferenceQueryQueryDocumentSnapshot._(e, e.data()); + return GeoPointQueryQueryDocumentSnapshot._(e, e.data()); }).toList(); final docChanges = snapshot.docChanges.map((change) { - return FirestoreDocumentChange( + return FirestoreDocumentChange( type: change.type, oldIndex: change.oldIndex, newIndex: change.newIndex, - doc: DocumentReferenceQueryDocumentSnapshot._( - change.doc, change.doc.data()), + doc: GeoPointQueryDocumentSnapshot._(change.doc, change.doc.data()), ); }).toList(); - return DocumentReferenceQueryQuerySnapshot._( + return GeoPointQueryQuerySnapshot._( snapshot, docs, docChanges, @@ -1095,35 +1310,570 @@ class _$DocumentReferenceQueryQuery } @override - Stream snapshots( - [SnapshotOptions? options]) { + Stream snapshots([SnapshotOptions? options]) { return reference.snapshots().map(_decodeSnapshot); } @override - Future get([GetOptions? options]) { + Future get([GetOptions? options]) { return reference.get(options).then(_decodeSnapshot); } @override - DocumentReferenceQueryQuery limit(int limit) { - return _$DocumentReferenceQueryQuery( + GeoPointQueryQuery limit(int limit) { + return _$GeoPointQueryQuery( reference.limit(limit), _collection, ); } @override - DocumentReferenceQueryQuery limitToLast(int limit) { - return _$DocumentReferenceQueryQuery( + GeoPointQueryQuery limitToLast(int limit) { + return _$GeoPointQueryQuery( reference.limitToLast(limit), _collection, ); } - DocumentReferenceQueryQuery whereRef({ - DocumentReference>? isEqualTo, - DocumentReference>? isNotEqualTo, + GeoPointQueryQuery whereDocumentId({ + String? isEqualTo, + String? isNotEqualTo, + String? isLessThan, + String? isLessThanOrEqualTo, + String? isGreaterThan, + String? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }) { + return _$GeoPointQueryQuery( + reference.where( + FieldPath.documentId, + isEqualTo: isEqualTo, + isNotEqualTo: isNotEqualTo, + isLessThan: isLessThan, + isLessThanOrEqualTo: isLessThanOrEqualTo, + isGreaterThan: isGreaterThan, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isNull: isNull, + whereIn: whereIn, + whereNotIn: whereNotIn, + ), + _collection, + ); + } + + GeoPointQueryQuery wherePoint({ + GeoPoint? isEqualTo, + GeoPoint? isNotEqualTo, + GeoPoint? isLessThan, + GeoPoint? isLessThanOrEqualTo, + GeoPoint? isGreaterThan, + GeoPoint? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }) { + return _$GeoPointQueryQuery( + reference.where( + "point", + isEqualTo: isEqualTo, + isNotEqualTo: isNotEqualTo, + isLessThan: isLessThan, + isLessThanOrEqualTo: isLessThanOrEqualTo, + isGreaterThan: isGreaterThan, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isNull: isNull, + whereIn: whereIn, + whereNotIn: whereNotIn, + ), + _collection, + ); + } + + GeoPointQueryQuery orderByDocumentId({ + bool descending = false, + Object? startAt = _sentinel, + Object? startAfter = _sentinel, + Object? endAt = _sentinel, + Object? endBefore = _sentinel, + GeoPointQueryDocumentSnapshot? startAtDocument, + GeoPointQueryDocumentSnapshot? endAtDocument, + GeoPointQueryDocumentSnapshot? endBeforeDocument, + GeoPointQueryDocumentSnapshot? startAfterDocument, + }) { + var query = reference.orderBy(FieldPath.documentId, descending: descending); + + if (startAtDocument != null) { + query = query.startAtDocument(startAtDocument.snapshot); + } + if (startAfterDocument != null) { + query = query.startAfterDocument(startAfterDocument.snapshot); + } + if (endAtDocument != null) { + query = query.endAtDocument(endAtDocument.snapshot); + } + if (endBeforeDocument != null) { + query = query.endBeforeDocument(endBeforeDocument.snapshot); + } + + if (startAt != _sentinel) { + query = query.startAt([startAt]); + } + if (startAfter != _sentinel) { + query = query.startAfter([startAfter]); + } + if (endAt != _sentinel) { + query = query.endAt([endAt]); + } + if (endBefore != _sentinel) { + query = query.endBefore([endBefore]); + } + + return _$GeoPointQueryQuery(query, _collection); + } + + GeoPointQueryQuery orderByPoint({ + bool descending = false, + Object? startAt = _sentinel, + Object? startAfter = _sentinel, + Object? endAt = _sentinel, + Object? endBefore = _sentinel, + GeoPointQueryDocumentSnapshot? startAtDocument, + GeoPointQueryDocumentSnapshot? endAtDocument, + GeoPointQueryDocumentSnapshot? endBeforeDocument, + GeoPointQueryDocumentSnapshot? startAfterDocument, + }) { + var query = reference.orderBy("point", descending: descending); + + if (startAtDocument != null) { + query = query.startAtDocument(startAtDocument.snapshot); + } + if (startAfterDocument != null) { + query = query.startAfterDocument(startAfterDocument.snapshot); + } + if (endAtDocument != null) { + query = query.endAtDocument(endAtDocument.snapshot); + } + if (endBeforeDocument != null) { + query = query.endBeforeDocument(endBeforeDocument.snapshot); + } + + if (startAt != _sentinel) { + query = query.startAt([startAt]); + } + if (startAfter != _sentinel) { + query = query.startAfter([startAfter]); + } + if (endAt != _sentinel) { + query = query.endAt([endAt]); + } + if (endBefore != _sentinel) { + query = query.endBefore([endBefore]); + } + + return _$GeoPointQueryQuery(query, _collection); + } + + @override + bool operator ==(Object other) { + return other is _$GeoPointQueryQuery && + other.runtimeType == runtimeType && + other.reference == reference; + } + + @override + int get hashCode => Object.hash(runtimeType, reference); +} + +class GeoPointQueryQuerySnapshot + extends FirestoreQuerySnapshot { + GeoPointQueryQuerySnapshot._( + this.snapshot, + this.docs, + this.docChanges, + ); + + final QuerySnapshot snapshot; + + @override + final List docs; + + @override + final List> docChanges; +} + +class GeoPointQueryQueryDocumentSnapshot extends FirestoreQueryDocumentSnapshot + implements GeoPointQueryDocumentSnapshot { + GeoPointQueryQueryDocumentSnapshot._(this.snapshot, this.data); + + @override + final QueryDocumentSnapshot snapshot; + + @override + GeoPointQueryDocumentReference get reference { + return GeoPointQueryDocumentReference(snapshot.reference); + } + + @override + final GeoPointQuery data; +} + +/// A collection reference object can be used for adding documents, +/// getting document references, and querying for documents +/// (using the methods inherited from Query). +abstract class DocumentReferenceQueryCollectionReference + implements + DocumentReferenceQueryQuery, + FirestoreCollectionReference { + factory DocumentReferenceQueryCollectionReference([ + FirebaseFirestore? firestore, + ]) = _$DocumentReferenceQueryCollectionReference; + + static DocumentReferenceQuery fromFirestore( + DocumentSnapshot> snapshot, + SnapshotOptions? options, + ) { + return _$DocumentReferenceQueryFromJson(snapshot.data()!); + } + + static Map toFirestore( + DocumentReferenceQuery value, + SetOptions? options, + ) { + return _$DocumentReferenceQueryToJson(value); + } + + @override + DocumentReferenceQueryDocumentReference doc([String? id]); + + /// Add a new document to this collection with the specified data, + /// assigning it a document ID automatically. + Future add( + DocumentReferenceQuery value); +} + +class _$DocumentReferenceQueryCollectionReference + extends _$DocumentReferenceQueryQuery + implements DocumentReferenceQueryCollectionReference { + factory _$DocumentReferenceQueryCollectionReference( + [FirebaseFirestore? firestore]) { + firestore ??= FirebaseFirestore.instance; + + return _$DocumentReferenceQueryCollectionReference._( + firestore.collection('firestore-example-app/42/doc-ref').withConverter( + fromFirestore: + DocumentReferenceQueryCollectionReference.fromFirestore, + toFirestore: DocumentReferenceQueryCollectionReference.toFirestore, + ), + ); + } + + _$DocumentReferenceQueryCollectionReference._( + CollectionReference reference, + ) : super(reference, reference); + + String get path => reference.path; + + @override + CollectionReference get reference => + super.reference as CollectionReference; + + @override + DocumentReferenceQueryDocumentReference doc([String? id]) { + assert( + id == null || id.split('/').length == 1, + 'The document ID cannot be from a different collection', + ); + return DocumentReferenceQueryDocumentReference( + reference.doc(id), + ); + } + + @override + Future add( + DocumentReferenceQuery value) { + return reference + .add(value) + .then((ref) => DocumentReferenceQueryDocumentReference(ref)); + } + + @override + bool operator ==(Object other) { + return other is _$DocumentReferenceQueryCollectionReference && + other.runtimeType == runtimeType && + other.reference == reference; + } + + @override + int get hashCode => Object.hash(runtimeType, reference); +} + +abstract class DocumentReferenceQueryDocumentReference + extends FirestoreDocumentReference { + factory DocumentReferenceQueryDocumentReference( + DocumentReference reference) = + _$DocumentReferenceQueryDocumentReference; + + DocumentReference get reference; + + /// A reference to the [DocumentReferenceQueryCollectionReference] containing this document. + DocumentReferenceQueryCollectionReference get parent { + return _$DocumentReferenceQueryCollectionReference(reference.firestore); + } + + @override + Stream snapshots(); + + @override + Future get([GetOptions? options]); + + @override + Future delete(); + + Future update({ + DocumentReference> ref, + }); + + Future set(DocumentReferenceQuery value); +} + +class _$DocumentReferenceQueryDocumentReference + extends FirestoreDocumentReference + implements DocumentReferenceQueryDocumentReference { + _$DocumentReferenceQueryDocumentReference(this.reference); + + @override + final DocumentReference reference; + + /// A reference to the [DocumentReferenceQueryCollectionReference] containing this document. + DocumentReferenceQueryCollectionReference get parent { + return _$DocumentReferenceQueryCollectionReference(reference.firestore); + } + + @override + Stream snapshots() { + return reference.snapshots().map((snapshot) { + return DocumentReferenceQueryDocumentSnapshot._( + snapshot, + snapshot.data(), + ); + }); + } + + @override + Future get([GetOptions? options]) { + return reference.get(options).then((snapshot) { + return DocumentReferenceQueryDocumentSnapshot._( + snapshot, + snapshot.data(), + ); + }); + } + + @override + Future delete() { + return reference.delete(); + } + + Future update({ + Object? ref = _sentinel, + }) async { + final json = { + if (ref != _sentinel) + "ref": ref as DocumentReference>, + }; + + return reference.update(json); + } + + Future set(DocumentReferenceQuery value) { + return reference.set(value); + } + + @override + bool operator ==(Object other) { + return other is DocumentReferenceQueryDocumentReference && + other.runtimeType == runtimeType && + other.parent == parent && + other.id == id; + } + + @override + int get hashCode => Object.hash(runtimeType, parent, id); +} + +class DocumentReferenceQueryDocumentSnapshot extends FirestoreDocumentSnapshot { + DocumentReferenceQueryDocumentSnapshot._( + this.snapshot, + this.data, + ); + + @override + final DocumentSnapshot snapshot; + + @override + DocumentReferenceQueryDocumentReference get reference { + return DocumentReferenceQueryDocumentReference( + snapshot.reference, + ); + } + + @override + final DocumentReferenceQuery? data; +} + +abstract class DocumentReferenceQueryQuery + implements QueryReference { + @override + DocumentReferenceQueryQuery limit(int limit); + + @override + DocumentReferenceQueryQuery limitToLast(int limit); + + DocumentReferenceQueryQuery whereDocumentId({ + String? isEqualTo, + String? isNotEqualTo, + String? isLessThan, + String? isLessThanOrEqualTo, + String? isGreaterThan, + String? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }); + DocumentReferenceQueryQuery whereRef({ + DocumentReference>? isEqualTo, + DocumentReference>? isNotEqualTo, + DocumentReference>? isLessThan, + DocumentReference>? isLessThanOrEqualTo, + DocumentReference>? isGreaterThan, + DocumentReference>? isGreaterThanOrEqualTo, + bool? isNull, + List>>? whereIn, + List>>? whereNotIn, + }); + + DocumentReferenceQueryQuery orderByDocumentId({ + bool descending = false, + String startAt, + String startAfter, + String endAt, + String endBefore, + DocumentReferenceQueryDocumentSnapshot? startAtDocument, + DocumentReferenceQueryDocumentSnapshot? endAtDocument, + DocumentReferenceQueryDocumentSnapshot? endBeforeDocument, + DocumentReferenceQueryDocumentSnapshot? startAfterDocument, + }); + + DocumentReferenceQueryQuery orderByRef({ + bool descending = false, + DocumentReference> startAt, + DocumentReference> startAfter, + DocumentReference> endAt, + DocumentReference> endBefore, + DocumentReferenceQueryDocumentSnapshot? startAtDocument, + DocumentReferenceQueryDocumentSnapshot? endAtDocument, + DocumentReferenceQueryDocumentSnapshot? endBeforeDocument, + DocumentReferenceQueryDocumentSnapshot? startAfterDocument, + }); +} + +class _$DocumentReferenceQueryQuery + extends QueryReference + implements DocumentReferenceQueryQuery { + _$DocumentReferenceQueryQuery( + this.reference, + this._collection, + ); + + final CollectionReference _collection; + + @override + final Query reference; + + DocumentReferenceQueryQuerySnapshot _decodeSnapshot( + QuerySnapshot snapshot, + ) { + final docs = snapshot.docs.map((e) { + return DocumentReferenceQueryQueryDocumentSnapshot._(e, e.data()); + }).toList(); + + final docChanges = snapshot.docChanges.map((change) { + return FirestoreDocumentChange( + type: change.type, + oldIndex: change.oldIndex, + newIndex: change.newIndex, + doc: DocumentReferenceQueryDocumentSnapshot._( + change.doc, change.doc.data()), + ); + }).toList(); + + return DocumentReferenceQueryQuerySnapshot._( + snapshot, + docs, + docChanges, + ); + } + + @override + Stream snapshots( + [SnapshotOptions? options]) { + return reference.snapshots().map(_decodeSnapshot); + } + + @override + Future get([GetOptions? options]) { + return reference.get(options).then(_decodeSnapshot); + } + + @override + DocumentReferenceQueryQuery limit(int limit) { + return _$DocumentReferenceQueryQuery( + reference.limit(limit), + _collection, + ); + } + + @override + DocumentReferenceQueryQuery limitToLast(int limit) { + return _$DocumentReferenceQueryQuery( + reference.limitToLast(limit), + _collection, + ); + } + + DocumentReferenceQueryQuery whereDocumentId({ + String? isEqualTo, + String? isNotEqualTo, + String? isLessThan, + String? isLessThanOrEqualTo, + String? isGreaterThan, + String? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }) { + return _$DocumentReferenceQueryQuery( + reference.where( + FieldPath.documentId, + isEqualTo: isEqualTo, + isNotEqualTo: isNotEqualTo, + isLessThan: isLessThan, + isLessThanOrEqualTo: isLessThanOrEqualTo, + isGreaterThan: isGreaterThan, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isNull: isNull, + whereIn: whereIn, + whereNotIn: whereNotIn, + ), + _collection, + ); + } + + DocumentReferenceQueryQuery whereRef({ + DocumentReference>? isEqualTo, + DocumentReference>? isNotEqualTo, DocumentReference>? isLessThan, DocumentReference>? isLessThanOrEqualTo, DocumentReference>? isGreaterThan, @@ -1134,7 +1884,7 @@ class _$DocumentReferenceQueryQuery }) { return _$DocumentReferenceQueryQuery( reference.where( - 'ref', + "ref", isEqualTo: isEqualTo, isNotEqualTo: isNotEqualTo, isLessThan: isLessThan, @@ -1149,6 +1899,48 @@ class _$DocumentReferenceQueryQuery ); } + DocumentReferenceQueryQuery orderByDocumentId({ + bool descending = false, + Object? startAt = _sentinel, + Object? startAfter = _sentinel, + Object? endAt = _sentinel, + Object? endBefore = _sentinel, + DocumentReferenceQueryDocumentSnapshot? startAtDocument, + DocumentReferenceQueryDocumentSnapshot? endAtDocument, + DocumentReferenceQueryDocumentSnapshot? endBeforeDocument, + DocumentReferenceQueryDocumentSnapshot? startAfterDocument, + }) { + var query = reference.orderBy(FieldPath.documentId, descending: descending); + + if (startAtDocument != null) { + query = query.startAtDocument(startAtDocument.snapshot); + } + if (startAfterDocument != null) { + query = query.startAfterDocument(startAfterDocument.snapshot); + } + if (endAtDocument != null) { + query = query.endAtDocument(endAtDocument.snapshot); + } + if (endBeforeDocument != null) { + query = query.endBeforeDocument(endBeforeDocument.snapshot); + } + + if (startAt != _sentinel) { + query = query.startAt([startAt]); + } + if (startAfter != _sentinel) { + query = query.startAfter([startAfter]); + } + if (endAt != _sentinel) { + query = query.endAt([endAt]); + } + if (endBefore != _sentinel) { + query = query.endBefore([endBefore]); + } + + return _$DocumentReferenceQueryQuery(query, _collection); + } + DocumentReferenceQueryQuery orderByRef({ bool descending = false, Object? startAt = _sentinel, @@ -1160,7 +1952,7 @@ class _$DocumentReferenceQueryQuery DocumentReferenceQueryDocumentSnapshot? endBeforeDocument, DocumentReferenceQueryDocumentSnapshot? startAfterDocument, }) { - var query = reference.orderBy('ref', descending: descending); + var query = reference.orderBy("ref", descending: descending); if (startAtDocument != null) { query = query.startAtDocument(startAtDocument.snapshot); @@ -1261,6 +2053,16 @@ Map _$TimestampQueryToJson(TimestampQuery instance) => 'time': const FirestoreTimestampConverter().toJson(instance.time), }; +GeoPointQuery _$GeoPointQueryFromJson(Map json) => + GeoPointQuery( + const FirestoreGeoPointConverter().fromJson(json['point'] as GeoPoint), + ); + +Map _$GeoPointQueryToJson(GeoPointQuery instance) => + { + 'point': const FirestoreGeoPointConverter().toJson(instance.point), + }; + DocumentReferenceQuery _$DocumentReferenceQueryFromJson( Map json) => DocumentReferenceQuery( diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm/example/test_driver/query_reference_test.dart b/packages/cloud_firestore_odm/cloud_firestore_odm/example/test_driver/query_reference_test.dart index 34ddacf33561..a43899c29ecd 100644 --- a/packages/cloud_firestore_odm/cloud_firestore_odm/example/test_driver/query_reference_test.dart +++ b/packages/cloud_firestore_odm/cloud_firestore_odm/example/test_driver/query_reference_test.dart @@ -120,33 +120,53 @@ void main() { expect(snapshot.docs[1].data.time, Timestamp.fromDate(DateTime(2010))); }); - test('supports DocumentReference', () async { - final ref = await initializeTest(documentReferenceRef); + test('supports GeoPoint', () async { + final ref = await initializeTest(geoPointQueryRef); - await ref.add( - DocumentReferenceQuery(FirebaseFirestore.instance.doc('foo/a')), - ); - await ref.add( - DocumentReferenceQuery(FirebaseFirestore.instance.doc('foo/b')), - ); - await ref.add( - DocumentReferenceQuery(FirebaseFirestore.instance.doc('foo/c')), - ); + await ref.add(GeoPointQuery(const GeoPoint(19, 0))); + await ref.add(GeoPointQuery(const GeoPoint(20, 0))); + await ref.add(GeoPointQuery(const GeoPoint(20, 0))); - final snapshot = await ref - .orderByRef(startAt: FirebaseFirestore.instance.doc('foo/b')) - .get(); + final snapshot = + await ref.orderByPoint(startAt: const GeoPoint(20, 0)).get(); expect(snapshot.docs.length, 2); - expect( - snapshot.docs[0].data.ref, - FirebaseFirestore.instance.doc('foo/b'), - ); - expect( - snapshot.docs[1].data.ref, - FirebaseFirestore.instance.doc('foo/c'), - ); + expect(snapshot.docs[0].data.point, const GeoPoint(20, 0)); + expect(snapshot.docs[1].data.point, const GeoPoint(20, 0)); }); + + test( + 'supports DocumentReference', + () async { + final ref = await initializeTest(documentReferenceRef); + + await ref.add( + DocumentReferenceQuery(FirebaseFirestore.instance.doc('foo/a')), + ); + await ref.add( + DocumentReferenceQuery(FirebaseFirestore.instance.doc('foo/b')), + ); + await ref.add( + DocumentReferenceQuery(FirebaseFirestore.instance.doc('foo/c')), + ); + + final snapshot = await ref + .orderByRef(startAt: FirebaseFirestore.instance.doc('foo/b')) + .get(); + + expect(snapshot.docs.length, 2); + + expect( + snapshot.docs[0].data.ref, + FirebaseFirestore.instance.doc('foo/b'), + ); + expect( + snapshot.docs[1].data.ref, + FirebaseFirestore.instance.doc('foo/c'), + ); + }, + skip: 'Blocked by FlutterFire support for querying document references', + ); }); } diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm/lib/cloud_firestore_odm.dart b/packages/cloud_firestore_odm/cloud_firestore_odm/lib/cloud_firestore_odm.dart index 9a7e7a29141b..0546ef41af5c 100644 --- a/packages/cloud_firestore_odm/cloud_firestore_odm/lib/cloud_firestore_odm.dart +++ b/packages/cloud_firestore_odm/cloud_firestore_odm/lib/cloud_firestore_odm.dart @@ -25,6 +25,7 @@ export 'src/firestore_reference.dart' const firestoreJsonConverters = [ FirestoreDateTimeConverter(), FirestoreTimestampConverter(), + FirestoreGeoPointConverter(), ]; /// A [JsonConverter] that adds support for [Timestamp] objects within ODM models. @@ -37,6 +38,16 @@ class FirestoreTimestampConverter extends JsonConverter { Timestamp toJson(Timestamp object) => object; } +/// A [JsonConverter] that adds support for [GeoPoint] objects within ODM models. +class FirestoreGeoPointConverter extends JsonConverter { + const FirestoreGeoPointConverter(); + @override + GeoPoint fromJson(GeoPoint json) => json; + + @override + GeoPoint toJson(GeoPoint object) => object; +} + /// A [JsonConverter] that adds support for [DateTime] objects within ODM models. class FirestoreDateTimeConverter extends JsonConverter { const FirestoreDateTimeConverter(); diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm_generator/lib/src/collection_generator.dart b/packages/cloud_firestore_odm/cloud_firestore_odm_generator/lib/src/collection_generator.dart index 0d3d86d39d69..913b6677c169 100644 --- a/packages/cloud_firestore_odm/cloud_firestore_odm_generator/lib/src/collection_generator.dart +++ b/packages/cloud_firestore_odm/cloud_firestore_odm_generator/lib/src/collection_generator.dart @@ -105,6 +105,10 @@ const _timestampChecker = TypeChecker.fromUrl( 'package:cloud_firestore_platform_interface/src/timestamp.dart#Timestamp', ); +const _geoPointChecker = TypeChecker.fromUrl( + 'package:cloud_firestore_platform_interface/src/geo_point.dart#GeoPoint', +); + @immutable class CollectionGenerator extends ParserGenerator { final _collectionTemplates = >[ @@ -325,9 +329,11 @@ class CollectionGenerator extends ParserGenerator { f.type.isDartCoreInt || f.type.isDartCoreDouble || f.type.isDartCoreBool || + f.type.isPrimitiveList || + f.type.isJsonDocumentReference || _dateTimeChecker.isAssignableFromType(f.type) || _timestampChecker.isAssignableFromType(f.type) || - f.type.isPrimitiveList, + _geoPointChecker.isAssignableFromType(f.type), // TODO filter list other than LIst ) .map( From 7feb93bb1029d2b18bacf03d8fe21c21fc5f8be3 Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Mon, 11 Jul 2022 14:08:47 +0200 Subject: [PATCH 6/6] update generated files --- .../example/lib/integration.g.dart | 2359 +++++++++++++++++ .../example/lib/integration/query.g.dart | 48 +- 2 files changed, 2399 insertions(+), 8 deletions(-) create mode 100644 packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration.g.dart diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration.g.dart b/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration.g.dart new file mode 100644 index 000000000000..49c62ec9ece0 --- /dev/null +++ b/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration.g.dart @@ -0,0 +1,2359 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +// ignore_for_file: type=lint + +part of 'integration.dart'; + +// ************************************************************************** +// CollectionGenerator +// ************************************************************************** + +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides + +class _Sentinel { + const _Sentinel(); +} + +const _sentinel = _Sentinel(); + +/// A collection reference object can be used for adding documents, +/// getting document references, and querying for documents +/// (using the methods inherited from Query). +abstract class ManualJsonCollectionReference + implements + ManualJsonQuery, + FirestoreCollectionReference { + factory ManualJsonCollectionReference([ + FirebaseFirestore? firestore, + ]) = _$ManualJsonCollectionReference; + + static ManualJson fromFirestore( + DocumentSnapshot> snapshot, + SnapshotOptions? options, + ) { + return ManualJson.fromJson(snapshot.data()!); + } + + static Map toFirestore( + ManualJson value, + SetOptions? options, + ) { + return value.toJson(); + } + + @override + CollectionReference get reference; + + @override + ManualJsonDocumentReference doc([String? id]); + + /// Add a new document to this collection with the specified data, + /// assigning it a document ID automatically. + Future add(ManualJson value); +} + +class _$ManualJsonCollectionReference extends _$ManualJsonQuery + implements ManualJsonCollectionReference { + factory _$ManualJsonCollectionReference([FirebaseFirestore? firestore]) { + firestore ??= FirebaseFirestore.instance; + + return _$ManualJsonCollectionReference._( + firestore.collection('root').withConverter( + fromFirestore: ManualJsonCollectionReference.fromFirestore, + toFirestore: ManualJsonCollectionReference.toFirestore, + ), + ); + } + + _$ManualJsonCollectionReference._( + CollectionReference reference, + ) : super(reference, reference); + + String get path => reference.path; + + @override + CollectionReference get reference => + super.reference as CollectionReference; + + @override + ManualJsonDocumentReference doc([String? id]) { + assert( + id == null || id.split('/').length == 1, + 'The document ID cannot be from a different collection', + ); + return ManualJsonDocumentReference( + reference.doc(id), + ); + } + + @override + Future add(ManualJson value) { + return reference.add(value).then((ref) => ManualJsonDocumentReference(ref)); + } + + @override + bool operator ==(Object other) { + return other is _$ManualJsonCollectionReference && + other.runtimeType == runtimeType && + other.reference == reference; + } + + @override + int get hashCode => Object.hash(runtimeType, reference); +} + +abstract class ManualJsonDocumentReference + extends FirestoreDocumentReference { + factory ManualJsonDocumentReference(DocumentReference reference) = + _$ManualJsonDocumentReference; + + DocumentReference get reference; + + /// A reference to the [ManualJsonCollectionReference] containing this document. + ManualJsonCollectionReference get parent { + return _$ManualJsonCollectionReference(reference.firestore); + } + + @override + Stream snapshots(); + + @override + Future get([GetOptions? options]); + + @override + Future delete(); + + Future update({ + String value, + }); + + Future set(ManualJson value); +} + +class _$ManualJsonDocumentReference + extends FirestoreDocumentReference + implements ManualJsonDocumentReference { + _$ManualJsonDocumentReference(this.reference); + + @override + final DocumentReference reference; + + /// A reference to the [ManualJsonCollectionReference] containing this document. + ManualJsonCollectionReference get parent { + return _$ManualJsonCollectionReference(reference.firestore); + } + + @override + Stream snapshots() { + return reference.snapshots().map((snapshot) { + return ManualJsonDocumentSnapshot._( + snapshot, + snapshot.data(), + ); + }); + } + + @override + Future get([GetOptions? options]) { + return reference.get(options).then((snapshot) { + return ManualJsonDocumentSnapshot._( + snapshot, + snapshot.data(), + ); + }); + } + + @override + Future delete() { + return reference.delete(); + } + + Future update({ + Object? value = _sentinel, + }) async { + final json = { + if (value != _sentinel) "value": value as String, + }; + + return reference.update(json); + } + + Future set(ManualJson value) { + return reference.set(value); + } + + @override + bool operator ==(Object other) { + return other is ManualJsonDocumentReference && + other.runtimeType == runtimeType && + other.parent == parent && + other.id == id; + } + + @override + int get hashCode => Object.hash(runtimeType, parent, id); +} + +class ManualJsonDocumentSnapshot extends FirestoreDocumentSnapshot { + ManualJsonDocumentSnapshot._( + this.snapshot, + this.data, + ); + + @override + final DocumentSnapshot snapshot; + + @override + ManualJsonDocumentReference get reference { + return ManualJsonDocumentReference( + snapshot.reference, + ); + } + + @override + final ManualJson? data; +} + +abstract class ManualJsonQuery + implements QueryReference { + @override + ManualJsonQuery limit(int limit); + + @override + ManualJsonQuery limitToLast(int limit); + + ManualJsonQuery whereDocumentId({ + String? isEqualTo, + String? isNotEqualTo, + String? isLessThan, + String? isLessThanOrEqualTo, + String? isGreaterThan, + String? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }); + ManualJsonQuery whereValue({ + String? isEqualTo, + String? isNotEqualTo, + String? isLessThan, + String? isLessThanOrEqualTo, + String? isGreaterThan, + String? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }); + + ManualJsonQuery orderByDocumentId({ + bool descending = false, + String startAt, + String startAfter, + String endAt, + String endBefore, + ManualJsonDocumentSnapshot? startAtDocument, + ManualJsonDocumentSnapshot? endAtDocument, + ManualJsonDocumentSnapshot? endBeforeDocument, + ManualJsonDocumentSnapshot? startAfterDocument, + }); + + ManualJsonQuery orderByValue({ + bool descending = false, + String startAt, + String startAfter, + String endAt, + String endBefore, + ManualJsonDocumentSnapshot? startAtDocument, + ManualJsonDocumentSnapshot? endAtDocument, + ManualJsonDocumentSnapshot? endBeforeDocument, + ManualJsonDocumentSnapshot? startAfterDocument, + }); +} + +class _$ManualJsonQuery extends QueryReference + implements ManualJsonQuery { + _$ManualJsonQuery( + this.reference, + this._collection, + ); + + final CollectionReference _collection; + + @override + final Query reference; + + ManualJsonQuerySnapshot _decodeSnapshot( + QuerySnapshot snapshot, + ) { + final docs = snapshot.docs.map((e) { + return ManualJsonQueryDocumentSnapshot._(e, e.data()); + }).toList(); + + final docChanges = snapshot.docChanges.map((change) { + return FirestoreDocumentChange( + type: change.type, + oldIndex: change.oldIndex, + newIndex: change.newIndex, + doc: ManualJsonDocumentSnapshot._(change.doc, change.doc.data()), + ); + }).toList(); + + return ManualJsonQuerySnapshot._( + snapshot, + docs, + docChanges, + ); + } + + @override + Stream snapshots([SnapshotOptions? options]) { + return reference.snapshots().map(_decodeSnapshot); + } + + @override + Future get([GetOptions? options]) { + return reference.get(options).then(_decodeSnapshot); + } + + @override + ManualJsonQuery limit(int limit) { + return _$ManualJsonQuery( + reference.limit(limit), + _collection, + ); + } + + @override + ManualJsonQuery limitToLast(int limit) { + return _$ManualJsonQuery( + reference.limitToLast(limit), + _collection, + ); + } + + ManualJsonQuery whereDocumentId({ + String? isEqualTo, + String? isNotEqualTo, + String? isLessThan, + String? isLessThanOrEqualTo, + String? isGreaterThan, + String? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }) { + return _$ManualJsonQuery( + reference.where( + FieldPath.documentId, + isEqualTo: isEqualTo, + isNotEqualTo: isNotEqualTo, + isLessThan: isLessThan, + isLessThanOrEqualTo: isLessThanOrEqualTo, + isGreaterThan: isGreaterThan, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isNull: isNull, + whereIn: whereIn, + whereNotIn: whereNotIn, + ), + _collection, + ); + } + + ManualJsonQuery whereValue({ + String? isEqualTo, + String? isNotEqualTo, + String? isLessThan, + String? isLessThanOrEqualTo, + String? isGreaterThan, + String? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }) { + return _$ManualJsonQuery( + reference.where( + "value", + isEqualTo: isEqualTo, + isNotEqualTo: isNotEqualTo, + isLessThan: isLessThan, + isLessThanOrEqualTo: isLessThanOrEqualTo, + isGreaterThan: isGreaterThan, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isNull: isNull, + whereIn: whereIn, + whereNotIn: whereNotIn, + ), + _collection, + ); + } + + ManualJsonQuery orderByDocumentId({ + bool descending = false, + Object? startAt = _sentinel, + Object? startAfter = _sentinel, + Object? endAt = _sentinel, + Object? endBefore = _sentinel, + ManualJsonDocumentSnapshot? startAtDocument, + ManualJsonDocumentSnapshot? endAtDocument, + ManualJsonDocumentSnapshot? endBeforeDocument, + ManualJsonDocumentSnapshot? startAfterDocument, + }) { + var query = reference.orderBy(FieldPath.documentId, descending: descending); + + if (startAtDocument != null) { + query = query.startAtDocument(startAtDocument.snapshot); + } + if (startAfterDocument != null) { + query = query.startAfterDocument(startAfterDocument.snapshot); + } + if (endAtDocument != null) { + query = query.endAtDocument(endAtDocument.snapshot); + } + if (endBeforeDocument != null) { + query = query.endBeforeDocument(endBeforeDocument.snapshot); + } + + if (startAt != _sentinel) { + query = query.startAt([startAt]); + } + if (startAfter != _sentinel) { + query = query.startAfter([startAfter]); + } + if (endAt != _sentinel) { + query = query.endAt([endAt]); + } + if (endBefore != _sentinel) { + query = query.endBefore([endBefore]); + } + + return _$ManualJsonQuery(query, _collection); + } + + ManualJsonQuery orderByValue({ + bool descending = false, + Object? startAt = _sentinel, + Object? startAfter = _sentinel, + Object? endAt = _sentinel, + Object? endBefore = _sentinel, + ManualJsonDocumentSnapshot? startAtDocument, + ManualJsonDocumentSnapshot? endAtDocument, + ManualJsonDocumentSnapshot? endBeforeDocument, + ManualJsonDocumentSnapshot? startAfterDocument, + }) { + var query = reference.orderBy("value", descending: descending); + + if (startAtDocument != null) { + query = query.startAtDocument(startAtDocument.snapshot); + } + if (startAfterDocument != null) { + query = query.startAfterDocument(startAfterDocument.snapshot); + } + if (endAtDocument != null) { + query = query.endAtDocument(endAtDocument.snapshot); + } + if (endBeforeDocument != null) { + query = query.endBeforeDocument(endBeforeDocument.snapshot); + } + + if (startAt != _sentinel) { + query = query.startAt([startAt]); + } + if (startAfter != _sentinel) { + query = query.startAfter([startAfter]); + } + if (endAt != _sentinel) { + query = query.endAt([endAt]); + } + if (endBefore != _sentinel) { + query = query.endBefore([endBefore]); + } + + return _$ManualJsonQuery(query, _collection); + } + + @override + bool operator ==(Object other) { + return other is _$ManualJsonQuery && + other.runtimeType == runtimeType && + other.reference == reference; + } + + @override + int get hashCode => Object.hash(runtimeType, reference); +} + +class ManualJsonQuerySnapshot + extends FirestoreQuerySnapshot { + ManualJsonQuerySnapshot._( + this.snapshot, + this.docs, + this.docChanges, + ); + + final QuerySnapshot snapshot; + + @override + final List docs; + + @override + final List> docChanges; +} + +class ManualJsonQueryDocumentSnapshot extends FirestoreQueryDocumentSnapshot + implements ManualJsonDocumentSnapshot { + ManualJsonQueryDocumentSnapshot._(this.snapshot, this.data); + + @override + final QueryDocumentSnapshot snapshot; + + @override + ManualJsonDocumentReference get reference { + return ManualJsonDocumentReference(snapshot.reference); + } + + @override + final ManualJson data; +} + +/// A collection reference object can be used for adding documents, +/// getting document references, and querying for documents +/// (using the methods inherited from Query). +abstract class AdvancedJsonCollectionReference + implements + AdvancedJsonQuery, + FirestoreCollectionReference { + factory AdvancedJsonCollectionReference([ + FirebaseFirestore? firestore, + ]) = _$AdvancedJsonCollectionReference; + + static AdvancedJson fromFirestore( + DocumentSnapshot> snapshot, + SnapshotOptions? options, + ) { + return _$AdvancedJsonFromJson(snapshot.data()!); + } + + static Map toFirestore( + AdvancedJson value, + SetOptions? options, + ) { + return value.toJson(); + } + + @override + CollectionReference get reference; + + @override + AdvancedJsonDocumentReference doc([String? id]); + + /// Add a new document to this collection with the specified data, + /// assigning it a document ID automatically. + Future add(AdvancedJson value); +} + +class _$AdvancedJsonCollectionReference extends _$AdvancedJsonQuery + implements AdvancedJsonCollectionReference { + factory _$AdvancedJsonCollectionReference([FirebaseFirestore? firestore]) { + firestore ??= FirebaseFirestore.instance; + + return _$AdvancedJsonCollectionReference._( + firestore.collection('firestore-example-app/test/advanced').withConverter( + fromFirestore: AdvancedJsonCollectionReference.fromFirestore, + toFirestore: AdvancedJsonCollectionReference.toFirestore, + ), + ); + } + + _$AdvancedJsonCollectionReference._( + CollectionReference reference, + ) : super(reference, reference); + + String get path => reference.path; + + @override + CollectionReference get reference => + super.reference as CollectionReference; + + @override + AdvancedJsonDocumentReference doc([String? id]) { + assert( + id == null || id.split('/').length == 1, + 'The document ID cannot be from a different collection', + ); + return AdvancedJsonDocumentReference( + reference.doc(id), + ); + } + + @override + Future add(AdvancedJson value) { + return reference + .add(value) + .then((ref) => AdvancedJsonDocumentReference(ref)); + } + + @override + bool operator ==(Object other) { + return other is _$AdvancedJsonCollectionReference && + other.runtimeType == runtimeType && + other.reference == reference; + } + + @override + int get hashCode => Object.hash(runtimeType, reference); +} + +abstract class AdvancedJsonDocumentReference + extends FirestoreDocumentReference { + factory AdvancedJsonDocumentReference( + DocumentReference reference) = + _$AdvancedJsonDocumentReference; + + DocumentReference get reference; + + /// A reference to the [AdvancedJsonCollectionReference] containing this document. + AdvancedJsonCollectionReference get parent { + return _$AdvancedJsonCollectionReference(reference.firestore); + } + + @override + Stream snapshots(); + + @override + Future get([GetOptions? options]); + + @override + Future delete(); + + Future update({ + String? firstName, + String? lastName, + int hashCode, + }); + + Future set(AdvancedJson value); +} + +class _$AdvancedJsonDocumentReference + extends FirestoreDocumentReference + implements AdvancedJsonDocumentReference { + _$AdvancedJsonDocumentReference(this.reference); + + @override + final DocumentReference reference; + + /// A reference to the [AdvancedJsonCollectionReference] containing this document. + AdvancedJsonCollectionReference get parent { + return _$AdvancedJsonCollectionReference(reference.firestore); + } + + @override + Stream snapshots() { + return reference.snapshots().map((snapshot) { + return AdvancedJsonDocumentSnapshot._( + snapshot, + snapshot.data(), + ); + }); + } + + @override + Future get([GetOptions? options]) { + return reference.get(options).then((snapshot) { + return AdvancedJsonDocumentSnapshot._( + snapshot, + snapshot.data(), + ); + }); + } + + @override + Future delete() { + return reference.delete(); + } + + Future update({ + Object? firstName = _sentinel, + Object? lastName = _sentinel, + Object? hashCode = _sentinel, + }) async { + final json = { + if (firstName != _sentinel) "firstName": firstName as String?, + if (lastName != _sentinel) "lastName": lastName as String?, + if (hashCode != _sentinel) "hashCode": hashCode as int, + }; + + return reference.update(json); + } + + Future set(AdvancedJson value) { + return reference.set(value); + } + + @override + bool operator ==(Object other) { + return other is AdvancedJsonDocumentReference && + other.runtimeType == runtimeType && + other.parent == parent && + other.id == id; + } + + @override + int get hashCode => Object.hash(runtimeType, parent, id); +} + +class AdvancedJsonDocumentSnapshot extends FirestoreDocumentSnapshot { + AdvancedJsonDocumentSnapshot._( + this.snapshot, + this.data, + ); + + @override + final DocumentSnapshot snapshot; + + @override + AdvancedJsonDocumentReference get reference { + return AdvancedJsonDocumentReference( + snapshot.reference, + ); + } + + @override + final AdvancedJson? data; +} + +abstract class AdvancedJsonQuery + implements QueryReference { + @override + AdvancedJsonQuery limit(int limit); + + @override + AdvancedJsonQuery limitToLast(int limit); + + AdvancedJsonQuery whereDocumentId({ + String? isEqualTo, + String? isNotEqualTo, + String? isLessThan, + String? isLessThanOrEqualTo, + String? isGreaterThan, + String? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }); + AdvancedJsonQuery whereFirstName({ + String? isEqualTo, + String? isNotEqualTo, + String? isLessThan, + String? isLessThanOrEqualTo, + String? isGreaterThan, + String? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }); + AdvancedJsonQuery whereLastName({ + String? isEqualTo, + String? isNotEqualTo, + String? isLessThan, + String? isLessThanOrEqualTo, + String? isGreaterThan, + String? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }); + AdvancedJsonQuery whereHashCode({ + int? isEqualTo, + int? isNotEqualTo, + int? isLessThan, + int? isLessThanOrEqualTo, + int? isGreaterThan, + int? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }); + + AdvancedJsonQuery orderByDocumentId({ + bool descending = false, + String startAt, + String startAfter, + String endAt, + String endBefore, + AdvancedJsonDocumentSnapshot? startAtDocument, + AdvancedJsonDocumentSnapshot? endAtDocument, + AdvancedJsonDocumentSnapshot? endBeforeDocument, + AdvancedJsonDocumentSnapshot? startAfterDocument, + }); + + AdvancedJsonQuery orderByFirstName({ + bool descending = false, + String? startAt, + String? startAfter, + String? endAt, + String? endBefore, + AdvancedJsonDocumentSnapshot? startAtDocument, + AdvancedJsonDocumentSnapshot? endAtDocument, + AdvancedJsonDocumentSnapshot? endBeforeDocument, + AdvancedJsonDocumentSnapshot? startAfterDocument, + }); + + AdvancedJsonQuery orderByLastName({ + bool descending = false, + String? startAt, + String? startAfter, + String? endAt, + String? endBefore, + AdvancedJsonDocumentSnapshot? startAtDocument, + AdvancedJsonDocumentSnapshot? endAtDocument, + AdvancedJsonDocumentSnapshot? endBeforeDocument, + AdvancedJsonDocumentSnapshot? startAfterDocument, + }); + + AdvancedJsonQuery orderByHashCode({ + bool descending = false, + int startAt, + int startAfter, + int endAt, + int endBefore, + AdvancedJsonDocumentSnapshot? startAtDocument, + AdvancedJsonDocumentSnapshot? endAtDocument, + AdvancedJsonDocumentSnapshot? endBeforeDocument, + AdvancedJsonDocumentSnapshot? startAfterDocument, + }); +} + +class _$AdvancedJsonQuery extends QueryReference + implements AdvancedJsonQuery { + _$AdvancedJsonQuery( + this.reference, + this._collection, + ); + + final CollectionReference _collection; + + @override + final Query reference; + + AdvancedJsonQuerySnapshot _decodeSnapshot( + QuerySnapshot snapshot, + ) { + final docs = snapshot.docs.map((e) { + return AdvancedJsonQueryDocumentSnapshot._(e, e.data()); + }).toList(); + + final docChanges = snapshot.docChanges.map((change) { + return FirestoreDocumentChange( + type: change.type, + oldIndex: change.oldIndex, + newIndex: change.newIndex, + doc: AdvancedJsonDocumentSnapshot._(change.doc, change.doc.data()), + ); + }).toList(); + + return AdvancedJsonQuerySnapshot._( + snapshot, + docs, + docChanges, + ); + } + + @override + Stream snapshots([SnapshotOptions? options]) { + return reference.snapshots().map(_decodeSnapshot); + } + + @override + Future get([GetOptions? options]) { + return reference.get(options).then(_decodeSnapshot); + } + + @override + AdvancedJsonQuery limit(int limit) { + return _$AdvancedJsonQuery( + reference.limit(limit), + _collection, + ); + } + + @override + AdvancedJsonQuery limitToLast(int limit) { + return _$AdvancedJsonQuery( + reference.limitToLast(limit), + _collection, + ); + } + + AdvancedJsonQuery whereDocumentId({ + String? isEqualTo, + String? isNotEqualTo, + String? isLessThan, + String? isLessThanOrEqualTo, + String? isGreaterThan, + String? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }) { + return _$AdvancedJsonQuery( + reference.where( + FieldPath.documentId, + isEqualTo: isEqualTo, + isNotEqualTo: isNotEqualTo, + isLessThan: isLessThan, + isLessThanOrEqualTo: isLessThanOrEqualTo, + isGreaterThan: isGreaterThan, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isNull: isNull, + whereIn: whereIn, + whereNotIn: whereNotIn, + ), + _collection, + ); + } + + AdvancedJsonQuery whereFirstName({ + String? isEqualTo, + String? isNotEqualTo, + String? isLessThan, + String? isLessThanOrEqualTo, + String? isGreaterThan, + String? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }) { + return _$AdvancedJsonQuery( + reference.where( + _$AdvancedJsonFieldMap["firstName"]!, + isEqualTo: isEqualTo, + isNotEqualTo: isNotEqualTo, + isLessThan: isLessThan, + isLessThanOrEqualTo: isLessThanOrEqualTo, + isGreaterThan: isGreaterThan, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isNull: isNull, + whereIn: whereIn, + whereNotIn: whereNotIn, + ), + _collection, + ); + } + + AdvancedJsonQuery whereLastName({ + String? isEqualTo, + String? isNotEqualTo, + String? isLessThan, + String? isLessThanOrEqualTo, + String? isGreaterThan, + String? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }) { + return _$AdvancedJsonQuery( + reference.where( + _$AdvancedJsonFieldMap["lastName"]!, + isEqualTo: isEqualTo, + isNotEqualTo: isNotEqualTo, + isLessThan: isLessThan, + isLessThanOrEqualTo: isLessThanOrEqualTo, + isGreaterThan: isGreaterThan, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isNull: isNull, + whereIn: whereIn, + whereNotIn: whereNotIn, + ), + _collection, + ); + } + + AdvancedJsonQuery whereHashCode({ + int? isEqualTo, + int? isNotEqualTo, + int? isLessThan, + int? isLessThanOrEqualTo, + int? isGreaterThan, + int? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }) { + return _$AdvancedJsonQuery( + reference.where( + _$AdvancedJsonFieldMap["hashCode"]!, + isEqualTo: isEqualTo, + isNotEqualTo: isNotEqualTo, + isLessThan: isLessThan, + isLessThanOrEqualTo: isLessThanOrEqualTo, + isGreaterThan: isGreaterThan, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isNull: isNull, + whereIn: whereIn, + whereNotIn: whereNotIn, + ), + _collection, + ); + } + + AdvancedJsonQuery orderByDocumentId({ + bool descending = false, + Object? startAt = _sentinel, + Object? startAfter = _sentinel, + Object? endAt = _sentinel, + Object? endBefore = _sentinel, + AdvancedJsonDocumentSnapshot? startAtDocument, + AdvancedJsonDocumentSnapshot? endAtDocument, + AdvancedJsonDocumentSnapshot? endBeforeDocument, + AdvancedJsonDocumentSnapshot? startAfterDocument, + }) { + var query = reference.orderBy(FieldPath.documentId, descending: descending); + + if (startAtDocument != null) { + query = query.startAtDocument(startAtDocument.snapshot); + } + if (startAfterDocument != null) { + query = query.startAfterDocument(startAfterDocument.snapshot); + } + if (endAtDocument != null) { + query = query.endAtDocument(endAtDocument.snapshot); + } + if (endBeforeDocument != null) { + query = query.endBeforeDocument(endBeforeDocument.snapshot); + } + + if (startAt != _sentinel) { + query = query.startAt([startAt]); + } + if (startAfter != _sentinel) { + query = query.startAfter([startAfter]); + } + if (endAt != _sentinel) { + query = query.endAt([endAt]); + } + if (endBefore != _sentinel) { + query = query.endBefore([endBefore]); + } + + return _$AdvancedJsonQuery(query, _collection); + } + + AdvancedJsonQuery orderByFirstName({ + bool descending = false, + Object? startAt = _sentinel, + Object? startAfter = _sentinel, + Object? endAt = _sentinel, + Object? endBefore = _sentinel, + AdvancedJsonDocumentSnapshot? startAtDocument, + AdvancedJsonDocumentSnapshot? endAtDocument, + AdvancedJsonDocumentSnapshot? endBeforeDocument, + AdvancedJsonDocumentSnapshot? startAfterDocument, + }) { + var query = reference.orderBy(_$AdvancedJsonFieldMap["firstName"]!, + descending: descending); + + if (startAtDocument != null) { + query = query.startAtDocument(startAtDocument.snapshot); + } + if (startAfterDocument != null) { + query = query.startAfterDocument(startAfterDocument.snapshot); + } + if (endAtDocument != null) { + query = query.endAtDocument(endAtDocument.snapshot); + } + if (endBeforeDocument != null) { + query = query.endBeforeDocument(endBeforeDocument.snapshot); + } + + if (startAt != _sentinel) { + query = query.startAt([startAt]); + } + if (startAfter != _sentinel) { + query = query.startAfter([startAfter]); + } + if (endAt != _sentinel) { + query = query.endAt([endAt]); + } + if (endBefore != _sentinel) { + query = query.endBefore([endBefore]); + } + + return _$AdvancedJsonQuery(query, _collection); + } + + AdvancedJsonQuery orderByLastName({ + bool descending = false, + Object? startAt = _sentinel, + Object? startAfter = _sentinel, + Object? endAt = _sentinel, + Object? endBefore = _sentinel, + AdvancedJsonDocumentSnapshot? startAtDocument, + AdvancedJsonDocumentSnapshot? endAtDocument, + AdvancedJsonDocumentSnapshot? endBeforeDocument, + AdvancedJsonDocumentSnapshot? startAfterDocument, + }) { + var query = reference.orderBy(_$AdvancedJsonFieldMap["lastName"]!, + descending: descending); + + if (startAtDocument != null) { + query = query.startAtDocument(startAtDocument.snapshot); + } + if (startAfterDocument != null) { + query = query.startAfterDocument(startAfterDocument.snapshot); + } + if (endAtDocument != null) { + query = query.endAtDocument(endAtDocument.snapshot); + } + if (endBeforeDocument != null) { + query = query.endBeforeDocument(endBeforeDocument.snapshot); + } + + if (startAt != _sentinel) { + query = query.startAt([startAt]); + } + if (startAfter != _sentinel) { + query = query.startAfter([startAfter]); + } + if (endAt != _sentinel) { + query = query.endAt([endAt]); + } + if (endBefore != _sentinel) { + query = query.endBefore([endBefore]); + } + + return _$AdvancedJsonQuery(query, _collection); + } + + AdvancedJsonQuery orderByHashCode({ + bool descending = false, + Object? startAt = _sentinel, + Object? startAfter = _sentinel, + Object? endAt = _sentinel, + Object? endBefore = _sentinel, + AdvancedJsonDocumentSnapshot? startAtDocument, + AdvancedJsonDocumentSnapshot? endAtDocument, + AdvancedJsonDocumentSnapshot? endBeforeDocument, + AdvancedJsonDocumentSnapshot? startAfterDocument, + }) { + var query = reference.orderBy(_$AdvancedJsonFieldMap["hashCode"]!, + descending: descending); + + if (startAtDocument != null) { + query = query.startAtDocument(startAtDocument.snapshot); + } + if (startAfterDocument != null) { + query = query.startAfterDocument(startAfterDocument.snapshot); + } + if (endAtDocument != null) { + query = query.endAtDocument(endAtDocument.snapshot); + } + if (endBeforeDocument != null) { + query = query.endBeforeDocument(endBeforeDocument.snapshot); + } + + if (startAt != _sentinel) { + query = query.startAt([startAt]); + } + if (startAfter != _sentinel) { + query = query.startAfter([startAfter]); + } + if (endAt != _sentinel) { + query = query.endAt([endAt]); + } + if (endBefore != _sentinel) { + query = query.endBefore([endBefore]); + } + + return _$AdvancedJsonQuery(query, _collection); + } + + @override + bool operator ==(Object other) { + return other is _$AdvancedJsonQuery && + other.runtimeType == runtimeType && + other.reference == reference; + } + + @override + int get hashCode => Object.hash(runtimeType, reference); +} + +class AdvancedJsonQuerySnapshot + extends FirestoreQuerySnapshot { + AdvancedJsonQuerySnapshot._( + this.snapshot, + this.docs, + this.docChanges, + ); + + final QuerySnapshot snapshot; + + @override + final List docs; + + @override + final List> docChanges; +} + +class AdvancedJsonQueryDocumentSnapshot extends FirestoreQueryDocumentSnapshot + implements AdvancedJsonDocumentSnapshot { + AdvancedJsonQueryDocumentSnapshot._(this.snapshot, this.data); + + @override + final QueryDocumentSnapshot snapshot; + + @override + AdvancedJsonDocumentReference get reference { + return AdvancedJsonDocumentReference(snapshot.reference); + } + + @override + final AdvancedJson data; +} + +/// A collection reference object can be used for adding documents, +/// getting document references, and querying for documents +/// (using the methods inherited from Query). +abstract class _PrivateAdvancedJsonCollectionReference + implements + _PrivateAdvancedJsonQuery, + FirestoreCollectionReference<_PrivateAdvancedJsonQuerySnapshot> { + factory _PrivateAdvancedJsonCollectionReference([ + FirebaseFirestore? firestore, + ]) = _$_PrivateAdvancedJsonCollectionReference; + + static _PrivateAdvancedJson fromFirestore( + DocumentSnapshot> snapshot, + SnapshotOptions? options, + ) { + return _$PrivateAdvancedJsonFromJson(snapshot.data()!); + } + + static Map toFirestore( + _PrivateAdvancedJson value, + SetOptions? options, + ) { + return value.toJson(); + } + + @override + CollectionReference<_PrivateAdvancedJson> get reference; + + @override + _PrivateAdvancedJsonDocumentReference doc([String? id]); + + /// Add a new document to this collection with the specified data, + /// assigning it a document ID automatically. + Future<_PrivateAdvancedJsonDocumentReference> add(_PrivateAdvancedJson value); +} + +class _$_PrivateAdvancedJsonCollectionReference + extends _$_PrivateAdvancedJsonQuery + implements _PrivateAdvancedJsonCollectionReference { + factory _$_PrivateAdvancedJsonCollectionReference( + [FirebaseFirestore? firestore]) { + firestore ??= FirebaseFirestore.instance; + + return _$_PrivateAdvancedJsonCollectionReference._( + firestore + .collection('firestore-example-app/test/private-advanced') + .withConverter( + fromFirestore: + _PrivateAdvancedJsonCollectionReference.fromFirestore, + toFirestore: _PrivateAdvancedJsonCollectionReference.toFirestore, + ), + ); + } + + _$_PrivateAdvancedJsonCollectionReference._( + CollectionReference<_PrivateAdvancedJson> reference, + ) : super(reference, reference); + + String get path => reference.path; + + @override + CollectionReference<_PrivateAdvancedJson> get reference => + super.reference as CollectionReference<_PrivateAdvancedJson>; + + @override + _PrivateAdvancedJsonDocumentReference doc([String? id]) { + assert( + id == null || id.split('/').length == 1, + 'The document ID cannot be from a different collection', + ); + return _PrivateAdvancedJsonDocumentReference( + reference.doc(id), + ); + } + + @override + Future<_PrivateAdvancedJsonDocumentReference> add( + _PrivateAdvancedJson value) { + return reference + .add(value) + .then((ref) => _PrivateAdvancedJsonDocumentReference(ref)); + } + + @override + bool operator ==(Object other) { + return other is _$_PrivateAdvancedJsonCollectionReference && + other.runtimeType == runtimeType && + other.reference == reference; + } + + @override + int get hashCode => Object.hash(runtimeType, reference); +} + +abstract class _PrivateAdvancedJsonDocumentReference + extends FirestoreDocumentReference<_PrivateAdvancedJsonDocumentSnapshot> { + factory _PrivateAdvancedJsonDocumentReference( + DocumentReference<_PrivateAdvancedJson> reference) = + _$_PrivateAdvancedJsonDocumentReference; + + DocumentReference<_PrivateAdvancedJson> get reference; + + /// A reference to the [_PrivateAdvancedJsonCollectionReference] containing this document. + _PrivateAdvancedJsonCollectionReference get parent { + return _$_PrivateAdvancedJsonCollectionReference(reference.firestore); + } + + @override + Stream<_PrivateAdvancedJsonDocumentSnapshot> snapshots(); + + @override + Future<_PrivateAdvancedJsonDocumentSnapshot> get([GetOptions? options]); + + @override + Future delete(); + + Future update({ + String? firstName, + String? lastName, + int hashCode, + }); + + Future set(_PrivateAdvancedJson value); +} + +class _$_PrivateAdvancedJsonDocumentReference + extends FirestoreDocumentReference<_PrivateAdvancedJsonDocumentSnapshot> + implements _PrivateAdvancedJsonDocumentReference { + _$_PrivateAdvancedJsonDocumentReference(this.reference); + + @override + final DocumentReference<_PrivateAdvancedJson> reference; + + /// A reference to the [_PrivateAdvancedJsonCollectionReference] containing this document. + _PrivateAdvancedJsonCollectionReference get parent { + return _$_PrivateAdvancedJsonCollectionReference(reference.firestore); + } + + @override + Stream<_PrivateAdvancedJsonDocumentSnapshot> snapshots() { + return reference.snapshots().map((snapshot) { + return _PrivateAdvancedJsonDocumentSnapshot._( + snapshot, + snapshot.data(), + ); + }); + } + + @override + Future<_PrivateAdvancedJsonDocumentSnapshot> get([GetOptions? options]) { + return reference.get(options).then((snapshot) { + return _PrivateAdvancedJsonDocumentSnapshot._( + snapshot, + snapshot.data(), + ); + }); + } + + @override + Future delete() { + return reference.delete(); + } + + Future update({ + Object? firstName = _sentinel, + Object? lastName = _sentinel, + Object? hashCode = _sentinel, + }) async { + final json = { + if (firstName != _sentinel) "firstName": firstName as String?, + if (lastName != _sentinel) "lastName": lastName as String?, + if (hashCode != _sentinel) "hashCode": hashCode as int, + }; + + return reference.update(json); + } + + Future set(_PrivateAdvancedJson value) { + return reference.set(value); + } + + @override + bool operator ==(Object other) { + return other is _PrivateAdvancedJsonDocumentReference && + other.runtimeType == runtimeType && + other.parent == parent && + other.id == id; + } + + @override + int get hashCode => Object.hash(runtimeType, parent, id); +} + +class _PrivateAdvancedJsonDocumentSnapshot extends FirestoreDocumentSnapshot { + _PrivateAdvancedJsonDocumentSnapshot._( + this.snapshot, + this.data, + ); + + @override + final DocumentSnapshot<_PrivateAdvancedJson> snapshot; + + @override + _PrivateAdvancedJsonDocumentReference get reference { + return _PrivateAdvancedJsonDocumentReference( + snapshot.reference, + ); + } + + @override + final _PrivateAdvancedJson? data; +} + +abstract class _PrivateAdvancedJsonQuery + implements QueryReference<_PrivateAdvancedJsonQuerySnapshot> { + @override + _PrivateAdvancedJsonQuery limit(int limit); + + @override + _PrivateAdvancedJsonQuery limitToLast(int limit); + + _PrivateAdvancedJsonQuery whereDocumentId({ + String? isEqualTo, + String? isNotEqualTo, + String? isLessThan, + String? isLessThanOrEqualTo, + String? isGreaterThan, + String? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }); + _PrivateAdvancedJsonQuery whereFirstName({ + String? isEqualTo, + String? isNotEqualTo, + String? isLessThan, + String? isLessThanOrEqualTo, + String? isGreaterThan, + String? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }); + _PrivateAdvancedJsonQuery whereLastName({ + String? isEqualTo, + String? isNotEqualTo, + String? isLessThan, + String? isLessThanOrEqualTo, + String? isGreaterThan, + String? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }); + _PrivateAdvancedJsonQuery whereHashCode({ + int? isEqualTo, + int? isNotEqualTo, + int? isLessThan, + int? isLessThanOrEqualTo, + int? isGreaterThan, + int? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }); + + _PrivateAdvancedJsonQuery orderByDocumentId({ + bool descending = false, + String startAt, + String startAfter, + String endAt, + String endBefore, + _PrivateAdvancedJsonDocumentSnapshot? startAtDocument, + _PrivateAdvancedJsonDocumentSnapshot? endAtDocument, + _PrivateAdvancedJsonDocumentSnapshot? endBeforeDocument, + _PrivateAdvancedJsonDocumentSnapshot? startAfterDocument, + }); + + _PrivateAdvancedJsonQuery orderByFirstName({ + bool descending = false, + String? startAt, + String? startAfter, + String? endAt, + String? endBefore, + _PrivateAdvancedJsonDocumentSnapshot? startAtDocument, + _PrivateAdvancedJsonDocumentSnapshot? endAtDocument, + _PrivateAdvancedJsonDocumentSnapshot? endBeforeDocument, + _PrivateAdvancedJsonDocumentSnapshot? startAfterDocument, + }); + + _PrivateAdvancedJsonQuery orderByLastName({ + bool descending = false, + String? startAt, + String? startAfter, + String? endAt, + String? endBefore, + _PrivateAdvancedJsonDocumentSnapshot? startAtDocument, + _PrivateAdvancedJsonDocumentSnapshot? endAtDocument, + _PrivateAdvancedJsonDocumentSnapshot? endBeforeDocument, + _PrivateAdvancedJsonDocumentSnapshot? startAfterDocument, + }); + + _PrivateAdvancedJsonQuery orderByHashCode({ + bool descending = false, + int startAt, + int startAfter, + int endAt, + int endBefore, + _PrivateAdvancedJsonDocumentSnapshot? startAtDocument, + _PrivateAdvancedJsonDocumentSnapshot? endAtDocument, + _PrivateAdvancedJsonDocumentSnapshot? endBeforeDocument, + _PrivateAdvancedJsonDocumentSnapshot? startAfterDocument, + }); +} + +class _$_PrivateAdvancedJsonQuery + extends QueryReference<_PrivateAdvancedJsonQuerySnapshot> + implements _PrivateAdvancedJsonQuery { + _$_PrivateAdvancedJsonQuery( + this.reference, + this._collection, + ); + + final CollectionReference _collection; + + @override + final Query<_PrivateAdvancedJson> reference; + + _PrivateAdvancedJsonQuerySnapshot _decodeSnapshot( + QuerySnapshot<_PrivateAdvancedJson> snapshot, + ) { + final docs = snapshot.docs.map((e) { + return _PrivateAdvancedJsonQueryDocumentSnapshot._(e, e.data()); + }).toList(); + + final docChanges = snapshot.docChanges.map((change) { + return FirestoreDocumentChange<_PrivateAdvancedJsonDocumentSnapshot>( + type: change.type, + oldIndex: change.oldIndex, + newIndex: change.newIndex, + doc: _PrivateAdvancedJsonDocumentSnapshot._( + change.doc, change.doc.data()), + ); + }).toList(); + + return _PrivateAdvancedJsonQuerySnapshot._( + snapshot, + docs, + docChanges, + ); + } + + @override + Stream<_PrivateAdvancedJsonQuerySnapshot> snapshots( + [SnapshotOptions? options]) { + return reference.snapshots().map(_decodeSnapshot); + } + + @override + Future<_PrivateAdvancedJsonQuerySnapshot> get([GetOptions? options]) { + return reference.get(options).then(_decodeSnapshot); + } + + @override + _PrivateAdvancedJsonQuery limit(int limit) { + return _$_PrivateAdvancedJsonQuery( + reference.limit(limit), + _collection, + ); + } + + @override + _PrivateAdvancedJsonQuery limitToLast(int limit) { + return _$_PrivateAdvancedJsonQuery( + reference.limitToLast(limit), + _collection, + ); + } + + _PrivateAdvancedJsonQuery whereDocumentId({ + String? isEqualTo, + String? isNotEqualTo, + String? isLessThan, + String? isLessThanOrEqualTo, + String? isGreaterThan, + String? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }) { + return _$_PrivateAdvancedJsonQuery( + reference.where( + FieldPath.documentId, + isEqualTo: isEqualTo, + isNotEqualTo: isNotEqualTo, + isLessThan: isLessThan, + isLessThanOrEqualTo: isLessThanOrEqualTo, + isGreaterThan: isGreaterThan, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isNull: isNull, + whereIn: whereIn, + whereNotIn: whereNotIn, + ), + _collection, + ); + } + + _PrivateAdvancedJsonQuery whereFirstName({ + String? isEqualTo, + String? isNotEqualTo, + String? isLessThan, + String? isLessThanOrEqualTo, + String? isGreaterThan, + String? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }) { + return _$_PrivateAdvancedJsonQuery( + reference.where( + _$PrivateAdvancedJsonFieldMap["firstName"]!, + isEqualTo: isEqualTo, + isNotEqualTo: isNotEqualTo, + isLessThan: isLessThan, + isLessThanOrEqualTo: isLessThanOrEqualTo, + isGreaterThan: isGreaterThan, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isNull: isNull, + whereIn: whereIn, + whereNotIn: whereNotIn, + ), + _collection, + ); + } + + _PrivateAdvancedJsonQuery whereLastName({ + String? isEqualTo, + String? isNotEqualTo, + String? isLessThan, + String? isLessThanOrEqualTo, + String? isGreaterThan, + String? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }) { + return _$_PrivateAdvancedJsonQuery( + reference.where( + _$PrivateAdvancedJsonFieldMap["lastName"]!, + isEqualTo: isEqualTo, + isNotEqualTo: isNotEqualTo, + isLessThan: isLessThan, + isLessThanOrEqualTo: isLessThanOrEqualTo, + isGreaterThan: isGreaterThan, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isNull: isNull, + whereIn: whereIn, + whereNotIn: whereNotIn, + ), + _collection, + ); + } + + _PrivateAdvancedJsonQuery whereHashCode({ + int? isEqualTo, + int? isNotEqualTo, + int? isLessThan, + int? isLessThanOrEqualTo, + int? isGreaterThan, + int? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }) { + return _$_PrivateAdvancedJsonQuery( + reference.where( + _$PrivateAdvancedJsonFieldMap["hashCode"]!, + isEqualTo: isEqualTo, + isNotEqualTo: isNotEqualTo, + isLessThan: isLessThan, + isLessThanOrEqualTo: isLessThanOrEqualTo, + isGreaterThan: isGreaterThan, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isNull: isNull, + whereIn: whereIn, + whereNotIn: whereNotIn, + ), + _collection, + ); + } + + _PrivateAdvancedJsonQuery orderByDocumentId({ + bool descending = false, + Object? startAt = _sentinel, + Object? startAfter = _sentinel, + Object? endAt = _sentinel, + Object? endBefore = _sentinel, + _PrivateAdvancedJsonDocumentSnapshot? startAtDocument, + _PrivateAdvancedJsonDocumentSnapshot? endAtDocument, + _PrivateAdvancedJsonDocumentSnapshot? endBeforeDocument, + _PrivateAdvancedJsonDocumentSnapshot? startAfterDocument, + }) { + var query = reference.orderBy(FieldPath.documentId, descending: descending); + + if (startAtDocument != null) { + query = query.startAtDocument(startAtDocument.snapshot); + } + if (startAfterDocument != null) { + query = query.startAfterDocument(startAfterDocument.snapshot); + } + if (endAtDocument != null) { + query = query.endAtDocument(endAtDocument.snapshot); + } + if (endBeforeDocument != null) { + query = query.endBeforeDocument(endBeforeDocument.snapshot); + } + + if (startAt != _sentinel) { + query = query.startAt([startAt]); + } + if (startAfter != _sentinel) { + query = query.startAfter([startAfter]); + } + if (endAt != _sentinel) { + query = query.endAt([endAt]); + } + if (endBefore != _sentinel) { + query = query.endBefore([endBefore]); + } + + return _$_PrivateAdvancedJsonQuery(query, _collection); + } + + _PrivateAdvancedJsonQuery orderByFirstName({ + bool descending = false, + Object? startAt = _sentinel, + Object? startAfter = _sentinel, + Object? endAt = _sentinel, + Object? endBefore = _sentinel, + _PrivateAdvancedJsonDocumentSnapshot? startAtDocument, + _PrivateAdvancedJsonDocumentSnapshot? endAtDocument, + _PrivateAdvancedJsonDocumentSnapshot? endBeforeDocument, + _PrivateAdvancedJsonDocumentSnapshot? startAfterDocument, + }) { + var query = reference.orderBy(_$PrivateAdvancedJsonFieldMap["firstName"]!, + descending: descending); + + if (startAtDocument != null) { + query = query.startAtDocument(startAtDocument.snapshot); + } + if (startAfterDocument != null) { + query = query.startAfterDocument(startAfterDocument.snapshot); + } + if (endAtDocument != null) { + query = query.endAtDocument(endAtDocument.snapshot); + } + if (endBeforeDocument != null) { + query = query.endBeforeDocument(endBeforeDocument.snapshot); + } + + if (startAt != _sentinel) { + query = query.startAt([startAt]); + } + if (startAfter != _sentinel) { + query = query.startAfter([startAfter]); + } + if (endAt != _sentinel) { + query = query.endAt([endAt]); + } + if (endBefore != _sentinel) { + query = query.endBefore([endBefore]); + } + + return _$_PrivateAdvancedJsonQuery(query, _collection); + } + + _PrivateAdvancedJsonQuery orderByLastName({ + bool descending = false, + Object? startAt = _sentinel, + Object? startAfter = _sentinel, + Object? endAt = _sentinel, + Object? endBefore = _sentinel, + _PrivateAdvancedJsonDocumentSnapshot? startAtDocument, + _PrivateAdvancedJsonDocumentSnapshot? endAtDocument, + _PrivateAdvancedJsonDocumentSnapshot? endBeforeDocument, + _PrivateAdvancedJsonDocumentSnapshot? startAfterDocument, + }) { + var query = reference.orderBy(_$PrivateAdvancedJsonFieldMap["lastName"]!, + descending: descending); + + if (startAtDocument != null) { + query = query.startAtDocument(startAtDocument.snapshot); + } + if (startAfterDocument != null) { + query = query.startAfterDocument(startAfterDocument.snapshot); + } + if (endAtDocument != null) { + query = query.endAtDocument(endAtDocument.snapshot); + } + if (endBeforeDocument != null) { + query = query.endBeforeDocument(endBeforeDocument.snapshot); + } + + if (startAt != _sentinel) { + query = query.startAt([startAt]); + } + if (startAfter != _sentinel) { + query = query.startAfter([startAfter]); + } + if (endAt != _sentinel) { + query = query.endAt([endAt]); + } + if (endBefore != _sentinel) { + query = query.endBefore([endBefore]); + } + + return _$_PrivateAdvancedJsonQuery(query, _collection); + } + + _PrivateAdvancedJsonQuery orderByHashCode({ + bool descending = false, + Object? startAt = _sentinel, + Object? startAfter = _sentinel, + Object? endAt = _sentinel, + Object? endBefore = _sentinel, + _PrivateAdvancedJsonDocumentSnapshot? startAtDocument, + _PrivateAdvancedJsonDocumentSnapshot? endAtDocument, + _PrivateAdvancedJsonDocumentSnapshot? endBeforeDocument, + _PrivateAdvancedJsonDocumentSnapshot? startAfterDocument, + }) { + var query = reference.orderBy(_$PrivateAdvancedJsonFieldMap["hashCode"]!, + descending: descending); + + if (startAtDocument != null) { + query = query.startAtDocument(startAtDocument.snapshot); + } + if (startAfterDocument != null) { + query = query.startAfterDocument(startAfterDocument.snapshot); + } + if (endAtDocument != null) { + query = query.endAtDocument(endAtDocument.snapshot); + } + if (endBeforeDocument != null) { + query = query.endBeforeDocument(endBeforeDocument.snapshot); + } + + if (startAt != _sentinel) { + query = query.startAt([startAt]); + } + if (startAfter != _sentinel) { + query = query.startAfter([startAfter]); + } + if (endAt != _sentinel) { + query = query.endAt([endAt]); + } + if (endBefore != _sentinel) { + query = query.endBefore([endBefore]); + } + + return _$_PrivateAdvancedJsonQuery(query, _collection); + } + + @override + bool operator ==(Object other) { + return other is _$_PrivateAdvancedJsonQuery && + other.runtimeType == runtimeType && + other.reference == reference; + } + + @override + int get hashCode => Object.hash(runtimeType, reference); +} + +class _PrivateAdvancedJsonQuerySnapshot + extends FirestoreQuerySnapshot<_PrivateAdvancedJsonQueryDocumentSnapshot> { + _PrivateAdvancedJsonQuerySnapshot._( + this.snapshot, + this.docs, + this.docChanges, + ); + + final QuerySnapshot<_PrivateAdvancedJson> snapshot; + + @override + final List<_PrivateAdvancedJsonQueryDocumentSnapshot> docs; + + @override + final List> + docChanges; +} + +class _PrivateAdvancedJsonQueryDocumentSnapshot + extends FirestoreQueryDocumentSnapshot + implements _PrivateAdvancedJsonDocumentSnapshot { + _PrivateAdvancedJsonQueryDocumentSnapshot._(this.snapshot, this.data); + + @override + final QueryDocumentSnapshot<_PrivateAdvancedJson> snapshot; + + @override + _PrivateAdvancedJsonDocumentReference get reference { + return _PrivateAdvancedJsonDocumentReference(snapshot.reference); + } + + @override + final _PrivateAdvancedJson data; +} + +/// A collection reference object can be used for adding documents, +/// getting document references, and querying for documents +/// (using the methods inherited from Query). +abstract class EmptyModelCollectionReference + implements + EmptyModelQuery, + FirestoreCollectionReference { + factory EmptyModelCollectionReference([ + FirebaseFirestore? firestore, + ]) = _$EmptyModelCollectionReference; + + static EmptyModel fromFirestore( + DocumentSnapshot> snapshot, + SnapshotOptions? options, + ) { + return EmptyModel.fromJson(snapshot.data()!); + } + + static Map toFirestore( + EmptyModel value, + SetOptions? options, + ) { + return value.toJson(); + } + + @override + CollectionReference get reference; + + @override + EmptyModelDocumentReference doc([String? id]); + + /// Add a new document to this collection with the specified data, + /// assigning it a document ID automatically. + Future add(EmptyModel value); +} + +class _$EmptyModelCollectionReference extends _$EmptyModelQuery + implements EmptyModelCollectionReference { + factory _$EmptyModelCollectionReference([FirebaseFirestore? firestore]) { + firestore ??= FirebaseFirestore.instance; + + return _$EmptyModelCollectionReference._( + firestore.collection('firestore-example-app/test/config').withConverter( + fromFirestore: EmptyModelCollectionReference.fromFirestore, + toFirestore: EmptyModelCollectionReference.toFirestore, + ), + ); + } + + _$EmptyModelCollectionReference._( + CollectionReference reference, + ) : super(reference, reference); + + String get path => reference.path; + + @override + CollectionReference get reference => + super.reference as CollectionReference; + + @override + EmptyModelDocumentReference doc([String? id]) { + assert( + id == null || id.split('/').length == 1, + 'The document ID cannot be from a different collection', + ); + return EmptyModelDocumentReference( + reference.doc(id), + ); + } + + @override + Future add(EmptyModel value) { + return reference.add(value).then((ref) => EmptyModelDocumentReference(ref)); + } + + @override + bool operator ==(Object other) { + return other is _$EmptyModelCollectionReference && + other.runtimeType == runtimeType && + other.reference == reference; + } + + @override + int get hashCode => Object.hash(runtimeType, reference); +} + +abstract class EmptyModelDocumentReference + extends FirestoreDocumentReference { + factory EmptyModelDocumentReference(DocumentReference reference) = + _$EmptyModelDocumentReference; + + DocumentReference get reference; + + /// A reference to the [EmptyModelCollectionReference] containing this document. + EmptyModelCollectionReference get parent { + return _$EmptyModelCollectionReference(reference.firestore); + } + + @override + Stream snapshots(); + + @override + Future get([GetOptions? options]); + + @override + Future delete(); + + Future set(EmptyModel value); +} + +class _$EmptyModelDocumentReference + extends FirestoreDocumentReference + implements EmptyModelDocumentReference { + _$EmptyModelDocumentReference(this.reference); + + @override + final DocumentReference reference; + + /// A reference to the [EmptyModelCollectionReference] containing this document. + EmptyModelCollectionReference get parent { + return _$EmptyModelCollectionReference(reference.firestore); + } + + @override + Stream snapshots() { + return reference.snapshots().map((snapshot) { + return EmptyModelDocumentSnapshot._( + snapshot, + snapshot.data(), + ); + }); + } + + @override + Future get([GetOptions? options]) { + return reference.get(options).then((snapshot) { + return EmptyModelDocumentSnapshot._( + snapshot, + snapshot.data(), + ); + }); + } + + @override + Future delete() { + return reference.delete(); + } + + Future set(EmptyModel value) { + return reference.set(value); + } + + @override + bool operator ==(Object other) { + return other is EmptyModelDocumentReference && + other.runtimeType == runtimeType && + other.parent == parent && + other.id == id; + } + + @override + int get hashCode => Object.hash(runtimeType, parent, id); +} + +class EmptyModelDocumentSnapshot extends FirestoreDocumentSnapshot { + EmptyModelDocumentSnapshot._( + this.snapshot, + this.data, + ); + + @override + final DocumentSnapshot snapshot; + + @override + EmptyModelDocumentReference get reference { + return EmptyModelDocumentReference( + snapshot.reference, + ); + } + + @override + final EmptyModel? data; +} + +abstract class EmptyModelQuery + implements QueryReference { + @override + EmptyModelQuery limit(int limit); + + @override + EmptyModelQuery limitToLast(int limit); + + EmptyModelQuery whereDocumentId({ + String? isEqualTo, + String? isNotEqualTo, + String? isLessThan, + String? isLessThanOrEqualTo, + String? isGreaterThan, + String? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }); + + EmptyModelQuery orderByDocumentId({ + bool descending = false, + String startAt, + String startAfter, + String endAt, + String endBefore, + EmptyModelDocumentSnapshot? startAtDocument, + EmptyModelDocumentSnapshot? endAtDocument, + EmptyModelDocumentSnapshot? endBeforeDocument, + EmptyModelDocumentSnapshot? startAfterDocument, + }); +} + +class _$EmptyModelQuery extends QueryReference + implements EmptyModelQuery { + _$EmptyModelQuery( + this.reference, + this._collection, + ); + + final CollectionReference _collection; + + @override + final Query reference; + + EmptyModelQuerySnapshot _decodeSnapshot( + QuerySnapshot snapshot, + ) { + final docs = snapshot.docs.map((e) { + return EmptyModelQueryDocumentSnapshot._(e, e.data()); + }).toList(); + + final docChanges = snapshot.docChanges.map((change) { + return FirestoreDocumentChange( + type: change.type, + oldIndex: change.oldIndex, + newIndex: change.newIndex, + doc: EmptyModelDocumentSnapshot._(change.doc, change.doc.data()), + ); + }).toList(); + + return EmptyModelQuerySnapshot._( + snapshot, + docs, + docChanges, + ); + } + + @override + Stream snapshots([SnapshotOptions? options]) { + return reference.snapshots().map(_decodeSnapshot); + } + + @override + Future get([GetOptions? options]) { + return reference.get(options).then(_decodeSnapshot); + } + + @override + EmptyModelQuery limit(int limit) { + return _$EmptyModelQuery( + reference.limit(limit), + _collection, + ); + } + + @override + EmptyModelQuery limitToLast(int limit) { + return _$EmptyModelQuery( + reference.limitToLast(limit), + _collection, + ); + } + + EmptyModelQuery whereDocumentId({ + String? isEqualTo, + String? isNotEqualTo, + String? isLessThan, + String? isLessThanOrEqualTo, + String? isGreaterThan, + String? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }) { + return _$EmptyModelQuery( + reference.where( + FieldPath.documentId, + isEqualTo: isEqualTo, + isNotEqualTo: isNotEqualTo, + isLessThan: isLessThan, + isLessThanOrEqualTo: isLessThanOrEqualTo, + isGreaterThan: isGreaterThan, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isNull: isNull, + whereIn: whereIn, + whereNotIn: whereNotIn, + ), + _collection, + ); + } + + EmptyModelQuery orderByDocumentId({ + bool descending = false, + Object? startAt = _sentinel, + Object? startAfter = _sentinel, + Object? endAt = _sentinel, + Object? endBefore = _sentinel, + EmptyModelDocumentSnapshot? startAtDocument, + EmptyModelDocumentSnapshot? endAtDocument, + EmptyModelDocumentSnapshot? endBeforeDocument, + EmptyModelDocumentSnapshot? startAfterDocument, + }) { + var query = reference.orderBy(FieldPath.documentId, descending: descending); + + if (startAtDocument != null) { + query = query.startAtDocument(startAtDocument.snapshot); + } + if (startAfterDocument != null) { + query = query.startAfterDocument(startAfterDocument.snapshot); + } + if (endAtDocument != null) { + query = query.endAtDocument(endAtDocument.snapshot); + } + if (endBeforeDocument != null) { + query = query.endBeforeDocument(endBeforeDocument.snapshot); + } + + if (startAt != _sentinel) { + query = query.startAt([startAt]); + } + if (startAfter != _sentinel) { + query = query.startAfter([startAfter]); + } + if (endAt != _sentinel) { + query = query.endAt([endAt]); + } + if (endBefore != _sentinel) { + query = query.endBefore([endBefore]); + } + + return _$EmptyModelQuery(query, _collection); + } + + @override + bool operator ==(Object other) { + return other is _$EmptyModelQuery && + other.runtimeType == runtimeType && + other.reference == reference; + } + + @override + int get hashCode => Object.hash(runtimeType, reference); +} + +class EmptyModelQuerySnapshot + extends FirestoreQuerySnapshot { + EmptyModelQuerySnapshot._( + this.snapshot, + this.docs, + this.docChanges, + ); + + final QuerySnapshot snapshot; + + @override + final List docs; + + @override + final List> docChanges; +} + +class EmptyModelQueryDocumentSnapshot extends FirestoreQueryDocumentSnapshot + implements EmptyModelDocumentSnapshot { + EmptyModelQueryDocumentSnapshot._(this.snapshot, this.data); + + @override + final QueryDocumentSnapshot snapshot; + + @override + EmptyModelDocumentReference get reference { + return EmptyModelDocumentReference(snapshot.reference); + } + + @override + final EmptyModel data; +} + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +EmptyModel _$EmptyModelFromJson(Map json) => EmptyModel(); + +const _$EmptyModelFieldMap = {}; + +Map _$EmptyModelToJson(EmptyModel instance) => + {}; + +AdvancedJson _$AdvancedJsonFromJson(Map json) => AdvancedJson( + firstName: json['first_name'] as String?, + lastName: json['LAST_NAME'] as String?, + ); + +const _$AdvancedJsonFieldMap = { + 'firstName': 'first_name', + 'lastName': 'LAST_NAME', +}; + +Map _$AdvancedJsonToJson(AdvancedJson instance) => + { + 'first_name': instance.firstName, + 'LAST_NAME': instance.lastName, + }; + +_PrivateAdvancedJson _$PrivateAdvancedJsonFromJson(Map json) => + _PrivateAdvancedJson( + firstName: json['first_name'] as String?, + lastName: json['LAST_NAME'] as String?, + ); + +const _$PrivateAdvancedJsonFieldMap = { + 'firstName': 'first_name', + 'lastName': 'LAST_NAME', +}; + +Map _$PrivateAdvancedJsonToJson( + _PrivateAdvancedJson instance) => + { + 'first_name': instance.firstName, + 'LAST_NAME': instance.lastName, + }; diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/query.g.dart b/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/query.g.dart index acddef9b87a2..4fbd5dfd490b 100644 --- a/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/query.g.dart +++ b/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/query.g.dart @@ -42,6 +42,9 @@ abstract class DateTimeQueryCollectionReference return _$DateTimeQueryToJson(value); } + @override + CollectionReference get reference; + @override DateTimeQueryDocumentReference doc([String? id]); @@ -373,7 +376,7 @@ class _$DateTimeQueryQuery extends QueryReference }) { return _$DateTimeQueryQuery( reference.where( - "time", + _$DateTimeQueryFieldMap["time"]!, isEqualTo: isEqualTo, isNotEqualTo: isNotEqualTo, isLessThan: isLessThan, @@ -441,7 +444,8 @@ class _$DateTimeQueryQuery extends QueryReference DateTimeQueryDocumentSnapshot? endBeforeDocument, DateTimeQueryDocumentSnapshot? startAfterDocument, }) { - var query = reference.orderBy("time", descending: descending); + var query = reference.orderBy(_$DateTimeQueryFieldMap["time"]!, + descending: descending); if (startAtDocument != null) { query = query.startAtDocument(startAtDocument.snapshot); @@ -541,6 +545,9 @@ abstract class TimestampQueryCollectionReference return _$TimestampQueryToJson(value); } + @override + CollectionReference get reference; + @override TimestampQueryDocumentReference doc([String? id]); @@ -874,7 +881,7 @@ class _$TimestampQueryQuery extends QueryReference }) { return _$TimestampQueryQuery( reference.where( - "time", + _$TimestampQueryFieldMap["time"]!, isEqualTo: isEqualTo, isNotEqualTo: isNotEqualTo, isLessThan: isLessThan, @@ -942,7 +949,8 @@ class _$TimestampQueryQuery extends QueryReference TimestampQueryDocumentSnapshot? endBeforeDocument, TimestampQueryDocumentSnapshot? startAfterDocument, }) { - var query = reference.orderBy("time", descending: descending); + var query = reference.orderBy(_$TimestampQueryFieldMap["time"]!, + descending: descending); if (startAtDocument != null) { query = query.startAtDocument(startAtDocument.snapshot); @@ -1043,6 +1051,9 @@ abstract class GeoPointQueryCollectionReference return _$GeoPointQueryToJson(value); } + @override + CollectionReference get reference; + @override GeoPointQueryDocumentReference doc([String? id]); @@ -1376,7 +1387,7 @@ class _$GeoPointQueryQuery extends QueryReference }) { return _$GeoPointQueryQuery( reference.where( - "point", + _$GeoPointQueryFieldMap["point"]!, isEqualTo: isEqualTo, isNotEqualTo: isNotEqualTo, isLessThan: isLessThan, @@ -1444,7 +1455,8 @@ class _$GeoPointQueryQuery extends QueryReference GeoPointQueryDocumentSnapshot? endBeforeDocument, GeoPointQueryDocumentSnapshot? startAfterDocument, }) { - var query = reference.orderBy("point", descending: descending); + var query = reference.orderBy(_$GeoPointQueryFieldMap["point"]!, + descending: descending); if (startAtDocument != null) { query = query.startAtDocument(startAtDocument.snapshot); @@ -1544,6 +1556,9 @@ abstract class DocumentReferenceQueryCollectionReference return _$DocumentReferenceQueryToJson(value); } + @override + CollectionReference get reference; + @override DocumentReferenceQueryDocumentReference doc([String? id]); @@ -1884,7 +1899,7 @@ class _$DocumentReferenceQueryQuery }) { return _$DocumentReferenceQueryQuery( reference.where( - "ref", + _$DocumentReferenceQueryFieldMap["ref"]!, isEqualTo: isEqualTo, isNotEqualTo: isNotEqualTo, isLessThan: isLessThan, @@ -1952,7 +1967,8 @@ class _$DocumentReferenceQueryQuery DocumentReferenceQueryDocumentSnapshot? endBeforeDocument, DocumentReferenceQueryDocumentSnapshot? startAfterDocument, }) { - var query = reference.orderBy("ref", descending: descending); + var query = reference.orderBy(_$DocumentReferenceQueryFieldMap["ref"]!, + descending: descending); if (startAtDocument != null) { query = query.startAtDocument(startAtDocument.snapshot); @@ -2038,6 +2054,10 @@ DateTimeQuery _$DateTimeQueryFromJson(Map json) => const FirestoreDateTimeConverter().fromJson(json['time'] as Timestamp), ); +const _$DateTimeQueryFieldMap = { + 'time': 'time', +}; + Map _$DateTimeQueryToJson(DateTimeQuery instance) => { 'time': const FirestoreDateTimeConverter().toJson(instance.time), @@ -2048,6 +2068,10 @@ TimestampQuery _$TimestampQueryFromJson(Map json) => const FirestoreTimestampConverter().fromJson(json['time'] as Timestamp), ); +const _$TimestampQueryFieldMap = { + 'time': 'time', +}; + Map _$TimestampQueryToJson(TimestampQuery instance) => { 'time': const FirestoreTimestampConverter().toJson(instance.time), @@ -2058,6 +2082,10 @@ GeoPointQuery _$GeoPointQueryFromJson(Map json) => const FirestoreGeoPointConverter().fromJson(json['point'] as GeoPoint), ); +const _$GeoPointQueryFieldMap = { + 'point': 'point', +}; + Map _$GeoPointQueryToJson(GeoPointQuery instance) => { 'point': const FirestoreGeoPointConverter().toJson(instance.point), @@ -2070,6 +2098,10 @@ DocumentReferenceQuery _$DocumentReferenceQueryFromJson( .fromJson(json['ref'] as DocumentReference>), ); +const _$DocumentReferenceQueryFieldMap = { + 'ref': 'ref', +}; + Map _$DocumentReferenceQueryToJson( DocumentReferenceQuery instance) => {