@visulima/storage 1.0.0-alpha.15 → 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.
Files changed (144) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/LICENSE.md +1094 -382
  3. package/dist/adapter/nuxt/module.d.ts +41 -34
  4. package/dist/handler/http/fetch/index.d.ts +297 -4
  5. package/dist/handler/http/hono/index.d.ts +1474 -58
  6. package/dist/handler/http/nextjs/index.d.ts +66 -58
  7. package/dist/handler/http/node/index.d.ts +361 -4
  8. package/dist/handler/http/solid-start/index.d.ts +66 -57
  9. package/dist/index.d.ts +376 -17
  10. package/dist/openapi/index.d.ts +24 -5
  11. package/dist/packem_shared/{GCSMetaStorage-BkUIdJ5m.js → GCSMetaStorage-CNXq7vGd.js} +1 -1
  12. package/dist/packem_shared/{GCStorage-BnsSAjdW.js → GCStorage-CdnSuQwa.js} +1 -1
  13. package/dist/packem_shared/S3Client.d-CZ62Jztg.d.ts +20357 -0
  14. package/dist/packem_shared/disk-storage-with-checksum.d-hEoe2ugb.d.ts +148 -0
  15. package/dist/packem_shared/{gcs-meta-storage-DBeGn2ix.js → gcs-meta-storage-B5AVt1aS.js} +1 -1
  16. package/dist/packem_shared/local-meta-storage.d-Dop9RP9k.d.ts +20 -0
  17. package/dist/packem_shared/media-transformer.d-DeHZkBVx.d.ts +331 -0
  18. package/dist/packem_shared/s3-base-storage.d-CczjSe98.d.ts +251 -0
  19. package/dist/packem_shared/storage.d-BOMUJD96.d.ts +939 -0
  20. package/dist/packem_shared/tus-base.d-BftIixIA.d.ts +99 -0
  21. package/dist/packem_shared/types.d-BPd_JkW1.d.ts +708 -0
  22. package/dist/packem_shared/types.d-D-mlfmef.d.ts +49 -0
  23. package/dist/storage/aws/clients/index.d.ts +166 -6
  24. package/dist/storage/aws/index.d.ts +320 -4
  25. package/dist/storage/aws-light/index.d.ts +252 -4
  26. package/dist/storage/azure/index.d.ts +10422 -4
  27. package/dist/storage/gcs/index.d.ts +4107 -5
  28. package/dist/storage/gcs/index.js +2 -2
  29. package/dist/storage/local/index.d.ts +7 -4
  30. package/dist/storage/netlify-blob/index.d.ts +142 -4
  31. package/dist/storage/vercel-blob/index.d.ts +129 -4
  32. package/dist/transformer/audio-transformer.d.ts +127 -125
  33. package/dist/transformer/image-transformer.d.ts +569 -568
  34. package/dist/transformer/index.d.ts +62 -5
  35. package/dist/transformer/video-transformer.d.ts +144 -142
  36. package/package.json +37 -37
  37. package/dist/handler/base/base-handler-core.d.ts +0 -91
  38. package/dist/handler/base/base-handler-fetch.d.ts +0 -76
  39. package/dist/handler/base/base-handler-node.d.ts +0 -137
  40. package/dist/handler/multipart/multipart-base.d.ts +0 -84
  41. package/dist/handler/multipart/multipart-fetch.d.ts +0 -64
  42. package/dist/handler/multipart/multipart.d.ts +0 -49
  43. package/dist/handler/rest/rest-base.d.ts +0 -106
  44. package/dist/handler/rest/rest-fetch.d.ts +0 -88
  45. package/dist/handler/rest/rest.d.ts +0 -93
  46. package/dist/handler/tus/tus-base.d.ts +0 -152
  47. package/dist/handler/tus/tus-fetch.d.ts +0 -72
  48. package/dist/handler/tus/tus.d.ts +0 -78
  49. package/dist/handler/types.d.ts +0 -53
  50. package/dist/handler/utils/request-parser.d.ts +0 -72
  51. package/dist/handler/utils/response-builder.d.ts +0 -83
  52. package/dist/handler/utils/storage-utils.d.ts +0 -10
  53. package/dist/handler/utils/stream-utils.d.ts +0 -29
  54. package/dist/handler/utils/upload-handlers.d.ts +0 -76
  55. package/dist/metrics/index.d.ts +0 -2
  56. package/dist/metrics/no-op-metrics.d.ts +0 -15
  57. package/dist/metrics/opentelemetry-metrics.d.ts +0 -55
  58. package/dist/openapi/rest.d.ts +0 -7
  59. package/dist/openapi/shared.d.ts +0 -13
  60. package/dist/openapi/transform.d.ts +0 -3
  61. package/dist/openapi/tus.d.ts +0 -7
  62. package/dist/openapi/xhr.d.ts +0 -7
  63. package/dist/storage/aws/clients/backblaze.d.ts +0 -12
  64. package/dist/storage/aws/clients/cloudflare.d.ts +0 -13
  65. package/dist/storage/aws/clients/digital-ocean.d.ts +0 -12
  66. package/dist/storage/aws/clients/minio.d.ts +0 -13
  67. package/dist/storage/aws/clients/tigris.d.ts +0 -12
  68. package/dist/storage/aws/clients/types.d.ts +0 -95
  69. package/dist/storage/aws/clients/wasabi.d.ts +0 -12
  70. package/dist/storage/aws/s3-base-storage.d.ts +0 -248
  71. package/dist/storage/aws/s3-client-adapter.d.ts +0 -110
  72. package/dist/storage/aws/s3-file.d.ts +0 -10
  73. package/dist/storage/aws/s3-meta-storage.d.ts +0 -15
  74. package/dist/storage/aws/s3-storage.d.ts +0 -70
  75. package/dist/storage/aws/types.d.ts +0 -118
  76. package/dist/storage/aws-light/aws-light-api-adapter.d.ts +0 -130
  77. package/dist/storage/aws-light/aws-light-file.d.ts +0 -10
  78. package/dist/storage/aws-light/aws-light-meta-storage.d.ts +0 -19
  79. package/dist/storage/aws-light/aws-light-storage.d.ts +0 -66
  80. package/dist/storage/aws-light/types.d.ts +0 -36
  81. package/dist/storage/azure/azure-file.d.ts +0 -6
  82. package/dist/storage/azure/azure-meta-storage.d.ts +0 -15
  83. package/dist/storage/azure/azure-storage.d.ts +0 -69
  84. package/dist/storage/azure/types.d.ts +0 -61
  85. package/dist/storage/gcs/fetch-error.d.ts +0 -11
  86. package/dist/storage/gcs/gcs-config.d.ts +0 -2
  87. package/dist/storage/gcs/gcs-file.d.ts +0 -6
  88. package/dist/storage/gcs/gcs-meta-storage.d.ts +0 -27
  89. package/dist/storage/gcs/gcs-storage.d.ts +0 -91
  90. package/dist/storage/gcs/types.d.ts +0 -54
  91. package/dist/storage/gcs/utils.d.ts +0 -7
  92. package/dist/storage/local/disk-storage-with-checksum.d.ts +0 -15
  93. package/dist/storage/local/disk-storage.d.ts +0 -135
  94. package/dist/storage/local/local-meta-storage.d.ts +0 -27
  95. package/dist/storage/meta-storage-options.d.ts +0 -11
  96. package/dist/storage/meta-storage.d.ts +0 -30
  97. package/dist/storage/netlify-blob/netlify-blob-file.d.ts +0 -12
  98. package/dist/storage/netlify-blob/netlify-blob-meta-storage.d.ts +0 -6
  99. package/dist/storage/netlify-blob/netlify-blob-storage.d.ts +0 -93
  100. package/dist/storage/netlify-blob/types.d.ts +0 -29
  101. package/dist/storage/storage.d.ts +0 -353
  102. package/dist/storage/types.d.ts +0 -217
  103. package/dist/storage/utils/file/file.d.ts +0 -25
  104. package/dist/storage/utils/file/get-file-status.d.ts +0 -9
  105. package/dist/storage/utils/file/has-content.d.ts +0 -9
  106. package/dist/storage/utils/file/index.d.ts +0 -10
  107. package/dist/storage/utils/file/is-expired.d.ts +0 -8
  108. package/dist/storage/utils/file/metadata.d.ts +0 -18
  109. package/dist/storage/utils/file/part-match.d.ts +0 -11
  110. package/dist/storage/utils/file/types.d.ts +0 -37
  111. package/dist/storage/utils/file/update-metadata.d.ts +0 -10
  112. package/dist/storage/utils/file/update-size.d.ts +0 -10
  113. package/dist/storage/vercel-blob/types.d.ts +0 -31
  114. package/dist/storage/vercel-blob/vercel-blob-file.d.ts +0 -16
  115. package/dist/storage/vercel-blob/vercel-blob-meta-storage.d.ts +0 -6
  116. package/dist/storage/vercel-blob/vercel-blob-storage.d.ts +0 -76
  117. package/dist/transformer/base-transformer.d.ts +0 -63
  118. package/dist/transformer/media-transformer.d.ts +0 -332
  119. package/dist/transformer/transformer-config.d.ts +0 -16
  120. package/dist/transformer/types.d.ts +0 -639
  121. package/dist/transformer/utils.d.ts +0 -33
  122. package/dist/transformer/validation-error.d.ts +0 -23
  123. package/dist/utils/cache.d.ts +0 -32
  124. package/dist/utils/chunked-upload.d.ts +0 -65
  125. package/dist/utils/detect-file-type.d.ts +0 -28
  126. package/dist/utils/errors.d.ts +0 -74
  127. package/dist/utils/file-path-url-matcher.d.ts +0 -18
  128. package/dist/utils/headers.d.ts +0 -111
  129. package/dist/utils/http.d.ts +0 -92
  130. package/dist/utils/locker.d.ts +0 -26
  131. package/dist/utils/pipes/stream-checksum.d.ts +0 -47
  132. package/dist/utils/pipes/stream-length.d.ts +0 -22
  133. package/dist/utils/primitives/get-last-one.d.ts +0 -3
  134. package/dist/utils/primitives/is-record.d.ts +0 -2
  135. package/dist/utils/primitives/map-values.d.ts +0 -9
  136. package/dist/utils/primitives/pick.d.ts +0 -2
  137. package/dist/utils/primitives/to-milliseconds.d.ts +0 -12
  138. package/dist/utils/primitives/to-seconds.d.ts +0 -12
  139. package/dist/utils/range-checksum.d.ts +0 -33
  140. package/dist/utils/range-hasher.d.ts +0 -46
  141. package/dist/utils/retry.d.ts +0 -64
  142. package/dist/utils/types.d.ts +0 -108
  143. package/dist/utils/validation-error.d.ts +0 -22
  144. package/dist/utils/validator.d.ts +0 -36
@@ -1,37 +0,0 @@
1
- import type { Readable } from "node:stream";
2
- import type { Metadata } from "./metadata.d.ts";
3
- export interface FileInit {
4
- contentType?: string;
5
- expiredAt?: Date | number | string;
6
- metadata: Metadata;
7
- originalName?: string;
8
- size?: number | string;
9
- storageClass?: string;
10
- ttl?: number | string;
11
- }
12
- export interface FileReturn extends Omit<Required<FileInit>, "storageClass" | "ttl" | "expiredAt"> {
13
- content: Buffer;
14
- ETag?: string;
15
- expiredAt?: Date | number | string;
16
- id: string;
17
- modifiedAt?: Date | number | string;
18
- name: string;
19
- storageClass?: string;
20
- }
21
- type UploadEventTypeValue = "completed" | "created" | "deleted" | "part" | "updated";
22
- export type UploadEventType = UploadEventTypeValue;
23
- export interface FileQuery {
24
- id: string;
25
- name?: string;
26
- size?: number;
27
- }
28
- export interface Checksum {
29
- checksum?: string;
30
- checksumAlgorithm?: string;
31
- }
32
- export interface FilePart extends Checksum, FileQuery {
33
- body: Readable;
34
- contentLength?: number;
35
- start: number;
36
- }
37
- export {};
@@ -1,10 +0,0 @@
1
- import type File from "./file.d.ts";
2
- /**
3
- * Updates a file object with new metadata using deep merge.
4
- * Also updates the originalName based on the merged metadata.
5
- * @param file File object to update
6
- * @param metadata Partial metadata to merge into the file
7
- * @template T - File type extending base File class
8
- */
9
- declare const updateMetadata: <T extends File>(file: T, metadata: Partial<T>) => void;
10
- export default updateMetadata;
@@ -1,10 +0,0 @@
1
- import type File from "./file.d.ts";
2
- /**
3
- * Updates a file's size, but only if the new size is smaller than the current size.
4
- * This prevents accidental size increases that could indicate data corruption.
5
- * @param file File object to update
6
- * @param size New size value
7
- * @returns The updated file object
8
- */
9
- declare const updateSize: (file: File, size: number) => File;
10
- export default updateSize;
@@ -1,31 +0,0 @@
1
- import type { LocalMetaStorageOptions } from "../local/local-meta-storage.d.ts";
2
- import type { BaseStorageOptions } from "../types.d.ts";
3
- export interface VercelBlobStorageOptions extends BaseStorageOptions {
4
- /**
5
- * Configure metafiles storage
6
- * @example
7
- * Using local metafiles
8
- * ```ts
9
- * const storage = new VercelBlobStorage({
10
- * token: process.env.BLOB_READ_WRITE_TOKEN,
11
- * metaStorageConfig: { directory: '/tmp/upload-metafiles' }
12
- * })
13
- * ```
14
- */
15
- metaStorageConfig?: LocalMetaStorageOptions;
16
- /**
17
- * Enable multipart uploads for large files
18
- * Can be a boolean to always use multipart, or a number (in bytes) as threshold
19
- * @default false
20
- * @example
21
- * // Always use multipart uploads
22
- * multipart: true
23
- * // Use multipart for files larger than 100MB
24
- * multipart: 100 * 1024 * 1024
25
- */
26
- multipart?: boolean | number;
27
- /**
28
- * Vercel Blob read-write token
29
- */
30
- token?: string;
31
- }
@@ -1,16 +0,0 @@
1
- import { File } from "../utils/index.d.ts";
2
- declare class VercelBlobFile extends File {
3
- /**
4
- * The blob's public URL
5
- */
6
- url?: string;
7
- /**
8
- * The blob's download URL (may be different from url for private blobs)
9
- */
10
- downloadUrl?: string;
11
- /**
12
- * The blob's pathname within the store
13
- */
14
- pathname?: string;
15
- }
16
- export default VercelBlobFile;
@@ -1,6 +0,0 @@
1
- import type { LocalMetaStorageOptions } from "../local/local-meta-storage.d.ts";
2
- import LocalMetaStorage from "../local/local-meta-storage.d.ts";
3
- declare class VercelBlobMetaStorage extends LocalMetaStorage {
4
- constructor(config?: LocalMetaStorageOptions);
5
- }
6
- export default VercelBlobMetaStorage;
@@ -1,76 +0,0 @@
1
- import type MetaStorage from "../meta-storage.d.ts";
2
- import { BaseStorage } from "../storage.d.ts";
3
- import type { FileInit, FilePart, FileQuery, FileReturn } from "../utils/index.d.ts";
4
- import type { VercelBlobStorageOptions } from "./types.d.ts";
5
- import VercelBlobFile from "./vercel-blob-file.d.ts";
6
- /**
7
- * Vercel Blob storage based backend.
8
- * @example
9
- * ```ts
10
- * const storage = new VercelBlobStorage({
11
- * token: process.env.BLOB_READ_WRITE_TOKEN,
12
- * metaStorageConfig: { directory: '/tmp/upload-metafiles' }
13
- * });
14
- * ```
15
- * @remarks
16
- * ## Supported Operations
17
- * - ✅ create, write, delete, get, copy, move
18
- * - ✅ Batch operations: deleteBatch, copyBatch, moveBatch (inherited from BaseStorage)
19
- * - ✅ exists: Implemented (checks metadata and Vercel Blob)
20
- * - ❌ getStream: Not implemented (use get() for file retrieval)
21
- * - ❌ list: Not implemented (Vercel Blob API doesn't support listing)
22
- * - ❌ update: Not implemented (Vercel Blob API doesn't support metadata updates)
23
- * - ❌ getUrl: Not implemented (Vercel Blob URLs available via Vercel Blob API)
24
- * - ❌ getUploadUrl: Not implemented (Vercel Blob upload URLs handled internally)
25
- */
26
- declare class VercelBlobStorage extends BaseStorage {
27
- static readonly name: string;
28
- checksumTypes: string[];
29
- protected meta: MetaStorage;
30
- private readonly token;
31
- private readonly multipart;
32
- constructor(config: VercelBlobStorageOptions);
33
- create(config: FileInit): Promise<VercelBlobFile>;
34
- write(part: FilePart | FileQuery | VercelBlobFile): Promise<VercelBlobFile>;
35
- /**
36
- * Deletes an upload and its metadata.
37
- * @param query File query containing the file ID to delete.
38
- * @param query.id File ID to delete.
39
- * @returns Promise resolving to the deleted file object with status: "deleted".
40
- * @throws {UploadError} If the file metadata cannot be found.
41
- */
42
- delete({ id }: FileQuery): Promise<VercelBlobFile>;
43
- /**
44
- * Checks if a file exists by verifying both metadata and the actual Vercel Blob.
45
- * Returns true only if both the metadata and the blob exist.
46
- * @param query File query containing the file ID to check.
47
- * @returns Promise resolving to true if both metadata and blob exist, false otherwise.
48
- */
49
- exists({ id }: FileQuery): Promise<boolean>;
50
- get({ id }: FileQuery): Promise<FileReturn>;
51
- /**
52
- * Copies an upload file to a new location.
53
- * @param name Source file name/ID.
54
- * @param destination Destination file name/ID.
55
- * @returns Promise resolving to the copied file object.
56
- * @throws {UploadError} If the source file cannot be found.
57
- */
58
- copy(name: string, destination: string): Promise<VercelBlobFile>;
59
- /**
60
- * Moves an upload file to a new location.
61
- * @param name Source file name/ID.
62
- * @param destination Destination file name/ID.
63
- * @returns Promise resolving to the moved file object.
64
- * @throws {UploadError} If the source file cannot be found.
65
- */
66
- move(name: string, destination: string): Promise<VercelBlobFile>;
67
- list(limit?: number): Promise<VercelBlobFile[]>;
68
- private internalOnComplete;
69
- /**
70
- * Determines if multipart upload should be used for the given file.
71
- * @param file File object to check.
72
- * @returns True if multipart upload should be used, false otherwise.
73
- */
74
- private shouldUseMultipart;
75
- }
76
- export default VercelBlobStorage;
@@ -1,63 +0,0 @@
1
- import { Readable } from "node:stream";
2
- import type { BaseStorage } from "../storage/storage.d.ts";
3
- import type { File, FileReturn } from "../storage/utils/index.d.ts";
4
- import type { Cache } from "../utils/cache.d.ts";
5
- import type { BaseTransformerConfig } from "./transformer-config.d.ts";
6
- /**
7
- * Abstract base class for all media transformers.
8
- *
9
- * Provides a common interface and shared functionality for image, video, and audio transformers.
10
- * All transformers must implement the abstract methods defined here.
11
- */
12
- declare abstract class BaseTransformer<Config extends BaseTransformerConfig, CacheValue extends object, TFile extends File = File, TFileReturn extends FileReturn = FileReturn> {
13
- protected readonly storage: BaseStorage<TFile, TFileReturn>;
14
- protected config: Config;
15
- protected logger?: Console;
16
- protected cache?: Cache<string, CacheValue>;
17
- /**
18
- * Creates a new BaseTransformer instance with common functionality.
19
- * @param storage The storage backend for retrieving and storing files.
20
- * @param config Configuration options for the transformer.
21
- * @param logger Optional logger instance for logging operations.
22
- * @protected
23
- */
24
- protected constructor(storage: BaseStorage<TFile, TFileReturn>, config: Config, logger?: Console);
25
- /**
26
- * Transforms a file with the given steps.
27
- * @param fileId Unique identifier of the file to transform.
28
- * @param steps Array of transformation steps to apply.
29
- * @returns Promise resolving to transformation result.
30
- */
31
- abstract transform(fileId: string, steps: any[]): Promise<any>;
32
- /**
33
- * Streams transform of a file with the given steps (for large files).
34
- * @param fileId Unique identifier of the file to transform.
35
- * @param steps Array of transformation steps to apply.
36
- * @returns Promise resolving to streaming result with headers, size, and stream.
37
- */
38
- transformStream?(fileId: string, steps: any[]): Promise<{
39
- headers?: Record<string, string>;
40
- size?: number;
41
- stream: Readable;
42
- }>;
43
- /**
44
- * Clears cache for a specific file or all files.
45
- * @param fileId Optional file identifier to clear cache for specific file.
46
- */
47
- clearCache(fileId?: string): void;
48
- /**
49
- * Gets cache statistics.
50
- * @returns Cache statistics including max size and current size.
51
- */
52
- getCacheStats(): {
53
- maxSize: number;
54
- size: number;
55
- };
56
- /**
57
- * Gets content type from transformation result based on format.
58
- * @param result Transformation result object containing format information.
59
- * @returns Content type string (MIME type).
60
- */
61
- protected getContentTypeFromResult(result: any): string;
62
- }
63
- export default BaseTransformer;
@@ -1,332 +0,0 @@
1
- import type { BaseStorage } from "../storage/storage.d.ts";
2
- import type { File, FileReturn } from "../storage/utils/index.d.ts";
3
- import type { MediaTransformerConfig, MediaTransformResult } from "./types.d.ts";
4
- /**
5
- * Unified media transformer that automatically detects media type and routes to appropriate transformer.
6
- * @template TFile The file type used by this transformer.
7
- * @template TFileReturn The return type for file retrieval operations.
8
- *
9
- * Supports transformations via query parameters for on-demand media processing across all supported formats.
10
- * @example
11
- * // eslint-disable-next-line jsdoc/match-description
12
- * ```ts
13
- * const transformer = new MediaTransformer(storage, {
14
- * maxImageSize: 10 * 1024 * 1024, // 10MB
15
- * maxVideoSize: 100 * 1024 * 1024, // 100MB
16
- * maxAudioSize: 50 * 1024 * 1024, // 50MB
17
- * cache: new MapCache(), // In-memory caching
18
- * saveTransformedFiles: true // Persist transformed files to storage
19
- * });
20
- *
21
- * // Handle transformation via query parameters
22
- * const result = await transformer.handle('file-id', {
23
- * width: 800,
24
- * height: 600,
25
- * fit: 'cover',
26
- * format: 'webp',
27
- * quality: 80
28
- * });
29
- *
30
- * // Fetch with URL query string
31
- * const result = await transformer.fetch('file-id', 'width=1280&height=720&codec=avc&bitrate=2000000');
32
- *
33
- * // Clear all cached transformed files
34
- * transformer.clearSavedTransformedFiles();
35
- * ```
36
- *
37
- * ## Configuration Options
38
- *
39
- * - `saveTransformedFiles`: Persist transformed files to storage for reuse (default: false)
40
- * - `cache`: Cache instance for in-memory caching (optional)
41
- * - `maxImageSize/maxVideoSize/maxAudioSize`: Size limits for processing
42
- * - `cacheTtl`: Cache time-to-live in seconds
43
- *
44
- * ## Supported Query Parameters
45
- *
46
- * ### Common Parameters
47
- * - `format`: Output format (jpeg/png/webp/avif/mp4/webm/mkv/mp3/wav/ogg/aac/flac)
48
- * - `quality`: Quality for images (0-100), bitrate for video/audio
49
- *
50
- * ### Image Parameters
51
- * - `width`: Width in pixels
52
- * - `height`: Height in pixels
53
- * - `fit`: Resize fit mode - cover/contain/fill/inside/outside
54
- * - `position`: Position for cover/contain fits
55
- * - `withoutEnlargement`: Avoid enlarging smaller images (boolean)
56
- * - `withoutReduction`: Avoid reducing larger images (boolean)
57
- * - `kernel`: Resize kernel - nearest/cubic/mitchell/lanczos2/lanczos3
58
- * - `fastShrinkOnLoad`: Fast shrink on load (boolean)
59
- * - `left/top/cropWidth/cropHeight`: Crop parameters
60
- * - `angle`: Rotation angle in degrees (any number, but angles other than 90°/180°/270° use interpolation and may affect quality)
61
- * - `background`: Background color for rotation
62
- * - `blur`: Apply blur effect (boolean)
63
- * - `sharpen`: Apply sharpening (boolean)
64
- * - `median`: Apply median filter with size (number)
65
- * // eslint-disable-next-line jsdoc/match-description
66
- * - `clahe`: Apply CLAHE (Contrast Limited Adaptive Histogram Equalization) (boolean)
67
- * - `threshold`: Apply thresholding with value (0-255)
68
- * - `gamma`: Apply gamma correction (boolean)
69
- * - `negate`: Negate (invert) the image (boolean)
70
- * - `normalise/normalize`: Normalise the image (boolean)
71
- * - `flatten`: Flatten alpha channel (boolean)
72
- * - `unflatten`: Unflatten alpha channel (boolean)
73
- * - `flip`: Flip image vertically (boolean)
74
- * - `flop`: Flop image horizontally (boolean)
75
- * - `greyscale/grayscale`: Convert to greyscale (boolean)
76
- * - `modulate`: Apply modulation effects (boolean)
77
- * - `brightness`: Brightness multiplier for modulation (number)
78
- * - `saturation`: Saturation multiplier for modulation (number)
79
- * - `hue`: Hue rotation in degrees for modulation (number)
80
- * // eslint-disable-next-line jsdoc/match-description
81
- * - `lightness`: Lightness adjustment for modulation (number)
82
- * - `tint`: Apply tinting (boolean)
83
- * - `colourspace`: Convert colourspace - srgb/rgb/cmyk/lab/b-w
84
- *
85
- * ### Video Parameters
86
- * - `width/height/fit`: Same as images
87
- * - `codec`: Video codec - avc/hevc/vp8/vp9/av1
88
- * - `bitrate`: Video bitrate in bits per second
89
- * - `frameRate`: Frame rate in Hz
90
- * - `keyFrameInterval`: Key frame interval in seconds
91
- * - `angle`: Rotation angle in degrees (any number, but angles other than 90°/180°/270° use interpolation and may affect quality)
92
- * - `background`: Background color for rotation
93
- *
94
- * ### Audio Parameters
95
- * - `sampleRate`: Sample rate in Hz
96
- * - `numberOfChannels`: Number of channels
97
- * - `codec`: Audio codec - aac/opus/mp3/vorbis/flac
98
- * - `bitrate`: Audio bitrate in bits per second
99
- *
100
- * ## File Persistence
101
- *
102
- * When `saveTransformedFiles` is enabled, transformed files are automatically saved to storage
103
- * with deterministic IDs based on the original file and transformation parameters. Subsequent
104
- * requests for the same transformation will serve the cached file directly, improving performance
105
- * and reducing processing costs.
106
- */
107
- declare class MediaTransformer<TFile extends File = File, TFileReturn extends FileReturn = FileReturn> {
108
- private readonly storage;
109
- private readonly imageTransformer?;
110
- private readonly videoTransformer?;
111
- private readonly audioTransformer?;
112
- private readonly config;
113
- private readonly logger;
114
- /**
115
- * Creates a new MediaTransformer instance.
116
- * @param storage The storage backend for retrieving and storing media files.
117
- * @param config Configuration options for the media transformer including transformer classes and settings.
118
- * @throws Error if no transformer classes are provided in the configuration.
119
- */
120
- constructor(storage: BaseStorage<TFile, TFileReturn>, config?: MediaTransformerConfig<TFile, TFileReturn>);
121
- supportedFormats(): string[];
122
- /**
123
- * Handles media transformation based on query parameters.
124
- * @param fileId File identifier.
125
- * @param query Query parameters for transformation.
126
- * @returns Unified transformation result.
127
- */
128
- handle(fileId: string, query: Record<string, string | undefined> | URLSearchParams | string): Promise<MediaTransformResult>;
129
- /**
130
- * Fetches media transformation with URL query string support.
131
- * @param fileId File identifier.
132
- * @param queryString URL query string (e.g., "width=800&amp;height=600&amp;format=webp").
133
- * @returns Unified transformation result.
134
- */
135
- fetch(fileId: string, queryString: string): Promise<MediaTransformResult>;
136
- /**
137
- * Clears cache for a specific file across all transformers.
138
- * @param fileId Optional file identifier to clear cache for. If omitted, clears all cache.
139
- */
140
- clearCache(fileId?: string): void;
141
- /**
142
- * Clears all saved transformed files from storage.
143
- * @remarks This is a maintenance operation and may take time for large numbers of files.
144
- */
145
- clearSavedTransformedFiles(): Promise<void>;
146
- /**
147
- * Clears saved transformed files for a specific original file.
148
- * @param originalFileId Original file identifier to clear transformed files for.
149
- */
150
- clearSavedTransformedFilesForFile(originalFileId: string): Promise<void>;
151
- /**
152
- * Gets cache statistics (combined from all transformers).
153
- * @returns Cache statistics for audio, image, and video transformers.
154
- */
155
- getCacheStats(): {
156
- audio?: {
157
- maxSize: number;
158
- size: number;
159
- };
160
- image?: {
161
- maxSize: number;
162
- size: number;
163
- };
164
- video?: {
165
- maxSize: number;
166
- size: number;
167
- };
168
- };
169
- /**
170
- * Validates query parameters for the given media type.
171
- * @param query The query parameters to validate.
172
- * @param mediaType The media type being validated ('image', 'video', or 'audio').
173
- * @throws {ValidationError} When invalid parameters are provided.
174
- */
175
- private validateQueryParameters;
176
- /**
177
- * 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.
178
- * @param query Query parameters to validate.
179
- * @throws {ValidationError} When validation fails.
180
- */
181
- private validateImageQueryParameters;
182
- /**
183
- * 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.
184
- * @param query Query parameters to validate.
185
- * @throws {ValidationError} When validation fails.
186
- */
187
- private validateVideoQueryParameters;
188
- /**
189
- * Generates a unique ID for transformed files based on original file and transformations.
190
- * @param originalFileId The original file identifier.
191
- * @param query The transformation query parameters.
192
- * @param mediaType The media type (image, video, audio).
193
- * @returns Unique deterministic identifier for the transformed file.
194
- * @private
195
- */
196
- private generateTransformedFileId;
197
- /**
198
- * Checks if the query contains any transformations.
199
- * @param query The transformation query parameters.
200
- * @returns True if any transformations are requested.
201
- * @private
202
- */
203
- private hasTransformations;
204
- /**
205
- * Creates a MediaTransformResult from a stored transformed file.
206
- * @param storedFile The stored transformed file.
207
- * @param mediaType The media type (image, video, audio).
208
- * @param originalFile The original file information.
209
- * @returns Media transformation result with metadata.
210
- * @private
211
- */
212
- private createMediaTransformResult;
213
- /**
214
- * Extracts format from content type.
215
- * @param contentType MIME content type string.
216
- * @returns Format string extracted from content type.
217
- * @private
218
- */
219
- private getFormatFromContentType;
220
- /**
221
- * Saves transformed file to storage.
222
- * @param result The transformation result to save.
223
- * @param originalFileId The original file identifier.
224
- * @param query The transformation query parameters.
225
- * @param mediaType The media type (image, video, audio).
226
- * @returns Promise that resolves when file is saved.
227
- * @private
228
- */
229
- private saveTransformedFile;
230
- /**
231
- * Validates query parameters for audio transformations. Checks for invalid video-only parameters, invalid codecs, invalid formats, and invalid numeric values.
232
- * @param query Query parameters to validate.
233
- * @throws {ValidationError} When validation fails.
234
- */
235
- private validateAudioQueryParameters;
236
- /**
237
- * Handles image transformation.
238
- * @param fileId The file identifier.
239
- * @param query The transformation query parameters.
240
- * @returns Promise resolving to media transformation result.
241
- * @private
242
- */
243
- private handleImageTransformation;
244
- /**
245
- * Handles video transformation.
246
- * @param fileId The file identifier.
247
- * @param query The transformation query parameters.
248
- * @returns Promise resolving to media transformation result.
249
- * @private
250
- */
251
- private handleVideoTransformation;
252
- /**
253
- * Handles audio transformation.
254
- * @param fileId The file identifier.
255
- * @param query The transformation query parameters.
256
- * @returns Promise resolving to media transformation result.
257
- * @private
258
- */
259
- private handleAudioTransformation;
260
- /**
261
- * Parses query parameters from various input formats.
262
- * @param query Query parameters in various formats.
263
- * @returns Normalized MediaTransformQuery object.
264
- * @private
265
- */
266
- private parseQuery;
267
- /**
268
- * Parses boolean parameter from string.
269
- * @param value String value to parse.
270
- * @returns Boolean value or undefined.
271
- * @private
272
- */
273
- private parseBooleanParameter;
274
- /**
275
- * Parses URLSearchParams into MediaTransformQuery.
276
- * @param parameters URL search parameters object.
277
- * @returns MediaTransformQuery object with parsed parameters.
278
- * @private
279
- */
280
- private parseURLSearchParams;
281
- /**
282
- * Detects media type from MIME type.
283
- * @param contentType MIME content type string.
284
- * @returns Detected media type.
285
- * @throws Error if content type is missing or unsupported.
286
- * @private
287
- */
288
- private detectMediaType;
289
- /**
290
- * Checks if query has image transformations.
291
- * @param query The transformation query parameters.
292
- * @returns True if image transformations are requested.
293
- * @private
294
- */
295
- private hasImageTransformations;
296
- /**
297
- * Checks if query has video transformations.
298
- * @param query The transformation query parameters.
299
- * @returns True if video transformations are requested.
300
- * @private
301
- */
302
- private hasVideoTransformations;
303
- /**
304
- * Checks if query has audio transformations.
305
- * @param query The transformation query parameters.
306
- * @returns True if audio transformations are requested.
307
- * @private
308
- */
309
- private hasAudioTransformations;
310
- /**
311
- * Converts ImageTransformer result to unified format.
312
- * @param result The image transformation result.
313
- * @returns Unified media transformation result.
314
- * @private
315
- */
316
- private convertImageResult;
317
- /**
318
- * Converts VideoTransformer result to unified format.
319
- * @param result The video transformation result.
320
- * @returns Unified media transformation result.
321
- * @private
322
- */
323
- private convertVideoResult;
324
- /**
325
- * Converts AudioTransformer result to unified format.
326
- * @param result The audio transformation result.
327
- * @returns Unified media transformation result.
328
- * @private
329
- */
330
- private convertAudioResult;
331
- }
332
- export default MediaTransformer;
@@ -1,16 +0,0 @@
1
- import type { Cache } from "../utils/cache.d.ts";
2
- /**
3
- * Base transformer configuration with common properties
4
- */
5
- export interface BaseTransformerConfig {
6
- /** Cache instance to use for caching */
7
- cache?: Cache;
8
- /** Cache TTL in seconds */
9
- cacheTtl?: number;
10
- /** Logger instance */
11
- logger?: Console;
12
- /** Maximum number of cached items */
13
- maxCacheSize?: number;
14
- /** Supported input formats */
15
- supportedFormats?: string[] | undefined;
16
- }