alepha 0.11.4 → 0.11.5

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/file.d.ts CHANGED
@@ -1 +1,528 @@
1
- export * from '@alepha/file';
1
+ import * as _alepha_core0 from "alepha";
2
+ import { FileLike, StreamLike } from "alepha";
3
+ import { Readable } from "node:stream";
4
+
5
+ //#region src/helpers/detectFileType.d.ts
6
+ interface FileTypeResult {
7
+ /**
8
+ * The detected MIME type
9
+ */
10
+ mimeType: string;
11
+ /**
12
+ * The detected file extension
13
+ */
14
+ extension: string;
15
+ /**
16
+ * Whether the file type was verified by magic bytes
17
+ */
18
+ verified: boolean;
19
+ /**
20
+ * The stream (potentially wrapped to allow re-reading)
21
+ */
22
+ stream: Readable;
23
+ }
24
+ /**
25
+ * Detects the file type by checking magic bytes against the stream content.
26
+ *
27
+ * @param stream - The readable stream to check
28
+ * @param filename - The filename (used to get the extension)
29
+ * @returns File type information including MIME type, extension, and verification status
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * const stream = fs.createReadStream('image.png');
34
+ * const result = await detectFileType(stream, 'image.png');
35
+ * console.log(result.mimeType); // 'image/png'
36
+ * console.log(result.verified); // true if magic bytes match
37
+ * ```
38
+ */
39
+ declare function detectFileType(stream: Readable, filename: string): Promise<FileTypeResult>;
40
+ //#endregion
41
+ //#region src/FileSystem.d.ts
42
+ /**
43
+ * Options for creating a file from a URL
44
+ */
45
+ interface CreateFileFromUrlOptions {
46
+ /**
47
+ * The URL to load the file from (file://, http://, or https://)
48
+ */
49
+ url: string;
50
+ /**
51
+ * The MIME type of the file (optional, will be detected from filename if not provided)
52
+ */
53
+ type?: string;
54
+ /**
55
+ * The name of the file (optional, will be extracted from URL if not provided)
56
+ */
57
+ name?: string;
58
+ }
59
+ /**
60
+ * Options for creating a file from a Buffer
61
+ */
62
+ interface CreateFileFromBufferOptions {
63
+ /**
64
+ * The Buffer containing the file data
65
+ */
66
+ buffer: Buffer;
67
+ /**
68
+ * The MIME type of the file (optional, will be detected from name if not provided)
69
+ */
70
+ type?: string;
71
+ /**
72
+ * The name of the file (required for proper content type detection)
73
+ */
74
+ name?: string;
75
+ }
76
+ /**
77
+ * Options for creating a file from a stream
78
+ */
79
+ interface CreateFileFromStreamOptions {
80
+ /**
81
+ * The readable stream containing the file data
82
+ */
83
+ stream: StreamLike;
84
+ /**
85
+ * The MIME type of the file (optional, will be detected from name if not provided)
86
+ */
87
+ type?: string;
88
+ /**
89
+ * The name of the file (required for proper content type detection)
90
+ */
91
+ name?: string;
92
+ /**
93
+ * The size of the file in bytes (optional)
94
+ */
95
+ size?: number;
96
+ }
97
+ /**
98
+ * Options for creating a file from text content
99
+ */
100
+ interface CreateFileFromTextOptions {
101
+ /**
102
+ * The text content to create the file from
103
+ */
104
+ text: string;
105
+ /**
106
+ * The MIME type of the file (default: text/plain)
107
+ */
108
+ type?: string;
109
+ /**
110
+ * The name of the file (default: "file.txt")
111
+ */
112
+ name?: string;
113
+ }
114
+ /**
115
+ * Options for creating a file from a Web File object
116
+ */
117
+ interface CreateFileFromWebFileOptions {
118
+ /**
119
+ * The Web File object
120
+ */
121
+ file: File;
122
+ /**
123
+ * Override the MIME type (optional, uses file.type if not provided)
124
+ */
125
+ type?: string;
126
+ /**
127
+ * Override the name (optional, uses file.name if not provided)
128
+ */
129
+ name?: string;
130
+ /**
131
+ * Override the size (optional, uses file.size if not provided)
132
+ */
133
+ size?: number;
134
+ }
135
+ /**
136
+ * Options for creating a file from an ArrayBuffer
137
+ */
138
+ interface CreateFileFromArrayBufferOptions {
139
+ /**
140
+ * The ArrayBuffer containing the file data
141
+ */
142
+ arrayBuffer: ArrayBuffer;
143
+ /**
144
+ * The MIME type of the file (optional, will be detected from name if not provided)
145
+ */
146
+ type?: string;
147
+ /**
148
+ * The name of the file (required for proper content type detection)
149
+ */
150
+ name?: string;
151
+ }
152
+ /**
153
+ * Union type for all createFile options
154
+ */
155
+ type CreateFileOptions = CreateFileFromUrlOptions | CreateFileFromBufferOptions | CreateFileFromStreamOptions | CreateFileFromTextOptions | CreateFileFromWebFileOptions | CreateFileFromArrayBufferOptions;
156
+ /**
157
+ * Options for rm (remove) operation
158
+ */
159
+ interface RmOptions {
160
+ /**
161
+ * If true, removes directories and their contents recursively
162
+ */
163
+ recursive?: boolean;
164
+ /**
165
+ * If true, no error will be thrown if the path does not exist
166
+ */
167
+ force?: boolean;
168
+ }
169
+ /**
170
+ * Options for cp (copy) operation
171
+ */
172
+ interface CpOptions {
173
+ /**
174
+ * If true, copy directories recursively
175
+ */
176
+ recursive?: boolean;
177
+ /**
178
+ * If true, overwrite existing destination
179
+ */
180
+ force?: boolean;
181
+ }
182
+ /**
183
+ * Options for mkdir operation
184
+ */
185
+ interface MkdirOptions {
186
+ /**
187
+ * If true, creates parent directories as needed
188
+ */
189
+ recursive?: boolean;
190
+ /**
191
+ * File mode (permission and sticky bits)
192
+ */
193
+ mode?: number;
194
+ }
195
+ /**
196
+ * Options for ls (list) operation
197
+ */
198
+ interface LsOptions {
199
+ /**
200
+ * If true, list contents of directories recursively
201
+ */
202
+ recursive?: boolean;
203
+ /**
204
+ * If true, include hidden files (starting with .)
205
+ */
206
+ hidden?: boolean;
207
+ }
208
+ /**
209
+ * FileSystem interface providing utilities for working with files.
210
+ */
211
+ declare abstract class FileSystem {
212
+ /**
213
+ * Creates a FileLike object from various sources.
214
+ *
215
+ * @param options - Options for creating the file
216
+ * @returns A FileLike object
217
+ */
218
+ abstract createFile(options: CreateFileOptions): FileLike;
219
+ /**
220
+ * Detects the file type by checking magic bytes in a stream.
221
+ *
222
+ * @param stream - The readable stream to check
223
+ * @param filename - The filename (used to get the extension)
224
+ * @returns File type information including MIME type, extension, and verification status
225
+ */
226
+ abstract detectFileType(stream: Readable, filename: string): Promise<FileTypeResult>;
227
+ /**
228
+ * Gets the content type (MIME type) based on a filename.
229
+ *
230
+ * @param filename - The filename to check
231
+ * @returns The MIME type
232
+ */
233
+ abstract getContentType(filename: string): string;
234
+ /**
235
+ * Removes a file or directory.
236
+ *
237
+ * @param path - The path to remove
238
+ * @param options - Remove options
239
+ */
240
+ abstract rm(path: string, options?: RmOptions): Promise<void>;
241
+ /**
242
+ * Copies a file or directory.
243
+ *
244
+ * @param src - Source path
245
+ * @param dest - Destination path
246
+ * @param options - Copy options
247
+ */
248
+ abstract cp(src: string, dest: string, options?: CpOptions): Promise<void>;
249
+ /**
250
+ * Moves/renames a file or directory.
251
+ *
252
+ * @param src - Source path
253
+ * @param dest - Destination path
254
+ */
255
+ abstract mv(src: string, dest: string): Promise<void>;
256
+ /**
257
+ * Creates a directory.
258
+ *
259
+ * @param path - The directory path to create
260
+ * @param options - Mkdir options
261
+ */
262
+ abstract mkdir(path: string, options?: MkdirOptions): Promise<void>;
263
+ /**
264
+ * Lists files in a directory.
265
+ *
266
+ * @param path - The directory path to list
267
+ * @param options - List options
268
+ * @returns Array of filenames
269
+ */
270
+ abstract ls(path: string, options?: LsOptions): Promise<string[]>;
271
+ }
272
+ //#endregion
273
+ //#region src/helpers/createFile.d.ts
274
+ declare const createFile: (source: string | Buffer | ArrayBuffer | StreamLike | File, options?: {
275
+ type?: string;
276
+ name?: string;
277
+ size?: number;
278
+ }) => FileLike;
279
+ declare const createFileFromWebFile: (source: File, options?: {
280
+ type?: string;
281
+ name?: string;
282
+ size?: number;
283
+ }) => FileLike;
284
+ declare const createFileFromBuffer: (source: Buffer, options?: {
285
+ type?: string;
286
+ name?: string;
287
+ }) => FileLike;
288
+ declare const createFileFromStream: (source: StreamLike, options?: {
289
+ type?: string;
290
+ name?: string;
291
+ size?: number;
292
+ }) => FileLike & {
293
+ _buffer: null | Buffer;
294
+ };
295
+ declare const createFileFromUrl: (url: string, options?: {
296
+ type?: string;
297
+ name?: string;
298
+ }) => FileLike;
299
+ /**
300
+ * Converts a stream-like object to a Buffer.
301
+ */
302
+ declare const streamToBuffer: (streamLike: StreamLike) => Promise<Buffer>;
303
+ /**
304
+ * Converts a Node.js Buffer to an ArrayBuffer.
305
+ */
306
+ declare const bufferToArrayBuffer: (buffer: Buffer) => ArrayBuffer;
307
+ declare const isReadableStream: (obj: unknown) => obj is NodeJS.ReadableStream;
308
+ //#endregion
309
+ //#region src/helpers/getContentType.d.ts
310
+ /**
311
+ * Can be used to get the content type of file based on its extension.
312
+ *
313
+ * Feel free to add more mime types in your project!
314
+ */
315
+ declare const mimeMap: Record<string, string>;
316
+ /**
317
+ * Returns the content type of file based on its filename.
318
+ * @see {mimeMap}
319
+ */
320
+ declare const getContentType: (filename: string) => string;
321
+ //#endregion
322
+ //#region src/NodeFileSystem.d.ts
323
+ /**
324
+ * Node.js implementation of FileSystem interface.
325
+ *
326
+ * @example
327
+ * ```typescript
328
+ * const fs = new NodeFileSystem();
329
+ *
330
+ * // Create from URL
331
+ * const file1 = fs.createFile({ url: "file:///path/to/file.png" });
332
+ *
333
+ * // Create from Buffer
334
+ * const file2 = fs.createFile({ buffer: Buffer.from("hello"), name: "hello.txt" });
335
+ *
336
+ * // Create from text
337
+ * const file3 = fs.createFile({ text: "Hello, world!", name: "greeting.txt" });
338
+ *
339
+ * // File operations
340
+ * await fs.mkdir("/tmp/mydir", { recursive: true });
341
+ * await fs.cp("/src/file.txt", "/dest/file.txt");
342
+ * await fs.mv("/old/path.txt", "/new/path.txt");
343
+ * const files = await fs.ls("/tmp");
344
+ * await fs.rm("/tmp/file.txt");
345
+ * ```
346
+ */
347
+ declare class NodeFileSystem implements FileSystem {
348
+ /**
349
+ * Creates a FileLike object from various sources.
350
+ *
351
+ * @param options - Options for creating the file
352
+ * @returns A FileLike object
353
+ *
354
+ * @example
355
+ * ```typescript
356
+ * const fs = new NodeFileSystem();
357
+ *
358
+ * // From URL
359
+ * const file1 = fs.createFile({ url: "https://example.com/image.png" });
360
+ *
361
+ * // From Buffer
362
+ * const file2 = fs.createFile({
363
+ * buffer: Buffer.from("hello"),
364
+ * name: "hello.txt",
365
+ * type: "text/plain"
366
+ * });
367
+ *
368
+ * // From text
369
+ * const file3 = fs.createFile({ text: "Hello!", name: "greeting.txt" });
370
+ *
371
+ * // From stream with detection
372
+ * const stream = createReadStream("/path/to/file.png");
373
+ * const file4 = fs.createFile({ stream, name: "image.png" });
374
+ * ```
375
+ */
376
+ createFile(options: CreateFileOptions): FileLike;
377
+ /**
378
+ * Detects the file type by checking magic bytes in a stream.
379
+ *
380
+ * @param stream - The readable stream to check
381
+ * @param filename - The filename (used to get the extension)
382
+ * @returns File type information including MIME type, extension, and verification status
383
+ *
384
+ * @example
385
+ * ```typescript
386
+ * const fs = new NodeFileSystem();
387
+ * const stream = createReadStream('image.png');
388
+ * const result = await fs.detectFileType(stream, 'image.png');
389
+ * console.log(result.mimeType); // 'image/png'
390
+ * console.log(result.verified); // true if magic bytes match
391
+ * ```
392
+ */
393
+ detectFileType(stream: Readable, filename: string): Promise<FileTypeResult>;
394
+ /**
395
+ * Gets the content type (MIME type) based on a filename.
396
+ *
397
+ * @param filename - The filename to check
398
+ * @returns The MIME type
399
+ *
400
+ * @example
401
+ * ```typescript
402
+ * const fs = new NodeFileSystem();
403
+ * const mimeType = fs.getContentType("image.png"); // "image/png"
404
+ * ```
405
+ */
406
+ getContentType(filename: string): string;
407
+ /**
408
+ * Removes a file or directory.
409
+ *
410
+ * @param path - The path to remove
411
+ * @param options - Remove options
412
+ *
413
+ * @example
414
+ * ```typescript
415
+ * const fs = new NodeFileSystem();
416
+ *
417
+ * // Remove a file
418
+ * await fs.rm("/tmp/file.txt");
419
+ *
420
+ * // Remove a directory recursively
421
+ * await fs.rm("/tmp/mydir", { recursive: true });
422
+ *
423
+ * // Remove with force (no error if doesn't exist)
424
+ * await fs.rm("/tmp/maybe-exists.txt", { force: true });
425
+ * ```
426
+ */
427
+ rm(path: string, options?: RmOptions): Promise<void>;
428
+ /**
429
+ * Copies a file or directory.
430
+ *
431
+ * @param src - Source path
432
+ * @param dest - Destination path
433
+ * @param options - Copy options
434
+ *
435
+ * @example
436
+ * ```typescript
437
+ * const fs = new NodeFileSystem();
438
+ *
439
+ * // Copy a file
440
+ * await fs.cp("/src/file.txt", "/dest/file.txt");
441
+ *
442
+ * // Copy a directory recursively
443
+ * await fs.cp("/src/dir", "/dest/dir", { recursive: true });
444
+ *
445
+ * // Copy with force (overwrite existing)
446
+ * await fs.cp("/src/file.txt", "/dest/file.txt", { force: true });
447
+ * ```
448
+ */
449
+ cp(src: string, dest: string, options?: CpOptions): Promise<void>;
450
+ /**
451
+ * Moves/renames a file or directory.
452
+ *
453
+ * @param src - Source path
454
+ * @param dest - Destination path
455
+ *
456
+ * @example
457
+ * ```typescript
458
+ * const fs = new NodeFileSystem();
459
+ *
460
+ * // Move/rename a file
461
+ * await fs.mv("/old/path.txt", "/new/path.txt");
462
+ *
463
+ * // Move a directory
464
+ * await fs.mv("/old/dir", "/new/dir");
465
+ * ```
466
+ */
467
+ mv(src: string, dest: string): Promise<void>;
468
+ /**
469
+ * Creates a directory.
470
+ *
471
+ * @param path - The directory path to create
472
+ * @param options - Mkdir options
473
+ *
474
+ * @example
475
+ * ```typescript
476
+ * const fs = new NodeFileSystem();
477
+ *
478
+ * // Create a directory
479
+ * await fs.mkdir("/tmp/mydir");
480
+ *
481
+ * // Create nested directories
482
+ * await fs.mkdir("/tmp/path/to/dir", { recursive: true });
483
+ *
484
+ * // Create with specific permissions
485
+ * await fs.mkdir("/tmp/mydir", { mode: 0o755 });
486
+ * ```
487
+ */
488
+ mkdir(path: string, options?: MkdirOptions): Promise<void>;
489
+ /**
490
+ * Lists files in a directory.
491
+ *
492
+ * @param path - The directory path to list
493
+ * @param options - List options
494
+ * @returns Array of filenames
495
+ *
496
+ * @example
497
+ * ```typescript
498
+ * const fs = new NodeFileSystem();
499
+ *
500
+ * // List files in a directory
501
+ * const files = await fs.ls("/tmp");
502
+ * console.log(files); // ["file1.txt", "file2.txt", "subdir"]
503
+ *
504
+ * // List with hidden files
505
+ * const allFiles = await fs.ls("/tmp", { hidden: true });
506
+ *
507
+ * // List recursively
508
+ * const allFilesRecursive = await fs.ls("/tmp", { recursive: true });
509
+ * ```
510
+ */
511
+ ls(path: string, options?: LsOptions): Promise<string[]>;
512
+ }
513
+ //#endregion
514
+ //#region src/index.d.ts
515
+ /**
516
+ * Provides file system capabilities for Alepha applications with support for multiple file sources and operations.
517
+ *
518
+ * The file module enables working with files from various sources (URLs, buffers, streams) and provides
519
+ * utilities for file type detection, content type determination, and common file system operations.
520
+ *
521
+ * @see {@link FileSystem}
522
+ * @see {@link NodeFileSystem}
523
+ * @module alepha.file
524
+ */
525
+ declare const AlephaFile: _alepha_core0.Service<_alepha_core0.Module<{}>>;
526
+ //#endregion
527
+ export { AlephaFile, CpOptions, CreateFileFromArrayBufferOptions, CreateFileFromBufferOptions, CreateFileFromStreamOptions, CreateFileFromTextOptions, CreateFileFromUrlOptions, CreateFileFromWebFileOptions, CreateFileOptions, FileSystem, FileTypeResult, LsOptions, MkdirOptions, NodeFileSystem, RmOptions, bufferToArrayBuffer, createFile, createFileFromBuffer, createFileFromStream, createFileFromUrl, createFileFromWebFile, detectFileType, getContentType, isReadableStream, mimeMap, streamToBuffer };
528
+ //# sourceMappingURL=index.d.ts.map
package/lock/redis.d.ts CHANGED
@@ -1 +1,24 @@
1
- export * from '@alepha/lock-redis';
1
+ import * as _alepha_core0 from "alepha";
2
+ import { LockProvider } from "alepha/lock";
3
+ import * as _alepha_logger0 from "alepha/logger";
4
+ import { RedisProvider } from "alepha/redis";
5
+
6
+ //#region src/providers/RedisLockProvider.d.ts
7
+ declare class RedisLockProvider implements LockProvider {
8
+ protected readonly log: _alepha_logger0.Logger;
9
+ protected readonly redisProvider: RedisProvider;
10
+ set(key: string, value: string, nx?: boolean, px?: number): Promise<string>;
11
+ del(...keys: string[]): Promise<void>;
12
+ }
13
+ //#endregion
14
+ //#region src/index.d.ts
15
+ /**
16
+ * Plugin for Alepha that provides a locking mechanism.
17
+ *
18
+ * @see {@link RedisLockProvider}
19
+ * @module alepha.lock.redis
20
+ */
21
+ declare const AlephaLockRedis: _alepha_core0.Service<_alepha_core0.Module<{}>>;
22
+ //#endregion
23
+ export { AlephaLockRedis, RedisLockProvider };
24
+ //# sourceMappingURL=index.d.ts.map