@adonisjs/http-server 8.0.0-next.0 → 8.0.0-next.10
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/chunk-2QM3D5BN.js +87 -0
- package/build/chunk-5PWHBE2E.js +128 -0
- package/build/chunk-QDK57QGB.js +1176 -0
- package/build/{chunk-VYBTM3NC.js → chunk-YBLFT4O6.js} +1161 -1719
- package/build/factories/http_context.d.ts +5 -4
- package/build/factories/http_server.d.ts +7 -0
- package/build/factories/main.d.ts +6 -6
- package/build/factories/main.js +33 -5
- package/build/factories/qs_parser_factory.d.ts +5 -4
- package/build/factories/request.d.ts +3 -2
- package/build/factories/response.d.ts +4 -3
- package/build/factories/router.d.ts +2 -1
- package/build/factories/server_factory.d.ts +3 -2
- package/build/factories/url_builder_factory.d.ts +3 -2
- package/build/index.d.ts +19 -16
- package/build/index.js +97 -42
- package/build/src/client/helpers.d.ts +37 -0
- package/build/src/client/types.d.ts +88 -66
- package/build/src/client/url_builder.d.ts +12 -10
- package/build/src/client/url_builder.js +12 -0
- package/build/src/cookies/client.d.ts +61 -3
- package/build/src/cookies/drivers/encrypted.d.ts +13 -0
- package/build/src/cookies/drivers/plain.d.ts +9 -0
- package/build/src/cookies/drivers/signed.d.ts +13 -0
- package/build/src/cookies/parser.d.ts +18 -0
- package/build/src/cookies/serializer.d.ts +22 -3
- package/build/src/debug.d.ts +13 -0
- package/build/src/define_config.d.ts +21 -5
- package/build/src/define_middleware.d.ts +20 -4
- package/build/src/errors.d.ts +67 -10
- package/build/src/exception_handler.d.ts +95 -41
- package/build/src/helpers.d.ts +60 -4
- package/build/src/helpers.js +9 -1
- package/build/src/http_context/local_storage.d.ts +18 -1
- package/build/src/http_context/main.d.ts +71 -13
- package/build/src/qs.d.ts +31 -3
- package/build/src/redirect.d.ts +87 -16
- package/build/src/request.d.ts +121 -15
- package/build/src/response.d.ts +421 -208
- package/build/src/response_status.d.ts +14 -0
- package/build/src/router/brisk.d.ts +18 -7
- package/build/src/router/executor.d.ts +7 -3
- package/build/src/router/factories/use_return_value.d.ts +6 -1
- package/build/src/router/group.d.ts +23 -6
- package/build/src/router/legacy/url_builder.d.ts +15 -15
- package/build/src/router/main.d.ts +133 -20
- package/build/src/router/matchers.d.ts +3 -0
- package/build/src/router/resource.d.ts +37 -5
- package/build/src/router/route.d.ts +30 -6
- package/build/src/router/signed_url_builder.d.ts +7 -10
- package/build/src/router/store.d.ts +10 -2
- package/build/src/server/factories/middleware_handler.d.ts +12 -3
- package/build/src/server/factories/route_finder.d.ts +16 -6
- package/build/src/server/factories/write_response.d.ts +10 -3
- package/build/src/server/main.d.ts +83 -29
- package/build/src/tracing_channels.d.ts +4 -4
- package/build/src/types/main.d.ts +1 -1
- package/build/src/types/middleware.d.ts +35 -10
- package/build/src/types/qs.d.ts +5 -0
- package/build/src/types/request.d.ts +1 -1
- package/build/src/types/response.d.ts +14 -6
- package/build/src/types/route.d.ts +53 -51
- package/build/src/types/server.d.ts +30 -15
- package/build/src/types/tracing_channels.d.ts +24 -6
- package/build/src/types/url_builder.d.ts +22 -0
- package/build/src/utils.d.ts +76 -11
- package/package.json +29 -30
- package/build/chunk-ASX56VAK.js +0 -76
- package/build/client.cjs +0 -232
- package/build/client.d.cts +0 -258
- package/build/client.d.ts +0 -258
- package/build/client.js +0 -229
- package/build/src/client/main.d.ts +0 -3
- package/build/src/client/router.d.ts +0 -68
package/build/client.d.ts
DELETED
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
import { Prettify } from '@poppinss/utils/types';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Types shared with the client. These should never import other types
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Options accepted by "url" and "route" helper methods
|
|
9
|
-
*/
|
|
10
|
-
type URLOptions = {
|
|
11
|
-
qs?: Record<string, any>;
|
|
12
|
-
prefixUrl?: string;
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Options accepted by "signedUrl" and "signedRoute" helper methods
|
|
16
|
-
*/
|
|
17
|
-
type SignedURLOptions = URLOptions & {
|
|
18
|
-
expiresIn?: string | number;
|
|
19
|
-
purpose?: string;
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* Returns params for a route identifier
|
|
23
|
-
*/
|
|
24
|
-
type RouteBuilderArguments<Routes, Method extends keyof Routes, Identifier extends keyof Routes[Method], Options extends any = URLOptions> = Routes extends LookupList ? Prettify<undefined extends Routes[Method][Identifier]['params'] ? [identifier: Identifier, params?: undefined, options?: Options] : [undefined] extends [Routes[Method][Identifier]['params']] ? [
|
|
25
|
-
identifier: Identifier,
|
|
26
|
-
params?: Routes[Method][Identifier]['params'] | Routes[Method][Identifier]['paramsTuple'],
|
|
27
|
-
options?: Options
|
|
28
|
-
] : [
|
|
29
|
-
identifier: Identifier,
|
|
30
|
-
params: Routes[Method][Identifier]['params'] | Routes[Method][Identifier]['paramsTuple'],
|
|
31
|
-
options?: Options
|
|
32
|
-
]> : never;
|
|
33
|
-
/**
|
|
34
|
-
* Shape of a route param matcher
|
|
35
|
-
*/
|
|
36
|
-
type RouteMatcher = {
|
|
37
|
-
match?: RegExp;
|
|
38
|
-
cast?: (value: string) => any;
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* Route token stored by matchit library
|
|
42
|
-
*/
|
|
43
|
-
type MatchItRouteToken = RouteMatcher & {
|
|
44
|
-
old: string;
|
|
45
|
-
type: 0 | 1 | 2 | 3;
|
|
46
|
-
val: string;
|
|
47
|
-
end: string;
|
|
48
|
-
};
|
|
49
|
-
/**
|
|
50
|
-
* Representation of route shared with the client
|
|
51
|
-
*/
|
|
52
|
-
type ClientRouteJSON = {
|
|
53
|
-
/**
|
|
54
|
-
* A unique name for the route
|
|
55
|
-
*/
|
|
56
|
-
name?: string;
|
|
57
|
-
/**
|
|
58
|
-
* Route URI pattern
|
|
59
|
-
*/
|
|
60
|
-
pattern: string;
|
|
61
|
-
/**
|
|
62
|
-
* HTTP methods, the route responds to.
|
|
63
|
-
*/
|
|
64
|
-
methods: string[];
|
|
65
|
-
/**
|
|
66
|
-
* Route domain
|
|
67
|
-
*/
|
|
68
|
-
domain: string;
|
|
69
|
-
/**
|
|
70
|
-
* Reference to the route handler
|
|
71
|
-
*/
|
|
72
|
-
handler: {
|
|
73
|
-
reference?: any;
|
|
74
|
-
} | Function;
|
|
75
|
-
/**
|
|
76
|
-
* Tokens to be used to construct the route URL
|
|
77
|
-
*/
|
|
78
|
-
tokens: MatchItRouteToken[];
|
|
79
|
-
};
|
|
80
|
-
/**
|
|
81
|
-
* LookupList type is used by the URLBuilder to provide
|
|
82
|
-
* type-safety when creating URLs.
|
|
83
|
-
*
|
|
84
|
-
* There is no runtime property that matches this type. Its
|
|
85
|
-
* purely for type-inference.
|
|
86
|
-
*/
|
|
87
|
-
type LookupList = {
|
|
88
|
-
[method: string]: {
|
|
89
|
-
[identifier: string]: {
|
|
90
|
-
paramsTuple?: [...any[]];
|
|
91
|
-
params?: {
|
|
92
|
-
[name: string]: any;
|
|
93
|
-
};
|
|
94
|
-
};
|
|
95
|
-
};
|
|
96
|
-
};
|
|
97
|
-
/**
|
|
98
|
-
* The urlFor helper is used to make URLs for pre-existing known routes. You can
|
|
99
|
-
* make a URL using the route name, route pattern, or the route controller
|
|
100
|
-
* reference (depends upon enabled lookupStrategies)
|
|
101
|
-
*
|
|
102
|
-
* ```ts
|
|
103
|
-
* urlFor('users.show', [1]) // /users/1
|
|
104
|
-
*
|
|
105
|
-
* // Lookup inside a specific domain
|
|
106
|
-
* urlFor('blog.adonisjs.com@posts.show', [1]) // /posts/1
|
|
107
|
-
* ```
|
|
108
|
-
*/
|
|
109
|
-
type UrlFor<Routes extends LookupList, Options extends any = URLOptions> = (<Identifier extends keyof Routes['ALL'] & string>(...[identifier, params, options]: RouteBuilderArguments<Routes, 'ALL', Identifier, Options>) => string) & {
|
|
110
|
-
/**
|
|
111
|
-
* Make URL for a GET route. An error will be raised if the route doesn't
|
|
112
|
-
* exist.
|
|
113
|
-
*
|
|
114
|
-
* ```ts
|
|
115
|
-
* urlFor.get('users.show', [1]) // { method: 'get', url: '/users/1' }
|
|
116
|
-
* urlFor.get('users.store', [1]) // Error: Route not found GET@users/store
|
|
117
|
-
* ```
|
|
118
|
-
*/
|
|
119
|
-
get<RouteIdentifier extends keyof Routes['GET'] & string>(...[identifier, params, options]: RouteBuilderArguments<Routes, 'GET', RouteIdentifier, Options>): {
|
|
120
|
-
method: 'get';
|
|
121
|
-
url: string;
|
|
122
|
-
};
|
|
123
|
-
/**
|
|
124
|
-
* Make URL for a POST route. An error will be raised if the route doesn't
|
|
125
|
-
* exist.
|
|
126
|
-
*
|
|
127
|
-
* ```ts
|
|
128
|
-
* urlFor.post('users.store') // { method: 'post', url: '/users' }
|
|
129
|
-
* urlFor.post('users.show', [1]) // Error: Route not found POST@users.show
|
|
130
|
-
* ```
|
|
131
|
-
*/
|
|
132
|
-
post<RouteIdentifier extends keyof Routes['POST'] & string>(...[identifier, params, options]: RouteBuilderArguments<Routes, 'POST', RouteIdentifier, Options>): {
|
|
133
|
-
method: 'post';
|
|
134
|
-
url: string;
|
|
135
|
-
};
|
|
136
|
-
/**
|
|
137
|
-
* Make URL for a PUT route. An error will be raised if the route doesn't
|
|
138
|
-
* exist.
|
|
139
|
-
*
|
|
140
|
-
* ```ts
|
|
141
|
-
* urlFor.put('users.update', [1]) // { method: 'put', url: '/users/1' }
|
|
142
|
-
* urlFor.put('users.show', [1]) // Error: Route not found PUT@users.show
|
|
143
|
-
* ```
|
|
144
|
-
*/
|
|
145
|
-
put<RouteIdentifier extends keyof Routes['PUT'] & string>(...[identifier, params, options]: RouteBuilderArguments<Routes, 'PUT', RouteIdentifier, Options>): {
|
|
146
|
-
method: 'put';
|
|
147
|
-
url: string;
|
|
148
|
-
};
|
|
149
|
-
/**
|
|
150
|
-
* Make URL for a PATCH route. An error will be raised if the route doesn't
|
|
151
|
-
* exist.
|
|
152
|
-
*
|
|
153
|
-
* ```ts
|
|
154
|
-
* urlFor.put('users.update', [1]) // { method: 'patch', url: '/users/1' }
|
|
155
|
-
* urlFor.put('users.show', [1]) // Error: Route not found PATCH@users.show
|
|
156
|
-
* ```
|
|
157
|
-
*/
|
|
158
|
-
patch<RouteIdentifier extends keyof Routes['PATCH'] & string>(...[identifier, params, options]: RouteBuilderArguments<Routes, 'PATCH', RouteIdentifier, Options>): {
|
|
159
|
-
method: 'patch';
|
|
160
|
-
url: string;
|
|
161
|
-
};
|
|
162
|
-
/**
|
|
163
|
-
* Make URL for a DELETE route. An error will be raised if the route doesn't
|
|
164
|
-
* exist.
|
|
165
|
-
*
|
|
166
|
-
* ```ts
|
|
167
|
-
* urlFor.delete('users.destroy', [1]) // { method: 'delete', url: '/users/1' }
|
|
168
|
-
* urlFor.delete('users.show', [1]) // Error: Route not found DELETE@users.show
|
|
169
|
-
* ```
|
|
170
|
-
*/
|
|
171
|
-
delete<RouteIdentifier extends keyof Routes['DELETE'] & string>(...[identifier, params, options]: RouteBuilderArguments<Routes, 'DELETE', RouteIdentifier, Options>): {
|
|
172
|
-
method: 'delete';
|
|
173
|
-
url: string;
|
|
174
|
-
};
|
|
175
|
-
/**
|
|
176
|
-
* Make URL for a custom route method. An error will be raised if the route doesn't
|
|
177
|
-
* exist for the same method.
|
|
178
|
-
*/
|
|
179
|
-
method<Method extends keyof Routes & string, RouteIdentifier extends keyof Routes[Method] & string>(method: Method, ...[identifier, params, options]: RouteBuilderArguments<Routes, Method, RouteIdentifier, Options>): {
|
|
180
|
-
method: Method;
|
|
181
|
-
url: string;
|
|
182
|
-
};
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* The router client contains the shared logic for finding routes
|
|
187
|
-
* used by the server and the client.
|
|
188
|
-
*/
|
|
189
|
-
declare class RouterClient<T extends ClientRouteJSON> {
|
|
190
|
-
/**
|
|
191
|
-
* List of route references kept for lookup.
|
|
192
|
-
*/
|
|
193
|
-
protected routes: {
|
|
194
|
-
[domain: string]: T[];
|
|
195
|
-
};
|
|
196
|
-
/**
|
|
197
|
-
* The lookup strategies to follow when generating URL builder
|
|
198
|
-
* types and client
|
|
199
|
-
*/
|
|
200
|
-
lookupStrategies: ('name' | 'pattern' | 'controller')[];
|
|
201
|
-
constructor(routes?: {
|
|
202
|
-
[domain: string]: T[];
|
|
203
|
-
});
|
|
204
|
-
/**
|
|
205
|
-
* Register route JSON payload
|
|
206
|
-
*/
|
|
207
|
-
protected register(route: T): void;
|
|
208
|
-
/**
|
|
209
|
-
* Define the lookup strategies to follow when generating URL builder
|
|
210
|
-
* types and client.
|
|
211
|
-
*/
|
|
212
|
-
updateLookupStrategies(strategies: ('name' | 'pattern' | 'controller')[]): this;
|
|
213
|
-
/**
|
|
214
|
-
* Finds a route by its identifier. The identifier can be the
|
|
215
|
-
* route name, controller.method name or the route pattern
|
|
216
|
-
* itself.
|
|
217
|
-
*
|
|
218
|
-
* When "followLookupStrategy" is enabled, the lookup will be performed
|
|
219
|
-
* on the basis of the lookup strategy enabled via the "lookupStrategies"
|
|
220
|
-
* method. The default lookupStrategy is "name" and "pattern".
|
|
221
|
-
*/
|
|
222
|
-
find(routeIdentifier: string, domain?: string, method?: string, followLookupStrategy?: boolean): T | null;
|
|
223
|
-
/**
|
|
224
|
-
* Finds a route by its identifier. The identifier can be the
|
|
225
|
-
* route name, controller.method name or the route pattern
|
|
226
|
-
* itself.
|
|
227
|
-
*
|
|
228
|
-
* An error is raised when unable to find the route.
|
|
229
|
-
*
|
|
230
|
-
* When "followLookupStrategy" is enabled, the lookup will be performed
|
|
231
|
-
* on the basis of the lookup strategy enabled via the "lookupStrategies"
|
|
232
|
-
* method. The default lookupStrategy is "name" and "pattern".
|
|
233
|
-
*/
|
|
234
|
-
findOrFail(routeIdentifier: string, domain?: string, method?: string, followLookupStrategy?: boolean): T;
|
|
235
|
-
/**
|
|
236
|
-
* Check if a route exists. The identifier can be the
|
|
237
|
-
* route name, controller.method name or the route pattern
|
|
238
|
-
* itself.
|
|
239
|
-
*
|
|
240
|
-
* When "followLookupStrategy" is enabled, the lookup will be performed
|
|
241
|
-
* on the basis of the lookup strategy enabled via the "lookupStrategies"
|
|
242
|
-
* method. The default lookupStrategy is "name" and "pattern".
|
|
243
|
-
*/
|
|
244
|
-
has(routeIdentifier: string, domain?: string, method?: string, followLookupStrategy?: boolean): boolean;
|
|
245
|
-
/**
|
|
246
|
-
* Returns a list of routes grouped by their domain names
|
|
247
|
-
*/
|
|
248
|
-
toJSON(): {
|
|
249
|
-
[domain: string]: T[];
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Creates the URLBuilder helper
|
|
255
|
-
*/
|
|
256
|
-
declare function createUrlBuilder<Routes extends LookupList>(router: RouterClient<ClientRouteJSON>, searchParamsStringifier: (qs: Record<string, any>) => string): UrlFor<Routes>;
|
|
257
|
-
|
|
258
|
-
export { type ClientRouteJSON, type LookupList, type MatchItRouteToken, type RouteBuilderArguments, type RouteMatcher, RouterClient, type SignedURLOptions, type URLOptions, type UrlFor, createUrlBuilder };
|
package/build/client.js
DELETED
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
// src/client/router.ts
|
|
2
|
-
var RouterClient = class {
|
|
3
|
-
/**
|
|
4
|
-
* List of route references kept for lookup.
|
|
5
|
-
*/
|
|
6
|
-
routes;
|
|
7
|
-
/**
|
|
8
|
-
* The lookup strategies to follow when generating URL builder
|
|
9
|
-
* types and client
|
|
10
|
-
*/
|
|
11
|
-
lookupStrategies = ["name", "pattern"];
|
|
12
|
-
constructor(routes) {
|
|
13
|
-
this.routes = routes ?? {};
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Register route JSON payload
|
|
17
|
-
*/
|
|
18
|
-
register(route) {
|
|
19
|
-
this.routes[route.domain] = this.routes[route.domain] || [];
|
|
20
|
-
this.routes[route.domain].push(route);
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Define the lookup strategies to follow when generating URL builder
|
|
24
|
-
* types and client.
|
|
25
|
-
*/
|
|
26
|
-
updateLookupStrategies(strategies) {
|
|
27
|
-
this.lookupStrategies = strategies;
|
|
28
|
-
return this;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Finds a route by its identifier. The identifier can be the
|
|
32
|
-
* route name, controller.method name or the route pattern
|
|
33
|
-
* itself.
|
|
34
|
-
*
|
|
35
|
-
* When "followLookupStrategy" is enabled, the lookup will be performed
|
|
36
|
-
* on the basis of the lookup strategy enabled via the "lookupStrategies"
|
|
37
|
-
* method. The default lookupStrategy is "name" and "pattern".
|
|
38
|
-
*/
|
|
39
|
-
find(routeIdentifier, domain, method, followLookupStrategy) {
|
|
40
|
-
if (!domain) {
|
|
41
|
-
let route = null;
|
|
42
|
-
for (const routeDomain of Object.keys(this.routes)) {
|
|
43
|
-
route = this.find(routeIdentifier, routeDomain, method, followLookupStrategy);
|
|
44
|
-
if (route) {
|
|
45
|
-
break;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return route;
|
|
49
|
-
}
|
|
50
|
-
const routes = this.routes[domain];
|
|
51
|
-
if (!routes) {
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
const lookupByName = !followLookupStrategy || this.lookupStrategies.includes("name");
|
|
55
|
-
const lookupByPattern = !followLookupStrategy || this.lookupStrategies.includes("pattern");
|
|
56
|
-
const lookupByController = !followLookupStrategy || this.lookupStrategies.includes("controller");
|
|
57
|
-
return routes.find((route) => {
|
|
58
|
-
if (method && !route.methods.includes(method)) {
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
61
|
-
if (route.name === routeIdentifier && lookupByName || route.pattern === routeIdentifier && lookupByPattern) {
|
|
62
|
-
return true;
|
|
63
|
-
}
|
|
64
|
-
if (typeof route.handler === "function" || !lookupByController) {
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
return route.handler.reference === routeIdentifier;
|
|
68
|
-
}) || null;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Finds a route by its identifier. The identifier can be the
|
|
72
|
-
* route name, controller.method name or the route pattern
|
|
73
|
-
* itself.
|
|
74
|
-
*
|
|
75
|
-
* An error is raised when unable to find the route.
|
|
76
|
-
*
|
|
77
|
-
* When "followLookupStrategy" is enabled, the lookup will be performed
|
|
78
|
-
* on the basis of the lookup strategy enabled via the "lookupStrategies"
|
|
79
|
-
* method. The default lookupStrategy is "name" and "pattern".
|
|
80
|
-
*/
|
|
81
|
-
findOrFail(routeIdentifier, domain, method, followLookupStrategy) {
|
|
82
|
-
const route = this.find(routeIdentifier, domain, method, followLookupStrategy);
|
|
83
|
-
if (!route) {
|
|
84
|
-
throw new Error(`Cannot lookup route "${routeIdentifier}"`);
|
|
85
|
-
}
|
|
86
|
-
return route;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Check if a route exists. The identifier can be the
|
|
90
|
-
* route name, controller.method name or the route pattern
|
|
91
|
-
* itself.
|
|
92
|
-
*
|
|
93
|
-
* When "followLookupStrategy" is enabled, the lookup will be performed
|
|
94
|
-
* on the basis of the lookup strategy enabled via the "lookupStrategies"
|
|
95
|
-
* method. The default lookupStrategy is "name" and "pattern".
|
|
96
|
-
*/
|
|
97
|
-
has(routeIdentifier, domain, method, followLookupStrategy) {
|
|
98
|
-
return !!this.find(routeIdentifier, domain, method, followLookupStrategy);
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Returns a list of routes grouped by their domain names
|
|
102
|
-
*/
|
|
103
|
-
toJSON() {
|
|
104
|
-
return this.routes;
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
// src/client/url_builder.ts
|
|
109
|
-
function createURL(identifier, tokens, searchParamsStringifier, params, options) {
|
|
110
|
-
const uriSegments = [];
|
|
111
|
-
const paramsArray = Array.isArray(params) ? params : null;
|
|
112
|
-
const paramsObject = !Array.isArray(params) ? params ?? {} : {};
|
|
113
|
-
let paramsIndex = 0;
|
|
114
|
-
for (const token of tokens) {
|
|
115
|
-
if (token.type === 0) {
|
|
116
|
-
uriSegments.push(token.val === "/" ? "" : `${token.val}${token.end}`);
|
|
117
|
-
continue;
|
|
118
|
-
}
|
|
119
|
-
if (token.type === 2) {
|
|
120
|
-
const values = paramsArray ? paramsArray.slice(paramsIndex) : paramsObject["*"];
|
|
121
|
-
if (!Array.isArray(values) || !values.length) {
|
|
122
|
-
throw new Error(
|
|
123
|
-
`Cannot make URL for "${identifier}". Invalid value provided for the wildcard param`
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
uriSegments.push(`${values.join("/")}${token.end}`);
|
|
127
|
-
break;
|
|
128
|
-
}
|
|
129
|
-
const paramName = token.val;
|
|
130
|
-
const value = paramsArray ? paramsArray[paramsIndex] : paramsObject[paramName];
|
|
131
|
-
const isDefined = value !== void 0 && value !== null;
|
|
132
|
-
if (token.type === 1 && !isDefined) {
|
|
133
|
-
throw new Error(
|
|
134
|
-
`Cannot make URL for "${identifier}". Missing value for the "${paramName}" param`
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
if (isDefined) {
|
|
138
|
-
uriSegments.push(`${value}${token.end}`);
|
|
139
|
-
}
|
|
140
|
-
paramsIndex++;
|
|
141
|
-
}
|
|
142
|
-
let URI = `/${uriSegments.join("/")}`;
|
|
143
|
-
if (options?.prefixUrl) {
|
|
144
|
-
URI = `${options?.prefixUrl.replace(/\/$/, "")}${URI}`;
|
|
145
|
-
}
|
|
146
|
-
if (options?.qs) {
|
|
147
|
-
const queryString = searchParamsStringifier(options?.qs);
|
|
148
|
-
URI = queryString ? `${URI}?${queryString}` : URI;
|
|
149
|
-
}
|
|
150
|
-
return URI;
|
|
151
|
-
}
|
|
152
|
-
function createUrlBuilder(router, searchParamsStringifier) {
|
|
153
|
-
let domainsList;
|
|
154
|
-
function createUrlForRoute(identifier, params, options, method) {
|
|
155
|
-
if (!domainsList) {
|
|
156
|
-
domainsList = Object.keys(router.toJSON()).filter((domain2) => domain2 !== "root");
|
|
157
|
-
}
|
|
158
|
-
const domain = domainsList.find((name) => identifier.startsWith(`${name}@`));
|
|
159
|
-
const routeIdentifier = domain ? identifier.replace(new RegExp(`^${domain}@`), "") : identifier;
|
|
160
|
-
const route = router.findOrFail(routeIdentifier, domain, method, true);
|
|
161
|
-
return createURL(
|
|
162
|
-
route.name ?? route.pattern,
|
|
163
|
-
route.tokens,
|
|
164
|
-
searchParamsStringifier,
|
|
165
|
-
params,
|
|
166
|
-
options
|
|
167
|
-
);
|
|
168
|
-
}
|
|
169
|
-
const urlFor = function route(...[identifier, params, options]) {
|
|
170
|
-
return createUrlForRoute(identifier, params, options);
|
|
171
|
-
};
|
|
172
|
-
urlFor.get = function urlForMethodGet(...[identifier, params, options]) {
|
|
173
|
-
return {
|
|
174
|
-
url: createUrlForRoute(identifier, params, options, "GET"),
|
|
175
|
-
method: "get",
|
|
176
|
-
toString() {
|
|
177
|
-
return this.url;
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
};
|
|
181
|
-
urlFor.post = function urlForMethodPost(...[identifier, params, options]) {
|
|
182
|
-
return {
|
|
183
|
-
url: createUrlForRoute(identifier, params, options, "POST"),
|
|
184
|
-
method: "post",
|
|
185
|
-
toString() {
|
|
186
|
-
return this.url;
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
};
|
|
190
|
-
urlFor.put = function urlForMethodPut(...[identifier, params, options]) {
|
|
191
|
-
return {
|
|
192
|
-
url: createUrlForRoute(identifier, params, options, "PUT"),
|
|
193
|
-
method: "put",
|
|
194
|
-
toString() {
|
|
195
|
-
return this.url;
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
};
|
|
199
|
-
urlFor.patch = function urlForMethodPatch(...[identifier, params, options]) {
|
|
200
|
-
return {
|
|
201
|
-
url: createUrlForRoute(identifier, params, options, "PATCH"),
|
|
202
|
-
method: "patch",
|
|
203
|
-
toString() {
|
|
204
|
-
return this.url;
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
};
|
|
208
|
-
urlFor.delete = function urlForMethodDelete(...[identifier, params, options]) {
|
|
209
|
-
return {
|
|
210
|
-
url: createUrlForRoute(identifier, params, options, "DELETE"),
|
|
211
|
-
method: "delete",
|
|
212
|
-
toString() {
|
|
213
|
-
return this.url;
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
|
-
};
|
|
217
|
-
urlFor.method = function urlForCustomMethod(method, ...[identifier, params, options]) {
|
|
218
|
-
return {
|
|
219
|
-
url: createUrlForRoute(identifier, params, options, method),
|
|
220
|
-
method,
|
|
221
|
-
toString() {
|
|
222
|
-
return this.url;
|
|
223
|
-
}
|
|
224
|
-
};
|
|
225
|
-
};
|
|
226
|
-
return urlFor;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
export { RouterClient, createUrlBuilder };
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { type ClientRouteJSON } from './types.ts';
|
|
2
|
-
/**
|
|
3
|
-
* The router client contains the shared logic for finding routes
|
|
4
|
-
* used by the server and the client.
|
|
5
|
-
*/
|
|
6
|
-
export declare class RouterClient<T extends ClientRouteJSON> {
|
|
7
|
-
/**
|
|
8
|
-
* List of route references kept for lookup.
|
|
9
|
-
*/
|
|
10
|
-
protected routes: {
|
|
11
|
-
[domain: string]: T[];
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* The lookup strategies to follow when generating URL builder
|
|
15
|
-
* types and client
|
|
16
|
-
*/
|
|
17
|
-
lookupStrategies: ('name' | 'pattern' | 'controller')[];
|
|
18
|
-
constructor(routes?: {
|
|
19
|
-
[domain: string]: T[];
|
|
20
|
-
});
|
|
21
|
-
/**
|
|
22
|
-
* Register route JSON payload
|
|
23
|
-
*/
|
|
24
|
-
protected register(route: T): void;
|
|
25
|
-
/**
|
|
26
|
-
* Define the lookup strategies to follow when generating URL builder
|
|
27
|
-
* types and client.
|
|
28
|
-
*/
|
|
29
|
-
updateLookupStrategies(strategies: ('name' | 'pattern' | 'controller')[]): this;
|
|
30
|
-
/**
|
|
31
|
-
* Finds a route by its identifier. The identifier can be the
|
|
32
|
-
* route name, controller.method name or the route pattern
|
|
33
|
-
* itself.
|
|
34
|
-
*
|
|
35
|
-
* When "followLookupStrategy" is enabled, the lookup will be performed
|
|
36
|
-
* on the basis of the lookup strategy enabled via the "lookupStrategies"
|
|
37
|
-
* method. The default lookupStrategy is "name" and "pattern".
|
|
38
|
-
*/
|
|
39
|
-
find(routeIdentifier: string, domain?: string, method?: string, followLookupStrategy?: boolean): T | null;
|
|
40
|
-
/**
|
|
41
|
-
* Finds a route by its identifier. The identifier can be the
|
|
42
|
-
* route name, controller.method name or the route pattern
|
|
43
|
-
* itself.
|
|
44
|
-
*
|
|
45
|
-
* An error is raised when unable to find the route.
|
|
46
|
-
*
|
|
47
|
-
* When "followLookupStrategy" is enabled, the lookup will be performed
|
|
48
|
-
* on the basis of the lookup strategy enabled via the "lookupStrategies"
|
|
49
|
-
* method. The default lookupStrategy is "name" and "pattern".
|
|
50
|
-
*/
|
|
51
|
-
findOrFail(routeIdentifier: string, domain?: string, method?: string, followLookupStrategy?: boolean): T;
|
|
52
|
-
/**
|
|
53
|
-
* Check if a route exists. The identifier can be the
|
|
54
|
-
* route name, controller.method name or the route pattern
|
|
55
|
-
* itself.
|
|
56
|
-
*
|
|
57
|
-
* When "followLookupStrategy" is enabled, the lookup will be performed
|
|
58
|
-
* on the basis of the lookup strategy enabled via the "lookupStrategies"
|
|
59
|
-
* method. The default lookupStrategy is "name" and "pattern".
|
|
60
|
-
*/
|
|
61
|
-
has(routeIdentifier: string, domain?: string, method?: string, followLookupStrategy?: boolean): boolean;
|
|
62
|
-
/**
|
|
63
|
-
* Returns a list of routes grouped by their domain names
|
|
64
|
-
*/
|
|
65
|
-
toJSON(): {
|
|
66
|
-
[domain: string]: T[];
|
|
67
|
-
};
|
|
68
|
-
}
|