UNPKG

@opra/common

Version:
142 lines (141 loc) 8.24 kB
import type { StrictOmit, Type, TypeThunkAsync } from 'ts-gems'; import { OpraFilter } from '../../filter/index.js'; import { OpraSchema } from '../../schema/index.js'; import { HttpOperation } from '../http/http-operation.js'; import type { HttpParameter } from '../http/http-parameter.js'; import { HttpRequestBody } from '../http/http-request-body.js'; import { type HttpOperationDecorator } from './http-operation.decorator.js'; /** Augmentation **/ declare module '../http/http-operation.js' { /** * HttpOperationStatic */ interface HttpOperationStatic { Entity: HttpOperationEntity; } interface HttpOperationEntity { Create(type: Type | string, options?: StrictOmit<HttpOperation.Entity.CreateArgs, 'type'>): HttpOperation.Entity.CreateDecorator; Create(args: HttpOperation.Entity.CreateArgs): HttpOperation.Entity.CreateDecorator; Delete(type: Type | string, options?: StrictOmit<HttpOperation.Entity.DeleteArgs, 'type'>): HttpOperation.Entity.DeleteDecorator; Delete(args: HttpOperation.Entity.DeleteArgs): HttpOperation.Entity.DeleteDecorator; DeleteMany(type: Type | string, options?: StrictOmit<HttpOperation.Entity.DeleteManyArgs, 'type'>): HttpOperation.Entity.DeleteManyDecorator; DeleteMany(args: HttpOperation.Entity.DeleteManyArgs): HttpOperation.Entity.DeleteManyDecorator; FindMany(type: Type | string, options?: StrictOmit<HttpOperation.Entity.FindManyArgs, 'type'>): HttpOperation.Entity.FindManyDecorator; FindMany(args: HttpOperation.Entity.FindManyArgs): HttpOperation.Entity.FindManyDecorator; Get(type: Type | string, options?: StrictOmit<HttpOperation.Entity.GetArgs, 'type'>): HttpOperation.Entity.GetDecorator; Get(args: HttpOperation.Entity.GetArgs): HttpOperation.Entity.GetDecorator; Replace(type: Type | string, options?: StrictOmit<HttpOperation.Entity.UpdateArgs, 'type'>): HttpOperation.Entity.ReplaceDecorator; Replace(args: HttpOperation.Entity.ReplaceArgs): HttpOperation.Entity.ReplaceDecorator; Update(type: Type | string, options?: StrictOmit<HttpOperation.Entity.UpdateArgs, 'type'>): HttpOperation.Entity.UpdateDecorator; Update(args: HttpOperation.Entity.UpdateArgs): HttpOperation.Entity.UpdateDecorator; UpdateMany(type: Type | string, options?: StrictOmit<HttpOperation.Entity.UpdateManyArgs, 'type'>): HttpOperation.Entity.UpdateManyDecorator; UpdateMany(args: HttpOperation.Entity.UpdateManyArgs): HttpOperation.Entity.UpdateManyDecorator; } namespace HttpOperation { namespace Entity { /** Create */ interface CreateDecorator extends HttpOperationDecorator { } interface CreateArgs extends StrictOmit<HttpOperation.Options, 'method' | 'requestBody'> { type: Type | string; requestBody?: Pick<HttpRequestBody.Options, 'description' | 'maxContentSize'> & { type?: Type | string; immediateFetch?: boolean; }; } /** Delete */ interface DeleteDecorator extends HttpOperationDecorator { KeyParam(name: string, optionsOrType?: StrictOmit<HttpParameter.Options, 'location'> | string | TypeThunkAsync): this; } interface DeleteArgs extends StrictOmit<HttpOperation.Options, 'method' | 'requestBody'> { type: Type | string; } /** DeleteMany */ interface FilterOptions { mappedField?: string; operators?: OpraFilter.ComparisonOperator[]; notes?: string; prepare?: (args: OpraFilter.ComparisonExpression.PrepareArgs) => any; } interface DeleteManyDecorator extends HttpOperationDecorator { Filter(field: string, operators?: OpraFilter.ComparisonOperator[] | string): this; Filter(field: string, options?: FilterOptions): this; } interface DeleteManyArgs extends StrictOmit<HttpOperation.Options, 'method' | 'requestBody'> { type: Type | string; } /** FindMany */ interface FindManyDecorator extends HttpOperationDecorator { SortFields(...fields: OpraSchema.Field.QualifiedName[]): FindManyDecorator; SortFields(fieldsMap: Record<OpraSchema.Field.QualifiedName, OpraSchema.Field.QualifiedName>): FindManyDecorator; DefaultSort(...fields: OpraSchema.Field.QualifiedName[]): FindManyDecorator; Filter(field: OpraSchema.Field.QualifiedName, operators?: OpraFilter.ComparisonOperator[] | string): this; Filter(field: string, options?: FilterOptions): this; } interface FindManyArgs extends StrictOmit<HttpOperation.Options, 'method' | 'requestBody'> { type: Type | string; defaultLimit?: number; defaultProjection?: string[]; maxLimit?: number; } /** Get */ interface GetDecorator extends HttpOperationDecorator { KeyParam(name: string, optionsOrType?: StrictOmit<HttpParameter.Options, 'location'> | string | TypeThunkAsync): this; } interface GetArgs extends StrictOmit<HttpOperation.Options, 'method' | 'requestBody'> { type: Type | string; } /** Replace */ interface ReplaceDecorator extends HttpOperationDecorator { KeyParam(name: string, optionsOrType?: StrictOmit<HttpParameter.Options, 'location'> | string | TypeThunkAsync): this; } interface ReplaceArgs extends StrictOmit<HttpOperation.Options, 'method' | 'requestBody'> { type: Type | string; } /** Update */ interface UpdateDecorator extends HttpOperationDecorator { KeyParam(name: string, optionsOrType?: StrictOmit<HttpParameter.Options, 'location'> | string | TypeThunkAsync): this; Filter(field: OpraSchema.Field.QualifiedName, operators?: OpraFilter.ComparisonOperator[] | string): this; Filter(field: string, options?: FilterOptions): this; } interface UpdateArgs extends StrictOmit<HttpOperation.Options, 'method' | 'requestBody'> { type: Type | string; requestBody?: Pick<HttpRequestBody.Options, 'description' | 'maxContentSize'> & { type?: Type | string; immediateFetch?: boolean; allowPatchOperators?: boolean; }; } /** UpdateMany */ interface UpdateManyDecorator extends HttpOperationDecorator { Filter(field: OpraSchema.Field.QualifiedName, operators?: OpraFilter.ComparisonOperator[] | string): this; Filter(field: string, options?: FilterOptions): this; } interface UpdateManyArgs extends StrictOmit<HttpOperation.Options, 'method' | 'requestBody'> { type: Type | string; requestBody?: Pick<HttpRequestBody.Options, 'description' | 'maxContentSize'> & { type?: Type | string; immediateFetch?: boolean; allowPatchOperators?: boolean; }; } } } } /** * * @param typ */ export declare function getDataTypeName(typ: Type | string): string; /** * */ export declare function createKeyParamDecorator<T extends HttpOperationDecorator>(decorator: T, decoratorChain: Function[]): (name: string, prmOptions?: StrictOmit<HttpParameter.Options, "location"> | string | Type) => T; /** * */ export declare function createSortFieldsDecorator<T extends HttpOperationDecorator>(decorator: T, decoratorChain: Function[]): (...varargs: any[]) => T; /** * */ export declare function createFilterDecorator<T extends HttpOperationDecorator>(decorator: T, decoratorChain: Function[], dataType: string | Type): (field: string, arg0?: OpraFilter.ComparisonOperator[] | string | HttpOperation.Entity.FilterOptions) => T;