mtmsdk 0.0.51 → 0.0.52
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 +1 -13
- package/dist/gomtmapi/@tanstack/react-query.gen.d.ts.map +1 -1
- package/dist/gomtmapi/@tanstack/react-query.gen.js +1 -37
- 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 +0 -57
- package/dist/gomtmapi/schemas.gen.d.ts.map +1 -1
- package/dist/gomtmapi/schemas.gen.js +0 -60
- package/dist/gomtmapi/schemas.gen.js.map +1 -1
- package/dist/gomtmapi/sdk.gen.d.ts +1 -13
- package/dist/gomtmapi/sdk.gen.d.ts.map +1 -1
- package/dist/gomtmapi/sdk.gen.js +0 -26
- package/dist/gomtmapi/sdk.gen.js.map +1 -1
- package/dist/gomtmapi/types.gen.d.ts +0 -94
- package/dist/gomtmapi/types.gen.d.ts.map +1 -1
- package/dist/gomtmapi/zod.gen.d.ts +0 -62
- package/dist/gomtmapi/zod.gen.d.ts.map +1 -1
- package/dist/gomtmapi/zod.gen.js +0 -51
- package/dist/gomtmapi/zod.gen.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -4
- package/dist/index.js.map +1 -1
- package/dist/lib/schema.d.ts +1 -11
- package/dist/lib/schema.d.ts.map +1 -1
- package/dist/lib/schema.js +0 -9
- package/dist/lib/schema.js.map +1 -1
- package/dist/mtgate_api/client.gen.d.ts.map +1 -1
- package/dist/mtgate_api/client.gen.js +1 -1
- package/dist/mtgate_api/client.gen.js.map +1 -1
- package/dist/mtgate_api/index.d.ts +2 -2
- package/dist/mtgate_api/index.d.ts.map +1 -1
- package/dist/mtgate_api/index.js +1 -1
- package/dist/mtgate_api/index.js.map +1 -1
- package/dist/mtgate_api/sdk.gen.d.ts +0 -8
- package/dist/mtgate_api/sdk.gen.d.ts.map +1 -1
- package/dist/mtgate_api/sdk.gen.js +1 -29
- package/dist/mtgate_api/sdk.gen.js.map +1 -1
- package/dist/mtgate_api/types.gen.d.ts +1 -200
- package/dist/mtgate_api/types.gen.d.ts.map +1 -1
- package/dist/openclaw/gateway.d.ts.map +1 -1
- package/dist/openclaw/gateway.js +1 -1
- package/dist/openclaw/gateway.js.map +1 -1
- package/dist/sbmng/@tanstack/react-query.gen.d.ts +39 -65
- package/dist/sbmng/@tanstack/react-query.gen.d.ts.map +1 -1
- package/dist/sbmng/@tanstack/react-query.gen.js +19 -65
- package/dist/sbmng/@tanstack/react-query.gen.js.map +1 -1
- package/dist/sbmng/index.d.ts +2 -2
- package/dist/sbmng/index.d.ts.map +1 -1
- package/dist/sbmng/index.js +1 -1
- package/dist/sbmng/index.js.map +1 -1
- package/dist/sbmng/schemas.gen.d.ts +6 -95
- package/dist/sbmng/schemas.gen.d.ts.map +1 -1
- package/dist/sbmng/schemas.gen.js +7 -139
- package/dist/sbmng/schemas.gen.js.map +1 -1
- package/dist/sbmng/sdk.gen.d.ts +7 -17
- package/dist/sbmng/sdk.gen.d.ts.map +1 -1
- package/dist/sbmng/sdk.gen.js +10 -32
- package/dist/sbmng/sdk.gen.js.map +1 -1
- package/dist/sbmng/types.gen.d.ts +41 -157
- package/dist/sbmng/types.gen.d.ts.map +1 -1
- package/dist/supabase/supabase-client.d.ts +85 -181
- package/dist/supabase/supabase-client.d.ts.map +1 -1
- package/dist/supabase/supabase.d.ts +170 -362
- package/dist/supabase/supabase.d.ts.map +1 -1
- package/dist/supabase/use-sb-query/build-query-opts.d.ts +6 -2
- package/dist/supabase/use-sb-query/build-query-opts.d.ts.map +1 -1
- package/dist/supabase/use-sb-query/build-query-opts.js +8 -4
- package/dist/supabase/use-sb-query/build-query-opts.js.map +1 -1
- package/dist/supabase/use-sb-query/use-query.d.ts +9 -6
- package/dist/supabase/use-sb-query/use-query.d.ts.map +1 -1
- package/dist/supabase/use-sb-query/use-query.js.map +1 -1
- package/dist/supabase/use-sb-query/use-rpc-query.d.ts +25 -17
- package/dist/supabase/use-sb-query/use-rpc-query.d.ts.map +1 -1
- package/dist/supabase/use-sb-query/use-rpc-query.js +48 -26
- package/dist/supabase/use-sb-query/use-rpc-query.js.map +1 -1
- package/dist/types/database.schemas.d.ts +129 -222
- package/dist/types/database.schemas.d.ts.map +1 -1
- package/dist/types/database.schemas.js +112 -124
- package/dist/types/database.schemas.js.map +1 -1
- package/dist/types/database.types.d.ts +85 -181
- package/dist/types/database.types.d.ts.map +1 -1
- package/dist/types/database.types.js.map +1 -1
- package/dist/types/index.d.ts +30 -59
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +16 -3
- package/dist/types/index.js.map +1 -1
- package/package.json +105 -110
- package/src/cloud-account/platform-configs.ts +73 -73
- package/src/gomtmapi/@tanstack/react-query.gen.ts +537 -575
- package/src/gomtmapi/client/client.gen.ts +311 -311
- package/src/gomtmapi/client/index.ts +25 -25
- package/src/gomtmapi/client/types.gen.ts +241 -241
- package/src/gomtmapi/client/utils.gen.ts +332 -332
- package/src/gomtmapi/client.gen.ts +16 -16
- package/src/gomtmapi/core/auth.gen.ts +42 -42
- package/src/gomtmapi/core/bodySerializer.gen.ts +100 -100
- package/src/gomtmapi/core/params.gen.ts +176 -176
- package/src/gomtmapi/core/pathSerializer.gen.ts +181 -181
- package/src/gomtmapi/core/queryKeySerializer.gen.ts +136 -136
- package/src/gomtmapi/core/serverSentEvents.gen.ts +266 -266
- package/src/gomtmapi/core/types.gen.ts +118 -118
- package/src/gomtmapi/core/utils.gen.ts +143 -143
- package/src/gomtmapi/index.ts +4 -4
- package/src/gomtmapi/schemas.gen.ts +532 -596
- package/src/gomtmapi/sdk.gen.ts +371 -399
- package/src/gomtmapi/types.gen.ts +854 -962
- package/src/gomtmapi/zod.gen.ts +448 -507
- package/src/index.ts +4 -5
- package/src/lib/aisdk/types.ts +7 -7
- package/src/lib/logger/index.ts +8 -8
- package/src/lib/schema.ts +37 -50
- package/src/mtgate_api/client/client.gen.ts +311 -311
- package/src/mtgate_api/client/index.ts +25 -25
- package/src/mtgate_api/client/types.gen.ts +241 -241
- package/src/mtgate_api/client/utils.gen.ts +332 -332
- package/src/mtgate_api/client.gen.ts +16 -16
- package/src/mtgate_api/core/auth.gen.ts +42 -42
- package/src/mtgate_api/core/bodySerializer.gen.ts +100 -100
- package/src/mtgate_api/core/params.gen.ts +176 -176
- package/src/mtgate_api/core/pathSerializer.gen.ts +181 -181
- package/src/mtgate_api/core/queryKeySerializer.gen.ts +136 -136
- package/src/mtgate_api/core/serverSentEvents.gen.ts +266 -266
- package/src/mtgate_api/core/types.gen.ts +118 -118
- package/src/mtgate_api/core/utils.gen.ts +143 -143
- package/src/mtgate_api/index.ts +4 -4
- package/src/mtgate_api/sdk.gen.ts +17 -54
- package/src/mtgate_api/types.gen.ts +5 -239
- package/src/openclaw/client-info.ts +54 -54
- package/src/openclaw/device-auth-utils.ts +26 -26
- package/src/openclaw/device-auth.ts +99 -99
- package/src/openclaw/device-identity.ts +108 -108
- package/src/openclaw/gateway.ts +392 -392
- package/src/openclaw/types.ts +518 -518
- package/src/sbmng/@tanstack/react-query.gen.ts +2967 -3017
- package/src/sbmng/client/client.gen.ts +311 -311
- package/src/sbmng/client/index.ts +25 -25
- package/src/sbmng/client/types.gen.ts +241 -241
- package/src/sbmng/client/utils.gen.ts +332 -332
- package/src/sbmng/client.gen.ts +16 -16
- package/src/sbmng/core/auth.gen.ts +42 -42
- package/src/sbmng/core/bodySerializer.gen.ts +100 -100
- package/src/sbmng/core/params.gen.ts +176 -176
- package/src/sbmng/core/pathSerializer.gen.ts +181 -181
- package/src/sbmng/core/queryKeySerializer.gen.ts +136 -136
- package/src/sbmng/core/serverSentEvents.gen.ts +266 -266
- package/src/sbmng/core/types.gen.ts +118 -118
- package/src/sbmng/core/utils.gen.ts +143 -143
- package/src/sbmng/index.ts +4 -4
- package/src/sbmng/schemas.gen.ts +9671 -9805
- package/src/sbmng/sdk.gen.ts +1755 -1780
- package/src/sbmng/types.gen.ts +7886 -8016
- package/src/supabase/auth-provider.tsx +67 -67
- package/src/supabase/context.tsx +51 -51
- package/src/supabase/cursor-pagination.ts +155 -155
- package/src/supabase/schema/browser.ts +44 -44
- package/src/supabase/schema/index.ts +25 -25
- package/src/supabase/supabase-client.ts +30 -30
- package/src/supabase/supabase.ts +67 -67
- package/src/supabase/use-sb-query/build-query-opts.ts +68 -56
- package/src/supabase/use-sb-query/key.ts +57 -57
- package/src/supabase/use-sb-query/use-query.ts +352 -340
- package/src/supabase/use-sb-query/use-rpc-mutation.ts +83 -83
- package/src/supabase/use-sb-query/use-rpc-query.ts +267 -231
- package/src/supabase/utils.ts +75 -75
- package/src/types/database.schemas.ts +4359 -4378
- package/src/types/database.types.ts +4182 -4288
- package/src/types/index.ts +85 -102
- package/dist/adk/api/client.d.ts +0 -9
- package/dist/adk/api/client.d.ts.map +0 -1
- package/dist/adk/api/client.js +0 -39
- package/dist/adk/api/client.js.map +0 -1
- package/dist/adk/core/constants/tool-icons.d.ts +0 -21
- package/dist/adk/core/constants/tool-icons.d.ts.map +0 -1
- package/dist/adk/core/constants/tool-icons.js +0 -47
- package/dist/adk/core/constants/tool-icons.js.map +0 -1
- package/dist/adk/core/models/AgentBuilder.d.ts +0 -77
- package/dist/adk/core/models/AgentBuilder.d.ts.map +0 -1
- package/dist/adk/core/models/AgentBuilder.js +0 -18
- package/dist/adk/core/models/AgentBuilder.js.map +0 -1
- package/dist/adk/core/models/AgentRunRequest.d.ts +0 -37
- package/dist/adk/core/models/AgentRunRequest.d.ts.map +0 -1
- package/dist/adk/core/models/AgentRunRequest.js +0 -18
- package/dist/adk/core/models/AgentRunRequest.js.map +0 -1
- package/dist/adk/core/models/Eval.d.ts +0 -55
- package/dist/adk/core/models/Eval.d.ts.map +0 -1
- package/dist/adk/core/models/Eval.js +0 -27
- package/dist/adk/core/models/Eval.js.map +0 -1
- package/dist/adk/core/models/LiveRequest.d.ts +0 -23
- package/dist/adk/core/models/LiveRequest.d.ts.map +0 -1
- package/dist/adk/core/models/LiveRequest.js +0 -18
- package/dist/adk/core/models/LiveRequest.js.map +0 -1
- package/dist/adk/core/models/RuntimeConfig.d.ts +0 -32
- package/dist/adk/core/models/RuntimeConfig.d.ts.map +0 -1
- package/dist/adk/core/models/RuntimeConfig.js +0 -18
- package/dist/adk/core/models/RuntimeConfig.js.map +0 -1
- package/dist/adk/core/models/Session.d.ts +0 -117
- package/dist/adk/core/models/Session.d.ts.map +0 -1
- package/dist/adk/core/models/Session.js +0 -31
- package/dist/adk/core/models/Session.js.map +0 -1
- package/dist/adk/core/models/Trace.d.ts +0 -40
- package/dist/adk/core/models/Trace.d.ts.map +0 -1
- package/dist/adk/core/models/Trace.js +0 -2
- package/dist/adk/core/models/Trace.js.map +0 -1
- package/dist/adk/core/models/types.d.ts +0 -338
- package/dist/adk/core/models/types.d.ts.map +0 -1
- package/dist/adk/core/models/types.js +0 -189
- package/dist/adk/core/models/types.js.map +0 -1
- package/dist/lib/utils.d.ts +0 -14
- package/dist/lib/utils.d.ts.map +0 -1
- package/dist/lib/utils.js +0 -45
- package/dist/lib/utils.js.map +0 -1
- package/dist/mtgate_api/@tanstack/react-query.gen.d.ts +0 -166
- package/dist/mtgate_api/@tanstack/react-query.gen.d.ts.map +0 -1
- package/dist/mtgate_api/@tanstack/react-query.gen.js +0 -118
- package/dist/mtgate_api/@tanstack/react-query.gen.js.map +0 -1
- package/dist/mtgate_api/schemas.gen.d.ts +0 -233
- package/dist/mtgate_api/schemas.gen.d.ts.map +0 -1
- package/dist/mtgate_api/schemas.gen.js +0 -277
- package/dist/mtgate_api/schemas.gen.js.map +0 -1
- package/dist/mtgate_api/zod.gen.d.ts +0 -321
- package/dist/mtgate_api/zod.gen.d.ts.map +0 -1
- package/dist/mtgate_api/zod.gen.js +0 -148
- package/dist/mtgate_api/zod.gen.js.map +0 -1
- package/dist/mtmai_api/@tanstack/react-query.gen.d.ts +0 -949
- package/dist/mtmai_api/@tanstack/react-query.gen.d.ts.map +0 -1
- package/dist/mtmai_api/@tanstack/react-query.gen.js +0 -917
- package/dist/mtmai_api/@tanstack/react-query.gen.js.map +0 -1
- package/dist/mtmai_api/client/client.gen.d.ts +0 -3
- package/dist/mtmai_api/client/client.gen.d.ts.map +0 -1
- package/dist/mtmai_api/client/client.gen.js +0 -236
- package/dist/mtmai_api/client/client.gen.js.map +0 -1
- package/dist/mtmai_api/client/index.d.ts +0 -9
- package/dist/mtmai_api/client/index.d.ts.map +0 -1
- package/dist/mtmai_api/client/index.js +0 -7
- package/dist/mtmai_api/client/index.js.map +0 -1
- package/dist/mtmai_api/client/types.gen.d.ts +0 -118
- package/dist/mtmai_api/client/types.gen.d.ts.map +0 -1
- package/dist/mtmai_api/client/types.gen.js +0 -3
- package/dist/mtmai_api/client/types.gen.js.map +0 -1
- package/dist/mtmai_api/client/utils.gen.d.ts +0 -34
- package/dist/mtmai_api/client/utils.gen.d.ts.map +0 -1
- package/dist/mtmai_api/client/utils.gen.js +0 -232
- package/dist/mtmai_api/client/utils.gen.js.map +0 -1
- package/dist/mtmai_api/client.gen.d.ts +0 -13
- package/dist/mtmai_api/client.gen.d.ts.map +0 -1
- package/dist/mtmai_api/client.gen.js +0 -4
- package/dist/mtmai_api/client.gen.js.map +0 -1
- package/dist/mtmai_api/core/auth.gen.d.ts +0 -19
- package/dist/mtmai_api/core/auth.gen.d.ts.map +0 -1
- package/dist/mtmai_api/core/auth.gen.js +0 -15
- package/dist/mtmai_api/core/auth.gen.js.map +0 -1
- package/dist/mtmai_api/core/bodySerializer.gen.d.ts +0 -26
- package/dist/mtmai_api/core/bodySerializer.gen.d.ts.map +0 -1
- package/dist/mtmai_api/core/bodySerializer.gen.js +0 -58
- package/dist/mtmai_api/core/bodySerializer.gen.js.map +0 -1
- package/dist/mtmai_api/core/params.gen.d.ts +0 -44
- package/dist/mtmai_api/core/params.gen.d.ts.map +0 -1
- package/dist/mtmai_api/core/params.gen.js +0 -101
- package/dist/mtmai_api/core/params.gen.js.map +0 -1
- package/dist/mtmai_api/core/pathSerializer.gen.d.ts +0 -34
- package/dist/mtmai_api/core/pathSerializer.gen.d.ts.map +0 -1
- package/dist/mtmai_api/core/pathSerializer.gen.js +0 -115
- package/dist/mtmai_api/core/pathSerializer.gen.js.map +0 -1
- package/dist/mtmai_api/core/queryKeySerializer.gen.d.ts +0 -19
- package/dist/mtmai_api/core/queryKeySerializer.gen.d.ts.map +0 -1
- package/dist/mtmai_api/core/queryKeySerializer.gen.js +0 -100
- package/dist/mtmai_api/core/queryKeySerializer.gen.js.map +0 -1
- package/dist/mtmai_api/core/serverSentEvents.gen.d.ts +0 -72
- package/dist/mtmai_api/core/serverSentEvents.gen.d.ts.map +0 -1
- package/dist/mtmai_api/core/serverSentEvents.gen.js +0 -138
- package/dist/mtmai_api/core/serverSentEvents.gen.js.map +0 -1
- package/dist/mtmai_api/core/types.gen.d.ts +0 -79
- package/dist/mtmai_api/core/types.gen.d.ts.map +0 -1
- package/dist/mtmai_api/core/types.gen.js +0 -3
- package/dist/mtmai_api/core/types.gen.js.map +0 -1
- package/dist/mtmai_api/core/utils.gen.d.ts +0 -20
- package/dist/mtmai_api/core/utils.gen.d.ts.map +0 -1
- package/dist/mtmai_api/core/utils.gen.js +0 -88
- package/dist/mtmai_api/core/utils.gen.js.map +0 -1
- package/dist/mtmai_api/index.d.ts +0 -3
- package/dist/mtmai_api/index.d.ts.map +0 -1
- package/dist/mtmai_api/index.js +0 -4
- package/dist/mtmai_api/index.js.map +0 -1
- package/dist/mtmai_api/schemas.gen.d.ts +0 -7721
- package/dist/mtmai_api/schemas.gen.d.ts.map +0 -1
- package/dist/mtmai_api/schemas.gen.js +0 -9774
- package/dist/mtmai_api/schemas.gen.js.map +0 -1
- package/dist/mtmai_api/sdk.gen.d.ts +0 -282
- package/dist/mtmai_api/sdk.gen.d.ts.map +0 -1
- package/dist/mtmai_api/sdk.gen.js +0 -404
- package/dist/mtmai_api/sdk.gen.js.map +0 -1
- package/dist/mtmai_api/types.gen.d.ts +0 -7152
- package/dist/mtmai_api/types.gen.d.ts.map +0 -1
- package/dist/mtmai_api/types.gen.js +0 -253
- package/dist/mtmai_api/types.gen.js.map +0 -1
- package/dist/mtmai_api/zod.gen.d.ts +0 -55827
- package/dist/mtmai_api/zod.gen.d.ts.map +0 -1
- package/dist/mtmai_api/zod.gen.js +0 -4805
- package/dist/mtmai_api/zod.gen.js.map +0 -1
- package/dist/supabase/use-sb-query/prefetch.d.ts +0 -10
- package/dist/supabase/use-sb-query/prefetch.d.ts.map +0 -1
- package/dist/supabase/use-sb-query/prefetch.js +0 -14
- package/dist/supabase/use-sb-query/prefetch.js.map +0 -1
- package/src/adk/api/client.ts +0 -46
- package/src/adk/core/constants/tool-icons.ts +0 -51
- package/src/adk/core/models/AgentBuilder.ts +0 -80
- package/src/adk/core/models/AgentRunRequest.ts +0 -33
- package/src/adk/core/models/Eval.ts +0 -70
- package/src/adk/core/models/LiveRequest.ts +0 -23
- package/src/adk/core/models/RuntimeConfig.ts +0 -33
- package/src/adk/core/models/Session.ts +0 -52
- package/src/adk/core/models/Trace.ts +0 -42
- package/src/adk/core/models/types.ts +0 -255
- package/src/lib/utils.ts +0 -54
- package/src/mtgate_api/@tanstack/react-query.gen.ts +0 -142
- package/src/mtgate_api/schemas.gen.ts +0 -290
- package/src/mtgate_api/zod.gen.ts +0 -176
- package/src/mtmai_api/@tanstack/react-query.gen.ts +0 -1010
- package/src/mtmai_api/client/client.gen.ts +0 -311
- package/src/mtmai_api/client/index.ts +0 -25
- package/src/mtmai_api/client/types.gen.ts +0 -241
- package/src/mtmai_api/client/utils.gen.ts +0 -332
- package/src/mtmai_api/client.gen.ts +0 -16
- package/src/mtmai_api/core/auth.gen.ts +0 -42
- package/src/mtmai_api/core/bodySerializer.gen.ts +0 -100
- package/src/mtmai_api/core/params.gen.ts +0 -176
- package/src/mtmai_api/core/pathSerializer.gen.ts +0 -181
- package/src/mtmai_api/core/queryKeySerializer.gen.ts +0 -136
- package/src/mtmai_api/core/serverSentEvents.gen.ts +0 -266
- package/src/mtmai_api/core/types.gen.ts +0 -118
- package/src/mtmai_api/core/utils.gen.ts +0 -143
- package/src/mtmai_api/index.ts +0 -4
- package/src/mtmai_api/schemas.gen.ts +0 -9980
- package/src/mtmai_api/sdk.gen.ts +0 -471
- package/src/mtmai_api/types.gen.ts +0 -7609
- package/src/mtmai_api/zod.gen.ts +0 -5101
- package/src/supabase/use-sb-query/prefetch.ts +0 -59
|
@@ -1,340 +1,352 @@
|
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
*
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
Pick<
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
UseReactSuspenseQueryResult<
|
|
255
|
-
"
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
UseReactSuspenseQueryResult<PostgrestResponse<Result
|
|
266
|
-
"
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
*
|
|
284
|
-
*
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
*
|
|
295
|
-
*
|
|
296
|
-
* @
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
* @
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
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 };
|