import type { Logger } from "#Source/log/index.ts" import type { Standard } from "#Source/validation/index.ts" import type { ApiCore } from "./api-core.ts" import type { ErrorResult, SuccessResult } from "./api-result.ts" import type { ApiSchemaOptions } from "./api-schema.ts" export interface ApiHandlerContext< Path extends string, Method extends "get" | "post", InputQuerySchema extends Standard.Schema, InputBodySchema extends Standard.Schema, OutputErrorSchema extends Standard.Schema, OutputSuccessSchema extends Standard.Schema, > extends ApiSchemaOptions< Path, Method, InputQuerySchema, InputBodySchema, OutputErrorSchema, OutputSuccessSchema > { inputQuery: Standard.Schema.InferOutput inputBody: Standard.Schema.InferOutput apiCore: ApiCore logger: Logger } // oxlint-disable-next-line typescript/no-explicit-any export type AnyApiHandlerContext = ApiHandlerContext export type GetInputQuerySchemaFromApiHandlerContext = Target extends ApiHandlerContext< infer _, infer __, infer InputQuerySchema, infer ___, infer ____, infer ______ > ? InputQuerySchema : never export type GetInputBodySchemaFromApiHandlerContext = Target extends ApiHandlerContext< infer _, infer __, infer ___, infer InputBodySchema, infer ____, infer ______ > ? InputBodySchema : never export type GetOutputErrorSchemaFromApiHandlerContext = Target extends ApiHandlerContext< infer _, infer __, infer ___, infer ____, infer OutputErrorSchema, infer ______ > ? OutputErrorSchema : never export type GetOutputSuccessSchemaFromApiHandlerContext = Target extends ApiHandlerContext< infer _, infer __, infer ___, infer ____, infer ______, infer OutputSuccessSchema > ? OutputSuccessSchema : never export type GetInputQueryFromApiHandlerContext = Standard.Schema.InferOutput> export type GetInputBodyFromApiHandlerContext = Standard.Schema.InferOutput> export type GetOutputErrorFromApiHandlerContext = Standard.Schema.InferOutput> export type GetOutputSuccessFromApiHandlerContext = Standard.Schema.InferOutput> export type GetOutputFromApiHandlerContext = | GetOutputErrorFromApiHandlerContext | GetOutputSuccessFromApiHandlerContext export type ApiHandlerResult< OutputErrorSchema extends Standard.Schema, OutputSuccessSchema extends Standard.Schema, > = | ErrorResult> | SuccessResult> export type ApiHandler< Path extends string, Method extends "get" | "post", InputQuerySchema extends Standard.Schema, InputBodySchema extends Standard.Schema, OutputErrorSchema extends Standard.Schema, OutputSuccessSchema extends Standard.Schema, > = ( context: ApiHandlerContext< Path, Method, InputQuerySchema, InputBodySchema, OutputErrorSchema, OutputSuccessSchema >, ) => Promise> // oxlint-disable-next-line typescript/no-explicit-any export type AnyApiHandler = ApiHandler