@tuyau/core 1.0.0-beta.13 → 1.0.0-beta.14
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.
|
@@ -1,3 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extending the HTTP response interface to include status and response
|
|
3
|
+
* in the return type.
|
|
4
|
+
*
|
|
5
|
+
* This is ONLY type information and the properties will not be available
|
|
6
|
+
* at runtime. This is needed to infer the correct response type
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
declare module '@adonisjs/core/http' {
|
|
10
|
+
interface HttpResponse {
|
|
11
|
+
continue(): {
|
|
12
|
+
__status: 100;
|
|
13
|
+
};
|
|
14
|
+
switchingProtocols(etag?: boolean): {
|
|
15
|
+
__status: 101;
|
|
16
|
+
};
|
|
17
|
+
ok<T>(body: T, etag?: boolean): {
|
|
18
|
+
__response: T;
|
|
19
|
+
__status: 200;
|
|
20
|
+
};
|
|
21
|
+
created<T>(body?: T, etag?: boolean): {
|
|
22
|
+
__response: T;
|
|
23
|
+
__status: 201;
|
|
24
|
+
};
|
|
25
|
+
accepted<T>(body: T, etag?: boolean): {
|
|
26
|
+
__response: T;
|
|
27
|
+
__status: 202;
|
|
28
|
+
};
|
|
29
|
+
nonAuthoritativeInformation<T>(body?: T, etag?: boolean): {
|
|
30
|
+
__response: T;
|
|
31
|
+
__status: 203;
|
|
32
|
+
};
|
|
33
|
+
noContent<T>(body?: T, etag?: boolean): {
|
|
34
|
+
__response: T;
|
|
35
|
+
__status: 204;
|
|
36
|
+
};
|
|
37
|
+
resetContent<T>(body?: T, etag?: boolean): {
|
|
38
|
+
__response: T;
|
|
39
|
+
__status: 205;
|
|
40
|
+
};
|
|
41
|
+
partialContent<T>(body: T, etag?: boolean): {
|
|
42
|
+
__response: T;
|
|
43
|
+
__status: 206;
|
|
44
|
+
};
|
|
45
|
+
multipleChoices<T>(body?: T, etag?: boolean): {
|
|
46
|
+
__response: T;
|
|
47
|
+
__status: 300;
|
|
48
|
+
};
|
|
49
|
+
movedPermanently<T>(body?: T, etag?: boolean): {
|
|
50
|
+
__response: T;
|
|
51
|
+
__status: 301;
|
|
52
|
+
};
|
|
53
|
+
movedTemporarily<T>(body?: T, etag?: boolean): {
|
|
54
|
+
__response: T;
|
|
55
|
+
__status: 302;
|
|
56
|
+
};
|
|
57
|
+
seeOther<T>(body?: T, etag?: boolean): {
|
|
58
|
+
__response: T;
|
|
59
|
+
__status: 303;
|
|
60
|
+
};
|
|
61
|
+
notModified<T>(body?: T, etag?: boolean): {
|
|
62
|
+
__response: T;
|
|
63
|
+
__status: 304;
|
|
64
|
+
};
|
|
65
|
+
useProxy<T>(body?: T, etag?: boolean): {
|
|
66
|
+
__response: T;
|
|
67
|
+
__status: 305;
|
|
68
|
+
};
|
|
69
|
+
temporaryRedirect<T>(body?: T, etag?: boolean): {
|
|
70
|
+
__response: T;
|
|
71
|
+
__status: 307;
|
|
72
|
+
};
|
|
73
|
+
badRequest<T>(body?: T, etag?: boolean): {
|
|
74
|
+
__response: T;
|
|
75
|
+
__status: 400;
|
|
76
|
+
};
|
|
77
|
+
unauthorized<T>(body?: T, etag?: boolean): {
|
|
78
|
+
__response: T;
|
|
79
|
+
__status: 401;
|
|
80
|
+
};
|
|
81
|
+
paymentRequired<T>(body?: T, etag?: boolean): {
|
|
82
|
+
__response: T;
|
|
83
|
+
__status: 402;
|
|
84
|
+
};
|
|
85
|
+
forbidden<T>(body?: T, etag?: boolean): {
|
|
86
|
+
__response: T;
|
|
87
|
+
__status: 403;
|
|
88
|
+
};
|
|
89
|
+
notFound<T>(body?: T, etag?: boolean): {
|
|
90
|
+
__response: T;
|
|
91
|
+
__status: 404;
|
|
92
|
+
};
|
|
93
|
+
methodNotAllowed<T>(body?: T, etag?: boolean): {
|
|
94
|
+
__response: T;
|
|
95
|
+
__status: 405;
|
|
96
|
+
};
|
|
97
|
+
notAcceptable<T>(body?: T, etag?: boolean): {
|
|
98
|
+
__response: T;
|
|
99
|
+
__status: 406;
|
|
100
|
+
};
|
|
101
|
+
proxyAuthenticationRequired<T>(body?: T, etag?: boolean): {
|
|
102
|
+
__response: T;
|
|
103
|
+
__status: 407;
|
|
104
|
+
};
|
|
105
|
+
requestTimeout<T>(body?: T, etag?: boolean): {
|
|
106
|
+
__response: T;
|
|
107
|
+
__status: 408;
|
|
108
|
+
};
|
|
109
|
+
conflict<T>(body?: T, etag?: boolean): {
|
|
110
|
+
__response: T;
|
|
111
|
+
__status: 409;
|
|
112
|
+
};
|
|
113
|
+
gone<T>(body?: T, etag?: boolean): {
|
|
114
|
+
__response: T;
|
|
115
|
+
__status: 410;
|
|
116
|
+
};
|
|
117
|
+
lengthRequired<T>(body?: T, etag?: boolean): {
|
|
118
|
+
__response: T;
|
|
119
|
+
__status: 411;
|
|
120
|
+
};
|
|
121
|
+
preconditionFailed<T>(body?: T, etag?: boolean): {
|
|
122
|
+
__response: T;
|
|
123
|
+
__status: 412;
|
|
124
|
+
};
|
|
125
|
+
requestEntityTooLarge<T>(body?: T, etag?: boolean): {
|
|
126
|
+
__response: T;
|
|
127
|
+
__status: 413;
|
|
128
|
+
};
|
|
129
|
+
requestUriTooLong<T>(body?: T, etag?: boolean): {
|
|
130
|
+
__response: T;
|
|
131
|
+
__status: 414;
|
|
132
|
+
};
|
|
133
|
+
unsupportedMediaType<T>(body?: T, etag?: boolean): {
|
|
134
|
+
__response: T;
|
|
135
|
+
__status: 415;
|
|
136
|
+
};
|
|
137
|
+
requestedRangeNotSatisfiable<T>(body?: T, etag?: boolean): {
|
|
138
|
+
__response: T;
|
|
139
|
+
__status: 416;
|
|
140
|
+
};
|
|
141
|
+
expectationFailed<T>(body?: T, etag?: boolean): {
|
|
142
|
+
__response: T;
|
|
143
|
+
__status: 417;
|
|
144
|
+
};
|
|
145
|
+
unprocessableEntity<T>(body?: T, etag?: boolean): {
|
|
146
|
+
__response: T;
|
|
147
|
+
__status: 422;
|
|
148
|
+
};
|
|
149
|
+
tooManyRequests<T>(body?: T, etag?: boolean): {
|
|
150
|
+
__response: T;
|
|
151
|
+
__status: 429;
|
|
152
|
+
};
|
|
153
|
+
internalServerError<T>(body?: T, etag?: boolean): {
|
|
154
|
+
__response: T;
|
|
155
|
+
__status: 500;
|
|
156
|
+
};
|
|
157
|
+
notImplemented<T>(body?: T, etag?: boolean): {
|
|
158
|
+
__response: T;
|
|
159
|
+
__status: 501;
|
|
160
|
+
};
|
|
161
|
+
badGateway<T>(body?: T, etag?: boolean): {
|
|
162
|
+
__response: T;
|
|
163
|
+
__status: 502;
|
|
164
|
+
};
|
|
165
|
+
serviceUnavailable<T>(body?: T, etag?: boolean): {
|
|
166
|
+
__response: T;
|
|
167
|
+
__status: 503;
|
|
168
|
+
};
|
|
169
|
+
gatewayTimeout<T>(body?: T, etag?: boolean): {
|
|
170
|
+
__response: T;
|
|
171
|
+
__status: 504;
|
|
172
|
+
};
|
|
173
|
+
httpVersionNotSupported<T>(body?: T, etag?: boolean): {
|
|
174
|
+
__response: T;
|
|
175
|
+
__status: 505;
|
|
176
|
+
};
|
|
177
|
+
json<T>(body: T, generateEtag?: boolean): {
|
|
178
|
+
__response: T;
|
|
179
|
+
__status: 200;
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
1
184
|
interface GenerateRegistryConfig {
|
|
2
185
|
/**
|
|
3
186
|
* Path to write the generated registry directory
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// src/backend/types.ts
|
|
2
|
+
import "@adonisjs/core/http";
|
|
3
|
+
|
|
1
4
|
// src/backend/generate_registry.ts
|
|
2
5
|
import { dirname } from "path";
|
|
3
6
|
import { writeFile, mkdir } from "fs/promises";
|
|
@@ -106,9 +109,9 @@ function generateRuntimeRegistryEntry(route) {
|
|
|
106
109
|
function wrapResponseType(responseType) {
|
|
107
110
|
if (responseType === "unknown" || responseType === "{}") return responseType;
|
|
108
111
|
if (responseType.startsWith("ReturnType<")) {
|
|
109
|
-
return `Awaited<${responseType}
|
|
112
|
+
return `ExtractResponse<Awaited<${responseType}>>`;
|
|
110
113
|
}
|
|
111
|
-
return responseType
|
|
114
|
+
return `ExtractResponse<${responseType}>`;
|
|
112
115
|
}
|
|
113
116
|
function determineBodyAndQueryTypes(options) {
|
|
114
117
|
const { methods, requestType } = options;
|
|
@@ -191,7 +194,7 @@ function generateTypesContent(routes) {
|
|
|
191
194
|
return `/* eslint-disable prettier/prettier */
|
|
192
195
|
/// <reference path="../manifest.d.ts" />
|
|
193
196
|
|
|
194
|
-
import type { ExtractBody, ExtractQuery, ExtractQueryForGet } from '@tuyau/core/types'
|
|
197
|
+
import type { ExtractBody, ExtractQuery, ExtractQueryForGet, ExtractResponse } from '@tuyau/core/types'
|
|
195
198
|
import type { InferInput } from '@vinejs/vine/types'
|
|
196
199
|
|
|
197
200
|
export interface Registry {
|
|
@@ -49,6 +49,14 @@ type ExtractQueryForGet<T> = Omit<T, 'headers' | 'cookies' | 'params'>;
|
|
|
49
49
|
* Excludes 'query', 'params', 'headers', and 'cookies' as these are handled separately by AdonisJS.
|
|
50
50
|
*/
|
|
51
51
|
type ExtractBody<T> = Omit<T, 'query' | 'params' | 'headers' | 'cookies'>;
|
|
52
|
+
/**
|
|
53
|
+
* Extract the actual response type from a controller return type.
|
|
54
|
+
* If the type has a `__response` property (from typed response methods like ok(), created(), etc.),
|
|
55
|
+
* extract that. Otherwise return the original type.
|
|
56
|
+
*/
|
|
57
|
+
type ExtractResponse<T> = T extends {
|
|
58
|
+
__response: infer R;
|
|
59
|
+
} ? R : T;
|
|
52
60
|
/**
|
|
53
61
|
* Registry mapping endpoint names to their definitions
|
|
54
62
|
*/
|
|
@@ -245,4 +253,4 @@ type RegistryGroupedByMethod<R extends Record<string, AdonisEndpoint>, M extends
|
|
|
245
253
|
};
|
|
246
254
|
};
|
|
247
255
|
|
|
248
|
-
export { type AdonisEndpoint, type AdonisRegistry, type BaseRequestOptions, type EndpointByMethodPattern, type EndpointByName, type EndpointFn, type EndpointTypes, type Endpoints, type EndpointsByMethod, type ExtractBody, type ExtractQuery, type ExtractQueryForGet, type InferRoutes, type InferTree, type MaybeArray, type Method, Path, PathWithRegistry, type PatternsByMethod, type QueryParameters, type RawRequestArgs, type RegValues, type RegistryGroupedByMethod, type RequestArgs, type ResponseOf, Route, RouteWithRegistry, type SchemaEndpoint, type Split, type StrKeys, type TransformApiDefinition, type TuyauConfiguration, type TuyauPlugin, type TuyauRegistry, type UnionToIntersection, type UserRegistry, type ValueOf };
|
|
256
|
+
export { type AdonisEndpoint, type AdonisRegistry, type BaseRequestOptions, type EndpointByMethodPattern, type EndpointByName, type EndpointFn, type EndpointTypes, type Endpoints, type EndpointsByMethod, type ExtractBody, type ExtractQuery, type ExtractQueryForGet, type ExtractResponse, type InferRoutes, type InferTree, type MaybeArray, type Method, Path, PathWithRegistry, type PatternsByMethod, type QueryParameters, type RawRequestArgs, type RegValues, type RegistryGroupedByMethod, type RequestArgs, type ResponseOf, Route, RouteWithRegistry, type SchemaEndpoint, type Split, type StrKeys, type TransformApiDefinition, type TuyauConfiguration, type TuyauPlugin, type TuyauRegistry, type UnionToIntersection, type UserRegistry, type ValueOf };
|