@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
|
@@ -4,186 +4,186 @@ import { z } from 'zod';
|
|
|
4
4
|
import type { InferOpenApi, InferOpenApiFromEndpoint } from '../infer';
|
|
5
5
|
|
|
6
6
|
describe('InferOpenApi', () => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
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
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
7
|
+
describe('single endpoint', () => {
|
|
8
|
+
it('should infer OpenAPI structure for GET endpoint', () => {
|
|
9
|
+
const endpoint = e
|
|
10
|
+
.get('/users/{id}')
|
|
11
|
+
.params(z.object({ id: z.string() }))
|
|
12
|
+
.output(z.object({ id: z.string(), name: z.string() }))
|
|
13
|
+
.handle(async ({ params }) => ({
|
|
14
|
+
id: params.id,
|
|
15
|
+
name: 'John',
|
|
16
|
+
}));
|
|
17
|
+
|
|
18
|
+
type API = InferOpenApiFromEndpoint<typeof endpoint>;
|
|
19
|
+
|
|
20
|
+
expectTypeOf<API>().toMatchTypeOf<{
|
|
21
|
+
paths: {
|
|
22
|
+
'/users/{id}': {
|
|
23
|
+
get: {
|
|
24
|
+
responses: {
|
|
25
|
+
'200': {
|
|
26
|
+
description: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
}>();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('should infer OpenAPI structure for POST endpoint with body', () => {
|
|
36
|
+
const endpoint = e
|
|
37
|
+
.post('/users')
|
|
38
|
+
.body(z.object({ name: z.string(), email: z.string() }))
|
|
39
|
+
.output(z.object({ id: z.string(), name: z.string() }))
|
|
40
|
+
.handle(async ({ body }) => ({
|
|
41
|
+
id: '123',
|
|
42
|
+
name: body.name,
|
|
43
|
+
}));
|
|
44
|
+
|
|
45
|
+
type API = InferOpenApiFromEndpoint<typeof endpoint>;
|
|
46
|
+
|
|
47
|
+
expectTypeOf<API>().toMatchTypeOf<{
|
|
48
|
+
paths: {
|
|
49
|
+
'/users': {
|
|
50
|
+
post: {
|
|
51
|
+
responses: {
|
|
52
|
+
'200': {
|
|
53
|
+
description: string;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
}>();
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe('multiple endpoints', () => {
|
|
64
|
+
it('should merge OpenAPI specs from multiple endpoints', () => {
|
|
65
|
+
const getUserEndpoint = e
|
|
66
|
+
.get('/users/{id}')
|
|
67
|
+
.params(z.object({ id: z.string() }))
|
|
68
|
+
.output(z.object({ id: z.string(), name: z.string() }))
|
|
69
|
+
.handle(async ({ params }) => ({
|
|
70
|
+
id: params.id,
|
|
71
|
+
name: 'John',
|
|
72
|
+
}));
|
|
73
|
+
|
|
74
|
+
const createUserEndpoint = e
|
|
75
|
+
.post('/users')
|
|
76
|
+
.body(z.object({ name: z.string() }))
|
|
77
|
+
.output(z.object({ id: z.string(), name: z.string() }))
|
|
78
|
+
.handle(async ({ body }) => ({
|
|
79
|
+
id: '123',
|
|
80
|
+
name: body.name,
|
|
81
|
+
}));
|
|
82
|
+
|
|
83
|
+
const endpoints = [getUserEndpoint, createUserEndpoint] as const;
|
|
84
|
+
|
|
85
|
+
type API = InferOpenApi<typeof endpoints>;
|
|
86
|
+
|
|
87
|
+
// Should have both paths
|
|
88
|
+
expectTypeOf<API>().toMatchTypeOf<{
|
|
89
|
+
paths: {
|
|
90
|
+
'/users/{id}': {
|
|
91
|
+
get: unknown;
|
|
92
|
+
};
|
|
93
|
+
'/users': {
|
|
94
|
+
post: unknown;
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
}>();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('should handle endpoints with different HTTP methods on same path', () => {
|
|
101
|
+
const getUserEndpoint = e
|
|
102
|
+
.get('/users')
|
|
103
|
+
.output(z.object({ users: z.array(z.object({ id: z.string() })) }))
|
|
104
|
+
.handle(async () => ({
|
|
105
|
+
users: [],
|
|
106
|
+
}));
|
|
107
|
+
|
|
108
|
+
const createUserEndpoint = e
|
|
109
|
+
.post('/users')
|
|
110
|
+
.body(z.object({ name: z.string() }))
|
|
111
|
+
.output(z.object({ id: z.string() }))
|
|
112
|
+
.handle(async ({ body }) => ({
|
|
113
|
+
id: '123',
|
|
114
|
+
}));
|
|
115
|
+
|
|
116
|
+
const endpoints = [getUserEndpoint, createUserEndpoint] as const;
|
|
117
|
+
|
|
118
|
+
type API = InferOpenApi<typeof endpoints>;
|
|
119
|
+
|
|
120
|
+
// Should have both methods on same path
|
|
121
|
+
expectTypeOf<API>().toMatchTypeOf<{
|
|
122
|
+
paths: {
|
|
123
|
+
'/users': {
|
|
124
|
+
get: unknown;
|
|
125
|
+
post: unknown;
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
}>();
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
describe('complex schemas', () => {
|
|
133
|
+
it('should handle endpoints with query parameters', () => {
|
|
134
|
+
const endpoint = e
|
|
135
|
+
.get('/users')
|
|
136
|
+
.query(
|
|
137
|
+
z.object({
|
|
138
|
+
page: z.coerce.number().optional(),
|
|
139
|
+
limit: z.coerce.number().optional(),
|
|
140
|
+
}),
|
|
141
|
+
)
|
|
142
|
+
.output(z.object({ users: z.array(z.object({ id: z.string() })) }))
|
|
143
|
+
.handle(async ({ query }) => ({
|
|
144
|
+
users: [],
|
|
145
|
+
}));
|
|
146
|
+
|
|
147
|
+
type API = InferOpenApiFromEndpoint<typeof endpoint>;
|
|
148
|
+
|
|
149
|
+
expectTypeOf<API>().toMatchTypeOf<{
|
|
150
|
+
paths: {
|
|
151
|
+
'/users': {
|
|
152
|
+
get: {
|
|
153
|
+
responses: {
|
|
154
|
+
'200': unknown;
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
}>();
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('should handle endpoints with body, params, and query', () => {
|
|
163
|
+
const endpoint = e
|
|
164
|
+
.put('/users/{id}')
|
|
165
|
+
.params(z.object({ id: z.string() }))
|
|
166
|
+
.query(z.object({ notify: z.coerce.boolean().optional() }))
|
|
167
|
+
.body(z.object({ name: z.string() }))
|
|
168
|
+
.output(z.object({ id: z.string(), name: z.string() }))
|
|
169
|
+
.handle(async ({ params, body }) => ({
|
|
170
|
+
id: params.id,
|
|
171
|
+
name: body.name,
|
|
172
|
+
}));
|
|
173
|
+
|
|
174
|
+
type API = InferOpenApiFromEndpoint<typeof endpoint>;
|
|
175
|
+
|
|
176
|
+
expectTypeOf<API>().toMatchTypeOf<{
|
|
177
|
+
paths: {
|
|
178
|
+
'/users/{id}': {
|
|
179
|
+
put: {
|
|
180
|
+
responses: {
|
|
181
|
+
'200': unknown;
|
|
182
|
+
};
|
|
183
|
+
};
|
|
184
|
+
};
|
|
185
|
+
};
|
|
186
|
+
}>();
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
189
|
});
|