@tsed/platform-koa 6.87.1 → 6.89.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/{components → cjs/components}/PlatformKoa.d.ts +0 -0
- package/lib/{components → cjs/components}/PlatformKoa.js +1 -1
- package/lib/cjs/components/PlatformKoa.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/caseSensitive.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/caseSensitive.js +1 -1
- package/lib/cjs/decorators/caseSensitive.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/ctx.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/ctx.js +1 -1
- package/lib/cjs/decorators/ctx.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/index.d.ts +0 -0
- package/lib/cjs/decorators/index.js +9 -0
- package/lib/cjs/decorators/index.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/routerSettings.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/routerSettings.js +1 -1
- package/lib/cjs/decorators/routerSettings.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/state.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/state.js +0 -0
- package/lib/cjs/decorators/state.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/strict.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/strict.js +1 -1
- package/lib/cjs/decorators/strict.js.map +1 -0
- package/lib/{index.d.ts → cjs/index.d.ts} +0 -0
- package/lib/{index.js → cjs/index.js} +4 -4
- package/lib/cjs/index.js.map +1 -0
- package/lib/{interfaces → cjs/interfaces}/PlatformKoaSettings.d.ts +0 -0
- package/lib/{interfaces → cjs/interfaces}/PlatformKoaSettings.js +0 -0
- package/lib/cjs/interfaces/PlatformKoaSettings.js.map +1 -0
- package/lib/{interfaces → cjs/interfaces}/index.d.ts +0 -0
- package/lib/{interfaces → cjs/interfaces}/index.js +1 -1
- package/lib/cjs/interfaces/index.js.map +1 -0
- package/lib/{middlewares → cjs/middlewares}/resourceNotFoundMiddleware.d.ts +0 -0
- package/lib/{middlewares → cjs/middlewares}/resourceNotFoundMiddleware.js +0 -0
- package/lib/cjs/middlewares/resourceNotFoundMiddleware.js.map +1 -0
- package/lib/{middlewares → cjs/middlewares}/staticsMiddleware.d.ts +0 -0
- package/lib/{middlewares → cjs/middlewares}/staticsMiddleware.js +2 -2
- package/lib/cjs/middlewares/staticsMiddleware.js.map +1 -0
- package/lib/{services → cjs/services}/PlatformKoaApplication.d.ts +0 -0
- package/lib/{services → cjs/services}/PlatformKoaApplication.js +5 -4
- package/lib/cjs/services/PlatformKoaApplication.js.map +1 -0
- package/lib/{services → cjs/services}/PlatformKoaHandler.d.ts +0 -0
- package/lib/{services → cjs/services}/PlatformKoaHandler.js +0 -0
- package/lib/cjs/services/PlatformKoaHandler.js.map +1 -0
- package/lib/{services → cjs/services}/PlatformKoaRequest.d.ts +1 -1
- package/lib/cjs/services/PlatformKoaRequest.js +44 -0
- package/lib/cjs/services/PlatformKoaRequest.js.map +1 -0
- package/lib/{services → cjs/services}/PlatformKoaResponse.d.ts +2 -2
- package/lib/{services → cjs/services}/PlatformKoaResponse.js +8 -8
- package/lib/cjs/services/PlatformKoaResponse.js.map +1 -0
- package/lib/{services → cjs/services}/PlatformKoaRouter.d.ts +0 -0
- package/lib/{services → cjs/services}/PlatformKoaRouter.js +7 -7
- package/lib/cjs/services/PlatformKoaRouter.js.map +1 -0
- package/lib/{services → cjs/services}/index.d.ts +0 -0
- package/lib/cjs/services/index.js +9 -0
- package/lib/cjs/services/index.js.map +1 -0
- package/lib/{utils → cjs/utils}/multer.d.ts +0 -0
- package/lib/{utils → cjs/utils}/multer.js +1 -1
- package/lib/cjs/utils/multer.js.map +1 -0
- package/lib/esm/components/PlatformKoa.js +74 -0
- package/lib/esm/components/PlatformKoa.js.map +1 -0
- package/lib/esm/decorators/caseSensitive.js +26 -0
- package/lib/esm/decorators/caseSensitive.js.map +1 -0
- package/lib/esm/decorators/ctx.js +27 -0
- package/lib/esm/decorators/ctx.js.map +1 -0
- package/lib/esm/decorators/index.js +6 -0
- package/lib/esm/decorators/index.js.map +1 -0
- package/lib/esm/decorators/routerSettings.js +27 -0
- package/lib/esm/decorators/routerSettings.js.map +1 -0
- package/lib/esm/decorators/state.js +5 -0
- package/lib/esm/decorators/state.js.map +1 -0
- package/lib/esm/decorators/strict.js +27 -0
- package/lib/esm/decorators/strict.js.map +1 -0
- package/lib/esm/index.js +13 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/interfaces/PlatformKoaSettings.js +2 -0
- package/lib/esm/interfaces/PlatformKoaSettings.js.map +1 -0
- package/lib/esm/interfaces/index.js +2 -0
- package/lib/esm/interfaces/index.js.map +1 -0
- package/lib/esm/middlewares/resourceNotFoundMiddleware.js +16 -0
- package/lib/esm/middlewares/resourceNotFoundMiddleware.js.map +1 -0
- package/lib/esm/middlewares/staticsMiddleware.js +30 -0
- package/lib/esm/middlewares/staticsMiddleware.js.map +1 -0
- package/lib/esm/services/PlatformKoaApplication.js +29 -0
- package/lib/esm/services/PlatformKoaApplication.js.map +1 -0
- package/lib/esm/services/PlatformKoaHandler.js +56 -0
- package/lib/esm/services/PlatformKoaHandler.js.map +1 -0
- package/lib/esm/services/PlatformKoaRequest.js +40 -0
- package/lib/esm/services/PlatformKoaRequest.js.map +1 -0
- package/lib/esm/services/PlatformKoaResponse.js +101 -0
- package/lib/esm/services/PlatformKoaResponse.js.map +1 -0
- package/lib/esm/services/PlatformKoaRouter.js +42 -0
- package/lib/esm/services/PlatformKoaRouter.js.map +1 -0
- package/lib/esm/services/index.js +6 -0
- package/lib/esm/services/index.js.map +1 -0
- package/lib/esm/utils/multer.js +51 -0
- package/lib/esm/utils/multer.js.map +1 -0
- package/lib/types/components/PlatformKoa.d.ts +38 -0
- package/lib/types/decorators/caseSensitive.d.ts +22 -0
- package/lib/types/decorators/ctx.d.ts +19 -0
- package/lib/types/decorators/index.d.ts +5 -0
- package/lib/types/decorators/routerSettings.d.ts +24 -0
- package/lib/types/decorators/state.d.ts +38 -0
- package/lib/types/decorators/strict.d.ts +23 -0
- package/lib/types/index.d.ts +4 -0
- package/lib/types/interfaces/PlatformKoaSettings.d.ts +8 -0
- package/lib/types/interfaces/index.d.ts +15 -0
- package/lib/types/middlewares/resourceNotFoundMiddleware.d.ts +6 -0
- package/lib/types/middlewares/staticsMiddleware.d.ts +6 -0
- package/lib/types/services/PlatformKoaApplication.d.ts +22 -0
- package/lib/types/services/PlatformKoaHandler.d.ts +10 -0
- package/lib/types/services/PlatformKoaRequest.d.ts +34 -0
- package/lib/types/services/PlatformKoaResponse.d.ts +57 -0
- package/lib/types/services/PlatformKoaRouter.d.ts +22 -0
- package/lib/types/services/index.d.ts +5 -0
- package/lib/types/utils/multer.d.ts +4 -0
- package/package.json +26 -18
- package/tsconfig.compile.esm.json +23 -0
- package/lib/components/PlatformKoa.js.map +0 -1
- package/lib/decorators/caseSensitive.js.map +0 -1
- package/lib/decorators/ctx.js.map +0 -1
- package/lib/decorators/index.js +0 -9
- package/lib/decorators/index.js.map +0 -1
- package/lib/decorators/routerSettings.js.map +0 -1
- package/lib/decorators/state.js.map +0 -1
- package/lib/decorators/strict.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/interfaces/PlatformKoaSettings.js.map +0 -1
- package/lib/interfaces/index.js.map +0 -1
- package/lib/middlewares/resourceNotFoundMiddleware.js.map +0 -1
- package/lib/middlewares/staticsMiddleware.js.map +0 -1
- package/lib/services/PlatformKoaApplication.js.map +0 -1
- package/lib/services/PlatformKoaHandler.js.map +0 -1
- package/lib/services/PlatformKoaRequest.js +0 -44
- package/lib/services/PlatformKoaRequest.js.map +0 -1
- package/lib/services/PlatformKoaResponse.js.map +0 -1
- package/lib/services/PlatformKoaRouter.js.map +0 -1
- package/lib/services/index.js +0 -9
- package/lib/services/index.js.map +0 -1
- package/lib/utils/multer.js.map +0 -1
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/// <reference types="koa__router" />
|
|
2
|
+
import KoaRouter from "@koa/router";
|
|
3
|
+
import { PlatformApplication, PlatformBuilder, PlatformBuilderOptions, PlatformHandler, PlatformRequest, PlatformResponse, PlatformRouter } from "@tsed/common";
|
|
4
|
+
import { Type } from "@tsed/core";
|
|
5
|
+
import Koa from "koa";
|
|
6
|
+
import { PlatformKoaApplication, PlatformKoaHandler, PlatformKoaRequest, PlatformKoaResponse, PlatformKoaRouter } from "../services";
|
|
7
|
+
/**
|
|
8
|
+
* @platform
|
|
9
|
+
* @koa
|
|
10
|
+
*/
|
|
11
|
+
export declare class PlatformKoa extends PlatformBuilder<Koa, KoaRouter> {
|
|
12
|
+
static providers: ({
|
|
13
|
+
provide: typeof PlatformResponse;
|
|
14
|
+
useClass: typeof PlatformKoaResponse;
|
|
15
|
+
} | {
|
|
16
|
+
provide: typeof PlatformRequest;
|
|
17
|
+
useClass: typeof PlatformKoaRequest;
|
|
18
|
+
} | {
|
|
19
|
+
provide: typeof PlatformHandler;
|
|
20
|
+
useClass: typeof PlatformKoaHandler;
|
|
21
|
+
} | {
|
|
22
|
+
provide: typeof PlatformRouter;
|
|
23
|
+
useClass: typeof PlatformKoaRouter;
|
|
24
|
+
} | {
|
|
25
|
+
provide: typeof PlatformApplication;
|
|
26
|
+
useClass: typeof PlatformKoaApplication;
|
|
27
|
+
})[];
|
|
28
|
+
constructor(options: PlatformBuilderOptions);
|
|
29
|
+
/**
|
|
30
|
+
* Create new serverless application. In this mode, the component scan are disabled.
|
|
31
|
+
* @param module
|
|
32
|
+
* @param settings
|
|
33
|
+
*/
|
|
34
|
+
static create(module: Type<any>, settings?: Partial<TsED.Configuration>): PlatformKoa;
|
|
35
|
+
static bootstrap(module: Type<any>, settings?: Partial<TsED.Configuration>): Promise<PlatformKoa>;
|
|
36
|
+
protected useRouter(): this;
|
|
37
|
+
protected useContext(): this;
|
|
38
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Specify the behavior of the router controller.
|
|
3
|
+
*
|
|
4
|
+
* ```typescript
|
|
5
|
+
* @Controller("/")
|
|
6
|
+
* @CaseSensitive(true)
|
|
7
|
+
* class MyCtrl {
|
|
8
|
+
*
|
|
9
|
+
* }
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* Property | Description | Default
|
|
13
|
+
* ---|---|---
|
|
14
|
+
* CaseSensitive | Enable case sensitivity. | Disabled by default, treating “/Foo” and “/foo” as the same.
|
|
15
|
+
* Strict | Enable strict routing. | Disabled by default, “/foo” and “/foo/” are treated the same by the router.
|
|
16
|
+
*
|
|
17
|
+
* @returns {Function}
|
|
18
|
+
* @decorator
|
|
19
|
+
* @koa
|
|
20
|
+
* @param sensitive
|
|
21
|
+
*/
|
|
22
|
+
export declare function CaseSensitive(sensitive: boolean): Function;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Context } from "koa";
|
|
2
|
+
/**
|
|
3
|
+
* Return the original Koa context.
|
|
4
|
+
* @decorator
|
|
5
|
+
* @operation
|
|
6
|
+
* @input
|
|
7
|
+
* @koa
|
|
8
|
+
*/
|
|
9
|
+
export declare function KoaCtx(): ParameterDecorator;
|
|
10
|
+
/**
|
|
11
|
+
* Return the original Koa context.
|
|
12
|
+
* @decorator
|
|
13
|
+
* @operation
|
|
14
|
+
* @input
|
|
15
|
+
* @koa
|
|
16
|
+
*/
|
|
17
|
+
export declare function Ctx(): ParameterDecorator;
|
|
18
|
+
export declare type Ctx = Context;
|
|
19
|
+
export declare type KoaCtx = Context;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/// <reference types="koa__router" />
|
|
2
|
+
import { RouterOptions } from "@koa/router";
|
|
3
|
+
/**
|
|
4
|
+
* Specify the behavior of the router controller.
|
|
5
|
+
*
|
|
6
|
+
* ```typescript
|
|
7
|
+
* @Controller("/")
|
|
8
|
+
* @RouterSettings({sensitive: true})
|
|
9
|
+
* class MyCtrl {
|
|
10
|
+
*
|
|
11
|
+
* }
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* Property | Description | Default
|
|
15
|
+
* ---|---|---
|
|
16
|
+
* sensitive | Enable case sensitivity. | Disabled by default, treating “/Foo” and “/foo” as the same.
|
|
17
|
+
* strict | Enable strict routing. | Disabled by default, “/foo” and “/foo/” are treated the same by the router.
|
|
18
|
+
*
|
|
19
|
+
* @returns {(target:any)=>void}
|
|
20
|
+
* @decorator
|
|
21
|
+
* @param routerOptions
|
|
22
|
+
* @koa
|
|
23
|
+
*/
|
|
24
|
+
export declare function RouterSettings(routerOptions: RouterOptions): Function;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* State return the value from koa.ctx.state object.
|
|
3
|
+
*
|
|
4
|
+
* #### Example
|
|
5
|
+
*
|
|
6
|
+
* ```typescript
|
|
7
|
+
* * @Middleware()
|
|
8
|
+
* class StateMiddleware {
|
|
9
|
+
* use(@State() state: any) {
|
|
10
|
+
* // set some on locals
|
|
11
|
+
* state.user = "user"
|
|
12
|
+
* }
|
|
13
|
+
* }
|
|
14
|
+
*
|
|
15
|
+
* @Controller('/')
|
|
16
|
+
* @UseBefore(StateMiddleware)
|
|
17
|
+
* class MyCtrl {
|
|
18
|
+
* @Get('/')
|
|
19
|
+
* @View('home.ejs') // will use locals and returned data to render the page
|
|
20
|
+
* get(@State('user') user: any) {
|
|
21
|
+
* console.log('user', user);
|
|
22
|
+
*
|
|
23
|
+
* return {
|
|
24
|
+
* description: 'Hello world'
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @param expression The path of the property to get.
|
|
31
|
+
* @decorator
|
|
32
|
+
* @operation
|
|
33
|
+
* @input
|
|
34
|
+
* @response
|
|
35
|
+
* @koa
|
|
36
|
+
*/
|
|
37
|
+
export declare function State(expression: string): ParameterDecorator;
|
|
38
|
+
export declare function State(): ParameterDecorator;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Specify the behavior of the router controller.
|
|
3
|
+
*
|
|
4
|
+
* ```typescript
|
|
5
|
+
* @Controller("/")
|
|
6
|
+
* @Strict(true)
|
|
7
|
+
* class MyCtrl {
|
|
8
|
+
*
|
|
9
|
+
* }
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* Property | Description | Default
|
|
13
|
+
* ---|---|---
|
|
14
|
+
* CaseSensitive | Enable case sensitivity. | Disabled by default, treating “/Foo” and “/foo” as the same.
|
|
15
|
+
* MergeParams | Preserve the req.params values from the parent router. If the parent and the child have conflicting param names, the child’s value take precedence. | false
|
|
16
|
+
* Strict | Enable strict routing. | Disabled by default, “/foo” and “/foo/” are treated the same by the router.
|
|
17
|
+
*
|
|
18
|
+
* @param strict
|
|
19
|
+
* @returns {Function}
|
|
20
|
+
* @decorator
|
|
21
|
+
* @koa
|
|
22
|
+
*/
|
|
23
|
+
export declare function Strict(strict: boolean): Function;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="koa__router" />
|
|
2
|
+
import { RouterOptions } from "@koa/router";
|
|
3
|
+
export interface PlatformKoaSettings {
|
|
4
|
+
/**
|
|
5
|
+
* Global configuration for the Express.Router. See express [documentation](http://expressjs.com/en/api.html#express.router).
|
|
6
|
+
*/
|
|
7
|
+
router: RouterOptions;
|
|
8
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import Koa from "koa";
|
|
2
|
+
import { PlatformKoaSettings } from "./PlatformKoaSettings";
|
|
3
|
+
export * from "./PlatformKoaSettings";
|
|
4
|
+
declare global {
|
|
5
|
+
namespace TsED {
|
|
6
|
+
interface Configuration {
|
|
7
|
+
/**
|
|
8
|
+
* Configuration related to Koa platform application.
|
|
9
|
+
*/
|
|
10
|
+
koa: PlatformKoaSettings;
|
|
11
|
+
}
|
|
12
|
+
interface NextFunction extends Koa.Next {
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/// <reference types="koa__router" />
|
|
2
|
+
import KoaRouter from "@koa/router";
|
|
3
|
+
import { Configuration, PlatformApplication, PlatformHandler } from "@tsed/common";
|
|
4
|
+
import Koa from "koa";
|
|
5
|
+
import { PlatformKoaRouter } from "./PlatformKoaRouter";
|
|
6
|
+
declare global {
|
|
7
|
+
namespace TsED {
|
|
8
|
+
interface Application extends Koa {
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* @platform
|
|
14
|
+
* @express
|
|
15
|
+
*/
|
|
16
|
+
export declare class PlatformKoaApplication extends PlatformKoaRouter implements PlatformApplication<Koa, KoaRouter> {
|
|
17
|
+
app: Koa;
|
|
18
|
+
rawApp: Koa;
|
|
19
|
+
constructor(platformHandler: PlatformHandler, configuration: Configuration);
|
|
20
|
+
getApp(): Koa;
|
|
21
|
+
callback(): any;
|
|
22
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { HandlerMetadata, OnRequestOptions, PlatformContext, PlatformHandler } from "@tsed/common";
|
|
2
|
+
import "./PlatformKoaRequest";
|
|
3
|
+
export declare class PlatformKoaHandler extends PlatformHandler {
|
|
4
|
+
flush(data: any, ctx: PlatformContext): Promise<void>;
|
|
5
|
+
protected createRawHandler(metadata: HandlerMetadata): any;
|
|
6
|
+
protected onRequest(requestOptions: OnRequestOptions): Promise<any>;
|
|
7
|
+
protected onError(error: unknown, requestOptions: OnRequestOptions): any;
|
|
8
|
+
protected onCtxRequest(requestOptions: OnRequestOptions): Promise<any>;
|
|
9
|
+
protected throwError(error: any, $ctx: PlatformContext): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import "@koa/router";
|
|
3
|
+
import { IncomingEvent, PlatformContext, PlatformRequest } from "@tsed/common";
|
|
4
|
+
import { IncomingMessage } from "http";
|
|
5
|
+
import Koa from "koa";
|
|
6
|
+
declare module "koa" {
|
|
7
|
+
interface Request {
|
|
8
|
+
id: string;
|
|
9
|
+
$ctx: PlatformContext;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
declare global {
|
|
13
|
+
namespace TsED {
|
|
14
|
+
interface Request extends Koa.Request {
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* @platform
|
|
20
|
+
* @koa
|
|
21
|
+
*/
|
|
22
|
+
export declare class PlatformKoaRequest extends PlatformRequest<Koa.Request> {
|
|
23
|
+
#private;
|
|
24
|
+
constructor(event: IncomingEvent, $ctx: PlatformContext);
|
|
25
|
+
get protocol(): string;
|
|
26
|
+
get host(): string;
|
|
27
|
+
get secure(): boolean;
|
|
28
|
+
get cookies(): {
|
|
29
|
+
[p: string]: any;
|
|
30
|
+
};
|
|
31
|
+
get session(): any;
|
|
32
|
+
getReq(): IncomingMessage;
|
|
33
|
+
destroy(): void;
|
|
34
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { IncomingEvent, PlatformContext, PlatformResponse } from "@tsed/common";
|
|
3
|
+
import { ServerResponse } from "http";
|
|
4
|
+
import Koa from "koa";
|
|
5
|
+
declare global {
|
|
6
|
+
namespace TsED {
|
|
7
|
+
interface Response extends Koa.Response {
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* @platform
|
|
13
|
+
* @koa
|
|
14
|
+
*/
|
|
15
|
+
export declare class PlatformKoaResponse extends PlatformResponse<Koa.Response> {
|
|
16
|
+
#private;
|
|
17
|
+
constructor(event: IncomingEvent, $ctx: PlatformContext);
|
|
18
|
+
get statusCode(): number;
|
|
19
|
+
get locals(): Koa.DefaultState;
|
|
20
|
+
/**
|
|
21
|
+
* Return the Node.js response object
|
|
22
|
+
*/
|
|
23
|
+
getRes(): ServerResponse;
|
|
24
|
+
hasStatus(): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Sets the HTTP status for the response.
|
|
27
|
+
*
|
|
28
|
+
* @param status
|
|
29
|
+
*/
|
|
30
|
+
status(status: number): this;
|
|
31
|
+
/**
|
|
32
|
+
* Set `Content-Type` response header with `type` through `mime.lookup()`
|
|
33
|
+
* when it does not contain "/", or set the Content-Type to `type` otherwise.
|
|
34
|
+
*
|
|
35
|
+
* Examples:
|
|
36
|
+
*
|
|
37
|
+
* res.type('.html');
|
|
38
|
+
* res.type('html');
|
|
39
|
+
* res.type('json');
|
|
40
|
+
* res.type('application/json');
|
|
41
|
+
* res.type('png');
|
|
42
|
+
*/
|
|
43
|
+
contentType(contentType: string): this;
|
|
44
|
+
getHeaders(): any;
|
|
45
|
+
/**
|
|
46
|
+
* Send any data to your consumer.
|
|
47
|
+
*
|
|
48
|
+
* This method accept a ReadableStream, a plain object, boolean, string, number, null and undefined data.
|
|
49
|
+
* It choose the better way to send the data.
|
|
50
|
+
*
|
|
51
|
+
* @param data
|
|
52
|
+
*/
|
|
53
|
+
body(data: any): this;
|
|
54
|
+
getBody(): any;
|
|
55
|
+
redirect(status: number, url: string): this;
|
|
56
|
+
location(location: string): this;
|
|
57
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/// <reference types="koa__router" />
|
|
2
|
+
import KoaRouter from "@koa/router";
|
|
3
|
+
import { RouterOptions as KoaRouterOptions } from "@koa/router";
|
|
4
|
+
import { PlatformHandler, PlatformMulter, PlatformMulterSettings, PlatformRouter, PlatformStaticsOptions } from "@tsed/common";
|
|
5
|
+
import { Configuration } from "@tsed/di";
|
|
6
|
+
import send from "koa-send";
|
|
7
|
+
declare global {
|
|
8
|
+
namespace TsED {
|
|
9
|
+
interface Router extends KoaRouter {
|
|
10
|
+
}
|
|
11
|
+
interface RouterOptions extends KoaRouterOptions {
|
|
12
|
+
}
|
|
13
|
+
interface StaticsOptions extends send.SendOptions {
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export declare class PlatformKoaRouter extends PlatformRouter<KoaRouter> {
|
|
18
|
+
constructor(platform: PlatformHandler, configuration: Configuration, routerOptions: any);
|
|
19
|
+
callback(): KoaRouter.Middleware<any, {}>[];
|
|
20
|
+
multer(options: PlatformMulterSettings): PlatformMulter;
|
|
21
|
+
statics(path: string, options: PlatformStaticsOptions): this;
|
|
22
|
+
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/platform-koa",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.89.0",
|
|
4
4
|
"description": "Koa package for Ts.ED framework",
|
|
5
|
-
"source": "./src/index.ts",
|
|
6
|
-
"main": "./lib/index.js",
|
|
7
|
-
"typings": "./lib/index.d.ts",
|
|
8
5
|
"private": false,
|
|
6
|
+
"source": "./src/index.ts",
|
|
7
|
+
"main": "./lib/cjs/index.js",
|
|
8
|
+
"typings": "./lib/types/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
"types": "./lib/types/index.d.ts",
|
|
11
|
+
"import": "./lib/esm/index.js",
|
|
12
|
+
"require": "./lib/cjs/index.js",
|
|
13
|
+
"default": "./lib/esm/index.js"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "yarn run build:esm && yarn run build:cjs",
|
|
17
|
+
"build:cjs": "tsc --build tsconfig.compile.json",
|
|
18
|
+
"build:esm": "tsc --build tsconfig.compile.esm.json",
|
|
19
|
+
"start": "ts-node -r tsconfig-paths/register test/app/index.ts"
|
|
20
|
+
},
|
|
9
21
|
"keywords": [
|
|
10
22
|
"Koa",
|
|
11
23
|
"TypeScript",
|
|
@@ -35,16 +47,12 @@
|
|
|
35
47
|
},
|
|
36
48
|
"homepage": "https://github.com/tsedio/tsed/tree/production/packages/platform/platform-koa",
|
|
37
49
|
"repository": "https://github.com/tsedio/tsed",
|
|
38
|
-
"scripts": {
|
|
39
|
-
"build": "tsc --build tsconfig.compile.json",
|
|
40
|
-
"start": "ts-node -r tsconfig-paths/register test/app/index.ts"
|
|
41
|
-
},
|
|
42
50
|
"devDependencies": {
|
|
43
51
|
"@koa/cors": "3.1.0",
|
|
44
|
-
"@tsed/common": "6.
|
|
45
|
-
"@tsed/core": "6.
|
|
46
|
-
"@tsed/di": "6.
|
|
47
|
-
"@tsed/platform-test-utils": "6.
|
|
52
|
+
"@tsed/common": "6.89.0",
|
|
53
|
+
"@tsed/core": "6.89.0",
|
|
54
|
+
"@tsed/di": "6.89.0",
|
|
55
|
+
"@tsed/platform-test-utils": "6.89.0",
|
|
48
56
|
"@types/koa": "2.11.3",
|
|
49
57
|
"@types/koa-bodyparser": "4.3.0",
|
|
50
58
|
"@types/koa-compose": "3.2.5",
|
|
@@ -69,13 +77,13 @@
|
|
|
69
77
|
"tslib": "2.2.0"
|
|
70
78
|
},
|
|
71
79
|
"peerDependencies": {
|
|
72
|
-
"@tsed/common": "^6.
|
|
73
|
-
"@tsed/core": "^6.
|
|
74
|
-
"@tsed/di": "^6.
|
|
75
|
-
"@tsed/json-mapper": "^6.
|
|
80
|
+
"@tsed/common": "^6.89.0",
|
|
81
|
+
"@tsed/core": "^6.89.0",
|
|
82
|
+
"@tsed/di": "^6.89.0",
|
|
83
|
+
"@tsed/json-mapper": "^6.89.0",
|
|
76
84
|
"@tsed/logger": ">=6.0.0",
|
|
77
|
-
"@tsed/openspec": "^6.
|
|
78
|
-
"@tsed/schema": "^6.
|
|
85
|
+
"@tsed/openspec": "^6.89.0",
|
|
86
|
+
"@tsed/schema": "^6.89.0",
|
|
79
87
|
"koa": ">=2.13.0",
|
|
80
88
|
"koa-bodyparser": ">=4.3.0",
|
|
81
89
|
"koa-compress": ">=5.0.1",
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.compile.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"baseUrl": ".",
|
|
5
|
+
"module": "ES2020",
|
|
6
|
+
"rootDir": "src",
|
|
7
|
+
"outDir": "./lib/esm",
|
|
8
|
+
"declaration": true,
|
|
9
|
+
"declarationDir": "./lib/types"
|
|
10
|
+
},
|
|
11
|
+
"exclude": [
|
|
12
|
+
"node_modules",
|
|
13
|
+
"test",
|
|
14
|
+
"lib",
|
|
15
|
+
"benchmark",
|
|
16
|
+
"coverage",
|
|
17
|
+
"spec",
|
|
18
|
+
"**/*.benchmark.ts",
|
|
19
|
+
"**/*.spec.ts",
|
|
20
|
+
"keys",
|
|
21
|
+
"jest.config.js"
|
|
22
|
+
]
|
|
23
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformKoa.js","sourceRoot":"","sources":["../../src/components/PlatformKoa.ts"],"names":[],"mappings":";;;AACA,yCAYsB;AAGtB,0FAAqF;AACrF,0CAAmI;AAGnI;;;GAGG;AACH,MAAa,WAAY,SAAQ,wBAA+B;IAwB9D,YAAY,OAA+B;QACzC,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,MAAM,QAAQ,GAAQ,CAAC,KAAU,EAAE,GAAgB,EAAE,EAAE;;YACrD,MAAA,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAqB,2BAAkB,CAAC,0CAAE,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC5F,CAAC,CAAC;QAEF,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,MAAM,GAAG,IAAI,CAAC;QAChC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC1C,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,MAAM,CAAC,MAAiB,EAAE,WAAwC,EAAE;QACzE,OAAO,IAAI,CAAC,KAAK,CAAc,WAAW,EAAE,MAAM,EAAE;YAClD,SAAS,EAAE,KAAK;YAChB,QAAQ,EAAE,KAAK;YACf,GAAG,QAAQ;YACX,qBAAqB,EAAE,IAAI;SAC5B,CAAC,CAAC;IACL,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,MAAiB,EAAE,WAAwC,EAAE;QAClF,OAAO,IAAI,CAAC,KAAK,CAAc,WAAW,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,SAAS,EAAE,CAAC;IAC5E,CAAC;IAES,SAAS;QACjB,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,uDAA0B,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,cAAc,EAAE,CAAC,CAAC;QAEhI,OAAO,IAAI,CAAC;IACd,CAAC;IAES,UAAU;QAClB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QAEtC,MAAM,MAAM,GAAG,sBAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAE5C,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,GAAY,EAAE,IAAU,EAAE,EAAE;YACvD,MAAM,MAAM,CAAC;gBACX,OAAO,EAAE,GAAG,CAAC,OAAc;gBAC3B,QAAQ,EAAE,GAAG,CAAC,QAAe;gBAC7B,GAAG;aACJ,CAAC,CAAC;YAEH,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;IACd,CAAC;;AA3EH,kCA4EC;AA3EQ,qBAAS,GAAG;IACjB;QACE,OAAO,EAAE,yBAAgB;QACzB,QAAQ,EAAE,8BAAmB;KAC9B;IACD;QACE,OAAO,EAAE,wBAAe;QACxB,QAAQ,EAAE,6BAAkB;KAC7B;IACD;QACE,OAAO,EAAE,wBAAe;QACxB,QAAQ,EAAE,6BAAkB;KAC7B;IACD;QACE,OAAO,EAAE,uBAAc;QACvB,QAAQ,EAAE,4BAAiB;KAC5B;IACD;QACE,OAAO,EAAE,4BAAmB;QAC5B,QAAQ,EAAE,iCAAsB;KACjC;CACF,CAAC","sourcesContent":["import KoaRouter from \"@koa/router\";\nimport {\n createContext,\n IProvider,\n PlatformApplication,\n PlatformBuilder,\n PlatformBuilderOptions,\n PlatformExceptions,\n PlatformHandler,\n PlatformRequest,\n PlatformResponse,\n PlatformRouter,\n PlatformViews\n} from \"@tsed/common\";\nimport {Type} from \"@tsed/core\";\nimport Koa, {Context, Next} from \"koa\";\nimport {resourceNotFoundMiddleware} from \"../middlewares/resourceNotFoundMiddleware\";\nimport {PlatformKoaApplication, PlatformKoaHandler, PlatformKoaRequest, PlatformKoaResponse, PlatformKoaRouter} from \"../services\";\nimport {getConfiguration} from \"@tsed/common/src/utils/getConfiguration\";\n\n/**\n * @platform\n * @koa\n */\nexport class PlatformKoa extends PlatformBuilder<Koa, KoaRouter> {\n static providers = [\n {\n provide: PlatformResponse,\n useClass: PlatformKoaResponse\n },\n {\n provide: PlatformRequest,\n useClass: PlatformKoaRequest\n },\n {\n provide: PlatformHandler,\n useClass: PlatformKoaHandler\n },\n {\n provide: PlatformRouter,\n useClass: PlatformKoaRouter\n },\n {\n provide: PlatformApplication,\n useClass: PlatformKoaApplication\n }\n ];\n\n constructor(options: PlatformBuilderOptions) {\n super(options);\n\n const listener: any = (error: any, ctx: Koa.Context) => {\n this.injector.get<PlatformExceptions>(PlatformExceptions)?.catch(error, ctx.request.$ctx);\n };\n\n this.app.getApp().silent = true;\n this.app.getApp().on(\"error\", listener);\n }\n\n /**\n * Create new serverless application. In this mode, the component scan are disabled.\n * @param module\n * @param settings\n */\n static create(module: Type<any>, settings: Partial<TsED.Configuration> = {}) {\n return this.build<PlatformKoa>(PlatformKoa, module, {\n httpsPort: false,\n httpPort: false,\n ...settings,\n disableComponentsScan: true\n });\n }\n\n static async bootstrap(module: Type<any>, settings: Partial<TsED.Configuration> = {}): Promise<PlatformKoa> {\n return this.build<PlatformKoa>(PlatformKoa, module, settings).bootstrap();\n }\n\n protected useRouter(): this {\n this.app.getApp().use(resourceNotFoundMiddleware).use(this.app.getRouter().routes()).use(this.app.getRouter().allowedMethods());\n\n return this;\n }\n\n protected useContext(): this {\n this.logger.info(\"Mount app context\");\n\n const invoke = createContext(this.injector);\n\n this.app.getApp().use(async (ctx: Context, next: Next) => {\n await invoke({\n request: ctx.request as any,\n response: ctx.response as any,\n ctx\n });\n\n return next();\n });\n\n return this;\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"caseSensitive.js","sourceRoot":"","sources":["../../src/decorators/caseSensitive.ts"],"names":[],"mappings":";;;AAAA,qDAAgD;AAEhD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAgB,aAAa,CAAC,SAAkB;IAC9C,OAAO,+BAAc,CAAC,EAAC,SAAS,EAAC,CAAC,CAAC;AACrC,CAAC;AAFD,sCAEC","sourcesContent":["import {RouterSettings} from \"./routerSettings\";\n\n/**\n * Specify the behavior of the router controller.\n *\n * ```typescript\n * @Controller(\"/\")\n * @CaseSensitive(true)\n * class MyCtrl {\n *\n * }\n * ```\n *\n * Property | Description | Default\n * ---|---|---\n * CaseSensitive | Enable case sensitivity. | Disabled by default, treating “/Foo” and “/foo” as the same.\n * Strict | Enable strict routing. | Disabled by default, “/foo” and “/foo/” are treated the same by the router.\n *\n * @returns {Function}\n * @decorator\n * @koa\n * @param sensitive\n */\nexport function CaseSensitive(sensitive: boolean) {\n return RouterSettings({sensitive});\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ctx.js","sourceRoot":"","sources":["../../src/decorators/ctx.ts"],"names":[],"mappings":";;;AAAA,yCAAsC;AAGtC;;;;;;GAMG;AACH,SAAgB,MAAM;IACpB,OAAO,iBAAQ,CAAC,SAAS,EAAE;QACzB,SAAS,EAAE,SAAS;QACpB,QAAQ,EAAE,kBAAkB;QAC5B,YAAY,EAAE,KAAK;QACnB,aAAa,EAAE,KAAK;KACrB,CAAC,CAAC;AACL,CAAC;AAPD,wBAOC;AAED;;;;;;GAMG;AACH,SAAgB,GAAG;IACjB,OAAO,MAAM,EAAE,CAAC;AAClB,CAAC;AAFD,kBAEC","sourcesContent":["import {UseParam} from \"@tsed/common\";\nimport type {Context} from \"koa\";\n\n/**\n * Return the original Koa context.\n * @decorator\n * @operation\n * @input\n * @koa\n */\nexport function KoaCtx(): ParameterDecorator {\n return UseParam(\"KOA_CTX\", {\n paramType: \"KOA_CTX\",\n dataPath: \"$ctx.request.ctx\",\n useConverter: false,\n useValidation: false\n });\n}\n\n/**\n * Return the original Koa context.\n * @decorator\n * @operation\n * @input\n * @koa\n */\nexport function Ctx(): ParameterDecorator {\n return KoaCtx();\n}\n\nexport type Ctx = Context;\nexport type KoaCtx = Context;\n"]}
|
package/lib/decorators/index.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./routerSettings"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./caseSensitive"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./strict"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./state"), exports);
|
|
8
|
-
tslib_1.__exportStar(require("./ctx"), exports);
|
|
9
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":";;;AAAA,2DAAiC;AACjC,0DAAgC;AAChC,mDAAyB;AACzB,kDAAwB;AACxB,gDAAsB","sourcesContent":["export * from \"./routerSettings\";\nexport * from \"./caseSensitive\";\nexport * from \"./strict\";\nexport * from \"./state\";\nexport * from \"./ctx\";\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"routerSettings.js","sourceRoot":"","sources":["../../src/decorators/routerSettings.ts"],"names":[],"mappings":";;;AAAA,yCAA4C;AAC5C,qCAAsC;AAGtC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAgB,cAAc,CAAC,aAA4B;IACzD,OAAO,iBAAU,CAAC,uBAAc,EAAE,aAAa,CAAC,CAAC;AACnD,CAAC;AAFD,wCAEC","sourcesContent":["import {ROUTER_OPTIONS} from \"@tsed/common\";\nimport {StoreMerge} from \"@tsed/core\";\nimport {RouterOptions} from \"@koa/router\";\n\n/**\n * Specify the behavior of the router controller.\n *\n * ```typescript\n * @Controller(\"/\")\n * @RouterSettings({sensitive: true})\n * class MyCtrl {\n *\n * }\n * ```\n *\n * Property | Description | Default\n * ---|---|---\n * sensitive | Enable case sensitivity. | Disabled by default, treating “/Foo” and “/foo” as the same.\n * strict | Enable strict routing. | Disabled by default, “/foo” and “/foo/” are treated the same by the router.\n *\n * @returns {(target:any)=>void}\n * @decorator\n * @param routerOptions\n * @koa\n */\nexport function RouterSettings(routerOptions: RouterOptions): Function {\n return StoreMerge(ROUTER_OPTIONS, routerOptions);\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/decorators/state.ts"],"names":[],"mappings":";;;AAAA,yCAAoC;AAwCpC,SAAgB,KAAK,CAAC,GAAG,IAAW;IAClC,OAAQ,eAAc,CAAC,GAAG,IAAI,CAAC,CAAC;AAClC,CAAC;AAFD,sBAEC","sourcesContent":["import {Locals} from \"@tsed/common\";\n\n/**\n * State return the value from koa.ctx.state object.\n *\n * #### Example\n *\n * ```typescript\n * * @Middleware()\n * class StateMiddleware {\n * use(@State() state: any) {\n * // set some on locals\n * state.user = \"user\"\n * }\n * }\n *\n * @Controller('/')\n * @UseBefore(StateMiddleware)\n * class MyCtrl {\n * @Get('/')\n * @View('home.ejs') // will use locals and returned data to render the page\n * get(@State('user') user: any) {\n * console.log('user', user);\n *\n * return {\n * description: 'Hello world'\n * }\n * }\n * }\n * ```\n *\n * @param expression The path of the property to get.\n * @decorator\n * @operation\n * @input\n * @response\n * @koa\n */\nexport function State(expression: string): ParameterDecorator;\nexport function State(): ParameterDecorator;\nexport function State(...args: any[]): ParameterDecorator {\n return (Locals as any)(...args);\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"strict.js","sourceRoot":"","sources":["../../src/decorators/strict.ts"],"names":[],"mappings":";;;AAAA,qDAAgD;AAEhD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAgB,MAAM,CAAC,MAAe;IACpC,OAAO,+BAAc,CAAC,EAAC,MAAM,EAAC,CAAC,CAAC;AAClC,CAAC;AAFD,wBAEC","sourcesContent":["import {RouterSettings} from \"./routerSettings\";\n\n/**\n * Specify the behavior of the router controller.\n *\n * ```typescript\n * @Controller(\"/\")\n * @Strict(true)\n * class MyCtrl {\n *\n * }\n * ```\n *\n * Property | Description | Default\n * ---|---|---\n * CaseSensitive | Enable case sensitivity. | Disabled by default, treating “/Foo” and “/foo” as the same.\n * MergeParams | Preserve the req.params values from the parent router. If the parent and the child have conflicting param names, the child’s value take precedence. | false\n * Strict | Enable strict routing. | Disabled by default, “/foo” and “/foo/” are treated the same by the router.\n *\n * @param strict\n * @returns {Function}\n * @decorator\n * @koa\n */\nexport function Strict(strict: boolean) {\n return RouterSettings({strict});\n}\n"]}
|
package/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,yCAA2D;AAC3D,0DAAqD;AAErD,qBAAY,CAAC,eAAe,GAAG,yBAAW,CAAC;AAC3C,wBAAe,CAAC,eAAe,GAAG,yBAAkB,CAAC;AAErD,aAAa;AACb,uDAA6B;AAE7B,aAAa;AACb,uDAA6B;AAE7B,WAAW;AACX,qDAA2B;AAE3B,aAAa;AACb,mEAAyC","sourcesContent":["import {PlatformBuilder, PlatformTest} from \"@tsed/common\";\nimport {PlatformKoa} from \"./components/PlatformKoa\";\n\nPlatformTest.platformBuilder = PlatformKoa;\nPlatformBuilder.currentPlatform = PlatformKoa as any;\n\n// interfaces\nexport * from \"./interfaces\";\n\n// decorators\nexport * from \"./decorators\";\n\n// services\nexport * from \"./services\";\n\n// components\nexport * from \"./components/PlatformKoa\";\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformKoaSettings.js","sourceRoot":"","sources":["../../src/interfaces/PlatformKoaSettings.ts"],"names":[],"mappings":"","sourcesContent":["import {RouterOptions} from \"@koa/router\";\n\nexport interface PlatformKoaSettings {\n /**\n * Global configuration for the Express.Router. See express [documentation](http://expressjs.com/en/api.html#express.router).\n */\n router: RouterOptions;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":";;;AAGA,gEAAsC","sourcesContent":["import Koa from \"koa\";\nimport {PlatformKoaSettings} from \"./PlatformKoaSettings\";\n\nexport * from \"./PlatformKoaSettings\";\n\ndeclare global {\n namespace TsED {\n export interface Configuration {\n /**\n * Configuration related to Koa platform application.\n */\n koa: PlatformKoaSettings;\n }\n\n export interface NextFunction extends Koa.Next {}\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resourceNotFoundMiddleware.js","sourceRoot":"","sources":["../../src/middlewares/resourceNotFoundMiddleware.ts"],"names":[],"mappings":";;;AAAA,yCAAiE;AAEjE;;;;GAIG;AACI,KAAK,UAAU,0BAA0B,CAAC,GAAQ,EAAE,IAAS;;IAClE,MAAM,IAAI,GAAoB,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC;IAC/C,MAAM,IAAI,EAAE,CAAC;IACb,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC;IAEjC,IAAI,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE;QACpC,MAAA,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAqB,2BAAkB,CAAC,0CAAE,gBAAgB,CAAC,IAAI,CAAC,CAAC;KACnF;AACH,CAAC;AARD,gEAQC","sourcesContent":["import {PlatformContext, PlatformExceptions} from \"@tsed/common\";\n\n/**\n * @ignore\n * @param ctx\n * @param next\n */\nexport async function resourceNotFoundMiddleware(ctx: any, next: any) {\n const $ctx: PlatformContext = ctx.request.$ctx;\n await next();\n const status = ctx.status || 404;\n\n if (status === 404 && !$ctx.isDone()) {\n $ctx.injector.get<PlatformExceptions>(PlatformExceptions)?.resourceNotFound($ctx);\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"staticsMiddleware.js","sourceRoot":"","sources":["../../src/middlewares/staticsMiddleware.ts"],"names":[],"mappings":";;;;AAEA,gEAA4B;AAE5B;;;GAGG;AACH,SAAgB,iBAAiB,CAAC,OAA+B;IAC/D,IAAI,OAAO,CAAC,KAAK,KAAK,KAAK;QAAE,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,YAAY,CAAC;IAE3E,OAAO,KAAK,EAAE,GAAY,EAAE,IAAS,EAAE,EAAE;QACvC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE;YACrD,IAAI,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;YAEpB,IAAI,GAAG,CAAC,aAAa,IAAI,GAAG,CAAC,aAAa,KAAK,GAAG,EAAE;gBAClD,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;aACzE;YACD,IAAI;gBACF,MAAM,IAAI,GAAG,MAAM,kBAAI,CAAC,GAAU,EAAE,IAAI,EAAE,OAA2B,CAAC,CAAC;gBAEvE,IAAI,IAAI,EAAE;oBACR,OAAO;iBACR;aACF;YAAC,OAAO,GAAG,EAAE;gBACZ,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,EAAE;oBACtB,MAAM,GAAG,CAAC;iBACX;aACF;SACF;QAED,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC;AAzBD,8CAyBC","sourcesContent":["import {PlatformStaticsOptions} from \"@tsed/common\";\nimport type {Context} from \"koa\";\nimport send from \"koa-send\";\n\n/**\n * @ignore\n * @param options\n */\nexport function staticsMiddleware(options: PlatformStaticsOptions): any {\n if (options.index !== false) options.index = options.index || \"index.html\";\n\n return async (ctx: Context, next: any) => {\n if ([\"GET\", \"HEAD\"].includes(ctx.method) && !ctx.body) {\n let path = ctx.path;\n\n if (ctx._matchedRoute && ctx._matchedRoute !== \"/\") {\n path = path.replace(String(ctx._matchedRoute).replace(\"/(.*)\", \"\"), \"\");\n }\n try {\n const done = await send(ctx as any, path, options as send.SendOptions);\n\n if (done) {\n return;\n }\n } catch (err) {\n if (err.status !== 404) {\n throw err;\n }\n }\n }\n\n return next();\n };\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformKoaApplication.js","sourceRoot":"","sources":["../../src/services/PlatformKoaApplication.ts"],"names":[],"mappings":";;;;AACA,yCAAyF;AACzF,sDAAsB;AACtB,2DAAsD;AAEtD,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAQhC;;;GAGG;AACH,IAAa,sBAAsB,GAAnC,MAAa,sBAAuB,SAAQ,qCAAiB;IAI3D,YAAsB,eAAgC,EAAmB,aAA4B;QACnG,KAAK,CAAC,eAAe,EAAE,aAAa,EAAE,EAAE,CAAC,CAAC;QAE1C,IAAI,CAAC,MAAM,GAAG,aAAa,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,IAAI,aAAG,EAAE,CAAC;QACxD,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACjC,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC;IAClC,CAAC;CACF,CAAA;AAlBY,sBAAsB;IAIpB,mBAAA,eAAM,EAAE,CAAA,EAAoC,mBAAA,sBAAa,EAAE,CAAA;6CAAjC,wBAAe;GAJ3C,sBAAsB,CAkBlC;AAlBY,wDAAsB","sourcesContent":["import KoaRouter from \"@koa/router\";\nimport {Configuration, Inject, PlatformApplication, PlatformHandler} from \"@tsed/common\";\nimport Koa from \"koa\";\nimport {PlatformKoaRouter} from \"./PlatformKoaRouter\";\n\nconst koaQs = require(\"koa-qs\");\n\ndeclare global {\n namespace TsED {\n export interface Application extends Koa {}\n }\n}\n\n/**\n * @platform\n * @express\n */\nexport class PlatformKoaApplication extends PlatformKoaRouter implements PlatformApplication<Koa, KoaRouter> {\n app: Koa;\n rawApp: Koa;\n\n constructor(@Inject() platformHandler: PlatformHandler, @Configuration() configuration: Configuration) {\n super(platformHandler, configuration, {});\n\n this.rawApp = configuration.get(\"koa.app\") || new Koa();\n koaQs(this.rawApp, \"extended\");\n }\n\n getApp(): Koa {\n return this.rawApp;\n }\n\n callback(): any {\n return this.getApp().callback();\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformKoaHandler.js","sourceRoot":"","sources":["../../src/services/PlatformKoaHandler.ts"],"names":[],"mappings":";;;AAAA,yCAA8G;AAE9G,gCAA8B;AAE9B,MAAM,cAAc,GAAG,CAAC,oBAAW,CAAC,QAAQ,EAAE,oBAAW,CAAC,UAAU,EAAE,oBAAW,CAAC,cAAc,EAAE,oBAAW,CAAC,MAAM,CAAC,CAAC;AAEtH,MAAa,kBAAmB,SAAQ,wBAAe;IAC9C,KAAK,CAAC,KAAK,CAAC,IAAS,EAAE,GAAoB;QAChD,IAAI,IAAI,KAAK,SAAS,IAAI,GAAG,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE;YAChD,IAAI,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC;SAC/B;QAED,OAAO,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAChC,CAAC;IAES,gBAAgB,CAAC,QAAyB;QAClD,IAAI,cAAc,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;YAC1C,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;YAC9C,OAAO,KAAK,EAAE,GAAgB,EAAE,IAAc,EAAE,EAAE,CAAC,OAAO,CAAC,EAAC,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC,IAAI,EAAC,CAAC,CAAC;SAC5F;QAED,OAAO,KAAK,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAC1C,CAAC;IAES,KAAK,CAAC,SAAS,CAAC,cAAgC;QACxD,MAAM,EAAC,QAAQ,EAAE,IAAI,EAAC,GAAG,cAAc,CAAC;QAExC,IAAI,IAAI,CAAC,IAAI,YAAY,KAAK,EAAE;YAC9B,IAAI,QAAQ,CAAC,aAAa,EAAE;gBAC1B,cAAc,CAAC,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC;aAChC;iBAAM;gBACL,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;aAChD;SACF;QAED,OAAO,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IACzC,CAAC;IAES,OAAO,CAAC,KAAc,EAAE,cAAgC;QAChE,MAAM,EAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAC,GAAG,cAAc,CAAC;QAE9C,uBAAuB;QACvB,IAAI,IAAI,CAAC,MAAM,EAAE,EAAE;YACjB,OAAO;SACR;QAED,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;QAElB,IAAI,CAAC,IAAI,IAAI,QAAQ,CAAC,OAAO,EAAE,EAAE;YAC/B,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;YAE7B,OAAO;SACR;QAED,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC;IAES,KAAK,CAAC,YAAY,CAAC,cAAgC;QAC3D,MAAM,EAAC,IAAI,EAAC,GAAG,cAAc,CAAC;QAE9B,IAAI;YACF,OAAO,MAAM,KAAK,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC;SACjD;QAAC,OAAO,KAAK,EAAE;YACd,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;SAC9B;IACH,CAAC;IAES,UAAU,CAAC,KAAU,EAAE,IAAqB;QACpD,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,GAAG,CAAC,CAAC;IAC5D,CAAC;CACF;AAhED,gDAgEC","sourcesContent":["import {HandlerMetadata, HandlerType, OnRequestOptions, PlatformContext, PlatformHandler} from \"@tsed/common\";\nimport Koa from \"koa\";\nimport \"./PlatformKoaRequest\";\n\nconst OVERRIDE_TYPES = [HandlerType.ENDPOINT, HandlerType.MIDDLEWARE, HandlerType.ERR_MIDDLEWARE, HandlerType.CTX_FN];\n\nexport class PlatformKoaHandler extends PlatformHandler {\n public async flush(data: any, ctx: PlatformContext): Promise<void> {\n if (data === undefined && ctx.getResponse().body) {\n data = ctx.getResponse().body;\n }\n\n return super.flush(data, ctx);\n }\n\n protected createRawHandler(metadata: HandlerMetadata) {\n if (OVERRIDE_TYPES.includes(metadata.type)) {\n const handler = this.compileHandler(metadata);\n return async (ctx: Koa.Context, next: Koa.Next) => handler({next, $ctx: ctx.request.$ctx});\n }\n\n return super.createRawHandler(metadata);\n }\n\n protected async onRequest(requestOptions: OnRequestOptions): Promise<any> {\n const {metadata, $ctx} = requestOptions;\n\n if ($ctx.data instanceof Error) {\n if (metadata.hasErrorParam) {\n requestOptions.err = $ctx.data;\n } else {\n return this.onError($ctx.data, requestOptions);\n }\n }\n\n return super.onRequest(requestOptions);\n }\n\n protected onError(error: unknown, requestOptions: OnRequestOptions) {\n const {next, $ctx, metadata} = requestOptions;\n\n // istanbul ignore next\n if ($ctx.isDone()) {\n return;\n }\n\n $ctx.data = error;\n\n if (!next || metadata.isFinal()) {\n this.throwError(error, $ctx);\n\n return;\n }\n\n return next();\n }\n\n protected async onCtxRequest(requestOptions: OnRequestOptions): Promise<any> {\n const {$ctx} = requestOptions;\n\n try {\n return await super.onCtxRequest(requestOptions);\n } catch (error) {\n this.throwError(error, $ctx);\n }\n }\n\n protected throwError(error: any, $ctx: PlatformContext) {\n $ctx.getApp().emit(\"error\", error, $ctx.getRequest().ctx);\n }\n}\n"]}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var _ctx;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.PlatformKoaRequest = void 0;
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
|
-
require("@koa/router");
|
|
7
|
-
const common_1 = require("@tsed/common");
|
|
8
|
-
/**
|
|
9
|
-
* @platform
|
|
10
|
-
* @koa
|
|
11
|
-
*/
|
|
12
|
-
class PlatformKoaRequest extends common_1.PlatformRequest {
|
|
13
|
-
constructor(event) {
|
|
14
|
-
super(event);
|
|
15
|
-
_ctx.set(this, void 0);
|
|
16
|
-
tslib_1.__classPrivateFieldSet(this, _ctx, this.raw.ctx);
|
|
17
|
-
}
|
|
18
|
-
get protocol() {
|
|
19
|
-
return tslib_1.__classPrivateFieldGet(this, _ctx).request.protocol;
|
|
20
|
-
}
|
|
21
|
-
get host() {
|
|
22
|
-
return tslib_1.__classPrivateFieldGet(this, _ctx).request.host;
|
|
23
|
-
}
|
|
24
|
-
get secure() {
|
|
25
|
-
return tslib_1.__classPrivateFieldGet(this, _ctx).request.secure;
|
|
26
|
-
}
|
|
27
|
-
get cookies() {
|
|
28
|
-
return tslib_1.__classPrivateFieldGet(this, _ctx).cookie || tslib_1.__classPrivateFieldGet(this, _ctx).cookies;
|
|
29
|
-
}
|
|
30
|
-
get session() {
|
|
31
|
-
return tslib_1.__classPrivateFieldGet(this, _ctx).session;
|
|
32
|
-
}
|
|
33
|
-
getReq() {
|
|
34
|
-
return this.raw.req;
|
|
35
|
-
}
|
|
36
|
-
destroy() {
|
|
37
|
-
// @ts-ignore
|
|
38
|
-
tslib_1.__classPrivateFieldSet(this, _ctx, null);
|
|
39
|
-
return super.destroy();
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
exports.PlatformKoaRequest = PlatformKoaRequest;
|
|
43
|
-
_ctx = new WeakMap();
|
|
44
|
-
//# sourceMappingURL=PlatformKoaRequest.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformKoaRequest.js","sourceRoot":"","sources":["../../src/services/PlatformKoaRequest.ts"],"names":[],"mappings":";;;;;AAAA,uBAAqB;AACrB,yCAA6E;AAiB7E;;;GAGG;AACH,MAAa,kBAAmB,SAAQ,wBAA4B;IAGlE,YAAY,KAAoB;QAC9B,KAAK,CAAC,KAAK,CAAC,CAAC;QAHf,uBAAkB;QAIhB,+BAAA,IAAI,QAAQ,IAAI,CAAC,GAAG,CAAC,GAAG,EAAC;IAC3B,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,2CAAU,OAAO,CAAC,QAAQ,CAAC;IACpC,CAAC;IAED,IAAI,IAAI;QACN,OAAO,2CAAU,OAAO,CAAC,IAAI,CAAC;IAChC,CAAC;IAED,IAAI,MAAM;QACR,OAAO,2CAAU,OAAO,CAAC,MAAM,CAAC;IAClC,CAAC;IAED,IAAI,OAAO;QACT,OAAO,2CAAU,MAAM,IAAI,2CAAU,OAAO,CAAC;IAC/C,CAAC;IAED,IAAI,OAAO;QACT,OAAO,2CAAU,OAAO,CAAC;IAC3B,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IACtB,CAAC;IAED,OAAO;QACL,aAAa;QACb,+BAAA,IAAI,QAAQ,IAAI,EAAC;QACjB,OAAO,KAAK,CAAC,OAAO,EAAE,CAAC;IACzB,CAAC;CACF;AArCD,gDAqCC","sourcesContent":["import \"@koa/router\";\nimport {IncomingEvent, PlatformContext, PlatformRequest} from \"@tsed/common\";\nimport {IncomingMessage} from \"http\";\nimport Koa from \"koa\";\n\ndeclare module \"koa\" {\n export interface Request {\n id: string;\n $ctx: PlatformContext;\n }\n}\n\ndeclare global {\n namespace TsED {\n export interface Request extends Koa.Request {}\n }\n}\n\n/**\n * @platform\n * @koa\n */\nexport class PlatformKoaRequest extends PlatformRequest<Koa.Request> {\n #ctx: Koa.Context;\n\n constructor(event: IncomingEvent) {\n super(event);\n this.#ctx = this.raw.ctx;\n }\n\n get protocol(): string {\n return this.#ctx.request.protocol;\n }\n\n get host(): string {\n return this.#ctx.request.host;\n }\n\n get secure(): boolean {\n return this.#ctx.request.secure;\n }\n\n get cookies(): {[p: string]: any} {\n return this.#ctx.cookie || this.#ctx.cookies;\n }\n\n get session(): any {\n return this.#ctx.session;\n }\n\n getReq(): IncomingMessage {\n return this.raw.req;\n }\n\n destroy() {\n // @ts-ignore\n this.#ctx = null;\n return super.destroy();\n }\n}\n"]}
|