Skip to content

Commit cb7d7fd

Browse files
kewl
1 parent 56d9030 commit cb7d7fd

File tree

1 file changed

+52
-2
lines changed

1 file changed

+52
-2
lines changed

packages/uploadthing/src/client-future.ts

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,22 @@ import type { AnyFileRoute } from "./types";
99

1010
/**
1111
* Error indicating the XHR request failed
12+
* @public
1213
*/
1314
export class XHRError extends Micro.TaggedError("XHRError")<{
1415
message: string;
1516
xhr: unknown;
1617
}> {}
1718

19+
/**
20+
* Error indicating the network request failed
21+
* @public
22+
*/
1823
export type NetworkError = XHRError | FetchError;
1924

2025
/**
2126
* Error indicating the upload was rejected during upload to the storage provider
27+
* @public
2228
*/
2329
export class UTStorageError extends Micro.TaggedError("UTStorageError")<{
2430
message: string;
@@ -27,6 +33,7 @@ export class UTStorageError extends Micro.TaggedError("UTStorageError")<{
2733

2834
/**
2935
* Error indicating the request to your UploadThing server failed
36+
* @public
3037
*/
3138
export class UTServerError<T> extends Micro.TaggedError("UTServerError")<{
3239
message: string;
@@ -37,6 +44,10 @@ export class UTServerError<T> extends Micro.TaggedError("UTServerError")<{
3744
data: T;
3845
}> {}
3946

47+
/**
48+
* Error indicating the upload failed
49+
* @public
50+
*/
4051
export type UploadThingClientError<TErrorShape> =
4152
| NetworkError
4253
| UTStorageError
@@ -45,7 +56,8 @@ export type UploadThingClientError<TErrorShape> =
4556
/**
4657
* A file that has not started uploading yet.
4758
* Can either be pending for the presigned request to resolve,
48-
* or pending for the browser to upload the file to the storage provider.
59+
* or pending for the browser to schedule the network request.
60+
* @public
4961
*/
5062
export interface PendingFile extends File {
5163
status: "pending";
@@ -62,6 +74,7 @@ export interface PendingFile extends File {
6274

6375
/**
6476
* A file that is currently uploading.
77+
* @public
6578
*/
6679
export interface UploadingFile extends File {
6780
status: "uploading";
@@ -78,6 +91,7 @@ export interface UploadingFile extends File {
7891

7992
/**
8093
* A file that failed to upload.
94+
* @public
8195
*/
8296
export interface FailedFile<TRoute extends AnyFileRoute> extends File {
8397
status: "failed";
@@ -98,6 +112,7 @@ export interface FailedFile<TRoute extends AnyFileRoute> extends File {
98112

99113
/**
100114
* A file that has been uploaded successfully.
115+
* @public
101116
*/
102117
export interface UploadedFile<TRoute extends AnyFileRoute> extends File {
103118
status: "uploaded";
@@ -126,6 +141,10 @@ export interface UploadedFile<TRoute extends AnyFileRoute> extends File {
126141
hash: string;
127142
}
128143

144+
/**
145+
* A web file with additional state properties
146+
* @public
147+
*/
129148
export type AnyFile<TFileRoute extends AnyFileRoute> =
130149
| PendingFile
131150
| UploadingFile
@@ -134,6 +153,7 @@ export type AnyFile<TFileRoute extends AnyFileRoute> =
134153

135154
/**
136155
* Predicate function to check if a file is pending
156+
* @public
137157
*/
138158
export function isPendingFile<TRoute extends AnyFileRoute = AnyFileRoute>(
139159
file: AnyFile<TRoute>,
@@ -143,6 +163,7 @@ export function isPendingFile<TRoute extends AnyFileRoute = AnyFileRoute>(
143163

144164
/**
145165
* Predicate function to check if a file is uploading
166+
* @public
146167
*/
147168
export function isUploadingFile<TRoute extends AnyFileRoute = AnyFileRoute>(
148169
file: AnyFile<TRoute>,
@@ -152,6 +173,7 @@ export function isUploadingFile<TRoute extends AnyFileRoute = AnyFileRoute>(
152173

153174
/**
154175
* Predicate function to check if a file is failed
176+
* @public
155177
*/
156178
export function isFailedFile<TRoute extends AnyFileRoute = AnyFileRoute>(
157179
file: AnyFile<TRoute>,
@@ -161,6 +183,7 @@ export function isFailedFile<TRoute extends AnyFileRoute = AnyFileRoute>(
161183

162184
/**
163185
* Predicate function to check if a file is uploaded
186+
* @public
164187
*/
165188
export function isUploadedFile<TRoute extends AnyFileRoute = AnyFileRoute>(
166189
file: AnyFile<TRoute>,
@@ -170,6 +193,7 @@ export function isUploadedFile<TRoute extends AnyFileRoute = AnyFileRoute>(
170193

171194
/**
172195
* Modifies a pending file to an uploading file in place
196+
* @internal
173197
*/
174198
function transitionToUploading(
175199
file: PendingFile,
@@ -183,6 +207,7 @@ function transitionToUploading(
183207

184208
/**
185209
* Modifies an uploading file to an uploaded file in place
210+
* @internal
186211
*/
187212
function transitionToUploaded<TRoute extends AnyFileRoute>(
188213
file: UploadingFile,
@@ -198,6 +223,7 @@ function transitionToUploaded<TRoute extends AnyFileRoute>(
198223

199224
/**
200225
* Modifies a pending or uploading file to a failed file in place
226+
* @internal
201227
*/
202228
function transitionToFailed<TRoute extends AnyFileRoute>(
203229
file: PendingFile | UploadingFile,
@@ -209,6 +235,10 @@ function transitionToFailed<TRoute extends AnyFileRoute>(
209235
return failedFile;
210236
}
211237

238+
/**
239+
* Event emitted when the presigned URLs have been retrieved from your server
240+
* @public
241+
*/
212242
export interface PresignedReceivedEvent<TRoute extends AnyFileRoute> {
213243
type: "presigned-received";
214244
/**
@@ -217,6 +247,10 @@ export interface PresignedReceivedEvent<TRoute extends AnyFileRoute> {
217247
files: AnyFile<TRoute>[];
218248
}
219249

250+
/**
251+
* Event emitted when a file starts uploading
252+
* @public
253+
*/
220254
export interface UploadStartedEvent<TRoute extends AnyFileRoute> {
221255
type: "upload-started";
222256
/**
@@ -229,10 +263,14 @@ export interface UploadStartedEvent<TRoute extends AnyFileRoute> {
229263
files: AnyFile<TRoute>[];
230264
}
231265

266+
/**
267+
* Event emitted when a file is uploading and received a progress update
268+
* @public
269+
*/
232270
export interface UploadProgressEvent<TRoute extends AnyFileRoute> {
233271
type: "upload-progress";
234272
/**
235-
* The file that is currently uploading.
273+
* The file that is currently uploading and received a progress update.
236274
*/
237275
file: UploadingFile;
238276
/**
@@ -241,6 +279,10 @@ export interface UploadProgressEvent<TRoute extends AnyFileRoute> {
241279
files: AnyFile<TRoute>[];
242280
}
243281

282+
/**
283+
* Event emitted when a file has finished uploading
284+
* @public
285+
*/
244286
export interface UploadCompletedEvent<TRoute extends AnyFileRoute> {
245287
type: "upload-completed";
246288
/**
@@ -253,6 +295,10 @@ export interface UploadCompletedEvent<TRoute extends AnyFileRoute> {
253295
files: AnyFile<TRoute>[];
254296
}
255297

298+
/**
299+
* Event emitted when a file failed to upload
300+
* @public
301+
*/
256302
export interface UploadFailedEvent<TRoute extends AnyFileRoute> {
257303
type: "upload-failed";
258304
/**
@@ -265,6 +311,10 @@ export interface UploadFailedEvent<TRoute extends AnyFileRoute> {
265311
files: AnyFile<TRoute>[];
266312
}
267313

314+
/**
315+
* Event emitted throughout the upload process
316+
* @public
317+
*/
268318
export type UploadEvent<TRoute extends AnyFileRoute> =
269319
| PresignedReceivedEvent<TRoute>
270320
| UploadStartedEvent<TRoute>

0 commit comments

Comments
 (0)