@geekmidas/client 0.3.0 → 0.5.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.
- package/dist/auth-fetcher.cjs +2 -3
- package/dist/auth-fetcher.cjs.map +1 -1
- package/dist/auth-fetcher.d.cts +2 -1
- package/dist/auth-fetcher.d.cts.map +1 -0
- package/dist/auth-fetcher.d.mts +2 -1
- package/dist/auth-fetcher.d.mts.map +1 -0
- package/dist/auth-fetcher.mjs +2 -3
- package/dist/auth-fetcher.mjs.map +1 -1
- package/dist/endpoint-hooks.cjs +10 -5
- package/dist/endpoint-hooks.cjs.map +1 -1
- package/dist/endpoint-hooks.d.cts +2 -2
- package/dist/endpoint-hooks.d.cts.map +1 -0
- package/dist/endpoint-hooks.d.mts +2 -2
- package/dist/endpoint-hooks.d.mts.map +1 -0
- package/dist/endpoint-hooks.mjs +10 -5
- package/dist/endpoint-hooks.mjs.map +1 -1
- package/dist/{fetcher-DLDD_7Sa.mjs → fetcher-5fnBE7Dk.mjs} +2 -2
- package/dist/fetcher-5fnBE7Dk.mjs.map +1 -0
- package/dist/{fetcher-KdwHgdAl.cjs → fetcher-CgLEaIAC.cjs} +2 -2
- package/dist/fetcher-CgLEaIAC.cjs.map +1 -0
- package/dist/fetcher.cjs +1 -1
- package/dist/fetcher.d.cts +3 -1
- package/dist/fetcher.d.cts.map +1 -0
- package/dist/fetcher.d.mts +3 -1
- package/dist/fetcher.d.mts.map +1 -0
- package/dist/fetcher.mjs +1 -1
- package/dist/infer.d.cts.map +1 -0
- package/dist/infer.d.mts.map +1 -0
- package/dist/openapi-hooks.cjs +3 -5
- package/dist/openapi-hooks.cjs.map +1 -1
- package/dist/openapi-hooks.d.cts +3 -3
- package/dist/openapi-hooks.d.cts.map +1 -0
- package/dist/openapi-hooks.d.mts +6 -6
- package/dist/openapi-hooks.d.mts.map +1 -0
- package/dist/openapi-hooks.mjs +3 -5
- package/dist/openapi-hooks.mjs.map +1 -1
- package/dist/openapi-types.d.cts.map +1 -0
- package/dist/openapi-types.d.mts.map +1 -0
- package/dist/openapi.cjs.map +1 -1
- package/dist/openapi.mjs.map +1 -1
- package/dist/react-query.cjs +1 -1
- package/dist/react-query.cjs.map +1 -1
- package/dist/react-query.d.cts +3 -1
- package/dist/react-query.d.cts.map +1 -0
- package/dist/react-query.d.mts +10 -8
- package/dist/react-query.d.mts.map +1 -0
- package/dist/react-query.mjs +1 -1
- package/dist/react-query.mjs.map +1 -1
- package/dist/{types-D4OSWveN.d.cts → types-4K4N-Fl1.d.cts} +8 -6
- package/dist/types-4K4N-Fl1.d.cts.map +1 -0
- package/dist/{types-Cdv1XAWr.d.mts → types-hhkZWjQn.d.mts} +8 -6
- package/dist/types-hhkZWjQn.d.mts.map +1 -0
- package/dist/types.d.cts +1 -1
- package/dist/types.d.mts +1 -1
- package/package.json +6 -5
- package/src/__tests__/auth-fetcher.spec.ts +505 -0
- package/src/__tests__/endpoint-hooks.spec.tsx +348 -348
- package/src/__tests__/fetcher.spec.ts +403 -403
- package/src/__tests__/infer.integration.spec.ts +171 -171
- package/src/__tests__/infer.spec.ts +182 -182
- package/src/__tests__/method-restrictions.spec.tsx +165 -165
- package/src/__tests__/openapi-hooks.spec.tsx +536 -537
- package/src/__tests__/react-query-infinite.spec.tsx +989 -989
- package/src/__tests__/react-query-invalidation.spec.tsx +223 -222
- package/src/__tests__/react-query.spec.tsx +567 -567
- package/src/__tests__/setup.ts +260 -260
- package/src/__tests__/types.spec.ts +127 -127
- package/src/__tests__/url-parsing.spec.ts +191 -191
- package/src/auth-fetcher.ts +160 -162
- package/src/endpoint-hooks.ts +151 -150
- package/src/fetcher.ts +163 -163
- package/src/infer.ts +64 -63
- package/src/openapi-hooks.ts +146 -146
- package/src/openapi-types.d.ts +428 -428
- package/src/openapi.json +593 -593
- package/src/react-query.ts +281 -281
- package/src/types.ts +124 -125
- package/tsconfig.json +12 -0
- package/dist/fetcher-DLDD_7Sa.mjs.map +0 -1
- package/dist/fetcher-KdwHgdAl.cjs.map +0 -1
|
@@ -11,70 +11,70 @@ import { createTypedQueryClient } from '../react-query';
|
|
|
11
11
|
import './setup';
|
|
12
12
|
|
|
13
13
|
describe('Method Restrictions', () => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
14
|
+
const queryClient = new QueryClient({
|
|
15
|
+
defaultOptions: {
|
|
16
|
+
queries: {
|
|
17
|
+
retry: false,
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
23
|
+
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
describe('useQuery', () => {
|
|
27
|
+
it('should accept GET endpoints', () => {
|
|
28
|
+
const typedClient = createTypedQueryClient<paths>({
|
|
29
|
+
baseURL: 'https://api.example.com',
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// This should compile - GET endpoints are allowed
|
|
33
|
+
const { result } = renderHook(() => typedClient.useQuery('GET /users'), {
|
|
34
|
+
wrapper,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
expect(result.current).toBeDefined();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('should accept GET endpoints with parameters', () => {
|
|
41
|
+
const typedClient = createTypedQueryClient<paths>({
|
|
42
|
+
baseURL: 'https://api.example.com',
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// This should compile - GET endpoints with params are allowed
|
|
46
|
+
const { result } = renderHook(
|
|
47
|
+
() =>
|
|
48
|
+
typedClient.useQuery('GET /users/{id}', {
|
|
49
|
+
params: { id: '123' },
|
|
50
|
+
}),
|
|
51
|
+
{ wrapper },
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
expect(result.current).toBeDefined();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('should accept GET endpoints with query parameters', () => {
|
|
58
|
+
const typedClient = createTypedQueryClient<paths>({
|
|
59
|
+
baseURL: 'https://api.example.com',
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// This should compile - GET endpoints with query params are allowed
|
|
63
|
+
const { result } = renderHook(
|
|
64
|
+
() =>
|
|
65
|
+
typedClient.useQuery('GET /posts', {
|
|
66
|
+
query: { page: 1, limit: 10 },
|
|
67
|
+
}),
|
|
68
|
+
{ wrapper },
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
expect(result.current).toBeDefined();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// The following tests would fail TypeScript compilation if uncommented
|
|
75
|
+
// They are left here as documentation of what should NOT work
|
|
76
|
+
|
|
77
|
+
/*
|
|
78
78
|
it('should NOT accept POST endpoints', () => {
|
|
79
79
|
const typedClient = createTypedQueryClient<paths>({
|
|
80
80
|
baseURL: 'https://api.example.com',
|
|
@@ -111,55 +111,55 @@ describe('Method Restrictions', () => {
|
|
|
111
111
|
);
|
|
112
112
|
});
|
|
113
113
|
*/
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
describe('useMutation', () => {
|
|
117
|
+
it('should accept POST endpoints', () => {
|
|
118
|
+
const typedClient = createTypedQueryClient<paths>({
|
|
119
|
+
baseURL: 'https://api.example.com',
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
// This should compile - POST endpoints are allowed
|
|
123
|
+
const { result } = renderHook(
|
|
124
|
+
() => typedClient.useMutation('POST /users'),
|
|
125
|
+
{ wrapper },
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
expect(result.current).toBeDefined();
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('should accept PUT endpoints', () => {
|
|
132
|
+
const typedClient = createTypedQueryClient<paths>({
|
|
133
|
+
baseURL: 'https://api.example.com',
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// This should compile - PUT endpoints are allowed
|
|
137
|
+
const { result } = renderHook(
|
|
138
|
+
() => typedClient.useMutation('PUT /users/{id}'),
|
|
139
|
+
{ wrapper },
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
expect(result.current).toBeDefined();
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('should accept DELETE endpoints', () => {
|
|
146
|
+
const typedClient = createTypedQueryClient<paths>({
|
|
147
|
+
baseURL: 'https://api.example.com',
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
// This should compile - DELETE endpoints are allowed
|
|
151
|
+
const { result } = renderHook(
|
|
152
|
+
() => typedClient.useMutation('DELETE /users/{id}'),
|
|
153
|
+
{ wrapper },
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
expect(result.current).toBeDefined();
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// The following test would fail TypeScript compilation if uncommented
|
|
160
|
+
// It is left here as documentation of what should NOT work
|
|
161
|
+
|
|
162
|
+
/*
|
|
163
163
|
it('should NOT accept GET endpoints', () => {
|
|
164
164
|
const typedClient = createTypedQueryClient<paths>({
|
|
165
165
|
baseURL: 'https://api.example.com',
|
|
@@ -172,56 +172,56 @@ describe('Method Restrictions', () => {
|
|
|
172
172
|
);
|
|
173
173
|
});
|
|
174
174
|
*/
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
describe('Type inference', () => {
|
|
178
|
+
it('should correctly infer response types for GET requests', () => {
|
|
179
|
+
const typedClient = createTypedQueryClient<paths>({
|
|
180
|
+
baseURL: 'https://api.example.com',
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
const { result } = renderHook(() => typedClient.useQuery('GET /users'), {
|
|
184
|
+
wrapper,
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
// TypeScript should infer this type correctly
|
|
188
|
+
type ResponseType = typeof result.current.data;
|
|
189
|
+
type ExpectedType =
|
|
190
|
+
| { users: Array<{ id: string; name: string; email: string }> }
|
|
191
|
+
| undefined;
|
|
192
|
+
|
|
193
|
+
// This assertion validates that the types match at compile time
|
|
194
|
+
const _typeCheck: ResponseType extends ExpectedType ? true : false = true;
|
|
195
|
+
const _typeCheck2: ExpectedType extends ResponseType ? true : false =
|
|
196
|
+
true;
|
|
197
|
+
|
|
198
|
+
expect(_typeCheck).toBe(true);
|
|
199
|
+
expect(_typeCheck2).toBe(true);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it('should correctly infer response types for POST requests', () => {
|
|
203
|
+
const typedClient = createTypedQueryClient<paths>({
|
|
204
|
+
baseURL: 'https://api.example.com',
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
const { result } = renderHook(
|
|
208
|
+
() => typedClient.useMutation('POST /users'),
|
|
209
|
+
{ wrapper },
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
// TypeScript should infer this type correctly
|
|
213
|
+
type ResponseType = typeof result.current.data;
|
|
214
|
+
type ExpectedType =
|
|
215
|
+
| { id: string; name: string; email: string }
|
|
216
|
+
| undefined;
|
|
217
|
+
|
|
218
|
+
// This assertion validates that the types match at compile time
|
|
219
|
+
const _typeCheck: ResponseType extends ExpectedType ? true : false = true;
|
|
220
|
+
const _typeCheck2: ExpectedType extends ResponseType ? true : false =
|
|
221
|
+
true;
|
|
222
|
+
|
|
223
|
+
expect(_typeCheck).toBe(true);
|
|
224
|
+
expect(_typeCheck2).toBe(true);
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
227
|
});
|