@moostjs/event-http 0.6.41 → 0.6.42
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 +16 -12
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +16 -12
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -540,6 +540,11 @@ function _define_property(obj, key, value) {
|
|
|
540
540
|
else obj[key] = value;
|
|
541
541
|
return obj;
|
|
542
542
|
}
|
|
543
|
+
const holdScopeUntilResponseCloses = { init: ({ unscope }) => {
|
|
544
|
+
const res = (0, _wooksjs_event_http.useResponse)().getRawRes(true);
|
|
545
|
+
if (res.closed) unscope();
|
|
546
|
+
else res.once("close", unscope);
|
|
547
|
+
} };
|
|
543
548
|
const LOGGER_TITLE = "moost-http";
|
|
544
549
|
/**
|
|
545
550
|
* ## Moost HTTP Adapter
|
|
@@ -604,14 +609,17 @@ const LOGGER_TITLE = "moost-http";
|
|
|
604
609
|
return this.httpApp.listen(port, hostname, backlog, listeningListener);
|
|
605
610
|
}
|
|
606
611
|
async onNotFound() {
|
|
607
|
-
|
|
612
|
+
this.notFoundHandler ?? (this.notFoundHandler = (0, moost.defineMoostEventHandler)({
|
|
608
613
|
loggerTitle: LOGGER_TITLE,
|
|
609
614
|
getIterceptorHandler: () => this.moost?.getGlobalInterceptorHandler(),
|
|
610
615
|
getControllerInstance: () => this.moost,
|
|
611
616
|
callControllerMethod: () => new _wooksjs_event_http.HttpError(404, "Resource Not Found"),
|
|
617
|
+
manualUnscope: true,
|
|
618
|
+
hooks: holdScopeUntilResponseCloses,
|
|
612
619
|
targetPath: "",
|
|
613
620
|
handlerType: "__SYSTEM__"
|
|
614
|
-
})
|
|
621
|
+
}));
|
|
622
|
+
return this.notFoundHandler();
|
|
615
623
|
}
|
|
616
624
|
onInit(moost$1) {
|
|
617
625
|
this.moost = moost$1;
|
|
@@ -642,6 +650,7 @@ const LOGGER_TITLE = "moost-http";
|
|
|
642
650
|
const httpPath = handler.path;
|
|
643
651
|
const path = typeof httpPath === "string" ? httpPath : typeof opts.method === "string" ? opts.method : "";
|
|
644
652
|
const targetPath = `${`${opts.prefix || ""}/${path}`.replaceAll(/\/\/+/g, "/")}${path.endsWith("//") ? "/" : ""}`;
|
|
653
|
+
const isUpgrade = handler.method === "UPGRADE";
|
|
645
654
|
fn = (0, moost.defineMoostEventHandler)({
|
|
646
655
|
loggerTitle: LOGGER_TITLE,
|
|
647
656
|
getIterceptorHandler: opts.getIterceptorHandler,
|
|
@@ -649,19 +658,13 @@ const LOGGER_TITLE = "moost-http";
|
|
|
649
658
|
controllerMethod: opts.method,
|
|
650
659
|
controllerName: opts.controllerName,
|
|
651
660
|
resolveArgs: opts.resolveArgs,
|
|
652
|
-
manualUnscope:
|
|
653
|
-
hooks:
|
|
654
|
-
if (handler.method === "UPGRADE") {
|
|
655
|
-
(0, _wooksjs_event_http.useRequest)().raw.on("end", unscope);
|
|
656
|
-
return;
|
|
657
|
-
}
|
|
658
|
-
(0, _wooksjs_event_http.useResponse)().getRawRes(true).once("close", unscope);
|
|
659
|
-
} },
|
|
661
|
+
manualUnscope: !isUpgrade,
|
|
662
|
+
hooks: isUpgrade ? void 0 : holdScopeUntilResponseCloses,
|
|
660
663
|
targetPath,
|
|
661
664
|
controllerPrefix: opts.prefix,
|
|
662
665
|
handlerType: handler.type
|
|
663
666
|
});
|
|
664
|
-
const routerBinding =
|
|
667
|
+
const routerBinding = isUpgrade ? this.httpApp.upgrade(targetPath, fn) : this.httpApp.on(handler.method, targetPath, fn);
|
|
665
668
|
const { getPath: pathBuilder } = routerBinding;
|
|
666
669
|
const id = ((0, moost.getMoostMate)().read(opts.fakeInstance, opts.method) || {}).id || opts.method;
|
|
667
670
|
if (id) {
|
|
@@ -686,11 +689,12 @@ const LOGGER_TITLE = "moost-http";
|
|
|
686
689
|
_define_property(this, "httpApp", void 0);
|
|
687
690
|
_define_property(this, "pathBuilders", {});
|
|
688
691
|
_define_property(this, "moost", void 0);
|
|
692
|
+
_define_property(this, "notFoundHandler", void 0);
|
|
689
693
|
_wooksjs_event_http.WooksHttpResponse.registerFramework({
|
|
690
694
|
image: "https://moost.org/moost-full-logo.svg",
|
|
691
695
|
link: "https://moost.org/",
|
|
692
696
|
poweredBy: "moostjs",
|
|
693
|
-
version: "0.6.
|
|
697
|
+
version: "0.6.42"
|
|
694
698
|
});
|
|
695
699
|
if (httpApp && httpApp instanceof _wooksjs_event_http.WooksHttp) this.httpApp = httpApp;
|
|
696
700
|
else if (httpApp) this.httpApp = (0, _wooksjs_event_http.createHttpApp)({
|
package/dist/index.d.ts
CHANGED
|
@@ -448,6 +448,7 @@ declare class MoostHttp implements TMoostAdapter<THttpHandlerMeta> {
|
|
|
448
448
|
}>;
|
|
449
449
|
onNotFound(): Promise<unknown>;
|
|
450
450
|
protected moost?: Moost;
|
|
451
|
+
private notFoundHandler?;
|
|
451
452
|
onInit(moost: Moost): void;
|
|
452
453
|
/**
|
|
453
454
|
* Called by `Moost.dispose()` before any `@MoostDispose` hook runs: stops the
|
package/dist/index.mjs
CHANGED
|
@@ -539,6 +539,11 @@ function _define_property(obj, key, value) {
|
|
|
539
539
|
else obj[key] = value;
|
|
540
540
|
return obj;
|
|
541
541
|
}
|
|
542
|
+
const holdScopeUntilResponseCloses = { init: ({ unscope }) => {
|
|
543
|
+
const res = useResponse().getRawRes(true);
|
|
544
|
+
if (res.closed) unscope();
|
|
545
|
+
else res.once("close", unscope);
|
|
546
|
+
} };
|
|
542
547
|
const LOGGER_TITLE = "moost-http";
|
|
543
548
|
/**
|
|
544
549
|
* ## Moost HTTP Adapter
|
|
@@ -603,14 +608,17 @@ const LOGGER_TITLE = "moost-http";
|
|
|
603
608
|
return this.httpApp.listen(port, hostname, backlog, listeningListener);
|
|
604
609
|
}
|
|
605
610
|
async onNotFound() {
|
|
606
|
-
|
|
611
|
+
this.notFoundHandler ?? (this.notFoundHandler = defineMoostEventHandler({
|
|
607
612
|
loggerTitle: LOGGER_TITLE,
|
|
608
613
|
getIterceptorHandler: () => this.moost?.getGlobalInterceptorHandler(),
|
|
609
614
|
getControllerInstance: () => this.moost,
|
|
610
615
|
callControllerMethod: () => new HttpError$1(404, "Resource Not Found"),
|
|
616
|
+
manualUnscope: true,
|
|
617
|
+
hooks: holdScopeUntilResponseCloses,
|
|
611
618
|
targetPath: "",
|
|
612
619
|
handlerType: "__SYSTEM__"
|
|
613
|
-
})
|
|
620
|
+
}));
|
|
621
|
+
return this.notFoundHandler();
|
|
614
622
|
}
|
|
615
623
|
onInit(moost) {
|
|
616
624
|
this.moost = moost;
|
|
@@ -641,6 +649,7 @@ const LOGGER_TITLE = "moost-http";
|
|
|
641
649
|
const httpPath = handler.path;
|
|
642
650
|
const path = typeof httpPath === "string" ? httpPath : typeof opts.method === "string" ? opts.method : "";
|
|
643
651
|
const targetPath = `${`${opts.prefix || ""}/${path}`.replaceAll(/\/\/+/g, "/")}${path.endsWith("//") ? "/" : ""}`;
|
|
652
|
+
const isUpgrade = handler.method === "UPGRADE";
|
|
644
653
|
fn = defineMoostEventHandler({
|
|
645
654
|
loggerTitle: LOGGER_TITLE,
|
|
646
655
|
getIterceptorHandler: opts.getIterceptorHandler,
|
|
@@ -648,19 +657,13 @@ const LOGGER_TITLE = "moost-http";
|
|
|
648
657
|
controllerMethod: opts.method,
|
|
649
658
|
controllerName: opts.controllerName,
|
|
650
659
|
resolveArgs: opts.resolveArgs,
|
|
651
|
-
manualUnscope:
|
|
652
|
-
hooks:
|
|
653
|
-
if (handler.method === "UPGRADE") {
|
|
654
|
-
useRequest().raw.on("end", unscope);
|
|
655
|
-
return;
|
|
656
|
-
}
|
|
657
|
-
useResponse().getRawRes(true).once("close", unscope);
|
|
658
|
-
} },
|
|
660
|
+
manualUnscope: !isUpgrade,
|
|
661
|
+
hooks: isUpgrade ? void 0 : holdScopeUntilResponseCloses,
|
|
659
662
|
targetPath,
|
|
660
663
|
controllerPrefix: opts.prefix,
|
|
661
664
|
handlerType: handler.type
|
|
662
665
|
});
|
|
663
|
-
const routerBinding =
|
|
666
|
+
const routerBinding = isUpgrade ? this.httpApp.upgrade(targetPath, fn) : this.httpApp.on(handler.method, targetPath, fn);
|
|
664
667
|
const { getPath: pathBuilder } = routerBinding;
|
|
665
668
|
const id = (getMoostMate().read(opts.fakeInstance, opts.method) || {}).id || opts.method;
|
|
666
669
|
if (id) {
|
|
@@ -685,11 +688,12 @@ const LOGGER_TITLE = "moost-http";
|
|
|
685
688
|
_define_property(this, "httpApp", void 0);
|
|
686
689
|
_define_property(this, "pathBuilders", {});
|
|
687
690
|
_define_property(this, "moost", void 0);
|
|
691
|
+
_define_property(this, "notFoundHandler", void 0);
|
|
688
692
|
WooksHttpResponse.registerFramework({
|
|
689
693
|
image: "https://moost.org/moost-full-logo.svg",
|
|
690
694
|
link: "https://moost.org/",
|
|
691
695
|
poweredBy: "moostjs",
|
|
692
|
-
version: "0.6.
|
|
696
|
+
version: "0.6.42"
|
|
693
697
|
});
|
|
694
698
|
if (httpApp && httpApp instanceof WooksHttp) this.httpApp = httpApp;
|
|
695
699
|
else if (httpApp) this.httpApp = createHttpApp({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moostjs/event-http",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.42",
|
|
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.25",
|
|
42
|
+
"@wooksjs/http-body": "^0.7.25"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"vitest": "3.2.7"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"@prostojs/infact": "^0.6.0",
|
|
49
|
-
"@wooksjs/event-core": "^0.7.
|
|
50
|
-
"moost": "^0.6.
|
|
49
|
+
"@wooksjs/event-core": "^0.7.25",
|
|
50
|
+
"moost": "^0.6.42"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
53
|
"pub": "pnpm publish --access public",
|