Skip to content

Commit

Permalink
fix(common): Move domain code to @tsed/schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita committed Jan 2, 2022
1 parent 68337c4 commit 3f405d1
Show file tree
Hide file tree
Showing 77 changed files with 784 additions and 905 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {All, buildRouter, ControllerProvider, Get, Use} from "@tsed/common";
import {InjectorService} from "@tsed/di";
import {OperationMethods} from "@tsed/schema";
import {EndpointMetadata, OperationMethods} from "@tsed/schema";
import {expect} from "chai";
import Sinon from "sinon";
import {EndpointMetadata} from "../domain/EndpointMetadata";
import {Platform} from "../services/Platform";
import {PlatformApplication} from "../services/PlatformApplication";
import {PlatformHandler} from "../services/PlatformHandler";
Expand Down Expand Up @@ -83,7 +82,7 @@ describe("buildRouter()", () => {
// GIVEN
const {endpoint, provider, injector} = getControllerBuilder({propertyKey: "getMethod"});

endpoint.addOperationPath(OperationMethods.GET, "/", {isFinal: true});
endpoint.operation.addOperationPath(OperationMethods.GET, "/", {isFinal: true});

// WHEN
const result: any = buildRouter(injector, provider);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {Type} from "@tsed/core";
import {GlobalProviders, InjectorService, ProviderType} from "@tsed/di";
import {getOperationsRoutes, OperationMethods} from "@tsed/schema";
import {getOperationsRoutes, OperationMethods, EndpointMetadata} from "@tsed/schema";
import {ControllerProvider} from "../domain/ControllerProvider";
import {PlatformRouter} from "../services/PlatformRouter";
import {EndpointMetadata} from "../domain/EndpointMetadata";
import {PlatformMiddlewaresChain} from "../services/PlatformMiddlewaresChain";

GlobalProviders.createRegistry(ProviderType.CONTROLLER, ControllerProvider, {
Expand Down
6 changes: 1 addition & 5 deletions packages/platform/common/src/decorators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ export * from "./httpsServer";
export * from "./multer";

// Method
export * from "./method/route";
export * from "./method/acceptMime";
export * from "./method/location";
export * from "./method/redirect";
export {AcceptMime, Location, Redirect, View, Get, Post, Put, Patch, Delete, Head, Options, All} from "@tsed/schema";
export * from "./method/endpointFn";
export * from "./method/view";

// Params
export * from "./params/responseData";
Expand Down
1 change: 0 additions & 1 deletion packages/platform/common/src/decorators/method/location.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/platform/common/src/decorators/method/redirect.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/platform/common/src/decorators/method/route.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {MultipartFile, ParamMetadata, ParamTypes, PlatformMulterMiddleware, Post} from "@tsed/common";
import {MultipartFile, ParamTypes, PlatformMulterMiddleware, Post} from "@tsed/common";
import {descriptorOf, Metadata, Store} from "@tsed/core";
import {getSpec, SpecTypes} from "@tsed/schema";
import {getSpec, JsonParameterStore, SpecTypes} from "@tsed/schema";
import {expect} from "chai";
import Sinon from "sinon";

Expand All @@ -20,7 +20,7 @@ describe("@MultipartFile()", () => {

// THEN
const store = Store.fromMethod(TestController, "test");
const param = ParamMetadata.get(TestController, "test", 0);
const param = JsonParameterStore.get(TestController, "test", 0);

it("should set params properly", () => {
expect(store.get(PlatformMulterMiddleware)).to.deep.eq({
Expand Down Expand Up @@ -210,7 +210,7 @@ describe("@MultipartFile()", () => {

// THEN
const store = Store.fromMethod(TestController, "test");
const param = ParamMetadata.get(TestController, "test", 0);
const param = JsonParameterStore.get(TestController, "test", 0);

it("should set params properly", () => {
expect(store.get(PlatformMulterMiddleware)).to.deep.eq({
Expand Down Expand Up @@ -428,7 +428,7 @@ describe("@MultipartFile()", () => {
});

it("should set params metadata", () => {
const param = ParamMetadata.get(Test, "test", 0);
const param = JsonParameterStore.get(Test, "test", 0);
expect(param.expression).to.eq("file1");
expect(param.paramType).to.eq(ParamTypes.FILES);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {DecoratorParameters, Metadata, StoreMerge, useDecorators, useMethodDecorators} from "@tsed/core";
import {ParamTypes, UseParam} from "@tsed/platform-params";
import {Consumes, InFile, Returns} from "@tsed/schema";
import {InFile} from "@tsed/schema";
import {PlatformMulterFile} from "../../config/interfaces/PlatformMulterSettings";
import {MulterInputOptions, PlatformMulterMiddleware} from "../../middlewares/PlatformMulterMiddleware";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import {ParamMetadata, ParamTypes} from "@tsed/platform-params";
import {ParamTypes} from "@tsed/platform-params";
import {expect} from "chai";
import {EndpointInfo} from "./endpointInfo";
import {JsonParameterStore} from "@tsed/schema";

describe("@EndpointInfo", () => {
it("should register a new ParamMetadata instance with the correct property", () => {
it("should register a new parameter instance with the correct property", () => {
class Ctrl {
test(@EndpointInfo() arg: EndpointInfo) {}
}

const param = ParamMetadata.get(Ctrl, "test", 0);
const param = JsonParameterStore.get(Ctrl, "test", 0);
expect(param.paramType).to.eq(ParamTypes.$CTX);
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {ParamTypes, UseParam} from "@tsed/platform-params";
import {EndpointMetadata} from "../../domain/EndpointMetadata";
import {EndpointMetadata} from "@tsed/schema";

/**
* Get the current endpoint metadata.
Expand Down
7 changes: 4 additions & 3 deletions packages/platform/common/src/decorators/params/error.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import {ParamMetadata, ParamTypes} from "@tsed/platform-params";
import {ParamTypes} from "@tsed/platform-params";
import {Err} from "./error";
import {expect} from "chai";
import {JsonParameterStore} from "@tsed/schema";

describe("@Err", () => {
it("should register a new ParamMetadata instance with the correct property", () => {
it("should register a new parameter instance with the correct property", () => {
class Ctrl {
test(@Err() arg: unknown) {}
}

const param = ParamMetadata.get(Ctrl, "test", 0);
const param = JsonParameterStore.get(Ctrl, "test", 0);
expect(param.paramType).to.eq(ParamTypes.ERR);
});
});
7 changes: 4 additions & 3 deletions packages/platform/common/src/decorators/params/next.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import {ParamMetadata, ParamTypes} from "@tsed/platform-params";
import {ParamTypes} from "@tsed/platform-params";
import {JsonParameterStore} from "@tsed/schema";
import {expect} from "chai";
import {Next} from "./next";

describe("@Next", () => {
it("should register a new ParamMetadata instance with the correct property", () => {
it("should register a new parameter instance with the correct property", () => {
class Ctrl {
test(@Next() arg: any) {}
}

const param = ParamMetadata.get(Ctrl, "test", 0);
const param = JsonParameterStore.get(Ctrl, "test", 0);
expect(param.paramType).to.eq(ParamTypes.NEXT_FN);
});
});
19 changes: 10 additions & 9 deletions packages/platform/common/src/decorators/params/request.spec.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,47 @@
import {ParamMetadata, ParamTypes, PlatformRequest} from "@tsed/common";
import {ParamTypes, PlatformRequest} from "@tsed/common";
import {expect} from "chai";
import {IncomingMessage} from "http";
import {Req} from "./request";
import {JsonParameterStore} from "@tsed/schema";

describe("@Req", () => {
it("should register a new ParamMetadata instance with the correct property (RawRequest)", () => {
it("should register a new parameter instance with the correct property (RawRequest)", () => {
class Ctrl {
test(@Req() arg: Req) {}
}

const param = ParamMetadata.get(Ctrl, "test", 0);
const param = JsonParameterStore.get(Ctrl, "test", 0);
expect(param.paramType).to.eq(ParamTypes.REQUEST);
expect(param.type).to.eq(Req);
});

it("should register a new ParamMetadata instance with the correct property (RawRequest with expression)", () => {
it("should register a new parameter instance with the correct property (RawRequest with expression)", () => {
class Ctrl {
test(@Req("user") arg: Req) {}
}

const param = ParamMetadata.get(Ctrl, "test", 0);
const param = JsonParameterStore.get(Ctrl, "test", 0);
expect(param.paramType).to.eq(ParamTypes.REQUEST);
expect(param.expression).to.eq("user");
expect(param.type).to.eq(Req);
});

it("should register a new ParamMetadata instance with the correct property (PlatformRequest)", () => {
it("should register a new parameter instance with the correct property (PlatformRequest)", () => {
class Ctrl {
test(@Req() arg: PlatformRequest) {}
}

const param = ParamMetadata.get(Ctrl, "test", 0);
const param = JsonParameterStore.get(Ctrl, "test", 0);
expect(param.paramType).to.eq(ParamTypes.PLATFORM_REQUEST);
expect(param.type).to.eq(PlatformRequest);
});

it("should register a new ParamMetadata instance with the correct property (IncomingMessage)", () => {
it("should register a new parameter instance with the correct property (IncomingMessage)", () => {
class Ctrl {
test(@Req() arg: IncomingMessage) {}
}

const param = ParamMetadata.get(Ctrl, "test", 0);
const param = JsonParameterStore.get(Ctrl, "test", 0);
expect(param.paramType).to.eq(ParamTypes.NODE_REQUEST);
expect(param.type).to.eq(IncomingMessage);
});
Expand Down
15 changes: 8 additions & 7 deletions packages/platform/common/src/decorators/params/response.spec.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
import {PlatformResponse} from "@tsed/common";
import {ParamMetadata, ParamTypes} from "@tsed/platform-params";
import {ParamTypes} from "@tsed/platform-params";
import {expect} from "chai";
import {ServerResponse} from "http";
import {Response} from "./response";
import {JsonParameterStore} from "@tsed/schema";

describe("@Res", () => {
it("should register a new ParamMetadata instance with the correct property (RawRes)", () => {
it("should register a new parameter instance with the correct property (RawRes)", () => {
class Ctrl {
test(@Response() arg: Response) {}
}

const param = ParamMetadata.get(Ctrl, "test", 0);
const param = JsonParameterStore.get(Ctrl, "test", 0);
expect(param.paramType).to.eq(ParamTypes.RESPONSE);
expect(param.type).to.eq(Response);
});
it("should register a new ParamMetadata instance with the correct property (PlatformResponse)", () => {
it("should register a new parameter instance with the correct property (PlatformResponse)", () => {
class Ctrl {
test(@Response() arg: PlatformResponse) {}
}

const param = ParamMetadata.get(Ctrl, "test", 0);
const param = JsonParameterStore.get(Ctrl, "test", 0);
expect(param.paramType).to.eq(ParamTypes.PLATFORM_RESPONSE);
expect(param.type).to.eq(PlatformResponse);
});
it("should register a new ParamMetadata instance with the correct property (ServerResponse)", () => {
it("should register a new parameter instance with the correct property (ServerResponse)", () => {
class Ctrl {
test(@Response() arg: ServerResponse) {}
}

const param = ParamMetadata.get(Ctrl, "test", 0);
const param = JsonParameterStore.get(Ctrl, "test", 0);
expect(param.paramType).to.eq(ParamTypes.NODE_RESPONSE);
expect(param.type).to.eq(ServerResponse);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import {ParamMetadata, ParamTypes} from "@tsed/platform-params";
import {ParamTypes} from "@tsed/platform-params";
import {expect} from "chai";
import {ResponseData} from "./responseData";
import {JsonParameterStore} from "@tsed/schema";

describe("@ResponseData", () => {
it("should register a new ParamMetadata instance with the correct property", () => {
it("should register a new parameter instance with the correct property", () => {
class Ctrl {
test(@ResponseData() arg: any) {}
}

const param = ParamMetadata.get(Ctrl, "test", 0);
const param = JsonParameterStore.get(Ctrl, "test", 0);
expect(param.paramType).to.eq(ParamTypes.$CTX);
expect(param.dataPath).to.eq("$ctx.data");
});
Expand Down
Loading

0 comments on commit 3f405d1

Please sign in to comment.