alepha 0.11.2 → 0.11.4

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 (50) hide show
  1. package/api/files.d.ts +1 -439
  2. package/api/jobs.d.ts +1 -218
  3. package/api/notifications.d.ts +1 -264
  4. package/api/users.d.ts +1 -924
  5. package/batch.d.ts +1 -585
  6. package/bucket.d.ts +1 -507
  7. package/cache/redis.d.ts +1 -40
  8. package/cache.d.ts +1 -288
  9. package/command.d.ts +1 -238
  10. package/core.d.ts +1 -1563
  11. package/datetime.d.ts +5 -3
  12. package/devtools.d.ts +1 -368
  13. package/email.d.ts +1 -144
  14. package/fake.cjs +8 -0
  15. package/fake.d.ts +1 -0
  16. package/fake.js +1 -0
  17. package/file.d.ts +1 -53
  18. package/lock/redis.d.ts +1 -24
  19. package/lock.d.ts +1 -552
  20. package/logger.d.ts +1 -284
  21. package/package.json +57 -50
  22. package/postgres.d.ts +1 -1931
  23. package/queue/redis.d.ts +1 -29
  24. package/queue.d.ts +1 -760
  25. package/react/auth.d.ts +1 -499
  26. package/react/form.d.ts +1 -188
  27. package/react/head.d.ts +1 -120
  28. package/react/i18n.d.ts +1 -118
  29. package/react.d.ts +1 -929
  30. package/redis.d.ts +1 -82
  31. package/scheduler.d.ts +1 -145
  32. package/security.d.ts +1 -586
  33. package/server/cache.d.ts +1 -163
  34. package/server/compress.d.ts +1 -32
  35. package/server/cookies.d.ts +1 -144
  36. package/server/cors.d.ts +1 -27
  37. package/server/health.d.ts +1 -59
  38. package/server/helmet.d.ts +1 -69
  39. package/server/links.d.ts +1 -316
  40. package/server/metrics.d.ts +1 -35
  41. package/server/multipart.d.ts +1 -42
  42. package/server/proxy.d.ts +1 -234
  43. package/server/security.d.ts +1 -87
  44. package/server/static.d.ts +1 -119
  45. package/server/swagger.d.ts +1 -148
  46. package/server.d.ts +1 -849
  47. package/topic/redis.d.ts +1 -42
  48. package/topic.d.ts +1 -819
  49. package/ui.d.ts +1 -619
  50. package/vite.d.ts +1 -197
package/bucket.d.ts CHANGED
@@ -1,507 +1 @@
1
- import * as _alepha_core1 from "alepha";
2
- import { Alepha, AlephaError, Descriptor, FileLike, KIND, Service } from "alepha";
3
- import * as fs from "node:fs";
4
- import * as _alepha_logger0 from "alepha/logger";
5
- import * as typebox0 from "typebox";
6
-
7
- //#region src/providers/FileStorageProvider.d.ts
8
- declare abstract class FileStorageProvider {
9
- /**
10
- * Uploads a file to the storage.
11
- *
12
- * @param bucketName - Container name
13
- * @param file - File to upload
14
- * @param fileId - Optional file identifier. If not provided, a unique ID will be generated.
15
- * @return The identifier of the uploaded file.
16
- */
17
- abstract upload(bucketName: string, file: FileLike, fileId?: string): Promise<string>;
18
- /**
19
- * Downloads a file from the storage.
20
- *
21
- * @param bucketName - Container name
22
- * @param fileId - Identifier of the file to download
23
- * @return The downloaded file as a FileLike object.
24
- */
25
- abstract download(bucketName: string, fileId: string): Promise<FileLike>;
26
- /**
27
- * Check if fileId exists in the storage bucket.
28
- *
29
- * @param bucketName - Container name
30
- * @param fileId - Identifier of the file to stream
31
- * @return True is the file exists, false otherwise.
32
- */
33
- abstract exists(bucketName: string, fileId: string): Promise<boolean>;
34
- /**
35
- * Delete permanently a file from the storage.
36
- *
37
- * @param bucketName - Container name
38
- * @param fileId - Identifier of the file to delete
39
- */
40
- abstract delete(bucketName: string, fileId: string): Promise<void>;
41
- }
42
- //#endregion
43
- //#region src/providers/MemoryFileStorageProvider.d.ts
44
- declare class MemoryFileStorageProvider implements FileStorageProvider {
45
- readonly files: Record<string, FileLike>;
46
- upload(bucketName: string, file: FileLike, fileId?: string): Promise<string>;
47
- download(bucketName: string, fileId: string): Promise<FileLike>;
48
- exists(bucketName: string, fileId: string): Promise<boolean>;
49
- delete(bucketName: string, fileId: string): Promise<void>;
50
- protected createId(): string;
51
- }
52
- //#endregion
53
- //#region src/descriptors/$bucket.d.ts
54
- /**
55
- * Creates a bucket descriptor for file storage and management with configurable validation.
56
- *
57
- * This descriptor provides a comprehensive file storage system that handles file uploads,
58
- * downloads, validation, and management across multiple storage backends. It supports
59
- * MIME type validation, size limits, and integrates seamlessly with various storage
60
- * providers for scalable file management in applications.
61
- *
62
- * **Key Features**
63
- *
64
- * - **Multi-Provider Support**: Works with filesystem, cloud storage (S3, Azure), and in-memory providers
65
- * - **File Validation**: Automatic MIME type checking and file size validation
66
- * - **Type Safety**: Full TypeScript support with FileLike interface compatibility
67
- * - **Event Integration**: Emits events for file operations (upload, delete) for monitoring
68
- * - **Flexible Configuration**: Per-bucket and per-operation configuration options
69
- * - **Automatic Detection**: Smart file type and size detection with fallback mechanisms
70
- * - **Error Handling**: Comprehensive error handling with descriptive error messages
71
- *
72
- * **Use Cases**
73
- *
74
- * Perfect for handling file storage requirements across applications:
75
- * - User profile picture and document uploads
76
- * - Product image and media management
77
- * - Document storage and retrieval systems
78
- * - Temporary file handling and processing
79
- * - Content delivery and asset management
80
- * - Backup and archival storage
81
- * - File-based data import/export workflows
82
- *
83
- * @example
84
- * **Basic file upload bucket:**
85
- * ```ts
86
- * import { $bucket } from "alepha/bucket";
87
- *
88
- * class MediaService {
89
- * images = $bucket({
90
- * name: "user-images",
91
- * description: "User uploaded profile images and photos",
92
- * mimeTypes: ["image/jpeg", "image/png", "image/gif", "image/webp"],
93
- * maxSize: 5 // 5MB limit
94
- * });
95
- *
96
- * async uploadProfileImage(file: FileLike, userId: string): Promise<string> {
97
- * // File is automatically validated against MIME types and size
98
- * const fileId = await this.images.upload(file);
99
- *
100
- * // Update user profile with new image
101
- * await this.userService.updateProfileImage(userId, fileId);
102
- *
103
- * return fileId;
104
- * }
105
- *
106
- * async getUserProfileImage(userId: string): Promise<FileLike> {
107
- * const user = await this.userService.getUser(userId);
108
- * if (!user.profileImageId) {
109
- * throw new Error('User has no profile image');
110
- * }
111
- *
112
- * return await this.images.download(user.profileImageId);
113
- * }
114
- * }
115
- * ```
116
- *
117
- * @example
118
- * **Document storage with multiple file types:**
119
- * ```ts
120
- * class DocumentManager {
121
- * documents = $bucket({
122
- * name: "company-documents",
123
- * description: "Legal documents, contracts, and reports",
124
- * mimeTypes: [
125
- * "application/pdf",
126
- * "application/msword",
127
- * "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
128
- * "text/plain",
129
- * "text/csv"
130
- * ],
131
- * maxSize: 50 // 50MB for large documents
132
- * });
133
- *
134
- * async uploadDocument(file: FileLike, metadata: { title: string; category: string; userId: string }): Promise<string> {
135
- * try {
136
- * const fileId = await this.documents.upload(file);
137
- *
138
- * // Store document metadata in database
139
- * await this.database.documents.create({
140
- * id: fileId,
141
- * title: metadata.title,
142
- * category: metadata.category,
143
- * uploadedBy: metadata.userId,
144
- * fileName: file.name,
145
- * fileSize: file.size,
146
- * mimeType: file.type,
147
- * uploadedAt: new Date()
148
- * });
149
- *
150
- * console.log(`Document uploaded successfully: ${metadata.title} (${fileId})`);
151
- * return fileId;
152
- *
153
- * } catch (error) {
154
- * console.error(`Failed to upload document: ${metadata.title}`, error);
155
- * throw error;
156
- * }
157
- * }
158
- *
159
- * async downloadDocument(documentId: string, userId: string): Promise<FileLike> {
160
- * // Check permissions
161
- * const document = await this.database.documents.findById(documentId);
162
- * if (!document) {
163
- * throw new Error('Document not found');
164
- * }
165
- *
166
- * const hasAccess = await this.permissionService.canAccessDocument(userId, documentId);
167
- * if (!hasAccess) {
168
- * throw new Error('Insufficient permissions to access document');
169
- * }
170
- *
171
- * // Download and return file
172
- * return await this.documents.download(documentId);
173
- * }
174
- *
175
- * async deleteDocument(documentId: string, userId: string): Promise<void> {
176
- * // Verify ownership or admin privileges
177
- * const document = await this.database.documents.findById(documentId);
178
- * if (document.uploadedBy !== userId && !await this.userService.isAdmin(userId)) {
179
- * throw new Error('Cannot delete document: insufficient permissions');
180
- * }
181
- *
182
- * // Delete from storage and database
183
- * await this.documents.delete(documentId);
184
- * await this.database.documents.delete(documentId);
185
- *
186
- * console.log(`Document deleted: ${document.title} (${documentId})`);
187
- * }
188
- * }
189
- * ```
190
- */
191
- declare const $bucket: {
192
- (options: BucketDescriptorOptions): BucketDescriptor;
193
- [KIND]: typeof BucketDescriptor;
194
- };
195
- interface BucketDescriptorOptions extends BucketFileOptions {
196
- /**
197
- * File storage provider configuration for the bucket.
198
- *
199
- * Options:
200
- * - **"memory"**: In-memory storage (default for development, lost on restart)
201
- * - **Service<FileStorageProvider>**: Custom provider class (e.g., S3FileStorageProvider, AzureBlobProvider)
202
- * - **undefined**: Uses the default file storage provider from dependency injection
203
- *
204
- * **Provider Selection Guidelines**:
205
- * - **Development**: Use "memory" for fast, simple testing without external dependencies
206
- * - **Production**: Use cloud providers (S3, Azure Blob, Google Cloud Storage) for scalability
207
- * - **Local deployment**: Use filesystem providers for on-premise installations
208
- * - **Hybrid**: Use different providers for different bucket types (temp files vs permanent storage)
209
- *
210
- * **Provider Capabilities**:
211
- * - File persistence and durability guarantees
212
- * - Scalability and performance characteristics
213
- * - Geographic distribution and CDN integration
214
- * - Cost implications for storage and bandwidth
215
- * - Backup and disaster recovery features
216
- *
217
- * @default Uses injected FileStorageProvider
218
- * @example "memory"
219
- * @example S3FileStorageProvider
220
- * @example AzureBlobStorageProvider
221
- */
222
- provider?: Service<FileStorageProvider> | "memory";
223
- /**
224
- * Unique name identifier for the bucket.
225
- *
226
- * This name is used for:
227
- * - Storage backend organization and partitioning
228
- * - File path generation and URL construction
229
- * - Logging, monitoring, and debugging
230
- * - Access control and permissions management
231
- * - Backup and replication configuration
232
- *
233
- * **Naming Conventions**:
234
- * - Use lowercase with hyphens for consistency
235
- * - Include purpose or content type in the name
236
- * - Avoid spaces and special characters
237
- * - Consider environment prefixes for deployment isolation
238
- *
239
- * If not provided, defaults to the property key where the bucket is declared.
240
- *
241
- * @example "user-avatars"
242
- * @example "product-images"
243
- * @example "legal-documents"
244
- * @example "temp-processing-files"
245
- */
246
- name?: string;
247
- }
248
- interface BucketFileOptions {
249
- /**
250
- * Human-readable description of the bucket's purpose and contents.
251
- *
252
- * Used for:
253
- * - Documentation generation and API references
254
- * - Developer onboarding and system understanding
255
- * - Monitoring dashboards and admin interfaces
256
- * - Compliance and audit documentation
257
- *
258
- * **Description Best Practices**:
259
- * - Explain what types of files this bucket stores
260
- * - Mention any special handling or processing requirements
261
- * - Include information about retention policies if applicable
262
- * - Note any compliance or security considerations
263
- *
264
- * @example "User profile pictures and avatar images"
265
- * @example "Product catalog images with automated thumbnail generation"
266
- * @example "Legal documents requiring long-term retention"
267
- * @example "Temporary files for data processing workflows"
268
- */
269
- description?: string;
270
- /**
271
- * Array of allowed MIME types for files uploaded to this bucket.
272
- *
273
- * When specified, only files with these exact MIME types will be accepted.
274
- * Files with disallowed MIME types will be rejected with an InvalidFileError.
275
- *
276
- * **MIME Type Categories**:
277
- * - Images: "image/jpeg", "image/png", "image/gif", "image/webp", "image/svg+xml"
278
- * - Documents: "application/pdf", "text/plain", "text/csv"
279
- * - Office: "application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
280
- * - Archives: "application/zip", "application/x-tar", "application/gzip"
281
- * - Media: "video/mp4", "audio/mpeg", "audio/wav"
282
- *
283
- * **Security Considerations**:
284
- * - Always validate MIME types for user uploads
285
- * - Be cautious with executable file types
286
- * - Consider using allow-lists rather than deny-lists
287
- * - Remember that MIME types can be spoofed by malicious users
288
- *
289
- * If not specified, all MIME types are allowed (not recommended for user uploads).
290
- *
291
- * @example ["image/jpeg", "image/png"] // Only JPEG and PNG images
292
- * @example ["application/pdf", "text/plain"] // Documents only
293
- * @example ["video/mp4", "video/webm"] // Video files
294
- */
295
- mimeTypes?: string[];
296
- /**
297
- * Maximum file size allowed in megabytes (MB).
298
- *
299
- * Files larger than this limit will be rejected with an InvalidFileError.
300
- * This helps prevent:
301
- * - Storage quota exhaustion
302
- * - Memory issues during file processing
303
- * - Long upload times and timeouts
304
- * - Abuse of storage resources
305
- *
306
- * **Size Guidelines by File Type**:
307
- * - Profile images: 1-5 MB
308
- * - Product photos: 5-10 MB
309
- * - Documents: 10-50 MB
310
- * - Video files: 50-500 MB
311
- * - Data files: 100-1000 MB
312
- *
313
- * **Considerations**:
314
- * - Consider your storage costs and limits
315
- * - Factor in network upload speeds for users
316
- * - Account for processing requirements (thumbnails, compression)
317
- * - Set reasonable limits based on actual use cases
318
- *
319
- * @default 10 MB
320
- *
321
- * @example 1 // 1MB for small images
322
- * @example 25 // 25MB for documents
323
- * @example 100 // 100MB for media files
324
- */
325
- maxSize?: number;
326
- }
327
- declare class BucketDescriptor extends Descriptor<BucketDescriptorOptions> {
328
- readonly provider: FileStorageProvider | MemoryFileStorageProvider;
329
- get name(): string;
330
- /**
331
- * Uploads a file to the bucket.
332
- */
333
- upload(file: FileLike, options?: BucketFileOptions): Promise<string>;
334
- /**
335
- * Delete permanently a file from the bucket.
336
- */
337
- delete(fileId: string, skipHook?: boolean): Promise<void>;
338
- /**
339
- * Checks if a file exists in the bucket.
340
- */
341
- exists(fileId: string): Promise<boolean>;
342
- /**
343
- * Downloads a file from the bucket.
344
- */
345
- download(fileId: string): Promise<FileLike>;
346
- protected $provider(): FileStorageProvider | MemoryFileStorageProvider;
347
- }
348
- interface BucketFileOptions {
349
- /**
350
- * Optional description of the bucket.
351
- */
352
- description?: string;
353
- /**
354
- * Allowed MIME types.
355
- */
356
- mimeTypes?: string[];
357
- /**
358
- * Maximum size of the files in the bucket.
359
- *
360
- * @default 10
361
- */
362
- maxSize?: number;
363
- }
364
- //#endregion
365
- //#region src/errors/FileNotFoundError.d.ts
366
- declare class FileNotFoundError extends AlephaError {
367
- readonly status = 404;
368
- }
369
- //#endregion
370
- //#region src/services/FileMetadataService.d.ts
371
- interface FileMetadata {
372
- name: string;
373
- type: string;
374
- }
375
- /**
376
- * Service for encoding/decoding file metadata in storage streams.
377
- *
378
- * The metadata is stored at the beginning of the file with the following structure:
379
- * - 4-byte header: UInt32BE containing the metadata length
380
- * - N-byte metadata: JSON object containing file metadata (name, type)
381
- * - Remaining bytes: Actual file content
382
- *
383
- * @example
384
- * ```typescript
385
- * const service = new FileMetadataService();
386
- *
387
- * // Encode metadata and content for storage
388
- * const { header, metadata } = service.encodeMetadata({
389
- * name: "document.pdf",
390
- * type: "application/pdf"
391
- * });
392
- *
393
- * // Decode metadata from stored file
394
- * const fileHandle = await open(filePath, 'r');
395
- * const { metadata, contentStart } = await service.decodeMetadata(fileHandle);
396
- * ```
397
- */
398
- declare class FileMetadataService {
399
- /**
400
- * Length of the header containing metadata size (4 bytes for UInt32BE)
401
- */
402
- static readonly METADATA_HEADER_LENGTH = 4;
403
- /**
404
- * Encodes file metadata into header and metadata buffers.
405
- *
406
- * @param file - The file or metadata to encode
407
- * @returns Object containing the header buffer and metadata buffer
408
- */
409
- encodeMetadata(file: FileLike | FileMetadata): {
410
- header: Buffer;
411
- metadata: Buffer;
412
- };
413
- /**
414
- * Decodes file metadata from a file handle.
415
- *
416
- * @param fileHandle - File handle opened for reading
417
- * @returns Object containing the decoded metadata and content start position
418
- */
419
- decodeMetadata(fileHandle: {
420
- read: (buffer: Buffer, offset: number, length: number, position: number) => Promise<{
421
- bytesRead: number;
422
- }>;
423
- }): Promise<{
424
- metadata: FileMetadata;
425
- contentStart: number;
426
- }>;
427
- /**
428
- * Decodes file metadata from a buffer.
429
- *
430
- * @param buffer - Buffer containing the file with metadata
431
- * @returns Object containing the decoded metadata and content start position
432
- */
433
- decodeMetadataFromBuffer(buffer: Buffer): {
434
- metadata: FileMetadata;
435
- contentStart: number;
436
- };
437
- /**
438
- * Creates a complete buffer with metadata header, metadata, and content.
439
- *
440
- * @param file - The file to encode
441
- * @param content - The file content as a buffer
442
- * @returns Complete buffer ready for storage
443
- */
444
- createFileBuffer(file: FileLike | FileMetadata, content: Buffer): Buffer;
445
- }
446
- //#endregion
447
- //#region src/providers/LocalFileStorageProvider.d.ts
448
- declare class LocalFileStorageProvider implements FileStorageProvider {
449
- protected readonly alepha: Alepha;
450
- protected readonly log: _alepha_logger0.Logger;
451
- protected readonly metadataService: FileMetadataService;
452
- options: {
453
- storagePath: string;
454
- };
455
- protected readonly configure: _alepha_core1.HookDescriptor<"start">;
456
- upload(bucketName: string, file: FileLike, fileId?: string): Promise<string>;
457
- download(bucketName: string, fileId: string): Promise<FileLike>;
458
- exists(bucketName: string, fileId: string): Promise<boolean>;
459
- delete(bucketName: string, fileId: string): Promise<void>;
460
- protected stat(bucket: string, fileId: string): Promise<fs.Stats>;
461
- protected createId(): string;
462
- protected path(bucket: string, fileId?: string): string;
463
- protected isErrorNoEntry(error: unknown): boolean;
464
- }
465
- declare const fileMetadataSchema: typebox0.TObject<{
466
- name: typebox0.TString;
467
- type: typebox0.TString;
468
- size: typebox0.TNumber;
469
- }>;
470
- //#endregion
471
- //#region src/index.d.ts
472
- declare module "alepha" {
473
- interface Hooks {
474
- /**
475
- * Triggered when a file is uploaded to a bucket.
476
- * Can be used to perform actions after a file is uploaded, like creating a database record!
477
- */
478
- "bucket:file:uploaded": {
479
- id: string;
480
- file: FileLike;
481
- bucket: BucketDescriptor;
482
- options: BucketFileOptions;
483
- };
484
- /**
485
- * Triggered when a file is deleted from a bucket.
486
- */
487
- "bucket:file:deleted": {
488
- id: string;
489
- bucket: BucketDescriptor;
490
- };
491
- }
492
- }
493
- /**
494
- * Provides file storage capabilities through declarative bucket descriptors with support for multiple storage backends.
495
- *
496
- * The bucket module enables unified file operations across different storage systems using the `$bucket` descriptor
497
- * on class properties. It abstracts storage provider differences, offering consistent APIs for local filesystem,
498
- * cloud storage, or in-memory storage for testing environments.
499
- *
500
- * @see {@link $bucket}
501
- * @see {@link FileStorageProvider}
502
- * @module alepha.bucket
503
- */
504
- declare const AlephaBucket: _alepha_core1.Service<_alepha_core1.Module<{}>>;
505
- //#endregion
506
- export { $bucket, AlephaBucket, BucketDescriptor, BucketDescriptorOptions, BucketFileOptions, FileMetadata, FileMetadataService, FileNotFoundError, FileStorageProvider, LocalFileStorageProvider, MemoryFileStorageProvider, fileMetadataSchema };
507
- //# sourceMappingURL=index.d.ts.map
1
+ export * from '@alepha/bucket';
package/cache/redis.d.ts CHANGED
@@ -1,40 +1 @@
1
- import { CacheProvider } from "alepha/cache";
2
- import * as _alepha_core1 from "alepha";
3
- import { Alepha, Static } from "alepha";
4
- import * as _alepha_logger0 from "alepha/logger";
5
- import { RedisProvider } from "alepha/redis";
6
-
7
- //#region src/providers/RedisCacheProvider.d.ts
8
- declare const envSchema: _alepha_core1.TObject<{
9
- REDIS_CACHE_PREFIX: _alepha_core1.TOptional<_alepha_core1.TString>;
10
- }>;
11
- declare module "alepha" {
12
- interface Env extends Partial<Static<typeof envSchema>> {}
13
- }
14
- declare class RedisCacheProvider implements CacheProvider {
15
- protected readonly log: _alepha_logger0.Logger;
16
- protected readonly redisProvider: RedisProvider;
17
- protected readonly env: {
18
- REDIS_CACHE_PREFIX?: string | undefined;
19
- };
20
- protected readonly alepha: Alepha;
21
- get(name: string, key: string): Promise<Uint8Array | undefined>;
22
- set(name: string, key: string, value: Uint8Array | string, ttl?: number): Promise<Uint8Array>;
23
- del(name: string, ...keys: string[]): Promise<void>;
24
- has(name: string, key: string): Promise<boolean>;
25
- keys(name: string, filter?: string): Promise<string[]>;
26
- clear(): Promise<void>;
27
- protected prefix(...path: string[]): string;
28
- }
29
- //#endregion
30
- //#region src/index.d.ts
31
- /**
32
- * Plugin for Alepha Cache that provides Redis caching capabilities.
33
- *
34
- * @see {@link RedisCacheProvider}
35
- * @module alepha.cache.redis
36
- */
37
- declare const AlephaCacheRedis: _alepha_core1.Service<_alepha_core1.Module<{}>>;
38
- //#endregion
39
- export { AlephaCacheRedis, RedisCacheProvider };
40
- //# sourceMappingURL=index.d.ts.map
1
+ export * from '@alepha/cache-redis';