import type { HttpContext } from '@adonisjs/core/http'; import type { LucidModel, LucidRow, ModelQueryBuilderContract } from '@adonisjs/lucid/types/model'; import type { Document, JsonApiQueryParams, Links, Meta } from './types.ts'; import { type Paginatorish } from './document_builder.ts'; import { LinkBuilder, type RouterContract } from './links.ts'; import { type DeserializedResource } from './deserializer.ts'; import { type RelationshipAction } from './relationships.ts'; import type { JsonApiRegistry } from './registry.ts'; import type { ResolvedJsonApiConfig } from './define_config.ts'; /** * Request-scoped JSON:API helper, exposed as the `jsonApi` property on the * HttpContext. * * ```ts * async index({ jsonApi }: HttpContext) { * const articles = await jsonApi.query(Article).paginate(...jsonApi.page) * return jsonApi.render(articles) * } * ``` */ export declare class JsonApiRequestContext { #private; constructor(ctx: HttpContext, registry: JsonApiRegistry, config: ResolvedJsonApiConfig, router?: RouterContract); /** * The parsed JSON:API query parameters. Throws a 400 JsonApiException on * malformed parameters. */ get params(): JsonApiQueryParams; /** * Whether errors thrown by this request should render as JSON:API error * documents. Call from the application exception handler: * * ```ts * async handle(error: unknown, ctx: HttpContext) { * if (ctx.jsonApi.handlesErrors()) { * return renderJsonApiError(error, ctx, this.debug) * } * return super.handle(error, ctx) * } * ``` * * Uses the `errorDetection` config predicate when set; otherwise detects * JSON:API requests automatically — the matched route was registered via * router.jsonApiResource(), or the client speaks the JSON:API media type. */ handlesErrors(): boolean; /** * The link builder for this request, namespaced by the current route's * name so generated URLs stay within the route group (e.g. /api/v1 vs * /api/v2) that served the request. */ get links(): LinkBuilder; /** * [pageNumber, pageSize] tuple for Lucid's paginate(), honouring * ?page[number]= and ?page[size]=. */ get page(): [number, number]; /** * Builds a model query with the request's include paths preloaded, sort * applied, and declared filters applied. Invalid include/sort/filter * parameters throw a 400. */ query(model: Model): ModelQueryBuilderContract; /** * Serializes rows/paginator into a JSON:API document — a pure * transformation that never touches the response. Use render() to also * prepare the response. */ serialize(input: LucidRow | LucidRow[] | Paginatorish | null, extras?: { meta?: Meta; links?: Links; }): Document; /** * serialize() + response preparation: sets the JSON:API media type, the * status when given, and the Location header on 201. */ render(input: LucidRow | LucidRow[] | Paginatorish | null, extras?: { meta?: Meta; links?: Links; status?: number; }): Document; /** * Deserializes the request body as a JSON:API resource document for the * given model: 400 on malformed documents, 409 on type/id conflicts, 403 * on client-generated ids, 404 when referenced related resources do not * exist. Returns model-ready attributes (to-one relationships mapped to * foreign keys) plus to-many id lists for syncToMany(). */ deserialize(model: LucidModel, options?: { expectedId?: string; expectedType?: string; }): Promise; /** * Applies deserialized to-many relationships (manyToMany sync, hasMany * adoption) to a persisted row. */ syncToMany(row: LucidRow, toMany: Record): Promise; /** * Renders a relationship linkage document for GET * /:id/relationships/:name endpoints. */ renderRelationship(row: LucidRow, name: string): Promise; /** * Applies a relationship write (PATCH=replace, POST=add, DELETE=remove) * from the request body, then returns the updated linkage document. */ updateRelationship(row: LucidRow, name: string, action: RelationshipAction): Promise; /** * Renders the related resources themselves, for GET /:id/:name endpoints * (the `related` link target). */ renderRelated(row: LucidRow, name: string): Promise; }