@tsed/platform-koa 8.0.0-rc.5 → 8.0.0-rc.6
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.
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
var PlatformKoa_1;
|
|
2
|
-
import { __decorate } from "tslib";
|
|
3
1
|
import KoaRouter from "@koa/router";
|
|
4
2
|
import { catchAsyncError, isFunction } from "@tsed/core";
|
|
5
|
-
import { runInContext } from "@tsed/di";
|
|
3
|
+
import { constant, inject, runInContext } from "@tsed/di";
|
|
6
4
|
import { PlatformExceptions } from "@tsed/platform-exceptions";
|
|
7
|
-
import { createContext, PlatformAdapter, PlatformBuilder, PlatformHandler,
|
|
5
|
+
import { adapter, application, createContext, PlatformAdapter, PlatformBuilder, PlatformHandler, PlatformRequest, PlatformResponse } from "@tsed/platform-http";
|
|
8
6
|
import { PlatformHandlerType } from "@tsed/platform-router";
|
|
9
7
|
import Koa from "koa";
|
|
10
8
|
import koaBodyParser from "koa-bodyparser";
|
|
@@ -30,7 +28,7 @@ KoaRouter.prototype.match = function match(...args) {
|
|
|
30
28
|
* @platform
|
|
31
29
|
* @koa
|
|
32
30
|
*/
|
|
33
|
-
|
|
31
|
+
export class PlatformKoa extends PlatformAdapter {
|
|
34
32
|
constructor() {
|
|
35
33
|
super(...arguments);
|
|
36
34
|
this.providers = [
|
|
@@ -48,7 +46,6 @@ let PlatformKoa = class PlatformKoa extends PlatformAdapter {
|
|
|
48
46
|
}
|
|
49
47
|
];
|
|
50
48
|
}
|
|
51
|
-
static { PlatformKoa_1 = this; }
|
|
52
49
|
static { this.NAME = "koa"; }
|
|
53
50
|
/**
|
|
54
51
|
* Create new serverless application. In this mode, the component scan are disabled.
|
|
@@ -58,7 +55,7 @@ let PlatformKoa = class PlatformKoa extends PlatformAdapter {
|
|
|
58
55
|
static create(module, settings = {}) {
|
|
59
56
|
return PlatformBuilder.create(module, {
|
|
60
57
|
...settings,
|
|
61
|
-
adapter:
|
|
58
|
+
adapter: PlatformKoa
|
|
62
59
|
});
|
|
63
60
|
}
|
|
64
61
|
/**
|
|
@@ -69,16 +66,14 @@ let PlatformKoa = class PlatformKoa extends PlatformAdapter {
|
|
|
69
66
|
static bootstrap(module, settings = {}) {
|
|
70
67
|
return PlatformBuilder.bootstrap(module, {
|
|
71
68
|
...settings,
|
|
72
|
-
adapter:
|
|
69
|
+
adapter: PlatformKoa
|
|
73
70
|
});
|
|
74
71
|
}
|
|
75
72
|
onInit() {
|
|
76
73
|
this.app.getApp().silent = true;
|
|
77
74
|
}
|
|
78
75
|
mapLayers(layers) {
|
|
79
|
-
const
|
|
80
|
-
const { app } = this;
|
|
81
|
-
const options = settings.get("koa.router", {});
|
|
76
|
+
const options = constant("koa.router", {});
|
|
82
77
|
const rawRouter = new KoaRouter(options);
|
|
83
78
|
layers.forEach((layer) => {
|
|
84
79
|
switch (layer.method) {
|
|
@@ -89,7 +84,7 @@ let PlatformKoa = class PlatformKoa extends PlatformAdapter {
|
|
|
89
84
|
rawRouter[layer.method](...layer.getArgs());
|
|
90
85
|
}
|
|
91
86
|
});
|
|
92
|
-
|
|
87
|
+
application().getApp().use(rawRouter.routes()).use(rawRouter.allowedMethods());
|
|
93
88
|
}
|
|
94
89
|
mapHandler(handler, metadata) {
|
|
95
90
|
return async (koaContext, next) => {
|
|
@@ -105,10 +100,9 @@ let PlatformKoa = class PlatformKoa extends PlatformAdapter {
|
|
|
105
100
|
};
|
|
106
101
|
}
|
|
107
102
|
useContext() {
|
|
108
|
-
const
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
app.use((koaContext, next) => {
|
|
103
|
+
const invoke = createContext();
|
|
104
|
+
const platformExceptions = inject(PlatformExceptions);
|
|
105
|
+
application().use((koaContext, next) => {
|
|
112
106
|
const $ctx = invoke({
|
|
113
107
|
request: koaContext.request,
|
|
114
108
|
response: koaContext.response,
|
|
@@ -134,7 +128,7 @@ let PlatformKoa = class PlatformKoa extends PlatformAdapter {
|
|
|
134
128
|
return this;
|
|
135
129
|
}
|
|
136
130
|
createApp() {
|
|
137
|
-
const app =
|
|
131
|
+
const app = constant("koa.app") || new Koa();
|
|
138
132
|
koaQs(app, "extended");
|
|
139
133
|
return {
|
|
140
134
|
app,
|
|
@@ -149,8 +143,8 @@ let PlatformKoa = class PlatformKoa extends PlatformAdapter {
|
|
|
149
143
|
statics(endpoint, options) {
|
|
150
144
|
return staticsMiddleware(options);
|
|
151
145
|
}
|
|
152
|
-
bodyParser(
|
|
153
|
-
const opts =
|
|
146
|
+
bodyParser(_, additionalOptions = {}) {
|
|
147
|
+
const opts = constant(`koa.bodyParser`);
|
|
154
148
|
let parser = koaBodyParser;
|
|
155
149
|
let options = {};
|
|
156
150
|
if (isFunction(opts)) {
|
|
@@ -159,9 +153,6 @@ let PlatformKoa = class PlatformKoa extends PlatformAdapter {
|
|
|
159
153
|
}
|
|
160
154
|
return parser({ ...options, ...additionalOptions });
|
|
161
155
|
}
|
|
162
|
-
}
|
|
163
|
-
PlatformKoa
|
|
164
|
-
PlatformProvider()
|
|
165
|
-
], PlatformKoa);
|
|
166
|
-
export { PlatformKoa };
|
|
156
|
+
}
|
|
157
|
+
adapter(PlatformKoa);
|
|
167
158
|
//# sourceMappingURL=PlatformKoa.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformKoa.js","sourceRoot":"","sources":["../../../src/components/PlatformKoa.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PlatformKoa.js","sourceRoot":"","sources":["../../../src/components/PlatformKoa.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,aAAa,CAAC;AACpC,OAAO,EAAC,eAAe,EAAE,UAAU,EAAO,MAAM,YAAY,CAAC;AAC7D,OAAO,EAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAC,MAAM,UAAU,CAAC;AACxD,OAAO,EAAC,kBAAkB,EAAC,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EACL,O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AAC;;AAGH,OAAO,CAAC,WAAW,CAAC,CAAC"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
1
3
|
import { Type } from "@tsed/core";
|
|
2
4
|
import { PlatformAdapter, PlatformBuilder, PlatformHandler, PlatformMulter, PlatformMulterSettings, PlatformRequest, PlatformResponse, PlatformStaticsOptions } from "@tsed/platform-http";
|
|
3
5
|
import { PlatformHandlerMetadata, PlatformLayer } from "@tsed/platform-router";
|
|
@@ -49,10 +51,10 @@ export declare class PlatformKoa extends PlatformAdapter<Koa> {
|
|
|
49
51
|
mapHandler(handler: Function, metadata: PlatformHandlerMetadata): (koaContext: Koa.Context, next: Koa.Next) => Promise<any>;
|
|
50
52
|
useContext(): this;
|
|
51
53
|
createApp(): {
|
|
52
|
-
app:
|
|
53
|
-
callback():
|
|
54
|
+
app: Koa<Koa.DefaultState, Koa.DefaultContext>;
|
|
55
|
+
callback(): (req: import("http").IncomingMessage | import("http2").Http2ServerRequest, res: import("http").ServerResponse<import("http").IncomingMessage> | import("http2").Http2ServerResponse<import("http2").Http2ServerRequest>) => Promise<void>;
|
|
54
56
|
};
|
|
55
57
|
multipart(options: PlatformMulterSettings): PlatformMulter;
|
|
56
58
|
statics(endpoint: string, options: PlatformStaticsOptions): any;
|
|
57
|
-
bodyParser(
|
|
59
|
+
bodyParser(_: "json" | "urlencoded" | "raw" | "text", additionalOptions?: any): any;
|
|
58
60
|
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@tsed/platform-koa",
|
|
3
3
|
"description": "Koa package for Ts.ED framework",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "8.0.0-rc.
|
|
5
|
+
"version": "8.0.0-rc.6",
|
|
6
6
|
"source": "./src/index.ts",
|
|
7
7
|
"main": "./lib/esm/index.js",
|
|
8
8
|
"module": "./lib/esm/index.js",
|
|
@@ -53,12 +53,12 @@
|
|
|
53
53
|
"repository": "https://github.com/tsedio/tsed",
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@koa/cors": "5.0.0",
|
|
56
|
-
"@tsed/barrels": "8.0.0-rc.
|
|
57
|
-
"@tsed/core": "8.0.0-rc.
|
|
58
|
-
"@tsed/di": "8.0.0-rc.
|
|
59
|
-
"@tsed/platform-http": "8.0.0-rc.
|
|
60
|
-
"@tsed/platform-test-sdk": "8.0.0-rc.
|
|
61
|
-
"@tsed/typescript": "8.0.0-rc.
|
|
56
|
+
"@tsed/barrels": "8.0.0-rc.6",
|
|
57
|
+
"@tsed/core": "8.0.0-rc.6",
|
|
58
|
+
"@tsed/di": "8.0.0-rc.6",
|
|
59
|
+
"@tsed/platform-http": "8.0.0-rc.6",
|
|
60
|
+
"@tsed/platform-test-sdk": "8.0.0-rc.6",
|
|
61
|
+
"@tsed/typescript": "8.0.0-rc.6",
|
|
62
62
|
"@types/koa": "2.15.0",
|
|
63
63
|
"@types/koa-bodyparser": "4.3.12",
|
|
64
64
|
"@types/koa-compose": "3.2.8",
|
|
@@ -86,13 +86,13 @@
|
|
|
86
86
|
"tslib": "2.7.0"
|
|
87
87
|
},
|
|
88
88
|
"peerDependencies": {
|
|
89
|
-
"@tsed/core": "8.0.0-rc.
|
|
90
|
-
"@tsed/di": "8.0.0-rc.
|
|
91
|
-
"@tsed/json-mapper": "8.0.0-rc.
|
|
89
|
+
"@tsed/core": "8.0.0-rc.6",
|
|
90
|
+
"@tsed/di": "8.0.0-rc.6",
|
|
91
|
+
"@tsed/json-mapper": "8.0.0-rc.6",
|
|
92
92
|
"@tsed/logger": ">=6.7.5",
|
|
93
|
-
"@tsed/openspec": "8.0.0-rc.
|
|
94
|
-
"@tsed/platform-http": "8.0.0-rc.
|
|
95
|
-
"@tsed/schema": "8.0.0-rc.
|
|
93
|
+
"@tsed/openspec": "8.0.0-rc.6",
|
|
94
|
+
"@tsed/platform-http": "8.0.0-rc.6",
|
|
95
|
+
"@tsed/schema": "8.0.0-rc.6",
|
|
96
96
|
"cross-env": "7.0.3",
|
|
97
97
|
"koa": ">=2.13.0",
|
|
98
98
|
"koa-bodyparser": ">=4.3.0",
|
package/vitest.config.mts
CHANGED