mirror of
https://github.com/nestjs/nest.git
synced 2026-02-22 23:41:40 +00:00
Compare commits
18 Commits
feat/micro
...
feat/allow
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ab660c7edd | ||
|
|
21279a9c49 | ||
|
|
03a61e9728 | ||
|
|
212d07fcbf | ||
|
|
bdc9b4409a | ||
|
|
397390083f | ||
|
|
fb6025eb76 | ||
|
|
1ed97489e3 | ||
|
|
7de7320550 | ||
|
|
af4e1d0a33 | ||
|
|
e1c1945a45 | ||
|
|
0d5ad26268 | ||
|
|
bc36e3c32a | ||
|
|
5f45310ab6 | ||
|
|
96bf1d9bb7 | ||
|
|
09cfc8279f | ||
|
|
b90e19f15f | ||
|
|
b62b9255cf |
@@ -118,3 +118,66 @@ export const All = createMappingDecorator(RequestMethod.ALL);
|
||||
* @publicApi
|
||||
*/
|
||||
export const Search = createMappingDecorator(RequestMethod.SEARCH);
|
||||
|
||||
/**
|
||||
* Route handler (method) Decorator. Routes Webdav PROPFIND requests to the specified path.
|
||||
*
|
||||
* @see [Routing](https://docs.nestjs.com/controllers#routing)
|
||||
*
|
||||
* @publicApi
|
||||
*/
|
||||
export const Propfind = createMappingDecorator(RequestMethod.PROPFIND);
|
||||
|
||||
/**
|
||||
* Route handler (method) Decorator. Routes Webdav PROPPATCH requests to the specified path.
|
||||
*
|
||||
* @see [Routing](https://docs.nestjs.com/controllers#routing)
|
||||
*
|
||||
* @publicApi
|
||||
*/
|
||||
export const Proppatch = createMappingDecorator(RequestMethod.PROPPATCH);
|
||||
|
||||
/**
|
||||
* Route handler (method) Decorator. Routes Webdav MKCOL requests to the specified path.
|
||||
*
|
||||
* @see [Routing](https://docs.nestjs.com/controllers#routing)
|
||||
*
|
||||
* @publicApi
|
||||
*/
|
||||
export const Mkcol = createMappingDecorator(RequestMethod.MKCOL);
|
||||
|
||||
/**
|
||||
* Route handler (method) Decorator. Routes Webdav COPY requests to the specified path.
|
||||
*
|
||||
* @see [Routing](https://docs.nestjs.com/controllers#routing)
|
||||
*
|
||||
* @publicApi
|
||||
*/
|
||||
export const Copy = createMappingDecorator(RequestMethod.COPY);
|
||||
|
||||
/**
|
||||
* Route handler (method) Decorator. Routes Webdav MOVE requests to the specified path.
|
||||
*
|
||||
* @see [Routing](https://docs.nestjs.com/controllers#routing)
|
||||
*
|
||||
* @publicApi
|
||||
*/
|
||||
export const Move = createMappingDecorator(RequestMethod.MOVE);
|
||||
|
||||
/**
|
||||
* Route handler (method) Decorator. Routes Webdav LOCK requests to the specified path.
|
||||
*
|
||||
* @see [Routing](https://docs.nestjs.com/controllers#routing)
|
||||
*
|
||||
* @publicApi
|
||||
*/
|
||||
export const Lock = createMappingDecorator(RequestMethod.LOCK);
|
||||
|
||||
/**
|
||||
* Route handler (method) Decorator. Routes Webdav UNLOCK requests to the specified path.
|
||||
*
|
||||
* @see [Routing](https://docs.nestjs.com/controllers#routing)
|
||||
*
|
||||
* @publicApi
|
||||
*/
|
||||
export const Unlock = createMappingDecorator(RequestMethod.UNLOCK);
|
||||
|
||||
@@ -13,6 +13,9 @@ export enum HttpStatus {
|
||||
NO_CONTENT = 204,
|
||||
RESET_CONTENT = 205,
|
||||
PARTIAL_CONTENT = 206,
|
||||
MULTI_STATUS = 207,
|
||||
ALREADY_REPORTED = 208,
|
||||
CONTENT_DIFFERENT = 210,
|
||||
AMBIGUOUS = 300,
|
||||
MOVED_PERMANENTLY = 301,
|
||||
FOUND = 302,
|
||||
@@ -41,13 +44,17 @@ export enum HttpStatus {
|
||||
I_AM_A_TEAPOT = 418,
|
||||
MISDIRECTED = 421,
|
||||
UNPROCESSABLE_ENTITY = 422,
|
||||
LOCKED = 423,
|
||||
FAILED_DEPENDENCY = 424,
|
||||
PRECONDITION_REQUIRED = 428,
|
||||
TOO_MANY_REQUESTS = 429,
|
||||
UNRECOVERABLE_ERROR = 456,
|
||||
INTERNAL_SERVER_ERROR = 500,
|
||||
NOT_IMPLEMENTED = 501,
|
||||
BAD_GATEWAY = 502,
|
||||
SERVICE_UNAVAILABLE = 503,
|
||||
GATEWAY_TIMEOUT = 504,
|
||||
HTTP_VERSION_NOT_SUPPORTED = 505,
|
||||
INSUFFICIENT_STORAGE = 507,
|
||||
LOOP_DETECTED = 508,
|
||||
}
|
||||
|
||||
@@ -8,4 +8,11 @@ export enum RequestMethod {
|
||||
OPTIONS,
|
||||
HEAD,
|
||||
SEARCH,
|
||||
PROPFIND,
|
||||
PROPPATCH,
|
||||
MKCOL,
|
||||
COPY,
|
||||
MOVE,
|
||||
LOCK,
|
||||
UNLOCK,
|
||||
}
|
||||
|
||||
@@ -47,6 +47,20 @@ export interface HttpServer<
|
||||
put(path: string, handler: RequestHandler<TRequest, TResponse>): any;
|
||||
patch(handler: RequestHandler<TRequest, TResponse>): any;
|
||||
patch(path: string, handler: RequestHandler<TRequest, TResponse>): any;
|
||||
propfind?(handler: RequestHandler<TRequest, TResponse>): any;
|
||||
propfind?(path: string, handler: RequestHandler<TRequest, TResponse>): any;
|
||||
proppatch?(handler: RequestHandler<TRequest, TResponse>): any;
|
||||
proppatch?(path: string, handler: RequestHandler<TRequest, TResponse>): any;
|
||||
mkcol?(handler: RequestHandler<TRequest, TResponse>): any;
|
||||
mkcol?(path: string, handler: RequestHandler<TRequest, TResponse>): any;
|
||||
copy?(handler: RequestHandler<TRequest, TResponse>): any;
|
||||
copy?(path: string, handler: RequestHandler<TRequest, TResponse>): any;
|
||||
move?(handler: RequestHandler<TRequest, TResponse>): any;
|
||||
move?(path: string, handler: RequestHandler<TRequest, TResponse>): any;
|
||||
lock?(handler: RequestHandler<TRequest, TResponse>): any;
|
||||
lock?(path: string, handler: RequestHandler<TRequest, TResponse>): any;
|
||||
unlock?(handler: RequestHandler<TRequest, TResponse>): any;
|
||||
unlock?(path: string, handler: RequestHandler<TRequest, TResponse>): any;
|
||||
all(path: string, handler: RequestHandler<TRequest, TResponse>): any;
|
||||
all(handler: RequestHandler<TRequest, TResponse>): any;
|
||||
options(handler: RequestHandler<TRequest, TResponse>): any;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { expect } from 'chai';
|
||||
import { applyDecorators, UseGuards } from '../../decorators';
|
||||
import { GUARDS_METADATA } from '../../constants';
|
||||
import { applyDecorators, UseGuards } from '../../decorators';
|
||||
import { CanActivate } from '../../interfaces';
|
||||
|
||||
describe('applyDecorators', () => {
|
||||
|
||||
@@ -1,7 +1,22 @@
|
||||
import { expect } from 'chai';
|
||||
import { Body, HostParam, Param, Query, Search } from '../../decorators';
|
||||
import { RequestMethod } from '../../enums/request-method.enum';
|
||||
import { All, Delete, Get, ParseIntPipe, Patch, Post, Put } from '../../index';
|
||||
import {
|
||||
All,
|
||||
Delete,
|
||||
Get,
|
||||
ParseIntPipe,
|
||||
Patch,
|
||||
Post,
|
||||
Put,
|
||||
Propfind,
|
||||
Proppatch,
|
||||
Mkcol,
|
||||
Move,
|
||||
Copy,
|
||||
Lock,
|
||||
Unlock,
|
||||
} from '../../index';
|
||||
import { ROUTE_ARGS_METADATA } from '../../constants';
|
||||
import { RouteParamtypes } from '../../enums/route-paramtypes.enum';
|
||||
|
||||
@@ -415,3 +430,409 @@ describe('Inheritance', () => {
|
||||
expect(methodUsingArray).to.be.eql(requestPropsUsingArray.method);
|
||||
});
|
||||
});
|
||||
|
||||
describe('@PropFind', () => {
|
||||
const requestPath = 'test';
|
||||
const requestProps = {
|
||||
path: requestPath,
|
||||
method: RequestMethod.PROPFIND,
|
||||
};
|
||||
|
||||
const requestPathUsingArray = ['foo', 'bar'];
|
||||
const requestPropsUsingArray = {
|
||||
path: requestPathUsingArray,
|
||||
method: RequestMethod.PROPFIND,
|
||||
};
|
||||
|
||||
it('should enhance class with expected request metadata', () => {
|
||||
class Test {
|
||||
@Propfind(requestPath)
|
||||
public static test() {}
|
||||
|
||||
@Propfind(requestPathUsingArray)
|
||||
public static testUsingArray() {}
|
||||
}
|
||||
|
||||
const path = Reflect.getMetadata('path', Test.test);
|
||||
const method = Reflect.getMetadata('method', Test.test);
|
||||
const pathUsingArray = Reflect.getMetadata('path', Test.testUsingArray);
|
||||
const methodUsingArray = Reflect.getMetadata('method', Test.testUsingArray);
|
||||
|
||||
expect(path).to.be.eql(requestPath);
|
||||
expect(method).to.be.eql(requestProps.method);
|
||||
expect(pathUsingArray).to.be.eql(requestPathUsingArray);
|
||||
expect(methodUsingArray).to.be.eql(requestPropsUsingArray.method);
|
||||
});
|
||||
|
||||
it('should set path on "/" by default', () => {
|
||||
class Test {
|
||||
@Propfind()
|
||||
public static test(
|
||||
@Query() query,
|
||||
@Param() params,
|
||||
@HostParam() hostParams,
|
||||
) {}
|
||||
|
||||
@Propfind([])
|
||||
public static testUsingArray(
|
||||
@Query() query,
|
||||
@Param() params,
|
||||
@HostParam() hostParams,
|
||||
) {}
|
||||
}
|
||||
|
||||
const path = Reflect.getMetadata('path', Test.test);
|
||||
const pathUsingArray = Reflect.getMetadata('path', Test.testUsingArray);
|
||||
|
||||
expect(path).to.be.eql('/');
|
||||
expect(pathUsingArray).to.be.eql('/');
|
||||
});
|
||||
});
|
||||
|
||||
describe('@PropPatch', () => {
|
||||
const requestPath = 'test';
|
||||
const requestProps = {
|
||||
path: requestPath,
|
||||
method: RequestMethod.PROPPATCH,
|
||||
};
|
||||
|
||||
const requestPathUsingArray = ['foo', 'bar'];
|
||||
const requestPropsUsingArray = {
|
||||
path: requestPathUsingArray,
|
||||
method: RequestMethod.PROPPATCH,
|
||||
};
|
||||
|
||||
it('should enhance class with expected request metadata', () => {
|
||||
class Test {
|
||||
@Proppatch(requestPath)
|
||||
public static test() {}
|
||||
|
||||
@Proppatch(requestPathUsingArray)
|
||||
public static testUsingArray() {}
|
||||
}
|
||||
|
||||
const path = Reflect.getMetadata('path', Test.test);
|
||||
const method = Reflect.getMetadata('method', Test.test);
|
||||
const pathUsingArray = Reflect.getMetadata('path', Test.testUsingArray);
|
||||
const methodUsingArray = Reflect.getMetadata('method', Test.testUsingArray);
|
||||
|
||||
expect(path).to.be.eql(requestPath);
|
||||
expect(method).to.be.eql(requestProps.method);
|
||||
expect(pathUsingArray).to.be.eql(requestPathUsingArray);
|
||||
expect(methodUsingArray).to.be.eql(requestPropsUsingArray.method);
|
||||
});
|
||||
|
||||
it('should set path on "/" by default', () => {
|
||||
class Test {
|
||||
@Proppatch()
|
||||
public static test(
|
||||
@Query() query,
|
||||
@Param() params,
|
||||
@HostParam() hostParams,
|
||||
) {}
|
||||
|
||||
@Proppatch([])
|
||||
public static testUsingArray(
|
||||
@Query() query,
|
||||
@Param() params,
|
||||
@HostParam() hostParams,
|
||||
) {}
|
||||
}
|
||||
|
||||
const path = Reflect.getMetadata('path', Test.test);
|
||||
const pathUsingArray = Reflect.getMetadata('path', Test.testUsingArray);
|
||||
|
||||
expect(path).to.be.eql('/');
|
||||
expect(pathUsingArray).to.be.eql('/');
|
||||
});
|
||||
});
|
||||
|
||||
describe('@MkCol', () => {
|
||||
const requestPath = 'test';
|
||||
const requestProps = {
|
||||
path: requestPath,
|
||||
method: RequestMethod.MKCOL,
|
||||
};
|
||||
|
||||
const requestPathUsingArray = ['foo', 'bar'];
|
||||
const requestPropsUsingArray = {
|
||||
path: requestPathUsingArray,
|
||||
method: RequestMethod.MKCOL,
|
||||
};
|
||||
|
||||
it('should enhance class with expected request metadata', () => {
|
||||
class Test {
|
||||
@Mkcol(requestPath)
|
||||
public static test() {}
|
||||
|
||||
@Mkcol(requestPathUsingArray)
|
||||
public static testUsingArray() {}
|
||||
}
|
||||
|
||||
const path = Reflect.getMetadata('path', Test.test);
|
||||
const method = Reflect.getMetadata('method', Test.test);
|
||||
const pathUsingArray = Reflect.getMetadata('path', Test.testUsingArray);
|
||||
const methodUsingArray = Reflect.getMetadata('method', Test.testUsingArray);
|
||||
|
||||
expect(path).to.be.eql(requestPath);
|
||||
expect(method).to.be.eql(requestProps.method);
|
||||
expect(pathUsingArray).to.be.eql(requestPathUsingArray);
|
||||
expect(methodUsingArray).to.be.eql(requestPropsUsingArray.method);
|
||||
});
|
||||
|
||||
it('should set path on "/" by default', () => {
|
||||
class Test {
|
||||
@Mkcol()
|
||||
public static test(
|
||||
@Query() query,
|
||||
@Param() params,
|
||||
@HostParam() hostParams,
|
||||
) {}
|
||||
|
||||
@Mkcol([])
|
||||
public static testUsingArray(
|
||||
@Query() query,
|
||||
@Param() params,
|
||||
@HostParam() hostParams,
|
||||
) {}
|
||||
}
|
||||
|
||||
const path = Reflect.getMetadata('path', Test.test);
|
||||
const pathUsingArray = Reflect.getMetadata('path', Test.testUsingArray);
|
||||
|
||||
expect(path).to.be.eql('/');
|
||||
expect(pathUsingArray).to.be.eql('/');
|
||||
});
|
||||
});
|
||||
|
||||
describe('@Copy', () => {
|
||||
const requestPath = 'test';
|
||||
const requestProps = {
|
||||
path: requestPath,
|
||||
method: RequestMethod.COPY,
|
||||
};
|
||||
|
||||
const requestPathUsingArray = ['foo', 'bar'];
|
||||
const requestPropsUsingArray = {
|
||||
path: requestPathUsingArray,
|
||||
method: RequestMethod.COPY,
|
||||
};
|
||||
|
||||
it('should enhance class with expected request metadata', () => {
|
||||
class Test {
|
||||
@Copy(requestPath)
|
||||
public static test() {}
|
||||
|
||||
@Copy(requestPathUsingArray)
|
||||
public static testUsingArray() {}
|
||||
}
|
||||
|
||||
const path = Reflect.getMetadata('path', Test.test);
|
||||
const method = Reflect.getMetadata('method', Test.test);
|
||||
const pathUsingArray = Reflect.getMetadata('path', Test.testUsingArray);
|
||||
const methodUsingArray = Reflect.getMetadata('method', Test.testUsingArray);
|
||||
|
||||
expect(path).to.be.eql(requestPath);
|
||||
expect(method).to.be.eql(requestProps.method);
|
||||
expect(pathUsingArray).to.be.eql(requestPathUsingArray);
|
||||
expect(methodUsingArray).to.be.eql(requestPropsUsingArray.method);
|
||||
});
|
||||
|
||||
it('should set path on "/" by default', () => {
|
||||
class Test {
|
||||
@Copy()
|
||||
public static test(
|
||||
@Query() query,
|
||||
@Param() params,
|
||||
@HostParam() hostParams,
|
||||
) {}
|
||||
|
||||
@Copy([])
|
||||
public static testUsingArray(
|
||||
@Query() query,
|
||||
@Param() params,
|
||||
@HostParam() hostParams,
|
||||
) {}
|
||||
}
|
||||
|
||||
const path = Reflect.getMetadata('path', Test.test);
|
||||
const pathUsingArray = Reflect.getMetadata('path', Test.testUsingArray);
|
||||
|
||||
expect(path).to.be.eql('/');
|
||||
expect(pathUsingArray).to.be.eql('/');
|
||||
});
|
||||
});
|
||||
|
||||
describe('@Move', () => {
|
||||
const requestPath = 'test';
|
||||
const requestProps = {
|
||||
path: requestPath,
|
||||
method: RequestMethod.MOVE,
|
||||
};
|
||||
|
||||
const requestPathUsingArray = ['foo', 'bar'];
|
||||
const requestPropsUsingArray = {
|
||||
path: requestPathUsingArray,
|
||||
method: RequestMethod.MOVE,
|
||||
};
|
||||
|
||||
it('should enhance class with expected request metadata', () => {
|
||||
class Test {
|
||||
@Move(requestPath)
|
||||
public static test() {}
|
||||
|
||||
@Move(requestPathUsingArray)
|
||||
public static testUsingArray() {}
|
||||
}
|
||||
|
||||
const path = Reflect.getMetadata('path', Test.test);
|
||||
const method = Reflect.getMetadata('method', Test.test);
|
||||
const pathUsingArray = Reflect.getMetadata('path', Test.testUsingArray);
|
||||
const methodUsingArray = Reflect.getMetadata('method', Test.testUsingArray);
|
||||
|
||||
expect(path).to.be.eql(requestPath);
|
||||
expect(method).to.be.eql(requestProps.method);
|
||||
expect(pathUsingArray).to.be.eql(requestPathUsingArray);
|
||||
expect(methodUsingArray).to.be.eql(requestPropsUsingArray.method);
|
||||
});
|
||||
|
||||
it('should set path on "/" by default', () => {
|
||||
class Test {
|
||||
@Move()
|
||||
public static test(
|
||||
@Query() query,
|
||||
@Param() params,
|
||||
@HostParam() hostParams,
|
||||
) {}
|
||||
|
||||
@Move([])
|
||||
public static testUsingArray(
|
||||
@Query() query,
|
||||
@Param() params,
|
||||
@HostParam() hostParams,
|
||||
) {}
|
||||
}
|
||||
|
||||
const path = Reflect.getMetadata('path', Test.test);
|
||||
const pathUsingArray = Reflect.getMetadata('path', Test.testUsingArray);
|
||||
|
||||
expect(path).to.be.eql('/');
|
||||
expect(pathUsingArray).to.be.eql('/');
|
||||
});
|
||||
});
|
||||
|
||||
describe('@Lock', () => {
|
||||
const requestPath = 'test';
|
||||
const requestProps = {
|
||||
path: requestPath,
|
||||
method: RequestMethod.LOCK,
|
||||
};
|
||||
|
||||
const requestPathUsingArray = ['foo', 'bar'];
|
||||
const requestPropsUsingArray = {
|
||||
path: requestPathUsingArray,
|
||||
method: RequestMethod.LOCK,
|
||||
};
|
||||
|
||||
it('should enhance class with expected request metadata', () => {
|
||||
class Test {
|
||||
@Lock(requestPath)
|
||||
public static test() {}
|
||||
|
||||
@Lock(requestPathUsingArray)
|
||||
public static testUsingArray() {}
|
||||
}
|
||||
|
||||
const path = Reflect.getMetadata('path', Test.test);
|
||||
const method = Reflect.getMetadata('method', Test.test);
|
||||
const pathUsingArray = Reflect.getMetadata('path', Test.testUsingArray);
|
||||
const methodUsingArray = Reflect.getMetadata('method', Test.testUsingArray);
|
||||
|
||||
expect(path).to.be.eql(requestPath);
|
||||
expect(method).to.be.eql(requestProps.method);
|
||||
expect(pathUsingArray).to.be.eql(requestPathUsingArray);
|
||||
expect(methodUsingArray).to.be.eql(requestPropsUsingArray.method);
|
||||
});
|
||||
|
||||
it('should set path on "/" by default', () => {
|
||||
class Test {
|
||||
@Lock()
|
||||
public static test(
|
||||
@Query() query,
|
||||
@Param() params,
|
||||
@HostParam() hostParams,
|
||||
) {}
|
||||
|
||||
@Lock([])
|
||||
public static testUsingArray(
|
||||
@Query() query,
|
||||
@Param() params,
|
||||
@HostParam() hostParams,
|
||||
) {}
|
||||
}
|
||||
|
||||
const path = Reflect.getMetadata('path', Test.test);
|
||||
const pathUsingArray = Reflect.getMetadata('path', Test.testUsingArray);
|
||||
|
||||
expect(path).to.be.eql('/');
|
||||
expect(pathUsingArray).to.be.eql('/');
|
||||
});
|
||||
});
|
||||
|
||||
describe('@Unlock', () => {
|
||||
const requestPath = 'test';
|
||||
const requestProps = {
|
||||
path: requestPath,
|
||||
method: RequestMethod.UNLOCK,
|
||||
};
|
||||
|
||||
const requestPathUsingArray = ['foo', 'bar'];
|
||||
const requestPropsUsingArray = {
|
||||
path: requestPathUsingArray,
|
||||
method: RequestMethod.UNLOCK,
|
||||
};
|
||||
|
||||
it('should enhance class with expected request metadata', () => {
|
||||
class Test {
|
||||
@Unlock(requestPath)
|
||||
public static test() {}
|
||||
|
||||
@Unlock(requestPathUsingArray)
|
||||
public static testUsingArray() {}
|
||||
}
|
||||
|
||||
const path = Reflect.getMetadata('path', Test.test);
|
||||
const method = Reflect.getMetadata('method', Test.test);
|
||||
const pathUsingArray = Reflect.getMetadata('path', Test.testUsingArray);
|
||||
const methodUsingArray = Reflect.getMetadata('method', Test.testUsingArray);
|
||||
|
||||
expect(path).to.be.eql(requestPath);
|
||||
expect(method).to.be.eql(requestProps.method);
|
||||
expect(pathUsingArray).to.be.eql(requestPathUsingArray);
|
||||
expect(methodUsingArray).to.be.eql(requestPropsUsingArray.method);
|
||||
});
|
||||
|
||||
it('should set path on "/" by default', () => {
|
||||
class Test {
|
||||
@Unlock()
|
||||
public static test(
|
||||
@Query() query,
|
||||
@Param() params,
|
||||
@HostParam() hostParams,
|
||||
) {}
|
||||
|
||||
@Unlock([])
|
||||
public static testUsingArray(
|
||||
@Query() query,
|
||||
@Param() params,
|
||||
@HostParam() hostParams,
|
||||
) {}
|
||||
}
|
||||
|
||||
const path = Reflect.getMetadata('path', Test.test);
|
||||
const pathUsingArray = Reflect.getMetadata('path', Test.testUsingArray);
|
||||
|
||||
expect(path).to.be.eql('/');
|
||||
expect(pathUsingArray).to.be.eql('/');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -62,6 +62,48 @@ export abstract class AbstractHttpAdapter<
|
||||
return this.instance.patch(...args);
|
||||
}
|
||||
|
||||
public propfind(handler: RequestHandler);
|
||||
public propfind(path: any, handler: RequestHandler);
|
||||
public propfind(...args: any[]) {
|
||||
return this.instance.propfind(...args);
|
||||
}
|
||||
|
||||
public proppatch(handler: RequestHandler);
|
||||
public proppatch(path: any, handler: RequestHandler);
|
||||
public proppatch(...args: any[]) {
|
||||
return this.instance.proppatch(...args);
|
||||
}
|
||||
|
||||
public mkcol(handler: RequestHandler);
|
||||
public mkcol(path: any, handler: RequestHandler);
|
||||
public mkcol(...args: any[]) {
|
||||
return this.instance.mkcol(...args);
|
||||
}
|
||||
|
||||
public copy(handler: RequestHandler);
|
||||
public copy(path: any, handler: RequestHandler);
|
||||
public copy(...args: any[]) {
|
||||
return this.instance.copy(...args);
|
||||
}
|
||||
|
||||
public move(handler: RequestHandler);
|
||||
public move(path: any, handler: RequestHandler);
|
||||
public move(...args: any[]) {
|
||||
return this.instance.move(...args);
|
||||
}
|
||||
|
||||
public lock(handler: RequestHandler);
|
||||
public lock(path: any, handler: RequestHandler);
|
||||
public lock(...args: any[]) {
|
||||
return this.instance.lock(...args);
|
||||
}
|
||||
|
||||
public unlock(handler: RequestHandler);
|
||||
public unlock(path: any, handler: RequestHandler);
|
||||
public unlock(...args: any[]) {
|
||||
return this.instance.unlock(...args);
|
||||
}
|
||||
|
||||
public all(handler: RequestHandler);
|
||||
public all(path: any, handler: RequestHandler);
|
||||
public all(...args: any[]) {
|
||||
|
||||
@@ -11,6 +11,13 @@ const REQUEST_METHOD_MAP = {
|
||||
[RequestMethod.OPTIONS]: 'options',
|
||||
[RequestMethod.HEAD]: 'head',
|
||||
[RequestMethod.SEARCH]: 'search',
|
||||
[RequestMethod.PROPFIND]: 'propfind',
|
||||
[RequestMethod.PROPPATCH]: 'proppatch',
|
||||
[RequestMethod.MKCOL]: 'mkcol',
|
||||
[RequestMethod.COPY]: 'copy',
|
||||
[RequestMethod.MOVE]: 'move',
|
||||
[RequestMethod.LOCK]: 'lock',
|
||||
[RequestMethod.UNLOCK]: 'unlock',
|
||||
} as const satisfies Record<RequestMethod, keyof HttpServer>;
|
||||
|
||||
export class RouterMethodFactory {
|
||||
|
||||
@@ -14,6 +14,13 @@ describe('RouterMethodFactory', () => {
|
||||
patch: () => {},
|
||||
options: () => {},
|
||||
head: () => {},
|
||||
propfind: () => {},
|
||||
proppatch: () => {},
|
||||
mkcol: () => {},
|
||||
copy: () => {},
|
||||
move: () => {},
|
||||
lock: () => {},
|
||||
unlock: () => {},
|
||||
all: () => {},
|
||||
};
|
||||
beforeEach(() => {
|
||||
@@ -29,6 +36,17 @@ describe('RouterMethodFactory', () => {
|
||||
expect(factory.get(target, RequestMethod.PATCH)).to.equal(target.patch);
|
||||
expect(factory.get(target, RequestMethod.OPTIONS)).to.equal(target.options);
|
||||
expect(factory.get(target, RequestMethod.HEAD)).to.equal(target.head);
|
||||
expect(factory.get(target, RequestMethod.PROPFIND)).to.equal(
|
||||
target.propfind,
|
||||
);
|
||||
expect(factory.get(target, RequestMethod.PROPPATCH)).to.equal(
|
||||
target.proppatch,
|
||||
);
|
||||
expect(factory.get(target, RequestMethod.MKCOL)).to.equal(target.mkcol);
|
||||
expect(factory.get(target, RequestMethod.COPY)).to.equal(target.copy);
|
||||
expect(factory.get(target, RequestMethod.MOVE)).to.equal(target.move);
|
||||
expect(factory.get(target, RequestMethod.LOCK)).to.equal(target.lock);
|
||||
expect(factory.get(target, RequestMethod.UNLOCK)).to.equal(target.unlock);
|
||||
expect(factory.get(target, -1 as any)).to.equal(target.use);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -77,16 +77,18 @@ export class ServerNats<
|
||||
}
|
||||
|
||||
public bindEvents(client: Client) {
|
||||
const queue = this.getOptionsProp(this.options, 'queue');
|
||||
const subscribe = (channel: string) =>
|
||||
const subscribe = (channel: string, queue: string) =>
|
||||
client.subscribe(channel, {
|
||||
queue,
|
||||
callback: this.getMessageHandler(channel).bind(this),
|
||||
});
|
||||
|
||||
const defaultQueue = this.getOptionsProp(this.options, 'queue');
|
||||
const registeredPatterns = [...this.messageHandlers.keys()];
|
||||
for (const channel of registeredPatterns) {
|
||||
const sub = subscribe(channel);
|
||||
const handlerRef = this.messageHandlers.get(channel);
|
||||
const queue = handlerRef.extras?.queue ?? defaultQueue;
|
||||
const sub = subscribe(channel, queue);
|
||||
this.subscriptions.push(sub);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,11 +113,26 @@ describe('ServerNats', () => {
|
||||
[pattern]: messageHandler,
|
||||
});
|
||||
});
|
||||
it('should subscribe to each acknowledge patterns', () => {
|
||||
|
||||
it('should subscribe to every pattern', () => {
|
||||
server.bindEvents(natsClient);
|
||||
expect(subscribeSpy.calledWith(pattern)).to.be.true;
|
||||
});
|
||||
|
||||
it('should use a per pattern queue if provided', () => {
|
||||
const queue = 'test';
|
||||
untypedServer.messageHandlers = objectToMap({
|
||||
[pattern]: Object.assign(messageHandler, {
|
||||
extras: {
|
||||
queue,
|
||||
},
|
||||
}),
|
||||
});
|
||||
server.bindEvents(natsClient);
|
||||
const lastCall = subscribeSpy.lastCall;
|
||||
expect(lastCall.args[1].queue).to.be.eql(queue);
|
||||
});
|
||||
|
||||
it('should fill the subscriptions array properly', () => {
|
||||
server.bindEvents(natsClient);
|
||||
expect(server['subscriptions'].length).to.be.equals(1);
|
||||
|
||||
@@ -320,6 +320,34 @@ export class FastifyAdapter<
|
||||
return this.injectRouteOptions('SEARCH', ...args);
|
||||
}
|
||||
|
||||
public propfind(...args: any[]) {
|
||||
return this.injectRouteOptions('PROPFIND', ...args);
|
||||
}
|
||||
|
||||
public proppatch(...args: any[]) {
|
||||
return this.injectRouteOptions('PROPPATCH', ...args);
|
||||
}
|
||||
|
||||
public mkcol(...args: any[]) {
|
||||
return this.injectRouteOptions('MKCOL', ...args);
|
||||
}
|
||||
|
||||
public copy(...args: any[]) {
|
||||
return this.injectRouteOptions('COPY', ...args);
|
||||
}
|
||||
|
||||
public move(...args: any[]) {
|
||||
return this.injectRouteOptions('MOVE', ...args);
|
||||
}
|
||||
|
||||
public lock(...args: any[]) {
|
||||
return this.injectRouteOptions('LOCK', ...args);
|
||||
}
|
||||
|
||||
public unlock(...args: any[]) {
|
||||
return this.injectRouteOptions('UNLOCK', ...args);
|
||||
}
|
||||
|
||||
public applyVersionFilter(
|
||||
handler: Function,
|
||||
version: VersionValue,
|
||||
|
||||
@@ -18,17 +18,17 @@
|
||||
"access": "public"
|
||||
},
|
||||
"dependencies": {
|
||||
"@fastify/cors": "9.0.1",
|
||||
"@fastify/formbody": "7.4.0",
|
||||
"@fastify/middie": "8.3.3",
|
||||
"fastify": "4.28.1",
|
||||
"light-my-request": "6.1.0",
|
||||
"@fastify/cors": "10.0.1",
|
||||
"@fastify/formbody": "8.0.1",
|
||||
"@fastify/middie": "9.0.2",
|
||||
"fastify": "5.1.0",
|
||||
"light-my-request": "6.3.0",
|
||||
"path-to-regexp": "3.3.0",
|
||||
"tslib": "2.7.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@fastify/static": "^6.0.0 || ^7.0.0",
|
||||
"@fastify/view": "^7.0.0 || ^8.0.0",
|
||||
"@fastify/static": "^6.0.0 || ^7.0.0 || ^8.0.0",
|
||||
"@fastify/view": "^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0",
|
||||
"@nestjs/common": "^10.0.0",
|
||||
"@nestjs/core": "^10.0.0"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user