Skip to content

Commit af5f54b

Browse files
authored
fix(@vercel/blob): Ensure all exported methods are correctly documented (#851)
* fix(@vercel/blob): Ensure all exported methods are correctly documented * Update packages/blob/src/client.ts
1 parent 0a62213 commit af5f54b

File tree

22 files changed

+679
-43
lines changed

22 files changed

+679
-43
lines changed

.changeset/giant-hoops-peel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@vercel/blob': patch
3+
---
4+
5+
Add correct documentation to all exported methods

packages/blob/src/client.ts

Lines changed: 315 additions & 22 deletions
Large diffs are not rendered by default.

packages/blob/src/head.ts

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,48 @@
11
import { requestApi } from './api';
22
import type { BlobCommandOptions } from './helpers';
33

4+
/**
5+
* Result of the head method containing metadata about a blob.
6+
*/
47
export interface HeadBlobResult {
5-
url: string;
6-
downloadUrl: string;
8+
/**
9+
* The size of the blob in bytes.
10+
*/
711
size: number;
12+
13+
/**
14+
* The date when the blob was uploaded.
15+
*/
816
uploadedAt: Date;
17+
18+
/**
19+
* The pathname of the blob within the store.
20+
*/
921
pathname: string;
22+
23+
/**
24+
* The content type of the blob.
25+
*/
1026
contentType: string;
27+
28+
/**
29+
* The content disposition header value.
30+
*/
1131
contentDisposition: string;
32+
33+
/**
34+
* The URL of the blob.
35+
*/
36+
url: string;
37+
38+
/**
39+
* A URL that will cause browsers to download the file instead of displaying it inline.
40+
*/
41+
downloadUrl: string;
42+
43+
/**
44+
* The cache control header value.
45+
*/
1246
cacheControl: string;
1347
}
1448

packages/blob/src/helpers.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ export interface BlobCommandOptions {
2121
abortSignal?: AbortSignal;
2222
}
2323

24-
// shared interface for put, copy and multipartUpload
24+
// shared interface for put, copy and multipart upload
2525
export interface CommonCreateBlobOptions extends BlobCommandOptions {
2626
/**
27-
* Whether the blob should be publicly accessible.
27+
* Whether the blob should be publicly accessible. The only currently allowed value is `public`.
2828
*/
2929
access: 'public';
3030
/**
@@ -49,12 +49,29 @@ export interface CommonCreateBlobOptions extends BlobCommandOptions {
4949
cacheControlMaxAge?: number;
5050
}
5151

52+
/**
53+
* Event object passed to the onUploadProgress callback.
54+
*/
5255
export interface UploadProgressEvent {
56+
/**
57+
* The number of bytes uploaded.
58+
*/
5359
loaded: number;
60+
61+
/**
62+
* The total number of bytes to upload.
63+
*/
5464
total: number;
65+
66+
/**
67+
* The percentage of the upload that has been completed.
68+
*/
5569
percentage: number;
5670
}
5771

72+
/**
73+
* Callback type for tracking upload progress.
74+
*/
5875
export type OnUploadProgressCallback = (
5976
progressEvent: UploadProgressEvent,
6077
) => void;
@@ -73,6 +90,9 @@ export type BlobRequest = ({
7390
onUploadProgress?: InternalOnUploadProgressCallback;
7491
}) => Promise<Response>;
7592

93+
/**
94+
* Interface for including upload progress tracking capabilities.
95+
*/
7696
export interface WithUploadProgress {
7797
/**
7898
* Callback to track the upload progress. You will receive an object with the following properties:
@@ -103,6 +123,14 @@ export class BlobError extends Error {
103123
}
104124
}
105125

126+
/**
127+
* Generates a download URL for a blob.
128+
* The download URL includes a ?download=1 parameter which causes browsers to download
129+
* the file instead of displaying it inline.
130+
*
131+
* @param blobUrl - The URL of the blob to generate a download URL for
132+
* @returns A string containing the download URL with the download parameter appended
133+
*/
106134
export function getDownloadUrl(blobUrl: string): string {
107135
const url = new URL(blobUrl);
108136

packages/blob/src/index.ts

Lines changed: 88 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,21 @@ export type { PutCommandOptions };
4141
* Uploads a blob into your store from your server.
4242
* Detailed documentation can be found here: https://vercel.com/docs/vercel-blob/using-blob-sdk#upload-a-blob
4343
*
44-
* If you want to upload from the browser directly, check out the documentation forAclient uploads: https://vercel.com/docs/vercel-blob/using-blob-sdk#client-uploads
44+
* If you want to upload from the browser directly, or if you're hitting Vercel upload limits, check out the documentation for client uploads: https://vercel.com/docs/vercel-blob/using-blob-sdk#client-uploads
4545
*
46-
* @param pathname - The pathname to upload the blob to, including the extension. This will influence the url of your blob like https://$storeId.public.blob.vercel-storage.com/$pathname.
46+
* @param pathname - The pathname to upload the blob to, including the extension. This will influence the URL of your blob like https://$storeId.public.blob.vercel-storage.com/$pathname.
4747
* @param body - The content of your blob, can be a: string, File, Blob, Buffer or Stream. We support almost everything fetch supports: https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#body.
48-
* @param options - Additional options like `token` or `contentType`.
48+
* @param options - Configuration options including:
49+
* - access - (Required) Must be 'public' as blobs are publicly accessible.
50+
* - addRandomSuffix - (Optional) A boolean specifying whether to add a random suffix to the pathname. It defaults to false. We recommend using this option to ensure there are no conflicts in your blob filenames.
51+
* - allowOverwrite - (Optional) A boolean to allow overwriting blobs. By default an error will be thrown if you try to overwrite a blob by using the same pathname for multiple blobs.
52+
* - contentType - (Optional) A string indicating the media type. By default, it's extracted from the pathname's extension.
53+
* - cacheControlMaxAge - (Optional) A number in seconds to configure how long Blobs are cached. Defaults to one month. Cannot be set to a value lower than 1 minute.
54+
* - token - (Optional) A string specifying the token to use when making requests. It defaults to process.env.BLOB_READ_WRITE_TOKEN when deployed on Vercel.
55+
* - multipart - (Optional) Whether to use multipart upload for large files. It will split the file into multiple parts, upload them in parallel and retry failed parts.
56+
* - abortSignal - (Optional) AbortSignal to cancel the operation.
57+
* - onUploadProgress - (Optional) Callback to track upload progress: onUploadProgress(\{loaded: number, total: number, percentage: number\})
58+
* @returns A promise that resolves to the blob information, including pathname, contentType, contentDisposition, url, and downloadUrl.
4959
*/
5060
export const put = createPutMethod<PutCommandOptions>({
5161
allowedOptions: [
@@ -85,6 +95,22 @@ export { copy } from './copy';
8595
// vercelBlob. completeMultipartUpload()
8696
// vercelBlob. createMultipartUploader()
8797

98+
/**
99+
* Creates a multipart upload. This is the first step in the manual multipart upload process.
100+
*
101+
* @param pathname - A string specifying the path inside the blob store. This will be the base value of the return URL and includes the filename and extension.
102+
* @param options - Configuration options including:
103+
* - access - (Required) Must be 'public' as blobs are publicly accessible.
104+
* - addRandomSuffix - (Optional) A boolean specifying whether to add a random suffix to the pathname. It defaults to true.
105+
* - allowOverwrite - (Optional) A boolean to allow overwriting blobs. By default an error will be thrown if you try to overwrite a blob by using the same pathname for multiple blobs.
106+
* - contentType - (Optional) The media type for the file. If not specified, it's derived from the file extension. Falls back to application/octet-stream when no extension exists or can't be matched.
107+
* - cacheControlMaxAge - (Optional) A number in seconds to configure the edge and browser cache. Defaults to one year.
108+
* - token - (Optional) A string specifying the token to use when making requests. It defaults to process.env.BLOB_READ_WRITE_TOKEN when deployed on Vercel.
109+
* - abortSignal - (Optional) AbortSignal to cancel the operation.
110+
* @returns A promise that resolves to an object containing:
111+
* - key: A string that identifies the blob object.
112+
* - uploadId: A string that identifies the multipart upload. Both are needed for subsequent uploadPart calls.
113+
*/
88114
export const createMultipartUpload =
89115
createCreateMultipartUploadMethod<CommonCreateBlobOptions>({
90116
allowedOptions: [
@@ -95,6 +121,25 @@ export const createMultipartUpload =
95121
],
96122
});
97123

124+
/**
125+
* Creates a multipart uploader that simplifies the multipart upload process.
126+
* This is a wrapper around the manual multipart upload process that provides a more convenient API.
127+
*
128+
* @param pathname - A string specifying the path inside the blob store. This will be the base value of the return URL and includes the filename and extension.
129+
* @param options - Configuration options including:
130+
* - access - (Required) Must be 'public' as blobs are publicly accessible.
131+
* - addRandomSuffix - (Optional) A boolean specifying whether to add a random suffix to the pathname. It defaults to true.
132+
* - allowOverwrite - (Optional) A boolean to allow overwriting blobs. By default an error will be thrown if you try to overwrite a blob by using the same pathname for multiple blobs.
133+
* - contentType - (Optional) The media type for the file. If not specified, it's derived from the file extension. Falls back to application/octet-stream when no extension exists or can't be matched.
134+
* - cacheControlMaxAge - (Optional) A number in seconds to configure the edge and browser cache. Defaults to one year.
135+
* - token - (Optional) A string specifying the token to use when making requests. It defaults to process.env.BLOB_READ_WRITE_TOKEN when deployed on Vercel.
136+
* - abortSignal - (Optional) AbortSignal to cancel the operation.
137+
* @returns A promise that resolves to an uploader object with the following properties and methods:
138+
* - key: A string that identifies the blob object.
139+
* - uploadId: A string that identifies the multipart upload.
140+
* - uploadPart: A method to upload a part of the file.
141+
* - complete: A method to complete the multipart upload process.
142+
*/
98143
export const createMultipartUploader =
99144
createCreateMultipartUploaderMethod<CommonCreateBlobOptions>({
100145
allowedOptions: [
@@ -106,6 +151,27 @@ export const createMultipartUploader =
106151
});
107152

108153
export type { UploadPartCommandOptions };
154+
155+
/**
156+
* Uploads a part of a multipart upload.
157+
* Used as part of the manual multipart upload process.
158+
*
159+
* @param pathname - Same value as the pathname parameter passed to createMultipartUpload. This will influence the final URL of your blob.
160+
* @param body - A blob object as ReadableStream, String, ArrayBuffer or Blob based on these supported body types. Each part must be a minimum of 5MB, except the last one which can be smaller.
161+
* @param options - Configuration options including:
162+
* - access - (Required) Must be 'public' as blobs are publicly accessible.
163+
* - uploadId - (Required) A string returned from createMultipartUpload which identifies the multipart upload.
164+
* - key - (Required) A string returned from createMultipartUpload which identifies the blob object.
165+
* - partNumber - (Required) A number identifying which part is uploaded (1-based index).
166+
* - contentType - (Optional) The media type for the blob. By default, it's derived from the pathname.
167+
* - token - (Optional) A string specifying the token to use when making requests. It defaults to process.env.BLOB_READ_WRITE_TOKEN when deployed on Vercel.
168+
* - addRandomSuffix - (Optional) A boolean specifying whether to add a random suffix to the pathname.
169+
* - allowOverwrite - (Optional) A boolean to allow overwriting blobs.
170+
* - cacheControlMaxAge - (Optional) A number in seconds to configure how long Blobs are cached.
171+
* - abortSignal - (Optional) AbortSignal to cancel the running request.
172+
* - onUploadProgress - (Optional) Callback to track upload progress: onUploadProgress(\{loaded: number, total: number, percentage: number\})
173+
* @returns A promise that resolves to the uploaded part information containing etag and partNumber, which will be needed for the completeMultipartUpload call.
174+
*/
109175
export const uploadPart = createUploadPartMethod<UploadPartCommandOptions>({
110176
allowedOptions: [
111177
'cacheControlMaxAge',
@@ -116,6 +182,25 @@ export const uploadPart = createUploadPartMethod<UploadPartCommandOptions>({
116182
});
117183

118184
export type { CompleteMultipartUploadCommandOptions };
185+
186+
/**
187+
* Completes a multipart upload by combining all uploaded parts.
188+
* This is the final step in the manual multipart upload process.
189+
*
190+
* @param pathname - Same value as the pathname parameter passed to createMultipartUpload.
191+
* @param parts - An array containing all the uploaded parts information from previous uploadPart calls. Each part must have properties etag and partNumber.
192+
* @param options - Configuration options including:
193+
* - access - (Required) Must be 'public' as blobs are publicly accessible.
194+
* - uploadId - (Required) A string returned from createMultipartUpload which identifies the multipart upload.
195+
* - key - (Required) A string returned from createMultipartUpload which identifies the blob object.
196+
* - contentType - (Optional) The media type for the file. If not specified, it's derived from the file extension.
197+
* - token - (Optional) A string specifying the token to use when making requests. It defaults to process.env.BLOB_READ_WRITE_TOKEN when deployed on Vercel.
198+
* - addRandomSuffix - (Optional) A boolean specifying whether to add a random suffix to the pathname. It defaults to true.
199+
* - allowOverwrite - (Optional) A boolean to allow overwriting blobs.
200+
* - cacheControlMaxAge - (Optional) A number in seconds to configure the edge and browser cache. Defaults to one year.
201+
* - abortSignal - (Optional) AbortSignal to cancel the operation.
202+
* @returns A promise that resolves to the finalized blob information, including pathname, contentType, contentDisposition, url, and downloadUrl.
203+
*/
119204
export const completeMultipartUpload =
120205
createCompleteMultipartUploadMethod<CompleteMultipartUploadCommandOptions>({
121206
allowedOptions: [

0 commit comments

Comments
 (0)