mtmsdk 0.0.52 → 0.0.53
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/gomtmapi/@tanstack/react-query.gen.d.ts +21 -173
- package/dist/gomtmapi/@tanstack/react-query.gen.d.ts.map +1 -1
- package/dist/gomtmapi/@tanstack/react-query.gen.js +39 -179
- package/dist/gomtmapi/@tanstack/react-query.gen.js.map +1 -1
- package/dist/gomtmapi/index.d.ts +2 -2
- package/dist/gomtmapi/index.d.ts.map +1 -1
- package/dist/gomtmapi/index.js +1 -1
- package/dist/gomtmapi/index.js.map +1 -1
- package/dist/gomtmapi/schemas.gen.d.ts +67 -81
- package/dist/gomtmapi/schemas.gen.d.ts.map +1 -1
- package/dist/gomtmapi/schemas.gen.js +68 -82
- package/dist/gomtmapi/schemas.gen.js.map +1 -1
- package/dist/gomtmapi/sdk.gen.d.ts +15 -95
- package/dist/gomtmapi/sdk.gen.d.ts.map +1 -1
- package/dist/gomtmapi/sdk.gen.js +22 -102
- package/dist/gomtmapi/sdk.gen.js.map +1 -1
- package/dist/gomtmapi/types.gen.d.ts +66 -209
- package/dist/gomtmapi/types.gen.d.ts.map +1 -1
- package/dist/gomtmapi/zod.gen.d.ts +48 -121
- package/dist/gomtmapi/zod.gen.d.ts.map +1 -1
- package/dist/gomtmapi/zod.gen.js +36 -99
- package/dist/gomtmapi/zod.gen.js.map +1 -1
- package/dist/sbmng/@tanstack/react-query.gen.d.ts +146 -146
- package/dist/sbmng/@tanstack/react-query.gen.js +6 -6
- package/dist/sbmng/schemas.gen.d.ts +4 -4
- package/dist/sbmng/schemas.gen.js +4 -4
- package/dist/sbmng/schemas.gen.js.map +1 -1
- package/dist/sbmng/sdk.gen.d.ts +6 -6
- package/dist/sbmng/sdk.gen.js +6 -6
- package/dist/supabase/auth-provider.d.ts +8 -1
- package/dist/supabase/auth-provider.d.ts.map +1 -1
- package/dist/supabase/context.d.ts +3844 -1
- package/dist/supabase/context.d.ts.map +1 -1
- package/dist/supabase/cursor-pagination.d.ts +4 -4
- package/dist/supabase/cursor-pagination.js +4 -4
- package/dist/supabase/schema/index.d.ts +1 -11
- package/dist/supabase/schema/index.d.ts.map +1 -1
- package/dist/supabase/schema/index.js +1 -19
- package/dist/supabase/schema/index.js.map +1 -1
- package/dist/supabase/schema/system-config.d.ts +12 -0
- package/dist/supabase/schema/system-config.d.ts.map +1 -0
- package/dist/supabase/schema/system-config.js +22 -0
- package/dist/supabase/schema/system-config.js.map +1 -0
- package/dist/supabase/supabase-client.d.ts +1 -471
- package/dist/supabase/supabase-client.d.ts.map +1 -1
- package/dist/supabase/supabase.d.ts +44 -984
- package/dist/supabase/supabase.d.ts.map +1 -1
- package/dist/supabase/use-sb-query/use-rpc-mutation.d.ts +8 -8
- package/dist/supabase/use-sb-query/use-rpc-mutation.js +8 -8
- package/dist/types/contracts.d.ts +63 -0
- package/dist/types/contracts.d.ts.map +1 -0
- package/dist/types/contracts.js +17 -0
- package/dist/types/contracts.js.map +1 -0
- package/dist/types/database.schemas.d.ts +27 -626
- package/dist/types/database.schemas.d.ts.map +1 -1
- package/dist/types/database.schemas.js +0 -432
- package/dist/types/database.schemas.js.map +1 -1
- package/dist/types/database.types.d.ts +1 -476
- package/dist/types/database.types.d.ts.map +1 -1
- package/dist/types/database.types.js +0 -10
- package/dist/types/database.types.js.map +1 -1
- package/dist/types/index.d.ts +9 -25
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +3 -5
- package/dist/types/index.js.map +1 -1
- package/package.json +101 -105
- package/dist/cloud-account/platform-configs.d.ts +0 -64
- package/dist/cloud-account/platform-configs.d.ts.map +0 -1
- package/dist/cloud-account/platform-configs.js +0 -44
- package/dist/cloud-account/platform-configs.js.map +0 -1
- package/dist/lib/aisdk/types.d.ts +0 -3
- package/dist/lib/aisdk/types.d.ts.map +0 -1
- package/dist/lib/aisdk/types.js +0 -5
- package/dist/lib/aisdk/types.js.map +0 -1
- package/dist/lib/logger/index.d.ts +0 -22
- package/dist/lib/logger/index.d.ts.map +0 -1
- package/dist/lib/logger/index.js +0 -7
- package/dist/lib/logger/index.js.map +0 -1
- package/dist/lib/schema.d.ts +0 -43
- package/dist/lib/schema.d.ts.map +0 -1
- package/dist/lib/schema.js +0 -28
- package/dist/lib/schema.js.map +0 -1
- package/dist/mtgate_api/client/client.gen.d.ts +0 -3
- package/dist/mtgate_api/client/client.gen.d.ts.map +0 -1
- package/dist/mtgate_api/client/client.gen.js +0 -236
- package/dist/mtgate_api/client/client.gen.js.map +0 -1
- package/dist/mtgate_api/client/index.d.ts +0 -9
- package/dist/mtgate_api/client/index.d.ts.map +0 -1
- package/dist/mtgate_api/client/index.js +0 -7
- package/dist/mtgate_api/client/index.js.map +0 -1
- package/dist/mtgate_api/client/types.gen.d.ts +0 -118
- package/dist/mtgate_api/client/types.gen.d.ts.map +0 -1
- package/dist/mtgate_api/client/types.gen.js +0 -3
- package/dist/mtgate_api/client/types.gen.js.map +0 -1
- package/dist/mtgate_api/client/utils.gen.d.ts +0 -34
- package/dist/mtgate_api/client/utils.gen.d.ts.map +0 -1
- package/dist/mtgate_api/client/utils.gen.js +0 -232
- package/dist/mtgate_api/client/utils.gen.js.map +0 -1
- package/dist/mtgate_api/client.gen.d.ts +0 -13
- package/dist/mtgate_api/client.gen.d.ts.map +0 -1
- package/dist/mtgate_api/client.gen.js +0 -4
- package/dist/mtgate_api/client.gen.js.map +0 -1
- package/dist/mtgate_api/core/auth.gen.d.ts +0 -19
- package/dist/mtgate_api/core/auth.gen.d.ts.map +0 -1
- package/dist/mtgate_api/core/auth.gen.js +0 -15
- package/dist/mtgate_api/core/auth.gen.js.map +0 -1
- package/dist/mtgate_api/core/bodySerializer.gen.d.ts +0 -26
- package/dist/mtgate_api/core/bodySerializer.gen.d.ts.map +0 -1
- package/dist/mtgate_api/core/bodySerializer.gen.js +0 -58
- package/dist/mtgate_api/core/bodySerializer.gen.js.map +0 -1
- package/dist/mtgate_api/core/params.gen.d.ts +0 -44
- package/dist/mtgate_api/core/params.gen.d.ts.map +0 -1
- package/dist/mtgate_api/core/params.gen.js +0 -101
- package/dist/mtgate_api/core/params.gen.js.map +0 -1
- package/dist/mtgate_api/core/pathSerializer.gen.d.ts +0 -34
- package/dist/mtgate_api/core/pathSerializer.gen.d.ts.map +0 -1
- package/dist/mtgate_api/core/pathSerializer.gen.js +0 -115
- package/dist/mtgate_api/core/pathSerializer.gen.js.map +0 -1
- package/dist/mtgate_api/core/queryKeySerializer.gen.d.ts +0 -19
- package/dist/mtgate_api/core/queryKeySerializer.gen.d.ts.map +0 -1
- package/dist/mtgate_api/core/queryKeySerializer.gen.js +0 -100
- package/dist/mtgate_api/core/queryKeySerializer.gen.js.map +0 -1
- package/dist/mtgate_api/core/serverSentEvents.gen.d.ts +0 -72
- package/dist/mtgate_api/core/serverSentEvents.gen.d.ts.map +0 -1
- package/dist/mtgate_api/core/serverSentEvents.gen.js +0 -138
- package/dist/mtgate_api/core/serverSentEvents.gen.js.map +0 -1
- package/dist/mtgate_api/core/types.gen.d.ts +0 -79
- package/dist/mtgate_api/core/types.gen.d.ts.map +0 -1
- package/dist/mtgate_api/core/types.gen.js +0 -3
- package/dist/mtgate_api/core/types.gen.js.map +0 -1
- package/dist/mtgate_api/core/utils.gen.d.ts +0 -20
- package/dist/mtgate_api/core/utils.gen.d.ts.map +0 -1
- package/dist/mtgate_api/core/utils.gen.js +0 -88
- package/dist/mtgate_api/core/utils.gen.js.map +0 -1
- package/dist/mtgate_api/index.d.ts +0 -3
- package/dist/mtgate_api/index.d.ts.map +0 -1
- package/dist/mtgate_api/index.js +0 -3
- package/dist/mtgate_api/index.js.map +0 -1
- package/dist/mtgate_api/sdk.gen.d.ts +0 -15
- package/dist/mtgate_api/sdk.gen.d.ts.map +0 -1
- package/dist/mtgate_api/sdk.gen.js +0 -3
- package/dist/mtgate_api/sdk.gen.js.map +0 -1
- package/dist/mtgate_api/types.gen.d.ts +0 -4
- package/dist/mtgate_api/types.gen.d.ts.map +0 -1
- package/dist/mtgate_api/types.gen.js +0 -3
- package/dist/mtgate_api/types.gen.js.map +0 -1
- package/dist/openclaw/client-info.d.ts +0 -38
- package/dist/openclaw/client-info.d.ts.map +0 -1
- package/dist/openclaw/client-info.js +0 -38
- package/dist/openclaw/client-info.js.map +0 -1
- package/dist/openclaw/device-auth-utils.d.ts +0 -12
- package/dist/openclaw/device-auth-utils.d.ts.map +0 -1
- package/dist/openclaw/device-auth-utils.js +0 -16
- package/dist/openclaw/device-auth-utils.js.map +0 -1
- package/dist/openclaw/device-auth.d.ts +0 -21
- package/dist/openclaw/device-auth.d.ts.map +0 -1
- package/dist/openclaw/device-auth.js +0 -87
- package/dist/openclaw/device-auth.js.map +0 -1
- package/dist/openclaw/device-identity.d.ts +0 -8
- package/dist/openclaw/device-identity.d.ts.map +0 -1
- package/dist/openclaw/device-identity.js +0 -87
- package/dist/openclaw/device-identity.js.map +0 -1
- package/dist/openclaw/gateway.d.ts +0 -100
- package/dist/openclaw/gateway.d.ts.map +0 -1
- package/dist/openclaw/gateway.js +0 -302
- package/dist/openclaw/gateway.js.map +0 -1
- package/dist/openclaw/types.d.ts +0 -473
- package/dist/openclaw/types.d.ts.map +0 -1
- package/dist/openclaw/types.js +0 -2
- package/dist/openclaw/types.js.map +0 -1
- package/src/cloud-account/platform-configs.ts +0 -73
- package/src/gomtmapi/@tanstack/react-query.gen.ts +0 -537
- package/src/gomtmapi/client/client.gen.ts +0 -311
- package/src/gomtmapi/client/index.ts +0 -25
- package/src/gomtmapi/client/types.gen.ts +0 -241
- package/src/gomtmapi/client/utils.gen.ts +0 -332
- package/src/gomtmapi/client.gen.ts +0 -16
- package/src/gomtmapi/core/auth.gen.ts +0 -42
- package/src/gomtmapi/core/bodySerializer.gen.ts +0 -100
- package/src/gomtmapi/core/params.gen.ts +0 -176
- package/src/gomtmapi/core/pathSerializer.gen.ts +0 -181
- package/src/gomtmapi/core/queryKeySerializer.gen.ts +0 -136
- package/src/gomtmapi/core/serverSentEvents.gen.ts +0 -266
- package/src/gomtmapi/core/types.gen.ts +0 -118
- package/src/gomtmapi/core/utils.gen.ts +0 -143
- package/src/gomtmapi/index.ts +0 -4
- package/src/gomtmapi/schemas.gen.ts +0 -532
- package/src/gomtmapi/sdk.gen.ts +0 -371
- package/src/gomtmapi/types.gen.ts +0 -854
- package/src/gomtmapi/zod.gen.ts +0 -448
- package/src/index.ts +0 -4
- package/src/lib/aisdk/types.ts +0 -8
- package/src/lib/logger/index.ts +0 -8
- package/src/lib/schema.ts +0 -37
- package/src/mtgate_api/client/client.gen.ts +0 -311
- package/src/mtgate_api/client/index.ts +0 -25
- package/src/mtgate_api/client/types.gen.ts +0 -241
- package/src/mtgate_api/client/utils.gen.ts +0 -332
- package/src/mtgate_api/client.gen.ts +0 -16
- package/src/mtgate_api/core/auth.gen.ts +0 -42
- package/src/mtgate_api/core/bodySerializer.gen.ts +0 -100
- package/src/mtgate_api/core/params.gen.ts +0 -176
- package/src/mtgate_api/core/pathSerializer.gen.ts +0 -181
- package/src/mtgate_api/core/queryKeySerializer.gen.ts +0 -136
- package/src/mtgate_api/core/serverSentEvents.gen.ts +0 -266
- package/src/mtgate_api/core/types.gen.ts +0 -118
- package/src/mtgate_api/core/utils.gen.ts +0 -143
- package/src/mtgate_api/index.ts +0 -4
- package/src/mtgate_api/sdk.gen.ts +0 -17
- package/src/mtgate_api/types.gen.ts +0 -5
- package/src/openclaw/client-info.ts +0 -54
- package/src/openclaw/device-auth-utils.ts +0 -26
- package/src/openclaw/device-auth.ts +0 -99
- package/src/openclaw/device-identity.ts +0 -108
- package/src/openclaw/gateway.ts +0 -392
- package/src/openclaw/types.ts +0 -518
- package/src/sbmng/@tanstack/react-query.gen.ts +0 -2967
- package/src/sbmng/client/client.gen.ts +0 -311
- package/src/sbmng/client/index.ts +0 -25
- package/src/sbmng/client/types.gen.ts +0 -241
- package/src/sbmng/client/utils.gen.ts +0 -332
- package/src/sbmng/client.gen.ts +0 -16
- package/src/sbmng/core/auth.gen.ts +0 -42
- package/src/sbmng/core/bodySerializer.gen.ts +0 -100
- package/src/sbmng/core/params.gen.ts +0 -176
- package/src/sbmng/core/pathSerializer.gen.ts +0 -181
- package/src/sbmng/core/queryKeySerializer.gen.ts +0 -136
- package/src/sbmng/core/serverSentEvents.gen.ts +0 -266
- package/src/sbmng/core/types.gen.ts +0 -118
- package/src/sbmng/core/utils.gen.ts +0 -143
- package/src/sbmng/index.ts +0 -4
- package/src/sbmng/schemas.gen.ts +0 -9671
- package/src/sbmng/sdk.gen.ts +0 -1755
- package/src/sbmng/types.gen.ts +0 -7886
- package/src/supabase/auth-provider.tsx +0 -67
- package/src/supabase/context.tsx +0 -51
- package/src/supabase/cursor-pagination.ts +0 -155
- package/src/supabase/schema/browser.ts +0 -45
- package/src/supabase/schema/index.ts +0 -25
- package/src/supabase/supabase-client.ts +0 -30
- package/src/supabase/supabase.ts +0 -67
- package/src/supabase/use-sb-query/build-query-opts.ts +0 -68
- package/src/supabase/use-sb-query/key.ts +0 -57
- package/src/supabase/use-sb-query/use-query.ts +0 -352
- package/src/supabase/use-sb-query/use-rpc-mutation.ts +0 -83
- package/src/supabase/use-sb-query/use-rpc-query.ts +0 -267
- package/src/supabase/utils.ts +0 -75
- package/src/types/database.schemas.ts +0 -4359
- package/src/types/database.types.ts +0 -4182
- package/src/types/index.ts +0 -85
|
@@ -1,352 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 将 supabase api封装位 react query的 形式.
|
|
3
|
-
* 原官方库: https://github.com/psteinroe/supabase-cache-helpers
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type {
|
|
7
|
-
AnyPostgrestResponse,
|
|
8
|
-
BuildNormalizedQueryOps,
|
|
9
|
-
PostgrestQueryParserOptions,
|
|
10
|
-
} from "@supabase-cache-helpers/postgrest-core";
|
|
11
|
-
import { PostgrestFilter, encodeObject, type DecodedKey } from "@supabase-cache-helpers/postgrest-core";
|
|
12
|
-
import type {
|
|
13
|
-
PostgrestError,
|
|
14
|
-
PostgrestMaybeSingleResponse,
|
|
15
|
-
PostgrestResponse,
|
|
16
|
-
PostgrestResponseSuccess,
|
|
17
|
-
PostgrestSingleResponse,
|
|
18
|
-
} from "@supabase/postgrest-js";
|
|
19
|
-
import {
|
|
20
|
-
useQueryClient,
|
|
21
|
-
useQuery as useReactQuery,
|
|
22
|
-
useSuspenseQuery as useReactSuspenseQuery,
|
|
23
|
-
type UseQueryOptions as UseReactQueryOptions,
|
|
24
|
-
type UseQueryResult as UseReactQueryResult,
|
|
25
|
-
type UseSuspenseQueryResult as UseReactSuspenseQueryResult,
|
|
26
|
-
type UseSuspenseQueryOptions as UserReactSuspenseQueryOptions,
|
|
27
|
-
} from "@tanstack/react-query";
|
|
28
|
-
import { buildQueryOpts, buildSuspenseQueryOpts } from "./build-query-opts";
|
|
29
|
-
import { decode, encode } from "./key";
|
|
30
|
-
|
|
31
|
-
export const KEY_PREFIX = "postgrest";
|
|
32
|
-
export const INFINITE_KEY_PREFIX = "page";
|
|
33
|
-
|
|
34
|
-
export type DecodedReactQueryKey = DecodedKey & {
|
|
35
|
-
isInfinite: boolean;
|
|
36
|
-
key: string[];
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export const POSTGREST_FILTER_KEY_PREFIX = "postgrest-filter";
|
|
40
|
-
|
|
41
|
-
type QueryKeySuffixOption = {
|
|
42
|
-
queryKeySuffix?: readonly unknown[];
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export const usePostgrestFilterCache = <R extends Record<string, unknown>>() => {
|
|
46
|
-
const queryClient = useQueryClient();
|
|
47
|
-
|
|
48
|
-
return (query: string, opts?: PostgrestQueryParserOptions) => {
|
|
49
|
-
const key = [POSTGREST_FILTER_KEY_PREFIX, query, opts ? encodeObject(opts) : null];
|
|
50
|
-
const cacheData = queryClient.getQueryData(key);
|
|
51
|
-
if (cacheData instanceof PostgrestFilter) {
|
|
52
|
-
return cacheData;
|
|
53
|
-
}
|
|
54
|
-
const filter = PostgrestFilter.fromQuery(query, opts);
|
|
55
|
-
queryClient.setQueryData(key, filter);
|
|
56
|
-
return filter as PostgrestFilter<R>;
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
export const useQueriesForTableLoader = (table: string) => {
|
|
61
|
-
const queryClient = useQueryClient();
|
|
62
|
-
const getPostgrestFilter = usePostgrestFilterCache();
|
|
63
|
-
|
|
64
|
-
return () =>
|
|
65
|
-
queryClient
|
|
66
|
-
.getQueryCache()
|
|
67
|
-
.getAll()
|
|
68
|
-
.map((c) => c.queryKey)
|
|
69
|
-
.reduce<ReturnType<BuildNormalizedQueryOps["queriesForTable"]>>((prev, curr) => {
|
|
70
|
-
const decodedKey = decode(curr);
|
|
71
|
-
if (decodedKey?.table === table) {
|
|
72
|
-
prev.push(getPostgrestFilter(decodedKey.queryKey).params);
|
|
73
|
-
}
|
|
74
|
-
return prev;
|
|
75
|
-
}, []);
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Applies Omit over a union, while preserving its union-ness.
|
|
80
|
-
*/
|
|
81
|
-
// biome-ignore lint/suspicious/noExplicitAny: keyof any 是 TypeScript 泛型约束的标准用法
|
|
82
|
-
type DistributiveOmit<T, K extends keyof any> = T extends any ? Omit<T, K> : never;
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Represents the return value of the `useQuery` hook when `query` is expected to return
|
|
86
|
-
* a single row.
|
|
87
|
-
*/
|
|
88
|
-
export type UseQuerySingleReturn<Result> = DistributiveOmit<
|
|
89
|
-
UseReactQueryResult<PostgrestSingleResponse<Result>["data"], PostgrestError>,
|
|
90
|
-
"refetch"
|
|
91
|
-
> &
|
|
92
|
-
Pick<UseReactQueryResult<PostgrestSingleResponse<Result>, PostgrestError>, "refetch"> &
|
|
93
|
-
Pick<PostgrestSingleResponse<Result>, "count">;
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Represents the return value of the `useQuery` hook when `query` is expected to return
|
|
97
|
-
* either a single row or an empty response.
|
|
98
|
-
*/
|
|
99
|
-
export type UseQueryMaybeSingleReturn<Result> = DistributiveOmit<
|
|
100
|
-
UseReactQueryResult<PostgrestMaybeSingleResponse<Result>["data"], PostgrestError>,
|
|
101
|
-
"refetch"
|
|
102
|
-
> &
|
|
103
|
-
Pick<UseReactQueryResult<PostgrestMaybeSingleResponse<Result>, PostgrestError>, "refetch"> &
|
|
104
|
-
Pick<PostgrestMaybeSingleResponse<Result>, "count">;
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Represents the return value of the `useQuery` hook when `query` is expected to return
|
|
108
|
-
* one or more rows.
|
|
109
|
-
*/
|
|
110
|
-
export type UseQueryReturn<Result> = DistributiveOmit<
|
|
111
|
-
UseReactQueryResult<PostgrestResponse<Result>["data"], PostgrestError>,
|
|
112
|
-
"refetch"
|
|
113
|
-
> &
|
|
114
|
-
Pick<UseReactQueryResult<PostgrestResponse<Result>, PostgrestError>, "refetch"> &
|
|
115
|
-
Pick<PostgrestResponse<Result>, "count">;
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Represents the return value of the `useQuery` hook when the type of the query response
|
|
119
|
-
* is not known.
|
|
120
|
-
*/
|
|
121
|
-
export type UseQueryAnyReturn<Result> = DistributiveOmit<
|
|
122
|
-
UseReactQueryResult<AnyPostgrestResponse<Result>["data"], PostgrestError>,
|
|
123
|
-
"refetch"
|
|
124
|
-
> &
|
|
125
|
-
Pick<UseReactQueryResult<AnyPostgrestResponse<Result>, PostgrestError>, "refetch"> &
|
|
126
|
-
Pick<AnyPostgrestResponse<Result>, "count">;
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* React hook to execute a PostgREST query and return a single item response.
|
|
130
|
-
*
|
|
131
|
-
* @param {PromiseLike<PostgrestSingleResponse<Result>>} query A promise that resolves to a PostgREST single item response.
|
|
132
|
-
* @param {Omit<UseReactQueryOptions<PostgrestSingleResponse<Result>, PostgrestError>, 'queryKey' | 'queryFn'>} [config] The React Query options.
|
|
133
|
-
* @returns {UseQuerySingleReturn<Result>} The hook result containing the single item response data.
|
|
134
|
-
*/
|
|
135
|
-
function useQuery<Result>(
|
|
136
|
-
query: PromiseLike<PostgrestSingleResponse<Result>>,
|
|
137
|
-
config?: Omit<UseReactQueryOptions<PostgrestSingleResponse<Result>, PostgrestError>, "queryKey" | "queryFn"> &
|
|
138
|
-
QueryKeySuffixOption,
|
|
139
|
-
): UseQuerySingleReturn<Result>;
|
|
140
|
-
/**
|
|
141
|
-
* React hook to execute a PostgREST query and return a maybe single item response.
|
|
142
|
-
*
|
|
143
|
-
* @param {PromiseLike<PostgrestMaybeSingleResponse<Result>>} query A promise that resolves to a PostgREST maybe single item response.
|
|
144
|
-
* @param {Omit<UseReactQueryOptions<PostgrestMaybeSingleResponse<Result>, PostgrestError>, 'queryKey' | 'queryFn'>} [config] The React Query options.
|
|
145
|
-
* @returns {UseQueryMaybeSingleReturn<Result>} The hook result containing the maybe single item response data.
|
|
146
|
-
*/
|
|
147
|
-
function useQuery<Result>(
|
|
148
|
-
query: PromiseLike<PostgrestMaybeSingleResponse<Result>>,
|
|
149
|
-
config?: Omit<UseReactQueryOptions<PostgrestMaybeSingleResponse<Result>, PostgrestError>, "queryKey" | "queryFn"> &
|
|
150
|
-
QueryKeySuffixOption,
|
|
151
|
-
): UseQueryMaybeSingleReturn<Result>;
|
|
152
|
-
/**
|
|
153
|
-
* React hook to execute a PostgREST query.
|
|
154
|
-
*
|
|
155
|
-
* @template Result The expected response data type.
|
|
156
|
-
* @param {PromiseLike<PostgrestResponse<Result>>} query A promise that resolves to a PostgREST response.
|
|
157
|
-
* @param {Omit<UseReactQueryOptions<PostgrestResponse<Result>, PostgrestError>, 'queryKey' | 'queryFn'>} [config] The React Query options.
|
|
158
|
-
* @returns {UseQueryReturn<Result>} The hook result containing the response data.
|
|
159
|
-
*/
|
|
160
|
-
function useQuery<Result>(
|
|
161
|
-
query: PromiseLike<PostgrestResponse<Result>>,
|
|
162
|
-
config?: Omit<UseReactQueryOptions<PostgrestResponse<Result>, PostgrestError>, "queryKey" | "queryFn"> &
|
|
163
|
-
QueryKeySuffixOption,
|
|
164
|
-
): UseQueryReturn<Result>;
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* React hook to execute a PostgREST query.
|
|
168
|
-
*
|
|
169
|
-
* @template Result The expected response data type.
|
|
170
|
-
* @param {PromiseLike<AnyPostgrestResponse<Result>>} query A promise that resolves to a PostgREST response of any kind.
|
|
171
|
-
* @param {Omit<UseReactQueryOptions<AnyPostgrestResponse<Result>, PostgrestError>, 'queryKey' | 'queryFn'>} [config] The React Query options.
|
|
172
|
-
* @returns {UseQueryAnyReturn<Result>} The hook result containing the response data.
|
|
173
|
-
*/
|
|
174
|
-
function useQuery<Result>(
|
|
175
|
-
query: PromiseLike<AnyPostgrestResponse<Result>>,
|
|
176
|
-
config?: Omit<UseReactQueryOptions<AnyPostgrestResponse<Result>, PostgrestError>, "queryKey" | "queryFn"> &
|
|
177
|
-
QueryKeySuffixOption,
|
|
178
|
-
): UseQueryAnyReturn<Result> {
|
|
179
|
-
const result = useReactQuery<AnyPostgrestResponse<Result>, PostgrestError>(buildQueryOpts<Result>(query, config));
|
|
180
|
-
|
|
181
|
-
// isPending and isLoadingError are the only cases in which no data is present
|
|
182
|
-
if (result.isPending || result.isLoadingError) {
|
|
183
|
-
return {
|
|
184
|
-
...result,
|
|
185
|
-
data: undefined,
|
|
186
|
-
count: null,
|
|
187
|
-
} as UseQueryAnyReturn<Result>;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
return {
|
|
191
|
-
...result,
|
|
192
|
-
data: result.data?.data,
|
|
193
|
-
count: result.data?.count,
|
|
194
|
-
} as UseQueryAnyReturn<Result>;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
export { useQuery };
|
|
198
|
-
|
|
199
|
-
// 增加 queryQuery 获取函数
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* 获取 PostgREST 查询的完整 QueryKey
|
|
203
|
-
* @param query Supabase PostgrestBuilder 实例 (例如: sb.from('...').select() 或 sb.rpc(...))
|
|
204
|
-
* @param isInfinite 是否为无限查询 (默认 false)
|
|
205
|
-
*/
|
|
206
|
-
export function getSbQueryKey<Result>(query: PromiseLike<AnyPostgrestResponse<Result>>, isInfinite = false): string[] {
|
|
207
|
-
return encode(query, isInfinite);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* 获取 PostgREST 查询的 "Base Key" (仅包含前缀、Schema、Table/RPC名称)
|
|
212
|
-
* 用于 invalidateQueries 时模糊匹配整个表或RPC的所有查询,忽略具体的 filter/page 参数。
|
|
213
|
-
*
|
|
214
|
-
* 结构: ['postgrest', 'null'|'page', schema, table|rpc, ...]
|
|
215
|
-
* 返回: 前4个元素
|
|
216
|
-
*/
|
|
217
|
-
export function getSbTableKey<Result>(query: PromiseLike<AnyPostgrestResponse<Result>>): string[] {
|
|
218
|
-
const fullKey = encode(query, false);
|
|
219
|
-
// 截取前4个元素作为基础Key: [prefix, infinitePrefix, schema, table]
|
|
220
|
-
// 这样 invalidateQueries(baseKey) 将会匹配该表/RPC下的所有查询变体
|
|
221
|
-
return fullKey.slice(0, 4);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
// 增加 suspense query 的支持 ========================================================================================
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* Represents the return value of the `useSuspenseQuery` hook when `query` is expected to return
|
|
228
|
-
* a single row.
|
|
229
|
-
*/
|
|
230
|
-
export type useSuspenseQuerySingleReturn<Result> = DistributiveOmit<
|
|
231
|
-
UseReactSuspenseQueryResult<PostgrestMaybeSingleResponseV4<Result>["data"], PostgrestError>,
|
|
232
|
-
"refetch"
|
|
233
|
-
> &
|
|
234
|
-
Pick<
|
|
235
|
-
UseReactSuspenseQueryResult<
|
|
236
|
-
// PostgrestSingleResponse<Result>,
|
|
237
|
-
Result,
|
|
238
|
-
PostgrestError
|
|
239
|
-
>,
|
|
240
|
-
"refetch"
|
|
241
|
-
> &
|
|
242
|
-
Pick<PostgrestSingleResponse<Result>, "count">;
|
|
243
|
-
|
|
244
|
-
export type PostgrestMaybeSingleResponseV4<T> = PostgrestResponseSuccess<T>;
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* Represents the return value of the `useSuspenseQuery` hook when `query` is expected to return
|
|
248
|
-
* either a single row or an empty response.
|
|
249
|
-
*/
|
|
250
|
-
export type useSuspenseQueryMaybeSingleReturn<Result> = DistributiveOmit<
|
|
251
|
-
UseReactSuspenseQueryResult<PostgrestMaybeSingleResponseV4<NonNullable<Result>>["data"], PostgrestError>,
|
|
252
|
-
"refetch"
|
|
253
|
-
> &
|
|
254
|
-
Pick<UseReactSuspenseQueryResult<PostgrestMaybeSingleResponseV4<NonNullable<Result>>, PostgrestError>, "refetch"> &
|
|
255
|
-
Pick<PostgrestMaybeSingleResponseV4<Result>, "count">;
|
|
256
|
-
|
|
257
|
-
/**
|
|
258
|
-
* Represents the return value of the `useSuspenseQuery` hook when `query` is expected to return
|
|
259
|
-
* one or more rows.
|
|
260
|
-
*/
|
|
261
|
-
export type useSuspenseQueryReturn<Result> = DistributiveOmit<
|
|
262
|
-
UseReactSuspenseQueryResult<PostgrestResponse<Result>["data"], PostgrestError>,
|
|
263
|
-
"refetch"
|
|
264
|
-
> &
|
|
265
|
-
Pick<UseReactSuspenseQueryResult<PostgrestResponse<Result>, PostgrestError>, "refetch"> &
|
|
266
|
-
Pick<PostgrestResponse<Result>, "count">;
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* Represents the return value of the `useSuspenseQuery` hook when the type of the query response
|
|
270
|
-
* is not known.
|
|
271
|
-
*/
|
|
272
|
-
export type useSuspenseQueryAnyReturn<Result> = DistributiveOmit<
|
|
273
|
-
UseReactSuspenseQueryResult<PostgrestResponse<Result>["data"], PostgrestError>,
|
|
274
|
-
"refetch"
|
|
275
|
-
> &
|
|
276
|
-
Pick<UseReactSuspenseQueryResult<PostgrestResponse<Result>, PostgrestError>, "refetch"> &
|
|
277
|
-
Pick<PostgrestResponse<Result>, "count">;
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* React hook to execute a PostgREST query and return a single item response.
|
|
281
|
-
*
|
|
282
|
-
* @param {PromiseLike<PostgrestSingleResponse<Result>>} query A promise that resolves to a PostgREST single item response.
|
|
283
|
-
* @param {Omit<UseReactQueryOptions<PostgrestSingleResponse<Result>, PostgrestError>, 'queryKey' | 'queryFn'>} [config] The React Query options.
|
|
284
|
-
* @returns {useSuspenseQuerySingleReturn<Result>} The hook result containing the single item response data.
|
|
285
|
-
*/
|
|
286
|
-
function useSbSuspenseQuery<Result>(
|
|
287
|
-
query: PromiseLike<PostgrestSingleResponse<Result>>,
|
|
288
|
-
config?: Omit<UseReactQueryOptions<PostgrestSingleResponse<Result>, PostgrestError>, "queryKey" | "queryFn"> &
|
|
289
|
-
QueryKeySuffixOption,
|
|
290
|
-
): useSuspenseQuerySingleReturn<NonNullable<Result>>;
|
|
291
|
-
/**
|
|
292
|
-
* React hook to execute a PostgREST query and return a maybe single item response.
|
|
293
|
-
*
|
|
294
|
-
* @param {PromiseLike<PostgrestMaybeSingleResponse<Result>>} query A promise that resolves to a PostgREST maybe single item response.
|
|
295
|
-
* @param {Omit<UseReactQueryOptions<PostgrestMaybeSingleResponse<Result>, PostgrestError>, 'queryKey' | 'queryFn'>} [config] The React Query options.
|
|
296
|
-
* @returns {useSuspenseQueryMaybeSingleReturn<Result>} The hook result containing the maybe single item response data.
|
|
297
|
-
*/
|
|
298
|
-
function useSbSuspenseQuery<Result>(
|
|
299
|
-
query: PromiseLike<PostgrestMaybeSingleResponse<Result>>,
|
|
300
|
-
config?: Omit<UseReactQueryOptions<PostgrestMaybeSingleResponse<Result>, PostgrestError>, "queryKey" | "queryFn"> &
|
|
301
|
-
QueryKeySuffixOption,
|
|
302
|
-
): useSuspenseQueryMaybeSingleReturn<NonNullable<Result>>;
|
|
303
|
-
/**
|
|
304
|
-
* React hook to execute a PostgREST query.
|
|
305
|
-
*
|
|
306
|
-
* @template Result The expected response data type.
|
|
307
|
-
* @param {PromiseLike<PostgrestResponse<Result>>} query A promise that resolves to a PostgREST response.
|
|
308
|
-
* @param {Omit<UseReactQueryOptions<PostgrestResponse<Result>, PostgrestError>, 'queryKey' | 'queryFn'>} [config] The React Query options.
|
|
309
|
-
* @returns {useSuspenseQueryReturn<Result>} The hook result containing the response data.
|
|
310
|
-
*/
|
|
311
|
-
function useSbSuspenseQuery<Result>(
|
|
312
|
-
query: PromiseLike<PostgrestResponse<Result>>,
|
|
313
|
-
config?: Omit<UseReactQueryOptions<PostgrestResponse<Result>, PostgrestError>, "queryKey" | "queryFn"> &
|
|
314
|
-
QueryKeySuffixOption,
|
|
315
|
-
): useSuspenseQueryReturn<NonNullable<Result>>;
|
|
316
|
-
|
|
317
|
-
/**
|
|
318
|
-
* React hook to execute a PostgREST query.
|
|
319
|
-
*
|
|
320
|
-
* @template Result The expected response data type.
|
|
321
|
-
* @param {PromiseLike<AnyPostgrestResponse<Result>>} query A promise that resolves to a PostgREST response of any kind.
|
|
322
|
-
* @param {Omit<UseReactQueryOptions<AnyPostgrestResponse<Result>, PostgrestError>, 'queryKey' | 'queryFn'>} [config] The React Query options.
|
|
323
|
-
* @returns {useSuspenseQueryAnyReturn<Result>} The hook result containing the response data.
|
|
324
|
-
*/
|
|
325
|
-
function useSbSuspenseQuery<Result>(
|
|
326
|
-
query: PromiseLike<PostgrestResponse<Result>>,
|
|
327
|
-
config?: Omit<UserReactSuspenseQueryOptions<AnyPostgrestResponse<Result>, PostgrestError>, "queryKey" | "queryFn"> &
|
|
328
|
-
QueryKeySuffixOption,
|
|
329
|
-
): useSuspenseQueryReturn<NonNullable<Result>> {
|
|
330
|
-
const result = useReactSuspenseQuery<AnyPostgrestResponse<Result>, PostgrestError>(
|
|
331
|
-
buildSuspenseQueryOpts<Result>(query, config),
|
|
332
|
-
);
|
|
333
|
-
|
|
334
|
-
// isPending and isLoadingError are the only cases in which no data is present
|
|
335
|
-
// if (result.isPending || result.isLoadingError) {
|
|
336
|
-
// return {
|
|
337
|
-
// ...result,
|
|
338
|
-
// data: undefined,
|
|
339
|
-
// count: null,
|
|
340
|
-
// } //as useSuspenseQueryAnyReturn<Result>;
|
|
341
|
-
// }
|
|
342
|
-
|
|
343
|
-
return {
|
|
344
|
-
...result,
|
|
345
|
-
data: result.data.data, // NonNullable<Result|Result[]>,
|
|
346
|
-
count: result.data.count,
|
|
347
|
-
} as useSuspenseQueryAnyReturn<NonNullable<Result>>;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
export const useSbQuery = useQuery;
|
|
351
|
-
|
|
352
|
-
export { useSbSuspenseQuery };
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Supabase RPC Mutation Hook
|
|
3
|
-
* 简化 RPC 写操作(upsert, delete 等)的调用
|
|
4
|
-
*
|
|
5
|
-
* 使用示例:
|
|
6
|
-
* ```tsx
|
|
7
|
-
* const updateProject = useRpcMutation("audit_project_upsert");
|
|
8
|
-
*
|
|
9
|
-
* // 调用
|
|
10
|
-
* await updateProject.mutateAsync({
|
|
11
|
-
* p_id: projectId,
|
|
12
|
-
* p_name: "New Name"
|
|
13
|
-
* });
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import type { PostgrestError } from "@supabase/supabase-js";
|
|
18
|
-
import { useMutation, type UseMutationOptions, type UseMutationResult } from "@tanstack/react-query";
|
|
19
|
-
import { useSupabaseBrowser } from "../context";
|
|
20
|
-
import type { RPCFunctionArgs, RPCFunctionName, RPCFunctionReturns } from "./use-rpc-query";
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* RPC Mutation 的返回类型
|
|
24
|
-
*/
|
|
25
|
-
export interface RpcMutationResult<TData> {
|
|
26
|
-
data: TData | null;
|
|
27
|
-
error: PostgrestError | null;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* 基于 RPC 函数名进行 Mutation 操作的 Hook
|
|
32
|
-
*
|
|
33
|
-
* @template TFunc RPC 函数名类型
|
|
34
|
-
* @template TData 返回数据类型
|
|
35
|
-
* @param functionName RPC 函数名
|
|
36
|
-
* @param options React Query Mutation 配置选项
|
|
37
|
-
* @returns Mutation 结果
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```tsx
|
|
41
|
-
* // 示例1: 基础使用
|
|
42
|
-
* const updateProject = useRpcMutation("audit_project_upsert");
|
|
43
|
-
*
|
|
44
|
-
* // 在表单提交中使用
|
|
45
|
-
* const handleSubmit = async (values) => {
|
|
46
|
-
* const { data, error } = await updateProject.mutateAsync({
|
|
47
|
-
* p_id: project.id,
|
|
48
|
-
* p_name: values.name,
|
|
49
|
-
* p_target: values.target
|
|
50
|
-
* });
|
|
51
|
-
*
|
|
52
|
-
* if (error) {
|
|
53
|
-
* toast.error(error.message);
|
|
54
|
-
* } else {
|
|
55
|
-
* toast.success("Updated successfully");
|
|
56
|
-
* }
|
|
57
|
-
* };
|
|
58
|
-
*
|
|
59
|
-
* // 示例2: 带类型推断
|
|
60
|
-
* type ProjectResult = { id: string; name: string };
|
|
61
|
-
* const updateProject = useRpcMutation<"audit_project_upsert", ProjectResult>("audit_project_upsert");
|
|
62
|
-
* ```
|
|
63
|
-
*/
|
|
64
|
-
export function useRpcMutation<
|
|
65
|
-
TFunc extends RPCFunctionName,
|
|
66
|
-
TData = RPCFunctionReturns<TFunc>,
|
|
67
|
-
TError = PostgrestError,
|
|
68
|
-
TContext = unknown,
|
|
69
|
-
>(
|
|
70
|
-
functionName: TFunc,
|
|
71
|
-
options?: Omit<UseMutationOptions<RpcMutationResult<TData>, TError, RPCFunctionArgs<TFunc>, TContext>, "mutationFn">,
|
|
72
|
-
): UseMutationResult<RpcMutationResult<TData>, TError, RPCFunctionArgs<TFunc>, TContext> {
|
|
73
|
-
const sb = useSupabaseBrowser();
|
|
74
|
-
|
|
75
|
-
return useMutation<RpcMutationResult<TData>, TError, RPCFunctionArgs<TFunc>, TContext>({
|
|
76
|
-
mutationFn: async (args) => {
|
|
77
|
-
// biome-ignore lint/suspicious/noExplicitAny: 绕过 Supabase 内部类型系统
|
|
78
|
-
const result = await sb.rpc(functionName, args as any);
|
|
79
|
-
return result as RpcMutationResult<TData>;
|
|
80
|
-
},
|
|
81
|
-
...options,
|
|
82
|
-
});
|
|
83
|
-
}
|