import type { JsonSchemaToTsProvider } from "@fastify/type-provider-json-schema-to-ts"; import type { WebsocketHandler } from "@fastify/websocket"; import type { ContextConfigDefault, FastifyBaseLogger, FastifyInstance, RawReplyDefaultExpression, RawRequestDefaultExpression, RawServerBase, RawServerDefault, RouteHandlerMethod, RouteShorthandOptions } from "fastify"; import type { RouteGenericInterface } from "fastify/types/route"; import type { OperationQueue } from "./operation-queue"; export type { SocketStream } from "@fastify/websocket"; declare module "fastify" { interface FastifyInstance { assetManager: any; /** * A queue of operations to run when the server is shutting down. * * When enqueuing operations, you can specify a priority to control the order in which they run. The lower the * number, the higher the priority. Operations with the same priority are run concurrently. * * The default priority is 50. We recommend using 0 to 100, incrementing by 10. However, anything between -Infinity * and Infinity will work. * * For more information, see {@linkcode OperationQueue}. * * @example * ```ts * server.onShutdown.enqueue("log-2", () => { * server.log.info("2"); * }); * * server.onShutdown.enqueue("log-1", { priority: 40 }, () => { * server.log.info("1"); * }); * * server.onShutdown.enqueue("log-3", { priority: 60 }, () => { * server.log.info("3"); * }); * * await server.close(); * // Logs: * // 1 * // 2 * // 3 * ``` */ onShutdown: OperationQueue<(instance: StarscreamServer) => unknown>; } } export interface StarscreamServer = RawRequestDefaultExpression, RawReply extends RawReplyDefaultExpression = RawReplyDefaultExpression, Logger extends FastifyBaseLogger = StarscreamLoggerInstance> extends FastifyInstance { } /** Type representing the autoloadable routes exported from the routes files */ export type StarscreamRoute = RouteHandlerMethod, RawReplyDefaultExpression, RouteGeneric, ContextConfig> & { options?: RouteShorthandOptions, RawReplyDefaultExpression, RouteGeneric, ContextConfig>; }; export type StarscreamLoggerInstance = FastifyBaseLogger; export type StarscreamPlugin = ((server: StarscreamServer) => Promise) & { enabled?: boolean; constraints?: { [name: string]: any; }; priority?: number; }; export type StarscreamWebsocketRoute = WebsocketHandler, RouteGeneric> & RouteShorthandOptions, RawReplyDefaultExpression, RouteGeneric, ContextConfig> & { options?: RouteShorthandOptions, RawReplyDefaultExpression, RouteGeneric, ContextConfig>; }; export type InjectedResponse = Awaited>;