@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.
@@ -1,4 +1,4 @@
1
- import { DIConfiguration, ProviderType, ProviderScope, Injectable, InjectorService, Configuration, Inject, Constant, Scope, Opts, DIContext, Provider, Module, setLoggerLevel, GlobalProviders, registerProvider, createContainer, Container, getConfiguration, registerController, DITest } from '@tsed/di';
1
+ import { DIConfiguration, ProviderType, ProviderScope, Injectable, InjectorService, Configuration, Inject, Constant, Scope, DIContext, Provider, Module, setLoggerLevel, GlobalProviders, registerProvider, Container, createContainer, getConfiguration, registerController, DITest } from '@tsed/di';
2
2
  export * from '@tsed/di';
3
3
  import { Context, ParamTypes, ParamMetadata, PlatformParams, UseParam, mapParamsOptions } from '@tsed/platform-params';
4
4
  export * from '@tsed/platform-params';
@@ -18,7 +18,8 @@ import { __decorate, __metadata, __param } from 'tslib';
18
18
  import { Env, AnyToPromise, AnyToPromiseStatus, nameOf, Store, descriptorOf, classOf, prototypeOf, deepMerge, isFunction, Enumerable, DecoratorTypes, isStream, isBoolean, isNumber, isString, uniq, toMap, constructorOf, StoreMerge, Metadata, useDecorators, useMethodDecorators, isArrayOrArrayClass, isClass } from '@tsed/core';
19
19
  import { PerfLogger } from '@tsed/perf';
20
20
  import { Exception, NotAcceptable } from '@tsed/exceptions';
21
- import { JsonEntityStore, getOperationsStores, JsonEntityComponent, OperationMethods, getProperties, Returns, Consumes, JsonEntityFn, Produces, Status } from '@tsed/schema';
21
+ import { JsonEntityStore, getOperationsStores, JsonEntityComponent, OperationMethods, Returns, Consumes, JsonEntityFn, Produces } from '@tsed/schema';
22
+ export { Location, Redirect } from '@tsed/schema';
22
23
  import { serialize, deserialize } from '@tsed/json-mapper';
23
24
  import { promisify } from 'util';
24
25
  import Http, { ServerResponse, IncomingMessage } from 'http';
@@ -670,14 +671,6 @@ let EndpointMetadata = EndpointMetadata_1 = class EndpointMetadata extends JsonE
670
671
  this.store.set("view", view);
671
672
  }
672
673
 
673
- get location() {
674
- return this.store.get("location");
675
- }
676
-
677
- set location(url) {
678
- this.store.set("location", url);
679
- }
680
-
681
674
  get acceptMimes() {
682
675
  return this.store.get("acceptMimes", []);
683
676
  }
@@ -685,16 +678,6 @@ let EndpointMetadata = EndpointMetadata_1 = class EndpointMetadata extends JsonE
685
678
  set acceptMimes(mimes) {
686
679
  this.store.set("acceptMimes", mimes);
687
680
  }
688
-
689
- get redirect() {
690
- return this.store.get("redirect");
691
- }
692
-
693
- set redirect(options) {
694
- this.store.set("redirect", _extends({
695
- status: 302
696
- }, options));
697
- }
698
681
  /**
699
682
  * Get all endpoints from a given class and his parents.
700
683
  * @param {Type<any>} target
@@ -847,12 +830,13 @@ function createHandlerMetadata(injector, obj, routeOptions = {}) {
847
830
  return new HandlerMetadata(options);
848
831
  }
849
832
 
850
- function toHeaders(headers) {
851
- return Object.entries(headers).reduce((headers, [key, item]) => {
833
+ function mergeHeaders(specHeaders, headers) {
834
+ return Object.entries(specHeaders).reduce((headers, [key, item]) => {
835
+ key = key.toLowerCase();
852
836
  return _extends({}, headers, {
853
- [key]: String(item.example)
837
+ [key]: headers[key] === undefined ? String(item.example) : headers[key]
854
838
  });
855
- }, {});
839
+ }, headers);
856
840
  }
857
841
  /**
858
842
  * @ignore
@@ -877,15 +861,13 @@ function setResponseHeaders(ctx) {
877
861
  response.status(operation.getStatus());
878
862
  }
879
863
 
864
+ const statusCode = response.statusCode;
880
865
  const headers = operation.getHeadersOf(response.statusCode);
881
- response.setHeaders(toHeaders(headers));
882
-
883
- if (endpoint.redirect) {
884
- response.redirect(endpoint.redirect.status || 302, endpoint.redirect.url);
885
- }
866
+ const mergedHeaders = mergeHeaders(headers, response.getHeaders());
867
+ response.setHeaders(mergedHeaders);
886
868
 
887
- if (endpoint.location) {
888
- response.location(endpoint.location);
869
+ if (operation.isRedirection(statusCode)) {
870
+ response.redirect(statusCode, String(mergedHeaders["location"]));
889
871
  }
890
872
  }
891
873
 
@@ -1486,22 +1468,6 @@ __decorate([__param(0, Context()), __metadata("design:type", Function), __metada
1486
1468
 
1487
1469
  PlatformMulterMiddleware = PlatformMulterMiddleware_1 = __decorate([Middleware()], PlatformMulterMiddleware);
1488
1470
 
1489
- /**
1490
- * @deprecated Since 2020-11-30. Use PlatformAcceptMimesMiddleware.
1491
- * @ignore
1492
- */
1493
-
1494
- let GlobalAcceptMimesMiddleware = class GlobalAcceptMimesMiddleware {
1495
- use(ctx) {
1496
- return;
1497
- }
1498
-
1499
- };
1500
-
1501
- __decorate([__param(0, Context()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0)], GlobalAcceptMimesMiddleware.prototype, "use", null);
1502
-
1503
- GlobalAcceptMimesMiddleware = __decorate([Middleware()], GlobalAcceptMimesMiddleware);
1504
-
1505
1471
  /**
1506
1472
  * @middleware
1507
1473
  * @platform
@@ -1528,23 +1494,6 @@ __decorate([__param(0, Context()), __metadata("design:type", Function), __metada
1528
1494
 
1529
1495
  PlatformAcceptMimesMiddleware = __decorate([Middleware()], PlatformAcceptMimesMiddleware);
1530
1496
 
1531
- /**
1532
- * @middleware
1533
- * @deprecated Since 2020-11-30. Use PlatformAcceptMimesMiddleware.
1534
- * @ignore
1535
- */
1536
-
1537
- let AcceptMimesMiddleware = class AcceptMimesMiddleware {
1538
- use(ctx) {
1539
- return;
1540
- }
1541
-
1542
- };
1543
-
1544
- __decorate([__param(0, Context()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0)], AcceptMimesMiddleware.prototype, "use", null);
1545
-
1546
- AcceptMimesMiddleware = __decorate([Middleware()], AcceptMimesMiddleware);
1547
-
1548
1497
  /**
1549
1498
  * Create Ts.ED context handler
1550
1499
  * @param fn
@@ -1707,8 +1656,10 @@ class PlatformControllerBuilder {
1707
1656
  */
1708
1657
 
1709
1658
  let PlatformRequest = class PlatformRequest {
1710
- constructor(raw) {
1711
- this.raw = raw;
1659
+ constructor({
1660
+ request
1661
+ }) {
1662
+ this.raw = request;
1712
1663
  }
1713
1664
 
1714
1665
  get secure() {
@@ -1836,7 +1787,9 @@ let PlatformRequest = class PlatformRequest {
1836
1787
 
1837
1788
  destroy() {
1838
1789
  // @ts-ignore
1839
- delete this.raw;
1790
+ delete this.raw; // @ts-ignore
1791
+
1792
+ delete this.response;
1840
1793
  }
1841
1794
  /**
1842
1795
  * Return the Framework response object (express, koa, etc...)
@@ -1856,7 +1809,7 @@ let PlatformRequest = class PlatformRequest {
1856
1809
  }
1857
1810
 
1858
1811
  };
1859
- PlatformRequest = __decorate([Injectable(), Scope(ProviderScope.INSTANCE), __param(0, Opts), __metadata("design:paramtypes", [Object])], PlatformRequest);
1812
+ PlatformRequest = __decorate([Injectable(), Scope(ProviderScope.INSTANCE), __metadata("design:paramtypes", [Object])], PlatformRequest);
1860
1813
 
1861
1814
  var PlatformResponse_1;
1862
1815
 
@@ -1868,8 +1821,10 @@ const onFinished = require("on-finished");
1868
1821
 
1869
1822
 
1870
1823
  let PlatformResponse = PlatformResponse_1 = class PlatformResponse {
1871
- constructor(raw) {
1872
- this.raw = raw;
1824
+ constructor({
1825
+ response
1826
+ }) {
1827
+ this.raw = response;
1873
1828
  }
1874
1829
  /**
1875
1830
  * Get the current statusCode
@@ -1980,7 +1935,11 @@ let PlatformResponse = PlatformResponse_1 = class PlatformResponse {
1980
1935
  }
1981
1936
 
1982
1937
  setHeader(key, item) {
1983
- this.raw.set(key, String(item));
1938
+ if (key.toLowerCase() === "location") {
1939
+ return this.location(String(item));
1940
+ }
1941
+
1942
+ this.raw.set(key, item);
1984
1943
  return this;
1985
1944
  }
1986
1945
  /**
@@ -2151,7 +2110,9 @@ let PlatformResponse = PlatformResponse_1 = class PlatformResponse {
2151
2110
  destroy() {
2152
2111
  // @ts-ignore
2153
2112
  delete this.raw;
2154
- delete this.data;
2113
+ delete this.data; // @ts-ignore
2114
+
2115
+ delete this.request;
2155
2116
  }
2156
2117
 
2157
2118
  isHeadersSent() {
@@ -2159,28 +2120,24 @@ let PlatformResponse = PlatformResponse_1 = class PlatformResponse {
2159
2120
  }
2160
2121
 
2161
2122
  };
2123
+ PlatformResponse = PlatformResponse_1 = __decorate([Injectable(), Scope(ProviderScope.INSTANCE), __metadata("design:paramtypes", [Object])], PlatformResponse);
2162
2124
 
2163
- __decorate([Inject(), __metadata("design:type", PlatformViews)], PlatformResponse.prototype, "platformViews", void 0);
2164
-
2165
- PlatformResponse = PlatformResponse_1 = __decorate([Injectable(), Scope(ProviderScope.INSTANCE), __param(0, Opts), __metadata("design:paramtypes", [Object])], PlatformResponse);
2166
-
2167
- const _excluded$2 = ["response", "request", "endpoint", "url", "ignoreUrlPatterns"];
2125
+ const _excluded$3 = ["event", "endpoint", "ignoreUrlPatterns", "ResponseKlass", "RequestKlass"];
2168
2126
 
2169
2127
  var _ignoreUrlPatterns = /*#__PURE__*/_classPrivateFieldLooseKey("ignoreUrlPatterns");
2170
2128
 
2171
2129
  class PlatformContext extends DIContext {
2172
2130
  constructor(_ref) {
2173
2131
  let {
2174
- response,
2175
- request,
2132
+ event,
2176
2133
  endpoint,
2177
- url,
2178
- ignoreUrlPatterns = []
2134
+ ignoreUrlPatterns = [],
2135
+ ResponseKlass = PlatformResponse,
2136
+ RequestKlass = PlatformRequest
2179
2137
  } = _ref,
2180
- options = _objectWithoutPropertiesLoose(_ref, _excluded$2);
2138
+ options = _objectWithoutPropertiesLoose(_ref, _excluded$3);
2181
2139
 
2182
2140
  super(_extends({}, options, {
2183
- url,
2184
2141
  ignoreLog: () => {
2185
2142
  return _classPrivateFieldLooseBase(this, _ignoreUrlPatterns)[_ignoreUrlPatterns].find(reg => !!this.url.match(reg));
2186
2143
  }
@@ -2190,21 +2147,23 @@ class PlatformContext extends DIContext {
2190
2147
  value: void 0
2191
2148
  });
2192
2149
  _classPrivateFieldLooseBase(this, _ignoreUrlPatterns)[_ignoreUrlPatterns] = [];
2193
- this.url = url;
2194
2150
  endpoint && (this.endpoint = endpoint);
2195
2151
  _classPrivateFieldLooseBase(this, _ignoreUrlPatterns)[_ignoreUrlPatterns] = ignoreUrlPatterns.map(pattern => typeof pattern === "string" ? new RegExp(pattern, "gi") : pattern);
2196
-
2197
- if (response) {
2198
- this.response = response;
2199
- this.container.set(PlatformResponse, response);
2200
- }
2201
-
2202
- if (request) {
2203
- this.request = request;
2204
- this.container.set(PlatformRequest, request);
2205
- }
2206
-
2152
+ this.response = new ResponseKlass(event);
2153
+ this.request = new RequestKlass(event);
2154
+ this.response.request = this.request;
2155
+ this.request.response = this.response;
2156
+ this.request.request.$ctx = this;
2157
+ this.request.request.id = this.id;
2158
+ this.logger.url = this.url;
2159
+ this.container.set(PlatformResponse, this.response);
2160
+ this.container.set(PlatformRequest, this.request);
2207
2161
  this.container.set(PlatformContext, this);
2162
+ this.response.setHeader("x-request-id", this.id);
2163
+ }
2164
+
2165
+ get url() {
2166
+ return this.request.url;
2208
2167
  }
2209
2168
 
2210
2169
  get app() {
@@ -2212,7 +2171,10 @@ class PlatformContext extends DIContext {
2212
2171
  }
2213
2172
 
2214
2173
  async destroy() {
2174
+ var _this$request, _this$request$request;
2175
+
2215
2176
  await super.destroy();
2177
+ (_this$request = this.request) == null ? true : (_this$request$request = _this$request.request) == null ? true : delete _this$request$request.$ctx;
2216
2178
  this.response.destroy();
2217
2179
  this.request.destroy(); // @ts-ignore
2218
2180
 
@@ -2427,22 +2389,6 @@ class ControllerProvider extends Provider {
2427
2389
 
2428
2390
  }
2429
2391
 
2430
- let PropertyMetadata = class PropertyMetadata extends JsonEntityStore {
2431
- static get(target, propertyKey) {
2432
- return JsonEntityStore.from(prototypeOf(target), propertyKey);
2433
- }
2434
- /**
2435
- * @deprecated Since 2020-11-11. Use getProperties from @tsed/schema
2436
- */
2437
-
2438
-
2439
- static getProperties(target, options = {}) {
2440
- return getProperties(target, options);
2441
- }
2442
-
2443
- };
2444
- PropertyMetadata = __decorate([JsonEntityComponent(DecoratorTypes.PROP)], PropertyMetadata);
2445
-
2446
2392
  function getControllerPath(basePath, provider) {
2447
2393
  return (basePath === provider.path ? provider.path : (basePath || "") + provider.path).replace(/\/\//gi, "/");
2448
2394
  }
@@ -2766,16 +2712,6 @@ async function listenHttpsServer(injector) {
2766
2712
  }
2767
2713
  }
2768
2714
 
2769
- /**
2770
- * @ignore
2771
- * @deprecated User injector.load(container, module) instead
2772
- */
2773
-
2774
- async function loadInjector(injector, container = createContainer()) {
2775
- injector.bootstrap(container);
2776
- return injector.load(container, PlatformModule);
2777
- }
2778
-
2779
2715
  function printRoutes(routes) {
2780
2716
  const mapColor = {
2781
2717
  GET: "green",
@@ -2807,47 +2743,49 @@ function printRoutes(routes) {
2807
2743
  return "\n" + str.trim();
2808
2744
  }
2809
2745
 
2746
+ const _excluded$2 = ["reqIdBuilder"];
2747
+
2810
2748
  const uuidv4 = require("uuid").v4;
2811
2749
 
2812
2750
  const defaultReqIdBuilder = req => req.get("x-request-id") || uuidv4().replace(/-/gi, "");
2813
2751
  /**
2814
2752
  * Create the TsED context to wrap request, response, injector, etc...
2815
2753
  * @param injector
2816
- * @param request
2817
- * @param response
2818
2754
  * @ignore
2819
2755
  */
2820
2756
 
2821
2757
 
2822
- async function createContext(injector, request, response) {
2823
- const {
2824
- level,
2825
- ignoreUrlPatterns,
2826
- maxStackSize,
2758
+ function createContext(injector) {
2759
+ var _injector$getProvider, _injector$getProvider2;
2760
+
2761
+ const ResponseKlass = (_injector$getProvider = injector.getProvider(PlatformResponse)) == null ? void 0 : _injector$getProvider.useClass;
2762
+ const RequestKlass = (_injector$getProvider2 = injector.getProvider(PlatformRequest)) == null ? void 0 : _injector$getProvider2.useClass;
2763
+ const platformViews = injector.get(PlatformViews);
2764
+
2765
+ const _injector$settings$lo = injector.settings.logger,
2766
+ {
2827
2767
  reqIdBuilder = defaultReqIdBuilder
2828
- } = injector.settings.logger;
2829
- const req = request.getRequest();
2830
- const id = reqIdBuilder(req);
2831
- const ctx = new PlatformContext({
2832
- id,
2833
- logger: injector.logger,
2834
- url: request.url,
2835
- ignoreUrlPatterns,
2836
- level,
2837
- maxStackSize,
2838
- injector,
2839
- response,
2840
- request
2841
- });
2842
- req.$ctx = ctx;
2843
- response.setHeader("x-request-id", id);
2844
- response.onEnd(async () => {
2845
- await ctx.emit("$onResponse", ctx);
2846
- await ctx.destroy();
2847
- delete req.$ctx;
2848
- });
2849
- await ctx.emit("$onRequest", ctx);
2850
- return ctx;
2768
+ } = _injector$settings$lo,
2769
+ loggerOptions = _objectWithoutPropertiesLoose(_injector$settings$lo, _excluded$2);
2770
+
2771
+ return async event => {
2772
+ const ctx = new PlatformContext(_extends({
2773
+ event,
2774
+ id: reqIdBuilder(event.request),
2775
+ logger: injector.logger
2776
+ }, loggerOptions, {
2777
+ injector,
2778
+ ResponseKlass,
2779
+ RequestKlass
2780
+ }));
2781
+ ctx.response.platformViews = platformViews;
2782
+ ctx.response.onEnd(async () => {
2783
+ await ctx.emit("$onResponse", ctx);
2784
+ await ctx.destroy();
2785
+ });
2786
+ await ctx.emit("$onRequest", ctx);
2787
+ return ctx;
2788
+ };
2851
2789
  }
2852
2790
 
2853
2791
  const SKIP_HOOKS = ["$beforeInit", "$afterInit", "$onInit", "$onMountingMiddlewares"];
@@ -3090,20 +3028,6 @@ class PlatformBuilder {
3090
3028
  }));
3091
3029
  this.settings.set("routes", routes);
3092
3030
  }
3093
-
3094
- createRequest(req) {
3095
- const Klass = _classPrivateFieldLooseBase(this, _providers)[_providers].get(PlatformRequest).useClass;
3096
-
3097
- return new Klass(req);
3098
- }
3099
-
3100
- createResponse(res) {
3101
- const Klass = _classPrivateFieldLooseBase(this, _providers)[_providers].get(PlatformResponse).useClass;
3102
-
3103
- const response = new Klass(res);
3104
- response.platformViews = this.injector.get(PlatformViews);
3105
- return response;
3106
- }
3107
3031
  /**
3108
3032
  * Load middlewares from configuration for the given hook
3109
3033
  * @param hook
@@ -3164,17 +3088,11 @@ class PlatformBuilder {
3164
3088
  }
3165
3089
 
3166
3090
  async loadRoutes() {
3167
- var _this$settings$accept;
3168
-
3169
3091
  // istanbul ignore next
3170
3092
  if (this.settings.logger.level !== "off") {
3171
3093
  this.app.use(PlatformLogMiddleware);
3172
3094
  }
3173
3095
 
3174
- if ((_this$settings$accept = this.settings.acceptMimes) != null && _this$settings$accept.length) {
3175
- this.app.use(GlobalAcceptMimesMiddleware);
3176
- }
3177
-
3178
3096
  this.log("Load routes");
3179
3097
  await this.callHook("$beforeRoutesInit");
3180
3098
  await this.callHook("$$loadRoutes");
@@ -3545,43 +3463,6 @@ function AcceptMime(...mimes) {
3545
3463
  }));
3546
3464
  }
3547
3465
 
3548
- /**
3549
- * Sets the response Location HTTP header to the specified path parameter.
3550
- *
3551
- * ```typescript
3552
- * @Location('/foo/bar')
3553
- * @Location('http://example.com')
3554
- * @Location('back')
3555
- * private myMethod() {
3556
- *
3557
- * }
3558
- * ```
3559
- *
3560
- * 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 “/”.
3561
- *
3562
- * @param location
3563
- * @returns {Function}
3564
- * @decorator
3565
- * @operation
3566
- */
3567
-
3568
- function Location(location) {
3569
- return EndpointFn(endpoint => {
3570
- endpoint.location = location;
3571
- });
3572
- }
3573
-
3574
- function Redirect(status, url) {
3575
- url = !url ? status : url;
3576
- status = typeof status === "number" ? status : 302;
3577
- return useDecorators(Status(status), EndpointFn(endpoint => {
3578
- endpoint.redirect = {
3579
- status: +status,
3580
- url: url
3581
- };
3582
- }));
3583
- }
3584
-
3585
3466
  const _excluded$1 = ["children"];
3586
3467
 
3587
3468
  function mapOptions(options) {
@@ -3641,22 +3522,6 @@ function Controller(options) {
3641
3522
  };
3642
3523
  }
3643
3524
 
3644
- /**
3645
- * Return the current response data. Prefer the @@Context@@ decorator to get or set data.
3646
- *
3647
- * @decorator
3648
- * @operation
3649
- * @input
3650
- * @deprecated Use `@Context() $ctx: Context` then $ctx.data.
3651
- */
3652
-
3653
- function ResponseData() {
3654
- return UseParam({
3655
- paramType: ParamTypes.$CTX,
3656
- dataPath: "$ctx.data"
3657
- });
3658
- }
3659
-
3660
3525
  function getParamType$1(target, propertyKey, parameterIndex) {
3661
3526
  const type = Metadata.getOwnParamTypes(target, propertyKey)[parameterIndex];
3662
3527
 
@@ -3783,23 +3648,6 @@ function Err() {
3783
3648
  });
3784
3649
  }
3785
3650
 
3786
- /**
3787
- * Get the current endpoint metadata.
3788
- * @decorator
3789
- * @operation
3790
- * @input
3791
- * @deprecated Use `@Context() $ctx: Context` then `$ctx.endpoint` instead.
3792
- */
3793
-
3794
- function EndpointInfo() {
3795
- return UseParam({
3796
- paramType: ParamTypes.$CTX,
3797
- dataPath: "$ctx.endpoint",
3798
- useConverter: false,
3799
- useValidation: false
3800
- });
3801
- }
3802
-
3803
3651
  const _excluded = ["use", "collection"];
3804
3652
 
3805
3653
  /**
@@ -3923,15 +3771,90 @@ class PlatformTest extends DITest {
3923
3771
  return (_DITest$injector$get = DITest.injector.get(PlatformApplication)) == null ? void 0 : _DITest$injector$get.callback();
3924
3772
  }
3925
3773
 
3774
+ static createRequest(options = {}) {
3775
+ return _extends({
3776
+ headers: {},
3777
+
3778
+ get(key) {
3779
+ return this.headers[key.toLowerCase()];
3780
+ },
3781
+
3782
+ accepts(mime) {
3783
+ return require("accepts")(this).types([].concat(mime));
3784
+ }
3785
+
3786
+ }, options);
3787
+ }
3788
+
3789
+ static createResponse(options = {}) {
3790
+ return _extends({
3791
+ headers: {},
3792
+ locals: {},
3793
+ statusCode: 200,
3794
+
3795
+ status(code) {
3796
+ this.statusCode = code;
3797
+ return this;
3798
+ },
3799
+
3800
+ contentType(content) {
3801
+ this.set("content-type", content);
3802
+ },
3803
+
3804
+ contentLength(content) {
3805
+ this.set("content-length", content);
3806
+ },
3807
+
3808
+ redirect(status, path) {
3809
+ this.statusCode = status;
3810
+ this.set("location", path);
3811
+ },
3812
+
3813
+ location(path) {
3814
+ this.set("location", path);
3815
+ },
3816
+
3817
+ get(key) {
3818
+ return this.headers[key.toLowerCase()];
3819
+ },
3820
+
3821
+ getHeaders() {
3822
+ return this.headers;
3823
+ },
3824
+
3825
+ set(key, value) {
3826
+ this.headers[key.toLowerCase()] = value;
3827
+ return this;
3828
+ },
3829
+
3830
+ send(data) {
3831
+ this.data = data;
3832
+ },
3833
+
3834
+ json(data) {
3835
+ this.data = data;
3836
+ }
3837
+
3838
+ }, options);
3839
+ }
3840
+
3926
3841
  static createRequestContext(options = {}) {
3927
- options.request = options.request || new PlatformRequest({});
3928
- options.response = options.response || new PlatformResponse({});
3929
- return new PlatformContext(_extends({
3842
+ var _options$request, _options$event, _options$response, _options$event2;
3843
+
3844
+ const event = {
3845
+ 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(),
3846
+ 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()
3847
+ };
3848
+ const ctx = new PlatformContext(_extends({
3930
3849
  id: "id",
3931
3850
  injector: DITest.injector,
3932
3851
  logger: DITest.injector.logger,
3933
3852
  url: "/"
3934
- }, options));
3853
+ }, options, {
3854
+ event
3855
+ }));
3856
+ ctx.response.platformViews = PlatformTest.get(PlatformViews);
3857
+ return ctx;
3935
3858
  }
3936
3859
 
3937
3860
  }
@@ -3943,5 +3866,5 @@ GlobalProviders.createRegistry(ProviderType.CONTROLLER, ControllerProvider, {
3943
3866
 
3944
3867
  });
3945
3868
 
3946
- export { AcceptMime, AcceptMimesMiddleware, All, AnyToPromiseWithCtx, Controller, ControllerProvider, ConverterService, Delete, EndpointFn, EndpointInfo, EndpointMetadata, Err, Get, GlobalAcceptMimesMiddleware, HandlerMetadata, HandlerType, Head, HttpServer, HttpsServer, Location, MulterFileSize, MulterOptions, MultipartFile, Next, Options, PLATFORM_ROUTER_OPTIONS, Patch, Platform, PlatformAcceptMimesMiddleware, PlatformApplication, PlatformBuilder, PlatformConfiguration, PlatformContext, PlatformControllerBuilder, PlatformHandler, PlatformLogMiddleware, PlatformModule, PlatformMulterMiddleware, PlatformRequest, PlatformResponse, PlatformRouteDetails, PlatformRouter, PlatformTest, Post, PropertyMetadata, Put, ROUTER_OPTIONS, Redirect, Req, Request, Res, Response, ResponseData, bindEndpointMiddleware, createContext, createHttpServer, createHttpsServer, createInjector, createPlatformApplication, listenHttpServer, listenHttpsServer, listenServer, loadInjector, mapReturnedResponse, printRoutes, useCtxHandler };
3869
+ export { AcceptMime, All, AnyToPromiseWithCtx, Controller, ControllerProvider, ConverterService, Delete, EndpointFn, EndpointMetadata, Err, Get, HandlerMetadata, HandlerType, Head, HttpServer, HttpsServer, MulterFileSize, MulterOptions, MultipartFile, Next, Options, PLATFORM_ROUTER_OPTIONS, Patch, Platform, PlatformAcceptMimesMiddleware, PlatformApplication, PlatformBuilder, PlatformConfiguration, PlatformContext, PlatformControllerBuilder, PlatformHandler, PlatformLogMiddleware, PlatformModule, PlatformMulterMiddleware, PlatformRequest, PlatformResponse, PlatformRouteDetails, PlatformRouter, PlatformTest, Post, Put, ROUTER_OPTIONS, Req, Request, Res, Response, bindEndpointMiddleware, createContext, createHttpServer, createHttpsServer, createInjector, createPlatformApplication, listenHttpServer, listenHttpsServer, listenServer, mapReturnedResponse, printRoutes, useCtxHandler };
3947
3870
  //# sourceMappingURL=index.modern.js.map