@geekmidas/client 0.4.0 → 1.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 (72) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/auth-fetcher.cjs +0 -1
  3. package/dist/auth-fetcher.cjs.map +1 -1
  4. package/dist/auth-fetcher.d.cts +1 -1
  5. package/dist/auth-fetcher.d.cts.map +1 -1
  6. package/dist/auth-fetcher.d.mts +1 -1
  7. package/dist/auth-fetcher.d.mts.map +1 -1
  8. package/dist/auth-fetcher.mjs +0 -1
  9. package/dist/auth-fetcher.mjs.map +1 -1
  10. package/dist/endpoint-hooks.cjs +10 -5
  11. package/dist/endpoint-hooks.cjs.map +1 -1
  12. package/dist/endpoint-hooks.d.cts +2 -2
  13. package/dist/endpoint-hooks.d.cts.map +1 -1
  14. package/dist/endpoint-hooks.d.mts +2 -2
  15. package/dist/endpoint-hooks.d.mts.map +1 -1
  16. package/dist/endpoint-hooks.mjs +10 -5
  17. package/dist/endpoint-hooks.mjs.map +1 -1
  18. package/dist/fetcher-5fnBE7Dk.mjs.map +1 -1
  19. package/dist/fetcher-CgLEaIAC.cjs.map +1 -1
  20. package/dist/fetcher.d.cts +1 -1
  21. package/dist/fetcher.d.cts.map +1 -1
  22. package/dist/fetcher.d.mts +1 -1
  23. package/dist/fetcher.d.mts.map +1 -1
  24. package/dist/infer.d.cts.map +1 -1
  25. package/dist/infer.d.mts.map +1 -1
  26. package/dist/openapi-hooks.cjs.map +1 -1
  27. package/dist/openapi-hooks.d.cts +2 -2
  28. package/dist/openapi-hooks.d.cts.map +1 -1
  29. package/dist/openapi-hooks.d.mts +5 -5
  30. package/dist/openapi-hooks.d.mts.map +1 -1
  31. package/dist/openapi-hooks.mjs.map +1 -1
  32. package/dist/openapi-types.d.cts.map +1 -1
  33. package/dist/openapi-types.d.mts.map +1 -1
  34. package/dist/openapi.cjs.map +1 -1
  35. package/dist/openapi.mjs.map +1 -1
  36. package/dist/react-query.cjs.map +1 -1
  37. package/dist/react-query.d.cts +1 -1
  38. package/dist/react-query.d.cts.map +1 -1
  39. package/dist/react-query.d.mts +8 -8
  40. package/dist/react-query.d.mts.map +1 -1
  41. package/dist/react-query.mjs.map +1 -1
  42. package/dist/{types-FxummKaL.d.mts → types-4K4N-Fl1.d.cts} +2 -2
  43. package/dist/types-4K4N-Fl1.d.cts.map +1 -0
  44. package/dist/{types-vutATyWv.d.cts → types-hhkZWjQn.d.mts} +2 -2
  45. package/dist/types-hhkZWjQn.d.mts.map +1 -0
  46. package/dist/types.d.cts +1 -1
  47. package/dist/types.d.mts +1 -1
  48. package/package.json +5 -5
  49. package/src/__tests__/auth-fetcher.spec.ts +476 -476
  50. package/src/__tests__/endpoint-hooks.spec.tsx +348 -348
  51. package/src/__tests__/fetcher.spec.ts +403 -403
  52. package/src/__tests__/infer.integration.spec.ts +171 -171
  53. package/src/__tests__/infer.spec.ts +182 -182
  54. package/src/__tests__/method-restrictions.spec.tsx +165 -165
  55. package/src/__tests__/openapi-hooks.spec.tsx +536 -536
  56. package/src/__tests__/react-query-infinite.spec.tsx +989 -989
  57. package/src/__tests__/react-query-invalidation.spec.tsx +223 -222
  58. package/src/__tests__/react-query.spec.tsx +567 -567
  59. package/src/__tests__/setup.ts +260 -260
  60. package/src/__tests__/types.spec.ts +127 -127
  61. package/src/__tests__/url-parsing.spec.ts +191 -191
  62. package/src/auth-fetcher.ts +160 -162
  63. package/src/endpoint-hooks.ts +151 -156
  64. package/src/fetcher.ts +163 -163
  65. package/src/infer.ts +64 -63
  66. package/src/openapi-hooks.ts +146 -146
  67. package/src/openapi-types.d.ts +428 -428
  68. package/src/openapi.json +593 -593
  69. package/src/react-query.ts +281 -281
  70. package/src/types.ts +121 -124
  71. package/dist/types-FxummKaL.d.mts.map +0 -1
  72. package/dist/types-vutATyWv.d.cts.map +0 -1
@@ -1,6 +1,6 @@
1
1
  import type {
2
- UseMutationOptions,
3
- UseQueryOptions,
2
+ UseMutationOptions,
3
+ UseQueryOptions,
4
4
  } from '@tanstack/react-query';
5
5
  import { useMutation, useQuery } from '@tanstack/react-query';
6
6
  import { createTypedFetcher } from './fetcher';
@@ -11,35 +11,35 @@ type HttpMethods = 'get' | 'post' | 'put' | 'patch' | 'delete';
11
11
 
12
12
  // Extract all operations from paths
13
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];
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
34
  }[keyof Paths];
35
35
 
36
36
  // Create operation map
37
37
  type OperationMap<Paths> = {
38
- [Op in AllOperations<Paths> as Op extends {
39
- operationId: infer Id extends string;
40
- }
41
- ? Id
42
- : never]: Op;
38
+ [Op in AllOperations<Paths> as Op extends {
39
+ operationId: infer Id extends string;
40
+ }
41
+ ? Id
42
+ : never]: Op;
43
43
  };
44
44
 
45
45
  // Get operation IDs
@@ -47,65 +47,65 @@ type OperationId<Paths> = keyof OperationMap<Paths>;
47
47
 
48
48
  // Get operations by method
49
49
  type OperationsByMethod<Paths, Method extends HttpMethods> = {
50
- [K in OperationId<Paths>]: OperationMap<Paths>[K] extends { method: Method }
51
- ? K
52
- : never;
50
+ [K in OperationId<Paths>]: OperationMap<Paths>[K] extends { method: Method }
51
+ ? K
52
+ : never;
53
53
  }[OperationId<Paths>];
54
54
 
55
55
  // Extract parameter types
56
56
  type OperationParams<
57
- Paths,
58
- OpId extends OperationId<Paths>,
57
+ Paths,
58
+ OpId extends OperationId<Paths>,
59
59
  > = OperationMap<Paths>[OpId] extends {
60
- path: infer Path extends keyof Paths;
61
- spec: infer Spec;
60
+ path: infer Path extends keyof Paths;
61
+ spec: infer Spec;
62
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;
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
84
 
85
85
  // Extract response type
86
86
  type OperationResponse<
87
- Paths,
88
- OpId extends OperationId<Paths>,
87
+ Paths,
88
+ OpId extends OperationId<Paths>,
89
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
- ? void
100
- : unknown
101
- : never;
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
102
 
103
103
  // Remove never properties
104
104
  type RemoveNever<T> = Pick<
105
- T,
106
- {
107
- [K in keyof T]: T[K] extends never ? never : K;
108
- }[keyof T]
105
+ T,
106
+ {
107
+ [K in keyof T]: T[K] extends never ? never : K;
108
+ }[keyof T]
109
109
  >;
110
110
 
111
111
  // Check if type is empty
@@ -113,81 +113,81 @@ type IsEmpty<T> = keyof T extends never ? true : false;
113
113
 
114
114
  // Runtime operation registry (would be generated)
115
115
  interface OperationRegistry {
116
- [operationId: string]: {
117
- path: string;
118
- method: string;
119
- };
116
+ [operationId: string]: {
117
+ path: string;
118
+ method: string;
119
+ };
120
120
  }
121
121
 
122
122
  export function createOpenAPIHooks<Paths>(
123
- options: FetcherOptions & { operations?: OperationRegistry } = {},
123
+ options: FetcherOptions & { operations?: OperationRegistry } = {},
124
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
- };
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
193
  }