@geekmidas/client 0.4.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 +0 -1
- package/dist/auth-fetcher.cjs.map +1 -1
- package/dist/auth-fetcher.d.cts +1 -1
- package/dist/auth-fetcher.d.cts.map +1 -1
- package/dist/auth-fetcher.d.mts +1 -1
- package/dist/auth-fetcher.d.mts.map +1 -1
- package/dist/auth-fetcher.mjs +0 -1
- 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 -1
- package/dist/endpoint-hooks.d.mts +2 -2
- package/dist/endpoint-hooks.d.mts.map +1 -1
- package/dist/endpoint-hooks.mjs +10 -5
- package/dist/endpoint-hooks.mjs.map +1 -1
- package/dist/fetcher-5fnBE7Dk.mjs.map +1 -1
- package/dist/fetcher-CgLEaIAC.cjs.map +1 -1
- package/dist/fetcher.d.cts +1 -1
- package/dist/fetcher.d.cts.map +1 -1
- package/dist/fetcher.d.mts +1 -1
- package/dist/fetcher.d.mts.map +1 -1
- package/dist/infer.d.cts.map +1 -1
- package/dist/infer.d.mts.map +1 -1
- package/dist/openapi-hooks.cjs.map +1 -1
- package/dist/openapi-hooks.d.cts +2 -2
- package/dist/openapi-hooks.d.cts.map +1 -1
- package/dist/openapi-hooks.d.mts +2 -2
- package/dist/openapi-hooks.d.mts.map +1 -1
- package/dist/openapi-hooks.mjs.map +1 -1
- package/dist/openapi-types.d.cts.map +1 -1
- package/dist/openapi-types.d.mts.map +1 -1
- package/dist/openapi.cjs.map +1 -1
- package/dist/openapi.mjs.map +1 -1
- package/dist/react-query.cjs.map +1 -1
- package/dist/react-query.d.cts +1 -1
- package/dist/react-query.d.cts.map +1 -1
- package/dist/react-query.d.mts +1 -1
- package/dist/react-query.d.mts.map +1 -1
- package/dist/react-query.mjs.map +1 -1
- package/dist/{types-FxummKaL.d.mts → types-4K4N-Fl1.d.cts} +2 -2
- package/dist/types-4K4N-Fl1.d.cts.map +1 -0
- package/dist/{types-vutATyWv.d.cts → types-hhkZWjQn.d.mts} +2 -2
- 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 +3 -3
- package/src/__tests__/auth-fetcher.spec.ts +476 -476
- 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 -536
- 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 -156
- 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 +121 -124
- package/dist/types-FxummKaL.d.mts.map +0 -1
- package/dist/types-vutATyWv.d.cts.map +0 -1
|
@@ -4,185 +4,185 @@ import { z } from 'zod';
|
|
|
4
4
|
import type { InferOpenApi } from '../infer';
|
|
5
5
|
|
|
6
6
|
describe('InferOpenApi - TypedFetcher Integration', () => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
7
|
+
it('should generate paths structure compatible with TypedFetcher', () => {
|
|
8
|
+
// Define some endpoints
|
|
9
|
+
const getUserEndpoint = e
|
|
10
|
+
.get('/users/{id}')
|
|
11
|
+
.params(z.object({ id: z.string() }))
|
|
12
|
+
.output(z.object({ id: z.string(), name: z.string(), email: z.string() }))
|
|
13
|
+
.handle(async ({ params }) => ({
|
|
14
|
+
id: params.id,
|
|
15
|
+
name: 'John Doe',
|
|
16
|
+
email: 'john@example.com',
|
|
17
|
+
}));
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
const createUserEndpoint = e
|
|
20
|
+
.post('/users')
|
|
21
|
+
.body(z.object({ name: z.string(), email: z.string() }))
|
|
22
|
+
.output(z.object({ id: z.string(), name: z.string(), email: z.string() }))
|
|
23
|
+
.handle(async ({ body }) => ({
|
|
24
|
+
id: '123',
|
|
25
|
+
name: body.name,
|
|
26
|
+
email: body.email,
|
|
27
|
+
}));
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
29
|
+
const listUsersEndpoint = e
|
|
30
|
+
.get('/users')
|
|
31
|
+
.query(z.object({ page: z.coerce.number().optional() }))
|
|
32
|
+
.output(
|
|
33
|
+
z.object({
|
|
34
|
+
users: z.array(
|
|
35
|
+
z.object({ id: z.string(), name: z.string(), email: z.string() }),
|
|
36
|
+
),
|
|
37
|
+
}),
|
|
38
|
+
)
|
|
39
|
+
.handle(async ({ query }) => ({
|
|
40
|
+
users: [],
|
|
41
|
+
}));
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
43
|
+
// Infer paths from endpoints
|
|
44
|
+
const endpoints = [
|
|
45
|
+
getUserEndpoint,
|
|
46
|
+
createUserEndpoint,
|
|
47
|
+
listUsersEndpoint,
|
|
48
|
+
] as const;
|
|
49
|
+
type Paths = InferOpenApi<typeof endpoints>['paths'];
|
|
50
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
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
51
|
+
// Verify the structure matches TypedFetcher expectations
|
|
52
|
+
expectTypeOf<Paths>().toMatchTypeOf<{
|
|
53
|
+
'/users/{id}': {
|
|
54
|
+
get: {
|
|
55
|
+
parameters: {
|
|
56
|
+
path: { id: string };
|
|
57
|
+
};
|
|
58
|
+
responses: {
|
|
59
|
+
200: {
|
|
60
|
+
content: {
|
|
61
|
+
'application/json': {
|
|
62
|
+
id: string;
|
|
63
|
+
name: string;
|
|
64
|
+
email: string;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
'/users': {
|
|
72
|
+
get: {
|
|
73
|
+
parameters: {
|
|
74
|
+
query: { page?: number };
|
|
75
|
+
};
|
|
76
|
+
responses: {
|
|
77
|
+
200: {
|
|
78
|
+
content: {
|
|
79
|
+
'application/json': {
|
|
80
|
+
users: Array<{ id: string; name: string; email: string }>;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
post: {
|
|
87
|
+
requestBody: {
|
|
88
|
+
content: {
|
|
89
|
+
'application/json': {
|
|
90
|
+
name: string;
|
|
91
|
+
email: string;
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
responses: {
|
|
96
|
+
200: {
|
|
97
|
+
content: {
|
|
98
|
+
'application/json': {
|
|
99
|
+
id: string;
|
|
100
|
+
name: string;
|
|
101
|
+
email: string;
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
}>();
|
|
109
|
+
});
|
|
110
110
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
111
|
+
it('should handle endpoints with multiple parameter types', () => {
|
|
112
|
+
const updateUserEndpoint = e
|
|
113
|
+
.put('/users/{id}')
|
|
114
|
+
.params(z.object({ id: z.string() }))
|
|
115
|
+
.query(z.object({ notify: z.coerce.boolean().optional() }))
|
|
116
|
+
.body(z.object({ name: z.string() }))
|
|
117
|
+
.output(z.object({ id: z.string(), name: z.string() }))
|
|
118
|
+
.handle(async ({ params, query, body }) => ({
|
|
119
|
+
id: params.id,
|
|
120
|
+
name: body.name,
|
|
121
|
+
}));
|
|
122
122
|
|
|
123
|
-
|
|
123
|
+
type Paths = InferOpenApi<[typeof updateUserEndpoint]>['paths'];
|
|
124
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
|
-
|
|
125
|
+
// Verify all parameter types are present
|
|
126
|
+
expectTypeOf<Paths>().toMatchTypeOf<{
|
|
127
|
+
'/users/{id}': {
|
|
128
|
+
parameters: {
|
|
129
|
+
path: { id: string };
|
|
130
|
+
query: { notify?: boolean };
|
|
131
|
+
};
|
|
132
|
+
put: {
|
|
133
|
+
parameters: {
|
|
134
|
+
path: { id: string };
|
|
135
|
+
query: { notify?: boolean };
|
|
136
|
+
};
|
|
137
|
+
requestBody: {
|
|
138
|
+
content: {
|
|
139
|
+
'application/json': {
|
|
140
|
+
name: string;
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
responses: {
|
|
145
|
+
200: {
|
|
146
|
+
content: {
|
|
147
|
+
'application/json': {
|
|
148
|
+
id: string;
|
|
149
|
+
name: string;
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
}>();
|
|
157
|
+
});
|
|
158
158
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
159
|
+
it('should handle endpoints without output schema', () => {
|
|
160
|
+
const deleteUserEndpoint = e
|
|
161
|
+
.delete('/users/{id}')
|
|
162
|
+
.params(z.object({ id: z.string() }))
|
|
163
|
+
.handle(async ({ params }) => {
|
|
164
|
+
// No return value
|
|
165
|
+
});
|
|
166
166
|
|
|
167
|
-
|
|
167
|
+
type Paths = InferOpenApi<[typeof deleteUserEndpoint]>['paths'];
|
|
168
168
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
169
|
+
// Verify response content is never when no output schema
|
|
170
|
+
expectTypeOf<Paths>().toMatchTypeOf<{
|
|
171
|
+
'/users/{id}': {
|
|
172
|
+
parameters: {
|
|
173
|
+
path: { id: string };
|
|
174
|
+
};
|
|
175
|
+
delete: {
|
|
176
|
+
parameters: {
|
|
177
|
+
path: { id: string };
|
|
178
|
+
};
|
|
179
|
+
responses: {
|
|
180
|
+
200: {
|
|
181
|
+
content: never;
|
|
182
|
+
};
|
|
183
|
+
};
|
|
184
|
+
};
|
|
185
|
+
};
|
|
186
|
+
}>();
|
|
187
|
+
});
|
|
188
188
|
});
|