@emeryld/rrroutes-client 2.1.4 → 2.1.6
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 +24 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +23 -18
- package/dist/index.mjs.map +1 -1
- package/dist/routesV3.client.index.d.ts +9 -1
- package/dist/routesV3.client.types.d.ts +10 -23
- package/dist/sockets/socket.client.index.d.ts +3 -3
- package/dist/sockets/socket.client.sys.d.ts +8 -8
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -33,6 +33,7 @@ var index_exports = {};
|
|
|
33
33
|
__export(index_exports, {
|
|
34
34
|
SocketClient: () => SocketClient,
|
|
35
35
|
buildRoomPayloadSchema: () => buildRoomPayloadSchema,
|
|
36
|
+
buildRouter: () => buildRouter,
|
|
36
37
|
buildSocketProvider: () => buildSocketProvider,
|
|
37
38
|
createRouteClient: () => createRouteClient,
|
|
38
39
|
defaultFetcher: () => defaultFetcher,
|
|
@@ -455,6 +456,10 @@ function createRouteClient(opts) {
|
|
|
455
456
|
build: buildInternal
|
|
456
457
|
};
|
|
457
458
|
}
|
|
459
|
+
function buildRouter(routeClient, routes) {
|
|
460
|
+
const buildLeaf = routeClient.build;
|
|
461
|
+
return ((key, opts, meta) => buildLeaf(routes[key], opts, meta));
|
|
462
|
+
}
|
|
458
463
|
function toFormData(body) {
|
|
459
464
|
const fd = new FormData();
|
|
460
465
|
for (const [k, v] of Object.entries(body ?? {})) {
|
|
@@ -730,7 +735,7 @@ var SocketClient = class {
|
|
|
730
735
|
});
|
|
731
736
|
this.logSocketConfigSnapshot("constructor");
|
|
732
737
|
}
|
|
733
|
-
this.onConnect = () => {
|
|
738
|
+
this.onConnect = async () => {
|
|
734
739
|
if (!this.socket) {
|
|
735
740
|
this.dbg({ type: "connection", phase: "connect_event", err: "Socket is null" });
|
|
736
741
|
throw new Error("Socket is null in onConnect handler");
|
|
@@ -744,12 +749,12 @@ var SocketClient = class {
|
|
|
744
749
|
}
|
|
745
750
|
});
|
|
746
751
|
this.logSocketConfigSnapshot("connect_event");
|
|
747
|
-
this.getSysEvent("sys:connect")({
|
|
752
|
+
await this.getSysEvent("sys:connect")({
|
|
748
753
|
socket: this.socket,
|
|
749
754
|
client: this
|
|
750
755
|
});
|
|
751
756
|
};
|
|
752
|
-
this.onReconnect = (attempt) => {
|
|
757
|
+
this.onReconnect = async (attempt) => {
|
|
753
758
|
if (!this.socket) {
|
|
754
759
|
this.dbg({ type: "connection", phase: "reconnect_event", err: "Socket is null" });
|
|
755
760
|
throw new Error("Socket is null in onReconnect handler");
|
|
@@ -764,13 +769,13 @@ var SocketClient = class {
|
|
|
764
769
|
}
|
|
765
770
|
});
|
|
766
771
|
this.logSocketConfigSnapshot("reconnect_event");
|
|
767
|
-
this.getSysEvent("sys:reconnect")({
|
|
772
|
+
await this.getSysEvent("sys:reconnect")({
|
|
768
773
|
attempt,
|
|
769
774
|
socket: this.socket,
|
|
770
775
|
client: this
|
|
771
776
|
});
|
|
772
777
|
};
|
|
773
|
-
this.onDisconnect = (reason) => {
|
|
778
|
+
this.onDisconnect = async (reason) => {
|
|
774
779
|
if (!this.socket) {
|
|
775
780
|
this.dbg({ type: "connection", phase: "disconnect_event", err: "Socket is null" });
|
|
776
781
|
throw new Error("Socket is null in onDisconnect handler");
|
|
@@ -784,13 +789,13 @@ var SocketClient = class {
|
|
|
784
789
|
}
|
|
785
790
|
});
|
|
786
791
|
this.logSocketConfigSnapshot("disconnect_event");
|
|
787
|
-
this.getSysEvent("sys:disconnect")({
|
|
792
|
+
await this.getSysEvent("sys:disconnect")({
|
|
788
793
|
reason: String(reason),
|
|
789
794
|
socket: this.socket,
|
|
790
795
|
client: this
|
|
791
796
|
});
|
|
792
797
|
};
|
|
793
|
-
this.onConnectError = (err) => {
|
|
798
|
+
this.onConnectError = async (err) => {
|
|
794
799
|
if (!this.socket) {
|
|
795
800
|
this.dbg({ type: "connection", phase: "connect_error_event", err: "Socket is null" });
|
|
796
801
|
throw new Error("Socket is null in onConnectError handler");
|
|
@@ -802,13 +807,13 @@ var SocketClient = class {
|
|
|
802
807
|
details: this.getVerboseDetails({ rawError: err })
|
|
803
808
|
});
|
|
804
809
|
this.logSocketConfigSnapshot("connect_error_event");
|
|
805
|
-
this.getSysEvent("sys:connect_error")({
|
|
810
|
+
await this.getSysEvent("sys:connect_error")({
|
|
806
811
|
error: String(err),
|
|
807
812
|
socket: this.socket,
|
|
808
813
|
client: this
|
|
809
814
|
});
|
|
810
815
|
};
|
|
811
|
-
this.onPong = (raw) => {
|
|
816
|
+
this.onPong = async (raw) => {
|
|
812
817
|
if (!this.socket) {
|
|
813
818
|
this.dbg({ type: "heartbeat", phase: "pong_recv", err: "Socket is null" });
|
|
814
819
|
throw new Error("Socket is null in onPong handler");
|
|
@@ -829,7 +834,7 @@ var SocketClient = class {
|
|
|
829
834
|
phase: "pong_recv",
|
|
830
835
|
payload: validated
|
|
831
836
|
});
|
|
832
|
-
this.getSysEvent("sys:pong")({
|
|
837
|
+
await this.getSysEvent("sys:pong")({
|
|
833
838
|
socket: this.socket,
|
|
834
839
|
payload: validated,
|
|
835
840
|
client: this
|
|
@@ -964,7 +969,7 @@ var SocketClient = class {
|
|
|
964
969
|
timeoutMs: this.hb.timeoutMs
|
|
965
970
|
}
|
|
966
971
|
});
|
|
967
|
-
const tick = () => {
|
|
972
|
+
const tick = async () => {
|
|
968
973
|
if (!socket) {
|
|
969
974
|
this.dbg({
|
|
970
975
|
type: "heartbeat",
|
|
@@ -973,7 +978,7 @@ var SocketClient = class {
|
|
|
973
978
|
});
|
|
974
979
|
return;
|
|
975
980
|
}
|
|
976
|
-
const payload = this.getSysEvent("sys:ping")({
|
|
981
|
+
const payload = await this.getSysEvent("sys:ping")({
|
|
977
982
|
socket,
|
|
978
983
|
client: this
|
|
979
984
|
});
|
|
@@ -1043,12 +1048,12 @@ var SocketClient = class {
|
|
|
1043
1048
|
metadata
|
|
1044
1049
|
});
|
|
1045
1050
|
}
|
|
1046
|
-
joinRooms(rooms, meta) {
|
|
1051
|
+
async joinRooms(rooms, meta) {
|
|
1047
1052
|
if (!this.socket) {
|
|
1048
1053
|
this.dbg({ type: "room", phase: "join", rooms: this.toArray(rooms), err: "Socket is null" });
|
|
1049
1054
|
throw new Error("Socket is null in joinRooms method");
|
|
1050
1055
|
}
|
|
1051
|
-
if (!this.getSysEvent("sys:room_join")({
|
|
1056
|
+
if (!await this.getSysEvent("sys:room_join")({
|
|
1052
1057
|
rooms,
|
|
1053
1058
|
meta,
|
|
1054
1059
|
socket: this.socket,
|
|
@@ -1091,12 +1096,12 @@ var SocketClient = class {
|
|
|
1091
1096
|
this.dbg({ type: "room", phase: "join", rooms: normalizedRooms });
|
|
1092
1097
|
}
|
|
1093
1098
|
}
|
|
1094
|
-
leaveRooms(rooms, meta) {
|
|
1099
|
+
async leaveRooms(rooms, meta) {
|
|
1095
1100
|
if (!this.socket) {
|
|
1096
1101
|
this.dbg({ type: "room", phase: "leave", rooms: this.toArray(rooms), err: "Socket is null" });
|
|
1097
1102
|
throw new Error("Socket is null in leaveRooms method");
|
|
1098
1103
|
}
|
|
1099
|
-
if (!this.getSysEvent("sys:room_leave")({
|
|
1104
|
+
if (!await this.getSysEvent("sys:room_leave")({
|
|
1100
1105
|
rooms,
|
|
1101
1106
|
meta,
|
|
1102
1107
|
socket: this.socket,
|
|
@@ -1220,7 +1225,7 @@ var SocketClient = class {
|
|
|
1220
1225
|
* Remove all listeners, stop timers, and leave rooms.
|
|
1221
1226
|
* Call when disposing the client instance.
|
|
1222
1227
|
*/
|
|
1223
|
-
destroy(leaveMeta) {
|
|
1228
|
+
async destroy(leaveMeta) {
|
|
1224
1229
|
const socket = this.socket;
|
|
1225
1230
|
this.dbg({
|
|
1226
1231
|
type: "lifecycle",
|
|
@@ -1248,7 +1253,7 @@ var SocketClient = class {
|
|
|
1248
1253
|
this.handlerMap.clear();
|
|
1249
1254
|
const toLeave = Array.from(this.roomCounts.entries()).filter(([, count]) => count > 0).map(([room]) => room);
|
|
1250
1255
|
if (toLeave.length > 0 && socket) {
|
|
1251
|
-
this.leaveRooms(toLeave, leaveMeta);
|
|
1256
|
+
await this.leaveRooms(toLeave, leaveMeta);
|
|
1252
1257
|
}
|
|
1253
1258
|
this.roomCounts.clear();
|
|
1254
1259
|
this.dbg({
|
|
@@ -1309,6 +1314,7 @@ var SocketClient = class {
|
|
|
1309
1314
|
0 && (module.exports = {
|
|
1310
1315
|
SocketClient,
|
|
1311
1316
|
buildRoomPayloadSchema,
|
|
1317
|
+
buildRouter,
|
|
1312
1318
|
buildSocketProvider,
|
|
1313
1319
|
createRouteClient,
|
|
1314
1320
|
defaultFetcher,
|