New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@ts-rest/express

Package Overview
Dependencies
Maintainers
1
Versions
123
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ts-rest/express - npm Package Compare versions

Comparing version 3.6.1 to 3.7.0

6

CHANGELOG.md
# @ts-rest/express
## 3.7.0
### Minor Changes
- d4d9be5: Add support for pathParams Zod verification
## 3.6.1

@@ -4,0 +10,0 @@

4

package.json
{
"name": "@ts-rest/express",
"version": "3.6.1",
"version": "3.7.0",
"peerDependenciesMeta": {

@@ -72,3 +72,3 @@ "zod": {

"vary": "1.1.2",
"@ts-rest/core": "3.6.1",
"@ts-rest/core": "3.7.0",
"@tsd/typescript": "4.7.4",

@@ -75,0 +75,0 @@ "eslint-formatter-pretty": "4.1.0",

/// <reference types="node" />
import { IRouter, Request } from 'express';
import { IncomingHttpHeaders } from 'http';
import { AppRoute, AppRouteMutation, AppRouteQuery, AppRouter, Without, ZodInferOrType, PathParams } from '@ts-rest/core';
import { AppRoute, AppRouteMutation, AppRouteQuery, AppRouter, PathParamsWithCustomValidators, Without, ZodInferOrType } from '@ts-rest/core';
export declare type ApiRouteResponse<T> = {

@@ -12,3 +12,3 @@ [K in keyof T]: {

declare type AppRouteQueryImplementation<T extends AppRouteQuery> = (input: Without<{
params: PathParams<T>;
params: PathParamsWithCustomValidators<T>;
query: ZodInferOrType<T['query']>;

@@ -20,3 +20,3 @@ headers: IncomingHttpHeaders;

declare type AppRouteMutationImplementation<T extends AppRouteMutation> = (input: Without<{
params: PathParams<T>;
params: PathParamsWithCustomValidators<T>;
query: ZodInferOrType<T['query']>;

@@ -23,0 +23,0 @@ body: WithoutFileIfMultiPart<T>;

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

};
const recursivelyApplyExpressRouter = (// eslint-disable-next-line @typescript-eslint/no-explicit-any
router, path, // eslint-disable-next-line @typescript-eslint/no-explicit-any
routeTransformer)=>{
const recursivelyApplyExpressRouter = (router, path, routeTransformer)=>{
if (typeof router === 'object') {

@@ -33,16 +31,18 @@ for(const key in router){

};
const transformAppRouteQueryImplementation = (// eslint-disable-next-line @typescript-eslint/no-explicit-any
route, schema, app)=>{
const transformAppRouteQueryImplementation = (route, schema, app)=>{
console.log(`[ts-rest] Initialized ${schema.method} ${schema.path}`);
app.get(schema.path, async (req, res)=>{
const zodQueryIssues = (0, _core.returnZodErrorsIfZodSchema)(schema.query, req.query);
if (zodQueryIssues.length > 0) {
return res.status(400).json({
errors: zodQueryIssues
});
const queryResult = (0, _core.checkZodSchema)(req.query, schema.query);
if (!queryResult.success) {
return res.status(400).send(queryResult.error);
}
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
const paramsResult = (0, _core.checkZodSchema)(req.params, schema.pathParams, {
passThroughExtraKeys: true
});
if (!paramsResult.success) {
return res.status(400).send(paramsResult.error);
}
const result = await route({
params: req.params,
query: req.query,
params: paramsResult.data,
query: queryResult.data,
headers: req.headers,

@@ -54,4 +54,3 @@ req: req

};
const transformAppRouteMutationImplementation = (// eslint-disable-next-line @typescript-eslint/no-explicit-any
route, schema, app)=>{
const transformAppRouteMutationImplementation = (route, schema, app)=>{
console.log(`[ts-rest] Initialized ${schema.method} ${schema.path}`);

@@ -61,20 +60,20 @@ const method = schema.method;

try {
const zodBodyIssues = (0, _core.returnZodErrorsIfZodSchema)(schema.body, req.body);
if (zodBodyIssues.length > 0) {
return res.status(400).json({
errors: zodBodyIssues
});
const queryResult = (0, _core.checkZodSchema)(req.query, schema.query);
if (!queryResult.success) {
return res.status(400).send(queryResult.error);
}
const zodQueryIssues = (0, _core.returnZodErrorsIfZodSchema)(schema.query, req.query);
if (zodQueryIssues.length > 0) {
return res.status(400).json({
errors: zodQueryIssues
});
const bodyResult = (0, _core.checkZodSchema)(req.body, schema.body);
if (!bodyResult.success) {
return res.status(400).send(bodyResult.error);
}
const paramsResult = (0, _core.checkZodSchema)(req.params, schema.pathParams, {
passThroughExtraKeys: true
});
if (!paramsResult.success) {
return res.status(400).send(paramsResult.error);
}
const result = await route({
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
params: req.params,
body: req.body,
query: req.query,
params: paramsResult.data,
body: bodyResult.data,
query: queryResult.data,
headers: req.headers,

@@ -120,4 +119,3 @@ // eslint-disable-next-line @typescript-eslint/ban-ts-comment

} else {
transformAppRouteQueryImplementation(// eslint-disable-next-line @typescript-eslint/no-explicit-any
route, routerViaPath, app);
transformAppRouteQueryImplementation(route, routerViaPath, app);
}

@@ -124,0 +122,0 @@ } else {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc