@avonjs/avonjs
Version:
A fluent Node.js API generator.
145 lines (144 loc) • 4.16 kB
TypeScript
import { type Attributes, type Model, type Nullable, type Optional, RequestTypes, type Transaction, type TransactionCallback, TrashedStatus } from '../../Contracts';
import type { Repository } from '../../Repositories';
import type Resource from '../../Resource';
import FormRequest from './FormRequest';
export default abstract class AvonRequest<R extends Repository<Model> = Repository<Model>> extends FormRequest {
/**
* Indicates type of the request instance.
*/
abstract type(): RequestTypes;
/**
* The repository transaction instance.
*/
protected _trx?: Transaction;
/**
* The user instance.
*/
protected _user: Nullable<Model>;
/**
* Get the transaction instance.
*/
getTransaction(): Transaction | undefined;
/**
* Get the transaction instance.
*/
transaction<V>(callback: TransactionCallback<V, R>): Promise<V>;
/**
* Determine if this request is a create or attach request.
*/
isCreateOrAttachRequest(): boolean;
/**
* Determine if this request is an update or update-attached request.
*/
isUpdateOrUpdateAttachedRequest(): boolean;
/**
* Determine if this request is a resource index request.
*/
isResourceIndexRequest(): boolean;
/**
* Determine if this request is a resource detail request.
*
* @return bool
*/
isResourceDetailRequest(): boolean;
/**
* Determine if this request is a resource review request.
*
* @return bool
*/
isResourceReviewRequest(): boolean;
/**
* Determine if this request is a resource association request.
*
* @return bool
*/
isResourceAssociationRequest(): boolean;
/**
* Determine if this request is an action request.
*/
isActionRequest(): boolean;
/**
* Determine if this request is an schema request.
*/
isSchemaRequest(): boolean;
/**
* Determine if this request is either create, attach, update, update-attached or action request.
*/
isFormRequest(): boolean;
/**
* Determine if this request is an index or detail request.
*/
isPresentationRequest(): boolean;
/**
* Determine if this request is an delete or force-delete request.
*/
isDeleteRequest(): boolean;
/**
* Determine if the requested resource is soft deleting.
*/
resourceSoftDeletes(): boolean;
/**
* Get the resource instance for the request or abort.
*/
resource(): Resource;
/**
* Get the repository for resource being requested.
*/
repository(): R;
/**
* Get the model for resource being requested.
*/
model(): Model;
/**
* Make a new model for given attributes.
*/
newModel(attributes: Attributes): Model;
/**
* Create new instance of the resource being requested for given item.
*/
newResource(resource?: Model): Resource;
/**
* Find the resource instance for the request or abort.
*/
findResourceOrFail(resourceId?: number): Promise<Resource>;
/**
* Find the resource instance for the request.
*/
findResource(resourceId?: number): Promise<Optional<Resource>>;
/**
* Find the model instance for the request or throw an exception.
*/
findModelOrFail(resourceId?: number): Promise<Model>;
/**
* Find the model instance for the request.
*/
findModel(resourceId?: number): Promise<Optional<Model>>;
/**
* Find the model instance for the request.
*/
findModelQuery(resourceId?: number): R;
/**
* Get resource "id" from route or query.
*/
resourceId(): any;
/**
* Get resource "name" from route or query.
*/
resourceName(): any;
/**
* Get trashed status.
*/
protected trashed(): TrashedStatus;
/**
* Get jwt payload.
*/
auth(): import("jsonwebtoken").JwtPayload | undefined;
/**
* Get the user instance.
*/
user<TModel extends Model>(): Nullable<TModel>;
/**
* Set the user instance.
*/
setUser(user: Nullable<Model>): this;
}