From 7f8a486b40cf53b5a35ddb18c2f873cdf42caf15 Mon Sep 17 00:00:00 2001 From: Chris Bianca Date: Thu, 8 Mar 2018 11:13:21 +0000 Subject: [PATCH 1/2] [types] Fix transaction flow type errors --- lib/modules/firestore/Transaction.js | 4 +- lib/modules/firestore/TransactionHandler.js | 40 ++++++++++++------- tests/ios/Podfile.lock | 14 +++---- .../project.pbxproj | 2 +- 4 files changed, 36 insertions(+), 24 deletions(-) diff --git a/lib/modules/firestore/Transaction.js b/lib/modules/firestore/Transaction.js index 07db5162..71cd1b5e 100644 --- a/lib/modules/firestore/Transaction.js +++ b/lib/modules/firestore/Transaction.js @@ -16,8 +16,8 @@ import { getNativeModule } from '../../utils/native'; type Command = { type: 'set' | 'update' | 'delete', path: string, - data: ?{ [string]: any }, - options: ?{ merge: boolean }, + data?: { [string]: any }, + options?: SetOptions | {}, }; type SetOptions = { diff --git a/lib/modules/firestore/TransactionHandler.js b/lib/modules/firestore/TransactionHandler.js index d8f0e190..3b4f5761 100644 --- a/lib/modules/firestore/TransactionHandler.js +++ b/lib/modules/firestore/TransactionHandler.js @@ -19,9 +19,9 @@ const generateTransactionId = (): number => transactionId++; export type TransactionMeta = { id: number, - stack: Array, - reject: null | Function, - resolve: null | Function, + stack: string[], + reject?: Function, + resolve?: Function, transaction: Transaction, updateFunction: (transaction: Transaction) => Promise, }; @@ -37,7 +37,12 @@ type TransactionEvent = { */ export default class TransactionHandler { _firestore: Firestore; - _pending: { [number]: TransactionMeta }; + _pending: { + [number]: { + meta: TransactionMeta, + transaction: Transaction, + }, + }; constructor(firestore: Firestore) { this._pending = {}; @@ -62,10 +67,9 @@ export default class TransactionHandler { updateFunction: (transaction: Transaction) => Promise ): Promise { const id = generateTransactionId(); - const meta = { + // $FlowExpectedError: Transaction has to be populated + const meta: TransactionMeta = { id, - reject: null, - resolve: null, updateFunction, stack: new Error().stack .split('\n') @@ -73,8 +77,10 @@ export default class TransactionHandler { .join('\n'), }; - meta.transaction = new Transaction(this._firestore, meta); - this._pending[id] = meta; + this._pending[id] = { + meta, + transaction: new Transaction(this._firestore, meta), + }; // deferred promise return new Promise((resolve, reject) => { @@ -145,7 +151,8 @@ export default class TransactionHandler { // abort if no longer exists js side if (!this._pending[id]) return this._remove(id); - const { updateFunction, transaction, reject } = this._pending[id]; + const { meta, transaction } = this._pending[id]; + const { updateFunction, reject } = meta; // clear any saved state from previous transaction runs transaction._prepare(); @@ -178,6 +185,7 @@ export default class TransactionHandler { // update is failed when either the users updateFunction // throws an error or rejects a promise if (updateFailed) { + // $FlowExpectedError: Reject will always be present return reject(finalError); } @@ -201,17 +209,20 @@ export default class TransactionHandler { */ _handleError(event: TransactionEvent) { const { id, error } = event; - const meta = this._pending[id]; + const { meta } = this._pending[id]; - if (meta) { + if (meta && error) { const { code, message } = error; // build a JS error and replace its stack // with the captured one at start of transaction // so it's actually relevant to the user const errorWithStack = new Error(message); + // $FlowExpectedError: code is needed for Firebase errors errorWithStack.code = code; + // $FlowExpectedError: stack should be a stack trace errorWithStack.stack = meta.stack; + // $FlowExpectedError: Reject will always be present meta.reject(errorWithStack); } } @@ -224,10 +235,11 @@ export default class TransactionHandler { */ _handleComplete(event: TransactionEvent) { const { id } = event; - const meta = this._pending[id]; + const { meta, transaction } = this._pending[id]; if (meta) { - const pendingResult = meta.transaction._pendingResult; + const pendingResult = transaction._pendingResult; + // $FlowExpectedError: Resolve will always be present meta.resolve(pendingResult); } } diff --git a/tests/ios/Podfile.lock b/tests/ios/Podfile.lock index fcb5d645..266af2b2 100644 --- a/tests/ios/Podfile.lock +++ b/tests/ios/Podfile.lock @@ -164,7 +164,7 @@ PODS: - React/Core - React/fishhook - React/RCTBlob - - RNFirebase (3.2.7): + - RNFirebase (3.3.0): - React - yoga (0.52.3.React) @@ -192,11 +192,11 @@ DEPENDENCIES: EXTERNAL SOURCES: React: - :path: ../node_modules/react-native + :path: "../node_modules/react-native" RNFirebase: - :path: ../../ios/RNFirebase.podspec + :path: "../../ios/RNFirebase.podspec" yoga: - :path: ../node_modules/react-native/ReactCommon/yoga + :path: "../node_modules/react-native/ReactCommon/yoga" SPEC CHECKSUMS: BoringSSL: f3d6b8ce199b9c450a8cfc14895d07a2627fc232 @@ -224,13 +224,13 @@ SPEC CHECKSUMS: gRPC-ProtoRPC: f29e8b7445e0d3c0311678ab121e6c164da4ca5e gRPC-RxLibrary: 8e0067bfe8a054022c7a81470baace4f2f633b48 GTMSessionFetcher: 5bb1eae636127de695590f50e7d248483eb891e6 - leveldb-library: 08cba283675b7ed2d99629a4bc5fd052cd2bb6a5 + leveldb-library: '08cba283675b7ed2d99629a4bc5fd052cd2bb6a5' nanopb: 5601e6bca2dbf1ed831b519092ec110f66982ca3 Protobuf: 8a9838fba8dae3389230e1b7f8c104aa32389c03 React: c0dfd2dfc970019d1ae7d48bf24cef530992e079 - RNFirebase: 3a141a97041ea0757e2036c2bb18acbe9f0e105d + RNFirebase: 056b672391f3e7b572d8ef221c84603970e0c114 yoga: f45a46b966e1eb0c7a532cfd4beec5b97332ba48 PODFILE CHECKSUM: 67c98bcb203cb992da590bcab6f690f727653ca5 -COCOAPODS: 1.3.1 +COCOAPODS: 1.2.1 diff --git a/tests/ios/ReactNativeFirebaseDemo.xcodeproj/project.pbxproj b/tests/ios/ReactNativeFirebaseDemo.xcodeproj/project.pbxproj index b09fdd99..4265ac18 100644 --- a/tests/ios/ReactNativeFirebaseDemo.xcodeproj/project.pbxproj +++ b/tests/ios/ReactNativeFirebaseDemo.xcodeproj/project.pbxproj @@ -1006,7 +1006,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; showEnvVarsInLog = 0; }; 6AE1012F46FF8A4D1D818A12 /* [CP] Copy Pods Resources */ = { From 73d5fe34c4d7a375dfe3087e435ced8bb40468be Mon Sep 17 00:00:00 2001 From: Chris Bianca Date: Thu, 8 Mar 2018 11:36:26 +0000 Subject: [PATCH 2/2] 3.3.1 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 10c7bba0..e05ea92d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "react-native-firebase", - "version": "3.3.0", + "version": "3.3.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index ae7009a1..7cb966b1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-firebase", - "version": "3.3.0", + "version": "3.3.1", "author": "Invertase (http://invertase.io)", "description": "A well tested, feature rich Firebase implementation for React Native, supporting iOS & Android. Individual module support for Admob, Analytics, Auth, Crash Reporting, Cloud Firestore, Database, Dynamic Links, Messaging (FCM), Remote Config, Storage and Performance.", "main": "dist/index.js",