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

88 lines • 4.01 kB
/** * The media schema for the Lucid store, as standalone functions. * * By default {@link LucidMediaStore} auto-creates the `media` table on first use * (`autoCreateSchema`, the ecosystem convention — a lib owns its own schema, same * as `@adonis-agora/authz`'s `createAuthzTables` and `@adonis-agora/durable`'s * `createDurableTables`). An app that prefers explicit control sets * `autoCreateSchema: false` and calls {@link createMediaTables} from a Lucid * migration instead. Both paths run the SAME DDL — the store's `ensureSchema` * delegates here — so they never drift. */ /** The bindings a Lucid `rawQuery` accepts (mirrors `RawQueryBindings`). */ export type LucidQueryBindings = readonly unknown[] | Record<string, unknown>; /** The slice of a Lucid query client the schema functions rely on. */ export interface LucidQueryClient { rawQuery(sql: string, bindings?: LucidQueryBindings): Promise<unknown>; } /** A Lucid `Database` / connection / query client. */ export interface LucidDatabase extends LucidQueryClient { dialect?: { name?: string; }; connection?(name?: string): { dialect?: { name?: string; }; }; } /** Table-name override (default matches the `media` table). */ export interface MediaTableNames { media?: string; } /** The default table names for the Lucid store's media schema. */ export declare const MEDIA_TABLES: Required<MediaTableNames>; /** Reject any table name that is not a bare SQL identifier (these are interpolated, never bound). */ export declare function assertSafeIdentifier(id: string): string; export declare function isPostgres(dialect: string | undefined): boolean; export declare function isMysql(dialect: string | undefined): boolean; /** * Best-effort dialect name from a Lucid client; `undefined` when it can't be read. */ export declare function detectDialect(db: LucidDatabase): string | undefined; /** * Create the `media` table (idempotent — `CREATE TABLE IF NOT EXISTS`). Safe to call * from a Lucid migration `up()` or repeatedly at boot. * * The shape mirrors the migration published by `node ace configure @adonis-agora/media`: * JSON payloads (`custom_properties`, `conversions`) are stored as TEXT — the store * (de)serializes them — and timestamps as epoch-ms integers, so the schema is portable * across SQLite / Postgres / MySQL. * * @param db a Lucid `Database` or connection client * @param options.table optional table-name override (defaults to {@link MEDIA_TABLES}) */ export declare function createMediaTables(db: LucidDatabase, options?: { table?: string; }): Promise<void>; /** * Drop the `media` table (idempotent — `DROP TABLE IF EXISTS`). For a migration `down()`. * * @param db a Lucid `Database` or connection client * @param options.table optional table-name override (defaults to {@link MEDIA_TABLES}) */ export declare function dropMediaTables(db: LucidDatabase, options?: { table?: string; }): Promise<void>; /** * Whether the `media` table has the `tenant_id` column tenancy needs (a zero-row probe query). * * @param db a Lucid `Database` or connection client * @param options.table optional table-name override (defaults to {@link MEDIA_TABLES}) */ export declare function hasMediaTenantColumn(db: LucidQueryClient, options?: { table?: string; }): Promise<boolean>; /** * Add the nullable `tenant_id` column and its `(tenant_id, owner_type, owner_id, collection)` index * to the `media` table when missing (idempotent). Tenancy (organizations as tenants) stamps new * files with it; existing rows stay `NULL`. Same DDL as the migration * `node ace media:publish-migration tenancy` publishes. * * @param db a Lucid `Database` or connection client * @param options.table optional table-name override (defaults to {@link MEDIA_TABLES}) */ export declare function ensureMediaTenantColumn(db: LucidDatabase, options?: { table?: string; }): Promise<void>; //# sourceMappingURL=lucid-schema.d.ts.map