@geekmidas/client 10.0.0-alpha.99 → 10.0.0

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.
Files changed (116) hide show
  1. package/CHANGELOG.md +154 -0
  2. package/README.md +57 -40
  3. package/dist/auth-fetcher.cjs +5 -7
  4. package/dist/auth-fetcher.cjs.map +1 -1
  5. package/dist/auth-fetcher.d.cts +17 -15
  6. package/dist/auth-fetcher.d.cts.map +1 -1
  7. package/dist/auth-fetcher.d.mts +17 -15
  8. package/dist/auth-fetcher.d.mts.map +1 -1
  9. package/dist/auth-fetcher.mjs +5 -6
  10. package/dist/auth-fetcher.mjs.map +1 -1
  11. package/dist/chunk-CUT6urMc.cjs +30 -0
  12. package/dist/endpoint-hooks.cjs +15 -11
  13. package/dist/endpoint-hooks.cjs.map +1 -1
  14. package/dist/endpoint-hooks.d.cts +7 -4
  15. package/dist/endpoint-hooks.d.cts.map +1 -1
  16. package/dist/endpoint-hooks.d.mts +7 -4
  17. package/dist/endpoint-hooks.d.mts.map +1 -1
  18. package/dist/endpoint-hooks.mjs +9 -5
  19. package/dist/endpoint-hooks.mjs.map +1 -1
  20. package/dist/fetcher-CakjC9C7.mjs +88 -0
  21. package/dist/fetcher-CakjC9C7.mjs.map +1 -0
  22. package/dist/fetcher-CwnSqc4D.cjs +100 -0
  23. package/dist/fetcher-CwnSqc4D.cjs.map +1 -0
  24. package/dist/fetcher.cjs +3 -115
  25. package/dist/fetcher.d.cts +8 -7
  26. package/dist/fetcher.d.cts.map +1 -1
  27. package/dist/fetcher.d.mts +8 -7
  28. package/dist/fetcher.d.mts.map +1 -1
  29. package/dist/fetcher.mjs +2 -90
  30. package/dist/infer.d.cts +13 -10
  31. package/dist/infer.d.cts.map +1 -1
  32. package/dist/infer.d.mts +13 -10
  33. package/dist/infer.d.mts.map +1 -1
  34. package/dist/infer.mjs +0 -1
  35. package/dist/openapi-hooks.cjs +16 -13
  36. package/dist/openapi-hooks.cjs.map +1 -1
  37. package/dist/openapi-hooks.d.cts +11 -8
  38. package/dist/openapi-hooks.d.cts.map +1 -1
  39. package/dist/openapi-hooks.d.mts +11 -8
  40. package/dist/openapi-hooks.d.mts.map +1 -1
  41. package/dist/openapi-hooks.mjs +12 -9
  42. package/dist/openapi-hooks.mjs.map +1 -1
  43. package/dist/openapi-types.d.cts +6 -5
  44. package/dist/openapi-types.d.cts.map +1 -1
  45. package/dist/openapi-types.d.mts +6 -5
  46. package/dist/openapi-types.d.mts.map +1 -1
  47. package/dist/openapi.cjs +526 -0
  48. package/dist/openapi.cjs.map +1 -0
  49. package/dist/openapi.mjs +501 -0
  50. package/dist/openapi.mjs.map +1 -0
  51. package/dist/react-query.cjs +16 -17
  52. package/dist/react-query.cjs.map +1 -1
  53. package/dist/react-query.d.cts +17 -12
  54. package/dist/react-query.d.cts.map +1 -1
  55. package/dist/react-query.d.mts +17 -12
  56. package/dist/react-query.d.mts.map +1 -1
  57. package/dist/react-query.mjs +9 -10
  58. package/dist/react-query.mjs.map +1 -1
  59. package/dist/types-D8Jrl4o3.d.mts +110 -0
  60. package/dist/types-D8Jrl4o3.d.mts.map +1 -0
  61. package/dist/types-DMQMHePI.d.cts +110 -0
  62. package/dist/types-DMQMHePI.d.cts.map +1 -0
  63. package/dist/types.d.cts +2 -122
  64. package/dist/types.d.mts +2 -122
  65. package/dist/types.mjs +0 -1
  66. package/package.json +15 -31
  67. package/src/__tests__/auth-fetcher.spec.ts +505 -0
  68. package/src/__tests__/endpoint-hooks.spec.tsx +374 -0
  69. package/src/__tests__/fetcher.spec.ts +580 -0
  70. package/src/__tests__/infer.integration.spec.ts +188 -0
  71. package/src/__tests__/infer.spec.ts +189 -0
  72. package/src/__tests__/method-restrictions.spec.tsx +227 -0
  73. package/src/__tests__/mutation-inference.spec.tsx +343 -0
  74. package/src/__tests__/openapi-hooks.spec.tsx +557 -0
  75. package/src/__tests__/react-query-infinite.spec.tsx +1003 -0
  76. package/src/__tests__/react-query-invalidation.spec.tsx +239 -0
  77. package/src/__tests__/react-query.spec.tsx +582 -0
  78. package/src/__tests__/setup.ts +281 -0
  79. package/src/__tests__/types.spec.ts +134 -0
  80. package/src/__tests__/url-parsing.spec.ts +196 -0
  81. package/src/auth-fetcher.ts +288 -0
  82. package/src/endpoint-hooks.ts +346 -0
  83. package/src/fetcher.ts +171 -0
  84. package/src/infer.ts +162 -0
  85. package/src/openapi-hooks.ts +193 -0
  86. package/src/openapi-types.d.ts +440 -0
  87. package/src/openapi.json +595 -0
  88. package/src/react-query.ts +341 -0
  89. package/src/types.ts +226 -0
  90. package/tsconfig.json +12 -0
  91. package/dist/fetcher.cjs.map +0 -1
  92. package/dist/fetcher.mjs.map +0 -1
  93. package/dist/index.cjs +0 -15
  94. package/dist/index.d.cts +0 -7
  95. package/dist/index.d.mts +0 -7
  96. package/dist/index.mjs +0 -7
  97. package/dist/methods.cjs +0 -21
  98. package/dist/methods.cjs.map +0 -1
  99. package/dist/methods.d.cts +0 -23
  100. package/dist/methods.d.cts.map +0 -1
  101. package/dist/methods.d.mts +0 -23
  102. package/dist/methods.d.mts.map +0 -1
  103. package/dist/methods.mjs +0 -19
  104. package/dist/methods.mjs.map +0 -1
  105. package/dist/telemetry-g3BE86Wd.d.cts +0 -68
  106. package/dist/telemetry-g3BE86Wd.d.cts.map +0 -1
  107. package/dist/telemetry-g3BE86Wd.d.mts +0 -68
  108. package/dist/telemetry-g3BE86Wd.d.mts.map +0 -1
  109. package/dist/telemetry.cjs +0 -128
  110. package/dist/telemetry.cjs.map +0 -1
  111. package/dist/telemetry.d.cts +0 -2
  112. package/dist/telemetry.d.mts +0 -2
  113. package/dist/telemetry.mjs +0 -125
  114. package/dist/telemetry.mjs.map +0 -1
  115. package/dist/types.d.cts.map +0 -1
  116. package/dist/types.d.mts.map +0 -1
@@ -0,0 +1,341 @@
1
+ import type {
2
+ QueryClient,
3
+ QueryFunctionContext,
4
+ UseInfiniteQueryOptions,
5
+ UseMutationOptions,
6
+ UseQueryOptions,
7
+ } from '@tanstack/react-query';
8
+ import {
9
+ useInfiniteQuery,
10
+ useMutation,
11
+ useQuery,
12
+ useQueryClient,
13
+ } from '@tanstack/react-query';
14
+ import { useMemo } from 'react';
15
+ import { createTypedFetcher } from './fetcher';
16
+ import type {
17
+ ExtractEndpointResponse,
18
+ FetcherOptions,
19
+ FilteredRequestConfig,
20
+ MutationEndpoint,
21
+ QueryEndpoint,
22
+ TypedEndpoint,
23
+ } from './types';
24
+
25
+ export interface TypedQueryClientOptions extends FetcherOptions {
26
+ queryClient?: QueryClient;
27
+ }
28
+
29
+ export class TypedQueryClient<Paths> {
30
+ private fetcher: ReturnType<typeof createTypedFetcher<Paths>>;
31
+ private queryClient?: QueryClient;
32
+
33
+ constructor(options: TypedQueryClientOptions = {}) {
34
+ this.fetcher = createTypedFetcher<Paths>(options);
35
+ this.queryClient = options.queryClient;
36
+ }
37
+
38
+ useQuery<T extends QueryEndpoint<Paths>>(
39
+ endpoint: T,
40
+ config?: FilteredRequestConfig<Paths, T>,
41
+ options?: Omit<
42
+ UseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>,
43
+ 'queryKey' | 'queryFn'
44
+ >,
45
+ ) {
46
+ const queryKey = this.buildQueryKey(endpoint, config);
47
+
48
+ // Memoize the combined options to prevent unnecessary re-renders
49
+ const memoizedOptions = useMemo(
50
+ () => ({
51
+ queryKey,
52
+ queryFn: () => this.fetcher(endpoint, config),
53
+ ...options,
54
+ }),
55
+ // Dependencies: queryKey, endpoint, config, and options
56
+ // Note: We stringify config and options to ensure stable references
57
+ // eslint-disable-next-line react-hooks/exhaustive-deps
58
+ [
59
+ queryKey.join(','),
60
+ endpoint,
61
+ JSON.stringify(config),
62
+ JSON.stringify(options),
63
+ ],
64
+ );
65
+
66
+ return useQuery<ExtractEndpointResponse<Paths, T>, Response>(
67
+ memoizedOptions,
68
+ );
69
+ }
70
+
71
+ useMutation<T extends MutationEndpoint<Paths>>(
72
+ endpoint: T,
73
+ options?: Omit<
74
+ UseMutationOptions<
75
+ ExtractEndpointResponse<Paths, T>,
76
+ Response,
77
+ FilteredRequestConfig<Paths, T>
78
+ >,
79
+ 'mutationFn'
80
+ >,
81
+ ) {
82
+ // Memoize the combined options to prevent unnecessary re-renders
83
+ const memoizedOptions = useMemo(
84
+ () => ({
85
+ mutationFn: (config: FilteredRequestConfig<Paths, T>) =>
86
+ this.fetcher(endpoint, config),
87
+ ...options,
88
+ }),
89
+ // Dependencies: endpoint and options
90
+ // Note: We stringify options to ensure stable reference
91
+ // eslint-disable-next-line react-hooks/exhaustive-deps
92
+ [endpoint, JSON.stringify(options)],
93
+ );
94
+
95
+ return useMutation<
96
+ ExtractEndpointResponse<Paths, T>,
97
+ Response,
98
+ FilteredRequestConfig<Paths, T>
99
+ >(memoizedOptions);
100
+ }
101
+
102
+ useInfiniteQuery<
103
+ T extends QueryEndpoint<Paths>,
104
+ TPageData = ExtractEndpointResponse<Paths, T>,
105
+ TPageParam = unknown,
106
+ >(
107
+ endpoint: T,
108
+ options: Omit<
109
+ UseInfiniteQueryOptions<
110
+ TPageData,
111
+ Response,
112
+ { pages: TPageData[]; pageParams: TPageParam[] },
113
+ unknown[],
114
+ TPageParam
115
+ >,
116
+ 'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'
117
+ > & {
118
+ getNextPageParam: (
119
+ lastPage: TPageData,
120
+ allPages: TPageData[],
121
+ lastPageParam: TPageParam,
122
+ allPageParams: TPageParam[],
123
+ ) => TPageParam | undefined;
124
+ initialPageParam: TPageParam;
125
+ },
126
+ config?: FilteredRequestConfig<Paths, T>,
127
+ ) {
128
+ const queryKey = this.buildQueryKey(endpoint, config);
129
+
130
+ // Memoize the combined options to prevent unnecessary re-renders
131
+ const memoizedOptions = useMemo(
132
+ () => ({
133
+ queryKey,
134
+ queryFn: ({
135
+ pageParam,
136
+ }: QueryFunctionContext<unknown[], TPageParam>) => {
137
+ let mergedConfig = config;
138
+ if (pageParam !== undefined && config) {
139
+ // If pageParam is an object, spread it into query
140
+ const pageQuery =
141
+ typeof pageParam === 'object' ? pageParam : { page: pageParam };
142
+ mergedConfig = {
143
+ ...config,
144
+ query: { ...(config as any).query, ...pageQuery },
145
+ } as any;
146
+ } else if (pageParam !== undefined && !config) {
147
+ // If pageParam is an object, use it directly, otherwise wrap in page property
148
+ const pageQuery =
149
+ typeof pageParam === 'object' ? pageParam : { page: pageParam };
150
+ mergedConfig = { query: pageQuery } as any;
151
+ }
152
+ return this.fetcher(endpoint, mergedConfig) as Promise<TPageData>;
153
+ },
154
+ ...options,
155
+ }),
156
+ // Dependencies: queryKey, endpoint, config, and options
157
+ // Note: We stringify config and options to ensure stable references
158
+ // eslint-disable-next-line react-hooks/exhaustive-deps
159
+ [
160
+ queryKey.join(','),
161
+ endpoint,
162
+ JSON.stringify(config),
163
+ JSON.stringify(options),
164
+ ],
165
+ );
166
+
167
+ return useInfiniteQuery<
168
+ TPageData,
169
+ Response,
170
+ { pages: TPageData[]; pageParams: TPageParam[] },
171
+ unknown[],
172
+ TPageParam
173
+ >(memoizedOptions);
174
+ }
175
+
176
+ buildQueryKey<T extends TypedEndpoint<Paths>>(
177
+ endpoint: T,
178
+ config?: FilteredRequestConfig<Paths, T>,
179
+ ): unknown[] {
180
+ const key: unknown[] = [endpoint];
181
+
182
+ if (config && 'params' in config && config.params) {
183
+ key.push({ params: config.params });
184
+ }
185
+
186
+ if (config && 'query' in config && config.query) {
187
+ key.push({ query: config.query });
188
+ }
189
+
190
+ return key;
191
+ }
192
+
193
+ /**
194
+ * Invalidate queries for a specific endpoint with optional config
195
+ * @param endpoint - The endpoint to invalidate (e.g., 'GET /users')
196
+ * @param config - Optional params/query to match specific queries
197
+ * @returns Promise that resolves when invalidation is complete
198
+ */
199
+ invalidateQueries<T extends QueryEndpoint<Paths>>(
200
+ endpoint: T,
201
+ config?: FilteredRequestConfig<Paths, T>,
202
+ ): Promise<void> {
203
+ const queryClient = this.getQueryClient();
204
+ const queryKey = this.buildQueryKey(endpoint, config);
205
+
206
+ return queryClient.invalidateQueries({
207
+ queryKey,
208
+ exact: !!config, // Use exact matching if config is provided
209
+ });
210
+ }
211
+
212
+ /**
213
+ * Invalidate all queries in the cache
214
+ * @returns Promise that resolves when invalidation is complete
215
+ */
216
+ invalidateAllQueries(): Promise<void> {
217
+ const queryClient = this.getQueryClient();
218
+ return queryClient.invalidateQueries();
219
+ }
220
+
221
+ /**
222
+ * Get the underlying QueryClient instance
223
+ * @returns The QueryClient instance
224
+ */
225
+ getQueryClient(): QueryClient {
226
+ if (this.queryClient) {
227
+ return this.queryClient;
228
+ }
229
+
230
+ // If no query client was provided, try to get it from context
231
+ // This will throw if used outside of QueryClientProvider
232
+ throw new Error(
233
+ 'No QueryClient set, please provide a QueryClient via the queryClient option or ensure you are within a QueryClientProvider',
234
+ );
235
+ }
236
+
237
+ /**
238
+ * Set the QueryClient instance
239
+ * @param queryClient - The QueryClient instance to use
240
+ */
241
+ setQueryClient(queryClient: QueryClient): void {
242
+ this.queryClient = queryClient;
243
+ }
244
+ }
245
+
246
+ export function createTypedQueryClient<Paths>(
247
+ options?: TypedQueryClientOptions,
248
+ ) {
249
+ return new TypedQueryClient<Paths>(options);
250
+ }
251
+
252
+ // Hook exports for convenience
253
+ export function useTypedQuery<Paths, T extends QueryEndpoint<Paths>>(
254
+ client: TypedQueryClient<Paths>,
255
+ endpoint: T,
256
+ config?: FilteredRequestConfig<Paths, T>,
257
+ options?: Omit<
258
+ UseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>,
259
+ 'queryKey' | 'queryFn'
260
+ >,
261
+ ) {
262
+ return client.useQuery(endpoint, config, options);
263
+ }
264
+
265
+ export function useTypedMutation<Paths, T extends MutationEndpoint<Paths>>(
266
+ client: TypedQueryClient<Paths>,
267
+ endpoint: T,
268
+ options?: Omit<
269
+ UseMutationOptions<
270
+ ExtractEndpointResponse<Paths, T>,
271
+ Response,
272
+ FilteredRequestConfig<Paths, T>
273
+ >,
274
+ 'mutationFn'
275
+ >,
276
+ ) {
277
+ return client.useMutation(endpoint, options);
278
+ }
279
+
280
+ export function useTypedInfiniteQuery<
281
+ Paths,
282
+ T extends QueryEndpoint<Paths>,
283
+ TPageData = ExtractEndpointResponse<Paths, T>,
284
+ TPageParam = unknown,
285
+ >(
286
+ client: TypedQueryClient<Paths>,
287
+ endpoint: T,
288
+ options: Omit<
289
+ UseInfiniteQueryOptions<
290
+ TPageData,
291
+ Response,
292
+ { pages: TPageData[]; pageParams: TPageParam[] },
293
+ unknown[],
294
+ TPageParam
295
+ >,
296
+ 'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'
297
+ > & {
298
+ getNextPageParam: (
299
+ lastPage: TPageData,
300
+ allPages: TPageData[],
301
+ lastPageParam: TPageParam,
302
+ allPageParams: TPageParam[],
303
+ ) => TPageParam | undefined;
304
+ initialPageParam: TPageParam;
305
+ },
306
+ config?: FilteredRequestConfig<Paths, T>,
307
+ ) {
308
+ return client.useInfiniteQuery(endpoint, options, config);
309
+ }
310
+
311
+ /**
312
+ * Hook to invalidate queries using the current QueryClient from context
313
+ */
314
+ export function useTypedInvalidateQueries<Paths>(
315
+ client: TypedQueryClient<Paths>,
316
+ ) {
317
+ const queryClient = useQueryClient();
318
+
319
+ return {
320
+ /**
321
+ * Invalidate queries for a specific endpoint
322
+ */
323
+ invalidateQueries: <T extends QueryEndpoint<Paths>>(
324
+ endpoint: T,
325
+ config?: FilteredRequestConfig<Paths, T>,
326
+ ) => {
327
+ const queryKey = client.buildQueryKey(endpoint, config);
328
+ return queryClient.invalidateQueries({
329
+ queryKey,
330
+ exact: !!config,
331
+ });
332
+ },
333
+
334
+ /**
335
+ * Invalidate all queries
336
+ */
337
+ invalidateAllQueries: () => {
338
+ return queryClient.invalidateQueries();
339
+ },
340
+ };
341
+ }
package/src/types.ts ADDED
@@ -0,0 +1,226 @@
1
+ export type OpenAPIRoutes<Paths> = keyof Paths;
2
+
3
+ type HttpMethod =
4
+ | 'get'
5
+ | 'post'
6
+ | 'put'
7
+ | 'patch'
8
+ | 'delete'
9
+ | 'head'
10
+ | 'options';
11
+
12
+ export type ExtractMethod<Paths, Route extends OpenAPIRoutes<Paths>> = Extract<
13
+ keyof Paths[Route],
14
+ HttpMethod
15
+ >;
16
+
17
+ export type ExtractPathParams<
18
+ Paths,
19
+ Route extends OpenAPIRoutes<Paths>,
20
+ > = Paths[Route] extends {
21
+ parameters?: { path?: infer P };
22
+ }
23
+ ? P
24
+ : never;
25
+
26
+ export type ExtractQueryParams<
27
+ Paths,
28
+ Route extends OpenAPIRoutes<Paths>,
29
+ Method extends ExtractMethod<Paths, Route>,
30
+ > = Paths[Route][Method] extends { parameters?: { query?: infer Q } }
31
+ ? Q
32
+ : never;
33
+
34
+ export type ExtractRequestBody<
35
+ Paths,
36
+ Route extends OpenAPIRoutes<Paths>,
37
+ Method extends ExtractMethod<Paths, Route>,
38
+ > = Paths[Route][Method] extends {
39
+ requestBody?: { content?: { 'application/json'?: infer B } };
40
+ }
41
+ ? B
42
+ : never;
43
+
44
+ export type ExtractResponse<
45
+ Paths,
46
+ Route extends OpenAPIRoutes<Paths>,
47
+ Method extends ExtractMethod<Paths, Route>,
48
+ > = Paths[Route][Method] extends {
49
+ responses?: { 200?: { content?: { 'application/json'?: infer R } } };
50
+ }
51
+ ? R
52
+ : Paths[Route][Method] extends {
53
+ responses?: { 201?: { content?: { 'application/json'?: infer R } } };
54
+ }
55
+ ? R
56
+ : never;
57
+
58
+ export type RequestConfig<
59
+ Paths,
60
+ Route extends OpenAPIRoutes<Paths>,
61
+ Method extends ExtractMethod<Paths, Route>,
62
+ > = {
63
+ params?: ExtractPathParams<Paths, Route>;
64
+ query?: ExtractQueryParams<Paths, Route, Method>;
65
+ body?: ExtractRequestBody<Paths, Route, Method>;
66
+ headers?: Record<string, string>;
67
+ };
68
+
69
+ export type EndpointString = `${Uppercase<string>} ${string}`;
70
+
71
+ // Generate all valid endpoint strings from OpenAPI paths
72
+ // Uses Extract with HttpMethod to filter out non-HTTP keys like 'parameters'
73
+ export type ValidEndpoint<Paths> = {
74
+ [Route in keyof Paths]: {
75
+ [Method in Extract<keyof Paths[Route], HttpMethod>]: `${Uppercase<
76
+ string & Method
77
+ >} ${string & Route}`;
78
+ }[Extract<keyof Paths[Route], HttpMethod>];
79
+ }[keyof Paths];
80
+
81
+ // Helper type to get autocomplete for endpoint strings
82
+ export type TypedEndpoint<Paths> =
83
+ ValidEndpoint<Paths> extends infer E ? (E extends string ? E : never) : never;
84
+
85
+ // Filter endpoints by HTTP method
86
+ export type FilterEndpointByMethod<
87
+ Paths,
88
+ Method extends string,
89
+ > = ValidEndpoint<Paths> extends infer E
90
+ ? E extends `${Method} ${string}`
91
+ ? E
92
+ : never
93
+ : never;
94
+
95
+ // Query endpoints (GET only)
96
+ export type QueryEndpoint<Paths> = FilterEndpointByMethod<Paths, 'GET'>;
97
+
98
+ // Mutation endpoints (POST, PATCH, PUT, DELETE)
99
+ export type MutationEndpoint<Paths> =
100
+ | FilterEndpointByMethod<Paths, 'POST'>
101
+ | FilterEndpointByMethod<Paths, 'PATCH'>
102
+ | FilterEndpointByMethod<Paths, 'PUT'>
103
+ | FilterEndpointByMethod<Paths, 'DELETE'>;
104
+
105
+ export type ParseEndpoint<T extends EndpointString> =
106
+ T extends `${infer Method} ${infer Route}`
107
+ ? { method: Lowercase<Method>; route: Route }
108
+ : never;
109
+
110
+ export type ExtractEndpointResponse<
111
+ Paths,
112
+ T extends EndpointString,
113
+ > = T extends `${infer Method} ${infer Route}`
114
+ ? Route extends OpenAPIRoutes<Paths>
115
+ ? Lowercase<Method> extends ExtractMethod<Paths, Route>
116
+ ? ExtractResponse<Paths, Route, Lowercase<Method>>
117
+ : never
118
+ : never
119
+ : never;
120
+
121
+ export type ExtractEndpointConfig<
122
+ Paths,
123
+ T extends EndpointString,
124
+ > = T extends `${infer Method} ${infer Route}`
125
+ ? Route extends OpenAPIRoutes<Paths>
126
+ ? Lowercase<Method> extends ExtractMethod<Paths, Route>
127
+ ? RequestConfig<Paths, Route, Lowercase<Method>>
128
+ : never
129
+ : never
130
+ : never;
131
+
132
+ /**
133
+ * Build a request config type where:
134
+ * - `params` is required if the endpoint has path parameters
135
+ * - `body` is required if the endpoint has a request body
136
+ * - `query` and `headers` are always optional
137
+ */
138
+ export type FilteredRequestConfig<
139
+ Paths,
140
+ T extends EndpointString,
141
+ > = T extends `${infer Method} ${infer Route}`
142
+ ? Route extends OpenAPIRoutes<Paths>
143
+ ? Lowercase<Method> extends ExtractMethod<Paths, Route>
144
+ ? BuildRequestConfig<
145
+ ExtractPathParams<Paths, Route>,
146
+ ExtractQueryParams<Paths, Route, Lowercase<Method>>,
147
+ ExtractRequestBody<Paths, Route, Lowercase<Method>>
148
+ >
149
+ : never
150
+ : never
151
+ : never;
152
+
153
+ /**
154
+ * Helper to build request config with correct required/optional fields.
155
+ * Uses [T] extends [never] pattern to prevent distribution over union types,
156
+ * which would cause the entire type to become `never`.
157
+ */
158
+ type BuildRequestConfig<TParams, TQuery, TBody> = SimplifyIntersection<
159
+ // params: required if not never
160
+ ([TParams] extends [never] ? {} : { params: TParams }) &
161
+ // body: required if not never
162
+ ([TBody] extends [never] ? {} : { body: TBody }) &
163
+ // query: optional if not never
164
+ ([TQuery] extends [never] ? {} : { query?: TQuery }) & {
165
+ // headers: always optional
166
+ headers?: Record<string, string>;
167
+ }
168
+ >;
169
+
170
+ /**
171
+ * Simplify intersection types for better IDE display
172
+ */
173
+ type SimplifyIntersection<T> = { [K in keyof T]: T[K] };
174
+
175
+ /**
176
+ * Check if the config object is required (has any required fields)
177
+ */
178
+ export type IsConfigRequired<
179
+ Paths,
180
+ T extends EndpointString,
181
+ > = T extends `${infer Method} ${infer Route}`
182
+ ? Route extends OpenAPIRoutes<Paths>
183
+ ? Lowercase<Method> extends ExtractMethod<Paths, Route>
184
+ ? ExtractPathParams<Paths, Route> extends never
185
+ ? ExtractRequestBody<Paths, Route, Lowercase<Method>> extends never
186
+ ? false
187
+ : true
188
+ : true
189
+ : false
190
+ : false
191
+ : false;
192
+
193
+ /**
194
+ * Typed function signature for the API client.
195
+ * Config is required when endpoint has path params or body.
196
+ */
197
+ export type TypedApiFunction<Paths> = <T extends TypedEndpoint<Paths>>(
198
+ endpoint: T,
199
+ ...args: IsConfigRequired<Paths, T> extends true
200
+ ? [config: FilteredRequestConfig<Paths, T>]
201
+ : [config?: FilteredRequestConfig<Paths, T>]
202
+ ) => Promise<ExtractEndpointResponse<Paths, T>>;
203
+
204
+ export interface FetcherOptions {
205
+ baseURL?: string;
206
+ headers?: Record<string, string>;
207
+ onRequest?: (config: RequestInit) => RequestInit | Promise<RequestInit>;
208
+ onResponse?: (response: Response) => Response | Promise<Response>;
209
+ onError?: (error: Error) => void | Promise<void>;
210
+ fetch?: typeof fetch;
211
+ }
212
+
213
+ export type WrappedResult<T, E = unknown> =
214
+ | { ok: true; data: T }
215
+ | { ok: false; error: E };
216
+
217
+ export type ErrorTransformer<E> = (error: unknown) => E | Promise<E>;
218
+
219
+ export type WrappedApiFunction<Paths, E = unknown> = <
220
+ T extends TypedEndpoint<Paths>,
221
+ >(
222
+ endpoint: T,
223
+ ...args: IsConfigRequired<Paths, T> extends true
224
+ ? [config: FilteredRequestConfig<Paths, T>]
225
+ : [config?: FilteredRequestConfig<Paths, T>]
226
+ ) => Promise<WrappedResult<ExtractEndpointResponse<Paths, T>, E>>;
package/tsconfig.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "rootDir": "./src",
6
+ "composite": true,
7
+ "lib": ["ES2023", "DOM"],
8
+ "jsx": "react-jsx"
9
+ },
10
+ "include": ["src/**/*"],
11
+ "exclude": ["src/__tests__/**/*"]
12
+ }
@@ -1 +0,0 @@
1
- {"version":3,"file":"fetcher.cjs","names":["traceContextInjector","methodCalls"],"sources":["../src/fetcher.ts"],"sourcesContent":["import qs from 'qs';\nimport { methodCalls } from './methods';\nimport { type TraceContextInjector, traceContextInjector } from './telemetry';\nimport type {\n\tEndpointString,\n\tErrorTransformer,\n\tExtractEndpointResponse,\n\tFetcherOptions,\n\tFilteredRequestConfig,\n\tParseEndpoint,\n\tTypedApiFunction,\n\tTypedEndpoint,\n\tWrappedResult,\n} from './types';\n\nexport type { FetcherOptions, WrappedResult } from './types';\n\nexport class TypedFetcher<Paths> {\n\tprivate baseURL: string;\n\tprivate defaultHeaders: Record<string, string>;\n\tprivate options: FetcherOptions;\n\tprivate fetchFn: FetchFn;\n\tprivate injectTraceContext: TraceContextInjector | undefined;\n\n\tstatic getFetchFn(fn?: FetchFn): FetchFn {\n\t\tif (fn) {\n\t\t\treturn fn;\n\t\t}\n\n\t\tif (typeof window !== 'undefined' && typeof window.fetch === 'function') {\n\t\t\treturn window.fetch.bind(window);\n\t\t}\n\n\t\tif (\n\t\t\ttypeof globalThis !== 'undefined' &&\n\t\t\ttypeof globalThis.fetch === 'function'\n\t\t) {\n\t\t\treturn globalThis.fetch.bind(globalThis);\n\t\t}\n\n\t\tthrow new Error('No fetch implementation found');\n\t}\n\n\tconstructor(options: FetcherOptions = {}) {\n\t\tthis.baseURL = options.baseURL || '';\n\t\tthis.defaultHeaders = options.headers || {};\n\t\tthis.options = options;\n\t\tthis.fetchFn = TypedFetcher.getFetchFn(options.fetch);\n\t\tthis.injectTraceContext = traceContextInjector(\n\t\t\tthis.baseURL,\n\t\t\toptions.telemetry,\n\t\t);\n\t}\n\n\tasync request<T extends TypedEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t): Promise<ExtractEndpointResponse<Paths, T>> {\n\t\tconst { method, route } = this.parseEndpoint(endpoint);\n\n\t\t// Replace path parameters\n\t\tlet url = route;\n\t\tif (config && 'params' in config && config.params) {\n\t\t\tObject.entries(config.params as Record<string, unknown>).forEach(\n\t\t\t\t([key, value]) => {\n\t\t\t\t\turl = url.replace(`{${key}}`, encodeURIComponent(String(value)));\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\n\t\t// Add query parameters\n\t\tif (config && 'query' in config && config.query) {\n\t\t\tconst queryString = qs.stringify(config.query, {\n\t\t\t\tencode: true,\n\t\t\t\tarrayFormat: 'brackets',\n\t\t\t\tskipNulls: true,\n\t\t\t});\n\t\t\tif (queryString) {\n\t\t\t\turl += `?${queryString}`;\n\t\t\t}\n\t\t}\n\n\t\t// Build request configuration\n\t\tlet requestConfig: RequestInit = {\n\t\t\tmethod: method.toUpperCase(),\n\t\t\theaders: {\n\t\t\t\t...this.defaultHeaders,\n\t\t\t\t...((config && 'headers' in config && config.headers) || {}),\n\t\t\t},\n\t\t};\n\n\t\t// Add body if present\n\t\tif (config && 'body' in config && config.body) {\n\t\t\trequestConfig.body = JSON.stringify(config.body);\n\t\t\trequestConfig.headers = {\n\t\t\t\t...requestConfig.headers,\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t};\n\t\t}\n\n\t\t// Trace context, before the interceptor so it sees the final headers\n\t\tthis.injectTraceContext?.(\n\t\t\t`${this.baseURL}${url}`,\n\t\t\trequestConfig.headers as Record<string, string>,\n\t\t);\n\n\t\t// Apply request interceptor\n\t\tif (this.options.onRequest) {\n\t\t\trequestConfig = await this.options.onRequest(requestConfig);\n\t\t}\n\n\t\ttry {\n\t\t\t// Make the request\n\t\t\tlet response = await this.fetchFn(`${this.baseURL}${url}`, requestConfig);\n\n\t\t\t// Apply response interceptor\n\t\t\tif (this.options.onResponse) {\n\t\t\t\tresponse = await this.options.onResponse(response);\n\t\t\t}\n\n\t\t\t// Handle errors\n\t\t\tif (!response.ok) {\n\t\t\t\tthrow response;\n\t\t\t}\n\n\t\t\t// Handle empty responses (204 No Content, etc.)\n\t\t\tif (\n\t\t\t\tresponse.status === 204 ||\n\t\t\t\tresponse.headers.get('content-length') === '0'\n\t\t\t) {\n\t\t\t\treturn undefined as ExtractEndpointResponse<Paths, T>;\n\t\t\t}\n\n\t\t\t// Parse JSON response\n\t\t\tconst data = await response.json();\n\t\t\treturn data as ExtractEndpointResponse<Paths, T>;\n\t\t} catch (error) {\n\t\t\t// Apply error handler\n\t\t\tif (this.options.onError) {\n\t\t\t\t// @ts-expect-error\n\t\t\t\tawait this.options.onError(error);\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\twrap<E = unknown>(onError?: ErrorTransformer<E>) {\n\t\treturn <T extends TypedEndpoint<Paths>>(\n\t\t\tendpoint: T,\n\t\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t\t): Promise<WrappedResult<ExtractEndpointResponse<Paths, T>, E>> =>\n\t\t\tthis.request(endpoint, config).then(\n\t\t\t\t(data) => ({ ok: true as const, data }),\n\t\t\t\tasync (error) => ({\n\t\t\t\t\tok: false as const,\n\t\t\t\t\terror: onError ? await onError(error) : (error as E),\n\t\t\t\t}),\n\t\t\t);\n\t}\n\n\tprivate parseEndpoint<T extends EndpointString>(\n\t\tendpoint: T,\n\t): ParseEndpoint<T> {\n\t\tconst [method, ...routeParts] = endpoint.split(' ');\n\t\tconst route = routeParts.join(' ');\n\t\treturn { method: method?.toLowerCase() ?? '', route } as ParseEndpoint<T>;\n\t}\n}\n\nexport function createTypedFetcher<Paths>(options?: FetcherOptions) {\n\tconst fetcher = new TypedFetcher<Paths>(options);\n\tconst fn = <T extends TypedEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t) => fetcher.request(endpoint, config);\n\n\treturn Object.assign(fn, methodCalls<Paths>(fn as TypedApiFunction<Paths>), {\n\t\twrap: <E = unknown>(onError?: ErrorTransformer<E>) =>\n\t\t\tObject.assign(fetcher.wrap(onError), fn, {\n\t\t\t\twrap: undefined,\n\t\t\t}),\n\t});\n}\n\nexport type FetchFn = typeof fetch;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,IAAa,eAAb,MAAa,aAAoB;CAChC;CACA;CACA;CACA;CACA;CAEA,OAAO,WAAW,IAAuB;EACxC,IAAI,IACH,OAAO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qs';\nimport { methodCalls } from './methods';\nimport { type TraceContextInjector, traceContextInjector } from './telemetry';\nimport type {\n\tEndpointString,\n\tErrorTransformer,\n\tExtractEndpointResponse,\n\tFetcherOptions,\n\tFilteredRequestConfig,\n\tParseEndpoint,\n\tTypedApiFunction,\n\tTypedEndpoint,\n\tWrappedResult,\n} from './types';\n\nexport type { FetcherOptions, WrappedResult } from './types';\n\nexport class TypedFetcher<Paths> {\n\tprivate baseURL: string;\n\tprivate defaultHeaders: Record<string, string>;\n\tprivate options: FetcherOptions;\n\tprivate fetchFn: FetchFn;\n\tprivate injectTraceContext: TraceContextInjector | undefined;\n\n\tstatic getFetchFn(fn?: FetchFn): FetchFn {\n\t\tif (fn) {\n\t\t\treturn fn;\n\t\t}\n\n\t\tif (typeof window !== 'undefined' && typeof window.fetch === 'function') {\n\t\t\treturn window.fetch.bind(window);\n\t\t}\n\n\t\tif (\n\t\t\ttypeof globalThis !== 'undefined' &&\n\t\t\ttypeof globalThis.fetch === 'function'\n\t\t) {\n\t\t\treturn globalThis.fetch.bind(globalThis);\n\t\t}\n\n\t\tthrow new Error('No fetch implementation found');\n\t}\n\n\tconstructor(options: FetcherOptions = {}) {\n\t\tthis.baseURL = options.baseURL || '';\n\t\tthis.defaultHeaders = options.headers || {};\n\t\tthis.options = options;\n\t\tthis.fetchFn = TypedFetcher.getFetchFn(options.fetch);\n\t\tthis.injectTraceContext = traceContextInjector(\n\t\t\tthis.baseURL,\n\t\t\toptions.telemetry,\n\t\t);\n\t}\n\n\tasync request<T extends TypedEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t): Promise<ExtractEndpointResponse<Paths, T>> {\n\t\tconst { method, route } = this.parseEndpoint(endpoint);\n\n\t\t// Replace path parameters\n\t\tlet url = route;\n\t\tif (config && 'params' in config && config.params) {\n\t\t\tObject.entries(config.params as Record<string, unknown>).forEach(\n\t\t\t\t([key, value]) => {\n\t\t\t\t\turl = url.replace(`{${key}}`, encodeURIComponent(String(value)));\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\n\t\t// Add query parameters\n\t\tif (config && 'query' in config && config.query) {\n\t\t\tconst queryString = qs.stringify(config.query, {\n\t\t\t\tencode: true,\n\t\t\t\tarrayFormat: 'brackets',\n\t\t\t\tskipNulls: true,\n\t\t\t});\n\t\t\tif (queryString) {\n\t\t\t\turl += `?${queryString}`;\n\t\t\t}\n\t\t}\n\n\t\t// Build request configuration\n\t\tlet requestConfig: RequestInit = {\n\t\t\tmethod: method.toUpperCase(),\n\t\t\theaders: {\n\t\t\t\t...this.defaultHeaders,\n\t\t\t\t...((config && 'headers' in config && config.headers) || {}),\n\t\t\t},\n\t\t};\n\n\t\t// Add body if present\n\t\tif (config && 'body' in config && config.body) {\n\t\t\trequestConfig.body = JSON.stringify(config.body);\n\t\t\trequestConfig.headers = {\n\t\t\t\t...requestConfig.headers,\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t};\n\t\t}\n\n\t\t// Trace context, before the interceptor so it sees the final headers\n\t\tthis.injectTraceContext?.(\n\t\t\t`${this.baseURL}${url}`,\n\t\t\trequestConfig.headers as Record<string, string>,\n\t\t);\n\n\t\t// Apply request interceptor\n\t\tif (this.options.onRequest) {\n\t\t\trequestConfig = await this.options.onRequest(requestConfig);\n\t\t}\n\n\t\ttry {\n\t\t\t// Make the request\n\t\t\tlet response = await this.fetchFn(`${this.baseURL}${url}`, requestConfig);\n\n\t\t\t// Apply response interceptor\n\t\t\tif (this.options.onResponse) {\n\t\t\t\tresponse = await this.options.onResponse(response);\n\t\t\t}\n\n\t\t\t// Handle errors\n\t\t\tif (!response.ok) {\n\t\t\t\tthrow response;\n\t\t\t}\n\n\t\t\t// Handle empty responses (204 No Content, etc.)\n\t\t\tif (\n\t\t\t\tresponse.status === 204 ||\n\t\t\t\tresponse.headers.get('content-length') === '0'\n\t\t\t) {\n\t\t\t\treturn undefined as ExtractEndpointResponse<Paths, T>;\n\t\t\t}\n\n\t\t\t// Parse JSON response\n\t\t\tconst data = await response.json();\n\t\t\treturn data as ExtractEndpointResponse<Paths, T>;\n\t\t} catch (error) {\n\t\t\t// Apply error handler\n\t\t\tif (this.options.onError) {\n\t\t\t\t// @ts-expect-error\n\t\t\t\tawait this.options.onError(error);\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\twrap<E = unknown>(onError?: ErrorTransformer<E>) {\n\t\treturn <T extends TypedEndpoint<Paths>>(\n\t\t\tendpoint: T,\n\t\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t\t): Promise<WrappedResult<ExtractEndpointResponse<Paths, T>, E>> =>\n\t\t\tthis.request(endpoint, config).then(\n\t\t\t\t(data) => ({ ok: true as const, data }),\n\t\t\t\tasync (error) => ({\n\t\t\t\t\tok: false as const,\n\t\t\t\t\terror: onError ? await onError(error) : (error as E),\n\t\t\t\t}),\n\t\t\t);\n\t}\n\n\tprivate parseEndpoint<T extends EndpointString>(\n\t\tendpoint: T,\n\t): ParseEndpoint<T> {\n\t\tconst [method, ...routeParts] = endpoint.split(' ');\n\t\tconst route = routeParts.join(' ');\n\t\treturn { method: method?.toLowerCase() ?? '', route } as ParseEndpoint<T>;\n\t}\n}\n\nexport function createTypedFetcher<Paths>(options?: FetcherOptions) {\n\tconst fetcher = new TypedFetcher<Paths>(options);\n\tconst fn = <T extends TypedEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t) => fetcher.request(endpoint, config);\n\n\treturn Object.assign(fn, methodCalls<Paths>(fn as TypedApiFunction<Paths>), {\n\t\twrap: <E = unknown>(onError?: ErrorTransformer<E>) =>\n\t\t\tObject.assign(fetcher.wrap(onError), fn, {\n\t\t\t\twrap: undefined,\n\t\t\t}),\n\t});\n}\n\nexport type FetchFn = typeof fetch;\n"],"mappings":";;;;AAiBA,IAAa,eAAb,MAAa,aAAoB;CAChC;CACA;CACA;CACA;CACA;CAEA,OAAO,WAAW,IAAuB;EACxC,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c,OACf;EAGA,IAAI,KAAK,QAAQ,WAChB,gBAAgB,MAAM,KAAK,QAAQ,UAAU,aAAa;EAG3D,IAAI;GAEH,IAAI,WAAW,MAAM,KAAK,QAAQ,GAAG,KAAK,UAAU,OAAO,aAAa;GAGxE,IAAI,KAAK,QAAQ,YAChB,WAAW,MAAM,KAAK,QAAQ,WAAW,QAAQ;GAIlD,IAAI,CAAC,SAAS,IACb,MAAM;GAIP,IACC,SAAS,WAAW,OACpB,SAAS,QAAQ,IAAI,gBAAgB,MAAM,KAE3C;GAKD,OAAO,MADY,SAAS,KAAK;EAElC,SAAS,OAAO;GAEf,IAAI,KAAK,QAAQ,SAEhB,MAAM,KAAK,QAAQ,QAAQ,KAAK;GAEjC,MAAM;EACP;CACD;CAEA,KAAkB,SAA+B;EAChD,QACC,UACA,WAEA,KAAK,QAAQ,UAAU,MAAM,CAAC,CAAC,MAC7B,UAAU;GAAE,IAAI;GAAe;EAAK,IACrC,OAAO,WAAW;GACjB,IAAI;GACJ,OAAO,UAAU,MAAM,QAAQ,KAAK,IAAK;EAC1C,EACD;CACF;CAEA,cACC,UACmB;EACnB,MAAM,CAAC,QAAQ,GAAG,cAAc,SAAS,MAAM,GAAG;EAClD,MAAM,QAAQ,WAAW,KAAK,GAAG;EACjC,OAAO;GAAE,QAAQ,QAAQ,YAAY,KAAK;GAAI;EAAM;CACrD;AACD;AAEA,SAAgB,mBAA0B,SAA0B;CACnE,MAAM,UAAU,IAAI,aAAoB,OAAO;CAC/C,MAAM,MACL,UACA,WACI,QAAQ,QAAQ,UAAU,MAAM;CAErC,OAAO,OAAO,OAAO,IAAI,YAAmB,EAA6B,GAAG,EAC3E,OAAoB,YACnB,OAAO,OAAO,QAAQ,KAAK,OAAO,GAAG,IAAI,EACxC,MAAM,KAAA,EACP,CAAC,EACH,CAAC;AACF"}
package/dist/index.cjs DELETED
@@ -1,15 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_methods = require("./methods.cjs");
3
- const require_telemetry = require("./telemetry.cjs");
4
- const require_fetcher = require("./fetcher.cjs");
5
- const require_auth_fetcher = require("./auth-fetcher.cjs");
6
- require("./infer.cjs");
7
- require("./types.cjs");
8
- exports.CALL_METHODS = require_methods.CALL_METHODS;
9
- exports.InvalidClientSampleRate = require_telemetry.InvalidClientSampleRate;
10
- exports.TypedFetcher = require_fetcher.TypedFetcher;
11
- exports.createAuthAwareFetcher = require_auth_fetcher.createAuthAwareFetcher;
12
- exports.createTypedFetcher = require_fetcher.createTypedFetcher;
13
- exports.methodCalls = require_methods.methodCalls;
14
- exports.sampledAt = require_telemetry.sampledAt;
15
- exports.traceContextInjector = require_telemetry.traceContextInjector;
package/dist/index.d.cts DELETED
@@ -1,7 +0,0 @@
1
- import { a as traceContextInjector, i as sampledAt, n as InvalidClientSampleRate, r as TraceContextInjector, t as ClientTelemetryOptions } from "./telemetry-g3BE86Wd.cjs";
2
- import { EndpointString, ErrorTransformer, ExtractEndpointConfig, ExtractEndpointResponse, ExtractMethod, ExtractPathParams, ExtractQueryParams, ExtractRequestBody, ExtractResponse, FetcherOptions, FilterEndpointByMethod, FilteredRequestConfig, IsConfigRequired, MutationEndpoint, OpenAPIRoutes, ParseEndpoint, QueryEndpoint, RequestConfig, TypedApiFunction, TypedEndpoint, ValidEndpoint, WrappedApiFunction, WrappedResult } from "./types.cjs";
3
- import { CALL_METHODS, CallMethod, MethodCall, MethodCalls, RoutesFor, methodCalls } from "./methods.cjs";
4
- import { ApiKeyProvider, AuthFetcherOptions, AuthStrategy, AuthenticatedEndpoints, AwsSigner, GetEndpointAuth, PublicEndpoints, SecuritySchemeObject, TokenProvider, UsedSecuritySchemes, createAuthAwareFetcher } from "./auth-fetcher.cjs";
5
- import { FetchFn, TypedFetcher, createTypedFetcher } from "./fetcher.cjs";
6
- import { InferOpenApi, InferOpenApiFromEndpoint } from "./infer.cjs";
7
- export { ApiKeyProvider, AuthFetcherOptions, AuthStrategy, AuthenticatedEndpoints, AwsSigner, CALL_METHODS, CallMethod, ClientTelemetryOptions, EndpointString, ErrorTransformer, ExtractEndpointConfig, ExtractEndpointResponse, ExtractMethod, ExtractPathParams, ExtractQueryParams, ExtractRequestBody, ExtractResponse, FetchFn, FetcherOptions, FilterEndpointByMethod, FilteredRequestConfig, GetEndpointAuth, InferOpenApi, InferOpenApiFromEndpoint, InvalidClientSampleRate, IsConfigRequired, MethodCall, MethodCalls, MutationEndpoint, OpenAPIRoutes, ParseEndpoint, PublicEndpoints, QueryEndpoint, RequestConfig, RoutesFor, SecuritySchemeObject, TokenProvider, TraceContextInjector, TypedApiFunction, TypedEndpoint, TypedFetcher, UsedSecuritySchemes, ValidEndpoint, WrappedApiFunction, WrappedResult, createAuthAwareFetcher, createTypedFetcher, methodCalls, sampledAt, traceContextInjector };
package/dist/index.d.mts DELETED
@@ -1,7 +0,0 @@
1
- import { a as traceContextInjector, i as sampledAt, n as InvalidClientSampleRate, r as TraceContextInjector, t as ClientTelemetryOptions } from "./telemetry-g3BE86Wd.mjs";
2
- import { EndpointString, ErrorTransformer, ExtractEndpointConfig, ExtractEndpointResponse, ExtractMethod, ExtractPathParams, ExtractQueryParams, ExtractRequestBody, ExtractResponse, FetcherOptions, FilterEndpointByMethod, FilteredRequestConfig, IsConfigRequired, MutationEndpoint, OpenAPIRoutes, ParseEndpoint, QueryEndpoint, RequestConfig, TypedApiFunction, TypedEndpoint, ValidEndpoint, WrappedApiFunction, WrappedResult } from "./types.mjs";
3
- import { CALL_METHODS, CallMethod, MethodCall, MethodCalls, RoutesFor, methodCalls } from "./methods.mjs";
4
- import { ApiKeyProvider, AuthFetcherOptions, AuthStrategy, AuthenticatedEndpoints, AwsSigner, GetEndpointAuth, PublicEndpoints, SecuritySchemeObject, TokenProvider, UsedSecuritySchemes, createAuthAwareFetcher } from "./auth-fetcher.mjs";
5
- import { FetchFn, TypedFetcher, createTypedFetcher } from "./fetcher.mjs";
6
- import { InferOpenApi, InferOpenApiFromEndpoint } from "./infer.mjs";
7
- export { ApiKeyProvider, AuthFetcherOptions, AuthStrategy, AuthenticatedEndpoints, AwsSigner, CALL_METHODS, CallMethod, ClientTelemetryOptions, EndpointString, ErrorTransformer, ExtractEndpointConfig, ExtractEndpointResponse, ExtractMethod, ExtractPathParams, ExtractQueryParams, ExtractRequestBody, ExtractResponse, FetchFn, FetcherOptions, FilterEndpointByMethod, FilteredRequestConfig, GetEndpointAuth, InferOpenApi, InferOpenApiFromEndpoint, InvalidClientSampleRate, IsConfigRequired, MethodCall, MethodCalls, MutationEndpoint, OpenAPIRoutes, ParseEndpoint, PublicEndpoints, QueryEndpoint, RequestConfig, RoutesFor, SecuritySchemeObject, TokenProvider, TraceContextInjector, TypedApiFunction, TypedEndpoint, TypedFetcher, UsedSecuritySchemes, ValidEndpoint, WrappedApiFunction, WrappedResult, createAuthAwareFetcher, createTypedFetcher, methodCalls, sampledAt, traceContextInjector };
package/dist/index.mjs DELETED
@@ -1,7 +0,0 @@
1
- import { CALL_METHODS, methodCalls } from "./methods.mjs";
2
- import { InvalidClientSampleRate, sampledAt, traceContextInjector } from "./telemetry.mjs";
3
- import { TypedFetcher, createTypedFetcher } from "./fetcher.mjs";
4
- import { createAuthAwareFetcher } from "./auth-fetcher.mjs";
5
- import "./infer.mjs";
6
- import "./types.mjs";
7
- export { CALL_METHODS, InvalidClientSampleRate, TypedFetcher, createAuthAwareFetcher, createTypedFetcher, methodCalls, sampledAt, traceContextInjector };
package/dist/methods.cjs DELETED
@@ -1,21 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- //#region src/methods.ts
3
- /** The HTTP methods a client offers as calls: `api.get(…)`, `api.post(…)`. */
4
- const CALL_METHODS = [
5
- "get",
6
- "post",
7
- "put",
8
- "patch",
9
- "delete",
10
- "options"
11
- ];
12
- /** The method calls for a client, each delegating to `api('METHOD /route', …)`. */
13
- function methodCalls(fn) {
14
- const call = (method) => (route, config) => fn(`${method.toUpperCase()} ${route}`, config);
15
- return Object.fromEntries(CALL_METHODS.map((method) => [method, call(method)]));
16
- }
17
- //#endregion
18
- exports.CALL_METHODS = CALL_METHODS;
19
- exports.methodCalls = methodCalls;
20
-
21
- //# sourceMappingURL=methods.cjs.map