@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
276 lines • 13.3 kB
TypeScript
export declare class MimeNotAllowedError extends Error {
readonly collection: string;
readonly mimeType: string;
readonly accepted: readonly string[];
readonly code = "E_MEDIA_MIME_NOT_ALLOWED";
constructor(collection: string, mimeType: string, accepted: readonly string[]);
}
/**
* The bytes are not what the caller said they were. Raised when a collection declares
* `acceptsMimeTypes` and the file's magic-byte signature identifies a type that either the
* collection does not accept or that contradicts the declared `mimeType` — the case
* {@link MimeNotAllowedError} cannot catch, because the declared type is written by the app (often
* hardcoded) rather than proven by the content.
*/
export declare class ContentTypeMismatchError extends Error {
readonly collection: string;
readonly declaredMimeType: string;
readonly detectedMimeType: string;
readonly code = "E_MEDIA_CONTENT_TYPE_MISMATCH";
constructor(collection: string, declaredMimeType: string, detectedMimeType: string, accepted: readonly string[]);
}
/**
* The content carries no recognisable signature, under a collection whose `acceptsMimeTypes` are
* ALL signature-detectable. Distinct from {@link ContentTypeMismatchError}, which reports bytes that
* were positively identified as some other type: here nothing was identified at all, and that is
* itself the proof — if every accepted type is one the signature table can recognise, content it
* cannot recognise is none of them.
*
* A collection that accepts even one signature-less type (`image/svg+xml`, `text/csv`,
* `text/plain`, office formats…) is NOT closed, and unrecognised content there stays accepted.
*/
export declare class ContentSignatureUnrecognizedError extends Error {
readonly collection: string;
readonly declaredMimeType: string | undefined;
readonly accepted: readonly string[];
readonly code = "E_MEDIA_CONTENT_SIGNATURE_UNRECOGNIZED";
constructor(collection: string, declaredMimeType: string | undefined, accepted: readonly string[]);
}
/**
* A media disk was resolved before `@adonisjs/drive` finished booting, so its disk manager does not
* exist yet. Drive's service module assigns the manager inside `app.booted(...)`; reading it any
* earlier yields `undefined`. The media provider resolves it lazily, at first real disk use, so in
* practice this only fires when media is called from outside a booted application.
*/
export declare class DriveNotReadyError extends Error {
readonly code = "E_MEDIA_DRIVE_NOT_READY";
constructor(disk: string);
}
export declare class MediaNotFoundError extends Error {
readonly code = "E_MEDIA_RECORD_NOT_FOUND";
constructor(id: string);
}
export declare class MediaObjectMissingError extends Error {
readonly code = "E_MEDIA_OBJECT_MISSING";
constructor(disk: string, key: string);
}
export declare class ConversionNotDefinedError extends Error {
readonly code = "E_MEDIA_CONVERSION_NOT_DEFINED";
constructor(collection: string, conversion: string);
}
/**
* A conversion was requested by a name that names neither an image preset nor a transformer of the
* record's collection — the transformer counterpart of {@link ConversionNotDefinedError}, raised by
* `MediaLibrary.transform`.
*/
export declare class TransformerNotDefinedError extends Error {
readonly code = "E_MEDIA_TRANSFORMER_NOT_DEFINED";
constructor(collection: string, transformer: string);
}
/**
* A transformer-produced conversion was read (`url` / `deliver` / HLS delivery) before it was
* generated. Deliberately NOT generated lazily on read like image conversions: a transform is
* assumed heavy (a video remux takes minutes), and a read path is the wrong place to pay that.
* Generate it explicitly — `media.library.transform(id, name)` from a job — then read again.
*/
export declare class TransformNotReadyError extends Error {
readonly mediaId: string;
readonly transformer: string;
readonly code = "E_MEDIA_TRANSFORM_NOT_READY";
constructor(mediaId: string, transformer: string);
}
/**
* Two derivatives of one collection claim the same name. Presets and transformers persist into the
* same `record.conversions` map, so the namespace is shared; raised at registry construction (boot),
* not on first attach.
*/
export declare class TransformerConflictError extends Error {
readonly code = "E_MEDIA_TRANSFORMER_CONFLICT";
constructor(collection: string, name: string);
}
/**
* A transformer needs a runtime capability the host doesn't provide — an optional peer that isn't
* installed (`mediabunny`), or an API the runtime lacks (WebCodecs in Node). Thrown by the built-in
* transformers and available for custom ones, so "this environment can't do that" always surfaces
* as one clear, typed error instead of a deep import/undefined crash.
*/
export declare class TransformerRuntimeMissingError extends Error {
readonly transformer: string;
readonly requirement: string;
readonly code = "E_MEDIA_TRANSFORMER_RUNTIME_MISSING";
constructor(transformer: string, requirement: string, hint?: string);
}
/**
* A transformer violated the output contract: wrote outside its prefix (`..`/absolute path),
* declared an `entry` it never wrote, or wrote artifacts without declaring an entry. These are
* programming errors in the transformer, surfaced with the transformer's name so the broken one is
* obvious.
*/
export declare class TransformerOutputError extends Error {
readonly code = "E_MEDIA_TRANSFORMER_OUTPUT_INVALID";
constructor(transformer: string, reason: string);
}
/**
* A metadata-only conversion (a probe, a blurhash) was asked for its file — `url`, `signedUrl` or
* `deliver` — but it has no artifact; only `record.conversions[name].meta` exists. Read the record
* instead of a URL.
*/
export declare class ConversionArtifactMissingError extends Error {
readonly code = "E_MEDIA_CONVERSION_ARTIFACT_MISSING";
constructor(mediaId: string, conversion: string);
}
/**
* The HLS transformer could not stream-copy the source: a track's codec cannot be carried by the
* segment format (MPEG-TS wants h264/aac), and no re-encode path exists in this runtime. Definitive
* for the file — retrying cannot fix it; re-encode the source, or provide a WebCodecs
* implementation (see `transformers.video({ webcodecs })`).
*/
export declare class HlsSourceUnsupportedError extends Error {
readonly code = "E_MEDIA_HLS_SOURCE_UNSUPPORTED";
/**
* @param hint what the caller can do about it; defaults to the mediabunny/WebCodecs advice.
*/
constructor(details: string, hint?: string);
}
/**
* An `ffmpeg` / `ffprobe` run (the `engines.ffmpeg()` / `engines.ffprobe()` engines) exited
* non-zero or produced something unusable. Carries the exit code and the tail of stderr, which is
* where ffmpeg explains itself (an unsupported codec for a stream copy, a corrupt input).
*/
export declare class FfmpegFailedError extends Error {
readonly binary: string;
readonly exitCode: number | null;
readonly stderr: string;
readonly code = "E_MEDIA_FFMPEG_FAILED";
constructor(binary: string, exitCode: number | null, stderr: string);
}
export declare class ImageProcessorMissingError extends Error {
readonly code = "E_MEDIA_IMAGE_PROCESSOR_MISSING";
constructor();
}
export declare class VariantNotFoundError extends Error {
readonly code = "E_MEDIA_VARIANT_NOT_FOUND";
constructor(variant: string);
}
export declare class UploadNotSupportedError extends Error {
readonly code = "E_MEDIA_UPLOAD_NOT_SUPPORTED";
constructor(disk: string, operation?: string);
}
export declare class UploadSessionNotFoundError extends Error {
readonly code = "E_MEDIA_UPLOAD_SESSION_NOT_FOUND";
constructor(id: string);
}
export declare class UploadOffsetConflictError extends Error {
readonly expected: number;
readonly received: number;
readonly code = "E_MEDIA_UPLOAD_OFFSET_CONFLICT";
constructor(expected: number, received: number);
}
export declare class UploadSessionExpiredError extends Error {
readonly code = "E_MEDIA_UPLOAD_SESSION_EXPIRED";
constructor(id: string);
}
/**
* A part size the S3 multipart API cannot honour: below the 5 MiB minimum (every part but the last
* must reach it, or `CompleteMultipartUpload` fails with `EntityTooSmall` AFTER the client uploaded
* everything), or small enough that the file would need more than the 10,000 parts S3 allows.
* Raised at `initiate`, where it costs nothing — the alternative is discovering it at complete,
* when the whole file has already crossed the wire.
*/
export declare class UploadPartSizeError extends Error {
readonly code = "E_MEDIA_UPLOAD_PART_SIZE";
constructor(detail: string);
}
/** A confirmed part number outside `1..totalParts` for the session — a client slicing with the wrong part size. */
export declare class UploadPartOutOfRangeError extends Error {
readonly partNumber: number;
readonly totalParts: number;
readonly code = "E_MEDIA_UPLOAD_PART_OUT_OF_RANGE";
constructor(partNumber: number, totalParts: number);
}
/**
* `complete()` was asked to assemble an upload whose parts are not all accounted for (neither
* confirmed to the session nor supplied in the call). Failing fast here names the EXACT missing
* part numbers; letting S3 discover it returns an opaque `InvalidPart` after a round-trip.
*/
export declare class UploadPartsIncompleteError extends Error {
readonly sessionId: string;
readonly missingParts: readonly number[];
readonly code = "E_MEDIA_UPLOAD_PARTS_INCOMPLETE";
constructor(sessionId: string, missingParts: readonly number[]);
}
/**
* A client-supplied upload file name is unsafe to interpolate into a storage key: it contains a
* path separator (so, after normalizing `\` to `/`, more than one segment), resolves to `.`/`..`,
* is empty, or carries a control character. Raised by {@link sanitizeFileName} before the name ever
* reaches a storage key — `MediaLibrary`'s `attach`/`attachExisting`, the default `keyFor` of
* `DirectUploadHandler` and `TusUploadHandler`, and `AttachmentManager#createFromFile` — so a
* traversal attempt (`../../etc/passwd`) or an absolute path never gets the chance to escape the
* upload's directory. Mirrors
* {@link TransformerOutputError}'s stance on hostile-shaped paths: reject outright, never silently
* normalize into place.
*/
export declare class UnsafeFileNameError extends Error {
readonly fileName: string;
readonly code = "E_MEDIA_UNSAFE_FILE_NAME";
constructor(fileName: string);
}
export declare class DirectUploadsNotConfiguredError extends Error {
readonly code = "E_MEDIA_DIRECT_NOT_CONFIGURED";
constructor();
}
export declare class ResumableUploadsNotConfiguredError extends Error {
readonly code = "E_MEDIA_RESUMABLE_NOT_CONFIGURED";
constructor();
}
export declare class StoreNotConfiguredError extends Error {
readonly code = "E_MEDIA_STORE_NOT_CONFIGURED";
constructor(name: string);
}
export declare class UploadSessionStoreNotConfiguredError extends Error {
readonly code = "E_MEDIA_UPLOAD_SESSION_STORE_NOT_CONFIGURED";
constructor(name: string);
}
/**
* A resize was requested at a width or quality outside `delivery.images` — the whitelist that stops
* a client from filling the storage with one cached variant per arbitrary size. Map it to a 400.
*/
export declare class ImageSizeNotAllowedError extends Error {
readonly field: 'width' | 'quality';
readonly value: unknown;
readonly allowed: readonly number[];
readonly code = "E_MEDIA_IMAGE_SIZE_NOT_ALLOWED";
constructor(field: 'width' | 'quality', value: unknown, allowed: readonly number[]);
}
/** A resize (`?w=`) was requested for a record that is not a raster image. Map it to a 400. */
export declare class NotAnImageError extends Error {
readonly mediaId: string;
readonly mimeType: string;
readonly code = "E_MEDIA_NOT_AN_IMAGE";
constructor(mediaId: string, mimeType: string);
}
/**
* A delivery request failed signature checking (`delivery.signing`): it carries no signature while
* one is required (`missing`), the signature does not match the request (`invalid` — any
* parameter changed, or a URL signed with another key), or it expired (`expired`). Map it to a 403.
*/
export declare class DeliverySignatureError extends Error {
readonly reason: 'missing' | 'invalid' | 'expired';
readonly code = "E_MEDIA_DELIVERY_SIGNATURE";
constructor(reason: 'missing' | 'invalid' | 'expired');
}
/**
* A media read or write was refused by its authorization rule (`media.access`, the delivery route,
* a collection's `access`). `status` is the HTTP answer: `401` when the request is anonymous,
* `403` when the signed-in user is not allowed.
*/
export declare class MediaAccessDeniedError extends Error {
readonly action: 'read' | 'write';
readonly collection: string;
readonly mediaId: string | undefined;
readonly anonymous: boolean;
readonly code = "E_MEDIA_ACCESS_DENIED";
readonly status: 401 | 403;
constructor(action: 'read' | 'write', collection: string, mediaId: string | undefined, anonymous: boolean);
}
//# sourceMappingURL=errors.d.ts.map