@busy-hour/blaze
Version:
<h1 align='center'>🔥 Blaze</h1> <div align='center'> An event driven framework for 🔥 Hono.js </div>
114 lines (113 loc) • 3.48 kB
TypeScript
/// <reference types="node" />
import type { AddressInfo } from 'node:net';
import { BlazeService } from '../loader/service';
import { type UseTrpc } from '../loader/trpc/index';
import type { BlazeFetch, CreateBlazeOption, ServeConfig } from '../types/router';
import type { ImportServiceOption, LoadServicesOption } from '../types/service';
import { BlazeRouter } from './BlazeRouter';
export declare class Blaze {
private readonly $services;
readonly router: BlazeRouter;
/**
* Shorthand for `app.router.doc`.
* It allows you to generate OpenAPI documents and serve it at the given path.
* @example
* ```ts
* app.doc('/doc', {
* openapi: '3.0.0',
* info: {
* version: '1.0.0',
* title: 'Blaze OpenAPI Example'
* }
* })
* ```
* @see {@link BlazeRouter.doc}
*/
readonly doc: BlazeRouter['doc'];
/**
* Shorthand for `app.router.doc31`.
* It allows you to generate OpenAPI documents and serve it at the given path.
* @example
* ```ts
* app.doc31('/doc', {
* openapi: '3.1.0',
* info: {
* version: '1.0.0',
* title: 'Blaze OpenAPI Example'
* }
* })
* ```
* @see {@link BlazeRouter.doc}
*/
readonly doc31: BlazeRouter['doc31'];
/**
* Shorthand for `app.router.use`.
* It allows you to add middleware to the router
* @example
* ```ts
* app.use(cors())
* ```
* @see {@link BlazeRouter.use}
*/
readonly use: BlazeRouter['use'];
private readonly ctx;
private readonly adapter;
readonly fetch: BlazeFetch;
readonly trpc: UseTrpc;
constructor(options?: CreateBlazeOption);
/**
* Start all the loaded services
* @example
* ```ts
* app.start()
* ```
* passing `autoStart: true` on app creation (`new Blaze({ autoStart: true })`) will also start all the services
*/
start(): void;
private addServices;
/**
* `load` all the services from the given path
* @example
* ```ts
* app.load({
* path: path.resolve(__dirname, 'services'),
* autoStart: true
* })
* ```
* `autoStart` options will start all the services when all the services are loaded
*/
load(options: LoadServicesOption): Promise<void>;
/**
* Same as `load` but requires an array of services instead of a path. Recommended if you want to bundle those services with Bun
* @example
* ```ts
* app.import({
* services: [userService, authService, ...],
* autoStart: true
* })
* ```
*/
import(options: ImportServiceOption): void;
/**
* List of all the loaded services
* @see {@link BlazeService}
*/
get services(): BlazeService[];
private getServeConfig;
/**
* Start the server at the given port
* @param listener - [Only for Node] a listener that will be called when the server is started.
* @example
* ```ts
* // Start server at port 3000
* app.serve(3000)
*
* // Pass a listener after server started
* app.serve(3000, (addressInfo) => {
* console.log(`Server started at ${addressInfo.address}:${addressInfo.port}`)
* })
* ```
*/
serve(port?: number): ServeConfig;
serve<Listener extends (addressInfo: AddressInfo) => void>(port: number, listener: Listener): [ServeConfig, Listener];
}