Skip to content
Draft
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
25 changes: 25 additions & 0 deletions packages/ml/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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 * from './modular';

export type { FirebaseApp, FirebaseML } from './types/ml';

export type { FirebaseMLTypes } from './types/namespaced';

export * from './namespaced';
export { default } from './namespaced';
32 changes: 32 additions & 0 deletions packages/ml/lib/modular.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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, FirebaseML } from './types/ml';

/**
* Returns the {@link FirebaseML} instance for the default or given {@link FirebaseApp}.
*
* @param app - The Firebase `FirebaseApp` to use. When omitted, the default app is used.
* @returns The ML service instance for that app.
*/
export function getML(app?: FirebaseApp): FirebaseML {
if (app) {
return getApp(app.name).ml();
}
return getApp().ml();
}
Comment thread
russellwheatley marked this conversation as resolved.
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.

37 changes: 24 additions & 13 deletions packages/ml/lib/index.js → packages/ml/lib/namespaced.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,38 @@
*
*/

import type { ReactNativeFirebase } from '@react-native-firebase/app';
import {
createModuleNamespace,
FirebaseModule,
getFirebaseRoot,
} from '@react-native-firebase/app/dist/module/internal';
import version from './version';
import './types/internal';
import type { FirebaseMLTypes } from './types/namespaced';
import { version } from './version';

const statics = {};
const statics = {
SDK_VERSION: version,
};

const namespace = 'ml';

const nativeModuleName = 'RNFBMLModule';

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

type MLNamespace = ReactNativeFirebase.FirebaseModuleWithStaticsAndApp<
FirebaseMLTypes.Module,
FirebaseMLTypes.Statics
> & {
firebase: ReactNativeFirebase.Module;
app(name?: string): ReactNativeFirebase.FirebaseApp;
};

// 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 defaultExport = createModuleNamespace({
statics,
version,
namespace,
Expand All @@ -46,12 +55,14 @@ export default createModuleNamespace({
hasMultiAppSupport: true,
hasCustomUrlOrRegionSupport: false,
ModuleClass: FirebaseMLModule,
});
}) as unknown as MLNamespace;

export default defaultExport;

// import ml, { firebase } from '@react-native-firebase/ml';
// ml().X(...);
// firebase.ml().X(...);
export const firebase = getFirebaseRoot();

// e.g.
// // import { MLCloudTextRecognizerModelType } from '@react-native-firebase/ml';
export const firebase = getFirebaseRoot() as unknown as ReactNativeFirebase.Module & {
ml: typeof defaultExport;
app(name?: string): ReactNativeFirebase.FirebaseApp & { ml(): FirebaseMLTypes.Module };
};
29 changes: 29 additions & 0 deletions packages/ml/lib/types/internal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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 contract for `RNFBMLModule`.
* The namespaced `FirebaseMLModule` implementation does not call into native from JS;
* this type anchors `FirebaseModule<typeof nativeModuleName>` and documents the bridge key.
*/
export interface RNFBMLModule {}

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

export type FirebaseApp = ReactNativeFirebase.FirebaseApp;

/**
* Firebase ML service instance for the modular API.
*
* Current Firebase JS SDK releases do not ship a `firebase/ml` modular entry point; this interface
* follows the same modular service-instance pattern used elsewhere in React Native Firebase (see e.g.
* the Firestore package's `Firestore` type).
*/
export interface FirebaseML extends ReactNativeFirebase.FirebaseModule {
/** The FirebaseApp this module is associated with */
app: FirebaseApp;
}
48 changes: 22 additions & 26 deletions packages/ml/lib/index.d.ts → packages/ml/lib/types/namespaced.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
*
*/

import { ReactNativeFirebase } from '@react-native-firebase/app';
import type { ReactNativeFirebase } from '@react-native-firebase/app';

/**
* Firebase ML package for React Native.
*
Expand Down Expand Up @@ -52,46 +53,40 @@ import { ReactNativeFirebase } from '@react-native-firebase/app';
*
* @firebase ml
*/
/**
* @deprecated Use the exported types directly instead.
* FirebaseMLTypes namespace is kept for backwards compatibility.
*/
/* eslint-disable @typescript-eslint/no-namespace */
export namespace FirebaseMLTypes {
import FirebaseModule = ReactNativeFirebase.FirebaseModule;
/**
* @deprecated Use the exported types directly instead. FirebaseMLTypes namespace is kept for backwards compatibility.
*/
type FirebaseModule = ReactNativeFirebase.FirebaseModule;

/**
* @deprecated Use the default export statics instead.
*/
export interface Statics {
/** @deprecated Use the default export statics instead. */
SDK_VERSION: string;
}

export class Module extends FirebaseModule {
/**
* @deprecated Use the exported `FirebaseML` type instead.
*/
export interface Module extends FirebaseModule {
/**
* @deprecated Use the exported `FirebaseML` type instead.
*
* The current `FirebaseApp` instance for this Firebase service.
*/
app: ReactNativeFirebase.FirebaseApp;
}
}

type MLNamespace = ReactNativeFirebase.FirebaseModuleWithStaticsAndApp<
FirebaseMLTypes.Module,
FirebaseMLTypes.Statics
> & {
firebase: ReactNativeFirebase.Module;
app(name?: string): ReactNativeFirebase.FirebaseApp;
};

declare const defaultExport: MLNamespace;

export const firebase: ReactNativeFirebase.Module & {
ml: typeof defaultExport;
app(name?: string): ReactNativeFirebase.FirebaseApp & { ml(): FirebaseMLTypes.Module };
};

export default defaultExport;

export * from './modular';

/**
* Attach namespace to `firebase.` and `FirebaseApp.`.
*/
declare module '@react-native-firebase/app' {
namespace ReactNativeFirebase {
import FirebaseModuleWithStaticsAndApp = ReactNativeFirebase.FirebaseModuleWithStaticsAndApp;
interface Module {
ml: FirebaseModuleWithStaticsAndApp<FirebaseMLTypes.Module, FirebaseMLTypes.Statics>;
}
Expand All @@ -101,3 +96,4 @@ declare module '@react-native-firebase/app' {
}
}
}
/* eslint-enable @typescript-eslint/no-namespace */
44 changes: 39 additions & 5 deletions packages/ml/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
"version": "24.0.0",
"author": "Invertase <oss@invertase.io> (http://invertase.io)",
"description": "React Native Firebase - Firebase ML brings the power of machine learning vision to your React Native application, supporting both Android & iOS.",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"main": "./dist/module/index.js",
"types": "./dist/typescript/lib/index.d.ts",
"scripts": {
"build": "genversion --semi lib/version.js",
"build": "genversion --esm --semi lib/version.ts",
"build:clean": "rimraf android/build && rimraf ios/build",
"prepare": "yarn run build"
"compile": "bob build",
"prepare": "yarn run build && yarn compile"
},
"repository": {
"type": "git",
Expand All @@ -31,5 +32,38 @@
"publishConfig": {
"access": "public",
"provenance": true
}
},
"devDependencies": {
"react-native-builder-bob": "^0.40.13"
},
"exports": {
".": {
"source": "./lib/index.ts",
"types": "./dist/typescript/lib/index.d.ts",
"default": "./dist/module/index.js"
},
"./package.json": "./package.json"
},
"react-native-builder-bob": {
"source": "lib",
"output": "dist",
"targets": [
[
"module",
{
"esm": true
}
],
[
"typescript",
{
"tsc": "../../node_modules/.bin/tsc"
}
]
]
},
"eslintIgnore": [
"node_modules/",
"dist/"
]
}
16 changes: 16 additions & 0 deletions packages/ml/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "../../tsconfig.packages.base.json",
"compilerOptions": {
"baseUrl": ".",
"rootDir": ".",
"paths": {
"@react-native-firebase/app/dist/module/internal": ["../app/dist/typescript/lib/internal"],
"@react-native-firebase/app/dist/module/internal/NativeModules": [
"../app/dist/typescript/lib/internal/NativeModules"
],
"@react-native-firebase/app": ["../app/dist/typescript/lib"]
}
},
"include": ["lib/**/*"],
"exclude": ["node_modules", "dist", "__tests__", "**/*.test.ts"]
}
Loading
Loading