nuxt4, and some changes on packages

This commit is contained in:
2025-08-19 21:38:30 +03:30
parent 61fee6c3da
commit 5b6f1a1cdf
900 changed files with 11139 additions and 15161 deletions
@@ -7,8 +7,8 @@ exports.StorageClient = void 0;
const StorageFileApi_1 = __importDefault(require("./packages/StorageFileApi"));
const StorageBucketApi_1 = __importDefault(require("./packages/StorageBucketApi"));
class StorageClient extends StorageBucketApi_1.default {
constructor(url, headers = {}, fetch) {
super(url, headers, fetch);
constructor(url, headers = {}, fetch, opts) {
super(url, headers, fetch, opts);
}
/**
* Perform file operation in a bucket.
+3 -1
View File
@@ -14,16 +14,18 @@ function isStorageError(error) {
}
exports.isStorageError = isStorageError;
class StorageApiError extends StorageError {
constructor(message, status) {
constructor(message, status, statusCode) {
super(message);
this.name = 'StorageApiError';
this.status = status;
this.statusCode = statusCode;
}
toJSON() {
return {
name: this.name,
message: this.message,
status: this.status,
statusCode: this.statusCode,
};
}
}
+12 -4
View File
@@ -19,7 +19,9 @@ const handleError = (error, reject, options) => __awaiter(void 0, void 0, void 0
error
.json()
.then((err) => {
reject(new errors_1.StorageApiError(_getErrorMessage(err), error.status || 500));
const status = error.status || 500;
const statusCode = (err === null || err === void 0 ? void 0 : err.statusCode) || status + '';
reject(new errors_1.StorageApiError(_getErrorMessage(err), status, statusCode));
})
.catch((err) => {
reject(new errors_1.StorageUnknownError(_getErrorMessage(err), err));
@@ -31,13 +33,19 @@ const handleError = (error, reject, options) => __awaiter(void 0, void 0, void 0
});
const _getRequestParams = (method, options, parameters, body) => {
const params = { method, headers: (options === null || options === void 0 ? void 0 : options.headers) || {} };
if (method === 'GET') {
if (method === 'GET' || !body) {
return params;
}
params.headers = Object.assign({ 'Content-Type': 'application/json' }, options === null || options === void 0 ? void 0 : options.headers);
if (body) {
if ((0, helpers_1.isPlainObject)(body)) {
params.headers = Object.assign({ 'Content-Type': 'application/json' }, options === null || options === void 0 ? void 0 : options.headers);
params.body = JSON.stringify(body);
}
else {
params.body = body;
}
if (options === null || options === void 0 ? void 0 : options.duplex) {
params.duplex = options.duplex;
}
return Object.assign(Object.assign({}, params), parameters);
};
function _handleRequest(fetcher, method, url, options, parameters, body) {
+18 -1
View File
@@ -32,7 +32,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.recursiveToCamel = exports.resolveResponse = exports.resolveFetch = void 0;
exports.isPlainObject = exports.recursiveToCamel = exports.resolveResponse = exports.resolveFetch = void 0;
const resolveFetch = (customFetch) => {
let _fetch;
if (customFetch) {
@@ -70,4 +70,21 @@ const recursiveToCamel = (item) => {
return result;
};
exports.recursiveToCamel = recursiveToCamel;
/**
* Determine if input is a plain object
* An object is plain if it's created by either {}, new Object(), or Object.create(null)
* source: https://github.com/sindresorhus/is-plain-obj
*/
const isPlainObject = (value) => {
if (typeof value !== 'object' || value === null) {
return false;
}
const prototype = Object.getPrototypeOf(value);
return ((prototype === null ||
prototype === Object.prototype ||
Object.getPrototypeOf(prototype) === null) &&
!(Symbol.toStringTag in value) &&
!(Symbol.iterator in value));
};
exports.isPlainObject = isPlainObject;
//# sourceMappingURL=helpers.js.map
+1 -1
View File
@@ -2,5 +2,5 @@
Object.defineProperty(exports, "__esModule", { value: true });
exports.version = void 0;
// generated by genversion
exports.version = '2.7.1';
exports.version = '2.11.0';
//# sourceMappingURL=version.js.map
@@ -14,8 +14,17 @@ const errors_1 = require("../lib/errors");
const fetch_1 = require("../lib/fetch");
const helpers_1 = require("../lib/helpers");
class StorageBucketApi {
constructor(url, headers = {}, fetch) {
this.url = url;
constructor(url, headers = {}, fetch, opts) {
const baseUrl = new URL(url);
// if legacy uri is used, replace with new storage host (disables request buffering to allow > 50GB uploads)
// "project-ref.supabase.co" becomes "project-ref.storage.supabase.co"
if (opts === null || opts === void 0 ? void 0 : opts.useNewHostname) {
const isSupabaseHost = /supabase\.(co|in|red)$/.test(baseUrl.hostname);
if (isSupabaseHost && !baseUrl.hostname.includes('storage.supabase.')) {
baseUrl.hostname = baseUrl.hostname.replace('supabase.', 'storage.supabase.');
}
}
this.url = baseUrl.href;
this.headers = Object.assign(Object.assign({}, constants_1.DEFAULT_HEADERS), headers);
this.fetch = (0, helpers_1.resolveFetch)(fetch);
}
@@ -67,6 +76,8 @@ class StorageBucketApi {
* The default value is null, which allows files with all mime types to be uploaded.
* Each mime type specified can be a wildcard, e.g. image/*, or a specific mime type, e.g. image/png.
* @returns newly created bucket id
* @param options.type (private-beta) specifies the bucket type. see `BucketType` for more details.
* - default bucket type is `STANDARD`
*/
createBucket(id, options = {
public: false,
@@ -76,6 +87,7 @@ class StorageBucketApi {
const data = yield (0, fetch_1.post)(this.fetch, `${this.url}/bucket`, {
id,
name: id,
type: options.type,
public: options.public,
file_size_limit: options.fileSizeLimit,
allowed_mime_types: options.allowedMimeTypes,
@@ -74,18 +74,11 @@ class StorageFileApi {
}
const cleanPath = this._removeEmptyFolders(path);
const _path = this._getFinalPath(cleanPath);
const res = yield this.fetch(`${this.url}/object/${_path}`, Object.assign({ method, body: body, headers }, ((options === null || options === void 0 ? void 0 : options.duplex) ? { duplex: options.duplex } : {})));
const data = yield res.json();
if (res.ok) {
return {
data: { path: cleanPath, id: data.Id, fullPath: data.Key },
error: null,
};
}
else {
const error = data;
return { data: null, error };
}
const data = yield (method == 'PUT' ? fetch_1.put : fetch_1.post)(this.fetch, `${this.url}/object/${_path}`, body, Object.assign({ headers }, ((options === null || options === void 0 ? void 0 : options.duplex) ? { duplex: options.duplex } : {})));
return {
data: { path: cleanPath, id: data.Id, fullPath: data.Key },
error: null,
};
}
catch (error) {
if ((0, errors_1.isStorageError)(error)) {
@@ -136,22 +129,11 @@ class StorageFileApi {
headers['cache-control'] = `max-age=${options.cacheControl}`;
headers['content-type'] = options.contentType;
}
const res = yield this.fetch(url.toString(), {
method: 'PUT',
body: body,
headers,
});
const data = yield res.json();
if (res.ok) {
return {
data: { path: cleanPath, fullPath: data.Key },
error: null,
};
}
else {
const error = data;
return { data: null, error };
}
const data = yield (0, fetch_1.put)(this.fetch, url.toString(), body, { headers });
return {
data: { path: cleanPath, fullPath: data.Key },
error: null,
};
}
catch (error) {
if ((0, errors_1.isStorageError)(error)) {
@@ -498,6 +480,7 @@ class StorageFileApi {
/**
* Lists all the files within a bucket.
* @param path The folder path.
* @param options Search options including limit (defaults to 100), offset, sortBy, and search
*/
list(path, options, parameters) {
return __awaiter(this, void 0, void 0, function* () {
@@ -514,6 +497,26 @@ class StorageFileApi {
}
});
}
/**
* @experimental this method signature might change in the future
* @param options search options
* @param parameters
*/
listV2(options, parameters) {
return __awaiter(this, void 0, void 0, function* () {
try {
const body = Object.assign({}, options);
const data = yield (0, fetch_1.post)(this.fetch, `${this.url}/object/list-v2/${this.bucketId}`, body, { headers: this.headers }, parameters);
return { data, error: null };
}
catch (error) {
if ((0, errors_1.isStorageError)(error)) {
return { data: null, error };
}
throw error;
}
});
}
encodeMetadata(metadata) {
return JSON.stringify(metadata);
}
@@ -524,7 +527,7 @@ class StorageFileApi {
return btoa(data);
}
_getFinalPath(path) {
return `${this.bucketId}/${path}`;
return `${this.bucketId}/${path.replace(/^\/+/, '')}`;
}
_removeEmptyFolders(path) {
return path.replace(/^\/|\/$/g, '').replace(/\/+/g, '/');
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "@supabase/storage-js",
"version": "2.7.1",
"version": "2.11.0",
"description": "Isomorphic storage client for Supabase.",
"keywords": [
"javascript",
@@ -29,7 +29,7 @@
"build:umd": "webpack",
"types-generate": "dts-gen -m '@supabase/storage-js' -s",
"test": "run-s test:clean test:infra test:suite test:clean",
"test:suite": "jest --runInBand",
"test:suite": "jest --runInBand --coverage",
"test:infra": "cd infra && docker compose down && docker compose up -d --build && sleep 10",
"test:clean": "cd infra && docker compose down --remove-orphans",
"docs": "typedoc --entryPoints src/index.ts --out docs/v2 --entryPoints src/packages/* --excludePrivate --excludeProtected",