@avonjs/avonjs
Version:
A fluent Node.js API generator.
122 lines (121 loc) • 4.02 kB
TypeScript
import FieldCollection from '../Collections/FieldCollection';
import { type AnyValue, type DisplayFieldCallback, type Model, type OpenApiSchema, type RelatableQueryCallback } from '../Contracts';
import { Filter } from '../Filters';
import type AssociableRequest from '../Http/Requests/AssociableRequest';
import type AvonRequest from '../Http/Requests/AvonRequest';
import { Ordering } from '../Orderings';
import type { Repository } from '../Repositories';
import type Resource from '../Resource';
import Lazy from './Lazy';
export default abstract class Relation extends Lazy {
/**
* Name of the relationship.
*/
relation?: string;
/**
* The related resource instance
*/
relatedResource: Resource;
/**
* The foreign key of the parent model.
* The attribute name that holds the parent model key.
*/
foreignKey: string;
/**
* The associated key on the child model.
* Defaults to primary key of parent model.
*/
ownerKey: string;
/**
* The callback that should be run to associate relations.
*/
relatableQueryCallback: RelatableQueryCallback;
constructor(resource: string, relation?: string);
/**
* Indicates fields uses to display in relation request.
*/
protected relatableFields: DisplayFieldCallback;
/**
* Get all of the possibly available filters for the request.
*/
availableFilters(request: AvonRequest): Filter[];
/**
* Resolve the related resource filters.
*/
protected relatedResourceFilters(request: AvonRequest): Filter[];
/**
* Get all of the possibly available filters for the request.
*/
availableOrderings(request: AvonRequest): Ordering[];
/**
* Resolve the related resource orderings.
*/
protected relatedResourceOrderings(request: AvonRequest): Ordering[];
/**
* Mutate the field value for response.
*/
getMutatedValue(request: AvonRequest, value: AnyValue): AnyValue;
/**
* Format the given related resource.
*/
formatRelatedResource(request: AvonRequest, resource: Model): import("../Contracts").AnyRecord;
/**
* Set related model foreign key.
*/
withForeignKey(foreignKey: string): this;
/**
* Get attribute that hold the related model key.
*/
foreignKeyName(request: AvonRequest): string;
/**
* Set related model owner key.
*/
withOwnerKey(ownerKey: string): this;
/**
* Get attribute that hold the related model key.
*/
ownerKeyName(request: AvonRequest): string;
/**
* Determine display fields.
*/
fields(callback: DisplayFieldCallback): this;
/**
* Resolve value for given resources.
*/
resolveForResources(request: AvonRequest, resources: Model[]): Promise<void>;
/**
* Resolve related value for given resources.
*/
resolveRelatables(request: AvonRequest, resources: Model[]): Promise<void>;
/**
* Get related models for given resources.
*/
abstract searchRelatables(request: AvonRequest, resources: Model[]): Promise<Model[]>;
/**
* Search associable resources.
*/
searchAssociable(request: AssociableRequest, withTrashed?: boolean): Promise<Repository<Model>>;
/**
* Determine the associate relations query.
*/
relatableQueryUsing(relatableQueryCallback: RelatableQueryCallback): this;
/**
* Define filterable attribute.
*/
filterableAttribute(request: AvonRequest): string;
/**
* Resolve the field's value.
*/
resolve(resource: Model, attribute?: string): AnyValue;
/**
* Determine field is filterable or not.
*/
isFilterable(): boolean;
/**
* Determine field is orderable or not.
*/
isOrderable(): boolean;
protected responseSchema(request: AvonRequest): OpenApiSchema;
protected payloadSchema(request: AvonRequest): OpenApiSchema;
protected schemaFields(request: AvonRequest): FieldCollection;
}