@emeryld/rrroutes-client 2.6.10 → 2.6.11
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 +201 -180
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +195 -174
- package/dist/index.mjs.map +1 -1
- package/dist/routesV3.client.batch.d.ts +13 -0
- package/dist/sockets/socket.client.context.client.d.ts +1 -1
- package/dist/sockets/socket.client.context.connection.d.ts +1 -1
- package/dist/sockets/socket.client.context.provider.d.ts +1 -1
- package/dist/sockets/socket.client.core.d.ts +5 -5
- package/dist/sockets/socketedRoute/socket.client.helper.rooms.d.ts +3 -3
- package/dist/sockets/socketedRoute/socket.client.helper.route.d.ts +11 -6
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,14 +1,149 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
// src/routesV3.client.ts
|
|
3
|
+
// src/routesV3.client.batch.ts
|
|
4
4
|
import {
|
|
5
|
-
lowProfileParse
|
|
5
|
+
lowProfileParse
|
|
6
6
|
} from "@emeryld/rrroutes-contract";
|
|
7
7
|
import {
|
|
8
|
-
keepPreviousData
|
|
9
|
-
useQuery
|
|
8
|
+
keepPreviousData,
|
|
9
|
+
useQuery
|
|
10
10
|
} from "@tanstack/react-query";
|
|
11
|
-
import { useCallback
|
|
11
|
+
import { useCallback, useRef } from "react";
|
|
12
|
+
function buildBatchBranch(leaves, options, deps) {
|
|
13
|
+
const {
|
|
14
|
+
fetchRaw,
|
|
15
|
+
queryClient,
|
|
16
|
+
validateResponses,
|
|
17
|
+
getBuiltLeaf,
|
|
18
|
+
encodeLeafKey,
|
|
19
|
+
toArgsTuple: toArgsTuple2
|
|
20
|
+
} = deps;
|
|
21
|
+
const batchMethod = options.method ?? "POST";
|
|
22
|
+
const defaultHeaders = options.headers;
|
|
23
|
+
const getQueryKeys = (input) => {
|
|
24
|
+
const out = {};
|
|
25
|
+
const argsByLeaf = input ?? {};
|
|
26
|
+
for (const [alias, built] of Object.entries(leaves)) {
|
|
27
|
+
const args = argsByLeaf[alias];
|
|
28
|
+
out[alias] = built.getQueryKeys(...toArgsTuple2(args));
|
|
29
|
+
}
|
|
30
|
+
return out;
|
|
31
|
+
};
|
|
32
|
+
const invalidateBranch = async (input) => {
|
|
33
|
+
const argsByLeaf = input ?? {};
|
|
34
|
+
await Promise.all(
|
|
35
|
+
Object.entries(leaves).map(([alias, built]) => {
|
|
36
|
+
const args = argsByLeaf[alias];
|
|
37
|
+
return built.invalidate(...toArgsTuple2(args));
|
|
38
|
+
})
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
const setDataBranch = (input) => {
|
|
42
|
+
const out = {};
|
|
43
|
+
for (const [alias, def] of Object.entries(input)) {
|
|
44
|
+
if (!def) continue;
|
|
45
|
+
const built = leaves[alias];
|
|
46
|
+
if (!built) continue;
|
|
47
|
+
out[alias] = built.setData(def.updater, ...toArgsTuple2(def.args));
|
|
48
|
+
}
|
|
49
|
+
return out;
|
|
50
|
+
};
|
|
51
|
+
const fetchBranch = async (input) => {
|
|
52
|
+
const payload = {};
|
|
53
|
+
for (const [aliasRaw, built] of Object.entries(leaves)) {
|
|
54
|
+
const leaf = getBuiltLeaf(built);
|
|
55
|
+
const encodedLeaf = encodeLeafKey(leaf);
|
|
56
|
+
const alias = aliasRaw;
|
|
57
|
+
const branchInput = input[alias];
|
|
58
|
+
const query = branchInput?.query;
|
|
59
|
+
const params = branchInput?.params;
|
|
60
|
+
const body = branchInput?.body;
|
|
61
|
+
payload[aliasRaw] = {
|
|
62
|
+
encodedLeaf,
|
|
63
|
+
...params !== void 0 ? { params } : {},
|
|
64
|
+
...query !== void 0 ? { query } : {},
|
|
65
|
+
...body !== void 0 ? { body } : {}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
const batchResponse = await fetchRaw({
|
|
69
|
+
path: options.path,
|
|
70
|
+
method: batchMethod,
|
|
71
|
+
body: payload,
|
|
72
|
+
headers: defaultHeaders
|
|
73
|
+
});
|
|
74
|
+
const rawData = batchResponse.data;
|
|
75
|
+
if (!rawData || typeof rawData !== "object" || Array.isArray(rawData)) {
|
|
76
|
+
throw new Error(
|
|
77
|
+
"Batch response must be a plain object keyed by branch aliases."
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
const mapped = {};
|
|
81
|
+
for (const [aliasRaw, built] of Object.entries(leaves)) {
|
|
82
|
+
if (!(aliasRaw in rawData)) {
|
|
83
|
+
throw new Error(`Batch response missing alias "${aliasRaw}".`);
|
|
84
|
+
}
|
|
85
|
+
const leaf = getBuiltLeaf(built);
|
|
86
|
+
const rawLeafData = rawData[aliasRaw];
|
|
87
|
+
const parsedLeafData = validateResponses && leaf.cfg.outputSchema ? lowProfileParse(leaf.cfg.outputSchema, rawLeafData) : rawLeafData;
|
|
88
|
+
if (validateResponses && !leaf.cfg.outputSchema) {
|
|
89
|
+
throw new Error(
|
|
90
|
+
`No output schema defined for leaf ${leaf.method.toUpperCase()} ${leaf.path}, cannot validate batch response.`
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
;
|
|
94
|
+
mapped[aliasRaw] = parsedLeafData;
|
|
95
|
+
}
|
|
96
|
+
return mapped;
|
|
97
|
+
};
|
|
98
|
+
const useEndpoint = (input, rqOpts) => {
|
|
99
|
+
const queryKeys = getQueryKeys(input);
|
|
100
|
+
const branchQueryKey = [
|
|
101
|
+
"batch",
|
|
102
|
+
String(batchMethod).toLowerCase(),
|
|
103
|
+
options.path,
|
|
104
|
+
queryKeys
|
|
105
|
+
];
|
|
106
|
+
const { onReceive, ...useQueryOptions } = rqOpts ?? {};
|
|
107
|
+
const listenersRef = useRef(/* @__PURE__ */ new Set());
|
|
108
|
+
const notifyOnReceive = useCallback(
|
|
109
|
+
(data) => {
|
|
110
|
+
onReceive?.(data);
|
|
111
|
+
listenersRef.current.forEach((listener) => listener(data));
|
|
112
|
+
},
|
|
113
|
+
[onReceive]
|
|
114
|
+
);
|
|
115
|
+
const registerOnReceive = useCallback(
|
|
116
|
+
(listener) => {
|
|
117
|
+
listenersRef.current.add(listener);
|
|
118
|
+
return () => {
|
|
119
|
+
listenersRef.current.delete(listener);
|
|
120
|
+
};
|
|
121
|
+
},
|
|
122
|
+
[]
|
|
123
|
+
);
|
|
124
|
+
const queryResult = useQuery(
|
|
125
|
+
{
|
|
126
|
+
...useQueryOptions,
|
|
127
|
+
queryKey: branchQueryKey,
|
|
128
|
+
placeholderData: useQueryOptions.placeholderData ?? keepPreviousData,
|
|
129
|
+
queryFn: async () => {
|
|
130
|
+
const result = await fetchBranch(input);
|
|
131
|
+
notifyOnReceive(result);
|
|
132
|
+
return result;
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
queryClient
|
|
136
|
+
);
|
|
137
|
+
return { ...queryResult, onReceive: registerOnReceive };
|
|
138
|
+
};
|
|
139
|
+
return {
|
|
140
|
+
fetch: fetchBranch,
|
|
141
|
+
useEndpoint,
|
|
142
|
+
getQueryKeys,
|
|
143
|
+
invalidate: invalidateBranch,
|
|
144
|
+
setData: setDataBranch
|
|
145
|
+
};
|
|
146
|
+
}
|
|
12
147
|
|
|
13
148
|
// src/routesV3.client.fetch.ts
|
|
14
149
|
var HttpError = class extends Error {
|
|
@@ -62,15 +197,15 @@ var defaultFetcher = async (req) => {
|
|
|
62
197
|
};
|
|
63
198
|
|
|
64
199
|
// src/routesV3.client.get.ts
|
|
65
|
-
import { buildCacheKey, lowProfileParse as
|
|
200
|
+
import { buildCacheKey, lowProfileParse as lowProfileParse3 } from "@emeryld/rrroutes-contract";
|
|
66
201
|
import {
|
|
67
|
-
keepPreviousData,
|
|
68
|
-
useQuery
|
|
202
|
+
keepPreviousData as keepPreviousData2,
|
|
203
|
+
useQuery as useQuery2
|
|
69
204
|
} from "@tanstack/react-query";
|
|
70
|
-
import { useCallback, useRef } from "react";
|
|
205
|
+
import { useCallback as useCallback2, useRef as useRef2 } from "react";
|
|
71
206
|
|
|
72
207
|
// src/routesV3.client.shared.ts
|
|
73
|
-
import { compilePath, lowProfileParse } from "@emeryld/rrroutes-contract";
|
|
208
|
+
import { compilePath, lowProfileParse as lowProfileParse2 } from "@emeryld/rrroutes-contract";
|
|
74
209
|
var toUpper = (m) => m.toUpperCase();
|
|
75
210
|
function toSearchString(query) {
|
|
76
211
|
if (!query) return "";
|
|
@@ -120,8 +255,8 @@ function toArgsTuple(args) {
|
|
|
120
255
|
return typeof args === "undefined" ? [] : [args];
|
|
121
256
|
}
|
|
122
257
|
function buildUrl(leaf, baseUrl, params, query) {
|
|
123
|
-
const normalizedParams = leaf.cfg.paramsSchema ?
|
|
124
|
-
const normalizedQuery = leaf.cfg.querySchema ?
|
|
258
|
+
const normalizedParams = leaf.cfg.paramsSchema ? lowProfileParse2(leaf.cfg.paramsSchema, params) : {};
|
|
259
|
+
const normalizedQuery = leaf.cfg.querySchema ? lowProfileParse2(leaf.cfg.querySchema, query) : {};
|
|
125
260
|
const path = compilePath(
|
|
126
261
|
leaf.path,
|
|
127
262
|
normalizedParams ?? {}
|
|
@@ -356,7 +491,7 @@ function buildGetLeaf(leaf, rqOpts, env) {
|
|
|
356
491
|
options.body,
|
|
357
492
|
leafCfg.bodyFiles
|
|
358
493
|
);
|
|
359
|
-
const normalizedBody = leafCfg.bodySchema ?
|
|
494
|
+
const normalizedBody = leafCfg.bodySchema ? lowProfileParse3(leafCfg.bodySchema, regularBody) : regularBody;
|
|
360
495
|
if (isMultipart && normalizedBody && typeof normalizedBody === "object") {
|
|
361
496
|
payload = toFormData(
|
|
362
497
|
{
|
|
@@ -413,7 +548,7 @@ function buildGetLeaf(leaf, rqOpts, env) {
|
|
|
413
548
|
`No output schema defined for leaf ${leafLabel}, cannot validate response.`
|
|
414
549
|
);
|
|
415
550
|
}
|
|
416
|
-
out.data =
|
|
551
|
+
out.data = lowProfileParse3(
|
|
417
552
|
leafCfg.outputSchema,
|
|
418
553
|
out.data
|
|
419
554
|
);
|
|
@@ -480,12 +615,12 @@ function buildGetLeaf(leaf, rqOpts, env) {
|
|
|
480
615
|
keys: queryKeys
|
|
481
616
|
});
|
|
482
617
|
const buildOptions = rqOpts ?? {};
|
|
483
|
-
const listenersRef =
|
|
484
|
-
const notifyOnReceive =
|
|
618
|
+
const listenersRef = useRef2(/* @__PURE__ */ new Set());
|
|
619
|
+
const notifyOnReceive = useCallback2((data) => {
|
|
485
620
|
buildOptions?.onReceive?.(data);
|
|
486
621
|
listenersRef.current.forEach((listener) => listener(data));
|
|
487
622
|
}, []);
|
|
488
|
-
const registerOnReceive =
|
|
623
|
+
const registerOnReceive = useCallback2(
|
|
489
624
|
(listener) => {
|
|
490
625
|
listenersRef.current.add(listener);
|
|
491
626
|
return () => {
|
|
@@ -494,11 +629,11 @@ function buildGetLeaf(leaf, rqOpts, env) {
|
|
|
494
629
|
},
|
|
495
630
|
[]
|
|
496
631
|
);
|
|
497
|
-
const queryResult =
|
|
632
|
+
const queryResult = useQuery2(
|
|
498
633
|
{
|
|
499
634
|
...buildOptions,
|
|
500
635
|
queryKey: getQueryKeys(...tuple),
|
|
501
|
-
placeholderData:
|
|
636
|
+
placeholderData: keepPreviousData2,
|
|
502
637
|
queryFn: () => fetchEndpoint(tuple, {
|
|
503
638
|
onReceive: notifyOnReceive
|
|
504
639
|
})
|
|
@@ -517,12 +652,12 @@ function buildGetLeaf(leaf, rqOpts, env) {
|
|
|
517
652
|
}
|
|
518
653
|
|
|
519
654
|
// src/routesV3.client.infiniteGet.ts
|
|
520
|
-
import { buildCacheKey as buildCacheKey2, lowProfileParse as
|
|
655
|
+
import { buildCacheKey as buildCacheKey2, lowProfileParse as lowProfileParse4 } from "@emeryld/rrroutes-contract";
|
|
521
656
|
import {
|
|
522
|
-
keepPreviousData as
|
|
657
|
+
keepPreviousData as keepPreviousData3,
|
|
523
658
|
useInfiniteQuery
|
|
524
659
|
} from "@tanstack/react-query";
|
|
525
|
-
import { useCallback as
|
|
660
|
+
import { useCallback as useCallback3, useRef as useRef3 } from "react";
|
|
526
661
|
function mergePageOutputs(prev, next) {
|
|
527
662
|
if (prev == null) return next;
|
|
528
663
|
if (next == null) return prev;
|
|
@@ -632,7 +767,7 @@ function buildInfiniteGetLeaf(leaf, rqOpts, env) {
|
|
|
632
767
|
options.body,
|
|
633
768
|
leafCfg.bodyFiles
|
|
634
769
|
);
|
|
635
|
-
const normalizedBody = leafCfg.bodySchema ?
|
|
770
|
+
const normalizedBody = leafCfg.bodySchema ? lowProfileParse4(leafCfg.bodySchema, regularBody) : regularBody;
|
|
636
771
|
if (isMultipart && normalizedBody && typeof normalizedBody === "object") {
|
|
637
772
|
payload = toFormData(
|
|
638
773
|
{
|
|
@@ -689,7 +824,7 @@ function buildInfiniteGetLeaf(leaf, rqOpts, env) {
|
|
|
689
824
|
`No output schema defined for leaf ${leafLabel}, cannot validate response.`
|
|
690
825
|
);
|
|
691
826
|
}
|
|
692
|
-
out.data =
|
|
827
|
+
out.data = lowProfileParse4(
|
|
693
828
|
leafCfg.outputSchema,
|
|
694
829
|
out.data
|
|
695
830
|
);
|
|
@@ -758,12 +893,12 @@ function buildInfiniteGetLeaf(leaf, rqOpts, env) {
|
|
|
758
893
|
const params = args?.params;
|
|
759
894
|
const query = args?.query;
|
|
760
895
|
const buildOptions = feedQueryOptions ?? {};
|
|
761
|
-
const listenersRef =
|
|
762
|
-
const notifyOnReceive =
|
|
896
|
+
const listenersRef = useRef3(/* @__PURE__ */ new Set());
|
|
897
|
+
const notifyOnReceive = useCallback3((data) => {
|
|
763
898
|
buildOptions?.onReceive?.(data);
|
|
764
899
|
listenersRef.current.forEach((listener) => listener(data));
|
|
765
900
|
}, []);
|
|
766
|
-
const registerOnReceive =
|
|
901
|
+
const registerOnReceive = useCallback3(
|
|
767
902
|
(listener) => {
|
|
768
903
|
listenersRef.current.add(listener);
|
|
769
904
|
return () => {
|
|
@@ -781,7 +916,7 @@ function buildInfiniteGetLeaf(leaf, rqOpts, env) {
|
|
|
781
916
|
const queryResult = useInfiniteQuery(
|
|
782
917
|
{
|
|
783
918
|
...buildOptions,
|
|
784
|
-
placeholderData: buildOptions.placeholderData ??
|
|
919
|
+
placeholderData: buildOptions.placeholderData ?? keepPreviousData3,
|
|
785
920
|
initialPageParam: feedInitialPageParam,
|
|
786
921
|
getNextPageParam: (lastPage) => cursorFromPage(lastPage),
|
|
787
922
|
queryKey: queryKeys,
|
|
@@ -874,11 +1009,11 @@ function buildInfiniteGetLeaf(leaf, rqOpts, env) {
|
|
|
874
1009
|
}
|
|
875
1010
|
|
|
876
1011
|
// src/routesV3.client.mutation.ts
|
|
877
|
-
import { buildCacheKey as buildCacheKey3, lowProfileParse as
|
|
1012
|
+
import { buildCacheKey as buildCacheKey3, lowProfileParse as lowProfileParse5 } from "@emeryld/rrroutes-contract";
|
|
878
1013
|
import {
|
|
879
1014
|
useMutation
|
|
880
1015
|
} from "@tanstack/react-query";
|
|
881
|
-
import { useCallback as
|
|
1016
|
+
import { useCallback as useCallback4, useRef as useRef4 } from "react";
|
|
882
1017
|
function buildMutationLeaf(leaf, rqOpts, env) {
|
|
883
1018
|
const leafCfg = leaf.cfg;
|
|
884
1019
|
const method = toUpper(leaf.method);
|
|
@@ -942,7 +1077,7 @@ function buildMutationLeaf(leaf, rqOpts, env) {
|
|
|
942
1077
|
options.body,
|
|
943
1078
|
leafCfg.bodyFiles
|
|
944
1079
|
);
|
|
945
|
-
const normalizedBody = leafCfg.bodySchema ?
|
|
1080
|
+
const normalizedBody = leafCfg.bodySchema ? lowProfileParse5(leafCfg.bodySchema, regularBody) : regularBody;
|
|
946
1081
|
if (isMultipart && normalizedBody && typeof normalizedBody === "object") {
|
|
947
1082
|
payload = toFormData(
|
|
948
1083
|
{
|
|
@@ -999,7 +1134,7 @@ function buildMutationLeaf(leaf, rqOpts, env) {
|
|
|
999
1134
|
`No output schema defined for leaf ${leafLabel}, cannot validate response.`
|
|
1000
1135
|
);
|
|
1001
1136
|
}
|
|
1002
|
-
out.data =
|
|
1137
|
+
out.data = lowProfileParse5(
|
|
1003
1138
|
leafCfg.outputSchema,
|
|
1004
1139
|
out.data
|
|
1005
1140
|
);
|
|
@@ -1066,11 +1201,11 @@ function buildMutationLeaf(leaf, rqOpts, env) {
|
|
|
1066
1201
|
variant: "mutation",
|
|
1067
1202
|
keys: mutationKey
|
|
1068
1203
|
});
|
|
1069
|
-
const listenersRef =
|
|
1070
|
-
const notifyListeners =
|
|
1204
|
+
const listenersRef = useRef4(/* @__PURE__ */ new Set());
|
|
1205
|
+
const notifyListeners = useCallback4((data) => {
|
|
1071
1206
|
listenersRef.current.forEach((listener) => listener(data));
|
|
1072
1207
|
}, []);
|
|
1073
|
-
const registerOnReceive =
|
|
1208
|
+
const registerOnReceive = useCallback4(
|
|
1074
1209
|
(listener) => {
|
|
1075
1210
|
listenersRef.current.add(listener);
|
|
1076
1211
|
return () => {
|
|
@@ -1309,138 +1444,14 @@ function createRouteClient(opts) {
|
|
|
1309
1444
|
throw error;
|
|
1310
1445
|
}
|
|
1311
1446
|
};
|
|
1312
|
-
const buildBranchInternal = (leaves, options) => {
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
out[alias] = built.getQueryKeys(...toArgsTuple2(args));
|
|
1321
|
-
}
|
|
1322
|
-
return out;
|
|
1323
|
-
};
|
|
1324
|
-
const invalidateBranch = async (input) => {
|
|
1325
|
-
const argsByLeaf = input ?? {};
|
|
1326
|
-
await Promise.all(
|
|
1327
|
-
Object.entries(leaves).map(([alias, built]) => {
|
|
1328
|
-
const args = argsByLeaf[alias];
|
|
1329
|
-
return built.invalidate(...toArgsTuple2(args));
|
|
1330
|
-
})
|
|
1331
|
-
);
|
|
1332
|
-
};
|
|
1333
|
-
const setDataBranch = (input) => {
|
|
1334
|
-
const out = {};
|
|
1335
|
-
for (const [alias, def] of Object.entries(input)) {
|
|
1336
|
-
if (!def) continue;
|
|
1337
|
-
const built = leaves[alias];
|
|
1338
|
-
if (!built) continue;
|
|
1339
|
-
out[alias] = built.setData(
|
|
1340
|
-
def.updater,
|
|
1341
|
-
...toArgsTuple2(def.args)
|
|
1342
|
-
);
|
|
1343
|
-
}
|
|
1344
|
-
return out;
|
|
1345
|
-
};
|
|
1346
|
-
const fetchBranch = async (input) => {
|
|
1347
|
-
const payload = {};
|
|
1348
|
-
for (const [aliasRaw, built] of Object.entries(leaves)) {
|
|
1349
|
-
const leaf = getBuiltLeaf(built);
|
|
1350
|
-
const encodedLeaf = encodeLeafKey(leaf);
|
|
1351
|
-
const alias = aliasRaw;
|
|
1352
|
-
const branchInput = input[alias];
|
|
1353
|
-
const query = branchInput?.query;
|
|
1354
|
-
const params = branchInput?.params;
|
|
1355
|
-
const body = branchInput?.body;
|
|
1356
|
-
payload[aliasRaw] = {
|
|
1357
|
-
encodedLeaf,
|
|
1358
|
-
...params !== void 0 ? { params } : {},
|
|
1359
|
-
...query !== void 0 ? { query } : {},
|
|
1360
|
-
...body !== void 0 ? { body } : {}
|
|
1361
|
-
};
|
|
1362
|
-
}
|
|
1363
|
-
const batchResponse = await fetchRaw({
|
|
1364
|
-
path: options.path,
|
|
1365
|
-
method: batchMethod,
|
|
1366
|
-
body: payload,
|
|
1367
|
-
headers: defaultHeaders
|
|
1368
|
-
});
|
|
1369
|
-
const rawData = batchResponse.data;
|
|
1370
|
-
if (!rawData || typeof rawData !== "object" || Array.isArray(rawData)) {
|
|
1371
|
-
throw new Error(
|
|
1372
|
-
"Batch response must be a plain object keyed by branch aliases."
|
|
1373
|
-
);
|
|
1374
|
-
}
|
|
1375
|
-
const mapped = {};
|
|
1376
|
-
for (const [aliasRaw, built] of Object.entries(leaves)) {
|
|
1377
|
-
if (!(aliasRaw in rawData)) {
|
|
1378
|
-
throw new Error(`Batch response missing alias "${aliasRaw}".`);
|
|
1379
|
-
}
|
|
1380
|
-
const leaf = getBuiltLeaf(built);
|
|
1381
|
-
const rawLeafData = rawData[aliasRaw];
|
|
1382
|
-
const parsedLeafData = validateResponses && leaf.cfg.outputSchema ? lowProfileParse5(leaf.cfg.outputSchema, rawLeafData) : rawLeafData;
|
|
1383
|
-
if (validateResponses && !leaf.cfg.outputSchema) {
|
|
1384
|
-
throw new Error(
|
|
1385
|
-
`No output schema defined for leaf ${leaf.method.toUpperCase()} ${leaf.path}, cannot validate batch response.`
|
|
1386
|
-
);
|
|
1387
|
-
}
|
|
1388
|
-
;
|
|
1389
|
-
mapped[aliasRaw] = parsedLeafData;
|
|
1390
|
-
}
|
|
1391
|
-
return mapped;
|
|
1392
|
-
};
|
|
1393
|
-
const useEndpoint = (input, rqOpts) => {
|
|
1394
|
-
const queryKeys = getQueryKeys(input);
|
|
1395
|
-
const branchQueryKey = [
|
|
1396
|
-
"batch",
|
|
1397
|
-
String(batchMethod).toLowerCase(),
|
|
1398
|
-
options.path,
|
|
1399
|
-
queryKeys
|
|
1400
|
-
];
|
|
1401
|
-
const { onReceive, ...useQueryOptions } = rqOpts ?? {};
|
|
1402
|
-
const listenersRef = useRef4(
|
|
1403
|
-
/* @__PURE__ */ new Set()
|
|
1404
|
-
);
|
|
1405
|
-
const notifyOnReceive = useCallback4(
|
|
1406
|
-
(data) => {
|
|
1407
|
-
onReceive?.(data);
|
|
1408
|
-
listenersRef.current.forEach((listener) => listener(data));
|
|
1409
|
-
},
|
|
1410
|
-
[onReceive]
|
|
1411
|
-
);
|
|
1412
|
-
const registerOnReceive = useCallback4(
|
|
1413
|
-
(listener) => {
|
|
1414
|
-
listenersRef.current.add(listener);
|
|
1415
|
-
return () => {
|
|
1416
|
-
listenersRef.current.delete(listener);
|
|
1417
|
-
};
|
|
1418
|
-
},
|
|
1419
|
-
[]
|
|
1420
|
-
);
|
|
1421
|
-
const queryResult = useQuery2(
|
|
1422
|
-
{
|
|
1423
|
-
...useQueryOptions,
|
|
1424
|
-
queryKey: branchQueryKey,
|
|
1425
|
-
placeholderData: useQueryOptions.placeholderData ?? keepPreviousData3,
|
|
1426
|
-
queryFn: async () => {
|
|
1427
|
-
const result = await fetchBranch(input);
|
|
1428
|
-
notifyOnReceive(result);
|
|
1429
|
-
return result;
|
|
1430
|
-
}
|
|
1431
|
-
},
|
|
1432
|
-
queryClient
|
|
1433
|
-
);
|
|
1434
|
-
return { ...queryResult, onReceive: registerOnReceive };
|
|
1435
|
-
};
|
|
1436
|
-
return {
|
|
1437
|
-
fetch: fetchBranch,
|
|
1438
|
-
useEndpoint,
|
|
1439
|
-
getQueryKeys,
|
|
1440
|
-
invalidate: invalidateBranch,
|
|
1441
|
-
setData: setDataBranch
|
|
1442
|
-
};
|
|
1443
|
-
};
|
|
1447
|
+
const buildBranchInternal = (leaves, options) => buildBatchBranch(leaves, options, {
|
|
1448
|
+
fetchRaw,
|
|
1449
|
+
queryClient,
|
|
1450
|
+
validateResponses,
|
|
1451
|
+
getBuiltLeaf,
|
|
1452
|
+
encodeLeafKey,
|
|
1453
|
+
toArgsTuple: toArgsTuple2
|
|
1454
|
+
});
|
|
1444
1455
|
return {
|
|
1445
1456
|
queryClient,
|
|
1446
1457
|
invalidate,
|
|
@@ -1466,8 +1477,9 @@ import * as React from "react";
|
|
|
1466
1477
|
var SocketCtx = React.createContext(null);
|
|
1467
1478
|
function useSocketClient() {
|
|
1468
1479
|
const ctx = React.useContext(SocketCtx);
|
|
1469
|
-
if (!ctx)
|
|
1470
|
-
|
|
1480
|
+
if (!ctx) {
|
|
1481
|
+
return null;
|
|
1482
|
+
}
|
|
1471
1483
|
return ctx;
|
|
1472
1484
|
}
|
|
1473
1485
|
|
|
@@ -1496,6 +1508,7 @@ function useSocketConnection(args) {
|
|
|
1496
1508
|
[]
|
|
1497
1509
|
);
|
|
1498
1510
|
React2.useEffect(() => {
|
|
1511
|
+
if (!client) return;
|
|
1499
1512
|
if (autoJoin && normalizedRooms.length > 0)
|
|
1500
1513
|
void client.joinRooms(normalizedRooms, args.joinMeta).catch((error) => reportAsyncError("joinRooms", error));
|
|
1501
1514
|
const unsubscribe = client.on(event, (payload, meta) => {
|
|
@@ -2685,12 +2698,12 @@ function mergeRoomState(prev, toRoomsResult) {
|
|
|
2685
2698
|
leaveMeta: toRoomsResult.leaveMeta ?? prev.leaveMeta
|
|
2686
2699
|
};
|
|
2687
2700
|
}
|
|
2688
|
-
function roomsFromData(data, toRooms) {
|
|
2701
|
+
function roomsFromData(data, args, toRooms) {
|
|
2689
2702
|
if (data == null) return { rooms: [] };
|
|
2690
2703
|
let state = { rooms: [] };
|
|
2691
2704
|
const add = (input) => {
|
|
2692
2705
|
const mergeForValue = (value) => {
|
|
2693
|
-
state = mergeRoomState(state, toRooms(value));
|
|
2706
|
+
state = mergeRoomState(state, toRooms(value, ...args));
|
|
2694
2707
|
};
|
|
2695
2708
|
if (Array.isArray(input)) {
|
|
2696
2709
|
input.forEach((entry) => mergeForValue(entry));
|
|
@@ -2735,7 +2748,11 @@ function buildSocketedRoute(options) {
|
|
|
2735
2748
|
);
|
|
2736
2749
|
const argsKey = useMemo3(() => safeJsonKey(useArgs[0] ?? null), [useArgs]);
|
|
2737
2750
|
const [roomState, setRoomState] = useState2(
|
|
2738
|
-
() => roomsFromData(
|
|
2751
|
+
() => roomsFromData(
|
|
2752
|
+
endpointResult.data,
|
|
2753
|
+
useArgs,
|
|
2754
|
+
toRooms
|
|
2755
|
+
)
|
|
2739
2756
|
);
|
|
2740
2757
|
const renderCountRef = useRef6(0);
|
|
2741
2758
|
const clientReadyRef = useRef6(null);
|
|
@@ -2789,7 +2806,10 @@ function buildSocketedRoute(options) {
|
|
|
2789
2806
|
});
|
|
2790
2807
|
const unsubscribe = endpointResult.onReceive((data) => {
|
|
2791
2808
|
setRoomState((prev) => {
|
|
2792
|
-
const next = mergeRoomState(
|
|
2809
|
+
const next = mergeRoomState(
|
|
2810
|
+
prev,
|
|
2811
|
+
toRoomsRef.current(data, ...useArgs)
|
|
2812
|
+
);
|
|
2793
2813
|
return roomStateEqual(prev, next) ? prev : next;
|
|
2794
2814
|
});
|
|
2795
2815
|
});
|
|
@@ -2806,7 +2826,7 @@ function buildSocketedRoute(options) {
|
|
|
2806
2826
|
toRoomsRef: describeObjectReference(toRooms)
|
|
2807
2827
|
}
|
|
2808
2828
|
});
|
|
2809
|
-
const next = roomsFromData(endpointDataRef.current, toRooms);
|
|
2829
|
+
const next = roomsFromData(endpointDataRef.current, useArgs, toRooms);
|
|
2810
2830
|
setRoomState((prev) => roomStateEqual(prev, next) ? prev : next);
|
|
2811
2831
|
}, [argsKey, toRooms, debug]);
|
|
2812
2832
|
useEffect3(() => {
|
|
@@ -2936,6 +2956,7 @@ function buildSocketedRoute(options) {
|
|
|
2936
2956
|
}
|
|
2937
2957
|
const nextRoomState = roomsFromData(
|
|
2938
2958
|
next,
|
|
2959
|
+
useArgs,
|
|
2939
2960
|
toRooms
|
|
2940
2961
|
);
|
|
2941
2962
|
setRoomState(
|