Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ts-rest/nest

Package Overview
Dependencies
Maintainers
1
Versions
126
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ts-rest/nest - npm Package Compare versions

Comparing version 3.20.0 to 3.21.0

index.mjs

79

index.js

@@ -1,6 +0,10 @@

import { SetMetadata, Injectable, UseInterceptors, applyDecorators, Put, Patch, Post, Get, Delete, createParamDecorator, BadRequestException } from '@nestjs/common';
import { map } from 'rxjs';
import { isAppRouteResponse, validateResponse, checkZodSchema, zodErrorResponse, parseJsonQueryObject } from '@ts-rest/core';
import { Reflector } from '@nestjs/core';
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var common = require('@nestjs/common');
var rxjs = require('rxjs');
var core = require('@ts-rest/core');
var core$1 = require('@nestjs/core');
const TsRestAppRouteMetadataKey = Symbol('ts-rest-app-route');

@@ -11,3 +15,3 @@ const JsonQuerySymbol = Symbol('ts-rest-json-query');

const JsonQuery = (jsonQuery = true) => {
return SetMetadata(JsonQuerySymbol, jsonQuery);
return common.SetMetadata(JsonQuerySymbol, jsonQuery);
};

@@ -53,3 +57,3 @@

let TsRestInterceptor = class TsRestInterceptor {
exports.TsRestInterceptor = class TsRestInterceptor {
constructor(reflector) {

@@ -65,6 +69,6 @@ this.reflector = reflector;

const isValidationEnabled = Boolean(this.reflector.getAllAndOverride(ValidateResponsesSymbol, [context.getHandler(), context.getClass()]));
return next.handle().pipe(map((value) => {
if (isAppRouteResponse(value)) {
return next.handle().pipe(rxjs.map((value) => {
if (core.isAppRouteResponse(value)) {
const response = isValidationEnabled
? validateResponse({
? core.validateResponse({
responseType: appRoute.responses[value.status],

@@ -81,6 +85,6 @@ response: value,

};
TsRestInterceptor = __decorate([
Injectable(),
__metadata("design:paramtypes", [Reflector])
], TsRestInterceptor);
exports.TsRestInterceptor = __decorate([
common.Injectable(),
__metadata("design:paramtypes", [core$1.Reflector])
], exports.TsRestInterceptor);

@@ -93,5 +97,5 @@ const TsRest = (appRouteOrOptions, options = {}) => {

decorators.push(...[
SetMetadata(TsRestAppRouteMetadataKey, appRouteOrOptions),
common.SetMetadata(TsRestAppRouteMetadataKey, appRouteOrOptions),
getMethodDecorator(appRouteOrOptions),
UseInterceptors(TsRestInterceptor),
common.UseInterceptors(exports.TsRestInterceptor),
]);

@@ -103,5 +107,5 @@ }

if (optionsToUse.validateResponses !== undefined) {
decorators.push(SetMetadata(ValidateResponsesSymbol, optionsToUse.validateResponses));
decorators.push(common.SetMetadata(ValidateResponsesSymbol, optionsToUse.validateResponses));
}
return applyDecorators(...decorators);
return common.applyDecorators(...decorators);
};

@@ -111,11 +115,11 @@ const getMethodDecorator = (appRoute) => {

case 'DELETE':
return Delete(appRoute.path);
return common.Delete(appRoute.path);
case 'GET':
return Get(appRoute.path);
return common.Get(appRoute.path);
case 'POST':
return Post(appRoute.path);
return common.Post(appRoute.path);
case 'PATCH':
return Patch(appRoute.path);
return common.Patch(appRoute.path);
case 'PUT':
return Put(appRoute.path);
return common.Put(appRoute.path);
}

@@ -127,3 +131,3 @@ };

const TsRestRequest = createParamDecorator((_, ctx) => {
const TsRestRequest = common.createParamDecorator((_, ctx) => {
var _a;

@@ -135,25 +139,25 @@ const req = ctx.switchToHttp().getRequest();

}
const pathParamsResult = checkZodSchema(req.params, appRoute.pathParams, {
const pathParamsResult = core.checkZodSchema(req.params, appRoute.pathParams, {
passThroughExtraKeys: true,
});
if (!pathParamsResult.success) {
throw new BadRequestException(zodErrorResponse(pathParamsResult.error));
throw new common.BadRequestException(core.zodErrorResponse(pathParamsResult.error));
}
const headersResult = checkZodSchema(req.headers, appRoute.headers, {
const headersResult = core.checkZodSchema(req.headers, appRoute.headers, {
passThroughExtraKeys: true,
});
if (!headersResult.success) {
throw new BadRequestException(zodErrorResponse(headersResult.error));
throw new common.BadRequestException(core.zodErrorResponse(headersResult.error));
}
const isJsonQuery = !!((_a = Reflect.getMetadata(JsonQuerySymbol, ctx.getHandler())) !== null && _a !== void 0 ? _a : Reflect.getMetadata(JsonQuerySymbol, ctx.getClass()));
const query = isJsonQuery
? parseJsonQueryObject(req.query)
? core.parseJsonQueryObject(req.query)
: req.query;
const queryResult = checkZodSchema(query, appRoute.query);
const queryResult = core.checkZodSchema(query, appRoute.query);
if (!queryResult.success) {
throw new BadRequestException(zodErrorResponse(queryResult.error));
throw new common.BadRequestException(core.zodErrorResponse(queryResult.error));
}
const bodyResult = checkZodSchema(req.body, appRoute.method === 'GET' ? null : appRoute.body);
const bodyResult = core.checkZodSchema(req.body, appRoute.method === 'GET' ? null : appRoute.body);
if (!bodyResult.success) {
throw new BadRequestException(zodErrorResponse(bodyResult.error));
throw new common.BadRequestException(core.zodErrorResponse(bodyResult.error));
}

@@ -169,2 +173,11 @@ return {

export { Api, ApiDecorator, JsonQuery, JsonQuerySymbol, TsRest, TsRestAppRouteMetadataKey, TsRestInterceptor, TsRestRequest, ValidateResponsesSymbol, initNestServer, nestControllerContract };
exports.Api = Api;
exports.ApiDecorator = ApiDecorator;
exports.JsonQuery = JsonQuery;
exports.JsonQuerySymbol = JsonQuerySymbol;
exports.TsRest = TsRest;
exports.TsRestAppRouteMetadataKey = TsRestAppRouteMetadataKey;
exports.TsRestRequest = TsRestRequest;
exports.ValidateResponsesSymbol = ValidateResponsesSymbol;
exports.initNestServer = initNestServer;
exports.nestControllerContract = nestControllerContract;
{
"name": "@ts-rest/nest",
"version": "3.20.0",
"version": "3.21.0",
"description": "Nest server integration for @ts-rest",

@@ -27,3 +27,3 @@ "license": "MIT",

"zod": "^3.0.0",
"@ts-rest/core": "3.20.0"
"@ts-rest/core": "3.21.0"
},

@@ -39,5 +39,4 @@ "peerDependenciesMeta": {

},
"module": "./index.js",
"main": "./index.cjs",
"type": "module",
"module": "./index.mjs",
"main": "./index.js",
"types": "./src/index.d.ts",

@@ -47,4 +46,4 @@ "exports": {

"types": "./src/index.d.ts",
"import": "./index.js",
"require": "./index.cjs"
"import": "./index.mjs",
"require": "./index.js"
}

@@ -51,0 +50,0 @@ },

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