@tsed/platform-koa 7.0.0-alpha.1 → 7.0.0-beta.10
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/cjs/components/PlatformKoa.js +145 -0
- package/lib/cjs/components/PlatformKoa.js.map +1 -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.js +1 -1
- package/lib/cjs/decorators/ctx.js.map +1 -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.js +0 -0
- package/lib/cjs/decorators/state.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/strict.js +1 -1
- package/lib/cjs/decorators/strict.js.map +1 -0
- package/lib/cjs/exports.js +7 -0
- package/lib/cjs/exports.js.map +1 -0
- package/lib/cjs/index.js +22 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/{interfaces → cjs/interfaces}/PlatformKoaSettings.js +0 -0
- package/lib/cjs/interfaces/PlatformKoaSettings.js.map +1 -0
- package/lib/{interfaces/index.js → cjs/interfaces/interfaces.js} +1 -1
- package/lib/cjs/interfaces/interfaces.js.map +1 -0
- package/lib/{middlewares → cjs/middlewares}/resourceNotFoundMiddleware.js +2 -2
- package/lib/cjs/middlewares/resourceNotFoundMiddleware.js.map +1 -0
- package/lib/{middlewares → cjs/middlewares}/staticsMiddleware.js +1 -1
- package/lib/cjs/middlewares/staticsMiddleware.js.map +1 -0
- package/lib/cjs/package.json +3 -0
- package/lib/{services → cjs/services}/PlatformKoaHandler.js +0 -0
- package/lib/cjs/services/PlatformKoaHandler.js.map +1 -0
- package/lib/cjs/services/PlatformKoaRequest.js +44 -0
- package/lib/cjs/services/PlatformKoaRequest.js.map +1 -0
- package/lib/{services → cjs/services}/PlatformKoaResponse.js +10 -10
- package/lib/cjs/services/PlatformKoaResponse.js.map +1 -0
- package/lib/cjs/utils/multer.js +80 -0
- package/lib/cjs/utils/multer.js.map +1 -0
- package/lib/esm/components/PlatformKoa.js +140 -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/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/exports.js +5 -0
- package/lib/esm/exports.js.map +1 -0
- package/lib/esm/index.js +19 -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/interfaces.js +2 -0
- package/lib/esm/interfaces/interfaces.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/package.json +3 -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/{utils → esm/utils}/multer.js +6 -8
- package/lib/esm/utils/multer.js.map +1 -0
- package/lib/types/components/PlatformKoa.d.ts +67 -0
- package/lib/{decorators → types/decorators}/caseSensitive.d.ts +0 -0
- package/lib/{decorators → types/decorators}/ctx.d.ts +0 -0
- package/lib/{decorators → types/decorators}/routerSettings.d.ts +0 -0
- package/lib/{decorators → types/decorators}/state.d.ts +0 -0
- package/lib/{decorators → types/decorators}/strict.d.ts +0 -0
- package/lib/types/exports.d.ts +1 -0
- package/lib/types/index.d.ts +18 -0
- package/lib/types/interfaces/PlatformKoaSettings.d.ts +15 -0
- package/lib/{interfaces/index.d.ts → types/interfaces/interfaces.d.ts} +0 -0
- package/lib/{middlewares → types/middlewares}/resourceNotFoundMiddleware.d.ts +0 -0
- package/lib/{middlewares → types/middlewares}/staticsMiddleware.d.ts +0 -0
- package/lib/{services → types/services}/PlatformKoaHandler.d.ts +0 -0
- package/lib/{services → types/services}/PlatformKoaRequest.d.ts +1 -1
- package/lib/{services → types/services}/PlatformKoaResponse.d.ts +3 -3
- package/lib/{utils → types/utils}/multer.d.ts +0 -0
- package/package.json +72 -38
- package/readme.md +0 -2
- package/tsconfig.compile.esm.json +12 -0
- package/lib/components/PlatformKoa.d.ts +0 -32
- package/lib/components/PlatformKoa.js +0 -65
- 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.d.ts +0 -5
- 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.d.ts +0 -4
- package/lib/index.js +0 -16
- package/lib/index.js.map +0 -1
- package/lib/interfaces/PlatformKoaSettings.d.ts +0 -8
- 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.d.ts +0 -22
- package/lib/services/PlatformKoaApplication.js +0 -31
- 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.d.ts +0 -22
- package/lib/services/PlatformKoaRouter.js +0 -45
- package/lib/services/PlatformKoaRouter.js.map +0 -1
- package/lib/services/index.d.ts +0 -5
- 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 @@
|
|
|
1
|
+
{"version":3,"file":"PlatformKoaResponse.js","sourceRoot":"","sources":["../../../src/services/PlatformKoaResponse.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAiC,gBAAgB,EAAC,MAAM,cAAc,CAAC;AAG9E,OAAO,EAAC,gBAAgB,EAAC,MAAM,cAAc,CAAC;AAC9C,OAAO,SAAS,MAAM,WAAW,CAAC;AAQlC;;;GAGG;AACH,MAAM,OAAO,mBAAoB,SAAQ,gBAA8B;IAGrE,YAAY,KAAoB,EAAE,IAAqB;QACrD,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QAHrB,2CAAkB;QAIhB,uBAAA,IAAI,4BAAQ,IAAI,CAAC,GAAG,CAAC,GAAG,MAAA,CAAC;IAC3B,CAAC;IAED,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC;IACzB,CAAC;IAED,IAAI,MAAM;QACR,OAAO,uBAAA,IAAI,gCAAK,CAAC,KAAK,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IACtB,CAAC;IAED,SAAS;QACP,yBAAyB;QACzB,OAAO,IAAI,CAAC,UAAU,KAAK,GAAG,CAAC;IACjC,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,MAAc;QACnB,IAAI,CAAC,GAAG,CAAC,MAA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KAAK,MAAM,EAAE;YACvB,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,GAAG,CAAC;SAChD;QAED,eAAe;QACf,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;QAE9C,OAAO,IAAI,CAAC;IACd,CAAC;CACF","sourcesContent":["import {IncomingEvent, PlatformContext, PlatformResponse} from \"@tsed/common\";\nimport {ServerResponse} from \"http\";\nimport Koa from \"koa\";\nimport {getStatusMessage} from \"@tsed/schema\";\nimport encodeUrl from \"encodeurl\";\n\ndeclare global {\n namespace TsED {\n export interface Response extends Koa.Response {}\n }\n}\n\n/**\n * @platform\n * @koa\n */\nexport class PlatformKoaResponse extends PlatformResponse<Koa.Response> {\n #ctx: Koa.Context;\n\n constructor(event: IncomingEvent, $ctx: PlatformContext) {\n super(event, $ctx);\n this.#ctx = this.raw.ctx;\n }\n\n get statusCode() {\n return this.raw.status;\n }\n\n get locals() {\n return this.#ctx.state;\n }\n\n /**\n * Return the Node.js response object\n */\n getRes(): ServerResponse {\n return this.raw.res;\n }\n\n hasStatus() {\n // KOA set 404 by default\n return this.statusCode !== 404;\n }\n\n /**\n * Sets the HTTP status for the response.\n *\n * @param status\n */\n status(status: number) {\n this.raw.status = status;\n\n return this;\n }\n\n /**\n * Set `Content-Type` response header with `type` through `mime.lookup()`\n * when it does not contain \"/\", or set the Content-Type to `type` otherwise.\n *\n * Examples:\n *\n * res.type('.html');\n * res.type('html');\n * res.type('json');\n * res.type('application/json');\n * res.type('png');\n */\n contentType(contentType: string) {\n this.raw.type = contentType;\n\n return this;\n }\n\n getHeaders() {\n return this.raw.headers;\n }\n\n /**\n * Send any data to your consumer.\n *\n * This method accept a ReadableStream, a plain object, boolean, string, number, null and undefined data.\n * It choose the better way to send the data.\n *\n * @param data\n */\n body(data: any): this {\n this.raw.body = data;\n\n return this;\n }\n\n getBody(): any {\n return this.raw.body;\n }\n\n redirect(status: number, url: string): this {\n status = status || 302;\n // Set location header\n url = this.location(url).raw.get(\"Location\");\n\n this.body(`${getStatusMessage(status)}. Redirecting to ${url}`);\n this.status(status);\n this.setHeader(\"Content-Length\", Buffer.byteLength(this.raw.body as any));\n\n if (this.request.method === \"HEAD\") {\n this.getRes().end();\n } else {\n this.getRes().end(this.getBody());\n }\n\n return this;\n }\n\n location(location: string): this {\n // \"back\" is an alias for the referrer\n if (location === \"back\") {\n location = this.request.get(\"Referrer\") || \"/\";\n }\n\n // set location\n this.raw.set(\"Location\", encodeUrl(location));\n\n return this;\n }\n}\n"]}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const util_1 = require("util");
|
|
1
|
+
import { promisify } from "util";
|
|
2
|
+
let multer;
|
|
3
|
+
import("multer").then(({ default: m }) => (multer = m));
|
|
5
4
|
/**
|
|
6
5
|
* @ignore
|
|
7
6
|
*/
|
|
@@ -36,14 +35,14 @@ function makePromise(multer, name) {
|
|
|
36
35
|
const fn = multer[name];
|
|
37
36
|
multer[name] = function apply(...args) {
|
|
38
37
|
const middleware = Reflect.apply(fn, this, args);
|
|
39
|
-
return createRawMiddleware(
|
|
38
|
+
return createRawMiddleware(promisify(middleware));
|
|
40
39
|
};
|
|
41
40
|
}
|
|
42
41
|
/**
|
|
43
42
|
* @ignore
|
|
44
43
|
*/
|
|
45
|
-
function getMulter(options) {
|
|
46
|
-
const m =
|
|
44
|
+
export function getMulter(options) {
|
|
45
|
+
const m = multer(options);
|
|
47
46
|
makePromise(m, "any");
|
|
48
47
|
makePromise(m, "array");
|
|
49
48
|
makePromise(m, "fields");
|
|
@@ -51,5 +50,4 @@ function getMulter(options) {
|
|
|
51
50
|
makePromise(m, "single");
|
|
52
51
|
return m;
|
|
53
52
|
}
|
|
54
|
-
exports.getMulter = getMulter;
|
|
55
53
|
//# sourceMappingURL=multer.js.map
|
|
@@ -0,0 +1 @@
|
|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AAE,IAAY;IAC5C,uBAAuB;IACvB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;QAAE,OAAO;IAE1B,MAAM,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAExB,MAAM,CAAC,IAAI,CAAC,GAAG,SAAS,KAAK,CAAC,GAAG,IAAW;QAC1C,MAAM,UAAU,GAAG,OAAO,CAAC,KAAK,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;QAEjD,OAAO,mBAAmB,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC;IACpD,CAAC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,OAAY;IACpC,MAAM,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IAE1B,WAAW,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IACtB,WAAW,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;IACxB,WAAW,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;IACzB,WAAW,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IACvB,WAAW,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;IAEzB,OAAO,CAAC,CAAC;AACX,CAAC","sourcesContent":["import Koa from \"koa\";\nimport {promisify} from \"util\";\n\nlet multer: any;\nimport(\"multer\").then(({default: m}) => (multer = m));\n\n/**\n * @ignore\n */\nfunction createRawMiddleware(middleware: any) {\n return async (request: Koa.Request) => {\n const ctx: any = request.ctx;\n\n await middleware(ctx.req, ctx.res);\n\n const forwardKey = (key: string) => {\n if (ctx.req[key]) {\n ctx.request[key] = ctx.req[key];\n ctx[key] = ctx.req[key];\n delete ctx.req[key];\n }\n };\n\n if (\"request\" in ctx) {\n if (ctx.req.body) {\n ctx.request.body = ctx.req.body;\n delete ctx.req.body;\n }\n\n forwardKey(\"file\");\n forwardKey(\"files\");\n }\n };\n}\n\n/**\n * @ignore\n */\nfunction makePromise(multer: any, name: string) {\n // istanbul ignore next\n if (!multer[name]) return;\n\n const fn = multer[name];\n\n multer[name] = function apply(...args: any[]) {\n const middleware = Reflect.apply(fn, this, args);\n\n return createRawMiddleware(promisify(middleware));\n };\n}\n\n/**\n * @ignore\n */\nexport function getMulter(options: any) {\n const m = multer(options);\n\n makePromise(m, \"any\");\n makePromise(m, \"array\");\n makePromise(m, \"fields\");\n makePromise(m, \"none\");\n makePromise(m, \"single\");\n\n return m;\n}\n"]}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/// <reference types="koa__router" />
|
|
2
|
+
import KoaRouter, { RouterOptions as KoaRouterOptions } from "@koa/router";
|
|
3
|
+
import { InjectorService, PlatformAdapter, PlatformBuilder, PlatformHandler, PlatformMulter, PlatformMulterSettings, PlatformRequest, PlatformResponse, PlatformStaticsOptions } from "@tsed/common";
|
|
4
|
+
import { Type } from "@tsed/core";
|
|
5
|
+
import Koa from "koa";
|
|
6
|
+
import { PlatformKoaResponse } from "../services/PlatformKoaResponse";
|
|
7
|
+
import { PlatformKoaRequest } from "../services/PlatformKoaRequest";
|
|
8
|
+
import { PlatformKoaHandler } from "../services/PlatformKoaHandler";
|
|
9
|
+
import send from "koa-send";
|
|
10
|
+
declare global {
|
|
11
|
+
namespace TsED {
|
|
12
|
+
interface Application extends Koa {
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
namespace TsED {
|
|
16
|
+
interface Router extends KoaRouter {
|
|
17
|
+
}
|
|
18
|
+
interface RouterOptions extends KoaRouterOptions {
|
|
19
|
+
}
|
|
20
|
+
interface StaticsOptions extends send.SendOptions {
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @platform
|
|
26
|
+
* @koa
|
|
27
|
+
*/
|
|
28
|
+
export declare class PlatformKoa implements PlatformAdapter<Koa, KoaRouter> {
|
|
29
|
+
private injector;
|
|
30
|
+
readonly providers: ({
|
|
31
|
+
provide: typeof PlatformResponse;
|
|
32
|
+
useClass: typeof PlatformKoaResponse;
|
|
33
|
+
} | {
|
|
34
|
+
provide: typeof PlatformRequest;
|
|
35
|
+
useClass: typeof PlatformKoaRequest;
|
|
36
|
+
} | {
|
|
37
|
+
provide: typeof PlatformHandler;
|
|
38
|
+
useClass: typeof PlatformKoaHandler;
|
|
39
|
+
})[];
|
|
40
|
+
constructor(injector: InjectorService);
|
|
41
|
+
/**
|
|
42
|
+
* Create new serverless application. In this mode, the component scan are disabled.
|
|
43
|
+
* @param module
|
|
44
|
+
* @param settings
|
|
45
|
+
*/
|
|
46
|
+
static create(module: Type<any>, settings?: Partial<TsED.Configuration>): PlatformBuilder<Koa<Koa.DefaultState, Koa.DefaultContext>, KoaRouter<Koa.DefaultState, Koa.DefaultContext>>;
|
|
47
|
+
/**
|
|
48
|
+
* Bootstrap a server application
|
|
49
|
+
* @param module
|
|
50
|
+
* @param settings
|
|
51
|
+
*/
|
|
52
|
+
static bootstrap(module: Type<any>, settings?: Partial<TsED.Configuration>): Promise<PlatformBuilder<Koa<Koa.DefaultState, Koa.DefaultContext>, KoaRouter<Koa.DefaultState, Koa.DefaultContext>>>;
|
|
53
|
+
onInit(): void;
|
|
54
|
+
useRouter(): this;
|
|
55
|
+
useContext(): this;
|
|
56
|
+
app(): {
|
|
57
|
+
app: any;
|
|
58
|
+
callback(): any;
|
|
59
|
+
};
|
|
60
|
+
router(routerOptions?: any): {
|
|
61
|
+
router: any;
|
|
62
|
+
callback(): any[];
|
|
63
|
+
};
|
|
64
|
+
multipart(options: PlatformMulterSettings): PlatformMulter;
|
|
65
|
+
statics(endpoint: string, options: PlatformStaticsOptions): any;
|
|
66
|
+
bodyParser(type: "json" | "urlencoded" | "raw" | "text", additionalOptions?: any): any;
|
|
67
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Automatically generated by barrelsby.
|
|
3
|
+
*/
|
|
4
|
+
export * from "./exports";
|
|
5
|
+
export * from "./components/PlatformKoa";
|
|
6
|
+
export * from "./decorators/caseSensitive";
|
|
7
|
+
export * from "./decorators/ctx";
|
|
8
|
+
export * from "./decorators/routerSettings";
|
|
9
|
+
export * from "./decorators/state";
|
|
10
|
+
export * from "./decorators/strict";
|
|
11
|
+
export * from "./interfaces/PlatformKoaSettings";
|
|
12
|
+
export * from "./interfaces/interfaces";
|
|
13
|
+
export * from "./middlewares/resourceNotFoundMiddleware";
|
|
14
|
+
export * from "./middlewares/staticsMiddleware";
|
|
15
|
+
export * from "./services/PlatformKoaHandler";
|
|
16
|
+
export * from "./services/PlatformKoaRequest";
|
|
17
|
+
export * from "./services/PlatformKoaResponse";
|
|
18
|
+
export * from "./utils/multer";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="koa__router" />
|
|
2
|
+
import type { RouterOptions } from "@koa/router";
|
|
3
|
+
import type { Middleware } from "koa";
|
|
4
|
+
import type { Options } from "koa-bodyparser";
|
|
5
|
+
export interface PlatformKoaSettings {
|
|
6
|
+
/**
|
|
7
|
+
* Koa router options
|
|
8
|
+
*/
|
|
9
|
+
router?: RouterOptions;
|
|
10
|
+
/**
|
|
11
|
+
* Body parser options
|
|
12
|
+
* @param opts
|
|
13
|
+
*/
|
|
14
|
+
bodyParser?: (opts?: Options) => Middleware | Options;
|
|
15
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -21,7 +21,7 @@ declare global {
|
|
|
21
21
|
*/
|
|
22
22
|
export declare class PlatformKoaRequest extends PlatformRequest<Koa.Request> {
|
|
23
23
|
#private;
|
|
24
|
-
constructor(event: IncomingEvent);
|
|
24
|
+
constructor(event: IncomingEvent, $ctx: PlatformContext);
|
|
25
25
|
get protocol(): string;
|
|
26
26
|
get host(): string;
|
|
27
27
|
get secure(): boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { IncomingEvent, PlatformResponse } from "@tsed/common";
|
|
2
|
+
import { IncomingEvent, PlatformContext, PlatformResponse } from "@tsed/common";
|
|
3
3
|
import { ServerResponse } from "http";
|
|
4
4
|
import Koa from "koa";
|
|
5
5
|
declare global {
|
|
@@ -14,7 +14,7 @@ declare global {
|
|
|
14
14
|
*/
|
|
15
15
|
export declare class PlatformKoaResponse extends PlatformResponse<Koa.Response> {
|
|
16
16
|
#private;
|
|
17
|
-
constructor(event: IncomingEvent);
|
|
17
|
+
constructor(event: IncomingEvent, $ctx: PlatformContext);
|
|
18
18
|
get statusCode(): number;
|
|
19
19
|
get locals(): Koa.DefaultState;
|
|
20
20
|
/**
|
|
@@ -41,7 +41,7 @@ export declare class PlatformKoaResponse extends PlatformResponse<Koa.Response>
|
|
|
41
41
|
* res.type('png');
|
|
42
42
|
*/
|
|
43
43
|
contentType(contentType: string): this;
|
|
44
|
-
getHeaders():
|
|
44
|
+
getHeaders(): import("http").OutgoingHttpHeaders;
|
|
45
45
|
/**
|
|
46
46
|
* Send any data to your consumer.
|
|
47
47
|
*
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,11 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/platform-koa",
|
|
3
|
-
"version": "7.0.0-
|
|
3
|
+
"version": "7.0.0-beta.10",
|
|
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
|
+
"module": "./lib/esm/index.js",
|
|
9
|
+
"typings": "./lib/types/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
"types": "./lib/types/index.d.ts",
|
|
12
|
+
"import": "./lib/esm/index.js",
|
|
13
|
+
"require": "./lib/cjs/index.js",
|
|
14
|
+
"default": "./lib/esm/index.js"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "yarn barrels && yarn run build:esm && yarn run build:cjs",
|
|
18
|
+
"build:cjs": "tsc --build tsconfig.compile.json",
|
|
19
|
+
"build:esm": "tsc --build tsconfig.compile.esm.json",
|
|
20
|
+
"barrels": "yarn barrelsby --delete -d ./src -e \"\\.spec\\.ts\" -e \"__mock__\" -e \".benchmark.ts\"",
|
|
21
|
+
"start": "ts-node -r tsconfig-paths/register test/app/index.ts"
|
|
22
|
+
},
|
|
9
23
|
"keywords": [
|
|
10
24
|
"Koa",
|
|
11
25
|
"TypeScript",
|
|
@@ -33,53 +47,73 @@
|
|
|
33
47
|
"bugs": {
|
|
34
48
|
"url": "https://github.com/tsedio/tsed/issues"
|
|
35
49
|
},
|
|
36
|
-
"homepage": "https://github.com/tsedio/tsed/tree/
|
|
50
|
+
"homepage": "https://github.com/tsedio/tsed/tree/beta/packages/platform/platform-koa",
|
|
37
51
|
"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
52
|
"devDependencies": {
|
|
43
|
-
"@koa/cors": "3.
|
|
44
|
-
"@tsed/common": "7.0.0-
|
|
45
|
-
"@tsed/core": "7.0.0-
|
|
46
|
-
"@tsed/di": "7.0.0-
|
|
47
|
-
"@tsed/platform-test-utils": "7.0.0-
|
|
48
|
-
"@types/koa": "2.
|
|
49
|
-
"@types/koa-bodyparser": "4.3.
|
|
53
|
+
"@koa/cors": "3.3.0",
|
|
54
|
+
"@tsed/common": "7.0.0-beta.10",
|
|
55
|
+
"@tsed/core": "7.0.0-beta.10",
|
|
56
|
+
"@tsed/di": "7.0.0-beta.10",
|
|
57
|
+
"@tsed/platform-test-utils": "7.0.0-beta.10",
|
|
58
|
+
"@types/koa": "2.13.4",
|
|
59
|
+
"@types/koa-bodyparser": "4.3.7",
|
|
50
60
|
"@types/koa-compose": "3.2.5",
|
|
51
|
-
"@types/koa-compress": "4.0.
|
|
52
|
-
"@types/koa-json": "2.0.
|
|
53
|
-
"@types/koa-mount": "4.0.
|
|
54
|
-
"@types/koa-send": "4.1.
|
|
55
|
-
"@types/koa-session": "5.10.
|
|
56
|
-
"@types/koa__router": "8.0.
|
|
57
|
-
"koa": "2.13.
|
|
61
|
+
"@types/koa-compress": "4.0.3",
|
|
62
|
+
"@types/koa-json": "2.0.20",
|
|
63
|
+
"@types/koa-mount": "4.0.1",
|
|
64
|
+
"@types/koa-send": "4.1.3",
|
|
65
|
+
"@types/koa-session": "5.10.6",
|
|
66
|
+
"@types/koa__router": "8.0.11",
|
|
67
|
+
"koa": "2.13.4",
|
|
58
68
|
"koa-bodyparser": "4.3.0",
|
|
59
|
-
"koa-compress": "5.0
|
|
69
|
+
"koa-compress": "5.1.0",
|
|
60
70
|
"koa-override": "3.0.0",
|
|
61
71
|
"koa-qs": "^3.0.0",
|
|
62
72
|
"koa-session": "6.2.0"
|
|
63
73
|
},
|
|
64
74
|
"dependencies": {
|
|
65
|
-
"@koa/router": "^
|
|
75
|
+
"@koa/router": "^10.1.1",
|
|
66
76
|
"encodeurl": "^1.0.2",
|
|
67
77
|
"koa-send": "5.0.1",
|
|
68
78
|
"multer": "^1.4.2",
|
|
69
|
-
"tslib": "2.
|
|
79
|
+
"tslib": "2.3.1"
|
|
70
80
|
},
|
|
71
81
|
"peerDependencies": {
|
|
72
|
-
"@tsed/common": "^7.0.0-
|
|
73
|
-
"@tsed/core": "^7.0.0-
|
|
74
|
-
"@tsed/di": "^7.0.0-
|
|
75
|
-
"@tsed/json-mapper": "^7.0.0-
|
|
76
|
-
"@tsed/logger": "
|
|
77
|
-
"@tsed/openspec": "^7.0.0-
|
|
78
|
-
"@tsed/schema": "^7.0.0-
|
|
79
|
-
"koa": "2.13.0",
|
|
80
|
-
"koa-bodyparser": "4.3.0",
|
|
81
|
-
"koa-compress": "5.0.1",
|
|
82
|
-
"koa-override": "3.0.0",
|
|
83
|
-
"koa-
|
|
82
|
+
"@tsed/common": "^7.0.0-beta.10",
|
|
83
|
+
"@tsed/core": "^7.0.0-beta.10",
|
|
84
|
+
"@tsed/di": "^7.0.0-beta.10",
|
|
85
|
+
"@tsed/json-mapper": "^7.0.0-beta.10",
|
|
86
|
+
"@tsed/logger": ">=6.1.1",
|
|
87
|
+
"@tsed/openspec": "^7.0.0-beta.10",
|
|
88
|
+
"@tsed/schema": "^7.0.0-beta.10",
|
|
89
|
+
"koa": ">=2.13.0",
|
|
90
|
+
"koa-bodyparser": ">=4.3.0",
|
|
91
|
+
"koa-compress": ">=5.0.1",
|
|
92
|
+
"koa-override": ">=3.0.0",
|
|
93
|
+
"koa-qs": ">=3.0.0",
|
|
94
|
+
"koa-session": ">=6.2.0"
|
|
95
|
+
},
|
|
96
|
+
"peerDependenciesMeta": {
|
|
97
|
+
"@tsed/common": {
|
|
98
|
+
"optional": false
|
|
99
|
+
},
|
|
100
|
+
"@tsed/core": {
|
|
101
|
+
"optional": false
|
|
102
|
+
},
|
|
103
|
+
"@tsed/di": {
|
|
104
|
+
"optional": false
|
|
105
|
+
},
|
|
106
|
+
"@tsed/json-mapper": {
|
|
107
|
+
"optional": false
|
|
108
|
+
},
|
|
109
|
+
"@tsed/openspec": {
|
|
110
|
+
"optional": false
|
|
111
|
+
},
|
|
112
|
+
"@tsed/schema": {
|
|
113
|
+
"optional": false
|
|
114
|
+
},
|
|
115
|
+
"@tsed/logger": {
|
|
116
|
+
"optional": false
|
|
117
|
+
}
|
|
84
118
|
}
|
|
85
119
|
}
|
package/readme.md
CHANGED
|
@@ -44,14 +44,12 @@ Please read [contributing guidelines here](https://tsed.io/CONTRIBUTING.html)
|
|
|
44
44
|
|
|
45
45
|
<a href="https://github.com/tsedio/ts-express-decorators/graphs/contributors"><img src="https://opencollective.com/tsed/contributors.svg?width=890" /></a>
|
|
46
46
|
|
|
47
|
-
|
|
48
47
|
## Backers
|
|
49
48
|
|
|
50
49
|
Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/tsed#backer)]
|
|
51
50
|
|
|
52
51
|
<a href="https://opencollective.com/tsed#backers" target="_blank"><img src="https://opencollective.com/tsed/backers.svg?width=890"></a>
|
|
53
52
|
|
|
54
|
-
|
|
55
53
|
## Sponsors
|
|
56
54
|
|
|
57
55
|
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/tsed#sponsor)]
|
|
@@ -0,0 +1,12 @@
|
|
|
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": ["node_modules", "test", "lib", "benchmark", "coverage", "spec", "**/*.benchmark.ts", "**/*.spec.ts", "keys", "jest.config.js"]
|
|
12
|
+
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/// <reference types="koa__router" />
|
|
2
|
-
import KoaRouter from "@koa/router";
|
|
3
|
-
import { PlatformApplication, PlatformBuilder, 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
|
-
static bootstrap(module: Type<any>, settings?: Partial<TsED.Configuration>): Promise<PlatformKoa>;
|
|
29
|
-
protected createInjector(module: Type<any>, settings: any): void;
|
|
30
|
-
protected useRouter(): this;
|
|
31
|
-
protected useContext(): this;
|
|
32
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PlatformKoa = void 0;
|
|
4
|
-
const common_1 = require("@tsed/common");
|
|
5
|
-
const resourceNotFoundMiddleware_1 = require("../middlewares/resourceNotFoundMiddleware");
|
|
6
|
-
const services_1 = require("../services");
|
|
7
|
-
/**
|
|
8
|
-
* @platform
|
|
9
|
-
* @koa
|
|
10
|
-
*/
|
|
11
|
-
class PlatformKoa extends common_1.PlatformBuilder {
|
|
12
|
-
static async bootstrap(module, settings = {}) {
|
|
13
|
-
return this.build(PlatformKoa).bootstrap(module, settings);
|
|
14
|
-
}
|
|
15
|
-
createInjector(module, settings) {
|
|
16
|
-
super.createInjector(module, settings);
|
|
17
|
-
const listener = (error, ctx) => {
|
|
18
|
-
var _a;
|
|
19
|
-
(_a = this.injector.get(common_1.PlatformExceptions)) === null || _a === void 0 ? void 0 : _a.catch(error, ctx.request.$ctx);
|
|
20
|
-
};
|
|
21
|
-
this.app.getApp().silent = true;
|
|
22
|
-
this.app.getApp().on("error", listener);
|
|
23
|
-
}
|
|
24
|
-
useRouter() {
|
|
25
|
-
this.app.getApp().use(resourceNotFoundMiddleware_1.resourceNotFoundMiddleware).use(this.app.getRouter().routes()).use(this.app.getRouter().allowedMethods());
|
|
26
|
-
return this;
|
|
27
|
-
}
|
|
28
|
-
useContext() {
|
|
29
|
-
this.logger.info("Mount app context");
|
|
30
|
-
const invoke = common_1.createContext(this.injector);
|
|
31
|
-
this.app.getApp().use(async (ctx, next) => {
|
|
32
|
-
await invoke({
|
|
33
|
-
request: ctx.request,
|
|
34
|
-
response: ctx.response,
|
|
35
|
-
ctx
|
|
36
|
-
});
|
|
37
|
-
return next();
|
|
38
|
-
});
|
|
39
|
-
return this;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
exports.PlatformKoa = PlatformKoa;
|
|
43
|
-
PlatformKoa.providers = [
|
|
44
|
-
{
|
|
45
|
-
provide: common_1.PlatformResponse,
|
|
46
|
-
useClass: services_1.PlatformKoaResponse
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
provide: common_1.PlatformRequest,
|
|
50
|
-
useClass: services_1.PlatformKoaRequest
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
provide: common_1.PlatformHandler,
|
|
54
|
-
useClass: services_1.PlatformKoaHandler
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
provide: common_1.PlatformRouter,
|
|
58
|
-
useClass: services_1.PlatformKoaRouter
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
provide: common_1.PlatformApplication,
|
|
62
|
-
useClass: services_1.PlatformKoaApplication
|
|
63
|
-
}
|
|
64
|
-
];
|
|
65
|
-
//# sourceMappingURL=PlatformKoa.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformKoa.js","sourceRoot":"","sources":["../../src/components/PlatformKoa.ts"],"names":[],"mappings":";;;AACA,yCAUsB;AAGtB,0FAAqF;AACrF,0CAAmI;AAEnI;;;GAGG;AAC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E,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;;AA7DH,kCA8DC;AA7DQ,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 PlatformApplication,\n PlatformBuilder,\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\";\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 static async bootstrap(module: Type<any>, settings: Partial<TsED.Configuration> = {}): Promise<PlatformKoa> {\n return this.build<PlatformKoa>(PlatformKoa).bootstrap(module, settings);\n }\n\n protected createInjector(module: Type<any>, settings: any) {\n super.createInjector(module, settings);\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 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;QACd,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({\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.d.ts
DELETED
package/lib/index.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const common_1 = require("@tsed/common");
|
|
5
|
-
const PlatformKoa_1 = require("./components/PlatformKoa");
|
|
6
|
-
common_1.PlatformTest.platformBuilder = PlatformKoa_1.PlatformKoa;
|
|
7
|
-
common_1.PlatformBuilder.currentPlatform = PlatformKoa_1.PlatformKoa;
|
|
8
|
-
// interfaces
|
|
9
|
-
tslib_1.__exportStar(require("./interfaces"), exports);
|
|
10
|
-
// decorators
|
|
11
|
-
tslib_1.__exportStar(require("./decorators"), exports);
|
|
12
|
-
// services
|
|
13
|
-
tslib_1.__exportStar(require("./services"), exports);
|
|
14
|
-
// components
|
|
15
|
-
tslib_1.__exportStar(require("./components/PlatformKoa"), exports);
|
|
16
|
-
//# sourceMappingURL=index.js.map
|
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,8 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -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"]}
|