@melchyore/adonis-auto-preload
Version:
Auto-preload multiple relationships when retrieving Lucid models
20 lines (19 loc) • 907 B
TypeScript
/// <reference types="@adonisjs/lucid" />
declare module '@ioc:Adonis/Addons/AutoPreload' {
import type { LucidModel } from '@ioc:Adonis/Lucid/Orm';
import type { NormalizeConstructor } from '@ioc:Adonis/Core/Helpers';
type GetWith<T> = T extends {
$with: any;
} ? T['$with'][number] extends infer Item ? Item extends string ? Item : never : never : never;
export interface AutoPreloadMixin {
<T extends NormalizeConstructor<LucidModel>>(superclass: T): T & {
$with: any;
without<U extends LucidModel>(this: U, relationships: Array<GetWith<U>>): U;
withOnly<U extends LucidModel>(this: U, relationships: Array<GetWith<U>>): U;
withoutAny<U extends LucidModel>(this: U): U;
new (...args: Array<any>): {};
};
}
const AutoPreload: AutoPreloadMixin;
export { AutoPreload };
}