Skip to content

Commit

Permalink
chore: Apply trpc 11 fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 committed Jul 30, 2024
1 parent e18690f commit cbca7ce
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/adapters/node-http/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export const createOpenApiNodeHttpHandler = <
const caller = router.createCaller(ctx);

const segments = procedure.path.split('.');
const procedureFn = segments.reduce((acc, curr) => acc[curr], caller as any) as AnyProcedure;
const procedureFn = segments.reduce((acc, curr) => acc[curr], caller) as AnyProcedure;

data = await procedureFn(input);

Expand Down Expand Up @@ -165,7 +165,7 @@ export const createOpenApiNodeHttpHandler = <
errors: [error],
});

const errorShape = router.getErrorShape({
const errorShape = router._def.getErrorShape({
error,
type: procedure?.type ?? 'unknown',
path: procedure?.path,
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/node-http/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const getQuery = (req: NodeHTTPRequest, url: URL): Record<string, string>

// normalize first value in array
Object.keys(req.query).forEach((key) => {
const value = req.query![key];
const value = req.query[key];
if (value) {
if (typeof value === 'string') {
query[key] = value;
Expand Down
20 changes: 2 additions & 18 deletions src/adapters/node-http/procedures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,20 @@ export const createProcedureCache = (router: OpenApiRouter) => {
>
>();

const { queries, mutations } = router._def;

forEachOpenApiProcedure(queries, ({ path: queryPath, procedure, openapi }) => {
forEachOpenApiProcedure(router._def.procedures, ({ path: queryPath, procedure, openapi }) => {
const { method } = openapi;
if (!procedureCache.has(method)) {
procedureCache.set(method, new Map());
}
const path = normalizePath(openapi.path);
const pathRegExp = getPathRegExp(path);
procedureCache.get(method)!.set(pathRegExp, {
type: 'query',
type: procedure._def.type,
path: queryPath,
procedure,
});
});

forEachOpenApiProcedure(mutations, ({ path: mutationPath, procedure, openapi }) => {
const { method } = openapi;
if (!procedureCache.has(method)) {
procedureCache.set(method, new Map());
}
const path = normalizePath(openapi.path);
const pathRegExp = getPathRegExp(path);
procedureCache.get(method)!.set(pathRegExp, {
type: 'mutation',
path: mutationPath,
procedure,
});
});

return (method: OpenApiMethod, path: string) => {
const procedureMethodCache = procedureCache.get(method);
if (!procedureMethodCache) {
Expand Down
7 changes: 1 addition & 6 deletions src/utils/procedure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@ export const getInputOutputParsers = (procedure: OpenApiProcedure) => {
};
};

const getProcedureType = (procedure: OpenApiProcedure): ProcedureType => {
if (procedure._def.query) return 'query';
if (procedure._def.mutation) return 'mutation';
if (procedure._def.subscription) return 'subscription';
throw new Error('Unknown procedure type');
};
const getProcedureType = (procedure) => procedure._def.type;

export const forEachOpenApiProcedure = (
procedureRecord: OpenApiProcedureRecord,
Expand Down

0 comments on commit cbca7ce

Please sign in to comment.