Skip to content

Commit 1407899

Browse files
committed
docs: align documentation with api reference
1 parent 9db6e3b commit 1407899

File tree

24 files changed

+732
-113
lines changed

24 files changed

+732
-113
lines changed
Lines changed: 51 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Class: ResourceFetcher
22

3-
Defined in: [packages/react-native-executorch/src/utils/ResourceFetcher.ts:63](https://github.com/software-mansion/react-native-executorch/blob/326d6344894d75625c600d5988666e215a32d466/packages/react-native-executorch/src/utils/ResourceFetcher.ts#L63)
3+
Defined in: [packages/react-native-executorch/src/utils/ResourceFetcher.ts:52](https://github.com/software-mansion/react-native-executorch/blob/9db6e3b8b0f1b11ef66f7c45d29a251b31e9c252/packages/react-native-executorch/src/utils/ResourceFetcher.ts#L52)
44

55
This module provides functions to download and work with downloaded files stored in the application's document directory inside the `react-native-executorch/` directory.
66
These utilities can help you manage your storage and clean up the downloaded files when they are no longer needed.
@@ -17,67 +17,50 @@ These utilities can help you manage your storage and clean up the downloaded fil
1717

1818
## Properties
1919

20-
### downloads
20+
### fs
2121

22-
> `static` **downloads**: `Map`\<[`ResourceSource`](../type-aliases/ResourceSource.md), `DownloadResource`\>
22+
> `static` **fs**: `object`
2323
24-
Defined in: [packages/react-native-executorch/src/utils/ResourceFetcher.ts:64](https://github.com/software-mansion/react-native-executorch/blob/326d6344894d75625c600d5988666e215a32d466/packages/react-native-executorch/src/utils/ResourceFetcher.ts#L64)
24+
Defined in: [packages/react-native-executorch/src/utils/ResourceFetcher.ts:118](https://github.com/software-mansion/react-native-executorch/blob/9db6e3b8b0f1b11ef66f7c45d29a251b31e9c252/packages/react-native-executorch/src/utils/ResourceFetcher.ts#L118)
2525

26-
## Methods
27-
28-
### cancelFetching()
29-
30-
> `static` **cancelFetching**(...`sources`): `Promise`\<`void`\>
31-
32-
Defined in: [packages/react-native-executorch/src/utils/ResourceFetcher.ts:284](https://github.com/software-mansion/react-native-executorch/blob/326d6344894d75625c600d5988666e215a32d466/packages/react-native-executorch/src/utils/ResourceFetcher.ts#L284)
33-
34-
Cancels an ongoing/paused download of files.
35-
36-
#### Parameters
26+
Filesystem utilities for reading downloaded resources.
3727

38-
##### sources
28+
#### readAsString()
3929

40-
...[`ResourceSource`](../type-aliases/ResourceSource.md)[]
30+
> **readAsString**: (`path`) => `Promise`\<`string`\>
4131
42-
The resource identifiers used when calling `fetch()`.
32+
Reads the contents of a file as a string.
4333

44-
#### Returns
34+
##### Parameters
4535

46-
`Promise`\<`void`\>
36+
###### path
4737

48-
A promise that resolves once the download is canceled.
38+
`string`
4939

50-
---
40+
Absolute file path to read.
5141

52-
### deleteResources()
42+
##### Returns
5343

54-
> `static` **deleteResources**(...`sources`): `Promise`\<`void`\>
44+
`Promise`\<`string`\>
5545

56-
Defined in: [packages/react-native-executorch/src/utils/ResourceFetcher.ts:327](https://github.com/software-mansion/react-native-executorch/blob/326d6344894d75625c600d5988666e215a32d466/packages/react-native-executorch/src/utils/ResourceFetcher.ts#L327)
46+
A promise that resolves to the file contents as a string.
5747

58-
Deletes downloaded resources from the local filesystem.
48+
##### Remarks
5949

60-
#### Parameters
50+
**REQUIRED**: Used internally for reading configuration files (e.g., tokenizer configs).
6151

62-
##### sources
52+
#### Remarks
6353

64-
...[`ResourceSource`](../type-aliases/ResourceSource.md)[]
54+
Provides access to filesystem operations through the configured adapter.
55+
Currently supports reading file contents as strings for configuration files.
6556

66-
The resource identifiers used when calling `fetch`.
67-
68-
#### Returns
69-
70-
`Promise`\<`void`\>
71-
72-
A promise that resolves once all specified resources have been removed.
73-
74-
---
57+
## Methods
7558

7659
### fetch()
7760

7861
> `static` **fetch**(`callback`, ...`sources`): `Promise`\<`string`[] \| `null`\>
7962
80-
Defined in: [packages/react-native-executorch/src/utils/ResourceFetcher.ts:74](https://github.com/software-mansion/react-native-executorch/blob/326d6344894d75625c600d5988666e215a32d466/packages/react-native-executorch/src/utils/ResourceFetcher.ts#L74)
63+
Defined in: [packages/react-native-executorch/src/utils/ResourceFetcher.ts:104](https://github.com/software-mansion/react-native-executorch/blob/9db6e3b8b0f1b11ef66f7c45d29a251b31e9c252/packages/react-native-executorch/src/utils/ResourceFetcher.ts#L104)
8164

8265
Fetches resources (remote URLs, local files or embedded assets), downloads or stores them locally for use by React Native ExecuTorch.
8366

@@ -100,109 +83,72 @@ Multiple resources that can be strings, asset references, or objects.
10083
`Promise`\<`string`[] \| `null`\>
10184

10285
If the fetch was successful, it returns a promise which resolves to an array of local file paths for the downloaded/stored resources (without file:// prefix).
103-
If the fetch was interrupted by `pauseFetching` or `cancelFetching`, it returns a promise which resolves to `null`.
86+
If the fetch was interrupted, it returns a promise which resolves to `null`.
10487

10588
---
10689

107-
### getFilesTotalSize()
90+
### getAdapter()
10891

109-
> `static` **getFilesTotalSize**(...`sources`): `Promise`\<`number`\>
92+
> `static` **getAdapter**(): [`ResourceFetcherAdapter`](../interfaces/ResourceFetcherAdapter.md)
11093
111-
Defined in: [packages/react-native-executorch/src/utils/ResourceFetcher.ts:345](https://github.com/software-mansion/react-native-executorch/blob/326d6344894d75625c600d5988666e215a32d466/packages/react-native-executorch/src/utils/ResourceFetcher.ts#L345)
94+
Defined in: [packages/react-native-executorch/src/utils/ResourceFetcher.ts:86](https://github.com/software-mansion/react-native-executorch/blob/9db6e3b8b0f1b11ef66f7c45d29a251b31e9c252/packages/react-native-executorch/src/utils/ResourceFetcher.ts#L86)
11295

113-
Fetches the info about files size. Works only for remote files.
114-
115-
#### Parameters
116-
117-
##### sources
118-
119-
...[`ResourceSource`](../type-aliases/ResourceSource.md)[]
120-
121-
The resource identifiers (URLs).
96+
Gets the current resource fetcher adapter instance.
12297

12398
#### Returns
12499

125-
`Promise`\<`number`\>
126-
127-
A promise that resolves to combined size of files in bytes.
128-
129-
---
100+
[`ResourceFetcherAdapter`](../interfaces/ResourceFetcherAdapter.md)
130101

131-
### listDownloadedFiles()
102+
The configured ResourceFetcherAdapter instance.
132103

133-
> `static` **listDownloadedFiles**(): `Promise`\<`string`[]\>
104+
#### Throws
134105

135-
Defined in: [packages/react-native-executorch/src/utils/ResourceFetcher.ts:306](https://github.com/software-mansion/react-native-executorch/blob/326d6344894d75625c600d5988666e215a32d466/packages/react-native-executorch/src/utils/ResourceFetcher.ts#L306)
136-
137-
Lists all the downloaded files used by React Native ExecuTorch.
138-
139-
#### Returns
106+
If no adapter has been set via [setAdapter](#setadapter).
140107

141-
`Promise`\<`string`[]\>
108+
#### Remarks
142109

143-
A promise, which resolves to an array of URIs for all the downloaded files.
110+
**INTERNAL**: Used internally by all resource fetching operations.
144111

145112
---
146113

147-
### listDownloadedModels()
114+
### resetAdapter()
148115

149-
> `static` **listDownloadedModels**(): `Promise`\<`string`[]\>
116+
> `static` **resetAdapter**(): `void`
150117
151-
Defined in: [packages/react-native-executorch/src/utils/ResourceFetcher.ts:316](https://github.com/software-mansion/react-native-executorch/blob/326d6344894d75625c600d5988666e215a32d466/packages/react-native-executorch/src/utils/ResourceFetcher.ts#L316)
118+
Defined in: [packages/react-native-executorch/src/utils/ResourceFetcher.ts:73](https://github.com/software-mansion/react-native-executorch/blob/9db6e3b8b0f1b11ef66f7c45d29a251b31e9c252/packages/react-native-executorch/src/utils/ResourceFetcher.ts#L73)
152119

153-
Lists all the downloaded models used by React Native ExecuTorch.
120+
Resets the resource fetcher adapter to null.
154121

155122
#### Returns
156123

157-
`Promise`\<`string`[]\>
158-
159-
A promise, which resolves to an array of URIs for all the downloaded models.
160-
161-
---
162-
163-
### pauseFetching()
164-
165-
> `static` **pauseFetching**(...`sources`): `Promise`\<`void`\>
166-
167-
Defined in: [packages/react-native-executorch/src/utils/ResourceFetcher.ts:261](https://github.com/software-mansion/react-native-executorch/blob/326d6344894d75625c600d5988666e215a32d466/packages/react-native-executorch/src/utils/ResourceFetcher.ts#L261)
124+
`void`
168125

169-
Pauses an ongoing download of files.
126+
#### Remarks
170127

171-
#### Parameters
172-
173-
##### sources
174-
175-
...[`ResourceSource`](../type-aliases/ResourceSource.md)[]
176-
177-
The resource identifiers used when calling `fetch`.
178-
179-
#### Returns
180-
181-
`Promise`\<`void`\>
182-
183-
A promise that resolves once the download is paused.
128+
**INTERNAL**: Used primarily for testing purposes to clear the adapter state.
184129

185130
---
186131

187-
### resumeFetching()
132+
### setAdapter()
188133

189-
> `static` **resumeFetching**(...`sources`): `Promise`\<`void`\>
134+
> `static` **setAdapter**(`adapter`): `void`
190135
191-
Defined in: [packages/react-native-executorch/src/utils/ResourceFetcher.ts:273](https://github.com/software-mansion/react-native-executorch/blob/326d6344894d75625c600d5988666e215a32d466/packages/react-native-executorch/src/utils/ResourceFetcher.ts#L273)
136+
Defined in: [packages/react-native-executorch/src/utils/ResourceFetcher.ts:63](https://github.com/software-mansion/react-native-executorch/blob/9db6e3b8b0f1b11ef66f7c45d29a251b31e9c252/packages/react-native-executorch/src/utils/ResourceFetcher.ts#L63)
192137

193-
Resumes a paused download of files.
138+
Sets a custom resource fetcher adapter for resource operations.
194139

195140
#### Parameters
196141

197-
##### sources
142+
##### adapter
198143

199-
...[`ResourceSource`](../type-aliases/ResourceSource.md)[]
144+
[`ResourceFetcherAdapter`](../interfaces/ResourceFetcherAdapter.md)
200145

201-
The resource identifiers used when calling fetch.
146+
The adapter instance to use for fetching resources.
202147

203148
#### Returns
204149

205-
`Promise`\<`void`\>
150+
`void`
151+
152+
#### Remarks
206153

207-
If the fetch was successful, it returns a promise which resolves to an array of local file paths for the downloaded resources (without file:// prefix).
208-
If the fetch was again interrupted by `pauseFetching` or `cancelFetching`, it returns a promise which resolves to `null`.
154+
**INTERNAL**: Used by platform-specific init functions (expo/bare) to inject their fetcher implementation.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Enumeration: DownloadStatus
2+
3+
Defined in: [packages/react-native-executorch/src/utils/ResourceFetcherUtils.ts:23](https://github.com/software-mansion/react-native-executorch/blob/9db6e3b8b0f1b11ef66f7c45d29a251b31e9c252/packages/react-native-executorch/src/utils/ResourceFetcherUtils.ts#L23)
4+
5+
Download status of the file.
6+
7+
## Enumeration Members
8+
9+
### ONGOING
10+
11+
> **ONGOING**: `0`
12+
13+
Defined in: [packages/react-native-executorch/src/utils/ResourceFetcherUtils.ts:27](https://github.com/software-mansion/react-native-executorch/blob/9db6e3b8b0f1b11ef66f7c45d29a251b31e9c252/packages/react-native-executorch/src/utils/ResourceFetcherUtils.ts#L27)
14+
15+
Download is still in progress.
16+
17+
---
18+
19+
### PAUSED
20+
21+
> **PAUSED**: `1`
22+
23+
Defined in: [packages/react-native-executorch/src/utils/ResourceFetcherUtils.ts:32](https://github.com/software-mansion/react-native-executorch/blob/9db6e3b8b0f1b11ef66f7c45d29a251b31e9c252/packages/react-native-executorch/src/utils/ResourceFetcherUtils.ts#L32)
24+
25+
Download is paused.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Enumeration: HTTP_CODE
2+
3+
Defined in: [packages/react-native-executorch/src/utils/ResourceFetcherUtils.ts:8](https://github.com/software-mansion/react-native-executorch/blob/9db6e3b8b0f1b11ef66f7c45d29a251b31e9c252/packages/react-native-executorch/src/utils/ResourceFetcherUtils.ts#L8)
4+
5+
Http status codes
6+
7+
## Enumeration Members
8+
9+
### OK
10+
11+
> **OK**: `200`
12+
13+
Defined in: [packages/react-native-executorch/src/utils/ResourceFetcherUtils.ts:11](https://github.com/software-mansion/react-native-executorch/blob/9db6e3b8b0f1b11ef66f7c45d29a251b31e9c252/packages/react-native-executorch/src/utils/ResourceFetcherUtils.ts#L11)
14+
15+
- Everything is ok.
16+
17+
---
18+
19+
### PARTIAL_CONTENT
20+
21+
> **PARTIAL_CONTENT**: `206`
22+
23+
Defined in: [packages/react-native-executorch/src/utils/ResourceFetcherUtils.ts:15](https://github.com/software-mansion/react-native-executorch/blob/9db6e3b8b0f1b11ef66f7c45d29a251b31e9c252/packages/react-native-executorch/src/utils/ResourceFetcherUtils.ts#L15)
24+
25+
- Server has fulfilled a client request for a specific part of a resource, instead of sending the entire file.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Enumeration: SourceType
2+
3+
Defined in: [packages/react-native-executorch/src/utils/ResourceFetcherUtils.ts:40](https://github.com/software-mansion/react-native-executorch/blob/9db6e3b8b0f1b11ef66f7c45d29a251b31e9c252/packages/react-native-executorch/src/utils/ResourceFetcherUtils.ts#L40)
4+
5+
Types of sources that can be downloaded
6+
7+
## Enumeration Members
8+
9+
### DEV_MODE_FILE
10+
11+
> **DEV_MODE_FILE**: `3`
12+
13+
Defined in: [packages/react-native-executorch/src/utils/ResourceFetcherUtils.ts:59](https://github.com/software-mansion/react-native-executorch/blob/9db6e3b8b0f1b11ef66f7c45d29a251b31e9c252/packages/react-native-executorch/src/utils/ResourceFetcherUtils.ts#L59)
14+
15+
Represents a file served via the metro bundler during development.
16+
17+
---
18+
19+
### LOCAL_FILE
20+
21+
> **LOCAL_FILE**: `1`
22+
23+
Defined in: [packages/react-native-executorch/src/utils/ResourceFetcherUtils.ts:49](https://github.com/software-mansion/react-native-executorch/blob/9db6e3b8b0f1b11ef66f7c45d29a251b31e9c252/packages/react-native-executorch/src/utils/ResourceFetcherUtils.ts#L49)
24+
25+
Represents a file stored locally on the filesystem.
26+
27+
---
28+
29+
### OBJECT
30+
31+
> **OBJECT**: `0`
32+
33+
Defined in: [packages/react-native-executorch/src/utils/ResourceFetcherUtils.ts:44](https://github.com/software-mansion/react-native-executorch/blob/9db6e3b8b0f1b11ef66f7c45d29a251b31e9c252/packages/react-native-executorch/src/utils/ResourceFetcherUtils.ts#L44)
34+
35+
Represents a raw object or data structure.
36+
37+
---
38+
39+
### RELEASE_MODE_FILE
40+
41+
> **RELEASE_MODE_FILE**: `2`
42+
43+
Defined in: [packages/react-native-executorch/src/utils/ResourceFetcherUtils.ts:54](https://github.com/software-mansion/react-native-executorch/blob/9db6e3b8b0f1b11ef66f7c45d29a251b31e9c252/packages/react-native-executorch/src/utils/ResourceFetcherUtils.ts#L54)
44+
45+
Represents a file bundled with the application in release mode.
46+
47+
---
48+
49+
### REMOTE_FILE
50+
51+
> **REMOTE_FILE**: `4`
52+
53+
Defined in: [packages/react-native-executorch/src/utils/ResourceFetcherUtils.ts:64](https://github.com/software-mansion/react-native-executorch/blob/9db6e3b8b0f1b11ef66f7c45d29a251b31e9c252/packages/react-native-executorch/src/utils/ResourceFetcherUtils.ts#L64)
54+
55+
Represents a file located at a remote URL.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Function: cleanupExecutorch()
2+
3+
> **cleanupExecutorch**(): `void`
4+
5+
Defined in: [packages/react-native-executorch/src/index.ts:32](https://github.com/software-mansion/react-native-executorch/blob/9db6e3b8b0f1b11ef66f7c45d29a251b31e9c252/packages/react-native-executorch/src/index.ts#L32)
6+
7+
Function that cleans current setup of fetching resources.
8+
9+
## Returns
10+
11+
`void`
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Function: initExecutorch()
2+
3+
> **initExecutorch**(`config`): `void`
4+
5+
Defined in: [packages/react-native-executorch/src/index.ts:23](https://github.com/software-mansion/react-native-executorch/blob/9db6e3b8b0f1b11ef66f7c45d29a251b31e9c252/packages/react-native-executorch/src/index.ts#L23)
6+
7+
Function that setups the provided resource fetcher.
8+
9+
## Parameters
10+
11+
### config
12+
13+
[`ExecutorchConfig`](../interfaces/ExecutorchConfig.md)
14+
15+
Configuration that you want to use in resource fetching.
16+
17+
## Returns
18+
19+
`void`

0 commit comments

Comments
 (0)