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,67 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import type { Session } from "@supabase/supabase-js";
|
|
4
|
-
import { createContext, useContext, useEffect, useMemo, useState, type PropsWithChildren, type ReactNode } from "react";
|
|
5
|
-
import { useSupabaseBrowser } from "./context";
|
|
6
|
-
|
|
7
|
-
interface SupabaseAuthContextType {
|
|
8
|
-
session: Session | null;
|
|
9
|
-
token: string | undefined;
|
|
10
|
-
isLoading: boolean;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const SupabaseAuthContext = createContext<SupabaseAuthContextType | undefined>(undefined);
|
|
14
|
-
|
|
15
|
-
export function useSupabaseAuth() {
|
|
16
|
-
const context = useContext(SupabaseAuthContext);
|
|
17
|
-
if (context === undefined) {
|
|
18
|
-
throw new Error("useSupabaseAuth must be used within a SupabaseAuthProvider");
|
|
19
|
-
}
|
|
20
|
-
return context;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function SupabaseAuthProvider({ children }: PropsWithChildren): ReactNode {
|
|
24
|
-
const sb = useSupabaseBrowser();
|
|
25
|
-
const [session, setSession] = useState<Session | null>(null);
|
|
26
|
-
const [isLoading, setIsLoading] = useState(true);
|
|
27
|
-
|
|
28
|
-
useEffect(() => {
|
|
29
|
-
let mounted = true;
|
|
30
|
-
|
|
31
|
-
async function loadSession() {
|
|
32
|
-
const {
|
|
33
|
-
data: { session },
|
|
34
|
-
} = await sb.auth.getSession();
|
|
35
|
-
if (mounted) {
|
|
36
|
-
setSession(session);
|
|
37
|
-
setIsLoading(false);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
loadSession();
|
|
41
|
-
|
|
42
|
-
const {
|
|
43
|
-
data: { subscription },
|
|
44
|
-
} = sb.auth.onAuthStateChange((_event, session) => {
|
|
45
|
-
if (mounted) {
|
|
46
|
-
setSession(session);
|
|
47
|
-
setIsLoading(false);
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
return () => {
|
|
52
|
-
mounted = false;
|
|
53
|
-
subscription.unsubscribe();
|
|
54
|
-
};
|
|
55
|
-
}, [sb]);
|
|
56
|
-
|
|
57
|
-
const value = useMemo(
|
|
58
|
-
() => ({
|
|
59
|
-
session,
|
|
60
|
-
token: session?.access_token,
|
|
61
|
-
isLoading,
|
|
62
|
-
}),
|
|
63
|
-
[session, isLoading],
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
return <SupabaseAuthContext.Provider value={value}>{children}</SupabaseAuthContext.Provider>;
|
|
67
|
-
}
|
package/src/supabase/context.tsx
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import { createBrowserClient } from "@supabase/ssr";
|
|
4
|
-
import { createContext, type ReactNode, useContext, useMemo } from "react";
|
|
5
|
-
import type { TypedSupabaseClient } from "../types";
|
|
6
|
-
import type { Database } from "../types/database.types";
|
|
7
|
-
|
|
8
|
-
let client: TypedSupabaseClient | undefined;
|
|
9
|
-
|
|
10
|
-
export function getSupabaseBrowserClient(url?: string, key?: string): TypedSupabaseClient {
|
|
11
|
-
if (url && key) {
|
|
12
|
-
return createBrowserClient<Database>(url, key);
|
|
13
|
-
}
|
|
14
|
-
if (!client) {
|
|
15
|
-
client = createBrowserClient<Database>(
|
|
16
|
-
// biome-ignore lint/style/noNonNullAssertion: .
|
|
17
|
-
process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
|
18
|
-
// biome-ignore lint/style/noNonNullAssertion: .
|
|
19
|
-
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
// biome-ignore lint/style/noNonNullAssertion: 已经确保了初始化
|
|
23
|
-
return client!;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const SupabaseContext = createContext<TypedSupabaseClient | undefined>(undefined);
|
|
27
|
-
|
|
28
|
-
export function useSupabaseContext(): TypedSupabaseClient {
|
|
29
|
-
const ctx = useContext(SupabaseContext);
|
|
30
|
-
if (!ctx) {
|
|
31
|
-
throw new Error("useSupabaseContext must be used within a SupabaseProvider");
|
|
32
|
-
}
|
|
33
|
-
return ctx;
|
|
34
|
-
}
|
|
35
|
-
export const useSupabaseBrowser = useSupabaseContext;
|
|
36
|
-
|
|
37
|
-
interface SupabaseClientProviderProps {
|
|
38
|
-
children: ReactNode;
|
|
39
|
-
publicKey?: string;
|
|
40
|
-
url?: string;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export const SupabaseClientProvider = ({ children, publicKey, url }: SupabaseClientProviderProps): ReactNode => {
|
|
44
|
-
const client = useMemo(() => getSupabaseBrowserClient(url, publicKey), [url, publicKey]);
|
|
45
|
-
|
|
46
|
-
return (
|
|
47
|
-
<SupabaseContext.Provider value={client}>
|
|
48
|
-
{children}
|
|
49
|
-
</SupabaseContext.Provider>
|
|
50
|
-
);
|
|
51
|
-
};
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 游标分页工具函数
|
|
3
|
-
*
|
|
4
|
-
* 提供类型安全的游标分页支持,配合 react-query 的 useInfiniteQuery 使用。
|
|
5
|
-
*
|
|
6
|
-
* @module mtmsdk/supabase/cursor-pagination
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* 游标类型定义
|
|
11
|
-
*
|
|
12
|
-
* 使用复合游标 (updated_at + id) 确保分页的唯一性和稳定性
|
|
13
|
-
*/
|
|
14
|
-
export interface CursorPagination {
|
|
15
|
-
cursor: string | null; // ISO 时间戳字符串, 如 "2026-01-20T08:00:00Z"
|
|
16
|
-
cursorId: string | null; // UUID 字符串
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* 从数据列表中提取下一页游标
|
|
21
|
-
*
|
|
22
|
-
* @param items - 当前页的数据列表
|
|
23
|
-
* @param limit - 每页数量
|
|
24
|
-
* @param cursorField - 游标字段名 (默认 "updated_at")
|
|
25
|
-
* @param idField - ID 字段名 (默认 "id")
|
|
26
|
-
* @returns 下一页游标, 如果没有更多数据则返回 undefined
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```tsx
|
|
30
|
-
* const { data, fetchNextPage, hasNextPage } = useInfiniteQuery({
|
|
31
|
-
* queryKey: ['projects', kw],
|
|
32
|
-
* queryFn: async ({ pageParam }) => {
|
|
33
|
-
* const { data } = await sb.rpc('audit_project_list_cursor', {
|
|
34
|
-
* p_cursor: pageParam?.cursor ?? null,
|
|
35
|
-
* p_cursor_id: pageParam?.cursorId ?? null,
|
|
36
|
-
* p_limit: 20,
|
|
37
|
-
* p_kw: kw
|
|
38
|
-
* });
|
|
39
|
-
* return data ?? [];
|
|
40
|
-
* },
|
|
41
|
-
* getNextPageParam: (lastPage) => getNextCursor(lastPage, 20),
|
|
42
|
-
* initialPageParam: null as CursorPagination | null
|
|
43
|
-
* });
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
export function getNextCursor<
|
|
47
|
-
T extends Record<string, unknown>,
|
|
48
|
-
>(
|
|
49
|
-
items: T[] | null | undefined,
|
|
50
|
-
limit: number,
|
|
51
|
-
cursorField: keyof T = "updated_at" as keyof T,
|
|
52
|
-
idField: keyof T = "id" as keyof T,
|
|
53
|
-
): CursorPagination | undefined {
|
|
54
|
-
// 如果数据为空或数量小于 limit,说明已到达最后一页
|
|
55
|
-
if (!items || items.length < limit) {
|
|
56
|
-
return undefined;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// 获取最后一条记录
|
|
60
|
-
const lastItem = items[items.length - 1];
|
|
61
|
-
if (!lastItem) {
|
|
62
|
-
return undefined;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const cursorValue = lastItem[cursorField];
|
|
66
|
-
const idValue = lastItem[idField];
|
|
67
|
-
|
|
68
|
-
// 验证游标值有效性
|
|
69
|
-
if (cursorValue === undefined || cursorValue === null) {
|
|
70
|
-
return undefined;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return {
|
|
74
|
-
cursor: String(cursorValue),
|
|
75
|
-
cursorId: idValue != null ? String(idValue) : null,
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* 将所有分页数据合并为单一列表
|
|
81
|
-
*
|
|
82
|
-
* @param pages - useInfiniteQuery 返回的 pages 数组
|
|
83
|
-
* @returns 合并后的扁平数据列表
|
|
84
|
-
*
|
|
85
|
-
* @example
|
|
86
|
-
* ```tsx
|
|
87
|
-
* const { data } = useInfiniteQuery({ ... });
|
|
88
|
-
* const allProjects = flattenPages(data?.pages);
|
|
89
|
-
* ```
|
|
90
|
-
*/
|
|
91
|
-
export function flattenPages<T>(
|
|
92
|
-
pages: T[][] | undefined,
|
|
93
|
-
): T[] {
|
|
94
|
-
if (!pages) return [];
|
|
95
|
-
return pages.flat();
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* 无限滚动分页状态
|
|
100
|
-
*/
|
|
101
|
-
export interface InfiniteScrollState {
|
|
102
|
-
isLoading: boolean;
|
|
103
|
-
isFetchingNextPage: boolean;
|
|
104
|
-
hasNextPage: boolean;
|
|
105
|
-
error: Error | null;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* 创建 IntersectionObserver 用于无限滚动
|
|
110
|
-
*
|
|
111
|
-
* @param onIntersect - 当元素进入视口时的回调
|
|
112
|
-
* @param options - IntersectionObserver 配置选项
|
|
113
|
-
* @returns cleanup 函数
|
|
114
|
-
*
|
|
115
|
-
* @example
|
|
116
|
-
* ```tsx
|
|
117
|
-
* const loadMoreRef = useRef<HTMLDivElement>(null);
|
|
118
|
-
*
|
|
119
|
-
* useEffect(() => {
|
|
120
|
-
* if (!loadMoreRef.current) return;
|
|
121
|
-
* return createInfiniteScrollObserver(
|
|
122
|
-
* () => {
|
|
123
|
-
* if (hasNextPage && !isFetchingNextPage) {
|
|
124
|
-
* fetchNextPage();
|
|
125
|
-
* }
|
|
126
|
-
* },
|
|
127
|
-
* { root: scrollContainerRef.current }
|
|
128
|
-
* )(loadMoreRef.current);
|
|
129
|
-
* }, [hasNextPage, isFetchingNextPage, fetchNextPage]);
|
|
130
|
-
* ```
|
|
131
|
-
*/
|
|
132
|
-
export function createInfiniteScrollObserver(
|
|
133
|
-
onIntersect: () => void,
|
|
134
|
-
options?: IntersectionObserverInit,
|
|
135
|
-
): (element: Element) => () => void {
|
|
136
|
-
return (element: Element) => {
|
|
137
|
-
const observer = new IntersectionObserver((entries) => {
|
|
138
|
-
const [entry] = entries;
|
|
139
|
-
if (entry?.isIntersecting) {
|
|
140
|
-
onIntersect();
|
|
141
|
-
}
|
|
142
|
-
}, {
|
|
143
|
-
root: null,
|
|
144
|
-
rootMargin: "100px",
|
|
145
|
-
threshold: 0.1,
|
|
146
|
-
...options,
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
observer.observe(element);
|
|
150
|
-
|
|
151
|
-
return () => {
|
|
152
|
-
observer.disconnect();
|
|
153
|
-
};
|
|
154
|
-
};
|
|
155
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import z from "zod";
|
|
2
|
-
|
|
3
|
-
export const zRpcBaseResponse = z.object({
|
|
4
|
-
error: z.object({
|
|
5
|
-
message: z.string(),
|
|
6
|
-
}),
|
|
7
|
-
});
|
|
8
|
-
export const zBrowserUpsertArgs = z
|
|
9
|
-
.object({
|
|
10
|
-
id: z.string().nullish(),//.transform( x => x ?? undefined ),
|
|
11
|
-
title: z.string(),
|
|
12
|
-
profile_id: z.string().nullish(),//.transform( x => x ?? undefined ),
|
|
13
|
-
description: z.string().nullish()//.transform( x => x ?? undefined ),
|
|
14
|
-
})
|
|
15
|
-
.meta({ ref: "BrowserUpsertArgs" });
|
|
16
|
-
|
|
17
|
-
export const zBrowserListReq = z
|
|
18
|
-
.object({
|
|
19
|
-
kw: z.string().optional(),
|
|
20
|
-
})
|
|
21
|
-
.describe("BrowserListReq")
|
|
22
|
-
.meta({ ref: "BrowserListReq" });
|
|
23
|
-
|
|
24
|
-
const zBrowserItem = z
|
|
25
|
-
.object({
|
|
26
|
-
id: z.string(),
|
|
27
|
-
title: z.string(),
|
|
28
|
-
})
|
|
29
|
-
.describe("BrowserItem")
|
|
30
|
-
.meta({ ref: "BrowserItem" });
|
|
31
|
-
|
|
32
|
-
export const zBrowserData = z
|
|
33
|
-
.object({
|
|
34
|
-
id: z.string(),
|
|
35
|
-
title: z.string(),
|
|
36
|
-
})
|
|
37
|
-
.describe("BrowserData")
|
|
38
|
-
.meta({ ref: "BrowserData" });
|
|
39
|
-
|
|
40
|
-
export const zBrowserListResponse = zRpcBaseResponse
|
|
41
|
-
.extend({
|
|
42
|
-
data: z.array(zBrowserItem),
|
|
43
|
-
})
|
|
44
|
-
// .describe("BrowserProfileResponse")
|
|
45
|
-
.meta({ ref: "BrowserList" });
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import z from "zod";
|
|
2
|
-
|
|
3
|
-
const singleRowPreprocessor = (val: unknown) => {
|
|
4
|
-
if (Array.isArray(val)) {
|
|
5
|
-
if (val.length === 0) return null;
|
|
6
|
-
if (val.length === 1) return val[0];
|
|
7
|
-
}
|
|
8
|
-
return val;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export const domainConfigSchema = z.preprocess(
|
|
12
|
-
singleRowPreprocessor,
|
|
13
|
-
z
|
|
14
|
-
.object({
|
|
15
|
-
primary_domain: z.string().min(1, "主域名不能为空"),
|
|
16
|
-
worker_subdomain_prefix: z.string().optional().default(""),
|
|
17
|
-
})
|
|
18
|
-
.nullable(),
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
export const smsProviderConfigSchema = z.object({
|
|
23
|
-
default_provider: z.enum(["manual", "demo"]).optional().default("manual"),
|
|
24
|
-
});
|
|
25
|
-
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { createServerClient } from "@supabase/ssr";
|
|
2
|
-
import type { cookies } from "next/headers";
|
|
3
|
-
import type { Database } from "../types/database.types";
|
|
4
|
-
|
|
5
|
-
export function useSupabaseServer(
|
|
6
|
-
cookieStore: Awaited<ReturnType<typeof cookies>>,
|
|
7
|
-
) {
|
|
8
|
-
return createServerClient<Database>(
|
|
9
|
-
process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
|
10
|
-
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
|
|
11
|
-
{
|
|
12
|
-
cookies: {
|
|
13
|
-
getAll() {
|
|
14
|
-
return cookieStore.getAll();
|
|
15
|
-
},
|
|
16
|
-
setAll(cookiesToSet) {
|
|
17
|
-
try {
|
|
18
|
-
for (const co of cookiesToSet) {
|
|
19
|
-
cookieStore.set(co.name, co.value, co.options);
|
|
20
|
-
}
|
|
21
|
-
} catch (e) {
|
|
22
|
-
//!!! 提示,对于nextjs + honoapi 后端方式使用,可能出现以下错误:
|
|
23
|
-
// Cookies can only be modified in a Server Action or Route Handler. Read more: https://nextjs.org/docs/app/api-reference/functions/cookies#options
|
|
24
|
-
//可以直接忽略.
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
);
|
|
30
|
-
}
|
package/src/supabase/supabase.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { createServerClient, parseCookieHeader } from "@supabase/ssr";
|
|
2
|
-
import { createClient } from "@supabase/supabase-js";
|
|
3
|
-
import type { Context } from "hono";
|
|
4
|
-
import { setCookie } from "hono/cookie";
|
|
5
|
-
import type { TypedSupabaseClient } from "../types";
|
|
6
|
-
import type { Database } from "../types/database.types";
|
|
7
|
-
|
|
8
|
-
export const getSupabaseUrl = () => {
|
|
9
|
-
if (!process.env.NEXT_PUBLIC_SUPABASE_URL) {
|
|
10
|
-
throw new Error("NEXT_PUBLIC_SUPABASE_URL missing!");
|
|
11
|
-
}
|
|
12
|
-
return process.env.NEXT_PUBLIC_SUPABASE_URL;
|
|
13
|
-
};
|
|
14
|
-
export const getSupabasePublicKey = () => {
|
|
15
|
-
if (!process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY) {
|
|
16
|
-
throw new Error("NEXT_PUBLIC_SUPABASE_ANON_KEY missing!");
|
|
17
|
-
}
|
|
18
|
-
return process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export const getSupabaseProjectRef = () => {
|
|
22
|
-
const uri = new URL(getSupabaseUrl());
|
|
23
|
-
const supabasePrject = uri.hostname.split(".")[0];
|
|
24
|
-
return supabasePrject;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export const getSupabase = (c: Context) => {
|
|
28
|
-
const client: TypedSupabaseClient = createServerClient<Database, "public">(getSupabaseUrl(), getSupabasePublicKey(), {
|
|
29
|
-
cookies: {
|
|
30
|
-
//@ts-expect-error
|
|
31
|
-
getAll() {
|
|
32
|
-
return parseCookieHeader(c.req.header("Cookie") ?? "");
|
|
33
|
-
},
|
|
34
|
-
setAll(cookiesToSet) {
|
|
35
|
-
for (const co of cookiesToSet) {
|
|
36
|
-
//@ts-expect-error
|
|
37
|
-
setCookie(c, co.name, co.value, co.options);
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
global: {
|
|
42
|
-
// 由于gomtm supabase 客户端已经登录.所以这里直接传递 Authorization 头,即可.
|
|
43
|
-
headers: {
|
|
44
|
-
...(c.req.header("Authorization") && {
|
|
45
|
-
Authorization: c.req.header("Authorization"),
|
|
46
|
-
}),
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
return client;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export const getSupabaseAdmin = () => {
|
|
55
|
-
const serviceRoleKey = process.env.SUPABASE_SERVICE_ROLE_KEY;
|
|
56
|
-
if (!serviceRoleKey) {
|
|
57
|
-
throw new Error("require SUPABASE_SERVICE_ROLE_KEY");
|
|
58
|
-
}
|
|
59
|
-
const client: TypedSupabaseClient = createClient<Database, "public">(getSupabaseUrl(), serviceRoleKey, {
|
|
60
|
-
auth: {
|
|
61
|
-
autoRefreshToken: false,
|
|
62
|
-
persistSession: false,
|
|
63
|
-
},
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
return client;
|
|
67
|
-
};
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type AnyPostgrestResponse,
|
|
3
|
-
isPostgrestBuilder,
|
|
4
|
-
isPostgrestTransformBuilder,
|
|
5
|
-
} from "@supabase-cache-helpers/postgrest-core";
|
|
6
|
-
import type { PostgrestError } from "@supabase/postgrest-js";
|
|
7
|
-
import type {
|
|
8
|
-
UseQueryOptions as UseReactQueryOptions,
|
|
9
|
-
UseSuspenseQueryOptions,
|
|
10
|
-
} from "@tanstack/react-query";
|
|
11
|
-
|
|
12
|
-
import { encode } from "./key";
|
|
13
|
-
|
|
14
|
-
type QueryKeySuffixOption = {
|
|
15
|
-
queryKeySuffix?: readonly unknown[];
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export function buildQueryOpts<Result>(
|
|
19
|
-
query: PromiseLike<AnyPostgrestResponse<Result>>,
|
|
20
|
-
config?: Omit<
|
|
21
|
-
UseReactQueryOptions<AnyPostgrestResponse<Result>, PostgrestError>,
|
|
22
|
-
"queryKey" | "queryFn"
|
|
23
|
-
> &
|
|
24
|
-
QueryKeySuffixOption,
|
|
25
|
-
): UseReactQueryOptions<AnyPostgrestResponse<Result>, PostgrestError> {
|
|
26
|
-
const { queryKeySuffix, ...reactQueryConfig } = config ?? {};
|
|
27
|
-
const queryKey = encode<Result>(query, false);
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
queryKey: queryKeySuffix?.length ? [...queryKey, ...queryKeySuffix] : queryKey,
|
|
31
|
-
queryFn: async ({ signal }) => {
|
|
32
|
-
if (isPostgrestTransformBuilder(query)) {
|
|
33
|
-
query = query.abortSignal(signal);
|
|
34
|
-
}
|
|
35
|
-
if (isPostgrestBuilder(query)) {
|
|
36
|
-
query = query.throwOnError();
|
|
37
|
-
}
|
|
38
|
-
return await query;
|
|
39
|
-
},
|
|
40
|
-
...reactQueryConfig,
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function buildSuspenseQueryOpts<Result>(
|
|
45
|
-
query: PromiseLike<AnyPostgrestResponse<Result>>,
|
|
46
|
-
config?: Omit<
|
|
47
|
-
UseSuspenseQueryOptions<AnyPostgrestResponse<Result>, PostgrestError>,
|
|
48
|
-
"queryKey" | "queryFn"
|
|
49
|
-
> &
|
|
50
|
-
QueryKeySuffixOption,
|
|
51
|
-
): UseSuspenseQueryOptions<AnyPostgrestResponse<Result>, PostgrestError> {
|
|
52
|
-
const { queryKeySuffix, ...reactQueryConfig } = config ?? {};
|
|
53
|
-
const queryKey = encode<Result>(query, false);
|
|
54
|
-
|
|
55
|
-
return {
|
|
56
|
-
queryKey: queryKeySuffix?.length ? [...queryKey, ...queryKeySuffix] : queryKey,
|
|
57
|
-
queryFn: async ({ signal }) => {
|
|
58
|
-
if (isPostgrestTransformBuilder(query)) {
|
|
59
|
-
query = query.abortSignal(signal);
|
|
60
|
-
}
|
|
61
|
-
if (isPostgrestBuilder(query)) {
|
|
62
|
-
query = query.throwOnError();
|
|
63
|
-
}
|
|
64
|
-
return await query;
|
|
65
|
-
},
|
|
66
|
-
...reactQueryConfig,
|
|
67
|
-
};
|
|
68
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { type DecodedKey, isPostgrestBuilder, PostgrestParser } from "@supabase-cache-helpers/postgrest-core";
|
|
2
|
-
|
|
3
|
-
export const KEY_PREFIX = "postgrest";
|
|
4
|
-
export const INFINITE_KEY_PREFIX = "page";
|
|
5
|
-
|
|
6
|
-
export type DecodedReactQueryKey = DecodedKey & {
|
|
7
|
-
isInfinite: boolean;
|
|
8
|
-
key: string[];
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export const encode = <Result>(key: unknown, isInfinite: boolean): string[] => {
|
|
12
|
-
if (!isPostgrestBuilder<Result>(key)) {
|
|
13
|
-
throw new Error("Key is not a PostgrestBuilder");
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const parser = new PostgrestParser<Result>(key);
|
|
17
|
-
return [
|
|
18
|
-
KEY_PREFIX,
|
|
19
|
-
isInfinite ? INFINITE_KEY_PREFIX : "null",
|
|
20
|
-
parser.schema,
|
|
21
|
-
parser.table,
|
|
22
|
-
parser.queryKey,
|
|
23
|
-
parser.bodyKey ?? "null",
|
|
24
|
-
`count=${parser.count}`,
|
|
25
|
-
`head=${parser.isHead}`,
|
|
26
|
-
parser.orderByKey,
|
|
27
|
-
];
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export const decode = (key: unknown): DecodedReactQueryKey | null => {
|
|
31
|
-
if (!Array.isArray(key)) return null;
|
|
32
|
-
|
|
33
|
-
const [prefix, infinitePrefix, schema, table, queryKey, bodyKey, count, head, orderByKey] = key;
|
|
34
|
-
|
|
35
|
-
// Exit early if not a postgrest key
|
|
36
|
-
if (prefix !== KEY_PREFIX) return null;
|
|
37
|
-
|
|
38
|
-
const params = new URLSearchParams(queryKey);
|
|
39
|
-
const limit = params.get("limit");
|
|
40
|
-
const offset = params.get("offset");
|
|
41
|
-
|
|
42
|
-
const countValue = count.replace("count=", "");
|
|
43
|
-
|
|
44
|
-
return {
|
|
45
|
-
limit: limit ? Number(limit) : undefined,
|
|
46
|
-
offset: offset ? Number(offset) : undefined,
|
|
47
|
-
bodyKey,
|
|
48
|
-
count: countValue === "null" ? null : countValue,
|
|
49
|
-
isHead: head === "head=true",
|
|
50
|
-
isInfinite: infinitePrefix === INFINITE_KEY_PREFIX,
|
|
51
|
-
key,
|
|
52
|
-
queryKey,
|
|
53
|
-
schema,
|
|
54
|
-
table,
|
|
55
|
-
orderByKey,
|
|
56
|
-
};
|
|
57
|
-
};
|