From f4c21f834569bb363c80af583b53164f7cbd5ada Mon Sep 17 00:00:00 2001 From: Rexios Date: Tue, 10 Oct 2023 12:56:09 -0400 Subject: [PATCH] feat(cloud_firestore_odm_generator): Support all serializable types (#11365) --- .../cloud_firestore_odm/example/build.yaml | 1 + .../collection_reference_test.dart | 78 + .../query_reference_test.dart | 16 + .../example/lib/integration.dart | 13 - .../example/lib/integration.g.dart | 933 +------ .../example/lib/integration/enums.dart | 39 + .../example/lib/integration/enums.g.dart | 1512 +++++++++++ .../example/lib/integration/freezed.g.dart | 122 +- .../lib/integration/named_query.g.dart | 44 +- .../example/lib/integration/query.dart | 9 + .../example/lib/integration/query.g.dart | 988 +++++++- .../example/lib/movie.g.dart | 375 ++- .../cloud_firestore_odm_generator/build.yaml | 1 + .../build.yaml | 3 +- .../lib/freezed.g.dart | 122 +- .../lib/model.dart | 16 - .../lib/simple.dart | 19 +- .../lib/simple.g.dart | 2254 ++++++++++++----- .../lib/src/collection_data.dart | 129 +- .../lib/src/collection_generator.dart | 2 +- .../lib/src/templates/document_reference.dart | 2 +- .../lib/src/templates/query_reference.dart | 22 +- .../pubspec.yaml | 1 + .../test/document_reference_test.dart | 7 +- .../doc/defining-models.md | 1 + 25 files changed, 4870 insertions(+), 1839 deletions(-) create mode 100644 packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/enums.dart create mode 100644 packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/enums.g.dart delete mode 100644 packages/cloud_firestore_odm/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/lib/model.dart diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm/example/build.yaml b/packages/cloud_firestore_odm/cloud_firestore_odm/example/build.yaml index c41289779073..87792e3f9f87 100644 --- a/packages/cloud_firestore_odm/cloud_firestore_odm/example/build.yaml +++ b/packages/cloud_firestore_odm/cloud_firestore_odm/example/build.yaml @@ -15,6 +15,7 @@ targets: - lib/** options: create_field_map: true + create_per_field_to_json: true source_gen|combining_builder: options: ignore_for_file: diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm/example/integration_test/collection_reference_test.dart b/packages/cloud_firestore_odm/cloud_firestore_odm/example/integration_test/collection_reference_test.dart index 1c85b61abbe9..2d9ec22d31bc 100644 --- a/packages/cloud_firestore_odm/cloud_firestore_odm/example/integration_test/collection_reference_test.dart +++ b/packages/cloud_firestore_odm/cloud_firestore_odm/example/integration_test/collection_reference_test.dart @@ -7,6 +7,7 @@ import 'dart:async'; import 'package:async/async.dart'; import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:cloud_firestore_odm_example/integration.dart'; +import 'package:cloud_firestore_odm_example/integration/enums.dart'; import 'package:cloud_firestore_odm_example/movie.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -975,4 +976,81 @@ void main() { }); }); }); + + group('enums', () { + test('enumValue', () async { + final collection = await initializeTest(EnumsCollectionReference()); + + await collection.add(Enums(id: 'A')); + await collection.add(Enums(id: 'B', enumValue: TestEnum.two)); + await collection.add(Enums(id: 'C', enumValue: TestEnum.two)); + + final querySnap = + await collection.whereEnumValue(isEqualTo: TestEnum.two).get(); + + expect( + querySnap.docs.map((e) => e.data.id), + ['B', 'C'], + ); + }); + + test('nullable enumValue', () async { + final collection = await initializeTest(EnumsCollectionReference()); + + await collection.add(Enums(id: 'A')); + await collection.add(Enums(id: 'B', nullableEnumValue: TestEnum.two)); + await collection.add(Enums(id: 'C', nullableEnumValue: TestEnum.two)); + + final querySnap = await collection + .whereNullableEnumValue(isEqualTo: TestEnum.two) + .get(); + + expect( + querySnap.docs.map((e) => e.data.id), + ['B', 'C'], + ); + }); + + test('enumList', () async { + final collection = await initializeTest(EnumsCollectionReference()); + + await collection + .add(Enums(id: 'A', enumList: [TestEnum.one, TestEnum.three])); + await collection + .add(Enums(id: 'B', enumList: [TestEnum.two, TestEnum.three])); + await collection + .add(Enums(id: 'C', enumList: [TestEnum.two, TestEnum.three])); + + final querySnap = + await collection.whereEnumList(arrayContains: TestEnum.two).get(); + + expect( + querySnap.docs.map((e) => e.data.id), + ['B', 'C'], + ); + }); + + test('nullable enumList', () async { + final collection = await initializeTest(EnumsCollectionReference()); + + await collection.add( + Enums(id: 'A', nullableEnumList: [TestEnum.one, TestEnum.three]), + ); + await collection.add( + Enums(id: 'B', nullableEnumList: [TestEnum.two, TestEnum.three]), + ); + await collection.add( + Enums(id: 'C', nullableEnumList: [TestEnum.two, TestEnum.three]), + ); + + final querySnap = await collection + .whereNullableEnumList(arrayContains: TestEnum.two) + .get(); + + expect( + querySnap.docs.map((e) => e.data.id), + ['B', 'C'], + ); + }); + }); } diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm/example/integration_test/query_reference_test.dart b/packages/cloud_firestore_odm/cloud_firestore_odm/example/integration_test/query_reference_test.dart index c08d5432c611..942683969ce6 100644 --- a/packages/cloud_firestore_odm/cloud_firestore_odm/example/integration_test/query_reference_test.dart +++ b/packages/cloud_firestore_odm/cloud_firestore_odm/example/integration_test/query_reference_test.dart @@ -92,6 +92,22 @@ void main() { }); }); + test('supports Durations', () async { + final ref = await initializeTest(durationQueryRef); + + await ref.add(DurationQuery(const Duration(days: 1))); + await ref.add(DurationQuery(const Duration(days: 2))); + await ref.add(DurationQuery(const Duration(days: 3))); + + final snapshot = + await ref.orderByDuration(startAt: const Duration(days: 2)).get(); + + expect(snapshot.docs.length, 2); + + expect(snapshot.docs[0].data.duration, const Duration(days: 2)); + expect(snapshot.docs[1].data.duration, const Duration(days: 3)); + }); + test('supports DateTimes', () async { final ref = await initializeTest(dateTimeQueryRef); diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration.dart b/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration.dart index bfdbc643ee48..5bdee31f13d3 100644 --- a/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration.dart +++ b/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration.dart @@ -21,19 +21,6 @@ class EmptyModel { @Collection('firestore-example-app/test/config') final emptyModelRef = EmptyModelCollectionReference(); -@Collection('root') -class ManualJson { - ManualJson(this.value); - - factory ManualJson.fromJson(Map json) { - return ManualJson(json['value']! as String); - } - - final String value; - - Map toJson() => {'value': value}; -} - @Collection('firestore-example-app/test/advanced') @JsonSerializable(fieldRename: FieldRename.snake) class AdvancedJson { 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 index e0912836168e..379fd38026a1 100644 --- 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 @@ -9,7 +9,7 @@ part of 'integration.dart'; // ************************************************************************** // 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, require_trailing_commas, prefer_single_quotes, prefer_double_quotes, use_super_parameters +// 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, require_trailing_commas, prefer_single_quotes, prefer_double_quotes, use_super_parameters, duplicate_ignore class _Sentinel { const _Sentinel(); @@ -17,774 +17,6 @@ class _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, $referenceWithoutCursor: 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(); - - /// Updates data on the document. Data will be merged with any existing - /// document data. - /// - /// If no document exists yet, the update will fail. - Future update({ - String value, - FieldValue valueFieldValue, - }); - - /// Updates fields in the current document using the transaction API. - /// - /// The update will fail if applied to a document that does not exist. - void transactionUpdate( - Transaction transaction, { - String value, - FieldValue valueFieldValue, - }); -} - -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(ManualJsonDocumentSnapshot._); - } - - @override - Future get([GetOptions? options]) { - return reference.get(options).then(ManualJsonDocumentSnapshot._); - } - - @override - Future transactionGet(Transaction transaction) { - return transaction.get(reference).then(ManualJsonDocumentSnapshot._); - } - - Future update({ - Object? value = _sentinel, - FieldValue? valueFieldValue, - }) async { - assert( - value == _sentinel || valueFieldValue == null, - "Cannot specify both value and valueFieldValue", - ); - final json = { - if (value != _sentinel) 'value': value as String, - if (valueFieldValue != null) 'value': valueFieldValue, - }; - - return reference.update(json); - } - - void transactionUpdate( - Transaction transaction, { - Object? value = _sentinel, - FieldValue? valueFieldValue, - }) { - assert( - value == _sentinel || valueFieldValue == null, - "Cannot specify both value and valueFieldValue", - ); - final json = { - if (value != _sentinel) 'value': value as String, - if (valueFieldValue != null) 'value': valueFieldValue, - }; - - transaction.update(reference, json); - } - - @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); -} - -abstract class ManualJsonQuery - implements QueryReference { - @override - ManualJsonQuery limit(int limit); - - @override - ManualJsonQuery limitToLast(int limit); - - /// Perform an order query based on a [FieldPath]. - /// - /// This method is considered unsafe as it does check that the field path - /// maps to a valid property or that parameters such as [isEqualTo] receive - /// a value of the correct type. - /// - /// If possible, instead use the more explicit variant of order queries: - /// - /// **AVOID**: - /// ```dart - /// collection.orderByFieldPath( - /// FieldPath.fromString('title'), - /// startAt: 'title', - /// ); - /// ``` - /// - /// **PREFER**: - /// ```dart - /// collection.orderByTitle(startAt: 'title'); - /// ``` - ManualJsonQuery orderByFieldPath( - FieldPath fieldPath, { - bool descending = false, - Object? startAt, - Object? startAfter, - Object? endAt, - Object? endBefore, - ManualJsonDocumentSnapshot? startAtDocument, - ManualJsonDocumentSnapshot? endAtDocument, - ManualJsonDocumentSnapshot? endBeforeDocument, - ManualJsonDocumentSnapshot? startAfterDocument, - }); - - /// Perform a where query based on a [FieldPath]. - /// - /// This method is considered unsafe as it does check that the field path - /// maps to a valid property or that parameters such as [isEqualTo] receive - /// a value of the correct type. - /// - /// If possible, instead use the more explicit variant of where queries: - /// - /// **AVOID**: - /// ```dart - /// collection.whereFieldPath(FieldPath.fromString('title'), isEqualTo: 'title'); - /// ``` - /// - /// **PREFER**: - /// ```dart - /// collection.whereTitle(isEqualTo: 'title'); - /// ``` - ManualJsonQuery whereFieldPath( - FieldPath fieldPath, { - Object? isEqualTo, - Object? isNotEqualTo, - Object? isLessThan, - Object? isLessThanOrEqualTo, - Object? isGreaterThan, - Object? isGreaterThanOrEqualTo, - Object? arrayContains, - List? arrayContainsAny, - List? whereIn, - List? whereNotIn, - bool? isNull, - }); - - 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._collection, { - required Query $referenceWithoutCursor, - $QueryCursor $queryCursor = const $QueryCursor(), - }) : super( - $referenceWithoutCursor: $referenceWithoutCursor, - $queryCursor: $queryCursor, - ); - - final CollectionReference _collection; - - @override - Stream snapshots([SnapshotOptions? options]) { - return reference - .snapshots() - .map(ManualJsonQuerySnapshot._fromQuerySnapshot); - } - - @override - Future get([GetOptions? options]) { - return reference - .get(options) - .then(ManualJsonQuerySnapshot._fromQuerySnapshot); - } - - @override - ManualJsonQuery limit(int limit) { - return _$ManualJsonQuery( - _collection, - $referenceWithoutCursor: $referenceWithoutCursor.limit(limit), - $queryCursor: $queryCursor, - ); - } - - @override - ManualJsonQuery limitToLast(int limit) { - return _$ManualJsonQuery( - _collection, - $referenceWithoutCursor: $referenceWithoutCursor.limitToLast(limit), - $queryCursor: $queryCursor, - ); - } - - ManualJsonQuery orderByFieldPath( - FieldPath fieldPath, { - bool descending = false, - Object? startAt = _sentinel, - Object? startAfter = _sentinel, - Object? endAt = _sentinel, - Object? endBefore = _sentinel, - ManualJsonDocumentSnapshot? startAtDocument, - ManualJsonDocumentSnapshot? endAtDocument, - ManualJsonDocumentSnapshot? endBeforeDocument, - ManualJsonDocumentSnapshot? startAfterDocument, - }) { - final query = - $referenceWithoutCursor.orderBy(fieldPath, descending: descending); - var queryCursor = $queryCursor; - - if (startAtDocument != null) { - queryCursor = queryCursor.copyWith( - startAt: const [], - startAtDocumentSnapshot: startAtDocument.snapshot, - ); - } - if (startAfterDocument != null) { - queryCursor = queryCursor.copyWith( - startAfter: const [], - startAfterDocumentSnapshot: startAfterDocument.snapshot, - ); - } - if (endAtDocument != null) { - queryCursor = queryCursor.copyWith( - endAt: const [], - endAtDocumentSnapshot: endAtDocument.snapshot, - ); - } - if (endBeforeDocument != null) { - queryCursor = queryCursor.copyWith( - endBefore: const [], - endBeforeDocumentSnapshot: endBeforeDocument.snapshot, - ); - } - - if (startAt != _sentinel) { - queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], - startAtDocumentSnapshot: null, - ); - } - if (startAfter != _sentinel) { - queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], - startAfterDocumentSnapshot: null, - ); - } - if (endAt != _sentinel) { - queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], - endAtDocumentSnapshot: null, - ); - } - if (endBefore != _sentinel) { - queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], - endBeforeDocumentSnapshot: null, - ); - } - return _$ManualJsonQuery( - _collection, - $referenceWithoutCursor: query, - $queryCursor: queryCursor, - ); - } - - ManualJsonQuery whereFieldPath( - FieldPath fieldPath, { - Object? isEqualTo, - Object? isNotEqualTo, - Object? isLessThan, - Object? isLessThanOrEqualTo, - Object? isGreaterThan, - Object? isGreaterThanOrEqualTo, - Object? arrayContains, - List? arrayContainsAny, - List? whereIn, - List? whereNotIn, - bool? isNull, - }) { - return _$ManualJsonQuery( - _collection, - $referenceWithoutCursor: $referenceWithoutCursor.where( - fieldPath, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, - arrayContains: arrayContains, - arrayContainsAny: arrayContainsAny, - whereIn: whereIn, - whereNotIn: whereNotIn, - isNull: isNull, - ), - $queryCursor: $queryCursor, - ); - } - - ManualJsonQuery whereDocumentId({ - String? isEqualTo, - String? isNotEqualTo, - String? isLessThan, - String? isLessThanOrEqualTo, - String? isGreaterThan, - String? isGreaterThanOrEqualTo, - bool? isNull, - List? whereIn, - List? whereNotIn, - }) { - return _$ManualJsonQuery( - _collection, - $referenceWithoutCursor: $referenceWithoutCursor.where( - FieldPath.documentId, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, - isNull: isNull, - whereIn: whereIn, - whereNotIn: whereNotIn, - ), - $queryCursor: $queryCursor, - ); - } - - ManualJsonQuery whereValue({ - String? isEqualTo, - String? isNotEqualTo, - String? isLessThan, - String? isLessThanOrEqualTo, - String? isGreaterThan, - String? isGreaterThanOrEqualTo, - bool? isNull, - List? whereIn, - List? whereNotIn, - }) { - return _$ManualJsonQuery( - _collection, - $referenceWithoutCursor: $referenceWithoutCursor.where( - 'value', - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, - isNull: isNull, - whereIn: whereIn, - whereNotIn: whereNotIn, - ), - $queryCursor: $queryCursor, - ); - } - - 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, - }) { - final query = $referenceWithoutCursor.orderBy(FieldPath.documentId, - descending: descending); - var queryCursor = $queryCursor; - - if (startAtDocument != null) { - queryCursor = queryCursor.copyWith( - startAt: const [], - startAtDocumentSnapshot: startAtDocument.snapshot, - ); - } - if (startAfterDocument != null) { - queryCursor = queryCursor.copyWith( - startAfter: const [], - startAfterDocumentSnapshot: startAfterDocument.snapshot, - ); - } - if (endAtDocument != null) { - queryCursor = queryCursor.copyWith( - endAt: const [], - endAtDocumentSnapshot: endAtDocument.snapshot, - ); - } - if (endBeforeDocument != null) { - queryCursor = queryCursor.copyWith( - endBefore: const [], - endBeforeDocumentSnapshot: endBeforeDocument.snapshot, - ); - } - - if (startAt != _sentinel) { - queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], - startAtDocumentSnapshot: null, - ); - } - if (startAfter != _sentinel) { - queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], - startAfterDocumentSnapshot: null, - ); - } - if (endAt != _sentinel) { - queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], - endAtDocumentSnapshot: null, - ); - } - if (endBefore != _sentinel) { - queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], - endBeforeDocumentSnapshot: null, - ); - } - - return _$ManualJsonQuery( - _collection, - $referenceWithoutCursor: query, - $queryCursor: queryCursor, - ); - } - - 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, - }) { - final query = - $referenceWithoutCursor.orderBy('value', descending: descending); - var queryCursor = $queryCursor; - - if (startAtDocument != null) { - queryCursor = queryCursor.copyWith( - startAt: const [], - startAtDocumentSnapshot: startAtDocument.snapshot, - ); - } - if (startAfterDocument != null) { - queryCursor = queryCursor.copyWith( - startAfter: const [], - startAfterDocumentSnapshot: startAfterDocument.snapshot, - ); - } - if (endAtDocument != null) { - queryCursor = queryCursor.copyWith( - endAt: const [], - endAtDocumentSnapshot: endAtDocument.snapshot, - ); - } - if (endBeforeDocument != null) { - queryCursor = queryCursor.copyWith( - endBefore: const [], - endBeforeDocumentSnapshot: endBeforeDocument.snapshot, - ); - } - - if (startAt != _sentinel) { - queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], - startAtDocumentSnapshot: null, - ); - } - if (startAfter != _sentinel) { - queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], - startAfterDocumentSnapshot: null, - ); - } - if (endAt != _sentinel) { - queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], - endAtDocumentSnapshot: null, - ); - } - if (endBefore != _sentinel) { - queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], - endBeforeDocumentSnapshot: null, - ); - } - - return _$ManualJsonQuery( - _collection, - $referenceWithoutCursor: query, - $queryCursor: queryCursor, - ); - } - - @override - bool operator ==(Object other) { - return other is _$ManualJsonQuery && - other.runtimeType == runtimeType && - other.reference == reference; - } - - @override - int get hashCode => Object.hash(runtimeType, reference); -} - -class ManualJsonDocumentSnapshot extends FirestoreDocumentSnapshot { - ManualJsonDocumentSnapshot._(this.snapshot) : data = snapshot.data(); - - @override - final DocumentSnapshot snapshot; - - @override - ManualJsonDocumentReference get reference { - return ManualJsonDocumentReference( - snapshot.reference, - ); - } - - @override - final ManualJson? data; -} - -class ManualJsonQuerySnapshot extends FirestoreQuerySnapshot { - ManualJsonQuerySnapshot._( - this.snapshot, - this.docs, - this.docChanges, - ); - - factory ManualJsonQuerySnapshot._fromQuerySnapshot( - QuerySnapshot snapshot, - ) { - final docs = snapshot.docs.map(ManualJsonQueryDocumentSnapshot._).toList(); - - final docChanges = snapshot.docChanges.map((change) { - return _decodeDocumentChange( - change, - ManualJsonDocumentSnapshot._, - ); - }).toList(); - - return ManualJsonQuerySnapshot._( - snapshot, - docs, - docChanges, - ); - } - - static FirestoreDocumentChange - _decodeDocumentChange( - DocumentChange docChange, - ManualJsonDocumentSnapshot Function(DocumentSnapshot doc) decodeDoc, - ) { - return FirestoreDocumentChange( - type: docChange.type, - oldIndex: docChange.oldIndex, - newIndex: docChange.newIndex, - doc: decodeDoc(docChange.doc), - ); - } - - final QuerySnapshot snapshot; - - @override - final List docs; - - @override - final List> docChanges; -} - -class ManualJsonQueryDocumentSnapshot - extends FirestoreQueryDocumentSnapshot - implements ManualJsonDocumentSnapshot { - ManualJsonQueryDocumentSnapshot._(this.snapshot) : data = snapshot.data(); - - @override - final QueryDocumentSnapshot snapshot; - - @override - final ManualJson data; - - @override - ManualJsonDocumentReference get reference { - return ManualJsonDocumentReference(snapshot.reference); - } -} - /// A collection reference object can be used for adding documents, /// getting document references, and querying for documents /// (using the methods inherited from Query). @@ -962,11 +194,13 @@ class _$AdvancedJsonDocumentReference extends FirestoreDocumentReference< ); final json = { if (firstName != _sentinel) - _$AdvancedJsonFieldMap['firstName']!: firstName as String?, + _$AdvancedJsonFieldMap['firstName']!: + _$AdvancedJsonPerFieldToJson.firstName(firstName as String?), if (firstNameFieldValue != null) _$AdvancedJsonFieldMap['firstName']!: firstNameFieldValue, if (lastName != _sentinel) - _$AdvancedJsonFieldMap['lastName']!: lastName as String?, + _$AdvancedJsonFieldMap['lastName']!: + _$AdvancedJsonPerFieldToJson.lastName(lastName as String?), if (lastNameFieldValue != null) _$AdvancedJsonFieldMap['lastName']!: lastNameFieldValue, }; @@ -991,11 +225,13 @@ class _$AdvancedJsonDocumentReference extends FirestoreDocumentReference< ); final json = { if (firstName != _sentinel) - _$AdvancedJsonFieldMap['firstName']!: firstName as String?, + _$AdvancedJsonFieldMap['firstName']!: + _$AdvancedJsonPerFieldToJson.firstName(firstName as String?), if (firstNameFieldValue != null) _$AdvancedJsonFieldMap['firstName']!: firstNameFieldValue, if (lastName != _sentinel) - _$AdvancedJsonFieldMap['lastName']!: lastName as String?, + _$AdvancedJsonFieldMap['lastName']!: + _$AdvancedJsonPerFieldToJson.lastName(lastName as String?), if (lastNameFieldValue != null) _$AdvancedJsonFieldMap['lastName']!: lastNameFieldValue, }; @@ -1355,15 +591,28 @@ class _$AdvancedJsonQuery _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$AdvancedJsonFieldMap['firstName']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: isEqualTo != null + ? _$AdvancedJsonPerFieldToJson.firstName(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$AdvancedJsonPerFieldToJson.firstName(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$AdvancedJsonPerFieldToJson.firstName(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$AdvancedJsonPerFieldToJson.firstName(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$AdvancedJsonPerFieldToJson.firstName(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$AdvancedJsonPerFieldToJson.firstName(isGreaterThanOrEqualTo) + : null, isNull: isNull, - whereIn: whereIn, - whereNotIn: whereNotIn, + whereIn: whereIn?.map((e) => _$AdvancedJsonPerFieldToJson.firstName(e)), + whereNotIn: + whereNotIn?.map((e) => _$AdvancedJsonPerFieldToJson.firstName(e)), ), $queryCursor: $queryCursor, ); @@ -1384,15 +633,28 @@ class _$AdvancedJsonQuery _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$AdvancedJsonFieldMap['lastName']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: isEqualTo != null + ? _$AdvancedJsonPerFieldToJson.lastName(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$AdvancedJsonPerFieldToJson.lastName(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$AdvancedJsonPerFieldToJson.lastName(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$AdvancedJsonPerFieldToJson.lastName(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$AdvancedJsonPerFieldToJson.lastName(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$AdvancedJsonPerFieldToJson.lastName(isGreaterThanOrEqualTo) + : null, isNull: isNull, - whereIn: whereIn, - whereNotIn: whereNotIn, + whereIn: whereIn?.map((e) => _$AdvancedJsonPerFieldToJson.lastName(e)), + whereNotIn: + whereNotIn?.map((e) => _$AdvancedJsonPerFieldToJson.lastName(e)), ), $queryCursor: $queryCursor, ); @@ -1899,11 +1161,13 @@ class _$_PrivateAdvancedJsonDocumentReference ); final json = { if (firstName != _sentinel) - _$PrivateAdvancedJsonFieldMap['firstName']!: firstName as String?, + _$PrivateAdvancedJsonFieldMap['firstName']!: + _$PrivateAdvancedJsonPerFieldToJson.firstName(firstName as String?), if (firstNameFieldValue != null) _$PrivateAdvancedJsonFieldMap['firstName']!: firstNameFieldValue, if (lastName != _sentinel) - _$PrivateAdvancedJsonFieldMap['lastName']!: lastName as String?, + _$PrivateAdvancedJsonFieldMap['lastName']!: + _$PrivateAdvancedJsonPerFieldToJson.lastName(lastName as String?), if (lastNameFieldValue != null) _$PrivateAdvancedJsonFieldMap['lastName']!: lastNameFieldValue, }; @@ -1928,11 +1192,13 @@ class _$_PrivateAdvancedJsonDocumentReference ); final json = { if (firstName != _sentinel) - _$PrivateAdvancedJsonFieldMap['firstName']!: firstName as String?, + _$PrivateAdvancedJsonFieldMap['firstName']!: + _$PrivateAdvancedJsonPerFieldToJson.firstName(firstName as String?), if (firstNameFieldValue != null) _$PrivateAdvancedJsonFieldMap['firstName']!: firstNameFieldValue, if (lastName != _sentinel) - _$PrivateAdvancedJsonFieldMap['lastName']!: lastName as String?, + _$PrivateAdvancedJsonFieldMap['lastName']!: + _$PrivateAdvancedJsonPerFieldToJson.lastName(lastName as String?), if (lastNameFieldValue != null) _$PrivateAdvancedJsonFieldMap['lastName']!: lastNameFieldValue, }; @@ -2294,15 +1560,30 @@ class _$_PrivateAdvancedJsonQuery extends QueryReference<_PrivateAdvancedJson, _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$PrivateAdvancedJsonFieldMap['firstName']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: isEqualTo != null + ? _$PrivateAdvancedJsonPerFieldToJson.firstName(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$PrivateAdvancedJsonPerFieldToJson.firstName(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$PrivateAdvancedJsonPerFieldToJson.firstName(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$PrivateAdvancedJsonPerFieldToJson.firstName(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$PrivateAdvancedJsonPerFieldToJson.firstName(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$PrivateAdvancedJsonPerFieldToJson + .firstName(isGreaterThanOrEqualTo) + : null, isNull: isNull, - whereIn: whereIn, - whereNotIn: whereNotIn, + whereIn: whereIn + ?.map((e) => _$PrivateAdvancedJsonPerFieldToJson.firstName(e)), + whereNotIn: whereNotIn + ?.map((e) => _$PrivateAdvancedJsonPerFieldToJson.firstName(e)), ), $queryCursor: $queryCursor, ); @@ -2323,15 +1604,30 @@ class _$_PrivateAdvancedJsonQuery extends QueryReference<_PrivateAdvancedJson, _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$PrivateAdvancedJsonFieldMap['lastName']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: isEqualTo != null + ? _$PrivateAdvancedJsonPerFieldToJson.lastName(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$PrivateAdvancedJsonPerFieldToJson.lastName(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$PrivateAdvancedJsonPerFieldToJson.lastName(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$PrivateAdvancedJsonPerFieldToJson.lastName(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$PrivateAdvancedJsonPerFieldToJson.lastName(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$PrivateAdvancedJsonPerFieldToJson + .lastName(isGreaterThanOrEqualTo) + : null, isNull: isNull, - whereIn: whereIn, - whereNotIn: whereNotIn, + whereIn: whereIn + ?.map((e) => _$PrivateAdvancedJsonPerFieldToJson.lastName(e)), + whereNotIn: whereNotIn + ?.map((e) => _$PrivateAdvancedJsonPerFieldToJson.lastName(e)), ), $queryCursor: $queryCursor, ); @@ -3256,6 +2552,9 @@ EmptyModel _$EmptyModelFromJson(Map json) => EmptyModel(); const _$EmptyModelFieldMap = {}; +// ignore: unused_element +abstract class _$EmptyModelPerFieldToJson {} + Map _$EmptyModelToJson(EmptyModel instance) => {}; @@ -3269,6 +2568,14 @@ const _$AdvancedJsonFieldMap = { 'lastName': 'LAST_NAME', }; +// ignore: unused_element +abstract class _$AdvancedJsonPerFieldToJson { + // ignore: unused_element + static Object? firstName(String? instance) => instance; + // ignore: unused_element + static Object? lastName(String? instance) => instance; +} + Map _$AdvancedJsonToJson(AdvancedJson instance) => { 'first_name': instance.firstName, @@ -3286,6 +2593,14 @@ const _$PrivateAdvancedJsonFieldMap = { 'lastName': 'LAST_NAME', }; +// ignore: unused_element +abstract class _$PrivateAdvancedJsonPerFieldToJson { + // ignore: unused_element + static Object? firstName(String? instance) => instance; + // ignore: unused_element + static Object? lastName(String? instance) => instance; +} + Map _$PrivateAdvancedJsonToJson( _PrivateAdvancedJson instance) => { diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/enums.dart b/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/enums.dart new file mode 100644 index 000000000000..f45aaa52199d --- /dev/null +++ b/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/enums.dart @@ -0,0 +1,39 @@ +// Copyright 2022, the Chromium project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'package:cloud_firestore/cloud_firestore.dart'; +import 'package:cloud_firestore_odm/cloud_firestore_odm.dart'; +import 'package:json_annotation/json_annotation.dart'; + +part 'enums.g.dart'; + +enum TestEnum { + one, + two, + three; +} + +@JsonSerializable() +class Enums { + Enums({ + required this.id, + this.enumValue = TestEnum.one, + this.nullableEnumValue, + this.enumList = const [], + this.nullableEnumList, + }); + + factory Enums.fromJson(Map json) => _$EnumsFromJson(json); + + Map toJson() => _$EnumsToJson(this); + + final String id; + final TestEnum enumValue; + final TestEnum? nullableEnumValue; + final List enumList; + final List? nullableEnumList; +} + +@Collection('firestore-example-app') +final enumsRef = EnumsCollectionReference(); diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/enums.g.dart b/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/enums.g.dart new file mode 100644 index 000000000000..37f4ba8d2fc0 --- /dev/null +++ b/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/enums.g.dart @@ -0,0 +1,1512 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +// ignore_for_file: type=lint + +part of 'enums.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, require_trailing_commas, prefer_single_quotes, prefer_double_quotes, use_super_parameters, duplicate_ignore + +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 EnumsCollectionReference + implements + EnumsQuery, + FirestoreCollectionReference { + factory EnumsCollectionReference([ + FirebaseFirestore? firestore, + ]) = _$EnumsCollectionReference; + + static Enums fromFirestore( + DocumentSnapshot> snapshot, + SnapshotOptions? options, + ) { + return Enums.fromJson(snapshot.data()!); + } + + static Map toFirestore( + Enums value, + SetOptions? options, + ) { + return value.toJson(); + } + + @override + CollectionReference get reference; + + @override + EnumsDocumentReference doc([String? id]); + + /// Add a new document to this collection with the specified data, + /// assigning it a document ID automatically. + Future add(Enums value); +} + +class _$EnumsCollectionReference extends _$EnumsQuery + implements EnumsCollectionReference { + factory _$EnumsCollectionReference([FirebaseFirestore? firestore]) { + firestore ??= FirebaseFirestore.instance; + + return _$EnumsCollectionReference._( + firestore.collection('firestore-example-app').withConverter( + fromFirestore: EnumsCollectionReference.fromFirestore, + toFirestore: EnumsCollectionReference.toFirestore, + ), + ); + } + + _$EnumsCollectionReference._( + CollectionReference reference, + ) : super(reference, $referenceWithoutCursor: reference); + + String get path => reference.path; + + @override + CollectionReference get reference => + super.reference as CollectionReference; + + @override + EnumsDocumentReference doc([String? id]) { + assert( + id == null || id.split('/').length == 1, + 'The document ID cannot be from a different collection', + ); + return EnumsDocumentReference( + reference.doc(id), + ); + } + + @override + Future add(Enums value) { + return reference.add(value).then((ref) => EnumsDocumentReference(ref)); + } + + @override + bool operator ==(Object other) { + return other is _$EnumsCollectionReference && + other.runtimeType == runtimeType && + other.reference == reference; + } + + @override + int get hashCode => Object.hash(runtimeType, reference); +} + +abstract class EnumsDocumentReference + extends FirestoreDocumentReference { + factory EnumsDocumentReference(DocumentReference reference) = + _$EnumsDocumentReference; + + DocumentReference get reference; + + /// A reference to the [EnumsCollectionReference] containing this document. + EnumsCollectionReference get parent { + return _$EnumsCollectionReference(reference.firestore); + } + + @override + Stream snapshots(); + + @override + Future get([GetOptions? options]); + + @override + Future delete(); + + /// Updates data on the document. Data will be merged with any existing + /// document data. + /// + /// If no document exists yet, the update will fail. + Future update({ + String id, + FieldValue idFieldValue, + TestEnum enumValue, + FieldValue enumValueFieldValue, + TestEnum? nullableEnumValue, + FieldValue nullableEnumValueFieldValue, + List enumList, + FieldValue enumListFieldValue, + List? nullableEnumList, + FieldValue nullableEnumListFieldValue, + }); + + /// Updates fields in the current document using the transaction API. + /// + /// The update will fail if applied to a document that does not exist. + void transactionUpdate( + Transaction transaction, { + String id, + FieldValue idFieldValue, + TestEnum enumValue, + FieldValue enumValueFieldValue, + TestEnum? nullableEnumValue, + FieldValue nullableEnumValueFieldValue, + List enumList, + FieldValue enumListFieldValue, + List? nullableEnumList, + FieldValue nullableEnumListFieldValue, + }); +} + +class _$EnumsDocumentReference + extends FirestoreDocumentReference + implements EnumsDocumentReference { + _$EnumsDocumentReference(this.reference); + + @override + final DocumentReference reference; + + /// A reference to the [EnumsCollectionReference] containing this document. + EnumsCollectionReference get parent { + return _$EnumsCollectionReference(reference.firestore); + } + + @override + Stream snapshots() { + return reference.snapshots().map(EnumsDocumentSnapshot._); + } + + @override + Future get([GetOptions? options]) { + return reference.get(options).then(EnumsDocumentSnapshot._); + } + + @override + Future transactionGet(Transaction transaction) { + return transaction.get(reference).then(EnumsDocumentSnapshot._); + } + + Future update({ + Object? id = _sentinel, + FieldValue? idFieldValue, + Object? enumValue = _sentinel, + FieldValue? enumValueFieldValue, + Object? nullableEnumValue = _sentinel, + FieldValue? nullableEnumValueFieldValue, + Object? enumList = _sentinel, + FieldValue? enumListFieldValue, + Object? nullableEnumList = _sentinel, + FieldValue? nullableEnumListFieldValue, + }) async { + assert( + id == _sentinel || idFieldValue == null, + "Cannot specify both id and idFieldValue", + ); + assert( + enumValue == _sentinel || enumValueFieldValue == null, + "Cannot specify both enumValue and enumValueFieldValue", + ); + assert( + nullableEnumValue == _sentinel || nullableEnumValueFieldValue == null, + "Cannot specify both nullableEnumValue and nullableEnumValueFieldValue", + ); + assert( + enumList == _sentinel || enumListFieldValue == null, + "Cannot specify both enumList and enumListFieldValue", + ); + assert( + nullableEnumList == _sentinel || nullableEnumListFieldValue == null, + "Cannot specify both nullableEnumList and nullableEnumListFieldValue", + ); + final json = { + if (id != _sentinel) + _$EnumsFieldMap['id']!: _$EnumsPerFieldToJson.id(id as String), + if (idFieldValue != null) _$EnumsFieldMap['id']!: idFieldValue, + if (enumValue != _sentinel) + _$EnumsFieldMap['enumValue']!: + _$EnumsPerFieldToJson.enumValue(enumValue as TestEnum), + if (enumValueFieldValue != null) + _$EnumsFieldMap['enumValue']!: enumValueFieldValue, + if (nullableEnumValue != _sentinel) + _$EnumsFieldMap['nullableEnumValue']!: _$EnumsPerFieldToJson + .nullableEnumValue(nullableEnumValue as TestEnum?), + if (nullableEnumValueFieldValue != null) + _$EnumsFieldMap['nullableEnumValue']!: nullableEnumValueFieldValue, + if (enumList != _sentinel) + _$EnumsFieldMap['enumList']!: + _$EnumsPerFieldToJson.enumList(enumList as List), + if (enumListFieldValue != null) + _$EnumsFieldMap['enumList']!: enumListFieldValue, + if (nullableEnumList != _sentinel) + _$EnumsFieldMap['nullableEnumList']!: _$EnumsPerFieldToJson + .nullableEnumList(nullableEnumList as List?), + if (nullableEnumListFieldValue != null) + _$EnumsFieldMap['nullableEnumList']!: nullableEnumListFieldValue, + }; + + return reference.update(json); + } + + void transactionUpdate( + Transaction transaction, { + Object? id = _sentinel, + FieldValue? idFieldValue, + Object? enumValue = _sentinel, + FieldValue? enumValueFieldValue, + Object? nullableEnumValue = _sentinel, + FieldValue? nullableEnumValueFieldValue, + Object? enumList = _sentinel, + FieldValue? enumListFieldValue, + Object? nullableEnumList = _sentinel, + FieldValue? nullableEnumListFieldValue, + }) { + assert( + id == _sentinel || idFieldValue == null, + "Cannot specify both id and idFieldValue", + ); + assert( + enumValue == _sentinel || enumValueFieldValue == null, + "Cannot specify both enumValue and enumValueFieldValue", + ); + assert( + nullableEnumValue == _sentinel || nullableEnumValueFieldValue == null, + "Cannot specify both nullableEnumValue and nullableEnumValueFieldValue", + ); + assert( + enumList == _sentinel || enumListFieldValue == null, + "Cannot specify both enumList and enumListFieldValue", + ); + assert( + nullableEnumList == _sentinel || nullableEnumListFieldValue == null, + "Cannot specify both nullableEnumList and nullableEnumListFieldValue", + ); + final json = { + if (id != _sentinel) + _$EnumsFieldMap['id']!: _$EnumsPerFieldToJson.id(id as String), + if (idFieldValue != null) _$EnumsFieldMap['id']!: idFieldValue, + if (enumValue != _sentinel) + _$EnumsFieldMap['enumValue']!: + _$EnumsPerFieldToJson.enumValue(enumValue as TestEnum), + if (enumValueFieldValue != null) + _$EnumsFieldMap['enumValue']!: enumValueFieldValue, + if (nullableEnumValue != _sentinel) + _$EnumsFieldMap['nullableEnumValue']!: _$EnumsPerFieldToJson + .nullableEnumValue(nullableEnumValue as TestEnum?), + if (nullableEnumValueFieldValue != null) + _$EnumsFieldMap['nullableEnumValue']!: nullableEnumValueFieldValue, + if (enumList != _sentinel) + _$EnumsFieldMap['enumList']!: + _$EnumsPerFieldToJson.enumList(enumList as List), + if (enumListFieldValue != null) + _$EnumsFieldMap['enumList']!: enumListFieldValue, + if (nullableEnumList != _sentinel) + _$EnumsFieldMap['nullableEnumList']!: _$EnumsPerFieldToJson + .nullableEnumList(nullableEnumList as List?), + if (nullableEnumListFieldValue != null) + _$EnumsFieldMap['nullableEnumList']!: nullableEnumListFieldValue, + }; + + transaction.update(reference, json); + } + + @override + bool operator ==(Object other) { + return other is EnumsDocumentReference && + other.runtimeType == runtimeType && + other.parent == parent && + other.id == id; + } + + @override + int get hashCode => Object.hash(runtimeType, parent, id); +} + +abstract class EnumsQuery implements QueryReference { + @override + EnumsQuery limit(int limit); + + @override + EnumsQuery limitToLast(int limit); + + /// Perform an order query based on a [FieldPath]. + /// + /// This method is considered unsafe as it does check that the field path + /// maps to a valid property or that parameters such as [isEqualTo] receive + /// a value of the correct type. + /// + /// If possible, instead use the more explicit variant of order queries: + /// + /// **AVOID**: + /// ```dart + /// collection.orderByFieldPath( + /// FieldPath.fromString('title'), + /// startAt: 'title', + /// ); + /// ``` + /// + /// **PREFER**: + /// ```dart + /// collection.orderByTitle(startAt: 'title'); + /// ``` + EnumsQuery orderByFieldPath( + FieldPath fieldPath, { + bool descending = false, + Object? startAt, + Object? startAfter, + Object? endAt, + Object? endBefore, + EnumsDocumentSnapshot? startAtDocument, + EnumsDocumentSnapshot? endAtDocument, + EnumsDocumentSnapshot? endBeforeDocument, + EnumsDocumentSnapshot? startAfterDocument, + }); + + /// Perform a where query based on a [FieldPath]. + /// + /// This method is considered unsafe as it does check that the field path + /// maps to a valid property or that parameters such as [isEqualTo] receive + /// a value of the correct type. + /// + /// If possible, instead use the more explicit variant of where queries: + /// + /// **AVOID**: + /// ```dart + /// collection.whereFieldPath(FieldPath.fromString('title'), isEqualTo: 'title'); + /// ``` + /// + /// **PREFER**: + /// ```dart + /// collection.whereTitle(isEqualTo: 'title'); + /// ``` + EnumsQuery whereFieldPath( + FieldPath fieldPath, { + Object? isEqualTo, + Object? isNotEqualTo, + Object? isLessThan, + Object? isLessThanOrEqualTo, + Object? isGreaterThan, + Object? isGreaterThanOrEqualTo, + Object? arrayContains, + List? arrayContainsAny, + List? whereIn, + List? whereNotIn, + bool? isNull, + }); + + EnumsQuery whereDocumentId({ + String? isEqualTo, + String? isNotEqualTo, + String? isLessThan, + String? isLessThanOrEqualTo, + String? isGreaterThan, + String? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }); + EnumsQuery whereId({ + String? isEqualTo, + String? isNotEqualTo, + String? isLessThan, + String? isLessThanOrEqualTo, + String? isGreaterThan, + String? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }); + EnumsQuery whereEnumValue({ + TestEnum? isEqualTo, + TestEnum? isNotEqualTo, + TestEnum? isLessThan, + TestEnum? isLessThanOrEqualTo, + TestEnum? isGreaterThan, + TestEnum? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }); + EnumsQuery whereNullableEnumValue({ + TestEnum? isEqualTo, + TestEnum? isNotEqualTo, + TestEnum? isLessThan, + TestEnum? isLessThanOrEqualTo, + TestEnum? isGreaterThan, + TestEnum? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }); + EnumsQuery whereEnumList({ + List? isEqualTo, + List? isNotEqualTo, + List? isLessThan, + List? isLessThanOrEqualTo, + List? isGreaterThan, + List? isGreaterThanOrEqualTo, + bool? isNull, + TestEnum? arrayContains, + List? arrayContainsAny, + }); + EnumsQuery whereNullableEnumList({ + List? isEqualTo, + List? isNotEqualTo, + List? isLessThan, + List? isLessThanOrEqualTo, + List? isGreaterThan, + List? isGreaterThanOrEqualTo, + bool? isNull, + TestEnum? arrayContains, + List? arrayContainsAny, + }); + + EnumsQuery orderByDocumentId({ + bool descending = false, + String startAt, + String startAfter, + String endAt, + String endBefore, + EnumsDocumentSnapshot? startAtDocument, + EnumsDocumentSnapshot? endAtDocument, + EnumsDocumentSnapshot? endBeforeDocument, + EnumsDocumentSnapshot? startAfterDocument, + }); + + EnumsQuery orderById({ + bool descending = false, + String startAt, + String startAfter, + String endAt, + String endBefore, + EnumsDocumentSnapshot? startAtDocument, + EnumsDocumentSnapshot? endAtDocument, + EnumsDocumentSnapshot? endBeforeDocument, + EnumsDocumentSnapshot? startAfterDocument, + }); + + EnumsQuery orderByEnumValue({ + bool descending = false, + TestEnum startAt, + TestEnum startAfter, + TestEnum endAt, + TestEnum endBefore, + EnumsDocumentSnapshot? startAtDocument, + EnumsDocumentSnapshot? endAtDocument, + EnumsDocumentSnapshot? endBeforeDocument, + EnumsDocumentSnapshot? startAfterDocument, + }); + + EnumsQuery orderByNullableEnumValue({ + bool descending = false, + TestEnum? startAt, + TestEnum? startAfter, + TestEnum? endAt, + TestEnum? endBefore, + EnumsDocumentSnapshot? startAtDocument, + EnumsDocumentSnapshot? endAtDocument, + EnumsDocumentSnapshot? endBeforeDocument, + EnumsDocumentSnapshot? startAfterDocument, + }); + + EnumsQuery orderByEnumList({ + bool descending = false, + List startAt, + List startAfter, + List endAt, + List endBefore, + EnumsDocumentSnapshot? startAtDocument, + EnumsDocumentSnapshot? endAtDocument, + EnumsDocumentSnapshot? endBeforeDocument, + EnumsDocumentSnapshot? startAfterDocument, + }); + + EnumsQuery orderByNullableEnumList({ + bool descending = false, + List? startAt, + List? startAfter, + List? endAt, + List? endBefore, + EnumsDocumentSnapshot? startAtDocument, + EnumsDocumentSnapshot? endAtDocument, + EnumsDocumentSnapshot? endBeforeDocument, + EnumsDocumentSnapshot? startAfterDocument, + }); +} + +class _$EnumsQuery extends QueryReference + implements EnumsQuery { + _$EnumsQuery( + this._collection, { + required Query $referenceWithoutCursor, + $QueryCursor $queryCursor = const $QueryCursor(), + }) : super( + $referenceWithoutCursor: $referenceWithoutCursor, + $queryCursor: $queryCursor, + ); + + final CollectionReference _collection; + + @override + Stream snapshots([SnapshotOptions? options]) { + return reference.snapshots().map(EnumsQuerySnapshot._fromQuerySnapshot); + } + + @override + Future get([GetOptions? options]) { + return reference.get(options).then(EnumsQuerySnapshot._fromQuerySnapshot); + } + + @override + EnumsQuery limit(int limit) { + return _$EnumsQuery( + _collection, + $referenceWithoutCursor: $referenceWithoutCursor.limit(limit), + $queryCursor: $queryCursor, + ); + } + + @override + EnumsQuery limitToLast(int limit) { + return _$EnumsQuery( + _collection, + $referenceWithoutCursor: $referenceWithoutCursor.limitToLast(limit), + $queryCursor: $queryCursor, + ); + } + + EnumsQuery orderByFieldPath( + FieldPath fieldPath, { + bool descending = false, + Object? startAt = _sentinel, + Object? startAfter = _sentinel, + Object? endAt = _sentinel, + Object? endBefore = _sentinel, + EnumsDocumentSnapshot? startAtDocument, + EnumsDocumentSnapshot? endAtDocument, + EnumsDocumentSnapshot? endBeforeDocument, + EnumsDocumentSnapshot? startAfterDocument, + }) { + final query = + $referenceWithoutCursor.orderBy(fieldPath, descending: descending); + var queryCursor = $queryCursor; + + if (startAtDocument != null) { + queryCursor = queryCursor.copyWith( + startAt: const [], + startAtDocumentSnapshot: startAtDocument.snapshot, + ); + } + if (startAfterDocument != null) { + queryCursor = queryCursor.copyWith( + startAfter: const [], + startAfterDocumentSnapshot: startAfterDocument.snapshot, + ); + } + if (endAtDocument != null) { + queryCursor = queryCursor.copyWith( + endAt: const [], + endAtDocumentSnapshot: endAtDocument.snapshot, + ); + } + if (endBeforeDocument != null) { + queryCursor = queryCursor.copyWith( + endBefore: const [], + endBeforeDocumentSnapshot: endBeforeDocument.snapshot, + ); + } + + if (startAt != _sentinel) { + queryCursor = queryCursor.copyWith( + startAt: [...queryCursor.startAt, startAt], + startAtDocumentSnapshot: null, + ); + } + if (startAfter != _sentinel) { + queryCursor = queryCursor.copyWith( + startAfter: [...queryCursor.startAfter, startAfter], + startAfterDocumentSnapshot: null, + ); + } + if (endAt != _sentinel) { + queryCursor = queryCursor.copyWith( + endAt: [...queryCursor.endAt, endAt], + endAtDocumentSnapshot: null, + ); + } + if (endBefore != _sentinel) { + queryCursor = queryCursor.copyWith( + endBefore: [...queryCursor.endBefore, endBefore], + endBeforeDocumentSnapshot: null, + ); + } + return _$EnumsQuery( + _collection, + $referenceWithoutCursor: query, + $queryCursor: queryCursor, + ); + } + + EnumsQuery whereFieldPath( + FieldPath fieldPath, { + Object? isEqualTo, + Object? isNotEqualTo, + Object? isLessThan, + Object? isLessThanOrEqualTo, + Object? isGreaterThan, + Object? isGreaterThanOrEqualTo, + Object? arrayContains, + List? arrayContainsAny, + List? whereIn, + List? whereNotIn, + bool? isNull, + }) { + return _$EnumsQuery( + _collection, + $referenceWithoutCursor: $referenceWithoutCursor.where( + fieldPath, + isEqualTo: isEqualTo, + isNotEqualTo: isNotEqualTo, + isLessThan: isLessThan, + isLessThanOrEqualTo: isLessThanOrEqualTo, + isGreaterThan: isGreaterThan, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + arrayContains: arrayContains, + arrayContainsAny: arrayContainsAny, + whereIn: whereIn, + whereNotIn: whereNotIn, + isNull: isNull, + ), + $queryCursor: $queryCursor, + ); + } + + EnumsQuery whereDocumentId({ + String? isEqualTo, + String? isNotEqualTo, + String? isLessThan, + String? isLessThanOrEqualTo, + String? isGreaterThan, + String? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }) { + return _$EnumsQuery( + _collection, + $referenceWithoutCursor: $referenceWithoutCursor.where( + FieldPath.documentId, + isEqualTo: isEqualTo, + isNotEqualTo: isNotEqualTo, + isLessThan: isLessThan, + isLessThanOrEqualTo: isLessThanOrEqualTo, + isGreaterThan: isGreaterThan, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isNull: isNull, + whereIn: whereIn, + whereNotIn: whereNotIn, + ), + $queryCursor: $queryCursor, + ); + } + + EnumsQuery whereId({ + String? isEqualTo, + String? isNotEqualTo, + String? isLessThan, + String? isLessThanOrEqualTo, + String? isGreaterThan, + String? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }) { + return _$EnumsQuery( + _collection, + $referenceWithoutCursor: $referenceWithoutCursor.where( + _$EnumsFieldMap['id']!, + isEqualTo: + isEqualTo != null ? _$EnumsPerFieldToJson.id(isEqualTo) : null, + isNotEqualTo: isNotEqualTo != null + ? _$EnumsPerFieldToJson.id(isNotEqualTo) + : null, + isLessThan: + isLessThan != null ? _$EnumsPerFieldToJson.id(isLessThan) : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$EnumsPerFieldToJson.id(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$EnumsPerFieldToJson.id(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$EnumsPerFieldToJson.id(isGreaterThanOrEqualTo) + : null, + isNull: isNull, + whereIn: whereIn?.map((e) => _$EnumsPerFieldToJson.id(e)), + whereNotIn: whereNotIn?.map((e) => _$EnumsPerFieldToJson.id(e)), + ), + $queryCursor: $queryCursor, + ); + } + + EnumsQuery whereEnumValue({ + TestEnum? isEqualTo, + TestEnum? isNotEqualTo, + TestEnum? isLessThan, + TestEnum? isLessThanOrEqualTo, + TestEnum? isGreaterThan, + TestEnum? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }) { + return _$EnumsQuery( + _collection, + $referenceWithoutCursor: $referenceWithoutCursor.where( + _$EnumsFieldMap['enumValue']!, + isEqualTo: isEqualTo != null + ? _$EnumsPerFieldToJson.enumValue(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$EnumsPerFieldToJson.enumValue(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$EnumsPerFieldToJson.enumValue(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$EnumsPerFieldToJson.enumValue(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$EnumsPerFieldToJson.enumValue(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$EnumsPerFieldToJson.enumValue(isGreaterThanOrEqualTo) + : null, + isNull: isNull, + whereIn: whereIn?.map((e) => _$EnumsPerFieldToJson.enumValue(e)), + whereNotIn: whereNotIn?.map((e) => _$EnumsPerFieldToJson.enumValue(e)), + ), + $queryCursor: $queryCursor, + ); + } + + EnumsQuery whereNullableEnumValue({ + TestEnum? isEqualTo, + TestEnum? isNotEqualTo, + TestEnum? isLessThan, + TestEnum? isLessThanOrEqualTo, + TestEnum? isGreaterThan, + TestEnum? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }) { + return _$EnumsQuery( + _collection, + $referenceWithoutCursor: $referenceWithoutCursor.where( + _$EnumsFieldMap['nullableEnumValue']!, + isEqualTo: isEqualTo != null + ? _$EnumsPerFieldToJson.nullableEnumValue(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$EnumsPerFieldToJson.nullableEnumValue(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$EnumsPerFieldToJson.nullableEnumValue(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$EnumsPerFieldToJson.nullableEnumValue(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$EnumsPerFieldToJson.nullableEnumValue(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$EnumsPerFieldToJson.nullableEnumValue(isGreaterThanOrEqualTo) + : null, + isNull: isNull, + whereIn: + whereIn?.map((e) => _$EnumsPerFieldToJson.nullableEnumValue(e)), + whereNotIn: + whereNotIn?.map((e) => _$EnumsPerFieldToJson.nullableEnumValue(e)), + ), + $queryCursor: $queryCursor, + ); + } + + EnumsQuery whereEnumList({ + List? isEqualTo, + List? isNotEqualTo, + List? isLessThan, + List? isLessThanOrEqualTo, + List? isGreaterThan, + List? isGreaterThanOrEqualTo, + bool? isNull, + TestEnum? arrayContains, + List? arrayContainsAny, + }) { + return _$EnumsQuery( + _collection, + $referenceWithoutCursor: $referenceWithoutCursor.where( + _$EnumsFieldMap['enumList']!, + isEqualTo: isEqualTo != null + ? _$EnumsPerFieldToJson.enumList(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$EnumsPerFieldToJson.enumList(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$EnumsPerFieldToJson.enumList(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$EnumsPerFieldToJson.enumList(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$EnumsPerFieldToJson.enumList(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$EnumsPerFieldToJson.enumList(isGreaterThanOrEqualTo) + : null, + isNull: isNull, + arrayContains: arrayContains != null + ? (_$EnumsPerFieldToJson.enumList([arrayContains]) as List?)!.single + : null, + arrayContainsAny: arrayContainsAny != null + ? _$EnumsPerFieldToJson.enumList(arrayContainsAny) + as Iterable? + : null, + ), + $queryCursor: $queryCursor, + ); + } + + EnumsQuery whereNullableEnumList({ + List? isEqualTo, + List? isNotEqualTo, + List? isLessThan, + List? isLessThanOrEqualTo, + List? isGreaterThan, + List? isGreaterThanOrEqualTo, + bool? isNull, + TestEnum? arrayContains, + List? arrayContainsAny, + }) { + return _$EnumsQuery( + _collection, + $referenceWithoutCursor: $referenceWithoutCursor.where( + _$EnumsFieldMap['nullableEnumList']!, + isEqualTo: isEqualTo != null + ? _$EnumsPerFieldToJson.nullableEnumList(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$EnumsPerFieldToJson.nullableEnumList(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$EnumsPerFieldToJson.nullableEnumList(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$EnumsPerFieldToJson.nullableEnumList(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$EnumsPerFieldToJson.nullableEnumList(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$EnumsPerFieldToJson.nullableEnumList(isGreaterThanOrEqualTo) + : null, + isNull: isNull, + arrayContains: arrayContains != null + ? (_$EnumsPerFieldToJson.nullableEnumList([arrayContains]) + as List?)! + .single + : null, + arrayContainsAny: arrayContainsAny != null + ? _$EnumsPerFieldToJson.nullableEnumList(arrayContainsAny) + as Iterable? + : null, + ), + $queryCursor: $queryCursor, + ); + } + + EnumsQuery orderByDocumentId({ + bool descending = false, + Object? startAt = _sentinel, + Object? startAfter = _sentinel, + Object? endAt = _sentinel, + Object? endBefore = _sentinel, + EnumsDocumentSnapshot? startAtDocument, + EnumsDocumentSnapshot? endAtDocument, + EnumsDocumentSnapshot? endBeforeDocument, + EnumsDocumentSnapshot? startAfterDocument, + }) { + final query = $referenceWithoutCursor.orderBy(FieldPath.documentId, + descending: descending); + var queryCursor = $queryCursor; + + if (startAtDocument != null) { + queryCursor = queryCursor.copyWith( + startAt: const [], + startAtDocumentSnapshot: startAtDocument.snapshot, + ); + } + if (startAfterDocument != null) { + queryCursor = queryCursor.copyWith( + startAfter: const [], + startAfterDocumentSnapshot: startAfterDocument.snapshot, + ); + } + if (endAtDocument != null) { + queryCursor = queryCursor.copyWith( + endAt: const [], + endAtDocumentSnapshot: endAtDocument.snapshot, + ); + } + if (endBeforeDocument != null) { + queryCursor = queryCursor.copyWith( + endBefore: const [], + endBeforeDocumentSnapshot: endBeforeDocument.snapshot, + ); + } + + if (startAt != _sentinel) { + queryCursor = queryCursor.copyWith( + startAt: [...queryCursor.startAt, startAt], + startAtDocumentSnapshot: null, + ); + } + if (startAfter != _sentinel) { + queryCursor = queryCursor.copyWith( + startAfter: [...queryCursor.startAfter, startAfter], + startAfterDocumentSnapshot: null, + ); + } + if (endAt != _sentinel) { + queryCursor = queryCursor.copyWith( + endAt: [...queryCursor.endAt, endAt], + endAtDocumentSnapshot: null, + ); + } + if (endBefore != _sentinel) { + queryCursor = queryCursor.copyWith( + endBefore: [...queryCursor.endBefore, endBefore], + endBeforeDocumentSnapshot: null, + ); + } + + return _$EnumsQuery( + _collection, + $referenceWithoutCursor: query, + $queryCursor: queryCursor, + ); + } + + EnumsQuery orderById({ + bool descending = false, + Object? startAt = _sentinel, + Object? startAfter = _sentinel, + Object? endAt = _sentinel, + Object? endBefore = _sentinel, + EnumsDocumentSnapshot? startAtDocument, + EnumsDocumentSnapshot? endAtDocument, + EnumsDocumentSnapshot? endBeforeDocument, + EnumsDocumentSnapshot? startAfterDocument, + }) { + final query = $referenceWithoutCursor.orderBy(_$EnumsFieldMap['id']!, + descending: descending); + var queryCursor = $queryCursor; + + if (startAtDocument != null) { + queryCursor = queryCursor.copyWith( + startAt: const [], + startAtDocumentSnapshot: startAtDocument.snapshot, + ); + } + if (startAfterDocument != null) { + queryCursor = queryCursor.copyWith( + startAfter: const [], + startAfterDocumentSnapshot: startAfterDocument.snapshot, + ); + } + if (endAtDocument != null) { + queryCursor = queryCursor.copyWith( + endAt: const [], + endAtDocumentSnapshot: endAtDocument.snapshot, + ); + } + if (endBeforeDocument != null) { + queryCursor = queryCursor.copyWith( + endBefore: const [], + endBeforeDocumentSnapshot: endBeforeDocument.snapshot, + ); + } + + if (startAt != _sentinel) { + queryCursor = queryCursor.copyWith( + startAt: [...queryCursor.startAt, startAt], + startAtDocumentSnapshot: null, + ); + } + if (startAfter != _sentinel) { + queryCursor = queryCursor.copyWith( + startAfter: [...queryCursor.startAfter, startAfter], + startAfterDocumentSnapshot: null, + ); + } + if (endAt != _sentinel) { + queryCursor = queryCursor.copyWith( + endAt: [...queryCursor.endAt, endAt], + endAtDocumentSnapshot: null, + ); + } + if (endBefore != _sentinel) { + queryCursor = queryCursor.copyWith( + endBefore: [...queryCursor.endBefore, endBefore], + endBeforeDocumentSnapshot: null, + ); + } + + return _$EnumsQuery( + _collection, + $referenceWithoutCursor: query, + $queryCursor: queryCursor, + ); + } + + EnumsQuery orderByEnumValue({ + bool descending = false, + Object? startAt = _sentinel, + Object? startAfter = _sentinel, + Object? endAt = _sentinel, + Object? endBefore = _sentinel, + EnumsDocumentSnapshot? startAtDocument, + EnumsDocumentSnapshot? endAtDocument, + EnumsDocumentSnapshot? endBeforeDocument, + EnumsDocumentSnapshot? startAfterDocument, + }) { + final query = $referenceWithoutCursor.orderBy(_$EnumsFieldMap['enumValue']!, + descending: descending); + var queryCursor = $queryCursor; + + if (startAtDocument != null) { + queryCursor = queryCursor.copyWith( + startAt: const [], + startAtDocumentSnapshot: startAtDocument.snapshot, + ); + } + if (startAfterDocument != null) { + queryCursor = queryCursor.copyWith( + startAfter: const [], + startAfterDocumentSnapshot: startAfterDocument.snapshot, + ); + } + if (endAtDocument != null) { + queryCursor = queryCursor.copyWith( + endAt: const [], + endAtDocumentSnapshot: endAtDocument.snapshot, + ); + } + if (endBeforeDocument != null) { + queryCursor = queryCursor.copyWith( + endBefore: const [], + endBeforeDocumentSnapshot: endBeforeDocument.snapshot, + ); + } + + if (startAt != _sentinel) { + queryCursor = queryCursor.copyWith( + startAt: [...queryCursor.startAt, startAt], + startAtDocumentSnapshot: null, + ); + } + if (startAfter != _sentinel) { + queryCursor = queryCursor.copyWith( + startAfter: [...queryCursor.startAfter, startAfter], + startAfterDocumentSnapshot: null, + ); + } + if (endAt != _sentinel) { + queryCursor = queryCursor.copyWith( + endAt: [...queryCursor.endAt, endAt], + endAtDocumentSnapshot: null, + ); + } + if (endBefore != _sentinel) { + queryCursor = queryCursor.copyWith( + endBefore: [...queryCursor.endBefore, endBefore], + endBeforeDocumentSnapshot: null, + ); + } + + return _$EnumsQuery( + _collection, + $referenceWithoutCursor: query, + $queryCursor: queryCursor, + ); + } + + EnumsQuery orderByNullableEnumValue({ + bool descending = false, + Object? startAt = _sentinel, + Object? startAfter = _sentinel, + Object? endAt = _sentinel, + Object? endBefore = _sentinel, + EnumsDocumentSnapshot? startAtDocument, + EnumsDocumentSnapshot? endAtDocument, + EnumsDocumentSnapshot? endBeforeDocument, + EnumsDocumentSnapshot? startAfterDocument, + }) { + final query = $referenceWithoutCursor + .orderBy(_$EnumsFieldMap['nullableEnumValue']!, descending: descending); + var queryCursor = $queryCursor; + + if (startAtDocument != null) { + queryCursor = queryCursor.copyWith( + startAt: const [], + startAtDocumentSnapshot: startAtDocument.snapshot, + ); + } + if (startAfterDocument != null) { + queryCursor = queryCursor.copyWith( + startAfter: const [], + startAfterDocumentSnapshot: startAfterDocument.snapshot, + ); + } + if (endAtDocument != null) { + queryCursor = queryCursor.copyWith( + endAt: const [], + endAtDocumentSnapshot: endAtDocument.snapshot, + ); + } + if (endBeforeDocument != null) { + queryCursor = queryCursor.copyWith( + endBefore: const [], + endBeforeDocumentSnapshot: endBeforeDocument.snapshot, + ); + } + + if (startAt != _sentinel) { + queryCursor = queryCursor.copyWith( + startAt: [...queryCursor.startAt, startAt], + startAtDocumentSnapshot: null, + ); + } + if (startAfter != _sentinel) { + queryCursor = queryCursor.copyWith( + startAfter: [...queryCursor.startAfter, startAfter], + startAfterDocumentSnapshot: null, + ); + } + if (endAt != _sentinel) { + queryCursor = queryCursor.copyWith( + endAt: [...queryCursor.endAt, endAt], + endAtDocumentSnapshot: null, + ); + } + if (endBefore != _sentinel) { + queryCursor = queryCursor.copyWith( + endBefore: [...queryCursor.endBefore, endBefore], + endBeforeDocumentSnapshot: null, + ); + } + + return _$EnumsQuery( + _collection, + $referenceWithoutCursor: query, + $queryCursor: queryCursor, + ); + } + + EnumsQuery orderByEnumList({ + bool descending = false, + Object? startAt = _sentinel, + Object? startAfter = _sentinel, + Object? endAt = _sentinel, + Object? endBefore = _sentinel, + EnumsDocumentSnapshot? startAtDocument, + EnumsDocumentSnapshot? endAtDocument, + EnumsDocumentSnapshot? endBeforeDocument, + EnumsDocumentSnapshot? startAfterDocument, + }) { + final query = $referenceWithoutCursor.orderBy(_$EnumsFieldMap['enumList']!, + descending: descending); + var queryCursor = $queryCursor; + + if (startAtDocument != null) { + queryCursor = queryCursor.copyWith( + startAt: const [], + startAtDocumentSnapshot: startAtDocument.snapshot, + ); + } + if (startAfterDocument != null) { + queryCursor = queryCursor.copyWith( + startAfter: const [], + startAfterDocumentSnapshot: startAfterDocument.snapshot, + ); + } + if (endAtDocument != null) { + queryCursor = queryCursor.copyWith( + endAt: const [], + endAtDocumentSnapshot: endAtDocument.snapshot, + ); + } + if (endBeforeDocument != null) { + queryCursor = queryCursor.copyWith( + endBefore: const [], + endBeforeDocumentSnapshot: endBeforeDocument.snapshot, + ); + } + + if (startAt != _sentinel) { + queryCursor = queryCursor.copyWith( + startAt: [...queryCursor.startAt, startAt], + startAtDocumentSnapshot: null, + ); + } + if (startAfter != _sentinel) { + queryCursor = queryCursor.copyWith( + startAfter: [...queryCursor.startAfter, startAfter], + startAfterDocumentSnapshot: null, + ); + } + if (endAt != _sentinel) { + queryCursor = queryCursor.copyWith( + endAt: [...queryCursor.endAt, endAt], + endAtDocumentSnapshot: null, + ); + } + if (endBefore != _sentinel) { + queryCursor = queryCursor.copyWith( + endBefore: [...queryCursor.endBefore, endBefore], + endBeforeDocumentSnapshot: null, + ); + } + + return _$EnumsQuery( + _collection, + $referenceWithoutCursor: query, + $queryCursor: queryCursor, + ); + } + + EnumsQuery orderByNullableEnumList({ + bool descending = false, + Object? startAt = _sentinel, + Object? startAfter = _sentinel, + Object? endAt = _sentinel, + Object? endBefore = _sentinel, + EnumsDocumentSnapshot? startAtDocument, + EnumsDocumentSnapshot? endAtDocument, + EnumsDocumentSnapshot? endBeforeDocument, + EnumsDocumentSnapshot? startAfterDocument, + }) { + final query = $referenceWithoutCursor + .orderBy(_$EnumsFieldMap['nullableEnumList']!, descending: descending); + var queryCursor = $queryCursor; + + if (startAtDocument != null) { + queryCursor = queryCursor.copyWith( + startAt: const [], + startAtDocumentSnapshot: startAtDocument.snapshot, + ); + } + if (startAfterDocument != null) { + queryCursor = queryCursor.copyWith( + startAfter: const [], + startAfterDocumentSnapshot: startAfterDocument.snapshot, + ); + } + if (endAtDocument != null) { + queryCursor = queryCursor.copyWith( + endAt: const [], + endAtDocumentSnapshot: endAtDocument.snapshot, + ); + } + if (endBeforeDocument != null) { + queryCursor = queryCursor.copyWith( + endBefore: const [], + endBeforeDocumentSnapshot: endBeforeDocument.snapshot, + ); + } + + if (startAt != _sentinel) { + queryCursor = queryCursor.copyWith( + startAt: [...queryCursor.startAt, startAt], + startAtDocumentSnapshot: null, + ); + } + if (startAfter != _sentinel) { + queryCursor = queryCursor.copyWith( + startAfter: [...queryCursor.startAfter, startAfter], + startAfterDocumentSnapshot: null, + ); + } + if (endAt != _sentinel) { + queryCursor = queryCursor.copyWith( + endAt: [...queryCursor.endAt, endAt], + endAtDocumentSnapshot: null, + ); + } + if (endBefore != _sentinel) { + queryCursor = queryCursor.copyWith( + endBefore: [...queryCursor.endBefore, endBefore], + endBeforeDocumentSnapshot: null, + ); + } + + return _$EnumsQuery( + _collection, + $referenceWithoutCursor: query, + $queryCursor: queryCursor, + ); + } + + @override + bool operator ==(Object other) { + return other is _$EnumsQuery && + other.runtimeType == runtimeType && + other.reference == reference; + } + + @override + int get hashCode => Object.hash(runtimeType, reference); +} + +class EnumsDocumentSnapshot extends FirestoreDocumentSnapshot { + EnumsDocumentSnapshot._(this.snapshot) : data = snapshot.data(); + + @override + final DocumentSnapshot snapshot; + + @override + EnumsDocumentReference get reference { + return EnumsDocumentReference( + snapshot.reference, + ); + } + + @override + final Enums? data; +} + +class EnumsQuerySnapshot + extends FirestoreQuerySnapshot { + EnumsQuerySnapshot._( + this.snapshot, + this.docs, + this.docChanges, + ); + + factory EnumsQuerySnapshot._fromQuerySnapshot( + QuerySnapshot snapshot, + ) { + final docs = snapshot.docs.map(EnumsQueryDocumentSnapshot._).toList(); + + final docChanges = snapshot.docChanges.map((change) { + return _decodeDocumentChange( + change, + EnumsDocumentSnapshot._, + ); + }).toList(); + + return EnumsQuerySnapshot._( + snapshot, + docs, + docChanges, + ); + } + + static FirestoreDocumentChange + _decodeDocumentChange( + DocumentChange docChange, + EnumsDocumentSnapshot Function(DocumentSnapshot doc) decodeDoc, + ) { + return FirestoreDocumentChange( + type: docChange.type, + oldIndex: docChange.oldIndex, + newIndex: docChange.newIndex, + doc: decodeDoc(docChange.doc), + ); + } + + final QuerySnapshot snapshot; + + @override + final List docs; + + @override + final List> docChanges; +} + +class EnumsQueryDocumentSnapshot extends FirestoreQueryDocumentSnapshot + implements EnumsDocumentSnapshot { + EnumsQueryDocumentSnapshot._(this.snapshot) : data = snapshot.data(); + + @override + final QueryDocumentSnapshot snapshot; + + @override + final Enums data; + + @override + EnumsDocumentReference get reference { + return EnumsDocumentReference(snapshot.reference); + } +} + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +Enums _$EnumsFromJson(Map json) => Enums( + id: json['id'] as String, + enumValue: $enumDecodeNullable(_$TestEnumEnumMap, json['enumValue']) ?? + TestEnum.one, + nullableEnumValue: + $enumDecodeNullable(_$TestEnumEnumMap, json['nullableEnumValue']), + enumList: (json['enumList'] as List?) + ?.map((e) => $enumDecode(_$TestEnumEnumMap, e)) + .toList() ?? + const [], + nullableEnumList: (json['nullableEnumList'] as List?) + ?.map((e) => $enumDecode(_$TestEnumEnumMap, e)) + .toList(), + ); + +const _$EnumsFieldMap = { + 'id': 'id', + 'enumValue': 'enumValue', + 'nullableEnumValue': 'nullableEnumValue', + 'enumList': 'enumList', + 'nullableEnumList': 'nullableEnumList', +}; + +// ignore: unused_element +abstract class _$EnumsPerFieldToJson { + // ignore: unused_element + static Object? id(String instance) => instance; + // ignore: unused_element + static Object? enumValue(TestEnum instance) => _$TestEnumEnumMap[instance]!; + // ignore: unused_element + static Object? nullableEnumValue(TestEnum? instance) => + _$TestEnumEnumMap[instance]; + // ignore: unused_element + static Object? enumList(List instance) => + instance.map((e) => _$TestEnumEnumMap[e]!).toList(); + // ignore: unused_element + static Object? nullableEnumList(List? instance) => + instance?.map((e) => _$TestEnumEnumMap[e]!).toList(); +} + +Map _$EnumsToJson(Enums instance) => { + 'id': instance.id, + 'enumValue': _$TestEnumEnumMap[instance.enumValue]!, + 'nullableEnumValue': _$TestEnumEnumMap[instance.nullableEnumValue], + 'enumList': instance.enumList.map((e) => _$TestEnumEnumMap[e]!).toList(), + 'nullableEnumList': + instance.nullableEnumList?.map((e) => _$TestEnumEnumMap[e]!).toList(), + }; + +const _$TestEnumEnumMap = { + TestEnum.one: 'one', + TestEnum.two: 'two', + TestEnum.three: 'three', +}; diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/freezed.g.dart b/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/freezed.g.dart index 80414b5a8498..53003979f8f3 100644 --- a/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/freezed.g.dart +++ b/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/freezed.g.dart @@ -9,7 +9,7 @@ part of 'freezed.dart'; // ************************************************************************** // 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, require_trailing_commas, prefer_single_quotes, prefer_double_quotes, use_super_parameters +// 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, require_trailing_commas, prefer_single_quotes, prefer_double_quotes, use_super_parameters, duplicate_ignore class _Sentinel { const _Sentinel(); @@ -191,11 +191,13 @@ class _$PersonDocumentReference ); final json = { if (firstName != _sentinel) - _$$_PersonFieldMap['firstName']!: firstName as String, + _$$_PersonFieldMap['firstName']!: + _$$_PersonPerFieldToJson.firstName(firstName as String), if (firstNameFieldValue != null) _$$_PersonFieldMap['firstName']!: firstNameFieldValue, if (lastName != _sentinel) - _$$_PersonFieldMap['lastName']!: lastName as String, + _$$_PersonFieldMap['lastName']!: + _$$_PersonPerFieldToJson.lastName(lastName as String), if (lastNameFieldValue != null) _$$_PersonFieldMap['lastName']!: lastNameFieldValue, }; @@ -220,11 +222,13 @@ class _$PersonDocumentReference ); final json = { if (firstName != _sentinel) - _$$_PersonFieldMap['firstName']!: firstName as String, + _$$_PersonFieldMap['firstName']!: + _$$_PersonPerFieldToJson.firstName(firstName as String), if (firstNameFieldValue != null) _$$_PersonFieldMap['firstName']!: firstNameFieldValue, if (lastName != _sentinel) - _$$_PersonFieldMap['lastName']!: lastName as String, + _$$_PersonFieldMap['lastName']!: + _$$_PersonPerFieldToJson.lastName(lastName as String), if (lastNameFieldValue != null) _$$_PersonFieldMap['lastName']!: lastNameFieldValue, }; @@ -579,15 +583,28 @@ class _$PersonQuery extends QueryReference _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$$_PersonFieldMap['firstName']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: isEqualTo != null + ? _$$_PersonPerFieldToJson.firstName(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$$_PersonPerFieldToJson.firstName(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$$_PersonPerFieldToJson.firstName(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$$_PersonPerFieldToJson.firstName(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$$_PersonPerFieldToJson.firstName(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$$_PersonPerFieldToJson.firstName(isGreaterThanOrEqualTo) + : null, isNull: isNull, - whereIn: whereIn, - whereNotIn: whereNotIn, + whereIn: whereIn?.map((e) => _$$_PersonPerFieldToJson.firstName(e)), + whereNotIn: + whereNotIn?.map((e) => _$$_PersonPerFieldToJson.firstName(e)), ), $queryCursor: $queryCursor, ); @@ -608,15 +625,28 @@ class _$PersonQuery extends QueryReference _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$$_PersonFieldMap['lastName']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: isEqualTo != null + ? _$$_PersonPerFieldToJson.lastName(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$$_PersonPerFieldToJson.lastName(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$$_PersonPerFieldToJson.lastName(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$$_PersonPerFieldToJson.lastName(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$$_PersonPerFieldToJson.lastName(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$$_PersonPerFieldToJson.lastName(isGreaterThanOrEqualTo) + : null, isNull: isNull, - whereIn: whereIn, - whereNotIn: whereNotIn, + whereIn: whereIn?.map((e) => _$$_PersonPerFieldToJson.lastName(e)), + whereNotIn: + whereNotIn?.map((e) => _$$_PersonPerFieldToJson.lastName(e)), ), $queryCursor: $queryCursor, ); @@ -1102,7 +1132,8 @@ class _$PublicRedirectedDocumentReference extends FirestoreDocumentReference< ); final json = { if (value != _sentinel) - _$$PublicRedirected2FieldMap['value']!: value as String, + _$$PublicRedirected2FieldMap['value']!: + _$$PublicRedirected2PerFieldToJson.value(value as String), if (valueFieldValue != null) _$$PublicRedirected2FieldMap['value']!: valueFieldValue, }; @@ -1121,7 +1152,8 @@ class _$PublicRedirectedDocumentReference extends FirestoreDocumentReference< ); final json = { if (value != _sentinel) - _$$PublicRedirected2FieldMap['value']!: value as String, + _$$PublicRedirected2FieldMap['value']!: + _$$PublicRedirected2PerFieldToJson.value(value as String), if (valueFieldValue != null) _$$PublicRedirected2FieldMap['value']!: valueFieldValue, }; @@ -1458,15 +1490,29 @@ class _$PublicRedirectedQuery _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$$PublicRedirected2FieldMap['value']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: isEqualTo != null + ? _$$PublicRedirected2PerFieldToJson.value(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$$PublicRedirected2PerFieldToJson.value(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$$PublicRedirected2PerFieldToJson.value(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$$PublicRedirected2PerFieldToJson.value(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$$PublicRedirected2PerFieldToJson.value(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$$PublicRedirected2PerFieldToJson.value(isGreaterThanOrEqualTo) + : null, isNull: isNull, - whereIn: whereIn, - whereNotIn: whereNotIn, + whereIn: + whereIn?.map((e) => _$$PublicRedirected2PerFieldToJson.value(e)), + whereNotIn: + whereNotIn?.map((e) => _$$PublicRedirected2PerFieldToJson.value(e)), ), $queryCursor: $queryCursor, ); @@ -1730,6 +1776,14 @@ const _$$_PersonFieldMap = { 'lastName': 'LAST_NAME', }; +// ignore: unused_element +abstract class _$$_PersonPerFieldToJson { + // ignore: unused_element + static Object? firstName(String instance) => instance; + // ignore: unused_element + static Object? lastName(String instance) => instance; +} + Map _$$_PersonToJson(_$_Person instance) => { 'first_name': instance.firstName, 'LAST_NAME': instance.lastName, @@ -1744,6 +1798,12 @@ const _$$PublicRedirected2FieldMap = { 'value': 'value', }; +// ignore: unused_element +abstract class _$$PublicRedirected2PerFieldToJson { + // ignore: unused_element + static Object? value(String instance) => instance; +} + Map _$$PublicRedirected2ToJson(_$PublicRedirected2 instance) => { 'value': instance.value, diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/named_query.g.dart b/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/named_query.g.dart index e46bf5637488..3d287d85e2af 100644 --- a/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/named_query.g.dart +++ b/packages/cloud_firestore_odm/cloud_firestore_odm/example/lib/integration/named_query.g.dart @@ -9,7 +9,7 @@ part of 'named_query.dart'; // ************************************************************************** // 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, require_trailing_commas, prefer_single_quotes, prefer_double_quotes, use_super_parameters +// 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, require_trailing_commas, prefer_single_quotes, prefer_double_quotes, use_super_parameters, duplicate_ignore class _Sentinel { const _Sentinel(); @@ -199,7 +199,9 @@ class _$ConflictDocumentReference "Cannot specify both number and numberFieldValue", ); final json = { - if (number != _sentinel) _$ConflictFieldMap['number']!: number as num, + if (number != _sentinel) + _$ConflictFieldMap['number']!: + _$ConflictPerFieldToJson.number(number as num), if (numberFieldValue != null) _$ConflictFieldMap['number']!: numberFieldValue, }; @@ -217,7 +219,9 @@ class _$ConflictDocumentReference "Cannot specify both number and numberFieldValue", ); final json = { - if (number != _sentinel) _$ConflictFieldMap['number']!: number as num, + if (number != _sentinel) + _$ConflictFieldMap['number']!: + _$ConflictPerFieldToJson.number(number as num), if (numberFieldValue != null) _$ConflictFieldMap['number']!: numberFieldValue, }; @@ -551,15 +555,27 @@ class _$ConflictQuery extends QueryReference _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$ConflictFieldMap['number']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: isEqualTo != null + ? _$ConflictPerFieldToJson.number(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$ConflictPerFieldToJson.number(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$ConflictPerFieldToJson.number(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$ConflictPerFieldToJson.number(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$ConflictPerFieldToJson.number(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$ConflictPerFieldToJson.number(isGreaterThanOrEqualTo) + : null, isNull: isNull, - whereIn: whereIn, - whereNotIn: whereNotIn, + whereIn: whereIn?.map((e) => _$ConflictPerFieldToJson.number(e)), + whereNotIn: whereNotIn?.map((e) => _$ConflictPerFieldToJson.number(e)), ), $queryCursor: $queryCursor, ); @@ -815,6 +831,12 @@ const _$ConflictFieldMap = { 'number': 'number', }; +// ignore: unused_element +abstract class _$ConflictPerFieldToJson { + // ignore: unused_element + static Object? number(num instance) => instance; +} + Map _$ConflictToJson(Conflict instance) => { 'number': instance.number, }; 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 bf35cbaf991b..9440716d2f24 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 @@ -8,6 +8,15 @@ import 'package:json_annotation/json_annotation.dart'; part 'query.g.dart'; +@Collection('firestore-example-app/42/duration') +final durationQueryRef = DurationQueryCollectionReference(); + +@JsonSerializable(converters: firestoreJsonConverters) +class DurationQuery { + DurationQuery(this.duration); + final Duration duration; +} + @Collection('firestore-example-app/42/date-time') final dateTimeQueryRef = DateTimeQueryCollectionReference(); 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 627e6bfbf288..b1218414181a 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 @@ -9,7 +9,7 @@ part of 'query.dart'; // ************************************************************************** // 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, require_trailing_commas, prefer_single_quotes, prefer_double_quotes, use_super_parameters +// 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, require_trailing_commas, prefer_single_quotes, prefer_double_quotes, use_super_parameters, duplicate_ignore class _Sentinel { const _Sentinel(); @@ -17,6 +17,801 @@ class _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 DurationQueryCollectionReference + implements + DurationQueryQuery, + FirestoreCollectionReference { + factory DurationQueryCollectionReference([ + FirebaseFirestore? firestore, + ]) = _$DurationQueryCollectionReference; + + static DurationQuery fromFirestore( + DocumentSnapshot> snapshot, + SnapshotOptions? options, + ) { + return _$DurationQueryFromJson(snapshot.data()!); + } + + static Map toFirestore( + DurationQuery value, + SetOptions? options, + ) { + return _$DurationQueryToJson(value); + } + + @override + CollectionReference get reference; + + @override + DurationQueryDocumentReference doc([String? id]); + + /// Add a new document to this collection with the specified data, + /// assigning it a document ID automatically. + Future add(DurationQuery value); +} + +class _$DurationQueryCollectionReference extends _$DurationQueryQuery + implements DurationQueryCollectionReference { + factory _$DurationQueryCollectionReference([FirebaseFirestore? firestore]) { + firestore ??= FirebaseFirestore.instance; + + return _$DurationQueryCollectionReference._( + firestore.collection('firestore-example-app/42/duration').withConverter( + fromFirestore: DurationQueryCollectionReference.fromFirestore, + toFirestore: DurationQueryCollectionReference.toFirestore, + ), + ); + } + + _$DurationQueryCollectionReference._( + CollectionReference reference, + ) : super(reference, $referenceWithoutCursor: reference); + + String get path => reference.path; + + @override + CollectionReference get reference => + super.reference as CollectionReference; + + @override + DurationQueryDocumentReference doc([String? id]) { + assert( + id == null || id.split('/').length == 1, + 'The document ID cannot be from a different collection', + ); + return DurationQueryDocumentReference( + reference.doc(id), + ); + } + + @override + Future add(DurationQuery value) { + return reference + .add(value) + .then((ref) => DurationQueryDocumentReference(ref)); + } + + @override + bool operator ==(Object other) { + return other is _$DurationQueryCollectionReference && + other.runtimeType == runtimeType && + other.reference == reference; + } + + @override + int get hashCode => Object.hash(runtimeType, reference); +} + +abstract class DurationQueryDocumentReference + extends FirestoreDocumentReference { + factory DurationQueryDocumentReference( + DocumentReference reference) = + _$DurationQueryDocumentReference; + + DocumentReference get reference; + + /// A reference to the [DurationQueryCollectionReference] containing this document. + DurationQueryCollectionReference get parent { + return _$DurationQueryCollectionReference(reference.firestore); + } + + @override + Stream snapshots(); + + @override + Future get([GetOptions? options]); + + @override + Future delete(); + + /// Updates data on the document. Data will be merged with any existing + /// document data. + /// + /// If no document exists yet, the update will fail. + Future update({ + Duration duration, + FieldValue durationFieldValue, + }); + + /// Updates fields in the current document using the transaction API. + /// + /// The update will fail if applied to a document that does not exist. + void transactionUpdate( + Transaction transaction, { + Duration duration, + FieldValue durationFieldValue, + }); +} + +class _$DurationQueryDocumentReference extends FirestoreDocumentReference< + DurationQuery, + DurationQueryDocumentSnapshot> implements DurationQueryDocumentReference { + _$DurationQueryDocumentReference(this.reference); + + @override + final DocumentReference reference; + + /// A reference to the [DurationQueryCollectionReference] containing this document. + DurationQueryCollectionReference get parent { + return _$DurationQueryCollectionReference(reference.firestore); + } + + @override + Stream snapshots() { + return reference.snapshots().map(DurationQueryDocumentSnapshot._); + } + + @override + Future get([GetOptions? options]) { + return reference.get(options).then(DurationQueryDocumentSnapshot._); + } + + @override + Future transactionGet( + Transaction transaction) { + return transaction.get(reference).then(DurationQueryDocumentSnapshot._); + } + + Future update({ + Object? duration = _sentinel, + FieldValue? durationFieldValue, + }) async { + assert( + duration == _sentinel || durationFieldValue == null, + "Cannot specify both duration and durationFieldValue", + ); + final json = { + if (duration != _sentinel) + _$DurationQueryFieldMap['duration']!: + _$DurationQueryPerFieldToJson.duration(duration as Duration), + if (durationFieldValue != null) + _$DurationQueryFieldMap['duration']!: durationFieldValue, + }; + + return reference.update(json); + } + + void transactionUpdate( + Transaction transaction, { + Object? duration = _sentinel, + FieldValue? durationFieldValue, + }) { + assert( + duration == _sentinel || durationFieldValue == null, + "Cannot specify both duration and durationFieldValue", + ); + final json = { + if (duration != _sentinel) + _$DurationQueryFieldMap['duration']!: + _$DurationQueryPerFieldToJson.duration(duration as Duration), + if (durationFieldValue != null) + _$DurationQueryFieldMap['duration']!: durationFieldValue, + }; + + transaction.update(reference, json); + } + + @override + bool operator ==(Object other) { + return other is DurationQueryDocumentReference && + other.runtimeType == runtimeType && + other.parent == parent && + other.id == id; + } + + @override + int get hashCode => Object.hash(runtimeType, parent, id); +} + +abstract class DurationQueryQuery + implements QueryReference { + @override + DurationQueryQuery limit(int limit); + + @override + DurationQueryQuery limitToLast(int limit); + + /// Perform an order query based on a [FieldPath]. + /// + /// This method is considered unsafe as it does check that the field path + /// maps to a valid property or that parameters such as [isEqualTo] receive + /// a value of the correct type. + /// + /// If possible, instead use the more explicit variant of order queries: + /// + /// **AVOID**: + /// ```dart + /// collection.orderByFieldPath( + /// FieldPath.fromString('title'), + /// startAt: 'title', + /// ); + /// ``` + /// + /// **PREFER**: + /// ```dart + /// collection.orderByTitle(startAt: 'title'); + /// ``` + DurationQueryQuery orderByFieldPath( + FieldPath fieldPath, { + bool descending = false, + Object? startAt, + Object? startAfter, + Object? endAt, + Object? endBefore, + DurationQueryDocumentSnapshot? startAtDocument, + DurationQueryDocumentSnapshot? endAtDocument, + DurationQueryDocumentSnapshot? endBeforeDocument, + DurationQueryDocumentSnapshot? startAfterDocument, + }); + + /// Perform a where query based on a [FieldPath]. + /// + /// This method is considered unsafe as it does check that the field path + /// maps to a valid property or that parameters such as [isEqualTo] receive + /// a value of the correct type. + /// + /// If possible, instead use the more explicit variant of where queries: + /// + /// **AVOID**: + /// ```dart + /// collection.whereFieldPath(FieldPath.fromString('title'), isEqualTo: 'title'); + /// ``` + /// + /// **PREFER**: + /// ```dart + /// collection.whereTitle(isEqualTo: 'title'); + /// ``` + DurationQueryQuery whereFieldPath( + FieldPath fieldPath, { + Object? isEqualTo, + Object? isNotEqualTo, + Object? isLessThan, + Object? isLessThanOrEqualTo, + Object? isGreaterThan, + Object? isGreaterThanOrEqualTo, + Object? arrayContains, + List? arrayContainsAny, + List? whereIn, + List? whereNotIn, + bool? isNull, + }); + + DurationQueryQuery whereDocumentId({ + String? isEqualTo, + String? isNotEqualTo, + String? isLessThan, + String? isLessThanOrEqualTo, + String? isGreaterThan, + String? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }); + DurationQueryQuery whereDuration({ + Duration? isEqualTo, + Duration? isNotEqualTo, + Duration? isLessThan, + Duration? isLessThanOrEqualTo, + Duration? isGreaterThan, + Duration? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }); + + DurationQueryQuery orderByDocumentId({ + bool descending = false, + String startAt, + String startAfter, + String endAt, + String endBefore, + DurationQueryDocumentSnapshot? startAtDocument, + DurationQueryDocumentSnapshot? endAtDocument, + DurationQueryDocumentSnapshot? endBeforeDocument, + DurationQueryDocumentSnapshot? startAfterDocument, + }); + + DurationQueryQuery orderByDuration({ + bool descending = false, + Duration startAt, + Duration startAfter, + Duration endAt, + Duration endBefore, + DurationQueryDocumentSnapshot? startAtDocument, + DurationQueryDocumentSnapshot? endAtDocument, + DurationQueryDocumentSnapshot? endBeforeDocument, + DurationQueryDocumentSnapshot? startAfterDocument, + }); +} + +class _$DurationQueryQuery + extends QueryReference + implements DurationQueryQuery { + _$DurationQueryQuery( + this._collection, { + required Query $referenceWithoutCursor, + $QueryCursor $queryCursor = const $QueryCursor(), + }) : super( + $referenceWithoutCursor: $referenceWithoutCursor, + $queryCursor: $queryCursor, + ); + + final CollectionReference _collection; + + @override + Stream snapshots([SnapshotOptions? options]) { + return reference + .snapshots() + .map(DurationQueryQuerySnapshot._fromQuerySnapshot); + } + + @override + Future get([GetOptions? options]) { + return reference + .get(options) + .then(DurationQueryQuerySnapshot._fromQuerySnapshot); + } + + @override + DurationQueryQuery limit(int limit) { + return _$DurationQueryQuery( + _collection, + $referenceWithoutCursor: $referenceWithoutCursor.limit(limit), + $queryCursor: $queryCursor, + ); + } + + @override + DurationQueryQuery limitToLast(int limit) { + return _$DurationQueryQuery( + _collection, + $referenceWithoutCursor: $referenceWithoutCursor.limitToLast(limit), + $queryCursor: $queryCursor, + ); + } + + DurationQueryQuery orderByFieldPath( + FieldPath fieldPath, { + bool descending = false, + Object? startAt = _sentinel, + Object? startAfter = _sentinel, + Object? endAt = _sentinel, + Object? endBefore = _sentinel, + DurationQueryDocumentSnapshot? startAtDocument, + DurationQueryDocumentSnapshot? endAtDocument, + DurationQueryDocumentSnapshot? endBeforeDocument, + DurationQueryDocumentSnapshot? startAfterDocument, + }) { + final query = + $referenceWithoutCursor.orderBy(fieldPath, descending: descending); + var queryCursor = $queryCursor; + + if (startAtDocument != null) { + queryCursor = queryCursor.copyWith( + startAt: const [], + startAtDocumentSnapshot: startAtDocument.snapshot, + ); + } + if (startAfterDocument != null) { + queryCursor = queryCursor.copyWith( + startAfter: const [], + startAfterDocumentSnapshot: startAfterDocument.snapshot, + ); + } + if (endAtDocument != null) { + queryCursor = queryCursor.copyWith( + endAt: const [], + endAtDocumentSnapshot: endAtDocument.snapshot, + ); + } + if (endBeforeDocument != null) { + queryCursor = queryCursor.copyWith( + endBefore: const [], + endBeforeDocumentSnapshot: endBeforeDocument.snapshot, + ); + } + + if (startAt != _sentinel) { + queryCursor = queryCursor.copyWith( + startAt: [...queryCursor.startAt, startAt], + startAtDocumentSnapshot: null, + ); + } + if (startAfter != _sentinel) { + queryCursor = queryCursor.copyWith( + startAfter: [...queryCursor.startAfter, startAfter], + startAfterDocumentSnapshot: null, + ); + } + if (endAt != _sentinel) { + queryCursor = queryCursor.copyWith( + endAt: [...queryCursor.endAt, endAt], + endAtDocumentSnapshot: null, + ); + } + if (endBefore != _sentinel) { + queryCursor = queryCursor.copyWith( + endBefore: [...queryCursor.endBefore, endBefore], + endBeforeDocumentSnapshot: null, + ); + } + return _$DurationQueryQuery( + _collection, + $referenceWithoutCursor: query, + $queryCursor: queryCursor, + ); + } + + DurationQueryQuery whereFieldPath( + FieldPath fieldPath, { + Object? isEqualTo, + Object? isNotEqualTo, + Object? isLessThan, + Object? isLessThanOrEqualTo, + Object? isGreaterThan, + Object? isGreaterThanOrEqualTo, + Object? arrayContains, + List? arrayContainsAny, + List? whereIn, + List? whereNotIn, + bool? isNull, + }) { + return _$DurationQueryQuery( + _collection, + $referenceWithoutCursor: $referenceWithoutCursor.where( + fieldPath, + isEqualTo: isEqualTo, + isNotEqualTo: isNotEqualTo, + isLessThan: isLessThan, + isLessThanOrEqualTo: isLessThanOrEqualTo, + isGreaterThan: isGreaterThan, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + arrayContains: arrayContains, + arrayContainsAny: arrayContainsAny, + whereIn: whereIn, + whereNotIn: whereNotIn, + isNull: isNull, + ), + $queryCursor: $queryCursor, + ); + } + + DurationQueryQuery whereDocumentId({ + String? isEqualTo, + String? isNotEqualTo, + String? isLessThan, + String? isLessThanOrEqualTo, + String? isGreaterThan, + String? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }) { + return _$DurationQueryQuery( + _collection, + $referenceWithoutCursor: $referenceWithoutCursor.where( + FieldPath.documentId, + isEqualTo: isEqualTo, + isNotEqualTo: isNotEqualTo, + isLessThan: isLessThan, + isLessThanOrEqualTo: isLessThanOrEqualTo, + isGreaterThan: isGreaterThan, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isNull: isNull, + whereIn: whereIn, + whereNotIn: whereNotIn, + ), + $queryCursor: $queryCursor, + ); + } + + DurationQueryQuery whereDuration({ + Duration? isEqualTo, + Duration? isNotEqualTo, + Duration? isLessThan, + Duration? isLessThanOrEqualTo, + Duration? isGreaterThan, + Duration? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }) { + return _$DurationQueryQuery( + _collection, + $referenceWithoutCursor: $referenceWithoutCursor.where( + _$DurationQueryFieldMap['duration']!, + isEqualTo: isEqualTo != null + ? _$DurationQueryPerFieldToJson.duration(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$DurationQueryPerFieldToJson.duration(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$DurationQueryPerFieldToJson.duration(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$DurationQueryPerFieldToJson.duration(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$DurationQueryPerFieldToJson.duration(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$DurationQueryPerFieldToJson.duration(isGreaterThanOrEqualTo) + : null, + isNull: isNull, + whereIn: whereIn?.map((e) => _$DurationQueryPerFieldToJson.duration(e)), + whereNotIn: + whereNotIn?.map((e) => _$DurationQueryPerFieldToJson.duration(e)), + ), + $queryCursor: $queryCursor, + ); + } + + DurationQueryQuery orderByDocumentId({ + bool descending = false, + Object? startAt = _sentinel, + Object? startAfter = _sentinel, + Object? endAt = _sentinel, + Object? endBefore = _sentinel, + DurationQueryDocumentSnapshot? startAtDocument, + DurationQueryDocumentSnapshot? endAtDocument, + DurationQueryDocumentSnapshot? endBeforeDocument, + DurationQueryDocumentSnapshot? startAfterDocument, + }) { + final query = $referenceWithoutCursor.orderBy(FieldPath.documentId, + descending: descending); + var queryCursor = $queryCursor; + + if (startAtDocument != null) { + queryCursor = queryCursor.copyWith( + startAt: const [], + startAtDocumentSnapshot: startAtDocument.snapshot, + ); + } + if (startAfterDocument != null) { + queryCursor = queryCursor.copyWith( + startAfter: const [], + startAfterDocumentSnapshot: startAfterDocument.snapshot, + ); + } + if (endAtDocument != null) { + queryCursor = queryCursor.copyWith( + endAt: const [], + endAtDocumentSnapshot: endAtDocument.snapshot, + ); + } + if (endBeforeDocument != null) { + queryCursor = queryCursor.copyWith( + endBefore: const [], + endBeforeDocumentSnapshot: endBeforeDocument.snapshot, + ); + } + + if (startAt != _sentinel) { + queryCursor = queryCursor.copyWith( + startAt: [...queryCursor.startAt, startAt], + startAtDocumentSnapshot: null, + ); + } + if (startAfter != _sentinel) { + queryCursor = queryCursor.copyWith( + startAfter: [...queryCursor.startAfter, startAfter], + startAfterDocumentSnapshot: null, + ); + } + if (endAt != _sentinel) { + queryCursor = queryCursor.copyWith( + endAt: [...queryCursor.endAt, endAt], + endAtDocumentSnapshot: null, + ); + } + if (endBefore != _sentinel) { + queryCursor = queryCursor.copyWith( + endBefore: [...queryCursor.endBefore, endBefore], + endBeforeDocumentSnapshot: null, + ); + } + + return _$DurationQueryQuery( + _collection, + $referenceWithoutCursor: query, + $queryCursor: queryCursor, + ); + } + + DurationQueryQuery orderByDuration({ + bool descending = false, + Object? startAt = _sentinel, + Object? startAfter = _sentinel, + Object? endAt = _sentinel, + Object? endBefore = _sentinel, + DurationQueryDocumentSnapshot? startAtDocument, + DurationQueryDocumentSnapshot? endAtDocument, + DurationQueryDocumentSnapshot? endBeforeDocument, + DurationQueryDocumentSnapshot? startAfterDocument, + }) { + final query = $referenceWithoutCursor + .orderBy(_$DurationQueryFieldMap['duration']!, descending: descending); + var queryCursor = $queryCursor; + + if (startAtDocument != null) { + queryCursor = queryCursor.copyWith( + startAt: const [], + startAtDocumentSnapshot: startAtDocument.snapshot, + ); + } + if (startAfterDocument != null) { + queryCursor = queryCursor.copyWith( + startAfter: const [], + startAfterDocumentSnapshot: startAfterDocument.snapshot, + ); + } + if (endAtDocument != null) { + queryCursor = queryCursor.copyWith( + endAt: const [], + endAtDocumentSnapshot: endAtDocument.snapshot, + ); + } + if (endBeforeDocument != null) { + queryCursor = queryCursor.copyWith( + endBefore: const [], + endBeforeDocumentSnapshot: endBeforeDocument.snapshot, + ); + } + + if (startAt != _sentinel) { + queryCursor = queryCursor.copyWith( + startAt: [...queryCursor.startAt, startAt], + startAtDocumentSnapshot: null, + ); + } + if (startAfter != _sentinel) { + queryCursor = queryCursor.copyWith( + startAfter: [...queryCursor.startAfter, startAfter], + startAfterDocumentSnapshot: null, + ); + } + if (endAt != _sentinel) { + queryCursor = queryCursor.copyWith( + endAt: [...queryCursor.endAt, endAt], + endAtDocumentSnapshot: null, + ); + } + if (endBefore != _sentinel) { + queryCursor = queryCursor.copyWith( + endBefore: [...queryCursor.endBefore, endBefore], + endBeforeDocumentSnapshot: null, + ); + } + + return _$DurationQueryQuery( + _collection, + $referenceWithoutCursor: query, + $queryCursor: queryCursor, + ); + } + + @override + bool operator ==(Object other) { + return other is _$DurationQueryQuery && + other.runtimeType == runtimeType && + other.reference == reference; + } + + @override + int get hashCode => Object.hash(runtimeType, reference); +} + +class DurationQueryDocumentSnapshot + extends FirestoreDocumentSnapshot { + DurationQueryDocumentSnapshot._(this.snapshot) : data = snapshot.data(); + + @override + final DocumentSnapshot snapshot; + + @override + DurationQueryDocumentReference get reference { + return DurationQueryDocumentReference( + snapshot.reference, + ); + } + + @override + final DurationQuery? data; +} + +class DurationQueryQuerySnapshot extends FirestoreQuerySnapshot { + DurationQueryQuerySnapshot._( + this.snapshot, + this.docs, + this.docChanges, + ); + + factory DurationQueryQuerySnapshot._fromQuerySnapshot( + QuerySnapshot snapshot, + ) { + final docs = + snapshot.docs.map(DurationQueryQueryDocumentSnapshot._).toList(); + + final docChanges = snapshot.docChanges.map((change) { + return _decodeDocumentChange( + change, + DurationQueryDocumentSnapshot._, + ); + }).toList(); + + return DurationQueryQuerySnapshot._( + snapshot, + docs, + docChanges, + ); + } + + static FirestoreDocumentChange + _decodeDocumentChange( + DocumentChange docChange, + DurationQueryDocumentSnapshot Function(DocumentSnapshot doc) decodeDoc, + ) { + return FirestoreDocumentChange( + type: docChange.type, + oldIndex: docChange.oldIndex, + newIndex: docChange.newIndex, + doc: decodeDoc(docChange.doc), + ); + } + + final QuerySnapshot snapshot; + + @override + final List docs; + + @override + final List> docChanges; +} + +class DurationQueryQueryDocumentSnapshot + extends FirestoreQueryDocumentSnapshot + implements DurationQueryDocumentSnapshot { + DurationQueryQueryDocumentSnapshot._(this.snapshot) : data = snapshot.data(); + + @override + final QueryDocumentSnapshot snapshot; + + @override + final DurationQuery data; + + @override + DurationQueryDocumentReference get reference { + return DurationQueryDocumentReference(snapshot.reference); + } +} + /// A collection reference object can be used for adding documents, /// getting document references, and querying for documents /// (using the methods inherited from Query). @@ -186,7 +981,9 @@ class _$DateTimeQueryDocumentReference extends FirestoreDocumentReference< "Cannot specify both time and timeFieldValue", ); final json = { - if (time != _sentinel) _$DateTimeQueryFieldMap['time']!: time as DateTime, + if (time != _sentinel) + _$DateTimeQueryFieldMap['time']!: + _$DateTimeQueryPerFieldToJson.time(time as DateTime), if (timeFieldValue != null) _$DateTimeQueryFieldMap['time']!: timeFieldValue, }; @@ -204,7 +1001,9 @@ class _$DateTimeQueryDocumentReference extends FirestoreDocumentReference< "Cannot specify both time and timeFieldValue", ); final json = { - if (time != _sentinel) _$DateTimeQueryFieldMap['time']!: time as DateTime, + if (time != _sentinel) + _$DateTimeQueryFieldMap['time']!: + _$DateTimeQueryPerFieldToJson.time(time as DateTime), if (timeFieldValue != null) _$DateTimeQueryFieldMap['time']!: timeFieldValue, }; @@ -541,15 +1340,28 @@ class _$DateTimeQueryQuery _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$DateTimeQueryFieldMap['time']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: isEqualTo != null + ? _$DateTimeQueryPerFieldToJson.time(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$DateTimeQueryPerFieldToJson.time(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$DateTimeQueryPerFieldToJson.time(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$DateTimeQueryPerFieldToJson.time(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$DateTimeQueryPerFieldToJson.time(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$DateTimeQueryPerFieldToJson.time(isGreaterThanOrEqualTo) + : null, isNull: isNull, - whereIn: whereIn, - whereNotIn: whereNotIn, + whereIn: whereIn?.map((e) => _$DateTimeQueryPerFieldToJson.time(e)), + whereNotIn: + whereNotIn?.map((e) => _$DateTimeQueryPerFieldToJson.time(e)), ), $queryCursor: $queryCursor, ); @@ -967,7 +1779,8 @@ class _$TimestampQueryDocumentReference extends FirestoreDocumentReference< ); final json = { if (time != _sentinel) - _$TimestampQueryFieldMap['time']!: time as Timestamp, + _$TimestampQueryFieldMap['time']!: + _$TimestampQueryPerFieldToJson.time(time as Timestamp), if (timeFieldValue != null) _$TimestampQueryFieldMap['time']!: timeFieldValue, }; @@ -986,7 +1799,8 @@ class _$TimestampQueryDocumentReference extends FirestoreDocumentReference< ); final json = { if (time != _sentinel) - _$TimestampQueryFieldMap['time']!: time as Timestamp, + _$TimestampQueryFieldMap['time']!: + _$TimestampQueryPerFieldToJson.time(time as Timestamp), if (timeFieldValue != null) _$TimestampQueryFieldMap['time']!: timeFieldValue, }; @@ -1323,15 +2137,28 @@ class _$TimestampQueryQuery _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$TimestampQueryFieldMap['time']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: isEqualTo != null + ? _$TimestampQueryPerFieldToJson.time(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$TimestampQueryPerFieldToJson.time(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$TimestampQueryPerFieldToJson.time(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$TimestampQueryPerFieldToJson.time(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$TimestampQueryPerFieldToJson.time(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$TimestampQueryPerFieldToJson.time(isGreaterThanOrEqualTo) + : null, isNull: isNull, - whereIn: whereIn, - whereNotIn: whereNotIn, + whereIn: whereIn?.map((e) => _$TimestampQueryPerFieldToJson.time(e)), + whereNotIn: + whereNotIn?.map((e) => _$TimestampQueryPerFieldToJson.time(e)), ), $queryCursor: $queryCursor, ); @@ -1750,7 +2577,8 @@ class _$GeoPointQueryDocumentReference extends FirestoreDocumentReference< ); final json = { if (point != _sentinel) - _$GeoPointQueryFieldMap['point']!: point as GeoPoint, + _$GeoPointQueryFieldMap['point']!: + _$GeoPointQueryPerFieldToJson.point(point as GeoPoint), if (pointFieldValue != null) _$GeoPointQueryFieldMap['point']!: pointFieldValue, }; @@ -1769,7 +2597,8 @@ class _$GeoPointQueryDocumentReference extends FirestoreDocumentReference< ); final json = { if (point != _sentinel) - _$GeoPointQueryFieldMap['point']!: point as GeoPoint, + _$GeoPointQueryFieldMap['point']!: + _$GeoPointQueryPerFieldToJson.point(point as GeoPoint), if (pointFieldValue != null) _$GeoPointQueryFieldMap['point']!: pointFieldValue, }; @@ -2106,15 +2935,28 @@ class _$GeoPointQueryQuery _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$GeoPointQueryFieldMap['point']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: isEqualTo != null + ? _$GeoPointQueryPerFieldToJson.point(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$GeoPointQueryPerFieldToJson.point(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$GeoPointQueryPerFieldToJson.point(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$GeoPointQueryPerFieldToJson.point(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$GeoPointQueryPerFieldToJson.point(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$GeoPointQueryPerFieldToJson.point(isGreaterThanOrEqualTo) + : null, isNull: isNull, - whereIn: whereIn, - whereNotIn: whereNotIn, + whereIn: whereIn?.map((e) => _$GeoPointQueryPerFieldToJson.point(e)), + whereNotIn: + whereNotIn?.map((e) => _$GeoPointQueryPerFieldToJson.point(e)), ), $queryCursor: $queryCursor, ); @@ -2541,7 +3383,8 @@ class _$DocumentReferenceQueryDocumentReference final json = { if (ref != _sentinel) _$DocumentReferenceQueryFieldMap['ref']!: - ref as DocumentReference>, + _$DocumentReferenceQueryPerFieldToJson + .ref(ref as DocumentReference>), if (refFieldValue != null) _$DocumentReferenceQueryFieldMap['ref']!: refFieldValue, }; @@ -2561,7 +3404,8 @@ class _$DocumentReferenceQueryDocumentReference final json = { if (ref != _sentinel) _$DocumentReferenceQueryFieldMap['ref']!: - ref as DocumentReference>, + _$DocumentReferenceQueryPerFieldToJson + .ref(ref as DocumentReference>), if (refFieldValue != null) _$DocumentReferenceQueryFieldMap['ref']!: refFieldValue, }; @@ -2901,15 +3745,29 @@ class _$DocumentReferenceQueryQuery extends QueryReference< _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$DocumentReferenceQueryFieldMap['ref']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: isEqualTo != null + ? _$DocumentReferenceQueryPerFieldToJson.ref(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$DocumentReferenceQueryPerFieldToJson.ref(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$DocumentReferenceQueryPerFieldToJson.ref(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$DocumentReferenceQueryPerFieldToJson.ref(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$DocumentReferenceQueryPerFieldToJson.ref(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$DocumentReferenceQueryPerFieldToJson.ref(isGreaterThanOrEqualTo) + : null, isNull: isNull, - whereIn: whereIn, - whereNotIn: whereNotIn, + whereIn: + whereIn?.map((e) => _$DocumentReferenceQueryPerFieldToJson.ref(e)), + whereNotIn: whereNotIn + ?.map((e) => _$DocumentReferenceQueryPerFieldToJson.ref(e)), ), $queryCursor: $queryCursor, ); @@ -3165,6 +4023,26 @@ class DocumentReferenceQueryQueryDocumentSnapshot // JsonSerializableGenerator // ************************************************************************** +DurationQuery _$DurationQueryFromJson(Map json) => + DurationQuery( + Duration(microseconds: json['duration'] as int), + ); + +const _$DurationQueryFieldMap = { + 'duration': 'duration', +}; + +// ignore: unused_element +abstract class _$DurationQueryPerFieldToJson { + // ignore: unused_element + static Object? duration(Duration instance) => instance.inMicroseconds; +} + +Map _$DurationQueryToJson(DurationQuery instance) => + { + 'duration': instance.duration.inMicroseconds, + }; + DateTimeQuery _$DateTimeQueryFromJson(Map json) => DateTimeQuery( const FirestoreDateTimeConverter().fromJson(json['time'] as Timestamp), @@ -3174,6 +4052,13 @@ const _$DateTimeQueryFieldMap = { 'time': 'time', }; +// ignore: unused_element +abstract class _$DateTimeQueryPerFieldToJson { + // ignore: unused_element + static Object? time(DateTime instance) => + const FirestoreDateTimeConverter().toJson(instance); +} + Map _$DateTimeQueryToJson(DateTimeQuery instance) => { 'time': const FirestoreDateTimeConverter().toJson(instance.time), @@ -3188,6 +4073,13 @@ const _$TimestampQueryFieldMap = { 'time': 'time', }; +// ignore: unused_element +abstract class _$TimestampQueryPerFieldToJson { + // ignore: unused_element + static Object? time(Timestamp instance) => + const FirestoreTimestampConverter().toJson(instance); +} + Map _$TimestampQueryToJson(TimestampQuery instance) => { 'time': const FirestoreTimestampConverter().toJson(instance.time), @@ -3202,6 +4094,13 @@ const _$GeoPointQueryFieldMap = { 'point': 'point', }; +// ignore: unused_element +abstract class _$GeoPointQueryPerFieldToJson { + // ignore: unused_element + static Object? point(GeoPoint instance) => + const FirestoreGeoPointConverter().toJson(instance); +} + Map _$GeoPointQueryToJson(GeoPointQuery instance) => { 'point': const FirestoreGeoPointConverter().toJson(instance.point), @@ -3218,6 +4117,13 @@ const _$DocumentReferenceQueryFieldMap = { 'ref': 'ref', }; +// ignore: unused_element +abstract class _$DocumentReferenceQueryPerFieldToJson { + // ignore: unused_element + static Object? ref(DocumentReference> instance) => + const FirestoreDocumentReferenceConverter().toJson(instance); +} + Map _$DocumentReferenceQueryToJson( DocumentReferenceQuery instance) => { 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 76ac24d5d83a..6bc8c87e98d8 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 @@ -9,7 +9,7 @@ part of 'movie.dart'; // ************************************************************************** // 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, require_trailing_commas, prefer_single_quotes, prefer_double_quotes, use_super_parameters +// 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, require_trailing_commas, prefer_single_quotes, prefer_double_quotes, use_super_parameters, duplicate_ignore class _Sentinel { const _Sentinel(); @@ -258,23 +258,35 @@ class _$MovieDocumentReference "Cannot specify both tags and tagsFieldValue", ); final json = { - if (poster != _sentinel) _$MovieFieldMap['poster']!: poster as String, + if (poster != _sentinel) + _$MovieFieldMap['poster']!: + _$MoviePerFieldToJson.poster(poster as String), if (posterFieldValue != null) _$MovieFieldMap['poster']!: posterFieldValue, - if (likes != _sentinel) _$MovieFieldMap['likes']!: likes as int, + if (likes != _sentinel) + _$MovieFieldMap['likes']!: _$MoviePerFieldToJson.likes(likes as int), if (likesFieldValue != null) _$MovieFieldMap['likes']!: likesFieldValue, - if (title != _sentinel) _$MovieFieldMap['title']!: title as String, + if (title != _sentinel) + _$MovieFieldMap['title']!: _$MoviePerFieldToJson.title(title as String), if (titleFieldValue != null) _$MovieFieldMap['title']!: titleFieldValue, - if (year != _sentinel) _$MovieFieldMap['year']!: year as int, + if (year != _sentinel) + _$MovieFieldMap['year']!: _$MoviePerFieldToJson.year(year as int), if (yearFieldValue != null) _$MovieFieldMap['year']!: yearFieldValue, - if (runtime != _sentinel) _$MovieFieldMap['runtime']!: runtime as String, + if (runtime != _sentinel) + _$MovieFieldMap['runtime']!: + _$MoviePerFieldToJson.runtime(runtime as String), if (runtimeFieldValue != null) _$MovieFieldMap['runtime']!: runtimeFieldValue, - if (rated != _sentinel) _$MovieFieldMap['rated']!: rated as String, + if (rated != _sentinel) + _$MovieFieldMap['rated']!: _$MoviePerFieldToJson.rated(rated as String), if (ratedFieldValue != null) _$MovieFieldMap['rated']!: ratedFieldValue, - if (genre != _sentinel) _$MovieFieldMap['genre']!: genre as List?, + if (genre != _sentinel) + _$MovieFieldMap['genre']!: + _$MoviePerFieldToJson.genre(genre as List?), if (genreFieldValue != null) _$MovieFieldMap['genre']!: genreFieldValue, - if (tags != _sentinel) _$MovieFieldMap['tags']!: tags as Set?, + if (tags != _sentinel) + _$MovieFieldMap['tags']!: + _$MoviePerFieldToJson.tags(tags as Set?), if (tagsFieldValue != null) _$MovieFieldMap['tags']!: tagsFieldValue, }; @@ -333,23 +345,35 @@ class _$MovieDocumentReference "Cannot specify both tags and tagsFieldValue", ); final json = { - if (poster != _sentinel) _$MovieFieldMap['poster']!: poster as String, + if (poster != _sentinel) + _$MovieFieldMap['poster']!: + _$MoviePerFieldToJson.poster(poster as String), if (posterFieldValue != null) _$MovieFieldMap['poster']!: posterFieldValue, - if (likes != _sentinel) _$MovieFieldMap['likes']!: likes as int, + if (likes != _sentinel) + _$MovieFieldMap['likes']!: _$MoviePerFieldToJson.likes(likes as int), if (likesFieldValue != null) _$MovieFieldMap['likes']!: likesFieldValue, - if (title != _sentinel) _$MovieFieldMap['title']!: title as String, + if (title != _sentinel) + _$MovieFieldMap['title']!: _$MoviePerFieldToJson.title(title as String), if (titleFieldValue != null) _$MovieFieldMap['title']!: titleFieldValue, - if (year != _sentinel) _$MovieFieldMap['year']!: year as int, + if (year != _sentinel) + _$MovieFieldMap['year']!: _$MoviePerFieldToJson.year(year as int), if (yearFieldValue != null) _$MovieFieldMap['year']!: yearFieldValue, - if (runtime != _sentinel) _$MovieFieldMap['runtime']!: runtime as String, + if (runtime != _sentinel) + _$MovieFieldMap['runtime']!: + _$MoviePerFieldToJson.runtime(runtime as String), if (runtimeFieldValue != null) _$MovieFieldMap['runtime']!: runtimeFieldValue, - if (rated != _sentinel) _$MovieFieldMap['rated']!: rated as String, + if (rated != _sentinel) + _$MovieFieldMap['rated']!: _$MoviePerFieldToJson.rated(rated as String), if (ratedFieldValue != null) _$MovieFieldMap['rated']!: ratedFieldValue, - if (genre != _sentinel) _$MovieFieldMap['genre']!: genre as List?, + if (genre != _sentinel) + _$MovieFieldMap['genre']!: + _$MoviePerFieldToJson.genre(genre as List?), if (genreFieldValue != null) _$MovieFieldMap['genre']!: genreFieldValue, - if (tags != _sentinel) _$MovieFieldMap['tags']!: tags as Set?, + if (tags != _sentinel) + _$MovieFieldMap['tags']!: + _$MoviePerFieldToJson.tags(tags as Set?), if (tagsFieldValue != null) _$MovieFieldMap['tags']!: tagsFieldValue, }; @@ -840,15 +864,26 @@ class _$MovieQuery extends QueryReference _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$MovieFieldMap['poster']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: + isEqualTo != null ? _$MoviePerFieldToJson.poster(isEqualTo) : null, + isNotEqualTo: isNotEqualTo != null + ? _$MoviePerFieldToJson.poster(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$MoviePerFieldToJson.poster(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$MoviePerFieldToJson.poster(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$MoviePerFieldToJson.poster(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$MoviePerFieldToJson.poster(isGreaterThanOrEqualTo) + : null, isNull: isNull, - whereIn: whereIn, - whereNotIn: whereNotIn, + whereIn: whereIn?.map((e) => _$MoviePerFieldToJson.poster(e)), + whereNotIn: whereNotIn?.map((e) => _$MoviePerFieldToJson.poster(e)), ), $queryCursor: $queryCursor, ); @@ -869,15 +904,25 @@ class _$MovieQuery extends QueryReference _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$MovieFieldMap['likes']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: + isEqualTo != null ? _$MoviePerFieldToJson.likes(isEqualTo) : null, + isNotEqualTo: isNotEqualTo != null + ? _$MoviePerFieldToJson.likes(isNotEqualTo) + : null, + isLessThan: + isLessThan != null ? _$MoviePerFieldToJson.likes(isLessThan) : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$MoviePerFieldToJson.likes(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$MoviePerFieldToJson.likes(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$MoviePerFieldToJson.likes(isGreaterThanOrEqualTo) + : null, isNull: isNull, - whereIn: whereIn, - whereNotIn: whereNotIn, + whereIn: whereIn?.map((e) => _$MoviePerFieldToJson.likes(e)), + whereNotIn: whereNotIn?.map((e) => _$MoviePerFieldToJson.likes(e)), ), $queryCursor: $queryCursor, ); @@ -898,15 +943,25 @@ class _$MovieQuery extends QueryReference _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$MovieFieldMap['title']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: + isEqualTo != null ? _$MoviePerFieldToJson.title(isEqualTo) : null, + isNotEqualTo: isNotEqualTo != null + ? _$MoviePerFieldToJson.title(isNotEqualTo) + : null, + isLessThan: + isLessThan != null ? _$MoviePerFieldToJson.title(isLessThan) : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$MoviePerFieldToJson.title(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$MoviePerFieldToJson.title(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$MoviePerFieldToJson.title(isGreaterThanOrEqualTo) + : null, isNull: isNull, - whereIn: whereIn, - whereNotIn: whereNotIn, + whereIn: whereIn?.map((e) => _$MoviePerFieldToJson.title(e)), + whereNotIn: whereNotIn?.map((e) => _$MoviePerFieldToJson.title(e)), ), $queryCursor: $queryCursor, ); @@ -927,15 +982,25 @@ class _$MovieQuery extends QueryReference _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$MovieFieldMap['year']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: + isEqualTo != null ? _$MoviePerFieldToJson.year(isEqualTo) : null, + isNotEqualTo: isNotEqualTo != null + ? _$MoviePerFieldToJson.year(isNotEqualTo) + : null, + isLessThan: + isLessThan != null ? _$MoviePerFieldToJson.year(isLessThan) : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$MoviePerFieldToJson.year(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$MoviePerFieldToJson.year(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$MoviePerFieldToJson.year(isGreaterThanOrEqualTo) + : null, isNull: isNull, - whereIn: whereIn, - whereNotIn: whereNotIn, + whereIn: whereIn?.map((e) => _$MoviePerFieldToJson.year(e)), + whereNotIn: whereNotIn?.map((e) => _$MoviePerFieldToJson.year(e)), ), $queryCursor: $queryCursor, ); @@ -956,15 +1021,26 @@ class _$MovieQuery extends QueryReference _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$MovieFieldMap['runtime']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: + isEqualTo != null ? _$MoviePerFieldToJson.runtime(isEqualTo) : null, + isNotEqualTo: isNotEqualTo != null + ? _$MoviePerFieldToJson.runtime(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$MoviePerFieldToJson.runtime(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$MoviePerFieldToJson.runtime(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$MoviePerFieldToJson.runtime(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$MoviePerFieldToJson.runtime(isGreaterThanOrEqualTo) + : null, isNull: isNull, - whereIn: whereIn, - whereNotIn: whereNotIn, + whereIn: whereIn?.map((e) => _$MoviePerFieldToJson.runtime(e)), + whereNotIn: whereNotIn?.map((e) => _$MoviePerFieldToJson.runtime(e)), ), $queryCursor: $queryCursor, ); @@ -985,15 +1061,25 @@ class _$MovieQuery extends QueryReference _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$MovieFieldMap['rated']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: + isEqualTo != null ? _$MoviePerFieldToJson.rated(isEqualTo) : null, + isNotEqualTo: isNotEqualTo != null + ? _$MoviePerFieldToJson.rated(isNotEqualTo) + : null, + isLessThan: + isLessThan != null ? _$MoviePerFieldToJson.rated(isLessThan) : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$MoviePerFieldToJson.rated(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$MoviePerFieldToJson.rated(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$MoviePerFieldToJson.rated(isGreaterThanOrEqualTo) + : null, isNull: isNull, - whereIn: whereIn, - whereNotIn: whereNotIn, + whereIn: whereIn?.map((e) => _$MoviePerFieldToJson.rated(e)), + whereNotIn: whereNotIn?.map((e) => _$MoviePerFieldToJson.rated(e)), ), $queryCursor: $queryCursor, ); @@ -1014,15 +1100,29 @@ class _$MovieQuery extends QueryReference _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$MovieFieldMap['genre']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: + isEqualTo != null ? _$MoviePerFieldToJson.genre(isEqualTo) : null, + isNotEqualTo: isNotEqualTo != null + ? _$MoviePerFieldToJson.genre(isNotEqualTo) + : null, + isLessThan: + isLessThan != null ? _$MoviePerFieldToJson.genre(isLessThan) : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$MoviePerFieldToJson.genre(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$MoviePerFieldToJson.genre(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$MoviePerFieldToJson.genre(isGreaterThanOrEqualTo) + : null, isNull: isNull, - arrayContains: arrayContains, - arrayContainsAny: arrayContainsAny, + arrayContains: arrayContains != null + ? (_$MoviePerFieldToJson.genre([arrayContains]) as List?)!.single + : null, + arrayContainsAny: arrayContainsAny != null + ? _$MoviePerFieldToJson.genre(arrayContainsAny) as Iterable? + : null, ), $queryCursor: $queryCursor, ); @@ -1043,15 +1143,29 @@ class _$MovieQuery extends QueryReference _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$MovieFieldMap['tags']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: + isEqualTo != null ? _$MoviePerFieldToJson.tags(isEqualTo) : null, + isNotEqualTo: isNotEqualTo != null + ? _$MoviePerFieldToJson.tags(isNotEqualTo) + : null, + isLessThan: + isLessThan != null ? _$MoviePerFieldToJson.tags(isLessThan) : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$MoviePerFieldToJson.tags(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$MoviePerFieldToJson.tags(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$MoviePerFieldToJson.tags(isGreaterThanOrEqualTo) + : null, isNull: isNull, - arrayContains: arrayContains, - arrayContainsAny: arrayContainsAny, + arrayContains: arrayContains != null + ? (_$MoviePerFieldToJson.tags({arrayContains}) as List?)!.single + : null, + arrayContainsAny: arrayContainsAny != null + ? _$MoviePerFieldToJson.tags(arrayContainsAny) as Iterable? + : null, ), $queryCursor: $queryCursor, ); @@ -1990,11 +2104,13 @@ class _$CommentDocumentReference ); final json = { if (authorName != _sentinel) - _$CommentFieldMap['authorName']!: authorName as String, + _$CommentFieldMap['authorName']!: + _$CommentPerFieldToJson.authorName(authorName as String), if (authorNameFieldValue != null) _$CommentFieldMap['authorName']!: authorNameFieldValue, if (message != _sentinel) - _$CommentFieldMap['message']!: message as String, + _$CommentFieldMap['message']!: + _$CommentPerFieldToJson.message(message as String), if (messageFieldValue != null) _$CommentFieldMap['message']!: messageFieldValue, }; @@ -2019,11 +2135,13 @@ class _$CommentDocumentReference ); final json = { if (authorName != _sentinel) - _$CommentFieldMap['authorName']!: authorName as String, + _$CommentFieldMap['authorName']!: + _$CommentPerFieldToJson.authorName(authorName as String), if (authorNameFieldValue != null) _$CommentFieldMap['authorName']!: authorNameFieldValue, if (message != _sentinel) - _$CommentFieldMap['message']!: message as String, + _$CommentFieldMap['message']!: + _$CommentPerFieldToJson.message(message as String), if (messageFieldValue != null) _$CommentFieldMap['message']!: messageFieldValue, }; @@ -2378,15 +2496,28 @@ class _$CommentQuery extends QueryReference _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$CommentFieldMap['authorName']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: isEqualTo != null + ? _$CommentPerFieldToJson.authorName(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$CommentPerFieldToJson.authorName(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$CommentPerFieldToJson.authorName(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$CommentPerFieldToJson.authorName(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$CommentPerFieldToJson.authorName(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$CommentPerFieldToJson.authorName(isGreaterThanOrEqualTo) + : null, isNull: isNull, - whereIn: whereIn, - whereNotIn: whereNotIn, + whereIn: whereIn?.map((e) => _$CommentPerFieldToJson.authorName(e)), + whereNotIn: + whereNotIn?.map((e) => _$CommentPerFieldToJson.authorName(e)), ), $queryCursor: $queryCursor, ); @@ -2407,15 +2538,27 @@ class _$CommentQuery extends QueryReference _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$CommentFieldMap['message']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: isEqualTo != null + ? _$CommentPerFieldToJson.message(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$CommentPerFieldToJson.message(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$CommentPerFieldToJson.message(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$CommentPerFieldToJson.message(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$CommentPerFieldToJson.message(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$CommentPerFieldToJson.message(isGreaterThanOrEqualTo) + : null, isNull: isNull, - whereIn: whereIn, - whereNotIn: whereNotIn, + whereIn: whereIn?.map((e) => _$CommentPerFieldToJson.message(e)), + whereNotIn: whereNotIn?.map((e) => _$CommentPerFieldToJson.message(e)), ), $queryCursor: $queryCursor, ); @@ -2769,6 +2912,28 @@ const _$MovieFieldMap = { 'tags': 'tags', }; +// ignore: unused_element +abstract class _$MoviePerFieldToJson { + // ignore: unused_element + static Object? id(String instance) => instance; + // ignore: unused_element + static Object? poster(String instance) => instance; + // ignore: unused_element + static Object? likes(int instance) => instance; + // ignore: unused_element + static Object? title(String instance) => instance; + // ignore: unused_element + static Object? year(int instance) => instance; + // ignore: unused_element + static Object? runtime(String instance) => instance; + // ignore: unused_element + static Object? rated(String instance) => instance; + // ignore: unused_element + static Object? genre(List? instance) => instance; + // ignore: unused_element + static Object? tags(Set? instance) => instance?.toList(); +} + Map _$MovieToJson(Movie instance) => { 'id': instance.id, 'poster': instance.poster, @@ -2791,6 +2956,14 @@ const _$CommentFieldMap = { 'message': 'message', }; +// ignore: unused_element +abstract class _$CommentPerFieldToJson { + // ignore: unused_element + static Object? authorName(String instance) => instance; + // ignore: unused_element + static Object? message(String instance) => instance; +} + Map _$CommentToJson(Comment instance) => { 'authorName': instance.authorName, 'message': instance.message, diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm_generator/build.yaml b/packages/cloud_firestore_odm/cloud_firestore_odm_generator/build.yaml index 4d648bdf2dd4..763e288ca067 100644 --- a/packages/cloud_firestore_odm/cloud_firestore_odm_generator/build.yaml +++ b/packages/cloud_firestore_odm/cloud_firestore_odm_generator/build.yaml @@ -6,6 +6,7 @@ targets: json_serializable: options: create_field_map: true + create_per_field_to_json: true builders: cloud_firestore_odm_generator: diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/build.yaml b/packages/cloud_firestore_odm/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/build.yaml index 7ba05383c0c5..d574b776055e 100644 --- a/packages/cloud_firestore_odm/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/build.yaml +++ b/packages/cloud_firestore_odm/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/build.yaml @@ -3,4 +3,5 @@ targets: builders: json_serializable: options: - create_field_map: true \ No newline at end of file + create_field_map: true + create_per_field_to_json: true \ No newline at end of file diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/lib/freezed.g.dart b/packages/cloud_firestore_odm/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/lib/freezed.g.dart index 70b2de101fb0..110cd87420a7 100644 --- a/packages/cloud_firestore_odm/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/lib/freezed.g.dart +++ b/packages/cloud_firestore_odm/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/lib/freezed.g.dart @@ -7,7 +7,7 @@ part of 'freezed.dart'; // ************************************************************************** // 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, require_trailing_commas, prefer_single_quotes, prefer_double_quotes, use_super_parameters +// 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, require_trailing_commas, prefer_single_quotes, prefer_double_quotes, use_super_parameters, duplicate_ignore class _Sentinel { const _Sentinel(); @@ -189,11 +189,13 @@ class _$PersonDocumentReference ); final json = { if (firstName != _sentinel) - _$$_PersonFieldMap['firstName']!: firstName as String, + _$$_PersonFieldMap['firstName']!: + _$$_PersonPerFieldToJson.firstName(firstName as String), if (firstNameFieldValue != null) _$$_PersonFieldMap['firstName']!: firstNameFieldValue, if (lastName != _sentinel) - _$$_PersonFieldMap['lastName']!: lastName as String, + _$$_PersonFieldMap['lastName']!: + _$$_PersonPerFieldToJson.lastName(lastName as String), if (lastNameFieldValue != null) _$$_PersonFieldMap['lastName']!: lastNameFieldValue, }; @@ -218,11 +220,13 @@ class _$PersonDocumentReference ); final json = { if (firstName != _sentinel) - _$$_PersonFieldMap['firstName']!: firstName as String, + _$$_PersonFieldMap['firstName']!: + _$$_PersonPerFieldToJson.firstName(firstName as String), if (firstNameFieldValue != null) _$$_PersonFieldMap['firstName']!: firstNameFieldValue, if (lastName != _sentinel) - _$$_PersonFieldMap['lastName']!: lastName as String, + _$$_PersonFieldMap['lastName']!: + _$$_PersonPerFieldToJson.lastName(lastName as String), if (lastNameFieldValue != null) _$$_PersonFieldMap['lastName']!: lastNameFieldValue, }; @@ -577,15 +581,28 @@ class _$PersonQuery extends QueryReference _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$$_PersonFieldMap['firstName']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: isEqualTo != null + ? _$$_PersonPerFieldToJson.firstName(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$$_PersonPerFieldToJson.firstName(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$$_PersonPerFieldToJson.firstName(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$$_PersonPerFieldToJson.firstName(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$$_PersonPerFieldToJson.firstName(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$$_PersonPerFieldToJson.firstName(isGreaterThanOrEqualTo) + : null, isNull: isNull, - whereIn: whereIn, - whereNotIn: whereNotIn, + whereIn: whereIn?.map((e) => _$$_PersonPerFieldToJson.firstName(e)), + whereNotIn: + whereNotIn?.map((e) => _$$_PersonPerFieldToJson.firstName(e)), ), $queryCursor: $queryCursor, ); @@ -606,15 +623,28 @@ class _$PersonQuery extends QueryReference _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$$_PersonFieldMap['lastName']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: isEqualTo != null + ? _$$_PersonPerFieldToJson.lastName(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$$_PersonPerFieldToJson.lastName(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$$_PersonPerFieldToJson.lastName(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$$_PersonPerFieldToJson.lastName(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$$_PersonPerFieldToJson.lastName(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$$_PersonPerFieldToJson.lastName(isGreaterThanOrEqualTo) + : null, isNull: isNull, - whereIn: whereIn, - whereNotIn: whereNotIn, + whereIn: whereIn?.map((e) => _$$_PersonPerFieldToJson.lastName(e)), + whereNotIn: + whereNotIn?.map((e) => _$$_PersonPerFieldToJson.lastName(e)), ), $queryCursor: $queryCursor, ); @@ -1100,7 +1130,8 @@ class _$PublicRedirectedDocumentReference extends FirestoreDocumentReference< ); final json = { if (value != _sentinel) - _$$PublicRedirected2FieldMap['value']!: value as String, + _$$PublicRedirected2FieldMap['value']!: + _$$PublicRedirected2PerFieldToJson.value(value as String), if (valueFieldValue != null) _$$PublicRedirected2FieldMap['value']!: valueFieldValue, }; @@ -1119,7 +1150,8 @@ class _$PublicRedirectedDocumentReference extends FirestoreDocumentReference< ); final json = { if (value != _sentinel) - _$$PublicRedirected2FieldMap['value']!: value as String, + _$$PublicRedirected2FieldMap['value']!: + _$$PublicRedirected2PerFieldToJson.value(value as String), if (valueFieldValue != null) _$$PublicRedirected2FieldMap['value']!: valueFieldValue, }; @@ -1456,15 +1488,29 @@ class _$PublicRedirectedQuery _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$$PublicRedirected2FieldMap['value']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: isEqualTo != null + ? _$$PublicRedirected2PerFieldToJson.value(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$$PublicRedirected2PerFieldToJson.value(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$$PublicRedirected2PerFieldToJson.value(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$$PublicRedirected2PerFieldToJson.value(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$$PublicRedirected2PerFieldToJson.value(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$$PublicRedirected2PerFieldToJson.value(isGreaterThanOrEqualTo) + : null, isNull: isNull, - whereIn: whereIn, - whereNotIn: whereNotIn, + whereIn: + whereIn?.map((e) => _$$PublicRedirected2PerFieldToJson.value(e)), + whereNotIn: + whereNotIn?.map((e) => _$$PublicRedirected2PerFieldToJson.value(e)), ), $queryCursor: $queryCursor, ); @@ -1728,6 +1774,14 @@ const _$$_PersonFieldMap = { 'lastName': 'LAST_NAME', }; +// ignore: unused_element +abstract class _$$_PersonPerFieldToJson { + // ignore: unused_element + static Object? firstName(String instance) => instance; + // ignore: unused_element + static Object? lastName(String instance) => instance; +} + Map _$$_PersonToJson(_$_Person instance) => { 'first_name': instance.firstName, 'LAST_NAME': instance.lastName, @@ -1742,6 +1796,12 @@ const _$$PublicRedirected2FieldMap = { 'value': 'value', }; +// ignore: unused_element +abstract class _$$PublicRedirected2PerFieldToJson { + // ignore: unused_element + static Object? value(String instance) => instance; +} + Map _$$PublicRedirected2ToJson(_$PublicRedirected2 instance) => { 'value': instance.value, diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/lib/model.dart b/packages/cloud_firestore_odm/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/lib/model.dart deleted file mode 100644 index 45860024dc9b..000000000000 --- a/packages/cloud_firestore_odm/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/lib/model.dart +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2022, the Chromium project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -// When separated accross multiple files, it is necessary to specify fromJson/toJson -// We voluntarily don't use JsonSerializable here, as it is not supported due to -// the generated FieldMap being private. -class SplitFileModel { - SplitFileModel(); - - // ignore: avoid_unused_constructor_parameters - factory SplitFileModel.fromJson(Map json) => - SplitFileModel(); - - Map toJson() => {}; -} diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/lib/simple.dart b/packages/cloud_firestore_odm/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/lib/simple.dart index 03b97776dc1b..c85ba19a0e34 100644 --- a/packages/cloud_firestore_odm/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/lib/simple.dart +++ b/packages/cloud_firestore_odm/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/lib/simple.dart @@ -6,8 +6,6 @@ import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:cloud_firestore_odm/cloud_firestore_odm.dart'; import 'package:json_annotation/json_annotation.dart'; -import 'model.dart'; - part 'simple.g.dart'; final ignoredGetterRef = IgnoredGetterCollectionReference(); @@ -35,6 +33,12 @@ class Model { final String value; } +enum TestEnum { + one, + two, + three; +} + @JsonSerializable() class Nested { Nested({ @@ -47,6 +51,10 @@ class Nested { required this.objectList, required this.dynamicList, required this.boolSet, + required this.enumValue, + required this.nullableEnumValue, + required this.enumList, + required this.nullableEnumList, }); factory Nested.fromJson(Map json) => _$NestedFromJson(json); @@ -62,14 +70,15 @@ class Nested { final List? objectList; final List? dynamicList; final Set? boolSet; + final TestEnum enumValue; + final TestEnum? nullableEnumValue; + final List enumList; + final List? nullableEnumList; } @Collection('nested') final nestedRef = NestedCollectionReference(); -@Collection('split-file') -final splitFileRef = SplitFileModelCollectionReference(); - @JsonSerializable() class EmptyModel { EmptyModel(); diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/lib/simple.g.dart b/packages/cloud_firestore_odm/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/lib/simple.g.dart index 2d56bb2bef68..a81c6d23a63e 100644 --- a/packages/cloud_firestore_odm/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/lib/simple.g.dart +++ b/packages/cloud_firestore_odm/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/lib/simple.g.dart @@ -7,7 +7,7 @@ part of 'simple.dart'; // ************************************************************************** // 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, require_trailing_commas, prefer_single_quotes, prefer_double_quotes, use_super_parameters +// 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, require_trailing_commas, prefer_single_quotes, prefer_double_quotes, use_super_parameters, duplicate_ignore class _Sentinel { const _Sentinel(); @@ -184,7 +184,9 @@ class _$IgnoredGetterDocumentReference extends FirestoreDocumentReference< "Cannot specify both value and valueFieldValue", ); final json = { - if (value != _sentinel) _$IgnoredGetterFieldMap['value']!: value as int, + if (value != _sentinel) + _$IgnoredGetterFieldMap['value']!: + _$IgnoredGetterPerFieldToJson.value(value as int), if (valueFieldValue != null) _$IgnoredGetterFieldMap['value']!: valueFieldValue, }; @@ -202,7 +204,9 @@ class _$IgnoredGetterDocumentReference extends FirestoreDocumentReference< "Cannot specify both value and valueFieldValue", ); final json = { - if (value != _sentinel) _$IgnoredGetterFieldMap['value']!: value as int, + if (value != _sentinel) + _$IgnoredGetterFieldMap['value']!: + _$IgnoredGetterPerFieldToJson.value(value as int), if (valueFieldValue != null) _$IgnoredGetterFieldMap['value']!: valueFieldValue, }; @@ -539,15 +543,28 @@ class _$IgnoredGetterQuery _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$IgnoredGetterFieldMap['value']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: isEqualTo != null + ? _$IgnoredGetterPerFieldToJson.value(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$IgnoredGetterPerFieldToJson.value(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$IgnoredGetterPerFieldToJson.value(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$IgnoredGetterPerFieldToJson.value(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$IgnoredGetterPerFieldToJson.value(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$IgnoredGetterPerFieldToJson.value(isGreaterThanOrEqualTo) + : null, isNull: isNull, - whereIn: whereIn, - whereNotIn: whereNotIn, + whereIn: whereIn?.map((e) => _$IgnoredGetterPerFieldToJson.value(e)), + whereNotIn: + whereNotIn?.map((e) => _$IgnoredGetterPerFieldToJson.value(e)), ), $queryCursor: $queryCursor, ); @@ -956,7 +973,8 @@ class _$ModelDocumentReference "Cannot specify both value and valueFieldValue", ); final json = { - if (value != _sentinel) _$ModelFieldMap['value']!: value as String, + if (value != _sentinel) + _$ModelFieldMap['value']!: _$ModelPerFieldToJson.value(value as String), if (valueFieldValue != null) _$ModelFieldMap['value']!: valueFieldValue, }; @@ -973,7 +991,8 @@ class _$ModelDocumentReference "Cannot specify both value and valueFieldValue", ); final json = { - if (value != _sentinel) _$ModelFieldMap['value']!: value as String, + if (value != _sentinel) + _$ModelFieldMap['value']!: _$ModelPerFieldToJson.value(value as String), if (valueFieldValue != null) _$ModelFieldMap['value']!: valueFieldValue, }; @@ -1303,15 +1322,25 @@ class _$ModelQuery extends QueryReference _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$ModelFieldMap['value']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: + isEqualTo != null ? _$ModelPerFieldToJson.value(isEqualTo) : null, + isNotEqualTo: isNotEqualTo != null + ? _$ModelPerFieldToJson.value(isNotEqualTo) + : null, + isLessThan: + isLessThan != null ? _$ModelPerFieldToJson.value(isLessThan) : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$ModelPerFieldToJson.value(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$ModelPerFieldToJson.value(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$ModelPerFieldToJson.value(isGreaterThanOrEqualTo) + : null, isNull: isNull, - whereIn: whereIn, - whereNotIn: whereNotIn, + whereIn: whereIn?.map((e) => _$ModelPerFieldToJson.value(e)), + whereNotIn: whereNotIn?.map((e) => _$ModelPerFieldToJson.value(e)), ), $queryCursor: $queryCursor, ); @@ -1666,8 +1695,12 @@ abstract class NestedDocumentReference /// /// If no document exists yet, the update will fail. Future update({ + Nested? value, + FieldValue valueFieldValue, int? simple, FieldValue simpleFieldValue, + List? valueList, + FieldValue valueListFieldValue, List? boolList, FieldValue boolListFieldValue, List? stringList, @@ -1680,6 +1713,14 @@ abstract class NestedDocumentReference FieldValue dynamicListFieldValue, Set? boolSet, FieldValue boolSetFieldValue, + TestEnum enumValue, + FieldValue enumValueFieldValue, + TestEnum? nullableEnumValue, + FieldValue nullableEnumValueFieldValue, + List enumList, + FieldValue enumListFieldValue, + List? nullableEnumList, + FieldValue nullableEnumListFieldValue, }); /// Updates fields in the current document using the transaction API. @@ -1687,8 +1728,12 @@ abstract class NestedDocumentReference /// The update will fail if applied to a document that does not exist. void transactionUpdate( Transaction transaction, { + Nested? value, + FieldValue valueFieldValue, int? simple, FieldValue simpleFieldValue, + List? valueList, + FieldValue valueListFieldValue, List? boolList, FieldValue boolListFieldValue, List? stringList, @@ -1701,6 +1746,14 @@ abstract class NestedDocumentReference FieldValue dynamicListFieldValue, Set? boolSet, FieldValue boolSetFieldValue, + TestEnum enumValue, + FieldValue enumValueFieldValue, + TestEnum? nullableEnumValue, + FieldValue nullableEnumValueFieldValue, + List enumList, + FieldValue enumListFieldValue, + List? nullableEnumList, + FieldValue nullableEnumListFieldValue, }); } @@ -1733,8 +1786,12 @@ class _$NestedDocumentReference } Future update({ + Object? value = _sentinel, + FieldValue? valueFieldValue, Object? simple = _sentinel, FieldValue? simpleFieldValue, + Object? valueList = _sentinel, + FieldValue? valueListFieldValue, Object? boolList = _sentinel, FieldValue? boolListFieldValue, Object? stringList = _sentinel, @@ -1747,11 +1804,27 @@ class _$NestedDocumentReference FieldValue? dynamicListFieldValue, Object? boolSet = _sentinel, FieldValue? boolSetFieldValue, + Object? enumValue = _sentinel, + FieldValue? enumValueFieldValue, + Object? nullableEnumValue = _sentinel, + FieldValue? nullableEnumValueFieldValue, + Object? enumList = _sentinel, + FieldValue? enumListFieldValue, + Object? nullableEnumList = _sentinel, + FieldValue? nullableEnumListFieldValue, }) async { + assert( + value == _sentinel || valueFieldValue == null, + "Cannot specify both value and valueFieldValue", + ); assert( simple == _sentinel || simpleFieldValue == null, "Cannot specify both simple and simpleFieldValue", ); + assert( + valueList == _sentinel || valueListFieldValue == null, + "Cannot specify both valueList and valueListFieldValue", + ); assert( boolList == _sentinel || boolListFieldValue == null, "Cannot specify both boolList and boolListFieldValue", @@ -1776,34 +1849,87 @@ class _$NestedDocumentReference boolSet == _sentinel || boolSetFieldValue == null, "Cannot specify both boolSet and boolSetFieldValue", ); + assert( + enumValue == _sentinel || enumValueFieldValue == null, + "Cannot specify both enumValue and enumValueFieldValue", + ); + assert( + nullableEnumValue == _sentinel || nullableEnumValueFieldValue == null, + "Cannot specify both nullableEnumValue and nullableEnumValueFieldValue", + ); + assert( + enumList == _sentinel || enumListFieldValue == null, + "Cannot specify both enumList and enumListFieldValue", + ); + assert( + nullableEnumList == _sentinel || nullableEnumListFieldValue == null, + "Cannot specify both nullableEnumList and nullableEnumListFieldValue", + ); final json = { - if (simple != _sentinel) _$NestedFieldMap['simple']!: simple as int?, + if (value != _sentinel) + _$NestedFieldMap['value']!: + _$NestedPerFieldToJson.value(value as Nested?), + if (valueFieldValue != null) _$NestedFieldMap['value']!: valueFieldValue, + if (simple != _sentinel) + _$NestedFieldMap['simple']!: + _$NestedPerFieldToJson.simple(simple as int?), if (simpleFieldValue != null) _$NestedFieldMap['simple']!: simpleFieldValue, + if (valueList != _sentinel) + _$NestedFieldMap['valueList']!: + _$NestedPerFieldToJson.valueList(valueList as List?), + if (valueListFieldValue != null) + _$NestedFieldMap['valueList']!: valueListFieldValue, if (boolList != _sentinel) - _$NestedFieldMap['boolList']!: boolList as List?, + _$NestedFieldMap['boolList']!: + _$NestedPerFieldToJson.boolList(boolList as List?), if (boolListFieldValue != null) _$NestedFieldMap['boolList']!: boolListFieldValue, if (stringList != _sentinel) - _$NestedFieldMap['stringList']!: stringList as List?, + _$NestedFieldMap['stringList']!: + _$NestedPerFieldToJson.stringList(stringList as List?), if (stringListFieldValue != null) _$NestedFieldMap['stringList']!: stringListFieldValue, if (numList != _sentinel) - _$NestedFieldMap['numList']!: numList as List?, + _$NestedFieldMap['numList']!: + _$NestedPerFieldToJson.numList(numList as List?), if (numListFieldValue != null) _$NestedFieldMap['numList']!: numListFieldValue, if (objectList != _sentinel) - _$NestedFieldMap['objectList']!: objectList as List?, + _$NestedFieldMap['objectList']!: + _$NestedPerFieldToJson.objectList(objectList as List?), if (objectListFieldValue != null) _$NestedFieldMap['objectList']!: objectListFieldValue, if (dynamicList != _sentinel) - _$NestedFieldMap['dynamicList']!: dynamicList as List?, + _$NestedFieldMap['dynamicList']!: + _$NestedPerFieldToJson.dynamicList(dynamicList as List?), if (dynamicListFieldValue != null) _$NestedFieldMap['dynamicList']!: dynamicListFieldValue, if (boolSet != _sentinel) - _$NestedFieldMap['boolSet']!: boolSet as Set?, + _$NestedFieldMap['boolSet']!: + _$NestedPerFieldToJson.boolSet(boolSet as Set?), if (boolSetFieldValue != null) _$NestedFieldMap['boolSet']!: boolSetFieldValue, + if (enumValue != _sentinel) + _$NestedFieldMap['enumValue']!: + _$NestedPerFieldToJson.enumValue(enumValue as TestEnum), + if (enumValueFieldValue != null) + _$NestedFieldMap['enumValue']!: enumValueFieldValue, + if (nullableEnumValue != _sentinel) + _$NestedFieldMap['nullableEnumValue']!: _$NestedPerFieldToJson + .nullableEnumValue(nullableEnumValue as TestEnum?), + if (nullableEnumValueFieldValue != null) + _$NestedFieldMap['nullableEnumValue']!: nullableEnumValueFieldValue, + if (enumList != _sentinel) + _$NestedFieldMap['enumList']!: + _$NestedPerFieldToJson.enumList(enumList as List), + if (enumListFieldValue != null) + _$NestedFieldMap['enumList']!: enumListFieldValue, + if (nullableEnumList != _sentinel) + _$NestedFieldMap['nullableEnumList']!: _$NestedPerFieldToJson + .nullableEnumList(nullableEnumList as List?), + if (nullableEnumListFieldValue != null) + _$NestedFieldMap['nullableEnumList']!: nullableEnumListFieldValue, }; return reference.update(json); @@ -1811,8 +1937,12 @@ class _$NestedDocumentReference void transactionUpdate( Transaction transaction, { + Object? value = _sentinel, + FieldValue? valueFieldValue, Object? simple = _sentinel, FieldValue? simpleFieldValue, + Object? valueList = _sentinel, + FieldValue? valueListFieldValue, Object? boolList = _sentinel, FieldValue? boolListFieldValue, Object? stringList = _sentinel, @@ -1825,11 +1955,27 @@ class _$NestedDocumentReference FieldValue? dynamicListFieldValue, Object? boolSet = _sentinel, FieldValue? boolSetFieldValue, + Object? enumValue = _sentinel, + FieldValue? enumValueFieldValue, + Object? nullableEnumValue = _sentinel, + FieldValue? nullableEnumValueFieldValue, + Object? enumList = _sentinel, + FieldValue? enumListFieldValue, + Object? nullableEnumList = _sentinel, + FieldValue? nullableEnumListFieldValue, }) { + assert( + value == _sentinel || valueFieldValue == null, + "Cannot specify both value and valueFieldValue", + ); assert( simple == _sentinel || simpleFieldValue == null, "Cannot specify both simple and simpleFieldValue", ); + assert( + valueList == _sentinel || valueListFieldValue == null, + "Cannot specify both valueList and valueListFieldValue", + ); assert( boolList == _sentinel || boolListFieldValue == null, "Cannot specify both boolList and boolListFieldValue", @@ -1854,34 +2000,87 @@ class _$NestedDocumentReference boolSet == _sentinel || boolSetFieldValue == null, "Cannot specify both boolSet and boolSetFieldValue", ); + assert( + enumValue == _sentinel || enumValueFieldValue == null, + "Cannot specify both enumValue and enumValueFieldValue", + ); + assert( + nullableEnumValue == _sentinel || nullableEnumValueFieldValue == null, + "Cannot specify both nullableEnumValue and nullableEnumValueFieldValue", + ); + assert( + enumList == _sentinel || enumListFieldValue == null, + "Cannot specify both enumList and enumListFieldValue", + ); + assert( + nullableEnumList == _sentinel || nullableEnumListFieldValue == null, + "Cannot specify both nullableEnumList and nullableEnumListFieldValue", + ); final json = { - if (simple != _sentinel) _$NestedFieldMap['simple']!: simple as int?, + if (value != _sentinel) + _$NestedFieldMap['value']!: + _$NestedPerFieldToJson.value(value as Nested?), + if (valueFieldValue != null) _$NestedFieldMap['value']!: valueFieldValue, + if (simple != _sentinel) + _$NestedFieldMap['simple']!: + _$NestedPerFieldToJson.simple(simple as int?), if (simpleFieldValue != null) _$NestedFieldMap['simple']!: simpleFieldValue, + if (valueList != _sentinel) + _$NestedFieldMap['valueList']!: + _$NestedPerFieldToJson.valueList(valueList as List?), + if (valueListFieldValue != null) + _$NestedFieldMap['valueList']!: valueListFieldValue, if (boolList != _sentinel) - _$NestedFieldMap['boolList']!: boolList as List?, + _$NestedFieldMap['boolList']!: + _$NestedPerFieldToJson.boolList(boolList as List?), if (boolListFieldValue != null) _$NestedFieldMap['boolList']!: boolListFieldValue, if (stringList != _sentinel) - _$NestedFieldMap['stringList']!: stringList as List?, + _$NestedFieldMap['stringList']!: + _$NestedPerFieldToJson.stringList(stringList as List?), if (stringListFieldValue != null) _$NestedFieldMap['stringList']!: stringListFieldValue, if (numList != _sentinel) - _$NestedFieldMap['numList']!: numList as List?, + _$NestedFieldMap['numList']!: + _$NestedPerFieldToJson.numList(numList as List?), if (numListFieldValue != null) _$NestedFieldMap['numList']!: numListFieldValue, if (objectList != _sentinel) - _$NestedFieldMap['objectList']!: objectList as List?, + _$NestedFieldMap['objectList']!: + _$NestedPerFieldToJson.objectList(objectList as List?), if (objectListFieldValue != null) _$NestedFieldMap['objectList']!: objectListFieldValue, if (dynamicList != _sentinel) - _$NestedFieldMap['dynamicList']!: dynamicList as List?, + _$NestedFieldMap['dynamicList']!: + _$NestedPerFieldToJson.dynamicList(dynamicList as List?), if (dynamicListFieldValue != null) _$NestedFieldMap['dynamicList']!: dynamicListFieldValue, if (boolSet != _sentinel) - _$NestedFieldMap['boolSet']!: boolSet as Set?, + _$NestedFieldMap['boolSet']!: + _$NestedPerFieldToJson.boolSet(boolSet as Set?), if (boolSetFieldValue != null) _$NestedFieldMap['boolSet']!: boolSetFieldValue, + if (enumValue != _sentinel) + _$NestedFieldMap['enumValue']!: + _$NestedPerFieldToJson.enumValue(enumValue as TestEnum), + if (enumValueFieldValue != null) + _$NestedFieldMap['enumValue']!: enumValueFieldValue, + if (nullableEnumValue != _sentinel) + _$NestedFieldMap['nullableEnumValue']!: _$NestedPerFieldToJson + .nullableEnumValue(nullableEnumValue as TestEnum?), + if (nullableEnumValueFieldValue != null) + _$NestedFieldMap['nullableEnumValue']!: nullableEnumValueFieldValue, + if (enumList != _sentinel) + _$NestedFieldMap['enumList']!: + _$NestedPerFieldToJson.enumList(enumList as List), + if (enumListFieldValue != null) + _$NestedFieldMap['enumList']!: enumListFieldValue, + if (nullableEnumList != _sentinel) + _$NestedFieldMap['nullableEnumList']!: _$NestedPerFieldToJson + .nullableEnumList(nullableEnumList as List?), + if (nullableEnumListFieldValue != null) + _$NestedFieldMap['nullableEnumList']!: nullableEnumListFieldValue, }; transaction.update(reference, json); @@ -1983,6 +2182,17 @@ abstract class NestedQuery List? whereIn, List? whereNotIn, }); + NestedQuery whereValue({ + Nested? isEqualTo, + Nested? isNotEqualTo, + Nested? isLessThan, + Nested? isLessThanOrEqualTo, + Nested? isGreaterThan, + Nested? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }); NestedQuery whereSimple({ int? isEqualTo, int? isNotEqualTo, @@ -1994,6 +2204,17 @@ abstract class NestedQuery List? whereIn, List? whereNotIn, }); + NestedQuery whereValueList({ + List? isEqualTo, + List? isNotEqualTo, + List? isLessThan, + List? isLessThanOrEqualTo, + List? isGreaterThan, + List? isGreaterThanOrEqualTo, + bool? isNull, + Nested? arrayContains, + List? arrayContainsAny, + }); NestedQuery whereBoolList({ List? isEqualTo, List? isNotEqualTo, @@ -2060,6 +2281,50 @@ abstract class NestedQuery bool? arrayContains, Set? arrayContainsAny, }); + NestedQuery whereEnumValue({ + TestEnum? isEqualTo, + TestEnum? isNotEqualTo, + TestEnum? isLessThan, + TestEnum? isLessThanOrEqualTo, + TestEnum? isGreaterThan, + TestEnum? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }); + NestedQuery whereNullableEnumValue({ + TestEnum? isEqualTo, + TestEnum? isNotEqualTo, + TestEnum? isLessThan, + TestEnum? isLessThanOrEqualTo, + TestEnum? isGreaterThan, + TestEnum? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }); + NestedQuery whereEnumList({ + List? isEqualTo, + List? isNotEqualTo, + List? isLessThan, + List? isLessThanOrEqualTo, + List? isGreaterThan, + List? isGreaterThanOrEqualTo, + bool? isNull, + TestEnum? arrayContains, + List? arrayContainsAny, + }); + NestedQuery whereNullableEnumList({ + List? isEqualTo, + List? isNotEqualTo, + List? isLessThan, + List? isLessThanOrEqualTo, + List? isGreaterThan, + List? isGreaterThanOrEqualTo, + bool? isNull, + TestEnum? arrayContains, + List? arrayContainsAny, + }); NestedQuery orderByDocumentId({ bool descending = false, @@ -2073,6 +2338,18 @@ abstract class NestedQuery NestedDocumentSnapshot? startAfterDocument, }); + NestedQuery orderByValue({ + bool descending = false, + Nested? startAt, + Nested? startAfter, + Nested? endAt, + Nested? endBefore, + NestedDocumentSnapshot? startAtDocument, + NestedDocumentSnapshot? endAtDocument, + NestedDocumentSnapshot? endBeforeDocument, + NestedDocumentSnapshot? startAfterDocument, + }); + NestedQuery orderBySimple({ bool descending = false, int? startAt, @@ -2085,6 +2362,18 @@ abstract class NestedQuery NestedDocumentSnapshot? startAfterDocument, }); + NestedQuery orderByValueList({ + bool descending = false, + List? startAt, + List? startAfter, + List? endAt, + List? endBefore, + NestedDocumentSnapshot? startAtDocument, + NestedDocumentSnapshot? endAtDocument, + NestedDocumentSnapshot? endBeforeDocument, + NestedDocumentSnapshot? startAfterDocument, + }); + NestedQuery orderByBoolList({ bool descending = false, List? startAt, @@ -2156,6 +2445,54 @@ abstract class NestedQuery NestedDocumentSnapshot? endBeforeDocument, NestedDocumentSnapshot? startAfterDocument, }); + + NestedQuery orderByEnumValue({ + bool descending = false, + TestEnum startAt, + TestEnum startAfter, + TestEnum endAt, + TestEnum endBefore, + NestedDocumentSnapshot? startAtDocument, + NestedDocumentSnapshot? endAtDocument, + NestedDocumentSnapshot? endBeforeDocument, + NestedDocumentSnapshot? startAfterDocument, + }); + + NestedQuery orderByNullableEnumValue({ + bool descending = false, + TestEnum? startAt, + TestEnum? startAfter, + TestEnum? endAt, + TestEnum? endBefore, + NestedDocumentSnapshot? startAtDocument, + NestedDocumentSnapshot? endAtDocument, + NestedDocumentSnapshot? endBeforeDocument, + NestedDocumentSnapshot? startAfterDocument, + }); + + NestedQuery orderByEnumList({ + bool descending = false, + List startAt, + List startAfter, + List endAt, + List endBefore, + NestedDocumentSnapshot? startAtDocument, + NestedDocumentSnapshot? endAtDocument, + NestedDocumentSnapshot? endBeforeDocument, + NestedDocumentSnapshot? startAfterDocument, + }); + + NestedQuery orderByNullableEnumList({ + bool descending = false, + List? startAt, + List? startAfter, + List? endAt, + List? endBefore, + NestedDocumentSnapshot? startAtDocument, + NestedDocumentSnapshot? endAtDocument, + NestedDocumentSnapshot? endBeforeDocument, + NestedDocumentSnapshot? startAfterDocument, + }); } class _$NestedQuery extends QueryReference @@ -2334,6 +2671,46 @@ class _$NestedQuery extends QueryReference ); } + NestedQuery whereValue({ + Nested? isEqualTo, + Nested? isNotEqualTo, + Nested? isLessThan, + Nested? isLessThanOrEqualTo, + Nested? isGreaterThan, + Nested? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }) { + return _$NestedQuery( + _collection, + $referenceWithoutCursor: $referenceWithoutCursor.where( + _$NestedFieldMap['value']!, + isEqualTo: + isEqualTo != null ? _$NestedPerFieldToJson.value(isEqualTo) : null, + isNotEqualTo: isNotEqualTo != null + ? _$NestedPerFieldToJson.value(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$NestedPerFieldToJson.value(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$NestedPerFieldToJson.value(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$NestedPerFieldToJson.value(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$NestedPerFieldToJson.value(isGreaterThanOrEqualTo) + : null, + isNull: isNull, + whereIn: whereIn?.map((e) => _$NestedPerFieldToJson.value(e)), + whereNotIn: whereNotIn?.map((e) => _$NestedPerFieldToJson.value(e)), + ), + $queryCursor: $queryCursor, + ); + } + NestedQuery whereSimple({ int? isEqualTo, int? isNotEqualTo, @@ -2349,15 +2726,73 @@ class _$NestedQuery extends QueryReference _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$NestedFieldMap['simple']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: + isEqualTo != null ? _$NestedPerFieldToJson.simple(isEqualTo) : null, + isNotEqualTo: isNotEqualTo != null + ? _$NestedPerFieldToJson.simple(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$NestedPerFieldToJson.simple(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$NestedPerFieldToJson.simple(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$NestedPerFieldToJson.simple(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$NestedPerFieldToJson.simple(isGreaterThanOrEqualTo) + : null, isNull: isNull, - whereIn: whereIn, - whereNotIn: whereNotIn, + whereIn: whereIn?.map((e) => _$NestedPerFieldToJson.simple(e)), + whereNotIn: whereNotIn?.map((e) => _$NestedPerFieldToJson.simple(e)), + ), + $queryCursor: $queryCursor, + ); + } + + NestedQuery whereValueList({ + List? isEqualTo, + List? isNotEqualTo, + List? isLessThan, + List? isLessThanOrEqualTo, + List? isGreaterThan, + List? isGreaterThanOrEqualTo, + bool? isNull, + Nested? arrayContains, + List? arrayContainsAny, + }) { + return _$NestedQuery( + _collection, + $referenceWithoutCursor: $referenceWithoutCursor.where( + _$NestedFieldMap['valueList']!, + isEqualTo: isEqualTo != null + ? _$NestedPerFieldToJson.valueList(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$NestedPerFieldToJson.valueList(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$NestedPerFieldToJson.valueList(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$NestedPerFieldToJson.valueList(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$NestedPerFieldToJson.valueList(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$NestedPerFieldToJson.valueList(isGreaterThanOrEqualTo) + : null, + isNull: isNull, + arrayContains: arrayContains != null + ? (_$NestedPerFieldToJson.valueList([arrayContains]) as List?)! + .single + : null, + arrayContainsAny: arrayContainsAny != null + ? _$NestedPerFieldToJson.valueList(arrayContainsAny) + as Iterable? + : null, ), $queryCursor: $queryCursor, ); @@ -2378,15 +2813,33 @@ class _$NestedQuery extends QueryReference _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$NestedFieldMap['boolList']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: isEqualTo != null + ? _$NestedPerFieldToJson.boolList(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$NestedPerFieldToJson.boolList(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$NestedPerFieldToJson.boolList(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$NestedPerFieldToJson.boolList(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$NestedPerFieldToJson.boolList(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$NestedPerFieldToJson.boolList(isGreaterThanOrEqualTo) + : null, isNull: isNull, - arrayContains: arrayContains, - arrayContainsAny: arrayContainsAny, + arrayContains: arrayContains != null + ? (_$NestedPerFieldToJson.boolList([arrayContains]) as List?)! + .single + : null, + arrayContainsAny: arrayContainsAny != null + ? _$NestedPerFieldToJson.boolList(arrayContainsAny) + as Iterable? + : null, ), $queryCursor: $queryCursor, ); @@ -2407,15 +2860,33 @@ class _$NestedQuery extends QueryReference _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$NestedFieldMap['stringList']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: isEqualTo != null + ? _$NestedPerFieldToJson.stringList(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$NestedPerFieldToJson.stringList(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$NestedPerFieldToJson.stringList(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$NestedPerFieldToJson.stringList(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$NestedPerFieldToJson.stringList(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$NestedPerFieldToJson.stringList(isGreaterThanOrEqualTo) + : null, isNull: isNull, - arrayContains: arrayContains, - arrayContainsAny: arrayContainsAny, + arrayContains: arrayContains != null + ? (_$NestedPerFieldToJson.stringList([arrayContains]) as List?)! + .single + : null, + arrayContainsAny: arrayContainsAny != null + ? _$NestedPerFieldToJson.stringList(arrayContainsAny) + as Iterable? + : null, ), $queryCursor: $queryCursor, ); @@ -2436,15 +2907,32 @@ class _$NestedQuery extends QueryReference _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$NestedFieldMap['numList']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: isEqualTo != null + ? _$NestedPerFieldToJson.numList(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$NestedPerFieldToJson.numList(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$NestedPerFieldToJson.numList(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$NestedPerFieldToJson.numList(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$NestedPerFieldToJson.numList(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$NestedPerFieldToJson.numList(isGreaterThanOrEqualTo) + : null, isNull: isNull, - arrayContains: arrayContains, - arrayContainsAny: arrayContainsAny, + arrayContains: arrayContains != null + ? (_$NestedPerFieldToJson.numList([arrayContains]) as List?)!.single + : null, + arrayContainsAny: arrayContainsAny != null + ? _$NestedPerFieldToJson.numList(arrayContainsAny) + as Iterable? + : null, ), $queryCursor: $queryCursor, ); @@ -2465,15 +2953,33 @@ class _$NestedQuery extends QueryReference _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$NestedFieldMap['objectList']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: isEqualTo != null + ? _$NestedPerFieldToJson.objectList(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$NestedPerFieldToJson.objectList(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$NestedPerFieldToJson.objectList(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$NestedPerFieldToJson.objectList(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$NestedPerFieldToJson.objectList(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$NestedPerFieldToJson.objectList(isGreaterThanOrEqualTo) + : null, isNull: isNull, - arrayContains: arrayContains, - arrayContainsAny: arrayContainsAny, + arrayContains: arrayContains != null + ? (_$NestedPerFieldToJson.objectList([arrayContains]) as List?)! + .single + : null, + arrayContainsAny: arrayContainsAny != null + ? _$NestedPerFieldToJson.objectList(arrayContainsAny) + as Iterable? + : null, ), $queryCursor: $queryCursor, ); @@ -2494,15 +3000,33 @@ class _$NestedQuery extends QueryReference _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$NestedFieldMap['dynamicList']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: isEqualTo != null + ? _$NestedPerFieldToJson.dynamicList(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$NestedPerFieldToJson.dynamicList(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$NestedPerFieldToJson.dynamicList(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$NestedPerFieldToJson.dynamicList(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$NestedPerFieldToJson.dynamicList(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$NestedPerFieldToJson.dynamicList(isGreaterThanOrEqualTo) + : null, isNull: isNull, - arrayContains: arrayContains, - arrayContainsAny: arrayContainsAny, + arrayContains: arrayContains != null + ? (_$NestedPerFieldToJson.dynamicList([arrayContains]) as List?)! + .single + : null, + arrayContainsAny: arrayContainsAny != null + ? _$NestedPerFieldToJson.dynamicList(arrayContainsAny) + as Iterable? + : null, ), $queryCursor: $queryCursor, ); @@ -2523,15 +3047,211 @@ class _$NestedQuery extends QueryReference _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$NestedFieldMap['boolSet']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: isEqualTo != null + ? _$NestedPerFieldToJson.boolSet(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$NestedPerFieldToJson.boolSet(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$NestedPerFieldToJson.boolSet(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$NestedPerFieldToJson.boolSet(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$NestedPerFieldToJson.boolSet(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$NestedPerFieldToJson.boolSet(isGreaterThanOrEqualTo) + : null, isNull: isNull, - arrayContains: arrayContains, - arrayContainsAny: arrayContainsAny, + arrayContains: arrayContains != null + ? (_$NestedPerFieldToJson.boolSet({arrayContains}) as List?)!.single + : null, + arrayContainsAny: arrayContainsAny != null + ? _$NestedPerFieldToJson.boolSet(arrayContainsAny) + as Iterable? + : null, + ), + $queryCursor: $queryCursor, + ); + } + + NestedQuery whereEnumValue({ + TestEnum? isEqualTo, + TestEnum? isNotEqualTo, + TestEnum? isLessThan, + TestEnum? isLessThanOrEqualTo, + TestEnum? isGreaterThan, + TestEnum? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }) { + return _$NestedQuery( + _collection, + $referenceWithoutCursor: $referenceWithoutCursor.where( + _$NestedFieldMap['enumValue']!, + isEqualTo: isEqualTo != null + ? _$NestedPerFieldToJson.enumValue(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$NestedPerFieldToJson.enumValue(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$NestedPerFieldToJson.enumValue(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$NestedPerFieldToJson.enumValue(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$NestedPerFieldToJson.enumValue(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$NestedPerFieldToJson.enumValue(isGreaterThanOrEqualTo) + : null, + isNull: isNull, + whereIn: whereIn?.map((e) => _$NestedPerFieldToJson.enumValue(e)), + whereNotIn: whereNotIn?.map((e) => _$NestedPerFieldToJson.enumValue(e)), + ), + $queryCursor: $queryCursor, + ); + } + + NestedQuery whereNullableEnumValue({ + TestEnum? isEqualTo, + TestEnum? isNotEqualTo, + TestEnum? isLessThan, + TestEnum? isLessThanOrEqualTo, + TestEnum? isGreaterThan, + TestEnum? isGreaterThanOrEqualTo, + bool? isNull, + List? whereIn, + List? whereNotIn, + }) { + return _$NestedQuery( + _collection, + $referenceWithoutCursor: $referenceWithoutCursor.where( + _$NestedFieldMap['nullableEnumValue']!, + isEqualTo: isEqualTo != null + ? _$NestedPerFieldToJson.nullableEnumValue(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$NestedPerFieldToJson.nullableEnumValue(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$NestedPerFieldToJson.nullableEnumValue(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$NestedPerFieldToJson.nullableEnumValue(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$NestedPerFieldToJson.nullableEnumValue(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$NestedPerFieldToJson.nullableEnumValue(isGreaterThanOrEqualTo) + : null, + isNull: isNull, + whereIn: + whereIn?.map((e) => _$NestedPerFieldToJson.nullableEnumValue(e)), + whereNotIn: + whereNotIn?.map((e) => _$NestedPerFieldToJson.nullableEnumValue(e)), + ), + $queryCursor: $queryCursor, + ); + } + + NestedQuery whereEnumList({ + List? isEqualTo, + List? isNotEqualTo, + List? isLessThan, + List? isLessThanOrEqualTo, + List? isGreaterThan, + List? isGreaterThanOrEqualTo, + bool? isNull, + TestEnum? arrayContains, + List? arrayContainsAny, + }) { + return _$NestedQuery( + _collection, + $referenceWithoutCursor: $referenceWithoutCursor.where( + _$NestedFieldMap['enumList']!, + isEqualTo: isEqualTo != null + ? _$NestedPerFieldToJson.enumList(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$NestedPerFieldToJson.enumList(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$NestedPerFieldToJson.enumList(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$NestedPerFieldToJson.enumList(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$NestedPerFieldToJson.enumList(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$NestedPerFieldToJson.enumList(isGreaterThanOrEqualTo) + : null, + isNull: isNull, + arrayContains: arrayContains != null + ? (_$NestedPerFieldToJson.enumList([arrayContains]) as List?)! + .single + : null, + arrayContainsAny: arrayContainsAny != null + ? _$NestedPerFieldToJson.enumList(arrayContainsAny) + as Iterable? + : null, + ), + $queryCursor: $queryCursor, + ); + } + + NestedQuery whereNullableEnumList({ + List? isEqualTo, + List? isNotEqualTo, + List? isLessThan, + List? isLessThanOrEqualTo, + List? isGreaterThan, + List? isGreaterThanOrEqualTo, + bool? isNull, + TestEnum? arrayContains, + List? arrayContainsAny, + }) { + return _$NestedQuery( + _collection, + $referenceWithoutCursor: $referenceWithoutCursor.where( + _$NestedFieldMap['nullableEnumList']!, + isEqualTo: isEqualTo != null + ? _$NestedPerFieldToJson.nullableEnumList(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$NestedPerFieldToJson.nullableEnumList(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$NestedPerFieldToJson.nullableEnumList(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$NestedPerFieldToJson.nullableEnumList(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$NestedPerFieldToJson.nullableEnumList(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$NestedPerFieldToJson.nullableEnumList(isGreaterThanOrEqualTo) + : null, + isNull: isNull, + arrayContains: arrayContains != null + ? (_$NestedPerFieldToJson.nullableEnumList([arrayContains]) + as List?)! + .single + : null, + arrayContainsAny: arrayContainsAny != null + ? _$NestedPerFieldToJson.nullableEnumList(arrayContainsAny) + as Iterable? + : null, ), $queryCursor: $queryCursor, ); @@ -2609,7 +3329,7 @@ class _$NestedQuery extends QueryReference ); } - NestedQuery orderBySimple({ + NestedQuery orderByValue({ bool descending = false, Object? startAt = _sentinel, Object? startAfter = _sentinel, @@ -2620,7 +3340,7 @@ class _$NestedQuery extends QueryReference NestedDocumentSnapshot? endBeforeDocument, NestedDocumentSnapshot? startAfterDocument, }) { - final query = $referenceWithoutCursor.orderBy(_$NestedFieldMap['simple']!, + final query = $referenceWithoutCursor.orderBy(_$NestedFieldMap['value']!, descending: descending); var queryCursor = $queryCursor; @@ -2681,7 +3401,7 @@ class _$NestedQuery extends QueryReference ); } - NestedQuery orderByBoolList({ + NestedQuery orderBySimple({ bool descending = false, Object? startAt = _sentinel, Object? startAfter = _sentinel, @@ -2692,7 +3412,7 @@ class _$NestedQuery extends QueryReference NestedDocumentSnapshot? endBeforeDocument, NestedDocumentSnapshot? startAfterDocument, }) { - final query = $referenceWithoutCursor.orderBy(_$NestedFieldMap['boolList']!, + final query = $referenceWithoutCursor.orderBy(_$NestedFieldMap['simple']!, descending: descending); var queryCursor = $queryCursor; @@ -2753,7 +3473,7 @@ class _$NestedQuery extends QueryReference ); } - NestedQuery orderByStringList({ + NestedQuery orderByValueList({ bool descending = false, Object? startAt = _sentinel, Object? startAfter = _sentinel, @@ -2765,7 +3485,7 @@ class _$NestedQuery extends QueryReference NestedDocumentSnapshot? startAfterDocument, }) { final query = $referenceWithoutCursor - .orderBy(_$NestedFieldMap['stringList']!, descending: descending); + .orderBy(_$NestedFieldMap['valueList']!, descending: descending); var queryCursor = $queryCursor; if (startAtDocument != null) { @@ -2825,7 +3545,7 @@ class _$NestedQuery extends QueryReference ); } - NestedQuery orderByNumList({ + NestedQuery orderByBoolList({ bool descending = false, Object? startAt = _sentinel, Object? startAfter = _sentinel, @@ -2836,7 +3556,7 @@ class _$NestedQuery extends QueryReference NestedDocumentSnapshot? endBeforeDocument, NestedDocumentSnapshot? startAfterDocument, }) { - final query = $referenceWithoutCursor.orderBy(_$NestedFieldMap['numList']!, + final query = $referenceWithoutCursor.orderBy(_$NestedFieldMap['boolList']!, descending: descending); var queryCursor = $queryCursor; @@ -2897,7 +3617,7 @@ class _$NestedQuery extends QueryReference ); } - NestedQuery orderByObjectList({ + NestedQuery orderByStringList({ bool descending = false, Object? startAt = _sentinel, Object? startAfter = _sentinel, @@ -2909,7 +3629,7 @@ class _$NestedQuery extends QueryReference NestedDocumentSnapshot? startAfterDocument, }) { final query = $referenceWithoutCursor - .orderBy(_$NestedFieldMap['objectList']!, descending: descending); + .orderBy(_$NestedFieldMap['stringList']!, descending: descending); var queryCursor = $queryCursor; if (startAtDocument != null) { @@ -2969,7 +3689,7 @@ class _$NestedQuery extends QueryReference ); } - NestedQuery orderByDynamicList({ + NestedQuery orderByNumList({ bool descending = false, Object? startAt = _sentinel, Object? startAfter = _sentinel, @@ -2980,8 +3700,8 @@ class _$NestedQuery extends QueryReference NestedDocumentSnapshot? endBeforeDocument, NestedDocumentSnapshot? startAfterDocument, }) { - final query = $referenceWithoutCursor - .orderBy(_$NestedFieldMap['dynamicList']!, descending: descending); + final query = $referenceWithoutCursor.orderBy(_$NestedFieldMap['numList']!, + descending: descending); var queryCursor = $queryCursor; if (startAtDocument != null) { @@ -3041,7 +3761,7 @@ class _$NestedQuery extends QueryReference ); } - NestedQuery orderByBoolSet({ + NestedQuery orderByObjectList({ bool descending = false, Object? startAt = _sentinel, Object? startAfter = _sentinel, @@ -3052,8 +3772,8 @@ class _$NestedQuery extends QueryReference NestedDocumentSnapshot? endBeforeDocument, NestedDocumentSnapshot? startAfterDocument, }) { - final query = $referenceWithoutCursor.orderBy(_$NestedFieldMap['boolSet']!, - descending: descending); + final query = $referenceWithoutCursor + .orderBy(_$NestedFieldMap['objectList']!, descending: descending); var queryCursor = $queryCursor; if (startAtDocument != null) { @@ -3113,411 +3833,308 @@ class _$NestedQuery extends QueryReference ); } - @override - bool operator ==(Object other) { - return other is _$NestedQuery && - other.runtimeType == runtimeType && - other.reference == reference; - } - - @override - int get hashCode => Object.hash(runtimeType, reference); -} + NestedQuery orderByDynamicList({ + bool descending = false, + Object? startAt = _sentinel, + Object? startAfter = _sentinel, + Object? endAt = _sentinel, + Object? endBefore = _sentinel, + NestedDocumentSnapshot? startAtDocument, + NestedDocumentSnapshot? endAtDocument, + NestedDocumentSnapshot? endBeforeDocument, + NestedDocumentSnapshot? startAfterDocument, + }) { + final query = $referenceWithoutCursor + .orderBy(_$NestedFieldMap['dynamicList']!, descending: descending); + var queryCursor = $queryCursor; -class NestedDocumentSnapshot extends FirestoreDocumentSnapshot { - NestedDocumentSnapshot._(this.snapshot) : data = snapshot.data(); + if (startAtDocument != null) { + queryCursor = queryCursor.copyWith( + startAt: const [], + startAtDocumentSnapshot: startAtDocument.snapshot, + ); + } + if (startAfterDocument != null) { + queryCursor = queryCursor.copyWith( + startAfter: const [], + startAfterDocumentSnapshot: startAfterDocument.snapshot, + ); + } + if (endAtDocument != null) { + queryCursor = queryCursor.copyWith( + endAt: const [], + endAtDocumentSnapshot: endAtDocument.snapshot, + ); + } + if (endBeforeDocument != null) { + queryCursor = queryCursor.copyWith( + endBefore: const [], + endBeforeDocumentSnapshot: endBeforeDocument.snapshot, + ); + } - @override - final DocumentSnapshot snapshot; + if (startAt != _sentinel) { + queryCursor = queryCursor.copyWith( + startAt: [...queryCursor.startAt, startAt], + startAtDocumentSnapshot: null, + ); + } + if (startAfter != _sentinel) { + queryCursor = queryCursor.copyWith( + startAfter: [...queryCursor.startAfter, startAfter], + startAfterDocumentSnapshot: null, + ); + } + if (endAt != _sentinel) { + queryCursor = queryCursor.copyWith( + endAt: [...queryCursor.endAt, endAt], + endAtDocumentSnapshot: null, + ); + } + if (endBefore != _sentinel) { + queryCursor = queryCursor.copyWith( + endBefore: [...queryCursor.endBefore, endBefore], + endBeforeDocumentSnapshot: null, + ); + } - @override - NestedDocumentReference get reference { - return NestedDocumentReference( - snapshot.reference, + return _$NestedQuery( + _collection, + $referenceWithoutCursor: query, + $queryCursor: queryCursor, ); } - @override - final Nested? data; -} - -class NestedQuerySnapshot - extends FirestoreQuerySnapshot { - NestedQuerySnapshot._( - this.snapshot, - this.docs, - this.docChanges, - ); - - factory NestedQuerySnapshot._fromQuerySnapshot( - QuerySnapshot snapshot, - ) { - final docs = snapshot.docs.map(NestedQueryDocumentSnapshot._).toList(); + NestedQuery orderByBoolSet({ + bool descending = false, + Object? startAt = _sentinel, + Object? startAfter = _sentinel, + Object? endAt = _sentinel, + Object? endBefore = _sentinel, + NestedDocumentSnapshot? startAtDocument, + NestedDocumentSnapshot? endAtDocument, + NestedDocumentSnapshot? endBeforeDocument, + NestedDocumentSnapshot? startAfterDocument, + }) { + final query = $referenceWithoutCursor.orderBy(_$NestedFieldMap['boolSet']!, + descending: descending); + var queryCursor = $queryCursor; - final docChanges = snapshot.docChanges.map((change) { - return _decodeDocumentChange( - change, - NestedDocumentSnapshot._, + if (startAtDocument != null) { + queryCursor = queryCursor.copyWith( + startAt: const [], + startAtDocumentSnapshot: startAtDocument.snapshot, ); - }).toList(); + } + if (startAfterDocument != null) { + queryCursor = queryCursor.copyWith( + startAfter: const [], + startAfterDocumentSnapshot: startAfterDocument.snapshot, + ); + } + if (endAtDocument != null) { + queryCursor = queryCursor.copyWith( + endAt: const [], + endAtDocumentSnapshot: endAtDocument.snapshot, + ); + } + if (endBeforeDocument != null) { + queryCursor = queryCursor.copyWith( + endBefore: const [], + endBeforeDocumentSnapshot: endBeforeDocument.snapshot, + ); + } - return NestedQuerySnapshot._( - snapshot, - docs, - docChanges, - ); - } + if (startAt != _sentinel) { + queryCursor = queryCursor.copyWith( + startAt: [...queryCursor.startAt, startAt], + startAtDocumentSnapshot: null, + ); + } + if (startAfter != _sentinel) { + queryCursor = queryCursor.copyWith( + startAfter: [...queryCursor.startAfter, startAfter], + startAfterDocumentSnapshot: null, + ); + } + if (endAt != _sentinel) { + queryCursor = queryCursor.copyWith( + endAt: [...queryCursor.endAt, endAt], + endAtDocumentSnapshot: null, + ); + } + if (endBefore != _sentinel) { + queryCursor = queryCursor.copyWith( + endBefore: [...queryCursor.endBefore, endBefore], + endBeforeDocumentSnapshot: null, + ); + } - static FirestoreDocumentChange - _decodeDocumentChange( - DocumentChange docChange, - NestedDocumentSnapshot Function(DocumentSnapshot doc) decodeDoc, - ) { - return FirestoreDocumentChange( - type: docChange.type, - oldIndex: docChange.oldIndex, - newIndex: docChange.newIndex, - doc: decodeDoc(docChange.doc), + return _$NestedQuery( + _collection, + $referenceWithoutCursor: query, + $queryCursor: queryCursor, ); } - final QuerySnapshot snapshot; + NestedQuery orderByEnumValue({ + bool descending = false, + Object? startAt = _sentinel, + Object? startAfter = _sentinel, + Object? endAt = _sentinel, + Object? endBefore = _sentinel, + NestedDocumentSnapshot? startAtDocument, + NestedDocumentSnapshot? endAtDocument, + NestedDocumentSnapshot? endBeforeDocument, + NestedDocumentSnapshot? startAfterDocument, + }) { + final query = $referenceWithoutCursor + .orderBy(_$NestedFieldMap['enumValue']!, descending: descending); + var queryCursor = $queryCursor; - @override - final List docs; + if (startAtDocument != null) { + queryCursor = queryCursor.copyWith( + startAt: const [], + startAtDocumentSnapshot: startAtDocument.snapshot, + ); + } + if (startAfterDocument != null) { + queryCursor = queryCursor.copyWith( + startAfter: const [], + startAfterDocumentSnapshot: startAfterDocument.snapshot, + ); + } + if (endAtDocument != null) { + queryCursor = queryCursor.copyWith( + endAt: const [], + endAtDocumentSnapshot: endAtDocument.snapshot, + ); + } + if (endBeforeDocument != null) { + queryCursor = queryCursor.copyWith( + endBefore: const [], + endBeforeDocumentSnapshot: endBeforeDocument.snapshot, + ); + } - @override - final List> docChanges; -} + if (startAt != _sentinel) { + queryCursor = queryCursor.copyWith( + startAt: [...queryCursor.startAt, startAt], + startAtDocumentSnapshot: null, + ); + } + if (startAfter != _sentinel) { + queryCursor = queryCursor.copyWith( + startAfter: [...queryCursor.startAfter, startAfter], + startAfterDocumentSnapshot: null, + ); + } + if (endAt != _sentinel) { + queryCursor = queryCursor.copyWith( + endAt: [...queryCursor.endAt, endAt], + endAtDocumentSnapshot: null, + ); + } + if (endBefore != _sentinel) { + queryCursor = queryCursor.copyWith( + endBefore: [...queryCursor.endBefore, endBefore], + endBeforeDocumentSnapshot: null, + ); + } -class NestedQueryDocumentSnapshot extends FirestoreQueryDocumentSnapshot - implements NestedDocumentSnapshot { - NestedQueryDocumentSnapshot._(this.snapshot) : data = snapshot.data(); - - @override - final QueryDocumentSnapshot snapshot; - - @override - final Nested data; - - @override - NestedDocumentReference get reference { - return NestedDocumentReference(snapshot.reference); - } -} - -/// 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 SplitFileModelCollectionReference - implements - SplitFileModelQuery, - FirestoreCollectionReference { - factory SplitFileModelCollectionReference([ - FirebaseFirestore? firestore, - ]) = _$SplitFileModelCollectionReference; - - static SplitFileModel fromFirestore( - DocumentSnapshot> snapshot, - SnapshotOptions? options, - ) { - return SplitFileModel.fromJson(snapshot.data()!); - } - - static Map toFirestore( - SplitFileModel value, - SetOptions? options, - ) { - return value.toJson(); - } - - @override - CollectionReference get reference; - - @override - SplitFileModelDocumentReference doc([String? id]); - - /// Add a new document to this collection with the specified data, - /// assigning it a document ID automatically. - Future add(SplitFileModel value); -} - -class _$SplitFileModelCollectionReference extends _$SplitFileModelQuery - implements SplitFileModelCollectionReference { - factory _$SplitFileModelCollectionReference([FirebaseFirestore? firestore]) { - firestore ??= FirebaseFirestore.instance; - - return _$SplitFileModelCollectionReference._( - firestore.collection('split-file').withConverter( - fromFirestore: SplitFileModelCollectionReference.fromFirestore, - toFirestore: SplitFileModelCollectionReference.toFirestore, - ), - ); - } - - _$SplitFileModelCollectionReference._( - CollectionReference reference, - ) : super(reference, $referenceWithoutCursor: reference); - - String get path => reference.path; - - @override - CollectionReference get reference => - super.reference as CollectionReference; - - @override - SplitFileModelDocumentReference doc([String? id]) { - assert( - id == null || id.split('/').length == 1, - 'The document ID cannot be from a different collection', - ); - return SplitFileModelDocumentReference( - reference.doc(id), + return _$NestedQuery( + _collection, + $referenceWithoutCursor: query, + $queryCursor: queryCursor, ); } - @override - Future add(SplitFileModel value) { - return reference - .add(value) - .then((ref) => SplitFileModelDocumentReference(ref)); - } - - @override - bool operator ==(Object other) { - return other is _$SplitFileModelCollectionReference && - other.runtimeType == runtimeType && - other.reference == reference; - } - - @override - int get hashCode => Object.hash(runtimeType, reference); -} - -abstract class SplitFileModelDocumentReference - extends FirestoreDocumentReference { - factory SplitFileModelDocumentReference( - DocumentReference reference) = - _$SplitFileModelDocumentReference; - - DocumentReference get reference; - - /// A reference to the [SplitFileModelCollectionReference] containing this document. - SplitFileModelCollectionReference get parent { - return _$SplitFileModelCollectionReference(reference.firestore); - } - - @override - Stream snapshots(); - - @override - Future get([GetOptions? options]); - - @override - Future delete(); -} - -class _$SplitFileModelDocumentReference extends FirestoreDocumentReference< - SplitFileModel, - SplitFileModelDocumentSnapshot> implements SplitFileModelDocumentReference { - _$SplitFileModelDocumentReference(this.reference); - - @override - final DocumentReference reference; - - /// A reference to the [SplitFileModelCollectionReference] containing this document. - SplitFileModelCollectionReference get parent { - return _$SplitFileModelCollectionReference(reference.firestore); - } - - @override - Stream snapshots() { - return reference.snapshots().map(SplitFileModelDocumentSnapshot._); - } - - @override - Future get([GetOptions? options]) { - return reference.get(options).then(SplitFileModelDocumentSnapshot._); - } - - @override - Future transactionGet( - Transaction transaction) { - return transaction.get(reference).then(SplitFileModelDocumentSnapshot._); - } - - @override - bool operator ==(Object other) { - return other is SplitFileModelDocumentReference && - other.runtimeType == runtimeType && - other.parent == parent && - other.id == id; - } - - @override - int get hashCode => Object.hash(runtimeType, parent, id); -} - -abstract class SplitFileModelQuery - implements QueryReference { - @override - SplitFileModelQuery limit(int limit); - - @override - SplitFileModelQuery limitToLast(int limit); - - /// Perform an order query based on a [FieldPath]. - /// - /// This method is considered unsafe as it does check that the field path - /// maps to a valid property or that parameters such as [isEqualTo] receive - /// a value of the correct type. - /// - /// If possible, instead use the more explicit variant of order queries: - /// - /// **AVOID**: - /// ```dart - /// collection.orderByFieldPath( - /// FieldPath.fromString('title'), - /// startAt: 'title', - /// ); - /// ``` - /// - /// **PREFER**: - /// ```dart - /// collection.orderByTitle(startAt: 'title'); - /// ``` - SplitFileModelQuery orderByFieldPath( - FieldPath fieldPath, { + NestedQuery orderByNullableEnumValue({ bool descending = false, - Object? startAt, - Object? startAfter, - Object? endAt, - Object? endBefore, - SplitFileModelDocumentSnapshot? startAtDocument, - SplitFileModelDocumentSnapshot? endAtDocument, - SplitFileModelDocumentSnapshot? endBeforeDocument, - SplitFileModelDocumentSnapshot? startAfterDocument, - }); - - /// Perform a where query based on a [FieldPath]. - /// - /// This method is considered unsafe as it does check that the field path - /// maps to a valid property or that parameters such as [isEqualTo] receive - /// a value of the correct type. - /// - /// If possible, instead use the more explicit variant of where queries: - /// - /// **AVOID**: - /// ```dart - /// collection.whereFieldPath(FieldPath.fromString('title'), isEqualTo: 'title'); - /// ``` - /// - /// **PREFER**: - /// ```dart - /// collection.whereTitle(isEqualTo: 'title'); - /// ``` - SplitFileModelQuery whereFieldPath( - FieldPath fieldPath, { - Object? isEqualTo, - Object? isNotEqualTo, - Object? isLessThan, - Object? isLessThanOrEqualTo, - Object? isGreaterThan, - Object? isGreaterThanOrEqualTo, - Object? arrayContains, - List? arrayContainsAny, - List? whereIn, - List? whereNotIn, - bool? isNull, - }); - - SplitFileModelQuery whereDocumentId({ - String? isEqualTo, - String? isNotEqualTo, - String? isLessThan, - String? isLessThanOrEqualTo, - String? isGreaterThan, - String? isGreaterThanOrEqualTo, - bool? isNull, - List? whereIn, - List? whereNotIn, - }); - - SplitFileModelQuery orderByDocumentId({ - bool descending = false, - String startAt, - String startAfter, - String endAt, - String endBefore, - SplitFileModelDocumentSnapshot? startAtDocument, - SplitFileModelDocumentSnapshot? endAtDocument, - SplitFileModelDocumentSnapshot? endBeforeDocument, - SplitFileModelDocumentSnapshot? startAfterDocument, - }); -} - -class _$SplitFileModelQuery - extends QueryReference - implements SplitFileModelQuery { - _$SplitFileModelQuery( - this._collection, { - required Query $referenceWithoutCursor, - $QueryCursor $queryCursor = const $QueryCursor(), - }) : super( - $referenceWithoutCursor: $referenceWithoutCursor, - $queryCursor: $queryCursor, - ); - - final CollectionReference _collection; - - @override - Stream snapshots([SnapshotOptions? options]) { - return reference - .snapshots() - .map(SplitFileModelQuerySnapshot._fromQuerySnapshot); - } + Object? startAt = _sentinel, + Object? startAfter = _sentinel, + Object? endAt = _sentinel, + Object? endBefore = _sentinel, + NestedDocumentSnapshot? startAtDocument, + NestedDocumentSnapshot? endAtDocument, + NestedDocumentSnapshot? endBeforeDocument, + NestedDocumentSnapshot? startAfterDocument, + }) { + final query = $referenceWithoutCursor.orderBy( + _$NestedFieldMap['nullableEnumValue']!, + descending: descending); + var queryCursor = $queryCursor; - @override - Future get([GetOptions? options]) { - return reference - .get(options) - .then(SplitFileModelQuerySnapshot._fromQuerySnapshot); - } + if (startAtDocument != null) { + queryCursor = queryCursor.copyWith( + startAt: const [], + startAtDocumentSnapshot: startAtDocument.snapshot, + ); + } + if (startAfterDocument != null) { + queryCursor = queryCursor.copyWith( + startAfter: const [], + startAfterDocumentSnapshot: startAfterDocument.snapshot, + ); + } + if (endAtDocument != null) { + queryCursor = queryCursor.copyWith( + endAt: const [], + endAtDocumentSnapshot: endAtDocument.snapshot, + ); + } + if (endBeforeDocument != null) { + queryCursor = queryCursor.copyWith( + endBefore: const [], + endBeforeDocumentSnapshot: endBeforeDocument.snapshot, + ); + } - @override - SplitFileModelQuery limit(int limit) { - return _$SplitFileModelQuery( - _collection, - $referenceWithoutCursor: $referenceWithoutCursor.limit(limit), - $queryCursor: $queryCursor, - ); - } + if (startAt != _sentinel) { + queryCursor = queryCursor.copyWith( + startAt: [...queryCursor.startAt, startAt], + startAtDocumentSnapshot: null, + ); + } + if (startAfter != _sentinel) { + queryCursor = queryCursor.copyWith( + startAfter: [...queryCursor.startAfter, startAfter], + startAfterDocumentSnapshot: null, + ); + } + if (endAt != _sentinel) { + queryCursor = queryCursor.copyWith( + endAt: [...queryCursor.endAt, endAt], + endAtDocumentSnapshot: null, + ); + } + if (endBefore != _sentinel) { + queryCursor = queryCursor.copyWith( + endBefore: [...queryCursor.endBefore, endBefore], + endBeforeDocumentSnapshot: null, + ); + } - @override - SplitFileModelQuery limitToLast(int limit) { - return _$SplitFileModelQuery( + return _$NestedQuery( _collection, - $referenceWithoutCursor: $referenceWithoutCursor.limitToLast(limit), - $queryCursor: $queryCursor, + $referenceWithoutCursor: query, + $queryCursor: queryCursor, ); } - SplitFileModelQuery orderByFieldPath( - FieldPath fieldPath, { + NestedQuery orderByEnumList({ bool descending = false, Object? startAt = _sentinel, Object? startAfter = _sentinel, Object? endAt = _sentinel, Object? endBefore = _sentinel, - SplitFileModelDocumentSnapshot? startAtDocument, - SplitFileModelDocumentSnapshot? endAtDocument, - SplitFileModelDocumentSnapshot? endBeforeDocument, - SplitFileModelDocumentSnapshot? startAfterDocument, + NestedDocumentSnapshot? startAtDocument, + NestedDocumentSnapshot? endAtDocument, + NestedDocumentSnapshot? endBeforeDocument, + NestedDocumentSnapshot? startAfterDocument, }) { - final query = - $referenceWithoutCursor.orderBy(fieldPath, descending: descending); + final query = $referenceWithoutCursor.orderBy(_$NestedFieldMap['enumList']!, + descending: descending); var queryCursor = $queryCursor; if (startAtDocument != null) { @@ -3569,89 +4186,27 @@ class _$SplitFileModelQuery endBeforeDocumentSnapshot: null, ); } - return _$SplitFileModelQuery( + + return _$NestedQuery( _collection, $referenceWithoutCursor: query, $queryCursor: queryCursor, ); } - SplitFileModelQuery whereFieldPath( - FieldPath fieldPath, { - Object? isEqualTo, - Object? isNotEqualTo, - Object? isLessThan, - Object? isLessThanOrEqualTo, - Object? isGreaterThan, - Object? isGreaterThanOrEqualTo, - Object? arrayContains, - List? arrayContainsAny, - List? whereIn, - List? whereNotIn, - bool? isNull, - }) { - return _$SplitFileModelQuery( - _collection, - $referenceWithoutCursor: $referenceWithoutCursor.where( - fieldPath, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, - arrayContains: arrayContains, - arrayContainsAny: arrayContainsAny, - whereIn: whereIn, - whereNotIn: whereNotIn, - isNull: isNull, - ), - $queryCursor: $queryCursor, - ); - } - - SplitFileModelQuery whereDocumentId({ - String? isEqualTo, - String? isNotEqualTo, - String? isLessThan, - String? isLessThanOrEqualTo, - String? isGreaterThan, - String? isGreaterThanOrEqualTo, - bool? isNull, - List? whereIn, - List? whereNotIn, - }) { - return _$SplitFileModelQuery( - _collection, - $referenceWithoutCursor: $referenceWithoutCursor.where( - FieldPath.documentId, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, - isNull: isNull, - whereIn: whereIn, - whereNotIn: whereNotIn, - ), - $queryCursor: $queryCursor, - ); - } - - SplitFileModelQuery orderByDocumentId({ + NestedQuery orderByNullableEnumList({ bool descending = false, Object? startAt = _sentinel, Object? startAfter = _sentinel, Object? endAt = _sentinel, Object? endBefore = _sentinel, - SplitFileModelDocumentSnapshot? startAtDocument, - SplitFileModelDocumentSnapshot? endAtDocument, - SplitFileModelDocumentSnapshot? endBeforeDocument, - SplitFileModelDocumentSnapshot? startAfterDocument, + NestedDocumentSnapshot? startAtDocument, + NestedDocumentSnapshot? endAtDocument, + NestedDocumentSnapshot? endBeforeDocument, + NestedDocumentSnapshot? startAfterDocument, }) { - final query = $referenceWithoutCursor.orderBy(FieldPath.documentId, - descending: descending); + final query = $referenceWithoutCursor + .orderBy(_$NestedFieldMap['nullableEnumList']!, descending: descending); var queryCursor = $queryCursor; if (startAtDocument != null) { @@ -3704,7 +4259,7 @@ class _$SplitFileModelQuery ); } - return _$SplitFileModelQuery( + return _$NestedQuery( _collection, $referenceWithoutCursor: query, $queryCursor: queryCursor, @@ -3713,7 +4268,7 @@ class _$SplitFileModelQuery @override bool operator ==(Object other) { - return other is _$SplitFileModelQuery && + return other is _$NestedQuery && other.runtimeType == runtimeType && other.reference == reference; } @@ -3722,58 +4277,56 @@ class _$SplitFileModelQuery int get hashCode => Object.hash(runtimeType, reference); } -class SplitFileModelDocumentSnapshot - extends FirestoreDocumentSnapshot { - SplitFileModelDocumentSnapshot._(this.snapshot) : data = snapshot.data(); +class NestedDocumentSnapshot extends FirestoreDocumentSnapshot { + NestedDocumentSnapshot._(this.snapshot) : data = snapshot.data(); @override - final DocumentSnapshot snapshot; + final DocumentSnapshot snapshot; @override - SplitFileModelDocumentReference get reference { - return SplitFileModelDocumentReference( + NestedDocumentReference get reference { + return NestedDocumentReference( snapshot.reference, ); } @override - final SplitFileModel? data; + final Nested? data; } -class SplitFileModelQuerySnapshot extends FirestoreQuerySnapshot { - SplitFileModelQuerySnapshot._( +class NestedQuerySnapshot + extends FirestoreQuerySnapshot { + NestedQuerySnapshot._( this.snapshot, this.docs, this.docChanges, ); - factory SplitFileModelQuerySnapshot._fromQuerySnapshot( - QuerySnapshot snapshot, + factory NestedQuerySnapshot._fromQuerySnapshot( + QuerySnapshot snapshot, ) { - final docs = - snapshot.docs.map(SplitFileModelQueryDocumentSnapshot._).toList(); + final docs = snapshot.docs.map(NestedQueryDocumentSnapshot._).toList(); final docChanges = snapshot.docChanges.map((change) { return _decodeDocumentChange( change, - SplitFileModelDocumentSnapshot._, + NestedDocumentSnapshot._, ); }).toList(); - return SplitFileModelQuerySnapshot._( + return NestedQuerySnapshot._( snapshot, docs, docChanges, ); } - static FirestoreDocumentChange + static FirestoreDocumentChange _decodeDocumentChange( DocumentChange docChange, - SplitFileModelDocumentSnapshot Function(DocumentSnapshot doc) decodeDoc, + NestedDocumentSnapshot Function(DocumentSnapshot doc) decodeDoc, ) { - return FirestoreDocumentChange( + return FirestoreDocumentChange( type: docChange.type, oldIndex: docChange.oldIndex, newIndex: docChange.newIndex, @@ -3781,30 +4334,28 @@ class SplitFileModelQuerySnapshot extends FirestoreQuerySnapshot snapshot; + final QuerySnapshot snapshot; @override - final List docs; + final List docs; @override - final List> - docChanges; + final List> docChanges; } -class SplitFileModelQueryDocumentSnapshot - extends FirestoreQueryDocumentSnapshot - implements SplitFileModelDocumentSnapshot { - SplitFileModelQueryDocumentSnapshot._(this.snapshot) : data = snapshot.data(); +class NestedQueryDocumentSnapshot extends FirestoreQueryDocumentSnapshot + implements NestedDocumentSnapshot { + NestedQueryDocumentSnapshot._(this.snapshot) : data = snapshot.data(); @override - final QueryDocumentSnapshot snapshot; + final QueryDocumentSnapshot snapshot; @override - final SplitFileModel data; + final Nested data; @override - SplitFileModelDocumentReference get reference { - return SplitFileModelDocumentReference(snapshot.reference); + NestedDocumentReference get reference { + return NestedDocumentReference(snapshot.reference); } } @@ -4567,7 +5118,9 @@ class _$OptionalJsonDocumentReference extends FirestoreDocumentReference< "Cannot specify both value and valueFieldValue", ); final json = { - if (value != _sentinel) _$OptionalJsonFieldMap['value']!: value as int, + if (value != _sentinel) + _$OptionalJsonFieldMap['value']!: + _$OptionalJsonPerFieldToJson.value(value as int), if (valueFieldValue != null) _$OptionalJsonFieldMap['value']!: valueFieldValue, }; @@ -4585,7 +5138,9 @@ class _$OptionalJsonDocumentReference extends FirestoreDocumentReference< "Cannot specify both value and valueFieldValue", ); final json = { - if (value != _sentinel) _$OptionalJsonFieldMap['value']!: value as int, + if (value != _sentinel) + _$OptionalJsonFieldMap['value']!: + _$OptionalJsonPerFieldToJson.value(value as int), if (valueFieldValue != null) _$OptionalJsonFieldMap['value']!: valueFieldValue, }; @@ -4922,15 +5477,28 @@ class _$OptionalJsonQuery _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$OptionalJsonFieldMap['value']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: isEqualTo != null + ? _$OptionalJsonPerFieldToJson.value(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$OptionalJsonPerFieldToJson.value(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$OptionalJsonPerFieldToJson.value(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$OptionalJsonPerFieldToJson.value(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$OptionalJsonPerFieldToJson.value(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$OptionalJsonPerFieldToJson.value(isGreaterThanOrEqualTo) + : null, isNull: isNull, - whereIn: whereIn, - whereNotIn: whereNotIn, + whereIn: whereIn?.map((e) => _$OptionalJsonPerFieldToJson.value(e)), + whereNotIn: + whereNotIn?.map((e) => _$OptionalJsonPerFieldToJson.value(e)), ), $queryCursor: $queryCursor, ); @@ -5339,7 +5907,9 @@ class _$MixedJsonDocumentReference "Cannot specify both value and valueFieldValue", ); final json = { - if (value != _sentinel) _$MixedJsonFieldMap['value']!: value as int, + if (value != _sentinel) + _$MixedJsonFieldMap['value']!: + _$MixedJsonPerFieldToJson.value(value as int), if (valueFieldValue != null) _$MixedJsonFieldMap['value']!: valueFieldValue, }; @@ -5357,7 +5927,9 @@ class _$MixedJsonDocumentReference "Cannot specify both value and valueFieldValue", ); final json = { - if (value != _sentinel) _$MixedJsonFieldMap['value']!: value as int, + if (value != _sentinel) + _$MixedJsonFieldMap['value']!: + _$MixedJsonPerFieldToJson.value(value as int), if (valueFieldValue != null) _$MixedJsonFieldMap['value']!: valueFieldValue, }; @@ -5691,15 +6263,27 @@ class _$MixedJsonQuery extends QueryReference _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$MixedJsonFieldMap['value']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: isEqualTo != null + ? _$MixedJsonPerFieldToJson.value(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$MixedJsonPerFieldToJson.value(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$MixedJsonPerFieldToJson.value(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$MixedJsonPerFieldToJson.value(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$MixedJsonPerFieldToJson.value(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$MixedJsonPerFieldToJson.value(isGreaterThanOrEqualTo) + : null, isNull: isNull, - whereIn: whereIn, - whereNotIn: whereNotIn, + whereIn: whereIn?.map((e) => _$MixedJsonPerFieldToJson.value(e)), + whereNotIn: whereNotIn?.map((e) => _$MixedJsonPerFieldToJson.value(e)), ), $queryCursor: $queryCursor, ); @@ -6155,10 +6739,13 @@ class _$RootDocumentReference ); final json = { if (nonNullable != _sentinel) - _$RootFieldMap['nonNullable']!: nonNullable as String, + _$RootFieldMap['nonNullable']!: + _$RootPerFieldToJson.nonNullable(nonNullable as String), if (nonNullableFieldValue != null) _$RootFieldMap['nonNullable']!: nonNullableFieldValue, - if (nullable != _sentinel) _$RootFieldMap['nullable']!: nullable as int?, + if (nullable != _sentinel) + _$RootFieldMap['nullable']!: + _$RootPerFieldToJson.nullable(nullable as int?), if (nullableFieldValue != null) _$RootFieldMap['nullable']!: nullableFieldValue, }; @@ -6183,10 +6770,13 @@ class _$RootDocumentReference ); final json = { if (nonNullable != _sentinel) - _$RootFieldMap['nonNullable']!: nonNullable as String, + _$RootFieldMap['nonNullable']!: + _$RootPerFieldToJson.nonNullable(nonNullable as String), if (nonNullableFieldValue != null) _$RootFieldMap['nonNullable']!: nonNullableFieldValue, - if (nullable != _sentinel) _$RootFieldMap['nullable']!: nullable as int?, + if (nullable != _sentinel) + _$RootFieldMap['nullable']!: + _$RootPerFieldToJson.nullable(nullable as int?), if (nullableFieldValue != null) _$RootFieldMap['nullable']!: nullableFieldValue, }; @@ -6540,15 +7130,27 @@ class _$RootQuery extends QueryReference _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$RootFieldMap['nonNullable']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: isEqualTo != null + ? _$RootPerFieldToJson.nonNullable(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$RootPerFieldToJson.nonNullable(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$RootPerFieldToJson.nonNullable(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$RootPerFieldToJson.nonNullable(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$RootPerFieldToJson.nonNullable(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$RootPerFieldToJson.nonNullable(isGreaterThanOrEqualTo) + : null, isNull: isNull, - whereIn: whereIn, - whereNotIn: whereNotIn, + whereIn: whereIn?.map((e) => _$RootPerFieldToJson.nonNullable(e)), + whereNotIn: whereNotIn?.map((e) => _$RootPerFieldToJson.nonNullable(e)), ), $queryCursor: $queryCursor, ); @@ -6569,15 +7171,26 @@ class _$RootQuery extends QueryReference _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$RootFieldMap['nullable']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: + isEqualTo != null ? _$RootPerFieldToJson.nullable(isEqualTo) : null, + isNotEqualTo: isNotEqualTo != null + ? _$RootPerFieldToJson.nullable(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$RootPerFieldToJson.nullable(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$RootPerFieldToJson.nullable(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$RootPerFieldToJson.nullable(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$RootPerFieldToJson.nullable(isGreaterThanOrEqualTo) + : null, isNull: isNull, - whereIn: whereIn, - whereNotIn: whereNotIn, + whereIn: whereIn?.map((e) => _$RootPerFieldToJson.nullable(e)), + whereNotIn: whereNotIn?.map((e) => _$RootPerFieldToJson.nullable(e)), ), $queryCursor: $queryCursor, ); @@ -7081,10 +7694,13 @@ class _$SubDocumentReference ); final json = { if (nonNullable != _sentinel) - _$SubFieldMap['nonNullable']!: nonNullable as String, + _$SubFieldMap['nonNullable']!: + _$SubPerFieldToJson.nonNullable(nonNullable as String), if (nonNullableFieldValue != null) _$SubFieldMap['nonNullable']!: nonNullableFieldValue, - if (nullable != _sentinel) _$SubFieldMap['nullable']!: nullable as int?, + if (nullable != _sentinel) + _$SubFieldMap['nullable']!: + _$SubPerFieldToJson.nullable(nullable as int?), if (nullableFieldValue != null) _$SubFieldMap['nullable']!: nullableFieldValue, }; @@ -7109,10 +7725,13 @@ class _$SubDocumentReference ); final json = { if (nonNullable != _sentinel) - _$SubFieldMap['nonNullable']!: nonNullable as String, + _$SubFieldMap['nonNullable']!: + _$SubPerFieldToJson.nonNullable(nonNullable as String), if (nonNullableFieldValue != null) _$SubFieldMap['nonNullable']!: nonNullableFieldValue, - if (nullable != _sentinel) _$SubFieldMap['nullable']!: nullable as int?, + if (nullable != _sentinel) + _$SubFieldMap['nullable']!: + _$SubPerFieldToJson.nullable(nullable as int?), if (nullableFieldValue != null) _$SubFieldMap['nullable']!: nullableFieldValue, }; @@ -7466,15 +8085,27 @@ class _$SubQuery extends QueryReference _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$SubFieldMap['nonNullable']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: isEqualTo != null + ? _$SubPerFieldToJson.nonNullable(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$SubPerFieldToJson.nonNullable(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$SubPerFieldToJson.nonNullable(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$SubPerFieldToJson.nonNullable(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$SubPerFieldToJson.nonNullable(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$SubPerFieldToJson.nonNullable(isGreaterThanOrEqualTo) + : null, isNull: isNull, - whereIn: whereIn, - whereNotIn: whereNotIn, + whereIn: whereIn?.map((e) => _$SubPerFieldToJson.nonNullable(e)), + whereNotIn: whereNotIn?.map((e) => _$SubPerFieldToJson.nonNullable(e)), ), $queryCursor: $queryCursor, ); @@ -7495,15 +8126,26 @@ class _$SubQuery extends QueryReference _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$SubFieldMap['nullable']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: + isEqualTo != null ? _$SubPerFieldToJson.nullable(isEqualTo) : null, + isNotEqualTo: isNotEqualTo != null + ? _$SubPerFieldToJson.nullable(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$SubPerFieldToJson.nullable(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$SubPerFieldToJson.nullable(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$SubPerFieldToJson.nullable(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$SubPerFieldToJson.nullable(isGreaterThanOrEqualTo) + : null, isNull: isNull, - whereIn: whereIn, - whereNotIn: whereNotIn, + whereIn: whereIn?.map((e) => _$SubPerFieldToJson.nullable(e)), + whereNotIn: whereNotIn?.map((e) => _$SubPerFieldToJson.nullable(e)), ), $queryCursor: $queryCursor, ); @@ -8001,7 +8643,9 @@ class _$AsCamelCaseDocumentReference "Cannot specify both value and valueFieldValue", ); final json = { - if (value != _sentinel) _$AsCamelCaseFieldMap['value']!: value as num, + if (value != _sentinel) + _$AsCamelCaseFieldMap['value']!: + _$AsCamelCasePerFieldToJson.value(value as num), if (valueFieldValue != null) _$AsCamelCaseFieldMap['value']!: valueFieldValue, }; @@ -8019,7 +8663,9 @@ class _$AsCamelCaseDocumentReference "Cannot specify both value and valueFieldValue", ); final json = { - if (value != _sentinel) _$AsCamelCaseFieldMap['value']!: value as num, + if (value != _sentinel) + _$AsCamelCaseFieldMap['value']!: + _$AsCamelCasePerFieldToJson.value(value as num), if (valueFieldValue != null) _$AsCamelCaseFieldMap['value']!: valueFieldValue, }; @@ -8356,15 +9002,28 @@ class _$AsCamelCaseQuery _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$AsCamelCaseFieldMap['value']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: isEqualTo != null + ? _$AsCamelCasePerFieldToJson.value(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$AsCamelCasePerFieldToJson.value(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$AsCamelCasePerFieldToJson.value(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$AsCamelCasePerFieldToJson.value(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$AsCamelCasePerFieldToJson.value(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$AsCamelCasePerFieldToJson.value(isGreaterThanOrEqualTo) + : null, isNull: isNull, - whereIn: whereIn, - whereNotIn: whereNotIn, + whereIn: whereIn?.map((e) => _$AsCamelCasePerFieldToJson.value(e)), + whereNotIn: + whereNotIn?.map((e) => _$AsCamelCasePerFieldToJson.value(e)), ), $queryCursor: $queryCursor, ); @@ -8796,7 +9455,9 @@ class _$CustomSubNameDocumentReference extends FirestoreDocumentReference< "Cannot specify both value and valueFieldValue", ); final json = { - if (value != _sentinel) _$CustomSubNameFieldMap['value']!: value as num, + if (value != _sentinel) + _$CustomSubNameFieldMap['value']!: + _$CustomSubNamePerFieldToJson.value(value as num), if (valueFieldValue != null) _$CustomSubNameFieldMap['value']!: valueFieldValue, }; @@ -8814,7 +9475,9 @@ class _$CustomSubNameDocumentReference extends FirestoreDocumentReference< "Cannot specify both value and valueFieldValue", ); final json = { - if (value != _sentinel) _$CustomSubNameFieldMap['value']!: value as num, + if (value != _sentinel) + _$CustomSubNameFieldMap['value']!: + _$CustomSubNamePerFieldToJson.value(value as num), if (valueFieldValue != null) _$CustomSubNameFieldMap['value']!: valueFieldValue, }; @@ -9151,15 +9814,28 @@ class _$CustomSubNameQuery _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$CustomSubNameFieldMap['value']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: isEqualTo != null + ? _$CustomSubNamePerFieldToJson.value(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$CustomSubNamePerFieldToJson.value(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$CustomSubNamePerFieldToJson.value(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$CustomSubNamePerFieldToJson.value(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$CustomSubNamePerFieldToJson.value(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$CustomSubNamePerFieldToJson.value(isGreaterThanOrEqualTo) + : null, isNull: isNull, - whereIn: whereIn, - whereNotIn: whereNotIn, + whereIn: whereIn?.map((e) => _$CustomSubNamePerFieldToJson.value(e)), + whereNotIn: + whereNotIn?.map((e) => _$CustomSubNamePerFieldToJson.value(e)), ), $queryCursor: $queryCursor, ); @@ -9596,7 +10272,8 @@ class _$ThisIsACustomPrefixDocumentReference extends FirestoreDocumentReference< ); final json = { if (value != _sentinel) - _$CustomClassPrefixFieldMap['value']!: value as num, + _$CustomClassPrefixFieldMap['value']!: + _$CustomClassPrefixPerFieldToJson.value(value as num), if (valueFieldValue != null) _$CustomClassPrefixFieldMap['value']!: valueFieldValue, }; @@ -9615,7 +10292,8 @@ class _$ThisIsACustomPrefixDocumentReference extends FirestoreDocumentReference< ); final json = { if (value != _sentinel) - _$CustomClassPrefixFieldMap['value']!: value as num, + _$CustomClassPrefixFieldMap['value']!: + _$CustomClassPrefixPerFieldToJson.value(value as num), if (valueFieldValue != null) _$CustomClassPrefixFieldMap['value']!: valueFieldValue, }; @@ -9954,15 +10632,29 @@ class _$ThisIsACustomPrefixQuery _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$CustomClassPrefixFieldMap['value']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: isEqualTo != null + ? _$CustomClassPrefixPerFieldToJson.value(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$CustomClassPrefixPerFieldToJson.value(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$CustomClassPrefixPerFieldToJson.value(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$CustomClassPrefixPerFieldToJson.value(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$CustomClassPrefixPerFieldToJson.value(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$CustomClassPrefixPerFieldToJson.value(isGreaterThanOrEqualTo) + : null, isNull: isNull, - whereIn: whereIn, - whereNotIn: whereNotIn, + whereIn: + whereIn?.map((e) => _$CustomClassPrefixPerFieldToJson.value(e)), + whereNotIn: + whereNotIn?.map((e) => _$CustomClassPrefixPerFieldToJson.value(e)), ), $queryCursor: $queryCursor, ); @@ -10387,7 +11079,9 @@ class _$ExplicitPathDocumentReference extends FirestoreDocumentReference< "Cannot specify both value and valueFieldValue", ); final json = { - if (value != _sentinel) _$ExplicitPathFieldMap['value']!: value as num, + if (value != _sentinel) + _$ExplicitPathFieldMap['value']!: + _$ExplicitPathPerFieldToJson.value(value as num), if (valueFieldValue != null) _$ExplicitPathFieldMap['value']!: valueFieldValue, }; @@ -10405,7 +11099,9 @@ class _$ExplicitPathDocumentReference extends FirestoreDocumentReference< "Cannot specify both value and valueFieldValue", ); final json = { - if (value != _sentinel) _$ExplicitPathFieldMap['value']!: value as num, + if (value != _sentinel) + _$ExplicitPathFieldMap['value']!: + _$ExplicitPathPerFieldToJson.value(value as num), if (valueFieldValue != null) _$ExplicitPathFieldMap['value']!: valueFieldValue, }; @@ -10742,15 +11438,28 @@ class _$ExplicitPathQuery _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$ExplicitPathFieldMap['value']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: isEqualTo != null + ? _$ExplicitPathPerFieldToJson.value(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$ExplicitPathPerFieldToJson.value(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$ExplicitPathPerFieldToJson.value(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$ExplicitPathPerFieldToJson.value(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$ExplicitPathPerFieldToJson.value(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$ExplicitPathPerFieldToJson.value(isGreaterThanOrEqualTo) + : null, isNull: isNull, - whereIn: whereIn, - whereNotIn: whereNotIn, + whereIn: whereIn?.map((e) => _$ExplicitPathPerFieldToJson.value(e)), + whereNotIn: + whereNotIn?.map((e) => _$ExplicitPathPerFieldToJson.value(e)), ), $queryCursor: $queryCursor, ); @@ -11183,7 +11892,9 @@ class _$ExplicitSubPathDocumentReference extends FirestoreDocumentReference< "Cannot specify both value and valueFieldValue", ); final json = { - if (value != _sentinel) _$ExplicitSubPathFieldMap['value']!: value as num, + if (value != _sentinel) + _$ExplicitSubPathFieldMap['value']!: + _$ExplicitSubPathPerFieldToJson.value(value as num), if (valueFieldValue != null) _$ExplicitSubPathFieldMap['value']!: valueFieldValue, }; @@ -11201,7 +11912,9 @@ class _$ExplicitSubPathDocumentReference extends FirestoreDocumentReference< "Cannot specify both value and valueFieldValue", ); final json = { - if (value != _sentinel) _$ExplicitSubPathFieldMap['value']!: value as num, + if (value != _sentinel) + _$ExplicitSubPathFieldMap['value']!: + _$ExplicitSubPathPerFieldToJson.value(value as num), if (valueFieldValue != null) _$ExplicitSubPathFieldMap['value']!: valueFieldValue, }; @@ -11538,15 +12251,28 @@ class _$ExplicitSubPathQuery _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( _$ExplicitSubPathFieldMap['value']!, - isEqualTo: isEqualTo, - isNotEqualTo: isNotEqualTo, - isLessThan: isLessThan, - isLessThanOrEqualTo: isLessThanOrEqualTo, - isGreaterThan: isGreaterThan, - isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + isEqualTo: isEqualTo != null + ? _$ExplicitSubPathPerFieldToJson.value(isEqualTo) + : null, + isNotEqualTo: isNotEqualTo != null + ? _$ExplicitSubPathPerFieldToJson.value(isNotEqualTo) + : null, + isLessThan: isLessThan != null + ? _$ExplicitSubPathPerFieldToJson.value(isLessThan) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$ExplicitSubPathPerFieldToJson.value(isLessThanOrEqualTo) + : null, + isGreaterThan: isGreaterThan != null + ? _$ExplicitSubPathPerFieldToJson.value(isGreaterThan) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$ExplicitSubPathPerFieldToJson.value(isGreaterThanOrEqualTo) + : null, isNull: isNull, - whereIn: whereIn, - whereNotIn: whereNotIn, + whereIn: whereIn?.map((e) => _$ExplicitSubPathPerFieldToJson.value(e)), + whereNotIn: + whereNotIn?.map((e) => _$ExplicitSubPathPerFieldToJson.value(e)), ), $queryCursor: $queryCursor, ); @@ -11819,6 +12545,14 @@ const _$IgnoredGetterFieldMap = { 'count3': 'count3', }; +// ignore: unused_element +abstract class _$IgnoredGetterPerFieldToJson { + // ignore: unused_element + static Object? value(int instance) => instance; + // ignore: unused_element + static Object? count3(int instance) => instance; +} + Map _$IgnoredGetterToJson(IgnoredGetter instance) => { 'value': instance.value, @@ -11833,6 +12567,12 @@ const _$ModelFieldMap = { 'value': 'value', }; +// ignore: unused_element +abstract class _$ModelPerFieldToJson { + // ignore: unused_element + static Object? value(String instance) => instance; +} + Map _$ModelToJson(Model instance) => { 'value': instance.value, }; @@ -11856,6 +12596,15 @@ Nested _$NestedFromJson(Map json) => Nested( dynamicList: json['dynamicList'] as List?, boolSet: (json['boolSet'] as List?)?.map((e) => e as bool).toSet(), + enumValue: $enumDecode(_$TestEnumEnumMap, json['enumValue']), + nullableEnumValue: + $enumDecodeNullable(_$TestEnumEnumMap, json['nullableEnumValue']), + enumList: (json['enumList'] as List) + .map((e) => $enumDecode(_$TestEnumEnumMap, e)) + .toList(), + nullableEnumList: (json['nullableEnumList'] as List?) + ?.map((e) => $enumDecode(_$TestEnumEnumMap, e)) + .toList(), ); const _$NestedFieldMap = { @@ -11868,8 +12617,45 @@ const _$NestedFieldMap = { 'objectList': 'objectList', 'dynamicList': 'dynamicList', 'boolSet': 'boolSet', + 'enumValue': 'enumValue', + 'nullableEnumValue': 'nullableEnumValue', + 'enumList': 'enumList', + 'nullableEnumList': 'nullableEnumList', }; +// ignore: unused_element +abstract class _$NestedPerFieldToJson { + // ignore: unused_element + static Object? value(Nested? instance) => instance; + // ignore: unused_element + static Object? simple(int? instance) => instance; + // ignore: unused_element + static Object? valueList(List? instance) => instance; + // ignore: unused_element + static Object? boolList(List? instance) => instance; + // ignore: unused_element + static Object? stringList(List? instance) => instance; + // ignore: unused_element + static Object? numList(List? instance) => instance; + // ignore: unused_element + static Object? objectList(List? instance) => instance; + // ignore: unused_element + static Object? dynamicList(List? instance) => instance; + // ignore: unused_element + static Object? boolSet(Set? instance) => instance?.toList(); + // ignore: unused_element + static Object? enumValue(TestEnum instance) => _$TestEnumEnumMap[instance]!; + // ignore: unused_element + static Object? nullableEnumValue(TestEnum? instance) => + _$TestEnumEnumMap[instance]; + // ignore: unused_element + static Object? enumList(List instance) => + instance.map((e) => _$TestEnumEnumMap[e]!).toList(); + // ignore: unused_element + static Object? nullableEnumList(List? instance) => + instance?.map((e) => _$TestEnumEnumMap[e]!).toList(); +} + Map _$NestedToJson(Nested instance) => { 'value': instance.value, 'simple': instance.simple, @@ -11880,12 +12666,26 @@ Map _$NestedToJson(Nested instance) => { 'objectList': instance.objectList, 'dynamicList': instance.dynamicList, 'boolSet': instance.boolSet?.toList(), + 'enumValue': _$TestEnumEnumMap[instance.enumValue]!, + 'nullableEnumValue': _$TestEnumEnumMap[instance.nullableEnumValue], + 'enumList': instance.enumList.map((e) => _$TestEnumEnumMap[e]!).toList(), + 'nullableEnumList': + instance.nullableEnumList?.map((e) => _$TestEnumEnumMap[e]!).toList(), }; +const _$TestEnumEnumMap = { + TestEnum.one: 'one', + TestEnum.two: 'two', + TestEnum.three: 'three', +}; + EmptyModel _$EmptyModelFromJson(Map json) => EmptyModel(); const _$EmptyModelFieldMap = {}; +// ignore: unused_element +abstract class _$EmptyModelPerFieldToJson {} + Map _$EmptyModelToJson(EmptyModel instance) => {}; @@ -11902,6 +12702,16 @@ const _$MinValidationFieldMap = { 'numNbr': 'numNbr', }; +// ignore: unused_element +abstract class _$MinValidationPerFieldToJson { + // ignore: unused_element + static Object? intNbr(int instance) => instance; + // ignore: unused_element + static Object? doubleNbr(double instance) => instance; + // ignore: unused_element + static Object? numNbr(num instance) => instance; +} + Map _$MinValidationToJson(MinValidation instance) => { 'intNbr': instance.intNbr, @@ -11919,6 +12729,14 @@ const _$RootFieldMap = { 'nullable': 'nullable', }; +// ignore: unused_element +abstract class _$RootPerFieldToJson { + // ignore: unused_element + static Object? nonNullable(String instance) => instance; + // ignore: unused_element + static Object? nullable(int? instance) => instance; +} + Map _$RootToJson(Root instance) => { 'nonNullable': instance.nonNullable, 'nullable': instance.nullable, @@ -11932,6 +12750,12 @@ const _$OptionalJsonFieldMap = { 'value': 'value', }; +// ignore: unused_element +abstract class _$OptionalJsonPerFieldToJson { + // ignore: unused_element + static Object? value(int instance) => instance; +} + Map _$OptionalJsonToJson(OptionalJson instance) => { 'value': instance.value, @@ -11945,6 +12769,12 @@ const _$MixedJsonFieldMap = { 'value': 'value', }; +// ignore: unused_element +abstract class _$MixedJsonPerFieldToJson { + // ignore: unused_element + static Object? value(int instance) => instance; +} + Map _$MixedJsonToJson(MixedJson instance) => { 'value': instance.value, }; @@ -11959,6 +12789,14 @@ const _$SubFieldMap = { 'nullable': 'nullable', }; +// ignore: unused_element +abstract class _$SubPerFieldToJson { + // ignore: unused_element + static Object? nonNullable(String instance) => instance; + // ignore: unused_element + static Object? nullable(int? instance) => instance; +} + Map _$SubToJson(Sub instance) => { 'nonNullable': instance.nonNullable, 'nullable': instance.nullable, @@ -11973,6 +12811,12 @@ const _$CustomSubNameFieldMap = { 'value': 'value', }; +// ignore: unused_element +abstract class _$CustomSubNamePerFieldToJson { + // ignore: unused_element + static Object? value(num instance) => instance; +} + Map _$CustomSubNameToJson(CustomSubName instance) => { 'value': instance.value, @@ -11986,6 +12830,12 @@ const _$AsCamelCaseFieldMap = { 'value': 'value', }; +// ignore: unused_element +abstract class _$AsCamelCasePerFieldToJson { + // ignore: unused_element + static Object? value(num instance) => instance; +} + Map _$AsCamelCaseToJson(AsCamelCase instance) => { 'value': instance.value, @@ -12000,6 +12850,12 @@ const _$CustomClassPrefixFieldMap = { 'value': 'value', }; +// ignore: unused_element +abstract class _$CustomClassPrefixPerFieldToJson { + // ignore: unused_element + static Object? value(num instance) => instance; +} + Map _$CustomClassPrefixToJson(CustomClassPrefix instance) => { 'value': instance.value, @@ -12013,6 +12869,12 @@ const _$ExplicitPathFieldMap = { 'value': 'value', }; +// ignore: unused_element +abstract class _$ExplicitPathPerFieldToJson { + // ignore: unused_element + static Object? value(num instance) => instance; +} + Map _$ExplicitPathToJson(ExplicitPath instance) => { 'value': instance.value, @@ -12027,6 +12889,12 @@ const _$ExplicitSubPathFieldMap = { 'value': 'value', }; +// ignore: unused_element +abstract class _$ExplicitSubPathPerFieldToJson { + // ignore: unused_element + static Object? value(num instance) => instance; +} + Map _$ExplicitSubPathToJson(ExplicitSubPath instance) => { 'value': instance.value, diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm_generator/lib/src/collection_data.dart b/packages/cloud_firestore_odm/cloud_firestore_odm_generator/lib/src/collection_data.dart index 597468bd87dd..8f0de3bee86a 100644 --- a/packages/cloud_firestore_odm/cloud_firestore_odm_generator/lib/src/collection_data.dart +++ b/packages/cloud_firestore_odm/cloud_firestore_odm_generator/lib/src/collection_data.dart @@ -10,19 +10,12 @@ import 'package:collection/collection.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:recase/recase.dart'; import 'package:source_gen/source_gen.dart'; +import 'package:source_helper/source_helper.dart'; import 'collection_generator.dart'; import 'names.dart'; const collectionChecker = TypeChecker.fromRuntime(Collection); -const dateTimeChecker = TypeChecker.fromRuntime(DateTime); -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', -); - const jsonSerializableChecker = TypeChecker.fromRuntime(JsonSerializable); const freezedChecker = TypeChecker.fromRuntime(Freezed); @@ -92,6 +85,7 @@ class CollectionData with Names { required this.queryableFields, required this.fromJson, required this.toJson, + required this.perFieldToJson, required this.idKey, required this.libraryElement, }) : collectionName = @@ -116,9 +110,6 @@ class CollectionData with Names { final type = CollectionData.modelTypeOfAnnotation(annotation); - final hasJsonSerializable = - jsonSerializableChecker.hasAnnotationOf(type.element!); - if (type is DynamicType) { throw InvalidGenerationSourceError( 'The annotation @Collection was used, but no generic type was specified. ', @@ -135,7 +126,7 @@ class CollectionData with Names { ); } - final hasFreezed = freezedChecker.hasAnnotationOf(type.element!); + final hasFreezed = freezedChecker.hasAnnotationOf(collectionTargetElement); final redirectedFreezedConstructors = collectionTargetElement.constructors.where( (element) { @@ -146,30 +137,24 @@ class CollectionData with Names { }, ).toList(); - // TODO throw when using json_serializable if the Model type and - // the collection are defined in separate libraries - - // TODO test error handling - if (redirectedFreezedConstructors.length > 1) { + final hasJsonSerializable = + jsonSerializableChecker.hasAnnotationOf(collectionTargetElement); + // Freezed classes are also JsonSerializable + if (!hasJsonSerializable && !hasFreezed) { throw InvalidGenerationSourceError( - 'Union types when using @freezed are currently unsupported. Use a single constructor instead', - element: annotatedElement, + 'Used @Collection with the class ${collectionTargetElement.name}, but ' + 'the class has no @JsonSerializable annotation.', ); } final annotatedElementSource = annotatedElement.librarySource; - // TODO(rrousselGit) handle parts // Whether the model class and the reference variable are defined in the same file // This is important because json_serializable generates private code for // decoding a Model class. final modelAndReferenceInTheSameLibrary = collectionTargetElement.librarySource == annotatedElementSource; - - final fromJson = collectionTargetElement.constructors.firstWhereOrNull( - (ctor) => ctor.name == 'fromJson', - ); - if (hasJsonSerializable && !modelAndReferenceInTheSameLibrary) { + if (!modelAndReferenceInTheSameLibrary) { throw InvalidGenerationSourceError( ''' When using json_serializable, the `@Collection` annotation and the class that @@ -182,16 +167,18 @@ represents the content of the collection must be in the same file. ); } - if ((!hasJsonSerializable || !modelAndReferenceInTheSameLibrary) && - fromJson == null) { + // TODO test error handling + if (redirectedFreezedConstructors.length > 1) { throw InvalidGenerationSourceError( - 'Used @Collection with the class ${collectionTargetElement.name}, but ' - 'the class has no `fromJson` constructor.', - todo: 'Add a `fromJson` constructor to ${collectionTargetElement.name}', + 'Union types when using @freezed are currently unsupported. Use a single constructor instead', element: annotatedElement, ); } + final collectionTargetElementPublicType = + collectionTargetElement.name.public; + final fromJson = collectionTargetElement.constructors + .firstWhereOrNull((ctor) => ctor.name == 'fromJson'); if (fromJson != null) { if (fromJson.parameters.length != 1 || !fromJson.parameters.first.isRequiredPositional || @@ -204,20 +191,17 @@ represents the content of the collection must be in the same file. ); } } - final toJson = collectionTargetElement // Looking into fromJson from superTypes too .allMethods .firstWhereOrNull((method) => method.name == 'toJson'); - if (!hasJsonSerializable && toJson == null) { - throw InvalidGenerationSourceError( - 'Used @Collection with the class ${collectionTargetElement.name}, but ' - 'the class has no `toJson` method.', - todo: 'Add a `toJson` method to ${collectionTargetElement.name}', - element: annotatedElement, - ); - } - + final redirectedFreezedClass = redirectedFreezedConstructors + .singleOrNull?.redirectedConstructor!.enclosingElement.name; + final generatedJsonTypePrefix = _generatedJsonTypePrefix( + hasFreezed: hasFreezed, + redirectedFreezedClass: redirectedFreezedClass, + collectionTargetElementPublicType: collectionTargetElementPublicType, + ); if (toJson != null) { if (toJson.parameters.isNotEmpty || !toJson.returnType.isDartCoreMap) { // TODO support serializing generic objects @@ -228,7 +212,6 @@ represents the content of the collection must be in the same file. ); } } - final data = CollectionData( type: type, path: path, @@ -237,12 +220,14 @@ represents the content of the collection must be in the same file. libraryElement: libraryElement, fromJson: (json) { if (fromJson != null) return '$type.fromJson($json)'; - return '_\$${type.toString().public}FromJson($json)'; + return '${generatedJsonTypePrefix}FromJson($json)'; }, toJson: (value) { if (toJson != null) return '$value.toJson()'; - return '_\$${type.toString().public}ToJson($value)'; + return '${generatedJsonTypePrefix}ToJson($value)'; }, + perFieldToJson: (field) => + '${generatedJsonTypePrefix}PerFieldToJson.$field', idKey: collectionTargetElement .allFields( hasFreezed: hasFreezed, @@ -263,29 +248,17 @@ represents the content of the collection must be in the same file. freezedConstructors: redirectedFreezedConstructors, ) .where((f) => f.isPublic) - .where((f) => _isSupportedType(f.type)) .where((f) => !f.hasId()) .where((f) => !f.isJsonIgnored()) .map( - (e) { - var key = "'${e.name}'"; - - if (hasFreezed) { - key = - // two $ because both Freezed and json_serializable add one - '_\$\$${redirectedFreezedConstructors.single.redirectedConstructor!.enclosingElement.name}FieldMap[$key]!'; - } else if (hasJsonSerializable) { - key = '_\$${collectionTargetElement.name.public}FieldMap[$key]!'; - } - - return QueryingField( - e.name, - e.type, - updatable: true, - field: key, - ); - }, - ).toList(), + (f) => QueryingField( + f.name, + f.type, + updatable: true, + field: "${generatedJsonTypePrefix}FieldMap['${f.name}']!", + ), + ) + .toList(), ], ); @@ -349,18 +322,16 @@ represents the content of the collection must be in the same file. return (annotation.type! as ParameterizedType).typeArguments.first; } - static bool _isSupportedType(DartType type) { - return type.isDartCoreString || - type.isDartCoreNum || - type.isDartCoreInt || - type.isDartCoreDouble || - type.isDartCoreBool || - type.isSupportedPrimitiveIterable || - type.isJsonDocumentReference || - dateTimeChecker.isAssignableFromType(type) || - timestampChecker.isAssignableFromType(type) || - geoPointChecker.isAssignableFromType(type); - // TODO filter list other than List + static String _generatedJsonTypePrefix({ + required bool hasFreezed, + required String? redirectedFreezedClass, + required String collectionTargetElementPublicType, + }) { + if (hasFreezed) { + return '_\$\$$redirectedFreezedClass'; + } else { + return '_\$$collectionTargetElementPublicType'; + } } @override @@ -385,6 +356,7 @@ represents the content of the collection must be in the same file. String Function(String json) fromJson; String Function(String value) toJson; + String Function(String field) perFieldToJson; @override String toString() { @@ -450,9 +422,9 @@ extension DartTypeExtension on DartType { (this as InterfaceType).typeArguments.single.isDartCoreMap; } - bool get isSupportedIterable => - _coreListChecker.isExactlyType(this) || - _coreSetChecker.isExactlyType(this); + bool get isList => _coreListChecker.isExactlyType(this); + bool get isSet => _coreSetChecker.isExactlyType(this); + bool get isSupportedIterable => isList || isSet; bool get isSupportedPrimitiveIterable { if (!isSupportedIterable) return false; @@ -463,6 +435,7 @@ extension DartTypeExtension on DartType { generic.isDartCoreString || generic.isDartCoreBool || generic.isDartCoreObject || + generic.isEnum || generic is DynamicType; } } 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 108096236cd8..c3024e2c1993 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 @@ -118,7 +118,7 @@ class CollectionGenerator Iterable generateForAll(GlobalData globalData) sync* { yield ''' // 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, require_trailing_commas, prefer_single_quotes, prefer_double_quotes, use_super_parameters +// 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, require_trailing_commas, prefer_single_quotes, prefer_double_quotes, use_super_parameters, duplicate_ignore '''; yield ''' diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm_generator/lib/src/templates/document_reference.dart b/packages/cloud_firestore_odm/cloud_firestore_odm_generator/lib/src/templates/document_reference.dart index 940dc941fcaf..27ecbdb99d9b 100644 --- a/packages/cloud_firestore_odm/cloud_firestore_odm_generator/lib/src/templates/document_reference.dart +++ b/packages/cloud_firestore_odm/cloud_firestore_odm_generator/lib/src/templates/document_reference.dart @@ -107,7 +107,7 @@ void transactionUpdate(Transaction transaction, {${parameters.join()}}); for (final field in data.updatableFields) ...[ ''' if (${field.name} != _sentinel) - ${field.field}: ${field.name} as ${field.type}, + ${field.field}: ${data.perFieldToJson(field.name)}(${field.name} as ${field.type}), ''', ''' if (${field.name}FieldValue != null) diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm_generator/lib/src/templates/query_reference.dart b/packages/cloud_firestore_odm/cloud_firestore_odm_generator/lib/src/templates/query_reference.dart index f4561dfaccd6..48312ece0d44 100644 --- a/packages/cloud_firestore_odm/cloud_firestore_odm_generator/lib/src/templates/query_reference.dart +++ b/packages/cloud_firestore_odm/cloud_firestore_odm_generator/lib/src/templates/query_reference.dart @@ -401,7 +401,27 @@ class ${data.queryReferenceImplName} final prototype = operators.entries.map((e) => '${e.value} ${e.key},').join(); - final parameters = operators.keys.map((e) => '$e: $e,').join(); + final perFieldToJson = data.perFieldToJson(field.name); + + final parameters = operators.keys.map((e) { + if (field.name == 'documentId' || e == 'isNull') { + return '$e: $e,'; + } else if ({'whereIn', 'whereNotIn'}.contains(e)) { + return '$e: $e?.map((e) => $perFieldToJson(e)),'; + } else if (e == 'arrayContainsAny') { + return '$e: $e != null ? $perFieldToJson($e) as Iterable? : null,'; + } else if (e == 'arrayContains') { + var transform = '$e: $e != null ? ($perFieldToJson('; + if (field.type.isSet) { + transform += '{$e}'; + } else { + transform += '[$e]'; + } + return '$transform) as List?)!.single : null,'; + } else { + return '$e: $e != null ? $perFieldToJson($e) : null,'; + } + }).join(); // TODO support whereX(isEqual: null); // TODO handle JsonSerializable case change and JsonKey(name: ...) diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm_generator/pubspec.yaml b/packages/cloud_firestore_odm/cloud_firestore_odm_generator/pubspec.yaml index da96688457a3..cebc967f3be3 100644 --- a/packages/cloud_firestore_odm/cloud_firestore_odm_generator/pubspec.yaml +++ b/packages/cloud_firestore_odm/cloud_firestore_odm_generator/pubspec.yaml @@ -20,6 +20,7 @@ dependencies: meta: ^1.8.0 recase: ^4.0.0 source_gen: ^1.3.2 + source_helper: ^1.3.4 dev_dependencies: build_runner: ^2.4.2 diff --git a/packages/cloud_firestore_odm/cloud_firestore_odm_generator/test/document_reference_test.dart b/packages/cloud_firestore_odm/cloud_firestore_odm_generator/test/document_reference_test.dart index 4f1bb294705c..c9031af6cc61 100644 --- a/packages/cloud_firestore_odm/cloud_firestore_odm_generator/test/document_reference_test.dart +++ b/packages/cloud_firestore_odm/cloud_firestore_odm_generator/test/document_reference_test.dart @@ -13,21 +13,18 @@ Future main() async { ); group('where(arrayContains)', () { - test(' is typed', () { + test('is typed', () { expect( library.withCode( ''' import 'simple.dart'; void main() { - // Does not arrayContains for non-list - // expect-error: UNDEFINED_METHOD nestedRef.whereValue(); nestedRef.whereSimple( // expect-error: UNDEFINED_NAMED_PARAMETER arrayContains: null, ); - // expect-error: UNDEFINED_METHOD nestedRef.whereValueList(); nestedRef.whereNumList(arrayContains: 42); @@ -52,11 +49,9 @@ import 'simple.dart'; void main() { nestedRef.doc('42').update( - // expect-error: UNDEFINED_NAMED_PARAMETER value: null, ); nestedRef.doc('42').update( - // expect-error: UNDEFINED_NAMED_PARAMETER valueList: null, ); nestedRef.doc('42').update( diff --git a/packages/cloud_firestore_odm/doc/defining-models.md b/packages/cloud_firestore_odm/doc/defining-models.md index 5e2740eff768..75604da1a96a 100644 --- a/packages/cloud_firestore_odm/doc/defining-models.md +++ b/packages/cloud_firestore_odm/doc/defining-models.md @@ -37,6 +37,7 @@ const firestoreSerializable = JsonSerializable( // The following values could alternatively be set inside your `build.yaml` explicitToJson: true, createFieldMap: true, + createPerFieldToJson: true, ); @firestoreSerializable