@tsed/common 6.87.2 → 6.88.0
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/decorators/index.d.ts +1 -0
- package/lib/decorators/method/view.d.ts +25 -0
- package/lib/index.d.ts +0 -1
- package/lib/index.js +54 -23
- package/lib/index.js.map +1 -1
- package/lib/index.modern.js +54 -17
- package/lib/index.modern.js.map +1 -1
- package/lib/services/PlatformRequest.d.ts +2 -1
- package/lib/services/PlatformResponse.d.ts +4 -4
- package/package.json +15 -15
|
@@ -6,6 +6,7 @@ export * from "./method/acceptMime";
|
|
|
6
6
|
export * from "./method/location";
|
|
7
7
|
export * from "./method/redirect";
|
|
8
8
|
export * from "./method/endpointFn";
|
|
9
|
+
export * from "./method/view";
|
|
9
10
|
export * from "./params/responseData";
|
|
10
11
|
export * from "./params/response";
|
|
11
12
|
export * from "./params/request";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Use a view and sends the rendered HTML string to the client. Optional parameter:
|
|
3
|
+
*
|
|
4
|
+
* * viewOptions, an object whose properties define local variables for the view.
|
|
5
|
+
*
|
|
6
|
+
* The view argument is a string that is the file path of the view file to render.
|
|
7
|
+
* This can be an absolute path, or a path relative to the views setting.
|
|
8
|
+
* If the path does not contain a file extension, then the view engine setting determines the file extension.
|
|
9
|
+
* If the path does contain a file extension, then Express will load the module for the specified template engine (via require())
|
|
10
|
+
* and render it using the loaded module’s __express function.
|
|
11
|
+
*
|
|
12
|
+
* For more information, see [Using template engines with Express](http://expressjs.com/guide/using-template-engines.html).
|
|
13
|
+
*
|
|
14
|
+
* > NOTE: The view argument performs file system operations like reading a file from disk and evaluating Node.js modules,
|
|
15
|
+
* and as so for security reasons should not contain input from the end-user.
|
|
16
|
+
*
|
|
17
|
+
* @param path Relative path to the view file.
|
|
18
|
+
* @param options Additional options
|
|
19
|
+
* @decorator
|
|
20
|
+
* @operation
|
|
21
|
+
* @response
|
|
22
|
+
* @ignores
|
|
23
|
+
* @deprecated Use View decorator from @tsed/platform-views instead.
|
|
24
|
+
*/
|
|
25
|
+
export declare function View(path: string, options?: Object): MethodDecorator;
|
package/lib/index.d.ts
CHANGED
|
@@ -6,7 +6,6 @@ export * from "@tsed/platform-exceptions";
|
|
|
6
6
|
export * from "@tsed/platform-response-filter";
|
|
7
7
|
export * from "@tsed/platform-cache";
|
|
8
8
|
export * from "@tsed/platform-middlewares";
|
|
9
|
-
export * from "@tsed/platform-views";
|
|
10
9
|
export * from "@tsed/components-scan";
|
|
11
10
|
export * from "@tsed/platform-log-middleware";
|
|
12
11
|
export { $log, Logger } from "@tsed/logger";
|
package/lib/index.js
CHANGED
|
@@ -6,7 +6,6 @@ var platformExceptions = require('@tsed/platform-exceptions');
|
|
|
6
6
|
var platformResponseFilter = require('@tsed/platform-response-filter');
|
|
7
7
|
var platformCache = require('@tsed/platform-cache');
|
|
8
8
|
var platformMiddlewares = require('@tsed/platform-middlewares');
|
|
9
|
-
var platformViews = require('@tsed/platform-views');
|
|
10
9
|
var componentsScan = require('@tsed/components-scan');
|
|
11
10
|
var platformLogMiddleware = require('@tsed/platform-log-middleware');
|
|
12
11
|
var tslib = require('tslib');
|
|
@@ -1489,7 +1488,8 @@ function buildRouter(injector, provider) {
|
|
|
1489
1488
|
exports.PlatformRequest = class PlatformRequest {
|
|
1490
1489
|
constructor({
|
|
1491
1490
|
request
|
|
1492
|
-
}) {
|
|
1491
|
+
}, $ctx) {
|
|
1492
|
+
this.$ctx = $ctx;
|
|
1493
1493
|
this.raw = request;
|
|
1494
1494
|
}
|
|
1495
1495
|
|
|
@@ -1620,7 +1620,9 @@ exports.PlatformRequest = class PlatformRequest {
|
|
|
1620
1620
|
// @ts-ignore
|
|
1621
1621
|
delete this.raw; // @ts-ignore
|
|
1622
1622
|
|
|
1623
|
-
delete this.response;
|
|
1623
|
+
delete this.response; // @ts-ignore
|
|
1624
|
+
|
|
1625
|
+
delete this.$ctx;
|
|
1624
1626
|
}
|
|
1625
1627
|
/**
|
|
1626
1628
|
* Return the Framework response object (express, koa, etc...)
|
|
@@ -1640,7 +1642,7 @@ exports.PlatformRequest = class PlatformRequest {
|
|
|
1640
1642
|
}
|
|
1641
1643
|
|
|
1642
1644
|
};
|
|
1643
|
-
exports.PlatformRequest = tslib.__decorate([di.Injectable(), di.Scope(di.ProviderScope.INSTANCE), tslib.__metadata("design:paramtypes", [Object])], exports.PlatformRequest);
|
|
1645
|
+
exports.PlatformRequest = tslib.__decorate([di.Injectable(), di.Scope(di.ProviderScope.INSTANCE), tslib.__metadata("design:paramtypes", [Object, Function])], exports.PlatformRequest);
|
|
1644
1646
|
|
|
1645
1647
|
var PlatformResponse_1;
|
|
1646
1648
|
|
|
@@ -1654,7 +1656,8 @@ const onFinished = require("on-finished");
|
|
|
1654
1656
|
exports.PlatformResponse = PlatformResponse_1 = class PlatformResponse {
|
|
1655
1657
|
constructor({
|
|
1656
1658
|
response
|
|
1657
|
-
}) {
|
|
1659
|
+
}, $ctx) {
|
|
1660
|
+
this.$ctx = $ctx;
|
|
1658
1661
|
this.raw = response;
|
|
1659
1662
|
}
|
|
1660
1663
|
/**
|
|
@@ -1871,7 +1874,11 @@ exports.PlatformResponse = PlatformResponse_1 = class PlatformResponse {
|
|
|
1871
1874
|
|
|
1872
1875
|
|
|
1873
1876
|
async render(path, options = {}) {
|
|
1874
|
-
|
|
1877
|
+
const {
|
|
1878
|
+
PlatformViews
|
|
1879
|
+
} = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@tsed/platform-views')); });
|
|
1880
|
+
const platformViews = await this.$ctx.injector.lazyInvoke(PlatformViews);
|
|
1881
|
+
return platformViews.render(path, _extends({}, this.locals, options));
|
|
1875
1882
|
}
|
|
1876
1883
|
/**
|
|
1877
1884
|
* Send any data to your consumer.
|
|
@@ -1943,7 +1950,9 @@ exports.PlatformResponse = PlatformResponse_1 = class PlatformResponse {
|
|
|
1943
1950
|
delete this.raw;
|
|
1944
1951
|
delete this.data; // @ts-ignore
|
|
1945
1952
|
|
|
1946
|
-
delete this.request;
|
|
1953
|
+
delete this.request; // @ts-ignore
|
|
1954
|
+
|
|
1955
|
+
delete this.$ctx;
|
|
1947
1956
|
}
|
|
1948
1957
|
|
|
1949
1958
|
isHeadersSent() {
|
|
@@ -1951,7 +1960,7 @@ exports.PlatformResponse = PlatformResponse_1 = class PlatformResponse {
|
|
|
1951
1960
|
}
|
|
1952
1961
|
|
|
1953
1962
|
};
|
|
1954
|
-
exports.PlatformResponse = PlatformResponse_1 = tslib.__decorate([di.Injectable(), di.Scope(di.ProviderScope.INSTANCE), tslib.__metadata("design:paramtypes", [Object])], exports.PlatformResponse);
|
|
1963
|
+
exports.PlatformResponse = PlatformResponse_1 = tslib.__decorate([di.Injectable(), di.Scope(di.ProviderScope.INSTANCE), tslib.__metadata("design:paramtypes", [Object, Function])], exports.PlatformResponse);
|
|
1955
1964
|
|
|
1956
1965
|
const _excluded$2 = ["event", "endpoint", "ignoreUrlPatterns", "ResponseKlass", "RequestKlass"];
|
|
1957
1966
|
class PlatformContext extends di.DIContext {
|
|
@@ -1973,8 +1982,8 @@ class PlatformContext extends di.DIContext {
|
|
|
1973
1982
|
this.ignoreUrlPatterns = [];
|
|
1974
1983
|
endpoint && (this.endpoint = endpoint);
|
|
1975
1984
|
this.ignoreUrlPatterns = ignoreUrlPatterns.map(pattern => typeof pattern === "string" ? new RegExp(pattern, "gi") : pattern);
|
|
1976
|
-
this.response = new ResponseKlass(event);
|
|
1977
|
-
this.request = new RequestKlass(event);
|
|
1985
|
+
this.response = new ResponseKlass(event, this);
|
|
1986
|
+
this.request = new RequestKlass(event, this);
|
|
1978
1987
|
this.response.request = this.request;
|
|
1979
1988
|
this.request.response = this.response;
|
|
1980
1989
|
this.request.request.$ctx = this;
|
|
@@ -2451,7 +2460,6 @@ function createContext(injector) {
|
|
|
2451
2460
|
|
|
2452
2461
|
const ResponseKlass = (_injector$getProvider = injector.getProvider(exports.PlatformResponse)) == null ? void 0 : _injector$getProvider.useClass;
|
|
2453
2462
|
const RequestKlass = (_injector$getProvider2 = injector.getProvider(exports.PlatformRequest)) == null ? void 0 : _injector$getProvider2.useClass;
|
|
2454
|
-
const platformViews$1 = injector.get(platformViews.PlatformViews);
|
|
2455
2463
|
|
|
2456
2464
|
const _ref = injector.settings.logger || {},
|
|
2457
2465
|
{
|
|
@@ -2469,7 +2477,6 @@ function createContext(injector) {
|
|
|
2469
2477
|
ResponseKlass,
|
|
2470
2478
|
RequestKlass
|
|
2471
2479
|
}));
|
|
2472
|
-
ctx.response.platformViews = platformViews$1;
|
|
2473
2480
|
ctx.response.onEnd(async () => {
|
|
2474
2481
|
await ctx.emit("$onResponse", ctx);
|
|
2475
2482
|
await ctx.destroy();
|
|
@@ -3036,6 +3043,39 @@ function EndpointFn(fn) {
|
|
|
3036
3043
|
return schema.JsonEntityFn(fn);
|
|
3037
3044
|
}
|
|
3038
3045
|
|
|
3046
|
+
/**
|
|
3047
|
+
* Use a view and sends the rendered HTML string to the client. Optional parameter:
|
|
3048
|
+
*
|
|
3049
|
+
* * viewOptions, an object whose properties define local variables for the view.
|
|
3050
|
+
*
|
|
3051
|
+
* The view argument is a string that is the file path of the view file to render.
|
|
3052
|
+
* This can be an absolute path, or a path relative to the views setting.
|
|
3053
|
+
* If the path does not contain a file extension, then the view engine setting determines the file extension.
|
|
3054
|
+
* If the path does contain a file extension, then Express will load the module for the specified template engine (via require())
|
|
3055
|
+
* and render it using the loaded module’s __express function.
|
|
3056
|
+
*
|
|
3057
|
+
* For more information, see [Using template engines with Express](http://expressjs.com/guide/using-template-engines.html).
|
|
3058
|
+
*
|
|
3059
|
+
* > NOTE: The view argument performs file system operations like reading a file from disk and evaluating Node.js modules,
|
|
3060
|
+
* and as so for security reasons should not contain input from the end-user.
|
|
3061
|
+
*
|
|
3062
|
+
* @param path Relative path to the view file.
|
|
3063
|
+
* @param options Additional options
|
|
3064
|
+
* @decorator
|
|
3065
|
+
* @operation
|
|
3066
|
+
* @response
|
|
3067
|
+
* @ignores
|
|
3068
|
+
* @deprecated Use View decorator from @tsed/platform-views instead.
|
|
3069
|
+
*/
|
|
3070
|
+
// istanbul ignore next
|
|
3071
|
+
|
|
3072
|
+
function View(path, options) {
|
|
3073
|
+
return core.StoreSet("view", {
|
|
3074
|
+
path,
|
|
3075
|
+
options
|
|
3076
|
+
});
|
|
3077
|
+
}
|
|
3078
|
+
|
|
3039
3079
|
/**
|
|
3040
3080
|
* Return the current response data. Prefer the @@Context@@ decorator to get or set data.
|
|
3041
3081
|
*
|
|
@@ -3396,7 +3436,7 @@ class PlatformTest extends di.DITest {
|
|
|
3396
3436
|
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(),
|
|
3397
3437
|
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()
|
|
3398
3438
|
};
|
|
3399
|
-
|
|
3439
|
+
return new PlatformContext(_extends({
|
|
3400
3440
|
id: "id",
|
|
3401
3441
|
injector: di.DITest.injector,
|
|
3402
3442
|
logger: di.DITest.injector.logger,
|
|
@@ -3404,8 +3444,6 @@ class PlatformTest extends di.DITest {
|
|
|
3404
3444
|
}, options, {
|
|
3405
3445
|
event
|
|
3406
3446
|
}));
|
|
3407
|
-
ctx.response.platformViews = PlatformTest.get(platformViews.PlatformViews);
|
|
3408
|
-
return ctx;
|
|
3409
3447
|
}
|
|
3410
3448
|
|
|
3411
3449
|
}
|
|
@@ -3513,6 +3551,7 @@ exports.Request = Request;
|
|
|
3513
3551
|
exports.Res = Res;
|
|
3514
3552
|
exports.Response = Response;
|
|
3515
3553
|
exports.ResponseData = ResponseData;
|
|
3554
|
+
exports.View = View;
|
|
3516
3555
|
exports.bindEndpointMiddleware = bindEndpointMiddleware;
|
|
3517
3556
|
exports.buildRouter = buildRouter;
|
|
3518
3557
|
exports.createContext = createContext;
|
|
@@ -3576,14 +3615,6 @@ Object.keys(platformMiddlewares).forEach(function (k) {
|
|
|
3576
3615
|
}
|
|
3577
3616
|
});
|
|
3578
3617
|
});
|
|
3579
|
-
Object.keys(platformViews).forEach(function (k) {
|
|
3580
|
-
if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
|
|
3581
|
-
enumerable: true,
|
|
3582
|
-
get: function () {
|
|
3583
|
-
return platformViews[k];
|
|
3584
|
-
}
|
|
3585
|
-
});
|
|
3586
|
-
});
|
|
3587
3618
|
Object.keys(componentsScan).forEach(function (k) {
|
|
3588
3619
|
if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
|
|
3589
3620
|
enumerable: true,
|