@visulima/storage 1.0.9 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/adapter/nuxt/module.d.ts +8 -8
- package/dist/ai/ai-sdk/index.d.ts +51 -59
- package/dist/ai/claude/index.d.ts +104 -119
- package/dist/ai/openai/index.d.ts +86 -99
- package/dist/ai/tanstack/index.d.ts +53 -61
- package/dist/handler/http/fetch/index.d.ts +201 -201
- package/dist/handler/http/hono/index.d.ts +59 -59
- package/dist/handler/http/nextjs/index.d.ts +54 -54
- package/dist/handler/http/node/index.d.ts +233 -246
- package/dist/handler/http/solid-start/index.d.ts +54 -54
- package/dist/index.d.ts +70 -70
- package/dist/index.js +1 -1
- package/dist/packem_shared/{AwsLightStorage-BK-WPL0h.js → AwsLightStorage-EsqkAtU5.js} +1 -1
- package/dist/packem_shared/{AzureStorage-1UvDIQZd.js → AzureStorage-DL-U7qFG.js} +1 -1
- package/dist/packem_shared/BoxMetaStorage-CHWrhgg2.js +1 -0
- package/dist/packem_shared/{BoxStorage-DbGqBLux.js → BoxStorage-B8_oCz27.js} +1 -1
- package/dist/packem_shared/BunS3MetaStorage-CHWrhgg2.js +1 -0
- package/dist/packem_shared/{BunS3Storage-DNvimm9e.js → BunS3Storage-_PVXu_na.js} +1 -1
- package/dist/packem_shared/BunnyMetaStorage-CHWrhgg2.js +1 -0
- package/dist/packem_shared/{BunnyStorage-C7d0opLL.js → BunnyStorage-BsoWjScH.js} +1 -1
- package/dist/packem_shared/CloudinaryMetaStorage-BI9YXcwU.js +1 -0
- package/dist/packem_shared/{CloudinaryStorage-Dc3XA2lP.js → CloudinaryStorage-BNwiLF9V.js} +1 -1
- package/dist/packem_shared/{DiskStorage-CI07TVNu.js → DiskStorage-D-NtQDms.js} +1 -1
- package/dist/packem_shared/{DiskStorageWithChecksum-vFCubS6K.js → DiskStorageWithChecksum-UnCtyEvs.js} +1 -1
- package/dist/packem_shared/DropboxMetaStorage-CHWrhgg2.js +1 -0
- package/dist/packem_shared/{DropboxStorage-CY9Ggu3m.js → DropboxStorage-BS9kj0nH.js} +1 -1
- package/dist/packem_shared/FirebaseMetaStorage-BI9YXcwU.js +1 -0
- package/dist/packem_shared/{FirebaseStorage-D6O9CJXN.js → FirebaseStorage-DNquii2p.js} +1 -1
- package/dist/packem_shared/FtpMetaStorage-CHWrhgg2.js +1 -0
- package/dist/packem_shared/{FtpStorage-DbEjbq8z.js → FtpStorage-Bd004--s.js} +1 -1
- package/dist/packem_shared/{GCSMetaStorage-DT8K6zdm.js → GCSMetaStorage-Bf4qDFB1.js} +1 -1
- package/dist/packem_shared/{GCStorage-6BHkFlEs.js → GCStorage-ChqEpgqR.js} +1 -1
- package/dist/packem_shared/GoogleDriveMetaStorage-xlHfKwmR.js +1 -0
- package/dist/packem_shared/{GoogleDriveStorage-Bklsz7Bh.js → GoogleDriveStorage-v1glykjd.js} +1 -1
- package/dist/packem_shared/{LocalMetaStorage-BhicZnNl.js → LocalMetaStorage-YWPBYEe7.js} +1 -1
- package/dist/packem_shared/NetlifyBlobMetaStorage-BI9YXcwU.js +1 -0
- package/dist/packem_shared/{NetlifyBlobStorage-CkpCCoN1.js → NetlifyBlobStorage-BPyEWSnx.js} +1 -1
- package/dist/packem_shared/OneDriveMetaStorage-xlHfKwmR.js +1 -0
- package/dist/packem_shared/{OneDriveStorage-CP6MvGAa.js → OneDriveStorage-BJ3Kzxc5.js} +1 -1
- package/dist/packem_shared/PocketBaseMetaStorage-DnrxOQhO.js +1 -0
- package/dist/packem_shared/{PocketBaseStorage-2qhbI2PW.js → PocketBaseStorage-DqKHbbvn.js} +1 -1
- package/dist/packem_shared/{S3Storage-YGeNk3Tt.js → S3Storage-BiI2k6d1.js} +1 -1
- package/dist/packem_shared/SftpMetaStorage-CHWrhgg2.js +1 -0
- package/dist/packem_shared/{SftpStorage-2Hz396Xr.js → SftpStorage-w8XdtZtw.js} +1 -1
- package/dist/packem_shared/SharePointMetaStorage-CHWrhgg2.js +1 -0
- package/dist/packem_shared/{SharePointStorage-CrX2Pk6C.js → SharePointStorage-DpDpI7Ln.js} +1 -1
- package/dist/packem_shared/SupabaseMetaStorage-xlHfKwmR.js +1 -0
- package/dist/packem_shared/{SupabaseStorage-Dc_DBX29.js → SupabaseStorage-B_ugUCs7.js} +1 -1
- package/dist/packem_shared/UploadThingMetaStorage-BI9YXcwU.js +1 -0
- package/dist/packem_shared/{UploadThingStorage-BChykYSe.js → UploadThingStorage-_H45IVqX.js} +1 -1
- package/dist/packem_shared/VercelBlobMetaStorage-CHWrhgg2.js +1 -0
- package/dist/packem_shared/{VercelBlobStorage-CsRyPfw3.js → VercelBlobStorage-U1YMKeHs.js} +1 -1
- package/dist/packem_shared/{approval.d-CMAYH9GF.d.ts → approval.d-C-d-t94D.d.ts} +6 -6
- package/dist/packem_shared/disk-storage-BwPk2IRa.js +1 -0
- package/dist/packem_shared/disk-storage-with-checksum.d-CQucFacO.d.ts +146 -0
- package/dist/packem_shared/{executors.d-BZP2rWo3.d.ts → executors.d-DeDH3Ilt.d.ts} +2 -2
- package/dist/packem_shared/files.d-D8H_ge9Y.d.ts +655 -0
- package/dist/packem_shared/{gcs-meta-storage-B7BnctnV.js → gcs-meta-storage-DQGu_cHq.js} +1 -1
- package/dist/packem_shared/local-meta-storage-DJDcuxf1.js +11 -0
- package/dist/packem_shared/{local-meta-storage.d-D9PBfkn6.d.ts → local-meta-storage.d-DuTEzyii.d.ts} +7 -7
- package/dist/packem_shared/media-transformer.d-CvMFjINm.d.ts +331 -0
- package/dist/packem_shared/{memory-storage.d-4EU1cMt1.d.ts → memory-storage.d-BRdTiY8y.d.ts} +32 -40
- package/dist/packem_shared/{s3-base-storage-BoTyhuzO.js → s3-base-storage-CMUui93V.js} +1 -1
- package/dist/packem_shared/{s3-base-storage.d-BQgP5B-t.d.ts → s3-base-storage.d-Cg7m4FuH.d.ts} +64 -70
- package/dist/packem_shared/storage.d-DIav_lF1.d.ts +1163 -0
- package/dist/packem_shared/tus-base.d-BiEg5t4t.d.ts +102 -0
- package/dist/packem_shared/{types.d-CrUWY4On.d.ts → types.d-CAAzKiI6.d.ts} +134 -134
- package/dist/packem_shared/types.d-DgHhkCAl.d.ts +104 -0
- package/dist/packem_shared/{types.d-CggTCgXr.d.ts → types.d-jAs_Rp_v.d.ts} +3 -3
- package/dist/storage/aws/clients/index.d.ts +388 -388
- package/dist/storage/aws/index.d.ts +109 -113
- package/dist/storage/aws/index.js +1 -1
- package/dist/storage/aws-light/index.d.ts +63 -67
- package/dist/storage/aws-light/index.js +1 -1
- package/dist/storage/azure/index.d.ts +133 -139
- package/dist/storage/azure/index.js +1 -1
- package/dist/storage/box/index.d.ts +88 -92
- package/dist/storage/box/index.js +1 -1
- package/dist/storage/bun-s3/index.d.ts +70 -76
- package/dist/storage/bun-s3/index.js +1 -1
- package/dist/storage/bunny/index.d.ts +51 -55
- package/dist/storage/bunny/index.js +1 -1
- package/dist/storage/cloudinary/index.d.ts +53 -59
- package/dist/storage/cloudinary/index.js +1 -1
- package/dist/storage/dropbox/index.d.ts +58 -62
- package/dist/storage/dropbox/index.js +1 -1
- package/dist/storage/firebase/index.d.ts +73 -79
- package/dist/storage/firebase/index.js +1 -1
- package/dist/storage/ftp/index.d.ts +37 -43
- package/dist/storage/ftp/index.js +1 -1
- package/dist/storage/gcs/index.d.ts +89 -95
- package/dist/storage/gcs/index.js +1 -1
- package/dist/storage/google-drive/index.d.ts +68 -72
- package/dist/storage/google-drive/index.js +1 -1
- package/dist/storage/local/index.d.ts +3 -3
- package/dist/storage/local/index.js +1 -1
- package/dist/storage/memory/index.d.ts +2 -2
- package/dist/storage/netlify-blob/index.d.ts +85 -93
- package/dist/storage/netlify-blob/index.js +1 -1
- package/dist/storage/onedrive/index.d.ts +43 -53
- package/dist/storage/onedrive/index.js +1 -1
- package/dist/storage/pocketbase/index.d.ts +66 -72
- package/dist/storage/pocketbase/index.js +1 -1
- package/dist/storage/sftp/index.d.ts +39 -45
- package/dist/storage/sftp/index.js +1 -1
- package/dist/storage/sharepoint/index.d.ts +95 -95
- package/dist/storage/sharepoint/index.js +1 -1
- package/dist/storage/supabase/index.d.ts +49 -55
- package/dist/storage/supabase/index.js +1 -1
- package/dist/storage/uploadthing/index.d.ts +33 -37
- package/dist/storage/uploadthing/index.js +1 -1
- package/dist/storage/vercel-blob/index.d.ts +109 -115
- package/dist/storage/vercel-blob/index.js +1 -1
- package/dist/transformer/audio-transformer.d.ts +96 -96
- package/dist/transformer/image-transformer.d.ts +422 -422
- package/dist/transformer/index.d.ts +34 -34
- package/dist/transformer/video-transformer.d.ts +111 -111
- package/package.json +1 -1
- package/dist/packem_shared/BoxMetaStorage-BSn6Qfnf.js +0 -1
- package/dist/packem_shared/BunS3MetaStorage-BSn6Qfnf.js +0 -1
- package/dist/packem_shared/BunnyMetaStorage-BSn6Qfnf.js +0 -1
- package/dist/packem_shared/CloudinaryMetaStorage-DPVnmNe5.js +0 -1
- package/dist/packem_shared/DropboxMetaStorage-BSn6Qfnf.js +0 -1
- package/dist/packem_shared/FirebaseMetaStorage-DPVnmNe5.js +0 -1
- package/dist/packem_shared/FtpMetaStorage-BSn6Qfnf.js +0 -1
- package/dist/packem_shared/GoogleDriveMetaStorage-Cbwa1CHV.js +0 -1
- package/dist/packem_shared/NetlifyBlobMetaStorage-DPVnmNe5.js +0 -1
- package/dist/packem_shared/OneDriveMetaStorage-Cbwa1CHV.js +0 -1
- package/dist/packem_shared/PocketBaseMetaStorage-DOTLwVE7.js +0 -1
- package/dist/packem_shared/SftpMetaStorage-BSn6Qfnf.js +0 -1
- package/dist/packem_shared/SharePointMetaStorage-BSn6Qfnf.js +0 -1
- package/dist/packem_shared/SupabaseMetaStorage-Cbwa1CHV.js +0 -1
- package/dist/packem_shared/UploadThingMetaStorage-DPVnmNe5.js +0 -1
- package/dist/packem_shared/VercelBlobMetaStorage-BSn6Qfnf.js +0 -1
- package/dist/packem_shared/disk-storage-CsQcYW3s.js +0 -1
- package/dist/packem_shared/disk-storage-with-checksum.d-B-VGEsfl.d.ts +0 -156
- package/dist/packem_shared/files.d-CH0iLBNC.d.ts +0 -655
- package/dist/packem_shared/local-meta-storage-iuJnu90B.js +0 -11
- package/dist/packem_shared/media-transformer.d-Quf4ai47.d.ts +0 -331
- package/dist/packem_shared/storage.d-CEM1upWM.d.ts +0 -1176
- package/dist/packem_shared/tus-base.d-DLzKE54M.d.ts +0 -106
- package/dist/packem_shared/types.d-Bon9GVVe.d.ts +0 -104
|
@@ -1 +1 @@
|
|
|
1
|
-
import{StorageClient as l}from"@supabase/storage-js";import{throwErrorCode as h,ERRORS as u}from"./ERRORS-BIBxE2oR.js";import{B as f}from"./storage-0j5nCAUp.js";import c from"./SupabaseFile-Bo5B-vM1.js";import g from"./SupabaseMetaStorage-
|
|
1
|
+
import{StorageClient as l}from"@supabase/storage-js";import{throwErrorCode as h,ERRORS as u}from"./ERRORS-BIBxE2oR.js";import{B as f}from"./storage-0j5nCAUp.js";import c from"./SupabaseFile-Bo5B-vM1.js";import g from"./SupabaseMetaStorage-xlHfKwmR.js";import{t as p}from"./get-file-status-y3wTtDQs.js";import{t as w}from"./update-size-DuNuLyxj.js";import{i as y}from"./part-match-D-9dGX42.js";import{e as b}from"./has-content-50BsqrWw.js";const d=3600*24*7,E=o=>{if(!o||!/^attachment(\s*;|\s*$)/i.test(o.trim()))return;const e=o.match(/filename\*?=(?:UTF-8'')?(?:"([^"]+)"|([^;]+))/i),a=e?.[1]??e?.[2];if(!a)return!0;try{return decodeURIComponent(a.trim())}catch{return a.trim()}},S=async o=>{const e=[];for await(const a of o)e.push(Buffer.from(a));return Buffer.concat(e)};class R extends f{static name="supabase";checksumTypes=[];meta;bucket;defaultUrlExpiresIn;storageClient;constructor(e){if(super(e),this.bucket=e.bucket,this.defaultUrlExpiresIn=Math.min(e.defaultUrlExpiresIn??3600,d),e.client)this.storageClient=e.client;else{const a=e.url??process.env.SUPABASE_URL,t=e.serviceKey??process.env.SUPABASE_SERVICE_ROLE_KEY??process.env.SUPABASE_KEY;if(!a)throw new Error("Supabase storage: `url` is required (or set SUPABASE_URL).");if(!t)throw new Error("Supabase storage: `serviceKey` is required (or set SUPABASE_SERVICE_ROLE_KEY / SUPABASE_KEY).");const i=a.replace(/\/+$/,"")+(a.endsWith("/storage/v1")?"":"/storage/v1");this.storageClient=new l(i,{apikey:t,Authorization:`Bearer ${t}`},e.fetch)}this.meta=e.metaStorage??new g(e.metaStorageConfig),this.isReady=!0}get raw(){return this.storageClient}async create(e,a){return this.instrumentOperation("create",async()=>{const t=new c(e);t.name=this.namingFunction(t),t.bucket=this.bucket,t.path=t.name,await this.validate(t);try{const i=await this.getMeta(t.id);if(i.bytesWritten>=0)return i}catch{}return t.bytesWritten=0,t.status=p(t),await this.saveMeta(t),await this.onCreate(t),t})}async write(e,a){return this.instrumentOperation("write",async()=>{let t;if("contentType"in e&&"metadata"in e&&!("body"in e)&&!("start"in e)?t=e:(t=await this.getMeta(e.id),await this.checkIfExpired(t)),t.status==="completed")return t;if(e.size!==void 0&&w(t,e.size),!y(e,t))throw new Error("File part does not match");const i=await this.lock(e.id);try{if(b(e)){if(this.isUnsupportedChecksum(e.checksumAlgorithm))throw new Error("Unsupported checksum algorithm");const r=await S(e.body),n=t.path??t.name,{data:s,error:m}=await this.runOperation(a,()=>this.storageClient.from(this.bucket).upload(n,r,{contentType:t.contentType,upsert:!0}));if(m)throw m;t.bytesWritten=r.length,t.size=r.length,t.path=s?.path??n,t.ETag=s?.id}return t.status=p(t),t.status==="completed"&&await this.internalOnComplete(t),await this.saveMeta(t),t}finally{await this.unlock(e.id,i)}})}async delete({id:e},a){return this.instrumentOperation("delete",async()=>{let t;try{t=await this.getMeta(e)}catch{}const i=t?.path??t?.name??e,{error:r}=await this.runOperation(a,()=>this.storageClient.from(this.bucket).remove([i]));if(r&&r.message&&!/not.*found/i.test(r.message))throw r;return t?(t.status="deleted",await this.deleteMeta(t.id),await this.onDelete(t),t):Object.assign(new c({contentType:"application/octet-stream",metadata:{},originalName:e}),{bucket:this.bucket,id:e,name:e,path:i,status:"deleted"})})}async exists({id:e},a){return this.instrumentOperation("exists",async()=>{let t=e;try{t=(await this.getMeta(e)).path??e}catch{}const{data:i,error:r}=await this.runOperation(a,()=>this.storageClient.from(this.bucket).exists(t));return r?!1:!!i})}async get({id:e},a){return this.instrumentOperation("get",async()=>{let t=e,i;try{i=await this.checkIfExpired(await this.getMeta(e)),t=i.path??i.name??e}catch{}const{data:r,error:n}=await this.runOperation(a,()=>this.storageClient.from(this.bucket).download(t));if(n||!r)throw n??new Error(`Supabase: object not found at "${t}"`);const s=Buffer.from(await this.runOperation(a,()=>r.arrayBuffer()));return{content:s,contentType:i?.contentType??r.type??"application/octet-stream",ETag:i?.ETag,expiredAt:i?.expiredAt,id:e,metadata:i?.metadata??{},modifiedAt:i?.modifiedAt,name:i?.name??t,originalName:i?.originalName??t,size:i?.size??s.length}})}async copy(e,a,t){return this.instrumentOperation("copy",async()=>{const i=(await this.getMetaSafe(e))?.path??e,r=a,{error:n}=await this.runOperation(t,()=>this.storageClient.from(this.bucket).copy(i,r));if(n)throw n;const s=new c({contentType:"application/octet-stream",metadata:{},originalName:a});return s.id=a,s.name=a,s.path=r,s.bucket=this.bucket,s})}async move(e,a,t){return this.instrumentOperation("move",async()=>{const i=(await this.getMetaSafe(e))?.path??e,{error:r}=await this.runOperation(t,()=>this.storageClient.from(this.bucket).move(i,a));if(r)throw r;const n=new c({contentType:"application/octet-stream",metadata:{},originalName:a});n.id=a,n.name=a,n.path=a,n.bucket=this.bucket;try{await this.deleteMeta(e)}catch{}return n})}async list(e=1e3,a){return this.instrumentOperation("list",async()=>{const{data:t,error:i}=await this.runOperation(a,()=>this.storageClient.from(this.bucket).list("",{limit:e}));if(i)throw i;return(t??[]).map(r=>{const n=new c({contentType:r.metadata?.mimetype??"application/octet-stream",metadata:r.metadata??{},originalName:r.name});return n.id=r.name,n.name=r.name,n.path=r.name,n.bucket=this.bucket,n.size=typeof r.metadata?.size=="number"?r.metadata.size:void 0,n.createdAt=r.created_at??void 0,n.modifiedAt=r.updated_at??void 0,n.ETag=r.metadata?.eTag??r.id??void 0,n})},{limit:e})}async getReadUrl(e,a){const t=Math.min(a?.expiresIn??this.defaultUrlExpiresIn,d),{data:i,error:r}=await this.storageClient.from(this.bucket).createSignedUrl(e,t,{download:E(a?.responseContentDisposition)});return r||!i?h(u.METHOD_NOT_ALLOWED,r?.message??"Supabase: createSignedUrl failed"):i.signedUrl}async getUploadUrl(e,a){if(a?.contentType!==void 0||a?.contentLength!==void 0)return h(u.BAD_REQUEST,"Supabase: `contentType`/`contentLength` are not supported for upload URLs. A Supabase signed upload URL does not bind the request Content-Type into the signature and cannot enforce a size limit; validate both at your application gateway/proxy before issuing the URL.");const{data:t,error:i}=await this.storageClient.from(this.bucket).createSignedUploadUrl(e);return i||!t?h(u.METHOD_NOT_ALLOWED,i?.message??"Supabase: createSignedUploadUrl failed"):t.signedUrl}async getMetaSafe(e){try{return await this.getMeta(e)}catch{return}}internalOnComplete=e=>this.deleteMeta(e.id)}export{R as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{y as s}from"./local-meta-storage-DJDcuxf1.js";class o extends s{constructor(r){super(r)}}export{o as default};
|
package/dist/packem_shared/{UploadThingStorage-BChykYSe.js → UploadThingStorage-_H45IVqX.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{UTApi as w,UTFile as u}from"uploadthing/server";import{throwErrorCode as l,ERRORS as h}from"./ERRORS-BIBxE2oR.js";import{B as g}from"./storage-0j5nCAUp.js";import d from"./UploadThingFile-BTFMpcIA.js";import T from"./UploadThingMetaStorage-
|
|
1
|
+
import{UTApi as w,UTFile as u}from"uploadthing/server";import{throwErrorCode as l,ERRORS as h}from"./ERRORS-BIBxE2oR.js";import{B as g}from"./storage-0j5nCAUp.js";import d from"./UploadThingFile-BTFMpcIA.js";import T from"./UploadThingMetaStorage-BI9YXcwU.js";import{t as m}from"./get-file-status-y3wTtDQs.js";import{t as U}from"./update-size-DuNuLyxj.js";import{i as I}from"./part-match-D-9dGX42.js";import{e as O}from"./has-content-50BsqrWw.js";const f=3600*24*7,E=p=>{let e;try{e=typeof atob=="function"?atob(p):Buffer.from(p,"base64").toString("utf8")}catch(t){throw new Error(`UploadThing: token is not valid base64: ${t.message}`)}let a;try{a=JSON.parse(e)}catch(t){throw new Error(`UploadThing: token does not decode to JSON: ${t.message}`)}if(!a||typeof a!="object"||typeof a.apiKey!="string"||typeof a.appId!="string")throw new Error("UploadThing: token missing `apiKey` or `appId`");return a},k=async p=>{const e=[];for await(const a of p)e.push(Buffer.from(a));return Buffer.concat(e)},y=p=>{const e=p.lastIndexOf("/");return e===-1?p:p.slice(e+1)};class S extends g{static name="uploadthing";checksumTypes=[];meta;acl;appId;defaultUrlExpiresIn;utapi;constructor(e){super(e);const a=e.token??process.env.UPLOADTHING_TOKEN;if(e.client)this.utapi=e.client;else{if(!a)throw new Error("UploadThing: missing token. Pass `token` or set UPLOADTHING_TOKEN.");this.utapi=new w({defaultKeyType:"customId",token:a})}if(!a)throw new Error("UploadThing: `token` is required even when passing `client` so the adapter can derive `appId` for CDN URLs.");this.appId=E(a).appId,this.acl=e.acl??"public-read",this.defaultUrlExpiresIn=Math.min(e.defaultUrlExpiresIn??3600,f),this.meta=e.metaStorage??new T(e.metaStorageConfig),this.isReady=!0}get raw(){return this.utapi}async create(e,a){return this.instrumentOperation("create",async()=>{const t=new d(e);t.name=this.namingFunction(t),t.customId=t.name,await this.validate(t);try{const i=await this.getMeta(t.id);if(i.bytesWritten>=0)return i}catch{}return t.bytesWritten=0,t.status=m(t),await this.saveMeta(t),await this.onCreate(t),t})}async write(e,a){return this.instrumentOperation("write",async()=>{let t;if("contentType"in e&&"metadata"in e&&!("body"in e)&&!("start"in e)?t=e:(t=await this.getMeta(e.id),await this.checkIfExpired(t)),t.status==="completed")return t;if(e.size!==void 0&&U(t,e.size),!I(e,t))throw new Error("File part does not match");const i=await this.lock(e.id);try{if(O(e)){if(this.isUnsupportedChecksum(e.checksumAlgorithm))throw new Error("Unsupported checksum algorithm");const n=await k(e.body),o=new Blob([new Uint8Array(n)],{type:t.contentType}),s=new u([o],y(t.name||t.id),{customId:t.name||t.id,type:t.contentType}),r=await this.runOperation(a,()=>this.utapi.uploadFiles(s,{acl:this.acl}));if(r.error)throw new Error(r.error.message);const{data:c}=r;t.bytesWritten=n.length,t.size=n.length,t.ufsKey=c.key,t.url=c.ufsUrl??c.url,t.ETag=c.fileHash,t.fileHash=c.fileHash}return t.status=m(t),t.status==="completed"&&await this.internalOnComplete(t),await this.saveMeta(t),t}finally{await this.unlock(e.id,i)}})}async delete({id:e},a){return this.instrumentOperation("delete",async()=>{let t;try{t=await this.getMeta(e)}catch{}const i=t?.customId??t?.name??e;return await this.runOperation(a,()=>this.utapi.deleteFiles(i)),t?(t.status="deleted",await this.deleteMeta(t.id),await this.onDelete(t),t):Object.assign(new d({contentType:"application/octet-stream",metadata:{},originalName:e}),{customId:i,id:e,name:e,status:"deleted"})})}async get({id:e},a){return this.instrumentOperation("get",async()=>{let t,i=e;try{t=await this.checkIfExpired(await this.getMeta(e)),i=t.customId??t.name??e}catch{}const n=await this.resolveFetchUrl(i,a),o=await this.runOperation(a,()=>fetch(n));if(!o.ok)throw new Error(`UploadThing: fetch failed: ${o.status} ${o.statusText} for ${i}`);const s=Buffer.from(await o.arrayBuffer());return{content:s,contentType:t?.contentType??o.headers.get("content-type")??"application/octet-stream",ETag:t?.ETag??o.headers.get("etag")??void 0,expiredAt:t?.expiredAt,id:e,metadata:t?.metadata??{},modifiedAt:t?.modifiedAt,name:t?.name??i,originalName:t?.originalName??i,size:t?.size??s.length}})}async copy(e,a,t){return this.instrumentOperation("copy",async()=>{const i=await this.get({id:e},t),n=new Blob([new Uint8Array(i.content)],{type:i.contentType}),o=new u([n],y(a),{customId:a,type:i.contentType}),s=await this.runOperation(t,()=>this.utapi.uploadFiles(o,{acl:this.acl}));if(s.error)throw new Error(s.error.message);const r=new d({contentType:i.contentType,metadata:{},originalName:a});return r.id=a,r.name=a,r.customId=a,r.size=typeof i.size=="string"?Number(i.size):i.size,r.ufsKey=s.data.key,r.url=s.data.ufsUrl??s.data.url,r.ETag=s.data.fileHash,r})}async move(e,a,t){return this.instrumentOperation("move",async()=>{const i=await this.copy(e,a,t);return await this.delete({id:e},t),i})}async list(e=1e3,a){return this.instrumentOperation("list",async()=>(await this.runOperation(a,()=>this.utapi.listFiles({limit:e}))).files.map(t=>{const i=t.customId??t.key,n=new d({contentType:"application/octet-stream",metadata:{},originalName:i});return n.id=i,n.name=i,n.customId=t.customId??void 0,n.ufsKey=t.key,n.size=t.size,n.modifiedAt=t.uploadedAt?new Date(t.uploadedAt).toISOString():void 0,n}),{limit:e})}async getReadUrl(e,a){if(a?.responseContentDisposition!==void 0||a?.responseContentType!==void 0)return l(h.METHOD_NOT_ALLOWED,"UploadThing: `responseContentDisposition`/`responseContentType` are not supported — no override exists on UploadThing CDN/signed URLs.");if(this.acl==="public-read")return`https://${this.appId}.ufs.sh/f/${encodeURIComponent(e)}`;const t=Math.min(a?.expiresIn??this.defaultUrlExpiresIn,f),{ufsUrl:i}=await this.utapi.generateSignedURL(e,{expiresIn:t,keyType:"customId"});return i}async getUploadUrl(e,a){return l(h.METHOD_NOT_ALLOWED,"UploadThing: presigned PUT URLs require the UFS ingest signing scheme — use the file-router pattern via `storage.raw` instead.")}async resolveFetchUrl(e,a){if(this.acl==="public-read")return`https://${this.appId}.ufs.sh/f/${encodeURIComponent(e)}`;const{ufsUrl:t}=await this.runOperation(a,()=>this.utapi.generateSignedURL(e,{expiresIn:this.defaultUrlExpiresIn,keyType:"customId"}));return t}internalOnComplete=e=>this.deleteMeta(e.id)}export{S as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{y as r}from"./local-meta-storage-DJDcuxf1.js";class o extends r{constructor(e){super(e)}}export{o as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{put as l,list as u,del as d,copy as h}from"@vercel/blob";import{a as y}from"./detect-file-type-BA7UBLKA.js";import{B as O,c as E}from"./storage-0j5nCAUp.js";import{y as g}from"./local-meta-storage-
|
|
1
|
+
import{put as l,list as u,del as d,copy as h}from"@vercel/blob";import{a as y}from"./detect-file-type-BA7UBLKA.js";import{B as O,c as E}from"./storage-0j5nCAUp.js";import{y as g}from"./local-meta-storage-DJDcuxf1.js";import m from"./VercelBlobFile-CVQwKlZk.js";import{t as p}from"./get-file-status-y3wTtDQs.js";import{t as T}from"./update-size-DuNuLyxj.js";import{i as b}from"./part-match-D-9dGX42.js";import{e as v}from"./has-content-50BsqrWw.js";class f extends O{static name="vercel-blob";checksumTypes=["md5"];get raw(){return{copy:h,credentials:this.credentials,del:d,list:u,put:l}}meta;credentials;multipart;access;constructor(e){super(e),this.credentials=f.resolveCredentials(e),this.multipart=e.multipart??!1,this.access=e.access??"public";const{metaStorage:r,metaStorageConfig:t}=e;this.meta=r||new g(t),this.isReady=!0}static resolveCredentials(e){if(e.token)return{token:e.token};const r=e.oidcToken??process.env.VERCEL_OIDC_TOKEN,t=e.storeId??process.env.BLOB_STORE_ID,i=t?.startsWith("store_")?t.slice(6):t;if(r&&i)return{oidcToken:r,storeId:i};if(r||i)throw new Error(`Vercel Blob OIDC auth requires both \`oidcToken\` and \`storeId\` (or \`VERCEL_OIDC_TOKEN\` and \`BLOB_STORE_ID\` env vars). Got: oidcToken=${r?"set":"missing"}, storeId=${i?"set":"missing"}.`);const a=process.env.BLOB_READ_WRITE_TOKEN||process.env.VERCEL_BLOB_TOKEN;if(a)return{token:a};throw new Error("Vercel Blob credentials are required. Provide `token`, an `oidcToken`+`storeId` pair, or set BLOB_READ_WRITE_TOKEN / (VERCEL_OIDC_TOKEN + BLOB_STORE_ID) env vars.")}async create(e,r){return this.instrumentOperation("create",async()=>{const t={...e};if(e.ttl){const a=typeof e.ttl=="string"?E(e.ttl):e.ttl;t.expiredAt=a===void 0?void 0:Date.now()+a}const i=new m(t);i.name=this.namingFunction(i),await this.validate(i);try{const a=await this.getMeta(i.id);if(a.bytesWritten>=0)return a}catch{}return i.bytesWritten=0,i.status=p(i),await this.saveMeta(i),await this.onCreate(i),i})}async write(e,r){return this.instrumentOperation("write",async()=>{let t;if("contentType"in e&&"metadata"in e&&!("body"in e)&&!("start"in e)?t=e:(t=await this.getMeta(e.id),await this.checkIfExpired(t)),t.status==="completed")return t;if(e.size!==void 0&&T(t,e.size),!b(e,t))throw new Error("File part does not match");const i=await this.lock(e.id);try{if(v(e)){if(this.isUnsupportedChecksum(e.checksumAlgorithm))throw new Error("Unsupported checksum algorithm");const a=[],n=e.body;for await(const o of n)a.push(Buffer.from(o));const s=Buffer.concat(a);if((t.bytesWritten===0||Number.isNaN(t.bytesWritten))&&(!t.contentType||t.contentType==="application/octet-stream"))try{const o=await y(s);o?.mime&&(t.contentType=o.mime)}catch{}const w=new Blob([s],{type:t.contentType}),c=await this.runOperation(r,()=>l(t.name,w,{access:this.access,multipart:this.shouldUseMultipart(t),...this.credentials}));t.url=c.url,t.pathname=c.pathname,t.downloadUrl=c.downloadUrl,t.bytesWritten=s.length}return t.status=p(t),t.status==="completed"&&await this.internalOnComplete(t),await this.saveMeta(t),t}finally{await this.unlock(e.id,i)}})}async delete({id:e},r){return this.instrumentOperation("delete",async()=>{const t=await this.getMeta(e);if(!t.url)throw new Error(`File ${e} does not have a valid URL`);const{url:i}=t;t.status="deleted";try{await this.runOperation(r,()=>d(i,{...this.credentials}))}catch(n){this.logger?.error("Failed to delete blob from Vercel Blob:",n);const s=this.normalizeError(n instanceof Error?n:new Error(String(n)));await this.onError(s)}await this.deleteMeta(t.id);const a={...t};return await this.onDelete(a),a})}async exists({id:e},r){return this.instrumentOperation("exists",async()=>{try{const t=await this.getMeta(e);if(!t.url||t.url.length===0)return!1;const{url:i}=t;return(await this.runOperation(r,()=>fetch(i,{method:"HEAD"}))).ok}catch{return!1}})}async get({id:e},r){return this.instrumentOperation("get",async()=>{const t=await this.checkIfExpired(await this.getMeta(e));if(!t.url||t.url.length===0)throw new Error("File URL not found");const{url:i}=t,a=await this.runOperation(r,()=>fetch(i)),n=Buffer.from(await this.runOperation(r,()=>a.arrayBuffer()));return{content:n,contentType:t.contentType,ETag:t.ETag,expiredAt:t.expiredAt,id:e,metadata:t.metadata,modifiedAt:t.modifiedAt,name:t.name,originalName:t.originalName,size:t.size||n.length}})}async copy(e,r,t){return this.instrumentOperation("copy",async()=>{const i=await this.getMeta(e);if(!i.url)throw new Error("Source file URL not found");const a=i.url,n=await this.runOperation(t,()=>h(a,r,{access:"public",...this.credentials}));return{...i,id:r,name:r,pathname:n.pathname,url:n.url}})}async move(e,r,t){return this.instrumentOperation("move",async()=>{const i=await this.copy(e,r,t);return await this.delete({id:e},t),i})}async list(e=1e3,r){return this.instrumentOperation("list",async()=>(await this.runOperation(r,()=>u({limit:e,...this.credentials}))).blobs.map(t=>{const i=new m({contentType:"application/octet-stream",metadata:{},originalName:t.pathname});return i.createdAt=t.uploadedAt?.toISOString(),i.id=t.pathname,i.modifiedAt=t.uploadedAt?.toISOString(),i.name=t.pathname,i.pathname=t.pathname,i.size=t.size,i.url=t.url,i.downloadUrl=t.downloadUrl,i}),{limit:e})}internalOnComplete=e=>this.deleteMeta(e.id);shouldUseMultipart(e){return typeof this.multipart=="boolean"?this.multipart:typeof this.multipart=="number"&&e.size!==void 0?e.size>=this.multipart:!1}}export{f as default};
|
|
@@ -65,11 +65,11 @@ type DeleteFileInput = z.infer<typeof deleteFileInputSchema>;
|
|
|
65
65
|
type CopyFileInput = z.infer<typeof copyFileInputSchema>;
|
|
66
66
|
type SignUploadUrlInput = z.infer<typeof signUploadUrlInputSchema>;
|
|
67
67
|
/**
|
|
68
|
-
* Whether write operations require user approval.
|
|
69
|
-
*
|
|
70
|
-
* - `true` — all write tools need approval (default)
|
|
71
|
-
* - `false` — no approval needed for any write tool
|
|
72
|
-
* - object — per-tool override; unspecified write tools default to `true`
|
|
73
|
-
*/
|
|
68
|
+
* Whether write operations require user approval.
|
|
69
|
+
*
|
|
70
|
+
* - `true` — all write tools need approval (default)
|
|
71
|
+
* - `false` — no approval needed for any write tool
|
|
72
|
+
* - object — per-tool override; unspecified write tools default to `true`
|
|
73
|
+
*/
|
|
74
74
|
type ApprovalConfig = boolean | Partial<Record<FileWriteToolName, boolean>>;
|
|
75
75
|
export { ApprovalConfig as A, CopyFileInput as C, DeleteFileInput as D, FileToolName as F, GetFileMetadataInput as G, ListFilesInput as L, SignUploadUrlInput as S, TOOL_SCHEMAS as T, UploadFileInput as U, DownloadFileInput as a, GetFileUrlInput as b, FileReadToolName as c, FileWriteToolName as d };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createReadStream as _,createWriteStream as C}from"node:fs";import{truncate as P,stat as F,open as L,copyFile as A}from"node:fs/promises";import{PassThrough as W,Transform as x,pipeline as U}from"node:stream";import{y as D,h as I,q as B,u as M,X as Q,x as V,d as H}from"./local-meta-storage-DJDcuxf1.js";import{A as X,m as q}from"./path-0oTTdkvl-DvWvbDbh.js";import{F as G}from"./index-nZWCQrSe.js";import{d as K}from"./detect-file-type-BA7UBLKA.js";import{throwErrorCode as g,ERRORS as h,isUploadError as Y}from"./ERRORS-BIBxE2oR.js";import{createHash as j}from"node:crypto";import{B as J,a as Z,c as $}from"./storage-0j5nCAUp.js";import tt from"./File-W8aOo15X.js";import{t as k}from"./get-file-status-y3wTtDQs.js";import{t as et}from"./update-size-DuNuLyxj.js";import{i as rt}from"./part-match-D-9dGX42.js";import{e as it}from"./has-content-50BsqrWw.js";class st extends x{constructor(t,e,r="base64"){super(),this.checksum=t,this.algorithm=e,this.encoding=r,this.hash=j(e)}checksum;algorithm;encoding;length=0;digest="";hash;get calculatedDigest(){return this.digest}_transform(t,e,r){this.push(t),this.hash.update(t),this.length+=t.length,r()}_flush(t){this.digest=this.hash.digest(this.encoding),this.checksum&&this.checksum!==this.digest?t(new Error("Checksum mismatch")):t()}}const at=(S,t,e="base64")=>t?new st(S,t,e):new W;class nt extends x{constructor(t=Number.POSITIVE_INFINITY){super(),this.limit=t}limit;length=0;_transform(t,e,r){const a=this.length+t.length;this.limit>=a?(this.push(t),this.length=a,r()):r(new Error("Stream length limit exceeded"))}}class w extends J{static name="disk";checksumTypes=["md5","sha1"];supportsRange=!0;get raw(){return{directory:this.directory}}directory;meta;constructor(t){const e={...t,fileNameValidation:t.fileNameValidation??Z};if(super(e),this.directory=e.directory,e.metaStorage)this.meta=e.metaStorage;else{const r={...e,...e.metaStorageConfig,logger:this.logger};this.meta=new D(r)}this.isReady=!1,this.accessCheck().then(()=>{this.isReady=!0}).catch(r=>{this.logger?.error("Storage access check failed: %O",r)})}normalizeError(t){return super.normalizeError(t)}async create(t){return this.instrumentOperation("create",async()=>{const e={...t};if(t.ttl){const i=typeof t.ttl=="string"?$(t.ttl):t.ttl;i!==void 0&&(e.expiredAt=Date.now()+i)}e.size!==void 0&&Number(e.size)<0&&g(h.REQUEST_ENTITY_TOO_LARGE,"Request entity too large");const r=new tt(e);try{const i=await this.getMeta(r.id);if(i.status==="completed")return i}catch{}r.name=this.namingFunction(r),(r.size===void 0||Number.isNaN(r.size))&&(r.size===void 0||(r.size=this.maxUploadSize)),await this.validate(r);const a=this.getFilePath(r.name);try{await I(a),r.bytesWritten=0}catch(i){const s=this.normalizeError(i instanceof Error?i:new Error(String(i)));await this.onError(s),g(h.FILE_ERROR,s.message)}return r.status=k(r),await this.saveMeta(r),await this.onCreate(r),r})}async write(t){return this.instrumentOperation("write",async()=>{let e;if("contentType"in t&&"metadata"in t&&!("body"in t)&&!("start"in t)?e=t:(e=await this.getMeta(t.id),await this.checkIfExpired(e)),e.status==="completed")return e;if(t.size!==void 0&&et(e,t.size),!rt(t,e))return g(h.FILE_CONFLICT);const r=this.getFilePath(e.name),a=await this.lock(r);try{const i=t.start||0;if(await I(r),e.bytesWritten===0&&(e.bytesWritten=i),it(t)){if(this.isUnsupportedChecksum(t.checksumAlgorithm))return g(h.UNSUPPORTED_CHECKSUM_ALGORITHM);if((t.start===0||t.start===void 0)&&(e.bytesWritten===0||Number.isNaN(e.bytesWritten))&&(!e.contentType||e.contentType==="application/octet-stream"))try{const{fileType:u,stream:d}=await K(t.body);u?.mime&&(e.contentType=u.mime),t.body=d}catch{}const s=t.signal,o={...e,...t,body:t.body};s&&(o.signal=s);const[n,m]=await this.lazyWrite(o);if(m)return await P(r,e.bytesWritten),g(m);const l=i+(t.contentLength||0);e.bytesWritten=Math.max(e.bytesWritten||0,l),e.bytesWritten=Math.max(e.bytesWritten||0,n),e.status=k(e),await this.saveMeta(e)}else await I(r),e.bytesWritten=0;return e}catch(i){if(Y(i))throw i;const s=this.normalizeError(i instanceof Error?i:new Error(String(i)));return await this.onError(s),g(h.FILE_ERROR,(typeof s.message=="string"?s.message:String(i))||String(i))}finally{await this.unlock(r,a)}})}async get({id:t},e){return this.instrumentOperation("get",async()=>{const r=await this.checkIfExpired(await this.meta.get(t)),{bytesWritten:a,contentType:i,expiredAt:s,metadata:o,modifiedAt:n,name:m,originalName:l,size:u}=r,d=this.getFilePath(m),E=e?.range,b=async c=>{const y=c;if(y.code==="ENOENT"||y.code==="EPERM"){const p=this.normalizeError(c instanceof Error?c:new Error(y.message||String(c)));return await this.onError(p),g(h.FILE_NOT_FOUND,(typeof p.message=="string"?p.message:String(c))||String(c))}const f=this.normalizeError(c instanceof Error?c:new Error(String(c)));throw await this.onError(f),c};if(E){let c;try{c=await F(d)}catch(R){return b(R)}const y=c.size,f=Math.max(0,E.start),p=E.end===void 0?y-1:Math.min(y-1,E.end);if(f>p||f>=y)return g(h.BAD_REQUEST,`Invalid range ${f}-${E.end??""}`);const N=p-f+1,z=Buffer.allocUnsafe(N);let O;try{O=await L(d,"r"),await O.read(z,0,N,f)}catch(R){return b(R)}finally{await O?.close()}const v=`W/"${y.toString(16)}-${Math.trunc(c.mtimeMs).toString(16)}-${f}-${p}"`;return{content:z,contentType:i,ETag:v,expiredAt:s,id:t,metadata:o,modifiedAt:n,name:m,originalName:l,size:N}}let T;try{T=await B(d,{buffer:!0})}catch(c){return b(c)}return{content:T,contentType:i,ETag:G(T),expiredAt:s,id:t,metadata:o,modifiedAt:n,name:m,originalName:l,size:u||a}})}async exists({id:t}){return this.instrumentOperation("exists",async()=>{try{const e=await this.getMeta(t),r=this.getFilePath(e.name);return await F(r),!0}catch{return!1}})}async getStream({id:t}){return this.instrumentOperation("getStream",async()=>{try{const e=await this.checkIfExpired(await this.meta.get(t)),{bytesWritten:r,contentType:a,expiredAt:i,modifiedAt:s,name:o,size:n}=e,m=_(this.getFilePath(o));return{headers:{"Content-Length":String(n||r),"Content-Type":a,...i&&{"X-Upload-Expires":i.toString()},...s&&{"Last-Modified":s.toString()}},size:n||r,stream:m}}catch(e){const r=this.normalizeError(e instanceof Error?e:new Error(String(e)));throw await this.onError(r),g(h.FILE_NOT_FOUND,(typeof r.message=="string"?r.message:String(e))||String(e))}})}async delete({id:t}){return this.instrumentOperation("delete",async()=>{const e=await this.getMeta(t);await M(this.getFilePath(e.name)),await this.deleteMeta(t);const r={...e,status:"deleted"};return await this.onDelete(r),r})}async copy(t,e){return this.instrumentOperation("copy",async()=>{w.assertSafeId(t),w.assertSafeId(e);const r=await this.getMeta(t);return await A(this.getFilePath(r.name),this.getFilePath(e)),{...r,name:e}})}async move(t,e){return this.instrumentOperation("move",async()=>{w.assertSafeId(t),w.assertSafeId(e);const r=await this.getMeta(t),a=this.getFilePath(r.name),i=this.getFilePath(e);try{await Q(a,i)}catch(s){if(s?.code==="EXDEV")await A(a,i),await M(a);else{const o=this.normalizeError(s instanceof Error?s:new Error(String(s)));throw await this.onError(o),s}}return{...r,id:r.id,name:e}})}async list(){return this.instrumentOperation("list",async()=>{const t={followSymlinks:!1,includeDirs:!1,includeFiles:!0,skip:["*.META$"]},e=[],{directory:r}=this,a=s=>s.replaceAll("\\","/"),i=a(r);for await(const s of V(r,t)){const{suffix:o}=this.meta,{path:n}=s;if(!n.includes(o)){const{birthtime:m,ctime:l,mtime:u}=await F(n),d=a(n),E=d.startsWith(i)?d.slice(i.length):d;e.push({createdAt:m||l,id:E,modifiedAt:u})}}return e})}getFilePath(t){return w.assertSafeId(t),X(t)&&g(h.INVALID_FILE_NAME,`Invalid file id: "${t}"`),q(this.directory,t)}lazyWrite(t){return new Promise((e,r)=>{const a=C(this.getFilePath(t.name),{flags:"r+",start:t.start}),i=new nt(t.contentLength||t.size-t.start),s=at(t.checksum,t.checksumAlgorithm),o=!t.checksum,{signal:n}=t,m=()=>{a.close(),i.destroy(),s.destroy()},l=d=>{m(),e([Number.NaN,d])};if(i.on("error",()=>{l(h.FILE_CONFLICT)}),s.on("error",()=>{l(h.CHECKSUM_MISMATCH)}),t.body.on("aborted",()=>{l(o?void 0:h.REQUEST_ABORTED)}),t.body.on("error",d=>{m(),r(d)}),n?.aborted){l(o?void 0:h.REQUEST_ABORTED);return}let u;n&&(u=()=>{m(),a.destroy(),i.destroy(),s.destroy(),t.body.destroy(),e([Number.NaN,o?void 0:h.REQUEST_ABORTED])},n.addEventListener("abort",u,{once:!0})),U(t.body,i,s,a,d=>{if(n&&u&&n.removeEventListener("abort",u),d){if(m(),n?.aborted){e([Number.NaN,o?void 0:h.REQUEST_ABORTED]);return}e([Number.NaN,h.FILE_ERROR]);return}e([t.start+a.bytesWritten])})})}async accessCheck(){await H(this.directory)}}export{w as F,nt as n,at as s};
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { F as File, M as MetaStorage, D as DiskStorageOptions, H as HttpError, d as FileInit, e as FilePart, f as FileQuery, O as OperationOptions, g as FileReturn, i as ERRORS, B as BaseStorage, j as DiskStorageWithChecksumOptions } from "./storage.d-DIav_lF1.js";
|
|
2
|
+
import { Readable } from 'node:stream';
|
|
3
|
+
/**
|
|
4
|
+
* Local disk-based storage implementation.
|
|
5
|
+
* @template TFile The file type used by this storage backend.
|
|
6
|
+
* @remarks
|
|
7
|
+
* ## Error Handling
|
|
8
|
+
* - Filesystem operations throw errors directly (no retry logic)
|
|
9
|
+
* - File not found errors are thrown immediately
|
|
10
|
+
* - Permission errors are propagated as-is
|
|
11
|
+
*
|
|
12
|
+
* ## Retry Behavior
|
|
13
|
+
* - No automatic retries (filesystem operations are typically immediate)
|
|
14
|
+
* - Errors are thrown directly for immediate feedback
|
|
15
|
+
*
|
|
16
|
+
* ## File Paths
|
|
17
|
+
* - Files are stored in the configured directory
|
|
18
|
+
* - Metadata files use the `.META` suffix by default
|
|
19
|
+
* - File paths are resolved relative to the storage directory
|
|
20
|
+
*/
|
|
21
|
+
declare class DiskStorage<TFile extends File = File> extends BaseStorage<TFile> {
|
|
22
|
+
static override readonly name: string;
|
|
23
|
+
override checksumTypes: string[];
|
|
24
|
+
override readonly supportsRange: boolean;
|
|
25
|
+
override get raw(): {
|
|
26
|
+
directory: string;
|
|
27
|
+
};
|
|
28
|
+
directory: string;
|
|
29
|
+
meta: MetaStorage<TFile>;
|
|
30
|
+
constructor(config: DiskStorageOptions<TFile>);
|
|
31
|
+
/**
|
|
32
|
+
* Normalizes errors with disk storage context.
|
|
33
|
+
* @param error The error to normalize.
|
|
34
|
+
* @returns Normalized HTTP error.
|
|
35
|
+
*/
|
|
36
|
+
override normalizeError(error: Error): HttpError;
|
|
37
|
+
/**
|
|
38
|
+
* Creates a new file upload and saves its metadata.
|
|
39
|
+
* @param fileInit File initialization configuration.
|
|
40
|
+
* @returns Promise resolving to the created file object.
|
|
41
|
+
* @throws {Error} If validation fails or file already exists and is completed.
|
|
42
|
+
* @remarks
|
|
43
|
+
* Supports TTL (time-to-live) option in fileInit.
|
|
44
|
+
* Creates the file on disk if it doesn't exist.
|
|
45
|
+
* Returns existing file if it's already completed.
|
|
46
|
+
*/
|
|
47
|
+
create(fileInit: FileInit): Promise<TFile>;
|
|
48
|
+
/**
|
|
49
|
+
* Writes data to a file upload.
|
|
50
|
+
* @param part File part containing data to write, file query, or full file object.
|
|
51
|
+
* @returns Promise resolving to the updated file object.
|
|
52
|
+
* @throws {Error} If file is expired (ERRORS.GONE), locked (ERRORS.FILE_LOCKED), or conflicts occur (ERRORS.FILE_CONFLICT).
|
|
53
|
+
* @remarks
|
|
54
|
+
* Supports chunked uploads with start position.
|
|
55
|
+
* Automatically detects file type from stream on first chunk if contentType is not set.
|
|
56
|
+
* Validates checksum algorithms if provided.
|
|
57
|
+
* Uses file locking to prevent concurrent writes.
|
|
58
|
+
* Updates file status to "completed" when all bytes are written.
|
|
59
|
+
*/
|
|
60
|
+
write(part: FilePart | FileQuery | TFile): Promise<TFile>;
|
|
61
|
+
/**
|
|
62
|
+
* Gets an uploaded file by ID.
|
|
63
|
+
* @param query File query containing the file ID to retrieve.
|
|
64
|
+
* @param query.id File ID to retrieve.
|
|
65
|
+
* @returns Promise resolving to the file data including content buffer.
|
|
66
|
+
* @throws {Error} If the file cannot be found (ERRORS.FILE_NOT_FOUND) or has expired (ERRORS.GONE).
|
|
67
|
+
* @remarks
|
|
68
|
+
* Loads the entire file content into memory as a Buffer.
|
|
69
|
+
* For large files, consider using getStream() instead.
|
|
70
|
+
* Includes ETag (MD5 hash) for content verification.
|
|
71
|
+
*/
|
|
72
|
+
get({ id }: FileQuery, options?: OperationOptions & {
|
|
73
|
+
range?: {
|
|
74
|
+
end?: number;
|
|
75
|
+
start: number;
|
|
76
|
+
};
|
|
77
|
+
}): Promise<FileReturn>;
|
|
78
|
+
/**
|
|
79
|
+
* Checks if a file exists by verifying both metadata and the actual filesystem file.
|
|
80
|
+
* Returns true only if both the metadata and the file exist.
|
|
81
|
+
* @param query File query containing the file ID to check.
|
|
82
|
+
* @returns Promise resolving to true if both metadata and file exist, false otherwise.
|
|
83
|
+
*/
|
|
84
|
+
override exists({ id }: FileQuery): Promise<boolean>;
|
|
85
|
+
/**
|
|
86
|
+
* Gets an uploaded file as a readable stream for efficient large file handling.
|
|
87
|
+
* @param query File query containing the file ID to stream.
|
|
88
|
+
* @param query.id File ID to stream.
|
|
89
|
+
* @returns Promise resolving to an object containing the stream, headers, and size.
|
|
90
|
+
* @throws {UploadError} If the file cannot be found (ERRORS.FILE_NOT_FOUND) or has expired (ERRORS.GONE).
|
|
91
|
+
* @remarks Creates a readable stream directly from the file system for efficient memory usage.
|
|
92
|
+
*/
|
|
93
|
+
override getStream({ id }: FileQuery): Promise<{
|
|
94
|
+
headers?: Record<string, string>;
|
|
95
|
+
size?: number;
|
|
96
|
+
stream: Readable;
|
|
97
|
+
}>;
|
|
98
|
+
/**
|
|
99
|
+
* Deletes an upload and its metadata.
|
|
100
|
+
* @param query File query containing the file ID to delete.
|
|
101
|
+
* @param query.id File ID to delete.
|
|
102
|
+
* @returns Promise resolving to the deleted file object with status: "deleted".
|
|
103
|
+
* @throws {UploadError} If the file metadata cannot be found.
|
|
104
|
+
*/
|
|
105
|
+
delete({ id }: FileQuery): Promise<TFile>;
|
|
106
|
+
/**
|
|
107
|
+
* Copies an upload file to a new location.
|
|
108
|
+
* @param name Source file name/ID.
|
|
109
|
+
* @param destination Destination file name/ID.
|
|
110
|
+
* @returns Promise resolving to the copied file object.
|
|
111
|
+
* @throws {UploadError} If the source file cannot be found.
|
|
112
|
+
*/
|
|
113
|
+
copy(name: string, destination: string): Promise<TFile>;
|
|
114
|
+
/**
|
|
115
|
+
* Moves an upload file to a new location.
|
|
116
|
+
* @param name Source file name/ID.
|
|
117
|
+
* @param destination Destination file name/ID.
|
|
118
|
+
* @returns Promise resolving to the moved file object.
|
|
119
|
+
* @throws {Error} If the source file cannot be found.
|
|
120
|
+
*/
|
|
121
|
+
move(name: string, destination: string): Promise<TFile>;
|
|
122
|
+
/**
|
|
123
|
+
* Retrieves a list of uploaded files.
|
|
124
|
+
* @returns Promise resolving to an array of file metadata objects.
|
|
125
|
+
* @remarks Walks the storage directory and returns all files, excluding metadata files.
|
|
126
|
+
*/
|
|
127
|
+
override list(): Promise<TFile[]>;
|
|
128
|
+
/**
|
|
129
|
+
* Returns the absolute on-disk path for the uploaded file, always rooted at
|
|
130
|
+
* `this.directory`. Absolute inputs and `..` traversals are rejected.
|
|
131
|
+
*/
|
|
132
|
+
protected getFilePath(filename: string): string;
|
|
133
|
+
protected lazyWrite(part: File & FilePart): Promise<[number, ERRORS?]>;
|
|
134
|
+
private accessCheck;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Additionally calculates checksum of the file/range.
|
|
138
|
+
*/
|
|
139
|
+
declare class DiskStorageWithChecksum<TFile extends File = File> extends DiskStorage<TFile> {
|
|
140
|
+
private hashes;
|
|
141
|
+
constructor(config: DiskStorageWithChecksumOptions<TFile>);
|
|
142
|
+
override delete({ id }: FileQuery): Promise<TFile>;
|
|
143
|
+
override write(part: FilePart | FileQuery): Promise<TFile>;
|
|
144
|
+
protected override lazyWrite(part: File & FilePart): Promise<[number, ERRORS?]>;
|
|
145
|
+
}
|
|
146
|
+
export { DiskStorage as D, DiskStorageWithChecksum as a };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { F as Files } from "./files.d-
|
|
1
|
+
import { F as Files } from "./files.d-D8H_ge9Y.js";
|
|
2
2
|
import 'node:stream';
|
|
3
3
|
import 'node:crypto';
|
|
4
4
|
import 'node:http';
|
|
5
5
|
import 'lru-cache';
|
|
6
|
-
import { C as CopyFileInput, D as DeleteFileInput, a as DownloadFileInput, G as GetFileMetadataInput, b as GetFileUrlInput, L as ListFilesInput, S as SignUploadUrlInput, U as UploadFileInput } from "./approval.d-
|
|
6
|
+
import { C as CopyFileInput, D as DeleteFileInput, a as DownloadFileInput, G as GetFileMetadataInput, b as GetFileUrlInput, L as ListFilesInput, S as SignUploadUrlInput, U as UploadFileInput } from "./approval.d-C-d-t94D.js";
|
|
7
7
|
interface CopyFileResult {
|
|
8
8
|
copied: true;
|
|
9
9
|
etag: string | undefined;
|