@geekmidas/client 9.0.2 → 10.0.0-alpha.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 (81) hide show
  1. package/dist/auth-fetcher-CBYuL6rx.d.cts +158 -0
  2. package/dist/auth-fetcher-CBYuL6rx.d.cts.map +1 -0
  3. package/dist/auth-fetcher-DOj0iz21.mjs +77 -0
  4. package/dist/auth-fetcher-DOj0iz21.mjs.map +1 -0
  5. package/dist/auth-fetcher-DxS8zOLc.d.mts +158 -0
  6. package/dist/auth-fetcher-DxS8zOLc.d.mts.map +1 -0
  7. package/dist/auth-fetcher-HILABmws.cjs +82 -0
  8. package/dist/auth-fetcher-HILABmws.cjs.map +1 -0
  9. package/dist/auth-fetcher.cjs +3 -76
  10. package/dist/auth-fetcher.d.cts +3 -158
  11. package/dist/auth-fetcher.d.mts +3 -158
  12. package/dist/auth-fetcher.mjs +3 -76
  13. package/dist/endpoint-hooks.d.mts +1 -1
  14. package/dist/fetcher-C1xtCKpT.d.mts +25 -0
  15. package/dist/fetcher-C1xtCKpT.d.mts.map +1 -0
  16. package/dist/fetcher-cDrfwN-Y.d.cts +25 -0
  17. package/dist/fetcher-cDrfwN-Y.d.cts.map +1 -0
  18. package/dist/fetcher.d.cts +3 -25
  19. package/dist/fetcher.d.mts +3 -25
  20. package/dist/index.cjs +8 -0
  21. package/dist/index.d.cts +5 -0
  22. package/dist/index.d.mts +5 -0
  23. package/dist/index.mjs +6 -0
  24. package/dist/infer-6KKCgmg1.cjs +0 -0
  25. package/{src/infer.ts → dist/infer-DfRq5kIb.d.cts} +54 -83
  26. package/dist/infer-DfRq5kIb.d.cts.map +1 -0
  27. package/dist/infer-bTirNeNW.d.mts +133 -0
  28. package/dist/infer-bTirNeNW.d.mts.map +1 -0
  29. package/dist/infer-uCUq1whM.mjs +0 -0
  30. package/dist/infer.cjs +1 -0
  31. package/dist/infer.d.cts +2 -133
  32. package/dist/infer.d.mts +2 -133
  33. package/dist/infer.mjs +1 -0
  34. package/dist/openapi-hooks.cjs.map +1 -1
  35. package/dist/openapi-hooks.d.cts +3 -3
  36. package/dist/openapi-hooks.d.cts.map +1 -1
  37. package/dist/openapi-hooks.d.mts +1 -1
  38. package/dist/openapi-hooks.d.mts.map +1 -1
  39. package/dist/openapi-hooks.mjs.map +1 -1
  40. package/dist/react-query.d.cts +7 -7
  41. package/dist/react-query.d.mts +1 -1
  42. package/dist/types-BH8WgGrm.mjs +0 -0
  43. package/dist/{types-D8Jrl4o3.d.mts → types-BMGM6sZc.d.mts} +1 -1
  44. package/dist/{types-D8Jrl4o3.d.mts.map → types-BMGM6sZc.d.mts.map} +1 -1
  45. package/dist/types-a8gm_IaQ.cjs +0 -0
  46. package/dist/types.cjs +1 -0
  47. package/dist/types.d.mts +1 -1
  48. package/dist/types.mjs +1 -0
  49. package/package.json +8 -5
  50. package/CHANGELOG.md +0 -146
  51. package/dist/auth-fetcher.cjs.map +0 -1
  52. package/dist/auth-fetcher.d.cts.map +0 -1
  53. package/dist/auth-fetcher.d.mts.map +0 -1
  54. package/dist/auth-fetcher.mjs.map +0 -1
  55. package/dist/fetcher.d.cts.map +0 -1
  56. package/dist/fetcher.d.mts.map +0 -1
  57. package/dist/infer.d.cts.map +0 -1
  58. package/dist/infer.d.mts.map +0 -1
  59. package/src/__tests__/auth-fetcher.spec.ts +0 -505
  60. package/src/__tests__/endpoint-hooks.spec.tsx +0 -374
  61. package/src/__tests__/fetcher.spec.ts +0 -580
  62. package/src/__tests__/infer.integration.spec.ts +0 -188
  63. package/src/__tests__/infer.spec.ts +0 -189
  64. package/src/__tests__/method-restrictions.spec.tsx +0 -227
  65. package/src/__tests__/mutation-inference.spec.tsx +0 -343
  66. package/src/__tests__/openapi-hooks.spec.tsx +0 -557
  67. package/src/__tests__/react-query-infinite.spec.tsx +0 -1003
  68. package/src/__tests__/react-query-invalidation.spec.tsx +0 -239
  69. package/src/__tests__/react-query.spec.tsx +0 -582
  70. package/src/__tests__/setup.ts +0 -281
  71. package/src/__tests__/types.spec.ts +0 -134
  72. package/src/__tests__/url-parsing.spec.ts +0 -196
  73. package/src/auth-fetcher.ts +0 -288
  74. package/src/endpoint-hooks.ts +0 -346
  75. package/src/fetcher.ts +0 -171
  76. package/src/openapi-hooks.ts +0 -193
  77. package/src/openapi-types.d.ts +0 -440
  78. package/src/openapi.json +0 -595
  79. package/src/react-query.ts +0 -341
  80. package/src/types.ts +0 -226
  81. package/tsconfig.json +0 -12
package/src/fetcher.ts DELETED
@@ -1,171 +0,0 @@
1
- import qs from 'qs';
2
- import type {
3
- EndpointString,
4
- ErrorTransformer,
5
- ExtractEndpointResponse,
6
- FetcherOptions,
7
- FilteredRequestConfig,
8
- ParseEndpoint,
9
- TypedEndpoint,
10
- WrappedResult,
11
- } from './types';
12
-
13
- export type { FetcherOptions, WrappedResult } from './types';
14
-
15
- export class TypedFetcher<Paths> {
16
- private baseURL: string;
17
- private defaultHeaders: Record<string, string>;
18
- private options: FetcherOptions;
19
- private fetchFn: FetchFn;
20
-
21
- static getFetchFn(fn?: FetchFn): FetchFn {
22
- if (fn) {
23
- return fn;
24
- }
25
-
26
- if (typeof window !== 'undefined' && typeof window.fetch === 'function') {
27
- return window.fetch.bind(window);
28
- }
29
-
30
- if (
31
- typeof globalThis !== 'undefined' &&
32
- typeof globalThis.fetch === 'function'
33
- ) {
34
- return globalThis.fetch.bind(globalThis);
35
- }
36
-
37
- throw new Error('No fetch implementation found');
38
- }
39
-
40
- constructor(options: FetcherOptions = {}) {
41
- this.baseURL = options.baseURL || '';
42
- this.defaultHeaders = options.headers || {};
43
- this.options = options;
44
- this.fetchFn = TypedFetcher.getFetchFn(options.fetch);
45
- }
46
-
47
- async request<T extends TypedEndpoint<Paths>>(
48
- endpoint: T,
49
- config?: FilteredRequestConfig<Paths, T>,
50
- ): Promise<ExtractEndpointResponse<Paths, T>> {
51
- const { method, route } = this.parseEndpoint(endpoint);
52
-
53
- // Replace path parameters
54
- let url = route;
55
- if (config && 'params' in config && config.params) {
56
- Object.entries(config.params as Record<string, unknown>).forEach(
57
- ([key, value]) => {
58
- url = url.replace(`{${key}}`, encodeURIComponent(String(value)));
59
- },
60
- );
61
- }
62
-
63
- // Add query parameters
64
- if (config && 'query' in config && config.query) {
65
- const queryString = qs.stringify(config.query, {
66
- encode: true,
67
- arrayFormat: 'brackets',
68
- skipNulls: true,
69
- });
70
- if (queryString) {
71
- url += `?${queryString}`;
72
- }
73
- }
74
-
75
- // Build request configuration
76
- let requestConfig: RequestInit = {
77
- method: method.toUpperCase(),
78
- headers: {
79
- ...this.defaultHeaders,
80
- ...((config && 'headers' in config && config.headers) || {}),
81
- },
82
- };
83
-
84
- // Add body if present
85
- if (config && 'body' in config && config.body) {
86
- requestConfig.body = JSON.stringify(config.body);
87
- requestConfig.headers = {
88
- ...requestConfig.headers,
89
- 'Content-Type': 'application/json',
90
- };
91
- }
92
-
93
- // Apply request interceptor
94
- if (this.options.onRequest) {
95
- requestConfig = await this.options.onRequest(requestConfig);
96
- }
97
-
98
- try {
99
- // Make the request
100
- let response = await this.fetchFn(`${this.baseURL}${url}`, requestConfig);
101
-
102
- // Apply response interceptor
103
- if (this.options.onResponse) {
104
- response = await this.options.onResponse(response);
105
- }
106
-
107
- // Handle errors
108
- if (!response.ok) {
109
- throw response;
110
- }
111
-
112
- // Handle empty responses (204 No Content, etc.)
113
- if (
114
- response.status === 204 ||
115
- response.headers.get('content-length') === '0'
116
- ) {
117
- return undefined as ExtractEndpointResponse<Paths, T>;
118
- }
119
-
120
- // Parse JSON response
121
- const data = await response.json();
122
- return data as ExtractEndpointResponse<Paths, T>;
123
- } catch (error) {
124
- // Apply error handler
125
- if (this.options.onError) {
126
- // @ts-expect-error
127
- await this.options.onError(error);
128
- }
129
- throw error;
130
- }
131
- }
132
-
133
- wrap<E = unknown>(onError?: ErrorTransformer<E>) {
134
- return <T extends TypedEndpoint<Paths>>(
135
- endpoint: T,
136
- config?: FilteredRequestConfig<Paths, T>,
137
- ): Promise<WrappedResult<ExtractEndpointResponse<Paths, T>, E>> =>
138
- this.request(endpoint, config).then(
139
- (data) => ({ ok: true as const, data }),
140
- async (error) => ({
141
- ok: false as const,
142
- error: onError ? await onError(error) : (error as E),
143
- }),
144
- );
145
- }
146
-
147
- private parseEndpoint<T extends EndpointString>(
148
- endpoint: T,
149
- ): ParseEndpoint<T> {
150
- const [method, ...routeParts] = endpoint.split(' ');
151
- const route = routeParts.join(' ');
152
- return { method: method?.toLowerCase() ?? '', route } as ParseEndpoint<T>;
153
- }
154
- }
155
-
156
- export function createTypedFetcher<Paths>(options?: FetcherOptions) {
157
- const fetcher = new TypedFetcher<Paths>(options);
158
- const fn = <T extends TypedEndpoint<Paths>>(
159
- endpoint: T,
160
- config?: FilteredRequestConfig<Paths, T>,
161
- ) => fetcher.request(endpoint, config);
162
-
163
- return Object.assign(fn, {
164
- wrap: <E = unknown>(onError?: ErrorTransformer<E>) =>
165
- Object.assign(fetcher.wrap(onError), fn, {
166
- wrap: undefined,
167
- }),
168
- });
169
- }
170
-
171
- export type FetchFn = typeof fetch;
@@ -1,193 +0,0 @@
1
- import type {
2
- UseMutationOptions,
3
- UseQueryOptions,
4
- } from '@tanstack/react-query';
5
- import { useMutation, useQuery } from '@tanstack/react-query';
6
- import { createTypedFetcher } from './fetcher';
7
- import type { FetcherOptions } from './types';
8
-
9
- // Simplified type helpers for OpenAPI paths
10
- type HttpMethods = 'get' | 'post' | 'put' | 'patch' | 'delete';
11
-
12
- // Extract all operations from paths
13
- type AllOperations<Paths> = {
14
- [Path in keyof Paths]: {
15
- [Method in keyof Paths[Path] & HttpMethods]: Paths[Path][Method] extends {
16
- operationId: infer OpId;
17
- }
18
- ? OpId extends string
19
- ? {
20
- operationId: OpId;
21
- path: Path;
22
- method: Method;
23
- spec: Paths[Path][Method] & {
24
- _pathParams?: Paths[Path] extends {
25
- parameters: { path: infer P };
26
- }
27
- ? P
28
- : never;
29
- };
30
- }
31
- : never
32
- : never;
33
- }[keyof Paths[Path] & HttpMethods];
34
- }[keyof Paths];
35
-
36
- // Create operation map
37
- type OperationMap<Paths> = {
38
- [Op in AllOperations<Paths> as Op extends {
39
- operationId: infer Id extends string;
40
- }
41
- ? Id
42
- : never]: Op;
43
- };
44
-
45
- // Get operation IDs
46
- type OperationId<Paths> = keyof OperationMap<Paths>;
47
-
48
- // Get operations by method
49
- type OperationsByMethod<Paths, Method extends HttpMethods> = {
50
- [K in OperationId<Paths>]: OperationMap<Paths>[K] extends { method: Method }
51
- ? K
52
- : never;
53
- }[OperationId<Paths>];
54
-
55
- // Extract parameter types
56
- type OperationParams<
57
- Paths,
58
- OpId extends OperationId<Paths>,
59
- > = OperationMap<Paths>[OpId] extends {
60
- path: infer Path extends keyof Paths;
61
- spec: infer Spec;
62
- }
63
- ? {
64
- params?: Paths[Path] extends { parameters: { path: infer P } }
65
- ? P
66
- : Spec extends { parameters: { path: infer P } }
67
- ? P
68
- : never;
69
- query?: Spec extends { parameters?: { query?: infer Q } } ? Q : never;
70
- body?: Spec extends {
71
- requestBody: { content: { 'application/json': infer Body } };
72
- }
73
- ? Body
74
- : Spec extends {
75
- requestBody: {
76
- required: true;
77
- content: { 'application/json': infer Body };
78
- };
79
- }
80
- ? Body
81
- : never;
82
- }
83
- : never;
84
-
85
- // Extract response type
86
- type OperationResponse<
87
- Paths,
88
- OpId extends OperationId<Paths>,
89
- > = OperationMap<Paths>[OpId] extends { spec: infer Spec }
90
- ? Spec extends {
91
- responses: { 200: { content: { 'application/json': infer R } } };
92
- }
93
- ? R
94
- : Spec extends {
95
- responses: { 201: { content: { 'application/json': infer R } } };
96
- }
97
- ? R
98
- : Spec extends { responses: { 204: any } }
99
- ? undefined
100
- : unknown
101
- : never;
102
-
103
- // Remove never properties
104
- type RemoveNever<T> = Pick<
105
- T,
106
- {
107
- [K in keyof T]: T[K] extends never ? never : K;
108
- }[keyof T]
109
- >;
110
-
111
- // Check if type is empty
112
- type IsEmpty<T> = keyof T extends never ? true : false;
113
-
114
- // Runtime operation registry (would be generated)
115
- interface OperationRegistry {
116
- [operationId: string]: {
117
- path: string;
118
- method: string;
119
- };
120
- }
121
-
122
- export function createOpenAPIHooks<Paths>(
123
- options: FetcherOptions & { operations?: OperationRegistry } = {},
124
- ) {
125
- const { operations, ...fetcherOptions } = options;
126
- const fetcher = createTypedFetcher<Paths>(fetcherOptions);
127
-
128
- function buildEndpoint<OpId extends OperationId<Paths>>(
129
- operationId: OpId,
130
- ): string {
131
- // Runtime lookup from registry
132
- const op = operations?.[operationId as string];
133
- if (op) {
134
- return `${op.method.toUpperCase()} ${op.path}`;
135
- }
136
- // Fallback for compile-time only usage
137
- return operationId as string;
138
- }
139
-
140
- return {
141
- useQuery: <OpId extends OperationsByMethod<Paths, 'get'>>(
142
- operationId: OpId,
143
- config?: RemoveNever<OperationParams<Paths, OpId>>,
144
- options?: Omit<
145
- UseQueryOptions<OperationResponse<Paths, OpId>, Error>,
146
- 'queryKey' | 'queryFn'
147
- >,
148
- ) => {
149
- const endpoint = buildEndpoint(operationId);
150
- const queryKey = [operationId, ...(config ? [config] : [])];
151
-
152
- return useQuery<OperationResponse<Paths, OpId>, Error>({
153
- queryKey,
154
- queryFn: async () => {
155
- const response = await fetcher(endpoint as any, config as any);
156
- return response as OperationResponse<Paths, OpId>;
157
- },
158
- ...options,
159
- });
160
- },
161
-
162
- useMutation: <
163
- OpId extends Exclude<
164
- OperationId<Paths>,
165
- OperationsByMethod<Paths, 'get'>
166
- >,
167
- >(
168
- operationId: OpId,
169
- options?: Omit<
170
- UseMutationOptions<
171
- OperationResponse<Paths, OpId>,
172
- Error,
173
- RemoveNever<OperationParams<Paths, OpId>>
174
- >,
175
- 'mutationFn'
176
- >,
177
- ) => {
178
- const endpoint = buildEndpoint(operationId);
179
-
180
- return useMutation<
181
- OperationResponse<Paths, OpId>,
182
- Error,
183
- RemoveNever<OperationParams<Paths, OpId>>
184
- >({
185
- mutationFn: async (variables) => {
186
- const response = await fetcher(endpoint as any, variables as any);
187
- return response as OperationResponse<Paths, OpId>;
188
- },
189
- ...options,
190
- });
191
- },
192
- };
193
- }