UNPKG

@busy-hour/blaze

Version:

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

60 lines (59 loc) • 1.61 kB
// src/loader/trpc/constructor.ts import { getTrpcInput, trpcHandler } from "./helper.js"; var TrpcConstructor = class { app; procedure; actions; trpcActions; $trpcMutations; $trpcQueries; constructor(app, procedure) { this.app = app; this.procedure = procedure; this.actions = this.app.services.map((service) => service.actions).flat(1); this.actions = this.actions.filter((action) => action.action.trpc); this.trpcActions = this.actions.reduce( (prev, curr) => { const type = curr.action.trpc; if (!type) return prev; prev[type].push(curr); return prev; }, { mutation: [], query: [], subscription: [] } ); this.$trpcMutations = null; this.$trpcQueries = null; } get trpcMutations() { if (this.$trpcMutations) return this.$trpcMutations; this.$trpcMutations = this.trpcActions.mutation.reduce((prev, curr) => { prev[curr.actionName] = getTrpcInput(this.procedure, curr).mutation( ({ input }) => trpcHandler(curr, input) ); return prev; }, {}); return this.$trpcMutations; } get trpcQueries() { if (this.$trpcQueries) return this.$trpcQueries; this.$trpcQueries = this.trpcActions.query.reduce((prev, curr) => { prev[curr.actionName] = getTrpcInput(this.procedure, curr).query( ({ input }) => trpcHandler(curr, input) ); return prev; }, {}); return this.$trpcQueries; } get procedures() { return { ...this.trpcMutations, ...this.trpcQueries }; } }; export { TrpcConstructor };