@supabase/storage-js 2.113.0 → 2.114.0-canary.0
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/dist/index.cjs +34 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +110 -5
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +110 -5
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +34 -9
- package/dist/index.mjs.map +1 -1
- package/dist/umd/supabase.js +1 -1
- package/package.json +1 -1
- package/src/lib/types.ts +90 -0
- package/src/lib/version.ts +1 -1
- package/src/packages/StorageBucketApi.ts +10 -0
- package/src/packages/StorageFileApi.ts +37 -12
package/dist/umd/supabase.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var supabase=(function(e){var t=class extends Error{constructor(e,t=`storage`,n,r){super(e),this.__isStorageError=!0,this.namespace=t,this.name=t===`vectors`?`StorageVectorsError`:`StorageError`,this.status=n,this.statusCode=r}toJSON(){return{name:this.name,message:this.message,status:this.status,statusCode:this.statusCode}}};function n(e){return typeof e==`object`&&!!e&&`__isStorageError`in e}var r=class extends t{constructor(e,t,n,r=`storage`,i){super(e,r,t,n),this.name=r===`vectors`?`StorageVectorsApiError`:`StorageApiError`,this.status=t,this.statusCode=n,this.code=i}toJSON(){return{...super.toJSON(),code:this.code}}},i=class extends t{constructor(e,t,n=`storage`){super(e,n),this.name=n===`vectors`?`StorageVectorsUnknownError`:`StorageUnknownError`,this.originalError=t}},a=class extends t{constructor(e){super(e,`vectors`)}};function o(e){return n(e)&&e.namespace===`vectors`}var s=class extends r{constructor(e,t,n){super(e,t,n,`vectors`)}},c=class extends i{constructor(e,t){super(e,t,`vectors`)}};let l=function(e){return e.InternalError=`InternalError`,e.S3VectorConflictException=`S3VectorConflictException`,e.S3VectorNotFoundException=`S3VectorNotFoundException`,e.S3VectorBucketNotEmpty=`S3VectorBucketNotEmpty`,e.S3VectorMaxBucketsExceeded=`S3VectorMaxBucketsExceeded`,e.S3VectorMaxIndexesExceeded=`S3VectorMaxIndexesExceeded`,e}({});function u(e,t,n){let r={...e},i=t.toLowerCase();for(let e of Object.keys(r))e.toLowerCase()===i&&delete r[e];return r[i]=n,r}function d(e){let t={};for(let[n,r]of Object.entries(e))t[n.toLowerCase()]=r;return t}let f=e=>e?(...t)=>e(...t):(...e)=>fetch(...e),p=e=>{if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)},m=e=>{if(Array.isArray(e))return e.map(e=>m(e));if(typeof e==`function`||e!==Object(e))return e;let t={};return Object.entries(e).forEach(([e,n])=>{let r=e.replace(/([-_][a-z])/gi,e=>e.toUpperCase().replace(/[-_]/g,``));t[r]=m(n)}),t},h=e=>!e||typeof e!=`string`||e.length===0||e.length>100||e.trim()!==e||e.includes(`/`)||e.includes(`\\`)?!1:/^[\w!.\*'() &$@=;:+,?-]+$/.test(e),g=e=>e.split(`/`).map(encodeURIComponent).join(`/`),_=e=>{if(typeof e==`object`&&e){let t=e;if(typeof t.msg==`string`)return t.msg;if(typeof t.message==`string`)return t.message;if(typeof t.error_description==`string`)return t.error_description;if(typeof t.error==`string`)return t.error;if(typeof t.error==`object`&&t.error!==null){let e=t.error;if(typeof e.message==`string`)return e.message}}return JSON.stringify(e)},v=async(e,t,n,a)=>{if(typeof e==`object`&&e&&`json`in e&&typeof e.json==`function`){let n=e,i=parseInt(String(n.status),10);Number.isFinite(i)||(i=500),n.json().then(e=>{let n=e?.statusCode||e?.code||i+``;t(new r(_(e),i,n,a,e?.code))}).catch(()=>{let e=i+``;t(new r(n.statusText||`HTTP ${i} error`,i,e,a))})}else t(new i(_(e),e,a))},y=(e,t,n,r)=>{let i={method:e,headers:t?.headers||{}};if(e===`GET`||e===`HEAD`||!r)return{...i,...n};if(p(r)){let e=t?.headers||{},n;for(let[t,r]of Object.entries(e))t.toLowerCase()===`content-type`&&(n=r);i.headers=u(e,`Content-Type`,n??`application/json`),i.body=JSON.stringify(r)}else i.body=r;return t?.duplex&&(i.duplex=t.duplex),{...i,...n}};async function b(e,t,n,r,i,a,o){return new Promise((s,c)=>{e(n,y(t,r,i,a)).then(e=>{if(!e.ok)throw e;if(r?.noResolveJson)return e;if(o===`vectors`){let t=e.headers.get(`content-type`);if(e.headers.get(`content-length`)===`0`||e.status===204||!t||!t.includes(`application/json`))return{}}return e.json()}).then(e=>s(e)).catch(e=>v(e,c,r,o))})}function x(e=`storage`){return{get:async(t,n,r,i)=>b(t,`GET`,n,r,i,void 0,e),post:async(t,n,r,i,a)=>b(t,`POST`,n,i,a,r,e),put:async(t,n,r,i,a)=>b(t,`PUT`,n,i,a,r,e),head:async(t,n,r,i)=>b(t,`HEAD`,n,{...r,noResolveJson:!0},i,void 0,e),remove:async(t,n,r,i,a)=>b(t,`DELETE`,n,i,a,r,e)}}let{get:S,post:C,put:w,head:T,remove:E}=x(`storage`),D=x(`vectors`);var O=class{constructor(e,t={},n,r=`storage`){this.shouldThrowOnError=!1,this.url=e,this.headers=d(t),this.fetch=f(n),this.namespace=r}throwOnError(){return this.shouldThrowOnError=!0,this}setHeader(e,t){return this.headers=u(this.headers,e,t),this}async handleOperation(e){try{return{data:await e(),error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(n(e))return{data:null,error:e};throw e}}};let k;var A=class{static{k=Symbol.toStringTag}constructor(e,t){this.downloadFn=e,this.shouldThrowOnError=t,this[k]=`StreamDownloadBuilder`,this.promise=null}then(e,t){return this.getPromise().then(e,t)}catch(e){return this.getPromise().catch(e)}finally(e){return this.getPromise().finally(e)}getPromise(){return this.promise||=this.execute(),this.promise}async execute(){try{return{data:(await this.downloadFn()).body,error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(n(e))return{data:null,error:e};throw e}}};let j;var M=class{static{j=Symbol.toStringTag}constructor(e,t){this.downloadFn=e,this.shouldThrowOnError=t,this[j]=`BlobDownloadBuilder`,this.promise=null}asStream(){return new A(this.downloadFn,this.shouldThrowOnError)}then(e,t){return this.getPromise().then(e,t)}catch(e){return this.getPromise().catch(e)}finally(e){return this.getPromise().finally(e)}getPromise(){return this.promise||=this.execute(),this.promise}async execute(){try{return{data:await(await this.downloadFn()).blob(),error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(n(e))return{data:null,error:e};throw e}}};let N={limit:100,offset:0,sortBy:{column:`name`,order:`asc`}},P={cacheControl:`3600`,contentType:`text/plain;charset=UTF-8`,upsert:!1};var F=class extends O{constructor(e,t={},n,r){super(e,t,r,`storage`),this.bucketId=n}async uploadOrUpdate(e,t,n,r){return this.handleOperation(async()=>{let i,a={...P,...r},o={...this.headers,...e===`POST`&&{"x-upsert":String(a.upsert)}},s=a.metadata;if(typeof Blob<`u`&&n instanceof Blob?(i=new FormData,i.append(`cacheControl`,a.cacheControl),s&&i.append(`metadata`,this.encodeMetadata(s)),i.append(``,n)):typeof FormData<`u`&&n instanceof FormData?(i=n,i.has(`cacheControl`)||i.append(`cacheControl`,a.cacheControl),s&&!i.has(`metadata`)&&i.append(`metadata`,this.encodeMetadata(s))):(i=n,o[`cache-control`]=`max-age=${a.cacheControl}`,o[`content-type`]=a.contentType,s&&(o[`x-metadata`]=this.toBase64(this.encodeMetadata(s))),(typeof ReadableStream<`u`&&i instanceof ReadableStream||i&&typeof i==`object`&&`pipe`in i&&typeof i.pipe==`function`)&&!a.duplex&&(a.duplex=`half`)),r?.headers)for(let[e,t]of Object.entries(r.headers))o=u(o,e,t);let c=this._removeEmptyFolders(t),l=this._getFinalPath(c),d=await(e==`PUT`?w:C)(this.fetch,`${this.url}/object/${l}`,i,{headers:o,...a?.duplex?{duplex:a.duplex}:{}});return{path:c,id:d.Id,fullPath:d.Key}})}async upload(e,t,n){return this.uploadOrUpdate(`POST`,e,t,n)}async uploadToSignedUrl(e,t,n,r){let i=this._removeEmptyFolders(e),a=this._getFinalPath(i),o=new URL(this.url+`/object/upload/sign/${a}`);return o.searchParams.set(`token`,t),this.handleOperation(async()=>{let e,t={...P,...r},a={...this.headers,"x-upsert":String(t.upsert)},s=t.metadata;if(typeof Blob<`u`&&n instanceof Blob?(e=new FormData,e.append(`cacheControl`,t.cacheControl),s&&e.append(`metadata`,this.encodeMetadata(s)),e.append(``,n)):typeof FormData<`u`&&n instanceof FormData?(e=n,e.has(`cacheControl`)||e.append(`cacheControl`,t.cacheControl),s&&!e.has(`metadata`)&&e.append(`metadata`,this.encodeMetadata(s))):(e=n,a[`cache-control`]=`max-age=${t.cacheControl}`,a[`content-type`]=t.contentType,s&&(a[`x-metadata`]=this.toBase64(this.encodeMetadata(s))),(typeof ReadableStream<`u`&&e instanceof ReadableStream||e&&typeof e==`object`&&`pipe`in e&&typeof e.pipe==`function`)&&!t.duplex&&(t.duplex=`half`)),r?.headers)for(let[e,t]of Object.entries(r.headers))a=u(a,e,t);return{path:i,fullPath:(await w(this.fetch,o.toString(),e,{headers:a,...t?.duplex?{duplex:t.duplex}:{}})).Key}})}async createSignedUploadUrl(e,n){return this.handleOperation(async()=>{let r=this._getFinalPath(e),i={...this.headers};n?.upsert&&(i[`x-upsert`]=`true`);let a=await C(this.fetch,`${this.url}/object/upload/sign/${r}`,{},{headers:i}),o=new URL(this.url+a.url),s=o.searchParams.get(`token`);if(!s)throw new t(`No token returned by API`);return{signedUrl:o.toString(),path:e,token:s}})}async update(e,t,n){return this.uploadOrUpdate(`PUT`,e,t,n)}async move(e,t,n){return this.handleOperation(async()=>await C(this.fetch,`${this.url}/object/move`,{bucketId:this.bucketId,sourceKey:e,destinationKey:t,destinationBucket:n?.destinationBucket},{headers:this.headers}))}async copy(e,t,n){return this.handleOperation(async()=>({path:(await C(this.fetch,`${this.url}/object/copy`,{bucketId:this.bucketId,sourceKey:e,destinationKey:t,destinationBucket:n?.destinationBucket},{headers:this.headers})).Key}))}async createSignedUrl(e,t,n){return this.handleOperation(async()=>{let r=this._getFinalPath(e),i=typeof n?.transform==`object`&&n.transform!==null&&Object.keys(n.transform).length>0,a=await C(this.fetch,`${this.url}/object/sign/${r}`,{expiresIn:t,...i?{transform:n.transform}:{}},{headers:this.headers}),o=new URLSearchParams;n?.download&&o.set(`download`,n.download===!0?``:n.download),n?.cacheNonce!=null&&o.set(`cacheNonce`,String(n.cacheNonce));let s=o.toString();return{signedUrl:encodeURI(`${this.url}${a.signedURL}${s?`&${s}`:``}`)}})}async createSignedUrls(e,t,n){return this.handleOperation(async()=>{let r=await C(this.fetch,`${this.url}/object/sign/${this.bucketId}`,{expiresIn:t,paths:e},{headers:this.headers}),i=new URLSearchParams;n?.download&&i.set(`download`,n.download===!0?``:n.download),n?.cacheNonce!=null&&i.set(`cacheNonce`,String(n.cacheNonce));let a=i.toString();return r.map(e=>({...e,signedUrl:e.signedURL?encodeURI(`${this.url}${e.signedURL}${a?`&${a}`:``}`):null}))})}download(e,t,n){let r=typeof t?.transform==`object`&&t.transform!==null&&Object.keys(t.transform).length>0?`render/image/authenticated`:`object`,i=new URLSearchParams;t?.transform&&this.applyTransformOptsToQuery(i,t.transform),t?.cacheNonce!=null&&i.set(`cacheNonce`,String(t.cacheNonce));let a=i.toString(),o=this._getFinalPath(e);return new M(()=>S(this.fetch,`${this.url}/${r}/${o}${a?`?${a}`:``}`,{headers:this.headers,noResolveJson:!0},n),this.shouldThrowOnError)}async info(e){let t=this._getFinalPath(e);return this.handleOperation(async()=>m(await S(this.fetch,`${this.url}/object/info/${t}`,{headers:this.headers})))}async exists(e){let t=this._getFinalPath(e);try{return await T(this.fetch,`${this.url}/object/${t}`,{headers:this.headers}),{data:!0,error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(n(e)){let t=e instanceof r?e.status:e instanceof i?e.originalError?.status:void 0;if(t!==void 0&&[400,404].includes(t))return{data:!1,error:e}}throw e}}getPublicUrl(e,t){let n=this._getFinalPath(e),r=new URLSearchParams;t?.download&&r.set(`download`,t.download===!0?``:t.download),t?.transform&&this.applyTransformOptsToQuery(r,t.transform),t?.cacheNonce!=null&&r.set(`cacheNonce`,String(t.cacheNonce));let i=r.toString(),a=typeof t?.transform==`object`&&t.transform!==null&&Object.keys(t.transform).length>0?`render/image`:`object`;return{data:{publicUrl:encodeURI(`${this.url}/${a}/public/${n}`)+(i?`?${i}`:``)}}}async remove(e){return this.handleOperation(async()=>await E(this.fetch,`${this.url}/object/${this.bucketId}`,{prefixes:e},{headers:this.headers}))}async purgeCache(e,t,n){return this.handleOperation(async()=>{let r=g(this._getFinalPath(e)),i=new URLSearchParams;t?.transformations&&i.set(`transformations`,`true`);let a=i.toString();return await E(this.fetch,`${this.url}/cdn/${r}${a?`?${a}`:``}`,{},{headers:this.headers},n)})}async list(e,t,n){return this.handleOperation(async()=>{let r=t?.sortBy?{...N.sortBy,...t.sortBy}:N.sortBy,i={...N,...t,sortBy:r,prefix:e||``};return await C(this.fetch,`${this.url}/object/list/${this.bucketId}`,i,{headers:this.headers},n)})}async listV2(e,t){return this.handleOperation(async()=>{let n={...e};return await C(this.fetch,`${this.url}/object/list-v2/${this.bucketId}`,n,{headers:this.headers},t)})}encodeMetadata(e){return JSON.stringify(e)}toBase64(e){return typeof Buffer<`u`?Buffer.from(e).toString(`base64`):btoa(e)}_getFinalPath(e){return`${this.bucketId}/${e.replace(/^\/+/,``)}`}_removeEmptyFolders(e){return e.replace(/^\/|\/$/g,``).replace(/\/+/g,`/`)}applyTransformOptsToQuery(e,t){return t.width&&e.set(`width`,t.width.toString()),t.height&&e.set(`height`,t.height.toString()),t.resize&&e.set(`resize`,t.resize),t.format&&e.set(`format`,t.format),t.quality&&e.set(`quality`,t.quality.toString()),e}};let I={"X-Client-Info":`storage-js/2.113.0`};var L=class extends O{constructor(e,t={},n,r){let i=new URL(e);r?.useNewHostname&&/supabase\.(co|in|red)$/.test(i.hostname)&&!i.hostname.includes(`storage.supabase.`)&&(i.hostname=i.hostname.replace(`supabase.`,`storage.supabase.`));let a=i.href.replace(/\/$/,``),o={...I,...t};super(a,o,n,`storage`)}async listBuckets(e){return this.handleOperation(async()=>{let t=this.listBucketOptionsToQueryString(e);return await S(this.fetch,`${this.url}/bucket${t}`,{headers:this.headers})})}async getBucket(e){return this.handleOperation(async()=>await S(this.fetch,`${this.url}/bucket/${e}`,{headers:this.headers}))}async createBucket(e,t={public:!1}){return this.handleOperation(async()=>await C(this.fetch,`${this.url}/bucket`,{id:e,name:e,type:t.type,public:t.public,file_size_limit:t.fileSizeLimit,allowed_mime_types:t.allowedMimeTypes},{headers:this.headers}))}async updateBucket(e,t){return this.handleOperation(async()=>await w(this.fetch,`${this.url}/bucket/${e}`,{id:e,name:e,public:t.public,file_size_limit:t.fileSizeLimit,allowed_mime_types:t.allowedMimeTypes},{headers:this.headers}))}async emptyBucket(e){return this.handleOperation(async()=>await C(this.fetch,`${this.url}/bucket/${e}/empty`,{},{headers:this.headers}))}async deleteBucket(e){return this.handleOperation(async()=>await E(this.fetch,`${this.url}/bucket/${e}`,{},{headers:this.headers}))}async purgeBucketCache(e,t,n){return this.handleOperation(async()=>{let r=new URLSearchParams;t?.transformations&&r.set(`transformations`,`true`);let i=r.toString();return await E(this.fetch,`${this.url}/cdn/${g(e)}${i?`?${i}`:``}`,{},{headers:this.headers},n)})}listBucketOptionsToQueryString(e){let t={};return e&&(`limit`in e&&(t.limit=String(e.limit)),`offset`in e&&(t.offset=String(e.offset)),e.search&&(t.search=e.search),e.sortColumn&&(t.sortColumn=e.sortColumn),e.sortOrder&&(t.sortOrder=e.sortOrder)),Object.keys(t).length>0?`?`+new URLSearchParams(t).toString():``}},R=class extends Error{constructor(e,t){super(e),this.name=`IcebergError`,this.status=t.status,this.icebergType=t.icebergType,this.icebergCode=t.icebergCode,this.details=t.details,this.isCommitStateUnknown=t.icebergType===`CommitStateUnknownException`||[500,502,504].includes(t.status)&&t.icebergType?.includes(`CommitState`)===!0}isNotFound(){return this.status===404}isConflict(){return this.status===409}isAuthenticationTimeout(){return this.status===419}};function z(e,t,n){let r=new URL(t,e);if(n)for(let[e,t]of Object.entries(n))t!==void 0&&r.searchParams.set(e,t);return r.toString()}async function B(e){return!e||e.type===`none`?{}:e.type===`bearer`?{Authorization:`Bearer ${e.token}`}:e.type===`header`?{[e.name]:e.value}:e.type===`custom`?await e.getHeaders():{}}function V(e){let t=e.fetchImpl??globalThis.fetch;return{async request({method:n,path:r,query:i,body:a,headers:o}){let s=z(e.baseUrl,r,i),c=await B(e.auth),l=await t(s,{method:n,headers:{...a?{"Content-Type":`application/json`}:{},...c,...o},body:a?JSON.stringify(a):void 0}),u=await l.text(),d=(l.headers.get(`content-type`)||``).includes(`application/json`),f=d&&u?JSON.parse(u):u;if(!l.ok){let e=d?f:void 0,t=e?.error;throw new R(t?.message??`Request failed with status ${l.status}`,{status:l.status,icebergType:t?.type,icebergCode:t?.code,details:e})}return{status:l.status,headers:l.headers,data:f}}}}function H(e){return e.join(``)}var U=class{constructor(e,t=``){this.client=e,this.prefix=t}async listNamespaces(e){let t=e?{parent:H(e.namespace)}:void 0;return(await this.client.request({method:`GET`,path:`${this.prefix}/namespaces`,query:t})).data.namespaces.map(e=>({namespace:e}))}async createNamespace(e,t){let n={namespace:e.namespace,properties:t?.properties};return(await this.client.request({method:`POST`,path:`${this.prefix}/namespaces`,body:n})).data}async dropNamespace(e){await this.client.request({method:`DELETE`,path:`${this.prefix}/namespaces/${H(e.namespace)}`})}async loadNamespaceMetadata(e){return{properties:(await this.client.request({method:`GET`,path:`${this.prefix}/namespaces/${H(e.namespace)}`})).data.properties}}async namespaceExists(e){try{return await this.client.request({method:`HEAD`,path:`${this.prefix}/namespaces/${H(e.namespace)}`}),!0}catch(e){if(e instanceof R&&e.status===404)return!1;throw e}}async createNamespaceIfNotExists(e,t){try{return await this.createNamespace(e,t)}catch(e){if(e instanceof R&&e.status===409)return;throw e}}};function W(e){return e.join(``)}var G=class{constructor(e,t=``,n){this.client=e,this.prefix=t,this.accessDelegation=n}async listTables(e){return(await this.client.request({method:`GET`,path:`${this.prefix}/namespaces/${W(e.namespace)}/tables`})).data.identifiers}async createTable(e,t){let n={};return this.accessDelegation&&(n[`X-Iceberg-Access-Delegation`]=this.accessDelegation),(await this.client.request({method:`POST`,path:`${this.prefix}/namespaces/${W(e.namespace)}/tables`,body:t,headers:n})).data.metadata}async updateTable(e,t){let n=await this.client.request({method:`POST`,path:`${this.prefix}/namespaces/${W(e.namespace)}/tables/${e.name}`,body:t});return{"metadata-location":n.data[`metadata-location`],metadata:n.data.metadata}}async dropTable(e,t){await this.client.request({method:`DELETE`,path:`${this.prefix}/namespaces/${W(e.namespace)}/tables/${e.name}`,query:{purgeRequested:String(t?.purge??!1)}})}async loadTable(e){let t={};return this.accessDelegation&&(t[`X-Iceberg-Access-Delegation`]=this.accessDelegation),(await this.client.request({method:`GET`,path:`${this.prefix}/namespaces/${W(e.namespace)}/tables/${e.name}`,headers:t})).data.metadata}async tableExists(e){let t={};this.accessDelegation&&(t[`X-Iceberg-Access-Delegation`]=this.accessDelegation);try{return await this.client.request({method:`HEAD`,path:`${this.prefix}/namespaces/${W(e.namespace)}/tables/${e.name}`,headers:t}),!0}catch(e){if(e instanceof R&&e.status===404)return!1;throw e}}async createTableIfNotExists(e,t){try{return await this.createTable(e,t)}catch(n){if(n instanceof R&&n.status===409)return await this.loadTable({namespace:e.namespace,name:t.name});throw n}}},K=class{constructor(e){let t=`v1`;e.catalogName&&(t+=`/${e.catalogName}`),this.client=V({baseUrl:e.baseUrl.endsWith(`/`)?e.baseUrl:`${e.baseUrl}/`,auth:e.auth,fetchImpl:e.fetch}),this.accessDelegation=e.accessDelegation?.join(`,`),this.namespaceOps=new U(this.client,t),this.tableOps=new G(this.client,t,this.accessDelegation)}async listNamespaces(e){return this.namespaceOps.listNamespaces(e)}async createNamespace(e,t){return this.namespaceOps.createNamespace(e,t)}async dropNamespace(e){await this.namespaceOps.dropNamespace(e)}async loadNamespaceMetadata(e){return this.namespaceOps.loadNamespaceMetadata(e)}async listTables(e){return this.tableOps.listTables(e)}async createTable(e,t){return this.tableOps.createTable(e,t)}async updateTable(e,t){return this.tableOps.updateTable(e,t)}async dropTable(e,t){await this.tableOps.dropTable(e,t)}async loadTable(e){return this.tableOps.loadTable(e)}async namespaceExists(e){return this.namespaceOps.namespaceExists(e)}async tableExists(e){return this.tableOps.tableExists(e)}async createNamespaceIfNotExists(e,t){return this.namespaceOps.createNamespaceIfNotExists(e,t)}async createTableIfNotExists(e,t){return this.tableOps.createTableIfNotExists(e,t)}},q=class extends O{constructor(e,t={},n){let r=e.replace(/\/$/,``),i={...I,...t};super(r,i,n,`storage`)}async createBucket(e){return this.handleOperation(async()=>await C(this.fetch,`${this.url}/bucket`,{name:e},{headers:this.headers}))}async listBuckets(e){return this.handleOperation(async()=>{let t=new URLSearchParams;e?.limit!==void 0&&t.set(`limit`,e.limit.toString()),e?.offset!==void 0&&t.set(`offset`,e.offset.toString()),e?.sortColumn&&t.set(`sortColumn`,e.sortColumn),e?.sortOrder&&t.set(`sortOrder`,e.sortOrder),e?.search&&t.set(`search`,e.search);let n=t.toString(),r=n?`${this.url}/bucket?${n}`:`${this.url}/bucket`;return await S(this.fetch,r,{headers:this.headers})})}async deleteBucket(e){return this.handleOperation(async()=>await E(this.fetch,`${this.url}/bucket/${e}`,{},{headers:this.headers}))}from(e){if(!h(e))throw new t(`Invalid bucket name: File, folder, and bucket names must follow AWS object key naming guidelines and should avoid the use of any other characters.`);let n=new K({baseUrl:this.url,catalogName:e,auth:{type:`custom`,getHeaders:async()=>this.headers},fetch:this.fetch}),r=this.shouldThrowOnError;return new Proxy(n,{get(e,t){let n=e[t];return typeof n==`function`?async(...t)=>{try{return{data:await n.apply(e,t),error:null}}catch(e){if(r)throw e;return{data:null,error:e}}}:n}})}},J=class extends O{constructor(e,t={},n){let r=e.replace(/\/$/,``),i={...I,"Content-Type":`application/json`,...t};super(r,i,n,`vectors`)}async createIndex(e){return this.handleOperation(async()=>await D.post(this.fetch,`${this.url}/CreateIndex`,e,{headers:this.headers})||{})}async getIndex(e,t){return this.handleOperation(async()=>await D.post(this.fetch,`${this.url}/GetIndex`,{vectorBucketName:e,indexName:t},{headers:this.headers}))}async listIndexes(e){return this.handleOperation(async()=>await D.post(this.fetch,`${this.url}/ListIndexes`,e,{headers:this.headers}))}async deleteIndex(e,t){return this.handleOperation(async()=>await D.post(this.fetch,`${this.url}/DeleteIndex`,{vectorBucketName:e,indexName:t},{headers:this.headers})||{})}},Y=class extends O{constructor(e,t={},n){let r=e.replace(/\/$/,``),i={...I,"Content-Type":`application/json`,...t};super(r,i,n,`vectors`)}async putVectors(e){if(e.vectors.length<1||e.vectors.length>500)throw Error(`Vector batch size must be between 1 and 500 items`);return this.handleOperation(async()=>await D.post(this.fetch,`${this.url}/PutVectors`,e,{headers:this.headers})||{})}async getVectors(e){return this.handleOperation(async()=>await D.post(this.fetch,`${this.url}/GetVectors`,e,{headers:this.headers}))}async listVectors(e){if(e.segmentCount!==void 0){if(e.segmentCount<1||e.segmentCount>16)throw Error(`segmentCount must be between 1 and 16`);if(e.segmentIndex!==void 0&&(e.segmentIndex<0||e.segmentIndex>=e.segmentCount))throw Error(`segmentIndex must be between 0 and ${e.segmentCount-1}`)}return this.handleOperation(async()=>await D.post(this.fetch,`${this.url}/ListVectors`,e,{headers:this.headers}))}async queryVectors(e){return this.handleOperation(async()=>await D.post(this.fetch,`${this.url}/QueryVectors`,e,{headers:this.headers}))}async deleteVectors(e){if(e.keys.length<1||e.keys.length>500)throw Error(`Keys batch size must be between 1 and 500 items`);return this.handleOperation(async()=>await D.post(this.fetch,`${this.url}/DeleteVectors`,e,{headers:this.headers})||{})}},X=class extends O{constructor(e,t={},n){let r=e.replace(/\/$/,``),i={...I,"Content-Type":`application/json`,...t};super(r,i,n,`vectors`)}async createBucket(e){return this.handleOperation(async()=>await D.post(this.fetch,`${this.url}/CreateVectorBucket`,{vectorBucketName:e},{headers:this.headers})||{})}async getBucket(e){return this.handleOperation(async()=>await D.post(this.fetch,`${this.url}/GetVectorBucket`,{vectorBucketName:e},{headers:this.headers}))}async listBuckets(e={}){return this.handleOperation(async()=>await D.post(this.fetch,`${this.url}/ListVectorBuckets`,e,{headers:this.headers}))}async deleteBucket(e){return this.handleOperation(async()=>await D.post(this.fetch,`${this.url}/DeleteVectorBucket`,{vectorBucketName:e},{headers:this.headers})||{})}},Z=class extends X{constructor(e,t={}){super(e,t.headers||{},t.fetch)}from(e){return new Q(this.url,this.headers,e,this.fetch)}async createBucket(e){return super.createBucket(e)}async getBucket(e){return super.getBucket(e)}async listBuckets(e={}){return super.listBuckets(e)}async deleteBucket(e){return super.deleteBucket(e)}},Q=class extends J{constructor(e,t,n,r){super(e,t,r),this.vectorBucketName=n}async createIndex(e){return super.createIndex({...e,vectorBucketName:this.vectorBucketName})}async listIndexes(e={}){return super.listIndexes({...e,vectorBucketName:this.vectorBucketName})}async getIndex(e){return super.getIndex(this.vectorBucketName,e)}async deleteIndex(e){return super.deleteIndex(this.vectorBucketName,e)}index(e){return new $(this.url,this.headers,this.vectorBucketName,e,this.fetch)}},$=class extends Y{constructor(e,t,n,r,i){super(e,t,i),this.vectorBucketName=n,this.indexName=r}async putVectors(e){return super.putVectors({...e,vectorBucketName:this.vectorBucketName,indexName:this.indexName})}async getVectors(e){return super.getVectors({...e,vectorBucketName:this.vectorBucketName,indexName:this.indexName})}async listVectors(e={}){return super.listVectors({...e,vectorBucketName:this.vectorBucketName,indexName:this.indexName})}async queryVectors(e){return super.queryVectors({...e,vectorBucketName:this.vectorBucketName,indexName:this.indexName})}async deleteVectors(e){return super.deleteVectors({...e,vectorBucketName:this.vectorBucketName,indexName:this.indexName})}},ee=class extends L{constructor(e,t={},n,r){super(e,t,n,r)}from(e){return new F(this.url,this.headers,e,this.fetch)}get vectors(){return new Z(this.url+`/vector`,{headers:this.headers,fetch:this.fetch})}get analytics(){return new q(this.url+`/iceberg`,this.headers,this.fetch)}};return e.StorageAnalyticsClient=q,e.StorageApiError=r,e.StorageClient=ee,e.StorageError=t,e.StorageUnknownError=i,e.StorageVectorsApiError=s,e.StorageVectorsClient=Z,e.StorageVectorsError=a,e.StorageVectorsErrorCode=l,e.StorageVectorsUnknownError=c,e.VectorBucketApi=X,e.VectorBucketScope=Q,e.VectorDataApi=Y,e.VectorIndexApi=J,e.VectorIndexScope=$,e.isStorageError=n,e.isStorageVectorsError=o,e})({});
|
|
1
|
+
var supabase=(function(e){var t=class extends Error{constructor(e,t=`storage`,n,r){super(e),this.__isStorageError=!0,this.namespace=t,this.name=t===`vectors`?`StorageVectorsError`:`StorageError`,this.status=n,this.statusCode=r}toJSON(){return{name:this.name,message:this.message,status:this.status,statusCode:this.statusCode}}};function n(e){return typeof e==`object`&&!!e&&`__isStorageError`in e}var r=class extends t{constructor(e,t,n,r=`storage`,i){super(e,r,t,n),this.name=r===`vectors`?`StorageVectorsApiError`:`StorageApiError`,this.status=t,this.statusCode=n,this.code=i}toJSON(){return{...super.toJSON(),code:this.code}}},i=class extends t{constructor(e,t,n=`storage`){super(e,n),this.name=n===`vectors`?`StorageVectorsUnknownError`:`StorageUnknownError`,this.originalError=t}},a=class extends t{constructor(e){super(e,`vectors`)}};function o(e){return n(e)&&e.namespace===`vectors`}var s=class extends r{constructor(e,t,n){super(e,t,n,`vectors`)}},c=class extends i{constructor(e,t){super(e,t,`vectors`)}};let l=function(e){return e.InternalError=`InternalError`,e.S3VectorConflictException=`S3VectorConflictException`,e.S3VectorNotFoundException=`S3VectorNotFoundException`,e.S3VectorBucketNotEmpty=`S3VectorBucketNotEmpty`,e.S3VectorMaxBucketsExceeded=`S3VectorMaxBucketsExceeded`,e.S3VectorMaxIndexesExceeded=`S3VectorMaxIndexesExceeded`,e}({});function u(e,t,n){let r={...e},i=t.toLowerCase();for(let e of Object.keys(r))e.toLowerCase()===i&&delete r[e];return r[i]=n,r}function d(e){let t={};for(let[n,r]of Object.entries(e))t[n.toLowerCase()]=r;return t}let f=e=>e?(...t)=>e(...t):(...e)=>fetch(...e),p=e=>{if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)},m=e=>{if(Array.isArray(e))return e.map(e=>m(e));if(typeof e==`function`||e!==Object(e))return e;let t={};return Object.entries(e).forEach(([e,n])=>{let r=e.replace(/([-_][a-z])/gi,e=>e.toUpperCase().replace(/[-_]/g,``));t[r]=m(n)}),t},h=e=>!e||typeof e!=`string`||e.length===0||e.length>100||e.trim()!==e||e.includes(`/`)||e.includes(`\\`)?!1:/^[\w!.\*'() &$@=;:+,?-]+$/.test(e),g=e=>e.split(`/`).map(encodeURIComponent).join(`/`),_=e=>{if(typeof e==`object`&&e){let t=e;if(typeof t.msg==`string`)return t.msg;if(typeof t.message==`string`)return t.message;if(typeof t.error_description==`string`)return t.error_description;if(typeof t.error==`string`)return t.error;if(typeof t.error==`object`&&t.error!==null){let e=t.error;if(typeof e.message==`string`)return e.message}}return JSON.stringify(e)},v=async(e,t,n,a)=>{if(typeof e==`object`&&e&&`json`in e&&typeof e.json==`function`){let n=e,i=parseInt(String(n.status),10);Number.isFinite(i)||(i=500),n.json().then(e=>{let n=e?.statusCode||e?.code||i+``;t(new r(_(e),i,n,a,e?.code))}).catch(()=>{let e=i+``;t(new r(n.statusText||`HTTP ${i} error`,i,e,a))})}else t(new i(_(e),e,a))},y=(e,t,n,r)=>{let i={method:e,headers:t?.headers||{}};if(e===`GET`||e===`HEAD`||!r)return{...i,...n};if(p(r)){let e=t?.headers||{},n;for(let[t,r]of Object.entries(e))t.toLowerCase()===`content-type`&&(n=r);i.headers=u(e,`Content-Type`,n??`application/json`),i.body=JSON.stringify(r)}else i.body=r;return t?.duplex&&(i.duplex=t.duplex),{...i,...n}};async function b(e,t,n,r,i,a,o){return new Promise((s,c)=>{e(n,y(t,r,i,a)).then(e=>{if(!e.ok)throw e;if(r?.noResolveJson)return e;if(o===`vectors`){let t=e.headers.get(`content-type`);if(e.headers.get(`content-length`)===`0`||e.status===204||!t||!t.includes(`application/json`))return{}}return e.json()}).then(e=>s(e)).catch(e=>v(e,c,r,o))})}function x(e=`storage`){return{get:async(t,n,r,i)=>b(t,`GET`,n,r,i,void 0,e),post:async(t,n,r,i,a)=>b(t,`POST`,n,i,a,r,e),put:async(t,n,r,i,a)=>b(t,`PUT`,n,i,a,r,e),head:async(t,n,r,i)=>b(t,`HEAD`,n,{...r,noResolveJson:!0},i,void 0,e),remove:async(t,n,r,i,a)=>b(t,`DELETE`,n,i,a,r,e)}}let{get:S,post:C,put:w,head:T,remove:E}=x(`storage`),D=x(`vectors`);var O=class{constructor(e,t={},n,r=`storage`){this.shouldThrowOnError=!1,this.url=e,this.headers=d(t),this.fetch=f(n),this.namespace=r}throwOnError(){return this.shouldThrowOnError=!0,this}setHeader(e,t){return this.headers=u(this.headers,e,t),this}async handleOperation(e){try{return{data:await e(),error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(n(e))return{data:null,error:e};throw e}}};let k;var A=class{static{k=Symbol.toStringTag}constructor(e,t){this.downloadFn=e,this.shouldThrowOnError=t,this[k]=`StreamDownloadBuilder`,this.promise=null}then(e,t){return this.getPromise().then(e,t)}catch(e){return this.getPromise().catch(e)}finally(e){return this.getPromise().finally(e)}getPromise(){return this.promise||=this.execute(),this.promise}async execute(){try{return{data:(await this.downloadFn()).body,error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(n(e))return{data:null,error:e};throw e}}};let j;var M=class{static{j=Symbol.toStringTag}constructor(e,t){this.downloadFn=e,this.shouldThrowOnError=t,this[j]=`BlobDownloadBuilder`,this.promise=null}asStream(){return new A(this.downloadFn,this.shouldThrowOnError)}then(e,t){return this.getPromise().then(e,t)}catch(e){return this.getPromise().catch(e)}finally(e){return this.getPromise().finally(e)}getPromise(){return this.promise||=this.execute(),this.promise}async execute(){try{return{data:await(await this.downloadFn()).blob(),error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(n(e))return{data:null,error:e};throw e}}};let N={limit:100,offset:0,sortBy:{column:`name`,order:`asc`}},P={cacheControl:`3600`,contentType:`text/plain;charset=UTF-8`,upsert:!1};var F=class extends O{constructor(e,t={},n,r){super(e,t,r,`storage`),this.bucketId=n}async uploadOrUpdate(e,t,n,r){return this.handleOperation(async()=>{let i,a={...P,...r},o={...this.headers,...e===`POST`&&{"x-upsert":String(a.upsert)}},s=a.metadata;if(typeof Blob<`u`&&n instanceof Blob?(i=new FormData,i.append(`cacheControl`,a.cacheControl),s&&i.append(`metadata`,this.encodeMetadata(s)),i.append(``,n)):typeof FormData<`u`&&n instanceof FormData?(i=n,i.has(`cacheControl`)||i.append(`cacheControl`,a.cacheControl),s&&!i.has(`metadata`)&&i.append(`metadata`,this.encodeMetadata(s))):(i=n,o[`cache-control`]=`max-age=${a.cacheControl}`,o[`content-type`]=a.contentType,s&&(o[`x-metadata`]=this.toBase64(this.encodeMetadata(s))),(typeof ReadableStream<`u`&&i instanceof ReadableStream||i&&typeof i==`object`&&`pipe`in i&&typeof i.pipe==`function`)&&!a.duplex&&(a.duplex=`half`)),r?.headers)for(let[e,t]of Object.entries(r.headers))o=u(o,e,t);let c=this._removeEmptyFolders(t),l=this._getFinalPath(c),d=await(e==`PUT`?w:C)(this.fetch,`${this.url}/object/${l}`,i,{headers:o,...a?.duplex?{duplex:a.duplex}:{}});return{path:c,id:d.Id,fullPath:d.Key}})}async upload(e,t,n){return this.uploadOrUpdate(`POST`,e,t,n)}async uploadToSignedUrl(e,t,n,r){let i=this._removeEmptyFolders(e),a=this._getFinalPath(i),o=new URL(this.url+`/object/upload/sign/${a}`);return o.searchParams.set(`token`,t),this.handleOperation(async()=>{let e,t={...P,...r},a={...this.headers,"x-upsert":String(t.upsert)},s=t.metadata;if(typeof Blob<`u`&&n instanceof Blob?(e=new FormData,e.append(`cacheControl`,t.cacheControl),s&&e.append(`metadata`,this.encodeMetadata(s)),e.append(``,n)):typeof FormData<`u`&&n instanceof FormData?(e=n,e.has(`cacheControl`)||e.append(`cacheControl`,t.cacheControl),s&&!e.has(`metadata`)&&e.append(`metadata`,this.encodeMetadata(s))):(e=n,a[`cache-control`]=`max-age=${t.cacheControl}`,a[`content-type`]=t.contentType,s&&(a[`x-metadata`]=this.toBase64(this.encodeMetadata(s))),(typeof ReadableStream<`u`&&e instanceof ReadableStream||e&&typeof e==`object`&&`pipe`in e&&typeof e.pipe==`function`)&&!t.duplex&&(t.duplex=`half`)),r?.headers)for(let[e,t]of Object.entries(r.headers))a=u(a,e,t);return{path:i,fullPath:(await w(this.fetch,o.toString(),e,{headers:a,...t?.duplex?{duplex:t.duplex}:{}})).Key}})}async createSignedUploadUrl(e,n){return this.handleOperation(async()=>{let r=this._getFinalPath(e),i={...this.headers};n?.upsert&&(i[`x-upsert`]=`true`);let a=await C(this.fetch,`${this.url}/object/upload/sign/${r}`,{},{headers:i}),o=new URL(this.url+a.url),s=o.searchParams.get(`token`);if(!s)throw new t(`No token returned by API`);return{signedUrl:o.toString(),path:e,token:s}})}async update(e,t,n){return this.uploadOrUpdate(`PUT`,e,t,n)}async move(e,t,n){return this.handleOperation(async()=>await C(this.fetch,`${this.url}/object/move`,{bucketId:this.bucketId,sourceKey:e,destinationKey:t,destinationBucket:n?.destinationBucket,sourceVersionId:n?.sourceVersionId},{headers:this.headers}))}async copy(e,t,n){return this.handleOperation(async()=>({path:(await C(this.fetch,`${this.url}/object/copy`,{bucketId:this.bucketId,sourceKey:e,destinationKey:t,destinationBucket:n?.destinationBucket,sourceVersionId:n?.sourceVersionId},{headers:this.headers})).Key}))}async createSignedUrl(e,t,n){return this.handleOperation(async()=>{let r=this._getFinalPath(e),i=typeof n?.transform==`object`&&n.transform!==null&&Object.keys(n.transform).length>0,a=await C(this.fetch,`${this.url}/object/sign/${r}`,{expiresIn:t,...i?{transform:n.transform}:{}},{headers:this.headers}),o=new URLSearchParams;n?.download&&o.set(`download`,n.download===!0?``:n.download),n?.cacheNonce!=null&&o.set(`cacheNonce`,String(n.cacheNonce));let s=o.toString();return{signedUrl:encodeURI(`${this.url}${a.signedURL}${s?`&${s}`:``}`)}})}async createSignedUrls(e,t,n){return this.handleOperation(async()=>{let r=await C(this.fetch,`${this.url}/object/sign/${this.bucketId}`,{expiresIn:t,paths:e},{headers:this.headers}),i=new URLSearchParams;n?.download&&i.set(`download`,n.download===!0?``:n.download),n?.cacheNonce!=null&&i.set(`cacheNonce`,String(n.cacheNonce));let a=i.toString();return r.map(e=>({...e,signedUrl:e.signedURL?encodeURI(`${this.url}${e.signedURL}${a?`&${a}`:``}`):null}))})}download(e,t,n){let r=typeof t?.transform==`object`&&t.transform!==null&&Object.keys(t.transform).length>0?`render/image/authenticated`:`object`,i=new URLSearchParams;t?.transform&&this.applyTransformOptsToQuery(i,t.transform),t?.cacheNonce!=null&&i.set(`cacheNonce`,String(t.cacheNonce)),t?.versionId!=null&&i.set(`versionId`,String(t.versionId));let a=i.toString(),o=this._getFinalPath(e);return new M(()=>S(this.fetch,`${this.url}/${r}/${o}${a?`?${a}`:``}`,{headers:this.headers,noResolveJson:!0},n),this.shouldThrowOnError)}async info(e,t){let n=this._getFinalPath(e),r=new URLSearchParams;t?.versionId!=null&&r.set(`versionId`,String(t.versionId));let i=r.toString();return this.handleOperation(async()=>m(await S(this.fetch,`${this.url}/object/info/${n}${i?`?${i}`:``}`,{headers:this.headers})))}async exists(e){let t=this._getFinalPath(e);try{return await T(this.fetch,`${this.url}/object/${t}`,{headers:this.headers}),{data:!0,error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(n(e)){let t=e instanceof r?e.status:e instanceof i?e.originalError?.status:void 0;if(t!==void 0&&[400,404].includes(t))return{data:!1,error:e}}throw e}}getPublicUrl(e,t){let n=this._getFinalPath(e),r=new URLSearchParams;t?.download&&r.set(`download`,t.download===!0?``:t.download),t?.transform&&this.applyTransformOptsToQuery(r,t.transform),t?.cacheNonce!=null&&r.set(`cacheNonce`,String(t.cacheNonce));let i=r.toString(),a=typeof t?.transform==`object`&&t.transform!==null&&Object.keys(t.transform).length>0?`render/image`:`object`;return{data:{publicUrl:encodeURI(`${this.url}/${a}/public/${n}`)+(i?`?${i}`:``)}}}async remove(e){return this.handleOperation(async()=>await E(this.fetch,`${this.url}/object/${this.bucketId}`,{prefixes:e},{headers:this.headers}))}async purgeCache(e,t,n){return this.handleOperation(async()=>{let r=g(this._getFinalPath(e)),i=new URLSearchParams;t?.transformations&&i.set(`transformations`,`true`);let a=i.toString();return await E(this.fetch,`${this.url}/cdn/${r}${a?`?${a}`:``}`,{},{headers:this.headers},n)})}async list(e,t,n){return this.handleOperation(async()=>{let r=t?.sortBy?{...N.sortBy,...t.sortBy}:N.sortBy,i={...N,...t,sortBy:r,prefix:e||``};return await C(this.fetch,`${this.url}/object/list/${this.bucketId}`,i,{headers:this.headers},n)})}async listV2(e,t){return this.handleOperation(async()=>{let n={...e};return await C(this.fetch,`${this.url}/object/list-v2/${this.bucketId}`,n,{headers:this.headers},t)})}encodeMetadata(e){return JSON.stringify(e)}toBase64(e){return typeof Buffer<`u`?Buffer.from(e).toString(`base64`):btoa(e)}_getFinalPath(e){return`${this.bucketId}/${e.replace(/^\/+/,``)}`}_removeEmptyFolders(e){return e.replace(/^\/|\/$/g,``).replace(/\/+/g,`/`)}applyTransformOptsToQuery(e,t){return t.width&&e.set(`width`,t.width.toString()),t.height&&e.set(`height`,t.height.toString()),t.resize&&e.set(`resize`,t.resize),t.format&&e.set(`format`,t.format),t.quality&&e.set(`quality`,t.quality.toString()),e}};let I={"X-Client-Info":`storage-js/2.114.0-canary.0`};var L=class extends O{constructor(e,t={},n,r){let i=new URL(e);r?.useNewHostname&&/supabase\.(co|in|red)$/.test(i.hostname)&&!i.hostname.includes(`storage.supabase.`)&&(i.hostname=i.hostname.replace(`supabase.`,`storage.supabase.`));let a=i.href.replace(/\/$/,``),o={...I,...t};super(a,o,n,`storage`)}async listBuckets(e){return this.handleOperation(async()=>{let t=this.listBucketOptionsToQueryString(e);return await S(this.fetch,`${this.url}/bucket${t}`,{headers:this.headers})})}async getBucket(e){return this.handleOperation(async()=>await S(this.fetch,`${this.url}/bucket/${e}`,{headers:this.headers}))}async createBucket(e,t={public:!1}){return this.handleOperation(async()=>await C(this.fetch,`${this.url}/bucket`,{id:e,name:e,type:t.type,public:t.public,file_size_limit:t.fileSizeLimit,allowed_mime_types:t.allowedMimeTypes,versioning_status:t.versioningStatus},{headers:this.headers}))}async updateBucket(e,t){return this.handleOperation(async()=>await w(this.fetch,`${this.url}/bucket/${e}`,{id:e,name:e,public:t.public,file_size_limit:t.fileSizeLimit,allowed_mime_types:t.allowedMimeTypes,versioning_status:t.versioningStatus},{headers:this.headers}))}async emptyBucket(e){return this.handleOperation(async()=>await C(this.fetch,`${this.url}/bucket/${e}/empty`,{},{headers:this.headers}))}async deleteBucket(e){return this.handleOperation(async()=>await E(this.fetch,`${this.url}/bucket/${e}`,{},{headers:this.headers}))}async purgeBucketCache(e,t,n){return this.handleOperation(async()=>{let r=new URLSearchParams;t?.transformations&&r.set(`transformations`,`true`);let i=r.toString();return await E(this.fetch,`${this.url}/cdn/${g(e)}${i?`?${i}`:``}`,{},{headers:this.headers},n)})}listBucketOptionsToQueryString(e){let t={};return e&&(`limit`in e&&(t.limit=String(e.limit)),`offset`in e&&(t.offset=String(e.offset)),e.search&&(t.search=e.search),e.sortColumn&&(t.sortColumn=e.sortColumn),e.sortOrder&&(t.sortOrder=e.sortOrder)),Object.keys(t).length>0?`?`+new URLSearchParams(t).toString():``}},R=class extends Error{constructor(e,t){super(e),this.name=`IcebergError`,this.status=t.status,this.icebergType=t.icebergType,this.icebergCode=t.icebergCode,this.details=t.details,this.isCommitStateUnknown=t.icebergType===`CommitStateUnknownException`||[500,502,504].includes(t.status)&&t.icebergType?.includes(`CommitState`)===!0}isNotFound(){return this.status===404}isConflict(){return this.status===409}isAuthenticationTimeout(){return this.status===419}};function z(e,t,n){let r=new URL(t,e);if(n)for(let[e,t]of Object.entries(n))t!==void 0&&r.searchParams.set(e,t);return r.toString()}async function B(e){return!e||e.type===`none`?{}:e.type===`bearer`?{Authorization:`Bearer ${e.token}`}:e.type===`header`?{[e.name]:e.value}:e.type===`custom`?await e.getHeaders():{}}function V(e){let t=e.fetchImpl??globalThis.fetch;return{async request({method:n,path:r,query:i,body:a,headers:o}){let s=z(e.baseUrl,r,i),c=await B(e.auth),l=await t(s,{method:n,headers:{...a?{"Content-Type":`application/json`}:{},...c,...o},body:a?JSON.stringify(a):void 0}),u=await l.text(),d=(l.headers.get(`content-type`)||``).includes(`application/json`),f=d&&u?JSON.parse(u):u;if(!l.ok){let e=d?f:void 0,t=e?.error;throw new R(t?.message??`Request failed with status ${l.status}`,{status:l.status,icebergType:t?.type,icebergCode:t?.code,details:e})}return{status:l.status,headers:l.headers,data:f}}}}function H(e){return e.join(``)}var U=class{constructor(e,t=``){this.client=e,this.prefix=t}async listNamespaces(e){let t=e?{parent:H(e.namespace)}:void 0;return(await this.client.request({method:`GET`,path:`${this.prefix}/namespaces`,query:t})).data.namespaces.map(e=>({namespace:e}))}async createNamespace(e,t){let n={namespace:e.namespace,properties:t?.properties};return(await this.client.request({method:`POST`,path:`${this.prefix}/namespaces`,body:n})).data}async dropNamespace(e){await this.client.request({method:`DELETE`,path:`${this.prefix}/namespaces/${H(e.namespace)}`})}async loadNamespaceMetadata(e){return{properties:(await this.client.request({method:`GET`,path:`${this.prefix}/namespaces/${H(e.namespace)}`})).data.properties}}async namespaceExists(e){try{return await this.client.request({method:`HEAD`,path:`${this.prefix}/namespaces/${H(e.namespace)}`}),!0}catch(e){if(e instanceof R&&e.status===404)return!1;throw e}}async createNamespaceIfNotExists(e,t){try{return await this.createNamespace(e,t)}catch(e){if(e instanceof R&&e.status===409)return;throw e}}};function W(e){return e.join(``)}var G=class{constructor(e,t=``,n){this.client=e,this.prefix=t,this.accessDelegation=n}async listTables(e){return(await this.client.request({method:`GET`,path:`${this.prefix}/namespaces/${W(e.namespace)}/tables`})).data.identifiers}async createTable(e,t){let n={};return this.accessDelegation&&(n[`X-Iceberg-Access-Delegation`]=this.accessDelegation),(await this.client.request({method:`POST`,path:`${this.prefix}/namespaces/${W(e.namespace)}/tables`,body:t,headers:n})).data.metadata}async updateTable(e,t){let n=await this.client.request({method:`POST`,path:`${this.prefix}/namespaces/${W(e.namespace)}/tables/${e.name}`,body:t});return{"metadata-location":n.data[`metadata-location`],metadata:n.data.metadata}}async dropTable(e,t){await this.client.request({method:`DELETE`,path:`${this.prefix}/namespaces/${W(e.namespace)}/tables/${e.name}`,query:{purgeRequested:String(t?.purge??!1)}})}async loadTable(e){let t={};return this.accessDelegation&&(t[`X-Iceberg-Access-Delegation`]=this.accessDelegation),(await this.client.request({method:`GET`,path:`${this.prefix}/namespaces/${W(e.namespace)}/tables/${e.name}`,headers:t})).data.metadata}async tableExists(e){let t={};this.accessDelegation&&(t[`X-Iceberg-Access-Delegation`]=this.accessDelegation);try{return await this.client.request({method:`HEAD`,path:`${this.prefix}/namespaces/${W(e.namespace)}/tables/${e.name}`,headers:t}),!0}catch(e){if(e instanceof R&&e.status===404)return!1;throw e}}async createTableIfNotExists(e,t){try{return await this.createTable(e,t)}catch(n){if(n instanceof R&&n.status===409)return await this.loadTable({namespace:e.namespace,name:t.name});throw n}}},K=class{constructor(e){let t=`v1`;e.catalogName&&(t+=`/${e.catalogName}`),this.client=V({baseUrl:e.baseUrl.endsWith(`/`)?e.baseUrl:`${e.baseUrl}/`,auth:e.auth,fetchImpl:e.fetch}),this.accessDelegation=e.accessDelegation?.join(`,`),this.namespaceOps=new U(this.client,t),this.tableOps=new G(this.client,t,this.accessDelegation)}async listNamespaces(e){return this.namespaceOps.listNamespaces(e)}async createNamespace(e,t){return this.namespaceOps.createNamespace(e,t)}async dropNamespace(e){await this.namespaceOps.dropNamespace(e)}async loadNamespaceMetadata(e){return this.namespaceOps.loadNamespaceMetadata(e)}async listTables(e){return this.tableOps.listTables(e)}async createTable(e,t){return this.tableOps.createTable(e,t)}async updateTable(e,t){return this.tableOps.updateTable(e,t)}async dropTable(e,t){await this.tableOps.dropTable(e,t)}async loadTable(e){return this.tableOps.loadTable(e)}async namespaceExists(e){return this.namespaceOps.namespaceExists(e)}async tableExists(e){return this.tableOps.tableExists(e)}async createNamespaceIfNotExists(e,t){return this.namespaceOps.createNamespaceIfNotExists(e,t)}async createTableIfNotExists(e,t){return this.tableOps.createTableIfNotExists(e,t)}},q=class extends O{constructor(e,t={},n){let r=e.replace(/\/$/,``),i={...I,...t};super(r,i,n,`storage`)}async createBucket(e){return this.handleOperation(async()=>await C(this.fetch,`${this.url}/bucket`,{name:e},{headers:this.headers}))}async listBuckets(e){return this.handleOperation(async()=>{let t=new URLSearchParams;e?.limit!==void 0&&t.set(`limit`,e.limit.toString()),e?.offset!==void 0&&t.set(`offset`,e.offset.toString()),e?.sortColumn&&t.set(`sortColumn`,e.sortColumn),e?.sortOrder&&t.set(`sortOrder`,e.sortOrder),e?.search&&t.set(`search`,e.search);let n=t.toString(),r=n?`${this.url}/bucket?${n}`:`${this.url}/bucket`;return await S(this.fetch,r,{headers:this.headers})})}async deleteBucket(e){return this.handleOperation(async()=>await E(this.fetch,`${this.url}/bucket/${e}`,{},{headers:this.headers}))}from(e){if(!h(e))throw new t(`Invalid bucket name: File, folder, and bucket names must follow AWS object key naming guidelines and should avoid the use of any other characters.`);let n=new K({baseUrl:this.url,catalogName:e,auth:{type:`custom`,getHeaders:async()=>this.headers},fetch:this.fetch}),r=this.shouldThrowOnError;return new Proxy(n,{get(e,t){let n=e[t];return typeof n==`function`?async(...t)=>{try{return{data:await n.apply(e,t),error:null}}catch(e){if(r)throw e;return{data:null,error:e}}}:n}})}},J=class extends O{constructor(e,t={},n){let r=e.replace(/\/$/,``),i={...I,"Content-Type":`application/json`,...t};super(r,i,n,`vectors`)}async createIndex(e){return this.handleOperation(async()=>await D.post(this.fetch,`${this.url}/CreateIndex`,e,{headers:this.headers})||{})}async getIndex(e,t){return this.handleOperation(async()=>await D.post(this.fetch,`${this.url}/GetIndex`,{vectorBucketName:e,indexName:t},{headers:this.headers}))}async listIndexes(e){return this.handleOperation(async()=>await D.post(this.fetch,`${this.url}/ListIndexes`,e,{headers:this.headers}))}async deleteIndex(e,t){return this.handleOperation(async()=>await D.post(this.fetch,`${this.url}/DeleteIndex`,{vectorBucketName:e,indexName:t},{headers:this.headers})||{})}},Y=class extends O{constructor(e,t={},n){let r=e.replace(/\/$/,``),i={...I,"Content-Type":`application/json`,...t};super(r,i,n,`vectors`)}async putVectors(e){if(e.vectors.length<1||e.vectors.length>500)throw Error(`Vector batch size must be between 1 and 500 items`);return this.handleOperation(async()=>await D.post(this.fetch,`${this.url}/PutVectors`,e,{headers:this.headers})||{})}async getVectors(e){return this.handleOperation(async()=>await D.post(this.fetch,`${this.url}/GetVectors`,e,{headers:this.headers}))}async listVectors(e){if(e.segmentCount!==void 0){if(e.segmentCount<1||e.segmentCount>16)throw Error(`segmentCount must be between 1 and 16`);if(e.segmentIndex!==void 0&&(e.segmentIndex<0||e.segmentIndex>=e.segmentCount))throw Error(`segmentIndex must be between 0 and ${e.segmentCount-1}`)}return this.handleOperation(async()=>await D.post(this.fetch,`${this.url}/ListVectors`,e,{headers:this.headers}))}async queryVectors(e){return this.handleOperation(async()=>await D.post(this.fetch,`${this.url}/QueryVectors`,e,{headers:this.headers}))}async deleteVectors(e){if(e.keys.length<1||e.keys.length>500)throw Error(`Keys batch size must be between 1 and 500 items`);return this.handleOperation(async()=>await D.post(this.fetch,`${this.url}/DeleteVectors`,e,{headers:this.headers})||{})}},X=class extends O{constructor(e,t={},n){let r=e.replace(/\/$/,``),i={...I,"Content-Type":`application/json`,...t};super(r,i,n,`vectors`)}async createBucket(e){return this.handleOperation(async()=>await D.post(this.fetch,`${this.url}/CreateVectorBucket`,{vectorBucketName:e},{headers:this.headers})||{})}async getBucket(e){return this.handleOperation(async()=>await D.post(this.fetch,`${this.url}/GetVectorBucket`,{vectorBucketName:e},{headers:this.headers}))}async listBuckets(e={}){return this.handleOperation(async()=>await D.post(this.fetch,`${this.url}/ListVectorBuckets`,e,{headers:this.headers}))}async deleteBucket(e){return this.handleOperation(async()=>await D.post(this.fetch,`${this.url}/DeleteVectorBucket`,{vectorBucketName:e},{headers:this.headers})||{})}},Z=class extends X{constructor(e,t={}){super(e,t.headers||{},t.fetch)}from(e){return new Q(this.url,this.headers,e,this.fetch)}async createBucket(e){return super.createBucket(e)}async getBucket(e){return super.getBucket(e)}async listBuckets(e={}){return super.listBuckets(e)}async deleteBucket(e){return super.deleteBucket(e)}},Q=class extends J{constructor(e,t,n,r){super(e,t,r),this.vectorBucketName=n}async createIndex(e){return super.createIndex({...e,vectorBucketName:this.vectorBucketName})}async listIndexes(e={}){return super.listIndexes({...e,vectorBucketName:this.vectorBucketName})}async getIndex(e){return super.getIndex(this.vectorBucketName,e)}async deleteIndex(e){return super.deleteIndex(this.vectorBucketName,e)}index(e){return new $(this.url,this.headers,this.vectorBucketName,e,this.fetch)}},$=class extends Y{constructor(e,t,n,r,i){super(e,t,i),this.vectorBucketName=n,this.indexName=r}async putVectors(e){return super.putVectors({...e,vectorBucketName:this.vectorBucketName,indexName:this.indexName})}async getVectors(e){return super.getVectors({...e,vectorBucketName:this.vectorBucketName,indexName:this.indexName})}async listVectors(e={}){return super.listVectors({...e,vectorBucketName:this.vectorBucketName,indexName:this.indexName})}async queryVectors(e){return super.queryVectors({...e,vectorBucketName:this.vectorBucketName,indexName:this.indexName})}async deleteVectors(e){return super.deleteVectors({...e,vectorBucketName:this.vectorBucketName,indexName:this.indexName})}},ee=class extends L{constructor(e,t={},n,r){super(e,t,n,r)}from(e){return new F(this.url,this.headers,e,this.fetch)}get vectors(){return new Z(this.url+`/vector`,{headers:this.headers,fetch:this.fetch})}get analytics(){return new q(this.url+`/iceberg`,this.headers,this.fetch)}};return e.StorageAnalyticsClient=q,e.StorageApiError=r,e.StorageClient=ee,e.StorageError=t,e.StorageUnknownError=i,e.StorageVectorsApiError=s,e.StorageVectorsClient=Z,e.StorageVectorsError=a,e.StorageVectorsErrorCode=l,e.StorageVectorsUnknownError=c,e.VectorBucketApi=X,e.VectorBucketScope=Q,e.VectorDataApi=Y,e.VectorIndexApi=J,e.VectorIndexScope=$,e.isStorageError=n,e.isStorageVectorsError=o,e})({});
|
package/package.json
CHANGED
package/src/lib/types.ts
CHANGED
|
@@ -7,6 +7,29 @@ import { StorageError } from './common/errors'
|
|
|
7
7
|
*/
|
|
8
8
|
export type BucketType = 'STANDARD' | 'ANALYTICS' | (string & {})
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Bucket-level object versioning status, as reported by the API.
|
|
12
|
+
* - DISABLED: versioning has never been enabled for the bucket (the implicit starting state)
|
|
13
|
+
* - ENABLED: new object writes create new versions
|
|
14
|
+
* - SUSPENDED: versioning was enabled, then suspended
|
|
15
|
+
*/
|
|
16
|
+
export type VersioningStatus = 'DISABLED' | 'ENABLED' | 'SUSPENDED'
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Bucket-level object versioning status that can be set via `createBucket`.
|
|
20
|
+
* `SUSPENDED` is excluded: it only makes sense for a bucket that has already
|
|
21
|
+
* had versioning enabled at some point - a brand-new bucket with no history
|
|
22
|
+
* should just start `DISABLED` instead.
|
|
23
|
+
*/
|
|
24
|
+
export type CreateSettableVersioningStatus = Exclude<VersioningStatus, 'SUSPENDED'>
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Bucket-level object versioning status that can be set via `updateBucket`.
|
|
28
|
+
* `DISABLED` is excluded: it's never a legal destination, since there's no
|
|
29
|
+
* transition back to it once versioning has been touched.
|
|
30
|
+
*/
|
|
31
|
+
export type UpdateSettableVersioningStatus = Exclude<VersioningStatus, 'DISABLED'>
|
|
32
|
+
|
|
10
33
|
export interface Bucket {
|
|
11
34
|
id: string
|
|
12
35
|
type?: BucketType
|
|
@@ -17,6 +40,7 @@ export interface Bucket {
|
|
|
17
40
|
created_at: string
|
|
18
41
|
updated_at: string
|
|
19
42
|
public: boolean
|
|
43
|
+
versioning_status?: VersioningStatus
|
|
20
44
|
}
|
|
21
45
|
|
|
22
46
|
export interface ListBucketOptions {
|
|
@@ -110,6 +134,14 @@ export interface FileObject {
|
|
|
110
134
|
* This field should not be relied upon.
|
|
111
135
|
*/
|
|
112
136
|
buckets?: Bucket
|
|
137
|
+
/** Version identifier for this object (null for folders, omitted on older schemas) */
|
|
138
|
+
version?: string | null
|
|
139
|
+
/** Timestamp at which this version was archived */
|
|
140
|
+
archived_at?: string | null
|
|
141
|
+
/** Whether this entry is a delete marker rather than a real object version (null for folders, omitted on older schemas) */
|
|
142
|
+
is_delete_marker?: boolean | null
|
|
143
|
+
/** Whether this object was created while the bucket had versioning enabled (null for folders, omitted on older schemas) */
|
|
144
|
+
is_versioned?: boolean | null
|
|
113
145
|
}
|
|
114
146
|
|
|
115
147
|
/**
|
|
@@ -144,6 +176,12 @@ export interface FileObjectV2 {
|
|
|
144
176
|
* This field may not be present in responses.
|
|
145
177
|
*/
|
|
146
178
|
updated_at?: string
|
|
179
|
+
/** Timestamp at which this version was archived */
|
|
180
|
+
archived_at?: string | null
|
|
181
|
+
/** Whether this entry is a delete marker rather than a real object version */
|
|
182
|
+
is_delete_marker?: boolean
|
|
183
|
+
/** Whether this object was created while the bucket had versioning enabled */
|
|
184
|
+
is_versioned?: boolean
|
|
147
185
|
}
|
|
148
186
|
|
|
149
187
|
export interface SortBy {
|
|
@@ -180,8 +218,18 @@ export interface FileOptions {
|
|
|
180
218
|
headers?: Record<string, string>
|
|
181
219
|
}
|
|
182
220
|
|
|
221
|
+
/**
|
|
222
|
+
* An entry for `remove()`. Either a plain path (deletes whichever row is currently
|
|
223
|
+
* at that path), or an object targeting an exact `(path, versionId)`
|
|
224
|
+
*/
|
|
225
|
+
export type DeleteObjectEntry = string | { path: string; versionId: string }
|
|
226
|
+
|
|
183
227
|
export interface DestinationOptions {
|
|
184
228
|
destinationBucket?: string
|
|
229
|
+
/**
|
|
230
|
+
* The version id of the source object to move/restore.
|
|
231
|
+
*/
|
|
232
|
+
sourceVersionId?: string
|
|
185
233
|
}
|
|
186
234
|
|
|
187
235
|
export interface SearchOptions {
|
|
@@ -205,6 +253,23 @@ export interface SearchOptions {
|
|
|
205
253
|
* The search string to filter files by.
|
|
206
254
|
*/
|
|
207
255
|
search?: string
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Controls whether noncurrent object versions are included in the results.
|
|
259
|
+
* @default 'exclude'
|
|
260
|
+
*/
|
|
261
|
+
noncurrentVersions?: 'exclude' | 'include' | 'only'
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Controls whether delete markers are included in the results.
|
|
265
|
+
* @default 'exclude'
|
|
266
|
+
*/
|
|
267
|
+
deleteMarkers?: 'exclude' | 'include' | 'only'
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* When true, only returns objects whose key exactly matches the given prefix.
|
|
271
|
+
*/
|
|
272
|
+
exactMatch?: boolean
|
|
208
273
|
}
|
|
209
274
|
|
|
210
275
|
export interface SortByV2 {
|
|
@@ -245,6 +310,23 @@ export interface SearchV2Options {
|
|
|
245
310
|
* @default 'name asc'
|
|
246
311
|
*/
|
|
247
312
|
sortBy?: SortByV2
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Controls whether noncurrent object versions are included in the results.
|
|
316
|
+
* @default 'exclude'
|
|
317
|
+
*/
|
|
318
|
+
noncurrentVersions?: 'exclude' | 'include' | 'only'
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Controls whether delete markers are included in the results.
|
|
322
|
+
* @default 'exclude'
|
|
323
|
+
*/
|
|
324
|
+
deleteMarkers?: 'exclude' | 'include' | 'only'
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* When true, only returns objects whose key exactly matches the given prefix.
|
|
328
|
+
*/
|
|
329
|
+
exactMatch?: boolean
|
|
248
330
|
}
|
|
249
331
|
|
|
250
332
|
/**
|
|
@@ -267,6 +349,14 @@ export interface SearchV2Object {
|
|
|
267
349
|
metadata: FileMetadata | null
|
|
268
350
|
/** @deprecated Last access timestamp */
|
|
269
351
|
last_accessed_at: string
|
|
352
|
+
/** Version identifier for this object */
|
|
353
|
+
version?: string
|
|
354
|
+
/** Timestamp at which this version was archived */
|
|
355
|
+
archived_at?: string | null
|
|
356
|
+
/** Whether this entry is a delete marker rather than a real object version */
|
|
357
|
+
is_delete_marker?: boolean
|
|
358
|
+
/** Whether this object was created while the bucket had versioning enabled */
|
|
359
|
+
is_versioned?: boolean
|
|
270
360
|
}
|
|
271
361
|
|
|
272
362
|
/**
|
package/src/lib/version.ts
CHANGED
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
// - Debugging and support (identifying which version is running)
|
|
5
5
|
// - Telemetry and logging (version reporting in errors/analytics)
|
|
6
6
|
// - Ensuring build artifacts match the published package version
|
|
7
|
-
export const version = '2.
|
|
7
|
+
export const version = '2.114.0-canary.0'
|
|
@@ -6,9 +6,11 @@ import BaseApiClient from '../lib/common/BaseApiClient'
|
|
|
6
6
|
import {
|
|
7
7
|
Bucket,
|
|
8
8
|
BucketType,
|
|
9
|
+
CreateSettableVersioningStatus,
|
|
9
10
|
FetchParameters,
|
|
10
11
|
ListBucketOptions,
|
|
11
12
|
PurgeCacheOptions,
|
|
13
|
+
UpdateSettableVersioningStatus,
|
|
12
14
|
} from '../lib/types'
|
|
13
15
|
import { StorageClientOptions } from '../StorageClient'
|
|
14
16
|
|
|
@@ -163,6 +165,8 @@ export default class StorageBucketApi extends BaseApiClient<StorageError> {
|
|
|
163
165
|
* Each mime type specified can be a wildcard, e.g. image/*, or a specific mime type, e.g. image/png.
|
|
164
166
|
* @param options.type (private-beta) specifies the bucket type. see `BucketType` for more details.
|
|
165
167
|
* - default bucket type is `STANDARD`
|
|
168
|
+
* @param options.versioningStatus the bucket's initial object versioning status.
|
|
169
|
+
* The default value is `DISABLED`
|
|
166
170
|
* @returns Promise with response containing newly created bucket name or error
|
|
167
171
|
*
|
|
168
172
|
* @example Create bucket
|
|
@@ -199,6 +203,7 @@ export default class StorageBucketApi extends BaseApiClient<StorageError> {
|
|
|
199
203
|
fileSizeLimit?: number | string | null
|
|
200
204
|
allowedMimeTypes?: string[] | null
|
|
201
205
|
type?: BucketType
|
|
206
|
+
versioningStatus?: CreateSettableVersioningStatus
|
|
202
207
|
} = {
|
|
203
208
|
public: false,
|
|
204
209
|
}
|
|
@@ -223,6 +228,7 @@ export default class StorageBucketApi extends BaseApiClient<StorageError> {
|
|
|
223
228
|
public: options.public,
|
|
224
229
|
file_size_limit: options.fileSizeLimit,
|
|
225
230
|
allowed_mime_types: options.allowedMimeTypes,
|
|
231
|
+
versioning_status: options.versioningStatus,
|
|
226
232
|
},
|
|
227
233
|
{ headers: this.headers }
|
|
228
234
|
)
|
|
@@ -242,6 +248,8 @@ export default class StorageBucketApi extends BaseApiClient<StorageError> {
|
|
|
242
248
|
* @param options.allowedMimeTypes specifies the allowed mime types that this bucket can accept during upload.
|
|
243
249
|
* The default value is null, which allows files with all mime types to be uploaded.
|
|
244
250
|
* Each mime type specified can be a wildcard, e.g. image/*, or a specific mime type, e.g. image/png.
|
|
251
|
+
* @param options.versioningStatus the bucket's new object versioning status. `DISABLED` is not
|
|
252
|
+
* valid here, there's no transition back to it once versioning has been touched.
|
|
245
253
|
* @returns Promise with response containing success message or error
|
|
246
254
|
*
|
|
247
255
|
* @example Update bucket
|
|
@@ -277,6 +285,7 @@ export default class StorageBucketApi extends BaseApiClient<StorageError> {
|
|
|
277
285
|
public: boolean
|
|
278
286
|
fileSizeLimit?: number | string | null
|
|
279
287
|
allowedMimeTypes?: string[] | null
|
|
288
|
+
versioningStatus?: UpdateSettableVersioningStatus
|
|
280
289
|
}
|
|
281
290
|
): Promise<
|
|
282
291
|
| {
|
|
@@ -298,6 +307,7 @@ export default class StorageBucketApi extends BaseApiClient<StorageError> {
|
|
|
298
307
|
public: options.public,
|
|
299
308
|
file_size_limit: options.fileSizeLimit,
|
|
300
309
|
allowed_mime_types: options.allowedMimeTypes,
|
|
310
|
+
versioning_status: options.versioningStatus,
|
|
301
311
|
},
|
|
302
312
|
{ headers: this.headers }
|
|
303
313
|
)
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
SearchV2Options,
|
|
21
21
|
SearchV2Result,
|
|
22
22
|
PurgeCacheOptions,
|
|
23
|
+
DeleteObjectEntry,
|
|
23
24
|
} from '../lib/types'
|
|
24
25
|
import BlobDownloadBuilder from './BlobDownloadBuilder'
|
|
25
26
|
|
|
@@ -509,6 +510,7 @@ export default class StorageFileApi extends BaseApiClient<StorageError> {
|
|
|
509
510
|
* @param fromPath The original file path, including the current file name. For example `folder/image.png`.
|
|
510
511
|
* @param toPath The new file path, including the new file name. For example `folder/image-new.png`.
|
|
511
512
|
* @param options The destination options.
|
|
513
|
+
* @param options.sourceVersionId The version id of the source object to move.
|
|
512
514
|
* @returns Promise with response containing success message or error
|
|
513
515
|
*
|
|
514
516
|
* @example Move file
|
|
@@ -558,6 +560,7 @@ export default class StorageFileApi extends BaseApiClient<StorageError> {
|
|
|
558
560
|
sourceKey: fromPath,
|
|
559
561
|
destinationKey: toPath,
|
|
560
562
|
destinationBucket: options?.destinationBucket,
|
|
563
|
+
sourceVersionId: options?.sourceVersionId,
|
|
561
564
|
},
|
|
562
565
|
{ headers: this.headers }
|
|
563
566
|
)
|
|
@@ -572,6 +575,7 @@ export default class StorageFileApi extends BaseApiClient<StorageError> {
|
|
|
572
575
|
* @param fromPath The original file path, including the current file name. For example `folder/image.png`.
|
|
573
576
|
* @param toPath The new file path, including the new file name. For example `folder/image-copy.png`.
|
|
574
577
|
* @param options The destination options.
|
|
578
|
+
* @param options.sourceVersionId The version id of the source object to copy.
|
|
575
579
|
* @returns Promise with response containing copied file path or error
|
|
576
580
|
*
|
|
577
581
|
* @example Copy file
|
|
@@ -621,6 +625,7 @@ export default class StorageFileApi extends BaseApiClient<StorageError> {
|
|
|
621
625
|
sourceKey: fromPath,
|
|
622
626
|
destinationKey: toPath,
|
|
623
627
|
destinationBucket: options?.destinationBucket,
|
|
628
|
+
sourceVersionId: options?.sourceVersionId,
|
|
624
629
|
},
|
|
625
630
|
{ headers: this.headers }
|
|
626
631
|
)
|
|
@@ -834,7 +839,7 @@ export default class StorageFileApi extends BaseApiClient<StorageError> {
|
|
|
834
839
|
* @category Storage
|
|
835
840
|
* @subcategory File Buckets
|
|
836
841
|
* @param path The full path and file name of the file to be downloaded. For example `folder/image.png`.
|
|
837
|
-
* @param options Optional settings: `transform` to transform the asset before serving it to the client,
|
|
842
|
+
* @param options Optional settings: `transform` to transform the asset before serving it to the client, `cacheNonce` to append a cache nonce parameter to the URL to invalidate the cache, and `versionId` to download a specific object version.
|
|
838
843
|
* @param parameters Additional fetch parameters like signal for cancellation. Supports standard fetch options including cache control.
|
|
839
844
|
* @returns BlobDownloadBuilder instance for downloading the file
|
|
840
845
|
*
|
|
@@ -893,11 +898,9 @@ export default class StorageFileApi extends BaseApiClient<StorageError> {
|
|
|
893
898
|
* - `objects` table permissions: `select`
|
|
894
899
|
* - Refer to the [Storage guide](/docs/guides/storage/security/access-control) on how access control works
|
|
895
900
|
*/
|
|
896
|
-
download<
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
parameters?: FetchParameters
|
|
900
|
-
): BlobDownloadBuilder {
|
|
901
|
+
download<
|
|
902
|
+
Options extends { transform?: TransformOptions; cacheNonce?: string; versionId?: string },
|
|
903
|
+
>(path: string, options?: Options, parameters?: FetchParameters): BlobDownloadBuilder {
|
|
901
904
|
const wantsTransformation =
|
|
902
905
|
typeof options?.transform === 'object' &&
|
|
903
906
|
options.transform !== null &&
|
|
@@ -907,6 +910,7 @@ export default class StorageFileApi extends BaseApiClient<StorageError> {
|
|
|
907
910
|
const query = new URLSearchParams()
|
|
908
911
|
if (options?.transform) this.applyTransformOptsToQuery(query, options.transform)
|
|
909
912
|
if (options?.cacheNonce != null) query.set('cacheNonce', String(options.cacheNonce))
|
|
913
|
+
if (options?.versionId != null) query.set('versionId', String(options.versionId))
|
|
910
914
|
const queryString = query.toString()
|
|
911
915
|
|
|
912
916
|
const _path = this._getFinalPath(path)
|
|
@@ -932,6 +936,7 @@ export default class StorageFileApi extends BaseApiClient<StorageError> {
|
|
|
932
936
|
* @category Storage
|
|
933
937
|
* @subcategory File Buckets
|
|
934
938
|
* @param path The file path, including the file name. For example `folder/image.png`.
|
|
939
|
+
* @param options Optional settings, including `versionId` to retrieve a specific object version.
|
|
935
940
|
* @returns Promise with response containing file metadata or error
|
|
936
941
|
*
|
|
937
942
|
* @example Get file info
|
|
@@ -947,7 +952,10 @@ export default class StorageFileApi extends BaseApiClient<StorageError> {
|
|
|
947
952
|
* }
|
|
948
953
|
* ```
|
|
949
954
|
*/
|
|
950
|
-
async info(
|
|
955
|
+
async info(
|
|
956
|
+
path: string,
|
|
957
|
+
options?: { versionId?: string }
|
|
958
|
+
): Promise<
|
|
951
959
|
| {
|
|
952
960
|
data: Camelize<FileObjectV2>
|
|
953
961
|
error: null
|
|
@@ -958,11 +966,18 @@ export default class StorageFileApi extends BaseApiClient<StorageError> {
|
|
|
958
966
|
}
|
|
959
967
|
> {
|
|
960
968
|
const _path = this._getFinalPath(path)
|
|
969
|
+
const query = new URLSearchParams()
|
|
970
|
+
if (options?.versionId != null) query.set('versionId', String(options.versionId))
|
|
971
|
+
const queryString = query.toString()
|
|
961
972
|
|
|
962
973
|
return this.handleOperation(async () => {
|
|
963
|
-
const data = await get(
|
|
964
|
-
|
|
965
|
-
|
|
974
|
+
const data = await get(
|
|
975
|
+
this.fetch,
|
|
976
|
+
`${this.url}/object/info/${_path}${queryString ? `?${queryString}` : ''}`,
|
|
977
|
+
{
|
|
978
|
+
headers: this.headers,
|
|
979
|
+
}
|
|
980
|
+
)
|
|
966
981
|
|
|
967
982
|
return recursiveToCamel(data) as Camelize<FileObjectV2>
|
|
968
983
|
})
|
|
@@ -1122,7 +1137,9 @@ export default class StorageFileApi extends BaseApiClient<StorageError> {
|
|
|
1122
1137
|
*
|
|
1123
1138
|
* @category Storage
|
|
1124
1139
|
* @subcategory File Buckets
|
|
1125
|
-
* @param paths An array of files to delete
|
|
1140
|
+
* @param paths An array of files to delete. Each entry is either a path (deletes whichever
|
|
1141
|
+
* version is currently at that path, e.g. `'folder/image.png'`), or `{ path, versionId }` to
|
|
1142
|
+
* delete an exact version current or archived (e.g. `{ path: 'folder/image.png', versionId: '...' }`).
|
|
1126
1143
|
* @returns Promise with response containing array of deleted file objects or error
|
|
1127
1144
|
*
|
|
1128
1145
|
* @example Delete file
|
|
@@ -1141,13 +1158,21 @@ export default class StorageFileApi extends BaseApiClient<StorageError> {
|
|
|
1141
1158
|
* }
|
|
1142
1159
|
* ```
|
|
1143
1160
|
*
|
|
1161
|
+
* @example Delete a specific object version
|
|
1162
|
+
* ```js
|
|
1163
|
+
* const { data, error } = await supabase
|
|
1164
|
+
* .storage
|
|
1165
|
+
* .from('avatars')
|
|
1166
|
+
* .remove([{ path: 'folder/avatar1.png', versionId: 'noncurrent-version-id' }])
|
|
1167
|
+
* ```
|
|
1168
|
+
*
|
|
1144
1169
|
* @remarks
|
|
1145
1170
|
* - RLS policy permissions required:
|
|
1146
1171
|
* - `buckets` table permissions: none
|
|
1147
1172
|
* - `objects` table permissions: `delete` and `select`
|
|
1148
1173
|
* - Refer to the [Storage guide](/docs/guides/storage/security/access-control) on how access control works
|
|
1149
1174
|
*/
|
|
1150
|
-
async remove(paths:
|
|
1175
|
+
async remove(paths: DeleteObjectEntry[]): Promise<
|
|
1151
1176
|
| {
|
|
1152
1177
|
data: FileObject[]
|
|
1153
1178
|
error: null
|