@geekmidas/client 9.0.2 → 10.0.0-alpha.1

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 (79) 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.map +1 -1
  36. package/dist/openapi-hooks.d.mts +1 -1
  37. package/dist/openapi-hooks.d.mts.map +1 -1
  38. package/dist/openapi-hooks.mjs.map +1 -1
  39. package/dist/react-query.d.mts +1 -1
  40. package/dist/types-BH8WgGrm.mjs +0 -0
  41. package/dist/{types-D8Jrl4o3.d.mts → types-BMGM6sZc.d.mts} +1 -1
  42. package/dist/{types-D8Jrl4o3.d.mts.map → types-BMGM6sZc.d.mts.map} +1 -1
  43. package/dist/types-a8gm_IaQ.cjs +0 -0
  44. package/dist/types.cjs +1 -0
  45. package/dist/types.d.mts +1 -1
  46. package/dist/types.mjs +1 -0
  47. package/package.json +8 -5
  48. package/CHANGELOG.md +0 -146
  49. package/dist/auth-fetcher.cjs.map +0 -1
  50. package/dist/auth-fetcher.d.cts.map +0 -1
  51. package/dist/auth-fetcher.d.mts.map +0 -1
  52. package/dist/auth-fetcher.mjs.map +0 -1
  53. package/dist/fetcher.d.cts.map +0 -1
  54. package/dist/fetcher.d.mts.map +0 -1
  55. package/dist/infer.d.cts.map +0 -1
  56. package/dist/infer.d.mts.map +0 -1
  57. package/src/__tests__/auth-fetcher.spec.ts +0 -505
  58. package/src/__tests__/endpoint-hooks.spec.tsx +0 -374
  59. package/src/__tests__/fetcher.spec.ts +0 -580
  60. package/src/__tests__/infer.integration.spec.ts +0 -188
  61. package/src/__tests__/infer.spec.ts +0 -189
  62. package/src/__tests__/method-restrictions.spec.tsx +0 -227
  63. package/src/__tests__/mutation-inference.spec.tsx +0 -343
  64. package/src/__tests__/openapi-hooks.spec.tsx +0 -557
  65. package/src/__tests__/react-query-infinite.spec.tsx +0 -1003
  66. package/src/__tests__/react-query-invalidation.spec.tsx +0 -239
  67. package/src/__tests__/react-query.spec.tsx +0 -582
  68. package/src/__tests__/setup.ts +0 -281
  69. package/src/__tests__/types.spec.ts +0 -134
  70. package/src/__tests__/url-parsing.spec.ts +0 -196
  71. package/src/auth-fetcher.ts +0 -288
  72. package/src/endpoint-hooks.ts +0 -346
  73. package/src/fetcher.ts +0 -171
  74. package/src/openapi-hooks.ts +0 -193
  75. package/src/openapi-types.d.ts +0 -440
  76. package/src/openapi.json +0 -595
  77. package/src/react-query.ts +0 -341
  78. package/src/types.ts +0 -226
  79. package/tsconfig.json +0 -12
@@ -1,343 +0,0 @@
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
- });