@react-native-firebase/firestore 23.8.6 → 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.
Files changed (359) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/RNFBFirestore.podspec +2 -1
  3. package/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreCollectionModule.java +17 -4
  4. package/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreDocumentModule.java +2 -2
  5. package/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestorePipelineExecutor.java +1243 -0
  6. package/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestorePipelineNodeBuilder.java +3919 -0
  7. package/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestorePipelineParser.java +1735 -0
  8. package/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreSerialize.java +1 -1
  9. package/dist/module/FieldPath.js +59 -0
  10. package/dist/module/FieldPath.js.map +1 -0
  11. package/dist/module/FieldValue.js +82 -0
  12. package/dist/module/FieldValue.js.map +1 -0
  13. package/{lib → dist/module}/FirestoreAggregate.js +31 -43
  14. package/dist/module/FirestoreAggregate.js.map +1 -0
  15. package/dist/module/FirestoreBlob.js +56 -0
  16. package/dist/module/FirestoreBlob.js.map +1 -0
  17. package/dist/module/FirestoreCollectionReference.js +70 -0
  18. package/dist/module/FirestoreCollectionReference.js.map +1 -0
  19. package/{lib → dist/module}/FirestoreDocumentChange.js +12 -15
  20. package/dist/module/FirestoreDocumentChange.js.map +1 -0
  21. package/dist/module/FirestoreDocumentReference.js +170 -0
  22. package/dist/module/FirestoreDocumentReference.js.map +1 -0
  23. package/dist/module/FirestoreDocumentSnapshot.js +88 -0
  24. package/dist/module/FirestoreDocumentSnapshot.js.map +1 -0
  25. package/dist/module/FirestoreFilter.js +146 -0
  26. package/dist/module/FirestoreFilter.js.map +1 -0
  27. package/dist/module/FirestoreGeoPoint.js +80 -0
  28. package/dist/module/FirestoreGeoPoint.js.map +1 -0
  29. package/{lib → dist/module}/FirestorePath.js +5 -12
  30. package/dist/module/FirestorePath.js.map +1 -0
  31. package/{lib → dist/module}/FirestorePersistentCacheIndexManager.js +11 -4
  32. package/dist/module/FirestorePersistentCacheIndexManager.js.map +1 -0
  33. package/dist/module/FirestoreQuery.js +298 -0
  34. package/dist/module/FirestoreQuery.js.map +1 -0
  35. package/{lib → dist/module}/FirestoreQueryModifiers.js +25 -136
  36. package/dist/module/FirestoreQueryModifiers.js.map +1 -0
  37. package/dist/module/FirestoreQuerySnapshot.js +98 -0
  38. package/dist/module/FirestoreQuerySnapshot.js.map +1 -0
  39. package/dist/module/FirestoreSnapshotMetadata.js +38 -0
  40. package/dist/module/FirestoreSnapshotMetadata.js.map +1 -0
  41. package/dist/module/FirestoreStatics.js +50 -0
  42. package/dist/module/FirestoreStatics.js.map +1 -0
  43. package/{lib → dist/module}/FirestoreTimestamp.js +39 -39
  44. package/dist/module/FirestoreTimestamp.js.map +1 -0
  45. package/dist/module/FirestoreTransaction.js +113 -0
  46. package/dist/module/FirestoreTransaction.js.map +1 -0
  47. package/dist/module/FirestoreTransactionHandler.js +137 -0
  48. package/dist/module/FirestoreTransactionHandler.js.map +1 -0
  49. package/dist/module/FirestoreVectorValue.js +75 -0
  50. package/dist/module/FirestoreVectorValue.js.map +1 -0
  51. package/dist/module/FirestoreWriteBatch.js +113 -0
  52. package/dist/module/FirestoreWriteBatch.js.map +1 -0
  53. package/dist/module/LoadBundleTask.js +70 -0
  54. package/dist/module/LoadBundleTask.js.map +1 -0
  55. package/dist/module/index.js +31 -0
  56. package/dist/module/index.js.map +1 -0
  57. package/dist/module/modular/Bytes.js +67 -0
  58. package/dist/module/modular/Bytes.js.map +1 -0
  59. package/dist/module/modular/FieldPath.js +25 -0
  60. package/dist/module/modular/FieldPath.js.map +1 -0
  61. package/dist/module/modular/FieldValue.js +37 -0
  62. package/dist/module/modular/FieldValue.js.map +1 -0
  63. package/dist/module/modular/GeoPoint.js +22 -0
  64. package/dist/module/modular/GeoPoint.js.map +1 -0
  65. package/dist/module/modular/Timestamp.js +22 -0
  66. package/dist/module/modular/Timestamp.js.map +1 -0
  67. package/dist/module/modular/VectorValue.js +25 -0
  68. package/dist/module/modular/VectorValue.js.map +1 -0
  69. package/dist/module/modular/query.js +222 -0
  70. package/dist/module/modular/query.js.map +1 -0
  71. package/dist/module/modular/snapshot.js +32 -0
  72. package/dist/module/modular/snapshot.js.map +1 -0
  73. package/dist/module/modular.js +229 -0
  74. package/dist/module/modular.js.map +1 -0
  75. package/dist/module/namespaced.js +298 -0
  76. package/dist/module/namespaced.js.map +1 -0
  77. package/dist/module/package.json +1 -0
  78. package/dist/module/pipelines/expressions.js +1273 -0
  79. package/dist/module/pipelines/expressions.js.map +1 -0
  80. package/dist/module/pipelines/index.js +32 -0
  81. package/dist/module/pipelines/index.js.map +1 -0
  82. package/dist/module/pipelines/pipeline-result.js +58 -0
  83. package/dist/module/pipelines/pipeline-result.js.map +1 -0
  84. package/dist/module/pipelines/pipeline-source.js +4 -0
  85. package/dist/module/pipelines/pipeline-source.js.map +1 -0
  86. package/dist/module/pipelines/pipeline.js +4 -0
  87. package/dist/module/pipelines/pipeline.js.map +1 -0
  88. package/dist/module/pipelines/pipeline_impl.js +42 -0
  89. package/dist/module/pipelines/pipeline_impl.js.map +1 -0
  90. package/dist/module/pipelines/pipeline_options.js +4 -0
  91. package/dist/module/pipelines/pipeline_options.js.map +1 -0
  92. package/dist/module/pipelines/pipeline_runtime.js +526 -0
  93. package/dist/module/pipelines/pipeline_runtime.js.map +1 -0
  94. package/dist/module/pipelines/pipeline_support.js +71 -0
  95. package/dist/module/pipelines/pipeline_support.js.map +1 -0
  96. package/dist/module/pipelines/pipeline_validate.js +183 -0
  97. package/dist/module/pipelines/pipeline_validate.js.map +1 -0
  98. package/dist/module/pipelines/stage_options.js +4 -0
  99. package/dist/module/pipelines/stage_options.js.map +1 -0
  100. package/dist/module/pipelines/types.js +2 -0
  101. package/dist/module/pipelines/types.js.map +1 -0
  102. package/dist/module/types/firestore.js +4 -0
  103. package/dist/module/types/firestore.js.map +1 -0
  104. package/dist/module/types/internal.js +4 -0
  105. package/dist/module/types/internal.js.map +1 -0
  106. package/dist/module/types/namespaced.js +338 -0
  107. package/dist/module/types/namespaced.js.map +1 -0
  108. package/{lib → dist/module}/utils/index.js +59 -114
  109. package/dist/module/utils/index.js.map +1 -0
  110. package/{lib → dist/module}/utils/serialize.js +58 -116
  111. package/dist/module/utils/serialize.js.map +1 -0
  112. package/{lib → dist/module}/utils/typemap.js +6 -20
  113. package/dist/module/utils/typemap.js.map +1 -0
  114. package/dist/module/version.js +5 -0
  115. package/dist/module/version.js.map +1 -0
  116. package/dist/module/web/RNFBFirestoreModule.android.js +5 -0
  117. package/dist/module/web/RNFBFirestoreModule.android.js.map +1 -0
  118. package/dist/module/web/RNFBFirestoreModule.ios.js +5 -0
  119. package/dist/module/web/RNFBFirestoreModule.ios.js.map +1 -0
  120. package/dist/module/web/RNFBFirestoreModule.js +387 -0
  121. package/dist/module/web/RNFBFirestoreModule.js.map +1 -0
  122. package/{lib → dist/module}/web/convert.js +60 -94
  123. package/dist/module/web/convert.js.map +1 -0
  124. package/dist/module/web/pipelines/pipeline.js +34 -0
  125. package/dist/module/web/pipelines/pipeline.js.map +1 -0
  126. package/dist/module/web/pipelines/pipeline_bridge_factory.js +217 -0
  127. package/dist/module/web/pipelines/pipeline_bridge_factory.js.map +1 -0
  128. package/dist/module/web/pipelines/pipeline_node_builder.js +294 -0
  129. package/dist/module/web/pipelines/pipeline_node_builder.js.map +1 -0
  130. package/dist/module/web/pipelines/pipeline_parser.js +21 -0
  131. package/dist/module/web/pipelines/pipeline_parser.js.map +1 -0
  132. package/dist/module/web/pipelines/pipeline_snapshot_serializer.js +89 -0
  133. package/dist/module/web/pipelines/pipeline_snapshot_serializer.js.map +1 -0
  134. package/dist/module/web/query.js +95 -0
  135. package/dist/module/web/query.js.map +1 -0
  136. package/dist/typescript/lib/FieldPath.d.ts +10 -0
  137. package/dist/typescript/lib/FieldPath.d.ts.map +1 -0
  138. package/dist/typescript/lib/FieldValue.d.ts +17 -0
  139. package/dist/typescript/lib/FieldValue.d.ts.map +1 -0
  140. package/dist/typescript/lib/FirestoreAggregate.d.ts +40 -0
  141. package/dist/typescript/lib/FirestoreAggregate.d.ts.map +1 -0
  142. package/dist/typescript/lib/FirestoreBlob.d.ts +11 -0
  143. package/dist/typescript/lib/FirestoreBlob.d.ts.map +1 -0
  144. package/dist/typescript/lib/FirestoreCollectionReference.d.ts +15 -0
  145. package/dist/typescript/lib/FirestoreCollectionReference.d.ts.map +1 -0
  146. package/dist/typescript/lib/FirestoreDocumentChange.d.ts +27 -0
  147. package/dist/typescript/lib/FirestoreDocumentChange.d.ts.map +1 -0
  148. package/dist/typescript/lib/FirestoreDocumentReference.d.ts +30 -0
  149. package/dist/typescript/lib/FirestoreDocumentReference.d.ts.map +1 -0
  150. package/dist/typescript/lib/FirestoreDocumentSnapshot.d.ts +30 -0
  151. package/dist/typescript/lib/FirestoreDocumentSnapshot.d.ts.map +1 -0
  152. package/dist/typescript/lib/FirestoreFilter.d.ts +52 -0
  153. package/dist/typescript/lib/FirestoreFilter.d.ts.map +1 -0
  154. package/dist/typescript/lib/FirestoreGeoPoint.d.ts +22 -0
  155. package/dist/typescript/lib/FirestoreGeoPoint.d.ts.map +1 -0
  156. package/dist/typescript/lib/FirestorePath.d.ts +12 -0
  157. package/dist/typescript/lib/FirestorePath.d.ts.map +1 -0
  158. package/dist/typescript/lib/FirestorePersistentCacheIndexManager.d.ts +16 -0
  159. package/dist/typescript/lib/FirestorePersistentCacheIndexManager.d.ts.map +1 -0
  160. package/dist/typescript/lib/FirestoreQuery.d.ts +39 -0
  161. package/dist/typescript/lib/FirestoreQuery.d.ts.map +1 -0
  162. package/dist/typescript/lib/FirestoreQueryModifiers.d.ts +59 -0
  163. package/dist/typescript/lib/FirestoreQueryModifiers.d.ts.map +1 -0
  164. package/dist/typescript/lib/FirestoreQuerySnapshot.d.ts +49 -0
  165. package/dist/typescript/lib/FirestoreQuerySnapshot.d.ts.map +1 -0
  166. package/dist/typescript/lib/FirestoreSnapshotMetadata.d.ts +8 -0
  167. package/dist/typescript/lib/FirestoreSnapshotMetadata.d.ts.map +1 -0
  168. package/dist/typescript/lib/FirestoreStatics.d.ts +23 -0
  169. package/dist/typescript/lib/FirestoreStatics.d.ts.map +1 -0
  170. package/dist/typescript/lib/FirestoreTimestamp.d.ts +33 -0
  171. package/dist/typescript/lib/FirestoreTimestamp.d.ts.map +1 -0
  172. package/dist/typescript/lib/FirestoreTransaction.d.ts +42 -0
  173. package/dist/typescript/lib/FirestoreTransaction.d.ts.map +1 -0
  174. package/dist/typescript/lib/FirestoreTransactionHandler.d.ts +26 -0
  175. package/dist/typescript/lib/FirestoreTransactionHandler.d.ts.map +1 -0
  176. package/dist/typescript/lib/FirestoreVectorValue.d.ts +17 -0
  177. package/dist/typescript/lib/FirestoreVectorValue.d.ts.map +1 -0
  178. package/dist/typescript/lib/FirestoreWriteBatch.d.ts +21 -0
  179. package/dist/typescript/lib/FirestoreWriteBatch.d.ts.map +1 -0
  180. package/dist/typescript/lib/LoadBundleTask.d.ts +16 -0
  181. package/dist/typescript/lib/LoadBundleTask.d.ts.map +1 -0
  182. package/dist/typescript/lib/index.d.ts +6 -0
  183. package/dist/typescript/lib/index.d.ts.map +1 -0
  184. package/dist/typescript/lib/modular/Bytes.d.ts +22 -0
  185. package/dist/typescript/lib/modular/Bytes.d.ts.map +1 -0
  186. package/dist/typescript/lib/modular/FieldPath.d.ts +4 -0
  187. package/dist/typescript/lib/modular/FieldPath.d.ts.map +1 -0
  188. package/dist/typescript/lib/modular/FieldValue.d.ts +8 -0
  189. package/dist/typescript/lib/modular/FieldValue.d.ts.map +1 -0
  190. package/dist/typescript/lib/modular/GeoPoint.d.ts +3 -0
  191. package/dist/typescript/lib/modular/GeoPoint.d.ts.map +1 -0
  192. package/dist/typescript/lib/modular/Timestamp.d.ts +3 -0
  193. package/dist/typescript/lib/modular/Timestamp.d.ts.map +1 -0
  194. package/dist/typescript/lib/modular/VectorValue.d.ts +4 -0
  195. package/dist/typescript/lib/modular/VectorValue.d.ts.map +1 -0
  196. package/dist/typescript/lib/modular/query.d.ts +93 -0
  197. package/dist/typescript/lib/modular/query.d.ts.map +1 -0
  198. package/dist/typescript/lib/modular/snapshot.d.ts +30 -0
  199. package/dist/typescript/lib/modular/snapshot.d.ts.map +1 -0
  200. package/dist/typescript/lib/modular.d.ts +69 -0
  201. package/dist/typescript/lib/modular.d.ts.map +1 -0
  202. package/dist/typescript/lib/namespaced.d.ts +13 -0
  203. package/dist/typescript/lib/namespaced.d.ts.map +1 -0
  204. package/dist/typescript/lib/pipelines/expressions.d.ts +723 -0
  205. package/dist/typescript/lib/pipelines/expressions.d.ts.map +1 -0
  206. package/dist/typescript/lib/pipelines/index.d.ts +31 -0
  207. package/dist/typescript/lib/pipelines/index.d.ts.map +1 -0
  208. package/dist/typescript/lib/pipelines/pipeline-result.d.ts +30 -0
  209. package/dist/typescript/lib/pipelines/pipeline-result.d.ts.map +1 -0
  210. package/dist/typescript/lib/pipelines/pipeline-source.d.ts +64 -0
  211. package/dist/typescript/lib/pipelines/pipeline-source.d.ts.map +1 -0
  212. package/dist/typescript/lib/pipelines/pipeline.d.ts +61 -0
  213. package/dist/typescript/lib/pipelines/pipeline.d.ts.map +1 -0
  214. package/dist/typescript/lib/pipelines/pipeline_impl.d.ts +21 -0
  215. package/dist/typescript/lib/pipelines/pipeline_impl.d.ts.map +1 -0
  216. package/dist/typescript/lib/pipelines/pipeline_options.d.ts +17 -0
  217. package/dist/typescript/lib/pipelines/pipeline_options.d.ts.map +1 -0
  218. package/dist/typescript/lib/pipelines/pipeline_runtime.d.ts +10 -0
  219. package/dist/typescript/lib/pipelines/pipeline_runtime.d.ts.map +1 -0
  220. package/dist/typescript/lib/pipelines/pipeline_support.d.ts +7 -0
  221. package/dist/typescript/lib/pipelines/pipeline_support.d.ts.map +1 -0
  222. package/dist/typescript/lib/pipelines/pipeline_validate.d.ts +9 -0
  223. package/dist/typescript/lib/pipelines/pipeline_validate.d.ts.map +1 -0
  224. package/dist/typescript/lib/pipelines/stage_options.d.ts +326 -0
  225. package/dist/typescript/lib/pipelines/stage_options.d.ts.map +1 -0
  226. package/dist/typescript/lib/pipelines/types.d.ts +10 -0
  227. package/dist/typescript/lib/pipelines/types.d.ts.map +1 -0
  228. package/dist/typescript/lib/types/firestore.d.ts +263 -0
  229. package/dist/typescript/lib/types/firestore.d.ts.map +1 -0
  230. package/dist/typescript/lib/types/internal.d.ts +483 -0
  231. package/dist/typescript/lib/types/internal.d.ts.map +1 -0
  232. package/dist/typescript/lib/types/namespaced.d.ts +2285 -0
  233. package/dist/typescript/lib/types/namespaced.d.ts.map +1 -0
  234. package/dist/typescript/lib/utils/index.d.ts +15 -0
  235. package/dist/typescript/lib/utils/index.d.ts.map +1 -0
  236. package/dist/typescript/lib/utils/serialize.d.ts +17 -0
  237. package/dist/typescript/lib/utils/serialize.d.ts.map +1 -0
  238. package/dist/typescript/lib/utils/typemap.d.ts +3 -0
  239. package/dist/typescript/lib/utils/typemap.d.ts.map +1 -0
  240. package/dist/typescript/lib/version.d.ts +2 -0
  241. package/dist/typescript/lib/version.d.ts.map +1 -0
  242. package/dist/typescript/lib/web/RNFBFirestoreModule.android.d.ts +3 -0
  243. package/dist/typescript/lib/web/RNFBFirestoreModule.android.d.ts.map +1 -0
  244. package/dist/typescript/lib/web/RNFBFirestoreModule.d.ts +75 -0
  245. package/dist/typescript/lib/web/RNFBFirestoreModule.d.ts.map +1 -0
  246. package/dist/typescript/lib/web/RNFBFirestoreModule.ios.d.ts +3 -0
  247. package/dist/typescript/lib/web/RNFBFirestoreModule.ios.d.ts.map +1 -0
  248. package/dist/typescript/lib/web/convert.d.ts +14 -0
  249. package/dist/typescript/lib/web/convert.d.ts.map +1 -0
  250. package/dist/typescript/lib/web/pipelines/pipeline.d.ts +4 -0
  251. package/dist/typescript/lib/web/pipelines/pipeline.d.ts.map +1 -0
  252. package/dist/typescript/lib/web/pipelines/pipeline_bridge_factory.d.ts +5 -0
  253. package/dist/typescript/lib/web/pipelines/pipeline_bridge_factory.d.ts.map +1 -0
  254. package/dist/typescript/lib/web/pipelines/pipeline_node_builder.d.ts +5 -0
  255. package/dist/typescript/lib/web/pipelines/pipeline_node_builder.d.ts.map +1 -0
  256. package/dist/typescript/lib/web/pipelines/pipeline_parser.d.ts +3 -0
  257. package/dist/typescript/lib/web/pipelines/pipeline_parser.d.ts.map +1 -0
  258. package/dist/typescript/lib/web/pipelines/pipeline_snapshot_serializer.d.ts +4 -0
  259. package/dist/typescript/lib/web/pipelines/pipeline_snapshot_serializer.d.ts.map +1 -0
  260. package/dist/typescript/lib/web/query.d.ts +23 -0
  261. package/dist/typescript/lib/web/query.d.ts.map +1 -0
  262. package/dist/typescript/package.json +1 -0
  263. package/ios/RNFBFirestore/RNFBFirestoreCollectionModule.m +52 -2
  264. package/ios/RNFBFirestore/RNFBFirestorePipelineBridgeFactory.swift +384 -0
  265. package/ios/RNFBFirestore/RNFBFirestorePipelineCallHandler.swift +86 -0
  266. package/ios/RNFBFirestore/RNFBFirestorePipelineNodeBuilder.swift +1500 -0
  267. package/ios/RNFBFirestore/RNFBFirestorePipelineParser.swift +1352 -0
  268. package/ios/RNFBFirestore/RNFBFirestorePipelineSnapshotSerializer.swift +98 -0
  269. package/lib/{FirestoreFieldPath.js → FieldPath.ts} +10 -12
  270. package/lib/{FirestoreFieldValue.js → FieldValue.ts} +22 -19
  271. package/lib/FirestoreAggregate.ts +124 -0
  272. package/lib/FirestoreBlob.ts +73 -0
  273. package/lib/FirestoreCollectionReference.ts +99 -0
  274. package/lib/FirestoreDocumentChange.ts +71 -0
  275. package/lib/FirestoreDocumentReference.ts +310 -0
  276. package/lib/FirestoreDocumentSnapshot.ts +149 -0
  277. package/lib/FirestoreFilter.ts +232 -0
  278. package/lib/{FirestoreGeoPoint.js → FirestoreGeoPoint.ts} +48 -8
  279. package/lib/FirestorePath.ts +54 -0
  280. package/lib/FirestorePersistentCacheIndexManager.ts +46 -0
  281. package/lib/{FirestoreQuery.js → FirestoreQuery.ts} +208 -100
  282. package/lib/FirestoreQueryModifiers.ts +411 -0
  283. package/lib/{FirestoreQuerySnapshot.js → FirestoreQuerySnapshot.ts} +61 -32
  284. package/lib/{FirestoreSnapshotMetadata.js → FirestoreSnapshotMetadata.ts} +8 -6
  285. package/lib/{FirestoreStatics.js → FirestoreStatics.ts} +18 -11
  286. package/lib/FirestoreTimestamp.ts +161 -0
  287. package/lib/{FirestoreTransaction.js → FirestoreTransaction.ts} +64 -27
  288. package/lib/{FirestoreTransactionHandler.js → FirestoreTransactionHandler.ts} +54 -75
  289. package/lib/{FirestoreVectorValue.js → FirestoreVectorValue.ts} +36 -15
  290. package/lib/{FirestoreWriteBatch.js → FirestoreWriteBatch.ts} +45 -21
  291. package/lib/LoadBundleTask.ts +85 -0
  292. package/lib/index.ts +71 -0
  293. package/lib/modular/Bytes.ts +81 -0
  294. package/lib/modular/FieldPath.ts +24 -0
  295. package/lib/modular/FieldValue.ts +40 -0
  296. package/lib/modular/GeoPoint.ts +20 -0
  297. package/lib/modular/Timestamp.ts +20 -0
  298. package/lib/modular/VectorValue.ts +24 -0
  299. package/lib/modular/query.ts +368 -0
  300. package/lib/modular/snapshot.ts +137 -0
  301. package/lib/modular.ts +552 -0
  302. package/lib/{index.js → namespaced.ts} +170 -80
  303. package/lib/pipelines/expressions.ts +2321 -0
  304. package/lib/pipelines/index.ts +203 -0
  305. package/lib/pipelines/pipeline-result.ts +78 -0
  306. package/lib/pipelines/pipeline-source.ts +83 -0
  307. package/lib/pipelines/pipeline.ts +99 -0
  308. package/lib/pipelines/pipeline_impl.ts +46 -0
  309. package/lib/pipelines/pipeline_options.ts +32 -0
  310. package/lib/pipelines/pipeline_runtime.ts +863 -0
  311. package/lib/pipelines/pipeline_support.ts +134 -0
  312. package/lib/pipelines/pipeline_validate.ts +242 -0
  313. package/lib/pipelines/stage_options.ts +376 -0
  314. package/lib/pipelines/types.ts +26 -0
  315. package/lib/types/firestore.ts +477 -0
  316. package/lib/types/internal.ts +747 -0
  317. package/lib/{index.d.ts → types/namespaced.ts} +280 -79
  318. package/lib/utils/index.ts +244 -0
  319. package/lib/utils/serialize.ts +314 -0
  320. package/lib/utils/typemap.ts +65 -0
  321. package/lib/version.ts +2 -0
  322. package/lib/web/{RNFBFirestoreModule.js → RNFBFirestoreModule.ts} +222 -234
  323. package/lib/web/convert.ts +287 -0
  324. package/lib/web/pipelines/pipeline.ts +47 -0
  325. package/lib/web/pipelines/pipeline_bridge_factory.ts +377 -0
  326. package/lib/web/pipelines/pipeline_node_builder.ts +413 -0
  327. package/lib/web/pipelines/pipeline_parser.ts +23 -0
  328. package/lib/web/pipelines/pipeline_snapshot_serializer.ts +133 -0
  329. package/lib/web/query.ts +150 -0
  330. package/package.json +46 -7
  331. package/tsconfig.json +35 -0
  332. package/lib/FirestoreBlob.js +0 -107
  333. package/lib/FirestoreCollectionReference.js +0 -70
  334. package/lib/FirestoreDocumentReference.js +0 -222
  335. package/lib/FirestoreDocumentSnapshot.js +0 -132
  336. package/lib/FirestoreFilter.js +0 -156
  337. package/lib/modular/Bytes.d.ts +0 -11
  338. package/lib/modular/Bytes.js +0 -62
  339. package/lib/modular/FieldPath.d.ts +0 -20
  340. package/lib/modular/FieldPath.js +0 -7
  341. package/lib/modular/FieldValue.d.ts +0 -67
  342. package/lib/modular/FieldValue.js +0 -41
  343. package/lib/modular/GeoPoint.d.ts +0 -17
  344. package/lib/modular/GeoPoint.js +0 -3
  345. package/lib/modular/Timestamp.d.ts +0 -85
  346. package/lib/modular/Timestamp.js +0 -3
  347. package/lib/modular/VectorValue.d.ts +0 -30
  348. package/lib/modular/VectorValue.js +0 -11
  349. package/lib/modular/index.d.ts +0 -788
  350. package/lib/modular/index.js +0 -410
  351. package/lib/modular/query.d.ts +0 -370
  352. package/lib/modular/query.js +0 -233
  353. package/lib/modular/snapshot.d.ts +0 -256
  354. package/lib/modular/snapshot.js +0 -33
  355. package/lib/modular/utils/observer.js +0 -16
  356. package/lib/version.js +0 -2
  357. package/lib/web/query.js +0 -112
  358. /package/lib/web/{RNFBFirestoreModule.android.js → RNFBFirestoreModule.android.ts} +0 -0
  359. /package/lib/web/{RNFBFirestoreModule.ios.js → RNFBFirestoreModule.ios.ts} +0 -0
@@ -0,0 +1,863 @@
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
+ isIOS,
21
+ isNumber,
22
+ isObject,
23
+ isString,
24
+ isUndefined,
25
+ } from '@react-native-firebase/app/dist/module/common';
26
+ import type {
27
+ FirestoreInternal,
28
+ FirestorePipelineExecuteOptionsInternal,
29
+ FirestorePipelinePrototypeInternal,
30
+ FirestorePipelineResultInternal,
31
+ FirestorePipelineSerializedInternal,
32
+ FirestorePipelineSnapshotInternal,
33
+ FirestorePipelineSourceInternal,
34
+ FirestorePipelineStageInternal,
35
+ FirestorePipelineTimestampInternal,
36
+ QueryWithAggregateInternals,
37
+ } from '../types/internal';
38
+ import type {
39
+ CollectionReference,
40
+ DocumentReference,
41
+ Query,
42
+ DocumentData,
43
+ } from '../types/firestore';
44
+ import FirestorePath from '../FirestorePath';
45
+ import FirestoreTimestamp from '../FirestoreTimestamp';
46
+ import DocumentReferenceClass from '../FirestoreDocumentReference';
47
+ import FieldPath, { fromDotSeparatedString } from '../FieldPath';
48
+ import { extractFieldPathData } from '../utils';
49
+ import { parseNativeMap } from '../utils/serialize';
50
+
51
+ import type {
52
+ AliasedAggregate,
53
+ BooleanExpression,
54
+ Field,
55
+ Ordering,
56
+ Selectable,
57
+ } from './expressions';
58
+ import type { Pipeline } from './pipeline';
59
+ import type {
60
+ PipelineCollectionSourceOptions,
61
+ PipelineCollectionGroupSourceOptions,
62
+ PipelineDatabaseSourceOptions,
63
+ PipelineDocumentsSourceOptions,
64
+ PipelineSource,
65
+ } from './pipeline-source';
66
+ import type { PipelineResult, PipelineSnapshot } from './pipeline-result';
67
+ import type {
68
+ PipelineAggregateOptions,
69
+ PipelineDistinctOptions,
70
+ PipelineFindNearestOptions,
71
+ PipelineRawStageOptions,
72
+ PipelineReplaceWithOptions,
73
+ PipelineSampleOptions,
74
+ PipelineUnionOptions,
75
+ PipelineUnnestOptions,
76
+ } from './stage_options';
77
+ import type { PipelineExecuteOptions } from './pipeline_options';
78
+ import { getFirestore } from '../modular';
79
+ import { getIOSUnsupportedPipelineFunctions } from './pipeline_support';
80
+ import { validateExecuteOptions, validateSerializedPipeline } from './pipeline_validate';
81
+
82
+ const PIPELINE_RUNTIME_SYMBOL = Symbol.for('RNFBFirestorePipelineRuntime');
83
+ const PIPELINE_RUNTIME_INSTALLER_SYMBOL = Symbol.for('RNFBFirestorePipelineRuntimeInstaller');
84
+
85
+ type GlobalWithPipelineInstaller = typeof globalThis & {
86
+ [PIPELINE_RUNTIME_INSTALLER_SYMBOL]?: (firestore?: FirestoreInternal) => void;
87
+ };
88
+
89
+ interface RuntimePipeline extends Pipeline {
90
+ readonly [PIPELINE_RUNTIME_SYMBOL]: true;
91
+ readonly firestore: FirestoreInternal;
92
+ serialize(visiting?: WeakSet<object>): FirestorePipelineSerializedInternal;
93
+ }
94
+
95
+ interface RuntimePipelineStageInternal {
96
+ stage: FirestorePipelineStageInternal['stage'];
97
+ options: Record<string, unknown>;
98
+ }
99
+
100
+ function isRuntimePipeline(value: unknown): value is RuntimePipeline {
101
+ return isObject(value) && (value as unknown as RuntimePipeline)[PIPELINE_RUNTIME_SYMBOL] === true;
102
+ }
103
+
104
+ function isRecord(value: unknown): value is Record<string, unknown> {
105
+ return isObject(value) && !isArray(value);
106
+ }
107
+
108
+ function hasAnyKey(value: Record<string, unknown>, keys: string[]): boolean {
109
+ return keys.some(key => Object.prototype.hasOwnProperty.call(value, key));
110
+ }
111
+
112
+ function assertSameFirestoreInstance(
113
+ actual: FirestoreInternal,
114
+ expected: FirestoreInternal,
115
+ method: 'collection' | 'documents',
116
+ ): void {
117
+ if (actual !== expected) {
118
+ throw new Error(
119
+ `firebase.firestore().pipeline().${method}(*) cannot use a reference from a different Firestore instance.`,
120
+ );
121
+ }
122
+ }
123
+
124
+ function getFirestoreReference(
125
+ value: unknown,
126
+ ): { firestore: FirestoreInternal; path: string } | undefined {
127
+ if (
128
+ isRecord(value) &&
129
+ isRecord(value.firestore) &&
130
+ isString(value.path) &&
131
+ value.path.length > 0
132
+ ) {
133
+ return {
134
+ firestore: value.firestore as unknown as FirestoreInternal,
135
+ path: value.path,
136
+ };
137
+ }
138
+
139
+ return undefined;
140
+ }
141
+
142
+ function parseTimestamp(
143
+ value: FirestorePipelineTimestampInternal | undefined,
144
+ ): FirestoreTimestamp | undefined {
145
+ if (value instanceof FirestoreTimestamp) {
146
+ return value;
147
+ }
148
+
149
+ if (isNumber(value)) {
150
+ return FirestoreTimestamp.fromMillis(value);
151
+ }
152
+
153
+ if (isArray(value)) {
154
+ const seconds = Number(value[0] ?? 0);
155
+ const nanoseconds = Number(value[1] ?? 0);
156
+ return new FirestoreTimestamp(seconds, nanoseconds);
157
+ }
158
+
159
+ if (isRecord(value)) {
160
+ const seconds = Number(value.seconds ?? 0);
161
+ const nanoseconds = Number(value.nanoseconds ?? 0);
162
+ return new FirestoreTimestamp(seconds, nanoseconds);
163
+ }
164
+
165
+ return undefined;
166
+ }
167
+
168
+ function getNativeTypeMapArray(value: unknown): [number, unknown?] | undefined {
169
+ if (isArray(value) && value.length > 0 && isNumber(value[0])) {
170
+ return value as [number, unknown?];
171
+ }
172
+
173
+ if (isRecord(value) && isNumber(value[0])) {
174
+ return [value[0], value[1]];
175
+ }
176
+
177
+ return undefined;
178
+ }
179
+
180
+ function isNativeTypeMapValue(value: unknown): boolean {
181
+ return getNativeTypeMapArray(value) !== undefined;
182
+ }
183
+
184
+ function isNativeTypeMapObject(value: unknown): value is Record<string, unknown> {
185
+ if (!isRecord(value)) {
186
+ return false;
187
+ }
188
+
189
+ const values = Object.values(value);
190
+ if (values.length === 0) {
191
+ return true;
192
+ }
193
+
194
+ return values.every(isNativeTypeMapValue);
195
+ }
196
+
197
+ function fieldPathToSegments(fieldPath: string | FieldPath | Field): string[] {
198
+ if (isString(fieldPath)) {
199
+ return fromDotSeparatedString(fieldPath)._segments;
200
+ }
201
+
202
+ if (fieldPath instanceof FieldPath) {
203
+ return fieldPath._segments;
204
+ }
205
+
206
+ if (isRecord(fieldPath) && isString(fieldPath.path)) {
207
+ return fromDotSeparatedString(fieldPath.path)._segments;
208
+ }
209
+
210
+ throw new Error(
211
+ "firebase.firestore().pipeline().execute().result.get(*) 'fieldPath' must be a string, FieldPath, or field().",
212
+ );
213
+ }
214
+
215
+ class RuntimePipelineResult<T = DocumentData> implements PipelineResult<T> {
216
+ private readonly _data: T;
217
+ readonly ref?: DocumentReference;
218
+ readonly id?: string;
219
+ readonly createTime?: FirestoreTimestamp;
220
+ readonly updateTime?: FirestoreTimestamp;
221
+
222
+ constructor(firestore: FirestoreInternal, nativeResult: FirestorePipelineResultInternal) {
223
+ if (isNativeTypeMapObject(nativeResult.data)) {
224
+ const normalizedData = Object.fromEntries(
225
+ Object.entries(nativeResult.data ?? {}).map(([key, value]) => [
226
+ key,
227
+ getNativeTypeMapArray(value) ?? value,
228
+ ]),
229
+ );
230
+ this._data = parseNativeMap(firestore, normalizedData) as T;
231
+ } else {
232
+ this._data = (nativeResult.data ?? {}) as T;
233
+ }
234
+
235
+ if (isString(nativeResult.path)) {
236
+ this.ref = new DocumentReferenceClass(
237
+ firestore,
238
+ FirestorePath.fromName(nativeResult.path),
239
+ ) as unknown as DocumentReference;
240
+ }
241
+
242
+ this.id = isString(nativeResult.id) ? nativeResult.id : this.ref?.id;
243
+ this.createTime = parseTimestamp(nativeResult.createTime);
244
+ this.updateTime = parseTimestamp(nativeResult.updateTime);
245
+ }
246
+
247
+ data(): T {
248
+ return this._data;
249
+ }
250
+
251
+ get(fieldPath: string | FieldPath | Field): unknown {
252
+ return extractFieldPathData(this._data, fieldPathToSegments(fieldPath));
253
+ }
254
+ }
255
+
256
+ function serializeValue(value: unknown, visiting: WeakSet<object>): unknown {
257
+ if (value instanceof FirestoreTimestamp) {
258
+ return { seconds: value.seconds, nanoseconds: value.nanoseconds };
259
+ }
260
+
261
+ if (value instanceof FieldPath) {
262
+ return { segments: value._toArray() };
263
+ }
264
+
265
+ if (isRuntimePipeline(value)) {
266
+ return value.serialize(visiting);
267
+ }
268
+
269
+ if (isArray(value)) {
270
+ return value.map(entry => serializeValue(entry, visiting));
271
+ }
272
+
273
+ if (isRecord(value)) {
274
+ if (visiting.has(value)) {
275
+ throw new Error(
276
+ 'firebase.firestore().pipeline() failed to serialize arguments because of a circular value.',
277
+ );
278
+ }
279
+
280
+ // Explicit wire format for aliased expressions so native (Android) always receives expr, alias, as.
281
+ const rec = value as Record<string, unknown>;
282
+ if (rec.__kind === 'aliasedExpression' && rec.expr !== undefined && rec.alias !== undefined) {
283
+ visiting.add(value);
284
+ const inner = rec.expr as Record<string, unknown>;
285
+ // Flat form for simple field path: { path, alias, as } so native does not need to parse nested expr.
286
+ if (
287
+ inner &&
288
+ typeof inner === 'object' &&
289
+ (inner.__kind === 'expression' || inner.exprType === 'Field') &&
290
+ typeof inner.path === 'string' &&
291
+ inner.path.length > 0
292
+ ) {
293
+ visiting.delete(value);
294
+ return { path: inner.path, alias: rec.alias, as: rec.alias };
295
+ }
296
+ const result = {
297
+ expr: serializeValue(rec.expr, visiting),
298
+ alias: rec.alias,
299
+ as: rec.alias,
300
+ };
301
+ visiting.delete(value);
302
+ return result;
303
+ }
304
+
305
+ // Convert document/collection references to a stable path representation.
306
+ if (
307
+ isString((value as { path?: unknown }).path) &&
308
+ isObject((value as { firestore?: unknown }).firestore)
309
+ ) {
310
+ return { path: (value as { path: string }).path };
311
+ }
312
+
313
+ visiting.add(value);
314
+ const output: Record<string, unknown> = {};
315
+ const entries = Object.entries(value);
316
+
317
+ for (const [key, entryValue] of entries) {
318
+ if (!isUndefined(entryValue)) {
319
+ output[key] = serializeValue(entryValue, visiting);
320
+ }
321
+ }
322
+
323
+ visiting.delete(value);
324
+ // Ensure aliased expressions have both "alias" and "as" for native (e.g. Android coerceSelectable).
325
+ if (
326
+ typeof (output as Record<string, unknown>).alias !== 'undefined' &&
327
+ (typeof (output as Record<string, unknown>).expr !== 'undefined' ||
328
+ (output as Record<string, unknown>).__kind === 'aliasedExpression')
329
+ ) {
330
+ (output as Record<string, unknown>).as = (output as Record<string, unknown>).alias;
331
+ }
332
+ return output;
333
+ }
334
+
335
+ return value;
336
+ }
337
+
338
+ function ensureNonEmptyString(path: unknown, method: string): string {
339
+ if (!isString(path) || path.length === 0) {
340
+ throw new Error(`firebase.firestore().pipeline().${method}(*) expected a non-empty string.`);
341
+ }
342
+
343
+ return path;
344
+ }
345
+
346
+ function asQueryInternals(query: Query): QueryWithAggregateInternals {
347
+ return query as unknown as QueryWithAggregateInternals;
348
+ }
349
+
350
+ class RuntimePipelineImpl<T = DocumentData> implements RuntimePipeline {
351
+ readonly [PIPELINE_RUNTIME_SYMBOL] = true as const;
352
+ readonly firestore: FirestoreInternal;
353
+
354
+ private readonly _source: FirestorePipelineSourceInternal;
355
+ private readonly _stages: RuntimePipelineStageInternal[];
356
+
357
+ constructor(
358
+ firestore: FirestoreInternal,
359
+ source: FirestorePipelineSourceInternal,
360
+ stages: RuntimePipelineStageInternal[] = [],
361
+ ) {
362
+ this.firestore = firestore;
363
+ this._source = source;
364
+ this._stages = stages;
365
+ }
366
+
367
+ private append(
368
+ stage: RuntimePipelineStageInternal['stage'],
369
+ options: Record<string, unknown>,
370
+ ): RuntimePipelineImpl<T> {
371
+ return new RuntimePipelineImpl(this.firestore, this._source, [
372
+ ...this._stages,
373
+ { stage, options },
374
+ ]);
375
+ }
376
+
377
+ serialize(
378
+ visiting: WeakSet<object> = new WeakSet<object>(),
379
+ ): FirestorePipelineSerializedInternal {
380
+ if (visiting.has(this)) {
381
+ throw new Error('firebase.firestore().pipeline() cannot union a pipeline with itself.');
382
+ }
383
+
384
+ visiting.add(this);
385
+ const stages = this._stages.map(
386
+ stage =>
387
+ ({
388
+ stage: stage.stage,
389
+ options: serializeValue(stage.options, visiting),
390
+ }) as FirestorePipelineStageInternal,
391
+ );
392
+ const source = serializeValue(this._source, visiting) as FirestorePipelineSourceInternal;
393
+ visiting.delete(this);
394
+
395
+ return { source, stages };
396
+ }
397
+
398
+ where(condition: BooleanExpression): Pipeline<T>;
399
+ where(options: { condition: BooleanExpression }): Pipeline<T>;
400
+ where(conditionOrOptions: BooleanExpression | { condition: BooleanExpression }): Pipeline<T> {
401
+ const condition =
402
+ isRecord(conditionOrOptions) && hasAnyKey(conditionOrOptions, ['condition'])
403
+ ? conditionOrOptions.condition
404
+ : conditionOrOptions;
405
+ return this.append('where', { condition });
406
+ }
407
+
408
+ select(...selection: (Selectable | string)[]): Pipeline<T>;
409
+ select(options: { selection: (Selectable | string)[] }): Pipeline<T>;
410
+ select(
411
+ ...selectionOrOptions: (Selectable | string)[] | [{ selection: (Selectable | string)[] }]
412
+ ): Pipeline<T> {
413
+ const first = selectionOrOptions[0];
414
+ const selections =
415
+ selectionOrOptions.length === 1 &&
416
+ isRecord(first) &&
417
+ hasAnyKey(first, ['selection', 'selections'])
418
+ ? (first.selection ?? (first as { selections?: (Selectable | string)[] }).selections) || []
419
+ : (selectionOrOptions as (Selectable | string)[]);
420
+ return this.append('select', { selections });
421
+ }
422
+
423
+ addFields(...field: Selectable[]): Pipeline<T>;
424
+ addFields(options: { field: Selectable[] }): Pipeline<T>;
425
+ addFields(...fieldOrOptions: Selectable[] | [{ field: Selectable[] }]): Pipeline<T> {
426
+ const first = fieldOrOptions[0];
427
+ const fields =
428
+ fieldOrOptions.length === 1 && isRecord(first) && hasAnyKey(first, ['field', 'fields'])
429
+ ? (first.field ?? (first as { fields?: Selectable[] }).fields) || []
430
+ : (fieldOrOptions as Selectable[]);
431
+ return this.append('addFields', { fields });
432
+ }
433
+
434
+ removeFields(...field: (Field | string)[]): Pipeline<T>;
435
+ removeFields(options: { field: (Field | string)[] }): Pipeline<T>;
436
+ removeFields(
437
+ ...fieldOrOptions: (Field | string)[] | [{ field: (Field | string)[] }]
438
+ ): Pipeline<T> {
439
+ const first = fieldOrOptions[0];
440
+ const fields =
441
+ fieldOrOptions.length === 1 && isRecord(first) && hasAnyKey(first, ['field', 'fields'])
442
+ ? (first.field ?? (first as { fields?: (Field | string)[] }).fields) || []
443
+ : (fieldOrOptions as (Field | string)[]);
444
+ return this.append('removeFields', { fields });
445
+ }
446
+
447
+ sort(...ordering: Ordering[]): Pipeline<T>;
448
+ sort(options: { ordering: Ordering[] }): Pipeline<T>;
449
+ sort(...orderingOrOptions: Ordering[] | [{ ordering: Ordering[] }]): Pipeline<T> {
450
+ const first = orderingOrOptions[0];
451
+ const orderings =
452
+ orderingOrOptions.length === 1 &&
453
+ isRecord(first) &&
454
+ hasAnyKey(first, ['ordering', 'orderings'])
455
+ ? (first.ordering ?? (first as { orderings?: Ordering[] }).orderings) || []
456
+ : (orderingOrOptions as Ordering[]);
457
+ return this.append('sort', { orderings });
458
+ }
459
+
460
+ limit(n: number): Pipeline<T>;
461
+ limit(options: { n: number }): Pipeline<T>;
462
+ limit(nOrOptions: number | { n: number }): Pipeline<T> {
463
+ const limit = isNumber(nOrOptions)
464
+ ? nOrOptions
465
+ : Number(nOrOptions.n ?? (nOrOptions as { limit?: number }).limit ?? 0);
466
+ return this.append('limit', { limit });
467
+ }
468
+
469
+ offset(n: number): Pipeline<T>;
470
+ offset(options: { n: number }): Pipeline<T>;
471
+ offset(nOrOptions: number | { n: number }): Pipeline<T> {
472
+ const offset = isNumber(nOrOptions)
473
+ ? nOrOptions
474
+ : Number(nOrOptions.n ?? (nOrOptions as { offset?: number }).offset ?? 0);
475
+ return this.append('offset', { offset });
476
+ }
477
+
478
+ aggregate(...accumulator: AliasedAggregate[]): Pipeline<T>;
479
+ aggregate(options: PipelineAggregateOptions): Pipeline<T>;
480
+ aggregate(...accumulatorOrOptions: AliasedAggregate[] | [PipelineAggregateOptions]): Pipeline<T> {
481
+ const first = accumulatorOrOptions[0];
482
+ const isOptionsRecord =
483
+ accumulatorOrOptions.length === 1 &&
484
+ isRecord(first) &&
485
+ hasAnyKey(first, ['accumulators', 'accumulator', 'groups', 'group']);
486
+ const accumulators = isOptionsRecord
487
+ ? (first.accumulators ?? (first as { accumulator?: AliasedAggregate[] }).accumulator) || []
488
+ : (accumulatorOrOptions as AliasedAggregate[]);
489
+ const groups = isOptionsRecord
490
+ ? ((first.groups ?? (first as { group?: (Field | string)[] }).group) as
491
+ | (string | Selectable)[]
492
+ | undefined)
493
+ : undefined;
494
+
495
+ return this.append('aggregate', { accumulators, groups });
496
+ }
497
+
498
+ distinct(...group: (Field | string)[]): Pipeline<T>;
499
+ distinct(options: PipelineDistinctOptions): Pipeline<T>;
500
+ distinct(...groupOrOptions: (Field | string)[] | [PipelineDistinctOptions]): Pipeline<T> {
501
+ const first = groupOrOptions[0];
502
+ const groups =
503
+ groupOrOptions.length === 1 && isRecord(first) && hasAnyKey(first, ['groups', 'group'])
504
+ ? (first.groups ?? (first as { group?: (Field | string)[] }).group) || []
505
+ : (groupOrOptions as (Field | string)[]);
506
+ return this.append('distinct', { groups });
507
+ }
508
+
509
+ findNearest(options: PipelineFindNearestOptions): Pipeline<T> {
510
+ return this.append('findNearest', options as unknown as Record<string, unknown>);
511
+ }
512
+
513
+ replaceWith(fieldName: string): Pipeline<T>;
514
+ replaceWith(expr: Selectable): Pipeline<T>;
515
+ replaceWith(options: PipelineReplaceWithOptions): Pipeline<T>;
516
+ replaceWith(
517
+ fieldNameOrExprOrOptions: string | Selectable | PipelineReplaceWithOptions,
518
+ ): Pipeline<T> {
519
+ if (isString(fieldNameOrExprOrOptions)) {
520
+ return this.append('replaceWith', { map: fieldNameOrExprOrOptions });
521
+ }
522
+
523
+ if (
524
+ isRecord(fieldNameOrExprOrOptions) &&
525
+ hasAnyKey(fieldNameOrExprOrOptions, ['map', 'expr', 'fieldName'])
526
+ ) {
527
+ const map =
528
+ fieldNameOrExprOrOptions.map ??
529
+ (fieldNameOrExprOrOptions as { expr?: Selectable }).expr ??
530
+ (fieldNameOrExprOrOptions as { fieldName?: string }).fieldName;
531
+ return this.append('replaceWith', { map });
532
+ }
533
+
534
+ return this.append('replaceWith', { map: fieldNameOrExprOrOptions });
535
+ }
536
+
537
+ sample(n: number): Pipeline<T>;
538
+ sample(options: PipelineSampleOptions): Pipeline<T>;
539
+ sample(nOrOptions: number | PipelineSampleOptions): Pipeline<T> {
540
+ if (isNumber(nOrOptions)) {
541
+ return this.append('sample', { documents: nOrOptions });
542
+ }
543
+
544
+ return this.append('sample', nOrOptions as Record<string, unknown>);
545
+ }
546
+
547
+ union(otherPipeline: Pipeline<T>): Pipeline<T>;
548
+ union(options: PipelineUnionOptions<T>): Pipeline<T>;
549
+ union(otherOrOptions: Pipeline<T> | PipelineUnionOptions<T>): Pipeline<T> {
550
+ const other = isRuntimePipeline(otherOrOptions)
551
+ ? otherOrOptions
552
+ : (otherOrOptions as PipelineUnionOptions<T>).pipeline;
553
+
554
+ if (!other || !isRuntimePipeline(other)) {
555
+ throw new Error(
556
+ 'firebase.firestore().pipeline().union(*) expected a pipeline created from firestore.pipeline().',
557
+ );
558
+ }
559
+
560
+ if (other.firestore !== this.firestore) {
561
+ throw new Error(
562
+ 'firebase.firestore().pipeline().union(*) cannot combine pipelines from different Firestore instances.',
563
+ );
564
+ }
565
+
566
+ return this.append('union', { other });
567
+ }
568
+
569
+ unnest(selectable: Selectable, indexField?: string): Pipeline<T>;
570
+ unnest(options: PipelineUnnestOptions): Pipeline<T>;
571
+ unnest(
572
+ selectableOrOptions: Selectable | PipelineUnnestOptions,
573
+ indexField?: string,
574
+ ): Pipeline<T> {
575
+ const isOptionsObject =
576
+ isRecord(selectableOrOptions) &&
577
+ (Object.prototype.hasOwnProperty.call(selectableOrOptions, 'indexField') ||
578
+ (Object.prototype.hasOwnProperty.call(selectableOrOptions, 'selectable') &&
579
+ !hasAnyKey(selectableOrOptions, [
580
+ '__kind',
581
+ 'exprType',
582
+ 'path',
583
+ 'name',
584
+ 'args',
585
+ 'alias',
586
+ ])));
587
+
588
+ if (isOptionsObject) {
589
+ return this.append('unnest', selectableOrOptions as Record<string, unknown>);
590
+ }
591
+
592
+ return this.append('unnest', { selectable: selectableOrOptions, indexField });
593
+ }
594
+
595
+ rawStage(
596
+ name: string,
597
+ params: Record<string, unknown>,
598
+ options?: PipelineRawStageOptions,
599
+ ): Pipeline<T> {
600
+ return this.append('rawStage', { name, params, options: options ?? {} });
601
+ }
602
+ }
603
+
604
+ class RuntimePipelineSourceImpl<
605
+ TPipeline extends Pipeline = Pipeline,
606
+ > implements PipelineSource<TPipeline> {
607
+ private readonly _firestore: FirestoreInternal;
608
+
609
+ constructor(firestore: FirestoreInternal) {
610
+ this._firestore = firestore;
611
+ }
612
+
613
+ collection(path: string): TPipeline;
614
+ collection(collectionRef: CollectionReference): TPipeline;
615
+ collection(options: PipelineCollectionSourceOptions): TPipeline;
616
+ collection(
617
+ pathOrCollectionRefOrOptions: string | CollectionReference | PipelineCollectionSourceOptions,
618
+ ): TPipeline {
619
+ if (isString(pathOrCollectionRefOrOptions)) {
620
+ return new RuntimePipelineImpl(this._firestore, {
621
+ source: 'collection',
622
+ path: ensureNonEmptyString(pathOrCollectionRefOrOptions, 'collection'),
623
+ }) as unknown as TPipeline;
624
+ }
625
+
626
+ if (!isRecord(pathOrCollectionRefOrOptions)) {
627
+ throw new Error(
628
+ 'firebase.firestore().pipeline().collection(*) expected a path, CollectionReference, or options object.',
629
+ );
630
+ }
631
+
632
+ const collectionRef =
633
+ getFirestoreReference(pathOrCollectionRefOrOptions.collectionRef) ??
634
+ getFirestoreReference(pathOrCollectionRefOrOptions);
635
+
636
+ if (collectionRef) {
637
+ assertSameFirestoreInstance(collectionRef.firestore, this._firestore, 'collection');
638
+ }
639
+
640
+ const path = isString(pathOrCollectionRefOrOptions.path)
641
+ ? pathOrCollectionRefOrOptions.path
642
+ : isRecord(pathOrCollectionRefOrOptions.collectionRef) &&
643
+ isString(pathOrCollectionRefOrOptions.collectionRef.path)
644
+ ? pathOrCollectionRefOrOptions.collectionRef.path
645
+ : undefined;
646
+
647
+ return new RuntimePipelineImpl(this._firestore, {
648
+ source: 'collection',
649
+ path: ensureNonEmptyString(path, 'collection'),
650
+ rawOptions: isRecord(pathOrCollectionRefOrOptions.rawOptions)
651
+ ? pathOrCollectionRefOrOptions.rawOptions
652
+ : undefined,
653
+ }) as unknown as TPipeline;
654
+ }
655
+
656
+ collectionGroup(collectionId: string): TPipeline;
657
+ collectionGroup(options: PipelineCollectionGroupSourceOptions): TPipeline;
658
+ collectionGroup(collectionIdOrOptions: string | PipelineCollectionGroupSourceOptions): TPipeline {
659
+ if (isString(collectionIdOrOptions)) {
660
+ return new RuntimePipelineImpl(this._firestore, {
661
+ source: 'collectionGroup',
662
+ collectionId: ensureNonEmptyString(collectionIdOrOptions, 'collectionGroup'),
663
+ }) as unknown as TPipeline;
664
+ }
665
+
666
+ if (!isRecord(collectionIdOrOptions)) {
667
+ throw new Error(
668
+ 'firebase.firestore().pipeline().collectionGroup(*) expected a collectionId string or options object.',
669
+ );
670
+ }
671
+
672
+ return new RuntimePipelineImpl(this._firestore, {
673
+ source: 'collectionGroup',
674
+ collectionId: ensureNonEmptyString(collectionIdOrOptions.collectionId, 'collectionGroup'),
675
+ rawOptions: isRecord(collectionIdOrOptions.rawOptions)
676
+ ? collectionIdOrOptions.rawOptions
677
+ : undefined,
678
+ }) as unknown as TPipeline;
679
+ }
680
+
681
+ database(options?: PipelineDatabaseSourceOptions): TPipeline {
682
+ return new RuntimePipelineImpl(this._firestore, {
683
+ source: 'database',
684
+ rawOptions: isRecord(options?.rawOptions) ? options.rawOptions : undefined,
685
+ }) as unknown as TPipeline;
686
+ }
687
+
688
+ documents(docs: Array<string | DocumentReference>): TPipeline;
689
+ documents(options: PipelineDocumentsSourceOptions): TPipeline;
690
+ documents(
691
+ docsOrOptions: Array<string | DocumentReference> | PipelineDocumentsSourceOptions,
692
+ ): TPipeline {
693
+ const docs = isArray(docsOrOptions)
694
+ ? docsOrOptions
695
+ : (docsOrOptions.docs ??
696
+ (docsOrOptions as { documents?: Array<string | DocumentReference> }).documents) ||
697
+ [];
698
+
699
+ if (!isArray(docs) || docs.length === 0) {
700
+ throw new Error(
701
+ 'firebase.firestore().pipeline().documents(*) expected at least one document path or DocumentReference.',
702
+ );
703
+ }
704
+
705
+ const documents = docs.map((doc, index) => {
706
+ if (isString(doc) && doc.length > 0) {
707
+ return doc;
708
+ }
709
+
710
+ if (isRecord(doc) && isString(doc.path) && doc.path.length > 0) {
711
+ const documentRef = getFirestoreReference(doc);
712
+ if (documentRef) {
713
+ assertSameFirestoreInstance(documentRef.firestore, this._firestore, 'documents');
714
+ }
715
+
716
+ return doc.path;
717
+ }
718
+
719
+ throw new Error(
720
+ `firebase.firestore().pipeline().documents(*) invalid value at index ${index}. Expected a document path or DocumentReference.`,
721
+ );
722
+ });
723
+
724
+ return new RuntimePipelineImpl(this._firestore, {
725
+ source: 'documents',
726
+ documents,
727
+ }) as unknown as TPipeline;
728
+ }
729
+
730
+ createFrom(query: Query): TPipeline {
731
+ const internals = asQueryInternals(query);
732
+
733
+ if (!internals || !internals._collectionPath || !internals._modifiers) {
734
+ throw new Error(
735
+ 'firebase.firestore().pipeline().createFrom(*) expected a Query from @react-native-firebase/firestore.',
736
+ );
737
+ }
738
+
739
+ if (internals._firestore !== this._firestore) {
740
+ throw new Error(
741
+ 'firebase.firestore().pipeline().createFrom(*) cannot use a Query from a different Firestore instance.',
742
+ );
743
+ }
744
+
745
+ return new RuntimePipelineImpl(this._firestore, {
746
+ source: 'query',
747
+ path: internals._collectionPath.relativeName,
748
+ queryType: internals._modifiers.type,
749
+ filters: internals._modifiers.filters,
750
+ orders: internals._modifiers.orders,
751
+ options: internals._modifiers.options,
752
+ }) as unknown as TPipeline;
753
+ }
754
+ }
755
+
756
+ export function createPipelineSource(firestore: FirestoreInternal): PipelineSource<Pipeline> {
757
+ return new RuntimePipelineSourceImpl(firestore);
758
+ }
759
+
760
+ export function installPipelineRuntime(firestoreInstance?: FirestoreInternal): void {
761
+ let firestore = firestoreInstance;
762
+ if (!firestore) {
763
+ try {
764
+ firestore = getFirestore() as FirestoreInternal;
765
+ } catch {
766
+ return;
767
+ }
768
+ }
769
+
770
+ const prototype = Object.getPrototypeOf(firestore) as FirestorePipelinePrototypeInternal | null;
771
+ if (!prototype || prototype.__rnfbFirestorePipelineInstalled__) {
772
+ return;
773
+ }
774
+
775
+ Object.defineProperty(prototype, 'pipeline', {
776
+ value(this: FirestoreInternal) {
777
+ return createPipelineSource(this);
778
+ },
779
+ configurable: true,
780
+ enumerable: false,
781
+ writable: true,
782
+ });
783
+
784
+ Object.defineProperty(prototype, '__rnfbFirestorePipelineInstalled__', {
785
+ value: true,
786
+ configurable: true,
787
+ enumerable: false,
788
+ writable: true,
789
+ });
790
+ }
791
+
792
+ export function registerPipelineRuntimeInstaller(): void {
793
+ const runtimeGlobal = globalThis as GlobalWithPipelineInstaller;
794
+ runtimeGlobal[PIPELINE_RUNTIME_INSTALLER_SYMBOL] = installPipelineRuntime;
795
+ }
796
+
797
+ function parseExecuteInput(pipelineOrOptions: Pipeline | PipelineExecuteOptions): {
798
+ runtimePipeline: RuntimePipeline;
799
+ executeOptions: FirestorePipelineExecuteOptionsInternal;
800
+ } {
801
+ if (isRuntimePipeline(pipelineOrOptions)) {
802
+ return { runtimePipeline: pipelineOrOptions, executeOptions: {} };
803
+ }
804
+
805
+ if (!isRecord(pipelineOrOptions)) {
806
+ throw new Error(
807
+ 'firebase.firestore().pipeline().execute(*) expected a Pipeline or PipelineExecuteOptions.',
808
+ );
809
+ }
810
+
811
+ const runtimePipeline = pipelineOrOptions.pipeline;
812
+ if (!isRuntimePipeline(runtimePipeline)) {
813
+ throw new Error(
814
+ 'firebase.firestore().pipeline().execute(*) expected options.pipeline to be created from firestore.pipeline().',
815
+ );
816
+ }
817
+
818
+ return {
819
+ runtimePipeline,
820
+ executeOptions:
821
+ validateExecuteOptions({
822
+ indexMode: pipelineOrOptions.indexMode,
823
+ rawOptions: pipelineOrOptions.rawOptions,
824
+ }) ?? {},
825
+ };
826
+ }
827
+
828
+ export async function executeRuntimePipeline(
829
+ pipelineOrOptions: Pipeline | PipelineExecuteOptions,
830
+ ): Promise<PipelineSnapshot> {
831
+ const { runtimePipeline, executeOptions } = parseExecuteInput(pipelineOrOptions);
832
+ const serializedPipeline = runtimePipeline.serialize();
833
+ validateSerializedPipeline(serializedPipeline);
834
+
835
+ if (isIOS) {
836
+ const unsupportedFunctions = getIOSUnsupportedPipelineFunctions(serializedPipeline);
837
+ if (unsupportedFunctions.length) {
838
+ throw new Error(
839
+ `pipelineExecute() does not support these functions on iOS yet: ${unsupportedFunctions.join(', ')}.`,
840
+ );
841
+ }
842
+ }
843
+
844
+ const nativeResponse = (await runtimePipeline.firestore.native.pipelineExecute(
845
+ serializedPipeline,
846
+ executeOptions,
847
+ )) as FirestorePipelineSnapshotInternal;
848
+
849
+ const executionTime = parseTimestamp(nativeResponse?.executionTime);
850
+ if (!executionTime) {
851
+ throw new Error(
852
+ 'firebase.firestore().pipeline().execute(*) expected pipelineExecute() to return executionTime.',
853
+ );
854
+ }
855
+ const results = (nativeResponse?.results ?? []).map(
856
+ result => new RuntimePipelineResult(runtimePipeline.firestore, result),
857
+ );
858
+
859
+ return {
860
+ results,
861
+ executionTime,
862
+ };
863
+ }