@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
68 lines • 3.3 kB
TypeScript
import { Readable } from 'node:stream';
import type { Disk, DiskMetaData, DiskResolver, DiskWriteOptions, SignedUrlOptions } from '../types.js';
/** Visibility an {@link InMemoryDisk} reports — or `'unknown'` for a disk with no such signal. */
export type DiskVisibility = 'public' | 'private' | 'unknown';
interface StoredFile {
data: Buffer;
contentType?: string | undefined;
lastModified: Date;
/**
* The `contentLength` the writer declared, recorded verbatim (`undefined` when it declared
* none, and always `undefined` for `put`, which needs no declaration).
*
* It is kept only so tests can assert it. A real S3 disk CANNOT write a stream without it,
* but this disk has the bytes in hand and never needs it — so silently ignoring it let
* callers drop the size and still pass every test here, while failing against real S3.
*/
contentLength?: number | undefined;
}
/**
* In-memory {@link Disk} satisfying the same structural contract as an `@adonisjs/drive` disk.
* Use it (via {@link inMemoryDiskResolver}) to drive the media-library and attachment layers in
* tests without a real filesystem or S3.
*/
export declare class InMemoryDisk implements Disk {
/** Used to render `getUrl`/`getSignedUrl`. */
private readonly baseUrl;
readonly files: Map<string, StoredFile>;
/** Options from the most recent `getSignedUrl` call, so tests can assert the contract. */
lastSignedUrlOptions: SignedUrlOptions | undefined;
/**
* Reports the object visibility `delivery.mode: 'auto'` branches on. Defined as an own property
* rather than a prototype method so `'unknown'` genuinely REMOVES it — that is the "disk that
* cannot answer" case, which `resolveDeliveryMode` detects by probing for the method.
*/
readonly getVisibility?: (key: string) => Promise<'public' | 'private'>;
constructor(
/** Used to render `getUrl`/`getSignedUrl`. */
baseUrl?: string,
/** What `getVisibility` reports; `'unknown'` omits the method entirely. */
visibility?: DiskVisibility);
put(key: string, contents: Uint8Array, options?: DiskWriteOptions): Promise<void>;
putStream(key: string, contents: Readable, options?: DiskWriteOptions): Promise<void>;
getBytes(key: string): Promise<Uint8Array>;
getStream(key: string): Promise<Readable>;
exists(key: string): Promise<boolean>;
delete(key: string): Promise<void>;
getUrl(key: string): Promise<string>;
getSignedUrl(key: string, options?: SignedUrlOptions): Promise<string>;
getMetaData(key: string): Promise<DiskMetaData>;
private require;
}
/**
* Build a {@link DiskResolver} over named in-memory disks. The first name is the default; a single
* unnamed disk is named `default`. Returns the resolver plus the disk map for assertions.
*
* ```ts
* const { resolve, disks } = inMemoryDiskResolver(['fs'])
* const storage = new StorageManager({ default: 'fs', resolve })
* ```
*/
export declare function inMemoryDiskResolver(names?: string[],
/** Visibility every disk reports; `'unknown'` builds disks with no `getVisibility` at all. */
visibility?: DiskVisibility): {
resolve: DiskResolver;
disks: Record<string, InMemoryDisk>;
};
export {};
//# sourceMappingURL=in_memory_disk.d.ts.map