πŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more β†’

trpc-to-openapi

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

trpc-to-openapi - npm Package Compare versions

Comparing version

to
2.2.0

@@ -5,4 +5,2 @@ "use strict";

const server_1 = require("@trpc/server");
const unstable_core_do_not_import_1 = require("@trpc/server/unstable-core-do-not-import");
const utils_1 = require("../utils");
const node_http_1 = require("./node-http");

@@ -71,30 +69,7 @@ const getUrlEncodedBody = async (req) => {

const req = await createRequestProxy(opts.req, url.toString());
const createContext = () => {
var _a;
if (opts.createContext) {
return ((_a = opts.createContext({
req: opts.req,
resHeaders,
info: (0, unstable_core_do_not_import_1.getRequestInfo)({
req: req,
path: decodeURIComponent((0, utils_1.normalizePath)(url.pathname)),
router: opts.router,
searchParams: url.searchParams,
headers: req.headers,
}),
})) !== null && _a !== void 0 ? _a : {});
}
return () => ({});
};
const openApiHttpHandler = (0, node_http_1.createOpenApiNodeHttpHandler)({
router: opts.router,
createContext,
// @ts-expect-error FIXME
onError: opts.onError,
// @ts-expect-error FIXME
responseMeta: opts.responseMeta,
}); // as CreateOpenApiNodeHttpHandlerOptions<TRouter, any, any>);
// @ts-expect-error FIXME
const openApiHttpHandler = (0, node_http_1.createOpenApiNodeHttpHandler)(opts);
return new Promise((resolve) => {
let statusCode;
return openApiHttpHandler(req, {
const res = {
setHeader: (key, value) => {

@@ -122,3 +97,4 @@ if (typeof value === 'string') {

},
});
};
return openApiHttpHandler(req, res);
});

@@ -125,0 +101,0 @@ };

@@ -5,9 +5,8 @@ "use strict";

const server_1 = require("@trpc/server");
const node_http_1 = require("@trpc/server/adapters/node-http");
const utils_1 = require("../utils");
const node_http_2 = require("./node-http");
const node_http_1 = require("./node-http");
const createOpenApiNextHandler = (opts) => {
const openApiHttpHandler = (0, node_http_2.createOpenApiNodeHttpHandler)(opts);
const openApiHttpHandler = (0, node_http_1.createOpenApiNodeHttpHandler)(opts);
return async (req, res) => {
var _a, _b;
var _a;
let pathname = null;

@@ -42,7 +41,7 @@ if (typeof req.query.trpc === 'string') {

}
(0, node_http_1.incomingMessageToRequest)(req, Object.assign(res, {
once: () => undefined,
}), {
maxBodySize: (_b = opts.maxBodySize) !== null && _b !== void 0 ? _b : null,
});
if (!('once' in res)) {
Object.assign(res, {
once: () => undefined,
});
}
req.url = (0, utils_1.normalizePath)(pathname);

@@ -49,0 +48,0 @@ await openApiHttpHandler(req, res);

@@ -1,2 +0,3 @@

import { type NodeHTTPHandlerOptions, type NodeHTTPRequest, type NodeHTTPResponse } from '@trpc/server/adapters/node-http';
import { type NodeHTTPHandlerOptions, type NodeHTTPResponse } from '@trpc/server/adapters/node-http';
import { NodeHTTPRequest } from '../../types';
import { OpenApiRouter } from '../../types';

@@ -3,0 +4,0 @@ export type CreateOpenApiNodeHttpHandlerOptions<TRouter extends OpenApiRouter, TRequest extends NodeHTTPRequest, TResponse extends NodeHTTPResponse> = Pick<NodeHTTPHandlerOptions<TRouter, TRequest, TResponse>, 'router' | 'createContext' | 'responseMeta' | 'onError' | 'maxBodySize'>;

@@ -5,3 +5,2 @@ "use strict";

const server_1 = require("@trpc/server");
const node_http_1 = require("@trpc/server/adapters/node-http");
const unstable_core_do_not_import_1 = require("@trpc/server/unstable-core-do-not-import");

@@ -40,4 +39,4 @@ const zod_1 = require("zod");

let ctx = undefined;
let info = undefined;
let data = undefined;
let info = undefined;
const { procedure, pathInput } = (_a = getProcedure(method, path)) !== null && _a !== void 0 ? _a : {};

@@ -59,14 +58,12 @@ try {

}
info = (0, unstable_core_do_not_import_1.getRequestInfo)({
req: req instanceof Request
? req
: (0, node_http_1.incomingMessageToRequest)(req, res, {
maxBodySize: maxBodySize !== null && maxBodySize !== void 0 ? maxBodySize : null,
}),
path: decodeURIComponent(path),
router,
searchParams: url.searchParams,
headers: req.headers,
});
const contentType = (0, utils_1.getContentType)(req);
const useBody = (0, utils_1.acceptsRequestBody)(method);
if (useBody && !(contentType === null || contentType === void 0 ? void 0 : contentType.startsWith('application/json'))) {
throw new server_1.TRPCError({
code: 'UNSUPPORTED_MEDIA_TYPE',
message: contentType
? `Unsupported content-type "${contentType}`
: 'Missing content-type header',
});
}
const inputParser = (0, utils_1.getInputOutputParsers)(procedure.procedure).inputParser;

@@ -89,2 +86,11 @@ const unwrappedSchema = (0, utils_1.unwrapZodType)(inputParser, true);

}
info = {
isBatchCall: false,
accept: null,
calls: [],
type: procedure.type,
connectionParams: null,
signal: (0, utils_1.getRequestSignal)(req, res, maxBodySize),
url,
};
ctx = await (createContext === null || createContext === void 0 ? void 0 : createContext({ req, res, info }));

@@ -143,3 +149,3 @@ const caller = router.createCaller(ctx);

? 'Input validation failed'
: (_l = (_k = errorShape === null || errorShape === void 0 ? void 0 : errorShape.message) !== null && _k !== void 0 ? _k : error.message) !== null && _l !== void 0 ? _l : 'An error occurred', code: error.code, issues: isInputValidationError ? error.cause.errors : undefined });
: ((_l = (_k = errorShape === null || errorShape === void 0 ? void 0 : errorShape.message) !== null && _k !== void 0 ? _k : error.message) !== null && _l !== void 0 ? _l : 'An error occurred'), code: error.code, issues: isInputValidationError ? error.cause.errors : undefined });
sendResponse(statusCode, headers, body);

@@ -146,0 +152,0 @@ }

@@ -1,4 +0,4 @@

import { NodeHTTPRequest } from '@trpc/server/adapters/node-http';
import { NodeHTTPRequest } from '../../types';
export declare const getQuery: (req: NodeHTTPRequest, url: URL) => Record<string, string | string[]>;
export declare const getBody: (req: NodeHTTPRequest, maxBodySize?: number) => Promise<any>;
//# sourceMappingURL=input.d.ts.map
import { TRPC_ERROR_CODE_KEY } from '@trpc/server/rpc';
import type { CreateRootTypes, Procedure, ProcedureType, Router, RouterRecord } from '@trpc/server/unstable-core-do-not-import';
import { IncomingMessage } from 'http';
import type { AnyZodObject, ZodIssue } from 'zod';

@@ -43,2 +44,6 @@ export { type OpenAPIObject, type SecuritySchemeObject } from 'openapi3-ts/oas31';

export type OpenApiResponse<D = any> = OpenApiSuccessResponse<D> | OpenApiErrorResponse;
export type NodeHTTPRequest = IncomingMessage & {
body?: unknown;
query?: unknown;
};
//# sourceMappingURL=types.d.ts.map

@@ -1,3 +0,6 @@

import { OpenApiMethod } from '../types';
import { NodeHTTPResponse } from '@trpc/server/adapters/node-http';
import { NodeHTTPRequest, OpenApiMethod } from '../types';
export declare const acceptsRequestBody: (method: OpenApiMethod | "HEAD") => boolean;
export declare const getContentType: (req: NodeHTTPRequest | Request) => string | undefined;
export declare const getRequestSignal: (req: NodeHTTPRequest | Request, res: NodeHTTPResponse, maxBodySize?: number) => AbortSignal;
//# sourceMappingURL=method.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.acceptsRequestBody = void 0;
exports.getRequestSignal = exports.getContentType = exports.acceptsRequestBody = void 0;
const node_http_1 = require("@trpc/server/adapters/node-http");
const acceptsRequestBody = (method) => {

@@ -11,2 +12,19 @@ if (method === 'GET' || method === 'DELETE') {

exports.acceptsRequestBody = acceptsRequestBody;
const getContentType = (req) => {
var _a, _b;
if (req instanceof Request) {
return (_a = req.headers.get('content-type')) !== null && _a !== void 0 ? _a : undefined;
}
return (_b = req.headers['content-type']) !== null && _b !== void 0 ? _b : undefined;
};
exports.getContentType = getContentType;
const getRequestSignal = (req, res, maxBodySize) => {
if (req instanceof Request) {
return req.signal;
}
return (0, node_http_1.incomingMessageToRequest)(req, res, {
maxBodySize: maxBodySize !== null && maxBodySize !== void 0 ? maxBodySize : null,
}).signal;
};
exports.getRequestSignal = getRequestSignal;
//# sourceMappingURL=method.js.map

@@ -1,2 +0,3 @@

import { type NodeHTTPHandlerOptions, type NodeHTTPRequest, type NodeHTTPResponse } from '@trpc/server/adapters/node-http';
import { type NodeHTTPHandlerOptions, type NodeHTTPResponse } from '@trpc/server/adapters/node-http';
import { NodeHTTPRequest } from '../../types';
import { OpenApiRouter } from '../../types';

@@ -3,0 +4,0 @@ export type CreateOpenApiNodeHttpHandlerOptions<TRouter extends OpenApiRouter, TRequest extends NodeHTTPRequest, TResponse extends NodeHTTPResponse> = Pick<NodeHTTPHandlerOptions<TRouter, TRequest, TResponse>, 'router' | 'createContext' | 'responseMeta' | 'onError' | 'maxBodySize'>;

@@ -1,4 +0,4 @@

import { NodeHTTPRequest } from '@trpc/server/adapters/node-http';
import { NodeHTTPRequest } from '../../types';
export declare const getQuery: (req: NodeHTTPRequest, url: URL) => Record<string, string | string[]>;
export declare const getBody: (req: NodeHTTPRequest, maxBodySize?: number) => Promise<any>;
//# sourceMappingURL=input.d.ts.map
import { TRPC_ERROR_CODE_KEY } from '@trpc/server/rpc';
import type { CreateRootTypes, Procedure, ProcedureType, Router, RouterRecord } from '@trpc/server/unstable-core-do-not-import';
import { IncomingMessage } from 'http';
import type { AnyZodObject, ZodIssue } from 'zod';

@@ -43,2 +44,6 @@ export { type OpenAPIObject, type SecuritySchemeObject } from 'openapi3-ts/oas31';

export type OpenApiResponse<D = any> = OpenApiSuccessResponse<D> | OpenApiErrorResponse;
export type NodeHTTPRequest = IncomingMessage & {
body?: unknown;
query?: unknown;
};
//# sourceMappingURL=types.d.ts.map

@@ -1,3 +0,6 @@

import { OpenApiMethod } from '../types';
import { NodeHTTPResponse } from '@trpc/server/adapters/node-http';
import { NodeHTTPRequest, OpenApiMethod } from '../types';
export declare const acceptsRequestBody: (method: OpenApiMethod | "HEAD") => boolean;
export declare const getContentType: (req: NodeHTTPRequest | Request) => string | undefined;
export declare const getRequestSignal: (req: NodeHTTPRequest | Request, res: NodeHTTPResponse, maxBodySize?: number) => AbortSignal;
//# sourceMappingURL=method.d.ts.map
{
"name": "trpc-to-openapi",
"version": "2.1.5",
"version": "2.2.0",
"description": "tRPC OpenAPI",

@@ -52,13 +52,13 @@ "author": "mcampa",

"peerDependencies": {
"@trpc/server": "^11.0.0-rc.648",
"@trpc/server": "^11.1.0",
"zod": "^3.23.8",
"zod-openapi": "^4.1.0"
"zod-openapi": "4.2.4"
},
"dependencies": {
"co-body": "^6.1.0",
"h3": "^1.6.4",
"co-body": "6.2.0",
"h3": "1.15.1",
"openapi3-ts": "4.4.0"
},
"devDependencies": {
"@trpc/client": "^11.0.0-rc.648",
"@trpc/client": "^11.1.0",
"@types/aws-lambda": "^8.10.115",

@@ -69,4 +69,4 @@ "@types/co-body": "^6.1.0",

"@types/koa": "^2.15.0",
"@types/node": "^20.2.3",
"@types/node-fetch": "^2.6.4",
"@types/node": "^22",
"@types/node-fetch": "^2.6.12",
"@typescript-eslint/eslint-plugin": "^7.18.0",

@@ -80,3 +80,3 @@ "@typescript-eslint/parser": "^7.18.0",

"koa": "^2.15.3",
"next": "^14.2.10",
"next": "^15.3.1",
"node-fetch": "^2.6.11",

@@ -90,3 +90,4 @@ "node-mocks-http": "^1.12.2",

"ts-node": "^10.9.1",
"typescript": "5.7.2"
"typescript": "5.7.2",
"zod-openapi": "4.2.4"
},

@@ -93,0 +94,0 @@ "optionalDependencies": {

@@ -14,3 +14,3 @@ <p align="center">

- tRPC ^11.0.0-rc.648 only πŸ‘ˆ
- Support for tRPC ^11.1.0
- Easy REST endpoints for your tRPC procedures.

@@ -17,0 +17,0 @@ - Perfect for incremental adoption.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet