import type { ExtractScopes, LucidModel } from '@adonisjs/lucid/types/model'; import type { ExtractModelRelations } from '@adonisjs/lucid/types/relations'; import type { IncludeTree, SortField } from './types.ts'; import type { DynamicModelQuery, DynamicScopes } from './lucid_access.ts'; import type { JsonApiRegistry } from './registry.ts'; /** * The related model behind a relation property. Every Lucid relation type * (HasMany, BelongsTo, …) carries its related model constructor as `model`. */ type RelatedModelOf = NonNullable extends { model: infer Model extends LucidModel; } ? Model : never; /** * A scope for one relation, typed to that relation's related model so its * named scopes autocomplete, exactly like Lucid's withScopes() callback. * Either a bare callback (scope this relation) or an object that also * carries scopes for deeper includes. */ export type PreloadScopeEntry = ((scopes: ExtractScopes) => void) | { scope?: (scopes: ExtractScopes) => void; preload?: PreloadScopeMap; }; /** * The argument to withPreloadScopes(): keyed by the model's relation names, * each entry typed to that relation's related model. Recurse through * `preload` to constrain nested includes, typed at every level. */ export type PreloadScopeMap = { [Key in ExtractModelRelations>]?: PreloadScopeEntry, Key>>; }; /** * The runtime, model-agnostic view of a preload-scope tree, mirroring the * include tree. The public PreloadScopeMap narrows this per model * for the caller; internally we walk this loose shape. */ export type PreloadScope = (scopes: DynamicScopes) => void; export type PreloadScopeNode = PreloadScope | { scope?: PreloadScope; preload?: PreloadScopeTree; }; export type PreloadScopeTree = Record; /** * Creates and registers a fresh preload-scope tree for a query builder. * Called once when the query is built; the returned tree is mutated in * place by later withPreloadScopes() calls and read at preload time. */ export declare function preloadScopesFor(query: object): PreloadScopeTree; /** * Merges scopes into a query builder's preload-scope tree, the entry point * for the withPreloadScopes() macro. Safe to call before or after the * includes are built: the tree is read at preload (execution) time. */ export declare function addPreloadScopes(query: object, scopes: PreloadScopeTree): void; /** * Validates every path of an include tree against the model's relationship * definitions. The spec requires a 400 when an unsupported include path is * requested. When a registry is given, relations left out of the resource's * exposeRelationships list are treated as unsupported too, so hidden * relations are rejected before any preloading happens. */ export declare function validateIncludeTree(Model: LucidModel, tree: IncludeTree, registry?: JsonApiRegistry): void; /** * Applies an include tree as nested preloads on a model query, walking the * preload-scope tree alongside it. Each relation is constrained by its * entry's scope (a bare callback, or the `scope` of an object entry), and * the entry's `preload` carries scopes for the next level down. The tree is * read here, inside the preload callback, which Lucid invokes at execution * time, so scopes added after the query is built (a `withPreloadScopes()` * chained after `jsonApi.query()`) still apply. */ export declare function applyIncludes(query: DynamicModelQuery, tree: IncludeTree, Model?: LucidModel, scopeTree?: PreloadScopeTree): void; /** * Applies ?sort= fields to a model query, mapping serialized attribute * names back to database column names. Unknown fields are a 400 per spec. */ export declare function applySort(query: DynamicModelQuery, Model: LucidModel, sort: SortField[]): void; export declare function resolveColumn(Model: LucidModel, serializedName: string): string | undefined; export {};