@moostjs/event-http 0.6.48 → 0.6.49
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/dist/index.cjs +48 -1
- package/dist/index.d.ts +40 -3
- package/dist/index.mjs +43 -3
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -528,6 +528,46 @@ const setStatusInterceptor = (code, opts) => ({
|
|
|
528
528
|
* @param n - Timeout duration in milliseconds.
|
|
529
529
|
*/ const BodyReadTimeoutMs = (n) => (0, moost.Intercept)(globalBodyReadTimeoutMs(n));
|
|
530
530
|
|
|
531
|
+
//#endregion
|
|
532
|
+
//#region packages/event-http/src/decorators/compress.decorator.ts
|
|
533
|
+
/**
|
|
534
|
+
* Overrides response compression for a handler or a whole controller.
|
|
535
|
+
*
|
|
536
|
+
* Calls `useResponse().setCompression(value)` before guards, argument resolution and the
|
|
537
|
+
* handler run, so the override also applies to error responses (401, 400, …).
|
|
538
|
+
* A method-level `@Compress` wins over a class-level one.
|
|
539
|
+
*
|
|
540
|
+
* - `true` (default) — compress with the app settings (`new MoostHttp({ compression })`),
|
|
541
|
+
* or the defaults when the app has compression off.
|
|
542
|
+
* - `false` — never compress this response (e.g. a body that mixes a secret with
|
|
543
|
+
* reflected input — see BREACH).
|
|
544
|
+
* - options object — compress with these settings layered over the app settings.
|
|
545
|
+
*
|
|
546
|
+
* ```ts
|
|
547
|
+
* import { Compress, Get } from '@moostjs/event-http'
|
|
548
|
+
* import { Controller } from 'moost'
|
|
549
|
+
*
|
|
550
|
+
* @Controller()
|
|
551
|
+
* export class ReportsController {
|
|
552
|
+
* @Get('report')
|
|
553
|
+
* @Compress({ brotliQuality: 6 })
|
|
554
|
+
* report() {
|
|
555
|
+
* return buildReport()
|
|
556
|
+
* }
|
|
557
|
+
*
|
|
558
|
+
* @Get('session')
|
|
559
|
+
* @Compress(false)
|
|
560
|
+
* session() {
|
|
561
|
+
* return { token, echo: query }
|
|
562
|
+
* }
|
|
563
|
+
* }
|
|
564
|
+
* ```
|
|
565
|
+
*
|
|
566
|
+
* @param value compression override, defaults to `true`
|
|
567
|
+
*/ const Compress = (value = true) => (0, moost.Intercept)((0, moost.defineBeforeInterceptor)(() => {
|
|
568
|
+
(0, _wooksjs_event_http.useResponse)().setCompression(value);
|
|
569
|
+
}, moost.TInterceptorPriority.BEFORE_ALL));
|
|
570
|
+
|
|
531
571
|
//#endregion
|
|
532
572
|
//#region packages/event-http/src/event-http.ts
|
|
533
573
|
function _define_property(obj, key, value) {
|
|
@@ -754,7 +794,7 @@ const LOGGER_TITLE = "moost-http";
|
|
|
754
794
|
image: "https://moost.org/moost-full-logo.svg",
|
|
755
795
|
link: "https://moost.org/",
|
|
756
796
|
poweredBy: "moostjs",
|
|
757
|
-
version: "0.6.
|
|
797
|
+
version: "0.6.49"
|
|
758
798
|
});
|
|
759
799
|
if (httpApp && httpApp instanceof _wooksjs_event_http.WooksHttp) this.httpApp = httpApp;
|
|
760
800
|
else if (httpApp) this.httpApp = (0, _wooksjs_event_http.createHttpApp)({
|
|
@@ -817,6 +857,7 @@ exports.Authorization = Authorization;
|
|
|
817
857
|
exports.Body = Body;
|
|
818
858
|
exports.BodyReadTimeoutMs = BodyReadTimeoutMs;
|
|
819
859
|
exports.BodySizeLimit = BodySizeLimit;
|
|
860
|
+
exports.Compress = Compress;
|
|
820
861
|
exports.CompressedBodySizeLimit = CompressedBodySizeLimit;
|
|
821
862
|
exports.Cookie = Cookie;
|
|
822
863
|
exports.CookieAttrsRef = CookieAttrsRef;
|
|
@@ -862,6 +903,12 @@ Object.defineProperty(exports, 'httpKind', {
|
|
|
862
903
|
return _wooksjs_event_http.httpKind;
|
|
863
904
|
}
|
|
864
905
|
});
|
|
906
|
+
Object.defineProperty(exports, 'isCompressibleType', {
|
|
907
|
+
enumerable: true,
|
|
908
|
+
get: function () {
|
|
909
|
+
return _wooksjs_event_http.isCompressibleType;
|
|
910
|
+
}
|
|
911
|
+
});
|
|
865
912
|
Object.defineProperty(exports, 'prerenderJson', {
|
|
866
913
|
enumerable: true,
|
|
867
914
|
get: function () {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as moost from 'moost';
|
|
2
2
|
import { TInterceptorPriority, TOvertakeFn, TInterceptorDef, TClassConstructor, TMoostAdapter, MOOST_ADAPTER_BRAND, TIsolatedSlot, EventContext, Moost, TConsoleBase, TMoostAdapterOptions } from 'moost';
|
|
3
3
|
import * as _wooksjs_event_http from '@wooksjs/event-http';
|
|
4
|
-
import { TCookieAttributes as TCookieAttributes$1, TCookieAttributesInput, WooksHttp, TWooksHttpOptions } from '@wooksjs/event-http';
|
|
5
|
-
export { HttpError, TCacheControl, TCookieAttributesInput, TPrerenderJsonOptions, TSetCookieData, httpKind, prerenderJson, useHttpContext } from '@wooksjs/event-http';
|
|
4
|
+
import { TCookieAttributes as TCookieAttributes$1, TCookieAttributesInput, THttpCompressionOptions, WooksHttp, TWooksHttpOptions } from '@wooksjs/event-http';
|
|
5
|
+
export { HttpError, TCacheControl, TCookieAttributesInput, THttpCompressionEncoding, THttpCompressionOptions, TPrerenderJsonOptions, TSetCookieData, httpKind, isCompressibleType, prerenderJson, useHttpContext } from '@wooksjs/event-http';
|
|
6
6
|
import { IncomingMessage, ServerResponse } from 'http';
|
|
7
7
|
import { Buffer } from 'buffer';
|
|
8
8
|
import { ListenOptions } from 'net';
|
|
@@ -366,6 +366,43 @@ declare const CompressedBodySizeLimit: (n: number) => ClassDecorator & MethodDec
|
|
|
366
366
|
*/
|
|
367
367
|
declare const BodyReadTimeoutMs: (n: number) => ClassDecorator & MethodDecorator;
|
|
368
368
|
|
|
369
|
+
/**
|
|
370
|
+
* Overrides response compression for a handler or a whole controller.
|
|
371
|
+
*
|
|
372
|
+
* Calls `useResponse().setCompression(value)` before guards, argument resolution and the
|
|
373
|
+
* handler run, so the override also applies to error responses (401, 400, …).
|
|
374
|
+
* A method-level `@Compress` wins over a class-level one.
|
|
375
|
+
*
|
|
376
|
+
* - `true` (default) — compress with the app settings (`new MoostHttp({ compression })`),
|
|
377
|
+
* or the defaults when the app has compression off.
|
|
378
|
+
* - `false` — never compress this response (e.g. a body that mixes a secret with
|
|
379
|
+
* reflected input — see BREACH).
|
|
380
|
+
* - options object — compress with these settings layered over the app settings.
|
|
381
|
+
*
|
|
382
|
+
* ```ts
|
|
383
|
+
* import { Compress, Get } from '@moostjs/event-http'
|
|
384
|
+
* import { Controller } from 'moost'
|
|
385
|
+
*
|
|
386
|
+
* @Controller()
|
|
387
|
+
* export class ReportsController {
|
|
388
|
+
* @Get('report')
|
|
389
|
+
* @Compress({ brotliQuality: 6 })
|
|
390
|
+
* report() {
|
|
391
|
+
* return buildReport()
|
|
392
|
+
* }
|
|
393
|
+
*
|
|
394
|
+
* @Get('session')
|
|
395
|
+
* @Compress(false)
|
|
396
|
+
* session() {
|
|
397
|
+
* return { token, echo: query }
|
|
398
|
+
* }
|
|
399
|
+
* }
|
|
400
|
+
* ```
|
|
401
|
+
*
|
|
402
|
+
* @param value compression override, defaults to `true`
|
|
403
|
+
*/
|
|
404
|
+
declare const Compress: (value?: boolean | THttpCompressionOptions) => ClassDecorator & MethodDecorator;
|
|
405
|
+
|
|
369
406
|
type TPathBuilder<ParamsType = Record<string, string | string[]>> = (params?: ParamsType) => string;
|
|
370
407
|
/** Handler metadata for HTTP events, carrying the HTTP method and route path. */
|
|
371
408
|
interface THttpHandlerMeta {
|
|
@@ -526,5 +563,5 @@ declare class MoostHttp implements TMoostAdapter<THttpHandlerMeta> {
|
|
|
526
563
|
*/
|
|
527
564
|
declare function enableLocalFetch(http: MoostHttp): () => void;
|
|
528
565
|
|
|
529
|
-
export { All, AuthGuard, Authenticate, Authorization, Body, BodyReadTimeoutMs, BodySizeLimit, CompressedBodySizeLimit, Cookie, CookieAttrsRef, CookieRef, Delete, Get, Header, HeaderRef, HttpMethod, Ip, IpList, Method, MoostHttp, Patch, Post, Put, Query, RawBody, Req, ReqId, Res, SetCookie, SetHeader, SetStatus, StatusRef, Upgrade, Url, defineAuthGuard, enableLocalFetch, extractTransports, globalBodyReadTimeoutMs, globalBodySizeLimit, globalCompressedBodySizeLimit };
|
|
566
|
+
export { All, AuthGuard, Authenticate, Authorization, Body, BodyReadTimeoutMs, BodySizeLimit, Compress, CompressedBodySizeLimit, Cookie, CookieAttrsRef, CookieRef, Delete, Get, Header, HeaderRef, HttpMethod, Ip, IpList, Method, MoostHttp, Patch, Post, Put, Query, RawBody, Req, ReqId, Res, SetCookie, SetHeader, SetStatus, StatusRef, Upgrade, Url, defineAuthGuard, enableLocalFetch, extractTransports, globalBodyReadTimeoutMs, globalBodySizeLimit, globalCompressedBodySizeLimit };
|
|
530
567
|
export type { TAuthGuardClass, TAuthGuardDef, TAuthGuardHandler, TAuthTransportApiKey, TAuthTransportBasic, TAuthTransportBearer, TAuthTransportCookie, TAuthTransportDeclaration, TAuthTransportValues, TCookieAttributes, TCookieRef, THeaderRef, THttpHandlerMeta, TMoostHttpInvokeOptions, TStatusRef };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { current } from "@wooksjs/event-core";
|
|
2
|
-
import { HttpError, HttpError as HttpError$1, WooksHttp, WooksHttpResponse, createHttpApp, httpKind, httpKind as httpKind$1, prerenderJson, useAuthorization, useCookies, useHeaders, useHttpContext, useRequest, useResponse, useUrlParams } from "@wooksjs/event-http";
|
|
2
|
+
import { HttpError, HttpError as HttpError$1, WooksHttp, WooksHttpResponse, createHttpApp, httpKind, httpKind as httpKind$1, isCompressibleType, prerenderJson, useAuthorization, useCookies, useHeaders, useHttpContext, useRequest, useResponse, useUrlParams } from "@wooksjs/event-http";
|
|
3
3
|
import { Before, Intercept, Interceptor, MOOST_ADAPTER_BRAND, Overtake, Resolve, TInterceptorPriority, current as current$1, defineBeforeInterceptor, defineMoostEventHandler, forkEventContext, getMoostMate, globalKey, run } from "moost";
|
|
4
4
|
import { seedBody, useBody } from "@wooksjs/http-body";
|
|
5
5
|
import { createProvideRegistry } from "@prostojs/infact";
|
|
@@ -527,6 +527,46 @@ const setStatusInterceptor = (code, opts) => ({
|
|
|
527
527
|
* @param n - Timeout duration in milliseconds.
|
|
528
528
|
*/ const BodyReadTimeoutMs = (n) => Intercept(globalBodyReadTimeoutMs(n));
|
|
529
529
|
|
|
530
|
+
//#endregion
|
|
531
|
+
//#region packages/event-http/src/decorators/compress.decorator.ts
|
|
532
|
+
/**
|
|
533
|
+
* Overrides response compression for a handler or a whole controller.
|
|
534
|
+
*
|
|
535
|
+
* Calls `useResponse().setCompression(value)` before guards, argument resolution and the
|
|
536
|
+
* handler run, so the override also applies to error responses (401, 400, …).
|
|
537
|
+
* A method-level `@Compress` wins over a class-level one.
|
|
538
|
+
*
|
|
539
|
+
* - `true` (default) — compress with the app settings (`new MoostHttp({ compression })`),
|
|
540
|
+
* or the defaults when the app has compression off.
|
|
541
|
+
* - `false` — never compress this response (e.g. a body that mixes a secret with
|
|
542
|
+
* reflected input — see BREACH).
|
|
543
|
+
* - options object — compress with these settings layered over the app settings.
|
|
544
|
+
*
|
|
545
|
+
* ```ts
|
|
546
|
+
* import { Compress, Get } from '@moostjs/event-http'
|
|
547
|
+
* import { Controller } from 'moost'
|
|
548
|
+
*
|
|
549
|
+
* @Controller()
|
|
550
|
+
* export class ReportsController {
|
|
551
|
+
* @Get('report')
|
|
552
|
+
* @Compress({ brotliQuality: 6 })
|
|
553
|
+
* report() {
|
|
554
|
+
* return buildReport()
|
|
555
|
+
* }
|
|
556
|
+
*
|
|
557
|
+
* @Get('session')
|
|
558
|
+
* @Compress(false)
|
|
559
|
+
* session() {
|
|
560
|
+
* return { token, echo: query }
|
|
561
|
+
* }
|
|
562
|
+
* }
|
|
563
|
+
* ```
|
|
564
|
+
*
|
|
565
|
+
* @param value compression override, defaults to `true`
|
|
566
|
+
*/ const Compress = (value = true) => Intercept(defineBeforeInterceptor(() => {
|
|
567
|
+
useResponse().setCompression(value);
|
|
568
|
+
}, TInterceptorPriority.BEFORE_ALL));
|
|
569
|
+
|
|
530
570
|
//#endregion
|
|
531
571
|
//#region packages/event-http/src/event-http.ts
|
|
532
572
|
function _define_property(obj, key, value) {
|
|
@@ -753,7 +793,7 @@ const LOGGER_TITLE = "moost-http";
|
|
|
753
793
|
image: "https://moost.org/moost-full-logo.svg",
|
|
754
794
|
link: "https://moost.org/",
|
|
755
795
|
poweredBy: "moostjs",
|
|
756
|
-
version: "0.6.
|
|
796
|
+
version: "0.6.49"
|
|
757
797
|
});
|
|
758
798
|
if (httpApp && httpApp instanceof WooksHttp) this.httpApp = httpApp;
|
|
759
799
|
else if (httpApp) this.httpApp = createHttpApp({
|
|
@@ -804,4 +844,4 @@ function isLocalOrigin(url) {
|
|
|
804
844
|
}
|
|
805
845
|
|
|
806
846
|
//#endregion
|
|
807
|
-
export { All, AuthGuard, Authenticate, Authorization, Body, BodyReadTimeoutMs, BodySizeLimit, CompressedBodySizeLimit, Cookie, CookieAttrsRef, CookieRef, Delete, Get, Header, HeaderRef, HttpError, HttpMethod, Ip, IpList, Method, MoostHttp, Patch, Post, Put, Query, RawBody, Req, ReqId, Res, SetCookie, SetHeader, SetStatus, StatusRef, Upgrade, Url, defineAuthGuard, enableLocalFetch, extractTransports, globalBodyReadTimeoutMs, globalBodySizeLimit, globalCompressedBodySizeLimit, httpKind, prerenderJson, useHttpContext };
|
|
847
|
+
export { All, AuthGuard, Authenticate, Authorization, Body, BodyReadTimeoutMs, BodySizeLimit, Compress, CompressedBodySizeLimit, Cookie, CookieAttrsRef, CookieRef, Delete, Get, Header, HeaderRef, HttpError, HttpMethod, Ip, IpList, Method, MoostHttp, Patch, Post, Put, Query, RawBody, Req, ReqId, Res, SetCookie, SetHeader, SetStatus, StatusRef, Upgrade, Url, defineAuthGuard, enableLocalFetch, extractTransports, globalBodyReadTimeoutMs, globalBodySizeLimit, globalCompressedBodySizeLimit, httpKind, isCompressibleType, prerenderJson, useHttpContext };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moostjs/event-http",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.49",
|
|
4
4
|
"description": "@moostjs/event-http",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"composables",
|
|
@@ -38,16 +38,16 @@
|
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@wooksjs/event-http": "^0.7.
|
|
42
|
-
"@wooksjs/http-body": "^0.7.
|
|
41
|
+
"@wooksjs/event-http": "^0.7.28",
|
|
42
|
+
"@wooksjs/http-body": "^0.7.28"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"vitest": "3.2.7"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"@prostojs/infact": "^0.6.1",
|
|
49
|
-
"@wooksjs/event-core": "^0.7.
|
|
50
|
-
"moost": "^0.6.
|
|
49
|
+
"@wooksjs/event-core": "^0.7.28",
|
|
50
|
+
"moost": "^0.6.49"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
53
|
"pub": "pnpm publish --access public",
|