UNPKG

@adonis-agora/media

Version:

Media-library for AdonisJS — owner collections (MIME whitelist, single-file replace, ordering), image conversions (eager/lazy), pluggable content transformers (HLS video via mediabunny, metadata probe, image blur-up placeholder), and column attachments, a

101 lines • 3.8 kB
/** * Every media milestone published on `agora:media:<event>`. The single runtime source for the * {@link MediaDiagnosticEvent} union — a Telescope watcher iterates this to subscribe/claim. */ export declare const MEDIA_DIAGNOSTIC_EVENTS: readonly ['attach', 'delete', 'conversion', 'attachment.create', 'attachment.delete', 'upload.start', 'upload.progress', 'upload.complete', 'upload.abort']; export type MediaDiagnosticEvent = (typeof MEDIA_DIAGNOSTIC_EVENTS)[number]; /** * Claim `media:<event>` for every event, so the generic diagnostics→telescope bridge skips them. * Reference-counted (mirrors `@adonis-agora/diagnostics`' `claimDiagnostics`): claiming an already * claimed key increments its count; the returned release decrements, deleting the key only at zero. * Idempotent release. */ export declare function claimMediaDiagnostics(events: readonly string[]): () => void; /** Whether `media:<event>` is currently claimed — the structural mirror of the diagnostics package's `isDiagnosticClaimed('media', event)`. */ export declare function isMediaDiagnosticClaimed(event: string): boolean; export interface AttachPayload { id: string; ownerType: string; ownerId: string; collection: string; disk: string; path: string; size: number; mimeType: string; } export interface DeletePayload { id: string; ownerType: string; ownerId: string; } export interface ConversionPayload { id: string; conversion: string; path: string; } export interface AttachmentCreatePayload { disk: string; path: string; size: number; mimeType: string; name: string; variants: string[]; } export interface AttachmentDeletePayload { disk: string; path: string; variants: string[]; } export interface UploadStartPayload { id: string; disk: string; key: string; mode: 'proxy' | 'direct'; size?: number | undefined; contentType?: string | undefined; } export interface UploadProgressPayload { id: string; /** Bytes received so far (the resume offset). */ offset: number; /** Number of chunk parts written so far. */ parts: number; /** Total expected size in bytes, when known up front. */ size?: number | undefined; } export interface UploadCompletePayload { id: string; disk: string; key: string; } export interface UploadAbortPayload { id: string; disk: string; key: string; } /** Maps each event to its payload type, so {@link publishMedia} is checked at the call site. */ export interface MediaDiagnosticPayloads { attach: AttachPayload; delete: DeletePayload; conversion: ConversionPayload; 'attachment.create': AttachmentCreatePayload; 'attachment.delete': AttachmentDeletePayload; 'upload.start': UploadStartPayload; 'upload.progress': UploadProgressPayload; 'upload.complete': UploadCompletePayload; 'upload.abort': UploadAbortPayload; } /** * Publish a media event on `agora:media:<event>` via the structural diagnostics slot. * No-op when diagnostics isn't installed (the slot is empty) — and it never throws back * into the library. */ export declare function publishMedia<E extends MediaDiagnosticEvent>(event: E, payload: MediaDiagnosticPayloads[E]): void; /** * Wrap a unit of media work in a structural trace span (`upload.policy.*` and friends). When a * diagnostics trace slot is installed it observes the call (lib hard-coded to `'media'`); otherwise * the wrapped function runs directly. Unlike {@link publishMedia}, errors are NOT swallowed — a * traced policy hook must surface its failure to the caller so the handler can map it. */ export declare function traceMedia<T>(event: string, fn: () => T, payload?: unknown): T; //# sourceMappingURL=diagnostics.d.ts.map