fets 0.6.5 → 0.6.6
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/cjs/client/createClient.js +24 -22
- package/cjs/createRouter.js +31 -55
- package/esm/client/createClient.js +24 -22
- package/esm/createRouter.js +31 -55
- package/package.json +1 -1
- package/typings/client/createClient.d.cts +2 -2
- package/typings/client/createClient.d.ts +2 -2
- package/typings/client/types.d.cts +1 -1
- package/typings/client/types.d.ts +1 -1
- package/typings/createRouter.d.cts +1 -1
- package/typings/createRouter.d.ts +1 -1
- package/typings/typed-fetch.d.cts +11 -25
- package/typings/typed-fetch.d.ts +11 -25
- package/typings/types.d.cts +5 -5
- package/typings/types.d.ts +5 -5
|
@@ -89,31 +89,33 @@ function createClient({ endpoint, fetchFn = fetch_1.fetch, plugins = [] }) {
|
|
|
89
89
|
},
|
|
90
90
|
});
|
|
91
91
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if (requestParams?.query) {
|
|
97
|
-
const searchParams = (0, qs_1.stringify)(requestParams.query, qsOptions);
|
|
98
|
-
if (finalUrl.includes('?')) {
|
|
99
|
-
finalUrl += '&' + searchParams;
|
|
92
|
+
if (response == null) {
|
|
93
|
+
let finalUrl = path;
|
|
94
|
+
if (endpoint && !path.startsWith('http')) {
|
|
95
|
+
finalUrl = `${endpoint}${path}`;
|
|
100
96
|
}
|
|
101
|
-
|
|
102
|
-
|
|
97
|
+
if (requestParams?.query) {
|
|
98
|
+
const searchParams = (0, qs_1.stringify)(requestParams.query, qsOptions);
|
|
99
|
+
if (finalUrl.includes('?')) {
|
|
100
|
+
finalUrl += '&' + searchParams;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
finalUrl += '?' + searchParams;
|
|
104
|
+
}
|
|
103
105
|
}
|
|
106
|
+
let currentFetchFn = fetchFn;
|
|
107
|
+
for (const onFetchHook of onFetchHooks) {
|
|
108
|
+
await onFetchHook({
|
|
109
|
+
url: finalUrl,
|
|
110
|
+
init: requestInit,
|
|
111
|
+
fetchFn: currentFetchFn,
|
|
112
|
+
setFetchFn(newFetchFn) {
|
|
113
|
+
currentFetchFn = newFetchFn;
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
response = await currentFetchFn(finalUrl, requestInit);
|
|
104
118
|
}
|
|
105
|
-
let currentFetchFn = fetchFn;
|
|
106
|
-
for (const onFetchHook of onFetchHooks) {
|
|
107
|
-
await onFetchHook({
|
|
108
|
-
url: finalUrl,
|
|
109
|
-
init: requestInit,
|
|
110
|
-
fetchFn: currentFetchFn,
|
|
111
|
-
setFetchFn(newFetchFn) {
|
|
112
|
-
currentFetchFn = newFetchFn;
|
|
113
|
-
},
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
response ||= await currentFetchFn(finalUrl, requestInit);
|
|
117
119
|
for (const onResponseHook of onResponseHooks) {
|
|
118
120
|
await onResponseHook({
|
|
119
121
|
path,
|
package/cjs/createRouter.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createRouter = exports.createRouterBase = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const qs_1 = require("qs");
|
|
5
6
|
const DefaultFetchAPI = tslib_1.__importStar(require("@whatwg-node/fetch"));
|
|
6
7
|
const server_1 = require("@whatwg-node/server");
|
|
7
8
|
const landing_page_js_1 = tslib_1.__importDefault(require("./landing-page.js"));
|
|
@@ -54,53 +55,39 @@ function createRouterBase({ fetchAPI: givenFetchAPI, base: basePath = '/', plugi
|
|
|
54
55
|
return Reflect.get(url, prop, url);
|
|
55
56
|
},
|
|
56
57
|
});
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return '';
|
|
65
|
-
}
|
|
66
|
-
return allQueries.length === 1 ? allQueries[0] : allQueries;
|
|
58
|
+
let parsedQuery;
|
|
59
|
+
Object.defineProperties(request, {
|
|
60
|
+
parsedUrl: {
|
|
61
|
+
get() {
|
|
62
|
+
return url;
|
|
63
|
+
},
|
|
64
|
+
configurable: true,
|
|
67
65
|
},
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
66
|
+
query: {
|
|
67
|
+
get() {
|
|
68
|
+
if (parsedQuery == null) {
|
|
69
|
+
const searchPart = request.url.split('?')[1];
|
|
70
|
+
if (searchPart == null) {
|
|
71
|
+
return EMPTY_OBJECT;
|
|
72
|
+
}
|
|
73
|
+
parsedQuery = (0, qs_1.parse)(searchPart);
|
|
74
|
+
}
|
|
75
|
+
return parsedQuery;
|
|
76
|
+
},
|
|
77
|
+
configurable: true,
|
|
73
78
|
},
|
|
74
79
|
});
|
|
75
80
|
const pathPatternMapByMethod = routeByPathByMethod.get(request.method);
|
|
76
81
|
if (pathPatternMapByMethod) {
|
|
77
82
|
const route = pathPatternMapByMethod.get(url.pathname);
|
|
78
83
|
if (route) {
|
|
79
|
-
const routerRequest = new Proxy(request, {
|
|
80
|
-
get(target, prop) {
|
|
81
|
-
if (prop === 'parsedUrl') {
|
|
82
|
-
return url;
|
|
83
|
-
}
|
|
84
|
-
if (prop === 'query') {
|
|
85
|
-
return queryProxy;
|
|
86
|
-
}
|
|
87
|
-
const targetProp = target[prop];
|
|
88
|
-
if (typeof targetProp === 'function') {
|
|
89
|
-
return targetProp.bind(target);
|
|
90
|
-
}
|
|
91
|
-
return targetProp;
|
|
92
|
-
},
|
|
93
|
-
has(target, prop) {
|
|
94
|
-
return prop in target || prop === 'parsedUrl' || prop === 'query';
|
|
95
|
-
},
|
|
96
|
-
});
|
|
97
84
|
for (const onRouteHandleHook of onRouteHandleHooks) {
|
|
98
85
|
onRouteHandleHook({
|
|
99
86
|
route,
|
|
100
|
-
request:
|
|
87
|
+
request: request,
|
|
101
88
|
});
|
|
102
89
|
}
|
|
103
|
-
const handlerResult$ = route.handler(
|
|
90
|
+
const handlerResult$ = route.handler(request, context);
|
|
104
91
|
if ((0, server_1.isPromise)(handlerResult$)) {
|
|
105
92
|
return handlerResult$.then(handlerResult => {
|
|
106
93
|
if (handlerResult) {
|
|
@@ -120,13 +107,11 @@ function createRouterBase({ fetchAPI: givenFetchAPI, base: basePath = '/', plugi
|
|
|
120
107
|
// Do not parse URL if not needed
|
|
121
108
|
const match = pattern.exec(url);
|
|
122
109
|
if (match != null) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
if (prop === 'params') {
|
|
129
|
-
return new Proxy(match.pathname.groups, {
|
|
110
|
+
let paramsProxy;
|
|
111
|
+
Object.defineProperty(request, 'params', {
|
|
112
|
+
get() {
|
|
113
|
+
if (paramsProxy == null) {
|
|
114
|
+
paramsProxy = new Proxy(match.pathname.groups, {
|
|
130
115
|
get(_, prop) {
|
|
131
116
|
const value = match.pathname.groups[prop.toString()];
|
|
132
117
|
if (value != null) {
|
|
@@ -136,26 +121,17 @@ function createRouterBase({ fetchAPI: givenFetchAPI, base: basePath = '/', plugi
|
|
|
136
121
|
},
|
|
137
122
|
});
|
|
138
123
|
}
|
|
139
|
-
|
|
140
|
-
return queryProxy;
|
|
141
|
-
}
|
|
142
|
-
const targetProp = target[prop];
|
|
143
|
-
if (typeof targetProp === 'function') {
|
|
144
|
-
return targetProp.bind(target);
|
|
145
|
-
}
|
|
146
|
-
return targetProp;
|
|
147
|
-
},
|
|
148
|
-
has(target, prop) {
|
|
149
|
-
return (prop in target || prop === 'parsedUrl' || prop === 'params' || prop === 'query');
|
|
124
|
+
return paramsProxy;
|
|
150
125
|
},
|
|
126
|
+
configurable: true,
|
|
151
127
|
});
|
|
152
128
|
for (const onRouteHandleHook of onRouteHandleHooks) {
|
|
153
129
|
onRouteHandleHook({
|
|
154
130
|
route,
|
|
155
|
-
request:
|
|
131
|
+
request: request,
|
|
156
132
|
});
|
|
157
133
|
}
|
|
158
|
-
return route.handler(
|
|
134
|
+
return route.handler(request, context);
|
|
159
135
|
}
|
|
160
136
|
});
|
|
161
137
|
if ((0, server_1.isPromise)(patternHandlerResult$)) {
|
|
@@ -85,31 +85,33 @@ export function createClient({ endpoint, fetchFn = fetch, plugins = [] }) {
|
|
|
85
85
|
},
|
|
86
86
|
});
|
|
87
87
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (requestParams?.query) {
|
|
93
|
-
const searchParams = qsStringify(requestParams.query, qsOptions);
|
|
94
|
-
if (finalUrl.includes('?')) {
|
|
95
|
-
finalUrl += '&' + searchParams;
|
|
88
|
+
if (response == null) {
|
|
89
|
+
let finalUrl = path;
|
|
90
|
+
if (endpoint && !path.startsWith('http')) {
|
|
91
|
+
finalUrl = `${endpoint}${path}`;
|
|
96
92
|
}
|
|
97
|
-
|
|
98
|
-
|
|
93
|
+
if (requestParams?.query) {
|
|
94
|
+
const searchParams = qsStringify(requestParams.query, qsOptions);
|
|
95
|
+
if (finalUrl.includes('?')) {
|
|
96
|
+
finalUrl += '&' + searchParams;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
finalUrl += '?' + searchParams;
|
|
100
|
+
}
|
|
99
101
|
}
|
|
102
|
+
let currentFetchFn = fetchFn;
|
|
103
|
+
for (const onFetchHook of onFetchHooks) {
|
|
104
|
+
await onFetchHook({
|
|
105
|
+
url: finalUrl,
|
|
106
|
+
init: requestInit,
|
|
107
|
+
fetchFn: currentFetchFn,
|
|
108
|
+
setFetchFn(newFetchFn) {
|
|
109
|
+
currentFetchFn = newFetchFn;
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
response = await currentFetchFn(finalUrl, requestInit);
|
|
100
114
|
}
|
|
101
|
-
let currentFetchFn = fetchFn;
|
|
102
|
-
for (const onFetchHook of onFetchHooks) {
|
|
103
|
-
await onFetchHook({
|
|
104
|
-
url: finalUrl,
|
|
105
|
-
init: requestInit,
|
|
106
|
-
fetchFn: currentFetchFn,
|
|
107
|
-
setFetchFn(newFetchFn) {
|
|
108
|
-
currentFetchFn = newFetchFn;
|
|
109
|
-
},
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
response ||= await currentFetchFn(finalUrl, requestInit);
|
|
113
115
|
for (const onResponseHook of onResponseHooks) {
|
|
114
116
|
await onResponseHook({
|
|
115
117
|
path,
|
package/esm/createRouter.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { parse as qsParse } from 'qs';
|
|
1
2
|
import * as DefaultFetchAPI from '@whatwg-node/fetch';
|
|
2
3
|
import { createServerAdapter, isPromise, useErrorHandling } from '@whatwg-node/server';
|
|
3
4
|
import landingPageRaw from './landing-page.js';
|
|
@@ -50,53 +51,39 @@ export function createRouterBase({ fetchAPI: givenFetchAPI, base: basePath = '/'
|
|
|
50
51
|
return Reflect.get(url, prop, url);
|
|
51
52
|
},
|
|
52
53
|
});
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return '';
|
|
61
|
-
}
|
|
62
|
-
return allQueries.length === 1 ? allQueries[0] : allQueries;
|
|
54
|
+
let parsedQuery;
|
|
55
|
+
Object.defineProperties(request, {
|
|
56
|
+
parsedUrl: {
|
|
57
|
+
get() {
|
|
58
|
+
return url;
|
|
59
|
+
},
|
|
60
|
+
configurable: true,
|
|
63
61
|
},
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
62
|
+
query: {
|
|
63
|
+
get() {
|
|
64
|
+
if (parsedQuery == null) {
|
|
65
|
+
const searchPart = request.url.split('?')[1];
|
|
66
|
+
if (searchPart == null) {
|
|
67
|
+
return EMPTY_OBJECT;
|
|
68
|
+
}
|
|
69
|
+
parsedQuery = qsParse(searchPart);
|
|
70
|
+
}
|
|
71
|
+
return parsedQuery;
|
|
72
|
+
},
|
|
73
|
+
configurable: true,
|
|
69
74
|
},
|
|
70
75
|
});
|
|
71
76
|
const pathPatternMapByMethod = routeByPathByMethod.get(request.method);
|
|
72
77
|
if (pathPatternMapByMethod) {
|
|
73
78
|
const route = pathPatternMapByMethod.get(url.pathname);
|
|
74
79
|
if (route) {
|
|
75
|
-
const routerRequest = new Proxy(request, {
|
|
76
|
-
get(target, prop) {
|
|
77
|
-
if (prop === 'parsedUrl') {
|
|
78
|
-
return url;
|
|
79
|
-
}
|
|
80
|
-
if (prop === 'query') {
|
|
81
|
-
return queryProxy;
|
|
82
|
-
}
|
|
83
|
-
const targetProp = target[prop];
|
|
84
|
-
if (typeof targetProp === 'function') {
|
|
85
|
-
return targetProp.bind(target);
|
|
86
|
-
}
|
|
87
|
-
return targetProp;
|
|
88
|
-
},
|
|
89
|
-
has(target, prop) {
|
|
90
|
-
return prop in target || prop === 'parsedUrl' || prop === 'query';
|
|
91
|
-
},
|
|
92
|
-
});
|
|
93
80
|
for (const onRouteHandleHook of onRouteHandleHooks) {
|
|
94
81
|
onRouteHandleHook({
|
|
95
82
|
route,
|
|
96
|
-
request:
|
|
83
|
+
request: request,
|
|
97
84
|
});
|
|
98
85
|
}
|
|
99
|
-
const handlerResult$ = route.handler(
|
|
86
|
+
const handlerResult$ = route.handler(request, context);
|
|
100
87
|
if (isPromise(handlerResult$)) {
|
|
101
88
|
return handlerResult$.then(handlerResult => {
|
|
102
89
|
if (handlerResult) {
|
|
@@ -116,13 +103,11 @@ export function createRouterBase({ fetchAPI: givenFetchAPI, base: basePath = '/'
|
|
|
116
103
|
// Do not parse URL if not needed
|
|
117
104
|
const match = pattern.exec(url);
|
|
118
105
|
if (match != null) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if (prop === 'params') {
|
|
125
|
-
return new Proxy(match.pathname.groups, {
|
|
106
|
+
let paramsProxy;
|
|
107
|
+
Object.defineProperty(request, 'params', {
|
|
108
|
+
get() {
|
|
109
|
+
if (paramsProxy == null) {
|
|
110
|
+
paramsProxy = new Proxy(match.pathname.groups, {
|
|
126
111
|
get(_, prop) {
|
|
127
112
|
const value = match.pathname.groups[prop.toString()];
|
|
128
113
|
if (value != null) {
|
|
@@ -132,26 +117,17 @@ export function createRouterBase({ fetchAPI: givenFetchAPI, base: basePath = '/'
|
|
|
132
117
|
},
|
|
133
118
|
});
|
|
134
119
|
}
|
|
135
|
-
|
|
136
|
-
return queryProxy;
|
|
137
|
-
}
|
|
138
|
-
const targetProp = target[prop];
|
|
139
|
-
if (typeof targetProp === 'function') {
|
|
140
|
-
return targetProp.bind(target);
|
|
141
|
-
}
|
|
142
|
-
return targetProp;
|
|
143
|
-
},
|
|
144
|
-
has(target, prop) {
|
|
145
|
-
return (prop in target || prop === 'parsedUrl' || prop === 'params' || prop === 'query');
|
|
120
|
+
return paramsProxy;
|
|
146
121
|
},
|
|
122
|
+
configurable: true,
|
|
147
123
|
});
|
|
148
124
|
for (const onRouteHandleHook of onRouteHandleHooks) {
|
|
149
125
|
onRouteHandleHook({
|
|
150
126
|
route,
|
|
151
|
-
request:
|
|
127
|
+
request: request,
|
|
152
128
|
});
|
|
153
129
|
}
|
|
154
|
-
return route.handler(
|
|
130
|
+
return route.handler(request, context);
|
|
155
131
|
}
|
|
156
132
|
});
|
|
157
133
|
if (isPromise(patternHandlerResult$)) {
|
package/package.json
CHANGED
|
@@ -25,10 +25,10 @@ export declare class ClientValidationError extends Error implements AggregateErr
|
|
|
25
25
|
* const client = createClient<NormalizeOAS<typeof oas>>({});
|
|
26
26
|
* ```
|
|
27
27
|
*/
|
|
28
|
-
export declare function createClient<TOAS extends OpenAPIDocument>(options: ClientOptionsWithStrictEndpoint<TOAS>): OASClient<TOAS>;
|
|
28
|
+
export declare function createClient<const TOAS extends OpenAPIDocument>(options: ClientOptionsWithStrictEndpoint<TOAS>): OASClient<TOAS>;
|
|
29
29
|
/**
|
|
30
30
|
* Create a client from a typed `Router`
|
|
31
31
|
*
|
|
32
32
|
* @see https://the-guild.dev/openapi/fets/client/quick-start#usage-with-fets-server
|
|
33
33
|
*/
|
|
34
|
-
export declare function createClient<TRouter extends Router<any, any, any>>(options: ClientOptions): TRouter['__client'];
|
|
34
|
+
export declare function createClient<const TRouter extends Router<any, any, any>>(options: ClientOptions): TRouter['__client'];
|
|
@@ -25,10 +25,10 @@ export declare class ClientValidationError extends Error implements AggregateErr
|
|
|
25
25
|
* const client = createClient<NormalizeOAS<typeof oas>>({});
|
|
26
26
|
* ```
|
|
27
27
|
*/
|
|
28
|
-
export declare function createClient<TOAS extends OpenAPIDocument>(options: ClientOptionsWithStrictEndpoint<TOAS>): OASClient<TOAS>;
|
|
28
|
+
export declare function createClient<const TOAS extends OpenAPIDocument>(options: ClientOptionsWithStrictEndpoint<TOAS>): OASClient<TOAS>;
|
|
29
29
|
/**
|
|
30
30
|
* Create a client from a typed `Router`
|
|
31
31
|
*
|
|
32
32
|
* @see https://the-guild.dev/openapi/fets/client/quick-start#usage-with-fets-server
|
|
33
33
|
*/
|
|
34
|
-
export declare function createClient<TRouter extends Router<any, any, any>>(options: ClientOptions): TRouter['__client'];
|
|
34
|
+
export declare function createClient<const TRouter extends Router<any, any, any>>(options: ClientOptions): TRouter['__client'];
|
|
@@ -302,7 +302,7 @@ export interface ClientRequestParams {
|
|
|
302
302
|
formData?: FormData;
|
|
303
303
|
formUrlEncoded?: Record<string, string | string[]>;
|
|
304
304
|
params?: Record<string, string>;
|
|
305
|
-
query?:
|
|
305
|
+
query?: any;
|
|
306
306
|
headers?: Record<string, string>;
|
|
307
307
|
}
|
|
308
308
|
export type ClientMethod = (requestParams?: ClientRequestParams) => Promise<Response>;
|
|
@@ -302,7 +302,7 @@ export interface ClientRequestParams {
|
|
|
302
302
|
formData?: FormData;
|
|
303
303
|
formUrlEncoded?: Record<string, string | string[]>;
|
|
304
304
|
params?: Record<string, string>;
|
|
305
|
-
query?:
|
|
305
|
+
query?: any;
|
|
306
306
|
headers?: Record<string, string>;
|
|
307
307
|
}
|
|
308
308
|
export type ClientMethod = (requestParams?: ClientRequestParams) => Promise<Response>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TypedRequest, TypedResponse } from './typed-fetch.cjs';
|
|
2
2
|
import type { OpenAPIDocument, Router, RouterBaseObject, RouterComponentsBase, RouterOptions, RouterSDK } from './types.cjs';
|
|
3
3
|
export declare function createRouterBase({ fetchAPI: givenFetchAPI, base: basePath, plugins, openAPI, swaggerUI, landingPage, }: RouterOptions<any, any> | undefined, openAPIDocument: OpenAPIDocument): RouterBaseObject<any, any, any>;
|
|
4
|
-
export declare function createRouter<TServerContext, TComponents extends RouterComponentsBase = {}, TRouterSDK extends RouterSDK<string, TypedRequest, TypedResponse> = {
|
|
4
|
+
export declare function createRouter<TServerContext, const TComponents extends RouterComponentsBase = {}, const TRouterSDK extends RouterSDK<string, TypedRequest, TypedResponse> = {
|
|
5
5
|
[TKey: string]: never;
|
|
6
6
|
}>(options?: RouterOptions<TServerContext, TComponents>): Router<TServerContext, TComponents, TRouterSDK>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TypedRequest, TypedResponse } from './typed-fetch.js';
|
|
2
2
|
import type { OpenAPIDocument, Router, RouterBaseObject, RouterComponentsBase, RouterOptions, RouterSDK } from './types.js';
|
|
3
3
|
export declare function createRouterBase({ fetchAPI: givenFetchAPI, base: basePath, plugins, openAPI, swaggerUI, landingPage, }: RouterOptions<any, any> | undefined, openAPIDocument: OpenAPIDocument): RouterBaseObject<any, any, any>;
|
|
4
|
-
export declare function createRouter<TServerContext, TComponents extends RouterComponentsBase = {}, TRouterSDK extends RouterSDK<string, TypedRequest, TypedResponse> = {
|
|
4
|
+
export declare function createRouter<TServerContext, const TComponents extends RouterComponentsBase = {}, const TRouterSDK extends RouterSDK<string, TypedRequest, TypedResponse> = {
|
|
5
5
|
[TKey: string]: never;
|
|
6
6
|
}>(options?: RouterOptions<TServerContext, TComponents>): Router<TServerContext, TComponents, TRouterSDK>;
|
|
@@ -31,7 +31,7 @@ export type TypedBody<TJSON, TFormData extends Record<string, FormDataEntryValue
|
|
|
31
31
|
type DefaultHTTPHeaders = 'accept' | 'accept-language' | 'content-language' | 'content-type' | 'content-length';
|
|
32
32
|
type Maybe = undefined | null;
|
|
33
33
|
type UndefinedToNull<T> = T extends undefined ? Exclude<T, undefined> | null : T;
|
|
34
|
-
export
|
|
34
|
+
export interface TypedHeaders<TMap extends Record<string, string>> {
|
|
35
35
|
append<TName extends DefaultHTTPHeaders | keyof TMap>(name: TName, value: TName extends keyof TMap ? TMap[TName] : string): void;
|
|
36
36
|
delete<TName extends DefaultHTTPHeaders | keyof TMap>(name: TName): void;
|
|
37
37
|
get<TName extends DefaultHTTPHeaders | keyof TMap>(name: TName): TName extends keyof TMap ? UndefinedToNull<TMap[TName]> : TName extends DefaultHTTPHeaders ? string | null : never;
|
|
@@ -43,7 +43,7 @@ export type TypedHeaders<TMap extends Record<string, string>> = {
|
|
|
43
43
|
values(): IterableIterator<TMap[keyof TMap]>;
|
|
44
44
|
[Symbol.iterator](): IterableIterator<[keyof TMap, TMap[keyof TMap]]>;
|
|
45
45
|
getSetCookie(): string[];
|
|
46
|
-
}
|
|
46
|
+
}
|
|
47
47
|
export type TypedHeadersCtor = new <TMap extends Record<string, string>>(init?: TMap) => TypedHeaders<TMap>;
|
|
48
48
|
export type TypedResponseInit<TStatusCode extends StatusCode = 200> = Omit<ResponseInit, 'status' | 'statusText'> & {
|
|
49
49
|
/**
|
|
@@ -147,8 +147,9 @@ export type TypedResponse<TJSON = unknown, THeaders extends Record<string, strin
|
|
|
147
147
|
*/
|
|
148
148
|
ok: TStatusCode extends OkStatusCode ? true : false;
|
|
149
149
|
};
|
|
150
|
-
export type
|
|
151
|
-
|
|
150
|
+
export type JSONofResponse<TResponse extends TypedResponse> = TResponse extends TypedResponse<infer TJSON> ? TJSON : never;
|
|
151
|
+
export type TypedResponseCtor<TTypedResponse extends TypedResponse = TypedResponse> = Omit<typeof Response, 'json'> & {
|
|
152
|
+
new <TStatusCode extends TTypedResponse['status'] = 200>(body: BodyInit | null | undefined, init: (TypedResponseInit<TStatusCode> & {
|
|
152
153
|
status: TStatusCode;
|
|
153
154
|
}) | undefined): TypedResponse<any, Record<string, string>, TStatusCode>;
|
|
154
155
|
new (body: BodyInit | null | undefined, init: ResponseInit | undefined): TypedResponse<any, Record<string, string>, 200>;
|
|
@@ -161,7 +162,7 @@ export type TypedResponseCtor = Omit<typeof Response, 'json'> & {
|
|
|
161
162
|
*
|
|
162
163
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/Response/json_static
|
|
163
164
|
*/
|
|
164
|
-
json<TJSON
|
|
165
|
+
json<TJSON extends JSONofResponse<TTypedResponse>, TStatusCode extends TTypedResponse['status']>(data: TJSON, options: TypedResponseInit<TStatusCode>): TypedResponse<TJSON, Record<string, string>, TStatusCode>;
|
|
165
166
|
/**
|
|
166
167
|
* The `json()` static method of the `Response` interface returns a `Response` that contains the provided JSON data as body,
|
|
167
168
|
* and a `Content-Type` header which is set to `application/json`.
|
|
@@ -169,7 +170,7 @@ export type TypedResponseCtor = Omit<typeof Response, 'json'> & {
|
|
|
169
170
|
*
|
|
170
171
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/Response/json_static
|
|
171
172
|
*/
|
|
172
|
-
json<TJSON
|
|
173
|
+
json<TJSON extends JSONofResponse<TTypedResponse>>(data: TJSON): TypedResponse<TJSON, Record<string, string>, 200>;
|
|
173
174
|
/**
|
|
174
175
|
* The redirect() static method of the Response interface returns a Response resulting in a redirect to the specified URL.
|
|
175
176
|
* @param url The URL that the new response is to originate from.
|
|
@@ -177,7 +178,7 @@ export type TypedResponseCtor = Omit<typeof Response, 'json'> & {
|
|
|
177
178
|
*
|
|
178
179
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/Response/redirect_static
|
|
179
180
|
*/
|
|
180
|
-
redirect<TStatusCode extends
|
|
181
|
+
redirect<TStatusCode extends TTypedResponse['status']>(url: string | URL, status: TStatusCode): TypedResponse<any, Record<string, string>, TStatusCode>;
|
|
181
182
|
/**
|
|
182
183
|
* The redirect() static method of the Response interface returns a Response resulting in a redirect to the specified URL.
|
|
183
184
|
* @param url The URL that the new response is to originate from.
|
|
@@ -195,28 +196,13 @@ export type TypedRequestInit<THeaders extends Record<string, string>, TMethod ex
|
|
|
195
196
|
headers: TypedHeaders<THeaders>;
|
|
196
197
|
body?: Exclude<BodyInit, FormData> | TFormData;
|
|
197
198
|
};
|
|
198
|
-
export type TypedRequest<TJSON = any, TFormData extends Record<string, FormDataEntryValue> = Record<string, FormDataEntryValue>, THeaders extends Record<string, string> = Record<string, string>, TMethod extends HTTPMethod = HTTPMethod, TQueryParams
|
|
199
|
+
export type TypedRequest<TJSON = any, TFormData extends Record<string, FormDataEntryValue> = Record<string, FormDataEntryValue>, THeaders extends Record<string, string> = Record<string, string>, TMethod extends HTTPMethod = HTTPMethod, TQueryParams = any, TPathParams extends Record<string, any> = Record<string, any>> = Omit<Request, 'json' | 'method' | 'headers' | 'formData'> & TypedBody<TJSON, TFormData, THeaders> & {
|
|
200
|
+
parsedUrl: URL;
|
|
199
201
|
method: TMethod;
|
|
200
|
-
parsedUrl: TypedURL<TQueryParams>;
|
|
201
202
|
params: TPathParams;
|
|
202
203
|
query: TQueryParams;
|
|
203
204
|
};
|
|
204
|
-
export type TypedRequestCtor = new <THeaders extends Record<string, string>, TMethod extends HTTPMethod,
|
|
205
|
-
export interface TypedURLSearchParams<TMap extends Record<string, string | string[]>> {
|
|
206
|
-
append<TName extends keyof TMap>(name: TName, value: TMap[TName] extends any[] ? TMap[TName][1] : TMap[TName]): void;
|
|
207
|
-
delete(name: keyof TMap): void;
|
|
208
|
-
get<TName extends keyof TMap>(name: TName): TMap[TName] extends any[] ? TMap[TName][1] : TMap[TName];
|
|
209
|
-
getAll<TName extends keyof TMap>(name: TName): TMap[TName] extends any[] ? TMap[TName] : [TMap[TName]];
|
|
210
|
-
set<TName extends keyof TMap>(name: TName, value: TMap[TName] extends any[] ? TMap[TName][1] : TMap[TName]): void;
|
|
211
|
-
sort(): void;
|
|
212
|
-
toString(): string;
|
|
213
|
-
forEach(callbackfn: <TName extends keyof TMap>(value: TMap[TName] extends any[] ? TMap[TName][1] : TMap[TName], name: TName, parent: TypedURLSearchParams<TMap>) => void, thisArg?: any): void;
|
|
214
|
-
}
|
|
215
|
-
export type TypedURLSearchParamsCtor = new <TMap extends Record<string, string | string[]>>(init?: TMap) => TypedURLSearchParams<TMap>;
|
|
216
|
-
export type TypedURL<TQueryParams extends Record<string, string | string[]>> = Omit<URL, 'searchParams'> & {
|
|
217
|
-
searchParams: TypedURLSearchParams<TQueryParams>;
|
|
218
|
-
};
|
|
219
|
-
export type TypedURLCtor = new <TQueryParams extends Record<string, string | string[]>>(input: string, base?: string | TypedURL<any>) => TypedURL<TQueryParams>;
|
|
205
|
+
export type TypedRequestCtor = new <THeaders extends Record<string, string>, TMethod extends HTTPMethod, TFormData extends Record<string, FormDataEntryValue>>(input: string | URL, init?: TypedRequestInit<THeaders, TMethod, TFormData>) => TypedRequest<any, TFormData, THeaders, TMethod, any, any>;
|
|
220
206
|
export interface TypedFormData<TMap extends Record<string, FormDataEntryValue> = Record<string, FormDataEntryValue>> {
|
|
221
207
|
append<TName extends keyof TMap>(name: TName, value: TMap[TName] extends any[] ? TMap[TName][0] : TMap[TName], fileName?: string): void;
|
|
222
208
|
delete(name: keyof TMap): void;
|
package/typings/typed-fetch.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export type TypedBody<TJSON, TFormData extends Record<string, FormDataEntryValue
|
|
|
31
31
|
type DefaultHTTPHeaders = 'accept' | 'accept-language' | 'content-language' | 'content-type' | 'content-length';
|
|
32
32
|
type Maybe = undefined | null;
|
|
33
33
|
type UndefinedToNull<T> = T extends undefined ? Exclude<T, undefined> | null : T;
|
|
34
|
-
export
|
|
34
|
+
export interface TypedHeaders<TMap extends Record<string, string>> {
|
|
35
35
|
append<TName extends DefaultHTTPHeaders | keyof TMap>(name: TName, value: TName extends keyof TMap ? TMap[TName] : string): void;
|
|
36
36
|
delete<TName extends DefaultHTTPHeaders | keyof TMap>(name: TName): void;
|
|
37
37
|
get<TName extends DefaultHTTPHeaders | keyof TMap>(name: TName): TName extends keyof TMap ? UndefinedToNull<TMap[TName]> : TName extends DefaultHTTPHeaders ? string | null : never;
|
|
@@ -43,7 +43,7 @@ export type TypedHeaders<TMap extends Record<string, string>> = {
|
|
|
43
43
|
values(): IterableIterator<TMap[keyof TMap]>;
|
|
44
44
|
[Symbol.iterator](): IterableIterator<[keyof TMap, TMap[keyof TMap]]>;
|
|
45
45
|
getSetCookie(): string[];
|
|
46
|
-
}
|
|
46
|
+
}
|
|
47
47
|
export type TypedHeadersCtor = new <TMap extends Record<string, string>>(init?: TMap) => TypedHeaders<TMap>;
|
|
48
48
|
export type TypedResponseInit<TStatusCode extends StatusCode = 200> = Omit<ResponseInit, 'status' | 'statusText'> & {
|
|
49
49
|
/**
|
|
@@ -147,8 +147,9 @@ export type TypedResponse<TJSON = unknown, THeaders extends Record<string, strin
|
|
|
147
147
|
*/
|
|
148
148
|
ok: TStatusCode extends OkStatusCode ? true : false;
|
|
149
149
|
};
|
|
150
|
-
export type
|
|
151
|
-
|
|
150
|
+
export type JSONofResponse<TResponse extends TypedResponse> = TResponse extends TypedResponse<infer TJSON> ? TJSON : never;
|
|
151
|
+
export type TypedResponseCtor<TTypedResponse extends TypedResponse = TypedResponse> = Omit<typeof Response, 'json'> & {
|
|
152
|
+
new <TStatusCode extends TTypedResponse['status'] = 200>(body: BodyInit | null | undefined, init: (TypedResponseInit<TStatusCode> & {
|
|
152
153
|
status: TStatusCode;
|
|
153
154
|
}) | undefined): TypedResponse<any, Record<string, string>, TStatusCode>;
|
|
154
155
|
new (body: BodyInit | null | undefined, init: ResponseInit | undefined): TypedResponse<any, Record<string, string>, 200>;
|
|
@@ -161,7 +162,7 @@ export type TypedResponseCtor = Omit<typeof Response, 'json'> & {
|
|
|
161
162
|
*
|
|
162
163
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/Response/json_static
|
|
163
164
|
*/
|
|
164
|
-
json<TJSON
|
|
165
|
+
json<TJSON extends JSONofResponse<TTypedResponse>, TStatusCode extends TTypedResponse['status']>(data: TJSON, options: TypedResponseInit<TStatusCode>): TypedResponse<TJSON, Record<string, string>, TStatusCode>;
|
|
165
166
|
/**
|
|
166
167
|
* The `json()` static method of the `Response` interface returns a `Response` that contains the provided JSON data as body,
|
|
167
168
|
* and a `Content-Type` header which is set to `application/json`.
|
|
@@ -169,7 +170,7 @@ export type TypedResponseCtor = Omit<typeof Response, 'json'> & {
|
|
|
169
170
|
*
|
|
170
171
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/Response/json_static
|
|
171
172
|
*/
|
|
172
|
-
json<TJSON
|
|
173
|
+
json<TJSON extends JSONofResponse<TTypedResponse>>(data: TJSON): TypedResponse<TJSON, Record<string, string>, 200>;
|
|
173
174
|
/**
|
|
174
175
|
* The redirect() static method of the Response interface returns a Response resulting in a redirect to the specified URL.
|
|
175
176
|
* @param url The URL that the new response is to originate from.
|
|
@@ -177,7 +178,7 @@ export type TypedResponseCtor = Omit<typeof Response, 'json'> & {
|
|
|
177
178
|
*
|
|
178
179
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/Response/redirect_static
|
|
179
180
|
*/
|
|
180
|
-
redirect<TStatusCode extends
|
|
181
|
+
redirect<TStatusCode extends TTypedResponse['status']>(url: string | URL, status: TStatusCode): TypedResponse<any, Record<string, string>, TStatusCode>;
|
|
181
182
|
/**
|
|
182
183
|
* The redirect() static method of the Response interface returns a Response resulting in a redirect to the specified URL.
|
|
183
184
|
* @param url The URL that the new response is to originate from.
|
|
@@ -195,28 +196,13 @@ export type TypedRequestInit<THeaders extends Record<string, string>, TMethod ex
|
|
|
195
196
|
headers: TypedHeaders<THeaders>;
|
|
196
197
|
body?: Exclude<BodyInit, FormData> | TFormData;
|
|
197
198
|
};
|
|
198
|
-
export type TypedRequest<TJSON = any, TFormData extends Record<string, FormDataEntryValue> = Record<string, FormDataEntryValue>, THeaders extends Record<string, string> = Record<string, string>, TMethod extends HTTPMethod = HTTPMethod, TQueryParams
|
|
199
|
+
export type TypedRequest<TJSON = any, TFormData extends Record<string, FormDataEntryValue> = Record<string, FormDataEntryValue>, THeaders extends Record<string, string> = Record<string, string>, TMethod extends HTTPMethod = HTTPMethod, TQueryParams = any, TPathParams extends Record<string, any> = Record<string, any>> = Omit<Request, 'json' | 'method' | 'headers' | 'formData'> & TypedBody<TJSON, TFormData, THeaders> & {
|
|
200
|
+
parsedUrl: URL;
|
|
199
201
|
method: TMethod;
|
|
200
|
-
parsedUrl: TypedURL<TQueryParams>;
|
|
201
202
|
params: TPathParams;
|
|
202
203
|
query: TQueryParams;
|
|
203
204
|
};
|
|
204
|
-
export type TypedRequestCtor = new <THeaders extends Record<string, string>, TMethod extends HTTPMethod,
|
|
205
|
-
export interface TypedURLSearchParams<TMap extends Record<string, string | string[]>> {
|
|
206
|
-
append<TName extends keyof TMap>(name: TName, value: TMap[TName] extends any[] ? TMap[TName][1] : TMap[TName]): void;
|
|
207
|
-
delete(name: keyof TMap): void;
|
|
208
|
-
get<TName extends keyof TMap>(name: TName): TMap[TName] extends any[] ? TMap[TName][1] : TMap[TName];
|
|
209
|
-
getAll<TName extends keyof TMap>(name: TName): TMap[TName] extends any[] ? TMap[TName] : [TMap[TName]];
|
|
210
|
-
set<TName extends keyof TMap>(name: TName, value: TMap[TName] extends any[] ? TMap[TName][1] : TMap[TName]): void;
|
|
211
|
-
sort(): void;
|
|
212
|
-
toString(): string;
|
|
213
|
-
forEach(callbackfn: <TName extends keyof TMap>(value: TMap[TName] extends any[] ? TMap[TName][1] : TMap[TName], name: TName, parent: TypedURLSearchParams<TMap>) => void, thisArg?: any): void;
|
|
214
|
-
}
|
|
215
|
-
export type TypedURLSearchParamsCtor = new <TMap extends Record<string, string | string[]>>(init?: TMap) => TypedURLSearchParams<TMap>;
|
|
216
|
-
export type TypedURL<TQueryParams extends Record<string, string | string[]>> = Omit<URL, 'searchParams'> & {
|
|
217
|
-
searchParams: TypedURLSearchParams<TQueryParams>;
|
|
218
|
-
};
|
|
219
|
-
export type TypedURLCtor = new <TQueryParams extends Record<string, string | string[]>>(input: string, base?: string | TypedURL<any>) => TypedURL<TQueryParams>;
|
|
205
|
+
export type TypedRequestCtor = new <THeaders extends Record<string, string>, TMethod extends HTTPMethod, TFormData extends Record<string, FormDataEntryValue>>(input: string | URL, init?: TypedRequestInit<THeaders, TMethod, TFormData>) => TypedRequest<any, TFormData, THeaders, TMethod, any, any>;
|
|
220
206
|
export interface TypedFormData<TMap extends Record<string, FormDataEntryValue> = Record<string, FormDataEntryValue>> {
|
|
221
207
|
append<TName extends keyof TMap>(name: TName, value: TMap[TName] extends any[] ? TMap[TName][0] : TMap[TName], fileName?: string): void;
|
|
222
208
|
delete(name: keyof TMap): void;
|
package/typings/types.d.cts
CHANGED
|
@@ -131,8 +131,8 @@ export type StatusCodeMap<T> = {
|
|
|
131
131
|
export interface RouterBaseObject<TServerContext, TComponents extends RouterComponentsBase, TRouterSDK extends RouterSDK<string, TypedRequest, TypedResponse>> {
|
|
132
132
|
openAPIDocument: OpenAPIDocument;
|
|
133
133
|
handle: ServerAdapterRequestHandler<TServerContext>;
|
|
134
|
-
route<TRouteSchemas extends RouteSchemas, TMethod extends HTTPMethod, TPath extends string, TTypedRequest extends TypedRequestFromRouteSchemas<TComponents, TRouteSchemas, TMethod, TPath>, TTypedResponse extends TypedResponseFromRouteSchemas<TComponents, TRouteSchemas>>(opts: RouteWithSchemasOpts<TServerContext, TComponents, TRouteSchemas, TMethod, TPath, TTypedRequest, TTypedResponse>): Router<TServerContext, TComponents, TRouterSDK & RouterSDK<TPath, TTypedRequest, TTypedResponse>>;
|
|
135
|
-
route<TMethod extends HTTPMethod, TPath extends string, TTypedRequest extends TypedRequest<any, Record<string, FormDataEntryValue>, Record<string, string>, TMethod,
|
|
134
|
+
route<const TRouteSchemas extends RouteSchemas, TMethod extends HTTPMethod, TPath extends string, TTypedRequest extends TypedRequestFromRouteSchemas<TComponents, TRouteSchemas, TMethod, TPath>, TTypedResponse extends TypedResponseFromRouteSchemas<TComponents, TRouteSchemas>>(opts: RouteWithSchemasOpts<TServerContext, TComponents, TRouteSchemas, TMethod, TPath, TTypedRequest, TTypedResponse>): Router<TServerContext, TComponents, TRouterSDK & RouterSDK<TPath, TTypedRequest, TTypedResponse>>;
|
|
135
|
+
route<TMethod extends HTTPMethod, TPath extends string, TTypedRequest extends TypedRequest<any, Record<string, FormDataEntryValue>, Record<string, string>, TMethod, any, Record<ExtractPathParamsWithPattern<TPath>, string>>, TTypedResponse extends TypedResponse>(opts: RouteWithTypesOpts<TServerContext, TMethod, TPath, TTypedRequest, TTypedResponse>): Router<TServerContext, TComponents, TRouterSDK & RouterSDK<TPath, TTypedRequest, TTypedResponse>>;
|
|
136
136
|
__client: TRouterSDK;
|
|
137
137
|
__onRouterInitHooks: OnRouterInitHook<TServerContext>[];
|
|
138
138
|
}
|
|
@@ -199,9 +199,9 @@ export type TypedRequestFromRouteSchemas<TComponents extends RouterComponentsBas
|
|
|
199
199
|
headers: JSONSchema;
|
|
200
200
|
} ? FromSchemaWithComponents<TComponents, TRouteSchemas['request']['headers']> extends Record<string, string> ? FromSchemaWithComponents<TComponents, TRouteSchemas['request']['headers']> : Record<string, string> : Record<string, string>, TMethod, TRouteSchemas['request'] extends {
|
|
201
201
|
query: JSONSchema;
|
|
202
|
-
} ? FromSchemaWithComponents<TComponents, TRouteSchemas['request']['query']>
|
|
202
|
+
} ? FromSchemaWithComponents<TComponents, TRouteSchemas['request']['query']> : any, TRouteSchemas['request'] extends {
|
|
203
203
|
params: JSONSchema;
|
|
204
|
-
} ? FromSchemaWithComponents<TComponents, TRouteSchemas['request']['params']> extends Record<string, any> ? FromSchemaWithComponents<TComponents, TRouteSchemas['request']['params']> : Record<ExtractPathParamsWithPattern<TPath>, string> : Record<ExtractPathParamsWithPattern<TPath>, string>> : TypedRequest<any, Record<string, FormDataEntryValue>, Record<string, string>, TMethod,
|
|
204
|
+
} ? FromSchemaWithComponents<TComponents, TRouteSchemas['request']['params']> extends Record<string, any> ? FromSchemaWithComponents<TComponents, TRouteSchemas['request']['params']> : Record<ExtractPathParamsWithPattern<TPath>, string> : Record<ExtractPathParamsWithPattern<TPath>, string>> : TypedRequest<any, Record<string, FormDataEntryValue>, Record<string, string>, TMethod, any, Record<ExtractPathParamsWithPattern<TPath>, string>>;
|
|
205
205
|
export type TypedResponseFromRouteSchemas<TComponents extends RouterComponentsBase, TRouteSchemas extends RouteSchemas> = TRouteSchemas extends {
|
|
206
206
|
responses: StatusCodeMap<JSONSchema>;
|
|
207
207
|
} ? TypedResponseWithJSONStatusMap<{
|
|
@@ -214,7 +214,7 @@ export type RouteWithSchemasOpts<TServerContext, TComponents extends RouterCompo
|
|
|
214
214
|
export type SecuritySchemeRefsFromComponents<TComponents extends RouterComponentsBase> = TComponents extends {
|
|
215
215
|
securitySchemes: Record<string, SecurityScheme>;
|
|
216
216
|
} ? Record<keyof TComponents['securitySchemes'], any> : never;
|
|
217
|
-
export type RouteWithTypesOpts<TServerContext, TMethod extends HTTPMethod, TPath extends string, TTypedRequest extends TypedRequest<any, Record<string, FormDataEntryValue>, Record<string, string>, TMethod,
|
|
217
|
+
export type RouteWithTypesOpts<TServerContext, TMethod extends HTTPMethod, TPath extends string, TTypedRequest extends TypedRequest<any, Record<string, FormDataEntryValue>, Record<string, string>, TMethod, any, Record<ExtractPathParamsWithPattern<TPath>, string>>, TTypedResponse extends TypedResponse> = {
|
|
218
218
|
operationId?: string;
|
|
219
219
|
description?: string;
|
|
220
220
|
method?: TMethod;
|
package/typings/types.d.ts
CHANGED
|
@@ -131,8 +131,8 @@ export type StatusCodeMap<T> = {
|
|
|
131
131
|
export interface RouterBaseObject<TServerContext, TComponents extends RouterComponentsBase, TRouterSDK extends RouterSDK<string, TypedRequest, TypedResponse>> {
|
|
132
132
|
openAPIDocument: OpenAPIDocument;
|
|
133
133
|
handle: ServerAdapterRequestHandler<TServerContext>;
|
|
134
|
-
route<TRouteSchemas extends RouteSchemas, TMethod extends HTTPMethod, TPath extends string, TTypedRequest extends TypedRequestFromRouteSchemas<TComponents, TRouteSchemas, TMethod, TPath>, TTypedResponse extends TypedResponseFromRouteSchemas<TComponents, TRouteSchemas>>(opts: RouteWithSchemasOpts<TServerContext, TComponents, TRouteSchemas, TMethod, TPath, TTypedRequest, TTypedResponse>): Router<TServerContext, TComponents, TRouterSDK & RouterSDK<TPath, TTypedRequest, TTypedResponse>>;
|
|
135
|
-
route<TMethod extends HTTPMethod, TPath extends string, TTypedRequest extends TypedRequest<any, Record<string, FormDataEntryValue>, Record<string, string>, TMethod,
|
|
134
|
+
route<const TRouteSchemas extends RouteSchemas, TMethod extends HTTPMethod, TPath extends string, TTypedRequest extends TypedRequestFromRouteSchemas<TComponents, TRouteSchemas, TMethod, TPath>, TTypedResponse extends TypedResponseFromRouteSchemas<TComponents, TRouteSchemas>>(opts: RouteWithSchemasOpts<TServerContext, TComponents, TRouteSchemas, TMethod, TPath, TTypedRequest, TTypedResponse>): Router<TServerContext, TComponents, TRouterSDK & RouterSDK<TPath, TTypedRequest, TTypedResponse>>;
|
|
135
|
+
route<TMethod extends HTTPMethod, TPath extends string, TTypedRequest extends TypedRequest<any, Record<string, FormDataEntryValue>, Record<string, string>, TMethod, any, Record<ExtractPathParamsWithPattern<TPath>, string>>, TTypedResponse extends TypedResponse>(opts: RouteWithTypesOpts<TServerContext, TMethod, TPath, TTypedRequest, TTypedResponse>): Router<TServerContext, TComponents, TRouterSDK & RouterSDK<TPath, TTypedRequest, TTypedResponse>>;
|
|
136
136
|
__client: TRouterSDK;
|
|
137
137
|
__onRouterInitHooks: OnRouterInitHook<TServerContext>[];
|
|
138
138
|
}
|
|
@@ -199,9 +199,9 @@ export type TypedRequestFromRouteSchemas<TComponents extends RouterComponentsBas
|
|
|
199
199
|
headers: JSONSchema;
|
|
200
200
|
} ? FromSchemaWithComponents<TComponents, TRouteSchemas['request']['headers']> extends Record<string, string> ? FromSchemaWithComponents<TComponents, TRouteSchemas['request']['headers']> : Record<string, string> : Record<string, string>, TMethod, TRouteSchemas['request'] extends {
|
|
201
201
|
query: JSONSchema;
|
|
202
|
-
} ? FromSchemaWithComponents<TComponents, TRouteSchemas['request']['query']>
|
|
202
|
+
} ? FromSchemaWithComponents<TComponents, TRouteSchemas['request']['query']> : any, TRouteSchemas['request'] extends {
|
|
203
203
|
params: JSONSchema;
|
|
204
|
-
} ? FromSchemaWithComponents<TComponents, TRouteSchemas['request']['params']> extends Record<string, any> ? FromSchemaWithComponents<TComponents, TRouteSchemas['request']['params']> : Record<ExtractPathParamsWithPattern<TPath>, string> : Record<ExtractPathParamsWithPattern<TPath>, string>> : TypedRequest<any, Record<string, FormDataEntryValue>, Record<string, string>, TMethod,
|
|
204
|
+
} ? FromSchemaWithComponents<TComponents, TRouteSchemas['request']['params']> extends Record<string, any> ? FromSchemaWithComponents<TComponents, TRouteSchemas['request']['params']> : Record<ExtractPathParamsWithPattern<TPath>, string> : Record<ExtractPathParamsWithPattern<TPath>, string>> : TypedRequest<any, Record<string, FormDataEntryValue>, Record<string, string>, TMethod, any, Record<ExtractPathParamsWithPattern<TPath>, string>>;
|
|
205
205
|
export type TypedResponseFromRouteSchemas<TComponents extends RouterComponentsBase, TRouteSchemas extends RouteSchemas> = TRouteSchemas extends {
|
|
206
206
|
responses: StatusCodeMap<JSONSchema>;
|
|
207
207
|
} ? TypedResponseWithJSONStatusMap<{
|
|
@@ -214,7 +214,7 @@ export type RouteWithSchemasOpts<TServerContext, TComponents extends RouterCompo
|
|
|
214
214
|
export type SecuritySchemeRefsFromComponents<TComponents extends RouterComponentsBase> = TComponents extends {
|
|
215
215
|
securitySchemes: Record<string, SecurityScheme>;
|
|
216
216
|
} ? Record<keyof TComponents['securitySchemes'], any> : never;
|
|
217
|
-
export type RouteWithTypesOpts<TServerContext, TMethod extends HTTPMethod, TPath extends string, TTypedRequest extends TypedRequest<any, Record<string, FormDataEntryValue>, Record<string, string>, TMethod,
|
|
217
|
+
export type RouteWithTypesOpts<TServerContext, TMethod extends HTTPMethod, TPath extends string, TTypedRequest extends TypedRequest<any, Record<string, FormDataEntryValue>, Record<string, string>, TMethod, any, Record<ExtractPathParamsWithPattern<TPath>, string>>, TTypedResponse extends TypedResponse> = {
|
|
218
218
|
operationId?: string;
|
|
219
219
|
description?: string;
|
|
220
220
|
method?: TMethod;
|