import type { ReactiveController, ReactiveControllerHost } from 'lit'; import type { Attachment } from '../types/index.js'; import type { UploadProvider, UploadResult } from '../providers/upload-provider.js'; export type UploadState = 'idle' | 'uploading' | 'complete' | 'error'; export interface UploadControllerOptions { /** Maximum number of concurrent uploads. Default: 3 */ concurrency?: number; /** Maximum retry attempts per file. Default: 2 */ maxRetries?: number; /** Delay between retries in ms. Default: 1000 */ retryDelay?: number; /** Per-file upload timeout in ms. Default: 300_000 (5 min) */ uploadTimeout?: number; /** Called when an attachment's status or progress changes */ onAttachmentUpdate?: (attachment: Attachment) => void; /** Called when a single file upload completes */ onUploadComplete?: (attachment: Attachment, result: UploadResult) => void; /** Called when a single file upload fails (all retries exhausted) */ onUploadError?: (attachment: Attachment, error: Error) => void; /** * Called when the entire queue is drained with zero errors. * Only fires when ALL queued files complete successfully. * If any file errored, this callback is NOT fired. */ onAllComplete?: (results: ReadonlyMap) => void; /** Called when the controller state changes */ onStateChange?: (state: UploadState) => void; } /** * UploadController — orchestrates file uploads via an UploadProvider. * * Manages queue, concurrency, retry, abort, progress tracking, and URL validation. * Follows the same ReactiveController pattern as StreamingController. * * @example * ```ts * import { UploadController } from '@loquix/core/controllers/upload.controller'; * import { MyUploadProvider } from './my-upload-provider'; * * class MyHost extends LitElement { * private _upload = new UploadController(this, new MyUploadProvider(), { * concurrency: 3, * onUploadComplete: (attachment, result) => { ... }, * }); * } * ``` */ export declare class UploadController implements ReactiveController { private _host; private _provider; private _options; private _state; private _queue; private _active; private _results; /** Retry timers keyed by attachment ID for per-attachment cancellation */ private _retryTimers; private _erroredIds; /** Tracks the latest known state of every attachment that passed through the controller */ private _trackedAttachments; constructor(host: ReactiveControllerHost, provider: UploadProvider, options?: UploadControllerOptions); hostConnected(): void; hostDisconnected(): void; /** Current controller state */ get state(): UploadState; /** Completed upload results keyed by attachment ID */ get results(): ReadonlyMap; /** Number of currently in-flight uploads */ get activeCount(): number; /** Number of items waiting in the queue */ get queuedCount(): number; /** * Queue attachments for upload. * * Each attachment is validated synchronously via `provider.validate()`. * Invalid files get `status: 'error'` immediately and are not queued. * Valid files are queued and processing begins immediately. */ add(attachments: Attachment[]): void; /** * Retry a failed attachment by re-queuing it. * Resets its retry count and status. * * Only errored attachments can be retried. Retrying an active, queued, * or already-completed attachment is a no-op to prevent duplicate uploads. * * @throws Error if attachmentId is unknown (never passed through the controller) */ retry(attachmentId: string): void; /** * Cancel a specific in-flight or queued upload. * Also clears any pending retry timer for this attachment. */ cancel(attachmentId: string): void; /** * Abort all in-flight and queued uploads. * Clears retry timers. Does NOT clear results. */ abortAll(): void; /** * Abort all uploads, clear results, and reset to idle. */ reset(): void; /** * Swap the upload provider. Aborts in-flight uploads if any. */ setProvider(provider: UploadProvider): void; /** Start uploading queued items up to concurrency limit */ private _drain; /** Execute a single upload */ private _startUpload; /** * Validate a URL returned by the provider. * Throws if the URL is malformed or not HTTPS. */ private _validateUrl; /** Derive controller state from current queue/active state */ private _updateState; private _setState; /** Find an attachment by ID across queue, active, and tracked history */ private _findAttachmentById; } //# sourceMappingURL=upload.controller.d.ts.map