diff --git a/README.md b/README.md index 5633a8b..c0cf42a 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,12 @@ The ODM allows data schemas to be defined which represent the data structure of - 🎯 Data selectors to help avoid unnecessary Widget rebuilds. - 💻 Full API code completion. +## Compatibility + +- **Freezed**: Compatible with Freezed 3.0.0 and above +- **Analyzer**: Supports analyzer 7.0.0 and above +- **Source Gen**: Compatible with source_gen 2.0.0 and above + ## Installation ### 1. Use a recent Dart version @@ -34,7 +40,7 @@ That is done by adding the following to your `pubspec.yaml`: ```yaml environment: - sdk: ">=2.18.0 <4.0.0" + sdk: ">=3.0.0 <4.0.0" ``` ### 2. FlutterFire Initialization @@ -104,6 +110,24 @@ class MyModel {...} Once installed, read the documentation on [defining models](./docs/defining-models.md). + +## Development +### Testing +To run tests, you should have chromedriver install on your system. +```shell +./scripts/run-tests.sh +``` +Note: make sure in `packages/cloud_firestore_odm_generator/pubspec.yaml` to replace +``` +cloud_firestore_odm: {VERSION} +``` +with +``` +cloud_firestore_odm: + path: ../cloud_firestore_odm +``` +This is required for the tests to run. Set back to correct version before deploying. + ## Issues and feedback Please file FlutterFire specific issues, bugs, or feature requests in our [issue tracker](https://github.com/firebaseextended/firestoreodm-flutter/issues/new). diff --git a/packages/cloud_firestore_odm/CHANGELOG.md b/packages/cloud_firestore_odm/CHANGELOG.md index aec44da..8b10346 100644 --- a/packages/cloud_firestore_odm/CHANGELOG.md +++ b/packages/cloud_firestore_odm/CHANGELOG.md @@ -1,3 +1,12 @@ +## 1.2.0 +- **CHORE**: Update cloud_firestore to ^6.0.0 + +## 1.1.0 + +- **FIX**: Resolve compatibility issues with Freezed 3.0.0 and above +- **FEAT**: Support analyzer 7.0.0 and above +- **CHORE**: Update dependencies to latest versions + ## 1.0.0-dev.88 - **BREAKING**: Removes `set` methods from `FirestoreDocumentReference` to make way for generated methods diff --git a/packages/cloud_firestore_odm/README.md b/packages/cloud_firestore_odm/README.md index f3bf4c2..3ccd508 100755 --- a/packages/cloud_firestore_odm/README.md +++ b/packages/cloud_firestore_odm/README.md @@ -7,6 +7,12 @@ To learn more about Firebase Cloud Firestore, please visit the [Firebase website [![pub package](https://img.shields.io/pub/v/cloud_firestore_odm.svg)](https://pub.dev/packages/cloud_firestore_odm) +## Compatibility + +- **Freezed**: Compatible with Freezed 3.0.0 and above +- **Analyzer**: Supports analyzer 7.0.0 and above +- **Source Gen**: Compatible with source_gen 2.0.0 and above + ## Getting Started To get started with Cloud Firestore for Flutter, please [see the documentation](https://github.com/firebaseextended/firestoreodm-flutter/tree/main/docs). diff --git a/packages/cloud_firestore_odm/example/integration_test/cloud_firestore_odm_e2e_test.dart b/packages/cloud_firestore_odm/example/integration_test/cloud_firestore_odm_e2e_test.dart index 6b1642c..3875a50 100644 --- a/packages/cloud_firestore_odm/example/integration_test/cloud_firestore_odm_e2e_test.dart +++ b/packages/cloud_firestore_odm/example/integration_test/cloud_firestore_odm_e2e_test.dart @@ -9,9 +9,8 @@ import 'package:integration_test/integration_test.dart'; import 'collection_reference_test.dart' as collection_reference_test; import 'document_reference_test.dart' as document_reference_test; - import 'firebase_options.dart'; - +import 'freezed_test.dart' as freezed_test; import 'path_test.dart' as path_test; import 'query_reference_test.dart' as query_reference_test; @@ -32,5 +31,6 @@ void main() { // firestore_builder_test.main(); query_reference_test.main(); path_test.main(); + freezed_test.main(); }); } diff --git a/packages/cloud_firestore_odm/example/integration_test/collection_reference_test.dart b/packages/cloud_firestore_odm/example/integration_test/collection_reference_test.dart index 2d9ec22..82b77a0 100644 --- a/packages/cloud_firestore_odm/example/integration_test/collection_reference_test.dart +++ b/packages/cloud_firestore_odm/example/integration_test/collection_reference_test.dart @@ -49,16 +49,12 @@ void main() { expect(b.data?.id, '456'); }); - test( - 'When using @Id, set/update do not insert an "id" property in the document', - () async { + test('When using @Id, set/update do not insert an "id" property in the document', () async { final collection = await initializeTest(MovieCollectionReference()); await collection.doc('123').set(createMovie(title: 'a', id: '42')); - final snapshot = await FirebaseFirestore.instance - .doc(collection.doc('123').path) - .get(); + final snapshot = await FirebaseFirestore.instance.doc(collection.doc('123').path).get(); expect(snapshot.data()?.containsKey('id'), false); }); @@ -67,8 +63,7 @@ void main() { test('reference', () async { expect( MovieCollectionReference().reference, - isA>() - .having((e) => e.path, 'path', 'firestore-example-app'), + isA>().having((e) => e.path, 'path', 'firestore-example-app'), ); expect( @@ -137,14 +132,12 @@ void main() { expect( await stream.next, isA().having((e) => e.docs, 'doc', [ - isA() - .having((e) => e.data.title, 'data.title', 'title'), + isA().having((e) => e.data.title, 'data.title', 'title'), ]), ); }); - test('emits an error if decoding fails, but keeps listening to updates', - () async { + test('emits an error if decoding fails, but keeps listening to updates', () async { final collection = await initializeTest(MovieCollectionReference()); await FirebaseFirestore.instance @@ -185,8 +178,7 @@ void main() { }); group('doc', () { - test('generates a custom ID for documents if none is specified', - () async { + test('generates a custom ID for documents if none is specified', () async { final collection = await initializeTest(MovieCollectionReference()); final doc = collection.doc(); @@ -200,10 +192,7 @@ void main() { test('can specify a custom ID to obtain an existing doc', () async { final collection = await initializeTest(MovieCollectionReference()); - await FirebaseFirestore.instance - .collection('firestore-example-app') - .doc('123') - .set( + await FirebaseFirestore.instance.collection('firestore-example-app').doc('123').set( MovieCollectionReference.toFirestore( createMovie(title: 'title'), null, @@ -217,8 +206,7 @@ void main() { expect( await doc.get(), - isA() - .having((e) => e.data?.title, 'data.title', 'title'), + isA().having((e) => e.data?.title, 'data.title', 'title'), ); }); }); @@ -256,16 +244,14 @@ void main() { stream, emits( isA().having((e) => e.docs, 'doc', [ - isA() - .having((e) => e.data.title, 'data.title', 'Foo'), + isA().having((e) => e.data.title, 'data.title', 'Foo'), ]), ), ); expect( await newDoc.get(), - isA() - .having((e) => e.data?.title, 'data.title', 'Foo'), + isA().having((e) => e.data?.title, 'data.title', 'Foo'), ); }); @@ -282,10 +268,8 @@ void main() { expect( querySnap.docs, [ - isA() - .having((d) => d.data.title, 'data.title', 'A'), - isA() - .having((d) => d.data.title, 'data.title', 'B'), + isA().having((d) => d.data.title, 'data.title', 'A'), + isA().having((d) => d.data.title, 'data.title', 'B'), ], ); }); @@ -299,16 +283,13 @@ void main() { final bSnap = await b.get(); - final querySnap = - await collection.orderByTitle(endAtDocument: bSnap).get(); + final querySnap = await collection.orderByTitle(endAtDocument: bSnap).get(); expect( querySnap.docs, [ - isA() - .having((d) => d.data.title, 'data.title', 'A'), - isA() - .having((d) => d.data.title, 'data.title', 'B'), + isA().having((d) => d.data.title, 'data.title', 'A'), + isA().having((d) => d.data.title, 'data.title', 'B'), ], ); }); @@ -327,10 +308,8 @@ void main() { expect( querySnap.docs, [ - isA() - .having((d) => d.data.title, 'data.title', 'A'), - isA() - .having((d) => d.data.title, 'data.title', 'B'), + isA().having((d) => d.data.title, 'data.title', 'A'), + isA().having((d) => d.data.title, 'data.title', 'B'), ], ); }); @@ -344,14 +323,12 @@ void main() { final bSnap = await b.get(); - final querySnap = - await collection.orderByTitle(endBeforeDocument: bSnap).get(); + final querySnap = await collection.orderByTitle(endBeforeDocument: bSnap).get(); expect( querySnap.docs, [ - isA() - .having((d) => d.data.title, 'data.title', 'A'), + isA().having((d) => d.data.title, 'data.title', 'A'), ], ); }); @@ -455,20 +432,15 @@ void main() { ), ); - final querySnap = await collection - .whereGenre(arrayContains: 'bar') - .orderByTitle() - .get(); + final querySnap = await collection.whereGenre(arrayContains: 'bar').orderByTitle().get(); expect( querySnap.docs.map((e) => e.data.title), ['B', 'C'], ); - final querySnap2 = await collection - .whereTags(arrayContains: 'serious') - .orderByTitle() - .get(); + final querySnap2 = + await collection.whereTags(arrayContains: 'serious').orderByTitle().get(); expect( querySnap2.docs.map((e) => e.data.title), @@ -506,8 +478,7 @@ void main() { await collection.doc('B').set(createMovie(title: 'title')); await collection.doc('C').set(createMovie(title: 'title')); - final querySnap = - await collection.orderByDocumentId(startAt: 'B').get(); + final querySnap = await collection.orderByDocumentId(startAt: 'B').get(); expect( querySnap.docs, @@ -525,8 +496,7 @@ void main() { await collection.doc('B').set(createMovie(title: 'title')); await collection.doc('C').set(createMovie(title: 'title')); - final querySnap = - await collection.whereDocumentId(isEqualTo: 'B').get(); + final querySnap = await collection.whereDocumentId(isEqualTo: 'B').get(); expect( querySnap.docs, @@ -539,15 +509,11 @@ void main() { group('where', () { test('supports field renaming', () async { - final collection = - await initializeTest(AdvancedJsonCollectionReference()); + final collection = await initializeTest(AdvancedJsonCollectionReference()); - await collection - .add(AdvancedJson(firstName: 'John', lastName: 'Doe')); - await collection - .add(AdvancedJson(firstName: 'John', lastName: 'Smith')); - await collection - .add(AdvancedJson(firstName: 'Mike', lastName: 'Doe')); + await collection.add(AdvancedJson(firstName: 'John', lastName: 'Doe')); + await collection.add(AdvancedJson(firstName: 'John', lastName: 'Smith')); + await collection.add(AdvancedJson(firstName: 'Mike', lastName: 'Doe')); expect( await collection.reference @@ -589,16 +555,12 @@ void main() { group('orderBy', () { test('supports field renaming', () async { - final collection = - await initializeTest(AdvancedJsonCollectionReference()); + final collection = await initializeTest(AdvancedJsonCollectionReference()); await collection.add(AdvancedJson(firstName: 'A', lastName: 'A')); - await collection - .add(AdvancedJson(firstName: 'John', lastName: 'Doe')); - await collection - .add(AdvancedJson(firstName: 'John', lastName: 'Smith')); - await collection - .add(AdvancedJson(firstName: 'Mike', lastName: 'Doe')); + await collection.add(AdvancedJson(firstName: 'John', lastName: 'Doe')); + await collection.add(AdvancedJson(firstName: 'John', lastName: 'Smith')); + await collection.add(AdvancedJson(firstName: 'Mike', lastName: 'Doe')); expect( await collection.reference @@ -646,10 +608,8 @@ void main() { expect( querySnap.docs, [ - isA() - .having((d) => d.data.title, 'data.title', 'B'), - isA() - .having((d) => d.data.title, 'data.title', 'C'), + isA().having((d) => d.data.title, 'data.title', 'B'), + isA().having((d) => d.data.title, 'data.title', 'C'), ], ); }, @@ -668,10 +628,8 @@ void main() { await collection.add(createMovie(title: 'C', likes: 1)); await collection.add(createMovie(title: 'C', likes: 2)); - final querySnap = await collection - .orderByTitle(startAt: 'B') - .orderByLikes(startAt: 2) - .get(); + final querySnap = + await collection.orderByTitle(startAt: 'B').orderByLikes(startAt: 2).get(); expect( querySnap.docs, @@ -700,16 +658,13 @@ void main() { final bSnap = await b.get(); - final querySnap = - await collection.orderByTitle(startAtDocument: bSnap).get(); + final querySnap = await collection.orderByTitle(startAtDocument: bSnap).get(); expect( querySnap.docs, [ - isA() - .having((d) => d.data.title, 'data.title', 'B'), - isA() - .having((d) => d.data.title, 'data.title', 'C'), + isA().having((d) => d.data.title, 'data.title', 'B'), + isA().having((d) => d.data.title, 'data.title', 'C'), ], ); }); @@ -723,14 +678,12 @@ void main() { await collection.add(createMovie(title: 'B')); await collection.add(createMovie(title: 'C')); - final querySnap = - await collection.orderByTitle(startAfter: 'B').get(); + final querySnap = await collection.orderByTitle(startAfter: 'B').get(); expect( querySnap.docs, [ - isA() - .having((d) => d.data.title, 'data.title', 'C'), + isA().having((d) => d.data.title, 'data.title', 'C'), ], ); }); @@ -744,14 +697,12 @@ void main() { final bSnap = await b.get(); - final querySnap = - await collection.orderByTitle(startAfterDocument: bSnap).get(); + final querySnap = await collection.orderByTitle(startAfterDocument: bSnap).get(); expect( querySnap.docs, [ - isA() - .having((d) => d.data.title, 'data.title', 'C'), + isA().having((d) => d.data.title, 'data.title', 'C'), ], ); }); @@ -769,10 +720,8 @@ void main() { expect( querySnap.docs, [ - isA() - .having((d) => d.data.title, 'data.title', 'A'), - isA() - .having((d) => d.data.title, 'data.title', 'B'), + isA().having((d) => d.data.title, 'data.title', 'A'), + isA().having((d) => d.data.title, 'data.title', 'B'), ], ); }); @@ -789,10 +738,8 @@ void main() { expect( querySnap.docs, [ - isA() - .having((d) => d.data.title, 'data.title', 'B'), - isA() - .having((d) => d.data.title, 'data.title', 'C'), + isA().having((d) => d.data.title, 'data.title', 'B'), + isA().having((d) => d.data.title, 'data.title', 'C'), ], ); }); @@ -956,9 +903,7 @@ void main() { test('overrides ==', () { expect( MovieCollectionReference().doc('123').comments, - MovieCollectionReference(FirebaseFirestore.instance) - .doc('123') - .comments, + MovieCollectionReference(FirebaseFirestore.instance).doc('123').comments, ); expect( MovieCollectionReference().doc('123').comments, @@ -985,11 +930,10 @@ void main() { 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(); + final querySnap = await collection.whereEnumValue(isEqualTo: TestEnum.two).get(); expect( - querySnap.docs.map((e) => e.data.id), + (querySnap.docs.map((e) => e.data.id).toList()..sort()), ['B', 'C'], ); }); @@ -1001,12 +945,10 @@ void main() { 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(); + final querySnap = await collection.whereNullableEnumValue(isEqualTo: TestEnum.two).get(); expect( - querySnap.docs.map((e) => e.data.id), + (querySnap.docs.map((e) => e.data.id).toList()..sort()), ['B', 'C'], ); }); @@ -1014,18 +956,14 @@ void main() { 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])); + 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(); + final querySnap = await collection.whereEnumList(arrayContains: TestEnum.two).get(); expect( - querySnap.docs.map((e) => e.data.id), + (querySnap.docs.map((e) => e.data.id).toList()..sort()), ['B', 'C'], ); }); @@ -1043,12 +981,10 @@ void main() { Enums(id: 'C', nullableEnumList: [TestEnum.two, TestEnum.three]), ); - final querySnap = await collection - .whereNullableEnumList(arrayContains: TestEnum.two) - .get(); + final querySnap = await collection.whereNullableEnumList(arrayContains: TestEnum.two).get(); expect( - querySnap.docs.map((e) => e.data.id), + (querySnap.docs.map((e) => e.data.id).toList()..sort()), ['B', 'C'], ); }); diff --git a/packages/cloud_firestore_odm/example/integration_test/common.dart b/packages/cloud_firestore_odm/example/integration_test/common.dart index c033ef9..be16607 100644 --- a/packages/cloud_firestore_odm/example/integration_test/common.dart +++ b/packages/cloud_firestore_odm/example/integration_test/common.dart @@ -9,8 +9,7 @@ import 'package:cloud_firestore_odm_example/movie.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:mockito/mockito.dart'; -Future - initializeTest>( +Future initializeTest>( T ref, ) async { final snapshot = await ref.reference.get(); diff --git a/packages/cloud_firestore_odm/example/integration_test/document_reference_test.dart b/packages/cloud_firestore_odm/example/integration_test/document_reference_test.dart index 465faaf..093e409 100644 --- a/packages/cloud_firestore_odm/example/integration_test/document_reference_test.dart +++ b/packages/cloud_firestore_odm/example/integration_test/document_reference_test.dart @@ -137,12 +137,8 @@ void main() { await collection.doc('123').get(); expect( - await collection - .doc('123') - .get(const GetOptions(source: Source.cache)), - isA() - .having((e) => e.data?.title, 'data.title', 'title') - .having( + await collection.doc('123').get(const GetOptions(source: Source.cache)), + isA().having((e) => e.data?.title, 'data.title', 'title').having( (e) => e.metadata.isFromCache, 'metadata.isFromCache', true, @@ -160,6 +156,8 @@ void main() { (transaction) => collection.doc('123').transactionGet(transaction), ); + print('result.data ${result.data}'); + print('result.data ${result.data}'); expect(result.id, '123'); expect(result.data?.title, 'title'); }); @@ -172,8 +170,7 @@ void main() { expect( await stream.next, - isA() - .having((e) => e.exists, 'exists', false), + isA().having((e) => e.exists, 'exists', false), ); await collection.doc('123').set(createMovie(title: 'title')); @@ -256,9 +253,7 @@ void main() { expect( await ref.doc('123').get().then((e) => e.data), - isA() - .having((e) => e.rated, 'rated', '') - .having((e) => e.title, 'title', 'Foo'), + isA().having((e) => e.rated, 'rated', '').having((e) => e.title, 'title', 'Foo'), ); }); }); @@ -286,12 +281,9 @@ void main() { ); }); - test('asserts that we cannot specify both FieldValue and normal value', - () async { + test('asserts that we cannot specify both FieldValue and normal value', () async { expect( - () => moviesRef - .doc('123') - .update(likes: 10, likesFieldValue: FieldValue.increment(10)), + () => moviesRef.doc('123').update(likes: 10, likesFieldValue: FieldValue.increment(10)), throwsAssertionError, ); }); @@ -420,9 +412,7 @@ void main() { }); group('root document reference', () { - test( - 'can make fromJson optional if model is annotated by JsonSerializable', - () async { + test('can make fromJson optional if model is annotated by JsonSerializable', () async { final collection = await initializeTest(optionalJsonRef); await collection.doc('123').set(OptionalJson(42)); @@ -440,10 +430,7 @@ void main() { await collection.doc('123').set(MixedJson(42)); - final rawSnapshot = await FirebaseFirestore.instance - .collection('root') - .doc('123') - .get(); + final rawSnapshot = await FirebaseFirestore.instance.collection('root').doc('123').get(); expect(rawSnapshot.data(), {'foo': 42}); expect( @@ -477,10 +464,7 @@ void main() { test('overrides ==', () { expect( MovieCollectionReference().doc('123').comments.doc('123'), - MovieCollectionReference(FirebaseFirestore.instance) - .doc('123') - .comments - .doc('123'), + MovieCollectionReference(FirebaseFirestore.instance).doc('123').comments.doc('123'), ); expect( MovieCollectionReference().doc('123').comments.doc('123'), @@ -492,21 +476,12 @@ void main() { ); expect( - MovieCollectionReference(customFirestore) - .doc('123') - .comments - .doc('123'), + MovieCollectionReference(customFirestore).doc('123').comments.doc('123'), isNot(MovieCollectionReference().doc('123').comments.doc('123')), ); expect( - MovieCollectionReference(customFirestore) - .doc('123') - .comments - .doc('123'), - MovieCollectionReference(customFirestore) - .doc('123') - .comments - .doc('123'), + MovieCollectionReference(customFirestore).doc('123').comments.doc('123'), + MovieCollectionReference(customFirestore).doc('123').comments.doc('123'), ); }); }); diff --git a/packages/cloud_firestore_odm/example/integration_test/firestore_builder_test.dart b/packages/cloud_firestore_odm/example/integration_test/firestore_builder_test.dart index 0e83f66..9b6611e 100644 --- a/packages/cloud_firestore_odm/example/integration_test/firestore_builder_test.dart +++ b/packages/cloud_firestore_odm/example/integration_test/firestore_builder_test.dart @@ -23,8 +23,7 @@ void main() { return ListView( children: [ - for (final doc in snapshot.requireData.docs) - Text(doc.data.title), + for (final doc in snapshot.requireData.docs) Text(doc.data.title), ], ); }, @@ -49,7 +48,7 @@ void main() { ); } - group('$FirestoreBuilder', () { + group('FirestoreBuilder', () { testWidgets('listens to documents', (tester) async { final collection = await initializeTest(MovieCollectionReference()); @@ -69,8 +68,7 @@ void main() { expect(find.text('Foo'), findsOneWidget); }); - testWidgets('emits errored snapshot when failed to decode a value', - (tester) async { + testWidgets('emits errored snapshot when failed to decode a value', (tester) async { final collection = await initializeTest(MovieCollectionReference()); await FirebaseFirestore.instance @@ -146,8 +144,7 @@ void main() { expect(find.text('A'), findsOneWidget); expect(find.text('B'), findsOneWidget); }); - testWidgets( - 'does not go back to loading if rebuilding the widget with the same query', + testWidgets('does not go back to loading if rebuilding the widget with the same query', (tester) async { final collection = await initializeTest(MovieCollectionReference()); diff --git a/packages/cloud_firestore_odm/example/integration_test/freezed_test.dart b/packages/cloud_firestore_odm/example/integration_test/freezed_test.dart index 461202b..faed47d 100644 --- a/packages/cloud_firestore_odm/example/integration_test/freezed_test.dart +++ b/packages/cloud_firestore_odm/example/integration_test/freezed_test.dart @@ -2,12 +2,21 @@ // 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_example/integration/freezed.dart'; +import 'package:firebase_core/firebase_core.dart'; import 'package:flutter_test/flutter_test.dart'; import 'common.dart'; +import 'firebase_options.dart'; void main() { + setUpAll(() async { + await Firebase.initializeApp( + options: DefaultFirebaseOptions.currentPlatform, + ); + FirebaseFirestore.instance.useFirestoreEmulator('localhost', 8080); + }); test('supports field renaming', () async { final collection = await initializeTest(PersonCollectionReference()); @@ -55,12 +64,13 @@ void main() { await aRef.update(firstName: 'A2', lastName: 'B2'); expect( - await aRef.reference - .withConverter>( - fromFirestore: (value, _) => value.data()!, - toFirestore: (value, _) => value, - ) - .get(), + (await aRef.reference + .withConverter>( + fromFirestore: (value, _) => value.data()!, + toFirestore: (value, _) => value, + ) + .get()) + .data(), { 'first_name': 'A2', 'LAST_NAME': 'B2', diff --git a/packages/cloud_firestore_odm/example/integration_test/path_test.dart b/packages/cloud_firestore_odm/example/integration_test/path_test.dart index cf4650f..fadcc03 100644 --- a/packages/cloud_firestore_odm/example/integration_test/path_test.dart +++ b/packages/cloud_firestore_odm/example/integration_test/path_test.dart @@ -21,8 +21,7 @@ void main() { final snapshot = await collection.get(); expect(snapshot.docs, [ - isA() - .having((e) => e.data.value, 'data.value', 42), + isA().having((e) => e.data.value, 'data.value', 42), ]); }); @@ -36,8 +35,7 @@ void main() { final snapshot = await collection.get(); expect(snapshot.docs, [ - isA() - .having((e) => e.data.value, 'data.value', 42), + isA().having((e) => e.data.value, 'data.value', 42), ]); }); }); @@ -53,15 +51,12 @@ void main() { final snapshot = await collection.get(); expect(snapshot.docs, [ - isA() - .having((e) => e.data.value, 'data.value', 42), + isA().having((e) => e.data.value, 'data.value', 42), ]); }); - test('can be manually specified through the Collection annotation', - () async { - final collection = - await initializeTest(rootRef.doc('123').thisIsACustomName); + test('can be manually specified through the Collection annotation', () async { + final collection = await initializeTest(rootRef.doc('123').thisIsACustomName); await FirebaseFirestore.instance .collection('root/123/custom-sub-name') @@ -70,18 +65,15 @@ void main() { final snapshot = await collection.get(); expect(snapshot.docs, [ - isA() - .having((e) => e.data.value, 'data.value', 42), + isA().having((e) => e.data.value, 'data.value', 42), ]); }); }); }); group('collection class prefix', () { - test('can be manually specified through the Collection annotation', - () async { - final collection = - await initializeTest(rootRef.doc('123').customClassPrefix); + test('can be manually specified through the Collection annotation', () async { + final collection = await initializeTest(rootRef.doc('123').customClassPrefix); await FirebaseFirestore.instance .collection('root/123/custom-class-prefix') @@ -90,8 +82,7 @@ void main() { final snapshot = await collection.get(); expect(snapshot.docs, [ - isA() - .having((e) => e.data?.value, 'data.value', 42), + isA().having((e) => e.data?.value, 'data.value', 42), ]); }); }); diff --git a/packages/cloud_firestore_odm/example/integration_test/query_reference_test.dart b/packages/cloud_firestore_odm/example/integration_test/query_reference_test.dart index 9426839..19b6a14 100644 --- a/packages/cloud_firestore_odm/example/integration_test/query_reference_test.dart +++ b/packages/cloud_firestore_odm/example/integration_test/query_reference_test.dart @@ -58,10 +58,7 @@ void main() { test('overrides ==', () { expect( MovieCollectionReference().doc('123').comments.limit(1), - MovieCollectionReference(FirebaseFirestore.instance) - .doc('123') - .comments - .limit(1), + MovieCollectionReference(FirebaseFirestore.instance).doc('123').comments.limit(1), ); expect( MovieCollectionReference().doc('123').comments.limit(1), @@ -73,21 +70,12 @@ void main() { ); expect( - MovieCollectionReference(customFirestore) - .doc('123') - .comments - .limit(1), + MovieCollectionReference(customFirestore).doc('123').comments.limit(1), isNot(MovieCollectionReference().doc('123').comments.limit(1)), ); expect( - MovieCollectionReference(customFirestore) - .doc('123') - .comments - .limit(1), - MovieCollectionReference(customFirestore) - .doc('123') - .comments - .limit(1), + MovieCollectionReference(customFirestore).doc('123').comments.limit(1), + MovieCollectionReference(customFirestore).doc('123').comments.limit(1), ); }); }); @@ -99,8 +87,7 @@ void main() { 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(); + final snapshot = await ref.orderByDuration(startAt: const Duration(days: 2)).get(); expect(snapshot.docs.length, 2); @@ -130,9 +117,7 @@ void main() { await ref.add(TimestampQuery(Timestamp.fromDate(DateTime(2000)))); await ref.add(TimestampQuery(Timestamp.fromDate(DateTime(2010)))); - final snapshot = await ref - .orderByTime(startAt: Timestamp.fromDate(DateTime(2000))) - .get(); + final snapshot = await ref.orderByTime(startAt: Timestamp.fromDate(DateTime(2000))).get(); expect(snapshot.docs.length, 2); @@ -147,8 +132,7 @@ void main() { await ref.add(GeoPointQuery(const GeoPoint(20, 0))); await ref.add(GeoPointQuery(const GeoPoint(20, 0))); - final snapshot = - await ref.orderByPoint(startAt: const GeoPoint(20, 0)).get(); + final snapshot = await ref.orderByPoint(startAt: const GeoPoint(20, 0)).get(); expect(snapshot.docs.length, 2); @@ -171,9 +155,8 @@ void main() { DocumentReferenceQuery(FirebaseFirestore.instance.doc('foo/c')), ); - final snapshot = await ref - .orderByRef(startAt: FirebaseFirestore.instance.doc('foo/b')) - .get(); + final snapshot = + await ref.orderByRef(startAt: FirebaseFirestore.instance.doc('foo/b')).get(); expect(snapshot.docs.length, 2); @@ -217,6 +200,8 @@ void main() { snapshot.docs.map((document) => document.data.number), everyElement(anyOf(1, 2, 3)), ); - }); + }, + skip: + 'FirebaseError: Tried to deserialize key from different project: react-native-firebase-testing vs flutterfire-e2e-tests'); }); } diff --git a/packages/cloud_firestore_odm/example/lib/integration.g.dart b/packages/cloud_firestore_odm/example/lib/integration.g.dart index 0ea7bee..3ad08ff 100644 --- a/packages/cloud_firestore_odm/example/lib/integration.g.dart +++ b/packages/cloud_firestore_odm/example/lib/integration.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: type=lint, type=warning +// ignore_for_file: type=lint part of 'integration.dart'; @@ -272,7 +272,11 @@ class _$AdvancedJsonDocumentReference extends FirestoreDocumentReference< _$AdvancedJsonFieldMap['lastName']!: lastNameFieldValue, }; - transaction.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + transaction.set(castedReference, json, options); } void batchSet( @@ -290,7 +294,11 @@ class _$AdvancedJsonDocumentReference extends FirestoreDocumentReference< _$AdvancedJsonFieldMap['lastName']!: lastNameFieldValue, }; - batch.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + batch.set(castedReference, json, options); } Future update({ @@ -942,25 +950,37 @@ class _$AdvancedJsonQuery if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$AdvancedJsonPerFieldToJson.firstName(startAt as String?) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$AdvancedJsonPerFieldToJson.firstName(startAfter as String?) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$AdvancedJsonPerFieldToJson.firstName(endAt as String?) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$AdvancedJsonPerFieldToJson.firstName(endBefore as String?) + ], endBeforeDocumentSnapshot: null, ); } @@ -1015,25 +1035,37 @@ class _$AdvancedJsonQuery if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$AdvancedJsonPerFieldToJson.lastName(startAt as String?) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$AdvancedJsonPerFieldToJson.lastName(startAfter as String?) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$AdvancedJsonPerFieldToJson.lastName(endAt as String?) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$AdvancedJsonPerFieldToJson.lastName(endBefore as String?) + ], endBeforeDocumentSnapshot: null, ); } @@ -1406,7 +1438,11 @@ class _$_PrivateAdvancedJsonDocumentReference _$PrivateAdvancedJsonFieldMap['lastName']!: lastNameFieldValue, }; - transaction.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + transaction.set(castedReference, json, options); } void batchSet( @@ -1424,7 +1460,11 @@ class _$_PrivateAdvancedJsonDocumentReference _$PrivateAdvancedJsonFieldMap['lastName']!: lastNameFieldValue, }; - batch.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + batch.set(castedReference, json, options); } Future update({ @@ -2088,25 +2128,37 @@ class _$_PrivateAdvancedJsonQuery extends QueryReference<_PrivateAdvancedJson, if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$PrivateAdvancedJsonPerFieldToJson.firstName(startAt as String?) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$PrivateAdvancedJsonPerFieldToJson.firstName(startAfter as String?) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$PrivateAdvancedJsonPerFieldToJson.firstName(endAt as String?) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$PrivateAdvancedJsonPerFieldToJson.firstName(endBefore as String?) + ], endBeforeDocumentSnapshot: null, ); } @@ -2162,25 +2214,37 @@ class _$_PrivateAdvancedJsonQuery extends QueryReference<_PrivateAdvancedJson, if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$PrivateAdvancedJsonPerFieldToJson.lastName(startAt as String?) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$PrivateAdvancedJsonPerFieldToJson.lastName(startAfter as String?) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$PrivateAdvancedJsonPerFieldToJson.lastName(endAt as String?) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$PrivateAdvancedJsonPerFieldToJson.lastName(endBefore as String?) + ], endBeforeDocumentSnapshot: null, ); } diff --git a/packages/cloud_firestore_odm/example/lib/integration/enums.g.dart b/packages/cloud_firestore_odm/example/lib/integration/enums.g.dart index 6946dff..20a9ff6 100644 --- a/packages/cloud_firestore_odm/example/lib/integration/enums.g.dart +++ b/packages/cloud_firestore_odm/example/lib/integration/enums.g.dart @@ -312,7 +312,11 @@ class _$EnumsDocumentReference _$EnumsFieldMap['nullableEnumList']!: nullableEnumListFieldValue, }; - transaction.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + transaction.set(castedReference, json, options); } void batchSet( @@ -338,7 +342,11 @@ class _$EnumsDocumentReference _$EnumsFieldMap['nullableEnumList']!: nullableEnumListFieldValue, }; - batch.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + batch.set(castedReference, json, options); } Future update({ @@ -1303,25 +1311,37 @@ class _$EnumsQuery extends QueryReference if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$EnumsPerFieldToJson.id(startAt as String) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$EnumsPerFieldToJson.id(startAfter as String) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$EnumsPerFieldToJson.id(endAt as String) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$EnumsPerFieldToJson.id(endBefore as String) + ], endBeforeDocumentSnapshot: null, ); } @@ -1376,25 +1396,37 @@ class _$EnumsQuery extends QueryReference if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$EnumsPerFieldToJson.enumValue(startAt as TestEnum) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$EnumsPerFieldToJson.enumValue(startAfter as TestEnum) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$EnumsPerFieldToJson.enumValue(endAt as TestEnum) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$EnumsPerFieldToJson.enumValue(endBefore as TestEnum) + ], endBeforeDocumentSnapshot: null, ); } @@ -1449,25 +1481,37 @@ class _$EnumsQuery extends QueryReference if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$EnumsPerFieldToJson.nullableEnumValue(startAt as TestEnum?) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$EnumsPerFieldToJson.nullableEnumValue(startAfter as TestEnum?) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$EnumsPerFieldToJson.nullableEnumValue(endAt as TestEnum?) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$EnumsPerFieldToJson.nullableEnumValue(endBefore as TestEnum?) + ], endBeforeDocumentSnapshot: null, ); } @@ -1522,25 +1566,37 @@ class _$EnumsQuery extends QueryReference if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$EnumsPerFieldToJson.enumList(startAt as List) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$EnumsPerFieldToJson.enumList(startAfter as List) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$EnumsPerFieldToJson.enumList(endAt as List) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$EnumsPerFieldToJson.enumList(endBefore as List) + ], endBeforeDocumentSnapshot: null, ); } @@ -1595,25 +1651,37 @@ class _$EnumsQuery extends QueryReference if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$EnumsPerFieldToJson.nullableEnumList(startAt as List?) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$EnumsPerFieldToJson.nullableEnumList(startAfter as List?) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$EnumsPerFieldToJson.nullableEnumList(endAt as List?) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$EnumsPerFieldToJson.nullableEnumList(endBefore as List?) + ], endBeforeDocumentSnapshot: null, ); } diff --git a/packages/cloud_firestore_odm/example/lib/integration/freezed.dart b/packages/cloud_firestore_odm/example/lib/integration/freezed.dart index 4453f8b..483385a 100644 --- a/packages/cloud_firestore_odm/example/lib/integration/freezed.dart +++ b/packages/cloud_firestore_odm/example/lib/integration/freezed.dart @@ -13,7 +13,7 @@ part 'freezed.g.dart'; @Collection('freezed-test') @freezed -class Person with _$Person { +abstract class Person with _$Person { @JsonSerializable(fieldRename: FieldRename.snake) factory Person({ required String firstName, @@ -28,7 +28,7 @@ final personRef = PersonCollectionReference(); @Collection('freezed-test') @freezed -class PublicRedirected with _$PublicRedirected { +abstract class PublicRedirected with _$PublicRedirected { factory PublicRedirected({required String value}) = PublicRedirected2; factory PublicRedirected.fromJson(Map json) => diff --git a/packages/cloud_firestore_odm/example/lib/integration/freezed.freezed.dart b/packages/cloud_firestore_odm/example/lib/integration/freezed.freezed.dart index 5c1d22c..cbe46b2 100644 --- a/packages/cloud_firestore_odm/example/lib/integration/freezed.freezed.dart +++ b/packages/cloud_firestore_odm/example/lib/integration/freezed.freezed.dart @@ -1,5 +1,5 @@ -// coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND +// coverage:ignore-file // ignore_for_file: type=lint // 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, invalid_annotation_target, unnecessary_question_mark @@ -9,85 +9,53 @@ part of 'freezed.dart'; // FreezedGenerator // ************************************************************************** +// dart format off T _$identity(T value) => value; -final _privateConstructorUsedError = UnsupportedError( - 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); - -Person _$PersonFromJson(Map json) { - return _Person.fromJson(json); -} - /// @nodoc mixin _$Person { - String get firstName => throw _privateConstructorUsedError; + String get firstName; @JsonKey(name: 'LAST_NAME') - String get lastName => throw _privateConstructorUsedError; + String get lastName; @JsonKey(includeFromJson: false, includeToJson: false) - int? get ignored => throw _privateConstructorUsedError; - - /// Serializes this Person to a JSON map. - Map toJson() => throw _privateConstructorUsedError; + int? get ignored; /// Create a copy of Person /// with the given fields replaced by the non-null parameter values. @JsonKey(includeFromJson: false, includeToJson: false) - $PersonCopyWith get copyWith => throw _privateConstructorUsedError; -} + @pragma('vm:prefer-inline') + $PersonCopyWith get copyWith => + _$PersonCopyWithImpl(this as Person, _$identity); -/// @nodoc -abstract class $PersonCopyWith<$Res> { - factory $PersonCopyWith(Person value, $Res Function(Person) then) = - _$PersonCopyWithImpl<$Res, Person>; - @useResult - $Res call( - {String firstName, - @JsonKey(name: 'LAST_NAME') String lastName, - @JsonKey(includeFromJson: false, includeToJson: false) int? ignored}); -} + /// Serializes this Person to a JSON map. + Map toJson(); -/// @nodoc -class _$PersonCopyWithImpl<$Res, $Val extends Person> - implements $PersonCopyWith<$Res> { - _$PersonCopyWithImpl(this._value, this._then); + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is Person && + (identical(other.firstName, firstName) || + other.firstName == firstName) && + (identical(other.lastName, lastName) || + other.lastName == lastName) && + (identical(other.ignored, ignored) || other.ignored == ignored)); + } - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash(runtimeType, firstName, lastName, ignored); - /// Create a copy of Person - /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') @override - $Res call({ - Object? firstName = null, - Object? lastName = null, - Object? ignored = freezed, - }) { - return _then(_value.copyWith( - firstName: null == firstName - ? _value.firstName - : firstName // ignore: cast_nullable_to_non_nullable - as String, - lastName: null == lastName - ? _value.lastName - : lastName // ignore: cast_nullable_to_non_nullable - as String, - ignored: freezed == ignored - ? _value.ignored - : ignored // ignore: cast_nullable_to_non_nullable - as int?, - ) as $Val); + String toString() { + return 'Person(firstName: $firstName, lastName: $lastName, ignored: $ignored)'; } } /// @nodoc -abstract class _$$PersonImplCopyWith<$Res> implements $PersonCopyWith<$Res> { - factory _$$PersonImplCopyWith( - _$PersonImpl value, $Res Function(_$PersonImpl) then) = - __$$PersonImplCopyWithImpl<$Res>; - @override +abstract mixin class $PersonCopyWith<$Res> { + factory $PersonCopyWith(Person value, $Res Function(Person) _then) = + _$PersonCopyWithImpl; @useResult $Res call( {String firstName, @@ -96,12 +64,11 @@ abstract class _$$PersonImplCopyWith<$Res> implements $PersonCopyWith<$Res> { } /// @nodoc -class __$$PersonImplCopyWithImpl<$Res> - extends _$PersonCopyWithImpl<$Res, _$PersonImpl> - implements _$$PersonImplCopyWith<$Res> { - __$$PersonImplCopyWithImpl( - _$PersonImpl _value, $Res Function(_$PersonImpl) _then) - : super(_value, _then); +class _$PersonCopyWithImpl<$Res> implements $PersonCopyWith<$Res> { + _$PersonCopyWithImpl(this._self, this._then); + + final Person _self; + final $Res Function(Person) _then; /// Create a copy of Person /// with the given fields replaced by the non-null parameter values. @@ -112,34 +79,203 @@ class __$$PersonImplCopyWithImpl<$Res> Object? lastName = null, Object? ignored = freezed, }) { - return _then(_$PersonImpl( + return _then(_self.copyWith( firstName: null == firstName - ? _value.firstName + ? _self.firstName : firstName // ignore: cast_nullable_to_non_nullable as String, lastName: null == lastName - ? _value.lastName + ? _self.lastName : lastName // ignore: cast_nullable_to_non_nullable as String, ignored: freezed == ignored - ? _value.ignored + ? _self.ignored : ignored // ignore: cast_nullable_to_non_nullable as int?, )); } } +/// Adds pattern-matching-related methods to [Person]. +extension PersonPatterns on Person { + /// A variant of `map` that fallback to returning `orElse`. + /// + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case final Subclass value: + /// return ...; + /// case _: + /// return orElse(); + /// } + /// ``` + + @optionalTypeArgs + TResult maybeMap( + TResult Function(_Person value)? $default, { + required TResult orElse(), + }) { + final _that = this; + switch (_that) { + case _Person() when $default != null: + return $default(_that); + case _: + return orElse(); + } + } + + /// A `switch`-like method, using callbacks. + /// + /// Callbacks receives the raw object, upcasted. + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case final Subclass value: + /// return ...; + /// case final Subclass2 value: + /// return ...; + /// } + /// ``` + + @optionalTypeArgs + TResult map( + TResult Function(_Person value) $default, + ) { + final _that = this; + switch (_that) { + case _Person(): + return $default(_that); + case _: + throw StateError('Unexpected subclass'); + } + } + + /// A variant of `map` that fallback to returning `null`. + /// + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case final Subclass value: + /// return ...; + /// case _: + /// return null; + /// } + /// ``` + + @optionalTypeArgs + TResult? mapOrNull( + TResult? Function(_Person value)? $default, + ) { + final _that = this; + switch (_that) { + case _Person() when $default != null: + return $default(_that); + case _: + return null; + } + } + + /// A variant of `when` that fallback to an `orElse` callback. + /// + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case Subclass(:final field): + /// return ...; + /// case _: + /// return orElse(); + /// } + /// ``` + + @optionalTypeArgs + TResult maybeWhen( + TResult Function( + String firstName, + @JsonKey(name: 'LAST_NAME') String lastName, + @JsonKey(includeFromJson: false, includeToJson: false) + int? ignored)? + $default, { + required TResult orElse(), + }) { + final _that = this; + switch (_that) { + case _Person() when $default != null: + return $default(_that.firstName, _that.lastName, _that.ignored); + case _: + return orElse(); + } + } + + /// A `switch`-like method, using callbacks. + /// + /// As opposed to `map`, this offers destructuring. + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case Subclass(:final field): + /// return ...; + /// case Subclass2(:final field2): + /// return ...; + /// } + /// ``` + + @optionalTypeArgs + TResult when( + TResult Function( + String firstName, + @JsonKey(name: 'LAST_NAME') String lastName, + @JsonKey(includeFromJson: false, includeToJson: false) int? ignored) + $default, + ) { + final _that = this; + switch (_that) { + case _Person(): + return $default(_that.firstName, _that.lastName, _that.ignored); + case _: + throw StateError('Unexpected subclass'); + } + } + + /// A variant of `when` that fallback to returning `null` + /// + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case Subclass(:final field): + /// return ...; + /// case _: + /// return null; + /// } + /// ``` + + @optionalTypeArgs + TResult? whenOrNull( + TResult? Function( + String firstName, + @JsonKey(name: 'LAST_NAME') String lastName, + @JsonKey(includeFromJson: false, includeToJson: false) + int? ignored)? + $default, + ) { + final _that = this; + switch (_that) { + case _Person() when $default != null: + return $default(_that.firstName, _that.lastName, _that.ignored); + case _: + return null; + } + } +} + /// @nodoc @JsonSerializable(fieldRename: FieldRename.snake) -class _$PersonImpl implements _Person { - _$PersonImpl( +class _Person implements Person { + _Person( {required this.firstName, @JsonKey(name: 'LAST_NAME') required this.lastName, @JsonKey(includeFromJson: false, includeToJson: false) this.ignored}); - - factory _$PersonImpl.fromJson(Map json) => - _$$PersonImplFromJson(json); + factory _Person.fromJson(Map json) => _$PersonFromJson(json); @override final String firstName; @@ -150,16 +286,26 @@ class _$PersonImpl implements _Person { @JsonKey(includeFromJson: false, includeToJson: false) final int? ignored; + /// Create a copy of Person + /// with the given fields replaced by the non-null parameter values. @override - String toString() { - return 'Person(firstName: $firstName, lastName: $lastName, ignored: $ignored)'; + @JsonKey(includeFromJson: false, includeToJson: false) + @pragma('vm:prefer-inline') + _$PersonCopyWith<_Person> get copyWith => + __$PersonCopyWithImpl<_Person>(this, _$identity); + + @override + Map toJson() { + return _$PersonToJson( + this, + ); } @override bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _$PersonImpl && + other is _Person && (identical(other.firstName, firstName) || other.firstName == firstName) && (identical(other.lastName, lastName) || @@ -171,46 +317,55 @@ class _$PersonImpl implements _Person { @override int get hashCode => Object.hash(runtimeType, firstName, lastName, ignored); - /// Create a copy of Person - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) @override - @pragma('vm:prefer-inline') - _$$PersonImplCopyWith<_$PersonImpl> get copyWith => - __$$PersonImplCopyWithImpl<_$PersonImpl>(this, _$identity); - - @override - Map toJson() { - return _$$PersonImplToJson( - this, - ); + String toString() { + return 'Person(firstName: $firstName, lastName: $lastName, ignored: $ignored)'; } } -abstract class _Person implements Person { - factory _Person( - {required final String firstName, - @JsonKey(name: 'LAST_NAME') required final String lastName, - @JsonKey(includeFromJson: false, includeToJson: false) - final int? ignored}) = _$PersonImpl; +/// @nodoc +abstract mixin class _$PersonCopyWith<$Res> implements $PersonCopyWith<$Res> { + factory _$PersonCopyWith(_Person value, $Res Function(_Person) _then) = + __$PersonCopyWithImpl; + @override + @useResult + $Res call( + {String firstName, + @JsonKey(name: 'LAST_NAME') String lastName, + @JsonKey(includeFromJson: false, includeToJson: false) int? ignored}); +} - factory _Person.fromJson(Map json) = _$PersonImpl.fromJson; +/// @nodoc +class __$PersonCopyWithImpl<$Res> implements _$PersonCopyWith<$Res> { + __$PersonCopyWithImpl(this._self, this._then); - @override - String get firstName; - @override - @JsonKey(name: 'LAST_NAME') - String get lastName; - @override - @JsonKey(includeFromJson: false, includeToJson: false) - int? get ignored; + final _Person _self; + final $Res Function(_Person) _then; /// Create a copy of Person /// with the given fields replaced by the non-null parameter values. @override - @JsonKey(includeFromJson: false, includeToJson: false) - _$$PersonImplCopyWith<_$PersonImpl> get copyWith => - throw _privateConstructorUsedError; + @pragma('vm:prefer-inline') + $Res call({ + Object? firstName = null, + Object? lastName = null, + Object? ignored = freezed, + }) { + return _then(_Person( + firstName: null == firstName + ? _self.firstName + : firstName // ignore: cast_nullable_to_non_nullable + as String, + lastName: null == lastName + ? _self.lastName + : lastName // ignore: cast_nullable_to_non_nullable + as String, + ignored: freezed == ignored + ? _self.ignored + : ignored // ignore: cast_nullable_to_non_nullable + as int?, + )); + } } PublicRedirected _$PublicRedirectedFromJson(Map json) { @@ -219,36 +374,53 @@ PublicRedirected _$PublicRedirectedFromJson(Map json) { /// @nodoc mixin _$PublicRedirected { - String get value => throw _privateConstructorUsedError; - - /// Serializes this PublicRedirected to a JSON map. - Map toJson() => throw _privateConstructorUsedError; + String get value; /// Create a copy of PublicRedirected /// with the given fields replaced by the non-null parameter values. @JsonKey(includeFromJson: false, includeToJson: false) + @pragma('vm:prefer-inline') $PublicRedirectedCopyWith get copyWith => - throw _privateConstructorUsedError; + _$PublicRedirectedCopyWithImpl( + this as PublicRedirected, _$identity); + + /// Serializes this PublicRedirected to a JSON map. + Map toJson(); + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is PublicRedirected && + (identical(other.value, value) || other.value == value)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash(runtimeType, value); + + @override + String toString() { + return 'PublicRedirected(value: $value)'; + } } /// @nodoc -abstract class $PublicRedirectedCopyWith<$Res> { +abstract mixin class $PublicRedirectedCopyWith<$Res> { factory $PublicRedirectedCopyWith( - PublicRedirected value, $Res Function(PublicRedirected) then) = - _$PublicRedirectedCopyWithImpl<$Res, PublicRedirected>; + PublicRedirected value, $Res Function(PublicRedirected) _then) = + _$PublicRedirectedCopyWithImpl; @useResult $Res call({String value}); } /// @nodoc -class _$PublicRedirectedCopyWithImpl<$Res, $Val extends PublicRedirected> +class _$PublicRedirectedCopyWithImpl<$Res> implements $PublicRedirectedCopyWith<$Res> { - _$PublicRedirectedCopyWithImpl(this._value, this._then); + _$PublicRedirectedCopyWithImpl(this._self, this._then); - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; + final PublicRedirected _self; + final $Res Function(PublicRedirected) _then; /// Create a copy of PublicRedirected /// with the given fields replaced by the non-null parameter values. @@ -257,71 +429,202 @@ class _$PublicRedirectedCopyWithImpl<$Res, $Val extends PublicRedirected> $Res call({ Object? value = null, }) { - return _then(_value.copyWith( + return _then(_self.copyWith( value: null == value - ? _value.value + ? _self.value : value // ignore: cast_nullable_to_non_nullable as String, - ) as $Val); + )); } } -/// @nodoc -abstract class _$$PublicRedirected2ImplCopyWith<$Res> - implements $PublicRedirectedCopyWith<$Res> { - factory _$$PublicRedirected2ImplCopyWith(_$PublicRedirected2Impl value, - $Res Function(_$PublicRedirected2Impl) then) = - __$$PublicRedirected2ImplCopyWithImpl<$Res>; - @override - @useResult - $Res call({String value}); -} +/// Adds pattern-matching-related methods to [PublicRedirected]. +extension PublicRedirectedPatterns on PublicRedirected { + /// A variant of `map` that fallback to returning `orElse`. + /// + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case final Subclass value: + /// return ...; + /// case _: + /// return orElse(); + /// } + /// ``` + + @optionalTypeArgs + TResult maybeMap( + TResult Function(PublicRedirected2 value)? $default, { + required TResult orElse(), + }) { + final _that = this; + switch (_that) { + case PublicRedirected2() when $default != null: + return $default(_that); + case _: + return orElse(); + } + } -/// @nodoc -class __$$PublicRedirected2ImplCopyWithImpl<$Res> - extends _$PublicRedirectedCopyWithImpl<$Res, _$PublicRedirected2Impl> - implements _$$PublicRedirected2ImplCopyWith<$Res> { - __$$PublicRedirected2ImplCopyWithImpl(_$PublicRedirected2Impl _value, - $Res Function(_$PublicRedirected2Impl) _then) - : super(_value, _then); + /// A `switch`-like method, using callbacks. + /// + /// Callbacks receives the raw object, upcasted. + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case final Subclass value: + /// return ...; + /// case final Subclass2 value: + /// return ...; + /// } + /// ``` + + @optionalTypeArgs + TResult map( + TResult Function(PublicRedirected2 value) $default, + ) { + final _that = this; + switch (_that) { + case PublicRedirected2(): + return $default(_that); + case _: + throw StateError('Unexpected subclass'); + } + } - /// Create a copy of PublicRedirected - /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? value = null, + /// A variant of `map` that fallback to returning `null`. + /// + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case final Subclass value: + /// return ...; + /// case _: + /// return null; + /// } + /// ``` + + @optionalTypeArgs + TResult? mapOrNull( + TResult? Function(PublicRedirected2 value)? $default, + ) { + final _that = this; + switch (_that) { + case PublicRedirected2() when $default != null: + return $default(_that); + case _: + return null; + } + } + + /// A variant of `when` that fallback to an `orElse` callback. + /// + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case Subclass(:final field): + /// return ...; + /// case _: + /// return orElse(); + /// } + /// ``` + + @optionalTypeArgs + TResult maybeWhen( + TResult Function(String value)? $default, { + required TResult orElse(), }) { - return _then(_$PublicRedirected2Impl( - value: null == value - ? _value.value - : value // ignore: cast_nullable_to_non_nullable - as String, - )); + final _that = this; + switch (_that) { + case PublicRedirected2() when $default != null: + return $default(_that.value); + case _: + return orElse(); + } + } + + /// A `switch`-like method, using callbacks. + /// + /// As opposed to `map`, this offers destructuring. + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case Subclass(:final field): + /// return ...; + /// case Subclass2(:final field2): + /// return ...; + /// } + /// ``` + + @optionalTypeArgs + TResult when( + TResult Function(String value) $default, + ) { + final _that = this; + switch (_that) { + case PublicRedirected2(): + return $default(_that.value); + case _: + throw StateError('Unexpected subclass'); + } + } + + /// A variant of `when` that fallback to returning `null` + /// + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case Subclass(:final field): + /// return ...; + /// case _: + /// return null; + /// } + /// ``` + + @optionalTypeArgs + TResult? whenOrNull( + TResult? Function(String value)? $default, + ) { + final _that = this; + switch (_that) { + case PublicRedirected2() when $default != null: + return $default(_that.value); + case _: + return null; + } } } /// @nodoc @JsonSerializable() -class _$PublicRedirected2Impl implements PublicRedirected2 { - _$PublicRedirected2Impl({required this.value}); - - factory _$PublicRedirected2Impl.fromJson(Map json) => - _$$PublicRedirected2ImplFromJson(json); +class PublicRedirected2 implements PublicRedirected { + PublicRedirected2({required this.value}); + factory PublicRedirected2.fromJson(Map json) => + _$PublicRedirected2FromJson(json); @override final String value; + /// Create a copy of PublicRedirected + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + @pragma('vm:prefer-inline') + $PublicRedirected2CopyWith get copyWith => + _$PublicRedirected2CopyWithImpl(this, _$identity); + @override - String toString() { - return 'PublicRedirected(value: $value)'; + Map toJson() { + return _$PublicRedirected2ToJson( + this, + ); } @override bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _$PublicRedirected2Impl && + other is PublicRedirected2 && (identical(other.value, value) || other.value == value)); } @@ -329,37 +632,45 @@ class _$PublicRedirected2Impl implements PublicRedirected2 { @override int get hashCode => Object.hash(runtimeType, value); - /// Create a copy of PublicRedirected - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) @override - @pragma('vm:prefer-inline') - _$$PublicRedirected2ImplCopyWith<_$PublicRedirected2Impl> get copyWith => - __$$PublicRedirected2ImplCopyWithImpl<_$PublicRedirected2Impl>( - this, _$identity); + String toString() { + return 'PublicRedirected(value: $value)'; + } +} +/// @nodoc +abstract mixin class $PublicRedirected2CopyWith<$Res> + implements $PublicRedirectedCopyWith<$Res> { + factory $PublicRedirected2CopyWith( + PublicRedirected2 value, $Res Function(PublicRedirected2) _then) = + _$PublicRedirected2CopyWithImpl; @override - Map toJson() { - return _$$PublicRedirected2ImplToJson( - this, - ); - } + @useResult + $Res call({String value}); } -abstract class PublicRedirected2 implements PublicRedirected { - factory PublicRedirected2({required final String value}) = - _$PublicRedirected2Impl; +/// @nodoc +class _$PublicRedirected2CopyWithImpl<$Res> + implements $PublicRedirected2CopyWith<$Res> { + _$PublicRedirected2CopyWithImpl(this._self, this._then); - factory PublicRedirected2.fromJson(Map json) = - _$PublicRedirected2Impl.fromJson; - - @override - String get value; + final PublicRedirected2 _self; + final $Res Function(PublicRedirected2) _then; /// Create a copy of PublicRedirected /// with the given fields replaced by the non-null parameter values. @override - @JsonKey(includeFromJson: false, includeToJson: false) - _$$PublicRedirected2ImplCopyWith<_$PublicRedirected2Impl> get copyWith => - throw _privateConstructorUsedError; + @pragma('vm:prefer-inline') + $Res call({ + Object? value = null, + }) { + return _then(PublicRedirected2( + value: null == value + ? _self.value + : value // ignore: cast_nullable_to_non_nullable + as String, + )); + } } + +// dart format on diff --git a/packages/cloud_firestore_odm/example/lib/integration/freezed.g.dart b/packages/cloud_firestore_odm/example/lib/integration/freezed.g.dart index 9f9482d..87b2361 100644 --- a/packages/cloud_firestore_odm/example/lib/integration/freezed.g.dart +++ b/packages/cloud_firestore_odm/example/lib/integration/freezed.g.dart @@ -242,9 +242,9 @@ class _$PersonDocumentReference final json = { ...model.toJson(), if (firstNameFieldValue != null) - _$$PersonImplFieldMap['firstName']!: firstNameFieldValue, + _$PersonFieldMap['firstName']!: firstNameFieldValue, if (lastNameFieldValue != null) - _$$PersonImplFieldMap['lastName']!: lastNameFieldValue, + _$PersonFieldMap['lastName']!: lastNameFieldValue, }; final castedReference = reference.withConverter>( @@ -264,12 +264,16 @@ class _$PersonDocumentReference final json = { ...model.toJson(), if (firstNameFieldValue != null) - _$$PersonImplFieldMap['firstName']!: firstNameFieldValue, + _$PersonFieldMap['firstName']!: firstNameFieldValue, if (lastNameFieldValue != null) - _$$PersonImplFieldMap['lastName']!: lastNameFieldValue, + _$PersonFieldMap['lastName']!: lastNameFieldValue, }; - transaction.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + transaction.set(castedReference, json, options); } void batchSet( @@ -282,12 +286,16 @@ class _$PersonDocumentReference final json = { ...model.toJson(), if (firstNameFieldValue != null) - _$$PersonImplFieldMap['firstName']!: firstNameFieldValue, + _$PersonFieldMap['firstName']!: firstNameFieldValue, if (lastNameFieldValue != null) - _$$PersonImplFieldMap['lastName']!: lastNameFieldValue, + _$PersonFieldMap['lastName']!: lastNameFieldValue, }; - batch.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + batch.set(castedReference, json, options); } Future update({ @@ -306,15 +314,15 @@ class _$PersonDocumentReference ); final json = { if (firstName != _sentinel) - _$$PersonImplFieldMap['firstName']!: - _$$PersonImplPerFieldToJson.firstName(firstName as String), + _$PersonFieldMap['firstName']!: + _$PersonPerFieldToJson.firstName(firstName as String), if (firstNameFieldValue != null) - _$$PersonImplFieldMap['firstName']!: firstNameFieldValue, + _$PersonFieldMap['firstName']!: firstNameFieldValue, if (lastName != _sentinel) - _$$PersonImplFieldMap['lastName']!: - _$$PersonImplPerFieldToJson.lastName(lastName as String), + _$PersonFieldMap['lastName']!: + _$PersonPerFieldToJson.lastName(lastName as String), if (lastNameFieldValue != null) - _$$PersonImplFieldMap['lastName']!: lastNameFieldValue, + _$PersonFieldMap['lastName']!: lastNameFieldValue, }; return reference.update(json); @@ -337,15 +345,15 @@ class _$PersonDocumentReference ); final json = { if (firstName != _sentinel) - _$$PersonImplFieldMap['firstName']!: - _$$PersonImplPerFieldToJson.firstName(firstName as String), + _$PersonFieldMap['firstName']!: + _$PersonPerFieldToJson.firstName(firstName as String), if (firstNameFieldValue != null) - _$$PersonImplFieldMap['firstName']!: firstNameFieldValue, + _$PersonFieldMap['firstName']!: firstNameFieldValue, if (lastName != _sentinel) - _$$PersonImplFieldMap['lastName']!: - _$$PersonImplPerFieldToJson.lastName(lastName as String), + _$PersonFieldMap['lastName']!: + _$PersonPerFieldToJson.lastName(lastName as String), if (lastNameFieldValue != null) - _$$PersonImplFieldMap['lastName']!: lastNameFieldValue, + _$PersonFieldMap['lastName']!: lastNameFieldValue, }; transaction.update(reference, json); @@ -368,15 +376,15 @@ class _$PersonDocumentReference ); final json = { if (firstName != _sentinel) - _$$PersonImplFieldMap['firstName']!: - _$$PersonImplPerFieldToJson.firstName(firstName as String), + _$PersonFieldMap['firstName']!: + _$PersonPerFieldToJson.firstName(firstName as String), if (firstNameFieldValue != null) - _$$PersonImplFieldMap['firstName']!: firstNameFieldValue, + _$PersonFieldMap['firstName']!: firstNameFieldValue, if (lastName != _sentinel) - _$$PersonImplFieldMap['lastName']!: - _$$PersonImplPerFieldToJson.lastName(lastName as String), + _$PersonFieldMap['lastName']!: + _$PersonPerFieldToJson.lastName(lastName as String), if (lastNameFieldValue != null) - _$$PersonImplFieldMap['lastName']!: lastNameFieldValue, + _$PersonFieldMap['lastName']!: lastNameFieldValue, }; batch.update(reference, json); @@ -665,30 +673,27 @@ class _$PersonQuery extends QueryReference return _$PersonQuery( _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( - _$$PersonImplFieldMap['firstName']!, + _$PersonFieldMap['firstName']!, isEqualTo: isEqualTo != _sentinel - ? _$$PersonImplPerFieldToJson.firstName(isEqualTo as String) + ? _$PersonPerFieldToJson.firstName(isEqualTo as String) : null, isNotEqualTo: isNotEqualTo != _sentinel - ? _$$PersonImplPerFieldToJson.firstName(isNotEqualTo as String) + ? _$PersonPerFieldToJson.firstName(isNotEqualTo as String) : null, isLessThan: isLessThan != null - ? _$$PersonImplPerFieldToJson.firstName(isLessThan as String) + ? _$PersonPerFieldToJson.firstName(isLessThan as String) : null, isLessThanOrEqualTo: isLessThanOrEqualTo != null - ? _$$PersonImplPerFieldToJson - .firstName(isLessThanOrEqualTo as String) + ? _$PersonPerFieldToJson.firstName(isLessThanOrEqualTo as String) : null, isGreaterThan: isGreaterThan != null - ? _$$PersonImplPerFieldToJson.firstName(isGreaterThan as String) + ? _$PersonPerFieldToJson.firstName(isGreaterThan as String) : null, isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null - ? _$$PersonImplPerFieldToJson - .firstName(isGreaterThanOrEqualTo as String) + ? _$PersonPerFieldToJson.firstName(isGreaterThanOrEqualTo as String) : null, - whereIn: whereIn?.map((e) => _$$PersonImplPerFieldToJson.firstName(e)), - whereNotIn: - whereNotIn?.map((e) => _$$PersonImplPerFieldToJson.firstName(e)), + whereIn: whereIn?.map((e) => _$PersonPerFieldToJson.firstName(e)), + whereNotIn: whereNotIn?.map((e) => _$PersonPerFieldToJson.firstName(e)), isNull: isNull ?? (isEqualTo == null ? false : null) ?? (isNotEqualTo == null ? true : null), @@ -712,30 +717,27 @@ class _$PersonQuery extends QueryReference return _$PersonQuery( _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( - _$$PersonImplFieldMap['lastName']!, + _$PersonFieldMap['lastName']!, isEqualTo: isEqualTo != _sentinel - ? _$$PersonImplPerFieldToJson.lastName(isEqualTo as String) + ? _$PersonPerFieldToJson.lastName(isEqualTo as String) : null, isNotEqualTo: isNotEqualTo != _sentinel - ? _$$PersonImplPerFieldToJson.lastName(isNotEqualTo as String) + ? _$PersonPerFieldToJson.lastName(isNotEqualTo as String) : null, isLessThan: isLessThan != null - ? _$$PersonImplPerFieldToJson.lastName(isLessThan as String) + ? _$PersonPerFieldToJson.lastName(isLessThan as String) : null, isLessThanOrEqualTo: isLessThanOrEqualTo != null - ? _$$PersonImplPerFieldToJson - .lastName(isLessThanOrEqualTo as String) + ? _$PersonPerFieldToJson.lastName(isLessThanOrEqualTo as String) : null, isGreaterThan: isGreaterThan != null - ? _$$PersonImplPerFieldToJson.lastName(isGreaterThan as String) + ? _$PersonPerFieldToJson.lastName(isGreaterThan as String) : null, isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null - ? _$$PersonImplPerFieldToJson - .lastName(isGreaterThanOrEqualTo as String) + ? _$PersonPerFieldToJson.lastName(isGreaterThanOrEqualTo as String) : null, - whereIn: whereIn?.map((e) => _$$PersonImplPerFieldToJson.lastName(e)), - whereNotIn: - whereNotIn?.map((e) => _$$PersonImplPerFieldToJson.lastName(e)), + whereIn: whereIn?.map((e) => _$PersonPerFieldToJson.lastName(e)), + whereNotIn: whereNotIn?.map((e) => _$PersonPerFieldToJson.lastName(e)), isNull: isNull ?? (isEqualTo == null ? false : null) ?? (isNotEqualTo == null ? true : null), @@ -904,7 +906,7 @@ class _$PersonQuery extends QueryReference PersonDocumentSnapshot? startAfterDocument, }) { final query = $referenceWithoutCursor - .orderBy(_$$PersonImplFieldMap['firstName']!, descending: descending); + .orderBy(_$PersonFieldMap['firstName']!, descending: descending); var queryCursor = $queryCursor; if (startAtDocument != null) { @@ -934,25 +936,37 @@ class _$PersonQuery extends QueryReference if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$PersonPerFieldToJson.firstName(startAt as String) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$PersonPerFieldToJson.firstName(startAfter as String) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$PersonPerFieldToJson.firstName(endAt as String) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$PersonPerFieldToJson.firstName(endBefore as String) + ], endBeforeDocumentSnapshot: null, ); } @@ -976,8 +990,8 @@ class _$PersonQuery extends QueryReference PersonDocumentSnapshot? endBeforeDocument, PersonDocumentSnapshot? startAfterDocument, }) { - final query = $referenceWithoutCursor - .orderBy(_$$PersonImplFieldMap['lastName']!, descending: descending); + final query = $referenceWithoutCursor.orderBy(_$PersonFieldMap['lastName']!, + descending: descending); var queryCursor = $queryCursor; if (startAtDocument != null) { @@ -1007,25 +1021,37 @@ class _$PersonQuery extends QueryReference if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$PersonPerFieldToJson.lastName(startAt as String) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$PersonPerFieldToJson.lastName(startAfter as String) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$PersonPerFieldToJson.lastName(endAt as String) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$PersonPerFieldToJson.lastName(endBefore as String) + ], endBeforeDocumentSnapshot: null, ); } @@ -1350,7 +1376,7 @@ class _$PublicRedirectedDocumentReference extends FirestoreDocumentReference< final json = { ...model.toJson(), if (valueFieldValue != null) - _$$PublicRedirected2ImplFieldMap['value']!: valueFieldValue, + _$PublicRedirected2FieldMap['value']!: valueFieldValue, }; final castedReference = reference.withConverter>( @@ -1369,10 +1395,14 @@ class _$PublicRedirectedDocumentReference extends FirestoreDocumentReference< final json = { ...model.toJson(), if (valueFieldValue != null) - _$$PublicRedirected2ImplFieldMap['value']!: valueFieldValue, + _$PublicRedirected2FieldMap['value']!: valueFieldValue, }; - transaction.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + transaction.set(castedReference, json, options); } void batchSet( @@ -1384,10 +1414,14 @@ class _$PublicRedirectedDocumentReference extends FirestoreDocumentReference< final json = { ...model.toJson(), if (valueFieldValue != null) - _$$PublicRedirected2ImplFieldMap['value']!: valueFieldValue, + _$PublicRedirected2FieldMap['value']!: valueFieldValue, }; - batch.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + batch.set(castedReference, json, options); } Future update({ @@ -1400,10 +1434,10 @@ class _$PublicRedirectedDocumentReference extends FirestoreDocumentReference< ); final json = { if (value != _sentinel) - _$$PublicRedirected2ImplFieldMap['value']!: - _$$PublicRedirected2ImplPerFieldToJson.value(value as String), + _$PublicRedirected2FieldMap['value']!: + _$PublicRedirected2PerFieldToJson.value(value as String), if (valueFieldValue != null) - _$$PublicRedirected2ImplFieldMap['value']!: valueFieldValue, + _$PublicRedirected2FieldMap['value']!: valueFieldValue, }; return reference.update(json); @@ -1420,10 +1454,10 @@ class _$PublicRedirectedDocumentReference extends FirestoreDocumentReference< ); final json = { if (value != _sentinel) - _$$PublicRedirected2ImplFieldMap['value']!: - _$$PublicRedirected2ImplPerFieldToJson.value(value as String), + _$PublicRedirected2FieldMap['value']!: + _$PublicRedirected2PerFieldToJson.value(value as String), if (valueFieldValue != null) - _$$PublicRedirected2ImplFieldMap['value']!: valueFieldValue, + _$PublicRedirected2FieldMap['value']!: valueFieldValue, }; transaction.update(reference, json); @@ -1440,10 +1474,10 @@ class _$PublicRedirectedDocumentReference extends FirestoreDocumentReference< ); final json = { if (value != _sentinel) - _$$PublicRedirected2ImplFieldMap['value']!: - _$$PublicRedirected2ImplPerFieldToJson.value(value as String), + _$PublicRedirected2FieldMap['value']!: + _$PublicRedirected2PerFieldToJson.value(value as String), if (valueFieldValue != null) - _$$PublicRedirected2ImplFieldMap['value']!: valueFieldValue, + _$PublicRedirected2FieldMap['value']!: valueFieldValue, }; batch.update(reference, json); @@ -1713,33 +1747,31 @@ class _$PublicRedirectedQuery return _$PublicRedirectedQuery( _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( - _$$PublicRedirected2ImplFieldMap['value']!, + _$PublicRedirected2FieldMap['value']!, isEqualTo: isEqualTo != _sentinel - ? _$$PublicRedirected2ImplPerFieldToJson.value(isEqualTo as String) + ? _$PublicRedirected2PerFieldToJson.value(isEqualTo as String) : null, isNotEqualTo: isNotEqualTo != _sentinel - ? _$$PublicRedirected2ImplPerFieldToJson - .value(isNotEqualTo as String) + ? _$PublicRedirected2PerFieldToJson.value(isNotEqualTo as String) : null, isLessThan: isLessThan != null - ? _$$PublicRedirected2ImplPerFieldToJson.value(isLessThan as String) + ? _$PublicRedirected2PerFieldToJson.value(isLessThan as String) : null, isLessThanOrEqualTo: isLessThanOrEqualTo != null - ? _$$PublicRedirected2ImplPerFieldToJson + ? _$PublicRedirected2PerFieldToJson .value(isLessThanOrEqualTo as String) : null, isGreaterThan: isGreaterThan != null - ? _$$PublicRedirected2ImplPerFieldToJson - .value(isGreaterThan as String) + ? _$PublicRedirected2PerFieldToJson.value(isGreaterThan as String) : null, isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null - ? _$$PublicRedirected2ImplPerFieldToJson + ? _$PublicRedirected2PerFieldToJson .value(isGreaterThanOrEqualTo as String) : null, - whereIn: whereIn - ?.map((e) => _$$PublicRedirected2ImplPerFieldToJson.value(e)), - whereNotIn: whereNotIn - ?.map((e) => _$$PublicRedirected2ImplPerFieldToJson.value(e)), + whereIn: + whereIn?.map((e) => _$PublicRedirected2PerFieldToJson.value(e)), + whereNotIn: + whereNotIn?.map((e) => _$PublicRedirected2PerFieldToJson.value(e)), isNull: isNull ?? (isEqualTo == null ? false : null) ?? (isNotEqualTo == null ? true : null), @@ -1907,9 +1939,8 @@ class _$PublicRedirectedQuery PublicRedirectedDocumentSnapshot? endBeforeDocument, PublicRedirectedDocumentSnapshot? startAfterDocument, }) { - final query = $referenceWithoutCursor.orderBy( - _$$PublicRedirected2ImplFieldMap['value']!, - descending: descending); + final query = $referenceWithoutCursor + .orderBy(_$PublicRedirected2FieldMap['value']!, descending: descending); var queryCursor = $queryCursor; if (startAtDocument != null) { @@ -1939,25 +1970,37 @@ class _$PublicRedirectedQuery if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$PublicRedirected2PerFieldToJson.value(startAt as String) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$PublicRedirected2PerFieldToJson.value(startAfter as String) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$PublicRedirected2PerFieldToJson.value(endAt as String) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$PublicRedirected2PerFieldToJson.value(endBefore as String) + ], endBeforeDocumentSnapshot: null, ); } @@ -2072,48 +2115,45 @@ class PublicRedirectedQueryDocumentSnapshot // JsonSerializableGenerator // ************************************************************************** -_$PersonImpl _$$PersonImplFromJson(Map json) => _$PersonImpl( +_Person _$PersonFromJson(Map json) => _Person( firstName: json['first_name'] as String, lastName: json['LAST_NAME'] as String, ); -const _$$PersonImplFieldMap = { +const _$PersonFieldMap = { 'firstName': 'first_name', 'lastName': 'LAST_NAME', }; // ignore: unused_element -abstract class _$$PersonImplPerFieldToJson { +abstract class _$PersonPerFieldToJson { // ignore: unused_element static Object? firstName(String instance) => instance; // ignore: unused_element static Object? lastName(String instance) => instance; } -Map _$$PersonImplToJson(_$PersonImpl instance) => - { +Map _$PersonToJson(_Person instance) => { 'first_name': instance.firstName, 'LAST_NAME': instance.lastName, }; -_$PublicRedirected2Impl _$$PublicRedirected2ImplFromJson( - Map json) => - _$PublicRedirected2Impl( +PublicRedirected2 _$PublicRedirected2FromJson(Map json) => + PublicRedirected2( value: json['value'] as String, ); -const _$$PublicRedirected2ImplFieldMap = { +const _$PublicRedirected2FieldMap = { 'value': 'value', }; // ignore: unused_element -abstract class _$$PublicRedirected2ImplPerFieldToJson { +abstract class _$PublicRedirected2PerFieldToJson { // ignore: unused_element static Object? value(String instance) => instance; } -Map _$$PublicRedirected2ImplToJson( - _$PublicRedirected2Impl instance) => +Map _$PublicRedirected2ToJson(PublicRedirected2 instance) => { 'value': instance.value, }; diff --git a/packages/cloud_firestore_odm/example/lib/integration/named_query.g.dart b/packages/cloud_firestore_odm/example/lib/integration/named_query.g.dart index 0b91d2f..c5dee3e 100644 --- a/packages/cloud_firestore_odm/example/lib/integration/named_query.g.dart +++ b/packages/cloud_firestore_odm/example/lib/integration/named_query.g.dart @@ -273,7 +273,11 @@ class _$ConflictDocumentReference _$ConflictFieldMap['number']!: numberFieldValue, }; - transaction.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + transaction.set(castedReference, json, options); } void batchSet( @@ -288,7 +292,11 @@ class _$ConflictDocumentReference _$ConflictFieldMap['number']!: numberFieldValue, }; - batch.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + batch.set(castedReference, json, options); } Future update({ @@ -830,25 +838,37 @@ class _$ConflictQuery extends QueryReference if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$ConflictPerFieldToJson.number(startAt as num) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$ConflictPerFieldToJson.number(startAfter as num) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$ConflictPerFieldToJson.number(endAt as num) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$ConflictPerFieldToJson.number(endBefore as num) + ], endBeforeDocumentSnapshot: null, ); } diff --git a/packages/cloud_firestore_odm/example/lib/integration/query.g.dart b/packages/cloud_firestore_odm/example/lib/integration/query.g.dart index be83670..df80fe6 100644 --- a/packages/cloud_firestore_odm/example/lib/integration/query.g.dart +++ b/packages/cloud_firestore_odm/example/lib/integration/query.g.dart @@ -260,7 +260,11 @@ class _$DurationQueryDocumentReference extends FirestoreDocumentReference< _$DurationQueryFieldMap['duration']!: durationFieldValue, }; - transaction.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + transaction.set(castedReference, json, options); } void batchSet( @@ -275,7 +279,11 @@ class _$DurationQueryDocumentReference extends FirestoreDocumentReference< _$DurationQueryFieldMap['duration']!: durationFieldValue, }; - batch.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + batch.set(castedReference, json, options); } Future update({ @@ -823,25 +831,37 @@ class _$DurationQueryQuery if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$DurationQueryPerFieldToJson.duration(startAt as Duration) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$DurationQueryPerFieldToJson.duration(startAfter as Duration) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$DurationQueryPerFieldToJson.duration(endAt as Duration) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$DurationQueryPerFieldToJson.duration(endBefore as Duration) + ], endBeforeDocumentSnapshot: null, ); } @@ -1190,7 +1210,11 @@ class _$DateTimeQueryDocumentReference extends FirestoreDocumentReference< _$DateTimeQueryFieldMap['time']!: timeFieldValue, }; - transaction.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + transaction.set(castedReference, json, options); } void batchSet( @@ -1205,7 +1229,11 @@ class _$DateTimeQueryDocumentReference extends FirestoreDocumentReference< _$DateTimeQueryFieldMap['time']!: timeFieldValue, }; - batch.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + batch.set(castedReference, json, options); } Future update({ @@ -1753,25 +1781,37 @@ class _$DateTimeQueryQuery if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$DateTimeQueryPerFieldToJson.time(startAt as DateTime) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$DateTimeQueryPerFieldToJson.time(startAfter as DateTime) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$DateTimeQueryPerFieldToJson.time(endAt as DateTime) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$DateTimeQueryPerFieldToJson.time(endBefore as DateTime) + ], endBeforeDocumentSnapshot: null, ); } @@ -2122,7 +2162,11 @@ class _$TimestampQueryDocumentReference extends FirestoreDocumentReference< _$TimestampQueryFieldMap['time']!: timeFieldValue, }; - transaction.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + transaction.set(castedReference, json, options); } void batchSet( @@ -2137,7 +2181,11 @@ class _$TimestampQueryDocumentReference extends FirestoreDocumentReference< _$TimestampQueryFieldMap['time']!: timeFieldValue, }; - batch.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + batch.set(castedReference, json, options); } Future update({ @@ -2685,25 +2733,37 @@ class _$TimestampQueryQuery if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$TimestampQueryPerFieldToJson.time(startAt as Timestamp) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$TimestampQueryPerFieldToJson.time(startAfter as Timestamp) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$TimestampQueryPerFieldToJson.time(endAt as Timestamp) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$TimestampQueryPerFieldToJson.time(endBefore as Timestamp) + ], endBeforeDocumentSnapshot: null, ); } @@ -3055,7 +3115,11 @@ class _$GeoPointQueryDocumentReference extends FirestoreDocumentReference< _$GeoPointQueryFieldMap['point']!: pointFieldValue, }; - transaction.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + transaction.set(castedReference, json, options); } void batchSet( @@ -3070,7 +3134,11 @@ class _$GeoPointQueryDocumentReference extends FirestoreDocumentReference< _$GeoPointQueryFieldMap['point']!: pointFieldValue, }; - batch.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + batch.set(castedReference, json, options); } Future update({ @@ -3618,25 +3686,37 @@ class _$GeoPointQueryQuery if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$GeoPointQueryPerFieldToJson.point(startAt as GeoPoint) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$GeoPointQueryPerFieldToJson.point(startAfter as GeoPoint) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$GeoPointQueryPerFieldToJson.point(endAt as GeoPoint) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$GeoPointQueryPerFieldToJson.point(endBefore as GeoPoint) + ], endBeforeDocumentSnapshot: null, ); } @@ -3995,7 +4075,11 @@ class _$DocumentReferenceQueryDocumentReference _$DocumentReferenceQueryFieldMap['ref']!: refFieldValue, }; - transaction.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + transaction.set(castedReference, json, options); } void batchSet( @@ -4010,7 +4094,11 @@ class _$DocumentReferenceQueryDocumentReference _$DocumentReferenceQueryFieldMap['ref']!: refFieldValue, }; - batch.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + batch.set(castedReference, json, options); } Future update({ @@ -4570,25 +4658,41 @@ class _$DocumentReferenceQueryQuery extends QueryReference< if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$DocumentReferenceQueryPerFieldToJson + .ref(startAt as DocumentReference>) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$DocumentReferenceQueryPerFieldToJson + .ref(startAfter as DocumentReference>) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$DocumentReferenceQueryPerFieldToJson + .ref(endAt as DocumentReference>) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$DocumentReferenceQueryPerFieldToJson + .ref(endBefore as DocumentReference>) + ], endBeforeDocumentSnapshot: null, ); } diff --git a/packages/cloud_firestore_odm/example/lib/movie.g.dart b/packages/cloud_firestore_odm/example/lib/movie.g.dart index f12e30a..17aee54 100644 --- a/packages/cloud_firestore_odm/example/lib/movie.g.dart +++ b/packages/cloud_firestore_odm/example/lib/movie.g.dart @@ -323,7 +323,7 @@ class _$MovieDocumentReference final castedReference = reference.withConverter>( fromFirestore: (snapshot, options) => throw UnimplementedError(), - toFirestore: (value, options) => value, + toFirestore: (value, options) => value..remove('id'), ); return castedReference.set(json, options); } @@ -355,7 +355,11 @@ class _$MovieDocumentReference if (tagsFieldValue != null) _$MovieFieldMap['tags']!: tagsFieldValue, }; - transaction.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value..remove('id'), + ); + transaction.set(castedReference, json, options); } void batchSet( @@ -385,7 +389,11 @@ class _$MovieDocumentReference if (tagsFieldValue != null) _$MovieFieldMap['tags']!: tagsFieldValue, }; - batch.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value..remove('id'), + ); + batch.set(castedReference, json, options); } Future update({ @@ -1612,25 +1620,37 @@ class _$MovieQuery extends QueryReference if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$MoviePerFieldToJson.poster(startAt as String) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$MoviePerFieldToJson.poster(startAfter as String) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$MoviePerFieldToJson.poster(endAt as String) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$MoviePerFieldToJson.poster(endBefore as String) + ], endBeforeDocumentSnapshot: null, ); } @@ -1685,25 +1705,37 @@ class _$MovieQuery extends QueryReference if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$MoviePerFieldToJson.likes(startAt as int) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$MoviePerFieldToJson.likes(startAfter as int) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$MoviePerFieldToJson.likes(endAt as int) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$MoviePerFieldToJson.likes(endBefore as int) + ], endBeforeDocumentSnapshot: null, ); } @@ -1758,25 +1790,37 @@ class _$MovieQuery extends QueryReference if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$MoviePerFieldToJson.title(startAt as String) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$MoviePerFieldToJson.title(startAfter as String) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$MoviePerFieldToJson.title(endAt as String) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$MoviePerFieldToJson.title(endBefore as String) + ], endBeforeDocumentSnapshot: null, ); } @@ -1831,25 +1875,34 @@ class _$MovieQuery extends QueryReference if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$MoviePerFieldToJson.year(startAt as int) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$MoviePerFieldToJson.year(startAfter as int) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [...queryCursor.endAt, _$MoviePerFieldToJson.year(endAt as int)], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$MoviePerFieldToJson.year(endBefore as int) + ], endBeforeDocumentSnapshot: null, ); } @@ -1904,25 +1957,37 @@ class _$MovieQuery extends QueryReference if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$MoviePerFieldToJson.runtime(startAt as String) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$MoviePerFieldToJson.runtime(startAfter as String) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$MoviePerFieldToJson.runtime(endAt as String) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$MoviePerFieldToJson.runtime(endBefore as String) + ], endBeforeDocumentSnapshot: null, ); } @@ -1977,25 +2042,37 @@ class _$MovieQuery extends QueryReference if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$MoviePerFieldToJson.rated(startAt as String) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$MoviePerFieldToJson.rated(startAfter as String) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$MoviePerFieldToJson.rated(endAt as String) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$MoviePerFieldToJson.rated(endBefore as String) + ], endBeforeDocumentSnapshot: null, ); } @@ -2050,25 +2127,37 @@ class _$MovieQuery extends QueryReference if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$MoviePerFieldToJson.genre(startAt as List?) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$MoviePerFieldToJson.genre(startAfter as List?) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$MoviePerFieldToJson.genre(endAt as List?) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$MoviePerFieldToJson.genre(endBefore as List?) + ], endBeforeDocumentSnapshot: null, ); } @@ -2123,25 +2212,37 @@ class _$MovieQuery extends QueryReference if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$MoviePerFieldToJson.tags(startAt as Set?) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$MoviePerFieldToJson.tags(startAfter as Set?) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$MoviePerFieldToJson.tags(endAt as Set?) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$MoviePerFieldToJson.tags(endBefore as Set?) + ], endBeforeDocumentSnapshot: null, ); } @@ -2514,7 +2615,11 @@ class _$CommentDocumentReference _$CommentFieldMap['message']!: messageFieldValue, }; - transaction.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + transaction.set(castedReference, json, options); } void batchSet( @@ -2532,7 +2637,11 @@ class _$CommentDocumentReference _$CommentFieldMap['message']!: messageFieldValue, }; - batch.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + batch.set(castedReference, json, options); } Future update({ @@ -3175,25 +3284,37 @@ class _$CommentQuery extends QueryReference if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$CommentPerFieldToJson.authorName(startAt as String) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$CommentPerFieldToJson.authorName(startAfter as String) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$CommentPerFieldToJson.authorName(endAt as String) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$CommentPerFieldToJson.authorName(endBefore as String) + ], endBeforeDocumentSnapshot: null, ); } @@ -3248,25 +3369,37 @@ class _$CommentQuery extends QueryReference if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$CommentPerFieldToJson.message(startAt as String) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$CommentPerFieldToJson.message(startAfter as String) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$CommentPerFieldToJson.message(endAt as String) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$CommentPerFieldToJson.message(endBefore as String) + ], endBeforeDocumentSnapshot: null, ); } diff --git a/packages/cloud_firestore_odm/example/pubspec.yaml b/packages/cloud_firestore_odm/example/pubspec.yaml index f7354cb..d24240e 100644 --- a/packages/cloud_firestore_odm/example/pubspec.yaml +++ b/packages/cloud_firestore_odm/example/pubspec.yaml @@ -2,16 +2,16 @@ name: cloud_firestore_odm_example publish_to: none environment: - sdk: '>=2.18.0 <4.0.0' + sdk: ">=3.0.0 <4.0.0" dependencies: - cloud_firestore: ^5.0.0 - cloud_firestore_odm: ^1.0.0-dev.85 - firebase_core: ^3.0.0 + cloud_firestore: ^6.0.0 + cloud_firestore_odm: ^1.2.0 + firebase_core: ^4.0.0 flutter: sdk: flutter - freezed_annotation: ^2.2.0 - json_annotation: ^4.8.1 + freezed_annotation: ^3.0.0 + json_annotation: ^4.9.0 meta: ^1.12.0 dev_dependencies: @@ -22,11 +22,11 @@ dev_dependencies: path: ../../cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test flutter_test: sdk: flutter - freezed: ^2.3.2 + freezed: ^3.0.0 http: ^1.0.0 integration_test: sdk: flutter - json_serializable: ^6.6.1 + json_serializable: ^6.7.0 mockito: ^5.0.0 dependency_overrides: diff --git a/packages/cloud_firestore_odm/example/web/index.html b/packages/cloud_firestore_odm/example/web/index.html index ab4fd86..86c769e 100644 --- a/packages/cloud_firestore_odm/example/web/index.html +++ b/packages/cloud_firestore_odm/example/web/index.html @@ -30,72 +30,6 @@ - - + diff --git a/packages/cloud_firestore_odm/pubspec.yaml b/packages/cloud_firestore_odm/pubspec.yaml index 1873718..ad66088 100644 --- a/packages/cloud_firestore_odm/pubspec.yaml +++ b/packages/cloud_firestore_odm/pubspec.yaml @@ -2,21 +2,22 @@ name: cloud_firestore_odm description: An ODM for Firebase Cloud Firestore (cloud_firestore). homepage: https://github.com/firebaseextended/firestoreodm-flutter repository: https://github.com/firebaseextended/firestoreodm-flutter -version: 1.0.0-dev.88 +version: 1.2.0 false_secrets: - example/** environment: - sdk: '>=2.18.0 <4.0.0' + sdk: ">=3.0.0 <4.0.0" dependencies: - cloud_firestore: ^5.0.0 + cloud_firestore: ^6.0.0 flutter: sdk: flutter - json_annotation: ^4.8.1 + json_annotation: ^4.9.0 meta: ^1.12.0 dev_dependencies: flutter_test: sdk: flutter + test: ^1.25.15 diff --git a/packages/cloud_firestore_odm_generator/CHANGELOG.md b/packages/cloud_firestore_odm_generator/CHANGELOG.md index 28119ba..ae0f17d 100644 --- a/packages/cloud_firestore_odm_generator/CHANGELOG.md +++ b/packages/cloud_firestore_odm_generator/CHANGELOG.md @@ -1,3 +1,13 @@ +## 1.2.0 +- **FIX**: `set`, `batchSet` and `transacrtionSet` methods would keep the `@ID() id` in the object in DB. +- **CHORE**: Update cloud_firestore to ^6.0.0 + +## 1.1.0 + +- **FIX**: Resolve compatibility issues with Freezed 3.0.0 and above +- **FEAT**: Support analyzer: ^7.0.0 and source_gen: ^2.0.0 +- **CHORE**: Update dependencies to latest versions + ## 1.0.0-dev.90 - 2025-02-23 - Ignore static getters on annotated classes (thanks to @Rexios80) diff --git a/packages/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/lib/freezed.dart b/packages/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/lib/freezed.dart index 4453f8b..e8af1d2 100644 --- a/packages/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/lib/freezed.dart +++ b/packages/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/lib/freezed.dart @@ -13,7 +13,7 @@ part 'freezed.g.dart'; @Collection('freezed-test') @freezed -class Person with _$Person { +abstract class Person with _$Person { @JsonSerializable(fieldRename: FieldRename.snake) factory Person({ required String firstName, @@ -28,9 +28,24 @@ final personRef = PersonCollectionReference(); @Collection('freezed-test') @freezed -class PublicRedirected with _$PublicRedirected { +abstract class PublicRedirected with _$PublicRedirected { factory PublicRedirected({required String value}) = PublicRedirected2; factory PublicRedirected.fromJson(Map json) => _$PublicRedirectedFromJson(json); } + +/// Freezed 3.x mixed mode +/// +/// Simple classes +@Collection('freezed-test') +@freezed +@JsonSerializable() +class SimpleFreezed with _$SimpleFreezed { + SimpleFreezed({required this.a}); + final int a; + + factory SimpleFreezed.fromJson(Map json) => + _$SimpleFreezedFromJson(json); + Map toJson() => _$SimpleFreezedToJson(this); +} diff --git a/packages/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/lib/freezed.freezed.dart b/packages/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/lib/freezed.freezed.dart index 5c1d22c..d7f233b 100644 --- a/packages/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/lib/freezed.freezed.dart +++ b/packages/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/lib/freezed.freezed.dart @@ -1,5 +1,5 @@ -// coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND +// coverage:ignore-file // ignore_for_file: type=lint // 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, invalid_annotation_target, unnecessary_question_mark @@ -9,85 +9,53 @@ part of 'freezed.dart'; // FreezedGenerator // ************************************************************************** +// dart format off T _$identity(T value) => value; -final _privateConstructorUsedError = UnsupportedError( - 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); - -Person _$PersonFromJson(Map json) { - return _Person.fromJson(json); -} - /// @nodoc mixin _$Person { - String get firstName => throw _privateConstructorUsedError; + String get firstName; @JsonKey(name: 'LAST_NAME') - String get lastName => throw _privateConstructorUsedError; + String get lastName; @JsonKey(includeFromJson: false, includeToJson: false) - int? get ignored => throw _privateConstructorUsedError; - - /// Serializes this Person to a JSON map. - Map toJson() => throw _privateConstructorUsedError; + int? get ignored; /// Create a copy of Person /// with the given fields replaced by the non-null parameter values. @JsonKey(includeFromJson: false, includeToJson: false) - $PersonCopyWith get copyWith => throw _privateConstructorUsedError; -} + @pragma('vm:prefer-inline') + $PersonCopyWith get copyWith => + _$PersonCopyWithImpl(this as Person, _$identity); -/// @nodoc -abstract class $PersonCopyWith<$Res> { - factory $PersonCopyWith(Person value, $Res Function(Person) then) = - _$PersonCopyWithImpl<$Res, Person>; - @useResult - $Res call( - {String firstName, - @JsonKey(name: 'LAST_NAME') String lastName, - @JsonKey(includeFromJson: false, includeToJson: false) int? ignored}); -} + /// Serializes this Person to a JSON map. + Map toJson(); -/// @nodoc -class _$PersonCopyWithImpl<$Res, $Val extends Person> - implements $PersonCopyWith<$Res> { - _$PersonCopyWithImpl(this._value, this._then); + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is Person && + (identical(other.firstName, firstName) || + other.firstName == firstName) && + (identical(other.lastName, lastName) || + other.lastName == lastName) && + (identical(other.ignored, ignored) || other.ignored == ignored)); + } - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash(runtimeType, firstName, lastName, ignored); - /// Create a copy of Person - /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') @override - $Res call({ - Object? firstName = null, - Object? lastName = null, - Object? ignored = freezed, - }) { - return _then(_value.copyWith( - firstName: null == firstName - ? _value.firstName - : firstName // ignore: cast_nullable_to_non_nullable - as String, - lastName: null == lastName - ? _value.lastName - : lastName // ignore: cast_nullable_to_non_nullable - as String, - ignored: freezed == ignored - ? _value.ignored - : ignored // ignore: cast_nullable_to_non_nullable - as int?, - ) as $Val); + String toString() { + return 'Person(firstName: $firstName, lastName: $lastName, ignored: $ignored)'; } } /// @nodoc -abstract class _$$PersonImplCopyWith<$Res> implements $PersonCopyWith<$Res> { - factory _$$PersonImplCopyWith( - _$PersonImpl value, $Res Function(_$PersonImpl) then) = - __$$PersonImplCopyWithImpl<$Res>; - @override +abstract mixin class $PersonCopyWith<$Res> { + factory $PersonCopyWith(Person value, $Res Function(Person) _then) = + _$PersonCopyWithImpl; @useResult $Res call( {String firstName, @@ -96,12 +64,11 @@ abstract class _$$PersonImplCopyWith<$Res> implements $PersonCopyWith<$Res> { } /// @nodoc -class __$$PersonImplCopyWithImpl<$Res> - extends _$PersonCopyWithImpl<$Res, _$PersonImpl> - implements _$$PersonImplCopyWith<$Res> { - __$$PersonImplCopyWithImpl( - _$PersonImpl _value, $Res Function(_$PersonImpl) _then) - : super(_value, _then); +class _$PersonCopyWithImpl<$Res> implements $PersonCopyWith<$Res> { + _$PersonCopyWithImpl(this._self, this._then); + + final Person _self; + final $Res Function(Person) _then; /// Create a copy of Person /// with the given fields replaced by the non-null parameter values. @@ -112,34 +79,203 @@ class __$$PersonImplCopyWithImpl<$Res> Object? lastName = null, Object? ignored = freezed, }) { - return _then(_$PersonImpl( + return _then(_self.copyWith( firstName: null == firstName - ? _value.firstName + ? _self.firstName : firstName // ignore: cast_nullable_to_non_nullable as String, lastName: null == lastName - ? _value.lastName + ? _self.lastName : lastName // ignore: cast_nullable_to_non_nullable as String, ignored: freezed == ignored - ? _value.ignored + ? _self.ignored : ignored // ignore: cast_nullable_to_non_nullable as int?, )); } } +/// Adds pattern-matching-related methods to [Person]. +extension PersonPatterns on Person { + /// A variant of `map` that fallback to returning `orElse`. + /// + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case final Subclass value: + /// return ...; + /// case _: + /// return orElse(); + /// } + /// ``` + + @optionalTypeArgs + TResult maybeMap( + TResult Function(_Person value)? $default, { + required TResult orElse(), + }) { + final _that = this; + switch (_that) { + case _Person() when $default != null: + return $default(_that); + case _: + return orElse(); + } + } + + /// A `switch`-like method, using callbacks. + /// + /// Callbacks receives the raw object, upcasted. + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case final Subclass value: + /// return ...; + /// case final Subclass2 value: + /// return ...; + /// } + /// ``` + + @optionalTypeArgs + TResult map( + TResult Function(_Person value) $default, + ) { + final _that = this; + switch (_that) { + case _Person(): + return $default(_that); + case _: + throw StateError('Unexpected subclass'); + } + } + + /// A variant of `map` that fallback to returning `null`. + /// + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case final Subclass value: + /// return ...; + /// case _: + /// return null; + /// } + /// ``` + + @optionalTypeArgs + TResult? mapOrNull( + TResult? Function(_Person value)? $default, + ) { + final _that = this; + switch (_that) { + case _Person() when $default != null: + return $default(_that); + case _: + return null; + } + } + + /// A variant of `when` that fallback to an `orElse` callback. + /// + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case Subclass(:final field): + /// return ...; + /// case _: + /// return orElse(); + /// } + /// ``` + + @optionalTypeArgs + TResult maybeWhen( + TResult Function( + String firstName, + @JsonKey(name: 'LAST_NAME') String lastName, + @JsonKey(includeFromJson: false, includeToJson: false) + int? ignored)? + $default, { + required TResult orElse(), + }) { + final _that = this; + switch (_that) { + case _Person() when $default != null: + return $default(_that.firstName, _that.lastName, _that.ignored); + case _: + return orElse(); + } + } + + /// A `switch`-like method, using callbacks. + /// + /// As opposed to `map`, this offers destructuring. + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case Subclass(:final field): + /// return ...; + /// case Subclass2(:final field2): + /// return ...; + /// } + /// ``` + + @optionalTypeArgs + TResult when( + TResult Function( + String firstName, + @JsonKey(name: 'LAST_NAME') String lastName, + @JsonKey(includeFromJson: false, includeToJson: false) int? ignored) + $default, + ) { + final _that = this; + switch (_that) { + case _Person(): + return $default(_that.firstName, _that.lastName, _that.ignored); + case _: + throw StateError('Unexpected subclass'); + } + } + + /// A variant of `when` that fallback to returning `null` + /// + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case Subclass(:final field): + /// return ...; + /// case _: + /// return null; + /// } + /// ``` + + @optionalTypeArgs + TResult? whenOrNull( + TResult? Function( + String firstName, + @JsonKey(name: 'LAST_NAME') String lastName, + @JsonKey(includeFromJson: false, includeToJson: false) + int? ignored)? + $default, + ) { + final _that = this; + switch (_that) { + case _Person() when $default != null: + return $default(_that.firstName, _that.lastName, _that.ignored); + case _: + return null; + } + } +} + /// @nodoc @JsonSerializable(fieldRename: FieldRename.snake) -class _$PersonImpl implements _Person { - _$PersonImpl( +class _Person implements Person { + _Person( {required this.firstName, @JsonKey(name: 'LAST_NAME') required this.lastName, @JsonKey(includeFromJson: false, includeToJson: false) this.ignored}); - - factory _$PersonImpl.fromJson(Map json) => - _$$PersonImplFromJson(json); + factory _Person.fromJson(Map json) => _$PersonFromJson(json); @override final String firstName; @@ -150,16 +286,26 @@ class _$PersonImpl implements _Person { @JsonKey(includeFromJson: false, includeToJson: false) final int? ignored; + /// Create a copy of Person + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + @pragma('vm:prefer-inline') + _$PersonCopyWith<_Person> get copyWith => + __$PersonCopyWithImpl<_Person>(this, _$identity); + @override - String toString() { - return 'Person(firstName: $firstName, lastName: $lastName, ignored: $ignored)'; + Map toJson() { + return _$PersonToJson( + this, + ); } @override bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _$PersonImpl && + other is _Person && (identical(other.firstName, firstName) || other.firstName == firstName) && (identical(other.lastName, lastName) || @@ -171,46 +317,55 @@ class _$PersonImpl implements _Person { @override int get hashCode => Object.hash(runtimeType, firstName, lastName, ignored); - /// Create a copy of Person - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - @override - @pragma('vm:prefer-inline') - _$$PersonImplCopyWith<_$PersonImpl> get copyWith => - __$$PersonImplCopyWithImpl<_$PersonImpl>(this, _$identity); - @override - Map toJson() { - return _$$PersonImplToJson( - this, - ); + String toString() { + return 'Person(firstName: $firstName, lastName: $lastName, ignored: $ignored)'; } } -abstract class _Person implements Person { - factory _Person( - {required final String firstName, - @JsonKey(name: 'LAST_NAME') required final String lastName, - @JsonKey(includeFromJson: false, includeToJson: false) - final int? ignored}) = _$PersonImpl; +/// @nodoc +abstract mixin class _$PersonCopyWith<$Res> implements $PersonCopyWith<$Res> { + factory _$PersonCopyWith(_Person value, $Res Function(_Person) _then) = + __$PersonCopyWithImpl; + @override + @useResult + $Res call( + {String firstName, + @JsonKey(name: 'LAST_NAME') String lastName, + @JsonKey(includeFromJson: false, includeToJson: false) int? ignored}); +} - factory _Person.fromJson(Map json) = _$PersonImpl.fromJson; +/// @nodoc +class __$PersonCopyWithImpl<$Res> implements _$PersonCopyWith<$Res> { + __$PersonCopyWithImpl(this._self, this._then); - @override - String get firstName; - @override - @JsonKey(name: 'LAST_NAME') - String get lastName; - @override - @JsonKey(includeFromJson: false, includeToJson: false) - int? get ignored; + final _Person _self; + final $Res Function(_Person) _then; /// Create a copy of Person /// with the given fields replaced by the non-null parameter values. @override - @JsonKey(includeFromJson: false, includeToJson: false) - _$$PersonImplCopyWith<_$PersonImpl> get copyWith => - throw _privateConstructorUsedError; + @pragma('vm:prefer-inline') + $Res call({ + Object? firstName = null, + Object? lastName = null, + Object? ignored = freezed, + }) { + return _then(_Person( + firstName: null == firstName + ? _self.firstName + : firstName // ignore: cast_nullable_to_non_nullable + as String, + lastName: null == lastName + ? _self.lastName + : lastName // ignore: cast_nullable_to_non_nullable + as String, + ignored: freezed == ignored + ? _self.ignored + : ignored // ignore: cast_nullable_to_non_nullable + as int?, + )); + } } PublicRedirected _$PublicRedirectedFromJson(Map json) { @@ -219,36 +374,53 @@ PublicRedirected _$PublicRedirectedFromJson(Map json) { /// @nodoc mixin _$PublicRedirected { - String get value => throw _privateConstructorUsedError; - - /// Serializes this PublicRedirected to a JSON map. - Map toJson() => throw _privateConstructorUsedError; + String get value; /// Create a copy of PublicRedirected /// with the given fields replaced by the non-null parameter values. @JsonKey(includeFromJson: false, includeToJson: false) + @pragma('vm:prefer-inline') $PublicRedirectedCopyWith get copyWith => - throw _privateConstructorUsedError; + _$PublicRedirectedCopyWithImpl( + this as PublicRedirected, _$identity); + + /// Serializes this PublicRedirected to a JSON map. + Map toJson(); + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is PublicRedirected && + (identical(other.value, value) || other.value == value)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash(runtimeType, value); + + @override + String toString() { + return 'PublicRedirected(value: $value)'; + } } /// @nodoc -abstract class $PublicRedirectedCopyWith<$Res> { +abstract mixin class $PublicRedirectedCopyWith<$Res> { factory $PublicRedirectedCopyWith( - PublicRedirected value, $Res Function(PublicRedirected) then) = - _$PublicRedirectedCopyWithImpl<$Res, PublicRedirected>; + PublicRedirected value, $Res Function(PublicRedirected) _then) = + _$PublicRedirectedCopyWithImpl; @useResult $Res call({String value}); } /// @nodoc -class _$PublicRedirectedCopyWithImpl<$Res, $Val extends PublicRedirected> +class _$PublicRedirectedCopyWithImpl<$Res> implements $PublicRedirectedCopyWith<$Res> { - _$PublicRedirectedCopyWithImpl(this._value, this._then); + _$PublicRedirectedCopyWithImpl(this._self, this._then); - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; + final PublicRedirected _self; + final $Res Function(PublicRedirected) _then; /// Create a copy of PublicRedirected /// with the given fields replaced by the non-null parameter values. @@ -257,44 +429,244 @@ class _$PublicRedirectedCopyWithImpl<$Res, $Val extends PublicRedirected> $Res call({ Object? value = null, }) { - return _then(_value.copyWith( + return _then(_self.copyWith( value: null == value - ? _value.value + ? _self.value : value // ignore: cast_nullable_to_non_nullable as String, - ) as $Val); + )); + } +} + +/// Adds pattern-matching-related methods to [PublicRedirected]. +extension PublicRedirectedPatterns on PublicRedirected { + /// A variant of `map` that fallback to returning `orElse`. + /// + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case final Subclass value: + /// return ...; + /// case _: + /// return orElse(); + /// } + /// ``` + + @optionalTypeArgs + TResult maybeMap( + TResult Function(PublicRedirected2 value)? $default, { + required TResult orElse(), + }) { + final _that = this; + switch (_that) { + case PublicRedirected2() when $default != null: + return $default(_that); + case _: + return orElse(); + } + } + + /// A `switch`-like method, using callbacks. + /// + /// Callbacks receives the raw object, upcasted. + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case final Subclass value: + /// return ...; + /// case final Subclass2 value: + /// return ...; + /// } + /// ``` + + @optionalTypeArgs + TResult map( + TResult Function(PublicRedirected2 value) $default, + ) { + final _that = this; + switch (_that) { + case PublicRedirected2(): + return $default(_that); + case _: + throw StateError('Unexpected subclass'); + } + } + + /// A variant of `map` that fallback to returning `null`. + /// + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case final Subclass value: + /// return ...; + /// case _: + /// return null; + /// } + /// ``` + + @optionalTypeArgs + TResult? mapOrNull( + TResult? Function(PublicRedirected2 value)? $default, + ) { + final _that = this; + switch (_that) { + case PublicRedirected2() when $default != null: + return $default(_that); + case _: + return null; + } + } + + /// A variant of `when` that fallback to an `orElse` callback. + /// + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case Subclass(:final field): + /// return ...; + /// case _: + /// return orElse(); + /// } + /// ``` + + @optionalTypeArgs + TResult maybeWhen( + TResult Function(String value)? $default, { + required TResult orElse(), + }) { + final _that = this; + switch (_that) { + case PublicRedirected2() when $default != null: + return $default(_that.value); + case _: + return orElse(); + } + } + + /// A `switch`-like method, using callbacks. + /// + /// As opposed to `map`, this offers destructuring. + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case Subclass(:final field): + /// return ...; + /// case Subclass2(:final field2): + /// return ...; + /// } + /// ``` + + @optionalTypeArgs + TResult when( + TResult Function(String value) $default, + ) { + final _that = this; + switch (_that) { + case PublicRedirected2(): + return $default(_that.value); + case _: + throw StateError('Unexpected subclass'); + } + } + + /// A variant of `when` that fallback to returning `null` + /// + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case Subclass(:final field): + /// return ...; + /// case _: + /// return null; + /// } + /// ``` + + @optionalTypeArgs + TResult? whenOrNull( + TResult? Function(String value)? $default, + ) { + final _that = this; + switch (_that) { + case PublicRedirected2() when $default != null: + return $default(_that.value); + case _: + return null; + } + } +} + +/// @nodoc +@JsonSerializable() +class PublicRedirected2 implements PublicRedirected { + PublicRedirected2({required this.value}); + factory PublicRedirected2.fromJson(Map json) => + _$PublicRedirected2FromJson(json); + + @override + final String value; + + /// Create a copy of PublicRedirected + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + @pragma('vm:prefer-inline') + $PublicRedirected2CopyWith get copyWith => + _$PublicRedirected2CopyWithImpl(this, _$identity); + + @override + Map toJson() { + return _$PublicRedirected2ToJson( + this, + ); + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is PublicRedirected2 && + (identical(other.value, value) || other.value == value)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash(runtimeType, value); + + @override + String toString() { + return 'PublicRedirected(value: $value)'; } } /// @nodoc -abstract class _$$PublicRedirected2ImplCopyWith<$Res> +abstract mixin class $PublicRedirected2CopyWith<$Res> implements $PublicRedirectedCopyWith<$Res> { - factory _$$PublicRedirected2ImplCopyWith(_$PublicRedirected2Impl value, - $Res Function(_$PublicRedirected2Impl) then) = - __$$PublicRedirected2ImplCopyWithImpl<$Res>; + factory $PublicRedirected2CopyWith( + PublicRedirected2 value, $Res Function(PublicRedirected2) _then) = + _$PublicRedirected2CopyWithImpl; @override @useResult $Res call({String value}); } /// @nodoc -class __$$PublicRedirected2ImplCopyWithImpl<$Res> - extends _$PublicRedirectedCopyWithImpl<$Res, _$PublicRedirected2Impl> - implements _$$PublicRedirected2ImplCopyWith<$Res> { - __$$PublicRedirected2ImplCopyWithImpl(_$PublicRedirected2Impl _value, - $Res Function(_$PublicRedirected2Impl) _then) - : super(_value, _then); +class _$PublicRedirected2CopyWithImpl<$Res> + implements $PublicRedirected2CopyWith<$Res> { + _$PublicRedirected2CopyWithImpl(this._self, this._then); + + final PublicRedirected2 _self; + final $Res Function(PublicRedirected2) _then; /// Create a copy of PublicRedirected /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') @override + @pragma('vm:prefer-inline') $Res call({ Object? value = null, }) { - return _then(_$PublicRedirected2Impl( + return _then(PublicRedirected2( value: null == value - ? _value.value + ? _self.value : value // ignore: cast_nullable_to_non_nullable as String, )); @@ -302,64 +674,201 @@ class __$$PublicRedirected2ImplCopyWithImpl<$Res> } /// @nodoc -@JsonSerializable() -class _$PublicRedirected2Impl implements PublicRedirected2 { - _$PublicRedirected2Impl({required this.value}); - - factory _$PublicRedirected2Impl.fromJson(Map json) => - _$$PublicRedirected2ImplFromJson(json); - - @override - final String value; +mixin _$SimpleFreezed { + int get a; - @override - String toString() { - return 'PublicRedirected(value: $value)'; - } + /// Create a copy of SimpleFreezed + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @pragma('vm:prefer-inline') + $SimpleFreezedCopyWith get copyWith => + _$SimpleFreezedCopyWithImpl( + this as SimpleFreezed, _$identity); @override bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _$PublicRedirected2Impl && - (identical(other.value, value) || other.value == value)); + other is SimpleFreezed && + (identical(other.a, a) || other.a == a)); } @JsonKey(includeFromJson: false, includeToJson: false) @override - int get hashCode => Object.hash(runtimeType, value); - - /// Create a copy of PublicRedirected - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - @override - @pragma('vm:prefer-inline') - _$$PublicRedirected2ImplCopyWith<_$PublicRedirected2Impl> get copyWith => - __$$PublicRedirected2ImplCopyWithImpl<_$PublicRedirected2Impl>( - this, _$identity); + int get hashCode => Object.hash(runtimeType, a); @override - Map toJson() { - return _$$PublicRedirected2ImplToJson( - this, - ); + String toString() { + return 'SimpleFreezed(a: $a)'; } } -abstract class PublicRedirected2 implements PublicRedirected { - factory PublicRedirected2({required final String value}) = - _$PublicRedirected2Impl; +/// @nodoc +abstract mixin class $SimpleFreezedCopyWith<$Res> { + factory $SimpleFreezedCopyWith( + SimpleFreezed value, $Res Function(SimpleFreezed) _then) = + _$SimpleFreezedCopyWithImpl; + @useResult + $Res call({int a}); +} - factory PublicRedirected2.fromJson(Map json) = - _$PublicRedirected2Impl.fromJson; +/// @nodoc +class _$SimpleFreezedCopyWithImpl<$Res> + implements $SimpleFreezedCopyWith<$Res> { + _$SimpleFreezedCopyWithImpl(this._self, this._then); - @override - String get value; + final SimpleFreezed _self; + final $Res Function(SimpleFreezed) _then; - /// Create a copy of PublicRedirected + /// Create a copy of SimpleFreezed /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') @override - @JsonKey(includeFromJson: false, includeToJson: false) - _$$PublicRedirected2ImplCopyWith<_$PublicRedirected2Impl> get copyWith => - throw _privateConstructorUsedError; + $Res call({ + Object? a = null, + }) { + return _then(SimpleFreezed( + a: null == a + ? _self.a + : a // ignore: cast_nullable_to_non_nullable + as int, + )); + } } + +/// Adds pattern-matching-related methods to [SimpleFreezed]. +extension SimpleFreezedPatterns on SimpleFreezed { + /// A variant of `map` that fallback to returning `orElse`. + /// + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case final Subclass value: + /// return ...; + /// case _: + /// return orElse(); + /// } + /// ``` + + @optionalTypeArgs + TResult maybeMap({ + required TResult orElse(), + }) { + final _that = this; + switch (_that) { + case _: + return orElse(); + } + } + + /// A `switch`-like method, using callbacks. + /// + /// Callbacks receives the raw object, upcasted. + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case final Subclass value: + /// return ...; + /// case final Subclass2 value: + /// return ...; + /// } + /// ``` + + @optionalTypeArgs + TResult map() { + final _that = this; + switch (_that) { + case _: + throw StateError('Unexpected subclass'); + } + } + + /// A variant of `map` that fallback to returning `null`. + /// + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case final Subclass value: + /// return ...; + /// case _: + /// return null; + /// } + /// ``` + + @optionalTypeArgs + TResult? mapOrNull() { + final _that = this; + switch (_that) { + case _: + return null; + } + } + + /// A variant of `when` that fallback to an `orElse` callback. + /// + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case Subclass(:final field): + /// return ...; + /// case _: + /// return orElse(); + /// } + /// ``` + + @optionalTypeArgs + TResult maybeWhen({ + required TResult orElse(), + }) { + final _that = this; + switch (_that) { + case _: + return orElse(); + } + } + + /// A `switch`-like method, using callbacks. + /// + /// As opposed to `map`, this offers destructuring. + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case Subclass(:final field): + /// return ...; + /// case Subclass2(:final field2): + /// return ...; + /// } + /// ``` + + @optionalTypeArgs + TResult when() { + final _that = this; + switch (_that) { + case _: + throw StateError('Unexpected subclass'); + } + } + + /// A variant of `when` that fallback to returning `null` + /// + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case Subclass(:final field): + /// return ...; + /// case _: + /// return null; + /// } + /// ``` + + @optionalTypeArgs + TResult? whenOrNull() { + final _that = this; + switch (_that) { + case _: + return null; + } + } +} + +// dart format on diff --git a/packages/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/lib/freezed.g.dart b/packages/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/lib/freezed.g.dart index 7ca05a2..85a3fa1 100644 --- a/packages/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/lib/freezed.g.dart +++ b/packages/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/lib/freezed.g.dart @@ -240,9 +240,9 @@ class _$PersonDocumentReference final json = { ...model.toJson(), if (firstNameFieldValue != null) - _$$PersonImplFieldMap['firstName']!: firstNameFieldValue, + _$PersonFieldMap['firstName']!: firstNameFieldValue, if (lastNameFieldValue != null) - _$$PersonImplFieldMap['lastName']!: lastNameFieldValue, + _$PersonFieldMap['lastName']!: lastNameFieldValue, }; final castedReference = reference.withConverter>( @@ -262,12 +262,16 @@ class _$PersonDocumentReference final json = { ...model.toJson(), if (firstNameFieldValue != null) - _$$PersonImplFieldMap['firstName']!: firstNameFieldValue, + _$PersonFieldMap['firstName']!: firstNameFieldValue, if (lastNameFieldValue != null) - _$$PersonImplFieldMap['lastName']!: lastNameFieldValue, + _$PersonFieldMap['lastName']!: lastNameFieldValue, }; - transaction.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + transaction.set(castedReference, json, options); } void batchSet( @@ -280,12 +284,16 @@ class _$PersonDocumentReference final json = { ...model.toJson(), if (firstNameFieldValue != null) - _$$PersonImplFieldMap['firstName']!: firstNameFieldValue, + _$PersonFieldMap['firstName']!: firstNameFieldValue, if (lastNameFieldValue != null) - _$$PersonImplFieldMap['lastName']!: lastNameFieldValue, + _$PersonFieldMap['lastName']!: lastNameFieldValue, }; - batch.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + batch.set(castedReference, json, options); } Future update({ @@ -304,15 +312,15 @@ class _$PersonDocumentReference ); final json = { if (firstName != _sentinel) - _$$PersonImplFieldMap['firstName']!: - _$$PersonImplPerFieldToJson.firstName(firstName as String), + _$PersonFieldMap['firstName']!: + _$PersonPerFieldToJson.firstName(firstName as String), if (firstNameFieldValue != null) - _$$PersonImplFieldMap['firstName']!: firstNameFieldValue, + _$PersonFieldMap['firstName']!: firstNameFieldValue, if (lastName != _sentinel) - _$$PersonImplFieldMap['lastName']!: - _$$PersonImplPerFieldToJson.lastName(lastName as String), + _$PersonFieldMap['lastName']!: + _$PersonPerFieldToJson.lastName(lastName as String), if (lastNameFieldValue != null) - _$$PersonImplFieldMap['lastName']!: lastNameFieldValue, + _$PersonFieldMap['lastName']!: lastNameFieldValue, }; return reference.update(json); @@ -335,15 +343,15 @@ class _$PersonDocumentReference ); final json = { if (firstName != _sentinel) - _$$PersonImplFieldMap['firstName']!: - _$$PersonImplPerFieldToJson.firstName(firstName as String), + _$PersonFieldMap['firstName']!: + _$PersonPerFieldToJson.firstName(firstName as String), if (firstNameFieldValue != null) - _$$PersonImplFieldMap['firstName']!: firstNameFieldValue, + _$PersonFieldMap['firstName']!: firstNameFieldValue, if (lastName != _sentinel) - _$$PersonImplFieldMap['lastName']!: - _$$PersonImplPerFieldToJson.lastName(lastName as String), + _$PersonFieldMap['lastName']!: + _$PersonPerFieldToJson.lastName(lastName as String), if (lastNameFieldValue != null) - _$$PersonImplFieldMap['lastName']!: lastNameFieldValue, + _$PersonFieldMap['lastName']!: lastNameFieldValue, }; transaction.update(reference, json); @@ -366,15 +374,15 @@ class _$PersonDocumentReference ); final json = { if (firstName != _sentinel) - _$$PersonImplFieldMap['firstName']!: - _$$PersonImplPerFieldToJson.firstName(firstName as String), + _$PersonFieldMap['firstName']!: + _$PersonPerFieldToJson.firstName(firstName as String), if (firstNameFieldValue != null) - _$$PersonImplFieldMap['firstName']!: firstNameFieldValue, + _$PersonFieldMap['firstName']!: firstNameFieldValue, if (lastName != _sentinel) - _$$PersonImplFieldMap['lastName']!: - _$$PersonImplPerFieldToJson.lastName(lastName as String), + _$PersonFieldMap['lastName']!: + _$PersonPerFieldToJson.lastName(lastName as String), if (lastNameFieldValue != null) - _$$PersonImplFieldMap['lastName']!: lastNameFieldValue, + _$PersonFieldMap['lastName']!: lastNameFieldValue, }; batch.update(reference, json); @@ -663,30 +671,27 @@ class _$PersonQuery extends QueryReference return _$PersonQuery( _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( - _$$PersonImplFieldMap['firstName']!, + _$PersonFieldMap['firstName']!, isEqualTo: isEqualTo != _sentinel - ? _$$PersonImplPerFieldToJson.firstName(isEqualTo as String) + ? _$PersonPerFieldToJson.firstName(isEqualTo as String) : null, isNotEqualTo: isNotEqualTo != _sentinel - ? _$$PersonImplPerFieldToJson.firstName(isNotEqualTo as String) + ? _$PersonPerFieldToJson.firstName(isNotEqualTo as String) : null, isLessThan: isLessThan != null - ? _$$PersonImplPerFieldToJson.firstName(isLessThan as String) + ? _$PersonPerFieldToJson.firstName(isLessThan as String) : null, isLessThanOrEqualTo: isLessThanOrEqualTo != null - ? _$$PersonImplPerFieldToJson - .firstName(isLessThanOrEqualTo as String) + ? _$PersonPerFieldToJson.firstName(isLessThanOrEqualTo as String) : null, isGreaterThan: isGreaterThan != null - ? _$$PersonImplPerFieldToJson.firstName(isGreaterThan as String) + ? _$PersonPerFieldToJson.firstName(isGreaterThan as String) : null, isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null - ? _$$PersonImplPerFieldToJson - .firstName(isGreaterThanOrEqualTo as String) + ? _$PersonPerFieldToJson.firstName(isGreaterThanOrEqualTo as String) : null, - whereIn: whereIn?.map((e) => _$$PersonImplPerFieldToJson.firstName(e)), - whereNotIn: - whereNotIn?.map((e) => _$$PersonImplPerFieldToJson.firstName(e)), + whereIn: whereIn?.map((e) => _$PersonPerFieldToJson.firstName(e)), + whereNotIn: whereNotIn?.map((e) => _$PersonPerFieldToJson.firstName(e)), isNull: isNull ?? (isEqualTo == null ? false : null) ?? (isNotEqualTo == null ? true : null), @@ -710,30 +715,27 @@ class _$PersonQuery extends QueryReference return _$PersonQuery( _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( - _$$PersonImplFieldMap['lastName']!, + _$PersonFieldMap['lastName']!, isEqualTo: isEqualTo != _sentinel - ? _$$PersonImplPerFieldToJson.lastName(isEqualTo as String) + ? _$PersonPerFieldToJson.lastName(isEqualTo as String) : null, isNotEqualTo: isNotEqualTo != _sentinel - ? _$$PersonImplPerFieldToJson.lastName(isNotEqualTo as String) + ? _$PersonPerFieldToJson.lastName(isNotEqualTo as String) : null, isLessThan: isLessThan != null - ? _$$PersonImplPerFieldToJson.lastName(isLessThan as String) + ? _$PersonPerFieldToJson.lastName(isLessThan as String) : null, isLessThanOrEqualTo: isLessThanOrEqualTo != null - ? _$$PersonImplPerFieldToJson - .lastName(isLessThanOrEqualTo as String) + ? _$PersonPerFieldToJson.lastName(isLessThanOrEqualTo as String) : null, isGreaterThan: isGreaterThan != null - ? _$$PersonImplPerFieldToJson.lastName(isGreaterThan as String) + ? _$PersonPerFieldToJson.lastName(isGreaterThan as String) : null, isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null - ? _$$PersonImplPerFieldToJson - .lastName(isGreaterThanOrEqualTo as String) + ? _$PersonPerFieldToJson.lastName(isGreaterThanOrEqualTo as String) : null, - whereIn: whereIn?.map((e) => _$$PersonImplPerFieldToJson.lastName(e)), - whereNotIn: - whereNotIn?.map((e) => _$$PersonImplPerFieldToJson.lastName(e)), + whereIn: whereIn?.map((e) => _$PersonPerFieldToJson.lastName(e)), + whereNotIn: whereNotIn?.map((e) => _$PersonPerFieldToJson.lastName(e)), isNull: isNull ?? (isEqualTo == null ? false : null) ?? (isNotEqualTo == null ? true : null), @@ -902,7 +904,7 @@ class _$PersonQuery extends QueryReference PersonDocumentSnapshot? startAfterDocument, }) { final query = $referenceWithoutCursor - .orderBy(_$$PersonImplFieldMap['firstName']!, descending: descending); + .orderBy(_$PersonFieldMap['firstName']!, descending: descending); var queryCursor = $queryCursor; if (startAtDocument != null) { @@ -932,25 +934,37 @@ class _$PersonQuery extends QueryReference if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$PersonPerFieldToJson.firstName(startAt as String) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$PersonPerFieldToJson.firstName(startAfter as String) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$PersonPerFieldToJson.firstName(endAt as String) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$PersonPerFieldToJson.firstName(endBefore as String) + ], endBeforeDocumentSnapshot: null, ); } @@ -974,8 +988,8 @@ class _$PersonQuery extends QueryReference PersonDocumentSnapshot? endBeforeDocument, PersonDocumentSnapshot? startAfterDocument, }) { - final query = $referenceWithoutCursor - .orderBy(_$$PersonImplFieldMap['lastName']!, descending: descending); + final query = $referenceWithoutCursor.orderBy(_$PersonFieldMap['lastName']!, + descending: descending); var queryCursor = $queryCursor; if (startAtDocument != null) { @@ -1005,25 +1019,37 @@ class _$PersonQuery extends QueryReference if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$PersonPerFieldToJson.lastName(startAt as String) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$PersonPerFieldToJson.lastName(startAfter as String) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$PersonPerFieldToJson.lastName(endAt as String) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$PersonPerFieldToJson.lastName(endBefore as String) + ], endBeforeDocumentSnapshot: null, ); } @@ -1348,7 +1374,7 @@ class _$PublicRedirectedDocumentReference extends FirestoreDocumentReference< final json = { ...model.toJson(), if (valueFieldValue != null) - _$$PublicRedirected2ImplFieldMap['value']!: valueFieldValue, + _$PublicRedirected2FieldMap['value']!: valueFieldValue, }; final castedReference = reference.withConverter>( @@ -1367,10 +1393,14 @@ class _$PublicRedirectedDocumentReference extends FirestoreDocumentReference< final json = { ...model.toJson(), if (valueFieldValue != null) - _$$PublicRedirected2ImplFieldMap['value']!: valueFieldValue, + _$PublicRedirected2FieldMap['value']!: valueFieldValue, }; - transaction.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + transaction.set(castedReference, json, options); } void batchSet( @@ -1382,10 +1412,14 @@ class _$PublicRedirectedDocumentReference extends FirestoreDocumentReference< final json = { ...model.toJson(), if (valueFieldValue != null) - _$$PublicRedirected2ImplFieldMap['value']!: valueFieldValue, + _$PublicRedirected2FieldMap['value']!: valueFieldValue, }; - batch.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + batch.set(castedReference, json, options); } Future update({ @@ -1398,10 +1432,10 @@ class _$PublicRedirectedDocumentReference extends FirestoreDocumentReference< ); final json = { if (value != _sentinel) - _$$PublicRedirected2ImplFieldMap['value']!: - _$$PublicRedirected2ImplPerFieldToJson.value(value as String), + _$PublicRedirected2FieldMap['value']!: + _$PublicRedirected2PerFieldToJson.value(value as String), if (valueFieldValue != null) - _$$PublicRedirected2ImplFieldMap['value']!: valueFieldValue, + _$PublicRedirected2FieldMap['value']!: valueFieldValue, }; return reference.update(json); @@ -1418,10 +1452,10 @@ class _$PublicRedirectedDocumentReference extends FirestoreDocumentReference< ); final json = { if (value != _sentinel) - _$$PublicRedirected2ImplFieldMap['value']!: - _$$PublicRedirected2ImplPerFieldToJson.value(value as String), + _$PublicRedirected2FieldMap['value']!: + _$PublicRedirected2PerFieldToJson.value(value as String), if (valueFieldValue != null) - _$$PublicRedirected2ImplFieldMap['value']!: valueFieldValue, + _$PublicRedirected2FieldMap['value']!: valueFieldValue, }; transaction.update(reference, json); @@ -1438,10 +1472,10 @@ class _$PublicRedirectedDocumentReference extends FirestoreDocumentReference< ); final json = { if (value != _sentinel) - _$$PublicRedirected2ImplFieldMap['value']!: - _$$PublicRedirected2ImplPerFieldToJson.value(value as String), + _$PublicRedirected2FieldMap['value']!: + _$PublicRedirected2PerFieldToJson.value(value as String), if (valueFieldValue != null) - _$$PublicRedirected2ImplFieldMap['value']!: valueFieldValue, + _$PublicRedirected2FieldMap['value']!: valueFieldValue, }; batch.update(reference, json); @@ -1711,33 +1745,31 @@ class _$PublicRedirectedQuery return _$PublicRedirectedQuery( _collection, $referenceWithoutCursor: $referenceWithoutCursor.where( - _$$PublicRedirected2ImplFieldMap['value']!, + _$PublicRedirected2FieldMap['value']!, isEqualTo: isEqualTo != _sentinel - ? _$$PublicRedirected2ImplPerFieldToJson.value(isEqualTo as String) + ? _$PublicRedirected2PerFieldToJson.value(isEqualTo as String) : null, isNotEqualTo: isNotEqualTo != _sentinel - ? _$$PublicRedirected2ImplPerFieldToJson - .value(isNotEqualTo as String) + ? _$PublicRedirected2PerFieldToJson.value(isNotEqualTo as String) : null, isLessThan: isLessThan != null - ? _$$PublicRedirected2ImplPerFieldToJson.value(isLessThan as String) + ? _$PublicRedirected2PerFieldToJson.value(isLessThan as String) : null, isLessThanOrEqualTo: isLessThanOrEqualTo != null - ? _$$PublicRedirected2ImplPerFieldToJson + ? _$PublicRedirected2PerFieldToJson .value(isLessThanOrEqualTo as String) : null, isGreaterThan: isGreaterThan != null - ? _$$PublicRedirected2ImplPerFieldToJson - .value(isGreaterThan as String) + ? _$PublicRedirected2PerFieldToJson.value(isGreaterThan as String) : null, isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null - ? _$$PublicRedirected2ImplPerFieldToJson + ? _$PublicRedirected2PerFieldToJson .value(isGreaterThanOrEqualTo as String) : null, - whereIn: whereIn - ?.map((e) => _$$PublicRedirected2ImplPerFieldToJson.value(e)), - whereNotIn: whereNotIn - ?.map((e) => _$$PublicRedirected2ImplPerFieldToJson.value(e)), + whereIn: + whereIn?.map((e) => _$PublicRedirected2PerFieldToJson.value(e)), + whereNotIn: + whereNotIn?.map((e) => _$PublicRedirected2PerFieldToJson.value(e)), isNull: isNull ?? (isEqualTo == null ? false : null) ?? (isNotEqualTo == null ? true : null), @@ -1905,9 +1937,8 @@ class _$PublicRedirectedQuery PublicRedirectedDocumentSnapshot? endBeforeDocument, PublicRedirectedDocumentSnapshot? startAfterDocument, }) { - final query = $referenceWithoutCursor.orderBy( - _$$PublicRedirected2ImplFieldMap['value']!, - descending: descending); + final query = $referenceWithoutCursor + .orderBy(_$PublicRedirected2FieldMap['value']!, descending: descending); var queryCursor = $queryCursor; if (startAtDocument != null) { @@ -1937,25 +1968,37 @@ class _$PublicRedirectedQuery if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$PublicRedirected2PerFieldToJson.value(startAt as String) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$PublicRedirected2PerFieldToJson.value(startAfter as String) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$PublicRedirected2PerFieldToJson.value(endAt as String) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$PublicRedirected2PerFieldToJson.value(endBefore as String) + ], endBeforeDocumentSnapshot: null, ); } @@ -2066,52 +2109,1010 @@ class PublicRedirectedQueryDocumentSnapshot } } -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** +/// 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 SimpleFreezedCollectionReference + implements + SimpleFreezedQuery, + FirestoreCollectionReference { + factory SimpleFreezedCollectionReference([ + FirebaseFirestore? firestore, + ]) = _$SimpleFreezedCollectionReference; -_$PersonImpl _$$PersonImplFromJson(Map json) => _$PersonImpl( - firstName: json['first_name'] as String, - lastName: json['LAST_NAME'] as String, + static SimpleFreezed fromFirestore( + DocumentSnapshot> snapshot, + SnapshotOptions? options, + ) { + return SimpleFreezed.fromJson(snapshot.data()!); + } + + static Map toFirestore( + SimpleFreezed value, + SetOptions? options, + ) { + return value.toJson(); + } + + @override + CollectionReference get reference; + + @override + SimpleFreezedDocumentReference doc([String? id]); + + /// Add a new document to this collection with the specified data, + /// assigning it a document ID automatically. + Future add(SimpleFreezed value); +} + +class _$SimpleFreezedCollectionReference extends _$SimpleFreezedQuery + implements SimpleFreezedCollectionReference { + factory _$SimpleFreezedCollectionReference([FirebaseFirestore? firestore]) { + firestore ??= FirebaseFirestore.instance; + + return _$SimpleFreezedCollectionReference._( + firestore.collection('freezed-test').withConverter( + fromFirestore: SimpleFreezedCollectionReference.fromFirestore, + toFirestore: SimpleFreezedCollectionReference.toFirestore, + ), ); + } -const _$$PersonImplFieldMap = { - 'firstName': 'first_name', - 'lastName': 'LAST_NAME', -}; + _$SimpleFreezedCollectionReference._( + CollectionReference reference, + ) : super(reference, $referenceWithoutCursor: reference); -// ignore: unused_element -abstract class _$$PersonImplPerFieldToJson { - // ignore: unused_element - static Object? firstName(String instance) => instance; - // ignore: unused_element - static Object? lastName(String instance) => instance; + String get path => reference.path; + + @override + CollectionReference get reference => + super.reference as CollectionReference; + + @override + SimpleFreezedDocumentReference doc([String? id]) { + assert( + id == null || id.split('/').length == 1, + 'The document ID cannot be from a different collection', + ); + return SimpleFreezedDocumentReference( + reference.doc(id), + ); + } + + @override + Future add(SimpleFreezed value) { + return reference + .add(value) + .then((ref) => SimpleFreezedDocumentReference(ref)); + } + + @override + bool operator ==(Object other) { + return other is _$SimpleFreezedCollectionReference && + other.runtimeType == runtimeType && + other.reference == reference; + } + + @override + int get hashCode => Object.hash(runtimeType, reference); } -Map _$$PersonImplToJson(_$PersonImpl instance) => - { +abstract class SimpleFreezedDocumentReference + extends FirestoreDocumentReference { + factory SimpleFreezedDocumentReference( + DocumentReference reference) = + _$SimpleFreezedDocumentReference; + + DocumentReference get reference; + + /// A reference to the [SimpleFreezedCollectionReference] containing this document. + SimpleFreezedCollectionReference get parent { + return _$SimpleFreezedCollectionReference(reference.firestore); + } + + @override + Stream snapshots(); + + @override + Future get([GetOptions? options]); + + @override + Future delete(); + + /// Sets data on the document, overwriting any existing data. If the document + /// does not yet exist, it will be created. + /// + /// If [SetOptions] are provided, the data can be merged into an existing + /// document instead of overwriting. + /// + /// Any [FieldValue]s provided will replace the corresponding fields in the + /// [model] during serialization. + Future set( + SimpleFreezed model, { + SetOptions? options, + FieldValue aFieldValue, + }); + + /// Writes to the document using the transaction API. + /// + /// If the document does not exist yet, it will be created. If you pass + /// [SetOptions], the provided data can be merged into the existing document. + /// + /// Any [FieldValue]s provided will replace the corresponding fields in the + /// [model] during serialization. + void transactionSet( + Transaction transaction, + SimpleFreezed model, { + SetOptions? options, + FieldValue aFieldValue, + }); + + /// Writes to the document using the batch API. + /// + /// If the document does not exist yet, it will be created. If you pass + /// [SetOptions], the provided data can be merged into the existing document. + /// + /// Any [FieldValue]s provided will replace the corresponding fields in the + /// [model] during serialization. + void batchSet( + WriteBatch batch, + SimpleFreezed model, { + SetOptions? options, + FieldValue aFieldValue, + }); + + /// 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({ + int a, + FieldValue aFieldValue, + }); + + /// 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, { + int a, + FieldValue aFieldValue, + }); + + /// Updates fields in the current document using the batch API. + /// + /// The update will fail if applied to a document that does not exist. + void batchUpdate( + WriteBatch batch, { + int a, + FieldValue aFieldValue, + }); +} + +class _$SimpleFreezedDocumentReference extends FirestoreDocumentReference< + SimpleFreezed, + SimpleFreezedDocumentSnapshot> implements SimpleFreezedDocumentReference { + _$SimpleFreezedDocumentReference(this.reference); + + @override + final DocumentReference reference; + + /// A reference to the [SimpleFreezedCollectionReference] containing this document. + SimpleFreezedCollectionReference get parent { + return _$SimpleFreezedCollectionReference(reference.firestore); + } + + @override + Stream snapshots() { + return reference.snapshots().map(SimpleFreezedDocumentSnapshot._); + } + + @override + Future get([GetOptions? options]) { + return reference.get(options).then(SimpleFreezedDocumentSnapshot._); + } + + @override + Future transactionGet( + Transaction transaction) { + return transaction.get(reference).then(SimpleFreezedDocumentSnapshot._); + } + + Future set( + SimpleFreezed model, { + SetOptions? options, + FieldValue? aFieldValue, + }) async { + final json = { + ...model.toJson(), + if (aFieldValue != null) _$SimpleFreezedFieldMap['a']!: aFieldValue, + }; + + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + return castedReference.set(json, options); + } + + void transactionSet( + Transaction transaction, + SimpleFreezed model, { + SetOptions? options, + FieldValue? aFieldValue, + }) { + final json = { + ...model.toJson(), + if (aFieldValue != null) _$SimpleFreezedFieldMap['a']!: aFieldValue, + }; + + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + transaction.set(castedReference, json, options); + } + + void batchSet( + WriteBatch batch, + SimpleFreezed model, { + SetOptions? options, + FieldValue? aFieldValue, + }) { + final json = { + ...model.toJson(), + if (aFieldValue != null) _$SimpleFreezedFieldMap['a']!: aFieldValue, + }; + + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + batch.set(castedReference, json, options); + } + + Future update({ + Object? a = _sentinel, + FieldValue? aFieldValue, + }) async { + assert( + a == _sentinel || aFieldValue == null, + "Cannot specify both a and aFieldValue", + ); + final json = { + if (a != _sentinel) + _$SimpleFreezedFieldMap['a']!: + _$SimpleFreezedPerFieldToJson.a(a as int), + if (aFieldValue != null) _$SimpleFreezedFieldMap['a']!: aFieldValue, + }; + + return reference.update(json); + } + + void transactionUpdate( + Transaction transaction, { + Object? a = _sentinel, + FieldValue? aFieldValue, + }) { + assert( + a == _sentinel || aFieldValue == null, + "Cannot specify both a and aFieldValue", + ); + final json = { + if (a != _sentinel) + _$SimpleFreezedFieldMap['a']!: + _$SimpleFreezedPerFieldToJson.a(a as int), + if (aFieldValue != null) _$SimpleFreezedFieldMap['a']!: aFieldValue, + }; + + transaction.update(reference, json); + } + + void batchUpdate( + WriteBatch batch, { + Object? a = _sentinel, + FieldValue? aFieldValue, + }) { + assert( + a == _sentinel || aFieldValue == null, + "Cannot specify both a and aFieldValue", + ); + final json = { + if (a != _sentinel) + _$SimpleFreezedFieldMap['a']!: + _$SimpleFreezedPerFieldToJson.a(a as int), + if (aFieldValue != null) _$SimpleFreezedFieldMap['a']!: aFieldValue, + }; + + batch.update(reference, json); + } + + @override + bool operator ==(Object other) { + return other is SimpleFreezedDocumentReference && + other.runtimeType == runtimeType && + other.parent == parent && + other.id == id; + } + + @override + int get hashCode => Object.hash(runtimeType, parent, id); +} + +abstract class SimpleFreezedQuery + implements QueryReference { + @override + SimpleFreezedQuery limit(int limit); + + @override + SimpleFreezedQuery limitToLast(int limit); + + /// 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'); + /// ``` + SimpleFreezedQuery whereFieldPath( + Object fieldPath, { + Object? isEqualTo, + Object? isNotEqualTo, + Object? isLessThan, + Object? isLessThanOrEqualTo, + Object? isGreaterThan, + Object? isGreaterThanOrEqualTo, + Object? arrayContains, + List? arrayContainsAny, + List? whereIn, + List? whereNotIn, + bool? isNull, + }); + + SimpleFreezedQuery whereDocumentId({ + String? isEqualTo, + String? isNotEqualTo, + String? isLessThan, + String? isLessThanOrEqualTo, + String? isGreaterThan, + String? isGreaterThanOrEqualTo, + List? whereIn, + List? whereNotIn, + bool? isNull, + }); + + SimpleFreezedQuery whereA({ + int? isEqualTo, + int? isNotEqualTo, + int? isLessThan, + int? isLessThanOrEqualTo, + int? isGreaterThan, + int? isGreaterThanOrEqualTo, + List? whereIn, + List? whereNotIn, + bool? isNull, + }); + + /// 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'); + /// ``` + SimpleFreezedQuery orderByFieldPath( + Object fieldPath, { + bool descending = false, + Object startAt, + Object startAfter, + Object endAt, + Object endBefore, + SimpleFreezedDocumentSnapshot? startAtDocument, + SimpleFreezedDocumentSnapshot? endAtDocument, + SimpleFreezedDocumentSnapshot? endBeforeDocument, + SimpleFreezedDocumentSnapshot? startAfterDocument, + }); + + SimpleFreezedQuery orderByDocumentId({ + bool descending = false, + String startAt, + String startAfter, + String endAt, + String endBefore, + SimpleFreezedDocumentSnapshot? startAtDocument, + SimpleFreezedDocumentSnapshot? endAtDocument, + SimpleFreezedDocumentSnapshot? endBeforeDocument, + SimpleFreezedDocumentSnapshot? startAfterDocument, + }); + + SimpleFreezedQuery orderByA({ + bool descending = false, + int startAt, + int startAfter, + int endAt, + int endBefore, + SimpleFreezedDocumentSnapshot? startAtDocument, + SimpleFreezedDocumentSnapshot? endAtDocument, + SimpleFreezedDocumentSnapshot? endBeforeDocument, + SimpleFreezedDocumentSnapshot? startAfterDocument, + }); +} + +class _$SimpleFreezedQuery + extends QueryReference + implements SimpleFreezedQuery { + _$SimpleFreezedQuery( + 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(SimpleFreezedQuerySnapshot._fromQuerySnapshot); + } + + @override + Future get([GetOptions? options]) { + return reference + .get(options) + .then(SimpleFreezedQuerySnapshot._fromQuerySnapshot); + } + + @override + SimpleFreezedQuery limit(int limit) { + return _$SimpleFreezedQuery( + _collection, + $referenceWithoutCursor: $referenceWithoutCursor.limit(limit), + $queryCursor: $queryCursor, + ); + } + + @override + SimpleFreezedQuery limitToLast(int limit) { + return _$SimpleFreezedQuery( + _collection, + $referenceWithoutCursor: $referenceWithoutCursor.limitToLast(limit), + $queryCursor: $queryCursor, + ); + } + + @override + SimpleFreezedQuery whereFieldPath( + Object fieldPath, { + Object? isEqualTo = _sentinel, + Object? isNotEqualTo = _sentinel, + Object? isLessThan, + Object? isLessThanOrEqualTo, + Object? isGreaterThan, + Object? isGreaterThanOrEqualTo, + Object? arrayContains, + List? arrayContainsAny, + List? whereIn, + List? whereNotIn, + bool? isNull, + }) { + return _$SimpleFreezedQuery( + _collection, + $referenceWithoutCursor: $referenceWithoutCursor.where( + fieldPath, + isEqualTo: isEqualTo != _sentinel ? isEqualTo : null, + isNotEqualTo: isNotEqualTo != _sentinel ? isNotEqualTo : null, + isLessThan: isLessThan, + isLessThanOrEqualTo: isLessThanOrEqualTo, + isGreaterThan: isGreaterThan, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + arrayContains: arrayContains, + arrayContainsAny: arrayContainsAny, + whereIn: whereIn, + whereNotIn: whereNotIn, + isNull: isNull ?? + (isEqualTo == null ? false : null) ?? + (isNotEqualTo == null ? true : null), + ), + $queryCursor: $queryCursor, + ); + } + + @override + SimpleFreezedQuery whereDocumentId({ + Object? isEqualTo = _sentinel, + Object? isNotEqualTo = _sentinel, + Object? isLessThan, + Object? isLessThanOrEqualTo, + Object? isGreaterThan, + Object? isGreaterThanOrEqualTo, + List? whereIn, + List? whereNotIn, + bool? isNull, + }) { + return _$SimpleFreezedQuery( + _collection, + $referenceWithoutCursor: $referenceWithoutCursor.where( + FieldPath.documentId, + isEqualTo: isEqualTo != _sentinel ? isEqualTo : null, + isNotEqualTo: isNotEqualTo != _sentinel ? isNotEqualTo : null, + isLessThan: isLessThan, + isLessThanOrEqualTo: isLessThanOrEqualTo, + isGreaterThan: isGreaterThan, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo, + whereIn: whereIn, + whereNotIn: whereNotIn, + isNull: isNull ?? + (isEqualTo == null ? false : null) ?? + (isNotEqualTo == null ? true : null), + ), + $queryCursor: $queryCursor, + ); + } + + @override + SimpleFreezedQuery whereA({ + Object? isEqualTo = _sentinel, + Object? isNotEqualTo = _sentinel, + Object? isLessThan, + Object? isLessThanOrEqualTo, + Object? isGreaterThan, + Object? isGreaterThanOrEqualTo, + List? whereIn, + List? whereNotIn, + bool? isNull, + }) { + return _$SimpleFreezedQuery( + _collection, + $referenceWithoutCursor: $referenceWithoutCursor.where( + _$SimpleFreezedFieldMap['a']!, + isEqualTo: isEqualTo != _sentinel + ? _$SimpleFreezedPerFieldToJson.a(isEqualTo as int) + : null, + isNotEqualTo: isNotEqualTo != _sentinel + ? _$SimpleFreezedPerFieldToJson.a(isNotEqualTo as int) + : null, + isLessThan: isLessThan != null + ? _$SimpleFreezedPerFieldToJson.a(isLessThan as int) + : null, + isLessThanOrEqualTo: isLessThanOrEqualTo != null + ? _$SimpleFreezedPerFieldToJson.a(isLessThanOrEqualTo as int) + : null, + isGreaterThan: isGreaterThan != null + ? _$SimpleFreezedPerFieldToJson.a(isGreaterThan as int) + : null, + isGreaterThanOrEqualTo: isGreaterThanOrEqualTo != null + ? _$SimpleFreezedPerFieldToJson.a(isGreaterThanOrEqualTo as int) + : null, + whereIn: whereIn?.map((e) => _$SimpleFreezedPerFieldToJson.a(e)), + whereNotIn: whereNotIn?.map((e) => _$SimpleFreezedPerFieldToJson.a(e)), + isNull: isNull ?? + (isEqualTo == null ? false : null) ?? + (isNotEqualTo == null ? true : null), + ), + $queryCursor: $queryCursor, + ); + } + + @override + SimpleFreezedQuery orderByFieldPath( + Object fieldPath, { + bool descending = false, + Object? startAt = _sentinel, + Object? startAfter = _sentinel, + Object? endAt = _sentinel, + Object? endBefore = _sentinel, + SimpleFreezedDocumentSnapshot? startAtDocument, + SimpleFreezedDocumentSnapshot? endAtDocument, + SimpleFreezedDocumentSnapshot? endBeforeDocument, + SimpleFreezedDocumentSnapshot? 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 _$SimpleFreezedQuery( + _collection, + $referenceWithoutCursor: query, + $queryCursor: queryCursor, + ); + } + + @override + SimpleFreezedQuery orderByDocumentId({ + bool descending = false, + Object? startAt = _sentinel, + Object? startAfter = _sentinel, + Object? endAt = _sentinel, + Object? endBefore = _sentinel, + SimpleFreezedDocumentSnapshot? startAtDocument, + SimpleFreezedDocumentSnapshot? endAtDocument, + SimpleFreezedDocumentSnapshot? endBeforeDocument, + SimpleFreezedDocumentSnapshot? 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 _$SimpleFreezedQuery( + _collection, + $referenceWithoutCursor: query, + $queryCursor: queryCursor, + ); + } + + @override + SimpleFreezedQuery orderByA({ + bool descending = false, + Object? startAt = _sentinel, + Object? startAfter = _sentinel, + Object? endAt = _sentinel, + Object? endBefore = _sentinel, + SimpleFreezedDocumentSnapshot? startAtDocument, + SimpleFreezedDocumentSnapshot? endAtDocument, + SimpleFreezedDocumentSnapshot? endBeforeDocument, + SimpleFreezedDocumentSnapshot? startAfterDocument, + }) { + final query = $referenceWithoutCursor.orderBy(_$SimpleFreezedFieldMap['a']!, + 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, + _$SimpleFreezedPerFieldToJson.a(startAt as int) + ], + startAtDocumentSnapshot: null, + ); + } + if (startAfter != _sentinel) { + queryCursor = queryCursor.copyWith( + startAfter: [ + ...queryCursor.startAfter, + _$SimpleFreezedPerFieldToJson.a(startAfter as int) + ], + startAfterDocumentSnapshot: null, + ); + } + if (endAt != _sentinel) { + queryCursor = queryCursor.copyWith( + endAt: [ + ...queryCursor.endAt, + _$SimpleFreezedPerFieldToJson.a(endAt as int) + ], + endAtDocumentSnapshot: null, + ); + } + if (endBefore != _sentinel) { + queryCursor = queryCursor.copyWith( + endBefore: [ + ...queryCursor.endBefore, + _$SimpleFreezedPerFieldToJson.a(endBefore as int) + ], + endBeforeDocumentSnapshot: null, + ); + } + + return _$SimpleFreezedQuery( + _collection, + $referenceWithoutCursor: query, + $queryCursor: queryCursor, + ); + } + + @override + bool operator ==(Object other) { + return other is _$SimpleFreezedQuery && + other.runtimeType == runtimeType && + other.reference == reference; + } + + @override + int get hashCode => Object.hash(runtimeType, reference); +} + +class SimpleFreezedDocumentSnapshot + extends FirestoreDocumentSnapshot { + SimpleFreezedDocumentSnapshot._(this.snapshot) : data = snapshot.data(); + + @override + final DocumentSnapshot snapshot; + + @override + SimpleFreezedDocumentReference get reference { + return SimpleFreezedDocumentReference( + snapshot.reference, + ); + } + + @override + final SimpleFreezed? data; +} + +class SimpleFreezedQuerySnapshot extends FirestoreQuerySnapshot { + SimpleFreezedQuerySnapshot._( + this.snapshot, + this.docs, + this.docChanges, + ); + + factory SimpleFreezedQuerySnapshot._fromQuerySnapshot( + QuerySnapshot snapshot, + ) { + final docs = + snapshot.docs.map(SimpleFreezedQueryDocumentSnapshot._).toList(); + + final docChanges = snapshot.docChanges.map((change) { + return _decodeDocumentChange( + change, + SimpleFreezedDocumentSnapshot._, + ); + }).toList(); + + return SimpleFreezedQuerySnapshot._( + snapshot, + docs, + docChanges, + ); + } + + static FirestoreDocumentChange + _decodeDocumentChange( + DocumentChange docChange, + SimpleFreezedDocumentSnapshot 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 SimpleFreezedQueryDocumentSnapshot + extends FirestoreQueryDocumentSnapshot + implements SimpleFreezedDocumentSnapshot { + SimpleFreezedQueryDocumentSnapshot._(this.snapshot) : data = snapshot.data(); + + @override + final QueryDocumentSnapshot snapshot; + + @override + final SimpleFreezed data; + + @override + SimpleFreezedDocumentReference get reference { + return SimpleFreezedDocumentReference(snapshot.reference); + } +} + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +SimpleFreezed _$SimpleFreezedFromJson(Map json) => + SimpleFreezed( + a: (json['a'] as num).toInt(), + ); + +const _$SimpleFreezedFieldMap = { + 'a': 'a', +}; + +// ignore: unused_element +abstract class _$SimpleFreezedPerFieldToJson { + // ignore: unused_element + static Object? a(int instance) => instance; +} + +Map _$SimpleFreezedToJson(SimpleFreezed instance) => + { + 'a': instance.a, + }; + +_Person _$PersonFromJson(Map json) => _Person( + firstName: json['first_name'] as String, + lastName: json['LAST_NAME'] as String, + ); + +const _$PersonFieldMap = { + 'firstName': 'first_name', + '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, }; -_$PublicRedirected2Impl _$$PublicRedirected2ImplFromJson( - Map json) => - _$PublicRedirected2Impl( +PublicRedirected2 _$PublicRedirected2FromJson(Map json) => + PublicRedirected2( value: json['value'] as String, ); -const _$$PublicRedirected2ImplFieldMap = { +const _$PublicRedirected2FieldMap = { 'value': 'value', }; // ignore: unused_element -abstract class _$$PublicRedirected2ImplPerFieldToJson { +abstract class _$PublicRedirected2PerFieldToJson { // ignore: unused_element static Object? value(String instance) => instance; } -Map _$$PublicRedirected2ImplToJson( - _$PublicRedirected2Impl instance) => +Map _$PublicRedirected2ToJson(PublicRedirected2 instance) => { 'value': instance.value, }; diff --git a/packages/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/lib/simple.g.dart b/packages/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/lib/simple.g.dart index e4b949b..031de0c 100644 --- a/packages/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/lib/simple.g.dart +++ b/packages/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/lib/simple.g.dart @@ -258,7 +258,11 @@ class _$IgnoredGetterDocumentReference extends FirestoreDocumentReference< _$IgnoredGetterFieldMap['value']!: valueFieldValue, }; - transaction.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + transaction.set(castedReference, json, options); } void batchSet( @@ -273,7 +277,11 @@ class _$IgnoredGetterDocumentReference extends FirestoreDocumentReference< _$IgnoredGetterFieldMap['value']!: valueFieldValue, }; - batch.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + batch.set(castedReference, json, options); } Future update({ @@ -819,25 +827,37 @@ class _$IgnoredGetterQuery if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$IgnoredGetterPerFieldToJson.value(startAt as int) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$IgnoredGetterPerFieldToJson.value(startAfter as int) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$IgnoredGetterPerFieldToJson.value(endAt as int) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$IgnoredGetterPerFieldToJson.value(endBefore as int) + ], endBeforeDocumentSnapshot: null, ); } @@ -1178,7 +1198,11 @@ class _$ModelDocumentReference if (valueFieldValue != null) _$ModelFieldMap['value']!: valueFieldValue, }; - transaction.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + transaction.set(castedReference, json, options); } void batchSet( @@ -1192,7 +1216,11 @@ class _$ModelDocumentReference if (valueFieldValue != null) _$ModelFieldMap['value']!: valueFieldValue, }; - batch.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + batch.set(castedReference, json, options); } Future update({ @@ -1725,25 +1753,37 @@ class _$ModelQuery extends QueryReference if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$ModelPerFieldToJson.value(startAt as String) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$ModelPerFieldToJson.value(startAfter as String) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$ModelPerFieldToJson.value(endAt as String) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$ModelPerFieldToJson.value(endBefore as String) + ], endBeforeDocumentSnapshot: null, ); } @@ -2261,7 +2301,11 @@ class _$NestedDocumentReference _$NestedFieldMap['nullableEnumList']!: nullableEnumListFieldValue, }; - transaction.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + transaction.set(castedReference, json, options); } void batchSet( @@ -2311,7 +2355,11 @@ class _$NestedDocumentReference _$NestedFieldMap['nullableEnumList']!: nullableEnumListFieldValue, }; - batch.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + batch.set(castedReference, json, options); } Future update({ @@ -4149,25 +4197,37 @@ class _$NestedQuery extends QueryReference if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$NestedPerFieldToJson.value(startAt as Nested?) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$NestedPerFieldToJson.value(startAfter as Nested?) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$NestedPerFieldToJson.value(endAt as Nested?) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$NestedPerFieldToJson.value(endBefore as Nested?) + ], endBeforeDocumentSnapshot: null, ); } @@ -4222,25 +4282,37 @@ class _$NestedQuery extends QueryReference if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$NestedPerFieldToJson.simple(startAt as int?) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$NestedPerFieldToJson.simple(startAfter as int?) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$NestedPerFieldToJson.simple(endAt as int?) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$NestedPerFieldToJson.simple(endBefore as int?) + ], endBeforeDocumentSnapshot: null, ); } @@ -4295,25 +4367,37 @@ class _$NestedQuery extends QueryReference if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$NestedPerFieldToJson.valueList(startAt as List?) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$NestedPerFieldToJson.valueList(startAfter as List?) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$NestedPerFieldToJson.valueList(endAt as List?) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$NestedPerFieldToJson.valueList(endBefore as List?) + ], endBeforeDocumentSnapshot: null, ); } @@ -4368,25 +4452,37 @@ class _$NestedQuery extends QueryReference if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$NestedPerFieldToJson.boolList(startAt as List?) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$NestedPerFieldToJson.boolList(startAfter as List?) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$NestedPerFieldToJson.boolList(endAt as List?) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$NestedPerFieldToJson.boolList(endBefore as List?) + ], endBeforeDocumentSnapshot: null, ); } @@ -4441,25 +4537,37 @@ class _$NestedQuery extends QueryReference if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$NestedPerFieldToJson.stringList(startAt as List?) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$NestedPerFieldToJson.stringList(startAfter as List?) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$NestedPerFieldToJson.stringList(endAt as List?) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$NestedPerFieldToJson.stringList(endBefore as List?) + ], endBeforeDocumentSnapshot: null, ); } @@ -4514,25 +4622,37 @@ class _$NestedQuery extends QueryReference if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$NestedPerFieldToJson.numList(startAt as List?) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$NestedPerFieldToJson.numList(startAfter as List?) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$NestedPerFieldToJson.numList(endAt as List?) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$NestedPerFieldToJson.numList(endBefore as List?) + ], endBeforeDocumentSnapshot: null, ); } @@ -4587,25 +4707,37 @@ class _$NestedQuery extends QueryReference if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$NestedPerFieldToJson.objectList(startAt as List?) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$NestedPerFieldToJson.objectList(startAfter as List?) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$NestedPerFieldToJson.objectList(endAt as List?) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$NestedPerFieldToJson.objectList(endBefore as List?) + ], endBeforeDocumentSnapshot: null, ); } @@ -4660,25 +4792,37 @@ class _$NestedQuery extends QueryReference if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$NestedPerFieldToJson.dynamicList(startAt as List?) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$NestedPerFieldToJson.dynamicList(startAfter as List?) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$NestedPerFieldToJson.dynamicList(endAt as List?) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$NestedPerFieldToJson.dynamicList(endBefore as List?) + ], endBeforeDocumentSnapshot: null, ); } @@ -4733,25 +4877,37 @@ class _$NestedQuery extends QueryReference if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$NestedPerFieldToJson.boolSet(startAt as Set?) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$NestedPerFieldToJson.boolSet(startAfter as Set?) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$NestedPerFieldToJson.boolSet(endAt as Set?) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$NestedPerFieldToJson.boolSet(endBefore as Set?) + ], endBeforeDocumentSnapshot: null, ); } @@ -4806,25 +4962,37 @@ class _$NestedQuery extends QueryReference if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$NestedPerFieldToJson.enumValue(startAt as TestEnum) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$NestedPerFieldToJson.enumValue(startAfter as TestEnum) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$NestedPerFieldToJson.enumValue(endAt as TestEnum) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$NestedPerFieldToJson.enumValue(endBefore as TestEnum) + ], endBeforeDocumentSnapshot: null, ); } @@ -4880,25 +5048,37 @@ class _$NestedQuery extends QueryReference if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$NestedPerFieldToJson.nullableEnumValue(startAt as TestEnum?) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$NestedPerFieldToJson.nullableEnumValue(startAfter as TestEnum?) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$NestedPerFieldToJson.nullableEnumValue(endAt as TestEnum?) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$NestedPerFieldToJson.nullableEnumValue(endBefore as TestEnum?) + ], endBeforeDocumentSnapshot: null, ); } @@ -4953,25 +5133,37 @@ class _$NestedQuery extends QueryReference if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$NestedPerFieldToJson.enumList(startAt as List) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$NestedPerFieldToJson.enumList(startAfter as List) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$NestedPerFieldToJson.enumList(endAt as List) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$NestedPerFieldToJson.enumList(endBefore as List) + ], endBeforeDocumentSnapshot: null, ); } @@ -5026,25 +5218,37 @@ class _$NestedQuery extends QueryReference if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$NestedPerFieldToJson.nullableEnumList(startAt as List?) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$NestedPerFieldToJson.nullableEnumList(startAfter as List?) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$NestedPerFieldToJson.nullableEnumList(endAt as List?) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$NestedPerFieldToJson.nullableEnumList(endBefore as List?) + ], endBeforeDocumentSnapshot: null, ); } @@ -5989,7 +6193,11 @@ class _$OptionalJsonDocumentReference extends FirestoreDocumentReference< _$OptionalJsonFieldMap['value']!: valueFieldValue, }; - transaction.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + transaction.set(castedReference, json, options); } void batchSet( @@ -6004,7 +6212,11 @@ class _$OptionalJsonDocumentReference extends FirestoreDocumentReference< _$OptionalJsonFieldMap['value']!: valueFieldValue, }; - batch.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + batch.set(castedReference, json, options); } Future update({ @@ -6550,25 +6762,37 @@ class _$OptionalJsonQuery if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$OptionalJsonPerFieldToJson.value(startAt as int) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$OptionalJsonPerFieldToJson.value(startAfter as int) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$OptionalJsonPerFieldToJson.value(endAt as int) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$OptionalJsonPerFieldToJson.value(endBefore as int) + ], endBeforeDocumentSnapshot: null, ); } @@ -6911,7 +7135,11 @@ class _$MixedJsonDocumentReference _$MixedJsonFieldMap['value']!: valueFieldValue, }; - transaction.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + transaction.set(castedReference, json, options); } void batchSet( @@ -6926,7 +7154,11 @@ class _$MixedJsonDocumentReference _$MixedJsonFieldMap['value']!: valueFieldValue, }; - batch.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + batch.set(castedReference, json, options); } Future update({ @@ -7468,25 +7700,37 @@ class _$MixedJsonQuery extends QueryReference if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$MixedJsonPerFieldToJson.value(startAt as int) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$MixedJsonPerFieldToJson.value(startAfter as int) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$MixedJsonPerFieldToJson.value(endAt as int) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$MixedJsonPerFieldToJson.value(endBefore as int) + ], endBeforeDocumentSnapshot: null, ); } @@ -7880,7 +8124,11 @@ class _$RootDocumentReference _$RootFieldMap['nullable']!: nullableFieldValue, }; - transaction.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + transaction.set(castedReference, json, options); } void batchSet( @@ -7898,7 +8146,11 @@ class _$RootDocumentReference _$RootFieldMap['nullable']!: nullableFieldValue, }; - batch.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + batch.set(castedReference, json, options); } Future update({ @@ -8538,25 +8790,37 @@ class _$RootQuery extends QueryReference if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$RootPerFieldToJson.nonNullable(startAt as String) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$RootPerFieldToJson.nonNullable(startAfter as String) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$RootPerFieldToJson.nonNullable(endAt as String) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$RootPerFieldToJson.nonNullable(endBefore as String) + ], endBeforeDocumentSnapshot: null, ); } @@ -8611,25 +8875,37 @@ class _$RootQuery extends QueryReference if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$RootPerFieldToJson.nullable(startAt as int?) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$RootPerFieldToJson.nullable(startAfter as int?) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$RootPerFieldToJson.nullable(endAt as int?) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$RootPerFieldToJson.nullable(endBefore as int?) + ], endBeforeDocumentSnapshot: null, ); } @@ -8999,7 +9275,11 @@ class _$SubDocumentReference _$SubFieldMap['nullable']!: nullableFieldValue, }; - transaction.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + transaction.set(castedReference, json, options); } void batchSet( @@ -9017,7 +9297,11 @@ class _$SubDocumentReference _$SubFieldMap['nullable']!: nullableFieldValue, }; - batch.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + batch.set(castedReference, json, options); } Future update({ @@ -9657,25 +9941,37 @@ class _$SubQuery extends QueryReference if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$SubPerFieldToJson.nonNullable(startAt as String) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$SubPerFieldToJson.nonNullable(startAfter as String) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$SubPerFieldToJson.nonNullable(endAt as String) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$SubPerFieldToJson.nonNullable(endBefore as String) + ], endBeforeDocumentSnapshot: null, ); } @@ -9730,25 +10026,37 @@ class _$SubQuery extends QueryReference if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$SubPerFieldToJson.nullable(startAt as int?) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$SubPerFieldToJson.nullable(startAfter as int?) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$SubPerFieldToJson.nullable(endAt as int?) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$SubPerFieldToJson.nullable(endBefore as int?) + ], endBeforeDocumentSnapshot: null, ); } @@ -10108,7 +10416,11 @@ class _$AsCamelCaseDocumentReference _$AsCamelCaseFieldMap['value']!: valueFieldValue, }; - transaction.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + transaction.set(castedReference, json, options); } void batchSet( @@ -10123,7 +10435,11 @@ class _$AsCamelCaseDocumentReference _$AsCamelCaseFieldMap['value']!: valueFieldValue, }; - batch.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + batch.set(castedReference, json, options); } Future update({ @@ -10669,25 +10985,37 @@ class _$AsCamelCaseQuery if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$AsCamelCasePerFieldToJson.value(startAt as num) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$AsCamelCasePerFieldToJson.value(startAfter as num) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$AsCamelCasePerFieldToJson.value(endAt as num) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$AsCamelCasePerFieldToJson.value(endBefore as num) + ], endBeforeDocumentSnapshot: null, ); } @@ -11053,7 +11381,11 @@ class _$CustomSubNameDocumentReference extends FirestoreDocumentReference< _$CustomSubNameFieldMap['value']!: valueFieldValue, }; - transaction.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + transaction.set(castedReference, json, options); } void batchSet( @@ -11068,7 +11400,11 @@ class _$CustomSubNameDocumentReference extends FirestoreDocumentReference< _$CustomSubNameFieldMap['value']!: valueFieldValue, }; - batch.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + batch.set(castedReference, json, options); } Future update({ @@ -11614,25 +11950,37 @@ class _$CustomSubNameQuery if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$CustomSubNamePerFieldToJson.value(startAt as num) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$CustomSubNamePerFieldToJson.value(startAfter as num) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$CustomSubNamePerFieldToJson.value(endAt as num) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$CustomSubNamePerFieldToJson.value(endBefore as num) + ], endBeforeDocumentSnapshot: null, ); } @@ -12002,7 +12350,11 @@ class _$ThisIsACustomPrefixDocumentReference extends FirestoreDocumentReference< _$CustomClassPrefixFieldMap['value']!: valueFieldValue, }; - transaction.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + transaction.set(castedReference, json, options); } void batchSet( @@ -12017,7 +12369,11 @@ class _$ThisIsACustomPrefixDocumentReference extends FirestoreDocumentReference< _$CustomClassPrefixFieldMap['value']!: valueFieldValue, }; - batch.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + batch.set(castedReference, json, options); } Future update({ @@ -12568,25 +12924,37 @@ class _$ThisIsACustomPrefixQuery if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$CustomClassPrefixPerFieldToJson.value(startAt as num) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$CustomClassPrefixPerFieldToJson.value(startAfter as num) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$CustomClassPrefixPerFieldToJson.value(endAt as num) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$CustomClassPrefixPerFieldToJson.value(endBefore as num) + ], endBeforeDocumentSnapshot: null, ); } @@ -12945,7 +13313,11 @@ class _$ExplicitPathDocumentReference extends FirestoreDocumentReference< _$ExplicitPathFieldMap['value']!: valueFieldValue, }; - transaction.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + transaction.set(castedReference, json, options); } void batchSet( @@ -12960,7 +13332,11 @@ class _$ExplicitPathDocumentReference extends FirestoreDocumentReference< _$ExplicitPathFieldMap['value']!: valueFieldValue, }; - batch.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + batch.set(castedReference, json, options); } Future update({ @@ -13506,25 +13882,37 @@ class _$ExplicitPathQuery if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$ExplicitPathPerFieldToJson.value(startAt as num) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$ExplicitPathPerFieldToJson.value(startAfter as num) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$ExplicitPathPerFieldToJson.value(endAt as num) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$ExplicitPathPerFieldToJson.value(endBefore as num) + ], endBeforeDocumentSnapshot: null, ); } @@ -13891,7 +14279,11 @@ class _$ExplicitSubPathDocumentReference extends FirestoreDocumentReference< _$ExplicitSubPathFieldMap['value']!: valueFieldValue, }; - transaction.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + transaction.set(castedReference, json, options); } void batchSet( @@ -13906,7 +14298,11 @@ class _$ExplicitSubPathDocumentReference extends FirestoreDocumentReference< _$ExplicitSubPathFieldMap['value']!: valueFieldValue, }; - batch.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + batch.set(castedReference, json, options); } Future update({ @@ -14453,25 +14849,37 @@ class _$ExplicitSubPathQuery if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$ExplicitSubPathPerFieldToJson.value(startAt as num) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$ExplicitSubPathPerFieldToJson.value(startAfter as num) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$ExplicitSubPathPerFieldToJson.value(endAt as num) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$ExplicitSubPathPerFieldToJson.value(endBefore as num) + ], endBeforeDocumentSnapshot: null, ); } @@ -14816,7 +15224,11 @@ class _$SubClassDocumentReference _$SubClassFieldMap['instanceGetter']!: instanceGetterFieldValue, }; - transaction.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + transaction.set(castedReference, json, options); } void batchSet( @@ -14831,7 +15243,11 @@ class _$SubClassDocumentReference _$SubClassFieldMap['instanceGetter']!: instanceGetterFieldValue, }; - batch.set(reference, json, options); + final castedReference = reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => value, + ); + batch.set(castedReference, json, options); } Future update({ @@ -15377,25 +15793,37 @@ class _$SubClassQuery extends QueryReference if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [ + ...queryCursor.startAt, + _$SubClassPerFieldToJson.instanceGetter(startAt as int) + ], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [ + ...queryCursor.startAfter, + _$SubClassPerFieldToJson.instanceGetter(startAfter as int) + ], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [ + ...queryCursor.endAt, + _$SubClassPerFieldToJson.instanceGetter(endAt as int) + ], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [ + ...queryCursor.endBefore, + _$SubClassPerFieldToJson.instanceGetter(endBefore as int) + ], endBeforeDocumentSnapshot: null, ); } diff --git a/packages/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/pubspec.yaml b/packages/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/pubspec.yaml index b3d3235..c360b38 100644 --- a/packages/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/pubspec.yaml +++ b/packages/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/pubspec.yaml @@ -2,25 +2,27 @@ name: cloud_firestore_odm_generator_integration_test publish_to: none environment: - sdk: '>=2.18.0 <4.0.0' + sdk: ">=3.0.0 <4.0.0" dependencies: - cloud_firestore: ^5.0.0 - cloud_firestore_odm: ^1.0.0-dev.85 + cloud_firestore: ^6.0.0 + cloud_firestore_odm: ^1.2.0 flutter: sdk: flutter - freezed_annotation: ^2.2.0 - json_annotation: ^4.8.1 + freezed_annotation: ^3.0.0 + json_annotation: ^4.9.0 meta: ^1.12.0 dev_dependencies: - build_runner: ^2.4.2 + build_runner: ^2.4.8 cloud_firestore_odm_generator: path: ../ flutter_test: sdk: flutter - freezed: ^2.3.2 - json_serializable: '>=6.6.1 <7.0.0' + freezed: ^3.0.2 + json_serializable: ^6.9.4 + test: ^1.25.1 + firebase_core_platform_interface: ^6.0.0 dependency_overrides: cloud_firestore_odm: diff --git a/packages/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/test/collection_test.dart b/packages/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/test/collection_test.dart index fb768c9..7970f35 100644 --- a/packages/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/test/collection_test.dart +++ b/packages/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/test/collection_test.dart @@ -2,13 +2,14 @@ // 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_odm_generator_integration_test/freezed.dart'; import 'package:cloud_firestore_odm_generator_integration_test/simple.dart'; import 'package:flutter_test/flutter_test.dart'; import 'setup_firestore_mock.dart'; void main() { - setUpAll(setupCloudFirestoreMocks); + setUpAll(setupFirestoreMocks); test('can specify @Collection on the model itself', () { expect( @@ -49,4 +50,24 @@ void main() { ); }); }); + + /// test freezed mixed mode classes + group('freezed mixed mode classes', () { + test('test freezed simple classes', () { + final simpleFreezed = SimpleFreezed(a: 42); + expect(simpleFreezed.toJson(), {'a': 42}); + + final simpleFreezedFromJson = SimpleFreezed.fromJson({'a': 42}); + expect(simpleFreezedFromJson.a, 42); + }); + + test('test freezed factory classes', () { + final publicRedirected = PublicRedirected(value: 'test'); + expect(publicRedirected.toJson(), {'value': 'test'}); + + final publicRedirectedFromJson = + PublicRedirected.fromJson({'value': 'test'}); + expect(publicRedirectedFromJson.value, 'test'); + }); + }); } diff --git a/packages/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/test/setup_firestore_mock.dart b/packages/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/test/setup_firestore_mock.dart index b406e47..9bd0210 100644 --- a/packages/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/test/setup_firestore_mock.dart +++ b/packages/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test/test/setup_firestore_mock.dart @@ -2,13 +2,57 @@ // 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:firebase_core/firebase_core.dart'; import 'package:firebase_core_platform_interface/firebase_core_platform_interface.dart'; import 'package:flutter_test/flutter_test.dart'; -Future setupCloudFirestoreMocks() async { +void setupFirestoreMocks() { TestWidgetsFlutterBinding.ensureInitialized(); - setupFirebaseCoreMocks(); - await Firebase.initializeApp(); + // Mock Platform Interface + final platform = FirebasePlatform.instance; + if (platform is! MockFirebasePlatform) { + // Register Mock if not already registered + FirebasePlatform.instance = MockFirebasePlatform(); + } +} + +class MockFirebasePlatform extends FirebasePlatform { + @override + bool get isAutomaticDataCollectionEnabled => true; + + @override + Future initializeApp({ + String? name, + FirebaseOptions? options, + }) async { + return MockFirebaseAppPlatform(); + } + + @override + FirebaseAppPlatform app([String name = defaultFirebaseAppName]) { + return MockFirebaseAppPlatform(); + } +} + +class MockFirebaseAppPlatform extends FirebaseAppPlatform { + MockFirebaseAppPlatform() + : super( + defaultFirebaseAppName, + const FirebaseOptions( + apiKey: 'mock-api-key', + appId: 'mock-app-id', + messagingSenderId: 'mock-sender-id', + projectId: 'mock-project-id', + )); + + @override + String get name => defaultFirebaseAppName; + + @override + FirebaseOptions get options => const FirebaseOptions( + apiKey: 'mock-api-key', + appId: 'mock-app-id', + messagingSenderId: 'mock-sender-id', + projectId: 'mock-project-id', + ); } diff --git a/packages/cloud_firestore_odm_generator/lib/src/collection_data.dart b/packages/cloud_firestore_odm_generator/lib/src/collection_data.dart index 83ad3ec..8cc9672 100644 --- a/packages/cloud_firestore_odm_generator/lib/src/collection_data.dart +++ b/packages/cloud_firestore_odm_generator/lib/src/collection_data.dart @@ -196,7 +196,7 @@ represents the content of the collection must be in the same file. .allMethods .firstWhereOrNull((method) => method.name == 'toJson'); final redirectedFreezedClass = redirectedFreezedConstructors - .singleOrNull?.redirectedConstructor!.enclosingElement.name; + .singleOrNull?.redirectedConstructor!.enclosingElement3.name; final generatedJsonTypePrefix = _generatedJsonTypePrefix( hasFreezed: hasFreezed, redirectedFreezedClass: redirectedFreezedClass, @@ -377,7 +377,10 @@ represents the content of the collection must be in the same file. required String collectionTargetElementPublicType, }) { if (hasFreezed) { - return '_\$\$${redirectedFreezedClass?.public}Impl'; + final className = + redirectedFreezedClass?.public ?? collectionTargetElementPublicType; + // Only support freezed 3.x or higher + return '_\$$className'; } else { return '_\$$collectionTargetElementPublicType'; } @@ -427,7 +430,21 @@ extension on ClassElement { required List freezedConstructors, }) { if (hasFreezed) { - return freezedConstructors.single.parameters; + /// For Freezed 3.x, support mixed mode classes. There can be the classic freezed way with a factory, + /// or there can be simple regular classes with a normal constructor. + /// + /// We need to find the factory constructor, or the normal constructor if there is no factory. + final factoryConstructor = freezedConstructors.firstWhereOrNull( + (ctor) => + ctor.isFactory && + !ctor.name.startsWith('_') && + ctor.name != 'fromJson', + ); + if (factoryConstructor == null) { + // No factory constructor, use the normal constructor + return fields; + } + return factoryConstructor.parameters; } else { final uniqueFields = {}; diff --git a/packages/cloud_firestore_odm_generator/lib/src/templates/document_reference.dart b/packages/cloud_firestore_odm_generator/lib/src/templates/document_reference.dart index 7f7104a..2975b4b 100644 --- a/packages/cloud_firestore_odm_generator/lib/src/templates/document_reference.dart +++ b/packages/cloud_firestore_odm_generator/lib/src/templates/document_reference.dart @@ -193,12 +193,28 @@ void batchSet( fieldValuesNullable: true, ); final fieldValuesJson = _json(data, includeFields: false); + final json = ''' { ...${data.toJson('model')}, $fieldValuesJson }'''; + final idKey = data.idKey; + + String toFirestoreBody; + if (idKey != null) { + toFirestoreBody = "value..remove('$idKey')"; + } else { + toFirestoreBody = 'value'; + } + + final castedReferenceStr = ''' +reference.withConverter>( + fromFirestore: (snapshot, options) => throw UnimplementedError(), + toFirestore: (value, options) => $toFirestoreBody, +)'''; + return ''' Future set( $type model, { @@ -207,10 +223,7 @@ Future set( }) async { final json = $json; - final castedReference = reference.withConverter>( - fromFirestore: (snapshot, options) => throw UnimplementedError(), - toFirestore: (value, options) => value, - ); + final castedReference = $castedReferenceStr; return castedReference.set(json, options); } @@ -222,7 +235,8 @@ void transactionSet( }) { final json = $json; - transaction.set(reference, json, options); + final castedReference = $castedReferenceStr; + transaction.set(castedReference, json, options); } void batchSet( @@ -233,7 +247,8 @@ void batchSet( }) { final json = $json; - batch.set(reference, json, options); + final castedReference = $castedReferenceStr; + batch.set(castedReference, json, options); } '''; } diff --git a/packages/cloud_firestore_odm_generator/lib/src/templates/query_reference.dart b/packages/cloud_firestore_odm_generator/lib/src/templates/query_reference.dart index 72d9517..d6bcffa 100644 --- a/packages/cloud_firestore_odm_generator/lib/src/templates/query_reference.dart +++ b/packages/cloud_firestore_odm_generator/lib/src/templates/query_reference.dart @@ -149,6 +149,12 @@ class ${data.queryReferenceImplName} if (field.name == 'fieldPath') '${field.type} fieldPath,', ].join(); + String withToJson(String arg) { + return field.name == 'documentId' || field.name == 'fieldPath' + ? arg + : '${data.perFieldToJson(field.name)}($arg as ${field.type})'; + } + buffer.writeln( ''' @override @@ -193,25 +199,25 @@ class ${data.queryReferenceImplName} if (startAt != _sentinel) { queryCursor = queryCursor.copyWith( - startAt: [...queryCursor.startAt, startAt], + startAt: [...queryCursor.startAt, ${withToJson('startAt')}], startAtDocumentSnapshot: null, ); } if (startAfter != _sentinel) { queryCursor = queryCursor.copyWith( - startAfter: [...queryCursor.startAfter, startAfter], + startAfter: [...queryCursor.startAfter, ${withToJson('startAfter')}], startAfterDocumentSnapshot: null, ); } if (endAt != _sentinel) { queryCursor = queryCursor.copyWith( - endAt: [...queryCursor.endAt, endAt], + endAt: [...queryCursor.endAt, ${withToJson('endAt')}], endAtDocumentSnapshot: null, ); } if (endBefore != _sentinel) { queryCursor = queryCursor.copyWith( - endBefore: [...queryCursor.endBefore, endBefore], + endBefore: [...queryCursor.endBefore, ${withToJson('endBefore')}], endBeforeDocumentSnapshot: null, ); } @@ -238,14 +244,12 @@ class ${data.queryReferenceImplName} (match) => match.group(0)!.toUpperCase(), ); - final nullableType = - field.type.nullabilitySuffix == NullabilitySuffix.question - ? '${field.type}' - : '${field.type}?'; + final nullableType = field.type.nullabilitySuffix == NullabilitySuffix.question + ? '${field.type}' + : '${field.type}?'; final nullableWhereType = _WherePrototype.plain(nullableType); - final sentinelObjectWhereType = - _WherePrototype.plain('Object?', '_sentinel'); + final sentinelObjectWhereType = _WherePrototype.plain('Object?', '_sentinel'); final objectWhereType = _WherePrototype.plain('Object?'); final perFieldToJson = data.perFieldToJson(field.name); @@ -322,10 +326,7 @@ class ${data.queryReferenceImplName} map: (name) { final itemType = field.name == 'fieldPath' ? field.type.toString() - : (field.type as InterfaceType) - .typeArguments - .first - .toString(); + : (field.type as InterfaceType).typeArguments.first.toString(); final cast = itemType != 'Object?' ? ' as $itemType' : ''; var transform = '$name != null ? ($perFieldToJson('; @@ -339,8 +340,7 @@ class ${data.queryReferenceImplName} ), 'arrayContainsAny': _WhereMapper( prototype: nullableWhereType, - map: (name) => - '$name != null ? $perFieldToJson($name) as Iterable? : null', + map: (name) => '$name != null ? $perFieldToJson($name) as Iterable? : null', ), } else if (!field.type.isSupportedIterable) ...{ 'whereIn': inMapper, @@ -354,8 +354,7 @@ class ${data.queryReferenceImplName} ), }; - final prototype = - operators.entries.map((e) => e.value.prototype.call(e.key)).join(); + final prototype = operators.entries.map((e) => e.value.prototype.call(e.key)).join(); final parameters = operators.entries.map((entry) { final key = entry.key; diff --git a/packages/cloud_firestore_odm_generator/lib/src/validator_generator.dart b/packages/cloud_firestore_odm_generator/lib/src/validator_generator.dart index 44e7a89..d9811c9 100644 --- a/packages/cloud_firestore_odm_generator/lib/src/validator_generator.dart +++ b/packages/cloud_firestore_odm_generator/lib/src/validator_generator.dart @@ -40,7 +40,7 @@ bool isValidatorAnnotation(ElementAnnotation annotation) { final element = annotation.element; if (element == null || element is! ConstructorElement) return false; - return element.enclosingElement.allSupertypes.any((superType) { + return element.enclosingElement3.allSupertypes.any((superType) { return superType.element.name == 'Validator' && superType.element.librarySource.uri.toString() == 'package:cloud_firestore_odm/src/validator.dart'; diff --git a/packages/cloud_firestore_odm_generator/pubspec.yaml b/packages/cloud_firestore_odm_generator/pubspec.yaml index fdab7d5..caa7ec4 100644 --- a/packages/cloud_firestore_odm_generator/pubspec.yaml +++ b/packages/cloud_firestore_odm_generator/pubspec.yaml @@ -2,29 +2,29 @@ name: cloud_firestore_odm_generator description: A code generator for cloud_firestore_odm. homepage: https://firebase.flutter.dev/docs/firestore/odm repository: https://github.com/firebaseextended/firestoreodm-flutter -version: 1.0.0-dev.90 +version: 1.2.0 environment: - sdk: ">=2.18.0 <4.0.0" + sdk: ">=3.0.0 <4.0.0" dependencies: - analyzer: ">=5.12.0 <7.0.0" - build: ^2.0.1 - build_config: ^1.0.0 - cloud_firestore_odm: ^1.0.0-dev.87 - collection: ^1.15.0 - freezed_annotation: ">=1.0.0 <3.0.0" + analyzer: ">=5.12.0 <8.0.0" + build: ^2.4.1 + build_config: ^1.1.2 + cloud_firestore_odm: ^1.2.0 + collection: ^1.18.0 + freezed_annotation: ^3.0.0 # Can be removed once this is fixed https://github.com/dart-lang/graphs/issues/86 - graphs: ^2.0.0 - json_annotation: ^4.8.1 - meta: ^1.8.0 - recase: ^4.0.0 - source_gen: ^1.3.2 + graphs: ^2.3.1 + json_annotation: ^4.9.0 + meta: ^1.12.0 + recase: ^4.1.0 + source_gen: ^2.0.0 source_helper: ^1.3.4 dev_dependencies: - build_runner: ^2.4.2 - expect_error: ^1.0.5 - json_serializable: ">=6.3.0 <7.0.0" - matcher: ^0.12.10 - test: ^1.16.8 + build_runner: ^2.4.8 + expect_error: ^1.0.8 + json_serializable: ^6.9.4 + matcher: ^0.12.16 + test: ^1.25.1 diff --git a/scripts/run-tests.sh b/scripts/run-tests.sh new file mode 100755 index 0000000..49d5368 --- /dev/null +++ b/scripts/run-tests.sh @@ -0,0 +1,22 @@ +cd packages/cloud_firestore_odm_generator/cloud_firestore_odm_generator_integration_test +dart run build_runner build -d +flutter test +cd .. +dart test +cd ../cloud_firestore_odm +flutter test +cd example +dart run build_runner build -d +firebase emulators:start --only firestore & +FIREBASE_EMULATOR_PID=$! + +chromedriver --port=4444 & +CHROMEDRIVER_PID=$! + +flutter drive --driver=test_driver/integration_test.dart --target=integration_test/cloud_firestore_odm_e2e_test.dart -d chrome +kill $CHROMEDRIVER_PID +kill $FIREBASE_EMULATOR_PID + + + +