gomtm 0.0.344 → 0.0.345

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,10 +1,10 @@
1
1
  import { PropsWithChildren } from "react";
2
- export declare function PrefetchConnectInfiniteQuery(props: {
2
+ export declare function PrefetchConnectQuery(props: {
3
3
  svc: string;
4
4
  method: string;
5
5
  input?: any;
6
6
  } & PropsWithChildren): Promise<import("react").JSX.Element>;
7
- export declare function PrefetchConnectQuery(props: {
7
+ export declare function PrefetchConnectInfiniteQuery(props: {
8
8
  svc: string;
9
9
  method: string;
10
10
  input?: any;
@@ -37,34 +37,34 @@ var __async = (__this, __arguments, generator) => {
37
37
  import { jsx } from "react/jsx-runtime";
38
38
  import { HydrationBoundary, QueryClient, dehydrate } from "@tanstack/react-query";
39
39
  import { createInfiniteQueryKey, createQueryKey, goMtmQueryFn } from "../mtmFetcher";
40
- function PrefetchConnectInfiniteQuery(props) {
40
+ function PrefetchConnectQuery(props) {
41
41
  return __async(this, null, function* () {
42
42
  const { svc, method, input, children } = props;
43
43
  const queryClient = new QueryClient();
44
- const queryKey = createInfiniteQueryKey(svc, method, input);
44
+ const queryKey = createQueryKey(svc, method, input);
45
45
  const data = yield goMtmQueryFn({ svc, method, input });
46
- yield queryClient.prefetchInfiniteQuery({
46
+ yield queryClient.prefetchQuery({
47
47
  queryKey,
48
48
  queryFn: (k) => __async(this, null, function* () {
49
49
  return data;
50
- }),
51
- initialPageParam: __spreadValues({}, input)
50
+ })
52
51
  });
53
52
  const dehydratedState = dehydrate(queryClient);
54
53
  return /* @__PURE__ */ jsx(HydrationBoundary, { state: dehydratedState, children });
55
54
  });
56
55
  }
57
- function PrefetchConnectQuery(props) {
56
+ function PrefetchConnectInfiniteQuery(props) {
58
57
  return __async(this, null, function* () {
59
58
  const { svc, method, input, children } = props;
60
59
  const queryClient = new QueryClient();
61
- const queryKey = createQueryKey(svc, method, input);
60
+ const queryKey = createInfiniteQueryKey(svc, method, input);
62
61
  const data = yield goMtmQueryFn({ svc, method, input });
63
- yield queryClient.prefetchQuery({
62
+ yield queryClient.prefetchInfiniteQuery({
64
63
  queryKey,
65
64
  queryFn: (k) => __async(this, null, function* () {
66
65
  return data;
67
- })
66
+ }),
67
+ initialPageParam: __spreadValues({}, input)
68
68
  });
69
69
  const dehydratedState = dehydrate(queryClient);
70
70
  return /* @__PURE__ */ jsx(HydrationBoundary, { state: dehydratedState, children });
@@ -0,0 +1,17 @@
1
+ /// <reference types="react" />
2
+ import { PlainMessage } from "@bufbuild/protobuf";
3
+ import { CurdView } from "../gomtmpb/mtm/sppb/mtm_pb";
4
+ interface CurdViewProps {
5
+ backendUrl?: string;
6
+ curdView: PlainMessage<CurdView>;
7
+ }
8
+ export interface ListViewState extends CurdViewProps {
9
+ }
10
+ export declare const curdViewContext: import("react").Context<import("zustand").StoreApi<ListViewState> | null>;
11
+ type CurdViewProviderProps = React.PropsWithChildren<CurdViewProps>;
12
+ export declare const CurdViewProvider: (props: CurdViewProviderProps) => import("react").JSX.Element;
13
+ export declare function useCurdView<T>(selector: (state: ListViewState) => T): T;
14
+ export declare const CurdViewView: (props: {
15
+ name: string;
16
+ }) => import("react").JSX.Element | null;
17
+ export {};
@@ -0,0 +1,100 @@
1
+ "use client";
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __spreadValues = (a, b) => {
10
+ for (var prop in b || (b = {}))
11
+ if (__hasOwnProp.call(b, prop))
12
+ __defNormalProp(a, prop, b[prop]);
13
+ if (__getOwnPropSymbols)
14
+ for (var prop of __getOwnPropSymbols(b)) {
15
+ if (__propIsEnum.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ }
18
+ return a;
19
+ };
20
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
+ var __objRest = (source, exclude) => {
22
+ var target = {};
23
+ for (var prop in source)
24
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
25
+ target[prop] = source[prop];
26
+ if (source != null && __getOwnPropSymbols)
27
+ for (var prop of __getOwnPropSymbols(source)) {
28
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
29
+ target[prop] = source[prop];
30
+ }
31
+ return target;
32
+ };
33
+ import { jsx } from "react/jsx-runtime";
34
+ import { toPlainMessage } from "@bufbuild/protobuf";
35
+ import { createContext, useContext, useRef } from "react";
36
+ import { createStore, useStore } from "zustand";
37
+ import { useGomtmSuspenseQuery } from "../gomtmQuery";
38
+ import { curdViewGet } from "../gomtmpb/mtm/sppb/mtm-MtmService_connectquery";
39
+ import { CurdView } from "../gomtmpb/mtm/sppb/mtm_pb";
40
+ import { CommonListViewV2 } from "./listview/CommonListViewV2";
41
+ import { ListViewStoreProvider } from "./listview/list-store";
42
+ const createListviewStore = (initProps) => {
43
+ const DEFAULT_PROPS = {
44
+ backendUrl: "",
45
+ curdView: toPlainMessage(new CurdView())
46
+ };
47
+ return createStore()((set, get) => __spreadProps(__spreadValues(__spreadValues({}, DEFAULT_PROPS), initProps), {
48
+ openRemove: false,
49
+ nextPage: () => {
50
+ }
51
+ }));
52
+ };
53
+ const curdViewContext = createContext(null);
54
+ const CurdViewProvider = (props) => {
55
+ const _a = props, { children } = _a, etc = __objRest(_a, ["children"]);
56
+ const storeRef = useRef();
57
+ if (!storeRef.current) {
58
+ storeRef.current = createListviewStore(props);
59
+ }
60
+ return /* @__PURE__ */ jsx(curdViewContext.Provider, { value: storeRef.current, children });
61
+ };
62
+ function useCurdView(selector) {
63
+ const store = useContext(curdViewContext);
64
+ if (!store)
65
+ throw new Error("useCurd Missing CurdViewProvider in the tree");
66
+ return useStore(store, selector);
67
+ }
68
+ const CurdViewView = (props) => {
69
+ const { name } = props;
70
+ const query = useGomtmSuspenseQuery(curdViewGet.service.typeName, curdViewGet.name, {
71
+ name
72
+ });
73
+ if (!query.data) {
74
+ return null;
75
+ }
76
+ switch (query.data.item.case) {
77
+ case "error":
78
+ return /* @__PURE__ */ jsx("div", { children: "error222" });
79
+ default:
80
+ if (!query.data.item.value) {
81
+ return /* @__PURE__ */ jsx("div", { children: "missing curd data222" });
82
+ }
83
+ const curdViewData = query.data.item.value;
84
+ return /* @__PURE__ */ jsx("div", { className: "bg-red-100 p-2", children: /* @__PURE__ */ jsx(CurdViewProvider, { curdView: curdViewData, children: /* @__PURE__ */ jsx(
85
+ ListViewStoreProvider,
86
+ {
87
+ slugPath: "/post",
88
+ svc: curdViewData.svcName,
89
+ methodList: curdViewData.methodList,
90
+ children: /* @__PURE__ */ jsx(CommonListViewV2, {})
91
+ }
92
+ ) }) });
93
+ }
94
+ };
95
+ export {
96
+ CurdViewProvider,
97
+ CurdViewView,
98
+ curdViewContext,
99
+ useCurdView
100
+ };
@@ -0,0 +1,4 @@
1
+ import { PropsWithChildren } from "react";
2
+ export declare const CurdViewSS: (props: {
3
+ name: string;
4
+ } & PropsWithChildren) => import("react").JSX.Element;
@@ -0,0 +1,10 @@
1
+ "use client";
2
+ import { Fragment, jsx } from "react/jsx-runtime";
3
+ import { CurdViewView } from "./CurdView";
4
+ const CurdViewSS = (props) => {
5
+ const { name } = props;
6
+ return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(CurdViewView, { name }) });
7
+ };
8
+ export {
9
+ CurdViewSS
10
+ };
@@ -2,14 +2,11 @@
2
2
  import { jsx, jsxs } from "react/jsx-runtime";
3
3
  import { Icons } from "mtxuilib/icons/icons";
4
4
  import { cn } from "mtxuilib/lib/utils";
5
- import { Dialog, DialogContent, DialogTitle } from "mtxuilib/ui/dialog";
6
5
  import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger } from "mtxuilib/ui/dropdown-menu";
7
6
  import { Pagination, PaginationContent, PaginationEllipsis, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious } from "mtxuilib/ui/pagination";
8
7
  import { MtButton } from "mtxuilib/ui/ui-mt/Button";
9
- import { Suspense, lazy, useMemo, useState } from "react";
10
- import { useHotkeys } from "react-hotkeys-hook";
8
+ import { Suspense, lazy } from "react";
11
9
  import { MtmErrorView } from "../../components/MtmErrorView";
12
- import { HOTKEY_Listview_Switchlayout } from "../../consts";
13
10
  import { useGomtmSuspenseInfiniteQuery } from "../../gomtmQuery";
14
11
  import { CurdCreatePanelTriggerButton } from "../create/CurdCreatePanel";
15
12
  import { CommontListResView } from "../list-item/ListViewLayoutRender";
@@ -68,39 +65,6 @@ const ListViewActions = () => {
68
65
  ] })
69
66
  ] });
70
67
  };
71
- const ListViewLayout = (props) => {
72
- const layout = useListview((x) => x.layout);
73
- const { children } = props;
74
- const Layout = useMemo(() => {
75
- switch (layout) {
76
- case "demo":
77
- return LzListViewLayoutDemo;
78
- default:
79
- return LzListViewLayoutDefault;
80
- }
81
- }, [layout]);
82
- return /* @__PURE__ */ jsx(Layout, { children });
83
- };
84
- const ListViewLayoutSwitch = () => {
85
- const layout = useListview((x) => x.layout);
86
- const setLayout = useListview((x) => x.setLayout);
87
- const [open, setOpen] = useState(false);
88
- useHotkeys(HOTKEY_Listview_Switchlayout, () => {
89
- setOpen((pre) => !pre);
90
- }, [open, setOpen]);
91
- return /* @__PURE__ */ jsx(Dialog, { open, onOpenChange: setOpen, children: /* @__PURE__ */ jsxs(DialogContent, { children: [
92
- /* @__PURE__ */ jsxs(DialogTitle, { children: [
93
- "LayoutSwitch,",
94
- layout
95
- ] }),
96
- /* @__PURE__ */ jsx("div", { className: "flex gap-2 bg-red-100 p-2", children: ALL_Layouts.map((layout2) => {
97
- return /* @__PURE__ */ jsx(MtButton, { onClick: () => {
98
- setLayout(layout2);
99
- setOpen(false);
100
- }, children: layout2 }, layout2);
101
- }) })
102
- ] }) });
103
- };
104
68
  export {
105
69
  CommonListView,
106
70
  ListViewActions,
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ export declare const LzListViewLayoutDemo: import("react").LazyExoticComponent<typeof import("./listview-layouts/listviewlayout-demo").default>;
3
+ export declare const LzListViewLayoutDefault: import("react").LazyExoticComponent<typeof import("./listview-layouts/default").default>;
4
+ export declare function CommonListViewV2(): import("react").JSX.Element | null;
5
+ export declare const ListViewActions: () => import("react").JSX.Element;
@@ -0,0 +1,66 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import { Icons } from "mtxuilib/icons/icons";
4
+ import { cn } from "mtxuilib/lib/utils";
5
+ import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger } from "mtxuilib/ui/dropdown-menu";
6
+ import { Pagination, PaginationContent, PaginationEllipsis, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious } from "mtxuilib/ui/pagination";
7
+ import { MtButton } from "mtxuilib/ui/ui-mt/Button";
8
+ import { Suspense, lazy } from "react";
9
+ import { MtmErrorView } from "../../components/MtmErrorView";
10
+ import { useGomtmSuspenseInfiniteQuery } from "../../gomtmQuery";
11
+ import { useCurdView } from "../CurdView";
12
+ import { CommontListResView } from "../list-item/ListViewLayoutRender";
13
+ const LzListViewLayoutDemo = lazy(() => import("./listview-layouts/listviewlayout-demo"));
14
+ const LzListViewLayoutDefault = lazy(() => import("./listview-layouts/default"));
15
+ function CommonListViewV2() {
16
+ const curdView = useCurdView((x) => x.curdView);
17
+ const listQuery = useGomtmSuspenseInfiniteQuery(curdView.svcName, curdView == null ? void 0 : curdView.methodList, {});
18
+ if (!(listQuery == null ? void 0 : listQuery.data)) {
19
+ return null;
20
+ }
21
+ return /* @__PURE__ */ jsxs("div", { className: "relative w-full", children: [
22
+ /* @__PURE__ */ jsx(
23
+ "div",
24
+ {
25
+ className: cn(
26
+ "w-full"
27
+ // 滚动设置
28
+ // " max-h-[700px] overflow-y-auto"
29
+ ),
30
+ children: listQuery.data.pages.map((page, i) => {
31
+ if (page.errCode) {
32
+ return /* @__PURE__ */ jsx(MtmErrorView, { unaryError: page }, i);
33
+ } else {
34
+ return /* @__PURE__ */ jsx(CommontListResView, { data: page }, i);
35
+ }
36
+ })
37
+ }
38
+ ),
39
+ listQuery.data.pages && !!listQuery.data.pages.length && /* @__PURE__ */ jsx(Pagination, { children: /* @__PURE__ */ jsxs(PaginationContent, { children: [
40
+ /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(PaginationPrevious, { href: "#" }) }),
41
+ /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(PaginationLink, { href: "#", children: "1" }) }),
42
+ /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(PaginationLink, { href: "#", isActive: true, children: "2" }) }),
43
+ /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(PaginationLink, { href: "#", children: "3" }) }),
44
+ /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(PaginationEllipsis, {}) }),
45
+ /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(PaginationNext, { href: "#" }) })
46
+ ] }) }),
47
+ /* @__PURE__ */ jsx("div", { className: "absolute right-1 top-1" })
48
+ ] });
49
+ }
50
+ const ListViewActions = () => {
51
+ return /* @__PURE__ */ jsxs(DropdownMenu, { children: [
52
+ /* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsx(MtButton, { variant: "ghost", className: "m-0 flex h-10 w-10 items-center justify-center border p-0 shadow-sm backdrop-blur", children: /* @__PURE__ */ jsx(Icons.ellipsis, {}) }) }),
53
+ /* @__PURE__ */ jsxs(DropdownMenuContent, { className: "w-56", children: [
54
+ /* @__PURE__ */ jsx(DropdownMenuLabel, { children: "List \u64CD\u4F5C" }),
55
+ /* @__PURE__ */ jsx(DropdownMenuSeparator, {}),
56
+ /* @__PURE__ */ jsx(DropdownMenuGroup, { children: /* @__PURE__ */ jsx(Suspense, { children: /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: /* @__PURE__ */ jsx("div", { className: "bg-yellow-100 p-2" }) }) }) }),
57
+ /* @__PURE__ */ jsx(DropdownMenuSeparator, {})
58
+ ] })
59
+ ] });
60
+ };
61
+ export {
62
+ CommonListViewV2,
63
+ ListViewActions,
64
+ LzListViewLayoutDefault,
65
+ LzListViewLayoutDemo
66
+ };
@@ -10,7 +10,7 @@ const ListViewRender = (props) => {
10
10
  return /* @__PURE__ */ jsxs(Fragment, { children: [
11
11
  /* @__PURE__ */ jsx(CommonListView, {}),
12
12
  /* @__PURE__ */ jsxs(Suspense, { children: [
13
- /* @__PURE__ */ jsx(CurdCreatePanel, {}),
13
+ /* @__PURE__ */ jsx(CurdCreatePanel, { fullScreen: true }),
14
14
  /* @__PURE__ */ jsx(CurdEditPanel, { fullScreen: true }),
15
15
  /* @__PURE__ */ jsx(PanelRemove, {})
16
16
  ] }),
@@ -1,5 +1,7 @@
1
1
  import { Renderable } from 'mtxuilib/lib/render';
2
2
  import { ComponentProps, PropsWithChildren } from 'react';
3
+ import { PlainMessage } from '@bufbuild/protobuf';
4
+ import { CurdView } from '../../gomtmpb/mtm/sppb/mtm_pb';
3
5
  interface ListViewStateProps {
4
6
  backendUrl?: string;
5
7
  svc: string;
@@ -20,6 +22,7 @@ interface ListViewStateProps {
20
22
  editorComponentName?: string;
21
23
  createRender?: Renderable<any>;
22
24
  createComponentName?: string;
25
+ curdView?: PlainMessage<CurdView>;
23
26
  }
24
27
  export interface ListViewState extends ListViewStateProps {
25
28
  openRemove: boolean;
@@ -41,6 +44,6 @@ type BearProviderProps = React.PropsWithChildren<ListViewStateProps>;
41
44
  export declare const ListViewStoreProvider: (props: BearProviderProps) => import("react").JSX.Element;
42
45
  export declare const ListView: (props: Omit<ComponentProps<typeof ListViewStoreProvider>, 'backendUrl'> & PropsWithChildren) => import("react").JSX.Element;
43
46
  export declare function useListview<T>(selector: (state: ListViewState) => T): T;
44
- export declare const useCurdUpdateMutation: () => import("@tanstack/react-query").UseMutationResult<any, Error, any, unknown>;
45
- export declare const useCurdCreateMutation: () => import("@tanstack/react-query").UseMutationResult<any, Error, any, unknown>;
47
+ export declare const useCurdUpdateMutation: () => import("@tanstack/react-query").UseMutationResult<unknown, any, any, any>;
48
+ export declare const useCurdCreateMutation: () => import("@tanstack/react-query").UseMutationResult<unknown, any, any, any>;
46
49
  export {};
@@ -26,13 +26,23 @@ import { Dialog, DialogContent, DialogTitle } from "mtxuilib/ui/dialog";
26
26
  import { MtButton } from "mtxuilib/ui/ui-mt/Button";
27
27
  import { useCallback } from "react";
28
28
  import { useGomtmMutation } from "../../gomtmQuery";
29
+ import { createQueryKey } from "../../mtmFetcher";
29
30
  import { useListview } from "../listview/list-store";
30
31
  function useCurdRemove() {
31
32
  const svc = useListview((x) => x.svc);
32
33
  const openRemove = useListview((x) => x.openRemove);
33
34
  const setOpenRemove = useListview((x) => x.setOpenRemove);
34
35
  const methodDelete = useListview((x) => x.methodDelete);
35
- const mutation = useGomtmMutation(svc, methodDelete);
36
+ const methodList = useListview((x) => x.methodList);
37
+ const mutation = useGomtmMutation(svc, methodDelete, {
38
+ onSuccess(data, variables, context) {
39
+ console.log("remove sucess", data);
40
+ queryClient.invalidateQueries({
41
+ queryKey: createQueryKey(svc, methodList)
42
+ });
43
+ setOpenRemove(false);
44
+ }
45
+ });
36
46
  const activateItem = useListview((x) => x.activateItem);
37
47
  const router = useMtRouter();
38
48
  const queryClient = useQueryClient();
@@ -40,10 +50,7 @@ function useCurdRemove() {
40
50
  yield mutation.mutateAsync({
41
51
  id: activateItem == null ? void 0 : activateItem.id
42
52
  });
43
- setOpenRemove(false);
44
- router.refresh();
45
- queryClient.invalidateQueries();
46
- }), [activateItem == null ? void 0 : activateItem.id, mutation, queryClient, router, setOpenRemove]);
53
+ }), [activateItem == null ? void 0 : activateItem.id, mutation]);
47
54
  return {
48
55
  handlerSubmit,
49
56
  open: openRemove,
@@ -1,6 +1,7 @@
1
1
  import { PlainMessage } from "@bufbuild/protobuf";
2
+ import { DefaultError, UseMutationOptions } from "@tanstack/react-query";
2
3
  import { MtmError } from "./gomtmpb/mtm/sppb/mtm_pb";
3
- export declare const useGomtmQuery: (svc: string, method: string, input?: any) => import("@tanstack/react-query").UseQueryResult<any, Error>;
4
- export declare const useGomtmSuspenseQuery: (svc: string, method: string, input?: any) => import("@tanstack/react-query").UseSuspenseQueryResult<any, Error>;
4
+ export declare function useGomtmQuery<T = any>(svc: string, method: string, input?: any): import("@tanstack/react-query").UseQueryResult<T, Error>;
5
+ export declare function useGomtmSuspenseQuery<T = any>(svc: string, method: string, input?: any): import("@tanstack/react-query").UseSuspenseQueryResult<T, Error>;
5
6
  export declare function useGomtmSuspenseInfiniteQuery<T = any>(svc: string, method: string, input?: any): import("@tanstack/react-query").UseSuspenseInfiniteQueryResult<import("@tanstack/react-query").InfiniteData<T & PlainMessage<MtmError>, unknown>, Error>;
6
- export declare const useGomtmMutation: (svc: string, method: string) => import("@tanstack/react-query").UseMutationResult<any, Error, any, unknown>;
7
+ export declare function useGomtmMutation<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown>(svc: string, method: string, options?: UseMutationOptions): import("@tanstack/react-query").UseMutationResult<TData, any, any, any>;
@@ -1,4 +1,23 @@
1
1
  "use client";
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __spreadValues = (a, b) => {
10
+ for (var prop in b || (b = {}))
11
+ if (__hasOwnProp.call(b, prop))
12
+ __defNormalProp(a, prop, b[prop]);
13
+ if (__getOwnPropSymbols)
14
+ for (var prop of __getOwnPropSymbols(b)) {
15
+ if (__propIsEnum.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ }
18
+ return a;
19
+ };
20
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
2
21
  import { useMutation, useQuery, useSuspenseInfiniteQuery, useSuspenseQuery } from "@tanstack/react-query";
3
22
  import { MTM_API_PREFIX } from "./consts";
4
23
  import { createInfiniteQueryKey, createQueryKey, goMtmQueryFn } from "./mtmFetcher";
@@ -8,6 +27,7 @@ const useGmtmQjeryFn = () => {
8
27
  const cookieStr = useGomtm((x) => x.cookieStr);
9
28
  const token = useGomtm((x) => x.token);
10
29
  const gomtmHost = useGomtm((x) => x.gomtmHost);
30
+ const cacheEnabled = useGomtm((x) => x.cacheEnabled);
11
31
  return (svc, method, input) => {
12
32
  return goMtmQueryFn({
13
33
  svc,
@@ -17,25 +37,26 @@ const useGmtmQjeryFn = () => {
17
37
  url: new URL(MTM_API_PREFIX, backendUrl).toString(),
18
38
  token,
19
39
  cookieStr,
20
- gomtmHost
40
+ gomtmHost,
41
+ cacheEnabled: !!cacheEnabled
21
42
  }
22
43
  });
23
44
  };
24
45
  };
25
- const useGomtmQuery = (svc, method, input) => {
46
+ function useGomtmQuery(svc, method, input) {
26
47
  const fn = useGmtmQjeryFn();
27
48
  return useQuery({
28
49
  queryKey: createQueryKey(svc, method, input),
29
50
  queryFn: (k) => fn(svc, method, input)
30
51
  });
31
- };
32
- const useGomtmSuspenseQuery = (svc, method, input) => {
52
+ }
53
+ function useGomtmSuspenseQuery(svc, method, input) {
33
54
  const fn = useGmtmQjeryFn();
34
55
  return useSuspenseQuery({
35
56
  queryKey: createQueryKey(svc, method, input),
36
57
  queryFn: (k) => fn(svc, method, input)
37
58
  });
38
- };
59
+ }
39
60
  function useGomtmSuspenseInfiniteQuery(svc, method, input) {
40
61
  const fn = useGmtmQjeryFn();
41
62
  return useSuspenseInfiniteQuery({
@@ -47,12 +68,12 @@ function useGomtmSuspenseInfiniteQuery(svc, method, input) {
47
68
  }
48
69
  });
49
70
  }
50
- const useGomtmMutation = (svc, method) => {
71
+ function useGomtmMutation(svc, method, options) {
51
72
  const fn = useGmtmQjeryFn();
52
- return useMutation({
73
+ return useMutation(__spreadProps(__spreadValues({}, options), {
53
74
  mutationFn: (input) => fn(svc, method, input)
54
- });
55
- };
75
+ }));
76
+ }
56
77
  export {
57
78
  useGomtmMutation,
58
79
  useGomtmQuery,
@@ -1,5 +1,5 @@
1
1
  import { ServiceType } from "@bufbuild/protobuf";
2
- export declare const createQueryKey: (svc: string, method: string, input: any) => any[];
2
+ export declare const createQueryKey: (svc: string, method: string, input?: any) => any[];
3
3
  export declare const createInfiniteQueryKey: (svc: string, method: string, input: any) => any[];
4
4
  interface goMtmQueryFnProps {
5
5
  svc: string;
@@ -10,6 +10,7 @@ interface goMtmQueryFnProps {
10
10
  token?: string;
11
11
  cookieStr?: string;
12
12
  gomtmHost: string;
13
+ cacheEnabled?: boolean;
13
14
  };
14
15
  }
15
16
  export declare const goMtmQueryFn: (props: goMtmQueryFnProps) => Promise<any>;
@@ -17,7 +18,7 @@ export declare const ssrGetBackendUrl: () => string;
17
18
  export declare const gomtmApiUrl: () => string;
18
19
  export declare function createMtmServiceClient<T extends ServiceType>(service: T, url?: string): import("@connectrpc/connect").PromiseClient<T>;
19
20
  export declare function createTransport(): import("@connectrpc/connect").Transport;
20
- export declare function createMtmServiceClientByName<T extends ServiceType>(svcName: string, url?: string, token?: string, gomtmHost?: string): import("@connectrpc/connect").PromiseClient<ServiceType>;
21
+ export declare function createMtmServiceClientByName<T extends ServiceType>(svcName: string, url?: string, token?: string, gomtmHost?: string, cacheEnabled?: boolean): import("@connectrpc/connect").PromiseClient<ServiceType>;
21
22
  type CustomRequestInit = RequestInit & {
22
23
  cookieStr?: string;
23
24
  token?: string;
@@ -107,7 +107,7 @@ function createTransport() {
107
107
  useHttpGet: true
108
108
  });
109
109
  }
110
- function createMtmServiceClientByName(svcName, url, token, gomtmHost) {
110
+ function createMtmServiceClientByName(svcName, url, token, gomtmHost, cacheEnabled) {
111
111
  let svcType = void 0;
112
112
  for (const a of allServices) {
113
113
  if (a.typeName == svcName) {
@@ -125,7 +125,8 @@ function createMtmServiceClientByName(svcName, url, token, gomtmHost) {
125
125
  fetch: gomtmFetcher({
126
126
  cookieStr: token,
127
127
  token,
128
- gomtmHost
128
+ gomtmHost,
129
+ enableCache: cacheEnabled
129
130
  })
130
131
  })
131
132
  );
@@ -162,7 +163,7 @@ const gomtmFetcher = (initGlobal) => {
162
163
  }, cookieStr1 && { "Cookie": cookieStr1 }), token && { "Authorization": "Bearer " + token }), gomtmHost && { [CONST_HeaderMtmHost]: gomtmHost })
163
164
  });
164
165
  let fetcher = fetch;
165
- req.enableCache = true;
166
+ req.enableCache = initGlobal == null ? void 0 : initGlobal.enableCache;
166
167
  if (req.enableCache) {
167
168
  fetcher = fetchMiddleWithCache(fetch);
168
169
  }