gomtm 0.0.280 → 0.0.282
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/esm/components/SSR.d.ts +4 -5
- package/dist/esm/components/SSR.js +5 -8
- package/dist/esm/curd/CurdDetailProvider.d.ts +0 -4
- package/dist/esm/curd/CurdDetailProvider.js +0 -33
- package/dist/esm/curd/ListPageCommands.js +1 -1
- package/dist/esm/curd/ListViewProvider.d.ts +17 -15
- package/dist/esm/curd/ListViewProvider.js +6 -21
- package/dist/esm/curd/MtListView.d.ts +3 -0
- package/dist/esm/curd/MtListView.js +50 -0
- package/dist/esm/curd/create/CurdCreatePanel.js +1 -1
- package/dist/esm/curd/edit/CurdEditPanel.js +2 -2
- package/dist/esm/curd/list-item/CommonListItemView.js +1 -1
- package/dist/esm/curd/list-item/PostCardListItem.js +1 -1
- package/dist/esm/curd/listview/ListViewProvider.d.ts +64 -0
- package/dist/esm/curd/listview/ListViewProvider.js +195 -0
- package/dist/esm/curd/listview/MtListView.d.ts +3 -0
- package/dist/esm/curd/listview/MtListView.js +50 -0
- package/dist/esm/curd/listview/listview-layouts/listview-demolayout/index.d.ts +2 -0
- package/dist/esm/curd/listview/listview-layouts/listview-demolayout/index.js +9 -0
- package/dist/esm/gomtmQuery.d.ts +14 -0
- package/dist/esm/gomtmQuery.js +102 -0
- package/dist/esm/mtmFetcher.d.ts +2 -0
- package/dist/esm/mtmFetcher.js +11 -2
- package/dist/tsconfig.type.tsbuildinfo +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
interface goMtmQueryFnProps {
|
|
2
|
+
svc: string;
|
|
3
|
+
method: string;
|
|
4
|
+
input?: any;
|
|
5
|
+
options?: {
|
|
6
|
+
url: string;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export declare const goMtmQueryFn: (props: goMtmQueryFnProps) => Promise<any>;
|
|
10
|
+
export declare const useGomtmQuery: (svc: string, method: string, input?: any) => import("@tanstack/react-query").UseQueryResult<any, Error>;
|
|
11
|
+
export declare const useGomtmSuspenseQuery: (svc: string, method: string, input?: any) => import("@tanstack/react-query").UseSuspenseQueryResult<any, Error>;
|
|
12
|
+
export declare const useGomtmSuspenseInfiniteQuery: (svc: string, method: string, input?: any) => import("@tanstack/react-query").UseSuspenseInfiniteQueryResult<import("@tanstack/react-query").InfiniteData<any, unknown>, Error>;
|
|
13
|
+
export declare const useGomtmMutation: (svc: string, method: string) => import("@tanstack/react-query").UseMutationResult<any, Error, any, unknown>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,102 @@
|
|
|
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 { useMutation, useQuery, useSuspenseInfiniteQuery, useSuspenseQuery } from "@tanstack/react-query";
|
|
23
|
+
import { camelCase } from "lodash";
|
|
24
|
+
import { MTM_API_PREFIX } from "./consts";
|
|
25
|
+
import { createMtmServiceClientByName, createQueryKey } from "./mtmFetcher";
|
|
26
|
+
import { useMtmApp } from "./providers/GomtmProvider";
|
|
27
|
+
const goMtmQueryFn = (props) => __async(void 0, null, function* () {
|
|
28
|
+
var _a;
|
|
29
|
+
const client = createMtmServiceClientByName(props.svc, (_a = props.options) == null ? void 0 : _a.url);
|
|
30
|
+
if (!client) {
|
|
31
|
+
throw new Error(`missing mtmclient:"${props.svc}"`);
|
|
32
|
+
}
|
|
33
|
+
const methodName = camelCase(props.method);
|
|
34
|
+
const methodFn = client[methodName];
|
|
35
|
+
if (!methodFn) {
|
|
36
|
+
throw new Error(`missing mtmclient method:"${props.svc}.${methodName}"`);
|
|
37
|
+
}
|
|
38
|
+
const data = yield methodFn(props.input);
|
|
39
|
+
console.log(`goMtmQueryFn ${props.svc}.${props.method}.${props.input}`, data);
|
|
40
|
+
return data;
|
|
41
|
+
});
|
|
42
|
+
const useGomtmQuery = (svc, method, input) => {
|
|
43
|
+
const query = useQuery({
|
|
44
|
+
queryKey: createQueryKey(svc, method, input),
|
|
45
|
+
queryFn: (k) => goMtmQueryFn({ svc, method, input })
|
|
46
|
+
});
|
|
47
|
+
return query;
|
|
48
|
+
};
|
|
49
|
+
const useGomtmSuspenseQuery = (svc, method, input) => {
|
|
50
|
+
const mtapp = useMtmApp();
|
|
51
|
+
const query = useSuspenseQuery({
|
|
52
|
+
queryKey: createQueryKey(svc, method, input),
|
|
53
|
+
queryFn: (k) => goMtmQueryFn({
|
|
54
|
+
svc,
|
|
55
|
+
method,
|
|
56
|
+
input,
|
|
57
|
+
options: {
|
|
58
|
+
url: new URL(MTM_API_PREFIX, mtapp.backendUrl || "").toString()
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
});
|
|
62
|
+
return query;
|
|
63
|
+
};
|
|
64
|
+
const useGomtmSuspenseInfiniteQuery = (svc, method, input) => {
|
|
65
|
+
const mtapp = useMtmApp();
|
|
66
|
+
const query = useSuspenseInfiniteQuery({
|
|
67
|
+
queryKey: createQueryKey(svc, method, input),
|
|
68
|
+
queryFn: (k) => goMtmQueryFn({
|
|
69
|
+
svc,
|
|
70
|
+
method,
|
|
71
|
+
input,
|
|
72
|
+
options: {
|
|
73
|
+
url: new URL(MTM_API_PREFIX, mtapp.backendUrl || "").toString()
|
|
74
|
+
}
|
|
75
|
+
}),
|
|
76
|
+
initialPageParam: input,
|
|
77
|
+
getNextPageParam: (lastPage, allPages, lastPageParam, allPageParams) => {
|
|
78
|
+
return lastPage;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
return query;
|
|
82
|
+
};
|
|
83
|
+
const useGomtmMutation = (svc, method) => {
|
|
84
|
+
const mtapp = useMtmApp();
|
|
85
|
+
return useMutation({
|
|
86
|
+
mutationFn: (input) => goMtmQueryFn({
|
|
87
|
+
svc,
|
|
88
|
+
method,
|
|
89
|
+
input,
|
|
90
|
+
options: {
|
|
91
|
+
url: new URL(MTM_API_PREFIX, mtapp.backendUrl || "").toString()
|
|
92
|
+
}
|
|
93
|
+
})
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
export {
|
|
97
|
+
goMtmQueryFn,
|
|
98
|
+
useGomtmMutation,
|
|
99
|
+
useGomtmQuery,
|
|
100
|
+
useGomtmSuspenseInfiniteQuery,
|
|
101
|
+
useGomtmSuspenseQuery
|
|
102
|
+
};
|
package/dist/esm/mtmFetcher.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { ServiceType } from "@bufbuild/protobuf";
|
|
2
|
+
export declare const createQueryKey: (svc: string, method: string, input: any) => any[];
|
|
3
|
+
export declare const createInfiniteQueryKey: (svc: string, method: string, input: any) => any[];
|
|
2
4
|
export declare const ssrGetBackendUrl: () => string;
|
|
3
5
|
export declare const gomtmApiUrl: () => string;
|
|
4
6
|
export declare function createMtmServiceClient<T extends ServiceType>(service: T, url?: string): import("@connectrpc/connect").PromiseClient<T>;
|
package/dist/esm/mtmFetcher.js
CHANGED
|
@@ -40,6 +40,13 @@ import { merge } from "lodash";
|
|
|
40
40
|
import { fetchMiddleWithCache } from "mtxlib/http/fetchMiddleWithCache";
|
|
41
41
|
import { MTM_API_PREFIX } from "./consts";
|
|
42
42
|
import { MtmService } from "./gomtmpb/mtm/sppb/mtm_connect";
|
|
43
|
+
const allServices = [MtmService];
|
|
44
|
+
const createQueryKey = (svc, method, input) => {
|
|
45
|
+
return [svc, method, input || {}];
|
|
46
|
+
};
|
|
47
|
+
const createInfiniteQueryKey = (svc, method, input) => {
|
|
48
|
+
return [svc, method, input || {}, "infinite"];
|
|
49
|
+
};
|
|
43
50
|
const ssrGetBackendUrl = () => {
|
|
44
51
|
var _a;
|
|
45
52
|
if (typeof window == "undefined") {
|
|
@@ -81,15 +88,15 @@ function createMtmServiceClientByName(svcName, url) {
|
|
|
81
88
|
if (!svcType) {
|
|
82
89
|
throw new Error(`unknown svcType ${svcName}`);
|
|
83
90
|
}
|
|
91
|
+
const baseUrl = url || gomtmApiUrl();
|
|
84
92
|
return createPromiseClient(
|
|
85
93
|
svcType,
|
|
86
94
|
createConnectTransport({
|
|
87
|
-
baseUrl
|
|
95
|
+
baseUrl,
|
|
88
96
|
fetch: gomtmFetcher()
|
|
89
97
|
})
|
|
90
98
|
);
|
|
91
99
|
}
|
|
92
|
-
const allServices = [MtmService];
|
|
93
100
|
const gomtmFetcher = (initGlobal) => {
|
|
94
101
|
return (input, init) => __async(void 0, null, function* () {
|
|
95
102
|
if (init) {
|
|
@@ -145,8 +152,10 @@ const gomtmFetcher = (initGlobal) => {
|
|
|
145
152
|
});
|
|
146
153
|
};
|
|
147
154
|
export {
|
|
155
|
+
createInfiniteQueryKey,
|
|
148
156
|
createMtmServiceClient,
|
|
149
157
|
createMtmServiceClientByName,
|
|
158
|
+
createQueryKey,
|
|
150
159
|
createTransport,
|
|
151
160
|
gomtmApiUrl,
|
|
152
161
|
gomtmFetcher,
|