@visulima/storage 1.0.0-alpha.14 → 1.0.0-alpha.16
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 +25 -0
- package/LICENSE.md +1094 -382
- package/dist/adapter/nuxt/module.d.ts +41 -34
- package/dist/handler/http/fetch/index.d.ts +297 -4
- package/dist/handler/http/hono/index.d.ts +1474 -58
- package/dist/handler/http/nextjs/index.d.ts +66 -58
- package/dist/handler/http/node/index.d.ts +361 -4
- package/dist/handler/http/solid-start/index.d.ts +66 -57
- package/dist/index.d.ts +376 -17
- package/dist/openapi/index.d.ts +24 -5
- package/dist/packem_shared/{GCSMetaStorage-BjdSXKri.js → GCSMetaStorage-CNXq7vGd.js} +1 -1
- package/dist/packem_shared/{GCStorage-D3JVWisH.js → GCStorage-CdnSuQwa.js} +1 -1
- package/dist/packem_shared/S3Client.d-CZ62Jztg.d.ts +20357 -0
- package/dist/packem_shared/disk-storage-with-checksum.d-hEoe2ugb.d.ts +148 -0
- package/dist/packem_shared/{gcs-meta-storage-C8rMsqR_.js → gcs-meta-storage-B5AVt1aS.js} +1 -1
- package/dist/packem_shared/local-meta-storage.d-Dop9RP9k.d.ts +20 -0
- package/dist/packem_shared/media-transformer.d-DeHZkBVx.d.ts +331 -0
- package/dist/packem_shared/s3-base-storage.d-CczjSe98.d.ts +251 -0
- package/dist/packem_shared/storage.d-BOMUJD96.d.ts +939 -0
- package/dist/packem_shared/tus-base.d-BftIixIA.d.ts +99 -0
- package/dist/packem_shared/types.d-BPd_JkW1.d.ts +708 -0
- package/dist/packem_shared/types.d-D-mlfmef.d.ts +49 -0
- package/dist/storage/aws/clients/index.d.ts +166 -6
- package/dist/storage/aws/index.d.ts +320 -4
- package/dist/storage/aws-light/index.d.ts +252 -4
- package/dist/storage/azure/index.d.ts +10422 -4
- package/dist/storage/gcs/index.d.ts +4107 -5
- package/dist/storage/gcs/index.js +2 -2
- package/dist/storage/local/index.d.ts +7 -4
- package/dist/storage/netlify-blob/index.d.ts +142 -4
- package/dist/storage/vercel-blob/index.d.ts +129 -4
- package/dist/transformer/audio-transformer.d.ts +127 -125
- package/dist/transformer/image-transformer.d.ts +569 -568
- package/dist/transformer/index.d.ts +62 -5
- package/dist/transformer/video-transformer.d.ts +144 -142
- package/package.json +38 -38
- package/dist/handler/base/base-handler-core.d.ts +0 -91
- package/dist/handler/base/base-handler-fetch.d.ts +0 -76
- package/dist/handler/base/base-handler-node.d.ts +0 -137
- package/dist/handler/multipart/multipart-base.d.ts +0 -84
- package/dist/handler/multipart/multipart-fetch.d.ts +0 -64
- package/dist/handler/multipart/multipart.d.ts +0 -49
- package/dist/handler/rest/rest-base.d.ts +0 -106
- package/dist/handler/rest/rest-fetch.d.ts +0 -88
- package/dist/handler/rest/rest.d.ts +0 -93
- package/dist/handler/tus/tus-base.d.ts +0 -152
- package/dist/handler/tus/tus-fetch.d.ts +0 -72
- package/dist/handler/tus/tus.d.ts +0 -78
- package/dist/handler/types.d.ts +0 -53
- package/dist/handler/utils/request-parser.d.ts +0 -72
- package/dist/handler/utils/response-builder.d.ts +0 -83
- package/dist/handler/utils/storage-utils.d.ts +0 -10
- package/dist/handler/utils/stream-utils.d.ts +0 -29
- package/dist/handler/utils/upload-handlers.d.ts +0 -76
- package/dist/metrics/index.d.ts +0 -2
- package/dist/metrics/no-op-metrics.d.ts +0 -15
- package/dist/metrics/opentelemetry-metrics.d.ts +0 -55
- package/dist/openapi/rest.d.ts +0 -7
- package/dist/openapi/shared.d.ts +0 -13
- package/dist/openapi/transform.d.ts +0 -3
- package/dist/openapi/tus.d.ts +0 -7
- package/dist/openapi/xhr.d.ts +0 -7
- package/dist/storage/aws/clients/backblaze.d.ts +0 -12
- package/dist/storage/aws/clients/cloudflare.d.ts +0 -13
- package/dist/storage/aws/clients/digital-ocean.d.ts +0 -12
- package/dist/storage/aws/clients/minio.d.ts +0 -13
- package/dist/storage/aws/clients/tigris.d.ts +0 -12
- package/dist/storage/aws/clients/types.d.ts +0 -95
- package/dist/storage/aws/clients/wasabi.d.ts +0 -12
- package/dist/storage/aws/s3-base-storage.d.ts +0 -248
- package/dist/storage/aws/s3-client-adapter.d.ts +0 -110
- package/dist/storage/aws/s3-file.d.ts +0 -10
- package/dist/storage/aws/s3-meta-storage.d.ts +0 -15
- package/dist/storage/aws/s3-storage.d.ts +0 -70
- package/dist/storage/aws/types.d.ts +0 -118
- package/dist/storage/aws-light/aws-light-api-adapter.d.ts +0 -130
- package/dist/storage/aws-light/aws-light-file.d.ts +0 -10
- package/dist/storage/aws-light/aws-light-meta-storage.d.ts +0 -19
- package/dist/storage/aws-light/aws-light-storage.d.ts +0 -66
- package/dist/storage/aws-light/types.d.ts +0 -36
- package/dist/storage/azure/azure-file.d.ts +0 -6
- package/dist/storage/azure/azure-meta-storage.d.ts +0 -15
- package/dist/storage/azure/azure-storage.d.ts +0 -69
- package/dist/storage/azure/types.d.ts +0 -61
- package/dist/storage/gcs/fetch-error.d.ts +0 -11
- package/dist/storage/gcs/gcs-config.d.ts +0 -2
- package/dist/storage/gcs/gcs-file.d.ts +0 -6
- package/dist/storage/gcs/gcs-meta-storage.d.ts +0 -27
- package/dist/storage/gcs/gcs-storage.d.ts +0 -91
- package/dist/storage/gcs/types.d.ts +0 -54
- package/dist/storage/gcs/utils.d.ts +0 -7
- package/dist/storage/local/disk-storage-with-checksum.d.ts +0 -15
- package/dist/storage/local/disk-storage.d.ts +0 -135
- package/dist/storage/local/local-meta-storage.d.ts +0 -27
- package/dist/storage/meta-storage-options.d.ts +0 -11
- package/dist/storage/meta-storage.d.ts +0 -30
- package/dist/storage/netlify-blob/netlify-blob-file.d.ts +0 -12
- package/dist/storage/netlify-blob/netlify-blob-meta-storage.d.ts +0 -6
- package/dist/storage/netlify-blob/netlify-blob-storage.d.ts +0 -93
- package/dist/storage/netlify-blob/types.d.ts +0 -29
- package/dist/storage/storage.d.ts +0 -353
- package/dist/storage/types.d.ts +0 -217
- package/dist/storage/utils/file/file.d.ts +0 -25
- package/dist/storage/utils/file/get-file-status.d.ts +0 -9
- package/dist/storage/utils/file/has-content.d.ts +0 -9
- package/dist/storage/utils/file/index.d.ts +0 -10
- package/dist/storage/utils/file/is-expired.d.ts +0 -8
- package/dist/storage/utils/file/metadata.d.ts +0 -18
- package/dist/storage/utils/file/part-match.d.ts +0 -11
- package/dist/storage/utils/file/types.d.ts +0 -37
- package/dist/storage/utils/file/update-metadata.d.ts +0 -10
- package/dist/storage/utils/file/update-size.d.ts +0 -10
- package/dist/storage/vercel-blob/types.d.ts +0 -31
- package/dist/storage/vercel-blob/vercel-blob-file.d.ts +0 -16
- package/dist/storage/vercel-blob/vercel-blob-meta-storage.d.ts +0 -6
- package/dist/storage/vercel-blob/vercel-blob-storage.d.ts +0 -76
- package/dist/transformer/base-transformer.d.ts +0 -63
- package/dist/transformer/media-transformer.d.ts +0 -332
- package/dist/transformer/transformer-config.d.ts +0 -16
- package/dist/transformer/types.d.ts +0 -639
- package/dist/transformer/utils.d.ts +0 -33
- package/dist/transformer/validation-error.d.ts +0 -23
- package/dist/utils/cache.d.ts +0 -32
- package/dist/utils/chunked-upload.d.ts +0 -65
- package/dist/utils/detect-file-type.d.ts +0 -28
- package/dist/utils/errors.d.ts +0 -74
- package/dist/utils/file-path-url-matcher.d.ts +0 -18
- package/dist/utils/headers.d.ts +0 -111
- package/dist/utils/http.d.ts +0 -92
- package/dist/utils/locker.d.ts +0 -26
- package/dist/utils/pipes/stream-checksum.d.ts +0 -47
- package/dist/utils/pipes/stream-length.d.ts +0 -22
- package/dist/utils/primitives/get-last-one.d.ts +0 -3
- package/dist/utils/primitives/is-record.d.ts +0 -2
- package/dist/utils/primitives/map-values.d.ts +0 -9
- package/dist/utils/primitives/pick.d.ts +0 -2
- package/dist/utils/primitives/to-milliseconds.d.ts +0 -12
- package/dist/utils/primitives/to-seconds.d.ts +0 -12
- package/dist/utils/range-checksum.d.ts +0 -33
- package/dist/utils/range-hasher.d.ts +0 -46
- package/dist/utils/retry.d.ts +0 -64
- package/dist/utils/types.d.ts +0 -108
- package/dist/utils/validation-error.d.ts +0 -22
- package/dist/utils/validator.d.ts +0 -36
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { F as File, M as MetaStorage, D as DiskStorageOptions, H as HttpError, b as FileInit, d as FilePart, e as FileQuery, a as FileReturn, E as ERRORS, B as BaseStorage, h as DiskStorageWithChecksumOptions } from "./storage.d-BOMUJD96.js";
|
|
2
|
+
import { Readable } from 'node:stream';
|
|
3
|
+
/**
|
|
4
|
+
* Local disk-based storage implementation.
|
|
5
|
+
* @template TFile The file type used by this storage backend.
|
|
6
|
+
* @remarks
|
|
7
|
+
* ## Error Handling
|
|
8
|
+
* - Filesystem operations throw errors directly (no retry logic)
|
|
9
|
+
* - File not found errors are thrown immediately
|
|
10
|
+
* - Permission errors are propagated as-is
|
|
11
|
+
*
|
|
12
|
+
* ## Retry Behavior
|
|
13
|
+
* - No automatic retries (filesystem operations are typically immediate)
|
|
14
|
+
* - Errors are thrown directly for immediate feedback
|
|
15
|
+
*
|
|
16
|
+
* ## File Paths
|
|
17
|
+
* - Files are stored in the configured directory
|
|
18
|
+
* - Metadata files use the `.META` suffix by default
|
|
19
|
+
* - File paths are resolved relative to the storage directory
|
|
20
|
+
*/
|
|
21
|
+
declare class DiskStorage<TFile extends File = File> extends BaseStorage<TFile> {
|
|
22
|
+
static override readonly name: string;
|
|
23
|
+
override checksumTypes: string[];
|
|
24
|
+
directory: string;
|
|
25
|
+
meta: MetaStorage<TFile>;
|
|
26
|
+
constructor(config: DiskStorageOptions<TFile>);
|
|
27
|
+
/**
|
|
28
|
+
* Normalizes errors with disk storage context.
|
|
29
|
+
* @param error The error to normalize.
|
|
30
|
+
* @returns Normalized HTTP error.
|
|
31
|
+
*/
|
|
32
|
+
override normalizeError(error: Error): HttpError;
|
|
33
|
+
/**
|
|
34
|
+
* Creates a new file upload and saves its metadata.
|
|
35
|
+
* @param fileInit File initialization configuration.
|
|
36
|
+
* @returns Promise resolving to the created file object.
|
|
37
|
+
* @throws {Error} If validation fails or file already exists and is completed.
|
|
38
|
+
* @remarks
|
|
39
|
+
* Supports TTL (time-to-live) option in fileInit.
|
|
40
|
+
* Creates the file on disk if it doesn't exist.
|
|
41
|
+
* Returns existing file if it's already completed.
|
|
42
|
+
*/
|
|
43
|
+
create(fileInit: FileInit): Promise<TFile>;
|
|
44
|
+
/**
|
|
45
|
+
* Writes data to a file upload.
|
|
46
|
+
* @param part File part containing data to write, file query, or full file object.
|
|
47
|
+
* @returns Promise resolving to the updated file object.
|
|
48
|
+
* @throws {Error} If file is expired (ERRORS.GONE), locked (ERRORS.FILE_LOCKED), or conflicts occur (ERRORS.FILE_CONFLICT).
|
|
49
|
+
* @remarks
|
|
50
|
+
* Supports chunked uploads with start position.
|
|
51
|
+
* Automatically detects file type from stream on first chunk if contentType is not set.
|
|
52
|
+
* Validates checksum algorithms if provided.
|
|
53
|
+
* Uses file locking to prevent concurrent writes.
|
|
54
|
+
* Updates file status to "completed" when all bytes are written.
|
|
55
|
+
*/
|
|
56
|
+
write(part: FilePart | FileQuery | TFile): Promise<TFile>;
|
|
57
|
+
/**
|
|
58
|
+
* Gets an uploaded file by ID.
|
|
59
|
+
* @param query File query containing the file ID to retrieve.
|
|
60
|
+
* @param query.id File ID to retrieve.
|
|
61
|
+
* @returns Promise resolving to the file data including content buffer.
|
|
62
|
+
* @throws {Error} If the file cannot be found (ERRORS.FILE_NOT_FOUND) or has expired (ERRORS.GONE).
|
|
63
|
+
* @remarks
|
|
64
|
+
* Loads the entire file content into memory as a Buffer.
|
|
65
|
+
* For large files, consider using getStream() instead.
|
|
66
|
+
* Includes ETag (MD5 hash) for content verification.
|
|
67
|
+
*/
|
|
68
|
+
get({
|
|
69
|
+
id
|
|
70
|
+
}: FileQuery): Promise<FileReturn>;
|
|
71
|
+
/**
|
|
72
|
+
* Checks if a file exists by verifying both metadata and the actual filesystem file.
|
|
73
|
+
* Returns true only if both the metadata and the file exist.
|
|
74
|
+
* @param query File query containing the file ID to check.
|
|
75
|
+
* @returns Promise resolving to true if both metadata and file exist, false otherwise.
|
|
76
|
+
*/
|
|
77
|
+
override exists({
|
|
78
|
+
id
|
|
79
|
+
}: FileQuery): Promise<boolean>;
|
|
80
|
+
/**
|
|
81
|
+
* Gets an uploaded file as a readable stream for efficient large file handling.
|
|
82
|
+
* @param query File query containing the file ID to stream.
|
|
83
|
+
* @param query.id File ID to stream.
|
|
84
|
+
* @returns Promise resolving to an object containing the stream, headers, and size.
|
|
85
|
+
* @throws {UploadError} If the file cannot be found (ERRORS.FILE_NOT_FOUND) or has expired (ERRORS.GONE).
|
|
86
|
+
* @remarks Creates a readable stream directly from the file system for efficient memory usage.
|
|
87
|
+
*/
|
|
88
|
+
override getStream({
|
|
89
|
+
id
|
|
90
|
+
}: FileQuery): Promise<{
|
|
91
|
+
headers?: Record<string, string>;
|
|
92
|
+
size?: number;
|
|
93
|
+
stream: Readable;
|
|
94
|
+
}>;
|
|
95
|
+
/**
|
|
96
|
+
* Deletes an upload and its metadata.
|
|
97
|
+
* @param query File query containing the file ID to delete.
|
|
98
|
+
* @param query.id File ID to delete.
|
|
99
|
+
* @returns Promise resolving to the deleted file object with status: "deleted".
|
|
100
|
+
* @throws {UploadError} If the file metadata cannot be found.
|
|
101
|
+
*/
|
|
102
|
+
delete({
|
|
103
|
+
id
|
|
104
|
+
}: FileQuery): Promise<TFile>;
|
|
105
|
+
/**
|
|
106
|
+
* Copies an upload file to a new location.
|
|
107
|
+
* @param name Source file name/ID.
|
|
108
|
+
* @param destination Destination file name/ID.
|
|
109
|
+
* @returns Promise resolving to the copied file object.
|
|
110
|
+
* @throws {UploadError} If the source file cannot be found.
|
|
111
|
+
*/
|
|
112
|
+
copy(name: string, destination: string): Promise<TFile>;
|
|
113
|
+
/**
|
|
114
|
+
* Moves an upload file to a new location.
|
|
115
|
+
* @param name Source file name/ID.
|
|
116
|
+
* @param destination Destination file name/ID.
|
|
117
|
+
* @returns Promise resolving to the moved file object.
|
|
118
|
+
* @throws {Error} If the source file cannot be found.
|
|
119
|
+
*/
|
|
120
|
+
move(name: string, destination: string): Promise<TFile>;
|
|
121
|
+
/**
|
|
122
|
+
* Retrieves a list of uploaded files.
|
|
123
|
+
* @returns Promise resolving to an array of file metadata objects.
|
|
124
|
+
* @remarks Walks the storage directory and returns all files, excluding metadata files.
|
|
125
|
+
*/
|
|
126
|
+
override list(): Promise<TFile[]>;
|
|
127
|
+
/**
|
|
128
|
+
* Returns path for the uploaded file
|
|
129
|
+
* If filename is already an absolute path, returns it as-is.
|
|
130
|
+
* Otherwise, joins it with the storage directory.
|
|
131
|
+
*/
|
|
132
|
+
protected getFilePath(filename: string): string;
|
|
133
|
+
protected lazyWrite(part: File & FilePart): Promise<[number, ERRORS?]>;
|
|
134
|
+
private accessCheck;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Additionally calculates checksum of the file/range.
|
|
138
|
+
*/
|
|
139
|
+
declare class DiskStorageWithChecksum<TFile extends File = File> extends DiskStorage<TFile> {
|
|
140
|
+
private hashes;
|
|
141
|
+
constructor(config: DiskStorageWithChecksumOptions<TFile>);
|
|
142
|
+
override delete({
|
|
143
|
+
id
|
|
144
|
+
}: FileQuery): Promise<TFile>;
|
|
145
|
+
override write(part: FilePart | FileQuery): Promise<TFile>;
|
|
146
|
+
protected override lazyWrite(part: File & FilePart): Promise<[number, ERRORS?]>;
|
|
147
|
+
}
|
|
148
|
+
export { DiskStorage as D, DiskStorageWithChecksum as a };
|
|
@@ -7,7 +7,7 @@ import GCSConfig from './GCSConfig-vPP22kN6.js';
|
|
|
7
7
|
import { h as hasContent } from './has-content-CY66ehMK.js';
|
|
8
8
|
|
|
9
9
|
var name = "@visulima/storage";
|
|
10
|
-
var version = "1.0.0-alpha.
|
|
10
|
+
var version = "1.0.0-alpha.15";
|
|
11
11
|
const package_ = {
|
|
12
12
|
name: name,
|
|
13
13
|
version: version};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { F as File, L as LocalMetaStorageOptions, M as MetaStorage } from "./storage.d-BOMUJD96.js";
|
|
2
|
+
import 'node:stream';
|
|
3
|
+
/**
|
|
4
|
+
* Stores upload metafiles on local disk
|
|
5
|
+
*/
|
|
6
|
+
declare class LocalMetaStorage<T extends File = File> extends MetaStorage<T> {
|
|
7
|
+
readonly directory: string;
|
|
8
|
+
constructor(config?: LocalMetaStorageOptions);
|
|
9
|
+
/**
|
|
10
|
+
* Returns metafile path.
|
|
11
|
+
* @param id upload id
|
|
12
|
+
*/
|
|
13
|
+
getMetaPath: (id: string) => string;
|
|
14
|
+
override save(id: string, file: T): Promise<T>;
|
|
15
|
+
override touch(id: string, file: T): Promise<T>;
|
|
16
|
+
override get(id: string): Promise<T>;
|
|
17
|
+
override delete(id: string): Promise<void>;
|
|
18
|
+
private accessCheck;
|
|
19
|
+
}
|
|
20
|
+
export { LocalMetaStorage as L };
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
import { F as File, a as FileReturn, B as BaseStorage } from "./storage.d-BOMUJD96.js";
|
|
2
|
+
import { O as MediaTransformerConfig, Q as MediaTransformResult } from "./types.d-BPd_JkW1.js";
|
|
3
|
+
/**
|
|
4
|
+
* Unified media transformer that automatically detects media type and routes to appropriate transformer.
|
|
5
|
+
* @template TFile The file type used by this transformer.
|
|
6
|
+
* @template TFileReturn The return type for file retrieval operations.
|
|
7
|
+
*
|
|
8
|
+
* Supports transformations via query parameters for on-demand media processing across all supported formats.
|
|
9
|
+
* @example
|
|
10
|
+
* // eslint-disable-next-line jsdoc/match-description
|
|
11
|
+
* ```ts
|
|
12
|
+
* const transformer = new MediaTransformer(storage, {
|
|
13
|
+
* maxImageSize: 10 * 1024 * 1024, // 10MB
|
|
14
|
+
* maxVideoSize: 100 * 1024 * 1024, // 100MB
|
|
15
|
+
* maxAudioSize: 50 * 1024 * 1024, // 50MB
|
|
16
|
+
* cache: new MapCache(), // In-memory caching
|
|
17
|
+
* saveTransformedFiles: true // Persist transformed files to storage
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* // Handle transformation via query parameters
|
|
21
|
+
* const result = await transformer.handle('file-id', {
|
|
22
|
+
* width: 800,
|
|
23
|
+
* height: 600,
|
|
24
|
+
* fit: 'cover',
|
|
25
|
+
* format: 'webp',
|
|
26
|
+
* quality: 80
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* // Fetch with URL query string
|
|
30
|
+
* const result = await transformer.fetch('file-id', 'width=1280&height=720&codec=avc&bitrate=2000000');
|
|
31
|
+
*
|
|
32
|
+
* // Clear all cached transformed files
|
|
33
|
+
* transformer.clearSavedTransformedFiles();
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* ## Configuration Options
|
|
37
|
+
*
|
|
38
|
+
* - `saveTransformedFiles`: Persist transformed files to storage for reuse (default: false)
|
|
39
|
+
* - `cache`: Cache instance for in-memory caching (optional)
|
|
40
|
+
* - `maxImageSize/maxVideoSize/maxAudioSize`: Size limits for processing
|
|
41
|
+
* - `cacheTtl`: Cache time-to-live in seconds
|
|
42
|
+
*
|
|
43
|
+
* ## Supported Query Parameters
|
|
44
|
+
*
|
|
45
|
+
* ### Common Parameters
|
|
46
|
+
* - `format`: Output format (jpeg/png/webp/avif/mp4/webm/mkv/mp3/wav/ogg/aac/flac)
|
|
47
|
+
* - `quality`: Quality for images (0-100), bitrate for video/audio
|
|
48
|
+
*
|
|
49
|
+
* ### Image Parameters
|
|
50
|
+
* - `width`: Width in pixels
|
|
51
|
+
* - `height`: Height in pixels
|
|
52
|
+
* - `fit`: Resize fit mode - cover/contain/fill/inside/outside
|
|
53
|
+
* - `position`: Position for cover/contain fits
|
|
54
|
+
* - `withoutEnlargement`: Avoid enlarging smaller images (boolean)
|
|
55
|
+
* - `withoutReduction`: Avoid reducing larger images (boolean)
|
|
56
|
+
* - `kernel`: Resize kernel - nearest/cubic/mitchell/lanczos2/lanczos3
|
|
57
|
+
* - `fastShrinkOnLoad`: Fast shrink on load (boolean)
|
|
58
|
+
* - `left/top/cropWidth/cropHeight`: Crop parameters
|
|
59
|
+
* - `angle`: Rotation angle in degrees (any number, but angles other than 90°/180°/270° use interpolation and may affect quality)
|
|
60
|
+
* - `background`: Background color for rotation
|
|
61
|
+
* - `blur`: Apply blur effect (boolean)
|
|
62
|
+
* - `sharpen`: Apply sharpening (boolean)
|
|
63
|
+
* - `median`: Apply median filter with size (number)
|
|
64
|
+
* // eslint-disable-next-line jsdoc/match-description
|
|
65
|
+
* - `clahe`: Apply CLAHE (Contrast Limited Adaptive Histogram Equalization) (boolean)
|
|
66
|
+
* - `threshold`: Apply thresholding with value (0-255)
|
|
67
|
+
* - `gamma`: Apply gamma correction (boolean)
|
|
68
|
+
* - `negate`: Negate (invert) the image (boolean)
|
|
69
|
+
* - `normalise/normalize`: Normalise the image (boolean)
|
|
70
|
+
* - `flatten`: Flatten alpha channel (boolean)
|
|
71
|
+
* - `unflatten`: Unflatten alpha channel (boolean)
|
|
72
|
+
* - `flip`: Flip image vertically (boolean)
|
|
73
|
+
* - `flop`: Flop image horizontally (boolean)
|
|
74
|
+
* - `greyscale/grayscale`: Convert to greyscale (boolean)
|
|
75
|
+
* - `modulate`: Apply modulation effects (boolean)
|
|
76
|
+
* - `brightness`: Brightness multiplier for modulation (number)
|
|
77
|
+
* - `saturation`: Saturation multiplier for modulation (number)
|
|
78
|
+
* - `hue`: Hue rotation in degrees for modulation (number)
|
|
79
|
+
* // eslint-disable-next-line jsdoc/match-description
|
|
80
|
+
* - `lightness`: Lightness adjustment for modulation (number)
|
|
81
|
+
* - `tint`: Apply tinting (boolean)
|
|
82
|
+
* - `colourspace`: Convert colourspace - srgb/rgb/cmyk/lab/b-w
|
|
83
|
+
*
|
|
84
|
+
* ### Video Parameters
|
|
85
|
+
* - `width/height/fit`: Same as images
|
|
86
|
+
* - `codec`: Video codec - avc/hevc/vp8/vp9/av1
|
|
87
|
+
* - `bitrate`: Video bitrate in bits per second
|
|
88
|
+
* - `frameRate`: Frame rate in Hz
|
|
89
|
+
* - `keyFrameInterval`: Key frame interval in seconds
|
|
90
|
+
* - `angle`: Rotation angle in degrees (any number, but angles other than 90°/180°/270° use interpolation and may affect quality)
|
|
91
|
+
* - `background`: Background color for rotation
|
|
92
|
+
*
|
|
93
|
+
* ### Audio Parameters
|
|
94
|
+
* - `sampleRate`: Sample rate in Hz
|
|
95
|
+
* - `numberOfChannels`: Number of channels
|
|
96
|
+
* - `codec`: Audio codec - aac/opus/mp3/vorbis/flac
|
|
97
|
+
* - `bitrate`: Audio bitrate in bits per second
|
|
98
|
+
*
|
|
99
|
+
* ## File Persistence
|
|
100
|
+
*
|
|
101
|
+
* When `saveTransformedFiles` is enabled, transformed files are automatically saved to storage
|
|
102
|
+
* with deterministic IDs based on the original file and transformation parameters. Subsequent
|
|
103
|
+
* requests for the same transformation will serve the cached file directly, improving performance
|
|
104
|
+
* and reducing processing costs.
|
|
105
|
+
*/
|
|
106
|
+
declare class MediaTransformer<TFile extends File = File, TFileReturn extends FileReturn = FileReturn> {
|
|
107
|
+
private readonly storage;
|
|
108
|
+
private readonly imageTransformer?;
|
|
109
|
+
private readonly videoTransformer?;
|
|
110
|
+
private readonly audioTransformer?;
|
|
111
|
+
private readonly config;
|
|
112
|
+
private readonly logger;
|
|
113
|
+
/**
|
|
114
|
+
* Creates a new MediaTransformer instance.
|
|
115
|
+
* @param storage The storage backend for retrieving and storing media files.
|
|
116
|
+
* @param config Configuration options for the media transformer including transformer classes and settings.
|
|
117
|
+
* @throws Error if no transformer classes are provided in the configuration.
|
|
118
|
+
*/
|
|
119
|
+
constructor(storage: BaseStorage<TFile, TFileReturn>, config?: MediaTransformerConfig<TFile, TFileReturn>);
|
|
120
|
+
supportedFormats(): string[];
|
|
121
|
+
/**
|
|
122
|
+
* Handles media transformation based on query parameters.
|
|
123
|
+
* @param fileId File identifier.
|
|
124
|
+
* @param query Query parameters for transformation.
|
|
125
|
+
* @returns Unified transformation result.
|
|
126
|
+
*/
|
|
127
|
+
handle(fileId: string, query: Record<string, string | undefined> | URLSearchParams | string): Promise<MediaTransformResult>;
|
|
128
|
+
/**
|
|
129
|
+
* Fetches media transformation with URL query string support.
|
|
130
|
+
* @param fileId File identifier.
|
|
131
|
+
* @param queryString URL query string (e.g., "width=800&height=600&format=webp").
|
|
132
|
+
* @returns Unified transformation result.
|
|
133
|
+
*/
|
|
134
|
+
fetch(fileId: string, queryString: string): Promise<MediaTransformResult>;
|
|
135
|
+
/**
|
|
136
|
+
* Clears cache for a specific file across all transformers.
|
|
137
|
+
* @param fileId Optional file identifier to clear cache for. If omitted, clears all cache.
|
|
138
|
+
*/
|
|
139
|
+
clearCache(fileId?: string): void;
|
|
140
|
+
/**
|
|
141
|
+
* Clears all saved transformed files from storage.
|
|
142
|
+
* @remarks This is a maintenance operation and may take time for large numbers of files.
|
|
143
|
+
*/
|
|
144
|
+
clearSavedTransformedFiles(): Promise<void>;
|
|
145
|
+
/**
|
|
146
|
+
* Clears saved transformed files for a specific original file.
|
|
147
|
+
* @param originalFileId Original file identifier to clear transformed files for.
|
|
148
|
+
*/
|
|
149
|
+
clearSavedTransformedFilesForFile(originalFileId: string): Promise<void>;
|
|
150
|
+
/**
|
|
151
|
+
* Gets cache statistics (combined from all transformers).
|
|
152
|
+
* @returns Cache statistics for audio, image, and video transformers.
|
|
153
|
+
*/
|
|
154
|
+
getCacheStats(): {
|
|
155
|
+
audio?: {
|
|
156
|
+
maxSize: number;
|
|
157
|
+
size: number;
|
|
158
|
+
};
|
|
159
|
+
image?: {
|
|
160
|
+
maxSize: number;
|
|
161
|
+
size: number;
|
|
162
|
+
};
|
|
163
|
+
video?: {
|
|
164
|
+
maxSize: number;
|
|
165
|
+
size: number;
|
|
166
|
+
};
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* Validates query parameters for the given media type.
|
|
170
|
+
* @param query The query parameters to validate.
|
|
171
|
+
* @param mediaType The media type being validated ('image', 'video', or 'audio').
|
|
172
|
+
* @throws {ValidationError} When invalid parameters are provided.
|
|
173
|
+
*/
|
|
174
|
+
private validateQueryParameters;
|
|
175
|
+
/**
|
|
176
|
+
* Validates query parameters for image transformations. Checks for invalid video/audio-only parameters, invalid fit values, invalid rotation angles, invalid formats, and incomplete crop parameter sets.
|
|
177
|
+
* @param query Query parameters to validate.
|
|
178
|
+
* @throws {ValidationError} When validation fails.
|
|
179
|
+
*/
|
|
180
|
+
private validateImageQueryParameters;
|
|
181
|
+
/**
|
|
182
|
+
* Validates query parameters for video transformations. Checks for invalid audio-only parameters, invalid fit values, invalid rotation angles, invalid codecs, invalid formats, incomplete crop parameter sets, and invalid numeric values.
|
|
183
|
+
* @param query Query parameters to validate.
|
|
184
|
+
* @throws {ValidationError} When validation fails.
|
|
185
|
+
*/
|
|
186
|
+
private validateVideoQueryParameters;
|
|
187
|
+
/**
|
|
188
|
+
* Generates a unique ID for transformed files based on original file and transformations.
|
|
189
|
+
* @param originalFileId The original file identifier.
|
|
190
|
+
* @param query The transformation query parameters.
|
|
191
|
+
* @param mediaType The media type (image, video, audio).
|
|
192
|
+
* @returns Unique deterministic identifier for the transformed file.
|
|
193
|
+
* @private
|
|
194
|
+
*/
|
|
195
|
+
private generateTransformedFileId;
|
|
196
|
+
/**
|
|
197
|
+
* Checks if the query contains any transformations.
|
|
198
|
+
* @param query The transformation query parameters.
|
|
199
|
+
* @returns True if any transformations are requested.
|
|
200
|
+
* @private
|
|
201
|
+
*/
|
|
202
|
+
private hasTransformations;
|
|
203
|
+
/**
|
|
204
|
+
* Creates a MediaTransformResult from a stored transformed file.
|
|
205
|
+
* @param storedFile The stored transformed file.
|
|
206
|
+
* @param mediaType The media type (image, video, audio).
|
|
207
|
+
* @param originalFile The original file information.
|
|
208
|
+
* @returns Media transformation result with metadata.
|
|
209
|
+
* @private
|
|
210
|
+
*/
|
|
211
|
+
private createMediaTransformResult;
|
|
212
|
+
/**
|
|
213
|
+
* Extracts format from content type.
|
|
214
|
+
* @param contentType MIME content type string.
|
|
215
|
+
* @returns Format string extracted from content type.
|
|
216
|
+
* @private
|
|
217
|
+
*/
|
|
218
|
+
private getFormatFromContentType;
|
|
219
|
+
/**
|
|
220
|
+
* Saves transformed file to storage.
|
|
221
|
+
* @param result The transformation result to save.
|
|
222
|
+
* @param originalFileId The original file identifier.
|
|
223
|
+
* @param query The transformation query parameters.
|
|
224
|
+
* @param mediaType The media type (image, video, audio).
|
|
225
|
+
* @returns Promise that resolves when file is saved.
|
|
226
|
+
* @private
|
|
227
|
+
*/
|
|
228
|
+
private saveTransformedFile;
|
|
229
|
+
/**
|
|
230
|
+
* Validates query parameters for audio transformations. Checks for invalid video-only parameters, invalid codecs, invalid formats, and invalid numeric values.
|
|
231
|
+
* @param query Query parameters to validate.
|
|
232
|
+
* @throws {ValidationError} When validation fails.
|
|
233
|
+
*/
|
|
234
|
+
private validateAudioQueryParameters;
|
|
235
|
+
/**
|
|
236
|
+
* Handles image transformation.
|
|
237
|
+
* @param fileId The file identifier.
|
|
238
|
+
* @param query The transformation query parameters.
|
|
239
|
+
* @returns Promise resolving to media transformation result.
|
|
240
|
+
* @private
|
|
241
|
+
*/
|
|
242
|
+
private handleImageTransformation;
|
|
243
|
+
/**
|
|
244
|
+
* Handles video transformation.
|
|
245
|
+
* @param fileId The file identifier.
|
|
246
|
+
* @param query The transformation query parameters.
|
|
247
|
+
* @returns Promise resolving to media transformation result.
|
|
248
|
+
* @private
|
|
249
|
+
*/
|
|
250
|
+
private handleVideoTransformation;
|
|
251
|
+
/**
|
|
252
|
+
* Handles audio transformation.
|
|
253
|
+
* @param fileId The file identifier.
|
|
254
|
+
* @param query The transformation query parameters.
|
|
255
|
+
* @returns Promise resolving to media transformation result.
|
|
256
|
+
* @private
|
|
257
|
+
*/
|
|
258
|
+
private handleAudioTransformation;
|
|
259
|
+
/**
|
|
260
|
+
* Parses query parameters from various input formats.
|
|
261
|
+
* @param query Query parameters in various formats.
|
|
262
|
+
* @returns Normalized MediaTransformQuery object.
|
|
263
|
+
* @private
|
|
264
|
+
*/
|
|
265
|
+
private parseQuery;
|
|
266
|
+
/**
|
|
267
|
+
* Parses boolean parameter from string.
|
|
268
|
+
* @param value String value to parse.
|
|
269
|
+
* @returns Boolean value or undefined.
|
|
270
|
+
* @private
|
|
271
|
+
*/
|
|
272
|
+
private parseBooleanParameter;
|
|
273
|
+
/**
|
|
274
|
+
* Parses URLSearchParams into MediaTransformQuery.
|
|
275
|
+
* @param parameters URL search parameters object.
|
|
276
|
+
* @returns MediaTransformQuery object with parsed parameters.
|
|
277
|
+
* @private
|
|
278
|
+
*/
|
|
279
|
+
private parseURLSearchParams;
|
|
280
|
+
/**
|
|
281
|
+
* Detects media type from MIME type.
|
|
282
|
+
* @param contentType MIME content type string.
|
|
283
|
+
* @returns Detected media type.
|
|
284
|
+
* @throws Error if content type is missing or unsupported.
|
|
285
|
+
* @private
|
|
286
|
+
*/
|
|
287
|
+
private detectMediaType;
|
|
288
|
+
/**
|
|
289
|
+
* Checks if query has image transformations.
|
|
290
|
+
* @param query The transformation query parameters.
|
|
291
|
+
* @returns True if image transformations are requested.
|
|
292
|
+
* @private
|
|
293
|
+
*/
|
|
294
|
+
private hasImageTransformations;
|
|
295
|
+
/**
|
|
296
|
+
* Checks if query has video transformations.
|
|
297
|
+
* @param query The transformation query parameters.
|
|
298
|
+
* @returns True if video transformations are requested.
|
|
299
|
+
* @private
|
|
300
|
+
*/
|
|
301
|
+
private hasVideoTransformations;
|
|
302
|
+
/**
|
|
303
|
+
* Checks if query has audio transformations.
|
|
304
|
+
* @param query The transformation query parameters.
|
|
305
|
+
* @returns True if audio transformations are requested.
|
|
306
|
+
* @private
|
|
307
|
+
*/
|
|
308
|
+
private hasAudioTransformations;
|
|
309
|
+
/**
|
|
310
|
+
* Converts ImageTransformer result to unified format.
|
|
311
|
+
* @param result The image transformation result.
|
|
312
|
+
* @returns Unified media transformation result.
|
|
313
|
+
* @private
|
|
314
|
+
*/
|
|
315
|
+
private convertImageResult;
|
|
316
|
+
/**
|
|
317
|
+
* Converts VideoTransformer result to unified format.
|
|
318
|
+
* @param result The video transformation result.
|
|
319
|
+
* @returns Unified media transformation result.
|
|
320
|
+
* @private
|
|
321
|
+
*/
|
|
322
|
+
private convertVideoResult;
|
|
323
|
+
/**
|
|
324
|
+
* Converts AudioTransformer result to unified format.
|
|
325
|
+
* @param result The audio transformation result.
|
|
326
|
+
* @returns Unified media transformation result.
|
|
327
|
+
* @private
|
|
328
|
+
*/
|
|
329
|
+
private convertAudioResult;
|
|
330
|
+
}
|
|
331
|
+
export { MediaTransformer as M };
|