Yedidya Rashi
Yedidya Rashi
TtRPC
Created by Yedidya Rashi on 9/26/2024 in #❓-help
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,
},
}) => {
...
},
)});
6 replies
TtRPC
Created by Yedidya Rashi on 8/26/2024 in #❓-help
TypeError [ERR_INVALID_STATE]: Invalid state: Controller is already closed
I am getting this error
⨯ unhandledRejection: TypeError [ERR_INVALID_STATE]: Invalid state: Controller is already closed
at new NodeError (node:internal/errors:405:5)
at ReadableStreamDefaultController.enqueue (node:internal/webstreams/readablestream:1045:13)
at eval (webpack-internal:///(rsc)/./node_modules/.pnpm/@trpc+server@11.0.0-rc.477/node_modules/@trpc/server/dist/unstable-core-do-not-import/stream/jsonl.mjs:72:31)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 'ERR_INVALID_STATE'
⨯ unhandledRejection: TypeError [ERR_INVALID_STATE]: Invalid state: Controller is already closed
at new NodeError (node:internal/errors:405:5)
at ReadableStreamDefaultController.enqueue (node:internal/webstreams/readablestream:1045:13)
at eval (webpack-internal:///(rsc)/./node_modules/.pnpm/@trpc+server@11.0.0-rc.477/node_modules/@trpc/server/dist/unstable-core-do-not-import/stream/jsonl.mjs:72:31)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 'ERR_INVALID_STATE'
this is my env: I am using pnpm as my package manager
System:
OS: macOS 14.6.1
CPU: (12) arm64 Apple M2 Max
Memory: 12.19 GB / 64.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.20.2 - ~/.nvm/versions/node/v18.20.2/bin/node
Yarn: 1.22.22 - ~/Library/pnpm/yarn
npm: 10.7.0 - ~/.nvm/versions/node/v18.20.2/bin/npm
pnpm: 9.1.0 - ~/Library/pnpm/pnpm
Watchman: 2024.08.12.00 - /opt/homebrew/bin/watchman
Browsers:
Chrome: 128.0.6613.85
Safari: 17.6
npmPackages:
@tanstack/react-query: ^5.51.23 => 5.51.23
@trpc/client: 11.0.0-rc.477 => 11.0.0-rc.477+a467f8314
@trpc/react-query: 11.0.0-rc.477 => 11.0.0-rc.477+a467f8314
@trpc/server: 11.0.0-rc.477 => 11.0.0-rc.477+a467f8314
next: ^14.2.5 => 14.2.5
react: ^18.3.1 => 18.3.1
typescript: ^5.5.4 => 5.5.4
System:
OS: macOS 14.6.1
CPU: (12) arm64 Apple M2 Max
Memory: 12.19 GB / 64.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.20.2 - ~/.nvm/versions/node/v18.20.2/bin/node
Yarn: 1.22.22 - ~/Library/pnpm/yarn
npm: 10.7.0 - ~/.nvm/versions/node/v18.20.2/bin/npm
pnpm: 9.1.0 - ~/Library/pnpm/pnpm
Watchman: 2024.08.12.00 - /opt/homebrew/bin/watchman
Browsers:
Chrome: 128.0.6613.85
Safari: 17.6
npmPackages:
@tanstack/react-query: ^5.51.23 => 5.51.23
@trpc/client: 11.0.0-rc.477 => 11.0.0-rc.477+a467f8314
@trpc/react-query: 11.0.0-rc.477 => 11.0.0-rc.477+a467f8314
@trpc/server: 11.0.0-rc.477 => 11.0.0-rc.477+a467f8314
next: ^14.2.5 => 14.2.5
react: ^18.3.1 => 18.3.1
typescript: ^5.5.4 => 5.5.4
4 replies