Skip to content

Commit 5b6ca03

Browse files
refactor: streamline type definitions and remove unused code
1 parent 083cfeb commit 5b6ca03

5 files changed

Lines changed: 24 additions & 56 deletions

File tree

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
11
import { TurboModuleRegistry, type TurboModule } from 'react-native';
22
import type { CodegenTypes } from 'react-native';
33

4-
type GenericType =
5-
| string
6-
| number
7-
| boolean
8-
| null
9-
| undefined
10-
| { [key: string]: GenericType }
11-
| GenericType[];
12-
13-
type GenericMap = { [key: string]: GenericType };
14-
154
type DownloadConfig = {
165
connectionTimeout?: CodegenTypes.Int32;
176
mimeType?: string;
@@ -21,10 +10,10 @@ export interface Spec extends TurboModule {
2110
download(
2211
url: string,
2312
downloadPath: string,
24-
config: GenericMap
13+
config: DownloadConfig
2514
): Promise<void>;
2615
}
2716

2817
export default TurboModuleRegistry.getEnforcing<Spec>('MxDownload');
2918

30-
export type { GenericMap, DownloadConfig };
19+
export type { DownloadConfig };

src/download-handler/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import NativeMxDownload from './NativeMxDownload';
22

3-
// Re-export DownloadConfig type for backward compatibility
4-
export type { DownloadConfig } from './NativeMxDownload';
5-
63
export const NativeDownloadHandler = {
74
download: (url: string, downloadPath: string, config: Record<string, any>) =>
85
NativeMxDownload.download(url, downloadPath, config),
Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { TurboModuleRegistry, type TurboModule } from 'react-native';
1+
import {
2+
TurboModuleRegistry,
3+
type TurboModule,
4+
type CodegenTypes,
5+
} from 'react-native';
26

37
type BlobData = {
48
blobId: string;
@@ -9,33 +13,27 @@ type BlobData = {
913
lastModified?: number;
1014
};
1115

12-
type GenericType =
13-
| string
14-
| number
15-
| boolean
16-
| null
17-
| undefined
18-
| { [key: string]: GenericType }
19-
| GenericType[];
20-
21-
type GenericMap = { [key: string]: GenericType };
22-
type GenericArray = GenericType[];
16+
type FsConstants = {
17+
DocumentDirectoryPath: string;
18+
SUPPORTS_DIRECTORY_MOVE: boolean;
19+
SUPPORTS_ENCRYPTION: boolean;
20+
};
2321

2422
export interface Spec extends TurboModule {
25-
constants(): GenericMap;
26-
save(blob: GenericMap, filePath: string): Promise<void>;
23+
constants(): FsConstants;
24+
save(blob: BlobData, filePath: string): Promise<void>;
2725
read(filePath: string): Promise<BlobData>;
2826
move(filePath: string, newPath: string): Promise<void>;
2927
remove(filePath: string): Promise<void>;
3028
list(dirPath: string): Promise<string[]>;
3129
readAsDataURL(filePath: string): Promise<string>;
3230
readAsText(filePath: string): Promise<string>;
3331
fileExists(filePath: string): Promise<boolean>;
34-
writeJson(data: GenericMap, filepath: string): Promise<void>;
35-
readJson(filepath: string): Promise<GenericMap | GenericArray>;
32+
writeJson(data: CodegenTypes.UnsafeObject, filepath: string): Promise<void>;
33+
readJson(filepath: string): Promise<CodegenTypes.UnsafeObject | null>;
3634
setEncryptionEnabled(enabled: boolean): void;
3735
}
3836

3937
export default TurboModuleRegistry.getEnforcing<Spec>('MxFileSystem');
4038

41-
export type { BlobData, GenericMap, GenericArray };
39+
export type { BlobData, FsConstants };

src/ota/NativeMxOta.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
11
import { TurboModuleRegistry, type TurboModule } from 'react-native';
22
import type { CodegenTypes } from 'react-native';
33

4-
type GenericType =
5-
| string
6-
| number
7-
| boolean
8-
| null
9-
| undefined
10-
| { [key: string]: GenericType }
11-
| GenericType[];
12-
13-
type GenericMap = { [key: string]: GenericType };
14-
154
type OtaDownloadConfig = {
165
url: string;
176
};
@@ -32,15 +21,14 @@ type DownloadProgress = {
3221
};
3322

3423
export interface Spec extends TurboModule {
35-
download(config: GenericMap): Promise<OtaDownloadResponse>;
36-
deploy(config: GenericMap): Promise<void>;
24+
download(config: OtaDownloadConfig): Promise<OtaDownloadResponse>;
25+
deploy(config: OtaDeployConfig): Promise<void>;
3726
readonly onDownloadProgress: CodegenTypes.EventEmitter<DownloadProgress>;
3827
}
3928

4029
export default TurboModuleRegistry.getEnforcing<Spec>('MxOta');
4130

4231
export type {
43-
GenericMap,
4432
OtaDownloadConfig,
4533
OtaDeployConfig,
4634
OtaDownloadResponse,

src/ota/index.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
import NativeMxOta from './NativeMxOta';
2-
3-
// Re-export types for backward compatibility
4-
export type {
5-
OtaDeployConfig,
6-
OtaDownloadConfig,
7-
OtaDownloadResponse,
1+
import NativeMxOta, {
2+
type OtaDeployConfig,
3+
type OtaDownloadConfig,
84
} from './NativeMxOta';
95

106
export const NativeOta = {
11-
download: (config: Record<string, any>) => NativeMxOta.download(config),
12-
deploy: (config: Record<string, any>) => NativeMxOta.deploy(config),
7+
download: (config: OtaDownloadConfig) => NativeMxOta.download(config),
8+
deploy: (config: OtaDeployConfig) => NativeMxOta.deploy(config),
139
};

0 commit comments

Comments
 (0)