@avonjs/avonjs
Version:
A fluent Node.js API generator.
341 lines (340 loc) • 13 kB
TypeScript
import Joi, { type AnySchema } from 'joi';
import type { OpenAPIV3 } from 'openapi-types';
import { type AnyValue, type DefaultCallback, type EvaluatorCallback, type FieldSchema, type FillCallback, type FilledCallback, type FilterableCallback, type Model, type NullableCallback, type OpenApiFieldSchema, type OpenApiSchema, type Optional, type OrderingCallback, type ParameterSerializable, type ResolveCallback, type ResourceEvaluatorCallback, type Rules, type SeeCallback } from '../Contracts';
import type { Filter } from '../Filters';
import type AvonRequest from '../Http/Requests/AvonRequest';
import type { Repository } from '../Repositories';
import Ordering from './Orderings/Ordering';
declare const Field_base: (abstract new (...args: import("../Contracts").Args) => {
seeCallback: SeeCallback;
authorizedToSee(request: AvonRequest): boolean;
canSee(callback: SeeCallback): any;
}) & (abstract new (...args: import("../Contracts").Args) => {
showOnIndexCallback: ResourceEvaluatorCallback;
showOnDetailCallback: ResourceEvaluatorCallback;
showOnReviewCallback: ResourceEvaluatorCallback;
showOnCreationCallback: EvaluatorCallback;
showOnUpdateCallback: ResourceEvaluatorCallback;
showOnAssociationCallback: ResourceEvaluatorCallback;
hideFromIndex(callback?: ResourceEvaluatorCallback | boolean): any;
hideFromDetail(callback?: ResourceEvaluatorCallback | boolean): any;
hideFromReview(callback?: ResourceEvaluatorCallback | boolean): any;
hideFromAssociation(callback?: ResourceEvaluatorCallback | boolean): any;
hideWhenCreating(callback?: EvaluatorCallback | boolean): any;
hideWhenUpdating(callback?: ResourceEvaluatorCallback | boolean): any;
showOnIndex(callback?: ResourceEvaluatorCallback | boolean): any;
showOnDetail(callback?: ResourceEvaluatorCallback | boolean): any;
showOnReview(callback?: ResourceEvaluatorCallback | boolean): any;
showOnAssociation(callback?: ResourceEvaluatorCallback | boolean): any;
showOnCreating(callback?: EvaluatorCallback | boolean): any;
showOnUpdating(callback?: ResourceEvaluatorCallback | boolean): any;
isShownOnUpdate(request: AvonRequest, resource: Model): boolean;
isShownOnIndex(request: AvonRequest, resource: Model): boolean;
isShownOnDetail(request: AvonRequest, resource: Model): boolean;
isShownOnReview(request: AvonRequest, resource: Model): boolean;
isShownOnAssociation(request: AvonRequest): boolean;
isShownOnCreation(request: AvonRequest): boolean;
onlyOnIndex(): any;
onlyOnDetail(): any;
onlyOnReview(): any;
onlyOnAssociation(): any;
onlyOnForms(): any;
exceptOnForms(): any;
}) & (abstract new (...args: import("../Contracts").Args) => {
orderableCallback?: OrderingCallback;
applyOrdering(request: AvonRequest, queryBuilder: Repository<Model>, value: AnyValue): void;
resolveOrdering(request: AvonRequest): import("../Orderings").Ordering | undefined;
orderable(callback?: OrderingCallback): any;
defaultOrderingCallback(): OrderingCallback;
makeOrdering(request: AvonRequest): import("../Orderings").Ordering;
orderableAttribute(request: AvonRequest): string;
}) & (abstract new (...args: import("../Contracts").Args) => {
filterableCallback?: FilterableCallback | boolean;
applyFilter(request: AvonRequest, queryBuilder: Repository<Model>, value: AnyValue): Promise<void>;
resolveFilter(request: AvonRequest): Filter | undefined;
filterable(callback?: FilterableCallback | boolean): any;
makeFilter(request: AvonRequest): Filter;
filterableAttribute(request: AvonRequest): string;
}) & (abstract new (...args: import("../Contracts").Args) => {
acceptsNullValues: boolean;
nullValidator: NullableCallback;
nullable(nullable?: boolean, validator?: NullableCallback): any;
nullValues(nullValidator: NullableCallback): any;
isNullable(): boolean;
isValidNullValue(value: AnyValue): boolean;
valueIsConsideredNull(value: AnyValue): boolean;
}) & (abstract new (...args: import("../Contracts").Args) => {
lookupCallback?: FilterableCallback | boolean;
lookupKeyUsing?: string;
applyLookup(request: AvonRequest, queryBuilder: Repository<Model>, value: AnyValue): Promise<void>;
isLookupable(): boolean;
lookupable(callback?: FilterableCallback | boolean): any;
lookupKey(): string;
lookupUsing(lookupKey: string): any;
}) & {
new (): {};
};
export default abstract class Field extends Field_base implements FieldSchema, ParameterSerializable {
/**
* The attribute / column name of the field.
*/
attribute: string;
/**
* The validation attribute for the field.
*/
validationAttribute?: string;
/**
* The field's resolved value.
*/
value?: AnyValue;
/**
* The callback to be used to hydrate the model attribute.
*/
fillCallback?: FillCallback;
/**
* The callback to be used to resolve the field's display value.
*/
displayCallback: ResolveCallback;
/**
* The callback to be used to resolve the field's value.
*/
resolveCallback: ResolveCallback;
/**
* The callback to be used for the field's default value.
*/
defaultCallback?: DefaultCallback;
/**
* The validation rules callback for creation and updates.
*/
protected rulesSchema: AnySchema;
/**
* The validation rules callback for creation.
*/
protected creationRulesSchema: AnySchema;
/**
* The validation rules callback for updates.
*/
protected updateRulesSchema: AnySchema;
/**
* The help text for the field.
*/
protected helpText?: string;
/**
* Custom label for the field.
*/
protected name?: string;
/**
* Define the default orderable callback.
*/
defaultOrderingCallback(): OrderingCallback;
constructor(attribute: string, resolveCallback?: ResolveCallback);
/**
* Resolve the field's value for display.
*/
resolveForDisplay(resource: Model, attribute?: string): AnyValue;
/**
* Resolve the field's value.
*/
resolve(resource: Model, attribute?: string): AnyValue;
/**
* Resolve the given attribute from the given resource.
*/
protected resolveAttribute(resource: Model, attribute: string): AnyValue;
/**
* Set the callback to be used for determining the field's default value.
*/
default(callback: DefaultCallback): this;
/**
* Resolve the default value for the field.
*/
resolveDefaultValue(request: AvonRequest): AnyValue;
/**
* Define the callback that should be used to display the field's value.
*/
displayUsing(displayCallback: ResolveCallback): this;
/**
* Define the callback that should be used to resolve the field's value.
*/
resolveUsing(resolveCallback: ResolveCallback): this;
/**
* Specify a callback that should be used to hydrate the model attribute for the field.
*/
fillUsing(fillCallback: FillCallback): this;
/**
* Hydrate the given attribute on the model based on the incoming request.
*/
fill<TModel extends Model>(request: AvonRequest, model: TModel): AnyValue;
/**
* Hydrate the given attribute on the model based on the incoming request.
*/
fillForAction<TModel extends Model>(request: AvonRequest, model: TModel): AnyValue;
/**
* Hydrate the given attribute on the model based on the incoming request.
*/
fillInto<TModel extends Model>(request: AvonRequest, model: TModel, attribute: string, requestAttribute?: string): AnyValue;
/**
* Hydrate the given attribute on the model based on the incoming request.
*/
protected fillAttribute<TModel extends Model>(request: AvonRequest, requestAttribute: string, model: TModel, attribute: string): AnyValue;
/**
* Hydrate the given attribute on the model based on the incoming request.
*/
protected fillAttributeFromRequest<TModel extends Model>(request: AvonRequest, requestAttribute: string, model: TModel, attribute: string): Optional<FilledCallback>;
/**
* Hydrate the given attribute on the model based on the default callback.
*/
protected fillAttributeFromDefault<TModel extends Model>(request: AvonRequest, model: TModel, attribute: string): void;
/**
* Get the value considered as null.
*/
nullValue(): AnyValue;
/**
* Set the value for the field.
*/
setValue(value: AnyValue): this;
/**
* Mutate the field value for response.
*/
abstract getMutatedValue(request: AvonRequest, value: AnyValue): AnyValue;
/**
* Set the validation rules for the field.
*/
rules(rules: AnySchema): this;
/**
* Get the validation rules for this field.
*/
getRules(request: AvonRequest): Rules;
/**
* Get the creation rules for this field.
*/
getCreationRules(request: AvonRequest): Rules;
/**
* Set the creation validation rules for the field.
*/
creationRules(rules: AnySchema): this;
/**
* Get the update rules for this field.
*/
getUpdateRules(request: AvonRequest): Rules;
/**
* Set the creation validation rules for the field.
*/
updateRules(rules: AnySchema): this;
/**
* Get the validation attribute for the field.
*/
getValidationAttribute(request: AvonRequest): string | undefined;
/**
* Get field validator.
*/
validator(): typeof Joi;
/**
* Determine if the field is required.
*/
isRequired(request: AvonRequest): boolean;
/**
* Determine if the field is required for creation.
*/
isRequiredForCreation(request: AvonRequest): boolean;
/**
* Determine if the field is required for update.
*/
isRequiredForUpdate(request: AvonRequest): boolean;
/**
* Define filterable attribute.
*/
filterableAttribute(request: AvonRequest): string;
/**
* Define orderable attribute.
*/
orderableAttribute(request: AvonRequest): string;
/**
* Determine field is fillable or not.
*/
fillable(): boolean;
/**
* Determine field is resolvable or not.
*/
resolvable(): boolean;
/**
* Specify the field help text.
*/
help(helpText: string): this;
/**
* Specify the field label.
*/
withName(name: string): this;
/**
* Determine if the element should be displayed for the given request.
*/
authorize(request: AvonRequest): boolean;
/**
* Make the field filter.
*/
makeFilter(request: AvonRequest): Filter;
/**
* Make the field filter.
*/
makeOrdering(request: AvonRequest): Ordering;
/**
* Determine that the field should be nullable.
*/
nullable(nullable?: boolean, validator?: NullableCallback): this;
/**
* Determine that the field should be filled in the request.
*/
required(required?: boolean): this;
/**
* Determines that the field can be omitted from the request.
*/
optional(optional?: boolean): this;
/**
* Get the value for the field.
*/
getValue(request: AvonRequest): AnyValue;
/**
* Get the swagger-ui schema.
*/
schema(request: AvonRequest): OpenApiFieldSchema;
/**
* Get the swagger-ui schema.
*/
protected payloadSchema(request: AvonRequest): OpenApiSchema;
/**
* Get the swagger-ui schema.
*/
protected responseSchema(request: AvonRequest): OpenApiSchema;
/**
* Get the base swagger-ui schema.
*/
protected baseSchema(request: AvonRequest): OpenApiSchema;
/**
* Serialize parameters for schema.
*/
serializeParameters(request: AvonRequest): OpenAPIV3.ParameterObject[];
/**
* Determine field is filterable or not.
*/
abstract isFilterable(): boolean;
/**
* Determine field is orderable or not.
*/
abstract isOrderable(): boolean;
lookupable(callback?: FilterableCallback | undefined): this;
filterable(callback?: FilterableCallback | undefined): this;
orderable(callback?: OrderingCallback | undefined): this;
canSee(callback: SeeCallback): this;
hideFromIndex(callback?: boolean | ResourceEvaluatorCallback): this;
hideFromDetail(callback?: boolean | ResourceEvaluatorCallback): this;
hideWhenCreating(callback?: boolean | EvaluatorCallback): this;
hideWhenUpdating(callback?: boolean | ResourceEvaluatorCallback): this;
showOnIndex(callback?: boolean | ResourceEvaluatorCallback): this;
showOnDetail(callback?: boolean | ResourceEvaluatorCallback): this;
showOnCreating(callback?: boolean | EvaluatorCallback): this;
showOnUpdating(callback?: boolean | ResourceEvaluatorCallback): this;
onlyOnIndex(): this;
onlyOnDetail(): this;
onlyOnForms(): this;
exceptOnForms(): this;
}
export {};