Yedidya Rashi
Yedidya Rashi2mo ago

unstable_concat return type is not been propagate to the input

I have a plugin that fetches all my services. I am not sure this is the best way it works for me. The problem is that the input type is not updated after the transformation. Thanks 😃
export function getAllServicesPlugin() {
const t = initTRPC.context<typeof createTRPCContext>().create();

return {
pluginProc: t.procedure
.input(serviceWithDateRangeSchema)
.use(async (opts) => {
const { input, ctx } = opts;

if (input.selectedServices.selectedCategory === "specific") {
return opts.next({
input: {
dateRange: input.dateRange,
services: input.selectedServices.services,
},
});
}
const categorizedRepositories = await getCategorizedRepositories(
ctx.connection,
);

return opts.next({
input: {
dateRange: input.dateRange,
services:
input.selectedServices.selectedCategory === "all-engineering"
? Object.values(categorizedRepositories).flat()
: (categorizedRepositories[
input.selectedServices.selectedCategory
] ?? []),
},
});
}),
};
}
export function getAllServicesPlugin() {
const t = initTRPC.context<typeof createTRPCContext>().create();

return {
pluginProc: t.procedure
.input(serviceWithDateRangeSchema)
.use(async (opts) => {
const { input, ctx } = opts;

if (input.selectedServices.selectedCategory === "specific") {
return opts.next({
input: {
dateRange: input.dateRange,
services: input.selectedServices.services,
},
});
}
const categorizedRepositories = await getCategorizedRepositories(
ctx.connection,
);

return opts.next({
input: {
dateRange: input.dateRange,
services:
input.selectedServices.selectedCategory === "all-engineering"
? Object.values(categorizedRepositories).flat()
: (categorizedRepositories[
input.selectedServices.selectedCategory
] ?? []),
},
});
}),
};
}
const metricsRouter = createTRPCRouter({
getBranchBuildDuration: publicProcedure
.input(serviceWithDateRangeSchema)
.output(
z.object({
overTime: z.array(branchBuildDuration),
aggregativeMetric: aggregativeMetricSchema,
}),
)
.unstable_concat(allServicePlugin.pluginProc)
.query(
async ({
ctx: { connection },
input: {
dateRange: { from, to },
services,
},
}) => {
...
},
)});
const metricsRouter = createTRPCRouter({
getBranchBuildDuration: publicProcedure
.input(serviceWithDateRangeSchema)
.output(
z.object({
overTime: z.array(branchBuildDuration),
aggregativeMetric: aggregativeMetricSchema,
}),
)
.unstable_concat(allServicePlugin.pluginProc)
.query(
async ({
ctx: { connection },
input: {
dateRange: { from, to },
services,
},
}) => {
...
},
)});
2 Replies
Alex / KATT 🐱
Only call next() once in a middleware or else the type will get confused I'm struggling to see what you're trying to do here, but it looks weird that you use input Are you versioning or something
Yedidya Rashi
Yedidya RashiOP2mo ago
I want to create a unified way to get data from db but when I think about it again a function will be simpler