@vercel/blob
Advanced tools
Comparing version 0.14.2-15030779-20231107083745 to 0.15.0
@@ -5,2 +5,29 @@ import { B as BlobCommandOptions, C as CreateBlobCommandOptions, P as PutCommandOptions, a as PutBlobResult } from './put-96a1f07e.js'; | ||
/** | ||
* Deletes one or multiple blobs from your store. | ||
* Detailed documentation can be found here: https://vercel.com/docs/storage/vercel-blob/using-blob-sdk#delete-a-blob | ||
* | ||
* @param url - Blob url or array of blob urls that identify the blobs to be deleted. You can only delete blobs that are located in a store, that your 'BLOB_READ_WRITE_TOKEN' has access to. | ||
* @param options - Additional options for the request. | ||
*/ | ||
declare function del(url: string[] | string, options?: BlobCommandOptions): Promise<void>; | ||
interface HeadBlobResult { | ||
url: string; | ||
size: number; | ||
uploadedAt: Date; | ||
pathname: string; | ||
contentType: string; | ||
contentDisposition: string; | ||
cacheControl: string; | ||
} | ||
/** | ||
* Fetches metadata of a blob object. | ||
* Detailed documentation can be found here: https://vercel.com/docs/storage/vercel-blob/using-blob-sdk#get-blob-metadata | ||
* | ||
* @param url - Blob url to lookup. | ||
* @param options - Additional options for the request. | ||
*/ | ||
declare function head(url: string, options?: BlobCommandOptions): Promise<HeadBlobResult>; | ||
interface ListBlobResultBlob { | ||
@@ -81,28 +108,3 @@ url: string; | ||
declare const put: (pathname: string, body: string | stream.Readable | Blob | ArrayBuffer | FormData | ReadableStream<any> | File, options?: PutCommandOptions | undefined) => Promise<PutBlobResult>; | ||
/** | ||
* Deletes one or multiple blobs from your store. | ||
* Detailed documentation can be found here: https://vercel.com/docs/storage/vercel-blob/using-blob-sdk#delete-a-blob | ||
* | ||
* @param url - Blob url or array of blob urls that identify the blobs to be deleted. You can only delete blobs that are located in a store, that your 'BLOB_READ_WRITE_TOKEN' has access to. | ||
* @param options - Additional options for the request. | ||
*/ | ||
declare function del(url: string[] | string, options?: BlobCommandOptions): Promise<void>; | ||
interface HeadBlobResult { | ||
url: string; | ||
size: number; | ||
uploadedAt: Date; | ||
pathname: string; | ||
contentType: string; | ||
contentDisposition: string; | ||
cacheControl: string; | ||
} | ||
/** | ||
* Fetches metadata of a blob object. | ||
* Detailed documentation can be found here: https://vercel.com/docs/storage/vercel-blob/using-blob-sdk#get-blob-metadata | ||
* | ||
* @param url - Blob url to lookup. | ||
* @param options - Additional options for the request. | ||
*/ | ||
declare function head(url: string, options?: BlobCommandOptions): Promise<HeadBlobResult>; | ||
export { CopyBlobResult, HeadBlobResult, ListBlobResult, ListBlobResultBlob, ListCommandOptions, ListFoldedBlobResult, PutBlobResult, copy, del, head, list, put }; | ||
export { CopyBlobResult, CopyCommandOptions, HeadBlobResult, ListBlobResult, ListBlobResultBlob, ListCommandOptions, ListFoldedBlobResult, PutBlobResult, PutCommandOptions, copy, del, head, list, put }; |
@@ -15,7 +15,44 @@ import { | ||
// src/index.ts | ||
import { fetch as fetch3 } from "undici"; | ||
// src/del.ts | ||
import { fetch } from "undici"; | ||
async function del(url, options) { | ||
const blobApiResponse = await fetch(getApiUrl("/delete"), { | ||
method: "POST", | ||
headers: { | ||
...getApiVersionHeader(), | ||
authorization: `Bearer ${getTokenFromOptionsOrEnv(options)}`, | ||
"content-type": "application/json" | ||
}, | ||
body: JSON.stringify({ urls: Array.isArray(url) ? url : [url] }) | ||
}); | ||
await validateBlobApiResponse(blobApiResponse); | ||
await blobApiResponse.json(); | ||
} | ||
// src/head.ts | ||
import { fetch as fetch2 } from "undici"; | ||
async function head(url, options) { | ||
const headApiUrl = new URL(getApiUrl()); | ||
headApiUrl.searchParams.set("url", url); | ||
const blobApiResponse = await fetch2(headApiUrl, { | ||
method: "GET", | ||
// HEAD can't have body as a response, so we use GET | ||
headers: { | ||
...getApiVersionHeader(), | ||
authorization: `Bearer ${getTokenFromOptionsOrEnv(options)}` | ||
} | ||
}); | ||
await validateBlobApiResponse(blobApiResponse); | ||
const headResult = await blobApiResponse.json(); | ||
return mapBlobResult(headResult); | ||
} | ||
function mapBlobResult(blobResult) { | ||
return { | ||
...blobResult, | ||
uploadedAt: new Date(blobResult.uploadedAt) | ||
}; | ||
} | ||
// src/list.ts | ||
import { fetch } from "undici"; | ||
import { fetch as fetch3 } from "undici"; | ||
async function list(options) { | ||
@@ -36,3 +73,3 @@ var _a; | ||
} | ||
const blobApiResponse = await fetch(listApiUrl, { | ||
const blobApiResponse = await fetch3(listApiUrl, { | ||
method: "GET", | ||
@@ -51,3 +88,3 @@ headers: { | ||
hasMore: results.hasMore, | ||
blobs: results.blobs.map(mapBlobResult) | ||
blobs: results.blobs.map(mapBlobResult2) | ||
}; | ||
@@ -58,6 +95,6 @@ } | ||
hasMore: results.hasMore, | ||
blobs: results.blobs.map(mapBlobResult) | ||
blobs: results.blobs.map(mapBlobResult2) | ||
}; | ||
} | ||
function mapBlobResult(blobResult) { | ||
function mapBlobResult2(blobResult) { | ||
return { | ||
@@ -70,3 +107,3 @@ ...blobResult, | ||
// src/copy.ts | ||
import { fetch as fetch2 } from "undici"; | ||
import { fetch as fetch4 } from "undici"; | ||
async function copy(fromUrl, toPathname, options) { | ||
@@ -92,3 +129,3 @@ if (!options) { | ||
} | ||
const blobApiResponse = await fetch2( | ||
const blobApiResponse = await fetch4( | ||
getApiUrl(`/${toPathname}?fromUrl=${fromUrl}`), | ||
@@ -105,36 +142,2 @@ { method: "PUT", headers } | ||
}); | ||
async function del(url, options) { | ||
const blobApiResponse = await fetch3(getApiUrl("/delete"), { | ||
method: "POST", | ||
headers: { | ||
...getApiVersionHeader(), | ||
authorization: `Bearer ${getTokenFromOptionsOrEnv(options)}`, | ||
"content-type": "application/json" | ||
}, | ||
body: JSON.stringify({ urls: Array.isArray(url) ? url : [url] }) | ||
}); | ||
await validateBlobApiResponse(blobApiResponse); | ||
await blobApiResponse.json(); | ||
} | ||
async function head(url, options) { | ||
const headApiUrl = new URL(getApiUrl()); | ||
headApiUrl.searchParams.set("url", url); | ||
const blobApiResponse = await fetch3(headApiUrl, { | ||
method: "GET", | ||
// HEAD can't have body as a response, so we use GET | ||
headers: { | ||
...getApiVersionHeader(), | ||
authorization: `Bearer ${getTokenFromOptionsOrEnv(options)}` | ||
} | ||
}); | ||
await validateBlobApiResponse(blobApiResponse); | ||
const headResult = await blobApiResponse.json(); | ||
return mapBlobResult2(headResult); | ||
} | ||
function mapBlobResult2(blobResult) { | ||
return { | ||
...blobResult, | ||
uploadedAt: new Date(blobResult.uploadedAt) | ||
}; | ||
} | ||
export { | ||
@@ -141,0 +144,0 @@ BlobAccessError, |
{ | ||
"name": "@vercel/blob", | ||
"version": "0.14.2-15030779-20231107083745", | ||
"version": "0.15.0", | ||
"description": "The Vercel Blob JavaScript API client", | ||
@@ -5,0 +5,0 @@ "homepage": "https://vercel.com/storage/blob", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
156766
1306