diff --git a/packages/ml/e2e/ml.e2e.js b/packages/ml/e2e/ml.e2e.js index 6937ea9d5b..ce9af7f8e3 100644 --- a/packages/ml/e2e/ml.e2e.js +++ b/packages/ml/e2e/ml.e2e.js @@ -16,19 +16,35 @@ */ describe('ml()', function () { - describe('namespace', function () { - it('accessible from firebase.app()', function () { - const app = firebase.app(); - should.exist(app.ml); - app.ml().app.should.equal(app); + describe('v8 compatibility', function () { + describe('namespace', function () { + it('accessible from firebase.app()', function () { + const app = firebase.app(); + should.exist(app.ml); + app.ml().app.should.equal(app); + }); + + it('supports multiple apps', async function () { + firebase.ml().app.name.should.equal('[DEFAULT]'); + + firebase + .ml(firebase.app('secondaryFromNative')) + .app.name.should.equal('secondaryFromNative'); + + firebase.app('secondaryFromNative').ml().app.name.should.equal('secondaryFromNative'); + }); }); + }); - it('supports multiple apps', async function () { - firebase.ml().app.name.should.equal('[DEFAULT]'); + describe('modular', function () { + it('supports multiple apps', function () { + const { getML } = mlModular; + const ml = getML(); + const secondaryML = getML(firebase.app('secondaryFromNative')); - firebase.ml(firebase.app('secondaryFromNative')).app.name.should.equal('secondaryFromNative'); + ml.app.name.should.equal('[DEFAULT]'); - firebase.app('secondaryFromNative').ml().app.name.should.equal('secondaryFromNative'); + secondaryML.app.name.should.equal('secondaryFromNative'); }); }); }); diff --git a/packages/ml/lib/index.js b/packages/ml/lib/index.js index 30e809d4ae..960e01f86b 100644 --- a/packages/ml/lib/index.js +++ b/packages/ml/lib/index.js @@ -33,6 +33,8 @@ class FirebaseMLModule extends FirebaseModule {} // import { SDK_VERSION } from '@react-native-firebase/ml'; export const SDK_VERSION = version; +export * from './modular'; + // import ML from '@react-native-firebase/ml'; // ml().X(...); export default createModuleNamespace({ diff --git a/packages/ml/lib/modular/index.d.ts b/packages/ml/lib/modular/index.d.ts new file mode 100644 index 0000000000..afdcc67a32 --- /dev/null +++ b/packages/ml/lib/modular/index.d.ts @@ -0,0 +1,14 @@ +import { ReactNativeFirebase } from '@react-native-firebase/app'; +import { FirebaseMLTypes } from '..'; + +type FirebaseApp = ReactNativeFirebase.Module; +type FirebaseML = FirebaseMLTypes.Module; + +/** + * Returns the existing default {@link FirebaseML} instance that is associated with the + * default {@link @firebase/app#FirebaseApp}. If no instance exists, initializes a new + * instance with default settings. + * + * @returns The {@link FirebaseML} instance of the provided app. + */ +export declare function getML(app?: FirebaseApp): FirebaseML; diff --git a/packages/ml/lib/modular/index.js b/packages/ml/lib/modular/index.js new file mode 100644 index 0000000000..26bb2a2c8e --- /dev/null +++ b/packages/ml/lib/modular/index.js @@ -0,0 +1,17 @@ +import { firebase } from '..'; + +/** + * @typedef {import('@react-native-firebase/app').ReactNativeFirebase.Module} FirebaseApp + * @typedef {import('..').FirebaseMLTypes.Module} FirebaseML + */ + +/** + * @param {FirebaseApp | undefined} app + * @returns {FirebaseML} + */ +export function getML(app) { + if (app) { + return firebase.ml(app); + } + return firebase.ml(); +} diff --git a/tests/app.js b/tests/app.js index 0dbd658c5e..e9e002f95a 100644 --- a/tests/app.js +++ b/tests/app.js @@ -51,6 +51,7 @@ import * as inAppMessagingModular from '@react-native-firebase/in-app-messaging' import * as installationsModular from '@react-native-firebase/installations'; import * as crashlyticsModular from '@react-native-firebase/crashlytics'; import * as dynamicLinksModular from '@react-native-firebase/dynamic-links'; +import * as mlModular from '@react-native-firebase/ml'; jet.exposeContextProperty('NativeModules', NativeModules); jet.exposeContextProperty('NativeEventEmitter', NativeEventEmitter); @@ -72,6 +73,7 @@ jet.exposeContextProperty('crashlyticsModular', crashlyticsModular); jet.exposeContextProperty('dynamicLinksModular', dynamicLinksModular); jet.exposeContextProperty('databaseModular', databaseModular); jet.exposeContextProperty('firestoreModular', firestoreModular); +jet.exposeContextProperty('mlModular', mlModular); firebase.database().useEmulator('localhost', 9000); firebase.auth().useEmulator('http://localhost:9099'); diff --git a/tests/e2e/globals.js b/tests/e2e/globals.js index 9c4e589c1b..46df6736c4 100644 --- a/tests/e2e/globals.js +++ b/tests/e2e/globals.js @@ -161,4 +161,10 @@ Object.defineProperty(global, 'firestoreModular', { }, }); +Object.defineProperty(global, 'mlModular', { + get() { + return jet.mlModular; + }, +}); + global.isCI = !!process.env.CI;