gomtm 0.0.181 → 0.0.182

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.
@@ -5,12 +5,13 @@ import { MtLink } from "mtxuilib/common/mtlink";
5
5
  import { cn } from "mtxuilib/lib/utils";
6
6
  import { useDebug } from "mtxuilib/store/app.atoms";
7
7
  import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "mtxuilib/ui/card";
8
- import { curdActivateIdAtom } from "../../curd/CurdListView";
8
+ import { curdActivateIdAtom, curdDashPathPrefixAtom } from "../../curd/curd.atoms";
9
9
  import { BlogPostItemActions } from "./BlogPostActions";
10
10
  const PostCard = (props) => {
11
11
  const { item } = props;
12
12
  const debug = useDebug();
13
13
  const [curdActivateId, setcurdActivateId] = useAtom(curdActivateIdAtom);
14
+ const [dashPrefix] = useAtom(curdDashPathPrefixAtom);
14
15
  return /* @__PURE__ */ jsxs(
15
16
  Card,
16
17
  {
@@ -24,7 +25,7 @@ const PostCard = (props) => {
24
25
  },
25
26
  children: [
26
27
  /* @__PURE__ */ jsxs(CardHeader, { children: [
27
- /* @__PURE__ */ jsx(CardTitle, { children: /* @__PURE__ */ jsx(MtLink, { href: `/post/${item.id}`, className: "pb-4 text-3xl font-bold hover:text-gray-700", children: item == null ? void 0 : item.title }) }),
28
+ /* @__PURE__ */ jsx(CardTitle, { children: /* @__PURE__ */ jsx(MtLink, { href: `${dashPrefix}/post/${item.id}`, className: "pb-4 text-3xl font-bold hover:text-gray-700", children: item == null ? void 0 : item.title }) }),
28
29
  /* @__PURE__ */ jsx(CardDescription, { children: "Deploy your new project in one-click." })
29
30
  ] }),
30
31
  /* @__PURE__ */ jsx(CardContent, { children: /* @__PURE__ */ jsxs("article", { className: "my-4 flex flex-col", children: [
@@ -12,8 +12,6 @@ export declare const DEFAULT_revalidate_SECONDS = 3;
12
12
  export declare const LOGIN_CALLBACK_URL_KEY = "back";
13
13
  export declare const ExtKey_Hostname = "host";
14
14
  export declare const ExtKey_mtmaccessToken = "access_token";
15
- export declare const ExtKey_mtmbackend = "mtmbackend";
16
- export declare const ExtKey_SelfBackend = "selfbackend";
17
15
  export declare const ItemAction_list_new_item = "list_new_item";
18
16
  export declare const Listview_list_filter = "Listview_list_filter";
19
17
  export declare const ActionEdit = "edit";
@@ -12,8 +12,6 @@ const DEFAULT_revalidate_SECONDS = 3;
12
12
  const LOGIN_CALLBACK_URL_KEY = "back";
13
13
  const ExtKey_Hostname = "host";
14
14
  const ExtKey_mtmaccessToken = "access_token";
15
- const ExtKey_mtmbackend = "mtmbackend";
16
- const ExtKey_SelfBackend = "selfbackend";
17
15
  const ItemAction_list_new_item = "list_new_item";
18
16
  const Listview_list_filter = "Listview_list_filter";
19
17
  const ActionEdit = "edit";
@@ -38,9 +36,7 @@ export {
38
36
  Cookie_Site_Host,
39
37
  DEFAULT_revalidate_SECONDS,
40
38
  ExtKey_Hostname,
41
- ExtKey_SelfBackend,
42
39
  ExtKey_mtmaccessToken,
43
- ExtKey_mtmbackend,
44
40
  HeaderMtmApi,
45
41
  HeaderMtmHost,
46
42
  ImageNoExist,
@@ -1,9 +1,6 @@
1
1
  import { AnyMessage, Message, PlainMessage } from "@bufbuild/protobuf";
2
2
  import { PropsWithChildren } from "react";
3
3
  import { MethodUnaryDescriptor } from "../connectquery";
4
- export declare const curdActivateIdAtom: import("jotai").PrimitiveAtom<string> & {
5
- init: string;
6
- };
7
4
  export declare function Curd3ListProvider<I extends Message<I>, O extends Message<O>>(props: {
8
5
  params: Partial<PlainMessage<I>>;
9
6
  methodList: MethodUnaryDescriptor<I, O>;
@@ -28,7 +28,6 @@ import { callUnaryMethod } from "../connectquery";
28
28
  import { ListViewLayout } from "../gomtmpb/mtm/sppb/mtm_pb";
29
29
  import { gomtmBaseUrlAtom, transportAtom } from "../providers/GomtmProvider";
30
30
  import { ListItemView } from "./list-item/ListItem";
31
- const curdActivateIdAtom = atom("");
32
31
  const curd3ListParamsAtom = atom({});
33
32
  const curd3MethodListAtom = atom(null);
34
33
  const curd3ItemsAtom = atom((get) => __async(void 0, null, function* () {
@@ -94,6 +93,5 @@ export {
94
93
  Curd2ListView,
95
94
  Curd3ListProvider,
96
95
  Curd3ListViewDebug,
97
- curdActivateIdAtom,
98
96
  useCurd3List
99
97
  };
@@ -0,0 +1,3 @@
1
+ import { Message } from "@bufbuild/protobuf";
2
+ import { PropsWithChildren } from "react";
3
+ export declare function CurdListViewByPathname<I extends Message<I>, O extends Message<O>>(props: {} & PropsWithChildren): import("react").JSX.Element;
@@ -0,0 +1,15 @@
1
+ "use client";
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
+ import { usePathname } from "next/navigation";
4
+ function CurdListViewByPathname(props) {
5
+ const { children } = props;
6
+ const pathname = usePathname();
7
+ return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs("h1", { children: [
8
+ "CurdListViewByPathname(",
9
+ pathname,
10
+ ")"
11
+ ] }) }) });
12
+ }
13
+ export {
14
+ CurdListViewByPathname
15
+ };
@@ -0,0 +1,6 @@
1
+ import { PropsWithChildren } from "react";
2
+ export declare function Curd3ListProviderV2(props: {
3
+ params?: any;
4
+ } & PropsWithChildren): import("react").JSX.Element;
5
+ export declare const Curd2ListViewV2: () => import("react").JSX.Element;
6
+ export declare const Curd3ListProviderV2Debug: () => import("react").JSX.Element;
@@ -0,0 +1,45 @@
1
+ "use client";
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
+ import { useAtom } from "jotai";
4
+ import { ScopeProvider } from "mtxlib/jotai/ScopeProvider";
5
+ import { AtomsHydrator } from "mtxlib/jotai/jotai-helper";
6
+ import { usePathname } from "next/navigation";
7
+ import { MtUnaryCallErrorView } from "../components/MtUnaryCallErrorView";
8
+ import { curd3ItemsAtom, curd3ListParamsAtom, curd3MethodListAtom, curdMethodListAtom, curdSvcAtom } from "./curd.atoms";
9
+ import { ListItemView } from "./list-item/ListItem";
10
+ function Curd3ListProviderV2(props) {
11
+ const { params, children } = props;
12
+ const [curdMethodList, setcurdMethodList] = useAtom(curdMethodListAtom);
13
+ const pathName = usePathname();
14
+ return /* @__PURE__ */ jsx(ScopeProvider, { atoms: [curd3ListParamsAtom, curd3MethodListAtom], children: /* @__PURE__ */ jsxs(AtomsHydrator, { atomValues: [
15
+ [curd3ListParamsAtom, params],
16
+ [curd3MethodListAtom, curdMethodList]
17
+ ], children: [
18
+ /* @__PURE__ */ jsx(Curd3ListProviderV2Debug, {}),
19
+ children
20
+ ] }) });
21
+ }
22
+ const Curd2ListViewV2 = () => {
23
+ const [res] = useAtom(curd3ItemsAtom);
24
+ return /* @__PURE__ */ jsx("div", { className: "bg-blue-100 p-2", children: res.errCode ? /* @__PURE__ */ jsx(MtUnaryCallErrorView, { unaryError: res }) : /* @__PURE__ */ jsx(Fragment, { children: res.items.map((item, i) => {
25
+ return /* @__PURE__ */ jsx(ListItemView, { item }, i);
26
+ }) }) });
27
+ };
28
+ const Curd3ListProviderV2Debug = () => {
29
+ const [curdSvc, setCurdSvc] = useAtom(curdSvcAtom);
30
+ const [curdMethodList, setCurdMethodList] = useAtom(curdMethodListAtom);
31
+ return /* @__PURE__ */ jsxs("div", { className: "bg-slate-200 p-2", children: [
32
+ /* @__PURE__ */ jsx("h1", { children: "Curd3ListProviderV2Debug" }),
33
+ /* @__PURE__ */ jsxs("div", { children: [
34
+ "method:",
35
+ curdSvc,
36
+ ".",
37
+ curdMethodList
38
+ ] })
39
+ ] });
40
+ };
41
+ export {
42
+ Curd2ListViewV2,
43
+ Curd3ListProviderV2,
44
+ Curd3ListProviderV2Debug
45
+ };
@@ -6,7 +6,7 @@ import { createContext, useMemo, useState } from "react";
6
6
  import { Icons } from "mtxuilib/icons/icons";
7
7
  import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger } from "mtxuilib/ui/dropdown-menu";
8
8
  import { MtButton } from "mtxuilib/ui/ui-mt/Button";
9
- import { curdActivateIdAtom } from "./CurdListView";
9
+ import { curdActivateIdAtom } from "./curd.atoms";
10
10
  const curdDetailViewContext = createContext(void 0);
11
11
  function CurdViewDetailProvider(props) {
12
12
  const [isOpenEdit, setIsOpenEdit] = useState(false);
@@ -0,0 +1,21 @@
1
+ import { AnyMessage, PlainMessage } from "@bufbuild/protobuf";
2
+ import { CommontListRes, MtmError } from "../gomtmpb/mtm/sppb/mtm_pb";
3
+ export declare const curdDashPathPrefixAtom: import("jotai").PrimitiveAtom<string> & {
4
+ init: string;
5
+ };
6
+ export declare const curdActivateIdAtom: import("jotai").PrimitiveAtom<string> & {
7
+ init: string;
8
+ };
9
+ export declare const curdSvcAtom: import("jotai").PrimitiveAtom<string> & {
10
+ init: string;
11
+ };
12
+ export declare const curdMethodListAtom: import("jotai").PrimitiveAtom<string> & {
13
+ init: string;
14
+ };
15
+ export declare const curd3ListParamsAtom: import("jotai").PrimitiveAtom<PlainMessage<AnyMessage>> & {
16
+ init: PlainMessage<AnyMessage>;
17
+ };
18
+ export declare const curd3MethodListAtom: import("jotai").PrimitiveAtom<string> & {
19
+ init: string;
20
+ };
21
+ export declare const curd3ItemsAtom: import("jotai").Atom<Promise<CommontListRes | PlainMessage<MtmError>>>;
@@ -0,0 +1,56 @@
1
+ "use client";
2
+ var __async = (__this, __arguments, generator) => {
3
+ return new Promise((resolve, reject) => {
4
+ var fulfilled = (value) => {
5
+ try {
6
+ step(generator.next(value));
7
+ } catch (e) {
8
+ reject(e);
9
+ }
10
+ };
11
+ var rejected = (value) => {
12
+ try {
13
+ step(generator.throw(value));
14
+ } catch (e) {
15
+ reject(e);
16
+ }
17
+ };
18
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
19
+ step((generator = generator.apply(__this, __arguments)).next());
20
+ });
21
+ };
22
+ import { atom } from "jotai";
23
+ import { createMtmServiceClientByName } from "../gomtm-clients-ss";
24
+ const curdDashPathPrefixAtom = atom("/gomtmadmin");
25
+ const curdActivateIdAtom = atom("");
26
+ const curdSvcAtom = atom("sppb.MtmService");
27
+ const curdMethodListAtom = atom("blogPostList");
28
+ const curd3ListParamsAtom = atom({});
29
+ const curd3MethodListAtom = atom("");
30
+ const curd3ItemsAtom = atom((get) => __async(void 0, null, function* () {
31
+ const params = get(curd3ListParamsAtom);
32
+ const methodList = get(curd3MethodListAtom);
33
+ if (!methodList) {
34
+ throw new Error("curd3ItemsAtom, missing methodList");
35
+ }
36
+ const svcName = get(curdSvcAtom);
37
+ if (!svcName) {
38
+ throw new Error(`curd3ItemsAtom, missing svcName:\u201C${svcName}\u201D`);
39
+ }
40
+ const client = yield createMtmServiceClientByName(svcName);
41
+ const methodFn = client[methodList];
42
+ if (!methodFn) {
43
+ throw new Error(`missing method ${svcName}.${methodList}`);
44
+ }
45
+ const data = yield methodFn(params);
46
+ return data;
47
+ }));
48
+ export {
49
+ curd3ItemsAtom,
50
+ curd3ListParamsAtom,
51
+ curd3MethodListAtom,
52
+ curdActivateIdAtom,
53
+ curdDashPathPrefixAtom,
54
+ curdMethodListAtom,
55
+ curdSvcAtom
56
+ };
@@ -1,5 +1,6 @@
1
1
  import { ServiceType } from "@bufbuild/protobuf";
2
2
  export declare function createMtmServiceClient<T extends ServiceType>(service: T, url?: string): import("@connectrpc/connect").PromiseClient<T>;
3
+ export declare function createMtmServiceClientByName<T extends ServiceType>(svcName: string, url?: string): import("@connectrpc/connect").PromiseClient<ServiceType>;
3
4
  type CustomRequestInit = RequestInit & {
4
5
  enableCache?: boolean;
5
6
  enableLog?: boolean;
@@ -41,6 +41,7 @@ import { createPromiseClient } from "@connectrpc/connect";
41
41
  import { createConnectTransport } from "@connectrpc/connect-web";
42
42
  import { merge } from "lodash";
43
43
  import { fetchMiddleWithCache } from "mtxlib/http/fetchMiddleWithCache";
44
+ import { MtmService } from "./gomtmpb/mtm/sppb/mtm_connect";
44
45
  function createMtmServiceClient(service, url) {
45
46
  const baseUrl = url || process.env.MTM_BACKEND;
46
47
  if (!baseUrl) {
@@ -55,6 +56,30 @@ function createMtmServiceClient(service, url) {
55
56
  })
56
57
  );
57
58
  }
59
+ function createMtmServiceClientByName(svcName, url) {
60
+ const baseUrl = url || process.env.MTM_BACKEND;
61
+ if (!baseUrl) {
62
+ throw new Error("missing mtm api url,\xB7MTM_BACKEND\xB7");
63
+ }
64
+ console.info("gomtm baseUrl:", baseUrl);
65
+ let svcType = void 0;
66
+ for (const a of allServices) {
67
+ if (a.typeName == svcName) {
68
+ svcType = a;
69
+ }
70
+ }
71
+ if (!svcType) {
72
+ throw new Error(`unknown svcType ${svcName}`);
73
+ }
74
+ return createPromiseClient(
75
+ svcType,
76
+ createConnectTransport({
77
+ baseUrl,
78
+ fetch: gomtmFetcher()
79
+ })
80
+ );
81
+ }
82
+ const allServices = [MtmService];
58
83
  const gomtmFetcher = (initGlobal) => {
59
84
  return (input, init) => __async(void 0, null, function* () {
60
85
  if (init) {
@@ -102,5 +127,6 @@ const gomtmFetcher = (initGlobal) => {
102
127
  };
103
128
  export {
104
129
  createMtmServiceClient,
130
+ createMtmServiceClientByName,
105
131
  gomtmFetcher
106
132
  };
@@ -1,6 +1,5 @@
1
- import { Dispatch, PropsWithChildren } from 'react';
1
+ import { PropsWithChildren } from 'react';
2
2
  import { Transport } from '@connectrpc/connect';
3
- import React from 'react';
4
3
  export declare const mtmAppStore: {
5
4
  get: <Value>(atom: import("jotai").Atom<Value>) => Value;
6
5
  set: <Value_1, Args extends unknown[], Result>(atom: import("jotai").WritableAtom<Value_1, Args, Result>, ...args: Args) => Result;
@@ -55,22 +54,11 @@ interface GomtmAppProps {
55
54
  backendUrl?: string | null;
56
55
  }
57
56
  interface IAppContext {
58
- token?: string | null;
59
57
  hostname?: string | null;
60
- isDebug?: boolean;
61
- debugData?: any;
62
- setDebugData: Dispatch<any>;
63
- isOpenDebugView?: boolean;
64
- setOpenDebugView: Dispatch<React.SetStateAction<boolean>>;
65
58
  }
66
- export declare function GomtmProvider(props: {} & GomtmAppProps & PropsWithChildren): React.JSX.Element;
59
+ export declare function GomtmProvider(props: {} & GomtmAppProps & PropsWithChildren): import("react").JSX.Element;
67
60
  export declare function useMtmApp(): IAppContext & GomtmAppProps;
68
61
  export declare const useMtmBackendUrl: () => string | null | undefined;
69
62
  export declare const useHostname: () => string;
70
- export declare const useExtInfo: () => (key: string) => string | null | undefined;
71
- export declare const useToken: () => {
72
- token: string;
73
- setToken: (newToken: string) => void;
74
- };
75
- export declare const MtConnectProvider: (props: PropsWithChildren) => React.JSX.Element;
63
+ export declare const MtConnectProvider: (props: PropsWithChildren) => import("react").JSX.Element;
76
64
  export {};
@@ -1,14 +1,12 @@
1
1
  "use client";
2
2
  import { Fragment, jsx } from "react/jsx-runtime";
3
- import { createContext, useCallback, useContext, useState } from "react";
3
+ import { createContext, useContext } from "react";
4
4
  import { createConnectTransport } from "@connectrpc/connect-web";
5
5
  import { atom, createStore, useAtom } from "jotai";
6
- import { getCookie } from "mtxlib/clientlib";
7
6
  import { AtomsHydrator } from "mtxlib/jotai/jotai-helper";
8
7
  import { isDebugAtom } from "mtxuilib/store/app.atoms";
9
8
  import { useHotkeys } from "react-hotkeys-hook";
10
9
  import { TransportProvider } from "../connectquery";
11
- import { ExtKey_Hostname, ExtKey_SelfBackend, ExtKey_mtmaccessToken, ExtKey_mtmbackend, MtM_TOKEN_NAME } from "../consts";
12
10
  import { gomtmFetcher } from "../gomtm-clients-ss";
13
11
  import { MtReactQueryProvider } from "./ReactQueryProvider";
14
12
  const mtmAppStore = createStore();
@@ -68,37 +66,6 @@ const useHostname = () => {
68
66
  }
69
67
  return "";
70
68
  };
71
- const useExtInfo = () => {
72
- const backendUrl = useMtmBackendUrl();
73
- const siteHost = useHostname();
74
- const { token } = useMtmApp();
75
- const fn = useCallback((key) => {
76
- switch (key) {
77
- case ExtKey_mtmbackend:
78
- return backendUrl;
79
- case ExtKey_Hostname:
80
- return siteHost;
81
- case ExtKey_mtmaccessToken:
82
- return token;
83
- case ExtKey_SelfBackend:
84
- return;
85
- default:
86
- throw new Error(`extinfo key error: ${key}`);
87
- }
88
- }, [backendUrl, siteHost, token]);
89
- return fn;
90
- };
91
- const useToken = () => {
92
- const [token] = useState(typeof window != "undefined" ? getCookie(MtM_TOKEN_NAME) : "");
93
- return {
94
- token: token || "",
95
- setToken: (newToken) => {
96
- if (typeof window != "undefined") {
97
- document.cookie = `${MtM_TOKEN_NAME}=${newToken}`;
98
- }
99
- }
100
- };
101
- };
102
69
  const MtConnectProvider = (props) => {
103
70
  const { children } = props;
104
71
  const [transport] = useAtom(transportAtom);
@@ -110,10 +77,8 @@ export {
110
77
  gomtmBaseUrlAtom,
111
78
  mtmAppStore,
112
79
  transportAtom,
113
- useExtInfo,
114
80
  useGomtmBackend,
115
81
  useHostname,
116
82
  useMtmApp,
117
- useMtmBackendUrl,
118
- useToken
83
+ useMtmBackendUrl
119
84
  };
@@ -7,10 +7,4 @@ export declare function useLogger(): {
7
7
  (...data: any[]): void;
8
8
  (message?: any, ...optionalParams: any[]): void;
9
9
  };
10
- error: {
11
- (...data: any[]): void;
12
- (...data: any[]): void;
13
- (...data: any[]): void;
14
- (message?: any, ...optionalParams: any[]): void;
15
- };
16
10
  };
@@ -1,8 +1,7 @@
1
1
  "use client";
2
2
  import { jsx } from "react/jsx-runtime";
3
3
  import { mtlogger } from "mtxlib/mt-logger";
4
- import { createContext, useContext, useMemo, useState } from "react";
5
- import { useMtmApp } from "./GomtmProvider";
4
+ import { createContext, useContext, useState } from "react";
6
5
  const LoggerContext = createContext(void 0);
7
6
  function LoggerProvider(props) {
8
7
  const { children } = props;
@@ -18,22 +17,7 @@ function useLogger() {
18
17
  if (context === void 0) {
19
18
  throw new Error("useLogger must be used within a LoggerProvider");
20
19
  }
21
- const mtapp = useMtmApp();
22
- const info = useMemo(() => {
23
- if (mtapp.isDebug) {
24
- return mtlogger.log;
25
- } else {
26
- return nonLogFn;
27
- }
28
- }, [mtapp.isDebug]);
29
- const error = useMemo(() => {
30
- if (mtapp.isDebug) {
31
- return mtlogger.error;
32
- } else {
33
- return nonLogFn;
34
- }
35
- }, [mtapp.isDebug]);
36
- return { info, error };
20
+ return { info: mtlogger.log };
37
21
  }
38
22
  export {
39
23
  LoggerProvider,