@geekmidas/client 9.0.1 → 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 -124
  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
@@ -1,239 +0,0 @@
1
- /**
2
- * @vitest-environment jsdom
3
- */
4
- import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
5
- import { renderHook, waitFor } from '@testing-library/react';
6
- // biome-ignore lint/style/useImportType: <explanation>
7
- import React from 'react';
8
- import { beforeEach, describe, expect, it, vi } from 'vitest';
9
- import type { paths } from '../openapi-types';
10
- import { TypedQueryClient, useTypedInvalidateQueries } from '../react-query';
11
-
12
- // Mock the fetcher module
13
- vi.mock('../fetcher', () => ({
14
- createTypedFetcher: () => vi.fn(),
15
- }));
16
-
17
- describe('TypedQueryClient - Query Invalidation', () => {
18
- let queryClient: QueryClient;
19
- let typedClient: TypedQueryClient<paths>;
20
-
21
- beforeEach(() => {
22
- queryClient = new QueryClient({
23
- defaultOptions: {
24
- queries: { retry: false },
25
- },
26
- });
27
- typedClient = new TypedQueryClient({ queryClient });
28
- });
29
-
30
- describe('buildQueryKey', () => {
31
- it('should build query key with endpoint only', () => {
32
- const key = typedClient.buildQueryKey('GET /users');
33
- expect(key).toEqual(['GET /users']);
34
- });
35
-
36
- it('should build query key with params', () => {
37
- const key = typedClient.buildQueryKey('GET /users/{id}', {
38
- params: { id: '123' },
39
- });
40
- expect(key).toEqual(['GET /users/{id}', { params: { id: '123' } }]);
41
- });
42
-
43
- it('should build query key with query params', () => {
44
- const key = typedClient.buildQueryKey('GET /users', {
45
- query: { page: 1, limit: 10 },
46
- });
47
- expect(key).toEqual(['GET /users', { query: { page: 1, limit: 10 } }]);
48
- });
49
-
50
- it('should build query key with params only for paths without query support', () => {
51
- const key = typedClient.buildQueryKey('GET /users/{id}', {
52
- params: { id: '123' },
53
- });
54
- expect(key).toEqual(['GET /users/{id}', { params: { id: '123' } }]);
55
- });
56
- });
57
-
58
- describe('invalidateQueries', () => {
59
- it('should invalidate queries with endpoint only (partial match)', async () => {
60
- const invalidateSpy = vi.spyOn(queryClient, 'invalidateQueries');
61
-
62
- await typedClient.invalidateQueries('GET /users');
63
-
64
- expect(invalidateSpy).toHaveBeenCalledWith({
65
- queryKey: ['GET /users'],
66
- exact: false,
67
- });
68
- });
69
-
70
- it('should invalidate queries with config (exact match)', async () => {
71
- const invalidateSpy = vi.spyOn(queryClient, 'invalidateQueries');
72
-
73
- await typedClient.invalidateQueries('GET /users/{id}', {
74
- params: { id: '123' },
75
- });
76
-
77
- expect(invalidateSpy).toHaveBeenCalledWith({
78
- queryKey: ['GET /users/{id}', { params: { id: '123' } }],
79
- exact: true,
80
- });
81
- });
82
-
83
- it('should invalidate queries with query params', async () => {
84
- const invalidateSpy = vi.spyOn(queryClient, 'invalidateQueries');
85
-
86
- await typedClient.invalidateQueries('GET /posts', {
87
- query: { sort: 'asc' },
88
- });
89
-
90
- expect(invalidateSpy).toHaveBeenCalledWith({
91
- queryKey: ['GET /posts', { query: { sort: 'asc' } }],
92
- exact: true,
93
- });
94
- });
95
- });
96
-
97
- describe('invalidateAllQueries', () => {
98
- it('should invalidate all queries', async () => {
99
- const invalidateSpy = vi.spyOn(queryClient, 'invalidateQueries');
100
-
101
- await typedClient.invalidateAllQueries();
102
-
103
- expect(invalidateSpy).toHaveBeenCalledWith();
104
- });
105
- });
106
-
107
- describe('getQueryClient / setQueryClient', () => {
108
- it('should return the query client when provided in constructor', () => {
109
- const client = typedClient.getQueryClient();
110
- expect(client).toBe(queryClient);
111
- });
112
-
113
- it('should throw error when no query client is set', () => {
114
- const clientWithoutQC = new TypedQueryClient();
115
-
116
- expect(() => clientWithoutQC.getQueryClient()).toThrow(
117
- 'No QueryClient set, please provide a QueryClient via the queryClient option or ensure you are within a QueryClientProvider',
118
- );
119
- });
120
-
121
- it('should allow setting query client after construction', () => {
122
- const clientWithoutQC = new TypedQueryClient();
123
- const newQueryClient = new QueryClient();
124
-
125
- clientWithoutQC.setQueryClient(newQueryClient);
126
-
127
- expect(clientWithoutQC.getQueryClient()).toBe(newQueryClient);
128
- });
129
- });
130
-
131
- describe('useTypedInvalidateQueries hook', () => {
132
- const wrapper = ({ children }: { children: React.ReactNode }) => (
133
- <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
134
- );
135
-
136
- it('should provide invalidateQueries function', async () => {
137
- const { result } = renderHook(
138
- () => useTypedInvalidateQueries(typedClient),
139
- { wrapper },
140
- );
141
-
142
- const invalidateSpy = vi.spyOn(queryClient, 'invalidateQueries');
143
-
144
- await result.current.invalidateQueries('GET /users/{id}', {
145
- params: { id: '456' },
146
- });
147
-
148
- expect(invalidateSpy).toHaveBeenCalledWith({
149
- queryKey: ['GET /users/{id}', { params: { id: '456' } }],
150
- exact: true,
151
- });
152
- });
153
-
154
- it('should provide invalidateAllQueries function', async () => {
155
- const { result } = renderHook(
156
- () => useTypedInvalidateQueries(typedClient),
157
- { wrapper },
158
- );
159
-
160
- const invalidateSpy = vi.spyOn(queryClient, 'invalidateQueries');
161
-
162
- await result.current.invalidateAllQueries();
163
-
164
- expect(invalidateSpy).toHaveBeenCalledWith();
165
- });
166
- });
167
-
168
- describe('Integration test: Query invalidation with real queries', () => {
169
- it('should invalidate matching queries after mutation', async () => {
170
- // Set up some queries in the cache
171
- queryClient.setQueryData(
172
- ['GET /users'],
173
- [
174
- { id: '1', name: 'User 1' },
175
- { id: '2', name: 'User 2' },
176
- ],
177
- );
178
- queryClient.setQueryData(['GET /users/{id}', { params: { id: '1' } }], {
179
- id: '1',
180
- name: 'User 1',
181
- });
182
- queryClient.setQueryData(
183
- ['GET /users', { query: { page: 1 } }],
184
- [{ id: '1', name: 'User 1' }],
185
- );
186
-
187
- // Verify data is in cache
188
- expect(queryClient.getQueryData(['GET /users'])).toBeDefined();
189
- expect(
190
- queryClient.getQueryData(['GET /users/{id}', { params: { id: '1' } }]),
191
- ).toBeDefined();
192
- expect(
193
- queryClient.getQueryData(['GET /users', { query: { page: 1 } }]),
194
- ).toBeDefined();
195
-
196
- // Invalidate all user queries (partial match)
197
- await typedClient.invalidateQueries('GET /users');
198
-
199
- // All queries starting with 'GET /users' should be invalidated
200
- await waitFor(() => {
201
- const cache = queryClient.getQueryCache();
202
- const queries = cache.findAll({ queryKey: ['GET /users'] });
203
- queries.forEach((query) => {
204
- expect(query.state.isInvalidated).toBe(true);
205
- });
206
- });
207
- });
208
-
209
- it('should only invalidate exact matches when config is provided', async () => {
210
- // Set up queries
211
- queryClient.setQueryData(
212
- ['GET /users', { query: { page: 1 } }],
213
- [{ id: '1', name: 'User 1' }],
214
- );
215
- queryClient.setQueryData(
216
- ['GET /users', { query: { page: 2 } }],
217
- [{ id: '2', name: 'User 2' }],
218
- );
219
-
220
- // Invalidate only page 1
221
- await typedClient.invalidateQueries('GET /users', {
222
- query: { page: 1 },
223
- });
224
-
225
- await waitFor(() => {
226
- const cache = queryClient.getQueryCache();
227
- const page1Query = cache.find({
228
- queryKey: ['GET /users', { query: { page: 1 } }],
229
- });
230
- const page2Query = cache.find({
231
- queryKey: ['GET /users', { query: { page: 2 } }],
232
- });
233
-
234
- expect(page1Query?.state.isInvalidated).toBe(true);
235
- expect(page2Query?.state.isInvalidated).toBe(false);
236
- });
237
- });
238
- });
239
- });