@tuyau/core 1.0.0 → 1.2.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/build/backend/generate_registry.d.ts +14 -4
- package/build/backend/generate_registry.js +255 -157
- package/build/client/index.d.ts +27 -29
- package/build/client/index.js +293 -56
- package/build/client/types/index.d.ts +3 -265
- package/build/index-SVztBh2W.d.ts +438 -0
- package/package.json +11 -11
|
@@ -1,265 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Supported HTTP methods for API endpoints
|
|
6
|
-
*/
|
|
7
|
-
type Method = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';
|
|
8
|
-
/**
|
|
9
|
-
* Base endpoint types structure
|
|
10
|
-
*/
|
|
11
|
-
interface EndpointTypes {
|
|
12
|
-
paramsTuple: [...any[]];
|
|
13
|
-
params: Record<string, string | number | boolean | bigint>;
|
|
14
|
-
query: Record<string, any>;
|
|
15
|
-
body: unknown;
|
|
16
|
-
response: unknown;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Schema endpoint, used in generated registry.schema.d.ts
|
|
20
|
-
* Does not include tokens (only present in runtime routes)
|
|
21
|
-
*/
|
|
22
|
-
interface SchemaEndpoint {
|
|
23
|
-
methods: Method[];
|
|
24
|
-
pattern: string;
|
|
25
|
-
types: EndpointTypes;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Definition of an AdonisJS endpoint with types and metadata
|
|
29
|
-
* Includes tokens for runtime route building
|
|
30
|
-
*/
|
|
31
|
-
interface AdonisEndpoint extends SchemaEndpoint {
|
|
32
|
-
tokens: ClientRouteMatchItTokens[];
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Extract query params from a validator type if it has a 'query' property.
|
|
36
|
-
* Used in generated registry to separate query params from body for POST/PUT/PATCH/DELETE.
|
|
37
|
-
* For GET/HEAD, use ExtractQueryForGet instead.
|
|
38
|
-
*/
|
|
39
|
-
type ExtractQuery<T> = 'query' extends keyof T ? T extends {
|
|
40
|
-
query?: infer Q;
|
|
41
|
-
} ? Q : {} : {};
|
|
42
|
-
/**
|
|
43
|
-
* Extract query params for GET/HEAD requests.
|
|
44
|
-
* Excludes headers, cookies, and params from the validator type since these are not query params.
|
|
45
|
-
*/
|
|
46
|
-
type ExtractQueryForGet<T> = Omit<T, 'headers' | 'cookies' | 'params'>;
|
|
47
|
-
/**
|
|
48
|
-
* Extract body from a validator type, excluding reserved properties.
|
|
49
|
-
* Excludes 'query', 'params', 'headers', and 'cookies' as these are handled separately by AdonisJS.
|
|
50
|
-
*/
|
|
51
|
-
type ExtractBody<T> = Omit<T, 'query' | 'params' | 'headers' | 'cookies'>;
|
|
52
|
-
/**
|
|
53
|
-
* Success status codes (2xx)
|
|
54
|
-
*/
|
|
55
|
-
type SuccessStatus = 200 | 201 | 202 | 203 | 204 | 205 | 206;
|
|
56
|
-
/**
|
|
57
|
-
* Extract the actual response type from a controller return type.
|
|
58
|
-
* - Success responses (2xx): extracts `__response`
|
|
59
|
-
* - Error responses (non-2xx with __response/__status): returns `never` to filter from unions
|
|
60
|
-
* - Plain types (no __status): returns as-is
|
|
61
|
-
*/
|
|
62
|
-
type ExtractResponse<T> = T extends {
|
|
63
|
-
__response: infer R;
|
|
64
|
-
__status: SuccessStatus;
|
|
65
|
-
} ? R : T extends {
|
|
66
|
-
__response: unknown;
|
|
67
|
-
__status: number;
|
|
68
|
-
} ? never : T;
|
|
69
|
-
/**
|
|
70
|
-
* Registry mapping endpoint names to their definitions
|
|
71
|
-
*/
|
|
72
|
-
interface AdonisRegistry extends Record<string, AdonisEndpoint> {
|
|
73
|
-
}
|
|
74
|
-
type ValueOf<T> = T[keyof T];
|
|
75
|
-
/**
|
|
76
|
-
* Split a string by a delimiter
|
|
77
|
-
*/
|
|
78
|
-
type Split<S extends string, D extends string = '.'> = S extends `${infer T}${D}${infer U}` ? [T, ...Split<U, D>] : [S];
|
|
79
|
-
/**
|
|
80
|
-
* Convert a union type to an intersection type
|
|
81
|
-
*/
|
|
82
|
-
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
83
|
-
/**
|
|
84
|
-
* Structure of a Tuyau registry containing routes and optional tree
|
|
85
|
-
*/
|
|
86
|
-
interface TuyauRegistry<Routes extends Record<string, AdonisEndpoint> = Record<string, AdonisEndpoint>, Tree = unknown> {
|
|
87
|
-
routes: Routes;
|
|
88
|
-
$tree?: Tree;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Extracts the $tree type from a registry
|
|
92
|
-
* Uses direct access instead of conditional type for performance
|
|
93
|
-
*/
|
|
94
|
-
type InferTree<R extends TuyauRegistry> = R['$tree'];
|
|
95
|
-
/**
|
|
96
|
-
* Extracts the routes from a registry
|
|
97
|
-
*/
|
|
98
|
-
type InferRoutes<R extends TuyauRegistry> = R['routes'];
|
|
99
|
-
type Endpoints = ValueOf<AdonisRegistry>;
|
|
100
|
-
type EndpointByName<Name extends keyof AdonisRegistry & string> = AdonisRegistry[Name];
|
|
101
|
-
/**
|
|
102
|
-
* Pre-computed base Ky options to avoid recomputing Omit on every request
|
|
103
|
-
*/
|
|
104
|
-
type BaseRequestOptions = Omit<Options, 'body' | 'params' | 'searchParams' | 'method' | 'json' | 'prefixUrl'>;
|
|
105
|
-
/**
|
|
106
|
-
* Helper types for optional/required fields - using literal types instead of mapped types
|
|
107
|
-
*/
|
|
108
|
-
type ParamsArg<T> = keyof T extends never ? {} : {} extends T ? {
|
|
109
|
-
params?: T;
|
|
110
|
-
} : {
|
|
111
|
-
params: T;
|
|
112
|
-
};
|
|
113
|
-
type QueryArg<T> = keyof T extends never ? {} : {} extends T ? {
|
|
114
|
-
query?: T;
|
|
115
|
-
} : {
|
|
116
|
-
query: T;
|
|
117
|
-
};
|
|
118
|
-
type BodyArg<T> = keyof T extends never ? {} : {} extends T ? {
|
|
119
|
-
body?: T;
|
|
120
|
-
} : {
|
|
121
|
-
body: T;
|
|
122
|
-
};
|
|
123
|
-
/**
|
|
124
|
-
* Request args without ky options
|
|
125
|
-
*/
|
|
126
|
-
type RawRequestArgs<E extends SchemaEndpoint> = ParamsArg<E['types']['params']> & QueryArg<E['types']['query']> & BodyArg<E['types']['body']>;
|
|
127
|
-
/**
|
|
128
|
-
* Constructs the request arguments type for an endpoint
|
|
129
|
-
*/
|
|
130
|
-
type RequestArgs<E extends SchemaEndpoint> = RawRequestArgs<E> & BaseRequestOptions;
|
|
131
|
-
/**
|
|
132
|
-
* Extracts response type from an endpoint
|
|
133
|
-
*/
|
|
134
|
-
type ResponseOf<E extends SchemaEndpoint> = E['types']['response'];
|
|
135
|
-
/**
|
|
136
|
-
* Function type for calling an endpoint
|
|
137
|
-
*/
|
|
138
|
-
type EndpointFn<E extends SchemaEndpoint> = (args: RequestArgs<E>) => Promise<E['types']['response']>;
|
|
139
|
-
/**
|
|
140
|
-
* Function type for an endpoint with inlined args
|
|
141
|
-
*/
|
|
142
|
-
type EndpointFnInline<E extends AdonisEndpoint> = (args: ParamsArg<E['types']['params']> & QueryArg<E['types']['query']> & BodyArg<E['types']['body']> & BaseRequestOptions) => Promise<E['types']['response']>;
|
|
143
|
-
/**
|
|
144
|
-
* Transforms a pre-computed ApiDefinition tree into callable endpoint functions
|
|
145
|
-
* This recursively converts each endpoint in the tree to a callable function
|
|
146
|
-
* Handles intersection types where a node is both an endpoint AND has children
|
|
147
|
-
*/
|
|
148
|
-
type TransformApiDefinition<T> = {
|
|
149
|
-
[K in keyof T]: T[K] extends AdonisEndpoint ? EndpointFnInline<T[K]> & TransformApiDefinition<Omit<T[K], keyof AdonisEndpoint>> : TransformApiDefinition<T[K]>;
|
|
150
|
-
};
|
|
151
|
-
/**
|
|
152
|
-
* Filters endpoints by HTTP method
|
|
153
|
-
*/
|
|
154
|
-
type EndpointsByMethod<Reg extends Record<string, AdonisEndpoint>, M extends Method> = {
|
|
155
|
-
[K in keyof Reg]: M extends Reg[K]['methods'][number] ? Reg[K] : never;
|
|
156
|
-
}[keyof Reg];
|
|
157
|
-
type StrKeys<R> = Extract<keyof R, string>;
|
|
158
|
-
type RegValues<R> = R[StrKeys<R>];
|
|
159
|
-
/**
|
|
160
|
-
* Gets URL patterns for endpoints matching a specific HTTP method
|
|
161
|
-
*/
|
|
162
|
-
type PatternsByMethod<Reg extends Record<string, AdonisEndpoint>, M extends Method> = EndpointsByMethod<Reg, M>['pattern'];
|
|
163
|
-
/**
|
|
164
|
-
* Finds an endpoint by HTTP method and URL pattern
|
|
165
|
-
*/
|
|
166
|
-
type EndpointByMethodPattern<R extends Record<string, AdonisEndpoint>, M extends Method, P extends PatternsByMethod<R, M>> = FilterByMethodPathForRegistry<R, M, P>;
|
|
167
|
-
/**
|
|
168
|
-
* Plugin function type for extending Tuyau functionality
|
|
169
|
-
*/
|
|
170
|
-
interface TuyauPlugin {
|
|
171
|
-
(params: {
|
|
172
|
-
options: TuyauConfiguration<any>;
|
|
173
|
-
}): void;
|
|
174
|
-
}
|
|
175
|
-
type MaybeArray<T> = T | T[];
|
|
176
|
-
/**
|
|
177
|
-
* Type for URL query parameters
|
|
178
|
-
*/
|
|
179
|
-
interface QueryParameters extends Record<string, MaybeArray<string | number | boolean | null | undefined> | QueryParameters> {
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Configuration options for creating a Tuyau client
|
|
183
|
-
*/
|
|
184
|
-
interface TuyauConfiguration<T extends TuyauRegistry> extends Omit<Options, 'prefixUrl' | 'body' | 'json' | 'method' | 'searchParams'> {
|
|
185
|
-
registry: T;
|
|
186
|
-
baseUrl: string;
|
|
187
|
-
plugins?: TuyauPlugin[];
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Should be augmented by the user to provide their endpoint registry
|
|
191
|
-
* Structure: { routes: Record<string, AdonisEndpoint>, $tree: ApiDefinition }
|
|
192
|
-
*/
|
|
193
|
-
interface UserRegistry {
|
|
194
|
-
}
|
|
195
|
-
type UserAdonisRegistry = UserRegistry extends {
|
|
196
|
-
routes: infer R;
|
|
197
|
-
} ? R extends Record<string, AdonisEndpoint> ? R : Record<string, AdonisEndpoint> : Record<string, AdonisEndpoint>;
|
|
198
|
-
type UserEndpointByName<Name extends keyof UserAdonisRegistry> = UserAdonisRegistry[Name];
|
|
199
|
-
type FilterByMethodPathForRegistry<Reg extends Record<string, AdonisEndpoint>, M extends Method, P extends ValueOf<Reg>['pattern'] & string> = {
|
|
200
|
-
[K in keyof Reg]: Reg[K]['pattern'] extends P ? M extends Reg[K]['methods'][number] ? Reg[K] : never : never;
|
|
201
|
-
}[keyof Reg];
|
|
202
|
-
type EndpointByNameForRegistry<Reg extends Record<string, AdonisEndpoint>, Name extends keyof Reg> = Reg[Name];
|
|
203
|
-
/**
|
|
204
|
-
* Internal type utilities for working with endpoints by HTTP method and path pattern
|
|
205
|
-
* Accepts a registry as generic parameter
|
|
206
|
-
*/
|
|
207
|
-
declare namespace PathWithRegistry {
|
|
208
|
-
type Request<Reg extends Record<string, AdonisEndpoint>, M extends Method, P extends PatternsByMethod<Reg, M>> = RequestArgs<FilterByMethodPathForRegistry<Reg, M, P>>;
|
|
209
|
-
type Response<Reg extends Record<string, AdonisEndpoint>, M extends Method, P extends PatternsByMethod<Reg, M>> = ResponseOf<FilterByMethodPathForRegistry<Reg, M, P>>;
|
|
210
|
-
type Params<Reg extends Record<string, AdonisEndpoint>, M extends Method, P extends PatternsByMethod<Reg, M>> = FilterByMethodPathForRegistry<Reg, M, P>['types']['params'];
|
|
211
|
-
type Body<Reg extends Record<string, AdonisEndpoint>, M extends Method, P extends PatternsByMethod<Reg, M>> = FilterByMethodPathForRegistry<Reg, M, P>['types']['body'];
|
|
212
|
-
type Query<Reg extends Record<string, AdonisEndpoint>, M extends Method, P extends PatternsByMethod<Reg, M>> = FilterByMethodPathForRegistry<Reg, M, P>['types']['query'];
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Internal type utilities for working with endpoints by route name
|
|
216
|
-
* Accepts a registry as generic parameter
|
|
217
|
-
*/
|
|
218
|
-
declare namespace RouteWithRegistry {
|
|
219
|
-
type Request<Reg extends Record<string, AdonisEndpoint>, Name extends keyof Reg> = RequestArgs<EndpointByNameForRegistry<Reg, Name>>;
|
|
220
|
-
type Response<Reg extends Record<string, AdonisEndpoint>, Name extends keyof Reg> = ResponseOf<EndpointByNameForRegistry<Reg, Name>>;
|
|
221
|
-
type Params<Reg extends Record<string, AdonisEndpoint>, Name extends keyof Reg> = EndpointByNameForRegistry<Reg, Name>['types']['params'];
|
|
222
|
-
type Body<Reg extends Record<string, AdonisEndpoint>, Name extends keyof Reg> = EndpointByNameForRegistry<Reg, Name>['types']['body'];
|
|
223
|
-
type Query<Reg extends Record<string, AdonisEndpoint>, Name extends keyof Reg> = EndpointByNameForRegistry<Reg, Name>['types']['query'];
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Type utilities for working with endpoints by HTTP method and path pattern
|
|
227
|
-
* Uses the user-augmented registry
|
|
228
|
-
*/
|
|
229
|
-
declare namespace Path {
|
|
230
|
-
type Request<M extends Method, P extends PatternsByMethod<UserAdonisRegistry, M>> = RequestArgs<FilterByMethodPathForRegistry<UserAdonisRegistry, M, P>>;
|
|
231
|
-
type Response<M extends Method, P extends PatternsByMethod<UserAdonisRegistry, M>> = ResponseOf<FilterByMethodPathForRegistry<UserAdonisRegistry, M, P>>;
|
|
232
|
-
type Params<M extends Method, P extends PatternsByMethod<UserAdonisRegistry, M>> = FilterByMethodPathForRegistry<UserAdonisRegistry, M, P>['types']['params'];
|
|
233
|
-
type Body<M extends Method, P extends PatternsByMethod<UserAdonisRegistry, M>> = FilterByMethodPathForRegistry<UserAdonisRegistry, M, P>['types']['body'];
|
|
234
|
-
type Query<M extends Method, P extends PatternsByMethod<UserAdonisRegistry, M>> = FilterByMethodPathForRegistry<UserAdonisRegistry, M, P>['types']['query'];
|
|
235
|
-
}
|
|
236
|
-
/**
|
|
237
|
-
* Type utilities for working with endpoints by route name
|
|
238
|
-
* Uses the user-augmented registry
|
|
239
|
-
*/
|
|
240
|
-
declare namespace Route {
|
|
241
|
-
type Request<Name extends keyof UserAdonisRegistry> = RequestArgs<UserEndpointByName<Name>>;
|
|
242
|
-
type Response<Name extends keyof UserAdonisRegistry> = ResponseOf<UserEndpointByName<Name>>;
|
|
243
|
-
type Params<Name extends keyof UserAdonisRegistry> = UserEndpointByName<Name>['types']['params'];
|
|
244
|
-
type Body<Name extends keyof UserAdonisRegistry> = UserEndpointByName<Name>['types']['body'];
|
|
245
|
-
type Query<Name extends keyof UserAdonisRegistry> = UserEndpointByName<Name>['types']['query'];
|
|
246
|
-
}
|
|
247
|
-
type ParamsShape<E> = E extends {
|
|
248
|
-
types: {
|
|
249
|
-
paramsTuple: infer PT;
|
|
250
|
-
params: infer P;
|
|
251
|
-
};
|
|
252
|
-
} ? (PT extends [] ? {
|
|
253
|
-
paramsTuple?: PT;
|
|
254
|
-
} : {
|
|
255
|
-
paramsTuple: PT;
|
|
256
|
-
}) & (keyof P extends never ? {} : {
|
|
257
|
-
params: P;
|
|
258
|
-
}) : never;
|
|
259
|
-
type RegistryGroupedByMethod<R extends Record<string, AdonisEndpoint>, M extends Method = Method> = {
|
|
260
|
-
[K in M | 'ALL']: {
|
|
261
|
-
[Route in keyof R as K extends 'ALL' ? Route : K extends R[Route]['methods'][number] ? Route : never]: ParamsShape<R[Route]>;
|
|
262
|
-
};
|
|
263
|
-
};
|
|
264
|
-
|
|
265
|
-
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 };
|
|
1
|
+
export { A as AdonisEndpoint, q as AdonisRegistry, B as BaseRequestOptions, C as CurrentRouteOptions, E as EndpointByMethodPattern, s as EndpointByName, x as EndpointFn, j as EndpointTypes, r as Endpoints, y as EndpointsByMethod, f as ErrorResponseOf, n as ExtractBody, p as ExtractErrorResponse, l as ExtractQuery, m as ExtractQueryForGet, o as ExtractResponse, I as InferRoutes, c as InferTree, N as KnownStatuses, F as MaybeArray, M as Method, K as Path, H as PathWithRegistry, P as PatternsByMethod, Q as QueryParameters, v as RawRequestArgs, z as RegValues, R as RegistryGroupedByMethod, d as RequestArgs, w as ResponseOf, t as ResponseType, L as Route, J as RouteWithRegistry, k as SchemaEndpoint, S as StrKeys, b as TransformApiDefinition, a as TuyauConfiguration, D as TuyauPlugin, T as TuyauRegistry, u as TuyauRequestOptions, U as UnionToIntersection, G as UserRegistry, V as ValueOf } from '../../index-SVztBh2W.js';
|
|
2
|
+
import 'ky';
|
|
3
|
+
import '@adonisjs/http-server/client/url_builder';
|