UNPKG

@busy-hour/blaze

Version:

<h1 align='center'>🔥 Blaze</h1> <div align='center'> An event driven framework for 🔥 Hono.js </div>

87 lines (86 loc) • 2.23 kB
// src/internal/config/index.ts import { z } from "zod"; import { crossRequire } from "../../utils/common.js"; import { DependencyModuleMap, ExternalModule, PossibleRunTime } from "../../utils/constant/config/index.js"; import { isBun, isDeno, isEdgeLight, isFastly, isNetlify, isNode, isWorkerd } from "../../utils/constant/config/runtime.js"; import { Logger } from "../logger/index.js"; var BlazeConfig = class { runTime; modules; constructor() { this.runTime = this.getRunTime(); this.modules = { [ExternalModule.NodeAdapter]: null, [ExternalModule.ZodApi]: this.loadModule(ExternalModule.ZodApi), [ExternalModule.Trpc]: this.loadModule(ExternalModule.Trpc), [ExternalModule.TrpcAdapter]: this.loadModule(ExternalModule.TrpcAdapter) }; if (this.runTime !== PossibleRunTime.NODE) return; this.modules[ExternalModule.NodeAdapter] = this.loadModule( ExternalModule.NodeAdapter ); } getRunTime() { if (isNetlify) return PossibleRunTime.NETLIFY; if (isEdgeLight) return PossibleRunTime.EDGE_LIGHT; if (isWorkerd) return PossibleRunTime.WORKER_D; if (isFastly) return PossibleRunTime.FASTLY; if (isDeno) return PossibleRunTime.DENO; if (isBun) return PossibleRunTime.BUN; if (isNode) return PossibleRunTime.NODE; return PossibleRunTime.OTHER; } loadModule(module) { try { return crossRequire(module); } catch { return null; } } module(module) { if (!this.modules[module]) { throw Logger.throw(`${DependencyModuleMap[module]} is not installed`); } return this.modules[module]; } /** * Load necessary module directly that will be used in the app. Recommended if you want to bundle the app with Bun * @example * ```ts * import * as nodeAdapter from '@hono/node-server' * * app.setModule(ExternalModule.NodeAdapter, nodeAdapter) * ``` */ setModule(id, module) { this.modules[id] = module; if (id === ExternalModule.ZodApi && module) { delete z.ZodType.prototype.openapi; const zodApi = module; zodApi.extendZodWithOpenApi(z); } } }; export { BlazeConfig };