@tsed/platform-koa 7.0.0-beta.13 → 7.0.0-beta.16
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/jest.config.js +3 -3
- package/lib/cjs/components/PlatformKoa.js +50 -32
- package/lib/cjs/components/PlatformKoa.js.map +1 -1
- package/lib/cjs/index.js +0 -4
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/services/PlatformKoaHandler.js +14 -43
- package/lib/cjs/services/PlatformKoaHandler.js.map +1 -1
- package/lib/cjs/services/PlatformKoaRequest.js +1 -1
- package/lib/cjs/services/PlatformKoaRequest.js.map +1 -1
- package/lib/esm/components/PlatformKoa.js +51 -33
- package/lib/esm/components/PlatformKoa.js.map +1 -1
- package/lib/esm/index.js +0 -4
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/services/PlatformKoaHandler.js +15 -44
- package/lib/esm/services/PlatformKoaHandler.js.map +1 -1
- package/lib/esm/services/PlatformKoaRequest.js +1 -1
- package/lib/esm/services/PlatformKoaRequest.js.map +1 -1
- package/lib/types/components/PlatformKoa.d.ts +7 -14
- package/lib/types/index.d.ts +0 -4
- package/lib/types/services/PlatformKoaHandler.d.ts +4 -7
- package/package.json +11 -11
- package/readme.md +1 -1
- package/lib/cjs/decorators/caseSensitive.js +0 -30
- package/lib/cjs/decorators/caseSensitive.js.map +0 -1
- package/lib/cjs/decorators/routerSettings.js +0 -31
- package/lib/cjs/decorators/routerSettings.js.map +0 -1
- package/lib/cjs/decorators/strict.js +0 -31
- package/lib/cjs/decorators/strict.js.map +0 -1
- package/lib/cjs/middlewares/resourceNotFoundMiddleware.js +0 -19
- package/lib/cjs/middlewares/resourceNotFoundMiddleware.js.map +0 -1
- package/lib/esm/decorators/caseSensitive.js +0 -26
- package/lib/esm/decorators/caseSensitive.js.map +0 -1
- package/lib/esm/decorators/routerSettings.js +0 -27
- package/lib/esm/decorators/routerSettings.js.map +0 -1
- package/lib/esm/decorators/strict.js +0 -27
- package/lib/esm/decorators/strict.js.map +0 -1
- package/lib/esm/middlewares/resourceNotFoundMiddleware.js +0 -15
- package/lib/esm/middlewares/resourceNotFoundMiddleware.js.map +0 -1
- package/lib/types/decorators/caseSensitive.d.ts +0 -22
- package/lib/types/decorators/routerSettings.d.ts +0 -24
- package/lib/types/decorators/strict.d.ts +0 -23
- package/lib/types/middlewares/resourceNotFoundMiddleware.d.ts +0 -6
package/jest.config.js
CHANGED
|
@@ -5,10 +5,10 @@ module.exports = {
|
|
|
5
5
|
...require("@tsed/jest-config")(__dirname, "platform-koa"),
|
|
6
6
|
coverageThreshold: {
|
|
7
7
|
global: {
|
|
8
|
-
statements: 99.
|
|
9
|
-
branches:
|
|
8
|
+
statements: 99.44,
|
|
9
|
+
branches: 90.9,
|
|
10
10
|
functions: 100,
|
|
11
|
-
lines: 99.
|
|
11
|
+
lines: 99.43
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
};
|
|
@@ -4,13 +4,12 @@ exports.PlatformKoa = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const router_1 = tslib_1.__importDefault(require("@koa/router"));
|
|
6
6
|
const common_1 = require("@tsed/common");
|
|
7
|
-
const platform_exceptions_1 = require("@tsed/platform-exceptions");
|
|
8
7
|
const core_1 = require("@tsed/core");
|
|
8
|
+
const platform_exceptions_1 = require("@tsed/platform-exceptions");
|
|
9
9
|
const koa_1 = tslib_1.__importDefault(require("koa"));
|
|
10
10
|
const koa_bodyparser_1 = tslib_1.__importDefault(require("koa-bodyparser"));
|
|
11
11
|
// @ts-ignore
|
|
12
12
|
const koa_qs_1 = tslib_1.__importDefault(require("koa-qs"));
|
|
13
|
-
const resourceNotFoundMiddleware_1 = require("../middlewares/resourceNotFoundMiddleware");
|
|
14
13
|
const staticsMiddleware_1 = require("../middlewares/staticsMiddleware");
|
|
15
14
|
const PlatformKoaHandler_1 = require("../services/PlatformKoaHandler");
|
|
16
15
|
const PlatformKoaRequest_1 = require("../services/PlatformKoaRequest");
|
|
@@ -73,31 +72,58 @@ class PlatformKoa {
|
|
|
73
72
|
});
|
|
74
73
|
}
|
|
75
74
|
onInit() {
|
|
76
|
-
const
|
|
77
|
-
const app = this.injector.get(common_1.PlatformApplication);
|
|
78
|
-
const listener = (error, ctx) => {
|
|
79
|
-
injector.get(platform_exceptions_1.PlatformExceptions)?.catch(error, ctx.request.$ctx);
|
|
80
|
-
};
|
|
75
|
+
const app = this.getPlatformApplication();
|
|
81
76
|
app.getApp().silent = true;
|
|
82
|
-
app.getApp().on("error", listener);
|
|
83
77
|
}
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
app.
|
|
87
|
-
|
|
88
|
-
|
|
78
|
+
mapLayers(layers) {
|
|
79
|
+
const { settings } = this.injector;
|
|
80
|
+
const app = this.getPlatformApplication();
|
|
81
|
+
const options = settings.get("koa.router", {});
|
|
82
|
+
const rawRouter = new router_1.default(options);
|
|
83
|
+
layers.forEach((layer) => {
|
|
84
|
+
switch (layer.method) {
|
|
85
|
+
case "statics":
|
|
86
|
+
rawRouter.use(layer.path, this.statics(layer.path, layer.opts));
|
|
87
|
+
break;
|
|
88
|
+
default:
|
|
89
|
+
rawRouter[layer.method](...layer.getArgs());
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
app.getApp().use(rawRouter.routes()).use(rawRouter.allowedMethods());
|
|
93
|
+
}
|
|
94
|
+
mapHandler(handler, metadata) {
|
|
95
|
+
if (metadata.isRawMiddleware()) {
|
|
96
|
+
return handler;
|
|
97
|
+
}
|
|
98
|
+
return async (koaContext, next) => {
|
|
99
|
+
const $ctx = (0, common_1.getContext)();
|
|
100
|
+
$ctx.next = next;
|
|
101
|
+
await handler($ctx);
|
|
102
|
+
};
|
|
89
103
|
}
|
|
90
104
|
useContext() {
|
|
91
|
-
const app = this.
|
|
92
|
-
const { logger } = this.injector;
|
|
93
|
-
logger.info("Mount app context");
|
|
105
|
+
const app = this.getPlatformApplication();
|
|
94
106
|
const invoke = (0, common_1.createContext)(this.injector);
|
|
95
|
-
app.
|
|
96
|
-
await invoke({
|
|
97
|
-
request:
|
|
98
|
-
response:
|
|
107
|
+
app.use(async (koaContext, next) => {
|
|
108
|
+
const $ctx = await invoke({
|
|
109
|
+
request: koaContext.request,
|
|
110
|
+
response: koaContext.response,
|
|
111
|
+
koaContext
|
|
99
112
|
});
|
|
100
|
-
|
|
113
|
+
try {
|
|
114
|
+
await $ctx.start();
|
|
115
|
+
await $ctx.runInContext(next);
|
|
116
|
+
const status = koaContext.status || 404;
|
|
117
|
+
if (status === 404 && !$ctx.isDone()) {
|
|
118
|
+
this.injector.get(platform_exceptions_1.PlatformExceptions)?.resourceNotFound($ctx);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
this.injector.get(platform_exceptions_1.PlatformExceptions)?.catch(error, $ctx);
|
|
123
|
+
}
|
|
124
|
+
finally {
|
|
125
|
+
await $ctx.finish();
|
|
126
|
+
}
|
|
101
127
|
});
|
|
102
128
|
return this;
|
|
103
129
|
}
|
|
@@ -111,17 +137,6 @@ class PlatformKoa {
|
|
|
111
137
|
}
|
|
112
138
|
};
|
|
113
139
|
}
|
|
114
|
-
router(routerOptions = {}) {
|
|
115
|
-
const { settings } = this.injector;
|
|
116
|
-
const options = Object.assign({}, settings.get("koa.router", {}), routerOptions);
|
|
117
|
-
const router = new router_1.default(options);
|
|
118
|
-
return {
|
|
119
|
-
router,
|
|
120
|
-
callback() {
|
|
121
|
-
return [router.routes(), router.allowedMethods()];
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
140
|
multipart(options) {
|
|
126
141
|
return (0, multer_1.getMulter)(options);
|
|
127
142
|
}
|
|
@@ -138,6 +153,9 @@ class PlatformKoa {
|
|
|
138
153
|
}
|
|
139
154
|
return parser({ ...options, ...additionalOptions });
|
|
140
155
|
}
|
|
156
|
+
getPlatformApplication() {
|
|
157
|
+
return this.injector.get(common_1.PlatformApplication);
|
|
158
|
+
}
|
|
141
159
|
}
|
|
142
160
|
exports.PlatformKoa = PlatformKoa;
|
|
143
161
|
//# sourceMappingURL=PlatformKoa.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformKoa.js","sourceRoot":"","sources":["../../../src/components/PlatformKoa.ts"],"names":[],"mappings":";;;;AAAA,iEAAyE;AACzE,
|
|
1
|
+
{"version":3,"file":"PlatformKoa.js","sourceRoot":"","sources":["../../../src/components/PlatformKoa.ts"],"names":[],"mappings":";;;;AAAA,iEAAyE;AACzE,yCAcsB;AACtB,qCAA4C;AAC5C,mEAA6D;AAE7D,sDAAuC;AACvC,4EAAsD;AACtD,aAAa;AACb,4DAA2B;AAE3B,wEAAmE;AACnE,uEAAkE;AAClE,uEAAkE;AAClE,yEAAoE;AACpE,4CAA0C;AAY1C,aAAa;AACb,gBAAS,CAAC,SAAS,CAAC,OAAO,GAAG,gBAAS,CAAC,SAAS,CAAC,KAAK,CAAC;AACxD,gBAAS,CAAC,SAAS,CAAC,KAAK,GAAG,SAAS,KAAK,CAAC,GAAG,IAAW;IACvD,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;IACtC,IAAI,OAAO,EAAE;QACX,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE;YACvB,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;SACtB;KACF;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAa,WAAW;IAgBF;IAfX,SAAS,GAAG;QACnB;YACE,OAAO,EAAE,yBAAgB;YACzB,QAAQ,EAAE,yCAAmB;SAC9B;QACD;YACE,OAAO,EAAE,wBAAe;YACxB,QAAQ,EAAE,uCAAkB;SAC7B;QACD;YACE,OAAO,EAAE,wBAAe;YACxB,QAAQ,EAAE,uCAAkB;SAC7B;KACF,CAAC;IAEF,YAAoB,QAAyB;QAAzB,aAAQ,GAAR,QAAQ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ACF;AAnJD,kCAmJC","sourcesContent":["import KoaRouter, {RouterOptions as KoaRouterOptions} from \"@koa/router\";\nimport {\n createContext,\n getContext,\n InjectorService,\n PlatformAdapter,\n PlatformApplication,\n PlatformBuilder,\n PlatformContext,\n PlatformHandler,\n PlatformMulter,\n PlatformMulterSettings,\n PlatformRequest,\n PlatformResponse,\n PlatformStaticsOptions\n} from \"@tsed/common\";\nimport {isFunction, Type} from \"@tsed/core\";\nimport {PlatformExceptions} from \"@tsed/platform-exceptions\";\nimport {PlatformHandlerMetadata, PlatformLayer} from \"@tsed/platform-router\";\nimport Koa, {Context, Next} from \"koa\";\nimport koaBodyParser, {Options} from \"koa-bodyparser\";\n// @ts-ignore\nimport koaQs from \"koa-qs\";\nimport send from \"koa-send\";\nimport {staticsMiddleware} from \"../middlewares/staticsMiddleware\";\nimport {PlatformKoaHandler} from \"../services/PlatformKoaHandler\";\nimport {PlatformKoaRequest} from \"../services/PlatformKoaRequest\";\nimport {PlatformKoaResponse} from \"../services/PlatformKoaResponse\";\nimport {getMulter} from \"../utils/multer\";\n\ndeclare global {\n namespace TsED {\n export interface Application extends Koa {}\n }\n\n namespace TsED {\n export interface StaticsOptions extends send.SendOptions {}\n }\n}\n\n// @ts-ignore\nKoaRouter.prototype.$$match = KoaRouter.prototype.match;\nKoaRouter.prototype.match = function match(...args: any[]) {\n const matched = this.$$match(...args);\n if (matched) {\n if (matched.path.length) {\n matched.route = true;\n }\n }\n\n return matched;\n};\n\n/**\n * @platform\n * @koa\n */\nexport class PlatformKoa implements PlatformAdapter<Koa> {\n readonly 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\n constructor(private injector: InjectorService) {}\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 PlatformBuilder.create<Koa>(module, {\n ...settings,\n adapter: PlatformKoa\n });\n }\n\n /**\n * Bootstrap a server application\n * @param module\n * @param settings\n */\n static async bootstrap(module: Type<any>, settings: Partial<TsED.Configuration> = {}) {\n return PlatformBuilder.bootstrap<Koa>(module, {\n ...settings,\n adapter: PlatformKoa\n });\n }\n\n onInit() {\n const app = this.getPlatformApplication();\n\n app.getApp().silent = true;\n }\n\n mapLayers(layers: PlatformLayer[]) {\n const {settings} = this.injector;\n const app = this.getPlatformApplication();\n const options = settings.get(\"koa.router\", {});\n const rawRouter = new KoaRouter(options) as any;\n\n layers.forEach((layer) => {\n switch (layer.method) {\n case \"statics\":\n rawRouter.use(layer.path, this.statics(layer.path as string, layer.opts as any));\n break;\n\n default:\n rawRouter[layer.method](...layer.getArgs());\n }\n });\n\n app.getApp().use(rawRouter.routes()).use(rawRouter.allowedMethods());\n }\n\n mapHandler(handler: Function, metadata: PlatformHandlerMetadata) {\n if (metadata.isRawMiddleware()) {\n return handler;\n }\n\n return async (koaContext: Koa.Context, next: Koa.Next) => {\n const $ctx = getContext<PlatformContext>()!;\n $ctx.next = next;\n\n await handler($ctx);\n };\n }\n\n useContext(): this {\n const app = this.getPlatformApplication();\n const invoke = createContext(this.injector);\n\n app.use(async (koaContext: Context, next: Next) => {\n const $ctx = await invoke({\n request: koaContext.request as any,\n response: koaContext.response as any,\n koaContext\n });\n\n try {\n await $ctx.start();\n await $ctx.runInContext(next);\n const status = koaContext.status || 404;\n\n if (status === 404 && !$ctx.isDone()) {\n this.injector.get<PlatformExceptions>(PlatformExceptions)?.resourceNotFound($ctx);\n }\n } catch (error) {\n this.injector.get<PlatformExceptions>(PlatformExceptions)?.catch(error, $ctx);\n } finally {\n await $ctx.finish();\n }\n });\n\n return this;\n }\n\n app() {\n const app = this.injector.settings.get(\"koa.app\") || new Koa();\n koaQs(app, \"extended\");\n\n return {\n app,\n callback() {\n return app.callback();\n }\n };\n }\n\n multipart(options: PlatformMulterSettings): PlatformMulter {\n return getMulter(options);\n }\n\n statics(endpoint: string, options: PlatformStaticsOptions) {\n return staticsMiddleware(options);\n }\n\n bodyParser(type: \"json\" | \"urlencoded\" | \"raw\" | \"text\", additionalOptions: any = {}): any {\n const opts = this.injector.settings.get(`koa.bodyParser`);\n let parser: any = koaBodyParser;\n\n let options: Options = {};\n\n if (isFunction(opts)) {\n parser = opts;\n options = {};\n }\n\n return parser({...options, ...additionalOptions});\n }\n\n private getPlatformApplication() {\n return this.injector.get<PlatformApplication>(PlatformApplication)!;\n }\n}\n"]}
|
package/lib/cjs/index.js
CHANGED
|
@@ -6,14 +6,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const tslib_1 = require("tslib");
|
|
7
7
|
tslib_1.__exportStar(require("./exports"), exports);
|
|
8
8
|
tslib_1.__exportStar(require("./components/PlatformKoa"), exports);
|
|
9
|
-
tslib_1.__exportStar(require("./decorators/caseSensitive"), exports);
|
|
10
9
|
tslib_1.__exportStar(require("./decorators/ctx"), exports);
|
|
11
|
-
tslib_1.__exportStar(require("./decorators/routerSettings"), exports);
|
|
12
10
|
tslib_1.__exportStar(require("./decorators/state"), exports);
|
|
13
|
-
tslib_1.__exportStar(require("./decorators/strict"), exports);
|
|
14
11
|
tslib_1.__exportStar(require("./interfaces/PlatformKoaSettings"), exports);
|
|
15
12
|
tslib_1.__exportStar(require("./interfaces/interfaces"), exports);
|
|
16
|
-
tslib_1.__exportStar(require("./middlewares/resourceNotFoundMiddleware"), exports);
|
|
17
13
|
tslib_1.__exportStar(require("./middlewares/staticsMiddleware"), exports);
|
|
18
14
|
tslib_1.__exportStar(require("./services/PlatformKoaHandler"), exports);
|
|
19
15
|
tslib_1.__exportStar(require("./services/PlatformKoaRequest"), exports);
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,oDAA0B;AAC1B,mEAAyC;AACzC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,oDAA0B;AAC1B,mEAAyC;AACzC,2DAAiC;AACjC,6DAAmC;AACnC,2EAAiD;AACjD,kEAAwC;AACxC,0EAAgD;AAChD,wEAA8C;AAC9C,wEAA8C;AAC9C,yEAA+C;AAC/C,yDAA+B","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./exports\";\nexport * from \"./components/PlatformKoa\";\nexport * from \"./decorators/ctx\";\nexport * from \"./decorators/state\";\nexport * from \"./interfaces/PlatformKoaSettings\";\nexport * from \"./interfaces/interfaces\";\nexport * from \"./middlewares/staticsMiddleware\";\nexport * from \"./services/PlatformKoaHandler\";\nexport * from \"./services/PlatformKoaRequest\";\nexport * from \"./services/PlatformKoaResponse\";\nexport * from \"./utils/multer\";\n"]}
|
|
@@ -2,58 +2,29 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PlatformKoaHandler = void 0;
|
|
4
4
|
const common_1 = require("@tsed/common");
|
|
5
|
+
const core_1 = require("@tsed/core");
|
|
5
6
|
require("./PlatformKoaRequest");
|
|
6
|
-
const OVERRIDE_TYPES = [common_1.HandlerType.ENDPOINT, common_1.HandlerType.MIDDLEWARE, common_1.HandlerType.ERR_MIDDLEWARE, common_1.HandlerType.CTX_FN];
|
|
7
7
|
class PlatformKoaHandler extends common_1.PlatformHandler {
|
|
8
|
-
async flush(
|
|
9
|
-
if (data === undefined && ctx.getResponse().body) {
|
|
10
|
-
data = ctx.getResponse().body;
|
|
8
|
+
async flush($ctx) {
|
|
9
|
+
if ($ctx.data === undefined && $ctx.getResponse().body) {
|
|
10
|
+
$ctx.data = $ctx.getResponse().body;
|
|
11
11
|
}
|
|
12
|
-
return super.flush(
|
|
12
|
+
return super.flush($ctx);
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
if (
|
|
16
|
-
const handler = this.compileHandler(metadata);
|
|
17
|
-
return async (ctx, next) => handler({ next, $ctx: ctx.request.$ctx });
|
|
18
|
-
}
|
|
19
|
-
return super.createRawHandler(metadata);
|
|
20
|
-
}
|
|
21
|
-
async onRequest(requestOptions) {
|
|
22
|
-
const { metadata, $ctx } = requestOptions;
|
|
23
|
-
if ($ctx.data instanceof Error) {
|
|
24
|
-
if (metadata.hasErrorParam) {
|
|
25
|
-
requestOptions.err = $ctx.data;
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
return this.onError($ctx.data, requestOptions);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return super.onRequest(requestOptions);
|
|
32
|
-
}
|
|
33
|
-
onError(error, requestOptions) {
|
|
34
|
-
const { next, $ctx, metadata } = requestOptions;
|
|
35
|
-
// istanbul ignore next
|
|
36
|
-
if ($ctx.isDone()) {
|
|
14
|
+
async onRequest(handler, $ctx) {
|
|
15
|
+
if ($ctx.error instanceof Error && !$ctx.handlerMetadata.hasErrorParam) {
|
|
37
16
|
return;
|
|
38
17
|
}
|
|
39
|
-
$ctx
|
|
40
|
-
if (!next || metadata.isFinal()) {
|
|
41
|
-
this.throwError(error, $ctx);
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
return next();
|
|
18
|
+
return super.onRequest(handler, $ctx);
|
|
45
19
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return await super.onCtxRequest(requestOptions);
|
|
20
|
+
next(error, next, $ctx) {
|
|
21
|
+
if ((0, core_1.isStream)($ctx.data) || $ctx.isDone()) {
|
|
22
|
+
return;
|
|
50
23
|
}
|
|
51
|
-
|
|
52
|
-
|
|
24
|
+
if (error && !($ctx.handlerMetadata.isEndpoint() && !$ctx.handlerMetadata.isFinal())) {
|
|
25
|
+
throw error;
|
|
53
26
|
}
|
|
54
|
-
|
|
55
|
-
throwError(error, $ctx) {
|
|
56
|
-
$ctx.getApp().emit("error", error, $ctx.getRequest().ctx);
|
|
27
|
+
return !$ctx.handlerMetadata.isFinal() && next();
|
|
57
28
|
}
|
|
58
29
|
}
|
|
59
30
|
exports.PlatformKoaHandler = PlatformKoaHandler;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformKoaHandler.js","sourceRoot":"","sources":["../../../src/services/PlatformKoaHandler.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"PlatformKoaHandler.js","sourceRoot":"","sources":["../../../src/services/PlatformKoaHandler.ts"],"names":[],"mappings":";;;AAAA,yCAAsF;AACtF,qCAAoC;AACpC,gCAA8B;AAE9B,MAAa,kBAAmB,SAAQ,wBAAe;IAC9C,KAAK,CAAC,KAAK,CAAC,IAAqB;QACtC,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE;YACtD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC;SACrC;QAED,OAAO,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,OAA+B,EAAE,IAAqB;QACpE,IAAI,IAAI,CAAC,KAAK,YAAY,KAAK,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,aAAa,EAAE;YACtE,OAAO;SACR;QAED,OAAO,KAAK,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACxC,CAAC;IAEM,IAAI,CAAC,KAAc,EAAE,IAAS,EAAE,IAAqB;QAC1D,IAAI,IAAA,eAAQ,EAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,EAAE;YACxC,OAAO;SACR;QAED,IAAI,KAAK,IAAI,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,CAAC,EAAE;YACpF,MAAM,KAAK,CAAC;SACb;QAED,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,IAAI,IAAI,EAAE,CAAC;IACnD,CAAC;CACF;AA5BD,gDA4BC","sourcesContent":["import {PlatformContext, PlatformHandler, PlatformParamsCallback} from \"@tsed/common\";\nimport {isStream} from \"@tsed/core\";\nimport \"./PlatformKoaRequest\";\n\nexport class PlatformKoaHandler extends PlatformHandler {\n public async flush($ctx: PlatformContext) {\n if ($ctx.data === undefined && $ctx.getResponse().body) {\n $ctx.data = $ctx.getResponse().body;\n }\n\n return super.flush($ctx);\n }\n\n async onRequest(handler: PlatformParamsCallback, $ctx: PlatformContext): Promise<any> {\n if ($ctx.error instanceof Error && !$ctx.handlerMetadata.hasErrorParam) {\n return;\n }\n\n return super.onRequest(handler, $ctx);\n }\n\n public next(error: unknown, next: any, $ctx: PlatformContext) {\n if (isStream($ctx.data) || $ctx.isDone()) {\n return;\n }\n\n if (error && !($ctx.handlerMetadata.isEndpoint() && !$ctx.handlerMetadata.isFinal())) {\n throw error;\n }\n\n return !$ctx.handlerMetadata.isFinal() && next();\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformKoaRequest.js","sourceRoot":"","sources":["../../../src/services/PlatformKoaRequest.ts"],"names":[],"mappings":";;;AAAA,uBAAqB;AACrB,yCAA8D;AAgB9D;;;GAGG;AACH,MAAa,kBAAmB,SAAQ,wBAA4B;IAClE,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"PlatformKoaRequest.js","sourceRoot":"","sources":["../../../src/services/PlatformKoaRequest.ts"],"names":[],"mappings":";;;AAAA,uBAAqB;AACrB,yCAA8D;AAgB9D;;;GAGG;AACH,MAAa,kBAAmB,SAAQ,wBAA4B;IAClE,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,UAAyB,CAAC;IACnD,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC;IACnC,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC;IAC/B,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC;IACjC,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC;IAC7C,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC;IAC1B,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC;IAC9B,CAAC;CACF;AA5BD,gDA4BC","sourcesContent":["import \"@koa/router\";\nimport {PlatformContext, PlatformRequest} from \"@tsed/common\";\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 get ctx(): Koa.Context {\n return this.$ctx.event.koaContext as Koa.Context;\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() {\n return this.ctx.request.req;\n }\n}\n"]}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import KoaRouter from "@koa/router";
|
|
2
|
-
import { createContext, PlatformApplication, PlatformBuilder, PlatformHandler, PlatformRequest, PlatformResponse } from "@tsed/common";
|
|
3
|
-
import { PlatformExceptions } from "@tsed/platform-exceptions";
|
|
2
|
+
import { createContext, getContext, PlatformApplication, PlatformBuilder, PlatformHandler, PlatformRequest, PlatformResponse } from "@tsed/common";
|
|
4
3
|
import { isFunction } from "@tsed/core";
|
|
4
|
+
import { PlatformExceptions } from "@tsed/platform-exceptions";
|
|
5
5
|
import Koa from "koa";
|
|
6
6
|
import koaBodyParser from "koa-bodyparser";
|
|
7
7
|
// @ts-ignore
|
|
8
8
|
import koaQs from "koa-qs";
|
|
9
|
-
import { resourceNotFoundMiddleware } from "../middlewares/resourceNotFoundMiddleware.js";
|
|
10
9
|
import { staticsMiddleware } from "../middlewares/staticsMiddleware.js";
|
|
11
10
|
import { PlatformKoaHandler } from "../services/PlatformKoaHandler.js";
|
|
12
11
|
import { PlatformKoaRequest } from "../services/PlatformKoaRequest.js";
|
|
@@ -69,31 +68,58 @@ export class PlatformKoa {
|
|
|
69
68
|
});
|
|
70
69
|
}
|
|
71
70
|
onInit() {
|
|
72
|
-
const
|
|
73
|
-
const app = this.injector.get(PlatformApplication);
|
|
74
|
-
const listener = (error, ctx) => {
|
|
75
|
-
injector.get(PlatformExceptions)?.catch(error, ctx.request.$ctx);
|
|
76
|
-
};
|
|
71
|
+
const app = this.getPlatformApplication();
|
|
77
72
|
app.getApp().silent = true;
|
|
78
|
-
app.getApp().on("error", listener);
|
|
79
73
|
}
|
|
80
|
-
|
|
81
|
-
const
|
|
82
|
-
app.
|
|
83
|
-
|
|
84
|
-
|
|
74
|
+
mapLayers(layers) {
|
|
75
|
+
const { settings } = this.injector;
|
|
76
|
+
const app = this.getPlatformApplication();
|
|
77
|
+
const options = settings.get("koa.router", {});
|
|
78
|
+
const rawRouter = new KoaRouter(options);
|
|
79
|
+
layers.forEach((layer) => {
|
|
80
|
+
switch (layer.method) {
|
|
81
|
+
case "statics":
|
|
82
|
+
rawRouter.use(layer.path, this.statics(layer.path, layer.opts));
|
|
83
|
+
break;
|
|
84
|
+
default:
|
|
85
|
+
rawRouter[layer.method](...layer.getArgs());
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
app.getApp().use(rawRouter.routes()).use(rawRouter.allowedMethods());
|
|
89
|
+
}
|
|
90
|
+
mapHandler(handler, metadata) {
|
|
91
|
+
if (metadata.isRawMiddleware()) {
|
|
92
|
+
return handler;
|
|
93
|
+
}
|
|
94
|
+
return async (koaContext, next) => {
|
|
95
|
+
const $ctx = getContext();
|
|
96
|
+
$ctx.next = next;
|
|
97
|
+
await handler($ctx);
|
|
98
|
+
};
|
|
85
99
|
}
|
|
86
100
|
useContext() {
|
|
87
|
-
const app = this.
|
|
88
|
-
const { logger } = this.injector;
|
|
89
|
-
logger.info("Mount app context");
|
|
101
|
+
const app = this.getPlatformApplication();
|
|
90
102
|
const invoke = createContext(this.injector);
|
|
91
|
-
app.
|
|
92
|
-
await invoke({
|
|
93
|
-
request:
|
|
94
|
-
response:
|
|
103
|
+
app.use(async (koaContext, next) => {
|
|
104
|
+
const $ctx = await invoke({
|
|
105
|
+
request: koaContext.request,
|
|
106
|
+
response: koaContext.response,
|
|
107
|
+
koaContext
|
|
95
108
|
});
|
|
96
|
-
|
|
109
|
+
try {
|
|
110
|
+
await $ctx.start();
|
|
111
|
+
await $ctx.runInContext(next);
|
|
112
|
+
const status = koaContext.status || 404;
|
|
113
|
+
if (status === 404 && !$ctx.isDone()) {
|
|
114
|
+
this.injector.get(PlatformExceptions)?.resourceNotFound($ctx);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
this.injector.get(PlatformExceptions)?.catch(error, $ctx);
|
|
119
|
+
}
|
|
120
|
+
finally {
|
|
121
|
+
await $ctx.finish();
|
|
122
|
+
}
|
|
97
123
|
});
|
|
98
124
|
return this;
|
|
99
125
|
}
|
|
@@ -107,17 +133,6 @@ export class PlatformKoa {
|
|
|
107
133
|
}
|
|
108
134
|
};
|
|
109
135
|
}
|
|
110
|
-
router(routerOptions = {}) {
|
|
111
|
-
const { settings } = this.injector;
|
|
112
|
-
const options = Object.assign({}, settings.get("koa.router", {}), routerOptions);
|
|
113
|
-
const router = new KoaRouter(options);
|
|
114
|
-
return {
|
|
115
|
-
router,
|
|
116
|
-
callback() {
|
|
117
|
-
return [router.routes(), router.allowedMethods()];
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
136
|
multipart(options) {
|
|
122
137
|
return getMulter(options);
|
|
123
138
|
}
|
|
@@ -134,5 +149,8 @@ export class PlatformKoa {
|
|
|
134
149
|
}
|
|
135
150
|
return parser({ ...options, ...additionalOptions });
|
|
136
151
|
}
|
|
152
|
+
getPlatformApplication() {
|
|
153
|
+
return this.injector.get(PlatformApplication);
|
|
154
|
+
}
|
|
137
155
|
}
|
|
138
156
|
//# sourceMappingURL=PlatformKoa.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformKoa.js","sourceRoot":"","sources":["../../../src/components/PlatformKoa.ts"],"names":[],"mappings":"AAAA,OAAO,SAA8C,MAAM,aAAa,CAAC;AACzE,OAAO,EACL,aAAa,
|
|
1
|
+
{"version":3,"file":"PlatformKoa.js","sourceRoot":"","sources":["../../../src/components/PlatformKoa.ts"],"names":[],"mappings":"AAAA,OAAO,SAA8C,MAAM,aAAa,CAAC;AACzE,OAAO,EACL,aAAa,EACb,UAAU,EAGV,mBAAmB,EACnB,eAAe,EAEf,eAAe,EAGf,eAAe,EACf,gBAAgB,EAEjB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAC,UAAU,EAAO,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAC,kBAAkB,EAAC,MAAM,2BAA2B,CAAC;AAE7D,OAAO,GAAoB,MAAM,KAAK,CAAC;AACvC,OAAO,aAAwB,MAAM,gBAAgB,CAAC;AACtD,aAAa;AACb,OAAO,KAAK,MAAM,QAAQ,CAAC;AAE3B,OAAO,EAAC,iBAAiB,EAAC,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAC,k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C;QAC/D,KAAK,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;QAEvB,OAAO;YACL,GAAG;YACH,QAAQ;gBACN,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;YACxB,CAAC;SACF,CAAC;IACJ,CAAC;IAED,SAAS,CAAC,OAA+B;QACvC,OAAO,SAAS,CAAC,OAAO,CAAC,CAAC;IAC5B,CAAC;IAED,OAAO,CAAC,QAAgB,EAAE,OAA+B;QACvD,OAAO,iBAAiB,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC;IAED,UAAU,CAAC,IAA4C,EAAE,oBAAyB,EAAE;QAClF,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;QAC1D,IAAI,MAAM,GAAQ,aAAa,CAAC;QAEhC,IAAI,OAAO,GAAY,EAAE,CAAC;QAE1B,IAAI,UAAU,CAAC,IAAI,CAAC,EAAE;YACpB,MAAM,GAAG,IAAI,CAAC;YACd,OAAO,GAAG,EAAE,CAAC;SACd;QAED,OAAO,MAAM,CAAC,EAAC,GAAG,OAAO,EAAE,GAAG,iBAAiB,EAAC,CAAC,CAAC;IACpD,CAAC;IAEO,sBAAsB;QAC5B,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAsB,mBAAmB,CAAE,CAAC;IACtE,CAAC;CACF","sourcesContent":["import KoaRouter, {RouterOptions as KoaRouterOptions} from \"@koa/router\";\nimport {\n createContext,\n getContext,\n InjectorService,\n PlatformAdapter,\n PlatformApplication,\n PlatformBuilder,\n PlatformContext,\n PlatformHandler,\n PlatformMulter,\n PlatformMulterSettings,\n PlatformRequest,\n PlatformResponse,\n PlatformStaticsOptions\n} from \"@tsed/common\";\nimport {isFunction, Type} from \"@tsed/core\";\nimport {PlatformExceptions} from \"@tsed/platform-exceptions\";\nimport {PlatformHandlerMetadata, PlatformLayer} from \"@tsed/platform-router\";\nimport Koa, {Context, Next} from \"koa\";\nimport koaBodyParser, {Options} from \"koa-bodyparser\";\n// @ts-ignore\nimport koaQs from \"koa-qs\";\nimport send from \"koa-send\";\nimport {staticsMiddleware} from \"../middlewares/staticsMiddleware\";\nimport {PlatformKoaHandler} from \"../services/PlatformKoaHandler\";\nimport {PlatformKoaRequest} from \"../services/PlatformKoaRequest\";\nimport {PlatformKoaResponse} from \"../services/PlatformKoaResponse\";\nimport {getMulter} from \"../utils/multer\";\n\ndeclare global {\n namespace TsED {\n export interface Application extends Koa {}\n }\n\n namespace TsED {\n export interface StaticsOptions extends send.SendOptions {}\n }\n}\n\n// @ts-ignore\nKoaRouter.prototype.$$match = KoaRouter.prototype.match;\nKoaRouter.prototype.match = function match(...args: any[]) {\n const matched = this.$$match(...args);\n if (matched) {\n if (matched.path.length) {\n matched.route = true;\n }\n }\n\n return matched;\n};\n\n/**\n * @platform\n * @koa\n */\nexport class PlatformKoa implements PlatformAdapter<Koa> {\n readonly 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\n constructor(private injector: InjectorService) {}\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 PlatformBuilder.create<Koa>(module, {\n ...settings,\n adapter: PlatformKoa\n });\n }\n\n /**\n * Bootstrap a server application\n * @param module\n * @param settings\n */\n static async bootstrap(module: Type<any>, settings: Partial<TsED.Configuration> = {}) {\n return PlatformBuilder.bootstrap<Koa>(module, {\n ...settings,\n adapter: PlatformKoa\n });\n }\n\n onInit() {\n const app = this.getPlatformApplication();\n\n app.getApp().silent = true;\n }\n\n mapLayers(layers: PlatformLayer[]) {\n const {settings} = this.injector;\n const app = this.getPlatformApplication();\n const options = settings.get(\"koa.router\", {});\n const rawRouter = new KoaRouter(options) as any;\n\n layers.forEach((layer) => {\n switch (layer.method) {\n case \"statics\":\n rawRouter.use(layer.path, this.statics(layer.path as string, layer.opts as any));\n break;\n\n default:\n rawRouter[layer.method](...layer.getArgs());\n }\n });\n\n app.getApp().use(rawRouter.routes()).use(rawRouter.allowedMethods());\n }\n\n mapHandler(handler: Function, metadata: PlatformHandlerMetadata) {\n if (metadata.isRawMiddleware()) {\n return handler;\n }\n\n return async (koaContext: Koa.Context, next: Koa.Next) => {\n const $ctx = getContext<PlatformContext>()!;\n $ctx.next = next;\n\n await handler($ctx);\n };\n }\n\n useContext(): this {\n const app = this.getPlatformApplication();\n const invoke = createContext(this.injector);\n\n app.use(async (koaContext: Context, next: Next) => {\n const $ctx = await invoke({\n request: koaContext.request as any,\n response: koaContext.response as any,\n koaContext\n });\n\n try {\n await $ctx.start();\n await $ctx.runInContext(next);\n const status = koaContext.status || 404;\n\n if (status === 404 && !$ctx.isDone()) {\n this.injector.get<PlatformExceptions>(PlatformExceptions)?.resourceNotFound($ctx);\n }\n } catch (error) {\n this.injector.get<PlatformExceptions>(PlatformExceptions)?.catch(error, $ctx);\n } finally {\n await $ctx.finish();\n }\n });\n\n return this;\n }\n\n app() {\n const app = this.injector.settings.get(\"koa.app\") || new Koa();\n koaQs(app, \"extended\");\n\n return {\n app,\n callback() {\n return app.callback();\n }\n };\n }\n\n multipart(options: PlatformMulterSettings): PlatformMulter {\n return getMulter(options);\n }\n\n statics(endpoint: string, options: PlatformStaticsOptions) {\n return staticsMiddleware(options);\n }\n\n bodyParser(type: \"json\" | \"urlencoded\" | \"raw\" | \"text\", additionalOptions: any = {}): any {\n const opts = this.injector.settings.get(`koa.bodyParser`);\n let parser: any = koaBodyParser;\n\n let options: Options = {};\n\n if (isFunction(opts)) {\n parser = opts;\n options = {};\n }\n\n return parser({...options, ...additionalOptions});\n }\n\n private getPlatformApplication() {\n return this.injector.get<PlatformApplication>(PlatformApplication)!;\n }\n}\n"]}
|
package/lib/esm/index.js
CHANGED
|
@@ -3,14 +3,10 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export * from "./exports.js";
|
|
5
5
|
export * from "./components/PlatformKoa.js";
|
|
6
|
-
export * from "./decorators/caseSensitive.js";
|
|
7
6
|
export * from "./decorators/ctx.js";
|
|
8
|
-
export * from "./decorators/routerSettings.js";
|
|
9
7
|
export * from "./decorators/state.js";
|
|
10
|
-
export * from "./decorators/strict.js";
|
|
11
8
|
export * from "./interfaces/PlatformKoaSettings.js";
|
|
12
9
|
export * from "./interfaces/interfaces.js";
|
|
13
|
-
export * from "./middlewares/resourceNotFoundMiddleware.js";
|
|
14
10
|
export * from "./middlewares/staticsMiddleware.js";
|
|
15
11
|
export * from "./services/PlatformKoaHandler.js";
|
|
16
12
|
export * from "./services/PlatformKoaRequest.js";
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,WAAW,CAAC;AAC1B,cAAc,0BAA0B,CAAC;AACzC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,WAAW,CAAC;AAC1B,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kCAAkC,CAAC;AACjD,cAAc,yBAAyB,CAAC;AACxC,cAAc,iCAAiC,CAAC;AAChD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gBAAgB,CAAC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./exports\";\nexport * from \"./components/PlatformKoa\";\nexport * from \"./decorators/ctx\";\nexport * from \"./decorators/state\";\nexport * from \"./interfaces/PlatformKoaSettings\";\nexport * from \"./interfaces/interfaces\";\nexport * from \"./middlewares/staticsMiddleware\";\nexport * from \"./services/PlatformKoaHandler\";\nexport * from \"./services/PlatformKoaRequest\";\nexport * from \"./services/PlatformKoaResponse\";\nexport * from \"./utils/multer\";\n"]}
|
|
@@ -1,56 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PlatformHandler } from "@tsed/common";
|
|
2
|
+
import { isStream } from "@tsed/core";
|
|
2
3
|
import "./PlatformKoaRequest.js";
|
|
3
|
-
const OVERRIDE_TYPES = [HandlerType.ENDPOINT, HandlerType.MIDDLEWARE, HandlerType.ERR_MIDDLEWARE, HandlerType.CTX_FN];
|
|
4
4
|
export class PlatformKoaHandler extends PlatformHandler {
|
|
5
|
-
async flush(
|
|
6
|
-
if (data === undefined && ctx.getResponse().body) {
|
|
7
|
-
data = ctx.getResponse().body;
|
|
5
|
+
async flush($ctx) {
|
|
6
|
+
if ($ctx.data === undefined && $ctx.getResponse().body) {
|
|
7
|
+
$ctx.data = $ctx.getResponse().body;
|
|
8
8
|
}
|
|
9
|
-
return super.flush(
|
|
9
|
+
return super.flush($ctx);
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
if (
|
|
13
|
-
const handler = this.compileHandler(metadata);
|
|
14
|
-
return async (ctx, next) => handler({ next, $ctx: ctx.request.$ctx });
|
|
15
|
-
}
|
|
16
|
-
return super.createRawHandler(metadata);
|
|
17
|
-
}
|
|
18
|
-
async onRequest(requestOptions) {
|
|
19
|
-
const { metadata, $ctx } = requestOptions;
|
|
20
|
-
if ($ctx.data instanceof Error) {
|
|
21
|
-
if (metadata.hasErrorParam) {
|
|
22
|
-
requestOptions.err = $ctx.data;
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
return this.onError($ctx.data, requestOptions);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return super.onRequest(requestOptions);
|
|
29
|
-
}
|
|
30
|
-
onError(error, requestOptions) {
|
|
31
|
-
const { next, $ctx, metadata } = requestOptions;
|
|
32
|
-
// istanbul ignore next
|
|
33
|
-
if ($ctx.isDone()) {
|
|
11
|
+
async onRequest(handler, $ctx) {
|
|
12
|
+
if ($ctx.error instanceof Error && !$ctx.handlerMetadata.hasErrorParam) {
|
|
34
13
|
return;
|
|
35
14
|
}
|
|
36
|
-
$ctx
|
|
37
|
-
if (!next || metadata.isFinal()) {
|
|
38
|
-
this.throwError(error, $ctx);
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
return next();
|
|
15
|
+
return super.onRequest(handler, $ctx);
|
|
42
16
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return await super.onCtxRequest(requestOptions);
|
|
17
|
+
next(error, next, $ctx) {
|
|
18
|
+
if (isStream($ctx.data) || $ctx.isDone()) {
|
|
19
|
+
return;
|
|
47
20
|
}
|
|
48
|
-
|
|
49
|
-
|
|
21
|
+
if (error && !($ctx.handlerMetadata.isEndpoint() && !$ctx.handlerMetadata.isFinal())) {
|
|
22
|
+
throw error;
|
|
50
23
|
}
|
|
51
|
-
|
|
52
|
-
throwError(error, $ctx) {
|
|
53
|
-
$ctx.getApp().emit("error", error, $ctx.getRequest().ctx);
|
|
24
|
+
return !$ctx.handlerMetadata.isFinal() && next();
|
|
54
25
|
}
|
|
55
26
|
}
|
|
56
27
|
//# sourceMappingURL=PlatformKoaHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformKoaHandler.js","sourceRoot":"","sources":["../../../src/services/PlatformKoaHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,
|
|
1
|
+
{"version":3,"file":"PlatformKoaHandler.js","sourceRoot":"","sources":["../../../src/services/PlatformKoaHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,eAAe,EAAyB,MAAM,cAAc,CAAC;AACtF,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AACpC,OAAO,sBAAsB,CAAC;AAE9B,MAAM,OAAO,kBAAmB,SAAQ,eAAe;IAC9C,KAAK,CAAC,KAAK,CAAC,IAAqB;QACtC,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE;YACtD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC;SACrC;QAED,OAAO,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,OAA+B,EAAE,IAAqB;QACpE,IAAI,IAAI,CAAC,KAAK,YAAY,KAAK,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,aAAa,EAAE;YACtE,OAAO;SACR;QAED,OAAO,KAAK,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACxC,CAAC;IAEM,IAAI,CAAC,KAAc,EAAE,IAAS,EAAE,IAAqB;QAC1D,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,EAAE;YACxC,OAAO;SACR;QAED,IAAI,KAAK,IAAI,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,CAAC,EAAE;YACpF,MAAM,KAAK,CAAC;SACb;QAED,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,IAAI,IAAI,EAAE,CAAC;IACnD,CAAC;CACF","sourcesContent":["import {PlatformContext, PlatformHandler, PlatformParamsCallback} from \"@tsed/common\";\nimport {isStream} from \"@tsed/core\";\nimport \"./PlatformKoaRequest\";\n\nexport class PlatformKoaHandler extends PlatformHandler {\n public async flush($ctx: PlatformContext) {\n if ($ctx.data === undefined && $ctx.getResponse().body) {\n $ctx.data = $ctx.getResponse().body;\n }\n\n return super.flush($ctx);\n }\n\n async onRequest(handler: PlatformParamsCallback, $ctx: PlatformContext): Promise<any> {\n if ($ctx.error instanceof Error && !$ctx.handlerMetadata.hasErrorParam) {\n return;\n }\n\n return super.onRequest(handler, $ctx);\n }\n\n public next(error: unknown, next: any, $ctx: PlatformContext) {\n if (isStream($ctx.data) || $ctx.isDone()) {\n return;\n }\n\n if (error && !($ctx.handlerMetadata.isEndpoint() && !$ctx.handlerMetadata.isFinal())) {\n throw error;\n }\n\n return !$ctx.handlerMetadata.isFinal() && next();\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformKoaRequest.js","sourceRoot":"","sources":["../../../src/services/PlatformKoaRequest.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAC;AACrB,OAAO,EAAkB,eAAe,EAAC,MAAM,cAAc,CAAC;AAgB9D;;;GAGG;AACH,MAAM,OAAO,kBAAmB,SAAQ,eAA4B;IAClE,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"PlatformKoaRequest.js","sourceRoot":"","sources":["../../../src/services/PlatformKoaRequest.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAC;AACrB,OAAO,EAAkB,eAAe,EAAC,MAAM,cAAc,CAAC;AAgB9D;;;GAGG;AACH,MAAM,OAAO,kBAAmB,SAAQ,eAA4B;IAClE,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,UAAyB,CAAC;IACnD,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC;IACnC,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC;IAC/B,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC;IACjC,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC;IAC7C,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC;IAC1B,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC;IAC9B,CAAC;CACF","sourcesContent":["import \"@koa/router\";\nimport {PlatformContext, PlatformRequest} from \"@tsed/common\";\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 get ctx(): Koa.Context {\n return this.$ctx.event.koaContext as Koa.Context;\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() {\n return this.ctx.request.req;\n }\n}\n"]}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
/// <reference types="koa__router" />
|
|
2
|
-
import KoaRouter, { RouterOptions as KoaRouterOptions } from "@koa/router";
|
|
3
1
|
import { InjectorService, PlatformAdapter, PlatformBuilder, PlatformHandler, PlatformMulter, PlatformMulterSettings, PlatformRequest, PlatformResponse, PlatformStaticsOptions } from "@tsed/common";
|
|
4
2
|
import { Type } from "@tsed/core";
|
|
3
|
+
import { PlatformHandlerMetadata, PlatformLayer } from "@tsed/platform-router";
|
|
5
4
|
import Koa from "koa";
|
|
6
5
|
import send from "koa-send";
|
|
7
6
|
import { PlatformKoaHandler } from "../services/PlatformKoaHandler";
|
|
@@ -13,10 +12,6 @@ declare global {
|
|
|
13
12
|
}
|
|
14
13
|
}
|
|
15
14
|
namespace TsED {
|
|
16
|
-
interface Router extends KoaRouter {
|
|
17
|
-
}
|
|
18
|
-
interface RouterOptions extends KoaRouterOptions {
|
|
19
|
-
}
|
|
20
15
|
interface StaticsOptions extends send.SendOptions {
|
|
21
16
|
}
|
|
22
17
|
}
|
|
@@ -25,7 +20,7 @@ declare global {
|
|
|
25
20
|
* @platform
|
|
26
21
|
* @koa
|
|
27
22
|
*/
|
|
28
|
-
export declare class PlatformKoa implements PlatformAdapter<Koa
|
|
23
|
+
export declare class PlatformKoa implements PlatformAdapter<Koa> {
|
|
29
24
|
private injector;
|
|
30
25
|
readonly providers: ({
|
|
31
26
|
provide: typeof PlatformResponse;
|
|
@@ -43,25 +38,23 @@ export declare class PlatformKoa implements PlatformAdapter<Koa, KoaRouter> {
|
|
|
43
38
|
* @param module
|
|
44
39
|
* @param settings
|
|
45
40
|
*/
|
|
46
|
-
static create(module: Type<any>, settings?: Partial<TsED.Configuration>): PlatformBuilder<Koa<Koa.DefaultState, Koa.DefaultContext
|
|
41
|
+
static create(module: Type<any>, settings?: Partial<TsED.Configuration>): PlatformBuilder<Koa<Koa.DefaultState, Koa.DefaultContext>>;
|
|
47
42
|
/**
|
|
48
43
|
* Bootstrap a server application
|
|
49
44
|
* @param module
|
|
50
45
|
* @param settings
|
|
51
46
|
*/
|
|
52
|
-
static bootstrap(module: Type<any>, settings?: Partial<TsED.Configuration>): Promise<PlatformBuilder<Koa<Koa.DefaultState, Koa.DefaultContext
|
|
47
|
+
static bootstrap(module: Type<any>, settings?: Partial<TsED.Configuration>): Promise<PlatformBuilder<Koa<Koa.DefaultState, Koa.DefaultContext>>>;
|
|
53
48
|
onInit(): void;
|
|
54
|
-
|
|
49
|
+
mapLayers(layers: PlatformLayer[]): void;
|
|
50
|
+
mapHandler(handler: Function, metadata: PlatformHandlerMetadata): Function;
|
|
55
51
|
useContext(): this;
|
|
56
52
|
app(): {
|
|
57
53
|
app: any;
|
|
58
54
|
callback(): any;
|
|
59
55
|
};
|
|
60
|
-
router(routerOptions?: any): {
|
|
61
|
-
router: any;
|
|
62
|
-
callback(): any[];
|
|
63
|
-
};
|
|
64
56
|
multipart(options: PlatformMulterSettings): PlatformMulter;
|
|
65
57
|
statics(endpoint: string, options: PlatformStaticsOptions): any;
|
|
66
58
|
bodyParser(type: "json" | "urlencoded" | "raw" | "text", additionalOptions?: any): any;
|
|
59
|
+
private getPlatformApplication;
|
|
67
60
|
}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -3,14 +3,10 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export * from "./exports";
|
|
5
5
|
export * from "./components/PlatformKoa";
|
|
6
|
-
export * from "./decorators/caseSensitive";
|
|
7
6
|
export * from "./decorators/ctx";
|
|
8
|
-
export * from "./decorators/routerSettings";
|
|
9
7
|
export * from "./decorators/state";
|
|
10
|
-
export * from "./decorators/strict";
|
|
11
8
|
export * from "./interfaces/PlatformKoaSettings";
|
|
12
9
|
export * from "./interfaces/interfaces";
|
|
13
|
-
export * from "./middlewares/resourceNotFoundMiddleware";
|
|
14
10
|
export * from "./middlewares/staticsMiddleware";
|
|
15
11
|
export * from "./services/PlatformKoaHandler";
|
|
16
12
|
export * from "./services/PlatformKoaRequest";
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PlatformContext, PlatformHandler, PlatformParamsCallback } from "@tsed/common";
|
|
2
2
|
import "./PlatformKoaRequest";
|
|
3
3
|
export declare class PlatformKoaHandler extends PlatformHandler {
|
|
4
|
-
flush(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
protected onError(error: unknown, requestOptions: OnRequestOptions): any;
|
|
8
|
-
protected onCtxRequest(requestOptions: OnRequestOptions): Promise<any>;
|
|
9
|
-
protected throwError(error: any, $ctx: PlatformContext): void;
|
|
4
|
+
flush($ctx: PlatformContext): Promise<import("@tsed/common").PlatformResponse<any>>;
|
|
5
|
+
onRequest(handler: PlatformParamsCallback, $ctx: PlatformContext): Promise<any>;
|
|
6
|
+
next(error: unknown, next: any, $ctx: PlatformContext): any;
|
|
10
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/platform-koa",
|
|
3
|
-
"version": "7.0.0-beta.
|
|
3
|
+
"version": "7.0.0-beta.16",
|
|
4
4
|
"description": "Koa package for Ts.ED framework",
|
|
5
5
|
"private": false,
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -52,10 +52,10 @@
|
|
|
52
52
|
"repository": "https://github.com/tsedio/tsed",
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@koa/cors": "3.3.0",
|
|
55
|
-
"@tsed/common": "7.0.0-beta.
|
|
56
|
-
"@tsed/core": "7.0.0-beta.
|
|
57
|
-
"@tsed/di": "7.0.0-beta.
|
|
58
|
-
"@tsed/platform-test-utils": "7.0.0-beta.
|
|
55
|
+
"@tsed/common": "7.0.0-beta.16",
|
|
56
|
+
"@tsed/core": "7.0.0-beta.16",
|
|
57
|
+
"@tsed/di": "7.0.0-beta.16",
|
|
58
|
+
"@tsed/platform-test-utils": "7.0.0-beta.16",
|
|
59
59
|
"@types/koa": "2.13.4",
|
|
60
60
|
"@types/koa-bodyparser": "4.3.7",
|
|
61
61
|
"@types/koa-compose": "3.2.5",
|
|
@@ -80,13 +80,13 @@
|
|
|
80
80
|
"tslib": "2.4.0"
|
|
81
81
|
},
|
|
82
82
|
"peerDependencies": {
|
|
83
|
-
"@tsed/common": "^7.0.0-beta.
|
|
84
|
-
"@tsed/core": "^7.0.0-beta.
|
|
85
|
-
"@tsed/di": "^7.0.0-beta.
|
|
86
|
-
"@tsed/json-mapper": "^7.0.0-beta.
|
|
83
|
+
"@tsed/common": "^7.0.0-beta.16",
|
|
84
|
+
"@tsed/core": "^7.0.0-beta.16",
|
|
85
|
+
"@tsed/di": "^7.0.0-beta.16",
|
|
86
|
+
"@tsed/json-mapper": "^7.0.0-beta.16",
|
|
87
87
|
"@tsed/logger": ">=6.2.0",
|
|
88
|
-
"@tsed/openspec": "^7.0.0-beta.
|
|
89
|
-
"@tsed/schema": "^7.0.0-beta.
|
|
88
|
+
"@tsed/openspec": "^7.0.0-beta.16",
|
|
89
|
+
"@tsed/schema": "^7.0.0-beta.16",
|
|
90
90
|
"koa": ">=2.13.0",
|
|
91
91
|
"koa-bodyparser": ">=4.3.0",
|
|
92
92
|
"koa-compress": ">=5.0.1",
|
package/readme.md
CHANGED
|
@@ -59,7 +59,7 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
|
|
|
59
59
|
|
|
60
60
|
The MIT License (MIT)
|
|
61
61
|
|
|
62
|
-
Copyright (c) 2016 -
|
|
62
|
+
Copyright (c) 2016 - 2022 Romain Lenzotti
|
|
63
63
|
|
|
64
64
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
65
65
|
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CaseSensitive = void 0;
|
|
4
|
-
const routerSettings_1 = require("./routerSettings");
|
|
5
|
-
/**
|
|
6
|
-
* Specify the behavior of the router controller.
|
|
7
|
-
*
|
|
8
|
-
* ```typescript
|
|
9
|
-
* @Controller("/")
|
|
10
|
-
* @CaseSensitive(true)
|
|
11
|
-
* class MyCtrl {
|
|
12
|
-
*
|
|
13
|
-
* }
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* Property | Description | Default
|
|
17
|
-
* ---|---|---
|
|
18
|
-
* CaseSensitive | Enable case sensitivity. | Disabled by default, treating “/Foo” and “/foo” as the same.
|
|
19
|
-
* Strict | Enable strict routing. | Disabled by default, “/foo” and “/foo/” are treated the same by the router.
|
|
20
|
-
*
|
|
21
|
-
* @returns {Function}
|
|
22
|
-
* @decorator
|
|
23
|
-
* @koa
|
|
24
|
-
* @param sensitive
|
|
25
|
-
*/
|
|
26
|
-
function CaseSensitive(sensitive) {
|
|
27
|
-
return (0, routerSettings_1.RouterSettings)({ sensitive });
|
|
28
|
-
}
|
|
29
|
-
exports.CaseSensitive = CaseSensitive;
|
|
30
|
-
//# sourceMappingURL=caseSensitive.js.map
|
|
@@ -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,IAAA,+BAAc,EAAC,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,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RouterSettings = void 0;
|
|
4
|
-
const common_1 = require("@tsed/common");
|
|
5
|
-
const core_1 = require("@tsed/core");
|
|
6
|
-
/**
|
|
7
|
-
* Specify the behavior of the router controller.
|
|
8
|
-
*
|
|
9
|
-
* ```typescript
|
|
10
|
-
* @Controller("/")
|
|
11
|
-
* @RouterSettings({sensitive: true})
|
|
12
|
-
* class MyCtrl {
|
|
13
|
-
*
|
|
14
|
-
* }
|
|
15
|
-
* ```
|
|
16
|
-
*
|
|
17
|
-
* Property | Description | Default
|
|
18
|
-
* ---|---|---
|
|
19
|
-
* sensitive | Enable case sensitivity. | Disabled by default, treating “/Foo” and “/foo” as the same.
|
|
20
|
-
* strict | Enable strict routing. | Disabled by default, “/foo” and “/foo/” are treated the same by the router.
|
|
21
|
-
*
|
|
22
|
-
* @returns {(target:any)=>void}
|
|
23
|
-
* @decorator
|
|
24
|
-
* @param routerOptions
|
|
25
|
-
* @koa
|
|
26
|
-
*/
|
|
27
|
-
function RouterSettings(routerOptions) {
|
|
28
|
-
return (0, core_1.StoreMerge)(common_1.ROUTER_OPTIONS, routerOptions);
|
|
29
|
-
}
|
|
30
|
-
exports.RouterSettings = RouterSettings;
|
|
31
|
-
//# sourceMappingURL=routerSettings.js.map
|
|
@@ -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,IAAA,iBAAU,EAAC,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,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Strict = void 0;
|
|
4
|
-
const routerSettings_1 = require("./routerSettings");
|
|
5
|
-
/**
|
|
6
|
-
* Specify the behavior of the router controller.
|
|
7
|
-
*
|
|
8
|
-
* ```typescript
|
|
9
|
-
* @Controller("/")
|
|
10
|
-
* @Strict(true)
|
|
11
|
-
* class MyCtrl {
|
|
12
|
-
*
|
|
13
|
-
* }
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* Property | Description | Default
|
|
17
|
-
* ---|---|---
|
|
18
|
-
* CaseSensitive | Enable case sensitivity. | Disabled by default, treating “/Foo” and “/foo” as the same.
|
|
19
|
-
* 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
|
|
20
|
-
* Strict | Enable strict routing. | Disabled by default, “/foo” and “/foo/” are treated the same by the router.
|
|
21
|
-
*
|
|
22
|
-
* @param strict
|
|
23
|
-
* @returns {Function}
|
|
24
|
-
* @decorator
|
|
25
|
-
* @koa
|
|
26
|
-
*/
|
|
27
|
-
function Strict(strict) {
|
|
28
|
-
return (0, routerSettings_1.RouterSettings)({ strict });
|
|
29
|
-
}
|
|
30
|
-
exports.Strict = Strict;
|
|
31
|
-
//# sourceMappingURL=strict.js.map
|
|
@@ -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,IAAA,+BAAc,EAAC,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"]}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resourceNotFoundMiddleware = void 0;
|
|
4
|
-
const platform_exceptions_1 = require("@tsed/platform-exceptions");
|
|
5
|
-
/**
|
|
6
|
-
* @ignore
|
|
7
|
-
* @param ctx
|
|
8
|
-
* @param next
|
|
9
|
-
*/
|
|
10
|
-
async function resourceNotFoundMiddleware(ctx, next) {
|
|
11
|
-
const $ctx = ctx.request.$ctx;
|
|
12
|
-
await next();
|
|
13
|
-
const status = ctx.status || 404;
|
|
14
|
-
if (status === 404 && !$ctx.isDone()) {
|
|
15
|
-
$ctx.injector.get(platform_exceptions_1.PlatformExceptions)?.resourceNotFound($ctx);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.resourceNotFoundMiddleware = resourceNotFoundMiddleware;
|
|
19
|
-
//# sourceMappingURL=resourceNotFoundMiddleware.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resourceNotFoundMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/resourceNotFoundMiddleware.ts"],"names":[],"mappings":";;;AACA,mEAA6D;AAE7D;;;;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,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAqB,wCAAkB,CAAC,EAAE,gBAAgB,CAAC,IAAI,CAAC,CAAC;KACnF;AACH,CAAC;AARD,gEAQC","sourcesContent":["import {PlatformContext} from \"@tsed/common\";\nimport {PlatformExceptions} from \"@tsed/platform-exceptions\";\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,26 +0,0 @@
|
|
|
1
|
-
import { RouterSettings } from "./routerSettings.js";
|
|
2
|
-
/**
|
|
3
|
-
* Specify the behavior of the router controller.
|
|
4
|
-
*
|
|
5
|
-
* ```typescript
|
|
6
|
-
* @Controller("/")
|
|
7
|
-
* @CaseSensitive(true)
|
|
8
|
-
* class MyCtrl {
|
|
9
|
-
*
|
|
10
|
-
* }
|
|
11
|
-
* ```
|
|
12
|
-
*
|
|
13
|
-
* Property | Description | Default
|
|
14
|
-
* ---|---|---
|
|
15
|
-
* CaseSensitive | Enable case sensitivity. | Disabled by default, treating “/Foo” and “/foo” as the same.
|
|
16
|
-
* Strict | Enable strict routing. | Disabled by default, “/foo” and “/foo/” are treated the same by the router.
|
|
17
|
-
*
|
|
18
|
-
* @returns {Function}
|
|
19
|
-
* @decorator
|
|
20
|
-
* @koa
|
|
21
|
-
* @param sensitive
|
|
22
|
-
*/
|
|
23
|
-
export function CaseSensitive(sensitive) {
|
|
24
|
-
return RouterSettings({ sensitive });
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=caseSensitive.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"caseSensitive.js","sourceRoot":"","sources":["../../../src/decorators/caseSensitive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,aAAa,CAAC,SAAkB;IAC9C,OAAO,cAAc,CAAC,EAAC,SAAS,EAAC,CAAC,CAAC;AACrC,CAAC","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,27 +0,0 @@
|
|
|
1
|
-
import { ROUTER_OPTIONS } from "@tsed/common";
|
|
2
|
-
import { StoreMerge } from "@tsed/core";
|
|
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 function RouterSettings(routerOptions) {
|
|
25
|
-
return StoreMerge(ROUTER_OPTIONS, routerOptions);
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=routerSettings.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"routerSettings.js","sourceRoot":"","sources":["../../../src/decorators/routerSettings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAC,UAAU,EAAC,MAAM,YAAY,CAAC;AAGtC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,cAAc,CAAC,aAA4B;IACzD,OAAO,UAAU,CAAC,cAAc,EAAE,aAAa,CAAC,CAAC;AACnD,CAAC","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,27 +0,0 @@
|
|
|
1
|
-
import { RouterSettings } from "./routerSettings.js";
|
|
2
|
-
/**
|
|
3
|
-
* Specify the behavior of the router controller.
|
|
4
|
-
*
|
|
5
|
-
* ```typescript
|
|
6
|
-
* @Controller("/")
|
|
7
|
-
* @Strict(true)
|
|
8
|
-
* class MyCtrl {
|
|
9
|
-
*
|
|
10
|
-
* }
|
|
11
|
-
* ```
|
|
12
|
-
*
|
|
13
|
-
* Property | Description | Default
|
|
14
|
-
* ---|---|---
|
|
15
|
-
* CaseSensitive | Enable case sensitivity. | Disabled by default, treating “/Foo” and “/foo” as the same.
|
|
16
|
-
* 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
|
|
17
|
-
* Strict | Enable strict routing. | Disabled by default, “/foo” and “/foo/” are treated the same by the router.
|
|
18
|
-
*
|
|
19
|
-
* @param strict
|
|
20
|
-
* @returns {Function}
|
|
21
|
-
* @decorator
|
|
22
|
-
* @koa
|
|
23
|
-
*/
|
|
24
|
-
export function Strict(strict) {
|
|
25
|
-
return RouterSettings({ strict });
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=strict.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"strict.js","sourceRoot":"","sources":["../../../src/decorators/strict.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,MAAM,CAAC,MAAe;IACpC,OAAO,cAAc,CAAC,EAAC,MAAM,EAAC,CAAC,CAAC;AAClC,CAAC","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"]}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { PlatformExceptions } from "@tsed/platform-exceptions";
|
|
2
|
-
/**
|
|
3
|
-
* @ignore
|
|
4
|
-
* @param ctx
|
|
5
|
-
* @param next
|
|
6
|
-
*/
|
|
7
|
-
export async function resourceNotFoundMiddleware(ctx, next) {
|
|
8
|
-
const $ctx = ctx.request.$ctx;
|
|
9
|
-
await next();
|
|
10
|
-
const status = ctx.status || 404;
|
|
11
|
-
if (status === 404 && !$ctx.isDone()) {
|
|
12
|
-
$ctx.injector.get(PlatformExceptions)?.resourceNotFound($ctx);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=resourceNotFoundMiddleware.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resourceNotFoundMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/resourceNotFoundMiddleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,kBAAkB,EAAC,MAAM,2BAA2B,CAAC;AAE7D;;;;GAIG;AACH,MAAM,CAAC,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,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAqB,kBAAkB,CAAC,EAAE,gBAAgB,CAAC,IAAI,CAAC,CAAC;KACnF;AACH,CAAC","sourcesContent":["import {PlatformContext} from \"@tsed/common\";\nimport {PlatformExceptions} from \"@tsed/platform-exceptions\";\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,22 +0,0 @@
|
|
|
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;
|
|
@@ -1,24 +0,0 @@
|
|
|
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;
|
|
@@ -1,23 +0,0 @@
|
|
|
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;
|