@supabase/storage-js 2.91.1 → 2.91.2
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 +476 -865
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1441 -1491
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1441 -1491
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +477 -861
- package/dist/index.mjs.map +1 -1
- package/dist/umd/supabase.js +1 -1
- package/package.json +1 -1
- package/src/StorageClient.ts +2 -2
- package/src/index.ts +15 -2
- package/src/lib/common/BaseApiClient.ts +90 -0
- package/src/lib/common/errors.ts +144 -0
- package/src/lib/common/fetch.ts +286 -0
- package/src/lib/{helpers.ts → common/helpers.ts} +71 -17
- package/src/lib/types.ts +304 -1
- package/src/lib/version.ts +1 -1
- package/src/packages/BlobDownloadBuilder.ts +1 -1
- package/src/packages/StorageAnalyticsClient.ts +17 -68
- package/src/packages/StorageBucketApi.ts +25 -109
- package/src/packages/StorageFileApi.ts +44 -172
- package/src/{lib/vectors → packages}/StorageVectorsClient.ts +2 -2
- package/src/packages/StreamDownloadBuilder.ts +1 -1
- package/src/packages/VectorBucketApi.ts +73 -0
- package/src/packages/VectorDataApi.ts +98 -0
- package/src/{lib/vectors → packages}/VectorIndexApi.ts +21 -66
- package/src/lib/errors.ts +0 -43
- package/src/lib/fetch.ts +0 -148
- package/src/lib/index.ts +0 -5
- package/src/lib/vectors/VectorBucketApi.ts +0 -118
- package/src/lib/vectors/VectorDataApi.ts +0 -152
- package/src/lib/vectors/constants.ts +0 -5
- package/src/lib/vectors/errors.ts +0 -78
- package/src/lib/vectors/fetch.ts +0 -218
- package/src/lib/vectors/helpers.ts +0 -79
- package/src/lib/vectors/index.ts +0 -66
- package/src/lib/vectors/types.ts +0 -301
package/dist/umd/supabase.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var supabase=(function(e){var t=class extends Error{constructor(e){super(e),this.__isStorageError=!0,this.name=`StorageError`}};function n(e){return typeof e==`object`&&!!e&&`__isStorageError`in e}var r=class extends t{constructor(e,t,n){super(e),this.name=`StorageApiError`,this.status=t,this.statusCode=n}toJSON(){return{name:this.name,message:this.message,status:this.status,statusCode:this.statusCode}}},i=class extends t{constructor(e,t){super(e),this.name=`StorageUnknownError`,this.originalError=t}};let a=e=>e?(...t)=>e(...t):(...e)=>fetch(...e),o=()=>Response,s=e=>{if(Array.isArray(e))return e.map(e=>s(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]=s(n)}),t},c=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)},l=e=>!e||typeof e!=`string`||e.length===0||e.length>100||e.trim()!==e||e.includes(`/`)||e.includes(`\\`)?!1:/^[\w!.\*'() &$@=;:+,?-]+$/.test(e),u=e=>e.msg||e.message||e.error_description||(typeof e.error==`string`?e.error:e.error?.message)||JSON.stringify(e),d=async(e,t,n)=>{e instanceof await o()&&!n?.noResolveJson?e.json().then(n=>{let i=e.status||500,a=n?.statusCode||i+``;t(new r(u(n),i,a))}).catch(e=>{t(new i(u(e),e))}):t(new i(u(e),e))},f=(e,t,n,r)=>{let i={method:e,headers:t?.headers||{}};return e===`GET`||!r?i:(c(r)?(i.headers={"Content-Type":`application/json`,...t?.headers},i.body=JSON.stringify(r)):i.body=r,t?.duplex&&(i.duplex=t.duplex),{...i,...n})};async function p(e,t,n,r,i,a){return new Promise((o,s)=>{e(n,f(t,r,i,a)).then(e=>{if(!e.ok)throw e;return r?.noResolveJson?e:e.json()}).then(e=>o(e)).catch(e=>d(e,s,r))})}async function m(e,t,n,r){return p(e,`GET`,t,n,r)}async function h(e,t,n,r,i){return p(e,`POST`,t,r,i,n)}async function g(e,t,n,r,i){return p(e,`PUT`,t,r,i,n)}async function ee(e,t,n,r){return p(e,`HEAD`,t,{...n,noResolveJson:!0},r)}async function _(e,t,n,r,i){return p(e,`DELETE`,t,r,i,n)}var v=class{constructor(e,t){this.downloadFn=e,this.shouldThrowOnError=t}then(e,t){return this.execute().then(e,t)}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 y;var te=class{static{y=Symbol.toStringTag}constructor(e,t){this.downloadFn=e,this.shouldThrowOnError=t,this[y]=`BlobDownloadBuilder`,this.promise=null}asStream(){return new v(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 ne={limit:100,offset:0,sortBy:{column:`name`,order:`asc`}},b={cacheControl:`3600`,contentType:`text/plain;charset=UTF-8`,upsert:!1};var x=class{constructor(e,t={},n,r){this.shouldThrowOnError=!1,this.url=e,this.headers=t,this.bucketId=n,this.fetch=a(r)}throwOnError(){return this.shouldThrowOnError=!0,this}async uploadOrUpdate(e,t,r,i){try{let n,a={...b,...i},o={...this.headers,...e===`POST`&&{"x-upsert":String(a.upsert)}},s=a.metadata;typeof Blob<`u`&&r instanceof Blob?(n=new FormData,n.append(`cacheControl`,a.cacheControl),s&&n.append(`metadata`,this.encodeMetadata(s)),n.append(``,r)):typeof FormData<`u`&&r instanceof FormData?(n=r,n.has(`cacheControl`)||n.append(`cacheControl`,a.cacheControl),s&&!n.has(`metadata`)&&n.append(`metadata`,this.encodeMetadata(s))):(n=r,o[`cache-control`]=`max-age=${a.cacheControl}`,o[`content-type`]=a.contentType,s&&(o[`x-metadata`]=this.toBase64(this.encodeMetadata(s))),(typeof ReadableStream<`u`&&n instanceof ReadableStream||n&&typeof n==`object`&&`pipe`in n&&typeof n.pipe==`function`)&&!a.duplex&&(a.duplex=`half`)),i?.headers&&(o={...o,...i.headers});let c=this._removeEmptyFolders(t),l=this._getFinalPath(c),u=await(e==`PUT`?g:h)(this.fetch,`${this.url}/object/${l}`,n,{headers:o,...a?.duplex?{duplex:a.duplex}:{}});return{data:{path:c,id:u.Id,fullPath:u.Key},error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(n(e))return{data:null,error:e};throw e}}async upload(e,t,n){return this.uploadOrUpdate(`POST`,e,t,n)}async uploadToSignedUrl(e,t,r,i){let a=this._removeEmptyFolders(e),o=this._getFinalPath(a),s=new URL(this.url+`/object/upload/sign/${o}`);s.searchParams.set(`token`,t);try{let e,t={upsert:b.upsert,...i},n={...this.headers,"x-upsert":String(t.upsert)};return typeof Blob<`u`&&r instanceof Blob?(e=new FormData,e.append(`cacheControl`,t.cacheControl),e.append(``,r)):typeof FormData<`u`&&r instanceof FormData?(e=r,e.append(`cacheControl`,t.cacheControl)):(e=r,n[`cache-control`]=`max-age=${t.cacheControl}`,n[`content-type`]=t.contentType),{data:{path:a,fullPath:(await g(this.fetch,s.toString(),e,{headers:n})).Key},error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(n(e))return{data:null,error:e};throw e}}async createSignedUploadUrl(e,r){try{let n=this._getFinalPath(e),i={...this.headers};r?.upsert&&(i[`x-upsert`]=`true`);let a=await h(this.fetch,`${this.url}/object/upload/sign/${n}`,{},{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{data:{signedUrl:o.toString(),path:e,token:s},error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(n(e))return{data:null,error:e};throw e}}async update(e,t,n){return this.uploadOrUpdate(`PUT`,e,t,n)}async move(e,t,r){try{return{data:await h(this.fetch,`${this.url}/object/move`,{bucketId:this.bucketId,sourceKey:e,destinationKey:t,destinationBucket:r?.destinationBucket},{headers:this.headers}),error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(n(e))return{data:null,error:e};throw e}}async copy(e,t,r){try{return{data:{path:(await h(this.fetch,`${this.url}/object/copy`,{bucketId:this.bucketId,sourceKey:e,destinationKey:t,destinationBucket:r?.destinationBucket},{headers:this.headers})).Key},error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(n(e))return{data:null,error:e};throw e}}async createSignedUrl(e,t,r){try{let n=this._getFinalPath(e),i=await h(this.fetch,`${this.url}/object/sign/${n}`,{expiresIn:t,...r?.transform?{transform:r.transform}:{}},{headers:this.headers}),a=r?.download?`&download=${r.download===!0?``:r.download}`:``;return i={signedUrl:encodeURI(`${this.url}${i.signedURL}${a}`)},{data:i,error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(n(e))return{data:null,error:e};throw e}}async createSignedUrls(e,t,r){try{let n=await h(this.fetch,`${this.url}/object/sign/${this.bucketId}`,{expiresIn:t,paths:e},{headers:this.headers}),i=r?.download?`&download=${r.download===!0?``:r.download}`:``;return{data:n.map(e=>({...e,signedUrl:e.signedURL?encodeURI(`${this.url}${e.signedURL}${i}`):null})),error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(n(e))return{data:null,error:e};throw e}}download(e,t){let n=t?.transform===void 0?`object`:`render/image/authenticated`,r=this.transformOptsToQueryString(t?.transform||{}),i=r?`?${r}`:``,a=this._getFinalPath(e);return new te(()=>m(this.fetch,`${this.url}/${n}/${a}${i}`,{headers:this.headers,noResolveJson:!0}),this.shouldThrowOnError)}async info(e){let t=this._getFinalPath(e);try{return{data:s(await m(this.fetch,`${this.url}/object/info/${t}`,{headers:this.headers})),error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(n(e))return{data:null,error:e};throw e}}async exists(e){let t=this._getFinalPath(e);try{return await ee(this.fetch,`${this.url}/object/${t}`,{headers:this.headers}),{data:!0,error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(n(e)&&e instanceof i){let t=e.originalError;if([400,404].includes(t?.status))return{data:!1,error:e}}throw e}}getPublicUrl(e,t){let n=this._getFinalPath(e),r=[],i=t?.download?`download=${t.download===!0?``:t.download}`:``;i!==``&&r.push(i);let a=t?.transform===void 0?`object`:`render/image`,o=this.transformOptsToQueryString(t?.transform||{});o!==``&&r.push(o);let s=r.join(`&`);return s!==``&&(s=`?${s}`),{data:{publicUrl:encodeURI(`${this.url}/${a}/public/${n}${s}`)}}}async remove(e){try{return{data:await _(this.fetch,`${this.url}/object/${this.bucketId}`,{prefixes:e},{headers:this.headers}),error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(n(e))return{data:null,error:e};throw e}}async list(e,t,r){try{let n={...ne,...t,prefix:e||``};return{data:await h(this.fetch,`${this.url}/object/list/${this.bucketId}`,n,{headers:this.headers},r),error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(n(e))return{data:null,error:e};throw e}}async listV2(e,t){try{let n={...e};return{data:await h(this.fetch,`${this.url}/object/list-v2/${this.bucketId}`,n,{headers:this.headers},t),error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(n(e))return{data:null,error:e};throw e}}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,`/`)}transformOptsToQueryString(e){let t=[];return e.width&&t.push(`width=${e.width}`),e.height&&t.push(`height=${e.height}`),e.resize&&t.push(`resize=${e.resize}`),e.format&&t.push(`format=${e.format}`),e.quality&&t.push(`quality=${e.quality}`),t.join(`&`)}};let S=`2.91.1`,C={"X-Client-Info":`storage-js/${S}`};var re=class{constructor(e,t={},n,r){this.shouldThrowOnError=!1;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.`)),this.url=i.href.replace(/\/$/,``),this.headers={...C,...t},this.fetch=a(n)}throwOnError(){return this.shouldThrowOnError=!0,this}async listBuckets(e){try{let t=this.listBucketOptionsToQueryString(e);return{data:await m(this.fetch,`${this.url}/bucket${t}`,{headers:this.headers}),error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(n(e))return{data:null,error:e};throw e}}async getBucket(e){try{return{data:await m(this.fetch,`${this.url}/bucket/${e}`,{headers:this.headers}),error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(n(e))return{data:null,error:e};throw e}}async createBucket(e,t={public:!1}){try{return{data:await h(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}),error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(n(e))return{data:null,error:e};throw e}}async updateBucket(e,t){try{return{data:await g(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}),error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(n(e))return{data:null,error:e};throw e}}async emptyBucket(e){try{return{data:await h(this.fetch,`${this.url}/bucket/${e}/empty`,{},{headers:this.headers}),error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(n(e))return{data:null,error:e};throw e}}async deleteBucket(e){try{return{data:await _(this.fetch,`${this.url}/bucket/${e}`,{},{headers:this.headers}),error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(n(e))return{data:null,error:e};throw e}}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():``}},w=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 ie(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 T(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 E(e){let t=e.fetchImpl??globalThis.fetch;return{async request({method:n,path:r,query:i,body:a,headers:o}){let s=ie(e.baseUrl,r,i),c=await T(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 w(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 D(e){return e.join(``)}var O=class{constructor(e,t=``){this.client=e,this.prefix=t}async listNamespaces(e){let t=e?{parent:D(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/${D(e.namespace)}`})}async loadNamespaceMetadata(e){return{properties:(await this.client.request({method:`GET`,path:`${this.prefix}/namespaces/${D(e.namespace)}`})).data.properties}}async namespaceExists(e){try{return await this.client.request({method:`HEAD`,path:`${this.prefix}/namespaces/${D(e.namespace)}`}),!0}catch(e){if(e instanceof w&&e.status===404)return!1;throw e}}async createNamespaceIfNotExists(e,t){try{return await this.createNamespace(e,t)}catch(e){if(e instanceof w&&e.status===409)return;throw e}}};function k(e){return e.join(``)}var A=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/${k(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/${k(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/${k(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/${k(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/${k(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/${k(e.namespace)}/tables/${e.name}`,headers:t}),!0}catch(e){if(e instanceof w&&e.status===404)return!1;throw e}}async createTableIfNotExists(e,t){try{return await this.createTable(e,t)}catch(n){if(n instanceof w&&n.status===409)return await this.loadTable({namespace:e.namespace,name:t.name});throw n}}},ae=class{constructor(e){let t=`v1`;e.catalogName&&(t+=`/${e.catalogName}`),this.client=E({baseUrl:e.baseUrl.endsWith(`/`)?e.baseUrl:`${e.baseUrl}/`,auth:e.auth,fetchImpl:e.fetch}),this.accessDelegation=e.accessDelegation?.join(`,`),this.namespaceOps=new O(this.client,t),this.tableOps=new A(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)}},j=class{constructor(e,t={},n){this.shouldThrowOnError=!1,this.url=e.replace(/\/$/,``),this.headers={...C,...t},this.fetch=a(n)}throwOnError(){return this.shouldThrowOnError=!0,this}async createBucket(e){try{return{data:await h(this.fetch,`${this.url}/bucket`,{name:e},{headers:this.headers}),error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(n(e))return{data:null,error:e};throw e}}async listBuckets(e){try{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{data:await m(this.fetch,r,{headers:this.headers}),error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(n(e))return{data:null,error:e};throw e}}async deleteBucket(e){try{return{data:await _(this.fetch,`${this.url}/bucket/${e}`,{},{headers:this.headers}),error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(n(e))return{data:null,error:e};throw e}}from(e){if(!l(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 ae({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}})}};let M={"X-Client-Info":`storage-js/${S}`,"Content-Type":`application/json`};var N=class extends Error{constructor(e){super(e),this.__isStorageVectorsError=!0,this.name=`StorageVectorsError`}};function P(e){return typeof e==`object`&&!!e&&`__isStorageVectorsError`in e}var F=class extends N{constructor(e,t,n){super(e),this.name=`StorageVectorsApiError`,this.status=t,this.statusCode=n}toJSON(){return{name:this.name,message:this.message,status:this.status,statusCode:this.statusCode}}},I=class extends N{constructor(e,t){super(e),this.name=`StorageVectorsUnknownError`,this.originalError=t}};let L=function(e){return e.InternalError=`InternalError`,e.S3VectorConflictException=`S3VectorConflictException`,e.S3VectorNotFoundException=`S3VectorNotFoundException`,e.S3VectorBucketNotEmpty=`S3VectorBucketNotEmpty`,e.S3VectorMaxBucketsExceeded=`S3VectorMaxBucketsExceeded`,e.S3VectorMaxIndexesExceeded=`S3VectorMaxIndexesExceeded`,e}({}),R=e=>e?(...t)=>e(...t):(...e)=>fetch(...e),z=()=>Response,B=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)},V=e=>Array.from(new Float32Array(e)),H=(e,t)=>{if(t!==void 0&&e.float32.length!==t)throw Error(`Vector dimension mismatch: expected ${t}, got ${e.float32.length}`)},U=e=>e.msg||e.message||e.error_description||e.error||JSON.stringify(e),W=async(e,t,n)=>{if(e&&typeof e==`object`&&`status`in e&&`ok`in e&&typeof e.status==`number`&&!n?.noResolveJson){let n=e.status||500,r=e;if(typeof r.json==`function`)r.json().then(e=>{let r=e?.statusCode||e?.code||n+``;t(new F(U(e),n,r))}).catch(()=>{let e=n+``;t(new F(r.statusText||`HTTP ${n} error`,n,e))});else{let e=n+``;t(new F(r.statusText||`HTTP ${n} error`,n,e))}}else t(new I(U(e),e))},G=(e,t,n,r)=>{let i={method:e,headers:t?.headers||{}};return e===`GET`||!r?i:(B(r)?(i.headers={"Content-Type":`application/json`,...t?.headers},i.body=JSON.stringify(r)):i.body=r,{...i,...n})};async function K(e,t,n,r,i,a){return new Promise((o,s)=>{e(n,G(t,r,i,a)).then(e=>{if(!e.ok)throw e;if(r?.noResolveJson)return e;let t=e.headers.get(`content-type`);return!t||!t.includes(`application/json`)?{}:e.json()}).then(e=>o(e)).catch(e=>W(e,s,r))})}async function q(e,t,n,r,i){return K(e,`POST`,t,r,i,n)}var J=class{constructor(e,t={},n){this.shouldThrowOnError=!1,this.url=e.replace(/\/$/,``),this.headers={...M,...t},this.fetch=R(n)}throwOnError(){return this.shouldThrowOnError=!0,this}async createIndex(e){try{return{data:await q(this.fetch,`${this.url}/CreateIndex`,e,{headers:this.headers})||{},error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(P(e))return{data:null,error:e};throw e}}async getIndex(e,t){try{return{data:await q(this.fetch,`${this.url}/GetIndex`,{vectorBucketName:e,indexName:t},{headers:this.headers}),error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(P(e))return{data:null,error:e};throw e}}async listIndexes(e){try{return{data:await q(this.fetch,`${this.url}/ListIndexes`,e,{headers:this.headers}),error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(P(e))return{data:null,error:e};throw e}}async deleteIndex(e,t){try{return{data:await q(this.fetch,`${this.url}/DeleteIndex`,{vectorBucketName:e,indexName:t},{headers:this.headers})||{},error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(P(e))return{data:null,error:e};throw e}}},Y=class{constructor(e,t={},n){this.shouldThrowOnError=!1,this.url=e.replace(/\/$/,``),this.headers={...M,...t},this.fetch=R(n)}throwOnError(){return this.shouldThrowOnError=!0,this}async putVectors(e){try{if(e.vectors.length<1||e.vectors.length>500)throw Error(`Vector batch size must be between 1 and 500 items`);return{data:await q(this.fetch,`${this.url}/PutVectors`,e,{headers:this.headers})||{},error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(P(e))return{data:null,error:e};throw e}}async getVectors(e){try{return{data:await q(this.fetch,`${this.url}/GetVectors`,e,{headers:this.headers}),error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(P(e))return{data:null,error:e};throw e}}async listVectors(e){try{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{data:await q(this.fetch,`${this.url}/ListVectors`,e,{headers:this.headers}),error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(P(e))return{data:null,error:e};throw e}}async queryVectors(e){try{return{data:await q(this.fetch,`${this.url}/QueryVectors`,e,{headers:this.headers}),error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(P(e))return{data:null,error:e};throw e}}async deleteVectors(e){try{if(e.keys.length<1||e.keys.length>500)throw Error(`Keys batch size must be between 1 and 500 items`);return{data:await q(this.fetch,`${this.url}/DeleteVectors`,e,{headers:this.headers})||{},error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(P(e))return{data:null,error:e};throw e}}},X=class{constructor(e,t={},n){this.shouldThrowOnError=!1,this.url=e.replace(/\/$/,``),this.headers={...M,...t},this.fetch=R(n)}throwOnError(){return this.shouldThrowOnError=!0,this}async createBucket(e){try{return{data:await q(this.fetch,`${this.url}/CreateVectorBucket`,{vectorBucketName:e},{headers:this.headers})||{},error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(P(e))return{data:null,error:e};throw e}}async getBucket(e){try{return{data:await q(this.fetch,`${this.url}/GetVectorBucket`,{vectorBucketName:e},{headers:this.headers}),error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(P(e))return{data:null,error:e};throw e}}async listBuckets(e={}){try{return{data:await q(this.fetch,`${this.url}/ListVectorBuckets`,e,{headers:this.headers}),error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(P(e))return{data:null,error:e};throw e}}async deleteBucket(e){try{return{data:await q(this.fetch,`${this.url}/DeleteVectorBucket`,{vectorBucketName:e},{headers:this.headers})||{},error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(P(e))return{data:null,error:e};throw e}}},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})}},oe=class extends re{constructor(e,t={},n,r){super(e,t,n,r)}from(e){return new x(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 j(this.url+`/iceberg`,this.headers,this.fetch)}};return e.StorageAnalyticsClient=j,e.StorageApiError=r,e.StorageClient=oe,e.StorageError=t,e.StorageUnknownError=i,e.StorageVectorsApiError=F,e.StorageVectorsClient=Z,e.StorageVectorsError=N,e.StorageVectorsErrorCode=L,e.StorageVectorsUnknownError=I,e.VectorBucketApi=X,e.VectorBucketScope=Q,e.VectorDataApi=Y,e.VectorIndexApi=J,e.VectorIndexScope=$,e.isPlainObject=B,e.isStorageError=n,e.isStorageVectorsError=P,e.normalizeToFloat32=V,e.resolveFetch=R,e.resolveResponse=z,e.validateVectorDimension=H,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}};function n(e){return typeof e==`object`&&!!e&&`__isStorageError`in e}var r=class extends t{constructor(e,t,n,r=`storage`){super(e,r,t,n),this.name=r===`vectors`?`StorageVectorsApiError`:`StorageApiError`,this.status=t,this.statusCode=n}toJSON(){return{name:this.name,message:this.message,status:this.status,statusCode:this.statusCode}}},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}({}),u=e=>e?(...t)=>e(...t):(...e)=>fetch(...e),d=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)},f=e=>{if(Array.isArray(e))return e.map(e=>f(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]=f(n)}),t},p=e=>!e||typeof e!=`string`||e.length===0||e.length>100||e.trim()!==e||e.includes(`/`)||e.includes(`\\`)?!1:/^[\w!.\*'() &$@=;:+,?-]+$/.test(e),m=e=>e.msg||e.message||e.error_description||(typeof e.error==`string`?e.error:e.error?.message)||JSON.stringify(e),h=async(e,t,n,a)=>{if(e&&typeof e==`object`&&`status`in e&&`ok`in e&&typeof e.status==`number`&&!n?.noResolveJson){let n=e,i=n.status||500;if(typeof n.json==`function`)n.json().then(e=>{let n=e?.statusCode||e?.code||i+``;t(new r(m(e),i,n,a))}).catch(()=>{if(a===`vectors`){let e=i+``;t(new r(n.statusText||`HTTP ${i} error`,i,e,a))}else{let e=i+``;t(new r(n.statusText||`HTTP ${i} error`,i,e,a))}});else{let e=i+``;t(new r(n.statusText||`HTTP ${i} error`,i,e,a))}}else t(new i(m(e),e,a))},g=(e,t,n,r)=>{let i={method:e,headers:t?.headers||{}};return e===`GET`||e===`HEAD`||!r?{...i,...n}:(d(r)?(i.headers={"Content-Type":`application/json`,...t?.headers},i.body=JSON.stringify(r)):i.body=r,t?.duplex&&(i.duplex=t.duplex),{...i,...n})};async function _(e,t,n,r,i,a,o){return new Promise((s,c)=>{e(n,g(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(!t||!t.includes(`application/json`))return{}}return e.json()}).then(e=>s(e)).catch(e=>h(e,c,r,o))})}function v(e=`storage`){return{get:async(t,n,r,i)=>_(t,`GET`,n,r,i,void 0,e),post:async(t,n,r,i,a)=>_(t,`POST`,n,i,a,r,e),put:async(t,n,r,i,a)=>_(t,`PUT`,n,i,a,r,e),head:async(t,n,r,i)=>_(t,`HEAD`,n,{...r,noResolveJson:!0},i,void 0,e),remove:async(t,n,r,i,a)=>_(t,`DELETE`,n,i,a,r,e)}}let{get:y,post:b,put:x,head:S,remove:C}=v(`storage`);var w=class{constructor(e,t={},n,r=`storage`){this.shouldThrowOnError=!1,this.url=e,this.headers=t,this.fetch=u(n),this.namespace=r}throwOnError(){return this.shouldThrowOnError=!0,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}}},T=class{constructor(e,t){this.downloadFn=e,this.shouldThrowOnError=t}then(e,t){return this.execute().then(e,t)}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 E;var D=class{static{E=Symbol.toStringTag}constructor(e,t){this.downloadFn=e,this.shouldThrowOnError=t,this[E]=`BlobDownloadBuilder`,this.promise=null}asStream(){return new T(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 O={limit:100,offset:0,sortBy:{column:`name`,order:`asc`}},k={cacheControl:`3600`,contentType:`text/plain;charset=UTF-8`,upsert:!1};var A=class extends w{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={...k,...r},o={...this.headers,...e===`POST`&&{"x-upsert":String(a.upsert)}},s=a.metadata;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&&(o={...o,...r.headers});let c=this._removeEmptyFolders(t),l=this._getFinalPath(c),u=await(e==`PUT`?x:b)(this.fetch,`${this.url}/object/${l}`,i,{headers:o,...a?.duplex?{duplex:a.duplex}:{}});return{path:c,id:u.Id,fullPath:u.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={upsert:k.upsert,...r},a={...this.headers,"x-upsert":String(t.upsert)};return typeof Blob<`u`&&n instanceof Blob?(e=new FormData,e.append(`cacheControl`,t.cacheControl),e.append(``,n)):typeof FormData<`u`&&n instanceof FormData?(e=n,e.append(`cacheControl`,t.cacheControl)):(e=n,a[`cache-control`]=`max-age=${t.cacheControl}`,a[`content-type`]=t.contentType),{path:i,fullPath:(await x(this.fetch,o.toString(),e,{headers:a})).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 b(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 b(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 b(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=await b(this.fetch,`${this.url}/object/sign/${r}`,{expiresIn:t,...n?.transform?{transform:n.transform}:{}},{headers:this.headers}),a=n?.download?`&download=${n.download===!0?``:n.download}`:``;return{signedUrl:encodeURI(`${this.url}${i.signedURL}${a}`)}})}async createSignedUrls(e,t,n){return this.handleOperation(async()=>{let r=await b(this.fetch,`${this.url}/object/sign/${this.bucketId}`,{expiresIn:t,paths:e},{headers:this.headers}),i=n?.download?`&download=${n.download===!0?``:n.download}`:``;return r.map(e=>({...e,signedUrl:e.signedURL?encodeURI(`${this.url}${e.signedURL}${i}`):null}))})}download(e,t){let n=t?.transform===void 0?`object`:`render/image/authenticated`,r=this.transformOptsToQueryString(t?.transform||{}),i=r?`?${r}`:``,a=this._getFinalPath(e);return new D(()=>y(this.fetch,`${this.url}/${n}/${a}${i}`,{headers:this.headers,noResolveJson:!0}),this.shouldThrowOnError)}async info(e){let t=this._getFinalPath(e);return this.handleOperation(async()=>f(await y(this.fetch,`${this.url}/object/info/${t}`,{headers:this.headers})))}async exists(e){let t=this._getFinalPath(e);try{return await S(this.fetch,`${this.url}/object/${t}`,{headers:this.headers}),{data:!0,error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(n(e)&&e instanceof i){let t=e.originalError;if([400,404].includes(t?.status))return{data:!1,error:e}}throw e}}getPublicUrl(e,t){let n=this._getFinalPath(e),r=[],i=t?.download?`download=${t.download===!0?``:t.download}`:``;i!==``&&r.push(i);let a=t?.transform===void 0?`object`:`render/image`,o=this.transformOptsToQueryString(t?.transform||{});o!==``&&r.push(o);let s=r.join(`&`);return s!==``&&(s=`?${s}`),{data:{publicUrl:encodeURI(`${this.url}/${a}/public/${n}${s}`)}}}async remove(e){return this.handleOperation(async()=>await C(this.fetch,`${this.url}/object/${this.bucketId}`,{prefixes:e},{headers:this.headers}))}async list(e,t,n){return this.handleOperation(async()=>{let r={...O,...t,prefix:e||``};return await b(this.fetch,`${this.url}/object/list/${this.bucketId}`,r,{headers:this.headers},n)})}async listV2(e,t){return this.handleOperation(async()=>{let n={...e};return await b(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,`/`)}transformOptsToQueryString(e){let t=[];return e.width&&t.push(`width=${e.width}`),e.height&&t.push(`height=${e.height}`),e.resize&&t.push(`resize=${e.resize}`),e.format&&t.push(`format=${e.format}`),e.quality&&t.push(`quality=${e.quality}`),t.join(`&`)}};let j={"X-Client-Info":`storage-js/2.91.2`};var M=class extends w{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={...j,...t};super(a,o,n,`storage`)}async listBuckets(e){return this.handleOperation(async()=>{let t=this.listBucketOptionsToQueryString(e);return await y(this.fetch,`${this.url}/bucket${t}`,{headers:this.headers})})}async getBucket(e){return this.handleOperation(async()=>await y(this.fetch,`${this.url}/bucket/${e}`,{headers:this.headers}))}async createBucket(e,t={public:!1}){return this.handleOperation(async()=>await b(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 x(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 b(this.fetch,`${this.url}/bucket/${e}/empty`,{},{headers:this.headers}))}async deleteBucket(e){return this.handleOperation(async()=>await C(this.fetch,`${this.url}/bucket/${e}`,{},{headers:this.headers}))}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():``}},N=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 P(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 F(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 I(e){let t=e.fetchImpl??globalThis.fetch;return{async request({method:n,path:r,query:i,body:a,headers:o}){let s=P(e.baseUrl,r,i),c=await F(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 N(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 L(e){return e.join(``)}var R=class{constructor(e,t=``){this.client=e,this.prefix=t}async listNamespaces(e){let t=e?{parent:L(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/${L(e.namespace)}`})}async loadNamespaceMetadata(e){return{properties:(await this.client.request({method:`GET`,path:`${this.prefix}/namespaces/${L(e.namespace)}`})).data.properties}}async namespaceExists(e){try{return await this.client.request({method:`HEAD`,path:`${this.prefix}/namespaces/${L(e.namespace)}`}),!0}catch(e){if(e instanceof N&&e.status===404)return!1;throw e}}async createNamespaceIfNotExists(e,t){try{return await this.createNamespace(e,t)}catch(e){if(e instanceof N&&e.status===409)return;throw e}}};function z(e){return e.join(``)}var B=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/${z(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/${z(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/${z(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/${z(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/${z(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/${z(e.namespace)}/tables/${e.name}`,headers:t}),!0}catch(e){if(e instanceof N&&e.status===404)return!1;throw e}}async createTableIfNotExists(e,t){try{return await this.createTable(e,t)}catch(n){if(n instanceof N&&n.status===409)return await this.loadTable({namespace:e.namespace,name:t.name});throw n}}},V=class{constructor(e){let t=`v1`;e.catalogName&&(t+=`/${e.catalogName}`),this.client=I({baseUrl:e.baseUrl.endsWith(`/`)?e.baseUrl:`${e.baseUrl}/`,auth:e.auth,fetchImpl:e.fetch}),this.accessDelegation=e.accessDelegation?.join(`,`),this.namespaceOps=new R(this.client,t),this.tableOps=new B(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)}},H=class extends w{constructor(e,t={},n){let r=e.replace(/\/$/,``),i={...j,...t};super(r,i,n,`storage`)}async createBucket(e){return this.handleOperation(async()=>await b(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 y(this.fetch,r,{headers:this.headers})})}async deleteBucket(e){return this.handleOperation(async()=>await C(this.fetch,`${this.url}/bucket/${e}`,{},{headers:this.headers}))}from(e){if(!p(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 V({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}})}},U=class extends w{constructor(e,t={},n){let r=e.replace(/\/$/,``),i={...j,"Content-Type":`application/json`,...t};super(r,i,n,`vectors`)}async createIndex(e){return this.handleOperation(async()=>await b(this.fetch,`${this.url}/CreateIndex`,e,{headers:this.headers})||{})}async getIndex(e,t){return this.handleOperation(async()=>await b(this.fetch,`${this.url}/GetIndex`,{vectorBucketName:e,indexName:t},{headers:this.headers}))}async listIndexes(e){return this.handleOperation(async()=>await b(this.fetch,`${this.url}/ListIndexes`,e,{headers:this.headers}))}async deleteIndex(e,t){return this.handleOperation(async()=>await b(this.fetch,`${this.url}/DeleteIndex`,{vectorBucketName:e,indexName:t},{headers:this.headers})||{})}},W=class extends w{constructor(e,t={},n){let r=e.replace(/\/$/,``),i={...j,"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 b(this.fetch,`${this.url}/PutVectors`,e,{headers:this.headers})||{})}async getVectors(e){return this.handleOperation(async()=>await b(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 b(this.fetch,`${this.url}/ListVectors`,e,{headers:this.headers}))}async queryVectors(e){return this.handleOperation(async()=>await b(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 b(this.fetch,`${this.url}/DeleteVectors`,e,{headers:this.headers})||{})}},G=class extends w{constructor(e,t={},n){let r=e.replace(/\/$/,``),i={...j,"Content-Type":`application/json`,...t};super(r,i,n,`vectors`)}async createBucket(e){return this.handleOperation(async()=>await b(this.fetch,`${this.url}/CreateVectorBucket`,{vectorBucketName:e},{headers:this.headers})||{})}async getBucket(e){return this.handleOperation(async()=>await b(this.fetch,`${this.url}/GetVectorBucket`,{vectorBucketName:e},{headers:this.headers}))}async listBuckets(e={}){return this.handleOperation(async()=>await b(this.fetch,`${this.url}/ListVectorBuckets`,e,{headers:this.headers}))}async deleteBucket(e){return this.handleOperation(async()=>await b(this.fetch,`${this.url}/DeleteVectorBucket`,{vectorBucketName:e},{headers:this.headers})||{})}},K=class extends G{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 U{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 J(this.url,this.headers,this.vectorBucketName,e,this.fetch)}},J=class extends W{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})}},Y=class extends M{constructor(e,t={},n,r){super(e,t,n,r)}from(e){return new A(this.url,this.headers,e,this.fetch)}get vectors(){return new K(this.url+`/vector`,{headers:this.headers,fetch:this.fetch})}get analytics(){return new H(this.url+`/iceberg`,this.headers,this.fetch)}};return e.StorageAnalyticsClient=H,e.StorageApiError=r,e.StorageClient=Y,e.StorageError=t,e.StorageUnknownError=i,e.StorageVectorsApiError=s,e.StorageVectorsClient=K,e.StorageVectorsError=a,e.StorageVectorsErrorCode=l,e.StorageVectorsUnknownError=c,e.VectorBucketApi=G,e.VectorBucketScope=q,e.VectorDataApi=W,e.VectorIndexApi=U,e.VectorIndexScope=J,e.isStorageError=n,e.isStorageVectorsError=o,e})({});
|
package/package.json
CHANGED
package/src/StorageClient.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import StorageFileApi from './packages/StorageFileApi'
|
|
2
2
|
import StorageBucketApi from './packages/StorageBucketApi'
|
|
3
3
|
import StorageAnalyticsClient from './packages/StorageAnalyticsClient'
|
|
4
|
-
import { Fetch } from './lib/fetch'
|
|
5
|
-
import { StorageVectorsClient } from './
|
|
4
|
+
import { Fetch } from './lib/common/fetch'
|
|
5
|
+
import { StorageVectorsClient } from './packages/StorageVectorsClient'
|
|
6
6
|
|
|
7
7
|
export interface StorageClientOptions {
|
|
8
8
|
useNewHostname?: boolean
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
export { StorageClient } from './StorageClient'
|
|
2
2
|
export type { StorageClientOptions } from './StorageClient'
|
|
3
3
|
export { default as StorageAnalyticsClient } from './packages/StorageAnalyticsClient'
|
|
4
|
+
|
|
5
|
+
// Vector Storage
|
|
6
|
+
export {
|
|
7
|
+
StorageVectorsClient,
|
|
8
|
+
VectorBucketScope,
|
|
9
|
+
VectorIndexScope,
|
|
10
|
+
} from './packages/StorageVectorsClient'
|
|
11
|
+
export type { StorageVectorsClientOptions } from './packages/StorageVectorsClient'
|
|
12
|
+
export { default as VectorBucketApi } from './packages/VectorBucketApi'
|
|
13
|
+
export { default as VectorDataApi } from './packages/VectorDataApi'
|
|
14
|
+
export { default as VectorIndexApi } from './packages/VectorIndexApi'
|
|
15
|
+
export type { CreateIndexOptions } from './packages/VectorIndexApi'
|
|
16
|
+
|
|
17
|
+
// Types and Errors
|
|
4
18
|
export * from './lib/types'
|
|
5
|
-
export * from './lib/errors'
|
|
6
|
-
export * from './lib/vectors'
|
|
19
|
+
export * from './lib/common/errors'
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { ErrorNamespace, isStorageError, StorageError } from './errors'
|
|
2
|
+
import { Fetch } from './fetch'
|
|
3
|
+
import { resolveFetch } from './helpers'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @ignore
|
|
7
|
+
* Base API client class for all Storage API classes
|
|
8
|
+
* Provides common infrastructure for error handling and configuration
|
|
9
|
+
*
|
|
10
|
+
* @typeParam TError - The error type (StorageError or subclass)
|
|
11
|
+
*/
|
|
12
|
+
export default abstract class BaseApiClient<TError extends StorageError = StorageError> {
|
|
13
|
+
protected url: string
|
|
14
|
+
protected headers: { [key: string]: string }
|
|
15
|
+
protected fetch: Fetch
|
|
16
|
+
protected shouldThrowOnError = false
|
|
17
|
+
protected namespace: ErrorNamespace
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new BaseApiClient instance
|
|
21
|
+
* @param url - Base URL for API requests
|
|
22
|
+
* @param headers - Default headers for API requests
|
|
23
|
+
* @param fetch - Optional custom fetch implementation
|
|
24
|
+
* @param namespace - Error namespace ('storage' or 'vectors')
|
|
25
|
+
*/
|
|
26
|
+
constructor(
|
|
27
|
+
url: string,
|
|
28
|
+
headers: { [key: string]: string } = {},
|
|
29
|
+
fetch?: Fetch,
|
|
30
|
+
namespace: ErrorNamespace = 'storage'
|
|
31
|
+
) {
|
|
32
|
+
this.url = url
|
|
33
|
+
this.headers = headers
|
|
34
|
+
this.fetch = resolveFetch(fetch)
|
|
35
|
+
this.namespace = namespace
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Enable throwing errors instead of returning them.
|
|
40
|
+
* When enabled, errors are thrown instead of returned in { data, error } format.
|
|
41
|
+
*
|
|
42
|
+
* @returns this - For method chaining
|
|
43
|
+
*/
|
|
44
|
+
public throwOnError(): this {
|
|
45
|
+
this.shouldThrowOnError = true
|
|
46
|
+
return this
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Handles API operation with standardized error handling
|
|
51
|
+
* Eliminates repetitive try-catch blocks across all API methods
|
|
52
|
+
*
|
|
53
|
+
* This wrapper:
|
|
54
|
+
* 1. Executes the operation
|
|
55
|
+
* 2. Returns { data, error: null } on success
|
|
56
|
+
* 3. Returns { data: null, error } on failure (if shouldThrowOnError is false)
|
|
57
|
+
* 4. Throws error on failure (if shouldThrowOnError is true)
|
|
58
|
+
*
|
|
59
|
+
* @typeParam T - The expected data type from the operation
|
|
60
|
+
* @param operation - Async function that performs the API call
|
|
61
|
+
* @returns Promise with { data, error } tuple
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* async listBuckets() {
|
|
66
|
+
* return this.handleOperation(async () => {
|
|
67
|
+
* return await get(this.fetch, `${this.url}/bucket`, {
|
|
68
|
+
* headers: this.headers,
|
|
69
|
+
* })
|
|
70
|
+
* })
|
|
71
|
+
* }
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
protected async handleOperation<T>(
|
|
75
|
+
operation: () => Promise<T>
|
|
76
|
+
): Promise<{ data: T; error: null } | { data: null; error: TError }> {
|
|
77
|
+
try {
|
|
78
|
+
const data = await operation()
|
|
79
|
+
return { data, error: null }
|
|
80
|
+
} catch (error) {
|
|
81
|
+
if (this.shouldThrowOnError) {
|
|
82
|
+
throw error
|
|
83
|
+
}
|
|
84
|
+
if (isStorageError(error)) {
|
|
85
|
+
return { data: null, error: error as TError }
|
|
86
|
+
}
|
|
87
|
+
throw error
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Namespace type for error classes
|
|
3
|
+
* Determines the error class names and type guards
|
|
4
|
+
*/
|
|
5
|
+
export type ErrorNamespace = 'storage' | 'vectors'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Base error class for all Storage errors
|
|
9
|
+
* Supports both 'storage' and 'vectors' namespaces
|
|
10
|
+
*/
|
|
11
|
+
export class StorageError extends Error {
|
|
12
|
+
protected __isStorageError = true
|
|
13
|
+
protected namespace: ErrorNamespace
|
|
14
|
+
status?: number
|
|
15
|
+
statusCode?: string
|
|
16
|
+
|
|
17
|
+
constructor(
|
|
18
|
+
message: string,
|
|
19
|
+
namespace: ErrorNamespace = 'storage',
|
|
20
|
+
status?: number,
|
|
21
|
+
statusCode?: string
|
|
22
|
+
) {
|
|
23
|
+
super(message)
|
|
24
|
+
this.namespace = namespace
|
|
25
|
+
this.name = namespace === 'vectors' ? 'StorageVectorsError' : 'StorageError'
|
|
26
|
+
this.status = status
|
|
27
|
+
this.statusCode = statusCode
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Type guard to check if an error is a StorageError
|
|
33
|
+
* @param error - The error to check
|
|
34
|
+
* @returns True if the error is a StorageError
|
|
35
|
+
*/
|
|
36
|
+
export function isStorageError(error: unknown): error is StorageError {
|
|
37
|
+
return typeof error === 'object' && error !== null && '__isStorageError' in error
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* API error returned from Storage service
|
|
42
|
+
* Includes HTTP status code and service-specific error code
|
|
43
|
+
*/
|
|
44
|
+
export class StorageApiError extends StorageError {
|
|
45
|
+
override status: number
|
|
46
|
+
override statusCode: string
|
|
47
|
+
|
|
48
|
+
constructor(
|
|
49
|
+
message: string,
|
|
50
|
+
status: number,
|
|
51
|
+
statusCode: string,
|
|
52
|
+
namespace: ErrorNamespace = 'storage'
|
|
53
|
+
) {
|
|
54
|
+
super(message, namespace, status, statusCode)
|
|
55
|
+
this.name = namespace === 'vectors' ? 'StorageVectorsApiError' : 'StorageApiError'
|
|
56
|
+
this.status = status
|
|
57
|
+
this.statusCode = statusCode
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
toJSON() {
|
|
61
|
+
return {
|
|
62
|
+
name: this.name,
|
|
63
|
+
message: this.message,
|
|
64
|
+
status: this.status,
|
|
65
|
+
statusCode: this.statusCode,
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Unknown error that doesn't match expected error patterns
|
|
72
|
+
* Wraps the original error for debugging
|
|
73
|
+
*/
|
|
74
|
+
export class StorageUnknownError extends StorageError {
|
|
75
|
+
originalError: unknown
|
|
76
|
+
|
|
77
|
+
constructor(message: string, originalError: unknown, namespace: ErrorNamespace = 'storage') {
|
|
78
|
+
super(message, namespace)
|
|
79
|
+
this.name = namespace === 'vectors' ? 'StorageVectorsUnknownError' : 'StorageUnknownError'
|
|
80
|
+
this.originalError = originalError
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// ============================================================================
|
|
85
|
+
// Backward Compatibility Exports for Vectors
|
|
86
|
+
// ============================================================================
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* @deprecated Use StorageError with namespace='vectors' instead
|
|
90
|
+
* Alias for backward compatibility with existing vector storage code
|
|
91
|
+
*/
|
|
92
|
+
export class StorageVectorsError extends StorageError {
|
|
93
|
+
constructor(message: string) {
|
|
94
|
+
super(message, 'vectors')
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Type guard to check if an error is a StorageVectorsError
|
|
100
|
+
* @param error - The error to check
|
|
101
|
+
* @returns True if the error is a StorageVectorsError
|
|
102
|
+
*/
|
|
103
|
+
export function isStorageVectorsError(error: unknown): error is StorageVectorsError {
|
|
104
|
+
return isStorageError(error) && (error as StorageError)['namespace'] === 'vectors'
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* @deprecated Use StorageApiError with namespace='vectors' instead
|
|
109
|
+
* Alias for backward compatibility with existing vector storage code
|
|
110
|
+
*/
|
|
111
|
+
export class StorageVectorsApiError extends StorageApiError {
|
|
112
|
+
constructor(message: string, status: number, statusCode: string) {
|
|
113
|
+
super(message, status, statusCode, 'vectors')
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* @deprecated Use StorageUnknownError with namespace='vectors' instead
|
|
119
|
+
* Alias for backward compatibility with existing vector storage code
|
|
120
|
+
*/
|
|
121
|
+
export class StorageVectorsUnknownError extends StorageUnknownError {
|
|
122
|
+
constructor(message: string, originalError: unknown) {
|
|
123
|
+
super(message, originalError, 'vectors')
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Error codes specific to S3 Vectors API
|
|
129
|
+
* Maps AWS service errors to application-friendly error codes
|
|
130
|
+
*/
|
|
131
|
+
export enum StorageVectorsErrorCode {
|
|
132
|
+
/** Internal server fault (HTTP 500) */
|
|
133
|
+
InternalError = 'InternalError',
|
|
134
|
+
/** Resource already exists / conflict (HTTP 409) */
|
|
135
|
+
S3VectorConflictException = 'S3VectorConflictException',
|
|
136
|
+
/** Resource not found (HTTP 404) */
|
|
137
|
+
S3VectorNotFoundException = 'S3VectorNotFoundException',
|
|
138
|
+
/** Delete bucket while not empty (HTTP 400) */
|
|
139
|
+
S3VectorBucketNotEmpty = 'S3VectorBucketNotEmpty',
|
|
140
|
+
/** Exceeds bucket quota/limit (HTTP 400) */
|
|
141
|
+
S3VectorMaxBucketsExceeded = 'S3VectorMaxBucketsExceeded',
|
|
142
|
+
/** Exceeds index quota/limit (HTTP 400) */
|
|
143
|
+
S3VectorMaxIndexesExceeded = 'S3VectorMaxIndexesExceeded',
|
|
144
|
+
}
|