@tsed/platform-koa 6.127.0 → 6.128.2

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 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.5,
8
+ statements: 98.99,
9
9
  branches: 85.45,
10
10
  functions: 100,
11
- lines: 99.49
11
+ lines: 98.97
12
12
  }
13
13
  }
14
14
  };
@@ -9,7 +9,6 @@ const koa_1 = tslib_1.__importDefault(require("koa"));
9
9
  const koa_bodyparser_1 = tslib_1.__importDefault(require("koa-bodyparser"));
10
10
  // @ts-ignore
11
11
  const koa_qs_1 = tslib_1.__importDefault(require("koa-qs"));
12
- const resourceNotFoundMiddleware_1 = require("../middlewares/resourceNotFoundMiddleware");
13
12
  const staticsMiddleware_1 = require("../middlewares/staticsMiddleware");
14
13
  const PlatformKoaHandler_1 = require("../services/PlatformKoaHandler");
15
14
  const PlatformKoaRequest_1 = require("../services/PlatformKoaRequest");
@@ -73,7 +72,7 @@ class PlatformKoa {
73
72
  }
74
73
  onInit() {
75
74
  const injector = this.injector;
76
- const app = this.injector.get(common_1.PlatformApplication);
75
+ const app = this.getPlatformApplication();
77
76
  const listener = (error, ctx) => {
78
77
  injector.get(common_1.PlatformExceptions)?.catch(error, ctx.request.$ctx);
79
78
  };
@@ -82,21 +81,35 @@ class PlatformKoa {
82
81
  }
83
82
  useRouter() {
84
83
  const app = this.injector.get(common_1.PlatformApplication);
85
- app.getApp().use(resourceNotFoundMiddleware_1.resourceNotFoundMiddleware);
86
84
  app.getApp().use(app.getRouter().routes()).use(app.getRouter().allowedMethods());
87
85
  return this;
88
86
  }
89
87
  useContext() {
90
- const app = this.injector.get(common_1.PlatformApplication);
91
- const { logger } = this.injector;
92
- logger.info("Mount app context");
88
+ const app = this.getPlatformApplication();
93
89
  const invoke = (0, common_1.createContext)(this.injector);
94
- app.getApp().use(async (ctx, next) => {
95
- await invoke({
96
- request: ctx.request,
97
- response: ctx.response
90
+ this.injector.logger.debug("Mount app context");
91
+ app.getApp().use(async (koaContext, next) => {
92
+ const $ctx = await invoke({
93
+ request: koaContext.request,
94
+ response: koaContext.response,
95
+ koaContext
96
+ });
97
+ return (0, common_1.runInContext)($ctx, async () => {
98
+ try {
99
+ await $ctx.start();
100
+ await next();
101
+ const status = koaContext.status || 404;
102
+ if (status === 404 && !$ctx.isDone()) {
103
+ this.injector.get(common_1.PlatformExceptions)?.resourceNotFound($ctx);
104
+ }
105
+ }
106
+ catch (error) {
107
+ this.injector.get(common_1.PlatformExceptions)?.catch(error, $ctx);
108
+ }
109
+ finally {
110
+ await $ctx.finish();
111
+ }
98
112
  });
99
- return next();
100
113
  });
101
114
  return this;
102
115
  }
@@ -137,6 +150,9 @@ class PlatformKoa {
137
150
  }
138
151
  return parser({ ...options, ...additionalOptions });
139
152
  }
153
+ getPlatformApplication() {
154
+ return this.injector.get(common_1.PlatformApplication);
155
+ }
140
156
  }
141
157
  exports.PlatformKoa = PlatformKoa;
142
158
  //# sourceMappingURL=PlatformKoa.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformKoa.js","sourceRoot":"","sources":["../../../src/components/PlatformKoa.ts"],"names":[],"mappings":";;;;AAAA,iEAAyE;AACzE,yCAasB;AACtB,qCAA4C;AAC5C,sDAAuC;AACvC,4EAAsD;AACtD,aAAa;AACb,4DAA2B;AAE3B,0FAAqF;AACrF,wEAAmE;AACnE,uEAAkE;AAClE,uEAAkE;AAClE,yEAAoE;AACpE,4CAA0C;AAgB1C,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,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AAC;IACpD,CAAC;CACF;AAjID,kCAiIC","sourcesContent":["import KoaRouter, {RouterOptions as KoaRouterOptions} from \"@koa/router\";\nimport {\n createContext,\n InjectorService,\n PlatformAdapter,\n PlatformApplication,\n PlatformBuilder,\n PlatformExceptions,\n PlatformHandler,\n PlatformMulter,\n PlatformMulterSettings,\n PlatformRequest,\n PlatformResponse,\n PlatformStaticsOptions\n} from \"@tsed/common\";\nimport {isFunction, Type} from \"@tsed/core\";\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 {resourceNotFoundMiddleware} from \"../middlewares/resourceNotFoundMiddleware\";\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 Router extends KoaRouter {}\n\n export interface RouterOptions extends KoaRouterOptions {}\n\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, KoaRouter> {\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, KoaRouter>(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, KoaRouter>(module, {\n ...settings,\n adapter: PlatformKoa\n });\n }\n\n onInit() {\n const injector = this.injector;\n const app = this.injector.get<PlatformApplication>(PlatformApplication)!;\n\n const listener: any = (error: any, ctx: Koa.Context) => {\n injector.get<PlatformExceptions>(PlatformExceptions)?.catch(error, ctx.request.$ctx);\n };\n\n app.getApp().silent = true;\n app.getApp().on(\"error\", listener);\n }\n\n useRouter(): this {\n const app = this.injector.get<PlatformApplication<Koa>>(PlatformApplication)!;\n\n app.getApp().use(resourceNotFoundMiddleware);\n app.getApp().use(app.getRouter().routes()).use(app.getRouter().allowedMethods());\n\n return this;\n }\n\n useContext(): this {\n const app = this.injector.get<PlatformApplication<Koa>>(PlatformApplication)!;\n const {logger} = this.injector;\n logger.info(\"Mount app context\");\n\n const invoke = createContext(this.injector);\n\n app.getApp().use(async (ctx: Context, next: Next) => {\n await invoke({\n request: ctx.request as any,\n response: ctx.response as any\n });\n\n return next();\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 router(routerOptions: any = {}) {\n const {settings} = this.injector;\n\n const options = Object.assign({}, settings.get(\"koa.router\", {}), routerOptions);\n const router = new KoaRouter(options) as any;\n\n return {\n router,\n callback() {\n return [router.routes(), router.allowedMethods()];\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"]}
1
+ {"version":3,"file":"PlatformKoa.js","sourceRoot":"","sources":["../../../src/components/PlatformKoa.ts"],"names":[],"mappings":";;;;AAAA,iEAAyE;AACzE,yCAesB;AACtB,qCAA4C;AAE5C,sDAAuC;AACvC,4EAAsD;AACtD,aAAa;AACb,4DAA2B;AAE3B,wEAAmE;AACnE,uEAAkE;AAClE,uEAAkE;AAClE,yEAAoE;AACpE,4CAA0C;AAgB1C,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,CAAiB;IAAG,CAAC;IAEjD;;;;OAIG;IACH,MAAM,CAAC,MAAM,CAAC,MAAiB,EAAE,WAAwC,EAAE;QACzE,OAAO,wB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["import KoaRouter, {RouterOptions as KoaRouterOptions} from \"@koa/router\";\nimport {\n createContext,\n getContext,\n InjectorService,\n PlatformAdapter,\n PlatformApplication,\n PlatformBuilder,\n PlatformExceptions,\n PlatformHandler,\n PlatformMulter,\n PlatformMulterSettings,\n PlatformRequest,\n PlatformResponse,\n PlatformStaticsOptions,\n runInContext\n} from \"@tsed/common\";\nimport {isFunction, Type} from \"@tsed/core\";\nimport {IncomingMessage, ServerResponse} from \"http\";\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 Router extends KoaRouter {}\n\n export interface RouterOptions extends KoaRouterOptions {}\n\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, KoaRouter> {\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, KoaRouter>(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, KoaRouter>(module, {\n ...settings,\n adapter: PlatformKoa\n });\n }\n\n onInit() {\n const injector = this.injector;\n const app = this.getPlatformApplication();\n\n const listener: any = (error: any, ctx: Koa.Context) => {\n injector.get<PlatformExceptions>(PlatformExceptions)?.catch(error, ctx.request.$ctx);\n };\n\n app.getApp().silent = true;\n app.getApp().on(\"error\", listener);\n }\n\n useRouter(): this {\n const app = this.injector.get<PlatformApplication<Koa>>(PlatformApplication)!;\n\n app.getApp().use(app.getRouter().routes()).use(app.getRouter().allowedMethods());\n\n return this;\n }\n\n useContext(): this {\n const app = this.getPlatformApplication();\n const invoke = createContext(this.injector);\n\n this.injector.logger.debug(\"Mount app context\");\n\n app.getApp().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 return runInContext($ctx, async () => {\n try {\n await $ctx.start();\n await 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\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 router(routerOptions: any = {}) {\n const {settings} = this.injector;\n\n const options = Object.assign({}, settings.get(\"koa.router\", {}), routerOptions);\n const router = new KoaRouter(options) as any;\n\n return {\n router,\n callback() {\n return [router.routes(), router.allowedMethods()];\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<Koa>>(PlatformApplication)!;\n }\n}\n"]}
package/lib/cjs/index.js CHANGED
@@ -13,7 +13,6 @@ tslib_1.__exportStar(require("./decorators/state"), exports);
13
13
  tslib_1.__exportStar(require("./decorators/strict"), exports);
14
14
  tslib_1.__exportStar(require("./interfaces/PlatformKoaSettings"), exports);
15
15
  tslib_1.__exportStar(require("./interfaces/interfaces"), exports);
16
- tslib_1.__exportStar(require("./middlewares/resourceNotFoundMiddleware"), exports);
17
16
  tslib_1.__exportStar(require("./middlewares/staticsMiddleware"), exports);
18
17
  tslib_1.__exportStar(require("./services/PlatformKoaHandler"), exports);
19
18
  tslib_1.__exportStar(require("./services/PlatformKoaRequest"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,oDAA0B;AAC1B,mEAAyC;AACzC,qEAA2C;AAC3C,2DAAiC;AACjC,sEAA4C;AAC5C,6DAAmC;AACnC,8DAAoC;AACpC,2EAAiD;AACjD,kEAAwC;AACxC,mFAAyD;AACzD,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/caseSensitive\";\nexport * from \"./decorators/ctx\";\nexport * from \"./decorators/routerSettings\";\nexport * from \"./decorators/state\";\nexport * from \"./decorators/strict\";\nexport * from \"./interfaces/PlatformKoaSettings\";\nexport * from \"./interfaces/interfaces\";\nexport * from \"./middlewares/resourceNotFoundMiddleware\";\nexport * from \"./middlewares/staticsMiddleware\";\nexport * from \"./services/PlatformKoaHandler\";\nexport * from \"./services/PlatformKoaRequest\";\nexport * from \"./services/PlatformKoaResponse\";\nexport * from \"./utils/multer\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,oDAA0B;AAC1B,mEAAyC;AACzC,qEAA2C;AAC3C,2DAAiC;AACjC,sEAA4C;AAC5C,6DAAmC;AACnC,8DAAoC;AACpC,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/caseSensitive\";\nexport * from \"./decorators/ctx\";\nexport * from \"./decorators/routerSettings\";\nexport * from \"./decorators/state\";\nexport * from \"./decorators/strict\";\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,11 +1,10 @@
1
1
  import KoaRouter from "@koa/router";
2
- import { createContext, PlatformApplication, PlatformBuilder, PlatformExceptions, PlatformHandler, PlatformRequest, PlatformResponse } from "@tsed/common";
2
+ import { createContext, PlatformApplication, PlatformBuilder, PlatformExceptions, PlatformHandler, PlatformRequest, PlatformResponse, runInContext } from "@tsed/common";
3
3
  import { isFunction } from "@tsed/core";
4
4
  import Koa from "koa";
5
5
  import koaBodyParser from "koa-bodyparser";
6
6
  // @ts-ignore
7
7
  import koaQs from "koa-qs";
8
- import { resourceNotFoundMiddleware } from "../middlewares/resourceNotFoundMiddleware.js";
9
8
  import { staticsMiddleware } from "../middlewares/staticsMiddleware.js";
10
9
  import { PlatformKoaHandler } from "../services/PlatformKoaHandler.js";
11
10
  import { PlatformKoaRequest } from "../services/PlatformKoaRequest.js";
@@ -69,7 +68,7 @@ export class PlatformKoa {
69
68
  }
70
69
  onInit() {
71
70
  const injector = this.injector;
72
- const app = this.injector.get(PlatformApplication);
71
+ const app = this.getPlatformApplication();
73
72
  const listener = (error, ctx) => {
74
73
  injector.get(PlatformExceptions)?.catch(error, ctx.request.$ctx);
75
74
  };
@@ -78,21 +77,35 @@ export class PlatformKoa {
78
77
  }
79
78
  useRouter() {
80
79
  const app = this.injector.get(PlatformApplication);
81
- app.getApp().use(resourceNotFoundMiddleware);
82
80
  app.getApp().use(app.getRouter().routes()).use(app.getRouter().allowedMethods());
83
81
  return this;
84
82
  }
85
83
  useContext() {
86
- const app = this.injector.get(PlatformApplication);
87
- const { logger } = this.injector;
88
- logger.info("Mount app context");
84
+ const app = this.getPlatformApplication();
89
85
  const invoke = createContext(this.injector);
90
- app.getApp().use(async (ctx, next) => {
91
- await invoke({
92
- request: ctx.request,
93
- response: ctx.response
86
+ this.injector.logger.debug("Mount app context");
87
+ app.getApp().use(async (koaContext, next) => {
88
+ const $ctx = await invoke({
89
+ request: koaContext.request,
90
+ response: koaContext.response,
91
+ koaContext
92
+ });
93
+ return runInContext($ctx, async () => {
94
+ try {
95
+ await $ctx.start();
96
+ await next();
97
+ const status = koaContext.status || 404;
98
+ if (status === 404 && !$ctx.isDone()) {
99
+ this.injector.get(PlatformExceptions)?.resourceNotFound($ctx);
100
+ }
101
+ }
102
+ catch (error) {
103
+ this.injector.get(PlatformExceptions)?.catch(error, $ctx);
104
+ }
105
+ finally {
106
+ await $ctx.finish();
107
+ }
94
108
  });
95
- return next();
96
109
  });
97
110
  return this;
98
111
  }
@@ -133,5 +146,8 @@ export class PlatformKoa {
133
146
  }
134
147
  return parser({ ...options, ...additionalOptions });
135
148
  }
149
+ getPlatformApplication() {
150
+ return this.injector.get(PlatformApplication);
151
+ }
136
152
  }
137
153
  //# 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,EAGb,mBAAmB,EACnB,eAAe,EACf,kBAAkB,EAClB,eAAe,EAGf,eAAe,EACf,gBAAgB,EAEjB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAC,UAAU,EAAO,MAAM,YAAY,CAAC;AAC5C,OAAO,GAAoB,MAAM,KAAK,CAAC;AACvC,OAAO,aAAwB,MAAM,gBAAgB,CAAC;AACtD,aAAa;AACb,OAAO,KAAK,MAAM,QAAQ,CAAC;AAE3B,OAAO,EAAC,0BAA0B,EAAC,MAAM,2CAA2C,CAAC;AACrF,OAAO,EAAC,iBAAiB,EAAC,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAC,kBAAkB,EAAC,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAC,kBAAkB,EAAC,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAC,mBAAmB,EAAC,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAC,SAAS,EAAC,MAAM,iBAAiB,CAAC;AAgB1C,aAAa;AACb,SAAS,CAAC,SAAS,CAAC,OAAO,GAAG,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC;AACxD,SAAS,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;IA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YACxB,CAAC;SACF,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,gBAAqB,EAAE;QAC5B,MAAM,EAAC,QAAQ,EAAC,GAAG,IAAI,CAAC,QAAQ,CAAC;QAEjC,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,QAAQ,CAAC,GAAG,CAAC,YAAY,EAAE,EAAE,CAAC,EAAE,aAAa,CAAC,CAAC;QACjF,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC,OAAO,CAAQ,CAAC;QAE7C,OAAO;YACL,MAAM;YACN,QAAQ;gBACN,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,MAAM,CAAC,cAAc,EAAE,CAAC,CAAC;YACpD,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;CACF","sourcesContent":["import KoaRouter, {RouterOptions as KoaRouterOptions} from \"@koa/router\";\nimport {\n createContext,\n InjectorService,\n PlatformAdapter,\n PlatformApplication,\n PlatformBuilder,\n PlatformExceptions,\n PlatformHandler,\n PlatformMulter,\n PlatformMulterSettings,\n PlatformRequest,\n PlatformResponse,\n PlatformStaticsOptions\n} from \"@tsed/common\";\nimport {isFunction, Type} from \"@tsed/core\";\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 {resourceNotFoundMiddleware} from \"../middlewares/resourceNotFoundMiddleware\";\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 Router extends KoaRouter {}\n\n export interface RouterOptions extends KoaRouterOptions {}\n\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, KoaRouter> {\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, KoaRouter>(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, KoaRouter>(module, {\n ...settings,\n adapter: PlatformKoa\n });\n }\n\n onInit() {\n const injector = this.injector;\n const app = this.injector.get<PlatformApplication>(PlatformApplication)!;\n\n const listener: any = (error: any, ctx: Koa.Context) => {\n injector.get<PlatformExceptions>(PlatformExceptions)?.catch(error, ctx.request.$ctx);\n };\n\n app.getApp().silent = true;\n app.getApp().on(\"error\", listener);\n }\n\n useRouter(): this {\n const app = this.injector.get<PlatformApplication<Koa>>(PlatformApplication)!;\n\n app.getApp().use(resourceNotFoundMiddleware);\n app.getApp().use(app.getRouter().routes()).use(app.getRouter().allowedMethods());\n\n return this;\n }\n\n useContext(): this {\n const app = this.injector.get<PlatformApplication<Koa>>(PlatformApplication)!;\n const {logger} = this.injector;\n logger.info(\"Mount app context\");\n\n const invoke = createContext(this.injector);\n\n app.getApp().use(async (ctx: Context, next: Next) => {\n await invoke({\n request: ctx.request as any,\n response: ctx.response as any\n });\n\n return next();\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 router(routerOptions: any = {}) {\n const {settings} = this.injector;\n\n const options = Object.assign({}, settings.get(\"koa.router\", {}), routerOptions);\n const router = new KoaRouter(options) as any;\n\n return {\n router,\n callback() {\n return [router.routes(), router.allowedMethods()];\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"]}
1
+ {"version":3,"file":"PlatformKoa.js","sourceRoot":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AC,GAAG,OAAO,EAAE,GAAG,iBAAiB,EAAC,CAAC,CAAC;IACpD,CAAC;IAEO,sBAAsB;QAC5B,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAA2B,mBAAmB,CAAE,CAAC;IAC3E,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 PlatformExceptions,\n PlatformHandler,\n PlatformMulter,\n PlatformMulterSettings,\n PlatformRequest,\n PlatformResponse,\n PlatformStaticsOptions,\n runInContext\n} from \"@tsed/common\";\nimport {isFunction, Type} from \"@tsed/core\";\nimport {IncomingMessage, ServerResponse} from \"http\";\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 Router extends KoaRouter {}\n\n export interface RouterOptions extends KoaRouterOptions {}\n\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, KoaRouter> {\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, KoaRouter>(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, KoaRouter>(module, {\n ...settings,\n adapter: PlatformKoa\n });\n }\n\n onInit() {\n const injector = this.injector;\n const app = this.getPlatformApplication();\n\n const listener: any = (error: any, ctx: Koa.Context) => {\n injector.get<PlatformExceptions>(PlatformExceptions)?.catch(error, ctx.request.$ctx);\n };\n\n app.getApp().silent = true;\n app.getApp().on(\"error\", listener);\n }\n\n useRouter(): this {\n const app = this.injector.get<PlatformApplication<Koa>>(PlatformApplication)!;\n\n app.getApp().use(app.getRouter().routes()).use(app.getRouter().allowedMethods());\n\n return this;\n }\n\n useContext(): this {\n const app = this.getPlatformApplication();\n const invoke = createContext(this.injector);\n\n this.injector.logger.debug(\"Mount app context\");\n\n app.getApp().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 return runInContext($ctx, async () => {\n try {\n await $ctx.start();\n await 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\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 router(routerOptions: any = {}) {\n const {settings} = this.injector;\n\n const options = Object.assign({}, settings.get(\"koa.router\", {}), routerOptions);\n const router = new KoaRouter(options) as any;\n\n return {\n router,\n callback() {\n return [router.routes(), router.allowedMethods()];\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<Koa>>(PlatformApplication)!;\n }\n}\n"]}
package/lib/esm/index.js CHANGED
@@ -10,7 +10,6 @@ export * from "./decorators/state.js";
10
10
  export * from "./decorators/strict.js";
11
11
  export * from "./interfaces/PlatformKoaSettings.js";
12
12
  export * from "./interfaces/interfaces.js";
13
- export * from "./middlewares/resourceNotFoundMiddleware.js";
14
13
  export * from "./middlewares/staticsMiddleware.js";
15
14
  export * from "./services/PlatformKoaHandler.js";
16
15
  export * from "./services/PlatformKoaRequest.js";
@@ -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,4BAA4B,CAAC;AAC3C,cAAc,kBAAkB,CAAC;AACjC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kCAAkC,CAAC;AACjD,cAAc,yBAAyB,CAAC;AACxC,cAAc,0CAA0C,CAAC;AACzD,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/caseSensitive\";\nexport * from \"./decorators/ctx\";\nexport * from \"./decorators/routerSettings\";\nexport * from \"./decorators/state\";\nexport * from \"./decorators/strict\";\nexport * from \"./interfaces/PlatformKoaSettings\";\nexport * from \"./interfaces/interfaces\";\nexport * from \"./middlewares/resourceNotFoundMiddleware\";\nexport * from \"./middlewares/staticsMiddleware\";\nexport * from \"./services/PlatformKoaHandler\";\nexport * from \"./services/PlatformKoaRequest\";\nexport * from \"./services/PlatformKoaResponse\";\nexport * from \"./utils/multer\";\n"]}
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,4BAA4B,CAAC;AAC3C,cAAc,kBAAkB,CAAC;AACjC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,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/caseSensitive\";\nexport * from \"./decorators/ctx\";\nexport * from \"./decorators/routerSettings\";\nexport * from \"./decorators/state\";\nexport * from \"./decorators/strict\";\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"]}
@@ -64,4 +64,5 @@ export declare class PlatformKoa implements PlatformAdapter<Koa, KoaRouter> {
64
64
  multipart(options: PlatformMulterSettings): PlatformMulter;
65
65
  statics(endpoint: string, options: PlatformStaticsOptions): any;
66
66
  bodyParser(type: "json" | "urlencoded" | "raw" | "text", additionalOptions?: any): any;
67
+ private getPlatformApplication;
67
68
  }
@@ -10,7 +10,6 @@ export * from "./decorators/state";
10
10
  export * from "./decorators/strict";
11
11
  export * from "./interfaces/PlatformKoaSettings";
12
12
  export * from "./interfaces/interfaces";
13
- export * from "./middlewares/resourceNotFoundMiddleware";
14
13
  export * from "./middlewares/staticsMiddleware";
15
14
  export * from "./services/PlatformKoaHandler";
16
15
  export * from "./services/PlatformKoaRequest";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsed/platform-koa",
3
- "version": "6.127.0",
3
+ "version": "6.128.2",
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": "6.127.0",
56
- "@tsed/core": "6.127.0",
57
- "@tsed/di": "6.127.0",
58
- "@tsed/platform-test-utils": "6.127.0",
55
+ "@tsed/common": "6.128.2",
56
+ "@tsed/core": "6.128.2",
57
+ "@tsed/di": "6.128.2",
58
+ "@tsed/platform-test-utils": "6.128.2",
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": "^6.127.0",
84
- "@tsed/core": "^6.127.0",
85
- "@tsed/di": "^6.127.0",
86
- "@tsed/json-mapper": "^6.127.0",
83
+ "@tsed/common": "^6.128.2",
84
+ "@tsed/core": "^6.128.2",
85
+ "@tsed/di": "^6.128.2",
86
+ "@tsed/json-mapper": "^6.128.2",
87
87
  "@tsed/logger": ">=6.2.0",
88
- "@tsed/openspec": "^6.127.0",
89
- "@tsed/schema": "^6.127.0",
88
+ "@tsed/openspec": "^6.128.2",
89
+ "@tsed/schema": "^6.128.2",
90
90
  "koa": ">=2.13.0",
91
91
  "koa-bodyparser": ">=4.3.0",
92
92
  "koa-compress": ">=5.0.1",
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resourceNotFoundMiddleware = void 0;
4
- const common_1 = require("@tsed/common");
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(common_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":";;;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,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAqB,2BAAkB,CAAC,EAAE,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,15 +0,0 @@
1
- import { PlatformExceptions } from "@tsed/common";
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":"AAAA,OAAO,EAAkB,kBAAkB,EAAC,MAAM,cAAc,CAAC;AAEjE;;;;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, 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,6 +0,0 @@
1
- /**
2
- * @ignore
3
- * @param ctx
4
- * @param next
5
- */
6
- export declare function resourceNotFoundMiddleware(ctx: any, next: any): Promise<void>;