@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
91 lines • 4.78 kB
TypeScript
import type { Database } from '@adonisjs/lucid/database';
import type { MediaRecord } from '../media_record.js';
import { type MediaCollectionTotals, type MediaListOptions, type MediaListPage, type MediaOwnerPageOptions, type MediaStore, type MediaTotalsOptions } from '../media_store.js';
import { type MediaSchemaInspection } from './lucid-schema.js';
export interface LucidMediaStoreOptions {
/** The Lucid connection name. Defaults to the `Database` default connection. */
connectionName?: string;
/** Table name. Default `media`. */
table?: string;
/**
* Database schema the table lives in (a Postgres schema, a MySQL database). Every query names
* it; with `autoCreateSchema` it is created when missing. Not supported on SQLite (the
* constructor throws). Default: the connection's current schema.
*/
schema?: string;
/**
* Auto-create the `media` table on first use (default `true`). Set to `false` to
* manage the schema explicitly via a migration calling {@link createMediaTables}.
*/
autoCreateSchema?: boolean;
/**
* Read and write the `tenant_id` column (media's `tenancy` is on). Off by default: the column is
* then never touched, so a table without it keeps working. With `autoCreateSchema` the column is
* added when missing; without it, a missing column fails the first query with
* {@link MediaTenancySchemaError} (run `node ace media:publish-migration tenancy`).
*/
tenantColumn?: boolean;
}
/** Thrown when tenancy is on and the `media` table has no `tenant_id` column. */
export declare class MediaTenancySchemaError extends Error {
readonly code = "E_MEDIA_TENANCY_SCHEMA";
constructor(table: string);
}
/**
* Lucid-backed {@link MediaStore}. Persists media records in a `media` table via `@adonisjs/lucid`'s
* query builder (Knex), so it works across SQLite / Postgres / MySQL. JSON payloads
* (`custom_properties`, `conversions`) are stored as TEXT and timestamps as epoch-ms integers, so the
* schema is portable across engines.
*
* The `media` table is auto-created on first use (`autoCreateSchema`, default `true`) — the
* ecosystem convention, same as `@adonis-agora/authz` and `@adonis-agora/durable`. An app that
* prefers explicit control sets `autoCreateSchema: false` and publishes the migration via
* `node ace configure @adonis-agora/media` (or calls {@link createMediaTables} from a migration).
*/
export declare class LucidMediaStore implements MediaStore {
private readonly db;
readonly tenantFiltering = true;
private readonly table;
/** The configured database schema, or `undefined` for the connection's current one. */
readonly schema: string | undefined;
/** {@link table} as the query builder takes it (`schema.table` when a schema is set). */
private readonly qualified;
private readonly connectionName;
private readonly autoCreate;
private readonly tenantColumn;
private schemaReady;
constructor(db: Database, options?: LucidMediaStoreOptions);
/** The connection's dialect name, when it can be read without a query. */
private dialect;
/** The options every schema helper takes: the table and, when set, the schema. */
private schemaOptions;
private client;
private query;
/** Ensure the schema exists before the first operation, once per store instance. */
private ready;
private assertTenantColumn;
/** Whether the table has the `tenant_id` column tenancy needs. */
hasTenantColumn(): Promise<boolean>;
/**
* Where the configured {@link schema} stands, for `agora:doctor`: whether it exists, whether the
* table is in it, and whether this connection may write to it. `null` without a schema.
*/
inspectSchema(): Promise<MediaSchemaInspection | null>;
/**
* Create the `media` table (idempotent). Delegates to the standalone {@link createMediaTables}
* so the auto-create path and a migration-based one run identical DDL.
*/
ensureSchema(): Promise<void>;
save(record: MediaRecord): Promise<MediaRecord>;
find(id: string): Promise<MediaRecord | null>;
listByOwner(ownerType: string, ownerId: string, collection?: string): Promise<MediaRecord[]>;
listByOwnerPaged(ownerType: string, ownerId: string, options?: MediaOwnerPageOptions): Promise<MediaListPage>;
list(options?: MediaListOptions & {
collectionIn?: readonly string[];
}): Promise<MediaListPage>;
delete(id: string): Promise<void>;
collectionTotals(options?: MediaTotalsOptions): Promise<MediaCollectionTotals[]>;
listTenants(): Promise<string[]>;
nextOrder(ownerType: string, ownerId: string, collection: string): Promise<number>;
}
//# sourceMappingURL=lucid.d.ts.map