@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.
Files changed (359) hide show
  1. package/CHANGELOG.md +27 -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,161 @@
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 { isDate, isNumber, isObject } from '@react-native-firebase/app/dist/module/common';
19
+
20
+ // Earliest date supported by Firestore timestamps (0001-01-01T00:00:00Z).
21
+ const MIN_SECONDS = -62135596800;
22
+
23
+ export default class Timestamp {
24
+ static now(): Timestamp {
25
+ return Timestamp.fromMillis(Date.now());
26
+ }
27
+
28
+ static fromDate(date: Date): Timestamp {
29
+ if (!isDate(date)) {
30
+ throw new Error(
31
+ "firebase.firestore.Timestamp.fromDate(*) 'date' expected a valid Date object.",
32
+ );
33
+ }
34
+
35
+ return Timestamp.fromMillis(date.getTime());
36
+ }
37
+
38
+ static fromMillis(milliseconds: number): Timestamp {
39
+ const seconds = Math.floor(milliseconds / 1000);
40
+ const nanoseconds = (milliseconds - seconds * 1000) * 1e6;
41
+ return new Timestamp(seconds, nanoseconds);
42
+ }
43
+
44
+ _seconds: number;
45
+ _nanoseconds: number;
46
+
47
+ constructor(seconds: number, nanoseconds: number) {
48
+ if (!isNumber(seconds)) {
49
+ throw new Error("firebase.firestore.Timestamp 'seconds' expected a number value.");
50
+ }
51
+
52
+ if (!isNumber(nanoseconds)) {
53
+ throw new Error("firebase.firestore.Timestamp 'nanoseconds' expected a number value.");
54
+ }
55
+
56
+ if (nanoseconds < 0) {
57
+ throw new Error(`firebase.firestore.Timestamp 'nanoseconds' out of range: ${nanoseconds}`);
58
+ }
59
+
60
+ if (nanoseconds >= 1e9) {
61
+ throw new Error(`firebase.firestore.Timestamp 'nanoseconds' out of range: ${nanoseconds}`);
62
+ }
63
+
64
+ if (seconds < MIN_SECONDS) {
65
+ throw new Error(`firebase.firestore.Timestamp 'seconds' out of range: ${seconds}`);
66
+ }
67
+
68
+ if (seconds >= 253402300800) {
69
+ throw new Error(`firebase.firestore.Timestamp 'seconds' out of range: ${seconds}`);
70
+ }
71
+
72
+ this._seconds = seconds;
73
+ this._nanoseconds = nanoseconds;
74
+ }
75
+
76
+ get seconds(): number {
77
+ return this._seconds;
78
+ }
79
+
80
+ get nanoseconds(): number {
81
+ return this._nanoseconds;
82
+ }
83
+
84
+ isEqual(other: Timestamp): boolean {
85
+ if (!(other instanceof Timestamp)) {
86
+ throw Error(
87
+ "firebase.firestore.Timestamp.isEqual(*) 'other' expected an instance of Timestamp.",
88
+ );
89
+ }
90
+
91
+ return other.seconds === this._seconds && other.nanoseconds === this._nanoseconds;
92
+ }
93
+
94
+ toDate(): Date {
95
+ return new Date(this.toMillis());
96
+ }
97
+
98
+ toMillis(): number {
99
+ return this._seconds * 1000 + this._nanoseconds / 1e6;
100
+ }
101
+
102
+ _compareTo(other: Timestamp): number {
103
+ if (this._seconds === other._seconds) {
104
+ if (this._nanoseconds < other._nanoseconds) return -1;
105
+ if (this._nanoseconds > other._nanoseconds) return 1;
106
+ return 0;
107
+ }
108
+ return this._seconds < other._seconds ? -1 : 1;
109
+ }
110
+
111
+ toString(): string {
112
+ return `Timestamp(seconds=${this.seconds}, nanoseconds=${this.nanoseconds})`;
113
+ }
114
+
115
+ static _jsonSchemaVersion: string = 'firestore/timestamp/1.0';
116
+ static _jsonSchema = {
117
+ type: Timestamp._jsonSchemaVersion,
118
+ seconds: 'number',
119
+ nanoseconds: 'number',
120
+ };
121
+
122
+ toJSON(): { seconds: number; nanoseconds: number; type: string } {
123
+ return {
124
+ type: Timestamp._jsonSchemaVersion,
125
+ seconds: this.seconds,
126
+ nanoseconds: this.nanoseconds,
127
+ };
128
+ }
129
+
130
+ static fromJSON(json: object): Timestamp {
131
+ if (
132
+ isObject(json) &&
133
+ (json as { type?: unknown }).type === Timestamp._jsonSchemaVersion &&
134
+ typeof (json as { seconds?: unknown }).seconds === 'number' &&
135
+ typeof (json as { nanoseconds?: unknown }).nanoseconds === 'number'
136
+ ) {
137
+ return new Timestamp(
138
+ (json as { seconds: number }).seconds,
139
+ (json as { nanoseconds: number }).nanoseconds,
140
+ );
141
+ }
142
+
143
+ throw new Error('Unexpected error creating Timestamp from JSON.');
144
+ }
145
+ /**
146
+ * Converts this object to a primitive string, which allows Timestamp objects to be compared
147
+ * using the `>`, `<=`, `>=` and `>` operators.
148
+ */
149
+ valueOf(): string {
150
+ // This method returns a string of the form <seconds>.<nanoseconds> where <seconds> is
151
+ // translated to have a non-negative value and both <seconds> and <nanoseconds> are left-padded
152
+ // with zeroes to be a consistent length. Strings with this format then have a lexiographical
153
+ // ordering that matches the expected ordering. The <seconds> translation is done to avoid
154
+ // having a leading negative sign (i.e. a leading '-' character) in its string representation,
155
+ // which would affect its lexiographical ordering.
156
+ const adjustedSeconds = this.seconds - MIN_SECONDS;
157
+ const formattedSeconds = String(adjustedSeconds).padStart(12, '0');
158
+ const formattedNanoseconds = String(this.nanoseconds).padStart(9, '0');
159
+ return `${formattedSeconds}.${formattedNanoseconds}`;
160
+ }
161
+ }
@@ -16,24 +16,50 @@
16
16
  */
17
17
 
18
18
  import { isObject, createDeprecationProxy } from '@react-native-firebase/app/dist/module/common';
19
- import FirestoreDocumentReference from './FirestoreDocumentReference';
20
- import FirestoreDocumentSnapshot from './FirestoreDocumentSnapshot';
21
- import { parseSetOptions, parseUpdateArgs } from './utils';
19
+ import DocumentReference from './FirestoreDocumentReference';
20
+ import DocumentSnapshot from './FirestoreDocumentSnapshot';
21
+ import type { DocumentSnapshotNativeData } from './FirestoreDocumentSnapshot';
22
+ import { parseSetOptions, parseUpdateArgs, applyFirestoreDataConverter } from './utils';
22
23
  import { buildNativeMap } from './utils/serialize';
24
+ import type { FirestoreInternal } from './types/internal';
25
+ import type { SetOptions } from './types/firestore';
26
+
27
+ export interface TransactionMeta {
28
+ id: number;
29
+ /** Receives the Transaction instance (this module's default export). */
30
+ updateFunction: (transaction: Transaction) => Promise<unknown>;
31
+ stack?: string;
32
+ resolve?: (result: unknown) => void;
33
+ reject?: (error: unknown) => void;
34
+ }
35
+
36
+ export interface TransactionCommand {
37
+ type: 'SET' | 'UPDATE' | 'DELETE';
38
+ path: string;
39
+ data?: Record<string, unknown>;
40
+ options?: Record<string, unknown>;
41
+ }
23
42
 
24
- export default class FirestoreTransaction {
25
- constructor(firestore, meta) {
43
+ export default class Transaction {
44
+ _firestore: FirestoreInternal;
45
+ _meta: TransactionMeta;
46
+ _calledGetCount: number;
47
+ _commandBuffer: TransactionCommand[];
48
+ _pendingResult: unknown;
49
+
50
+ constructor(firestore: FirestoreInternal, meta: TransactionMeta) {
26
51
  this._firestore = firestore;
27
52
  this._meta = meta;
53
+ this._calledGetCount = 0;
54
+ this._commandBuffer = [];
55
+ this._pendingResult = undefined;
28
56
  }
29
57
 
30
58
  /**
31
59
  * Clears the command buffer and any pending result in prep for
32
60
  * the next transaction iteration attempt.
33
- *
34
- * @private
35
61
  */
36
- _prepare() {
62
+ _prepare(): void {
37
63
  this._calledGetCount = 0;
38
64
  this._commandBuffer = [];
39
65
  this._pendingResult = undefined;
@@ -42,8 +68,8 @@ export default class FirestoreTransaction {
42
68
  /**
43
69
  * Reads the document referenced by the provided DocumentReference.
44
70
  */
45
- get(documentRef) {
46
- if (!(documentRef instanceof FirestoreDocumentReference)) {
71
+ get(documentRef: DocumentReference): Promise<DocumentSnapshot> {
72
+ if (!(documentRef instanceof DocumentReference)) {
47
73
  throw new Error(
48
74
  "firebase.firestore().runTransaction() Transaction.get(*) 'documentRef' expected a DocumentReference.",
49
75
  );
@@ -52,59 +78,70 @@ export default class FirestoreTransaction {
52
78
  this._calledGetCount++;
53
79
  return this._firestore.native
54
80
  .transactionGetDocument(this._meta.id, documentRef.path)
55
- .then(data => createDeprecationProxy(new FirestoreDocumentSnapshot(this._firestore, data)));
81
+ .then((data: unknown) =>
82
+ createDeprecationProxy(
83
+ new DocumentSnapshot(this._firestore, data as DocumentSnapshotNativeData, null),
84
+ ),
85
+ );
56
86
  }
57
87
 
58
88
  /**
59
89
  * Writes to the document referred to by the provided DocumentReference.
60
- * If the document does not exist yet, it will be created. If you pass options,
61
- * the provided data can be merged into the existing document.
62
90
  */
63
- set(documentRef, data, options) {
64
- if (!(documentRef instanceof FirestoreDocumentReference)) {
91
+ set(documentRef: DocumentReference, data: Record<string, unknown>, options?: SetOptions): this {
92
+ if (!(documentRef instanceof DocumentReference)) {
65
93
  throw new Error(
66
94
  "firebase.firestore().runTransaction() Transaction.set(*) 'documentRef' expected a DocumentReference.",
67
95
  );
68
96
  }
69
97
 
70
- if (!isObject(data)) {
98
+ let setOptions: Record<string, unknown>;
99
+ try {
100
+ setOptions = parseSetOptions(options);
101
+ } catch (e) {
71
102
  throw new Error(
72
- "firebase.firestore().runTransaction() Transaction.set(_, *) 'data' must be an object..",
103
+ `firebase.firestore().runTransaction() Transaction.set(_, _, *) ${(e as Error).message}.`,
73
104
  );
74
105
  }
75
106
 
76
- let setOptions;
107
+ let converted: Record<string, unknown> | unknown = data;
77
108
  try {
78
- setOptions = parseSetOptions(options);
109
+ converted = applyFirestoreDataConverter(data, documentRef.converter, setOptions);
79
110
  } catch (e) {
80
111
  throw new Error(
81
- `firebase.firestore().runTransaction() Transaction.set(_, _, *) ${e.message}.`,
112
+ `firebase.firestore().runTransaction() Transaction.set(_, *) 'withConverter.toFirestore' threw an error: ${(e as Error).message}.`,
113
+ );
114
+ }
115
+
116
+ if (!isObject(converted)) {
117
+ throw new Error(
118
+ "firebase.firestore().runTransaction() Transaction.set(_, *) 'data' must be an object..",
82
119
  );
83
120
  }
84
121
 
85
122
  this._commandBuffer.push({
86
123
  type: 'SET',
87
124
  path: documentRef.path,
88
- data: buildNativeMap(data, this._firestore._settings.ignoreUndefinedProperties),
125
+ data: buildNativeMap(converted, this._firestore._settings.ignoreUndefinedProperties),
89
126
  options: setOptions,
90
127
  });
91
128
 
92
129
  return this;
93
130
  }
94
131
 
95
- update(documentRef, ...args) {
96
- if (!(documentRef instanceof FirestoreDocumentReference)) {
132
+ update(documentRef: DocumentReference, ...args: unknown[]): this {
133
+ if (!(documentRef instanceof DocumentReference)) {
97
134
  throw new Error(
98
135
  "firebase.firestore().runTransaction() Transaction.update(*) 'documentRef' expected a DocumentReference.",
99
136
  );
100
137
  }
101
138
 
102
- let data;
139
+ let data: Record<string, unknown>;
103
140
  try {
104
141
  data = parseUpdateArgs(args);
105
142
  } catch (e) {
106
143
  throw new Error(
107
- `firebase.firestore().runTransaction() Transaction.update(_, *) ${e.message}`,
144
+ `firebase.firestore().runTransaction() Transaction.update(_, *) ${(e as Error).message}`,
108
145
  );
109
146
  }
110
147
 
@@ -117,8 +154,8 @@ export default class FirestoreTransaction {
117
154
  return this;
118
155
  }
119
156
 
120
- delete(documentRef) {
121
- if (!(documentRef instanceof FirestoreDocumentReference)) {
157
+ delete(documentRef: DocumentReference): this {
158
+ if (!(documentRef instanceof DocumentReference)) {
122
159
  throw new Error(
123
160
  "firebase.firestore().runTransaction() Transaction.delete(*) 'documentRef' expected a DocumentReference.",
124
161
  );
@@ -16,19 +16,33 @@
16
16
  */
17
17
 
18
18
  import NativeError from '@react-native-firebase/app/dist/module/internal/NativeFirebaseError';
19
- import FirestoreTransaction from './FirestoreTransaction';
19
+ import Transaction, { type TransactionMeta } from './FirestoreTransaction';
20
+ import type { FirestoreInternal } from './types/internal';
20
21
 
21
22
  let transactionId = 0;
22
23
 
23
- /**
24
- * Uses the push id generator to create a transaction id
25
- * @returns {number}
26
- * @private
27
- */
28
- const generateTransactionId = () => transactionId++;
24
+ const generateTransactionId = (): number => transactionId++;
25
+
26
+ export interface TransactionPendingEntry {
27
+ meta: TransactionMeta;
28
+ transaction: Transaction;
29
+ }
30
+
31
+ export interface TransactionEventBody {
32
+ type?: 'update' | 'error' | 'complete';
33
+ error?: unknown;
34
+ }
35
+
36
+ export interface TransactionEvent {
37
+ body: TransactionEventBody;
38
+ listenerId?: number;
39
+ }
29
40
 
30
41
  export default class FirestoreTransactionHandler {
31
- constructor(firestore) {
42
+ _firestore: FirestoreInternal;
43
+ _pending: Record<number, TransactionPendingEntry>;
44
+
45
+ constructor(firestore: FirestoreInternal) {
32
46
  this._firestore = firestore;
33
47
  this._pending = {};
34
48
  this._firestore.emitter.addListener(
@@ -37,7 +51,7 @@ export default class FirestoreTransactionHandler {
37
51
  );
38
52
  }
39
53
 
40
- _onTransactionEvent(event) {
54
+ _onTransactionEvent(event: TransactionEvent): void {
41
55
  switch (event.body.type) {
42
56
  case 'update':
43
57
  this._handleUpdate(event);
@@ -51,29 +65,29 @@ export default class FirestoreTransactionHandler {
51
65
  }
52
66
  }
53
67
 
54
- async _handleUpdate(event) {
55
- const { listenerId: id } = event;
68
+ async _handleUpdate(event: TransactionEvent): Promise<void> {
69
+ const id = event.listenerId;
56
70
 
57
- // abort if no longer exists js side
58
- if (!this._pending[id]) {
59
- return this._remove(id);
71
+ if (id === undefined || !this._pending[id]) {
72
+ if (id !== undefined) {
73
+ this._remove(id);
74
+ }
75
+ return;
60
76
  }
61
77
 
62
78
  const { meta, transaction } = this._pending[id];
63
79
  const { updateFunction, reject } = meta;
64
80
 
65
- // clear any saved state from previous transaction runs
66
81
  transaction._prepare();
67
82
 
68
- let finalError;
69
- let updateFailed;
70
- let pendingResult;
83
+ let finalError: unknown;
84
+ let updateFailed = false;
85
+ let pendingResult: unknown;
71
86
 
72
87
  try {
73
88
  const possiblePromise = updateFunction(transaction);
74
89
 
75
- // validate user has returned a promise in their update function
76
- if (!possiblePromise || !possiblePromise.then) {
90
+ if (!possiblePromise || typeof (possiblePromise as Promise<unknown>)?.then !== 'function') {
77
91
  throw new Error(
78
92
  "firebase.firestore().runTransaction(*) 'updateFunction' must return a Promise.",
79
93
  );
@@ -81,39 +95,25 @@ export default class FirestoreTransactionHandler {
81
95
 
82
96
  pendingResult = await possiblePromise;
83
97
  } catch (exception) {
84
- // exception can still be falsey if user `Promise.reject();` 's with no args
85
- // so we track the exception with a updateFailed boolean to ensure no fall-through
86
98
  updateFailed = true;
87
99
  finalError = exception;
88
100
  }
89
101
 
90
- // reject the final promise and remove from native
91
- // update is failed when either the users updateFunction
92
- // throws an error or rejects a promise
93
102
  if (updateFailed || finalError) {
94
- return reject(finalError);
103
+ reject?.(finalError);
104
+ return;
95
105
  }
96
106
 
97
- // capture the resolved result as we'll need this
98
- // to resolve the runTransaction() promise when
99
- // native emits that the transaction is final
100
107
  transaction._pendingResult = pendingResult;
101
108
 
102
- // send the buffered update/set/delete commands for native to process
103
109
  return this._firestore.native.transactionApplyBuffer(id, transaction._commandBuffer);
104
110
  }
105
111
 
106
- /**
107
- * Reject the promise with a native error event
108
- *
109
- * @param event
110
- * @private
111
- */
112
- _handleError(event) {
113
- const { listenerId: id, body } = event;
114
- const { error } = body;
115
-
116
- if (!this._pending[id]) {
112
+ _handleError(event: TransactionEvent): void {
113
+ const id = event.listenerId;
114
+ const { error } = event.body;
115
+
116
+ if (id === undefined || !this._pending[id]) {
117
117
  return;
118
118
  }
119
119
 
@@ -121,74 +121,53 @@ export default class FirestoreTransactionHandler {
121
121
 
122
122
  if (meta && error) {
123
123
  const errorAndStack = NativeError.fromEvent(error, 'firestore', meta.stack);
124
- meta.reject(errorAndStack);
124
+ meta.reject?.(errorAndStack);
125
125
  }
126
126
  }
127
127
 
128
- /**
129
- * Once the transaction has completed on native, resolve the promise with any
130
- * pending results
131
- *
132
- * @param event
133
- * @private
134
- */
135
- _handleComplete(event) {
136
- const { listenerId: id } = event;
137
-
138
- if (!this._pending[id]) {
128
+ _handleComplete(event: TransactionEvent): void {
129
+ const id = event.listenerId;
130
+
131
+ if (id === undefined || !this._pending[id]) {
139
132
  return;
140
133
  }
141
134
 
142
135
  const { meta, transaction } = this._pending[id];
143
136
  if (meta) {
144
- meta.resolve(transaction._pendingResult);
137
+ meta.resolve?.(transaction._pendingResult);
145
138
  }
146
139
  }
147
140
 
148
- /**
149
- * Internally adds a transaction execution function to the queue
150
- *
151
- * @param updateFunction
152
- * @returns {Promise<any>}
153
- * @private
154
- */
155
- _add(updateFunction) {
141
+ _add(updateFunction: (transaction: Transaction) => Promise<unknown>): Promise<unknown> {
156
142
  const id = generateTransactionId();
157
143
 
158
- const meta = {
144
+ const meta: TransactionMeta = {
159
145
  id,
160
146
  updateFunction,
161
- stack: new Error().stack.split('\n').slice(2).join('\n'),
147
+ stack: new Error().stack?.split('\n').slice(2).join('\n'),
162
148
  };
163
149
 
164
150
  this._pending[id] = {
165
151
  meta,
166
- transaction: new FirestoreTransaction(this._firestore, meta),
152
+ transaction: new Transaction(this._firestore, meta),
167
153
  };
168
154
 
169
155
  return new Promise((resolve, reject) => {
170
156
  this._firestore.native.transactionBegin(id);
171
157
 
172
- meta.resolve = result => {
158
+ meta.resolve = (result: unknown) => {
173
159
  this._remove(id);
174
160
  resolve(result);
175
161
  };
176
162
 
177
- meta.reject = error => {
163
+ meta.reject = (error: unknown) => {
178
164
  this._remove(id);
179
165
  reject(error);
180
166
  };
181
167
  });
182
168
  }
183
169
 
184
- /**
185
- * Internally removes the transaction once it has resolved
186
- * or rejected
187
- *
188
- * @param id
189
- * @private
190
- */
191
- _remove(id) {
170
+ _remove(id: number): void {
192
171
  this._firestore.native.transactionDispose(id);
193
172
  delete this._pending[id];
194
173
  }
@@ -15,10 +15,14 @@
15
15
  *
16
16
  */
17
17
 
18
- import { isArray, isNumber } from '@react-native-firebase/app/dist/module/common';
18
+ import { isArray, isNumber, isObject } from '@react-native-firebase/app/dist/module/common';
19
19
 
20
- export default class FirestoreVectorValue {
21
- constructor(values) {
20
+ type FirestoreVectorJson = { vectorValues: number[]; type?: string };
21
+
22
+ export default class VectorValue {
23
+ _values: number[];
24
+
25
+ constructor(values?: number[]) {
22
26
  if (values === undefined) {
23
27
  this._values = [];
24
28
  return;
@@ -31,25 +35,43 @@ export default class FirestoreVectorValue {
31
35
  }
32
36
 
33
37
  for (let i = 0; i < values.length; i++) {
34
- const v = values[i];
35
- if (!isNumber(v)) {
38
+ const value = values[i];
39
+ if (!isNumber(value)) {
36
40
  throw new Error(
37
41
  `firebase.firestore.VectorValue(values?) 'values[${i}]' expected a number value.`,
38
42
  );
39
43
  }
40
44
  }
41
45
 
42
- // Store a shallow copy to ensure immutability semantics for the input array
43
46
  this._values = values.slice();
44
47
  }
45
48
 
46
- static fromJSON(json) {
47
- parsedVector = JSON.parse(json);
48
- return new FirestoreVectorValue(parsedVector.vectorValues);
49
+ static _jsonSchemaVersion: string = 'firestore/vectorValue/1.0';
50
+ static _jsonSchema = {
51
+ type: VectorValue._jsonSchemaVersion,
52
+ vectorValues: 'object',
53
+ };
54
+
55
+ static fromJSON(json: object): VectorValue {
56
+ const parsedVector = isObject(json) ? (json as FirestoreVectorJson & { type?: unknown }) : null;
57
+ if (
58
+ parsedVector &&
59
+ (parsedVector.type === undefined || parsedVector.type === VectorValue._jsonSchemaVersion) &&
60
+ Array.isArray(parsedVector.vectorValues) &&
61
+ parsedVector.vectorValues.every(element => typeof element === 'number')
62
+ ) {
63
+ return new VectorValue(parsedVector.vectorValues);
64
+ }
65
+
66
+ if (parsedVector && parsedVector.type === VectorValue._jsonSchemaVersion) {
67
+ throw new Error("Expected 'vectorValues' field to be a number array");
68
+ }
69
+
70
+ throw new Error('Unexpected error creating Timestamp from JSON.');
49
71
  }
50
72
 
51
- isEqual(other) {
52
- if (!(other instanceof FirestoreVectorValue)) {
73
+ isEqual(other: VectorValue): boolean {
74
+ if (!(other instanceof VectorValue)) {
53
75
  throw new Error(
54
76
  "firebase.firestore.VectorValue.isEqual(*) 'other' expected a VectorValue instance.",
55
77
  );
@@ -59,17 +81,16 @@ export default class FirestoreVectorValue {
59
81
  const b = other._values;
60
82
  if (a.length !== b.length) return false;
61
83
  for (let i = 0; i < a.length; i++) {
62
- // Use strict equality; Firestore numbers allow NaN/Infinity – equality semantics match JS
63
84
  if (a[i] !== b[i]) return false;
64
85
  }
65
86
  return true;
66
87
  }
67
88
 
68
- toArray() {
89
+ toArray(): number[] {
69
90
  return this._values.slice();
70
91
  }
71
92
 
72
- toJSON() {
73
- return { vectorValues: this._values.slice() };
93
+ toJSON(): { vectorValues: number[]; type: string } {
94
+ return { type: VectorValue._jsonSchemaVersion, vectorValues: this._values.slice() };
74
95
  }
75
96
  }