import type { LucidModel } from '@adonisjs/lucid/types/model'; import type { ResourceIdentifier } from './types.ts'; import type { JsonApiRegistry } from './registry.ts'; /** * A relationship write's references to existing rows. claims carries the * identifiers as the client sent them, so verifyRelatedExist can check a * claimed type against the row it names. */ export type RelatedReference = { relation: string; ids: string[]; claims?: ResourceIdentifier[]; }; /** * Result of deserializing a JSON:API resource document into Lucid-friendly * shapes: * - `attributes` uses model attribute names (serialized names mapped back) * and includes foreign keys derived from to-one relationships, so it can * be passed straight to a validator or Model.create()/merge(). * - `toMany` holds relation name → related ids, to be synced after save. */ export type DeserializedResource = { id?: string; /** * The type the client sent as data.type, already validated against the * accepted set. For an STI base endpoint this says which family member * the document described, so the caller can stamp the discriminator. */ type: string; attributes: Record; toMany: Record; /** * Every related resource referenced by the document (to-one and to-many), * for existence verification (404 per spec). */ references: RelatedReference[]; }; export type DeserializeOptions = { /** * Narrows the accepted primary type to exactly this string. For an * endpoint whose URL names one member of an STI family * (/api/v1/:type), pass the type the URL names, so a body claiming a * different family member is a 409. Without it, an STI base model * accepts any member of its declared family, and any other model * accepts its single type. */ expectedType?: string; /** * The id from the endpoint URL. When set (PATCH), data.id must be present * and match (400/409). When unset (POST), a client-generated id is * rejected with 403 unless allowClientIds is enabled. */ expectedId?: string; allowClientIds?: boolean; }; /** * Deserializes a JSON:API resource document (request body) targeting the * given model, per https://jsonapi.org/format/#crud */ export declare function deserializeResourceDocument(Model: LucidModel, registry: JsonApiRegistry, body: unknown, options?: DeserializeOptions): DeserializedResource; /** * Verifies that every referenced related resource exists. The spec requires * a 404 when a request references a resource that does not exist. */ export declare function verifyRelatedExist(Model: LucidModel, references: RelatedReference[], registry: JsonApiRegistry): Promise;