UNPKG

@busy-hour/blaze

Version:

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

61 lines (60 loc) • 2.12 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 trpc_exports = {}; __export(trpc_exports, { loadTrpc: () => loadTrpc, useTrpc: () => useTrpc }); module.exports = __toCommonJS(trpc_exports); var import_instance = require("../../internal/config/instance"); var import_config = require("../../utils/constant/config/index"); var import_constructor = require("./constructor"); function loadTrpc(app) { const instance = import_instance.BlazeConfig.module(import_config.ExternalModule.Trpc).initTRPC.create(); const trpcLoader = new import_constructor.TrpcConstructor(app, instance.procedure); const router = instance.router(trpcLoader.procedures); return { router, instance, procedure: instance.procedure }; } function useTrpc(path, { endpoint = "/trpc", middlewares = [], ...options } = {}) { const trpc = loadTrpc(this); this.use(path, ...middlewares, async (ctx) => { const response = await import_instance.BlazeConfig.module( import_config.ExternalModule.TrpcAdapter ).fetchRequestHandler({ ...options, router: trpc.router, async createContext() { }, endpoint, req: ctx.req.raw }); ctx.body(response.body, response); return response; }); return trpc; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { loadTrpc, useTrpc });