@react-native-firebase/firestore 23.8.8 → 24.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/RNFBFirestore.podspec +2 -1
- package/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreCollectionModule.java +17 -4
- package/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreDocumentModule.java +2 -2
- package/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestorePipelineExecutor.java +1243 -0
- package/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestorePipelineNodeBuilder.java +3919 -0
- package/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestorePipelineParser.java +1735 -0
- package/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreSerialize.java +1 -1
- package/dist/module/FieldPath.js +59 -0
- package/dist/module/FieldPath.js.map +1 -0
- package/dist/module/FieldValue.js +82 -0
- package/dist/module/FieldValue.js.map +1 -0
- package/{lib → dist/module}/FirestoreAggregate.js +31 -43
- package/dist/module/FirestoreAggregate.js.map +1 -0
- package/dist/module/FirestoreBlob.js +56 -0
- package/dist/module/FirestoreBlob.js.map +1 -0
- package/dist/module/FirestoreCollectionReference.js +70 -0
- package/dist/module/FirestoreCollectionReference.js.map +1 -0
- package/{lib → dist/module}/FirestoreDocumentChange.js +12 -15
- package/dist/module/FirestoreDocumentChange.js.map +1 -0
- package/dist/module/FirestoreDocumentReference.js +170 -0
- package/dist/module/FirestoreDocumentReference.js.map +1 -0
- package/dist/module/FirestoreDocumentSnapshot.js +88 -0
- package/dist/module/FirestoreDocumentSnapshot.js.map +1 -0
- package/dist/module/FirestoreFilter.js +146 -0
- package/dist/module/FirestoreFilter.js.map +1 -0
- package/dist/module/FirestoreGeoPoint.js +80 -0
- package/dist/module/FirestoreGeoPoint.js.map +1 -0
- package/{lib → dist/module}/FirestorePath.js +5 -12
- package/dist/module/FirestorePath.js.map +1 -0
- package/{lib → dist/module}/FirestorePersistentCacheIndexManager.js +11 -4
- package/dist/module/FirestorePersistentCacheIndexManager.js.map +1 -0
- package/dist/module/FirestoreQuery.js +298 -0
- package/dist/module/FirestoreQuery.js.map +1 -0
- package/{lib → dist/module}/FirestoreQueryModifiers.js +25 -136
- package/dist/module/FirestoreQueryModifiers.js.map +1 -0
- package/dist/module/FirestoreQuerySnapshot.js +98 -0
- package/dist/module/FirestoreQuerySnapshot.js.map +1 -0
- package/dist/module/FirestoreSnapshotMetadata.js +38 -0
- package/dist/module/FirestoreSnapshotMetadata.js.map +1 -0
- package/dist/module/FirestoreStatics.js +50 -0
- package/dist/module/FirestoreStatics.js.map +1 -0
- package/{lib → dist/module}/FirestoreTimestamp.js +39 -39
- package/dist/module/FirestoreTimestamp.js.map +1 -0
- package/dist/module/FirestoreTransaction.js +113 -0
- package/dist/module/FirestoreTransaction.js.map +1 -0
- package/dist/module/FirestoreTransactionHandler.js +137 -0
- package/dist/module/FirestoreTransactionHandler.js.map +1 -0
- package/dist/module/FirestoreVectorValue.js +75 -0
- package/dist/module/FirestoreVectorValue.js.map +1 -0
- package/dist/module/FirestoreWriteBatch.js +113 -0
- package/dist/module/FirestoreWriteBatch.js.map +1 -0
- package/dist/module/LoadBundleTask.js +70 -0
- package/dist/module/LoadBundleTask.js.map +1 -0
- package/dist/module/index.js +31 -0
- package/dist/module/index.js.map +1 -0
- package/dist/module/modular/Bytes.js +67 -0
- package/dist/module/modular/Bytes.js.map +1 -0
- package/dist/module/modular/FieldPath.js +25 -0
- package/dist/module/modular/FieldPath.js.map +1 -0
- package/dist/module/modular/FieldValue.js +37 -0
- package/dist/module/modular/FieldValue.js.map +1 -0
- package/dist/module/modular/GeoPoint.js +22 -0
- package/dist/module/modular/GeoPoint.js.map +1 -0
- package/dist/module/modular/Timestamp.js +22 -0
- package/dist/module/modular/Timestamp.js.map +1 -0
- package/dist/module/modular/VectorValue.js +25 -0
- package/dist/module/modular/VectorValue.js.map +1 -0
- package/dist/module/modular/query.js +222 -0
- package/dist/module/modular/query.js.map +1 -0
- package/dist/module/modular/snapshot.js +32 -0
- package/dist/module/modular/snapshot.js.map +1 -0
- package/dist/module/modular.js +229 -0
- package/dist/module/modular.js.map +1 -0
- package/dist/module/namespaced.js +298 -0
- package/dist/module/namespaced.js.map +1 -0
- package/dist/module/package.json +1 -0
- package/dist/module/pipelines/expressions.js +1273 -0
- package/dist/module/pipelines/expressions.js.map +1 -0
- package/dist/module/pipelines/index.js +32 -0
- package/dist/module/pipelines/index.js.map +1 -0
- package/dist/module/pipelines/pipeline-result.js +58 -0
- package/dist/module/pipelines/pipeline-result.js.map +1 -0
- package/dist/module/pipelines/pipeline-source.js +4 -0
- package/dist/module/pipelines/pipeline-source.js.map +1 -0
- package/dist/module/pipelines/pipeline.js +4 -0
- package/dist/module/pipelines/pipeline.js.map +1 -0
- package/dist/module/pipelines/pipeline_impl.js +42 -0
- package/dist/module/pipelines/pipeline_impl.js.map +1 -0
- package/dist/module/pipelines/pipeline_options.js +4 -0
- package/dist/module/pipelines/pipeline_options.js.map +1 -0
- package/dist/module/pipelines/pipeline_runtime.js +526 -0
- package/dist/module/pipelines/pipeline_runtime.js.map +1 -0
- package/dist/module/pipelines/pipeline_support.js +71 -0
- package/dist/module/pipelines/pipeline_support.js.map +1 -0
- package/dist/module/pipelines/pipeline_validate.js +183 -0
- package/dist/module/pipelines/pipeline_validate.js.map +1 -0
- package/dist/module/pipelines/stage_options.js +4 -0
- package/dist/module/pipelines/stage_options.js.map +1 -0
- package/dist/module/pipelines/types.js +2 -0
- package/dist/module/pipelines/types.js.map +1 -0
- package/dist/module/types/firestore.js +4 -0
- package/dist/module/types/firestore.js.map +1 -0
- package/dist/module/types/internal.js +4 -0
- package/dist/module/types/internal.js.map +1 -0
- package/dist/module/types/namespaced.js +338 -0
- package/dist/module/types/namespaced.js.map +1 -0
- package/{lib → dist/module}/utils/index.js +59 -114
- package/dist/module/utils/index.js.map +1 -0
- package/{lib → dist/module}/utils/serialize.js +58 -116
- package/dist/module/utils/serialize.js.map +1 -0
- package/{lib → dist/module}/utils/typemap.js +6 -20
- package/dist/module/utils/typemap.js.map +1 -0
- package/dist/module/version.js +5 -0
- package/dist/module/version.js.map +1 -0
- package/dist/module/web/RNFBFirestoreModule.android.js +5 -0
- package/dist/module/web/RNFBFirestoreModule.android.js.map +1 -0
- package/dist/module/web/RNFBFirestoreModule.ios.js +5 -0
- package/dist/module/web/RNFBFirestoreModule.ios.js.map +1 -0
- package/dist/module/web/RNFBFirestoreModule.js +387 -0
- package/dist/module/web/RNFBFirestoreModule.js.map +1 -0
- package/{lib → dist/module}/web/convert.js +60 -94
- package/dist/module/web/convert.js.map +1 -0
- package/dist/module/web/pipelines/pipeline.js +34 -0
- package/dist/module/web/pipelines/pipeline.js.map +1 -0
- package/dist/module/web/pipelines/pipeline_bridge_factory.js +217 -0
- package/dist/module/web/pipelines/pipeline_bridge_factory.js.map +1 -0
- package/dist/module/web/pipelines/pipeline_node_builder.js +294 -0
- package/dist/module/web/pipelines/pipeline_node_builder.js.map +1 -0
- package/dist/module/web/pipelines/pipeline_parser.js +21 -0
- package/dist/module/web/pipelines/pipeline_parser.js.map +1 -0
- package/dist/module/web/pipelines/pipeline_snapshot_serializer.js +89 -0
- package/dist/module/web/pipelines/pipeline_snapshot_serializer.js.map +1 -0
- package/dist/module/web/query.js +95 -0
- package/dist/module/web/query.js.map +1 -0
- package/dist/typescript/lib/FieldPath.d.ts +10 -0
- package/dist/typescript/lib/FieldPath.d.ts.map +1 -0
- package/dist/typescript/lib/FieldValue.d.ts +17 -0
- package/dist/typescript/lib/FieldValue.d.ts.map +1 -0
- package/dist/typescript/lib/FirestoreAggregate.d.ts +40 -0
- package/dist/typescript/lib/FirestoreAggregate.d.ts.map +1 -0
- package/dist/typescript/lib/FirestoreBlob.d.ts +11 -0
- package/dist/typescript/lib/FirestoreBlob.d.ts.map +1 -0
- package/dist/typescript/lib/FirestoreCollectionReference.d.ts +15 -0
- package/dist/typescript/lib/FirestoreCollectionReference.d.ts.map +1 -0
- package/dist/typescript/lib/FirestoreDocumentChange.d.ts +27 -0
- package/dist/typescript/lib/FirestoreDocumentChange.d.ts.map +1 -0
- package/dist/typescript/lib/FirestoreDocumentReference.d.ts +30 -0
- package/dist/typescript/lib/FirestoreDocumentReference.d.ts.map +1 -0
- package/dist/typescript/lib/FirestoreDocumentSnapshot.d.ts +30 -0
- package/dist/typescript/lib/FirestoreDocumentSnapshot.d.ts.map +1 -0
- package/dist/typescript/lib/FirestoreFilter.d.ts +52 -0
- package/dist/typescript/lib/FirestoreFilter.d.ts.map +1 -0
- package/dist/typescript/lib/FirestoreGeoPoint.d.ts +22 -0
- package/dist/typescript/lib/FirestoreGeoPoint.d.ts.map +1 -0
- package/dist/typescript/lib/FirestorePath.d.ts +12 -0
- package/dist/typescript/lib/FirestorePath.d.ts.map +1 -0
- package/dist/typescript/lib/FirestorePersistentCacheIndexManager.d.ts +16 -0
- package/dist/typescript/lib/FirestorePersistentCacheIndexManager.d.ts.map +1 -0
- package/dist/typescript/lib/FirestoreQuery.d.ts +39 -0
- package/dist/typescript/lib/FirestoreQuery.d.ts.map +1 -0
- package/dist/typescript/lib/FirestoreQueryModifiers.d.ts +59 -0
- package/dist/typescript/lib/FirestoreQueryModifiers.d.ts.map +1 -0
- package/dist/typescript/lib/FirestoreQuerySnapshot.d.ts +49 -0
- package/dist/typescript/lib/FirestoreQuerySnapshot.d.ts.map +1 -0
- package/dist/typescript/lib/FirestoreSnapshotMetadata.d.ts +8 -0
- package/dist/typescript/lib/FirestoreSnapshotMetadata.d.ts.map +1 -0
- package/dist/typescript/lib/FirestoreStatics.d.ts +23 -0
- package/dist/typescript/lib/FirestoreStatics.d.ts.map +1 -0
- package/dist/typescript/lib/FirestoreTimestamp.d.ts +33 -0
- package/dist/typescript/lib/FirestoreTimestamp.d.ts.map +1 -0
- package/dist/typescript/lib/FirestoreTransaction.d.ts +42 -0
- package/dist/typescript/lib/FirestoreTransaction.d.ts.map +1 -0
- package/dist/typescript/lib/FirestoreTransactionHandler.d.ts +26 -0
- package/dist/typescript/lib/FirestoreTransactionHandler.d.ts.map +1 -0
- package/dist/typescript/lib/FirestoreVectorValue.d.ts +17 -0
- package/dist/typescript/lib/FirestoreVectorValue.d.ts.map +1 -0
- package/dist/typescript/lib/FirestoreWriteBatch.d.ts +21 -0
- package/dist/typescript/lib/FirestoreWriteBatch.d.ts.map +1 -0
- package/dist/typescript/lib/LoadBundleTask.d.ts +16 -0
- package/dist/typescript/lib/LoadBundleTask.d.ts.map +1 -0
- package/dist/typescript/lib/index.d.ts +6 -0
- package/dist/typescript/lib/index.d.ts.map +1 -0
- package/dist/typescript/lib/modular/Bytes.d.ts +22 -0
- package/dist/typescript/lib/modular/Bytes.d.ts.map +1 -0
- package/dist/typescript/lib/modular/FieldPath.d.ts +4 -0
- package/dist/typescript/lib/modular/FieldPath.d.ts.map +1 -0
- package/dist/typescript/lib/modular/FieldValue.d.ts +8 -0
- package/dist/typescript/lib/modular/FieldValue.d.ts.map +1 -0
- package/dist/typescript/lib/modular/GeoPoint.d.ts +3 -0
- package/dist/typescript/lib/modular/GeoPoint.d.ts.map +1 -0
- package/dist/typescript/lib/modular/Timestamp.d.ts +3 -0
- package/dist/typescript/lib/modular/Timestamp.d.ts.map +1 -0
- package/dist/typescript/lib/modular/VectorValue.d.ts +4 -0
- package/dist/typescript/lib/modular/VectorValue.d.ts.map +1 -0
- package/dist/typescript/lib/modular/query.d.ts +93 -0
- package/dist/typescript/lib/modular/query.d.ts.map +1 -0
- package/dist/typescript/lib/modular/snapshot.d.ts +30 -0
- package/dist/typescript/lib/modular/snapshot.d.ts.map +1 -0
- package/dist/typescript/lib/modular.d.ts +69 -0
- package/dist/typescript/lib/modular.d.ts.map +1 -0
- package/dist/typescript/lib/namespaced.d.ts +13 -0
- package/dist/typescript/lib/namespaced.d.ts.map +1 -0
- package/dist/typescript/lib/pipelines/expressions.d.ts +723 -0
- package/dist/typescript/lib/pipelines/expressions.d.ts.map +1 -0
- package/dist/typescript/lib/pipelines/index.d.ts +31 -0
- package/dist/typescript/lib/pipelines/index.d.ts.map +1 -0
- package/dist/typescript/lib/pipelines/pipeline-result.d.ts +30 -0
- package/dist/typescript/lib/pipelines/pipeline-result.d.ts.map +1 -0
- package/dist/typescript/lib/pipelines/pipeline-source.d.ts +64 -0
- package/dist/typescript/lib/pipelines/pipeline-source.d.ts.map +1 -0
- package/dist/typescript/lib/pipelines/pipeline.d.ts +61 -0
- package/dist/typescript/lib/pipelines/pipeline.d.ts.map +1 -0
- package/dist/typescript/lib/pipelines/pipeline_impl.d.ts +21 -0
- package/dist/typescript/lib/pipelines/pipeline_impl.d.ts.map +1 -0
- package/dist/typescript/lib/pipelines/pipeline_options.d.ts +17 -0
- package/dist/typescript/lib/pipelines/pipeline_options.d.ts.map +1 -0
- package/dist/typescript/lib/pipelines/pipeline_runtime.d.ts +10 -0
- package/dist/typescript/lib/pipelines/pipeline_runtime.d.ts.map +1 -0
- package/dist/typescript/lib/pipelines/pipeline_support.d.ts +7 -0
- package/dist/typescript/lib/pipelines/pipeline_support.d.ts.map +1 -0
- package/dist/typescript/lib/pipelines/pipeline_validate.d.ts +9 -0
- package/dist/typescript/lib/pipelines/pipeline_validate.d.ts.map +1 -0
- package/dist/typescript/lib/pipelines/stage_options.d.ts +326 -0
- package/dist/typescript/lib/pipelines/stage_options.d.ts.map +1 -0
- package/dist/typescript/lib/pipelines/types.d.ts +10 -0
- package/dist/typescript/lib/pipelines/types.d.ts.map +1 -0
- package/dist/typescript/lib/types/firestore.d.ts +263 -0
- package/dist/typescript/lib/types/firestore.d.ts.map +1 -0
- package/dist/typescript/lib/types/internal.d.ts +483 -0
- package/dist/typescript/lib/types/internal.d.ts.map +1 -0
- package/dist/typescript/lib/types/namespaced.d.ts +2285 -0
- package/dist/typescript/lib/types/namespaced.d.ts.map +1 -0
- package/dist/typescript/lib/utils/index.d.ts +15 -0
- package/dist/typescript/lib/utils/index.d.ts.map +1 -0
- package/dist/typescript/lib/utils/serialize.d.ts +17 -0
- package/dist/typescript/lib/utils/serialize.d.ts.map +1 -0
- package/dist/typescript/lib/utils/typemap.d.ts +3 -0
- package/dist/typescript/lib/utils/typemap.d.ts.map +1 -0
- package/dist/typescript/lib/version.d.ts +2 -0
- package/dist/typescript/lib/version.d.ts.map +1 -0
- package/dist/typescript/lib/web/RNFBFirestoreModule.android.d.ts +3 -0
- package/dist/typescript/lib/web/RNFBFirestoreModule.android.d.ts.map +1 -0
- package/dist/typescript/lib/web/RNFBFirestoreModule.d.ts +75 -0
- package/dist/typescript/lib/web/RNFBFirestoreModule.d.ts.map +1 -0
- package/dist/typescript/lib/web/RNFBFirestoreModule.ios.d.ts +3 -0
- package/dist/typescript/lib/web/RNFBFirestoreModule.ios.d.ts.map +1 -0
- package/dist/typescript/lib/web/convert.d.ts +14 -0
- package/dist/typescript/lib/web/convert.d.ts.map +1 -0
- package/dist/typescript/lib/web/pipelines/pipeline.d.ts +4 -0
- package/dist/typescript/lib/web/pipelines/pipeline.d.ts.map +1 -0
- package/dist/typescript/lib/web/pipelines/pipeline_bridge_factory.d.ts +5 -0
- package/dist/typescript/lib/web/pipelines/pipeline_bridge_factory.d.ts.map +1 -0
- package/dist/typescript/lib/web/pipelines/pipeline_node_builder.d.ts +5 -0
- package/dist/typescript/lib/web/pipelines/pipeline_node_builder.d.ts.map +1 -0
- package/dist/typescript/lib/web/pipelines/pipeline_parser.d.ts +3 -0
- package/dist/typescript/lib/web/pipelines/pipeline_parser.d.ts.map +1 -0
- package/dist/typescript/lib/web/pipelines/pipeline_snapshot_serializer.d.ts +4 -0
- package/dist/typescript/lib/web/pipelines/pipeline_snapshot_serializer.d.ts.map +1 -0
- package/dist/typescript/lib/web/query.d.ts +23 -0
- package/dist/typescript/lib/web/query.d.ts.map +1 -0
- package/dist/typescript/package.json +1 -0
- package/ios/RNFBFirestore/RNFBFirestoreCollectionModule.m +52 -2
- package/ios/RNFBFirestore/RNFBFirestorePipelineBridgeFactory.swift +384 -0
- package/ios/RNFBFirestore/RNFBFirestorePipelineCallHandler.swift +86 -0
- package/ios/RNFBFirestore/RNFBFirestorePipelineNodeBuilder.swift +1500 -0
- package/ios/RNFBFirestore/RNFBFirestorePipelineParser.swift +1352 -0
- package/ios/RNFBFirestore/RNFBFirestorePipelineSnapshotSerializer.swift +98 -0
- package/lib/{FirestoreFieldPath.js → FieldPath.ts} +10 -12
- package/lib/{FirestoreFieldValue.js → FieldValue.ts} +22 -19
- package/lib/FirestoreAggregate.ts +124 -0
- package/lib/FirestoreBlob.ts +73 -0
- package/lib/FirestoreCollectionReference.ts +99 -0
- package/lib/FirestoreDocumentChange.ts +71 -0
- package/lib/FirestoreDocumentReference.ts +310 -0
- package/lib/FirestoreDocumentSnapshot.ts +149 -0
- package/lib/FirestoreFilter.ts +232 -0
- package/lib/{FirestoreGeoPoint.js → FirestoreGeoPoint.ts} +48 -8
- package/lib/FirestorePath.ts +54 -0
- package/lib/FirestorePersistentCacheIndexManager.ts +46 -0
- package/lib/{FirestoreQuery.js → FirestoreQuery.ts} +208 -100
- package/lib/FirestoreQueryModifiers.ts +411 -0
- package/lib/{FirestoreQuerySnapshot.js → FirestoreQuerySnapshot.ts} +61 -32
- package/lib/{FirestoreSnapshotMetadata.js → FirestoreSnapshotMetadata.ts} +8 -6
- package/lib/{FirestoreStatics.js → FirestoreStatics.ts} +18 -11
- package/lib/FirestoreTimestamp.ts +161 -0
- package/lib/{FirestoreTransaction.js → FirestoreTransaction.ts} +64 -27
- package/lib/{FirestoreTransactionHandler.js → FirestoreTransactionHandler.ts} +54 -75
- package/lib/{FirestoreVectorValue.js → FirestoreVectorValue.ts} +36 -15
- package/lib/{FirestoreWriteBatch.js → FirestoreWriteBatch.ts} +45 -21
- package/lib/LoadBundleTask.ts +85 -0
- package/lib/index.ts +71 -0
- package/lib/modular/Bytes.ts +81 -0
- package/lib/modular/FieldPath.ts +24 -0
- package/lib/modular/FieldValue.ts +40 -0
- package/lib/modular/GeoPoint.ts +20 -0
- package/lib/modular/Timestamp.ts +20 -0
- package/lib/modular/VectorValue.ts +24 -0
- package/lib/modular/query.ts +368 -0
- package/lib/modular/snapshot.ts +137 -0
- package/lib/modular.ts +552 -0
- package/lib/{index.js → namespaced.ts} +170 -80
- package/lib/pipelines/expressions.ts +2321 -0
- package/lib/pipelines/index.ts +203 -0
- package/lib/pipelines/pipeline-result.ts +78 -0
- package/lib/pipelines/pipeline-source.ts +83 -0
- package/lib/pipelines/pipeline.ts +99 -0
- package/lib/pipelines/pipeline_impl.ts +46 -0
- package/lib/pipelines/pipeline_options.ts +32 -0
- package/lib/pipelines/pipeline_runtime.ts +863 -0
- package/lib/pipelines/pipeline_support.ts +134 -0
- package/lib/pipelines/pipeline_validate.ts +242 -0
- package/lib/pipelines/stage_options.ts +376 -0
- package/lib/pipelines/types.ts +26 -0
- package/lib/types/firestore.ts +477 -0
- package/lib/types/internal.ts +747 -0
- package/lib/{index.d.ts → types/namespaced.ts} +280 -79
- package/lib/utils/index.ts +244 -0
- package/lib/utils/serialize.ts +314 -0
- package/lib/utils/typemap.ts +65 -0
- package/lib/version.ts +2 -0
- package/lib/web/{RNFBFirestoreModule.js → RNFBFirestoreModule.ts} +222 -234
- package/lib/web/convert.ts +287 -0
- package/lib/web/pipelines/pipeline.ts +47 -0
- package/lib/web/pipelines/pipeline_bridge_factory.ts +377 -0
- package/lib/web/pipelines/pipeline_node_builder.ts +413 -0
- package/lib/web/pipelines/pipeline_parser.ts +23 -0
- package/lib/web/pipelines/pipeline_snapshot_serializer.ts +133 -0
- package/lib/web/query.ts +150 -0
- package/package.json +46 -7
- package/tsconfig.json +35 -0
- package/lib/FirestoreBlob.js +0 -107
- package/lib/FirestoreCollectionReference.js +0 -70
- package/lib/FirestoreDocumentReference.js +0 -222
- package/lib/FirestoreDocumentSnapshot.js +0 -132
- package/lib/FirestoreFilter.js +0 -156
- package/lib/modular/Bytes.d.ts +0 -11
- package/lib/modular/Bytes.js +0 -62
- package/lib/modular/FieldPath.d.ts +0 -20
- package/lib/modular/FieldPath.js +0 -7
- package/lib/modular/FieldValue.d.ts +0 -67
- package/lib/modular/FieldValue.js +0 -41
- package/lib/modular/GeoPoint.d.ts +0 -17
- package/lib/modular/GeoPoint.js +0 -3
- package/lib/modular/Timestamp.d.ts +0 -85
- package/lib/modular/Timestamp.js +0 -3
- package/lib/modular/VectorValue.d.ts +0 -30
- package/lib/modular/VectorValue.js +0 -11
- package/lib/modular/index.d.ts +0 -788
- package/lib/modular/index.js +0 -410
- package/lib/modular/query.d.ts +0 -370
- package/lib/modular/query.js +0 -233
- package/lib/modular/snapshot.d.ts +0 -256
- package/lib/modular/snapshot.js +0 -33
- package/lib/modular/utils/observer.js +0 -16
- package/lib/version.js +0 -2
- package/lib/web/query.js +0 -112
- /package/lib/web/{RNFBFirestoreModule.android.js → RNFBFirestoreModule.android.ts} +0 -0
- /package/lib/web/{RNFBFirestoreModule.ios.js → RNFBFirestoreModule.ios.ts} +0 -0
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this library except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import {
|
|
19
|
+
isObject,
|
|
20
|
+
isString,
|
|
21
|
+
isUndefined,
|
|
22
|
+
isNull,
|
|
23
|
+
createDeprecationProxy,
|
|
24
|
+
filterModularArgument,
|
|
25
|
+
} from '@react-native-firebase/app/dist/module/common';
|
|
26
|
+
import NativeError from '@react-native-firebase/app/dist/module/internal/NativeFirebaseError';
|
|
27
|
+
import {
|
|
28
|
+
parseSetOptions,
|
|
29
|
+
parseSnapshotArgs,
|
|
30
|
+
parseUpdateArgs,
|
|
31
|
+
validateWithConverter,
|
|
32
|
+
applyFirestoreDataConverter,
|
|
33
|
+
} from './utils';
|
|
34
|
+
import { buildNativeMap, provideDocumentReferenceClass } from './utils/serialize';
|
|
35
|
+
|
|
36
|
+
import type FirestoreCollectionReferenceClass from './FirestoreCollectionReference';
|
|
37
|
+
import type DocumentSnapshot from './FirestoreDocumentSnapshot';
|
|
38
|
+
import type { FirestoreInternal, FirestoreSyncEventBodyInternal } from './types/internal';
|
|
39
|
+
import type { DocumentSnapshotNativeData } from './FirestoreDocumentSnapshot';
|
|
40
|
+
import type FirestorePath from './FirestorePath';
|
|
41
|
+
import type { DocumentData, FirestoreDataConverter } from './types/firestore';
|
|
42
|
+
|
|
43
|
+
let FirestoreCollectionReference:
|
|
44
|
+
| (new (
|
|
45
|
+
firestore: FirestoreInternal,
|
|
46
|
+
path: FirestorePath,
|
|
47
|
+
converter?: FirestoreDataConverter<DocumentData, DocumentData> | null,
|
|
48
|
+
) => FirestoreCollectionReferenceClass)
|
|
49
|
+
| null = null;
|
|
50
|
+
|
|
51
|
+
export function provideCollectionReferenceClass(
|
|
52
|
+
collectionReference: new (
|
|
53
|
+
firestore: FirestoreInternal,
|
|
54
|
+
path: FirestorePath,
|
|
55
|
+
converter?: FirestoreDataConverter<DocumentData, DocumentData> | null,
|
|
56
|
+
) => FirestoreCollectionReferenceClass,
|
|
57
|
+
): void {
|
|
58
|
+
FirestoreCollectionReference = collectionReference;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
let FirestoreDocumentSnapshotClass:
|
|
62
|
+
| (new (
|
|
63
|
+
firestore: FirestoreInternal,
|
|
64
|
+
data: DocumentSnapshotNativeData,
|
|
65
|
+
converter: FirestoreDataConverter<DocumentData, DocumentData> | null,
|
|
66
|
+
) => DocumentSnapshot)
|
|
67
|
+
| null = null;
|
|
68
|
+
|
|
69
|
+
export function provideDocumentSnapshotClass(
|
|
70
|
+
documentSnapshot: new (
|
|
71
|
+
firestore: FirestoreInternal,
|
|
72
|
+
data: DocumentSnapshotNativeData,
|
|
73
|
+
converter: FirestoreDataConverter<DocumentData, DocumentData> | null,
|
|
74
|
+
) => DocumentSnapshot,
|
|
75
|
+
): void {
|
|
76
|
+
FirestoreDocumentSnapshotClass = documentSnapshot;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
let _id = 0;
|
|
80
|
+
|
|
81
|
+
export default class DocumentReference {
|
|
82
|
+
_firestore: FirestoreInternal;
|
|
83
|
+
_documentPath: FirestorePath;
|
|
84
|
+
_converter: FirestoreDataConverter<DocumentData, DocumentData> | null;
|
|
85
|
+
|
|
86
|
+
constructor(firestore: FirestoreInternal, documentPath: FirestorePath, converter?: unknown) {
|
|
87
|
+
this._firestore = firestore;
|
|
88
|
+
this._documentPath = documentPath;
|
|
89
|
+
this._converter = (converter === undefined ? null : converter) as FirestoreDataConverter<
|
|
90
|
+
DocumentData,
|
|
91
|
+
DocumentData
|
|
92
|
+
> | null;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
get firestore(): FirestoreInternal {
|
|
96
|
+
return this._firestore;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
get converter(): unknown {
|
|
100
|
+
return this._converter;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
get id(): string {
|
|
104
|
+
return this._documentPath.id;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
get parent(): FirestoreCollectionReferenceClass {
|
|
108
|
+
const parentPath = this._documentPath.parent();
|
|
109
|
+
return new FirestoreCollectionReference!(this._firestore, parentPath!, this._converter);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
get path(): string {
|
|
113
|
+
return this._documentPath.relativeName;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
collection(collectionPath: string): FirestoreCollectionReferenceClass {
|
|
117
|
+
if (!isString(collectionPath)) {
|
|
118
|
+
throw new Error(
|
|
119
|
+
"firebase.firestore().doc().collection(*) 'collectionPath' must be a string value.",
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (collectionPath === '') {
|
|
124
|
+
throw new Error(
|
|
125
|
+
"firebase.firestore().doc().collection(*) 'collectionPath' must be a non-empty string.",
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const path = this._documentPath.child(collectionPath);
|
|
130
|
+
|
|
131
|
+
if (!path.isCollection) {
|
|
132
|
+
throw new Error(
|
|
133
|
+
"firebase.firestore().doc().collection(*) 'collectionPath' must point to a collection.",
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return new FirestoreCollectionReference!(this._firestore, path);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
delete(): Promise<void> {
|
|
141
|
+
return this._firestore.native.documentDelete(this.path);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
get(options?: { source?: 'default' | 'server' | 'cache' }): Promise<DocumentSnapshot> {
|
|
145
|
+
if (!isUndefined(options) && !isObject(options)) {
|
|
146
|
+
throw new Error("firebase.firestore().doc().get(*) 'options' must be an object is provided.");
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (
|
|
150
|
+
options &&
|
|
151
|
+
options.source &&
|
|
152
|
+
options.source !== 'default' &&
|
|
153
|
+
options.source !== 'server' &&
|
|
154
|
+
options.source !== 'cache'
|
|
155
|
+
) {
|
|
156
|
+
throw new Error(
|
|
157
|
+
"firebase.firestore().doc().get(*) 'options' GetOptions.source must be one of 'default', 'server' or 'cache'.",
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return this._firestore.native
|
|
162
|
+
.documentGet(this.path, options)
|
|
163
|
+
.then(
|
|
164
|
+
(data: unknown) =>
|
|
165
|
+
createDeprecationProxy(
|
|
166
|
+
new FirestoreDocumentSnapshotClass!(
|
|
167
|
+
this._firestore,
|
|
168
|
+
data as DocumentSnapshotNativeData,
|
|
169
|
+
this._converter,
|
|
170
|
+
),
|
|
171
|
+
) as DocumentSnapshot,
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
isEqual(other: DocumentReference): boolean {
|
|
176
|
+
if (!(other instanceof DocumentReference)) {
|
|
177
|
+
throw new Error(
|
|
178
|
+
"firebase.firestore().doc().isEqual(*) 'other' expected a DocumentReference instance.",
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return !(
|
|
183
|
+
this.path !== other.path ||
|
|
184
|
+
this.firestore.app.name !== other.firestore.app.name ||
|
|
185
|
+
this.firestore.app.options.projectId !== other.firestore.app.options.projectId ||
|
|
186
|
+
this.converter !== other.converter
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
onSnapshot(...args: unknown[]): () => void {
|
|
191
|
+
let snapshotListenOptions: { includeMetadataChanges?: boolean };
|
|
192
|
+
let callback: (snapshot: DocumentSnapshot | null, error: Error | null) => void;
|
|
193
|
+
let onNext: (snapshot: DocumentSnapshot) => void;
|
|
194
|
+
let onError: (error: Error) => void;
|
|
195
|
+
|
|
196
|
+
try {
|
|
197
|
+
const options = parseSnapshotArgs(args);
|
|
198
|
+
snapshotListenOptions = options.snapshotListenOptions;
|
|
199
|
+
callback = options.callback;
|
|
200
|
+
onNext = options.onNext;
|
|
201
|
+
onError = options.onError;
|
|
202
|
+
} catch (e) {
|
|
203
|
+
throw new Error(`firebase.firestore().doc().onSnapshot(*) ${(e as Error).message}`);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function handleSuccess(documentSnapshot: DocumentSnapshot): void {
|
|
207
|
+
callback(documentSnapshot, null);
|
|
208
|
+
onNext(documentSnapshot);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function handleError(error: Error): void {
|
|
212
|
+
callback(null, error);
|
|
213
|
+
onError(error);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const listenerId = _id++;
|
|
217
|
+
|
|
218
|
+
const onSnapshotSubscription = this._firestore.emitter.addListener(
|
|
219
|
+
this._firestore.eventNameForApp(`firestore_document_sync_event:${listenerId}`),
|
|
220
|
+
(event: { body: FirestoreSyncEventBodyInternal }) => {
|
|
221
|
+
if (event.body.error) {
|
|
222
|
+
handleError(NativeError.fromEvent(event.body.error, 'firestore'));
|
|
223
|
+
} else {
|
|
224
|
+
const snapshot = event.body.snapshot;
|
|
225
|
+
if (!snapshot) return;
|
|
226
|
+
const documentSnapshot = createDeprecationProxy(
|
|
227
|
+
new FirestoreDocumentSnapshotClass!(this._firestore, snapshot, this._converter),
|
|
228
|
+
);
|
|
229
|
+
handleSuccess(documentSnapshot);
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
const unsubscribe = (): void => {
|
|
235
|
+
onSnapshotSubscription.remove();
|
|
236
|
+
this._firestore.native.documentOffSnapshot(listenerId);
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
this._firestore.native.documentOnSnapshot(this.path, listenerId, snapshotListenOptions);
|
|
240
|
+
|
|
241
|
+
return unsubscribe;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
set(data: unknown, options?: unknown): Promise<void> {
|
|
245
|
+
let setOptions: ReturnType<typeof parseSetOptions>;
|
|
246
|
+
try {
|
|
247
|
+
setOptions = parseSetOptions(options);
|
|
248
|
+
} catch (e) {
|
|
249
|
+
throw new Error(`firebase.firestore().doc().set(_, *) ${(e as Error).message}.`);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
let converted = data;
|
|
253
|
+
try {
|
|
254
|
+
converted = applyFirestoreDataConverter(data, this._converter, setOptions);
|
|
255
|
+
} catch (e) {
|
|
256
|
+
throw new Error(
|
|
257
|
+
`firebase.firestore().doc().set(*) 'withConverter.toFirestore' threw an error: ${(e as Error).message}.`,
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (!isObject(converted)) {
|
|
262
|
+
throw new Error("firebase.firestore().doc().set(*) 'data' must be an object.");
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return this._firestore.native.documentSet(
|
|
266
|
+
this.path,
|
|
267
|
+
buildNativeMap(converted, this._firestore._settings.ignoreUndefinedProperties),
|
|
268
|
+
setOptions,
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
update(...args: unknown[]): Promise<void> {
|
|
273
|
+
const updatedArgs = filterModularArgument(args);
|
|
274
|
+
if (updatedArgs.length === 0) {
|
|
275
|
+
throw new Error(
|
|
276
|
+
'firebase.firestore().doc().update(*) expected at least 1 argument but was called with 0 arguments.',
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
let data: Record<string, unknown>;
|
|
281
|
+
try {
|
|
282
|
+
data = parseUpdateArgs(updatedArgs);
|
|
283
|
+
} catch (e) {
|
|
284
|
+
throw new Error(`firebase.firestore().doc().update(*) ${(e as Error).message}`);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
return this._firestore.native.documentUpdate(
|
|
288
|
+
this.path,
|
|
289
|
+
buildNativeMap(data, this._firestore._settings.ignoreUndefinedProperties),
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
withConverter(
|
|
294
|
+
converter: FirestoreDataConverter<DocumentData, DocumentData> | null,
|
|
295
|
+
): DocumentReference {
|
|
296
|
+
if (isUndefined(converter) || isNull(converter)) {
|
|
297
|
+
return new DocumentReference(this._firestore, this._documentPath, null);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
try {
|
|
301
|
+
validateWithConverter(converter);
|
|
302
|
+
} catch (e) {
|
|
303
|
+
throw new Error(`firebase.firestore().doc().withConverter() ${(e as Error).message}`);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
return new DocumentReference(this._firestore, this._documentPath, converter);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
provideDocumentReferenceClass(DocumentReference);
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this library except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { isString } from '@react-native-firebase/app/dist/module/common';
|
|
19
|
+
import DocumentReference, { provideDocumentSnapshotClass } from './FirestoreDocumentReference';
|
|
20
|
+
import FieldPath, { fromDotSeparatedString } from './FieldPath';
|
|
21
|
+
import FirestorePath from './FirestorePath';
|
|
22
|
+
import SnapshotMetadata from './FirestoreSnapshotMetadata';
|
|
23
|
+
import type { SnapshotOptions } from './types/firestore';
|
|
24
|
+
import { extractFieldPathData } from './utils';
|
|
25
|
+
import { parseNativeMap } from './utils/serialize';
|
|
26
|
+
import type {
|
|
27
|
+
FirestoreInternal,
|
|
28
|
+
ConverterWithFromFirestoreInternal,
|
|
29
|
+
DocumentFieldValueInternal,
|
|
30
|
+
} from './types/internal';
|
|
31
|
+
import type {
|
|
32
|
+
DocumentData,
|
|
33
|
+
DocumentSnapshot as DocumentSnapshotDeclare,
|
|
34
|
+
FirestoreDataConverter,
|
|
35
|
+
} from './types/firestore';
|
|
36
|
+
|
|
37
|
+
export interface DocumentSnapshotNativeData {
|
|
38
|
+
path: string;
|
|
39
|
+
data?: unknown;
|
|
40
|
+
metadata?: [boolean, boolean];
|
|
41
|
+
exists?: boolean;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export default class DocumentSnapshot {
|
|
45
|
+
_firestore: FirestoreInternal;
|
|
46
|
+
_nativeData: DocumentSnapshotNativeData;
|
|
47
|
+
_data: Record<string, unknown> | undefined;
|
|
48
|
+
_metadata: SnapshotMetadata;
|
|
49
|
+
_ref: DocumentReference;
|
|
50
|
+
_exists: boolean;
|
|
51
|
+
_converter: FirestoreDataConverter<DocumentData, DocumentData> | null;
|
|
52
|
+
|
|
53
|
+
constructor(
|
|
54
|
+
firestore: FirestoreInternal,
|
|
55
|
+
nativeData: DocumentSnapshotNativeData,
|
|
56
|
+
converter: FirestoreDataConverter<DocumentData, DocumentData> | null,
|
|
57
|
+
) {
|
|
58
|
+
this._firestore = firestore;
|
|
59
|
+
this._nativeData = nativeData;
|
|
60
|
+
this._data = parseNativeMap(firestore, nativeData.data as Record<string, unknown> | undefined);
|
|
61
|
+
this._metadata = new SnapshotMetadata(nativeData.metadata ?? [false, false]);
|
|
62
|
+
this._ref = new DocumentReference(firestore, FirestorePath.fromName(nativeData.path));
|
|
63
|
+
this._exists = nativeData.exists ?? false;
|
|
64
|
+
this._converter = converter;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
get id(): string {
|
|
68
|
+
return this._ref.id;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
get metadata(): SnapshotMetadata {
|
|
72
|
+
return this._metadata;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
get ref(): DocumentReference {
|
|
76
|
+
return this._ref;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
exists(): boolean {
|
|
80
|
+
return this._exists;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
data(options?: SnapshotOptions): DocumentData | undefined {
|
|
84
|
+
if (this._converter) {
|
|
85
|
+
try {
|
|
86
|
+
return (this._converter as ConverterWithFromFirestoreInternal).fromFirestore(
|
|
87
|
+
new DocumentSnapshot(
|
|
88
|
+
this._firestore,
|
|
89
|
+
this._nativeData,
|
|
90
|
+
null,
|
|
91
|
+
) as unknown as DocumentSnapshotDeclare<DocumentData, DocumentData>,
|
|
92
|
+
options,
|
|
93
|
+
) as DocumentData;
|
|
94
|
+
} catch (e) {
|
|
95
|
+
throw new Error(
|
|
96
|
+
`firebase.firestore() DocumentSnapshot.data(*) 'withConverter.fromFirestore' threw an error: ${(e as Error).message}.`,
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return this._data;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
get(fieldPath: string | FieldPath, _options?: SnapshotOptions): DocumentFieldValueInternal {
|
|
104
|
+
if (!isString(fieldPath) && !(fieldPath instanceof FieldPath)) {
|
|
105
|
+
throw new Error(
|
|
106
|
+
"firebase.firestore() DocumentSnapshot.get(*) 'fieldPath' expected type string or FieldPath.",
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
let path: FieldPath;
|
|
111
|
+
|
|
112
|
+
if (isString(fieldPath)) {
|
|
113
|
+
try {
|
|
114
|
+
path = fromDotSeparatedString(fieldPath);
|
|
115
|
+
} catch (e) {
|
|
116
|
+
throw new Error(
|
|
117
|
+
`firebase.firestore() DocumentSnapshot.get(*) 'fieldPath' ${(e as Error).message}.`,
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
} else {
|
|
121
|
+
path = fieldPath;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return extractFieldPathData(this._data, path._segments) as DocumentFieldValueInternal;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
isEqual(other: DocumentSnapshot): boolean {
|
|
128
|
+
if (!(other instanceof DocumentSnapshot)) {
|
|
129
|
+
throw new Error(
|
|
130
|
+
"firebase.firestore() DocumentSnapshot.isEqual(*) 'other' expected a DocumentSnapshot instance.",
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (
|
|
135
|
+
this.exists() !== other.exists() ||
|
|
136
|
+
!this.metadata.isEqual(other.metadata) ||
|
|
137
|
+
!this.ref.isEqual(other.ref)
|
|
138
|
+
) {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const thisData = JSON.stringify(this.data());
|
|
143
|
+
const otherData = JSON.stringify(other.data());
|
|
144
|
+
|
|
145
|
+
return thisData === otherData;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
provideDocumentSnapshotClass(DocumentSnapshot);
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this library except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import {
|
|
19
|
+
isArray,
|
|
20
|
+
isNull,
|
|
21
|
+
isString,
|
|
22
|
+
isUndefined,
|
|
23
|
+
} from '@react-native-firebase/app/dist/module/common';
|
|
24
|
+
import { fromDotSeparatedString } from './FieldPath';
|
|
25
|
+
import { OPERATORS } from './FirestoreQueryModifiers';
|
|
26
|
+
import { generateNativeData } from './utils/serialize';
|
|
27
|
+
import type FieldPath from './FieldPath';
|
|
28
|
+
import type { Primitive } from './types/firestore';
|
|
29
|
+
|
|
30
|
+
const AND_QUERY = 'AND';
|
|
31
|
+
const OR_QUERY = 'OR';
|
|
32
|
+
|
|
33
|
+
type FilterOperator = typeof AND_QUERY | typeof OR_QUERY;
|
|
34
|
+
type FieldFilterOperator = keyof typeof OPERATORS;
|
|
35
|
+
|
|
36
|
+
/** Value allowed in a filter (primitive, object, or array for in/array-contains-any). */
|
|
37
|
+
type FilterValue = Primitive | Record<string, unknown> | unknown[];
|
|
38
|
+
|
|
39
|
+
export function Filter(
|
|
40
|
+
fieldPath: string | FieldPath,
|
|
41
|
+
operator: FieldFilterOperator,
|
|
42
|
+
value: FilterValue | unknown,
|
|
43
|
+
): _Filter {
|
|
44
|
+
return new _Filter(fieldPath, operator, value as FilterValue);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export class _Filter {
|
|
48
|
+
fieldPath?: string | FieldPath;
|
|
49
|
+
operator: FieldFilterOperator | FilterOperator;
|
|
50
|
+
value?: FilterValue;
|
|
51
|
+
queries?: _Filter[];
|
|
52
|
+
|
|
53
|
+
constructor(
|
|
54
|
+
fieldPath: string | FieldPath | null,
|
|
55
|
+
operator: FieldFilterOperator | FilterOperator | null,
|
|
56
|
+
value: FilterValue | null,
|
|
57
|
+
filterOperator?: FilterOperator,
|
|
58
|
+
queries?: _Filter[],
|
|
59
|
+
) {
|
|
60
|
+
if (filterOperator !== undefined && [AND_QUERY, OR_QUERY].includes(filterOperator)) {
|
|
61
|
+
this.operator = filterOperator;
|
|
62
|
+
this.queries = queries;
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
this.fieldPath = fieldPath ?? undefined;
|
|
67
|
+
this.operator = operator as FieldFilterOperator | FilterOperator;
|
|
68
|
+
// Preserve null for == / != (required for mapFieldQuery; do not coerce to undefined)
|
|
69
|
+
this.value = value as FilterValue | undefined;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
_toMap(): FilterMap {
|
|
73
|
+
if ([AND_QUERY, OR_QUERY].includes(this.operator as FilterOperator)) {
|
|
74
|
+
return {
|
|
75
|
+
operator: this.operator,
|
|
76
|
+
queries: this.queries!.map(query => query._toMap()),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
fieldPath: this.fieldPath,
|
|
82
|
+
operator: this.operator,
|
|
83
|
+
value: this.value,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
Filter.and = function and(...queries: _Filter[]): _Filter {
|
|
89
|
+
if (queries.length > 10 || queries.length < 1) {
|
|
90
|
+
throw new Error(`Expected 1-10 instances of Filter, but got ${queries.length} Filters`);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const validateFilters = queries.every(filter => filter instanceof _Filter);
|
|
94
|
+
if (!validateFilters) {
|
|
95
|
+
throw new Error('Expected every argument to be an instance of Filter');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return new _Filter(null, null, null, AND_QUERY, queries);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/** Serialized field filter or composite (AND/OR) for generateFilters output. */
|
|
102
|
+
interface SerializedFieldFilter {
|
|
103
|
+
fieldPath: FieldPath | string[];
|
|
104
|
+
operator: string;
|
|
105
|
+
value: [number, unknown?] | null;
|
|
106
|
+
}
|
|
107
|
+
interface SerializedCompositeFilter {
|
|
108
|
+
operator: FilterOperator;
|
|
109
|
+
queries: SerializedFilterSpec[];
|
|
110
|
+
}
|
|
111
|
+
type SerializedFilterSpec = SerializedFieldFilter | SerializedCompositeFilter;
|
|
112
|
+
|
|
113
|
+
function hasOrOperator(obj: _Filter): boolean {
|
|
114
|
+
return (
|
|
115
|
+
obj.operator === OR_QUERY ||
|
|
116
|
+
(Array.isArray(obj.queries) && obj.queries.some(query => hasOrOperator(query)))
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
Filter.or = function or(...queries: _Filter[]): _Filter {
|
|
121
|
+
if (queries.length > 10 || queries.length < 1) {
|
|
122
|
+
throw new Error(`Expected 1-10 instances of Filter, but got ${queries.length} Filters`);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const validateFilters = queries.every(filter => filter instanceof _Filter);
|
|
126
|
+
if (!validateFilters) {
|
|
127
|
+
throw new Error('Expected every argument to be an instance of Filter');
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (queries.some(hasOrOperator)) {
|
|
131
|
+
throw new Error('OR Filters with nested OR Filters are not supported');
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return new _Filter(null, null, null, OR_QUERY, queries);
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
interface FilterMap {
|
|
138
|
+
fieldPath?: string | FieldPath;
|
|
139
|
+
operator: FieldFilterOperator | FilterOperator;
|
|
140
|
+
value?: FilterValue;
|
|
141
|
+
queries?: FilterMap[];
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Modifiers object passed to generateFilters (e.g. QueryModifiers). */
|
|
145
|
+
export interface FilterModifiersInternal {
|
|
146
|
+
isValidOperator(operator: string): boolean;
|
|
147
|
+
isEqualOperator(operator: string): boolean;
|
|
148
|
+
isNotEqualOperator(operator: string): boolean;
|
|
149
|
+
isInOperator(operator: string): boolean;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function mapFieldQuery(
|
|
153
|
+
filterMap: FilterMap,
|
|
154
|
+
modifiers: FilterModifiersInternal,
|
|
155
|
+
): SerializedFilterSpec {
|
|
156
|
+
const { fieldPath, operator, value, queries } = filterMap;
|
|
157
|
+
if (operator === AND_QUERY || operator === OR_QUERY) {
|
|
158
|
+
return {
|
|
159
|
+
operator,
|
|
160
|
+
queries: (queries ?? []).map(q => mapFieldQuery(q, modifiers)),
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
let path: FieldPath | string;
|
|
165
|
+
if (isString(fieldPath)) {
|
|
166
|
+
try {
|
|
167
|
+
path = fromDotSeparatedString(fieldPath);
|
|
168
|
+
} catch (e) {
|
|
169
|
+
throw new Error(`first argument of Filter(*,_ , _) 'fieldPath' ${(e as Error).message}.`);
|
|
170
|
+
}
|
|
171
|
+
} else if (fieldPath !== undefined) {
|
|
172
|
+
path = fieldPath;
|
|
173
|
+
} else {
|
|
174
|
+
throw new Error("first argument of Filter(*,_ , _) 'fieldPath' is required.");
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (!modifiers.isValidOperator(operator)) {
|
|
178
|
+
throw new Error(
|
|
179
|
+
"second argument of Filter(*,_ , _) 'opStr' is invalid. Expected one of '==', '>', '>=', '<', '<=', '!=', 'array-contains', 'not-in', 'array-contains-any' or 'in'.",
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (isUndefined(value)) {
|
|
184
|
+
throw new Error("third argument of Filter(*,_ , _) 'value' argument expected.");
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (
|
|
188
|
+
isNull(value) &&
|
|
189
|
+
!modifiers.isEqualOperator(operator) &&
|
|
190
|
+
!modifiers.isNotEqualOperator(operator)
|
|
191
|
+
) {
|
|
192
|
+
throw new Error(
|
|
193
|
+
"third argument of Filter(*,_ , _) 'value' is invalid. You can only perform equals comparisons on null",
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (modifiers.isInOperator(operator)) {
|
|
198
|
+
if (!isArray(value) || !value.length) {
|
|
199
|
+
throw new Error(
|
|
200
|
+
`third argument of Filter(*,_ , _) 'value' is invalid. A non-empty array is required for '${String(
|
|
201
|
+
operator,
|
|
202
|
+
)}' filters.`,
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (value.length > 10) {
|
|
207
|
+
throw new Error(
|
|
208
|
+
`third argument of Filter(*,_ , _) 'value' is invalid. '${String(
|
|
209
|
+
operator,
|
|
210
|
+
)}' filters support a maximum of 10 elements in the value array.`,
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return {
|
|
216
|
+
fieldPath: path,
|
|
217
|
+
operator: OPERATORS[operator as FieldFilterOperator]!,
|
|
218
|
+
value: generateNativeData(value, true),
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export function generateFilters(
|
|
223
|
+
filter: _Filter,
|
|
224
|
+
modifiers: FilterModifiersInternal,
|
|
225
|
+
): { operator: string; queries: SerializedFilterSpec[] } {
|
|
226
|
+
const filterMap = filter._toMap();
|
|
227
|
+
const queries = (filterMap.queries ?? []).map(q => mapFieldQuery(q, modifiers));
|
|
228
|
+
return {
|
|
229
|
+
operator: filterMap.operator ?? '',
|
|
230
|
+
queries,
|
|
231
|
+
};
|
|
232
|
+
}
|