@geekmidas/client 10.0.0-alpha.98 → 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,343 @@
1
+ /**
2
+ * @vitest-environment jsdom
3
+ *
4
+ * Type inference test for mutation hooks with complex paths.
5
+ * This mirrors the structure generated by `gkm openapi` to verify
6
+ * that FilteredRequestConfig resolves correctly (not `never`).
7
+ */
8
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
9
+ import { renderHook, waitFor } from '@testing-library/react';
10
+ import { HttpResponse, http } from 'msw';
11
+ // biome-ignore lint/style/useImportType: needed for JSX
12
+ import React, { createElement } from 'react';
13
+ import { beforeEach, describe, expect, it } from 'vitest';
14
+ import { createEndpointHooks } from '../endpoint-hooks';
15
+ import type { TypedApiFunction } from '../types';
16
+ import { server } from './setup';
17
+
18
+ // ============================================================
19
+ // Paths that mirror a real generated openapi.ts structure
20
+ // ============================================================
21
+ interface GeneratedPaths {
22
+ '/account/profile': {
23
+ post: {
24
+ requestBody: {
25
+ content: {
26
+ 'application/json': { email: string; name: string };
27
+ };
28
+ };
29
+ responses: {
30
+ 200: {
31
+ content: {
32
+ 'application/json': Record<string, unknown>;
33
+ };
34
+ };
35
+ };
36
+ };
37
+ get: {
38
+ responses: {
39
+ 200: {
40
+ content: {
41
+ 'application/json': {
42
+ id: string;
43
+ email: string;
44
+ name: string;
45
+ } | null;
46
+ };
47
+ };
48
+ };
49
+ };
50
+ };
51
+ '/chats/{chatId}/participants': {
52
+ parameters: {
53
+ path: { chatId: string };
54
+ };
55
+ post: {
56
+ requestBody: {
57
+ content: {
58
+ 'application/json': { userId: string; role: 'Owner' | 'Member' };
59
+ };
60
+ };
61
+ responses: {
62
+ 200: {
63
+ content: {
64
+ 'application/json': {
65
+ id: string;
66
+ chatId: string;
67
+ userId: string;
68
+ role: string;
69
+ };
70
+ };
71
+ };
72
+ };
73
+ };
74
+ };
75
+ '/chats': {
76
+ post: {
77
+ requestBody: {
78
+ content: {
79
+ 'application/json': { type: string; name?: string };
80
+ };
81
+ };
82
+ responses: {
83
+ 200: {
84
+ content: {
85
+ 'application/json': { id: string; type: string; name: string };
86
+ };
87
+ };
88
+ };
89
+ };
90
+ get: {
91
+ parameters: {
92
+ query: { cursor?: string; limit: number };
93
+ };
94
+ responses: {
95
+ 200: {
96
+ content: {
97
+ 'application/json': {
98
+ data: Array<{ id: string; name: string }>;
99
+ hasMore: boolean;
100
+ };
101
+ };
102
+ };
103
+ };
104
+ };
105
+ };
106
+ '/chats/{id}': {
107
+ parameters: {
108
+ path: { id: string };
109
+ };
110
+ delete: {
111
+ responses: {
112
+ 200: {
113
+ content: {
114
+ 'application/json': { success: boolean };
115
+ };
116
+ };
117
+ };
118
+ };
119
+ get: {
120
+ responses: {
121
+ 200: {
122
+ content: {
123
+ 'application/json': { id: string; name: string };
124
+ };
125
+ };
126
+ };
127
+ };
128
+ patch: {
129
+ requestBody: {
130
+ content: {
131
+ 'application/json': { name?: string; status?: string };
132
+ };
133
+ };
134
+ responses: {
135
+ 200: {
136
+ content: {
137
+ 'application/json': { id: string; name: string; status: string };
138
+ };
139
+ };
140
+ };
141
+ };
142
+ };
143
+ '/chats/{chatId}/leave': {
144
+ parameters: {
145
+ path: { chatId: string };
146
+ };
147
+ post: {
148
+ responses: {
149
+ 200: {
150
+ content: {
151
+ 'application/json': { success: boolean };
152
+ };
153
+ };
154
+ };
155
+ };
156
+ };
157
+ }
158
+
159
+ // ============================================================
160
+ // Mock fetcher
161
+ // ============================================================
162
+ function createMockFetcher(): TypedApiFunction<GeneratedPaths> {
163
+ return async (endpoint: string, config?: any) => {
164
+ const [method, path] = endpoint.split(' ');
165
+ let url = `https://api.example.com${path}`;
166
+
167
+ if (config?.params) {
168
+ for (const [key, value] of Object.entries(config.params)) {
169
+ url = url.replace(`{${key}}`, value as string);
170
+ }
171
+ }
172
+
173
+ const response = await fetch(url, {
174
+ method,
175
+ headers: { 'Content-Type': 'application/json', ...config?.headers },
176
+ body: config?.body ? JSON.stringify(config.body) : undefined,
177
+ });
178
+
179
+ return response.json();
180
+ };
181
+ }
182
+
183
+ function createWrapper() {
184
+ const queryClient = new QueryClient({
185
+ defaultOptions: { queries: { retry: false } },
186
+ });
187
+ return ({ children }: { children: React.ReactNode }) =>
188
+ createElement(QueryClientProvider, { client: queryClient }, children);
189
+ }
190
+
191
+ // ============================================================
192
+ // Tests
193
+ // ============================================================
194
+ describe('mutation type inference with generated paths', () => {
195
+ beforeEach(() => {
196
+ server.use(
197
+ http.post(
198
+ 'https://api.example.com/account/profile',
199
+ async ({ request }) => {
200
+ const body = (await request.json()) as any;
201
+ return HttpResponse.json({ id: '1', ...body });
202
+ },
203
+ ),
204
+ http.post('https://api.example.com/chats', async ({ request }) => {
205
+ const body = (await request.json()) as any;
206
+ return HttpResponse.json({
207
+ id: 'chat-1',
208
+ type: body.type,
209
+ name: body.name ?? 'New Chat',
210
+ });
211
+ }),
212
+ http.post(
213
+ 'https://api.example.com/chats/:chatId/participants',
214
+ async ({ params, request }) => {
215
+ const body = (await request.json()) as any;
216
+ return HttpResponse.json({
217
+ id: 'p-1',
218
+ chatId: params.chatId,
219
+ userId: body.userId,
220
+ role: body.role,
221
+ });
222
+ },
223
+ ),
224
+ http.delete('https://api.example.com/chats/:id', () => {
225
+ return HttpResponse.json({ success: true });
226
+ }),
227
+ http.patch(
228
+ 'https://api.example.com/chats/:id',
229
+ async ({ params, request }) => {
230
+ const body = (await request.json()) as any;
231
+ return HttpResponse.json({
232
+ id: params.id,
233
+ name: body.name ?? 'Chat',
234
+ status: body.status ?? 'Active',
235
+ });
236
+ },
237
+ ),
238
+ http.post('https://api.example.com/chats/:chatId/leave', () => {
239
+ return HttpResponse.json({ success: true });
240
+ }),
241
+ );
242
+ });
243
+
244
+ it('should resolve body-only mutation args (POST /chats)', async () => {
245
+ const hooks = createEndpointHooks<GeneratedPaths>(createMockFetcher());
246
+ const { result } = renderHook(() => hooks.useMutation('POST /chats'), {
247
+ wrapper: createWrapper(),
248
+ });
249
+
250
+ // If args were `never`, this call would be a type error
251
+ result.current.mutate({ body: { type: 'GeneralChat', name: 'Test' } });
252
+
253
+ await waitFor(() => expect(result.current.isSuccess).toBe(true));
254
+ expect(result.current.data).toMatchObject({
255
+ id: 'chat-1',
256
+ type: 'GeneralChat',
257
+ });
258
+ });
259
+
260
+ it('should resolve body-only mutation args (POST /account/profile)', async () => {
261
+ const hooks = createEndpointHooks<GeneratedPaths>(createMockFetcher());
262
+ const { result } = renderHook(
263
+ () => hooks.useMutation('POST /account/profile'),
264
+ {
265
+ wrapper: createWrapper(),
266
+ },
267
+ );
268
+
269
+ result.current.mutate({ body: { email: 'test@test.com', name: 'Test' } });
270
+
271
+ await waitFor(() => expect(result.current.isSuccess).toBe(true));
272
+ expect(result.current.data).toMatchObject({ email: 'test@test.com' });
273
+ });
274
+
275
+ it('should resolve params+body mutation args (POST /chats/{chatId}/participants)', async () => {
276
+ const hooks = createEndpointHooks<GeneratedPaths>(createMockFetcher());
277
+ const { result } = renderHook(
278
+ () => hooks.useMutation('POST /chats/{chatId}/participants'),
279
+ { wrapper: createWrapper() },
280
+ );
281
+
282
+ result.current.mutate({
283
+ params: { chatId: 'chat-1' },
284
+ body: { userId: 'user-1', role: 'Member' },
285
+ });
286
+
287
+ await waitFor(() => expect(result.current.isSuccess).toBe(true));
288
+ expect(result.current.data).toMatchObject({
289
+ chatId: 'chat-1',
290
+ userId: 'user-1',
291
+ });
292
+ });
293
+
294
+ it('should resolve params-only mutation args (DELETE /chats/{id})', async () => {
295
+ const hooks = createEndpointHooks<GeneratedPaths>(createMockFetcher());
296
+ const { result } = renderHook(
297
+ () => hooks.useMutation('DELETE /chats/{id}'),
298
+ {
299
+ wrapper: createWrapper(),
300
+ },
301
+ );
302
+
303
+ result.current.mutate({ params: { id: 'chat-1' } });
304
+
305
+ await waitFor(() => expect(result.current.isSuccess).toBe(true));
306
+ expect(result.current.data).toEqual({ success: true });
307
+ });
308
+
309
+ it('should resolve params+body mutation args (PATCH /chats/{id})', async () => {
310
+ const hooks = createEndpointHooks<GeneratedPaths>(createMockFetcher());
311
+ const { result } = renderHook(
312
+ () => hooks.useMutation('PATCH /chats/{id}'),
313
+ {
314
+ wrapper: createWrapper(),
315
+ },
316
+ );
317
+
318
+ result.current.mutate({
319
+ params: { id: 'chat-1' },
320
+ body: { name: 'Renamed Chat' },
321
+ });
322
+
323
+ await waitFor(() => expect(result.current.isSuccess).toBe(true));
324
+ expect(result.current.data).toMatchObject({
325
+ id: 'chat-1',
326
+ name: 'Renamed Chat',
327
+ });
328
+ });
329
+
330
+ it('should resolve params-only POST mutation args (POST /chats/{chatId}/leave)', async () => {
331
+ const hooks = createEndpointHooks<GeneratedPaths>(createMockFetcher());
332
+ const { result } = renderHook(
333
+ () => hooks.useMutation('POST /chats/{chatId}/leave'),
334
+ { wrapper: createWrapper() },
335
+ );
336
+
337
+ // POST with only path params, no body
338
+ result.current.mutate({ params: { chatId: 'chat-1' } });
339
+
340
+ await waitFor(() => expect(result.current.isSuccess).toBe(true));
341
+ expect(result.current.data).toEqual({ success: true });
342
+ });
343
+ });