elysia 2.0.0-beta.3 → 2.0.0-beta.4
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/adapter/bun/index.d.ts +1 -1
- package/dist/adapter/bun/index.js +320 -56
- package/dist/adapter/bun/index.mjs +321 -57
- package/dist/adapter/utils.js +48 -27
- package/dist/adapter/utils.mjs +48 -27
- package/dist/base.d.ts +16 -5
- package/dist/base.js +171 -74
- package/dist/base.mjs +172 -75
- package/dist/compile/aot-capture.js +1 -1
- package/dist/compile/aot-capture.mjs +1 -1
- package/dist/compile/aot.d.ts +1 -0
- package/dist/compile/aot.js +3 -0
- package/dist/compile/aot.mjs +3 -0
- package/dist/compile/handler/frozen-validator.d.ts +4 -1
- package/dist/compile/handler/frozen-validator.js +8 -3
- package/dist/compile/handler/frozen-validator.mjs +5 -3
- package/dist/compile/handler/index.d.ts +1 -1
- package/dist/compile/handler/index.js +3 -3
- package/dist/compile/handler/index.mjs +3 -3
- package/dist/compile/handler/reconstruct.d.ts +1 -1
- package/dist/compile/handler/reconstruct.js +4 -3
- package/dist/compile/handler/reconstruct.mjs +4 -3
- package/dist/compile/jit-probe.d.ts +2 -2
- package/dist/context.d.ts +1 -1
- package/dist/context.js +5 -1
- package/dist/context.mjs +5 -1
- package/dist/package.js +1 -1
- package/dist/package.mjs +1 -1
- package/dist/plugin/aot/core.d.ts +11 -5
- package/dist/plugin/aot/core.js +86 -38
- package/dist/plugin/aot/core.mjs +87 -41
- package/dist/plugin/aot/esbuild.js +8 -2
- package/dist/plugin/aot/esbuild.mjs +9 -3
- package/dist/plugin/aot/hooks.d.ts +2 -1
- package/dist/plugin/aot/hooks.js +3 -3
- package/dist/plugin/aot/hooks.mjs +4 -4
- package/dist/plugin/aot/source.d.ts +4 -1
- package/dist/plugin/aot/source.js +21 -14
- package/dist/plugin/aot/source.mjs +21 -14
- package/dist/plugin/aot/worker.js +2 -2
- package/dist/plugin/aot/worker.mjs +2 -2
- package/dist/route-table.d.ts +3 -0
- package/dist/route-table.js +4 -1
- package/dist/route-table.mjs +4 -1
- package/dist/schema-snapshot.js +17 -22
- package/dist/schema-snapshot.mjs +17 -22
- package/dist/type/bridge-live.js +1 -1
- package/dist/type/bridge-live.mjs +1 -1
- package/dist/type/coerce.d.ts +1 -1
- package/dist/type/constants.d.ts +1 -1
- package/dist/type/typebox-value-live.d.ts +2 -2
- package/dist/type/typebox-value-live.js +2 -2
- package/dist/type/typebox-value-live.mjs +2 -2
- package/dist/type/typebox-value.d.ts +6 -6
- package/dist/type/validator/index.d.ts +1 -1
- package/dist/type/validator/index.js +10 -7
- package/dist/type/validator/index.mjs +10 -7
- package/dist/type/validator/validator-cache.d.ts +1 -1
- package/dist/type/validator/validator-cache.js +17 -9
- package/dist/type/validator/validator-cache.mjs +17 -9
- package/dist/utils.d.ts +10 -1
- package/dist/utils.js +8 -1
- package/dist/utils.mjs +6 -1
- package/dist/ws/context.d.ts +4 -1
- package/dist/ws/context.js +21 -3
- package/dist/ws/context.mjs +20 -3
- package/dist/ws/route.js +57 -12
- package/dist/ws/route.mjs +59 -14
- package/package.json +2 -2
package/dist/ws/route.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isBun } from "../universal/constants.mjs";
|
|
2
|
-
import { assignOwn, deriveEntryFn, isNotEmpty, nullObject } from "../utils.mjs";
|
|
2
|
+
import { assignOwn, deriveEntryFn, isNotEmpty, isSocketQuiet, nullObject } from "../utils.mjs";
|
|
3
3
|
import { isBridgeLive } from "../type/bridge.mjs";
|
|
4
4
|
import { ElysiaError, ElysiaStatus, ValidationError, internalServerErrorBodyString, problemBody, problemResponse } from "../error.mjs";
|
|
5
5
|
import { mapResponse } from "../adapter/web-standard/handler.mjs";
|
|
@@ -13,7 +13,7 @@ import { StandardValidator } from "../validator/index.mjs";
|
|
|
13
13
|
import { RouteValidator } from "../validator/route.mjs";
|
|
14
14
|
import { buildFrozenRouteValidator, isBridgeNotInitialized } from "../compile/handler/frozen-validator.mjs";
|
|
15
15
|
import { composeRouteHook, localMacroRoot, resolveWSLocalHook } from "../compile/handler/index.mjs";
|
|
16
|
-
import { ElysiaWS, isGeneratorObject } from "./context.mjs";
|
|
16
|
+
import { ElysiaWS, isGeneratorObject, trackWSSettling } from "./context.mjs";
|
|
17
17
|
import { createMessageParser } from "./parser.mjs";
|
|
18
18
|
|
|
19
19
|
//#region src/ws/route.ts
|
|
@@ -569,6 +569,8 @@ function accumulateWSOptions(target, routeOptions, _path) {
|
|
|
569
569
|
}
|
|
570
570
|
const MAX_INFLIGHT_MESSAGES = 256;
|
|
571
571
|
function buildGlobalWSHandler() {
|
|
572
|
+
let lifecycle;
|
|
573
|
+
const runLifecycle = (callback, ...args) => lifecycle ? lifecycle.run(callback, ...args) : callback(...args);
|
|
572
574
|
function getElysia(ws) {
|
|
573
575
|
let elysia = ws.data.elysia;
|
|
574
576
|
if (!elysia) {
|
|
@@ -583,9 +585,19 @@ function buildGlobalWSHandler() {
|
|
|
583
585
|
ws.send(typeof error?.message === "string" ? error.message : "Internal Server Error");
|
|
584
586
|
} catch {}
|
|
585
587
|
};
|
|
588
|
+
const releaseLifecycle = (ws) => {
|
|
589
|
+
if (!lifecycle?.closing && isSocketQuiet(ws)) {
|
|
590
|
+
delete ws.data["~lifecycleRun"];
|
|
591
|
+
lifecycle?.sockets.delete(ws);
|
|
592
|
+
}
|
|
593
|
+
};
|
|
586
594
|
const release = (ws) => {
|
|
587
|
-
const
|
|
588
|
-
|
|
595
|
+
const data = ws.data;
|
|
596
|
+
const inflight = data.inflight;
|
|
597
|
+
if (inflight) {
|
|
598
|
+
data.inflight = inflight - 1;
|
|
599
|
+
if (inflight === 1 && data.closeHandlerInvoked) releaseLifecycle(ws);
|
|
600
|
+
}
|
|
589
601
|
};
|
|
590
602
|
function dispatch(ws, message) {
|
|
591
603
|
let result;
|
|
@@ -602,8 +614,9 @@ function buildGlobalWSHandler() {
|
|
|
602
614
|
});
|
|
603
615
|
else release(ws);
|
|
604
616
|
}
|
|
605
|
-
|
|
617
|
+
const handler = {
|
|
606
618
|
message(ws, message) {
|
|
619
|
+
if (lifecycle?.closing) return;
|
|
607
620
|
const data = ws.data;
|
|
608
621
|
if (!data.message) return;
|
|
609
622
|
const inflight = (data.inflight ?? 0) + 1;
|
|
@@ -616,41 +629,73 @@ function buildGlobalWSHandler() {
|
|
|
616
629
|
data.inflight = inflight;
|
|
617
630
|
const opening = data.opening;
|
|
618
631
|
if (opening) return void opening.then(() => {
|
|
619
|
-
if (ws.readyState > 1) return release(ws);
|
|
632
|
+
if (lifecycle?.closing || ws.readyState > 1) return release(ws);
|
|
620
633
|
dispatch(ws, message);
|
|
621
634
|
});
|
|
622
635
|
dispatch(ws, message);
|
|
623
636
|
},
|
|
624
637
|
open(ws) {
|
|
625
|
-
|
|
638
|
+
if (lifecycle) Object.defineProperty(ws.data, "~lifecycleRun", {
|
|
639
|
+
configurable: true,
|
|
640
|
+
value: lifecycle.run
|
|
641
|
+
});
|
|
642
|
+
lifecycle?.sockets.add(ws);
|
|
643
|
+
if (lifecycle?.closing) {
|
|
644
|
+
ws.data.closeHandlerInvoked = true;
|
|
645
|
+
try {
|
|
646
|
+
ws.terminate();
|
|
647
|
+
} catch {}
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
const open = ws.data.open;
|
|
651
|
+
const result = open && runLifecycle(open, getElysia(ws));
|
|
626
652
|
if (result instanceof Promise) {
|
|
627
653
|
const clear = () => {
|
|
628
654
|
ws.data.opening = void 0;
|
|
655
|
+
releaseLifecycle(ws);
|
|
629
656
|
};
|
|
630
657
|
ws.data.opening = result.then(clear, clear);
|
|
631
658
|
}
|
|
632
659
|
},
|
|
633
660
|
drain(ws) {
|
|
661
|
+
if (lifecycle?.closing) return;
|
|
634
662
|
const elyWs = getElysia(ws);
|
|
635
663
|
drainWaiters(elyWs);
|
|
636
|
-
ws.data.drain
|
|
664
|
+
const drain = ws.data.drain;
|
|
665
|
+
trackWSSettling(ws.data, drain && runLifecycle(drain, elyWs), () => releaseLifecycle(ws));
|
|
637
666
|
},
|
|
638
667
|
close(ws, code, reason) {
|
|
639
668
|
const elyWs = getElysia(ws);
|
|
640
669
|
drainWaiters(elyWs);
|
|
641
|
-
ws.data.
|
|
642
|
-
if (ws.data.closeHandlerInvoked) return;
|
|
670
|
+
if (ws.data.closeHandlerInvoked) return releaseLifecycle(ws);
|
|
643
671
|
ws.data.closeHandlerInvoked = true;
|
|
644
|
-
|
|
645
|
-
|
|
672
|
+
let result;
|
|
673
|
+
try {
|
|
674
|
+
const close = ws.data.close;
|
|
675
|
+
result = close && runLifecycle(close, elyWs, code, reason);
|
|
676
|
+
} finally {
|
|
677
|
+
if (!(result instanceof Promise)) releaseLifecycle(ws);
|
|
678
|
+
}
|
|
679
|
+
if (result instanceof Promise) {
|
|
680
|
+
const closing = result.catch(() => {});
|
|
681
|
+
trackWSSettling(ws.data, closing, () => releaseLifecycle(ws));
|
|
682
|
+
}
|
|
646
683
|
},
|
|
647
684
|
ping(ws, data) {
|
|
648
|
-
|
|
685
|
+
if (lifecycle?.closing) return;
|
|
686
|
+
const ping = ws.data.ping;
|
|
687
|
+
trackWSSettling(ws.data, ping && runLifecycle(ping, getElysia(ws), data), () => releaseLifecycle(ws));
|
|
649
688
|
},
|
|
650
689
|
pong(ws, data) {
|
|
651
|
-
|
|
690
|
+
if (lifecycle?.closing) return;
|
|
691
|
+
const pong = ws.data.pong;
|
|
692
|
+
trackWSSettling(ws.data, pong && runLifecycle(pong, getElysia(ws), data), () => releaseLifecycle(ws));
|
|
652
693
|
}
|
|
653
694
|
};
|
|
695
|
+
Object.defineProperty(handler, "~lifecycle", { set(value) {
|
|
696
|
+
lifecycle = value;
|
|
697
|
+
} });
|
|
698
|
+
return handler;
|
|
654
699
|
}
|
|
655
700
|
|
|
656
701
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "elysia",
|
|
3
3
|
"description": "Ergonomic Framework for Human",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.4",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "saltyAom",
|
|
7
7
|
"url": "https://github.com/SaltyAom",
|
|
@@ -244,7 +244,7 @@
|
|
|
244
244
|
],
|
|
245
245
|
"dependencies": {
|
|
246
246
|
"deuri": "^3.0.0",
|
|
247
|
-
"memoirist": "1.2.
|
|
247
|
+
"memoirist": "1.2.2"
|
|
248
248
|
},
|
|
249
249
|
"devDependencies": {
|
|
250
250
|
"@eslint/eslintrc": "^3.3.5",
|