import type API from './Classes/API.js'; import type { FastifyInstance, FastifyPluginOptions, FastifyReply, FastifyRequest } from 'fastify'; import { FastifySchema } from 'fastify/types/schema.js'; import type { Knex } from 'knex'; declare module 'fastify' { interface FastifyInstance { knexAPI: API; knex: Knex; } } export type TKARequest = FastifyRequest; export type TKAReply = FastifyReply; export type TKARequestList = TKARequest & { query: TKAControllerFiltersList | unknown; }; export type TKAParamsIds = Record; export type TKAPks = string | string[] | undefined; export type TKAInternalPks = string[]; export type TTableDefinition = { name: string; pk?: TKAPks; verbs?: TKAVerbs[]; }; export type TTableDefinitionNormalized = TTableDefinition & { pk: TKAInternalPks; }; export type TTablesDefinition = Array; export type TTablesDefinitionNormalized = Array; export type TKACheckAuth = (req: TKARequest, res: TKAReply) => Promise; export type IKACommonOptions = { prefix?: string; tables?: TTablesDefinition; schemas?: (tableName: string, schema: TKAAPISchemas) => TKAAPISchemas; columnSchema?: (tableName: string, columnName: string, jsonColumnSchema: JSONSchemaProps) => JSONSchemaProps | undefined; schemaDirPath?: string; checkAuth?: TKACheckAuth | undefined; verbs?: (tableName: string, verbs: TKAVerbs[] | undefined) => TKAVerbs[] | undefined; }; export type IKAOptions = { knexConfig: Knex.Config; } & IKACommonOptions; export type IKAPluginOptions = FastifyPluginOptions & IKAOptions; export type IKAApiOptions = IKACommonOptions & { fastify: FastifyInstance; knex: Knex; }; export type TColumnsInfo = Record; type TKASchemaResponse = { 200?: JSONSchemaProps; 201?: JSONSchemaProps; 204?: JSONSchemaProps; 302?: JSONSchemaProps; 400?: JSONSchemaProps; 401?: JSONSchemaProps; 404?: JSONSchemaProps; 500?: JSONSchemaProps; }; export type TKASchema = FastifySchema & { summary?: string; response?: TKASchemaResponse; tags?: Array; params?: { type: string; properties: Record; }; }; export type TKAVerbs = 'view' | 'list' | 'create' | 'update' | 'delete'; export type TKAAPISchemas = Record; export type JSONType = 'string' | 'number' | 'integer' | 'boolean' | 'object' | 'array' | 'null' | 'object'; type AnyType = string | number | boolean | object | undefined | Array | null; export type JSONSchemaProps = { type: JSONType; properties?: Record; items?: JSONSchemaProps; $ref?: string; description?: string; required?: Array; enum?: Array; default?: AnyType; additionalProperties?: boolean; oneOf?: Array; anyOf?: Array; allOf?: Array; not?: JSONSchemaProps; title?: string; format?: string; minLength?: number; maxLength?: number; minimum?: number; maximum?: number; multipleOf?: number; exclusiveMinimum?: number; exclusiveMaximum?: number; pattern?: string; minItems?: number; maxItems?: number; uniqueItems?: boolean; contains?: JSONSchemaProps; examples?: AnyType; const?: AnyType; readOnly?: boolean; writeOnly?: boolean; discriminator?: string; xml?: AnyType; externalDocs?: AnyType; deprecated?: boolean; if?: JSONSchemaProps; then?: JSONSchemaProps; else?: JSONSchemaProps; contentEncoding?: string; contentMediaType?: string; contentSchema?: JSONSchemaProps; [key: string]: AnyType; example?: AnyType; }; export interface TKAController { list: (req: TKARequest, res: TKAReply) => Promise; view: (req: TKARequest, res: TKAReply) => Promise; create: (req: TKARequest, res: TKAReply) => Promise; update: (req: TKARequest, res: TKAReply) => Promise; delete: (req: TKARequest, res: TKAReply) => Promise; } export type TKAControllerFiltersPagination = { offset?: number; skip?: number; limit?: number; page?: number; window?: number; }; export type TKAControllerFiltersSort = { sort?: string; }; export type TKAControllerFiltersProjection = { fields?: string; }; export type TKAControllerFiltersSearch = { filter?: string; }; export type TKAControllerFiltersList = TKAControllerFiltersPagination & TKAControllerFiltersSort & TKAControllerFiltersProjection & TKAControllerFiltersSearch; export type TKACrudVerbOptions = { url: string; schema?: TKASchema; handler?: (req: TKARequest, reply: TKAReply, config: TKACrudGenHandlerOptions) => TKAController; }; export type TKACrudVerbs = { list?: TKACrudVerbOptions; view?: TKACrudVerbOptions; create?: TKACrudVerbOptions; update?: TKACrudVerbOptions; delete?: TKACrudVerbOptions; }; export type TKACrudOptions = { controller: TKAController; prefix?: string; checkAuth?: TKACheckAuth | undefined; verbs?: TKAVerbs[] | undefined; pks: TKAInternalPks; } & TKAAPISchemas; export type TKACrudGenHandlerOptions = { type: TKAVerbs; } & TKACrudOptions; export type TKACrudRow = Record; export type TKAListResult = { total: number; items: Array; }; export type TKAVerbResult = TKACrudRow; export {};