gemi 0.21.1 → 0.23.0

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":"HttpReload.d.ts","sourceRoot":"","sources":["../../client/HttpReload.tsx"],"names":[],"mappings":"AAOA,eAAO,MAAM,UAAU,mCAyCtB,CAAC"}
1
+ {"version":3,"file":"HttpReload.d.ts","sourceRoot":"","sources":["../../client/HttpReload.tsx"],"names":[],"mappings":"AAOA,eAAO,MAAM,UAAU,mCA2CtB,CAAC"}
@@ -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;CACZ,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;IACZ,KAAK,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAC/B,IAAI,EAAE,MAAM,CAAC;gBAGX,GAAG,EAAE,MAAM,EACX,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,EACtC,KAAK,EAAE,OAAO,UAAU,CAAC,KAAK,EAC9B,IAAI,EAAE,MAAM;IAqBd,UAAU,CAAC,UAAU,EAAE,MAAM;IA+B7B,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,GAAG;YAoBnC,cAAc;CAgD7B"}
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;CACZ,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;IACZ,KAAK,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAC/B,IAAI,EAAE,MAAM,CAAC;gBAGX,GAAG,EAAE,MAAM,EACX,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,EACtC,KAAK,EAAE,OAAO,UAAU,CAAC,KAAK,EAC9B,IAAI,EAAE,MAAM;IAqBd,UAAU,CAAC,UAAU,EAAE,MAAM;IA+B7B,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,GAAG;YAqBnC,cAAc;CAsD7B"}
@@ -10,7 +10,7 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
10
10
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
11
11
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
12
12
  var _i, _n, _t, _e, _s, _l, _o, _d, _p, _g, _H_instances, r_fn, R_fn, b_fn, u_fn, m_fn, a_fn, P_fn, E_fn, S_fn, O_fn, k_fn, x_fn, h_fn, f_fn, T_fn, A_fn, y_fn, w_fn, c_fn, C_fn, _a, _i2, _n2, _t2, _e2, _s2, _l2, _b;
13
- import require$$1, { createContext, useRef, useContext, useState, useEffect, useCallback, useSyncExternalStore, useMemo, memo, lazy, StrictMode, useTransition, Component, createElement, isValidElement, Fragment as Fragment$1 } from "react";
13
+ import require$$1, { createContext, useRef, useContext, useState, useCallback, useEffect, useSyncExternalStore, useMemo, memo, lazy, StrictMode, useTransition, Component, createElement, isValidElement, Fragment as Fragment$1 } from "react";
14
14
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
15
15
  import require$$2, { createPortal } from "react-dom";
16
16
  class Subject {
@@ -83,14 +83,6 @@ class QueryResource {
83
83
  return store.get(variantKey);
84
84
  }
85
85
  mutate(variantKey, fn) {
86
- const store = this.store.getValue();
87
- const state = store.get(variantKey);
88
- const data = fn(state.data);
89
- this.staleVariants.add(variantKey);
90
- this.store.next(
91
- store.set(variantKey, { loading: false, data, error: null })
92
- );
93
- this.resolveVariant(variantKey);
94
86
  const cacheKey = [window.location.origin, this.key, variantKey].filter((s) => s.length > 0).join("?");
95
87
  try {
96
88
  if (caches) {
@@ -98,8 +90,16 @@ class QueryResource {
98
90
  }
99
91
  } catch (err) {
100
92
  }
93
+ const store = this.store.getValue();
94
+ const state = store.get(variantKey);
95
+ const data = fn(state.data);
96
+ this.staleVariants.add(variantKey);
97
+ this.store.next(
98
+ store.set(variantKey, { loading: false, data, error: null })
99
+ );
100
+ this.resolveVariant(variantKey, false, false);
101
101
  }
102
- async resolveVariant(variantKey, silent = false) {
102
+ async resolveVariant(variantKey, silent = false, cache = true) {
103
103
  if (typeof window === "undefined") {
104
104
  return;
105
105
  }
@@ -113,7 +113,9 @@ class QueryResource {
113
113
  });
114
114
  }
115
115
  const fullUrl = [this.key, variantKey].filter((s) => s.length).join("?");
116
- const response = await this.fetch(`${this.host}/api${fullUrl}`);
116
+ const response = await this.fetch(`${this.host}/api${fullUrl}`, {
117
+ cache: cache ? "default" : "reload"
118
+ });
117
119
  let data = null;
118
120
  try {
119
121
  data = await response.json();
@@ -247,16 +249,19 @@ function useQuery(url, ...args) {
247
249
  const retryIntervalRef = useRef(null);
248
250
  const retryingMap = useRef(/* @__PURE__ */ new Map());
249
251
  const [state, setState] = useState(() => resource.getVariant(variantKey));
250
- const retry = (variantKey2) => {
251
- if (!retryingMap.current.get(variantKey2)) {
252
- if (config.debug) console.log("retrying", variantKey2);
253
- retryingMap.current.set(variantKey2, true);
254
- retryIntervalRef.current = setTimeout(() => {
255
- resource.getVariant(variantKey2);
256
- retryingMap.current.set(variantKey2, false);
257
- }, config.retryIntervalOnError);
258
- }
259
- };
252
+ const retry = useCallback(
253
+ (variantKey2) => {
254
+ if (!retryingMap.current.get(variantKey2)) {
255
+ if (config.debug) console.log("retrying", variantKey2);
256
+ retryingMap.current.set(variantKey2, true);
257
+ retryIntervalRef.current = setTimeout(() => {
258
+ resource.getVariant(variantKey2);
259
+ retryingMap.current.set(variantKey2, false);
260
+ }, config.retryIntervalOnError);
261
+ }
262
+ },
263
+ [config.debug, config.retryIntervalOnError, resource]
264
+ );
260
265
  useEffect(() => {
261
266
  const key = JSON.stringify(params);
262
267
  if (key !== paramsRef.current) {
@@ -264,7 +269,24 @@ function useQuery(url, ...args) {
264
269
  setState(resource.getVariant(variantKey));
265
270
  paramsRef.current = key;
266
271
  }
267
- }, [params]);
272
+ }, [params, url, variantKey, getResource, resource]);
273
+ const handleReload = useCallback(() => {
274
+ if (config.debug) {
275
+ console.log("Reloading query for", variantKey);
276
+ }
277
+ const data = resource.getVariant(variantKey).data;
278
+ resource.mutate.call(resource, variantKey, () => data);
279
+ }, [variantKey, resource, config.debug]);
280
+ useEffect(() => {
281
+ if (import.meta.hot) {
282
+ import.meta.hot.on("http-reload", handleReload);
283
+ }
284
+ return () => {
285
+ if (import.meta.hot) {
286
+ import.meta.hot.off("http-reload", handleReload);
287
+ }
288
+ };
289
+ }, [handleReload]);
268
290
  const handleStateUpdate = useCallback(
269
291
  (nextState) => {
270
292
  if (config.debug) {
@@ -284,7 +306,7 @@ function useQuery(url, ...args) {
284
306
  setState(nextState);
285
307
  }
286
308
  },
287
- [variantKey]
309
+ [variantKey, config.keepPreviousData, config.debug, retry]
288
310
  );
289
311
  useEffect(() => {
290
312
  handleStateUpdate(resource.getVariant(variantKey));
@@ -295,7 +317,7 @@ function useQuery(url, ...args) {
295
317
  unsub();
296
318
  clearInterval(retryIntervalRef.current);
297
319
  };
298
- }, [variantKey, resource]);
320
+ }, [variantKey, resource, handleStateUpdate]);
299
321
  function mutate(fn) {
300
322
  return resource.mutate.call(resource, variantKey, (data) => {
301
323
  if (data === void 0 || data === null) {
@@ -1698,18 +1720,12 @@ function useRoute() {
1698
1720
  }
1699
1721
  const HttpReload = () => {
1700
1722
  const { replace } = useNavigate();
1701
- const searchParams = useSearchParams();
1723
+ useSearchParams();
1702
1724
  const { pathname } = useRoute();
1703
- const params = useParams();
1725
+ useParams();
1704
1726
  const [reloading, setReloading] = useState(false);
1705
1727
  const handleReload = () => {
1706
1728
  setReloading(true);
1707
- replace(pathname, {
1708
- params,
1709
- search: searchParams.toJSON()
1710
- }).catch(console.log).finally(() => {
1711
- setReloading(false);
1712
- });
1713
1729
  };
1714
1730
  useEffect(() => {
1715
1731
  if (import.meta.hot) {
@@ -31991,19 +32007,19 @@ const Routes = (props) => {
31991
32007
  const { routerSubject, fetchRouteCSS } = useContext(ClientRouterContext);
31992
32008
  const [transitionPath, setTransitionPath] = useState([
31993
32009
  null,
31994
- routerSubject.getValue().pathname
32010
+ routerSubject == null ? void 0 : routerSubject.getValue().pathname
31995
32011
  ]);
31996
32012
  const { breadcrumbs, pageData, i18n, prefetchedData } = useContext(ServerDataContext);
31997
32013
  const [routeState, setRouteState] = useState({
31998
- params: routerSubject.getValue().params,
31999
- search: routerSubject.getValue().search,
32000
- pathname: routerSubject.getValue().pathname,
32001
- views: routerSubject.getValue().views,
32014
+ params: routerSubject == null ? void 0 : routerSubject.getValue().params,
32015
+ search: routerSubject == null ? void 0 : routerSubject.getValue().search,
32016
+ pathname: routerSubject == null ? void 0 : routerSubject.getValue().pathname,
32017
+ views: routerSubject == null ? void 0 : routerSubject.getValue().views,
32002
32018
  action: null,
32003
- hash: routerSubject.getValue().hash,
32004
- state: routerSubject.getValue().state,
32005
- routePath: routerSubject.getValue().routePath,
32006
- locale: routerSubject.getValue().locale,
32019
+ hash: routerSubject == null ? void 0 : routerSubject.getValue().hash,
32020
+ state: routerSubject == null ? void 0 : routerSubject.getValue().state,
32021
+ routePath: routerSubject == null ? void 0 : routerSubject.getValue().routePath,
32022
+ locale: routerSubject == null ? void 0 : routerSubject.getValue().locale,
32007
32023
  breadcrumbs,
32008
32024
  data: pageData,
32009
32025
  i18n,
@@ -32011,7 +32027,7 @@ const Routes = (props) => {
32011
32027
  });
32012
32028
  const { replace } = useNavigate();
32013
32029
  useEffect(() => {
32014
- return routerSubject.subscribe(async (routerState) => {
32030
+ return routerSubject == null ? void 0 : routerSubject.subscribe(async (routerState) => {
32015
32031
  const { pathname, search, state, views } = routerState;
32016
32032
  setTransitionPath((current) => {
32017
32033
  const [, prevTarget] = current;