From ae4be987eec6a109ff99f59f5f47915c3e58a415 Mon Sep 17 00:00:00 2001 From: Romain Lenzotti Date: Sat, 2 Apr 2022 17:07:04 +0200 Subject: [PATCH] feat: remove ConverterService usage in the codebase --- docs/docs/configuration.md | 15 +- docs/docs/platform-api.md | 6 +- docs/docs/serve-files.md | 6 +- .../modulev0-endpoint-versionning.ts | 4 +- .../modulev1-endpoint-versionning.ts | 4 +- .../server-endpoint-versionning.ts | 15 +- .../configuration/server-resolvers.ts | 4 - docs/docs/snippets/configuration/server.ts | 5 +- docs/tutorials/passport.md | 2 +- packages/orm/adapters-redis/package.json | 4 +- .../src/adapters/RedisAdapter.ts | 3 +- .../services/PlatformResponseFilter.spec.ts | 2 + .../src/services/PlatformResponseFilter.ts | 15 +- .../platform-serverless-http/readme.md | 2 +- .../src/class/SocketHandlersBuilder.spec.ts | 132 +++++++----------- .../src/class/SocketHandlersBuilder.ts | 11 +- .../src/services/SocketIOService.spec.ts | 85 ++++++----- .../socketio/src/services/SocketIOService.ts | 5 +- .../ConverterUserSocketMiddleware.ts | 8 +- packages/third-parties/stripe/readme.md | 3 +- yarn.lock | 2 +- 21 files changed, 151 insertions(+), 182 deletions(-) diff --git a/docs/docs/configuration.md b/docs/docs/configuration.md index a88cd5e40dc..2082b0b650a 100644 --- a/docs/docs/configuration.md +++ b/docs/docs/configuration.md @@ -16,16 +16,11 @@ The default configuration is as follows: ```json { - "rootDir": "path/to/root/project", "env": "development", "port": 8080, "debug": false, "httpsPort": 8000, - "uploadDir": "${rootDir}/uploads", - "mount": { - "/rest": "${rootDir}/controllers/**/*.ts" - }, - "componentsScan": ["${rootDir}/middlewares/**/*.ts", "${rootDir}/services/**/*.ts", "${rootDir}/converters/**/*.ts"] + "uploadDir": "./uploads" } ``` @@ -159,11 +154,11 @@ It is also possible to split the configuration by using the @@Module@@: -### componentsScan +### ~~componentsScan~~ (deprecated) - type: `string[]` -List of glob pattern to scan directories which contains [Services](/docs/services.md), [Middlewares](/docs/middlewares.md) or [Converters](/docs/converters.md). +List of glob pattern to scan directories which contains [Services](/docs/services.md) or [Middlewares](/docs/middlewares.md). ### middlewares @@ -252,7 +247,7 @@ Add providers or modules here. These modules or provider will be built before th -### exclude +### ~~exclude~~ (deprecated) - type: `string[]` @@ -298,7 +293,7 @@ It's also possible to register resolvers with the @@Module@@ decorator: ### views -Object to configure Views engines with Consolidate. See more on [View engine](/docs/templating.md). +Object to configure Views engines with Ts.ED engines or Consolidate (deprecated). See more on [View engine](/docs/templating.md). ### acceptMimes diff --git a/docs/docs/platform-api.md b/docs/docs/platform-api.md index 031545fdacf..4cb1348425a 100644 --- a/docs/docs/platform-api.md +++ b/docs/docs/platform-api.md @@ -37,8 +37,8 @@ import compress from "compression"; import cookieParser from "cookie-parser"; import methodOverride from "method-override"; -@ServerSettings({ - viewsDir: `${rootDir}/views` +@Configuration({ + viewsDir: `${process.cwd()}/views` }) export class Server extends ServerLoader { $beforeRoutesInit() { @@ -73,7 +73,7 @@ import methodOverride from "method-override"; @Configuration({ views: { - root: `${rootDir}/views`, + root: `${process.cwd()}/views`, viewEngine: "ejs" } }) diff --git a/docs/docs/serve-files.md b/docs/docs/serve-files.md index 602d39514f5..61b96f96b1d 100644 --- a/docs/docs/serve-files.md +++ b/docs/docs/serve-files.md @@ -81,18 +81,20 @@ Since v6.74.0, it's possible to load statics before controllers instead of loadi Just use the options `hook` to change the default behavior: ```typescript +import * as process from "process"; + @Configuration({ statics: { "/before": [ { - root: `${rootDir}/public`, + root: `${process.cwd()}/public`, hook: "$beforeRoutesInit" // ... statics options } ], "/after": [ { - root: `${rootDir}/public`, + root: `${process.cwd()}/public`, hook: "$afterRoutesInit" // ... statics options } diff --git a/docs/docs/snippets/configuration/modulev0-endpoint-versionning.ts b/docs/docs/snippets/configuration/modulev0-endpoint-versionning.ts index 94f935cbf6f..ce66343d54c 100644 --- a/docs/docs/snippets/configuration/modulev0-endpoint-versionning.ts +++ b/docs/docs/snippets/configuration/modulev0-endpoint-versionning.ts @@ -1,9 +1,9 @@ import {Module} from "@tsed/di"; -import {resolve} from "path"; +import {UserController} from "./users/UserController"; @Module({ mount: { - "/rest/v0": [`./controllers/v0/users/*.ts`, `./controllers/v0/groups/*.ts`] + "/rest/v0": [UserController] } }) export class ModuleV0 {} diff --git a/docs/docs/snippets/configuration/modulev1-endpoint-versionning.ts b/docs/docs/snippets/configuration/modulev1-endpoint-versionning.ts index 8c543144d3a..162955574a5 100644 --- a/docs/docs/snippets/configuration/modulev1-endpoint-versionning.ts +++ b/docs/docs/snippets/configuration/modulev1-endpoint-versionning.ts @@ -1,9 +1,9 @@ import {Module} from "@tsed/di"; -import {resolve} from "path"; +import {UserController} from "./users/UserController"; @Module({ mount: { - "/rest/v1": [`./controllers/v1/**/*.ts`] + "/rest/v1": [UserController] } }) export class ModuleV1 {} diff --git a/docs/docs/snippets/configuration/server-endpoint-versionning.ts b/docs/docs/snippets/configuration/server-endpoint-versionning.ts index 2587f85e81d..c68b4047021 100644 --- a/docs/docs/snippets/configuration/server-endpoint-versionning.ts +++ b/docs/docs/snippets/configuration/server-endpoint-versionning.ts @@ -1,10 +1,19 @@ import {Configuration} from "@tsed/di"; -import {resolve} from "path"; +import * as v1Controllers from "./controllers/v1/index"; +import * as v0Controllers from "./controllers/v0/index"; @Configuration({ mount: { - "/rest/v1": [`./controllers/v1/**/*.ts`], - "/rest/v0": [`./controllers/v0/users/*.ts`, `./controllers/v0/groups/*.ts`] + "/rest/v1": [...Object.values(v1Controllers)], + "/rest/v0": [...Object.values(v0Controllers)] } }) export class Server {} + +// v1/index.ts +export * from "./users/UserControllers"; +export * from "./groups/GroupsControllers"; + +// v0/index.ts +export * from "./users/UserControllers"; +export * from "./groups/GroupsControllers"; diff --git a/docs/docs/snippets/configuration/server-resolvers.ts b/docs/docs/snippets/configuration/server-resolvers.ts index 84b789cbf0a..aeded388ec8 100644 --- a/docs/docs/snippets/configuration/server-resolvers.ts +++ b/docs/docs/snippets/configuration/server-resolvers.ts @@ -1,11 +1,7 @@ import {Configuration} from "@tsed/di"; -import {resolve} from "path"; import {myContainer} from "./inversify.config"; -const rootDir = resolve(__dirname); - @Configuration({ - rootDir, resolvers: [ { get(token: any) { diff --git a/docs/docs/snippets/configuration/server.ts b/docs/docs/snippets/configuration/server.ts index 23da91434e0..712ea9b7297 100644 --- a/docs/docs/snippets/configuration/server.ts +++ b/docs/docs/snippets/configuration/server.ts @@ -1,16 +1,15 @@ import {Configuration} from "@tsed/di"; -import * as Path from "path"; import {MyController} from "./controllers/manual/MyController"; @Configuration({ mount: { "/rest": [ - `./controllers/current/**/*.ts`, + `./controllers/current/**/*.ts`, // deprecated MyController // support manual import ], "/rest/v0": [ // versioning - `./controllers/v0/users/*.js`, + `./controllers/v0/users/*.js`, // deprecated `!./controllers/v0/groups/old/*.ts` // Exclusion ] } diff --git a/docs/tutorials/passport.md b/docs/tutorials/passport.md index 376bde00437..02a660b36d8 100644 --- a/docs/tutorials/passport.md +++ b/docs/tutorials/passport.md @@ -74,7 +74,7 @@ class CustomUserInfoModel { @Configuration({ componentsScan: [ - `${rootDir}/protocols/*.ts` // scan protocols directory + `${process.cwd()}/protocols/*.ts` // scan protocols directory ], passport: { userInfoModel: CustomUserInfoModel diff --git a/packages/orm/adapters-redis/package.json b/packages/orm/adapters-redis/package.json index 220aa7624c3..36481998243 100644 --- a/packages/orm/adapters-redis/package.json +++ b/packages/orm/adapters-redis/package.json @@ -26,7 +26,7 @@ }, "devDependencies": { "@tsed/core": "6.108.0", - "@types/ioredis": "^4.28.10", + "@types/ioredis": "4.28.10", "@types/ioredis-mock": "5.6.0", "ioredis": "4.28.5", "ioredis-mock": "7.2.0" @@ -40,4 +40,4 @@ "ioredis-mock": "^5.2.0", "uuid": "8.3.2" } -} \ No newline at end of file +} diff --git a/packages/orm/adapters-redis/src/adapters/RedisAdapter.ts b/packages/orm/adapters-redis/src/adapters/RedisAdapter.ts index bc7f46a6021..b85daff2196 100644 --- a/packages/orm/adapters-redis/src/adapters/RedisAdapter.ts +++ b/packages/orm/adapters-redis/src/adapters/RedisAdapter.ts @@ -1,6 +1,7 @@ import {Adapter, AdapterModel} from "@tsed/adapters"; import {Inject} from "@tsed/di"; -import IoRedis, {Redis} from "ioredis"; +import IoRedis from "ioredis"; +import type {Redis} from "ioredis"; import {v4 as uuid} from "uuid"; import "../services/RedisFactory"; diff --git a/packages/platform/platform-response-filter/src/services/PlatformResponseFilter.spec.ts b/packages/platform/platform-response-filter/src/services/PlatformResponseFilter.spec.ts index 108d0122780..ce191d4e5e1 100644 --- a/packages/platform/platform-response-filter/src/services/PlatformResponseFilter.spec.ts +++ b/packages/platform/platform-response-filter/src/services/PlatformResponseFilter.spec.ts @@ -111,6 +111,7 @@ describe("PlatformResponseFilter", () => { sandbox.stub(ctx.request, "get").returns("application/json"); sandbox.stub(ctx.request, "accepts").returns(["application/json"]); + // @ts-ignore platformResponseFilter.types.set("*/*", { transform(data: unknown, ctx: PlatformContext) { return {data}; @@ -162,6 +163,7 @@ describe("PlatformResponseFilter", () => { const data = {text: "test"}; ctx.endpoint = EndpointMetadata.get(Test, "test"); + // @ts-ignore platformResponseFilter.types.set("*/*", { transform(data: unknown, ctx: PlatformContext) { return {data}; diff --git a/packages/platform/platform-response-filter/src/services/PlatformResponseFilter.ts b/packages/platform/platform-response-filter/src/services/PlatformResponseFilter.ts index 88d5b0fd787..27bd95580b8 100644 --- a/packages/platform/platform-response-filter/src/services/PlatformResponseFilter.ts +++ b/packages/platform/platform-response-filter/src/services/PlatformResponseFilter.ts @@ -1,9 +1,9 @@ import {isSerializable, Type} from "@tsed/core"; +import {serialize} from "@tsed/json-mapper"; import {BaseContext, Constant, Inject, Injectable, InjectorService} from "@tsed/di"; import {ResponseFilterKey, ResponseFiltersContainer} from "../domain/ResponseFiltersContainer"; import {ResponseFilterMethods} from "../interfaces/ResponseFilterMethods"; import {ANY_CONTENT_TYPE, getContentType} from "../utils/getContentType"; -import {ConverterService} from "./ConverterService"; import {renderView} from "../utils/renderView"; /** @@ -11,14 +11,17 @@ import {renderView} from "../utils/renderView"; */ @Injectable() export class PlatformResponseFilter { - types: Map = new Map(); + protected types: Map = new Map(); @Inject() - injector: InjectorService; + protected injector: InjectorService; @Constant("responseFilters", []) protected responseFilters: Type[]; + @Constant("converter.additionalProperties") + protected additionalProperties: string; + get contentTypes(): ResponseFilterKey[] { return [...this.types.keys()]; } @@ -44,6 +47,7 @@ export class PlatformResponseFilter { return contentType; } + /** * Call filters to transform data * @param data @@ -65,6 +69,7 @@ export class PlatformResponseFilter { return data; } + /** * Serialize data before calling filters * @param data @@ -77,7 +82,9 @@ export class PlatformResponseFilter { if (endpoint.view) { data = await renderView(data, ctx); } else if (isSerializable(data)) { - data = this.injector.get(ConverterService)!.serialize(data, { + data = serialize(data, { + useAlias: true, + additionalProperties: this.additionalProperties === "accept", ...endpoint.getResponseOptions(response.statusCode), endpoint: true }); diff --git a/packages/platform/platform-serverless-http/readme.md b/packages/platform/platform-serverless-http/readme.md index b3893137bfa..2f6f36d5d72 100644 --- a/packages/platform/platform-serverless-http/readme.md +++ b/packages/platform/platform-serverless-http/readme.md @@ -103,7 +103,7 @@ import {TimeslotsController} from "./controllers/TimeslotsController"; } ], views: { - root: `${rootDir}/views`, + root: "${rootDir}/views", extensions: { ejs: "ejs" } diff --git a/packages/third-parties/socketio/src/class/SocketHandlersBuilder.spec.ts b/packages/third-parties/socketio/src/class/SocketHandlersBuilder.spec.ts index f77be3d5915..efb4966d2ef 100644 --- a/packages/third-parties/socketio/src/class/SocketHandlersBuilder.spec.ts +++ b/packages/third-parties/socketio/src/class/SocketHandlersBuilder.spec.ts @@ -39,15 +39,11 @@ describe("SocketHandlersBuilder", () => { } }; - const builder: any = new SocketHandlersBuilder( - provider, - {} as any, - { - get() { - return instance; - } - } as any - ); + const builder: any = new SocketHandlersBuilder(provider, { + get() { + return instance; + } + } as any); builder.socketProviderMetadata = new SocketProviderMetadata({ namespace: "/", injectNamespaces: [{propertyKey: "key1"}, {propertyKey: "key2", nsp: "/test"}], @@ -140,15 +136,11 @@ describe("SocketHandlersBuilder", () => { on: Sinon.stub() }; - const builder: any = new SocketHandlersBuilder( - provider, - {} as any, - { - get() { - return instance; - } - } as any - ); + const builder: any = new SocketHandlersBuilder(provider, { + get() { + return instance; + } + } as any); const invokeStub = Sinon.stub(builder, "invoke"); const buildHandlersStub = Sinon.stub(builder, "buildHandlers"); @@ -192,15 +184,11 @@ describe("SocketHandlersBuilder", () => { on: Sinon.stub() }; - const builder: any = new SocketHandlersBuilder( - provider, - {} as any, - { - get() { - return instance; - } - } as any - ); + const builder: any = new SocketHandlersBuilder(provider, { + get() { + return instance; + } + } as any); const invokeStub = Sinon.stub(builder, "invoke"); const destroySessionStub = Sinon.stub(builder, "destroySession"); @@ -228,15 +216,11 @@ describe("SocketHandlersBuilder", () => { } }; - const builder: any = new SocketHandlersBuilder( - provider, - {} as any, - { - get() { - return instance; - } - } as any - ); + const builder: any = new SocketHandlersBuilder(provider, { + get() { + return instance; + } + } as any); builder.createSession({id: "id"}); expect(instance._nspSession.get("id")).to.be.instanceof(Map); @@ -255,15 +239,11 @@ describe("SocketHandlersBuilder", () => { instance._nspSession.set("id", new Map()); - const builder: any = new SocketHandlersBuilder( - provider, - {} as any, - { - get() { - return instance; - } - } as any - ); + const builder: any = new SocketHandlersBuilder(provider, { + get() { + return instance; + } + } as any); builder.destroySession({id: "id"}); @@ -289,7 +269,7 @@ describe("SocketHandlersBuilder", () => { const socketStub = { on: Sinon.stub() }; - const builder: any = new SocketHandlersBuilder(provider, {} as any, {} as any); + const builder: any = new SocketHandlersBuilder(provider, {} as any); const runQueueStub = Sinon.stub(builder, "runQueue"); builder.buildHandlers(socketStub, "ws"); @@ -310,15 +290,11 @@ describe("SocketHandlersBuilder", () => { } }; - const builder: any = new SocketHandlersBuilder( - provider, - {} as any, - { - get() { - return instance; - } - } as any - ); + const builder: any = new SocketHandlersBuilder(provider, { + get() { + return instance; + } + } as any); const buildParametersStub = Sinon.stub(builder, "buildParameters").returns(["argMapped"]); builder.invoke(instance, metadata.handlers.testHandler, {scope: "scope"}); @@ -341,15 +317,11 @@ describe("SocketHandlersBuilder", () => { } }; - const builder: any = new SocketHandlersBuilder( - provider, - {} as any, - { - get() { - return instance; - } - } as any - ); + const builder: any = new SocketHandlersBuilder(provider, { + get() { + return instance; + } + } as any); return { instance, @@ -572,15 +544,11 @@ describe("SocketHandlersBuilder", () => { bindResponseMiddlewareStub = Sinon.stub(SocketHandlersBuilder as any, "bindResponseMiddleware"); - builder = new SocketHandlersBuilder( - provider, - {} as any, - { - get() { - return instance; - } - } as any - ); + builder = new SocketHandlersBuilder(provider, { + get() { + return instance; + } + } as any); invokeStub = Sinon.stub(builder, "invoke"); bindMiddlewareStub = Sinon.stub(builder, "bindMiddleware"); @@ -702,7 +670,7 @@ describe("SocketHandlersBuilder", () => { const scope = {scope: "scope"}; - const builder: any = new SocketHandlersBuilder(provider, {} as any, injector); + const builder: any = new SocketHandlersBuilder(provider, injector); const invokeStub = Sinon.stub(builder, "invoke"); builder.bindMiddleware({target: "target"}, scope, Promise.resolve()); @@ -747,7 +715,7 @@ describe("SocketHandlersBuilder", () => { getStub.returns(instance); const scope = {scope: "scope", args: undefined}; - const builder: any = new SocketHandlersBuilder(provider as any, {} as any, injector); + const builder: any = new SocketHandlersBuilder(provider as any, injector); Sinon.stub(builder, "invoke").returns({result: "result"}); // WHEN @@ -794,7 +762,7 @@ describe("SocketHandlersBuilder", () => { const scope = {scope: "scope", args: undefined}; const error = new Error("test"); - const builder: any = new SocketHandlersBuilder(provider as any, {} as any, injector); + const builder: any = new SocketHandlersBuilder(provider as any, injector); Sinon.stub(builder, "invoke").returns({result: "result"}); // WHEN @@ -828,17 +796,13 @@ describe("SocketHandlersBuilder", () => { args: ["any"] }; - const converterService = { - deserialize: Sinon.stub().returns("value") - }; - - const builder: any = new SocketHandlersBuilder(provider, converterService as any, {} as any); + const builder = new SocketHandlersBuilder(provider, PlatformTest.injector); + // @ts-ignore builder.deserialize({parameters} as any, scope as any); - expect(converterService.deserialize).to.have.been.calledWithExactly("any", { - type: String, - collectionType: Array + expect(scope).to.deep.eq({ + args: [["any"]] }); }); }); diff --git a/packages/third-parties/socketio/src/class/SocketHandlersBuilder.ts b/packages/third-parties/socketio/src/class/SocketHandlersBuilder.ts index 22cb6f02f70..af2b0962a05 100644 --- a/packages/third-parties/socketio/src/class/SocketHandlersBuilder.ts +++ b/packages/third-parties/socketio/src/class/SocketHandlersBuilder.ts @@ -1,7 +1,7 @@ import {InjectorService, Provider} from "@tsed/di"; -import {ConverterService} from "@tsed/common"; import {Store} from "@tsed/core"; import {$log} from "@tsed/logger"; +import {deserialize} from "@tsed/json-mapper"; import {Namespace, Socket} from "socket.io"; import {SocketFilters} from "../interfaces/SocketFilters"; import {SocketHandlerMetadata} from "../interfaces/SocketHandlerMetadata"; @@ -18,7 +18,7 @@ import {SocketProviderMetadata} from "./SocketProviderMetadata"; export class SocketHandlersBuilder { private socketProviderMetadata: SocketProviderMetadata; - constructor(private provider: Provider, private converterService: ConverterService, private injector: InjectorService) { + constructor(private provider: Provider, private injector: InjectorService) { this.socketProviderMetadata = new SocketProviderMetadata(this.provider.store.get("socketIO")); } @@ -183,7 +183,12 @@ export class SocketHandlersBuilder { let value = scope.args[mapIndex!]; if (filter === SocketFilters.ARGS && useConverter) { - value = this.converterService.deserialize(value, {type, collectionType}); + value = deserialize(value, { + useAlias: true, + additionalProperties: this.injector.settings.get("converter.additionalProperties") === "accept", + type, + collectionType + }); scope.args[mapIndex!] = value; } }); diff --git a/packages/third-parties/socketio/src/services/SocketIOService.spec.ts b/packages/third-parties/socketio/src/services/SocketIOService.spec.ts index 9430e9d7791..b389dcce9b1 100644 --- a/packages/third-parties/socketio/src/services/SocketIOService.spec.ts +++ b/packages/third-parties/socketio/src/services/SocketIOService.spec.ts @@ -1,60 +1,53 @@ import {expect} from "chai"; -import {InjectorService} from "@tsed/di"; import {PlatformTest} from "@tsed/common"; import Sinon from "sinon"; import {SocketIOService} from "../index"; +import {Server} from "./SocketIOServer"; + +async function createServiceFixture() { + const namespace = { + on: Sinon.stub() + }; + const ioStub = { + of: Sinon.stub().returns(namespace) + }; + const instance = { + onConnection: Sinon.stub(), + onDisconnect: Sinon.stub() + }; + + const socket = { + on: Sinon.stub() + }; + + const service = await PlatformTest.invoke(SocketIOService, [ + { + token: Server, + use: ioStub + } + ]); + + return {namespace, ioStub, service, instance, socket}; +} describe("SocketIOService", () => { + beforeEach(() => PlatformTest.create()); + afterEach(() => PlatformTest.reset()); + describe("getNsp()", () => { - let namespace: any; - let ioStub: any; - let socket: any; - let instance: any; - - before( - PlatformTest.inject([InjectorService], (injector: InjectorService) => { - namespace = { - on: Sinon.stub() - }; - ioStub = { - of: Sinon.stub().returns(namespace) - }; - instance = { - onConnection: Sinon.stub(), - onDisconnect: Sinon.stub() - }; - socket = { - on: Sinon.stub() - }; - - const service = new SocketIOService(injector, ioStub, {} as any); - const nspConf = service.getNsp("/"); - nspConf.instances.push(instance); - - namespace.on.getCall(0).args[1](socket); - socket.on.getCall(0).args[1](); - }) - ); - - after(PlatformTest.reset); - - it("should call io.of and create namespace", () => { - expect(ioStub.of).to.have.been.calledWithExactly("/"); - }); + it("should call io.of and create namespace", async () => { + const {service, namespace, ioStub, socket, instance} = await createServiceFixture(); - it("should call namespace.on", () => { - expect(namespace.on).to.have.been.calledWithExactly("connection", Sinon.match.func); - }); + const nspConf = service.getNsp("/"); + nspConf.instances.push(instance); - it("should call builder.onConnection", () => { - expect(instance.onConnection).to.have.been.calledWithExactly(socket, namespace); - }); + namespace.on.getCall(0).args[1](socket); + socket.on.getCall(0).args[1](); - it("should call socket.on when socket is disconnected", () => { + expect(ioStub.of).to.have.been.calledWithExactly("/"); + expect(namespace.on).to.have.been.calledWithExactly("connection", Sinon.match.func); + expect(instance.onConnection).to.have.been.calledWithExactly(socket, namespace); expect(socket.on).to.have.been.calledWithExactly("disconnect", Sinon.match.func); - }); - - it("should call builder.onDisconnect", () => { expect(instance.onDisconnect).to.have.been.calledWithExactly(socket, namespace); }); }); diff --git a/packages/third-parties/socketio/src/services/SocketIOService.ts b/packages/third-parties/socketio/src/services/SocketIOService.ts index 2ee85e5e1e5..9138f959298 100644 --- a/packages/third-parties/socketio/src/services/SocketIOService.ts +++ b/packages/third-parties/socketio/src/services/SocketIOService.ts @@ -1,5 +1,4 @@ import {InjectorService, Provider, Service} from "@tsed/common"; -import {ConverterService} from "@tsed/common"; import SocketIO from "socket.io"; // tslint:disable-line: no-unused-variable import {SocketHandlersBuilder} from "../class/SocketHandlersBuilder"; import {SocketProviderMetadata} from "../class/SocketProviderMetadata"; @@ -16,7 +15,7 @@ export class SocketIOService { */ private namespaces: Map = new Map(); - constructor(private injector: InjectorService, @IO private io: SocketIO.Server, private converterService: ConverterService) {} + constructor(private injector: InjectorService, @IO private io: SocketIO.Server) {} /** * @@ -59,7 +58,7 @@ export class SocketIOService { nsps.set(nsp, value.nsp); }); - const builder = new SocketHandlersBuilder(provider, this.converterService, this.injector).build(nsps); + const builder = new SocketHandlersBuilder(provider, this.injector).build(nsps); nspConfig.instances.push(builder); } diff --git a/packages/third-parties/socketio/test/app/middlewares/ConverterUserSocketMiddleware.ts b/packages/third-parties/socketio/test/app/middlewares/ConverterUserSocketMiddleware.ts index 012cc6c356e..ece4d523f86 100644 --- a/packages/third-parties/socketio/test/app/middlewares/ConverterUserSocketMiddleware.ts +++ b/packages/third-parties/socketio/test/app/middlewares/ConverterUserSocketMiddleware.ts @@ -1,14 +1,12 @@ -import {ConverterService} from "@tsed/common"; -import {Args, SocketSession, SocketMiddleware} from "@tsed/socketio"; +import {Args, SocketMiddleware, SocketSession} from "@tsed/socketio"; import {User} from "../models/User"; +import {deserialize} from "@tsed/json-mapper"; @SocketMiddleware() export class ConverterUserSocketMiddleware { - constructor(private converterService: ConverterService) {} - use(@Args(0) user: any[], @SocketSession session: Map) { session.set("test", "test2"); - user = this.converterService.deserialize(user, User); + user = deserialize(user, {type: User, useAlias: true}); return [user]; } diff --git a/packages/third-parties/stripe/readme.md b/packages/third-parties/stripe/readme.md index 2152d95d150..4a86228102d 100644 --- a/packages/third-parties/stripe/readme.md +++ b/packages/third-parties/stripe/readme.md @@ -178,10 +178,9 @@ import {expect} from "chai"; import {Stripe} from "stripe"; import SuperTest from "supertest"; import {StripeWebhooksCtrl} from "./StripWebhookCtrl"; -import {rootDir, Server} from "../Server"; +import {Server} from "../Server"; const utils = PlatformTestUtils.create({ - rootDir, platform: PlatformExpress, server: Server, logger: { diff --git a/yarn.lock b/yarn.lock index bd1d5e8c49a..eabf7a045f3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3854,7 +3854,7 @@ dependencies: "@types/ioredis" "*" -"@types/ioredis@*", "@types/ioredis@^4.28.10": +"@types/ioredis@*", "@types/ioredis@4.28.10": version "4.28.10" resolved "https://registry.yarnpkg.com/@types/ioredis/-/ioredis-4.28.10.tgz#40ceb157a4141088d1394bb87c98ed09a75a06ff" integrity sha512-69LyhUgrXdgcNDv7ogs1qXZomnfOEnSmrmMFqKgt1XMJxmoOSG/u3wYy13yACIfKuMJ8IhKgHafDO3sx19zVQQ==