/** * Backend Files Domain Service * * Extends BaseBackendDomainService for CRUD operations on the `media` table. * Similar to ExampleDomainService - uses base class methods with domain-specific config. * * Note: File upload/download is handled by @plyaz/storage service. * This service manages file metadata in the database. */ import { BaseBackendDomainService } from '../base'; import type { CoreServiceCreateOptions, CoreInjectedServices, CoreDeleteOptions } from '@plyaz/types/core'; import { FilesRepository } from '../../models/files'; import { FilesMapperClass } from './mappers/FilesMapper'; import { FilesValidatorClass } from './validators/FilesValidator'; import type { FilesEntity, FilesDatabaseRow, FilesDomainServiceConfig, FilesCreateInput } from '@plyaz/types/core'; import type { FilesStoreItem } from '@plyaz/types/store'; import type { GetFileResponse } from '@plyaz/types/api'; import type { FileMetadata, StorageResolvedVariant } from '@plyaz/types/storage'; type FilesMapperType = InstanceType; type FilesValidatorType = InstanceType; /** * Backend Files Domain Service * * CRUD methods inherited from BaseBackendDomainService: * - getById(id): Promise * - getAll(query?): Promise * - patch(id, data): Promise * - delete(id): Promise * - exists(id): Promise */ export declare class BackendFilesDomainService extends BaseBackendDomainService, Record, CoreDeleteOptions, FilesDatabaseRow, FilesRepository, FilesStoreItem, FilesMapperType, FilesValidatorType> { private _repository?; protected eventPrefix: string; protected cachePrefix: string; static readonly serviceKey: "files"; /** * Lazy repository getter - creates repository on first access. * Throws if DbService is not initialized. */ protected get repository(): FilesRepository; /** * Create service instance */ static create(config?: FilesDomainServiceConfig, options?: CoreServiceCreateOptions): Promise; constructor(config?: FilesDomainServiceConfig, injected?: CoreInjectedServices); isAvailable(): boolean; dispose(): void; /** * Download file content * GET /files/:id/download * * Follows same pattern as base class CRUD methods: * 1. assertReady * 2. Record start time * 3. Log debug info * 4. Emit starting event * 5. Execute operation * 6. Emit success event * 7. Record metrics * * @param params - Download parameters (fileId required) * @returns Download result with buffer, filename, mimeType */ downloadFile(params: { fileId: string; }): Promise<{ buffer: string; filename: string; mimeType: string; }>; /** * Lifecycle hook: called before file download. * Override in subclass for custom pre-download logic. */ protected beforeDownloadFile?(params: { fileId: string; }): Promise; /** * Lifecycle hook: called after file download. * Override in subclass for custom post-download logic. */ protected afterDownloadFile?(result: { buffer: string; filename: string; mimeType: string; }): Promise; /** * Get signed URL for file * GET /files/:id/signed-url * * Follows same pattern as base class CRUD methods. * * @param params - Signed URL parameters (fileId required) * @returns Signed URL result with url and expiresAt */ getSignedUrl(params: { fileId: string; expiresIn?: number; }): Promise<{ url: string; expiresAt: string; }>; /** * Lifecycle hook: called before getting signed URL. * Override in subclass for custom pre-signedUrl logic. */ protected beforeGetSignedUrl?(params: { fileId: string; expiresIn?: number; }): Promise; /** * Lifecycle hook: called after getting signed URL. * Override in subclass for custom post-signedUrl logic. */ protected afterGetSignedUrl?(result: { url: string; expiresAt: string; }): Promise; /** * Persist uploaded file metadata to the media table. * Called by StorageService.onFileUploaded event handler. * * Uses upsert logic: updates existing record if storage_path exists, * otherwise creates new record. * * @param metadata - File metadata from storage upload * @param variants - Optional file variants (thumbnails, etc.) * @param userId - Optional user ID who uploaded the file * @returns The created/updated DB record with UUID */ persistUploadedFile(metadata: FileMetadata, variants?: Record, userId?: string): Promise; /** * Get file record by storage path * Used to retrieve the DB record after upload (since event handler persists it) */ getByStoragePath(storagePath: string): Promise; } export declare function getBackendFilesDomainService(config?: FilesDomainServiceConfig, options?: CoreServiceCreateOptions): Promise; export declare function resetFilesDomainService(): void; export {}; //# sourceMappingURL=BackendFilesDomainService.d.ts.map