@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,76 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
+
import type { Readable } from "node:stream";
|
|
3
|
+
import type { UploadFile } from "../../storage/utils/index.d.ts";
|
|
4
|
+
import type { ResponseBody, UploadResponse } from "../../utils/types.d.ts";
|
|
5
|
+
import type { ResponseFile, ResponseList } from "../types.d.ts";
|
|
6
|
+
/**
|
|
7
|
+
* Handles HEAD/OPTIONS requests.
|
|
8
|
+
* @param file Response file with headers and status code
|
|
9
|
+
* @param send Function to send response
|
|
10
|
+
*/
|
|
11
|
+
export declare const handleHeadOptionsRequest: <TFile extends UploadFile, NodeResponse extends ServerResponse>(file: ResponseFile<TFile>, send: (response: NodeResponse, data: {
|
|
12
|
+
headers: Record<string, string | number>;
|
|
13
|
+
statusCode: number;
|
|
14
|
+
}) => void, response: NodeResponse) => void;
|
|
15
|
+
/**
|
|
16
|
+
* Handles GET requests with streaming support.
|
|
17
|
+
* @param file Response file (may contain stream)
|
|
18
|
+
* @param request HTTP request
|
|
19
|
+
* @param response HTTP response
|
|
20
|
+
* @param next Optional Express next function
|
|
21
|
+
* @param send Function to send regular response
|
|
22
|
+
* @param sendStream Function to send stream response
|
|
23
|
+
* @param parseRangeHeader Function to parse range header
|
|
24
|
+
*/
|
|
25
|
+
export declare const handleGetRequest: <TFile extends UploadFile, NodeResponse extends ServerResponse>(file: ResponseFile<TFile> | ResponseList<TFile>, request: IncomingMessage, response: NodeResponse, next: (() => void) | undefined, send: (response: NodeResponse, data: UploadResponse<ResponseBody>) => void, sendStream: (response: NodeResponse, stream: Readable, options: {
|
|
26
|
+
headers: Record<string, string | number>;
|
|
27
|
+
range?: {
|
|
28
|
+
end: number;
|
|
29
|
+
start: number;
|
|
30
|
+
};
|
|
31
|
+
size?: number;
|
|
32
|
+
statusCode: number;
|
|
33
|
+
}) => void, parseRangeHeader: (rangeHeader: string | undefined, fileSize: number) => {
|
|
34
|
+
end: number;
|
|
35
|
+
start: number;
|
|
36
|
+
} | undefined) => void;
|
|
37
|
+
/**
|
|
38
|
+
* Handles completed upload responses.
|
|
39
|
+
* @param file Response file
|
|
40
|
+
* @param request HTTP request
|
|
41
|
+
* @param response HTTP response
|
|
42
|
+
* @param next Optional Express next function
|
|
43
|
+
* @param storage Storage instance for onComplete hook
|
|
44
|
+
* @param logger Optional logger
|
|
45
|
+
* @param finish Function to finish the response
|
|
46
|
+
*/
|
|
47
|
+
export declare const handleCompletedUpload: <TFile extends UploadFile, NodeResponse extends ServerResponse>(file: ResponseFile<TFile>, request: IncomingMessage, response: NodeResponse, next: (() => void) | undefined, storage: {
|
|
48
|
+
onComplete: (file: TFile, responseFile: ResponseFile<TFile>, request?: IncomingMessage) => void | Promise<void>;
|
|
49
|
+
}, logger: {
|
|
50
|
+
error?: (message: string, error: unknown) => void;
|
|
51
|
+
} | undefined, finish: (request: IncomingMessage, response: NodeResponse, uploadResponse: ResponseFile<TFile>) => void) => Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Handles partial upload responses.
|
|
54
|
+
* @param file Response file
|
|
55
|
+
* @param request HTTP request
|
|
56
|
+
* @param response HTTP response
|
|
57
|
+
* @param send Function to send response
|
|
58
|
+
*/
|
|
59
|
+
export declare const handlePartialUpload: <TFile extends UploadFile, NodeResponse extends ServerResponse>(file: ResponseFile<TFile>, request: IncomingMessage, response: NodeResponse, send: (response: NodeResponse, data: {
|
|
60
|
+
body: Buffer | string | undefined;
|
|
61
|
+
headers: Record<string, string>;
|
|
62
|
+
statusCode: number;
|
|
63
|
+
}) => void) => void;
|
|
64
|
+
/**
|
|
65
|
+
* Handles errors during upload processing.
|
|
66
|
+
* @param error The error that occurred
|
|
67
|
+
* @param request HTTP request
|
|
68
|
+
* @param emit Function to emit events
|
|
69
|
+
* @param listenerCount Function to count event listeners
|
|
70
|
+
* @param logger Optional logger
|
|
71
|
+
* @param sendError Function to send error response
|
|
72
|
+
* @param response HTTP response
|
|
73
|
+
*/
|
|
74
|
+
export declare const handleUploadError: <NodeResponse extends ServerResponse>(error: unknown, request: IncomingMessage, emit: (event: string, data: unknown) => boolean, listenerCount: (event: string) => number, logger: {
|
|
75
|
+
error?: (message: string, error: unknown) => void;
|
|
76
|
+
} | undefined, sendError: (response: NodeResponse, error: Error) => Promise<void>, response: NodeResponse) => Promise<void>;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { waitForStorage } from "./handler/utils/storage-utils.d.ts";
|
|
2
|
+
export { NoOpMetrics, OpenTelemetryMetrics } from "./metrics/index.d.ts";
|
|
3
|
+
export { default as DiskStorage } from "./storage/local/disk-storage.d.ts";
|
|
4
|
+
export { default as DiskStorageWithChecksum } from "./storage/local/disk-storage-with-checksum.d.ts";
|
|
5
|
+
export type { LocalMetaStorageOptions } from "./storage/local/local-meta-storage.d.ts";
|
|
6
|
+
export { default as LocalMetaStorage } from "./storage/local/local-meta-storage.d.ts";
|
|
7
|
+
export { default as MetaStorage } from "./storage/meta-storage.d.ts";
|
|
8
|
+
export { BaseStorage as AbstractBaseStorage, defaultCloudStorageFileNameValidation, defaultFilesystemFileNameValidation } from "./storage/storage.d.ts";
|
|
9
|
+
export type { BaseStorageOptions, BatchOperationResponse, BatchOperationResult, DiskStorageOptions, DiskStorageWithChecksumOptions, ExpirationOptions, MetaStorageOptions, OnComplete, OnCreate, OnDelete, OnError, OnUpdate, PurgeList, } from "./storage/types.d.ts";
|
|
10
|
+
export type { FileInit, FilePart, FileQuery, UploadEventType, UploadFile } from "./storage/utils/file/index.d.ts";
|
|
11
|
+
export { File, Metadata } from "./storage/utils/file/index.d.ts";
|
|
12
|
+
export { ErrorMap, ERRORS, isUploadError, throwErrorCode, UploadError } from "./utils/errors.d.ts";
|
|
13
|
+
export type { RetryConfig } from "./utils/retry.d.ts";
|
|
14
|
+
export { createRetryWrapper, isRetryableError, retry } from "./utils/retry.d.ts";
|
|
15
|
+
export type { Header, Headers, HttpError, HttpErrorBody, IncomingMessageWithBody, Metrics, RangeChecksum, RangeHasher, ResponseBody, ResponseBodyType, ResponseTuple, UploadResponse, Validation, ValidationError, ValidatorConfig, } from "./utils/types.d.ts";
|
|
16
|
+
export type { AnyWebReadableByteStreamWithFileType, AnyWebReadableStream, Detector, FileTypeOptions, FileTypeParser, FileTypeResult, StreamOptions, TokenizerPositionError, } from "file-type";
|
|
17
|
+
export { fileTypeFromBlob, fileTypeFromBuffer, fileTypeFromTokenizer, supportedExtensions, supportedMimeTypes } from "file-type";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { waitForStorage } from './packem_shared/waitForStorage-Cscw85sx.js';
|
|
2
|
+
export { D as DiskStorage } from './packem_shared/disk-storage-Bh2wy3YW.js';
|
|
3
|
+
export { default as DiskStorageWithChecksum } from './packem_shared/DiskStorageWithChecksum-BJTmMklc.js';
|
|
4
|
+
export { L as LocalMetaStorage } from './packem_shared/local-meta-storage-By-3SNBI.js';
|
|
5
|
+
export { default as MetaStorage } from './packem_shared/MetaStorage-pECeFOad.js';
|
|
6
|
+
export { B as AbstractBaseStorage, d as defaultCloudStorageFileNameValidation, a as defaultFilesystemFileNameValidation } from './packem_shared/storage-C6NSXb8h.js';
|
|
7
|
+
export { ERRORS, ErrorMap, UploadError, isUploadError, throwErrorCode } from './packem_shared/ERRORS-D0apMqnc.js';
|
|
8
|
+
export { createRetryWrapper, isRetryableError, retry } from './packem_shared/isRetryableError-Dycp7127.js';
|
|
9
|
+
export { fileTypeFromBlob, fileTypeFromBuffer, fileTypeFromTokenizer, supportedExtensions, supportedMimeTypes } from 'file-type';
|
|
10
|
+
export { default as NoOpMetrics } from './packem_shared/NoOpMetrics-DhAk5rXc.js';
|
|
11
|
+
export { default as OpenTelemetryMetrics } from './packem_shared/OpenTelemetryMetrics-BnxhqIaH.js';
|
|
12
|
+
export { default as File } from './packem_shared/File-Bb3P23dr.js';
|
|
13
|
+
export { Metadata } from './packem_shared/Metadata-DRLXeJ0F.js';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* No-op metrics implementation.
|
|
3
|
+
* Used when metrics are not provided, ensuring no overhead when metrics are disabled.
|
|
4
|
+
*/
|
|
5
|
+
import type { Metrics } from "../utils/types.d.ts";
|
|
6
|
+
/**
|
|
7
|
+
* No-op metrics that does nothing.
|
|
8
|
+
* Used as a default when metrics are not provided.
|
|
9
|
+
*/
|
|
10
|
+
declare class NoOpMetrics implements Metrics {
|
|
11
|
+
increment(_name: string, _value?: number, _attributes?: Record<string, string | number>): void;
|
|
12
|
+
timing(_name: string, _duration: number, _attributes?: Record<string, string | number>): void;
|
|
13
|
+
gauge(_name: string, _value: number, _attributes?: Record<string, string | number>): void;
|
|
14
|
+
}
|
|
15
|
+
export default NoOpMetrics;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenTelemetry Metrics implementation for storage operations.
|
|
3
|
+
*
|
|
4
|
+
* Provides counters, timers, and gauges using OpenTelemetry Metrics API.
|
|
5
|
+
* This allows integration with any OpenTelemetry-compatible observability backend
|
|
6
|
+
* (Prometheus, Datadog, New Relic, etc.).
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { metrics } from "@opentelemetry/api";
|
|
10
|
+
* import { OpenTelemetryMetrics } from "@visulima/storage/metrics";
|
|
11
|
+
* import { S3Storage } from "@visulima/storage/provider/aws";
|
|
12
|
+
*
|
|
13
|
+
* // Initialize OpenTelemetry (typically done once in your app)
|
|
14
|
+
* const meter = metrics.getMeter("@visulima/storage", "1.0.0");
|
|
15
|
+
*
|
|
16
|
+
* // Create metrics instance
|
|
17
|
+
* const storageMetrics = new OpenTelemetryMetrics(meter);
|
|
18
|
+
*
|
|
19
|
+
* // Use with storage
|
|
20
|
+
* const storage = new S3Storage({
|
|
21
|
+
* bucket: "my-bucket",
|
|
22
|
+
* metrics: storageMetrics,
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
import type { Meter } from "@opentelemetry/api";
|
|
27
|
+
import type { Metrics } from "../utils/types.d.ts";
|
|
28
|
+
/**
|
|
29
|
+
* OpenTelemetry-based metrics implementation.
|
|
30
|
+
*/
|
|
31
|
+
declare class OpenTelemetryMetrics implements Metrics {
|
|
32
|
+
private readonly meter;
|
|
33
|
+
private readonly counters;
|
|
34
|
+
private readonly histograms;
|
|
35
|
+
private readonly gauges;
|
|
36
|
+
/**
|
|
37
|
+
* Creates a new OpenTelemetryMetrics instance.
|
|
38
|
+
* @param meter OpenTelemetry Meter instance. If not provided, uses the default meter.
|
|
39
|
+
* @throws {Error} If \@opentelemetry/api is not installed
|
|
40
|
+
*/
|
|
41
|
+
constructor(meter?: Meter);
|
|
42
|
+
/**
|
|
43
|
+
* Increment a counter metric.
|
|
44
|
+
*/
|
|
45
|
+
increment(name: string, value?: number, attributes?: Record<string, string | number>): void;
|
|
46
|
+
/**
|
|
47
|
+
* Record a duration/timing metric in milliseconds.
|
|
48
|
+
*/
|
|
49
|
+
timing(name: string, duration: number, attributes?: Record<string, string | number>): void;
|
|
50
|
+
/**
|
|
51
|
+
* Set a gauge metric value.
|
|
52
|
+
*/
|
|
53
|
+
gauge(name: string, value: number, attributes?: Record<string, string | number>): void;
|
|
54
|
+
}
|
|
55
|
+
export default OpenTelemetryMetrics;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { default as restOpenApiSpec } from "./rest.d.ts";
|
|
2
|
+
export { sharedErrorSchemaObject, sharedFileMetaExampleObject, sharedFileMetaSchemaObject, sharedGet, sharedGetList } from "./shared.d.ts";
|
|
3
|
+
export { default as transformOpenApiSpec } from "./transform.d.ts";
|
|
4
|
+
export { default as tusOpenApiSpec } from "./tus.d.ts";
|
|
5
|
+
export { default as xhrOpenApiSpec } from "./xhr.d.ts";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { default as restOpenApiSpec } from '../packem_shared/restOpenApiSpec-CwcHHY2C.js';
|
|
2
|
+
export { sharedErrorSchemaObject, sharedFileMetaExampleObject, sharedFileMetaSchemaObject, sharedGet, sharedGetList } from '../packem_shared/sharedGet-Cpo7QUyu.js';
|
|
3
|
+
export { default as transformOpenApiSpec } from '../packem_shared/transformOpenApiSpec-DWM5WtnN.js';
|
|
4
|
+
export { default as tusOpenApiSpec } from '../packem_shared/tusOpenApiSpec-6ohiToBy.js';
|
|
5
|
+
export { default as xhrOpenApiSpec } from '../packem_shared/xhrOpenApiSpec-DS17brnx.js';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { OpenAPIV3 } from "openapi-types";
|
|
2
|
+
declare const swaggerSpec: (origin: string, path: string, options: {
|
|
3
|
+
supportedTransformerFormat?: string[];
|
|
4
|
+
tags?: string[] | undefined;
|
|
5
|
+
transformer?: boolean | "audio" | "video" | "image";
|
|
6
|
+
}) => Partial<OpenAPIV3.Document>;
|
|
7
|
+
export default swaggerSpec;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { OpenAPIV3 } from "openapi-types";
|
|
2
|
+
type TransformType = boolean | "audio" | "video" | "image";
|
|
3
|
+
declare const getOrganizedTransformationParameters: (transform?: TransformType, format?: string[]) => {
|
|
4
|
+
groups: Record<string, string[]>;
|
|
5
|
+
parameters: OpenAPIV3.ParameterObject[];
|
|
6
|
+
};
|
|
7
|
+
export { getOrganizedTransformationParameters };
|
|
8
|
+
export declare const sharedGet: (operationId: string, tags: string[] | undefined, transform?: TransformType, transformerFormat?: string[]) => OpenAPIV3.OperationObject;
|
|
9
|
+
export declare const sharedGetMeta: (operationId: string, tags: string[] | undefined) => OpenAPIV3.OperationObject;
|
|
10
|
+
export declare const sharedErrorSchemaObject: Record<string, OpenAPIV3.NonArraySchemaObject>;
|
|
11
|
+
export declare const sharedFileMetaSchemaObject: Record<string, OpenAPIV3.NonArraySchemaObject>;
|
|
12
|
+
export declare const sharedFileMetaExampleObject: Record<string, OpenAPIV3.ExampleObject>;
|
|
13
|
+
export declare const sharedGetList: (operationId: string, tags: string[] | undefined) => OpenAPIV3.OperationObject;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { OpenAPIV3 } from "openapi-types";
|
|
2
|
+
declare const swaggerSpec: (path: string, options: {
|
|
3
|
+
supportedTransformerFormat?: string[];
|
|
4
|
+
tags?: string[] | undefined;
|
|
5
|
+
transformer?: boolean | "audio" | "video" | "image";
|
|
6
|
+
}) => Partial<OpenAPIV3.Document>;
|
|
7
|
+
export default swaggerSpec;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { OpenAPIV3 } from "openapi-types";
|
|
2
|
+
declare const swaggerSpec: (origin: string, path: string, options: {
|
|
3
|
+
supportedTransformerFormat?: string[];
|
|
4
|
+
tags?: string[] | undefined;
|
|
5
|
+
transformer?: boolean | "audio" | "video" | "image";
|
|
6
|
+
}) => Partial<OpenAPIV3.Document>;
|
|
7
|
+
export default swaggerSpec;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { Readable } from 'node:stream';
|
|
2
|
+
import { S as S3BaseStorage } from './s3-base-storage-C1DIHTYY.js';
|
|
3
|
+
import { a as AwsLightApiAdapter, A as AwsLightMetaStorage } from './aws-light-meta-storage-DKJBgbR6.js';
|
|
4
|
+
import AwsLightFile from './AwsLightFile-tTneXZgG.js';
|
|
5
|
+
|
|
6
|
+
class AwsLightStorage extends S3BaseStorage {
|
|
7
|
+
static name = "aws-light";
|
|
8
|
+
s3Api;
|
|
9
|
+
constructor(config) {
|
|
10
|
+
const { bucket = process.env.S3_BUCKET || process.env.AWS_S3_BUCKET, region = process.env.S3_REGION || process.env.AWS_REGION } = config;
|
|
11
|
+
if (!bucket) {
|
|
12
|
+
throw new Error("S3 bucket is not defined");
|
|
13
|
+
}
|
|
14
|
+
if (!region) {
|
|
15
|
+
throw new Error("S3 region is not defined");
|
|
16
|
+
}
|
|
17
|
+
if (!config.accessKeyId) {
|
|
18
|
+
throw new Error("accessKeyId is required");
|
|
19
|
+
}
|
|
20
|
+
if (!config.secretAccessKey) {
|
|
21
|
+
throw new Error("secretAccessKey is required");
|
|
22
|
+
}
|
|
23
|
+
super({
|
|
24
|
+
bucket,
|
|
25
|
+
clientDirectUpload: config.clientDirectUpload,
|
|
26
|
+
expiration: config.expiration?.maxAge ? { maxAge: String(config.expiration.maxAge) } : void 0,
|
|
27
|
+
filename: config.filename,
|
|
28
|
+
logger: config.logger,
|
|
29
|
+
metaStorage: config.metaStorage,
|
|
30
|
+
metaStorageConfig: config.metaStorageConfig ? { ...config.metaStorageConfig, ...config } : { ...config },
|
|
31
|
+
partSize: config.partSize,
|
|
32
|
+
retryConfig: {
|
|
33
|
+
...config.retryConfig,
|
|
34
|
+
shouldRetry: (error) => {
|
|
35
|
+
const errorWithStatus = error;
|
|
36
|
+
if (errorWithStatus.statusCode && [408, 429, 500, 502, 503, 504].includes(errorWithStatus.statusCode)) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
return errorWithStatus.retryable ?? false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
this.s3Api = new AwsLightApiAdapter({
|
|
44
|
+
accessKeyId: config.accessKeyId,
|
|
45
|
+
bucket,
|
|
46
|
+
endpoint: config.endpoint,
|
|
47
|
+
region,
|
|
48
|
+
secretAccessKey: config.secretAccessKey,
|
|
49
|
+
service: config.service,
|
|
50
|
+
sessionToken: config.sessionToken
|
|
51
|
+
});
|
|
52
|
+
const { metaStorage, metaStorageConfig } = config;
|
|
53
|
+
if (!metaStorage) {
|
|
54
|
+
const metaConfig = { ...config, ...metaStorageConfig, logger: this.logger };
|
|
55
|
+
this.meta = new AwsLightMetaStorage(metaConfig);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Normalizes AWS S3 errors with S3-specific context.
|
|
60
|
+
*/
|
|
61
|
+
normalizeError(error) {
|
|
62
|
+
const awsError = error;
|
|
63
|
+
if (awsError.statusCode || awsError.code) {
|
|
64
|
+
return {
|
|
65
|
+
code: awsError.code || awsError.name,
|
|
66
|
+
message: awsError.message,
|
|
67
|
+
name: awsError.name,
|
|
68
|
+
statusCode: awsError.statusCode || 500
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
return super.normalizeError(error);
|
|
72
|
+
}
|
|
73
|
+
async update({ id }, metadata) {
|
|
74
|
+
if (this.config.clientDirectUpload) {
|
|
75
|
+
const file = await this.getMeta(id);
|
|
76
|
+
return this.buildPresigned({ ...file, ...metadata });
|
|
77
|
+
}
|
|
78
|
+
return super.update({ id }, metadata);
|
|
79
|
+
}
|
|
80
|
+
async getStream({ id }) {
|
|
81
|
+
return this.instrumentOperation("getStream", async () => {
|
|
82
|
+
const s3Api = this.getS3Api();
|
|
83
|
+
const { Body, ContentLength, ContentType, ETag, Expires, LastModified } = await this.retry(
|
|
84
|
+
() => s3Api.getObject({
|
|
85
|
+
Bucket: this.bucket,
|
|
86
|
+
Key: id
|
|
87
|
+
})
|
|
88
|
+
);
|
|
89
|
+
await this.checkIfExpired({ expiredAt: Expires });
|
|
90
|
+
const stream = Body instanceof ReadableStream ? Readable.fromWeb(Body) : Body;
|
|
91
|
+
const readableStream = new Readable({
|
|
92
|
+
read() {
|
|
93
|
+
stream.on("data", (chunk) => {
|
|
94
|
+
this.push(chunk);
|
|
95
|
+
});
|
|
96
|
+
stream.on("end", () => {
|
|
97
|
+
this.push(null);
|
|
98
|
+
});
|
|
99
|
+
stream.on("error", (error) => {
|
|
100
|
+
this.destroy(error);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
return {
|
|
105
|
+
headers: {
|
|
106
|
+
"Content-Length": ContentLength?.toString() ?? "0",
|
|
107
|
+
"Content-Type": ContentType,
|
|
108
|
+
...ETag && { ETag },
|
|
109
|
+
...Expires && { "X-Upload-Expires": Expires.toString() },
|
|
110
|
+
...LastModified && { "Last-Modified": LastModified.toString() }
|
|
111
|
+
},
|
|
112
|
+
size: Number(ContentLength),
|
|
113
|
+
stream: readableStream
|
|
114
|
+
};
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
getS3Api() {
|
|
118
|
+
return this.s3Api;
|
|
119
|
+
}
|
|
120
|
+
// eslint-disable-next-line class-methods-use-this
|
|
121
|
+
getFileClass() {
|
|
122
|
+
return AwsLightFile;
|
|
123
|
+
}
|
|
124
|
+
// eslint-disable-next-line class-methods-use-this
|
|
125
|
+
getAcl() {
|
|
126
|
+
return void 0;
|
|
127
|
+
}
|
|
128
|
+
async accessCheck(_maxWaitTime = 30) {
|
|
129
|
+
await this.s3Api.checkBucketAccess({ Bucket: this.bucket });
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export { AwsLightStorage as default };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { BlobServiceClient, StorageSharedKeyCredential } from '@azure/storage-blob';
|
|
2
|
+
import { throwErrorCode, ERRORS } from './ERRORS-D0apMqnc.js';
|
|
3
|
+
import MetaStorage from './MetaStorage-pECeFOad.js';
|
|
4
|
+
import { parseMetadata, stringifyMetadata } from './Metadata-DRLXeJ0F.js';
|
|
5
|
+
|
|
6
|
+
class AzureMetaStorage extends MetaStorage {
|
|
7
|
+
constructor(config) {
|
|
8
|
+
super(config);
|
|
9
|
+
this.config = config;
|
|
10
|
+
const { client, ...metaConfig } = config;
|
|
11
|
+
if (client === void 0) {
|
|
12
|
+
const connectionString = metaConfig.connectionString || process.env.AZURE_STORAGE_CONNECTION_STRING || void 0;
|
|
13
|
+
if (connectionString) {
|
|
14
|
+
this.client = BlobServiceClient.fromConnectionString(connectionString);
|
|
15
|
+
} else {
|
|
16
|
+
const accountKey = metaConfig.accountKey || process.env.AZURE_STORAGE_ACCOUNT_KEY || void 0;
|
|
17
|
+
const accountName = metaConfig.accountName || process.env.AZURE_STORAGE_ACCOUNT || void 0;
|
|
18
|
+
if (!metaConfig.accountKey) {
|
|
19
|
+
throw new Error("Missing required parameter: Azure blob storage account key.");
|
|
20
|
+
}
|
|
21
|
+
if (!metaConfig.accountName) {
|
|
22
|
+
throw new Error("Missing required parameter: Azure blob storage account name.");
|
|
23
|
+
}
|
|
24
|
+
const signedCredentials = new StorageSharedKeyCredential(accountName, accountKey);
|
|
25
|
+
this.client = new BlobServiceClient(config.endpoint ?? `https://${accountName}.blob.core.windows.net`, signedCredentials);
|
|
26
|
+
}
|
|
27
|
+
} else {
|
|
28
|
+
this.client = client;
|
|
29
|
+
}
|
|
30
|
+
const containerName = metaConfig.containerName || process.env.AZURE_STORAGE_CONTAINER || void 0;
|
|
31
|
+
if (!containerName) {
|
|
32
|
+
throw new Error("Missing required parameter: Azure container name.");
|
|
33
|
+
}
|
|
34
|
+
this.containerClient = this.client.getContainerClient(metaConfig.containerName);
|
|
35
|
+
}
|
|
36
|
+
client;
|
|
37
|
+
containerClient;
|
|
38
|
+
async get(id) {
|
|
39
|
+
const appendBlobClient = this.containerClient.getAppendBlobClient(this.getMetaName(id));
|
|
40
|
+
let propertyData;
|
|
41
|
+
try {
|
|
42
|
+
propertyData = await appendBlobClient.getProperties();
|
|
43
|
+
} catch {
|
|
44
|
+
throw throwErrorCode(ERRORS.UNKNOWN_ERROR);
|
|
45
|
+
}
|
|
46
|
+
if (!propertyData.metadata) {
|
|
47
|
+
throw throwErrorCode(ERRORS.FILE_NOT_FOUND);
|
|
48
|
+
}
|
|
49
|
+
const file = propertyData.metadata;
|
|
50
|
+
if (file.metadata && typeof file.metadata === "string") {
|
|
51
|
+
file.metadata = parseMetadata(file.metadata);
|
|
52
|
+
}
|
|
53
|
+
return file;
|
|
54
|
+
}
|
|
55
|
+
async touch(id, file) {
|
|
56
|
+
return this.save(id, file);
|
|
57
|
+
}
|
|
58
|
+
async delete(id) {
|
|
59
|
+
const blobClient = this.containerClient.getBlockBlobClient(this.getMetaName(id));
|
|
60
|
+
await blobClient.deleteIfExists();
|
|
61
|
+
}
|
|
62
|
+
async save(id, file) {
|
|
63
|
+
const transformedMetadata = { ...file };
|
|
64
|
+
if (transformedMetadata.metadata) {
|
|
65
|
+
transformedMetadata.metadata = stringifyMetadata(file.metadata);
|
|
66
|
+
}
|
|
67
|
+
const appendBlobClient = this.containerClient.getAppendBlobClient(this.getMetaName(id));
|
|
68
|
+
await appendBlobClient.setMetadata(transformedMetadata, {});
|
|
69
|
+
return file;
|
|
70
|
+
}
|
|
71
|
+
async list() {
|
|
72
|
+
const blobs = [];
|
|
73
|
+
const iterator = this.containerClient.listBlobsFlat({
|
|
74
|
+
prefix: this.prefix
|
|
75
|
+
});
|
|
76
|
+
for await (const blob of iterator) {
|
|
77
|
+
blobs.push(blob);
|
|
78
|
+
}
|
|
79
|
+
return blobs.filter((blob) => blob.name.endsWith(this.suffix)).map((blob) => {
|
|
80
|
+
return {
|
|
81
|
+
createdAt: blob.properties.createdOn,
|
|
82
|
+
id: this.getIdFromMetaName(blob.name)
|
|
83
|
+
};
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export { AzureMetaStorage as default };
|