diff --git a/docs/docs/snippets/middlewares/custom-endpoint-decorator-accept-mime.ts b/docs/docs/snippets/middlewares/custom-endpoint-decorator-accept-mime.ts index 60dc0c32a8e..45158221c11 100644 --- a/docs/docs/snippets/middlewares/custom-endpoint-decorator-accept-mime.ts +++ b/docs/docs/snippets/middlewares/custom-endpoint-decorator-accept-mime.ts @@ -1,8 +1,8 @@ import {AcceptMimesMiddleware, UseBefore} from "@tsed/common"; -import {applyDecorators, StoreSet} from "@tsed/core"; +import {useDecorators, StoreSet} from "@tsed/core"; export function AcceptMime(...mimes: string[]): Function { - return applyDecorators( + return useDecorators( StoreSet(AcceptMimesMiddleware, mimes), UseBefore(AcceptMimesMiddleware) ); diff --git a/docs/docs/snippets/middlewares/custom-endpoint-decorator-status.ts b/docs/docs/snippets/middlewares/custom-endpoint-decorator-status.ts index 6b7f22436d1..ff63759e857 100644 --- a/docs/docs/snippets/middlewares/custom-endpoint-decorator-status.ts +++ b/docs/docs/snippets/middlewares/custom-endpoint-decorator-status.ts @@ -1,8 +1,8 @@ import {UseAfter} from "@tsed/common"; -import {applyDecorators} from "@tsed/core"; +import {useDecorators} from "@tsed/core"; export function CustomStatus(code: number) { - return applyDecorators( + return useDecorators( UseAfter((req: any, res: any, next: any) => { res.status(code); next(); diff --git a/docs/docs/snippets/pipes/pipes-decorator-with-options.ts b/docs/docs/snippets/pipes/pipes-decorator-with-options.ts index 091d00b8eac..a343843cad8 100644 --- a/docs/docs/snippets/pipes/pipes-decorator-with-options.ts +++ b/docs/docs/snippets/pipes/pipes-decorator-with-options.ts @@ -1,5 +1,5 @@ import {RawPathParams, UsePipe} from "@tsed/common"; -import {applyDecorators} from "@tsed/core"; +import {useDecorators} from "@tsed/core"; import {PersonPipe} from "../services/PersonPipe"; export interface IUsePersonParamOptions { @@ -7,7 +7,7 @@ export interface IUsePersonParamOptions { } export function UsePersonParam(expression: string, options: IUsePersonParamOptions = {}): ParameterDecorator { - return applyDecorators( + return useDecorators( RawPathParams(expression), UsePipe(PersonPipe, options) // UsePipe accept second parameter to store your options ); diff --git a/docs/docs/snippets/pipes/pipes-decorator.ts b/docs/docs/snippets/pipes/pipes-decorator.ts index 8aca4c64c10..bab6c4a903e 100644 --- a/docs/docs/snippets/pipes/pipes-decorator.ts +++ b/docs/docs/snippets/pipes/pipes-decorator.ts @@ -1,9 +1,9 @@ import {RawPathParams, UsePipe} from "@tsed/common"; -import {applyDecorators} from "@tsed/core"; +import {useDecorators} from "@tsed/core"; import {PersonPipe} from "../services/PersonPipe"; export function UsePersonParam(expression: string): ParameterDecorator { - return applyDecorators( + return useDecorators( RawPathParams(expression), UsePipe(PersonPipe) ); diff --git a/docs/docs/snippets/pipes/use-params.ts b/docs/docs/snippets/pipes/use-params.ts index be733c58fbf..54fb0daaebe 100644 --- a/docs/docs/snippets/pipes/use-params.ts +++ b/docs/docs/snippets/pipes/use-params.ts @@ -4,13 +4,13 @@ import { UseDeserialization, UseParamExpression, UseParamType, + UseType, UseValidation } from "@tsed/common"; -import {UseType} from "@tsed/common"; -import {applyDecorators} from "@tsed/core"; +import {useDecorators} from "@tsed/core"; export function UseParam(paramType: ParamTypes | string, options: IParamOptions = {}): ParameterDecorator { - return applyDecorators( + return useDecorators( UseParamType(paramType), options.useType && UseType(options.useType), options.expression && UseParamExpression(options.expression), diff --git a/packages/core/src/interfaces/HashOf.ts b/packages/core/src/interfaces/HashOf.ts index 1955996fdae..43fce2e6094 100644 --- a/packages/core/src/interfaces/HashOf.ts +++ b/packages/core/src/interfaces/HashOf.ts @@ -1 +1 @@ -export type HashOf = {[key: string]: T}; +export type HashOf = Record; diff --git a/packages/core/src/utils/applyBefore.spec.ts b/packages/core/src/utils/applyBefore.spec.ts deleted file mode 100644 index a0988a8f39f..00000000000 --- a/packages/core/src/utils/applyBefore.spec.ts +++ /dev/null @@ -1,21 +0,0 @@ -import {expect} from "chai"; -import Sinon from "sinon"; -import {applyBefore} from "../../src"; - -describe("applyBefore", () => { - it("should override the original method", () => { - const originalMethod = Sinon.stub(); - originalMethod.returns("returns"); - const obj = { - method: originalMethod - }; - const cbStub = Sinon.stub(); - - applyBefore(obj, "method", cbStub); - const result = obj.method("arg", "arg2"); - expect(obj.method).to.not.eq(originalMethod); - expect(cbStub).to.have.been.calledOnce.and.calledWithExactly("arg", "arg2"); - expect(originalMethod).to.have.been.calledOnce.and.calledWithExactly("arg", "arg2"); - expect(result).to.eq("returns"); - }); -}); diff --git a/packages/core/src/utils/applyBefore.ts b/packages/core/src/utils/applyBefore.ts deleted file mode 100644 index b402424c10a..00000000000 --- a/packages/core/src/utils/applyBefore.ts +++ /dev/null @@ -1,16 +0,0 @@ -/** - * - * @param target - * @param {string} name - * @param {Function} callback - * @ignore - * @deprecated - */ -export function applyBefore(target: any, name: string, callback: Function) { - const original = target[name]; - target[name] = function (...args: any[]) { - callback(...args); - - return original.apply(this, args); - }; -} diff --git a/packages/core/src/utils/decorators/decoratorTypeOf.spec.ts b/packages/core/src/utils/decorators/decoratorTypeOf.spec.ts index eb61197be72..a7a73429fb6 100644 --- a/packages/core/src/utils/decorators/decoratorTypeOf.spec.ts +++ b/packages/core/src/utils/decorators/decoratorTypeOf.spec.ts @@ -1,83 +1,9 @@ import {expect} from "chai"; -import {decoratorTypeOf, getDecoratorType} from "./decoratorTypeOf"; +import {decoratorTypeOf} from "./decoratorTypeOf"; class Test {} describe("decoratorTypeOf()", () => { - describe("when short type", () => { - it("should return class", () => { - expect(getDecoratorType([Test])).to.equal("class"); - }); - - it("should return property (static)", () => { - expect(getDecoratorType([Test, "props"])).to.equal("property"); - }); - - it("should return property (instance)", () => { - expect(getDecoratorType([Test.prototype, "props"])).to.equal("property"); - }); - - it("should return method (instance, getter)", () => { - expect( - decoratorTypeOf([ - Test.prototype, - "props", - { - get: () => {} - } - ]) - ).to.equal("property"); - }); - - it("should return method (instance, setter)", () => { - expect( - decoratorTypeOf([ - Test.prototype, - "props", - { - set: () => {} - } - ]) - ).to.equal("property"); - }); - - it("should return method (static)", () => { - expect( - decoratorTypeOf([ - Test, - "props", - { - value: () => {} - } - ]) - ).to.equal("method.static"); - }); - - it("should return method (instance)", () => { - expect( - decoratorTypeOf([ - Test.prototype, - "props", - { - value: () => {} - } - ]) - ).to.equal("method"); - }); - - it("should return params (static)", () => { - expect(decoratorTypeOf([Test, "props", 0])).to.equal("parameter.static"); - }); - - it("should return params (instance)", () => { - expect(decoratorTypeOf([Test.prototype, "props", 0])).to.equal("parameter"); - }); - - it("should return params (constructor)", () => { - expect(decoratorTypeOf([Test.prototype, undefined, 0])).to.equal("parameter.constructor"); - }); - }); - it("should return class", () => { expect(decoratorTypeOf([Test])).to.equal("class"); }); diff --git a/packages/core/src/utils/decorators/decoratorTypeOf.ts b/packages/core/src/utils/decorators/decoratorTypeOf.ts index 94e365bec8a..cb7b1aee9bb 100644 --- a/packages/core/src/utils/decorators/decoratorTypeOf.ts +++ b/packages/core/src/utils/decorators/decoratorTypeOf.ts @@ -1,15 +1,6 @@ import {DecoratorTypes} from "../../domain/DecoratorTypes"; import {classOf} from "../objects/classOf"; -/** - * @deprecated Since 2020-11-28. Use decoratorTypeOf function. - */ -export function getDecoratorType(args: any[], longType = false): DecoratorTypes { - const type = decoratorTypeOf(args); - - return longType ? type : ((type as string).split(".")[0] as any); -} - export function decoratorTypeOf(args: any[]): DecoratorTypes { const [target, propertyKey, descriptor] = args; diff --git a/packages/core/src/utils/decorators/useDecorators.spec.ts b/packages/core/src/utils/decorators/useDecorators.spec.ts index 65efb439e9c..2d59fe01f2b 100644 --- a/packages/core/src/utils/decorators/useDecorators.spec.ts +++ b/packages/core/src/utils/decorators/useDecorators.spec.ts @@ -1,4 +1,4 @@ -import {applyDecorators, Store, StoreFn, useDecorators} from "@tsed/core"; +import {Store, StoreFn, useDecorators} from "@tsed/core"; import {expect} from "chai"; import {AnyDecorator} from "../../interfaces/AnyDecorator"; @@ -27,29 +27,3 @@ describe("useDecorators", () => { expect(Store.from(Test).get("decorator2")).to.eq("test2"); }); }); - -describe("applyDecorators", () => { - function decorator1(value: any) { - return StoreFn((store) => { - store.set("decorator1", value); - }); - } - - function decorator2(value: any) { - return StoreFn((store) => { - store.set("decorator2", value); - }); - } - - function decorate() { - return applyDecorators(decorator1("test1"), decorator2("test2")); - } - - @decorate() - class Test {} - - it("should apply all decorators", () => { - expect(Store.from(Test).get("decorator1")).to.eq("test1"); - expect(Store.from(Test).get("decorator2")).to.eq("test2"); - }); -}); diff --git a/packages/core/src/utils/decorators/useDecorators.ts b/packages/core/src/utils/decorators/useDecorators.ts index 3474d125a37..2f852b83def 100644 --- a/packages/core/src/utils/decorators/useDecorators.ts +++ b/packages/core/src/utils/decorators/useDecorators.ts @@ -1,15 +1,6 @@ import {DecoratorParameters} from "../../interfaces/DecoratorParameters"; import {AnyDecorator} from "../../interfaces/AnyDecorator"; -/** - * @deprecated Since 2020-11-28. Use useDecorators function. - * @param decorators - * @ignore - */ -export function applyDecorators(...decorators: (any | ClassDecorator | MethodDecorator | PropertyDescriptor | ParameterDecorator)[]): any { - return useDecorators(...decorators); -} - export function useDecorators(...decorators: AnyDecorator[]): any { return (...args: DecoratorParameters) => { decorators diff --git a/packages/core/src/utils/index.ts b/packages/core/src/utils/index.ts index 204c599645a..53b43b55cdf 100644 --- a/packages/core/src/utils/index.ts +++ b/packages/core/src/utils/index.ts @@ -1,4 +1,3 @@ -export * from "./applyBefore"; export * from "./catchError"; export * from "./proxyDelegation"; export * from "./uniq"; diff --git a/packages/core/src/utils/objects/deepExtends.ts b/packages/core/src/utils/objects/deepExtends.ts index 1db511669ca..a8199822642 100644 --- a/packages/core/src/utils/objects/deepExtends.ts +++ b/packages/core/src/utils/objects/deepExtends.ts @@ -1,10 +1,9 @@ -import {HashOf} from "../../interfaces/HashOf"; import {classOf} from "./classOf"; import {isArrayOrArrayClass} from "./isArray"; import {isPrimitive} from "./isPrimitive"; import {objectKeys} from "./objectKeys"; -export type DeepExtendsReducers = HashOf<(collection: any[], value: any) => any>; +export type DeepExtendsReducers = Record any>; function reducer() { return (collection: any[], value: any) => { diff --git a/packages/schema/src/domain/JsonResponse.ts b/packages/schema/src/domain/JsonResponse.ts index 934fd3a2568..12349b640bc 100644 --- a/packages/schema/src/domain/JsonResponse.ts +++ b/packages/schema/src/domain/JsonResponse.ts @@ -1,4 +1,4 @@ -import {cleanObject, HashOf} from "@tsed/core"; +import {cleanObject} from "@tsed/core"; import {OS3MediaType, OS3Response} from "@tsed/openspec"; import {JsonHeader, JsonSchemaOptions} from "../interfaces"; import {mapHeaders} from "../utils/mapHeaders"; @@ -44,13 +44,13 @@ export class JsonResponse extends JsonMap { return this; } - headers(headers: HashOf): this { + headers(headers: Record): this { this.set("headers", mapHeaders(headers)); return this; } - content(content: HashOf>) { + content(content: Record>) { this.set("content", toJsonMapCollection(content, JsonMedia)); return this;