-
Notifications
You must be signed in to change notification settings - Fork 2.3k
feat(functions): turbo modules implementation #8603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
russellwheatley
wants to merge
81
commits into
main
Choose a base branch
from
functions-turbo
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 69 commits
Commits
Show all changes
81 commits
Select commit
Hold shift + click to select a range
3dfaa1c
feat(storage): move to turbomodules
russellwheatley 9d896d2
chore: convert to TS
russellwheatley b80b1a7
format
russellwheatley 1431fbf
chore: ignore some things for now
russellwheatley cff1c5f
chore: update package.json main & types
russellwheatley abd0073
init with bob builder
russellwheatley 9f30fa8
yarn.lock
russellwheatley 18c0fdf
chore: rm rootDir from tsconfig.json
russellwheatley 800bf1a
test: import as type for tests
russellwheatley 1962777
chore: fix types
russellwheatley 4dd309f
update types
russellwheatley 193aa9b
rm type test
russellwheatley a49cf27
chore: fix path of type definitions
russellwheatley 6b52129
chore: moving functions to TS
russellwheatley 1214b3e
fix: imports
russellwheatley 34138fa
fix some types
russellwheatley 6802209
update types
russellwheatley a1cd58a
port over remaining types and delete js files
russellwheatley bd27a05
remove functions declaration
russellwheatley 3b645b1
chore: create spec for turbomodules
russellwheatley 909b963
rename spec
russellwheatley 98f387c
rm old version of cli
russellwheatley 7bad518
fix: need react-native as dependency for codegen to work
russellwheatley 3ba3a76
update scripts for generating code
russellwheatley d3ca750
generated code for android & ios
russellwheatley 7eda482
update podspec & config file as per RN docs
russellwheatley e714ad8
rm generated code
russellwheatley 9f17910
rename to Native prefix otherwise ignored by codegen
russellwheatley d8ffb33
updated generic types for spec
russellwheatley 4bd4607
latest generated code based on updated spec
russellwheatley 90bbbed
update naming of generated code
russellwheatley 938d1c3
update RNFB functions module
russellwheatley d4b2541
make file `.mm` & update podspec for functions
russellwheatley fba772e
podfile.lock
russellwheatley 88eeda8
Merge branch 'main' into functions-turbo
russellwheatley 3218d4d
yarn.lock
russellwheatley 30f5d35
chore: update version
russellwheatley cdfee94
chore: reverse order of prepare script
russellwheatley a04eb09
feat(android): make NativeFunctionsModule compatible with existing code
russellwheatley 1ca5cbb
update path
russellwheatley 1ca1da2
move modular/namespaced to same directory to fix TS
russellwheatley f4014d0
exclude jni from compilation
russellwheatley 459f936
fix: retreive if turbomodule
russellwheatley 471b285
fix: rename native module name
russellwheatley 1bb2088
setup example app
russellwheatley 72ce7a7
update functions spec
russellwheatley 468cdce
regenerated code with args
russellwheatley 6884aee
update android code handling
russellwheatley 65a9dd4
fix: iOS turbomodules implementation
russellwheatley 9b64eac
chore: regenerate code
russellwheatley b966ffe
attempt at fixing iOS issue
russellwheatley e75a23f
Merge branch 'main' into functions-turbo
russellwheatley c01d1ed
yarn.lock
russellwheatley e657017
podlock
russellwheatley 0b9a679
fix: ios
russellwheatley 771e7cb
fix: ios correct types
russellwheatley 831f2fb
chore: config for turbomodules
russellwheatley 2500468
fix: ios implementation
russellwheatley 3012669
chore: move types
russellwheatley 5751dee
chore: move types back
russellwheatley 184450e
chore: fix lint
russellwheatley c6a1182
fix: use get for TurboModules
russellwheatley 3a2d634
fix: move back types
russellwheatley 434393e
chore: remove unused js file
russellwheatley a661db6
chore: finally fix types
russellwheatley 4b8c892
update to typescript
russellwheatley b8b969d
try updating tsconfig.json
russellwheatley 3380bc9
fix(ios): pass nsnull if no data
russellwheatley 9437462
chore: make var for allArgs, easier to debug
russellwheatley 50bda8a
chore: remove unneeded package
russellwheatley 44c9206
chore: make note about podspec updates
russellwheatley bcc522f
chore: update android code
russellwheatley fe6816b
chore: reinsert code comments
russellwheatley b8c7db7
chore: remove todo
russellwheatley 67cce20
chore: typing improvement
russellwheatley c8b2683
chore: types
russellwheatley cf18e11
chore: improve details typing
russellwheatley 699c96b
chore: we now expose everything via index (now modular)
russellwheatley 3bf85d8
chore: improve web typing
russellwheatley c83c945
yarn.lock
russellwheatley ba19d1b
fix: allow details to be null
russellwheatley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
...unctions/android/src/main/java/io/invertase/firebase/functions/NativeFunctionsModule.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
package io.invertase.firebase.functions; | ||
|
||
/* | ||
* Copyright (c) 2016-present Invertase Limited & Contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this library except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
import static io.invertase.firebase.functions.UniversalFirebaseFunctionsModule.CODE_KEY; | ||
import static io.invertase.firebase.functions.UniversalFirebaseFunctionsModule.DATA_KEY; | ||
import static io.invertase.firebase.functions.UniversalFirebaseFunctionsModule.DETAILS_KEY; | ||
import static io.invertase.firebase.functions.UniversalFirebaseFunctionsModule.MSG_KEY; | ||
|
||
import com.facebook.fbreact.specs.NativeFunctionsModuleSpec; | ||
import com.facebook.react.bridge.Arguments; | ||
import com.facebook.react.bridge.Promise; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.bridge.ReadableMap; | ||
import com.facebook.react.bridge.WritableMap; | ||
import com.google.android.gms.tasks.Task; | ||
import com.google.firebase.functions.FirebaseFunctionsException; | ||
import io.invertase.firebase.common.RCTConvertFirebase; | ||
import io.invertase.firebase.common.UniversalFirebaseModule; | ||
import java.io.IOException; | ||
|
||
public class NativeFunctionsModule extends NativeFunctionsModuleSpec { | ||
private static final String SERVICE_NAME = "Functions"; | ||
private final UniversalFirebaseFunctionsModule module; | ||
private final UniversalFirebaseModule universalFirebaseModule; | ||
|
||
public NativeFunctionsModule(ReactApplicationContext reactContext) { | ||
super(reactContext); | ||
// cannot have multiple inheritance so we make this a property rather than extending it | ||
universalFirebaseModule = new UniversalFirebaseModule(reactContext, SERVICE_NAME); | ||
this.module = new UniversalFirebaseFunctionsModule(reactContext, SERVICE_NAME); | ||
} | ||
|
||
@Override | ||
public void httpsCallable( | ||
String appName, | ||
String region, | ||
String emulatorHost, | ||
double emulatorPort, | ||
String name, | ||
ReadableMap data, | ||
ReadableMap options, | ||
Promise promise) { | ||
|
||
Object callableData = data.toHashMap().get(DATA_KEY); | ||
|
||
// Convert emulatorPort to Integer (null if not using emulator) | ||
Integer port = emulatorHost != null ? (int) emulatorPort : null; | ||
|
||
Task<Object> callMethodTask = module.httpsCallable( | ||
appName, region, emulatorHost, port, name, callableData, options); | ||
|
||
// resolve | ||
callMethodTask.addOnSuccessListener( | ||
universalFirebaseModule.getExecutor(), | ||
result -> { | ||
promise.resolve(RCTConvertFirebase.mapPutValue(DATA_KEY, result, Arguments.createMap())); | ||
}); | ||
|
||
// reject | ||
callMethodTask.addOnFailureListener( | ||
universalFirebaseModule.getExecutor(), | ||
exception -> handleFunctionsException(exception, promise)); | ||
} | ||
|
||
@Override | ||
public void httpsCallableFromUrl( | ||
String appName, | ||
String region, | ||
String emulatorHost, | ||
double emulatorPort, | ||
String url, | ||
ReadableMap data, | ||
ReadableMap options, | ||
Promise promise) { | ||
|
||
Object callableData = data.toHashMap().get(DATA_KEY); | ||
|
||
// Convert emulatorPort to Integer (null if not using emulator) | ||
Integer port = emulatorHost != null ? (int) emulatorPort : null; | ||
|
||
Task<Object> callMethodTask = module.httpsCallableFromUrl( | ||
appName, region, emulatorHost, port, url, callableData, options); | ||
|
||
callMethodTask.addOnSuccessListener( | ||
universalFirebaseModule.getExecutor(), | ||
result -> { | ||
promise.resolve(RCTConvertFirebase.mapPutValue(DATA_KEY, result, Arguments.createMap())); | ||
}); | ||
|
||
callMethodTask.addOnFailureListener( | ||
universalFirebaseModule.getExecutor(), | ||
exception -> handleFunctionsException(exception, promise)); | ||
} | ||
|
||
private void handleFunctionsException(Exception exception, Promise promise) { | ||
Object details = null; | ||
String code = "UNKNOWN"; | ||
String message = exception.getMessage(); | ||
WritableMap userInfo = Arguments.createMap(); | ||
|
||
if (exception.getCause() instanceof FirebaseFunctionsException) { | ||
FirebaseFunctionsException functionsException = | ||
(FirebaseFunctionsException) exception.getCause(); | ||
details = functionsException.getDetails(); | ||
code = functionsException.getCode().name(); | ||
message = functionsException.getMessage(); | ||
String timeout = FirebaseFunctionsException.Code.DEADLINE_EXCEEDED.name(); | ||
Boolean isTimeout = code.contains(timeout); | ||
|
||
if (functionsException.getCause() instanceof IOException && !isTimeout) { | ||
// return UNAVAILABLE for network io errors, to match iOS | ||
code = FirebaseFunctionsException.Code.UNAVAILABLE.name(); | ||
message = FirebaseFunctionsException.Code.UNAVAILABLE.name(); | ||
} | ||
} | ||
|
||
RCTConvertFirebase.mapPutValue(CODE_KEY, code, userInfo); | ||
RCTConvertFirebase.mapPutValue(MSG_KEY, message, userInfo); | ||
RCTConvertFirebase.mapPutValue(DETAILS_KEY, details, userInfo); | ||
promise.reject(code, message, exception, userInfo); | ||
} | ||
russellwheatley marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
44 changes: 44 additions & 0 deletions
44
...nctions/android/src/main/java/io/invertase/firebase/functions/NativeFunctionsPackage.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package io.invertase.firebase.functions; | ||
|
||
/* | ||
* Copyright (c) 2016-present Invertase Limited & Contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this library except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
import com.facebook.react.ReactPackage; | ||
import com.facebook.react.bridge.NativeModule; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.uimanager.ViewManager; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import javax.annotation.Nonnull; | ||
|
||
@SuppressWarnings("unused") | ||
public class NativeFunctionsPackage implements ReactPackage { | ||
@Nonnull | ||
@Override | ||
public List<NativeModule> createNativeModules(@Nonnull ReactApplicationContext reactContext) { | ||
List<NativeModule> modules = new ArrayList<>(); | ||
modules.add(new NativeFunctionsModule(reactContext)); | ||
return modules; | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public List<ViewManager> createViewManagers(@Nonnull ReactApplicationContext reactContext) { | ||
return Collections.emptyList(); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...rebase/functions/generated/java/com/facebook/fbreact/specs/NativeFunctionsModuleSpec.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
/** | ||
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). | ||
* | ||
* Do not edit this file as changes may cause incorrect behavior and will be lost | ||
* once the code is regenerated. | ||
* | ||
* @generated by codegen project: GenerateModuleJavaSpec.js | ||
* | ||
* @nolint | ||
*/ | ||
|
||
package com.facebook.fbreact.specs; | ||
|
||
import com.facebook.proguard.annotations.DoNotStrip; | ||
import com.facebook.react.bridge.Promise; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.bridge.ReactContextBaseJavaModule; | ||
import com.facebook.react.bridge.ReactMethod; | ||
import com.facebook.react.bridge.ReadableMap; | ||
import com.facebook.react.turbomodule.core.interfaces.TurboModule; | ||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
|
||
public abstract class NativeFunctionsModuleSpec extends ReactContextBaseJavaModule implements TurboModule { | ||
public static final String NAME = "NativeFunctionsModule"; | ||
|
||
public NativeFunctionsModuleSpec(ReactApplicationContext reactContext) { | ||
super(reactContext); | ||
} | ||
|
||
@Override | ||
public @Nonnull String getName() { | ||
return NAME; | ||
} | ||
|
||
@ReactMethod | ||
@DoNotStrip | ||
public abstract void httpsCallable(String appName, String region, @Nullable String emulatorHost, double emulatorPort, String name, ReadableMap data, ReadableMap options, Promise promise); | ||
|
||
@ReactMethod | ||
@DoNotStrip | ||
public abstract void httpsCallableFromUrl(String appName, String region, @Nullable String emulatorHost, double emulatorPort, String url, ReadableMap data, ReadableMap options, Promise promise); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.