UNPKG

@busy-hour/blaze

Version:

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

98 lines (97 loc) • 3.54 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var config_exports = {}; __export(config_exports, { BlazeConfig: () => BlazeConfig }); module.exports = __toCommonJS(config_exports); var import_zod = require("zod"); var import_common = require("../../utils/common"); var import_config = require("../../utils/constant/config/index"); var import_runtime = require("../../utils/constant/config/runtime"); var import_logger = require("../logger/index"); class BlazeConfig { runTime; modules; constructor() { this.runTime = this.getRunTime(); this.modules = { [import_config.ExternalModule.NodeAdapter]: null, [import_config.ExternalModule.ZodApi]: this.loadModule(import_config.ExternalModule.ZodApi), [import_config.ExternalModule.Trpc]: this.loadModule(import_config.ExternalModule.Trpc), [import_config.ExternalModule.TrpcAdapter]: this.loadModule(import_config.ExternalModule.TrpcAdapter) }; if (this.runTime !== import_config.PossibleRunTime.NODE) return; this.modules[import_config.ExternalModule.NodeAdapter] = this.loadModule( import_config.ExternalModule.NodeAdapter ); } getRunTime() { if (import_runtime.isNetlify) return import_config.PossibleRunTime.NETLIFY; if (import_runtime.isEdgeLight) return import_config.PossibleRunTime.EDGE_LIGHT; if (import_runtime.isWorkerd) return import_config.PossibleRunTime.WORKER_D; if (import_runtime.isFastly) return import_config.PossibleRunTime.FASTLY; if (import_runtime.isDeno) return import_config.PossibleRunTime.DENO; if (import_runtime.isBun) return import_config.PossibleRunTime.BUN; if (import_runtime.isNode) return import_config.PossibleRunTime.NODE; return import_config.PossibleRunTime.OTHER; } loadModule(module2) { try { return (0, import_common.crossRequire)(module2); } catch { return null; } } module(module2) { if (!this.modules[module2]) { throw import_logger.Logger.throw(`${import_config.DependencyModuleMap[module2]} is not installed`); } return this.modules[module2]; } /** * 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, module2) { this.modules[id] = module2; if (id === import_config.ExternalModule.ZodApi && module2) { delete import_zod.z.ZodType.prototype.openapi; const zodApi = module2; zodApi.extendZodWithOpenApi(import_zod.z); } } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { BlazeConfig });