gemi 0.33.0 → 0.33.2
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryResource.d.ts","sourceRoot":"","sources":["../../client/QueryResource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,KAAK,KAAK,GAAG;IACX,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,EAAE,GAAG,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,qBAAa,aAAa;IACxB,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;IACnC,aAAa,cAAqB;IAClC,eAAe,sBAA6B;IAC5C,GAAG,EAAE,MAAM,CAAC;gBAEA,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAkB1D,UAAU,CAAC,UAAU,EAAE,MAAM;
|
|
1
|
+
{"version":3,"file":"QueryResource.d.ts","sourceRoot":"","sources":["../../client/QueryResource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,KAAK,KAAK,GAAG;IACX,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,EAAE,GAAG,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,qBAAa,aAAa;IACxB,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;IACnC,aAAa,cAAqB;IAClC,eAAe,sBAA6B;IAC5C,GAAG,EAAE,MAAM,CAAC;gBAEA,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAkB1D,UAAU,CAAC,UAAU,EAAE,MAAM;IA8B7B,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,GAAE,CAAC,IAAI,EAAE,GAAG,KAAK,GAAoB;IAmClE,OAAO,CAAC,UAAU,EAAE,MAAM;YAIZ,cAAc;CAgE7B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSignOut.d.ts","sourceRoot":"","sources":["../../../client/auth/useSignOut.ts"],"names":[],"mappings":"AAGA,UAAU,cAAc;IACtB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;CACxB;AAMD,wBAAgB,UAAU,CAAC,IAAI,GAAE,cAA4B;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"useSignOut.d.ts","sourceRoot":"","sources":["../../../client/auth/useSignOut.ts"],"names":[],"mappings":"AAGA,UAAU,cAAc;IACtB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;CACxB;AAMD,wBAAgB,UAAU,CAAC,IAAI,GAAE,cAA4B;;;;;;;;;;EAY5D"}
|
package/dist/client/index.js
CHANGED
|
@@ -122,7 +122,7 @@ class QueryResource {
|
|
|
122
122
|
store.set(variantKey, {
|
|
123
123
|
loading: true,
|
|
124
124
|
data: previousState == null ? void 0 : previousState.data,
|
|
125
|
-
error: previousState == null ? void 0 : previousState.
|
|
125
|
+
error: previousState == null ? void 0 : previousState.error,
|
|
126
126
|
version: previousState == null ? void 0 : previousState.version
|
|
127
127
|
});
|
|
128
128
|
}
|
|
@@ -144,6 +144,7 @@ class QueryResource {
|
|
|
144
144
|
version: previousState == null ? void 0 : previousState.version
|
|
145
145
|
})
|
|
146
146
|
);
|
|
147
|
+
return;
|
|
147
148
|
}
|
|
148
149
|
if (response.ok) {
|
|
149
150
|
this.store.next(
|
|
@@ -247,7 +248,8 @@ function useQuery(url, ...args) {
|
|
|
247
248
|
const options = { ...defaultOptions$1, ..._options };
|
|
248
249
|
const config = { ...defaultConfig, ..._config };
|
|
249
250
|
const params = "params" in options ? { ..._params, ...options.params } : _params;
|
|
250
|
-
const
|
|
251
|
+
const paramsKey = JSON.stringify(params);
|
|
252
|
+
const paramsRef = useRef(paramsKey);
|
|
251
253
|
const search = "search" in options ? options.search ?? {} : {};
|
|
252
254
|
const { getResource } = useContext(QueryManagerContext);
|
|
253
255
|
const normalPath = applyParams$1(url, params);
|
|
@@ -261,6 +263,8 @@ function useQuery(url, ...args) {
|
|
|
261
263
|
const [resource, setResource] = useState(
|
|
262
264
|
() => getResource(normalPath, fallbackData)
|
|
263
265
|
);
|
|
266
|
+
const configRef = useRef(config);
|
|
267
|
+
configRef.current = config;
|
|
264
268
|
const refreshIntervalRef = useRef(
|
|
265
269
|
null
|
|
266
270
|
);
|
|
@@ -271,6 +275,7 @@ function useQuery(url, ...args) {
|
|
|
271
275
|
null
|
|
272
276
|
);
|
|
273
277
|
const refetchUntilDurationRef = useRef(0);
|
|
278
|
+
const prefetchedRef = useRef(false);
|
|
274
279
|
const [state, setState] = useState(() => {
|
|
275
280
|
if (lazy2) {
|
|
276
281
|
return { loading: false, data: null, error: null, version: 0 };
|
|
@@ -278,35 +283,34 @@ function useQuery(url, ...args) {
|
|
|
278
283
|
return resource.getVariant(variantKey);
|
|
279
284
|
});
|
|
280
285
|
const retry = useCallback(
|
|
281
|
-
(
|
|
282
|
-
if (!retryingMap.current.get(
|
|
283
|
-
if (
|
|
284
|
-
retryingMap.current.set(
|
|
286
|
+
(vk) => {
|
|
287
|
+
if (!retryingMap.current.get(vk)) {
|
|
288
|
+
if (configRef.current.debug) console.log("retrying", vk);
|
|
289
|
+
retryingMap.current.set(vk, true);
|
|
285
290
|
retryIntervalRef.current = setTimeout(() => {
|
|
286
|
-
resource.getVariant(
|
|
287
|
-
retryingMap.current.set(
|
|
288
|
-
},
|
|
291
|
+
resource.getVariant(vk);
|
|
292
|
+
retryingMap.current.set(vk, false);
|
|
293
|
+
}, configRef.current.retryIntervalOnError);
|
|
289
294
|
}
|
|
290
295
|
},
|
|
291
|
-
[
|
|
296
|
+
[resource]
|
|
292
297
|
);
|
|
293
298
|
useEffect(() => {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
setResource(getResource(applyParams$1(url, params)));
|
|
299
|
+
if (paramsKey !== paramsRef.current) {
|
|
300
|
+
setResource(getResource(normalPath));
|
|
297
301
|
if (fetchedRef.current) {
|
|
298
302
|
setState(resource.getVariant(variantKey));
|
|
299
303
|
}
|
|
300
|
-
paramsRef.current =
|
|
304
|
+
paramsRef.current = paramsKey;
|
|
301
305
|
}
|
|
302
|
-
}, [
|
|
306
|
+
}, [paramsKey, normalPath, variantKey, getResource, resource]);
|
|
303
307
|
const handleReload = useCallback(() => {
|
|
304
|
-
if (
|
|
308
|
+
if (configRef.current.debug) {
|
|
305
309
|
console.log("Reloading query for", variantKey);
|
|
306
310
|
}
|
|
307
311
|
const data = resource.getVariant(variantKey).data;
|
|
308
|
-
resource.mutate
|
|
309
|
-
}, [variantKey, resource
|
|
312
|
+
resource.mutate(variantKey, () => data);
|
|
313
|
+
}, [variantKey, resource]);
|
|
310
314
|
useEffect(() => {
|
|
311
315
|
if (!fetchedRef.current) return;
|
|
312
316
|
refreshIntervalRef.current = setInterval(() => {
|
|
@@ -330,14 +334,15 @@ function useQuery(url, ...args) {
|
|
|
330
334
|
}, [handleReload]);
|
|
331
335
|
const handleStateUpdate = useCallback(
|
|
332
336
|
(nextState) => {
|
|
333
|
-
|
|
337
|
+
const cfg = configRef.current;
|
|
338
|
+
if (cfg.debug) {
|
|
334
339
|
console.log("state updating due to url update", variantKey);
|
|
335
340
|
console.log(nextState);
|
|
336
341
|
}
|
|
337
342
|
if (nextState.error) {
|
|
338
343
|
retry(variantKey);
|
|
339
344
|
}
|
|
340
|
-
if (
|
|
345
|
+
if (cfg.keepPreviousData) {
|
|
341
346
|
if (nextState.loading) {
|
|
342
347
|
setState((s) => ({ ...s, loading: true }));
|
|
343
348
|
} else {
|
|
@@ -346,8 +351,8 @@ function useQuery(url, ...args) {
|
|
|
346
351
|
} else {
|
|
347
352
|
setState(nextState);
|
|
348
353
|
}
|
|
349
|
-
if (
|
|
350
|
-
const nextDuration =
|
|
354
|
+
if (cfg.refetchUntil && !nextState.loading && nextState.data && !nextState.error) {
|
|
355
|
+
const nextDuration = cfg.refetchUntil(
|
|
351
356
|
nextState.data,
|
|
352
357
|
refetchUntilDurationRef.current
|
|
353
358
|
);
|
|
@@ -361,13 +366,13 @@ function useQuery(url, ...args) {
|
|
|
361
366
|
}
|
|
362
367
|
}
|
|
363
368
|
},
|
|
364
|
-
[variantKey,
|
|
369
|
+
[variantKey, retry, resource]
|
|
365
370
|
);
|
|
366
371
|
useEffect(() => {
|
|
367
372
|
if (fetchedRef.current) {
|
|
368
373
|
handleStateUpdate(resource.getVariant(variantKey));
|
|
369
374
|
}
|
|
370
|
-
const unsub = resource.store.subscribe
|
|
375
|
+
const unsub = resource.store.subscribe((store) => {
|
|
371
376
|
const variant = store.get(variantKey);
|
|
372
377
|
if (variant) {
|
|
373
378
|
handleStateUpdate(variant);
|
|
@@ -375,19 +380,37 @@ function useQuery(url, ...args) {
|
|
|
375
380
|
});
|
|
376
381
|
return () => {
|
|
377
382
|
unsub();
|
|
378
|
-
|
|
383
|
+
clearTimeout(retryIntervalRef.current);
|
|
379
384
|
if (refetchUntilTimerRef.current) {
|
|
380
385
|
clearTimeout(refetchUntilTimerRef.current);
|
|
381
386
|
}
|
|
382
387
|
};
|
|
383
388
|
}, [variantKey, resource, handleStateUpdate]);
|
|
389
|
+
const trigger = useCallback(() => {
|
|
390
|
+
fetchedRef.current = true;
|
|
391
|
+
const store = resource.store.getValue();
|
|
392
|
+
const variant = store.get(variantKey);
|
|
393
|
+
if (!variant || !variant.loading && !variant.data) {
|
|
394
|
+
resource.refetch(variantKey);
|
|
395
|
+
}
|
|
396
|
+
}, [resource, variantKey]);
|
|
397
|
+
const prefetch = useCallback(() => {
|
|
398
|
+
if (prefetchedRef.current) return;
|
|
399
|
+
prefetchedRef.current = true;
|
|
400
|
+
fetchedRef.current = true;
|
|
401
|
+
resource.refetch(variantKey);
|
|
402
|
+
}, [resource, variantKey]);
|
|
403
|
+
useCallback(() => {
|
|
404
|
+
fetchedRef.current = true;
|
|
405
|
+
resource.refetch(variantKey);
|
|
406
|
+
}, [resource, variantKey]);
|
|
384
407
|
function mutate(fn) {
|
|
385
408
|
if (!fn) {
|
|
386
409
|
fetchedRef.current = true;
|
|
387
410
|
resource.refetch(variantKey);
|
|
388
411
|
return;
|
|
389
412
|
}
|
|
390
|
-
return resource.mutate
|
|
413
|
+
return resource.mutate(variantKey, (data) => {
|
|
391
414
|
if (data === void 0 || data === null) {
|
|
392
415
|
console.warn("Mutate function called before the query.");
|
|
393
416
|
return;
|
|
@@ -422,7 +445,8 @@ function useQuery(url, ...args) {
|
|
|
422
445
|
loading: (state == null ? void 0 : state.loading) ?? true,
|
|
423
446
|
error: state == null ? void 0 : state.error,
|
|
424
447
|
mutate,
|
|
425
|
-
|
|
448
|
+
trigger,
|
|
449
|
+
prefetch,
|
|
426
450
|
version: state == null ? void 0 : state.version
|
|
427
451
|
};
|
|
428
452
|
}
|
|
@@ -2545,13 +2569,13 @@ const Link = memo((props) => {
|
|
|
2545
2569
|
);
|
|
2546
2570
|
});
|
|
2547
2571
|
const Redirect = (props) => {
|
|
2548
|
-
const { href, params = {}, search = {}, action } = props;
|
|
2572
|
+
const { href, params = {}, search = {}, action = "replace" } = props;
|
|
2549
2573
|
const { push, replace } = useNavigate();
|
|
2550
2574
|
useEffect(() => {
|
|
2551
|
-
if (action === "
|
|
2552
|
-
push(href, { params, search });
|
|
2553
|
-
} else {
|
|
2575
|
+
if (action === "replace") {
|
|
2554
2576
|
replace(href, { params, search });
|
|
2577
|
+
} else {
|
|
2578
|
+
push(href, { params, search });
|
|
2555
2579
|
}
|
|
2556
2580
|
}, [replace, action, push, params, search, href]);
|
|
2557
2581
|
return /* @__PURE__ */ jsx(Fragment, {});
|
|
@@ -32649,15 +32673,14 @@ const defaultArgs$1 = {
|
|
|
32649
32673
|
}
|
|
32650
32674
|
};
|
|
32651
32675
|
function useSignOut(args = defaultArgs$1) {
|
|
32652
|
-
const
|
|
32653
|
-
return
|
|
32654
|
-
"POST",
|
|
32676
|
+
const mutator = useMutate();
|
|
32677
|
+
return usePost(
|
|
32655
32678
|
"/auth/sign-out",
|
|
32656
32679
|
{},
|
|
32657
32680
|
{
|
|
32658
32681
|
onSuccess: () => {
|
|
32659
32682
|
args.onSuccess();
|
|
32660
|
-
|
|
32683
|
+
mutator({ path: "/auth/me" });
|
|
32661
32684
|
}
|
|
32662
32685
|
}
|
|
32663
32686
|
);
|