@visulima/storage 1.0.0-alpha.1 → 1.0.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/README.md +33 -14
- package/dist/adapter/nuxt/module.d.ts +39 -0
- package/dist/adapter/nuxt/module.js +93 -0
- package/dist/adapter/nuxt/package.json +20 -0
- package/dist/handler/base/base-handler-core.d.ts +91 -0
- package/dist/handler/base/base-handler-fetch.d.ts +76 -0
- package/dist/handler/base/base-handler-node.d.ts +137 -0
- package/dist/handler/http/fetch/index.d.ts +4 -0
- package/dist/handler/http/fetch/index.js +4 -0
- package/dist/handler/http/hono/index.d.ts +67 -0
- package/dist/handler/http/hono/index.js +65 -0
- package/dist/handler/http/nextjs/index.d.ts +61 -0
- package/dist/handler/http/nextjs/index.js +37 -0
- package/dist/handler/http/node/index.d.ts +4 -0
- package/dist/handler/http/node/index.js +4 -0
- package/dist/handler/http/solid-start/index.d.ts +60 -0
- package/dist/handler/http/solid-start/index.js +44 -0
- package/dist/handler/multipart/multipart-base.d.ts +84 -0
- package/dist/handler/multipart/multipart-fetch.d.ts +64 -0
- package/dist/handler/multipart/multipart.d.ts +49 -0
- package/dist/handler/rest/rest-base.d.ts +106 -0
- package/dist/handler/rest/rest-fetch.d.ts +88 -0
- package/dist/handler/rest/rest.d.ts +93 -0
- package/dist/handler/tus/tus-base.d.ts +152 -0
- package/dist/handler/tus/tus-fetch.d.ts +72 -0
- package/dist/handler/tus/tus.d.ts +78 -0
- package/dist/handler/types.d.ts +53 -0
- package/dist/handler/utils/request-parser.d.ts +72 -0
- package/dist/handler/utils/response-builder.d.ts +83 -0
- package/dist/handler/utils/storage-utils.d.ts +10 -0
- package/dist/handler/utils/stream-utils.d.ts +29 -0
- package/dist/handler/utils/upload-handlers.d.ts +76 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +13 -0
- package/dist/metrics/index.d.ts +2 -0
- package/dist/metrics/no-op-metrics.d.ts +15 -0
- package/dist/metrics/opentelemetry-metrics.d.ts +55 -0
- package/dist/openapi/index.d.ts +5 -0
- package/dist/openapi/index.js +5 -0
- package/dist/openapi/rest.d.ts +7 -0
- package/dist/openapi/shared.d.ts +13 -0
- package/dist/openapi/transform.d.ts +3 -0
- package/dist/openapi/tus.d.ts +7 -0
- package/dist/openapi/xhr.d.ts +7 -0
- package/dist/packem_shared/AwsLightFile-tTneXZgG.js +11 -0
- package/dist/packem_shared/AwsLightMetaStorage-BWSOtVaN.js +4 -0
- package/dist/packem_shared/AwsLightStorage-Blv-GP4v.js +133 -0
- package/dist/packem_shared/AzureFile-CesgFzps.js +8 -0
- package/dist/packem_shared/AzureSMetaStorage-CFs-OYJT.js +88 -0
- package/dist/packem_shared/AzureStorage-B0v048hG.js +357 -0
- package/dist/packem_shared/BaseTransformer-C2gLib6v.js +82 -0
- package/dist/packem_shared/DiskStorage-BlltBst6.js +12 -0
- package/dist/packem_shared/DiskStorageWithChecksum-BJTmMklc.js +238 -0
- package/dist/packem_shared/ERRORS-D0apMqnc.js +97 -0
- package/dist/packem_shared/File-Bb3P23dr.js +69 -0
- package/dist/packem_shared/GCSConfig-vPP22kN6.js +11 -0
- package/dist/packem_shared/GCSFile-BIEunhAN.js +8 -0
- package/dist/packem_shared/GCSMetaStorage-BMFEdzJ7.js +7 -0
- package/dist/packem_shared/GCStorage-DnhiwaS9.js +406 -0
- package/dist/packem_shared/LocalMetaStorage-CZHhKkMd.js +7 -0
- package/dist/packem_shared/MediaTransformer-D6658DL1.js +1197 -0
- package/dist/packem_shared/MetaStorage-pECeFOad.js +46 -0
- package/dist/packem_shared/Metadata-DRLXeJ0F.js +89 -0
- package/dist/packem_shared/Multipart-CNFK_Okz.js +163 -0
- package/dist/packem_shared/Multipart-CtUL7BQw.js +128 -0
- package/dist/packem_shared/NetlifyBlobFile-CXzyjqrD.js +14 -0
- package/dist/packem_shared/NetlifyBlobMetaStorage-DxZ5aDvD.js +9 -0
- package/dist/packem_shared/NetlifyBlobStorage-CLPtjHqd.js +376 -0
- package/dist/packem_shared/NoOpMetrics-DhAk5rXc.js +10 -0
- package/dist/packem_shared/OpenTelemetryMetrics-BnxhqIaH.js +67 -0
- package/dist/packem_shared/Rest-CAOAEkOj.js +267 -0
- package/dist/packem_shared/Rest-DNuLwBrK.js +228 -0
- package/dist/packem_shared/S3File-DZiyk9Qt.js +11 -0
- package/dist/packem_shared/S3MetaStorage-Dz9aDabA.js +76 -0
- package/dist/packem_shared/S3Storage-DHmTk-hU.js +316 -0
- package/dist/packem_shared/TUS_RESUMABLE-GJzZ9R-f.js +434 -0
- package/dist/packem_shared/Tus-B8PmlMgR.js +200 -0
- package/dist/packem_shared/Tus-C4F1aYOl.js +195 -0
- package/dist/packem_shared/ValidationError-BfF1aE4h.js +26 -0
- package/dist/packem_shared/VercelBlobFile-BCg4aTEq.js +18 -0
- package/dist/packem_shared/VercelBlobMetaStorage-Bd9F-VFm.js +9 -0
- package/dist/packem_shared/VercelBlobStorage-DD9LMOS6.js +261 -0
- package/dist/packem_shared/_commonjsHelpers-B85MJLTf.js +5 -0
- package/dist/packem_shared/aws-light-meta-storage-DKJBgbR6.js +446 -0
- package/dist/packem_shared/backblaze-BlMnIcBC.js +20 -0
- package/dist/packem_shared/base-handler-core-BKuf4YLT.js +303 -0
- package/dist/packem_shared/base-handler-fetch-Cr0hLiqg.js +291 -0
- package/dist/packem_shared/base-handler-node-gk5aN9Cx.js +730 -0
- package/dist/packem_shared/cache-B88MXQ_2.js +18 -0
- package/dist/packem_shared/cloudflare-Bi1q8wXE.js +21 -0
- package/dist/packem_shared/defaultCloudStorageFileNameValidation-DUuacjWv.js +11 -0
- package/dist/packem_shared/digitalOcean-CWQRJM3L.js +21 -0
- package/dist/packem_shared/disk-storage-Bh2wy3YW.js +810 -0
- package/dist/packem_shared/gcs-meta-storage-0tgMNnPO.js +158 -0
- package/dist/packem_shared/has-content-CY66ehMK.js +3 -0
- package/dist/packem_shared/headers-DoS5nwM-.js +3220 -0
- package/dist/packem_shared/is-expired-CTThU1q5.js +8 -0
- package/dist/packem_shared/isRetryableError-Dycp7127.js +82 -0
- package/dist/packem_shared/isValidMediaType-BeDgiObq.js +35 -0
- package/dist/packem_shared/local-meta-storage-By-3SNBI.js +649 -0
- package/dist/packem_shared/minio-C2YBZQOw.js +22 -0
- package/dist/packem_shared/multipart-base-B3i67SSX.js +102 -0
- package/dist/packem_shared/part-match-BMNqHDYD.js +96 -0
- package/dist/packem_shared/path-CR6YkPXX-7R1-9CMk.js +161 -0
- package/dist/packem_shared/response-builder-BtnRiBUI.js +45 -0
- package/dist/packem_shared/rest-base-GRCcnan7.js +457 -0
- package/dist/packem_shared/restOpenApiSpec-CwcHHY2C.js +800 -0
- package/dist/packem_shared/s3-base-storage-C1DIHTYY.js +510 -0
- package/dist/packem_shared/sharedGet-Cpo7QUyu.js +1019 -0
- package/dist/packem_shared/storage-C6NSXb8h.js +1175 -0
- package/dist/packem_shared/tigris-Hac8TKnX.js +21 -0
- package/dist/packem_shared/transformOpenApiSpec-DWM5WtnN.js +975 -0
- package/dist/packem_shared/tusOpenApiSpec-6ohiToBy.js +740 -0
- package/dist/packem_shared/update-size-CCGm6i1J.js +8 -0
- package/dist/packem_shared/validator-BeX_lJet.js +78 -0
- package/dist/packem_shared/waitForStorage-Cscw85sx.js +18 -0
- package/dist/packem_shared/wasabi-DIyflHSd.js +21 -0
- package/dist/packem_shared/xhrOpenApiSpec-DS17brnx.js +264 -0
- package/dist/storage/aws/clients/backblaze.d.ts +12 -0
- package/dist/storage/aws/clients/cloudflare.d.ts +13 -0
- package/dist/storage/aws/clients/digital-ocean.d.ts +12 -0
- package/dist/storage/aws/clients/index.d.ts +6 -0
- package/dist/storage/aws/clients/index.js +6 -0
- package/dist/storage/aws/clients/minio.d.ts +13 -0
- package/dist/storage/aws/clients/tigris.d.ts +12 -0
- package/dist/storage/aws/clients/types.d.ts +95 -0
- package/dist/storage/aws/clients/wasabi.d.ts +12 -0
- package/dist/storage/aws/index.d.ts +4 -0
- package/dist/storage/aws/index.js +3 -0
- package/dist/storage/aws/s3-base-storage.d.ts +248 -0
- package/dist/storage/aws/s3-client-adapter.d.ts +110 -0
- package/dist/storage/aws/s3-file.d.ts +10 -0
- package/dist/storage/aws/s3-meta-storage.d.ts +15 -0
- package/dist/storage/aws/s3-storage.d.ts +70 -0
- package/dist/storage/aws/types.d.ts +119 -0
- package/dist/storage/aws-light/aws-light-api-adapter.d.ts +130 -0
- package/dist/storage/aws-light/aws-light-file.d.ts +10 -0
- package/dist/storage/aws-light/aws-light-meta-storage.d.ts +19 -0
- package/dist/storage/aws-light/aws-light-storage.d.ts +65 -0
- package/dist/storage/aws-light/index.d.ts +4 -0
- package/dist/storage/aws-light/index.js +3 -0
- package/dist/storage/aws-light/types.d.ts +37 -0
- package/dist/storage/azure/azure-file.d.ts +6 -0
- package/dist/storage/azure/azure-meta-storage.d.ts +15 -0
- package/dist/storage/azure/azure-storage.d.ts +69 -0
- package/dist/storage/azure/index.d.ts +4 -0
- package/dist/storage/azure/index.js +3 -0
- package/dist/storage/azure/types.d.ts +62 -0
- package/dist/storage/gcs/fetch-error.d.ts +11 -0
- package/dist/storage/gcs/gcs-config.d.ts +2 -0
- package/dist/storage/gcs/gcs-file.d.ts +6 -0
- package/dist/storage/gcs/gcs-meta-storage.d.ts +27 -0
- package/dist/storage/gcs/gcs-storage.d.ts +91 -0
- package/dist/storage/gcs/index.d.ts +5 -0
- package/dist/storage/gcs/index.js +4 -0
- package/dist/storage/gcs/types.d.ts +55 -0
- package/dist/storage/gcs/utils.d.ts +7 -0
- package/dist/storage/local/disk-storage-with-checksum.d.ts +15 -0
- package/dist/storage/local/disk-storage.d.ts +135 -0
- package/dist/storage/local/index.d.ts +4 -0
- package/dist/storage/local/index.js +3 -0
- package/dist/storage/local/local-meta-storage.d.ts +32 -0
- package/dist/storage/meta-storage.d.ts +30 -0
- package/dist/storage/netlify-blob/index.d.ts +4 -0
- package/dist/storage/netlify-blob/index.js +3 -0
- package/dist/storage/netlify-blob/netlify-blob-file.d.ts +12 -0
- package/dist/storage/netlify-blob/netlify-blob-meta-storage.d.ts +7 -0
- package/dist/storage/netlify-blob/netlify-blob-storage.d.ts +93 -0
- package/dist/storage/netlify-blob/types.d.ts +30 -0
- package/dist/storage/storage.d.ts +353 -0
- package/dist/storage/types.d.ts +221 -0
- package/dist/storage/utils/file/file.d.ts +25 -0
- package/dist/storage/utils/file/get-file-status.d.ts +9 -0
- package/dist/storage/utils/file/has-content.d.ts +9 -0
- package/dist/storage/utils/file/index.d.ts +10 -0
- package/dist/storage/utils/file/is-expired.d.ts +8 -0
- package/dist/storage/utils/file/metadata.d.ts +18 -0
- package/dist/storage/utils/file/part-match.d.ts +11 -0
- package/dist/storage/utils/file/types.d.ts +37 -0
- package/dist/storage/utils/file/update-metadata.d.ts +10 -0
- package/dist/storage/utils/file/update-size.d.ts +10 -0
- package/dist/storage/vercel-blob/index.d.ts +4 -0
- package/dist/storage/vercel-blob/index.js +3 -0
- package/dist/storage/vercel-blob/types.d.ts +32 -0
- package/dist/storage/vercel-blob/vercel-blob-file.d.ts +16 -0
- package/dist/storage/vercel-blob/vercel-blob-meta-storage.d.ts +7 -0
- package/dist/storage/vercel-blob/vercel-blob-storage.d.ts +76 -0
- package/dist/transformer/audio-transformer.d.ts +128 -0
- package/dist/transformer/audio-transformer.js +278 -0
- package/dist/transformer/base-transformer.d.ts +63 -0
- package/dist/transformer/image-transformer.d.ts +571 -0
- package/dist/transformer/image-transformer.js +1100 -0
- package/dist/transformer/index.d.ts +5 -0
- package/dist/transformer/index.js +4 -0
- package/dist/transformer/media-transformer.d.ts +332 -0
- package/dist/transformer/types.d.ts +652 -0
- package/dist/transformer/utils.d.ts +33 -0
- package/dist/transformer/validation-error.d.ts +23 -0
- package/dist/transformer/video-transformer.d.ts +145 -0
- package/dist/transformer/video-transformer.js +310 -0
- package/dist/utils/cache.d.ts +32 -0
- package/dist/utils/chunked-upload.d.ts +65 -0
- package/dist/utils/detect-file-type.d.ts +28 -0
- package/dist/utils/errors.d.ts +74 -0
- package/dist/utils/file-path-url-matcher.d.ts +18 -0
- package/dist/utils/headers.d.ts +111 -0
- package/dist/utils/http.d.ts +92 -0
- package/dist/utils/locker.d.ts +26 -0
- package/dist/utils/pipes/stream-checksum.d.ts +47 -0
- package/dist/utils/pipes/stream-length.d.ts +22 -0
- package/dist/utils/primitives/get-last-one.d.ts +3 -0
- package/dist/utils/primitives/is-record.d.ts +2 -0
- package/dist/utils/primitives/map-values.d.ts +9 -0
- package/dist/utils/primitives/pick.d.ts +2 -0
- package/dist/utils/primitives/to-milliseconds.d.ts +12 -0
- package/dist/utils/primitives/to-seconds.d.ts +12 -0
- package/dist/utils/range-checksum.d.ts +33 -0
- package/dist/utils/range-hasher.d.ts +46 -0
- package/dist/utils/retry.d.ts +64 -0
- package/dist/utils/types.d.ts +108 -0
- package/dist/utils/validation-error.d.ts +22 -0
- package/dist/utils/validator.d.ts +36 -0
- package/package.json +5 -5
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
const defaultRetryConfig = {
|
|
2
|
+
backoffMultiplier: 2,
|
|
3
|
+
calculateDelay: void 0,
|
|
4
|
+
initialDelay: 1e3,
|
|
5
|
+
maxDelay: 3e4,
|
|
6
|
+
maxRetries: 3,
|
|
7
|
+
retryableStatusCodes: [408, 429, 500, 502, 503, 504],
|
|
8
|
+
shouldRetry: () => true
|
|
9
|
+
};
|
|
10
|
+
const calculateExponentialBackoff = (attempt, initialDelay, backoffMultiplier, maxDelay) => {
|
|
11
|
+
const delay = initialDelay * backoffMultiplier ** attempt;
|
|
12
|
+
return Math.min(delay, maxDelay);
|
|
13
|
+
};
|
|
14
|
+
const sleep = (ms) => new Promise((resolve) => {
|
|
15
|
+
setTimeout(resolve, ms);
|
|
16
|
+
});
|
|
17
|
+
const isRetryableError = (error, retryableStatusCodes = defaultRetryConfig.retryableStatusCodes) => {
|
|
18
|
+
if (error instanceof Error) {
|
|
19
|
+
const errorWithCode = error;
|
|
20
|
+
const errorCode = errorWithCode.code;
|
|
21
|
+
const errorName = error.name;
|
|
22
|
+
if (errorCode === "ECONNRESET" || errorCode === "ETIMEDOUT" || errorCode === "ENOTFOUND" || errorCode === "ECONNREFUSED" || errorCode === "EAI_AGAIN" || errorName === "NetworkError" || errorName === "TimeoutError") {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
const errorWithMetadata = error;
|
|
26
|
+
if (errorWithMetadata.$metadata) {
|
|
27
|
+
const statusCode = errorWithMetadata.$metadata.httpStatusCode;
|
|
28
|
+
if (statusCode && retryableStatusCodes.includes(statusCode)) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
if (errorWithMetadata.$fault === "server") {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (errorWithMetadata.statusCode && retryableStatusCodes.includes(errorWithMetadata.statusCode)) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
const { retryable } = errorWithMetadata;
|
|
39
|
+
if (retryable === true) {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
if (typeof retryable === "string" && retryable === "true") {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
return false;
|
|
48
|
+
};
|
|
49
|
+
const retry = async (function_, config = {}) => {
|
|
50
|
+
const {
|
|
51
|
+
backoffMultiplier = defaultRetryConfig.backoffMultiplier,
|
|
52
|
+
calculateDelay = defaultRetryConfig.calculateDelay,
|
|
53
|
+
initialDelay = defaultRetryConfig.initialDelay,
|
|
54
|
+
maxDelay = defaultRetryConfig.maxDelay,
|
|
55
|
+
maxRetries = defaultRetryConfig.maxRetries,
|
|
56
|
+
retryableStatusCodes = defaultRetryConfig.retryableStatusCodes,
|
|
57
|
+
shouldRetry = defaultRetryConfig.shouldRetry
|
|
58
|
+
} = config;
|
|
59
|
+
let lastError;
|
|
60
|
+
for (let attempt = 0; attempt <= maxRetries; attempt += 1) {
|
|
61
|
+
try {
|
|
62
|
+
return await function_();
|
|
63
|
+
} catch (error) {
|
|
64
|
+
lastError = error;
|
|
65
|
+
if (attempt >= maxRetries) {
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
const isRetryable = shouldRetry(error) || isRetryableError(error, retryableStatusCodes);
|
|
69
|
+
if (!isRetryable) {
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
const delay = calculateDelay ? calculateDelay(attempt, error) : calculateExponentialBackoff(attempt, initialDelay, backoffMultiplier, maxDelay);
|
|
73
|
+
if (delay !== void 0 && delay > 0) {
|
|
74
|
+
await sleep(delay);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
throw lastError;
|
|
79
|
+
};
|
|
80
|
+
const createRetryWrapper = (config = {}) => (function_) => retry(function_, config);
|
|
81
|
+
|
|
82
|
+
export { createRetryWrapper, isRetryableError, retry };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import mime from 'mime';
|
|
2
|
+
|
|
3
|
+
const isValidMediaType = (contentType, expectedType) => {
|
|
4
|
+
if (!contentType) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
return contentType.startsWith(`${expectedType}/`);
|
|
8
|
+
};
|
|
9
|
+
const getFormatFromContentType = (contentType) => {
|
|
10
|
+
if (!contentType) {
|
|
11
|
+
return void 0;
|
|
12
|
+
}
|
|
13
|
+
return mime.getExtension(contentType) || void 0;
|
|
14
|
+
};
|
|
15
|
+
const validateMediaFile = (file, expectedType, config) => {
|
|
16
|
+
const fileSize = typeof file.size === "string" ? Number.parseInt(file.size, 10) : file.size;
|
|
17
|
+
if (config?.maxSize && fileSize > config.maxSize) {
|
|
18
|
+
throw new Error(`${expectedType} size ${fileSize} exceeds maximum allowed size ${config.maxSize}`);
|
|
19
|
+
}
|
|
20
|
+
if (!isValidMediaType(file.contentType, expectedType)) {
|
|
21
|
+
throw new Error(`File is not ${expectedType === "image" ? "an" : "a"} ${expectedType}: ${file.contentType}`);
|
|
22
|
+
}
|
|
23
|
+
const format = getFormatFromContentType(file.contentType);
|
|
24
|
+
if (config?.supportedFormats && format && !config.supportedFormats.includes(format)) {
|
|
25
|
+
throw new Error(`Unsupported ${expectedType} format: ${format}`);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
const isKnownContentType = (contentType) => {
|
|
29
|
+
if (!contentType) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
return !!mime.getExtension(contentType);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export { getFormatFromContentType, isKnownContentType, isValidMediaType, validateMediaFile };
|