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,332 +1,332 @@
|
|
|
1
|
-
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
-
|
|
3
|
-
import { getAuthToken } from '../core/auth.gen';
|
|
4
|
-
import type { QuerySerializerOptions } from '../core/bodySerializer.gen';
|
|
5
|
-
import { jsonBodySerializer } from '../core/bodySerializer.gen';
|
|
6
|
-
import {
|
|
7
|
-
serializeArrayParam,
|
|
8
|
-
serializeObjectParam,
|
|
9
|
-
serializePrimitiveParam,
|
|
10
|
-
} from '../core/pathSerializer.gen';
|
|
11
|
-
import { getUrl } from '../core/utils.gen';
|
|
12
|
-
import type { Client, ClientOptions, Config, RequestOptions } from './types.gen';
|
|
13
|
-
|
|
14
|
-
export const createQuerySerializer = <T = unknown>({
|
|
15
|
-
parameters = {},
|
|
16
|
-
...args
|
|
17
|
-
}: QuerySerializerOptions = {}) => {
|
|
18
|
-
const querySerializer = (queryParams: T) => {
|
|
19
|
-
const search: string[] = [];
|
|
20
|
-
if (queryParams && typeof queryParams === 'object') {
|
|
21
|
-
for (const name in queryParams) {
|
|
22
|
-
const value = queryParams[name];
|
|
23
|
-
|
|
24
|
-
if (value === undefined || value === null) {
|
|
25
|
-
continue;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const options = parameters[name] || args;
|
|
29
|
-
|
|
30
|
-
if (Array.isArray(value)) {
|
|
31
|
-
const serializedArray = serializeArrayParam({
|
|
32
|
-
allowReserved: options.allowReserved,
|
|
33
|
-
explode: true,
|
|
34
|
-
name,
|
|
35
|
-
style: 'form',
|
|
36
|
-
value,
|
|
37
|
-
...options.array,
|
|
38
|
-
});
|
|
39
|
-
if (serializedArray) search.push(serializedArray);
|
|
40
|
-
} else if (typeof value === 'object') {
|
|
41
|
-
const serializedObject = serializeObjectParam({
|
|
42
|
-
allowReserved: options.allowReserved,
|
|
43
|
-
explode: true,
|
|
44
|
-
name,
|
|
45
|
-
style: 'deepObject',
|
|
46
|
-
value: value as Record<string, unknown>,
|
|
47
|
-
...options.object,
|
|
48
|
-
});
|
|
49
|
-
if (serializedObject) search.push(serializedObject);
|
|
50
|
-
} else {
|
|
51
|
-
const serializedPrimitive = serializePrimitiveParam({
|
|
52
|
-
allowReserved: options.allowReserved,
|
|
53
|
-
name,
|
|
54
|
-
value: value as string,
|
|
55
|
-
});
|
|
56
|
-
if (serializedPrimitive) search.push(serializedPrimitive);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return search.join('&');
|
|
61
|
-
};
|
|
62
|
-
return querySerializer;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Infers parseAs value from provided Content-Type header.
|
|
67
|
-
*/
|
|
68
|
-
export const getParseAs = (
|
|
69
|
-
contentType: string | null,
|
|
70
|
-
): Exclude<Config['parseAs'], 'auto'> => {
|
|
71
|
-
if (!contentType) {
|
|
72
|
-
// If no Content-Type header is provided, the best we can do is return the raw response body,
|
|
73
|
-
// which is effectively the same as the 'stream' option.
|
|
74
|
-
return 'stream';
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const cleanContent = contentType.split(';')[0]?.trim();
|
|
78
|
-
|
|
79
|
-
if (!cleanContent) {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (
|
|
84
|
-
cleanContent.startsWith('application/json') ||
|
|
85
|
-
cleanContent.endsWith('+json')
|
|
86
|
-
) {
|
|
87
|
-
return 'json';
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (cleanContent === 'multipart/form-data') {
|
|
91
|
-
return 'formData';
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (
|
|
95
|
-
['application/', 'audio/', 'image/', 'video/'].some((type) =>
|
|
96
|
-
cleanContent.startsWith(type),
|
|
97
|
-
)
|
|
98
|
-
) {
|
|
99
|
-
return 'blob';
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (cleanContent.startsWith('text/')) {
|
|
103
|
-
return 'text';
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
const checkForExistence = (
|
|
110
|
-
options: Pick<RequestOptions, 'auth' | 'query'> & {
|
|
111
|
-
headers: Headers;
|
|
112
|
-
},
|
|
113
|
-
name?: string,
|
|
114
|
-
): boolean => {
|
|
115
|
-
if (!name) {
|
|
116
|
-
return false;
|
|
117
|
-
}
|
|
118
|
-
if (
|
|
119
|
-
options.headers.has(name) ||
|
|
120
|
-
options.query?.[name] ||
|
|
121
|
-
options.headers.get('Cookie')?.includes(`${name}=`)
|
|
122
|
-
) {
|
|
123
|
-
return true;
|
|
124
|
-
}
|
|
125
|
-
return false;
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
export const setAuthParams = async ({
|
|
129
|
-
security,
|
|
130
|
-
...options
|
|
131
|
-
}: Pick<Required<RequestOptions>, 'security'> &
|
|
132
|
-
Pick<RequestOptions, 'auth' | 'query'> & {
|
|
133
|
-
headers: Headers;
|
|
134
|
-
}) => {
|
|
135
|
-
for (const auth of security) {
|
|
136
|
-
if (checkForExistence(options, auth.name)) {
|
|
137
|
-
continue;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const token = await getAuthToken(auth, options.auth);
|
|
141
|
-
|
|
142
|
-
if (!token) {
|
|
143
|
-
continue;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const name = auth.name ?? 'Authorization';
|
|
147
|
-
|
|
148
|
-
switch (auth.in) {
|
|
149
|
-
case 'query':
|
|
150
|
-
if (!options.query) {
|
|
151
|
-
options.query = {};
|
|
152
|
-
}
|
|
153
|
-
options.query[name] = token;
|
|
154
|
-
break;
|
|
155
|
-
case 'cookie':
|
|
156
|
-
options.headers.append('Cookie', `${name}=${token}`);
|
|
157
|
-
break;
|
|
158
|
-
case 'header':
|
|
159
|
-
default:
|
|
160
|
-
options.headers.set(name, token);
|
|
161
|
-
break;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
export const buildUrl: Client['buildUrl'] = (options) =>
|
|
167
|
-
getUrl({
|
|
168
|
-
baseUrl: options.baseUrl as string,
|
|
169
|
-
path: options.path,
|
|
170
|
-
query: options.query,
|
|
171
|
-
querySerializer:
|
|
172
|
-
typeof options.querySerializer === 'function'
|
|
173
|
-
? options.querySerializer
|
|
174
|
-
: createQuerySerializer(options.querySerializer),
|
|
175
|
-
url: options.url,
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
export const mergeConfigs = (a: Config, b: Config): Config => {
|
|
179
|
-
const config = { ...a, ...b };
|
|
180
|
-
if (config.baseUrl?.endsWith('/')) {
|
|
181
|
-
config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
|
|
182
|
-
}
|
|
183
|
-
config.headers = mergeHeaders(a.headers, b.headers);
|
|
184
|
-
return config;
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
const headersEntries = (headers: Headers): Array<[string, string]> => {
|
|
188
|
-
const entries: Array<[string, string]> = [];
|
|
189
|
-
headers.forEach((value, key) => {
|
|
190
|
-
entries.push([key, value]);
|
|
191
|
-
});
|
|
192
|
-
return entries;
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
export const mergeHeaders = (
|
|
196
|
-
...headers: Array<Required<Config>['headers'] | undefined>
|
|
197
|
-
): Headers => {
|
|
198
|
-
const mergedHeaders = new Headers();
|
|
199
|
-
for (const header of headers) {
|
|
200
|
-
if (!header) {
|
|
201
|
-
continue;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
const iterator =
|
|
205
|
-
header instanceof Headers
|
|
206
|
-
? headersEntries(header)
|
|
207
|
-
: Object.entries(header);
|
|
208
|
-
|
|
209
|
-
for (const [key, value] of iterator) {
|
|
210
|
-
if (value === null) {
|
|
211
|
-
mergedHeaders.delete(key);
|
|
212
|
-
} else if (Array.isArray(value)) {
|
|
213
|
-
for (const v of value) {
|
|
214
|
-
mergedHeaders.append(key, v as string);
|
|
215
|
-
}
|
|
216
|
-
} else if (value !== undefined) {
|
|
217
|
-
// assume object headers are meant to be JSON stringified, i.e. their
|
|
218
|
-
// content value in OpenAPI specification is 'application/json'
|
|
219
|
-
mergedHeaders.set(
|
|
220
|
-
key,
|
|
221
|
-
typeof value === 'object' ? JSON.stringify(value) : (value as string),
|
|
222
|
-
);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
return mergedHeaders;
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
type ErrInterceptor<Err, Res, Req, Options> = (
|
|
230
|
-
error: Err,
|
|
231
|
-
response: Res,
|
|
232
|
-
request: Req,
|
|
233
|
-
options: Options,
|
|
234
|
-
) => Err | Promise<Err>;
|
|
235
|
-
|
|
236
|
-
type ReqInterceptor<Req, Options> = (
|
|
237
|
-
request: Req,
|
|
238
|
-
options: Options,
|
|
239
|
-
) => Req | Promise<Req>;
|
|
240
|
-
|
|
241
|
-
type ResInterceptor<Res, Req, Options> = (
|
|
242
|
-
response: Res,
|
|
243
|
-
request: Req,
|
|
244
|
-
options: Options,
|
|
245
|
-
) => Res | Promise<Res>;
|
|
246
|
-
|
|
247
|
-
class Interceptors<Interceptor> {
|
|
248
|
-
fns: Array<Interceptor | null> = [];
|
|
249
|
-
|
|
250
|
-
clear(): void {
|
|
251
|
-
this.fns = [];
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
eject(id: number | Interceptor): void {
|
|
255
|
-
const index = this.getInterceptorIndex(id);
|
|
256
|
-
if (this.fns[index]) {
|
|
257
|
-
this.fns[index] = null;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
exists(id: number | Interceptor): boolean {
|
|
262
|
-
const index = this.getInterceptorIndex(id);
|
|
263
|
-
return Boolean(this.fns[index]);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
getInterceptorIndex(id: number | Interceptor): number {
|
|
267
|
-
if (typeof id === 'number') {
|
|
268
|
-
return this.fns[id] ? id : -1;
|
|
269
|
-
}
|
|
270
|
-
return this.fns.indexOf(id);
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
update(
|
|
274
|
-
id: number | Interceptor,
|
|
275
|
-
fn: Interceptor,
|
|
276
|
-
): number | Interceptor | false {
|
|
277
|
-
const index = this.getInterceptorIndex(id);
|
|
278
|
-
if (this.fns[index]) {
|
|
279
|
-
this.fns[index] = fn;
|
|
280
|
-
return id;
|
|
281
|
-
}
|
|
282
|
-
return false;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
use(fn: Interceptor): number {
|
|
286
|
-
this.fns.push(fn);
|
|
287
|
-
return this.fns.length - 1;
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
export interface Middleware<Req, Res, Err, Options> {
|
|
292
|
-
error: Interceptors<ErrInterceptor<Err, Res, Req, Options>>;
|
|
293
|
-
request: Interceptors<ReqInterceptor<Req, Options>>;
|
|
294
|
-
response: Interceptors<ResInterceptor<Res, Req, Options>>;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
export const createInterceptors = <Req, Res, Err, Options>(): Middleware<
|
|
298
|
-
Req,
|
|
299
|
-
Res,
|
|
300
|
-
Err,
|
|
301
|
-
Options
|
|
302
|
-
> => ({
|
|
303
|
-
error: new Interceptors<ErrInterceptor<Err, Res, Req, Options>>(),
|
|
304
|
-
request: new Interceptors<ReqInterceptor<Req, Options>>(),
|
|
305
|
-
response: new Interceptors<ResInterceptor<Res, Req, Options>>(),
|
|
306
|
-
});
|
|
307
|
-
|
|
308
|
-
const defaultQuerySerializer = createQuerySerializer({
|
|
309
|
-
allowReserved: false,
|
|
310
|
-
array: {
|
|
311
|
-
explode: true,
|
|
312
|
-
style: 'form',
|
|
313
|
-
},
|
|
314
|
-
object: {
|
|
315
|
-
explode: true,
|
|
316
|
-
style: 'deepObject',
|
|
317
|
-
},
|
|
318
|
-
});
|
|
319
|
-
|
|
320
|
-
const defaultHeaders = {
|
|
321
|
-
'Content-Type': 'application/json',
|
|
322
|
-
};
|
|
323
|
-
|
|
324
|
-
export const createConfig = <T extends ClientOptions = ClientOptions>(
|
|
325
|
-
override: Config<Omit<ClientOptions, keyof T> & T> = {},
|
|
326
|
-
): Config<Omit<ClientOptions, keyof T> & T> => ({
|
|
327
|
-
...jsonBodySerializer,
|
|
328
|
-
headers: defaultHeaders,
|
|
329
|
-
parseAs: 'auto',
|
|
330
|
-
querySerializer: defaultQuerySerializer,
|
|
331
|
-
...override,
|
|
332
|
-
});
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
|
|
3
|
+
import { getAuthToken } from '../core/auth.gen';
|
|
4
|
+
import type { QuerySerializerOptions } from '../core/bodySerializer.gen';
|
|
5
|
+
import { jsonBodySerializer } from '../core/bodySerializer.gen';
|
|
6
|
+
import {
|
|
7
|
+
serializeArrayParam,
|
|
8
|
+
serializeObjectParam,
|
|
9
|
+
serializePrimitiveParam,
|
|
10
|
+
} from '../core/pathSerializer.gen';
|
|
11
|
+
import { getUrl } from '../core/utils.gen';
|
|
12
|
+
import type { Client, ClientOptions, Config, RequestOptions } from './types.gen';
|
|
13
|
+
|
|
14
|
+
export const createQuerySerializer = <T = unknown>({
|
|
15
|
+
parameters = {},
|
|
16
|
+
...args
|
|
17
|
+
}: QuerySerializerOptions = {}) => {
|
|
18
|
+
const querySerializer = (queryParams: T) => {
|
|
19
|
+
const search: string[] = [];
|
|
20
|
+
if (queryParams && typeof queryParams === 'object') {
|
|
21
|
+
for (const name in queryParams) {
|
|
22
|
+
const value = queryParams[name];
|
|
23
|
+
|
|
24
|
+
if (value === undefined || value === null) {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const options = parameters[name] || args;
|
|
29
|
+
|
|
30
|
+
if (Array.isArray(value)) {
|
|
31
|
+
const serializedArray = serializeArrayParam({
|
|
32
|
+
allowReserved: options.allowReserved,
|
|
33
|
+
explode: true,
|
|
34
|
+
name,
|
|
35
|
+
style: 'form',
|
|
36
|
+
value,
|
|
37
|
+
...options.array,
|
|
38
|
+
});
|
|
39
|
+
if (serializedArray) search.push(serializedArray);
|
|
40
|
+
} else if (typeof value === 'object') {
|
|
41
|
+
const serializedObject = serializeObjectParam({
|
|
42
|
+
allowReserved: options.allowReserved,
|
|
43
|
+
explode: true,
|
|
44
|
+
name,
|
|
45
|
+
style: 'deepObject',
|
|
46
|
+
value: value as Record<string, unknown>,
|
|
47
|
+
...options.object,
|
|
48
|
+
});
|
|
49
|
+
if (serializedObject) search.push(serializedObject);
|
|
50
|
+
} else {
|
|
51
|
+
const serializedPrimitive = serializePrimitiveParam({
|
|
52
|
+
allowReserved: options.allowReserved,
|
|
53
|
+
name,
|
|
54
|
+
value: value as string,
|
|
55
|
+
});
|
|
56
|
+
if (serializedPrimitive) search.push(serializedPrimitive);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return search.join('&');
|
|
61
|
+
};
|
|
62
|
+
return querySerializer;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Infers parseAs value from provided Content-Type header.
|
|
67
|
+
*/
|
|
68
|
+
export const getParseAs = (
|
|
69
|
+
contentType: string | null,
|
|
70
|
+
): Exclude<Config['parseAs'], 'auto'> => {
|
|
71
|
+
if (!contentType) {
|
|
72
|
+
// If no Content-Type header is provided, the best we can do is return the raw response body,
|
|
73
|
+
// which is effectively the same as the 'stream' option.
|
|
74
|
+
return 'stream';
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const cleanContent = contentType.split(';')[0]?.trim();
|
|
78
|
+
|
|
79
|
+
if (!cleanContent) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (
|
|
84
|
+
cleanContent.startsWith('application/json') ||
|
|
85
|
+
cleanContent.endsWith('+json')
|
|
86
|
+
) {
|
|
87
|
+
return 'json';
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (cleanContent === 'multipart/form-data') {
|
|
91
|
+
return 'formData';
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (
|
|
95
|
+
['application/', 'audio/', 'image/', 'video/'].some((type) =>
|
|
96
|
+
cleanContent.startsWith(type),
|
|
97
|
+
)
|
|
98
|
+
) {
|
|
99
|
+
return 'blob';
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (cleanContent.startsWith('text/')) {
|
|
103
|
+
return 'text';
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const checkForExistence = (
|
|
110
|
+
options: Pick<RequestOptions, 'auth' | 'query'> & {
|
|
111
|
+
headers: Headers;
|
|
112
|
+
},
|
|
113
|
+
name?: string,
|
|
114
|
+
): boolean => {
|
|
115
|
+
if (!name) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
if (
|
|
119
|
+
options.headers.has(name) ||
|
|
120
|
+
options.query?.[name] ||
|
|
121
|
+
options.headers.get('Cookie')?.includes(`${name}=`)
|
|
122
|
+
) {
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
return false;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export const setAuthParams = async ({
|
|
129
|
+
security,
|
|
130
|
+
...options
|
|
131
|
+
}: Pick<Required<RequestOptions>, 'security'> &
|
|
132
|
+
Pick<RequestOptions, 'auth' | 'query'> & {
|
|
133
|
+
headers: Headers;
|
|
134
|
+
}) => {
|
|
135
|
+
for (const auth of security) {
|
|
136
|
+
if (checkForExistence(options, auth.name)) {
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const token = await getAuthToken(auth, options.auth);
|
|
141
|
+
|
|
142
|
+
if (!token) {
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const name = auth.name ?? 'Authorization';
|
|
147
|
+
|
|
148
|
+
switch (auth.in) {
|
|
149
|
+
case 'query':
|
|
150
|
+
if (!options.query) {
|
|
151
|
+
options.query = {};
|
|
152
|
+
}
|
|
153
|
+
options.query[name] = token;
|
|
154
|
+
break;
|
|
155
|
+
case 'cookie':
|
|
156
|
+
options.headers.append('Cookie', `${name}=${token}`);
|
|
157
|
+
break;
|
|
158
|
+
case 'header':
|
|
159
|
+
default:
|
|
160
|
+
options.headers.set(name, token);
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
export const buildUrl: Client['buildUrl'] = (options) =>
|
|
167
|
+
getUrl({
|
|
168
|
+
baseUrl: options.baseUrl as string,
|
|
169
|
+
path: options.path,
|
|
170
|
+
query: options.query,
|
|
171
|
+
querySerializer:
|
|
172
|
+
typeof options.querySerializer === 'function'
|
|
173
|
+
? options.querySerializer
|
|
174
|
+
: createQuerySerializer(options.querySerializer),
|
|
175
|
+
url: options.url,
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
export const mergeConfigs = (a: Config, b: Config): Config => {
|
|
179
|
+
const config = { ...a, ...b };
|
|
180
|
+
if (config.baseUrl?.endsWith('/')) {
|
|
181
|
+
config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
|
|
182
|
+
}
|
|
183
|
+
config.headers = mergeHeaders(a.headers, b.headers);
|
|
184
|
+
return config;
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
const headersEntries = (headers: Headers): Array<[string, string]> => {
|
|
188
|
+
const entries: Array<[string, string]> = [];
|
|
189
|
+
headers.forEach((value, key) => {
|
|
190
|
+
entries.push([key, value]);
|
|
191
|
+
});
|
|
192
|
+
return entries;
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
export const mergeHeaders = (
|
|
196
|
+
...headers: Array<Required<Config>['headers'] | undefined>
|
|
197
|
+
): Headers => {
|
|
198
|
+
const mergedHeaders = new Headers();
|
|
199
|
+
for (const header of headers) {
|
|
200
|
+
if (!header) {
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const iterator =
|
|
205
|
+
header instanceof Headers
|
|
206
|
+
? headersEntries(header)
|
|
207
|
+
: Object.entries(header);
|
|
208
|
+
|
|
209
|
+
for (const [key, value] of iterator) {
|
|
210
|
+
if (value === null) {
|
|
211
|
+
mergedHeaders.delete(key);
|
|
212
|
+
} else if (Array.isArray(value)) {
|
|
213
|
+
for (const v of value) {
|
|
214
|
+
mergedHeaders.append(key, v as string);
|
|
215
|
+
}
|
|
216
|
+
} else if (value !== undefined) {
|
|
217
|
+
// assume object headers are meant to be JSON stringified, i.e. their
|
|
218
|
+
// content value in OpenAPI specification is 'application/json'
|
|
219
|
+
mergedHeaders.set(
|
|
220
|
+
key,
|
|
221
|
+
typeof value === 'object' ? JSON.stringify(value) : (value as string),
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return mergedHeaders;
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
type ErrInterceptor<Err, Res, Req, Options> = (
|
|
230
|
+
error: Err,
|
|
231
|
+
response: Res,
|
|
232
|
+
request: Req,
|
|
233
|
+
options: Options,
|
|
234
|
+
) => Err | Promise<Err>;
|
|
235
|
+
|
|
236
|
+
type ReqInterceptor<Req, Options> = (
|
|
237
|
+
request: Req,
|
|
238
|
+
options: Options,
|
|
239
|
+
) => Req | Promise<Req>;
|
|
240
|
+
|
|
241
|
+
type ResInterceptor<Res, Req, Options> = (
|
|
242
|
+
response: Res,
|
|
243
|
+
request: Req,
|
|
244
|
+
options: Options,
|
|
245
|
+
) => Res | Promise<Res>;
|
|
246
|
+
|
|
247
|
+
class Interceptors<Interceptor> {
|
|
248
|
+
fns: Array<Interceptor | null> = [];
|
|
249
|
+
|
|
250
|
+
clear(): void {
|
|
251
|
+
this.fns = [];
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
eject(id: number | Interceptor): void {
|
|
255
|
+
const index = this.getInterceptorIndex(id);
|
|
256
|
+
if (this.fns[index]) {
|
|
257
|
+
this.fns[index] = null;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
exists(id: number | Interceptor): boolean {
|
|
262
|
+
const index = this.getInterceptorIndex(id);
|
|
263
|
+
return Boolean(this.fns[index]);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
getInterceptorIndex(id: number | Interceptor): number {
|
|
267
|
+
if (typeof id === 'number') {
|
|
268
|
+
return this.fns[id] ? id : -1;
|
|
269
|
+
}
|
|
270
|
+
return this.fns.indexOf(id);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
update(
|
|
274
|
+
id: number | Interceptor,
|
|
275
|
+
fn: Interceptor,
|
|
276
|
+
): number | Interceptor | false {
|
|
277
|
+
const index = this.getInterceptorIndex(id);
|
|
278
|
+
if (this.fns[index]) {
|
|
279
|
+
this.fns[index] = fn;
|
|
280
|
+
return id;
|
|
281
|
+
}
|
|
282
|
+
return false;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
use(fn: Interceptor): number {
|
|
286
|
+
this.fns.push(fn);
|
|
287
|
+
return this.fns.length - 1;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
export interface Middleware<Req, Res, Err, Options> {
|
|
292
|
+
error: Interceptors<ErrInterceptor<Err, Res, Req, Options>>;
|
|
293
|
+
request: Interceptors<ReqInterceptor<Req, Options>>;
|
|
294
|
+
response: Interceptors<ResInterceptor<Res, Req, Options>>;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export const createInterceptors = <Req, Res, Err, Options>(): Middleware<
|
|
298
|
+
Req,
|
|
299
|
+
Res,
|
|
300
|
+
Err,
|
|
301
|
+
Options
|
|
302
|
+
> => ({
|
|
303
|
+
error: new Interceptors<ErrInterceptor<Err, Res, Req, Options>>(),
|
|
304
|
+
request: new Interceptors<ReqInterceptor<Req, Options>>(),
|
|
305
|
+
response: new Interceptors<ResInterceptor<Res, Req, Options>>(),
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
const defaultQuerySerializer = createQuerySerializer({
|
|
309
|
+
allowReserved: false,
|
|
310
|
+
array: {
|
|
311
|
+
explode: true,
|
|
312
|
+
style: 'form',
|
|
313
|
+
},
|
|
314
|
+
object: {
|
|
315
|
+
explode: true,
|
|
316
|
+
style: 'deepObject',
|
|
317
|
+
},
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
const defaultHeaders = {
|
|
321
|
+
'Content-Type': 'application/json',
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
export const createConfig = <T extends ClientOptions = ClientOptions>(
|
|
325
|
+
override: Config<Omit<ClientOptions, keyof T> & T> = {},
|
|
326
|
+
): Config<Omit<ClientOptions, keyof T> & T> => ({
|
|
327
|
+
...jsonBodySerializer,
|
|
328
|
+
headers: defaultHeaders,
|
|
329
|
+
parseAs: 'auto',
|
|
330
|
+
querySerializer: defaultQuerySerializer,
|
|
331
|
+
...override,
|
|
332
|
+
});
|