@pz4l/tinyimg-core 0.0.0
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/README.md +688 -0
- package/README.zh-CN.md +688 -0
- package/dist/index.d.mts +516 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +851 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +53 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,516 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
import * as p_limit0 from "p-limit";
|
|
3
|
+
|
|
4
|
+
//#region src/cache/buffer-storage.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Cache storage for reading and writing compressed image data by hash.
|
|
7
|
+
*
|
|
8
|
+
* Uses atomic writes (temp file + rename) for concurrent safety.
|
|
9
|
+
* Handles corruption gracefully by returning null on read failures.
|
|
10
|
+
*/
|
|
11
|
+
declare class BufferCacheStorage {
|
|
12
|
+
private readonly cacheDir;
|
|
13
|
+
constructor(cacheDir: string);
|
|
14
|
+
/**
|
|
15
|
+
* Ensure cache directory exists.
|
|
16
|
+
*/
|
|
17
|
+
private ensureDir;
|
|
18
|
+
/**
|
|
19
|
+
* Get the cache file path for an image hash.
|
|
20
|
+
*
|
|
21
|
+
* @param hash - MD5 hash of the image buffer
|
|
22
|
+
* @returns Path to cache file (MD5 hash as filename, no extension)
|
|
23
|
+
*/
|
|
24
|
+
getCachePath(hash: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Read cached compressed image data by hash.
|
|
27
|
+
*
|
|
28
|
+
* @param hash - MD5 hash of the image buffer
|
|
29
|
+
* @returns Cached Buffer or null if not found/corrupted
|
|
30
|
+
*/
|
|
31
|
+
read(hash: string): Promise<Buffer | null>;
|
|
32
|
+
/**
|
|
33
|
+
* Write compressed image data to cache by hash.
|
|
34
|
+
*
|
|
35
|
+
* Uses atomic write pattern: temp file + rename.
|
|
36
|
+
*
|
|
37
|
+
* @param hash - MD5 hash of the image buffer
|
|
38
|
+
* @param data - Compressed image data to cache
|
|
39
|
+
*/
|
|
40
|
+
write(hash: string, data: Buffer): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Read cached image data from multiple cache directories in priority order.
|
|
44
|
+
*
|
|
45
|
+
* @param hash - MD5 hash of the image buffer
|
|
46
|
+
* @param cacheDirs - Array of cache directories (priority order)
|
|
47
|
+
* @returns First successful Buffer read or null if all miss
|
|
48
|
+
*/
|
|
49
|
+
declare function readCacheByHash(hash: string, cacheDirs: string[]): Promise<Buffer | null>;
|
|
50
|
+
/**
|
|
51
|
+
* Write compressed image data to cache by hash.
|
|
52
|
+
*
|
|
53
|
+
* @param hash - MD5 hash of the image buffer
|
|
54
|
+
* @param data - Compressed image data to cache
|
|
55
|
+
* @param cacheDir - Cache directory to write to
|
|
56
|
+
*/
|
|
57
|
+
declare function writeCacheByHash(hash: string, data: Buffer, cacheDir: string): Promise<void>;
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/cache/hash.d.ts
|
|
60
|
+
/**
|
|
61
|
+
* Calculate MD5 hash of a file's content.
|
|
62
|
+
*
|
|
63
|
+
* @param filePath - Absolute path to the file
|
|
64
|
+
* @returns MD5 hash as a 32-character hexadecimal string
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* const hash = await calculateMD5('/path/to/image.png')
|
|
69
|
+
* console.log(hash) // 'a1b2c3d4e5f6...'
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
declare function calculateMD5(filePath: string): Promise<string>;
|
|
73
|
+
/**
|
|
74
|
+
* Calculate MD5 hash of a buffer's content.
|
|
75
|
+
*
|
|
76
|
+
* @param buffer - Buffer to hash
|
|
77
|
+
* @returns MD5 hash as a 32-character hexadecimal string
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* const hash = await calculateMD5FromBuffer(buffer)
|
|
82
|
+
* console.log(hash) // 'a1b2c3d4e5f6...'
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
declare function calculateMD5FromBuffer(buffer: Buffer): Promise<string>;
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region src/cache/paths.d.ts
|
|
88
|
+
/**
|
|
89
|
+
* Get the project-level cache directory path.
|
|
90
|
+
*
|
|
91
|
+
* @param projectRoot - Absolute path to the project root directory
|
|
92
|
+
* @returns Path to project cache directory: `node_modules/.tinyimg_cache/`
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* const cachePath = getProjectCachePath('/Users/test/project')
|
|
97
|
+
* // Returns: '/Users/test/project/node_modules/.tinyimg_cache'
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
declare function getProjectCachePath(projectRoot: string): string;
|
|
101
|
+
/**
|
|
102
|
+
* Get the global cache directory path.
|
|
103
|
+
*
|
|
104
|
+
* @returns Path to global cache directory: `~/.tinyimg/cache/`
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```ts
|
|
108
|
+
* const cachePath = getGlobalCachePath()
|
|
109
|
+
* // Returns: '/Users/username/.tinyimg/cache'
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
declare function getGlobalCachePath(): string;
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/cache/stats.d.ts
|
|
115
|
+
/**
|
|
116
|
+
* Cache statistics interface.
|
|
117
|
+
*/
|
|
118
|
+
interface CacheStats {
|
|
119
|
+
count: number;
|
|
120
|
+
size: number;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Format bytes to human-readable format.
|
|
124
|
+
*
|
|
125
|
+
* @param bytes - Number of bytes
|
|
126
|
+
* @returns Formatted string (e.g., "1.23 MB", "456 KB")
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```ts
|
|
130
|
+
* formatBytes(0) // "0 B"
|
|
131
|
+
* formatBytes(512) // "512 B"
|
|
132
|
+
* formatBytes(1024) // "1.00 KB"
|
|
133
|
+
* formatBytes(1024 * 1024) // "1.00 MB"
|
|
134
|
+
* formatBytes(1024 * 1024 * 1024) // "1.00 GB"
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
declare function formatBytes(bytes: number): string;
|
|
138
|
+
/**
|
|
139
|
+
* Get cache statistics for a directory.
|
|
140
|
+
*
|
|
141
|
+
* @param cacheDir - Cache directory path
|
|
142
|
+
* @returns Cache statistics (count and size)
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```ts
|
|
146
|
+
* const stats = await getCacheStats('/path/to/cache')
|
|
147
|
+
* console.log(`Files: ${stats.count}, Size: ${formatBytes(stats.size)}`)
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
declare function getCacheStats(cacheDir: string): Promise<CacheStats>;
|
|
151
|
+
/**
|
|
152
|
+
* Get cache statistics for both project and global cache.
|
|
153
|
+
*
|
|
154
|
+
* @param projectRoot - Optional project root directory
|
|
155
|
+
* @returns Object with project and global cache statistics
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```ts
|
|
159
|
+
* // Get both project and global stats
|
|
160
|
+
* const stats = await getAllCacheStats('/project/path')
|
|
161
|
+
* console.log(`Project: ${stats.project?.count}, Global: ${stats.global.count}`)
|
|
162
|
+
*
|
|
163
|
+
* // Get only global stats
|
|
164
|
+
* const globalOnly = await getAllCacheStats()
|
|
165
|
+
* console.log(`Global: ${globalOnly.global.count}`)
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
declare function getAllCacheStats(projectRoot?: string): Promise<{
|
|
169
|
+
project: CacheStats | null;
|
|
170
|
+
global: CacheStats;
|
|
171
|
+
}>;
|
|
172
|
+
//#endregion
|
|
173
|
+
//#region src/cache/storage.d.ts
|
|
174
|
+
/**
|
|
175
|
+
* Cache storage for reading and writing compressed image data.
|
|
176
|
+
*
|
|
177
|
+
* Uses atomic writes (temp file + rename) for concurrent safety.
|
|
178
|
+
* Handles corruption gracefully by returning null on read failures.
|
|
179
|
+
*/
|
|
180
|
+
declare class CacheStorage {
|
|
181
|
+
private readonly cacheDir;
|
|
182
|
+
constructor(cacheDir: string);
|
|
183
|
+
/**
|
|
184
|
+
* Ensure cache directory exists.
|
|
185
|
+
*/
|
|
186
|
+
private ensureDir;
|
|
187
|
+
/**
|
|
188
|
+
* Get the cache file path for an image.
|
|
189
|
+
*
|
|
190
|
+
* @param imagePath - Absolute path to the source image
|
|
191
|
+
* @returns Path to cache file (MD5 hash as filename, no extension)
|
|
192
|
+
*/
|
|
193
|
+
getCachePath(imagePath: string): Promise<string>;
|
|
194
|
+
/**
|
|
195
|
+
* Read cached compressed image data.
|
|
196
|
+
*
|
|
197
|
+
* @param imagePath - Absolute path to the source image
|
|
198
|
+
* @returns Cached Buffer or null if not found/corrupted
|
|
199
|
+
*/
|
|
200
|
+
read(imagePath: string): Promise<Buffer | null>;
|
|
201
|
+
/**
|
|
202
|
+
* Write compressed image data to cache.
|
|
203
|
+
*
|
|
204
|
+
* Uses atomic write pattern: temp file + rename.
|
|
205
|
+
*
|
|
206
|
+
* @param imagePath - Absolute path to the source image
|
|
207
|
+
* @param data - Compressed image data to cache
|
|
208
|
+
*/
|
|
209
|
+
write(imagePath: string, data: Buffer): Promise<void>;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Read cached image data from multiple cache directories in priority order.
|
|
213
|
+
*
|
|
214
|
+
* @param imagePath - Absolute path to the source image
|
|
215
|
+
* @param cacheDirs - Array of cache directories (priority order)
|
|
216
|
+
* @returns First successful Buffer read or null if all miss
|
|
217
|
+
*/
|
|
218
|
+
declare function readCache(imagePath: string, cacheDirs: string[]): Promise<Buffer | null>;
|
|
219
|
+
/**
|
|
220
|
+
* Write compressed image data to cache.
|
|
221
|
+
*
|
|
222
|
+
* @param imagePath - Absolute path to the source image
|
|
223
|
+
* @param data - Compressed image data to cache
|
|
224
|
+
* @param cacheDir - Cache directory to write to
|
|
225
|
+
*/
|
|
226
|
+
declare function writeCache(imagePath: string, data: Buffer, cacheDir: string): Promise<void>;
|
|
227
|
+
//#endregion
|
|
228
|
+
//#region src/keys/pool.d.ts
|
|
229
|
+
type KeyStrategy = 'random' | 'round-robin' | 'priority';
|
|
230
|
+
declare class KeyPool {
|
|
231
|
+
private keys;
|
|
232
|
+
private selector;
|
|
233
|
+
private currentSelection;
|
|
234
|
+
constructor(strategy?: KeyStrategy);
|
|
235
|
+
private createSelector;
|
|
236
|
+
selectKey(): Promise<string>;
|
|
237
|
+
decrementQuota(): void;
|
|
238
|
+
getCurrentKey(): string | null;
|
|
239
|
+
}
|
|
240
|
+
//#endregion
|
|
241
|
+
//#region src/compress/service.d.ts
|
|
242
|
+
interface CompressServiceOptions extends CompressOptions {
|
|
243
|
+
/**
|
|
244
|
+
* Enable cache (default: true)
|
|
245
|
+
*/
|
|
246
|
+
cache?: boolean;
|
|
247
|
+
/**
|
|
248
|
+
* Use project cache only, ignore global cache (default: false)
|
|
249
|
+
*/
|
|
250
|
+
projectCacheOnly?: boolean;
|
|
251
|
+
/**
|
|
252
|
+
* Concurrency limit for batch operations (default: 8)
|
|
253
|
+
*/
|
|
254
|
+
concurrency?: number;
|
|
255
|
+
/**
|
|
256
|
+
* Optional KeyPool instance for testing or advanced usage
|
|
257
|
+
* If not provided, a new KeyPool will be created with 'random' strategy
|
|
258
|
+
*/
|
|
259
|
+
keyPool?: KeyPool;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Compress a single image with cache integration and fallback
|
|
263
|
+
*
|
|
264
|
+
* @param buffer - Original image data
|
|
265
|
+
* @param options - Compression options
|
|
266
|
+
* @returns Compressed image data
|
|
267
|
+
*/
|
|
268
|
+
declare function compressImage(buffer: Buffer, options?: CompressServiceOptions): Promise<Buffer>;
|
|
269
|
+
/**
|
|
270
|
+
* Compress multiple images with concurrency control
|
|
271
|
+
*
|
|
272
|
+
* @param buffers - Array of image buffers
|
|
273
|
+
* @param options - Compression options
|
|
274
|
+
* @returns Array of compressed buffers
|
|
275
|
+
*/
|
|
276
|
+
declare function compressImages(buffers: Buffer[], options?: CompressServiceOptions): Promise<Buffer[]>;
|
|
277
|
+
//#endregion
|
|
278
|
+
//#region src/compress/types.d.ts
|
|
279
|
+
/**
|
|
280
|
+
* Compressor interface for compression implementations
|
|
281
|
+
*
|
|
282
|
+
* @example
|
|
283
|
+
* ```ts
|
|
284
|
+
* const compressor: ICompressor = {
|
|
285
|
+
* compress: async (buffer: Buffer) => {
|
|
286
|
+
* // Compression logic
|
|
287
|
+
* return compressedBuffer
|
|
288
|
+
* }
|
|
289
|
+
* }
|
|
290
|
+
* ```
|
|
291
|
+
*/
|
|
292
|
+
interface ICompressor {
|
|
293
|
+
/**
|
|
294
|
+
* Compress an image buffer
|
|
295
|
+
*
|
|
296
|
+
* @param buffer - Original image data
|
|
297
|
+
* @returns Compressed image data
|
|
298
|
+
* @throws Error when compression fails
|
|
299
|
+
*/
|
|
300
|
+
compress: (buffer: Buffer) => Promise<Buffer>;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Compression mode for selecting compression strategy
|
|
304
|
+
*/
|
|
305
|
+
type CompressionMode = 'auto' | 'api' | 'web';
|
|
306
|
+
/**
|
|
307
|
+
* Options for compression operations
|
|
308
|
+
*
|
|
309
|
+
* @example
|
|
310
|
+
* ```ts
|
|
311
|
+
* const options: CompressOptions = {
|
|
312
|
+
* mode: 'api',
|
|
313
|
+
* maxRetries: 5,
|
|
314
|
+
* compressors: [customCompressor]
|
|
315
|
+
* }
|
|
316
|
+
* ```
|
|
317
|
+
*/
|
|
318
|
+
interface CompressOptions {
|
|
319
|
+
/**
|
|
320
|
+
* Compression mode (default: 'auto')
|
|
321
|
+
* - 'auto': Try API compressor first, fallback to web compressor
|
|
322
|
+
* - 'api': Use API compressor only
|
|
323
|
+
* - 'web': Use web compressor only
|
|
324
|
+
*/
|
|
325
|
+
mode?: CompressionMode;
|
|
326
|
+
/**
|
|
327
|
+
* Custom compressor array for fallback chain
|
|
328
|
+
* If not provided, uses default compressors based on mode
|
|
329
|
+
*/
|
|
330
|
+
compressors?: ICompressor[];
|
|
331
|
+
/**
|
|
332
|
+
* Maximum retry attempts for transient failures (default: 3)
|
|
333
|
+
*/
|
|
334
|
+
maxRetries?: number;
|
|
335
|
+
}
|
|
336
|
+
//#endregion
|
|
337
|
+
//#region src/compress/web-compressor.d.ts
|
|
338
|
+
declare class TinyPngWebCompressor implements ICompressor {
|
|
339
|
+
private retryManager;
|
|
340
|
+
constructor(maxRetries?: number);
|
|
341
|
+
compress(buffer: Buffer): Promise<Buffer>;
|
|
342
|
+
private uploadToTinyPngWeb;
|
|
343
|
+
private downloadCompressedImage;
|
|
344
|
+
getFailureCount(): number;
|
|
345
|
+
}
|
|
346
|
+
//#endregion
|
|
347
|
+
//#region src/compress/api-compressor.d.ts
|
|
348
|
+
declare class TinyPngApiCompressor implements ICompressor {
|
|
349
|
+
private keyPool;
|
|
350
|
+
private retryManager;
|
|
351
|
+
private currentKey;
|
|
352
|
+
constructor(keyPool: KeyPool, maxRetries?: number);
|
|
353
|
+
compress(buffer: Buffer): Promise<Buffer>;
|
|
354
|
+
getFailureCount(): number;
|
|
355
|
+
}
|
|
356
|
+
//#endregion
|
|
357
|
+
//#region src/compress/compose.d.ts
|
|
358
|
+
/**
|
|
359
|
+
* Compress buffer with automatic fallback through multiple compressors
|
|
360
|
+
*
|
|
361
|
+
* @param buffer - Original image data
|
|
362
|
+
* @param options - Compression options (mode, compressors, maxRetries)
|
|
363
|
+
* @returns Compressed image data
|
|
364
|
+
* @throws AllCompressionFailedError when all compressors fail
|
|
365
|
+
*
|
|
366
|
+
* @example
|
|
367
|
+
* ```ts
|
|
368
|
+
* try {
|
|
369
|
+
* const compressed = await compressWithFallback(buffer, { mode: 'auto' })
|
|
370
|
+
* } catch (error) {
|
|
371
|
+
* if (error instanceof AllCompressionFailedError) {
|
|
372
|
+
* // All compression methods failed
|
|
373
|
+
* }
|
|
374
|
+
* }
|
|
375
|
+
* ```
|
|
376
|
+
*/
|
|
377
|
+
declare function compressWithFallback(buffer: Buffer, options?: CompressOptions): Promise<Buffer>;
|
|
378
|
+
/**
|
|
379
|
+
* Get default compressor types for a given mode
|
|
380
|
+
* This is a helper - actual compressor instances created in service layer
|
|
381
|
+
*
|
|
382
|
+
* @param mode - Compression mode
|
|
383
|
+
* @returns Compressor type names (not instances)
|
|
384
|
+
*
|
|
385
|
+
* @example
|
|
386
|
+
* ```ts
|
|
387
|
+
* const types = getCompressorTypesForMode('auto')
|
|
388
|
+
* // Returns: ['TinyPngApiCompressor', 'TinyPngWebCompressor']
|
|
389
|
+
* ```
|
|
390
|
+
*/
|
|
391
|
+
declare function getCompressorTypesForMode(mode?: CompressionMode): string[];
|
|
392
|
+
//#endregion
|
|
393
|
+
//#region src/compress/concurrency.d.ts
|
|
394
|
+
/**
|
|
395
|
+
* Create a concurrency limiter for async operations
|
|
396
|
+
*
|
|
397
|
+
* @param concurrency - Max concurrent operations (default: 8)
|
|
398
|
+
* @returns Limit function that wraps async operations
|
|
399
|
+
*
|
|
400
|
+
* @example
|
|
401
|
+
* ```ts
|
|
402
|
+
* const limit = createConcurrencyLimiter(2)
|
|
403
|
+
* const task1 = limit(() => asyncOperation1())
|
|
404
|
+
* const task2 = limit(() => asyncOperation2())
|
|
405
|
+
* await Promise.all([task1, task2])
|
|
406
|
+
* ```
|
|
407
|
+
*/
|
|
408
|
+
declare function createConcurrencyLimiter(concurrency?: number): p_limit0.LimitFunction;
|
|
409
|
+
/**
|
|
410
|
+
* Execute tasks with concurrency control
|
|
411
|
+
*
|
|
412
|
+
* @param tasks - Array of async functions to execute
|
|
413
|
+
* @param concurrency - Max concurrent tasks (default: 8)
|
|
414
|
+
* @returns Promise resolving to array of results
|
|
415
|
+
*
|
|
416
|
+
* @example
|
|
417
|
+
* ```ts
|
|
418
|
+
* const tasks = [
|
|
419
|
+
* () => compressImage(buffer1),
|
|
420
|
+
* () => compressImage(buffer2),
|
|
421
|
+
* () => compressImage(buffer3)
|
|
422
|
+
* ]
|
|
423
|
+
* const results = await executeWithConcurrency(tasks, 2)
|
|
424
|
+
* // Only 2 compressions run at a time
|
|
425
|
+
* ```
|
|
426
|
+
*/
|
|
427
|
+
declare function executeWithConcurrency<T>(tasks: (() => Promise<T>)[], concurrency?: number): Promise<T[]>;
|
|
428
|
+
//#endregion
|
|
429
|
+
//#region src/compress/retry.d.ts
|
|
430
|
+
declare class RetryManager {
|
|
431
|
+
private maxRetries;
|
|
432
|
+
private baseDelay;
|
|
433
|
+
private failureCount;
|
|
434
|
+
constructor(maxRetries?: number, baseDelay?: number);
|
|
435
|
+
execute<T>(operation: () => Promise<T>): Promise<T>;
|
|
436
|
+
private shouldRetry;
|
|
437
|
+
private sleep;
|
|
438
|
+
getFailureCount(): number;
|
|
439
|
+
reset(): void;
|
|
440
|
+
}
|
|
441
|
+
//#endregion
|
|
442
|
+
//#region src/config/loader.d.ts
|
|
443
|
+
interface LoadedKey {
|
|
444
|
+
key: string;
|
|
445
|
+
valid?: boolean;
|
|
446
|
+
lastCheck?: string;
|
|
447
|
+
}
|
|
448
|
+
declare function loadKeys(): LoadedKey[];
|
|
449
|
+
//#endregion
|
|
450
|
+
//#region src/config/types.d.ts
|
|
451
|
+
interface KeyMetadata {
|
|
452
|
+
key: string;
|
|
453
|
+
valid: boolean;
|
|
454
|
+
lastCheck: string;
|
|
455
|
+
}
|
|
456
|
+
interface ConfigFile {
|
|
457
|
+
keys: KeyMetadata[];
|
|
458
|
+
}
|
|
459
|
+
//#endregion
|
|
460
|
+
//#region src/config/storage.d.ts
|
|
461
|
+
declare function ensureConfigFile(): void;
|
|
462
|
+
declare function readConfig(): ConfigFile;
|
|
463
|
+
declare function writeConfig(config: ConfigFile): void;
|
|
464
|
+
//#endregion
|
|
465
|
+
//#region src/errors/types.d.ts
|
|
466
|
+
declare class AllKeysExhaustedError extends Error {
|
|
467
|
+
constructor(message?: string);
|
|
468
|
+
}
|
|
469
|
+
declare class NoValidKeysError extends Error {
|
|
470
|
+
constructor(message?: string);
|
|
471
|
+
}
|
|
472
|
+
declare class AllCompressionFailedError extends Error {
|
|
473
|
+
constructor(message?: string);
|
|
474
|
+
}
|
|
475
|
+
//#endregion
|
|
476
|
+
//#region src/keys/masker.d.ts
|
|
477
|
+
declare function maskKey(key: string): string;
|
|
478
|
+
//#endregion
|
|
479
|
+
//#region src/keys/quota.d.ts
|
|
480
|
+
declare function queryQuota(key: string): Promise<number>;
|
|
481
|
+
interface QuotaTracker {
|
|
482
|
+
key: string;
|
|
483
|
+
remaining: number;
|
|
484
|
+
localCounter: number;
|
|
485
|
+
decrement: () => void;
|
|
486
|
+
isZero: () => boolean;
|
|
487
|
+
}
|
|
488
|
+
declare function createQuotaTracker(key: string, remaining: number): QuotaTracker;
|
|
489
|
+
//#endregion
|
|
490
|
+
//#region src/keys/selector.d.ts
|
|
491
|
+
interface KeySelection {
|
|
492
|
+
key: string;
|
|
493
|
+
tracker: ReturnType<typeof createQuotaTracker>;
|
|
494
|
+
}
|
|
495
|
+
declare class RandomSelector {
|
|
496
|
+
select(keys: string[]): Promise<KeySelection | null>;
|
|
497
|
+
protected getAvailableKeys(keys: string[]): Promise<KeySelection[]>;
|
|
498
|
+
}
|
|
499
|
+
declare class RoundRobinSelector extends RandomSelector {
|
|
500
|
+
private currentIndex;
|
|
501
|
+
select(keys: string[]): Promise<KeySelection | null>;
|
|
502
|
+
reset(): void;
|
|
503
|
+
}
|
|
504
|
+
declare class PrioritySelector extends RandomSelector {
|
|
505
|
+
select(keys: string[]): Promise<KeySelection | null>;
|
|
506
|
+
}
|
|
507
|
+
//#endregion
|
|
508
|
+
//#region src/keys/validator.d.ts
|
|
509
|
+
declare function validateKey(key: string): Promise<boolean>;
|
|
510
|
+
//#endregion
|
|
511
|
+
//#region src/utils/logger.d.ts
|
|
512
|
+
declare function logWarning(message: string): void;
|
|
513
|
+
declare function logInfo(message: string): void;
|
|
514
|
+
//#endregion
|
|
515
|
+
export { AllCompressionFailedError, AllKeysExhaustedError, BufferCacheStorage, type CacheStats, CacheStorage, type CompressOptions, type CompressServiceOptions, type CompressionMode, type ConfigFile, type ICompressor, type KeyMetadata, KeyPool, type KeyStrategy, type LoadedKey, NoValidKeysError, PrioritySelector, RandomSelector, RetryManager, RoundRobinSelector, TinyPngApiCompressor, TinyPngWebCompressor, calculateMD5, calculateMD5FromBuffer, compressImage, compressImages, compressWithFallback, createConcurrencyLimiter, createQuotaTracker, ensureConfigFile, executeWithConcurrency, formatBytes, getAllCacheStats, getCacheStats, getCompressorTypesForMode, getGlobalCachePath, getProjectCachePath, loadKeys, logInfo, logWarning, maskKey, queryQuota, readCache, readCacheByHash, readConfig, validateKey, writeCache, writeCacheByHash, writeConfig };
|
|
516
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/cache/buffer-storage.ts","../src/cache/hash.ts","../src/cache/paths.ts","../src/cache/stats.ts","../src/cache/storage.ts","../src/keys/pool.ts","../src/compress/service.ts","../src/compress/types.ts","../src/compress/web-compressor.ts","../src/compress/api-compressor.ts","../src/compress/compose.ts","../src/compress/concurrency.ts","../src/compress/retry.ts","../src/config/loader.ts","../src/config/types.ts","../src/config/storage.ts","../src/errors/types.ts","../src/keys/masker.ts","../src/keys/quota.ts","../src/keys/selector.ts","../src/keys/validator.ts","../src/utils/logger.ts"],"mappings":";;;;;;;AAWA;;;cAAa,kBAAA;EAAA,iBACkB,QAAA;cAAA,QAAA;EA6CY;;;EAAA,QAxC3B,SAAA;;;;;;;EAUd,YAAA,CAAa,IAAA;EAUa;;;;;;EAApB,IAAA,CAAK,IAAA,WAAe,OAAA,CAAQ,MAAA;EAoBc;;AAmBlD;;;;;;EAnBQ,KAAA,CAAM,IAAA,UAAc,IAAA,EAAM,MAAA,GAAS,OAAA;AAAA;;;AA2C3C;;;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