Skip to content

Commit e02db2c

Browse files
refactor: move to types/ directory
1 parent 54c6fdc commit e02db2c

File tree

11 files changed

+153
-133
lines changed

11 files changed

+153
-133
lines changed

packages/app/lib/common/index.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import { Platform } from 'react-native';
1818
import Base64 from './Base64';
1919
import { isFunction, isObject, isString } from './validate';
20+
import type { DataUrlParts, Observer } from '../types/internal';
2021

2122
export * from './id';
2223
export * from './path';
@@ -26,10 +27,7 @@ export * from './validate';
2627
export { default as Base64 } from './Base64';
2728
export { default as ReferenceBase } from './ReferenceBase';
2829

29-
export interface DataUrlParts {
30-
base64String: string | undefined;
31-
mediaType: string | undefined;
32-
}
30+
export type { DataUrlParts, Observer };
3331

3432
export function getDataUrlParts(dataUrlString: string): DataUrlParts {
3533
const isBase64 = dataUrlString.includes(';base64');
@@ -111,12 +109,6 @@ export function tryJSONStringify(data: any): string | null {
111109
}
112110
}
113111

114-
export interface Observer<T> {
115-
next: (value: T) => void;
116-
error?: (error: Error) => void;
117-
complete?: () => void;
118-
}
119-
120112
export function parseListenerOrObserver<T>(
121113
listenerOrObserver: ((value: T) => void) | Observer<T>,
122114
): (value: T) => void {

packages/app/lib/common/promise.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,7 @@
1616
*/
1717

1818
import { isFunction } from './validate';
19-
20-
export interface Deferred<T> {
21-
promise: Promise<T>;
22-
resolve: ((value: T) => void) | null;
23-
reject: ((reason?: any) => void) | null;
24-
}
19+
import type { Deferred, Callback } from '../types/internal';
2520

2621
/**
2722
* Creates a deferred promise
@@ -41,8 +36,6 @@ export function promiseDefer<T = void>(): Deferred<T> {
4136
return deferred;
4237
}
4338

44-
type Callback<T> = ((error: Error | null, result?: T) => void) | ((error: Error | null) => void);
45-
4639
/**
4740
* Attaches an optional callback to a promise
4841
* @param promise

packages/app/lib/common/serialize.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@
1717

1818
import { tryJSONParse, tryJSONStringify } from './index';
1919
import { isObject } from './validate';
20-
21-
export interface SerializedValue {
22-
type: string;
23-
value: any;
24-
}
20+
import type { SerializedValue } from '../types/internal';
2521

2622
export function serializeType(value: any): SerializedValue {
2723
if (isObject(value)) {

packages/app/lib/internal/FirebaseModule.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,12 @@
1818
import { getAppModule, getNativeModule } from './registry/nativeModule';
1919
import SharedEventEmitter from './SharedEventEmitter';
2020
import type { ReactNativeFirebase } from '../types/app';
21+
import type { FirebaseJsonConfig, ModuleConfig } from '../types/internal';
2122
import type { ReactNativeFirebaseNativeModules } from './NativeModules';
2223
import type EventEmitter from 'react-native/Libraries/vendor/emitter/EventEmitter';
2324

24-
/**
25-
* Firebase JSON configuration from firebase.json file
26-
* Structure: { "react-native": { [key: string]: boolean | string }, ... }
27-
*/
28-
export type FirebaseJsonConfig = Record<string, unknown>;
29-
3025
let firebaseJson: FirebaseJsonConfig | null = null;
3126

32-
export interface ModuleConfig {
33-
namespace: string;
34-
nativeModuleName?: string | string[];
35-
hasMultiAppSupport?: boolean;
36-
hasCustomUrlOrRegionSupport?: boolean;
37-
nativeEvents?: boolean | string[];
38-
disablePrependCustomUrlOrRegion?: boolean;
39-
turboModule?: boolean;
40-
}
41-
4227
export default class FirebaseModule<
4328
NativeModuleName extends keyof ReactNativeFirebaseNativeModules = any,
4429
> {

packages/app/lib/internal/NativeFirebaseError.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,7 @@
1515
*
1616
*/
1717

18-
export interface NativeErrorUserInfo {
19-
code?: string;
20-
message?: string;
21-
nativeErrorCode?: string | number;
22-
nativeErrorMessage?: string;
23-
[key: string]: any;
24-
}
25-
26-
export interface NativeError {
27-
userInfo: NativeErrorUserInfo;
28-
message?: string;
29-
customData?: any;
30-
operationType?: string;
31-
}
18+
import type { NativeErrorUserInfo, NativeError } from '../types/internal';
3219

3320
export default class NativeFirebaseError extends Error {
3421
readonly namespace!: string;

packages/app/lib/internal/asyncStorage.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,7 @@
1515
*
1616
*/
1717

18-
// AsyncStorage interface compatible with React Native AsyncStorage
19-
export interface AsyncStorageStatic {
20-
setItem: (key: string, value: string) => Promise<void>;
21-
getItem: (key: string) => Promise<string | null>;
22-
removeItem: (key: string) => Promise<void>;
23-
}
18+
import type { AsyncStorageStatic } from '../types/internal';
2419

2520
// Memory storage Map instance
2621
export const memoryStorage = new Map<string, string>();

packages/app/lib/internal/logger.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,9 @@
1515
*
1616
*/
1717

18-
export type LogLevelString = 'debug' | 'verbose' | 'info' | 'warn' | 'error' | 'silent';
18+
import type { LogCallback, LogOptions } from '../types/app';
1919

20-
export interface LogOptions {
21-
level?: LogLevelString;
22-
}
23-
24-
export type LogCallback = (callbackParams: LogCallbackParams) => void;
25-
26-
export interface LogCallbackParams {
27-
level: LogLevelString;
28-
message: string;
29-
args: unknown[];
30-
type: string;
31-
}
20+
type LogLevelString = 'debug' | 'verbose' | 'info' | 'warn' | 'error' | 'silent';
3221

3322
/**
3423
* The JS SDK supports 5 log levels and also allows a user the ability to

packages/app/lib/internal/registry/namespace.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import FirebaseApp from '../../FirebaseApp';
2020
import { version as SDK_VERSION } from '../../version';
2121
import { DEFAULT_APP_NAME, KNOWN_NAMESPACES, type KnownNamespace } from '../constants';
2222
import FirebaseModule from '../FirebaseModule';
23-
import type { ModuleGetter, FirebaseRoot, NamespaceConfig } from '../../types/app';
23+
import type { ModuleGetter, FirebaseRoot, NamespaceConfig } from '../../types/internal';
2424
import {
2525
getApp,
2626
getApps,

packages/app/lib/internal/registry/nativeModule.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
*
1616
*/
1717
import { APP_NATIVE_MODULE } from '../constants';
18-
import NativeFirebaseError, { type NativeError } from '../NativeFirebaseError';
18+
import NativeFirebaseError from '../NativeFirebaseError';
19+
import type { NativeError } from '../../types/internal';
1920
import RNFBNativeEventEmitter from '../RNFBNativeEventEmitter';
2021
import SharedEventEmitter from '../SharedEventEmitter';
2122
import { getReactNativeModule } from '../nativeModule';

packages/app/lib/types/app.ts

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -626,62 +626,3 @@ export interface LogOptions {
626626

627627
// Re-export FirebaseApp as a named type for easier importing
628628
export type FirebaseApp = ReactNativeFirebase.FirebaseApp;
629-
630-
/**
631-
* Internal namespace types for Firebase module registry
632-
*/
633-
634-
/**
635-
* Type for a Firebase module getter function that can optionally accept
636-
* a custom URL/region/databaseId parameter
637-
*/
638-
export type ModuleGetter = {
639-
(customUrlOrRegionOrDatabaseId?: string): ReactNativeFirebase.FirebaseModule;
640-
[key: string]: unknown;
641-
};
642-
643-
/**
644-
* Type for Firebase root object with module getters
645-
*/
646-
export interface FirebaseRoot {
647-
initializeApp: (
648-
options: ReactNativeFirebase.FirebaseAppOptions,
649-
configOrName?: string | ReactNativeFirebase.FirebaseAppConfig,
650-
) => Promise<ReactNativeFirebase.FirebaseApp>;
651-
setReactNativeAsyncStorage: (asyncStorage: ReactNativeFirebase.ReactNativeAsyncStorage) => void;
652-
app: (name?: string) => ReactNativeFirebase.FirebaseApp;
653-
apps: ReactNativeFirebase.FirebaseApp[];
654-
SDK_VERSION: string;
655-
setLogLevel: (logLevel: ReactNativeFirebase.LogLevelString) => void;
656-
[key: string]: unknown;
657-
}
658-
659-
/**
660-
* Configuration interface for module namespace registration
661-
*/
662-
export interface ModuleConfig {
663-
namespace: string;
664-
nativeModuleName?: string | string[];
665-
hasMultiAppSupport?: boolean;
666-
hasCustomUrlOrRegionSupport?: boolean;
667-
nativeEvents?: boolean | string[];
668-
disablePrependCustomUrlOrRegion?: boolean;
669-
turboModule?: boolean;
670-
}
671-
672-
/**
673-
* Extended configuration for namespace registration including native module details
674-
*/
675-
export interface NamespaceConfig extends ModuleConfig {
676-
nativeModuleName: string | string[];
677-
nativeEvents: boolean | string[];
678-
// ModuleClass can be FirebaseModule or any subclass of it
679-
// Uses FirebaseAppBase (the concrete class type) rather than FirebaseApp (the augmented interface)
680-
ModuleClass: new (
681-
app: ReactNativeFirebase.FirebaseAppBase,
682-
config: ModuleConfig,
683-
customUrlOrRegion?: string | null,
684-
) => ReactNativeFirebase.FirebaseModule;
685-
statics?: object;
686-
version?: string;
687-
}

0 commit comments

Comments
 (0)