Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 0 additions & 103 deletions packages/ml/lib/index.d.ts

This file was deleted.

27 changes: 27 additions & 0 deletions packages/ml/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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.
*
*/

// Export types from types/ml (public/modular API; Statics re-exported via modular)
export type { ML, FirebaseApp } from './types/ml';
export type { FirebaseMLTypes } from './types/namespaced';

// Export modular API functions
export * from './modular';

// Export namespaced API
export * from './namespaced';
export { default } from './namespaced';
37 changes: 37 additions & 0 deletions packages/ml/lib/modular.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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 { getApp } from '@react-native-firebase/app';
import type { FirebaseApp } from '@react-native-firebase/app';
import type { ML } from './types/ml';

export type { Statics } from './types/ml';

/**
* Returns the existing default {@link ML} instance that is associated with the
* default {@link @firebase/app#FirebaseApp}. If no instance exists, initializes a new
* instance with default settings.
*
* @param app - Optional {@link FirebaseApp} instance. If not provided, uses the default app.
* @returns The {@link ML} instance of the provided app.
*/
export function getML(app?: FirebaseApp): ML {
if (app) {
return getApp(app.name).ml() as ML;
}
return getApp().ml() as ML;
}
14 changes: 0 additions & 14 deletions packages/ml/lib/modular/index.d.ts

This file was deleted.

17 changes: 0 additions & 17 deletions packages/ml/lib/modular/index.js

This file was deleted.

42 changes: 26 additions & 16 deletions packages/ml/lib/index.js → packages/ml/lib/namespaced.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,24 @@ import {
FirebaseModule,
getFirebaseRoot,
} from '@react-native-firebase/app/dist/module/internal';
import version from './version';
import type { ReactNativeFirebase } from '@react-native-firebase/app';
import { version } from './version';
import type { FirebaseMLTypes } from './types/namespaced';
import './types/internal';

const statics = {};
const statics: FirebaseMLTypes.Statics = {
SDK_VERSION: version,
};

const namespace = 'ml';

const nativeModuleName = 'RNFBMLModule';
const nativeModuleName = 'RNFBMLModule' as const;

class FirebaseMLModule extends FirebaseModule {}
class FirebaseMLModule extends FirebaseModule<typeof nativeModuleName> {}

// 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({
const mlNamespace = createModuleNamespace({
statics,
version,
namespace,
Expand All @@ -48,10 +48,20 @@ export default createModuleNamespace({
ModuleClass: FirebaseMLModule,
});

// import ml, { firebase } from '@react-native-firebase/ml';
// ml().X(...);
// firebase.ml().X(...);
export const firebase = getFirebaseRoot();
type MLNamespace = ReactNativeFirebase.FirebaseModuleWithStaticsAndApp<
FirebaseMLTypes.Module,
FirebaseMLTypes.Statics
> & {
firebase: ReactNativeFirebase.Module;
app(name?: string): ReactNativeFirebase.FirebaseApp;
};

export default mlNamespace as unknown as MLNamespace;

// e.g.
// // import { MLCloudTextRecognizerModelType } from '@react-native-firebase/ml';
export const firebase =
getFirebaseRoot() as unknown as ReactNativeFirebase.FirebaseNamespacedExport<
'ml',
FirebaseMLTypes.Module,
FirebaseMLTypes.Statics,
false
>;
31 changes: 31 additions & 0 deletions packages/ml/lib/types/internal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.
*
*/

/**
* Wrapped native module interface for ML.
* ML Kit module exposes no instance methods beyond the base FirebaseModule.
*/
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
export interface RNFBMLModule {
// No additional methods; ML uses base FirebaseModule only.
}

declare module '@react-native-firebase/app/dist/module/internal/NativeModules' {
interface ReactNativeFirebaseNativeModules {
RNFBMLModule: RNFBMLModule;
}
}
41 changes: 41 additions & 0 deletions packages/ml/lib/types/ml.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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 type { ReactNativeFirebase } from '@react-native-firebase/app';

// ============ Module Interface (public/modular API) ============

/**
* ML module instance - returned from firebase.ml() or getML().
* Note: Firebase ML Kit has no JavaScript SDK; types match RNFB native API.
*/
export interface ML {
/** The FirebaseApp this module is associated with */
app: ReactNativeFirebase.FirebaseApp;
}

// ============ Statics Interface ============

export interface Statics {
SDK_VERSION: string;
}

/**
* FirebaseApp type with ml() method.
* @deprecated Import FirebaseApp from '@react-native-firebase/app' instead.
*/
export type FirebaseApp = ReactNativeFirebase.FirebaseApp;
51 changes: 51 additions & 0 deletions packages/ml/lib/types/namespaced.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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 type { ReactNativeFirebase } from '@react-native-firebase/app';

type FirebaseModule = ReactNativeFirebase.FirebaseModule;

/**
* @deprecated Use the exported types directly instead.
* FirebaseMLTypes namespace is kept for backwards compatibility.
*/
/* eslint-disable @typescript-eslint/no-namespace */
export namespace FirebaseMLTypes {
export interface Statics {
SDK_VERSION: string;
}

export interface Module extends FirebaseModule {
/** @deprecated Use the modular API instead. */
app: ReactNativeFirebase.FirebaseApp;
}
}
/* eslint-enable @typescript-eslint/no-namespace */

/* eslint-disable @typescript-eslint/no-namespace */
declare module '@react-native-firebase/app' {
namespace ReactNativeFirebase {
import FirebaseModuleWithStaticsAndApp = ReactNativeFirebase.FirebaseModuleWithStaticsAndApp;
interface Module {
ml: FirebaseModuleWithStaticsAndApp<FirebaseMLTypes.Module, FirebaseMLTypes.Statics>;
}
interface FirebaseApp {
ml(): FirebaseMLTypes.Module;
}
}
}
/* eslint-enable @typescript-eslint/no-namespace */
Loading
Loading