@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,5 +1,62 @@
1
- export { default as BaseTransformer } from "./base-transformer.d.ts";
2
- export { default as MediaTransformer } from "./media-transformer.d.ts";
3
- export type { AudioChannelMixOptions, AudioResampleOptions, AudioTransformationStep, AudioTransformerConfig, AudioTransformOptions, AudioTransformResult, CropOptions, ImageFormat, ImageTransformerConfig, MediaTransformationStep, MediaTransformerConfig, MediaTransformQuery, MediaTransformResult, ResizeOptions, RotateOptions, TransformationStep, TransformOptions, TransformResult, VideoCropOptions, VideoResizeOptions, VideoRotateOptions, VideoTransformationStep, VideoTransformerConfig, VideoTransformOptions, VideoTransformResult, } from "./types.d.ts";
4
- export { getFormatFromContentType, isKnownContentType, isValidMediaType, validateMediaFile } from "./utils.d.ts";
5
- export { default as ValidationError } from "./validation-error.d.ts";
1
+ export { type c as AudioChannelMixOptions, type b as AudioResampleOptions, type d as AudioTransformOptions, type a as AudioTransformResult, type e as AudioTransformationStep, type A as AudioTransformerConfig, B as BaseTransformer, type C as CropOptions, type g as ImageFormat, type I as ImageTransformerConfig, type U as MediaTransformQuery, type Q as MediaTransformResult, type W as MediaTransformationStep, type O as MediaTransformerConfig, type R as ResizeOptions, type f as RotateOptions, type h as TransformOptions, type T as TransformResult, type x as TransformationStep, type F as VideoCropOptions, type z as VideoResizeOptions, type H as VideoRotateOptions, type K as VideoTransformOptions, type y as VideoTransformResult, type N as VideoTransformationStep, type V as VideoTransformerConfig } from "../packem_shared/types.d-BPd_JkW1.js";
2
+ export { M as MediaTransformer } from "../packem_shared/media-transformer.d-DeHZkBVx.js";
3
+ import { a as FileReturn } from "../packem_shared/storage.d-BOMUJD96.js";
4
+ import 'node:stream';
5
+ import 'node:crypto';
6
+ import 'node:http';
7
+ import 'lru-cache';
8
+ /**
9
+ * Check if a content type is valid for a specific media type.
10
+ * @param contentType MIME content type string to validate
11
+ * @param expectedType Expected media type ('image', 'video', or 'audio')
12
+ * @returns True if the content type is valid for the expected media type
13
+ */
14
+ declare const isValidMediaType: (contentType: string | undefined, expectedType: "image" | "video" | "audio") => boolean;
15
+ /**
16
+ * Get format (extension) from content type using mime package.
17
+ * @param contentType MIME content type string to extract format from
18
+ * @returns Format string or undefined if not found
19
+ */
20
+ declare const getFormatFromContentType: (contentType: string | undefined) => string | undefined;
21
+ /**
22
+ * Validate a media file for a specific type with size and format checks.
23
+ * @param file File to validate
24
+ * @param expectedType Expected media type ('image', 'video', or 'audio')
25
+ * @param config Validation configuration with optional maxSize and supportedFormats
26
+ * @param config.maxSize Maximum allowed file size in bytes
27
+ * @param config.supportedFormats Array of supported file formats
28
+ * @throws Error if validation fails (size exceeded, wrong type, or unsupported format)
29
+ */
30
+ declare const validateMediaFile: (file: FileReturn, expectedType: "image" | "video" | "audio", config?: {
31
+ maxSize?: number;
32
+ supportedFormats?: string[];
33
+ }) => void;
34
+ /**
35
+ * Validate that a content type is known and supported by the mime package.
36
+ * @param contentType MIME content type string to check
37
+ * @returns True if the content type is known and has a registered extension
38
+ */
39
+ declare const isKnownContentType: (contentType: string | undefined) => boolean;
40
+ /**
41
+ * Custom error class for validation failures
42
+ */
43
+ declare class ValidationError extends Error {
44
+ readonly code: string;
45
+ readonly details: {
46
+ invalidParams: string[];
47
+ mediaType: string;
48
+ suggestions?: string[];
49
+ validParams: string[];
50
+ };
51
+ /**
52
+ * Creates a new ValidationError instance with detailed error information.
53
+ * @param message Human-readable error message describing the validation failure
54
+ * @param code Machine-readable error code for programmatic error handling
55
+ * @param mediaType The media type where validation failed ('image', 'video', or 'audio')
56
+ * @param invalidParameters Array of parameter names that were invalid
57
+ * @param validParameters Array of valid parameter names or values
58
+ * @param suggestions Optional array of suggested corrections or valid values
59
+ */
60
+ constructor(message: string, code: string, mediaType: string, invalidParameters: string[], validParameters: string[], suggestions?: string[]);
61
+ }
62
+ export { ValidationError, getFormatFromContentType, isKnownContentType, isValidMediaType, validateMediaFile };
@@ -1,145 +1,147 @@
1
- import type { BaseStorage } from "../storage/storage.d.ts";
2
- import type { File, FileReturn } from "../storage/utils/index.d.ts";
3
- import BaseTransformer from "./base-transformer.d.ts";
4
- import type { VideoCropOptions, VideoResizeOptions, VideoRotateOptions, VideoTransformationStep, VideoTransformerConfig, VideoTransformOptions, VideoTransformResult } from "./types.d.ts";
1
+ import { F as File, a as FileReturn, B as BaseStorage } from "../packem_shared/storage.d-BOMUJD96.js";
2
+ import { V as VideoTransformerConfig, y as VideoTransformResult, z as VideoResizeOptions, F as VideoCropOptions, H as VideoRotateOptions, K as VideoTransformOptions, N as VideoTransformationStep, B as BaseTransformer } from "../packem_shared/types.d-BPd_JkW1.js";
3
+ import 'node:stream';
4
+ import 'node:crypto';
5
+ import 'node:http';
6
+ import 'lru-cache';
5
7
  /**
6
- * Video transformer that uses storage backends and Mediabunny library to retrieve and transform videos.
7
- * @template TFile The file type used by this transformer.
8
- * @template TFileReturn The return type for file retrieval operations.
9
- *
10
- * Supports video transformations with query parameters for on-demand video processing.
11
- * @example
12
- * ```ts
13
- * const transformer = new VideoTransformer(storage, {
14
- * maxVideoSize: 100 * 1024 * 1024, // 100MB
15
- * cache: new Map()
16
- * });
17
- *
18
- * // Programmatic usage - resize a video
19
- * const result = await transformer.resize('video-id', {
20
- * width: 1920,
21
- * height: 1080,
22
- * fit: 'contain'
23
- * });
24
- *
25
- * // URL-based transformations
26
- * // GET /files/video-id?width=1280&height=720&fit=cover&bitrate=2000000
27
- * // GET /files/video-id?codec=vp9&bitrate=1000000
28
- * ```
29
- *
30
- * ## Supported Query Parameters
31
- *
32
- * - `width`: Width in pixels (Number)
33
- * - `height`: Height in pixels (Number)
34
- * - `fit`: Resize fit mode - cover/contain/fill/inside/outside
35
- * - `codec`: Video codec - avc/hevc/vp8/vp9/av1
36
- * - `bitrate`: Video bitrate in bits per second (Number)
37
- * - `frameRate`: Frame rate in Hz (Number)
38
- * - `format`: Output format - mp4/webm/mkv/ogg
39
- */
8
+ * Video transformer that uses storage backends and Mediabunny library to retrieve and transform videos.
9
+ * @template TFile The file type used by this transformer.
10
+ * @template TFileReturn The return type for file retrieval operations.
11
+ *
12
+ * Supports video transformations with query parameters for on-demand video processing.
13
+ * @example
14
+ * ```ts
15
+ * const transformer = new VideoTransformer(storage, {
16
+ * maxVideoSize: 100 * 1024 * 1024, // 100MB
17
+ * cache: new Map()
18
+ * });
19
+ *
20
+ * // Programmatic usage - resize a video
21
+ * const result = await transformer.resize('video-id', {
22
+ * width: 1920,
23
+ * height: 1080,
24
+ * fit: 'contain'
25
+ * });
26
+ *
27
+ * // URL-based transformations
28
+ * // GET /files/video-id?width=1280&height=720&fit=cover&bitrate=2000000
29
+ * // GET /files/video-id?codec=vp9&bitrate=1000000
30
+ * ```
31
+ *
32
+ * ## Supported Query Parameters
33
+ *
34
+ * - `width`: Width in pixels (Number)
35
+ * - `height`: Height in pixels (Number)
36
+ * - `fit`: Resize fit mode - cover/contain/fill/inside/outside
37
+ * - `codec`: Video codec - avc/hevc/vp8/vp9/av1
38
+ * - `bitrate`: Video bitrate in bits per second (Number)
39
+ * - `frameRate`: Frame rate in Hz (Number)
40
+ * - `format`: Output format - mp4/webm/mkv/ogg
41
+ */
40
42
  declare class VideoTransformer<TFile extends File = File, TFileReturn extends FileReturn = FileReturn> extends BaseTransformer<VideoTransformerConfig, VideoTransformResult<TFileReturn>, TFile, TFileReturn> {
41
- /**
42
- * Creates a new VideoTransformer instance.
43
- * @param storage The storage backend for retrieving and storing video files.
44
- * @param config Configuration options for video transformation including cache settings, codec defaults, and size limits.
45
- */
46
- constructor(storage: BaseStorage<TFile, TFileReturn>, config?: VideoTransformerConfig);
47
- /**
48
- * Resizes a video to specified dimensions with optional fit mode.
49
- * @param fileId Unique identifier of the video file to resize.
50
- * @param options Resize options including width, height, and fit mode.
51
- * @returns Promise resolving to transformed video result.
52
- */
53
- resize(fileId: string, options: VideoResizeOptions): Promise<VideoTransformResult<TFileReturn>>;
54
- /**
55
- * Crops a video to the specified region.
56
- * @param fileId Unique identifier of the video file to crop.
57
- * @param options Crop options including region coordinates.
58
- * @returns Promise resolving to transformed video result.
59
- */
60
- crop(fileId: string, options: VideoCropOptions): Promise<VideoTransformResult<TFileReturn>>;
61
- /**
62
- * Rotates a video by the specified angle.
63
- * @param fileId Unique identifier of the video file to rotate.
64
- * @param options Rotation configuration with angle in degrees and optional background color.
65
- * @returns Promise resolving to transformed video result.
66
- */
67
- rotate(fileId: string, options: VideoRotateOptions): Promise<VideoTransformResult<TFileReturn>>;
68
- /**
69
- * Converts video format or codec.
70
- * @param fileId Unique identifier of the video file to convert.
71
- * @param format Target video format (e.g., "mp4", "webm", "mkv").
72
- * @param options Video transformation options including quality, bitrate, and codec settings.
73
- * @returns Promise resolving to transformed video result with updated format metadata.
74
- */
75
- convertFormat(fileId: string, format: string, options?: VideoTransformOptions): Promise<VideoTransformResult<TFileReturn>>;
76
- /**
77
- * Transcodes video to different codec.
78
- * @param fileId Unique identifier of the video file to transcode.
79
- * @param codec Target video codec (e.g., "avc", "hevc", "vp9").
80
- * @param options Additional transform options.
81
- * @returns Promise resolving to transformed video result.
82
- */
83
- transcode(fileId: string, codec: VideoTransformOptions["codec"], options?: Omit<VideoTransformOptions, "codec">): Promise<VideoTransformResult<TFileReturn>>;
84
- /**
85
- * Applies a custom transformation pipeline to a video.
86
- * @param fileId Unique identifier of the video file to transform.
87
- * @param steps Array of transformation steps to apply in sequence.
88
- * @returns Promise resolving to transformed video result.
89
- */
90
- transform(fileId: string, steps: VideoTransformationStep[]): Promise<VideoTransformResult<TFileReturn>>;
91
- /**
92
- * Applies multiple transformations in sequence using Mediabunny.
93
- * @param buffer The original video buffer.
94
- * @param steps Array of video transformation steps to apply.
95
- * @returns Promise resolving to transformed video buffer.
96
- * @private
97
- */
98
- private applyTransformations;
99
- /**
100
- * Converts transformation steps to Mediabunny video options.
101
- * @param steps Array of video transformation steps to convert.
102
- * @returns Mediabunny video options object for conversion.
103
- * @private
104
- */
105
- private stepsToVideoOptions;
106
- /**
107
- * Determines output format based on transformation steps.
108
- * @param steps Array of video transformation steps.
109
- * @returns Mediabunny output format instance (defaults to MP4).
110
- * @private
111
- */
112
- private determineOutputFormat;
113
- /**
114
- * Converts format string to Mediabunny output format.
115
- * @param format Video format string (mp4, webm, mkv, ogg).
116
- * @returns Mediabunny output format instance.
117
- * @private
118
- */
119
- private formatStringToOutputFormat;
120
- /**
121
- * Validates that the file is a supported video.
122
- * @param file The file to validate.
123
- * @returns Promise that resolves if validation passes.
124
- * @throws Error if file size exceeds limits, wrong content type, unsupported format, or invalid video.
125
- * @private
126
- */
127
- private validateVideo;
128
- /**
129
- * Creates transformation result with metadata.
130
- * @param buffer The transformed video buffer.
131
- * @param originalFile The original file information.
132
- * @returns Video transformation result with metadata.
133
- * @private
134
- */
135
- private createTransformResult;
136
- /**
137
- * Generates cache key for transformation.
138
- * @param fileId The file identifier.
139
- * @param steps Array of transformation steps.
140
- * @returns Unique cache key string.
141
- * @private
142
- */
143
- private generateCacheKey;
43
+ /**
44
+ * Creates a new VideoTransformer instance.
45
+ * @param storage The storage backend for retrieving and storing video files.
46
+ * @param config Configuration options for video transformation including cache settings, codec defaults, and size limits.
47
+ */
48
+ constructor(storage: BaseStorage<TFile, TFileReturn>, config?: VideoTransformerConfig);
49
+ /**
50
+ * Resizes a video to specified dimensions with optional fit mode.
51
+ * @param fileId Unique identifier of the video file to resize.
52
+ * @param options Resize options including width, height, and fit mode.
53
+ * @returns Promise resolving to transformed video result.
54
+ */
55
+ resize(fileId: string, options: VideoResizeOptions): Promise<VideoTransformResult<TFileReturn>>;
56
+ /**
57
+ * Crops a video to the specified region.
58
+ * @param fileId Unique identifier of the video file to crop.
59
+ * @param options Crop options including region coordinates.
60
+ * @returns Promise resolving to transformed video result.
61
+ */
62
+ crop(fileId: string, options: VideoCropOptions): Promise<VideoTransformResult<TFileReturn>>;
63
+ /**
64
+ * Rotates a video by the specified angle.
65
+ * @param fileId Unique identifier of the video file to rotate.
66
+ * @param options Rotation configuration with angle in degrees and optional background color.
67
+ * @returns Promise resolving to transformed video result.
68
+ */
69
+ rotate(fileId: string, options: VideoRotateOptions): Promise<VideoTransformResult<TFileReturn>>;
70
+ /**
71
+ * Converts video format or codec.
72
+ * @param fileId Unique identifier of the video file to convert.
73
+ * @param format Target video format (e.g., "mp4", "webm", "mkv").
74
+ * @param options Video transformation options including quality, bitrate, and codec settings.
75
+ * @returns Promise resolving to transformed video result with updated format metadata.
76
+ */
77
+ convertFormat(fileId: string, format: string, options?: VideoTransformOptions): Promise<VideoTransformResult<TFileReturn>>;
78
+ /**
79
+ * Transcodes video to different codec.
80
+ * @param fileId Unique identifier of the video file to transcode.
81
+ * @param codec Target video codec (e.g., "avc", "hevc", "vp9").
82
+ * @param options Additional transform options.
83
+ * @returns Promise resolving to transformed video result.
84
+ */
85
+ transcode(fileId: string, codec: VideoTransformOptions["codec"], options?: Omit<VideoTransformOptions, "codec">): Promise<VideoTransformResult<TFileReturn>>;
86
+ /**
87
+ * Applies a custom transformation pipeline to a video.
88
+ * @param fileId Unique identifier of the video file to transform.
89
+ * @param steps Array of transformation steps to apply in sequence.
90
+ * @returns Promise resolving to transformed video result.
91
+ */
92
+ transform(fileId: string, steps: VideoTransformationStep[]): Promise<VideoTransformResult<TFileReturn>>;
93
+ /**
94
+ * Applies multiple transformations in sequence using Mediabunny.
95
+ * @param buffer The original video buffer.
96
+ * @param steps Array of video transformation steps to apply.
97
+ * @returns Promise resolving to transformed video buffer.
98
+ * @private
99
+ */
100
+ private applyTransformations;
101
+ /**
102
+ * Converts transformation steps to Mediabunny video options.
103
+ * @param steps Array of video transformation steps to convert.
104
+ * @returns Mediabunny video options object for conversion.
105
+ * @private
106
+ */
107
+ private stepsToVideoOptions;
108
+ /**
109
+ * Determines output format based on transformation steps.
110
+ * @param steps Array of video transformation steps.
111
+ * @returns Mediabunny output format instance (defaults to MP4).
112
+ * @private
113
+ */
114
+ private determineOutputFormat;
115
+ /**
116
+ * Converts format string to Mediabunny output format.
117
+ * @param format Video format string (mp4, webm, mkv, ogg).
118
+ * @returns Mediabunny output format instance.
119
+ * @private
120
+ */
121
+ private formatStringToOutputFormat;
122
+ /**
123
+ * Validates that the file is a supported video.
124
+ * @param file The file to validate.
125
+ * @returns Promise that resolves if validation passes.
126
+ * @throws Error if file size exceeds limits, wrong content type, unsupported format, or invalid video.
127
+ * @private
128
+ */
129
+ private validateVideo;
130
+ /**
131
+ * Creates transformation result with metadata.
132
+ * @param buffer The transformed video buffer.
133
+ * @param originalFile The original file information.
134
+ * @returns Video transformation result with metadata.
135
+ * @private
136
+ */
137
+ private createTransformResult;
138
+ /**
139
+ * Generates cache key for transformation.
140
+ * @param fileId The file identifier.
141
+ * @param steps Array of transformation steps.
142
+ * @returns Unique cache key string.
143
+ * @private
144
+ */
145
+ private generateCacheKey;
144
146
  }
145
- export default VideoTransformer;
147
+ export { VideoTransformer as default };
package/package.json CHANGED
@@ -1,61 +1,61 @@
1
1
  {
2
2
  "name": "@visulima/storage",
3
- "version": "1.0.0-alpha.15",
3
+ "version": "1.0.0-alpha.16",
4
4
  "description": "Visulima upload - Store files in a web-accessible location via a simplified API. Can automatically scale and rotate images. Includes S3, Azure, GCS and local filesystem-based backends with the most convenient features of each.",
5
5
  "keywords": [
6
6
  "anolilab",
7
- "visulima",
7
+ "astro",
8
+ "aws",
9
+ "aws-s3",
10
+ "azure",
11
+ "better-upload",
12
+ "better-uploads",
13
+ "chunk",
14
+ "chunked-upload",
15
+ "chunked-uploads",
16
+ "cloudflare-r2",
17
+ "cloudflare-workers",
18
+ "digitalocean-spaces",
19
+ "edge-runtime",
20
+ "elysia",
21
+ "enterprise-security",
8
22
  "express",
9
- "upload",
10
- "uploads",
23
+ "fastify",
11
24
  "file",
25
+ "file-upload",
12
26
  "files",
13
- "chunk",
14
- "resumable",
15
- "chunked-uploads",
16
- "tus",
17
27
  "form",
18
- "post",
19
- "multipart",
20
28
  "form-data",
21
29
  "formdata",
22
- "middleware",
23
- "better-upload",
24
- "better-uploads",
25
- "s3",
26
- "azure",
27
- "aws",
30
+ "framework-agnostic",
28
31
  "gcs",
29
32
  "google",
30
- "storage",
31
- "file-upload",
32
- "cloudflare-r2",
33
- "digitalocean-spaces",
34
33
  "google-cloud-storage",
34
+ "hono",
35
+ "middleware",
35
36
  "minio",
36
- "presigned-urls",
37
+ "multipart",
38
+ "multipart-upload",
37
39
  "nextjs",
38
- "remix",
39
- "sveltekit",
40
40
  "nuxt",
41
- "astro",
41
+ "post",
42
+ "presigned-urls",
42
43
  "react",
43
- "aws-s3",
44
- "typescript",
45
- "hono",
46
- "fastify",
47
- "elysia",
48
- "framework-agnostic",
49
- "edge-runtime",
50
- "cloudflare-workers",
51
- "vercel-edge",
44
+ "remix",
45
+ "resumable",
46
+ "s3",
52
47
  "serverless",
48
+ "storage",
49
+ "sveltekit",
50
+ "tus",
51
+ "typescript",
53
52
  "universal",
54
- "enterprise-security",
55
- "multipart-upload",
56
- "chunked-upload",
53
+ "upload",
57
54
  "upload-library",
58
- "uploadthing"
55
+ "uploads",
56
+ "uploadthing",
57
+ "vercel-edge",
58
+ "visulima"
59
59
  ],
60
60
  "homepage": "https://visulima.com/packages/uploads",
61
61
  "repository": {
@@ -1,91 +0,0 @@
1
- import { EventEmitter } from "node:events";
2
- import type { BaseStorage } from "../../storage/storage.d.ts";
3
- import type { UploadFile } from "../../storage/utils/index.d.ts";
4
- import type MediaTransformer from "../../transformer/media-transformer.d.ts";
5
- import type { ErrorResponses } from "../../utils/errors.d.ts";
6
- import type { ResponseBodyType } from "../../utils/types.d.ts";
7
- import type { UploadOptions } from "../types.d.ts";
8
- /**
9
- * Core base class containing shared business logic for all handlers.
10
- * This class is platform-agnostic and contains no Node.js or Web API specific code.
11
- * @template TFile The file type used by this handler.
12
- */
13
- declare abstract class BaseHandlerCore<TFile extends UploadFile> extends EventEmitter {
14
- /**
15
- * Response body type for the handler.
16
- */
17
- responseType: ResponseBodyType;
18
- /**
19
- * Storage instance for file operations.
20
- */
21
- storage: BaseStorage<TFile>;
22
- /**
23
- * Optional media transformer for image/video processing.
24
- */
25
- mediaTransformer?: MediaTransformer;
26
- /**
27
- * Whether to disable termination for finished uploads.
28
- */
29
- disableTerminationForFinishedUploads?: boolean;
30
- /**
31
- * Logger instance for debugging and error reporting.
32
- */
33
- protected logger?: Console;
34
- /**
35
- * Gets the logger instance.
36
- * @returns Logger instance or undefined.
37
- */
38
- get loggerInstance(): Console | undefined;
39
- /**
40
- * Internal error responses configuration.
41
- */
42
- protected internalErrorResponses: ErrorResponses;
43
- /**
44
- * Gets the error responses configuration.
45
- * @returns Error responses configuration.
46
- */
47
- get errorResponses(): ErrorResponses;
48
- constructor({ disableTerminationForFinishedUploads, mediaTransformer, storage }: UploadOptions<TFile>);
49
- /**
50
- * Sets custom error responses.
51
- * @param value Partial error responses to override defaults.
52
- */
53
- set errorResponses(value: Partial<ErrorResponses>);
54
- /**
55
- * Assemble error responses by merging defaults with custom overrides.
56
- * @param customErrors Custom error responses to override defaults
57
- */
58
- assembleErrors: (customErrors?: {}) => void;
59
- /**
60
- * Parses HTTP Range header and returns start/end byte positions for partial content requests.
61
- * @param rangeHeader HTTP Range header value (e.g., "bytes=0-1023").
62
- * @param fileSize Total size of the file in bytes.
63
- * @returns Object with start and end positions, or undefined if range is invalid.
64
- */
65
- parseRangeHeader(rangeHeader: string | undefined, fileSize: number): {
66
- end: number;
67
- start: number;
68
- } | undefined;
69
- /**
70
- * Build file URL from request and file data.
71
- * Platform-agnostic version that accepts URL string.
72
- * @param requestUrl Request URL string
73
- * @param file File object containing ID and content type
74
- * @returns Constructed file URL with extension based on content type
75
- */
76
- protected buildFileUrlFromString(requestUrl: string, file: TFile): string;
77
- /**
78
- * Negotiates content type based on Accept header and supported formats.
79
- * Platform-agnostic version that accepts header string.
80
- * @param acceptHeader Accept header value
81
- * @param supportedTypes Array of supported MIME types to match against
82
- * @returns Best matching content type or undefined if no match found
83
- */
84
- negotiateContentTypeFromHeader(acceptHeader: string | undefined, supportedTypes: string[]): string | undefined;
85
- /**
86
- * Check for undefined ID or path errors and throw appropriate HTTP errors.
87
- * @param error The error to check
88
- */
89
- protected checkForUndefinedIdOrPath(error: unknown): void;
90
- }
91
- export default BaseHandlerCore;
@@ -1,76 +0,0 @@
1
- import type { UploadFile } from "../../storage/utils/index.d.ts";
2
- import type { UploadResponse } from "../../utils/types.d.ts";
3
- import type { Handlers, ResponseFile, ResponseList, UploadOptions } from "../types.d.ts";
4
- import BaseHandlerCore from "./base-handler-core.d.ts";
5
- /**
6
- * Base handler for Web API Fetch platform (Request/Response).
7
- * Extends BaseHandlerCore with Fetch-specific request/response handling.
8
- * @template TFile The file type used by this handler.
9
- */
10
- declare abstract class BaseHandlerFetch<TFile extends UploadFile> extends BaseHandlerCore<TFile> {
11
- /**
12
- * Limiting enabled HTTP method handler.
13
- */
14
- static readonly methods: Handlers[];
15
- /**
16
- * Map of registered HTTP method handlers.
17
- */
18
- protected registeredHandlers: Map<string, (request: Request) => Promise<ResponseFile<TFile> | ResponseList<TFile>>>;
19
- constructor(options: UploadOptions<TFile>);
20
- /**
21
- * Gets the registered handlers map.
22
- * @returns Map of registered handlers.
23
- */
24
- get handlers(): Map<string, (request: Request) => Promise<ResponseFile<TFile> | ResponseList<TFile>>>;
25
- /**
26
- * Handles Web API Fetch requests (for Hono, Cloudflare Workers, etc.).
27
- * @param request Web API Request object.
28
- * @returns Promise resolving to Web API Response.
29
- */
30
- fetch(request: Request): Promise<globalThis.Response>;
31
- /**
32
- * Compose and register HTTP method handlers.
33
- * Subclasses should override this to register their specific handlers.
34
- */
35
- protected abstract compose(): void;
36
- /**
37
- * Handle the response from handlers for fetch requests and convert to Web API Response.
38
- * @param request Web API Request object
39
- * @param file Response file or list from handler
40
- * @returns Promise resolving to Web API Response object
41
- */
42
- protected handleFetchResponse(request: Request, file: ResponseFile<TFile> | ResponseList<TFile>): Promise<globalThis.Response>;
43
- /**
44
- * Convert headers to Web API Headers format by flattening arrays and converting to strings.
45
- * @param headers Headers object with potentially array values
46
- * @returns Headers object with all values as strings
47
- */
48
- protected convertHeaders(headers: Record<string, number | string | string[]>): Record<string, string>;
49
- /**
50
- * Create Web API Response from UploadResponse object.
51
- * @param uploadResponse Upload response containing body, headers, and status code
52
- * @returns Web API Response object
53
- */
54
- protected createResponse(uploadResponse: UploadResponse): globalThis.Response;
55
- /**
56
- * Create error Response from Error object with appropriate status code and message.
57
- * @param error Error object to convert to HTTP error response
58
- * @returns Web API Response object with error details
59
- */
60
- protected createErrorResponse(error: Error): Promise<globalThis.Response>;
61
- /**
62
- * Build file URL from request and file data.
63
- * @param request Web API Request object
64
- * @param file File object containing ID and content type
65
- * @returns Constructed file URL with extension based on content type
66
- */
67
- protected buildFileUrl(request: Request, file: TFile): string;
68
- /**
69
- * Negotiates content type based on Accept header and supported formats.
70
- * @param request Web API Request object containing Accept header.
71
- * @param supportedTypes Array of supported MIME types to match against.
72
- * @returns Best matching content type or undefined if no match found.
73
- */
74
- negotiateContentType(request: Request, supportedTypes: string[]): string | undefined;
75
- }
76
- export default BaseHandlerFetch;