@tsed/common 6.70.1 → 7.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/builder/PlatformBuilder.d.ts +0 -4
- package/lib/decorators/index.d.ts +0 -2
- package/lib/decorators/method/location.d.ts +1 -20
- package/lib/decorators/method/redirect.d.ts +1 -50
- package/lib/domain/EndpointMetadata.d.ts +0 -4
- package/lib/domain/PlatformContext.d.ts +6 -8
- package/lib/domain/index.d.ts +0 -1
- package/lib/index.js +177 -248
- package/lib/index.js.map +1 -1
- package/lib/index.modern.js +169 -246
- package/lib/index.modern.js.map +1 -1
- package/lib/interfaces/IncomingEvent.d.ts +6 -0
- package/lib/interfaces/index.d.ts +1 -0
- package/lib/middlewares/index.d.ts +0 -2
- package/lib/services/PlatformRequest.d.ts +7 -1
- package/lib/services/PlatformResponse.d.ts +12 -9
- package/lib/services/PlatformTest.d.ts +3 -1
- package/lib/utils/createContext.d.ts +2 -5
- package/lib/utils/index.d.ts +0 -1
- package/package.json +15 -15
- package/lib/decorators/params/endpointInfo.d.ts +0 -10
- package/lib/decorators/params/responseData.d.ts +0 -9
- package/lib/domain/PropertyMetadata.d.ts +0 -11
- package/lib/middlewares/AcceptMimesMiddleware.d.ts +0 -10
- package/lib/middlewares/GlobalAcceptMimesMiddleware.d.ts +0 -9
- package/lib/utils/loadInjector.d.ts +0 -6
package/lib/index.js
CHANGED
|
@@ -668,14 +668,6 @@ exports.EndpointMetadata = EndpointMetadata_1 = class EndpointMetadata extends s
|
|
|
668
668
|
this.store.set("view", view);
|
|
669
669
|
}
|
|
670
670
|
|
|
671
|
-
get location() {
|
|
672
|
-
return this.store.get("location");
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
set location(url) {
|
|
676
|
-
this.store.set("location", url);
|
|
677
|
-
}
|
|
678
|
-
|
|
679
671
|
get acceptMimes() {
|
|
680
672
|
return this.store.get("acceptMimes", []);
|
|
681
673
|
}
|
|
@@ -683,16 +675,6 @@ exports.EndpointMetadata = EndpointMetadata_1 = class EndpointMetadata extends s
|
|
|
683
675
|
set acceptMimes(mimes) {
|
|
684
676
|
this.store.set("acceptMimes", mimes);
|
|
685
677
|
}
|
|
686
|
-
|
|
687
|
-
get redirect() {
|
|
688
|
-
return this.store.get("redirect");
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
set redirect(options) {
|
|
692
|
-
this.store.set("redirect", _extends({
|
|
693
|
-
status: 302
|
|
694
|
-
}, options));
|
|
695
|
-
}
|
|
696
678
|
/**
|
|
697
679
|
* Get all endpoints from a given class and his parents.
|
|
698
680
|
* @param {Type<any>} target
|
|
@@ -845,12 +827,13 @@ function createHandlerMetadata(injector, obj, routeOptions = {}) {
|
|
|
845
827
|
return new HandlerMetadata(options);
|
|
846
828
|
}
|
|
847
829
|
|
|
848
|
-
function
|
|
849
|
-
return Object.entries(
|
|
830
|
+
function mergeHeaders(specHeaders, headers) {
|
|
831
|
+
return Object.entries(specHeaders).reduce((headers, [key, item]) => {
|
|
832
|
+
key = key.toLowerCase();
|
|
850
833
|
return _extends({}, headers, {
|
|
851
|
-
[key]: String(item.example)
|
|
834
|
+
[key]: headers[key] === undefined ? String(item.example) : headers[key]
|
|
852
835
|
});
|
|
853
|
-
},
|
|
836
|
+
}, headers);
|
|
854
837
|
}
|
|
855
838
|
/**
|
|
856
839
|
* @ignore
|
|
@@ -875,15 +858,13 @@ function setResponseHeaders(ctx) {
|
|
|
875
858
|
response.status(operation.getStatus());
|
|
876
859
|
}
|
|
877
860
|
|
|
861
|
+
const statusCode = response.statusCode;
|
|
878
862
|
const headers = operation.getHeadersOf(response.statusCode);
|
|
879
|
-
response.
|
|
863
|
+
const mergedHeaders = mergeHeaders(headers, response.getHeaders());
|
|
864
|
+
response.setHeaders(mergedHeaders);
|
|
880
865
|
|
|
881
|
-
if (
|
|
882
|
-
response.redirect(
|
|
883
|
-
}
|
|
884
|
-
|
|
885
|
-
if (endpoint.location) {
|
|
886
|
-
response.location(endpoint.location);
|
|
866
|
+
if (operation.isRedirection(statusCode)) {
|
|
867
|
+
response.redirect(statusCode, String(mergedHeaders["location"]));
|
|
887
868
|
}
|
|
888
869
|
}
|
|
889
870
|
|
|
@@ -1476,22 +1457,6 @@ tslib.__decorate([tslib.__param(0, platformParams.Context()), tslib.__metadata("
|
|
|
1476
1457
|
|
|
1477
1458
|
exports.PlatformMulterMiddleware = PlatformMulterMiddleware_1 = tslib.__decorate([platformMiddlewares.Middleware()], exports.PlatformMulterMiddleware);
|
|
1478
1459
|
|
|
1479
|
-
/**
|
|
1480
|
-
* @deprecated Since 2020-11-30. Use PlatformAcceptMimesMiddleware.
|
|
1481
|
-
* @ignore
|
|
1482
|
-
*/
|
|
1483
|
-
|
|
1484
|
-
exports.GlobalAcceptMimesMiddleware = class GlobalAcceptMimesMiddleware {
|
|
1485
|
-
use(ctx) {
|
|
1486
|
-
return;
|
|
1487
|
-
}
|
|
1488
|
-
|
|
1489
|
-
};
|
|
1490
|
-
|
|
1491
|
-
tslib.__decorate([tslib.__param(0, platformParams.Context()), tslib.__metadata("design:type", Function), tslib.__metadata("design:paramtypes", [Object]), tslib.__metadata("design:returntype", void 0)], exports.GlobalAcceptMimesMiddleware.prototype, "use", null);
|
|
1492
|
-
|
|
1493
|
-
exports.GlobalAcceptMimesMiddleware = tslib.__decorate([platformMiddlewares.Middleware()], exports.GlobalAcceptMimesMiddleware);
|
|
1494
|
-
|
|
1495
1460
|
/**
|
|
1496
1461
|
* @middleware
|
|
1497
1462
|
* @platform
|
|
@@ -1518,23 +1483,6 @@ tslib.__decorate([tslib.__param(0, platformParams.Context()), tslib.__metadata("
|
|
|
1518
1483
|
|
|
1519
1484
|
exports.PlatformAcceptMimesMiddleware = tslib.__decorate([platformMiddlewares.Middleware()], exports.PlatformAcceptMimesMiddleware);
|
|
1520
1485
|
|
|
1521
|
-
/**
|
|
1522
|
-
* @middleware
|
|
1523
|
-
* @deprecated Since 2020-11-30. Use PlatformAcceptMimesMiddleware.
|
|
1524
|
-
* @ignore
|
|
1525
|
-
*/
|
|
1526
|
-
|
|
1527
|
-
exports.AcceptMimesMiddleware = class AcceptMimesMiddleware {
|
|
1528
|
-
use(ctx) {
|
|
1529
|
-
return;
|
|
1530
|
-
}
|
|
1531
|
-
|
|
1532
|
-
};
|
|
1533
|
-
|
|
1534
|
-
tslib.__decorate([tslib.__param(0, platformParams.Context()), tslib.__metadata("design:type", Function), tslib.__metadata("design:paramtypes", [Object]), tslib.__metadata("design:returntype", void 0)], exports.AcceptMimesMiddleware.prototype, "use", null);
|
|
1535
|
-
|
|
1536
|
-
exports.AcceptMimesMiddleware = tslib.__decorate([platformMiddlewares.Middleware()], exports.AcceptMimesMiddleware);
|
|
1537
|
-
|
|
1538
1486
|
/**
|
|
1539
1487
|
* Create Ts.ED context handler
|
|
1540
1488
|
* @param fn
|
|
@@ -1697,8 +1645,10 @@ class PlatformControllerBuilder {
|
|
|
1697
1645
|
*/
|
|
1698
1646
|
|
|
1699
1647
|
exports.PlatformRequest = class PlatformRequest {
|
|
1700
|
-
constructor(
|
|
1701
|
-
|
|
1648
|
+
constructor({
|
|
1649
|
+
request
|
|
1650
|
+
}) {
|
|
1651
|
+
this.raw = request;
|
|
1702
1652
|
}
|
|
1703
1653
|
|
|
1704
1654
|
get secure() {
|
|
@@ -1826,7 +1776,9 @@ exports.PlatformRequest = class PlatformRequest {
|
|
|
1826
1776
|
|
|
1827
1777
|
destroy() {
|
|
1828
1778
|
// @ts-ignore
|
|
1829
|
-
delete this.raw;
|
|
1779
|
+
delete this.raw; // @ts-ignore
|
|
1780
|
+
|
|
1781
|
+
delete this.response;
|
|
1830
1782
|
}
|
|
1831
1783
|
/**
|
|
1832
1784
|
* Return the Framework response object (express, koa, etc...)
|
|
@@ -1846,7 +1798,7 @@ exports.PlatformRequest = class PlatformRequest {
|
|
|
1846
1798
|
}
|
|
1847
1799
|
|
|
1848
1800
|
};
|
|
1849
|
-
exports.PlatformRequest = tslib.__decorate([di.Injectable(), di.Scope(di.ProviderScope.INSTANCE), tslib.
|
|
1801
|
+
exports.PlatformRequest = tslib.__decorate([di.Injectable(), di.Scope(di.ProviderScope.INSTANCE), tslib.__metadata("design:paramtypes", [Object])], exports.PlatformRequest);
|
|
1850
1802
|
|
|
1851
1803
|
var PlatformResponse_1;
|
|
1852
1804
|
|
|
@@ -1858,8 +1810,10 @@ const onFinished = require("on-finished");
|
|
|
1858
1810
|
|
|
1859
1811
|
|
|
1860
1812
|
exports.PlatformResponse = PlatformResponse_1 = class PlatformResponse {
|
|
1861
|
-
constructor(
|
|
1862
|
-
|
|
1813
|
+
constructor({
|
|
1814
|
+
response
|
|
1815
|
+
}) {
|
|
1816
|
+
this.raw = response;
|
|
1863
1817
|
}
|
|
1864
1818
|
/**
|
|
1865
1819
|
* Get the current statusCode
|
|
@@ -1970,7 +1924,11 @@ exports.PlatformResponse = PlatformResponse_1 = class PlatformResponse {
|
|
|
1970
1924
|
}
|
|
1971
1925
|
|
|
1972
1926
|
setHeader(key, item) {
|
|
1973
|
-
|
|
1927
|
+
if (key.toLowerCase() === "location") {
|
|
1928
|
+
return this.location(String(item));
|
|
1929
|
+
}
|
|
1930
|
+
|
|
1931
|
+
this.raw.set(key, item);
|
|
1974
1932
|
return this;
|
|
1975
1933
|
}
|
|
1976
1934
|
/**
|
|
@@ -2141,7 +2099,9 @@ exports.PlatformResponse = PlatformResponse_1 = class PlatformResponse {
|
|
|
2141
2099
|
destroy() {
|
|
2142
2100
|
// @ts-ignore
|
|
2143
2101
|
delete this.raw;
|
|
2144
|
-
delete this.data;
|
|
2102
|
+
delete this.data; // @ts-ignore
|
|
2103
|
+
|
|
2104
|
+
delete this.request;
|
|
2145
2105
|
}
|
|
2146
2106
|
|
|
2147
2107
|
isHeadersSent() {
|
|
@@ -2149,28 +2109,24 @@ exports.PlatformResponse = PlatformResponse_1 = class PlatformResponse {
|
|
|
2149
2109
|
}
|
|
2150
2110
|
|
|
2151
2111
|
};
|
|
2112
|
+
exports.PlatformResponse = PlatformResponse_1 = tslib.__decorate([di.Injectable(), di.Scope(di.ProviderScope.INSTANCE), tslib.__metadata("design:paramtypes", [Object])], exports.PlatformResponse);
|
|
2152
2113
|
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
exports.PlatformResponse = PlatformResponse_1 = tslib.__decorate([di.Injectable(), di.Scope(di.ProviderScope.INSTANCE), tslib.__param(0, di.Opts), tslib.__metadata("design:paramtypes", [Object])], exports.PlatformResponse);
|
|
2156
|
-
|
|
2157
|
-
const _excluded$2 = ["response", "request", "endpoint", "url", "ignoreUrlPatterns"];
|
|
2114
|
+
const _excluded$3 = ["event", "endpoint", "ignoreUrlPatterns", "ResponseKlass", "RequestKlass"];
|
|
2158
2115
|
|
|
2159
2116
|
var _ignoreUrlPatterns = /*#__PURE__*/_classPrivateFieldLooseKey("ignoreUrlPatterns");
|
|
2160
2117
|
|
|
2161
2118
|
class PlatformContext extends di.DIContext {
|
|
2162
2119
|
constructor(_ref) {
|
|
2163
2120
|
let {
|
|
2164
|
-
|
|
2165
|
-
request,
|
|
2121
|
+
event,
|
|
2166
2122
|
endpoint,
|
|
2167
|
-
|
|
2168
|
-
|
|
2123
|
+
ignoreUrlPatterns = [],
|
|
2124
|
+
ResponseKlass = exports.PlatformResponse,
|
|
2125
|
+
RequestKlass = exports.PlatformRequest
|
|
2169
2126
|
} = _ref,
|
|
2170
|
-
options = _objectWithoutPropertiesLoose(_ref, _excluded$
|
|
2127
|
+
options = _objectWithoutPropertiesLoose(_ref, _excluded$3);
|
|
2171
2128
|
|
|
2172
2129
|
super(_extends({}, options, {
|
|
2173
|
-
url,
|
|
2174
2130
|
ignoreLog: () => {
|
|
2175
2131
|
return _classPrivateFieldLooseBase(this, _ignoreUrlPatterns)[_ignoreUrlPatterns].find(reg => !!this.url.match(reg));
|
|
2176
2132
|
}
|
|
@@ -2180,21 +2136,23 @@ class PlatformContext extends di.DIContext {
|
|
|
2180
2136
|
value: void 0
|
|
2181
2137
|
});
|
|
2182
2138
|
_classPrivateFieldLooseBase(this, _ignoreUrlPatterns)[_ignoreUrlPatterns] = [];
|
|
2183
|
-
this.url = url;
|
|
2184
2139
|
endpoint && (this.endpoint = endpoint);
|
|
2185
2140
|
_classPrivateFieldLooseBase(this, _ignoreUrlPatterns)[_ignoreUrlPatterns] = ignoreUrlPatterns.map(pattern => typeof pattern === "string" ? new RegExp(pattern, "gi") : pattern);
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
}
|
|
2196
|
-
|
|
2141
|
+
this.response = new ResponseKlass(event);
|
|
2142
|
+
this.request = new RequestKlass(event);
|
|
2143
|
+
this.response.request = this.request;
|
|
2144
|
+
this.request.response = this.response;
|
|
2145
|
+
this.request.request.$ctx = this;
|
|
2146
|
+
this.request.request.id = this.id;
|
|
2147
|
+
this.logger.url = this.url;
|
|
2148
|
+
this.container.set(exports.PlatformResponse, this.response);
|
|
2149
|
+
this.container.set(exports.PlatformRequest, this.request);
|
|
2197
2150
|
this.container.set(PlatformContext, this);
|
|
2151
|
+
this.response.setHeader("x-request-id", this.id);
|
|
2152
|
+
}
|
|
2153
|
+
|
|
2154
|
+
get url() {
|
|
2155
|
+
return this.request.url;
|
|
2198
2156
|
}
|
|
2199
2157
|
|
|
2200
2158
|
get app() {
|
|
@@ -2202,7 +2160,10 @@ class PlatformContext extends di.DIContext {
|
|
|
2202
2160
|
}
|
|
2203
2161
|
|
|
2204
2162
|
async destroy() {
|
|
2163
|
+
var _this$request, _this$request$request;
|
|
2164
|
+
|
|
2205
2165
|
await super.destroy();
|
|
2166
|
+
(_this$request = this.request) == null ? true : (_this$request$request = _this$request.request) == null ? true : delete _this$request$request.$ctx;
|
|
2206
2167
|
this.response.destroy();
|
|
2207
2168
|
this.request.destroy(); // @ts-ignore
|
|
2208
2169
|
|
|
@@ -2417,22 +2378,6 @@ class ControllerProvider extends di.Provider {
|
|
|
2417
2378
|
|
|
2418
2379
|
}
|
|
2419
2380
|
|
|
2420
|
-
exports.PropertyMetadata = class PropertyMetadata extends schema.JsonEntityStore {
|
|
2421
|
-
static get(target, propertyKey) {
|
|
2422
|
-
return schema.JsonEntityStore.from(core.prototypeOf(target), propertyKey);
|
|
2423
|
-
}
|
|
2424
|
-
/**
|
|
2425
|
-
* @deprecated Since 2020-11-11. Use getProperties from @tsed/schema
|
|
2426
|
-
*/
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
static getProperties(target, options = {}) {
|
|
2430
|
-
return schema.getProperties(target, options);
|
|
2431
|
-
}
|
|
2432
|
-
|
|
2433
|
-
};
|
|
2434
|
-
exports.PropertyMetadata = tslib.__decorate([schema.JsonEntityComponent(core.DecoratorTypes.PROP)], exports.PropertyMetadata);
|
|
2435
|
-
|
|
2436
2381
|
function getControllerPath(basePath, provider) {
|
|
2437
2382
|
return (basePath === provider.path ? provider.path : (basePath || "") + provider.path).replace(/\/\//gi, "/");
|
|
2438
2383
|
}
|
|
@@ -2756,16 +2701,6 @@ async function listenHttpsServer(injector) {
|
|
|
2756
2701
|
}
|
|
2757
2702
|
}
|
|
2758
2703
|
|
|
2759
|
-
/**
|
|
2760
|
-
* @ignore
|
|
2761
|
-
* @deprecated User injector.load(container, module) instead
|
|
2762
|
-
*/
|
|
2763
|
-
|
|
2764
|
-
async function loadInjector(injector, container = di.createContainer()) {
|
|
2765
|
-
injector.bootstrap(container);
|
|
2766
|
-
return injector.load(container, exports.PlatformModule);
|
|
2767
|
-
}
|
|
2768
|
-
|
|
2769
2704
|
function printRoutes(routes) {
|
|
2770
2705
|
const mapColor = {
|
|
2771
2706
|
GET: "green",
|
|
@@ -2797,47 +2732,49 @@ function printRoutes(routes) {
|
|
|
2797
2732
|
return "\n" + str.trim();
|
|
2798
2733
|
}
|
|
2799
2734
|
|
|
2735
|
+
const _excluded$2 = ["reqIdBuilder"];
|
|
2736
|
+
|
|
2800
2737
|
const uuidv4 = require("uuid").v4;
|
|
2801
2738
|
|
|
2802
2739
|
const defaultReqIdBuilder = req => req.get("x-request-id") || uuidv4().replace(/-/gi, "");
|
|
2803
2740
|
/**
|
|
2804
2741
|
* Create the TsED context to wrap request, response, injector, etc...
|
|
2805
2742
|
* @param injector
|
|
2806
|
-
* @param request
|
|
2807
|
-
* @param response
|
|
2808
2743
|
* @ignore
|
|
2809
2744
|
*/
|
|
2810
2745
|
|
|
2811
2746
|
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2747
|
+
function createContext(injector) {
|
|
2748
|
+
var _injector$getProvider, _injector$getProvider2;
|
|
2749
|
+
|
|
2750
|
+
const ResponseKlass = (_injector$getProvider = injector.getProvider(exports.PlatformResponse)) == null ? void 0 : _injector$getProvider.useClass;
|
|
2751
|
+
const RequestKlass = (_injector$getProvider2 = injector.getProvider(exports.PlatformRequest)) == null ? void 0 : _injector$getProvider2.useClass;
|
|
2752
|
+
const platformViews$1 = injector.get(platformViews.PlatformViews);
|
|
2753
|
+
|
|
2754
|
+
const _injector$settings$lo = injector.settings.logger,
|
|
2755
|
+
{
|
|
2817
2756
|
reqIdBuilder = defaultReqIdBuilder
|
|
2818
|
-
} =
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
await ctx.
|
|
2837
|
-
|
|
2838
|
-
}
|
|
2839
|
-
await ctx.emit("$onRequest", ctx);
|
|
2840
|
-
return ctx;
|
|
2757
|
+
} = _injector$settings$lo,
|
|
2758
|
+
loggerOptions = _objectWithoutPropertiesLoose(_injector$settings$lo, _excluded$2);
|
|
2759
|
+
|
|
2760
|
+
return async event => {
|
|
2761
|
+
const ctx = new PlatformContext(_extends({
|
|
2762
|
+
event,
|
|
2763
|
+
id: reqIdBuilder(event.request),
|
|
2764
|
+
logger: injector.logger
|
|
2765
|
+
}, loggerOptions, {
|
|
2766
|
+
injector,
|
|
2767
|
+
ResponseKlass,
|
|
2768
|
+
RequestKlass
|
|
2769
|
+
}));
|
|
2770
|
+
ctx.response.platformViews = platformViews$1;
|
|
2771
|
+
ctx.response.onEnd(async () => {
|
|
2772
|
+
await ctx.emit("$onResponse", ctx);
|
|
2773
|
+
await ctx.destroy();
|
|
2774
|
+
});
|
|
2775
|
+
await ctx.emit("$onRequest", ctx);
|
|
2776
|
+
return ctx;
|
|
2777
|
+
};
|
|
2841
2778
|
}
|
|
2842
2779
|
|
|
2843
2780
|
const SKIP_HOOKS = ["$beforeInit", "$afterInit", "$onInit", "$onMountingMiddlewares"];
|
|
@@ -3080,20 +3017,6 @@ class PlatformBuilder {
|
|
|
3080
3017
|
}));
|
|
3081
3018
|
this.settings.set("routes", routes);
|
|
3082
3019
|
}
|
|
3083
|
-
|
|
3084
|
-
createRequest(req) {
|
|
3085
|
-
const Klass = _classPrivateFieldLooseBase(this, _providers)[_providers].get(exports.PlatformRequest).useClass;
|
|
3086
|
-
|
|
3087
|
-
return new Klass(req);
|
|
3088
|
-
}
|
|
3089
|
-
|
|
3090
|
-
createResponse(res) {
|
|
3091
|
-
const Klass = _classPrivateFieldLooseBase(this, _providers)[_providers].get(exports.PlatformResponse).useClass;
|
|
3092
|
-
|
|
3093
|
-
const response = new Klass(res);
|
|
3094
|
-
response.platformViews = this.injector.get(platformViews.PlatformViews);
|
|
3095
|
-
return response;
|
|
3096
|
-
}
|
|
3097
3020
|
/**
|
|
3098
3021
|
* Load middlewares from configuration for the given hook
|
|
3099
3022
|
* @param hook
|
|
@@ -3154,17 +3077,11 @@ class PlatformBuilder {
|
|
|
3154
3077
|
}
|
|
3155
3078
|
|
|
3156
3079
|
async loadRoutes() {
|
|
3157
|
-
var _this$settings$accept;
|
|
3158
|
-
|
|
3159
3080
|
// istanbul ignore next
|
|
3160
3081
|
if (this.settings.logger.level !== "off") {
|
|
3161
3082
|
this.app.use(exports.PlatformLogMiddleware);
|
|
3162
3083
|
}
|
|
3163
3084
|
|
|
3164
|
-
if ((_this$settings$accept = this.settings.acceptMimes) != null && _this$settings$accept.length) {
|
|
3165
|
-
this.app.use(exports.GlobalAcceptMimesMiddleware);
|
|
3166
|
-
}
|
|
3167
|
-
|
|
3168
3085
|
this.log("Load routes");
|
|
3169
3086
|
await this.callHook("$beforeRoutesInit");
|
|
3170
3087
|
await this.callHook("$$loadRoutes");
|
|
@@ -3535,43 +3452,6 @@ function AcceptMime(...mimes) {
|
|
|
3535
3452
|
}));
|
|
3536
3453
|
}
|
|
3537
3454
|
|
|
3538
|
-
/**
|
|
3539
|
-
* Sets the response Location HTTP header to the specified path parameter.
|
|
3540
|
-
*
|
|
3541
|
-
* ```typescript
|
|
3542
|
-
* @Location('/foo/bar')
|
|
3543
|
-
* @Location('http://example.com')
|
|
3544
|
-
* @Location('back')
|
|
3545
|
-
* private myMethod() {
|
|
3546
|
-
*
|
|
3547
|
-
* }
|
|
3548
|
-
* ```
|
|
3549
|
-
*
|
|
3550
|
-
* A path value of “back” has a special meaning, it refers to the URL specified in the `Referer` header of the request. If the `Referer` header was not specified, it refers to “/”.
|
|
3551
|
-
*
|
|
3552
|
-
* @param location
|
|
3553
|
-
* @returns {Function}
|
|
3554
|
-
* @decorator
|
|
3555
|
-
* @operation
|
|
3556
|
-
*/
|
|
3557
|
-
|
|
3558
|
-
function Location(location) {
|
|
3559
|
-
return EndpointFn(endpoint => {
|
|
3560
|
-
endpoint.location = location;
|
|
3561
|
-
});
|
|
3562
|
-
}
|
|
3563
|
-
|
|
3564
|
-
function Redirect(status, url) {
|
|
3565
|
-
url = !url ? status : url;
|
|
3566
|
-
status = typeof status === "number" ? status : 302;
|
|
3567
|
-
return core.useDecorators(schema.Status(status), EndpointFn(endpoint => {
|
|
3568
|
-
endpoint.redirect = {
|
|
3569
|
-
status: +status,
|
|
3570
|
-
url: url
|
|
3571
|
-
};
|
|
3572
|
-
}));
|
|
3573
|
-
}
|
|
3574
|
-
|
|
3575
3455
|
const _excluded$1 = ["children"];
|
|
3576
3456
|
|
|
3577
3457
|
function mapOptions(options) {
|
|
@@ -3631,22 +3511,6 @@ function Controller(options) {
|
|
|
3631
3511
|
};
|
|
3632
3512
|
}
|
|
3633
3513
|
|
|
3634
|
-
/**
|
|
3635
|
-
* Return the current response data. Prefer the @@Context@@ decorator to get or set data.
|
|
3636
|
-
*
|
|
3637
|
-
* @decorator
|
|
3638
|
-
* @operation
|
|
3639
|
-
* @input
|
|
3640
|
-
* @deprecated Use `@Context() $ctx: Context` then $ctx.data.
|
|
3641
|
-
*/
|
|
3642
|
-
|
|
3643
|
-
function ResponseData() {
|
|
3644
|
-
return platformParams.UseParam({
|
|
3645
|
-
paramType: platformParams.ParamTypes.$CTX,
|
|
3646
|
-
dataPath: "$ctx.data"
|
|
3647
|
-
});
|
|
3648
|
-
}
|
|
3649
|
-
|
|
3650
3514
|
function getParamType$1(target, propertyKey, parameterIndex) {
|
|
3651
3515
|
const type = core.Metadata.getOwnParamTypes(target, propertyKey)[parameterIndex];
|
|
3652
3516
|
|
|
@@ -3773,23 +3637,6 @@ function Err() {
|
|
|
3773
3637
|
});
|
|
3774
3638
|
}
|
|
3775
3639
|
|
|
3776
|
-
/**
|
|
3777
|
-
* Get the current endpoint metadata.
|
|
3778
|
-
* @decorator
|
|
3779
|
-
* @operation
|
|
3780
|
-
* @input
|
|
3781
|
-
* @deprecated Use `@Context() $ctx: Context` then `$ctx.endpoint` instead.
|
|
3782
|
-
*/
|
|
3783
|
-
|
|
3784
|
-
function EndpointInfo() {
|
|
3785
|
-
return platformParams.UseParam({
|
|
3786
|
-
paramType: platformParams.ParamTypes.$CTX,
|
|
3787
|
-
dataPath: "$ctx.endpoint",
|
|
3788
|
-
useConverter: false,
|
|
3789
|
-
useValidation: false
|
|
3790
|
-
});
|
|
3791
|
-
}
|
|
3792
|
-
|
|
3793
3640
|
const _excluded = ["use", "collection"];
|
|
3794
3641
|
|
|
3795
3642
|
/**
|
|
@@ -3913,15 +3760,90 @@ class PlatformTest extends di.DITest {
|
|
|
3913
3760
|
return (_DITest$injector$get = di.DITest.injector.get(exports.PlatformApplication)) == null ? void 0 : _DITest$injector$get.callback();
|
|
3914
3761
|
}
|
|
3915
3762
|
|
|
3763
|
+
static createRequest(options = {}) {
|
|
3764
|
+
return _extends({
|
|
3765
|
+
headers: {},
|
|
3766
|
+
|
|
3767
|
+
get(key) {
|
|
3768
|
+
return this.headers[key.toLowerCase()];
|
|
3769
|
+
},
|
|
3770
|
+
|
|
3771
|
+
accepts(mime) {
|
|
3772
|
+
return require("accepts")(this).types([].concat(mime));
|
|
3773
|
+
}
|
|
3774
|
+
|
|
3775
|
+
}, options);
|
|
3776
|
+
}
|
|
3777
|
+
|
|
3778
|
+
static createResponse(options = {}) {
|
|
3779
|
+
return _extends({
|
|
3780
|
+
headers: {},
|
|
3781
|
+
locals: {},
|
|
3782
|
+
statusCode: 200,
|
|
3783
|
+
|
|
3784
|
+
status(code) {
|
|
3785
|
+
this.statusCode = code;
|
|
3786
|
+
return this;
|
|
3787
|
+
},
|
|
3788
|
+
|
|
3789
|
+
contentType(content) {
|
|
3790
|
+
this.set("content-type", content);
|
|
3791
|
+
},
|
|
3792
|
+
|
|
3793
|
+
contentLength(content) {
|
|
3794
|
+
this.set("content-length", content);
|
|
3795
|
+
},
|
|
3796
|
+
|
|
3797
|
+
redirect(status, path) {
|
|
3798
|
+
this.statusCode = status;
|
|
3799
|
+
this.set("location", path);
|
|
3800
|
+
},
|
|
3801
|
+
|
|
3802
|
+
location(path) {
|
|
3803
|
+
this.set("location", path);
|
|
3804
|
+
},
|
|
3805
|
+
|
|
3806
|
+
get(key) {
|
|
3807
|
+
return this.headers[key.toLowerCase()];
|
|
3808
|
+
},
|
|
3809
|
+
|
|
3810
|
+
getHeaders() {
|
|
3811
|
+
return this.headers;
|
|
3812
|
+
},
|
|
3813
|
+
|
|
3814
|
+
set(key, value) {
|
|
3815
|
+
this.headers[key.toLowerCase()] = value;
|
|
3816
|
+
return this;
|
|
3817
|
+
},
|
|
3818
|
+
|
|
3819
|
+
send(data) {
|
|
3820
|
+
this.data = data;
|
|
3821
|
+
},
|
|
3822
|
+
|
|
3823
|
+
json(data) {
|
|
3824
|
+
this.data = data;
|
|
3825
|
+
}
|
|
3826
|
+
|
|
3827
|
+
}, options);
|
|
3828
|
+
}
|
|
3829
|
+
|
|
3916
3830
|
static createRequestContext(options = {}) {
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
|
|
3831
|
+
var _options$request, _options$event, _options$response, _options$event2;
|
|
3832
|
+
|
|
3833
|
+
const event = {
|
|
3834
|
+
request: (options == null ? void 0 : (_options$request = options.request) == null ? void 0 : _options$request.request) || (options == null ? void 0 : (_options$event = options.event) == null ? void 0 : _options$event.request) || PlatformTest.createRequest(),
|
|
3835
|
+
response: (options == null ? void 0 : (_options$response = options.response) == null ? void 0 : _options$response.response) || (options == null ? void 0 : (_options$event2 = options.event) == null ? void 0 : _options$event2.response) || PlatformTest.createResponse()
|
|
3836
|
+
};
|
|
3837
|
+
const ctx = new PlatformContext(_extends({
|
|
3920
3838
|
id: "id",
|
|
3921
3839
|
injector: di.DITest.injector,
|
|
3922
3840
|
logger: di.DITest.injector.logger,
|
|
3923
3841
|
url: "/"
|
|
3924
|
-
}, options
|
|
3842
|
+
}, options, {
|
|
3843
|
+
event
|
|
3844
|
+
}));
|
|
3845
|
+
ctx.response.platformViews = PlatformTest.get(platformViews.PlatformViews);
|
|
3846
|
+
return ctx;
|
|
3925
3847
|
}
|
|
3926
3848
|
|
|
3927
3849
|
}
|
|
@@ -3945,6 +3867,18 @@ Object.defineProperty(exports, 'Logger', {
|
|
|
3945
3867
|
return logger.Logger;
|
|
3946
3868
|
}
|
|
3947
3869
|
});
|
|
3870
|
+
Object.defineProperty(exports, 'Location', {
|
|
3871
|
+
enumerable: true,
|
|
3872
|
+
get: function () {
|
|
3873
|
+
return schema.Location;
|
|
3874
|
+
}
|
|
3875
|
+
});
|
|
3876
|
+
Object.defineProperty(exports, 'Redirect', {
|
|
3877
|
+
enumerable: true,
|
|
3878
|
+
get: function () {
|
|
3879
|
+
return schema.Redirect;
|
|
3880
|
+
}
|
|
3881
|
+
});
|
|
3948
3882
|
exports.AcceptMime = AcceptMime;
|
|
3949
3883
|
exports.All = All;
|
|
3950
3884
|
exports.AnyToPromiseWithCtx = AnyToPromiseWithCtx;
|
|
@@ -3952,14 +3886,12 @@ exports.Controller = Controller;
|
|
|
3952
3886
|
exports.ControllerProvider = ControllerProvider;
|
|
3953
3887
|
exports.Delete = Delete;
|
|
3954
3888
|
exports.EndpointFn = EndpointFn;
|
|
3955
|
-
exports.EndpointInfo = EndpointInfo;
|
|
3956
3889
|
exports.Err = Err;
|
|
3957
3890
|
exports.Get = Get;
|
|
3958
3891
|
exports.HandlerMetadata = HandlerMetadata;
|
|
3959
3892
|
exports.Head = Head;
|
|
3960
3893
|
exports.HttpServer = HttpServer;
|
|
3961
3894
|
exports.HttpsServer = HttpsServer;
|
|
3962
|
-
exports.Location = Location;
|
|
3963
3895
|
exports.MulterFileSize = MulterFileSize;
|
|
3964
3896
|
exports.MulterOptions = MulterOptions;
|
|
3965
3897
|
exports.MultipartFile = MultipartFile;
|
|
@@ -3975,12 +3907,10 @@ exports.PlatformTest = PlatformTest;
|
|
|
3975
3907
|
exports.Post = Post;
|
|
3976
3908
|
exports.Put = Put;
|
|
3977
3909
|
exports.ROUTER_OPTIONS = ROUTER_OPTIONS;
|
|
3978
|
-
exports.Redirect = Redirect;
|
|
3979
3910
|
exports.Req = Req;
|
|
3980
3911
|
exports.Request = Request;
|
|
3981
3912
|
exports.Res = Res;
|
|
3982
3913
|
exports.Response = Response;
|
|
3983
|
-
exports.ResponseData = ResponseData;
|
|
3984
3914
|
exports.bindEndpointMiddleware = bindEndpointMiddleware;
|
|
3985
3915
|
exports.createContext = createContext;
|
|
3986
3916
|
exports.createHttpServer = createHttpServer;
|
|
@@ -3990,7 +3920,6 @@ exports.createPlatformApplication = createPlatformApplication;
|
|
|
3990
3920
|
exports.listenHttpServer = listenHttpServer;
|
|
3991
3921
|
exports.listenHttpsServer = listenHttpsServer;
|
|
3992
3922
|
exports.listenServer = listenServer;
|
|
3993
|
-
exports.loadInjector = loadInjector;
|
|
3994
3923
|
exports.mapReturnedResponse = mapReturnedResponse;
|
|
3995
3924
|
exports.printRoutes = printRoutes;
|
|
3996
3925
|
exports.useCtxHandler = useCtxHandler;
|